… | |
… | |
9 | |
9 | |
10 | sub rec_inv_by_slaying { |
10 | sub rec_inv_by_slaying { |
11 | my ($ob, $slaying, $cb) = @_; |
11 | my ($ob, $slaying, $cb) = @_; |
12 | $cb->($ob) if $ob->slaying eq $slaying; |
12 | $cb->($ob) if $ob->slaying eq $slaying; |
13 | for my $iob ($ob->inv) { rec_inv_by_slaying ($iob, $slaying, $cb) } |
13 | for my $iob ($ob->inv) { rec_inv_by_slaying ($iob, $slaying, $cb) } |
|
|
14 | } |
|
|
15 | |
|
|
16 | =item count_linked ($map, $connected) |
|
|
17 | |
|
|
18 | Counts the number of objects with the connected value C<$connected> on |
|
|
19 | the map C<$map>. |
|
|
20 | |
|
|
21 | =cut |
|
|
22 | |
|
|
23 | sub count_linked { |
|
|
24 | my ($map, $connected) = @_; |
|
|
25 | my (@a) = $map->find_link ($connected); |
|
|
26 | scalar @a |
14 | } |
27 | } |
15 | |
28 | |
16 | =item object attachment: 'check_inventory_on_apply' |
29 | =item object attachment: 'check_inventory_on_apply' |
17 | |
30 | |
18 | This attachment checks on apply whether the applyer |
31 | This attachment checks on apply whether the applyer |
… | |
… | |
59 | rec_inv_by_slaying ($pl, $cfg->{key_string}, sub { |
72 | rec_inv_by_slaying ($pl, $cfg->{key_string}, sub { |
60 | my ($ob) = @_; |
73 | my ($ob) = @_; |
61 | $match = $ob; |
74 | $match = $ob; |
62 | }); |
75 | }); |
63 | if ($match) { |
76 | if ($match) { |
64 | $match->decrease_ob_nr ($cfg->{decrease_by_cnt}) if $cfg->{decrease_by_cnt}; |
77 | $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}; |
78 | $pl->message ($cfg->{message_on_match}, cf::NDI_UNIQUE) if defined $cfg->{message_on_match}; |
66 | } else { |
79 | } else { |
67 | $pl->message ($cfg->{message_on_nomatch}, cf::NDI_RED | cf::NDI_UNIQUE) if defined $cfg->{message_on_nomatch}; |
80 | $pl->message ($cfg->{message_on_nomatch}, cf::NDI_RED | cf::NDI_UNIQUE) if defined $cfg->{message_on_nomatch}; |
68 | cf::override; |
81 | cf::override; |
69 | } |
82 | } |
70 | }; |
83 | }; |
71 | |
84 | |
|
|
85 | |
|
|
86 | =item object attachment: 'trigger_on_dialog_flag' |
|
|
87 | |
|
|
88 | This attachment checks whether the player has a specific |
|
|
89 | dialog flag set (the ones you can set with @setflag, see also |
|
|
90 | L<NPC_Dialogue>, and triggers a connection depending on that. |
|
|
91 | |
|
|
92 | The attachment has following configuration: |
|
|
93 | |
|
|
94 | =over 4 |
|
|
95 | |
|
|
96 | =item flag |
|
|
97 | |
|
|
98 | This field should contain the name of the flag that you want to check |
|
|
99 | for. |
|
|
100 | |
|
|
101 | =item connection |
|
|
102 | |
|
|
103 | The connection ID of the connection you want to trigger. |
|
|
104 | |
|
|
105 | =item state |
|
|
106 | |
|
|
107 | The state of the connection: 0 for release, 1 for push. |
|
|
108 | |
72 | =back |
109 | =back |
73 | |
110 | |
74 | =cut |
111 | =cut |
|
|
112 | |
|
|
113 | cf::object::attachment trigger_on_dialog_flag => |
|
|
114 | on_move_trigger => sub { |
|
|
115 | my ($self, $who, $orig) = @_; |
|
|
116 | my $cfg = $self->{trigger_on_dialog_flag}; |
|
|
117 | if (exists $who->{ob}{dialog_flag}{$cfg->{flag}}) { |
|
|
118 | if ($who->{ob}{dialog_flag}{$cfg->{flag}}) { |
|
|
119 | $self->map->trigger ($cfg->{connection}, $cfg->{state}); |
|
|
120 | } |
|
|
121 | cf::override; |
|
|
122 | } |
|
|
123 | }; |
|
|
124 | |
|
|
125 | =item object attachment: 'display_info_window' |
|
|
126 | |
|
|
127 | If you attach this attachment to a sign a window containing the |
|
|
128 | message will open in the client when the player applies it. |
|
|
129 | |
|
|
130 | Use this feature with care, as popups usually are very noisy. |
|
|
131 | This is mostly thought for tutorial or other instructions. |
|
|
132 | |
|
|
133 | =cut |
|
|
134 | |
|
|
135 | cf::object::attachment display_info_window => |
|
|
136 | on_apply => sub { |
|
|
137 | my ($self, $pl) = @_; |
|
|
138 | |
|
|
139 | return unless $pl->contr->ns->{can_widget}; |
|
|
140 | |
|
|
141 | my $cfg = $self->{display_info_window}; |
|
|
142 | |
|
|
143 | if ($pl->contr->ns->{info_wins}->{$self->uuid}) { |
|
|
144 | $pl->contr->ns->{info_wins}->{$self->uuid}->destroy; |
|
|
145 | } |
|
|
146 | |
|
|
147 | my $ws = $pl->contr->ns->new_widgetset; |
|
|
148 | |
|
|
149 | my $w = $ws->{my_main} = $ws->new (Toplevel => |
|
|
150 | force_w => 600, |
|
|
151 | force_h => 400, |
|
|
152 | x => 'center', |
|
|
153 | y => 'center', |
|
|
154 | title => 'Information Sign', |
|
|
155 | has_close_button => 1, |
|
|
156 | on_delete => sub { $ws->destroy }, |
|
|
157 | ); |
|
|
158 | $w->add ($ws->{txt_area} = $ws->new ('TextScroller')); |
|
|
159 | $ws->{txt_area}->add_paragraph ($self->msg); |
|
|
160 | $w->show; |
|
|
161 | $pl->contr->ns->{info_wins}->{$self->uuid} = $ws; |
|
|
162 | |
|
|
163 | cf::override 1; |
|
|
164 | }; |
|
|
165 | |
|
|
166 | =back |
|
|
167 | |
|
|
168 | =cut |