blib/lib/auto/share/dist/Games-Axmud/plugins/_wilderness_cmds.pm untested

filter: Statementstmt 0.0% 0 / 83 Branchbran 0.0% 0 / 28 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 118 CC 15 SCAR 50.5
CC
15
Cov
0%
do
210.0
new
6.0
BEGIN
2.0
CRAP 155.7
1 #!/usr/bin/perl -w
2  
3 # Client commands for the 'wilderness' plugin
4  
5 { package Games::Axmud::Cmd::Plugin::WildEmpire;
6  
7 use strict;
8 use warnings;
9 # use diagnostics;
10  
11 use Glib qw(TRUE FALSE);
12  
13 our @ISA = qw(Games::Axmud::Generic::Plugin::Cmd Games::Axmud::Generic::Cmd Games::Axmud);
14  
15 ##################
16 # Constructors
17  
18 sub new {
19  
20 # Create a new instance of this command object (there should only be one)
21 #
22 # Expected arguments
23 # (none besides $class)
24 #
25 # Return values
26 # 'undef' if GA::Generic::Cmd->new reports an error
27 # Blessed reference to the new object on success
28  
29 my ($class, $check) = @_;
30  
31 # Setup
32 my $self = Games::Axmud::Generic::Cmd->new('wildempire', FALSE, TRUE);
33 if (! $self) {return undef};
34  
35 $self->{defaultUserCmdList} = ['wempire', 'wildempire'];
36 $self->{userCmdList} = \@{$self->{defaultUserCmdList}};
37 $self->{descrip} = '(wilderness plugin) Sets EmpireMUD wilderness mode',
38  
39 # Bless the object into existence
40 bless $self, $class;
41 return $self;
42 }
43  
44 ##################
45 # Methods
46  
47 sub do {
48  
49 my (
50 $self, $session, $inputString, $userCmd, $standardCmd,
51 $check,
52 ) = @_;
53  
54 # Local variables
55 my ($worldObj, $modifyFlag, $compObj);
56  
57 # Check for improper arguments
58 if (defined $check) {
59  
60 return $self->improper($session, $inputString);
61 }
62  
63 # Import the current world profile (for convenience)
64 $worldObj = $session->currentWorld;
65  
66 # Must be connected to EmpireMUD
67 if ($worldObj->name ne 'empire') {
68  
69 return $self->error(
70 $session, $inputString,
71 'You must be connected to EmpireMUD 2.0 (in online or offline mode) to use this'
72 . ' command',
73 );
74 }
75  
76 # This command replaces the room statement component 'verb_exit_1' with 'ignore_line_99', or
77 # vice-versa
78 # (We use the number 99 to reduced the probablity of overwriting any components the user
79 # might have added themselves)
80 # We can check for their existence to see if we are modifying or reverting changes to the
81 # profile
82 if (defined $worldObj->ivFind('verboseComponentList', 'verb_exit_1')) {
83  
84 $modifyFlag = TRUE;
85  
86 } elsif (defined $worldObj->ivFind('verboseComponentList', 'ignore_line_99')) {
87  
88 $modifyFlag = FALSE;
89  
90 } else {
91  
92 # Applying our modifications on top of the user's own modifications might be
93 # disastrous, so simply refuse to do it
94 return $self->error(
95 $session, $inputString,
96 'The world profile has been modified from its pre-configured state, so this plugin'
97 . ' can\'t be used to modify it further',
98 );
99 }
100  
101 # Convert world profile to use wilderness mode
102 if ($modifyFlag) {
103  
104 # If the 'ignore_line_99' component doesn't exist, create it
105 if (! $worldObj->ivExists('componentHash', 'ignore_line_99')) {
106  
107 $compObj = Games::Axmud::Obj::Component->new(
108 $session,
109 $worldObj,
110 'ignore_line_99',
111 'ignore_line',
112 );
113  
114 if ($compObj) {
115  
116 $compObj->{size} = 0;
117 $compObj->{minSize} = 0;
118 $compObj->{maxSize} = 1;
119 $compObj->{analyseMode} = 'check_line';
120 $compObj->{boldSensitiveFlag} = FALSE;
121 $compObj->{useInitialTagsFlag} = FALSE;
122 $compObj->{combineLinesFlag} = FALSE; # Separate lines
123  
124 $compObj->{startPatternList} = [
125 '^\+\-{20,}\+$',
126 ];
127 $compObj->{startTagList} = [];
128 $compObj->{startAllFlag} = FALSE;
129 $compObj->{startTagMode} = 'default';
130  
131 $worldObj->ivAdd('componentHash', $compObj->name, $compObj);
132 }
133  
134 } else {
135  
136 $compObj = $worldObj->ivShow('componentHash', 'ignore_line_99');
137 }
138  
139 # Update IVs
140 $worldObj->ivEmpty('exitAliasHash');
141  
142 $worldObj->ivSplice(
143 'verboseComponentList',
144 $worldObj->ivMatch('verboseComponentList', 'verb_exit_1'),
145 1,
146 'ignore_line_99',
147 );
148  
149 # Set the painter to draw 'wilderness' rooms, by default
150 $session->worldModelObj->painterObj->ivPoke('wildMode', 'wild');
151  
152 # For user's convenience, turn on autocompletion of twin exits
153 $session->worldModelObj->ivPoke('autocompleteExitsFlag', TRUE);
154  
155 # Revert world profile from wilderness mode
156 } else {
157  
158 # The component should still exist but, if not, create it
159 if (! $worldObj->ivExists('componentHash', 'verb_exit_1')) {
160  
161 $compObj = Games::Axmud::Obj::Component->new(
162 $session,
163 $worldObj,
164 'verb_exit_1',
165 'verb_exit',
166 );
167  
168 if ($compObj) {
169  
170 $compObj->{size} = 0;
171 $compObj->{minSize} = 0;
172 $compObj->{maxSize} = 1;
173 $compObj->{analyseMode} = 'check_line';
174 $compObj->{boldSensitiveFlag} = FALSE;
175 $compObj->{useInitialTagsFlag} = FALSE;
176 $compObj->{combineLinesFlag} = FALSE; # Separate lines
177  
178 $compObj->{startPatternList} = [
179 '^\+\-{20,}\+$',
180 ];
181 $compObj->{startTagList} = [];
182 $compObj->{startAllFlag} = FALSE;
183 $compObj->{startTagMode} = 'default';
184  
185 $worldObj->ivAdd('componentHash', $compObj->name, $compObj);
186 }
187  
188 } else {
189  
190 $compObj = $worldObj->ivShow('componentHash', 'verb_exit_1');
191 }
192  
193 # Update IVs
194 $worldObj->ivPoke(
195 'exitAliasHash',
196 '^\+\-{20,}\+$',
197 'n_s_e_w_nw_ne_sw_se',
198 );
199  
200 $worldObj->ivSplice(
201 'verboseComponentList',
202 $worldObj->ivMatch('verboseComponentList', 'ignore_line_99'),
203 1,
204 'verb_exit_1',
205 );
206  
207 # Set the painter to draw 'normal' rooms, by default
208 $session->worldModelObj->painterObj->ivPoke('wildMode', 'normal');
209 }
210  
211 # Operation complete. Update any automapper windows that are open, so the right widgets are
212 # sensitised/desensitised
213 foreach my $otherSession ($axmud::CLIENT->ivValues('sessionHash')) {
214  
215 if ($otherSession->currentWorld->name eq 'empire') {
216  
217 if ($otherSession->mapWin) {
218  
219 $otherSession->mapWin->restrictWidgets();
220 }
221  
222 if ($otherSession->locatorTask) {
223  
224 $otherSession->pseudoCmd('resetlocator');
225 }
226 }
227 }
228  
229 # Show a confirmation
230 if ($modifyFlag) {
231  
232 return $self->complete(
233 $session, $standardCmd,
234 'Operation complete. The easiest way to draw new rooms in wilderness areas is to'
235 . ' enable the painter and to make it draw new rooms in wilderness mode',
236 );
237  
238 } else {
239  
240 return $self->complete(
241 $session, $standardCmd,
242 'Operation complete - the world profile is no longer configured to use wilderness'
243 . ' mode',
244 );
245 }
246 }
247  
248 ##################
249 # Accessors - set
250  
251 ##################
252 # Accessors - get
253 }
254  
255 # Package must return a true value
256 1