ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cf.schmorp.de/maps/perl/nimbus.ext
(Generate patch)

Comparing cf.schmorp.de/maps/perl/nimbus.ext (file contents):
Revision 1.8 by root, Tue Mar 28 16:08:19 2006 UTC vs.
Revision 1.19 by root, Tue Dec 12 16:59:34 2006 UTC

9); 9);
10 10
11sub stats_get($) { 11sub stats_get($) {
12 my ($stats, $save) = @_; 12 my ($stats, $save) = @_;
13 13
14 for my $stat (@STATS) {
15 $save->{$stat} = $stats->$stat; 14 $save->{$_} = $stats->$_
16 } 15 for @STATS;
17 16
18 $save 17 $save
19} 18}
20 19
21sub stats_set($$) { 20sub stats_set($$) {
22 my ($stats, $save) = @_; 21 my ($stats, $save) = @_;
23 22
24 for my $stat (@STATS) {
25 $stats->$stat ($save->{$stat}); 23 $stats->$_ ($save->{$_})
26 } 24 for @STATS;
27 25
28 $stats->hp ($stats->maxhp); 26 $stats->hp ($stats->maxhp);
29 $stats->grace ($stats->maxgrace); 27 $stats->grace ($stats->maxgrace);
30 $stats->food (999); 28 $stats->food (999);
31} 29}
53 } 51 }
54} 52}
55 53
56# called when the player will likely die (modulo explore mode) 54# called when the player will likely die (modulo explore mode)
57# but before any stats/exp is changed 55# but before any stats/exp is changed
58sub on_player_death { 56cf::attach_to_players
57 on_death => sub {
59 my ($ob) = @_; 58 my ($pl) = @_;
59 my $ob = $pl->ob;
60 60
61 my $pl = $ob->contr; 61 # save player stats and experience to restore it later
62 62
63 # save player stats and experience to restore it later 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 };
64 70
65 my $save = { 71 $ob->{in_nimbus} = $save;
66 stats => stats_get $ob->stats,
67 orig_stats => stats_get $pl->orig_stats,
68 savebed => [$pl->get_savebed],
69 skill_exp => skills_get $ob,
70 };
71 72
72 $ob->{in_nimbus} ||= $save; 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 }
73 78
74 my $path = sprintf "%s/%s/%s/%s", 79 my $path = sprintf "%s/%s/%s/%s",
75 cf::localdir, cf::playerdir, $ob->name, "nimbus"; 80 cf::localdir, cf::playerdir, $ob->name, "nimbus";
76 81
82 if ($ob->map->path ne $path) {
77 my $nimbus = cf::map::get_map "/schmorp/nimbus"; 83 my $nimbus = cf::map::find "/schmorp/nimbus";
78 $nimbus->set_path ($path); 84 $nimbus->path ($path);
79 $nimbus->set_unique (1); 85 $nimbus->unique (1);
80 86
81 $pl->set_savebed ($path, 24, 12); 87 $pl->savebed ($path, 24, 12);
82 88 }
83 $ob->message ("\n"); 89 },
84 $ob->message ("You start to feel dizzy.\n"); 90;
85 $ob->message ("The world around you blurs.\n");
86 $ob->message ("\n");
87
88 0
89}
90 91
91sub teleport { 92sub teleport {
92 my ($pl, $map, $x, $y) = @_; 93 my ($pl, $map, $x, $y) = @_;
93 94
94 return if $pl->ob->map->path eq $map 95 return if $pl->ob->map->path eq $map
95 && abs ($pl->ob->x - $x) <= 1 96 && abs ($pl->ob->x - $x) <= 1
96 && abs ($pl->ob->y - $y) <= 1; 97 && abs ($pl->ob->y - $y) <= 1;
97 98
98 my $portal = cf::object::new "exit"; 99 my $portal = cf::object::new "exit";
99 100
100 $portal->set_slaying ($map); 101 $portal->slaying ($map);
101 $portal->set_hp ($x); 102 $portal->stats->hp ($x);
102 $portal->set_sp ($y); 103 $portal->stats->sp ($y);
103 104
104 $portal->apply ($pl->ob); 105 $portal->apply ($pl->ob);
105 106
106 $portal->free; 107 $portal->destroy;
107} 108}
108 109
109sub on_trigger { 110cf::register_attachment nimbus_exit =>
110 my ($event) = @_; 111 on_trigger => sub {
111 my $options = $event->{options}; 112 my ($self, $ob) = @_;
112 my $ob = $event->{activator};
113 my $pl = $ob->contr;
114 my @savebed;
115 113
116 if (my $save = delete $ob->{in_nimbus}) { 114 my $pl = $ob->contr;
117 @savebed = @{$save->{savebed}}; 115 my @savebed;
118 116
119 if ($options eq "restore") { 117 if (my $save = delete $ob->{in_nimbus}) {
118 @savebed = @{$save->{savebed}};
119
120 if ($self->{nimbus_exit}{restore}) {
120 $ob->message ("The gods acknowledge your success.\n"); 121 $ob->message ("The gods acknowledge your success.\n");
121 stats_set $ob->stats, $save->{stats}; 122 stats_set $ob->stats, $save->{stats};
122 stats_set $pl->orig_stats, $save->{orig_stats}; 123 stats_set $pl->orig_stats, $save->{orig_stats};
123 $ob->player_lvl_adj; # update overall level 124 $ob->player_lvl_adj; # update overall level
124 skills_set $ob, $save->{skill_exp}; 125 skills_set $ob, $save->{skill_exp};
126 } else {
127 $ob->message ("The gods are disappointed with you.\n");
128 }
129
125 } else { 130 } else {
126 $ob->message ("The gods are disappointed with you.\n"); 131 @savebed = ("/scorn/taverns/inn", 10, 5);
127 } 132 }
128 133
129 } else { 134 $pl->savebed (@savebed);
130 @savebed = ("/scorn/taverns/inn", 10, 5);
131 }
132 135
133 $pl->set_savebed (@savebed); 136 my $map = $ob->map;
134 137
135 my $map = $ob->map; 138 teleport $pl, @savebed;
136 139
137 teleport $pl, @savebed; 140 # should make this a temporary map and let cf deal with it
141 unlink $map->path;
142 unlink $map->path . ".pst";
138 143
139 # should make this a temporary map and let cf deal with it
140 unlink $map->path;
141 unlink $map->path . ".cfperl";
142 $map->delete_map; 144 $map->delete_map;
143 145
144 $pl->play_sound_player_only (cf::SOUND_PLAYER_DIES); 146 $pl->play_sound_player_only (cf::SOUND_PLAYER_DIES);
145 147
146 $ob->message ("You feel as if you woke up from a dream.\n"); 148 $ob->message ("You feel as if you woke up from a dream.\n");
147 $ob->message ("You have a headache.\n"); 149 $ob->message ("You have a headache.\n");
148 $ob->message ("Maybe you should have a drink.\n"); 150 $ob->message ("Maybe you should have a drink.\n");
149 151
150 1 152 cf::override;
151} 153 },
154;
152 155

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines