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.1 by root, Fri Mar 17 02:40:09 2006 UTC vs.
Revision 1.11 by root, Sat Apr 8 14:53:12 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines