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.7 by root, Mon Jun 11 21:38:13 2007 UTC vs.
Revision 1.9 by root, Wed Dec 5 11:08:34 2007 UTC

52} 52}
53 53
54cf::register_script_function "reseller::list_sells" => sub { 54cf::register_script_function "reseller::list_sells" => sub {
55 my ($who, $msg, $npc) = @_; 55 my ($who, $msg, $npc) = @_;
56 my $ext_re_sales = $npc->get_ob_key_value ('ext_reseller_sales'); 56 my $ext_re_sales = $npc->get_ob_key_value ('ext_reseller_sales');
57 my $sells = $ext_re_sales && cf::from_json $ext_re_sales; 57 my $sells = $ext_re_sales && cf::decode_json $ext_re_sales;
58 my $hissells = $sells->{$who->name}; 58 my $hissells = $sells->{$who->name};
59 59
60 unless (keys %{$hissells || {}}) { 60 unless (keys %{$hissells || {}}) {
61 $who->reply ($npc, "I'm sorry, but you sold nothing.\n"); 61 $who->reply ($npc, "I'm sorry, but you sold nothing.\n");
62 return 0; 62 return 0;
73}; 73};
74 74
75cf::register_script_function "reseller::pay_player" => sub { 75cf::register_script_function "reseller::pay_player" => sub {
76 my ($who, $msg, $npc) = @_; 76 my ($who, $msg, $npc) = @_;
77 my $ext_re_sales = $npc->get_ob_key_value ('ext_reseller_sales'); 77 my $ext_re_sales = $npc->get_ob_key_value ('ext_reseller_sales');
78 my $sells = $ext_re_sales && cf::from_json $ext_re_sales; 78 my $sells = $ext_re_sales && cf::decode_json $ext_re_sales;
79 my $hissells = $sells->{$who->name}; 79 my $hissells = $sells->{$who->name};
80 80
81 unless (keys %{$hissells || {}}) { 81 unless (keys %{$hissells || {}}) {
82 $who->reply ($npc, "I'm sorry, but you sold nothing.\n"); 82 $who->reply ($npc, "I'm sorry, but you sold nothing.\n");
83 return 0; 83 return 0;
91 91
92 audit_log ($who, 'collects', "$sum silver"); 92 audit_log ($who, 'collects', "$sum silver");
93 93
94 $sells->{$who->name} = {}; 94 $sells->{$who->name} = {};
95 95
96 $npc->set_ob_key_value (ext_reseller_sales => cf::to_json $sells) 96 $npc->set_ob_key_value (ext_reseller_sales => cf::encode_json $sells)
97 if $sells; 97 if $sells;
98 98
99 0 99 0
100}; 100};
101 101
110 warn "Couldn't find shop keeper in " . $who->map->path . "\n"; 110 warn "Couldn't find shop keeper in " . $who->map->path . "\n";
111 return cf::override; 111 return cf::override;
112 } 112 }
113 113
114 my $ext_re_sales = $obs[0]->get_ob_key_value ('ext_reseller_sales'); 114 my $ext_re_sales = $obs[0]->get_ob_key_value ('ext_reseller_sales');
115 my $sells = $ext_re_sales && cf::from_json $ext_re_sales; 115 my $sells = $ext_re_sales && cf::decode_json $ext_re_sales;
116 116
117 my $unpaid_items = {}; 117 my $unpaid_items = {};
118 118
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 $item->insert_ob_in_ob ($who); 124 $who->insert ($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
155 } 155 }
156 156
157 audit_log ($who, 'removed', (join ",", @seller_noted)) 157 audit_log ($who, 'removed', (join ",", @seller_noted))
158 if @seller_noted; 158 if @seller_noted;
159 159
160 $obs[0]->set_ob_key_value (ext_reseller_sales => cf::to_json $sells) 160 $obs[0]->set_ob_key_value (ext_reseller_sales => cf::encode_json $sells)
161 if $sells; 161 if $sells;
162 162
163 cf::override; 163 cf::override;
164 }, 164 },
165; 165;
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 $who->message ("The shopkeeper says: Sorry, you can't sell money here.", cf::NDI_BROWN); 175 $who->message ("The shopkeeper says: Sorry, you can't sell money here.", cf::NDI_BROWN);
176 $what->insert_ob_in_ob ($who); 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 $who->message ("The shopkeeper says: Sorry, you can't sell unidentified stuff here.", cf::NDI_BROWN); 181 $who->message ("The shopkeeper says: Sorry, you can't sell unidentified stuff here.", cf::NDI_BROWN);
182 $what->insert_ob_in_ob ($who); 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 $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);
192 $what->insert_ob_in_ob ($who); 192 $who->insert ($what);
193 return cf::override; 193 return cf::override;
194 } 194 }
195 195
196 while ($name =~ s/^\s*(\d+)\s*(\S+)//) { 196 while ($name =~ s/^\s*(\d+)\s*(\S+)//) {
197 if ($aliases{lc $2} or $unit{lc $2}) { 197 if ($aliases{lc $2} or $unit{lc $2}) {
198 $value += $1 * ($unit{lc $2} ? $unit{lc $2} : $unit{$aliases{lc $2}}); 198 $value += $1 * ($unit{lc $2} ? $unit{lc $2} : $unit{$aliases{lc $2}});
199 } else { 199 } else {
200 $what->insert_ob_in_ob ($who); 200 $who->insert ($what);
201 $who->message ("The shopkeeper says: I don't know the currency '$2'", cf::NDI_BROWN); 201 $who->message ("The shopkeeper says: I don't know the currency '$2'", cf::NDI_BROWN);
202 return cf::override; 202 return cf::override;
203 } 203 }
204 } 204 }
205 } else { 205 } else {
206 $value = $what->query_cost ($who, cf::F_SELL | cf::F_SHOP) / ($what->nrof || 1); 206 $value = $what->query_cost ($who, cf::F_SELL | cf::F_SHOP) / ($what->nrof || 1);
207 } 207 }
208 208
209 if ($value < 0) { 209 if ($value < 0) {
210 $what->insert_ob_in_ob ($who); 210 $who->insert ($what);
211 $who->message ("The shopkeeper says: You can't sell something for a negative value: $value", cf::NDI_BROWN); 211 $who->message ("The shopkeeper says: You can't sell something for a negative value: $value", cf::NDI_BROWN);
212 return cf::override; 212 return cf::override;
213 } 213 }
214 214
215 my $fee = $value / 100; # 1% selling fee 215 my $fee = $value / 100; # 1% selling fee
217 unless ($who->pay_amount ($fee)) { 217 unless ($who->pay_amount ($fee)) {
218 $who->message ( 218 $who->message (
219 "The shopkeeper says: You need " . cf::cost_string_from_value ($fee) . " to pay the 1% fee for this item", 219 "The shopkeeper says: You need " . cf::cost_string_from_value ($fee) . " to pay the 1% fee for this item",
220 cf::NDI_BROWN 220 cf::NDI_BROWN
221 ); 221 );
222 $what->insert_ob_in_ob ($who); 222 $who->insert ($what);
223 return cf::override; 223 return cf::override;
224 } else { 224 } else {
225 $who->message ( 225 $who->message (
226 "The shopkeeper says: Ok, got the fee of " . cf::cost_string_from_value ($fee) . " for the item", 226 "The shopkeeper says: Ok, got the fee of " . cf::cost_string_from_value ($fee) . " for the item",
227 cf::NDI_BROWN 227 cf::NDI_BROWN

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines