1 #define MAX_LIST 30
2
3 int value;
4 string name_of_item;
5
6 short() {
7 return "store room for the shop";
8 }
9
init()10 init() {
11 add_action("south", "south");
12 }
13
inventory(str)14 inventory(str)
15 {
16 object ob;
17 int max;
18 if (!str)
19 str = "all";
20 max = MAX_LIST;
21 ob = first_inventory(this_object());
22 while(ob && max > 0) {
23 if (str == "all") {
24 list(ob);
25 max -= 1;
26 }
27 if (str == "weapons" && call_other(ob, "weapon_class", 0)) {
28 list(ob);
29 max -= 1;
30 }
31 if (str == "armours" && call_other(ob, "armour_class", 0)) {
32 list(ob);
33 max -= 1;
34 }
35 ob = next_inventory(ob);
36 }
37 }
38
list(ob)39 list(ob)
40 {
41 int value;
42
43 value = call_other(ob, "query_value", 0);
44 if (value) {
45 write(value*2 + ":\t" + call_other(ob, "short") + ".\n");
46 }
47 }
48
value(item)49 value(item) {
50 name_of_item = present(item);
51 if (!name_of_item) {
52 return 0;
53 }
54 value = call_other(name_of_item, "query_value", 0);
55 if (!value) {
56 return 0;
57 }
58 write("The "); write(item); write(" would cost you ");
59 write(value*2); write(" gold coins.\n");
60 return 1;
61 }
62
buy(item)63 buy(item) {
64 name_of_item = present(item);
65 if (!name_of_item) {
66 write("No such item in the store.\n");
67 return;
68 }
69 value = call_other(name_of_item, "query_value", 0);
70 if (!value) {
71 write("Item has no value.\n");
72 return;
73 }
74 value *= 2;
75 if (call_other(this_player(), "query_money", 0) < value) {
76 write("It would cost you ");
77 write(value); write(" gold coins, which you don't have.\n");
78 return;
79 }
80 if (!call_other(this_player(), "add_weight",
81 call_other(name_of_item, "query_weight"))) {
82 write("You can't carry that much.\n");
83 return;
84 }
85 call_other(this_player(), "add_money", 0 - value);
86 move_object(name_of_item, this_player());
87 write("Ok.\n");
88 say(call_other(this_player(), "query_name") + " buys " + item + ".\n");
89 }
90
south()91 south() {
92 call_other(this_player(), "move_player", "leaves#room/shop");
93 return 1;
94 }
95
heart_beat()96 heart_beat()
97 {
98 object ob, next_ob;
99 ob = first_inventory(this_object());
100 while(ob) {
101 next_ob = next_inventory(ob);
102 destruct(ob);
103 ob = next_ob;
104 }
105 }
106
reset(arg)107 reset(arg) {
108 if (!arg)
109 set_light(1);
110 if (!present("torch")) {
111 object torch;
112 torch = clone_object("obj/torch");
113 call_other(torch, "set_name", "torch");
114 call_other(torch, "set_fuel", 2000);
115 call_other(torch, "set_weight", 1);
116 move_object(torch, this_object());
117 }
118 }
119
120 long()
121 {
122 write("All things from the shop are stored here.\n");
123 }
124
store(item)125 store(item)
126 {
127 string short_desc;
128 object ob;
129
130 short_desc = call_other(item, "short");
131 ob = first_inventory(this_object());
132 while(ob) {
133 if (call_other(ob, "short") == short_desc) {
134 /* Move it before destruct, because the weight
135 has already been compensated for. */
136 move_object(item, this_object());
137 destruct(item);
138 return;
139 }
140 ob = next_inventory(ob);
141 }
142 move_object(item, this_object());
143 }
144