--- deliantra/server/ext/rent.ext 2006/12/15 19:29:18 1.1 +++ deliantra/server/ext/rent.ext 2007/02/15 03:19:02 1.7 @@ -14,29 +14,14 @@ "/brest/apartments/brest_town_house" => [30000, "brest", "brecht"], ); -sub teleport { - my ($pl, $map, $x, $y) = @_; - - my $portal = cf::object::new "exit"; - - $portal->slaying ($map); - $portal->stats->hp ($x); - $portal->stats->sp ($y); - $portal->apply ($pl->ob); - $portal->destroy; -} - # 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); - teleport $pl, "/world/world_105_115", 2, 34 - unless - $pl->ob->map - && $pl->ob->map->path !~ /nimbus/ - && $pl->ob->map->path !~ m%/var/crossfire/players/%; + cf::override; } sub update_balance { @@ -150,7 +135,8 @@ $pl->ob->reply (undef, "I am sorry to hear that, we will immediately stop charging you for your apartment, of course."); }; -cf::attach_to_players prio => 100, +cf::player->attach ( + prio => 100, on_login => sub { my ($pl) = @_; @@ -165,43 +151,45 @@ } update_balance $pl; - }; + }, +); -cf::register_map_attachment rent => +cf::map::attachment rent => 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, sir!"); + } else { + $pl->ob->reply (undef, "We are sorry, sir, 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, "Sir, you have to rent this apartment in The Apartment Shop in Scorn first!"); + reject_entry $pl; + } }, ; -Event->timer (after => 60, interval => 3600, data => cf::WF_AUTOCANCEL, cb => sub { - pay_balance $_ for cf::player::list; -}); +our $RENT_TIMER = Event->timer ( + reentrant => 0, + after => 60, + interval => 3600, + data => cf::WF_AUTOCANCEL, + cb => sub { + pay_balance $_ for cf::player::list; + }, +);