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

Comparing deliantra/maps/perl/nimbus.ext (file contents):
Revision 1.4 by root, Mon Mar 20 22:49:26 2006 UTC vs.
Revision 1.16 by root, Wed Aug 30 12:06:17 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 food dam luck 8 exp food dam luck
9); 9);
10 10
11sub stats_get($) { 11sub stats_get($) {
12 my ($stats, $save) = @_; 12 my ($stats, $save) = @_;
13 13
32 32
33sub skills_get($) { 33sub skills_get($) {
34 my ($ob) = @_; 34 my ($ob) = @_;
35 35
36 +{ 36 +{
37 "" => $ob->stats->exp,
38
39 map +($_->skill => $_->stats->exp), 37 map +($_->skill => $_->stats->exp),
40 grep $_->type == cf::SKILL, 38 grep $_->type == cf::SKILL,
41 $ob->inv 39 $ob->inv
42 } 40 }
43} 41}
44 42
45sub skills_set($$) { 43sub skills_set($$) {
46 my ($ob, $skill) = @_; 44 my ($ob, $skills) = @_;
47 45
48 for (grep $_->type == cf::SKILL, $ob->inv) { 46 for my $skill (grep $_->type == cf::SKILL, $ob->inv) {
49 $_->set_exp ($skill->{$_->skill}) 47 my $name = $skill->skill;
50 if exists $skill->{$_->skill}; 48
49 if ($skill->stats->exp < $skills->{$name}) {
50 $skill->stats->exp ($skills->{$name});
51 $ob->player_lvl_adj ($skill);
52 }
51 } 53 }
52} 54}
53 55
54# called when the player will likely die (modulo explore mode) 56# called when the player will likely die (modulo explore mode)
55# but before any stats/exp is changed 57# but before any stats/exp is changed
56sub on_player_death { 58cf::attach_to_players
59 on_death => sub {
57 my ($event) = @_; 60 my ($pl) = @_;
61 my $ob = $pl->ob;
58 62
59 my $ob = $event->{who}; 63 # save player stats and experience to restore it later
60 my $pl = $ob->contr;
61 64
62 # save player stats and experience to restore it later 65 unless ($ob->{in_nimbus}) {
66 my $save = {
67 stats => stats_get $ob->stats,
68 orig_stats => stats_get $pl->orig_stats,
69 savebed => [$pl->get_savebed],
70 skill_exp => skills_get $ob,
71 };
63 72
64 my $save = { 73 $ob->{in_nimbus} = $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 74
71 $ob->{nimbus_save} ||= $save; 75 $ob->message ("\n");
76 $ob->message ("You start to feel dizzy.\n");
77 $ob->message ("The world around you blurs.\n");
78 $ob->message ("\n");
79 }
72 80
73 my $path = sprintf "%s/%s/%s/%s", 81 my $path = sprintf "%s/%s/%s/%s",
74 cf::localdir, cf::playerdir, $ob->name, "nimbus"; 82 cf::localdir, cf::playerdir, $ob->name, "nimbus";
75 83
84 if ($ob->map->path ne $path) {
76 my $nimbus = cf::map::get_map "/schmorp/nimbus"; 85 my $nimbus = cf::map::find "/schmorp/nimbus";
77 $nimbus->set_path ($path); 86 $nimbus->set_path ($path);
78 $nimbus->set_unique (1); 87 $nimbus->set_unique (1);
79 88
80 $pl->set_savebed ($path, 24, 12); 89 $pl->set_savebed ($path, 24, 12);
90 }
91 },
92;
81 93
82 0 94sub teleport {
95 my ($pl, $map, $x, $y) = @_;
96
97 return if $pl->ob->map->path eq $map
98 && abs ($pl->ob->x - $x) <= 1
99 && abs ($pl->ob->y - $y) <= 1;
100
101 my $portal = cf::object::new "exit";
102
103 $portal->set_slaying ($map);
104 $portal->set_hp ($x);
105 $portal->set_sp ($y);
106
107 $portal->apply ($pl->ob);
108
109 $portal->free;
83} 110}
84 111
85sub on_trigger { 112cf::register_attachment nimbus_exit =>
86 my ($event) = @_; 113 on_trigger => sub {
87 my $options = $event->{options}; 114 my ($self, $ob) = @_;
88 my $ob = $event->{activator};
89 my $pl = $ob->contr;
90 my @savebed;
91 115
92 warn "trigger $options $ob->{nimbus_save}\n";#d# 116 my $pl = $ob->contr;
93 warn $ob->name; 117 my @savebed;
94 118
95 if (my $save = delete $ob->{nimbus_save}) { 119 if (my $save = delete $ob->{in_nimbus}) {
96 @savebed = @{$save->{savebed}}; 120 @savebed = @{$save->{savebed}};
97 121
98 if ($options eq "restore" || 1) { 122 if ($self->{nimbus_exit}{restore}) {
123 $ob->message ("The gods acknowledge your success.\n");
99 stats_set $ob->stats, $save->{stats}; 124 stats_set $ob->stats, $save->{stats};
100 stats_set $pl->orig_stats, $save->{orig_stats}; 125 stats_set $pl->orig_stats, $save->{orig_stats};
126 $ob->player_lvl_adj; # update overall level
101 skills_set $ob, $save->{skill_exp}; 127 skills_set $ob, $save->{skill_exp};
128 } else {
129 $ob->message ("The gods are disappointed with you.\n");
130 }
131
132 } else {
133 @savebed = ("/scorn/taverns/inn", 10, 5);
102 } 134 }
103 135
104 } else { 136 $pl->set_savebed (@savebed);
105 @savebed = ("/scorn/taverns/inn", 10, 5);
106 }
107 137
108 $pl->set_savebed (@savebed); 138 my $map = $ob->map;
109 139
110 # TODO: you wake up... 140 teleport $pl, @savebed;
111 $ob->teleport (cf::map::get_map $savebed[0], $savebed[1], $savebed[2]);
112 141
113 # TODO: invalidate map 142 # should make this a temporary map and let cf deal with it
143 unlink $map->path;
144 unlink $map->path . ".pst";
114 145
115 1 146 $map->delete_map;
116}
117 147
148 $pl->play_sound_player_only (cf::SOUND_PLAYER_DIES);
149
150 $ob->message ("You feel as if you woke up from a dream.\n");
151 $ob->message ("You have a headache.\n");
152 $ob->message ("Maybe you should have a drink.\n");
153
154 cf::override;
155 },
156;
157

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines