… | |
… | |
24 | return @unpaid; |
24 | return @unpaid; |
25 | } |
25 | } |
26 | |
26 | |
27 | sub find_unpaid { |
27 | sub find_unpaid { |
28 | my ($ob) = @_; |
28 | my ($ob) = @_; |
29 | my @r = find_rec ($ob, sub { $_[0]->get_flag (cf::FLAG_UNPAID) }); |
29 | my @r = find_rec ($ob, sub { $_[0]->flag (cf::FLAG_UNPAID) }); |
30 | return @r; |
30 | return @r; |
31 | } |
31 | } |
32 | |
32 | |
33 | sub find_traded { |
33 | sub find_traded { |
34 | my ($ob) = @_; |
34 | my ($ob) = @_; |
… | |
… | |
93 | |
93 | |
94 | 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'); |
95 | |
95 | |
96 | for my $item (find_unpaid ($who)) { |
96 | for my $item (find_unpaid ($who)) { |
97 | 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) { |
98 | $item->set_flag (cf::FLAG_UNPAID, 0); |
98 | $item->flag (cf::FLAG_UNPAID, 0); |
99 | $item->remove; |
99 | $item->remove; |
100 | $item->insert_ob_in_ob ($who); |
100 | $item->insert_ob_in_ob ($who); |
101 | next; |
101 | next; |
102 | } |
102 | } |
103 | |
103 | |
… | |
… | |
111 | } |
111 | } |
112 | |
112 | |
113 | $self->apply_shop_mat ($who); |
113 | $self->apply_shop_mat ($who); |
114 | |
114 | |
115 | for my $item (find_traded ($who)) { |
115 | for my $item (find_traded ($who)) { |
116 | next if $item->get_flag (cf::FLAG_UNPAID); |
116 | next if $item->flag (cf::FLAG_UNPAID); |
117 | $item->set_value ($item->get_ob_key_value ('ext_reseller_orig_value')); |
117 | $item->value ($item->get_ob_key_value ('ext_reseller_orig_value')); |
118 | $item->set_ob_key_value (ext_reseller_seller => ''); |
118 | $item->set_ob_key_value (ext_reseller_seller => ''); |
119 | } |
119 | } |
120 | |
120 | |
121 | $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 | cf::override; |
122 | }, |
124 | }, |
123 | ; |
125 | ; |
124 | |
126 | |
125 | cf::register_attachment "reseller_floor", |
127 | cf::register_attachment "reseller_floor", |
126 | on_drop_on => sub { |
128 | on_drop_on => sub { |
127 | my ($on, $what, $who) = @_; |
129 | my ($on, $what, $who) = @_; |
128 | my $name = $what->custom_name; |
130 | my $name = $what->custom_name; |
129 | |
131 | |
130 | return if $what->get_flag (cf::FLAG_UNPAID); |
132 | return if $what->flag (cf::FLAG_UNPAID); |
131 | |
133 | |
132 | if ($what->type == cf::MONEY) { |
134 | if ($what->type == cf::MONEY) { |
133 | $who->message ("The shopkeeper says: Sorry, you can't sell money here.", cf::NDI_BROWN); |
135 | $who->message ("The shopkeeper says: Sorry, you can't sell money here.", cf::NDI_BROWN); |
134 | $what->insert_ob_in_ob ($who); |
136 | $what->insert_ob_in_ob ($who); |
135 | return cf::override; |
137 | return cf::override; |
136 | } |
138 | } |
137 | |
139 | |
138 | if (!$what->get_flag (cf::FLAG_IDENTIFIED) && $what->need_identify) { |
140 | if (!$what->flag (cf::FLAG_IDENTIFIED) && $what->need_identify) { |
139 | $who->message ("The shopkeeper says: Sorry, you can't sell unidentified stuff here.", cf::NDI_BROWN); |
141 | $who->message ("The shopkeeper says: Sorry, you can't sell unidentified stuff here.", cf::NDI_BROWN); |
140 | $what->insert_ob_in_ob ($who); |
142 | $what->insert_ob_in_ob ($who); |
141 | return cf::override; |
143 | return cf::override; |
142 | } |
144 | } |
143 | |
145 | |
… | |
… | |
184 | "The shopkeeper says: Ok, got the fee of " . cf::cost_string_from_value ($fee) . " for the item", |
186 | "The shopkeeper says: Ok, got the fee of " . cf::cost_string_from_value ($fee) . " for the item", |
185 | cf::NDI_BROWN |
187 | cf::NDI_BROWN |
186 | ); |
188 | ); |
187 | } |
189 | } |
188 | |
190 | |
189 | $what->set_value ($value); |
191 | $what->value ($value); |
190 | my $cost = $what->query_cost ($who, cf::F_BUY | cf::F_SHOP) / ($what->nrof || 1); |
192 | my $cost = $what->query_cost ($who, cf::F_BUY | cf::F_SHOP) / ($what->nrof || 1); |
191 | |
193 | |
192 | my $fact = 0; |
194 | my $fact = 0; |
193 | if ($cost) { |
195 | if ($cost) { |
194 | $fact = $value / $cost; |
196 | $fact = $value / $cost; |
195 | $what->set_value (cf::ceil ($value * $fact)); |
197 | $what->value (cf::ceil ($value * $fact)); |
196 | } |
198 | } |
197 | |
199 | |
198 | # warn "END VALUE: $value * $fact => " . $what->value . "\n"; |
200 | # warn "END VALUE: $value * $fact => " . $what->value . "\n"; |
199 | |
201 | |
200 | # my $cost = $what->query_cost ($who, cf::F_BUY | cf::F_SHOP) / $what->nrof; |
202 | # my $cost = $what->query_cost ($who, cf::F_BUY | cf::F_SHOP) / $what->nrof; |
… | |
… | |
208 | ); |
210 | ); |
209 | |
211 | |
210 | $what->set_ob_key_value (ext_reseller_seller => $who->name); |
212 | $what->set_ob_key_value (ext_reseller_seller => $who->name); |
211 | $what->set_ob_key_value (ext_reseller_orig_value => $orig_value); |
213 | $what->set_ob_key_value (ext_reseller_orig_value => $orig_value); |
212 | # warn "SET SELLER ON " . $what->name . " + " . $what->{seller}->[0] . "\n"; |
214 | # warn "SET SELLER ON " . $what->name . " + " . $what->{seller}->[0] . "\n"; |
213 | $what->set_custom_name ( |
|
|
214 | $what->name . " (by " . $who->name . ")" |
215 | $what->custom_name ($what->name . " (by " . $who->name . ")"); |
215 | ); |
|
|
216 | $what->set_flag (cf::FLAG_UNPAID, 1); |
216 | $what->flag (cf::FLAG_UNPAID, 1); |
217 | $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); |
218 | |
218 | |
219 | cf::override; |
219 | cf::override; |
220 | }, |
220 | }, |
221 | ; |
221 | ; |