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 |
root |
1.6 |
exp food dam luck |
9 |
root |
1.1 |
); |
10 |
|
|
|
11 |
|
|
sub stats_get($) { |
12 |
|
|
my ($stats, $save) = @_; |
13 |
|
|
|
14 |
root |
1.18 |
$save->{$_} = $stats->$_ |
15 |
|
|
for @STATS; |
16 |
root |
1.1 |
|
17 |
|
|
$save |
18 |
|
|
} |
19 |
|
|
|
20 |
|
|
sub stats_set($$) { |
21 |
|
|
my ($stats, $save) = @_; |
22 |
|
|
|
23 |
root |
1.18 |
$stats->$_ ($save->{$_}) |
24 |
|
|
for @STATS; |
25 |
root |
1.2 |
|
26 |
|
|
$stats->hp ($stats->maxhp); |
27 |
|
|
$stats->grace ($stats->maxgrace); |
28 |
|
|
$stats->food (999); |
29 |
root |
1.1 |
} |
30 |
|
|
|
31 |
|
|
sub skills_get($) { |
32 |
|
|
my ($ob) = @_; |
33 |
|
|
|
34 |
root |
1.2 |
+{ |
35 |
root |
1.3 |
map +($_->skill => $_->stats->exp), |
36 |
root |
1.2 |
grep $_->type == cf::SKILL, |
37 |
|
|
$ob->inv |
38 |
|
|
} |
39 |
root |
1.1 |
} |
40 |
|
|
|
41 |
root |
1.2 |
sub skills_set($$) { |
42 |
root |
1.6 |
my ($ob, $skills) = @_; |
43 |
root |
1.2 |
|
44 |
root |
1.6 |
for my $skill (grep $_->type == cf::SKILL, $ob->inv) { |
45 |
|
|
my $name = $skill->skill; |
46 |
root |
1.5 |
|
47 |
root |
1.6 |
if ($skill->stats->exp < $skills->{$name}) { |
48 |
|
|
$skill->stats->exp ($skills->{$name}); |
49 |
|
|
$ob->player_lvl_adj ($skill); |
50 |
root |
1.5 |
} |
51 |
root |
1.2 |
} |
52 |
root |
1.1 |
} |
53 |
|
|
|
54 |
|
|
# called when the player will likely die (modulo explore mode) |
55 |
|
|
# but before any stats/exp is changed |
56 |
root |
1.12 |
cf::attach_to_players |
57 |
|
|
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 |
root |
1.17 |
savebed => [$pl->savebed], |
68 |
root |
1.12 |
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 |
root |
1.1 |
|
79 |
root |
1.12 |
my $path = sprintf "%s/%s/%s/%s", |
80 |
|
|
cf::localdir, cf::playerdir, $ob->name, "nimbus"; |
81 |
root |
1.1 |
|
82 |
root |
1.12 |
if ($ob->map->path ne $path) { |
83 |
root |
1.15 |
my $nimbus = cf::map::find "/schmorp/nimbus"; |
84 |
root |
1.17 |
$nimbus->path ($path); |
85 |
|
|
$nimbus->unique (1); |
86 |
root |
1.12 |
|
87 |
root |
1.17 |
$pl->savebed ($path, 24, 12); |
88 |
root |
1.12 |
} |
89 |
|
|
}, |
90 |
|
|
; |
91 |
root |
1.1 |
|
92 |
root |
1.7 |
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 |
root |
1.18 |
$portal->slaying ($map); |
102 |
|
|
$portal->stats->hp ($x); |
103 |
|
|
$portal->stats->sp ($y); |
104 |
root |
1.7 |
|
105 |
|
|
$portal->apply ($pl->ob); |
106 |
|
|
|
107 |
root |
1.19 |
$portal->destroy; |
108 |
root |
1.7 |
} |
109 |
|
|
|
110 |
root |
1.13 |
cf::register_attachment nimbus_exit => |
111 |
|
|
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 |
root |
1.10 |
|
130 |
root |
1.6 |
} else { |
131 |
root |
1.13 |
@savebed = ("/scorn/taverns/inn", 10, 5); |
132 |
root |
1.2 |
} |
133 |
|
|
|
134 |
root |
1.17 |
$pl->savebed (@savebed); |
135 |
root |
1.1 |
|
136 |
root |
1.13 |
my $map = $ob->map; |
137 |
root |
1.1 |
|
138 |
root |
1.13 |
teleport $pl, @savebed; |
139 |
root |
1.5 |
|
140 |
root |
1.13 |
# should make this a temporary map and let cf deal with it |
141 |
|
|
unlink $map->path; |
142 |
|
|
unlink $map->path . ".pst"; |
143 |
root |
1.1 |
|
144 |
root |
1.13 |
$map->delete_map; |
145 |
root |
1.5 |
|
146 |
root |
1.13 |
$pl->play_sound_player_only (cf::SOUND_PLAYER_DIES); |
147 |
root |
1.7 |
|
148 |
root |
1.13 |
$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 |
root |
1.1 |
|
152 |
root |
1.13 |
cf::override; |
153 |
|
|
}, |
154 |
|
|
; |
155 |
root |
1.1 |
|