ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/nimbus.ext
Revision: 1.1
Committed: Fri Mar 17 02:40:09 2006 UTC (18 years, 2 months ago) by root
Branch: MAIN
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 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_fix($) {
22 my ($stats) = @_;
23
24 $stats->hp = $stats->maxhp;
25 $stats->grace = $stats->maxgrace;
26 $stats->food = 999;
27 }
28
29 sub stats_set($$) {
30 my ($stats, $save) = @_;
31
32 for my $stat (@STATS) {
33 $stats->$stat ($save->{$stat});
34 }
35 }
36
37 sub skills_get($) {
38 my ($ob) = @_;
39
40 [map [$_->skill, $_->exp],
41 grep $_->type == cf::SKILL,
42 $ob->inv]
43 }
44
45 sub skills_set($) {
46 die;
47 }
48
49 # called when the player will likely die (modulo explore mode)
50 # but before any stats/exp is changed
51 sub on_player_death {
52 my ($event) = @_;
53
54 my $ob = $event->{who};
55 my $pl = $ob->contr;
56
57 # save player stats and experience to restore it later
58
59 my $save = {
60 stats => stats_get $ob->stats,
61 orig_stats => stats_get $pl->orig_stats,
62 savebed => [$pl->get_savebed],
63 skill_exp => skills_get $ob,
64 };
65
66 $ob->{nimbus_save} = $save;
67
68 my $path = sprintf "%s/%s/%s/%s",
69 cf::localdir, cf::playerdir, $ob->name, "nimbus";
70
71 my $nimbus = cf::map::get_map "/schmorp/nimbus";
72 $nimbus->set_path ($path);
73 $nimbus->set_unique (1);
74
75 $pl->set_savebed ($path, 24, 12);
76 }
77
78 sub on_trigger {
79 my ($event) = @_;
80 my $options = $event->{options};
81 my $ob = $event->{activator};
82 my $pl = $ob->contr;
83 my @savebed;
84
85 warn "trigger $options $ob->{nimbus_save}\n";#d#
86 warn $ob->name;
87
88 if (my $save = delete $ob->{nimbus_save}) {
89 @savebed = @{$save->{savebed}};
90
91 use Data::Dumper;
92 print STDERR Dumper $save;
93 } else {
94 @savebed = ("/scorn/taverns/inn", 10, 5);
95 }
96
97 $pl->set_savebed (@savebed);
98
99 # TODO: you wake up...
100 $ob->teleport (cf::map::get_map $savebed[0], $savebed[1], $savebed[2]);
101
102 # TODO: invalidate map
103
104 1
105 }
106