ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cf.schmorp.de/maps/perl/nimbus.ext
(Generate patch)

Comparing cf.schmorp.de/maps/perl/nimbus.ext (file contents):
Revision 1.1 by root, Fri Mar 17 02:40:09 2006 UTC vs.
Revision 1.4 by root, Mon Mar 20 22:49:26 2006 UTC

3# handle the nimbus map and other stuff 3# handle the nimbus map and other stuff
4 4
5my @STATS = qw( 5my @STATS = qw(
6 Str Dex Con Wis Cha Int Pow 6 Str Dex Con Wis Cha Int Pow
7 wc ac hp maxhp sp maxsp grace maxgrace 7 wc ac hp maxhp sp maxsp grace maxgrace
8 exp food dam luck 8 food dam luck
9); 9);
10 10
11sub stats_get($) { 11sub stats_get($) {
12 my ($stats, $save) = @_; 12 my ($stats, $save) = @_;
13 13
16 } 16 }
17 17
18 $save 18 $save
19} 19}
20 20
21sub stats_fix($) {
22 my ($stats) = @_;
23
24 $stats->hp = $stats->maxhp;
25 $stats->grace = $stats->maxgrace;
26 $stats->food = 999;
27}
28
29sub stats_set($$) { 21sub stats_set($$) {
30 my ($stats, $save) = @_; 22 my ($stats, $save) = @_;
31 23
32 for my $stat (@STATS) { 24 for my $stat (@STATS) {
33 $stats->$stat ($save->{$stat}); 25 $stats->$stat ($save->{$stat});
34 } 26 }
27
28 $stats->hp ($stats->maxhp);
29 $stats->grace ($stats->maxgrace);
30 $stats->food (999);
35} 31}
36 32
37sub skills_get($) { 33sub skills_get($) {
38 my ($ob) = @_; 34 my ($ob) = @_;
39 35
40 [map [$_->skill, $_->exp], 36 +{
37 "" => $ob->stats->exp,
38
39 map +($_->skill => $_->stats->exp),
41 grep $_->type == cf::SKILL, 40 grep $_->type == cf::SKILL,
42 $ob->inv] 41 $ob->inv
42 }
43} 43}
44 44
45sub skills_set($) { 45sub skills_set($$) {
46 die; 46 my ($ob, $skill) = @_;
47
48 for (grep $_->type == cf::SKILL, $ob->inv) {
49 $_->set_exp ($skill->{$_->skill})
50 if exists $skill->{$_->skill};
51 }
47} 52}
48 53
49# called when the player will likely die (modulo explore mode) 54# called when the player will likely die (modulo explore mode)
50# but before any stats/exp is changed 55# but before any stats/exp is changed
51sub on_player_death { 56sub on_player_death {
61 orig_stats => stats_get $pl->orig_stats, 66 orig_stats => stats_get $pl->orig_stats,
62 savebed => [$pl->get_savebed], 67 savebed => [$pl->get_savebed],
63 skill_exp => skills_get $ob, 68 skill_exp => skills_get $ob,
64 }; 69 };
65 70
66 $ob->{nimbus_save} = $save; 71 $ob->{nimbus_save} ||= $save;
67 72
68 my $path = sprintf "%s/%s/%s/%s", 73 my $path = sprintf "%s/%s/%s/%s",
69 cf::localdir, cf::playerdir, $ob->name, "nimbus"; 74 cf::localdir, cf::playerdir, $ob->name, "nimbus";
70 75
71 my $nimbus = cf::map::get_map "/schmorp/nimbus"; 76 my $nimbus = cf::map::get_map "/schmorp/nimbus";
72 $nimbus->set_path ($path); 77 $nimbus->set_path ($path);
73 $nimbus->set_unique (1); 78 $nimbus->set_unique (1);
74 79
75 $pl->set_savebed ($path, 24, 12); 80 $pl->set_savebed ($path, 24, 12);
81
82 0
76} 83}
77 84
78sub on_trigger { 85sub on_trigger {
79 my ($event) = @_; 86 my ($event) = @_;
80 my $options = $event->{options}; 87 my $options = $event->{options};
86 warn $ob->name; 93 warn $ob->name;
87 94
88 if (my $save = delete $ob->{nimbus_save}) { 95 if (my $save = delete $ob->{nimbus_save}) {
89 @savebed = @{$save->{savebed}}; 96 @savebed = @{$save->{savebed}};
90 97
91 use Data::Dumper; 98 if ($options eq "restore" || 1) {
92 print STDERR Dumper $save; 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
93 } else { 104 } else {
94 @savebed = ("/scorn/taverns/inn", 10, 5); 105 @savebed = ("/scorn/taverns/inn", 10, 5);
95 } 106 }
96 107
97 $pl->set_savebed (@savebed); 108 $pl->set_savebed (@savebed);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines