ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/nimbus.ext
Revision: 1.2
Committed: Fri Mar 17 03:13:49 2006 UTC (18 years, 2 months ago) by root
Branch: MAIN
Changes since 1.1: +22 -15 lines
Log Message:
all crossfire-devs are _users.

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     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 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     map +($_->skill => $_->exp),
38     grep $_->type == cf::SKILL,
39     $ob->inv
40     }
41 root 1.1 }
42    
43 root 1.2 sub skills_set($$) {
44     my ($ob, $skill) = @_;
45    
46     for (grep $_->type == cf::SKILL, $ob->inv) {
47     $_->set_exp ($skill->{$_->skill})
48     if exists $skill->{$_->skill};
49     }
50 root 1.1 }
51    
52     # called when the player will likely die (modulo explore mode)
53     # but before any stats/exp is changed
54     sub on_player_death {
55     my ($event) = @_;
56    
57     my $ob = $event->{who};
58     my $pl = $ob->contr;
59    
60     # save player stats and experience to restore it later
61    
62     my $save = {
63     stats => stats_get $ob->stats,
64     orig_stats => stats_get $pl->orig_stats,
65     savebed => [$pl->get_savebed],
66     skill_exp => skills_get $ob,
67     };
68    
69     $ob->{nimbus_save} = $save;
70    
71     my $path = sprintf "%s/%s/%s/%s",
72     cf::localdir, cf::playerdir, $ob->name, "nimbus";
73    
74     my $nimbus = cf::map::get_map "/schmorp/nimbus";
75     $nimbus->set_path ($path);
76     $nimbus->set_unique (1);
77    
78     $pl->set_savebed ($path, 24, 12);
79     }
80    
81     sub on_trigger {
82     my ($event) = @_;
83     my $options = $event->{options};
84     my $ob = $event->{activator};
85     my $pl = $ob->contr;
86     my @savebed;
87    
88     warn "trigger $options $ob->{nimbus_save}\n";#d#
89     warn $ob->name;
90    
91     if (my $save = delete $ob->{nimbus_save}) {
92     @savebed = @{$save->{savebed}};
93    
94 root 1.2 if ($options eq "restore" || 1) {
95     stats_set $ob->stats, $save->{stats};
96     stats_set $pl->orig_stats, $save->{orig_stats};
97     skills_set $ob, $save->{skill_exp};
98     }
99    
100 root 1.1 } else {
101     @savebed = ("/scorn/taverns/inn", 10, 5);
102     }
103    
104     $pl->set_savebed (@savebed);
105    
106     # TODO: you wake up...
107     $ob->teleport (cf::map::get_map $savebed[0], $savebed[1], $savebed[2]);
108    
109     # TODO: invalidate map
110    
111     1
112     }
113