--- cf.schmorp.de/maps/perl/nimbus.ext 2006/03/20 23:28:56 1.5 +++ cf.schmorp.de/maps/perl/nimbus.ext 2006/08/30 12:06:17 1.16 @@ -5,7 +5,7 @@ my @STATS = qw( Str Dex Con Wis Cha Int Pow wc ac hp maxhp sp maxsp grace maxgrace - food dam luck + exp food dam luck ); sub stats_get($) { @@ -34,8 +34,6 @@ my ($ob) = @_; +{ - "" => $ob->stats->exp, - map +($_->skill => $_->stats->exp), grep $_->type == cf::SKILL, $ob->inv @@ -43,90 +41,117 @@ } sub skills_set($$) { - my ($ob, $skill) = @_; + my ($ob, $skills) = @_; - my $cur = skills_get $ob; + for my $skill (grep $_->type == cf::SKILL, $ob->inv) { + my $name = $skill->skill; - while (my ($name, $exp) = each %$skill) { - if ($cur->{$name} < $exp) { - length $name - ? $ob->change_skill ($exp - $cur->{$name}, $name) - : $ob->change_skill ($exp - $cur->{$name}); + 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 -sub on_player_death { - my ($event) = @_; +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->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 $ob = $event->{who}; - my $pl = $ob->contr; + my $path = sprintf "%s/%s/%s/%s", + cf::localdir, cf::playerdir, $ob->name, "nimbus"; - # save player stats and experience to restore it later + if ($ob->map->path ne $path) { + my $nimbus = cf::map::find "/schmorp/nimbus"; + $nimbus->set_path ($path); + $nimbus->set_unique (1); + + $pl->set_savebed ($path, 24, 12); + } + }, +; - my $save = { - stats => stats_get $ob->stats, - orig_stats => stats_get $pl->orig_stats, - savebed => [$pl->get_savebed], - skill_exp => skills_get $ob, - }; +sub teleport { + my ($pl, $map, $x, $y) = @_; - $ob->{in_nimbus} ||= $save; + return if $pl->ob->map->path eq $map + && abs ($pl->ob->x - $x) <= 1 + && abs ($pl->ob->y - $y) <= 1; - my $path = sprintf "%s/%s/%s/%s", - cf::localdir, cf::playerdir, $ob->name, "nimbus"; + my $portal = cf::object::new "exit"; - my $nimbus = cf::map::get_map "/schmorp/nimbus"; - $nimbus->set_path ($path); - $nimbus->set_unique (1); - - $pl->set_savebed ($path, 24, 12); + $portal->set_slaying ($map); + $portal->set_hp ($x); + $portal->set_sp ($y); - $pl->message ("\n"); - $pl->message ("You start to feel dizzy.\n"); - $pl->message ("The world around you blurs.\n"); - $pl->message ("\n"); + $portal->apply ($pl->ob); - 0 + $portal->free; } -sub on_trigger { - my ($event) = @_; - my $options = $event->{options}; - my $ob = $event->{activator}; - my $pl = $ob->contr; - my @savebed; - - warn "trigger $options $ob->{nimbus_save}\n";#d# - warn $ob->name; - - if (my $save = delete $ob->{in_nimbus}) { - @savebed = @{$save->{savebed}}; - - if ($options eq "restore" || 1) { - stats_set $ob->stats, $save->{stats}; - stats_set $pl->orig_stats, $save->{orig_stats}; - skills_set $ob, $save->{skill_exp}; +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"); + } + + } else { + @savebed = ("/scorn/taverns/inn", 10, 5); } - } else { - @savebed = ("/scorn/taverns/inn", 10, 5); - } + $pl->set_savebed (@savebed); - $pl->set_savebed (@savebed); + my $map = $ob->map; - my $map = $ob->map; + teleport $pl, @savebed; - $ob->teleport (cf::map::get_map $savebed[0], $savebed[1], $savebed[2]); + # should make this a temporary map and let cf deal with it + unlink $map->path; + unlink $map->path . ".pst"; - $map->delete_map; + $map->delete_map; - $pl->message ("You feel as if you woke up from a dream.\n"); - $pl->message ("You have a headache.\n"); - $pl->message ("Maybe you should have a drink.\n"); + $pl->play_sound_player_only (cf::SOUND_PLAYER_DIES); - 1 -} + $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; + }, +;