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

# 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.4 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.4 "" => $ob->stats->exp,
38    
39 root 1.3 map +($_->skill => $_->stats->exp),
40 root 1.2 grep $_->type == cf::SKILL,
41     $ob->inv
42     }
43 root 1.1 }
44    
45 root 1.2 sub skills_set($$) {
46     my ($ob, $skill) = @_;
47    
48 root 1.5 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 root 1.2 }
57 root 1.1 }
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 root 1.5 $ob->{in_nimbus} ||= $save;
77 root 1.1
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 root 1.4
87 root 1.5 $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 root 1.4 0
93 root 1.1 }
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 root 1.5 if (my $save = delete $ob->{in_nimbus}) {
106 root 1.1 @savebed = @{$save->{savebed}};
107    
108 root 1.2 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 root 1.1 } else {
115     @savebed = ("/scorn/taverns/inn", 10, 5);
116     }
117    
118     $pl->set_savebed (@savebed);
119    
120 root 1.5 my $map = $ob->map;
121    
122 root 1.1 $ob->teleport (cf::map::get_map $savebed[0], $savebed[1], $savebed[2]);
123    
124 root 1.5 $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 root 1.1
130     1
131     }
132