ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/nimbus.ext
Revision: 1.4
Committed: Mon Mar 20 22:49:26 2006 UTC (18 years, 2 months ago) by root
Branch: MAIN
Changes since 1.3: +6 -2 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     for (grep $_->type == cf::SKILL, $ob->inv) {
49     $_->set_exp ($skill->{$_->skill})
50     if exists $skill->{$_->skill};
51     }
52 root 1.1 }
53    
54     # called when the player will likely die (modulo explore mode)
55     # but before any stats/exp is changed
56     sub on_player_death {
57     my ($event) = @_;
58    
59     my $ob = $event->{who};
60     my $pl = $ob->contr;
61    
62     # save player stats and experience to restore it later
63    
64     my $save = {
65     stats => stats_get $ob->stats,
66     orig_stats => stats_get $pl->orig_stats,
67     savebed => [$pl->get_savebed],
68     skill_exp => skills_get $ob,
69     };
70    
71 root 1.4 $ob->{nimbus_save} ||= $save;
72 root 1.1
73     my $path = sprintf "%s/%s/%s/%s",
74     cf::localdir, cf::playerdir, $ob->name, "nimbus";
75    
76     my $nimbus = cf::map::get_map "/schmorp/nimbus";
77     $nimbus->set_path ($path);
78     $nimbus->set_unique (1);
79    
80     $pl->set_savebed ($path, 24, 12);
81 root 1.4
82     0
83 root 1.1 }
84    
85     sub on_trigger {
86     my ($event) = @_;
87     my $options = $event->{options};
88     my $ob = $event->{activator};
89     my $pl = $ob->contr;
90     my @savebed;
91    
92     warn "trigger $options $ob->{nimbus_save}\n";#d#
93     warn $ob->name;
94    
95     if (my $save = delete $ob->{nimbus_save}) {
96     @savebed = @{$save->{savebed}};
97    
98 root 1.2 if ($options eq "restore" || 1) {
99     stats_set $ob->stats, $save->{stats};
100     stats_set $pl->orig_stats, $save->{orig_stats};
101     skills_set $ob, $save->{skill_exp};
102     }
103    
104 root 1.1 } else {
105     @savebed = ("/scorn/taverns/inn", 10, 5);
106     }
107    
108     $pl->set_savebed (@savebed);
109    
110     # TODO: you wake up...
111     $ob->teleport (cf::map::get_map $savebed[0], $savebed[1], $savebed[2]);
112    
113     # TODO: invalidate map
114    
115     1
116     }
117