… | |
… | |
25 | } |
25 | } |
26 | } |
26 | } |
27 | return @unpaid; |
27 | return @unpaid; |
28 | } |
28 | } |
29 | |
29 | |
|
|
30 | cf::register_script_function "reseller::list_sells" => sub { |
|
|
31 | my ($who, $msg, $npc) = @_; |
|
|
32 | my $sells = $npc->{sells}->{$who->name}; |
|
|
33 | |
|
|
34 | unless (keys %{$sells || {}}) { |
|
|
35 | $who->reply ($npc, "I'm sorry, but you sold nothing.\n"); |
|
|
36 | return 0; |
|
|
37 | } |
|
|
38 | |
|
|
39 | $who->message ($npc->name . " says: You sold:\n", cf::NDI_BROWN); |
|
|
40 | for (keys %$sells) { |
|
|
41 | my $n = $_; |
|
|
42 | $n =~ s/\s*\(unpaid\)//g; |
|
|
43 | $who->message ("$n for " . cf::cost_string_from_value ($sells->{$_}), cf::NDI_BROWN); |
|
|
44 | } |
|
|
45 | |
|
|
46 | 0 |
|
|
47 | }; |
|
|
48 | |
30 | sub on_trigger { |
49 | sub on_trigger { |
31 | my ($ev, $ob, $who_caused, $who) = @_; |
50 | my ($ev, $ob, $who_caused, $who) = @_; |
32 | my $opt = $ev->options; |
51 | my $opt = $ev->options; |
|
|
52 | warn "OPT $opt\n"; |
33 | return 0 unless $opt =~ m/(\d+),(\d+)/; |
53 | return 1 unless $opt =~ m/(\S+),(\d+),(\d+)/; |
34 | my $val = 0; |
54 | my @obs = grep { $_->name eq $1 } $who->map->at ($2, $3); |
35 | $val += $_->value for find_unpaid ($who); |
55 | unless (@obs) { |
36 | warn "PAID $val\n"; |
56 | warn "Couldn't find shop keeper in " . $who->map . "\n"; |
|
|
57 | return 1; |
|
|
58 | } |
|
|
59 | warn "FOOOOGEOG ".$obs[0]->name." <<\n"; |
|
|
60 | |
|
|
61 | for my $item (find_unpaid ($who)) { |
|
|
62 | my $value = $item->query_cost ($who, cf::F_BUY | cf::F_SHOP); |
|
|
63 | |
|
|
64 | warn "Object " . $item->name . " bought by " . $who->name . " on map " |
|
|
65 | . $who->map->path . " for $value silver has no seller set\n" |
|
|
66 | unless $item->{seller}; |
|
|
67 | |
|
|
68 | $obs[0]->{sells}->{$item->{seller} || ''}->{$item->name} += $value; |
|
|
69 | |
|
|
70 | 1 and |
|
|
71 | warn "Object " . $item->name . " bought by " . $who->name . " on map " |
|
|
72 | . $who->map->path . " for $value silver sold by " . $item->{seller} . "\n"; |
|
|
73 | } |
|
|
74 | use Data::Dumper; |
|
|
75 | warn "DO[" .Data::Dumper::Dumper ([$obs[0]]) . "]\n"; |
37 | return 0; |
76 | return 0; |
38 | } |
77 | } |
39 | |
78 | |
40 | sub on_drop_on { |
79 | sub on_drop_on { |
41 | my ($ev, $on, $who, $what) = @_; |
80 | my ($ev, $on, $who, $what) = @_; |
… | |
… | |
43 | |
82 | |
44 | if ($what->get_flag (cf::FLAG_UNPAID)) { |
83 | if ($what->get_flag (cf::FLAG_UNPAID)) { |
45 | return 0; |
84 | return 0; |
46 | } |
85 | } |
47 | |
86 | |
|
|
87 | if (!$what->get_flag (cf::FLAG_IDENTIFIED)) { |
|
|
88 | $who->message ("The shopkeeper says: Sorry, i don't accept unidentified stuff."); |
|
|
89 | $what->insert_ob_in_ob ($who); |
|
|
90 | return 1; |
|
|
91 | } |
|
|
92 | |
48 | unless ($name =~ m/\d+\s*\S+/) { |
93 | unless ($name =~ m/\d+\s*\S+/) { |
49 | $who->message ("The shopkeeper says: Sorry, i don't recognize '$name' as currency. Please name your item like '10 royalty' or '10 platinum 2 silver'"); |
94 | $who->message ("The shopkeeper says: Sorry, i don't recognize '$name' as currency. Please name your item like '10 royalty' or '10 platinum 2 silver'", cf::NDI_BROWN); |
50 | $what->insert_ob_in_ob ($who); |
95 | $what->insert_ob_in_ob ($who); |
51 | return 1; |
96 | return 1; |
52 | } |
97 | } |
53 | |
98 | |
54 | my $value = 0; |
99 | my $value = 0; |
55 | while ($name =~ s/^\s*(\d+)\s*(\S+)//) { |
100 | while ($name =~ s/^\s*(\d+)\s*(\S+)//) { |
56 | if ($aliases{lc $2} or $unit{lc $2}) { |
101 | if ($aliases{lc $2} or $unit{lc $2}) { |
57 | $value += $1 * ($unit{lc $2} ? $unit{lc $2} : $unit{$aliases{lc $2}}); |
102 | $value += $1 * ($unit{lc $2} ? $unit{lc $2} : $unit{$aliases{lc $2}}); |
58 | } else { |
103 | } else { |
59 | $what->insert_ob_in_ob ($who); |
104 | $what->insert_ob_in_ob ($who); |
60 | $who->message ("The shopkeeper says: I don't know the currency '$2'"); |
105 | $who->message ("The shopkeeper says: I don't know the currency '$2'", cf::NDI_BROWN); |
61 | return 1; |
106 | return 1; |
62 | } |
107 | } |
63 | } |
108 | } |
64 | |
109 | |
|
|
110 | |
|
|
111 | my $nrof = $what->nrof; |
|
|
112 | $what->set_nrof (1); |
65 | $what->set_value ($value); |
113 | $what->set_value ($value); |
66 | my $cost = $what->query_cost ($who, cf::F_BUY | cf::F_SHOP); |
114 | my $cost = $what->query_cost ($who, cf::F_BUY | cf::F_SHOP); |
67 | |
115 | |
68 | if ($cost) { |
116 | if ($cost) { |
69 | my $fact = $value / $cost; |
117 | my $fact = $value / $cost; |
70 | $what->set_value (cf::ceil ($value * $fact)); |
118 | $what->set_value (cf::ceil ($value * $fact)); |
71 | } |
119 | } |
72 | |
120 | |
|
|
121 | $what->set_nrof ($nrof); |
|
|
122 | $who->message ("The shopkeeper says: Ok, I marked " . $what->nrof . " " . $what->name . " to sell for " . cf::cost_string_from_value ($value) . " a piece", cf::NDI_BROWN); |
73 | $what->set_flag (cf::FLAG_UNPAID, 1); |
123 | $what->set_flag (cf::FLAG_UNPAID, 1); |
74 | $what->{seller} = $who->name; |
124 | $what->{seller} = $who->name; |
75 | $what->set_custom_name (undef); |
125 | $what->set_custom_name (undef); |
76 | $what->insert_ob_in_map_at ($who->map, $who, cf::INS_BELOW_ORIGINATOR, $who->x, $who->y); |
126 | $what->insert_ob_in_map_at ($who->map, $who, cf::INS_BELOW_ORIGINATOR, $who->x, $who->y); |
77 | 1; |
127 | 1; |