… | |
… | |
48 | unless (keys %{$hissells || {}}) { |
48 | unless (keys %{$hissells || {}}) { |
49 | $who->reply ($npc, "I'm sorry, but you sold nothing.\n"); |
49 | $who->reply ($npc, "I'm sorry, but you sold nothing.\n"); |
50 | return 0; |
50 | return 0; |
51 | } |
51 | } |
52 | |
52 | |
53 | $who->reply ($npc, "You sold:\n", cf::NDI_BROWN); |
53 | my $reply = "T<You sold:>\n\n"; |
|
|
54 | |
54 | for (keys %$hissells) { |
55 | for (keys %$hissells) { |
55 | my $n = $_; |
56 | my $n = $_; |
56 | $n =~ s/\s*\(unpaid\)//g; |
57 | $n =~ s/\s*\(unpaid\)//g; |
57 | $who->reply ($npc, "$n for " . cf::cost_string_from_value ($hissells->{$_}), cf::NDI_BROWN); |
58 | $reply .= " B<$n> (for " . cf::cost_string_from_value ($hissells->{$_}) . ")\n"; |
58 | } |
59 | } |
|
|
60 | |
|
|
61 | $who->reply ($npc, $reply); |
59 | |
62 | |
60 | 0 |
63 | 0 |
61 | }; |
64 | }; |
62 | |
65 | |
63 | cf::register_script_function "reseller::pay_player" => sub { |
66 | cf::register_script_function "reseller::pay_player" => sub { |
… | |
… | |
73 | |
76 | |
74 | my $sum = 0; |
77 | my $sum = 0; |
75 | $sum += $_ for values %$hissells; |
78 | $sum += $_ for values %$hissells; |
76 | |
79 | |
77 | $who->pay_player ($sum); |
80 | $who->pay_player ($sum); |
78 | $who->reply ($npc, "Here are the " . cf::cost_string_from_value ($sum) . " for your sales"); |
81 | $who->reply ($npc, "Here are the " . cf::cost_string_from_value ($sum) . " for your sales."); |
79 | |
82 | |
80 | audit_log ($who, 'collects', "$sum silver"); |
83 | audit_log ($who, 'collects', "$sum silver"); |
81 | |
84 | |
82 | $sells->{$who->name} = {}; |
85 | $sells->{$who->name} = {}; |
83 | |
86 | |
… | |
… | |
153 | ; |
156 | ; |
154 | |
157 | |
155 | sub give_back { |
158 | sub give_back { |
156 | my ($who, $what) = @_; |
159 | my ($who, $what) = @_; |
157 | $who->insert ($what); |
160 | $who->insert ($what); |
158 | $who->esrv_send_item ($what); |
|
|
159 | } |
161 | } |
160 | |
162 | |
161 | sub give_back_with_message { |
163 | sub give_back_with_message { |
162 | my ($who, $what, $msg) = @_; |
164 | my ($who, $what, $msg) = @_; |
163 | $who->message ($msg, cf::NDI_BROWN); |
165 | $who->message ($msg, cf::NDI_BROWN); |
… | |
… | |
188 | |
190 | |
189 | if ($name =~ m/\S/) { |
191 | if ($name =~ m/\S/) { |
190 | unless ($name =~ m/\d+\s*\S+/) { |
192 | unless ($name =~ m/\d+\s*\S+/) { |
191 | give_back_with_message ($who, $what, |
193 | give_back_with_message ($who, $what, |
192 | "The shopkeeper says: Sorry, I don't recognize '$name' as currency. " |
194 | "The shopkeeper says: Sorry, I don't recognize '$name' as currency. " |
193 | . "Please name your item like '17 platinum' or '10 gold 8 silver'"); |
195 | . "Please name your item like '17 platinum' or '10 gold 8 silver.'"); |
194 | return cf::override; |
196 | return cf::override; |
195 | } |
197 | } |
196 | |
198 | |
197 | while ($name =~ s/^\s*(\d+)\s*(\S+)//) { |
199 | while ($name =~ s/^\s*(\d+)\s*(\S+)//) { |
198 | my ($v, $c) = ($1, $2); |
200 | my ($v, $c) = ($1, $2); |
… | |
… | |
211 | # reseller shop as dumpyard: |
213 | # reseller shop as dumpyard: |
212 | # $value = $what->query_cost ($who, cf::F_SELL | cf::F_SHOP) / ($what->nrof || 1); |
214 | # $value = $what->query_cost ($who, cf::F_SELL | cf::F_SHOP) / ($what->nrof || 1); |
213 | give_back_with_message ($who, $what, |
215 | give_back_with_message ($who, $what, |
214 | "Sorry, you can't just sell stuff without assigning a price to it! " |
216 | "Sorry, you can't just sell stuff without assigning a price to it! " |
215 | . "Please name your item like '17 platinum' or '10 gold 8 silver' " |
217 | . "Please name your item like '17 platinum' or '10 gold 8 silver' " |
216 | . "and drop it again. (To rename the item use the 'rename' " |
218 | . "and drop it again. (To rename the item use the B<rename> " |
217 | . "context menu item in the inventory)." |
219 | . "entry in the inventory item popup menu)." |
218 | ); |
220 | ); |
219 | return cf::override; |
221 | return cf::override; |
220 | } |
222 | } |
221 | |
223 | |
222 | if ($value < 0) { |
224 | if ($value < 0) { |
223 | give_back_with_message ($who, $what, |
225 | give_back_with_message ($who, $what, |
224 | "The shopkeeper says: You can't sell something for a negative value: $value"); |
226 | "The shopkeeper says: You can't sell something for a negative value: $value."); |
225 | return cf::override; |
227 | return cf::override; |
226 | } |
228 | } |
227 | |
229 | |
228 | my $fee = $value / 100; # 1% selling fee |
230 | my $fee = $value / 100; # 1% selling fee |
229 | |
231 | |
230 | unless ($who->pay_amount ($fee)) { |
232 | unless ($who->pay_amount ($fee)) { |
231 | give_back_with_message ($who, $what, |
233 | give_back_with_message ($who, $what, |
232 | "The shopkeeper says: You need " . cf::cost_string_from_value ($fee) |
234 | "The shopkeeper says: You need " . cf::cost_string_from_value ($fee) |
233 | . " to pay the 1% fee for this item"); |
235 | . " to pay the 1% fee for this item."); |
234 | return cf::override; |
236 | return cf::override; |
235 | } else { |
237 | } else { |
236 | $who->message ( |
238 | $who->message ( |
237 | "The shopkeeper says: Ok, got the fee of " . cf::cost_string_from_value ($fee) |
239 | "The shopkeeper says: Ok, got the fee of " . cf::cost_string_from_value ($fee) |
238 | . " for the item", |
240 | . " for the item.", |
239 | cf::NDI_BROWN |
241 | cf::NDI_BROWN |
240 | ); |
242 | ); |
241 | } |
243 | } |
242 | |
244 | |
243 | $what->value ($value); |
245 | $what->value ($value); |