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.5 by root, Mon Mar 20 23:28:56 2006 UTC vs.
Revision 1.18 by root, Fri Sep 8 17:33:55 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines