| 1 | # Copyright (C) 2011-2024 A S Lewis | ||
| 2 | # | ||
| 3 | # This program is free software: you can redistribute it and/or modify it under the terms of the GNU | ||
| 4 | # General Public License as published by the Free Software Foundation, either version 3 of the | ||
| 5 | # License, or (at your option) any later version. | ||
| 6 | # | ||
| 7 | # This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without | ||
| 8 | # even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 9 | # General Public License for more details. | ||
| 10 | # | ||
| 11 | # You should have received a copy of the GNU General Public License along with this program. If not, | ||
| 12 | # see <http://www.gnu.org/licenses/>. | ||
| 13 | # | ||
| 14 | # | ||
| 15 | # Games::Axmud::Obj::Mission | ||
| 16 | # Handles missions (very simple scripts) | ||
| 17 | |||
| 18 | { package Games::Axmud::Obj::Mission; | ||
| 19 | |||
| 20 | use strict; | ||
| 21 | use warnings; | ||
| 22 | # use diagnostics; | ||
| 23 | |||
| 24 | use Glib qw(TRUE FALSE); | ||
| 25 | |||
| 26 | our @ISA = qw(Games::Axmud); | ||
| 27 | |||
| 28 | ################## | ||
| 29 | # Constructors | ||
| 30 | |||
| 31 | sub new { | ||
| 32 | |||
| 33 | # Called by GA::Cmd::AddMission->do | ||
| 34 | # Creates a new instance of the mission object | ||
| 35 | # | ||
| 36 | # Expected arguments | ||
| 37 | # $session - The GA::Session which called this function (not stored as an IV) | ||
| 38 | # $name - A unique string name for this mission (max 16 chars, containing | ||
| 39 | # A-Za-z0-9_ - 1st char can't be number, non-Latin alphabets acceptable. | ||
| 40 | # Must not exist as a key in the global hash of reserved names, | ||
| 41 | # $axmud::CLIENT->constReservedHash) | ||
| 42 | # | ||
| 43 | # Optional arguments | ||
| 44 | # $descrip - A short description for the mission (max 64 chars) ('undef' if not | ||
| 45 | # specified) | ||
| 46 | # | ||
| 47 | # Return values | ||
| 48 | # 'undef' on improper arguments or if $name is invalid | ||
| 49 | # Blessed reference to the newly-created object on success | ||
| 50 | |||
| 51 | my ($class, $session, $name, $descrip, $check) = @_; | ||
| 52 | |||
| 53 | # Check for improper arguments | ||
| 54 | if (! defined $class || ! defined $session || ! defined $name || defined $check) { | ||
| 55 | |||
| 56 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 57 | } | ||
| 58 | |||
| 59 | # Check that $name is valid and not already in use by another mission (missions are | ||
| 60 | # stored in the current world profile) | ||
| 61 | if (! $axmud::CLIENT->nameCheck($name, 16)) { | ||
| 62 | |||
| 63 | return $axmud::CLIENT->writeError( | ||
| 64 | 'Registry naming error: invalid name \'' . $name . '\'', | ||
| 65 | $class . '->new', | ||
| 66 | ); | ||
| 67 | |||
| 68 | } elsif ($session->currentWorld->ivExists('missionHash', $name)) { | ||
| 69 | |||
| 70 | return $axmud::CLIENT->writeError( | ||
| 71 | 'Registry naming error: current world profile already has a mission called \'' | ||
| 72 | . $name . '\'', | ||
| 73 | $class . '->new', | ||
| 74 | ); | ||
| 75 | } | ||
| 76 | |||
| 77 | # If a description was specified, check it for length | ||
| 78 | if (defined $descrip) { | ||
| 79 | |||
| 80 | if (length($descrip) > 64) { | ||
| 81 | |||
| 82 | return $axmud::CLIENT->writeError( | ||
| 83 | 'Mission description is too long (max 64 characters)', | ||
| 84 | $class . '->new', | ||
| 85 | ); | ||
| 86 | } | ||
| 87 | |||
| 88 | } else { | ||
| 89 | |||
| 90 | $descrip = '<no description available>'; | ||
| 91 | } | ||
| 92 | |||
| 93 | # Setup | ||
| 94 | my $self = { | ||
| 95 | _objName => $name, | ||
| 96 | _objClass => $class, | ||
| 97 | _parentFile => $session->currentWorld->name, | ||
| 98 | _parentWorld => undef, | ||
| 99 | _privFlag => TRUE, # All IVs are private | ||
| 100 | |||
| 101 | # IVs | ||
| 102 | # --- | ||
| 103 | |||
| 104 | # A unique name for the mission (max 16 chars) | ||
| 105 | name => $name, | ||
| 106 | # A short description for the mission (max 64 chars) | ||
| 107 | descrip => $descrip, | ||
| 108 | |||
| 109 | # The contents of the mission | ||
| 110 | # Each element in the list is a string beginning with an identifying character, | ||
| 111 | # (optionally followed by any amount of whitespace), followed by a command to process | ||
| 112 | # - so the following elements are equivalent: | ||
| 113 | # >kill orc | ||
| 114 | # > kill orc | ||
| 115 | # > kill orc | ||
| 116 | # The initial character (and any following whitespace) is stripped, before the string is | ||
| 117 | # used. Valid initial characters are: | ||
| 118 | # '>' identifies the string as a world command | ||
| 119 | # ';' identifies the string as a client command | ||
| 120 | # '.' identifies the string as a speedwalk command | ||
| 121 | # '#' identifies the string as a comment to be displayed in the 'main' window | ||
| 122 | # '@' identifies the string as a break (anything following the '@' is ignored) | ||
| 123 | # There are three special kinds of break (see the help for ';startmission'): | ||
| 124 | # 't' identifies a trigger break; it is followed by a string used as the stimulus | ||
| 125 | # in a trigger. When the trigger fires, the mission continues | ||
| 126 | # 'p' identifies a pause break; it is followed by a number, the time (in seconds) to | ||
| 127 | # wait | ||
| 128 | # 'l' identifies a Locator break; it waits for the Locator task to decide it's not | ||
| 129 | # expecting any more room descriptions (anything following the 'l' is ignored) | ||
| 130 | # There are four initial characters for missions being used as login scripts: | ||
| 131 | # 'n' sends the current character profile's nickname (if set) | ||
| 132 | # 'w' sends the corresponding password (if known) | ||
| 133 | # 'a' sends the corresponding account name (if known) | ||
| 134 | # 'c' sends a combination of the three above; if the command contains '@name@', it is | ||
| 135 | # substituted for the current character profile's name; '@password@' is | ||
| 136 | # substituted for the corresponding password and '@account@' is substituted | ||
| 137 | # for the corresponding account name. The string, probably modified, is then | ||
| 138 | # sent as an ordinary world command. If @name@, @password@ and @account@ are | ||
| 139 | # used, but are not set, the world command isn't sent. If there is no | ||
| 140 | # current character, the world command isn't sent (even if @name@ is not used) | ||
| 141 | # | ||
| 142 | # Normally, the mission consists of a group of commands followed by a break, followed by | ||
| 143 | # another group of commands, followed by another break, and so on | ||
| 144 | # When the mission is initiated, commands are sent continuously to the world until a | ||
| 145 | # break is found. The user needs to re-initiate the mission, at which time the next | ||
| 146 | # group of commands is sent continuously until the next break is found | ||
| 147 | # Comments can appear anywhere in the list, but it's best to put them immediately before | ||
| 148 | # a break | ||
| 149 | missionList => [], | ||
| 150 | |||
| 151 | # (The remaining IVs are only used when a mission, stored in | ||
| 152 | # GA::Session->currentMission, is running) | ||
| 153 | |||
| 154 | # Flag set to TRUE if the mission should not display confirmation messages in the | ||
| 155 | # 'main' window, FALSE if it should display them (as normal) | ||
| 156 | # NB Comments and error/warning messages are displayed as normal, even when TRUE | ||
| 157 | quietFlag => FALSE, | ||
| 158 | |||
| 159 | # When a mission is first initiated (or rest), the contents of ->missionList are copied | ||
| 160 | # into this list. This list is gradually emptied as the mission progresses. When the | ||
| 161 | # list is empty, the mission is complete. | ||
| 162 | currentList => [], | ||
| 163 | # Counts how many strings have been used during a current mission. If this IV is set to | ||
| 164 | # n, then $self->currentList[n] is the next string for processing. If set to 0, the | ||
| 165 | # mission isn't current. The first string is #1 | ||
| 166 | nextString => 0, | ||
| 167 | |||
| 168 | # Every time a comment is displayed, it is saved here (so the ';repeatcomment' command | ||
| 169 | # can show it again, if it has scrolled off the screen) | ||
| 170 | prevComment => undef, | ||
| 171 | # Every command sent is added to this list, so the ';repeatmission' command can access | ||
| 172 | # them | ||
| 173 | prevCmdList => [], | ||
| 174 | |||
| 175 | # Whenever a current mission is not on a break, this variable set to 'undef'. Otherwise, | ||
| 176 | # it is set to a string describing the break we're on: 'break' (for normal breaks), | ||
| 177 | # 'trigger', 'pause', 'locator' | ||
| 178 | breakType => undef, | ||
| 179 | # For triggers breaks, the name of the active trigger interface created | ||
| 180 | triggerName => undef, | ||
| 181 | # For pause breaks, the name of the active timer interface created | ||
| 182 | timerName => undef, | ||
| 183 | }; | ||
| 184 | |||
| 185 | # Bless the object into existence | ||
| 186 | bless $self, $class; | ||
| 187 | return $self; | ||
| 188 | } | ||
| 189 | |||
| 190 | sub clone { | ||
| 191 | |||
| 192 | # Called by GA::Cmd::StartMission->do or CloneMission->do | ||
| 193 | # Creates a clone of an existing mission | ||
| 194 | # | ||
| 195 | # Expected arguments | ||
| 196 | # $session - The GA::Session which called this function (not stored as an IV) | ||
| 197 | # | ||
| 198 | # Optional arguments | ||
| 199 | # $name - A unique string name for this mission (max 16 chars, containing | ||
| 200 | # A-Za-z0-9_ - 1st char can't be number, non-Latin alphabets acceptable. | ||
| 201 | # Must not exist as a key in the global hash of reserved names, | ||
| 202 | # $axmud::CLIENT->constReservedHash). If not specified (because the cloned | ||
| 203 | # mission is to be stored in GA::Session->currentMission), the clone has | ||
| 204 | # the same name as the original | ||
| 205 | # | ||
| 206 | # Return values | ||
| 207 | # 'undef' on improper arguments or if $name is invalid (when specified) | ||
| 208 | # Blessed reference to the newly-created object on success | ||
| 209 | |||
| 210 | my ($self, $session, $name, $check) = @_; | ||
| 211 | |||
| 212 | # Check for improper arguments | ||
| 213 | if (! defined $session || defined $check) { | ||
| 214 | |||
| 215 | return $axmud::CLIENT->writeImproper($self->_objClass . '->clone', @_); | ||
| 216 | } | ||
| 217 | |||
| 218 | if (defined $name) { | ||
| 219 | |||
| 220 | # Check that $name is valid and not already in use by another profile | ||
| 221 | if (! $axmud::CLIENT->nameCheck($name, 16)) { | ||
| 222 | |||
| 223 | return $axmud::CLIENT->writeError( | ||
| 224 | 'Registry naming error: invalid name \'' . $name . '\'', | ||
| 225 | $self->_objClass . '->clone', | ||
| 226 | ); | ||
| 227 | |||
| 228 | } elsif ($axmud::CLIENT->ivExists('worldProfHash', $name)) { | ||
| 229 | |||
| 230 | return $axmud::CLIENT->writeError( | ||
| 231 | 'Registry naming error: profile \'' . $name . '\' already exists', | ||
| 232 | $self->_objClass . '->clone', | ||
| 233 | ); | ||
| 234 | } | ||
| 235 | |||
| 236 | } else { | ||
| 237 | |||
| 238 | # The cloned mission has the same ->name as the original | ||
| 239 | $name = $self->name; | ||
| 240 | } | ||
| 241 | |||
| 242 | # Setup | ||
| 243 | my $clone = { | ||
| 244 | _objName => $name, | ||
| 245 | _objClass => $self->_objClass, | ||
| 246 | _parentFile => $session->currentWorld->name, | ||
| 247 | _parentWorld => undef, | ||
| 248 | _privFlag => TRUE, # All IVs are private | ||
| 249 | |||
| 250 | # IVs | ||
| 251 | # --- | ||
| 252 | |||
| 253 | name => $name, | ||
| 254 | descrip => $self->descrip, | ||
| 255 | |||
| 256 | quietFlag => FALSE, | ||
| 257 | |||
| 258 | missionList => [$self->missionList], | ||
| 259 | |||
| 260 | currentList => [], | ||
| 261 | nextString => 0, | ||
| 262 | |||
| 263 | prevComment => undef, | ||
| 264 | prevCmdList => [], | ||
| 265 | |||
| 266 | breakType => undef, | ||
| 267 | triggerName => undef, | ||
| 268 | timerName => undef, | ||
| 269 | }; | ||
| 270 | |||
| 271 | # Bless the cloned object into existence | ||
| 272 | bless $clone, $self->_objClass; | ||
| 273 | |||
| 274 | return $clone; | ||
| 275 | } | ||
| 276 | |||
| 277 | ################## | ||
| 278 | # Methods | ||
| 279 | |||
| 280 | sub startMission { | ||
| 281 | |||
| 282 | # Called by GA::Cmd::StartMission->do | ||
| 283 | # Starts the mission stored in this object | ||
| 284 | # | ||
| 285 | # Expected arguments | ||
| 286 | # (none besides $self) | ||
| 287 | # | ||
| 288 | # Optional arguments | ||
| 289 | # $quietFlag - Flag set to TRUE if the mission should not display confirmation messages | ||
| 290 | # in the 'main' window, FALSE (or 'undef') if it should display them | ||
| 291 | # (as normal) | ||
| 292 | # | ||
| 293 | # Return values | ||
| 294 | # 'undef' on improper arguments | ||
| 295 | # 1 otherwise | ||
| 296 | |||
| 297 | my ($self, $quietFlag, $check) = @_; | ||
| 298 | |||
| 299 | # Check for improper arguments | ||
| 300 | if (defined $check) { | ||
| 301 | |||
| 302 | return $axmud::CLIENT->writeImproper($self->_objClass . '->startMission', @_); | ||
| 303 | } | ||
| 304 | |||
| 305 | # Make sure that all the IVs used when a GA::Session is running a mission have their | ||
| 306 | # default values | ||
| 307 | $self->resetMission(); | ||
| 308 | |||
| 309 | # Start the mission | ||
| 310 | $self->ivPoke('currentList', $self->missionList); | ||
| 311 | if ($quietFlag) { | ||
| 312 | |||
| 313 | $self->ivPoke('quietFlag', TRUE); | ||
| 314 | } | ||
| 315 | |||
| 316 | return 1; | ||
| 317 | } | ||
| 318 | |||
| 319 | sub resetBreak { | ||
| 320 | |||
| 321 | # Called by GA::Cmd::Mission->do at the end of a break | ||
| 322 | # Resets a few IVs | ||
| 323 | # | ||
| 324 | # Expected arguments | ||
| 325 | # (none besides $self) | ||
| 326 | # | ||
| 327 | # Return values | ||
| 328 | # 'undef' on improper arguments | ||
| 329 | # 1 otherwise | ||
| 330 | |||
| 331 | my ($self, $check) = @_; | ||
| 332 | |||
| 333 | # Check for improper arguments | ||
| 334 | if (defined $check) { | ||
| 335 | |||
| 336 | return $axmud::CLIENT->writeImproper($self->_objClass . '->resetBreak', @_); | ||
| 337 | } | ||
| 338 | |||
| 339 | # Reset IVs | ||
| 340 | $self->ivUndef('breakType'); | ||
| 341 | $self->ivUndef('triggerName'); | ||
| 342 | $self->ivUndef('timerName'); | ||
| 343 | |||
| 344 | return 1; | ||
| 345 | } | ||
| 346 | |||
| 347 | sub continueMission { | ||
| 348 | |||
| 349 | # Called by GA::Cmd::StartMission->do, etc | ||
| 350 | # Also called by $self->triggerSeen, etc | ||
| 351 | # | ||
| 352 | # Proceeds with the next stage in the mission. Starting with the first remainining element | ||
| 353 | # in $self->currentList, processes each element in turn until either a break or the end | ||
| 354 | # of the list is reached | ||
| 355 | # | ||
| 356 | # Expected arguments | ||
| 357 | # $session - The calling function's GA::Session | ||
| 358 | # | ||
| 359 | # Optional arguments | ||
| 360 | # $singleFlag - Set to TRUE if only one string from ->currentList should be processed | ||
| 361 | # (e.g. when called by GA::Cmd::Mission->do); otherwise 'undef' | ||
| 362 | # | ||
| 363 | # | ||
| 364 | # Return values | ||
| 365 | # 'undef' on improper arguments | ||
| 366 | # 1 if a break is reached (or the first string is processed, when $singleFlag is TRUE) | ||
| 367 | # 2 if $self->currentList has been emptied, signifying the end of the mission | ||
| 368 | |||
| 369 | my ($self, $session, $singleFlag, $check) = @_; | ||
| 370 | |||
| 371 | # Local variables | ||
| 372 | my ($count, $name, $nickname, $pwd, $pwdFlag, $account); | ||
| 373 | |||
| 374 | # Check for improper arguments | ||
| 375 | if (! defined $session || defined $check) { | ||
| 376 | |||
| 377 | return $axmud::CLIENT->writeImproper($self->_objClass . '->continueMission', @_); | ||
| 378 | } | ||
| 379 | |||
| 380 | # Process each string in turn | ||
| 381 | $count = 0; | ||
| 382 | while (1) { | ||
| 383 | |||
| 384 | my ($string, $initChar, $cmd, $triggerObj, $triggerString, $timerObj, $interval); | ||
| 385 | |||
| 386 | # $count is needed to identify the first while loop; $self->nextString identifies which | ||
| 387 | # string in the list $self->currentList is next to be processed (i.e. on the next | ||
| 388 | # 'while' loop) | ||
| 389 | $count++; | ||
| 390 | $self->ivIncrement('nextString'); | ||
| 391 | |||
| 392 | if (! $self->currentList) { | ||
| 393 | |||
| 394 | # The mission has finished | ||
| 395 | $self->completeMission($session); | ||
| 396 | |||
| 397 | return 2; | ||
| 398 | |||
| 399 | } else { | ||
| 400 | |||
| 401 | # Get the next string to process | ||
| 402 | $string = $self->ivShift('currentList'); | ||
| 403 | } | ||
| 404 | |||
| 405 | # $string starts with an initial char, followed by optional whitespace, followed by a | ||
| 406 | # command to process. Separate $string into its components | ||
| 407 | $initChar = substr($string, 0, 1); | ||
| 408 | $cmd = substr($string, 1); | ||
| 409 | $cmd = $axmud::CLIENT->trimWhitespace($cmd); | ||
| 410 | |||
| 411 | if ($initChar eq '>') { | ||
| 412 | |||
| 413 | # It's a world command | ||
| 414 | $session->doInstruct($cmd); | ||
| 415 | |||
| 416 | # Add the command to the misson's previous command list, in case the user wants to | ||
| 417 | # repeat it (keep the '>' to identify it as a world command) | ||
| 418 | $self->ivPush('prevCmdList', $string); | ||
| 419 | |||
| 420 | # If the flag has been set, we don't send any more commands for now | ||
| 421 | if ($singleFlag) { | ||
| 422 | |||
| 423 | return 1; | ||
| 424 | } | ||
| 425 | |||
| 426 | } elsif ($initChar eq ';') { | ||
| 427 | |||
| 428 | # If $cmd is empty, then simply ignore this string | ||
| 429 | if ($cmd) { | ||
| 430 | |||
| 431 | # It's a client command - so we need to re-attach the initial ';' | ||
| 432 | $session->doInstruct(';' . $cmd); | ||
| 433 | |||
| 434 | # Add the command to the misson's previous command list, in case the user wants | ||
| 435 | # to repeat them (keep the '!' to identify it as a client command) | ||
| 436 | $self->ivPush('prevCmdList', $string); | ||
| 437 | |||
| 438 | # If the flag has been set, we don't send any more commands for now | ||
| 439 | if ($singleFlag) { | ||
| 440 | |||
| 441 | return 1; | ||
| 442 | } | ||
| 443 | } | ||
| 444 | |||
| 445 | } elsif ($initChar eq '.') { | ||
| 446 | |||
| 447 | # If $cmd is empty, then simply ignore this string | ||
| 448 | if ($cmd) { | ||
| 449 | |||
| 450 | # It's a speedwalk command | ||
| 451 | $session->speedWalkCmd('.' . $cmd); | ||
| 452 | |||
| 453 | # If the flag has been set, we don't send any more commands for now | ||
| 454 | if ($singleFlag) { | ||
| 455 | |||
| 456 | return 1; | ||
| 457 | } | ||
| 458 | } | ||
| 459 | |||
| 460 | } elsif ($initChar eq '#') { | ||
| 461 | |||
| 462 | # If $cmd is empty, then simply ignore this string | ||
| 463 | if ($cmd) { | ||
| 464 | |||
| 465 | # It's a comment. Display it | ||
| 466 | $self->displayComment($session, $cmd); | ||
| 467 | # Save the comment, in case the user wants to repeat it | ||
| 468 | $self->ivPoke('prevComment', $cmd); | ||
| 469 | } | ||
| 470 | |||
| 471 | } elsif ($initChar eq '@') { | ||
| 472 | |||
| 473 | # It's a break. However, if this is the first string in the list and this function | ||
| 474 | # was called by ';incrementmission', we're probably at the start of a | ||
| 475 | # break-comment-break sequence. We don't want to do nothing, because that's | ||
| 476 | # disconcerting, so ignore the break. Otherwise, process the break | ||
| 477 | if (! $singleFlag || $count != 1) { | ||
| 478 | |||
| 479 | $self->ivPoke('breakType', 'break'); | ||
| 480 | # Return 1 to show a break has been reached | ||
| 481 | return 1; | ||
| 482 | } | ||
| 483 | |||
| 484 | } elsif ($initChar eq 't') { | ||
| 485 | |||
| 486 | # It's a trigger break | ||
| 487 | if (! $cmd) { | ||
| 488 | |||
| 489 | $session->writeWarning( | ||
| 490 | 'Current mission\'s trigger string is invalid (using normal break instead)', | ||
| 491 | $self->_objClass . '->continueMission', | ||
| 492 | ); | ||
| 493 | |||
| 494 | # Create a normal break instead | ||
| 495 | $self->ivPoke('breakType', 'break'); | ||
| 496 | # Return 1 to show a break has been reached | ||
| 497 | return 1; | ||
| 498 | |||
| 499 | } else { | ||
| 500 | |||
| 501 | # Create a trigger | ||
| 502 | $triggerObj = $session->createDependentInterface( | ||
| 503 | 'trigger', | ||
| 504 | $cmd, # A pattern | ||
| 505 | $self, | ||
| 506 | 'triggerSeen', | ||
| 507 | ); | ||
| 508 | |||
| 509 | if (! $triggerObj) { | ||
| 510 | |||
| 511 | $session->writeWarning( | ||
| 512 | 'Current mission failed to create trigger for the pattern \'' . $cmd | ||
| 513 | . '\' (using normal break instead)', | ||
| 514 | $self->_objClass . '->continueMission', | ||
| 515 | ); | ||
| 516 | |||
| 517 | # Create a normal break instead | ||
| 518 | $self->ivPoke('breakType', 'break'); | ||
| 519 | # Return 1 to show a break has been reached | ||
| 520 | return 1; | ||
| 521 | |||
| 522 | } else { | ||
| 523 | |||
| 524 | $self->ivPoke('breakType', 'trigger'); | ||
| 525 | $self->ivPoke('triggerName', $triggerObj->name); | ||
| 526 | # Return 1 to show a break has been reached | ||
| 527 | return 1; | ||
| 528 | } | ||
| 529 | } | ||
| 530 | |||
| 531 | } elsif ($initChar eq 'p') { | ||
| 532 | |||
| 533 | # It's a pause break. Check the supplied value is a valid number | ||
| 534 | if (! $axmud::CLIENT->floatCheck($cmd, 0) || $cmd == 0) { | ||
| 535 | |||
| 536 | $session->writeWarning( | ||
| 537 | 'Current mission\'s pause interval \'' . $cmd . '\' is invalid, using' | ||
| 538 | . ' a 10 second interval instead', | ||
| 539 | $self->_objClass . '->continueMission', | ||
| 540 | ); | ||
| 541 | |||
| 542 | # Use 10 seconds as a default value | ||
| 543 | $cmd = 10; | ||
| 544 | } | ||
| 545 | |||
| 546 | # Create a timer that counts once, then deletes itself | ||
| 547 | $timerObj = $session->createDependentInterface( | ||
| 548 | 'timer', | ||
| 549 | $cmd, # A time interval | ||
| 550 | $self, | ||
| 551 | 'timerSeen', | ||
| 552 | # Optional attributes | ||
| 553 | 'count', | ||
| 554 | 1, | ||
| 555 | 'temporary', | ||
| 556 | 1, | ||
| 557 | ); | ||
| 558 | |||
| 559 | if (! $timerObj) { | ||
| 560 | |||
| 561 | $session->writeWarning( | ||
| 562 | 'Current mission failed to create timer for the interval \'' . $cmd . '\'' | ||
| 563 | . ' (using normal break instead)', | ||
| 564 | $self->_objClass . '->continueMission', | ||
| 565 | ); | ||
| 566 | |||
| 567 | # Create a normal break instead | ||
| 568 | $self->ivPoke('breakType', 'break'); | ||
| 569 | $self->ivPoke('timerName', $timerObj); | ||
| 570 | # Return 1 to show a break has been reached | ||
| 571 | return 1; | ||
| 572 | |||
| 573 | } else { | ||
| 574 | |||
| 575 | $self->ivPoke('breakType', 'pause'); | ||
| 576 | # Return 1 to show a break has been reached | ||
| 577 | return 1; | ||
| 578 | } | ||
| 579 | |||
| 580 | } elsif ($initChar eq 'l') { | ||
| 581 | |||
| 582 | # It's a locator break | ||
| 583 | if (! $session->locatorTask) { | ||
| 584 | |||
| 585 | # Don't create an ordinary break instead - it doesn't matter too much if we just | ||
| 586 | # keep sending commands to the world | ||
| 587 | $session->writeWarning( | ||
| 588 | 'Current mission\'s Locator break ignored - no Locator task running', | ||
| 589 | $self->_objClass . '->continueMission', | ||
| 590 | ); | ||
| 591 | |||
| 592 | } elsif (! $session->locatorTask->roomObj) { | ||
| 593 | |||
| 594 | # Likewise for this warning | ||
| 595 | $session->writeWarning( | ||
| 596 | 'Current mission\'s Locator break ignored - the Locator task doesn\'t know' | ||
| 597 | . ' what the character\'s current location is', | ||
| 598 | $self->_objClass . '->continueMission', | ||
| 599 | ); | ||
| 600 | |||
| 601 | } else { | ||
| 602 | |||
| 603 | # Create the break | ||
| 604 | $self->ivPoke('breakType', 'locator'); | ||
| 605 | # The Locator task's ->main function will call $self->taskReady when the task | ||
| 606 | # isn't expecting any more room statements | ||
| 607 | # Return 1 to show a break has been reached | ||
| 608 | return 1; | ||
| 609 | } | ||
| 610 | |||
| 611 | } elsif ($initChar eq 'n' || $initChar eq 'w' || $initChar eq 'a') { | ||
| 612 | |||
| 613 | # It's an instruction to send the character's name, password or associated account | ||
| 614 | # name (for missions being used as a login script) | ||
| 615 | # In blind mode, and when the character is not yet marked as logged in, don't annoy | ||
| 616 | # a blind user by reading out these error messages | ||
| 617 | if ($session->loginFlag) { | ||
| 618 | |||
| 619 | if (! $axmud::BLIND_MODE_FLAG) { | ||
| 620 | |||
| 621 | $session->writeWarning( | ||
| 622 | 'Current mission ignored a request to send the character\'s login' | ||
| 623 | . ' details to the world - character is already marked as' | ||
| 624 | . ' \'logged in\'', | ||
| 625 | $self->_objClass . 'continueMission', | ||
| 626 | ); | ||
| 627 | } | ||
| 628 | |||
| 629 | $self->completeMission($session); | ||
| 630 | |||
| 631 | return 2; | ||
| 632 | |||
| 633 | } elsif ( ! $session->currentChar) { | ||
| 634 | |||
| 635 | if (! $axmud::BLIND_MODE_FLAG || $session->loginFlag) { | ||
| 636 | |||
| 637 | $session->writeWarning( | ||
| 638 | 'Current mission ignored a request to send the character\'s login' | ||
| 639 | . ' details to the world - no current character set', | ||
| 640 | $self->_objClass . 'continueMission', | ||
| 641 | ); | ||
| 642 | } | ||
| 643 | |||
| 644 | $self->completeMission($session); | ||
| 645 | |||
| 646 | return 2; | ||
| 647 | |||
| 648 | } else { | ||
| 649 | |||
| 650 | $pwd = $session->currentWorld->ivShow( | ||
| 651 | 'passwordHash', | ||
| 652 | $session->currentChar->name, | ||
| 653 | ); | ||
| 654 | |||
| 655 | $account = $session->currentWorld->ivShow( | ||
| 656 | 'accountHash', | ||
| 657 | $session->currentChar->name, | ||
| 658 | ); | ||
| 659 | |||
| 660 | if (! $pwd) { | ||
| 661 | |||
| 662 | # (If password not set, don't send any of the character's login details - | ||
| 663 | # not the name, password or the associated account name) | ||
| 664 | if (! $axmud::BLIND_MODE_FLAG || $session->loginFlag) { | ||
| 665 | |||
| 666 | $session->writeWarning( | ||
| 667 | 'Current mission ignored a request to send the character\'s login' | ||
| 668 | . ' details to the world - no password set', | ||
| 669 | $self->_objClass . '->continueMission', | ||
| 670 | ); | ||
| 671 | } | ||
| 672 | |||
| 673 | $self->completeMission($session); | ||
| 674 | |||
| 675 | return 2; | ||
| 676 | |||
| 677 | } elsif ($initChar eq 'a' && ! $account) { | ||
| 678 | |||
| 679 | # (If associated account not set but the mission wants to send it to the | ||
| 680 | # world, we also have to end the mission here) | ||
| 681 | if (! $axmud::BLIND_MODE_FLAG || $session->loginFlag) { | ||
| 682 | |||
| 683 | $session->writeWarning( | ||
| 684 | 'Current mission ignored a request to send the character\'s' | ||
| 685 | . ' associated account name - no account name set', | ||
| 686 | $self->_objClass . '->continueMission', | ||
| 687 | ); | ||
| 688 | } | ||
| 689 | |||
| 690 | $self->completeMission($session); | ||
| 691 | |||
| 692 | return 2; | ||
| 693 | } | ||
| 694 | } | ||
| 695 | |||
| 696 | if ($initChar eq 'n') { | ||
| 697 | |||
| 698 | # Send the character's name as a normal world command (and don't add the | ||
| 699 | # command to the mission's previous command list) | ||
| 700 | $session->doInstruct($session->currentChar->nickname); | ||
| 701 | |||
| 702 | } elsif ($initChar eq 'w') { | ||
| 703 | |||
| 704 | # Send the character's password as a normal world command, obfuscated in the | ||
| 705 | # 'main' window (and don't add the command to the mission's previous command | ||
| 706 | # list) | ||
| 707 | $session->worldCmd($pwd, $pwd); | ||
| 708 | |||
| 709 | } elsif ($initChar eq 'a') { | ||
| 710 | |||
| 711 | # Send the character's associated account name as a normal world command (and | ||
| 712 | # don't add the command to the mission's previous command list) | ||
| 713 | $session->doInstruct($account); | ||
| 714 | } | ||
| 715 | |||
| 716 | # If the flag has been set, we don't send any more commands for now | ||
| 717 | if ($singleFlag) { | ||
| 718 | |||
| 719 | return 1; | ||
| 720 | } | ||
| 721 | |||
| 722 | } elsif ($initChar eq 'c') { | ||
| 723 | |||
| 724 | # It's an instruction which should be modified to substitute @name@, @password@ and | ||
| 725 | # @account@ for the current character's name and corresponding password and | ||
| 726 | # account name; the modified instruction is then sent as an ordinary world | ||
| 727 | # command (for missions being used as a login script) | ||
| 728 | if ($session->loginFlag) { | ||
| 729 | |||
| 730 | $session->writeWarning( | ||
| 731 | 'Current mission ignored a request to send the character\'s login details' | ||
| 732 | . ' to the world - character is already marked as \'logged in\'', | ||
| 733 | $self->_objClass . 'continueMission', | ||
| 734 | ); | ||
| 735 | |||
| 736 | $self->completeMission($session); | ||
| 737 | |||
| 738 | return 2; | ||
| 739 | |||
| 740 | } elsif ( ! $session->currentChar) { | ||
| 741 | |||
| 742 | $session->writeWarning( | ||
| 743 | 'Current mission ignored a request to send the character\'s login details' | ||
| 744 | . ' to the world - no current character set', | ||
| 745 | $self->_objClass . 'continueMission', | ||
| 746 | ); | ||
| 747 | |||
| 748 | $self->completeMission($session); | ||
| 749 | |||
| 750 | return 2; | ||
| 751 | } | ||
| 752 | |||
| 753 | # For convenience, import the current character's name and corresponding password | ||
| 754 | # and corresponding account name | ||
| 755 | $name = $session->currentChar->name; | ||
| 756 | |||
| 757 | $pwd = $session->currentWorld->ivShow( | ||
| 758 | 'passwordHash', | ||
| 759 | $name, | ||
| 760 | ); | ||
| 761 | |||
| 762 | $account = $session->currentWorld->ivShow( | ||
| 763 | 'accountHash', | ||
| 764 | $name, | ||
| 765 | ); | ||
| 766 | |||
| 767 | # Substitute @name@ | ||
| 768 | $cmd =~ s/\@name\@/$nickname/; | ||
| 769 | |||
| 770 | # Substitute @password@ | ||
| 771 | if ($cmd =~ m/\@password\@/) { | ||
| 772 | |||
| 773 | if (! defined $pwd) { | ||
| 774 | |||
| 775 | $session->writeWarning( | ||
| 776 | 'Current mission ignored a request to send the character\'s password' | ||
| 777 | . ' to the world - no password set', | ||
| 778 | $self->_objClass . 'continueMission', | ||
| 779 | ); | ||
| 780 | |||
| 781 | $self->completeMission($session); | ||
| 782 | |||
| 783 | return 2; | ||
| 784 | |||
| 785 | } else { | ||
| 786 | |||
| 787 | $cmd =~ s/\@password\@/$pwd/; | ||
| 788 | $pwdFlag = TRUE; | ||
| 789 | } | ||
| 790 | } | ||
| 791 | |||
| 792 | # Substitute @account@ | ||
| 793 | if ($cmd =~ m/\@account\@/) { | ||
| 794 | |||
| 795 | if (! defined $account) { | ||
| 796 | |||
| 797 | $session->writeWarning( | ||
| 798 | 'Current mission ignored a request to send the character\'s account' | ||
| 799 | . ' name to the world - no account name set', | ||
| 800 | $self->_objClass . 'continueMission', | ||
| 801 | ); | ||
| 802 | |||
| 803 | $self->completeMission($session); | ||
| 804 | |||
| 805 | return 2; | ||
| 806 | |||
| 807 | } else { | ||
| 808 | |||
| 809 | $cmd =~ s/\@account\@/$account/; | ||
| 810 | } | ||
| 811 | } | ||
| 812 | |||
| 813 | # Send the world command | ||
| 814 | if ($pwdFlag) { | ||
| 815 | |||
| 816 | # Send the command, which contains a password, as a normal world command, | ||
| 817 | # obfuscated in the 'main' window (and don't add the command to the mission's | ||
| 818 | # previous command list) | ||
| 819 | $session->worldCmd($cmd, $cmd); | ||
| 820 | |||
| 821 | } else { | ||
| 822 | |||
| 823 | # Send the character's login details as a normal world command (and don't add | ||
| 824 | # the command to the mission's previous command list) | ||
| 825 | $session->doInstruct($cmd); | ||
| 826 | } | ||
| 827 | |||
| 828 | # If the flag has been set, we don't send any more commands for now | ||
| 829 | if ($singleFlag) { | ||
| 830 | |||
| 831 | return 1; | ||
| 832 | } | ||
| 833 | |||
| 834 | } else { | ||
| 835 | |||
| 836 | # Ignore the invalid command; show a warning, then move on to the next string | ||
| 837 | $session->writeWarning( | ||
| 838 | 'Current mission ignored an invalid string: \'' . $string . '\'', | ||
| 839 | $self->_objClass . '->continueMission', | ||
| 840 | ); | ||
| 841 | } | ||
| 842 | } | ||
| 843 | } | ||
| 844 | |||
| 845 | sub completeMission { | ||
| 846 | |||
| 847 | # Called by several stages of $self->continueMission | ||
| 848 | # Shows a confirmation messages, resets IVs and updates the GA::Session IV | ||
| 849 | # | ||
| 850 | # Expected arguments | ||
| 851 | # $session - The calling function's GA::Session | ||
| 852 | # | ||
| 853 | # Return values | ||
| 854 | # 'undef' on improper arguments | ||
| 855 | # 1 otherwise | ||
| 856 | |||
| 857 | my ($self, $session, $check) = @_; | ||
| 858 | |||
| 859 | # Check for improper arguments | ||
| 860 | if (! defined $session || defined $check) { | ||
| 861 | |||
| 862 | return $axmud::CLIENT->writeImproper($self->_objClass . '->completeMission', @_); | ||
| 863 | } | ||
| 864 | |||
| 865 | # Abuse $self->displayComment to show a confirmation message | ||
| 866 | if (! $self->quietFlag) { | ||
| 867 | |||
| 868 | $self->displayComment($session, 'Mission complete'); | ||
| 869 | } | ||
| 870 | |||
| 871 | # Update our own temporary IVs | ||
| 872 | $self->resetMission(); | ||
| 873 | # Update the GA::Session's IV | ||
| 874 | $session->reset_currentMission(); | ||
| 875 | |||
| 876 | return 1; | ||
| 877 | } | ||
| 878 | |||
| 879 | sub resetMission { | ||
| 880 | |||
| 881 | # Called by $self->startMission or ->completeMission | ||
| 882 | # Resets all the IVs used when a GA::Session is running a mission | ||
| 883 | # | ||
| 884 | # Expected arguments | ||
| 885 | # (none besides $self) | ||
| 886 | # | ||
| 887 | # Return values | ||
| 888 | # 'undef' on improper arguments | ||
| 889 | # 1 otherwise | ||
| 890 | |||
| 891 | my ($self, $check) = @_; | ||
| 892 | |||
| 893 | # Check for improper arguments | ||
| 894 | if (defined $check) { | ||
| 895 | |||
| 896 | return $axmud::CLIENT->writeImproper($self->_objClass . '->resetMission', @_); | ||
| 897 | } | ||
| 898 | |||
| 899 | $self->ivPoke('quietFlag', FALSE); | ||
| 900 | $self->ivEmpty('currentList'); | ||
| 901 | $self->ivPoke('nextString', 0); | ||
| 902 | $self->ivUndef('prevComment'); | ||
| 903 | $self->ivEmpty('prevCmdList'); | ||
| 904 | $self->ivUndef('breakType'); | ||
| 905 | $self->ivUndef('triggerName'); | ||
| 906 | $self->ivUndef('timerName'); | ||
| 907 | |||
| 908 | return 1; | ||
| 909 | } | ||
| 910 | |||
| 911 | sub displayComment { | ||
| 912 | |||
| 913 | # Called by $self->continueMission and GA::Cmd::RepeatComment | ||
| 914 | # Shows a comment in the 'main' window | ||
| 915 | # | ||
| 916 | # Expected arguments | ||
| 917 | # $session - The calling function's GA::Session | ||
| 918 | # $comment - The comment to show | ||
| 919 | # | ||
| 920 | # Return values | ||
| 921 | # 'undef' on improper arguments | ||
| 922 | # 1 otherwise | ||
| 923 | |||
| 924 | my ($self, $session, $comment, $check) = @_; | ||
| 925 | |||
| 926 | # Check for improper arguments | ||
| 927 | if (! defined $session || ! defined $comment || defined $check) { | ||
| 928 | |||
| 929 | return $axmud::CLIENT->writeImproper($self->_objClass . '->displayComment', @_); | ||
| 930 | } | ||
| 931 | |||
| 932 | $session->writeText( | ||
| 933 | 'MISSION: \'' . $self->name . '\' (step ' . $self->nextString . ')', | ||
| 934 | ); | ||
| 935 | |||
| 936 | $session->writeText($comment); | ||
| 937 | |||
| 938 | return 1; | ||
| 939 | } | ||
| 940 | |||
| 941 | sub taskReady { | ||
| 942 | |||
| 943 | # Called by GA::Task::Locator->processLine while the mission is on a Locator break, whenever | ||
| 944 | # the task notices that there are no more room statements expected (i.e. the character has | ||
| 945 | # arrived at their intended destination) | ||
| 946 | # | ||
| 947 | # Expected arguments | ||
| 948 | # $session - The calling function's GA::Session | ||
| 949 | # | ||
| 950 | # Return values | ||
| 951 | # 'undef' on improper arguments | ||
| 952 | # 1 otherwise | ||
| 953 | |||
| 954 | my ($self, $session, $check) = @_; | ||
| 955 | |||
| 956 | # Check for improper arguments | ||
| 957 | if (! defined $session || defined $check) { | ||
| 958 | |||
| 959 | return $axmud::CLIENT->writeImproper($self->_objClass . '->taskReady', @_); | ||
| 960 | } | ||
| 961 | |||
| 962 | # Reset the mission's IVs | ||
| 963 | $self->ivUndef('breakType'); | ||
| 964 | |||
| 965 | # Send the next group of commands, and return the result ('undef', 1 or 2) | ||
| 966 | return ($self->continueMission($session)); | ||
| 967 | } | ||
| 968 | |||
| 969 | sub statusTaskChange { | ||
| 970 | |||
| 971 | # Called by GA::Task::Status->deadSeen, ->passedOutSeen or ->asleepSeen when the character | ||
| 972 | # dies, passes out or falls asleep | ||
| 973 | # Terminates the current mission | ||
| 974 | # | ||
| 975 | # Expected arguments | ||
| 976 | # $session - The calling function's GA::Session | ||
| 977 | # $status - The Status task's new ->lifeStatus IV: 'sleep', 'passout' or | ||
| 978 | # 'dead' (if it's 'alive', this function does nothing) | ||
| 979 | # | ||
| 980 | # Return values | ||
| 981 | # 'undef' on improper arguments | ||
| 982 | # 1 otherwise | ||
| 983 | |||
| 984 | my ($self, $session, $status, $check) = @_; | ||
| 985 | |||
| 986 | # Local variables | ||
| 987 | my $comment; | ||
| 988 | |||
| 989 | # Check for improper arguments | ||
| 990 | if ( | ||
| 991 | ! defined $session || ! defined $status | ||
| 992 | || ( | ||
| 993 | $status ne 'alive' && $status ne 'sleep' && $status ne 'passout' | ||
| 994 | && $status ne 'dead' | ||
| 995 | ) || defined $check | ||
| 996 | ) { | ||
| 997 | return $axmud::CLIENT->writeImproper($self->_objClass . '->statusTaskChange', @_); | ||
| 998 | } | ||
| 999 | |||
| 1000 | if ($status eq 'alive') { | ||
| 1001 | |||
| 1002 | # Do nothing | ||
| 1003 | return 1; | ||
| 1004 | |||
| 1005 | } else { | ||
| 1006 | |||
| 1007 | $comment = 'Mission terminated because character has '; | ||
| 1008 | if ($status eq 'sleep') { | ||
| 1009 | $comment .= 'fallen asleep'; | ||
| 1010 | } elsif ($status eq 'passout') { | ||
| 1011 | $comment .= 'passed out'; | ||
| 1012 | } elsif ($status eq 'dead') { | ||
| 1013 | $comment .= 'died'; | ||
| 1014 | } | ||
| 1015 | |||
| 1016 | $self->displayComment($session, $comment); | ||
| 1017 | $session->reset_currentMission(); | ||
| 1018 | |||
| 1019 | return 1; | ||
| 1020 | } | ||
| 1021 | } | ||
| 1022 | |||
| 1023 | # Response methods | ||
| 1024 | |||
| 1025 | sub triggerSeen { | ||
| 1026 | |||
| 1027 | # Called by GA::Session->checkTriggers, while on a trigger break, after the trigger created | ||
| 1028 | # by $self->continueMission fires | ||
| 1029 | # | ||
| 1030 | # Expected arguments (standard args from GA::Session->checkTriggers) | ||
| 1031 | # $session - The calling function's GA::Session | ||
| 1032 | # $interfaceNum - The number of the active trigger interface that fired | ||
| 1033 | # $line - The line of text received from the world | ||
| 1034 | # $stripLine - $line, with all escape sequences removed | ||
| 1035 | # $modLine - $stripLine, possibly modified by previously-checked triggers | ||
| 1036 | # $grpStringListRef | ||
| 1037 | # - Reference to a list of group substrings from the pattern match | ||
| 1038 | # (equivalent of @_) | ||
| 1039 | # $matchMinusListRef | ||
| 1040 | # - Reference to a list of matched substring offsets (equivalent of @-) | ||
| 1041 | # $matchPlusListRef | ||
| 1042 | # - Reference to a list of matched substring offsets (equivalent of @+) | ||
| 1043 | # | ||
| 1044 | # Return values | ||
| 1045 | # 'undef' on improper arguments, or if $session is the wrong session, or if the interface | ||
| 1046 | # object can't be found | ||
| 1047 | # Otherwise returns the result of the call to $self->continueMission ('undef', 1 or 2) | ||
| 1048 | |||
| 1049 | my ( | ||
| 1050 | $self, $session, $interfaceNum, $line, $stripLine, $modLine, $grpStringListRef, | ||
| 1051 | $matchMinusListRef, $matchPlusListRef, $check, | ||
| 1052 | ) = @_; | ||
| 1053 | |||
| 1054 | # Local variables | ||
| 1055 | my $obj; | ||
| 1056 | |||
| 1057 | # Check for improper arguments | ||
| 1058 | if ( | ||
| 1059 | ! defined $session || ! defined $interfaceNum || ! defined $line || ! defined $stripLine | ||
| 1060 | || ! defined $modLine || ! defined $grpStringListRef || ! defined $matchMinusListRef | ||
| 1061 | || ! defined $matchPlusListRef || defined $check | ||
| 1062 | ) { | ||
| 1063 | return $axmud::CLIENT->writeImproper($self->_objClass . '->triggerSeen', @_); | ||
| 1064 | } | ||
| 1065 | |||
| 1066 | # Get the interface object itself | ||
| 1067 | $obj = $session->ivShow('interfaceNumHash', $interfaceNum); | ||
| 1068 | if (! $obj) { | ||
| 1069 | |||
| 1070 | return undef; | ||
| 1071 | } | ||
| 1072 | |||
| 1073 | # Respond to the fired trigger | ||
| 1074 | |||
| 1075 | # The trigger must only fire once, so mark the trigger to be deleted (it is first disabled, | ||
| 1076 | # then deleted at the start of the next task loop) | ||
| 1077 | $session->deleteInterface($obj->name); | ||
| 1078 | |||
| 1079 | # Reset the mission's IVs | ||
| 1080 | $self->ivUndef('triggerName'); | ||
| 1081 | $self->ivUndef('breakType'); | ||
| 1082 | |||
| 1083 | # Send the next group of commands, and return the result ('undef', 1 or 2) | ||
| 1084 | return $self->continueMission($session); | ||
| 1085 | } | ||
| 1086 | |||
| 1087 | sub timerSeen { | ||
| 1088 | |||
| 1089 | # Called by GA::Session->checkTimers, while on a pause break, after the timer created by | ||
| 1090 | # $self->continueMission fires | ||
| 1091 | # | ||
| 1092 | # Expected arguments (standard args from GA::Session->checkTimers) | ||
| 1093 | # $session - The calling function's GA::Session | ||
| 1094 | # $interfaceNum - The number of the active timer interface that fired | ||
| 1095 | # $actualTime - The time (matches GA::Session->sessionTime) at which the timer | ||
| 1096 | # actually fired, in seconds | ||
| 1097 | # $dueTime - The time (matches GA::Session->sessionTime) at which the timer was due | ||
| 1098 | # to fire, in seconds | ||
| 1099 | # | ||
| 1100 | # Return values | ||
| 1101 | # 'undef' on improper arguments, or if $session is the wrong session, or if the interface | ||
| 1102 | # object can't be found | ||
| 1103 | # Otherwise returns the result of the call to $self->continueMission ('undef', 1 or 2) | ||
| 1104 | |||
| 1105 | my ($self, $session, $interfaceNum, $actualTime, $dueTime, $check) = @_; | ||
| 1106 | |||
| 1107 | # Local variables | ||
| 1108 | my $obj; | ||
| 1109 | |||
| 1110 | # Check for improper arguments | ||
| 1111 | if ( | ||
| 1112 | ! defined $session || ! defined $interfaceNum || ! defined $actualTime | ||
| 1113 | || ! defined $dueTime || defined $check | ||
| 1114 | ) { | ||
| 1115 | return $axmud::CLIENT->writeImproper($self->_objClass . '->timerSeen', @_); | ||
| 1116 | } | ||
| 1117 | |||
| 1118 | # Get the interface object itself | ||
| 1119 | $obj = $session->ivShow('interfaceNumHash', $interfaceNum); | ||
| 1120 | if (! $obj) { | ||
| 1121 | |||
| 1122 | return undef; | ||
| 1123 | } | ||
| 1124 | |||
| 1125 | # Respond to the fired timer | ||
| 1126 | |||
| 1127 | # Reset the mission's IVs (the timer was marked as 'temporary' when it was created, so it | ||
| 1128 | # will only fire once) | ||
| 1129 | $self->ivUndef('timerName'); | ||
| 1130 | $self->ivUndef('breakType'); | ||
| 1131 | |||
| 1132 | # Send the next group of commands, and return the result ('undef', 1 or 2) | ||
| 1133 | return ($self->continueMission($session)); | ||
| 1134 | } | ||
| 1135 | |||
| 1136 | ################## | ||
| 1137 | # Accessors - set | ||
| 1138 | |||
| 1139 | ################## | ||
| 1140 | # Accessors - get | ||
| 1141 | |||
| 1142 | sub name | ||
| 1143 | { $_[0]->{name} } | ||
| 1144 | sub descrip | ||
| 1145 | { $_[0]->{descrip} } | ||
| 1146 | |||
| 1147 | sub missionList | ||
| 1148 | { my $self = shift; return @{$self->{missionList}}; } | ||
| 1149 | |||
| 1150 | sub quietFlag | ||
| 1151 | { $_[0]->{quietFlag} } | ||
| 1152 | |||
| 1153 | sub currentList | ||
| 1154 | { my $self = shift; return @{$self->{currentList}}; } | ||
| 1155 | sub nextString | ||
| 1156 | { $_[0]->{nextString} } | ||
| 1157 | |||
| 1158 | sub prevComment | ||
| 1159 | { $_[0]->{previousComment} } | ||
| 1160 | sub prevCmdList | ||
| 1161 | { my $self = shift; return @{$self->{prevCmdList}}; } | ||
| 1162 | |||
| 1163 | sub breakType | ||
| 1164 | { $_[0]->{breakType} } | ||
| 1165 | sub triggerName | ||
| 1166 | { $_[0]->{triggerName} } | ||
| 1167 | sub timerName | ||
| 1168 | { $_[0]->{timerName} } | ||
| 1169 | } | ||
| 1170 | |||
| 1171 | # Package must return a true value | ||
| 1172 | 1 |