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

Comparing deliantra/maps/perl/reseller.ext (file contents):
Revision 1.7 by elmex, Tue Aug 15 16:51:59 2006 UTC vs.
Revision 1.10 by root, Sun Aug 27 15:23:59 2006 UTC

77 $npc->set_ob_key_value (ext_reseller_sales => cf::to_json $sells); 77 $npc->set_ob_key_value (ext_reseller_sales => cf::to_json $sells);
78 78
79 0 79 0
80}; 80};
81 81
82sub on_trigger { 82cf::register_attachment "reseller_shopmat",
83 on_move_trigger => sub {
83 my ($ev, $ob, $who_caused, $who) = @_; 84 my ($self, $who_caused, $who) = @_;
84 my $opt = $ev->options;
85 return 1 unless $opt =~ m/(\S+),(\d+),(\d+)/;
86 85
87 my @obs = grep { $_->name eq $1 } $who->map->at ($2, $3); 86 my @obs = grep { $_->name eq $self->{reseller_shopmat}{npc_name} }
87 $who->map->at ($self->{reseller_shopmat}{npc_x}, $self->{reseller_shopmat}{npc_y});
88
88 unless (@obs) { 89 unless (@obs) {
89 warn "Couldn't find shop keeper in " . $who->map . "\n"; 90 warn "Couldn't find shop keeper in " . $who->map . "\n";
90 return 1; 91 return cf::override;
91 } 92 }
92 93
93 my $sells = cf::from_json $obs[0]->get_ob_key_value ('ext_reseller_sales'); 94 my $sells = cf::from_json $obs[0]->get_ob_key_value ('ext_reseller_sales');
94 95
95 for my $item (find_unpaid ($who)) { 96 for my $item (find_unpaid ($who)) {
96 if ($item->get_ob_key_value ('ext_reseller_seller') eq $who->name) { 97 if ($item->get_ob_key_value ('ext_reseller_seller') eq $who->name) {
97 $item->set_flag (cf::FLAG_UNPAID, 0); 98 $item->set_flag (cf::FLAG_UNPAID, 0);
98 $item->remove; 99 $item->remove;
99 $item->insert_ob_in_ob ($who); 100 $item->insert_ob_in_ob ($who);
100 next; 101 next;
101 } 102 }
102 103
103 my $value = $item->query_cost ($who, cf::F_BUY | cf::F_SHOP); 104 my $value = $item->query_cost ($who, cf::F_BUY | cf::F_SHOP);
104 105
105 warn "Object " . $item->name . " bought by " . $who->name . " on map " 106 warn "Object " . $item->name . " bought by " . $who->name . " on map "
106 . $who->map->path . " for $value silver has no seller set\n" 107 . $who->map->path . " for $value silver has no seller set\n"
107 unless $item->get_ob_key_value ('ext_reseller_seller') ne ''; 108 if $item->get_ob_key_value ('ext_reseller_seller') eq '';
108 109
109 $sells->{$item->get_ob_key_value ('ext_reseller_seller')}->{$item->name} += $value; 110 $sells->{$item->get_ob_key_value ('ext_reseller_seller')}->{$item->name} += $value;
110 } 111 }
111 112
112 $ob->apply_shop_mat ($who); 113 $self->apply_shop_mat ($who);
113 114
114 for my $item (find_traded ($who)) { 115 for my $item (find_traded ($who)) {
115 next if $item->get_flag (cf::FLAG_UNPAID); 116 next if $item->get_flag (cf::FLAG_UNPAID);
116 $item->set_value ($item->get_ob_key_value ('ext_reseller_orig_value')); 117 $item->set_value ($item->get_ob_key_value ('ext_reseller_orig_value'));
117 $item->set_ob_key_value (ext_reseller_seller => ''); 118 $item->set_ob_key_value (ext_reseller_seller => '');
118 } 119 }
119 120
120 $obs[0]->set_ob_key_value (ext_reseller_sales => cf::to_json $sells); 121 $obs[0]->set_ob_key_value (ext_reseller_sales => cf::to_json $sells);
122 },
123;
121 124
122 return 0; 125cf::register "reseller_floor",
123} 126 on_drop_on => sub {
124 127 my ($on, $what, $who) = @_;
125sub on_drop_on {
126 my ($ev, $on, $who, $what) = @_;
127 my $name = $what->custom_name; 128 my $name = $what->custom_name;
128 129
129 if ($what->get_flag (cf::FLAG_UNPAID)) { 130 return if $what->get_flag (cf::FLAG_UNPAID);
130 return 0;
131 }
132 131
133 if ($what->type == cf::MONEY) { 132 if ($what->type == cf::MONEY) {
134 $who->message ("The shopkeeper says: Sorry, you can't sell money here.", cf::NDI_BROWN); 133 $who->message ("The shopkeeper says: Sorry, you can't sell money here.", cf::NDI_BROWN);
135 $what->insert_ob_in_ob ($who); 134 $what->insert_ob_in_ob ($who);
136 return 1; 135 return cf::override;
137 } 136 }
138 137
139 if (!$what->get_flag (cf::FLAG_IDENTIFIED) && $what->need_identify) { 138 if (!$what->get_flag (cf::FLAG_IDENTIFIED) && $what->need_identify) {
140 $who->message ("The shopkeeper says: Sorry, you can't sell unidentified stuff here.", cf::NDI_BROWN); 139 $who->message ("The shopkeeper says: Sorry, you can't sell unidentified stuff here.", cf::NDI_BROWN);
141 $what->insert_ob_in_ob ($who); 140 $what->insert_ob_in_ob ($who);
142 return 1; 141 return cf::override;
143 } 142 }
144 143
145 my $orig_value = $what->value; 144 my $orig_value = $what->value;
146 my $value = 0; 145 my $value = 0;
147 146
148 if ($name =~ m/\S/) { 147 if ($name =~ m/\S/) {
149 unless ($name =~ m/\d+\s*\S+/) { 148 unless ($name =~ m/\d+\s*\S+/) {
150 $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); 149 $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);
151 $what->insert_ob_in_ob ($who);
152 return 1;
153 }
154
155 while ($name =~ s/^\s*(\d+)\s*(\S+)//) {
156 if ($aliases{lc $2} or $unit{lc $2}) {
157 $value += $1 * ($unit{lc $2} ? $unit{lc $2} : $unit{$aliases{lc $2}});
158 } else {
159 $what->insert_ob_in_ob ($who); 150 $what->insert_ob_in_ob ($who);
160 $who->message ("The shopkeeper says: I don't know the currency '$2'", cf::NDI_BROWN);
161 return 1; 151 return cf::override;
162 } 152 }
153
154 while ($name =~ s/^\s*(\d+)\s*(\S+)//) {
155 if ($aliases{lc $2} or $unit{lc $2}) {
156 $value += $1 * ($unit{lc $2} ? $unit{lc $2} : $unit{$aliases{lc $2}});
157 } else {
158 $what->insert_ob_in_ob ($who);
159 $who->message ("The shopkeeper says: I don't know the currency '$2'", cf::NDI_BROWN);
160 return cf::override;
161 }
163 } 162 }
164 } else { 163 } else {
165 $value = $what->query_cost ($who, cf::F_SELL | cf::F_SHOP) / ($what->nrof || 1); 164 $value = $what->query_cost ($who, cf::F_SELL | cf::F_SHOP) / ($what->nrof || 1);
166 } 165 }
167 166
168 if ($value < 0) { 167 if ($value < 0) {
169 $what->insert_ob_in_ob ($who); 168 $what->insert_ob_in_ob ($who);
170 $who->message ("The shopkeeper says: You can't sell something for a negative value: $value", cf::NDI_BROWN); 169 $who->message ("The shopkeeper says: You can't sell something for a negative value: $value", cf::NDI_BROWN);
171 return 1; 170 return cf::override;
172 } 171 }
173 172
174 my $fee = $value / 100; # 1% selling fee 173 my $fee = $value / 100; # 1% selling fee
175 174
176 unless ($who->pay_amount ($fee)) { 175 unless ($who->pay_amount ($fee)) {
177 $who->message ( 176 $who->message (
178 "The shopkeeper says: You need " . cf::cost_string_from_value ($fee) . " to pay the 1% fee for this item", 177 "The shopkeeper says: You need " . cf::cost_string_from_value ($fee) . " to pay the 1% fee for this item",
179 cf::NDI_BROWN 178 cf::NDI_BROWN
180 ); 179 );
181 $what->insert_ob_in_ob ($who); 180 $what->insert_ob_in_ob ($who);
182 return 1; 181 return cf::override;
183 } else { 182 } else {
184 $who->message ( 183 $who->message (
185 "The shopkeeper says: Ok, got the fee of " . cf::cost_string_from_value ($fee) . " for the item", 184 "The shopkeeper says: Ok, got the fee of " . cf::cost_string_from_value ($fee) . " for the item",
186 cf::NDI_BROWN 185 cf::NDI_BROWN
187 ); 186 );
188 } 187 }
189 188
190
191 $what->set_value ($value); 189 $what->set_value ($value);
192 my $cost = $what->query_cost ($who, cf::F_BUY | cf::F_SHOP) / ($what->nrof || 1); 190 my $cost = $what->query_cost ($who, cf::F_BUY | cf::F_SHOP) / ($what->nrof || 1);
193 191
194 my $fact = 0; 192 my $fact = 0;
195 if ($cost) { 193 if ($cost) {
196 $fact = $value / $cost; 194 $fact = $value / $cost;
197 $what->set_value (cf::ceil ($value * $fact)); 195 $what->set_value (cf::ceil ($value * $fact));
198 } 196 }
199 197
200# warn "END VALUE: $value * $fact => " . $what->value . "\n"; 198# warn "END VALUE: $value * $fact => " . $what->value . "\n";
201 199
202# my $cost = $what->query_cost ($who, cf::F_BUY | cf::F_SHOP) / $what->nrof; 200# my $cost = $what->query_cost ($who, cf::F_BUY | cf::F_SHOP) / $what->nrof;
203# warn "COSTS NOW: $cost\n"; 201# warn "COSTS NOW: $cost\n";
204 202
205 $who->message ( 203 $who->message (
206 "The shopkeeper says: Ok, I marked " 204 "The shopkeeper says: Ok, I marked "
207 . ($what->nrof || 1) . " " . $what->name . " to be sold for at least " 205 . ($what->nrof || 1) . " " . $what->name . " to be sold for at least "
208 . cf::cost_string_from_value ($value) 206 . cf::cost_string_from_value ($value)
209 . ($what->nrof > 1 ? " each" : ""), cf::NDI_BROWN 207 . ($what->nrof > 1 ? " each" : ""), cf::NDI_BROWN
210 ); 208 );
211 209
212 $what->set_ob_key_value (ext_reseller_seller => $who->name); 210 $what->set_ob_key_value (ext_reseller_seller => $who->name);
213 $what->set_ob_key_value (ext_reseller_orig_value => $orig_value); 211 $what->set_ob_key_value (ext_reseller_orig_value => $orig_value);
214# warn "SET SELLER ON " . $what->name . " + " . $what->{seller}->[0] . "\n"; 212# warn "SET SELLER ON " . $what->name . " + " . $what->{seller}->[0] . "\n";
215 $what->set_custom_name ( 213 $what->set_custom_name (
216 $what->name . " (by " . $who->name . ")" 214 $what->name . " (by " . $who->name . ")"
217 ); 215 );
218 $what->set_flag (cf::FLAG_UNPAID, 1); 216 $what->set_flag (cf::FLAG_UNPAID, 1);
219 $what->insert_ob_in_map_at ($who->map, $who, cf::INS_BELOW_ORIGINATOR, $who->x, $who->y); 217 $what->insert_ob_in_map_at ($who->map, $who, cf::INS_BELOW_ORIGINATOR, $who->x, $who->y);
220 1; 218
221} 219 cf::override;
220 },
221;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines