1 #include "std.h"
2
3 #undef EXTRA_INIT
4 #define EXTRA_INIT\
5 add_action("sell", "sell");\
6 add_action("value", "value");\
7 add_action("buy", "buy");\
8 add_action("north", "north");\
9 add_action("list", "list");
10
11 TWO_EXIT("room/vill_road2", "south",
12 "room/storage", "west",
13 "The shop",
14 "You are in a shop. You can buy or sell things here.\n" +
15 "Commands are: 'buy item', 'sell item', 'sell all', 'list', 'list weapons'\n"+
16 "'list armours' and 'value item'.\n" +
17 "There is an opening to the north, and some shimmering\n" +
18 "blue light in the doorway.\nTo the west you see a small room.\n", 1)
19
20
sell(item)21 sell(item) {
22 object ob;
23
24 if (!item)
25 return 0;
26 if (item == "all") {
27 object next;
28 ob = first_inventory(this_player());
29 while(ob) {
30 next = next_inventory(ob);
31 if (!ob->drop() && ob->query_value()) {
32 write(ob->short() + ":\t");
33 do_sell(ob);
34 }
35 ob = next;
36 }
37 write("Ok.\n");
38 return 1;
39 }
40 ob = present(item, this_player());
41 if (!ob)
42 ob = present(item, this_object());
43 if (!ob) {
44 write("No such item ("); write(item); write(") here.\n");
45 return 1;
46 }
47 do_sell(ob);
48 return 1;
49 }
50
do_sell(ob)51 do_sell(ob) {
52 int value, do_destroy;
53 value = ob->query_value();
54 if (!value) {
55 write(ob->short() + " has no value.\n");
56 return 1;
57 }
58 if (environment(ob) == this_player()) {
59 int weight;
60 if (call_other(ob, "drop", 0)) {
61 write("I can't take it from you!\n");
62 return 1;
63 }
64 weight = call_other(ob, "query_weight", 0);
65 call_other(this_player(), "add_weight", - weight);
66 }
67 if (value > 2000)
68 do_destroy = 1;
69 if (value > 1000) {
70 write("The shop is low on money...\n");
71 value = 1000;
72 }
73 write("You get "); write(value); write(" gold coins.\n");
74 say(call_other(this_player(), "query_name", 0) + " sells " +
75 call_other(ob, "short", 0) + ".\n");
76 call_other(this_player(), "add_money", value);
77 add_worth(value, ob);
78 if (do_destroy) {
79 write("The valuable item is hidden away.\n");
80 destruct(ob);
81 return 1;
82 }
83 call_other("room/store", "store", ob);
84 return 1;
85 }
86
value(item)87 value(item) {
88 int value;
89 string name_of_item;
90
91 if (!item)
92 return 0;
93 name_of_item = present(item);
94 if (!name_of_item)
95 name_of_item = find_item_in_player(item);
96 if (!name_of_item) {
97 if (call_other("room/store", "value", item))
98 return 1;
99 write("No such item ("); write(item); write(") here\n");
100 write("or in the store.\n");
101 return 1;
102 }
103 value = call_other(name_of_item, "query_value", 0);
104 if (!value) {
105 write(item); write(" has no value.\n");
106 return 1;
107 }
108 write("You would get "); write(value); write(" gold coins.\n");
109 return 1;
110 }
111
buy(item)112 buy(item) {
113 if (!item)
114 return 0;
115 call_other("room/store", "buy", item);
116 return 1;
117 }
118
north()119 north() {
120 if (call_other(this_player(), "query_level", 0) < 20) {
121 write("A strong magic force stops you.\n");
122 say(call_other(this_player(), "query_name", 0) +
123 " tries to go through the field, but fails.\n");
124 return 1;
125 }
126 write("You wriggle through the force field...\n");
127 call_other(this_player(), "move_player", "north#room/store");
128 return 1;
129 }
130
list(obj)131 list(obj) {
132 call_other("room/store", "inventory", obj);
133 return 1;
134 }
135
find_item_in_player(i)136 find_item_in_player(i)
137 {
138 object ob;
139
140 ob = first_inventory(this_player());
141 while(ob) {
142 if (call_other(ob, "id", i))
143 return ob;
144 ob = next_inventory(ob);
145 }
146 return 0;
147 }
148
query_drop_castle()149 query_drop_castle() {
150 return 1;
151 }
152