ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/reseller.ext
(Generate patch)

Comparing deliantra/server/ext/reseller.ext (file contents):
Revision 1.9 by root, Wed Dec 5 11:08:34 2007 UTC vs.
Revision 1.11 by root, Thu Apr 10 15:35:16 2008 UTC

1#!perl # mandatory 1#!perl # mandatory
2
3my %unit = (
4 silver => 1,
5 gold => 10,
6 platina => 50,
7 royalty => 5000,
8);
9
10my %aliases = (
11 platinum => 'platina',
12 royalties => 'royalty',
13);
14 2
15sub ob2info { 3sub ob2info {
16 my ($item, $rval) = @_; 4 my ($item, $rval) = @_;
17 sprintf "[%s from %s (%d:%d%s) nrof: %d uuid: %s]", 5 sprintf "[%s from %s (%d:%d%s) nrof: %d uuid: %s]",
18 $item->name, $item->get_ob_key_value ('ext_reseller_seller'), 6 $item->name, $item->get_ob_key_value ('ext_reseller_seller'),
119 for my $item (find_unpaid ($who)) { 107 for my $item (find_unpaid ($who)) {
120 if ($item->get_ob_key_value ('ext_reseller_seller') eq $who->name) { 108 if ($item->get_ob_key_value ('ext_reseller_seller') eq $who->name) {
121 audit_log ($who, 'removes', ob2info ($item)); 109 audit_log ($who, 'removes', ob2info ($item));
122 $item->flag (cf::FLAG_UNPAID, 0); 110 $item->flag (cf::FLAG_UNPAID, 0);
123 $item->remove; 111 $item->remove;
124 $who->insert ($item); 112 give_back ($who, $item);
125 next; 113 next;
126 } 114 }
127 115
128 my $value = $item->query_cost ($who, cf::F_BUY | cf::F_SHOP); 116 my $value = $item->query_cost ($who, cf::F_BUY | cf::F_SHOP);
129 117
162 150
163 cf::override; 151 cf::override;
164 }, 152 },
165; 153;
166 154
155sub give_back {
156 my ($who, $what) = @_;
157 $who->insert ($what);
158 $who->esrv_send_item ($what);
159}
160
161sub give_back_with_message {
162 my ($who, $what, $msg) = @_;
163 $who->message ($msg, cf::NDI_BROWN);
164 give_back ($who, $what);
165}
166
167cf::object::attachment "reseller_floor", 167cf::object::attachment "reseller_floor",
168 on_drop_on => sub { 168 on_drop_on => sub {
169 my ($on, $what, $who) = @_; 169 my ($on, $what, $who) = @_;
170 my $name = $what->custom_name; 170 my $name = $what->custom_name;
171 171
172 return if $what->flag (cf::FLAG_UNPAID); 172 return if $what->flag (cf::FLAG_UNPAID);
173 173
174 if ($what->type == cf::MONEY) { 174 if ($what->type == cf::MONEY) {
175 give_back_with_message ($who, $what,
175 $who->message ("The shopkeeper says: Sorry, you can't sell money here.", cf::NDI_BROWN); 176 "The shopkeeper says: Sorry, you can't sell money here.");
176 $who->insert ($what);
177 return cf::override; 177 return cf::override;
178 } 178 }
179 179
180 if (!$what->flag (cf::FLAG_IDENTIFIED) && $what->need_identify) { 180 if (!$what->flag (cf::FLAG_IDENTIFIED) && $what->need_identify) {
181 give_back_with_message ($who, $what,
181 $who->message ("The shopkeeper says: Sorry, you can't sell unidentified stuff here.", cf::NDI_BROWN); 182 "The shopkeeper says: Sorry, you can't sell unidentified stuff here.");
182 $who->insert ($what);
183 return cf::override; 183 return cf::override;
184 } 184 }
185 185
186 my $orig_value = $what->value; 186 my $orig_value = $what->value;
187 my $value = 0; 187 my $value = 0;
188 188
189 if ($name =~ m/\S/) { 189 if ($name =~ m/\S/) {
190 unless ($name =~ m/\d+\s*\S+/) { 190 unless ($name =~ m/\d+\s*\S+/) {
191 $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); 191 give_back_with_message ($who, $what,
192 $who->insert ($what); 192 "The shopkeeper says: Sorry, I don't recognize '$name' as currency. "
193 . "Please name your item like '17 platinum' or '10 gold 8 silver'");
193 return cf::override; 194 return cf::override;
194 } 195 }
195 196
196 while ($name =~ s/^\s*(\d+)\s*(\S+)//) { 197 while ($name =~ s/^\s*(\d+)\s*(\S+)//) {
197 if ($aliases{lc $2} or $unit{lc $2}) { 198 my ($v, $c) = ($1, $2);
198 $value += $1 * ($unit{lc $2} ? $unit{lc $2} : $unit{$aliases{lc $2}}); 199 if (my $coin = cf::coin_from_name $c) {
200 $value += $v * $coin->value;
199 } else { 201 } else {
200 $who->insert ($what); 202 give_back_with_message ($who, $what,
201 $who->message ("The shopkeeper says: I don't know the currency '$2'", cf::NDI_BROWN); 203 "The shopkeeper says: I don't know the currency '$c', you can use one of these currencies: "
204 . (join ", ", cf::coin_names)
205 );
202 return cf::override; 206 return cf::override;
203 } 207 }
204 } 208 }
205 } else { 209 } else {
210 # commented out the following line because too many just use the
211 # reseller shop as dumpyard:
206 $value = $what->query_cost ($who, cf::F_SELL | cf::F_SHOP) / ($what->nrof || 1); 212 # $value = $what->query_cost ($who, cf::F_SELL | cf::F_SHOP) / ($what->nrof || 1);
213 give_back_with_message ($who, $what,
214 "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' "
216 . "and drop it again. (To rename the item use the 'rename' "
217 . "context menu item in the inventory)."
218 );
219 return cf::override;
207 } 220 }
208 221
209 if ($value < 0) { 222 if ($value < 0) {
210 $who->insert ($what); 223 give_back_with_message ($who, $what,
211 $who->message ("The shopkeeper says: You can't sell something for a negative value: $value", cf::NDI_BROWN); 224 "The shopkeeper says: You can't sell something for a negative value: $value");
212 return cf::override; 225 return cf::override;
213 } 226 }
214 227
215 my $fee = $value / 100; # 1% selling fee 228 my $fee = $value / 100; # 1% selling fee
216 229
217 unless ($who->pay_amount ($fee)) { 230 unless ($who->pay_amount ($fee)) {
218 $who->message ( 231 give_back_with_message ($who, $what,
219 "The shopkeeper says: You need " . cf::cost_string_from_value ($fee) . " to pay the 1% fee for this item", 232 "The shopkeeper says: You need " . cf::cost_string_from_value ($fee)
220 cf::NDI_BROWN 233 . " to pay the 1% fee for this item");
221 );
222 $who->insert ($what);
223 return cf::override; 234 return cf::override;
224 } else { 235 } else {
225 $who->message ( 236 $who->message (
226 "The shopkeeper says: Ok, got the fee of " . cf::cost_string_from_value ($fee) . " for the item", 237 "The shopkeeper says: Ok, got the fee of " . cf::cost_string_from_value ($fee)
238 . " for the item",
227 cf::NDI_BROWN 239 cf::NDI_BROWN
228 ); 240 );
229 } 241 }
230 242
231 $what->value ($value); 243 $what->value ($value);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines