| 1 |
root |
1.1 |
#! perl |
| 2 |
|
|
|
| 3 |
|
|
# handle the nimbus map and other stuff |
| 4 |
|
|
|
| 5 |
|
|
my @STATS = qw( |
| 6 |
|
|
Str Dex Con Wis Cha Int Pow |
| 7 |
|
|
wc ac hp maxhp sp maxsp grace maxgrace |
| 8 |
|
|
exp food dam luck |
| 9 |
|
|
); |
| 10 |
|
|
|
| 11 |
|
|
sub stats_get($) { |
| 12 |
|
|
my ($stats, $save) = @_; |
| 13 |
|
|
|
| 14 |
|
|
$save->{$_} = $stats->$_ |
| 15 |
|
|
for @STATS; |
| 16 |
|
|
|
| 17 |
|
|
$save |
| 18 |
|
|
} |
| 19 |
|
|
|
| 20 |
|
|
sub stats_set($$) { |
| 21 |
|
|
my ($stats, $save) = @_; |
| 22 |
|
|
|
| 23 |
|
|
$stats->$_ ($save->{$_}) |
| 24 |
|
|
for @STATS; |
| 25 |
|
|
|
| 26 |
|
|
$stats->hp ($stats->maxhp); |
| 27 |
|
|
$stats->grace ($stats->maxgrace); |
| 28 |
|
|
$stats->food (999); |
| 29 |
|
|
} |
| 30 |
|
|
|
| 31 |
|
|
sub skills_get($) { |
| 32 |
|
|
my ($ob) = @_; |
| 33 |
|
|
|
| 34 |
|
|
+{ |
| 35 |
|
|
map +($_->skill => $_->stats->exp), |
| 36 |
|
|
grep $_->type == cf::SKILL, |
| 37 |
|
|
$ob->inv |
| 38 |
|
|
} |
| 39 |
|
|
} |
| 40 |
|
|
|
| 41 |
|
|
sub skills_set($$) { |
| 42 |
|
|
my ($ob, $skills) = @_; |
| 43 |
|
|
|
| 44 |
|
|
for my $skill (grep $_->type == cf::SKILL, $ob->inv) { |
| 45 |
|
|
my $name = $skill->skill; |
| 46 |
|
|
|
| 47 |
|
|
if ($skill->stats->exp < $skills->{$name}) { |
| 48 |
|
|
$skill->stats->exp ($skills->{$name}); |
| 49 |
|
|
$ob->player_lvl_adj ($skill); |
| 50 |
|
|
} |
| 51 |
|
|
} |
| 52 |
|
|
} |
| 53 |
|
|
|
| 54 |
|
|
# called when the player will likely die (modulo explore mode) |
| 55 |
|
|
# but before any stats/exp is changed |
| 56 |
root |
1.2 |
cf::player->attach ( |
| 57 |
root |
1.1 |
on_death => sub { |
| 58 |
|
|
my ($pl) = @_; |
| 59 |
|
|
my $ob = $pl->ob; |
| 60 |
|
|
|
| 61 |
|
|
# save player stats and experience to restore it later |
| 62 |
|
|
|
| 63 |
|
|
unless ($ob->{in_nimbus}) { |
| 64 |
|
|
my $save = { |
| 65 |
|
|
stats => stats_get $ob->stats, |
| 66 |
|
|
orig_stats => stats_get $pl->orig_stats, |
| 67 |
|
|
savebed => [$pl->savebed], |
| 68 |
|
|
skill_exp => skills_get $ob, |
| 69 |
|
|
}; |
| 70 |
|
|
|
| 71 |
|
|
$ob->{in_nimbus} = $save; |
| 72 |
|
|
|
| 73 |
|
|
$ob->message ("\n"); |
| 74 |
|
|
$ob->message ("You start to feel dizzy.\n"); |
| 75 |
|
|
$ob->message ("The world around you blurs.\n"); |
| 76 |
|
|
$ob->message ("\n"); |
| 77 |
|
|
} |
| 78 |
|
|
|
| 79 |
|
|
my $path = sprintf "%s/%s/%s/%s", |
| 80 |
|
|
cf::localdir, cf::playerdir, $ob->name, "nimbus"; |
| 81 |
|
|
|
| 82 |
|
|
if ($ob->map->path ne $path) { |
| 83 |
|
|
my $nimbus = cf::map::find "/schmorp/nimbus"; |
| 84 |
|
|
$nimbus->path ($path); |
| 85 |
|
|
$nimbus->unique (1); |
| 86 |
|
|
|
| 87 |
|
|
$pl->savebed ($path, 24, 12); |
| 88 |
|
|
} |
| 89 |
|
|
}, |
| 90 |
root |
1.2 |
); |
| 91 |
root |
1.1 |
|
| 92 |
|
|
sub teleport { |
| 93 |
|
|
my ($pl, $map, $x, $y) = @_; |
| 94 |
|
|
|
| 95 |
|
|
return if $pl->ob->map->path eq $map |
| 96 |
|
|
&& abs ($pl->ob->x - $x) <= 1 |
| 97 |
|
|
&& abs ($pl->ob->y - $y) <= 1; |
| 98 |
|
|
|
| 99 |
|
|
my $portal = cf::object::new "exit"; |
| 100 |
|
|
|
| 101 |
|
|
$portal->slaying ($map); |
| 102 |
|
|
$portal->stats->hp ($x); |
| 103 |
|
|
$portal->stats->sp ($y); |
| 104 |
|
|
|
| 105 |
|
|
$portal->apply ($pl->ob); |
| 106 |
|
|
|
| 107 |
|
|
$portal->destroy; |
| 108 |
|
|
} |
| 109 |
|
|
|
| 110 |
root |
1.2 |
cf::object::attachment nimbus_exit => |
| 111 |
root |
1.1 |
on_trigger => sub { |
| 112 |
|
|
my ($self, $ob) = @_; |
| 113 |
|
|
|
| 114 |
|
|
my $pl = $ob->contr; |
| 115 |
|
|
my @savebed; |
| 116 |
|
|
|
| 117 |
|
|
if (my $save = delete $ob->{in_nimbus}) { |
| 118 |
|
|
@savebed = @{$save->{savebed}}; |
| 119 |
|
|
|
| 120 |
|
|
if ($self->{nimbus_exit}{restore}) { |
| 121 |
|
|
$ob->message ("The gods acknowledge your success.\n"); |
| 122 |
|
|
stats_set $ob->stats, $save->{stats}; |
| 123 |
|
|
stats_set $pl->orig_stats, $save->{orig_stats}; |
| 124 |
|
|
$ob->player_lvl_adj; # update overall level |
| 125 |
|
|
skills_set $ob, $save->{skill_exp}; |
| 126 |
|
|
} else { |
| 127 |
|
|
$ob->message ("The gods are disappointed with you.\n"); |
| 128 |
|
|
} |
| 129 |
|
|
|
| 130 |
|
|
} else { |
| 131 |
|
|
@savebed = ("/scorn/taverns/inn", 10, 5); |
| 132 |
|
|
} |
| 133 |
|
|
|
| 134 |
|
|
$pl->savebed (@savebed); |
| 135 |
|
|
|
| 136 |
|
|
my $map = $ob->map; |
| 137 |
|
|
|
| 138 |
|
|
teleport $pl, @savebed; |
| 139 |
|
|
|
| 140 |
|
|
# should make this a temporary map and let cf deal with it |
| 141 |
|
|
unlink $map->path; |
| 142 |
|
|
unlink $map->path . ".pst"; |
| 143 |
|
|
|
| 144 |
|
|
$map->delete_map; |
| 145 |
|
|
|
| 146 |
|
|
$pl->play_sound_player_only (cf::SOUND_PLAYER_DIES); |
| 147 |
|
|
|
| 148 |
|
|
$ob->message ("You feel as if you woke up from a dream.\n"); |
| 149 |
|
|
$ob->message ("You have a headache.\n"); |
| 150 |
|
|
$ob->message ("Maybe you should have a drink.\n"); |
| 151 |
|
|
|
| 152 |
|
|
cf::override; |
| 153 |
|
|
}, |
| 154 |
|
|
; |
| 155 |
|
|
|