ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/nimbus.ext
Revision: 1.5
Committed: Mon Mar 20 23:28:56 2006 UTC (18 years, 2 months ago) by root
Branch: MAIN
Changes since 1.4: +22 -7 lines
Log Message:
*** empty log message ***

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 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 "" => $ob->stats->exp,
38
39 map +($_->skill => $_->stats->exp),
40 grep $_->type == cf::SKILL,
41 $ob->inv
42 }
43 }
44
45 sub skills_set($$) {
46 my ($ob, $skill) = @_;
47
48 my $cur = skills_get $ob;
49
50 while (my ($name, $exp) = each %$skill) {
51 if ($cur->{$name} < $exp) {
52 length $name
53 ? $ob->change_skill ($exp - $cur->{$name}, $name)
54 : $ob->change_skill ($exp - $cur->{$name});
55 }
56 }
57 }
58
59 # called when the player will likely die (modulo explore mode)
60 # but before any stats/exp is changed
61 sub on_player_death {
62 my ($event) = @_;
63
64 my $ob = $event->{who};
65 my $pl = $ob->contr;
66
67 # save player stats and experience to restore it later
68
69 my $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
76 $ob->{in_nimbus} ||= $save;
77
78 my $path = sprintf "%s/%s/%s/%s",
79 cf::localdir, cf::playerdir, $ob->name, "nimbus";
80
81 my $nimbus = cf::map::get_map "/schmorp/nimbus";
82 $nimbus->set_path ($path);
83 $nimbus->set_unique (1);
84
85 $pl->set_savebed ($path, 24, 12);
86
87 $pl->message ("\n");
88 $pl->message ("You start to feel dizzy.\n");
89 $pl->message ("The world around you blurs.\n");
90 $pl->message ("\n");
91
92 0
93 }
94
95 sub on_trigger {
96 my ($event) = @_;
97 my $options = $event->{options};
98 my $ob = $event->{activator};
99 my $pl = $ob->contr;
100 my @savebed;
101
102 warn "trigger $options $ob->{nimbus_save}\n";#d#
103 warn $ob->name;
104
105 if (my $save = delete $ob->{in_nimbus}) {
106 @savebed = @{$save->{savebed}};
107
108 if ($options eq "restore" || 1) {
109 stats_set $ob->stats, $save->{stats};
110 stats_set $pl->orig_stats, $save->{orig_stats};
111 skills_set $ob, $save->{skill_exp};
112 }
113
114 } else {
115 @savebed = ("/scorn/taverns/inn", 10, 5);
116 }
117
118 $pl->set_savebed (@savebed);
119
120 my $map = $ob->map;
121
122 $ob->teleport (cf::map::get_map $savebed[0], $savebed[1], $savebed[2]);
123
124 $map->delete_map;
125
126 $pl->message ("You feel as if you woke up from a dream.\n");
127 $pl->message ("You have a headache.\n");
128 $pl->message ("Maybe you should have a drink.\n");
129
130 1
131 }
132