ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/nimbus.ext
Revision: 1.13
Committed: Fri Jan 2 16:41:32 2009 UTC (15 years, 4 months ago) by root
Branch: MAIN
CVS Tags: rel-2_82, rel-2_81, rel-2_80, rel-3_1, rel-3_0, rel-2_76, rel-2_77, rel-2_75, rel-2_79, rel-2_90, rel-2_92, rel-2_93, rel-2_78, HEAD
Changes since 1.12: +2 -2 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #! perl # mandatory
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 $save->{$_} = $stats->$_
15 for @STATS;
16
17 $save
18 }
19
20 sub stats_set($$) {
21 my ($stats, $save) = @_;
22
23 $stats->$_ ($save->{$_})
24 for @STATS;
25
26 $stats->hp ($stats->maxhp);
27 $stats->grace ($stats->maxgrace);
28 $stats->food (999);
29 }
30
31 sub skills_get($) {
32 my ($ob) = @_;
33
34 +{
35 map +($_->skill => $_->stats->exp),
36 grep $_->type == cf::SKILL,
37 $ob->inv
38 }
39 }
40
41 sub skills_set($$) {
42 my ($ob, $skills) = @_;
43
44 for my $skill (grep $_->type == cf::SKILL, $ob->inv) {
45 my $name = $skill->skill;
46
47 if ($skill->stats->exp < $skills->{$name}) {
48 $skill->stats->exp ($skills->{$name});
49 $ob->player_lvl_adj ($skill);
50 }
51 }
52 }
53
54 # called when the player will likely die (modulo explore mode)
55 # but before any stats/exp is changed
56 cf::player->attach (
57 on_death => sub {
58 my ($pl) = @_;
59 my $ob = $pl->ob;
60
61 # save player stats and experience to restore it later
62
63 unless ($ob->{in_nimbus}) {
64 my $save = {
65 stats => stats_get $ob->stats,
66 orig_stats => stats_get $pl->orig_stats,
67 savebed => [$pl->savebed],
68 skill_exp => skills_get $ob,
69 };
70
71 $ob->{in_nimbus} = $save;
72
73 $ob->message ("\n");
74 $ob->message ("You start to feel dizzy.\n");
75 $ob->message ("The world around you blurs.\n");
76 $ob->message ("\n");
77
78 $pl->savebed ("/nimbus", 24, 12);
79 }
80 },
81 );
82
83 cf::object::attachment nimbus_exit =>
84 on_trigger => sub {
85 my ($self, $ob) = @_;
86
87 my $pl = $ob->contr;
88 my @savebed;
89
90 if (my $save = delete $ob->{in_nimbus}) {
91 @savebed = @{$save->{savebed}};
92
93 if ($self->{nimbus_exit}{restore}) {
94 $ob->message ("The gods acknowledge your success.\n");
95 stats_set $ob->stats, $save->{stats};
96 stats_set $pl->orig_stats, $save->{orig_stats};
97 $ob->player_lvl_adj; # update overall level
98 skills_set $ob, $save->{skill_exp};
99 } else {
100 $ob->message ("The gods are disappointed with you.\n");
101 }
102
103 } else {
104 @savebed = ("/scorn/taverns/inn", 10, 5);
105 }
106
107 my $map = $ob->map;
108 $pl->savebed (@savebed);
109
110 cf::async {
111 $Coro::current->{desc} = "nimbus exit";
112 $ob->goto (@savebed);
113
114 $map->nuke;
115
116 #$pl->play_sound (cf::sound::find "player_dies");
117
118 $ob->message ("You feel as if you woke up from a dream.\n"
119 . "You have a headache.\n"
120 . "Maybe you should have a drink.\n");
121 };
122
123 cf::override;
124 },
125 ;
126