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.10 by elmex, Mon Dec 24 16:41:55 2007 UTC

119 for my $item (find_unpaid ($who)) { 119 for my $item (find_unpaid ($who)) {
120 if ($item->get_ob_key_value ('ext_reseller_seller') eq $who->name) { 120 if ($item->get_ob_key_value ('ext_reseller_seller') eq $who->name) {
121 audit_log ($who, 'removes', ob2info ($item)); 121 audit_log ($who, 'removes', ob2info ($item));
122 $item->flag (cf::FLAG_UNPAID, 0); 122 $item->flag (cf::FLAG_UNPAID, 0);
123 $item->remove; 123 $item->remove;
124 $who->insert ($item); 124 give_back ($who, $item);
125 next; 125 next;
126 } 126 }
127 127
128 my $value = $item->query_cost ($who, cf::F_BUY | cf::F_SHOP); 128 my $value = $item->query_cost ($who, cf::F_BUY | cf::F_SHOP);
129 129
162 162
163 cf::override; 163 cf::override;
164 }, 164 },
165; 165;
166 166
167sub give_back {
168 my ($who, $what) = @_;
169 $who->insert ($what);
170 $who->esrv_send_item ($what);
171}
172
173sub give_back_with_message {
174 my ($who, $what, $msg) = @_;
175 $who->message ($msg, cf::NDI_BROWN);
176 give_back ($who, $what);
177}
178
167cf::object::attachment "reseller_floor", 179cf::object::attachment "reseller_floor",
168 on_drop_on => sub { 180 on_drop_on => sub {
169 my ($on, $what, $who) = @_; 181 my ($on, $what, $who) = @_;
170 my $name = $what->custom_name; 182 my $name = $what->custom_name;
171 183
172 return if $what->flag (cf::FLAG_UNPAID); 184 return if $what->flag (cf::FLAG_UNPAID);
173 185
174 if ($what->type == cf::MONEY) { 186 if ($what->type == cf::MONEY) {
187 give_back_with_message ($who, $what,
175 $who->message ("The shopkeeper says: Sorry, you can't sell money here.", cf::NDI_BROWN); 188 "The shopkeeper says: Sorry, you can't sell money here.");
176 $who->insert ($what);
177 return cf::override; 189 return cf::override;
178 } 190 }
179 191
180 if (!$what->flag (cf::FLAG_IDENTIFIED) && $what->need_identify) { 192 if (!$what->flag (cf::FLAG_IDENTIFIED) && $what->need_identify) {
193 give_back_with_message ($who, $what,
181 $who->message ("The shopkeeper says: Sorry, you can't sell unidentified stuff here.", cf::NDI_BROWN); 194 "The shopkeeper says: Sorry, you can't sell unidentified stuff here.");
182 $who->insert ($what);
183 return cf::override; 195 return cf::override;
184 } 196 }
185 197
186 my $orig_value = $what->value; 198 my $orig_value = $what->value;
187 my $value = 0; 199 my $value = 0;
188 200
189 if ($name =~ m/\S/) { 201 if ($name =~ m/\S/) {
190 unless ($name =~ m/\d+\s*\S+/) { 202 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); 203 give_back_with_message ($who, $what,
192 $who->insert ($what); 204 "The shopkeeper says: Sorry, I don't recognize '$name' as currency. "
205 ."Please name your item like '10 royalty' or '10 platinum 2 silver'");
193 return cf::override; 206 return cf::override;
194 } 207 }
195 208
196 while ($name =~ s/^\s*(\d+)\s*(\S+)//) { 209 while ($name =~ s/^\s*(\d+)\s*(\S+)//) {
197 if ($aliases{lc $2} or $unit{lc $2}) { 210 if ($aliases{lc $2} or $unit{lc $2}) {
198 $value += $1 * ($unit{lc $2} ? $unit{lc $2} : $unit{$aliases{lc $2}}); 211 $value += $1 * ($unit{lc $2} ? $unit{lc $2} : $unit{$aliases{lc $2}});
199 } else { 212 } else {
200 $who->insert ($what); 213 give_back_with_message ($who, $what,
201 $who->message ("The shopkeeper says: I don't know the currency '$2'", cf::NDI_BROWN); 214 "The shopkeeper says: I don't know the currency '$2', you can use one of these currencies: ".join (", ", keys %unit)." or also: ".join (", ", keys %aliases));
202 return cf::override; 215 return cf::override;
203 } 216 }
204 } 217 }
205 } else { 218 } else {
219 # commented out the following line because too many just use the
220 # reseller shop as dumpyard:
206 $value = $what->query_cost ($who, cf::F_SELL | cf::F_SHOP) / ($what->nrof || 1); 221 # $value = $what->query_cost ($who, cf::F_SELL | cf::F_SHOP) / ($what->nrof || 1);
222 give_back_with_message ($who, $what,
223 "Sorry, you can't just sell stuff without assigning a price to it! "
224 ."Please name your item like '10 royalty' or '10 platinum 2 silver' "
225 ."and drop it again. (To rename the item use the 'rename' "
226 ."context menu item in the inventory).");
227 return cf::override;
207 } 228 }
208 229
209 if ($value < 0) { 230 if ($value < 0) {
210 $who->insert ($what); 231 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); 232 "The shopkeeper says: You can't sell something for a negative value: $value");
212 return cf::override; 233 return cf::override;
213 } 234 }
214 235
215 my $fee = $value / 100; # 1% selling fee 236 my $fee = $value / 100; # 1% selling fee
216 237
217 unless ($who->pay_amount ($fee)) { 238 unless ($who->pay_amount ($fee)) {
218 $who->message ( 239 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", 240 "The shopkeeper says: You need " . cf::cost_string_from_value ($fee)
220 cf::NDI_BROWN 241 . " to pay the 1% fee for this item");
221 );
222 $who->insert ($what);
223 return cf::override; 242 return cf::override;
224 } else { 243 } else {
225 $who->message ( 244 $who->message (
226 "The shopkeeper says: Ok, got the fee of " . cf::cost_string_from_value ($fee) . " for the item", 245 "The shopkeeper says: Ok, got the fee of " . cf::cost_string_from_value ($fee)
246 . " for the item",
227 cf::NDI_BROWN 247 cf::NDI_BROWN
228 ); 248 );
229 } 249 }
230 250
231 $what->value ($value); 251 $what->value ($value);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines