ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/nimbus.ext
Revision: 1.8
Committed: Tue Mar 28 16:08:19 2006 UTC (18 years, 1 month ago) by root
Branch: MAIN
Changes since 1.7: +1 -2 lines
Log Message:
decrossfirefy global event calling conventions

File Contents

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