--- deliantra/server/ext/rent.ext 2007/01/04 18:39:14 1.4 +++ deliantra/server/ext/rent.ext 2010/03/12 17:59:32 1.22 @@ -2,28 +2,31 @@ use List::Util; -my %apartment = ( +our %apartment = ( "/scorn/apartment/apartments" => [ 1, "scorn", "skorn"], "/santo_dominion/sdomino_appartment" => [ 10, "santo dominion", "domino"], "/darcap/darcap/apartment" => [ 30, "darcap", "thecap"], + "/gotischerbereich/steinwandstadt/sapartment1" => [ 100, "steinwandstadt", "konkret"], "/navar_city/apartments/apartment" => [ 250, "navar", "navar"], "/azumauindo/ranbounagisatoshi/apartments/sapartment" => [ 100, "乱暴渚都市", "benjo"], "/azumauindo/suno-yamatoshi/apartments/lapartment1" => [ 1000, "スノー大和島根", "sama"], + "/elmex/jeweler/jeweler_inn_upper" => [ 500, "jeweler town", "jewelor"], "/pup_land/nurnberg/apartment/main" => [ 300, "nürnberg", "sauerkraut"], - "/pup_land/lone_town/apartment/groundfloor" => [50000, "lone town", "looney"], + "/celvear_port/tower2/tower2" => [ 300, "celvear", "risen"], + "/lostwages/petapartment" => [ 5000, "lostwages", "losvegas"], + "/gotischerbereich/towerapartment/tower1" => [10000, "gotisch", "retreat"], "/brest/apartments/brest_town_house" => [30000, "brest", "brecht"], + "/pup_land/lone_town/apartment/groundfloor" => [50000, "lone town", "looney"], ); # we have to special case some special cases :) sub reject_entry { my ($pl) = @_; - cf::override; + my $prev_pos = $pl->ob->{_prev_pos}; + $pl->ob->goto ($prev_pos ? @$prev_pos : ("/world/world_105_115", 2, 34)); - $pl->goto_map ("/world/world_105_115", 2, 34) - unless - $pl->ob->map - && !$pl->ob->map->{path}{user_rel}; + cf::override; } sub update_balance { @@ -49,6 +52,8 @@ sub pay_balance { my ($pl) = @_; + cf::cede_to_tick; + update_balance $pl; return unless $pl->{rent}{balance} > 0; @@ -61,11 +66,11 @@ cf::db_put rent => balance => $deduct + cf::db_get rent => "balance"; $pl->ob->{bank_balance} -= $deduct; $pl->{rent}{balance} -= $deduct; - $pl->ob->reply (undef, "Something whispers into your ear:\n" - . "Sir, we deducted your apartment rent ($deduct_string) from your bank account."); + $pl->ob->reply (undef, "Something whispers into your ear: " + . "Your highness, we deducted your apartment rent ($deduct_string) from your bank account."); } else { - $pl->ob->reply (undef, "Something whispers into your ear:\n" - . "Sir, we want to deduct the apartment rent ($deduct_string), but the bank informed us that they cannot perform the transaction. " + $pl->ob->reply (undef, "Something whispers into your ear: " + . "Your highness, we want to deduct the apartment rent ($deduct_string), but the bank informed us that they cannot perform the transaction. " . "Please even out your balance so we can deduct the fees, otherwise we will be forced to shut down your access to the apartment."); } } @@ -93,8 +98,8 @@ while (my ($k, $v) = each %apartment) { my $type = exists $pl->{rent}{apartment}{$k} ? 1 : 2; - $pl->ob->reply (undef, "model \"$v->[2]\", situated in $v->[1] (" - . (cf::cost_string_from_value $v->[0]) . "/hr)") + $pl->ob->reply (undef, "model \"$v->[2]\", located in $v->[1] (" + . (cf::cost_string_from_value $v->[0]) . "/hr)\n") if $type & $types; } }; @@ -119,7 +124,7 @@ $pl->{rent}{apartment}{$apartment} = undef; - $pl->ob->reply (undef, "Wonderful decision, sir! " + $pl->ob->reply (undef, "Wonderful decision, your highness! " . "We told the proprietor in $apartment{$apartment}[1] to expect you and let you in. " . "We are sure you will be satisfied!"); }; @@ -147,7 +152,7 @@ if ($pl->{rent}{last_online_check}) { $pl->{rent}{last_online_check} = time - List::Util::min 3600, - $pl->ob->get_ob_key_value ("schmorplog_last_save") - $pl->{rent}{last_online_check}; + $pl->ob->kv_get ("schmorplog_last_save") - $pl->{rent}{last_online_check}; } else { $pl->{rent}{last_online_check} = time; } @@ -160,37 +165,32 @@ on_enter => sub { my ($map, $pl, $x, $y) = @_; - # can freely enter homes of other people - { - my $path = sprintf "%s/%s/%s/", - cf::localdir, cf::playerdir, $pl->ob->name; + my $pfx = sprintf "~%s/", $pl->ob->name; - return if $path ne substr $map->path, 0, length $path; - } + # only do something if entering ones own apartment + if ($pfx eq substr $map->path, 0, length $pfx) { + for my $path (keys %{ $pl->{rent}{apartment} }) { + $path = sprintf "~%s%s", $pl->ob->name, $path; + + if ($map->path eq $path) { + if (check_balance $pl) { + $pl->ob->reply (undef, "Welcome to your apartment, your highness!"); + } else { + $pl->ob->reply (undef, "We are sorry, your highness, you have to pay your rent first."); + reject_entry $pl; + } - for my $path (keys %{ $pl->{rent}{apartment} }) { - $path =~ y/\//_/; - $path = sprintf "%s/%s/%s/%s", - cf::localdir, cf::playerdir, $pl->ob->name, $path; - - if ($map->path eq $path) { - if (check_balance $pl) { - $pl->ob->reply (undef, "Welcome to your apartment, sir!"); - } else { - $pl->ob->reply (undef, "We are sorry, sir, you have to pay your rent first."); - reject_entry $pl; + return; } - - return; } - } - $pl->ob->reply (undef, "Sir, you have to rent this apartment in The Apartment Shop in Scorn first!"); - reject_entry $pl; + $pl->ob->reply (undef, "Your highness, you have to rent this apartment in The Apartment Shop in Scorn or other apartment shops first!"); + reject_entry $pl; + } }, ; -our $RENT_TIMER = Event->timer (after => 60, interval => 3600, data => cf::WF_AUTOCANCEL, cb => sub { +our $RENT_TIMER = cf::periodic 3600, Coro::unblock_sub { pay_balance $_ for cf::player::list; -}); +};