--- deliantra/server/ext/reseller.ext 2007/01/24 19:39:14 1.5 +++ 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, @@ -53,7 +53,8 @@ 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 || {}}) { @@ -73,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 || {}}) { @@ -91,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 }; @@ -108,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 = {}; @@ -117,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; } @@ -153,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; }, @@ -168,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; } @@ -184,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; } @@ -192,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; } @@ -202,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; } @@ -214,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 (