--- cf.schmorp.de/maps/perl/nimbus.ext 2006/04/08 14:53:12 1.11 +++ cf.schmorp.de/maps/perl/nimbus.ext 2006/12/12 16:59:34 1.19 @@ -11,9 +11,8 @@ sub stats_get($) { my ($stats, $save) = @_; - for my $stat (@STATS) { - $save->{$stat} = $stats->$stat; - } + $save->{$_} = $stats->$_ + for @STATS; $save } @@ -21,9 +20,8 @@ sub stats_set($$) { my ($stats, $save) = @_; - for my $stat (@STATS) { - $stats->$stat ($save->{$stat}); - } + $stats->$_ ($save->{$_}) + for @STATS; $stats->hp ($stats->maxhp); $stats->grace ($stats->maxgrace); @@ -55,42 +53,41 @@ # called when the player will likely die (modulo explore mode) # but before any stats/exp is changed -sub on_player_death { - my ($ob) = @_; - - my $pl = $ob->contr; - - # save player stats and experience to restore it later - - unless ($ob->{in_nimbus}) { - my $save = { - stats => stats_get $ob->stats, - orig_stats => stats_get $pl->orig_stats, - savebed => [$pl->get_savebed], - skill_exp => skills_get $ob, - }; - - $ob->{in_nimbus} = $save; - - $ob->message ("\n"); - $ob->message ("You start to feel dizzy.\n"); - $ob->message ("The world around you blurs.\n"); - $ob->message ("\n"); - } - - my $path = sprintf "%s/%s/%s/%s", - cf::localdir, cf::playerdir, $ob->name, "nimbus"; +cf::attach_to_players + on_death => sub { + my ($pl) = @_; + my $ob = $pl->ob; + + # save player stats and experience to restore it later + + unless ($ob->{in_nimbus}) { + my $save = { + stats => stats_get $ob->stats, + orig_stats => stats_get $pl->orig_stats, + savebed => [$pl->savebed], + skill_exp => skills_get $ob, + }; + + $ob->{in_nimbus} = $save; + + $ob->message ("\n"); + $ob->message ("You start to feel dizzy.\n"); + $ob->message ("The world around you blurs.\n"); + $ob->message ("\n"); + } - if ($ob->map->path ne $path) { - my $nimbus = cf::map::get_map "/schmorp/nimbus"; - $nimbus->set_path ($path); - $nimbus->set_unique (1); - - $pl->set_savebed ($path, 24, 12); - } + my $path = sprintf "%s/%s/%s/%s", + cf::localdir, cf::playerdir, $ob->name, "nimbus"; - 0 -} + if ($ob->map->path ne $path) { + my $nimbus = cf::map::find "/schmorp/nimbus"; + $nimbus->path ($path); + $nimbus->unique (1); + + $pl->savebed ($path, 24, 12); + } + }, +; sub teleport { my ($pl, $map, $x, $y) = @_; @@ -101,56 +98,58 @@ my $portal = cf::object::new "exit"; - $portal->set_slaying ($map); - $portal->set_hp ($x); - $portal->set_sp ($y); + $portal->slaying ($map); + $portal->stats->hp ($x); + $portal->stats->sp ($y); $portal->apply ($pl->ob); - $portal->free; + $portal->destroy; } -sub on_trigger { - my ($event, $porter, $ob) = @_; +cf::register_attachment nimbus_exit => + on_trigger => sub { + my ($self, $ob) = @_; + + my $pl = $ob->contr; + my @savebed; + + if (my $save = delete $ob->{in_nimbus}) { + @savebed = @{$save->{savebed}}; + + if ($self->{nimbus_exit}{restore}) { + $ob->message ("The gods acknowledge your success.\n"); + stats_set $ob->stats, $save->{stats}; + stats_set $pl->orig_stats, $save->{orig_stats}; + $ob->player_lvl_adj; # update overall level + skills_set $ob, $save->{skill_exp}; + } else { + $ob->message ("The gods are disappointed with you.\n"); + } - my $options = $event->options; - my $pl = $ob->contr; - my @savebed; - - if (my $save = delete $ob->{in_nimbus}) { - @savebed = @{$save->{savebed}}; - - if ($options eq "restore") { - $ob->message ("The gods acknowledge your success.\n"); - stats_set $ob->stats, $save->{stats}; - stats_set $pl->orig_stats, $save->{orig_stats}; - $ob->player_lvl_adj; # update overall level - skills_set $ob, $save->{skill_exp}; } else { - $ob->message ("The gods are disappointed with you.\n"); + @savebed = ("/scorn/taverns/inn", 10, 5); } - } else { - @savebed = ("/scorn/taverns/inn", 10, 5); - } + $pl->savebed (@savebed); - $pl->set_savebed (@savebed); + my $map = $ob->map; - my $map = $ob->map; + teleport $pl, @savebed; - teleport $pl, @savebed; + # should make this a temporary map and let cf deal with it + unlink $map->path; + unlink $map->path . ".pst"; - # should make this a temporary map and let cf deal with it - unlink $map->path; - unlink $map->path . ".cfperl"; - $map->delete_map; + $map->delete_map; - $pl->play_sound_player_only (cf::SOUND_PLAYER_DIES); + $pl->play_sound_player_only (cf::SOUND_PLAYER_DIES); - $ob->message ("You feel as if you woke up from a dream.\n"); - $ob->message ("You have a headache.\n"); - $ob->message ("Maybe you should have a drink.\n"); + $ob->message ("You feel as if you woke up from a dream.\n"); + $ob->message ("You have a headache.\n"); + $ob->message ("Maybe you should have a drink.\n"); - 1 -} + cf::override; + }, +;