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

Comparing deliantra/maps/perl/nimbus.ext (file contents):
Revision 1.7 by root, Tue Mar 21 02:06:23 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 ($event) = @_; 58 my ($pl) = @_;
59 my $ob = $pl->ob;
60 60
61 my $ob = $event->{who}; 61 # save player stats and experience to restore it later
62 my $pl = $ob->contr;
63 62
64 # 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 };
65 70
66 my $save = { 71 $ob->{in_nimbus} = $save;
67 stats => stats_get $ob->stats,
68 orig_stats => stats_get $pl->orig_stats,
69 savebed => [$pl->get_savebed],
70 skill_exp => skills_get $ob,
71 };
72 72
73 $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 }
74 78
75 my $path = sprintf "%s/%s/%s/%s", 79 my $path = sprintf "%s/%s/%s/%s",
76 cf::localdir, cf::playerdir, $ob->name, "nimbus"; 80 cf::localdir, cf::playerdir, $ob->name, "nimbus";
77 81
82 if ($ob->map->path ne $path) {
78 my $nimbus = cf::map::get_map "/schmorp/nimbus"; 83 my $nimbus = cf::map::find "/schmorp/nimbus";
79 $nimbus->set_path ($path); 84 $nimbus->path ($path);
80 $nimbus->set_unique (1); 85 $nimbus->unique (1);
81 86
82 $pl->set_savebed ($path, 24, 12); 87 $pl->savebed ($path, 24, 12);
83 88 }
84 $ob->message ("\n"); 89 },
85 $ob->message ("You start to feel dizzy.\n"); 90;
86 $ob->message ("The world around you blurs.\n");
87 $ob->message ("\n");
88
89 0
90}
91 91
92sub teleport { 92sub teleport {
93 my ($pl, $map, $x, $y) = @_; 93 my ($pl, $map, $x, $y) = @_;
94 94
95 return if $pl->ob->map->path eq $map 95 return if $pl->ob->map->path eq $map
96 && abs ($pl->ob->x - $x) <= 1 96 && abs ($pl->ob->x - $x) <= 1
97 && abs ($pl->ob->y - $y) <= 1; 97 && abs ($pl->ob->y - $y) <= 1;
98 98
99 my $portal = cf::object::new "exit"; 99 my $portal = cf::object::new "exit";
100 100
101 $portal->set_slaying ($map); 101 $portal->slaying ($map);
102 $portal->set_hp ($x); 102 $portal->stats->hp ($x);
103 $portal->set_sp ($y); 103 $portal->stats->sp ($y);
104 104
105 $portal->apply ($pl->ob); 105 $portal->apply ($pl->ob);
106 106
107 $portal->free; 107 $portal->destroy;
108} 108}
109 109
110sub on_trigger { 110cf::register_attachment nimbus_exit =>
111 my ($event) = @_; 111 on_trigger => sub {
112 my $options = $event->{options}; 112 my ($self, $ob) = @_;
113 my $ob = $event->{activator};
114 my $pl = $ob->contr;
115 my @savebed;
116 113
117 if (my $save = delete $ob->{in_nimbus}) { 114 my $pl = $ob->contr;
118 @savebed = @{$save->{savebed}}; 115 my @savebed;
119 116
120 if ($options eq "restore") { 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"); 121 $ob->message ("The gods acknowledge your success.\n");
122 stats_set $ob->stats, $save->{stats}; 122 stats_set $ob->stats, $save->{stats};
123 stats_set $pl->orig_stats, $save->{orig_stats}; 123 stats_set $pl->orig_stats, $save->{orig_stats};
124 $ob->player_lvl_adj; # update overall level 124 $ob->player_lvl_adj; # update overall level
125 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
126 } else { 130 } else {
127 $ob->message ("The gods are disappointed with you.\n"); 131 @savebed = ("/scorn/taverns/inn", 10, 5);
128 } 132 }
129 133
130 } else { 134 $pl->savebed (@savebed);
131 @savebed = ("/scorn/taverns/inn", 10, 5);
132 }
133 135
134 $pl->set_savebed (@savebed); 136 my $map = $ob->map;
135 137
136 my $map = $ob->map; 138 teleport $pl, @savebed;
137 139
138 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";
139 143
140 # should make this a temporary map and let cf deal with it
141 unlink $map->path;
142 unlink $map->path . ".cfperl";
143 $map->delete_map; 144 $map->delete_map;
144 145
145 $pl->play_sound_player_only (cf::SOUND_PLAYER_DIES); 146 $pl->play_sound_player_only (cf::SOUND_PLAYER_DIES);
146 147
147 $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");
148 $ob->message ("You have a headache.\n"); 149 $ob->message ("You have a headache.\n");
149 $ob->message ("Maybe you should have a drink.\n"); 150 $ob->message ("Maybe you should have a drink.\n");
150 151
151 1 152 cf::override;
152} 153 },
154;
153 155

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines