ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/nimbus.ext
Revision: 1.10
Committed: Fri Mar 31 22:47:20 2006 UTC (18 years, 1 month ago) by root
Branch: MAIN
Changes since 1.9: +3 -3 lines
Log Message:
api change

File Contents

# Content
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 exp food dam luck
9 );
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
28 $stats->hp ($stats->maxhp);
29 $stats->grace ($stats->maxgrace);
30 $stats->food (999);
31 }
32
33 sub skills_get($) {
34 my ($ob) = @_;
35
36 +{
37 map +($_->skill => $_->stats->exp),
38 grep $_->type == cf::SKILL,
39 $ob->inv
40 }
41 }
42
43 sub skills_set($$) {
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 }
54 }
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 my ($ob) = @_;
60
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 unless ($ob->{in_nimbus}) {
73 $ob->{in_nimbus} = $save;
74
75 my $path = sprintf "%s/%s/%s/%s",
76 cf::localdir, cf::playerdir, $ob->name, "nimbus";
77
78 my $nimbus = cf::map::get_map "/schmorp/nimbus";
79 $nimbus->set_path ($path);
80 $nimbus->set_unique (1);
81
82 $pl->set_savebed ($path, 24, 12);
83
84 $ob->message ("\n");
85 $ob->message ("You start to feel dizzy.\n");
86 $ob->message ("The world around you blurs.\n");
87 $ob->message ("\n");
88 }
89
90 0
91 }
92
93 sub teleport {
94 my ($pl, $map, $x, $y) = @_;
95
96 return if $pl->ob->map->path eq $map
97 && abs ($pl->ob->x - $x) <= 1
98 && abs ($pl->ob->y - $y) <= 1;
99
100 my $portal = cf::object::new "exit";
101
102 $portal->set_slaying ($map);
103 $portal->set_hp ($x);
104 $portal->set_sp ($y);
105
106 $portal->apply ($pl->ob);
107
108 $portal->free;
109 }
110
111 sub on_trigger {
112 my ($event, $porter, $ob) = @_;
113
114 my $options = $event->options;
115 my $pl = $ob->contr;
116 my @savebed;
117
118 if (my $save = delete $ob->{in_nimbus}) {
119 @savebed = @{$save->{savebed}};
120
121 if ($options eq "restore") {
122 $ob->message ("The gods acknowledge your success.\n");
123 stats_set $ob->stats, $save->{stats};
124 stats_set $pl->orig_stats, $save->{orig_stats};
125 $ob->player_lvl_adj; # update overall level
126 skills_set $ob, $save->{skill_exp};
127 } else {
128 $ob->message ("The gods are disappointed with you.\n");
129 }
130
131 } else {
132 @savebed = ("/scorn/taverns/inn", 10, 5);
133 }
134
135 $pl->set_savebed (@savebed);
136
137 my $map = $ob->map;
138
139 teleport $pl, @savebed;
140
141 # should make this a temporary map and let cf deal with it
142 unlink $map->path;
143 unlink $map->path . ".cfperl";
144 $map->delete_map;
145
146 $pl->play_sound_player_only (cf::SOUND_PLAYER_DIES);
147
148 $ob->message ("You feel as if you woke up from a dream.\n");
149 $ob->message ("You have a headache.\n");
150 $ob->message ("Maybe you should have a drink.\n");
151
152 1
153 }
154