--- deliantra/server/ext/reseller.ext 2007/01/13 23:06:13 1.4 +++ deliantra/server/ext/reseller.ext 2007/09/30 16:24:30 1.8 @@ -1,4 +1,4 @@ -#!perl # MANDATORY +#!perl # mandatory my %unit = ( silver => 1, @@ -27,34 +27,34 @@ $who->map->path, $who->name, $action, $info; } +sub find_rec; + sub find_rec { my ($ob, $cb) = @_; - my @unpaid; + my @found; for my $i ($ob->inv) { - push @unpaid, $i if $cb->($i); - - push @unpaid, find_unpaid ($i, $cb) - if $i->inv; + push @found, $i if $cb->($i); + push @found, find_rec $i, $cb if $i->inv; } - return @unpaid; + + return @found; } sub find_unpaid { my ($ob) = @_; - my @r = find_rec ($ob, sub { $_[0]->flag (cf::FLAG_UNPAID) }); - return @r; + find_rec $ob, sub { $_[0]->flag (cf::FLAG_UNPAID) }; } sub find_traded { my ($ob) = @_; - my @r = find_rec ($ob, sub { $_[0]->get_ob_key_value ('ext_reseller_seller') ne '' }); - return @r; + find_rec $ob, sub { $_[0]->get_ob_key_value ('ext_reseller_seller') ne '' }; } cf::register_script_function "reseller::list_sells" => sub { my ($who, $msg, $npc) = @_; - my $sells = cf::from_json $npc->get_ob_key_value ('ext_reseller_sales'); + my $ext_re_sales = $npc->get_ob_key_value ('ext_reseller_sales'); + my $sells = $ext_re_sales && cf::from_json $ext_re_sales; my $hissells = $sells->{$who->name}; unless (keys %{$hissells || {}}) { @@ -74,7 +74,8 @@ cf::register_script_function "reseller::pay_player" => sub { my ($who, $msg, $npc) = @_; - my $sells = cf::from_json $npc->get_ob_key_value ('ext_reseller_sales'); + my $ext_re_sales = $npc->get_ob_key_value ('ext_reseller_sales'); + my $sells = $ext_re_sales && cf::from_json $ext_re_sales; my $hissells = $sells->{$who->name}; unless (keys %{$hissells || {}}) { @@ -92,7 +93,8 @@ $sells->{$who->name} = {}; - $npc->set_ob_key_value (ext_reseller_sales => cf::to_json $sells); + $npc->set_ob_key_value (ext_reseller_sales => cf::to_json $sells) + if $sells; 0 }; @@ -109,7 +111,8 @@ return cf::override; } - my $sells = cf::from_json $obs[0]->get_ob_key_value ('ext_reseller_sales'); + my $ext_re_sales = $obs[0]->get_ob_key_value ('ext_reseller_sales'); + my $sells = $ext_re_sales && cf::from_json $ext_re_sales; my $unpaid_items = {}; @@ -118,7 +121,7 @@ audit_log ($who, 'removes', ob2info ($item)); $item->flag (cf::FLAG_UNPAID, 0); $item->remove; - $item->insert_ob_in_ob ($who); + $who->insert ($item); next; } @@ -154,7 +157,8 @@ audit_log ($who, 'removed', (join ",", @seller_noted)) if @seller_noted; - $obs[0]->set_ob_key_value (ext_reseller_sales => cf::to_json $sells); + $obs[0]->set_ob_key_value (ext_reseller_sales => cf::to_json $sells) + if $sells; cf::override; }, @@ -169,13 +173,13 @@ if ($what->type == cf::MONEY) { $who->message ("The shopkeeper says: Sorry, you can't sell money here.", cf::NDI_BROWN); - $what->insert_ob_in_ob ($who); + $who->insert ($what); return cf::override; } if (!$what->flag (cf::FLAG_IDENTIFIED) && $what->need_identify) { $who->message ("The shopkeeper says: Sorry, you can't sell unidentified stuff here.", cf::NDI_BROWN); - $what->insert_ob_in_ob ($who); + $who->insert ($what); return cf::override; } @@ -185,7 +189,7 @@ if ($name =~ m/\S/) { unless ($name =~ m/\d+\s*\S+/) { $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); - $what->insert_ob_in_ob ($who); + $who->insert ($what); return cf::override; } @@ -193,7 +197,7 @@ if ($aliases{lc $2} or $unit{lc $2}) { $value += $1 * ($unit{lc $2} ? $unit{lc $2} : $unit{$aliases{lc $2}}); } else { - $what->insert_ob_in_ob ($who); + $who->insert ($what); $who->message ("The shopkeeper says: I don't know the currency '$2'", cf::NDI_BROWN); return cf::override; } @@ -203,7 +207,7 @@ } if ($value < 0) { - $what->insert_ob_in_ob ($who); + $who->insert ($what); $who->message ("The shopkeeper says: You can't sell something for a negative value: $value", cf::NDI_BROWN); return cf::override; } @@ -215,7 +219,7 @@ "The shopkeeper says: You need " . cf::cost_string_from_value ($fee) . " to pay the 1% fee for this item", cf::NDI_BROWN ); - $what->insert_ob_in_ob ($who); + $who->insert ($what); return cf::override; } else { $who->message (