ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/map_lib.ext
Revision: 1.6
Committed: Mon Apr 21 06:35:26 2008 UTC (16 years, 1 month ago) by root
Branch: MAIN
CVS Tags: rel-2_82, rel-2_81, rel-2_80, rel-2_6, rel-2_7, rel-2_72, rel-2_73, rel-2_71, rel-2_76, rel-2_77, rel-2_74, rel-2_75, rel-2_54, rel-2_55, rel-2_56, rel-2_79, rel-2_52, rel-2_53, rel-2_90, rel-2_92, rel-2_93, rel-2_78, rel-2_61
Changes since 1.5: +1 -1 lines
Log Message:
refactor decrease_ob* into ->decrease method.

File Contents

# Content
1 #! perl
2
3 =head1 CF+ map maker library and utilities
4
5 =over 4
6
7 =cut
8 # This extension loads some nice functionality for map makers
9
10 sub rec_inv_by_slaying {
11 my ($ob, $slaying, $cb) = @_;
12 $cb->($ob) if $ob->slaying eq $slaying;
13 for my $iob ($ob->inv) { rec_inv_by_slaying ($iob, $slaying, $cb) }
14 }
15
16 =item object attachment: 'check_inventory_on_apply'
17
18 This attachment checks on apply whether the applyer
19 has a specific item. Currently you can only match the slaying
20 field of the inventory item of the player.
21
22 On match the apply isn't inhibited.
23
24 Following configuration can be supplied to this attachment:
25
26 =over 4
27
28 =item key_string
29
30 This is the string that will be matched against the slaying field
31 of the inventory item of the player. The first found item will be
32 decreased by the amount that can be passed in the 'decrease_by_cnt'
33 option.
34
35 =item decrease_by_cnt
36
37 This is the amount the matching object will be decreased by from the inventory.
38 Default is 0 and means nothing will be removed.
39
40 =item message_on_match
41
42 This is the message that will printed to the player if a matching
43 object was found.
44
45 =item message_on_nomatch
46
47 This is the message that will printed to the player if NO matching
48 object was found.
49
50 =back
51
52 =cut
53
54 cf::object::attachment check_inventory_on_apply =>
55 on_apply => sub {
56 my ($self, $pl) = @_;
57 my $cfg = $self->{check_inventory_on_apply};
58 my $match;
59 rec_inv_by_slaying ($pl, $cfg->{key_string}, sub {
60 my ($ob) = @_;
61 $match = $ob;
62 });
63 if ($match) {
64 $match->decrease ($cfg->{decrease_by_cnt}) if $cfg->{decrease_by_cnt};
65 $pl->message ($cfg->{message_on_match}, cf::NDI_UNIQUE) if defined $cfg->{message_on_match};
66 } else {
67 $pl->message ($cfg->{message_on_nomatch}, cf::NDI_RED | cf::NDI_UNIQUE) if defined $cfg->{message_on_nomatch};
68 cf::override;
69 }
70 };
71
72
73 =item object attachment: 'trigger_on_dialog_flag'
74
75 This attachment checks whether the player has a specific
76 dialog flag set (the ones you can set with @setflag, see also
77 L<NPC_Dialogue>, and triggers a connection depending on that.
78
79 The attachment has following configuration:
80
81 =over 4
82
83 =item flag
84
85 This field should contain the name of the flag that you want to check
86 for.
87
88 =item connection
89
90 The connection ID of the connection you want to trigger.
91
92 =item state
93
94 The state of the connection: 0 for release, 1 for push.
95
96 =back
97
98 =cut
99
100 cf::object::attachment trigger_on_dialog_flag =>
101 on_move_trigger => sub {
102 my ($self, $who, $orig) = @_;
103 my $cfg = $self->{trigger_on_dialog_flag};
104 if (exists $who->{ob}{dialog_flag}{$cfg->{flag}}) {
105 if ($who->{ob}{dialog_flag}{$cfg->{flag}}) {
106 $self->map->trigger ($cfg->{connection}, $cfg->{state});
107 }
108 cf::override;
109 }
110 };
111
112 =item object attachment: 'display_info_window'
113
114 If you attach this attachment to a sign a window containing the
115 message will open in the client when the player applies it.
116
117 Use this feature with care, as popups usually are very noisy.
118 This is mostly thought for tutorial or other instructions.
119
120 =cut
121
122 cf::object::attachment display_info_window =>
123 on_apply => sub {
124 my ($self, $pl) = @_;
125
126 return unless $pl->contr->ns->{can_widget};
127
128 my $cfg = $self->{display_info_window};
129
130 if ($pl->contr->ns->{info_wins}->{$self->uuid}) {
131 $pl->contr->ns->{info_wins}->{$self->uuid}->destroy;
132 }
133
134 my $ws = $pl->contr->ns->new_widgetset;
135
136 my $w = $ws->{my_main} = $ws->new (Toplevel =>
137 force_w => 600,
138 force_h => 400,
139 x => 'center',
140 y => 'center',
141 title => 'Information Sign',
142 has_close_button => 1,
143 on_delete => sub { $ws->destroy },
144 );
145 $w->add ($ws->{txt_area} = $ws->new ('TextScroller'));
146 $ws->{txt_area}->add_paragraph ($self->msg);
147 $w->show;
148 $pl->contr->ns->{info_wins}->{$self->uuid} = $ws;
149
150 cf::override 1;
151 };
152
153 =back
154
155 =cut