1 | #!perl # mandatory |
1 | #!perl # mandatory |
2 | |
2 | |
3 | sub ob2info { |
3 | sub ob2info { |
4 | my ($item, $rval) = @_; |
4 | my ($item, $rval) = @_; |
|
|
5 | |
5 | sprintf "[%s from %s (%d:%d%s) nrof: %d uuid: %s]", |
6 | sprintf "[%s from %s (%d:%d%s) nrof: %d uuid: %s]", |
6 | $item->name, $item->kv_get ('ext_reseller_seller'), |
7 | $item->name, $item->kv_get ('ext_reseller_seller'), |
7 | $item->kv_get ('ext_reseller_orig_value'), $item->value, |
8 | $item->kv_get ('ext_reseller_orig_value'), $item->value, |
8 | (defined $rval ? ":$rval" : ""), $item->nrof, $item->uuid; |
9 | (defined $rval ? ":$rval" : ""), $item->nrof, $item->uuid |
9 | } |
10 | } |
10 | |
11 | |
11 | sub audit_log { |
12 | sub audit_log { |
12 | my ($who, $action, $info) = @_; |
13 | my ($who, $action, $info) = @_; |
13 | warn |
14 | cf::info |
14 | sprintf "RESELLER_AUDIT(%s) %s %s: %s\n", |
15 | sprintf "RESELLER_AUDIT(%s) %s %s: %s\n", |
15 | $who->map->path, $who->name, $action, $info; |
16 | $who->map->path, $who->name, $action, $info; |
16 | } |
17 | } |
17 | |
18 | |
18 | sub find_rec; |
19 | sub find_rec; |
19 | |
20 | |
20 | sub find_rec { |
21 | sub find_rec { |
21 | my ($ob, $cb) = @_; |
22 | my ($ob, $cb) = @_; |
22 | |
23 | |
23 | my @found; |
24 | my @found; |
|
|
25 | |
24 | for my $i ($ob->inv) { |
26 | for my $i ($ob->inv) { |
25 | push @found, $i if $cb->($i); |
27 | push @found, $i if $cb->($i); |
26 | push @found, find_rec $i, $cb if $i->inv; |
28 | push @found, find_rec $i, $cb if $i->inv; |
27 | } |
29 | } |
28 | |
30 | |
29 | return @found; |
31 | @found |
30 | } |
32 | } |
31 | |
33 | |
32 | sub find_unpaid { |
34 | sub find_unpaid { |
33 | my ($ob) = @_; |
35 | my ($ob) = @_; |
|
|
36 | |
34 | find_rec $ob, sub { $_[0]->flag (cf::FLAG_UNPAID) }; |
37 | find_rec $ob, sub { $_[0]->flag (cf::FLAG_UNPAID) }; |
35 | } |
38 | } |
36 | |
39 | |
37 | sub find_traded { |
40 | sub find_traded { |
38 | my ($ob) = @_; |
41 | my ($ob) = @_; |
|
|
42 | |
39 | find_rec $ob, sub { $_[0]->kv_get ('ext_reseller_seller') ne '' }; |
43 | find_rec $ob, sub { $_[0]->kv_get ('ext_reseller_seller') ne '' }; |
40 | } |
44 | } |
41 | |
45 | |
42 | cf::register_script_function "reseller::list_sells" => sub { |
46 | cf::register_script_function "reseller::list_sells" => sub { |
43 | my ($who, $msg, $npc) = @_; |
47 | my ($who, $msg, $npc) = @_; |
… | |
… | |
96 | |
100 | |
97 | my @obs = grep { $_->name eq $self->{reseller_shopmat}{npc_name} } |
101 | my @obs = grep { $_->name eq $self->{reseller_shopmat}{npc_name} } |
98 | $who->map->at ($self->{reseller_shopmat}{npc_x}, $self->{reseller_shopmat}{npc_y}); |
102 | $who->map->at ($self->{reseller_shopmat}{npc_x}, $self->{reseller_shopmat}{npc_y}); |
99 | |
103 | |
100 | unless (@obs) { |
104 | unless (@obs) { |
101 | warn "Couldn't find shop keeper in " . $who->map->path . "\n"; |
105 | cf::error "Couldn't find shop keeper in " . $who->map->path . "\n"; |
102 | return cf::override; |
106 | return cf::override; |
103 | } |
107 | } |
104 | |
108 | |
105 | my $ext_re_sales = $obs[0]->kv_get ('ext_reseller_sales'); |
109 | my $ext_re_sales = $obs[0]->kv_get ('ext_reseller_sales'); |
106 | my $sells = $ext_re_sales && cf::decode_json $ext_re_sales; |
110 | my $sells = $ext_re_sales && cf::decode_json $ext_re_sales; |
… | |
… | |
116 | next; |
120 | next; |
117 | } |
121 | } |
118 | |
122 | |
119 | my $value = $item->query_cost ($who, cf::F_BUY | cf::F_SHOP); |
123 | my $value = $item->query_cost ($who, cf::F_BUY | cf::F_SHOP); |
120 | |
124 | |
121 | warn "Object " . $item->name . " bought by " . $who->name . " on map " |
125 | cf::debug "Object ", $item->name, " bought by ", $who->name, " on map " , |
122 | . $who->map->path . " for $value silver has no seller set\n" |
126 | $who->map->path, " for $value silver has no seller set\n" |
123 | if $item->kv_get ('ext_reseller_seller') eq ''; |
127 | if $item->kv_get ('ext_reseller_seller') eq ''; |
124 | |
128 | |
125 | $unpaid_items->{$item} = [$value, $item]; |
129 | $unpaid_items->{$item} = [$value, $item]; |
126 | } |
130 | } |
127 | |
131 | |
… | |
… | |
207 | ); |
211 | ); |
208 | return cf::override; |
212 | return cf::override; |
209 | } |
213 | } |
210 | } |
214 | } |
211 | } else { |
215 | } else { |
212 | # commented out the following line because too many just use the |
216 | # commented out the following line because too many just use the |
213 | # reseller shop as dumpyard: |
217 | # reseller shop as dumpyard: |
214 | # $value = $what->query_cost ($who, cf::F_SELL | cf::F_SHOP) / ($what->nrof || 1); |
218 | # $value = $what->query_cost ($who, cf::F_SELL | cf::F_SHOP) / ($what->nrof || 1); |
215 | give_back_with_message ($who, $what, |
219 | give_back_with_message ($who, $what, |
216 | "Sorry, you can't just sell stuff without assigning a price to it! " |
220 | "Sorry, you can't just sell stuff without assigning a price to it! " |
217 | . "Please name your item like '17 platinum' or '10 gold 8 silver' " |
221 | . "Please name your item like '17 platinum' or '10 gold 8 silver' " |
218 | . "and drop it again. (To rename the item use the B<rename> " |
222 | . "and drop it again. (To rename the item use the B<rename> " |
219 | . "entry in the inventory item popup menu)." |
223 | . "entry in the inventory item popup menu)." |
220 | ); |
224 | ); |
|
|
225 | return cf::override; |
|
|
226 | } |
|
|
227 | |
|
|
228 | if ($value > 100 ** 4) { # also for overflow prevention |
|
|
229 | give_back_with_message ($who, $what, |
|
|
230 | "The shopkeeper says: You can't sell something for such a high " |
|
|
231 | . "value. Please keep it below 100 royalty."); |
221 | return cf::override; |
232 | return cf::override; |
222 | } |
233 | } |
223 | |
234 | |
224 | if ($value < 0) { |
235 | if ($value < 0) { |
225 | give_back_with_message ($who, $what, |
236 | give_back_with_message ($who, $what, |
… | |
… | |
255 | |
266 | |
256 | # my $cost = $what->query_cost ($who, cf::F_BUY | cf::F_SHOP) / $what->nrof; |
267 | # my $cost = $what->query_cost ($who, cf::F_BUY | cf::F_SHOP) / $what->nrof; |
257 | # warn "COSTS NOW: $cost\n"; |
268 | # warn "COSTS NOW: $cost\n"; |
258 | |
269 | |
259 | $who->message ( |
270 | $who->message ( |
260 | "The shopkeeper says: Ok, I marked " |
271 | "The shopkeeper says: Ok, I marked " |
261 | . ($what->nrof || 1) . " " . $what->name . " to be sold for at least " |
272 | . ($what->nrof || 1) . " " . $what->name . " to be sold for at least " |
262 | . cf::cost_string_from_value ($value) |
273 | . cf::cost_string_from_value ($value) |
263 | . ($what->nrof > 1 ? " each" : ""), cf::NDI_BROWN |
274 | . ($what->nrof > 1 ? " each" : ""), cf::NDI_BROWN |
264 | ); |
275 | ); |
265 | |
276 | |
266 | $what->kv_set (ext_reseller_seller => $who->name); |
277 | $what->kv_set (ext_reseller_seller => $who->name); |
… | |
… | |
273 | audit_log ($who, 'sells', ob2info ($what)); |
284 | audit_log ($who, 'sells', ob2info ($what)); |
274 | |
285 | |
275 | cf::override; |
286 | cf::override; |
276 | }, |
287 | }, |
277 | ; |
288 | ; |
|
|
289 | |