#! perl # handle the nimbus map and other stuff my @STATS = qw( Str Dex Con Wis Cha Int Pow wc ac hp maxhp sp maxsp grace maxgrace exp food dam luck ); sub stats_get($) { my ($stats, $save) = @_; $save->{$_} = $stats->$_ for @STATS; $save } sub stats_set($$) { my ($stats, $save) = @_; $stats->$_ ($save->{$_}) for @STATS; $stats->hp ($stats->maxhp); $stats->grace ($stats->maxgrace); $stats->food (999); } sub skills_get($) { my ($ob) = @_; +{ map +($_->skill => $_->stats->exp), grep $_->type == cf::SKILL, $ob->inv } } sub skills_set($$) { my ($ob, $skills) = @_; for my $skill (grep $_->type == cf::SKILL, $ob->inv) { my $name = $skill->skill; if ($skill->stats->exp < $skills->{$name}) { $skill->stats->exp ($skills->{$name}); $ob->player_lvl_adj ($skill); } } } # called when the player will likely die (modulo explore mode) # but before any stats/exp is changed cf::player->attach ( 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"); } $pl->savebed ("/nimbus", 24, 12); }, ); cf::object::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"); } } else { @savebed = ("/scorn/taverns/inn", 10, 5); } my $map = $ob->map; $pl->savebed (@savebed); $ob->goto_map (@savebed); $map->nuke; $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"); cf::override; }, ;