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 | |