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.5 by root, Mon Mar 20 23:28:56 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 my $cur = skills_get $ob; 46 for my $skill (grep $_->type == cf::SKILL, $ob->inv) {
47 my $name = $skill->skill;
49 48
50 while (my ($name, $exp) = each %$skill) { 49 if ($skill->stats->exp < $skills->{$name}) {
51 if ($cur->{$name} < $exp) { 50 $skill->stats->exp ($skills->{$name});
52 length $name 51 $ob->player_lvl_adj ($skill);
53 ? $ob->change_skill ($exp - $cur->{$name}, $name)
54 : $ob->change_skill ($exp - $cur->{$name});
55 } 52 }
56 } 53 }
57} 54}
58 55
59# called when the player will likely die (modulo explore mode) 56# called when the player will likely die (modulo explore mode)
60# but before any stats/exp is changed 57# but before any stats/exp is changed
61sub on_player_death { 58cf::attach_to_players
59 on_death => sub {
62 my ($event) = @_; 60 my ($pl) = @_;
61 my $ob = $pl->ob;
63 62
64 my $ob = $event->{who}; 63 # save player stats and experience to restore it later
65 my $pl = $ob->contr;
66 64
67 # 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 };
68 72
69 my $save = { 73 $ob->{in_nimbus} = $save;
70 stats => stats_get $ob->stats,
71 orig_stats => stats_get $pl->orig_stats,
72 savebed => [$pl->get_savebed],
73 skill_exp => skills_get $ob,
74 };
75 74
76 $ob->{in_nimbus} ||= $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 }
77 80
78 my $path = sprintf "%s/%s/%s/%s", 81 my $path = sprintf "%s/%s/%s/%s",
79 cf::localdir, cf::playerdir, $ob->name, "nimbus"; 82 cf::localdir, cf::playerdir, $ob->name, "nimbus";
80 83
84 if ($ob->map->path ne $path) {
81 my $nimbus = cf::map::get_map "/schmorp/nimbus"; 85 my $nimbus = cf::map::find "/schmorp/nimbus";
82 $nimbus->set_path ($path); 86 $nimbus->set_path ($path);
83 $nimbus->set_unique (1); 87 $nimbus->set_unique (1);
84 88
85 $pl->set_savebed ($path, 24, 12); 89 $pl->set_savebed ($path, 24, 12);
90 }
91 },
92;
86 93
87 $pl->message ("\n"); 94sub teleport {
88 $pl->message ("You start to feel dizzy.\n"); 95 my ($pl, $map, $x, $y) = @_;
89 $pl->message ("The world around you blurs.\n");
90 $pl->message ("\n");
91 96
92 0 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;
93} 110}
94 111
95sub on_trigger { 112cf::register_attachment nimbus_exit =>
96 my ($event) = @_; 113 on_trigger => sub {
97 my $options = $event->{options}; 114 my ($self, $ob) = @_;
98 my $ob = $event->{activator};
99 my $pl = $ob->contr;
100 my @savebed;
101 115
102 warn "trigger $options $ob->{nimbus_save}\n";#d# 116 my $pl = $ob->contr;
103 warn $ob->name; 117 my @savebed;
104 118
105 if (my $save = delete $ob->{in_nimbus}) { 119 if (my $save = delete $ob->{in_nimbus}) {
106 @savebed = @{$save->{savebed}}; 120 @savebed = @{$save->{savebed}};
107 121
108 if ($options eq "restore" || 1) { 122 if ($self->{nimbus_exit}{restore}) {
123 $ob->message ("The gods acknowledge your success.\n");
109 stats_set $ob->stats, $save->{stats}; 124 stats_set $ob->stats, $save->{stats};
110 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
111 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);
112 } 134 }
113 135
114 } else { 136 $pl->set_savebed (@savebed);
115 @savebed = ("/scorn/taverns/inn", 10, 5);
116 }
117 137
118 $pl->set_savebed (@savebed); 138 my $map = $ob->map;
119 139
120 my $map = $ob->map; 140 teleport $pl, @savebed;
121 141
122 $ob->teleport (cf::map::get_map $savebed[0], $savebed[1], $savebed[2]); 142 # should make this a temporary map and let cf deal with it
143 unlink $map->path;
144 unlink $map->path . ".pst";
123 145
124 $map->delete_map; 146 $map->delete_map;
125 147
126 $pl->message ("You feel as if you woke up from a dream.\n"); 148 $pl->play_sound_player_only (cf::SOUND_PLAYER_DIES);
127 $pl->message ("You have a headache.\n");
128 $pl->message ("Maybe you should have a drink.\n");
129 149
130 1 150 $ob->message ("You feel as if you woke up from a dream.\n");
131} 151 $ob->message ("You have a headache.\n");
152 $ob->message ("Maybe you should have a drink.\n");
132 153
154 cf::override;
155 },
156;
157

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines