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.5 by root, Mon Mar 20 23:28:56 2006 UTC vs.
Revision 1.12 by root, Fri Aug 25 15:07:43 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines