| 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::Task::XXX | ||
| 16 | # Objects handling built-in tasks | ||
| 17 | |||
| 18 | { package Games::Axmud::Task::Advance; | ||
| 19 | |||
| 20 | use strict; | ||
| 21 | use warnings; | ||
| 22 | # use diagnostics; | ||
| 23 | |||
| 24 | use Glib qw(TRUE FALSE); | ||
| 25 | |||
| 26 | our @ISA = qw(Games::Axmud::Generic::Task Games::Axmud); | ||
| 27 | |||
| 28 | ################## | ||
| 29 | # Constructors | ||
| 30 | |||
| 31 | sub new { | ||
| 32 | |||
| 33 | # Creates a new instances of the Advance task | ||
| 34 | # | ||
| 35 | # Expected arguments | ||
| 36 | # $session - The parent GA::Session (not stored as an IV) | ||
| 37 | # | ||
| 38 | # Optional arguments | ||
| 39 | # $taskType - Which tasklist this task is being created into - 'current' for the current | ||
| 40 | # tasklist (tasks which are actually running now), 'initial' (tasks which | ||
| 41 | # should be run when the user connects to the world), 'custom' (tasks with | ||
| 42 | # customised initial parameters, which are run when the user demands). If | ||
| 43 | # set to 'undef', this is a temporary task, created in order to access the | ||
| 44 | # default values stored in IVs, that will not be added to any tasklist | ||
| 45 | # $profName - ($taskType = 'current', when called by $self->clone) Name of the | ||
| 46 | # profile from whose initial tasklist this task was created ('undef' if | ||
| 47 | # none) | ||
| 48 | # - ($taskType = 'initial') name of the profile in whose initial tasklist this | ||
| 49 | # task will be. If 'undef', the global initial tasklist is used | ||
| 50 | # - ($taskType = 'custom') 'undef' | ||
| 51 | # $profCategory | ||
| 52 | # - ($taskType = 'current', 'initial') which category the profile falls undef | ||
| 53 | # (i.e. 'world', 'race', 'char', etc, or 'undef' if no profile) | ||
| 54 | # - ($taskType = 'custom') 'undef' | ||
| 55 | # $customName | ||
| 56 | # - ($taskType = 'current', 'initial') 'undef' | ||
| 57 | # - ($taskType = 'custom') the custom task name, matching a key in | ||
| 58 | # GA::Session->customTaskHash | ||
| 59 | # | ||
| 60 | # Return values | ||
| 61 | # 'undef' on improper arguments or if the task can't be added to the specified tasklist | ||
| 62 | # Blessed reference to the newly-created object on success | ||
| 63 | |||
| 64 | my ($class, $session, $taskType, $profName, $profCategory, $customName, $check) = @_; | ||
| 65 | |||
| 66 | # Check for improper arguments | ||
| 67 | if (! defined $class || ! defined $session || defined $check) { | ||
| 68 | |||
| 69 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 70 | } | ||
| 71 | |||
| 72 | if ($taskType) { | ||
| 73 | |||
| 74 | # For initial tasks, check that $profName exists | ||
| 75 | if ( | ||
| 76 | $taskType eq 'initial' | ||
| 77 | && defined $profName | ||
| 78 | && ! $session->ivExists('profHash', $profName) | ||
| 79 | ) { | ||
| 80 | return $session->writeError( | ||
| 81 | 'Can\'t create new initial task because \'' . $profName . '\' profile doesn\'t' | ||
| 82 | . ' exist', | ||
| 83 | $class . '->new', | ||
| 84 | ); | ||
| 85 | |||
| 86 | # For custom tasks, check that $customName doesn't already exist | ||
| 87 | } elsif ( | ||
| 88 | $taskType eq 'custom' | ||
| 89 | && $axmud::CLIENT->ivExists('customTaskHash', $customName) | ||
| 90 | ) { | ||
| 91 | return $session->writeError( | ||
| 92 | 'Can\'t create new custom task because \'' . $customName . '\' is already being' | ||
| 93 | . ' used', | ||
| 94 | $class . '->new', | ||
| 95 | ); | ||
| 96 | |||
| 97 | } elsif ($taskType ne 'current' && $taskType ne 'initial' && $taskType ne 'custom') { | ||
| 98 | |||
| 99 | return $session->writeError( | ||
| 100 | 'Can\'t create new task because \'' . $taskType . '\' is an invalid tasklist', | ||
| 101 | $class . '->new', | ||
| 102 | ); | ||
| 103 | } | ||
| 104 | } | ||
| 105 | |||
| 106 | # Task settings | ||
| 107 | my $self = Games::Axmud::Generic::Task->new( | ||
| 108 | $session, | ||
| 109 | $taskType, | ||
| 110 | $profName, | ||
| 111 | $profCategory, | ||
| 112 | $customName, | ||
| 113 | ); | ||
| 114 | |||
| 115 | $self->{_objName} = 'advance_task'; | ||
| 116 | $self->{_objClass} = $class; | ||
| 117 | $self->{_parentFile} = undef; # Set below | ||
| 118 | $self->{_parentWorld} = undef; # Set below | ||
| 119 | $self->{_privFlag} = TRUE, # All IVs are private | ||
| 120 | |||
| 121 | $self->{name} = 'advance_task'; | ||
| 122 | $self->{prettyName} = 'Advance'; | ||
| 123 | $self->{shortName} = 'Av'; | ||
| 124 | $self->{shortCutIV} = 'advanceTask'; # Axmud built-in jealous task | ||
| 125 | |||
| 126 | $self->{category} = 'process'; | ||
| 127 | $self->{descrip} = 'Advances character\'s guild skills'; | ||
| 128 | $self->{jealousyFlag} = TRUE; | ||
| 129 | $self->{requireLocatorFlag} = FALSE; | ||
| 130 | $self->{profSensitivityFlag} = TRUE; | ||
| 131 | $self->{storableFlag} = FALSE; # Start with ';advance' command | ||
| 132 | $self->{delayTime} = 0; | ||
| 133 | $self->{allowWinFlag} = FALSE; | ||
| 134 | $self->{requireWinFlag} = FALSE; | ||
| 135 | $self->{startWithWinFlag} = FALSE; | ||
| 136 | $self->{winPreferList} = []; | ||
| 137 | $self->{winmap} = undef; | ||
| 138 | $self->{winUpdateFunc} = undef; | ||
| 139 | $self->{tabMode} = undef; | ||
| 140 | $self->{monochromeFlag} = FALSE; | ||
| 141 | $self->{noScrollFlag} = FALSE; | ||
| 142 | $self->{ttsFlag} = FALSE; | ||
| 143 | $self->{ttsConfig} = undef; | ||
| 144 | $self->{ttsAttribHash} = {}; | ||
| 145 | $self->{ttsFlagAttribHash} = {}; | ||
| 146 | $self->{ttsAlertAttribHash} = {}; | ||
| 147 | $self->{status} = 'wait_init'; | ||
| 148 | # $self->{activeFlag} = TRUE; # Task can't be activated/disactivated | ||
| 149 | |||
| 150 | # Task parameters | ||
| 151 | # | ||
| 152 | # The skills to advance. A list in groups of two, with each group in the format | ||
| 153 | # ('skill', 'number') where <skill> is the skill to advance, and <number> the times to | ||
| 154 | # advance it. | ||
| 155 | # If 'skill' is 'undef', the next skill in the current character's skill order/cycle list is | ||
| 156 | # used | ||
| 157 | # If 'number' is -1, the skill is advanced as many times as possible, before moving onto the | ||
| 158 | # next group | ||
| 159 | # If the list is empty, it's treated the same way as a 2-element list ('undef', -1) meaning | ||
| 160 | # advance the pre-defined list as many times as possible | ||
| 161 | $self->{skillList} = []; | ||
| 162 | # The name of the current skill being advanced now | ||
| 163 | $self->{currentSkill} = undef; | ||
| 164 | # How many MORE times to advance the skill (-1 means indefinitely), 0 means this is the last | ||
| 165 | # time we're advancing this skill. Set to 'undef' when no skill being advanced | ||
| 166 | $self->{currentSkillNum} = undef; | ||
| 167 | |||
| 168 | # Advance mode: | ||
| 169 | # 'named_skill' - advancing a named skill | ||
| 170 | # 'order_list' - advancing a pre-defined skill from the order list | ||
| 171 | # 'cycle_list' - advancing a pre-defined skill from the cycle list | ||
| 172 | # In modes 'order_list' and 'cycle_list', if the advance fails, the skill is re-inserted | ||
| 173 | # into the character's order/cycle list so, the next time the task runs, the same skill | ||
| 174 | # can be advanced again (hopefully when the character has more XP/cash) | ||
| 175 | $self->{advanceMode} = 'named_skill'; | ||
| 176 | # When a success message is seen, $self->advanceSuccessSeen sets this flag to TRUE (set to | ||
| 177 | # FALSE otherwise) | ||
| 178 | $self->{advanceSuccessFlag} = TRUE; | ||
| 179 | # When a failure message is seen, $self->advanceFailSeen sets this flag to TRUE (set to | ||
| 180 | # FALSE otherwise) | ||
| 181 | $self->{advanceFailFlag} = FALSE; | ||
| 182 | # How long to wait (in seconds) for each advance to produce a response (a timeout) | ||
| 183 | $self->{waitTime} = 30; | ||
| 184 | # Next time to check (matches GA::Session->sessionTime); | ||
| 185 | $self->{nextCheckTime} = undef; | ||
| 186 | |||
| 187 | # Flag set to TRUE at stage 2, when the character hasn't logged in and a warning message is | ||
| 188 | # shown (we only want to show it once) | ||
| 189 | $self->{warningFlag} = FALSE; | ||
| 190 | |||
| 191 | # Bless task | ||
| 192 | bless $self, $class; | ||
| 193 | |||
| 194 | # For all tasks that aren't temporary... | ||
| 195 | if ($taskType) { | ||
| 196 | |||
| 197 | # Check that the task doesn't belong to a disabled plugin (in which case, it can't be | ||
| 198 | # added to any current, initial or custom tasklist) | ||
| 199 | if (! $self->checkPlugins()) { | ||
| 200 | |||
| 201 | return undef; | ||
| 202 | } | ||
| 203 | |||
| 204 | # Set the parent file object | ||
| 205 | $self->setParentFileObj($session, $taskType, $profName, $profCategory); | ||
| 206 | |||
| 207 | # Create entries in tasklists, if possible | ||
| 208 | if (! $self->updateTaskLists($session)) { | ||
| 209 | |||
| 210 | return undef; | ||
| 211 | } | ||
| 212 | } | ||
| 213 | |||
| 214 | # Task creation complete | ||
| 215 | return $self; | ||
| 216 | } | ||
| 217 | |||
| 218 | sub clone { | ||
| 219 | |||
| 220 | # Create a clone of an existing task | ||
| 221 | # Usually used upon connection to a world, when every task in the initial tasklists must | ||
| 222 | # be cloned into a new object, representing a task in the current tasklist | ||
| 223 | # (Also used when cloning a profile object, since all the tasks in its initial tasklist must | ||
| 224 | # also be cloned) | ||
| 225 | # | ||
| 226 | # Expected arguments | ||
| 227 | # $session - The parent GA::Session (not stored as an IV) | ||
| 228 | # $taskType - Which tasklist this task is being created into - 'current' for the current | ||
| 229 | # tasklist (tasks which are actually running now), 'initial' (tasks which | ||
| 230 | # should be run when the user connects to the world). Custom tasks aren't | ||
| 231 | # cloned (at the moment) | ||
| 232 | # | ||
| 233 | # Optional arguments | ||
| 234 | # $profName - ($taskType = 'initial') name of the profile in whose initial tasklist the | ||
| 235 | # existing task is stored | ||
| 236 | # $profCategory | ||
| 237 | # - ($taskType = 'initial') which category the profile falls under (i.e. | ||
| 238 | # 'world', 'race', 'char', etc) | ||
| 239 | # | ||
| 240 | # Return values | ||
| 241 | # 'undef' on improper arguments or if the task can't be cloned | ||
| 242 | # Blessed reference to the newly-created object on success | ||
| 243 | |||
| 244 | my ($self, $session, $taskType, $profName, $profCategory, $check) = @_; | ||
| 245 | |||
| 246 | # Check for improper arguments | ||
| 247 | if ( | ||
| 248 | ! defined $session || ! defined $taskType || defined $check | ||
| 249 | || ($taskType ne 'current' && $taskType ne 'initial') | ||
| 250 | || ($taskType eq 'initial' && (! defined $profName || ! defined $profCategory)) | ||
| 251 | ) { | ||
| 252 | return $axmud::CLIENT->writeImproper($self->_objClass . '->clone', @_); | ||
| 253 | } | ||
| 254 | |||
| 255 | # For initial tasks, check that $profName exists | ||
| 256 | if ( | ||
| 257 | $taskType eq 'initial' | ||
| 258 | && defined $profName | ||
| 259 | && ! $session->ivExists('profHash', $profName) | ||
| 260 | ) { | ||
| 261 | return $axmud::CLIENT->writeError( | ||
| 262 | 'Can\'t create cloned task because \'' . $profName . '\' profile doesn\'t exist', | ||
| 263 | $self->_objClass . '->clone', | ||
| 264 | ); | ||
| 265 | } | ||
| 266 | |||
| 267 | # Check that the task doesn't belong to a disabled plugin (in which case, it can't be | ||
| 268 | # cloned) | ||
| 269 | if (! $self->checkPlugins()) { | ||
| 270 | |||
| 271 | return undef; | ||
| 272 | } | ||
| 273 | |||
| 274 | # Create the new task, using default settings and parameters | ||
| 275 | my $clone = $self->_objClass->new($session, $taskType, $profName, $profCategory); | ||
| 276 | |||
| 277 | # Most of the cloned task's settings have default values, but a few are copied from the | ||
| 278 | # original | ||
| 279 | $self->cloneTaskSettings($clone); | ||
| 280 | |||
| 281 | # Give the new (cloned) task the same initial parameters as the original one | ||
| 282 | $clone->{skillList} = [$self->skillList]; | ||
| 283 | $clone->{currentSkill} = $self->currentSkill; | ||
| 284 | $clone->{currentSkillNum} = $self->currentSkillNum; | ||
| 285 | |||
| 286 | $clone->{advanceMode} = $self->advanceMode; | ||
| 287 | $clone->{advanceSuccessFlag} = $self->advanceSuccessFlag; | ||
| 288 | $clone->{advanceFailFlag} = $self->advanceFailFlag; | ||
| 289 | $clone->{waitTime} = $self->waitTime; | ||
| 290 | $clone->{nextCheckTime} = $self->nextCheckTime; | ||
| 291 | |||
| 292 | $clone->{warningFlag} = $self->warningFlag; | ||
| 293 | |||
| 294 | # Cloning complete | ||
| 295 | return $clone; | ||
| 296 | } | ||
| 297 | |||
| 298 | # sub preserve {} # Inherited from generic task | ||
| 299 | |||
| 300 | # sub setParentFileObj {} # Inherited from generic task | ||
| 301 | |||
| 302 | # sub updateTaskLists {} # Inherited from generic task | ||
| 303 | |||
| 304 | # sub ttsReadAttrib {} # Inherited from generic task | ||
| 305 | |||
| 306 | # sub ttsSwitchFlagAttrib {} # Inherited from generic task | ||
| 307 | |||
| 308 | # sub ttsSetAlertAttrib {} # Inherited from generic task | ||
| 309 | |||
| 310 | ################## | ||
| 311 | # Task windows | ||
| 312 | |||
| 313 | # sub toggleWin {} # Inherited from generic task | ||
| 314 | |||
| 315 | # sub openWin {} # Inherited from generic task | ||
| 316 | |||
| 317 | # sub closeWin {} # Inherited from generic task | ||
| 318 | |||
| 319 | ################## | ||
| 320 | # Methods | ||
| 321 | |||
| 322 | # sub main {} # Inherited from generic task | ||
| 323 | |||
| 324 | # sub doShutdown {} # Inherited from generic task | ||
| 325 | |||
| 326 | # sub doReset {} # Inherited from generic task | ||
| 327 | |||
| 328 | # sub doFirstStage {} # Inherited from generic task | ||
| 329 | |||
| 330 | sub doStage { | ||
| 331 | |||
| 332 | # Called by $self->main to process all stages (except stage 1) | ||
| 333 | # | ||
| 334 | # Expected arguments | ||
| 335 | # (none besides $self) | ||
| 336 | # | ||
| 337 | # Return values | ||
| 338 | # 'undef' on improper arguments or if this function sets that task's ->status IV to | ||
| 339 | # 'finished' or sets its ->shutdownFlag to TRUE | ||
| 340 | # Otherwise, we normally return the new value of $self->stage | ||
| 341 | |||
| 342 | my ($self, $check) = @_; | ||
| 343 | |||
| 344 | # Check for improper arguments | ||
| 345 | if (defined $check) { | ||
| 346 | |||
| 347 | return $axmud::CLIENT->writeImproper($self->_objClass . '->doStage', @_); | ||
| 348 | } | ||
| 349 | |||
| 350 | if ($self->stage == 2) { | ||
| 351 | |||
| 352 | my ($worldObj, $charObj); | ||
| 353 | |||
| 354 | # No point in continuing if there is no current guild or character | ||
| 355 | if (! $self->session->currentGuild || ! $self->session->currentChar) { | ||
| 356 | |||
| 357 | if (! $self->session->currentGuild) { | ||
| 358 | |||
| 359 | $self->writeError( | ||
| 360 | 'Advance task halting because there is no current guild profile', | ||
| 361 | $self->_objClass . '->doStage', | ||
| 362 | ); | ||
| 363 | |||
| 364 | } else { | ||
| 365 | |||
| 366 | $self->writeError( | ||
| 367 | 'Advance task halting because there is no current character profile', | ||
| 368 | $self->_objClass . '->doStage', | ||
| 369 | ); | ||
| 370 | } | ||
| 371 | |||
| 372 | $self->ivPoke('shutdownFlag', TRUE); | ||
| 373 | return undef; | ||
| 374 | |||
| 375 | # However, if the character hasn't logged in yet, wait indefinitely. The first time, | ||
| 376 | # show a warning; on subsequent times, just wait | ||
| 377 | } elsif (! $self->session->loginFlag) { | ||
| 378 | |||
| 379 | if (! $self->warningFlag) { | ||
| 380 | |||
| 381 | $self->writeWarning( | ||
| 382 | 'Advance task waiting for the character to log in to the world', | ||
| 383 | $self->_objClass . '->doStage', | ||
| 384 | ); | ||
| 385 | |||
| 386 | $self->ivPoke('warningFlag', TRUE); | ||
| 387 | } | ||
| 388 | |||
| 389 | # Repeat this stage indefinitely | ||
| 390 | return $self->ivPoke('stage', 2); | ||
| 391 | } | ||
| 392 | |||
| 393 | # Import current profiles | ||
| 394 | $worldObj = $self->session->currentWorld; | ||
| 395 | $charObj = $self->session->currentChar; | ||
| 396 | |||
| 397 | # If the current character's skill IVs have never been reset (i.e. never had default | ||
| 398 | # values imported from the current guild profile), reset them now | ||
| 399 | if (! $charObj->resetSkillsFlag) { | ||
| 400 | |||
| 401 | if (! $charObj->resetSkills($self->session)) { | ||
| 402 | |||
| 403 | $self->writeError( | ||
| 404 | 'Advance task halting because the current character profile can\'t reset' | ||
| 405 | . ' its skill IVs', | ||
| 406 | $self->_objClass . '->doStage', | ||
| 407 | ); | ||
| 408 | |||
| 409 | $self->ivPoke('shutdownFlag', TRUE); | ||
| 410 | return undef; | ||
| 411 | } | ||
| 412 | } | ||
| 413 | |||
| 414 | # If this guild's skill lists are completely empty, show a complaint (unless the user | ||
| 415 | # has specified a skill to advance) | ||
| 416 | if ( | ||
| 417 | ! defined $self->ivFirst('skillList') | ||
| 418 | && ( | ||
| 419 | ($charObj->advanceMethod eq 'order' && ! $charObj->advanceOrderList) | ||
| 420 | || ($charObj->advanceMethod eq 'cycle' && ! $charObj->advanceCycleList) | ||
| 421 | || ( | ||
| 422 | $charObj->advanceMethod eq 'combo' | ||
| 423 | && $charObj->advanceMethodStatus eq 'order' | ||
| 424 | && ! $charObj->advanceOrderList | ||
| 425 | ) | ||
| 426 | ) | ||
| 427 | ) { | ||
| 428 | $self->writeError( | ||
| 429 | 'Advance task halting because the current character\'s skill list is completely' | ||
| 430 | . ' empty', | ||
| 431 | $self->_objClass . '->doStage', | ||
| 432 | ); | ||
| 433 | |||
| 434 | $self->ivPoke('shutdownFlag', TRUE); | ||
| 435 | return FALSE; | ||
| 436 | } | ||
| 437 | |||
| 438 | # Create triggers to capture the messages for skills when successfully advanced, and | ||
| 439 | # when failing to advance | ||
| 440 | $self->resetTriggers(); | ||
| 441 | |||
| 442 | # If $self->skillList is empty, it means that we have to advance pre-defined skills as | ||
| 443 | # often as possible. Create an entry in the list (a group of 2 elements) that means | ||
| 444 | # 'advance pre-defined skills as often as possible' | ||
| 445 | if (! $self->skillList) { | ||
| 446 | |||
| 447 | $self->ivPush('skillList', undef, -1); | ||
| 448 | } | ||
| 449 | |||
| 450 | return $self->ivPoke('stage', 3); | ||
| 451 | |||
| 452 | } elsif ($self->stage == 3) { | ||
| 453 | |||
| 454 | my ($charObj, $skill, $number); | ||
| 455 | |||
| 456 | # Import the current character profile | ||
| 457 | $charObj = $self->session->currentChar; | ||
| 458 | |||
| 459 | # When there are no more skills to advance, $self->skillList is empty | ||
| 460 | if (! $self->skillList) { | ||
| 461 | |||
| 462 | $self->writeText('Advance task: Finished advancing skills'); | ||
| 463 | |||
| 464 | $self->ivPoke('shutdownFlag', TRUE); | ||
| 465 | return undef; | ||
| 466 | } | ||
| 467 | |||
| 468 | # Get the next skill from the list | ||
| 469 | $skill = $self->ivShift('skillList'); | ||
| 470 | $number = $self->ivShift('skillList'); | ||
| 471 | |||
| 472 | if (defined $skill) { | ||
| 473 | |||
| 474 | # Mark this as a named skill, not a pre-defined one | ||
| 475 | $self->ivPoke('advanceMode', 'named_skill'); | ||
| 476 | |||
| 477 | # If $skill is set to 'undef', it means use the next pre-defined skill (stored in | ||
| 478 | # the character profile) | ||
| 479 | } else { | ||
| 480 | |||
| 481 | # Find the next pre-defined skill, and store it in $skill 'order' mode | ||
| 482 | if ( | ||
| 483 | $charObj->advanceMethod eq 'order' | ||
| 484 | || ( | ||
| 485 | $charObj->advanceMethod eq 'combo' | ||
| 486 | && $charObj->advanceMethodStatus eq 'order' | ||
| 487 | ) | ||
| 488 | ) { | ||
| 489 | # If the list is empty... | ||
| 490 | if (! $charObj->currentAdvanceOrderList) { | ||
| 491 | |||
| 492 | if ($charObj->advanceMethod eq 'combo') { | ||
| 493 | |||
| 494 | # In 'combo' mode, once the order is exhausted, switch to the cycle list | ||
| 495 | $self->writeText( | ||
| 496 | 'Advance task: Character\'s skill list (\'order\' mode) exhausted;' | ||
| 497 | . ' switching to \'cycle\'', | ||
| 498 | ); | ||
| 499 | |||
| 500 | # (We'll process the cycle list in a moment) | ||
| 501 | $charObj->ivPoke('advanceMethodStatus', 'cycle'); | ||
| 502 | |||
| 503 | } else { | ||
| 504 | |||
| 505 | # Nothing more to do | ||
| 506 | $self->writeText( | ||
| 507 | 'Advance task: Character\'s skill list (\'order\' mode) exhausted;' | ||
| 508 | . ' cannot advance any more skills', | ||
| 509 | ); | ||
| 510 | |||
| 511 | $self->ivPoke('shutdownFlag', TRUE); | ||
| 512 | return undef; | ||
| 513 | } | ||
| 514 | |||
| 515 | # Otherwise, extract the first skill to be advanced | ||
| 516 | } else { | ||
| 517 | |||
| 518 | $skill = $charObj->ivShift('currentAdvanceOrderList'); | ||
| 519 | # Mark this as a pre-defined skill from the order list | ||
| 520 | $self->ivPoke('advanceMode', 'order_list'); | ||
| 521 | } | ||
| 522 | } | ||
| 523 | |||
| 524 | # 'cycle' mode | ||
| 525 | if ( | ||
| 526 | $charObj->advanceMethod eq 'cycle' | ||
| 527 | || ( | ||
| 528 | $charObj->advanceMethod eq 'combo' | ||
| 529 | && $charObj->advanceMethodStatus eq 'cycle' | ||
| 530 | ) | ||
| 531 | ) { | ||
| 532 | # If the list is empty, refresh it (ie start advancing skills from the | ||
| 533 | # beginning of the cycle again) | ||
| 534 | if (! $charObj->currentAdvanceCycleList) { | ||
| 535 | |||
| 536 | $charObj->currentAdvanceCycleList = $charObj->ivPoke( | ||
| 537 | 'currentAdvanceCycleList', | ||
| 538 | $charObj->advanceCycleList, | ||
| 539 | ); | ||
| 540 | } | ||
| 541 | |||
| 542 | # Extract the next skill to be advanced | ||
| 543 | $skill = $charObj->ivShift('currentAdvanceCycleList'); | ||
| 544 | # Mark this as a pre-defined skill from the order list | ||
| 545 | $self->ivPoke('advanceMode', 'cycle_list'); | ||
| 546 | |||
| 547 | } | ||
| 548 | |||
| 549 | # Failsafe | ||
| 550 | if (! $skill) { | ||
| 551 | |||
| 552 | $self->writeError( | ||
| 553 | 'General error in selecting a skill to advance', | ||
| 554 | $self->_objClass . '->doStage', | ||
| 555 | ); | ||
| 556 | |||
| 557 | # Can't continue | ||
| 558 | $self->ivPoke('shutdownFlag', TRUE); | ||
| 559 | return undef; | ||
| 560 | } | ||
| 561 | |||
| 562 | # Re-insert an instruction at the beginning of $self->skillList so that, when it's | ||
| 563 | # time to advance the next skill, another pre-defined skill is selected | ||
| 564 | if ($number > 1) { | ||
| 565 | |||
| 566 | $self->ivUnshift('skillList', undef, ($number - 1)); | ||
| 567 | |||
| 568 | } elsif ($number == -1) { | ||
| 569 | |||
| 570 | # Continue advancing pre-defined skills as long as possible | ||
| 571 | $self->ivUnshift('skillList', undef, -1); | ||
| 572 | } | ||
| 573 | } | ||
| 574 | |||
| 575 | # If we know how much XP/Cash we need to advance this skill, check whether it's going to | ||
| 576 | # be possible | ||
| 577 | if (! $self->checkAdvancePossible($skill)) { | ||
| 578 | |||
| 579 | # (A message has already been displayed) | ||
| 580 | if ($self->advanceMode eq 'order_list') { | ||
| 581 | |||
| 582 | # Replace the current skill in the character's skill order list, so it can be | ||
| 583 | # advanced at the next attempt (when the character has more XP/Cash) | ||
| 584 | $charObj->ivUnshift('currentAdvanceOrderList', $skill); | ||
| 585 | |||
| 586 | } elsif ($self->advanceMode eq 'cycle_list') { | ||
| 587 | |||
| 588 | # Replace the current skill in the character's skill cycle list | ||
| 589 | $charObj->ivUnshift('currentAdvanceCycleList', $skill); | ||
| 590 | } | ||
| 591 | |||
| 592 | # Give up advancing skills | ||
| 593 | $self->ivPoke('shutdownFlag', TRUE); | ||
| 594 | return undef; | ||
| 595 | } | ||
| 596 | |||
| 597 | # Record which skill we're advancing | ||
| 598 | $self->ivPoke('currentSkill', $skill); | ||
| 599 | $self->ivPoke('currentSkillNumber', $number); | ||
| 600 | |||
| 601 | # Try to advance this skill | ||
| 602 | $self->sendCmd('advance', 'text', $skill); | ||
| 603 | # Don't wait forever for a response - set a timeout | ||
| 604 | $self->ivPoke('nextCheckTime', ($self->session->sessionTime + $self->waitTime)); | ||
| 605 | |||
| 606 | return $self->ivPoke('stage', 4); | ||
| 607 | |||
| 608 | } elsif ($self->stage == 4) { | ||
| 609 | |||
| 610 | my ($charObj, $num, $skillObj); | ||
| 611 | |||
| 612 | # Import the current character profile | ||
| 613 | $charObj = $self->session->currentChar; | ||
| 614 | |||
| 615 | # Wait for something to happen - one of the triggers to fire, or the maximum time per | ||
| 616 | # advance to elapse | ||
| 617 | if ($self->advanceSuccessFlag) { | ||
| 618 | |||
| 619 | $self->writeText('Advanced skill \'' . $self->currentSkill . '\''); | ||
| 620 | # Reset the flag, ready for the next trigger to fire | ||
| 621 | $self->ivPoke('advanceSuccessFlag', FALSE); | ||
| 622 | |||
| 623 | # The skill was advanced. Update the character profile's skill statistics | ||
| 624 | # (Assume the skill level has gone up by 1, and not by more) | ||
| 625 | if ($charObj->ivExists('skillLevelHash', $self->currentSkill)) { | ||
| 626 | |||
| 627 | $num = $charObj->ivShow('skillLevelHash', $self->currentSkill); | ||
| 628 | $num++; | ||
| 629 | $charObj->ivAdd('skillLevelHash', $self->currentSkill, $num); | ||
| 630 | |||
| 631 | $num = $charObj->ivShow( | ||
| 632 | 'skillAdvanceCountHash', | ||
| 633 | $self->currentSkill, | ||
| 634 | ); | ||
| 635 | $num++; | ||
| 636 | $charObj->ivAdd('skillAdvanceCountHash', $self->currentSkill, $num); | ||
| 637 | |||
| 638 | # NB we don't know ->skillTotalXPHash, ->skillNextXPHash, ->skillTotalCashHash | ||
| 639 | # or ->skillNextCashHash yet | ||
| 640 | } | ||
| 641 | |||
| 642 | # Create a new skill history object to record the successful advance | ||
| 643 | $skillObj | ||
| 644 | = Games::Axmud::Obj::SkillHistory->new($self->session, $self->currentSkill); | ||
| 645 | |||
| 646 | if (! $skillObj) { | ||
| 647 | |||
| 648 | $self->writeWarning( | ||
| 649 | 'Could not create a skill history object for this advance', | ||
| 650 | $self->_objClass . '->doStage', | ||
| 651 | ); | ||
| 652 | |||
| 653 | } else { | ||
| 654 | |||
| 655 | if ($self->advanceMode eq 'named_skill') { | ||
| 656 | $skillObj->ivPoke('advanceMethod', 'manual'); | ||
| 657 | } elsif ($self->advanceMode eq 'order_list') { | ||
| 658 | $skillObj->ivPoke('advanceMethod', 'order'); | ||
| 659 | } elsif ($self->advanceMode eq 'cycle_list') { | ||
| 660 | $skillObj->ivPoke('advanceMethod', 'cycle'); | ||
| 661 | } | ||
| 662 | |||
| 663 | if ($charObj->ivExists('skillLevelHash', $self->currentSkill)) { | ||
| 664 | |||
| 665 | $skillObj->ivPoke( | ||
| 666 | 'skillLevel', | ||
| 667 | $charObj->ivShow('skillLevelHash', $self->currentSkill), | ||
| 668 | ); | ||
| 669 | |||
| 670 | $skillObj->ivPoke( | ||
| 671 | 'skillAdvanceCount', | ||
| 672 | $charObj->ivShow('skillAdvanceCountHash', $self->currentSkill), | ||
| 673 | ); | ||
| 674 | |||
| 675 | # NB We don't know ->skillThisXP, ->skillNextXP, ->skillThisCash or | ||
| 676 | # ->skillNextCash yet | ||
| 677 | } | ||
| 678 | } | ||
| 679 | |||
| 680 | # Run checks | ||
| 681 | if ($self->currentSkillNumber == 1) { | ||
| 682 | |||
| 683 | # We have finished advancing this skill | ||
| 684 | $self->ivUndef('currentSkill'); | ||
| 685 | $self->ivUndef('currentSkillNumber'); | ||
| 686 | |||
| 687 | # Find the next skill to advance | ||
| 688 | return $self->ivPoke('stage', 3); | ||
| 689 | |||
| 690 | } elsif ($self->currentSkillNumber > 1) { | ||
| 691 | |||
| 692 | # Update the number of times the skill must be advanced | ||
| 693 | $self->ivDecrement('currentSkillNumber'); | ||
| 694 | } | ||
| 695 | |||
| 696 | # The current skill, $self->currentSkill, must be advanced again. | ||
| 697 | # If we know how much XP/Cash we need to advance this skill, check whether it's | ||
| 698 | # going to be possible | ||
| 699 | if (! $self->checkAdvancePossible($self->currentSkill)) { | ||
| 700 | |||
| 701 | # (A message has already been displayed) | ||
| 702 | if ($self->advanceMode eq 'order_list') { | ||
| 703 | |||
| 704 | # Replace the current skill in the character's skill order list, so it can | ||
| 705 | # be advanced at the next attempt (when the character has more XP/Cash) | ||
| 706 | $charObj->ivUnshift('currentAdvanceOrderList', $self->currentSkill); | ||
| 707 | |||
| 708 | } elsif ($self->advanceMode eq 'cycle_list') { | ||
| 709 | |||
| 710 | # Replace the current skill in the character's skill cycle list | ||
| 711 | $charObj->ivUnshift('currentAdvanceCycleList', $self->currentSkill); | ||
| 712 | } | ||
| 713 | |||
| 714 | } else { | ||
| 715 | |||
| 716 | # Otherwise, advance the skill | ||
| 717 | $self->ivUnshift('skillList', $self->currentSkill, $self->currentSkillNumber); | ||
| 718 | } | ||
| 719 | |||
| 720 | return $self->ivPoke('stage', 3); | ||
| 721 | |||
| 722 | } elsif ( | ||
| 723 | $self->advanceFailFlag | ||
| 724 | || $self->session->sessionTime > $self->nextCheckTime | ||
| 725 | ) { | ||
| 726 | if ($self->advanceMode eq 'order_list') { | ||
| 727 | |||
| 728 | # Replace the current skill in the character's skill order list, so it can be | ||
| 729 | # advanced at the next attempt (when the character has more XP/Cash) | ||
| 730 | $charObj->ivUnshift('currentAdvanceOrderList', $self->currentSkill); | ||
| 731 | |||
| 732 | } elsif ($self->advanceMode eq 'cycle_list') { | ||
| 733 | |||
| 734 | # Replace the current skill in the character's skill cycle list | ||
| 735 | $charObj->ivUnshift('currentAdvanceCycleList', $self->currentSkill); | ||
| 736 | } | ||
| 737 | |||
| 738 | if ($self->advanceFailFlag) { | ||
| 739 | |||
| 740 | $self->writeText( | ||
| 741 | 'Tried to advance skill \'' . $self->currentSkill . '\', but failed', | ||
| 742 | ); | ||
| 743 | |||
| 744 | } else { | ||
| 745 | |||
| 746 | $self->writeText( | ||
| 747 | 'Timed out trying to advance skill \'' . $self->currentSkill . '\'', | ||
| 748 | ); | ||
| 749 | } | ||
| 750 | |||
| 751 | # Give up advancing skills | ||
| 752 | $self->ivPoke('shutdownFlag', TRUE); | ||
| 753 | return undef; | ||
| 754 | |||
| 755 | } else { | ||
| 756 | |||
| 757 | # Keep waiting | ||
| 758 | return $self->ivPoke('stage', 4); | ||
| 759 | } | ||
| 760 | |||
| 761 | } else { | ||
| 762 | |||
| 763 | # The task stage has somehow been set to an invalid value | ||
| 764 | return $self->invalidStage(); | ||
| 765 | } | ||
| 766 | } | ||
| 767 | |||
| 768 | sub resetTriggers { | ||
| 769 | |||
| 770 | # Called by $self->main, stage 2, to create (dependent) triggers that capture the world's | ||
| 771 | # response to an attempt to advance skills | ||
| 772 | # | ||
| 773 | # Expected arguments | ||
| 774 | # (none besides $self) | ||
| 775 | # | ||
| 776 | # Return values | ||
| 777 | # 'undef' on improper arguments | ||
| 778 | # 1 otherwise | ||
| 779 | |||
| 780 | my ($self, $check) = @_; | ||
| 781 | |||
| 782 | # Local variables | ||
| 783 | my $worldObj; | ||
| 784 | |||
| 785 | # Check for improper arguments | ||
| 786 | if (defined $check) { | ||
| 787 | |||
| 788 | return $axmud::CLIENT->writeImproper($self->_objClass . '->resetTriggers', @_); | ||
| 789 | } | ||
| 790 | |||
| 791 | # Import the current world | ||
| 792 | $worldObj = $self->session->currentWorld; | ||
| 793 | |||
| 794 | # Advance success patterns | ||
| 795 | OUTER: foreach my $pattern ($worldObj->advanceSuccessPatternList) { | ||
| 796 | |||
| 797 | my $interfaceObj = $self->session->createDependentInterface( | ||
| 798 | 'trigger', | ||
| 799 | $pattern, | ||
| 800 | $self, | ||
| 801 | 'advanceSuccessSeen', | ||
| 802 | ); | ||
| 803 | |||
| 804 | if (! $interfaceObj) { | ||
| 805 | |||
| 806 | $self->writeWarning( | ||
| 807 | 'Couldn\'t create trigger for current world profile\'s' | ||
| 808 | . ' ->advanceSuccessPatternList IV', | ||
| 809 | $self->_objClass . '->resetTriggers', | ||
| 810 | ); | ||
| 811 | |||
| 812 | last OUTER; | ||
| 813 | } | ||
| 814 | } | ||
| 815 | |||
| 816 | # Advance fail patterns | ||
| 817 | OUTER: foreach my $pattern ($worldObj->advanceFailPatternList) { | ||
| 818 | |||
| 819 | my $interfaceObj = $self->session->createDependentInterface( | ||
| 820 | 'trigger', | ||
| 821 | $pattern, | ||
| 822 | $self, | ||
| 823 | 'advanceFailSeen', | ||
| 824 | ); | ||
| 825 | |||
| 826 | if (! $interfaceObj) { | ||
| 827 | |||
| 828 | $self->writeWarning( | ||
| 829 | 'Couldn\'t create trigger for current world profile\'s' | ||
| 830 | . ' ->advanceFailPatternList IV', | ||
| 831 | $self->_objClass . '->resetTriggers', | ||
| 832 | ); | ||
| 833 | |||
| 834 | last OUTER; | ||
| 835 | } | ||
| 836 | } | ||
| 837 | |||
| 838 | # Trigger reset complete | ||
| 839 | return 1; | ||
| 840 | } | ||
| 841 | |||
| 842 | sub checkAdvancePossible { | ||
| 843 | |||
| 844 | # Called by $self->doStage, stages 3 & 4 | ||
| 845 | # When supplied with a skill that's about to be advanced, check whether it's possible (so | ||
| 846 | # far as we can tell) | ||
| 847 | # | ||
| 848 | # Expected arguments | ||
| 849 | # $skill - The skill to be advanced | ||
| 850 | # | ||
| 851 | # Return values | ||
| 852 | # 'undef' on improper arguments, or if we are sure that this skill can't be advanced | ||
| 853 | # (because of lack of XP, cash, or it's already at the maximum number of advances) | ||
| 854 | # 1 if we are sure this skill can be advanced, or if we assume it is possible, or if we're | ||
| 855 | # not sure | ||
| 856 | |||
| 857 | my ($self, $skill, $check) = @_; | ||
| 858 | |||
| 859 | # Local variables | ||
| 860 | my ($guildObj, $charObj); | ||
| 861 | |||
| 862 | # Check for improper arguments | ||
| 863 | if (! defined $skill || defined $check) { | ||
| 864 | |||
| 865 | return $axmud::CLIENT->writeImproper($self->_objClass . '->checkAdvancePossible', @_); | ||
| 866 | } | ||
| 867 | |||
| 868 | # Import current profiles and the Status task | ||
| 869 | $guildObj = $self->session->currentGuild; | ||
| 870 | $charObj = $self->session->currentChar; | ||
| 871 | |||
| 872 | # Check if the skill is already at the maximum level for this guild | ||
| 873 | if ( | ||
| 874 | $guildObj | ||
| 875 | && $guildObj->ivExists('skillMaxLevelHash', $skill) | ||
| 876 | && $guildObj->ivShow('skillMaxLevelHash', $skill) | ||
| 877 | <= $charObj->ivShow('skillLevelHash', $skill) | ||
| 878 | ) { | ||
| 879 | return $self->writeWarning( | ||
| 880 | 'Can\'t advance the skill \'' . $skill . '\' - it\'s already at the maximum level' | ||
| 881 | . ' for this guild', | ||
| 882 | $self->_objClass . '->checkAdvancePossible', | ||
| 883 | ); | ||
| 884 | } | ||
| 885 | |||
| 886 | # Check that the character has enough XP, if the amount of XP needed is known | ||
| 887 | if ( | ||
| 888 | $charObj | ||
| 889 | && $charObj->xpCurrent # Character's XP known | ||
| 890 | && $charObj->ivShow('skillNextXPHash', $skill) | ||
| 891 | && $charObj->xpCurrent < $charObj->ivShow('skillNextXPHash', $skill) | ||
| 892 | ) { | ||
| 893 | return $self->writeWarning( | ||
| 894 | 'Can\'t advance the skill \'' . $skill . '\' - not enough XP (have ' | ||
| 895 | . $charObj->xpCurrent . ', need ' | ||
| 896 | . $charObj->ivShow('skillNextXPHash', $skill), | ||
| 897 | $self->_objClass . '->checkAdvancePossible', | ||
| 898 | ); | ||
| 899 | } | ||
| 900 | |||
| 901 | # Check that the character has enough cash, if the amount of cash needed is known | ||
| 902 | if ( | ||
| 903 | $charObj | ||
| 904 | && defined $charObj->purseContents # Character's purse known | ||
| 905 | && $charObj->ivShow('skillNextCashHash', $skill) | ||
| 906 | && $charObj->purseContents < $charObj->ivShow('skillNextCashHash', $skill) | ||
| 907 | ) { | ||
| 908 | return $self->writeWarning( | ||
| 909 | 'Can\'t advance the skill \'' . $skill . '\' - not enough cash (have ' | ||
| 910 | . $charObj->purseContents . ', need ' | ||
| 911 | . $charObj->ivShow('skillNextCashHash', $skill), | ||
| 912 | $self->_objClass . '->checkAdvancePossible', | ||
| 913 | ); | ||
| 914 | } | ||
| 915 | |||
| 916 | # Otherwise assume the advance is possible | ||
| 917 | return 1; | ||
| 918 | } | ||
| 919 | |||
| 920 | ################## | ||
| 921 | # Response methods | ||
| 922 | |||
| 923 | sub advanceSuccessSeen { | ||
| 924 | |||
| 925 | # Called by GA::Session->checkTriggers | ||
| 926 | # | ||
| 927 | # This task's ->resetTriggers function creates some triggers to capture strings matching | ||
| 928 | # the world's response to a successful advance | ||
| 929 | # e.g. 'You improve your skills' | ||
| 930 | # | ||
| 931 | # The function sets a flag IV to true, enabling $self->doStage to take action when the | ||
| 932 | # task loop next spins. Group substrings and the interface's ->propertyHash are not used | ||
| 933 | # | ||
| 934 | # Expected arguments (standard args from GA::Session->checkTriggers) | ||
| 935 | # $session - The calling function's GA::Session | ||
| 936 | # $interfaceNum - The number of the active trigger interface that fired | ||
| 937 | # $line - The line of text received from the world | ||
| 938 | # $stripLine - $line, with all escape sequences removed | ||
| 939 | # $modLine - $stripLine, possibly modified by previously-checked triggers | ||
| 940 | # $grpStringListRef | ||
| 941 | # - Reference to a list of group substrings from the pattern match | ||
| 942 | # (equivalent of @_) | ||
| 943 | # $matchMinusListRef | ||
| 944 | # - Reference to a list of matched substring offsets (equivalent of @-) | ||
| 945 | # $matchPlusListRef | ||
| 946 | # - Reference to a list of matched substring offsets (equivalent of @+) | ||
| 947 | # | ||
| 948 | # Return values | ||
| 949 | # 'undef' on improper arguments, or if $session is the wrong session or if the interface | ||
| 950 | # object can't be found | ||
| 951 | # 1 otherwise | ||
| 952 | |||
| 953 | my ( | ||
| 954 | $self, $session, $interfaceNum, $line, $stripLine, $modLine, $grpStringListRef, | ||
| 955 | $matchMinusListRef, $matchPlusListRef, $check, | ||
| 956 | ) = @_; | ||
| 957 | |||
| 958 | # Local variables | ||
| 959 | my $obj; | ||
| 960 | |||
| 961 | # Check for improper arguments | ||
| 962 | if ( | ||
| 963 | ! defined $session || ! defined $interfaceNum || ! defined $line || ! defined $stripLine | ||
| 964 | || ! defined $modLine || ! defined $grpStringListRef || ! defined $matchMinusListRef | ||
| 965 | || ! defined $matchPlusListRef || defined $check | ||
| 966 | ) { | ||
| 967 | return $axmud::CLIENT->writeImproper($self->_objClass . '->advanceSuccessSeen', @_); | ||
| 968 | } | ||
| 969 | |||
| 970 | # Basic check - the trigger should belong to the right session | ||
| 971 | if ($session ne $self->session) { | ||
| 972 | |||
| 973 | return undef; | ||
| 974 | } | ||
| 975 | |||
| 976 | # Get the interface object itself | ||
| 977 | $obj = $session->ivShow('interfaceNumHash', $interfaceNum); | ||
| 978 | if (! $obj) { | ||
| 979 | |||
| 980 | return undef; | ||
| 981 | } | ||
| 982 | |||
| 983 | # Respond to the fired trigger | ||
| 984 | |||
| 985 | # Set the flag; on the next task loop, $self->doStage (at stage 4) will check it, and | ||
| 986 | # respond | ||
| 987 | $self->ivPoke('advanceSuccessFlag', TRUE); | ||
| 988 | |||
| 989 | return 1; | ||
| 990 | } | ||
| 991 | |||
| 992 | sub advanceFailSeen { | ||
| 993 | |||
| 994 | # Called by GA::Session->checkTriggers | ||
| 995 | # | ||
| 996 | # This task's ->resetTriggers function creates some triggers to capture strings matching | ||
| 997 | # the world's response to a failed advance | ||
| 998 | # e.g. 'You don't have enough experience to improve your skills' | ||
| 999 | # | ||
| 1000 | # The function sets a flag IV to true, enabling $self->doStage to take action when the | ||
| 1001 | # task loop next spins. Group substrings and the interface's ->propertyHash are not used | ||
| 1002 | # | ||
| 1003 | # Expected arguments (standard args from GA::Session->checkTriggers) | ||
| 1004 | # $session - The calling function's GA::Session | ||
| 1005 | # $interfaceNum - The number of the active trigger interface that fired | ||
| 1006 | # $line - The line of text received from the world | ||
| 1007 | # $stripLine - $line, with all escape sequences removed | ||
| 1008 | # $modLine - $stripLine, possibly modified by previously-checked triggers | ||
| 1009 | # $grpStringListRef | ||
| 1010 | # - Reference to a list of group substrings from the pattern match | ||
| 1011 | # (equivalent of @_) | ||
| 1012 | # $matchMinusListRef | ||
| 1013 | # - Reference to a list of matched substring offsets (equivalent of @-) | ||
| 1014 | # $matchPlusListRef | ||
| 1015 | # - Reference to a list of matched substring offsets (equivalent of @+) | ||
| 1016 | # | ||
| 1017 | # Return values | ||
| 1018 | # 'undef' on improper arguments, or if $session is the wrong session or if the interface | ||
| 1019 | # object can't be found | ||
| 1020 | # 1 otherwise | ||
| 1021 | |||
| 1022 | my ( | ||
| 1023 | $self, $session, $interfaceNum, $line, $stripLine, $modLine, $grpStringListRef, | ||
| 1024 | $matchMinusListRef, $matchPlusListRef, $check, | ||
| 1025 | ) = @_; | ||
| 1026 | |||
| 1027 | # Local variables | ||
| 1028 | my $obj; | ||
| 1029 | |||
| 1030 | # Check for improper arguments | ||
| 1031 | if ( | ||
| 1032 | ! defined $session || ! defined $interfaceNum || ! defined $line || ! defined $stripLine | ||
| 1033 | || ! defined $modLine || ! defined $grpStringListRef || ! defined $matchMinusListRef | ||
| 1034 | || ! defined $matchPlusListRef || defined $check | ||
| 1035 | ) { | ||
| 1036 | return $axmud::CLIENT->writeImproper($self->_objClass . '->advanceFailSeen', @_); | ||
| 1037 | } | ||
| 1038 | |||
| 1039 | # Basic check - the trigger should belong to the right session | ||
| 1040 | if ($session ne $self->session) { | ||
| 1041 | |||
| 1042 | return undef; | ||
| 1043 | } | ||
| 1044 | |||
| 1045 | # Get the interface object itself | ||
| 1046 | $obj = $session->ivShow('interfaceNumHash', $interfaceNum); | ||
| 1047 | if (! $obj) { | ||
| 1048 | |||
| 1049 | return undef; | ||
| 1050 | } | ||
| 1051 | |||
| 1052 | # Respond to the fired trigger | ||
| 1053 | |||
| 1054 | # Set the flag; on the next task loop, $self->doStage (at stage 4) will check it, and | ||
| 1055 | # respond | ||
| 1056 | $self->ivPoke('advanceFailFlag', TRUE); | ||
| 1057 | |||
| 1058 | return 1; | ||
| 1059 | } | ||
| 1060 | |||
| 1061 | ################## | ||
| 1062 | # Accessors - set | ||
| 1063 | |||
| 1064 | ################## | ||
| 1065 | # Accessors - task settings - get | ||
| 1066 | |||
| 1067 | # The accessors for task settings are inherited from the generic task | ||
| 1068 | |||
| 1069 | ################## | ||
| 1070 | # Accessors - task parameters - get | ||
| 1071 | |||
| 1072 | sub skillList | ||
| 1073 | { my $self = shift; return @{$self->{skillList}}; } | ||
| 1074 | sub currentSkill | ||
| 1075 | { $_[0]->{currentSkill} } | ||
| 1076 | sub currentSkillNum | ||
| 1077 | { $_[0]->{currentSkillNum} } | ||
| 1078 | |||
| 1079 | sub advanceMode | ||
| 1080 | { $_[0]->{advanceMode} } | ||
| 1081 | sub advanceSuccessFlag | ||
| 1082 | { $_[0]->{advanceSuccessFlag} } | ||
| 1083 | sub advanceFailFlag | ||
| 1084 | { $_[0]->{advanceFailFlag} } | ||
| 1085 | sub waitTime | ||
| 1086 | { $_[0]->{waitTime} } | ||
| 1087 | sub nextCheckTime | ||
| 1088 | { $_[0]->{nextCheckTime} } | ||
| 1089 | |||
| 1090 | sub warningFlag | ||
| 1091 | { $_[0]->{warningFlag} } | ||
| 1092 | } | ||
| 1093 | |||
| 1094 | { package Games::Axmud::Task::Attack; | ||
| 1095 | |||
| 1096 | use strict; | ||
| 1097 | use warnings; | ||
| 1098 | # use diagnostics; | ||
| 1099 | |||
| 1100 | use Glib qw(TRUE FALSE); | ||
| 1101 | |||
| 1102 | our @ISA = qw(Games::Axmud::Generic::Task Games::Axmud); | ||
| 1103 | |||
| 1104 | ################## | ||
| 1105 | # Constructors | ||
| 1106 | |||
| 1107 | sub new { | ||
| 1108 | |||
| 1109 | # Creates a new instance of the Attack task | ||
| 1110 | # | ||
| 1111 | # Expected arguments | ||
| 1112 | # $session - The parent GA::Session (not stored as an IV) | ||
| 1113 | # | ||
| 1114 | # Optional arguments | ||
| 1115 | # $taskType - Which tasklist this task is being created into - 'current' for the current | ||
| 1116 | # tasklist (tasks which are actually running now), 'initial' (tasks which | ||
| 1117 | # should be run when the user connects to the world), 'custom' (tasks with | ||
| 1118 | # customised initial parameters, which are run when the user demands). If | ||
| 1119 | # set to 'undef', this is a temporary task, created in order to access the | ||
| 1120 | # default values stored in IVs, that will not be added to any tasklist | ||
| 1121 | # $profName - ($taskType = 'current', when called by $self->clone) Name of the | ||
| 1122 | # profile from whose initial tasklist this task was created ('undef' if | ||
| 1123 | # none) | ||
| 1124 | # - ($taskType = 'initial') name of the profile in whose initial tasklist this | ||
| 1125 | # task will be. If 'undef', the global initial tasklist is used | ||
| 1126 | # - ($taskType = 'custom') 'undef' | ||
| 1127 | # $profCategory | ||
| 1128 | # - ($taskType = 'current', 'initial') which category the profile falls undef | ||
| 1129 | # (i.e. 'world', 'race', 'char', etc, or 'undef' if no profile) | ||
| 1130 | # - ($taskType = 'custom') 'undef' | ||
| 1131 | # $customName | ||
| 1132 | # - ($taskType = 'current', 'initial') 'undef' | ||
| 1133 | # - ($taskType = 'custom') the custom task name, matching a key in | ||
| 1134 | # GA::Session->customTaskHash | ||
| 1135 | # | ||
| 1136 | # Return values | ||
| 1137 | # 'undef' on improper arguments or if the task can't be added to the specified tasklist | ||
| 1138 | # Blessed reference to the newly-created object on success | ||
| 1139 | |||
| 1140 | my ($class, $session, $taskType, $profName, $profCategory, $customName, $check) = @_; | ||
| 1141 | |||
| 1142 | # Check for improper arguments | ||
| 1143 | if (! defined $class || ! defined $session || defined $check) { | ||
| 1144 | |||
| 1145 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 1146 | } | ||
| 1147 | |||
| 1148 | if ($taskType) { | ||
| 1149 | |||
| 1150 | # For initial tasks, check that $profName exists | ||
| 1151 | if ( | ||
| 1152 | $taskType eq 'initial' | ||
| 1153 | && defined $profName | ||
| 1154 | && ! $session->ivExists('profHash', $profName) | ||
| 1155 | ) { | ||
| 1156 | return $session->writeError( | ||
| 1157 | 'Can\'t create new task because \'' . $profName . '\' profile doesn\'t exist', | ||
| 1158 | $class . '->new', | ||
| 1159 | ); | ||
| 1160 | |||
| 1161 | # For custom tasks, check that $customName doesn't already exist | ||
| 1162 | } elsif ( | ||
| 1163 | $taskType eq 'custom' | ||
| 1164 | && $axmud::CLIENT->ivExists('customTaskHash', $customName) | ||
| 1165 | ) { | ||
| 1166 | return $session->writeError( | ||
| 1167 | 'Can\'t create new custom task because \'' . $customName . '\' is already being' | ||
| 1168 | . ' used', | ||
| 1169 | $class . '->new', | ||
| 1170 | ); | ||
| 1171 | |||
| 1172 | } elsif ($taskType ne 'current' && $taskType ne 'initial' && $taskType ne 'custom') { | ||
| 1173 | |||
| 1174 | return $session->writeError( | ||
| 1175 | 'Can\'t create new task because \'' . $taskType . '\' is an invalid tasklist', | ||
| 1176 | $class . '->new', | ||
| 1177 | ); | ||
| 1178 | } | ||
| 1179 | } | ||
| 1180 | |||
| 1181 | # Task settings | ||
| 1182 | my $self = Games::Axmud::Generic::Task->new( | ||
| 1183 | $session, | ||
| 1184 | $taskType, | ||
| 1185 | $profName, | ||
| 1186 | $profCategory, | ||
| 1187 | $customName, | ||
| 1188 | ); | ||
| 1189 | |||
| 1190 | $self->{_objName} = 'attack_task'; | ||
| 1191 | $self->{_objClass} = $class; | ||
| 1192 | $self->{_parentFile} = undef; # Set below | ||
| 1193 | $self->{_parentWorld} = undef; # Set below | ||
| 1194 | $self->{_privFlag} = TRUE, # All IVs are private | ||
| 1195 | |||
| 1196 | $self->{name} = 'attack_task'; | ||
| 1197 | $self->{prettyName} = 'Attack'; | ||
| 1198 | $self->{shortName} = 'At'; | ||
| 1199 | $self->{shortCutIV} = 'attackTask'; # Axmud built-in jealous task | ||
| 1200 | |||
| 1201 | $self->{category} = 'activity'; | ||
| 1202 | $self->{descrip} = 'Monitors attacks involving the current character'; | ||
| 1203 | $self->{jealousyFlag} = TRUE; | ||
| 1204 | $self->{requireLocatorFlag} = FALSE; | ||
| 1205 | $self->{profSensitivityFlag} = TRUE; | ||
| 1206 | $self->{storableFlag} = TRUE; | ||
| 1207 | $self->{delayTime} = 0; | ||
| 1208 | $self->{allowWinFlag} = FALSE; | ||
| 1209 | $self->{requireWinFlag} = FALSE; | ||
| 1210 | $self->{startWithWinFlag} = FALSE; | ||
| 1211 | $self->{winPreferList} = []; | ||
| 1212 | $self->{winmap} = undef; | ||
| 1213 | $self->{winUpdateFunc} = undef; | ||
| 1214 | $self->{tabMode} = undef; | ||
| 1215 | $self->{monochromeFlag} = FALSE; | ||
| 1216 | $self->{noScrollFlag} = FALSE; | ||
| 1217 | $self->{ttsFlag} = TRUE; | ||
| 1218 | $self->{ttsConfig} = 'attack'; | ||
| 1219 | $self->{ttsAttribHash} = {}; | ||
| 1220 | $self->{ttsFlagAttribHash} = { | ||
| 1221 | 'fight' => FALSE, | ||
| 1222 | 'interact' => FALSE, | ||
| 1223 | 'interaction' => FALSE, | ||
| 1224 | }; | ||
| 1225 | $self->{ttsAlertAttribHash} = {}; | ||
| 1226 | $self->{status} = 'wait_init'; | ||
| 1227 | # $self->{activeFlag} = TRUE; # Task can't be activated/disactivated | ||
| 1228 | |||
| 1229 | # Task parameters | ||
| 1230 | |||
| 1231 | # A list of commands to send whenever a fight succeeds (i.e., the character kills an | ||
| 1232 | # opponent) - typically 'get coins from corpses', 'score', etc | ||
| 1233 | # (These commands are sent with GA::Session->relayCmd, so don't get interpolated) | ||
| 1234 | $self->{fightCmdList} = []; | ||
| 1235 | # A list of commands to send whenever an interaction succeeds | ||
| 1236 | # (These commands are sent with GA::Session->relayCmd, so don't get interpolated) | ||
| 1237 | $self->{interactCmdList} = []; | ||
| 1238 | # Flag set to TRUE if fight/interaction results should be announced in the 'main' window, | ||
| 1239 | # FALSE if not | ||
| 1240 | $self->{announceFlag} = TRUE; | ||
| 1241 | |||
| 1242 | # Bless task | ||
| 1243 | bless $self, $class; | ||
| 1244 | |||
| 1245 | # For all tasks that aren't temporary... | ||
| 1246 | if ($taskType) { | ||
| 1247 | |||
| 1248 | # Check that the task doesn't belong to a disabled plugin (in which case, it can't be | ||
| 1249 | # added to any current, initial or custom tasklist) | ||
| 1250 | if (! $self->checkPlugins()) { | ||
| 1251 | |||
| 1252 | return undef; | ||
| 1253 | } | ||
| 1254 | |||
| 1255 | # Set the parent file object | ||
| 1256 | $self->setParentFileObj($session, $taskType, $profName, $profCategory); | ||
| 1257 | |||
| 1258 | # Create entries in tasklists, if possible | ||
| 1259 | if (! $self->updateTaskLists($session)) { | ||
| 1260 | |||
| 1261 | return undef; | ||
| 1262 | } | ||
| 1263 | } | ||
| 1264 | |||
| 1265 | # Task creation complete | ||
| 1266 | return $self; | ||
| 1267 | } | ||
| 1268 | |||
| 1269 | sub clone { | ||
| 1270 | |||
| 1271 | # Create a clone of an existing task | ||
| 1272 | # Usually used upon connection to a world, when every task in the initial tasklists must | ||
| 1273 | # be cloned into a new object, representing a task in the current tasklist | ||
| 1274 | # (Also used when cloning a profile object, since all the tasks in its initial tasklist must | ||
| 1275 | # also be cloned) | ||
| 1276 | # | ||
| 1277 | # Expected arguments | ||
| 1278 | # $session - The parent GA::Session (not stored as an IV) | ||
| 1279 | # $taskType - Which tasklist this task is being created into - 'current' for the current | ||
| 1280 | # tasklist (tasks which are actually running now), 'initial' (tasks which | ||
| 1281 | # should be run when the user connects to the world). Custom tasks aren't | ||
| 1282 | # cloned (at the moment) | ||
| 1283 | # | ||
| 1284 | # Optional arguments | ||
| 1285 | # $profName - ($taskType = 'initial') name of the profile in whose initial tasklist the | ||
| 1286 | # existing task is stored | ||
| 1287 | # $profCategory | ||
| 1288 | # - ($taskType = 'initial') which category the profile falls under (i.e. | ||
| 1289 | # 'world', 'race', 'char', etc) | ||
| 1290 | # | ||
| 1291 | # Return values | ||
| 1292 | # 'undef' on improper arguments or if the task can't be cloned | ||
| 1293 | # Blessed reference to the newly-created object on success | ||
| 1294 | |||
| 1295 | my ($self, $session, $taskType, $profName, $profCategory, $check) = @_; | ||
| 1296 | |||
| 1297 | # Check for improper arguments | ||
| 1298 | if ( | ||
| 1299 | ! defined $session || ! defined $taskType || defined $check | ||
| 1300 | || ($taskType ne 'current' && $taskType ne 'initial') | ||
| 1301 | || ($taskType eq 'initial' && (! defined $profName || ! defined $profCategory)) | ||
| 1302 | ) { | ||
| 1303 | return $axmud::CLIENT->writeImproper($self->_objClass . '->clone', @_); | ||
| 1304 | } | ||
| 1305 | |||
| 1306 | # For initial tasks, check that $profName exists | ||
| 1307 | if ( | ||
| 1308 | $taskType eq 'initial' | ||
| 1309 | && defined $profName | ||
| 1310 | && ! $session->ivExists('profHash', $profName) | ||
| 1311 | ) { | ||
| 1312 | return $axmud::CLIENT->writeError( | ||
| 1313 | 'Can\'t create cloned task because \'' . $profName . '\' profile doesn\'t exist', | ||
| 1314 | $self->_objClass . '->clone', | ||
| 1315 | ); | ||
| 1316 | } | ||
| 1317 | |||
| 1318 | # Check that the task doesn't belong to a disabled plugin (in which case, it can't be | ||
| 1319 | # cloned) | ||
| 1320 | if (! $self->checkPlugins()) { | ||
| 1321 | |||
| 1322 | return undef; | ||
| 1323 | } | ||
| 1324 | |||
| 1325 | # Create the new task, using default settings and parameters | ||
| 1326 | my $clone = $self->_objClass->new($session, $taskType, $profName, $profCategory); | ||
| 1327 | |||
| 1328 | # Most of the cloned task's settings have default values, but a few are copied from the | ||
| 1329 | # original | ||
| 1330 | $self->cloneTaskSettings($clone); | ||
| 1331 | |||
| 1332 | # Give the new (cloned) task the same initial parameters as the original one | ||
| 1333 | $clone->{fightCmdList} = [$self->fightCmdList]; | ||
| 1334 | $clone->{interactCmdList} = [$self->interactCmdList]; | ||
| 1335 | $clone->{announceFlag} = $self->announceFlag; | ||
| 1336 | |||
| 1337 | # Cloning complete | ||
| 1338 | return $clone; | ||
| 1339 | } | ||
| 1340 | |||
| 1341 | sub preserve { | ||
| 1342 | |||
| 1343 | # Called by $self->main whenever this task is reset, in order to preserve some if its task | ||
| 1344 | # parameters (but not necessarily all of them) | ||
| 1345 | # | ||
| 1346 | # Expected arguments | ||
| 1347 | # $newTask - The new task which has been created, to which some of this task's instance | ||
| 1348 | # variables might have to be transferred | ||
| 1349 | # | ||
| 1350 | # Return values | ||
| 1351 | # 'undef' on improper arguments, or if $newTask isn't in the GA::Session's current | ||
| 1352 | # tasklist | ||
| 1353 | # 1 on success | ||
| 1354 | |||
| 1355 | my ($self, $newTask, $check) = @_; | ||
| 1356 | |||
| 1357 | # Check for improper arguments | ||
| 1358 | if (! defined $newTask || defined $check) { | ||
| 1359 | |||
| 1360 | return $axmud::CLIENT->writeImproper($self->_objClass . '->preserve', @_); | ||
| 1361 | } | ||
| 1362 | |||
| 1363 | # Check the task is in the current tasklist | ||
| 1364 | if (! $self->session->ivExists('currentTaskHash', $newTask->uniqueName)) { | ||
| 1365 | |||
| 1366 | return $self->writeWarning( | ||
| 1367 | '\'' . $self->uniqueName . '\' task missing from the current tasklist', | ||
| 1368 | $self->_objClass . '->preserve', | ||
| 1369 | ); | ||
| 1370 | } | ||
| 1371 | |||
| 1372 | # Preserve some task parameters (the others are left with their default settings, some of | ||
| 1373 | # which will be re-initialised in stage 2) | ||
| 1374 | |||
| 1375 | # Preserve the command lists | ||
| 1376 | $newTask->ivPoke('fightCmdList', $self->fightCmdList); | ||
| 1377 | $newTask->ivPoke('interactCmdList', $self->interactCmdList); | ||
| 1378 | $newTask->ivPoke('announceFlag', $self->announceFlag); | ||
| 1379 | |||
| 1380 | return 1; | ||
| 1381 | } | ||
| 1382 | |||
| 1383 | # sub setParentFileObj {} # Inherited from generic task | ||
| 1384 | |||
| 1385 | # sub updateTaskLists {} # Inherited from generic task | ||
| 1386 | |||
| 1387 | # sub ttsReadAttrib {} # Inherited from generic task | ||
| 1388 | |||
| 1389 | # sub ttsSwitchFlagAttrib {} # Inherited from generic task | ||
| 1390 | |||
| 1391 | # sub ttsSetAlertAttrib {} # Inherited from generic task | ||
| 1392 | |||
| 1393 | ################## | ||
| 1394 | # Task windows | ||
| 1395 | |||
| 1396 | # sub toggleWin {} # Inherited from generic task | ||
| 1397 | |||
| 1398 | # sub openWin {} # Inherited from generic task | ||
| 1399 | |||
| 1400 | # sub closeWin {} # Inherited from generic task | ||
| 1401 | |||
| 1402 | ################## | ||
| 1403 | # Methods | ||
| 1404 | |||
| 1405 | # sub init {} # Inherited from generic task | ||
| 1406 | |||
| 1407 | sub doInit { | ||
| 1408 | |||
| 1409 | # Called by $self->init, just before the task completes its setup ($self->init) | ||
| 1410 | # | ||
| 1411 | # Expected arguments | ||
| 1412 | # (none besides $self) | ||
| 1413 | # | ||
| 1414 | # Return values | ||
| 1415 | # 'undef' on improper arguments | ||
| 1416 | # 1 otherwise | ||
| 1417 | |||
| 1418 | my ($self, $check) = @_; | ||
| 1419 | |||
| 1420 | # Check for improper arguments | ||
| 1421 | if (defined $check) { | ||
| 1422 | |||
| 1423 | return $axmud::CLIENT->writeImproper($self->_objClass . '->doInit', @_); | ||
| 1424 | } | ||
| 1425 | |||
| 1426 | # If triggers have already been created for this task, remove them before replacing them | ||
| 1427 | # with new triggers | ||
| 1428 | $self->session->tidyInterfaces($self); | ||
| 1429 | |||
| 1430 | # Set up dependent triggers for fights | ||
| 1431 | $self->resetFightTriggers(); | ||
| 1432 | # Set up dependent triggers for interactions | ||
| 1433 | $self->resetInteractionTriggers(); | ||
| 1434 | |||
| 1435 | return 1; | ||
| 1436 | } | ||
| 1437 | |||
| 1438 | # sub doShutdown {} # Inherited from generic task | ||
| 1439 | |||
| 1440 | # sub doReset {} # Inherited from generic task | ||
| 1441 | |||
| 1442 | sub resetFightTriggers { | ||
| 1443 | |||
| 1444 | # Called by $self->doInit to set up triggers for fights, based on the patterns stored in the | ||
| 1445 | # current world profile | ||
| 1446 | # | ||
| 1447 | # Expected arguments | ||
| 1448 | # (none besides $self) | ||
| 1449 | # | ||
| 1450 | # Return values | ||
| 1451 | # 'undef' on improper arguments | ||
| 1452 | # 1 otherwise | ||
| 1453 | |||
| 1454 | my ($self, $check) = @_; | ||
| 1455 | |||
| 1456 | # Local variables | ||
| 1457 | my @list; | ||
| 1458 | |||
| 1459 | # Check for improper arguments | ||
| 1460 | if (defined $check) { | ||
| 1461 | |||
| 1462 | return $axmud::CLIENT->writeImproper($self->_objClass . '->resetFightTriggers', @_); | ||
| 1463 | } | ||
| 1464 | |||
| 1465 | # Set up triggers for fights | ||
| 1466 | @list = $self->session->currentWorld->targetKilledPatternList; | ||
| 1467 | OUTER: while (@list) { | ||
| 1468 | |||
| 1469 | my ($pattern, $grpNum, $interfaceObj); | ||
| 1470 | |||
| 1471 | # The pattern to match | ||
| 1472 | $pattern = shift @list; | ||
| 1473 | # Which group substring contains the data we need | ||
| 1474 | $grpNum = shift @list; | ||
| 1475 | |||
| 1476 | # Check that @list doesn't contain missing or extra arguments | ||
| 1477 | if (! defined $grpNum) { | ||
| 1478 | |||
| 1479 | $self->writeWarning( | ||
| 1480 | 'Missing arguments in current world profile\'s ->targetKilledPatternList IV', | ||
| 1481 | $self->_objClass . '->resetFightTriggers', | ||
| 1482 | ); | ||
| 1483 | |||
| 1484 | last OUTER; | ||
| 1485 | } | ||
| 1486 | |||
| 1487 | # Create the dependent trigger interface | ||
| 1488 | $interfaceObj = $self->session->createDependentInterface( | ||
| 1489 | 'trigger', | ||
| 1490 | $pattern, | ||
| 1491 | $self, | ||
| 1492 | 'targetKilledSeen', | ||
| 1493 | ); | ||
| 1494 | |||
| 1495 | if (! $interfaceObj) { | ||
| 1496 | |||
| 1497 | $self->writeWarning( | ||
| 1498 | 'Couldn\'t create trigger for current world profile\'s' | ||
| 1499 | . ' ->targetKilledPatternList IV', | ||
| 1500 | $self->_objClass . '->resetFightTriggers', | ||
| 1501 | ); | ||
| 1502 | |||
| 1503 | last OUTER; | ||
| 1504 | |||
| 1505 | } else { | ||
| 1506 | |||
| 1507 | # Give the trigger some properties that will help $self->barPatternSeen to decide | ||
| 1508 | # what to do when the trigger fires (specifically, which group substring contains | ||
| 1509 | # the data, and which IV to update with it) | ||
| 1510 | $interfaceObj->ivAdd('propertyHash', 'grp_num', $grpNum); | ||
| 1511 | } | ||
| 1512 | } | ||
| 1513 | |||
| 1514 | return 1; | ||
| 1515 | } | ||
| 1516 | |||
| 1517 | sub resetInteractionTriggers { | ||
| 1518 | |||
| 1519 | # Called by $self->doInit to set up triggers for interactions, based on the patterns stored | ||
| 1520 | # in the current world profile | ||
| 1521 | # | ||
| 1522 | # Expected arguments | ||
| 1523 | # (none besides $self) | ||
| 1524 | # | ||
| 1525 | # Return values | ||
| 1526 | # 'undef' on improper arguments | ||
| 1527 | # 1 otherwise | ||
| 1528 | |||
| 1529 | my ($self, $check) = @_; | ||
| 1530 | |||
| 1531 | # Local variables | ||
| 1532 | my @list; | ||
| 1533 | |||
| 1534 | # Check for improper arguments | ||
| 1535 | if (defined $check) { | ||
| 1536 | |||
| 1537 | return $axmud::CLIENT->writeImproper( | ||
| 1538 | $self->_objClass . '->resetInteractionTriggers', | ||
| 1539 | @_, | ||
| 1540 | ); | ||
| 1541 | } | ||
| 1542 | |||
| 1543 | # Set up triggers for successful interactions | ||
| 1544 | @list = $self->session->currentWorld->interactionSuccessPatternList; | ||
| 1545 | OUTER: while (@list) { | ||
| 1546 | |||
| 1547 | my ($pattern, $grpNum, $interfaceObj); | ||
| 1548 | |||
| 1549 | # The pattern to match | ||
| 1550 | $pattern = shift @list; | ||
| 1551 | # Which group substring contains the data we need | ||
| 1552 | $grpNum = shift @list; | ||
| 1553 | |||
| 1554 | # Check that @list doesn't contain missing or extra arguments | ||
| 1555 | if (! defined $grpNum) { | ||
| 1556 | |||
| 1557 | $self->writeWarning( | ||
| 1558 | 'Missing arguments in current world profile\'s' | ||
| 1559 | . ' ->interactionSuccessPatternList IV', | ||
| 1560 | $self->_objClass . '->resetInteractionTriggers', | ||
| 1561 | ); | ||
| 1562 | |||
| 1563 | last OUTER; | ||
| 1564 | } | ||
| 1565 | |||
| 1566 | # Create the dependent trigger interface | ||
| 1567 | $interfaceObj = $self->session->createDependentInterface( | ||
| 1568 | 'trigger', | ||
| 1569 | $pattern, | ||
| 1570 | $self, | ||
| 1571 | 'interactionSuccessSeen', | ||
| 1572 | ); | ||
| 1573 | |||
| 1574 | if (! $interfaceObj) { | ||
| 1575 | |||
| 1576 | $self->writeWarning( | ||
| 1577 | 'Couldn\'t create trigger for current world profile\'s' | ||
| 1578 | . ' ->interactionSuccessPatternList IV', | ||
| 1579 | $self->_objClass . '->resetInteractionTriggers', | ||
| 1580 | ); | ||
| 1581 | |||
| 1582 | last OUTER; | ||
| 1583 | |||
| 1584 | } else { | ||
| 1585 | |||
| 1586 | # Give the trigger some properties that will help $self->interactionSuccessSeen to | ||
| 1587 | # decide what to do when the trigger fires (specifically, which group substring | ||
| 1588 | # contains the data, and which IV to update with it) | ||
| 1589 | $interfaceObj->ivAdd('propertyHash', 'grp_num', $grpNum); | ||
| 1590 | } | ||
| 1591 | } | ||
| 1592 | |||
| 1593 | # Set up triggers for failed interactions | ||
| 1594 | @list = $self->session->currentWorld->interactionFailPatternList; | ||
| 1595 | OUTER: while (@list) { | ||
| 1596 | |||
| 1597 | my ($pattern, $grpNum, $interfaceObj); | ||
| 1598 | |||
| 1599 | # The pattern to match | ||
| 1600 | $pattern = shift @list; | ||
| 1601 | # Which group substring contains the data we need | ||
| 1602 | $grpNum = shift @list; | ||
| 1603 | |||
| 1604 | # Check that @list doesn't contain missing or extra arguments | ||
| 1605 | if (! defined $grpNum) { | ||
| 1606 | |||
| 1607 | $self->writeWarning( | ||
| 1608 | 'Missing arguments in current world profile\'s' | ||
| 1609 | . ' ->interactionFailPatternList IV', | ||
| 1610 | $self->_objClass . '->resetInteractionTriggers', | ||
| 1611 | ); | ||
| 1612 | |||
| 1613 | last OUTER; | ||
| 1614 | } | ||
| 1615 | |||
| 1616 | # Create the dependent trigger interface | ||
| 1617 | $interfaceObj = $self->session->createDependentInterface( | ||
| 1618 | 'trigger', | ||
| 1619 | $pattern, | ||
| 1620 | $self, | ||
| 1621 | 'interactionFailSeen', | ||
| 1622 | ); | ||
| 1623 | |||
| 1624 | if (! $interfaceObj) { | ||
| 1625 | |||
| 1626 | $self->writeWarning( | ||
| 1627 | 'Couldn\'t create trigger for current world profile\'s' | ||
| 1628 | . ' ->interactionFailPatternList IV', | ||
| 1629 | $self->_objClass . '->resetInteractionTriggers', | ||
| 1630 | ); | ||
| 1631 | |||
| 1632 | last OUTER; | ||
| 1633 | |||
| 1634 | } else { | ||
| 1635 | |||
| 1636 | # Give the trigger some properties that will help $self->interactionFailSeen to | ||
| 1637 | # decide what to do when the trigger fires (specifically, which group substring | ||
| 1638 | # contains the data, and which IV to update with it) | ||
| 1639 | $interfaceObj->ivAdd('propertyHash', 'grp_num', $grpNum); | ||
| 1640 | } | ||
| 1641 | } | ||
| 1642 | |||
| 1643 | # Set up triggers for interactions that lead to a fight | ||
| 1644 | @list = $self->session->currentWorld->interactionFightPatternList; | ||
| 1645 | OUTER: while (@list) { | ||
| 1646 | |||
| 1647 | my ($pattern, $grpNum, $interfaceObj); | ||
| 1648 | |||
| 1649 | # The pattern to match | ||
| 1650 | $pattern = shift @list; | ||
| 1651 | # Which group substring contains the data we need | ||
| 1652 | $grpNum = shift @list; | ||
| 1653 | |||
| 1654 | # Check that @list doesn't contain missing or extra arguments | ||
| 1655 | if (! defined $grpNum) { | ||
| 1656 | |||
| 1657 | $self->writeWarning( | ||
| 1658 | 'Missing arguments in current world profile\'s' | ||
| 1659 | . ' ->interactionFightPatternList IV', | ||
| 1660 | $self->_objClass . '->resetInteractionTriggers', | ||
| 1661 | ); | ||
| 1662 | |||
| 1663 | last OUTER; | ||
| 1664 | } | ||
| 1665 | |||
| 1666 | # Create the dependent trigger interface | ||
| 1667 | $interfaceObj = $self->session->createDependentInterface( | ||
| 1668 | 'trigger', | ||
| 1669 | $pattern, | ||
| 1670 | $self, | ||
| 1671 | 'interactionFightSeen', | ||
| 1672 | ); | ||
| 1673 | |||
| 1674 | if (! $interfaceObj) { | ||
| 1675 | |||
| 1676 | $self->writeWarning( | ||
| 1677 | 'Couldn\'t create trigger for current world profile\'s' | ||
| 1678 | . ' ->interactionFightPatternList IV', | ||
| 1679 | $self->_objClass . '->resetInteractionTriggers', | ||
| 1680 | ); | ||
| 1681 | |||
| 1682 | last OUTER; | ||
| 1683 | |||
| 1684 | } else { | ||
| 1685 | |||
| 1686 | # Give the trigger some properties that will help $self->interactionFightSeen to | ||
| 1687 | # decide what to do when the trigger fires (specifically, which group substring | ||
| 1688 | # contains the data, and which IV to update with it) | ||
| 1689 | $interfaceObj->ivAdd('propertyHash', 'grp_num', $grpNum); | ||
| 1690 | } | ||
| 1691 | } | ||
| 1692 | |||
| 1693 | # Set up triggers for disastrous interaction | ||
| 1694 | @list = $self->session->currentWorld->interactionDisasterPatternList; | ||
| 1695 | OUTER: while (@list) { | ||
| 1696 | |||
| 1697 | my ($pattern, $grpNum, $interfaceObj); | ||
| 1698 | |||
| 1699 | # The pattern to match | ||
| 1700 | $pattern = shift @list; | ||
| 1701 | # Which group substring contains the data we need | ||
| 1702 | $grpNum = shift @list; | ||
| 1703 | |||
| 1704 | # Check that @list doesn't contain missing or extra arguments | ||
| 1705 | if (! defined $grpNum) { | ||
| 1706 | |||
| 1707 | $self->writeWarning( | ||
| 1708 | 'Missing arguments in current world profile\'s' | ||
| 1709 | . ' ->interactionDisasterPatternList IV', | ||
| 1710 | $self->_objClass . '->resetInteractionTriggers', | ||
| 1711 | ); | ||
| 1712 | |||
| 1713 | last OUTER; | ||
| 1714 | } | ||
| 1715 | |||
| 1716 | # Create the dependent trigger interface | ||
| 1717 | $interfaceObj = $self->session->createDependentInterface( | ||
| 1718 | 'trigger', | ||
| 1719 | $pattern, | ||
| 1720 | $self, | ||
| 1721 | 'interactionDisasterSeen', | ||
| 1722 | ); | ||
| 1723 | |||
| 1724 | if (! $interfaceObj) { | ||
| 1725 | |||
| 1726 | $self->writeWarning( | ||
| 1727 | 'Couldn\'t create trigger for current world profile\'s' | ||
| 1728 | . ' ->interactionDisasterPatternList IV', | ||
| 1729 | $self->_objClass . '->resetInteractionTriggers', | ||
| 1730 | ); | ||
| 1731 | |||
| 1732 | last OUTER; | ||
| 1733 | |||
| 1734 | } else { | ||
| 1735 | |||
| 1736 | # Give the trigger some properties that will help $self->interactionDisasterSeen to | ||
| 1737 | # decide what to do when the trigger fires (specifically, which group substring | ||
| 1738 | # contains the data, and which IV to update with it) | ||
| 1739 | $interfaceObj->ivAdd('propertyHash', 'grp_num', $grpNum); | ||
| 1740 | } | ||
| 1741 | } | ||
| 1742 | |||
| 1743 | return 1; | ||
| 1744 | } | ||
| 1745 | |||
| 1746 | ################## | ||
| 1747 | # Response methods | ||
| 1748 | |||
| 1749 | sub targetKilledSeen { | ||
| 1750 | |||
| 1751 | # Called by GA::Session->checkTriggers | ||
| 1752 | # | ||
| 1753 | # This task's ->resetFightTriggers function creates some triggers to capture strings | ||
| 1754 | # matching the text received, when the character wins a fight | ||
| 1755 | # e.g. ('^You kill (.*)$', 1) | ||
| 1756 | # | ||
| 1757 | # The world profile's target killed list occurs in groups of 2 elements, representing | ||
| 1758 | # [0] - the pattern to match | ||
| 1759 | # [1] - which group substring contains the data we need | ||
| 1760 | # | ||
| 1761 | # The trigger interfaces have the following properties in ->propertyHash: | ||
| 1762 | # grp_num - which group substring contains the data we need (same as [1] ) | ||
| 1763 | # | ||
| 1764 | # This function checks the appropriate group substring and updates IVs for this task and/or | ||
| 1765 | # the Status task. If there are any commands in $self->fightCmdList, they are sent to the | ||
| 1766 | # world. | ||
| 1767 | # | ||
| 1768 | # Expected arguments (standard args from GA::Session->checkTriggers) | ||
| 1769 | # $session - The calling function's GA::Session | ||
| 1770 | # $interfaceNum - The number of the active trigger interface that fired | ||
| 1771 | # $line - The line of text received from the world | ||
| 1772 | # $stripLine - $line, with all escape sequences removed | ||
| 1773 | # $modLine - $stripLine, possibly modified by previously-checked triggers | ||
| 1774 | # $grpStringListRef | ||
| 1775 | # - Reference to a list of group substrings from the pattern match | ||
| 1776 | # (equivalent of @_) | ||
| 1777 | # $matchMinusListRef | ||
| 1778 | # - Reference to a list of matched substring offsets (equivalent of @-) | ||
| 1779 | # $matchPlusListRef | ||
| 1780 | # - Reference to a list of matched substring offsets (equivalent of @+) | ||
| 1781 | # | ||
| 1782 | # Return values | ||
| 1783 | # 'undef' on improper arguments, or if $session is the wrong session, if the interface | ||
| 1784 | # object can't be found, if the victim can't be extracted from the matching text or if | ||
| 1785 | # the received line of text is an exception to the normal rules | ||
| 1786 | # 1 otherwise | ||
| 1787 | |||
| 1788 | my ( | ||
| 1789 | $self, $session, $interfaceNum, $line, $stripLine, $modLine, $grpStringListRef, | ||
| 1790 | $matchMinusListRef, $matchPlusListRef, $check, | ||
| 1791 | ) = @_; | ||
| 1792 | |||
| 1793 | # Local variables | ||
| 1794 | my ($obj, $grpNum, $victim, $charObj, $taskObj); | ||
| 1795 | |||
| 1796 | # Check for improper arguments | ||
| 1797 | if ( | ||
| 1798 | ! defined $session || ! defined $interfaceNum || ! defined $line || ! defined $stripLine | ||
| 1799 | || ! defined $modLine || ! defined $grpStringListRef || ! defined $matchMinusListRef | ||
| 1800 | || ! defined $matchPlusListRef || defined $check | ||
| 1801 | ) { | ||
| 1802 | return $axmud::CLIENT->writeImproper($self->_objClass . '->targetKilledSeen', @_); | ||
| 1803 | } | ||
| 1804 | |||
| 1805 | # Basic check - the trigger should belong to the right session | ||
| 1806 | if ($session ne $self->session) { | ||
| 1807 | |||
| 1808 | return undef; | ||
| 1809 | } | ||
| 1810 | |||
| 1811 | # Get the interface object itself | ||
| 1812 | $obj = $session->ivShow('interfaceNumHash', $interfaceNum); | ||
| 1813 | if (! $obj) { | ||
| 1814 | |||
| 1815 | return undef; | ||
| 1816 | } | ||
| 1817 | |||
| 1818 | # Respond to the fired trigger | ||
| 1819 | |||
| 1820 | # Import the trigger's properties | ||
| 1821 | $grpNum = $obj->ivShow('propertyHash', 'grp_num'); | ||
| 1822 | # Get the victim | ||
| 1823 | $victim = $$grpStringListRef[$grpNum]; | ||
| 1824 | if (! defined $victim) { | ||
| 1825 | |||
| 1826 | return undef; | ||
| 1827 | |||
| 1828 | } else { | ||
| 1829 | |||
| 1830 | # Remove any leading or trailing whitespace | ||
| 1831 | $victim = $axmud::CLIENT->trimWhitespace($victim); | ||
| 1832 | # Remove any punctuation from the end of the string | ||
| 1833 | $victim =~ s/\W+$//; | ||
| 1834 | } | ||
| 1835 | |||
| 1836 | # Import the current character and Status task | ||
| 1837 | $charObj = $session->currentChar; | ||
| 1838 | $taskObj = $session->statusTask; | ||
| 1839 | |||
| 1840 | # Check that $modLine isn't an exception to the usual rules | ||
| 1841 | foreach my $pattern ($session->currentWorld->noTargetKilledPatternList) { | ||
| 1842 | |||
| 1843 | if ($modLine =~ m/$pattern/) { | ||
| 1844 | |||
| 1845 | # Ignore this line | ||
| 1846 | return undef; | ||
| 1847 | } | ||
| 1848 | } | ||
| 1849 | |||
| 1850 | # Fight complete. Update the current character profile's IVs (via the Status task) | ||
| 1851 | if ($charObj) { | ||
| 1852 | |||
| 1853 | # ->fightVictimHash is similarly not updated, but we can update the base string hash | ||
| 1854 | if ($charObj->ivExists('fightVictimStringHash', lc($victim))) { | ||
| 1855 | $charObj->ivIncHash('fightVictimStringHash', lc($victim)); | ||
| 1856 | } else { | ||
| 1857 | $charObj->ivAdd('fightVictimStringHash', lc($victim), 1); | ||
| 1858 | } | ||
| 1859 | |||
| 1860 | if ($taskObj) { | ||
| 1861 | |||
| 1862 | # Updates ->fightCount, ->killCount | ||
| 1863 | $taskObj->inc_fightCount(); | ||
| 1864 | } | ||
| 1865 | } | ||
| 1866 | |||
| 1867 | # Write something in the 'main' window, if allowed | ||
| 1868 | if ($self->announceFlag) { | ||
| 1869 | |||
| 1870 | $self->writeText( | ||
| 1871 | '\'' . $self->uniqueName . '\' task : Detected killed target \'' . $victim . '\'', | ||
| 1872 | ); | ||
| 1873 | } | ||
| 1874 | |||
| 1875 | # Write something to the 'attack' logfile, if allowed | ||
| 1876 | $axmud::CLIENT->writeLog( | ||
| 1877 | $self->session, | ||
| 1878 | FALSE, # Not a 'standard' logfile | ||
| 1879 | $modLine, | ||
| 1880 | FALSE, # Don't precede with a newline character | ||
| 1881 | TRUE, # Use final newline character | ||
| 1882 | 'attack', # Write to this logfile | ||
| 1883 | ); | ||
| 1884 | |||
| 1885 | # Play a sound effect (if allowed) | ||
| 1886 | $axmud::CLIENT->playSound('kill'); | ||
| 1887 | |||
| 1888 | # Read a text-to-speech (TTS) message, if required | ||
| 1889 | $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->targetKilledSeen'); | ||
| 1890 | if ($self->ivShow('ttsFlagAttribHash', 'fight')) { | ||
| 1891 | |||
| 1892 | $self->ttsQuick('Killed ' . $victim); | ||
| 1893 | } | ||
| 1894 | |||
| 1895 | # Send the list of victim commands (if any) | ||
| 1896 | foreach my $cmd ($self->fightCmdList) { | ||
| 1897 | |||
| 1898 | $session->relayCmd($cmd); | ||
| 1899 | } | ||
| 1900 | |||
| 1901 | return 1; | ||
| 1902 | } | ||
| 1903 | |||
| 1904 | sub interactionSuccessSeen { | ||
| 1905 | |||
| 1906 | # Called by GA::Session->checkTriggers | ||
| 1907 | # | ||
| 1908 | # This task's ->resetInteractionTriggers function creates some triggers to capture strings | ||
| 1909 | # matching the text received, when the character experiences a successful interaction | ||
| 1910 | # e.g. ('^You cast a spell on (.*)$', 1) | ||
| 1911 | # | ||
| 1912 | # The world profile's successful interaction list occurs in groups of 2 elements, | ||
| 1913 | # representing | ||
| 1914 | # [0] - the pattern to match | ||
| 1915 | # [1] - which group substring contains the data we need | ||
| 1916 | # | ||
| 1917 | # The trigger interfaces have the following properties in ->propertyHash: | ||
| 1918 | # grp_num - which group substring contains the data we need (same as [1] ) | ||
| 1919 | # | ||
| 1920 | # This function checks the appropriate group substring and updates IVs for this task and/or | ||
| 1921 | # the Status task. If there are any commands in $self->interactCmdList, they are sent to | ||
| 1922 | # the world | ||
| 1923 | # | ||
| 1924 | # Expected arguments (standard args from GA::Session->checkTriggers) | ||
| 1925 | # $session - The calling function's GA::Session | ||
| 1926 | # $interfaceNum - The number of the active trigger interface that fired | ||
| 1927 | # $line - The line of text received from the world | ||
| 1928 | # $stripLine - $line, with all escape sequences removed | ||
| 1929 | # $modLine - $stripLine, possibly modified by previously-checked triggers | ||
| 1930 | # $grpStringListRef | ||
| 1931 | # - Reference to a list of group substrings from the pattern match | ||
| 1932 | # (equivalent of @_) | ||
| 1933 | # $matchMinusListRef | ||
| 1934 | # - Reference to a list of matched substring offsets (equivalent of @-) | ||
| 1935 | # $matchPlusListRef | ||
| 1936 | # - Reference to a list of matched substring offsets (equivalent of @+) | ||
| 1937 | # | ||
| 1938 | # Return values | ||
| 1939 | # 'undef' on improper arguments, or if $session is the wrong session, if the interface | ||
| 1940 | # object can't be found, if the victim can't be extracted from the matching text or if | ||
| 1941 | # the received line of text is an exception to the normal rules | ||
| 1942 | # 1 otherwise | ||
| 1943 | |||
| 1944 | my ( | ||
| 1945 | $self, $session, $interfaceNum, $line, $stripLine, $modLine, $grpStringListRef, | ||
| 1946 | $matchMinusListRef, $matchPlusListRef, $check, | ||
| 1947 | ) = @_; | ||
| 1948 | |||
| 1949 | # Local variables | ||
| 1950 | my ($obj, $grpNum, $victim, $charObj, $taskObj); | ||
| 1951 | |||
| 1952 | # Check for improper arguments | ||
| 1953 | if ( | ||
| 1954 | ! defined $session || ! defined $interfaceNum || ! defined $line || ! defined $stripLine | ||
| 1955 | || ! defined $modLine || ! defined $grpStringListRef || ! defined $matchMinusListRef | ||
| 1956 | || ! defined $matchPlusListRef || defined $check | ||
| 1957 | ) { | ||
| 1958 | return $axmud::CLIENT->writeImproper($self->_objClass . '->interactionSuccessSeen', @_); | ||
| 1959 | } | ||
| 1960 | |||
| 1961 | # Basic check - the trigger should belong to the right session | ||
| 1962 | if ($session ne $self->session) { | ||
| 1963 | |||
| 1964 | return undef; | ||
| 1965 | } | ||
| 1966 | |||
| 1967 | # Get the interface object itself | ||
| 1968 | $obj = $session->ivShow('interfaceNumHash', $interfaceNum); | ||
| 1969 | if (! $obj) { | ||
| 1970 | |||
| 1971 | return undef; | ||
| 1972 | } | ||
| 1973 | |||
| 1974 | # Respond to the fired trigger | ||
| 1975 | |||
| 1976 | # Import the trigger's properties | ||
| 1977 | $grpNum = $obj->ivShow('propertyHash', 'grp_num'); | ||
| 1978 | # Get the victim | ||
| 1979 | $victim = $$grpStringListRef[$grpNum]; | ||
| 1980 | if (! defined $victim) { | ||
| 1981 | |||
| 1982 | return undef; | ||
| 1983 | |||
| 1984 | } else { | ||
| 1985 | |||
| 1986 | # Remove any leading or trailing whitespace | ||
| 1987 | $victim = $axmud::CLIENT->trimWhitespace($victim); | ||
| 1988 | # Remove any punctuation from the end of the string | ||
| 1989 | $victim =~ s/\W+$//; | ||
| 1990 | } | ||
| 1991 | |||
| 1992 | # Import the current character and Status task | ||
| 1993 | $charObj = $session->currentChar; | ||
| 1994 | $taskObj = $session->statusTask; | ||
| 1995 | |||
| 1996 | # Check that $modLine isn't an exception to the usual rules | ||
| 1997 | foreach my $pattern ($session->currentWorld->noInteractionSuccessPatternList) { | ||
| 1998 | |||
| 1999 | if ($modLine =~ m/$pattern/) { | ||
| 2000 | |||
| 2001 | # Ignore this line | ||
| 2002 | return undef; | ||
| 2003 | } | ||
| 2004 | } | ||
| 2005 | |||
| 2006 | # Update the current character profile's IVs (via the Status task) | ||
| 2007 | if ($charObj) { | ||
| 2008 | |||
| 2009 | # ->interactionVictimHash can't be updated because we don't have a main noun; but | ||
| 2010 | # we can still update the base string hash | ||
| 2011 | if ($charObj->ivExists('interactionVictimStringHash', lc($victim))) { | ||
| 2012 | $charObj->ivIncHash('interactionVictimStringHash', lc($victim)); | ||
| 2013 | } else { | ||
| 2014 | $charObj->ivAdd('interactionVictimStringHash', lc($victim), 1); | ||
| 2015 | } | ||
| 2016 | |||
| 2017 | if ($taskObj) { | ||
| 2018 | |||
| 2019 | # Updates ->interactCount, ->interactSuccessCount | ||
| 2020 | $taskObj->inc_interactSuccessCount(); | ||
| 2021 | } | ||
| 2022 | } | ||
| 2023 | |||
| 2024 | # Write something in the 'main' window, if allowed | ||
| 2025 | if ($self->announceFlag) { | ||
| 2026 | |||
| 2027 | $self->writeText( | ||
| 2028 | '\'' . $self->uniqueName . '\' task : Detected successful interaction with \'' | ||
| 2029 | . $victim . '\'', | ||
| 2030 | ); | ||
| 2031 | } | ||
| 2032 | |||
| 2033 | # Write something to the 'attack' logfile, if allowed | ||
| 2034 | $axmud::CLIENT->writeLog( | ||
| 2035 | $self->session, | ||
| 2036 | FALSE, # Not a 'standard' logfile | ||
| 2037 | $modLine, | ||
| 2038 | FALSE, # Don't precede with a newline character | ||
| 2039 | TRUE, # Use final newline character | ||
| 2040 | 'attack', # Write to this logfile | ||
| 2041 | ); | ||
| 2042 | |||
| 2043 | # Play a sound effect (if allowed) | ||
| 2044 | $axmud::CLIENT->playSound('notify'); | ||
| 2045 | |||
| 2046 | # Read a text-to-speech (TTS) message, if required | ||
| 2047 | $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->interactionSuccessSeen'); | ||
| 2048 | if ( | ||
| 2049 | $self->ivShow('ttsFlagAttribHash', 'interact') | ||
| 2050 | || $self->ivShow('ttsFlagAttribHash', 'interaction') | ||
| 2051 | ) { | ||
| 2052 | $self->ttsQuick('Successful interaction with ' . $victim); | ||
| 2053 | } | ||
| 2054 | |||
| 2055 | # Send the list of victim commands (if any) | ||
| 2056 | foreach my $cmd ($self->interactCmdList) { | ||
| 2057 | |||
| 2058 | $session->relayCmd($cmd); | ||
| 2059 | } | ||
| 2060 | |||
| 2061 | return 1; | ||
| 2062 | } | ||
| 2063 | |||
| 2064 | sub interactionFailSeen { | ||
| 2065 | |||
| 2066 | # Called by GA::Session->checkTriggers | ||
| 2067 | # | ||
| 2068 | # This task's ->resetInteractionTriggers function creates some triggers to capture strings | ||
| 2069 | # matching the text received, when the character experiences a failed interaction | ||
| 2070 | # e.g. ('^You fail to cast a spell on (.*)$', 1) | ||
| 2071 | # | ||
| 2072 | # The world profile's failed interaction list occurs in groups of 2 elements, representing | ||
| 2073 | # [0] - the pattern to match | ||
| 2074 | # [1] - which group substring contains the data we need | ||
| 2075 | # | ||
| 2076 | # The trigger interfaces have the following properties in ->propertyHash: | ||
| 2077 | # grp_num - which group substring contains the data we need (same as [1] ) | ||
| 2078 | # | ||
| 2079 | # This function checks the appropriate group substring and updates IVs for this task and/or | ||
| 2080 | # the Status task. If there are any commands in $self->interactCmdList, they are sent to | ||
| 2081 | # the world | ||
| 2082 | # | ||
| 2083 | # Expected arguments (standard args from GA::Session->checkTriggers) | ||
| 2084 | # $session - The calling function's GA::Session | ||
| 2085 | # $interfaceNum - The number of the active trigger interface that fired | ||
| 2086 | # $line - The line of text received from the world | ||
| 2087 | # $stripLine - $line, with all escape sequences removed | ||
| 2088 | # $modLine - $stripLine, possibly modified by previously-checked triggers | ||
| 2089 | # $grpStringListRef | ||
| 2090 | # - Reference to a list of group substrings from the pattern match | ||
| 2091 | # (equivalent of @_) | ||
| 2092 | # $matchMinusListRef | ||
| 2093 | # - Reference to a list of matched substring offsets (equivalent of @-) | ||
| 2094 | # $matchPlusListRef | ||
| 2095 | # - Reference to a list of matched substring offsets (equivalent of @+) | ||
| 2096 | # | ||
| 2097 | # Return values | ||
| 2098 | # 'undef' on improper arguments, or if $session is the wrong session, if the interface | ||
| 2099 | # object can't be found, if the victim can't be extracted from the matching text or if | ||
| 2100 | # the received line of text is an exception to the normal rules | ||
| 2101 | # 1 otherwise | ||
| 2102 | |||
| 2103 | my ( | ||
| 2104 | $self, $session, $interfaceNum, $line, $stripLine, $modLine, $grpStringListRef, | ||
| 2105 | $matchMinusListRef, $matchPlusListRef, $check, | ||
| 2106 | ) = @_; | ||
| 2107 | |||
| 2108 | # Local variables | ||
| 2109 | my ($obj, $grpNum, $victim, $charObj, $taskObj); | ||
| 2110 | |||
| 2111 | # Check for improper arguments | ||
| 2112 | if ( | ||
| 2113 | ! defined $session || ! defined $interfaceNum || ! defined $line || ! defined $stripLine | ||
| 2114 | || ! defined $modLine || ! defined $grpStringListRef || ! defined $matchMinusListRef | ||
| 2115 | || ! defined $matchPlusListRef || defined $check | ||
| 2116 | ) { | ||
| 2117 | return $axmud::CLIENT->writeImproper($self->_objClass . '->interactionFailSeen', @_); | ||
| 2118 | } | ||
| 2119 | |||
| 2120 | # Basic check - the trigger should belong to the right session | ||
| 2121 | if ($session ne $self->session) { | ||
| 2122 | |||
| 2123 | return undef; | ||
| 2124 | } | ||
| 2125 | |||
| 2126 | # Get the interface object itself | ||
| 2127 | $obj = $session->ivShow('interfaceNumHash', $interfaceNum); | ||
| 2128 | if (! $obj) { | ||
| 2129 | |||
| 2130 | return undef; | ||
| 2131 | } | ||
| 2132 | |||
| 2133 | # Respond to the fired trigger | ||
| 2134 | |||
| 2135 | # Import the trigger's properties | ||
| 2136 | $grpNum = $obj->ivShow('propertyHash', 'grp_num'); | ||
| 2137 | # Get the victim | ||
| 2138 | $victim = $$grpStringListRef[$grpNum]; | ||
| 2139 | if (! defined $victim) { | ||
| 2140 | |||
| 2141 | return undef; | ||
| 2142 | |||
| 2143 | } else { | ||
| 2144 | |||
| 2145 | # Remove any leading or trailing whitespace | ||
| 2146 | $victim = $axmud::CLIENT->trimWhitespace($victim); | ||
| 2147 | # Remove any punctuation from the end of the string | ||
| 2148 | $victim =~ s/\W+$//; | ||
| 2149 | } | ||
| 2150 | |||
| 2151 | # Import the current character and Status task | ||
| 2152 | $charObj = $session->currentChar; | ||
| 2153 | $taskObj = $session->statusTask; | ||
| 2154 | |||
| 2155 | # Check that $modLine isn't an exception to the usual rules | ||
| 2156 | foreach my $pattern ($session->currentWorld->noInteractionFailPatternList) { | ||
| 2157 | |||
| 2158 | if ($modLine =~ m/$pattern/) { | ||
| 2159 | |||
| 2160 | # Ignore this line | ||
| 2161 | return undef; | ||
| 2162 | } | ||
| 2163 | } | ||
| 2164 | |||
| 2165 | # Interaction complete. Update the current character profile's IVs (via the Status task) | ||
| 2166 | if ($charObj && $taskObj) { | ||
| 2167 | |||
| 2168 | # Updates ->interactCount, ->interactFailCount | ||
| 2169 | $taskObj->inc_interactFailCount(); | ||
| 2170 | } | ||
| 2171 | |||
| 2172 | # Write something in the 'main' window, if allowed | ||
| 2173 | if ($self->announceFlag) { | ||
| 2174 | |||
| 2175 | $self->writeText( | ||
| 2176 | '\'' . $self->uniqueName . '\' task : Detected failed interaction with \'' | ||
| 2177 | . $victim . '\'', | ||
| 2178 | ); | ||
| 2179 | } | ||
| 2180 | |||
| 2181 | # Write something to the 'attack' logfile, if allowed | ||
| 2182 | $axmud::CLIENT->writeLog( | ||
| 2183 | $self->session, | ||
| 2184 | FALSE, # Not a 'standard' logfile | ||
| 2185 | $modLine, | ||
| 2186 | FALSE, # Don't precede with a newline character | ||
| 2187 | TRUE, # Use final newline character | ||
| 2188 | 'attack', # Write to this logfile | ||
| 2189 | ); | ||
| 2190 | |||
| 2191 | # Play a sound effect (if allowed) | ||
| 2192 | $axmud::CLIENT->playSound('notify'); | ||
| 2193 | |||
| 2194 | # Read a text-to-speech (TTS) message, if required | ||
| 2195 | $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->interactionFailSeen'); | ||
| 2196 | if ( | ||
| 2197 | $self->ivShow('ttsFlagAttribHash', 'interact') | ||
| 2198 | || $self->ivShow('ttsFlagAttribHash', 'interaction') | ||
| 2199 | ) { | ||
| 2200 | $self->ttsQuick('Failed interaction with ' . $victim); | ||
| 2201 | } | ||
| 2202 | |||
| 2203 | # Send the list of victim commands (if any) | ||
| 2204 | foreach my $cmd ($self->interactCmdList) { | ||
| 2205 | |||
| 2206 | $session->relayCmd($cmd); | ||
| 2207 | } | ||
| 2208 | |||
| 2209 | return 1; | ||
| 2210 | } | ||
| 2211 | |||
| 2212 | sub interactionFightSeen { | ||
| 2213 | |||
| 2214 | # Called by GA::Session->checkTriggers | ||
| 2215 | # | ||
| 2216 | # This task's ->resetInteractionTriggers function creates some triggers to capture strings | ||
| 2217 | # matching the text received, when the character experiences an interaction which leads to | ||
| 2218 | # a fight | ||
| 2219 | # e.g. ('^The (.*) dislikes your spell and attacks you!$', 1) | ||
| 2220 | # | ||
| 2221 | # The world profile's interaction fight list occurs in groups of 2 elements, representing | ||
| 2222 | # [0] - the pattern to match | ||
| 2223 | # [1] - which group substring contains the data we need | ||
| 2224 | # | ||
| 2225 | # The trigger interfaces have the following properties in ->propertyHash: | ||
| 2226 | # grp_num - which group substring contains the data we need (same as [1] ) | ||
| 2227 | # | ||
| 2228 | # This function checks the appropriate group substring and updates IVs for this task and/or | ||
| 2229 | # the Status task. If there are any commands in $self->interactCmdList, they are sent to | ||
| 2230 | # the world | ||
| 2231 | # | ||
| 2232 | # Expected arguments (standard args from GA::Session->checkTriggers) | ||
| 2233 | # $session - The calling function's GA::Session | ||
| 2234 | # $interfaceNum - The number of the active trigger interface that fired | ||
| 2235 | # $line - The line of text received from the world | ||
| 2236 | # $stripLine - $line, with all escape sequences removed | ||
| 2237 | # $modLine - $stripLine, possibly modified by previously-checked triggers | ||
| 2238 | # $grpStringListRef | ||
| 2239 | # - Reference to a list of group substrings from the pattern match | ||
| 2240 | # (equivalent of @_) | ||
| 2241 | # $matchMinusListRef | ||
| 2242 | # - Reference to a list of matched substring offsets (equivalent of @-) | ||
| 2243 | # $matchPlusListRef | ||
| 2244 | # - Reference to a list of matched substring offsets (equivalent of @+) | ||
| 2245 | # | ||
| 2246 | # Return values | ||
| 2247 | # 'undef' on improper arguments, or if $session is the wrong session, if the interface | ||
| 2248 | # object can't be found, if the victim can't be extracted from the matching text or if | ||
| 2249 | # the received line of text is an exception to the normal rules | ||
| 2250 | # 1 otherwise | ||
| 2251 | |||
| 2252 | my ( | ||
| 2253 | $self, $session, $interfaceNum, $line, $stripLine, $modLine, $grpStringListRef, | ||
| 2254 | $matchMinusListRef, $matchPlusListRef, $check, | ||
| 2255 | ) = @_; | ||
| 2256 | |||
| 2257 | # Local variables | ||
| 2258 | my ($obj, $grpNum, $victim, $charObj, $taskObj); | ||
| 2259 | |||
| 2260 | # Check for improper arguments | ||
| 2261 | if ( | ||
| 2262 | ! defined $session || ! defined $interfaceNum || ! defined $line || ! defined $stripLine | ||
| 2263 | || ! defined $modLine || ! defined $grpStringListRef || ! defined $matchMinusListRef | ||
| 2264 | || ! defined $matchPlusListRef || defined $check | ||
| 2265 | ) { | ||
| 2266 | return $axmud::CLIENT->writeImproper($self->_objClass . '->interactionFightSeen', @_); | ||
| 2267 | } | ||
| 2268 | |||
| 2269 | # Basic check - the trigger should belong to the right session | ||
| 2270 | if ($session ne $self->session) { | ||
| 2271 | |||
| 2272 | return undef; | ||
| 2273 | } | ||
| 2274 | |||
| 2275 | # Get the interface object itself | ||
| 2276 | $obj = $session->ivShow('interfaceNumHash', $interfaceNum); | ||
| 2277 | if (! $obj) { | ||
| 2278 | |||
| 2279 | return undef; | ||
| 2280 | } | ||
| 2281 | |||
| 2282 | # Respond to the fired trigger | ||
| 2283 | |||
| 2284 | # Import the trigger's properties | ||
| 2285 | $grpNum = $obj->ivShow('propertyHash', 'grp_num'); | ||
| 2286 | # Get the victim | ||
| 2287 | $victim = $$grpStringListRef[$grpNum]; | ||
| 2288 | if (! defined $victim) { | ||
| 2289 | |||
| 2290 | return undef; | ||
| 2291 | |||
| 2292 | } else { | ||
| 2293 | |||
| 2294 | # Remove any leading or trailing whitespace | ||
| 2295 | $victim = $axmud::CLIENT->trimWhitespace($victim); | ||
| 2296 | # Remove any punctuation from the end of the string | ||
| 2297 | $victim =~ s/\W+$//; | ||
| 2298 | } | ||
| 2299 | |||
| 2300 | # Import the current character and Status task | ||
| 2301 | $charObj = $session->currentChar; | ||
| 2302 | $taskObj = $session->statusTask; | ||
| 2303 | |||
| 2304 | # Check that $modLine isn't an exception to the usual rules | ||
| 2305 | foreach my $pattern ($session->currentWorld->noInteractionFightPatternList) { | ||
| 2306 | |||
| 2307 | if ($modLine =~ m/$pattern/) { | ||
| 2308 | |||
| 2309 | # Ignore this line | ||
| 2310 | return undef; | ||
| 2311 | } | ||
| 2312 | } | ||
| 2313 | |||
| 2314 | # Interaction complete. Update the current character profile's IVs (via the Status task) | ||
| 2315 | if ($charObj && $taskObj) { | ||
| 2316 | |||
| 2317 | # Updates ->interactCount, ->interactFightCount | ||
| 2318 | $taskObj->inc_interactFightCount(); | ||
| 2319 | } | ||
| 2320 | |||
| 2321 | # Write something in the 'main' window, if allowed | ||
| 2322 | if ($self->announceFlag) { | ||
| 2323 | |||
| 2324 | $self->writeText( | ||
| 2325 | '\'' . $self->uniqueName . '\' task : Detected interaction leading to fight with \'' | ||
| 2326 | . $victim . '\'', | ||
| 2327 | ); | ||
| 2328 | } | ||
| 2329 | |||
| 2330 | # Write something to the 'attack' logfile, if allowed | ||
| 2331 | $axmud::CLIENT->writeLog( | ||
| 2332 | $self->session, | ||
| 2333 | FALSE, # Not a 'standard' logfile | ||
| 2334 | $modLine, | ||
| 2335 | FALSE, # Don't precede with a newline character | ||
| 2336 | TRUE, # Use final newline character | ||
| 2337 | 'attack', # Write to this logfile | ||
| 2338 | ); | ||
| 2339 | |||
| 2340 | # Play a sound effect (if allowed) | ||
| 2341 | $axmud::CLIENT->playSound('notify'); | ||
| 2342 | |||
| 2343 | # Read a text-to-speech (TTS) message, if required | ||
| 2344 | $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->interactionFightSeen'); | ||
| 2345 | if ( | ||
| 2346 | $self->ivShow('ttsFlagAttribHash', 'interact') | ||
| 2347 | || $self->ivShow('ttsFlagAttribHash', 'interaction') | ||
| 2348 | ) { | ||
| 2349 | $self->ttsQuick('Interaction with ' . $victim . ' has become a fight'); | ||
| 2350 | } | ||
| 2351 | |||
| 2352 | # Send the list of victim commands (if any) | ||
| 2353 | foreach my $cmd ($self->interactCmdList) { | ||
| 2354 | |||
| 2355 | $session->relayCmd($cmd); | ||
| 2356 | } | ||
| 2357 | |||
| 2358 | return 1; | ||
| 2359 | } | ||
| 2360 | |||
| 2361 | sub interactionDisasterSeen { | ||
| 2362 | |||
| 2363 | # Called by GA::Session->checkTriggers | ||
| 2364 | # | ||
| 2365 | # This task's ->resetInteractionTriggers function creates some triggers to capture strings | ||
| 2366 | # matching the text received, when the character experiences a disastrous interaction | ||
| 2367 | # e.g. ('^The (.*) is enraged and chops your arms off!$', 1) | ||
| 2368 | # | ||
| 2369 | # The world profile's failed interaction list occurs in groups of 2 elements, representing | ||
| 2370 | # [0] - the pattern to match | ||
| 2371 | # [1] - which group substring contains the data we need | ||
| 2372 | # | ||
| 2373 | # The trigger interfaces have the following properties in ->propertyHash: | ||
| 2374 | # grp_num - which group substring contains the data we need (same as [1] ) | ||
| 2375 | # | ||
| 2376 | # This function checks the appropriate group substring and updates IVs for this task and/or | ||
| 2377 | # the Status task. If there are any commands in $self->interactCmdList, they are sent to | ||
| 2378 | # the world | ||
| 2379 | # | ||
| 2380 | # Expected arguments (standard args from GA::Session->checkTriggers) | ||
| 2381 | # $session - The calling function's GA::Session | ||
| 2382 | # $interfaceNum - The number of the active trigger interface that fired | ||
| 2383 | # $line - The line of text received from the world | ||
| 2384 | # $stripLine - $line, with all escape sequences removed | ||
| 2385 | # $modLine - $stripLine, possibly modified by previously-checked triggers | ||
| 2386 | # $grpStringListRef | ||
| 2387 | # - Reference to a list of group substrings from the pattern match | ||
| 2388 | # (equivalent of @_) | ||
| 2389 | # $matchMinusListRef | ||
| 2390 | # - Reference to a list of matched substring offsets (equivalent of @-) | ||
| 2391 | # $matchPlusListRef | ||
| 2392 | # - Reference to a list of matched substring offsets (equivalent of @+) | ||
| 2393 | # | ||
| 2394 | # Return values | ||
| 2395 | # 'undef' on improper arguments, or if $session is the wrong session, if the interface | ||
| 2396 | # object can't be found, if the victim can't be extracted from the matching text or if | ||
| 2397 | # the received line of text is an exception to the normal rules | ||
| 2398 | # 1 otherwise | ||
| 2399 | |||
| 2400 | my ( | ||
| 2401 | $self, $session, $interfaceNum, $line, $stripLine, $modLine, $grpStringListRef, | ||
| 2402 | $matchMinusListRef, $matchPlusListRef, $check, | ||
| 2403 | ) = @_; | ||
| 2404 | |||
| 2405 | # Local variables | ||
| 2406 | my ($obj, $grpNum, $victim, $charObj, $taskObj); | ||
| 2407 | |||
| 2408 | # Check for improper arguments | ||
| 2409 | if ( | ||
| 2410 | ! defined $session || ! defined $interfaceNum || ! defined $line || ! defined $stripLine | ||
| 2411 | || ! defined $modLine || ! defined $grpStringListRef || ! defined $matchMinusListRef | ||
| 2412 | || ! defined $matchPlusListRef || defined $check | ||
| 2413 | ) { | ||
| 2414 | return $axmud::CLIENT->writeImproper( | ||
| 2415 | $self->_objClass . '->interactionDisasterSeen', | ||
| 2416 | @_, | ||
| 2417 | ); | ||
| 2418 | } | ||
| 2419 | |||
| 2420 | # Basic check - the trigger should belong to the right session | ||
| 2421 | if ($session ne $self->session) { | ||
| 2422 | |||
| 2423 | return undef; | ||
| 2424 | } | ||
| 2425 | |||
| 2426 | # Get the interface object itself | ||
| 2427 | $obj = $session->ivShow('interfaceNumHash', $interfaceNum); | ||
| 2428 | if (! $obj) { | ||
| 2429 | |||
| 2430 | return undef; | ||
| 2431 | } | ||
| 2432 | |||
| 2433 | # Respond to the fired trigger | ||
| 2434 | |||
| 2435 | # Import the trigger's properties | ||
| 2436 | $grpNum = $obj->ivShow('propertyHash', 'grp_num'); | ||
| 2437 | # Get the victim | ||
| 2438 | $victim = $$grpStringListRef[$grpNum]; | ||
| 2439 | if (! defined $victim) { | ||
| 2440 | |||
| 2441 | return undef; | ||
| 2442 | |||
| 2443 | } else { | ||
| 2444 | |||
| 2445 | # Remove any leading or trailing whitespace | ||
| 2446 | $victim = $axmud::CLIENT->trimWhitespace($victim); | ||
| 2447 | # Remove any punctuation from the end of the string | ||
| 2448 | $victim =~ s/\W+$//; | ||
| 2449 | } | ||
| 2450 | |||
| 2451 | # Import the current character and Status task | ||
| 2452 | $charObj = $session->currentChar; | ||
| 2453 | $taskObj = $session->statusTask; | ||
| 2454 | |||
| 2455 | # Check that $modLine isn't an exception to the usual rules | ||
| 2456 | foreach my $pattern ($session->currentWorld->noInteractionDisasterPatternList) { | ||
| 2457 | |||
| 2458 | if ($modLine =~ m/$pattern/) { | ||
| 2459 | |||
| 2460 | # Ignore this line | ||
| 2461 | return undef; | ||
| 2462 | } | ||
| 2463 | } | ||
| 2464 | |||
| 2465 | # Interaction complete. Update the current character profile's IVs (via the Status task) | ||
| 2466 | if ($charObj && $taskObj) { | ||
| 2467 | |||
| 2468 | # Updates ->interactCount, ->interactDisasterCount | ||
| 2469 | $taskObj->inc_interactDisasterCount(); | ||
| 2470 | } | ||
| 2471 | |||
| 2472 | # Write something in the 'main' window, if allowed | ||
| 2473 | if ($self->announceFlag) { | ||
| 2474 | |||
| 2475 | $self->writeText( | ||
| 2476 | '\'' . $self->uniqueName . '\' task : Detected disastrous interaction with \'' | ||
| 2477 | . $victim . '\'', | ||
| 2478 | ); | ||
| 2479 | } | ||
| 2480 | |||
| 2481 | # Write something to the 'attack' logfile, if allowed | ||
| 2482 | $axmud::CLIENT->writeLog( | ||
| 2483 | $self->session, | ||
| 2484 | FALSE, # Not a 'standard' logfile | ||
| 2485 | $modLine, | ||
| 2486 | FALSE, # Don't precede with a newline character | ||
| 2487 | TRUE, # Use final newline character | ||
| 2488 | 'attack', # Write to this logfile | ||
| 2489 | ); | ||
| 2490 | |||
| 2491 | # Play a sound effect (if allowed) | ||
| 2492 | $axmud::CLIENT->playSound('notify'); | ||
| 2493 | |||
| 2494 | # Read a text-to-speech (TTS) message, if required | ||
| 2495 | $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->interactionDisasterSeen'); | ||
| 2496 | if ( | ||
| 2497 | $self->ivShow('ttsFlagAttribHash', 'interact') | ||
| 2498 | || $self->ivShow('ttsFlagAttribHash', 'interaction') | ||
| 2499 | ) { | ||
| 2500 | $self->ttsQuick('Disastrous interaction with ' . $victim); | ||
| 2501 | } | ||
| 2502 | |||
| 2503 | # Send the list of victim commands (if any) | ||
| 2504 | foreach my $cmd ($self->interactCmdList) { | ||
| 2505 | |||
| 2506 | $session->relayCmd($cmd); | ||
| 2507 | } | ||
| 2508 | |||
| 2509 | return 1; | ||
| 2510 | } | ||
| 2511 | |||
| 2512 | ################## | ||
| 2513 | # Accessors - set | ||
| 2514 | |||
| 2515 | ################## | ||
| 2516 | # Accessors - task settings - get | ||
| 2517 | |||
| 2518 | # The accessors for task settings are inherited from the generic task | ||
| 2519 | |||
| 2520 | ################## | ||
| 2521 | # Accessors - task parameters - get | ||
| 2522 | |||
| 2523 | sub fightCmdList | ||
| 2524 | { my $self = shift; return @{$self->{fightCmdList}}; } | ||
| 2525 | sub interactCmdList | ||
| 2526 | { my $self = shift; return @{$self->{interactCmdList}}; } | ||
| 2527 | sub announceFlag | ||
| 2528 | { $_[0]->{announceFlag} } | ||
| 2529 | } | ||
| 2530 | |||
| 2531 | { package Games::Axmud::Task::Channels; | ||
| 2532 | |||
| 2533 | use strict; | ||
| 2534 | use warnings; | ||
| 2535 | # use diagnostics; | ||
| 2536 | |||
| 2537 | use Glib qw(TRUE FALSE); | ||
| 2538 | |||
| 2539 | our @ISA = qw(Games::Axmud::Generic::Task Games::Axmud); | ||
| 2540 | |||
| 2541 | ################## | ||
| 2542 | # Constructors | ||
| 2543 | |||
| 2544 | sub new { | ||
| 2545 | |||
| 2546 | # Creates a new instances of the Channels task | ||
| 2547 | # | ||
| 2548 | # Expected arguments | ||
| 2549 | # $session - The parent GA::Session (not stored as an IV) | ||
| 2550 | # | ||
| 2551 | # Optional arguments | ||
| 2552 | # $taskType - Which tasklist this task is being created into - 'current' for the current | ||
| 2553 | # tasklist (tasks which are actually running now), 'initial' (tasks which | ||
| 2554 | # should be run when the user connects to the world), 'custom' (tasks with | ||
| 2555 | # customised initial parameters, which are run when the user demands). If | ||
| 2556 | # set to 'undef', this is a temporary task, created in order to access the | ||
| 2557 | # default values stored in IVs, that will not be added to any tasklist | ||
| 2558 | # $profName - ($taskType = 'current', when called by $self->clone) Name of the | ||
| 2559 | # profile from whose initial tasklist this task was created ('undef' if | ||
| 2560 | # none) | ||
| 2561 | # - ($taskType = 'initial') name of the profile in whose initial tasklist this | ||
| 2562 | # task will be. If 'undef', the global initial tasklist is used | ||
| 2563 | # - ($taskType = 'custom') 'undef' | ||
| 2564 | # $profCategory | ||
| 2565 | # - ($taskType = 'current', 'initial') which category the profile falls undef | ||
| 2566 | # (i.e. 'world', 'race', 'char', etc, or 'undef' if no profile) | ||
| 2567 | # - ($taskType = 'custom') 'undef' | ||
| 2568 | # $customName | ||
| 2569 | # - ($taskType = 'current', 'initial') 'undef' | ||
| 2570 | # - ($taskType = 'custom') the custom task name, matching a key in | ||
| 2571 | # GA::Session->customTaskHash | ||
| 2572 | # | ||
| 2573 | # Return values | ||
| 2574 | # 'undef' on improper arguments or if the task can't be added to the specified tasklist | ||
| 2575 | # Blessed reference to the newly-created object on success | ||
| 2576 | |||
| 2577 | my ($class, $session, $taskType, $profName, $profCategory, $customName, $check) = @_; | ||
| 2578 | |||
| 2579 | # Check for improper arguments | ||
| 2580 | if (! defined $class || ! defined $session || defined $check) { | ||
| 2581 | |||
| 2582 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 2583 | } | ||
| 2584 | |||
| 2585 | if ($taskType) { | ||
| 2586 | |||
| 2587 | # For initial tasks, check that $profName exists | ||
| 2588 | if ( | ||
| 2589 | $taskType eq 'initial' | ||
| 2590 | && defined $profName | ||
| 2591 | && ! $session->ivExists('profHash', $profName) | ||
| 2592 | ) { | ||
| 2593 | return $session->writeError( | ||
| 2594 | 'Can\'t create new task because \'' . $profName . '\' profile doesn\'t exist', | ||
| 2595 | $class . '->new', | ||
| 2596 | ); | ||
| 2597 | |||
| 2598 | # For custom tasks, check that $customName doesn't already exist | ||
| 2599 | } elsif ( | ||
| 2600 | $taskType eq 'custom' | ||
| 2601 | && $axmud::CLIENT->ivExists('customTaskHash', $customName) | ||
| 2602 | ) { | ||
| 2603 | return $session->writeError( | ||
| 2604 | 'Can\'t create new custom task because \'' . $customName . '\' is already being' | ||
| 2605 | . ' used', | ||
| 2606 | $class . '->new', | ||
| 2607 | ); | ||
| 2608 | |||
| 2609 | } elsif ($taskType ne 'current' && $taskType ne 'initial' && $taskType ne 'custom') { | ||
| 2610 | |||
| 2611 | return $session->writeError( | ||
| 2612 | 'Can\'t create new task because \'' . $taskType . '\' is an invalid tasklist', | ||
| 2613 | $class . '->new', | ||
| 2614 | ); | ||
| 2615 | } | ||
| 2616 | } | ||
| 2617 | |||
| 2618 | # Task settings | ||
| 2619 | my $self = Games::Axmud::Generic::Task->new( | ||
| 2620 | $session, | ||
| 2621 | $taskType, | ||
| 2622 | $profName, | ||
| 2623 | $profCategory, | ||
| 2624 | $customName, | ||
| 2625 | ); | ||
| 2626 | |||
| 2627 | $self->{_objName} = 'channels_task'; | ||
| 2628 | $self->{_objClass} = $class; | ||
| 2629 | $self->{_parentFile} = undef; # Set below | ||
| 2630 | $self->{_parentWorld} = undef; # Set below | ||
| 2631 | $self->{_privFlag} = TRUE, # All IVs are private | ||
| 2632 | |||
| 2633 | $self->{name} = 'channels_task'; | ||
| 2634 | $self->{prettyName} = 'Channels'; | ||
| 2635 | $self->{shortName} = 'Cl'; | ||
| 2636 | $self->{shortCutIV} = 'channelsTask'; # Axmud built-in jealous task | ||
| 2637 | |||
| 2638 | $self->{category} = 'activity'; | ||
| 2639 | $self->{descrip} = 'Displays text received from the world in multiple tabs'; | ||
| 2640 | $self->{jealousyFlag} = TRUE; | ||
| 2641 | $self->{requireLocatorFlag} = FALSE; | ||
| 2642 | $self->{profSensitivityFlag} = TRUE; | ||
| 2643 | $self->{storableFlag} = TRUE; | ||
| 2644 | $self->{delayTime} = 0; | ||
| 2645 | $self->{allowWinFlag} = TRUE; | ||
| 2646 | $self->{requireWinFlag} = TRUE; | ||
| 2647 | $self->{startWithWinFlag} = TRUE; | ||
| 2648 | $self->{winPreferList} = ['pane', 'grid']; | ||
| 2649 | $self->{winmap} = 'basic_fill'; | ||
| 2650 | $self->{winUpdateFunc} = 'restoreWin'; | ||
| 2651 | $self->{tabMode} = 'empty'; | ||
| 2652 | $self->{monochromeFlag} = FALSE; | ||
| 2653 | $self->{noScrollFlag} = FALSE; | ||
| 2654 | $self->{ttsFlag} = TRUE; | ||
| 2655 | $self->{ttsConfig} = 'channels'; | ||
| 2656 | $self->{ttsAttribHash} = {}; | ||
| 2657 | $self->{ttsFlagAttribHash} = { | ||
| 2658 | 'channels' => FALSE, | ||
| 2659 | }; | ||
| 2660 | $self->{ttsAlertAttribHash} = {}; | ||
| 2661 | $self->{status} = 'wait_init'; | ||
| 2662 | # $self->{activeFlag} = TRUE; # Task can't be activated/disactivated | ||
| 2663 | |||
| 2664 | # Task parameters | ||
| 2665 | # | ||
| 2666 | # Multiple triggers can match a single line, but this task only displays a single line in | ||
| 2667 | # its task window once. The display buffer line number of the last line that matched a | ||
| 2668 | # tell, social or custom pattern | ||
| 2669 | $self->{lastLine} = 0; | ||
| 2670 | # The task window's pane object (GA::Table::Pane) has multiple tabs, one for each channel. | ||
| 2671 | # A hash of tabs in use, in the form | ||
| 2672 | # $tabHash{channel_name} = blessed_reference_to_tab_object | ||
| 2673 | $self->{tabHash} = {}, | ||
| 2674 | |||
| 2675 | # Summary mode | ||
| 2676 | # 'single' - Use a single tab, in which all text for all channels is displayed. Any | ||
| 2677 | # channels specified in $self->initChannelList are ignored | ||
| 2678 | # 'multi' - Every channel has its own tab and, in addition, there is a 'summmary' tab | ||
| 2679 | # which duplicates text displayed in every channel | ||
| 2680 | # 'default' - Every channel has its own tab and there is no 'summary' channel | ||
| 2681 | $self->{summaryMode} = 'default', | ||
| 2682 | # The channel name to use for the 'summary' channel | ||
| 2683 | $self->{summaryChannel} = 'all', | ||
| 2684 | |||
| 2685 | # List of channels for which a tab should be added when the window opens, even though there | ||
| 2686 | # is no text to display yet | ||
| 2687 | $self->{initChannelList} = [ | ||
| 2688 | # Three of the four 'channels' for which the Divert task has an assigned background | ||
| 2689 | # colour/sound effect | ||
| 2690 | 'tell', 'social', 'custom', | ||
| 2691 | ]; | ||
| 2692 | # List of channels that should be ignored (i.e. no tab is created for the channel, and when | ||
| 2693 | # text is received to display in one of these channels, it is not displayed, not even in | ||
| 2694 | # the summary channel) | ||
| 2695 | # The summary channel and any channels in $self->initChannelList can't be ignored. If | ||
| 2696 | # any of them are added to this list, they are not ignored | ||
| 2697 | $self->{ignoreChannelList} = [], | ||
| 2698 | |||
| 2699 | # In these hashes, the keys are affected channels names, and the corresponding values are | ||
| 2700 | # 'undef' or FALSE if the effect shouldn't be applied (so the user can disable it, | ||
| 2701 | # without emptying the hash of channel names) | ||
| 2702 | # | ||
| 2703 | # Hash of sound effects that should be played when text is displayed in a channel. The keys | ||
| 2704 | # are channel names; the corresponding value is a sound effect | ||
| 2705 | $self->{soundEffectHash} = { | ||
| 2706 | 'tell' => 'greeting', | ||
| 2707 | 'social' => 'notify', | ||
| 2708 | 'custom' => 'notify', | ||
| 2709 | 'warning' => 'alarm', | ||
| 2710 | }, | ||
| 2711 | # Hash of flags. The keys are channel names, the corresponding value is TRUE if the task | ||
| 2712 | # window's urgency hint should be displayed when the channel receives text, FALSE if not | ||
| 2713 | $self->{urgencyHash} = { | ||
| 2714 | 'tell' => FALSE, | ||
| 2715 | 'social' => FALSE, | ||
| 2716 | 'custom' => FALSE, | ||
| 2717 | 'warning' => FALSE, | ||
| 2718 | }, | ||
| 2719 | |||
| 2720 | # Flag set to TRUE if the tabs should have a close button, FALSE if not | ||
| 2721 | $self->{tabCloseButtonFlag} = FALSE; | ||
| 2722 | # Flag set to TRUE if channel names, displayed in the tab labels, should be capitalised | ||
| 2723 | $self->{capitaliseFlag} = TRUE; | ||
| 2724 | # Flag set to TRUE if the original line's colour/style tags should be preserved in the task | ||
| 2725 | # window | ||
| 2726 | $self->{useColourStyleFlag} = TRUE; | ||
| 2727 | |||
| 2728 | # Bless task | ||
| 2729 | bless $self, $class; | ||
| 2730 | |||
| 2731 | # For all tasks that aren't temporary... | ||
| 2732 | if ($taskType) { | ||
| 2733 | |||
| 2734 | # Check that the task doesn't belong to a disabled plugin (in which case, it can't be | ||
| 2735 | # added to any current, initial or custom tasklist) | ||
| 2736 | if (! $self->checkPlugins()) { | ||
| 2737 | |||
| 2738 | return undef; | ||
| 2739 | } | ||
| 2740 | |||
| 2741 | # Set the parent file object | ||
| 2742 | $self->setParentFileObj($session, $taskType, $profName, $profCategory); | ||
| 2743 | |||
| 2744 | # Create entries in tasklists, if possible | ||
| 2745 | if (! $self->updateTaskLists($session)) { | ||
| 2746 | |||
| 2747 | return undef; | ||
| 2748 | } | ||
| 2749 | } | ||
| 2750 | |||
| 2751 | # Task creation complete | ||
| 2752 | return $self; | ||
| 2753 | } | ||
| 2754 | |||
| 2755 | sub clone { | ||
| 2756 | |||
| 2757 | # Create a clone of an existing task | ||
| 2758 | # Usually used upon connection to a world, when every task in the initial tasklists must | ||
| 2759 | # be cloned into a new object, representing a task in the current tasklist | ||
| 2760 | # (Also used when cloning a profile object, since all the tasks in its initial tasklist must | ||
| 2761 | # also be cloned) | ||
| 2762 | # | ||
| 2763 | # Expected arguments | ||
| 2764 | # $session - The parent GA::Session (not stored as an IV) | ||
| 2765 | # $taskType - Which tasklist this task is being created into - 'current' for the current | ||
| 2766 | # tasklist (tasks which are actually running now), 'initial' (tasks which | ||
| 2767 | # should be run when the user connects to the world). Custom tasks aren't | ||
| 2768 | # cloned (at the moment) | ||
| 2769 | # | ||
| 2770 | # Optional arguments | ||
| 2771 | # $profName - ($taskType = 'initial') name of the profile in whose initial tasklist the | ||
| 2772 | # existing task is stored | ||
| 2773 | # $profCategory | ||
| 2774 | # - ($taskType = 'initial') which category the profile falls under (i.e. | ||
| 2775 | # 'world', 'race', 'char', etc) | ||
| 2776 | # | ||
| 2777 | # Return values | ||
| 2778 | # 'undef' on improper arguments or if the task can't be cloned | ||
| 2779 | # Blessed reference to the newly-created object on success | ||
| 2780 | |||
| 2781 | my ($self, $session, $taskType, $profName, $profCategory, $check) = @_; | ||
| 2782 | |||
| 2783 | # Check for improper arguments | ||
| 2784 | if ( | ||
| 2785 | ! defined $session || ! defined $taskType || defined $check | ||
| 2786 | || ($taskType ne 'current' && $taskType ne 'initial') | ||
| 2787 | || ($taskType eq 'initial' && (! defined $profName || ! defined $profCategory)) | ||
| 2788 | ) { | ||
| 2789 | return $axmud::CLIENT->writeImproper($self->_objClass . '->clone', @_); | ||
| 2790 | } | ||
| 2791 | |||
| 2792 | # For initial tasks, check that $profName exists | ||
| 2793 | if ( | ||
| 2794 | $taskType eq 'initial' | ||
| 2795 | && defined $profName | ||
| 2796 | && ! $session->ivExists('profHash', $profName) | ||
| 2797 | ) { | ||
| 2798 | return $axmud::CLIENT->writeError( | ||
| 2799 | 'Can\'t create cloned task because \'' . $profName . '\' profile doesn\'t exist', | ||
| 2800 | $self->_objClass . '->clone', | ||
| 2801 | ); | ||
| 2802 | } | ||
| 2803 | |||
| 2804 | # Check that the task doesn't belong to a disabled plugin (in which case, it can't be | ||
| 2805 | # cloned) | ||
| 2806 | if (! $self->checkPlugins()) { | ||
| 2807 | |||
| 2808 | return undef; | ||
| 2809 | } | ||
| 2810 | |||
| 2811 | # Create the new task, using default settings and parameters | ||
| 2812 | my $clone = $self->_objClass->new($session, $taskType, $profName, $profCategory); | ||
| 2813 | |||
| 2814 | # Most of the cloned task's settings have default values, but a few are copied from the | ||
| 2815 | # original | ||
| 2816 | $self->cloneTaskSettings($clone); | ||
| 2817 | |||
| 2818 | # Give the new (cloned) task the same initial parameters as the original one | ||
| 2819 | $clone->{lastLine} = $self->lastLine; | ||
| 2820 | $clone->{tabHash} = {$self->tabHash}; | ||
| 2821 | |||
| 2822 | $clone->{summaryMode} = $self->summaryMode; | ||
| 2823 | $clone->{summaryChannel} = $self->summaryChannel; | ||
| 2824 | |||
| 2825 | $clone->{initChannelList} = [$self->initChannelList]; | ||
| 2826 | $clone->{ignoreChannelList} = [$self->ignoreChannelList]; | ||
| 2827 | |||
| 2828 | $clone->{soundEffectHash} = {$self->soundEffectHash}; | ||
| 2829 | $clone->{urgencyHash} = {$self->urgencyHash}; | ||
| 2830 | |||
| 2831 | $clone->{tabCloseButtonFlag} = $self->tabCloseButtonFlag; | ||
| 2832 | $clone->{capitaliseFlag} = $self->capitaliseFlag; | ||
| 2833 | $clone->{useColourStyleFlag} = $self->useColourStyleFlag; | ||
| 2834 | |||
| 2835 | # Cloning complete | ||
| 2836 | return $clone; | ||
| 2837 | } | ||
| 2838 | |||
| 2839 | sub preserve { | ||
| 2840 | |||
| 2841 | # Called by $self->main whenever this task is reset, in order to preserve some if its task | ||
| 2842 | # parameters (but not necessarily all of them) | ||
| 2843 | # | ||
| 2844 | # Expected arguments | ||
| 2845 | # $newTask - The new task which has been created, to which some of this task's instance | ||
| 2846 | # variables might have to be transferred | ||
| 2847 | # | ||
| 2848 | # Return values | ||
| 2849 | # 'undef' on improper arguments, or if $newTask isn't in the GA::Session's current | ||
| 2850 | # tasklist | ||
| 2851 | # 1 on success | ||
| 2852 | |||
| 2853 | my ($self, $newTask, $check) = @_; | ||
| 2854 | |||
| 2855 | # Check for improper arguments | ||
| 2856 | if (! defined $newTask || defined $check) { | ||
| 2857 | |||
| 2858 | return $axmud::CLIENT->writeImproper($self->_objClass . '->preserve', @_); | ||
| 2859 | } | ||
| 2860 | |||
| 2861 | # Check the task is in the current tasklist | ||
| 2862 | if (! $self->session->ivExists('currentTaskHash', $newTask->uniqueName)) { | ||
| 2863 | |||
| 2864 | return $self->writeWarning( | ||
| 2865 | '\'' . $self->uniqueName . '\' task missing from the current tasklist', | ||
| 2866 | $self->_objClass . '->preserve', | ||
| 2867 | ); | ||
| 2868 | } | ||
| 2869 | |||
| 2870 | # Preserve some task parameters (the others are left with their default settings, some of | ||
| 2871 | # which will be re-initialised in stage 2) | ||
| 2872 | |||
| 2873 | # Preserve summary channel IVs | ||
| 2874 | $newTask->ivPoke('summaryMode', $self->summaryMode); | ||
| 2875 | $newTask->ivPoke('summaryChannel', $self->summaryChannel); | ||
| 2876 | |||
| 2877 | # Preserve initial and ignorable channels | ||
| 2878 | $newTask->ivPoke('initChannelList', $self->initChannelList); | ||
| 2879 | $newTask->ivPoke('ignoreChannelList', $self->ignoreChannelList); | ||
| 2880 | |||
| 2881 | # Preserve sound effect and urgency settings | ||
| 2882 | $newTask->ivPoke('soundEffectHash', $self->soundEffectHash); | ||
| 2883 | $newTask->ivPoke('urgencyHash', $self->urgencyHash); | ||
| 2884 | |||
| 2885 | # Preserve other customisation settings | ||
| 2886 | $newTask->ivPoke('tabCloseButtonFlag', $self->tabCloseButtonFlag); | ||
| 2887 | $newTask->ivPoke('capitaliseFlag', $self->capitaliseFlag); | ||
| 2888 | $newTask->ivPoke('useColourStyleFlag', $self->useColourStyleFlag); | ||
| 2889 | |||
| 2890 | return 1; | ||
| 2891 | } | ||
| 2892 | |||
| 2893 | # sub setParentFileObj {} # Inherited from generic task | ||
| 2894 | |||
| 2895 | # sub updateTaskLists {} # Inherited from generic task | ||
| 2896 | |||
| 2897 | # sub ttsReadAttrib {} # Inherited from generic task | ||
| 2898 | |||
| 2899 | # sub ttsSwitchFlagAttrib {} # Inherited from generic task | ||
| 2900 | |||
| 2901 | # sub ttsSetAlertAttrib {} # Inherited from generic task | ||
| 2902 | |||
| 2903 | ################## | ||
| 2904 | # Task windows | ||
| 2905 | |||
| 2906 | # sub toggleWin {} # Inherited from generic task | ||
| 2907 | |||
| 2908 | # sub openWin {} # Inherited from generic task | ||
| 2909 | |||
| 2910 | # sub closeWin {} # Inherited from generic task | ||
| 2911 | |||
| 2912 | ################## | ||
| 2913 | # Methods | ||
| 2914 | |||
| 2915 | # sub init {} # Inherited from generic task | ||
| 2916 | |||
| 2917 | sub doInit { | ||
| 2918 | |||
| 2919 | # Called by $self->init, just before the task completes its setup ($self->init) | ||
| 2920 | # | ||
| 2921 | # Expected arguments | ||
| 2922 | # (none besides $self) | ||
| 2923 | # | ||
| 2924 | # Return values | ||
| 2925 | # 'undef' on improper arguments or if a Divert task is running | ||
| 2926 | # 1 otherwise | ||
| 2927 | |||
| 2928 | my ($self, $check) = @_; | ||
| 2929 | |||
| 2930 | # Check for improper arguments | ||
| 2931 | if (defined $check) { | ||
| 2932 | |||
| 2933 | return $axmud::CLIENT->writeImproper($self->_objClass . '->doInit', @_); | ||
| 2934 | } | ||
| 2935 | |||
| 2936 | # The Channels and Divert tasks can't run at the same time | ||
| 2937 | if ($self->session->divertTask) { | ||
| 2938 | |||
| 2939 | $self->writeError( | ||
| 2940 | 'The Channels and Divert tasks cannot run at the same time, so halting the' | ||
| 2941 | . ' Channels task', | ||
| 2942 | $self->_objClass . '->doStage', | ||
| 2943 | ); | ||
| 2944 | |||
| 2945 | # Mark the task to be shutdown | ||
| 2946 | $self->ivPoke('shutdownFlag', TRUE); | ||
| 2947 | return undef; | ||
| 2948 | } | ||
| 2949 | |||
| 2950 | # If triggers have already been created for this task, remove them before replacing them | ||
| 2951 | # with new triggers | ||
| 2952 | $self->session->tidyInterfaces($self); | ||
| 2953 | |||
| 2954 | if (! $self->resetTriggers()) { | ||
| 2955 | |||
| 2956 | $self->writeError( | ||
| 2957 | 'Could not create ' . $self->prettyName . ' task triggers, so halting the task', | ||
| 2958 | $self->_objClass . '->doStage', | ||
| 2959 | ); | ||
| 2960 | |||
| 2961 | # Mark the task to be shutdown | ||
| 2962 | $self->ivPoke('shutdownFlag', TRUE); | ||
| 2963 | return undef; | ||
| 2964 | } | ||
| 2965 | |||
| 2966 | # If the task window has actually opened... | ||
| 2967 | if ($self->winObj) { | ||
| 2968 | |||
| 2969 | # Set up the initial set of tabs specified by various IVs | ||
| 2970 | $self->refreshTabs(); | ||
| 2971 | } | ||
| 2972 | |||
| 2973 | return 1; | ||
| 2974 | } | ||
| 2975 | |||
| 2976 | # sub doShutdown {} # Inherited from generic task | ||
| 2977 | |||
| 2978 | sub doReset { | ||
| 2979 | |||
| 2980 | # Called just before the task completes a reset | ||
| 2981 | # For process tasks, called by $self->main. For activity tasks, called by $self->reset | ||
| 2982 | # | ||
| 2983 | # Removes existings tabs and replaces them with the initial set of tabs specified by various | ||
| 2984 | # IVs | ||
| 2985 | # | ||
| 2986 | # Expected arguments | ||
| 2987 | # $newTaskObj - The replacement task object | ||
| 2988 | # | ||
| 2989 | # Return values | ||
| 2990 | # 'undef' on improper arguments | ||
| 2991 | # 1 otherwise | ||
| 2992 | |||
| 2993 | my ($self, $newTaskObj, $check) = @_; | ||
| 2994 | |||
| 2995 | # Check for improper arguments | ||
| 2996 | if (! defined $newTaskObj || defined $check) { | ||
| 2997 | |||
| 2998 | return $axmud::CLIENT->writeImproper($self->_objClass . '->doReset', @_); | ||
| 2999 | } | ||
| 3000 | |||
| 3001 | # Close all of the pane's existing tabs | ||
| 3002 | foreach my $tabObj ($self->ivValues('tabHash')) { | ||
| 3003 | |||
| 3004 | $tabObj->paneObj->removeTab($tabObj); | ||
| 3005 | } | ||
| 3006 | |||
| 3007 | return 1; | ||
| 3008 | } | ||
| 3009 | |||
| 3010 | # sub doFirstStage {} # Inherited from generic task | ||
| 3011 | |||
| 3012 | sub resetTriggers { | ||
| 3013 | |||
| 3014 | # Called by $self->doInit, GA::Cmd::AddChannelPattern->do and | ||
| 3015 | # GA::Cmd::DeleteChannelPattern->do | ||
| 3016 | # Removes all of this task's dependent triggers and replaces them with new ones | ||
| 3017 | # | ||
| 3018 | # Expected arguments | ||
| 3019 | # (none besides $self) | ||
| 3020 | # | ||
| 3021 | # Return values | ||
| 3022 | # 'undef' on improper arguments, or if there's an error replacing or creating the triggers | ||
| 3023 | # 1 otherwise | ||
| 3024 | |||
| 3025 | my ($self, $check) = @_; | ||
| 3026 | |||
| 3027 | # Local variables | ||
| 3028 | my @channelList; | ||
| 3029 | |||
| 3030 | # Check for improper arguments | ||
| 3031 | if (defined $check) { | ||
| 3032 | |||
| 3033 | return $axmud::CLIENT->writeImproper($self->_objClass . '->resetTriggers', @_); | ||
| 3034 | } | ||
| 3035 | |||
| 3036 | # First remove any existing triggers. ->tidyInterfaces returns the number of triggers | ||
| 3037 | # removed, or 'undef' it there's an error | ||
| 3038 | if (! defined $self->session->tidyInterfaces($self)) { | ||
| 3039 | |||
| 3040 | return undef; | ||
| 3041 | } | ||
| 3042 | |||
| 3043 | # Import the list of patterns (groups of 3) | ||
| 3044 | @channelList = $self->session->currentWorld->channelList; | ||
| 3045 | if (@channelList) { | ||
| 3046 | |||
| 3047 | do { | ||
| 3048 | |||
| 3049 | my ($pattern, $channel, $flag, $interfaceObj); | ||
| 3050 | |||
| 3051 | $pattern = shift @channelList; | ||
| 3052 | $channel = shift @channelList; | ||
| 3053 | $flag = shift @channelList; | ||
| 3054 | |||
| 3055 | # Create dependent trigger | ||
| 3056 | $interfaceObj = $self->session->createDependentInterface( | ||
| 3057 | 'trigger', | ||
| 3058 | $pattern, | ||
| 3059 | $self, | ||
| 3060 | 'channelsPatternSeen', | ||
| 3061 | 'gag', | ||
| 3062 | $flag, | ||
| 3063 | ); | ||
| 3064 | |||
| 3065 | if (! $interfaceObj) { | ||
| 3066 | |||
| 3067 | # If there's an error creating any triggers, remove any triggers already created | ||
| 3068 | $self->session->tidyInterfaces($self); | ||
| 3069 | return undef; | ||
| 3070 | |||
| 3071 | } else { | ||
| 3072 | |||
| 3073 | # Give the trigger some properties that will tell $self->channelsPatternSeen | ||
| 3074 | # which channel to use when the trigger fires | ||
| 3075 | $interfaceObj->ivAdd('propertyHash', 'channel', $channel); | ||
| 3076 | } | ||
| 3077 | |||
| 3078 | } until (! @channelList); | ||
| 3079 | } | ||
| 3080 | |||
| 3081 | return 1; | ||
| 3082 | } | ||
| 3083 | |||
| 3084 | sub displayText { | ||
| 3085 | |||
| 3086 | # Called by $self->channelsPatternSeen to display text in a tab in the task window | ||
| 3087 | # Can also be called by any other code which needs to display text in one of the task's | ||
| 3088 | # tabs. This capability has been introduced so that any code can display text in the | ||
| 3089 | # 'warning' channel's tab; artificially adding text to any other channel's tab would be | ||
| 3090 | # rude | ||
| 3091 | # | ||
| 3092 | # Expected arguments | ||
| 3093 | # $channel - The channel name, e.g. 'tell', 'social', 'custom', 'warning' | ||
| 3094 | # $text - The text to display in this channel. When called by | ||
| 3095 | # $self->channelsPatternSeen, it's the (whole) line of text received | ||
| 3096 | # from the world, stripped of control sequences, possibly after being | ||
| 3097 | # modified by rewriter triggers have acted on it (equivalent to | ||
| 3098 | # GA::Buffer::Display->modLine) | ||
| 3099 | # | ||
| 3100 | # Optional arguments | ||
| 3101 | # $triggerFlag - Set to TRUE when called by $self->channelsPatternSeen (only), so that | ||
| 3102 | # this function can reintroduce colour/style tags that were stripped | ||
| 3103 | # away from $text. Must be FALSE (or 'undef') when called by anything | ||
| 3104 | # else | ||
| 3105 | # | ||
| 3106 | # Return values | ||
| 3107 | # 'undef' on improper arguments or if a tab for the channel doesn't exist and can't be | ||
| 3108 | # created | ||
| 3109 | # 1 otherwise | ||
| 3110 | |||
| 3111 | my ($self, $channel, $text, $triggerFlag, $check) = @_; | ||
| 3112 | |||
| 3113 | # Local variables | ||
| 3114 | my ( | ||
| 3115 | $paneObj, $origText, $bufferObj, $tabObj, $checkObj, $summaryTabObj, $visibleTabObj, | ||
| 3116 | $effect, | ||
| 3117 | ); | ||
| 3118 | |||
| 3119 | # Check for improper arguments | ||
| 3120 | if (! defined $channel || ! defined $text || defined $check) { | ||
| 3121 | |||
| 3122 | return $axmud::CLIENT->writeImproper($self->_objClass . '->displayText', @_); | ||
| 3123 | } | ||
| 3124 | |||
| 3125 | # Import the task window's GA::Table::Pane object (for convenience) | ||
| 3126 | if ($self->defaultTabObj) { | ||
| 3127 | |||
| 3128 | $paneObj = $self->defaultTabObj->paneObj; | ||
| 3129 | } | ||
| 3130 | |||
| 3131 | # Preserve the original text, in case we convert the text to speech below | ||
| 3132 | $origText = $text; | ||
| 3133 | |||
| 3134 | # Display the text (if there is any) | ||
| 3135 | if ($self->taskWinFlag && $text ne '') { | ||
| 3136 | |||
| 3137 | # If called by $self->channelsPatternSeen, get the line's display buffer object | ||
| 3138 | if ($triggerFlag) { | ||
| 3139 | |||
| 3140 | $bufferObj = $self->session->ivShow( | ||
| 3141 | 'displayBufferHash', | ||
| 3142 | $self->session->displayBufferLast, | ||
| 3143 | ); | ||
| 3144 | |||
| 3145 | if (! $bufferObj) { | ||
| 3146 | |||
| 3147 | # If the buffer object is missing (extremely unlikely), behave as though some | ||
| 3148 | # other part of the code had called this function | ||
| 3149 | $triggerFlag = FALSE; | ||
| 3150 | } | ||
| 3151 | } | ||
| 3152 | |||
| 3153 | if ($self->summaryMode eq 'multi' || $self->summaryMode eq 'default') { | ||
| 3154 | |||
| 3155 | # Each tab in the task window has a unique tab number; however, tab numbers are | ||
| 3156 | # reset if all the tabs are closed | ||
| 3157 | # Get the tab corresponding to $channel, and make sure it's still visible in the | ||
| 3158 | # task window | ||
| 3159 | $tabObj = $self->ivShow('tabHash', $channel); | ||
| 3160 | if (defined $tabObj) { | ||
| 3161 | |||
| 3162 | # Check the tab is still visible in the pane. $self->closeTabCallback takes care | ||
| 3163 | # of updating $self->tabHash when a tab is manually closed, but it's better to | ||
| 3164 | # be safe than sorry | ||
| 3165 | $checkObj = $paneObj->ivShow('tabObjHash', $tabObj->number); | ||
| 3166 | if (! $checkObj || $checkObj ne $tabObj) { | ||
| 3167 | |||
| 3168 | $tabObj = undef; | ||
| 3169 | } | ||
| 3170 | } | ||
| 3171 | |||
| 3172 | # If the tab corresponding to $channel doesn't exist, create it (unless it's a | ||
| 3173 | # channel that should be ignored) | ||
| 3174 | if (! $tabObj) { | ||
| 3175 | |||
| 3176 | if (defined $self->ivFind('ignoreChannelList', $channel)) { | ||
| 3177 | |||
| 3178 | # Text on this channel should be ignored | ||
| 3179 | return undef; | ||
| 3180 | |||
| 3181 | } else { | ||
| 3182 | |||
| 3183 | $tabObj = $self->addTab( | ||
| 3184 | $self->getLabelText($channel, FALSE), | ||
| 3185 | ); | ||
| 3186 | |||
| 3187 | if (! $tabObj) { | ||
| 3188 | |||
| 3189 | # Nothing we can do to display this message | ||
| 3190 | return undef; | ||
| 3191 | |||
| 3192 | } else { | ||
| 3193 | |||
| 3194 | $self->ivAdd('tabHash', $channel, $tabObj); | ||
| 3195 | $paneObj = $tabObj->textViewObj->paneObj; | ||
| 3196 | } | ||
| 3197 | } | ||
| 3198 | } | ||
| 3199 | } | ||
| 3200 | |||
| 3201 | if ($self->summaryMode eq 'single' || $self->summaryMode eq 'multi') { | ||
| 3202 | |||
| 3203 | # Get the summary channel. If it doesn't exist (because the user has closed the | ||
| 3204 | # tab manually), don't create it | ||
| 3205 | $summaryTabObj = $self->ivShow('tabHash', $self->summaryChannel); | ||
| 3206 | if (defined $summaryTabObj) { | ||
| 3207 | |||
| 3208 | # Check the tab is still visible in the pane | ||
| 3209 | $checkObj = $paneObj->ivShow('tabObjHash', $tabObj->number); | ||
| 3210 | if (! $checkObj || $checkObj ne $tabObj) { | ||
| 3211 | |||
| 3212 | $summaryTabObj = undef; | ||
| 3213 | } | ||
| 3214 | } | ||
| 3215 | } | ||
| 3216 | |||
| 3217 | # Display the text in one or both tabs. We can use the original text colours/styles if | ||
| 3218 | # called by $self->channelsPatternSeen and if the flag allows us | ||
| 3219 | if (! $bufferObj || ! $self->useColourStyleFlag) { | ||
| 3220 | |||
| 3221 | # Display the text without applying any colour/style tags | ||
| 3222 | if ($tabObj) { | ||
| 3223 | |||
| 3224 | $tabObj->textViewObj->insertWithLinks($text); | ||
| 3225 | } | ||
| 3226 | |||
| 3227 | if ($summaryTabObj) { | ||
| 3228 | |||
| 3229 | $summaryTabObj->textViewObj->insertWithLinks($text); | ||
| 3230 | } | ||
| 3231 | |||
| 3232 | } else { | ||
| 3233 | |||
| 3234 | # Display the text, preserving original colour/style tags in the task window's | ||
| 3235 | # textview | ||
| 3236 | if ($tabObj) { | ||
| 3237 | |||
| 3238 | $bufferObj->copyLine($tabObj->textViewObj); | ||
| 3239 | } | ||
| 3240 | |||
| 3241 | if ($summaryTabObj) { | ||
| 3242 | |||
| 3243 | $bufferObj->copyLine($summaryTabObj->textViewObj); | ||
| 3244 | } | ||
| 3245 | } | ||
| 3246 | |||
| 3247 | # If the tab isn't the visible one, make its label red (but don't change the colour of | ||
| 3248 | # the summary tab's label, and don't change the colour at all if the summary tab is | ||
| 3249 | # the visible one) | ||
| 3250 | $visibleTabObj = $paneObj->getVisibleTab(); | ||
| 3251 | if ( | ||
| 3252 | $tabObj | ||
| 3253 | && $visibleTabObj | ||
| 3254 | && $tabObj ne $visibleTabObj | ||
| 3255 | && (! $summaryTabObj || $visibleTabObj ne $summaryTabObj) | ||
| 3256 | ) { | ||
| 3257 | $paneObj->setTabLabel( | ||
| 3258 | $tabObj->number, | ||
| 3259 | $self->getLabelText($channel, TRUE), | ||
| 3260 | ); | ||
| 3261 | } | ||
| 3262 | |||
| 3263 | # If the text was actually displayed in a tab... | ||
| 3264 | if ($tabObj || $summaryTabObj) { | ||
| 3265 | |||
| 3266 | # Play a sound effect, if required | ||
| 3267 | $effect = $self->ivShow('soundEffectHash', $channel); | ||
| 3268 | if (defined $effect) { | ||
| 3269 | |||
| 3270 | $axmud::CLIENT->playSound($effect); | ||
| 3271 | } | ||
| 3272 | |||
| 3273 | # Set the task window's urgency hint, if required | ||
| 3274 | if ($self->ivShow('urgencyHash', $channel)) { | ||
| 3275 | |||
| 3276 | $self->winObj->setUrgent(); | ||
| 3277 | } | ||
| 3278 | } | ||
| 3279 | } | ||
| 3280 | |||
| 3281 | # If there are any Watch tasks running - in any session - update them | ||
| 3282 | foreach my $otherSession ($axmud::CLIENT->listSessions()) { | ||
| 3283 | |||
| 3284 | my ($world, $char); | ||
| 3285 | |||
| 3286 | if ($otherSession->watchTask) { | ||
| 3287 | |||
| 3288 | $world = $self->session->currentWorld->name; | ||
| 3289 | if ($self->session->currentChar) { | ||
| 3290 | |||
| 3291 | $char = $self->session->currentChar->name; # Otherwise 'undef' | ||
| 3292 | } | ||
| 3293 | |||
| 3294 | $otherSession->watchTask->displayText('divert', $world, $char, $text); | ||
| 3295 | } | ||
| 3296 | } | ||
| 3297 | |||
| 3298 | # Also write the text to the logs, as if it had appeared in the 'main' window (if allowed) | ||
| 3299 | if ($triggerFlag && $bufferObj) { | ||
| 3300 | |||
| 3301 | $self->session->writeIncomingDataLogs($bufferObj->stripLine, $bufferObj->modLine); | ||
| 3302 | } | ||
| 3303 | |||
| 3304 | # Read out a TTS message, if required | ||
| 3305 | if ($self->ivShow('ttsFlagAttribHash', 'channels')) { | ||
| 3306 | |||
| 3307 | $self->ttsQuick($origText); | ||
| 3308 | } | ||
| 3309 | |||
| 3310 | return 1; | ||
| 3311 | } | ||
| 3312 | |||
| 3313 | sub resetWin { | ||
| 3314 | |||
| 3315 | # Called by GA::Cmd::EmptyChannelsWindow->do and $self->doReset | ||
| 3316 | # Resets the task window - removes all tabs (and the text they contain), and replaces them | ||
| 3317 | # with the initial set | ||
| 3318 | # | ||
| 3319 | # Expected arguments | ||
| 3320 | # (none besides $self) | ||
| 3321 | # | ||
| 3322 | # Return values | ||
| 3323 | # 'undef' on improper arguments | ||
| 3324 | # 1 otherwise | ||
| 3325 | |||
| 3326 | my ($self, $check) = @_; | ||
| 3327 | |||
| 3328 | # Local variables | ||
| 3329 | my $paneObj; | ||
| 3330 | |||
| 3331 | # Check for improper arguments | ||
| 3332 | if (defined $check) { | ||
| 3333 | |||
| 3334 | return $axmud::CLIENT->writeImproper($self->_objClass . '->resetWin', @_); | ||
| 3335 | } | ||
| 3336 | |||
| 3337 | if ($self->winObj) { | ||
| 3338 | |||
| 3339 | $paneObj = $self->winObj->findTableObj('pane'); | ||
| 3340 | } | ||
| 3341 | |||
| 3342 | if ($paneObj) { | ||
| 3343 | |||
| 3344 | # Close all of the pane's existing tabs | ||
| 3345 | foreach my $tabObj ($paneObj->ivValues('tabObjHash')) { | ||
| 3346 | |||
| 3347 | $paneObj->removeTab($tabObj); | ||
| 3348 | } | ||
| 3349 | |||
| 3350 | # Update IVs | ||
| 3351 | $self->ivEmpty('tabHash'); | ||
| 3352 | |||
| 3353 | # Restore the initial set of tabs specified by various IVs | ||
| 3354 | $self->refreshTabs(); | ||
| 3355 | |||
| 3356 | # If the task window's urgency hint is set, then reset it | ||
| 3357 | $self->winObj->resetUrgent(); | ||
| 3358 | } | ||
| 3359 | |||
| 3360 | return 1; | ||
| 3361 | } | ||
| 3362 | |||
| 3363 | sub refreshTabs { | ||
| 3364 | |||
| 3365 | # Called by $self->doInit and ->resetWin | ||
| 3366 | # Assuming that the task window's pane object contain no tabs, sets up an initial set of | ||
| 3367 | # tabs specified by various IVs | ||
| 3368 | # | ||
| 3369 | # Expected arguments | ||
| 3370 | # (none besides $self) | ||
| 3371 | # | ||
| 3372 | # Return values | ||
| 3373 | # 'undef' on improper arguments | ||
| 3374 | # 1 otherwise | ||
| 3375 | |||
| 3376 | my ($self, $check) = @_; | ||
| 3377 | |||
| 3378 | # Local variables | ||
| 3379 | my ($paneObj, $summaryTabObj, $firstTabObj); | ||
| 3380 | |||
| 3381 | # Check for improper arguments | ||
| 3382 | if (defined $check) { | ||
| 3383 | |||
| 3384 | return $axmud::CLIENT->writeImproper($self->_objClass . '->refreshTabs', @_); | ||
| 3385 | } | ||
| 3386 | |||
| 3387 | # Mark the task window's tabs as closeable, or not | ||
| 3388 | $paneObj = $self->winObj->findTableObj('pane'); | ||
| 3389 | if ($paneObj) { | ||
| 3390 | |||
| 3391 | $paneObj->set_canCloseFlag($self->tabCloseButtonFlag); | ||
| 3392 | } | ||
| 3393 | |||
| 3394 | # Add a 'summary' tab, if one is specified | ||
| 3395 | if ($self->summaryMode eq 'single' || $self->summaryMode eq 'multi') { | ||
| 3396 | |||
| 3397 | $summaryTabObj = $self->addTab( | ||
| 3398 | $self->getLabelText($self->summaryChannel, FALSE), | ||
| 3399 | ); | ||
| 3400 | |||
| 3401 | if ($summaryTabObj) { | ||
| 3402 | |||
| 3403 | $self->ivAdd('tabHash', $self->summaryChannel, $summaryTabObj); | ||
| 3404 | $firstTabObj = $summaryTabObj; | ||
| 3405 | } | ||
| 3406 | } | ||
| 3407 | |||
| 3408 | if ($self->summaryMode ne 'single') { | ||
| 3409 | |||
| 3410 | # Add tabs for any channels which should be opened immediately, even before text to | ||
| 3411 | # display in those channels has been received | ||
| 3412 | foreach my $channel ($self->initChannelList) { | ||
| 3413 | |||
| 3414 | my $tabObj = $self->addTab( | ||
| 3415 | $self->getLabelText($channel, FALSE), | ||
| 3416 | ); | ||
| 3417 | |||
| 3418 | if ($tabObj) { | ||
| 3419 | |||
| 3420 | $self->ivAdd('tabHash', $channel, $tabObj); | ||
| 3421 | if (! $firstTabObj) { | ||
| 3422 | |||
| 3423 | $firstTabObj = $tabObj; | ||
| 3424 | } | ||
| 3425 | } | ||
| 3426 | } | ||
| 3427 | } | ||
| 3428 | |||
| 3429 | # Make the first tab created the visible one | ||
| 3430 | if ($firstTabObj) { | ||
| 3431 | |||
| 3432 | $paneObj->setVisibleTab($firstTabObj); | ||
| 3433 | } | ||
| 3434 | |||
| 3435 | return 1; | ||
| 3436 | } | ||
| 3437 | |||
| 3438 | sub getLabelText { | ||
| 3439 | |||
| 3440 | # Called by various functions in this task | ||
| 3441 | # Change the text and/or colour of one of the task window's tab labels | ||
| 3442 | # | ||
| 3443 | # Expected arguments | ||
| 3444 | # $text - The new label text; for this task, the name of the channel | ||
| 3445 | # $colourFlag - If TRUE, the label text is a different colour (signifying that the tab's | ||
| 3446 | # textview has received new text since it was last visible). If FALSE, the | ||
| 3447 | # label text is the normal colour | ||
| 3448 | # | ||
| 3449 | # Return values | ||
| 3450 | # 'undef' on improper arguments or if the tab's text can't be updated | ||
| 3451 | # 1 otherwise | ||
| 3452 | |||
| 3453 | my ($self, $text, $colourFlag, $check) = @_; | ||
| 3454 | |||
| 3455 | # Check for improper arguments | ||
| 3456 | if (! defined $text || ! defined $colourFlag || defined $check) { | ||
| 3457 | |||
| 3458 | return $axmud::CLIENT->writeImproper($self->_objClass . '->getLabelText', @_); | ||
| 3459 | } | ||
| 3460 | |||
| 3461 | # Capitalise the channel name, if required | ||
| 3462 | if ($self->capitaliseFlag) { | ||
| 3463 | |||
| 3464 | $text = ucfirst($text); | ||
| 3465 | } | ||
| 3466 | |||
| 3467 | # If tabs are not using a close button, add extra space to make the tab label a bit wider | ||
| 3468 | if (! $self->tabCloseButtonFlag) { | ||
| 3469 | |||
| 3470 | $text = ' ' . $text . ' '; | ||
| 3471 | } | ||
| 3472 | |||
| 3473 | # Change the text colour, if required | ||
| 3474 | if ($colourFlag) { | ||
| 3475 | |||
| 3476 | $text = '<span foreground="red">' . $text . '</span>'; | ||
| 3477 | } | ||
| 3478 | |||
| 3479 | return $text; | ||
| 3480 | } | ||
| 3481 | |||
| 3482 | ################## | ||
| 3483 | # Response methods | ||
| 3484 | |||
| 3485 | sub channelsPatternSeen { | ||
| 3486 | |||
| 3487 | # Called by GA::Session->checkTriggers | ||
| 3488 | # | ||
| 3489 | # This task's ->resetTriggers function creates some triggers to capture strings matching | ||
| 3490 | # patterns in the world profile's ->patternList | ||
| 3491 | # e.g. Gandalf tells you, Give me the ring! | ||
| 3492 | # | ||
| 3493 | # The function diverts the line to the task window, displaying it in a tab matching the | ||
| 3494 | # pattern's corresponding channel. Group substrings are ignored | ||
| 3495 | # | ||
| 3496 | # The trigger interfaces have the following properties in ->propertyHash: | ||
| 3497 | # channel - Which channel to use | ||
| 3498 | # | ||
| 3499 | # Expected arguments (standard args from GA::Session->checkTriggers) | ||
| 3500 | # $session - The calling function's GA::Session | ||
| 3501 | # $interfaceNum - The number of the active trigger interface that fired | ||
| 3502 | # $line - The line of text received from the world | ||
| 3503 | # $stripLine - $line, with all escape sequences removed | ||
| 3504 | # $modLine - $stripLine, possibly modified by previously-checked triggers | ||
| 3505 | # $grpStringListRef | ||
| 3506 | # - Reference to a list of group substrings from the pattern match | ||
| 3507 | # (equivalent of @_) | ||
| 3508 | # $matchMinusListRef | ||
| 3509 | # - Reference to a list of matched substring offsets (equivalent of @-) | ||
| 3510 | # $matchPlusListRef | ||
| 3511 | # - Reference to a list of matched substring offsets (equivalent of @+) | ||
| 3512 | # | ||
| 3513 | # Return values | ||
| 3514 | # 'undef' on improper arguments, or if $session is the wrong session, if the interface | ||
| 3515 | # object can't be found, if the corresponding IV can't be found or if the received | ||
| 3516 | # line of text matches one of the exception patterns for this type of message | ||
| 3517 | # 1 otherwise | ||
| 3518 | |||
| 3519 | my ( | ||
| 3520 | $self, $session, $interfaceNum, $line, $stripLine, $modLine, $grpStringListRef, | ||
| 3521 | $matchMinusListRef, $matchPlusListRef, $check, | ||
| 3522 | ) = @_; | ||
| 3523 | |||
| 3524 | # Local variables | ||
| 3525 | my $obj; | ||
| 3526 | |||
| 3527 | # Check for improper arguments | ||
| 3528 | if ( | ||
| 3529 | ! defined $session || ! defined $interfaceNum || ! defined $line || ! defined $stripLine | ||
| 3530 | || ! defined $modLine || ! defined $grpStringListRef || ! defined $matchMinusListRef | ||
| 3531 | || ! defined $matchPlusListRef || defined $check | ||
| 3532 | ) { | ||
| 3533 | return $axmud::CLIENT->writeImproper( | ||
| 3534 | $self->_objClass . '->channelsPatternSeen', | ||
| 3535 | @_, | ||
| 3536 | ); | ||
| 3537 | } | ||
| 3538 | |||
| 3539 | # Basic check - the trigger should belong to the right session | ||
| 3540 | if ($session ne $self->session) { | ||
| 3541 | |||
| 3542 | return undef; | ||
| 3543 | } | ||
| 3544 | |||
| 3545 | # Get the interface object itself | ||
| 3546 | $obj = $session->ivShow('interfaceNumHash', $interfaceNum); | ||
| 3547 | if (! $obj) { | ||
| 3548 | |||
| 3549 | return undef; | ||
| 3550 | } | ||
| 3551 | |||
| 3552 | # Respond to the fired trigger | ||
| 3553 | |||
| 3554 | # Ignore the trigger, if this line has already been diverted | ||
| 3555 | if ($self->lastLine && $self->lastLine == $self->session->displayBufferLast) { | ||
| 3556 | |||
| 3557 | return undef; | ||
| 3558 | |||
| 3559 | } else { | ||
| 3560 | |||
| 3561 | # Don't act on any more triggers from this line | ||
| 3562 | $self->ivPoke('lastLine', $self->session->displayBufferLast); | ||
| 3563 | } | ||
| 3564 | |||
| 3565 | # Check this line of text doesn't match one of the patterns in the exception list, | ||
| 3566 | # GA::Profile::World->noChannelList | ||
| 3567 | # Any line of text which matches a pattern in that list is diverted back to the 'main' | ||
| 3568 | # window, and is not displayed in the task window | ||
| 3569 | # Check that $modLine doesn't contain one of those exception patterns | ||
| 3570 | foreach my $pattern ($self->session->currentWorld->noChannelList) { | ||
| 3571 | |||
| 3572 | if ($modLine =~ m/$pattern/i) { | ||
| 3573 | |||
| 3574 | # Divert the text back into the 'main' window, where it belongs (but only if a gag | ||
| 3575 | # trigger was used) | ||
| 3576 | if ($obj->ivShow('attribHash', 'gag')) { | ||
| 3577 | |||
| 3578 | $self->session->defaultTabObj->textViewObj->insertText( | ||
| 3579 | $modLine, | ||
| 3580 | 'after', # Assume that the line would have ended in a newline char | ||
| 3581 | ); | ||
| 3582 | |||
| 3583 | # Write to logs, if allowed | ||
| 3584 | $self->session->writeIncomingDataLogs($stripLine, $modLine); | ||
| 3585 | } | ||
| 3586 | |||
| 3587 | # (Don't bother checking the other exception patterns) | ||
| 3588 | return undef; | ||
| 3589 | } | ||
| 3590 | } | ||
| 3591 | |||
| 3592 | # Display the text in the task window | ||
| 3593 | $self->displayText( | ||
| 3594 | $obj->ivShow('propertyHash', 'channel'), | ||
| 3595 | $modLine, | ||
| 3596 | $stripLine, | ||
| 3597 | ); | ||
| 3598 | |||
| 3599 | # Write the message to a logfile (if possible) | ||
| 3600 | $axmud::CLIENT->writeLog( | ||
| 3601 | $self->session, | ||
| 3602 | FALSE, # Not a 'standard' logfile | ||
| 3603 | $modLine, | ||
| 3604 | FALSE, # Don't precede with a newline character | ||
| 3605 | TRUE, # Use final newline character | ||
| 3606 | 'channels', # Write to this logfile | ||
| 3607 | ); | ||
| 3608 | |||
| 3609 | return 1; | ||
| 3610 | } | ||
| 3611 | |||
| 3612 | sub switchTabCallback { | ||
| 3613 | |||
| 3614 | # Usually called GA::Table::Pane->respondVisibleTab whenever the visible tab in the task | ||
| 3615 | # window changes | ||
| 3616 | # Resets the colour of the tab's label text | ||
| 3617 | # | ||
| 3618 | # Expected arguments | ||
| 3619 | # $paneObj - The GA::Table::Pane object for the task window | ||
| 3620 | # $tabObj - The GA::Obj::Tab for the newly-visible tab | ||
| 3621 | # | ||
| 3622 | # Optional arguments | ||
| 3623 | # $id - A value passed by the pane object; for tasks, set to this task's ->name | ||
| 3624 | # (in general, might be 'undef') | ||
| 3625 | # | ||
| 3626 | # Return values | ||
| 3627 | # 'undef' on improper arguments | ||
| 3628 | # 1 otherwise | ||
| 3629 | |||
| 3630 | my ($self, $paneObj, $tabObj, $id, $check) = @_; | ||
| 3631 | |||
| 3632 | # Local variables | ||
| 3633 | my ( | ||
| 3634 | $channel, | ||
| 3635 | %reverseHash, | ||
| 3636 | ); | ||
| 3637 | |||
| 3638 | # Check for improper arguments | ||
| 3639 | if (! defined $paneObj || ! defined $tabObj || defined $check) { | ||
| 3640 | |||
| 3641 | return $axmud::CLIENT->writeImproper($self->_objClass . '->switchTabCallback', @_); | ||
| 3642 | } | ||
| 3643 | |||
| 3644 | %reverseHash = reverse $self->tabHash; | ||
| 3645 | $channel = $reverseHash{$tabObj}; | ||
| 3646 | |||
| 3647 | if (defined $channel) { | ||
| 3648 | |||
| 3649 | $paneObj->setTabLabel( | ||
| 3650 | $tabObj->number, | ||
| 3651 | $self->getLabelText($channel, FALSE), | ||
| 3652 | ); | ||
| 3653 | } | ||
| 3654 | |||
| 3655 | return 1; | ||
| 3656 | } | ||
| 3657 | |||
| 3658 | sub closeTabCallback { | ||
| 3659 | |||
| 3660 | # Usually called GA::Table::Pane->removeTab whenever a tab in the task window is manually | ||
| 3661 | # closed by the user | ||
| 3662 | # Updates $self->tabHash | ||
| 3663 | # | ||
| 3664 | # Expected arguments | ||
| 3665 | # $paneObj - The GA::Table::Pane object for the task window | ||
| 3666 | # $tabObj - The GA::Obj::Tab for the closed tab | ||
| 3667 | # | ||
| 3668 | # Optional arguments | ||
| 3669 | # $id - A value passed by the pane object; for tasks, set to this task's ->name | ||
| 3670 | # (in general, might be 'undef') | ||
| 3671 | # | ||
| 3672 | # Return values | ||
| 3673 | # 'undef' on improper arguments | ||
| 3674 | # 1 otherwise | ||
| 3675 | |||
| 3676 | my ($self, $paneObj, $tabObj, $id, $check) = @_; | ||
| 3677 | |||
| 3678 | # Local variables | ||
| 3679 | my $chooseTabObj; | ||
| 3680 | |||
| 3681 | # Check for improper arguments | ||
| 3682 | if (! defined $paneObj || ! defined $tabObj || defined $check) { | ||
| 3683 | |||
| 3684 | return $axmud::CLIENT->writeImproper($self->_objClass . '->closeTabCallback', @_); | ||
| 3685 | } | ||
| 3686 | |||
| 3687 | OUTER: foreach my $channel ($self->ivKeys('tabHash')) { | ||
| 3688 | |||
| 3689 | my $otherTabObj = $self->ivShow('tabhash', $channel); | ||
| 3690 | |||
| 3691 | if ($otherTabObj eq $tabObj) { | ||
| 3692 | |||
| 3693 | $self->ivDelete('tabHash', $channel); | ||
| 3694 | |||
| 3695 | last OUTER; | ||
| 3696 | } | ||
| 3697 | } | ||
| 3698 | |||
| 3699 | if ($self->defaultTabObj && $self->defaultTabObj eq $tabObj) { | ||
| 3700 | |||
| 3701 | # The first tab opened has been closed. Choose another default tab | ||
| 3702 | foreach my $tabObj ($self->ivValues('tabHash')) { | ||
| 3703 | |||
| 3704 | if (! $chooseTabObj || $tabObj->number < $chooseTabObj->number) { | ||
| 3705 | |||
| 3706 | $chooseTabObj = $tabObj; | ||
| 3707 | } | ||
| 3708 | } | ||
| 3709 | |||
| 3710 | # If there are no tabs left then, of course, $self->defaultTabObj is set to 'undef' | ||
| 3711 | $self->ivPoke('defaultTabobj', $chooseTabObj); | ||
| 3712 | } | ||
| 3713 | |||
| 3714 | return 1; | ||
| 3715 | } | ||
| 3716 | |||
| 3717 | ################## | ||
| 3718 | # Accessors - set | ||
| 3719 | |||
| 3720 | ################## | ||
| 3721 | # Accessors - task settings - get | ||
| 3722 | |||
| 3723 | # The accessors for task settings are inherited from the generic task | ||
| 3724 | |||
| 3725 | ################## | ||
| 3726 | # Accessors - task parameters - get | ||
| 3727 | |||
| 3728 | sub lastLine | ||
| 3729 | { $_[0]->{lastLine} } | ||
| 3730 | sub tabHash | ||
| 3731 | { my $self = shift; return %{$self->{tabHash}}; } | ||
| 3732 | |||
| 3733 | sub summaryMode | ||
| 3734 | { $_[0]->{summaryMode} } | ||
| 3735 | sub summaryChannel | ||
| 3736 | { $_[0]->{summaryChannel} } | ||
| 3737 | |||
| 3738 | sub initChannelList | ||
| 3739 | { my $self = shift; return @{$self->{initChannelList}}; } | ||
| 3740 | sub ignoreChannelList | ||
| 3741 | { my $self = shift; return @{$self->{ignoreChannelList}}; } | ||
| 3742 | |||
| 3743 | sub soundEffectHash | ||
| 3744 | { my $self = shift; return %{$self->{soundEffectHash}}; } | ||
| 3745 | sub urgencyHash | ||
| 3746 | { my $self = shift; return %{$self->{urgencyHash}}; } | ||
| 3747 | |||
| 3748 | sub tabCloseButtonFlag | ||
| 3749 | { $_[0]->{tabCloseButtonFlag} } | ||
| 3750 | sub capitaliseFlag | ||
| 3751 | { $_[0]->{capitaliseFlag} } | ||
| 3752 | sub useColourStyleFlag | ||
| 3753 | { $_[0]->{useColourStyleFlag} } | ||
| 3754 | } | ||
| 3755 | |||
| 3756 | { package Games::Axmud::Task::Chat; | ||
| 3757 | |||
| 3758 | # Chat task, based on the Kildclient plugin by Eduardo M Kalinowski | ||
| 3759 | |||
| 3760 | use strict; | ||
| 3761 | use warnings; | ||
| 3762 | # use diagnostics; | ||
| 3763 | |||
| 3764 | use Glib qw(TRUE FALSE); | ||
| 3765 | |||
| 3766 | our @ISA = qw(Games::Axmud::Generic::Task Games::Axmud); | ||
| 3767 | |||
| 3768 | ################## | ||
| 3769 | # Constructors | ||
| 3770 | |||
| 3771 | sub new { | ||
| 3772 | |||
| 3773 | # Creates a new instance of the Chat task | ||
| 3774 | # | ||
| 3775 | # Expected arguments | ||
| 3776 | # $session - The parent GA::Session (not stored as an IV) | ||
| 3777 | # | ||
| 3778 | # Optional arguments | ||
| 3779 | # $taskType - Which tasklist this task is being created into - 'current' for the current | ||
| 3780 | # tasklist (tasks which are actually running now), 'initial' (tasks which | ||
| 3781 | # should be run when the user connects to the world), 'custom' (tasks with | ||
| 3782 | # customised initial parameters, which are run when the user demands). If | ||
| 3783 | # set to 'undef', this is a temporary task, created in order to access the | ||
| 3784 | # default values stored in IVs, that will not be added to any tasklist | ||
| 3785 | # $profName - ($taskType = 'current', when called by $self->clone) Name of the | ||
| 3786 | # profile from whose initial tasklist this task was created ('undef' if | ||
| 3787 | # none) | ||
| 3788 | # - ($taskType = 'initial') name of the profile in whose initial tasklist this | ||
| 3789 | # task will be. If 'undef', the global initial tasklist is used | ||
| 3790 | # - ($taskType = 'custom') 'undef' | ||
| 3791 | # $profCategory | ||
| 3792 | # - ($taskType = 'current', 'initial') which category the profile falls undef | ||
| 3793 | # (i.e. 'world', 'race', 'char', etc, or 'undef' if no profile) | ||
| 3794 | # - ($taskType = 'custom') 'undef' | ||
| 3795 | # $customName | ||
| 3796 | # - ($taskType = 'current', 'initial') 'undef' | ||
| 3797 | # - ($taskType = 'custom') the custom task name, matching a key in | ||
| 3798 | # GA::Session->customTaskHash | ||
| 3799 | # | ||
| 3800 | # Return values | ||
| 3801 | # 'undef' on improper arguments or if the task can't be added to the specified tasklist | ||
| 3802 | # Blessed reference to the newly-created object on success | ||
| 3803 | |||
| 3804 | my ($class, $session, $taskType, $profName, $profCategory, $customName, $check) = @_; | ||
| 3805 | |||
| 3806 | # Check for improper arguments | ||
| 3807 | if (! defined $class || ! defined $session || defined $check) { | ||
| 3808 | |||
| 3809 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 3810 | } | ||
| 3811 | |||
| 3812 | if ($taskType) { | ||
| 3813 | |||
| 3814 | # For initial tasks, check that $profName exists | ||
| 3815 | if ( | ||
| 3816 | $taskType eq 'initial' | ||
| 3817 | && defined $profName | ||
| 3818 | && ! $session->ivExists('profHash', $profName) | ||
| 3819 | ) { | ||
| 3820 | return $session->writeError( | ||
| 3821 | 'Can\'t create new task because \'' . $profName . '\' profile doesn\'t exist', | ||
| 3822 | $class . '->new', | ||
| 3823 | ); | ||
| 3824 | |||
| 3825 | # For custom tasks, check that $customName doesn't already exist | ||
| 3826 | } elsif ( | ||
| 3827 | $taskType eq 'custom' | ||
| 3828 | && $axmud::CLIENT->ivExists('customTaskHash', $customName) | ||
| 3829 | ) { | ||
| 3830 | return $session->writeError( | ||
| 3831 | 'Can\'t create new custom task because \'' . $customName . '\' is already being' | ||
| 3832 | . ' used', | ||
| 3833 | $class . '->new', | ||
| 3834 | ); | ||
| 3835 | |||
| 3836 | } elsif ($taskType ne 'current' && $taskType ne 'initial' && $taskType ne 'custom') { | ||
| 3837 | |||
| 3838 | return $session->writeError( | ||
| 3839 | 'Can\'t create new task because \'' . $taskType . '\' is an invalid tasklist', | ||
| 3840 | $class . '->new', | ||
| 3841 | ); | ||
| 3842 | } | ||
| 3843 | } | ||
| 3844 | |||
| 3845 | # Task settings | ||
| 3846 | my $self = Games::Axmud::Generic::Task->new( | ||
| 3847 | $session, | ||
| 3848 | $taskType, | ||
| 3849 | $profName, | ||
| 3850 | $profCategory, | ||
| 3851 | $customName, | ||
| 3852 | ); | ||
| 3853 | |||
| 3854 | $self->{_objName} = 'chat_task'; | ||
| 3855 | $self->{_objClass} = $class; | ||
| 3856 | $self->{_parentFile} = undef; # Set below | ||
| 3857 | $self->{_parentWorld} = undef; # Set below | ||
| 3858 | # All IVs are private (but as a convenience, Chat tasks are allowed to set the IVs of other | ||
| 3859 | # Chat tasks) | ||
| 3860 | $self->{_privFlag} = TRUE, | ||
| 3861 | |||
| 3862 | $self->{name} = 'chat_task'; | ||
| 3863 | $self->{prettyName} = 'Chat'; | ||
| 3864 | $self->{shortName} = 'Ch'; | ||
| 3865 | $self->{shortCutIV} = undef; # Set by $self->doInit, if required | ||
| 3866 | |||
| 3867 | $self->{category} = 'activity'; | ||
| 3868 | $self->{descrip} = 'Instant messenger task using zChat/MudMaster protocols'; | ||
| 3869 | $self->{jealousyFlag} = FALSE; | ||
| 3870 | $self->{requireLocatorFlag} = FALSE; | ||
| 3871 | $self->{profSensitivityFlag} = TRUE; | ||
| 3872 | $self->{storableFlag} = FALSE; # Start with ';listen' | ||
| 3873 | $self->{delayTime} = 0; | ||
| 3874 | $self->{allowWinFlag} = TRUE; | ||
| 3875 | $self->{requireWinFlag} = FALSE; | ||
| 3876 | $self->{startWithWinFlag} = FALSE; | ||
| 3877 | $self->{winPreferList} = ['entry', 'grid']; | ||
| 3878 | $self->{winmap} = 'entry_fill'; | ||
| 3879 | $self->{winUpdateFunc} = undef; | ||
| 3880 | $self->{tabMode} = 'simple'; | ||
| 3881 | $self->{monochromeFlag} = FALSE; | ||
| 3882 | $self->{noScrollFlag} = FALSE; | ||
| 3883 | $self->{ttsFlag} = TRUE; | ||
| 3884 | $self->{ttsConfig} = 'chat'; | ||
| 3885 | $self->{ttsAttribHash} = {}; | ||
| 3886 | $self->{ttsFlagAttribHash} = { | ||
| 3887 | 'chat' => FALSE, | ||
| 3888 | 'chatout' => FALSE, | ||
| 3889 | 'chatin' => FALSE, | ||
| 3890 | 'chatecho' => FALSE, | ||
| 3891 | 'chatsystem' => FALSE, | ||
| 3892 | 'chatremote' => FALSE, | ||
| 3893 | 'chatsnoop' => FALSE, | ||
| 3894 | }; | ||
| 3895 | $self->{ttsAlertAttribHash} = {}; | ||
| 3896 | $self->{status} = 'wait_init'; | ||
| 3897 | # $self->{activeFlag} = TRUE; # Task can't be activated/disactivated | ||
| 3898 | |||
| 3899 | # Task parameters | ||
| 3900 | |||
| 3901 | # Is this Chat task the lead Chat task (the one that listens out for incoming connections)? | ||
| 3902 | # (TRUE yes, FALSE no) | ||
| 3903 | $self->{leadTaskFlag} = FALSE; | ||
| 3904 | # Is this Chat task actually connected to someone? (TRUE yes, FALSE no) | ||
| 3905 | $self->{sessionFlag} = FALSE; | ||
| 3906 | # Flag set to TRUE when the connection is closed (set to FALSE up until that moment) | ||
| 3907 | $self->{connectionClosedFlag} = FALSE; | ||
| 3908 | # If this chat session is with someone in your contacts list (i.e. a GA::Obj::ChatContact | ||
| 3909 | # object), the blessed reference of the object (set to 'undef' for chat sessions with | ||
| 3910 | # someone else) | ||
| 3911 | $self->{chatContactObj} = undef; | ||
| 3912 | |||
| 3913 | # The user's IP address, set when the task starts. If GA::Client->ipv4Get can't find it, | ||
| 3914 | # it uses a backup value of '127.0.0.1' (which is what we would get from | ||
| 3915 | # IO::Socket::INET->sockhost, if a socket were open) | ||
| 3916 | $self->{ip} = undef; | ||
| 3917 | # The port currently used for accepting incoming connections ('undef' when not accepting | ||
| 3918 | # any) | ||
| 3919 | $self->{port} = undef; | ||
| 3920 | # The IO::Socket used for incoming connections ('undef' when not accepting any) | ||
| 3921 | $self->{acceptSocket} = undef; | ||
| 3922 | # The Glib::IO watch used for incoming connections ('undef' when not accepting any) | ||
| 3923 | $self->{acceptID} = undef; | ||
| 3924 | # A timeout to kill an incoming connection which isn't established quickly enough (in | ||
| 3925 | # seconds) | ||
| 3926 | $self->{incomingTimeout} = 60; | ||
| 3927 | # A timeout to kill an outgoing connection which isn't established quickly enough (in | ||
| 3928 | # seconds) | ||
| 3929 | $self->{outgoingTimeout} = 10; | ||
| 3930 | |||
| 3931 | # The socket used for communications | ||
| 3932 | $self->{clientSocket} = undef; | ||
| 3933 | # Chat protocol: 0 for MudMaster, 1 for zChat (matches a key in $self->constOptHash) | ||
| 3934 | $self->{chatType} = undef; | ||
| 3935 | # ID for the IO Watch callback | ||
| 3936 | $self->{ioWatchID} = undef; | ||
| 3937 | # ID for the timeout callback (to close connections that are not established after 60 secs) | ||
| 3938 | $self->{timeoutID} = undef; | ||
| 3939 | # Operation code that has been read, but that has not been processed | ||
| 3940 | $self->{pendingOpCode} = undef; | ||
| 3941 | # Last invalid opcode received (stored so that we don't send endless error messages to the | ||
| 3942 | # chat contact) | ||
| 3943 | $self->{lastInvalidOpCode} = undef; | ||
| 3944 | # Size of data for the pending operation | ||
| 3945 | $self->{pendingDataSize} = undef; | ||
| 3946 | # Buffer to hold incoming data for the connection | ||
| 3947 | $self->{dataBuffer} = undef; | ||
| 3948 | # The character set to use by default | ||
| 3949 | $self->{defaultEncoding} = 'iso-8859-1'; | ||
| 3950 | # The character set actually used | ||
| 3951 | $self->{encoding} = undef; | ||
| 3952 | |||
| 3953 | # Two hooks used for snooping, which start disabled - one for the 'receive_text' event, | ||
| 3954 | # another for the 'send_cmd' event. Stored by the lead Chat task only | ||
| 3955 | $self->{receiveHook} = undef; | ||
| 3956 | $self->{sendHook} = undef; | ||
| 3957 | # The lead Chat task uses a timer interface to check for idle users periodically. The | ||
| 3958 | # interface object created | ||
| 3959 | $self->{idleTimer} = undef; | ||
| 3960 | # How long the timer should wait (in seconds) before checking whether the user is idle | ||
| 3961 | $self->{idleCheckTime} = 5; | ||
| 3962 | # How long the user should be idle, before the lead Chat task sends out a 'STATUS' message | ||
| 3963 | # to all connections | ||
| 3964 | $self->{idleSeconds} = 300; # 5 minutes | ||
| 3965 | |||
| 3966 | # Flag set by ';chataccept' when there is no Chat task running. $self->acceptCalls can't be | ||
| 3967 | # called right away; instead, we instruct ->init to call it by setting the flag to TRUE | ||
| 3968 | # (and setting the port, if one was specified) | ||
| 3969 | $self->{acceptCallsOnInitFlag} = FALSE; | ||
| 3970 | $self->{acceptCallsOnInitPort} = undef; | ||
| 3971 | # Flag set by ';chatcall' or ';chatcall'. $self->genericCall can't be called right away, | ||
| 3972 | # instead, we instruct ->init to call it by setting the flag to TRUE (and setting the | ||
| 3973 | # following Ivs - $port is optional) | ||
| 3974 | $self->{makeCallOnInitFlag} = FALSE; | ||
| 3975 | $self->{makeCallOnInitType} = undef; # 'MM' or 'ZCHAT' | ||
| 3976 | $self->{makeCallOnInitIP} = undef; | ||
| 3977 | $self->{makeCallOnInitPort} = undef; | ||
| 3978 | # Flags set when the lead Chat task, which already has its own connection, receives another | ||
| 3979 | # incoming chat request. The lead Chat task creates this task, and sets the following IVs | ||
| 3980 | # so that ->init can respond to the request | ||
| 3981 | $self->{receiveCallOnInitFlag} = FALSE; | ||
| 3982 | $self->{receiveCallOnInitSocket} | ||
| 3983 | = undef; | ||
| 3984 | |||
| 3985 | # The name used in chat sessions. Set to the current character's name (albeit capitalised), | ||
| 3986 | # unless changed by the user | ||
| 3987 | $self->{localName} = undef; | ||
| 3988 | # The Windows .bmp file being used as the chat icon ('undef' if no icon used) | ||
| 3989 | $self->{localIconFile} = undef; | ||
| 3990 | # Your email address, if it has been broadcast to the chat contact - otherwise set to | ||
| 3991 | # 'undef' | ||
| 3992 | $self->{localEmail} = undef; | ||
| 3993 | # The name of the chat group, if there is one | ||
| 3994 | $self->{localGroup} = undef; | ||
| 3995 | # Our status, used in zChat sessions only. | ||
| 3996 | # (from http://www.zuggsoft.com/zchat/zchatprot.htm) | ||
| 3997 | # 0 - no status | ||
| 3998 | # 1 - Normal status | ||
| 3999 | # 2 - InActive status | ||
| 4000 | # 3 - AFK status | ||
| 4001 | # The Chat task uses values of '0' for MudMaster connections, and 1/3 (only) for zChat | ||
| 4002 | # connections | ||
| 4003 | $self->{localStatus} = 0; | ||
| 4004 | # zChat's stamp is a random 32-bit number | ||
| 4005 | $self->{localZChatStamp} = int(rand(2**32 - 1)); | ||
| 4006 | |||
| 4007 | # When the chat contact sends their own icon, we store it in this IV as a Gtk3::Gdk::Pixbuf, | ||
| 4008 | # so that it can be saved in the contacts list, where necessary | ||
| 4009 | $self->{remoteIcon} = undef; | ||
| 4010 | # The same icon scaled to 16x16 (required by GA::Obj::ChatContact) | ||
| 4011 | $self->{remoteIconScaled} = undef; | ||
| 4012 | # Nickname of the connected peer | ||
| 4013 | $self->{remoteName} = undef; | ||
| 4014 | # Connected peer's advertised IP | ||
| 4015 | $self->{remoteIP} = undef; | ||
| 4016 | # Connected peer's advertised port (used for incoming connections) | ||
| 4017 | $self->{remotePort} = undef; | ||
| 4018 | # Connected peer's email (only displayed, not used by the task) | ||
| 4019 | $self->{remoteEmail} = undef; | ||
| 4020 | # Connected peer's zChat stamp (if any) | ||
| 4021 | $self->{remoteStamp} = undef; | ||
| 4022 | # Version of the connected peer's client | ||
| 4023 | $self->{remoteVersion} = undef; | ||
| 4024 | # Status of the connected peer's client | ||
| 4025 | $self->{remoteStatus} = 0; | ||
| 4026 | # The zChat ID (i.e. zMUD registration number) of the connected peer | ||
| 4027 | $self->{remoteZChatID} = undef; | ||
| 4028 | |||
| 4029 | # Can the connected peer snoop on us? (TRUE yes, FALSE no) | ||
| 4030 | $self->{allowSnoopFlag} = FALSE; | ||
| 4031 | # Is the connected peer snooping on us now? (TRUE yes, FALSE no) | ||
| 4032 | $self->{isSnoopedFlag} = FALSE; | ||
| 4033 | # The number of snoopers (stored by the lead Chat task only) | ||
| 4034 | $self->{snooperCount} = 0; | ||
| 4035 | # Chat contacts can request to see a list of chat connections. This flag is set to TRUE if | ||
| 4036 | # this connection is 'public', meaning that it's included in the list; or set to FALSE if | ||
| 4037 | # this connection is 'private', meaning that it's not included in the list | ||
| 4038 | $self->{publicConnectionFlag} = FALSE; | ||
| 4039 | # Flag set to TRUE in zChat sessions after a ';submit' chat command, allowing the chat | ||
| 4040 | # contact to send world commands remotely. Set to FALSE by default or in a MudMaster | ||
| 4041 | # session | ||
| 4042 | $self->{allowRemoteCmdFlag} = FALSE; | ||
| 4043 | # What happens when the user enters text into the task window's entry box: | ||
| 4044 | # 'chat' - it's a chat message | ||
| 4045 | # 'emote' - it's an emote | ||
| 4046 | # 'cmd' - it's a remote command | ||
| 4047 | $self->{entryMode} = 'chat'; | ||
| 4048 | # Flag set to TRUE in zChat sessions when this chat session is 'serving' - i.e. | ||
| 4049 | # CHAT_TEXT_EVERYBODY messages received in one chat session are echoed to every other chat | ||
| 4050 | # session, and CHAT_TEXT_GROUP messages received in one chat session are echoed to every | ||
| 4051 | # other chat session in the named group | ||
| 4052 | # Otherwise, set to FALSE (and set to FALSE in MudMaster sessions) | ||
| 4053 | $self->{servingFlag} = FALSE; | ||
| 4054 | |||
| 4055 | # Time that the last ping was sent | ||
| 4056 | $self->{pingTime} = undef; | ||
| 4057 | # A random value sent in each ping to detect the correct reply when several pings are sent | ||
| 4058 | $self->{pingStamp} = undef; | ||
| 4059 | # Is the file being sent or received? (according to $self->constOptHash, set to 2 for | ||
| 4060 | # sending, 1 for receiving) | ||
| 4061 | $self->{fileDir} = undef; | ||
| 4062 | # Name of the file being transferred | ||
| 4063 | $self->{fileName} = undef; | ||
| 4064 | # Filehandle of the file being transferred | ||
| 4065 | $self->{fileHandle} = undef; | ||
| 4066 | # Total size of the file being transferred | ||
| 4067 | $self->{fileTotalSize} = undef; | ||
| 4068 | # How many bytes already transferred | ||
| 4069 | $self->{fileSize} = undef; | ||
| 4070 | |||
| 4071 | # The colours in which to display various things. If set to 'undef', use the normal colour | ||
| 4072 | # (white on black), otherwise use the specified colour (which must be a standard Axmud | ||
| 4073 | # colour tag) | ||
| 4074 | # Sent chats/emotes | ||
| 4075 | $self->{chatOutColour} = 'white'; | ||
| 4076 | # Received chats/emotes | ||
| 4077 | $self->{chatInColour} = 'green'; | ||
| 4078 | # Echoed CHAT_TEXT_EVERYBODY and CHAT_TEXT_GROUP messages | ||
| 4079 | $self->{chatEchoColour} = 'magenta'; | ||
| 4080 | # Local system messages | ||
| 4081 | $self->{systemColour} = 'cyan'; | ||
| 4082 | # Remote system messages | ||
| 4083 | $self->{remoteColour} = 'RED'; | ||
| 4084 | # Snooping colour | ||
| 4085 | $self->{snoopColour} = 'yellow'; | ||
| 4086 | # Flag set to TRUE (briefly) by ->showInfo, instructing ->writeText to display all messages | ||
| 4087 | # in the colour for local system messages | ||
| 4088 | $self->{allSystemColourFlag} = FALSE; | ||
| 4089 | # Flag set to TRUE if smileys be displayed in the task window, FALSE otherwise | ||
| 4090 | $self->{allowSmileyFlag} = TRUE; | ||
| 4091 | # The size of smileys, relative to the font size used in the window. A factor of 2 seems to | ||
| 4092 | # look the best; the icon's size is $fontSize * $self->smileySizeFactor | ||
| 4093 | $self->{smileySizeFactor} = 2; | ||
| 4094 | |||
| 4095 | # IVs that will be used when PGP encryption is implemented (for the zChat protocol) | ||
| 4096 | # Our own public and secret keys | ||
| 4097 | $self->{localPublicKey} = undef; | ||
| 4098 | $self->{localSecretKey} = undef; | ||
| 4099 | # The chat contact's public key | ||
| 4100 | $self->{remotePublicKey} = undef; | ||
| 4101 | |||
| 4102 | # Constants used in the original chat.pl plugin | ||
| 4103 | $self->{constOptHash} = { | ||
| 4104 | # Chat types | ||
| 4105 | 'MM' => 0, | ||
| 4106 | 'ZCHAT' => 1, | ||
| 4107 | # Chat commands for both protocols | ||
| 4108 | 'NAME_CHANGE' => 1, | ||
| 4109 | 'REQUEST_CONNECTIONS' => 2, | ||
| 4110 | 'CONNECTION_LIST' => 3, | ||
| 4111 | 'TEXT_EVERYBODY' => 4, | ||
| 4112 | 'TEXT_PERSONAL' => 5, | ||
| 4113 | 'TEXT_GROUP' => 6, | ||
| 4114 | 'MESSAGE' => 7, | ||
| 4115 | 'VERSION' => 19, | ||
| 4116 | 'FILE_START' => 20, | ||
| 4117 | 'FILE_DENY' => 21, | ||
| 4118 | 'FILE_BLOCK_REQUEST' => 22, | ||
| 4119 | 'FILE_BLOCK' => 23, | ||
| 4120 | 'FILE_END' => 24, | ||
| 4121 | 'FILE_CANCEL' => 25, | ||
| 4122 | 'PING_REQUEST' => 26, | ||
| 4123 | 'PING_RESPONSE' => 27, | ||
| 4124 | 'PEEK_CONNECTIONS' => 28, | ||
| 4125 | 'PEEK_LIST' => 29, | ||
| 4126 | 'SNOOP' => 30, | ||
| 4127 | 'SNOOP_DATA' => 31, | ||
| 4128 | # Chat commands specific to the MM chat protocol | ||
| 4129 | 'DO_NOT_DISTURB' => 8, | ||
| 4130 | 'END_OF_COMMAND' => 255, | ||
| 4131 | # Chat commands specific to the zChat protocol | ||
| 4132 | 'ICON' => 100, | ||
| 4133 | 'STATUS' => 101, | ||
| 4134 | 'EMAIL' => 102, | ||
| 4135 | 'REQUEST_PGP_KEY' => 103, # Not implemented | ||
| 4136 | 'PGP_KEY' => 104, # Not implemented | ||
| 4137 | 'SEND_COMMAND' => 105, | ||
| 4138 | 'STAMP' => 106, | ||
| 4139 | # Chat commands For file transfer | ||
| 4140 | 'MM_FILE_BLOCK_SIZE' => 500, | ||
| 4141 | 'ZCHAT_FILE_BLOCK_SIZE' => 1024, | ||
| 4142 | # File directions | ||
| 4143 | 'RECEIVING' => 1, | ||
| 4144 | 'SENDING' => 2, | ||
| 4145 | # Chat destinations | ||
| 4146 | 'PERSONAL' => 0, | ||
| 4147 | 'EVERYBODY' => 1, | ||
| 4148 | 'GROUP' => 2, | ||
| 4149 | }; | ||
| 4150 | # Opcodes which can't be sent until the connection has been negotiated (prevents us from | ||
| 4151 | # sending strange messages like 'You chat to , 'Hello!'' | ||
| 4152 | # NB $self->receiveFile will refuse any incoming 'FILE_START' opcodes when the connection | ||
| 4153 | # hasn't been negotiated yet | ||
| 4154 | $self->{restrictedHash} = { | ||
| 4155 | 4 => 'TEXT_EVERYBODY', | ||
| 4156 | 5 => 'TEXT_PERSONAL', | ||
| 4157 | 6 => 'TEXT_GROUP', | ||
| 4158 | 20 => 'FILE_START', | ||
| 4159 | 30 => 'SNOOP', | ||
| 4160 | # Chat commands specific to the zChat protocol | ||
| 4161 | 105 => 'SEND_COMMAND', | ||
| 4162 | }; | ||
| 4163 | # Commands to control the chat sessions can be entered into the task window's entry box | ||
| 4164 | # (when preceded by the client command sigil, ';') | ||
| 4165 | # A hash of commands that can be entered, in the form | ||
| 4166 | # $hash{chat_command} = method_to_call | ||
| 4167 | $self->{cmdHash} = { | ||
| 4168 | 'name' => 'setName', | ||
| 4169 | 'group' => 'setGroup', | ||
| 4170 | 'chat' => 'chat', # Added for completeness | ||
| 4171 | 'emote' => 'emote', | ||
| 4172 | 'chatgroup' => 'chatToGroup', | ||
| 4173 | 'cg' => 'chatToGroup', # Abbreviation for chat.pl compatibility | ||
| 4174 | 'emotegroup' => 'emoteToGroup', | ||
| 4175 | 'eg' => 'emoteToGroup', # Abbreviation for chat.pl compatibility | ||
| 4176 | 'chatall' => 'chatToAll', | ||
| 4177 | 'ca' => 'chatToAll', | ||
| 4178 | 'emoteall' => 'emoteToAll', | ||
| 4179 | 'ea' => 'emoteToAll', | ||
| 4180 | 'ping' => 'pingPeer', | ||
| 4181 | 'dnd' => 'sendDoNotDisturb', | ||
| 4182 | 'submit' => 'submitToCmds', | ||
| 4183 | 'escape' => 'escapeFromCmds', | ||
| 4184 | 'cmd' => 'sendRemoteCmd', | ||
| 4185 | 'sendfile' => 'sendFile', | ||
| 4186 | 'stopfile' => 'stopFile', | ||
| 4187 | 'snoop' => 'requestSnoop', | ||
| 4188 | 'allowsnoop' => 'acceptSnoop', | ||
| 4189 | 'allow' => 'acceptSnoop', | ||
| 4190 | 'forbidsnoop' => 'refuseSnoop', | ||
| 4191 | 'forbid' => 'refuseSnoop', | ||
| 4192 | 'noallowsnoop' | ||
| 4193 | => 'refuseSnoop', # Alias for chat.pl compatibility | ||
| 4194 | 'hangup' => 'hangUp', # Alias for chat.pl compatibility | ||
| 4195 | 'halt' => 'hangUp', | ||
| 4196 | 'close' => 'hangUp', | ||
| 4197 | 'public' => 'setPublic', | ||
| 4198 | 'private' => 'setPrivate', | ||
| 4199 | 'peek' => 'peekRemoteConnections', | ||
| 4200 | 'request' => 'requestRemoteConnections', | ||
| 4201 | 'serve' => 'setServing', | ||
| 4202 | 'noserve' => 'setNotServing', | ||
| 4203 | 'info' => 'showInfo', | ||
| 4204 | 'icon' => 'setIcon', | ||
| 4205 | 'email' => 'setEmail', | ||
| 4206 | 'smiley' => 'setSmiley', | ||
| 4207 | 'save' => 'saveContact', | ||
| 4208 | 'help' => 'winHelp', | ||
| 4209 | 'mode' => 'setMode', | ||
| 4210 | }; | ||
| 4211 | |||
| 4212 | # List of strings displayed in response to the task's internal 'help' command | ||
| 4213 | $self->{helpList} = [ | ||
| 4214 | 'List of commands for the Chat task window:', | ||
| 4215 | ' ;name <nick> - Sets chat nickname to <nick>', | ||
| 4216 | ' ;name - Sets default chat nickname', | ||
| 4217 | ' ;group <name> - Joins a group called <name>', | ||
| 4218 | ' ;group - Leaves the current group', | ||
| 4219 | ' ;chat <text> - Sends some text', | ||
| 4220 | ' ;emote <text> - Sends some text as an emote', | ||
| 4221 | ' ;chatgroup <text> - Sends text to the group', | ||
| 4222 | ' ;emotegroup <text> - Sends an emote to the group', | ||
| 4223 | ' ;chatall <text> - Sends text to everyone', | ||
| 4224 | ' ;emoteall <text> - Sends an emote to everyone', | ||
| 4225 | ' ;ping - Pings the chat contact', | ||
| 4226 | ' ;dnd - Sends \'Do not disturb\' (MM)', | ||
| 4227 | ' ;submit - Allow remote world commands (zC)', | ||
| 4228 | ' ;escape - Forbid remote world commands (zC)', | ||
| 4229 | ' ;cmd <text> - Send a remote world command (zC)', | ||
| 4230 | ' ;sendfile <file> - Sends a file', | ||
| 4231 | ' ;sendfile - Chooses a file to send', | ||
| 4232 | ' ;stopfile - Stops a file transfer', | ||
| 4233 | ' ;allowsnoop - Allow the chat contact to snoop you', | ||
| 4234 | ' ;forbidsnoop - Forbids chat contact from snooping', | ||
| 4235 | ' ;snoop - Asks to start/stop snooping', | ||
| 4236 | ' ;hangup - Terminate this session', | ||
| 4237 | ' ;public - Marks the connection as public', | ||
| 4238 | ' ;private - Marks the connection as private', | ||
| 4239 | ' ;peek - View connections of other contacts', | ||
| 4240 | ' ;request - Requests a conference call', | ||
| 4241 | ' ;serve - Relay text to other chat contacts', | ||
| 4242 | ' ;noserve - Stop relaying text', | ||
| 4243 | ' ;info - Display info about the session', | ||
| 4244 | ' ;icon <file> - Sets your icon (must be .bmp, zC)', | ||
| 4245 | ' ;icon - Chooses your icon (zC)', | ||
| 4246 | ' ;email <email> - Sets the email to broadcast', | ||
| 4247 | ' ;email - Stops broadcasting your email', | ||
| 4248 | ' ;smiley on - Turns on smileys', | ||
| 4249 | ' ;smiley off - Turns off smileys', | ||
| 4250 | ' ;save <contact> - Saves chat contact in contacts list', | ||
| 4251 | ' ;save - Update existing contact', | ||
| 4252 | ' ;help - Show this list of commands', | ||
| 4253 | 'Typed text not beginning with ; is treated like this:', | ||
| 4254 | ' ;mode chat - Treat the text as chat', | ||
| 4255 | ' <text> - Sends some text', | ||
| 4256 | ' ;mode emote - Treat the text as an emote', | ||
| 4257 | ' <emote> - Sends some text as an emote', | ||
| 4258 | ' ;mode cmd - Send the text as a remote command', | ||
| 4259 | ' <cmd> - Send a remote command (zC)', | ||
| 4260 | 'Available in all modes:', | ||
| 4261 | ' \'<text> - Sends some text', # Escape char, so extra space | ||
| 4262 | ' :<emote> - Sends some text as an emote', | ||
| 4263 | ' #<cmd> - Send a remote command (zC)', | ||
| 4264 | ]; | ||
| 4265 | |||
| 4266 | # Bless task | ||
| 4267 | bless $self, $class; | ||
| 4268 | |||
| 4269 | # For all tasks that aren't temporary... | ||
| 4270 | if ($taskType) { | ||
| 4271 | |||
| 4272 | # Check that the task doesn't belong to a disabled plugin (in which case, it can't be | ||
| 4273 | # added to any current, initial or custom tasklist) | ||
| 4274 | if (! $self->checkPlugins()) { | ||
| 4275 | |||
| 4276 | return undef; | ||
| 4277 | } | ||
| 4278 | |||
| 4279 | # Set the parent file object | ||
| 4280 | $self->setParentFileObj($session, $taskType, $profName, $profCategory); | ||
| 4281 | |||
| 4282 | # Create entries in tasklists, if possible | ||
| 4283 | if (! $self->updateTaskLists($session)) { | ||
| 4284 | |||
| 4285 | return undef; | ||
| 4286 | } | ||
| 4287 | } | ||
| 4288 | |||
| 4289 | # Task creation complete | ||
| 4290 | return $self; | ||
| 4291 | } | ||
| 4292 | |||
| 4293 | sub clone { | ||
| 4294 | |||
| 4295 | # Create a clone of an existing task | ||
| 4296 | # Usually used upon connection to a world, when every task in the initial tasklists must | ||
| 4297 | # be cloned into a new object, representing a task in the current tasklist | ||
| 4298 | # (Also used when cloning a profile object, since all the tasks in its initial tasklist must | ||
| 4299 | # also be cloned) | ||
| 4300 | # | ||
| 4301 | # Expected arguments | ||
| 4302 | # $session - The parent GA::Session (not stored as an IV) | ||
| 4303 | # $taskType - Which tasklist this task is being created into - 'current' for the current | ||
| 4304 | # tasklist (tasks which are actually running now), 'initial' (tasks which | ||
| 4305 | # should be run when the user connects to the world). Custom tasks aren't | ||
| 4306 | # cloned (at the moment) | ||
| 4307 | # | ||
| 4308 | # Optional arguments | ||
| 4309 | # $profName - ($taskType = 'initial') name of the profile in whose initial tasklist the | ||
| 4310 | # existing task is stored | ||
| 4311 | # $profCategory | ||
| 4312 | # - ($taskType = 'initial') which category the profile falls under (i.e. | ||
| 4313 | # 'world', 'race', 'char', etc) | ||
| 4314 | # | ||
| 4315 | # Return values | ||
| 4316 | # 'undef' on improper arguments or if the task can't be cloned | ||
| 4317 | # Blessed reference to the newly-created object on success | ||
| 4318 | |||
| 4319 | my ($self, $session, $taskType, $profName, $profCategory, $check) = @_; | ||
| 4320 | |||
| 4321 | # Check for improper arguments | ||
| 4322 | if ( | ||
| 4323 | ! defined $session || ! defined $taskType || defined $check | ||
| 4324 | || ($taskType ne 'current' && $taskType ne 'initial') | ||
| 4325 | || ($taskType eq 'initial' && (! defined $profName || ! defined $profCategory)) | ||
| 4326 | ) { | ||
| 4327 | return $axmud::CLIENT->writeImproper($self->_objClass . '->clone', @_); | ||
| 4328 | } | ||
| 4329 | |||
| 4330 | # For initial tasks, check that $profName exists | ||
| 4331 | if ( | ||
| 4332 | $taskType eq 'initial' | ||
| 4333 | && defined $profName | ||
| 4334 | && ! $session->ivExists('profHash', $profName) | ||
| 4335 | ) { | ||
| 4336 | return $axmud::CLIENT->writeError( | ||
| 4337 | 'Can\'t create cloned task because \'' . $profName . '\' profile doesn\'t exist', | ||
| 4338 | $self->_objClass . '->clone', | ||
| 4339 | ); | ||
| 4340 | } | ||
| 4341 | |||
| 4342 | # Check that the task doesn't belong to a disabled plugin (in which case, it can't be | ||
| 4343 | # cloned) | ||
| 4344 | if (! $self->checkPlugins()) { | ||
| 4345 | |||
| 4346 | return undef; | ||
| 4347 | } | ||
| 4348 | |||
| 4349 | # Create the new task, using default settings and parameters | ||
| 4350 | my $clone = $self->_objClass->new($session, $taskType, $profName, $profCategory); | ||
| 4351 | |||
| 4352 | # Most of the cloned task's settings have default values, but a few are copied from the | ||
| 4353 | # original | ||
| 4354 | $self->cloneTaskSettings($clone); | ||
| 4355 | |||
| 4356 | # Give the new (cloned) task the same initial parameters as the original one | ||
| 4357 | $clone->{leadTaskFlag} = $self->leadTaskFlag; | ||
| 4358 | $clone->{sessionFlag} = $self->sessionFlag; | ||
| 4359 | $clone->{connectionClosedFlag} = $self->connectionClosedFlag; | ||
| 4360 | $clone->{chatContactObj} = $self->chatContactObj; | ||
| 4361 | |||
| 4362 | $clone->{port} = $self->port; | ||
| 4363 | $clone->{acceptSocket} = $self->acceptSocket; | ||
| 4364 | $clone->{acceptID} = $self->acceptID; | ||
| 4365 | $clone->{incomingTimeout} = $self->incomingTimeout; | ||
| 4366 | $clone->{outgoingTimeout} = $self->outgoingTimeout; | ||
| 4367 | |||
| 4368 | $clone->{clientSocket} = $self->clientSocket; | ||
| 4369 | $clone->{chatType} = $self->chatType; | ||
| 4370 | $clone->{ioWatchID} = $self->ioWatchID; | ||
| 4371 | $clone->{timeoutID} = $self->timeoutID; | ||
| 4372 | $clone->{pendingOpCode} = $self->pendingOpCode; | ||
| 4373 | $clone->{lastInvalidOpCode} = $self->lastInvalidOpCode; | ||
| 4374 | $clone->{pendingDataSize} = $self->pendingDataSize; | ||
| 4375 | $clone->{dataBuffer} = $self->dataBuffer; | ||
| 4376 | $clone->{defaultEncoding} = $self->defaultEncoding; | ||
| 4377 | $clone->{encoding} = $self->encoding; | ||
| 4378 | |||
| 4379 | $clone->{receiveHook} = $self->receiveHook; | ||
| 4380 | $clone->{sendHook} = $self->sendHook; | ||
| 4381 | $clone->{idleTimer} = $self->idleTimer; | ||
| 4382 | $clone->{idleCheckTime} = $self->idleCheckTime; | ||
| 4383 | $clone->{idleSeconds} = $self->idleSeconds; | ||
| 4384 | |||
| 4385 | $clone->{acceptCallsOnInitFlag} = $self->acceptCallsOnInitFlag; | ||
| 4386 | $clone->{acceptCallsOnInitPort} = $self->acceptCallsOnInitPort; | ||
| 4387 | $clone->{makeCallOnInitFlag} = $self->makeCallOnInitFlag; | ||
| 4388 | $clone->{makeCallOnInitType} = $self->makeCallOnInitType; | ||
| 4389 | $clone->{makeCallOnInitIP} = $self->makeCallOnInitIP; | ||
| 4390 | $clone->{makeCallOnInitPort} = $self->makeCallOnInitPort; | ||
| 4391 | $clone->{receiveCallOnInitFlag} = $self->receiveCallOnInitFlag; | ||
| 4392 | $clone->{receiveCallOnInitSocket} | ||
| 4393 | = $self->receiveCallOnInitSocket; | ||
| 4394 | |||
| 4395 | $clone->{localName} = $self->localName; | ||
| 4396 | $clone->{localIconFile} = $self->localIconFile; | ||
| 4397 | $clone->{localEmail} = $self->localEmail; | ||
| 4398 | $clone->{localGroup} = $self->localGroup; | ||
| 4399 | $clone->{localStatus} = $self->localStatus; | ||
| 4400 | $clone->{localZChatStamp} = $self->localZChatStamp; | ||
| 4401 | |||
| 4402 | $clone->{remoteIcon} = $self->remoteIcon; | ||
| 4403 | $clone->{remoteIconScaled} = $self->remoteIconScaled; | ||
| 4404 | $clone->{remoteName} = $self->remoteName; | ||
| 4405 | $clone->{remoteIP} = $self->remoteIP; | ||
| 4406 | $clone->{remotePort} = $self->remotePort; | ||
| 4407 | $clone->{remoteEmail} = $self->remoteEmail; | ||
| 4408 | $clone->{remoteStamp} = $self->remoteStamp; | ||
| 4409 | $clone->{remoteVersion} = $self->remoteVersion; | ||
| 4410 | $clone->{remoteStatus} = $self->remoteStatus; | ||
| 4411 | $clone->{remoteZChatID} = $self->remoteZChatID; | ||
| 4412 | |||
| 4413 | $clone->{allowSnoopFlag} = $self->allowSnoopFlag; | ||
| 4414 | $clone->{isSnoopedFlag} = $self->isSnoopedFlag; | ||
| 4415 | $clone->{snooperCount} = $self->snooperCount; | ||
| 4416 | $clone->{publicConnectionFlag} = $self->publicConnectionFlag; | ||
| 4417 | $clone->{allowRemoteCmdFlag} | ||
| 4418 | = $self->allowRemoteCmdFlag; | ||
| 4419 | $clone->{entryMode} = $self->entryMode; | ||
| 4420 | $clone->{servingFlag} = $self->servingFlag; | ||
| 4421 | |||
| 4422 | $clone->{pingTime} = $self->pingTime; | ||
| 4423 | $clone->{pingStamp} = $self->pingStamp; | ||
| 4424 | $clone->{fileDir} = $self->fileDir; | ||
| 4425 | $clone->{fileName} = $self->fileName; | ||
| 4426 | $clone->{fileHandle} = $self->fileHandle; | ||
| 4427 | $clone->{fileTotalSize} = $self->fileTotalSize; | ||
| 4428 | $clone->{fileSize} = $self->fileSize; | ||
| 4429 | |||
| 4430 | $clone->{chatOutColour} = $self->chatOutColour; | ||
| 4431 | $clone->{chatInColour} = $self->chatInColour; | ||
| 4432 | $clone->{chatEchoColour} = $self->chatEchoColour; | ||
| 4433 | $clone->{systemColour} = $self->systemColour; | ||
| 4434 | $clone->{remoteColour} = $self->remoteColour; | ||
| 4435 | $clone->{snoopColour} = $self->snoopColour; | ||
| 4436 | $clone->{allSystemColourFlag} = $self->allSystemColourFlag; | ||
| 4437 | $clone->{allowSmileyFlag} = $self->allowSmileyFlag; | ||
| 4438 | $clone->{smileySizeFactor} = $self->smileySizeFactor; | ||
| 4439 | |||
| 4440 | $clone->{localPublicKey} = $self->localPublicKey; | ||
| 4441 | $clone->{localSecretKey} = $self->localSecretKey; | ||
| 4442 | $clone->{remotePublicKey} = $self->remotePublicKey; | ||
| 4443 | |||
| 4444 | $clone->{constOptHash} = {$self->constOptHash}; | ||
| 4445 | $clone->{restrictedHash} = {$self->restrictedHash}; | ||
| 4446 | $clone->{cmdHash} = {$self->cmdHash}; | ||
| 4447 | |||
| 4448 | $clone->{helpList} = [$self->helpList]; | ||
| 4449 | |||
| 4450 | # Cloning complete | ||
| 4451 | return $clone; | ||
| 4452 | } | ||
| 4453 | |||
| 4454 | sub preserve { | ||
| 4455 | |||
| 4456 | # Called by $self->main whenever this task is reset, in order to preserve some if its task | ||
| 4457 | # parameters (but not necessarily all of them) | ||
| 4458 | # | ||
| 4459 | # Expected arguments | ||
| 4460 | # $newTask - The new task which has been created, to which some of this task's instance | ||
| 4461 | # variables might have to be transferred | ||
| 4462 | # | ||
| 4463 | # Return values | ||
| 4464 | # 'undef' on improper arguments, or if $newTask isn't in the GA::Session's current | ||
| 4465 | # tasklist | ||
| 4466 | # 1 on success | ||
| 4467 | |||
| 4468 | my ($self, $newTask, $check) = @_; | ||
| 4469 | |||
| 4470 | # Check for improper arguments | ||
| 4471 | if (! defined $newTask || defined $check) { | ||
| 4472 | |||
| 4473 | return $axmud::CLIENT->writeImproper($self->_objClass . '->preserve', @_); | ||
| 4474 | } | ||
| 4475 | |||
| 4476 | # Check the task is in the current tasklist | ||
| 4477 | if (! $self->session->ivExists('currentTaskHash', $newTask->uniqueName)) { | ||
| 4478 | |||
| 4479 | return $self->writeWarning( | ||
| 4480 | '\'' . $self->uniqueName . '\' task missing from the current tasklist', | ||
| 4481 | $self->_objClass . '->preserve', | ||
| 4482 | ); | ||
| 4483 | } | ||
| 4484 | |||
| 4485 | # Preserve some task parameters (the others are left with their default settings, some of | ||
| 4486 | # which will be re-initialised in stage 2) | ||
| 4487 | |||
| 4488 | # Preserve the flag that says whether this is the lead chat task, or not | ||
| 4489 | $newTask->ivPoke('leadTaskFlag', $self->leadTaskFlag); | ||
| 4490 | # Preserve the GA::Obj::ChatContact, if there is one | ||
| 4491 | $newTask->ivPoke('chatContactObj', $self->chatContactObj); | ||
| 4492 | # Preserve colours | ||
| 4493 | $newTask->ivPoke('chatOutColour', $self->chatOutColour); | ||
| 4494 | $newTask->ivPoke('chatInColour', $self->chatInColour); | ||
| 4495 | $newTask->ivPoke('chatEchoColour', $self->chatEchoColour); | ||
| 4496 | $newTask->ivPoke('systemColour', $self->systemColour); | ||
| 4497 | $newTask->ivPoke('remoteColour', $self->remoteColour); | ||
| 4498 | $newTask->ivPoke('snoopColour', $self->snoopColour); | ||
| 4499 | # Preserve the smiley settings | ||
| 4500 | $newTask->ivPoke('allowSmileyFlag', $self->allowSmileyFlag); | ||
| 4501 | $newTask->ivPoke('smileySizeFactor', $self->smileySizeFactor); | ||
| 4502 | |||
| 4503 | return 1; | ||
| 4504 | } | ||
| 4505 | |||
| 4506 | # sub setParentFileObj {} # Inherited from generic task | ||
| 4507 | |||
| 4508 | # sub updateTaskLists {} # Inherited from generic task | ||
| 4509 | |||
| 4510 | # sub ttsReadAttrib {} # Inherited from generic task | ||
| 4511 | |||
| 4512 | sub ttsSwitchFlagAttrib { | ||
| 4513 | |||
| 4514 | # Called by GA::Cmd::Switch->do and PermSwitch->do | ||
| 4515 | # Users can use the client command ';switch' to interact with individual tasks, typically | ||
| 4516 | # telling them to turn on/off the automatic reading out of information (e.g. the Locator | ||
| 4517 | # task can be told to start or stop reading out room titles as they are received from | ||
| 4518 | # the world) | ||
| 4519 | # The ';switch' command is in the form ';switch <flag_attribute>'. The ';switch' command | ||
| 4520 | # looks up the <flag_attribute> (which is a string, not a TRUE/FALSE value) in | ||
| 4521 | # GA::Client->ttsFlagAttribHash, which tells it which task to call | ||
| 4522 | # | ||
| 4523 | # Expected arguments | ||
| 4524 | # $flagAttrib - The TTS flag attribute specified by the calling function. Must be one of | ||
| 4525 | # the keys in $self->ttsFlagAttribHash | ||
| 4526 | # | ||
| 4527 | # Optional arguments | ||
| 4528 | # $noSpecialFlag | ||
| 4529 | # - Set to TRUE when called by GA::Cmd::PermSwitch->do, in which case only | ||
| 4530 | # this task's hash of flag attributes is updated. Otherwise set to FALSE | ||
| 4531 | # (or 'undef'), in which case other things can happen when a flag | ||
| 4532 | # attribute is switched. For all built-in tasks, there is no difference | ||
| 4533 | # in behaviour | ||
| 4534 | # | ||
| 4535 | # Return values | ||
| 4536 | # 'undef' on improper arguments or if the $flagAttrib doesn't exist in this task's | ||
| 4537 | # ->ttsFlagAttribHash | ||
| 4538 | # Otherwise returns a confirmation message for the calling function to display | ||
| 4539 | |||
| 4540 | my ($self, $flagAttrib, $noSpecialFlag, $check) = @_; | ||
| 4541 | |||
| 4542 | # Local variables | ||
| 4543 | my $msg; | ||
| 4544 | |||
| 4545 | # Check for improper arguments | ||
| 4546 | if (! defined $flagAttrib || defined $check) { | ||
| 4547 | |||
| 4548 | return $axmud::CLIENT->writeImproper($self->_objClass . '->ttsSwitchFlagAttrib', @_); | ||
| 4549 | } | ||
| 4550 | |||
| 4551 | # TTS flag attributes are case-insensitive | ||
| 4552 | $flagAttrib = lc($flagAttrib); | ||
| 4553 | |||
| 4554 | # Check that the specified flag attribute is actually used by this task (';switch' or | ||
| 4555 | # ';permswitch' should carry out this check, but better safe than sorry) | ||
| 4556 | if (! $self->ivExists('ttsFlagAttribHash', $flagAttrib)) { | ||
| 4557 | |||
| 4558 | return undef; | ||
| 4559 | |||
| 4560 | } else { | ||
| 4561 | |||
| 4562 | # If a current task performs some kind of action, when a flag attribute is switched, | ||
| 4563 | # the code for the action should be placed here. (Tasks in the global initial | ||
| 4564 | # tasklist can't perform an action, of course.) | ||
| 4565 | if (! $noSpecialFlag) { | ||
| 4566 | |||
| 4567 | # (no actions to perform) | ||
| 4568 | } | ||
| 4569 | |||
| 4570 | $msg = '\'' . $self->prettyName . '\' flag attribute \'' . $flagAttrib | ||
| 4571 | . '\' switched to '; | ||
| 4572 | |||
| 4573 | # One change from the generic ->ttsSwitchFlagAttrib function: if the 'chat' attribute | ||
| 4574 | # is switched on/off, switch the other six attributes on/off, too | ||
| 4575 | if ($flagAttrib eq 'chat') { | ||
| 4576 | |||
| 4577 | if ($self->ivShow('ttsFlagAttribHash', 'chat')) { | ||
| 4578 | |||
| 4579 | $self->ivAdd('ttsFlagAttribHash', 'chat', FALSE); | ||
| 4580 | $self->ivAdd('ttsFlagAttribHash', 'chatout', FALSE); | ||
| 4581 | $self->ivAdd('ttsFlagAttribHash', 'chatin', FALSE); | ||
| 4582 | $self->ivAdd('ttsFlagAttribHash', 'chatecho', FALSE); | ||
| 4583 | $self->ivAdd('ttsFlagAttribHash', 'chatsystem', FALSE); | ||
| 4584 | $self->ivAdd('ttsFlagAttribHash', 'chatremote', FALSE); | ||
| 4585 | $self->ivAdd('ttsFlagAttribHash', 'chatsnoop', FALSE); | ||
| 4586 | $msg .= 'OFF'; | ||
| 4587 | |||
| 4588 | } else { | ||
| 4589 | |||
| 4590 | $self->ivAdd('ttsFlagAttribHash', 'chat', TRUE); | ||
| 4591 | $self->ivAdd('ttsFlagAttribHash', 'chatout', TRUE); | ||
| 4592 | $self->ivAdd('ttsFlagAttribHash', 'chatin', TRUE); | ||
| 4593 | $self->ivAdd('ttsFlagAttribHash', 'chatecho', TRUE); | ||
| 4594 | $self->ivAdd('ttsFlagAttribHash', 'chatsystem', TRUE); | ||
| 4595 | $self->ivAdd('ttsFlagAttribHash', 'chatremote', TRUE); | ||
| 4596 | $self->ivAdd('ttsFlagAttribHash', 'chatsnoop', TRUE); | ||
| 4597 | $msg .= 'ON'; | ||
| 4598 | } | ||
| 4599 | |||
| 4600 | } else { | ||
| 4601 | |||
| 4602 | if ($self->ivShow('ttsFlagAttribHash', $flagAttrib)) { | ||
| 4603 | |||
| 4604 | $self->ivAdd('ttsFlagAttribHash', $flagAttrib, FALSE); | ||
| 4605 | $msg .= 'OFF'; | ||
| 4606 | |||
| 4607 | } else { | ||
| 4608 | |||
| 4609 | $self->ivAdd('ttsFlagAttribHash', $flagAttrib, TRUE); | ||
| 4610 | $msg .= 'ON'; | ||
| 4611 | } | ||
| 4612 | } | ||
| 4613 | |||
| 4614 | return $msg; | ||
| 4615 | } | ||
| 4616 | } | ||
| 4617 | |||
| 4618 | # sub ttsSetAlertAttrib {} # Inherited from generic task | ||
| 4619 | |||
| 4620 | ################## | ||
| 4621 | # Task windows | ||
| 4622 | |||
| 4623 | # sub toggleWin {} # Inherited from generic task | ||
| 4624 | |||
| 4625 | # sub openWin {} # Inherited from generic task | ||
| 4626 | |||
| 4627 | # sub closeWin {} # Inherited from generic task | ||
| 4628 | |||
| 4629 | ################## | ||
| 4630 | # Methods | ||
| 4631 | |||
| 4632 | # sub init {} # Inherited from generic task | ||
| 4633 | |||
| 4634 | sub doInit { | ||
| 4635 | |||
| 4636 | # Called by $self->init, just before the task completes its setup ($self->init) | ||
| 4637 | # | ||
| 4638 | # Expected arguments | ||
| 4639 | # (none besides $self) | ||
| 4640 | # | ||
| 4641 | # Return values | ||
| 4642 | # 'undef' on improper arguments or if there is an error | ||
| 4643 | # 1 otherwise | ||
| 4644 | |||
| 4645 | my ($self, $check) = @_; | ||
| 4646 | |||
| 4647 | # Local variables | ||
| 4648 | my ($localIP, $result); | ||
| 4649 | |||
| 4650 | # Check for improper arguments | ||
| 4651 | if (defined $check) { | ||
| 4652 | |||
| 4653 | return $axmud::CLIENT->writeImproper($self->_objClass . '->doInit', @_); | ||
| 4654 | } | ||
| 4655 | |||
| 4656 | # If there is no 'lead' Chat task, then this task must be the lead task | ||
| 4657 | if (! $self->session->chatTask) { | ||
| 4658 | |||
| 4659 | # This task should be stored in the current session's ->chatTask IV | ||
| 4660 | $self->ivPoke('shortCutIV', 'chatTask'); | ||
| 4661 | $self->session->add_standardTask($self); | ||
| 4662 | |||
| 4663 | $self->ivPoke('leadTaskFlag', TRUE); | ||
| 4664 | |||
| 4665 | } else { | ||
| 4666 | |||
| 4667 | # Make sure this isn't the lead Chat task | ||
| 4668 | $self->ivPoke('leadTaskFlag', FALSE); | ||
| 4669 | } | ||
| 4670 | |||
| 4671 | # Fetch the user's IP address | ||
| 4672 | $localIP = $axmud::CLIENT->ipv4Get(); | ||
| 4673 | if (! defined $localIP) { | ||
| 4674 | |||
| 4675 | # Emergency failsafe; use what we would get from IO::Socket::INET->sockhost, if it were | ||
| 4676 | # open | ||
| 4677 | $self->ivPoke('ip', '127.0.0.1'); | ||
| 4678 | |||
| 4679 | } else { | ||
| 4680 | |||
| 4681 | $self->ivPoke('ip', $localIP); | ||
| 4682 | } | ||
| 4683 | |||
| 4684 | # Check that there is a current character. If not, change this task's ->status back to | ||
| 4685 | # 'wait_init'. $self->init will be called repeatedly when the task loop spins until there | ||
| 4686 | # is a current character | ||
| 4687 | if (! $self->session->currentChar) { | ||
| 4688 | |||
| 4689 | $self->ivPoke('status', 'wait_init'); | ||
| 4690 | return 1; | ||
| 4691 | } | ||
| 4692 | |||
| 4693 | # If there was no Chat task running when the user typed the ';chataccept' command, a flag | ||
| 4694 | # has been set which instructs us to call $self->acceptCalls right away | ||
| 4695 | if ($self->acceptCallsOnInitFlag) { | ||
| 4696 | |||
| 4697 | if ($self->acceptCallsOnInitPort) { | ||
| 4698 | $result = $self->acceptCalls($self->acceptCallsOnInitPort); | ||
| 4699 | } else { | ||
| 4700 | $result = $self->acceptCalls(); | ||
| 4701 | } | ||
| 4702 | |||
| 4703 | if (! $result) { | ||
| 4704 | |||
| 4705 | $self->ivPoke('shutdownFlag', TRUE); | ||
| 4706 | |||
| 4707 | return $self->writeError( | ||
| 4708 | '\'' . $self->uniqueName . '\' task is halting because it couldn\'t open a port' | ||
| 4709 | . ' to listen for incoming connections', | ||
| 4710 | $self->_objClass . '->doInit' | ||
| 4711 | ); | ||
| 4712 | } | ||
| 4713 | |||
| 4714 | # If this Chat task was created by the lead Chat task which received an incoming call, but | ||
| 4715 | # which was already dealing with a connection, call ->acceptConnection to deal with it | ||
| 4716 | } elsif ($self->receiveCallOnInitFlag) { | ||
| 4717 | |||
| 4718 | $result = $self->receiveConnection($self->receiveCallOnInitSocket); | ||
| 4719 | if (! $result) { | ||
| 4720 | |||
| 4721 | $self->ivPoke('shutdownFlag', TRUE); | ||
| 4722 | |||
| 4723 | return $self->writeError( | ||
| 4724 | '\'' . $self->uniqueName . '\' task is halting because it couldn\'t process an' | ||
| 4725 | . ' incoming connection', | ||
| 4726 | $self->_objClass . '->doInit' | ||
| 4727 | ); | ||
| 4728 | } | ||
| 4729 | |||
| 4730 | # If this Chat task was created by a ';chatcall' or a ';chatzcall' command, a flag has been | ||
| 4731 | # set which instructs us to call someone right away | ||
| 4732 | } elsif ($self->makeCallOnInitFlag) { | ||
| 4733 | |||
| 4734 | if ($self->makeCallOnInitType eq 'MM') { | ||
| 4735 | $result = $self->mcall($self->makeCallOnInitIP, $self->makeCallOnInitPort); | ||
| 4736 | } elsif ($self->makeCallOnInitType eq 'ZCHAT') { | ||
| 4737 | $result = $self->zcall($self->makeCallOnInitIP, $self->makeCallOnInitPort); | ||
| 4738 | } | ||
| 4739 | |||
| 4740 | if (! $result) { | ||
| 4741 | |||
| 4742 | $self->ivPoke('shutdownFlag', TRUE); | ||
| 4743 | |||
| 4744 | # In rare circumstances, $self->makeCallOnInitIP won't be set | ||
| 4745 | if ($self->makeCallOnInitIP) { | ||
| 4746 | |||
| 4747 | return $self->writeError( | ||
| 4748 | '\'' . $self->uniqueName . '\' task is halting because it couldn\'t call ' | ||
| 4749 | . $self->makeCallOnInitIP . ' ' . $self->makeCallOnInitPort, | ||
| 4750 | $self->_objClass . '->doInit' | ||
| 4751 | ); | ||
| 4752 | |||
| 4753 | } else { | ||
| 4754 | |||
| 4755 | # An error message has already been displayed | ||
| 4756 | return undef; | ||
| 4757 | } | ||
| 4758 | } | ||
| 4759 | } | ||
| 4760 | |||
| 4761 | if ($self->leadTaskFlag) { | ||
| 4762 | |||
| 4763 | # If interfaces have already been created for this task (unlikely), remove them before | ||
| 4764 | # replacing them with new ones | ||
| 4765 | $self->session->tidyInterfaces($self); | ||
| 4766 | |||
| 4767 | # Create new interfaces | ||
| 4768 | if (! $self->resetHooks || ! $self->resetTimers) { | ||
| 4769 | |||
| 4770 | $self->writeError( | ||
| 4771 | 'Could not create ' . $self->prettyName . ' task interfaces, so halting the' | ||
| 4772 | . ' task', | ||
| 4773 | $self->_objClass . '->doInit', | ||
| 4774 | ); | ||
| 4775 | } | ||
| 4776 | } | ||
| 4777 | |||
| 4778 | return 1; | ||
| 4779 | } | ||
| 4780 | |||
| 4781 | sub doShutdown { | ||
| 4782 | |||
| 4783 | # Called just before the task completes a shutdown | ||
| 4784 | # For process tasks, called by $self->main. For activity tasks, called by $self->shutdown | ||
| 4785 | # | ||
| 4786 | # Expected arguments | ||
| 4787 | # (none besides $self) | ||
| 4788 | # | ||
| 4789 | # Return values | ||
| 4790 | # 'undef' on improper arguments | ||
| 4791 | # 1 otherwise | ||
| 4792 | |||
| 4793 | my ($self, $check) = @_; | ||
| 4794 | |||
| 4795 | # Check for improper arguments | ||
| 4796 | if (defined $check) { | ||
| 4797 | |||
| 4798 | return $axmud::CLIENT->writeImproper($self->_objClass . '->doShutdown', @_); | ||
| 4799 | } | ||
| 4800 | |||
| 4801 | # Halt the current chat session, if it is open | ||
| 4802 | if ($self->sessionFlag) { | ||
| 4803 | |||
| 4804 | $self->terminateChatSession(); | ||
| 4805 | } | ||
| 4806 | |||
| 4807 | # If this is the 'lead' Chat task, then we need to assign another Chat task as the 'lead' | ||
| 4808 | # Chat task | ||
| 4809 | if ($self->leadTaskFlag) { | ||
| 4810 | |||
| 4811 | # Choose a new task | ||
| 4812 | $self->assignLeadTask(); | ||
| 4813 | } | ||
| 4814 | |||
| 4815 | # If the socket for listening to incoming connections is open, close it | ||
| 4816 | if ($self->acceptID) { | ||
| 4817 | |||
| 4818 | $self->refuseCalls(); | ||
| 4819 | } | ||
| 4820 | |||
| 4821 | # If this is the lead Chat task (even after the call to ->assignLeadTask, because this task | ||
| 4822 | # is the only Chat task running), then reset the GA::Session IV | ||
| 4823 | if ($self->session->chatTask && $self->session->chatTask eq $self) { | ||
| 4824 | |||
| 4825 | $self->ivUndef('shortCutIV'); | ||
| 4826 | $self->session->del_standardTask($self); | ||
| 4827 | } | ||
| 4828 | |||
| 4829 | return 1; | ||
| 4830 | } | ||
| 4831 | |||
| 4832 | sub doReset { | ||
| 4833 | |||
| 4834 | # Called just before the task completes a reset | ||
| 4835 | # For process tasks, called by $self->main. For activity tasks, called by $self->reset | ||
| 4836 | # | ||
| 4837 | # Expected arguments | ||
| 4838 | # $newTaskObj - The replacement task object | ||
| 4839 | # | ||
| 4840 | # Return values | ||
| 4841 | # 'undef' on improper arguments | ||
| 4842 | # 1 otherwise | ||
| 4843 | |||
| 4844 | my ($self, $newTaskObj, $check) = @_; | ||
| 4845 | |||
| 4846 | # Local variables | ||
| 4847 | my $acceptID; | ||
| 4848 | |||
| 4849 | # Check for improper arguments | ||
| 4850 | if (! defined $newTaskObj || defined $check) { | ||
| 4851 | |||
| 4852 | return $axmud::CLIENT->writeImproper($self->_objClass . '->doReset', @_); | ||
| 4853 | } | ||
| 4854 | |||
| 4855 | # If this is the lead Chat task, then reset the GA::Session IV | ||
| 4856 | if ($self->leadTaskFlag) { | ||
| 4857 | |||
| 4858 | # Transfer the Accept ID to the new task, while retaining the old socket | ||
| 4859 | if ($self->acceptID) { | ||
| 4860 | |||
| 4861 | Glib::Source->remove($self->acceptID); | ||
| 4862 | |||
| 4863 | $acceptID = Glib::IO->add_watch( | ||
| 4864 | $self->acceptSocket->fileno, | ||
| 4865 | 'in', | ||
| 4866 | sub { $newTaskObj->acceptConnection(@_); }, | ||
| 4867 | $self->acceptSocket, | ||
| 4868 | ); | ||
| 4869 | |||
| 4870 | $newTaskObj->ivPoke('port', $self->port); | ||
| 4871 | $newTaskObj->ivPoke('acceptSocket', $self->acceptSocket); | ||
| 4872 | $newTaskObj->ivPoke('acceptID', $acceptID); | ||
| 4873 | } | ||
| 4874 | |||
| 4875 | # Mark the other task as the new lead Chat task | ||
| 4876 | $newTaskObj->ivPoke('leadTaskFlag', TRUE); | ||
| 4877 | $self->ivPoke('leadTaskFlag', FALSE); | ||
| 4878 | |||
| 4879 | # Inform the GA::Session of the change of lead Chat task | ||
| 4880 | $self->ivUndef('shortCutIV'); | ||
| 4881 | $newTaskObj->ivPoke('shortCutIV', 'chatTask'); | ||
| 4882 | $self->session->add_standardTask($newTaskObj); | ||
| 4883 | } | ||
| 4884 | |||
| 4885 | return 1; | ||
| 4886 | } | ||
| 4887 | |||
| 4888 | sub resetHooks { | ||
| 4889 | |||
| 4890 | # Called by $self->doInit to create dependent hook interfaces for the lead Chat task | ||
| 4891 | # | ||
| 4892 | # Expected arguments | ||
| 4893 | # (none besides $self) | ||
| 4894 | # | ||
| 4895 | # Return values | ||
| 4896 | # 'undef' on improper arguments or if any of the interfaces can't be created | ||
| 4897 | # 1 otherwise | ||
| 4898 | |||
| 4899 | my ($self, $check) = @_; | ||
| 4900 | |||
| 4901 | # Local variables | ||
| 4902 | my ($receiveObj, $sendObj); | ||
| 4903 | |||
| 4904 | # Check for improper arguments | ||
| 4905 | if (defined $check) { | ||
| 4906 | |||
| 4907 | return $axmud::CLIENT->writeImproper($self->_objClass . '->resetHooks', @_); | ||
| 4908 | } | ||
| 4909 | |||
| 4910 | # Create two hooks, initially disabled, to allow snooping | ||
| 4911 | $receiveObj = $self->session->createDependentInterface( | ||
| 4912 | 'hook', | ||
| 4913 | 'receive_text', # Stimulus | ||
| 4914 | $self, | ||
| 4915 | 'hookCallback', | ||
| 4916 | 'enabled', | ||
| 4917 | 0, | ||
| 4918 | ); | ||
| 4919 | |||
| 4920 | if (! $receiveObj) { | ||
| 4921 | |||
| 4922 | return undef; | ||
| 4923 | } | ||
| 4924 | |||
| 4925 | $sendObj = $self->session->createDependentInterface( | ||
| 4926 | 'hook', | ||
| 4927 | 'send_cmd', # Stimulus | ||
| 4928 | $self, | ||
| 4929 | 'hookCallback', | ||
| 4930 | 'enabled', | ||
| 4931 | 0, | ||
| 4932 | ); | ||
| 4933 | |||
| 4934 | if (! $sendObj) { | ||
| 4935 | |||
| 4936 | return undef; | ||
| 4937 | } | ||
| 4938 | |||
| 4939 | # Update IVs | ||
| 4940 | $self->ivPoke('receiveHook', $receiveObj); | ||
| 4941 | $self->ivPoke('sendHook', $sendObj); | ||
| 4942 | |||
| 4943 | return 1; | ||
| 4944 | } | ||
| 4945 | |||
| 4946 | sub resetTimers { | ||
| 4947 | |||
| 4948 | # Called by $self->doInit to a create dependent timer interfaces for the lead Chat task | ||
| 4949 | # | ||
| 4950 | # Expected arguments | ||
| 4951 | # (none besides $self) | ||
| 4952 | # | ||
| 4953 | # Return values | ||
| 4954 | # 'undef' on improper arguments or if any of the interfaces can't be created | ||
| 4955 | # 1 otherwise | ||
| 4956 | |||
| 4957 | my ($self, $check) = @_; | ||
| 4958 | |||
| 4959 | # Local variables | ||
| 4960 | my $timerObj; | ||
| 4961 | |||
| 4962 | # Check for improper arguments | ||
| 4963 | if (defined $check) { | ||
| 4964 | |||
| 4965 | return $axmud::CLIENT->writeImproper($self->_objClass . '->resetTimers', @_); | ||
| 4966 | } | ||
| 4967 | |||
| 4968 | # Create a timer, initially enabled, to watch out for idle users | ||
| 4969 | $timerObj = $self->session->createDependentInterface( | ||
| 4970 | 'timer', | ||
| 4971 | $self->idleCheckTime, # Stimulus | ||
| 4972 | $self, | ||
| 4973 | 'timerCallback', | ||
| 4974 | ); | ||
| 4975 | |||
| 4976 | if (! $timerObj) { | ||
| 4977 | |||
| 4978 | return undef; | ||
| 4979 | } | ||
| 4980 | |||
| 4981 | # Update IVs | ||
| 4982 | $self->ivPoke('idleTimer', $timerObj); | ||
| 4983 | |||
| 4984 | return 1; | ||
| 4985 | } | ||
| 4986 | |||
| 4987 | sub assignLeadTask { | ||
| 4988 | |||
| 4989 | # Called by $self->doShutdown or $self->terminateChatSession when this, the lead Chat task, | ||
| 4990 | # is shutting down in order to select a new lead Chat task (if there are any others) | ||
| 4991 | # | ||
| 4992 | # Expected arguments | ||
| 4993 | # (none besides $self) | ||
| 4994 | # | ||
| 4995 | # Return values | ||
| 4996 | # 'undef' on improper arguments | ||
| 4997 | # 1 otherwise | ||
| 4998 | |||
| 4999 | my ($self, $check) = @_; | ||
| 5000 | |||
| 5001 | # Local variables | ||
| 5002 | my ( | ||
| 5003 | $newTaskObj, $acceptID, $result, | ||
| 5004 | @list, @sortedList, @nameList, | ||
| 5005 | %hash, | ||
| 5006 | ); | ||
| 5007 | |||
| 5008 | # Check for improper arguments | ||
| 5009 | if (defined $check) { | ||
| 5010 | |||
| 5011 | return $axmud::CLIENT->writeImproper($self->_objClass . '->assignLeadTask', @_); | ||
| 5012 | } | ||
| 5013 | |||
| 5014 | # Compile a list of all the Chat tasks in the current tasklist, except this one | ||
| 5015 | @list = $self->findOtherTasks(); | ||
| 5016 | if (@list == 1) { | ||
| 5017 | |||
| 5018 | # There is only one remaining Chat task, so make that the lead Chat task | ||
| 5019 | $newTaskObj = $list[0]; | ||
| 5020 | |||
| 5021 | } elsif (@list) { | ||
| 5022 | |||
| 5023 | # Choose a new lead task. Compile a sorted list of Chat task names, and a parallel hash | ||
| 5024 | @sortedList = sort {lc($a->uniqueName) cmp lc($b->uniqueName)} (@list); | ||
| 5025 | foreach my $taskObj (@sortedList) { | ||
| 5026 | |||
| 5027 | push (@nameList, $taskObj->uniqueName); | ||
| 5028 | $hash{$taskObj->uniqueName} = $taskObj; | ||
| 5029 | } | ||
| 5030 | |||
| 5031 | $result = $self->session->mainWin->showComboDialogue( | ||
| 5032 | 'Chat task', | ||
| 5033 | 'Choose a new lead Chat task', | ||
| 5034 | \@nameList, | ||
| 5035 | ); | ||
| 5036 | |||
| 5037 | if ($result) { | ||
| 5038 | |||
| 5039 | $newTaskObj = $hash{$result}; | ||
| 5040 | } | ||
| 5041 | } | ||
| 5042 | |||
| 5043 | if ($newTaskObj) { | ||
| 5044 | |||
| 5045 | # Transfer the Accept ID to the new task, while retaining the old socket | ||
| 5046 | if ($self->acceptID) { | ||
| 5047 | |||
| 5048 | Glib::Source->remove($self->acceptID); | ||
| 5049 | |||
| 5050 | $acceptID = Glib::IO->add_watch( | ||
| 5051 | $self->acceptSocket->fileno, | ||
| 5052 | 'in', | ||
| 5053 | sub { $newTaskObj->acceptConnection(@_); }, | ||
| 5054 | $self->acceptSocket, | ||
| 5055 | ); | ||
| 5056 | |||
| 5057 | $newTaskObj->ivPoke('port', $self->port); | ||
| 5058 | $newTaskObj->ivPoke('acceptSocket', $self->acceptSocket); | ||
| 5059 | $newTaskObj->ivPoke('acceptID', $acceptID); | ||
| 5060 | } | ||
| 5061 | |||
| 5062 | # Mark the other task as the new lead Chat task | ||
| 5063 | $newTaskObj->ivPoke('leadTaskFlag', TRUE); | ||
| 5064 | $self->ivPoke('leadTaskFlag', FALSE); | ||
| 5065 | |||
| 5066 | # Inform the GA::Session of the change of lead Chat task | ||
| 5067 | $self->ivUndef('shortCutIV'); | ||
| 5068 | $newTaskObj->ivPoke('shortCutIV', 'chatTask'); | ||
| 5069 | $self->session->add_standardTask($newTaskObj); | ||
| 5070 | |||
| 5071 | # If there are currently any snooping sessions, destroy the old hooks, and create | ||
| 5072 | # new ones for the new lead task | ||
| 5073 | if ($self->sendHook) { | ||
| 5074 | |||
| 5075 | # Destroy this task's hooks | ||
| 5076 | $self->session->tidyInterfaces($self); | ||
| 5077 | # Create hooks for the new task | ||
| 5078 | $newTaskObj->resetHooks(); | ||
| 5079 | } | ||
| 5080 | } | ||
| 5081 | |||
| 5082 | return 1; | ||
| 5083 | } | ||
| 5084 | |||
| 5085 | sub writeText { | ||
| 5086 | |||
| 5087 | # Called to write text to the task window | ||
| 5088 | # | ||
| 5089 | # Expected arguments | ||
| 5090 | # $text - The text to write | ||
| 5091 | # | ||
| 5092 | # Optional arguments | ||
| 5093 | # $type - What kind of message this is (which determines the colour used) - should be | ||
| 5094 | # one of 'chat_out', 'chat_in', 'echo', 'system', 'remote' or 'snoop'. If | ||
| 5095 | # 'undef' (or an invalid value), the standard colour is used. However, | ||
| 5096 | # if $self->allSystemColourFlag is set to TRUE, $type is ignored and all | ||
| 5097 | # messages are displayed in the colour specified by $self->systemColour | ||
| 5098 | # | ||
| 5099 | # Return values | ||
| 5100 | # 'undef' on improper arguments or if the task window is closed | ||
| 5101 | # 1 otherwise | ||
| 5102 | |||
| 5103 | my ($self, $text, $type, $check) = @_; | ||
| 5104 | |||
| 5105 | # Local variables | ||
| 5106 | my ( | ||
| 5107 | $count, $modText, $fontSize, | ||
| 5108 | %smileyHash, %ttsHash, | ||
| 5109 | ); | ||
| 5110 | |||
| 5111 | # Check for improper arguments | ||
| 5112 | if (! defined $text || defined $check) { | ||
| 5113 | |||
| 5114 | return $axmud::CLIENT->writeImproper($self->_objClass . '->writeText', @_); | ||
| 5115 | } | ||
| 5116 | |||
| 5117 | # Don't write anything to the task window if there isn't one open | ||
| 5118 | if (! $self->taskWinFlag) { | ||
| 5119 | |||
| 5120 | return undef; | ||
| 5121 | } | ||
| 5122 | |||
| 5123 | # If $text is an empty string, then we need to convert it into a string containing a space | ||
| 5124 | # (because GA::Obj::TextView->insertText won't do anything with an empty string) | ||
| 5125 | if (! $text) { | ||
| 5126 | |||
| 5127 | $text = ' '; | ||
| 5128 | |||
| 5129 | # The original chat.pl sends strings which begin with a newline character. We don't want | ||
| 5130 | # that in our task window, thank you very much. | ||
| 5131 | } elsif (substr($text, 0, 1) eq "\n") { | ||
| 5132 | |||
| 5133 | $text = substr($text, 1); | ||
| 5134 | } | ||
| 5135 | |||
| 5136 | # Import the hash of smileys | ||
| 5137 | %smileyHash = $axmud::CLIENT->chatSmileyHash; | ||
| 5138 | |||
| 5139 | # If the text contains smileys (matching keys in GA::Client->chatSmileyHash), and if we're | ||
| 5140 | # allowed to show smileys, we have to break $modText into portions, each containing either | ||
| 5141 | # a smiley or non-smiley text. Show one portion at a time, repeating until there are non | ||
| 5142 | # left | ||
| 5143 | $count = 0; | ||
| 5144 | $modText = $text; | ||
| 5145 | do { | ||
| 5146 | |||
| 5147 | my ($portion, $posn, $smiley, $nlString, $pixbuf); | ||
| 5148 | |||
| 5149 | # The first portion must be prepended by a newline character; any remaining portions are | ||
| 5150 | # not | ||
| 5151 | $count++; | ||
| 5152 | if ($count == 1) { | ||
| 5153 | $nlString = 'before'; | ||
| 5154 | } else { | ||
| 5155 | $nlString = 'echo'; | ||
| 5156 | } | ||
| 5157 | |||
| 5158 | if (! $self->allowSmileyFlag) { | ||
| 5159 | |||
| 5160 | # Display the text without converting any smileys into icons | ||
| 5161 | $portion = $modText; | ||
| 5162 | $modText = ''; | ||
| 5163 | |||
| 5164 | } else { | ||
| 5165 | |||
| 5166 | # Find the position of the first smiley in $modText | ||
| 5167 | foreach my $thisSmiley (keys %smileyHash) { | ||
| 5168 | |||
| 5169 | my $index = index($modText, $thisSmiley); | ||
| 5170 | if ($index > -1) { | ||
| 5171 | |||
| 5172 | # We found a smiley. Do a greedy match, meaning that we take the first | ||
| 5173 | # smiley we found, but that we prefer longer smileys over shorter ones | ||
| 5174 | if ( | ||
| 5175 | ! defined $posn | ||
| 5176 | || $index < $posn | ||
| 5177 | || ($index == $posn && length ($smiley) > length ($thisSmiley)) | ||
| 5178 | ) { | ||
| 5179 | # Check that the smiley's icon file still exists | ||
| 5180 | if (-e $smileyHash{$thisSmiley}) { | ||
| 5181 | |||
| 5182 | # Use this smiley | ||
| 5183 | $posn = $index; | ||
| 5184 | $smiley = $thisSmiley; | ||
| 5185 | } | ||
| 5186 | } | ||
| 5187 | } | ||
| 5188 | } | ||
| 5189 | |||
| 5190 | if (! defined $posn) { | ||
| 5191 | |||
| 5192 | # No smiley found. Display the rest of the text | ||
| 5193 | $portion = $modText; | ||
| 5194 | $modText = ''; | ||
| 5195 | |||
| 5196 | } elsif ($posn == 0) { | ||
| 5197 | |||
| 5198 | # Smiley found at the beginning of $modText. Show only the smiley | ||
| 5199 | $portion = ''; | ||
| 5200 | $modText = substr($modText, length($smiley)); | ||
| 5201 | |||
| 5202 | } else { | ||
| 5203 | |||
| 5204 | # Smiley found, but not at the start of $modText. Display all the text up until | ||
| 5205 | # the smiley, then display the smiley | ||
| 5206 | $portion = substr($modText, 0, $posn); | ||
| 5207 | $modText = substr($modText, $posn + length ($smiley)); | ||
| 5208 | } | ||
| 5209 | } | ||
| 5210 | |||
| 5211 | if ($portion) { | ||
| 5212 | |||
| 5213 | # Display a portion of text | ||
| 5214 | |||
| 5215 | # Use a colour, if $type was specified (or if all messages must be displayed in the | ||
| 5216 | # colour specified by $self->systemColour) | ||
| 5217 | if (defined $type || $self->allSystemColourFlag) { | ||
| 5218 | |||
| 5219 | if ( | ||
| 5220 | ($self->allSystemColourFlag || $type eq 'system') | ||
| 5221 | && defined $self->systemColour | ||
| 5222 | ) { | ||
| 5223 | $self->insertWithLinks($portion, $self->systemColour, $nlString); | ||
| 5224 | |||
| 5225 | } elsif ($type eq 'chat_out' && defined $self->chatOutColour) { | ||
| 5226 | |||
| 5227 | $self->insertWithLinks($portion, $self->chatOutColour, $nlString); | ||
| 5228 | |||
| 5229 | } elsif ($type eq 'chat_in' && defined $self->chatInColour) { | ||
| 5230 | |||
| 5231 | $self->insertWithLinks($portion, $self->chatInColour, $nlString); | ||
| 5232 | |||
| 5233 | } elsif ($type eq 'echo' && defined $self->chatEchoColour) { | ||
| 5234 | |||
| 5235 | $self->insertWithLinks( | ||
| 5236 | 'ECHO: ' . $portion, | ||
| 5237 | $self->chatEchoColour, | ||
| 5238 | $nlString, | ||
| 5239 | ); | ||
| 5240 | |||
| 5241 | } elsif ($type eq 'remote' && defined $self->remoteColour) { | ||
| 5242 | |||
| 5243 | $self->insertWithLinks($portion, $self->remoteColour, $nlString); | ||
| 5244 | |||
| 5245 | } elsif ($type eq 'snoop' && defined $self->snoopColour) { | ||
| 5246 | |||
| 5247 | $self->insertWithLinks($portion, $self->snoopColour, $nlString); | ||
| 5248 | |||
| 5249 | } else { | ||
| 5250 | |||
| 5251 | # By default, use the task window's standard text colour | ||
| 5252 | $self->insertWithLinks($portion, $nlString); | ||
| 5253 | } | ||
| 5254 | |||
| 5255 | } else { | ||
| 5256 | |||
| 5257 | # Colour not specified, so just use the task window's standard text colour | ||
| 5258 | $self->insertWithLinks($portion, $nlString); | ||
| 5259 | } | ||
| 5260 | } | ||
| 5261 | |||
| 5262 | if ($smiley) { | ||
| 5263 | |||
| 5264 | if ($portion) { | ||
| 5265 | |||
| 5266 | # The smiley is coming after a portion of text, so we don't prepend the image | ||
| 5267 | # with a newline character | ||
| 5268 | $nlString = 'echo'; | ||
| 5269 | } | ||
| 5270 | |||
| 5271 | # Display a smiley. Convert the image to a pixbuf | ||
| 5272 | $fontSize = $self->defaultTabObj->textViewObj->fontSize; | ||
| 5273 | if (! defined $fontSize) { | ||
| 5274 | |||
| 5275 | $fontSize = $axmud::CLIENT->constFontSize; | ||
| 5276 | } | ||
| 5277 | |||
| 5278 | $pixbuf = Gtk3::Gdk::Pixbuf->new_from_file_at_scale( | ||
| 5279 | $smileyHash{$smiley}, | ||
| 5280 | # Width/height comparable to font size | ||
| 5281 | ($fontSize * $self->smileySizeFactor), | ||
| 5282 | ($fontSize * $self->smileySizeFactor), | ||
| 5283 | TRUE, # Preserve aspect ratio | ||
| 5284 | ); | ||
| 5285 | |||
| 5286 | if (! $pixbuf) { | ||
| 5287 | |||
| 5288 | # Emergency fallback - display the smiley as text | ||
| 5289 | $self->insertText($smiley, $nlString); | ||
| 5290 | |||
| 5291 | } else { | ||
| 5292 | |||
| 5293 | # Display the smiley icon | ||
| 5294 | $self->showImage($pixbuf, undef, undef, undef, $nlString); | ||
| 5295 | } | ||
| 5296 | } | ||
| 5297 | |||
| 5298 | } until (! $modText); | ||
| 5299 | |||
| 5300 | # If there are any Watch tasks running - in any session - update them | ||
| 5301 | foreach my $otherSession ($axmud::CLIENT->listSessions()) { | ||
| 5302 | |||
| 5303 | my ($world, $char); | ||
| 5304 | |||
| 5305 | if ($otherSession->watchTask) { | ||
| 5306 | |||
| 5307 | $world = $self->session->currentWorld->name; | ||
| 5308 | if ($self->session->currentChar) { | ||
| 5309 | |||
| 5310 | $char = $self->session->currentChar->name; # Otherwise 'undef' | ||
| 5311 | } | ||
| 5312 | |||
| 5313 | $otherSession->watchTask->displayText('chat', $world, $char, $text); | ||
| 5314 | } | ||
| 5315 | } | ||
| 5316 | |||
| 5317 | # Write the message to a logfile (if possible) | ||
| 5318 | $axmud::CLIENT->writeLog( | ||
| 5319 | $self->session, | ||
| 5320 | FALSE, # Not a 'standard' logfile | ||
| 5321 | $text, | ||
| 5322 | FALSE, # Don't precede with a newline character | ||
| 5323 | TRUE, # Use final newline character | ||
| 5324 | 'chat', # Write to this logfile | ||
| 5325 | ); | ||
| 5326 | |||
| 5327 | # Read out a TTS message, if required | ||
| 5328 | %ttsHash = $self->ttsFlagAttribHash; | ||
| 5329 | if ( | ||
| 5330 | $self->ivShow('ttsFlagAttribHash', 'chat') | ||
| 5331 | || ( | ||
| 5332 | defined $type | ||
| 5333 | && ( | ||
| 5334 | ($type eq 'chat_out' && $ttsHash{'chatout'}) | ||
| 5335 | || ($type eq 'chat_in' && $ttsHash{'chatin'}) | ||
| 5336 | || ($type eq 'echo' && $ttsHash{'chatecho'}) | ||
| 5337 | || ($type eq 'system' && $ttsHash{'chatsystem'}) | ||
| 5338 | || ($type eq 'remote' && $ttsHash{'chatremote'}) | ||
| 5339 | || ($type eq 'snoop' && $ttsHash{'chatsnoop'}) | ||
| 5340 | ) | ||
| 5341 | ) | ||
| 5342 | ) { | ||
| 5343 | $self->ttsQuick($text); | ||
| 5344 | } | ||
| 5345 | |||
| 5346 | return 1; | ||
| 5347 | } | ||
| 5348 | |||
| 5349 | sub writeImproper { | ||
| 5350 | |||
| 5351 | # Called whenever the user types a chat command with the wrong (i.e. missing or extra) | ||
| 5352 | # arguments | ||
| 5353 | # | ||
| 5354 | # Expected arguments | ||
| 5355 | # $inputString - The (whole) chat command typed | ||
| 5356 | # | ||
| 5357 | # Return values | ||
| 5358 | # 'undef' | ||
| 5359 | |||
| 5360 | my ($self, $inputString, $check) = @_; | ||
| 5361 | |||
| 5362 | # Check for improper arguments | ||
| 5363 | if (! defined $inputString || defined $check) { | ||
| 5364 | |||
| 5365 | return $axmud::CLIENT->writeImproper($self->_objClass . '->writeImproper', @_); | ||
| 5366 | } | ||
| 5367 | |||
| 5368 | $self->writeText( | ||
| 5369 | 'Invalid chat command (try \';help\')', | ||
| 5370 | 'system', | ||
| 5371 | ); | ||
| 5372 | |||
| 5373 | # Read out a TTS message, if required | ||
| 5374 | if ( | ||
| 5375 | $self->ivShow('ttsFlagAttribHash', 'chat') | ||
| 5376 | || $self->ivShow('ttsFlagAttribHash', 'chatimproper') | ||
| 5377 | ) { | ||
| 5378 | $self->ttsQuick('Invalid chat task command'); | ||
| 5379 | } | ||
| 5380 | |||
| 5381 | return undef; | ||
| 5382 | } | ||
| 5383 | |||
| 5384 | sub refuseOpCode { | ||
| 5385 | |||
| 5386 | # Called by several functions (e.g. $self->chat, ->emote, etc) when the connection hasn't | ||
| 5387 | # yet been negotiated | ||
| 5388 | # Displays a system message in the task window | ||
| 5389 | # | ||
| 5390 | # Expected arguments | ||
| 5391 | # $opCode - The restricted opcode (a key in $self->restrictedHash) which can't be used | ||
| 5392 | # until the connection has been negotiated | ||
| 5393 | # | ||
| 5394 | # Return values | ||
| 5395 | # 'undef' | ||
| 5396 | |||
| 5397 | my ($self, $opCode, $check) = @_; | ||
| 5398 | |||
| 5399 | # Check for improper arguments | ||
| 5400 | if (! defined $opCode || defined $check) { | ||
| 5401 | |||
| 5402 | return $axmud::CLIENT->writeImproper($self->_objClass . '->refuseOpCode', @_); | ||
| 5403 | } | ||
| 5404 | |||
| 5405 | if ($self->chatContactObj) { | ||
| 5406 | |||
| 5407 | $self->writeText( | ||
| 5408 | 'Not yet connected to \'' . $self->chatContactObj->name . '\'', | ||
| 5409 | 'system', | ||
| 5410 | ); | ||
| 5411 | |||
| 5412 | } else { | ||
| 5413 | |||
| 5414 | $self->writeText( | ||
| 5415 | 'Not yet connected to the chat contact', | ||
| 5416 | 'system', | ||
| 5417 | ); | ||
| 5418 | } | ||
| 5419 | |||
| 5420 | return undef; | ||
| 5421 | } | ||
| 5422 | |||
| 5423 | sub setChatWinTitle { | ||
| 5424 | |||
| 5425 | # Called by $self->setName, ->changeRemoteName and ->newChatWin | ||
| 5426 | # Sets the title of the task window (if there is one) to show who is calling whom | ||
| 5427 | # | ||
| 5428 | # Expected arguments | ||
| 5429 | # (none besides $self) | ||
| 5430 | # | ||
| 5431 | # Return values | ||
| 5432 | # 'undef' on improper arguments | ||
| 5433 | # 1 otherwise | ||
| 5434 | |||
| 5435 | my ($self, $check) = @_; | ||
| 5436 | |||
| 5437 | # Check for improper arguments | ||
| 5438 | if (defined $check) { | ||
| 5439 | |||
| 5440 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setChatWinTitle', @_); | ||
| 5441 | } | ||
| 5442 | |||
| 5443 | if (! $self->sessionFlag || ! $self->localName || ! $self->remoteName) { | ||
| 5444 | |||
| 5445 | # Reset the window's title | ||
| 5446 | $self->setTaskWinTitle(); | ||
| 5447 | |||
| 5448 | } else { | ||
| 5449 | |||
| 5450 | $self->setTaskWinTitle( | ||
| 5451 | $self->prettyName . ': ' . $self->localName . ' > ' . $self->remoteName, | ||
| 5452 | ); | ||
| 5453 | } | ||
| 5454 | |||
| 5455 | return 1; | ||
| 5456 | } | ||
| 5457 | |||
| 5458 | # Client commands | ||
| 5459 | |||
| 5460 | sub acceptCalls { | ||
| 5461 | |||
| 5462 | # Called by GA::Cmd::ChatAccept->do and $self->reset | ||
| 5463 | # Starts listening out for incoming calls | ||
| 5464 | # | ||
| 5465 | # Expected arguments | ||
| 5466 | # (none besides $self) | ||
| 5467 | # | ||
| 5468 | # Optional arguments | ||
| 5469 | # $port - The port to use for incoming calls. If not specified, the default port is used | ||
| 5470 | # | ||
| 5471 | # Return values | ||
| 5472 | # 'undef' on improper arguments, if this task isn't the lead Chat task, if this task is | ||
| 5473 | # already listening out for incoming connections or if a socket can't be opened | ||
| 5474 | # 1 otherwise | ||
| 5475 | |||
| 5476 | my ($self, $port, $check) = @_; | ||
| 5477 | |||
| 5478 | # Local variables | ||
| 5479 | my ($acceptSocket, $acceptID); | ||
| 5480 | |||
| 5481 | # Check for improper arguments | ||
| 5482 | if (defined $check) { | ||
| 5483 | |||
| 5484 | return $axmud::CLIENT->writeImproper($self->_objClass . '->acceptCalls', @_); | ||
| 5485 | } | ||
| 5486 | |||
| 5487 | if (! $self->leadTaskFlag) { | ||
| 5488 | |||
| 5489 | return $self->writeError( | ||
| 5490 | 'The \'' .$self->uniqueName . '\' task is not the lead Chat task, so cannot listen' | ||
| 5491 | . ' out for incoming connections', | ||
| 5492 | $self->_objClass . '->acceptCalls', | ||
| 5493 | ); | ||
| 5494 | |||
| 5495 | } elsif ($self->acceptSocket) { | ||
| 5496 | |||
| 5497 | $self->writeText( | ||
| 5498 | 'Already listening for incoming calls on port ' . $self->port, | ||
| 5499 | 'system', | ||
| 5500 | ); | ||
| 5501 | |||
| 5502 | return undef; | ||
| 5503 | } | ||
| 5504 | |||
| 5505 | # Set the port to use | ||
| 5506 | if (! $port) { | ||
| 5507 | |||
| 5508 | $port = $axmud::CLIENT->constChatPort; | ||
| 5509 | } | ||
| 5510 | |||
| 5511 | # Open a new TCP socket | ||
| 5512 | $acceptSocket = IO::Socket::INET->new( | ||
| 5513 | 'Listen' => 5, | ||
| 5514 | 'LocalPort' => $port, | ||
| 5515 | 'Proto' => 'tcp', | ||
| 5516 | 'ReuseAddr' => 1, | ||
| 5517 | ); | ||
| 5518 | |||
| 5519 | if ($acceptSocket) { | ||
| 5520 | |||
| 5521 | # Listen for incoming connections | ||
| 5522 | $acceptID = Glib::IO->add_watch( | ||
| 5523 | $acceptSocket->fileno, | ||
| 5524 | 'in', | ||
| 5525 | sub { $self->acceptConnection(@_); }, | ||
| 5526 | $acceptSocket, | ||
| 5527 | ); | ||
| 5528 | } | ||
| 5529 | |||
| 5530 | if (! $acceptSocket || ! $acceptID) { | ||
| 5531 | |||
| 5532 | return $self->writeError( | ||
| 5533 | 'The \'' .$self->prettyName . '\' task could not open a socket to listen for' | ||
| 5534 | . ' incoming connections', | ||
| 5535 | $self->_objClass . '->acceptCalls', | ||
| 5536 | ); | ||
| 5537 | |||
| 5538 | } else { | ||
| 5539 | |||
| 5540 | # Store IVs | ||
| 5541 | $self->ivPoke('port', $port); | ||
| 5542 | $self->ivPoke('acceptSocket', $acceptSocket); | ||
| 5543 | $self->ivPoke('acceptID', $acceptID); | ||
| 5544 | |||
| 5545 | # (A confirmation message is displayed by the calling function) | ||
| 5546 | return 1; | ||
| 5547 | } | ||
| 5548 | } | ||
| 5549 | |||
| 5550 | sub refuseCalls { | ||
| 5551 | |||
| 5552 | # Called by GA::Cmd::ChatRefuse->do, $self->shutdown and $self->reset | ||
| 5553 | # Stops listening out for incoming calls. If this is the only Chat task and there isn't a | ||
| 5554 | # chat session in progress, then it's safe to halt the task | ||
| 5555 | # | ||
| 5556 | # Expected arguments | ||
| 5557 | # (none besides $self) | ||
| 5558 | # | ||
| 5559 | # Return values | ||
| 5560 | # 'undef' on improper arguments, if this task isn't the lead Chat task or if this task is | ||
| 5561 | # already not listening out for incoming connections | ||
| 5562 | # 1 otherwise | ||
| 5563 | |||
| 5564 | my ($self, $check) = @_; | ||
| 5565 | |||
| 5566 | # Local variables | ||
| 5567 | my $count; | ||
| 5568 | |||
| 5569 | # Check for improper arguments | ||
| 5570 | if (defined $check) { | ||
| 5571 | |||
| 5572 | return $axmud::CLIENT->writeImproper($self->_objClass . '->refuseCalls', @_); | ||
| 5573 | } | ||
| 5574 | |||
| 5575 | if (! $self->leadTaskFlag) { | ||
| 5576 | |||
| 5577 | return $self->writeError( | ||
| 5578 | 'The \'' .$self->uniqueName . '\' task is not the lead Chat task, so cannot listen' | ||
| 5579 | . ' out for incoming connections', | ||
| 5580 | $self->_objClass . '->acceptCalls', | ||
| 5581 | ); | ||
| 5582 | |||
| 5583 | } elsif (! $self->acceptSocket || ! $self->acceptID) { | ||
| 5584 | |||
| 5585 | return $self->writeText( | ||
| 5586 | 'Already not listening for incoming calls on port ' . $self->port, | ||
| 5587 | 'system', | ||
| 5588 | ); | ||
| 5589 | } | ||
| 5590 | |||
| 5591 | # Stop listening for incoming connections | ||
| 5592 | Glib::Source->remove($self->acceptID); | ||
| 5593 | close $self->acceptSocket; | ||
| 5594 | |||
| 5595 | # Reset IVs | ||
| 5596 | $self->ivUndef('acceptSocket'); | ||
| 5597 | $self->ivUndef('acceptID'); | ||
| 5598 | |||
| 5599 | # If there are no other Chat tasks running, it's safe to shut down this task | ||
| 5600 | if (! $self->sessionFlag && ! $self->findOtherTasks()) { | ||
| 5601 | |||
| 5602 | # Halt this task | ||
| 5603 | $self->ivPoke('shutdownFlag', TRUE); | ||
| 5604 | } | ||
| 5605 | |||
| 5606 | # (A confirmation message is displayed by the calling function) | ||
| 5607 | return 1; | ||
| 5608 | } | ||
| 5609 | |||
| 5610 | sub mcall { | ||
| 5611 | |||
| 5612 | # Called by GA::Cmd::ChatCall->do or $self->init | ||
| 5613 | # Initiates a call with someone using the MudMaster protocol | ||
| 5614 | # | ||
| 5615 | # Expected arguments | ||
| 5616 | # $ip - The IP address to call | ||
| 5617 | # | ||
| 5618 | # Optional arguments | ||
| 5619 | # $port - The port to call. If 'undef', GA::Client->constChatPort is used | ||
| 5620 | # | ||
| 5621 | # Return values | ||
| 5622 | # 'undef' on improper arguments | ||
| 5623 | # Otherwise returns the result of $self->requestConnection | ||
| 5624 | |||
| 5625 | my ($self, $ip, $port, $check) = @_; | ||
| 5626 | |||
| 5627 | # Check for improper arguments | ||
| 5628 | if (! defined $ip || defined $check) { | ||
| 5629 | |||
| 5630 | return $axmud::CLIENT->writeImproper($self->_objClass . '->mcall', @_); | ||
| 5631 | } | ||
| 5632 | |||
| 5633 | # Use the default port, if $port was not specified | ||
| 5634 | if (! defined $port) { | ||
| 5635 | |||
| 5636 | $port = $axmud::CLIENT->constChatPort; | ||
| 5637 | } | ||
| 5638 | |||
| 5639 | # Place the call | ||
| 5640 | return $self->requestConnection($ip, $port, $self->ivShow('constOptHash', 'MM')); | ||
| 5641 | } | ||
| 5642 | |||
| 5643 | sub zcall { | ||
| 5644 | |||
| 5645 | # Called by GA::Cmd::ChatZCall->do or $self->init | ||
| 5646 | # Initiates a call with someone using the zChat protocol | ||
| 5647 | # | ||
| 5648 | # Expected arguments | ||
| 5649 | # $ip - The IP address to call | ||
| 5650 | # | ||
| 5651 | # Optional arguments | ||
| 5652 | # $port - The port to call. If 'undef', GA::Client->constChatPort is used | ||
| 5653 | # | ||
| 5654 | # Return values | ||
| 5655 | # 'undef' on improper arguments | ||
| 5656 | # Otherwise returns the result of $self->requestConnection | ||
| 5657 | |||
| 5658 | my ($self, $ip, $port, $check) = @_; | ||
| 5659 | |||
| 5660 | # Check for improper arguments | ||
| 5661 | if (! defined $ip || defined $check) { | ||
| 5662 | |||
| 5663 | return $axmud::CLIENT->writeImproper($self->_objClass . '->zcall', @_); | ||
| 5664 | } | ||
| 5665 | |||
| 5666 | # Use the default port, if $port was not specified | ||
| 5667 | if (! defined $port) { | ||
| 5668 | |||
| 5669 | $port = $axmud::CLIENT->constChatPort; | ||
| 5670 | } | ||
| 5671 | |||
| 5672 | # Place the call | ||
| 5673 | return $self->requestConnection($ip, $port, $self->ivShow('constOptHash', 'ZCHAT')); | ||
| 5674 | } | ||
| 5675 | |||
| 5676 | sub findName { | ||
| 5677 | |||
| 5678 | # Called by GA::Cmd::Chat->do, Emote->do, etc | ||
| 5679 | # Returns a list of all chat connections with a contact whose ->remoteName matches a | ||
| 5680 | # specified name. The match is case-insensitive. | ||
| 5681 | # | ||
| 5682 | # Expected arguments | ||
| 5683 | # $name - The name to match | ||
| 5684 | # | ||
| 5685 | # Return values | ||
| 5686 | # An empty list on improper arguments | ||
| 5687 | # Otherwise returns a list of each Chat task with a matching ->remoteName IV | ||
| 5688 | |||
| 5689 | my ($self, $name, $check) = @_; | ||
| 5690 | |||
| 5691 | # Local variables | ||
| 5692 | my (@emptyList, @matchList); | ||
| 5693 | |||
| 5694 | # Check for improper arguments | ||
| 5695 | if (! defined $name || defined $check) { | ||
| 5696 | |||
| 5697 | $axmud::CLIENT->writeImproper($self->_objClass . '->findName', @_); | ||
| 5698 | return @emptyList; | ||
| 5699 | } | ||
| 5700 | |||
| 5701 | # Compile a list of Chat tasks, including this one, with a matching ->remoteName IV | ||
| 5702 | foreach my $taskObj ($self->session->ivValues('currentTaskHash')) { | ||
| 5703 | |||
| 5704 | if ( | ||
| 5705 | $taskObj->name eq 'chat_task' | ||
| 5706 | && defined $taskObj->remoteName | ||
| 5707 | && lc($taskObj->remoteName) eq lc($name) | ||
| 5708 | ) { | ||
| 5709 | push (@matchList, $taskObj); | ||
| 5710 | } | ||
| 5711 | } | ||
| 5712 | |||
| 5713 | return @matchList; | ||
| 5714 | } | ||
| 5715 | |||
| 5716 | sub findGroup { | ||
| 5717 | |||
| 5718 | # Called by GA::Cmd::ChatGroup->do, EmoteGroup->do, etc | ||
| 5719 | # Returns a list of all chat connections with a contact whose ->localGroup matches a | ||
| 5720 | # specified name. The match is case-insensitive. | ||
| 5721 | # | ||
| 5722 | # Expected arguments | ||
| 5723 | # $group - The group name to match | ||
| 5724 | # | ||
| 5725 | # Return values | ||
| 5726 | # An empty list on improper arguments | ||
| 5727 | # Otherwise returns a list of each Chat task with a matching ->localGroup IV | ||
| 5728 | |||
| 5729 | my ($self, $group, $check) = @_; | ||
| 5730 | |||
| 5731 | # Local variables | ||
| 5732 | my (@emptyList, @matchList); | ||
| 5733 | |||
| 5734 | # Check for improper arguments | ||
| 5735 | if (! defined $group || defined $check) { | ||
| 5736 | |||
| 5737 | $axmud::CLIENT->writeImproper($self->_objClass . '->findGroup', @_); | ||
| 5738 | return @emptyList; | ||
| 5739 | } | ||
| 5740 | |||
| 5741 | # Compile a list of Chat tasks, including this one, with a matching ->remoteName IV | ||
| 5742 | foreach my $taskObj ($self->session->ivValues('currentTaskHash')) { | ||
| 5743 | |||
| 5744 | if ( | ||
| 5745 | $taskObj->name eq 'chat_task' | ||
| 5746 | && defined $taskObj->localGroup | ||
| 5747 | && lc($taskObj->localGroup) eq lc($group) | ||
| 5748 | ) { | ||
| 5749 | push (@matchList, $taskObj); | ||
| 5750 | } | ||
| 5751 | } | ||
| 5752 | |||
| 5753 | return @matchList; | ||
| 5754 | } | ||
| 5755 | |||
| 5756 | sub findAllTasks { | ||
| 5757 | |||
| 5758 | # Called by GA::Cmd::ChatAll->do, GA::Cmd::EmoteAll->do, etc. Also called by this task's | ||
| 5759 | # functions | ||
| 5760 | # Returns a list of all Chat tasks in the current tasklist, including this one | ||
| 5761 | # | ||
| 5762 | # Expected arguments | ||
| 5763 | # (none besides $self) | ||
| 5764 | # | ||
| 5765 | # Return values | ||
| 5766 | # An empty list on improper arguments | ||
| 5767 | # Otherwise returns a list of all Chat tasks | ||
| 5768 | |||
| 5769 | my ($self, $check) = @_; | ||
| 5770 | |||
| 5771 | # Local variables | ||
| 5772 | my (@emptyList, @matchList); | ||
| 5773 | |||
| 5774 | # Check for improper arguments | ||
| 5775 | if (defined $check) { | ||
| 5776 | |||
| 5777 | $axmud::CLIENT->writeImproper($self->_objClass . '->findAllTasks', @_); | ||
| 5778 | return @emptyList; | ||
| 5779 | } | ||
| 5780 | |||
| 5781 | # Compile a list of all Chat tasks, including this one | ||
| 5782 | foreach my $taskObj ($self->session->ivValues('currentTaskHash')) { | ||
| 5783 | |||
| 5784 | if ($taskObj->name eq 'chat_task') { | ||
| 5785 | |||
| 5786 | push (@matchList, $taskObj); | ||
| 5787 | } | ||
| 5788 | } | ||
| 5789 | |||
| 5790 | return @matchList; | ||
| 5791 | } | ||
| 5792 | |||
| 5793 | sub findOtherTasks { | ||
| 5794 | |||
| 5795 | # Called by this task's functions | ||
| 5796 | # Returns a list of all Chat tasks in the current tasklist, except this one | ||
| 5797 | # | ||
| 5798 | # Expected arguments | ||
| 5799 | # (none besides $self) | ||
| 5800 | # | ||
| 5801 | # Return values | ||
| 5802 | # An empty list on improper arguments | ||
| 5803 | # Otherwise returns a list of Chat tasks (may be an empty list) | ||
| 5804 | |||
| 5805 | my ($self, $check) = @_; | ||
| 5806 | |||
| 5807 | # Local variables | ||
| 5808 | my (@emptyList, @matchList); | ||
| 5809 | |||
| 5810 | # Check for improper arguments | ||
| 5811 | if (defined $check) { | ||
| 5812 | |||
| 5813 | $axmud::CLIENT->writeImproper($self->_objClass . '->findAllTasks', @_); | ||
| 5814 | return @emptyList; | ||
| 5815 | } | ||
| 5816 | |||
| 5817 | # Compile a list of all Chat tasks, including this one | ||
| 5818 | foreach my $taskObj ($self->session->ivValues('currentTaskHash')) { | ||
| 5819 | |||
| 5820 | if ($taskObj ne $self && $taskObj->name eq 'chat_task') { | ||
| 5821 | |||
| 5822 | push (@matchList, $taskObj); | ||
| 5823 | } | ||
| 5824 | } | ||
| 5825 | |||
| 5826 | return @matchList; | ||
| 5827 | } | ||
| 5828 | |||
| 5829 | # Task window commands | ||
| 5830 | |||
| 5831 | sub setName { | ||
| 5832 | |||
| 5833 | # Sets the name used in chat sessions | ||
| 5834 | # | ||
| 5835 | # Expected arguments | ||
| 5836 | # $argString - The text typed, minus the initial command sigil (if any) and the initial | ||
| 5837 | # chat command (if any) | ||
| 5838 | # | ||
| 5839 | # Return values | ||
| 5840 | # 'undef' on improper arguments or if an invalid name is specified | ||
| 5841 | # 1 otherwise | ||
| 5842 | |||
| 5843 | my ($self, $argString, $check) = @_; | ||
| 5844 | |||
| 5845 | # Local variables | ||
| 5846 | my @list; | ||
| 5847 | |||
| 5848 | # Check for improper arguments | ||
| 5849 | if (! defined $argString || defined $check) { | ||
| 5850 | |||
| 5851 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setName', @_); | ||
| 5852 | } | ||
| 5853 | |||
| 5854 | if ($argString) { | ||
| 5855 | |||
| 5856 | if (length ($argString) < 3 || length ($argString) > 16) { | ||
| 5857 | |||
| 5858 | $self->writeText( | ||
| 5859 | 'Your chat nickname must be between 3-16 characters', | ||
| 5860 | 'system', | ||
| 5861 | ); | ||
| 5862 | |||
| 5863 | return undef; | ||
| 5864 | |||
| 5865 | } else { | ||
| 5866 | |||
| 5867 | # Use the specified name | ||
| 5868 | $self->ivPoke('localName', $argString); | ||
| 5869 | } | ||
| 5870 | |||
| 5871 | } else { | ||
| 5872 | |||
| 5873 | # Use the default name | ||
| 5874 | if ($self->session->currentChar) { | ||
| 5875 | |||
| 5876 | $self->ivPoke('localName', ucfirst($self->session->currentChar->name)); | ||
| 5877 | |||
| 5878 | } else { | ||
| 5879 | |||
| 5880 | # Emergency failsafe - 'Axmud user' | ||
| 5881 | $self->ivPoke('localName', $axmud::SCRIPT . ' user'); | ||
| 5882 | } | ||
| 5883 | } | ||
| 5884 | |||
| 5885 | $self->broadcast( | ||
| 5886 | $self->ivShow('constOptHash', 'NAME_CHANGE'), | ||
| 5887 | $self->localName, | ||
| 5888 | ); | ||
| 5889 | |||
| 5890 | $self->writeText( | ||
| 5891 | 'You change your chat nickname to \'' . $self->localName . '\'', | ||
| 5892 | 'system', | ||
| 5893 | ); | ||
| 5894 | |||
| 5895 | # Update the window title to show the new name | ||
| 5896 | $self->setChatWinTitle(); | ||
| 5897 | |||
| 5898 | # $self->broadcast sends a message to every chat contact about the change of nickname, so | ||
| 5899 | # every current Chat task besides this one must also be informed | ||
| 5900 | @list = $self->findOtherTasks(); | ||
| 5901 | foreach my $taskObj (@list) { | ||
| 5902 | |||
| 5903 | $taskObj->ivPoke('localName', $self->localName); | ||
| 5904 | |||
| 5905 | $taskObj->writeText( | ||
| 5906 | 'Your chat nickname has been changed to \'' . $taskObj->localName . '\'', | ||
| 5907 | 'system', | ||
| 5908 | ); | ||
| 5909 | |||
| 5910 | # Also update the window's title to show the new name | ||
| 5911 | $taskObj->setChatWinTitle(); | ||
| 5912 | } | ||
| 5913 | |||
| 5914 | return 1; | ||
| 5915 | } | ||
| 5916 | |||
| 5917 | sub setGroup { | ||
| 5918 | |||
| 5919 | # Defines the group to which this chat session belongs | ||
| 5920 | # | ||
| 5921 | # Expected arguments | ||
| 5922 | # $argString - The text typed, minus the initial command sigil (if any) and the initial | ||
| 5923 | # chat command (if any) | ||
| 5924 | # | ||
| 5925 | # Return values | ||
| 5926 | # 'undef' on improper arguments | ||
| 5927 | # 1 otherwise | ||
| 5928 | |||
| 5929 | my ($self, $argString, $check) = @_; | ||
| 5930 | |||
| 5931 | # Local variables | ||
| 5932 | my $group; | ||
| 5933 | |||
| 5934 | # Check for improper arguments | ||
| 5935 | if (! defined $argString || defined $check) { | ||
| 5936 | |||
| 5937 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setGroup', @_); | ||
| 5938 | } | ||
| 5939 | |||
| 5940 | if ($argString) { | ||
| 5941 | |||
| 5942 | # Group name is maximum 15 characters | ||
| 5943 | $group = substr($argString, 0, 15); | ||
| 5944 | |||
| 5945 | $self->ivPoke('localGroup', $group); | ||
| 5946 | |||
| 5947 | # Display a confirmation | ||
| 5948 | $self->writeText( | ||
| 5949 | 'Joined the group \'' . $group . '\'', | ||
| 5950 | 'system', | ||
| 5951 | ); | ||
| 5952 | |||
| 5953 | } elsif (! $self->localGroup) { | ||
| 5954 | |||
| 5955 | return $self->writeText( | ||
| 5956 | 'This session is not in a group (try \';group <name>\')', | ||
| 5957 | 'system', | ||
| 5958 | ); | ||
| 5959 | |||
| 5960 | } else { | ||
| 5961 | |||
| 5962 | $self->writeText( | ||
| 5963 | 'Left the group \'' . $self->localGroup . '\'', | ||
| 5964 | 'system', | ||
| 5965 | ); | ||
| 5966 | |||
| 5967 | $self->ivPoke('localGroup', ''); | ||
| 5968 | } | ||
| 5969 | |||
| 5970 | return 1; | ||
| 5971 | } | ||
| 5972 | |||
| 5973 | sub chat { | ||
| 5974 | |||
| 5975 | # Sends something to a chat session | ||
| 5976 | # | ||
| 5977 | # Expected arguments | ||
| 5978 | # $argString - The text typed, minus the initial command sigil (if any) and the initial | ||
| 5979 | # chat command (if any) | ||
| 5980 | # | ||
| 5981 | # Return values | ||
| 5982 | # 'undef' on improper arguments or if the connection hasn't been negotiated yet | ||
| 5983 | # 1 otherwise | ||
| 5984 | |||
| 5985 | my ($self, $argString, $check) = @_; | ||
| 5986 | |||
| 5987 | # Local variables | ||
| 5988 | my $result; | ||
| 5989 | |||
| 5990 | # Check for improper arguments | ||
| 5991 | if (! defined $argString || defined $check) { | ||
| 5992 | |||
| 5993 | return $axmud::CLIENT->writeImproper($self->_objClass . '->chat', @_); | ||
| 5994 | } | ||
| 5995 | |||
| 5996 | # Don't comply if the connection hasn't been negotiated yet | ||
| 5997 | if (! $self->remoteName) { | ||
| 5998 | |||
| 5999 | return $self->refuseOpCode($self->ivShow('constOptHash', 'TEXT_PERSONAL')); | ||
| 6000 | } | ||
| 6001 | |||
| 6002 | # Don't do anything if $argString is empty (we don't want to send a line of text like | ||
| 6003 | # <You chat to Bob, ''> ) | ||
| 6004 | if ($argString) { | ||
| 6005 | |||
| 6006 | $result = $self->sendCmd( | ||
| 6007 | $self->ivShow('constOptHash', 'TEXT_PERSONAL'), | ||
| 6008 | $self->formatText($argString, FALSE, $self->ivShow('constOptHash', 'PERSONAL')), | ||
| 6009 | ); | ||
| 6010 | |||
| 6011 | # If the opcode wasn't restricted... | ||
| 6012 | if ($result) { | ||
| 6013 | |||
| 6014 | # Don't enclose a recognised smiley in quotes | ||
| 6015 | if ($axmud::CLIENT->ivExists('constChatSmileyHash', $argString)) { | ||
| 6016 | |||
| 6017 | $self->writeText( | ||
| 6018 | 'You chat to ' . $self->remoteName . ', ' . $argString, | ||
| 6019 | 'chat_out', | ||
| 6020 | ); | ||
| 6021 | |||
| 6022 | } else { | ||
| 6023 | |||
| 6024 | $self->writeText( | ||
| 6025 | 'You chat to ' . $self->remoteName . ', \'' . $argString . '\'', | ||
| 6026 | 'chat_out', | ||
| 6027 | ); | ||
| 6028 | } | ||
| 6029 | } | ||
| 6030 | } | ||
| 6031 | |||
| 6032 | return 1; | ||
| 6033 | } | ||
| 6034 | |||
| 6035 | sub emote { | ||
| 6036 | |||
| 6037 | # Sends something as an emote to a chat session | ||
| 6038 | # | ||
| 6039 | # Expected arguments | ||
| 6040 | # $argString - The text typed, minus the initial command sigil (if any) and the initial | ||
| 6041 | # chat command (if any) | ||
| 6042 | # | ||
| 6043 | # Return values | ||
| 6044 | # 'undef' on improper arguments or if the connection hasn't been negotiated yet | ||
| 6045 | # 1 otherwise | ||
| 6046 | |||
| 6047 | my ($self, $argString, $check) = @_; | ||
| 6048 | |||
| 6049 | # Check for improper arguments | ||
| 6050 | if (! defined $argString || defined $check) { | ||
| 6051 | |||
| 6052 | return $axmud::CLIENT->writeImproper($self->_objClass . '->emote', @_); | ||
| 6053 | } | ||
| 6054 | |||
| 6055 | # Don't comply if the connection hasn't been negotiated yet | ||
| 6056 | if (! $self->remoteName) { | ||
| 6057 | |||
| 6058 | return $self->refuseOpCode($self->ivShow('constOptHash', 'TEXT_PERSONAL')); | ||
| 6059 | } | ||
| 6060 | |||
| 6061 | # Don't do anything if $argString is empty (we don't want to send a line of text like | ||
| 6062 | # <You emote to Bob, ''> ) | ||
| 6063 | if ($argString) { | ||
| 6064 | |||
| 6065 | $self->sendCmd( | ||
| 6066 | $self->ivShow('constOptHash', 'TEXT_PERSONAL'), | ||
| 6067 | $self->formatText($argString, TRUE, $self->ivShow('constOptHash', 'PERSONAL')), | ||
| 6068 | ); | ||
| 6069 | |||
| 6070 | $self->writeText( | ||
| 6071 | 'You emote to ' . $self->remoteName . ': ' . $self->localName . ' ' . $argString, | ||
| 6072 | 'chat_out', | ||
| 6073 | ); | ||
| 6074 | } | ||
| 6075 | |||
| 6076 | return 1; | ||
| 6077 | } | ||
| 6078 | |||
| 6079 | sub chatToGroup { | ||
| 6080 | |||
| 6081 | # Sends something to the group | ||
| 6082 | # | ||
| 6083 | # Expected arguments | ||
| 6084 | # $argString - The text typed, minus the initial command sigil (if any) and the initial | ||
| 6085 | # chat command (if any) | ||
| 6086 | # | ||
| 6087 | # Return values | ||
| 6088 | # 'undef' on improper arguments, if a ->localGroup hasn't been defined or if the | ||
| 6089 | # connection hasn't been negotiated yet | ||
| 6090 | # 1 otherwise | ||
| 6091 | |||
| 6092 | my ($self, $argString, $check) = @_; | ||
| 6093 | |||
| 6094 | # Local variables | ||
| 6095 | my $groupFormat; | ||
| 6096 | |||
| 6097 | # Check for improper arguments | ||
| 6098 | if (! defined $argString || defined $check) { | ||
| 6099 | |||
| 6100 | return $axmud::CLIENT->writeImproper($self->_objClass . '->chatToGroup', @_); | ||
| 6101 | } | ||
| 6102 | |||
| 6103 | # Don't comply if the connection hasn't been negotiated yet | ||
| 6104 | if (! $self->remoteName) { | ||
| 6105 | |||
| 6106 | return $self->refuseOpCode($self->ivShow('constOptHash', 'TEXT_GROUP')); | ||
| 6107 | } | ||
| 6108 | |||
| 6109 | # Don't do anything if $argString is empty (we don't want to send a line of text like | ||
| 6110 | # <You chat to Bob, ''> ) | ||
| 6111 | if ($argString) { | ||
| 6112 | |||
| 6113 | if (! $self->localGroup) { | ||
| 6114 | |||
| 6115 | return $self->writeText( | ||
| 6116 | 'This session is not in a group (try \';group <name>\')', | ||
| 6117 | 'system', | ||
| 6118 | ); | ||
| 6119 | |||
| 6120 | } else { | ||
| 6121 | |||
| 6122 | $groupFormat = $self->formatGroup($self->localGroup); | ||
| 6123 | } | ||
| 6124 | |||
| 6125 | $self->broadcast( | ||
| 6126 | $self->ivShow('constOptHash', 'TEXT_GROUP'), | ||
| 6127 | $groupFormat . $self->formatText( | ||
| 6128 | $argString, | ||
| 6129 | FALSE, | ||
| 6130 | $self->ivShow('constOptHash', 'GROUP'), | ||
| 6131 | ), | ||
| 6132 | $self->localGroup, | ||
| 6133 | ); | ||
| 6134 | |||
| 6135 | # Don't enclose a recognised smiley in quotes | ||
| 6136 | if ($axmud::CLIENT->ivExists('constChatSmileyHash', $argString)) { | ||
| 6137 | |||
| 6138 | $self->writeText( | ||
| 6139 | 'You chat to the group ' . $self->localGroup . ', ' . $argString, | ||
| 6140 | 'chat_out', | ||
| 6141 | ); | ||
| 6142 | |||
| 6143 | } else { | ||
| 6144 | |||
| 6145 | $self->writeText( | ||
| 6146 | 'You chat to the group ' . $self->localGroup . ', \'' . $argString . '\'', | ||
| 6147 | 'chat_out', | ||
| 6148 | ); | ||
| 6149 | } | ||
| 6150 | } | ||
| 6151 | |||
| 6152 | return 1; | ||
| 6153 | } | ||
| 6154 | |||
| 6155 | sub emoteToGroup { | ||
| 6156 | |||
| 6157 | # Sends something to the group | ||
| 6158 | # | ||
| 6159 | # Expected arguments | ||
| 6160 | # $argString - The text typed, minus the initial command sigil (if any) and the initial | ||
| 6161 | # chat command (if any) | ||
| 6162 | # | ||
| 6163 | # Return values | ||
| 6164 | # 'undef' on improper arguments, if a ->localGroup hasn't been defined or if the | ||
| 6165 | # connection hasn't been negotiated yet | ||
| 6166 | # 1 otherwise | ||
| 6167 | |||
| 6168 | my ($self, $argString, $check) = @_; | ||
| 6169 | |||
| 6170 | # Local variables | ||
| 6171 | my $groupFormat; | ||
| 6172 | |||
| 6173 | # Check for improper arguments | ||
| 6174 | if (! defined $argString || defined $check) { | ||
| 6175 | |||
| 6176 | return $axmud::CLIENT->writeImproper($self->_objClass . '->emoteToGroup', @_); | ||
| 6177 | } | ||
| 6178 | |||
| 6179 | # Don't comply if the connection hasn't been negotiated yet | ||
| 6180 | if (! $self->remoteName) { | ||
| 6181 | |||
| 6182 | return $self->refuseOpCode($self->ivShow('constOptHash', 'TEXT_GROUP')); | ||
| 6183 | } | ||
| 6184 | |||
| 6185 | # Don't do anything if $argString is empty (we don't want to send a line of text like | ||
| 6186 | # <You emote to Bob, ''> ) | ||
| 6187 | if ($argString) { | ||
| 6188 | |||
| 6189 | if (! $self->localGroup) { | ||
| 6190 | |||
| 6191 | return $self->writeText( | ||
| 6192 | 'This session is not in a group (try \';group <name>\')', | ||
| 6193 | 'system', | ||
| 6194 | ); | ||
| 6195 | |||
| 6196 | } else { | ||
| 6197 | |||
| 6198 | $groupFormat = $self->formatGroup($self->localGroup); | ||
| 6199 | } | ||
| 6200 | |||
| 6201 | $self->broadcast( | ||
| 6202 | $self->ivShow('constOptHash', 'TEXT_GROUP'), | ||
| 6203 | $groupFormat . $self->formatText( | ||
| 6204 | $argString, | ||
| 6205 | TRUE, | ||
| 6206 | $self->ivShow('constOptHash', 'GROUP'), | ||
| 6207 | ), | ||
| 6208 | $self->localGroup, | ||
| 6209 | ); | ||
| 6210 | |||
| 6211 | $self->writeText( | ||
| 6212 | 'You emote to the group ' . $self->localGroup . ': ' . $self->localName . ' ' | ||
| 6213 | . $argString, | ||
| 6214 | 'chat_out', | ||
| 6215 | ); | ||
| 6216 | } | ||
| 6217 | |||
| 6218 | return 1; | ||
| 6219 | } | ||
| 6220 | |||
| 6221 | sub chatToAll { | ||
| 6222 | |||
| 6223 | # Sends something to all open connections | ||
| 6224 | # | ||
| 6225 | # Expected arguments | ||
| 6226 | # $argString - The text typed, minus the initial command sigil (if any) and the initial | ||
| 6227 | # chat command (if any) | ||
| 6228 | # | ||
| 6229 | # Return values | ||
| 6230 | # 'undef' on improper arguments or if the connection hasn't been negotiated yet | ||
| 6231 | # 1 otherwise | ||
| 6232 | |||
| 6233 | my ($self, $argString, $check) = @_; | ||
| 6234 | |||
| 6235 | # Check for improper arguments | ||
| 6236 | if (! defined $argString || defined $check) { | ||
| 6237 | |||
| 6238 | return $axmud::CLIENT->writeImproper($self->_objClass . '->chatToAll', @_); | ||
| 6239 | } | ||
| 6240 | |||
| 6241 | # Don't comply if the connection hasn't been negotiated yet | ||
| 6242 | if (! $self->remoteName) { | ||
| 6243 | |||
| 6244 | return $self->refuseOpCode($self->ivShow('constOptHash', 'TEXT_EVERYBODY')); | ||
| 6245 | } | ||
| 6246 | |||
| 6247 | # Don't do anything if $argString is empty (we don't want to send a line of text like | ||
| 6248 | # <You chat to Bob, ''> ) | ||
| 6249 | if ($argString) { | ||
| 6250 | |||
| 6251 | $self->broadcast( | ||
| 6252 | $self->ivShow('constOptHash', 'TEXT_EVERYBODY'), | ||
| 6253 | $self->formatText($argString, FALSE, $self->ivShow('constOptHash', 'EVERYBODY')), | ||
| 6254 | ); | ||
| 6255 | |||
| 6256 | # Don't enclose a recognised smiley in quotes | ||
| 6257 | if ($axmud::CLIENT->ivExists('constChatSmileyHash', $argString)) { | ||
| 6258 | |||
| 6259 | $self->writeText( | ||
| 6260 | 'You chat to everybody, ' . $argString, | ||
| 6261 | 'chat_out', | ||
| 6262 | ); | ||
| 6263 | |||
| 6264 | } else { | ||
| 6265 | |||
| 6266 | $self->writeText( | ||
| 6267 | 'You chat to everybody, \'' . $argString . '\'', | ||
| 6268 | 'chat_out', | ||
| 6269 | ); | ||
| 6270 | } | ||
| 6271 | } | ||
| 6272 | |||
| 6273 | return 1; | ||
| 6274 | } | ||
| 6275 | |||
| 6276 | sub emoteToAll { | ||
| 6277 | |||
| 6278 | # Emotes something to all open connections | ||
| 6279 | # | ||
| 6280 | # Expected arguments | ||
| 6281 | # $argString - The text typed, minus the initial command sigil (if any) and the initial | ||
| 6282 | # chat command (if any) | ||
| 6283 | # | ||
| 6284 | # Return values | ||
| 6285 | # 'undef' on improper arguments or if the connection hasn't been negotiated yet | ||
| 6286 | # 1 otherwise | ||
| 6287 | |||
| 6288 | my ($self, $argString, $check) = @_; | ||
| 6289 | |||
| 6290 | # Check for improper arguments | ||
| 6291 | if (! defined $argString || defined $check) { | ||
| 6292 | |||
| 6293 | return $axmud::CLIENT->writeImproper($self->_objClass . '->emoteToAll', @_); | ||
| 6294 | } | ||
| 6295 | |||
| 6296 | # Don't comply if the connection hasn't been negotiated yet | ||
| 6297 | if (! $self->remoteName) { | ||
| 6298 | |||
| 6299 | return $self->refuseOpCode($self->ivShow('constOptHash', 'TEXT_EVERYBODY')); | ||
| 6300 | } | ||
| 6301 | |||
| 6302 | # Don't do anything if $argString is empty (we don't want to send a line of text like | ||
| 6303 | # <You emote to Bob, ''> ) | ||
| 6304 | if ($argString) { | ||
| 6305 | |||
| 6306 | $self->broadcast( | ||
| 6307 | $self->ivShow('constOptHash', 'TEXT_EVERYBODY'), | ||
| 6308 | $self->formatText($argString, TRUE, $self->ivShow('constOptHash', 'EVERYBODY')), | ||
| 6309 | ); | ||
| 6310 | |||
| 6311 | $self->writeText( | ||
| 6312 | 'You emote to everybody: ' . $self->localName . ' ' . $argString, | ||
| 6313 | 'chat_out', | ||
| 6314 | ); | ||
| 6315 | } | ||
| 6316 | |||
| 6317 | return 1; | ||
| 6318 | } | ||
| 6319 | |||
| 6320 | sub pingPeer { | ||
| 6321 | |||
| 6322 | # Pings the chat contact | ||
| 6323 | # | ||
| 6324 | # Expected arguments | ||
| 6325 | # $argString - The text typed, minus the initial command sigil (if any) and the initial | ||
| 6326 | # chat command (if any) | ||
| 6327 | # | ||
| 6328 | # Return values | ||
| 6329 | # 'undef' on improper arguments | ||
| 6330 | # 1 otherwise | ||
| 6331 | |||
| 6332 | my ($self, $argString, $check) = @_; | ||
| 6333 | |||
| 6334 | # Check for improper arguments | ||
| 6335 | if (! defined $argString || defined $check) { | ||
| 6336 | |||
| 6337 | return $axmud::CLIENT->writeImproper($self->_objClass . '->pingPeer', @_); | ||
| 6338 | } | ||
| 6339 | |||
| 6340 | # There should not be any arguments to the chat command itself | ||
| 6341 | if ($argString) { | ||
| 6342 | |||
| 6343 | return $self->writeImproper(); | ||
| 6344 | } | ||
| 6345 | |||
| 6346 | $self->ivPoke('pingStamp', int(rand(2**32 - 1))); | ||
| 6347 | |||
| 6348 | # Update IVs | ||
| 6349 | $self->ivPoke('pingTime', $axmud::CLIENT->getTime()); | ||
| 6350 | |||
| 6351 | $self->sendCmd( | ||
| 6352 | $self->ivShow('constOptHash', 'PING_REQUEST'), | ||
| 6353 | $self->pingStamp, | ||
| 6354 | ); | ||
| 6355 | |||
| 6356 | return 1; | ||
| 6357 | } | ||
| 6358 | |||
| 6359 | sub sendDoNotDisturb { | ||
| 6360 | |||
| 6361 | # Sends a DO_NOT_DISTURB message to the chat contact (in MudMaster connections only) | ||
| 6362 | # | ||
| 6363 | # Expected arguments | ||
| 6364 | # $argString - The text typed, minus the initial command sigil (if any) and the initial | ||
| 6365 | # chat command (if any) | ||
| 6366 | # | ||
| 6367 | # Return values | ||
| 6368 | # 'undef' on improper arguments or if called in a zChat session | ||
| 6369 | # 1 otherwise | ||
| 6370 | |||
| 6371 | my ($self, $argString, $check) = @_; | ||
| 6372 | |||
| 6373 | # Check for improper arguments | ||
| 6374 | if (! defined $argString || defined $check) { | ||
| 6375 | |||
| 6376 | return $axmud::CLIENT->writeImproper($self->_objClass . '->sendDoNotDisturb', @_); | ||
| 6377 | } | ||
| 6378 | |||
| 6379 | # There should not be any arguments to the chat command itself | ||
| 6380 | if ($argString) { | ||
| 6381 | |||
| 6382 | return $self->writeImproper(); | ||
| 6383 | } | ||
| 6384 | |||
| 6385 | if ($self->chatType == $self->ivShow('constOptHash', 'ZCHAT')) { | ||
| 6386 | |||
| 6387 | $self->writeText( | ||
| 6388 | 'Only the MudMaster protocol supports \'do not disturb\' messages.', | ||
| 6389 | 'system', | ||
| 6390 | ); | ||
| 6391 | |||
| 6392 | return undef; | ||
| 6393 | } | ||
| 6394 | |||
| 6395 | $self->sendCmd( | ||
| 6396 | $self->ivShow('constOptHash', 'DO_NOT_DISTURB'), | ||
| 6397 | '', | ||
| 6398 | ); | ||
| 6399 | |||
| 6400 | $self->writeText( | ||
| 6401 | 'Sent \'do not disturb\' request to ' . $self->remoteName, | ||
| 6402 | 'system', | ||
| 6403 | ); | ||
| 6404 | |||
| 6405 | return 1; | ||
| 6406 | } | ||
| 6407 | |||
| 6408 | sub submitToCmds { | ||
| 6409 | |||
| 6410 | # Allows the chat contact to send world commands to this world | ||
| 6411 | # | ||
| 6412 | # Expected arguments | ||
| 6413 | # $argString - The text typed, minus the initial command sigil (if any) and the initial | ||
| 6414 | # chat command (if any) | ||
| 6415 | # | ||
| 6416 | # Return values | ||
| 6417 | # 'undef' on improper arguments or if called in a MudMaster session | ||
| 6418 | # 1 otherwise | ||
| 6419 | |||
| 6420 | my ($self, $argString, $check) = @_; | ||
| 6421 | |||
| 6422 | # Check for improper arguments | ||
| 6423 | if (! defined $argString || defined $check) { | ||
| 6424 | |||
| 6425 | return $axmud::CLIENT->writeImproper($self->_objClass . '->submitToCmds', @_); | ||
| 6426 | } | ||
| 6427 | |||
| 6428 | # There should not be any arguments to the chat command itself | ||
| 6429 | if ($argString) { | ||
| 6430 | |||
| 6431 | return $self->writeImproper(); | ||
| 6432 | } | ||
| 6433 | |||
| 6434 | if ($self->chatType == $self->ivShow('constOptHash', 'MM')) { | ||
| 6435 | |||
| 6436 | $self->writeText( | ||
| 6437 | 'Only the zChat protocol supports remote commands.', | ||
| 6438 | 'system', | ||
| 6439 | ); | ||
| 6440 | |||
| 6441 | return undef; | ||
| 6442 | |||
| 6443 | } elsif ($self->allowRemoteCmdFlag) { | ||
| 6444 | |||
| 6445 | $self->writeText( | ||
| 6446 | 'Remote commands are already allowed in this session.', | ||
| 6447 | 'system', | ||
| 6448 | ); | ||
| 6449 | |||
| 6450 | } else { | ||
| 6451 | |||
| 6452 | $self->ivPoke('allowRemoteCmdFlag', TRUE); | ||
| 6453 | |||
| 6454 | $self->sendCmd( | ||
| 6455 | $self->ivShow('constOptHash', 'MESSAGE'), | ||
| 6456 | 'You can now send remote commands to ' . $self->localName, | ||
| 6457 | ); | ||
| 6458 | |||
| 6459 | $self->writeText( | ||
| 6460 | $self->remoteName . ' can now send you remote commands.', | ||
| 6461 | 'system', | ||
| 6462 | ); | ||
| 6463 | } | ||
| 6464 | |||
| 6465 | return 1; | ||
| 6466 | } | ||
| 6467 | |||
| 6468 | sub escapeFromCmds { | ||
| 6469 | |||
| 6470 | # Forbids the chat contact from sending world commands to this world | ||
| 6471 | # | ||
| 6472 | # Expected arguments | ||
| 6473 | # $argString - The text typed, minus the initial command sigil (if any) and the initial | ||
| 6474 | # chat command (if any) | ||
| 6475 | # | ||
| 6476 | # Return values | ||
| 6477 | # 'undef' on improper arguments or if called in a MudMaster session | ||
| 6478 | # 1 otherwise | ||
| 6479 | |||
| 6480 | my ($self, $argString, $check) = @_; | ||
| 6481 | |||
| 6482 | # Check for improper arguments | ||
| 6483 | if (! defined $argString || defined $check) { | ||
| 6484 | |||
| 6485 | return $axmud::CLIENT->writeImproper($self->_objClass . '->escapeFromCmds', @_); | ||
| 6486 | } | ||
| 6487 | |||
| 6488 | # There should not be any arguments to the chat command itself | ||
| 6489 | if ($argString) { | ||
| 6490 | |||
| 6491 | return $self->writeImproper(); | ||
| 6492 | } | ||
| 6493 | |||
| 6494 | if ($self->chatType == $self->ivShow('constOptHash', 'MM')) { | ||
| 6495 | |||
| 6496 | $self->writeText( | ||
| 6497 | 'Only the zChat protocol supports remote commands.', | ||
| 6498 | 'system', | ||
| 6499 | ); | ||
| 6500 | |||
| 6501 | return undef; | ||
| 6502 | |||
| 6503 | } elsif (! $self->allowRemoteCmdFlag) { | ||
| 6504 | |||
| 6505 | $self->writeText( | ||
| 6506 | 'Remote commands are already forbidden in this session.', | ||
| 6507 | 'system', | ||
| 6508 | ); | ||
| 6509 | |||
| 6510 | } else { | ||
| 6511 | |||
| 6512 | $self->ivPoke('allowRemoteCmdFlag', FALSE); | ||
| 6513 | |||
| 6514 | $self->sendCmd( | ||
| 6515 | $self->ivShow('constOptHash', 'MESSAGE'), | ||
| 6516 | 'You can no longer send remote commands to ' . $self->localName, | ||
| 6517 | ); | ||
| 6518 | |||
| 6519 | $self->writeText( | ||
| 6520 | $self->remoteName . ' can no longer send you remote commands.', | ||
| 6521 | 'system', | ||
| 6522 | ); | ||
| 6523 | } | ||
| 6524 | |||
| 6525 | return 1; | ||
| 6526 | } | ||
| 6527 | |||
| 6528 | sub sendRemoteCmd { | ||
| 6529 | |||
| 6530 | # Sends a remote world command to the chat contact's world | ||
| 6531 | # | ||
| 6532 | # Expected arguments | ||
| 6533 | # $argString - The text typed, minus the initial command sigil (if any) and the initial | ||
| 6534 | # chat command (if any) | ||
| 6535 | # | ||
| 6536 | # Return values | ||
| 6537 | # 'undef' on improper arguments, if the connection has not been negotiated yet or if | ||
| 6538 | # called in a MudMaster session | ||
| 6539 | # 1 otherwise | ||
| 6540 | |||
| 6541 | my ($self, $argString, $check) = @_; | ||
| 6542 | |||
| 6543 | # Check for improper arguments | ||
| 6544 | if (! defined $argString || defined $check) { | ||
| 6545 | |||
| 6546 | return $axmud::CLIENT->writeImproper($self->_objClass . '->sendRemoteCmd', @_); | ||
| 6547 | } | ||
| 6548 | |||
| 6549 | # Don't comply if the connection hasn't been negotiated yet | ||
| 6550 | if (! $self->remoteName) { | ||
| 6551 | |||
| 6552 | return $self->refuseOpCode($self->ivShow('constOptHash', 'SEND_COMMAND')); | ||
| 6553 | } | ||
| 6554 | |||
| 6555 | # The user must specify a command to send | ||
| 6556 | if (! $argString) { | ||
| 6557 | |||
| 6558 | return $self->writeImproper(); | ||
| 6559 | } | ||
| 6560 | |||
| 6561 | if ($self->chatType == $self->ivShow('constOptHash', 'MM')) { | ||
| 6562 | |||
| 6563 | $self->writeText( | ||
| 6564 | 'Only the zChat protocol supports remote commands.', | ||
| 6565 | 'system', | ||
| 6566 | ); | ||
| 6567 | |||
| 6568 | return undef; | ||
| 6569 | |||
| 6570 | # Don't do anything if $argString is empty (we don't want to send a null command) | ||
| 6571 | } elsif ($argString) { | ||
| 6572 | |||
| 6573 | $self->sendCmd( | ||
| 6574 | $self->ivShow('constOptHash', 'SEND_COMMAND'), | ||
| 6575 | $argString, | ||
| 6576 | ); | ||
| 6577 | |||
| 6578 | $self->writeText( | ||
| 6579 | 'Send remote command: ' . $argString, | ||
| 6580 | 'system', | ||
| 6581 | ); | ||
| 6582 | } | ||
| 6583 | |||
| 6584 | return 1; | ||
| 6585 | } | ||
| 6586 | |||
| 6587 | sub sendFile { | ||
| 6588 | |||
| 6589 | # Sends a file to the chat contact | ||
| 6590 | # | ||
| 6591 | # Expected arguments | ||
| 6592 | # $argString - The text typed, minus the initial command sigil (if any) and the initial | ||
| 6593 | # chat command (if any) | ||
| 6594 | # | ||
| 6595 | # Return values | ||
| 6596 | # 'undef' on improper arguments, if the connection hasn't been negotiated yet, if a file | ||
| 6597 | # transfer is already in progress, if the user cancels when prompted to choose a file | ||
| 6598 | # or if a filehandle for the file can't be opened (presumably because it doesn't | ||
| 6599 | # exist) | ||
| 6600 | # 1 otherwise | ||
| 6601 | |||
| 6602 | my ($self, $argString, $check) = @_; | ||
| 6603 | |||
| 6604 | # Local variables | ||
| 6605 | my ($result, $file, $baseFileName); | ||
| 6606 | |||
| 6607 | # Check for improper arguments | ||
| 6608 | if (! defined $argString || defined $check) { | ||
| 6609 | |||
| 6610 | return $axmud::CLIENT->writeImproper($self->_objClass . '->sendFile', @_); | ||
| 6611 | } | ||
| 6612 | |||
| 6613 | # Don't comply if the connection hasn't been negotiated yet | ||
| 6614 | if (! $self->remoteName) { | ||
| 6615 | |||
| 6616 | return $self->refuseOpCode($self->ivShow('constOptHash', 'FILE_START')); | ||
| 6617 | } | ||
| 6618 | |||
| 6619 | if ($self->fileDir) { | ||
| 6620 | |||
| 6621 | $self->writeText( | ||
| 6622 | 'A file transfer is already in progress.', | ||
| 6623 | 'system', | ||
| 6624 | ); | ||
| 6625 | |||
| 6626 | return undef; | ||
| 6627 | } | ||
| 6628 | |||
| 6629 | # If the user didn't specify a file to send, prompt them to choose one | ||
| 6630 | if (! $argString) { | ||
| 6631 | |||
| 6632 | if ($self->winObj && ! $self->tableObj) { | ||
| 6633 | |||
| 6634 | $file = $self->winObj->showFileChooser( | ||
| 6635 | 'Select file', | ||
| 6636 | 'open', | ||
| 6637 | ); | ||
| 6638 | |||
| 6639 | } else { | ||
| 6640 | |||
| 6641 | $file = $self->session->mainWin->showFileChooser( | ||
| 6642 | 'Select file', | ||
| 6643 | 'open', | ||
| 6644 | ); | ||
| 6645 | } | ||
| 6646 | |||
| 6647 | if (! $file) { | ||
| 6648 | |||
| 6649 | # User cancelled | ||
| 6650 | return undef; | ||
| 6651 | } | ||
| 6652 | |||
| 6653 | } else { | ||
| 6654 | |||
| 6655 | # The user specified a file to get | ||
| 6656 | $file = $argString; | ||
| 6657 | } | ||
| 6658 | |||
| 6659 | # Try to open the filehandle | ||
| 6660 | if(! open($self->{fileHandle}, $file)) { | ||
| 6661 | |||
| 6662 | $self->writeText( | ||
| 6663 | 'Could not open \'' . $file . '\': ' . $!, | ||
| 6664 | 'system', | ||
| 6665 | ); | ||
| 6666 | |||
| 6667 | return undef; | ||
| 6668 | } | ||
| 6669 | |||
| 6670 | # Prepare to send the file | ||
| 6671 | $self->ivPoke('fileName', $file); | ||
| 6672 | $self->ivPoke('fileDir', $self->ivShow('constOptHash', 'SENDING')); | ||
| 6673 | $self->ivPoke('fileTotalSize', -s $file); | ||
| 6674 | $self->ivPoke('fileSize', 0); | ||
| 6675 | |||
| 6676 | # Extract the file name from the path | ||
| 6677 | if ($file =~ m{.*/([^/]+)$}) { | ||
| 6678 | $baseFileName = $1; | ||
| 6679 | } else { | ||
| 6680 | $baseFileName = $file; | ||
| 6681 | } | ||
| 6682 | |||
| 6683 | $self->sendCmd( | ||
| 6684 | $self->ivShow('constOptHash', 'FILE_START'), | ||
| 6685 | $baseFileName . ',' . $self->fileTotalSize, | ||
| 6686 | ); | ||
| 6687 | |||
| 6688 | $self->writeText( | ||
| 6689 | 'Sending file \'' . $file . '\' to ' . $self->remoteName, | ||
| 6690 | 'system', | ||
| 6691 | ); | ||
| 6692 | |||
| 6693 | return 1; | ||
| 6694 | } | ||
| 6695 | |||
| 6696 | sub stopFile { | ||
| 6697 | |||
| 6698 | # Stops a file transfer | ||
| 6699 | # | ||
| 6700 | # Expected arguments | ||
| 6701 | # $argString - The text typed, minus the initial command sigil (if any) and the initial | ||
| 6702 | # chat command (if any) | ||
| 6703 | # | ||
| 6704 | # Return values | ||
| 6705 | # 'undef' on improper arguments or if no file is being transferred | ||
| 6706 | # 1 otherwise | ||
| 6707 | |||
| 6708 | my ($self, $argString, $check) = @_; | ||
| 6709 | |||
| 6710 | # Check for improper arguments | ||
| 6711 | if (! defined $argString || defined $check) { | ||
| 6712 | |||
| 6713 | return $axmud::CLIENT->writeImproper($self->_objClass . '->stopFile', @_); | ||
| 6714 | } | ||
| 6715 | |||
| 6716 | # There should not be any arguments to the chat command itself | ||
| 6717 | if ($argString) { | ||
| 6718 | |||
| 6719 | return $self->writeImproper(); | ||
| 6720 | } | ||
| 6721 | |||
| 6722 | if (! $self->fileDir) { | ||
| 6723 | |||
| 6724 | $self->writeText( | ||
| 6725 | 'No file is being transferred.', | ||
| 6726 | 'system', | ||
| 6727 | ); | ||
| 6728 | |||
| 6729 | return undef; | ||
| 6730 | |||
| 6731 | } else { | ||
| 6732 | |||
| 6733 | $self->sendCmd( | ||
| 6734 | $self->ivShow('constOptHash', 'FILE_CANCEL'), | ||
| 6735 | '', | ||
| 6736 | ); | ||
| 6737 | |||
| 6738 | $self->fileStop('Transfer of file \'' . $self->fileName . '\' aborted.'); | ||
| 6739 | |||
| 6740 | return 1; | ||
| 6741 | } | ||
| 6742 | } | ||
| 6743 | |||
| 6744 | sub acceptSnoop { | ||
| 6745 | |||
| 6746 | # Allows the chat contact to snoop on our session | ||
| 6747 | # | ||
| 6748 | # Expected arguments | ||
| 6749 | # $argString - The text typed, minus the initial command sigil (if any) and the initial | ||
| 6750 | # chat command (if any) | ||
| 6751 | # | ||
| 6752 | # Return values | ||
| 6753 | # 'undef' on improper arguments | ||
| 6754 | # 1 otherwise | ||
| 6755 | |||
| 6756 | my ($self, $argString, $check) = @_; | ||
| 6757 | |||
| 6758 | # Check for improper arguments | ||
| 6759 | if (! defined $argString || defined $check) { | ||
| 6760 | |||
| 6761 | return $axmud::CLIENT->writeImproper($self->_objClass . '->acceptSnoop', @_); | ||
| 6762 | } | ||
| 6763 | |||
| 6764 | # There should not be any arguments to the chat command itself | ||
| 6765 | if ($argString) { | ||
| 6766 | |||
| 6767 | return $self->writeImproper(); | ||
| 6768 | } | ||
| 6769 | |||
| 6770 | $self->ivPoke('allowSnoopFlag', TRUE); | ||
| 6771 | |||
| 6772 | $self->sendCmd( | ||
| 6773 | $self->ivShow('constOptHash', 'MESSAGE'), | ||
| 6774 | 'You can now snoop on ' . $self->localName, | ||
| 6775 | ); | ||
| 6776 | |||
| 6777 | $self->writeText( | ||
| 6778 | 'Snooping of this session is now allowed.', | ||
| 6779 | 'system', | ||
| 6780 | ); | ||
| 6781 | |||
| 6782 | return 1; | ||
| 6783 | } | ||
| 6784 | |||
| 6785 | sub refuseSnoop { | ||
| 6786 | |||
| 6787 | # Allows the chat contact to snoop on our session | ||
| 6788 | # | ||
| 6789 | # Expected arguments | ||
| 6790 | # $argString - The text typed, minus the initial command sigil (if any) and the initial | ||
| 6791 | # chat command (if any) | ||
| 6792 | # | ||
| 6793 | # Return values | ||
| 6794 | # 'undef' on improper arguments or if no file is being transferred | ||
| 6795 | # 1 otherwise | ||
| 6796 | |||
| 6797 | my ($self, $argString, $check) = @_; | ||
| 6798 | |||
| 6799 | # Check for improper arguments | ||
| 6800 | if (! defined $argString || defined $check) { | ||
| 6801 | |||
| 6802 | return $axmud::CLIENT->writeImproper($self->_objClass . '->refuseSnoop', @_); | ||
| 6803 | } | ||
| 6804 | |||
| 6805 | # There should not be any arguments to the chat command itself | ||
| 6806 | if ($argString) { | ||
| 6807 | |||
| 6808 | return $self->writeImproper(); | ||
| 6809 | } | ||
| 6810 | |||
| 6811 | $self->ivPoke('allowSnoopFlag', FALSE); | ||
| 6812 | |||
| 6813 | $self->sendCmd( | ||
| 6814 | $self->ivShow('constOptHash', 'MESSAGE'), | ||
| 6815 | 'You can no longer snoop on ' . $self->localName, | ||
| 6816 | ); | ||
| 6817 | |||
| 6818 | $self->writeText( | ||
| 6819 | 'Snooping of this session is now forbidden.', | ||
| 6820 | 'system', | ||
| 6821 | ); | ||
| 6822 | |||
| 6823 | $self->stopSnooped(); | ||
| 6824 | |||
| 6825 | return 1; | ||
| 6826 | } | ||
| 6827 | |||
| 6828 | sub requestSnoop { | ||
| 6829 | |||
| 6830 | # Tries to start snooping the chat contact | ||
| 6831 | # | ||
| 6832 | # Expected arguments | ||
| 6833 | # $argString - The text typed, minus the initial command sigil (if any) and the initial | ||
| 6834 | # chat command (if any) | ||
| 6835 | # | ||
| 6836 | # Return values | ||
| 6837 | # 'undef' on improper arguments, if the connection has not been negotiated yet or if using | ||
| 6838 | # the wrong chat protocol | ||
| 6839 | # 1 otherwise | ||
| 6840 | |||
| 6841 | my ($self, $argString, $check) = @_; | ||
| 6842 | |||
| 6843 | # Check for improper arguments | ||
| 6844 | if (! defined $argString || defined $check) { | ||
| 6845 | |||
| 6846 | return $axmud::CLIENT->writeImproper($self->_objClass . '->requestSnoop', @_); | ||
| 6847 | } | ||
| 6848 | |||
| 6849 | # Don't comply if the connection hasn't been negotiated yet | ||
| 6850 | if (! $self->remoteName) { | ||
| 6851 | |||
| 6852 | return $self->refuseOpCode($self->ivShow('constOptHash', 'SNOOP')); | ||
| 6853 | } | ||
| 6854 | |||
| 6855 | # There should not be any arguments to the chat command itself | ||
| 6856 | if ($argString) { | ||
| 6857 | |||
| 6858 | return $self->writeImproper(); | ||
| 6859 | } | ||
| 6860 | |||
| 6861 | $self->writeText( | ||
| 6862 | 'Asked to start/stop snooping on ' . $self->remoteName . '.', | ||
| 6863 | 'system', | ||
| 6864 | ); | ||
| 6865 | |||
| 6866 | $self->sendCmd( | ||
| 6867 | $self->ivShow('constOptHash', 'SNOOP'), | ||
| 6868 | '', | ||
| 6869 | ); | ||
| 6870 | |||
| 6871 | return 1; | ||
| 6872 | } | ||
| 6873 | |||
| 6874 | sub hangUp { | ||
| 6875 | |||
| 6876 | # Closes a chat connection | ||
| 6877 | # | ||
| 6878 | # Expected arguments | ||
| 6879 | # $argString - The text typed, minus the initial command sigil (if any) and the initial | ||
| 6880 | # chat command (if any) | ||
| 6881 | # | ||
| 6882 | # Return values | ||
| 6883 | # 'undef' on improper arguments or if there is no current chat session | ||
| 6884 | # 1 otherwise | ||
| 6885 | |||
| 6886 | my ($self, $argString, $check) = @_; | ||
| 6887 | |||
| 6888 | # Check for improper arguments | ||
| 6889 | if (! defined $argString || defined $check) { | ||
| 6890 | |||
| 6891 | return $axmud::CLIENT->writeImproper($self->_objClass . '->hangUp', @_); | ||
| 6892 | } | ||
| 6893 | |||
| 6894 | # (There should not be any arguments to the chat command itself, but we don't check them: | ||
| 6895 | # it's important to allow the user to hang up quickly, without fussing over their typing | ||
| 6896 | # skills) | ||
| 6897 | |||
| 6898 | # Don't hang up if there is no connection | ||
| 6899 | if (! $self->sessionFlag) { | ||
| 6900 | |||
| 6901 | # No connection made | ||
| 6902 | return undef; | ||
| 6903 | } | ||
| 6904 | |||
| 6905 | $self->terminateChatSession(); | ||
| 6906 | |||
| 6907 | $self->writeText( | ||
| 6908 | 'Chat session closed.', | ||
| 6909 | 'system', | ||
| 6910 | ); | ||
| 6911 | |||
| 6912 | return 1; | ||
| 6913 | } | ||
| 6914 | |||
| 6915 | sub setPublic { | ||
| 6916 | |||
| 6917 | # Set this chat connection as 'public' - visible to all chat contacts | ||
| 6918 | # | ||
| 6919 | # Expected arguments | ||
| 6920 | # $argString - The text typed, minus the initial command sigil (if any) and the initial | ||
| 6921 | # chat command (if any) | ||
| 6922 | # | ||
| 6923 | # Return values | ||
| 6924 | # 'undef' on improper arguments or if the connection is already marked as 'public' | ||
| 6925 | # 1 otherwise | ||
| 6926 | |||
| 6927 | my ($self, $argString, $check) = @_; | ||
| 6928 | |||
| 6929 | # Check for improper arguments | ||
| 6930 | if (! defined $argString || defined $check) { | ||
| 6931 | |||
| 6932 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setPublic', @_); | ||
| 6933 | } | ||
| 6934 | |||
| 6935 | # There should not be any arguments to the chat command itself | ||
| 6936 | if ($argString) { | ||
| 6937 | |||
| 6938 | return $self->writeImproper(); | ||
| 6939 | } | ||
| 6940 | |||
| 6941 | if ($self->publicConnectionFlag) { | ||
| 6942 | |||
| 6943 | $self->writeText( | ||
| 6944 | 'This connection is already set to \'public\'.', | ||
| 6945 | 'system', | ||
| 6946 | ); | ||
| 6947 | |||
| 6948 | return undef; | ||
| 6949 | |||
| 6950 | } else { | ||
| 6951 | |||
| 6952 | $self->ivPoke('publicConnectionFlag', TRUE); | ||
| 6953 | |||
| 6954 | $self->writeText( | ||
| 6955 | 'This connection is now set to \'public\'.', | ||
| 6956 | 'system', | ||
| 6957 | ); | ||
| 6958 | |||
| 6959 | $self->sendCmd( | ||
| 6960 | $self->ivShow('constOptHash', 'MESSAGE'), | ||
| 6961 | $self->localName . ' has marked this connection as \'public\'.', | ||
| 6962 | ); | ||
| 6963 | |||
| 6964 | return 1; | ||
| 6965 | } | ||
| 6966 | } | ||
| 6967 | |||
| 6968 | sub setPrivate { | ||
| 6969 | |||
| 6970 | # Set this chat connection as 'private' - not visible to all chat contacts (default) | ||
| 6971 | # | ||
| 6972 | # Expected arguments | ||
| 6973 | # $argString - The text typed, minus the initial command sigil (if any) and the initial | ||
| 6974 | # chat command (if any) | ||
| 6975 | # | ||
| 6976 | # Return values | ||
| 6977 | # 'undef' on improper arguments or if the connection is already marked as 'private' | ||
| 6978 | # 1 otherwise | ||
| 6979 | |||
| 6980 | my ($self, $argString, $check) = @_; | ||
| 6981 | |||
| 6982 | # Check for improper arguments | ||
| 6983 | if (! defined $argString || defined $check) { | ||
| 6984 | |||
| 6985 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setPrivate', @_); | ||
| 6986 | } | ||
| 6987 | |||
| 6988 | # There should not be any arguments to the chat command itself | ||
| 6989 | if ($argString) { | ||
| 6990 | |||
| 6991 | return $self->writeImproper(); | ||
| 6992 | } | ||
| 6993 | |||
| 6994 | if (! $self->publicConnectionFlag) { | ||
| 6995 | |||
| 6996 | $self->writeText( | ||
| 6997 | 'This connection is already set to \'private\'.', | ||
| 6998 | 'system', | ||
| 6999 | ); | ||
| 7000 | |||
| 7001 | return undef; | ||
| 7002 | |||
| 7003 | } else { | ||
| 7004 | |||
| 7005 | $self->ivPoke('publicConnectionFlag', FALSE); | ||
| 7006 | |||
| 7007 | $self->writeText( | ||
| 7008 | 'This connection is now set to \'private\'.', | ||
| 7009 | 'system', | ||
| 7010 | ); | ||
| 7011 | |||
| 7012 | $self->sendCmd( | ||
| 7013 | $self->ivShow('constOptHash', 'MESSAGE'), | ||
| 7014 | $self->localName . ' has marked this connection as \'private\'.', | ||
| 7015 | ); | ||
| 7016 | |||
| 7017 | return 1; | ||
| 7018 | } | ||
| 7019 | } | ||
| 7020 | |||
| 7021 | sub peekRemoteConnections { | ||
| 7022 | |||
| 7023 | # Sends a request to the chat contact to send a list of all their public connections; when | ||
| 7024 | # the response is received, the list is displayed in the task window | ||
| 7025 | # | ||
| 7026 | # Expected arguments | ||
| 7027 | # $argString - The text typed, minus the initial command sigil (if any) and the initial | ||
| 7028 | # chat command (if any) | ||
| 7029 | # | ||
| 7030 | # Return values | ||
| 7031 | # 'undef' on improper arguments | ||
| 7032 | # 1 otherwise | ||
| 7033 | |||
| 7034 | my ($self, $argString, $check) = @_; | ||
| 7035 | |||
| 7036 | # Check for improper arguments | ||
| 7037 | if (! defined $argString || defined $check) { | ||
| 7038 | |||
| 7039 | return $axmud::CLIENT->writeImproper($self->_objClass . '->peekRemoteConnections', @_); | ||
| 7040 | } | ||
| 7041 | |||
| 7042 | # There should not be any arguments to the chat command itself | ||
| 7043 | if ($argString) { | ||
| 7044 | |||
| 7045 | return $self->writeImproper(); | ||
| 7046 | } | ||
| 7047 | |||
| 7048 | $self->sendCmd( | ||
| 7049 | $self->ivShow('constOptHash', 'PEEK_CONNECTIONS'), | ||
| 7050 | '', | ||
| 7051 | ); | ||
| 7052 | |||
| 7053 | $self->writeText( | ||
| 7054 | 'A request has been sent to \'' . $self->remoteName . '\' for a list of their public' | ||
| 7055 | . ' connections.', | ||
| 7056 | 'system', | ||
| 7057 | ); | ||
| 7058 | |||
| 7059 | return 1; | ||
| 7060 | } | ||
| 7061 | |||
| 7062 | sub requestRemoteConnections { | ||
| 7063 | |||
| 7064 | # Sends a request to the chat contact to send a list of all their public connections; when | ||
| 7065 | # the response is received, this Chat task then attemps to connect to any of them who | ||
| 7066 | # aren't already connected to us | ||
| 7067 | # | ||
| 7068 | # Expected arguments | ||
| 7069 | # $argString - The text typed, minus the initial command sigil (if any) and the initial | ||
| 7070 | # chat command (if any) | ||
| 7071 | # | ||
| 7072 | # Return values | ||
| 7073 | # 'undef' on improper arguments | ||
| 7074 | # 1 otherwise | ||
| 7075 | |||
| 7076 | my ($self, $argString, $check) = @_; | ||
| 7077 | |||
| 7078 | # Check for improper arguments | ||
| 7079 | if (! defined $argString || defined $check) { | ||
| 7080 | |||
| 7081 | return $axmud::CLIENT->writeImproper( | ||
| 7082 | $self->_objClass . '->requestRemoteConnections', | ||
| 7083 | @_, | ||
| 7084 | ); | ||
| 7085 | } | ||
| 7086 | |||
| 7087 | # There should not be any arguments to the chat command itself | ||
| 7088 | if ($argString) { | ||
| 7089 | |||
| 7090 | return $self->writeImproper(); | ||
| 7091 | } | ||
| 7092 | |||
| 7093 | $self->sendCmd( | ||
| 7094 | $self->ivShow('constOptHash', 'REQUEST_CONNECTIONS'), | ||
| 7095 | '', | ||
| 7096 | ); | ||
| 7097 | |||
| 7098 | $self->writeText( | ||
| 7099 | 'A request has been sent to \'' . $self->remoteName . '\' for a list of their public' | ||
| 7100 | . ' connections.', | ||
| 7101 | 'system', | ||
| 7102 | ); | ||
| 7103 | |||
| 7104 | return 1; | ||
| 7105 | } | ||
| 7106 | |||
| 7107 | sub setServing { | ||
| 7108 | |||
| 7109 | # Set this chat connection as 'serving' - echoes CHAT_TEXT_EVERYBODY to all other sessions, | ||
| 7110 | # and CHAT_TEXT_GROUP messages to all other chat sessions in the same group | ||
| 7111 | # | ||
| 7112 | # Expected arguments | ||
| 7113 | # $argString - The text typed, minus the initial command sigil (if any) and the initial | ||
| 7114 | # chat command (if any) | ||
| 7115 | # | ||
| 7116 | # Return values | ||
| 7117 | # 'undef' on improper arguments or if the connection is already marked as 'serving' | ||
| 7118 | # 1 otherwise | ||
| 7119 | |||
| 7120 | my ($self, $argString, $check) = @_; | ||
| 7121 | |||
| 7122 | # Check for improper arguments | ||
| 7123 | if (! defined $argString || defined $check) { | ||
| 7124 | |||
| 7125 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setServing', @_); | ||
| 7126 | } | ||
| 7127 | |||
| 7128 | # There should not be any arguments to the chat command itself | ||
| 7129 | if ($argString) { | ||
| 7130 | |||
| 7131 | return $self->writeImproper(); | ||
| 7132 | } | ||
| 7133 | |||
| 7134 | if ($self->servingFlag) { | ||
| 7135 | |||
| 7136 | $self->writeText( | ||
| 7137 | 'This connection is already set to \'serving\'.', | ||
| 7138 | 'system', | ||
| 7139 | ); | ||
| 7140 | |||
| 7141 | return undef; | ||
| 7142 | |||
| 7143 | } else { | ||
| 7144 | |||
| 7145 | $self->ivPoke('servingFlag', TRUE); | ||
| 7146 | |||
| 7147 | $self->writeText( | ||
| 7148 | 'This connection is now set to \'serving\'.', | ||
| 7149 | 'system', | ||
| 7150 | ); | ||
| 7151 | |||
| 7152 | $self->sendCmd( | ||
| 7153 | $self->ivShow('constOptHash', 'MESSAGE'), | ||
| 7154 | $self->localName . ' has marked this connection as \'serving\'.', | ||
| 7155 | ); | ||
| 7156 | |||
| 7157 | return 1; | ||
| 7158 | } | ||
| 7159 | } | ||
| 7160 | |||
| 7161 | sub setNotServing { | ||
| 7162 | |||
| 7163 | # Set this chat connection as 'not serving' - no longer echoes CHAT_TEXT_EVERYBODY and | ||
| 7164 | # CHAT_TEXT_GROUP to other chat sessions | ||
| 7165 | # | ||
| 7166 | # Expected arguments | ||
| 7167 | # $argString - The text typed, minus the initial command sigil (if any) and the initial | ||
| 7168 | # chat command (if any) | ||
| 7169 | # | ||
| 7170 | # Return values | ||
| 7171 | # 'undef' on improper arguments or if the connection is already marked as 'not serving' | ||
| 7172 | # 1 otherwise | ||
| 7173 | |||
| 7174 | my ($self, $argString, $check) = @_; | ||
| 7175 | |||
| 7176 | # Check for improper arguments | ||
| 7177 | if (! defined $argString || defined $check) { | ||
| 7178 | |||
| 7179 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setNotServing', @_); | ||
| 7180 | } | ||
| 7181 | |||
| 7182 | # There should not be any arguments to the chat command itself | ||
| 7183 | if ($argString) { | ||
| 7184 | |||
| 7185 | return $self->writeImproper(); | ||
| 7186 | } | ||
| 7187 | |||
| 7188 | if (! $self->servingFlag) { | ||
| 7189 | |||
| 7190 | $self->writeText( | ||
| 7191 | 'This connection is already set to \'not serving\'.', | ||
| 7192 | 'system', | ||
| 7193 | ); | ||
| 7194 | |||
| 7195 | return undef; | ||
| 7196 | |||
| 7197 | } else { | ||
| 7198 | |||
| 7199 | $self->ivPoke('servingFlag', FALSE); | ||
| 7200 | |||
| 7201 | $self->writeText( | ||
| 7202 | 'This connection is now set to \'not serving\'.', | ||
| 7203 | 'system', | ||
| 7204 | ); | ||
| 7205 | |||
| 7206 | $self->sendCmd( | ||
| 7207 | $self->ivShow('constOptHash', 'MESSAGE'), | ||
| 7208 | $self->localName . ' has marked this connection as \'not serving\'.', | ||
| 7209 | ); | ||
| 7210 | |||
| 7211 | return 1; | ||
| 7212 | } | ||
| 7213 | } | ||
| 7214 | |||
| 7215 | sub showInfo { | ||
| 7216 | |||
| 7217 | # Shows information about the current connection | ||
| 7218 | # | ||
| 7219 | # Expected arguments | ||
| 7220 | # $argString - The text typed, minus the initial command sigil (if any) and the initial | ||
| 7221 | # chat command (if any) | ||
| 7222 | # | ||
| 7223 | # Return values | ||
| 7224 | # 'undef' on improper arguments or if there is no current chat session | ||
| 7225 | # 1 otherwise | ||
| 7226 | |||
| 7227 | my ($self, $argString, $check) = @_; | ||
| 7228 | |||
| 7229 | # Local variables | ||
| 7230 | my ( | ||
| 7231 | $header, $line, $type, $public, $serving, $version, $group, $email, $allowSmiley, | ||
| 7232 | $canSnoop, $isSnoop, $bytes, $cmd, $status, | ||
| 7233 | ); | ||
| 7234 | |||
| 7235 | # Check for improper arguments | ||
| 7236 | if (! defined $argString || defined $check) { | ||
| 7237 | |||
| 7238 | return $axmud::CLIENT->writeImproper($self->_objClass . '->showInfo', @_); | ||
| 7239 | } | ||
| 7240 | |||
| 7241 | # There should not be any arguments to the chat command itself | ||
| 7242 | if ($argString) { | ||
| 7243 | |||
| 7244 | return $self->writeImproper(); | ||
| 7245 | } | ||
| 7246 | |||
| 7247 | # Set a flag, just for this function, which causes ->writeText to display everything in the | ||
| 7248 | # colour for local system messages | ||
| 7249 | $self->ivPoke('allSystemColourFlag', TRUE); | ||
| 7250 | |||
| 7251 | if ($self->remoteName) { | ||
| 7252 | $header = 'Chat session with ' . $self->remoteName; | ||
| 7253 | } else { | ||
| 7254 | $header = 'Chat session'; | ||
| 7255 | } | ||
| 7256 | $self->writeText($header); | ||
| 7257 | $line .= '-' x length($header); | ||
| 7258 | $self->writeText($line); | ||
| 7259 | |||
| 7260 | $self->writeText('Your IP : ' . $self->ip); | ||
| 7261 | $self->writeText('Incoming IP : ' . $self->clientSocket->peerhost()); | ||
| 7262 | $self->writeText('IP advertised as : ' . $self->remoteIP); | ||
| 7263 | $self->writeText('Port advertised as : ' . $self->remotePort); | ||
| 7264 | |||
| 7265 | if ($self->chatType == $self->ivShow('constOptHash', 'MM')) { | ||
| 7266 | $type = 'MudMaster'; | ||
| 7267 | } else { | ||
| 7268 | $type = 'zChat'; | ||
| 7269 | } | ||
| 7270 | $self->writeText('Chat protocol : ' . $type); | ||
| 7271 | |||
| 7272 | if ($self->publicConnectionFlag) { | ||
| 7273 | $public = 'Public'; | ||
| 7274 | } else { | ||
| 7275 | $public = 'Private'; | ||
| 7276 | } | ||
| 7277 | $self->writeText('Privacy : ' . $public); | ||
| 7278 | |||
| 7279 | if ($self->servingFlag) { | ||
| 7280 | $serving = 'Yes'; | ||
| 7281 | } else { | ||
| 7282 | $serving = 'No'; | ||
| 7283 | } | ||
| 7284 | $self->writeText('Serving messages : ' . $serving); | ||
| 7285 | |||
| 7286 | if ($self->localGroup) { | ||
| 7287 | $group = $self->localGroup; | ||
| 7288 | } else { | ||
| 7289 | $group = '<none>'; | ||
| 7290 | } | ||
| 7291 | $self->writeText('Group : ' . $group); | ||
| 7292 | |||
| 7293 | if ($self->chatType != $self->ivShow('constOptHash', 'MM')) { | ||
| 7294 | |||
| 7295 | if ($self->allowRemoteCmdFlag) { | ||
| 7296 | $cmd = 'Allowed'; | ||
| 7297 | } else { | ||
| 7298 | $cmd = 'Not allowed'; | ||
| 7299 | } | ||
| 7300 | $self->writeText('Remote commands : ' . $cmd); | ||
| 7301 | |||
| 7302 | if ($self->localStatus == 0) { | ||
| 7303 | $status = '0 (no status)'; | ||
| 7304 | } elsif ($self->localStatus == 1) { | ||
| 7305 | $status = '1 (normal)'; | ||
| 7306 | } elsif ($self->localStatus == 2) { | ||
| 7307 | $status = '2 (inactive)'; | ||
| 7308 | } elsif ($self->localStatus == 3) { | ||
| 7309 | $status = '3 (away from keys)'; | ||
| 7310 | } | ||
| 7311 | $self->writeText('zChat status : ' . $status); | ||
| 7312 | |||
| 7313 | if ($self->remoteStatus == 0) { | ||
| 7314 | $status = '0 (no status)'; | ||
| 7315 | } elsif ($self->remoteStatus == 1) { | ||
| 7316 | $status = '1 (normal)'; | ||
| 7317 | } elsif ($self->remoteStatus == 2) { | ||
| 7318 | $status = '2 (inactive)'; | ||
| 7319 | } elsif ($self->remoteStatus == 3) { | ||
| 7320 | $status = '3 (away from keys)'; | ||
| 7321 | } | ||
| 7322 | $self->writeText('Remote status : ' . $status); | ||
| 7323 | } | ||
| 7324 | |||
| 7325 | if ($self->remoteVersion) { | ||
| 7326 | $version = $self->remoteVersion; | ||
| 7327 | } else { | ||
| 7328 | $version = '<unknown>'; | ||
| 7329 | } | ||
| 7330 | $self->writeText('Remote version : ' . $version); | ||
| 7331 | |||
| 7332 | if ($self->localEmail) { | ||
| 7333 | $email = $self->localEmail; | ||
| 7334 | } else { | ||
| 7335 | $email = '<not set>'; | ||
| 7336 | } | ||
| 7337 | $self->writeText('Local email : ' . $email); | ||
| 7338 | |||
| 7339 | if ($self->remoteEmail) { | ||
| 7340 | $email = $self->remoteEmail; | ||
| 7341 | } else { | ||
| 7342 | $email = '<unknown>'; | ||
| 7343 | } | ||
| 7344 | $self->writeText('Remote email : ' . $email); | ||
| 7345 | |||
| 7346 | if ($self->allowSmileyFlag) { | ||
| 7347 | $allowSmiley = 'on'; | ||
| 7348 | } else { | ||
| 7349 | $allowSmiley = 'off'; | ||
| 7350 | } | ||
| 7351 | $self->writeText('Smileys on : ' . $allowSmiley); | ||
| 7352 | |||
| 7353 | if ($self->allowSnoopFlag) { | ||
| 7354 | $canSnoop = 'yes'; | ||
| 7355 | } else { | ||
| 7356 | $canSnoop = 'no'; | ||
| 7357 | } | ||
| 7358 | $self->writeText('Peer can snoop : ' . $canSnoop); | ||
| 7359 | |||
| 7360 | if ($self->isSnoopedFlag) { | ||
| 7361 | $isSnoop = 'yes'; | ||
| 7362 | } else { | ||
| 7363 | $isSnoop = 'no'; | ||
| 7364 | } | ||
| 7365 | $self->writeText('Peer is snooping : ' . $isSnoop); | ||
| 7366 | |||
| 7367 | if ($self->fileDir) { | ||
| 7368 | |||
| 7369 | if ($self->fileDir == $self->ivShow('constOptHash', 'SENDING')) { | ||
| 7370 | $self->writeText('Sending file : ' . $self->fileName); | ||
| 7371 | } else { | ||
| 7372 | $self->writeText('Receiving file : ' . $self->fileName); | ||
| 7373 | } | ||
| 7374 | |||
| 7375 | $self->writeText('File size : ' . $self->fileTotalSize); | ||
| 7376 | $self->writeText('Bytes transferred : ' . $self->fileSize); | ||
| 7377 | |||
| 7378 | $bytes = $self->fileTotalSize - $self->fileSize; | ||
| 7379 | $self->writeText( | ||
| 7380 | 'Bytes left : ' . $bytes . ' (' | ||
| 7381 | . sprintf("%.0f", 100 * ($bytes/$self->fileTotalSize)) . '%)' | ||
| 7382 | ); | ||
| 7383 | } | ||
| 7384 | |||
| 7385 | # Stop displaying everything in the local system colour | ||
| 7386 | $self->ivPoke('allSystemColourFlag', FALSE); | ||
| 7387 | |||
| 7388 | return 1; | ||
| 7389 | } | ||
| 7390 | |||
| 7391 | sub setIcon { | ||
| 7392 | |||
| 7393 | # Sets the icon for this chat session | ||
| 7394 | # | ||
| 7395 | # Expected arguments | ||
| 7396 | # $argString - The text typed, minus the initial command sigil (if any) and the initial | ||
| 7397 | # chat command (if any) | ||
| 7398 | # | ||
| 7399 | # Return values | ||
| 7400 | # 'undef' on improper arguments, if called in a MudMaster session, if the user cancels | ||
| 7401 | # when prompted to choose an icon or if the selected file isn't in Window bitmap | ||
| 7402 | # (.bmp) format | ||
| 7403 | # 1 otherwise | ||
| 7404 | |||
| 7405 | my ($self, $argString, $check) = @_; | ||
| 7406 | |||
| 7407 | # Local variables | ||
| 7408 | my ($file, $fileHandle, $data); | ||
| 7409 | |||
| 7410 | # Check for improper arguments | ||
| 7411 | if (! defined $argString || defined $check) { | ||
| 7412 | |||
| 7413 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setIcon', @_); | ||
| 7414 | } | ||
| 7415 | |||
| 7416 | if ($self->chatType != $self->ivShow('constOptHash', 'ZCHAT')) { | ||
| 7417 | |||
| 7418 | $self->writeText( | ||
| 7419 | 'Only the zChat protocol supports icons.', | ||
| 7420 | 'system', | ||
| 7421 | ); | ||
| 7422 | |||
| 7423 | return undef; | ||
| 7424 | } | ||
| 7425 | |||
| 7426 | # If the user didn't specify an icon file, prompt them to choose one | ||
| 7427 | if (! $argString) { | ||
| 7428 | |||
| 7429 | if ($self->winObj && ! $self->tableObj) { | ||
| 7430 | |||
| 7431 | $file = $self->winObj->showFileChooser( | ||
| 7432 | 'Select an icon file (must be .bmp)', | ||
| 7433 | 'open', | ||
| 7434 | ); | ||
| 7435 | |||
| 7436 | } else { | ||
| 7437 | |||
| 7438 | $file = $self->session->mainWin->showFileChooser( | ||
| 7439 | 'Select an icon file (must be .bmp)', | ||
| 7440 | 'open', | ||
| 7441 | ); | ||
| 7442 | } | ||
| 7443 | |||
| 7444 | if (! $file) { | ||
| 7445 | |||
| 7446 | # User cancelled | ||
| 7447 | return undef; | ||
| 7448 | } | ||
| 7449 | |||
| 7450 | } else { | ||
| 7451 | |||
| 7452 | # The user specified a file to get | ||
| 7453 | $file = $argString; | ||
| 7454 | } | ||
| 7455 | |||
| 7456 | # File must be in .bmp format | ||
| 7457 | if (substr($file, -4) ne '.bmp') { | ||
| 7458 | |||
| 7459 | $self->writeText( | ||
| 7460 | 'Icons must be Windows .bmp files', | ||
| 7461 | 'system', | ||
| 7462 | ); | ||
| 7463 | |||
| 7464 | return undef; | ||
| 7465 | } | ||
| 7466 | |||
| 7467 | # Send the icon to the chat contact with an 'ICON' instruction | ||
| 7468 | $self->prepareIcon($file); | ||
| 7469 | |||
| 7470 | $self->writeText( | ||
| 7471 | 'Using icon \'' . $file . '\'', | ||
| 7472 | 'system', | ||
| 7473 | ); | ||
| 7474 | |||
| 7475 | return 1; | ||
| 7476 | } | ||
| 7477 | |||
| 7478 | sub setEmail { | ||
| 7479 | |||
| 7480 | # Sets the email address to broadcast for this chat session | ||
| 7481 | # | ||
| 7482 | # Expected arguments | ||
| 7483 | # $argString - The text typed, minus the initial command sigil (if any) and the initial | ||
| 7484 | # chat command (if any) | ||
| 7485 | # | ||
| 7486 | # Return values | ||
| 7487 | # 'undef' on improper arguments or if an invalid email is specified | ||
| 7488 | # 1 otherwise | ||
| 7489 | |||
| 7490 | my ($self, $argString, $check) = @_; | ||
| 7491 | |||
| 7492 | # Check for improper arguments | ||
| 7493 | if (! defined $argString || defined $check) { | ||
| 7494 | |||
| 7495 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setEmail', @_); | ||
| 7496 | } | ||
| 7497 | |||
| 7498 | # If no email specified, don't broadcast one | ||
| 7499 | if (! $argString) { | ||
| 7500 | |||
| 7501 | $self->ivUndef('localEmail'); | ||
| 7502 | |||
| 7503 | $self->sendCmd( | ||
| 7504 | $self->ivShow('constOptHash', 'EMAIL'), | ||
| 7505 | '<none>', | ||
| 7506 | ); | ||
| 7507 | |||
| 7508 | $self->writeText( | ||
| 7509 | 'Stopped broadcasting your email', | ||
| 7510 | 'system', | ||
| 7511 | ); | ||
| 7512 | |||
| 7513 | return 1; | ||
| 7514 | } | ||
| 7515 | |||
| 7516 | # Email must be no more than 128 characters, and contain an @ | ||
| 7517 | if (length $argString < 3 || length $argString > 128 || index($argString, '@') == -1) { | ||
| 7518 | |||
| 7519 | $self->writeText( | ||
| 7520 | 'Invalid chat email address (must be between 3 and 128 characters (and contain an' | ||
| 7521 | . ' \'@\' character)', | ||
| 7522 | 'system', | ||
| 7523 | ); | ||
| 7524 | |||
| 7525 | return undef; | ||
| 7526 | |||
| 7527 | } else { | ||
| 7528 | |||
| 7529 | $self->ivPoke('localEmail', $argString); | ||
| 7530 | |||
| 7531 | $self->sendCmd( | ||
| 7532 | $self->ivShow('constOptHash', 'EMAIL'), | ||
| 7533 | $self->localEmail, | ||
| 7534 | ); | ||
| 7535 | |||
| 7536 | $self->writeText( | ||
| 7537 | 'Changed your email to \'' . $self->localEmail . '\'', | ||
| 7538 | 'system', | ||
| 7539 | ); | ||
| 7540 | |||
| 7541 | return 1; | ||
| 7542 | } | ||
| 7543 | } | ||
| 7544 | |||
| 7545 | sub setSmiley { | ||
| 7546 | |||
| 7547 | # Turns smileys on/off for this chat session | ||
| 7548 | # | ||
| 7549 | # Expected arguments | ||
| 7550 | # $argString - The text typed, minus the initial command sigil (if any) and the initial | ||
| 7551 | # chat command (if any) | ||
| 7552 | # | ||
| 7553 | # Return values | ||
| 7554 | # 'undef' on improper arguments or if an invalid email is specified | ||
| 7555 | # 1 otherwise | ||
| 7556 | |||
| 7557 | my ($self, $argString, $check) = @_; | ||
| 7558 | |||
| 7559 | # Check for improper arguments | ||
| 7560 | if (! defined $argString || defined $check) { | ||
| 7561 | |||
| 7562 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setSmiley', @_); | ||
| 7563 | } | ||
| 7564 | |||
| 7565 | # If 'on' or 'off' not specified, just show the current setting | ||
| 7566 | if (! $argString || ($argString ne 'on' && $argString ne 'off')) { | ||
| 7567 | |||
| 7568 | if ($self->allowSmileyFlag) { | ||
| 7569 | |||
| 7570 | $self->writeText( | ||
| 7571 | 'Smileys turned on for this chat session (try \';smiley off\')', | ||
| 7572 | 'system', | ||
| 7573 | ); | ||
| 7574 | |||
| 7575 | return 1; | ||
| 7576 | |||
| 7577 | } else { | ||
| 7578 | |||
| 7579 | $self->writeText( | ||
| 7580 | 'Smileys turned off for this chat session (try \';smiley on\')', | ||
| 7581 | 'system', | ||
| 7582 | ); | ||
| 7583 | |||
| 7584 | return 1; | ||
| 7585 | } | ||
| 7586 | |||
| 7587 | } elsif ($argString eq 'on') { | ||
| 7588 | |||
| 7589 | if ($self->allowSmileyFlag) { | ||
| 7590 | |||
| 7591 | $self->writeText( | ||
| 7592 | 'Smileys already turned on for this chat session', | ||
| 7593 | 'system', | ||
| 7594 | ); | ||
| 7595 | |||
| 7596 | return 1; | ||
| 7597 | |||
| 7598 | } else { | ||
| 7599 | |||
| 7600 | $self->ivPoke('allowSmileyFlag', TRUE); | ||
| 7601 | |||
| 7602 | $self->writeText( | ||
| 7603 | 'Smileys now turned on for this chat session', | ||
| 7604 | 'system', | ||
| 7605 | ); | ||
| 7606 | |||
| 7607 | return 1; | ||
| 7608 | } | ||
| 7609 | |||
| 7610 | } else { | ||
| 7611 | |||
| 7612 | if (! $self->allowSmileyFlag) { | ||
| 7613 | |||
| 7614 | $self->writeText( | ||
| 7615 | 'Smileys already turned off for this chat session', | ||
| 7616 | 'system', | ||
| 7617 | ); | ||
| 7618 | |||
| 7619 | return 1; | ||
| 7620 | |||
| 7621 | } else { | ||
| 7622 | |||
| 7623 | $self->ivPoke('allowSmileyFlag', FALSE); | ||
| 7624 | |||
| 7625 | $self->writeText( | ||
| 7626 | 'Smileys now turned off for this chat session', | ||
| 7627 | 'system', | ||
| 7628 | ); | ||
| 7629 | |||
| 7630 | return 1; | ||
| 7631 | } | ||
| 7632 | } | ||
| 7633 | } | ||
| 7634 | |||
| 7635 | sub winHelp { | ||
| 7636 | |||
| 7637 | # Displays a list of Chat task commands in the task window | ||
| 7638 | # | ||
| 7639 | # Expected arguments | ||
| 7640 | # $argString - The text typed, minus the initial command sigil (if any) and the initial | ||
| 7641 | # chat command (if any) | ||
| 7642 | # | ||
| 7643 | # Return values | ||
| 7644 | # 'undef' on improper arguments | ||
| 7645 | # 1 otherwise | ||
| 7646 | |||
| 7647 | my ($self, $argString, $check) = @_; | ||
| 7648 | |||
| 7649 | # Check for improper arguments | ||
| 7650 | if (! defined $argString || defined $check) { | ||
| 7651 | |||
| 7652 | return $axmud::CLIENT->writeImproper($self->_objClass . '->winHelp', @_); | ||
| 7653 | } | ||
| 7654 | |||
| 7655 | # (There should not be any arguments to the chat command itself, but we don't check them: | ||
| 7656 | # it's important to allow the user to read help, without fussing over their typing skills) | ||
| 7657 | if ($self->taskWinFlag) { | ||
| 7658 | |||
| 7659 | foreach my $string ($self->helpList) { | ||
| 7660 | |||
| 7661 | $self->writeText($string, 'system'); | ||
| 7662 | } | ||
| 7663 | } | ||
| 7664 | |||
| 7665 | return 1; | ||
| 7666 | } | ||
| 7667 | |||
| 7668 | sub saveContact { | ||
| 7669 | |||
| 7670 | # Saves the chat contact in our contacts list or, if we're talking to someone already in the | ||
| 7671 | # contact list, updates their info | ||
| 7672 | # NB A contact's icon is automatically updated as soon as it is received by ->processIcon | ||
| 7673 | # | ||
| 7674 | # Expected arguments | ||
| 7675 | # $argString - The text typed, minus the initial command sigil (if any) and the initial | ||
| 7676 | # chat command (if any) | ||
| 7677 | # | ||
| 7678 | # Return values | ||
| 7679 | # 'undef' on improper arguments or if the chat contact can't be saved in our contacts list | ||
| 7680 | # 1 otherwise | ||
| 7681 | |||
| 7682 | my ($self, $argString, $check) = @_; | ||
| 7683 | |||
| 7684 | # Local variables | ||
| 7685 | my ($contactObj, $updateFlag, $tempFile, $fileHandle); | ||
| 7686 | |||
| 7687 | # Check for improper arguments | ||
| 7688 | if (! defined $argString || defined $check) { | ||
| 7689 | |||
| 7690 | return $axmud::CLIENT->writeImproper($self->_objClass . '->saveContact', @_); | ||
| 7691 | } | ||
| 7692 | |||
| 7693 | if ($argString) { | ||
| 7694 | |||
| 7695 | # Does this contact already exist? | ||
| 7696 | if ($axmud::CLIENT->ivExists('chatContactHash', $argString)) { | ||
| 7697 | |||
| 7698 | # Use it | ||
| 7699 | $contactObj = $axmud::CLIENT->ivShow('chatContactHash', $argString); | ||
| 7700 | $updateFlag = TRUE; | ||
| 7701 | |||
| 7702 | # If not, create a new GA::Obj::ChatContact | ||
| 7703 | } else { | ||
| 7704 | |||
| 7705 | $contactObj = Games::Axmud::Obj::ChatContact->new( | ||
| 7706 | $self->session, | ||
| 7707 | $argString, | ||
| 7708 | $self->chatType, | ||
| 7709 | ); | ||
| 7710 | |||
| 7711 | if (! $contactObj) { | ||
| 7712 | |||
| 7713 | $self->writeText( | ||
| 7714 | 'Failed to save the chat contact.', | ||
| 7715 | 'system', | ||
| 7716 | ); | ||
| 7717 | |||
| 7718 | return undef; | ||
| 7719 | } | ||
| 7720 | } | ||
| 7721 | |||
| 7722 | } else { | ||
| 7723 | |||
| 7724 | if (! $self->chatContactObj) { | ||
| 7725 | |||
| 7726 | # User typed ';save' but needs to type ';save <contact>' | ||
| 7727 | $self->writeText( | ||
| 7728 | 'This chat contact not yet saved (try \';save <contact>\').', | ||
| 7729 | 'system', | ||
| 7730 | ); | ||
| 7731 | |||
| 7732 | return undef; | ||
| 7733 | |||
| 7734 | } else { | ||
| 7735 | |||
| 7736 | # Use the existing contact | ||
| 7737 | $contactObj = $self->chatContactObj; | ||
| 7738 | $updateFlag = TRUE; | ||
| 7739 | } | ||
| 7740 | } | ||
| 7741 | |||
| 7742 | # Update (or set for the first time) the contact's IVs (NB we don't set ->protocol; the | ||
| 7743 | # default chat protocol is for the user to decide manually) | ||
| 7744 | $contactObj->ivPoke('ip', $self->remoteIP); | ||
| 7745 | $contactObj->ivPoke('port', $self->remotePort); | ||
| 7746 | $contactObj->ivPoke('email', $self->remoteEmail); | ||
| 7747 | # If the chat contact hasn't sent an icon, don't write over the default icon already stored | ||
| 7748 | # in the GA::Obj::ChatContact | ||
| 7749 | if ($self->remoteIcon) { | ||
| 7750 | |||
| 7751 | $contactObj->ivPoke('lastIcon', $self->remoteIcon); | ||
| 7752 | $contactObj->ivPoke('lastIconScaled', $self->remoteIconScaled); | ||
| 7753 | } | ||
| 7754 | |||
| 7755 | # Operation complete | ||
| 7756 | $self->ivPoke('chatContactObj', $contactObj); | ||
| 7757 | |||
| 7758 | if ($updateFlag) { | ||
| 7759 | |||
| 7760 | $self->writeText( | ||
| 7761 | 'Contact \'' . $contactObj->name . '\' updated.', | ||
| 7762 | 'system', | ||
| 7763 | ); | ||
| 7764 | |||
| 7765 | } else { | ||
| 7766 | |||
| 7767 | $self->writeText( | ||
| 7768 | 'New contact \'' . $contactObj->name . '\' created.', | ||
| 7769 | 'system', | ||
| 7770 | ); | ||
| 7771 | } | ||
| 7772 | |||
| 7773 | return 1; | ||
| 7774 | } | ||
| 7775 | |||
| 7776 | sub setMode { | ||
| 7777 | |||
| 7778 | # Set $self->entryMode, which specifies what happens when the user types raw text (i.e. text | ||
| 7779 | # not beginning with the sigils ; or #) | ||
| 7780 | # | ||
| 7781 | # Expected arguments | ||
| 7782 | # $argString - The text typed, minus the initial command sigil (if any) and the initial | ||
| 7783 | # chat command (if any) | ||
| 7784 | # | ||
| 7785 | # Return values | ||
| 7786 | # 'undef' on improper arguments, if the user specifies an invalid mode or if 'cmd' mode | ||
| 7787 | # is specified, but this isn't a zChat session | ||
| 7788 | # 1 otherwise | ||
| 7789 | |||
| 7790 | my ($self, $argString, $check) = @_; | ||
| 7791 | |||
| 7792 | # Check for improper arguments | ||
| 7793 | if (! defined $argString || defined $check) { | ||
| 7794 | |||
| 7795 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setMode', @_); | ||
| 7796 | } | ||
| 7797 | |||
| 7798 | # The user must specify a mode | ||
| 7799 | if (! $argString) { | ||
| 7800 | |||
| 7801 | return $self->writeImproper(); | ||
| 7802 | } | ||
| 7803 | |||
| 7804 | if ($argString eq 'chat') { | ||
| 7805 | |||
| 7806 | $self->ivPoke('entryMode', 'chat'); | ||
| 7807 | |||
| 7808 | $self->writeText( | ||
| 7809 | 'Typed text will now be treated as chat.', | ||
| 7810 | 'system', | ||
| 7811 | ); | ||
| 7812 | |||
| 7813 | return 1; | ||
| 7814 | |||
| 7815 | } elsif ($argString eq 'emote') { | ||
| 7816 | |||
| 7817 | $self->ivPoke('entryMode', 'emote'); | ||
| 7818 | |||
| 7819 | $self->writeText( | ||
| 7820 | 'Typed text will now be treated as an emote.', | ||
| 7821 | 'system', | ||
| 7822 | ); | ||
| 7823 | |||
| 7824 | return 1; | ||
| 7825 | |||
| 7826 | } elsif ($argString eq 'cmd') { | ||
| 7827 | |||
| 7828 | if ($self->chatType != $self->ivShow('constOptHash', 'ZCHAT')) { | ||
| 7829 | |||
| 7830 | $self->writeText( | ||
| 7831 | 'Only the zChat protocol supports remote commands.', | ||
| 7832 | 'system', | ||
| 7833 | ); | ||
| 7834 | |||
| 7835 | return undef; | ||
| 7836 | |||
| 7837 | } else { | ||
| 7838 | |||
| 7839 | $self->ivPoke('entryMode', 'cmd'); | ||
| 7840 | |||
| 7841 | $self->writeText( | ||
| 7842 | 'Typed text will now be sent as a remote command.', | ||
| 7843 | 'system', | ||
| 7844 | ); | ||
| 7845 | } | ||
| 7846 | |||
| 7847 | } else { | ||
| 7848 | |||
| 7849 | $self->writeText( | ||
| 7850 | 'Valid modes are \'chat\', \'emote\' and \'cmd\'.', | ||
| 7851 | 'system', | ||
| 7852 | ); | ||
| 7853 | |||
| 7854 | return undef; | ||
| 7855 | } | ||
| 7856 | } | ||
| 7857 | |||
| 7858 | # Supplementary functions | ||
| 7859 | |||
| 7860 | sub requestConnection { | ||
| 7861 | |||
| 7862 | # Called by $self->mcall and $self->zcall | ||
| 7863 | # Makes an outgoing chat call of the specified type | ||
| 7864 | # | ||
| 7865 | # Expected arguments | ||
| 7866 | # $ip - The IP address to contact | ||
| 7867 | # $port - The port | ||
| 7868 | # $type - Which chat protocol to use, a value in $self->constOptHash matching the key | ||
| 7869 | # 'ZCHAT' or 'MM' | ||
| 7870 | # | ||
| 7871 | # Return values | ||
| 7872 | # 'undef' on improper arguments or if the connection can't be made | ||
| 7873 | # 1 otherwise | ||
| 7874 | |||
| 7875 | my ($self, $ip, $port, $type, $check) = @_; | ||
| 7876 | |||
| 7877 | # Local variables | ||
| 7878 | my ($socket, $request, $localName, $listenPort); | ||
| 7879 | |||
| 7880 | # Check for improper arguments | ||
| 7881 | if (! defined $ip || ! defined $port || ! defined $type || defined $check) { | ||
| 7882 | |||
| 7883 | return $axmud::CLIENT->writeImproper($self->_objClass . '->requestConnection', @_); | ||
| 7884 | } | ||
| 7885 | |||
| 7886 | # Open a new socket (filehandle) | ||
| 7887 | $socket = IO::Socket::INET->new( | ||
| 7888 | 'PeerAddr' => $ip, | ||
| 7889 | 'PeerPort' => $port, | ||
| 7890 | 'Proto' => 'tcp', | ||
| 7891 | 'Timeout' => $self->outgoingTimeout, # Default 10 seconds | ||
| 7892 | ); | ||
| 7893 | |||
| 7894 | if (! defined $socket) { | ||
| 7895 | |||
| 7896 | return $self->writeError( | ||
| 7897 | $self->prettyName . ' task could not connect to ' . $ip . ', port ' . $port, | ||
| 7898 | $self->_objClass . '->requestConnection' | ||
| 7899 | ); | ||
| 7900 | } | ||
| 7901 | |||
| 7902 | # Set IVs at the start of the chat session | ||
| 7903 | $self->ivPoke('sessionFlag', TRUE); | ||
| 7904 | $self->ivPoke('clientSocket', $socket); | ||
| 7905 | $self->ivPoke('chatType', $type); | ||
| 7906 | $self->ivPoke('remoteIP', $ip); | ||
| 7907 | $self->ivPoke('remotePort', $port); | ||
| 7908 | $self->ivPoke('localGroup', ''); | ||
| 7909 | $self->ivPoke('encoding', $self->defaultEncoding); | ||
| 7910 | |||
| 7911 | # Respond to a Glib::IO event to process the response to our connection request by calling | ||
| 7912 | # $self->callEstablishmentData() | ||
| 7913 | $self->ivPoke( | ||
| 7914 | 'ioWatchID', | ||
| 7915 | Glib::IO->add_watch( | ||
| 7916 | $socket->fileno, | ||
| 7917 | 'in', | ||
| 7918 | sub { $self->callEstablishmentData(@_); }, | ||
| 7919 | ), | ||
| 7920 | ); | ||
| 7921 | |||
| 7922 | # Respond to a Glib::Timeout event to abandon a pending connection after 60 seconds (by | ||
| 7923 | # default) by calling $self->killPendingConnection(). The call to Glib::Timeout->add | ||
| 7924 | # must convert the value to milliseconds | ||
| 7925 | $self->ivPoke( | ||
| 7926 | 'timeoutID', | ||
| 7927 | Glib::Timeout->add( | ||
| 7928 | ($self->incomingTimeout * 1000), # Default value is 60 seconds | ||
| 7929 | sub { $self->killPendingConnection(); }, | ||
| 7930 | ), | ||
| 7931 | ); | ||
| 7932 | |||
| 7933 | # Open a task window | ||
| 7934 | $self->newChatWin(); | ||
| 7935 | $self->writeText( | ||
| 7936 | 'Calling ' . $ip . ' on port ' . $port . '...', | ||
| 7937 | 'system', | ||
| 7938 | ); | ||
| 7939 | |||
| 7940 | # Decide which port is advertised to the chat peer as the one we're using for incoming | ||
| 7941 | # connections | ||
| 7942 | # If $self->port is defined, use it. Otherwise, tell the chat peer that we're listening on | ||
| 7943 | # the default port - even though the port is closed | ||
| 7944 | if ($self->port) { | ||
| 7945 | $listenPort = $self->port; | ||
| 7946 | } else { | ||
| 7947 | $listenPort = $axmud::CLIENT->constChatPort; | ||
| 7948 | } | ||
| 7949 | |||
| 7950 | # Set the chat name to use. Use the value stored in GA::Client, if it's been set; otherwise | ||
| 7951 | # use the current character | ||
| 7952 | if ($axmud::CLIENT->chatName) { | ||
| 7953 | |||
| 7954 | $self->ivPoke('localName', $axmud::CLIENT->chatName); | ||
| 7955 | |||
| 7956 | } elsif ($self->session->currentChar) { | ||
| 7957 | |||
| 7958 | $self->ivPoke('localName', ucfirst($self->session->currentChar->name)); | ||
| 7959 | |||
| 7960 | } else { | ||
| 7961 | |||
| 7962 | # Emergency failsafe - 'Axmud user' | ||
| 7963 | $self->ivPoke('localName', $axmud::SCRIPT . ' user'); | ||
| 7964 | } | ||
| 7965 | |||
| 7966 | # Set the email to broadcast. Use the value stored in GA::Client, if it's been set; | ||
| 7967 | # otherwise don't broadcast an email. (NB The email is only broadcast in zChat sessions.) | ||
| 7968 | if ($axmud::CLIENT->chatEmail) { | ||
| 7969 | |||
| 7970 | $self->ivPoke('localEmail', $axmud::CLIENT->chatEmail); | ||
| 7971 | } | ||
| 7972 | |||
| 7973 | # Request a connection from the chat peer | ||
| 7974 | $localName = $self->localName; | ||
| 7975 | if ($type == $self->ivShow('constOptHash', 'MM')) { | ||
| 7976 | |||
| 7977 | # (Quoted from http://tintin.sourceforge.io/manual/chatprotocol.php) | ||
| 7978 | # Once a connection is made the caller sends a connection string which looks like: | ||
| 7979 | # "CHAT:<chat name>\n<ip address><port>". | ||
| 7980 | # The sprintf syntax is: | ||
| 7981 | # "CHAT:%s\n%s%-5u" | ||
| 7982 | # The port must be 5 characters, padded on the right side with spaces. Once this string | ||
| 7983 | # has been sent it waits for a response from the other side. If a "NO" is received the | ||
| 7984 | # call is cancelled. If the call was accepted the string "YES:<chat name>\n" is | ||
| 7985 | # received. | ||
| 7986 | $request = sprintf( | ||
| 7987 | "CHAT:$localName\n" # CHAT:<chat name>\n | ||
| 7988 | . "%s" # <ip address> | ||
| 7989 | . "%-5s", # <port> | ||
| 7990 | $self->ip, | ||
| 7991 | $listenPort, | ||
| 7992 | ); | ||
| 7993 | |||
| 7994 | } else { | ||
| 7995 | |||
| 7996 | # (Quoted from http://www.zuggsoft.com/zchat/zchatprot.htm) | ||
| 7997 | # Send the following data through a normal TCP/IP packet. The TCP/IP packet contains the | ||
| 7998 | # IP address and Port number of the Server being called. The data in the connection | ||
| 7999 | # request packet is: | ||
| 8000 | # ZCHAT:<ChatName>\t<ChatID>\lf<ClientIPAddress><ClientPort>\lf<SecurityInfo> | ||
| 8001 | # The ClientPort is formatted as a five-digit number with leading zeros. The sprintf | ||
| 8002 | # syntax is: | ||
| 8003 | # "ZCHAT:%s\t%s\n%s%-5u\n%s". | ||
| 8004 | # Optional information can be included in the connection request by adding another \lf | ||
| 8005 | # after the SecurityInfo and then sending the optional data. | ||
| 8006 | # | ||
| 8007 | # NB <ChatID> is a unique number generated when zMUD users register their product. | ||
| 8008 | # Earlier versions of zMUD's chat facility did not support this, sending a zero | ||
| 8009 | # instead; so shall we | ||
| 8010 | $request = sprintf( | ||
| 8011 | "ZCHAT:$localName\t" # ZCHAT:<ChatName>\t | ||
| 8012 | . "0\n" # <ChatID>\lf | ||
| 8013 | . "%s" # <ClientIPAddress> | ||
| 8014 | . "%05u", # <ClientPort> | ||
| 8015 | $self->ip, | ||
| 8016 | $listenPort, | ||
| 8017 | ); | ||
| 8018 | } | ||
| 8019 | |||
| 8020 | syswrite($socket, $request); | ||
| 8021 | |||
| 8022 | return 1; | ||
| 8023 | } | ||
| 8024 | |||
| 8025 | sub acceptConnection { | ||
| 8026 | |||
| 8027 | # Called in response to a Glib::IO event when we receive a connection request from a chat | ||
| 8028 | # contact | ||
| 8029 | # $socket->accept() won't block because the connection because it is only called when there | ||
| 8030 | # is an incoming connection (because of the IO watch) | ||
| 8031 | # | ||
| 8032 | # Expected arguments | ||
| 8033 | # $fileNo, $condition | ||
| 8034 | # - Arguments supplied by the Glib::IO event (not required by this function) | ||
| 8035 | # - $fileNo is the file descriptor, $self->acceptSocket->fileno | ||
| 8036 | # - $condition is the Glib::IOCondition, namely 'in' / 'G_IO_IN' | ||
| 8037 | # $socket - The socket used; matches the socket stored in the lead Chat task's | ||
| 8038 | # ->acceptSocket IV | ||
| 8039 | # | ||
| 8040 | # Return values | ||
| 8041 | # 'undef' on improper arguments | ||
| 8042 | # 1 otherwise | ||
| 8043 | |||
| 8044 | my ($self, $fileNo, $condition, $socket, $check) = @_; | ||
| 8045 | |||
| 8046 | # Local variables | ||
| 8047 | my ($clientSocket, $newTaskObj); | ||
| 8048 | |||
| 8049 | # Check for improper arguments | ||
| 8050 | if (! defined $fileNo || ! defined $condition || ! defined $socket || defined $check) { | ||
| 8051 | |||
| 8052 | return $axmud::CLIENT->writeImproper($self->_objClass . '->acceptConnection', @_); | ||
| 8053 | } | ||
| 8054 | |||
| 8055 | # Accept the connection, creating a new socket to handle it | ||
| 8056 | $clientSocket = $socket->accept(); | ||
| 8057 | |||
| 8058 | if (! $self->sessionFlag) { | ||
| 8059 | |||
| 8060 | # This (lead) Chat task has no connection, so use it for the incoming connection | ||
| 8061 | |||
| 8062 | # Set IVs at the start of the chat session | ||
| 8063 | $self->ivPoke('connectionClosedFlag', FALSE); | ||
| 8064 | $self->ivPoke('sessionFlag', TRUE); | ||
| 8065 | $self->ivPoke('clientSocket', $clientSocket); | ||
| 8066 | $self->ivPoke('localGroup', ''); | ||
| 8067 | $self->ivPoke('encoding', $self->defaultEncoding); | ||
| 8068 | |||
| 8069 | # Respond to a Glib::IO event to process incoming connection requests by calling | ||
| 8070 | # $self->receiveEstablishmentData() | ||
| 8071 | $self->ivPoke( | ||
| 8072 | 'ioWatchID', | ||
| 8073 | Glib::IO->add_watch( | ||
| 8074 | $clientSocket->fileno, | ||
| 8075 | 'in', | ||
| 8076 | sub { $self->receiveEstablishmentData(@_); }, | ||
| 8077 | ), | ||
| 8078 | ); | ||
| 8079 | |||
| 8080 | # Respond to a Glib::Timeout event to abandon a pending connection after 60 seconds | ||
| 8081 | # (by default) by calling $self->killPendingConnection(). The call to | ||
| 8082 | # Glib::Timeout->add must convert the value to milliseconds | ||
| 8083 | $self->ivPoke( | ||
| 8084 | 'timeoutID', | ||
| 8085 | Glib::Timeout->add( | ||
| 8086 | ($self->incomingTimeout * 1000), # Default value is 60 seconds | ||
| 8087 | sub { $self->killPendingConnection(); }, | ||
| 8088 | ), | ||
| 8089 | ); | ||
| 8090 | |||
| 8091 | } else { | ||
| 8092 | |||
| 8093 | # This Chat task already has a connection, so we need to create a new Chat task to | ||
| 8094 | # handle it | ||
| 8095 | $newTaskObj = Games::Axmud::Task::Chat->new($self->session, 'current'); | ||
| 8096 | if ($newTaskObj) { | ||
| 8097 | |||
| 8098 | # Tell the task to handle an incoming call | ||
| 8099 | $newTaskObj->ivPoke('receiveCallOnInitFlag', TRUE); | ||
| 8100 | $newTaskObj->ivPoke('receiveCallOnInitSocket', $clientSocket); | ||
| 8101 | } | ||
| 8102 | } | ||
| 8103 | |||
| 8104 | return 1; | ||
| 8105 | } | ||
| 8106 | |||
| 8107 | sub receiveConnection { | ||
| 8108 | |||
| 8109 | # Called by $self->init, after the lead Chat task (which already has its own connection) | ||
| 8110 | # receives another incoming call, which it passes to this task | ||
| 8111 | # | ||
| 8112 | # Expected arguments | ||
| 8113 | # $clientSocket - The socket (filehandle) of the incoming connection | ||
| 8114 | # | ||
| 8115 | # Return values | ||
| 8116 | # 'undef' on improper arguments | ||
| 8117 | # 1 otherwise | ||
| 8118 | |||
| 8119 | my ($self, $clientSocket, $check) = @_; | ||
| 8120 | |||
| 8121 | # Check for improper arguments | ||
| 8122 | if (! defined $clientSocket || defined $check) { | ||
| 8123 | |||
| 8124 | return $axmud::CLIENT->writeImproper($self->_objClass . '->receiveConnection', @_); | ||
| 8125 | } | ||
| 8126 | |||
| 8127 | # Set IVs at the start of the chat session | ||
| 8128 | $self->ivPoke('sessionFlag', TRUE); | ||
| 8129 | $self->ivPoke('clientSocket', $clientSocket); | ||
| 8130 | $self->ivPoke('localGroup', ''); | ||
| 8131 | $self->ivPoke('encoding', $self->defaultEncoding); | ||
| 8132 | |||
| 8133 | # Respond to a Glib::IO event to process incoming connection requests by calling | ||
| 8134 | # $self->receiveEstablishmentData() | ||
| 8135 | $self->ivPoke( | ||
| 8136 | 'ioWatchID', | ||
| 8137 | Glib::IO->add_watch( | ||
| 8138 | $clientSocket->fileno, | ||
| 8139 | 'in', | ||
| 8140 | sub { $self->receiveEstablishmentData(@_); }, | ||
| 8141 | ), | ||
| 8142 | ); | ||
| 8143 | |||
| 8144 | # Respond to a Glib::Timeout event to abandon a pending connection after 60 seconds | ||
| 8145 | # (by default) by calling $self->killPendingConnection(). The call to Glib::Timeout->add | ||
| 8146 | # must convert the value to milliseconds | ||
| 8147 | $self->ivPoke( | ||
| 8148 | 'timeoutID', | ||
| 8149 | Glib::Timeout->add( | ||
| 8150 | ($self->incomingTimeout * 1000), # Default value is 60 seconds | ||
| 8151 | sub { $self->killPendingConnection(); }, | ||
| 8152 | ), | ||
| 8153 | ); | ||
| 8154 | |||
| 8155 | return 1; | ||
| 8156 | } | ||
| 8157 | |||
| 8158 | sub callEstablishmentData { | ||
| 8159 | |||
| 8160 | # Called by $self->acceptConnection when data is ready in a chat socket for which no | ||
| 8161 | # connection has been established, when we are making the call | ||
| 8162 | # | ||
| 8163 | # Expected arguments | ||
| 8164 | # $fileNo, $condition | ||
| 8165 | # - Arguments supplied by the Glib::IO event (not required by this function) | ||
| 8166 | # - $fileNo is the file descriptor, $self->clientSocket->fileno | ||
| 8167 | # - $condition is the Glib::IOCondition, namely 'in' / 'G_IO_IN' | ||
| 8168 | # | ||
| 8169 | # Return values | ||
| 8170 | # 'undef' on improper arguments, if the connection is established or if it fails to be | ||
| 8171 | # established | ||
| 8172 | # 1 if we're still waiting | ||
| 8173 | |||
| 8174 | my ($self, $fileNo, $condition, $check) = @_; | ||
| 8175 | |||
| 8176 | # Local variables | ||
| 8177 | my ($tempBuffer, $bytesRead); | ||
| 8178 | |||
| 8179 | # Check for improper arguments | ||
| 8180 | if (! defined $fileNo || ! defined $condition || defined $check) { | ||
| 8181 | |||
| 8182 | return $axmud::CLIENT->writeImproper($self->_objClass . '->callEstablishmentData', @_); | ||
| 8183 | } | ||
| 8184 | |||
| 8185 | # Read 1024 bytes of data into $tempBuffer from the filehandle $self->clientSocket | ||
| 8186 | $bytesRead = sysread($self->clientSocket, $tempBuffer, 1024); | ||
| 8187 | |||
| 8188 | if ( | ||
| 8189 | ! defined $bytesRead # There was an error | ||
| 8190 | || $bytesRead <= 0 # End of file | ||
| 8191 | ) { | ||
| 8192 | $self->terminateChatSession(); | ||
| 8193 | |||
| 8194 | $self->writeText( | ||
| 8195 | 'Chat session closed.', | ||
| 8196 | 'system', | ||
| 8197 | ); | ||
| 8198 | |||
| 8199 | return undef; | ||
| 8200 | } | ||
| 8201 | |||
| 8202 | # Add the incoming data to the buffer | ||
| 8203 | $self->{dataBuffer} .= $tempBuffer; | ||
| 8204 | |||
| 8205 | # Process the incoming data, which is the same for both MudMaster and zChat | ||
| 8206 | # MudMaster (http://tintin.sourceforge.io/manual/chatprotocol.php): | ||
| 8207 | # If a "NO" is received the call is cancelled. If the call was accepted the string | ||
| 8208 | # "YES:<chat name>\n" is received. | ||
| 8209 | # zChat (http://www.zuggsoft.com/zchat/zchatprot.htm) | ||
| 8210 | # If the Server is not accepting connections or if the security tests fail, or if the | ||
| 8211 | # Server wants to reject the request for any other reason, it sends a TCP/IP packet | ||
| 8212 | # back to the client with the data: NO | ||
| 8213 | while (1) { | ||
| 8214 | |||
| 8215 | my ($nlPos, $result); | ||
| 8216 | |||
| 8217 | # Find the end-of-line, whose presence tells us that we've received the whole response | ||
| 8218 | # to our chat request | ||
| 8219 | $nlPos = index($self->dataBuffer, "\n"); | ||
| 8220 | if ($nlPos == -1) { | ||
| 8221 | |||
| 8222 | # Wait for the whole response | ||
| 8223 | return 1; | ||
| 8224 | } | ||
| 8225 | |||
| 8226 | if ($self->dataBuffer =~ /^YES:(.*)/) { | ||
| 8227 | |||
| 8228 | # Extract the chat peer's nickname | ||
| 8229 | $self->changeRemoteName($1, 1); | ||
| 8230 | substr($self->{dataBuffer}, 0, $nlPos + 1) = ''; | ||
| 8231 | |||
| 8232 | # As soon as the connection is negotiated, the server and the client exchange | ||
| 8233 | # information about each other by sending commands | ||
| 8234 | $self->sendCmd( | ||
| 8235 | $self->ivShow('constOptHash', 'VERSION'), | ||
| 8236 | $self->getVersion(), | ||
| 8237 | ); | ||
| 8238 | |||
| 8239 | if ($self->chatType == $self->ivShow('constOptHash', 'ZCHAT')) { | ||
| 8240 | |||
| 8241 | # Our initial status is 1 ('Normal status') unless the user has been idle for | ||
| 8242 | # a minimum time, in which case it is 3 ('AFK') | ||
| 8243 | $self->ivPoke('localStatus', 1); | ||
| 8244 | $self->sendCmd( | ||
| 8245 | $self->ivShow('constOptHash', 'STATUS'), | ||
| 8246 | chr(1), | ||
| 8247 | ); | ||
| 8248 | |||
| 8249 | # Send the icon to the chat contact with an 'ICON' instruction | ||
| 8250 | if (-e $axmud::CLIENT->chatIcon) { | ||
| 8251 | |||
| 8252 | $self->prepareIcon($axmud::CLIENT->chatIcon); | ||
| 8253 | } | ||
| 8254 | |||
| 8255 | if ($self->localEmail) { | ||
| 8256 | |||
| 8257 | $self->sendCmd( | ||
| 8258 | $self->ivShow('constOptHash', 'EMAIL'), | ||
| 8259 | $self->localEmail, | ||
| 8260 | ); | ||
| 8261 | } | ||
| 8262 | |||
| 8263 | $self->sendCmd( | ||
| 8264 | $self->ivShow('constOptHash', 'STAMP'), | ||
| 8265 | pack("L", $self->localZChatStamp), | ||
| 8266 | ); | ||
| 8267 | } | ||
| 8268 | |||
| 8269 | # Respond to a Glib::IO event to process incoming data from the chat peer by calling | ||
| 8270 | # $self->mmChatDataReady() or $self->zChatDataReady | ||
| 8271 | # (This replaces the callback used to call this function) | ||
| 8272 | $self->ivPoke( | ||
| 8273 | 'ioWatchID', | ||
| 8274 | Glib::IO->add_watch( | ||
| 8275 | $self->clientSocket->fileno, | ||
| 8276 | 'in', | ||
| 8277 | $self->chatType == $self->ivShow('constOptHash', 'MM') | ||
| 8278 | ? sub { $self->mmChatDataReady(@_); } | ||
| 8279 | : sub { $self->zChatDataReady(@_); }, | ||
| 8280 | ), | ||
| 8281 | ); | ||
| 8282 | |||
| 8283 | # Now that the connection is established, remove the pending connection timeout | ||
| 8284 | Glib::Source->remove($self->timeoutID); | ||
| 8285 | |||
| 8286 | $self->writeText( | ||
| 8287 | 'Chat session to ' . $self->remoteName . ' at ' . $self->remoteIP . ' port ' | ||
| 8288 | . $self->remotePort . ' established.', | ||
| 8289 | 'system', | ||
| 8290 | ); | ||
| 8291 | |||
| 8292 | return undef; | ||
| 8293 | |||
| 8294 | } elsif ($self->dataBuffer =~ /^NO/) { | ||
| 8295 | |||
| 8296 | $self->writeError( | ||
| 8297 | '\'' . $self->prettyName . '\' task: remote party declined to chat', | ||
| 8298 | $self->_objClass . '->callEstablishmentData', | ||
| 8299 | ); | ||
| 8300 | |||
| 8301 | Glib::Source->remove($self->timeoutID); | ||
| 8302 | $self->terminateChatSession(); | ||
| 8303 | |||
| 8304 | return undef; | ||
| 8305 | |||
| 8306 | } else { | ||
| 8307 | |||
| 8308 | # Invalid reply. Ignore this line and wait for the next one. (If we're waiting too | ||
| 8309 | # long, the timeout stored in $self->timeoutID will close the connection anyway) | ||
| 8310 | substr($self->{dataBuffer}, 0, $nlPos + 1) = ''; | ||
| 8311 | |||
| 8312 | return 1; | ||
| 8313 | } | ||
| 8314 | } | ||
| 8315 | |||
| 8316 | # Continue processing | ||
| 8317 | return 1; | ||
| 8318 | } | ||
| 8319 | |||
| 8320 | sub receiveEstablishmentData { | ||
| 8321 | |||
| 8322 | # Called by $self->acceptConnection when data is ready in a chat socket for which no | ||
| 8323 | # connection has been established, when we are accepting an incoming call | ||
| 8324 | # | ||
| 8325 | # Expected arguments | ||
| 8326 | # $fileNo, $condition | ||
| 8327 | # - Arguments supplied by the Glib::IO event (not required by this function) | ||
| 8328 | # - $fileNo is the file descriptor, $self->clientSocket->fileno | ||
| 8329 | # - $condition is the Glib::IOCondition, namely 'in' / 'G_IO_IN' | ||
| 8330 | # | ||
| 8331 | # Return values | ||
| 8332 | # 'undef' on improper arguments, if the connection is established or if it fails to be | ||
| 8333 | # established | ||
| 8334 | # 1 if we're still waiting | ||
| 8335 | |||
| 8336 | my ($self, $fileNo, $condition, $check) = @_; | ||
| 8337 | |||
| 8338 | # Local variables | ||
| 8339 | my ($tempBuffer, $bytesRead); | ||
| 8340 | |||
| 8341 | # Check for improper arguments | ||
| 8342 | if (! defined $fileNo || ! defined $condition || defined $check) { | ||
| 8343 | |||
| 8344 | return $axmud::CLIENT->writeImproper( | ||
| 8345 | $self->_objClass . '->receiveEstablishmentData', | ||
| 8346 | @_, | ||
| 8347 | ); | ||
| 8348 | } | ||
| 8349 | |||
| 8350 | # Read 1024 bytes of data into $tempBuffer from the filehandle $self->clientSocket | ||
| 8351 | $bytesRead = sysread($self->clientSocket, $tempBuffer, 1024); | ||
| 8352 | |||
| 8353 | if ( | ||
| 8354 | ! defined $bytesRead # There was an error | ||
| 8355 | || $bytesRead <= 0 # End of file | ||
| 8356 | ) { | ||
| 8357 | $self->terminateChatSession(); | ||
| 8358 | |||
| 8359 | $self->writeText( | ||
| 8360 | 'Chat session closed.', | ||
| 8361 | 'system', | ||
| 8362 | ); | ||
| 8363 | |||
| 8364 | return undef; | ||
| 8365 | } | ||
| 8366 | |||
| 8367 | # Add the incoming data to the buffer | ||
| 8368 | $self->{dataBuffer} .= $tempBuffer; | ||
| 8369 | |||
| 8370 | # Process the incoming header | ||
| 8371 | # | ||
| 8372 | # (Quoted from http://tintin.sourceforge.io/manual/chatprotocol.php) | ||
| 8373 | # Once a connection is made the caller sends a connection string which looks like: | ||
| 8374 | # "CHAT:<chat name>\n<ip address><port>". | ||
| 8375 | # The sprintf syntax is: | ||
| 8376 | # "CHAT:%s\n%s%-5u" | ||
| 8377 | # The port must be 5 characters, padded on the right side with spaces. | ||
| 8378 | # | ||
| 8379 | # (Quoted from http://www.zuggsoft.com/zchat/zchatprot.htm) | ||
| 8380 | # Send the following data through a normal TCP/IP packet. The TCP/IP packet contains the IP | ||
| 8381 | # address and Port number of the Server being called. The data in the connection request | ||
| 8382 | # packet is: | ||
| 8383 | # ZCHAT:<ChatName>\t<ChatID>\lf<ClientIPAddress><ClientPort>\lf<SecurityInfo> | ||
| 8384 | # The ClientPort is formatted as a five-digit number with leading zeros. The sprintf | ||
| 8385 | # syntax is: | ||
| 8386 | # "ZCHAT:%s\t%s\n%s%-5u\n%s". | ||
| 8387 | # Optional information can be included in the connection request by adding another \lf after | ||
| 8388 | # the SecurityInfo and then sending the optional data. | ||
| 8389 | # | ||
| 8390 | # NB <ChatID> is a unique number generated when zMUD users register their product. Earlier | ||
| 8391 | # versions of zMUD's chat facility did not support this, sending a zero instead; so shall | ||
| 8392 | # we | ||
| 8393 | while (1) { | ||
| 8394 | |||
| 8395 | my ( | ||
| 8396 | $nlPos, $nlPos2, $result, $addressString, $sessionContactObj, $msg, | ||
| 8397 | @matchList, | ||
| 8398 | ); | ||
| 8399 | |||
| 8400 | # Process everything up until the first newline character | ||
| 8401 | if (! defined $self->chatType) { | ||
| 8402 | |||
| 8403 | # Both the MudMaster and zChat headers contain a first newline characters | ||
| 8404 | $nlPos = index($self->dataBuffer, "\n"); | ||
| 8405 | if ($nlPos == -1) { | ||
| 8406 | |||
| 8407 | # Wait for the whole header | ||
| 8408 | return 1; | ||
| 8409 | } | ||
| 8410 | |||
| 8411 | if ($self->dataBuffer =~ /^CHAT:(.*)/) { | ||
| 8412 | |||
| 8413 | # It's a MudMaster header | ||
| 8414 | $self->ivPoke('chatType', $self->ivShow('constOptHash', 'MM')); | ||
| 8415 | $self->ivPoke('remoteName', $1); | ||
| 8416 | $self->ivPoke('remoteZChatID', 0); | ||
| 8417 | |||
| 8418 | # Remove everything up to and including the newline character | ||
| 8419 | substr($self->{dataBuffer}, 0, $nlPos + 1) = ''; | ||
| 8420 | |||
| 8421 | } elsif ($self->dataBuffer =~ /^ZCHAT:(.*)\t(.*)/) { | ||
| 8422 | |||
| 8423 | # It's a zChat header | ||
| 8424 | $self->ivPoke('chatType', $self->ivShow('constOptHash', 'ZCHAT')); | ||
| 8425 | $self->ivPoke('remoteName', $1); | ||
| 8426 | $self->ivPoke('remoteZChatID', $2); | ||
| 8427 | |||
| 8428 | # Remove everything up to and including the newline character | ||
| 8429 | substr($self->{dataBuffer}, 0, $nlPos + 1) = ''; | ||
| 8430 | |||
| 8431 | } else { | ||
| 8432 | |||
| 8433 | # Wrong header. Let's ignore this line and wait for another one | ||
| 8434 | substr($self->{dataBuffer}, 0, $nlPos + 1) = ''; | ||
| 8435 | } | ||
| 8436 | |||
| 8437 | # MM: Process the rest of the header | ||
| 8438 | # <ip address><port> | ||
| 8439 | # zChat: Process everything up until the second newline character | ||
| 8440 | # <ClientIPAddress><ClientPort>\lf<SecurityInfo> | ||
| 8441 | } else { | ||
| 8442 | |||
| 8443 | # Play a sound effect for incoming calls (if allowed) | ||
| 8444 | $axmud::CLIENT->playSound('call'); | ||
| 8445 | |||
| 8446 | # Check to see whether any of our contacts matches the incoming call | ||
| 8447 | foreach my $contactObj ($axmud::CLIENT->ivValues('chatContactHash')) { | ||
| 8448 | |||
| 8449 | if ($contactObj->ip && $contactObj->ip eq $self->clientSocket->peerhost()) { | ||
| 8450 | |||
| 8451 | push (@matchList, $contactObj); | ||
| 8452 | } | ||
| 8453 | } | ||
| 8454 | |||
| 8455 | if (@matchList == 1) { | ||
| 8456 | |||
| 8457 | # The incoming call is probably from one of our contacts | ||
| 8458 | $sessionContactObj = $matchList[0]; | ||
| 8459 | } | ||
| 8460 | |||
| 8461 | if ( | ||
| 8462 | $axmud::CLIENT->chatAcceptMode eq 'prompt' | ||
| 8463 | || ($axmud::CLIENT->chatAcceptMode eq 'accept_contact' && ! $sessionContactObj) | ||
| 8464 | ) { | ||
| 8465 | $msg = 'Accept chat call with \'' . $self->remoteName . '\' from ' | ||
| 8466 | . $self->clientSocket->peerhost(); | ||
| 8467 | |||
| 8468 | if ($sessionContactObj) { | ||
| 8469 | $msg .= ' (matches known contact \'' . $sessionContactObj->name . '\')?'; | ||
| 8470 | } else { | ||
| 8471 | $msg .= '?'; | ||
| 8472 | } | ||
| 8473 | |||
| 8474 | $result = $self->session->mainWin->showMsgDialogue( | ||
| 8475 | 'Chat task', | ||
| 8476 | 'question', | ||
| 8477 | $msg, | ||
| 8478 | 'yes-no', | ||
| 8479 | 'no', | ||
| 8480 | ); | ||
| 8481 | |||
| 8482 | # Check that the connection hasn't already timed out | ||
| 8483 | if ($self->connectionClosedFlag) { | ||
| 8484 | |||
| 8485 | # Display an explanatory message, if the user accepted the connection | ||
| 8486 | if ($result eq 'yes') { | ||
| 8487 | |||
| 8488 | $self->writeError( | ||
| 8489 | '\'' . $self->prettyName . '\' task: incoming chat connection has' | ||
| 8490 | . ' already closed', | ||
| 8491 | $self->_objClass . '->receiveEstablishmentData', | ||
| 8492 | ); | ||
| 8493 | } | ||
| 8494 | |||
| 8495 | # In either case, it's the end of the process | ||
| 8496 | return undef; | ||
| 8497 | } | ||
| 8498 | |||
| 8499 | if ($result ne 'yes') { | ||
| 8500 | |||
| 8501 | # Refuse the connection ("NO" for MudMaster, "NO\n" for zChat) | ||
| 8502 | if ($self->chatType == $self->ivShow('constOptHash', 'MM')) { | ||
| 8503 | syswrite($self->clientSocket, "NO"); | ||
| 8504 | } else { | ||
| 8505 | syswrite($self->clientSocket, "NO\n"); | ||
| 8506 | } | ||
| 8507 | |||
| 8508 | Glib::Source->remove($self->timeoutID); | ||
| 8509 | $self->terminateChatSession(); | ||
| 8510 | |||
| 8511 | return undef; | ||
| 8512 | } | ||
| 8513 | } | ||
| 8514 | |||
| 8515 | # Set $addressString to <ip address><port> or <ClientIPAddress><ClientPort> | ||
| 8516 | if ($self->chatType == $self->ivShow('constOptHash', 'ZCHAT')) { | ||
| 8517 | |||
| 8518 | # Only the zChat header contains a second newline character | ||
| 8519 | $nlPos2 = index($self->dataBuffer, "\n"); | ||
| 8520 | if ($nlPos2 == -1) { | ||
| 8521 | |||
| 8522 | # Neither this Chat task, nor Kildclient's chat.pl plugin send the | ||
| 8523 | # '\lf<SecurityInfo>' component | ||
| 8524 | # Assume it is missing and just work with the <ClientIPAddress><ClientPort> | ||
| 8525 | # component | ||
| 8526 | $addressString = $self->dataBuffer; | ||
| 8527 | |||
| 8528 | } else { | ||
| 8529 | |||
| 8530 | # Extract everything beore | ||
| 8531 | $addressString = substr($self->dataBuffer, 0, $nlPos2 + 1); | ||
| 8532 | substr($self->{dataBuffer}, 0, $nlPos2 + 1) = ''; | ||
| 8533 | } | ||
| 8534 | |||
| 8535 | } else { | ||
| 8536 | |||
| 8537 | # The MudMaster header doesn't contain a second newline character | ||
| 8538 | $addressString = $self->dataBuffer; | ||
| 8539 | $self->ivPoke('dataBuffer', ''); | ||
| 8540 | } | ||
| 8541 | |||
| 8542 | # Extract the IP address and port | ||
| 8543 | $self->ivPoke( | ||
| 8544 | 'remoteIP', | ||
| 8545 | substr( | ||
| 8546 | $addressString, | ||
| 8547 | 0, | ||
| 8548 | length($addressString) - 5, | ||
| 8549 | ), | ||
| 8550 | ); | ||
| 8551 | |||
| 8552 | $self->ivPoke('remotePort', int(substr($addressString, -5, 5))); | ||
| 8553 | |||
| 8554 | # FOR NOW: we don't process zChat's <SecurityInfo> | ||
| 8555 | $self->ivPoke('dataBuffer', ''); | ||
| 8556 | |||
| 8557 | # Set the chat name to use. Use the value stored in GA::Client, if it's been set; | ||
| 8558 | # otherwise use the current character | ||
| 8559 | if ($axmud::CLIENT->chatName) { | ||
| 8560 | |||
| 8561 | $self->ivPoke('localName', $axmud::CLIENT->chatName); | ||
| 8562 | |||
| 8563 | } elsif ($self->session->currentChar) { | ||
| 8564 | |||
| 8565 | $self->ivPoke('localName', ucfirst($self->session->currentChar->name)); | ||
| 8566 | |||
| 8567 | } else { | ||
| 8568 | |||
| 8569 | # Emergency failsafe - 'Axmud user' | ||
| 8570 | $self->ivPoke('localName', $axmud::SCRIPT . ' user'); | ||
| 8571 | } | ||
| 8572 | |||
| 8573 | # Set the email to broadcast. Use the value stored in GA::Client, if it's been set; | ||
| 8574 | # otherwise don't broadcast an email. (NB The email is only broadcast in zChat | ||
| 8575 | # sessions.) | ||
| 8576 | if ($axmud::CLIENT->chatEmail) { | ||
| 8577 | |||
| 8578 | $self->ivPoke('localEmail', $axmud::CLIENT->chatEmail); | ||
| 8579 | } | ||
| 8580 | |||
| 8581 | # Accept the connection | ||
| 8582 | # (Quoted from http://tintin.sourceforge.io/manual/chatprotocol.php) | ||
| 8583 | # If a "NO" is received the call is cancelled. If the call was accepted the string | ||
| 8584 | # "YES:<chat name>\n" is received. | ||
| 8585 | # | ||
| 8586 | # (Quoted from http://www.zuggsoft.com/zchat/zchatprot.htm) | ||
| 8587 | # To accept a connection, the Server sends a TCP/IP packet back to the client with | ||
| 8588 | # the data: | ||
| 8589 | # YES:<ServerChatName>\lf | ||
| 8590 | # If the Server is not accepting connections or if the security tests fail, or if | ||
| 8591 | # the Server wants to reject the request for any other reason, it sends a TCP/IP | ||
| 8592 | # packet back to the client with the data: NO | ||
| 8593 | syswrite($self->clientSocket, 'YES:' . $self->localName . "\n"); | ||
| 8594 | |||
| 8595 | # As soon as the connection is negotiated, the server and the client exchange | ||
| 8596 | # information about each other by sending commands | ||
| 8597 | $self->sendCmd( | ||
| 8598 | $self->ivShow('constOptHash', 'VERSION'), | ||
| 8599 | $self->getVersion(), | ||
| 8600 | ); | ||
| 8601 | |||
| 8602 | if ($self->chatType == $self->ivShow('constOptHash', 'ZCHAT')) { | ||
| 8603 | |||
| 8604 | # Our initial status is 1 ('Normal status') unless the user has been idle for | ||
| 8605 | # a minimum time, in which case it is 3 ('AFK') | ||
| 8606 | $self->ivPoke('localStatus', 1); | ||
| 8607 | $self->sendCmd( | ||
| 8608 | $self->ivShow('constOptHash', 'STATUS'), | ||
| 8609 | chr(1) | ||
| 8610 | ); | ||
| 8611 | |||
| 8612 | # Send the icon to the chat contact with an 'ICON' instruction | ||
| 8613 | if (-e $axmud::CLIENT->chatIcon) { | ||
| 8614 | |||
| 8615 | $self->prepareIcon($axmud::CLIENT->chatIcon); | ||
| 8616 | } | ||
| 8617 | |||
| 8618 | if ($self->localEmail) { | ||
| 8619 | |||
| 8620 | $self->sendCmd( | ||
| 8621 | $self->ivShow('constOptHash', 'EMAIL'), | ||
| 8622 | $self->localEmail, | ||
| 8623 | ); | ||
| 8624 | } | ||
| 8625 | |||
| 8626 | $self->sendCmd( | ||
| 8627 | $self->ivShow('constOptHash', 'STAMP'), | ||
| 8628 | pack("L", $self->localZChatStamp) | ||
| 8629 | ); | ||
| 8630 | } | ||
| 8631 | |||
| 8632 | # Open a new task window | ||
| 8633 | $self->newChatWin(); | ||
| 8634 | |||
| 8635 | # Respond to a Glib::IO event to process incoming data from the chat peer by calling | ||
| 8636 | # $self->mmChatDataReady() or $self->zChatDataReady | ||
| 8637 | # (This replaces the callback used to call this function) | ||
| 8638 | $self->ivPoke( | ||
| 8639 | 'ioWatchID', | ||
| 8640 | Glib::IO->add_watch( | ||
| 8641 | $self->clientSocket->fileno, | ||
| 8642 | 'in', | ||
| 8643 | $self->chatType == $self->ivShow('constOptHash', 'MM') | ||
| 8644 | ? sub { $self->mmChatDataReady(@_); } | ||
| 8645 | : sub { $self->zChatDataReady(@_); }, | ||
| 8646 | ), | ||
| 8647 | ); | ||
| 8648 | |||
| 8649 | # Now that the connection is established, remove the pending connection timeout | ||
| 8650 | Glib::Source->remove($self->timeoutID); | ||
| 8651 | |||
| 8652 | if ($sessionContactObj) { | ||
| 8653 | |||
| 8654 | $self->ivPoke('chatContactObj', $sessionContactObj); | ||
| 8655 | |||
| 8656 | if ($sessionContactObj->name eq $self->remoteName) { | ||
| 8657 | |||
| 8658 | $self->writeText( | ||
| 8659 | 'Chat session with contact \'' . $self->remoteName . '\'', | ||
| 8660 | 'system', | ||
| 8661 | ) | ||
| 8662 | |||
| 8663 | } else { | ||
| 8664 | |||
| 8665 | $self->writeText( | ||
| 8666 | 'Chat session with contact \'' . $sessionContactObj->name | ||
| 8667 | . '\' (using name \'' . $self->remoteName . '\')', | ||
| 8668 | 'system', | ||
| 8669 | ) | ||
| 8670 | } | ||
| 8671 | |||
| 8672 | } else { | ||
| 8673 | |||
| 8674 | $self->writeText( | ||
| 8675 | 'Chat session with \'' . $self->remoteName . '\' from ' . $self->remoteIP | ||
| 8676 | . ' port ' . $self->remotePort, | ||
| 8677 | 'system', | ||
| 8678 | ); | ||
| 8679 | } | ||
| 8680 | |||
| 8681 | return undef; | ||
| 8682 | } | ||
| 8683 | } | ||
| 8684 | |||
| 8685 | return 1; # Continue processing | ||
| 8686 | } | ||
| 8687 | |||
| 8688 | sub killPendingConnection { | ||
| 8689 | |||
| 8690 | # Called by $self->requestConnection and ->acceptConnection | ||
| 8691 | # Kills connections that have been open for some time but have not yet been successfully | ||
| 8692 | # established (i.e. when the Glib::Timeout stored in $self->timeoutID expires) | ||
| 8693 | # | ||
| 8694 | # Expected arguments | ||
| 8695 | # (none besides $self) | ||
| 8696 | # | ||
| 8697 | # Return values | ||
| 8698 | # 'undef' | ||
| 8699 | |||
| 8700 | my ($self, $check) = @_; | ||
| 8701 | |||
| 8702 | # Check for improper arguments | ||
| 8703 | if (defined $check) { | ||
| 8704 | |||
| 8705 | return $axmud::CLIENT->writeImproper($self->_objClass . '->killPendingConnection', @_); | ||
| 8706 | } | ||
| 8707 | |||
| 8708 | if ($self->taskWinFlag) { | ||
| 8709 | |||
| 8710 | $self->writeError( | ||
| 8711 | '\'' . $self->prettyName . '\' task: no reply from remote party, connection closed', | ||
| 8712 | $self->_objClass . '->killPendingConnection', | ||
| 8713 | ); | ||
| 8714 | } | ||
| 8715 | |||
| 8716 | $self->terminateChatSession(); | ||
| 8717 | |||
| 8718 | return undef; | ||
| 8719 | } | ||
| 8720 | |||
| 8721 | sub mmChatDataReady { | ||
| 8722 | |||
| 8723 | # Called by anonymous subs in $self->callEstablishmentData and | ||
| 8724 | # $self->receiveEstablishmentData | ||
| 8725 | # Data has been received from the chat peer in a MudMaster connection | ||
| 8726 | # | ||
| 8727 | # Expected arguments | ||
| 8728 | # $fileNo, $condition | ||
| 8729 | # - Arguments supplied by the Glib::IO event (not required by this function) | ||
| 8730 | # - $fileNo is the file descriptor, $self->clientSocket->fileno | ||
| 8731 | # - $condition is the Glib::IOCondition, namely 'in' / 'G_IO_IN' | ||
| 8732 | # | ||
| 8733 | # Return values | ||
| 8734 | # 'undef' on improper arguments, if there's an error reading from the filehandle, if the | ||
| 8735 | # filehandle sends an 'end of file' | ||
| 8736 | # 1 otherwise | ||
| 8737 | |||
| 8738 | my ($self, $fileNo, $condition, $check) = @_; | ||
| 8739 | |||
| 8740 | # Local variables | ||
| 8741 | my ($bytesRead, $tempBuffer, $endDataPos); | ||
| 8742 | |||
| 8743 | # Check for improper arguments | ||
| 8744 | if (! defined $fileNo || ! defined $condition || defined $check) { | ||
| 8745 | |||
| 8746 | return $axmud::CLIENT->writeImproper($self->_objClass . '->mmChatDataReady', @_); | ||
| 8747 | } | ||
| 8748 | |||
| 8749 | # Read 1024 bytes of data into $tempBuffer from the filehandle $self->clientSocket | ||
| 8750 | $bytesRead = sysread($self->clientSocket, $tempBuffer, 1024); | ||
| 8751 | |||
| 8752 | if ( | ||
| 8753 | ! defined $bytesRead # There was an error | ||
| 8754 | || $bytesRead <= 0 # End of file | ||
| 8755 | ) { | ||
| 8756 | $self->terminateChatSession(); | ||
| 8757 | |||
| 8758 | $self->writeText( | ||
| 8759 | 'Chat session closed.', | ||
| 8760 | 'system', | ||
| 8761 | ); | ||
| 8762 | |||
| 8763 | return undef; | ||
| 8764 | } | ||
| 8765 | |||
| 8766 | # Add the incoming data to the buffer | ||
| 8767 | $self->{dataBuffer} .= $tempBuffer; | ||
| 8768 | |||
| 8769 | # (http://tintin.sourceforge.io/manual/chatprotocol.php) | ||
| 8770 | # Once the MudMaster connection is open, instructions are sent in the form | ||
| 8771 | # <COMMAND BYTE><data><END OF COMMAND> | ||
| 8772 | # | ||
| 8773 | # Extract instructions and process them, one by one, until there are none left | ||
| 8774 | while (1) { | ||
| 8775 | |||
| 8776 | if (! defined($self->pendingOpCode)) { | ||
| 8777 | |||
| 8778 | # Extract the op code <COMMAND BYTE>, a 1-byte value | ||
| 8779 | if (length($self->dataBuffer) < 1) { | ||
| 8780 | |||
| 8781 | # Wait for more data before extracting the op code | ||
| 8782 | return 1; | ||
| 8783 | } | ||
| 8784 | |||
| 8785 | $self->ivPoke('pendingOpCode', ord($self->dataBuffer)); | ||
| 8786 | substr($self->{dataBuffer}, 0, 1) = ''; | ||
| 8787 | |||
| 8788 | } else { | ||
| 8789 | |||
| 8790 | if ($self->pendingOpCode == $self->ivShow('constOptHash', 'FILE_BLOCK')) { | ||
| 8791 | |||
| 8792 | # "A file block is ALWAYS 500 bytes so no CHAT_END_OF_COMMAND should be added" | ||
| 8793 | # FILE_BLOCK instructions are supposed to be in the format: | ||
| 8794 | # <CHAT_FILE_BLOCK><block of data> | ||
| 8795 | # However, MudMaster does actually send a CHAT_END_OF_COMMAND after the block, | ||
| 8796 | # regardless of what the specs say, so the format is actually | ||
| 8797 | # <CHAT_FILE_BLOCK><block of data><END OF COMMAND> | ||
| 8798 | # Therefore, the size of the file block is (MM_FILE_BLOCK_SIZE + 1) | ||
| 8799 | if ( | ||
| 8800 | length($self->dataBuffer) | ||
| 8801 | < ($self->ivShow('constOptHash', 'MM_FILE_BLOCK_SIZE') + 1) | ||
| 8802 | ) { | ||
| 8803 | # Wait for more data before processing the instruction | ||
| 8804 | return 1; | ||
| 8805 | } | ||
| 8806 | |||
| 8807 | # Process the file block | ||
| 8808 | $self->fileBlockReceived( | ||
| 8809 | substr( | ||
| 8810 | $self->dataBuffer, | ||
| 8811 | 0, | ||
| 8812 | $self->ivShow('constOptHash', 'MM_FILE_BLOCK_SIZE'), | ||
| 8813 | ), | ||
| 8814 | ); | ||
| 8815 | |||
| 8816 | substr( | ||
| 8817 | $self->{dataBuffer}, | ||
| 8818 | 0, | ||
| 8819 | ($self->ivShow('constOptHash', 'MM_FILE_BLOCK_SIZE') + 1) | ||
| 8820 | ) = ''; | ||
| 8821 | |||
| 8822 | $self->ivUndef('pendingOpCode'); | ||
| 8823 | |||
| 8824 | } else { | ||
| 8825 | |||
| 8826 | # Find the position of the <END OF COMMAND> component | ||
| 8827 | $endDataPos = index( | ||
| 8828 | $self->dataBuffer, | ||
| 8829 | chr($self->ivShow('constOptHash', 'END_OF_COMMAND')) | ||
| 8830 | ); | ||
| 8831 | |||
| 8832 | if ($endDataPos == -1) { | ||
| 8833 | |||
| 8834 | # <END OF COMMAND> not received yet; wait for more data before processing | ||
| 8835 | # the instruction | ||
| 8836 | return 1; | ||
| 8837 | } | ||
| 8838 | |||
| 8839 | # Extract the <data> component (i.e. everything before $endDataPos) and send it | ||
| 8840 | # for processing | ||
| 8841 | $self->dispatchCmd(substr($self->dataBuffer, 0, $endDataPos)); | ||
| 8842 | |||
| 8843 | # Remove the <data> component from the buffer | ||
| 8844 | substr($self->{dataBuffer}, 0, ($endDataPos + 1)) = ''; | ||
| 8845 | # Once the command has been processed, we don't need to remember the opcode | ||
| 8846 | $self->ivUndef('pendingOpCode'); | ||
| 8847 | } | ||
| 8848 | } | ||
| 8849 | } | ||
| 8850 | |||
| 8851 | # Continue processing | ||
| 8852 | return 1; | ||
| 8853 | } | ||
| 8854 | |||
| 8855 | sub zChatDataReady { | ||
| 8856 | |||
| 8857 | # Called by anonymous subs in $self->callEstablishmentData and | ||
| 8858 | # $self->receiveEstablishmentData | ||
| 8859 | # Data has been received from the chat peer in a zChat connection | ||
| 8860 | # | ||
| 8861 | # Expected arguments | ||
| 8862 | # $fileNo, $condition | ||
| 8863 | # - Arguments supplied by the Glib::IO event (not required by this function) | ||
| 8864 | # - $fileNo is the file descriptor, $self->clientSocket->fileno | ||
| 8865 | # - $condition is the Glib::IOCondition, namely 'in' / 'G_IO_IN' | ||
| 8866 | # | ||
| 8867 | # Return values | ||
| 8868 | # 'undef' on improper arguments, if there's an error reading from the filehandle, if the | ||
| 8869 | # filehandle sends an 'end of file' | ||
| 8870 | # 1 otherwise | ||
| 8871 | |||
| 8872 | my ($self, $fileNo, $condition, $check) = @_; | ||
| 8873 | |||
| 8874 | # Local variables | ||
| 8875 | my ($bytesRead, $tempBuffer); | ||
| 8876 | |||
| 8877 | # Check for improper arguments | ||
| 8878 | if (! defined $fileNo || ! defined $condition || defined $check) { | ||
| 8879 | |||
| 8880 | return $axmud::CLIENT->writeImproper($self->_objClass . '->zChatDataReady', @_); | ||
| 8881 | } | ||
| 8882 | |||
| 8883 | # Read 1024 bytes of data into $tempBuffer from the filehandle $self->clientSocket | ||
| 8884 | $bytesRead = sysread($self->clientSocket, $tempBuffer, 1024); | ||
| 8885 | |||
| 8886 | if ( | ||
| 8887 | ! defined $bytesRead # There was an error | ||
| 8888 | || $bytesRead <= 0 # End of file | ||
| 8889 | ) { | ||
| 8890 | $self->terminateChatSession(); | ||
| 8891 | |||
| 8892 | $self->writeText( | ||
| 8893 | 'Chat session closed.', | ||
| 8894 | 'system', | ||
| 8895 | ); | ||
| 8896 | |||
| 8897 | return undef; | ||
| 8898 | } | ||
| 8899 | |||
| 8900 | # Add the incoming data to the buffer | ||
| 8901 | $self->{dataBuffer} .= $tempBuffer; | ||
| 8902 | |||
| 8903 | # (http://www.zuggsoft.com/zchat/zchatprot.htm) | ||
| 8904 | # Once the zChat connection is open, instructions are sent in the form | ||
| 8905 | # <CommandID><Length><Data> | ||
| 8906 | # | ||
| 8907 | # Extract instructions and process them, one by one, until there are none left | ||
| 8908 | while (1) { | ||
| 8909 | |||
| 8910 | if (! defined($self->pendingOpCode)) { | ||
| 8911 | |||
| 8912 | # Extract the op code <CommandID>, "a 16-bit value, with the lower 8-bits sent | ||
| 8913 | # first, followed by the upper 8-bits" | ||
| 8914 | if (length($self->dataBuffer) < 2) { | ||
| 8915 | |||
| 8916 | # Wait for more data before extracting the op code | ||
| 8917 | return 1; | ||
| 8918 | } | ||
| 8919 | |||
| 8920 | # 'v' template = 'An unsigned short (16-bit) in "VAX" (little-endian) order' | ||
| 8921 | $self->ivPoke( | ||
| 8922 | 'pendingOpCode', | ||
| 8923 | unpack( | ||
| 8924 | 'v', | ||
| 8925 | substr($self->dataBuffer, 0, 2), | ||
| 8926 | ) | ||
| 8927 | ); | ||
| 8928 | substr($self->{dataBuffer}, 0, 2) = ''; | ||
| 8929 | |||
| 8930 | } elsif (! defined($self->pendingDataSize)) { | ||
| 8931 | |||
| 8932 | # Get the size of the data component <Length>, "is a 16-bit value, with the lower | ||
| 8933 | # 8-bits sent first , followed by the upper 8-bits" | ||
| 8934 | if (length($self->dataBuffer) < 2) { | ||
| 8935 | |||
| 8936 | # Wait for more data before extracting the length | ||
| 8937 | return 1; | ||
| 8938 | } | ||
| 8939 | |||
| 8940 | # 'v' template = 'An unsigned short (16-bit) in "VAX" (little-endian) order' | ||
| 8941 | $self->ivPoke( | ||
| 8942 | 'pendingDataSize', | ||
| 8943 | unpack( | ||
| 8944 | 'v', | ||
| 8945 | substr($self->dataBuffer, 0, 2), | ||
| 8946 | ) | ||
| 8947 | ); | ||
| 8948 | |||
| 8949 | substr($self->{dataBuffer}, 0, 2) = ''; | ||
| 8950 | |||
| 8951 | } elsif (length($self->dataBuffer) >= $self->pendingDataSize) { | ||
| 8952 | |||
| 8953 | # Extract the <Data> component (i.e. the first $self->pendingDataSize bytes left in | ||
| 8954 | # the buffer) and send it for processing. | ||
| 8955 | $self->dispatchCmd(substr($self->dataBuffer, 0, $self->pendingDataSize)); | ||
| 8956 | |||
| 8957 | # Remove the <Data> component from the buffer | ||
| 8958 | substr($self->{dataBuffer}, 0, $self->pendingDataSize) = ''; | ||
| 8959 | # Once the command has been processed, we don't need to remember the opcode or its | ||
| 8960 | # data | ||
| 8961 | $self->ivUndef('pendingOpCode'); | ||
| 8962 | $self->ivUndef('pendingDataSize'); | ||
| 8963 | |||
| 8964 | } else { | ||
| 8965 | |||
| 8966 | # There are no more complete instructions to process | ||
| 8967 | return 1; | ||
| 8968 | } | ||
| 8969 | } | ||
| 8970 | |||
| 8971 | # Continue processing | ||
| 8972 | return 1; | ||
| 8973 | } | ||
| 8974 | |||
| 8975 | sub sendCmd { | ||
| 8976 | |||
| 8977 | # Called by various functions | ||
| 8978 | # Packs a command in the appropriate representation and sends it | ||
| 8979 | # | ||
| 8980 | # Expected arguments | ||
| 8981 | # $opCode - The opcode (command) to broadcast, matches one of the values in | ||
| 8982 | # $self->constOptHash | ||
| 8983 | # $data - The data to broadcast alongside the opcode. For some opcodes, the $data | ||
| 8984 | # component is an empty string (but never 'undef') | ||
| 8985 | # | ||
| 8986 | # Return values | ||
| 8987 | # 'undef' on improper arguments or if a restricted $opCode is used when the connection | ||
| 8988 | # hasn't yet been negotiated | ||
| 8989 | # 1 otherwise | ||
| 8990 | |||
| 8991 | my ($self, $opCode, $data, $check) = @_; | ||
| 8992 | |||
| 8993 | # Local variables | ||
| 8994 | my ( | ||
| 8995 | $cmd, | ||
| 8996 | @taskList, | ||
| 8997 | ); | ||
| 8998 | |||
| 8999 | # Check for improper arguments | ||
| 9000 | if (! defined $opCode || ! defined $data || defined $check) { | ||
| 9001 | |||
| 9002 | return $axmud::CLIENT->writeImproper($self->_objClass . '->sendCmd', @_); | ||
| 9003 | } | ||
| 9004 | |||
| 9005 | # Check for restricted opcodes | ||
| 9006 | if (! $self->remoteName && $self->ivExists('restrictedHash', $opCode)) { | ||
| 9007 | |||
| 9008 | # This is a failsafe; the calling function ought to have already filtered out the | ||
| 9009 | # restricted opcode | ||
| 9010 | $self->writeText( | ||
| 9011 | 'Restricted opcode error (' . $self->ivShow('restrictedHash', $opCode) . ')', | ||
| 9012 | 'system', | ||
| 9013 | ); | ||
| 9014 | |||
| 9015 | return undef; | ||
| 9016 | } | ||
| 9017 | |||
| 9018 | # The data component is encoded using the character set in $self->encoding - the default is | ||
| 9019 | # 'iso-8859-1' - unless we're sending files or parts of files ('FILE_BLOCK', 'ICON') | ||
| 9020 | if ( | ||
| 9021 | $opCode != $self->ivShow('constOptHash', 'FILE_BLOCK') | ||
| 9022 | && $opCode != $self->ivShow('constOptHash', 'ICON') | ||
| 9023 | ) { | ||
| 9024 | $data = Encode::encode($self->encoding, $data); | ||
| 9025 | } | ||
| 9026 | |||
| 9027 | # zChat instructions Text Everybody (4), Text Personal (5) and Text Group (6) must be | ||
| 9028 | # preceded by $self->localZChatStamp | ||
| 9029 | # | ||
| 9030 | # (from http://www.zuggsoft.com/zchat/zchatprot.htm) | ||
| 9031 | # StampedText has the format | ||
| 9032 | # <Stamp><Text> | ||
| 9033 | # where Stamp is a 4-byte session ID number. When Sending, send your Stamp Code, which is | ||
| 9034 | # the random number you generated and broadcast when zChat first started. If the received | ||
| 9035 | # Stamp value matches the Receivers Stamp ID, the message is ignored (since it represents | ||
| 9036 | # a message loop). | ||
| 9037 | # | ||
| 9038 | # The original chat.pl also adds a stamp to 'SNOOP_DATA'. I'll assume that's not an error... | ||
| 9039 | if ( | ||
| 9040 | $self->chatType == $self->ivShow('constOptHash', 'ZCHAT') | ||
| 9041 | && ( | ||
| 9042 | $opCode == $self->ivShow('constOptHash', 'TEXT_PERSONAL') | ||
| 9043 | || $opCode == $self->ivShow('constOptHash', 'TEXT_GROUP') | ||
| 9044 | || $opCode == $self->ivShow('constOptHash', 'TEXT_EVERYBODY') | ||
| 9045 | || $opCode == $self->ivShow('constOptHash', 'SNOOP_DATA') | ||
| 9046 | ) | ||
| 9047 | ) { | ||
| 9048 | $data = pack("L", $self->localZChatStamp) . $data; | ||
| 9049 | } | ||
| 9050 | |||
| 9051 | if ($self->chatType == $self->ivShow('constOptHash', 'MM')) { | ||
| 9052 | |||
| 9053 | # (from http://tintin.sourceforge.io/manual/chatprotocol.php) | ||
| 9054 | # A chat data block looks like this: <COMMAND BYTE><data><END OF COMMAND>. All data | ||
| 9055 | # dealing with needs to follow this format with a couple exceptions. The connection | ||
| 9056 | # process doesn't use the data blocks and the file transfer blocks are a fixed size | ||
| 9057 | # and don't need the <END OF COMMAND> byte. | ||
| 9058 | # | ||
| 9059 | # NB According to the chat.pl source, MudMaster does, in fact, send <END OF COMMAND> | ||
| 9060 | # after a 'FILE_BLOCK', regardless of what the quote above says - and so shall we | ||
| 9061 | $cmd = chr($opCode) . $data . chr($self->ivShow('constOptHash', 'END_OF_COMMAND')); | ||
| 9062 | |||
| 9063 | } elsif ($self->chatType == $self->ivShow('constOptHash', 'ZCHAT')) { | ||
| 9064 | |||
| 9065 | # (from http://www.zuggsoft.com/zchat/zchatprot.htm) | ||
| 9066 | # Commands are normal TCP/IP packets that contain the following data format: | ||
| 9067 | # <CommandID><Length><Data> | ||
| 9068 | # | ||
| 9069 | # CommandID | ||
| 9070 | # is a 16-bit value, with the lower 8-bits sent first, followed by the upper 8-bits. | ||
| 9071 | # It represents the ID of the command being sent. Each Command ID is described | ||
| 9072 | # below in more detail. | ||
| 9073 | # Length | ||
| 9074 | # is a 16-bit value, with the lower 8-bits sent first , followed by the upper 8-bits. | ||
| 9075 | # It represents the length of the Data field in bytes. By using a Length field | ||
| 9076 | # instead of a terminating character after the Data, any data value can be easily | ||
| 9077 | # sent. | ||
| 9078 | # Data | ||
| 9079 | # is the data required by the command. | ||
| 9080 | $cmd = pack('vv', $opCode, length($data)) . $data; | ||
| 9081 | } | ||
| 9082 | |||
| 9083 | # If the filehandle is still open (we can avoid a rare error by checking), send the command | ||
| 9084 | # to the chat contact | ||
| 9085 | if (fileno $self->clientSocket) { | ||
| 9086 | |||
| 9087 | syswrite($self->clientSocket, $cmd); | ||
| 9088 | } | ||
| 9089 | |||
| 9090 | return 1; | ||
| 9091 | } | ||
| 9092 | |||
| 9093 | sub broadcast { | ||
| 9094 | |||
| 9095 | # Called by various functions | ||
| 9096 | # Broadcasts a command to all open chat sessions or (optionally) to all open sessions with a | ||
| 9097 | # particular group | ||
| 9098 | # | ||
| 9099 | # Expected arguments | ||
| 9100 | # $opCode - The opcode (command) to broadcast, matches one of the values in | ||
| 9101 | # $self->constOptHash | ||
| 9102 | # $data - The data to broadcast alongside the opcode. For some opcodes, the $data | ||
| 9103 | # component is an empty string | ||
| 9104 | # | ||
| 9105 | # Optional arguments | ||
| 9106 | # $group - If defined, the command is broadcast only to chat sessions in this group. | ||
| 9107 | # $group matches $self->localGroup. If 'undef', the command is broadcast | ||
| 9108 | # to all open sessions | ||
| 9109 | # | ||
| 9110 | # Return values | ||
| 9111 | # 'undef' on improper arguments | ||
| 9112 | # 1 otherwise | ||
| 9113 | |||
| 9114 | my ($self, $opCode, $data, $group, $check) = @_; | ||
| 9115 | |||
| 9116 | # Check for improper arguments | ||
| 9117 | if (! defined $opCode || ! defined $data || defined $check) { | ||
| 9118 | |||
| 9119 | return $axmud::CLIENT->writeImproper($self->_objClass . '->broadcast', @_); | ||
| 9120 | } | ||
| 9121 | |||
| 9122 | if ($group) { | ||
| 9123 | |||
| 9124 | # Group names have a maximum size. If users specify longer group names, the names are | ||
| 9125 | # always reduced to 15 characters | ||
| 9126 | $group = substr($group, 0, 15); | ||
| 9127 | } | ||
| 9128 | |||
| 9129 | # Check every Chat task | ||
| 9130 | foreach my $taskObj ($self->session->ivValues('currentTaskHash')) { | ||
| 9131 | |||
| 9132 | if ( | ||
| 9133 | $taskObj->name eq 'chat_task' | ||
| 9134 | && $taskObj->sessionFlag | ||
| 9135 | && ! $taskObj->connectionClosedFlag | ||
| 9136 | && ! ( | ||
| 9137 | $taskObj->chatType == $self->ivShow('constOptHash', 'MM') | ||
| 9138 | && $opCode >= $self->ivShow('constOptHash', 'PEEK_CONNECTIONS') | ||
| 9139 | ) && ! ( | ||
| 9140 | $group | ||
| 9141 | && $taskObj->localGroup ne $group | ||
| 9142 | ) | ||
| 9143 | ) { | ||
| 9144 | # Broadcast the command to this Chat task session | ||
| 9145 | $taskObj->sendCmd($opCode, $data); | ||
| 9146 | } | ||
| 9147 | } | ||
| 9148 | |||
| 9149 | return 1; | ||
| 9150 | } | ||
| 9151 | |||
| 9152 | sub dispatchCmd { | ||
| 9153 | |||
| 9154 | # Called by several functions | ||
| 9155 | # Processes an incoming MudMaster or zChat instruction | ||
| 9156 | # | ||
| 9157 | # Expected arguments | ||
| 9158 | # $data - In a MudMaster session, the <data> component in an instruction in the form | ||
| 9159 | # <COMMAND BYTE><data><END OF COMMAND> | ||
| 9160 | # - In a zChat session, the <data> component in an instruction in the form | ||
| 9161 | # <CommandID><Length><Data> | ||
| 9162 | # | ||
| 9163 | # Return values | ||
| 9164 | # 'undef' on improper arguments | ||
| 9165 | # 1 otherwise | ||
| 9166 | |||
| 9167 | my ($self, $data, $check) = @_; | ||
| 9168 | |||
| 9169 | # Local variables | ||
| 9170 | my ( | ||
| 9171 | $opCode, | ||
| 9172 | %hash, | ||
| 9173 | ); | ||
| 9174 | |||
| 9175 | # Check for improper arguments | ||
| 9176 | if (! defined $data || defined $check) { | ||
| 9177 | |||
| 9178 | return $axmud::CLIENT->writeImproper($self->_objClass . '->dispatchCmd', @_); | ||
| 9179 | } | ||
| 9180 | |||
| 9181 | # Import $self->constOptHash for quick lookup | ||
| 9182 | %hash = $self->constOptHash; | ||
| 9183 | |||
| 9184 | # Process the instruction | ||
| 9185 | $opCode = $self->pendingOpCode; | ||
| 9186 | |||
| 9187 | # MM: CHAT_NAME_CHANGE (1) | ||
| 9188 | # zC: Name Change (1) | ||
| 9189 | if ($opCode == $hash{'NAME_CHANGE'}) { | ||
| 9190 | |||
| 9191 | $self->changeRemoteName($data); | ||
| 9192 | |||
| 9193 | # MM: CHAT_REQUEST_CONNECTIONS (2) | ||
| 9194 | # zC: Request Connections (2) | ||
| 9195 | } elsif ($opCode == $hash{'REQUEST_CONNECTIONS'}) { | ||
| 9196 | |||
| 9197 | $self->sendConnectionList(); | ||
| 9198 | |||
| 9199 | # MM: CHAT_CONNECTION_LIST (3) | ||
| 9200 | # zC: Connection List (3) | ||
| 9201 | } elsif ($opCode == $hash{'CONNECTION_LIST'}) { | ||
| 9202 | |||
| 9203 | $self->reviewConnectionList($data); | ||
| 9204 | |||
| 9205 | # MM: CHAT_TEXT_EVERYBODY (4) | ||
| 9206 | # MM: CHAT_TEXT_PERSONAL (5) | ||
| 9207 | # MM: CHAT_TEXT_GROUP (6) | ||
| 9208 | # zC: Text Everybody (4) | ||
| 9209 | # zC: Text Personal (5) | ||
| 9210 | # zC: Text Group (6) | ||
| 9211 | } elsif ( | ||
| 9212 | $opCode == $hash{'TEXT_EVERYBODY'} | ||
| 9213 | || $opCode == $hash{'TEXT_PERSONAL'} | ||
| 9214 | || $opCode == $hash{'TEXT_GROUP'} | ||
| 9215 | ) { | ||
| 9216 | $self->processTextMsg($data); | ||
| 9217 | |||
| 9218 | # MM: CHAT_MESSAGE (7) | ||
| 9219 | # zC: Message (7) | ||
| 9220 | } elsif ($opCode == $hash{'MESSAGE'}) { | ||
| 9221 | |||
| 9222 | $self->displayRemoteMsg($data); | ||
| 9223 | |||
| 9224 | # MM: CHAT_DO_NOT_DISTURB (8) | ||
| 9225 | } elsif ($opCode == $hash{'DO_NOT_DISTURB'}) { | ||
| 9226 | |||
| 9227 | # This opcode is not well documented, but just writes a 'please don't disturb me' | ||
| 9228 | # message to the task window | ||
| 9229 | $self->writeText( | ||
| 9230 | $self->remoteName . ' has sent you a \'do not disturb\' request.', | ||
| 9231 | 'remote', | ||
| 9232 | ); | ||
| 9233 | |||
| 9234 | # MM: CHAT_VERSION (19) | ||
| 9235 | # zC: Version (19) | ||
| 9236 | } elsif ($opCode == $hash{'VERSION'}) { | ||
| 9237 | |||
| 9238 | $self->ivPoke('remoteVersion', $data); | ||
| 9239 | |||
| 9240 | # MM: CHAT_FILE_START (20) | ||
| 9241 | # zC: File Start (20) | ||
| 9242 | } elsif ($opCode == $hash{'FILE_START'}) { | ||
| 9243 | |||
| 9244 | $self->receiveFile($data); | ||
| 9245 | |||
| 9246 | # MM: CHAT_FILE_DENY (21) | ||
| 9247 | # zC: File Deny (21) | ||
| 9248 | } elsif ($opCode == $hash{'FILE_DENY'}) { | ||
| 9249 | |||
| 9250 | $self->fileStop(); | ||
| 9251 | |||
| 9252 | # MM: CHAT_FILE_BLOCK_REQUEST (22) | ||
| 9253 | # zc: File Block Request (22) | ||
| 9254 | } elsif ($opCode == $hash{'FILE_BLOCK_REQUEST'}) { | ||
| 9255 | |||
| 9256 | $self->fileSendNextBlock(); | ||
| 9257 | |||
| 9258 | # MM: CHAT_FILE_BLOCK (23) | ||
| 9259 | # zC: File Block (23) | ||
| 9260 | } elsif ($opCode == $hash{'FILE_BLOCK'}) { | ||
| 9261 | |||
| 9262 | $self->fileBlockReceived($data); | ||
| 9263 | |||
| 9264 | # MM: CHAT_FILE_END (24) | ||
| 9265 | # zC: File End (24) | ||
| 9266 | } elsif ($opCode == $hash{'FILE_END'}) { | ||
| 9267 | |||
| 9268 | $self->fileEnd(); | ||
| 9269 | |||
| 9270 | # MM: CHAT_FILE_CANCEL (25) | ||
| 9271 | # zC: File Cancel (25) | ||
| 9272 | } elsif ($opCode == $hash{'FILE_CANCEL'}) { | ||
| 9273 | |||
| 9274 | $self->fileStop(); | ||
| 9275 | |||
| 9276 | # MM: CHAT_PING_REQUEST (26) | ||
| 9277 | # zC: Ping Request (26) | ||
| 9278 | } elsif ($opCode == $hash{'PING_REQUEST'}) { | ||
| 9279 | |||
| 9280 | $self->sendCmd($hash{'PING_RESPONSE'}, $data); | ||
| 9281 | |||
| 9282 | # MM: CHAT_PING_RESPONSE (27) | ||
| 9283 | # zC: Ping Response (27) | ||
| 9284 | } elsif ($opCode == $hash{'PING_RESPONSE'}) { | ||
| 9285 | |||
| 9286 | $self->pingResponse($data); | ||
| 9287 | |||
| 9288 | # MM: CHAT_PEEK_CONNECTIONS (28) | ||
| 9289 | # zC: Peek Connections (28) | ||
| 9290 | } elsif ($opCode == $hash{'PEEK_CONNECTIONS'}) { | ||
| 9291 | |||
| 9292 | $self->sendConnectionList(); | ||
| 9293 | |||
| 9294 | # MM: CHAT_PEEK_LIST (29) | ||
| 9295 | # zC: Peek List (29) | ||
| 9296 | } elsif ($opCode == $hash{'PEEK_LIST'}) { | ||
| 9297 | |||
| 9298 | $self->showConnectionList($data); | ||
| 9299 | |||
| 9300 | # MM: CHAT_SNOOP_START (30) | ||
| 9301 | # zC: Snoop (30) | ||
| 9302 | } elsif ($opCode == $hash{'SNOOP'}) { | ||
| 9303 | |||
| 9304 | if ($self->isSnoopedFlag) { | ||
| 9305 | $self->stopSnooped(); | ||
| 9306 | } else { | ||
| 9307 | $self->startSnooped(); | ||
| 9308 | } | ||
| 9309 | |||
| 9310 | # MM: CHAT_SNOOP_DATA (31) | ||
| 9311 | # zC: Snoop Data (31) | ||
| 9312 | } elsif ($opCode == $hash{'SNOOP_DATA'}) { | ||
| 9313 | |||
| 9314 | $self->processSnoopedData($data); | ||
| 9315 | |||
| 9316 | # zC: Icon (100) | ||
| 9317 | } elsif ($opCode == $hash{'ICON'}) { | ||
| 9318 | |||
| 9319 | $self->processIcon($data); | ||
| 9320 | |||
| 9321 | # zC: Status (101) | ||
| 9322 | } elsif ($opCode == $hash{'STATUS'}) { | ||
| 9323 | |||
| 9324 | $self->processStatus($data); | ||
| 9325 | |||
| 9326 | # zC: Email Address (102) | ||
| 9327 | } elsif ($opCode == $hash{'EMAIL'}) { | ||
| 9328 | |||
| 9329 | $self->ivPoke('remoteEmail', $data); | ||
| 9330 | if ($self->chatContactObj) { | ||
| 9331 | |||
| 9332 | $self->chatContactObj->ivPoke('email', $data); | ||
| 9333 | } | ||
| 9334 | |||
| 9335 | # zC: Send command (105) | ||
| 9336 | } elsif ($opCode == $hash{'SEND_COMMAND'}) { | ||
| 9337 | |||
| 9338 | $self->relayRemoteCmd($data); | ||
| 9339 | |||
| 9340 | # zC: Stamp (106) | ||
| 9341 | } elsif ($opCode == $hash{'STAMP'}) { | ||
| 9342 | |||
| 9343 | $self->ivPoke('remoteStamp', unpack("L", $data)); | ||
| 9344 | |||
| 9345 | # Sometimes (for unknown reasons) the data component $data is empty | ||
| 9346 | if ($self->remoteStamp) { | ||
| 9347 | |||
| 9348 | if ($self->remoteStamp == $self->localZChatStamp) { | ||
| 9349 | |||
| 9350 | $self->ivPoke('localZChatStamp', int(rand(2**32 - 1))); | ||
| 9351 | $self->broadcast($hash{'STAMP'}, pack('L', $self->localZChatStamp)); | ||
| 9352 | } | ||
| 9353 | } | ||
| 9354 | |||
| 9355 | # Unsupported or invalid opcode. Ignore it completely, if it's the same as the last | ||
| 9356 | # invalid opcode we received | ||
| 9357 | } elsif (! defined $self->lastInvalidOpCode || $self->lastInvalidOpCode != $opCode) { | ||
| 9358 | |||
| 9359 | $self->ivPoke('lastInvalidOpCode', $opCode); | ||
| 9360 | |||
| 9361 | # Request PGP Key (103) | ||
| 9362 | if ($opCode == 103) { | ||
| 9363 | |||
| 9364 | $self->writeText( | ||
| 9365 | 'Received unsupported opcode #103 (REQUEST_PGP_KEY)', | ||
| 9366 | 'system', | ||
| 9367 | ); | ||
| 9368 | |||
| 9369 | $self->sendCmd( | ||
| 9370 | $hash{'MESSAGE'}, | ||
| 9371 | 'Sorry, ' . $axmud::SCRIPT . ' does not support \'REQUEST_PGP_KEY\'' | ||
| 9372 | . ' (opcode 103) requests', | ||
| 9373 | ); | ||
| 9374 | |||
| 9375 | # PGP Key (104) | ||
| 9376 | } elsif ($opCode == 104) { | ||
| 9377 | |||
| 9378 | $self->writeText( | ||
| 9379 | 'Received unsupported opcode #104 (PGP_KEY)', | ||
| 9380 | 'system', | ||
| 9381 | ); | ||
| 9382 | |||
| 9383 | $self->sendCmd( | ||
| 9384 | $hash{'MESSAGE'}, | ||
| 9385 | 'Sorry, ' . $axmud::SCRIPT . ' does not support \'PGP_KEY\' (opcode 104)' | ||
| 9386 | . ' requests', | ||
| 9387 | ); | ||
| 9388 | |||
| 9389 | |||
| 9390 | # Invalid opcodes | ||
| 9391 | } else { | ||
| 9392 | |||
| 9393 | $self->writeText( | ||
| 9394 | 'Received invalid opcode #' . $opCode, | ||
| 9395 | 'system', | ||
| 9396 | ); | ||
| 9397 | |||
| 9398 | $self->sendCmd( | ||
| 9399 | $hash{'MESSAGE'}, | ||
| 9400 | 'Sorry, request denied (invalid opcode #' . $opCode . ')', | ||
| 9401 | ); | ||
| 9402 | } | ||
| 9403 | } | ||
| 9404 | |||
| 9405 | return 1; | ||
| 9406 | } | ||
| 9407 | |||
| 9408 | sub formatText { | ||
| 9409 | |||
| 9410 | # Called by various task functions | ||
| 9411 | # Formats a message to be sent in a 'TEXT_PERSONAL', 'TEXT_GROUP' or 'TEXT_EVERYBODY' | ||
| 9412 | # instruction | ||
| 9413 | # | ||
| 9414 | # Expected arguments | ||
| 9415 | # $text - The text to be sent | ||
| 9416 | # $isEmoteFlag - Is this an emote? (TRUE yes, FALSE no) | ||
| 9417 | # $dest - A value in $self->constOptHash matching the key 'PERSONAL', | ||
| 9418 | # 'EVERYBODY' or 'GROUP' | ||
| 9419 | # | ||
| 9420 | # Return values | ||
| 9421 | # 'undef' on improper arguments | ||
| 9422 | # Otherwise returns the message to be sent | ||
| 9423 | |||
| 9424 | my ($self, $text, $isEmoteFlag, $dest, $check) = @_; | ||
| 9425 | |||
| 9426 | # Local variables | ||
| 9427 | my ($destName, $string); | ||
| 9428 | |||
| 9429 | # Check for improper arguments | ||
| 9430 | if (! defined $text || ! defined $isEmoteFlag || ! defined $dest || defined $check) { | ||
| 9431 | |||
| 9432 | return $axmud::CLIENT->writeImproper($self->_objClass . '->formatText', @_); | ||
| 9433 | } | ||
| 9434 | |||
| 9435 | if ($dest == $self->ivShow('constOptHash', 'PERSONAL')) { | ||
| 9436 | $destName = 'you'; | ||
| 9437 | } elsif ($dest == $self->ivShow('constOptHash', 'GROUP')) { | ||
| 9438 | $destName = 'the group'; | ||
| 9439 | } elsif ($dest == $self->ivShow('constOptHash', 'EVERYBODY')) { | ||
| 9440 | $destName = 'everybody'; | ||
| 9441 | } | ||
| 9442 | |||
| 9443 | if (! $isEmoteFlag) { | ||
| 9444 | |||
| 9445 | # e.g. 'Alice chats to Bob, 'hello'' | ||
| 9446 | |||
| 9447 | # Don't enclose a recognised smiley in quotes | ||
| 9448 | if ($axmud::CLIENT->ivExists('constChatSmileyHash', $text)) { | ||
| 9449 | $string = $self->localName . ' chats to ' . $destName . ', ' . $text; | ||
| 9450 | } else { | ||
| 9451 | $string = $self->localName . ' chats to ' . $destName . ', \'' . $text . "'"; | ||
| 9452 | } | ||
| 9453 | |||
| 9454 | } elsif ($destName eq 'you') { | ||
| 9455 | |||
| 9456 | # e.g. 'Alice laughs.' | ||
| 9457 | $string = $self->localName . ' ' . $text . ""; | ||
| 9458 | |||
| 9459 | } else { | ||
| 9460 | |||
| 9461 | # e.g. '(To Bob) Alice laughs.' | ||
| 9462 | $string = "To " . $destName . ') ' . $self->localName . ' ' . $text . ""; | ||
| 9463 | } | ||
| 9464 | |||
| 9465 | return $string; | ||
| 9466 | } | ||
| 9467 | |||
| 9468 | sub formatGroup { | ||
| 9469 | |||
| 9470 | # Called by $self->chatToGroup, ->emoteToGroup and ->processTextMsg | ||
| 9471 | # Processes $self->localGroup into a 15-character string padded with spaces. (MM pads with | ||
| 9472 | # spaces on the right; zChat pads with spaces on the left) | ||
| 9473 | # | ||
| 9474 | # Expected arguments | ||
| 9475 | # $group - The string to format (normally matches $self->localGroup) | ||
| 9476 | # | ||
| 9477 | # Return values | ||
| 9478 | # 'undef' on improper arguments | ||
| 9479 | # Otherwise returns the formatted text | ||
| 9480 | |||
| 9481 | my ($self, $group, $check) = @_; | ||
| 9482 | |||
| 9483 | # Local variables | ||
| 9484 | my $groupFormat; | ||
| 9485 | |||
| 9486 | # Check for improper arguments | ||
| 9487 | if (! defined $group || defined $check) { | ||
| 9488 | |||
| 9489 | return $axmud::CLIENT->writeImproper($self->_objClass . '->formatGroup', @_); | ||
| 9490 | } | ||
| 9491 | |||
| 9492 | if ($self->chatType == $self->ivShow('constOptHash', 'MM')) { | ||
| 9493 | |||
| 9494 | # (from http://tintin.sourceforge.io/manual/chatprotocol.php) | ||
| 9495 | # Used when you send text to a specific group of connections. Works basically the same | ||
| 9496 | # as the other text commands. The group name is a 15 character string. It *must* be 15 | ||
| 9497 | # characters long and pad it on the right with spaces to fill it out. | ||
| 9498 | $groupFormat = sprintf('%-15s', $group); | ||
| 9499 | |||
| 9500 | } else { | ||
| 9501 | |||
| 9502 | # (from http://www.zuggsoft.com/zchat/zchatprot.htm) | ||
| 9503 | # Like the Text Everybody command, but the Text is sent to a specific group of | ||
| 9504 | # connections. The Data field is: | ||
| 9505 | # <Stamp><GroupName><Text> | ||
| 9506 | # where GroupName is a 15-character string, padded with spaces on the left, that gives | ||
| 9507 | # the Name of the group. | ||
| 9508 | $groupFormat = sprintf('%15s', $group); | ||
| 9509 | } | ||
| 9510 | |||
| 9511 | return $groupFormat; | ||
| 9512 | } | ||
| 9513 | |||
| 9514 | sub newChatWin { | ||
| 9515 | |||
| 9516 | # Called by various functions | ||
| 9517 | # Opens a task window for this task, by calling the usual ->openWin() | ||
| 9518 | # Also calls $self->setChatWinTitle to change the window's title to something like | ||
| 9519 | # 'Chat: Alice > Bob' | ||
| 9520 | # | ||
| 9521 | # Expected arguments | ||
| 9522 | # (none besides $self) | ||
| 9523 | # | ||
| 9524 | # Return values | ||
| 9525 | # 'undef' on improper arguments | ||
| 9526 | # Otherwise, returns the result of the call to $self->openWin | ||
| 9527 | |||
| 9528 | my ($self, $check) = @_; | ||
| 9529 | |||
| 9530 | # Local variables | ||
| 9531 | my $result; | ||
| 9532 | |||
| 9533 | # Check for improper arguments | ||
| 9534 | if (defined $check) { | ||
| 9535 | |||
| 9536 | return $axmud::CLIENT->writeImproper($self->_objClass . '->newChatWin', @_); | ||
| 9537 | } | ||
| 9538 | |||
| 9539 | $result = $self->openWin($self->winmap, 'grid'); | ||
| 9540 | if ($result) { | ||
| 9541 | |||
| 9542 | # Update the window title to show who is calling whom | ||
| 9543 | $self->setChatWinTitle(); | ||
| 9544 | } | ||
| 9545 | |||
| 9546 | return $result; | ||
| 9547 | } | ||
| 9548 | |||
| 9549 | sub getVersion { | ||
| 9550 | |||
| 9551 | # Called by various functions | ||
| 9552 | # Returns a string in the form: | ||
| 9553 | # 'Axmud v1.0.0' | ||
| 9554 | # | ||
| 9555 | # Expected arguments | ||
| 9556 | # (none besides $self) | ||
| 9557 | # | ||
| 9558 | # Return values | ||
| 9559 | # 'undef' on improper arguments | ||
| 9560 | # Otherwise, returns the string | ||
| 9561 | |||
| 9562 | my ($self, $check) = @_; | ||
| 9563 | |||
| 9564 | # Check for improper arguments | ||
| 9565 | if (defined $check) { | ||
| 9566 | |||
| 9567 | return $axmud::CLIENT->writeImproper($self->_objClass . '->getVersion', @_); | ||
| 9568 | } | ||
| 9569 | |||
| 9570 | return $axmud::SCRIPT . ' v' . $axmud::VERSION; | ||
| 9571 | } | ||
| 9572 | |||
| 9573 | sub prepareIcon { | ||
| 9574 | |||
| 9575 | # Called by $self->setIcon, ->callEstablishmentData and ->receiveEstablishmentData | ||
| 9576 | # Loads the contents of an icon file, and sends it the chat contact via an 'ICON' | ||
| 9577 | # instruction | ||
| 9578 | # We assume that the file really exists and is really in Window bitmap format | ||
| 9579 | # | ||
| 9580 | # Expected arguments | ||
| 9581 | # $filePath - The full filepath of the icon to send | ||
| 9582 | # | ||
| 9583 | # Return values | ||
| 9584 | # 'undef' on improper arguments or if the file can't be opend | ||
| 9585 | # 1 otherwise | ||
| 9586 | |||
| 9587 | my ($self, $filePath, $check) = @_; | ||
| 9588 | |||
| 9589 | # Local variables | ||
| 9590 | my ($fileHandle, $data); | ||
| 9591 | |||
| 9592 | # Check for improper arguments | ||
| 9593 | if (! defined $filePath || defined $check) { | ||
| 9594 | |||
| 9595 | return $axmud::CLIENT->writeImproper($self->_objClass . '->prepareIcon', @_); | ||
| 9596 | } | ||
| 9597 | |||
| 9598 | # Try to open a filehandle to read the file | ||
| 9599 | if(! open($fileHandle, $filePath)) { | ||
| 9600 | |||
| 9601 | $self->writeText( | ||
| 9602 | 'Could not open \'' . $filePath . '\': ' . $!, | ||
| 9603 | 'system', | ||
| 9604 | ); | ||
| 9605 | |||
| 9606 | return undef; | ||
| 9607 | } | ||
| 9608 | |||
| 9609 | # Read the contents of the file | ||
| 9610 | sysread($fileHandle, $data, -s $filePath); | ||
| 9611 | |||
| 9612 | # Send the contents to the chat contact via a 'ICON' opcode | ||
| 9613 | $self->sendCmd( | ||
| 9614 | $self->ivShow('constOptHash', 'ICON'), | ||
| 9615 | $data, | ||
| 9616 | ); | ||
| 9617 | |||
| 9618 | # Tidy up | ||
| 9619 | close($fileHandle); | ||
| 9620 | |||
| 9621 | # Store which icon file is being used in this chat session | ||
| 9622 | $self->ivPoke('localIconFile', $filePath); | ||
| 9623 | |||
| 9624 | return 1; | ||
| 9625 | } | ||
| 9626 | |||
| 9627 | sub terminateChatSession { | ||
| 9628 | |||
| 9629 | # Called by various functions | ||
| 9630 | # Terminates the chat session. Closes sockets and the task window, updates IVs and halts | ||
| 9631 | # the task (unless it is the lead Chat task, which should continue running in order to | ||
| 9632 | # listen out for incoming calls) | ||
| 9633 | # | ||
| 9634 | # Expected arguments | ||
| 9635 | # (none besides $self) | ||
| 9636 | # | ||
| 9637 | # Return values | ||
| 9638 | # 'undef' | ||
| 9639 | |||
| 9640 | my ($self, $check) = @_; | ||
| 9641 | |||
| 9642 | # Check for improper arguments | ||
| 9643 | if (defined $check) { | ||
| 9644 | |||
| 9645 | return $axmud::CLIENT->writeImproper($self->_objClass . '->terminateChatSession', @_); | ||
| 9646 | } | ||
| 9647 | |||
| 9648 | # Close the connection | ||
| 9649 | close $self->clientSocket; | ||
| 9650 | |||
| 9651 | # Remove the Glib::IO callback | ||
| 9652 | if ($self->ioWatchID) { | ||
| 9653 | |||
| 9654 | Glib::Source->remove($self->ioWatchID); | ||
| 9655 | } | ||
| 9656 | |||
| 9657 | # Shut down snooping | ||
| 9658 | $self->stopSnooped(); | ||
| 9659 | |||
| 9660 | # Mark the session as closed | ||
| 9661 | $self->ivPoke('sessionFlag', FALSE); | ||
| 9662 | $self->ivPoke('connectionClosedFlag', TRUE); | ||
| 9663 | $self->ivUndef('chatContactObj'); | ||
| 9664 | |||
| 9665 | # Discard information about the connection | ||
| 9666 | $self->ivUndef('clientSocket'); | ||
| 9667 | $self->ivUndef('chatType'); | ||
| 9668 | $self->ivUndef('ioWatchID'); | ||
| 9669 | $self->ivUndef('timeoutID'); | ||
| 9670 | $self->ivUndef('pendingOpCode'); | ||
| 9671 | $self->ivUndef('lastInvalidOpCode'); | ||
| 9672 | $self->ivUndef('pendingDataSize'); | ||
| 9673 | $self->ivUndef('dataBuffer'); | ||
| 9674 | |||
| 9675 | $self->ivUndef('remoteIcon'); | ||
| 9676 | $self->ivUndef('remoteIconScaled'); | ||
| 9677 | $self->ivUndef('remoteName'); | ||
| 9678 | $self->ivUndef('remoteIP'); | ||
| 9679 | $self->ivUndef('remotePort'); | ||
| 9680 | $self->ivUndef('remoteEmail'); | ||
| 9681 | $self->ivUndef('remoteStamp'); | ||
| 9682 | $self->ivUndef('remoteVersion'); | ||
| 9683 | $self->ivPoke('remoteStatus', 0); | ||
| 9684 | $self->ivUndef('remoteZChatID'); | ||
| 9685 | $self->ivUndef('remotePublicKey'); | ||
| 9686 | |||
| 9687 | # Reset other IVs - in case this is the lead Chat task, we don't want settings from this | ||
| 9688 | # chat session interfering with the next one | ||
| 9689 | $self->ivPoke('entryMode', 'chat'); | ||
| 9690 | $self->ivPoke('servingFlag', FALSE); | ||
| 9691 | |||
| 9692 | $self->ivUndef('pingTime'); | ||
| 9693 | $self->ivUndef('pingStamp'); | ||
| 9694 | $self->ivUndef('fileDir'); | ||
| 9695 | $self->ivUndef('fileName'); | ||
| 9696 | $self->ivUndef('fileHandle'); | ||
| 9697 | $self->ivUndef('fileTotalSize'); | ||
| 9698 | $self->ivUndef('fileSize'); | ||
| 9699 | |||
| 9700 | # If this is the lead Chat task, assign a new one (if there are any other lead tasks) | ||
| 9701 | if ($self->leadTaskFlag) { | ||
| 9702 | |||
| 9703 | $self->assignLeadTask(); | ||
| 9704 | # Close the task window, if it is open (which it should be) | ||
| 9705 | if ($self->taskWinFlag) { | ||
| 9706 | |||
| 9707 | $self->closeWin(); | ||
| 9708 | } | ||
| 9709 | } | ||
| 9710 | |||
| 9711 | # If this not the lead Chat task (or is no longer the lead Chat task), halt the task. | ||
| 9712 | # (Chat tasks which aren't the lead task don't run when there is no chat session in | ||
| 9713 | # progress) | ||
| 9714 | if (! $self->leadTaskFlag) { | ||
| 9715 | |||
| 9716 | $self->ivPoke('shutdownFlag', TRUE); | ||
| 9717 | |||
| 9718 | } else { | ||
| 9719 | |||
| 9720 | # Reset the IV ->chatType (must be 'undef', or $self->receiveEstablishmentData won't | ||
| 9721 | # know that it's supposed to be looking for a new header) | ||
| 9722 | $self->ivUndef('chatType'); | ||
| 9723 | # Also reset the last invalid opcode received - it's of no relevance in the next chat | ||
| 9724 | # session that might open | ||
| 9725 | $self->ivUndef('lastInvalidOpCode'); | ||
| 9726 | } | ||
| 9727 | |||
| 9728 | return undef; | ||
| 9729 | } | ||
| 9730 | |||
| 9731 | # Supplementary functions called by $self->dispatchCmd | ||
| 9732 | |||
| 9733 | sub changeRemoteName { | ||
| 9734 | |||
| 9735 | # Called by ->dispatchCmd in response to the 'NAME_CHANGE' opcode | ||
| 9736 | # Also called by $self->callEstablishmentData | ||
| 9737 | # | ||
| 9738 | # Stores the nickname of the chat contact | ||
| 9739 | # | ||
| 9740 | # Expected arguements | ||
| 9741 | # $name - The chat contact's nickname | ||
| 9742 | # | ||
| 9743 | # Optional arguments | ||
| 9744 | # $quietFlag - If set to TRUE, does not print anything in the task window (otherwise | ||
| 9745 | # 'undef') | ||
| 9746 | # | ||
| 9747 | # Return values | ||
| 9748 | # 'undef' on improper arguments | ||
| 9749 | # 1 otherwise | ||
| 9750 | |||
| 9751 | my ($self, $name, $quietFlag, $check) = @_; | ||
| 9752 | |||
| 9753 | # Local variables | ||
| 9754 | my $oldName; | ||
| 9755 | |||
| 9756 | # Check for improper arguments | ||
| 9757 | if (! defined $name || defined $check) { | ||
| 9758 | |||
| 9759 | return $axmud::CLIENT->writeImproper($self->_objClass . '->changeRemoteName', @_); | ||
| 9760 | } | ||
| 9761 | |||
| 9762 | $oldName = $self->remoteName; | ||
| 9763 | $self->ivPoke('remoteName', $name); | ||
| 9764 | |||
| 9765 | if (! $quietFlag) { | ||
| 9766 | |||
| 9767 | $self->writeText( | ||
| 9768 | $oldName . ' is now known as ' . $name, | ||
| 9769 | 'system', | ||
| 9770 | ); | ||
| 9771 | } | ||
| 9772 | |||
| 9773 | # Update the window title to show who is calling whom | ||
| 9774 | $self->setChatWinTitle(); | ||
| 9775 | |||
| 9776 | return 1; | ||
| 9777 | } | ||
| 9778 | |||
| 9779 | sub sendConnectionList { | ||
| 9780 | |||
| 9781 | # Called by $self->dispatchCmd in response to the 'REQUEST_CONNECTIONS' and | ||
| 9782 | # 'PEEK_CONNECTIONS' opcodes | ||
| 9783 | # Sends a list of connections which are marked as 'public' (not including this connection) | ||
| 9784 | # | ||
| 9785 | # Expected arguments | ||
| 9786 | # (none besides $self) | ||
| 9787 | # | ||
| 9788 | # Return values | ||
| 9789 | # 'undef' on improper arguments | ||
| 9790 | # 1 otherwise | ||
| 9791 | |||
| 9792 | my ($self, $check) = @_; | ||
| 9793 | |||
| 9794 | # Local variables | ||
| 9795 | my $data; | ||
| 9796 | |||
| 9797 | # Check for improper arguments | ||
| 9798 | if (defined $check) { | ||
| 9799 | |||
| 9800 | return $axmud::CLIENT->writeImproper($self->_objClass . '->sendConnectionList', @_); | ||
| 9801 | } | ||
| 9802 | |||
| 9803 | # Find all Chat tasks whose connections are marked as 'public'. Don't include this task's | ||
| 9804 | # connection, because this is the chat peer that sent the CHAT_REQUEST_CONNECTIONS opcode | ||
| 9805 | foreach my $taskObj ($self->session->ivValues('currentTaskHash')) { | ||
| 9806 | |||
| 9807 | if ( | ||
| 9808 | $taskObj->name eq 'chat_task' | ||
| 9809 | && $taskObj ne $self | ||
| 9810 | && $taskObj->publicConnectionFlag | ||
| 9811 | # Special case: 3 chat clients, all operating from the same IP address (with the | ||
| 9812 | # same default port) | ||
| 9813 | # Alice, is listening on port 4050. Both Bob and Charlie establish public | ||
| 9814 | # connections with Alice, but neither Bob nor Charlie are listening for incoming | ||
| 9815 | # calls | ||
| 9816 | # Bob asks Alice for her list of public connections. Alice replies that she's | ||
| 9817 | # talking to Charlie, whose remote IP/port is advertised as 127.0.0.1 4050 | ||
| 9818 | # (because when Charlie is not listening for calls, he advertises his port as | ||
| 9819 | # 4050) | ||
| 9820 | # However, 127.0.0.1 4050 is also Bob's IP and port, so Bob receives his own IP and | ||
| 9821 | # port (which could be somewhat confusing) | ||
| 9822 | # The solution is not to send details of Charlie's advertised IP/port if they are | ||
| 9823 | # the same as the one used by Bob | ||
| 9824 | && ( | ||
| 9825 | # Bob's / Charlie's advertised IPs not the same (or either is unknown) | ||
| 9826 | ! $taskObj->remoteIP | ||
| 9827 | || ! $self->remoteIP | ||
| 9828 | || $taskObj->remoteIP ne $self->remoteIP | ||
| 9829 | # Bob's / Charlie's advertised ports not the same (or either is unknown) | ||
| 9830 | || ! $taskObj->remotePort | ||
| 9831 | || ! $self->remotePort | ||
| 9832 | || $taskObj->remotePort != $self->remotePort | ||
| 9833 | ) | ||
| 9834 | ) { | ||
| 9835 | # (from http://tintin.sourceforge.io/manual/chatprotocol.php) | ||
| 9836 | # <CHAT_CONNECTION_LIST><address>,<port>,<address>,<port><CHAT_END_OF_COMMAND> | ||
| 9837 | # The receiver needs to put all the IPs and port numbers of the public connections | ||
| 9838 | # in a comma delimited string and send them back as a connection list. | ||
| 9839 | # | ||
| 9840 | # (from http://www.zuggsoft.com/zchat/zchatprot.htm) | ||
| 9841 | # The response to the Request Connections command above. The Data sent by the | ||
| 9842 | # receiver is: | ||
| 9843 | # <IPAddr>,<Port>,<IPAddr>,<Port> etc | ||
| 9844 | # If there is no IP Address for a connection, the string "<Unknown>" is sent in | ||
| 9845 | # place of the IP Address field. For example, the Data field might look like: | ||
| 9846 | # 192.168.0.2,4050,<Unknown>,4050,192.168.0.1,4000 | ||
| 9847 | if ($data) { | ||
| 9848 | $data .= ','; | ||
| 9849 | } else { | ||
| 9850 | $data = ''; | ||
| 9851 | } | ||
| 9852 | |||
| 9853 | if ($taskObj->remoteIP) { | ||
| 9854 | $data .= $taskObj->remoteIP; | ||
| 9855 | } else { | ||
| 9856 | $data .= '<Unknown>'; | ||
| 9857 | } | ||
| 9858 | |||
| 9859 | if ($taskObj->remotePort) { | ||
| 9860 | $data .= ',' . $taskObj->remotePort; | ||
| 9861 | } else { | ||
| 9862 | $data .= ',' . '<Unknown>'; | ||
| 9863 | } | ||
| 9864 | } | ||
| 9865 | } | ||
| 9866 | |||
| 9867 | # If there is at least one public connection, send it; otherwise, don't send any response at | ||
| 9868 | # all | ||
| 9869 | if ($data) { | ||
| 9870 | |||
| 9871 | if ($self->pendingOpCode == $self->ivShow('constOptHash', 'REQUEST_CONNECTIONS')) { | ||
| 9872 | |||
| 9873 | $self->sendCmd( | ||
| 9874 | $self->ivShow('constOptHash', 'CONNECTION_LIST'), | ||
| 9875 | $data, | ||
| 9876 | ); | ||
| 9877 | |||
| 9878 | } else { | ||
| 9879 | |||
| 9880 | $self->sendCmd( | ||
| 9881 | $self->ivShow('constOptHash', 'PEEK_LIST'), | ||
| 9882 | $data, | ||
| 9883 | ); | ||
| 9884 | } | ||
| 9885 | } | ||
| 9886 | |||
| 9887 | return 1; | ||
| 9888 | } | ||
| 9889 | |||
| 9890 | sub reviewConnectionList { | ||
| 9891 | |||
| 9892 | # Called by $self->dispatchCmd in response to the 'CONNECTION_LIST' opcode | ||
| 9893 | # Reviews a list of the chat contact's public connections which we've just received | ||
| 9894 | # Try to connect to any of them with which we're not already connected | ||
| 9895 | # | ||
| 9896 | # Expected arguments | ||
| 9897 | # $data - A string containing the chat contact's public connections, in the form | ||
| 9898 | # described below | ||
| 9899 | # | ||
| 9900 | # Return values | ||
| 9901 | # 'undef' on improper arguments | ||
| 9902 | # 1 otherwise | ||
| 9903 | |||
| 9904 | my ($self, $data, $check) = @_; | ||
| 9905 | |||
| 9906 | # Local variables | ||
| 9907 | my (@taskList, @dataList); | ||
| 9908 | |||
| 9909 | # Check for improper arguments | ||
| 9910 | if (defined $check) { | ||
| 9911 | |||
| 9912 | return $axmud::CLIENT->writeImproper($self->_objClass . '->reviewConnectionList', @_); | ||
| 9913 | } | ||
| 9914 | |||
| 9915 | # Get a list of all tasks, including this one | ||
| 9916 | @taskList = $self->findAllTasks(); | ||
| 9917 | |||
| 9918 | # (from http://tintin.sourceforge.io/manual/chatprotocol.php) | ||
| 9919 | # <CHAT_CONNECTION_LIST><address>,<port>,<address>,<port><CHAT_END_OF_COMMAND> | ||
| 9920 | # The receiver needs to put all the IPs and port numbers of the public connections in a | ||
| 9921 | # comma delimited string and send them back as a connection list. | ||
| 9922 | # | ||
| 9923 | # (from http://www.zuggsoft.com/zchat/zchatprot.htm) | ||
| 9924 | # The response to the Request Connections command above. The Data sent by the receiver is: | ||
| 9925 | # <IPAddr>,<Port>,<IPAddr>,<Port> etc | ||
| 9926 | # If there is no IP Address for a connection, the string "<Unknown>" is sent in place of the | ||
| 9927 | # IP Address field. For example, the Data field might look like: | ||
| 9928 | # 192.168.0.2,4050,<Unknown>,4050,192.168.0.1,4000 | ||
| 9929 | |||
| 9930 | # Split $data into a list in the form (ip, port, ip, port...) | ||
| 9931 | @dataList = split(m/,/, $data); | ||
| 9932 | |||
| 9933 | do { | ||
| 9934 | |||
| 9935 | my ($ip, $port, $connectedFlag, $newTaskObj); | ||
| 9936 | |||
| 9937 | $ip = shift @dataList; | ||
| 9938 | $port = shift @dataList; | ||
| 9939 | |||
| 9940 | if ($ip && $ip ne '<Unknown>' && $port && $port ne '<Unknown>') { | ||
| 9941 | |||
| 9942 | # Are we already connected to someone at this address? | ||
| 9943 | OUTER: foreach my $taskObj (@taskList) { | ||
| 9944 | |||
| 9945 | if ( | ||
| 9946 | $taskObj->sessionFlag | ||
| 9947 | && $taskObj->remoteIP | ||
| 9948 | && $taskObj->remoteIP eq $ip | ||
| 9949 | && $taskObj->remotePort | ||
| 9950 | && $taskObj->remotePort == $port | ||
| 9951 | ) { | ||
| 9952 | # We are already connected | ||
| 9953 | $connectedFlag = TRUE; | ||
| 9954 | last OUTER; | ||
| 9955 | } | ||
| 9956 | } | ||
| 9957 | |||
| 9958 | if (! $connectedFlag) { | ||
| 9959 | |||
| 9960 | # We're not already connected to this address. Create a new Chat task which, | ||
| 9961 | # when it initialises, will make the connection | ||
| 9962 | $newTaskObj = Games::Axmud::Task::Chat->new($self->session, 'current'); | ||
| 9963 | if ($newTaskObj) { | ||
| 9964 | |||
| 9965 | # Tell the new task to make a call to the specified ip/port, when its | ||
| 9966 | # ->init function is called | ||
| 9967 | # Use the same protocol as the current connection | ||
| 9968 | $newTaskObj->ivPoke('makeCallOnInitFlag', TRUE); | ||
| 9969 | if ($self->chatType == $self->ivShow('constOptHash', 'MM')) { | ||
| 9970 | $newTaskObj->ivPoke('makeCallOnInitType', 'MM'); | ||
| 9971 | } else { | ||
| 9972 | $newTaskObj->ivPoke('makeCallOnInitType', 'ZCHAT'); | ||
| 9973 | } | ||
| 9974 | |||
| 9975 | $newTaskObj->ivPoke('makeCallOnInitIP', $ip); | ||
| 9976 | $newTaskObj->ivPoke('makeCallOnInitPort', $port); | ||
| 9977 | |||
| 9978 | $self->writeText( | ||
| 9979 | 'Making conference call to ' . $ip . ' ' . $port . '...', | ||
| 9980 | 'system', | ||
| 9981 | ); | ||
| 9982 | } | ||
| 9983 | } | ||
| 9984 | } | ||
| 9985 | |||
| 9986 | } until (! @dataList); | ||
| 9987 | |||
| 9988 | return 1; | ||
| 9989 | } | ||
| 9990 | |||
| 9991 | sub processTextMsg { | ||
| 9992 | |||
| 9993 | # Called by $self->dispatchCmd for the opcodes 'TEXT_EVERYBODY', 'TEXT_PERSONAL' and | ||
| 9994 | # 'TEXT_GROUP' | ||
| 9995 | # | ||
| 9996 | # Processes a text communication (i.e. a chat or an emote) which has been received from the | ||
| 9997 | # chat contact | ||
| 9998 | # In zChat sessions, checks the stamp. Also, if $self->servingFlag is set to TRUE, echoes | ||
| 9999 | # TEXT_EVERYBODY and TEXT_GROUP communications to other Chat tasks | ||
| 10000 | # | ||
| 10001 | # Expected arguments | ||
| 10002 | # $data - The text received | ||
| 10003 | # | ||
| 10004 | # Return values | ||
| 10005 | # 'undef' on improper arguments or if the message originated from this Chat task, in which | ||
| 10006 | # case we don't use it | ||
| 10007 | # 1 otherwise | ||
| 10008 | |||
| 10009 | my ($self, $data, $check) = @_; | ||
| 10010 | |||
| 10011 | # Local variables | ||
| 10012 | my ( | ||
| 10013 | $comm, $stamp, $group, $text, $stripText, | ||
| 10014 | @taskList, | ||
| 10015 | ); | ||
| 10016 | |||
| 10017 | # Check for improper arguments | ||
| 10018 | if (! defined $data || defined $check) { | ||
| 10019 | |||
| 10020 | return $axmud::CLIENT->writeImproper($self->_objClass . '->processTextMsg', @_); | ||
| 10021 | } | ||
| 10022 | |||
| 10023 | if ($self->chatType == $self->ivShow('constOptHash', 'ZCHAT')) { | ||
| 10024 | |||
| 10025 | # zChat (from http://www.zuggsoft.com/zchat/zchatprot.htm) | ||
| 10026 | # StampedText has the format | ||
| 10027 | # <Stamp><Text> | ||
| 10028 | # where Stamp is a 4-byte session ID number. When Sending, send your Stamp Code, which | ||
| 10029 | # is the random number you generated and broadcast when zChat first started. If the | ||
| 10030 | # received Stamp value matches the Receivers Stamp ID, the message is ignored (since | ||
| 10031 | # it represents a message loop). | ||
| 10032 | # | ||
| 10033 | # In effect this means that, as communications get passed around from one zChat client | ||
| 10034 | # to the next, a communication we sent may end up getting sent back to us. If the | ||
| 10035 | # incoming communication uses our own stamp, ignore it | ||
| 10036 | $stamp = unpack('L', substr($data, 0, 4)); | ||
| 10037 | if ($stamp == $self->localZChatStamp) { | ||
| 10038 | |||
| 10039 | # This message was produced by us, so ignore it | ||
| 10040 | return undef; | ||
| 10041 | |||
| 10042 | } else { | ||
| 10043 | |||
| 10044 | # Remote the stamp from the incoming message | ||
| 10045 | $comm = substr($data, 4); | ||
| 10046 | } | ||
| 10047 | |||
| 10048 | } else { | ||
| 10049 | |||
| 10050 | # MudMaster protocol doesn't use stamps | ||
| 10051 | $comm = $data; | ||
| 10052 | } | ||
| 10053 | |||
| 10054 | if ($self->pendingOpCode == $self->ivShow('constOptHash', 'TEXT_GROUP')) { | ||
| 10055 | |||
| 10056 | # MM (from http://tintin.sourceforge.io/manual/chatprotocol.php) | ||
| 10057 | # <CHAT_TEXT_GROUP><group><text to send><CHAT_END_OF_COMMAND> | ||
| 10058 | # Used when you send text to a specific group of connections. Works basically the same | ||
| 10059 | # as the other text commands. The group name is a 15 character string. It *must* be 15 | ||
| 10060 | # characters long and pad it on the right with spaces to fill it out. | ||
| 10061 | # | ||
| 10062 | # zChat (from http://www.zuggsoft.com/zchat/zchatprot.htm) | ||
| 10063 | # Like the Text Everybody command, but the Text is sent to a specific group of | ||
| 10064 | # connections. The Data field is: | ||
| 10065 | # <Stamp><GroupName><Text> | ||
| 10066 | # where GroupName is a 15-character string, padded with spaces on the left, that gives | ||
| 10067 | # the Name of the group. The Sender formats the entire message to be displayed (like | ||
| 10068 | # "<Name> chats to the group <GroupName>: hello"). | ||
| 10069 | # The Receiver simply displays the message. | ||
| 10070 | |||
| 10071 | # Extract the <group> and <text_to_send> components | ||
| 10072 | $group = substr($comm, 0, 15); | ||
| 10073 | $text = substr($comm, 15); | ||
| 10074 | |||
| 10075 | # $group contains exactly 15 characters, padded with spaces on the left or right. | ||
| 10076 | # Trim the whitespace away | ||
| 10077 | $group = $axmud::CLIENT->trimWhitespace($group); | ||
| 10078 | |||
| 10079 | } else { | ||
| 10080 | |||
| 10081 | $text = $comm; | ||
| 10082 | } | ||
| 10083 | |||
| 10084 | # Display the communication in the task window | ||
| 10085 | Encode::from_to($text, $self->encoding, 'utf-8-strict'); | ||
| 10086 | $stripText = $self->stripAnsi($text); | ||
| 10087 | |||
| 10088 | # If an Axmud user types a smiley like :), Axmud will send <You chat to Alice, :)> rather | ||
| 10089 | # than <You chat to Alice, ':)> | ||
| 10090 | # Other clients probably won't do that, so check $stripText against smileys. If it ends in | ||
| 10091 | # a smiley, surrounded by quotes, strip the quotes | ||
| 10092 | OUTER: foreach my $smiley ($axmud::CLIENT->ivKeys('constChatSmileyHash')) { | ||
| 10093 | |||
| 10094 | my $modSmiley = quotemeta($smiley); | ||
| 10095 | if ($stripText =~ s/\'$modSmiley\'\s*$/$smiley/) { | ||
| 10096 | |||
| 10097 | # Once one smiley is found, no point checking the others | ||
| 10098 | last OUTER; | ||
| 10099 | } | ||
| 10100 | } | ||
| 10101 | |||
| 10102 | $self->writeText( | ||
| 10103 | $stripText, | ||
| 10104 | 'chat_in', | ||
| 10105 | ); | ||
| 10106 | |||
| 10107 | # In zChat sessions, echo CHAT_TEXT_EVERYBODY and CHAT_TEXT_GROUP to other Chat tasks that | ||
| 10108 | # are running, if allowed | ||
| 10109 | if ($self->servingFlag) { | ||
| 10110 | |||
| 10111 | if ($self->pendingOpCode == $self->ivShow('constOptHash', 'TEXT_EVERYBODY')) { | ||
| 10112 | |||
| 10113 | # Get a list of all running Chat tasks, except this one | ||
| 10114 | @taskList = $self->findOtherTasks(); | ||
| 10115 | |||
| 10116 | } elsif ($self->pendingOpCode == $self->ivShow('constOptHash', 'TEXT_GROUP')) { | ||
| 10117 | |||
| 10118 | # Get a list of all running Chat tasks in the specified group, except this one | ||
| 10119 | foreach my $taskObj ($self->session->ivValues('currentTaskHash')) { | ||
| 10120 | |||
| 10121 | if ( | ||
| 10122 | $taskObj->name eq 'chat_task' | ||
| 10123 | && $taskObj ne $self | ||
| 10124 | && $taskObj->localGroup && $taskObj->localGroup eq $group | ||
| 10125 | ) { | ||
| 10126 | push (@taskList, $taskObj); | ||
| 10127 | } | ||
| 10128 | } | ||
| 10129 | } | ||
| 10130 | |||
| 10131 | # Echo the communication to each selected Chat task | ||
| 10132 | foreach my $taskObj (@taskList) { | ||
| 10133 | |||
| 10134 | my $groupFormat; | ||
| 10135 | |||
| 10136 | if ($self->pendingOpCode == $self->ivShow('constOptHash', 'TEXT_EVERYBODY')) { | ||
| 10137 | |||
| 10138 | $taskObj->sendCmd( | ||
| 10139 | $self->pendingOpCode, # Value matching 'TEXT_EVERYBODY' | ||
| 10140 | $text, # Preserve ANSI formatting | ||
| 10141 | ); | ||
| 10142 | |||
| 10143 | $taskObj->writeText( | ||
| 10144 | $stripText, | ||
| 10145 | 'echo', | ||
| 10146 | ); | ||
| 10147 | |||
| 10148 | } else { | ||
| 10149 | |||
| 10150 | # Produce a string for the group, padded with spaces to the left or the right, | ||
| 10151 | # as appropriate (see comments above) | ||
| 10152 | $groupFormat = $self->formatGroup($group); | ||
| 10153 | |||
| 10154 | $taskObj->sendCmd( | ||
| 10155 | $self->pendingOpCode, # Value matching 'TEXT_GROUP' | ||
| 10156 | $groupFormat . $text, # Preserve ANSI formatting | ||
| 10157 | ); | ||
| 10158 | |||
| 10159 | $taskObj->writeText( | ||
| 10160 | $stripText, | ||
| 10161 | 'echo', | ||
| 10162 | ); | ||
| 10163 | } | ||
| 10164 | } | ||
| 10165 | } | ||
| 10166 | |||
| 10167 | return 1; | ||
| 10168 | } | ||
| 10169 | |||
| 10170 | sub displayRemoteMsg { | ||
| 10171 | |||
| 10172 | # Called by $self->dispatchCmd for the opcode 'MESSAGE' | ||
| 10173 | # Displays a message sent by the chat contact's client for our attention in a colour used | ||
| 10174 | # only for this purpose | ||
| 10175 | # | ||
| 10176 | # Expected arguments | ||
| 10177 | # $data - The text of the message received | ||
| 10178 | # | ||
| 10179 | # Return values | ||
| 10180 | # 'undef' on improper arguments | ||
| 10181 | # 1 otherwise | ||
| 10182 | |||
| 10183 | my ($self, $data, $check) = @_; | ||
| 10184 | |||
| 10185 | # Local variables | ||
| 10186 | my $stripData; | ||
| 10187 | |||
| 10188 | # Check for improper arguments | ||
| 10189 | if (! defined $data || defined $check) { | ||
| 10190 | |||
| 10191 | return $axmud::CLIENT->writeImproper($self->_objClass . '->displayRemoteMsg', @_); | ||
| 10192 | } | ||
| 10193 | |||
| 10194 | # Reencode the text and remove ANSI codes | ||
| 10195 | Encode::from_to($data, $self->encoding, 'utf-8-strict'); | ||
| 10196 | $stripData = $self->stripAnsi($data); | ||
| 10197 | |||
| 10198 | # Display the remote message | ||
| 10199 | $self->writeText( | ||
| 10200 | 'Message from ' . $self->remoteName . ' : ' . $stripData, | ||
| 10201 | 'remote', | ||
| 10202 | ); | ||
| 10203 | |||
| 10204 | return 1; | ||
| 10205 | } | ||
| 10206 | |||
| 10207 | sub receiveFile { | ||
| 10208 | |||
| 10209 | # Called by $self->dispatchCmd in response to the 'FILE_START' opcode | ||
| 10210 | # Asks the user if they want to accept a file. If so, start the transfer | ||
| 10211 | # | ||
| 10212 | # Expected arguments | ||
| 10213 | # $data - The data component of the received message, containing details about the file | ||
| 10214 | # | ||
| 10215 | # Return values | ||
| 10216 | # 'undef' on improper arguments, if the connection hasn't been negotiated yet, if a file | ||
| 10217 | # transfer is already in progress, if the user rejects the file transfer or cancels | ||
| 10218 | # when asked where it should be saved | ||
| 10219 | # 1 otherwise | ||
| 10220 | |||
| 10221 | my ($self, $data, $check) = @_; | ||
| 10222 | |||
| 10223 | # Local variables | ||
| 10224 | my ($file, $length, $result, $fileName); | ||
| 10225 | |||
| 10226 | # Check for improper arguments | ||
| 10227 | if (! defined $data || defined $check) { | ||
| 10228 | |||
| 10229 | return $axmud::CLIENT->writeImproper($self->_objClass . '->receiveFile', @_); | ||
| 10230 | } | ||
| 10231 | |||
| 10232 | # Refuse to accept the file if the connection hasn't been negotiated yet | ||
| 10233 | if (! $self->remoteName) { | ||
| 10234 | |||
| 10235 | $self->sendCmd( | ||
| 10236 | $self->ivShow('constOptHash', 'FILE_DENY'), | ||
| 10237 | 'Waiting to negotiate connection.', | ||
| 10238 | ); | ||
| 10239 | |||
| 10240 | return undef; | ||
| 10241 | } | ||
| 10242 | |||
| 10243 | # It shouldn't be possible to be asked to receive a file, while another transfer is still in | ||
| 10244 | # progress. But we'll check anyway | ||
| 10245 | if ($self->fileDir) { | ||
| 10246 | |||
| 10247 | $self->sendCmd( | ||
| 10248 | $self->ivShow('constOptHash', 'FILE_DENY'), | ||
| 10249 | 'A file transfer is already in progress.', | ||
| 10250 | ); | ||
| 10251 | |||
| 10252 | return undef; | ||
| 10253 | } | ||
| 10254 | |||
| 10255 | ($file, $length) = split(',', $data); | ||
| 10256 | |||
| 10257 | # Prompt the user for permission to receive the file | ||
| 10258 | if ($self->winObj && ! $self->tableObj) { | ||
| 10259 | |||
| 10260 | $result = $self->winObj->showMsgDialogue( | ||
| 10261 | 'Chat task', | ||
| 10262 | 'question', | ||
| 10263 | $self->remoteName . ' wants to send you \'' . $file . '\' (length ' . $length | ||
| 10264 | . ' bytes). Accept it?', | ||
| 10265 | 'yes-no', | ||
| 10266 | 'no', | ||
| 10267 | ); | ||
| 10268 | |||
| 10269 | } else { | ||
| 10270 | |||
| 10271 | $result = $self->session->mainWin->showMsgDialogue( | ||
| 10272 | 'Chat task', | ||
| 10273 | 'question', | ||
| 10274 | $self->remoteName . ' wants to send you \'' . $file . '\' (length ' . $length | ||
| 10275 | . ' bytes). Accept it?', | ||
| 10276 | 'yes-no', | ||
| 10277 | 'no', | ||
| 10278 | ); | ||
| 10279 | } | ||
| 10280 | |||
| 10281 | if ($result ne 'yes') { | ||
| 10282 | |||
| 10283 | $self->sendCmd( | ||
| 10284 | $self->ivShow('constOptHash', 'FILE_DENY'), | ||
| 10285 | $self->localName . ' rejected the file transfer.', | ||
| 10286 | ); | ||
| 10287 | |||
| 10288 | return undef; | ||
| 10289 | } | ||
| 10290 | |||
| 10291 | # Prompt the user to choose where to save the file | ||
| 10292 | if ($self->winObj && ! $self->tableObj) { | ||
| 10293 | |||
| 10294 | $fileName = $self->winObj->showFileChooser( | ||
| 10295 | 'Save file as', | ||
| 10296 | 'save', | ||
| 10297 | ); | ||
| 10298 | |||
| 10299 | } else { | ||
| 10300 | |||
| 10301 | $fileName = $self->session->mainWin->showFileChooser( | ||
| 10302 | 'Save file as', | ||
| 10303 | 'save', | ||
| 10304 | ); | ||
| 10305 | } | ||
| 10306 | |||
| 10307 | if (! $fileName) { | ||
| 10308 | |||
| 10309 | $self->sendCmd( | ||
| 10310 | $self->ivShow('constOptHash', 'FILE_DENY'), | ||
| 10311 | $self->localName . ' rejected the file transfer.', | ||
| 10312 | ); | ||
| 10313 | |||
| 10314 | return undef; | ||
| 10315 | } | ||
| 10316 | |||
| 10317 | if (! open ($self->{fileHandle}, ">$fileName")) { | ||
| 10318 | |||
| 10319 | $self->writeText( | ||
| 10320 | 'Could not open \'' . $fileName . '\': ' . $!, | ||
| 10321 | 'system', | ||
| 10322 | ); | ||
| 10323 | |||
| 10324 | $self->sendCmd( | ||
| 10325 | $self->ivShow('constOptHash', 'FILE_DENY'), | ||
| 10326 | $self->localName . ' rejected the file transfer.', | ||
| 10327 | ); | ||
| 10328 | |||
| 10329 | return undef; | ||
| 10330 | } | ||
| 10331 | |||
| 10332 | # Start the transfer of the file | ||
| 10333 | $self->ivPoke('fileDir', $self->ivShow('constOptHash', 'RECEIVING')); | ||
| 10334 | $self->ivPoke('fileName', $fileName); | ||
| 10335 | $self->ivPoke('fileTotalSize', $length); | ||
| 10336 | $self->ivPoke('fileSize', 0); | ||
| 10337 | |||
| 10338 | $self->writeText( | ||
| 10339 | 'Started transfer of file \'' . $fileName . '\'', | ||
| 10340 | 'system', | ||
| 10341 | ); | ||
| 10342 | |||
| 10343 | $self->sendCmd( | ||
| 10344 | $self->ivShow('constOptHash', 'FILE_BLOCK_REQUEST'), | ||
| 10345 | '', | ||
| 10346 | ); | ||
| 10347 | |||
| 10348 | return 1; | ||
| 10349 | } | ||
| 10350 | |||
| 10351 | sub fileSendNextBlock { | ||
| 10352 | |||
| 10353 | # Called by $self->dispatchCmd in response to the 'FILE_BLOCK_REQUEST' opcode | ||
| 10354 | # Sends the next portion of the file to the chat contact | ||
| 10355 | # | ||
| 10356 | # Expected arguments | ||
| 10357 | # (none besides $self) | ||
| 10358 | # | ||
| 10359 | # Return values | ||
| 10360 | # 'undef' on improper arguments, if there is no file transfer in progress or if there is | ||
| 10361 | # an error reading the file | ||
| 10362 | # 1 otherwise | ||
| 10363 | |||
| 10364 | my ($self, $check) = @_; | ||
| 10365 | |||
| 10366 | # Local variables | ||
| 10367 | my ($remainingSize, $blockSize, $bytesToRead, $buffer, $nRead, $block); | ||
| 10368 | |||
| 10369 | # Check for improper arguments | ||
| 10370 | if (defined $check) { | ||
| 10371 | |||
| 10372 | return $axmud::CLIENT->writeImproper($self->_objClass . '->fileSendNextBlock', @_); | ||
| 10373 | } | ||
| 10374 | |||
| 10375 | # It shouldn't be possible to receive a block when a file transfer isn't in progress, but | ||
| 10376 | # we'll check anyway | ||
| 10377 | if (! defined $self->fileDir) { | ||
| 10378 | |||
| 10379 | $self->sendCmd( | ||
| 10380 | $self->ivShow('constOptHash', 'FILE_CANCEL'), | ||
| 10381 | '', | ||
| 10382 | ); | ||
| 10383 | |||
| 10384 | return undef; | ||
| 10385 | } | ||
| 10386 | |||
| 10387 | # Update our variables | ||
| 10388 | $remainingSize = $self->fileTotalSize - $self->fileSize; | ||
| 10389 | if ($remainingSize == 0) { | ||
| 10390 | |||
| 10391 | $self->sendCmd( | ||
| 10392 | $self->ivShow('constOptHash', 'FILE_END'), | ||
| 10393 | '', | ||
| 10394 | ); | ||
| 10395 | |||
| 10396 | $self->fileStop( | ||
| 10397 | 'Finished transfer of file \'' . $self->fileName . '\'', | ||
| 10398 | ); | ||
| 10399 | |||
| 10400 | return 1; | ||
| 10401 | } | ||
| 10402 | |||
| 10403 | $blockSize = $self->chatType == $self->ivShow('constOptHash', 'MM') | ||
| 10404 | ? $self->ivShow('constOptHash', 'MM_FILE_BLOCK_SIZE') | ||
| 10405 | : $self->ivShow('constOptHash', 'ZCHAT_FILE_BLOCK_SIZE'); | ||
| 10406 | |||
| 10407 | $bytesToRead = $remainingSize < $blockSize | ||
| 10408 | ? $remainingSize | ||
| 10409 | : $blockSize; | ||
| 10410 | |||
| 10411 | $nRead = sysread($self->{fileHandle}, $buffer, $bytesToRead); | ||
| 10412 | if ($nRead != $bytesToRead) { | ||
| 10413 | |||
| 10414 | # Houston, we have a problem | ||
| 10415 | $self->sendCmd( | ||
| 10416 | $self->ivShow('constOptHash', 'MESSAGE'), | ||
| 10417 | 'Error while reading file', | ||
| 10418 | ); | ||
| 10419 | $self->sendCmd( | ||
| 10420 | $self->ivShow('constOptHash', 'FILE_CANCEL'), | ||
| 10421 | '', | ||
| 10422 | ); | ||
| 10423 | |||
| 10424 | $self->fileStop( | ||
| 10425 | 'Error while reading file. File transfer cancelled.', | ||
| 10426 | ); | ||
| 10427 | |||
| 10428 | return undef; | ||
| 10429 | |||
| 10430 | } else { | ||
| 10431 | |||
| 10432 | $block = $buffer . chr(0) x ($blockSize - $bytesToRead); | ||
| 10433 | |||
| 10434 | $self->sendCmd( | ||
| 10435 | $self->ivShow('constOptHash', 'FILE_BLOCK'), | ||
| 10436 | $block, | ||
| 10437 | ); | ||
| 10438 | |||
| 10439 | $self->ivPoke('fileSize', $self->fileSize + $bytesToRead); | ||
| 10440 | |||
| 10441 | return 1; | ||
| 10442 | } | ||
| 10443 | } | ||
| 10444 | |||
| 10445 | sub fileBlockReceived { | ||
| 10446 | |||
| 10447 | # Called by $self->dispatchCmd in response to the 'FILE_BLOCK' opcode | ||
| 10448 | # Receives a block of the file, adds it to previously received blocks, and asks for the next | ||
| 10449 | # block | ||
| 10450 | # | ||
| 10451 | # Expected arguments | ||
| 10452 | # $block - The file block received | ||
| 10453 | # | ||
| 10454 | # Return values | ||
| 10455 | # 'undef' on improper arguments or if there is no file transfer in progress | ||
| 10456 | # 1 otherwise | ||
| 10457 | |||
| 10458 | my ($self, $block, $check) = @_; | ||
| 10459 | |||
| 10460 | # Local variables | ||
| 10461 | my ($length, $remainingSize, $bytesToWrite); | ||
| 10462 | |||
| 10463 | # Check for improper arguments | ||
| 10464 | if (! defined $block || defined $check) { | ||
| 10465 | |||
| 10466 | return $axmud::CLIENT->writeImproper($self->_objClass . '->fileBlockReceived', @_); | ||
| 10467 | } | ||
| 10468 | |||
| 10469 | # It shouldn't be possible to receive a block when a file transfer isn't in progress, but | ||
| 10470 | # we'll check anyway | ||
| 10471 | if (! defined $self->fileDir) { | ||
| 10472 | |||
| 10473 | $self->sendCmd( | ||
| 10474 | $self->ivShow('constOptHash', 'FILE_CANCEL'), | ||
| 10475 | '', | ||
| 10476 | ); | ||
| 10477 | |||
| 10478 | return undef; | ||
| 10479 | } | ||
| 10480 | |||
| 10481 | # Update our variables | ||
| 10482 | $length = length($block); | ||
| 10483 | $remainingSize = $self->fileTotalSize - $self->fileSize; | ||
| 10484 | $bytesToWrite = $remainingSize < $length | ||
| 10485 | ? $remainingSize | ||
| 10486 | : $length; | ||
| 10487 | |||
| 10488 | # Add the received data to the file | ||
| 10489 | syswrite($self->{fileHandle}, $block, $bytesToWrite); | ||
| 10490 | $self->ivPoke('fileSize', $self->fileSize + $length); | ||
| 10491 | |||
| 10492 | # Ask for the next block | ||
| 10493 | $self->sendCmd( | ||
| 10494 | $self->ivShow('constOptHash', 'FILE_BLOCK_REQUEST'), | ||
| 10495 | '', | ||
| 10496 | ); | ||
| 10497 | |||
| 10498 | return 1; | ||
| 10499 | } | ||
| 10500 | |||
| 10501 | sub fileEnd { | ||
| 10502 | |||
| 10503 | # Called by $self->dispatchCmd in response to the 'FILE_END' opcode | ||
| 10504 | # Closes the filehandle used to create the local copy of the file and resets IVs | ||
| 10505 | # | ||
| 10506 | # Expected arguments | ||
| 10507 | # (none besides $self) | ||
| 10508 | # | ||
| 10509 | # Return values | ||
| 10510 | # 'undef' on improper arguments | ||
| 10511 | # 1 otherwise | ||
| 10512 | |||
| 10513 | my ($self, $check) = @_; | ||
| 10514 | |||
| 10515 | # Check for improper arguments | ||
| 10516 | if (defined $check) { | ||
| 10517 | |||
| 10518 | return $axmud::CLIENT->writeImproper($self->_objClass . '->fileEnd', @_); | ||
| 10519 | } | ||
| 10520 | |||
| 10521 | $self->writeText( | ||
| 10522 | 'Transfer of file ' . $self->fileName . ' finished.', | ||
| 10523 | 'system', | ||
| 10524 | ); | ||
| 10525 | |||
| 10526 | # Tidy up | ||
| 10527 | close($self->fileHandle); | ||
| 10528 | |||
| 10529 | $self->ivUndef('fileHandle'); | ||
| 10530 | $self->ivUndef('fileName'); | ||
| 10531 | $self->ivUndef('fileDir'); | ||
| 10532 | |||
| 10533 | return 1; | ||
| 10534 | } | ||
| 10535 | |||
| 10536 | sub fileStop { | ||
| 10537 | |||
| 10538 | # Called by $self->dispatchCmd in response to the 'FILE_CANCEL' and 'FILE_DENY' opcodes | ||
| 10539 | # The file transfer must be stopped, either because one of the parties aborted it or because | ||
| 10540 | # of an error | ||
| 10541 | # | ||
| 10542 | # Expected arguments | ||
| 10543 | # (none besides $self) | ||
| 10544 | # | ||
| 10545 | # Optional arguments | ||
| 10546 | # $errorMsg - The error message to display, if the calling function specified one | ||
| 10547 | # (if 'undef', a standard message is displayed) | ||
| 10548 | # | ||
| 10549 | # Return values | ||
| 10550 | # 'undef' on improper arguments or if we receive a 'FILE_CANCEL' message we don't need | ||
| 10551 | # 1 otherwise | ||
| 10552 | |||
| 10553 | my ($self, $errorMsg, $check) = @_; | ||
| 10554 | |||
| 10555 | # Check for improper arguments | ||
| 10556 | if (defined $check) { | ||
| 10557 | |||
| 10558 | return $axmud::CLIENT->writeImproper($self->_objClass . '->fileStop', @_); | ||
| 10559 | } | ||
| 10560 | |||
| 10561 | # At least one kind of client sends a 'FILE_CANCEL' in reply to our refusal to accept a | ||
| 10562 | # file. In this case, the file transfer was not initiated from here | ||
| 10563 | if (! defined $self->fileDir) { | ||
| 10564 | |||
| 10565 | return undef; | ||
| 10566 | } | ||
| 10567 | |||
| 10568 | # Display a confirmation when we are the ones sending the file | ||
| 10569 | if ($self->fileDir) { | ||
| 10570 | |||
| 10571 | if ($errorMsg) { | ||
| 10572 | |||
| 10573 | $self->writeText($errorMsg, 'system'); | ||
| 10574 | |||
| 10575 | } else { | ||
| 10576 | |||
| 10577 | $self->writeText( | ||
| 10578 | 'Transfer of file ' . $self->fileName . ' aborted by remote party.', | ||
| 10579 | 'system', | ||
| 10580 | ); | ||
| 10581 | } | ||
| 10582 | } | ||
| 10583 | |||
| 10584 | # Delete the (incomplete) portion of the local copy of the file when we are the ones | ||
| 10585 | # receiving the file | ||
| 10586 | if ($self->fileDir == $self->ivShow('constOptHash', 'RECEIVING')) { | ||
| 10587 | |||
| 10588 | unlink($self->fileName); | ||
| 10589 | } | ||
| 10590 | |||
| 10591 | # Tidy up | ||
| 10592 | close($self->fileHandle); | ||
| 10593 | |||
| 10594 | $self->ivUndef('fileHandle'); | ||
| 10595 | $self->ivUndef('fileName'); | ||
| 10596 | $self->ivUndef('fileDir'); | ||
| 10597 | |||
| 10598 | return 1; | ||
| 10599 | } | ||
| 10600 | |||
| 10601 | sub pingResponse { | ||
| 10602 | |||
| 10603 | # Called by $self->dispatchCmd in response to the 'PING_RESPONSE' opcode | ||
| 10604 | # Displays a message in the task window, confirming how long the ping took to arrive back | ||
| 10605 | # | ||
| 10606 | # Expected arguments | ||
| 10607 | # $data - The details sent by the chat contact's client (see below) | ||
| 10608 | # | ||
| 10609 | # Return values | ||
| 10610 | # 'undef' on improper arguments | ||
| 10611 | # 1 otherwise | ||
| 10612 | |||
| 10613 | my ($self, $data, $check) = @_; | ||
| 10614 | |||
| 10615 | # Local variables | ||
| 10616 | my ($elapsedSecs, $remoteStatus); | ||
| 10617 | |||
| 10618 | # Check for improper arguments | ||
| 10619 | if (! defined $data || defined $check) { | ||
| 10620 | |||
| 10621 | return $axmud::CLIENT->writeImproper($self->_objClass . '->pingResponse', @_); | ||
| 10622 | } | ||
| 10623 | |||
| 10624 | # (from http://tintin.sourceforge.io/manual/chatprotocol.php) | ||
| 10625 | # <CHAT_PING_RESPONSE><timing data><CHAT_END_OF_COMMAND> | ||
| 10626 | # When receiving a CHAT_PING_REQUEST you should send back the timing data. | ||
| 10627 | # | ||
| 10628 | # (from http://www.zuggsoft.com/zchat/zchatprot.htm) | ||
| 10629 | # Sent in response to the Ping Request. The Data field is the same data received from the | ||
| 10630 | # Ping Request. When the Sender of the Ping Request gets this data back, it can compare | ||
| 10631 | # the Clock value in the data field that is returned (which is the time when the initial | ||
| 10632 | # Ping Request was sent) to the current Clock value to determine how much time passed in | ||
| 10633 | # transit. | ||
| 10634 | |||
| 10635 | # It's possible there might be several pings going around. Check this is the one we're | ||
| 10636 | # expecting | ||
| 10637 | if ($data == $self->pingStamp) { | ||
| 10638 | |||
| 10639 | # Work out the elapsed time | ||
| 10640 | $elapsedSecs = $axmud::CLIENT->getTime() - $self->pingTime; | ||
| 10641 | |||
| 10642 | # Display confirmation, rounding to 3 decimal places | ||
| 10643 | if ($elapsedSecs < 0.001) { | ||
| 10644 | |||
| 10645 | $self->writeText( | ||
| 10646 | 'Ping received reply in less than 0.001 second(s)', | ||
| 10647 | 'system', | ||
| 10648 | ); | ||
| 10649 | |||
| 10650 | } else { | ||
| 10651 | |||
| 10652 | $self->writeText( | ||
| 10653 | 'Ping received reply in ' . sprintf('%.3f', $elapsedSecs) . ' second(s)', | ||
| 10654 | 'system', | ||
| 10655 | ); | ||
| 10656 | } | ||
| 10657 | } | ||
| 10658 | |||
| 10659 | return 1; | ||
| 10660 | } | ||
| 10661 | |||
| 10662 | sub showConnectionList { | ||
| 10663 | |||
| 10664 | # Called by $self->dispatchCmd in response to the 'PEEK_LIST' opcode | ||
| 10665 | # Shows a list of the chat contact's public connections in the task window | ||
| 10666 | # | ||
| 10667 | # Expected arguments | ||
| 10668 | # $data - A string containing the chat contact's public connections, in the form | ||
| 10669 | # described below | ||
| 10670 | # | ||
| 10671 | # Return values | ||
| 10672 | # 'undef' on improper arguments | ||
| 10673 | # 1 otherwise | ||
| 10674 | |||
| 10675 | my ($self, $data, $check) = @_; | ||
| 10676 | |||
| 10677 | # Local variables | ||
| 10678 | my (@taskList, @dataList); | ||
| 10679 | |||
| 10680 | # Check for improper arguments | ||
| 10681 | if (defined $check) { | ||
| 10682 | |||
| 10683 | return $axmud::CLIENT->writeImproper($self->_objClass . '->showConnectionList', @_); | ||
| 10684 | } | ||
| 10685 | |||
| 10686 | # Get a list of all tasks, including this one | ||
| 10687 | @taskList = $self->findAllTasks(); | ||
| 10688 | |||
| 10689 | # (from http://tintin.sourceforge.io/manual/chatprotocol.php) | ||
| 10690 | # <CHAT_CONNECTION_LIST><address>,<port>,<address>,<port><CHAT_END_OF_COMMAND> | ||
| 10691 | # The receiver needs to put all the IPs and port numbers of the public connections in a | ||
| 10692 | # comma delimited string and send them back as a connection list. | ||
| 10693 | # | ||
| 10694 | # (from http://www.zuggsoft.com/zchat/zchatprot.htm) | ||
| 10695 | # The response to the Request Connections command above. The Data sent by the receiver is: | ||
| 10696 | # <IPAddr>,<Port>,<IPAddr>,<Port> etc | ||
| 10697 | # If there is no IP Address for a connection, the string "<Unknown>" is sent in place of the | ||
| 10698 | # IP Address field. For example, the Data field might look like: | ||
| 10699 | # 192.168.0.2,4050,<Unknown>,4050,192.168.0.1,4000 | ||
| 10700 | |||
| 10701 | $self->writeText('List of public connections for \'' . $self->remoteName . '\''); | ||
| 10702 | |||
| 10703 | # Split $data into a list in the form (ip, port, ip, port...) | ||
| 10704 | @dataList = split(m/,/, $data); | ||
| 10705 | do { | ||
| 10706 | |||
| 10707 | my ($ip, $port); | ||
| 10708 | |||
| 10709 | $ip = shift @dataList; | ||
| 10710 | $port = shift @dataList; | ||
| 10711 | |||
| 10712 | $self->writeText(sprintf(' %-16.16s %-5.5s', $ip, $port)); | ||
| 10713 | |||
| 10714 | } until (! @dataList); | ||
| 10715 | |||
| 10716 | return 1; | ||
| 10717 | } | ||
| 10718 | |||
| 10719 | sub startSnooped { | ||
| 10720 | |||
| 10721 | # Called by $self->dispatchCmd in response to the 'SNOOP' opcode | ||
| 10722 | # Starts a snooping session, in which we send all received data to the chat contact(s) | ||
| 10723 | # | ||
| 10724 | # Expected arguments | ||
| 10725 | # (none besides $self) | ||
| 10726 | # | ||
| 10727 | # Return values | ||
| 10728 | # 'undef' on improper arguments or if snooping isn't currently allowed | ||
| 10729 | # 1 otherwise | ||
| 10730 | |||
| 10731 | my ($self, $check) = @_; | ||
| 10732 | |||
| 10733 | # Check for improper arguments | ||
| 10734 | if (defined $check) { | ||
| 10735 | |||
| 10736 | return $axmud::CLIENT->writeImproper($self->_objClass . '->startSnooped', @_); | ||
| 10737 | } | ||
| 10738 | |||
| 10739 | if (! $self->allowSnoopFlag) { | ||
| 10740 | |||
| 10741 | $self->sendCmd( | ||
| 10742 | $self->ivShow('constOptHash', 'MESSAGE'), | ||
| 10743 | $self->localName . ' has declined to allow you to snoop on their session.', | ||
| 10744 | ); | ||
| 10745 | |||
| 10746 | $self->writeText( | ||
| 10747 | $self->remoteName . ' tried to snoop you.', | ||
| 10748 | 'system', | ||
| 10749 | ); | ||
| 10750 | |||
| 10751 | return undef; | ||
| 10752 | |||
| 10753 | } else { | ||
| 10754 | |||
| 10755 | $self->ivPoke('isSnoopedFlag', TRUE); | ||
| 10756 | |||
| 10757 | # The lead Chat task stores the number of snoopers | ||
| 10758 | if (! $self->session->chatTask->snooperCount) { | ||
| 10759 | |||
| 10760 | # This is the first snooper; enable the two hook interfaces that capture local text | ||
| 10761 | $self->receiveHook->modifyAttribs($self->session, 'enabled', 1); | ||
| 10762 | $self->sendHook->modifyAttribs($self->session, 'enabled', 1); | ||
| 10763 | } | ||
| 10764 | |||
| 10765 | $self->session->chatTask->ivIncrement('snooperCount'); | ||
| 10766 | |||
| 10767 | $self->sendCmd( | ||
| 10768 | $self->ivShow('constOptHash', 'MESSAGE'), | ||
| 10769 | 'You are now snooping ' . $self->localName, | ||
| 10770 | ); | ||
| 10771 | |||
| 10772 | $self->writeText( | ||
| 10773 | $self->remoteName . ' is snooping you.', | ||
| 10774 | 'system', | ||
| 10775 | ); | ||
| 10776 | |||
| 10777 | return 1; | ||
| 10778 | } | ||
| 10779 | } | ||
| 10780 | |||
| 10781 | sub stopSnooped { | ||
| 10782 | |||
| 10783 | # Called by $self->dispatchCmd in response to the 'SNOOP' opcode, and also by several other | ||
| 10784 | # functions | ||
| 10785 | # Terminates a snooping session. No more snoop data is sent to the chat contact | ||
| 10786 | # | ||
| 10787 | # Expected arguments | ||
| 10788 | # (none besides $self) | ||
| 10789 | # | ||
| 10790 | # Return values | ||
| 10791 | # 'undef' on improper arguments or if there is currently no snooping session | ||
| 10792 | # 1 otherwise | ||
| 10793 | |||
| 10794 | my ($self, $check) = @_; | ||
| 10795 | |||
| 10796 | # Check for improper arguments | ||
| 10797 | if (defined $check) { | ||
| 10798 | |||
| 10799 | return $axmud::CLIENT->writeImproper($self->_objClass . '->stopSnooped', @_); | ||
| 10800 | } | ||
| 10801 | |||
| 10802 | if (! $self->isSnoopedFlag) { | ||
| 10803 | |||
| 10804 | # There is no snooping session | ||
| 10805 | return undef; | ||
| 10806 | |||
| 10807 | } else { | ||
| 10808 | |||
| 10809 | $self->ivPoke('isSnoopedFlag', FALSE); | ||
| 10810 | # The lead Chat task stores the number of snoopers | ||
| 10811 | $self->session->chatTask->ivDecrement('snooperCount'); | ||
| 10812 | |||
| 10813 | if (! $self->session->chatTask->snooperCount) { | ||
| 10814 | |||
| 10815 | # There are no more snoopers; disable the two hook interfaces that capture local | ||
| 10816 | # text | ||
| 10817 | $self->receiveHook->modifyAttribs($self->session, 'enabled', 0); | ||
| 10818 | $self->sendHook->modifyAttribs($self->session, 'enabled', 0); | ||
| 10819 | } | ||
| 10820 | |||
| 10821 | $self->sendCmd( | ||
| 10822 | $self->ivShow('constOptHash', 'MESSAGE'), | ||
| 10823 | 'You stop snooping ' . $self->localName, | ||
| 10824 | ); | ||
| 10825 | |||
| 10826 | $self->writeText( | ||
| 10827 | $self->remoteName . ' has stopped snooping you.', | ||
| 10828 | 'system', | ||
| 10829 | ); | ||
| 10830 | |||
| 10831 | return 1; | ||
| 10832 | } | ||
| 10833 | } | ||
| 10834 | |||
| 10835 | sub processSnoopedData { | ||
| 10836 | |||
| 10837 | # Called by $self->dispatchCmd in response to the 'SNOOP_DATA' opcode | ||
| 10838 | # Displays text from the chat contact's session in this task's window | ||
| 10839 | # | ||
| 10840 | # Expected arguments | ||
| 10841 | # $data - The text sent | ||
| 10842 | # | ||
| 10843 | # Return values | ||
| 10844 | # 'undef' on improper arguments | ||
| 10845 | # 1 otherwise | ||
| 10846 | |||
| 10847 | my ($self, $data, $check) = @_; | ||
| 10848 | |||
| 10849 | # Local variables | ||
| 10850 | my $stripData; | ||
| 10851 | |||
| 10852 | # Check for improper arguments | ||
| 10853 | if (! defined $data || defined $check) { | ||
| 10854 | |||
| 10855 | return $axmud::CLIENT->writeImproper($self->_objClass . '->processSnoopedData', @_); | ||
| 10856 | } | ||
| 10857 | |||
| 10858 | # The original chat.pl sends the zChat stamp at the beginning of data. I'll assume this is | ||
| 10859 | # not an error | ||
| 10860 | if ($self->chatType == $self->ivShow('constOptHash', 'ZCHAT')) { | ||
| 10861 | |||
| 10862 | $data = substr($data, 4); | ||
| 10863 | } | ||
| 10864 | |||
| 10865 | # Display the communication in the task window | ||
| 10866 | Encode::from_to($data, $self->encoding, 'utf-8-strict'); | ||
| 10867 | $stripData = $self->stripAnsi($data); | ||
| 10868 | |||
| 10869 | $self->writeText( | ||
| 10870 | $stripData, | ||
| 10871 | 'snoop', | ||
| 10872 | ); | ||
| 10873 | |||
| 10874 | return 1; | ||
| 10875 | } | ||
| 10876 | |||
| 10877 | sub processIcon { | ||
| 10878 | |||
| 10879 | # Called by $self->dispatchCmd in response to the 'ICON' opcode | ||
| 10880 | # Processes the chat contact's icon sent during a zChat session | ||
| 10881 | # | ||
| 10882 | # Expected arguments | ||
| 10883 | # $data - A string containing the raw Window .bmp file | ||
| 10884 | # | ||
| 10885 | # Return values | ||
| 10886 | # 'undef' on improper arguments | ||
| 10887 | # 1 otherwise | ||
| 10888 | |||
| 10889 | my ($self, $data, $check) = @_; | ||
| 10890 | |||
| 10891 | # Local variables | ||
| 10892 | my ($file, $fileHandle); | ||
| 10893 | |||
| 10894 | # Check for improper arguments | ||
| 10895 | if (! defined $data || defined $check) { | ||
| 10896 | |||
| 10897 | return $axmud::CLIENT->writeImproper($self->_objClass . '->processIcon', @_); | ||
| 10898 | } | ||
| 10899 | |||
| 10900 | # Save the incoming file, temporarily, in the Axmud data directory | ||
| 10901 | $file = $axmud::DATA_DIR . '/.tempicon_' . int(rand(1_000_000)) . '.bmp'; | ||
| 10902 | |||
| 10903 | open ($fileHandle, ">$file"); | ||
| 10904 | syswrite($fileHandle, $data, length ($data)); | ||
| 10905 | close($fileHandle); | ||
| 10906 | |||
| 10907 | # Use this file to set the task window's icon | ||
| 10908 | if ($self->winObj && ! $self->tableObj) { | ||
| 10909 | |||
| 10910 | $self->winObj->winWidget->set_icon_from_file($file); | ||
| 10911 | } | ||
| 10912 | |||
| 10913 | # Store the icon as a pixbuf, so that it can be stored in the contacts list, if necessary | ||
| 10914 | my ($pixBuffer, $pixBuffer2); | ||
| 10915 | |||
| 10916 | $pixBuffer = Gtk3::Gdk::Pixbuf->new_from_file($file); | ||
| 10917 | if ($pixBuffer) { | ||
| 10918 | |||
| 10919 | # Also create a scaled 16x16 copy of the icon for display in a simple list | ||
| 10920 | $pixBuffer2 = Gtk3::Gdk::Pixbuf->new_from_file_at_scale( | ||
| 10921 | $file, | ||
| 10922 | 16, 16, # Width, height | ||
| 10923 | 1, # Scaled | ||
| 10924 | ); | ||
| 10925 | } | ||
| 10926 | |||
| 10927 | if ($pixBuffer && $pixBuffer2) { | ||
| 10928 | |||
| 10929 | # If this session's chat contact is in our contacts list, update their stored icons | ||
| 10930 | # (actually, it's the pixbufs which are stored) | ||
| 10931 | if ($self->chatContactObj) { | ||
| 10932 | |||
| 10933 | $self->chatContactObj->ivPoke('lastIcon', $pixBuffer); | ||
| 10934 | $self->chatContactObj->ivPoke('lastIconScaled', $pixBuffer2); | ||
| 10935 | } | ||
| 10936 | |||
| 10937 | # Store our own copies | ||
| 10938 | $self->ivPoke('remoteIcon', $pixBuffer); | ||
| 10939 | $self->ivPoke('remoteIconScaled', $pixBuffer2); | ||
| 10940 | } | ||
| 10941 | |||
| 10942 | # Delete the temporary file | ||
| 10943 | unlink $file; | ||
| 10944 | |||
| 10945 | return 1; | ||
| 10946 | } | ||
| 10947 | |||
| 10948 | sub processStatus { | ||
| 10949 | |||
| 10950 | # Called by $self->dispatchCmd in response to the 'STATUS' opcode | ||
| 10951 | # Processes the chat contact's status sent during a zChat session | ||
| 10952 | # | ||
| 10953 | # Expected arguments | ||
| 10954 | # $data - The status sent (see comments below) | ||
| 10955 | # | ||
| 10956 | # Return values | ||
| 10957 | # 'undef' on improper arguments | ||
| 10958 | # 1 otherwise | ||
| 10959 | |||
| 10960 | my ($self, $data, $check) = @_; | ||
| 10961 | |||
| 10962 | # Local variables | ||
| 10963 | my $remoteStatus; | ||
| 10964 | |||
| 10965 | # Check for improper arguments | ||
| 10966 | if (! defined $data || defined $check) { | ||
| 10967 | |||
| 10968 | return $axmud::CLIENT->writeImproper($self->_objClass . '->processStatus', @_); | ||
| 10969 | } | ||
| 10970 | |||
| 10971 | # (from http://www.zuggsoft.com/zchat/zchatprot.htm) | ||
| 10972 | # Used to broadcast your current status to all your connections. Data is a single byte, with | ||
| 10973 | # the value: | ||
| 10974 | # 0 - no status | ||
| 10975 | # 1 - Normal status | ||
| 10976 | # 2 - InActive status | ||
| 10977 | # 3 - AFK status | ||
| 10978 | # Whenever the status of the chat client changes, this command is broadcast to all chat | ||
| 10979 | # connections. Normal means the user is actively using the chat client. InActive means | ||
| 10980 | # that the user is using some other program on their system and the chat client is not | ||
| 10981 | # necessarily visible. AFK means that no keyboard or mouse activity has been detected in | ||
| 10982 | # a while and the user is probably away from the computer | ||
| 10983 | $remoteStatus = ord($data); | ||
| 10984 | |||
| 10985 | if (! $self->remoteStatus) { | ||
| 10986 | |||
| 10987 | # Don't do anything if the status is 'no status', and don't bother displaying a message | ||
| 10988 | # at the start of the connection to show that the chat peer's status is 'Normal' | ||
| 10989 | if ($remoteStatus == 2) { | ||
| 10990 | |||
| 10991 | $self->writeText( | ||
| 10992 | $self->remoteName . '\'s status is \'inactive\'', | ||
| 10993 | 'remote', | ||
| 10994 | ); | ||
| 10995 | |||
| 10996 | } elsif ($remoteStatus == 3) { | ||
| 10997 | |||
| 10998 | $self->writeText( | ||
| 10999 | $self->remoteName . '\'s status is \'away from keys\'', | ||
| 11000 | 'remote', | ||
| 11001 | ); | ||
| 11002 | } | ||
| 11003 | |||
| 11004 | } else { | ||
| 11005 | |||
| 11006 | # Don't do anything if the status is 'no status' | ||
| 11007 | if ($remoteStatus == 1) { | ||
| 11008 | |||
| 11009 | $self->writeText( | ||
| 11010 | $self->remoteName . '\'s status is now \'normal\'', | ||
| 11011 | 'remote', | ||
| 11012 | ); | ||
| 11013 | |||
| 11014 | } elsif ($remoteStatus == 2) { | ||
| 11015 | |||
| 11016 | $self->writeText( | ||
| 11017 | $self->remoteName . '\'s status is now \'inactive\'', | ||
| 11018 | 'remote', | ||
| 11019 | ); | ||
| 11020 | |||
| 11021 | } elsif ($remoteStatus == 3) { | ||
| 11022 | |||
| 11023 | $self->writeText( | ||
| 11024 | $self->remoteName . '\'s status is now \'away from keys\'', | ||
| 11025 | 'remote', | ||
| 11026 | ); | ||
| 11027 | } | ||
| 11028 | } | ||
| 11029 | |||
| 11030 | # Update the IV | ||
| 11031 | $self->ivPoke('remoteStatus', $remoteStatus); | ||
| 11032 | |||
| 11033 | return 1; | ||
| 11034 | } | ||
| 11035 | |||
| 11036 | sub relayRemoteCmd { | ||
| 11037 | |||
| 11038 | # Called when a SEND_COMMAND message is received | ||
| 11039 | # | ||
| 11040 | # Expected arguments | ||
| 11041 | # $data - The command to send | ||
| 11042 | # | ||
| 11043 | # Return values | ||
| 11044 | # 'undef' on improper arguments | ||
| 11045 | # 1 otherwise | ||
| 11046 | |||
| 11047 | my ($self, $data, $check) = @_; | ||
| 11048 | |||
| 11049 | # Check for improper arguments | ||
| 11050 | if (defined $check) { | ||
| 11051 | |||
| 11052 | return $axmud::CLIENT->writeImproper($self->_objClass . '->relayRemoteCmd', @_); | ||
| 11053 | } | ||
| 11054 | |||
| 11055 | # (from http://www.zuggsoft.com/zchat/zchatprot.htm) | ||
| 11056 | # Used to send a zMUD command line to another user. The Data field is the entire zMUD | ||
| 11057 | # command line. The Receiver of this command can choose to execute the command line, or | ||
| 11058 | # it can send a Message denying the request if commands are not allowed from this user. | ||
| 11059 | if (! $self->allowRemoteCmdFlag) { | ||
| 11060 | |||
| 11061 | $self->sendCmd( | ||
| 11062 | $self->ivShow('constOptHash', 'MESSAGE'), | ||
| 11063 | $self->localName . ' does not currently accept remote commands.', | ||
| 11064 | ); | ||
| 11065 | |||
| 11066 | $self->writeText( | ||
| 11067 | 'Ignored a remote command sent by ' . $self->remoteName, | ||
| 11068 | 'system', | ||
| 11069 | ); | ||
| 11070 | |||
| 11071 | } else { | ||
| 11072 | |||
| 11073 | # Send the command to the world | ||
| 11074 | $self->session->worldCmd($data); | ||
| 11075 | |||
| 11076 | # If the chat contact is not snooping us, send a confirmation | ||
| 11077 | if (! $self->isSnoopedFlag) { | ||
| 11078 | |||
| 11079 | $self->sendCmd( | ||
| 11080 | $self->ivShow('constOptHash', 'MESSAGE'), | ||
| 11081 | 'Used command \'' . $data . '\'', | ||
| 11082 | ); | ||
| 11083 | } | ||
| 11084 | |||
| 11085 | # Display a local confirmation, regardless | ||
| 11086 | $self->writeText( | ||
| 11087 | 'Received command: ' . $data, | ||
| 11088 | 'remote', | ||
| 11089 | ); | ||
| 11090 | } | ||
| 11091 | |||
| 11092 | return 1; | ||
| 11093 | } | ||
| 11094 | |||
| 11095 | sub stripAnsi { | ||
| 11096 | |||
| 11097 | # Called when $self->processTextMsg, ->displayRemoteMsg and ->processSnoopedData | ||
| 11098 | # Strips escape sequences from a string received during the chat session. Returns the | ||
| 11099 | # stripped string | ||
| 11100 | # | ||
| 11101 | # Expected arguments | ||
| 11102 | # $string - A string, possibly containing escape sequences | ||
| 11103 | # | ||
| 11104 | # Return values | ||
| 11105 | # 'undef' on improper arguments | ||
| 11106 | # The stripped string, otherwise | ||
| 11107 | |||
| 11108 | my ($self, $string, $check) = @_; | ||
| 11109 | |||
| 11110 | # Check for improper arguments | ||
| 11111 | if (defined $check) { | ||
| 11112 | |||
| 11113 | return $axmud::CLIENT->writeImproper($self->_objClass . '->stripAnsi', @_); | ||
| 11114 | } | ||
| 11115 | |||
| 11116 | # Use the same regex as GA::Session->extractANSISequences uses | ||
| 11117 | $string =~ s/(\x1b\x5b.*?[HfABCDsuJKmhIp])//g; | ||
| 11118 | |||
| 11119 | return $string; | ||
| 11120 | } | ||
| 11121 | |||
| 11122 | ################## | ||
| 11123 | # Response methods | ||
| 11124 | |||
| 11125 | sub entryCallback { | ||
| 11126 | |||
| 11127 | # Usually called by ->signal_connect in GA::Strip::Entry->setEntrySignals or in | ||
| 11128 | # GA::Table::Entry->setActivateEvent, when the user types something in the strip/table | ||
| 11129 | # object's Gtk3::Entry and presses RETURN | ||
| 11130 | # | ||
| 11131 | # Text that begins with the client command sigil ';' is treated as a Chat task command, e.g. | ||
| 11132 | # ;ping | ||
| 11133 | # ;snoop | ||
| 11134 | # (All Chat task commands are stored as keys in $self->cmdHash) | ||
| 11135 | # | ||
| 11136 | # Chat messages can start with an initial ' character, emotes can start with an initial ':' | ||
| 11137 | # character and remote commands can start with an initial '#' character | ||
| 11138 | # Otherwise, the text entered is treated as if it were preceded by ;chat, ;emote or ;cmd | ||
| 11139 | # (depending on the value of $self->entryMode) | ||
| 11140 | # | ||
| 11141 | # Expected arguments | ||
| 11142 | # $obj - The strip or table object whose Gtk3::Entry was used | ||
| 11143 | # $entry - The Gtk3::Entry itself | ||
| 11144 | # | ||
| 11145 | # Optional arguments | ||
| 11146 | # $id - A value passed to the table object that identifies the particular | ||
| 11147 | # Gtk3::Entry used (in case the table object uses multiple entries). By | ||
| 11148 | # default, $self->openWin sets $id to the same as $self->uniqueName; | ||
| 11149 | # could be an 'undef' value otherwise | ||
| 11150 | # $text - The text typed in the entry by the user (should not be 'undef') | ||
| 11151 | # | ||
| 11152 | # Return values | ||
| 11153 | # 'undef' on improper arguments or if an unrecognised Chat command is used | ||
| 11154 | # Otherwise, returns the result of the function called in response | ||
| 11155 | |||
| 11156 | my ($self, $obj, $entry, $id, $text, $check) = @_; | ||
| 11157 | |||
| 11158 | # Local variables | ||
| 11159 | my ( | ||
| 11160 | $smileyFlag, $sigilFlag, $initChar, $inputString, $cmd, $argumentString, $method, | ||
| 11161 | @inputWord, | ||
| 11162 | ); | ||
| 11163 | |||
| 11164 | # Check for improper arguments | ||
| 11165 | if (! defined $obj || ! defined $entry || defined $check) { | ||
| 11166 | |||
| 11167 | return $axmud::CLIENT->writeImproper($self->_objClass . '->entryCallback', @_); | ||
| 11168 | } | ||
| 11169 | |||
| 11170 | # First thing is to remove the command sigil, if there is one. $inputString is set to the | ||
| 11171 | # value of $text, minus the command sigil | ||
| 11172 | # Exception: if $text begings with a smiley, treat it as a smiley, not as a sigil | ||
| 11173 | OUTER: foreach my $smiley ($axmud::CLIENT->ivKeys('chatSmileyHash')) { | ||
| 11174 | |||
| 11175 | if (substr($text, 0, length($smiley)) eq $smiley) { | ||
| 11176 | |||
| 11177 | $smileyFlag = TRUE; | ||
| 11178 | last OUTER; | ||
| 11179 | } | ||
| 11180 | } | ||
| 11181 | |||
| 11182 | if (! $smileyFlag) { | ||
| 11183 | |||
| 11184 | $initChar = substr($text, 0, 1); | ||
| 11185 | if ($initChar eq ';' || $initChar eq '\'' || $initChar eq ':' || $initChar eq '#') { | ||
| 11186 | |||
| 11187 | $inputString = substr($text, 1); | ||
| 11188 | $sigilFlag = TRUE; | ||
| 11189 | |||
| 11190 | } else { | ||
| 11191 | |||
| 11192 | # It's not a Chat task command | ||
| 11193 | $inputString = $text; | ||
| 11194 | } | ||
| 11195 | |||
| 11196 | } else { | ||
| 11197 | |||
| 11198 | $inputString = $text; | ||
| 11199 | } | ||
| 11200 | |||
| 11201 | if ($sigilFlag) { | ||
| 11202 | |||
| 11203 | if ($initChar eq ';') { | ||
| 11204 | |||
| 11205 | # Parse the Chat task command into a list of distinct words (or groups of words), | ||
| 11206 | # exactly as it would be parsed if it were typed as a client command in the 'main' | ||
| 11207 | # window | ||
| 11208 | @inputWord = $self->session->parseCmd($inputString); | ||
| 11209 | |||
| 11210 | # Remember the actual Chat task command typed - and make it lower-case | ||
| 11211 | $cmd = lc(shift (@inputWord)); | ||
| 11212 | |||
| 11213 | # Remember everything EXCEPT the actual command typed | ||
| 11214 | $argumentString = substr($inputString, length($cmd)); | ||
| 11215 | # Trim whitespace from the beginning of that string, so that the first letter of | ||
| 11216 | # $argumentString is the first letter of the first word typed, after the command | ||
| 11217 | # itself | ||
| 11218 | $argumentString =~ s/^\s+//; | ||
| 11219 | |||
| 11220 | # If the command matches one in $self->cmdHash, call the corresponding function. | ||
| 11221 | # If it doesn't, do nothing | ||
| 11222 | if ($self->ivExists('cmdHash', $cmd)) { | ||
| 11223 | |||
| 11224 | $method = $self->ivShow('cmdHash', $cmd); | ||
| 11225 | |||
| 11226 | return $self->$method($argumentString); | ||
| 11227 | |||
| 11228 | } else { | ||
| 11229 | |||
| 11230 | # Not a valid chat command | ||
| 11231 | $self->writeText( | ||
| 11232 | 'Unrecognised chat command \'' . $cmd . '\' (try \';help\')', | ||
| 11233 | 'system', | ||
| 11234 | ); | ||
| 11235 | |||
| 11236 | return undef; | ||
| 11237 | } | ||
| 11238 | |||
| 11239 | } elsif ($initChar eq '\'') { | ||
| 11240 | |||
| 11241 | # Send the entered text as chat | ||
| 11242 | return $self->chat($inputString); | ||
| 11243 | |||
| 11244 | } elsif ($initChar eq ':') { | ||
| 11245 | |||
| 11246 | # Send the entered text as an emote | ||
| 11247 | return $self->emote($inputString); | ||
| 11248 | |||
| 11249 | } elsif ($initChar eq '#') { | ||
| 11250 | |||
| 11251 | # Send the entered text as a remote command | ||
| 11252 | return $self->sendRemoteCmdd($inputString); | ||
| 11253 | } | ||
| 11254 | |||
| 11255 | } else { | ||
| 11256 | |||
| 11257 | # Otherwise, the entered text is treated as chat, an emote or a remote command, | ||
| 11258 | # depending on the value of $self->entryMode | ||
| 11259 | if ($self->entryMode eq 'emote') { | ||
| 11260 | |||
| 11261 | # Send the entered text as an emote | ||
| 11262 | return $self->emote($inputString); | ||
| 11263 | |||
| 11264 | } elsif ($self->entryMode eq 'cmd') { | ||
| 11265 | |||
| 11266 | # Send the entered text as a remote command | ||
| 11267 | return $self->sendRemoteCmd($inputString); | ||
| 11268 | |||
| 11269 | } else { | ||
| 11270 | |||
| 11271 | # Entry mode 0 - send the entered text as chat | ||
| 11272 | return $self->chat($inputString); | ||
| 11273 | } | ||
| 11274 | } | ||
| 11275 | |||
| 11276 | return 1; | ||
| 11277 | } | ||
| 11278 | |||
| 11279 | sub hookCallback { | ||
| 11280 | |||
| 11281 | # Called by GA::Session->checkHooks | ||
| 11282 | # | ||
| 11283 | # This task's ->resetHooks function creates some hooks which fire when text is received from | ||
| 11284 | # the world, and when a command is sent to it. The hooks are only enabled during a | ||
| 11285 | # snooping session. | ||
| 11286 | # This function passes the received text or the command to the chat contact. The interface's | ||
| 11287 | # ->propertyHash is not used | ||
| 11288 | # | ||
| 11289 | # Expected arguments (standard args from GA::Session->checkHooks) | ||
| 11290 | # $session - The calling function's GA::Session | ||
| 11291 | # $interfaceNum - The number of the active hook interface that fired | ||
| 11292 | # $hookEvent - The hook event, which should be 'receive_text' or 'send_cmd' | ||
| 11293 | # | ||
| 11294 | # Optional arguments | ||
| 11295 | # $hookVar - The line of text received, or the command sent. An optional argument | ||
| 11296 | # in the call from GA::Session->checkHooks, but never set to 'undef' | ||
| 11297 | # for this task's hooks | ||
| 11298 | # $hookVal - A second optional argument in the call from GA::Session->checkHooks; | ||
| 11299 | # always set to 'undef' for this task's hooks | ||
| 11300 | # | ||
| 11301 | # Return values | ||
| 11302 | # 'undef' on improper arguments, or if $session is the wrong session or if the interface | ||
| 11303 | # object can't be found | ||
| 11304 | # 1 otherwise | ||
| 11305 | |||
| 11306 | my ($self, $session, $interfaceNum, $hookEvent, $hookVar, $hookVal, $check) = @_; | ||
| 11307 | |||
| 11308 | # Local variables | ||
| 11309 | my ($obj, $opCode); | ||
| 11310 | |||
| 11311 | # Check for improper arguments | ||
| 11312 | if ( | ||
| 11313 | ! defined $session || ! defined $interfaceNum || ! defined $hookEvent || defined $check | ||
| 11314 | ) { | ||
| 11315 | return $axmud::CLIENT->writeImproper($self->_objClass . '->hookCallback', @_); | ||
| 11316 | } | ||
| 11317 | |||
| 11318 | # Basic check - the hook should belong to the right session | ||
| 11319 | if ($session ne $self->session) { | ||
| 11320 | |||
| 11321 | return undef; | ||
| 11322 | } | ||
| 11323 | |||
| 11324 | # Get the interface object itself | ||
| 11325 | $obj = $session->ivShow('interfaceNumHash', $interfaceNum); | ||
| 11326 | if (! $obj) { | ||
| 11327 | |||
| 11328 | return undef; | ||
| 11329 | } | ||
| 11330 | |||
| 11331 | # Respond to the fired hook | ||
| 11332 | |||
| 11333 | # Import the opcode for 'SNOOP_DATA' | ||
| 11334 | $opCode = $self->ivShow('constOptHash', 'SNOOP_DATA'); | ||
| 11335 | |||
| 11336 | # Look for running Chat tasks | ||
| 11337 | foreach my $taskObj ($self->session->ivValus('currentTaskHash')) { | ||
| 11338 | |||
| 11339 | if ( | ||
| 11340 | $taskObj->name eq 'chat_task' | ||
| 11341 | && $taskObj->status eq 'running' # i.e. not paused | ||
| 11342 | && ! $taskObj->connectionClosedFlag | ||
| 11343 | && $taskObj->isSnoopedFlag | ||
| 11344 | ) { | ||
| 11345 | $taskObj->sendCmd( | ||
| 11346 | $opCode, | ||
| 11347 | $hookVar, # Text received, or command sent | ||
| 11348 | ); | ||
| 11349 | } | ||
| 11350 | } | ||
| 11351 | |||
| 11352 | return 1; | ||
| 11353 | } | ||
| 11354 | |||
| 11355 | sub timerCallback { | ||
| 11356 | |||
| 11357 | # Called by GA::Session->checkTimers | ||
| 11358 | # | ||
| 11359 | # This task's ->resetTimers function creates a timer which fires periodically. | ||
| 11360 | # Every time the timer fires, this function checks whether the user is idle, and takes | ||
| 11361 | # action if so | ||
| 11362 | # | ||
| 11363 | # Expected arguments (standard args from GA::Session->checkTimers) | ||
| 11364 | # $session - The calling function's GA::Session | ||
| 11365 | # $interfaceNum - The number of the active timer interface that fired | ||
| 11366 | # $actualTime - The time (matches GA::Session->sessionTime) at which the timer | ||
| 11367 | # actually fired, in seconds | ||
| 11368 | # $dueTime - The time (matches GA::Session->sessionTime) at which the timer was | ||
| 11369 | # due to fire, in seconds | ||
| 11370 | # | ||
| 11371 | # Return values | ||
| 11372 | # 'undef' on improper arguments, or if $session is the wrong session or if the interface | ||
| 11373 | # object can't be found | ||
| 11374 | # 1 otherwise | ||
| 11375 | |||
| 11376 | my ($self, $session, $interfaceNum, $actualTime, $dueTime, $check) = @_; | ||
| 11377 | |||
| 11378 | # Local variables | ||
| 11379 | my ( | ||
| 11380 | $obj, $idleTime, | ||
| 11381 | @taskList, | ||
| 11382 | ); | ||
| 11383 | |||
| 11384 | # Check for improper arguments | ||
| 11385 | if ( | ||
| 11386 | ! defined $session || ! defined $interfaceNum || ! defined $actualTime | ||
| 11387 | || ! defined $dueTime || defined $check | ||
| 11388 | ) { | ||
| 11389 | return $axmud::CLIENT->writeImproper($self->_objClass . '->timerCallback', @_); | ||
| 11390 | } | ||
| 11391 | |||
| 11392 | # Basic check - the timer should belong to the right session | ||
| 11393 | if ($session ne $self->session) { | ||
| 11394 | |||
| 11395 | return undef; | ||
| 11396 | } | ||
| 11397 | |||
| 11398 | # Get the interface object itself | ||
| 11399 | $obj = $session->ivShow('interfaceNumHash', $interfaceNum); | ||
| 11400 | if (! $obj) { | ||
| 11401 | |||
| 11402 | return undef; | ||
| 11403 | } | ||
| 11404 | |||
| 11405 | # Respond to the fired timer | ||
| 11406 | |||
| 11407 | # Check how long the user has been idle, in seconds | ||
| 11408 | if (defined $self->session->lastInstructTime) { | ||
| 11409 | |||
| 11410 | $idleTime = int($self->session->sessionTime - $self->session->lastInstructTime); | ||
| 11411 | |||
| 11412 | } else { | ||
| 11413 | |||
| 11414 | # No instruction executed yet | ||
| 11415 | $idleTime = int($self->session->sessionTime); | ||
| 11416 | } | ||
| 11417 | |||
| 11418 | # If it's a zChat session and the user's status is 'Normal'... | ||
| 11419 | if ($self->localStatus == 1) { | ||
| 11420 | |||
| 11421 | # If the user is idle longer than the allowed time, send a new status to all connections | ||
| 11422 | if ($idleTime > $self->idleSeconds) { | ||
| 11423 | |||
| 11424 | @taskList = $self->findAllTasks(); | ||
| 11425 | foreach my $taskObj (@taskList) { | ||
| 11426 | |||
| 11427 | # Broadcast the change to all Chat tasks with active connections | ||
| 11428 | if ($taskObj->sessionFlag) { | ||
| 11429 | |||
| 11430 | $taskObj->ivPoke('localStatus', 3); | ||
| 11431 | |||
| 11432 | $taskObj->broadcast( | ||
| 11433 | $self->ivShow('constOptHash', 'STATUS'), | ||
| 11434 | chr(3), # 'AFK' | ||
| 11435 | ); | ||
| 11436 | |||
| 11437 | $taskObj->writeText( | ||
| 11438 | 'Your status is now \'away from keys\'', | ||
| 11439 | 'system', | ||
| 11440 | ); | ||
| 11441 | } | ||
| 11442 | } | ||
| 11443 | } | ||
| 11444 | |||
| 11445 | # If it's a zChat session and the user's status is already 'AFK'... | ||
| 11446 | } elsif ($self->localStatus == 3) { | ||
| 11447 | |||
| 11448 | # If the user's idle time is less than the timer's own delay time, then the user has | ||
| 11449 | # interacted with the 'main' window since we last checked | ||
| 11450 | # NB $self->sendCmd() also performs this check | ||
| 11451 | if ($idleTime <= $self->idleCheckTime) { | ||
| 11452 | |||
| 11453 | @taskList = $self->findAllTasks(); | ||
| 11454 | foreach my $taskObj (@taskList) { | ||
| 11455 | |||
| 11456 | $taskObj->ivPoke('localStatus', 1); | ||
| 11457 | |||
| 11458 | # Broadcast the change to all Chat tasks with active connections | ||
| 11459 | if ($taskObj->sessionFlag) { | ||
| 11460 | |||
| 11461 | $taskObj->broadcast( | ||
| 11462 | $self->ivShow('constOptHash', 'STATUS'), | ||
| 11463 | chr(1), # 'Normal' | ||
| 11464 | ); | ||
| 11465 | |||
| 11466 | $taskObj->writeText( | ||
| 11467 | 'Your status is now \'normal\'', | ||
| 11468 | 'system', | ||
| 11469 | ); | ||
| 11470 | } | ||
| 11471 | } | ||
| 11472 | } | ||
| 11473 | } | ||
| 11474 | |||
| 11475 | return 1; | ||
| 11476 | } | ||
| 11477 | |||
| 11478 | ################## | ||
| 11479 | # Accessors - set | ||
| 11480 | |||
| 11481 | sub del_winObj { | ||
| 11482 | |||
| 11483 | # Called by GA::Win::Generic->winDestroy | ||
| 11484 | # | ||
| 11485 | # This task's behaviour is unusual because there can be a 'lead' Chat task and any number | ||
| 11486 | # of other Chat tasks), so we can't use the default ->del_winObj function | ||
| 11487 | # When this Chat task is the lead Chat task, it can both start and stop without a task | ||
| 11488 | # window. Otherwise, when the user manually closes the window, the task must halt | ||
| 11489 | |||
| 11490 | my ($self, $winObj, $check) = @_; | ||
| 11491 | |||
| 11492 | # Local variables | ||
| 11493 | my $stripObj; | ||
| 11494 | |||
| 11495 | # Check for improper arguments | ||
| 11496 | if (! defined $winObj || defined $check) { | ||
| 11497 | |||
| 11498 | return $axmud::CLIENT->writeImproper($self->_objClass . '->del_winObj', @_); | ||
| 11499 | } | ||
| 11500 | |||
| 11501 | # Do nothing if the task already knows the window is closed, or if the task is shutting down | ||
| 11502 | # anyway | ||
| 11503 | if ($self->winObj && $self->winObj eq $winObj && ! $self->shutdownFlag) { | ||
| 11504 | |||
| 11505 | # Mark the window as closed | ||
| 11506 | $self->ivUndef('winObj'); | ||
| 11507 | $self->ivPoke('taskWinFlag', FALSE); | ||
| 11508 | $self->ivPoke('taskWinEntryFlag', FALSE); | ||
| 11509 | $self->ivUndef('defaultTabObj'); | ||
| 11510 | |||
| 11511 | # For pseudo-windows, this function should probably not be called; nevertheless, if the | ||
| 11512 | # parent table object is still open, close it | ||
| 11513 | if ($winObj->pseudoWinTableObj) { | ||
| 11514 | |||
| 11515 | $stripObj = $winObj->pseudoWinTableObj->stripObj; | ||
| 11516 | if ($stripObj->ivExists('tableObjHash', $winObj->pseudoWinTableObj->number)) { | ||
| 11517 | |||
| 11518 | $stripObj->removeTableObj($winObj->pseudoWinTableObj); | ||
| 11519 | } | ||
| 11520 | } | ||
| 11521 | |||
| 11522 | if (! $self->leadTaskFlag) { | ||
| 11523 | |||
| 11524 | # This is not the lead Chat task, so halt the task | ||
| 11525 | $self->ivPoke('shutdownFlag', TRUE); | ||
| 11526 | $self->writeText( | ||
| 11527 | 'Window for \'' . $self->prettyName . '\' task closed (task will also halt)', | ||
| 11528 | ); | ||
| 11529 | |||
| 11530 | } else { | ||
| 11531 | |||
| 11532 | # The task can continue, in order to listen for incoming connections | ||
| 11533 | if ($self->sessionFlag) { | ||
| 11534 | |||
| 11535 | $self->terminateChatSession(); | ||
| 11536 | |||
| 11537 | if ($self->remoteName) { | ||
| 11538 | |||
| 11539 | $self->writeText( | ||
| 11540 | 'Chat session with ' . $self->remoteName . ' closed (task will' | ||
| 11541 | . ' continue)', | ||
| 11542 | ); | ||
| 11543 | |||
| 11544 | } else { | ||
| 11545 | |||
| 11546 | $self->writeText( | ||
| 11547 | 'Chat session closed (task will continue)', | ||
| 11548 | ); | ||
| 11549 | } | ||
| 11550 | |||
| 11551 | } else { | ||
| 11552 | |||
| 11553 | $self->writeText( | ||
| 11554 | 'Window for \'' . $self->prettyName . '\' task closed (task will continue)', | ||
| 11555 | ); | ||
| 11556 | } | ||
| 11557 | } | ||
| 11558 | } | ||
| 11559 | |||
| 11560 | return 1; | ||
| 11561 | } | ||
| 11562 | |||
| 11563 | ################## | ||
| 11564 | # Accessors - task settings - get | ||
| 11565 | |||
| 11566 | # The accessors for task settings are inherited from the generic task | ||
| 11567 | |||
| 11568 | ################## | ||
| 11569 | # Accessors - task parameters - get | ||
| 11570 | |||
| 11571 | sub leadTaskFlag | ||
| 11572 | { $_[0]->{leadTaskFlag} } | ||
| 11573 | sub sessionFlag | ||
| 11574 | { $_[0]->{sessionFlag} } | ||
| 11575 | sub connectionClosedFlag | ||
| 11576 | { $_[0]->{connectionClosedFlag} } | ||
| 11577 | sub chatContactObj | ||
| 11578 | { $_[0]->{chatContactObj} } | ||
| 11579 | |||
| 11580 | sub ip | ||
| 11581 | { $_[0]->{ip} } | ||
| 11582 | sub port | ||
| 11583 | { $_[0]->{port} } | ||
| 11584 | sub acceptSocket | ||
| 11585 | { $_[0]->{acceptSocket} } | ||
| 11586 | sub acceptID | ||
| 11587 | { $_[0]->{acceptID} } | ||
| 11588 | sub incomingTimeout | ||
| 11589 | { $_[0]->{incomingTimeout} } | ||
| 11590 | sub outgoingTimeout | ||
| 11591 | { $_[0]->{outgoingTimeout} } | ||
| 11592 | |||
| 11593 | sub clientSocket | ||
| 11594 | { $_[0]->{clientSocket} } | ||
| 11595 | sub chatType | ||
| 11596 | { $_[0]->{chatType} } | ||
| 11597 | sub ioWatchID | ||
| 11598 | { $_[0]->{ioWatchID} } | ||
| 11599 | sub timeoutID | ||
| 11600 | { $_[0]->{timeoutID} } | ||
| 11601 | sub pendingOpCode | ||
| 11602 | { $_[0]->{pendingOpCode} } | ||
| 11603 | sub lastInvalidOpCode | ||
| 11604 | { $_[0]->{lastInvalidOpCode} } | ||
| 11605 | sub pendingDataSize | ||
| 11606 | { $_[0]->{pendingDataSize} } | ||
| 11607 | sub dataBuffer | ||
| 11608 | { $_[0]->{dataBuffer} } | ||
| 11609 | sub defaultEncoding | ||
| 11610 | { $_[0]->{defaultEncoding} } | ||
| 11611 | sub encoding | ||
| 11612 | { $_[0]->{encoding} } | ||
| 11613 | |||
| 11614 | sub receiveHook | ||
| 11615 | { $_[0]->{receiveHook} } | ||
| 11616 | sub sendHook | ||
| 11617 | { $_[0]->{sendHook} } | ||
| 11618 | sub idleTimer | ||
| 11619 | { $_[0]->{idleTimer} } | ||
| 11620 | sub idleCheckTime | ||
| 11621 | { $_[0]->{idleCheckTime} } | ||
| 11622 | sub idleSeconds | ||
| 11623 | { $_[0]->{idleSeconds} } | ||
| 11624 | |||
| 11625 | sub acceptCallsOnInitFlag | ||
| 11626 | { $_[0]->{acceptCallsOnInitFlag} } | ||
| 11627 | sub acceptCallsOnInitPort | ||
| 11628 | { $_[0]->{acceptCallsOnInitPort} } | ||
| 11629 | sub makeCallOnInitFlag | ||
| 11630 | { $_[0]->{makeCallOnInitFlag} } | ||
| 11631 | sub makeCallOnInitType | ||
| 11632 | { $_[0]->{makeCallOnInitType} } | ||
| 11633 | sub makeCallOnInitIP | ||
| 11634 | { $_[0]->{makeCallOnInitIP} } | ||
| 11635 | sub makeCallOnInitPort | ||
| 11636 | { $_[0]->{makeCallOnInitPort} } | ||
| 11637 | sub receiveCallOnInitFlag | ||
| 11638 | { $_[0]->{receiveCallOnInitFlag} } | ||
| 11639 | sub receiveCallOnInitSocket | ||
| 11640 | { $_[0]->{receiveCallOnInitSocket} } | ||
| 11641 | |||
| 11642 | sub localName | ||
| 11643 | { $_[0]->{localName} } | ||
| 11644 | sub localIconFile | ||
| 11645 | { $_[0]->{localIconFile} } | ||
| 11646 | sub localEmail | ||
| 11647 | { $_[0]->{localEmail} } | ||
| 11648 | sub localGroup | ||
| 11649 | { $_[0]->{localGroup} } | ||
| 11650 | sub localStatus | ||
| 11651 | { $_[0]->{localStatus} } | ||
| 11652 | sub localZChatStamp | ||
| 11653 | { $_[0]->{localZChatStamp} } | ||
| 11654 | |||
| 11655 | sub remoteIcon | ||
| 11656 | { $_[0]->{remoteIcon} } | ||
| 11657 | sub remoteIconScaled | ||
| 11658 | { $_[0]->{remoteIconScaled} } | ||
| 11659 | sub remoteName | ||
| 11660 | { $_[0]->{remoteName} } | ||
| 11661 | sub remoteIP | ||
| 11662 | { $_[0]->{remoteIP} } | ||
| 11663 | sub remotePort | ||
| 11664 | { $_[0]->{remotePort} } | ||
| 11665 | sub remoteEmail | ||
| 11666 | { $_[0]->{remoteEmail} } | ||
| 11667 | sub remoteStamp | ||
| 11668 | { $_[0]->{remoteStamp} } | ||
| 11669 | sub remoteVersion | ||
| 11670 | { $_[0]->{remoteVersion} } | ||
| 11671 | sub remoteStatus | ||
| 11672 | { $_[0]->{remoteStatus} } | ||
| 11673 | sub remoteZChatID | ||
| 11674 | { $_[0]->{remoteZChatID} } | ||
| 11675 | |||
| 11676 | sub allowSnoopFlag | ||
| 11677 | { $_[0]->{allowSnoopFlag} } | ||
| 11678 | sub isSnoopedFlag | ||
| 11679 | { $_[0]->{isSnoopedFlag} } | ||
| 11680 | sub snooperCount | ||
| 11681 | { $_[0]->{snooperCount} } | ||
| 11682 | sub publicConnectionFlag | ||
| 11683 | { $_[0]->{publicConnectionFlag} } | ||
| 11684 | sub allowRemoteCmdFlag | ||
| 11685 | { $_[0]->{allowRemoteCmdFlag} } | ||
| 11686 | sub entryMode | ||
| 11687 | { $_[0]->{entryMode} } | ||
| 11688 | sub servingFlag | ||
| 11689 | { $_[0]->{servingFlag} } | ||
| 11690 | |||
| 11691 | sub pingTime | ||
| 11692 | { $_[0]->{pingTime} } | ||
| 11693 | sub pingStamp | ||
| 11694 | { $_[0]->{pingStamp} } | ||
| 11695 | sub fileDir | ||
| 11696 | { $_[0]->{fileDir} } | ||
| 11697 | sub fileName | ||
| 11698 | { $_[0]->{fileName} } | ||
| 11699 | sub fileHandle | ||
| 11700 | { $_[0]->{fileHandle} } | ||
| 11701 | sub fileTotalSize | ||
| 11702 | { $_[0]->{fileTotalSize} } | ||
| 11703 | sub fileSize | ||
| 11704 | { $_[0]->{fileSize} } | ||
| 11705 | |||
| 11706 | sub chatOutColour | ||
| 11707 | { $_[0]->{chatOutColour} } | ||
| 11708 | sub chatInColour | ||
| 11709 | { $_[0]->{chatInColour} } | ||
| 11710 | sub chatEchoColour | ||
| 11711 | { $_[0]->{chatEchoColour} } | ||
| 11712 | sub systemColour | ||
| 11713 | { $_[0]->{systemColour} } | ||
| 11714 | sub remoteColour | ||
| 11715 | { $_[0]->{remoteColour} } | ||
| 11716 | sub snoopColour | ||
| 11717 | { $_[0]->{snoopColour} } | ||
| 11718 | sub allSystemColourFlag | ||
| 11719 | { $_[0]->{allSystemColourFlag} } | ||
| 11720 | sub allowSmileyFlag | ||
| 11721 | { $_[0]->{allowSmileyFlag} } | ||
| 11722 | sub smileySizeFactor | ||
| 11723 | { $_[0]->{smileySizeFactor} } | ||
| 11724 | |||
| 11725 | sub localPublicKey | ||
| 11726 | { $_[0]->{localPublicKey} } | ||
| 11727 | sub localSecretKey | ||
| 11728 | { $_[0]->{localSecretKey} } | ||
| 11729 | sub remotePublicKey | ||
| 11730 | { $_[0]->{remotePublicKey} } | ||
| 11731 | |||
| 11732 | sub constOptHash | ||
| 11733 | { my $self = shift; return %{$self->{constOptHash}}; } | ||
| 11734 | sub restrictedHash | ||
| 11735 | { my $self = shift; return %{$self->{restrictedHash}}; } | ||
| 11736 | sub cmdHash | ||
| 11737 | { my $self = shift; return %{$self->{cmdHash}}; } | ||
| 11738 | |||
| 11739 | sub helpList | ||
| 11740 | { my $self = shift; return @{$self->{helpList}}; } | ||
| 11741 | } | ||
| 11742 | |||
| 11743 | { package Games::Axmud::Task::Compass; | ||
| 11744 | |||
| 11745 | use strict; | ||
| 11746 | use warnings; | ||
| 11747 | # use diagnostics; | ||
| 11748 | |||
| 11749 | use Glib qw(TRUE FALSE); | ||
| 11750 | |||
| 11751 | our @ISA = qw(Games::Axmud::Generic::Task Games::Axmud); | ||
| 11752 | |||
| 11753 | ################## | ||
| 11754 | # Constructors | ||
| 11755 | |||
| 11756 | sub new { | ||
| 11757 | |||
| 11758 | # Creates a new instance of the Compass task | ||
| 11759 | # | ||
| 11760 | # Expected arguments | ||
| 11761 | # $session - The parent GA::Session (not stored as an IV) | ||
| 11762 | # | ||
| 11763 | # Optional arguments | ||
| 11764 | # $taskType - Which tasklist this task is being created into - 'current' for the current | ||
| 11765 | # tasklist (tasks which are actually running now), 'initial' (tasks which | ||
| 11766 | # should be run when the user connects to the world), 'custom' (tasks with | ||
| 11767 | # customised initial parameters, which are run when the user demands). If | ||
| 11768 | # set to 'undef', this is a temporary task, created in order to access the | ||
| 11769 | # default values stored in IVs, that will not be added to any tasklist | ||
| 11770 | # $profName - ($taskType = 'current', when called by $self->clone) Name of the | ||
| 11771 | # profile from whose initial tasklist this task was created ('undef' if | ||
| 11772 | # none) | ||
| 11773 | # - ($taskType = 'initial') name of the profile in whose initial tasklist this | ||
| 11774 | # task will be. If 'undef', the global initial tasklist is used | ||
| 11775 | # - ($taskType = 'custom') 'undef' | ||
| 11776 | # $profCategory | ||
| 11777 | # - ($taskType = 'current', 'initial') which category the profile falls undef | ||
| 11778 | # (i.e. 'world', 'race', 'char', etc, or 'undef' if no profile) | ||
| 11779 | # - ($taskType = 'custom') 'undef' | ||
| 11780 | # $customName | ||
| 11781 | # - ($taskType = 'current', 'initial') 'undef' | ||
| 11782 | # - ($taskType = 'custom') the custom task name, matching a key in | ||
| 11783 | # GA::Session->customTaskHash | ||
| 11784 | # | ||
| 11785 | # Return values | ||
| 11786 | # 'undef' on improper arguments or if the task can't be added to the specified tasklist | ||
| 11787 | # Blessed reference to the newly-created object on success | ||
| 11788 | |||
| 11789 | my ($class, $session, $taskType, $profName, $profCategory, $customName, $check) = @_; | ||
| 11790 | |||
| 11791 | # Check for improper arguments | ||
| 11792 | if (! defined $class || ! defined $session || defined $check) { | ||
| 11793 | |||
| 11794 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 11795 | } | ||
| 11796 | |||
| 11797 | if ($taskType) { | ||
| 11798 | |||
| 11799 | # For initial tasks, check that $profName exists | ||
| 11800 | if ( | ||
| 11801 | $taskType eq 'initial' | ||
| 11802 | && defined $profName | ||
| 11803 | && ! $session->ivExists('profHash', $profName) | ||
| 11804 | ) { | ||
| 11805 | return $session->writeError( | ||
| 11806 | 'Can\'t create new task because \'' . $profName . '\' profile doesn\'t exist', | ||
| 11807 | $class . '->new', | ||
| 11808 | ); | ||
| 11809 | |||
| 11810 | # For custom tasks, check that $customName doesn't already exist | ||
| 11811 | } elsif ( | ||
| 11812 | $taskType eq 'custom' | ||
| 11813 | && $axmud::CLIENT->ivExists('customTaskHash', $customName) | ||
| 11814 | ) { | ||
| 11815 | return $session->writeError( | ||
| 11816 | 'Can\'t create new custom task because \'' . $customName . '\' is already being' | ||
| 11817 | . ' used', | ||
| 11818 | $class . '->new', | ||
| 11819 | ); | ||
| 11820 | |||
| 11821 | } elsif ($taskType ne 'current' && $taskType ne 'initial' && $taskType ne 'custom') { | ||
| 11822 | |||
| 11823 | return $session->writeError( | ||
| 11824 | 'Can\'t create new task because \'' . $taskType . '\' is an invalid tasklist', | ||
| 11825 | $class . '->new', | ||
| 11826 | ); | ||
| 11827 | } | ||
| 11828 | } | ||
| 11829 | |||
| 11830 | # Task settings | ||
| 11831 | my $self = Games::Axmud::Generic::Task->new( | ||
| 11832 | $session, | ||
| 11833 | $taskType, | ||
| 11834 | $profName, | ||
| 11835 | $profCategory, | ||
| 11836 | $customName, | ||
| 11837 | ); | ||
| 11838 | |||
| 11839 | $self->{_objName} = 'compass_task'; | ||
| 11840 | $self->{_objClass} = $class; | ||
| 11841 | $self->{_parentFile} = undef; # Set below | ||
| 11842 | $self->{_parentWorld} = undef; # Set below | ||
| 11843 | $self->{_privFlag} = TRUE, # All IVs are private | ||
| 11844 | |||
| 11845 | $self->{name} = 'compass_task'; | ||
| 11846 | $self->{prettyName} = 'Compass'; | ||
| 11847 | $self->{shortName} = 'Co'; | ||
| 11848 | $self->{shortCutIV} = 'compassTask'; # Axmud built-in jealous task | ||
| 11849 | |||
| 11850 | $self->{category} = 'activity'; | ||
| 11851 | $self->{descrip} = 'Creates a task window with a clickable compass'; | ||
| 11852 | $self->{jealousyFlag} = TRUE; | ||
| 11853 | $self->{requireLocatorFlag} = FALSE; | ||
| 11854 | $self->{profSensitivityFlag} = TRUE; | ||
| 11855 | $self->{storableFlag} = TRUE; | ||
| 11856 | $self->{delayTime} = 0; | ||
| 11857 | $self->{allowWinFlag} = TRUE; | ||
| 11858 | $self->{requireWinFlag} = FALSE; | ||
| 11859 | $self->{startWithWinFlag} = TRUE; | ||
| 11860 | $self->{winPreferList} = ['pseudo', 'grid']; | ||
| 11861 | $self->{winmap} = 'basic_empty'; | ||
| 11862 | $self->{winUpdateFunc} = 'createWidgets'; | ||
| 11863 | $self->{tabMode} = undef; | ||
| 11864 | $self->{monochromeFlag} = FALSE; | ||
| 11865 | $self->{noScrollFlag} = FALSE; | ||
| 11866 | $self->{ttsFlag} = FALSE; | ||
| 11867 | $self->{ttsConfig} = undef; | ||
| 11868 | $self->{ttsAttribHash} = {}; | ||
| 11869 | $self->{ttsFlagAttribHash} = {}; | ||
| 11870 | $self->{ttsAlertAttribHash} = {}; | ||
| 11871 | $self->{status} = 'wait_init'; | ||
| 11872 | # $self->{activeFlag} = TRUE; # Task can't be activated/disactivated | ||
| 11873 | |||
| 11874 | # Task parameters | ||
| 11875 | # | ||
| 11876 | # Flag set to TRUE if the task window is enabled (this task sends a direction or a world | ||
| 11877 | # command when a keypad key is pressed); set to FALSE when they are disabled (keypad keys | ||
| 11878 | # behave normally) | ||
| 11879 | # If this flag is TRUE when the task starts, the task window is automatically enabled | ||
| 11880 | $self->{enabledFlag} = TRUE; | ||
| 11881 | |||
| 11882 | # The table objects (GA::Table::Button) created for each Gtk3::Button | ||
| 11883 | # A hash so we can work out which compass button was pressed, in the form | ||
| 11884 | # $compassHash{table_object} = standard_primary_direction | ||
| 11885 | $self->{compassHash} = {}; | ||
| 11886 | # A similar hash for the other buttons (which produce commands like 'kill all' or 'look'), | ||
| 11887 | # in the form | ||
| 11888 | # $cmdHash{table_object} = command_string | ||
| 11889 | $self->{cmdHash} = {}; | ||
| 11890 | # A second hash for these other buttons, linking the Gtk3::Button object to an Axmud | ||
| 11891 | # standard keycode. Hash in the form | ||
| 11892 | # $hash{standard_keycode} = table_object | ||
| 11893 | $self->{cmdKeycodeHash} = {}; | ||
| 11894 | |||
| 11895 | # Table objects created for various Gtk3 widgets, stored here because various functions | ||
| 11896 | # need them | ||
| 11897 | $self->{radioTableObj} = undef; # GA::Table::RadioButton | ||
| 11898 | $self->{radioTableObj2} = undef; # GA::Table::RadioButton | ||
| 11899 | $self->{comboTableObj} = undef; # GA::Table::ComboBox | ||
| 11900 | |||
| 11901 | # A list of the independent macro interfaces created, one for each button on the keypad | ||
| 11902 | # (e.g. so that pressing '7' on the keypad sends the command 'northwest') | ||
| 11903 | $self->{macroList} = [], | ||
| 11904 | # A hash of Axmud interfaces for independent macros matching the non-compass buttons only, | ||
| 11905 | # in the form | ||
| 11906 | # $macroHash{standard_keycode} = interface_object | ||
| 11907 | $self->{macroHash} = {}, | ||
| 11908 | |||
| 11909 | # When keypad macros are turned on, which standard keycode corresponds to which standard | ||
| 11910 | # direction. A hash in the form | ||
| 11911 | # $keypadDirHash{standard_keycode} = standard_direction | ||
| 11912 | # In order to disable a particular keycode, set the corresponding standard direction to | ||
| 11913 | # 'undef'. Do not delete the key-value pair from the hash and don't add extra keys. For | ||
| 11914 | # example: | ||
| 11915 | # ->keypadDirHash{'kp_1'} = 'undef' | ||
| 11916 | $self->{keypadDirHash} = { | ||
| 11917 | 'kp_8' => 'north', | ||
| 11918 | 'kp_9' => 'northeast', | ||
| 11919 | 'kp_6' => 'east', | ||
| 11920 | 'kp_3' => 'southeast', | ||
| 11921 | 'kp_2' => 'south', | ||
| 11922 | 'kp_1' => 'southwest', | ||
| 11923 | 'kp_4' => 'west', | ||
| 11924 | 'kp_7' => 'northwest', | ||
| 11925 | 'kp_add' => 'up', | ||
| 11926 | 'kp_subtract' => 'down', | ||
| 11927 | }; | ||
| 11928 | # Other keypad keys correspond to some common commands like 'inventory'. Here, we use a hash | ||
| 11929 | # in the form | ||
| 11930 | # $keypadCmdHash{standard_keycode} = command_string | ||
| 11931 | # In order to disable a particular keycode, set the corresponding command string to 'undef'. | ||
| 11932 | # Do not delete the key-value pair from the hash and don't add extra keys. For example: | ||
| 11933 | # ->keypadCmdHash{'kp_enter'} = 'undef' | ||
| 11934 | # | ||
| 11935 | # command_string is processed in the following way: | ||
| 11936 | # First, the string is split into a list, using a comma as the delimiter | ||
| 11937 | # e.g. 'kill,victim,mall' => ('kill', 'victim', 'mall') | ||
| 11938 | # e.g. 'amuse orc' => ('amuse orc') | ||
| 11939 | # | ||
| 11940 | # Now, if the FIRST item on the list is a standard command - one of those specified by the | ||
| 11941 | # command cages - it is treated like a standard command. The remaining items on the list | ||
| 11942 | # are in pairs, in the form | ||
| 11943 | # ('word', 'replacement', 'word', 'replacement') | ||
| 11944 | # The command cage is expecting (by default) a string like 'kill victim' - this is | ||
| 11945 | # interpolated into 'kill mall' ('victim' is the 'word', and 'mall' is the 'replacement' | ||
| 11946 | # | ||
| 11947 | # If the FIRST item on the list is not a standard command, then the whole command_string is | ||
| 11948 | # sent to the world | ||
| 11949 | # e.g. 'kill,victim,mall' => 'kill mall' is sent to the world, because 'kill' is a | ||
| 11950 | # standard world command (as specified by the command | ||
| 11951 | # cages) | ||
| 11952 | # e.g. 'amuse orc' => 'amuse orc' is sent to the world, uninterpolated, because | ||
| 11953 | # 'amuse' is not a standard world command | ||
| 11954 | $self->{keypadCmdHash} = { | ||
| 11955 | # 'kill', 'inventory', 'sc', 'look', 'get' and 'loot' are all standard world commands in | ||
| 11956 | # the command cages | ||
| 11957 | 'kp_0' => ';kill', | ||
| 11958 | 'kp_5' => 'look', | ||
| 11959 | 'kp_divide' => 'inventory', | ||
| 11960 | 'kp_multiply' => 'sc', # Brief score | ||
| 11961 | 'kp_full_stop' => 'get,object,all', | ||
| 11962 | 'kp_enter' => 'loot_room', | ||
| 11963 | }; | ||
| 11964 | # A hash to link each standard keycode used to the button actually pressed | ||
| 11965 | # (e.g. links 'kp_multiply' to '* key') | ||
| 11966 | # In each key-value pair, the key is a standard keycode, the corresponding value is a hint | ||
| 11967 | # displayed as a tooltip for each button | ||
| 11968 | # The hash is in the form | ||
| 11969 | # $keypadHintHash{standard_keycode} = hint | ||
| 11970 | $self->{keypadHintHash} = { | ||
| 11971 | 'kp_0' => '0 key', | ||
| 11972 | 'kp_1' => '1 key', | ||
| 11973 | 'kp_2' => '2 key', | ||
| 11974 | 'kp_3' => '3 key', | ||
| 11975 | 'kp_4' => '4 key', | ||
| 11976 | 'kp_5' => '5 key', | ||
| 11977 | 'kp_6' => '6 key', | ||
| 11978 | 'kp_7' => '7 key', | ||
| 11979 | 'kp_8' => '8 key', | ||
| 11980 | 'kp_9' => '9 key', | ||
| 11981 | 'kp_add' => '+ key', | ||
| 11982 | 'kp_subtract' => '- key', | ||
| 11983 | 'kp_multiply' => '* key', | ||
| 11984 | 'kp_divide' => '/ key', | ||
| 11985 | 'kp_full_stop' => '. key', | ||
| 11986 | 'kp_enter' => 'ENTER key', | ||
| 11987 | }; | ||
| 11988 | |||
| 11989 | # Bless task | ||
| 11990 | bless $self, $class; | ||
| 11991 | |||
| 11992 | # For all tasks that aren't temporary... | ||
| 11993 | if ($taskType) { | ||
| 11994 | |||
| 11995 | # Check that the task doesn't belong to a disabled plugin (in which case, it can't be | ||
| 11996 | # added to any current, initial or custom tasklist) | ||
| 11997 | if (! $self->checkPlugins()) { | ||
| 11998 | |||
| 11999 | return undef; | ||
| 12000 | } | ||
| 12001 | |||
| 12002 | # Set the parent file object | ||
| 12003 | $self->setParentFileObj($session, $taskType, $profName, $profCategory); | ||
| 12004 | |||
| 12005 | # Create entries in tasklists, if possible | ||
| 12006 | if (! $self->updateTaskLists($session)) { | ||
| 12007 | |||
| 12008 | return undef; | ||
| 12009 | } | ||
| 12010 | } | ||
| 12011 | |||
| 12012 | # Task creation complete | ||
| 12013 | return $self; | ||
| 12014 | } | ||
| 12015 | |||
| 12016 | sub clone { | ||
| 12017 | |||
| 12018 | # Create a clone of an existing task | ||
| 12019 | # Usually used upon connection to a world, when every task in the initial tasklists must | ||
| 12020 | # be cloned into a new object, representing a task in the current tasklist | ||
| 12021 | # (Also used when cloning a profile object, since all the tasks in its initial tasklist must | ||
| 12022 | # also be cloned) | ||
| 12023 | # | ||
| 12024 | # Expected arguments | ||
| 12025 | # $session - The parent GA::Session (not stored as an IV) | ||
| 12026 | # $taskType - Which tasklist this task is being created into - 'current' for the current | ||
| 12027 | # tasklist (tasks which are actually running now), 'initial' (tasks which | ||
| 12028 | # should be run when the user connects to the world). Custom tasks aren't | ||
| 12029 | # cloned (at the moment) | ||
| 12030 | # | ||
| 12031 | # Optional arguments | ||
| 12032 | # $profName - ($taskType = 'initial') name of the profile in whose initial tasklist the | ||
| 12033 | # existing task is stored | ||
| 12034 | # $profCategory | ||
| 12035 | # - ($taskType = 'initial') which category the profile falls under (i.e. | ||
| 12036 | # 'world', 'race', 'char', etc) | ||
| 12037 | # | ||
| 12038 | # Return values | ||
| 12039 | # 'undef' on improper arguments or if the task can't be cloned | ||
| 12040 | # Blessed reference to the newly-created object on success | ||
| 12041 | |||
| 12042 | my ($self, $session, $taskType, $profName, $profCategory, $check) = @_; | ||
| 12043 | |||
| 12044 | # Check for improper arguments | ||
| 12045 | if ( | ||
| 12046 | ! defined $session || ! defined $taskType || defined $check | ||
| 12047 | || ($taskType ne 'current' && $taskType ne 'initial') | ||
| 12048 | || ($taskType eq 'initial' && (! defined $profName || ! defined $profCategory)) | ||
| 12049 | ) { | ||
| 12050 | return $axmud::CLIENT->writeImproper($self->_objClass . '->clone', @_); | ||
| 12051 | } | ||
| 12052 | |||
| 12053 | # For initial tasks, check that $profName exists | ||
| 12054 | if ( | ||
| 12055 | $taskType eq 'initial' | ||
| 12056 | && defined $profName | ||
| 12057 | && ! $session->ivExists('profHash', $profName) | ||
| 12058 | ) { | ||
| 12059 | return $axmud::CLIENT->writeError( | ||
| 12060 | 'Can\'t create cloned task because \'' . $profName . '\' profile doesn\'t exist', | ||
| 12061 | $self->_objClass . '->clone', | ||
| 12062 | ); | ||
| 12063 | } | ||
| 12064 | |||
| 12065 | # Check that the task doesn't belong to a disabled plugin (in which case, it can't be | ||
| 12066 | # cloned) | ||
| 12067 | if (! $self->checkPlugins()) { | ||
| 12068 | |||
| 12069 | return undef; | ||
| 12070 | } | ||
| 12071 | |||
| 12072 | # Create the new task, using default settings and parameters | ||
| 12073 | my $clone = $self->_objClass->new($session, $taskType, $profName, $profCategory); | ||
| 12074 | |||
| 12075 | # Most of the cloned task's settings have default values, but a few are copied from the | ||
| 12076 | # original | ||
| 12077 | $self->cloneTaskSettings($clone); | ||
| 12078 | |||
| 12079 | # Give the new (cloned) task the same initial parameters as the original one | ||
| 12080 | $clone->{enabledFlag} = $self->enabledFlag; | ||
| 12081 | $clone->{compassHash} = {$self->compassHash}; | ||
| 12082 | $clone->{cmdHash} = {$self->cmdHash}; | ||
| 12083 | $clone->{cmdKeycodeHash} = {$self->cmdKeycodeHash}; | ||
| 12084 | |||
| 12085 | $clone->{radioTableObj} = $self->radioTableObj; | ||
| 12086 | $clone->{radioTableObj2} = $self->radioTableObj2; | ||
| 12087 | $clone->{comboTableObj} = $self->comboTableObj; | ||
| 12088 | |||
| 12089 | $clone->{macroList} = [$self->macroList]; | ||
| 12090 | $clone->{macroHash} = {$self->macroHash}; | ||
| 12091 | |||
| 12092 | $clone->{keypadDirHash} = {$self->keypadDirHash}; | ||
| 12093 | $clone->{keypadCmdHash} = {$self->keypadCmdHash}; | ||
| 12094 | $clone->{keypadHintHash} = {$self->keypadHintHash}; | ||
| 12095 | |||
| 12096 | # Cloning complete | ||
| 12097 | return $clone; | ||
| 12098 | } | ||
| 12099 | |||
| 12100 | # sub preserve {} # Inherited from generic task | ||
| 12101 | |||
| 12102 | # sub setParentFileObj {} # Inherited from generic task | ||
| 12103 | |||
| 12104 | # sub updateTaskLists {} # Inherited from generic task | ||
| 12105 | |||
| 12106 | # sub ttsReadAttrib {} # Inherited from generic task | ||
| 12107 | |||
| 12108 | # sub ttsSwitchFlagAttrib {} # Inherited from generic task | ||
| 12109 | |||
| 12110 | # sub ttsSetAlertAttrib {} # Inherited from generic task | ||
| 12111 | |||
| 12112 | ################## | ||
| 12113 | # Task windows | ||
| 12114 | |||
| 12115 | # sub toggleWin {} # Inherited from generic task | ||
| 12116 | |||
| 12117 | # sub openWin {} # Inherited from generic task | ||
| 12118 | |||
| 12119 | # sub closeWin {} # Inherited from generic task | ||
| 12120 | |||
| 12121 | ################## | ||
| 12122 | # Methods | ||
| 12123 | |||
| 12124 | # sub init {} # Inherited from generic task | ||
| 12125 | |||
| 12126 | sub doInit { | ||
| 12127 | |||
| 12128 | # Called by $self->init, just before the task completes its setup ($self->init) | ||
| 12129 | # | ||
| 12130 | # Expected arguments | ||
| 12131 | # (none besides $self) | ||
| 12132 | # | ||
| 12133 | # Return values | ||
| 12134 | # 'undef' on improper arguments | ||
| 12135 | # 1 otherwise | ||
| 12136 | |||
| 12137 | my ($self, $check) = @_; | ||
| 12138 | |||
| 12139 | # Check for improper arguments | ||
| 12140 | if (defined $check) { | ||
| 12141 | |||
| 12142 | return $axmud::CLIENT->writeImproper($self->_objClass . '->doInit', @_); | ||
| 12143 | } | ||
| 12144 | |||
| 12145 | # Set up the keyboard macros | ||
| 12146 | $self->resetMacros(); | ||
| 12147 | |||
| 12148 | # If the task has recently been updated, quickest way to update the window is to remove all | ||
| 12149 | # the current table objects, before creating new ones | ||
| 12150 | if ($self->hasResetFlag) { | ||
| 12151 | |||
| 12152 | if (! defined $self->winObj->tableStripObj->removeAllTableObjs()) { | ||
| 12153 | |||
| 12154 | # Operation failed; task must close | ||
| 12155 | $self->ivPoke('shutdownFlag', TRUE); | ||
| 12156 | return 1; | ||
| 12157 | } | ||
| 12158 | } | ||
| 12159 | |||
| 12160 | # Draw widgets for the task window | ||
| 12161 | $self->createWidgets(); | ||
| 12162 | |||
| 12163 | # If the task window should start enabled, then enable it (by pseudo-clicking the second | ||
| 12164 | # radio button) | ||
| 12165 | if ($self->enabledFlag) { | ||
| 12166 | |||
| 12167 | $self->enable(); | ||
| 12168 | } | ||
| 12169 | |||
| 12170 | return 1; | ||
| 12171 | } | ||
| 12172 | |||
| 12173 | sub doShutdown { | ||
| 12174 | |||
| 12175 | # Called just before the task completes a shutdown | ||
| 12176 | # For process tasks, called by $self->main. For activity tasks, called by $self->shutdown | ||
| 12177 | # | ||
| 12178 | # Destroys any macros created by this task | ||
| 12179 | # | ||
| 12180 | # Expected arguments | ||
| 12181 | # (none besides $self) | ||
| 12182 | # | ||
| 12183 | # Return values | ||
| 12184 | # 'undef' on improper arguments | ||
| 12185 | # 1 otherwise | ||
| 12186 | |||
| 12187 | my ($self, $check) = @_; | ||
| 12188 | |||
| 12189 | # Check for improper arguments | ||
| 12190 | if (defined $check) { | ||
| 12191 | |||
| 12192 | return $axmud::CLIENT->writeImproper($self->_objClass . '->doShutdown', @_); | ||
| 12193 | } | ||
| 12194 | |||
| 12195 | # Remove macros, ready for $self->resetMacros to be called to create new ones | ||
| 12196 | foreach my $interfaceObj ($self->macroList) { | ||
| 12197 | |||
| 12198 | # The TRUE argument means 'don't show an error message if the interface doesn't exist' | ||
| 12199 | $self->session->deleteInterface($interfaceObj->name, TRUE); | ||
| 12200 | } | ||
| 12201 | |||
| 12202 | return 1; | ||
| 12203 | } | ||
| 12204 | |||
| 12205 | sub doReset { | ||
| 12206 | |||
| 12207 | # Called just before the task completes a reset | ||
| 12208 | # For process tasks, called by $self->main. For activity tasks, called by $self->reset | ||
| 12209 | # | ||
| 12210 | # Destroys any macros created by this task | ||
| 12211 | # | ||
| 12212 | # Expected arguments | ||
| 12213 | # $newTaskObj - The replacement task object | ||
| 12214 | # | ||
| 12215 | # Return values | ||
| 12216 | # 'undef' on improper arguments | ||
| 12217 | # 1 otherwise | ||
| 12218 | |||
| 12219 | my ($self, $newTaskObj, $check) = @_; | ||
| 12220 | |||
| 12221 | # Check for improper arguments | ||
| 12222 | if (! defined $newTaskObj || defined $check) { | ||
| 12223 | |||
| 12224 | return $axmud::CLIENT->writeImproper($self->_objClass . '->doReset', @_); | ||
| 12225 | } | ||
| 12226 | |||
| 12227 | # Remove macros, ready for $self->resetMacros to be called to create new ones | ||
| 12228 | foreach my $interfaceObj ($self->macroList) { | ||
| 12229 | |||
| 12230 | # The TRUE argument means 'don't show an error message if the interface doesn't exist' | ||
| 12231 | $self->session->deleteInterface($interfaceObj->name, TRUE); | ||
| 12232 | } | ||
| 12233 | |||
| 12234 | return 1; | ||
| 12235 | } | ||
| 12236 | |||
| 12237 | sub resetMacros { | ||
| 12238 | |||
| 12239 | # Called by $self->doInit to set up macros that fire when the user presses one of the keys | ||
| 12240 | # on their keypad | ||
| 12241 | # | ||
| 12242 | # Expected arguments | ||
| 12243 | # (none) | ||
| 12244 | # | ||
| 12245 | # Return values | ||
| 12246 | # 'undef' on improper arguments | ||
| 12247 | # 1 otherwise | ||
| 12248 | |||
| 12249 | my ($self, $check) = @_; | ||
| 12250 | |||
| 12251 | # Local variables | ||
| 12252 | my ( | ||
| 12253 | $dictObj, | ||
| 12254 | @macroList, | ||
| 12255 | %dirHash, %cmdHash, %macroHash, | ||
| 12256 | ); | ||
| 12257 | |||
| 12258 | # Check for improper arguments | ||
| 12259 | if (defined $check) { | ||
| 12260 | |||
| 12261 | return $axmud::CLIENT->writeImproper($self->_objClass . '->resetMacros', @_); | ||
| 12262 | } | ||
| 12263 | |||
| 12264 | # Import the hash of standard directions (for quick lookup) | ||
| 12265 | %dirHash = $self->keypadDirHash; | ||
| 12266 | # Import the hash of keyboard commands (for quick lookup) | ||
| 12267 | %cmdHash = $self->keypadCmdHash; | ||
| 12268 | # Import the current dictionary | ||
| 12269 | $dictObj = $self->session->currentDict; | ||
| 12270 | |||
| 12271 | # Create one macro (initially disabled) for each standard primary direction | ||
| 12272 | OUTER: foreach my $standardKeycode (keys %dirHash) { | ||
| 12273 | |||
| 12274 | my ($standardDir, $interfaceObj); | ||
| 12275 | |||
| 12276 | $standardDir = $dirHash{$standardKeycode}; | ||
| 12277 | |||
| 12278 | # If the value in a key-value pair is 'undef', the corresponding key (a standard | ||
| 12279 | # keycode) isn't available to this task | ||
| 12280 | if (defined $standardDir) { | ||
| 12281 | |||
| 12282 | # Create the independent macro interface | ||
| 12283 | $interfaceObj = $self->session->createIndependentInterface( | ||
| 12284 | 'macro', | ||
| 12285 | $standardKeycode, # Stimulus | ||
| 12286 | $dictObj->ivShow('primaryDirHash', $standardDir), # Response | ||
| 12287 | 'enabled', | ||
| 12288 | 0, | ||
| 12289 | ); | ||
| 12290 | |||
| 12291 | if (! $interfaceObj) { | ||
| 12292 | |||
| 12293 | $self->writeWarning( | ||
| 12294 | 'Couldn\'t create macro for the standard keycode \'' . $standardKeycode | ||
| 12295 | . '\'', | ||
| 12296 | $self->_objClass . '->resetMacros', | ||
| 12297 | ); | ||
| 12298 | |||
| 12299 | last OUTER; | ||
| 12300 | |||
| 12301 | } else { | ||
| 12302 | |||
| 12303 | push (@macroList, $interfaceObj); | ||
| 12304 | } | ||
| 12305 | } | ||
| 12306 | } | ||
| 12307 | |||
| 12308 | # Create one macro (initially disabled) for each command mentioned in | ||
| 12309 | # $self->keypadCmdHash | ||
| 12310 | OUTER: foreach my $standardKeycode (keys %cmdHash) { | ||
| 12311 | |||
| 12312 | my ($cmdString, $cmd, $interfaceObj); | ||
| 12313 | |||
| 12314 | $cmdString = $cmdHash{$standardKeycode}; | ||
| 12315 | |||
| 12316 | # If the value in a key-value pair is 'undef', the corresponding key (a standard | ||
| 12317 | # keycode) isn't available to this task | ||
| 12318 | if (defined $cmdString) { | ||
| 12319 | |||
| 12320 | # $cmdString is in the form 'sharpen axe' (for a command to be sent unaltered), or | ||
| 12321 | # in the form 'kill,victim,axe' (for a command to be interpolated) | ||
| 12322 | # Convert the string into the actual command to be sent (an empty string is an | ||
| 12323 | # acceptable return value, in which case we don't create a macro so that no | ||
| 12324 | # command is sent when the user presses the corresponding key) | ||
| 12325 | if ($cmdString =~ m/,/) { | ||
| 12326 | |||
| 12327 | $cmd = $self->session->prepareCmd(split(m/,/, $cmdString)); | ||
| 12328 | } | ||
| 12329 | |||
| 12330 | if (! defined $cmd) { | ||
| 12331 | |||
| 12332 | # Couldn't interpolate the command, so use the original string unaltered | ||
| 12333 | $cmd = $cmdString; | ||
| 12334 | } | ||
| 12335 | |||
| 12336 | if ($cmd) { | ||
| 12337 | |||
| 12338 | # Create the independent macro interface | ||
| 12339 | $interfaceObj = $self->session->createIndependentInterface( | ||
| 12340 | 'macro', | ||
| 12341 | $standardKeycode, # Stimulus | ||
| 12342 | $cmd, # Response | ||
| 12343 | 'enabled', | ||
| 12344 | 0, | ||
| 12345 | ); | ||
| 12346 | |||
| 12347 | if (! $interfaceObj) { | ||
| 12348 | |||
| 12349 | $self->writeWarning( | ||
| 12350 | 'Couldn\'t create macro for the standard keycode \'' . $standardKeycode | ||
| 12351 | . '\'', | ||
| 12352 | $self->_objClass . '->resetMacros', | ||
| 12353 | ); | ||
| 12354 | |||
| 12355 | last OUTER; | ||
| 12356 | |||
| 12357 | } else { | ||
| 12358 | |||
| 12359 | push (@macroList, $interfaceObj); | ||
| 12360 | $macroHash{$standardKeycode} = $interfaceObj; | ||
| 12361 | } | ||
| 12362 | } | ||
| 12363 | } | ||
| 12364 | } | ||
| 12365 | |||
| 12366 | # Update IVs | ||
| 12367 | $self->ivPoke('macroList', @macroList); | ||
| 12368 | $self->ivPoke('macroHash', %macroHash); | ||
| 12369 | |||
| 12370 | return 1; | ||
| 12371 | } | ||
| 12372 | |||
| 12373 | sub createWidgets { | ||
| 12374 | |||
| 12375 | # Set up the widgets used in the task window | ||
| 12376 | # | ||
| 12377 | # Expected arguments | ||
| 12378 | # (none besides $self) | ||
| 12379 | # | ||
| 12380 | # Return values | ||
| 12381 | # 'undef' on improper arguments or if the task window isn't open | ||
| 12382 | # 1 otherwise | ||
| 12383 | |||
| 12384 | my ($self, $check) = @_; | ||
| 12385 | |||
| 12386 | # Local variables | ||
| 12387 | my ( | ||
| 12388 | $cmd, $radioTableObj, $radioTableObj2, $comboTableObj, | ||
| 12389 | @list, @comboList, | ||
| 12390 | %dirHash, %abbrevHash, %keypadHintHash, %keypadCmdHash, %compassHash, %cmdHash, | ||
| 12391 | %cmdKeycodeHash, | ||
| 12392 | ); | ||
| 12393 | |||
| 12394 | # Check for improper arguments | ||
| 12395 | if (defined $check) { | ||
| 12396 | |||
| 12397 | return $axmud::CLIENT->writeImproper($self->_objClass . '->createWidgets', @_); | ||
| 12398 | } | ||
| 12399 | |||
| 12400 | # If the task window (a 'grid' window or a pseudo-window inside the session's 'main' window) | ||
| 12401 | # isn't open, don't need to create widgets | ||
| 12402 | if (! $self->winObj) { | ||
| 12403 | |||
| 12404 | return undef; | ||
| 12405 | } | ||
| 12406 | |||
| 12407 | # Import the current dictionary's primary directions | ||
| 12408 | %dirHash = $self->session->currentDict->primaryDirHash; | ||
| 12409 | %abbrevHash = $self->session->currentDict->primaryAbbrevHash; | ||
| 12410 | # Import some local hashes | ||
| 12411 | %keypadHintHash = $self->keypadHintHash; | ||
| 12412 | %keypadCmdHash = $self->keypadCmdHash; | ||
| 12413 | |||
| 12414 | # Reduce the standard spacing between table objects (5 pixels around each button is too | ||
| 12415 | # much) | ||
| 12416 | $self->winObj->tableStripObj->changeSpacing(2); | ||
| 12417 | |||
| 12418 | # Create buttons for each of the ten main primary directions (ignoring 'northnorthwest', | ||
| 12419 | # etc), and store the buttons in a hash | ||
| 12420 | @list = ( | ||
| 12421 | 'northwest', 'kp_7', 0, 9, 0, 11, | ||
| 12422 | 'north', 'kp_8', 10, 19, 0, 11, | ||
| 12423 | 'northeast', 'kp_9', 20, 29, 0, 11, | ||
| 12424 | 'west', 'kp_4', 0, 9, 12, 23, | ||
| 12425 | 'east', 'kp_6', 20, 29, 12, 23, | ||
| 12426 | 'southwest', 'kp_1', 0, 9, 24, 35, | ||
| 12427 | 'south', 'kp_2', 10, 19, 24, 35, | ||
| 12428 | 'southeast', 'kp_3', 20, 29, 24, 35, | ||
| 12429 | 'up', 'kp_subtract', 0, 14, 36, 47, | ||
| 12430 | 'down', 'kp_add', 15, 29, 36, 47, | ||
| 12431 | ); | ||
| 12432 | |||
| 12433 | do { | ||
| 12434 | |||
| 12435 | my ($dir, $keycode, $left, $right, $top, $bottom, $hint, $tooltips, $thisTableObj); | ||
| 12436 | |||
| 12437 | $dir = shift @list; | ||
| 12438 | $keycode = shift @list; | ||
| 12439 | $left = shift @list; | ||
| 12440 | $right = shift @list; | ||
| 12441 | $top = shift @list; | ||
| 12442 | $bottom = shift @list; | ||
| 12443 | |||
| 12444 | $hint = $keypadHintHash{$keycode}; | ||
| 12445 | |||
| 12446 | if ($dirHash{$dir}) { | ||
| 12447 | $tooltips = 'Click to go ' . $dirHash{$dir} . ' (' . $hint . ')'; | ||
| 12448 | } else { | ||
| 12449 | $tooltips = 'Direction not set (' . $hint . ')'; | ||
| 12450 | } | ||
| 12451 | |||
| 12452 | $thisTableObj = $self->winObj->tableStripObj->addTableObj( | ||
| 12453 | 'Games::Axmud::Table::Button', | ||
| 12454 | $left, $right, $top, $bottom, | ||
| 12455 | undef, | ||
| 12456 | # Init settings | ||
| 12457 | 'func' => $self->getMethodRef('compassCallback'), | ||
| 12458 | 'id' => $keycode, | ||
| 12459 | 'text' => $self->shortenText($abbrevHash{$dir}, 3), | ||
| 12460 | 'tooltips' => $tooltips, | ||
| 12461 | ); | ||
| 12462 | |||
| 12463 | $compassHash{$thisTableObj} = $dir; | ||
| 12464 | |||
| 12465 | } until (! @list); | ||
| 12466 | |||
| 12467 | # Create buttons for other commands, using the remaining keypad keys | ||
| 12468 | @list = ( | ||
| 12469 | 'kp_divide', 30, 44, 36, 47, | ||
| 12470 | 'kp_multiply', 45, 59, 36, 47, | ||
| 12471 | 'kp_0', 0, 14, 48, 59, | ||
| 12472 | 'kp_full_stop', 15, 29, 48, 59, | ||
| 12473 | 'kp_enter', 30, 44, 48, 59, | ||
| 12474 | 'kp_5', 45, 59, 48, 59, | ||
| 12475 | ); | ||
| 12476 | |||
| 12477 | do { | ||
| 12478 | |||
| 12479 | my ( | ||
| 12480 | $keycode, $left, $right, $top, $bottom, $original, $cmd, $text, $hint, $tooltips, | ||
| 12481 | $thisTableObj, | ||
| 12482 | ); | ||
| 12483 | |||
| 12484 | $keycode = shift @list; | ||
| 12485 | $left = shift @list; | ||
| 12486 | $right = shift @list; | ||
| 12487 | $top = shift @list; | ||
| 12488 | $bottom = shift @list; | ||
| 12489 | |||
| 12490 | $original = $keypadCmdHash{$keycode}; | ||
| 12491 | if ($original =~ m/,/) { | ||
| 12492 | |||
| 12493 | $cmd = $self->session->prepareCmd(split(m/,/, $original)); | ||
| 12494 | } | ||
| 12495 | |||
| 12496 | if (! defined $cmd) { | ||
| 12497 | |||
| 12498 | # Command can't be interpolated, so use the original | ||
| 12499 | $cmd = $original; | ||
| 12500 | } | ||
| 12501 | |||
| 12502 | $hint = $keypadHintHash{$keycode}; | ||
| 12503 | |||
| 12504 | if ($cmd) { | ||
| 12505 | $tooltips = 'Click to send \'' . $cmd . '\' (' . $hint . ')'; | ||
| 12506 | } else { | ||
| 12507 | $tooltips = 'Command not set (' . $hint . ')'; | ||
| 12508 | } | ||
| 12509 | |||
| 12510 | $thisTableObj = $self->winObj->tableStripObj->addTableObj( | ||
| 12511 | 'Games::Axmud::Table::Button', | ||
| 12512 | $left, $right, $top, $bottom, | ||
| 12513 | undef, | ||
| 12514 | # Init settings | ||
| 12515 | 'func' => $self->getMethodRef('cmdCallback'), | ||
| 12516 | 'id' => $keycode, | ||
| 12517 | 'text' => $self->shortenText($cmd, 12), | ||
| 12518 | 'tooltips' => $tooltips, | ||
| 12519 | ); | ||
| 12520 | |||
| 12521 | $cmdHash{$thisTableObj} = $cmd; | ||
| 12522 | $cmdKeycodeHash{$keycode} = $thisTableObj; | ||
| 12523 | |||
| 12524 | } until (! @list); | ||
| 12525 | |||
| 12526 | # Store all the buttons created, so that $self->moveCallback and ->cmdCallback can work | ||
| 12527 | # out which Gtk3::Button corresponds to which command | ||
| 12528 | $self->ivPoke('compassHash', %compassHash); | ||
| 12529 | $self->ivPoke('cmdHash', %cmdHash); | ||
| 12530 | $self->ivPoke('cmdKeycodeHash', %cmdKeycodeHash); | ||
| 12531 | |||
| 12532 | # Create two radiobuttons to enable/disable the use of the keypad | ||
| 12533 | $self->winObj->tableStripObj->addTableObj( | ||
| 12534 | 'Games::Axmud::Table::Label', | ||
| 12535 | 30, 39, 0, 11, | ||
| 12536 | undef, | ||
| 12537 | # Init settings | ||
| 12538 | 'text' => 'Keypad', | ||
| 12539 | 'align_y' => 0.5, | ||
| 12540 | ); | ||
| 12541 | |||
| 12542 | $radioTableObj = $self->winObj->tableStripObj->addTableObj( | ||
| 12543 | 'Games::Axmud::Table::RadioButton', | ||
| 12544 | 40, 49, 0, 11, | ||
| 12545 | undef, | ||
| 12546 | # Init settings | ||
| 12547 | 'func' => $self->getMethodRef('radioButtonCallback'), | ||
| 12548 | 'id' => 'button_1', | ||
| 12549 | 'text' => 'Disable', | ||
| 12550 | 'select_flag' => FALSE, | ||
| 12551 | ); | ||
| 12552 | |||
| 12553 | $radioTableObj2 = $self->winObj->tableStripObj->addTableObj( | ||
| 12554 | 'Games::Axmud::Table::RadioButton', | ||
| 12555 | 50, 59, 0, 11, | ||
| 12556 | undef, | ||
| 12557 | # Init settings | ||
| 12558 | 'func' => $self->getMethodRef('radioButtonCallback'), | ||
| 12559 | 'id' => 'button_2', | ||
| 12560 | 'text' => 'Enable', | ||
| 12561 | 'select_flag' => FALSE, | ||
| 12562 | 'group' => $radioTableObj->group, | ||
| 12563 | ); | ||
| 12564 | |||
| 12565 | # Create a combobox and an entry so that the user can set new values in $self->keypadCmdHash | ||
| 12566 | $self->winObj->tableStripObj->addTableObj( | ||
| 12567 | 'Games::Axmud::Table::Label', | ||
| 12568 | 30, 39, 12, 23, | ||
| 12569 | undef, | ||
| 12570 | # Init settings | ||
| 12571 | 'text' => 'Keycode', | ||
| 12572 | ); | ||
| 12573 | |||
| 12574 | @comboList = ( | ||
| 12575 | 'kp_0', | ||
| 12576 | 'kp_5', | ||
| 12577 | 'kp_multiply', | ||
| 12578 | 'kp_divide', | ||
| 12579 | 'kp_full_stop', | ||
| 12580 | 'kp_enter', | ||
| 12581 | ); | ||
| 12582 | $comboTableObj = $self->winObj->tableStripObj->addTableObj( | ||
| 12583 | 'Games::Axmud::Table::ComboBox', | ||
| 12584 | 40, 59, 12, 23, | ||
| 12585 | undef, | ||
| 12586 | # Init settings | ||
| 12587 | 'title' => 'Select keycode', | ||
| 12588 | 'list_ref' => \@comboList, | ||
| 12589 | ); | ||
| 12590 | |||
| 12591 | $self->winObj->tableStripObj->addTableObj( | ||
| 12592 | 'Games::Axmud::Table::Label', | ||
| 12593 | 30, 39, 24, 35, | ||
| 12594 | undef, | ||
| 12595 | # Init settings | ||
| 12596 | 'text' => 'Command', | ||
| 12597 | ); | ||
| 12598 | |||
| 12599 | $self->winObj->tableStripObj->addTableObj( | ||
| 12600 | 'Games::Axmud::Table::Entry', | ||
| 12601 | 40, 59, 24, 35, | ||
| 12602 | undef, | ||
| 12603 | # Init settings | ||
| 12604 | 'func' => $self->getMethodRef('miniEntryCallback'), | ||
| 12605 | ); | ||
| 12606 | |||
| 12607 | # Store the table objects for the benefit of the callback functions | ||
| 12608 | $self->ivPoke('radioTableObj', $radioTableObj); | ||
| 12609 | $self->ivPoke('radioTableObj2', $radioTableObj2); | ||
| 12610 | $self->ivPoke('comboTableObj', $comboTableObj); | ||
| 12611 | |||
| 12612 | # Display all the widgets | ||
| 12613 | $self->winObj->winShowAll($self->_objClass . '->createWidgets'); | ||
| 12614 | |||
| 12615 | return 1; | ||
| 12616 | } | ||
| 12617 | |||
| 12618 | sub shortenText { | ||
| 12619 | |||
| 12620 | # Called by $self->createWidgets and ->entryCallback | ||
| 12621 | # If the buttons are assigned very long labels, the task window gets stretched. Prevent this | ||
| 12622 | # (hopefully) but limiting the size of the text assigned to button labels | ||
| 12623 | # Also converts the modified text to upper-case characters, before returning it | ||
| 12624 | # | ||
| 12625 | # Expected arguments | ||
| 12626 | # $text - Some text representing a command | ||
| 12627 | # $max - The maximum size of the text (minimum 3) | ||
| 12628 | # | ||
| 12629 | # Return values | ||
| 12630 | # 'undef' on improper arguments | ||
| 12631 | # Otherwise, the shortened $text | ||
| 12632 | |||
| 12633 | my ($self, $text, $max, $check) = @_; | ||
| 12634 | |||
| 12635 | # Check for improper arguments | ||
| 12636 | if (! defined $text || ! defined $max || defined $check) { | ||
| 12637 | |||
| 12638 | return $axmud::CLIENT->writeImproper($self->_objClass . '->shortenText', @_); | ||
| 12639 | } | ||
| 12640 | |||
| 12641 | if (length ($text) > $max) { | ||
| 12642 | |||
| 12643 | $text = substr($text, 0, $max) . '...'; | ||
| 12644 | } | ||
| 12645 | |||
| 12646 | return uc($text); | ||
| 12647 | } | ||
| 12648 | |||
| 12649 | sub enable { | ||
| 12650 | |||
| 12651 | # Called by GA::Cmd::Compass->do and PermCompass->do, and also by $self->doInit | ||
| 12652 | # Enables the task window, meaning that keypad keys send a world command | ||
| 12653 | # | ||
| 12654 | # Expected arguments | ||
| 12655 | # (none besides $self) | ||
| 12656 | # | ||
| 12657 | # Optional arguments | ||
| 12658 | # $callbackFlag - TRUE if called by $self->radioButtonCallback, in which case there's no | ||
| 12659 | # need to modify the radio button widget itself | ||
| 12660 | # | ||
| 12661 | # Return values | ||
| 12662 | # 'undef' on improper arguments | ||
| 12663 | # 1 otherwise | ||
| 12664 | |||
| 12665 | my ($self, $callbackFlag, $check) = @_; | ||
| 12666 | |||
| 12667 | # Check for improper arguments | ||
| 12668 | if (defined $check) { | ||
| 12669 | |||
| 12670 | return $axmud::CLIENT->writeImproper($self->_objClass . '->enable', @_); | ||
| 12671 | } | ||
| 12672 | |||
| 12673 | $self->ivPoke('enabledFlag', TRUE); | ||
| 12674 | |||
| 12675 | # If the task window is open, switch the radio buttons to 'enable' | ||
| 12676 | if ($self->winObj && $self->radioTableObj2 && ! $callbackFlag) { | ||
| 12677 | |||
| 12678 | $self->radioTableObj2->button->set_active(TRUE); | ||
| 12679 | } | ||
| 12680 | |||
| 12681 | # Modify the 'enabled' attribute for each independent macro interface | ||
| 12682 | foreach my $interfaceObj ($self->macroList) { | ||
| 12683 | |||
| 12684 | $interfaceObj->modifyAttribs($self->session, 'enabled', TRUE); | ||
| 12685 | } | ||
| 12686 | |||
| 12687 | return 1; | ||
| 12688 | } | ||
| 12689 | |||
| 12690 | sub disable { | ||
| 12691 | |||
| 12692 | # Called by GA::Cmd::Compass->do and PermCompass->do | ||
| 12693 | # Disables the task window, meaning that keypad keys behave normally | ||
| 12694 | # | ||
| 12695 | # Expected arguments | ||
| 12696 | # (none besides $self) | ||
| 12697 | # | ||
| 12698 | # Optional arguments | ||
| 12699 | # $callbackFlag - TRUE if called by $self->radioButtonCallback, in which case there's no | ||
| 12700 | # need to modify the radio button widget itself | ||
| 12701 | # | ||
| 12702 | # Return values | ||
| 12703 | # 'undef' on improper arguments | ||
| 12704 | # 1 otherwise | ||
| 12705 | |||
| 12706 | my ($self, $callbackFlag, $check) = @_; | ||
| 12707 | |||
| 12708 | # Check for improper arguments | ||
| 12709 | if (defined $check) { | ||
| 12710 | |||
| 12711 | return $axmud::CLIENT->writeImproper($self->_objClass . '->disable', @_); | ||
| 12712 | } | ||
| 12713 | |||
| 12714 | $self->ivPoke('enabledFlag', FALSE); | ||
| 12715 | |||
| 12716 | # If the task window is open, switch the radio buttons to 'disable' | ||
| 12717 | if ($self->winObj && $self->radioTableObj && ! $callbackFlag) { | ||
| 12718 | |||
| 12719 | $self->radioTableObj->button->set_active(TRUE); | ||
| 12720 | } | ||
| 12721 | |||
| 12722 | # Modify the 'enabled' attribute for each independent macro interface | ||
| 12723 | foreach my $interfaceObj ($self->macroList) { | ||
| 12724 | |||
| 12725 | $interfaceObj->modifyAttribs($self->session, 'enabled', FALSE); | ||
| 12726 | } | ||
| 12727 | |||
| 12728 | return 1; | ||
| 12729 | } | ||
| 12730 | |||
| 12731 | ################## | ||
| 12732 | # Response methods | ||
| 12733 | |||
| 12734 | sub compassCallback { | ||
| 12735 | |||
| 12736 | # Called by a ->signal_connect in a GA::Table::Button object when the user clicks on one | ||
| 12737 | # of the compass buttons | ||
| 12738 | # Sends the corresponding movement command to the world | ||
| 12739 | # | ||
| 12740 | # Expected arguments | ||
| 12741 | # $tableObj - The GA::Table::Button object for the button | ||
| 12742 | # $button - The actual Gtk3::Button clicked | ||
| 12743 | # $id - The callback ID; in this case, a keycode | ||
| 12744 | # | ||
| 12745 | # Return values | ||
| 12746 | # 'undef' on improper arguments, if the button isn't one of the compass buttons or if no | ||
| 12747 | # direction has been set for this button | ||
| 12748 | # 1 otherwise | ||
| 12749 | |||
| 12750 | my ($self, $tableObj, $button, $id, $check) = @_; | ||
| 12751 | |||
| 12752 | # Local variables | ||
| 12753 | my ($standardDir, $customDir); | ||
| 12754 | |||
| 12755 | # Check for improper arguments | ||
| 12756 | if (! defined $tableObj || ! defined $button || ! defined $id || defined $check) { | ||
| 12757 | |||
| 12758 | return $axmud::CLIENT->writeImproper($self->_objClass . '->compassCallback', @_); | ||
| 12759 | } | ||
| 12760 | |||
| 12761 | # Work out which movement button was clicked | ||
| 12762 | if (! $self->ivExists('compassHash', $tableObj)) { | ||
| 12763 | |||
| 12764 | # Unrecognised button | ||
| 12765 | return undef; | ||
| 12766 | |||
| 12767 | } else { | ||
| 12768 | |||
| 12769 | $standardDir = $self->ivShow('compassHash', $tableObj); | ||
| 12770 | } | ||
| 12771 | |||
| 12772 | # Get the equivalent direction (using custom direction from the current dictionary) | ||
| 12773 | $customDir = $self->session->currentDict->ivShow('primaryDirHash', $standardDir); | ||
| 12774 | if (! $customDir) { | ||
| 12775 | |||
| 12776 | # Unrecognised direction (or no direction set) | ||
| 12777 | return undef; | ||
| 12778 | |||
| 12779 | } else { | ||
| 12780 | |||
| 12781 | # Go in that direction | ||
| 12782 | $self->session->sendModCmd('go', 'direction', $customDir); | ||
| 12783 | |||
| 12784 | return 1; | ||
| 12785 | } | ||
| 12786 | } | ||
| 12787 | |||
| 12788 | sub cmdCallback { | ||
| 12789 | |||
| 12790 | # Called by a ->signal_connect in a GA::Table::Button object when the user clicks on one | ||
| 12791 | # of the non-compass buttons | ||
| 12792 | # Sends the corresponding non-movement command to the world | ||
| 12793 | # | ||
| 12794 | # Expected arguments | ||
| 12795 | # $tableObj - The GA::Table::Button object for the button | ||
| 12796 | # $button - The actual Gtk3::Button clicked | ||
| 12797 | # $id - The callback ID; in this case, a keycode | ||
| 12798 | # | ||
| 12799 | # Return values | ||
| 12800 | # 'undef' on improper arguments, if the button isn't one of the non-compass buttons or if | ||
| 12801 | # no command has been set for this button | ||
| 12802 | # 1 otherwise | ||
| 12803 | |||
| 12804 | my ($self, $tableObj, $button, $id, $check) = @_; | ||
| 12805 | |||
| 12806 | # Local variables | ||
| 12807 | my $cmd; | ||
| 12808 | |||
| 12809 | # Check for improper arguments | ||
| 12810 | if (! defined $tableObj || ! defined $button || ! defined $id || defined $check) { | ||
| 12811 | |||
| 12812 | return $axmud::CLIENT->writeImproper($self->_objClass . '->cmdCallback', @_); | ||
| 12813 | } | ||
| 12814 | |||
| 12815 | # Work out which non-movement button was clicked | ||
| 12816 | if (! $self->ivExists('cmdHash', $tableObj)) { | ||
| 12817 | |||
| 12818 | # Unrecognised button | ||
| 12819 | return undef; | ||
| 12820 | |||
| 12821 | } else { | ||
| 12822 | |||
| 12823 | $cmd = $self->ivShow('cmdHash', $tableObj); | ||
| 12824 | if (! $cmd) { | ||
| 12825 | |||
| 12826 | # Unrecognised command (or no command set) | ||
| 12827 | return undef; | ||
| 12828 | |||
| 12829 | } else { | ||
| 12830 | |||
| 12831 | # Send the command (interpolation has already been done) | ||
| 12832 | $self->session->worldCmd($cmd); | ||
| 12833 | return 1; | ||
| 12834 | } | ||
| 12835 | } | ||
| 12836 | } | ||
| 12837 | |||
| 12838 | sub radioButtonCallback { | ||
| 12839 | |||
| 12840 | # Called by a ->signal_connect in a GA::Table::RadioButton object when the user clicks on | ||
| 12841 | # one of the radio buttons | ||
| 12842 | # Enables or disable the keypad macros, as appropriate | ||
| 12843 | # | ||
| 12844 | # Expected arguments | ||
| 12845 | # $tableObj - The GA::Table::RadioButton object for the button | ||
| 12846 | # $radioButton - The actual Gtk3::RadioButton clicked | ||
| 12847 | # $id - The callback ID; in this case, the strings 'button_1' or 'button_2' | ||
| 12848 | # | ||
| 12849 | # Return values | ||
| 12850 | # 'undef' on improper arguments | ||
| 12851 | # 1 otherwise | ||
| 12852 | |||
| 12853 | my ($self, $tableObj, $radioButton, $id, $check) = @_; | ||
| 12854 | |||
| 12855 | # Check for improper arguments | ||
| 12856 | if (! defined $tableObj || ! defined $radioButton || ! defined $id || defined $check) { | ||
| 12857 | |||
| 12858 | return $axmud::CLIENT->writeImproper($self->_objClass . '->radioButtonCallback', @_); | ||
| 12859 | } | ||
| 12860 | |||
| 12861 | # Work out which button was clicked | ||
| 12862 | if ($id eq 'button_1') { | ||
| 12863 | |||
| 12864 | # Disable the keypad macros. The TRUE argument means 'don't modify the widget' | ||
| 12865 | $self->disable(TRUE); | ||
| 12866 | |||
| 12867 | } elsif ($id eq 'button_2') { | ||
| 12868 | |||
| 12869 | # Otherwise, enable the keypad macros | ||
| 12870 | $self->enable(TRUE); | ||
| 12871 | } | ||
| 12872 | |||
| 12873 | return 1; | ||
| 12874 | } | ||
| 12875 | |||
| 12876 | sub miniEntryCallback { | ||
| 12877 | |||
| 12878 | # Called by a ->signal_connect in a GA::Table::Entry object when the user types something | ||
| 12879 | # in the entry box and presses ENTER | ||
| 12880 | # Finds the keycode currently displayed in the combobox and updates both the macro and the | ||
| 12881 | # Gtk3::Button for that keycode | ||
| 12882 | # | ||
| 12883 | # Expected arguments | ||
| 12884 | # $entryTableObj - The GA::Table::Entry object for the entry | ||
| 12885 | # $entry - The actual Gtk3::Entry used | ||
| 12886 | # $id - The callback ID; in this case, an empty string | ||
| 12887 | # $text - The text entered by the user (may be an empty string) | ||
| 12888 | # | ||
| 12889 | # Return values | ||
| 12890 | # 'undef' on improper arguments, if no keycode has been selected in the combobox, if | ||
| 12891 | # nothing has been typed in the entry box or for a general error | ||
| 12892 | # 1 otherwise | ||
| 12893 | |||
| 12894 | my ($self, $entryTableObj, $entry, $id, $text, $check) = @_; | ||
| 12895 | |||
| 12896 | # Local variables | ||
| 12897 | my ($cmd, $keycode, $buttonTableObj, $interfaceObj); | ||
| 12898 | |||
| 12899 | # Check for improper arguments | ||
| 12900 | if ( | ||
| 12901 | ! defined $entryTableObj || ! defined $entry || ! defined $id || ! defined $text | ||
| 12902 | || defined $check | ||
| 12903 | ) { | ||
| 12904 | return $axmud::CLIENT->writeImproper($self->_objClass . '->miniEntryCallback', @_); | ||
| 12905 | } | ||
| 12906 | |||
| 12907 | # Get the text entered in the Gtk3::Entry and trim leading/trailing whitespace | ||
| 12908 | $cmd = $axmud::CLIENT->trimWhitespace($text); | ||
| 12909 | |||
| 12910 | # Retrieve the last value selected in the combobox, which will be a standard keycode | ||
| 12911 | $keycode = $self->comboTableObj->get_text(); | ||
| 12912 | |||
| 12913 | if (! defined $keycode || ! $self->ivExists('keypadCmdHash', $keycode) || ! $cmd) { | ||
| 12914 | |||
| 12915 | # No selection made in the combobox. Reset both the entry and the combobox | ||
| 12916 | $entryTableObj->set_text(); | ||
| 12917 | $self->comboTableObj->resetCombo(); | ||
| 12918 | |||
| 12919 | return undef; | ||
| 12920 | } | ||
| 12921 | |||
| 12922 | # Update the main IV | ||
| 12923 | $self->ivAdd('keypadCmdHash', $keycode, $cmd); | ||
| 12924 | |||
| 12925 | # Find the corresponding button | ||
| 12926 | $buttonTableObj = $self->ivShow('cmdKeycodeHash', $keycode); | ||
| 12927 | |||
| 12928 | # Change the button's label, and the command sent when the button is clicked (max text | ||
| 12929 | # length is 12) | ||
| 12930 | $buttonTableObj->set_text($self->shortenText($cmd, 12)); | ||
| 12931 | $self->ivAdd('cmdHash', $buttonTableObj, $cmd); | ||
| 12932 | |||
| 12933 | # Change the button's tooltips | ||
| 12934 | $buttonTableObj->set_tooltips( | ||
| 12935 | 'Click to send \'' . $cmd . '\' (' . $self->ivShow('keypadHintHash', $keycode) . ')', | ||
| 12936 | ); | ||
| 12937 | |||
| 12938 | # Find the macro interface corresponding to the selected standard keycode | ||
| 12939 | $interfaceObj = $self->ivShow('macroHash', $keycode); | ||
| 12940 | if ($interfaceObj) { | ||
| 12941 | |||
| 12942 | # Modify the macro to send the new command, instead of the old one | ||
| 12943 | $interfaceObj->modifyAttribs($self->session, 'response', $cmd); | ||
| 12944 | } | ||
| 12945 | |||
| 12946 | # Clear the entry box | ||
| 12947 | $entryTableObj->set_text(); | ||
| 12948 | |||
| 12949 | # Update the task window to show the new button label | ||
| 12950 | $self->winObj->winShowAll($self->_objClass . '->miniEntryCallback'); | ||
| 12951 | |||
| 12952 | return 1; | ||
| 12953 | } | ||
| 12954 | |||
| 12955 | ################## | ||
| 12956 | # Accessors - set | ||
| 12957 | |||
| 12958 | sub set_enabledFlag { | ||
| 12959 | |||
| 12960 | # Called by GA::Cmd::PermCompass->do | ||
| 12961 | |||
| 12962 | my ($self, $flag, $check) = @_; | ||
| 12963 | |||
| 12964 | # Check for improper arguments | ||
| 12965 | if (! defined $flag || defined $check) { | ||
| 12966 | |||
| 12967 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_enabledFlag', @_); | ||
| 12968 | } | ||
| 12969 | |||
| 12970 | if (! $flag) { | ||
| 12971 | $self->ivPoke('enabledFlag', FALSE); | ||
| 12972 | } else { | ||
| 12973 | $self->ivPoke('enabledFlag', TRUE); | ||
| 12974 | } | ||
| 12975 | |||
| 12976 | return 1; | ||
| 12977 | } | ||
| 12978 | |||
| 12979 | sub set_key { | ||
| 12980 | |||
| 12981 | # Called by GA::Cmd::Compass->do and PermCompass->do | ||
| 12982 | |||
| 12983 | my ($self, $keycode, $cmd, $check) = @_; | ||
| 12984 | |||
| 12985 | # Local variables | ||
| 12986 | my ($buttonTableObj, $interfaceObj); | ||
| 12987 | |||
| 12988 | # Check for improper arguments | ||
| 12989 | if ( | ||
| 12990 | ! defined $keycode | ||
| 12991 | || ! $self->ivExists('keypadCmdHash', $keycode) | ||
| 12992 | || defined $check | ||
| 12993 | ) { | ||
| 12994 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_key', @_); | ||
| 12995 | } | ||
| 12996 | |||
| 12997 | # (Code adapted from $self->entryCallback) | ||
| 12998 | |||
| 12999 | # Trim leading/trailing whitespace ($cmd is an optional argument) | ||
| 13000 | if ($cmd) { | ||
| 13001 | |||
| 13002 | $cmd = $axmud::CLIENT->trimWhitespace($cmd); | ||
| 13003 | } | ||
| 13004 | |||
| 13005 | # Update the main IV | ||
| 13006 | $self->ivAdd('keypadCmdHash', $keycode, $cmd); | ||
| 13007 | |||
| 13008 | # If the window is open, update it | ||
| 13009 | if ($self->winObj) { | ||
| 13010 | |||
| 13011 | # Find the corresponding button table object | ||
| 13012 | $buttonTableObj = $self->ivShow('cmdKeycodeHash', $keycode); | ||
| 13013 | |||
| 13014 | # Change the button's label, and the command sent when the button is clicked (max text | ||
| 13015 | # length is 12) | ||
| 13016 | $buttonTableObj->set_text($self->shortenText($cmd, 12)); | ||
| 13017 | $self->ivAdd('cmdHash', $buttonTableObj, $cmd); | ||
| 13018 | |||
| 13019 | # Change the button's tooltips | ||
| 13020 | $buttonTableObj->set_tooltips( | ||
| 13021 | 'Click to send \'' . $cmd . '\' (' . $self->ivShow('keypadHintHash', $keycode) | ||
| 13022 | . ')', | ||
| 13023 | ); | ||
| 13024 | |||
| 13025 | # Find the macro interface corresponding to the selected standard keycode | ||
| 13026 | $interfaceObj = $self->ivShow('macroHash', $keycode); | ||
| 13027 | if ($interfaceObj) { | ||
| 13028 | |||
| 13029 | # Modify the macro to send the new command, instead of the old one | ||
| 13030 | $interfaceObj->modifyAttribs($self->session, 'response', $cmd); | ||
| 13031 | } | ||
| 13032 | |||
| 13033 | # Update the task window to show the new button label | ||
| 13034 | $self->winObj->winShowAll($self->_objClass . '->set_key'); | ||
| 13035 | } | ||
| 13036 | |||
| 13037 | return 1; | ||
| 13038 | } | ||
| 13039 | |||
| 13040 | ################## | ||
| 13041 | # Accessors - task settings - get | ||
| 13042 | |||
| 13043 | # The accessors for task settings are inherited from the generic task | ||
| 13044 | |||
| 13045 | ################## | ||
| 13046 | # Accessors - task parameters - get | ||
| 13047 | |||
| 13048 | sub enabledFlag | ||
| 13049 | { $_[0]->{enabledFlag} } | ||
| 13050 | |||
| 13051 | sub compassHash | ||
| 13052 | { my $self = shift; return %{$self->{compassHash}}; } | ||
| 13053 | sub cmdHash | ||
| 13054 | { my $self = shift; return %{$self->{cmdHash}}; } | ||
| 13055 | sub cmdKeycodeHash | ||
| 13056 | { my $self = shift; return %{$self->{cmdKeycodeHash}}; } | ||
| 13057 | |||
| 13058 | sub radioTableObj | ||
| 13059 | { $_[0]->{radioTableObj} } | ||
| 13060 | sub radioTableObj2 | ||
| 13061 | { $_[0]->{radioTableObj2} } | ||
| 13062 | sub comboTableObj | ||
| 13063 | { $_[0]->{comboTableObj} } | ||
| 13064 | |||
| 13065 | sub macroList | ||
| 13066 | { my $self = shift; return @{$self->{macroList}}; } | ||
| 13067 | sub macroHash | ||
| 13068 | { my $self = shift; return %{$self->{macroHash}}; } | ||
| 13069 | |||
| 13070 | sub keypadDirHash | ||
| 13071 | { my $self = shift; return %{$self->{keypadDirHash}}; } | ||
| 13072 | sub keypadCmdHash | ||
| 13073 | { my $self = shift; return %{$self->{keypadCmdHash}}; } | ||
| 13074 | sub keypadHintHash | ||
| 13075 | { my $self = shift; return %{$self->{keypadHintHash}}; } | ||
| 13076 | } | ||
| 13077 | |||
| 13078 | { package Games::Axmud::Task::Condition; | ||
| 13079 | |||
| 13080 | use strict; | ||
| 13081 | use warnings; | ||
| 13082 | # use diagnostics; | ||
| 13083 | |||
| 13084 | use Glib qw(TRUE FALSE); | ||
| 13085 | |||
| 13086 | our @ISA = qw(Games::Axmud::Generic::Task Games::Axmud); | ||
| 13087 | |||
| 13088 | ################## | ||
| 13089 | # Constructors | ||
| 13090 | |||
| 13091 | sub new { | ||
| 13092 | |||
| 13093 | # Creates a new instances of the Condition task | ||
| 13094 | # | ||
| 13095 | # Expected arguments | ||
| 13096 | # $session - The parent GA::Session (not stored as an IV) | ||
| 13097 | # | ||
| 13098 | # Optional arguments | ||
| 13099 | # $taskType - Which tasklist this task is being created into - 'current' for the current | ||
| 13100 | # tasklist (tasks which are actually running now), 'initial' (tasks which | ||
| 13101 | # should be run when the user connects to the world), 'custom' (tasks with | ||
| 13102 | # customised initial parameters, which are run when the user demands). If | ||
| 13103 | # set to 'undef', this is a temporary task, created in order to access the | ||
| 13104 | # default values stored in IVs, that will not be added to any tasklist | ||
| 13105 | # $profName - ($taskType = 'current', when called by $self->clone) Name of the | ||
| 13106 | # profile from whose initial tasklist this task was created ('undef' if | ||
| 13107 | # none) | ||
| 13108 | # - ($taskType = 'initial') name of the profile in whose initial tasklist this | ||
| 13109 | # task will be. If 'undef', the global initial tasklist is used | ||
| 13110 | # - ($taskType = 'custom') 'undef' | ||
| 13111 | # $profCategory | ||
| 13112 | # - ($taskType = 'current', 'initial') which category the profile falls undef | ||
| 13113 | # (i.e. 'world', 'race', 'char', etc, or 'undef' if no profile) | ||
| 13114 | # - ($taskType = 'custom') 'undef' | ||
| 13115 | # $customName | ||
| 13116 | # - ($taskType = 'current', 'initial') 'undef' | ||
| 13117 | # - ($taskType = 'custom') the custom task name, matching a key in | ||
| 13118 | # GA::Session->customTaskHash | ||
| 13119 | # | ||
| 13120 | # Return values | ||
| 13121 | # 'undef' on improper arguments or if the task can't be added to the specified tasklist | ||
| 13122 | # Blessed reference to the newly-created object on success | ||
| 13123 | |||
| 13124 | my ($class, $session, $taskType, $profName, $profCategory, $customName, $check) = @_; | ||
| 13125 | |||
| 13126 | # Check for improper arguments | ||
| 13127 | if (! defined $class || ! defined $session || defined $check) { | ||
| 13128 | |||
| 13129 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 13130 | } | ||
| 13131 | |||
| 13132 | if ($taskType) { | ||
| 13133 | |||
| 13134 | # For initial tasks, check that $profName exists | ||
| 13135 | if ( | ||
| 13136 | $taskType eq 'initial' | ||
| 13137 | && defined $profName | ||
| 13138 | && ! $session->ivExists('profHash', $profName) | ||
| 13139 | ) { | ||
| 13140 | return $session->writeError( | ||
| 13141 | 'Can\'t create new task because \'' . $profName . '\' profile doesn\'t exist', | ||
| 13142 | $class . '->new', | ||
| 13143 | ); | ||
| 13144 | |||
| 13145 | # For custom tasks, check that $customName doesn't already exist | ||
| 13146 | } elsif ( | ||
| 13147 | $taskType eq 'custom' | ||
| 13148 | && $axmud::CLIENT->ivExists('customTaskHash', $customName) | ||
| 13149 | ) { | ||
| 13150 | return $session->writeError( | ||
| 13151 | 'Can\'t create new custom task because \'' . $customName . '\' is already being' | ||
| 13152 | . ' used', | ||
| 13153 | $class . '->new', | ||
| 13154 | ); | ||
| 13155 | |||
| 13156 | } elsif ($taskType ne 'current' && $taskType ne 'initial' && $taskType ne 'custom') { | ||
| 13157 | |||
| 13158 | return $session->writeError( | ||
| 13159 | 'Can\'t create new task because \'' . $taskType . '\' is an invalid tasklist', | ||
| 13160 | $class . '->new', | ||
| 13161 | ); | ||
| 13162 | } | ||
| 13163 | } | ||
| 13164 | |||
| 13165 | # Task settings | ||
| 13166 | my $self = Games::Axmud::Generic::Task->new( | ||
| 13167 | $session, | ||
| 13168 | $taskType, | ||
| 13169 | $profName, | ||
| 13170 | $profCategory, | ||
| 13171 | $customName, | ||
| 13172 | ); | ||
| 13173 | |||
| 13174 | $self->{_objName} = 'condition_task'; | ||
| 13175 | $self->{_objClass} = $class; | ||
| 13176 | $self->{_parentFile} = undef; # Set below | ||
| 13177 | $self->{_parentWorld} = undef; # Set below | ||
| 13178 | $self->{_privFlag} = TRUE, # All IVs are private | ||
| 13179 | |||
| 13180 | $self->{name} = 'condition_task'; | ||
| 13181 | $self->{prettyName} = 'Condition'; | ||
| 13182 | $self->{shortName} = 'Cn'; | ||
| 13183 | $self->{shortCutIV} = 'conditionTask'; # Axmud built-in jealous task | ||
| 13184 | |||
| 13185 | $self->{category} = 'process'; | ||
| 13186 | $self->{descrip} = 'Tracks the condition of objects in the inventory'; | ||
| 13187 | $self->{jealousyFlag} = TRUE; | ||
| 13188 | $self->{requireLocatorFlag} = FALSE; | ||
| 13189 | $self->{profSensitivityFlag} = TRUE; | ||
| 13190 | $self->{storableFlag} = TRUE; | ||
| 13191 | $self->{delayTime} = 0; | ||
| 13192 | $self->{allowWinFlag} = FALSE; | ||
| 13193 | $self->{requireWinFlag} = FALSE; | ||
| 13194 | $self->{startWithWinFlag} = FALSE; | ||
| 13195 | $self->{winPreferList} = []; | ||
| 13196 | $self->{winmap} = undef; | ||
| 13197 | $self->{winUpdateFunc} = undef; | ||
| 13198 | $self->{tabMode} = undef; | ||
| 13199 | $self->{monochromeFlag} = FALSE; | ||
| 13200 | $self->{noScrollFlag} = FALSE; | ||
| 13201 | $self->{ttsFlag} = FALSE; | ||
| 13202 | $self->{ttsConfig} = undef; | ||
| 13203 | $self->{ttsAttribHash} = {}; | ||
| 13204 | $self->{ttsFlagAttribHash} = {}; | ||
| 13205 | $self->{ttsAlertAttribHash} = {}; | ||
| 13206 | $self->{status} = 'wait_init'; | ||
| 13207 | # The task is activated when it starts, and can be disactivated (temporarily) to allow the | ||
| 13208 | # user to see the normal output of commands like 'examine axe', etc | ||
| 13209 | $self->{activeFlag} = FALSE; # Task can be activated/disactivated | ||
| 13210 | |||
| 13211 | # Task parameters | ||
| 13212 | # | ||
| 13213 | # The dependent trigger interfaces created; one for non-gagged patterns, the other for | ||
| 13214 | # gagged patterns | ||
| 13215 | $self->{triggerList} = []; | ||
| 13216 | $self->{ignoreTriggerList} = []; | ||
| 13217 | |||
| 13218 | # If this flag is set to TRUE, the check is only performed once (set to FALSE otherwise) | ||
| 13219 | $self->{checkOnceFlag} = FALSE; | ||
| 13220 | # The inventory list, imported from the Inventory task at the beginning of each check. | ||
| 13221 | # Objects are removed from this list, one by one, as they are checked | ||
| 13222 | $self->{inventoryList} = []; | ||
| 13223 | # Every time the Inventory task updates its inventory, it copies the old list into its own | ||
| 13224 | # ->previousList. That gets carved up by ->ivSplice operations, so the Inventory task | ||
| 13225 | # supplies this task with a copy, because doing any splicing | ||
| 13226 | $self->{previousList} = []; | ||
| 13227 | # Blessed reference of the current model object being checked ('undef' if none being | ||
| 13228 | # checked right now) | ||
| 13229 | $self->{currentObj} = undef; | ||
| 13230 | # When comparing two objects, how certain the task needs to be that it they match. | ||
| 13231 | # 0 = any objects match, 100 = only identical objects match, 70 - objects are fairly (70%) | ||
| 13232 | # similar, 90 = objects are very (90%) similar), etc | ||
| 13233 | $self->{sensitivity} = 80; | ||
| 13234 | |||
| 13235 | # If $self->checkOnceFlag is FALSE, the following parameters are consulted: | ||
| 13236 | # How many seconds to wait before the first check (ignored if $self->checkOnceFlag is set to | ||
| 13237 | # TRUE, in which case the check happens right away) | ||
| 13238 | $self->{firstCheckTime} = 15; | ||
| 13239 | # How many seconds to wait before performing the next check | ||
| 13240 | $self->{waitTime} = 90; | ||
| 13241 | # The time at which to perform the next check (matches GA::Session->sessionTime) | ||
| 13242 | $self->{nextCheckTime} = undef; | ||
| 13243 | # If flag set to TRUE, no check cycles are done; set to FALSE otherwise. | ||
| 13244 | # Can be set to TRUE by any code (with a call to ->set_ignoreCheckFlag) when it wants to | ||
| 13245 | # temporarily delay the inventory check; when it's time for an condition check, no check | ||
| 13246 | # happens, and $self->condition is set as normal | ||
| 13247 | $self->{ignoreCheckFlag} = FALSE; | ||
| 13248 | |||
| 13249 | # Maximum no. seconds to wait while checking each object (a timeout) | ||
| 13250 | $self->{maxObjTime} = 5; | ||
| 13251 | # The time at which to give up the check on the current object (matches | ||
| 13252 | # GA::Session->sessionTime) | ||
| 13253 | $self->{nextObjTime} = undef; | ||
| 13254 | |||
| 13255 | # Bless task | ||
| 13256 | bless $self, $class; | ||
| 13257 | |||
| 13258 | # For all tasks that aren't temporary... | ||
| 13259 | if ($taskType) { | ||
| 13260 | |||
| 13261 | # Check that the task doesn't belong to a disabled plugin (in which case, it can't be | ||
| 13262 | # added to any current, initial or custom tasklist) | ||
| 13263 | if (! $self->checkPlugins()) { | ||
| 13264 | |||
| 13265 | return undef; | ||
| 13266 | } | ||
| 13267 | |||
| 13268 | # Set the parent file object | ||
| 13269 | $self->setParentFileObj($session, $taskType, $profName, $profCategory); | ||
| 13270 | |||
| 13271 | # Create entries in tasklists, if possible | ||
| 13272 | if (! $self->updateTaskLists($session)) { | ||
| 13273 | |||
| 13274 | return undef; | ||
| 13275 | } | ||
| 13276 | } | ||
| 13277 | |||
| 13278 | # Task creation complete | ||
| 13279 | return $self; | ||
| 13280 | } | ||
| 13281 | |||
| 13282 | sub clone { | ||
| 13283 | |||
| 13284 | # Create a clone of an existing task | ||
| 13285 | # Usually used upon connection to a world, when every task in the initial tasklists must | ||
| 13286 | # be cloned into a new object, representing a task in the current tasklist | ||
| 13287 | # (Also used when cloning a profile object, since all the tasks in its initial tasklist must | ||
| 13288 | # also be cloned) | ||
| 13289 | # | ||
| 13290 | # Expected arguments | ||
| 13291 | # $session - The parent GA::Session (not stored as an IV) | ||
| 13292 | # $taskType - Which tasklist this task is being created into - 'current' for the current | ||
| 13293 | # tasklist (tasks which are actually running now), 'initial' (tasks which | ||
| 13294 | # should be run when the user connects to the world). Custom tasks aren't | ||
| 13295 | # cloned (at the moment) | ||
| 13296 | # | ||
| 13297 | # Optional arguments | ||
| 13298 | # $profName - ($taskType = 'initial') name of the profile in whose initial tasklist the | ||
| 13299 | # existing task is stored | ||
| 13300 | # $profCategory | ||
| 13301 | # - ($taskType = 'initial') which category the profile falls under (i.e. | ||
| 13302 | # 'world', 'race', 'char', etc) | ||
| 13303 | # | ||
| 13304 | # Return values | ||
| 13305 | # 'undef' on improper arguments or if the task can't be cloned | ||
| 13306 | # Blessed reference to the newly-created object on success | ||
| 13307 | |||
| 13308 | my ($self, $session, $taskType, $profName, $profCategory, $check) = @_; | ||
| 13309 | |||
| 13310 | # Check for improper arguments | ||
| 13311 | if ( | ||
| 13312 | ! defined $session || ! defined $taskType || defined $check | ||
| 13313 | || ($taskType ne 'current' && $taskType ne 'initial') | ||
| 13314 | || ($taskType eq 'initial' && (! defined $profName || ! defined $profCategory)) | ||
| 13315 | ) { | ||
| 13316 | return $axmud::CLIENT->writeImproper($self->_objClass . '->clone', @_); | ||
| 13317 | } | ||
| 13318 | |||
| 13319 | # For initial tasks, check that $profName exists | ||
| 13320 | if ( | ||
| 13321 | $taskType eq 'initial' | ||
| 13322 | && defined $profName | ||
| 13323 | && ! $session->ivExists('profHash', $profName) | ||
| 13324 | ) { | ||
| 13325 | return $axmud::CLIENT->writeError( | ||
| 13326 | 'Can\'t create cloned task because \'' . $profName . '\' profile doesn\'t exist', | ||
| 13327 | $self->_objClass . '->clone', | ||
| 13328 | ); | ||
| 13329 | } | ||
| 13330 | |||
| 13331 | # Check that the task doesn't belong to a disabled plugin (in which case, it can't be | ||
| 13332 | # cloned) | ||
| 13333 | if (! $self->checkPlugins()) { | ||
| 13334 | |||
| 13335 | return undef; | ||
| 13336 | } | ||
| 13337 | |||
| 13338 | # Create the new task, using default settings and parameters | ||
| 13339 | my $clone = $self->_objClass->new($session, $taskType, $profName, $profCategory); | ||
| 13340 | |||
| 13341 | # Most of the cloned task's settings have default values, but a few are copied from the | ||
| 13342 | # original | ||
| 13343 | $self->cloneTaskSettings($clone); | ||
| 13344 | |||
| 13345 | # Give the new (cloned) task the same initial parameters as the original one | ||
| 13346 | $clone->{triggerList} = [$self->triggerList]; | ||
| 13347 | $clone->{ignoreTriggerList} = [$self->ignoreTriggerList]; | ||
| 13348 | |||
| 13349 | $clone->{checkOnceFlag} = $self->checkOnceFlag; | ||
| 13350 | $clone->{inventoryList} = [$self->inventoryList]; | ||
| 13351 | $clone->{previousList} = [$self->previousList]; | ||
| 13352 | $clone->{currentObj} = $self->currentObj; | ||
| 13353 | $clone->{sensitivity} = $self->sensitivity; | ||
| 13354 | |||
| 13355 | $clone->{firstCheckTime} = $self->firstCheckTime; | ||
| 13356 | $clone->{waitTime} = $self->waitTime; | ||
| 13357 | $clone->{nextCheckTime} = $self->nextCheckTime; | ||
| 13358 | $clone->{ignoreCheckFlag} = $self->ignoreCheckFlag; | ||
| 13359 | |||
| 13360 | $clone->{maxObjTime} = $self->maxObjTime; | ||
| 13361 | $clone->{nextObjTime} = $self->nextObjTime; | ||
| 13362 | |||
| 13363 | # Cloning complete | ||
| 13364 | return $clone; | ||
| 13365 | } | ||
| 13366 | |||
| 13367 | sub preserve { | ||
| 13368 | |||
| 13369 | # Called by $self->main whenever this task is reset, in order to preserve some if its task | ||
| 13370 | # parameters (but not necessarily all of them) | ||
| 13371 | # | ||
| 13372 | # Expected arguments | ||
| 13373 | # $newTask - The new task which has been created, to which some of this task's instance | ||
| 13374 | # variables might have to be transferred | ||
| 13375 | # | ||
| 13376 | # Return values | ||
| 13377 | # 'undef' on improper arguments, or if $newTask isn't in the GA::Session's current | ||
| 13378 | # tasklist | ||
| 13379 | # 1 on success | ||
| 13380 | |||
| 13381 | my ($self, $newTask, $check) = @_; | ||
| 13382 | |||
| 13383 | # Check for improper arguments | ||
| 13384 | if (! defined $newTask || defined $check) { | ||
| 13385 | |||
| 13386 | return $axmud::CLIENT->writeImproper($self->_objClass . '->preserve', @_); | ||
| 13387 | } | ||
| 13388 | |||
| 13389 | # Check the task is in the current tasklist | ||
| 13390 | if (! $self->session->ivExists('currentTaskHash', $newTask->uniqueName)) { | ||
| 13391 | |||
| 13392 | return $self->writeWarning( | ||
| 13393 | '\'' . $self->uniqueName . '\' task missing from the current tasklist', | ||
| 13394 | $self->_objClass . '->preserve', | ||
| 13395 | ); | ||
| 13396 | } | ||
| 13397 | |||
| 13398 | # Preserve some task parameters (the others are left with their default settings, some of | ||
| 13399 | # which will be re-initialised in stage 2) | ||
| 13400 | |||
| 13401 | $newTask->ivPoke('checkOnceFlag', $self->checkOnceFlag); | ||
| 13402 | $newTask->ivPoke('sensitivity', $self->sensitivity); | ||
| 13403 | $newTask->ivPoke('firstCheckTime', $self->firstCheckTime); | ||
| 13404 | $newTask->ivPoke('waitTime', $self->waitTime); | ||
| 13405 | $newTask->ivPoke('ignoreCheckFlag', $self->ignoreCheckFlag); | ||
| 13406 | $newTask->ivPoke('maxObjTime', $self->maxObjTime); | ||
| 13407 | |||
| 13408 | return 1; | ||
| 13409 | } | ||
| 13410 | |||
| 13411 | # sub setParentFileObj {} # Inherited from generic task | ||
| 13412 | |||
| 13413 | # sub updateTaskLists {} # Inherited from generic task | ||
| 13414 | |||
| 13415 | # sub ttsReadAttrib {} # Inherited from generic task | ||
| 13416 | |||
| 13417 | # sub ttsSwitchFlagAttrib {} # Inherited from generic task | ||
| 13418 | |||
| 13419 | # sub ttsSetAlertAttrib {} # Inherited from generic task | ||
| 13420 | |||
| 13421 | ################## | ||
| 13422 | # Task windows | ||
| 13423 | |||
| 13424 | # sub toggleWin {} # Inherited from generic task | ||
| 13425 | |||
| 13426 | # sub openWin {} # Inherited from generic task | ||
| 13427 | |||
| 13428 | # sub closeWin {} # Inherited from generic task | ||
| 13429 | |||
| 13430 | ################## | ||
| 13431 | # Methods | ||
| 13432 | |||
| 13433 | # sub main {} # Inherited from generic task | ||
| 13434 | |||
| 13435 | # sub doShutdown {} # Inherited from generic task | ||
| 13436 | |||
| 13437 | # sub doReset {} # Inherited from generic task | ||
| 13438 | |||
| 13439 | # sub doFirstStage { # Inherited from generic task | ||
| 13440 | |||
| 13441 | sub doStage { | ||
| 13442 | |||
| 13443 | # Called by $self->main to process all stages (except stage 1) | ||
| 13444 | # | ||
| 13445 | # Expected arguments | ||
| 13446 | # (none besides $self) | ||
| 13447 | # | ||
| 13448 | # Return values | ||
| 13449 | # 'undef' on improper arguments or if this function sets that task's ->status IV to | ||
| 13450 | # 'finished' or sets its ->shutdownFlag to TRUE | ||
| 13451 | # Otherwise, we normally return the new value of $self->stage | ||
| 13452 | |||
| 13453 | my ($self, $check) = @_; | ||
| 13454 | |||
| 13455 | # Check for improper arguments | ||
| 13456 | if (defined $check) { | ||
| 13457 | |||
| 13458 | return $axmud::CLIENT->writeImproper($self->_objClass . '->doStage', @_); | ||
| 13459 | } | ||
| 13460 | |||
| 13461 | if ($self->stage == 2) { | ||
| 13462 | |||
| 13463 | # Can't do anything until the current character has been set, the user has logged | ||
| 13464 | # in to the world and the Inventory task has started | ||
| 13465 | if ( | ||
| 13466 | ! $self->session->currentChar | ||
| 13467 | || ! $self->session->loginFlag | ||
| 13468 | || ! $self->session->inventoryTask | ||
| 13469 | || ! $self->session->inventoryTask->activeFlag | ||
| 13470 | ) { | ||
| 13471 | # Repeat this stage indefinitely | ||
| 13472 | return $self->ivPoke('stage', 2); | ||
| 13473 | } | ||
| 13474 | |||
| 13475 | # The task is now active | ||
| 13476 | $self->ivPoke('activeFlag', TRUE); | ||
| 13477 | |||
| 13478 | # Set up triggers | ||
| 13479 | $self->resetTriggers(); | ||
| 13480 | |||
| 13481 | # Set the time at which the first (i.e. next) check occurs | ||
| 13482 | if ($self->checkOnceFlag) { | ||
| 13483 | |||
| 13484 | # Do the first (and only) check right away | ||
| 13485 | $self->ivPoke('nextCheckTime', 0); | ||
| 13486 | |||
| 13487 | } else { | ||
| 13488 | |||
| 13489 | # Do the first check after some seconds | ||
| 13490 | $self->ivPoke( | ||
| 13491 | 'nextCheckTime', | ||
| 13492 | ($self->session->sessionTime + $self->firstCheckTime), | ||
| 13493 | ); | ||
| 13494 | } | ||
| 13495 | |||
| 13496 | return $self->ivPoke('stage', 3); | ||
| 13497 | |||
| 13498 | } elsif ($self->stage == 3) { | ||
| 13499 | |||
| 13500 | # Stage 3: the start of a condition check cycle | ||
| 13501 | |||
| 13502 | my ( | ||
| 13503 | $invTaskObj, $charObj, | ||
| 13504 | @newList, | ||
| 13505 | ); | ||
| 13506 | |||
| 13507 | # Import the Inventory task and the current character profile | ||
| 13508 | $invTaskObj = $self->session->inventoryTask; | ||
| 13509 | $charObj = $self->session->currentChar; | ||
| 13510 | |||
| 13511 | # If this task has been disactivated, or if the Inventory task doesn't exist, wait | ||
| 13512 | # indefinitely | ||
| 13513 | # If it's not time for the next check, wait until it is | ||
| 13514 | if ( | ||
| 13515 | ! $self->activeFlag | ||
| 13516 | || ! $invTaskObj | ||
| 13517 | || ! $invTaskObj->activeFlag | ||
| 13518 | || $self->session->sessionTime < $self->nextCheckTime | ||
| 13519 | ) { | ||
| 13520 | # Wait indefinitely | ||
| 13521 | return $self->ivPoke('stage', 3); | ||
| 13522 | |||
| 13523 | } elsif ($self->ignoreCheckFlag) { | ||
| 13524 | |||
| 13525 | # Don't do a check, but set $self->nextCheckTime as if a check cycle had just been | ||
| 13526 | # completed | ||
| 13527 | return $self->endCheck(); | ||
| 13528 | } | ||
| 13529 | |||
| 13530 | # Otherwise, import the Inventory task's inventory list | ||
| 13531 | $self->ivPoke('inventoryList', $invTaskObj->inventoryList); | ||
| 13532 | $self->ivUndef('currentObj'); | ||
| 13533 | |||
| 13534 | # If the inventory list is empty, that's the end of the check | ||
| 13535 | if (! $self->inventoryList) { | ||
| 13536 | |||
| 13537 | return $self->endCheck(); | ||
| 13538 | } | ||
| 13539 | |||
| 13540 | # If the character's monitored object list is empty, we monitor all objects; otherwise | ||
| 13541 | # we must remove everything from $self->inventoryList that doesn't match a monitored | ||
| 13542 | # object | ||
| 13543 | if ($charObj->monitorObjList) { | ||
| 13544 | |||
| 13545 | foreach my $obj ($self->inventoryList) { | ||
| 13546 | |||
| 13547 | if ( | ||
| 13548 | $self->session->worldModelObj->objCompare( | ||
| 13549 | $self->sensitivity, | ||
| 13550 | $obj, | ||
| 13551 | $charObj->monitorObjList, | ||
| 13552 | ) | ||
| 13553 | ) { | ||
| 13554 | # We need to monitor this object | ||
| 13555 | push (@newList, $obj); | ||
| 13556 | } | ||
| 13557 | } | ||
| 13558 | |||
| 13559 | # If @newList is empty, that's the end of the check | ||
| 13560 | if (! @newList) { | ||
| 13561 | |||
| 13562 | return $self->endCheck(); | ||
| 13563 | |||
| 13564 | } else { | ||
| 13565 | |||
| 13566 | $self->ivPoke('inventoryList', @newList); | ||
| 13567 | } | ||
| 13568 | } | ||
| 13569 | |||
| 13570 | # Check the condition of items in the inventory, one by one | ||
| 13571 | return $self->ivPoke('stage', 4); | ||
| 13572 | |||
| 13573 | } elsif ($self->stage == 4) { | ||
| 13574 | |||
| 13575 | # Stage 4: Check the next object in $self->inventoryList | ||
| 13576 | |||
| 13577 | if (! $self->inventoryList) { | ||
| 13578 | |||
| 13579 | # Every object has been checked. If only one check is allowed, end the task now | ||
| 13580 | if ($self->checkOnceFlag) { | ||
| 13581 | |||
| 13582 | # Task complete | ||
| 13583 | $self->ivPoke('shutdownFlag', TRUE); | ||
| 13584 | return undef; | ||
| 13585 | } | ||
| 13586 | |||
| 13587 | # Otherwise, set the time at which the next check cycle occurs | ||
| 13588 | $self->ivPoke( | ||
| 13589 | 'nextCheckTime', | ||
| 13590 | ($self->session->sessionTime + $self->waitTime), | ||
| 13591 | ); | ||
| 13592 | |||
| 13593 | # Stage 3 waits for the start of the next check cycle | ||
| 13594 | return $self->ivPoke('stage', 3); | ||
| 13595 | |||
| 13596 | } else { | ||
| 13597 | |||
| 13598 | # Retrieve the first unchecked object in the inventory list | ||
| 13599 | $self->ivPoke('currentObj', $self->ivShift('inventoryList')); | ||
| 13600 | # Send the 'examine' command to the world | ||
| 13601 | $self->session->sendModCmd('examine', 'object', $self->currentObj->noun); | ||
| 13602 | # Wait for a response | ||
| 13603 | $self->ivPoke( | ||
| 13604 | 'nextObjTime', | ||
| 13605 | ($self->session->sessionTime + $self->maxObjTime), | ||
| 13606 | ); | ||
| 13607 | |||
| 13608 | return $self->ivPoke('stage', 5); | ||
| 13609 | } | ||
| 13610 | |||
| 13611 | } elsif ($self->stage == 5) { | ||
| 13612 | |||
| 13613 | # Stage 5: Having sent a command to the world, wait for a response | ||
| 13614 | |||
| 13615 | # When the world responds with the selected item's condition, $self->triggerSeen is | ||
| 13616 | # called. That method sets $self->currentObj to 'undef', so that we know its condition | ||
| 13617 | # has been found | ||
| 13618 | # Wait until the object's condition has been found or until the time limit is reached | ||
| 13619 | if ( | ||
| 13620 | ! defined ($self->currentObj) | ||
| 13621 | || $self->session->sessionTime < $self->nextCheckTime | ||
| 13622 | ) { | ||
| 13623 | # Move on to the next object in the list | ||
| 13624 | $self->ivUndef('currentObj', undef); | ||
| 13625 | |||
| 13626 | return $self->ivPoke('stage', 4); | ||
| 13627 | |||
| 13628 | } else { | ||
| 13629 | |||
| 13630 | # Continue waiting for a response for this object | ||
| 13631 | return $self->ivPoke('stage', 5); | ||
| 13632 | } | ||
| 13633 | |||
| 13634 | } else { | ||
| 13635 | |||
| 13636 | # The task stage has somehow been set to an invalid value | ||
| 13637 | return $self->invalidStage(); | ||
| 13638 | } | ||
| 13639 | } | ||
| 13640 | |||
| 13641 | sub activate { | ||
| 13642 | |||
| 13643 | # Called by GA::Cmd::ActivateInventory->do (not called by $self->doStage, because the task | ||
| 13644 | # is activated at stage 2, before interfaces are created) | ||
| 13645 | # Enables the interfaces created by this task | ||
| 13646 | # | ||
| 13647 | # Expected arguments | ||
| 13648 | # (none besides $self) | ||
| 13649 | # | ||
| 13650 | # Return values | ||
| 13651 | # 'undef' on improper arguments | ||
| 13652 | # 1 otherwise | ||
| 13653 | |||
| 13654 | my ($self, $check) = @_; | ||
| 13655 | |||
| 13656 | # Local variables | ||
| 13657 | my @list; | ||
| 13658 | |||
| 13659 | # Check for improper arguments | ||
| 13660 | if (defined $check) { | ||
| 13661 | |||
| 13662 | return $axmud::CLIENT->writeImproper($self->_objClass . '->activate', @_); | ||
| 13663 | } | ||
| 13664 | |||
| 13665 | # Compile a list of triggers | ||
| 13666 | @list = ($self->triggerList, $self->ignoreTriggerList); | ||
| 13667 | |||
| 13668 | # Enable each interface in turn | ||
| 13669 | foreach my $obj (@list) { | ||
| 13670 | |||
| 13671 | $obj->modifyAttribs($self->session, 'enabled', 1); | ||
| 13672 | } | ||
| 13673 | |||
| 13674 | # Update IVs | ||
| 13675 | $self->ivPoke('activeFlag', TRUE); | ||
| 13676 | $self->ivPoke( | ||
| 13677 | 'nextCheckTime', | ||
| 13678 | ($self->session->sessionTime + $self->firstCheckTime), | ||
| 13679 | ); | ||
| 13680 | |||
| 13681 | return 1; | ||
| 13682 | } | ||
| 13683 | |||
| 13684 | sub disactivate { | ||
| 13685 | |||
| 13686 | # Called by GA::Cmd::DisactivateInventory->do | ||
| 13687 | # Disables the interfaces created by this task | ||
| 13688 | # | ||
| 13689 | # Expected arguments | ||
| 13690 | # (none besides $self) | ||
| 13691 | # | ||
| 13692 | # Return values | ||
| 13693 | # 'undef' on improper arguments | ||
| 13694 | # 1 otherwise | ||
| 13695 | |||
| 13696 | my ($self, $check) = @_; | ||
| 13697 | |||
| 13698 | # Local variables | ||
| 13699 | my @list; | ||
| 13700 | |||
| 13701 | # Check for improper arguments | ||
| 13702 | if (defined $check) { | ||
| 13703 | |||
| 13704 | return $axmud::CLIENT->writeImproper($self->_objClass . '->disactivate', @_); | ||
| 13705 | } | ||
| 13706 | |||
| 13707 | # Compile a list of triggers | ||
| 13708 | @list = ($self->triggerList, $self->ignoreTriggerList); | ||
| 13709 | |||
| 13710 | # Disable each interface in turn | ||
| 13711 | foreach my $obj (@list) { | ||
| 13712 | |||
| 13713 | $obj->modifyAttribs($self->session, 'enabled', 0); | ||
| 13714 | } | ||
| 13715 | |||
| 13716 | # Update IVs | ||
| 13717 | $self->ivPoke('activeFlag', FALSE); | ||
| 13718 | # Reset some IVs in case a condition check was in progress | ||
| 13719 | $self->ivEmpty('inventoryList'); | ||
| 13720 | $self->ivUndef('currentObj'); | ||
| 13721 | $self->ivUndef('nextCheckTime'); | ||
| 13722 | $self->ivUndef('nextObjTime'); | ||
| 13723 | |||
| 13724 | # $self->main, stage 3, waits for the task to be activated again | ||
| 13725 | $self->ivPoke('stage', 3); | ||
| 13726 | |||
| 13727 | return 1; | ||
| 13728 | } | ||
| 13729 | |||
| 13730 | sub resetTriggers { | ||
| 13731 | |||
| 13732 | # Called by $self->doStage at task stage 2, to create all the trigger interfaces used by | ||
| 13733 | # this task | ||
| 13734 | # | ||
| 13735 | # Expected arguments | ||
| 13736 | # (none besides $self) | ||
| 13737 | # | ||
| 13738 | # Return values | ||
| 13739 | # 'undef' on improper arguments | ||
| 13740 | # 1 otherwise | ||
| 13741 | |||
| 13742 | my ($self, $check) = @_; | ||
| 13743 | |||
| 13744 | # Local variables | ||
| 13745 | my @list; | ||
| 13746 | |||
| 13747 | # Check for improper arguments | ||
| 13748 | if (defined $check) { | ||
| 13749 | |||
| 13750 | return $axmud::CLIENT->writeImproper($self->_objClass . '->resetTriggers', @_); | ||
| 13751 | } | ||
| 13752 | |||
| 13753 | # The world profile stores characteristic patterns which mark text as showing the condition | ||
| 13754 | # of an object ('It is in excellent condition', etc) | ||
| 13755 | # It also stores patterns which should be ignored; we'll create triggers for those first, | ||
| 13756 | # so that the ignorable patterns get checked before the usable patterns | ||
| 13757 | |||
| 13758 | # Set up triggers for ignorable patterns | ||
| 13759 | OUTER: foreach my $pattern ($self->session->currentWorld->conditionIgnorePatternList) { | ||
| 13760 | |||
| 13761 | my $interfaceObj = $self->session->createDependentInterface( | ||
| 13762 | 'trigger', | ||
| 13763 | $pattern, | ||
| 13764 | $self, | ||
| 13765 | 'ignorePatternSeen', | ||
| 13766 | 'gag', | ||
| 13767 | 1, | ||
| 13768 | ); | ||
| 13769 | |||
| 13770 | if (! $interfaceObj) { | ||
| 13771 | |||
| 13772 | $self->writeWarning( | ||
| 13773 | 'Couldn\'t create trigger for current world profile\'s' | ||
| 13774 | . ' ->conditionIgnorePatternList IV', | ||
| 13775 | $self->_objClass . '->resetTriggers', | ||
| 13776 | ); | ||
| 13777 | |||
| 13778 | last OUTER; | ||
| 13779 | |||
| 13780 | } else { | ||
| 13781 | |||
| 13782 | # Store the trigger | ||
| 13783 | $self->ivPush('ignoreTriggerList', $interfaceObj); | ||
| 13784 | } | ||
| 13785 | } | ||
| 13786 | |||
| 13787 | # Set up triggers for usable patterns | ||
| 13788 | @list = $self->session->currentWorld->conditionPatternList; | ||
| 13789 | OUTER: while (@list) { | ||
| 13790 | |||
| 13791 | my ($pattern, $grpNum, $gag, $condition, $interfaceObj, $flag); | ||
| 13792 | |||
| 13793 | # The pattern to match | ||
| 13794 | $pattern = shift @list; | ||
| 13795 | # Which group substring contains the data we need | ||
| 13796 | $grpNum = shift @list; | ||
| 13797 | # 'hide' to use a gag trigger, 'show' to use a non-gag trigger | ||
| 13798 | $gag = shift @list; | ||
| 13799 | # The corresponding condition in the range 0-100 | ||
| 13800 | $condition = shift @list; | ||
| 13801 | |||
| 13802 | # Check that @list doesn't contain missing or extra arguments | ||
| 13803 | if ( | ||
| 13804 | ! defined $condition | ||
| 13805 | || ($gag ne 'show' && $gag ne 'hide') | ||
| 13806 | ) { | ||
| 13807 | $self->writeWarning( | ||
| 13808 | 'Missing or invalid arguments in current world profile\'s' | ||
| 13809 | . ' ->conditionPatternList IV', | ||
| 13810 | $self->_objClass . '->resetTriggers', | ||
| 13811 | ); | ||
| 13812 | |||
| 13813 | last OUTER; | ||
| 13814 | } | ||
| 13815 | |||
| 13816 | if ($gag eq 'show') { | ||
| 13817 | $flag = FALSE; | ||
| 13818 | } elsif ($gag eq 'hide') { | ||
| 13819 | $flag = TRUE; | ||
| 13820 | } | ||
| 13821 | |||
| 13822 | # Create the dependent trigger interface | ||
| 13823 | $interfaceObj = $self->session->createDependentInterface( | ||
| 13824 | 'trigger', | ||
| 13825 | $pattern, | ||
| 13826 | $self, | ||
| 13827 | 'triggerSeen', | ||
| 13828 | 'gag', | ||
| 13829 | $flag, | ||
| 13830 | ); | ||
| 13831 | |||
| 13832 | if (! $interfaceObj) { | ||
| 13833 | |||
| 13834 | $self->writeWarning( | ||
| 13835 | 'Couldn\'t create trigger for current world profile\'s' | ||
| 13836 | . ' ->conditionPatternList IV', | ||
| 13837 | $self->_objClass . '->resetTriggers', | ||
| 13838 | ); | ||
| 13839 | |||
| 13840 | last OUTER; | ||
| 13841 | |||
| 13842 | } else { | ||
| 13843 | |||
| 13844 | # Store the trigger | ||
| 13845 | $self->ivPush('triggerList', $interfaceObj); | ||
| 13846 | |||
| 13847 | # Give the trigger some properties that will help $self->triggerSeen to decide | ||
| 13848 | # what to do when the trigger fires | ||
| 13849 | $interfaceObj->ivAdd('propertyHash', 'grp_num', $grpNum); | ||
| 13850 | $interfaceObj->ivAdd('propertyHash', 'condition', $condition); | ||
| 13851 | } | ||
| 13852 | } | ||
| 13853 | |||
| 13854 | # Reset complete | ||
| 13855 | return 1; | ||
| 13856 | } | ||
| 13857 | |||
| 13858 | sub endCheck { | ||
| 13859 | |||
| 13860 | # Can be called by anything, but mainly called by $self->doStage, stage 3 | ||
| 13861 | # Ends the task's current check cycle, if one is in progress | ||
| 13862 | # | ||
| 13863 | # Expected arguments | ||
| 13864 | # (none besides $self) | ||
| 13865 | # | ||
| 13866 | # Optional arguments | ||
| 13867 | # $ignoreCheckFlag - If set to TRUE, no more inventory checks are run until the flag | ||
| 13868 | # is set back to FALSE | ||
| 13869 | # | ||
| 13870 | # Return values | ||
| 13871 | # 'undef' on improper arguments or if the task is shutting down now | ||
| 13872 | # 1 otherwise | ||
| 13873 | |||
| 13874 | my ($self, $ignoreCheckFlag, $check) = @_; | ||
| 13875 | |||
| 13876 | # Check for improper arguments | ||
| 13877 | if (defined $check) { | ||
| 13878 | |||
| 13879 | return $axmud::CLIENT->writeImproper($self->_objClass . '->endCheck', @_); | ||
| 13880 | } | ||
| 13881 | |||
| 13882 | # If called by something other than $self->doStage, and we're in the middle of a check, stop | ||
| 13883 | # checking | ||
| 13884 | if ($self->inventoryList) { | ||
| 13885 | |||
| 13886 | $self->ivEmpty('inventoryList'); | ||
| 13887 | } | ||
| 13888 | |||
| 13889 | # Stop doing inventory checks, if the flag is set | ||
| 13890 | if ($ignoreCheckFlag) { | ||
| 13891 | |||
| 13892 | $self->ivPoke('ignoreCheckFlag', TRUE); | ||
| 13893 | } | ||
| 13894 | |||
| 13895 | # If only one check is allowed, end the task | ||
| 13896 | if ($self->checkOnceFlag) { | ||
| 13897 | |||
| 13898 | # Task complete | ||
| 13899 | $self->ivPoke('shutdownFlag', TRUE); | ||
| 13900 | return undef; | ||
| 13901 | |||
| 13902 | } else { | ||
| 13903 | |||
| 13904 | # Set the time at which the next check occurs | ||
| 13905 | $self->ivPoke( | ||
| 13906 | 'nextCheckTime', | ||
| 13907 | ($self->session->sessionTime + $self->waitTime), | ||
| 13908 | ); | ||
| 13909 | |||
| 13910 | # Wait until the time is up | ||
| 13911 | return $self->ivPoke('stage', 3); | ||
| 13912 | } | ||
| 13913 | } | ||
| 13914 | |||
| 13915 | ################## | ||
| 13916 | # Response methods | ||
| 13917 | |||
| 13918 | sub triggerSeen { | ||
| 13919 | |||
| 13920 | # Called by GA::Session->checkTriggers | ||
| 13921 | # | ||
| 13922 | # This task's ->resetTriggers function creates some triggers to capture condition patterns | ||
| 13923 | # e.g. 'The (.*) is in perfect condition' | ||
| 13924 | # | ||
| 13925 | # The world profile's condition pattern list occurs in groups of 4 elements, representing | ||
| 13926 | # [0] - the pattern to match | ||
| 13927 | # [1] - which group substring contains the object (set to 0 if no part of the string is | ||
| 13928 | # guaranteed to contain the object) | ||
| 13929 | # [2] - 'hide' to use a gag trigger, 'show' to use a non-gag trigger | ||
| 13930 | # [3] - the corresponding condition in the range 0-100 | ||
| 13931 | # | ||
| 13932 | # The trigger interfaces have the following properties in ->propertyHash: | ||
| 13933 | # grp_num - which group substring contains the data we need (same as [1]) | ||
| 13934 | # condition - the corresponding condition (same as [3]) | ||
| 13935 | # | ||
| 13936 | # This function analyses the matched string and updates IVs accordingly | ||
| 13937 | # | ||
| 13938 | # Expected arguments (standard args from GA::Session->checkTriggers) | ||
| 13939 | # $session - The calling function's GA::Session | ||
| 13940 | # $interfaceNum - The number of the active trigger interface that fired | ||
| 13941 | # $line - The line of text received from the world | ||
| 13942 | # $stripLine - $line, with all escape sequences removed | ||
| 13943 | # $modLine - $stripLine, possibly modified by previously-checked triggers | ||
| 13944 | # $grpStringListRef | ||
| 13945 | # - Reference to a list of group substrings from the pattern match | ||
| 13946 | # (equivalent of @_) | ||
| 13947 | # $matchMinusListRef | ||
| 13948 | # - Reference to a list of matched substring offsets (equivalent of @-) | ||
| 13949 | # $matchPlusListRef | ||
| 13950 | # - Reference to a list of matched substring offsets (equivalent of @+) | ||
| 13951 | # | ||
| 13952 | # Return values | ||
| 13953 | # 'undef' on improper arguments, or if $session is the wrong session, if the interface | ||
| 13954 | # object can't be found or if the line seems to refer to a different object than the | ||
| 13955 | # one we're checking (stored in $self->currentObj) | ||
| 13956 | # 1 otherwise | ||
| 13957 | |||
| 13958 | my ( | ||
| 13959 | $self, $session, $interfaceNum, $line, $stripLine, $modLine, $grpStringListRef, | ||
| 13960 | $matchMinusListRef, $matchPlusListRef, $check, | ||
| 13961 | ) = @_; | ||
| 13962 | |||
| 13963 | # Local variables | ||
| 13964 | my ( | ||
| 13965 | $obj, $grpNum, $condition, $worldModelObj, $invTaskObj, $objString, | ||
| 13966 | @objList, @newList, | ||
| 13967 | ); | ||
| 13968 | |||
| 13969 | # Check for improper arguments | ||
| 13970 | if ( | ||
| 13971 | ! defined $session || ! defined $interfaceNum || ! defined $line || ! defined $stripLine | ||
| 13972 | || ! defined $modLine || ! defined $grpStringListRef || ! defined $matchMinusListRef | ||
| 13973 | || ! defined $matchPlusListRef || defined $check | ||
| 13974 | ) { | ||
| 13975 | return $axmud::CLIENT->writeImproper($self->_objClass . '->triggerSeen', @_); | ||
| 13976 | } | ||
| 13977 | |||
| 13978 | # Basic check - the trigger should belong to the right session | ||
| 13979 | if ($session ne $self->session) { | ||
| 13980 | |||
| 13981 | return undef; | ||
| 13982 | } | ||
| 13983 | |||
| 13984 | # Get the interface object itself | ||
| 13985 | $obj = $session->ivShow('interfaceNumHash', $interfaceNum); | ||
| 13986 | if (! $obj) { | ||
| 13987 | |||
| 13988 | return undef; | ||
| 13989 | } | ||
| 13990 | |||
| 13991 | # Respond to the fired trigger | ||
| 13992 | |||
| 13993 | # Import the trigger's properties | ||
| 13994 | $grpNum = $obj->ivShow('propertyHash', 'grp_num'); | ||
| 13995 | $condition = $obj->ivShow('propertyHash', 'condition'); | ||
| 13996 | |||
| 13997 | # Import the model object and inventory task | ||
| 13998 | $worldModelObj = $self->session->worldModelObj; | ||
| 13999 | $invTaskObj = $self->session->inventoryTask; | ||
| 14000 | |||
| 14001 | # Do nothing unless this task is in 'active' mode, there's a condition check in progress | ||
| 14002 | # and the Inventory task is still in 'active' mode | ||
| 14003 | if ($self->activeFlag && $self->currentObject && $invTaskObj && $invTaskObj->activeFlag) { | ||
| 14004 | |||
| 14005 | # If $grpNum is not 0, the line contains the object itself (e.g. 'The metal axe is in an | ||
| 14006 | # excellent condition'), so we can check whether it matches $self->currentObj | ||
| 14007 | # If $grpNum is 0, then no part of the line contains the actual object (e.g. 'It is in | ||
| 14008 | # an excellent condition'), so we must just assume that the condition refers to | ||
| 14009 | # $self->currentObj | ||
| 14010 | if ($grpNum) { | ||
| 14011 | |||
| 14012 | # $objectString is set to a string like 'a metal axe' | ||
| 14013 | $objString = $$grpStringListRef[$grpNum]; | ||
| 14014 | # Remove unnecessary whitespace from $objectString, if it was defined (an object | ||
| 14015 | # string might not be needed at this world) | ||
| 14016 | if ($objString) { | ||
| 14017 | |||
| 14018 | $objString = $axmud::CLIENT->trimWhitespace($objString); | ||
| 14019 | } | ||
| 14020 | |||
| 14021 | # Convert the string into a list of blessed references to non-model objects | ||
| 14022 | # (the list should contain one item, but if it contains none, assume that it's | ||
| 14023 | # the right object anyway) | ||
| 14024 | @objList = $worldModelObj->parseObj($self->session, FALSE, $objString); | ||
| 14025 | if (@objList) { | ||
| 14026 | |||
| 14027 | # See whether the first object in the list corresponds to $self->currentObject | ||
| 14028 | if (! $self->objCompare($self->sensitivity, $self->currentObj, $objList[0])) { | ||
| 14029 | |||
| 14030 | # The line that caused the trigger to fire describes an object that doesn't | ||
| 14031 | # match the one for which we're looking | ||
| 14032 | return undef; | ||
| 14033 | } | ||
| 14034 | } | ||
| 14035 | } | ||
| 14036 | |||
| 14037 | # Now, we have a problem. If, halfway through checking the condition of objects in the | ||
| 14038 | # inventory, the Inventory task updates its list, $self->currentObj will no longer | ||
| 14039 | # be in that task's list, ->inventoryList | ||
| 14040 | # As a result, although this task will continue checking conditions, those conditions | ||
| 14041 | # will be assigned to objects in the Inventory task's old list, now stored in | ||
| 14042 | # ->previousList (which has been copied into this task's ->previousList) | ||
| 14043 | # If $self->currentObj exists in $self->previousList, we need to find the equivalent | ||
| 14044 | # object in the Inventory task's current ->inventoryList | ||
| 14045 | if ( | ||
| 14046 | $self->previousList | ||
| 14047 | && defined $self->ivFind('previousList', $self->currentObj) | ||
| 14048 | ) { | ||
| 14049 | # Find the equivalent object in the Inventory task's updated ->inventoryList | ||
| 14050 | @newList = $invTaskObj->inventoryList; | ||
| 14051 | OUTER: foreach my $newObj (@newList) { | ||
| 14052 | |||
| 14053 | if ( | ||
| 14054 | $worldModelObj->objCompare($self->sensitivity, $self->currentObj, $newObj) | ||
| 14055 | ) { | ||
| 14056 | # If $newObj->condition has already been set, we need to check whether it | ||
| 14057 | # was set by this function (in which case there are probably duplicate | ||
| 14058 | # objects in the character's inventory), or whether it was copied by the | ||
| 14059 | # Inventory task's ->triggerSeen (in which case we overwrite it with the | ||
| 14060 | # new value). | ||
| 14061 | # If it was set by this function, $newObj->conditionChangeFlag is set to | ||
| 14062 | # TRUE | ||
| 14063 | if (! $newObj->conditionChangeFlag) { | ||
| 14064 | |||
| 14065 | $newObj->ivPoke('condition', $condition); | ||
| 14066 | $newObj->ivPoke('conditionChangeFlag', TRUE); | ||
| 14067 | } | ||
| 14068 | |||
| 14069 | last OUTER; | ||
| 14070 | } | ||
| 14071 | } | ||
| 14072 | |||
| 14073 | } else { | ||
| 14074 | |||
| 14075 | # The Inventory task's list hasn't been updated yet, so set the object's condition | ||
| 14076 | # directly | ||
| 14077 | $self->currentObj->ivPoke('condition', $condition); | ||
| 14078 | $self->currentObj->ivPoke('conditionChangeFlag', TRUE); | ||
| 14079 | } | ||
| 14080 | |||
| 14081 | # Mark the current object as 'undef', so that the next object in the inventory list can | ||
| 14082 | # be checked (by $self->doStage) | ||
| 14083 | $self->ivPoke('currentObj', undef); | ||
| 14084 | |||
| 14085 | # Tell the Inventory task to refresh its task window | ||
| 14086 | $invTaskObj->set_refreshWinFlag(TRUE); | ||
| 14087 | } | ||
| 14088 | |||
| 14089 | return 1; | ||
| 14090 | } | ||
| 14091 | |||
| 14092 | sub ignorePatternSeen { | ||
| 14093 | |||
| 14094 | # Called by GA::Session->checkTriggers | ||
| 14095 | # | ||
| 14096 | # This task's ->resetTriggers function creates some triggers to capture condition patterns | ||
| 14097 | # which contain an object's condition (e.g. 'It is in excellent condition') and a second | ||
| 14098 | # set of patterns which contain no useful information (e.g. 'You consider the axe's | ||
| 14099 | # condition') and which can be ignored | ||
| 14100 | # | ||
| 14101 | # The function does nothing (a commented-out call to ->writeDebug is provided, in case it | ||
| 14102 | # will be useful) | ||
| 14103 | # | ||
| 14104 | # Expected arguments (standard args from GA::Session->checkTriggers) | ||
| 14105 | # $session - The calling function's GA::Session | ||
| 14106 | # $interfaceNum - The number of the active trigger interface that fired | ||
| 14107 | # $line - The line of text received from the world | ||
| 14108 | # $stripLine - $line, with all escape sequences removed | ||
| 14109 | # $modLine - $stripLine, possibly modified by previously-checked triggers | ||
| 14110 | # $grpStringListRef | ||
| 14111 | # - Reference to a list of group substrings from the pattern match | ||
| 14112 | # (equivalent of @_) | ||
| 14113 | # $matchMinusListRef | ||
| 14114 | # - Reference to a list of matched substring offsets (equivalent of @-) | ||
| 14115 | # $matchPlusListRef | ||
| 14116 | # - Reference to a list of matched substring offsets (equivalent of @+) | ||
| 14117 | # | ||
| 14118 | # Return values | ||
| 14119 | # 'undef' on improper arguments, or if $session is the wrong session or if the interface | ||
| 14120 | # object can't be found | ||
| 14121 | # 1 otherwise | ||
| 14122 | |||
| 14123 | my ( | ||
| 14124 | $self, $session, $interfaceNum, $line, $stripLine, $modLine, $grpStringListRef, | ||
| 14125 | $matchMinusListRef, $matchPlusListRef, $check, | ||
| 14126 | ) = @_; | ||
| 14127 | |||
| 14128 | # Local variables | ||
| 14129 | my $obj; | ||
| 14130 | |||
| 14131 | # Check for improper arguments | ||
| 14132 | if ( | ||
| 14133 | ! defined $session || ! defined $interfaceNum || ! defined $line || ! defined $stripLine | ||
| 14134 | || ! defined $modLine || ! defined $grpStringListRef || ! defined $matchMinusListRef | ||
| 14135 | || ! defined $matchPlusListRef || defined $check | ||
| 14136 | ) { | ||
| 14137 | return $axmud::CLIENT->writeImproper( | ||
| 14138 | $self->_objClass . '->ignorePatternSeen', | ||
| 14139 | @_, | ||
| 14140 | ); | ||
| 14141 | } | ||
| 14142 | |||
| 14143 | # Basic check - the trigger should belong to the right session | ||
| 14144 | if ($session ne $self->session) { | ||
| 14145 | |||
| 14146 | return undef; | ||
| 14147 | } | ||
| 14148 | |||
| 14149 | # Get the interface object itself | ||
| 14150 | $obj = $session->ivShow('interfaceNumHash', $interfaceNum); | ||
| 14151 | if (! $obj) { | ||
| 14152 | |||
| 14153 | return undef; | ||
| 14154 | } | ||
| 14155 | |||
| 14156 | # Respond to the fired trigger | ||
| 14157 | |||
| 14158 | # $self->writeDebug('Condition task ignore pattern found: \'' . $$grpStringListRef[0] . '\''); | ||
| 14159 | |||
| 14160 | return 1; | ||
| 14161 | } | ||
| 14162 | |||
| 14163 | ################## | ||
| 14164 | # Accessors - set | ||
| 14165 | |||
| 14166 | sub set_ignoreCheckFlag { | ||
| 14167 | |||
| 14168 | my ($self, $flag, $check) = @_; | ||
| 14169 | |||
| 14170 | # Check for improper arguments | ||
| 14171 | if (! defined $flag || defined $check) { | ||
| 14172 | |||
| 14173 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_ignoreCheckFlag', @_); | ||
| 14174 | } | ||
| 14175 | |||
| 14176 | if ($flag) { | ||
| 14177 | $self->ivPoke('ignoreCheckFlag', TRUE); | ||
| 14178 | } else { | ||
| 14179 | $self->ivPoke('ignoreCheckFlag', FALSE); | ||
| 14180 | } | ||
| 14181 | |||
| 14182 | return 1; | ||
| 14183 | } | ||
| 14184 | |||
| 14185 | sub set_previousList { | ||
| 14186 | |||
| 14187 | my ($self, @previousList) = @_; | ||
| 14188 | |||
| 14189 | # (No improper arguments to check) | ||
| 14190 | |||
| 14191 | $self->ivPoke('previousList', @previousList); # @previousList can be empty | ||
| 14192 | |||
| 14193 | return 1; | ||
| 14194 | } | ||
| 14195 | |||
| 14196 | ################## | ||
| 14197 | # Accessors - task settings - get | ||
| 14198 | |||
| 14199 | # The accessors for task settings are inherited from the generic task | ||
| 14200 | |||
| 14201 | ################## | ||
| 14202 | # Accessors - task parameters - get | ||
| 14203 | |||
| 14204 | sub triggerList | ||
| 14205 | { my $self = shift; return @{$self->{triggerList}}; } | ||
| 14206 | sub ignoreTriggerList | ||
| 14207 | { my $self = shift; return @{$self->{ignoreTriggerList}}; } | ||
| 14208 | |||
| 14209 | sub checkOnceFlag | ||
| 14210 | { $_[0]->{checkOnceFlag} } | ||
| 14211 | sub inventoryList | ||
| 14212 | { my $self = shift; return @{$self->{inventoryList}}; } | ||
| 14213 | sub previousList | ||
| 14214 | { my $self = shift; return @{$self->{previousList}}; } | ||
| 14215 | sub currentObj | ||
| 14216 | { $_[0]->{currentObj} } | ||
| 14217 | sub sensitivity | ||
| 14218 | { $_[0]->{sensitivity} } | ||
| 14219 | |||
| 14220 | sub firstCheckTime | ||
| 14221 | { $_[0]->{firstCheckTime} } | ||
| 14222 | sub waitTime | ||
| 14223 | { $_[0]->{waitTime} } | ||
| 14224 | sub nextCheckTime | ||
| 14225 | { $_[0]->{nextCheckTime} } | ||
| 14226 | sub ignoreCheckFlag | ||
| 14227 | { $_[0]->{ignoreCheckFlag} } | ||
| 14228 | |||
| 14229 | sub maxObjTime | ||
| 14230 | { $_[0]->{maxObjTime} } | ||
| 14231 | sub nextObjTime | ||
| 14232 | { $_[0]->{nextObjTime} } | ||
| 14233 | } | ||
| 14234 | |||
| 14235 | { package Games::Axmud::Task::Connections; | ||
| 14236 | |||
| 14237 | use strict; | ||
| 14238 | use warnings; | ||
| 14239 | # use diagnostics; | ||
| 14240 | |||
| 14241 | use Glib qw(TRUE FALSE); | ||
| 14242 | |||
| 14243 | our @ISA = qw(Games::Axmud::Generic::Task Games::Axmud); | ||
| 14244 | |||
| 14245 | ################## | ||
| 14246 | # Constructors | ||
| 14247 | |||
| 14248 | sub new { | ||
| 14249 | |||
| 14250 | # Creates a new instance of the Connections task | ||
| 14251 | # | ||
| 14252 | # Expected arguments | ||
| 14253 | # $session - The parent GA::Session (not stored as an IV) | ||
| 14254 | # | ||
| 14255 | # Optional arguments | ||
| 14256 | # $taskType - Which tasklist this task is being created into - 'current' for the current | ||
| 14257 | # tasklist (tasks which are actually running now), 'initial' (tasks which | ||
| 14258 | # should be run when the user connects to the world), 'custom' (tasks with | ||
| 14259 | # customised initial parameters, which are run when the user demands). If | ||
| 14260 | # set to 'undef', this is a temporary task, created in order to access the | ||
| 14261 | # default values stored in IVs, that will not be added to any tasklist | ||
| 14262 | # $profName - ($taskType = 'current', when called by $self->clone) Name of the | ||
| 14263 | # profile from whose initial tasklist this task was created ('undef' if | ||
| 14264 | # none) | ||
| 14265 | # - ($taskType = 'initial') name of the profile in whose initial tasklist this | ||
| 14266 | # task will be. If 'undef', the global initial tasklist is used | ||
| 14267 | # - ($taskType = 'custom') 'undef' | ||
| 14268 | # $profCategory | ||
| 14269 | # - ($taskType = 'current', 'initial') which category the profile falls undef | ||
| 14270 | # (i.e. 'world', 'race', 'char', etc, or 'undef' if no profile) | ||
| 14271 | # - ($taskType = 'custom') 'undef' | ||
| 14272 | # $customName | ||
| 14273 | # - ($taskType = 'current', 'initial') 'undef' | ||
| 14274 | # - ($taskType = 'custom') the custom task name, matching a key in | ||
| 14275 | # GA::Session->customTaskHash | ||
| 14276 | # | ||
| 14277 | # Return values | ||
| 14278 | # 'undef' on improper arguments or if the task can't be added to the specified tasklist | ||
| 14279 | # Blessed reference to the newly-created object on success | ||
| 14280 | |||
| 14281 | my ($class, $session, $taskType, $profName, $profCategory, $customName, $check) = @_; | ||
| 14282 | |||
| 14283 | # Check for improper arguments | ||
| 14284 | if (! defined $class || ! defined $session || defined $check) { | ||
| 14285 | |||
| 14286 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 14287 | } | ||
| 14288 | |||
| 14289 | if ($taskType) { | ||
| 14290 | |||
| 14291 | # For initial tasks, check that $profName exists | ||
| 14292 | if ( | ||
| 14293 | $taskType eq 'initial' | ||
| 14294 | && defined $profName | ||
| 14295 | && ! $session->ivExists('profHash', $profName) | ||
| 14296 | ) { | ||
| 14297 | return $session->writeError( | ||
| 14298 | 'Can\'t create new task because \'' . $profName . '\' profile doesn\'t exist', | ||
| 14299 | $class . '->new', | ||
| 14300 | ); | ||
| 14301 | |||
| 14302 | # For custom tasks, check that $customName doesn't already exist | ||
| 14303 | } elsif ( | ||
| 14304 | $taskType eq 'custom' | ||
| 14305 | && $axmud::CLIENT->ivExists('customTaskHash', $customName) | ||
| 14306 | ) { | ||
| 14307 | return $session->writeError( | ||
| 14308 | 'Can\'t create new custom task because \'' . $customName . '\' is already being' | ||
| 14309 | . ' used', | ||
| 14310 | $class . '->new', | ||
| 14311 | ); | ||
| 14312 | |||
| 14313 | } elsif ($taskType ne 'current' && $taskType ne 'initial' && $taskType ne 'custom') { | ||
| 14314 | |||
| 14315 | return $session->writeError( | ||
| 14316 | 'Can\'t create new task because \'' . $taskType . '\' is an invalid tasklist', | ||
| 14317 | $class . '->new', | ||
| 14318 | ); | ||
| 14319 | } | ||
| 14320 | } | ||
| 14321 | |||
| 14322 | # Task settings | ||
| 14323 | my $self = Games::Axmud::Generic::Task->new( | ||
| 14324 | $session, | ||
| 14325 | $taskType, | ||
| 14326 | $profName, | ||
| 14327 | $profCategory, | ||
| 14328 | $customName, | ||
| 14329 | ); | ||
| 14330 | |||
| 14331 | $self->{_objName} = 'connections_task'; | ||
| 14332 | $self->{_objClass} = $class; | ||
| 14333 | $self->{_parentFile} = undef; # Set below | ||
| 14334 | $self->{_parentWorld} = undef; # Set below | ||
| 14335 | $self->{_privFlag} = TRUE, # All IVs are private | ||
| 14336 | |||
| 14337 | $self->{name} = 'connections_task'; | ||
| 14338 | $self->{prettyName} = 'Connections'; | ||
| 14339 | $self->{shortName} = 'Co'; | ||
| 14340 | $self->{shortCutIV} = 'connectionsTask'; # Axmud built-in jealous task | ||
| 14341 | |||
| 14342 | $self->{category} = 'process'; | ||
| 14343 | $self->{descrip} = 'Display a constantly-updated list of connections'; | ||
| 14344 | $self->{jealousyFlag} = TRUE; | ||
| 14345 | $self->{requireLocatorFlag} = FALSE; | ||
| 14346 | $self->{profSensitivityFlag} = FALSE; | ||
| 14347 | $self->{storableFlag} = TRUE; | ||
| 14348 | $self->{delayTime} = 0.2; | ||
| 14349 | $self->{allowWinFlag} = TRUE; | ||
| 14350 | $self->{requireWinFlag} = FALSE; | ||
| 14351 | $self->{startWithWinFlag} = TRUE; | ||
| 14352 | $self->{winPreferList} = ['pane', 'grid']; | ||
| 14353 | $self->{winmap} = 'basic_fill'; | ||
| 14354 | $self->{winUpdateFunc} = undef; | ||
| 14355 | $self->{tabMode} = 'simple'; | ||
| 14356 | $self->{monochromeFlag} = FALSE; | ||
| 14357 | $self->{noScrollFlag} = TRUE; | ||
| 14358 | $self->{ttsFlag} = FALSE; | ||
| 14359 | $self->{ttsConfig} = undef; | ||
| 14360 | $self->{ttsAttribHash} = {}; | ||
| 14361 | $self->{ttsFlagAttribHash} = {}; | ||
| 14362 | $self->{ttsAlertAttribHash} = {}; | ||
| 14363 | $self->{status} = 'wait_init'; | ||
| 14364 | # $self->{activeFlag} = TRUE; # Task can't be activated/disactivated | ||
| 14365 | |||
| 14366 | # Task parameters | ||
| 14367 | # Flag set to TRUE if the connection/idle times for each session should be shown, FALSE if | ||
| 14368 | # not | ||
| 14369 | $self->{showInfoFlag} = FALSE; | ||
| 14370 | # This task creates macros to intercept CTRL+1, CTRL+2 ... CTRL+9 (or an equivalent set of | ||
| 14371 | # keypresses). If this flag is TRUE, the macros are created enabled; if FALSE, they are | ||
| 14372 | # created disabled | ||
| 14373 | $self->{useMacrosFlag} = TRUE; | ||
| 14374 | # Which set of keypresses to use: | ||
| 14375 | # 'default' - CTRL+1, CTRL+2 ... CTRL+9 | ||
| 14376 | # 'simple' - F1, F2 ... F9 | ||
| 14377 | $self->{macroMode} = 'default'; | ||
| 14378 | # A list of macros created | ||
| 14379 | $self->{macroList} = []; | ||
| 14380 | |||
| 14381 | # Bless task | ||
| 14382 | bless $self, $class; | ||
| 14383 | |||
| 14384 | # For all tasks that aren't temporary... | ||
| 14385 | if ($taskType) { | ||
| 14386 | |||
| 14387 | # Check that the task doesn't belong to a disabled plugin (in which case, it can't be | ||
| 14388 | # added to any current, initial or custom tasklist) | ||
| 14389 | if (! $self->checkPlugins()) { | ||
| 14390 | |||
| 14391 | return undef; | ||
| 14392 | } | ||
| 14393 | |||
| 14394 | # Set the parent file object | ||
| 14395 | $self->setParentFileObj($session, $taskType, $profName, $profCategory); | ||
| 14396 | |||
| 14397 | # Create entries in tasklists, if possible | ||
| 14398 | if (! $self->updateTaskLists($session)) { | ||
| 14399 | |||
| 14400 | return undef; | ||
| 14401 | } | ||
| 14402 | } | ||
| 14403 | |||
| 14404 | # Task creation complete | ||
| 14405 | return $self; | ||
| 14406 | } | ||
| 14407 | |||
| 14408 | sub clone { | ||
| 14409 | |||
| 14410 | # Create a clone of an existing task | ||
| 14411 | # Usually used upon connection to a world, when every task in the initial tasklists must | ||
| 14412 | # be cloned into a new object, representing a task in the current tasklist | ||
| 14413 | # (Also used when cloning a profile object, since all the tasks in its initial tasklist must | ||
| 14414 | # also be cloned) | ||
| 14415 | # | ||
| 14416 | # Expected arguments | ||
| 14417 | # $session - The parent GA::Session (not stored as an IV) | ||
| 14418 | # $taskType - Which tasklist this task is being created into - 'current' for the current | ||
| 14419 | # tasklist (tasks which are actually running now), 'initial' (tasks which | ||
| 14420 | # should be run when the user connects to the world). Custom tasks aren't | ||
| 14421 | # cloned (at the moment) | ||
| 14422 | # | ||
| 14423 | # Optional arguments | ||
| 14424 | # $profName - ($taskType = 'initial') name of the profile in whose initial tasklist the | ||
| 14425 | # existing task is stored | ||
| 14426 | # $profCategory | ||
| 14427 | # - ($taskType = 'initial') which category the profile falls under (i.e. | ||
| 14428 | # 'world', 'race', 'char', etc) | ||
| 14429 | # | ||
| 14430 | # Return values | ||
| 14431 | # 'undef' on improper arguments or if the task can't be cloned | ||
| 14432 | # Blessed reference to the newly-created object on success | ||
| 14433 | |||
| 14434 | my ($self, $session, $taskType, $profName, $profCategory, $check) = @_; | ||
| 14435 | |||
| 14436 | # Check for improper arguments | ||
| 14437 | if ( | ||
| 14438 | ! defined $session || ! defined $taskType || defined $check | ||
| 14439 | || ($taskType ne 'current' && $taskType ne 'initial') | ||
| 14440 | || ($taskType eq 'initial' && (! defined $profName || ! defined $profCategory)) | ||
| 14441 | ) { | ||
| 14442 | return $axmud::CLIENT->writeImproper($self->_objClass . '->clone', @_); | ||
| 14443 | } | ||
| 14444 | |||
| 14445 | # For initial tasks, check that $profName exists | ||
| 14446 | if ( | ||
| 14447 | $taskType eq 'initial' | ||
| 14448 | && defined $profName | ||
| 14449 | && ! $session->ivExists('profHash', $profName) | ||
| 14450 | ) { | ||
| 14451 | return $axmud::CLIENT->writeError( | ||
| 14452 | 'Can\'t create cloned task because \'' . $profName . '\' profile doesn\'t exist', | ||
| 14453 | $self->_objClass . '->clone', | ||
| 14454 | ); | ||
| 14455 | } | ||
| 14456 | |||
| 14457 | # Check that the task doesn't belong to a disabled plugin (in which case, it can't be | ||
| 14458 | # cloned) | ||
| 14459 | if (! $self->checkPlugins()) { | ||
| 14460 | |||
| 14461 | return undef; | ||
| 14462 | } | ||
| 14463 | |||
| 14464 | # Create the new task, using default settings and parameters | ||
| 14465 | my $clone = $self->_objClass->new($session, $taskType, $profName, $profCategory); | ||
| 14466 | |||
| 14467 | # Most of the cloned task's settings have default values, but a few are copied from the | ||
| 14468 | # original | ||
| 14469 | $self->cloneTaskSettings($clone); | ||
| 14470 | |||
| 14471 | # Give the new (cloned) task the same initial parameters as the original one | ||
| 14472 | $clone->{showInfoFlag} = $self->showInfoFlag; | ||
| 14473 | $clone->{useMacrosFlag} = {$self->useMacrosFlag}; | ||
| 14474 | $clone->{macroMode} = {$self->macroMode}; | ||
| 14475 | |||
| 14476 | # Cloning complete | ||
| 14477 | return $clone; | ||
| 14478 | } | ||
| 14479 | |||
| 14480 | sub preserve { | ||
| 14481 | |||
| 14482 | # Called by $self->main whenever this task is reset, in order to preserve some if its task | ||
| 14483 | # parameters (but not necessarily all of them) | ||
| 14484 | # | ||
| 14485 | # Expected arguments | ||
| 14486 | # $newTask - The new task which has been created, to which some of this task's instance | ||
| 14487 | # variables might have to be transferred | ||
| 14488 | # | ||
| 14489 | # Return values | ||
| 14490 | # 'undef' on improper arguments, or if $newTask isn't in the GA::Session's current | ||
| 14491 | # tasklist | ||
| 14492 | # 1 on success | ||
| 14493 | |||
| 14494 | my ($self, $newTask, $check) = @_; | ||
| 14495 | |||
| 14496 | # Check for improper arguments | ||
| 14497 | if (! defined $newTask || defined $check) { | ||
| 14498 | |||
| 14499 | return $axmud::CLIENT->writeImproper($self->_objClass . '->preserve', @_); | ||
| 14500 | } | ||
| 14501 | |||
| 14502 | # Check the task is in the current tasklist | ||
| 14503 | if (! $self->session->ivExists('currentTaskHash', $newTask->uniqueName)) { | ||
| 14504 | |||
| 14505 | return $self->writeWarning( | ||
| 14506 | '\'' . $self->uniqueName . '\' task missing from the current tasklist', | ||
| 14507 | $self->_objClass . '->preserve', | ||
| 14508 | ); | ||
| 14509 | } | ||
| 14510 | |||
| 14511 | # Preserve some task parameters (the others are left with their default settings, some of | ||
| 14512 | # which will be re-initialised in stage 2) | ||
| 14513 | |||
| 14514 | # Preserve the command lists | ||
| 14515 | $newTask->ivPoke('showInfoFlag', $self->showInfoFlag); | ||
| 14516 | $newTask->ivPoke('useMacrosFlag', $self->useMacrosFlag); | ||
| 14517 | $newTask->ivPoke('macroMode', $self->macroMode); | ||
| 14518 | |||
| 14519 | return 1; | ||
| 14520 | } | ||
| 14521 | |||
| 14522 | # sub setParentFileObj {} # Inherited from generic task | ||
| 14523 | |||
| 14524 | # sub updateTaskLists {} # Inherited from generic task | ||
| 14525 | |||
| 14526 | # sub ttsReadAttrib {} # Inherited from generic task | ||
| 14527 | |||
| 14528 | # sub ttsSwitchFlagAttrib {} # Inherited from generic task | ||
| 14529 | |||
| 14530 | # sub ttsSetAlertAttrib {} # Inherited from generic task | ||
| 14531 | |||
| 14532 | ################## | ||
| 14533 | # Task windows | ||
| 14534 | |||
| 14535 | # sub toggleWin {} # Inherited from generic task | ||
| 14536 | |||
| 14537 | # sub openWin {} # Inherited from generic task | ||
| 14538 | |||
| 14539 | # sub closeWin {} # Inherited from generic task | ||
| 14540 | |||
| 14541 | ################## | ||
| 14542 | # Methods | ||
| 14543 | |||
| 14544 | # sub main {} # Inherited from generic task | ||
| 14545 | |||
| 14546 | # sub doShutdown {} # Inherited from generic task | ||
| 14547 | |||
| 14548 | # sub doReset {} # Inherited from generic task | ||
| 14549 | |||
| 14550 | # sub doFirstStage {} # Inherited from generic task | ||
| 14551 | |||
| 14552 | sub doStage { | ||
| 14553 | |||
| 14554 | # Called by $self->main to process all stages (except stage 1) | ||
| 14555 | # | ||
| 14556 | # Expected arguments | ||
| 14557 | # (none besides $self) | ||
| 14558 | # | ||
| 14559 | # Return values | ||
| 14560 | # 'undef' on improper arguments or if this function sets that task's ->status IV to | ||
| 14561 | # 'finished' or sets its ->shutdownFlag to TRUE | ||
| 14562 | # Otherwise, we normally return the new value of $self->stage | ||
| 14563 | |||
| 14564 | my ($self, $check) = @_; | ||
| 14565 | |||
| 14566 | # Check for improper arguments | ||
| 14567 | if (defined $check) { | ||
| 14568 | |||
| 14569 | return $axmud::CLIENT->writeImproper($self->_objClass . '->doStage', @_); | ||
| 14570 | } | ||
| 14571 | |||
| 14572 | if ($self->stage == 2) { | ||
| 14573 | |||
| 14574 | # Create macros to intercept CTRL+1, CTRL+2 ... CTRL+9 | ||
| 14575 | if (! $self->resetMacros()) { | ||
| 14576 | |||
| 14577 | $self->writeError( | ||
| 14578 | 'Could not create macros for the ' . $self->prettyName . ' task, so halting', | ||
| 14579 | $self->_objClass . '->doStage', | ||
| 14580 | ); | ||
| 14581 | |||
| 14582 | # Mark the task to be shutdown | ||
| 14583 | $self->ivPoke('shutdownFlag', TRUE); | ||
| 14584 | return undef; | ||
| 14585 | |||
| 14586 | } else { | ||
| 14587 | |||
| 14588 | return $self->ivPoke('stage', 3); | ||
| 14589 | } | ||
| 14590 | |||
| 14591 | } elsif ($self->stage == 3) { | ||
| 14592 | |||
| 14593 | my ($string, $count); | ||
| 14594 | |||
| 14595 | # On every spin of the task loop, update the task window (if it is open) | ||
| 14596 | if ($self->taskWinFlag) { | ||
| 14597 | |||
| 14598 | # Add the header | ||
| 14599 | if ($axmud::CLIENT->shareMainWinFlag) { | ||
| 14600 | $string = ') (* current, > visible)'; | ||
| 14601 | } else { | ||
| 14602 | $string = ') (* current)'; | ||
| 14603 | } | ||
| 14604 | |||
| 14605 | $self->insertText( | ||
| 14606 | 'CONNECTIONS (Time ' . int($self->session->sessionTime) . $string, | ||
| 14607 | 'empty', | ||
| 14608 | ); | ||
| 14609 | |||
| 14610 | if (! $self->showInfoFlag) { | ||
| 14611 | |||
| 14612 | $self->insertText(' # World Character Status'); | ||
| 14613 | |||
| 14614 | } else { | ||
| 14615 | |||
| 14616 | $self->insertText( | ||
| 14617 | ' # World Character Status Info', | ||
| 14618 | ); | ||
| 14619 | } | ||
| 14620 | |||
| 14621 | # Add the remaining lines, one for each session | ||
| 14622 | $count = 0; | ||
| 14623 | foreach my $otherSession ( | ||
| 14624 | sort {lc($a) cmp lc($b)} ($axmud::CLIENT->ivValues('sessionHash')) | ||
| 14625 | ) { | ||
| 14626 | my ($column, $colour, $char); | ||
| 14627 | |||
| 14628 | $count++; | ||
| 14629 | |||
| 14630 | |||
| 14631 | if ($otherSession eq $self->session) { | ||
| 14632 | $column = '*'; | ||
| 14633 | } else { | ||
| 14634 | $column = ' '; | ||
| 14635 | } | ||
| 14636 | |||
| 14637 | if ( | ||
| 14638 | $axmud::CLIENT->shareMainWinFlag | ||
| 14639 | && $otherSession->mainWin->visibleSession eq $otherSession | ||
| 14640 | ) { | ||
| 14641 | $column .= '> '; | ||
| 14642 | } else { | ||
| 14643 | $column .= ' '; | ||
| 14644 | } | ||
| 14645 | |||
| 14646 | $self->insertText($column . sprintf('%-2.2s ', $count)); | ||
| 14647 | |||
| 14648 | # Use the same colour as the 'main' window tab | ||
| 14649 | if ($otherSession->status eq 'offline') { | ||
| 14650 | $colour = 'magenta'; | ||
| 14651 | } elsif ($otherSession->status eq 'disconnected') { | ||
| 14652 | $colour = 'blue'; | ||
| 14653 | } elsif ($otherSession->showNewTextFlag) { | ||
| 14654 | $colour = 'red'; | ||
| 14655 | } else { | ||
| 14656 | $colour = $self->defaultTabObj->textViewObj->textColour; | ||
| 14657 | } | ||
| 14658 | |||
| 14659 | $self->insertText( | ||
| 14660 | sprintf('%-16.16s ', $otherSession->currentWorld->name), | ||
| 14661 | 'echo', | ||
| 14662 | $colour, | ||
| 14663 | ); | ||
| 14664 | |||
| 14665 | if ($otherSession->currentChar) { | ||
| 14666 | $char = $otherSession->currentChar->name; | ||
| 14667 | } else { | ||
| 14668 | $char = '<none>'; | ||
| 14669 | } | ||
| 14670 | |||
| 14671 | $self->insertText( | ||
| 14672 | sprintf( | ||
| 14673 | '%-16.16s %-12.12s', | ||
| 14674 | $char, | ||
| 14675 | $otherSession->status, | ||
| 14676 | ), | ||
| 14677 | 'echo', | ||
| 14678 | ); | ||
| 14679 | |||
| 14680 | if ($self->showInfoFlag) { | ||
| 14681 | |||
| 14682 | |||
| 14683 | $self->insertText( | ||
| 14684 | ' ' . $otherSession->getTimeLabelText(), | ||
| 14685 | 'echo', | ||
| 14686 | ); | ||
| 14687 | } | ||
| 14688 | } | ||
| 14689 | } | ||
| 14690 | |||
| 14691 | # Repeat this stage indefinitely | ||
| 14692 | return $self->ivPoke('stage', 3); | ||
| 14693 | |||
| 14694 | } else { | ||
| 14695 | |||
| 14696 | # The task stage has somehow been set to an invalid value | ||
| 14697 | return $self->invalidStage(); | ||
| 14698 | } | ||
| 14699 | } | ||
| 14700 | |||
| 14701 | sub resetMacros { | ||
| 14702 | |||
| 14703 | # Called by $self->doStage at stage 2 to set up macros to intercept CTRL+1, CTRL+2 ... | ||
| 14704 | # CTRL+9 (or equivalents) | ||
| 14705 | # | ||
| 14706 | # Expected arguments | ||
| 14707 | # (none) | ||
| 14708 | # | ||
| 14709 | # Return values | ||
| 14710 | # 'undef' on improper arguments | ||
| 14711 | # 1 otherwise | ||
| 14712 | |||
| 14713 | my ($self, $check) = @_; | ||
| 14714 | |||
| 14715 | # Local variables | ||
| 14716 | my @macroList; | ||
| 14717 | |||
| 14718 | # Check for improper arguments | ||
| 14719 | if (defined $check) { | ||
| 14720 | |||
| 14721 | return $axmud::CLIENT->writeImproper($self->_objClass . '->resetMacros', @_); | ||
| 14722 | } | ||
| 14723 | |||
| 14724 | # Create one macro (initially disabled) for each keycode string between 1-9 | ||
| 14725 | for (my $count = 1; $count <= 9; $count++) { | ||
| 14726 | |||
| 14727 | my ($interfaceObj, $keycodeString); | ||
| 14728 | |||
| 14729 | if ($self->macroMode eq 'simple') { | ||
| 14730 | $keycodeString = 'f' . $count; # e.g. 'f1' | ||
| 14731 | } else { | ||
| 14732 | $keycodeString = 'ctrl ' . $count; # e.g. 'ctrl 1'; | ||
| 14733 | } | ||
| 14734 | |||
| 14735 | # Create the dependent macro interface | ||
| 14736 | $interfaceObj = $self->session->createDependentInterface( | ||
| 14737 | 'macro', | ||
| 14738 | $keycodeString, | ||
| 14739 | $self, | ||
| 14740 | 'macroSeen', | ||
| 14741 | 'enabled', | ||
| 14742 | $self->useMacrosFlag, | ||
| 14743 | ); | ||
| 14744 | |||
| 14745 | if (! $interfaceObj) { | ||
| 14746 | |||
| 14747 | # If there's an error creating any macros, remove any macros already created | ||
| 14748 | $self->session->tidyInterfaces($self); | ||
| 14749 | return undef; | ||
| 14750 | |||
| 14751 | } else { | ||
| 14752 | |||
| 14753 | push (@macroList, $interfaceObj); | ||
| 14754 | |||
| 14755 | # Give the trigger some properties that will give $self->macroSeen a number between | ||
| 14756 | # 1-9 (quicker than processing the interface object's IVs) | ||
| 14757 | $interfaceObj->ivAdd('propertyHash', 'number', $count); | ||
| 14758 | } | ||
| 14759 | } | ||
| 14760 | |||
| 14761 | # Update IVs | ||
| 14762 | $self->ivPoke('macroList', @macroList); | ||
| 14763 | |||
| 14764 | return 1; | ||
| 14765 | } | ||
| 14766 | |||
| 14767 | ################## | ||
| 14768 | # Response methods | ||
| 14769 | |||
| 14770 | sub macroSeen { | ||
| 14771 | |||
| 14772 | # Called by GA::Session->checkMacros | ||
| 14773 | # | ||
| 14774 | # This task's ->resetMacros function creates some macros to capture CTRL+1, CTRL+2 ... | ||
| 14775 | # CTRL+9 (or equivalents) | ||
| 14776 | # | ||
| 14777 | # If the number corresponds to a session, that session is made the visible one | ||
| 14778 | # | ||
| 14779 | # The trigger interfaces have the following properties in ->propertyHash: | ||
| 14780 | # number - A number between 1 and 9 | ||
| 14781 | # | ||
| 14782 | # Expected arguments (standard args from GA::Session->checkTriggers) | ||
| 14783 | # $session - The calling function's GA::Session | ||
| 14784 | # $interfaceNum - The number of the active trigger interface that fired | ||
| 14785 | # $keycodeString - The keycode string, e.g. 'ctrl 1' | ||
| 14786 | # | ||
| 14787 | # Return values | ||
| 14788 | # 'undef' on improper arguments, or if $session is the wrong session or if the interface | ||
| 14789 | # object can't be found | ||
| 14790 | # 1 otherwise | ||
| 14791 | |||
| 14792 | my ($self, $session, $interfaceNum, $keycodeString, $check) = @_; | ||
| 14793 | |||
| 14794 | # Local variables | ||
| 14795 | my ( | ||
| 14796 | $obj, $number, $newSession, | ||
| 14797 | @list, | ||
| 14798 | ); | ||
| 14799 | |||
| 14800 | # Check for improper arguments | ||
| 14801 | if ( | ||
| 14802 | ! defined $session || ! defined $interfaceNum || ! defined $keycodeString | ||
| 14803 | || defined $check | ||
| 14804 | ) { | ||
| 14805 | return $axmud::CLIENT->writeImproper($self->_objClass . '->macroSeen', @_); | ||
| 14806 | } | ||
| 14807 | |||
| 14808 | # Basic check - the trigger should belong to the right session | ||
| 14809 | if ($session ne $self->session) { | ||
| 14810 | |||
| 14811 | return undef; | ||
| 14812 | } | ||
| 14813 | |||
| 14814 | # Get the interface object itself | ||
| 14815 | $obj = $session->ivShow('interfaceNumHash', $interfaceNum); | ||
| 14816 | if (! $obj) { | ||
| 14817 | |||
| 14818 | return undef; | ||
| 14819 | } | ||
| 14820 | |||
| 14821 | # Respond to the fired macro | ||
| 14822 | |||
| 14823 | $number = $obj->ivShow('propertyHash', 'number'); | ||
| 14824 | # Find the equivalent GA::Session. $number is a value between 1-9, representing the first | ||
| 14825 | # nine sessions which are still running, in the order they were created | ||
| 14826 | @list = sort {$a->number <=> $b->number} ($axmud::CLIENT->ivValues('sessionHash')); | ||
| 14827 | # If there aren't enough session, $newSession will remain as 'undef' | ||
| 14828 | $newSession = $list[$number - 1]; | ||
| 14829 | if (defined $newSession) { | ||
| 14830 | |||
| 14831 | $newSession->defaultTabObj->paneObj->setVisibleTab($newSession->defaultTabObj); | ||
| 14832 | $newSession->mainWin->restoreFocus(); | ||
| 14833 | } | ||
| 14834 | |||
| 14835 | return 1; | ||
| 14836 | } | ||
| 14837 | |||
| 14838 | ################## | ||
| 14839 | # Accessors - set | ||
| 14840 | |||
| 14841 | ################## | ||
| 14842 | # Accessors - task settings - get | ||
| 14843 | |||
| 14844 | # The accessors for task settings are inherited from the generic task | ||
| 14845 | |||
| 14846 | ################## | ||
| 14847 | # Accessors - task parameters - get | ||
| 14848 | |||
| 14849 | sub showInfoFlag | ||
| 14850 | { $_[0]->{showInfoFlag} } | ||
| 14851 | sub useMacrosFlag | ||
| 14852 | { $_[0]->{useMacrosFlag} } | ||
| 14853 | sub macroMode | ||
| 14854 | { $_[0]->{macroMode} } | ||
| 14855 | sub macroList | ||
| 14856 | { my $self = shift; return @{$self->{macroList}}; } | ||
| 14857 | } | ||
| 14858 | |||
| 14859 | { package Games::Axmud::Task::Countdown; | ||
| 14860 | |||
| 14861 | use strict; | ||
| 14862 | use warnings; | ||
| 14863 | # use diagnostics; | ||
| 14864 | |||
| 14865 | use Glib qw(TRUE FALSE); | ||
| 14866 | |||
| 14867 | our @ISA = qw(Games::Axmud::Generic::Task Games::Axmud); | ||
| 14868 | |||
| 14869 | ################## | ||
| 14870 | # Constructors | ||
| 14871 | |||
| 14872 | sub new { | ||
| 14873 | |||
| 14874 | # Creates a new instance of the Countdown task | ||
| 14875 | # | ||
| 14876 | # Expected arguments | ||
| 14877 | # $session - The parent GA::Session (not stored as an IV) | ||
| 14878 | # | ||
| 14879 | # Optional arguments | ||
| 14880 | # $taskType - Which tasklist this task is being created into - 'current' for the current | ||
| 14881 | # tasklist (tasks which are actually running now), 'initial' (tasks which | ||
| 14882 | # should be run when the user connects to the world), 'custom' (tasks with | ||
| 14883 | # customised initial parameters, which are run when the user demands). If | ||
| 14884 | # set to 'undef', this is a temporary task, created in order to access the | ||
| 14885 | # default values stored in IVs, that will not be added to any tasklist | ||
| 14886 | # $profName - ($taskType = 'current', when called by $self->clone) Name of the | ||
| 14887 | # profile from whose initial tasklist this task was created ('undef' if | ||
| 14888 | # none) | ||
| 14889 | # - ($taskType = 'initial') name of the profile in whose initial tasklist this | ||
| 14890 | # task will be. If 'undef', the global initial tasklist is used | ||
| 14891 | # - ($taskType = 'custom') 'undef' | ||
| 14892 | # $profCategory | ||
| 14893 | # - ($taskType = 'current', 'initial') which category the profile falls undef | ||
| 14894 | # (i.e. 'world', 'race', 'char', etc, or 'undef' if no profile) | ||
| 14895 | # - ($taskType = 'custom') 'undef' | ||
| 14896 | # $customName | ||
| 14897 | # - ($taskType = 'current', 'initial') 'undef' | ||
| 14898 | # - ($taskType = 'custom') the custom task name, matching a key in | ||
| 14899 | # GA::Session->customTaskHash | ||
| 14900 | # | ||
| 14901 | # Return values | ||
| 14902 | # 'undef' on improper arguments or if the task can't be added to the specified tasklist | ||
| 14903 | # Blessed reference to the newly-created object on success | ||
| 14904 | |||
| 14905 | my ($class, $session, $taskType, $profName, $profCategory, $customName, $check) = @_; | ||
| 14906 | |||
| 14907 | # Check for improper arguments | ||
| 14908 | if (! defined $class || ! defined $session || defined $check) { | ||
| 14909 | |||
| 14910 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 14911 | } | ||
| 14912 | |||
| 14913 | if ($taskType) { | ||
| 14914 | |||
| 14915 | # For initial tasks, check that $profName exists | ||
| 14916 | if ( | ||
| 14917 | $taskType eq 'initial' | ||
| 14918 | && defined $profName | ||
| 14919 | && ! $session->ivExists('profHash', $profName) | ||
| 14920 | ) { | ||
| 14921 | return $session->writeError( | ||
| 14922 | 'Can\'t create new task because \'' . $profName . '\' profile doesn\'t exist', | ||
| 14923 | $class . '->new', | ||
| 14924 | ); | ||
| 14925 | |||
| 14926 | # For custom tasks, check that $customName doesn't already exist | ||
| 14927 | } elsif ( | ||
| 14928 | $taskType eq 'custom' | ||
| 14929 | && $axmud::CLIENT->ivExists('customTaskHash', $customName) | ||
| 14930 | ) { | ||
| 14931 | return $session->writeError( | ||
| 14932 | 'Can\'t create new custom task because \'' . $customName . '\' is already being' | ||
| 14933 | . ' used', | ||
| 14934 | $class . '->new', | ||
| 14935 | ); | ||
| 14936 | |||
| 14937 | } elsif ($taskType ne 'current' && $taskType ne 'initial' && $taskType ne 'custom') { | ||
| 14938 | |||
| 14939 | return $session->writeError( | ||
| 14940 | 'Can\'t create new task because \'' . $taskType . '\' is an invalid tasklist', | ||
| 14941 | $class . '->new', | ||
| 14942 | ); | ||
| 14943 | } | ||
| 14944 | } | ||
| 14945 | |||
| 14946 | # Task settings | ||
| 14947 | my $self = Games::Axmud::Generic::Task->new( | ||
| 14948 | $session, | ||
| 14949 | $taskType, | ||
| 14950 | $profName, | ||
| 14951 | $profCategory, | ||
| 14952 | $customName, | ||
| 14953 | ); | ||
| 14954 | |||
| 14955 | $self->{_objName} = 'countdown_task'; | ||
| 14956 | $self->{_objClass} = $class; | ||
| 14957 | $self->{_parentFile} = undef; # Set below | ||
| 14958 | $self->{_parentWorld} = undef; # Set below | ||
| 14959 | $self->{_privFlag} = TRUE, # All IVs are private | ||
| 14960 | |||
| 14961 | $self->{name} = 'countdown_task'; | ||
| 14962 | $self->{prettyName} = 'Countdown'; | ||
| 14963 | $self->{shortName} = 'Cd'; | ||
| 14964 | $self->{shortCutIV} = undef; # Built-in task, but not jealous | ||
| 14965 | |||
| 14966 | $self->{category} = 'process'; | ||
| 14967 | $self->{descrip} = 'Creates a task window to show a countdown clock'; | ||
| 14968 | $self->{jealousyFlag} = FALSE; | ||
| 14969 | $self->{requireLocatorFlag} = FALSE; | ||
| 14970 | $self->{profSensitivityFlag} = FALSE; | ||
| 14971 | $self->{storableFlag} = TRUE; | ||
| 14972 | $self->{delayTime} = 0; | ||
| 14973 | $self->{allowWinFlag} = TRUE; | ||
| 14974 | $self->{requireWinFlag} = TRUE; | ||
| 14975 | $self->{startWithWinFlag} = TRUE; | ||
| 14976 | $self->{winPreferList} = ['pseudo', 'grid']; | ||
| 14977 | $self->{winmap} = 'basic_empty'; | ||
| 14978 | $self->{winUpdateFunc} = 'createWidgets'; | ||
| 14979 | $self->{tabMode} = undef; | ||
| 14980 | $self->{monochromeFlag} = FALSE; | ||
| 14981 | $self->{noScrollFlag} = FALSE; | ||
| 14982 | $self->{ttsFlag} = FALSE; | ||
| 14983 | $self->{ttsConfig} = undef; | ||
| 14984 | $self->{ttsAttribHash} = {}; | ||
| 14985 | $self->{ttsFlagAttribHash} = {}; | ||
| 14986 | $self->{ttsAlertAttribHash} = {}; | ||
| 14987 | $self->{status} = 'wait_init'; | ||
| 14988 | # $self->{activeFlag} = TRUE; # Task can't be activated/disactivated | ||
| 14989 | |||
| 14990 | # Task parameters | ||
| 14991 | |||
| 14992 | # Table objects created for various Gtk3 widgets, stored here because various functions | ||
| 14993 | # need them | ||
| 14994 | $self->{textViewTableObj} = undef; # GA::Table::TextView | ||
| 14995 | $self->{entryTableObj} = undef; # GA::Table::Entry | ||
| 14996 | $self->{comboTableObj} = undef; # GA::Table::Combo | ||
| 14997 | $self->{comboTableObj2} = undef; # GA::Table::Combo | ||
| 14998 | $self->{buttonTableObj} = undef; # GA::Table::Button | ||
| 14999 | $self->{buttonTableObj2} = undef; # GA::Table::Button | ||
| 15000 | $self->{buttonTableObj3} = undef; # GA::Table::Button | ||
| 15001 | |||
| 15002 | # Two IVs set by GA::Cmd::SetCountdown->do and GA::Cmd::SetCountup->do, so that a newly- | ||
| 15003 | # opened task can start counting down/up as soon as it opens | ||
| 15004 | # IV with the values 'up' or 'down' | ||
| 15005 | $self->{initMode} = undef; | ||
| 15006 | # The time, in seconds, to count | ||
| 15007 | $self->{initTime} = undef; | ||
| 15008 | |||
| 15009 | # The font and the text/underlay colours used to show the time. Colours are Axmud colour | ||
| 15010 | # tags | ||
| 15011 | $self->{textFont} = 'monospace'; # Should be a monospace font | ||
| 15012 | $self->{textSize} = '5'; # Relative size; value in range 1-10 | ||
| 15013 | $self->{textColour} = 'white'; | ||
| 15014 | $self->{underlayColour} = 'black'; | ||
| 15015 | $self->{textWarning} = 'white'; | ||
| 15016 | $self->{underlayWarning} = 'red'; | ||
| 15017 | # The last underlay colour set; only when it changes, do we need to actually update the | ||
| 15018 | # Gtk3::TextView and its surrounding area | ||
| 15019 | $self->{previousColour} = undef; | ||
| 15020 | |||
| 15021 | # The operating mode - 'default' when no time is visible, 'up' when counting up, 'down' | ||
| 15022 | # when counting down | ||
| 15023 | $self->{countMode} = 'default'; | ||
| 15024 | # Flag set to TRUE when the 'Pause' button has been pressed | ||
| 15025 | $self->{pausedFlag} = FALSE; | ||
| 15026 | # The time (matches GA::Session->sessionTime) at which the clock started | ||
| 15027 | $self->{clockStart} = undef; | ||
| 15028 | # The time (matches GA::Session->sessionTime) at which the clock should stop | ||
| 15029 | $self->{clockStop} = undef; | ||
| 15030 | # The time (matches GA::Session->sessionTime) at which the clock was paused; set back to | ||
| 15031 | # 'undef' when the clock resumes ticking | ||
| 15032 | $self->{clockFreeze} = undef; | ||
| 15033 | # How long the clock runs. ->clockTarget is the time in seconds; ->clockShow is the number | ||
| 15034 | # of seconds left | ||
| 15035 | $self->{clockTarget} = undef; | ||
| 15036 | $self->{clockLeft} = undef; | ||
| 15037 | # What time (matches ->clockLeft) at which to show a warning | ||
| 15038 | $self->{clockWarning} = undef; | ||
| 15039 | |||
| 15040 | # Sound effects. If 'undef', an empty string or an unrecognised sound effect, or if sound is | ||
| 15041 | # turned off, nothing is played | ||
| 15042 | $self->{stopEffect} = 'alert'; | ||
| 15043 | $self->{warningEffect} = 'bell'; | ||
| 15044 | |||
| 15045 | # Bless task | ||
| 15046 | bless $self, $class; | ||
| 15047 | |||
| 15048 | # For all tasks that aren't temporary... | ||
| 15049 | if ($taskType) { | ||
| 15050 | |||
| 15051 | # Check that the task doesn't belong to a disabled plugin (in which case, it can't be | ||
| 15052 | # added to any current, initial or custom tasklist) | ||
| 15053 | if (! $self->checkPlugins()) { | ||
| 15054 | |||
| 15055 | return undef; | ||
| 15056 | } | ||
| 15057 | |||
| 15058 | # Set the parent file object | ||
| 15059 | $self->setParentFileObj($session, $taskType, $profName, $profCategory); | ||
| 15060 | |||
| 15061 | # Create entries in tasklists, if possible | ||
| 15062 | if (! $self->updateTaskLists($session)) { | ||
| 15063 | |||
| 15064 | return undef; | ||
| 15065 | } | ||
| 15066 | } | ||
| 15067 | |||
| 15068 | # Task creation complete | ||
| 15069 | return $self; | ||
| 15070 | } | ||
| 15071 | |||
| 15072 | # sub clone {} # Inherited from generic task | ||
| 15073 | |||
| 15074 | # sub preserve {} # Inherited from generic task | ||
| 15075 | |||
| 15076 | # sub setParentFileObj {} # Inherited from generic task | ||
| 15077 | |||
| 15078 | # sub updateTaskLists {} # Inherited from generic task | ||
| 15079 | |||
| 15080 | # sub ttsReadAttrib {} # Inherited from generic task | ||
| 15081 | |||
| 15082 | # sub ttsSwitchFlagAttrib {} # Inherited from generic task | ||
| 15083 | |||
| 15084 | # sub ttsSetAlertAttrib {} # Inherited from generic task | ||
| 15085 | |||
| 15086 | ################## | ||
| 15087 | # Task windows | ||
| 15088 | |||
| 15089 | # sub toggleWin {} # Inherited from generic task | ||
| 15090 | |||
| 15091 | # sub openWin {} # Inherited from generic task | ||
| 15092 | |||
| 15093 | # sub closeWin {} # Inherited from generic task | ||
| 15094 | |||
| 15095 | ################## | ||
| 15096 | # Methods | ||
| 15097 | |||
| 15098 | # sub main {} # Inherited from generic task | ||
| 15099 | |||
| 15100 | # sub doShutdown {} # Inherited from generic task | ||
| 15101 | |||
| 15102 | # sub doReset {} # Inherited from generic task | ||
| 15103 | |||
| 15104 | # sub doFirstStage {} # Inherited from generic task | ||
| 15105 | |||
| 15106 | sub doStage { | ||
| 15107 | |||
| 15108 | # Called by $self->main to process all stages (except stage 1) | ||
| 15109 | # | ||
| 15110 | # Expected arguments | ||
| 15111 | # (none besides $self) | ||
| 15112 | # | ||
| 15113 | # Return values | ||
| 15114 | # 'undef' on improper arguments or if this function sets that task's ->status IV to | ||
| 15115 | # 'finished' or sets its ->shutdownFlag to TRUE | ||
| 15116 | # Otherwise, we normally return the new value of $self->stage | ||
| 15117 | |||
| 15118 | my ($self, $check) = @_; | ||
| 15119 | |||
| 15120 | # Check for improper arguments | ||
| 15121 | if (defined $check) { | ||
| 15122 | |||
| 15123 | return $axmud::CLIENT->writeImproper($self->_objClass . '->doStage', @_); | ||
| 15124 | } | ||
| 15125 | |||
| 15126 | if ($self->stage == 2) { | ||
| 15127 | |||
| 15128 | # Draw widgets for the task window | ||
| 15129 | $self->createWidgets(); | ||
| 15130 | |||
| 15131 | # If initialisation IVs were set, we can start the clock immediately | ||
| 15132 | if (defined $self->initMode) { | ||
| 15133 | |||
| 15134 | $self->startClock($self->initMode, $self->initTime); | ||
| 15135 | } | ||
| 15136 | |||
| 15137 | return $self->ivPoke('stage', 3); | ||
| 15138 | |||
| 15139 | } elsif ($self->stage == 3) { | ||
| 15140 | |||
| 15141 | my ($time, $oldTime); | ||
| 15142 | |||
| 15143 | if ($self->countMode ne 'default' && ! $self->pausedFlag) { | ||
| 15144 | |||
| 15145 | # Clock is running | ||
| 15146 | $time = $self->clockStop - $self->session->sessionTime; | ||
| 15147 | if ($time <= 0) { | ||
| 15148 | |||
| 15149 | # Stop the clock! | ||
| 15150 | $self->ivUndef('clockWarning'); # Don't draw in red | ||
| 15151 | if ($self->countMode eq 'down') { | ||
| 15152 | $self->drawTime(0); | ||
| 15153 | } else { | ||
| 15154 | $self->drawTime($self->clockTarget); | ||
| 15155 | } | ||
| 15156 | |||
| 15157 | # Update IVs | ||
| 15158 | $self->ivPoke('countMode', 'default'); | ||
| 15159 | $self->ivPoke('pausedFlag', FALSE); | ||
| 15160 | $self->ivUndef('clockStart'); | ||
| 15161 | $self->ivUndef('clockStop'); | ||
| 15162 | $self->ivUndef('clockFreeze'); | ||
| 15163 | $self->ivUndef('clockTarget'); | ||
| 15164 | $self->ivUndef('clockLeft'); | ||
| 15165 | |||
| 15166 | # Update widgets | ||
| 15167 | $self->entryTableObj->set_normal(TRUE); | ||
| 15168 | $self->buttonTableObj->set_normal(TRUE); | ||
| 15169 | $self->buttonTableObj2->set_normal(FALSE); | ||
| 15170 | $self->buttonTableObj3->set_normal(FALSE); | ||
| 15171 | |||
| 15172 | # Play sound effects | ||
| 15173 | if (defined $self->stopEffect && $self->stopEffect ne '') { | ||
| 15174 | |||
| 15175 | $axmud::CLIENT->playSound($self->stopEffect); | ||
| 15176 | } | ||
| 15177 | |||
| 15178 | } elsif (int($time) < ($self->clockLeft - 1)) { | ||
| 15179 | |||
| 15180 | # Update the clock time | ||
| 15181 | $oldTime = $self->clockLeft; | ||
| 15182 | $self->ivPoke('clockLeft', int($time) + 1); | ||
| 15183 | |||
| 15184 | if ($self->countMode eq 'down') { | ||
| 15185 | $self->drawTime($self->clockLeft); | ||
| 15186 | } else { | ||
| 15187 | $self->drawTime(int($self->clockStop - $self->clockStart - $time)); | ||
| 15188 | } | ||
| 15189 | |||
| 15190 | # Play sound effects | ||
| 15191 | if ( | ||
| 15192 | defined $self->clockWarning | ||
| 15193 | && $self->clockWarning >= $self->clockLeft | ||
| 15194 | && $self->clockWarning < $oldTime | ||
| 15195 | && defined $self->warningEffect | ||
| 15196 | && $self->warningEffect ne '' | ||
| 15197 | ) { | ||
| 15198 | $axmud::CLIENT->playSound($self->warningEffect); | ||
| 15199 | } | ||
| 15200 | } | ||
| 15201 | } | ||
| 15202 | |||
| 15203 | # Repeat this stage indefinitely | ||
| 15204 | return $self->ivPoke('stage', 3); | ||
| 15205 | |||
| 15206 | } else { | ||
| 15207 | |||
| 15208 | # The task stage has somehow been set to an invalid value | ||
| 15209 | return $self->invalidStage(); | ||
| 15210 | } | ||
| 15211 | } | ||
| 15212 | |||
| 15213 | sub createWidgets { | ||
| 15214 | |||
| 15215 | # Set up the widgets used in the task window | ||
| 15216 | # | ||
| 15217 | # Expected arguments | ||
| 15218 | # (none besides $self) | ||
| 15219 | # | ||
| 15220 | # Return values | ||
| 15221 | # 'undef' on improper arguments or if the task window isn't open | ||
| 15222 | # 1 otherwise | ||
| 15223 | |||
| 15224 | my ($self, $check) = @_; | ||
| 15225 | |||
| 15226 | # Local variables | ||
| 15227 | my (@comboList, @comboList2); | ||
| 15228 | |||
| 15229 | # Check for improper arguments | ||
| 15230 | if (defined $check) { | ||
| 15231 | |||
| 15232 | return $axmud::CLIENT->writeImproper($self->_objClass . '->createWidgets', @_); | ||
| 15233 | } | ||
| 15234 | |||
| 15235 | # If the task window (a 'grid' window or a pseudo-window inside the session's 'main' window) | ||
| 15236 | # isn't open, don't need to create widgets | ||
| 15237 | if (! $self->winObj) { | ||
| 15238 | |||
| 15239 | return undef; | ||
| 15240 | } | ||
| 15241 | |||
| 15242 | # v1.3.095 The original code (preserved below) used a Gtk3::Label. Alas, Axmud colour tags | ||
| 15243 | # (used by the surrounding area) and Pango colours (used by the label) aren't the same | ||
| 15244 | # So, replaced the label with a Gtk3::TextView, so that everything can use Axmud colour tags | ||
| 15245 | |||
| 15246 | # my $labelTableObj = $self->winObj->tableStripObj->addTableObj( | ||
| 15247 | # 'Games::Axmud::Table::Label', | ||
| 15248 | # 0, 59, 0, 39, | ||
| 15249 | # undef, | ||
| 15250 | # # Init settings | ||
| 15251 | # 'justify' => 'centre', | ||
| 15252 | # 'align_x' => 0.5, | ||
| 15253 | # 'align_y' => 0.5, | ||
| 15254 | # 'expand_horizontal_flag' => TRUE, | ||
| 15255 | # 'expand_vertical_flag' => TRUE, | ||
| 15256 | # ); | ||
| 15257 | # | ||
| 15258 | # # (Must store the IV immediately, so the call to ->setBackgroundColour will work) | ||
| 15259 | # $self->ivPoke('labelTableObj', $labelTableObj); | ||
| 15260 | # $self->setBackgroundColour($self->underlayColour); | ||
| 15261 | # | ||
| 15262 | # # (This line forces the label to the middle of the window) | ||
| 15263 | # $labelTableObj->label->set_hexpand(TRUE); | ||
| 15264 | |||
| 15265 | my $textViewTableObj = $self->winObj->tableStripObj->addTableObj( | ||
| 15266 | 'Games::Axmud::Table::TextView', | ||
| 15267 | 0, 59, 0, 39, | ||
| 15268 | undef, | ||
| 15269 | # Init settings | ||
| 15270 | 'edit_flag' => FALSE, | ||
| 15271 | 'expand_horizontal_flag' => TRUE, | ||
| 15272 | 'expand_vertical_flag' => TRUE, | ||
| 15273 | ); | ||
| 15274 | |||
| 15275 | $textViewTableObj->textView->set_justification('GTK_JUSTIFY_CENTER'); | ||
| 15276 | $textViewTableObj->textView->set_valign('GTK_ALIGN_CENTER'); | ||
| 15277 | |||
| 15278 | # # (Must store the IV immediately, so the call to ->setBackgroundColour will work) | ||
| 15279 | $self->ivPoke('textViewTableObj', $textViewTableObj); | ||
| 15280 | $self->setBackgroundColour($self->underlayColour); | ||
| 15281 | |||
| 15282 | my $entryTableObj = $self->winObj->tableStripObj->addTableObj( | ||
| 15283 | 'Games::Axmud::Table::Entry', | ||
| 15284 | 0, 19, 40, 49, | ||
| 15285 | undef, | ||
| 15286 | # Init settings | ||
| 15287 | 'func' => $self->getMethodRef('enterCallback'), | ||
| 15288 | 'clear_flag' => FALSE, | ||
| 15289 | 'width_chars' => 8, | ||
| 15290 | 'max_chars' => 8, | ||
| 15291 | ); | ||
| 15292 | |||
| 15293 | @comboList = ( | ||
| 15294 | 'seconds', | ||
| 15295 | 'minutes', | ||
| 15296 | 'hours', | ||
| 15297 | ); | ||
| 15298 | my $comboTableObj = $self->winObj->tableStripObj->addTableObj( | ||
| 15299 | 'Games::Axmud::Table::ComboBox', | ||
| 15300 | 20, 39, 40, 49, | ||
| 15301 | undef, | ||
| 15302 | # Init settings | ||
| 15303 | 'list_ref' => \@comboList, | ||
| 15304 | ); | ||
| 15305 | |||
| 15306 | @comboList2 = ( | ||
| 15307 | 'count down', | ||
| 15308 | 'count up', | ||
| 15309 | ); | ||
| 15310 | my $comboTableObj2 = $self->winObj->tableStripObj->addTableObj( | ||
| 15311 | 'Games::Axmud::Table::ComboBox', | ||
| 15312 | 40, 59, 40, 49, | ||
| 15313 | undef, | ||
| 15314 | # Init settings | ||
| 15315 | 'list_ref' => \@comboList2, | ||
| 15316 | ); | ||
| 15317 | |||
| 15318 | my $buttonTableObj = $self->winObj->tableStripObj->addTableObj( | ||
| 15319 | 'Games::Axmud::Table::Button', | ||
| 15320 | 0, 19, 50, 59, | ||
| 15321 | undef, | ||
| 15322 | # Init settings | ||
| 15323 | 'func' => $self->getMethodRef('startCallback'), | ||
| 15324 | 'id' => 'start', | ||
| 15325 | 'text' => 'Start', | ||
| 15326 | 'tooltips' => 'Start the clock', | ||
| 15327 | ); | ||
| 15328 | |||
| 15329 | my $buttonTableObj2 = $self->winObj->tableStripObj->addTableObj( | ||
| 15330 | 'Games::Axmud::Table::Button', | ||
| 15331 | 20, 39, 50, 59, | ||
| 15332 | undef, | ||
| 15333 | # Init settings | ||
| 15334 | 'func' => $self->getMethodRef('pauseCallback'), | ||
| 15335 | 'id' => 'pause', | ||
| 15336 | 'text' => 'Pause', | ||
| 15337 | 'tooltips' => 'Pause the clock', | ||
| 15338 | 'normal_flag' => FALSE, | ||
| 15339 | ); | ||
| 15340 | |||
| 15341 | my $buttonTableObj3 = $self->winObj->tableStripObj->addTableObj( | ||
| 15342 | 'Games::Axmud::Table::Button', | ||
| 15343 | 40, 59, 50, 59, | ||
| 15344 | undef, | ||
| 15345 | # Init settings | ||
| 15346 | 'func' => $self->getMethodRef('stopCallback'), | ||
| 15347 | 'id' => 'stop', | ||
| 15348 | 'text' => 'Stop', | ||
| 15349 | 'tooltips' => 'Stop the clock', | ||
| 15350 | 'normal_flag' => FALSE, | ||
| 15351 | ); | ||
| 15352 | |||
| 15353 | # Store the remaining table objects for the benefit of various functions | ||
| 15354 | $self->ivPoke('entryTableObj', $entryTableObj); | ||
| 15355 | $self->ivPoke('comboTableObj', $comboTableObj); | ||
| 15356 | $self->ivPoke('comboTableObj2', $comboTableObj2); | ||
| 15357 | $self->ivPoke('buttonTableObj', $buttonTableObj); | ||
| 15358 | $self->ivPoke('buttonTableObj2', $buttonTableObj2); | ||
| 15359 | $self->ivPoke('buttonTableObj3', $buttonTableObj3); | ||
| 15360 | |||
| 15361 | # Display all the widgets, including a blank textview | ||
| 15362 | $self->drawTime(); | ||
| 15363 | $self->winObj->winShowAll($self->_objClass . '->createWidgets'); | ||
| 15364 | |||
| 15365 | return 1; | ||
| 15366 | } | ||
| 15367 | |||
| 15368 | sub initClock { | ||
| 15369 | |||
| 15370 | # Called by GA::Cmd::SetCountdown->do and GA::Cmd::SetCountup->do | ||
| 15371 | # Sets the task's initialisation IVs, so that the clock starts counting as soon as stage 3 | ||
| 15372 | # is reached for the first time | ||
| 15373 | # | ||
| 15374 | # Expected arguments | ||
| 15375 | # $mode - 'up' to count up, 'down' to count down | ||
| 15376 | # $secs - The time to count, in seconds | ||
| 15377 | # | ||
| 15378 | # Return values | ||
| 15379 | # 'undef' on improper arguments, if $self->stage is already at 3 or if $secs is invalid | ||
| 15380 | # 1 otherwise | ||
| 15381 | |||
| 15382 | my ($self, $mode, $secs, $check) = @_; | ||
| 15383 | |||
| 15384 | # Check for improper arguments | ||
| 15385 | if ( | ||
| 15386 | ! defined $mode | ||
| 15387 | || ($mode ne 'down' && $mode ne 'up') | ||
| 15388 | || ! defined $secs || defined $check | ||
| 15389 | ) { | ||
| 15390 | return $axmud::CLIENT->writeImproper($self->_objClass . '->initClock', @_); | ||
| 15391 | } | ||
| 15392 | |||
| 15393 | # This function can't be called if the task is already running | ||
| 15394 | if ($self->stage >= 3) { | ||
| 15395 | |||
| 15396 | return undef; | ||
| 15397 | |||
| 15398 | # Check $secs is valid | ||
| 15399 | } elsif (! $axmud::CLIENT->floatCheck($secs, 0) || $secs == 0) { | ||
| 15400 | |||
| 15401 | return undef; | ||
| 15402 | } | ||
| 15403 | |||
| 15404 | # Update IVs | ||
| 15405 | $self->ivPoke('initMode', $mode); | ||
| 15406 | $self->ivPoke('initTime', $secs); | ||
| 15407 | |||
| 15408 | return 1; | ||
| 15409 | } | ||
| 15410 | |||
| 15411 | sub startClock { | ||
| 15412 | |||
| 15413 | # Called by $self->doStage (at stage 2) and $self->startCallback | ||
| 15414 | # Also called by GA::Cmd::Countdown->do and Countup->do | ||
| 15415 | # Starts the clock, counting down towards zero or up from zero | ||
| 15416 | # | ||
| 15417 | # Expected arguments | ||
| 15418 | # $mode - 'up' to count up, 'down' to count down | ||
| 15419 | # $secs - The time to count, in seconds | ||
| 15420 | # | ||
| 15421 | # Return values | ||
| 15422 | # 'undef' on improper arguments | ||
| 15423 | # 1 otherwise | ||
| 15424 | |||
| 15425 | my ($self, $mode, $secs, $check) = @_; | ||
| 15426 | |||
| 15427 | # Local variables | ||
| 15428 | my $maxSecs; | ||
| 15429 | |||
| 15430 | # Check for improper arguments | ||
| 15431 | if ( | ||
| 15432 | ! defined $mode | ||
| 15433 | || ($mode ne 'down' && $mode ne 'up') | ||
| 15434 | || ! defined $secs || defined $check | ||
| 15435 | ) { | ||
| 15436 | return $axmud::CLIENT->writeImproper($self->_objClass . '->startClock', @_); | ||
| 15437 | } | ||
| 15438 | |||
| 15439 | # The maximum time is 99, 59 minutes and 59 seconds. If $secs exceeds that, revert to the | ||
| 15440 | # maximum | ||
| 15441 | $maxSecs = 100 * 60 * 60; | ||
| 15442 | if ($secs >= $maxSecs) { | ||
| 15443 | |||
| 15444 | $secs = $maxSecs - 1; | ||
| 15445 | } | ||
| 15446 | |||
| 15447 | # Update IVs | ||
| 15448 | $self->ivPoke('countMode', $mode); | ||
| 15449 | $self->ivPoke('pausedFlag', FALSE); | ||
| 15450 | $self->ivPoke('clockStart', $self->session->sessionTime); | ||
| 15451 | $self->ivPoke('clockStop', ($self->session->sessionTime + $secs)); | ||
| 15452 | $self->ivUndef('clockFreeze'); | ||
| 15453 | $self->ivPoke('clockTarget', $secs); | ||
| 15454 | $self->ivPoke('clockLeft', $secs); | ||
| 15455 | |||
| 15456 | # The time at which a warning is shown depends on how long the clock is going to run. | ||
| 15457 | if ($secs <= 10) { | ||
| 15458 | |||
| 15459 | # If it's less than 10 seconds, don't show a warning at all | ||
| 15460 | $self->ivPoke('clockWarning', undef); | ||
| 15461 | |||
| 15462 | } elsif ($secs <= 60) { | ||
| 15463 | |||
| 15464 | # Less than a minute | ||
| 15465 | $self->ivPoke('clockWarning', 5); | ||
| 15466 | |||
| 15467 | } elsif ($secs <= 120) { | ||
| 15468 | |||
| 15469 | # Less than two minutes | ||
| 15470 | $self->ivPoke('clockWarning', 10); | ||
| 15471 | |||
| 15472 | } elsif ($secs <= 300) { | ||
| 15473 | |||
| 15474 | # Less than five minutes | ||
| 15475 | $self->ivPoke('clockWarning', 30); | ||
| 15476 | |||
| 15477 | } elsif ($secs <= 600) { | ||
| 15478 | |||
| 15479 | # Less than ten minutes | ||
| 15480 | $self->ivPoke('clockWarning', 60); | ||
| 15481 | |||
| 15482 | } elsif ($secs <= 1200) { | ||
| 15483 | |||
| 15484 | # Less than twenty minutes | ||
| 15485 | $self->ivPoke('clockWarning', 120); | ||
| 15486 | |||
| 15487 | } else { | ||
| 15488 | |||
| 15489 | # Default - 5-minute warning | ||
| 15490 | $self->ivPoke('clockWarning', 300); | ||
| 15491 | } | ||
| 15492 | |||
| 15493 | # Update table widgets | ||
| 15494 | $self->entryTableObj->set_normal(FALSE); | ||
| 15495 | $self->buttonTableObj->set_normal(FALSE); | ||
| 15496 | $self->buttonTableObj2->set_normal(TRUE); | ||
| 15497 | $self->buttonTableObj3->set_normal(TRUE); | ||
| 15498 | |||
| 15499 | # Show the first clock time | ||
| 15500 | if ($self->countMode eq 'up') { | ||
| 15501 | $self->drawTime(0); | ||
| 15502 | } else { | ||
| 15503 | $self->drawTime($self->clockLeft); | ||
| 15504 | } | ||
| 15505 | |||
| 15506 | return 1; | ||
| 15507 | } | ||
| 15508 | |||
| 15509 | sub drawTime { | ||
| 15510 | |||
| 15511 | # Called by various functions to set (or reset) the clock time displayed as a | ||
| 15512 | # Gtk3::TextView | ||
| 15513 | # | ||
| 15514 | # Expected arguments | ||
| 15515 | # (none besides $self) | ||
| 15516 | # | ||
| 15517 | # Optional values | ||
| 15518 | # $secs - The time to show, in seconds | ||
| 15519 | # | ||
| 15520 | # Return values | ||
| 15521 | # 'undef' on improper arguments | ||
| 15522 | # 1 otherwise | ||
| 15523 | |||
| 15524 | my ($self, $secs, $check) = @_; | ||
| 15525 | |||
| 15526 | # Local variables | ||
| 15527 | my ( | ||
| 15528 | $origSecs, $string, $hours, $mins, $textColour, $underlayColour, $provider, $display, | ||
| 15529 | $screen, $theming, $context, | ||
| 15530 | ); | ||
| 15531 | |||
| 15532 | # Check for improper arguments | ||
| 15533 | if (defined $check) { | ||
| 15534 | |||
| 15535 | return $axmud::CLIENT->writeImproper($self->_objClass . '->drawTime', @_); | ||
| 15536 | } | ||
| 15537 | |||
| 15538 | # Convert $secs, an integer, into a string like '49:12' | ||
| 15539 | $origSecs = $secs; | ||
| 15540 | if (! defined $secs) { | ||
| 15541 | |||
| 15542 | # No time shown | ||
| 15543 | $string = ''; | ||
| 15544 | |||
| 15545 | } else { | ||
| 15546 | |||
| 15547 | $hours = int($secs / 3600); | ||
| 15548 | $secs -= ($hours * 3600); | ||
| 15549 | |||
| 15550 | $mins = int($secs / 60); | ||
| 15551 | $secs -= ($mins * 60); | ||
| 15552 | |||
| 15553 | if ($hours) { | ||
| 15554 | if ($hours > 9) { | ||
| 15555 | $string = sprintf('%02d:%02d:%02d', $hours, $mins, $secs); | ||
| 15556 | } else { | ||
| 15557 | $string = sprintf('%01d:%02d:%02d', $hours, $mins, $secs); | ||
| 15558 | } | ||
| 15559 | } elsif ($mins) { | ||
| 15560 | if ($mins > 9) { | ||
| 15561 | $string = sprintf('%02d:%02d', $mins, $secs); | ||
| 15562 | } else { | ||
| 15563 | $string = sprintf('%01d:%02d', $mins, $secs); | ||
| 15564 | } | ||
| 15565 | } else { | ||
| 15566 | $string = sprintf('0:%02d', $secs); | ||
| 15567 | } | ||
| 15568 | } | ||
| 15569 | |||
| 15570 | # Set the colours to use | ||
| 15571 | if ( | ||
| 15572 | ! defined $self->clockWarning | ||
| 15573 | || ! $self->clockLeft | ||
| 15574 | || ! $origSecs | ||
| 15575 | || $self->clockWarning < $self->clockLeft | ||
| 15576 | ) { | ||
| 15577 | $textColour = $self->textColour; | ||
| 15578 | $underlayColour = $self->underlayColour; | ||
| 15579 | |||
| 15580 | } else { | ||
| 15581 | |||
| 15582 | $textColour = $self->textWarning; | ||
| 15583 | $underlayColour = $self->underlayWarning; | ||
| 15584 | } | ||
| 15585 | |||
| 15586 | if (! defined $self->previousColour || $self->previousColour ne $underlayColour) { | ||
| 15587 | |||
| 15588 | # Update IVs (don't change the background, if the old colour is the same as the new one) | ||
| 15589 | $self->ivPoke('previousColour', $underlayColour); | ||
| 15590 | |||
| 15591 | # Update the colour of the background surrounding the Gtk3::TextView | ||
| 15592 | $self->setBackgroundColour($underlayColour); | ||
| 15593 | |||
| 15594 | # Set the textview colours (code adapted from GA::Obj::Desktop->setTextViewStyle) | ||
| 15595 | $provider = Gtk3::CssProvider->new(); | ||
| 15596 | $display = Gtk3::Gdk::Display::get_default(); | ||
| 15597 | $screen = Gtk3::Gdk::Display::get_default_screen($display); | ||
| 15598 | Gtk3::StyleContext::add_provider_for_screen($screen, $provider, 600); | ||
| 15599 | |||
| 15600 | $theming = "#css_text_id_cdtask, textview text {\n" | ||
| 15601 | . " background-color: " | ||
| 15602 | . $axmud::CLIENT->returnRGBColour($underlayColour) . ";\n" | ||
| 15603 | . " color: " . $textColour . ";\n" | ||
| 15604 | . "}\n" | ||
| 15605 | . "#css_label_id_cdtask, textview {\n"; | ||
| 15606 | |||
| 15607 | # ($self->textSize is a relative value in the range 1-10; convert the Pango value to an | ||
| 15608 | # acceptable CSS value by simple multiplication) | ||
| 15609 | if ($^O eq 'MSWin32') { | ||
| 15610 | |||
| 15611 | $theming | ||
| 15612 | .= " font-family: " . $self->textFont . ";\n" | ||
| 15613 | . " font-size: " . ($self->textSize * 10) . "px;\n" | ||
| 15614 | . "}"; | ||
| 15615 | |||
| 15616 | } else { | ||
| 15617 | |||
| 15618 | $theming | ||
| 15619 | .= " font-family: " . $self->textFont . ", monospace;\n" | ||
| 15620 | . " font-size: " . ($self->textSize * 10). "pt;\n" | ||
| 15621 | . "}"; | ||
| 15622 | } | ||
| 15623 | |||
| 15624 | $provider->load_from_data ([map ord, split //, $theming]); | ||
| 15625 | |||
| 15626 | $context = $self->textViewTableObj->textView->get_style_context(); | ||
| 15627 | $context->add_provider($provider, 600); | ||
| 15628 | } | ||
| 15629 | |||
| 15630 | # Set the text itself | ||
| 15631 | $self->textViewTableObj->set_text($string); | ||
| 15632 | |||
| 15633 | # Update the window title | ||
| 15634 | if ($string eq '') { | ||
| 15635 | $self->setTaskWinTitle(); | ||
| 15636 | } else { | ||
| 15637 | $self->setTaskWinTitle('(' . $string . ')', TRUE); | ||
| 15638 | } | ||
| 15639 | |||
| 15640 | return 1; | ||
| 15641 | } | ||
| 15642 | |||
| 15643 | sub setBackgroundColour { | ||
| 15644 | |||
| 15645 | # Called by $self->createWidgets and ->drawTime to set the colour of the area surrounding | ||
| 15646 | # the textview, to match the textview's own underlay colour | ||
| 15647 | # | ||
| 15648 | # Expected arguments | ||
| 15649 | # $colour - A string like 'white' which represents both an Axmud colour tag and a | ||
| 15650 | # Pango colour, so must be valid for both (if not, 'black' is used as an | ||
| 15651 | # emergency backup) | ||
| 15652 | # | ||
| 15653 | # Return values | ||
| 15654 | # 'undef' on improper arguments | ||
| 15655 | # 1 otherwise | ||
| 15656 | |||
| 15657 | my ($self, $colour, $check) = @_; | ||
| 15658 | |||
| 15659 | # Local variables | ||
| 15660 | my ($rgb, $r, $g, $b); | ||
| 15661 | |||
| 15662 | # Check for improper arguments | ||
| 15663 | if (! defined $colour || defined $check) { | ||
| 15664 | |||
| 15665 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setBackgroundColour', @_); | ||
| 15666 | } | ||
| 15667 | |||
| 15668 | $rgb = $axmud::CLIENT->ivShow('colourTagHash', $colour); | ||
| 15669 | if (! defined $rgb) { | ||
| 15670 | |||
| 15671 | $rgb = '#000000'; | ||
| 15672 | } | ||
| 15673 | |||
| 15674 | $r = hex(substr($rgb, 1, 2)) / 255; | ||
| 15675 | $g = hex(substr($rgb, 3, 2)) / 255; | ||
| 15676 | $b = hex(substr($rgb, 5, 2)) / 255; | ||
| 15677 | |||
| 15678 | $self->textViewTableObj->scroll->override_background_color( | ||
| 15679 | 'GTK_STATE_FLAG_NORMAL', | ||
| 15680 | Gtk3::Gdk::RGBA->new($r, $g, $b, 1), | ||
| 15681 | ); | ||
| 15682 | |||
| 15683 | return 1, | ||
| 15684 | } | ||
| 15685 | |||
| 15686 | ################## | ||
| 15687 | # Response methods | ||
| 15688 | |||
| 15689 | sub startCallback { | ||
| 15690 | |||
| 15691 | # Called by a ->signal_connect in a GA::Table::Button object when the user clicks on the | ||
| 15692 | # 'Start' button | ||
| 15693 | # Also called by $self->entryCallback | ||
| 15694 | # | ||
| 15695 | # Expected arguments | ||
| 15696 | # $tableObj - The GA::Table::Button object for the button | ||
| 15697 | # $button - The actual Gtk3::Button clicked | ||
| 15698 | # $id - The callback ID; in this case, 'start' | ||
| 15699 | # | ||
| 15700 | # Return values | ||
| 15701 | # 'undef' on improper arguments, if the user hasn't entered a valid time value (or if | ||
| 15702 | # they've entered no value at all) or if $self->countMode is not 'default' | ||
| 15703 | # 1 otherwise | ||
| 15704 | |||
| 15705 | my ($self, $tableObj, $button, $id, $check) = @_; | ||
| 15706 | |||
| 15707 | # Local variables | ||
| 15708 | my ($time, $unit, $method); | ||
| 15709 | |||
| 15710 | # Check for improper arguments | ||
| 15711 | if (! defined $tableObj || ! defined $button || ! defined $id || defined $check) { | ||
| 15712 | |||
| 15713 | return $axmud::CLIENT->writeImproper($self->_objClass . '->startCallback', @_); | ||
| 15714 | } | ||
| 15715 | |||
| 15716 | if ($self->countMode ne 'default') { | ||
| 15717 | |||
| 15718 | # This shouldn't be possible | ||
| 15719 | return undef; | ||
| 15720 | } | ||
| 15721 | |||
| 15722 | # Get the time value, and check it's valid | ||
| 15723 | $time = $self->entryTableObj->get_text(); | ||
| 15724 | if ($time eq '') { | ||
| 15725 | |||
| 15726 | # User hasn't entered a value | ||
| 15727 | return undef; | ||
| 15728 | |||
| 15729 | } elsif (! $axmud::CLIENT->floatCheck($time, 0) || $time == 0) { | ||
| 15730 | |||
| 15731 | # Non-numeric value, or less than 0 | ||
| 15732 | return $self->winObj->showMsgDialogue( | ||
| 15733 | 'Start clock', | ||
| 15734 | 'Invalid number \'' . $time . '\'', | ||
| 15735 | 'ok', | ||
| 15736 | ); | ||
| 15737 | } | ||
| 15738 | |||
| 15739 | # Convert the time to seconds | ||
| 15740 | $unit = $self->comboTableObj->get_text(); | ||
| 15741 | if ($unit eq 'minutes') { | ||
| 15742 | $time *= 60; | ||
| 15743 | } elsif ($unit eq 'hours') { | ||
| 15744 | $time *= 3600; | ||
| 15745 | } | ||
| 15746 | |||
| 15747 | $time = int($time); | ||
| 15748 | |||
| 15749 | # Start the clock | ||
| 15750 | $method = $self->comboTableObj2->get_text(); | ||
| 15751 | if ($method eq 'count up') { | ||
| 15752 | $self->startClock('up', $time); | ||
| 15753 | } else { | ||
| 15754 | $self->startClock('down', $time); | ||
| 15755 | } | ||
| 15756 | |||
| 15757 | return 1; | ||
| 15758 | } | ||
| 15759 | |||
| 15760 | sub pauseCallback { | ||
| 15761 | |||
| 15762 | # Called by a ->signal_connect in a GA::Table::Button object when the user clicks on the | ||
| 15763 | # 'Pause' button | ||
| 15764 | # | ||
| 15765 | # Expected arguments | ||
| 15766 | # $tableObj - The GA::Table::Button object for the button | ||
| 15767 | # $button - The actual Gtk3::Button clicked | ||
| 15768 | # $id - The callback ID; in this case, 'pause' | ||
| 15769 | # | ||
| 15770 | # Return values | ||
| 15771 | # 'undef' on improper arguments or if $self->countMode is 'default' | ||
| 15772 | # 1 otherwise | ||
| 15773 | |||
| 15774 | my ($self, $tableObj, $button, $id, $check) = @_; | ||
| 15775 | |||
| 15776 | # Local variables | ||
| 15777 | my ($time, $unit, $method); | ||
| 15778 | |||
| 15779 | # Check for improper arguments | ||
| 15780 | if (! defined $tableObj || ! defined $button || ! defined $id || defined $check) { | ||
| 15781 | |||
| 15782 | return $axmud::CLIENT->writeImproper($self->_objClass . '->pauseCallback', @_); | ||
| 15783 | } | ||
| 15784 | |||
| 15785 | if ($self->countMode eq 'default') { | ||
| 15786 | |||
| 15787 | # This shouldn't be possible | ||
| 15788 | return undef; | ||
| 15789 | } | ||
| 15790 | |||
| 15791 | if (! $self->pausedFlag) { | ||
| 15792 | |||
| 15793 | $self->ivPoke('pausedFlag', TRUE); | ||
| 15794 | $self->ivPoke('clockFreeze', $self->session->sessionTime); | ||
| 15795 | |||
| 15796 | # Update widgets | ||
| 15797 | $self->entryTableObj->set_normal(FALSE); | ||
| 15798 | $self->buttonTableObj->set_normal(FALSE); | ||
| 15799 | $self->buttonTableObj2->set_normal(TRUE); | ||
| 15800 | $self->buttonTableObj3->set_normal(FALSE); | ||
| 15801 | |||
| 15802 | } else { | ||
| 15803 | |||
| 15804 | $self->ivPoke('pausedFlag', FALSE); | ||
| 15805 | $self->ivPoke( | ||
| 15806 | 'clockStop', | ||
| 15807 | $self->clockStop + $self->session->sessionTime - $self->clockFreeze, | ||
| 15808 | ); | ||
| 15809 | |||
| 15810 | $self->ivUndef('clockFreeze'); | ||
| 15811 | |||
| 15812 | # Update widgets | ||
| 15813 | $self->entryTableObj->set_normal(FALSE); | ||
| 15814 | $self->buttonTableObj->set_normal(FALSE); | ||
| 15815 | $self->buttonTableObj2->set_normal(TRUE); | ||
| 15816 | $self->buttonTableObj3->set_normal(TRUE); | ||
| 15817 | } | ||
| 15818 | |||
| 15819 | return 1; | ||
| 15820 | } | ||
| 15821 | |||
| 15822 | sub stopCallback { | ||
| 15823 | |||
| 15824 | # Called by a ->signal_connect in a GA::Table::Button object when the user clicks on the | ||
| 15825 | # 'Stop' button | ||
| 15826 | # | ||
| 15827 | # Expected arguments | ||
| 15828 | # $tableObj - The GA::Table::Button object for the button | ||
| 15829 | # $button - The actual Gtk3::Button clicked | ||
| 15830 | # $id - The callback ID; in this case, 'stop' | ||
| 15831 | # | ||
| 15832 | # Return values | ||
| 15833 | # 'undef' on improper arguments, if the user hasn't entered a valid time value (or if | ||
| 15834 | # they've entered no value at all) or if $self->countMode is still 'default' | ||
| 15835 | # 1 otherwise | ||
| 15836 | |||
| 15837 | my ($self, $tableObj, $button, $id, $check) = @_; | ||
| 15838 | |||
| 15839 | # Local variables | ||
| 15840 | my ($time, $unit, $method); | ||
| 15841 | |||
| 15842 | # Check for improper arguments | ||
| 15843 | if (! defined $tableObj || ! defined $button || ! defined $id || defined $check) { | ||
| 15844 | |||
| 15845 | return $axmud::CLIENT->writeImproper($self->_objClass . '->stopCallback', @_); | ||
| 15846 | } | ||
| 15847 | |||
| 15848 | if ($self->countMode eq 'default') { | ||
| 15849 | |||
| 15850 | # This shouldn't happen | ||
| 15851 | return undef; | ||
| 15852 | } | ||
| 15853 | |||
| 15854 | # Reset the clock | ||
| 15855 | $self->drawTime(); | ||
| 15856 | |||
| 15857 | # Update IVs | ||
| 15858 | $self->ivPoke('countMode', 'default'); | ||
| 15859 | $self->ivPoke('pausedFlag', FALSE); | ||
| 15860 | $self->ivUndef('clockStart'); | ||
| 15861 | $self->ivUndef('clockStop'); | ||
| 15862 | $self->ivUndef('clockFreeze'); | ||
| 15863 | $self->ivUndef('clockTarget'); | ||
| 15864 | $self->ivUndef('clockLeft'); | ||
| 15865 | $self->ivUndef('clockWarning'); | ||
| 15866 | |||
| 15867 | # Update widgets | ||
| 15868 | $self->entryTableObj->set_normal(TRUE); | ||
| 15869 | $self->buttonTableObj->set_normal(TRUE); | ||
| 15870 | $self->buttonTableObj2->set_normal(FALSE); | ||
| 15871 | $self->buttonTableObj3->set_normal(FALSE); | ||
| 15872 | |||
| 15873 | return 1; | ||
| 15874 | } | ||
| 15875 | |||
| 15876 | sub enterCallback { | ||
| 15877 | |||
| 15878 | # Called by a ->signal_connect in a GA::Table::Button object when the user clicks on the | ||
| 15879 | # types a value in he Gtk3::Entry, and presses Enter | ||
| 15880 | # | ||
| 15881 | # Expected arguments | ||
| 15882 | # $tableObj - The GA::Table::Entry object for the button | ||
| 15883 | # $entry - The actual Gtk3::Entry used | ||
| 15884 | # $id - The callback ID | ||
| 15885 | # $value - The contents of the Gtk3:Entry | ||
| 15886 | # | ||
| 15887 | # Return values | ||
| 15888 | # 'undef' on improper arguments, if the user hasn't entered a valid time value (or if | ||
| 15889 | # they've entered no value at all) or if $self->countMode is not 'default' | ||
| 15890 | # 1 otherwise | ||
| 15891 | |||
| 15892 | my ($self, $tableObj, $entry, $id, $value, $check) = @_; | ||
| 15893 | |||
| 15894 | # Local variables | ||
| 15895 | my ($time, $unit, $method); | ||
| 15896 | |||
| 15897 | # Check for improper arguments | ||
| 15898 | if ( | ||
| 15899 | ! defined $tableObj || ! defined $entry || ! defined $id || ! defined $value | ||
| 15900 | || defined $check | ||
| 15901 | ) { | ||
| 15902 | return $axmud::CLIENT->writeImproper($self->_objClass . '->enterCallback', @_); | ||
| 15903 | } | ||
| 15904 | |||
| 15905 | # For convenience, just make a fake call to the 'Start' button's callback | ||
| 15906 | return $self->startCallback($tableObj, $entry, $id); | ||
| 15907 | } | ||
| 15908 | |||
| 15909 | ################## | ||
| 15910 | # Accessors - set | ||
| 15911 | |||
| 15912 | ################## | ||
| 15913 | # Accessors - task settings - get | ||
| 15914 | |||
| 15915 | # The accessors for task settings are inherited from the generic task | ||
| 15916 | |||
| 15917 | ################## | ||
| 15918 | # Accessors - task parameters - get | ||
| 15919 | |||
| 15920 | sub textViewTableObj | ||
| 15921 | { $_[0]->{textViewTableObj} } | ||
| 15922 | sub entryTableObj | ||
| 15923 | { $_[0]->{entryTableObj} } | ||
| 15924 | sub comboTableObj | ||
| 15925 | { $_[0]->{comboTableObj} } | ||
| 15926 | sub comboTableObj2 | ||
| 15927 | { $_[0]->{comboTableObj2} } | ||
| 15928 | sub buttonTableObj | ||
| 15929 | { $_[0]->{buttonTableObj} } | ||
| 15930 | sub buttonTableObj2 | ||
| 15931 | { $_[0]->{buttonTableObj2} } | ||
| 15932 | sub buttonTableObj3 | ||
| 15933 | { $_[0]->{buttonTableObj3} } | ||
| 15934 | |||
| 15935 | sub initMode | ||
| 15936 | { $_[0]->{initMode} } | ||
| 15937 | sub initTime | ||
| 15938 | { $_[0]->{initTime} } | ||
| 15939 | |||
| 15940 | sub textFont | ||
| 15941 | { $_[0]->{textFont} } | ||
| 15942 | sub textSize | ||
| 15943 | { $_[0]->{textSize} } | ||
| 15944 | sub textColour | ||
| 15945 | { $_[0]->{textColour} } | ||
| 15946 | sub underlayColour | ||
| 15947 | { $_[0]->{underlayColour} } | ||
| 15948 | sub textWarning | ||
| 15949 | { $_[0]->{textWarning} } | ||
| 15950 | sub underlayWarning | ||
| 15951 | { $_[0]->{underlayWarning} } | ||
| 15952 | sub previousColour | ||
| 15953 | { $_[0]->{previousColour} } | ||
| 15954 | |||
| 15955 | sub countMode | ||
| 15956 | { $_[0]->{countMode} } | ||
| 15957 | sub pausedFlag | ||
| 15958 | { $_[0]->{pausedFlag} } | ||
| 15959 | sub clockStart | ||
| 15960 | { $_[0]->{clockStart} } | ||
| 15961 | sub clockStop | ||
| 15962 | { $_[0]->{clockStop} } | ||
| 15963 | sub clockFreeze | ||
| 15964 | { $_[0]->{clockFreeze} } | ||
| 15965 | sub clockTarget | ||
| 15966 | { $_[0]->{clockTarget} } | ||
| 15967 | sub clockLeft | ||
| 15968 | { $_[0]->{clockLeft} } | ||
| 15969 | sub clockWarning | ||
| 15970 | { $_[0]->{clockWarning} } | ||
| 15971 | |||
| 15972 | sub stopEffect | ||
| 15973 | { $_[0]->{stopEffect} } | ||
| 15974 | sub warningEffect | ||
| 15975 | { $_[0]->{warningEffect} } | ||
| 15976 | } | ||
| 15977 | |||
| 15978 | { package Games::Axmud::Task::Divert; | ||
| 15979 | |||
| 15980 | use strict; | ||
| 15981 | use warnings; | ||
| 15982 | # use diagnostics; | ||
| 15983 | |||
| 15984 | use Glib qw(TRUE FALSE); | ||
| 15985 | |||
| 15986 | our @ISA = qw(Games::Axmud::Generic::Task Games::Axmud); | ||
| 15987 | |||
| 15988 | ################## | ||
| 15989 | # Constructors | ||
| 15990 | |||
| 15991 | sub new { | ||
| 15992 | |||
| 15993 | # Creates a new instances of the Divert task | ||
| 15994 | # | ||
| 15995 | # Expected arguments | ||
| 15996 | # $session - The parent GA::Session (not stored as an IV) | ||
| 15997 | # | ||
| 15998 | # Optional arguments | ||
| 15999 | # $taskType - Which tasklist this task is being created into - 'current' for the current | ||
| 16000 | # tasklist (tasks which are actually running now), 'initial' (tasks which | ||
| 16001 | # should be run when the user connects to the world), 'custom' (tasks with | ||
| 16002 | # customised initial parameters, which are run when the user demands). If | ||
| 16003 | # set to 'undef', this is a temporary task, created in order to access the | ||
| 16004 | # default values stored in IVs, that will not be added to any tasklist | ||
| 16005 | # $profName - ($taskType = 'current', when called by $self->clone) Name of the | ||
| 16006 | # profile from whose initial tasklist this task was created ('undef' if | ||
| 16007 | # none) | ||
| 16008 | # - ($taskType = 'initial') name of the profile in whose initial tasklist this | ||
| 16009 | # task will be. If 'undef', the global initial tasklist is used | ||
| 16010 | # - ($taskType = 'custom') 'undef' | ||
| 16011 | # $profCategory | ||
| 16012 | # - ($taskType = 'current', 'initial') which category the profile falls undef | ||
| 16013 | # (i.e. 'world', 'race', 'char', etc, or 'undef' if no profile) | ||
| 16014 | # - ($taskType = 'custom') 'undef' | ||
| 16015 | # $customName | ||
| 16016 | # - ($taskType = 'current', 'initial') 'undef' | ||
| 16017 | # - ($taskType = 'custom') the custom task name, matching a key in | ||
| 16018 | # GA::Session->customTaskHash | ||
| 16019 | # | ||
| 16020 | # Return values | ||
| 16021 | # 'undef' on improper arguments or if the task can't be added to the specified tasklist | ||
| 16022 | # Blessed reference to the newly-created object on success | ||
| 16023 | |||
| 16024 | my ($class, $session, $taskType, $profName, $profCategory, $customName, $check) = @_; | ||
| 16025 | |||
| 16026 | # Check for improper arguments | ||
| 16027 | if (! defined $class || ! defined $session || defined $check) { | ||
| 16028 | |||
| 16029 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 16030 | } | ||
| 16031 | |||
| 16032 | if ($taskType) { | ||
| 16033 | |||
| 16034 | # For initial tasks, check that $profName exists | ||
| 16035 | if ( | ||
| 16036 | $taskType eq 'initial' | ||
| 16037 | && defined $profName | ||
| 16038 | && ! $session->ivExists('profHash', $profName) | ||
| 16039 | ) { | ||
| 16040 | return $session->writeError( | ||
| 16041 | 'Can\'t create new task because \'' . $profName . '\' profile doesn\'t exist', | ||
| 16042 | $class . '->new', | ||
| 16043 | ); | ||
| 16044 | |||
| 16045 | # For custom tasks, check that $customName doesn't already exist | ||
| 16046 | } elsif ( | ||
| 16047 | $taskType eq 'custom' | ||
| 16048 | && $axmud::CLIENT->ivExists('customTaskHash', $customName) | ||
| 16049 | ) { | ||
| 16050 | return $session->writeError( | ||
| 16051 | 'Can\'t create new custom task because \'' . $customName . '\' is already being' | ||
| 16052 | . ' used', | ||
| 16053 | $class . '->new', | ||
| 16054 | ); | ||
| 16055 | |||
| 16056 | } elsif ($taskType ne 'current' && $taskType ne 'initial' && $taskType ne 'custom') { | ||
| 16057 | |||
| 16058 | return $session->writeError( | ||
| 16059 | 'Can\'t create new task because \'' . $taskType . '\' is an invalid tasklist', | ||
| 16060 | $class . '->new', | ||
| 16061 | ); | ||
| 16062 | } | ||
| 16063 | } | ||
| 16064 | |||
| 16065 | # Task settings | ||
| 16066 | my $self = Games::Axmud::Generic::Task->new( | ||
| 16067 | $session, | ||
| 16068 | $taskType, | ||
| 16069 | $profName, | ||
| 16070 | $profCategory, | ||
| 16071 | $customName, | ||
| 16072 | ); | ||
| 16073 | |||
| 16074 | $self->{_objName} = 'divert_task'; | ||
| 16075 | $self->{_objClass} = $class; | ||
| 16076 | $self->{_parentFile} = undef; # Set below | ||
| 16077 | $self->{_parentWorld} = undef; # Set below | ||
| 16078 | $self->{_privFlag} = TRUE, # All IVs are private | ||
| 16079 | |||
| 16080 | $self->{name} = 'divert_task'; | ||
| 16081 | $self->{prettyName} = 'Divert'; | ||
| 16082 | $self->{shortName} = 'Dv'; | ||
| 16083 | $self->{shortCutIV} = 'divertTask'; # Axmud built-in jealous task | ||
| 16084 | |||
| 16085 | $self->{category} = 'process'; | ||
| 16086 | $self->{descrip} = 'Diverts text received from the world to a task window'; | ||
| 16087 | $self->{jealousyFlag} = TRUE; | ||
| 16088 | $self->{requireLocatorFlag} = FALSE; | ||
| 16089 | $self->{profSensitivityFlag} = TRUE; | ||
| 16090 | $self->{storableFlag} = TRUE; | ||
| 16091 | $self->{delayTime} = 0; | ||
| 16092 | $self->{allowWinFlag} = TRUE; | ||
| 16093 | # v1.3.111 - in blind mode, no window appears (but TTS is still available) | ||
| 16094 | $self->{requireWinFlag} = FALSE; | ||
| 16095 | $self->{startWithWinFlag} = TRUE; | ||
| 16096 | $self->{winPreferList} = ['entry', 'grid']; | ||
| 16097 | $self->{winmap} = 'entry_fill'; | ||
| 16098 | $self->{winUpdateFunc} = 'restoreWin'; | ||
| 16099 | $self->{tabMode} = 'simple'; | ||
| 16100 | $self->{monochromeFlag} = TRUE; | ||
| 16101 | $self->{noScrollFlag} = FALSE; | ||
| 16102 | $self->{ttsFlag} = TRUE; | ||
| 16103 | $self->{ttsConfig} = 'divert'; | ||
| 16104 | $self->{ttsAttribHash} = {}; | ||
| 16105 | $self->{ttsFlagAttribHash} = { | ||
| 16106 | 'divert' => FALSE, | ||
| 16107 | 'tell' => FALSE, | ||
| 16108 | 'social' => FALSE, | ||
| 16109 | 'custom' => FALSE, | ||
| 16110 | 'warning' => FALSE, | ||
| 16111 | }; | ||
| 16112 | $self->{ttsAlertAttribHash} = {}; | ||
| 16113 | $self->{status} = 'wait_init'; | ||
| 16114 | # $self->{activeFlag} = TRUE; # Task can't be activated/disactivated | ||
| 16115 | |||
| 16116 | # Task parameters | ||
| 16117 | # | ||
| 16118 | # The normal background colour for the window (set when the window is enabled) - set to one | ||
| 16119 | # of Axmud's standard colour tags or 'undef' to use the default colour | ||
| 16120 | $self->{defaultColour} = undef; | ||
| 16121 | # When some text is diverted to the task window, the window's background colour changes. | ||
| 16122 | # The colour depends on the channel. The channels 'tell', 'social', 'custom' and 'warning' | ||
| 16123 | # have a colour assigned to them; all other channels share the same colour | ||
| 16124 | # The IVs are set to an Axmud colour tag. Any non-underlay tag can be used, but the task's | ||
| 16125 | # edit window only shows standard colour tags like 'blue' and 'RED' | ||
| 16126 | # The colour to use for the 'tell' channel | ||
| 16127 | $self->{tellAlertColour} = 'YELLOW'; | ||
| 16128 | # The colour to use for the 'social' channel | ||
| 16129 | $self->{socialAlertColour} = 'BLUE'; | ||
| 16130 | # The colour to use for the 'custom' channel | ||
| 16131 | $self->{customAlertColour} = 'cyan'; | ||
| 16132 | # The colour to use for the 'warning' channel | ||
| 16133 | $self->{warningAlertColour} = 'RED', | ||
| 16134 | # The colour to use for all other channels | ||
| 16135 | $self->{otherAlertColour} = 'magenta', | ||
| 16136 | |||
| 16137 | # When diverted text is received, how many seconds to use the alert colour | ||
| 16138 | $self->{tellAlertInterval} = 10; | ||
| 16139 | $self->{socialAlertInterval} = 3; | ||
| 16140 | $self->{customAlertInterval} = 3; | ||
| 16141 | $self->{warningAlertInterval} = 10; | ||
| 16142 | $self->{otherAlertInterval} = 10; | ||
| 16143 | |||
| 16144 | # Which sound effects are played when diverted text is received. The value should be | ||
| 16145 | # one of the keys in GA::Client->customSoundHash; if the value is 'undef', no sound effect | ||
| 16146 | # is played | ||
| 16147 | $self->{tellAlertSound} = 'greeting'; | ||
| 16148 | $self->{socialAlertSound} = 'notify'; | ||
| 16149 | $self->{customAlertSound} = 'notify'; | ||
| 16150 | $self->{warningAlertSound} = 'alarm'; | ||
| 16151 | $self->{otherAlertSound} = 'notify'; | ||
| 16152 | |||
| 16153 | # Limits to the amount of text displayed in the task window. If set to 0, the whole matching | ||
| 16154 | # line is displayed. Otherwise, the first n characters are displayed | ||
| 16155 | $self->{tellCharLimit} = 0; | ||
| 16156 | $self->{socialCharLimit} = 0; | ||
| 16157 | $self->{customCharLimit} = 0; | ||
| 16158 | $self->{warningCharLimit} = 0; | ||
| 16159 | $self->{otherCharLimit} = 0; | ||
| 16160 | |||
| 16161 | # Flags which, if set to TRUE, cause the automapper object's current room to be displayed | ||
| 16162 | # when a tell, social or custom alert occurs. (If the automapper's current room isn't set, | ||
| 16163 | # nothing extra is displayed) | ||
| 16164 | $self->{tellRoomFlag} = FALSE; | ||
| 16165 | $self->{socialRoomFlag} = FALSE; | ||
| 16166 | $self->{customRoomFlag} = FALSE; | ||
| 16167 | $self->{warningRoomFlag} = FALSE; | ||
| 16168 | $self->{otherRoomFlag} = FALSE; | ||
| 16169 | |||
| 16170 | # Flags which, if set to TRUE, cause the task window's urgency hint to be set when text is | ||
| 16171 | # diverted (might not work in all desktop environments) | ||
| 16172 | $self->{tellUrgencyFlag} = FALSE; | ||
| 16173 | $self->{socialUrgencyFlag} = FALSE; | ||
| 16174 | $self->{customUrgencyFlag} = FALSE; | ||
| 16175 | $self->{warningUrgencyFlag} = FALSE; | ||
| 16176 | $self->{otherUrgencyFlag} = FALSE; | ||
| 16177 | |||
| 16178 | # When diverted text is received, the time (matching GA::Session->sessionTime) at which the | ||
| 16179 | # alert background colour should be replaced by the default background colour . Usually | ||
| 16180 | # set to 'undef', which means the default background colour is visible | ||
| 16181 | $self->{resetTime} = undef; | ||
| 16182 | # Flag set to TRUE the first time diverted text is received (set to FALSE if no diverted | ||
| 16183 | # text has been received) | ||
| 16184 | $self->{firstTextFlag} = FALSE; | ||
| 16185 | # Multiple triggers can match a single line, but this task only displays a single line in | ||
| 16186 | # its task window once. The display buffer line number of the last line that matched a | ||
| 16187 | # tell, social or custom pattern | ||
| 16188 | $self->{lastLine} = 0; | ||
| 16189 | # A short string written to the task window, in front of any text typed by the user (to make | ||
| 16190 | # clear what was typed by whom) | ||
| 16191 | $self->{responseString} = '=> '; | ||
| 16192 | # A list of all lines displayed in the window so that, if the window is closed when text is | ||
| 16193 | # visible in it, when the window is opened they'll be ready for the user to see | ||
| 16194 | $self->{lineList} = []; | ||
| 16195 | |||
| 16196 | # Bless task | ||
| 16197 | bless $self, $class; | ||
| 16198 | |||
| 16199 | # For all tasks that aren't temporary... | ||
| 16200 | if ($taskType) { | ||
| 16201 | |||
| 16202 | # Check that the task doesn't belong to a disabled plugin (in which case, it can't be | ||
| 16203 | # added to any current, initial or custom tasklist) | ||
| 16204 | if (! $self->checkPlugins()) { | ||
| 16205 | |||
| 16206 | return undef; | ||
| 16207 | } | ||
| 16208 | |||
| 16209 | # Set the parent file object | ||
| 16210 | $self->setParentFileObj($session, $taskType, $profName, $profCategory); | ||
| 16211 | |||
| 16212 | # Create entries in tasklists, if possible | ||
| 16213 | if (! $self->updateTaskLists($session)) { | ||
| 16214 | |||
| 16215 | return undef; | ||
| 16216 | } | ||
| 16217 | } | ||
| 16218 | |||
| 16219 | # Task creation complete | ||
| 16220 | return $self; | ||
| 16221 | } | ||
| 16222 | |||
| 16223 | sub clone { | ||
| 16224 | |||
| 16225 | # Create a clone of an existing task | ||
| 16226 | # Usually used upon connection to a world, when every task in the initial tasklists must | ||
| 16227 | # be cloned into a new object, representing a task in the current tasklist | ||
| 16228 | # (Also used when cloning a profile object, since all the tasks in its initial tasklist must | ||
| 16229 | # also be cloned) | ||
| 16230 | # | ||
| 16231 | # Expected arguments | ||
| 16232 | # $session - The parent GA::Session (not stored as an IV) | ||
| 16233 | # $taskType - Which tasklist this task is being created into - 'current' for the current | ||
| 16234 | # tasklist (tasks which are actually running now), 'initial' (tasks which | ||
| 16235 | # should be run when the user connects to the world). Custom tasks aren't | ||
| 16236 | # cloned (at the moment) | ||
| 16237 | # | ||
| 16238 | # Optional arguments | ||
| 16239 | # $profName - ($taskType = 'initial') name of the profile in whose initial tasklist the | ||
| 16240 | # existing task is stored | ||
| 16241 | # $profCategory | ||
| 16242 | # - ($taskType = 'initial') which category the profile falls under (i.e. | ||
| 16243 | # 'world', 'race', 'char', etc) | ||
| 16244 | # | ||
| 16245 | # Return values | ||
| 16246 | # 'undef' on improper arguments or if the task can't be cloned | ||
| 16247 | # Blessed reference to the newly-created object on success | ||
| 16248 | |||
| 16249 | my ($self, $session, $taskType, $profName, $profCategory, $check) = @_; | ||
| 16250 | |||
| 16251 | # Check for improper arguments | ||
| 16252 | if ( | ||
| 16253 | ! defined $session || ! defined $taskType || defined $check | ||
| 16254 | || ($taskType ne 'current' && $taskType ne 'initial') | ||
| 16255 | || ($taskType eq 'initial' && (! defined $profName || ! defined $profCategory)) | ||
| 16256 | ) { | ||
| 16257 | return $axmud::CLIENT->writeImproper($self->_objClass . '->clone', @_); | ||
| 16258 | } | ||
| 16259 | |||
| 16260 | # For initial tasks, check that $profName exists | ||
| 16261 | if ( | ||
| 16262 | $taskType eq 'initial' | ||
| 16263 | && defined $profName | ||
| 16264 | && ! $session->ivExists('profHash', $profName) | ||
| 16265 | ) { | ||
| 16266 | return $axmud::CLIENT->writeError( | ||
| 16267 | 'Can\'t create cloned task because \'' . $profName . '\' profile doesn\'t exist', | ||
| 16268 | $self->_objClass . '->clone', | ||
| 16269 | ); | ||
| 16270 | } | ||
| 16271 | |||
| 16272 | # Check that the task doesn't belong to a disabled plugin (in which case, it can't be | ||
| 16273 | # cloned) | ||
| 16274 | if (! $self->checkPlugins()) { | ||
| 16275 | |||
| 16276 | return undef; | ||
| 16277 | } | ||
| 16278 | |||
| 16279 | # Create the new task, using default settings and parameters | ||
| 16280 | my $clone = $self->_objClass->new($session, $taskType, $profName, $profCategory); | ||
| 16281 | |||
| 16282 | # Most of the cloned task's settings have default values, but a few are copied from the | ||
| 16283 | # original | ||
| 16284 | $self->cloneTaskSettings($clone); | ||
| 16285 | |||
| 16286 | # Give the new (cloned) task the same initial parameters as the original one | ||
| 16287 | $clone->{defaultColour} = $self->defaultColour; | ||
| 16288 | $clone->{tellAlertColour} = $self->tellAlertColour; | ||
| 16289 | $clone->{socialAlertColour} = $self->socialAlertColour; | ||
| 16290 | $clone->{customAlertColour} = $self->customAlertColour; | ||
| 16291 | $clone->{warningAlertColour} = $self->warningAlertColour; | ||
| 16292 | $clone->{otherAlertColour} = $self->otherAlertColour; | ||
| 16293 | |||
| 16294 | $clone->{tellAlertInterval} = $self->tellAlertInterval; | ||
| 16295 | $clone->{socialAlertInterval} = $self->socialAlertInterval; | ||
| 16296 | $clone->{customAlertInterval} = $self->customAlertInterval; | ||
| 16297 | $clone->{warningAlertInterval} = $self->warningAlertInterval; | ||
| 16298 | $clone->{otherAlertInterval} = $self->otherAlertInterval; | ||
| 16299 | |||
| 16300 | $clone->{tellAlertSound} = $self->tellAlertSound; | ||
| 16301 | $clone->{socialAlertSound} = $self->socialAlertSound; | ||
| 16302 | $clone->{customAlertSound} = $self->customAlertSound; | ||
| 16303 | $clone->{warningAlertSound} = $self->warningAlertSound; | ||
| 16304 | $clone->{otherAlertSound} = $self->otherAlertSound; | ||
| 16305 | |||
| 16306 | $clone->{tellCharLimit} = $self->tellCharLimit; | ||
| 16307 | $clone->{socialCharLimit} = $self->socialCharLimit; | ||
| 16308 | $clone->{customCharLimit} = $self->customCharLimit; | ||
| 16309 | $clone->{warningCharLimit} = $self->warningCharLimit; | ||
| 16310 | $clone->{otherCharLimit} = $self->otherCharLimit; | ||
| 16311 | |||
| 16312 | $clone->{tellRoomFlag} = $self->tellRoomFlag; | ||
| 16313 | $clone->{socialRoomFlag} = $self->socialRoomFlag; | ||
| 16314 | $clone->{customRoomFlag} = $self->customRoomFlag; | ||
| 16315 | $clone->{warningRoomFlag} = $self->warningRoomFlag; | ||
| 16316 | $clone->{otherRoomFlag} = $self->otherRoomFlag; | ||
| 16317 | |||
| 16318 | $clone->{tellUrgencyFlag} = $self->tellUrgencyFlag; | ||
| 16319 | $clone->{socialUrgencyFlag} = $self->socialUrgencyFlag; | ||
| 16320 | $clone->{customUrgencyFlag} = $self->customUrgencyFlag; | ||
| 16321 | $clone->{warningUrgencyFlag} = $self->warningUrgencyFlag; | ||
| 16322 | $clone->{otherUrgencyFlag} = $self->otherUrgencyFlag; | ||
| 16323 | |||
| 16324 | $clone->{resetTime} = $self->resetTime; | ||
| 16325 | $clone->{firstTextFlag} = $self->firstTextFlag; | ||
| 16326 | $clone->{lastLine} = $self->lastLine; | ||
| 16327 | $clone->{responseString} = $self->responseString; | ||
| 16328 | |||
| 16329 | $clone->{lineList} = [$self->lineList]; | ||
| 16330 | |||
| 16331 | # Cloning complete | ||
| 16332 | return $clone; | ||
| 16333 | } | ||
| 16334 | |||
| 16335 | sub preserve { | ||
| 16336 | |||
| 16337 | # Called by $self->main whenever this task is reset, in order to preserve some if its task | ||
| 16338 | # parameters (but not necessarily all of them) | ||
| 16339 | # | ||
| 16340 | # Expected arguments | ||
| 16341 | # $newTask - The new task which has been created, to which some of this task's instance | ||
| 16342 | # variables might have to be transferred | ||
| 16343 | # | ||
| 16344 | # Return values | ||
| 16345 | # 'undef' on improper arguments, or if $newTask isn't in the GA::Session's current | ||
| 16346 | # tasklist | ||
| 16347 | # 1 on success | ||
| 16348 | |||
| 16349 | my ($self, $newTask, $check) = @_; | ||
| 16350 | |||
| 16351 | # Check for improper arguments | ||
| 16352 | if (! defined $newTask || defined $check) { | ||
| 16353 | |||
| 16354 | return $axmud::CLIENT->writeImproper($self->_objClass . '->preserve', @_); | ||
| 16355 | } | ||
| 16356 | |||
| 16357 | # Check the task is in the current tasklist | ||
| 16358 | if (! $self->session->ivExists('currentTaskHash', $newTask->uniqueName)) { | ||
| 16359 | |||
| 16360 | return $self->writeWarning( | ||
| 16361 | '\'' . $self->uniqueName . '\' task missing from the current tasklist', | ||
| 16362 | $self->_objClass . '->preserve', | ||
| 16363 | ); | ||
| 16364 | } | ||
| 16365 | |||
| 16366 | # Preserve some task parameters (the others are left with their default settings, some of | ||
| 16367 | # which will be re-initialised in stage 2) | ||
| 16368 | |||
| 16369 | # Preserve the default colour | ||
| 16370 | $newTask->ivPoke('defaultColour', $self->defaultColour); | ||
| 16371 | # Preserve the background colours | ||
| 16372 | $newTask->ivPoke('tellAlertColour', $self->tellAlertColour); | ||
| 16373 | $newTask->ivPoke('socialAlertColour', $self->socialAlertColour); | ||
| 16374 | $newTask->ivPoke('customAlertColour', $self->customAlertColour); | ||
| 16375 | $newTask->ivPoke('warningAlertColour', $self->warningAlertColour); | ||
| 16376 | $newTask->ivPoke('otherAlertColour', $self->otherAlertColour); | ||
| 16377 | # Preserve intervals before resetting the background colour | ||
| 16378 | $newTask->ivPoke('tellAlertInterval', $self->tellAlertInterval); | ||
| 16379 | $newTask->ivPoke('socialAlertInterval', $self->socialAlertInterval); | ||
| 16380 | $newTask->ivPoke('customAlertInterval', $self->customAlertInterval); | ||
| 16381 | $newTask->ivPoke('warningAlertInterval', $self->warningAlertInterval); | ||
| 16382 | $newTask->ivPoke('otherAlertInterval', $self->otherAlertInterval); | ||
| 16383 | # Preserve sound effects | ||
| 16384 | $newTask->ivPoke('tellAlertSound', $self->tellAlertSound); | ||
| 16385 | $newTask->ivPoke('socialAlertSound', $self->socialAlertSound); | ||
| 16386 | $newTask->ivPoke('customAlertSound', $self->customAlertSound); | ||
| 16387 | $newTask->ivPoke('warningAlertSound', $self->warningAlertSound); | ||
| 16388 | $newTask->ivPoke('otherAlertSound', $self->otherAlertSound); | ||
| 16389 | # Preserve character limits | ||
| 16390 | $newTask->ivPoke('tellCharLimit', $self->tellCharLimit); | ||
| 16391 | $newTask->ivPoke('socialCharLimit', $self->socialCharLimit); | ||
| 16392 | $newTask->ivPoke('customCharLimit', $self->customCharLimit); | ||
| 16393 | $newTask->ivPoke('warningCharLimit', $self->warningCharLimit); | ||
| 16394 | $newTask->ivPoke('otherCharLimit', $self->otherCharLimit); | ||
| 16395 | # Preserve room flags | ||
| 16396 | $newTask->ivPoke('tellRoomFlag', $self->tellRoomFlag); | ||
| 16397 | $newTask->ivPoke('socialRoomFlag', $self->socialRoomFlag); | ||
| 16398 | $newTask->ivPoke('customRoomFlag', $self->customRoomFlag); | ||
| 16399 | $newTask->ivPoke('warningRoomFlag', $self->warningRoomFlag); | ||
| 16400 | $newTask->ivPoke('otherRoomFlag', $self->otherRoomFlag); | ||
| 16401 | # Preserve urgency hint flags | ||
| 16402 | $newTask->ivPoke('tellUrgencyFlag', $self->tellUrgencyFlag); | ||
| 16403 | $newTask->ivPoke('socialUrgencyFlag', $self->socialUrgencyFlag); | ||
| 16404 | $newTask->ivPoke('customUrgencyFlag', $self->customUrgencyFlag); | ||
| 16405 | $newTask->ivPoke('warningUrgencyFlag', $self->warningUrgencyFlag); | ||
| 16406 | $newTask->ivPoke('otherUrgencyFlag', $self->otherUrgencyFlag); | ||
| 16407 | |||
| 16408 | return 1; | ||
| 16409 | } | ||
| 16410 | |||
| 16411 | # sub setParentFileObj {} # Inherited from generic task | ||
| 16412 | |||
| 16413 | # sub updateTaskLists {} # Inherited from generic task | ||
| 16414 | |||
| 16415 | # sub ttsReadAttrib {} # Inherited from generic task | ||
| 16416 | |||
| 16417 | sub ttsSwitchFlagAttrib { | ||
| 16418 | |||
| 16419 | # Called by GA::Cmd::Switch->do and PermSwitch->do | ||
| 16420 | # Users can use the client command ';switch' to interact with individual tasks, typically | ||
| 16421 | # telling them to turn on/off the automatic reading out of information (e.g. the Locator | ||
| 16422 | # task can be told to start or stop reading out room titles as they are received from | ||
| 16423 | # the world) | ||
| 16424 | # The ';switch' command is in the form ';switch <flag_attribute>'. The ';switch' command | ||
| 16425 | # looks up the <flag_attribute> (which is a string, not a TRUE/FALSE value) in | ||
| 16426 | # GA::Client->ttsFlagAttribHash, which tells it which task to call | ||
| 16427 | # | ||
| 16428 | # Expected arguments | ||
| 16429 | # $flagAttrib - The TTS flag attribute specified by the calling function. Must be one of | ||
| 16430 | # the keys in $self->ttsFlagAttribHash | ||
| 16431 | # | ||
| 16432 | # Optional arguments | ||
| 16433 | # $noSpecialFlag | ||
| 16434 | # - Set to TRUE when called by GA::Cmd::PermSwitch->do, in which case only | ||
| 16435 | # this task's hash of flag attributes is updated. Otherwise set to FALSE | ||
| 16436 | # (or 'undef'), in which case other things can happen when a flag | ||
| 16437 | # attribute is switched. For all built-in tasks, there is no difference | ||
| 16438 | # in behaviour | ||
| 16439 | # | ||
| 16440 | # Return values | ||
| 16441 | # 'undef' on improper arguments or if the $flagAttrib doesn't exist in this task's | ||
| 16442 | # ->ttsFlagAttribHash | ||
| 16443 | # Otherwise returns a confirmation message for the calling function to display | ||
| 16444 | |||
| 16445 | my ($self, $flagAttrib, $noSpecialFlag, $check) = @_; | ||
| 16446 | |||
| 16447 | # Local variables | ||
| 16448 | my $msg; | ||
| 16449 | |||
| 16450 | # Check for improper arguments | ||
| 16451 | if (! defined $flagAttrib || defined $check) { | ||
| 16452 | |||
| 16453 | return $axmud::CLIENT->writeImproper($self->_objClass . '->ttsSwitchFlagAttrib', @_); | ||
| 16454 | } | ||
| 16455 | |||
| 16456 | # TTS flag attributes are case-insensitive | ||
| 16457 | $flagAttrib = lc($flagAttrib); | ||
| 16458 | |||
| 16459 | # Check that the specified attribute flag is actually used by this task (';switch' should | ||
| 16460 | # carry out this check, but better safe than sorry) | ||
| 16461 | if (! $self->ivExists('ttsFlagAttribHash', $flagAttrib)) { | ||
| 16462 | |||
| 16463 | return undef; | ||
| 16464 | |||
| 16465 | } else { | ||
| 16466 | |||
| 16467 | # If a current task performs some kind of action, when a flag attribute is switched, | ||
| 16468 | # the code for the action should be placed here. (Tasks in the global initial | ||
| 16469 | # tasklist can't perform an action, of course.) | ||
| 16470 | if (! $noSpecialFlag) { | ||
| 16471 | |||
| 16472 | # (no actions to perform) | ||
| 16473 | } | ||
| 16474 | |||
| 16475 | $msg = '\'' . $self->prettyName . '\' flag attribute \'' . $flagAttrib | ||
| 16476 | . '\' switched to '; | ||
| 16477 | |||
| 16478 | # One change from the generic ->ttsSwitchFlagAttrib function: if the 'divert' attribute | ||
| 16479 | # is switched on/off, switch the other four attributes on/off, too | ||
| 16480 | if ($flagAttrib eq 'divert') { | ||
| 16481 | |||
| 16482 | if ($self->ivShow('ttsFlagAttribHash', 'divert')) { | ||
| 16483 | |||
| 16484 | $self->ivAdd('ttsFlagAttribHash', 'divert', FALSE); | ||
| 16485 | $self->ivAdd('ttsFlagAttribHash', 'tell', FALSE); | ||
| 16486 | $self->ivAdd('ttsFlagAttribHash', 'social', FALSE); | ||
| 16487 | $self->ivAdd('ttsFlagAttribHash', 'custom', FALSE); | ||
| 16488 | $self->ivAdd('ttsFlagAttribHash', 'warning', FALSE); | ||
| 16489 | $msg .= 'OFF'; | ||
| 16490 | |||
| 16491 | } else { | ||
| 16492 | |||
| 16493 | $self->ivAdd('ttsFlagAttribHash', 'divert', TRUE); | ||
| 16494 | $self->ivAdd('ttsFlagAttribHash', 'tell', TRUE); | ||
| 16495 | $self->ivAdd('ttsFlagAttribHash', 'social', TRUE); | ||
| 16496 | $self->ivAdd('ttsFlagAttribHash', 'custom', TRUE); | ||
| 16497 | $self->ivAdd('ttsFlagAttribHash', 'warning', TRUE); | ||
| 16498 | $msg .= 'ON'; | ||
| 16499 | } | ||
| 16500 | |||
| 16501 | } else { | ||
| 16502 | |||
| 16503 | if ($self->ivShow('ttsFlagAttribHash', $flagAttrib)) { | ||
| 16504 | |||
| 16505 | $self->ivAdd('ttsFlagAttribHash', $flagAttrib, FALSE); | ||
| 16506 | $msg .= 'OFF'; | ||
| 16507 | |||
| 16508 | } else { | ||
| 16509 | |||
| 16510 | $self->ivAdd('ttsFlagAttribHash', $flagAttrib, TRUE); | ||
| 16511 | $msg .= 'ON'; | ||
| 16512 | } | ||
| 16513 | } | ||
| 16514 | |||
| 16515 | return $msg; | ||
| 16516 | } | ||
| 16517 | } | ||
| 16518 | |||
| 16519 | # sub ttsSetAlertAttrib {} # Inherited from generic task | ||
| 16520 | |||
| 16521 | ################## | ||
| 16522 | # Task windows | ||
| 16523 | |||
| 16524 | # sub toggleWin {} # Inherited from generic task | ||
| 16525 | |||
| 16526 | # sub openWin {} # Inherited from generic task | ||
| 16527 | |||
| 16528 | # sub closeWin {} # Inherited from generic task | ||
| 16529 | |||
| 16530 | ################## | ||
| 16531 | # Methods | ||
| 16532 | |||
| 16533 | # sub main {} # Inherited from generic task | ||
| 16534 | |||
| 16535 | # sub doShutdown {} # Inherited from generic task | ||
| 16536 | |||
| 16537 | sub doReset { | ||
| 16538 | |||
| 16539 | # Called just before the task completes a reset | ||
| 16540 | # For process tasks, called by $self->main. For activity tasks, called by $self->reset | ||
| 16541 | # | ||
| 16542 | # Makes sure the task window is using the default background colour | ||
| 16543 | # | ||
| 16544 | # Expected arguments | ||
| 16545 | # $newTaskObj - The replacement task object | ||
| 16546 | # | ||
| 16547 | # Return values | ||
| 16548 | # 'undef' on improper arguments | ||
| 16549 | # 1 otherwise | ||
| 16550 | |||
| 16551 | my ($self, $newTaskObj, $check) = @_; | ||
| 16552 | |||
| 16553 | # Check for improper arguments | ||
| 16554 | if (! defined $newTaskObj || defined $check) { | ||
| 16555 | |||
| 16556 | return $axmud::CLIENT->writeImproper($self->_objClass . '->doReset', @_); | ||
| 16557 | } | ||
| 16558 | |||
| 16559 | # In case the task window is currently a different colour when the task is reset, set it | ||
| 16560 | # back to the default colour | ||
| 16561 | if ($self->defaultTabObj) { | ||
| 16562 | |||
| 16563 | $self->defaultTabObj->paneObj->applyMonochrome( | ||
| 16564 | $self->defaultTabObj, | ||
| 16565 | $self->defaultColour, | ||
| 16566 | ); | ||
| 16567 | } | ||
| 16568 | |||
| 16569 | return 1; | ||
| 16570 | } | ||
| 16571 | |||
| 16572 | sub doFirstStage { | ||
| 16573 | |||
| 16574 | # Called by $self->main, just before the task completes the first stage ($self->stage) | ||
| 16575 | # | ||
| 16576 | # Expected arguments | ||
| 16577 | # (none besides $self) | ||
| 16578 | # | ||
| 16579 | # Return values | ||
| 16580 | # 'undef' on improper arguments | ||
| 16581 | # 1 otherwise | ||
| 16582 | |||
| 16583 | my ($self, $check) = @_; | ||
| 16584 | |||
| 16585 | # Check for improper arguments | ||
| 16586 | if (defined $check) { | ||
| 16587 | |||
| 16588 | return $axmud::CLIENT->writeImproper($self->_objClass . '->doFirstStage', @_); | ||
| 16589 | } | ||
| 16590 | |||
| 16591 | if ($self->session->channelsTask) { | ||
| 16592 | |||
| 16593 | $self->writeError( | ||
| 16594 | 'The Channels and Divert tasks cannot run at the same time, so halting the' | ||
| 16595 | . ' Divert task', | ||
| 16596 | $self->_objClass . '->doStage', | ||
| 16597 | ); | ||
| 16598 | |||
| 16599 | # Mark the task to be shutdown | ||
| 16600 | $self->ivPoke('shutdownFlag', TRUE); | ||
| 16601 | return undef; | ||
| 16602 | } | ||
| 16603 | } | ||
| 16604 | |||
| 16605 | sub doStage { | ||
| 16606 | |||
| 16607 | # Called by $self->main to process all stages (except stage 1) | ||
| 16608 | # | ||
| 16609 | # Expected arguments | ||
| 16610 | # (none besides $self) | ||
| 16611 | # | ||
| 16612 | # Return values | ||
| 16613 | # 'undef' on improper arguments or if this function sets that task's ->status IV to | ||
| 16614 | # 'finished' or sets its ->shutdownFlag to TRUE | ||
| 16615 | # Otherwise, we normally return the new value of $self->stage | ||
| 16616 | |||
| 16617 | my ($self, $check) = @_; | ||
| 16618 | |||
| 16619 | # Check for improper arguments | ||
| 16620 | if (defined $check) { | ||
| 16621 | |||
| 16622 | return $axmud::CLIENT->writeImproper($self->_objClass . '->doStage', @_); | ||
| 16623 | } | ||
| 16624 | |||
| 16625 | if ($self->stage == 2) { | ||
| 16626 | |||
| 16627 | # Create dependent triggers for patterns defined by the current world profile | ||
| 16628 | if (! $self->resetTriggers()) { | ||
| 16629 | |||
| 16630 | $self->writeError( | ||
| 16631 | 'Could not create ' . $self->prettyName . ' task triggers, so halting the task', | ||
| 16632 | $self->_objClass . '->doStage', | ||
| 16633 | ); | ||
| 16634 | |||
| 16635 | # Mark the task to be shutdown | ||
| 16636 | $self->ivPoke('shutdownFlag', TRUE); | ||
| 16637 | return undef; | ||
| 16638 | } | ||
| 16639 | |||
| 16640 | return $self->ivPoke('stage', 3); | ||
| 16641 | |||
| 16642 | } elsif ($self->stage == 3) { | ||
| 16643 | |||
| 16644 | if (defined $self->resetTime && $self->resetTime <= $self->session->sessionTime) { | ||
| 16645 | |||
| 16646 | if ($self->defaultTabObj) { | ||
| 16647 | |||
| 16648 | # The delay, started the last time some diverted text was received, is over. | ||
| 16649 | # Revert the task window to its original background colour | ||
| 16650 | $self->defaultTabObj->paneObj->applyMonochrome( | ||
| 16651 | $self->defaultTabObj, | ||
| 16652 | $self->defaultColour, | ||
| 16653 | ); | ||
| 16654 | } | ||
| 16655 | |||
| 16656 | $self->ivPoke('resetTime', undef); | ||
| 16657 | } | ||
| 16658 | |||
| 16659 | # Repeat this stage indefinitely | ||
| 16660 | return $self->ivPoke('stage', 3); | ||
| 16661 | |||
| 16662 | } else { | ||
| 16663 | |||
| 16664 | # The task stage has somehow been set to an invalid value | ||
| 16665 | return $self->invalidStage(); | ||
| 16666 | } | ||
| 16667 | } | ||
| 16668 | |||
| 16669 | sub resetTriggers { | ||
| 16670 | |||
| 16671 | # Called by $self->doStage, GA::Cmd::AddChannelPattern->do and | ||
| 16672 | # GA::Cmd::DeleteChannelPattern->do | ||
| 16673 | # Removes all of this task's dependent triggers and replaces them with new ones | ||
| 16674 | # | ||
| 16675 | # Expected arguments | ||
| 16676 | # (none besides $self) | ||
| 16677 | # | ||
| 16678 | # Return values | ||
| 16679 | # 'undef' on improper arguments, or if there's an error replacing or creating the triggers | ||
| 16680 | # 1 otherwise | ||
| 16681 | |||
| 16682 | my ($self, $check) = @_; | ||
| 16683 | |||
| 16684 | # Local variables | ||
| 16685 | my @channelList; | ||
| 16686 | |||
| 16687 | # Check for improper arguments | ||
| 16688 | if (defined $check) { | ||
| 16689 | |||
| 16690 | return $axmud::CLIENT->writeImproper($self->_objClass . '->resetTriggers', @_); | ||
| 16691 | } | ||
| 16692 | |||
| 16693 | # First remove any existing triggers. ->tidyInterfaces returns the number of triggers | ||
| 16694 | # removed, or 'undef' it there's an error | ||
| 16695 | if (! defined $self->session->tidyInterfaces($self)) { | ||
| 16696 | |||
| 16697 | return undef; | ||
| 16698 | } | ||
| 16699 | |||
| 16700 | # Import the list of patterns (groups of 3) | ||
| 16701 | @channelList = $self->session->currentWorld->channelList; | ||
| 16702 | if (@channelList) { | ||
| 16703 | |||
| 16704 | do { | ||
| 16705 | |||
| 16706 | my ($pattern, $channel, $flag, $interfaceObj); | ||
| 16707 | |||
| 16708 | $pattern = shift @channelList; | ||
| 16709 | $channel = shift @channelList; | ||
| 16710 | $flag = shift @channelList; | ||
| 16711 | |||
| 16712 | # Create dependent trigger | ||
| 16713 | $interfaceObj = $self->session->createDependentInterface( | ||
| 16714 | 'trigger', | ||
| 16715 | $pattern, | ||
| 16716 | $self, | ||
| 16717 | 'divertPatternSeen', | ||
| 16718 | 'gag', | ||
| 16719 | $flag, | ||
| 16720 | ); | ||
| 16721 | |||
| 16722 | if (! $interfaceObj) { | ||
| 16723 | |||
| 16724 | # If there's an error creating any triggers, remove any triggers already created | ||
| 16725 | $self->session->tidyInterfaces($self); | ||
| 16726 | return undef; | ||
| 16727 | |||
| 16728 | } else { | ||
| 16729 | |||
| 16730 | # Give the trigger some properties that will tell $self->divertPatternSeen which | ||
| 16731 | # channel to use when the trigger fires | ||
| 16732 | $interfaceObj->ivAdd('propertyHash', 'channel', $channel); | ||
| 16733 | } | ||
| 16734 | |||
| 16735 | } until (! @channelList); | ||
| 16736 | } | ||
| 16737 | |||
| 16738 | return 1; | ||
| 16739 | } | ||
| 16740 | |||
| 16741 | sub displayText { | ||
| 16742 | |||
| 16743 | # Called by $self->divertPatternSeen and ->displayWarning (only) to display text in the task | ||
| 16744 | # window | ||
| 16745 | # | ||
| 16746 | # Expected arguments | ||
| 16747 | # $channel - The channel name, e.g. 'tell', 'social', 'custom', 'warning' | ||
| 16748 | # | ||
| 16749 | # Optional arguments | ||
| 16750 | # $text - The text to display. If 'undef', no text is displayed in the task window, | ||
| 16751 | # but the background colour is still changed | ||
| 16752 | # $stripLine - The original line of text received from the world (after escape sequences | ||
| 16753 | # are removed); used for writing logs ('undef' for 'warning' messages) | ||
| 16754 | # | ||
| 16755 | # Return values | ||
| 16756 | # 'undef' on improper arguments or if the task window isn't open | ||
| 16757 | # 1 otherwise | ||
| 16758 | |||
| 16759 | my ($self, $channel, $text, $stripLine, $check) = @_; | ||
| 16760 | |||
| 16761 | # Local variables | ||
| 16762 | my ($time, $origText, $otherFlag); | ||
| 16763 | |||
| 16764 | # Check for improper arguments | ||
| 16765 | if (! defined $channel || defined $check) { | ||
| 16766 | |||
| 16767 | return $axmud::CLIENT->writeImproper($self->_objClass . '->displayText', @_); | ||
| 16768 | } | ||
| 16769 | |||
| 16770 | # Change the task window's background colour, and set the interval at which the colour | ||
| 16771 | # will revert back to the default colour | ||
| 16772 | # Also, play a sound (if allowed) and apply a size limit to the text (if a limit is set) | ||
| 16773 | if ($channel eq 'tell') { | ||
| 16774 | |||
| 16775 | if ($self->defaultTabObj) { | ||
| 16776 | |||
| 16777 | $time = $self->session->sessionTime + $self->tellAlertInterval; | ||
| 16778 | $self->defaultTabObj->paneObj->applyMonochrome( | ||
| 16779 | $self->defaultTabObj, | ||
| 16780 | $self->tellAlertColour, | ||
| 16781 | ); | ||
| 16782 | } | ||
| 16783 | |||
| 16784 | if ($self->tellAlertSound) { | ||
| 16785 | |||
| 16786 | $axmud::CLIENT->playSound($self->tellAlertSound); | ||
| 16787 | } | ||
| 16788 | |||
| 16789 | if ($self->tellCharLimit) { | ||
| 16790 | |||
| 16791 | $text = substr($text, 0, $self->tellCharLimit); | ||
| 16792 | } | ||
| 16793 | |||
| 16794 | } elsif ($channel eq 'social') { | ||
| 16795 | |||
| 16796 | if ($self->defaultTabObj) { | ||
| 16797 | |||
| 16798 | $time = $self->session->sessionTime + $self->socialAlertInterval; | ||
| 16799 | $self->defaultTabObj->paneObj->applyMonochrome( | ||
| 16800 | $self->defaultTabObj, | ||
| 16801 | $self->socialAlertColour, | ||
| 16802 | ); | ||
| 16803 | } | ||
| 16804 | |||
| 16805 | if ($self->socialAlertSound) { | ||
| 16806 | |||
| 16807 | $axmud::CLIENT->playSound($self->socialAlertSound); | ||
| 16808 | } | ||
| 16809 | |||
| 16810 | if ($self->socialCharLimit) { | ||
| 16811 | |||
| 16812 | $text = substr($text, 0, $self->socialCharLimit); | ||
| 16813 | } | ||
| 16814 | |||
| 16815 | } elsif ($channel eq 'custom') { | ||
| 16816 | |||
| 16817 | if ($self->defaultTabObj) { | ||
| 16818 | |||
| 16819 | $time = $self->session->sessionTime + $self->customAlertInterval; | ||
| 16820 | $self->defaultTabObj->paneObj->applyMonochrome( | ||
| 16821 | $self->defaultTabObj, | ||
| 16822 | $self->customAlertColour, | ||
| 16823 | ); | ||
| 16824 | } | ||
| 16825 | |||
| 16826 | if ($self->customAlertSound) { | ||
| 16827 | |||
| 16828 | $axmud::CLIENT->playSound($self->customAlertSound); | ||
| 16829 | } | ||
| 16830 | |||
| 16831 | if ($self->customCharLimit) { | ||
| 16832 | |||
| 16833 | $text = substr($text, 0, $self->customCharLimit); | ||
| 16834 | } | ||
| 16835 | |||
| 16836 | } elsif ($channel eq 'warning') { | ||
| 16837 | |||
| 16838 | if ($self->defaultTabObj) { | ||
| 16839 | |||
| 16840 | $time = $self->session->sessionTime + $self->warningAlertInterval; | ||
| 16841 | $self->defaultTabObj->paneObj->applyMonochrome( | ||
| 16842 | $self->defaultTabObj, | ||
| 16843 | $self->warningAlertColour, | ||
| 16844 | ); | ||
| 16845 | } | ||
| 16846 | |||
| 16847 | if ($self->warningAlertSound) { | ||
| 16848 | |||
| 16849 | $axmud::CLIENT->playSound($self->warningAlertSound); | ||
| 16850 | } | ||
| 16851 | |||
| 16852 | if ($self->warningCharLimit) { | ||
| 16853 | |||
| 16854 | $text = substr($text, 0, $self->warningCharLimit); | ||
| 16855 | } | ||
| 16856 | |||
| 16857 | } else { | ||
| 16858 | |||
| 16859 | $otherFlag = TRUE; | ||
| 16860 | |||
| 16861 | if ($self->defaultTabObj) { | ||
| 16862 | |||
| 16863 | $time = $self->session->sessionTime + $self->otherAlertInterval; | ||
| 16864 | $self->defaultTabObj->paneObj->applyMonochrome( | ||
| 16865 | $self->defaultTabObj, | ||
| 16866 | $self->otherAlertColour, | ||
| 16867 | ); | ||
| 16868 | } | ||
| 16869 | |||
| 16870 | if ($self->otherAlertSound) { | ||
| 16871 | |||
| 16872 | $axmud::CLIENT->playSound($self->otherAlertSound); | ||
| 16873 | } | ||
| 16874 | |||
| 16875 | if ($self->otherCharLimit) { | ||
| 16876 | |||
| 16877 | $text = substr($text, 0, $self->otherCharLimit); | ||
| 16878 | } | ||
| 16879 | } | ||
| 16880 | |||
| 16881 | if ($self->taskWinFlag) { | ||
| 16882 | |||
| 16883 | # (Different types of messages have different intervals; don't change the time at which | ||
| 16884 | # the window reverts if the new interval finishes before the existing one) | ||
| 16885 | if (! $self->resetTime || $self->resetTime < $time) { | ||
| 16886 | |||
| 16887 | $self->ivPoke('resetTime', $time); | ||
| 16888 | } | ||
| 16889 | } | ||
| 16890 | |||
| 16891 | # Preserve the original text, in case we convert the text to speech below | ||
| 16892 | $origText = $text; | ||
| 16893 | |||
| 16894 | # Add the automapper's current room, if allowed | ||
| 16895 | if ( | ||
| 16896 | $self->session->mapObj->currentRoom | ||
| 16897 | && ( | ||
| 16898 | ($channel eq 'tell' && $self->tellRoomFlag) | ||
| 16899 | || ($channel eq 'social' && $self->socialRoomFlag) | ||
| 16900 | || ($channel eq 'custom' && $self->customRoomFlag) | ||
| 16901 | || ($channel eq 'warning' && $self->warningRoomFlag) | ||
| 16902 | || ($otherFlag && $self->otherRoomFlag) | ||
| 16903 | ) | ||
| 16904 | ) { | ||
| 16905 | $text .= ' [Room #' . $self->session->mapObj->currentRoom->number . ']'; | ||
| 16906 | } | ||
| 16907 | |||
| 16908 | # Display the text (if there is any) | ||
| 16909 | if ($self->taskWinFlag && $text ne '') { | ||
| 16910 | |||
| 16911 | if (! $self->firstTextFlag) { | ||
| 16912 | |||
| 16913 | # This is the first text to be displayed in the task window; need to remove any | ||
| 16914 | # holding messages | ||
| 16915 | $self->insertWithLinks($text, 'empty'); | ||
| 16916 | $self->ivPoke('firstTextFlag', TRUE); | ||
| 16917 | |||
| 16918 | } else { | ||
| 16919 | |||
| 16920 | $self->insertWithLinks($text); | ||
| 16921 | } | ||
| 16922 | } | ||
| 16923 | |||
| 16924 | # If there are any Watch tasks running - in any session - update them | ||
| 16925 | foreach my $otherSession ($axmud::CLIENT->listSessions()) { | ||
| 16926 | |||
| 16927 | my ($world, $char); | ||
| 16928 | |||
| 16929 | if ($otherSession->watchTask) { | ||
| 16930 | |||
| 16931 | $world = $self->session->currentWorld->name; | ||
| 16932 | if ($self->session->currentChar) { | ||
| 16933 | |||
| 16934 | $char = $self->session->currentChar->name; # Otherwise 'undef' | ||
| 16935 | } | ||
| 16936 | |||
| 16937 | $otherSession->watchTask->displayText('divert', $world, $char, $text); | ||
| 16938 | } | ||
| 16939 | } | ||
| 16940 | |||
| 16941 | # Set the task window's urgency hint, if the appropriate flag is set | ||
| 16942 | if ($self->winObj) { | ||
| 16943 | |||
| 16944 | if ( | ||
| 16945 | ($channel eq 'tell' && $self->tellUrgencyFlag) | ||
| 16946 | || ($channel eq 'social' && $self->socialUrgencyFlag) | ||
| 16947 | || ($channel eq 'custom' && $self->customUrgencyFlag) | ||
| 16948 | || ($channel eq 'warning' && $self->warningUrgencyFlag) | ||
| 16949 | || ($otherFlag && $self->otherUrgencyFlag) | ||
| 16950 | ) { | ||
| 16951 | $self->winObj->setUrgent(); | ||
| 16952 | } | ||
| 16953 | } | ||
| 16954 | |||
| 16955 | # Also write the text to the logs, as if it had appeared in the 'main' window (if allowed) | ||
| 16956 | if (defined $stripLine && defined $origText) { | ||
| 16957 | |||
| 16958 | $self->session->writeIncomingDataLogs($stripLine, $origText); | ||
| 16959 | } | ||
| 16960 | |||
| 16961 | # Store the text in this list IV so that, if the window is closed and then re-opened, all | ||
| 16962 | # the lines of text (since the last use of ';emptydivertwindow') can be re-displayed | ||
| 16963 | $self->ivPush('lineList', $text); | ||
| 16964 | |||
| 16965 | # Read out a TTS message, if required | ||
| 16966 | if ( | ||
| 16967 | # Read out all messages, if set | ||
| 16968 | $self->ivShow('ttsFlagAttribHash', 'divert') | ||
| 16969 | # Read out only this text for this $channel, if set | ||
| 16970 | || $self->ivShow('ttsFlagAttribHash', $channel) | ||
| 16971 | ) { | ||
| 16972 | $self->ttsQuick($origText); | ||
| 16973 | } | ||
| 16974 | |||
| 16975 | return 1; | ||
| 16976 | } | ||
| 16977 | |||
| 16978 | sub displayWarning { | ||
| 16979 | |||
| 16980 | # Can be called by anything that wants to display some text in the task window as if it were | ||
| 16981 | # in the 'warning' channel (a handy alternative to an audible alarm) | ||
| 16982 | # | ||
| 16983 | # Expected arguments | ||
| 16984 | # (none besides $self) | ||
| 16985 | # | ||
| 16986 | # Return values | ||
| 16987 | # $text - The warning text to display. If 'undef', nothing is displayed, but the | ||
| 16988 | # window's background colour is still changed | ||
| 16989 | # | ||
| 16990 | # Return values | ||
| 16991 | # 'undef' on improper arguments | ||
| 16992 | # 1 otherwise | ||
| 16993 | |||
| 16994 | my ($self, $text, $check) = @_; | ||
| 16995 | |||
| 16996 | # Check for improper arguments | ||
| 16997 | if (defined $check) { | ||
| 16998 | |||
| 16999 | return $axmud::CLIENT->writeImproper($self->_objClass . '->displayWarning', @_); | ||
| 17000 | } | ||
| 17001 | |||
| 17002 | # Write the text to the window | ||
| 17003 | $self->displayText('warning', $text); | ||
| 17004 | |||
| 17005 | return 1; | ||
| 17006 | } | ||
| 17007 | |||
| 17008 | sub resetWin { | ||
| 17009 | |||
| 17010 | # Called by GA::Cmd::EmptyDivertWindow->do | ||
| 17011 | # Resets the task window - removes any text, and sets the background colour back to the | ||
| 17012 | # default | ||
| 17013 | # | ||
| 17014 | # Expected arguments | ||
| 17015 | # (none besides $self) | ||
| 17016 | # | ||
| 17017 | # Return values | ||
| 17018 | # 'undef' on improper arguments | ||
| 17019 | # 1 otherwise | ||
| 17020 | |||
| 17021 | my ($self, $check) = @_; | ||
| 17022 | |||
| 17023 | # Check for improper arguments | ||
| 17024 | if (defined $check) { | ||
| 17025 | |||
| 17026 | return $axmud::CLIENT->writeImproper($self->_objClass . '->resetWin', @_); | ||
| 17027 | } | ||
| 17028 | |||
| 17029 | if ($self->taskWinFlag) { | ||
| 17030 | |||
| 17031 | # Empty the window of text | ||
| 17032 | $self->clearBuffer(); | ||
| 17033 | |||
| 17034 | # Use the default background colour | ||
| 17035 | if ($self->defaultTabObj) { | ||
| 17036 | |||
| 17037 | $self->defaultTabObj->paneObj->applyMonochrome($self->defaultColour); | ||
| 17038 | } | ||
| 17039 | |||
| 17040 | # If the window's urgency hint is set, then reset it | ||
| 17041 | if ($self->winObj) { | ||
| 17042 | |||
| 17043 | $self->winObj->resetUrgent(); | ||
| 17044 | } | ||
| 17045 | } | ||
| 17046 | |||
| 17047 | $self->ivPoke('resetTime', undef); | ||
| 17048 | $self->ivEmpty('lineList'); | ||
| 17049 | |||
| 17050 | return 1; | ||
| 17051 | } | ||
| 17052 | |||
| 17053 | sub restoreWin { | ||
| 17054 | |||
| 17055 | # Called by $self->toggleWin, when the window is re-opened after being closed | ||
| 17056 | # Restores all the lines of text that would have been displayed, had the window been open | ||
| 17057 | # | ||
| 17058 | # Expected arguments | ||
| 17059 | # (none besides $self) | ||
| 17060 | # | ||
| 17061 | # Return values | ||
| 17062 | # 'undef' on improper arguments | ||
| 17063 | # 1 otherwise | ||
| 17064 | |||
| 17065 | my ($self, $check) = @_; | ||
| 17066 | |||
| 17067 | # Check for improper arguments | ||
| 17068 | if (defined $check) { | ||
| 17069 | |||
| 17070 | return $axmud::CLIENT->writeImproper($self->_objClass . '->restoreWin', @_); | ||
| 17071 | } | ||
| 17072 | |||
| 17073 | if ($self->taskWinFlag) { | ||
| 17074 | |||
| 17075 | foreach my $line ($self->lineList) { | ||
| 17076 | |||
| 17077 | $self->insertText($line); | ||
| 17078 | } | ||
| 17079 | } | ||
| 17080 | |||
| 17081 | return 1; | ||
| 17082 | } | ||
| 17083 | |||
| 17084 | ################## | ||
| 17085 | # Response methods | ||
| 17086 | |||
| 17087 | sub divertPatternSeen { | ||
| 17088 | |||
| 17089 | # Called by GA::Session->checkTriggers | ||
| 17090 | # | ||
| 17091 | # This task's ->resetTriggers function creates some triggers to capture strings matching | ||
| 17092 | # patterns in the world profile's ->patternList | ||
| 17093 | # e.g. Gandalf tells you, Give me the ring! | ||
| 17094 | # | ||
| 17095 | # The function diverts the line to the task window and modifies its background colour | ||
| 17096 | # (temporarily). Group substrings are ignored | ||
| 17097 | # | ||
| 17098 | # The trigger interfaces have the following properties in ->propertyHash: | ||
| 17099 | # channel - Which channel to use | ||
| 17100 | # | ||
| 17101 | # Expected arguments (standard args from GA::Session->checkTriggers) | ||
| 17102 | # $session - The calling function's GA::Session | ||
| 17103 | # $interfaceNum - The number of the active trigger interface that fired | ||
| 17104 | # $line - The line of text received from the world | ||
| 17105 | # $stripLine - $line, with all escape sequences removed | ||
| 17106 | # $modLine - $stripLine, possibly modified by previously-checked triggers | ||
| 17107 | # $grpStringListRef | ||
| 17108 | # - Reference to a list of group substrings from the pattern match | ||
| 17109 | # (equivalent of @_) | ||
| 17110 | # $matchMinusListRef | ||
| 17111 | # - Reference to a list of matched substring offsets (equivalent of @-) | ||
| 17112 | # $matchPlusListRef | ||
| 17113 | # - Reference to a list of matched substring offsets (equivalent of @+) | ||
| 17114 | # | ||
| 17115 | # Return values | ||
| 17116 | # 'undef' on improper arguments, or if $session is the wrong session, if the interface | ||
| 17117 | # object can't be found, if the corresponding IV can't be found or if the received | ||
| 17118 | # line of text matches one of the exception patterns for this type of message | ||
| 17119 | # 1 otherwise | ||
| 17120 | |||
| 17121 | my ( | ||
| 17122 | $self, $session, $interfaceNum, $line, $stripLine, $modLine, $grpStringListRef, | ||
| 17123 | $matchMinusListRef, $matchPlusListRef, $check, | ||
| 17124 | ) = @_; | ||
| 17125 | |||
| 17126 | # Local variables | ||
| 17127 | my $obj; | ||
| 17128 | |||
| 17129 | # Check for improper arguments | ||
| 17130 | if ( | ||
| 17131 | ! defined $session || ! defined $interfaceNum || ! defined $line || ! defined $stripLine | ||
| 17132 | || ! defined $modLine || ! defined $grpStringListRef || ! defined $matchMinusListRef | ||
| 17133 | || ! defined $matchPlusListRef || defined $check | ||
| 17134 | ) { | ||
| 17135 | return $axmud::CLIENT->writeImproper( | ||
| 17136 | $self->_objClass . '->divertPatternSeen', | ||
| 17137 | @_, | ||
| 17138 | ); | ||
| 17139 | } | ||
| 17140 | |||
| 17141 | # Basic check - the trigger should belong to the right session | ||
| 17142 | if ($session ne $self->session) { | ||
| 17143 | |||
| 17144 | return undef; | ||
| 17145 | } | ||
| 17146 | |||
| 17147 | # Get the interface object itself | ||
| 17148 | $obj = $session->ivShow('interfaceNumHash', $interfaceNum); | ||
| 17149 | if (! $obj) { | ||
| 17150 | |||
| 17151 | return undef; | ||
| 17152 | } | ||
| 17153 | |||
| 17154 | # Respond to the fired trigger | ||
| 17155 | |||
| 17156 | # Ignore the trigger, if this line has already been diverted | ||
| 17157 | if ($self->lastLine && $self->lastLine == $self->session->displayBufferLast) { | ||
| 17158 | |||
| 17159 | return undef; | ||
| 17160 | |||
| 17161 | } else { | ||
| 17162 | |||
| 17163 | # Don't act on any more triggers from this line | ||
| 17164 | $self->ivPoke('lastLine', $self->session->displayBufferLast); | ||
| 17165 | } | ||
| 17166 | |||
| 17167 | # Check this line of text doesn't match one of the patterns in the exception list, | ||
| 17168 | # GA::Profile::World->noChannelList | ||
| 17169 | # Any line of text which matches a pattern in that list is diverted back to the 'main' | ||
| 17170 | # window, and is not displayed in the task window | ||
| 17171 | # Check that $modLine doesn't contain one of those exception patterns | ||
| 17172 | foreach my $pattern ($self->session->currentWorld->noChannelList) { | ||
| 17173 | |||
| 17174 | if ($modLine =~ m/$pattern/i) { | ||
| 17175 | |||
| 17176 | # Divert the text back into the 'main' window, where it belongs (but only if a gag | ||
| 17177 | # trigger was used) | ||
| 17178 | if ($obj->ivShow('attribHash', 'gag')) { | ||
| 17179 | |||
| 17180 | $self->session->defaultTabObj->textViewObj->insertText( | ||
| 17181 | $modLine, | ||
| 17182 | 'after', # Assume that the line would have ended in a newline char | ||
| 17183 | ); | ||
| 17184 | |||
| 17185 | # Write to logs, if allowed | ||
| 17186 | $self->session->writeIncomingDataLogs($stripLine, $modLine); | ||
| 17187 | } | ||
| 17188 | |||
| 17189 | # (Don't bother checking the other exception patterns) | ||
| 17190 | return undef; | ||
| 17191 | } | ||
| 17192 | } | ||
| 17193 | |||
| 17194 | # Display the text in the task window | ||
| 17195 | $self->displayText( | ||
| 17196 | $obj->ivShow('propertyHash', 'channel'), | ||
| 17197 | $modLine, | ||
| 17198 | $stripLine, | ||
| 17199 | ); | ||
| 17200 | |||
| 17201 | # Write the message to a logfile (if possible) | ||
| 17202 | $axmud::CLIENT->writeLog( | ||
| 17203 | $self->session, | ||
| 17204 | FALSE, # Not a 'standard' logfile | ||
| 17205 | $modLine, | ||
| 17206 | FALSE, # Don't precede with a newline character | ||
| 17207 | TRUE, # Use final newline character | ||
| 17208 | 'divert', # Write to this logfile | ||
| 17209 | ); | ||
| 17210 | |||
| 17211 | return 1; | ||
| 17212 | } | ||
| 17213 | |||
| 17214 | sub entryCallback { | ||
| 17215 | |||
| 17216 | # Usually called by ->signal_connect in GA::Strip::Entry->setEntrySignals or in | ||
| 17217 | # GA::Table::Entry->setActivateEvent, when the user types something in the strip/table | ||
| 17218 | # object's Gtk3::Entry and presses RETURN | ||
| 17219 | # The text is treated as an ordinary instruction (but Perl commands are not allowed); a | ||
| 17220 | # copy is also displayed in the task window | ||
| 17221 | # | ||
| 17222 | # Expected arguments | ||
| 17223 | # $obj - The strip or table object whose Gtk3::Entry was used | ||
| 17224 | # $entry - The Gtk3::Entry itself | ||
| 17225 | # | ||
| 17226 | # Optional arguments | ||
| 17227 | # $id - A value passed to the table object that identifies the particular | ||
| 17228 | # Gtk3::Entry used (in case the table object uses multiple entries). By | ||
| 17229 | # default, $self->openWin sets $id to the same as $self->uniqueName; | ||
| 17230 | # could be an 'undef' value otherwise | ||
| 17231 | # $text - The text typed in the entry by the user (should not be 'undef') | ||
| 17232 | # | ||
| 17233 | # Return values | ||
| 17234 | # 'undef' on improper arguments | ||
| 17235 | # 1 otherwise | ||
| 17236 | |||
| 17237 | my ($self, $obj, $entry, $id, $text, $check) = @_; | ||
| 17238 | |||
| 17239 | # Check for improper arguments | ||
| 17240 | if (! defined $obj || ! defined $entry || defined $check) { | ||
| 17241 | |||
| 17242 | return $axmud::CLIENT->writeImproper($self->_objClass . '->entryCallback', @_); | ||
| 17243 | } | ||
| 17244 | |||
| 17245 | if ($self->taskWinFlag) { | ||
| 17246 | |||
| 17247 | # Execute the instruction (but don't allow Perl commands) | ||
| 17248 | $self->session->doInstruct($text, TRUE); | ||
| 17249 | $self->insertText($self->responseString . $text); | ||
| 17250 | } | ||
| 17251 | |||
| 17252 | return 1; | ||
| 17253 | } | ||
| 17254 | |||
| 17255 | ################## | ||
| 17256 | # Accessors - set | ||
| 17257 | |||
| 17258 | ################## | ||
| 17259 | # Accessors - task settings - get | ||
| 17260 | |||
| 17261 | # The accessors for task settings are inherited from the generic task | ||
| 17262 | |||
| 17263 | ################## | ||
| 17264 | # Accessors - task parameters - get | ||
| 17265 | |||
| 17266 | sub defaultColour | ||
| 17267 | { $_[0]->{defaultColour} } | ||
| 17268 | sub tellAlertColour | ||
| 17269 | { $_[0]->{tellAlertColour} } | ||
| 17270 | sub socialAlertColour | ||
| 17271 | { $_[0]->{socialAlertColour} } | ||
| 17272 | sub customAlertColour | ||
| 17273 | { $_[0]->{customAlertColour} } | ||
| 17274 | sub warningAlertColour | ||
| 17275 | { $_[0]->{warningAlertColour} } | ||
| 17276 | sub otherAlertColour | ||
| 17277 | { $_[0]->{otherAlertColour} } | ||
| 17278 | |||
| 17279 | sub tellAlertInterval | ||
| 17280 | { $_[0]->{tellAlertInterval} } | ||
| 17281 | sub socialAlertInterval | ||
| 17282 | { $_[0]->{socialAlertInterval} } | ||
| 17283 | sub customAlertInterval | ||
| 17284 | { $_[0]->{customAlertInterval} } | ||
| 17285 | sub warningAlertInterval | ||
| 17286 | { $_[0]->{warningAlertInterval} } | ||
| 17287 | sub otherAlertInterval | ||
| 17288 | { $_[0]->{otherAlertInterval} } | ||
| 17289 | |||
| 17290 | sub tellAlertSound | ||
| 17291 | { $_[0]->{tellAlertSound} } | ||
| 17292 | sub socialAlertSound | ||
| 17293 | { $_[0]->{socialAlertSound} } | ||
| 17294 | sub customAlertSound | ||
| 17295 | { $_[0]->{customAlertSound} } | ||
| 17296 | sub warningAlertSound | ||
| 17297 | { $_[0]->{warningAlertSound} } | ||
| 17298 | sub otherAlertSound | ||
| 17299 | { $_[0]->{otherAlertSound} } | ||
| 17300 | |||
| 17301 | sub tellCharLimit | ||
| 17302 | { $_[0]->{tellCharLimit} } | ||
| 17303 | sub socialCharLimit | ||
| 17304 | { $_[0]->{socialCharLimit} } | ||
| 17305 | sub customCharLimit | ||
| 17306 | { $_[0]->{customCharLimit} } | ||
| 17307 | sub warningCharLimit | ||
| 17308 | { $_[0]->{warningCharLimit} } | ||
| 17309 | sub otherCharLimit | ||
| 17310 | { $_[0]->{otherCharLimit} } | ||
| 17311 | |||
| 17312 | sub tellRoomFlag | ||
| 17313 | { $_[0]->{tellRoomFlag} } | ||
| 17314 | sub socialRoomFlag | ||
| 17315 | { $_[0]->{socialRoomFlag} } | ||
| 17316 | sub customRoomFlag | ||
| 17317 | { $_[0]->{customRoomFlag} } | ||
| 17318 | sub warningRoomFlag | ||
| 17319 | { $_[0]->{warningRoomFlag} } | ||
| 17320 | sub otherRoomFlag | ||
| 17321 | { $_[0]->{otherRoomFlag} } | ||
| 17322 | |||
| 17323 | sub tellUrgencyFlag | ||
| 17324 | { $_[0]->{tellUrgencyFlag} } | ||
| 17325 | sub socialUrgencyFlag | ||
| 17326 | { $_[0]->{socialUrgencyFlag} } | ||
| 17327 | sub customUrgencyFlag | ||
| 17328 | { $_[0]->{customUrgencyFlag} } | ||
| 17329 | sub warningUrgencyFlag | ||
| 17330 | { $_[0]->{warningUrgencyFlag} } | ||
| 17331 | sub otherUrgencyFlag | ||
| 17332 | { $_[0]->{otherUrgencyFlag} } | ||
| 17333 | |||
| 17334 | sub resetTime | ||
| 17335 | { $_[0]->{resetTime} } | ||
| 17336 | sub firstTextFlag | ||
| 17337 | { $_[0]->{firstTextFlag} } | ||
| 17338 | sub lastLine | ||
| 17339 | { $_[0]->{lastLine} } | ||
| 17340 | sub responseString | ||
| 17341 | { $_[0]->{responseString} } | ||
| 17342 | sub lineList | ||
| 17343 | { my $self = shift; return @{$self->{lineList}}; } | ||
| 17344 | } | ||
| 17345 | |||
| 17346 | { package Games::Axmud::Task::Frame; | ||
| 17347 | |||
| 17348 | use strict; | ||
| 17349 | use warnings; | ||
| 17350 | # use diagnostics; | ||
| 17351 | |||
| 17352 | use Glib qw(TRUE FALSE); | ||
| 17353 | |||
| 17354 | our @ISA = qw(Games::Axmud::Generic::Task Games::Axmud); | ||
| 17355 | |||
| 17356 | ################## | ||
| 17357 | # Constructors | ||
| 17358 | |||
| 17359 | sub new { | ||
| 17360 | |||
| 17361 | # Creates a new instance of the Frame task | ||
| 17362 | # | ||
| 17363 | # Expected arguments | ||
| 17364 | # $session - The parent GA::Session (not stored as an IV) | ||
| 17365 | # | ||
| 17366 | # Optional arguments | ||
| 17367 | # $taskType - Which tasklist this task is being created into - 'current' for the current | ||
| 17368 | # tasklist (tasks which are actually running now), 'initial' (tasks which | ||
| 17369 | # should be run when the user connects to the world), 'custom' (tasks with | ||
| 17370 | # customised initial parameters, which are run when the user demands). If | ||
| 17371 | # set to 'undef', this is a temporary task, created in order to access the | ||
| 17372 | # default values stored in IVs, that will not be added to any tasklist | ||
| 17373 | # $profName - ($taskType = 'current', when called by $self->clone) Name of the | ||
| 17374 | # profile from whose initial tasklist this task was created ('undef' if | ||
| 17375 | # none) | ||
| 17376 | # - ($taskType = 'initial') name of the profile in whose initial tasklist this | ||
| 17377 | # task will be. If 'undef', the global initial tasklist is used | ||
| 17378 | # - ($taskType = 'custom') 'undef' | ||
| 17379 | # $profCategory | ||
| 17380 | # - ($taskType = 'current', 'initial') which category the profile falls undef | ||
| 17381 | # (i.e. 'world', 'race', 'char', etc, or 'undef' if no profile) | ||
| 17382 | # - ($taskType = 'custom') 'undef' | ||
| 17383 | # $customName | ||
| 17384 | # - ($taskType = 'current', 'initial') 'undef' | ||
| 17385 | # - ($taskType = 'custom') the custom task name, matching a key in | ||
| 17386 | # GA::Session->customTaskHash | ||
| 17387 | # | ||
| 17388 | # Return values | ||
| 17389 | # 'undef' on improper arguments or if the task can't be added to the specified tasklist | ||
| 17390 | # Blessed reference to the newly-created object on success | ||
| 17391 | |||
| 17392 | my ($class, $session, $taskType, $profName, $profCategory, $customName, $check) = @_; | ||
| 17393 | |||
| 17394 | # Check for improper arguments | ||
| 17395 | if (! defined $class || ! defined $session || defined $check) { | ||
| 17396 | |||
| 17397 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 17398 | } | ||
| 17399 | |||
| 17400 | if ($taskType) { | ||
| 17401 | |||
| 17402 | # For initial tasks, check that $profName exists | ||
| 17403 | if ( | ||
| 17404 | $taskType eq 'initial' | ||
| 17405 | && defined $profName | ||
| 17406 | && ! $session->ivExists('profHash', $profName) | ||
| 17407 | ) { | ||
| 17408 | return $session->writeError( | ||
| 17409 | 'Can\'t create new task because \'' . $profName . '\' profile doesn\'t exist', | ||
| 17410 | $class . '->new', | ||
| 17411 | ); | ||
| 17412 | |||
| 17413 | # For custom tasks, check that $customName doesn't already exist | ||
| 17414 | } elsif ( | ||
| 17415 | $taskType eq 'custom' | ||
| 17416 | && $axmud::CLIENT->ivExists('customTaskHash', $customName) | ||
| 17417 | ) { | ||
| 17418 | return $session->writeError( | ||
| 17419 | 'Can\'t create new custom task because \'' . $customName . '\' is already being' | ||
| 17420 | . ' used', | ||
| 17421 | $class . '->new', | ||
| 17422 | ); | ||
| 17423 | |||
| 17424 | } elsif ($taskType ne 'current' && $taskType ne 'initial' && $taskType ne 'custom') { | ||
| 17425 | |||
| 17426 | return $session->writeError( | ||
| 17427 | 'Can\'t create new task because \'' . $taskType . '\' is an invalid tasklist', | ||
| 17428 | $class . '->new', | ||
| 17429 | ); | ||
| 17430 | } | ||
| 17431 | } | ||
| 17432 | |||
| 17433 | # Task settings | ||
| 17434 | my $self = Games::Axmud::Generic::Task->new( | ||
| 17435 | $session, | ||
| 17436 | $taskType, | ||
| 17437 | $profName, | ||
| 17438 | $profCategory, | ||
| 17439 | $customName, | ||
| 17440 | ); | ||
| 17441 | |||
| 17442 | $self->{_objName} = 'frame_task'; | ||
| 17443 | $self->{_objClass} = $class; | ||
| 17444 | $self->{_parentFile} = undef; # Set below | ||
| 17445 | $self->{_parentWorld} = undef; # Set below | ||
| 17446 | $self->{_privFlag} = TRUE, # All IVs are private | ||
| 17447 | |||
| 17448 | $self->{name} = 'frame_task'; | ||
| 17449 | $self->{prettyName} = 'Frame'; | ||
| 17450 | $self->{shortName} = 'Fr'; | ||
| 17451 | $self->{shortCutIV} = undef; # Built-in task, but not jealous | ||
| 17452 | |||
| 17453 | $self->{category} = 'activity'; | ||
| 17454 | $self->{descrip} = 'Implements MXP floating frames using a task window'; | ||
| 17455 | $self->{jealousyFlag} = FALSE; | ||
| 17456 | $self->{requireLocatorFlag} = FALSE; | ||
| 17457 | $self->{profSensitivityFlag} = FALSE; | ||
| 17458 | $self->{storableFlag} = FALSE; | ||
| 17459 | $self->{delayTime} = 0; | ||
| 17460 | $self->{allowWinFlag} = TRUE; | ||
| 17461 | $self->{requireWinFlag} = TRUE; | ||
| 17462 | $self->{startWithWinFlag} = TRUE; | ||
| 17463 | $self->{winPreferList} = ['grid']; | ||
| 17464 | $self->{winmap} = 'basic_fill'; | ||
| 17465 | $self->{winUpdateFunc} = undef; # No func to call after ;opentaskwindow | ||
| 17466 | $self->{tabMode} = 'simple'; | ||
| 17467 | $self->{monochromeFlag} = FALSE; | ||
| 17468 | $self->{noScrollFlag} = FALSE; | ||
| 17469 | $self->{ttsFlag} = FALSE; | ||
| 17470 | $self->{ttsConfig} = undef; | ||
| 17471 | $self->{ttsAttribHash} = {}; | ||
| 17472 | $self->{ttsFlagAttribHash} = {}; | ||
| 17473 | $self->{ttsAlertAttribHash} = {}; | ||
| 17474 | $self->{status} = 'wait_init'; | ||
| 17475 | # $self->{activeFlag} = TRUE; # Task can't be activated/disactivated | ||
| 17476 | |||
| 17477 | # Task parameters | ||
| 17478 | |||
| 17479 | # The GA::Mxp::Frame object that uses this task's window | ||
| 17480 | $self->{frameObj} = undef; | ||
| 17481 | # The preferred size and position of the task window on the workspace, in pixels | ||
| 17482 | $self->{leftPixels} = undef; | ||
| 17483 | $self->{topPixels} = undef; | ||
| 17484 | $self->{widthPixels} = undef; | ||
| 17485 | $self->{heightPixels} = undef; | ||
| 17486 | |||
| 17487 | # Bless task | ||
| 17488 | bless $self, $class; | ||
| 17489 | |||
| 17490 | # For all tasks that aren't temporary... | ||
| 17491 | if ($taskType) { | ||
| 17492 | |||
| 17493 | # Check that the task doesn't belong to a disabled plugin (in which case, it can't be | ||
| 17494 | # added to any current, initial or custom tasklist) | ||
| 17495 | if (! $self->checkPlugins()) { | ||
| 17496 | |||
| 17497 | return undef; | ||
| 17498 | } | ||
| 17499 | |||
| 17500 | # Set the parent file object | ||
| 17501 | $self->setParentFileObj($session, $taskType, $profName, $profCategory); | ||
| 17502 | |||
| 17503 | # Create entries in tasklists, if possible | ||
| 17504 | if (! $self->updateTaskLists($session)) { | ||
| 17505 | |||
| 17506 | return undef; | ||
| 17507 | } | ||
| 17508 | } | ||
| 17509 | |||
| 17510 | # Task creation complete | ||
| 17511 | return $self; | ||
| 17512 | } | ||
| 17513 | |||
| 17514 | sub clone { | ||
| 17515 | |||
| 17516 | # Create a clone of an existing task | ||
| 17517 | # Usually used upon connection to a world, when every task in the initial tasklists must | ||
| 17518 | # be cloned into a new object, representing a task in the current tasklist | ||
| 17519 | # (Also used when cloning a profile object, since all the tasks in its initial tasklist must | ||
| 17520 | # also be cloned) | ||
| 17521 | # | ||
| 17522 | # Expected arguments | ||
| 17523 | # $session - The parent GA::Session (not stored as an IV) | ||
| 17524 | # $taskType - Which tasklist this task is being created into - 'current' for the current | ||
| 17525 | # tasklist (tasks which are actually running now), 'initial' (tasks which | ||
| 17526 | # should be run when the user connects to the world). Custom tasks aren't | ||
| 17527 | # cloned (at the moment) | ||
| 17528 | # | ||
| 17529 | # Optional arguments | ||
| 17530 | # $profName - ($taskType = 'initial') name of the profile in whose initial tasklist the | ||
| 17531 | # existing task is stored | ||
| 17532 | # $profCategory | ||
| 17533 | # - ($taskType = 'initial') which category the profile falls under (i.e. | ||
| 17534 | # 'world', 'race', 'char', etc) | ||
| 17535 | # | ||
| 17536 | # Return values | ||
| 17537 | # 'undef' on improper arguments or if the task can't be cloned | ||
| 17538 | # Blessed reference to the newly-created object on success | ||
| 17539 | |||
| 17540 | my ($self, $session, $taskType, $profName, $profCategory, $check) = @_; | ||
| 17541 | |||
| 17542 | # Check for improper arguments | ||
| 17543 | if ( | ||
| 17544 | ! defined $session || ! defined $taskType || defined $check | ||
| 17545 | || ($taskType ne 'current' && $taskType ne 'initial') | ||
| 17546 | || ($taskType eq 'initial' && (! defined $profName || ! defined $profCategory)) | ||
| 17547 | ) { | ||
| 17548 | return $axmud::CLIENT->writeImproper($self->_objClass . '->clone', @_); | ||
| 17549 | } | ||
| 17550 | |||
| 17551 | # For initial tasks, check that $profName exists | ||
| 17552 | if ( | ||
| 17553 | $taskType eq 'initial' | ||
| 17554 | && defined $profName | ||
| 17555 | && ! $session->ivExists('profHash', $profName) | ||
| 17556 | ) { | ||
| 17557 | return $axmud::CLIENT->writeError( | ||
| 17558 | 'Can\'t create cloned task because \'' . $profName . '\' profile doesn\'t exist', | ||
| 17559 | $self->_objClass . '->clone', | ||
| 17560 | ); | ||
| 17561 | } | ||
| 17562 | |||
| 17563 | # Check that the task doesn't belong to a disabled plugin (in which case, it can't be | ||
| 17564 | # cloned) | ||
| 17565 | if (! $self->checkPlugins()) { | ||
| 17566 | |||
| 17567 | return undef; | ||
| 17568 | } | ||
| 17569 | |||
| 17570 | # Create the new task, using default settings and parameters | ||
| 17571 | my $clone = $self->_objClass->new($session, $taskType, $profName, $profCategory); | ||
| 17572 | |||
| 17573 | # Most of the cloned task's settings have default values, but a few are copied from the | ||
| 17574 | # original | ||
| 17575 | $self->cloneTaskSettings($clone); | ||
| 17576 | |||
| 17577 | # Give the new (cloned) task the same initial parameters as the original one | ||
| 17578 | # $clone->{frameObj} = $self->frameObj; | ||
| 17579 | |||
| 17580 | # Cloning complete | ||
| 17581 | return $clone; | ||
| 17582 | } | ||
| 17583 | |||
| 17584 | sub preserve { | ||
| 17585 | |||
| 17586 | # Called by $self->main whenever this task is reset, in order to preserve some if its task | ||
| 17587 | # parameters (but not necessarily all of them) | ||
| 17588 | # | ||
| 17589 | # Expected arguments | ||
| 17590 | # $newTask - The new task which has been created, to which some of this task's instance | ||
| 17591 | # variables might have to be transferred | ||
| 17592 | # | ||
| 17593 | # Return values | ||
| 17594 | # 'undef' on improper arguments, or if $newTask isn't in the GA::Session's current | ||
| 17595 | # tasklist | ||
| 17596 | # 1 on success | ||
| 17597 | |||
| 17598 | my ($self, $newTask, $check) = @_; | ||
| 17599 | |||
| 17600 | # Check for improper arguments | ||
| 17601 | if (! defined $newTask || defined $check) { | ||
| 17602 | |||
| 17603 | return $axmud::CLIENT->writeImproper($self->_objClass . '->preserve', @_); | ||
| 17604 | } | ||
| 17605 | |||
| 17606 | # Check the task is in the current tasklist | ||
| 17607 | if (! $self->session->ivExists('currentTaskHash', $newTask->uniqueName)) { | ||
| 17608 | |||
| 17609 | return $self->writeWarning( | ||
| 17610 | '\'' . $self->uniqueName . '\' task missing from the current tasklist', | ||
| 17611 | $self->_objClass . '->preserve', | ||
| 17612 | ); | ||
| 17613 | } | ||
| 17614 | |||
| 17615 | # Preserve some task parameters (the others are left with their default settings, some of | ||
| 17616 | # which will be re-initialised in stage 2) | ||
| 17617 | |||
| 17618 | # Preserve the GA::Mxp::Frame object and the window's preferred size/position | ||
| 17619 | $newTask->ivPoke('frameObj', $self->frameObj); | ||
| 17620 | $newTask->ivPoke('leftPixels', $self->leftPixels); | ||
| 17621 | $newTask->ivPoke('topPixels', $self->topPixels); | ||
| 17622 | $newTask->ivPoke('widthPixels', $self->widthPixels); | ||
| 17623 | $newTask->ivPoke('heightPixels', $self->heightPixels); | ||
| 17624 | |||
| 17625 | return 1; | ||
| 17626 | } | ||
| 17627 | |||
| 17628 | # sub setParentFileObj {} # Inherited from generic task | ||
| 17629 | |||
| 17630 | # sub updateTaskLists {} # Inherited from generic task | ||
| 17631 | |||
| 17632 | # sub ttsReadAttrib {} # Inherited from generic task | ||
| 17633 | |||
| 17634 | # sub ttsSwitchFlagAttrib {} # Inherited from generic task | ||
| 17635 | |||
| 17636 | # sub ttsSetAlertAttrib {} # Inherited from generic task | ||
| 17637 | |||
| 17638 | ################## | ||
| 17639 | # Task windows | ||
| 17640 | |||
| 17641 | # sub toggleWin {} # Inherited from generic task | ||
| 17642 | |||
| 17643 | sub openWin { | ||
| 17644 | |||
| 17645 | # Called by the task's ->main method or by its ->toggleWin method | ||
| 17646 | # Tries to open each type of task window in $self->winPreferList, halting at the first | ||
| 17647 | # successful attempt (or when all attempts fail) | ||
| 17648 | # | ||
| 17649 | # Expected arguments | ||
| 17650 | # (none besides self) | ||
| 17651 | # | ||
| 17652 | # Optional arguments | ||
| 17653 | # $winmap - Ignored if specified | ||
| 17654 | # @preferList - Ignored if specified | ||
| 17655 | # | ||
| 17656 | # Return values | ||
| 17657 | # 'undef' on improper arguments or if a task window is not opened | ||
| 17658 | # 1 if a window is opened | ||
| 17659 | |||
| 17660 | my ($self, $winmap, @preferList) = @_; | ||
| 17661 | |||
| 17662 | # Local variables | ||
| 17663 | my ($winObj, $workspaceObj, $gridObj, $layer); | ||
| 17664 | |||
| 17665 | # (No improper arguments to check) | ||
| 17666 | |||
| 17667 | # We want to open the window at a preferred size and position, so we use our own code, | ||
| 17668 | # rather than code in the generic task | ||
| 17669 | # Also, if $winmap / @preferList are specified, they is ignored; this function only opens a | ||
| 17670 | # 'grid' window using a 'basic_fill' winmap | ||
| 17671 | # Only the workspace used by the session's 'main' window is used; if the task window can't | ||
| 17672 | # be opened there, it's not opened at all | ||
| 17673 | |||
| 17674 | # If $self->frameObj isn't set, there's no point in opening a task window | ||
| 17675 | if (! $self->frameObj) { | ||
| 17676 | |||
| 17677 | return undef; | ||
| 17678 | } | ||
| 17679 | |||
| 17680 | # Set the task IV to enable/disable scrolling | ||
| 17681 | if (! $self->frameObj->scrollingFlag) { | ||
| 17682 | |||
| 17683 | $self->ivPoke('noScrollFlag', TRUE); | ||
| 17684 | } | ||
| 17685 | |||
| 17686 | # Prepare arguments | ||
| 17687 | $workspaceObj = $self->session->mainWin->workspaceObj; | ||
| 17688 | $gridObj = $workspaceObj->findWorkspaceGrid($self->session); | ||
| 17689 | |||
| 17690 | # Use the layer one higher than the highest window (ignoring other Frame task windows, of | ||
| 17691 | # course), so that the task window's size won't be adjusted to fit around existing windows | ||
| 17692 | # Exception: if Pueblo specified a floating frame, implement that by putting the task window | ||
| 17693 | # in the highest layer (rather than calling Gtk3::Window->set_keep_above, or something) | ||
| 17694 | if ($self->frameObj->floatingFlag) { | ||
| 17695 | |||
| 17696 | $layer = $gridObj->maxLayers - 1; | ||
| 17697 | |||
| 17698 | } else { | ||
| 17699 | |||
| 17700 | # Start on layer 1, on the assumption that the session's 'main' window must exist, so | ||
| 17701 | # there is probably a window in layer 0 | ||
| 17702 | $layer = 1; | ||
| 17703 | foreach my $otherWinObj ($gridObj->ivValues('gridWinHash')) { | ||
| 17704 | |||
| 17705 | if ( | ||
| 17706 | ( | ||
| 17707 | ! $otherWinObj->owner | ||
| 17708 | || ! $otherWinObj->owner->isa('Games::Axmud::Task::Frame') | ||
| 17709 | ) | ||
| 17710 | && $otherWinObj->areaObj->layer >= $layer | ||
| 17711 | ) { | ||
| 17712 | $layer = $otherWinObj->areaObj->layer + 1; | ||
| 17713 | } | ||
| 17714 | } | ||
| 17715 | } | ||
| 17716 | |||
| 17717 | # Open the window | ||
| 17718 | $winObj = $workspaceObj->createGridWin( | ||
| 17719 | 'custom', # All task windows are 'custom' windows | ||
| 17720 | $self->name, # Window name is the same as the task name | ||
| 17721 | $self->frameObj->title, # Window title | ||
| 17722 | 'basic_fill', # Winmap | ||
| 17723 | 'Games::Axmud::Win::Internal', # Package name | ||
| 17724 | undef, # No windows exists yet | ||
| 17725 | undef, # Ditto | ||
| 17726 | $self, # Owner | ||
| 17727 | $self->session, # Session | ||
| 17728 | $gridObj, # Session's workspace grid object | ||
| 17729 | undef, # Use any zone | ||
| 17730 | $layer, | ||
| 17731 | $self->leftPixels, # Preferred window size/position (integer or 'undef') | ||
| 17732 | $self->topPixels, | ||
| 17733 | $self->widthPixels, | ||
| 17734 | $self->heightPixels, | ||
| 17735 | ); | ||
| 17736 | |||
| 17737 | if (! $winObj) { | ||
| 17738 | |||
| 17739 | # Window not opened | ||
| 17740 | return undef; | ||
| 17741 | } | ||
| 17742 | |||
| 17743 | # Window created and enabled | ||
| 17744 | $self->ivPoke('winObj', $winObj); | ||
| 17745 | $self->ivPoke('taskWinFlag', TRUE); | ||
| 17746 | # Set its title (using the frame title, not the task name) | ||
| 17747 | $self->setTaskWinTitle($self->frameObj->name); | ||
| 17748 | |||
| 17749 | # Add a tab, if required. The TRUE argument indicates window setup | ||
| 17750 | $self->addTab(undef, TRUE); | ||
| 17751 | # (No entry box to setup) | ||
| 17752 | |||
| 17753 | # Update the frame object's IVs | ||
| 17754 | $self->frameObj->ivPoke('tabObj', $self->defaultTabObj); | ||
| 17755 | $self->frameObj->ivPoke('paneObj', $self->defaultTabObj->paneObj); | ||
| 17756 | $self->frameObj->ivPoke('textViewObj', $self->defaultTabObj->textViewObj); | ||
| 17757 | |||
| 17758 | return 1; | ||
| 17759 | } | ||
| 17760 | |||
| 17761 | sub closeWin { | ||
| 17762 | |||
| 17763 | # Called by the task's ->main method or by its ->toggleWin method, or by any other code | ||
| 17764 | # Close the task window for this task, if it is open | ||
| 17765 | # | ||
| 17766 | # Expected arguments | ||
| 17767 | # (none besides self) | ||
| 17768 | # | ||
| 17769 | # Return values | ||
| 17770 | # 'undef' on improper arguments or if the window was not closed | ||
| 17771 | # 1 if the window was closed | ||
| 17772 | |||
| 17773 | my ($self, $check) = @_; | ||
| 17774 | |||
| 17775 | # Check for improper arguments | ||
| 17776 | if (defined $check) { | ||
| 17777 | |||
| 17778 | return $axmud::CLIENT->writeImproper($self->_objClass . '->closeWin', @_); | ||
| 17779 | } | ||
| 17780 | |||
| 17781 | # Most of the code is in the generic function | ||
| 17782 | if (! $self->Games::Axmud::Generic::Task::closeWin()) { | ||
| 17783 | |||
| 17784 | # Task window not closed | ||
| 17785 | return undef; | ||
| 17786 | |||
| 17787 | } else { | ||
| 17788 | |||
| 17789 | # Also inform the session, so it can stop using frames altogether | ||
| 17790 | $self->session->removeMxpFrames(); | ||
| 17791 | |||
| 17792 | return 1; | ||
| 17793 | } | ||
| 17794 | } | ||
| 17795 | |||
| 17796 | ################## | ||
| 17797 | # Methods | ||
| 17798 | |||
| 17799 | # sub init {} # Inherited from generic task | ||
| 17800 | |||
| 17801 | # sub doInit {} # Inherited from generic task | ||
| 17802 | |||
| 17803 | # sub doShutdown {} # Inherited from generic task | ||
| 17804 | |||
| 17805 | # sub doReset {} # Inherited from generic task | ||
| 17806 | |||
| 17807 | ################## | ||
| 17808 | # Response methods | ||
| 17809 | |||
| 17810 | ################## | ||
| 17811 | # Accessors - set | ||
| 17812 | |||
| 17813 | sub set_frameObj { | ||
| 17814 | |||
| 17815 | my ($self, $frameObj, $check) = @_; | ||
| 17816 | |||
| 17817 | # Check for improper arguments | ||
| 17818 | if (! defined $frameObj || defined $check) { | ||
| 17819 | |||
| 17820 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_frameObj', @_); | ||
| 17821 | } | ||
| 17822 | |||
| 17823 | # Update IVs | ||
| 17824 | $self->ivPoke('frameObj', $frameObj); | ||
| 17825 | |||
| 17826 | return 1; | ||
| 17827 | } | ||
| 17828 | |||
| 17829 | sub del_winObj { | ||
| 17830 | |||
| 17831 | # Called by GA::Win::Generic->winDestroy | ||
| 17832 | |||
| 17833 | my ($self, $winObj, $check) = @_; | ||
| 17834 | |||
| 17835 | # Local variables | ||
| 17836 | my $stripObj; | ||
| 17837 | |||
| 17838 | # Check for improper arguments | ||
| 17839 | if (! defined $winObj || defined $check) { | ||
| 17840 | |||
| 17841 | return $axmud::CLIENT->writeImproper($self->_objClass . '->del_winObj', @_); | ||
| 17842 | } | ||
| 17843 | |||
| 17844 | # Most of the code is in the generic function | ||
| 17845 | if (! $self->Games::Axmud::Generic::Task::del_winObj($winObj)) { | ||
| 17846 | |||
| 17847 | return undef; | ||
| 17848 | |||
| 17849 | } else { | ||
| 17850 | |||
| 17851 | # Inform the session, so it can stop using frames altogether | ||
| 17852 | $self->session->removeMxpFrames(); | ||
| 17853 | |||
| 17854 | return 1; | ||
| 17855 | } | ||
| 17856 | } | ||
| 17857 | |||
| 17858 | sub set_winPosn { | ||
| 17859 | |||
| 17860 | my ($self, $left, $top, $width, $height, $check) = @_; | ||
| 17861 | |||
| 17862 | # Check for improper arguments | ||
| 17863 | if (defined $check) { | ||
| 17864 | |||
| 17865 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_winPosn', @_); | ||
| 17866 | } | ||
| 17867 | |||
| 17868 | # Update IVs | ||
| 17869 | $self->ivPoke('leftPixels', $left); | ||
| 17870 | $self->ivPoke('topPixels', $top); | ||
| 17871 | $self->ivPoke('widthPixels', $width); | ||
| 17872 | $self->ivPoke('heightPixels', $height); | ||
| 17873 | |||
| 17874 | return 1; | ||
| 17875 | } | ||
| 17876 | |||
| 17877 | ################## | ||
| 17878 | # Accessors - task settings - get | ||
| 17879 | |||
| 17880 | # The accessors for task settings are inherited from the generic task | ||
| 17881 | |||
| 17882 | ################## | ||
| 17883 | # Accessors - task parameters - get | ||
| 17884 | |||
| 17885 | sub frameObj | ||
| 17886 | { $_[0]->{frameObj} } | ||
| 17887 | sub leftPixels | ||
| 17888 | { $_[0]->{leftPixels} } | ||
| 17889 | sub topPixels | ||
| 17890 | { $_[0]->{topPixels} } | ||
| 17891 | sub widthPixels | ||
| 17892 | { $_[0]->{widthPixels} } | ||
| 17893 | sub heightPixels | ||
| 17894 | { $_[0]->{heightPixels} } | ||
| 17895 | } | ||
| 17896 | |||
| 17897 | { package Games::Axmud::Task::Inventory; | ||
| 17898 | |||
| 17899 | use strict; | ||
| 17900 | use warnings; | ||
| 17901 | # use diagnostics; | ||
| 17902 | |||
| 17903 | use Glib qw(TRUE FALSE); | ||
| 17904 | |||
| 17905 | our @ISA = qw(Games::Axmud::Generic::Task Games::Axmud); | ||
| 17906 | |||
| 17907 | ################## | ||
| 17908 | # Constructors | ||
| 17909 | |||
| 17910 | sub new { | ||
| 17911 | |||
| 17912 | # Creates a new instances of the Inventory task | ||
| 17913 | # | ||
| 17914 | # Expected arguments | ||
| 17915 | # $session - The parent GA::Session (not stored as an IV) | ||
| 17916 | # | ||
| 17917 | # Optional arguments | ||
| 17918 | # $taskType - Which tasklist this task is being created into - 'current' for the current | ||
| 17919 | # tasklist (tasks which are actually running now), 'initial' (tasks which | ||
| 17920 | # should be run when the user connects to the world), 'custom' (tasks with | ||
| 17921 | # customised initial parameters, which are run when the user demands). If | ||
| 17922 | # set to 'undef', this is a temporary task, created in order to access the | ||
| 17923 | # default values stored in IVs, that will not be added to any tasklist | ||
| 17924 | # $profName - ($taskType = 'current', when called by $self->clone) Name of the | ||
| 17925 | # profile from whose initial tasklist this task was created ('undef' if | ||
| 17926 | # none) | ||
| 17927 | # - ($taskType = 'initial') name of the profile in whose initial tasklist this | ||
| 17928 | # task will be. If 'undef', the global initial tasklist is used | ||
| 17929 | # - ($taskType = 'custom') 'undef' | ||
| 17930 | # $profCategory | ||
| 17931 | # - ($taskType = 'current', 'initial') which category the profile falls undef | ||
| 17932 | # (i.e. 'world', 'race', 'char', etc, or 'undef' if no profile) | ||
| 17933 | # - ($taskType = 'custom') 'undef' | ||
| 17934 | # $customName | ||
| 17935 | # - ($taskType = 'current', 'initial') 'undef' | ||
| 17936 | # - ($taskType = 'custom') the custom task name, matching a key in | ||
| 17937 | # GA::Session->customTaskHash | ||
| 17938 | # | ||
| 17939 | # Return values | ||
| 17940 | # 'undef' on improper arguments or if the task can't be added to the specified tasklist | ||
| 17941 | # Blessed reference to the newly-created object on success | ||
| 17942 | |||
| 17943 | my ($class, $session, $taskType, $profName, $profCategory, $customName, $check) = @_; | ||
| 17944 | |||
| 17945 | # Check for improper arguments | ||
| 17946 | if (! defined $class || ! defined $session || defined $check) { | ||
| 17947 | |||
| 17948 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 17949 | } | ||
| 17950 | |||
| 17951 | if ($taskType) { | ||
| 17952 | |||
| 17953 | # For initial tasks, check that $profName exists | ||
| 17954 | if ( | ||
| 17955 | $taskType eq 'initial' | ||
| 17956 | && defined $profName | ||
| 17957 | && ! $session->ivExists('profHash', $profName) | ||
| 17958 | ) { | ||
| 17959 | return $session->writeError( | ||
| 17960 | 'Can\'t create new task because \'' . $profName . '\' profile doesn\'t exist', | ||
| 17961 | $class . '->new', | ||
| 17962 | ); | ||
| 17963 | |||
| 17964 | # For custom tasks, check that $customName doesn't already exist | ||
| 17965 | } elsif ( | ||
| 17966 | $taskType eq 'custom' | ||
| 17967 | && $axmud::CLIENT->ivExists('customTaskHash', $customName) | ||
| 17968 | ) { | ||
| 17969 | return $session->writeError( | ||
| 17970 | 'Can\'t create new custom task because \'' . $customName . '\' is already being' | ||
| 17971 | . ' used', | ||
| 17972 | $class . '->new', | ||
| 17973 | ); | ||
| 17974 | |||
| 17975 | } elsif ($taskType ne 'current' && $taskType ne 'initial' && $taskType ne 'custom') { | ||
| 17976 | |||
| 17977 | return $session->writeError( | ||
| 17978 | 'Can\'t create new task because \'' . $taskType . '\' is an invalid tasklist', | ||
| 17979 | $class . '->new', | ||
| 17980 | ); | ||
| 17981 | } | ||
| 17982 | } | ||
| 17983 | |||
| 17984 | # Task settings | ||
| 17985 | my $self = Games::Axmud::Generic::Task->new( | ||
| 17986 | $session, | ||
| 17987 | $taskType, | ||
| 17988 | $profName, | ||
| 17989 | $profCategory, | ||
| 17990 | $customName, | ||
| 17991 | ); | ||
| 17992 | |||
| 17993 | $self->{_objName} = 'inventory_task'; | ||
| 17994 | $self->{_objClass} = $class; | ||
| 17995 | $self->{_parentFile} = undef; # Set below | ||
| 17996 | $self->{_parentWorld} = undef; # Set below | ||
| 17997 | $self->{_privFlag} = TRUE, # All IVs are private | ||
| 17998 | |||
| 17999 | $self->{name} = 'inventory_task'; | ||
| 18000 | $self->{prettyName} = 'Inventory'; | ||
| 18001 | $self->{shortName} = 'Iv'; | ||
| 18002 | $self->{shortCutIV} = 'inventoryTask'; # Axmud built-in jealous task | ||
| 18003 | |||
| 18004 | $self->{category} = 'process'; | ||
| 18005 | $self->{descrip} = 'Keeps track of the character\'s inventory'; | ||
| 18006 | $self->{jealousyFlag} = TRUE; | ||
| 18007 | $self->{requireLocatorFlag} = FALSE; | ||
| 18008 | $self->{profSensitivityFlag} = TRUE; | ||
| 18009 | $self->{storableFlag} = TRUE; | ||
| 18010 | $self->{delayTime} = 0; | ||
| 18011 | $self->{allowWinFlag} = TRUE; | ||
| 18012 | $self->{requireWinFlag} = FALSE; | ||
| 18013 | $self->{startWithWinFlag} = TRUE; | ||
| 18014 | $self->{winPreferList} = ['pane', 'grid']; | ||
| 18015 | $self->{winmap} = 'basic_fill'; | ||
| 18016 | $self->{winUpdateFunc} = undef; | ||
| 18017 | $self->{tabMode} = 'simple'; | ||
| 18018 | $self->{monochromeFlag} = FALSE; | ||
| 18019 | $self->{noScrollFlag} = TRUE; | ||
| 18020 | $self->{ttsFlag} = FALSE; | ||
| 18021 | $self->{ttsConfig} = undef; | ||
| 18022 | $self->{ttsAttribHash} = {}; | ||
| 18023 | $self->{ttsFlagAttribHash} = {}; | ||
| 18024 | $self->{ttsAlertAttribHash} = {}; | ||
| 18025 | $self->{status} = 'wait_init'; | ||
| 18026 | # The task is activated when it starts, and can be disactivated (temporarily) to allow the | ||
| 18027 | # user to see the normal output of commands like 'inventory', etc | ||
| 18028 | $self->{activeFlag} = FALSE; # Task can be activated/disactivated | ||
| 18029 | # The task should be called only once per second (to give a better chance of capturing the | ||
| 18030 | # whole of the character's inventory) | ||
| 18031 | $self->{delayTime} = 1; | ||
| 18032 | |||
| 18033 | # Task parameters | ||
| 18034 | # | ||
| 18035 | # If ->activeFlag = TRUE, a list of commands that should be sent to the world, and how | ||
| 18036 | # often. The list is imported from GA::Profile::Char->inventoryCmdHash. Hash in the form | ||
| 18037 | # $cmdHash{'i'} = 60 >> the task creates a timer to send the command 'i' every 60 secs | ||
| 18038 | $self->{cmdHash} = {}; | ||
| 18039 | # The independent timer interface objects created; enable when the task is active, disabled | ||
| 18040 | # when it is disactivated. Hash in the form | ||
| 18041 | # $timerNameHash{timer_name} = timer_interface_object | ||
| 18042 | $self->{timerHash} = {}; | ||
| 18043 | # The dependent trigger interfaces created; one for non-gagged patterns, the other for | ||
| 18044 | # gagged patterns | ||
| 18045 | $self->{triggerList} = []; | ||
| 18046 | $self->{ignoreTriggerList} = []; | ||
| 18047 | |||
| 18048 | # The world profile has a ->inventoryMode IV, which tells this task how to gather the | ||
| 18049 | # character's inventory: | ||
| 18050 | # Mode 'match_all' - Use lines matching patterns in ->inventoryPatternList | ||
| 18051 | # Mode 'start_stop' - Use all lines between a 'start' and 'stop' line | ||
| 18052 | # Mode 'start_empty' - Use lines between a 'start' line and the first empty line | ||
| 18053 | # | ||
| 18054 | # This IV is used in mode 'match_all', whenever a 'stop' line is received. The next received | ||
| 18055 | # line which matches a pattern in ->inventoryPatternList causes the inventory list to be | ||
| 18056 | # reset (when a 'start' line is received, the inventory list is reset before the line is | ||
| 18057 | # processed) | ||
| 18058 | $self->{resetInventoryFlag} = FALSE; | ||
| 18059 | # | ||
| 18060 | # The following IVs are used in modes 'start_stop' and 'start_empty' | ||
| 18061 | # A list of lines matching 'start' and 'stop' patterns, in the order in which they were | ||
| 18062 | # found. Every time the task loop calls this task (default - once a second), the list | ||
| 18063 | # is processed, and then emptied. | ||
| 18064 | # In GA::Profile::World->inventoryMode 'start_stop', a list in the form | ||
| 18065 | # ('start', start_line_num, start_line_text, 'stop', stop_line_num, stop_line_text...) | ||
| 18066 | # In ->inventoryMode 'start_empty', a list in the form | ||
| 18067 | # ('start', start_line_num, start_line_text...) | ||
| 18068 | # If the world sends two inventory lists, one after the other (e.g. if we send the 'i' and | ||
| 18069 | # 'money' commands together), the list will contain more than one start line. | ||
| 18070 | # If the list contains anything at all, when this task is called, the inventory saved in | ||
| 18071 | # $self->inventoryList is reset and then refilled. If, when the list is processed, the | ||
| 18072 | # list contains more than one 'start' line, $self->inventoryList is reset for the first | ||
| 18073 | # one, but only reset for subsequent 'start' lines if those lines are the same as an | ||
| 18074 | # earlier 'start' line (so, it's safe to send 'inventory;inventory', as well as safe to | ||
| 18075 | # send 'inventory;money' - the former will only update $self->inventoryList once) | ||
| 18076 | # The list described above | ||
| 18077 | $self->{startStopList} = []; | ||
| 18078 | # As ->startStopList is being written, this flag is set to TRUE when a 'start' line is | ||
| 18079 | # found, and set back to FALSE when a 'stop' line is found | ||
| 18080 | $self->{startFlag} = FALSE; | ||
| 18081 | # As the contents of ->startStopList are processed, the text of any 'start' line is added | ||
| 18082 | # to this list, such that identical 'start' lines are not processed | ||
| 18083 | $self->{startLineTextList} = []; | ||
| 18084 | # In modes 'start_stop' & 'start_empty', a list of lines from the display buffer (matches | ||
| 18085 | # GA::Buffer::Display->modLine) which have already been processed, because they match one | ||
| 18086 | # of the patterns iN ->inventoryPatternList (and don't match one of the patterns in | ||
| 18087 | # ->inventoryIgnorePatternList). Always empty in mode 'match_all' | ||
| 18088 | $self->{useLineList} = []; | ||
| 18089 | # The display buffer number of the last line that caused one of this task's triggers to | ||
| 18090 | # fire. If a second trigger fires on the same line, it's ignored completely; only the | ||
| 18091 | # first trigger on each line is used | ||
| 18092 | $self->{lastLine} = 0; | ||
| 18093 | |||
| 18094 | # The list of things currently in the character's inventory (each element in the list is a | ||
| 18095 | # non-model object) | ||
| 18096 | $self->{inventoryList} = []; | ||
| 18097 | # The contents of ->inventoryList, the previous time the character's inventory was | ||
| 18098 | # analysed. If the Condition task was running, this previous list of things contains | ||
| 18099 | # information about their condition, which we need to preserve (because it can take | ||
| 18100 | # several minutes to test the condition of everything in the inventory, but the inventory | ||
| 18101 | # itself is usually gathered once every 60 seconds) | ||
| 18102 | $self->{previousList} = []; | ||
| 18103 | # When comparing two objects, how certain the task needs to be that it they match. | ||
| 18104 | # 0 = any objects match, 100 = only identical objects match, 70 - objects are fairly (70%) | ||
| 18105 | # similar, 90 = objects are very (90%) similar, etc | ||
| 18106 | $self->{sensitivity} = 80; | ||
| 18107 | |||
| 18108 | # Flag set to TRUE any time one of the timers fires, meaning that the task window has to | ||
| 18109 | # be refreshed (set to FALSE otherwise) | ||
| 18110 | $self->{refreshWinFlag} = FALSE; | ||
| 18111 | |||
| 18112 | # Bless task | ||
| 18113 | bless $self, $class; | ||
| 18114 | |||
| 18115 | # For all tasks that aren't temporary... | ||
| 18116 | if ($taskType) { | ||
| 18117 | |||
| 18118 | # Check that the task doesn't belong to a disabled plugin (in which case, it can't be | ||
| 18119 | # added to any current, initial or custom tasklist) | ||
| 18120 | if (! $self->checkPlugins()) { | ||
| 18121 | |||
| 18122 | return undef; | ||
| 18123 | } | ||
| 18124 | |||
| 18125 | # Set the parent file object | ||
| 18126 | $self->setParentFileObj($session, $taskType, $profName, $profCategory); | ||
| 18127 | |||
| 18128 | # Create entries in tasklists, if possible | ||
| 18129 | if (! $self->updateTaskLists($session)) { | ||
| 18130 | |||
| 18131 | return undef; | ||
| 18132 | } | ||
| 18133 | } | ||
| 18134 | |||
| 18135 | # Task creation complete | ||
| 18136 | return $self; | ||
| 18137 | } | ||
| 18138 | |||
| 18139 | sub clone { | ||
| 18140 | |||
| 18141 | # Create a clone of an existing task | ||
| 18142 | # Usually used upon connection to a world, when every task in the initial tasklists must | ||
| 18143 | # be cloned into a new object, representing a task in the current tasklist | ||
| 18144 | # (Also used when cloning a profile object, since all the tasks in its initial tasklist must | ||
| 18145 | # also be cloned) | ||
| 18146 | # | ||
| 18147 | # Expected arguments | ||
| 18148 | # $session - The parent GA::Session (not stored as an IV) | ||
| 18149 | # $taskType - Which tasklist this task is being created into - 'current' for the current | ||
| 18150 | # tasklist (tasks which are actually running now), 'initial' (tasks which | ||
| 18151 | # should be run when the user connects to the world). Custom tasks aren't | ||
| 18152 | # cloned (at the moment) | ||
| 18153 | # | ||
| 18154 | # Optional arguments | ||
| 18155 | # $profName - ($taskType = 'initial') name of the profile in whose initial tasklist the | ||
| 18156 | # existing task is stored | ||
| 18157 | # $profCategory | ||
| 18158 | # - ($taskType = 'initial') which category the profile falls under (i.e. | ||
| 18159 | # 'world', 'race', 'char', etc) | ||
| 18160 | # | ||
| 18161 | # Return values | ||
| 18162 | # 'undef' on improper arguments or if the task can't be cloned | ||
| 18163 | # Blessed reference to the newly-created object on success | ||
| 18164 | |||
| 18165 | my ($self, $session, $taskType, $profName, $profCategory, $check) = @_; | ||
| 18166 | |||
| 18167 | # Check for improper arguments | ||
| 18168 | if ( | ||
| 18169 | ! defined $session || ! defined $taskType || defined $check | ||
| 18170 | || ($taskType ne 'current' && $taskType ne 'initial') | ||
| 18171 | || ($taskType eq 'initial' && (! defined $profName || ! defined $profCategory)) | ||
| 18172 | ) { | ||
| 18173 | return $axmud::CLIENT->writeImproper($self->_objClass . '->clone', @_); | ||
| 18174 | } | ||
| 18175 | |||
| 18176 | # For initial tasks, check that $profName exists | ||
| 18177 | if ( | ||
| 18178 | $taskType eq 'initial' | ||
| 18179 | && defined $profName | ||
| 18180 | && ! $session->ivExists('profHash', $profName) | ||
| 18181 | ) { | ||
| 18182 | return $axmud::CLIENT->writeError( | ||
| 18183 | 'Can\'t create cloned task because \'' . $profName . '\' profile doesn\'t exist', | ||
| 18184 | $self->_objClass . '->clone', | ||
| 18185 | ); | ||
| 18186 | } | ||
| 18187 | |||
| 18188 | # Check that the task doesn't belong to a disabled plugin (in which case, it can't be | ||
| 18189 | # cloned) | ||
| 18190 | if (! $self->checkPlugins()) { | ||
| 18191 | |||
| 18192 | return undef; | ||
| 18193 | } | ||
| 18194 | |||
| 18195 | # Create the new task, using default settings and parameters | ||
| 18196 | my $clone = $self->_objClass->new($session, $taskType, $profName, $profCategory); | ||
| 18197 | |||
| 18198 | # Most of the cloned task's settings have default values, but a few are copied from the | ||
| 18199 | # original | ||
| 18200 | $self->cloneTaskSettings($clone); | ||
| 18201 | |||
| 18202 | # Give the new (cloned) task the same initial parameters as the original one | ||
| 18203 | $clone->{cmdHash} = {$self->cmdHash}; | ||
| 18204 | $clone->{timerHash} = {$self->timerHash}; | ||
| 18205 | $clone->{triggerList} = [$self->triggerList]; | ||
| 18206 | $clone->{ignoreTriggerList} = [$self->ignoreTriggerList]; | ||
| 18207 | |||
| 18208 | $clone->{resetInventoryFlag} = $self->resetInventoryFlag; | ||
| 18209 | |||
| 18210 | $clone->{startStopList} = [$self->startStopList]; | ||
| 18211 | $clone->{startFlag} = $self->startFlag; | ||
| 18212 | $clone->{startLineTextList} = [$self->startLineTextList]; | ||
| 18213 | $clone->{useLineList} = [$self->useLineList]; | ||
| 18214 | $clone->{lastLine} = $self->lastLine; | ||
| 18215 | |||
| 18216 | $clone->{inventoryList} = [$self->inventoryList]; | ||
| 18217 | $clone->{previousList} = [$self->previousList]; | ||
| 18218 | $clone->{sensitivity} = $self->sensitivity; | ||
| 18219 | |||
| 18220 | $clone->{refreshWinFlag} = $self->refreshWinFlag; | ||
| 18221 | |||
| 18222 | # Cloning complete | ||
| 18223 | return $clone; | ||
| 18224 | } | ||
| 18225 | |||
| 18226 | sub preserve { | ||
| 18227 | |||
| 18228 | # Called by $self->main whenever this task is reset, in order to preserve some if its task | ||
| 18229 | # parameters (but not necessarily all of them) | ||
| 18230 | # | ||
| 18231 | # Expected arguments | ||
| 18232 | # $newTask - The new task which has been created, to which some of this task's instance | ||
| 18233 | # variables might have to be transferred | ||
| 18234 | # | ||
| 18235 | # Return values | ||
| 18236 | # 'undef' on improper arguments, or if $newTask isn't in the GA::Session's current | ||
| 18237 | # tasklist | ||
| 18238 | # 1 on success | ||
| 18239 | |||
| 18240 | my ($self, $newTask, $check) = @_; | ||
| 18241 | |||
| 18242 | # Check for improper arguments | ||
| 18243 | if (! defined $newTask || defined $check) { | ||
| 18244 | |||
| 18245 | return $axmud::CLIENT->writeImproper($self->_objClass . '->preserve', @_); | ||
| 18246 | } | ||
| 18247 | |||
| 18248 | # Check the task is in the current tasklist | ||
| 18249 | if (! $self->session->ivExists('currentTaskHash', $newTask->uniqueName)) { | ||
| 18250 | |||
| 18251 | return $self->writeWarning( | ||
| 18252 | '\'' . $self->uniqueName . '\' task missing from the current tasklist', | ||
| 18253 | $self->_objClass . '->preserve', | ||
| 18254 | ); | ||
| 18255 | } | ||
| 18256 | |||
| 18257 | # Preserve some task parameters (the others are left with their default settings, some of | ||
| 18258 | # which will be re-initialised in stage 2) | ||
| 18259 | |||
| 18260 | # Preserve the inventory lists so we don't lose track of what we have in containers (like | ||
| 18261 | # sacks). Don't preserve the previous inventory | ||
| 18262 | $newTask->ivPoke('inventoryList', $self->inventoryList); | ||
| 18263 | # Preserve the sensitivity at which objects are compared | ||
| 18264 | $newTask->ivPoke('sensitivity', $self->sensitivity); | ||
| 18265 | |||
| 18266 | return 1; | ||
| 18267 | } | ||
| 18268 | |||
| 18269 | # sub setParentFileObj {} # Inherited from generic task | ||
| 18270 | |||
| 18271 | # sub updateTaskLists {} # Inherited from generic task | ||
| 18272 | |||
| 18273 | # sub ttsReadAttrib {} # Inherited from generic task | ||
| 18274 | |||
| 18275 | # sub ttsSwitchFlagAttrib {} # Inherited from generic task | ||
| 18276 | |||
| 18277 | # sub ttsSetAlertAttrib {} # Inherited from generic task | ||
| 18278 | |||
| 18279 | ################## | ||
| 18280 | # Task windows | ||
| 18281 | |||
| 18282 | # sub toggleWin {} # Inherited from generic task | ||
| 18283 | |||
| 18284 | # sub openWin {} # Inherited from generic task | ||
| 18285 | |||
| 18286 | # sub closeWin {} # Inherited from generic task | ||
| 18287 | |||
| 18288 | ################## | ||
| 18289 | # Methods | ||
| 18290 | |||
| 18291 | # sub main {} # Inherited from generic task | ||
| 18292 | |||
| 18293 | sub doShutdown { | ||
| 18294 | |||
| 18295 | # Called by $self->main, just before the task completes a shutdown | ||
| 18296 | # | ||
| 18297 | # Expected arguments | ||
| 18298 | # (none besides $self) | ||
| 18299 | # | ||
| 18300 | # Return values | ||
| 18301 | # 'undef' on improper arguments | ||
| 18302 | # 1 otherwise | ||
| 18303 | |||
| 18304 | my ($self, $check) = @_; | ||
| 18305 | |||
| 18306 | # Check for improper arguments | ||
| 18307 | if (defined $check) { | ||
| 18308 | |||
| 18309 | return $axmud::CLIENT->writeImproper($self->_objClass . '->doShutdown', @_); | ||
| 18310 | } | ||
| 18311 | |||
| 18312 | # Destroy the independent timer interfaces created by this task (which aren't destroyed | ||
| 18313 | # automatically when the task finishes) | ||
| 18314 | foreach my $obj ($self->ivValues('timerHash')) { | ||
| 18315 | |||
| 18316 | # Delete the timer. The TRUE argument means 'don't show an error message if the | ||
| 18317 | # interface has already been deleted (probably during a disconnection)' | ||
| 18318 | $self->session->deleteInterface($obj->name, TRUE); | ||
| 18319 | } | ||
| 18320 | |||
| 18321 | return 1; | ||
| 18322 | } | ||
| 18323 | |||
| 18324 | # sub doReset {} # Inherited from generic task | ||
| 18325 | |||
| 18326 | sub doFirstStage { | ||
| 18327 | |||
| 18328 | # Called by $self->main, just before the task completes the first stage ($self->stage) | ||
| 18329 | # | ||
| 18330 | # Expected arguments | ||
| 18331 | # (none besides $self) | ||
| 18332 | # | ||
| 18333 | # Return values | ||
| 18334 | # 'undef' on improper arguments | ||
| 18335 | # 1 otherwise | ||
| 18336 | |||
| 18337 | my ($self, $check) = @_; | ||
| 18338 | |||
| 18339 | # Check for improper arguments | ||
| 18340 | if (defined $check) { | ||
| 18341 | |||
| 18342 | return $axmud::CLIENT->writeImproper($self->_objClass . '->doFirstStage', @_); | ||
| 18343 | } | ||
| 18344 | |||
| 18345 | # Display a holding message in the task window, if necessary | ||
| 18346 | if (! $self->session->currentChar || ! $self->session->loginFlag) { | ||
| 18347 | |||
| 18348 | # Empty the window, and show the message | ||
| 18349 | $self->insertText('<waiting for current character and login>', 'empty'); | ||
| 18350 | } | ||
| 18351 | |||
| 18352 | return 1; | ||
| 18353 | } | ||
| 18354 | |||
| 18355 | sub doStage { | ||
| 18356 | |||
| 18357 | # Called by $self->main to process all stages (except stage 1) | ||
| 18358 | # | ||
| 18359 | # Expected arguments | ||
| 18360 | # (none besides $self) | ||
| 18361 | # | ||
| 18362 | # Return values | ||
| 18363 | # 'undef' on improper arguments or if this function sets that task's ->status IV to | ||
| 18364 | # 'finished' or sets its ->shutdownFlag to TRUE | ||
| 18365 | # Otherwise, we normally return the new value of $self->stage | ||
| 18366 | |||
| 18367 | my ($self, $check) = @_; | ||
| 18368 | |||
| 18369 | # Check for improper arguments | ||
| 18370 | if (defined $check) { | ||
| 18371 | |||
| 18372 | return $axmud::CLIENT->writeImproper($self->_objClass . '->doStage', @_); | ||
| 18373 | } | ||
| 18374 | |||
| 18375 | if ($self->stage == 2) { | ||
| 18376 | |||
| 18377 | # Can't do anything until the current character has been set and the user has logged | ||
| 18378 | # in to the world | ||
| 18379 | if (! $self->session->currentChar || ! $self->session->loginFlag) { | ||
| 18380 | |||
| 18381 | # Repeat this stage indefinitely | ||
| 18382 | return $self->ivPoke('stage', 2); | ||
| 18383 | } | ||
| 18384 | |||
| 18385 | # From the current character, import the list of commands to send periodically | ||
| 18386 | $self->ivPoke('cmdHash', $self->session->currentChar->inventoryCmdHash); | ||
| 18387 | |||
| 18388 | # The task is now active | ||
| 18389 | $self->ivPoke('activeFlag', TRUE); | ||
| 18390 | |||
| 18391 | # Set up timers and triggers | ||
| 18392 | $self->resetInterfaces(); | ||
| 18393 | |||
| 18394 | # Mark the task window as needing to be refreshed | ||
| 18395 | $self->ivPoke('refreshWinFlag', TRUE); | ||
| 18396 | |||
| 18397 | return $self->ivPoke('stage', 3); | ||
| 18398 | |||
| 18399 | } elsif ($self->stage == 3) { | ||
| 18400 | |||
| 18401 | my $worldObj; | ||
| 18402 | |||
| 18403 | # Import the current world profile | ||
| 18404 | $worldObj = $self->session->currentWorld; | ||
| 18405 | |||
| 18406 | # If the beginning and/or end of an inventory list has been detected, | ||
| 18407 | # $self->startStopList won't be empty | ||
| 18408 | if ($self->startStopList) { | ||
| 18409 | |||
| 18410 | # Update $self->inventoryList | ||
| 18411 | $self->updateInventory($worldObj); | ||
| 18412 | |||
| 18413 | # Every time this function is called (default - once a second), reset the start/ | ||
| 18414 | # stop lines and everything in between | ||
| 18415 | $self->resetLineData(); | ||
| 18416 | |||
| 18417 | # Tell this task's window to refresh, if open | ||
| 18418 | $self->ivPoke('refreshWinFlag', TRUE); | ||
| 18419 | } | ||
| 18420 | |||
| 18421 | # Refresh the task window, if any new inventory-related text has been received | ||
| 18422 | if ($self->refreshWinFlag) { | ||
| 18423 | |||
| 18424 | $self->refreshWin(); | ||
| 18425 | } | ||
| 18426 | |||
| 18427 | # Repeat this stage indefinitely | ||
| 18428 | return $self->ivPoke('stage', 3); | ||
| 18429 | |||
| 18430 | } else { | ||
| 18431 | |||
| 18432 | # The task stage has somehow been set to an invalid value | ||
| 18433 | return $self->invalidStage(); | ||
| 18434 | } | ||
| 18435 | } | ||
| 18436 | |||
| 18437 | sub activate { | ||
| 18438 | |||
| 18439 | # Called by GA::Cmd::ActivateInventory->do (not called by $self->doStage, because the task | ||
| 18440 | # is activated at stage 2, before interfaces are created) | ||
| 18441 | # Enables the interfaces created by this task | ||
| 18442 | # | ||
| 18443 | # Expected arguments | ||
| 18444 | # (none besides $self) | ||
| 18445 | # | ||
| 18446 | # Return values | ||
| 18447 | # 'undef' on improper arguments | ||
| 18448 | # 1 otherwise | ||
| 18449 | |||
| 18450 | my ($self, $check) = @_; | ||
| 18451 | |||
| 18452 | # Check for improper arguments | ||
| 18453 | if (defined $check) { | ||
| 18454 | |||
| 18455 | return $axmud::CLIENT->writeImproper($self->_objClass . '->activate', @_); | ||
| 18456 | } | ||
| 18457 | |||
| 18458 | # Enable each timer in turn | ||
| 18459 | foreach my $obj ($self->ivValues('timerHash')) { | ||
| 18460 | |||
| 18461 | $obj->modifyAttribs($self->session, 'enabled', 1); | ||
| 18462 | } | ||
| 18463 | |||
| 18464 | # Update IVs | ||
| 18465 | $self->ivPoke('activeFlag', TRUE); | ||
| 18466 | $self->ivPoke('refreshWinFlag', TRUE); | ||
| 18467 | $self->resetLineData(); | ||
| 18468 | |||
| 18469 | return 1; | ||
| 18470 | } | ||
| 18471 | |||
| 18472 | sub disactivate { | ||
| 18473 | |||
| 18474 | # Called by GA::Cmd::DisactivateInventory->do | ||
| 18475 | # Disables the interfaces created by this task | ||
| 18476 | # | ||
| 18477 | # Expected arguments | ||
| 18478 | # (none besides $self) | ||
| 18479 | # | ||
| 18480 | # Return values | ||
| 18481 | # 'undef' on improper arguments | ||
| 18482 | # 1 otherwise | ||
| 18483 | |||
| 18484 | my ($self, $check) = @_; | ||
| 18485 | |||
| 18486 | # Check for improper arguments | ||
| 18487 | if (defined $check) { | ||
| 18488 | |||
| 18489 | return $axmud::CLIENT->writeImproper($self->_objClass . '->disactivate', @_); | ||
| 18490 | } | ||
| 18491 | |||
| 18492 | # Disable each timer in turn | ||
| 18493 | foreach my $obj ($self->ivValues('timerHash')) { | ||
| 18494 | |||
| 18495 | $obj->modifyAttribs($self->session, 'enabled', 0); | ||
| 18496 | } | ||
| 18497 | |||
| 18498 | # Update IVs | ||
| 18499 | $self->ivPoke('activeFlag', FALSE); | ||
| 18500 | $self->ivPoke('refreshWinFlag', TRUE); | ||
| 18501 | $self->resetLineData(); | ||
| 18502 | |||
| 18503 | return 1; | ||
| 18504 | } | ||
| 18505 | |||
| 18506 | sub resetInterfaces { | ||
| 18507 | |||
| 18508 | # Called by $self->doStage at task stage 2, to create all the timer and trigger interfaces | ||
| 18509 | # used by this task | ||
| 18510 | # | ||
| 18511 | # Expected arguments | ||
| 18512 | # (none besides $self) | ||
| 18513 | # | ||
| 18514 | # Return values | ||
| 18515 | # 'undef' on improper arguments | ||
| 18516 | # 1 otherwise | ||
| 18517 | |||
| 18518 | my ($self, $check) = @_; | ||
| 18519 | |||
| 18520 | # Local variables | ||
| 18521 | my ( | ||
| 18522 | $worldObj, | ||
| 18523 | @list, | ||
| 18524 | %typeHash, %cmdHash, | ||
| 18525 | ); | ||
| 18526 | |||
| 18527 | # Check for improper arguments | ||
| 18528 | if (defined $check) { | ||
| 18529 | |||
| 18530 | return $axmud::CLIENT->writeImproper($self->_objClass . '->resetInterfaces', @_); | ||
| 18531 | } | ||
| 18532 | |||
| 18533 | # Import the current world profile | ||
| 18534 | $worldObj = $self->session->currentWorld; | ||
| 18535 | |||
| 18536 | # Create a hash of valid possession types (for quick lookup) | ||
| 18537 | %typeHash = ( | ||
| 18538 | 'wield' => undef, | ||
| 18539 | 'hold' => undef, | ||
| 18540 | 'wear' => undef, | ||
| 18541 | 'carry' => undef, | ||
| 18542 | 'sack' => undef, | ||
| 18543 | 'purse' => undef, | ||
| 18544 | 'deposit' => undef, | ||
| 18545 | 'deposit_only' => undef, | ||
| 18546 | 'withdraw' => undef, | ||
| 18547 | 'withdraw_only' => undef, | ||
| 18548 | 'balance' => undef, | ||
| 18549 | 'empty_purse' => undef, | ||
| 18550 | 'empty_bank' => undef, | ||
| 18551 | 'misc' => undef, | ||
| 18552 | 'ignore' => undef, | ||
| 18553 | ); | ||
| 18554 | |||
| 18555 | # The world profile stores characteristic patterns which mark text as being part of the | ||
| 18556 | # inventory list (e.g. 'You are wearing: ', 'You have .* in your purse' etc) | ||
| 18557 | # It also stores patterns which mean the whole line should be ignored; we'll create triggers | ||
| 18558 | # for those first, so that the ignorable patterns get checked before the usable patterns | ||
| 18559 | |||
| 18560 | # Set up triggers for ignorable patterns | ||
| 18561 | @list = $worldObj->inventoryIgnorePatternList; | ||
| 18562 | OUTER: while (@list) { | ||
| 18563 | |||
| 18564 | my ($pattern, $gag, $flag, $interfaceObj); | ||
| 18565 | |||
| 18566 | # The pattern to match | ||
| 18567 | $pattern = shift @list; | ||
| 18568 | # 'hide' to use a gag trigger, 'show' to use a non-gag trigger | ||
| 18569 | $gag = shift @list; | ||
| 18570 | |||
| 18571 | if ($gag eq 'show') { | ||
| 18572 | $flag = FALSE; | ||
| 18573 | } elsif ($gag eq 'hide') { | ||
| 18574 | $flag = TRUE; | ||
| 18575 | } | ||
| 18576 | |||
| 18577 | # Create the dependent trigger interface | ||
| 18578 | $interfaceObj = $self->session->createDependentInterface( | ||
| 18579 | 'trigger', | ||
| 18580 | $pattern, | ||
| 18581 | $self, | ||
| 18582 | 'ignorePatternSeen', | ||
| 18583 | 'gag', | ||
| 18584 | $flag, | ||
| 18585 | ); | ||
| 18586 | |||
| 18587 | if (! $interfaceObj) { | ||
| 18588 | |||
| 18589 | $self->writeWarning( | ||
| 18590 | 'Couldn\'t create trigger for current world profile\'s' | ||
| 18591 | . ' ->inventoryIgnorePatternList IV', | ||
| 18592 | $self->_objClass . '->resetInterfaces', | ||
| 18593 | ); | ||
| 18594 | |||
| 18595 | last OUTER; | ||
| 18596 | |||
| 18597 | } else { | ||
| 18598 | |||
| 18599 | # Store the trigger | ||
| 18600 | $self->ivPush('ignoreTriggerList', $interfaceObj); | ||
| 18601 | } | ||
| 18602 | } | ||
| 18603 | |||
| 18604 | # Set up triggers for usable patterns | ||
| 18605 | @list = $worldObj->inventoryPatternList; | ||
| 18606 | OUTER: while (@list) { | ||
| 18607 | |||
| 18608 | my ($pattern, $grpNum, $type, $gag, $posn, $flag, $interfaceObj); | ||
| 18609 | |||
| 18610 | # The pattern to match | ||
| 18611 | $pattern = shift @list; | ||
| 18612 | # Which group substring contains the data we need | ||
| 18613 | $grpNum = shift @list; | ||
| 18614 | # The type of possession: a key in %typeHash | ||
| 18615 | $type = shift @list; | ||
| 18616 | # 'hide' to use a gag trigger, 'show' to use a non-gag trigger | ||
| 18617 | $gag = shift @list; | ||
| 18618 | # 'start' if this line is always at the beginning of an inventory list; 'stop' if it is | ||
| 18619 | # always the end of an inventory list; 'optional' for any other line | ||
| 18620 | $posn = shift @list; | ||
| 18621 | |||
| 18622 | # Check that @list doesn't contain missing or extra arguments | ||
| 18623 | if ( | ||
| 18624 | ! defined $posn | ||
| 18625 | || ! exists $typeHash{$type} | ||
| 18626 | || ($gag ne 'show' && $gag ne 'hide') | ||
| 18627 | || ($posn ne 'start' && $posn ne 'stop' && $posn ne 'optional') | ||
| 18628 | ) { | ||
| 18629 | $self->writeWarning( | ||
| 18630 | 'Missing or invalid arguments in current world profile\'s' | ||
| 18631 | . ' ->inventoryPatternList IV', | ||
| 18632 | $self->_objClass . '->resetInterfaces', | ||
| 18633 | ); | ||
| 18634 | |||
| 18635 | last OUTER; | ||
| 18636 | } | ||
| 18637 | |||
| 18638 | if ($gag eq 'show') { | ||
| 18639 | $flag = FALSE; | ||
| 18640 | } elsif ($gag eq 'hide') { | ||
| 18641 | $flag = TRUE; | ||
| 18642 | } | ||
| 18643 | |||
| 18644 | # Create the dependent trigger interface | ||
| 18645 | $interfaceObj = $self->session->createDependentInterface( | ||
| 18646 | 'trigger', | ||
| 18647 | $pattern, | ||
| 18648 | $self, | ||
| 18649 | 'triggerSeen', | ||
| 18650 | 'gag', | ||
| 18651 | $flag, | ||
| 18652 | ); | ||
| 18653 | |||
| 18654 | if (! $interfaceObj) { | ||
| 18655 | |||
| 18656 | $self->writeWarning( | ||
| 18657 | 'Couldn\'t create trigger for current world profile\'s' | ||
| 18658 | . ' ->inventoryPatternList IV', | ||
| 18659 | $self->_objClass . '->resetInterfaces', | ||
| 18660 | ); | ||
| 18661 | |||
| 18662 | last OUTER; | ||
| 18663 | |||
| 18664 | } else { | ||
| 18665 | |||
| 18666 | # Store the trigger | ||
| 18667 | $self->ivPush('triggerList', $interfaceObj); | ||
| 18668 | |||
| 18669 | # Give the trigger some properties that will help $self->triggerSeen to decide | ||
| 18670 | # what to do when the trigger fires | ||
| 18671 | $interfaceObj->ivAdd('propertyHash', 'grp_num', $grpNum); | ||
| 18672 | $interfaceObj->ivAdd('propertyHash', 'inv_type', $type); | ||
| 18673 | $interfaceObj->ivAdd('propertyHash', 'position', $posn); | ||
| 18674 | } | ||
| 18675 | } | ||
| 18676 | |||
| 18677 | # Import the hash of commands to send periodically | ||
| 18678 | %cmdHash = $self->cmdHash; | ||
| 18679 | OUTER: foreach my $cmd (keys %cmdHash) { | ||
| 18680 | |||
| 18681 | my ($interval, $interfaceObj); | ||
| 18682 | |||
| 18683 | # The interval is how many seconds to wait before re-sending the same command | ||
| 18684 | $interval = $cmdHash{$cmd}; | ||
| 18685 | |||
| 18686 | # Each command should be sent for the first time right now | ||
| 18687 | $self->session->worldCmd($cmd); | ||
| 18688 | |||
| 18689 | # Create independent timers to send the command to the world every few seconds | ||
| 18690 | $interfaceObj = $self->session->createIndependentInterface( | ||
| 18691 | 'timer', | ||
| 18692 | $interval, # Stimulus | ||
| 18693 | $cmd, # Response | ||
| 18694 | ); | ||
| 18695 | |||
| 18696 | if (! $interfaceObj) { | ||
| 18697 | |||
| 18698 | $self->writeWarning( | ||
| 18699 | 'Couldn\'t create timer for current character profile\'s' | ||
| 18700 | . ' ->inventoryCmdHash IV', | ||
| 18701 | $self->_objClass . '->resetInterfaces', | ||
| 18702 | ); | ||
| 18703 | |||
| 18704 | last OUTER; | ||
| 18705 | |||
| 18706 | } else { | ||
| 18707 | |||
| 18708 | # Store the timer | ||
| 18709 | $self->ivAdd('timerHash', $cmd, $interfaceObj); | ||
| 18710 | } | ||
| 18711 | } | ||
| 18712 | |||
| 18713 | # Reset complete | ||
| 18714 | return 1; | ||
| 18715 | } | ||
| 18716 | |||
| 18717 | sub updateInventory { | ||
| 18718 | |||
| 18719 | # Called by $self->doStage at task stage 3 to update the character's inventory based on | ||
| 18720 | # the information stored in $self->startStopList | ||
| 18721 | # | ||
| 18722 | # Expected arguments | ||
| 18723 | # $worldObj - The current world profile object | ||
| 18724 | # | ||
| 18725 | # Return values | ||
| 18726 | # 'undef' on improper arguments or if there is an error | ||
| 18727 | # 1 otherwise | ||
| 18728 | |||
| 18729 | my ($self, $worldObj, $check) = @_; | ||
| 18730 | |||
| 18731 | # Local variables | ||
| 18732 | my @startStopList; | ||
| 18733 | |||
| 18734 | # Check for improper arguments | ||
| 18735 | if (! defined $worldObj || defined $check) { | ||
| 18736 | |||
| 18737 | return $axmud::CLIENT->writeImproper($self->_objClass . '->updateInventory', @_); | ||
| 18738 | } | ||
| 18739 | |||
| 18740 | # In GA::Profile::World->inventoryMode 'start_stop', $self->startStopList is in the form | ||
| 18741 | # ('start', start_line_num, start_line_text, 'stop', stop_line_num, stop_line_text...) | ||
| 18742 | # In ->inventoryMode 'start_empty', $self->startStopList is in the form | ||
| 18743 | # ('start', start_line_num, start_line_text...) | ||
| 18744 | # Import $self->startStopList | ||
| 18745 | @startStopList = $self->startStopList; | ||
| 18746 | |||
| 18747 | do { | ||
| 18748 | |||
| 18749 | my ( | ||
| 18750 | $startType, $startLineNum, $startLineText, $stopType, $stopLineNum, $stopLineText, | ||
| 18751 | $matchFlag, $lineNum, $exitFlag, | ||
| 18752 | @lineTextList, | ||
| 18753 | ); | ||
| 18754 | |||
| 18755 | # Remove the 'start' line data | ||
| 18756 | $startType = shift @startStopList; | ||
| 18757 | $startLineNum = shift @startStopList; | ||
| 18758 | $startLineText = shift @startStopList; | ||
| 18759 | |||
| 18760 | if ($startType ne 'start') { | ||
| 18761 | |||
| 18762 | # List is corrupted | ||
| 18763 | return undef; | ||
| 18764 | } | ||
| 18765 | |||
| 18766 | # Remove the 'stop' line data, if it exists | ||
| 18767 | if (@startStopList && $startStopList[0] eq 'stop') { | ||
| 18768 | |||
| 18769 | $stopType = shift @startStopList; | ||
| 18770 | $stopLineNum = shift @startStopList; | ||
| 18771 | $stopLineText = shift @startStopList; | ||
| 18772 | } | ||
| 18773 | |||
| 18774 | # This function may have to cope with several inventory lists, one after the other. For | ||
| 18775 | # example, the user might type 'money;i' which sends us two inventory lists, which | ||
| 18776 | # must be combined. The user might also type 'i;i;i' which sends us three identical | ||
| 18777 | # inventory lists; each successive 'i' overwrites the ->inventoryList compiled by the | ||
| 18778 | # previous one | ||
| 18779 | # Check $startLineText against all other $startLineTexts received recently | ||
| 18780 | if ($self->startLineTextList) { | ||
| 18781 | |||
| 18782 | OUTER: foreach my $otherText ($self->startLineTextList) { | ||
| 18783 | |||
| 18784 | if ($otherText eq $startLineText) { | ||
| 18785 | |||
| 18786 | # This is the second time a line matching a particular 'start' pattern has | ||
| 18787 | # been found; to avoid duplication of an object, we have to empty the | ||
| 18788 | # whole list | ||
| 18789 | $self->ivEmpty('inventoryList'); | ||
| 18790 | $matchFlag = TRUE; | ||
| 18791 | |||
| 18792 | last OUTER; | ||
| 18793 | } | ||
| 18794 | } | ||
| 18795 | } | ||
| 18796 | |||
| 18797 | # Record this start line text for the next spin of this DO loop (unless it's already | ||
| 18798 | # been added to $self->startLineTextList) | ||
| 18799 | if (! $matchFlag) { | ||
| 18800 | |||
| 18801 | $self->ivPush('startLineTextList', $startLineText); | ||
| 18802 | } | ||
| 18803 | |||
| 18804 | # When the triggers that matched the 'start' line (and/or 'stop' line) fire, they record | ||
| 18805 | # the size of the GA::Session's display buffer at that point - BEFORE the line is | ||
| 18806 | # added to the display buffer. As a result, the number of the actual display buffer | ||
| 18807 | # line that caused the trigger to fire is currently unknown (the best we can say is | ||
| 18808 | # that the value isn't lower than $startLineNum / $stopLineNum, respectively) | ||
| 18809 | # Find the actual line numbers | ||
| 18810 | $startLineNum = $self->findMatchingLine($startLineNum, $startLineText); | ||
| 18811 | if ($stopLineNum) { | ||
| 18812 | |||
| 18813 | $stopLineNum = $self->findMatchingLine($stopLineNum, $stopLineText); | ||
| 18814 | } | ||
| 18815 | |||
| 18816 | # Depending on the value of GA::Profile::World->inventoryMode, we may have to process | ||
| 18817 | # lines from the display buffer, adding them to the inventory list | ||
| 18818 | if ( | ||
| 18819 | $worldObj->inventoryMode eq 'start_stop' | ||
| 18820 | && $startLineNum && $stopLineNum | ||
| 18821 | # Must be at least one line between the start/stop lines | ||
| 18822 | && $startLineNum < ($stopLineNum - 1) | ||
| 18823 | ) { | ||
| 18824 | # Compile a list of display buffer lines between the 'start' and 'stop' lines | ||
| 18825 | # (inclusive), but ignore lines that have already been processed | ||
| 18826 | OUTER: for (my $count = $startLineNum; $count < $stopLineNum; $count++) { | ||
| 18827 | |||
| 18828 | my $bufferObj = $self->session->ivShow('displayBufferHash', $count); | ||
| 18829 | if ($bufferObj) { | ||
| 18830 | |||
| 18831 | # Has this line already been processed? | ||
| 18832 | INNER: foreach my $string ($self->useLineList) { | ||
| 18833 | |||
| 18834 | if ($string eq $bufferObj->modLine) { | ||
| 18835 | |||
| 18836 | # This line already processed | ||
| 18837 | next OUTER; | ||
| 18838 | } | ||
| 18839 | } | ||
| 18840 | |||
| 18841 | # The line hasn't been processed yet | ||
| 18842 | push (@lineTextList, $bufferObj->modLine); | ||
| 18843 | } | ||
| 18844 | } | ||
| 18845 | |||
| 18846 | } elsif ( | ||
| 18847 | $worldObj->inventoryMode eq 'start_empty' | ||
| 18848 | && $startLineNum | ||
| 18849 | # The start line isn't the last line in the buffer | ||
| 18850 | && $startLineNum < $self->session->displayBufferLast | ||
| 18851 | ) { | ||
| 18852 | # Compile a list of display buffer lines between the 'start' and either the first | ||
| 18853 | # empty line, or the last line in the display buffer | ||
| 18854 | $lineNum = $startLineNum - 1; # First line to check is $startLine | ||
| 18855 | do { | ||
| 18856 | |||
| 18857 | my ($bufferObj, $lineText, $matchFlag); | ||
| 18858 | |||
| 18859 | $lineNum++; | ||
| 18860 | |||
| 18861 | $bufferObj = $self->session->ivShow('displayBufferHash', $lineNum); | ||
| 18862 | if (! $bufferObj) { | ||
| 18863 | |||
| 18864 | # End of the buffer reached, or missing line | ||
| 18865 | $exitFlag = TRUE; | ||
| 18866 | |||
| 18867 | } else { | ||
| 18868 | |||
| 18869 | $lineText = $bufferObj->modLine; | ||
| 18870 | if (! ($lineText =~ m/\w/)) { | ||
| 18871 | |||
| 18872 | # First empty line found; stop looking here | ||
| 18873 | $exitFlag = TRUE; | ||
| 18874 | } | ||
| 18875 | } | ||
| 18876 | |||
| 18877 | if (! $exitFlag) { | ||
| 18878 | |||
| 18879 | # Has this line already been processed? | ||
| 18880 | INNER: foreach my $string ($self->useLineList) { | ||
| 18881 | |||
| 18882 | if ($string eq $lineText) { | ||
| 18883 | |||
| 18884 | # This line already processed | ||
| 18885 | $matchFlag = TRUE; | ||
| 18886 | last INNER; | ||
| 18887 | } | ||
| 18888 | } | ||
| 18889 | |||
| 18890 | if (! $matchFlag) { | ||
| 18891 | |||
| 18892 | # The line hasn't been processed yet | ||
| 18893 | push (@lineTextList, $bufferObj->modLine); | ||
| 18894 | } | ||
| 18895 | } | ||
| 18896 | |||
| 18897 | } until ($exitFlag); | ||
| 18898 | } | ||
| 18899 | |||
| 18900 | if (@lineTextList) { | ||
| 18901 | |||
| 18902 | # Process every unprocessed line | ||
| 18903 | foreach my $lineText (@lineTextList) { | ||
| 18904 | |||
| 18905 | $self->processString($lineText); | ||
| 18906 | } | ||
| 18907 | } | ||
| 18908 | |||
| 18909 | } until (! @startStopList); | ||
| 18910 | |||
| 18911 | return 1; | ||
| 18912 | } | ||
| 18913 | |||
| 18914 | sub findMatchingLine { | ||
| 18915 | |||
| 18916 | # Called by $self->updateInventory | ||
| 18917 | # When $self->triggerSeen is called, one of this task's triggers has fired; but the | ||
| 18918 | # matching line is not stored in the GA::Session's display buffer until later on, when all | ||
| 18919 | # triggers have been tested. As a result, we don't know the display buffer line number of | ||
| 18920 | # the line that caused the trigger to fire | ||
| 18921 | # This function finds the number of the display buffer line matching a specified string | ||
| 18922 | # | ||
| 18923 | # Expected arguments | ||
| 18924 | # $initLineNum - The size of the display buffer some time before the trigger fired; we | ||
| 18925 | # know that the matching line number must be equal or greater than | ||
| 18926 | # this value | ||
| 18927 | # $lineText - The text of the line that caused the trigger to fire | ||
| 18928 | # | ||
| 18929 | # Return values | ||
| 18930 | # 'undef' on improper arguments or if the line number can't be found | ||
| 18931 | # Otherwise returns the display buffer line number of the matching line | ||
| 18932 | |||
| 18933 | my ($self, $initLineNum, $lineText, $check) = @_; | ||
| 18934 | |||
| 18935 | # Local variables | ||
| 18936 | my $exitFlag; | ||
| 18937 | |||
| 18938 | # Check for improper arguments | ||
| 18939 | if (! defined $initLineNum || ! defined $lineText || defined $check) { | ||
| 18940 | |||
| 18941 | return $axmud::CLIENT->writeImproper($self->_objClass . '->findMatchingLine', @_); | ||
| 18942 | } | ||
| 18943 | |||
| 18944 | # Subtract one, so that the first iteration checks $initLineNum | ||
| 18945 | $initLineNum--; | ||
| 18946 | |||
| 18947 | do { | ||
| 18948 | |||
| 18949 | my ($bufferObj); | ||
| 18950 | |||
| 18951 | $initLineNum++; | ||
| 18952 | |||
| 18953 | $bufferObj = $self->session->ivShow('displayBufferHash', $initLineNum); | ||
| 18954 | if (! $bufferObj) { | ||
| 18955 | |||
| 18956 | # We've reached the end of the buffer, without finding a matching line. Report an | ||
| 18957 | # error to the calling function | ||
| 18958 | return undef; | ||
| 18959 | |||
| 18960 | } elsif ($bufferObj->modLine eq $lineText) { | ||
| 18961 | |||
| 18962 | # This is the line we're looking for | ||
| 18963 | return $initLineNum; | ||
| 18964 | } | ||
| 18965 | |||
| 18966 | } until (0); | ||
| 18967 | } | ||
| 18968 | |||
| 18969 | sub processString { | ||
| 18970 | |||
| 18971 | # Called by $self->updateInventory or $self->triggerSeen | ||
| 18972 | # Given a string which contains (exclusively) objects in the character's inventory, process | ||
| 18973 | # the string and store the objects | ||
| 18974 | # | ||
| 18975 | # Expected arguments | ||
| 18976 | # $string - The string to process | ||
| 18977 | # | ||
| 18978 | # Optional arguments | ||
| 18979 | # $type - When called by $self->triggerSeen, the inventory type ('wield', 'hold', | ||
| 18980 | # 'wear', 'carry', 'sack', purse', 'deposit', 'deposit_only', 'withdraw', | ||
| 18981 | # 'withdraw_only', 'balance', 'empty_purse', 'empty_bank', 'misc', | ||
| 18982 | # 'ignore'). If 'undef', 'carry' is used as a default inventory type | ||
| 18983 | # | ||
| 18984 | # Return values | ||
| 18985 | # 'undef' on improper arguments or if the string is empty | ||
| 18986 | # 1 otherwise | ||
| 18987 | |||
| 18988 | my ($self, $string, $type, $check) = @_; | ||
| 18989 | |||
| 18990 | # Local variables | ||
| 18991 | my ( | ||
| 18992 | $statusObj, $modelObj, $worldObj, $cashValue, | ||
| 18993 | @patternList, @stringList, @modList, | ||
| 18994 | ); | ||
| 18995 | |||
| 18996 | # Check for improper arguments | ||
| 18997 | if (! defined $string || defined $check) { | ||
| 18998 | |||
| 18999 | return $axmud::CLIENT->writeImproper($self->_objClass . '->processString', @_); | ||
| 19000 | } | ||
| 19001 | |||
| 19002 | # Don't process an empty string | ||
| 19003 | if (! $string) { | ||
| 19004 | |||
| 19005 | return undef; | ||
| 19006 | } | ||
| 19007 | |||
| 19008 | # Import Perl objects (for speed) | ||
| 19009 | $statusObj = $self->session->statusTask; | ||
| 19010 | $modelObj = $self->session->worldModelObj; | ||
| 19011 | $worldObj = $self->session->currentWorld; | ||
| 19012 | |||
| 19013 | # The default inventory type is 'carry' | ||
| 19014 | if (! defined $type) { | ||
| 19015 | |||
| 19016 | $type = 'carry'; | ||
| 19017 | } | ||
| 19018 | |||
| 19019 | # The world profile provides patterns which specify portions of $string that can be | ||
| 19020 | # discarded | ||
| 19021 | # This time, all patterns are matched against $string, and all matching portions are | ||
| 19022 | # discarded | ||
| 19023 | @patternList = $worldObj->inventoryDiscardPatternList; | ||
| 19024 | if (@patternList) { | ||
| 19025 | |||
| 19026 | do { | ||
| 19027 | |||
| 19028 | my $pattern = shift @patternList; | ||
| 19029 | $string =~ s/$pattern//; | ||
| 19030 | |||
| 19031 | } until (! @patternList); | ||
| 19032 | } | ||
| 19033 | |||
| 19034 | # The world profile provides patterns which should be applied in a Perl split operation, | ||
| 19035 | # discarding the matching portions and using everything between them as separate objects | ||
| 19036 | push (@stringList, $string); | ||
| 19037 | foreach my $pattern ($worldObj->inventorySplitPatternList) { | ||
| 19038 | |||
| 19039 | foreach my $item (@stringList) { | ||
| 19040 | |||
| 19041 | push (@modList, split(/$pattern/, $item)); | ||
| 19042 | } | ||
| 19043 | |||
| 19044 | @stringList = @modList; | ||
| 19045 | @modList = (); | ||
| 19046 | } | ||
| 19047 | |||
| 19048 | # If $string has been split into multiple strings, apply the same $type to all of them | ||
| 19049 | foreach my $item (@stringList) { | ||
| 19050 | |||
| 19051 | my @objList; | ||
| 19052 | |||
| 19053 | # For carried objects in an inventory list... | ||
| 19054 | if ( | ||
| 19055 | $type eq 'wield' || $type eq 'hold' || $type eq 'wear' || $type eq 'carry' | ||
| 19056 | || $type eq 'sack' || $type eq 'misc' | ||
| 19057 | ) { | ||
| 19058 | # Convert the matched string into a list of non-model objects | ||
| 19059 | push (@objList, $modelObj->parseObj($self->session, FALSE, $item)); | ||
| 19060 | |||
| 19061 | OUTER: foreach my $obj (@objList) { | ||
| 19062 | |||
| 19063 | my ( | ||
| 19064 | $count, $index, | ||
| 19065 | @previousList, | ||
| 19066 | ); | ||
| 19067 | |||
| 19068 | # Add the object to this task's inventory list | ||
| 19069 | $self->ivPush('inventoryList', $obj); | ||
| 19070 | # Set the object's inventory type | ||
| 19071 | $obj->ivPoke('inventoryType', $type); | ||
| 19072 | |||
| 19073 | # Compare $obj against everything in the previous inventory list. If a match is | ||
| 19074 | # found, remove the equivalent object from the previous inventory list, but | ||
| 19075 | # copy its condition (if set) to $obj | ||
| 19076 | @previousList = $self->previousList; # We're going to splice the IV | ||
| 19077 | $count = -1; | ||
| 19078 | |||
| 19079 | INNER: foreach my $oldObj (@previousList) { | ||
| 19080 | |||
| 19081 | $count++; | ||
| 19082 | if ($modelObj->objCompare($self->sensitivity, $obj, $oldObj)) { | ||
| 19083 | |||
| 19084 | # $obj was also present in the previous list. Remove the entry from that | ||
| 19085 | # list | ||
| 19086 | |||
| 19087 | # Remove the entry in the previous list | ||
| 19088 | $index = $self->ivFind('previousList', $oldObj); | ||
| 19089 | if (defined $index) { | ||
| 19090 | |||
| 19091 | $self->ivSplice('previousList', $index, 1); | ||
| 19092 | } | ||
| 19093 | |||
| 19094 | # If $oldObj had a condition set, copy it to the current object | ||
| 19095 | if (defined $oldObj->condition) { | ||
| 19096 | |||
| 19097 | $obj->ivPoke('condition', $oldObj->condition); | ||
| 19098 | } | ||
| 19099 | |||
| 19100 | # Only need to copy one condition setting per object | ||
| 19101 | next OUTER; | ||
| 19102 | } | ||
| 19103 | } | ||
| 19104 | } | ||
| 19105 | |||
| 19106 | # For all lines representing money.. | ||
| 19107 | } elsif ($type ne 'ignore') { | ||
| 19108 | |||
| 19109 | if ($type eq 'empty') { | ||
| 19110 | |||
| 19111 | $cashValue = 0; | ||
| 19112 | |||
| 19113 | } else { | ||
| 19114 | |||
| 19115 | # Convert the value into the standard currency unit (defined by the current | ||
| 19116 | # world profile) | ||
| 19117 | $cashValue = $self->convertCash($item); | ||
| 19118 | } | ||
| 19119 | |||
| 19120 | if (defined $cashValue) { | ||
| 19121 | |||
| 19122 | # Update the Status task, if it is running | ||
| 19123 | if ($statusObj) { | ||
| 19124 | |||
| 19125 | $statusObj->set_cashValues($type, $cashValue); | ||
| 19126 | } | ||
| 19127 | } | ||
| 19128 | } | ||
| 19129 | } | ||
| 19130 | |||
| 19131 | return 1; | ||
| 19132 | } | ||
| 19133 | |||
| 19134 | sub resetLineData { | ||
| 19135 | |||
| 19136 | # Called by several of this task's functions | ||
| 19137 | # Resets IVs that store information about display buffer lines which contain the character's | ||
| 19138 | # inventory | ||
| 19139 | # | ||
| 19140 | # Expected arguments | ||
| 19141 | # (none besides $self) | ||
| 19142 | # | ||
| 19143 | # Return values | ||
| 19144 | # 'undef' on improper arguments | ||
| 19145 | # 1 otherwise | ||
| 19146 | |||
| 19147 | my ($self, $check) = @_; | ||
| 19148 | |||
| 19149 | # Check for improper arguments | ||
| 19150 | if (defined $check) { | ||
| 19151 | |||
| 19152 | return $axmud::CLIENT->writeImproper($self->_objClass . '->resetLineData', @_); | ||
| 19153 | } | ||
| 19154 | |||
| 19155 | $self->ivPoke('resetInventoryFlag', FALSE); | ||
| 19156 | |||
| 19157 | $self->ivEmpty('startStopList'); | ||
| 19158 | $self->ivPoke('startFlag', FALSE); | ||
| 19159 | $self->ivEmpty('startLineTextList'); | ||
| 19160 | $self->ivEmpty('useLineList'); | ||
| 19161 | |||
| 19162 | return 1; | ||
| 19163 | } | ||
| 19164 | |||
| 19165 | sub refreshWin { | ||
| 19166 | |||
| 19167 | # Called by $self->doStage (at stage 3) | ||
| 19168 | # Refreshes the task window (if it is open) | ||
| 19169 | # | ||
| 19170 | # Expected arguments | ||
| 19171 | # (none besides $self) | ||
| 19172 | # | ||
| 19173 | # Return values | ||
| 19174 | # 'undef' on improper arguments or if the task window isn't open | ||
| 19175 | # 1 otherwise | ||
| 19176 | |||
| 19177 | my ($self, $check) = @_; | ||
| 19178 | |||
| 19179 | # Local variables | ||
| 19180 | my ( | ||
| 19181 | $worldModelObj, | ||
| 19182 | @inventoryList, @modList, @protectList, @monitorList, | ||
| 19183 | %inventoryHash, | ||
| 19184 | ); | ||
| 19185 | |||
| 19186 | # Check for improper arguments | ||
| 19187 | if (defined $check) { | ||
| 19188 | |||
| 19189 | return $axmud::CLIENT->writeImproper($self->_objClass . '->refreshWin', @_); | ||
| 19190 | } | ||
| 19191 | |||
| 19192 | # Don't do anything if the task window isn't open | ||
| 19193 | if (! $self->taskWinFlag) { | ||
| 19194 | |||
| 19195 | return undef; | ||
| 19196 | } | ||
| 19197 | |||
| 19198 | # Empty the task window, and write the first line of text | ||
| 19199 | if ($self->activeFlag) { | ||
| 19200 | |||
| 19201 | $self->insertText( | ||
| 19202 | 'Inv task activated (* protected @ monitored)', | ||
| 19203 | 'empty', | ||
| 19204 | 'white', | ||
| 19205 | ); | ||
| 19206 | |||
| 19207 | } else { | ||
| 19208 | |||
| 19209 | $self->insertText('Inv task disactivated', 'empty', 'white'); | ||
| 19210 | } | ||
| 19211 | |||
| 19212 | # Import the protected and monitored object lists | ||
| 19213 | @protectList = $self->session->currentChar->protectObjList; | ||
| 19214 | @monitorList = $self->session->currentChar->monitorObjList; | ||
| 19215 | # Import the world model | ||
| 19216 | $worldModelObj = $self->session->worldModelObj; | ||
| 19217 | |||
| 19218 | # Import the inventory, and eliminate duplicates; instead, compile a hash showing the | ||
| 19219 | # number of identical copies of each type of object | ||
| 19220 | @inventoryList = $self->inventoryList; | ||
| 19221 | foreach my $obj (@inventoryList) { | ||
| 19222 | |||
| 19223 | if (exists $inventoryHash{$obj->baseString}) { | ||
| 19224 | |||
| 19225 | # This is a duplicate | ||
| 19226 | $inventoryHash{$obj->baseString} = $inventoryHash{$obj->baseString} + 1; | ||
| 19227 | |||
| 19228 | } else { | ||
| 19229 | |||
| 19230 | # First occurence of this object | ||
| 19231 | push (@modList, $obj); | ||
| 19232 | $inventoryHash{$obj->baseString} = 1; | ||
| 19233 | } | ||
| 19234 | } | ||
| 19235 | |||
| 19236 | # Write a line of text for each unique item in the inventory | ||
| 19237 | OUTER: foreach my $obj (@modList) { | ||
| 19238 | |||
| 19239 | my ( | ||
| 19240 | $line, $nounString, $otherNounString, $adjString, $unknownWordString, $multiple, | ||
| 19241 | $condition, | ||
| 19242 | ); | ||
| 19243 | |||
| 19244 | # Check whether the object is on the protected object list | ||
| 19245 | if ( | ||
| 19246 | @protectList | ||
| 19247 | && $worldModelObj->objCompare($self->sensitivity, $obj, @protectList) | ||
| 19248 | ) { | ||
| 19249 | $line = '*'; # $obj matches a protected object | ||
| 19250 | } else { | ||
| 19251 | $line = ' '; # $obj doesn't match a protected object | ||
| 19252 | } | ||
| 19253 | |||
| 19254 | # Check whether the object is on the monitored object list | ||
| 19255 | if (! $self->session->conditionTask) { | ||
| 19256 | |||
| 19257 | # When the Condition task is not running, no objects are monitored | ||
| 19258 | $line .= ' '; | ||
| 19259 | |||
| 19260 | } elsif (! @monitorList) { | ||
| 19261 | |||
| 19262 | # If the monitored object list is empty, all objects are monitored | ||
| 19263 | $line .= '@'; | ||
| 19264 | |||
| 19265 | } elsif ($worldModelObj->objCompare($self->sensitivity, $obj, @monitorList)) { | ||
| 19266 | |||
| 19267 | $line .= '@'; # $obj matches a monitored object | ||
| 19268 | |||
| 19269 | } else { | ||
| 19270 | |||
| 19271 | $line .= ' '; # $obj doesn't match a monitored object | ||
| 19272 | } | ||
| 19273 | |||
| 19274 | # Add a letter to show whether the object is wielded, worn, etc | ||
| 19275 | if ($obj->inventoryType eq 'wield') { | ||
| 19276 | $line .= 'W '; | ||
| 19277 | } elsif ($obj->inventoryType eq 'hold') { | ||
| 19278 | $line .= 'H '; | ||
| 19279 | } elsif ($obj->inventoryType eq 'wear') { | ||
| 19280 | $line .= 'R '; | ||
| 19281 | } elsif ($obj->inventoryType eq 'carry') { | ||
| 19282 | $line .= 'C '; | ||
| 19283 | } elsif ($obj->inventoryType eq 'sack') { | ||
| 19284 | $line .= 'S '; | ||
| 19285 | } elsif ($obj->inventoryType eq 'misc') { | ||
| 19286 | $line .= '- '; | ||
| 19287 | } else { | ||
| 19288 | |||
| 19289 | # Invalid value for ->inventoryType | ||
| 19290 | $line .= ' '; | ||
| 19291 | } | ||
| 19292 | |||
| 19293 | # Convert the object's word lists into strings, with each word separated by a space | ||
| 19294 | $nounString = $obj->noun; | ||
| 19295 | $otherNounString = join(' ', $obj->otherNounList); | ||
| 19296 | $adjString = join(' ', $obj->adjList, $obj->pseudoAdjList); | ||
| 19297 | $unknownWordString = join(' ', $obj->unknownWordList); | ||
| 19298 | $multiple = $obj->multiple; | ||
| 19299 | $condition = $obj->condition; | ||
| 19300 | |||
| 19301 | # Display the information, in a single line, in different colours | ||
| 19302 | $self->insertText($line . $nounString, 'white'); | ||
| 19303 | |||
| 19304 | if ($otherNounString) { | ||
| 19305 | |||
| 19306 | $self->insertText(' ' . $otherNounString, 'echo', 'yellow'); | ||
| 19307 | } | ||
| 19308 | |||
| 19309 | if ($adjString) { | ||
| 19310 | |||
| 19311 | $self->insertText(' ' .$adjString, 'echo', 'green'); | ||
| 19312 | } | ||
| 19313 | |||
| 19314 | if ($unknownWordString) { | ||
| 19315 | |||
| 19316 | $self->insertText(' ' . $unknownWordString, 'echo', 'magenta'); | ||
| 19317 | } | ||
| 19318 | |||
| 19319 | if ($multiple != 1 && $multiple > 0) { | ||
| 19320 | $self->insertText(' [' . $multiple . ']', 'echo', 'white'); | ||
| 19321 | } elsif ($multiple == -1) { | ||
| 19322 | $self->insertText(' [m]', 'echo', 'white'); | ||
| 19323 | } | ||
| 19324 | |||
| 19325 | if (defined $condition) { | ||
| 19326 | |||
| 19327 | $self->insertText(' <' . $condition . '>', 'echo', 'white'); | ||
| 19328 | } | ||
| 19329 | |||
| 19330 | if ($inventoryHash{$obj->baseString} > 1) { | ||
| 19331 | |||
| 19332 | $self->insertText( | ||
| 19333 | ' [' . $inventoryHash{$obj->baseString} . ']', 'echo', 'white', | ||
| 19334 | ); | ||
| 19335 | } | ||
| 19336 | } | ||
| 19337 | |||
| 19338 | # Refresh finished | ||
| 19339 | $self->ivPoke('refreshWinFlag', FALSE); | ||
| 19340 | |||
| 19341 | return 1; | ||
| 19342 | } | ||
| 19343 | |||
| 19344 | sub convertCash { | ||
| 19345 | |||
| 19346 | # Called by $self->triggerSeen | ||
| 19347 | # Converts a list of cash values (e.g. '135 gold, 5 silver and 15 bronze coins') into a | ||
| 19348 | # single value in the unit specified by the current world profile's | ||
| 19349 | # ->standardCurrencyUnit | ||
| 19350 | # | ||
| 19351 | # e.g. If the world's ->currencyHash defines the following exchange values: | ||
| 19352 | # Gold = 1, Silver = 0.1, Bronze = 0.01 | ||
| 19353 | # ...then the sum above would be 135.65 gold coins | ||
| 19354 | # | ||
| 19355 | # Expected arguments | ||
| 19356 | # @lines - A list of lines received from the world (most of the time it's only one line) | ||
| 19357 | # | ||
| 19358 | # Return values | ||
| 19359 | # 'undef' on improper arguments, if the list of @lines is empty or if no cash value can be | ||
| 19360 | # calculated | ||
| 19361 | # Otherwise, returns the equivalent cash value in the standard unit (which might be 0) | ||
| 19362 | |||
| 19363 | my ($self, @lines) = @_; | ||
| 19364 | |||
| 19365 | # Local variables | ||
| 19366 | my ( | ||
| 19367 | $returnValue, $matchFlag, | ||
| 19368 | @objList, | ||
| 19369 | %currencyHash, | ||
| 19370 | ); | ||
| 19371 | |||
| 19372 | # Check for improper arguments | ||
| 19373 | if (! @lines) { | ||
| 19374 | |||
| 19375 | return $axmud::CLIENT->writeImproper($self->_objClass . '->convertCash', @_); | ||
| 19376 | } | ||
| 19377 | |||
| 19378 | # Import the world profile's currency hash. Hash in the form | ||
| 19379 | # $currencyHash{'gold'} = 1; | ||
| 19380 | %currencyHash = $self->session->currentWorld->currencyHash; | ||
| 19381 | |||
| 19382 | # Convert the lines into a list of non-model objects, one object for each denomination | ||
| 19383 | # (i.e. one object for the 135 gold coins, one for the 5 silver, one for the 15 bronze) | ||
| 19384 | # (The TRUE flag tells the function to convert '5 coins' into a single object, with its | ||
| 19385 | # ->multiple flag set to 5) | ||
| 19386 | @objList = $self->session->worldModelObj->parseObj($self->session, TRUE, @lines); | ||
| 19387 | if (! @objList) { | ||
| 19388 | |||
| 19389 | # No objects were found in any of the lines | ||
| 19390 | return undef; | ||
| 19391 | } | ||
| 19392 | |||
| 19393 | # For each object, check the nouns, adjectives and unknown words against a known | ||
| 19394 | # denomination (a key in %currencyHash) | ||
| 19395 | $returnValue = 0; | ||
| 19396 | OUTER: foreach my $obj (@objList) { | ||
| 19397 | |||
| 19398 | # Compile a list of all the words that describe this object | ||
| 19399 | my @wordList = ( | ||
| 19400 | $obj->noun, $obj->otherNounList, $obj->adjList, | ||
| 19401 | $obj->pseudoAdjList, $obj->rootAdjList, $obj->unknownWordList, | ||
| 19402 | ); | ||
| 19403 | |||
| 19404 | # Ignore objects whose ->multiple isn't above zero (-1 means 'some') | ||
| 19405 | if ($obj->multiple <= 0) { | ||
| 19406 | |||
| 19407 | next OUTER; | ||
| 19408 | } | ||
| 19409 | |||
| 19410 | # Check each describing word in turn | ||
| 19411 | INNER: foreach my $word (@wordList) { | ||
| 19412 | |||
| 19413 | if (exists $currencyHash{$word}) { | ||
| 19414 | |||
| 19415 | # Convert the coin (or coins) into the equivalent value in the standard | ||
| 19416 | # denomination (e.g. convert 5 silver coins into 0.5 gold coins), and add it | ||
| 19417 | # to the running total | ||
| 19418 | $returnValue += ($currencyHash{$word} * $obj->multiple); | ||
| 19419 | # At least one match found | ||
| 19420 | $matchFlag = TRUE; | ||
| 19421 | # Use the first matching word found - don't keep looking | ||
| 19422 | next OUTER; | ||
| 19423 | } | ||
| 19424 | } | ||
| 19425 | } | ||
| 19426 | |||
| 19427 | if (! $matchFlag) { | ||
| 19428 | |||
| 19429 | # Nothing in @lines contains a recognisable cash value | ||
| 19430 | return undef; | ||
| 19431 | |||
| 19432 | } else { | ||
| 19433 | |||
| 19434 | # Return the equivalent value in the standard denomination | ||
| 19435 | return $returnValue; | ||
| 19436 | } | ||
| 19437 | } | ||
| 19438 | |||
| 19439 | ################## | ||
| 19440 | # Response methods | ||
| 19441 | |||
| 19442 | sub triggerSeen { | ||
| 19443 | |||
| 19444 | # Called by GA::Session->checkTriggers | ||
| 19445 | # | ||
| 19446 | # This task's ->resetInterfaces function creates some triggers to capture inventory lists | ||
| 19447 | # e.g. 'You are carrying (.*)' | ||
| 19448 | # | ||
| 19449 | # The world profile's inventory pattern list occurs in groups of 5 elements, representing | ||
| 19450 | # [0] - the pattern to match | ||
| 19451 | # [1] - which group substring contains the data we need (might be 0 if the line doesn't | ||
| 19452 | # contain any objects) | ||
| 19453 | # [2] - what kind of possession this is. Standard strings are: | ||
| 19454 | # 'wield', 'hold', 'wear', 'carry' for objects; | ||
| 19455 | # 'sack' for anything being carried in something else (which usually doesn't | ||
| 19456 | # appear in the inventory list); | ||
| 19457 | # 'purse', 'deposit', 'deposit_only', 'withdraw', 'withdraw_only', 'balance' | ||
| 19458 | # which update the character's purse and bank balances; | ||
| 19459 | # 'empty_purse' for an empty purse, 'empty_bank' for an empty bank account | ||
| 19460 | # 'misc' for any other type of possession | ||
| 19461 | # 'ignore' for a line in the inventory which should be ignored | ||
| 19462 | # [3] - 'hide' to use a gag trigger, 'show' to use a non-gag trigger | ||
| 19463 | # [4] - 'start' if this line is always at the beginning of an inventory list; 'stop' | ||
| 19464 | # if it is always the end of an inventory list; 'optional' for any other line | ||
| 19465 | # | ||
| 19466 | # The trigger interfaces have the following properties in ->propertyHash: | ||
| 19467 | # grp_num - which group substring contains the data we need (same as [1] ) | ||
| 19468 | # inv_type - 'wield', 'hold', 'wear', 'carry', 'sack', 'purse', 'deposit', | ||
| 19469 | # 'deposit_only', 'withdraw', 'withdraw_only', 'balance', | ||
| 19470 | # 'empty_purse', 'empty_bank', 'misc', 'ignore' (same as [2] ) | ||
| 19471 | # position - 'start', 'stop', 'optional' (same as [4]) | ||
| 19472 | # | ||
| 19473 | # This function analyses the matched string and updates IVs accordingly | ||
| 19474 | # | ||
| 19475 | # Expected arguments (standard args from GA::Session->checkTriggers) | ||
| 19476 | # $session - The calling function's GA::Session | ||
| 19477 | # $interfaceNum - The number of the active trigger interface that fired | ||
| 19478 | # $line - The line of text received from the world | ||
| 19479 | # $stripLine - $line, with all escape sequences removed | ||
| 19480 | # $modLine - $stripLine, possibly modified by previously-checked triggers | ||
| 19481 | # $grpStringListRef | ||
| 19482 | # - Reference to a list of group substrings from the pattern match | ||
| 19483 | # (equivalent of @_) | ||
| 19484 | # $matchMinusListRef | ||
| 19485 | # - Reference to a list of matched substring offsets (equivalent of @-) | ||
| 19486 | # $matchPlusListRef | ||
| 19487 | # - Reference to a list of matched substring offsets (equivalent of @+) | ||
| 19488 | # | ||
| 19489 | # Return values | ||
| 19490 | # 'undef' on improper arguments, or if $session is the wrong session or if the interface | ||
| 19491 | # object can't be found | ||
| 19492 | # 1 otherwise | ||
| 19493 | |||
| 19494 | my ( | ||
| 19495 | $self, $session, $interfaceNum, $line, $stripLine, $modLine, $grpStringListRef, | ||
| 19496 | $matchMinusListRef, $matchPlusListRef, $check, | ||
| 19497 | ) = @_; | ||
| 19498 | |||
| 19499 | # Local variables | ||
| 19500 | my ($obj, $grpNum, $invType, $posn, $grpString, $worldObj, $nowFlag); | ||
| 19501 | |||
| 19502 | # Check for improper arguments | ||
| 19503 | if ( | ||
| 19504 | ! defined $session || ! defined $interfaceNum || ! defined $line || ! defined $stripLine | ||
| 19505 | || ! defined $modLine || ! defined $grpStringListRef || ! defined $matchMinusListRef | ||
| 19506 | || ! defined $matchPlusListRef || defined $check | ||
| 19507 | ) { | ||
| 19508 | return $axmud::CLIENT->writeImproper($self->_objClass . '->triggerSeen', @_); | ||
| 19509 | } | ||
| 19510 | |||
| 19511 | # Basic check - the trigger should belong to the right session | ||
| 19512 | if ($session ne $self->session) { | ||
| 19513 | |||
| 19514 | return undef; | ||
| 19515 | } | ||
| 19516 | |||
| 19517 | # Get the interface object itself | ||
| 19518 | $obj = $session->ivShow('interfaceNumHash', $interfaceNum); | ||
| 19519 | if (! $obj) { | ||
| 19520 | |||
| 19521 | return undef; | ||
| 19522 | } | ||
| 19523 | |||
| 19524 | # Respond to the fired trigger | ||
| 19525 | |||
| 19526 | # Import the trigger's properties | ||
| 19527 | $grpNum = $obj->ivShow('propertyHash', 'grp_num'); | ||
| 19528 | $invType = $obj->ivShow('propertyHash', 'inv_type'); | ||
| 19529 | $posn = $obj->ivShow('propertyHash', 'position'); | ||
| 19530 | |||
| 19531 | if ($grpNum) { | ||
| 19532 | |||
| 19533 | # Get the correct group substring | ||
| 19534 | $grpString = $$grpStringListRef[$grpNum]; | ||
| 19535 | # Trim any unnecessary whitespace from it | ||
| 19536 | $grpString = $axmud::CLIENT->trimWhitespace($grpString); | ||
| 19537 | } | ||
| 19538 | |||
| 19539 | # Shortcut to the current world | ||
| 19540 | $worldObj = $self->session->currentWorld; | ||
| 19541 | |||
| 19542 | # We respond only to the first trigger that fires on each line (unless it's a 'start' or | ||
| 19543 | # 'stop' line), to prevent the task interpreting a single line as multiple objects of | ||
| 19544 | # inventory | ||
| 19545 | if ($posn eq 'optional' && $self->lastLine == $self->session->displayBufferLast) { | ||
| 19546 | |||
| 19547 | # This line has already been used | ||
| 19548 | return undef; | ||
| 19549 | |||
| 19550 | } else { | ||
| 19551 | |||
| 19552 | $self->ivPoke('lastLine', $self->session->displayBufferLast); | ||
| 19553 | } | ||
| 19554 | |||
| 19555 | # Empty this task's inventory list in certain circumstances | ||
| 19556 | if ($posn eq 'start' || $self->resetInventoryFlag) { | ||
| 19557 | |||
| 19558 | $self->ivPoke('resetInventoryFlag', FALSE); | ||
| 19559 | |||
| 19560 | # Modes 'start_stop', 'start_empty' | ||
| 19561 | if ( | ||
| 19562 | $worldObj->inventoryMode eq 'start_stop' | ||
| 19563 | || $worldObj->inventoryMode eq 'start_empty' | ||
| 19564 | ) { | ||
| 19565 | # Store the beginning of the inventory list | ||
| 19566 | $self->ivPoke('startFlag', TRUE); | ||
| 19567 | $self->ivPush('startStopList', | ||
| 19568 | 'start', | ||
| 19569 | $self->session->displayBufferLast, | ||
| 19570 | $modLine, | ||
| 19571 | ); | ||
| 19572 | } | ||
| 19573 | |||
| 19574 | # Empty the inventory list, but retain a copy so we can preserve an object's condition | ||
| 19575 | if ($self->inventoryList) { | ||
| 19576 | |||
| 19577 | $self->ivPoke('previousList', $self->inventoryList); | ||
| 19578 | $self->ivEmpty('inventoryList'); | ||
| 19579 | |||
| 19580 | } else { | ||
| 19581 | |||
| 19582 | $self->ivEmpty('previousList'); | ||
| 19583 | } | ||
| 19584 | |||
| 19585 | # If the Condition task is running, it receives its own copy of ->previousList | ||
| 19586 | # (because this task's ->previousList gets emptied by successive ->ivSplice | ||
| 19587 | # operations) | ||
| 19588 | if ($self->session->conditionTask) { | ||
| 19589 | |||
| 19590 | $self->session->conditionTask->set_previousList($self->previousList); | ||
| 19591 | } | ||
| 19592 | |||
| 19593 | # The objects in $grpString must be processed | ||
| 19594 | $nowFlag = TRUE; | ||
| 19595 | |||
| 19596 | } elsif ($posn eq 'stop') { | ||
| 19597 | |||
| 19598 | # Mode 'match_all' | ||
| 19599 | if ($worldObj->inventoryMode eq 'match_all') { | ||
| 19600 | |||
| 19601 | # Next matching line, no matter what type it is, causes the current inventory list | ||
| 19602 | # to be emptied | ||
| 19603 | $self->ivPoke('resetInventoryFlag', TRUE); | ||
| 19604 | |||
| 19605 | # Modes 'start_stop', 'start_empty' | ||
| 19606 | } else { | ||
| 19607 | |||
| 19608 | # Store the end of the inventory list | ||
| 19609 | $self->ivPoke('startFlag', FALSE); | ||
| 19610 | $self->ivPush('startStopList', | ||
| 19611 | 'stop', | ||
| 19612 | $self->session->displayBufferLast, | ||
| 19613 | $modLine, | ||
| 19614 | ); | ||
| 19615 | } | ||
| 19616 | |||
| 19617 | } elsif (! $self->startFlag && $worldObj->inventoryMode ne 'match_all') { | ||
| 19618 | |||
| 19619 | # This line can be ignored - we are not currently at or between a start/stop line (and | ||
| 19620 | # not in mode 'match_all', in which case all matching lines are processed) | ||
| 19621 | return undef; | ||
| 19622 | } | ||
| 19623 | |||
| 19624 | # Add items to the character's inventory, as long as this line is a 'start' or 'stop' line, | ||
| 19625 | # or is between a 'start' and 'stop' line (or if we're in mode 'match_all', in which case | ||
| 19626 | # all lines are processed immediately) | ||
| 19627 | if ( | ||
| 19628 | $grpString # No group substring means the line doesn't contain object(s) | ||
| 19629 | && ( | ||
| 19630 | $nowFlag | ||
| 19631 | || $posn eq 'stop' | ||
| 19632 | || $worldObj->inventoryMode eq 'match_all' | ||
| 19633 | || $self->startFlag | ||
| 19634 | ) | ||
| 19635 | ) { | ||
| 19636 | $self->processString($grpString, $invType); | ||
| 19637 | } | ||
| 19638 | |||
| 19639 | # In modes 'start_stop', 'start_empty', store an inventory line which has already been used | ||
| 19640 | # (even if it wasn't sent to ->processString to be parsed) | ||
| 19641 | if ($worldObj->inventoryMode ne 'match_all') { | ||
| 19642 | |||
| 19643 | $self->ivPush('useLineList', $modLine); | ||
| 19644 | } | ||
| 19645 | |||
| 19646 | # Tell this task's window to refresh, if open | ||
| 19647 | $self->ivPoke('refreshWinFlag', TRUE); | ||
| 19648 | |||
| 19649 | return 1; | ||
| 19650 | } | ||
| 19651 | |||
| 19652 | sub ignorePatternSeen { | ||
| 19653 | |||
| 19654 | # Called by GA::Session->checkTriggers | ||
| 19655 | # | ||
| 19656 | # This task's ->resetInterfaces function creates some triggers to capture lines from | ||
| 19657 | # inventory lists which don't contain objects, but which should still be gagged | ||
| 19658 | # e.g. 'In your pockets you find these currencies:' | ||
| 19659 | # | ||
| 19660 | # The function does nothing (a commented-out call to ->writeDebug is provided, in case it | ||
| 19661 | # will be useful) | ||
| 19662 | # | ||
| 19663 | # Expected arguments (standard args from GA::Session->checkTriggers) | ||
| 19664 | # $session - The calling function's GA::Session | ||
| 19665 | # $interfaceNum - The number of the active trigger interface that fired | ||
| 19666 | # $line - The line of text received from the world | ||
| 19667 | # $stripLine - $line, with all escape sequences removed | ||
| 19668 | # $modLine - $stripLine, possibly modified by previously-checked triggers | ||
| 19669 | # $grpStringListRef | ||
| 19670 | # - Reference to a list of group substrings from the pattern match | ||
| 19671 | # (equivalent of @_) | ||
| 19672 | # $matchMinusListRef | ||
| 19673 | # - Reference to a list of matched substring offsets (equivalent of @-) | ||
| 19674 | # $matchPlusListRef | ||
| 19675 | # - Reference to a list of matched substring offsets (equivalent of @+) | ||
| 19676 | # | ||
| 19677 | # Return values | ||
| 19678 | # 'undef' on improper arguments, or if $session is the wrong session or if the interface | ||
| 19679 | # object can't be found | ||
| 19680 | # 1 otherwise | ||
| 19681 | |||
| 19682 | my ( | ||
| 19683 | $self, $session, $interfaceNum, $line, $stripLine, $modLine, $grpStringListRef, | ||
| 19684 | $matchMinusListRef, $matchPlusListRef, $check, | ||
| 19685 | ) = @_; | ||
| 19686 | |||
| 19687 | # Local variables | ||
| 19688 | my $obj; | ||
| 19689 | |||
| 19690 | # Check for improper arguments | ||
| 19691 | if ( | ||
| 19692 | ! defined $session || ! defined $interfaceNum || ! defined $line || ! defined $stripLine | ||
| 19693 | || ! defined $modLine || ! defined $grpStringListRef || ! defined $matchMinusListRef | ||
| 19694 | || ! defined $matchPlusListRef || defined $check | ||
| 19695 | ) { | ||
| 19696 | return $axmud::CLIENT->writeImproper( | ||
| 19697 | $self->_objClass . '->ignorePatternSeen', | ||
| 19698 | @_, | ||
| 19699 | ); | ||
| 19700 | } | ||
| 19701 | |||
| 19702 | # Basic check - the trigger should belong to the right session | ||
| 19703 | if ($session ne $self->session) { | ||
| 19704 | |||
| 19705 | return undef; | ||
| 19706 | } | ||
| 19707 | |||
| 19708 | # Get the interface object itself | ||
| 19709 | $obj = $session->ivShow('interfaceNumHash', $interfaceNum); | ||
| 19710 | if (! $obj) { | ||
| 19711 | |||
| 19712 | return undef; | ||
| 19713 | } | ||
| 19714 | |||
| 19715 | # Respond to the fired trigger | ||
| 19716 | |||
| 19717 | # We respond only to the first trigger that fires on each line, to prevent the task | ||
| 19718 | # interpreting a single line as multiple objects of inventory | ||
| 19719 | if ($self->lastLine == $self->session->displayBufferLast) { | ||
| 19720 | |||
| 19721 | # This line has already been used | ||
| 19722 | return undef; | ||
| 19723 | |||
| 19724 | } else { | ||
| 19725 | |||
| 19726 | $self->ivPoke('lastLine', $self->session->displayBufferLast); | ||
| 19727 | } | ||
| 19728 | |||
| 19729 | # $self->writeDebug('Inventory task ignore pattern found: \'' . $$grpStringListRef[0] . '\''); | ||
| 19730 | |||
| 19731 | return 1; | ||
| 19732 | } | ||
| 19733 | |||
| 19734 | ################## | ||
| 19735 | # Accessors - set | ||
| 19736 | |||
| 19737 | sub set_refreshWinFlag { | ||
| 19738 | |||
| 19739 | my ($self, $flag, $check) = @_; | ||
| 19740 | |||
| 19741 | # Check for improper arguments | ||
| 19742 | if (! defined $flag || defined $check) { | ||
| 19743 | |||
| 19744 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_refreshWinFlag', @_); | ||
| 19745 | } | ||
| 19746 | |||
| 19747 | if ($flag) { | ||
| 19748 | $self->ivPoke('refreshWinFlag', TRUE); | ||
| 19749 | } else { | ||
| 19750 | $self->ivPoke('refreshWinFlag', FALSE); | ||
| 19751 | } | ||
| 19752 | |||
| 19753 | return 1; | ||
| 19754 | } | ||
| 19755 | |||
| 19756 | ################## | ||
| 19757 | # Accessors - task settings - get | ||
| 19758 | |||
| 19759 | # The accessors for task settings are inherited from the generic task | ||
| 19760 | |||
| 19761 | ################## | ||
| 19762 | # Accessors - task parameters - get | ||
| 19763 | |||
| 19764 | sub cmdHash | ||
| 19765 | { my $self = shift; return %{$self->{cmdHash}}; } | ||
| 19766 | sub timerHash | ||
| 19767 | { my $self = shift; return %{$self->{timerHash}}; } | ||
| 19768 | sub triggerList | ||
| 19769 | { my $self = shift; return @{$self->{triggerList}}; } | ||
| 19770 | sub ignoreTriggerList | ||
| 19771 | { my $self = shift; return @{$self->{ignoreTriggerList}}; } | ||
| 19772 | |||
| 19773 | sub resetInventoryFlag | ||
| 19774 | { $_[0]->{resetInventoryFlag} } | ||
| 19775 | |||
| 19776 | sub startStopList | ||
| 19777 | { my $self = shift; return @{$self->{startStopList}}; } | ||
| 19778 | sub startFlag | ||
| 19779 | { $_[0]->{startFlag} } | ||
| 19780 | sub startLineTextList | ||
| 19781 | { my $self = shift; return @{$self->{startLineTextList}}; } | ||
| 19782 | sub useLineList | ||
| 19783 | { my $self = shift; return @{$self->{useLineList}}; } | ||
| 19784 | sub lastLine | ||
| 19785 | { $_[0]->{lastLine} } | ||
| 19786 | |||
| 19787 | sub inventoryList | ||
| 19788 | { my $self = shift; return @{$self->{inventoryList}}; } | ||
| 19789 | sub previousList | ||
| 19790 | { my $self = shift; return @{$self->{previousList}}; } | ||
| 19791 | sub sensitivity | ||
| 19792 | { $_[0]->{sensitivity} } | ||
| 19793 | |||
| 19794 | sub refreshWinFlag | ||
| 19795 | { $_[0]->{refreshWinFlag} } | ||
| 19796 | } | ||
| 19797 | |||
| 19798 | { package Games::Axmud::Task::Launch; | ||
| 19799 | |||
| 19800 | use strict; | ||
| 19801 | use warnings; | ||
| 19802 | # use diagnostics; | ||
| 19803 | |||
| 19804 | use Glib qw(TRUE FALSE); | ||
| 19805 | |||
| 19806 | our @ISA = qw(Games::Axmud::Generic::Task Games::Axmud); | ||
| 19807 | |||
| 19808 | ################## | ||
| 19809 | # Constructors | ||
| 19810 | |||
| 19811 | sub new { | ||
| 19812 | |||
| 19813 | # Creates a new instance of the Launch task | ||
| 19814 | # | ||
| 19815 | # Expected arguments | ||
| 19816 | # $session - The parent GA::Session (not stored as an IV) | ||
| 19817 | # | ||
| 19818 | # Optional arguments | ||
| 19819 | # $taskType - Which tasklist this task is being created into - 'current' for the current | ||
| 19820 | # tasklist (tasks which are actually running now), 'initial' (tasks which | ||
| 19821 | # should be run when the user connects to the world), 'custom' (tasks with | ||
| 19822 | # customised initial parameters, which are run when the user demands). If | ||
| 19823 | # set to 'undef', this is a temporary task, created in order to access the | ||
| 19824 | # default values stored in IVs, that will not be added to any tasklist | ||
| 19825 | # $profName - ($taskType = 'current', when called by $self->clone) Name of the | ||
| 19826 | # profile from whose initial tasklist this task was created ('undef' if | ||
| 19827 | # none) | ||
| 19828 | # - ($taskType = 'initial') name of the profile in whose initial tasklist this | ||
| 19829 | # task will be. If 'undef', the global initial tasklist is used | ||
| 19830 | # - ($taskType = 'custom') 'undef' | ||
| 19831 | # $profCategory | ||
| 19832 | # - ($taskType = 'current', 'initial') which category the profile falls undef | ||
| 19833 | # (i.e. 'world', 'race', 'char', etc, or 'undef' if no profile) | ||
| 19834 | # - ($taskType = 'custom') 'undef' | ||
| 19835 | # $customName | ||
| 19836 | # - ($taskType = 'current', 'initial') 'undef' | ||
| 19837 | # - ($taskType = 'custom') the custom task name, matching a key in | ||
| 19838 | # GA::Session->customTaskHash | ||
| 19839 | # | ||
| 19840 | # Return values | ||
| 19841 | # 'undef' on improper arguments or if the task can't be added to the specified tasklist | ||
| 19842 | # Blessed reference to the newly-created object on success | ||
| 19843 | |||
| 19844 | my ($class, $session, $taskType, $profName, $profCategory, $customName, $check) = @_; | ||
| 19845 | |||
| 19846 | # Check for improper arguments | ||
| 19847 | if (! defined $class || ! defined $session || defined $check) { | ||
| 19848 | |||
| 19849 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 19850 | } | ||
| 19851 | |||
| 19852 | if ($taskType) { | ||
| 19853 | |||
| 19854 | # For initial tasks, check that $profName exists | ||
| 19855 | if ( | ||
| 19856 | $taskType eq 'initial' | ||
| 19857 | && defined $profName | ||
| 19858 | && ! $session->ivExists('profHash', $profName) | ||
| 19859 | ) { | ||
| 19860 | return $session->writeError( | ||
| 19861 | 'Can\'t create new task because \'' . $profName . '\' profile doesn\'t exist', | ||
| 19862 | $class . '->new', | ||
| 19863 | ); | ||
| 19864 | |||
| 19865 | # For custom tasks, check that $customName doesn't already exist | ||
| 19866 | } elsif ( | ||
| 19867 | $taskType eq 'custom' | ||
| 19868 | && $axmud::CLIENT->ivExists('customTaskHash', $customName) | ||
| 19869 | ) { | ||
| 19870 | return $session->writeError( | ||
| 19871 | 'Can\'t create new custom task because \'' . $customName . '\' is already being' | ||
| 19872 | . ' used', | ||
| 19873 | $class . '->new', | ||
| 19874 | ); | ||
| 19875 | |||
| 19876 | } elsif ($taskType ne 'current' && $taskType ne 'initial' && $taskType ne 'custom') { | ||
| 19877 | |||
| 19878 | return $session->writeError( | ||
| 19879 | 'Can\'t create new task because \'' . $taskType . '\' is an invalid tasklist', | ||
| 19880 | $class . '->new', | ||
| 19881 | ); | ||
| 19882 | } | ||
| 19883 | } | ||
| 19884 | |||
| 19885 | # Task settings | ||
| 19886 | my $self = Games::Axmud::Generic::Task->new( | ||
| 19887 | $session, | ||
| 19888 | $taskType, | ||
| 19889 | $profName, | ||
| 19890 | $profCategory, | ||
| 19891 | $customName, | ||
| 19892 | ); | ||
| 19893 | |||
| 19894 | $self->{_objName} = 'launch_task'; | ||
| 19895 | $self->{_objClass} = $class; | ||
| 19896 | $self->{_parentFile} = undef; # Set below | ||
| 19897 | $self->{_parentWorld} = undef; # Set below | ||
| 19898 | $self->{_privFlag} = TRUE, # All IVs are private | ||
| 19899 | |||
| 19900 | $self->{name} = 'launch_task'; | ||
| 19901 | $self->{prettyName} = 'Launch'; | ||
| 19902 | $self->{shortName} = 'La'; | ||
| 19903 | $self->{shortCutIV} = 'launchTask'; # Axmud built-in jealous task | ||
| 19904 | |||
| 19905 | $self->{category} = 'activity'; | ||
| 19906 | $self->{descrip} = 'Opens a task window from which scripts can be launched'; | ||
| 19907 | $self->{jealousyFlag} = TRUE; | ||
| 19908 | $self->{requireLocatorFlag} = FALSE; | ||
| 19909 | $self->{profSensitivistyFlag} = TRUE; | ||
| 19910 | $self->{storableFlag} = TRUE; | ||
| 19911 | $self->{delayTime} = 0; | ||
| 19912 | $self->{allowWinFlag} = TRUE; | ||
| 19913 | $self->{requireWinFlag} = TRUE; | ||
| 19914 | $self->{startWithWinFlag} = TRUE; | ||
| 19915 | $self->{winPreferList} = ['pseudo', 'grid']; | ||
| 19916 | $self->{winmap} = 'basic_empty'; | ||
| 19917 | $self->{winUpdateFunc} = 'createWidgets'; | ||
| 19918 | $self->{tabMode} = undef; | ||
| 19919 | $self->{monochromeFlag} = FALSE; | ||
| 19920 | $self->{noScrollFlag} = FALSE; | ||
| 19921 | $self->{ttsFlag} = FALSE; | ||
| 19922 | $self->{ttsConfig} = undef; | ||
| 19923 | $self->{ttsAttribHash} = {}; | ||
| 19924 | $self->{ttsFlagAttribHash} = {}; | ||
| 19925 | $self->{ttsAlertAttribHash} = {}; | ||
| 19926 | $self->{status} = 'wait_init'; | ||
| 19927 | # $self->{activeFlag} = TRUE; # Task can't be activated/disactivated | ||
| 19928 | |||
| 19929 | # Task parameters | ||
| 19930 | # | ||
| 19931 | # Table object handling the GA::Obj::SimpleList | ||
| 19932 | $self->{slTableObj} = undef; | ||
| 19933 | # A hash of scripts displayed in the window, in the form | ||
| 19934 | # $fileHash{script_name} = full_file_path | ||
| 19935 | # ...where 'script_name' is the file name, e.g. 'wumpus.bas' | ||
| 19936 | $self->{fileHash} = {}; | ||
| 19937 | |||
| 19938 | # Bless task | ||
| 19939 | bless $self, $class; | ||
| 19940 | |||
| 19941 | # For all tasks that aren't temporary... | ||
| 19942 | if ($taskType) { | ||
| 19943 | |||
| 19944 | # Check that the task doesn't belong to a disabled plugin (in which case, it can't be | ||
| 19945 | # added to any current, initial or custom tasklist) | ||
| 19946 | if (! $self->checkPlugins()) { | ||
| 19947 | |||
| 19948 | return undef; | ||
| 19949 | } | ||
| 19950 | |||
| 19951 | # Set the parent file object | ||
| 19952 | $self->setParentFileObj($session, $taskType, $profName, $profCategory); | ||
| 19953 | |||
| 19954 | # Create entries in tasklists, if possible | ||
| 19955 | if (! $self->updateTaskLists($session)) { | ||
| 19956 | |||
| 19957 | return undef; | ||
| 19958 | } | ||
| 19959 | } | ||
| 19960 | |||
| 19961 | # Task creation complete | ||
| 19962 | return $self; | ||
| 19963 | } | ||
| 19964 | |||
| 19965 | # sub clone {} # Inherited from generic task | ||
| 19966 | |||
| 19967 | # sub preserve {} # Inherited from generic task | ||
| 19968 | |||
| 19969 | # sub preserve {} # Inherited from generic task | ||
| 19970 | |||
| 19971 | # sub setParentFileObj {} # Inherited from generic task | ||
| 19972 | |||
| 19973 | # sub updateTaskLists {} # Inherited from generic task | ||
| 19974 | |||
| 19975 | # sub ttsReadAttrib {} # Inherited from generic task | ||
| 19976 | |||
| 19977 | # sub ttsSwitchFlagAttrib {} # Inherited from generic task | ||
| 19978 | |||
| 19979 | # sub ttsSetAlertAttrib {} # Inherited from generic task | ||
| 19980 | |||
| 19981 | ################## | ||
| 19982 | # Task windows | ||
| 19983 | |||
| 19984 | # sub toggleWin {} # Inherited from generic task | ||
| 19985 | |||
| 19986 | # sub openWin {} # Inherited from generic task | ||
| 19987 | |||
| 19988 | # sub closeWin {} # Inherited from generic task | ||
| 19989 | |||
| 19990 | ################## | ||
| 19991 | # Methods | ||
| 19992 | |||
| 19993 | # sub init {} # Inherited from generic task | ||
| 19994 | |||
| 19995 | sub doInit { | ||
| 19996 | |||
| 19997 | # Called by $self->init, just before the task completes its setup ($self->init) | ||
| 19998 | # | ||
| 19999 | # Expected arguments | ||
| 20000 | # (none besides $self) | ||
| 20001 | # | ||
| 20002 | # Return values | ||
| 20003 | # 'undef' on improper arguments | ||
| 20004 | # 1 otherwise | ||
| 20005 | |||
| 20006 | my ($self, $check) = @_; | ||
| 20007 | |||
| 20008 | # Check for improper arguments | ||
| 20009 | if (defined $check) { | ||
| 20010 | |||
| 20011 | return $axmud::CLIENT->writeImproper($self->_objClass . '->doInit', @_); | ||
| 20012 | } | ||
| 20013 | |||
| 20014 | # If the task has recently been updated, quickest way to update the window is to remove all | ||
| 20015 | # the current table objects, before creating new ones | ||
| 20016 | if ($self->hasResetFlag) { | ||
| 20017 | |||
| 20018 | if (! defined $self->winObj->tableStripObj->removeAllTableObjs()) { | ||
| 20019 | |||
| 20020 | # Operation failed; task must close | ||
| 20021 | $self->ivPoke('shutdownFlag', TRUE); | ||
| 20022 | return 1; | ||
| 20023 | } | ||
| 20024 | } | ||
| 20025 | |||
| 20026 | # Create widgets for the task window | ||
| 20027 | $self->createWidgets(); | ||
| 20028 | |||
| 20029 | # Display the list of available scripts in the task window's simple list | ||
| 20030 | $self->populateList(); | ||
| 20031 | |||
| 20032 | return 1; | ||
| 20033 | } | ||
| 20034 | |||
| 20035 | # sub doShutdown {} # Inherited from generic task | ||
| 20036 | |||
| 20037 | # sub doReset {} # Inherited from generic task | ||
| 20038 | |||
| 20039 | sub createWidgets { | ||
| 20040 | |||
| 20041 | # Set up the widgets used in the task window | ||
| 20042 | # | ||
| 20043 | # Expected arguments | ||
| 20044 | # (none besides $self) | ||
| 20045 | # | ||
| 20046 | # Return values | ||
| 20047 | # 'undef' on improper arguments | ||
| 20048 | # 1 otherwise | ||
| 20049 | |||
| 20050 | my ($self, $check) = @_; | ||
| 20051 | |||
| 20052 | # Check for improper arguments | ||
| 20053 | if (defined $check) { | ||
| 20054 | |||
| 20055 | return $axmud::CLIENT->writeImproper($self->_objClass . '->createWidgets', @_); | ||
| 20056 | } | ||
| 20057 | |||
| 20058 | # Add a simple list on the left | ||
| 20059 | my $tableObj = $self->winObj->tableStripObj->addTableObj( | ||
| 20060 | 'Games::Axmud::Table::SimpleList', | ||
| 20061 | 0, 44, 0, 59, | ||
| 20062 | undef, | ||
| 20063 | # Init settings | ||
| 20064 | 'column_ref' => [ | ||
| 20065 | 'Script', 'text', | ||
| 20066 | 'Path', 'text', | ||
| 20067 | ], | ||
| 20068 | ); | ||
| 20069 | |||
| 20070 | $self->winObj->tableStripObj->addTableObj( | ||
| 20071 | 'Games::Axmud::Table::Button', | ||
| 20072 | 45, 59, 0, 9, | ||
| 20073 | undef, | ||
| 20074 | # Init settings | ||
| 20075 | 'func' => $self->getMethodRef('newCallback'), | ||
| 20076 | 'text' => 'New script', | ||
| 20077 | 'tooltips' => 'Add a new script to this list', | ||
| 20078 | 'align_x' => 0.5, | ||
| 20079 | ); | ||
| 20080 | |||
| 20081 | $self->winObj->tableStripObj->addTableObj( | ||
| 20082 | 'Games::Axmud::Table::Button', | ||
| 20083 | 45, 59, 10, 19, | ||
| 20084 | undef, | ||
| 20085 | # Init settings | ||
| 20086 | 'func' => $self->getMethodRef('editCallback'), | ||
| 20087 | 'text' => 'Edit script', | ||
| 20088 | 'tooltips' => 'Edits the selected script', | ||
| 20089 | 'align_x' => 0.5, | ||
| 20090 | ); | ||
| 20091 | |||
| 20092 | $self->winObj->tableStripObj->addTableObj( | ||
| 20093 | 'Games::Axmud::Table::Button', | ||
| 20094 | 45, 59, 20, 29, | ||
| 20095 | undef, | ||
| 20096 | # Init settings | ||
| 20097 | 'func' => $self->getMethodRef('deleteCallback'), | ||
| 20098 | 'text' => 'Delete script', | ||
| 20099 | 'tooltips' => 'Deletes the selected script', | ||
| 20100 | 'align_x' => 0.5, | ||
| 20101 | ); | ||
| 20102 | |||
| 20103 | $self->winObj->tableStripObj->addTableObj( | ||
| 20104 | 'Games::Axmud::Table::Button', | ||
| 20105 | 45, 59, 30, 39, | ||
| 20106 | undef, | ||
| 20107 | # Init settings | ||
| 20108 | 'func' => $self->getMethodRef('runCallback'), | ||
| 20109 | 'text' => 'Run script', | ||
| 20110 | 'tooltips' => 'Runs the selected script', | ||
| 20111 | 'align_x' => 0.5, | ||
| 20112 | ); | ||
| 20113 | |||
| 20114 | $self->winObj->tableStripObj->addTableObj( | ||
| 20115 | 'Games::Axmud::Table::Button', | ||
| 20116 | 45, 59, 40, 49, | ||
| 20117 | undef, | ||
| 20118 | # Init settings | ||
| 20119 | 'func' => $self->getMethodRef('runTaskCallback'), | ||
| 20120 | 'text' => 'Run as task', | ||
| 20121 | 'tooltips' => 'Runs the selected script as a task', | ||
| 20122 | 'align_x' => 0.5, | ||
| 20123 | ); | ||
| 20124 | |||
| 20125 | $self->winObj->tableStripObj->addTableObj( | ||
| 20126 | 'Games::Axmud::Table::Button', | ||
| 20127 | 45, 59, 50, 59, | ||
| 20128 | undef, | ||
| 20129 | # Init settings | ||
| 20130 | 'func' => $self->getMethodRef('refreshCallback'), | ||
| 20131 | 'text' => 'Refresh list', | ||
| 20132 | 'tooltips' => 'Refreshes the list of scripts', | ||
| 20133 | 'align_x' => 0.5, | ||
| 20134 | ); | ||
| 20135 | |||
| 20136 | # Store the simple list's table object, so that callbacks can access it | ||
| 20137 | $self->ivPoke('slTableObj', $tableObj); | ||
| 20138 | |||
| 20139 | # Display all the widgets | ||
| 20140 | $self->winObj->winShowAll($self->_objClass . '->createWidgets'); | ||
| 20141 | |||
| 20142 | return 1; | ||
| 20143 | } | ||
| 20144 | |||
| 20145 | sub populateList { | ||
| 20146 | |||
| 20147 | # Displays the list of available scripts in the task window's simple list | ||
| 20148 | # | ||
| 20149 | # Expected arguments | ||
| 20150 | # (none besides $self) | ||
| 20151 | # | ||
| 20152 | # Optional arguments | ||
| 20153 | # $newSelectFile - If set, the name of the file (e.g. 'wumpus.bas') that should be | ||
| 20154 | # selected after the list is populated. If 'undef', the previous | ||
| 20155 | # selected file (if any) remains selected | ||
| 20156 | # | ||
| 20157 | # Return values | ||
| 20158 | # 'undef' on improper arguments | ||
| 20159 | # 1 otherwise | ||
| 20160 | |||
| 20161 | my ($self, $newSelectFile, $check) = @_; | ||
| 20162 | |||
| 20163 | # Local variables | ||
| 20164 | my ( | ||
| 20165 | $index, $rowRef, $oldSelectFile, $foundFlag, $count, | ||
| 20166 | @dirList, @fileList, @dataList, | ||
| 20167 | %fileHash, | ||
| 20168 | ); | ||
| 20169 | |||
| 20170 | # Check for improper arguments | ||
| 20171 | if (defined $check) { | ||
| 20172 | |||
| 20173 | return $axmud::CLIENT->writeImproper($self->_objClass . '->populateList', @_); | ||
| 20174 | } | ||
| 20175 | |||
| 20176 | # The simple list is updated once a second, so we need to preserve whichever script is | ||
| 20177 | # selected (if any) | ||
| 20178 | # Get the currently selected row's number (if any) | ||
| 20179 | $index = $self->slTableObj->get_select(); | ||
| 20180 | if (defined $index) { | ||
| 20181 | |||
| 20182 | # Get the selected row itself | ||
| 20183 | $rowRef = $self->slTableObj->get_row($index); | ||
| 20184 | $oldSelectFile = $$rowRef[0]; | ||
| 20185 | } | ||
| 20186 | |||
| 20187 | # Get a list of directories in which scripts are stored | ||
| 20188 | @dirList = ( | ||
| 20189 | $axmud::DATA_DIR . '/scripts', | ||
| 20190 | $axmud::CLIENT->scriptDirList, | ||
| 20191 | ); | ||
| 20192 | |||
| 20193 | # Get a list of scripts in each directory of @dirList. If we encounter a duplicate, ignore | ||
| 20194 | # it and use the earlier one (which would be the script loaded by, for example, | ||
| 20195 | # ';runscript') | ||
| 20196 | foreach my $dir (@dirList) { | ||
| 20197 | |||
| 20198 | my @pathList; | ||
| 20199 | |||
| 20200 | if ($^O eq 'MSWin32') { | ||
| 20201 | @pathList = glob($dir . '\\*.bas'); | ||
| 20202 | } else { | ||
| 20203 | @pathList = glob($dir . '/*.bas'); | ||
| 20204 | } | ||
| 20205 | |||
| 20206 | foreach my $path (@pathList) { | ||
| 20207 | |||
| 20208 | my $file; | ||
| 20209 | |||
| 20210 | # $path is the whole path, $file is just the filename (e.g. test.bas) | ||
| 20211 | $file = $path; | ||
| 20212 | # Repair MSWin paths, so $scriptDir can be used in a substitution | ||
| 20213 | $file =~ s/\\/\\\\/g; | ||
| 20214 | # Do the substitution | ||
| 20215 | $file =~ s/$dir\///; | ||
| 20216 | |||
| 20217 | # If a script of this name has not already been found, use it | ||
| 20218 | if (! exists $fileHash{$file}) { | ||
| 20219 | |||
| 20220 | $fileHash{$file} = $path; | ||
| 20221 | push (@fileList, $file); | ||
| 20222 | } | ||
| 20223 | |||
| 20224 | # If the file that was selected (when this function was called) still exists, we | ||
| 20225 | # can re-select it below | ||
| 20226 | if ($oldSelectFile && $oldSelectFile eq $path) { | ||
| 20227 | |||
| 20228 | $foundFlag = TRUE; | ||
| 20229 | } | ||
| 20230 | } | ||
| 20231 | } | ||
| 20232 | |||
| 20233 | @fileList = sort {$a cmp $b} (@fileList); | ||
| 20234 | foreach my $file (@fileList) { | ||
| 20235 | |||
| 20236 | push (@dataList, [$file, $fileHash{$file}]); | ||
| 20237 | } | ||
| 20238 | |||
| 20239 | # Update the task window's simple list | ||
| 20240 | $self->slTableObj->set_list(@dataList); | ||
| 20241 | |||
| 20242 | # If $newSelectFile was specified, work out which row to select | ||
| 20243 | if (defined $newSelectFile) { | ||
| 20244 | |||
| 20245 | $count = -1; | ||
| 20246 | OUTER: foreach my $file (@fileList) { | ||
| 20247 | |||
| 20248 | $count++; | ||
| 20249 | if ($file eq $newSelectFile) { | ||
| 20250 | |||
| 20251 | $index = $count; | ||
| 20252 | last OUTER; | ||
| 20253 | } | ||
| 20254 | } | ||
| 20255 | |||
| 20256 | } elsif (! $foundFlag) { | ||
| 20257 | |||
| 20258 | # The old selected file no longer exists, so don't try to re-select it | ||
| 20259 | $index = undef; | ||
| 20260 | } | ||
| 20261 | |||
| 20262 | # Select one of the rows (if required) | ||
| 20263 | if (defined $index) { | ||
| 20264 | |||
| 20265 | $self->slTableObj->set_select($index); | ||
| 20266 | } | ||
| 20267 | |||
| 20268 | # Save details about each file, and its full file path, so that we don't have to work them | ||
| 20269 | # out a second time | ||
| 20270 | $self->ivPoke('fileHash', %fileHash); | ||
| 20271 | |||
| 20272 | return 1; | ||
| 20273 | } | ||
| 20274 | |||
| 20275 | ################## | ||
| 20276 | # Response methods | ||
| 20277 | |||
| 20278 | sub newCallback { | ||
| 20279 | |||
| 20280 | # Called by an anonymous function in the task window object when the user clicks the | ||
| 20281 | # 'New script' button | ||
| 20282 | # Prompts the user for a script name and, if it doesn't already exist, creates a new file | ||
| 20283 | # in the default scripts directory | ||
| 20284 | # | ||
| 20285 | # Expected arguments | ||
| 20286 | # $tableObj - The GA::Table::Button object for the button | ||
| 20287 | # $button - The actual Gtk3::Button clicked | ||
| 20288 | # $id - The callback ID; in this case, an empty string | ||
| 20289 | # | ||
| 20290 | # Return values | ||
| 20291 | # 'undef' on improper arguments | ||
| 20292 | # 1 otherwise | ||
| 20293 | |||
| 20294 | my ($self, $tableObj, $button, $id, $check) = @_; | ||
| 20295 | |||
| 20296 | # Local variables | ||
| 20297 | my ( | ||
| 20298 | $scriptName, $path, $fileHandle, | ||
| 20299 | @list, | ||
| 20300 | ); | ||
| 20301 | |||
| 20302 | # Check for improper arguments | ||
| 20303 | if (! defined $tableObj || ! defined $button || ! defined $id || defined $check) { | ||
| 20304 | |||
| 20305 | return $axmud::CLIENT->writeImproper($self->_objClass . '->newCallback', @_); | ||
| 20306 | } | ||
| 20307 | |||
| 20308 | # Prompt the user for a file name | ||
| 20309 | $scriptName = $self->winObj->showEntryDialogue( | ||
| 20310 | 'New script', | ||
| 20311 | 'Enter a name for the script (e.g. \'wumpus\')', | ||
| 20312 | $self->winObj->winWidget, | ||
| 20313 | ); | ||
| 20314 | |||
| 20315 | if (defined $scriptName) { | ||
| 20316 | |||
| 20317 | # Does a file of this name already exist in the default script directory? | ||
| 20318 | $path = $axmud::DATA_DIR . '/scripts/' . $scriptName . '.bas'; | ||
| 20319 | if (-e $path) { | ||
| 20320 | |||
| 20321 | return $self->winObj->showMsgDialogue( | ||
| 20322 | 'New script', | ||
| 20323 | 'error', | ||
| 20324 | 'The file \'' . $path . '\' already exists', | ||
| 20325 | 'ok', | ||
| 20326 | ); | ||
| 20327 | } | ||
| 20328 | |||
| 20329 | # Open the file for writing, overwriting previous contents | ||
| 20330 | if (! open ($fileHandle, ">$path")) { | ||
| 20331 | |||
| 20332 | return $self->winObj->showMsgDialogue( | ||
| 20333 | 'New script', | ||
| 20334 | 'error', | ||
| 20335 | 'Unable to create the file \'' . $path . '\'', | ||
| 20336 | 'ok', | ||
| 20337 | ); | ||
| 20338 | } | ||
| 20339 | |||
| 20340 | # The contents of the file are the same as that used in the default 'test.bas' script | ||
| 20341 | @list = ( | ||
| 20342 | "REM Write your own " . $axmud::BASIC_NAME . " code here\n", | ||
| 20343 | "\n", | ||
| 20344 | "END\n", | ||
| 20345 | ); | ||
| 20346 | |||
| 20347 | # Write the file | ||
| 20348 | print $fileHandle @list; | ||
| 20349 | close $fileHandle; | ||
| 20350 | |||
| 20351 | # Update the task window's simple list, selecting the file we just created | ||
| 20352 | $self->populateList($scriptName . '.bas'); | ||
| 20353 | } | ||
| 20354 | |||
| 20355 | return 1; | ||
| 20356 | } | ||
| 20357 | |||
| 20358 | sub editCallback { | ||
| 20359 | |||
| 20360 | # Called by an anonymous function in the task window object when the user clicks the | ||
| 20361 | # 'Edit script' button | ||
| 20362 | # Opens the selected file (if any) in Axmud's default text editor | ||
| 20363 | # | ||
| 20364 | # Expected arguments | ||
| 20365 | # $tableObj - The GA::Table::Button object for the button | ||
| 20366 | # $button - The actual Gtk3::Button clicked | ||
| 20367 | # $id - The callback ID; in this case, an empty string | ||
| 20368 | # | ||
| 20369 | # Return values | ||
| 20370 | # 'undef' on improper arguments | ||
| 20371 | # 1 otherwise | ||
| 20372 | |||
| 20373 | my ($self, $tableObj, $button, $id, $check) = @_; | ||
| 20374 | |||
| 20375 | # Local variables | ||
| 20376 | my ($index, $rowRef, $selectFile, $path, $cmd); | ||
| 20377 | |||
| 20378 | # Check for improper arguments | ||
| 20379 | if (! defined $tableObj || ! defined $button || ! defined $id || defined $check) { | ||
| 20380 | |||
| 20381 | return $axmud::CLIENT->writeImproper($self->_objClass . '->editCallback', @_); | ||
| 20382 | } | ||
| 20383 | |||
| 20384 | $index = $self->slTableObj->get_select(); | ||
| 20385 | if (defined $index) { | ||
| 20386 | |||
| 20387 | # Get the selected row itself | ||
| 20388 | $rowRef = $self->slTableObj->get_row($index); | ||
| 20389 | $selectFile = $$rowRef[0]; | ||
| 20390 | |||
| 20391 | # Open the selected file in the external text editor | ||
| 20392 | $cmd = $axmud::CLIENT->textEditCmd; | ||
| 20393 | if (! $cmd || ! ($cmd =~ m/%s/)) { | ||
| 20394 | |||
| 20395 | return $self->winObj->showMsgDialogue( | ||
| 20396 | 'New script', | ||
| 20397 | 'error', | ||
| 20398 | 'Can\'t edit the ' . $axmud::BASIC_NAME . ' script - invalid external' | ||
| 20399 | . ' application command', | ||
| 20400 | 'ok', | ||
| 20401 | ); | ||
| 20402 | } | ||
| 20403 | |||
| 20404 | $path = $self->ivShow('fileHash', $selectFile); | ||
| 20405 | $cmd =~ s/%s/$path/; | ||
| 20406 | if ($cmd) { | ||
| 20407 | |||
| 20408 | system $cmd; | ||
| 20409 | } | ||
| 20410 | } | ||
| 20411 | |||
| 20412 | # In all cases, update the task window's simple list (leave the same script selected) | ||
| 20413 | $self->populateList($selectFile); | ||
| 20414 | |||
| 20415 | return 1; | ||
| 20416 | } | ||
| 20417 | |||
| 20418 | sub deleteCallback { | ||
| 20419 | |||
| 20420 | # Called by an anonymous function in the task window object when the user clicks the | ||
| 20421 | # 'Delete script' button | ||
| 20422 | # Deletes the selected file (if any) | ||
| 20423 | # | ||
| 20424 | # Expected arguments | ||
| 20425 | # $tableObj - The GA::Table::Button object for the button | ||
| 20426 | # $button - The actual Gtk3::Button clicked | ||
| 20427 | # $id - The callback ID; in this case, an empty string | ||
| 20428 | # | ||
| 20429 | # Return values | ||
| 20430 | # 'undef' on improper arguments | ||
| 20431 | # 1 otherwise | ||
| 20432 | |||
| 20433 | my ($self, $tableObj, $button, $id, $check) = @_; | ||
| 20434 | |||
| 20435 | # Local variables | ||
| 20436 | my ($index, $rowRef, $selectFile, $path, $choice); | ||
| 20437 | |||
| 20438 | # Check for improper arguments | ||
| 20439 | if (! defined $tableObj || ! defined $button || ! defined $id || defined $check) { | ||
| 20440 | |||
| 20441 | return $axmud::CLIENT->writeImproper($self->_objClass . '->deleteCallback', @_); | ||
| 20442 | } | ||
| 20443 | |||
| 20444 | $index = $self->slTableObj->get_select(); | ||
| 20445 | if (defined $index) { | ||
| 20446 | |||
| 20447 | # Get the selected row itself | ||
| 20448 | $rowRef = $self->slTableObj->get_row($index); | ||
| 20449 | $selectFile = $$rowRef[0]; | ||
| 20450 | $path = $self->ivShow('fileHash', $selectFile); | ||
| 20451 | |||
| 20452 | # Prompt the user for a confirmation... | ||
| 20453 | $choice = $self->winObj->showMsgDialogue( | ||
| 20454 | 'Delete script', | ||
| 20455 | 'question', | ||
| 20456 | 'Are you sure you want to delete \'' . $path . '\'?', | ||
| 20457 | 'yes-no', | ||
| 20458 | 'no', | ||
| 20459 | ); | ||
| 20460 | |||
| 20461 | if (defined $choice && $choice eq 'yes' && -e $path) { | ||
| 20462 | |||
| 20463 | unlink $path; | ||
| 20464 | } | ||
| 20465 | } | ||
| 20466 | |||
| 20467 | # In all cases, update the task window's simple list | ||
| 20468 | $self->populateList(); | ||
| 20469 | |||
| 20470 | return 1; | ||
| 20471 | } | ||
| 20472 | |||
| 20473 | sub runCallback { | ||
| 20474 | |||
| 20475 | # Called by an anonymous function in the task window object when the user clicks the | ||
| 20476 | # 'Run script' button | ||
| 20477 | # Runs the selected script (if any) | ||
| 20478 | # | ||
| 20479 | # Expected arguments | ||
| 20480 | # $tableObj - The GA::Table::Button object for the button | ||
| 20481 | # $button - The actual Gtk3::Button clicked | ||
| 20482 | # $id - The callback ID; in this case, an empty string | ||
| 20483 | # | ||
| 20484 | # Return values | ||
| 20485 | # 'undef' on improper arguments | ||
| 20486 | # 1 otherwise | ||
| 20487 | |||
| 20488 | my ($self, $tableObj, $button, $id, $check) = @_; | ||
| 20489 | |||
| 20490 | # Local variables | ||
| 20491 | my ($index, $rowRef, $selectFile, $shortFile); | ||
| 20492 | |||
| 20493 | # Check for improper arguments | ||
| 20494 | if (! defined $tableObj || ! defined $button || ! defined $id || defined $check) { | ||
| 20495 | |||
| 20496 | return $axmud::CLIENT->writeImproper($self->_objClass . '->runCallback', @_); | ||
| 20497 | } | ||
| 20498 | |||
| 20499 | $index = $self->slTableObj->get_select(); | ||
| 20500 | if (defined $index) { | ||
| 20501 | |||
| 20502 | # Get the selected row itself | ||
| 20503 | $rowRef = $self->slTableObj->get_row($index); | ||
| 20504 | $selectFile = $$rowRef[0]; | ||
| 20505 | |||
| 20506 | # The ';runscript' command needs us to remove the '.bas' ending | ||
| 20507 | $shortFile = $selectFile; | ||
| 20508 | $shortFile =~ s/\.bas$//; | ||
| 20509 | $self->session->pseudoCmd('runscript ' . $shortFile); | ||
| 20510 | } | ||
| 20511 | |||
| 20512 | # In all cases, update the task window's simple list (leave the same script selected) | ||
| 20513 | $self->populateList($selectFile); | ||
| 20514 | |||
| 20515 | return 1; | ||
| 20516 | } | ||
| 20517 | |||
| 20518 | sub runTaskCallback { | ||
| 20519 | |||
| 20520 | # Called by an anonymous function in the task window object when the user clicks the | ||
| 20521 | # 'Run as task' button | ||
| 20522 | # Runs the selected script (if any) as a task | ||
| 20523 | # | ||
| 20524 | # Expected arguments | ||
| 20525 | # $tableObj - The GA::Table::Button object for the button | ||
| 20526 | # $button - The actual Gtk3::Button clicked | ||
| 20527 | # $id - The callback ID; in this case, an empty string | ||
| 20528 | # | ||
| 20529 | # Return values | ||
| 20530 | # 'undef' on improper arguments | ||
| 20531 | # 1 otherwise | ||
| 20532 | |||
| 20533 | my ($self, $tableObj, $button, $id, $check) = @_; | ||
| 20534 | |||
| 20535 | # Local variables | ||
| 20536 | my ($index, $rowRef, $selectFile, $shortFile); | ||
| 20537 | |||
| 20538 | # Check for improper arguments | ||
| 20539 | if (! defined $tableObj || ! defined $button || ! defined $id || defined $check) { | ||
| 20540 | |||
| 20541 | return $axmud::CLIENT->writeImproper($self->_objClass . '->runTaskCallback', @_); | ||
| 20542 | } | ||
| 20543 | |||
| 20544 | $index = $self->slTableObj->get_select(); | ||
| 20545 | if (defined $index) { | ||
| 20546 | |||
| 20547 | # Get the selected row itself | ||
| 20548 | $rowRef = $self->slTableObj->get_row($index); | ||
| 20549 | $selectFile = $$rowRef[0]; | ||
| 20550 | |||
| 20551 | # The ';runscripttask' command needs us to remove the '.bas' ending | ||
| 20552 | $shortFile = $selectFile; | ||
| 20553 | $shortFile =~ s/\.bas$//; | ||
| 20554 | $self->session->pseudoCmd('runscripttask ' . $shortFile); | ||
| 20555 | } | ||
| 20556 | |||
| 20557 | # In all cases, update the task window's simple list (leave the same script selected) | ||
| 20558 | $self->populateList($selectFile); | ||
| 20559 | |||
| 20560 | return 1; | ||
| 20561 | } | ||
| 20562 | |||
| 20563 | sub refreshCallback { | ||
| 20564 | |||
| 20565 | # Called by an anonymous function in the task window object when the user clicks the | ||
| 20566 | # 'Refresh list' button | ||
| 20567 | # Refreshes the simple list, in case any script files have been added/removed by something | ||
| 20568 | # (or someone) other than this task | ||
| 20569 | # | ||
| 20570 | # Expected arguments | ||
| 20571 | # $tableObj - The GA::Table::Button object for the button | ||
| 20572 | # $button - The actual Gtk3::Button clicked | ||
| 20573 | # $id - The callback ID; in this case, an empty string | ||
| 20574 | # | ||
| 20575 | # Return values | ||
| 20576 | # 'undef' on improper arguments | ||
| 20577 | # 1 otherwise | ||
| 20578 | |||
| 20579 | my ($self, $tableObj, $button, $id, $check) = @_; | ||
| 20580 | |||
| 20581 | # Check for improper arguments | ||
| 20582 | if (! defined $tableObj || ! defined $button || ! defined $id || defined $check) { | ||
| 20583 | |||
| 20584 | return $axmud::CLIENT->writeImproper($self->_objClass . '->refreshCallback', @_); | ||
| 20585 | } | ||
| 20586 | |||
| 20587 | # Update the task window's simple list | ||
| 20588 | $self->populateList(); | ||
| 20589 | |||
| 20590 | return 1; | ||
| 20591 | } | ||
| 20592 | |||
| 20593 | ################## | ||
| 20594 | # Accessors - set | ||
| 20595 | |||
| 20596 | ################## | ||
| 20597 | # Accessors - task settings - get | ||
| 20598 | |||
| 20599 | # The accessors for task settings are inherited from the generic task | ||
| 20600 | |||
| 20601 | ################## | ||
| 20602 | # Accessors - task parameters - get | ||
| 20603 | |||
| 20604 | sub slTableObj | ||
| 20605 | { $_[0]->{slTableObj} } | ||
| 20606 | sub fileHash | ||
| 20607 | { my $self = shift; return %{$self->{fileHash}}; } | ||
| 20608 | } | ||
| 20609 | |||
| 20610 | { package Games::Axmud::Task::Locator; | ||
| 20611 | |||
| 20612 | use strict; | ||
| 20613 | use warnings; | ||
| 20614 | # use diagnostics; | ||
| 20615 | |||
| 20616 | use Glib qw(TRUE FALSE); | ||
| 20617 | |||
| 20618 | our @ISA = qw(Games::Axmud::Generic::Task Games::Axmud); | ||
| 20619 | |||
| 20620 | ################## | ||
| 20621 | # Constructors | ||
| 20622 | |||
| 20623 | sub new { | ||
| 20624 | |||
| 20625 | # Creates a new instances of the Locator task | ||
| 20626 | # | ||
| 20627 | # Expected arguments | ||
| 20628 | # $session - The parent GA::Session (not stored as an IV) | ||
| 20629 | # | ||
| 20630 | # Optional arguments | ||
| 20631 | # $taskType - Which tasklist this task is being created into - 'current' for the current | ||
| 20632 | # tasklist (tasks which are actually running now), 'initial' (tasks which | ||
| 20633 | # should be run when the user connects to the world), 'custom' (tasks with | ||
| 20634 | # customised initial parameters, which are run when the user demands). If | ||
| 20635 | # set to 'undef', this is a temporary task, created in order to access the | ||
| 20636 | # default values stored in IVs, that will not be added to any tasklist | ||
| 20637 | # $profName - ($taskType = 'current', when called by $self->clone) Name of the | ||
| 20638 | # profile from whose initial tasklist this task was created ('undef' if | ||
| 20639 | # none) | ||
| 20640 | # - ($taskType = 'initial') name of the profile in whose initial tasklist this | ||
| 20641 | # task will be. If 'undef', the global initial tasklist is used | ||
| 20642 | # - ($taskType = 'custom') 'undef' | ||
| 20643 | # $profCategory | ||
| 20644 | # - ($taskType = 'current', 'initial') which category the profile falls undef | ||
| 20645 | # (i.e. 'world', 'race', 'char', etc, or 'undef' if no profile) | ||
| 20646 | # - ($taskType = 'custom') 'undef' | ||
| 20647 | # $customName | ||
| 20648 | # - ($taskType = 'current', 'initial') 'undef' | ||
| 20649 | # - ($taskType = 'custom') the custom task name, matching a key in | ||
| 20650 | # GA::Session->customTaskHash | ||
| 20651 | # | ||
| 20652 | # Return values | ||
| 20653 | # 'undef' on improper arguments or if the task can't be added to the specified tasklist | ||
| 20654 | # Blessed reference to the newly-created object on success | ||
| 20655 | |||
| 20656 | my ($class, $session, $taskType, $profName, $profCategory, $customName, $check) = @_; | ||
| 20657 | |||
| 20658 | # Check for improper arguments | ||
| 20659 | if (! defined $class || ! defined $session || defined $check) { | ||
| 20660 | |||
| 20661 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 20662 | } | ||
| 20663 | |||
| 20664 | if ($taskType) { | ||
| 20665 | |||
| 20666 | # For initial tasks, check that $profName exists | ||
| 20667 | if ( | ||
| 20668 | $taskType eq 'initial' | ||
| 20669 | && defined $profName | ||
| 20670 | && ! $session->ivExists('profHash', $profName) | ||
| 20671 | ) { | ||
| 20672 | return $session->writeError( | ||
| 20673 | 'Can\'t create new task because \'' . $profName . '\' profile doesn\'t exist', | ||
| 20674 | $class . '->new', | ||
| 20675 | ); | ||
| 20676 | |||
| 20677 | # For custom tasks, check that $customName doesn't already exist | ||
| 20678 | } elsif ( | ||
| 20679 | $taskType eq 'custom' | ||
| 20680 | && $axmud::CLIENT->ivExists('customTaskHash', $customName) | ||
| 20681 | ) { | ||
| 20682 | return $session->writeError( | ||
| 20683 | 'Can\'t create new custom task because \'' . $customName . '\' is already being' | ||
| 20684 | . ' used', | ||
| 20685 | $class . '->new', | ||
| 20686 | ); | ||
| 20687 | |||
| 20688 | } elsif ($taskType ne 'current' && $taskType ne 'initial' && $taskType ne 'custom') { | ||
| 20689 | |||
| 20690 | return $session->writeError( | ||
| 20691 | 'Can\'t create new task because \'' . $taskType . '\' is an invalid tasklist', | ||
| 20692 | $class . '->new', | ||
| 20693 | ); | ||
| 20694 | } | ||
| 20695 | } | ||
| 20696 | |||
| 20697 | # Task settings | ||
| 20698 | my $self = Games::Axmud::Generic::Task->new( | ||
| 20699 | $session, | ||
| 20700 | $taskType, | ||
| 20701 | $profName, | ||
| 20702 | $profCategory, | ||
| 20703 | $customName, | ||
| 20704 | ); | ||
| 20705 | |||
| 20706 | $self->{_objName} = 'locator_task'; | ||
| 20707 | $self->{_objClass} = $class; | ||
| 20708 | $self->{_parentFile} = undef; # Set below | ||
| 20709 | $self->{_parentWorld} = undef; # Set below | ||
| 20710 | $self->{_privFlag} = TRUE, # All IVs are private | ||
| 20711 | |||
| 20712 | $self->{name} = 'locator_task'; | ||
| 20713 | $self->{prettyName} = 'Locator'; | ||
| 20714 | $self->{shortName} = 'Lc'; | ||
| 20715 | $self->{shortCutIV} = 'locatorTask'; # Axmud built-in jealous task | ||
| 20716 | |||
| 20717 | $self->{category} = 'process'; | ||
| 20718 | $self->{descrip} = 'Keeps track of character\'s location in the world'; | ||
| 20719 | $self->{jealousyFlag} = TRUE; | ||
| 20720 | $self->{requireLocatorFlag} = FALSE; # Locator doesn't require itself | ||
| 20721 | $self->{profSensitivityFlag} = TRUE; | ||
| 20722 | $self->{storableFlag} = TRUE; | ||
| 20723 | $self->{delayTime} = 0; | ||
| 20724 | $self->{allowWinFlag} = TRUE; | ||
| 20725 | $self->{requireWinFlag} = FALSE; | ||
| 20726 | $self->{startWithWinFlag} = TRUE; | ||
| 20727 | $self->{winPreferList} = ['pane', 'grid']; | ||
| 20728 | $self->{winmap} = 'basic_fill'; | ||
| 20729 | $self->{winUpdateFunc} = 'refreshWin'; | ||
| 20730 | $self->{tabMode} = 'simple'; | ||
| 20731 | $self->{monochromeFlag} = FALSE; | ||
| 20732 | $self->{noScrollFlag} = TRUE; | ||
| 20733 | $self->{ttsFlag} = TRUE; | ||
| 20734 | $self->{ttsConfig} = 'locator'; | ||
| 20735 | $self->{ttsAttribHash} = { | ||
| 20736 | 'title' => undef, | ||
| 20737 | 'descrip' => undef, | ||
| 20738 | 'description' => undef, | ||
| 20739 | 'exit' => undef, | ||
| 20740 | 'exits' => undef, | ||
| 20741 | 'content' => undef, | ||
| 20742 | 'contents' => undef, | ||
| 20743 | }; | ||
| 20744 | $self->{ttsFlagAttribHash} = { | ||
| 20745 | 'title' => FALSE, | ||
| 20746 | 'descrip' => FALSE, | ||
| 20747 | 'description' => FALSE, | ||
| 20748 | 'exit' => FALSE, | ||
| 20749 | 'exits' => FALSE, | ||
| 20750 | 'content' => FALSE, | ||
| 20751 | 'contents' => FALSE, | ||
| 20752 | }; | ||
| 20753 | $self->{ttsAlertAttribHash} = {}; | ||
| 20754 | $self->{status} = 'wait_init'; | ||
| 20755 | # $self->{activeFlag} = TRUE; # Task can't be activated/disactivated | ||
| 20756 | |||
| 20757 | # Task parameters | ||
| 20758 | # Total number of room statements seen since the task started (or since the last reset) | ||
| 20759 | $self->{roomCount} = 0; | ||
| 20760 | # The last line in the display buffer searched by the task (matches a key in | ||
| 20761 | # GA::Session->displayBufferHash); 'undef' if no lines searched yet | ||
| 20762 | $self->{lastBufferLine} = undef; | ||
| 20763 | # The last line in the display buffer where the task found an anchor for a room statement | ||
| 20764 | # (usually a line containing the list of exits); 'undef' if no anchors found yet | ||
| 20765 | $self->{lastAnchorLine} = undef; | ||
| 20766 | # The last line in the room statement whose anchor is stored in ->lastAnchorLine (if the | ||
| 20767 | # anchor was the last line of the statement, this IV's value will be the same as the value | ||
| 20768 | # stored in ->lastAnchorLine) | ||
| 20769 | $self->{lastStatementEndLine} = undef; | ||
| 20770 | # The first line in the room statement whose anchor is stored in ->lastAnchorLine (not used | ||
| 20771 | # by anything at the moment, but available if required) | ||
| 20772 | $self->{lastStatementStartLine} = undef; | ||
| 20773 | # Lines are usually analysed only ones. In certain cases (where a world profile's | ||
| 20774 | # ->verboseFinalPattern, ->shortFinalPattern or ->briefFinalPattern is set), when the task | ||
| 20775 | # receives some but not all of the room statement, it can wait until the rest of the | ||
| 20776 | # statement is received, before processing it (in fact, it waits until a line matching | ||
| 20777 | # ->verboseFinalPattern etc is received) | ||
| 20778 | # In that situation, this IV is set to the first line that should be re-analysed; its value | ||
| 20779 | # is copied to $self->lastBufferLine once per task loop until the rest of the room | ||
| 20780 | # statement is received | ||
| 20781 | $self->{restartBufferLine} = undef; | ||
| 20782 | # Blessed reference to the current room object (a GA::ModelObj::Room), which contains | ||
| 20783 | # information about the current room, as it is now: the same information is not | ||
| 20784 | # necessarily stored by the automapper's current room. 'undef' if no current room | ||
| 20785 | $self->{roomObj} = undef; | ||
| 20786 | # Blessed reference to the previous room object (a GA::ModelObj::Room), which will be the | ||
| 20787 | # most recent one created by this task. 'undef' if no previous room | ||
| 20788 | $self->{prevRoomObj} = undef; | ||
| 20789 | # If the automapper has a current room, the world model number of that room (which will | ||
| 20790 | # correspond to the non-model room, $self->roomObj). 'undef' otherwise | ||
| 20791 | $self->{modelNumber} = undef; | ||
| 20792 | |||
| 20793 | # The 'weather' component captures lines of text that should not be stored in the model, but | ||
| 20794 | # should be displayed in this task's window. (This is mostly used for weather and the time | ||
| 20795 | # of day, but can be used for anything) | ||
| 20796 | # The contents of this hash is replaced whenever $self->processAnchor successfully extracts | ||
| 20797 | # a room statement | ||
| 20798 | # The keys are the name of the 'weather' component. The corresponding values are the line(s) | ||
| 20799 | # captured by that component, with any text portions removed as normal, and with multiple | ||
| 20800 | # lines joined together in a single string. Both key and value are displayed in the window | ||
| 20801 | $self->{weatherHash} = {}; | ||
| 20802 | # Flag which sets how objects in the room contents are displayed in the Locator task window. | ||
| 20803 | # FALSE to display the (original) base string, TRUE to nouns first, and so on | ||
| 20804 | $self->{showParsedFlag} = FALSE; | ||
| 20805 | |||
| 20806 | # Hash used to store the received lines of text that comprise certain components of the | ||
| 20807 | # room statement, so that the text-to-speech routines can read them aloud (if required). | ||
| 20808 | # Hash in the form | ||
| 20809 | # $ttsToReadHash{attribute} = string | ||
| 20810 | # ...where 'attribute' is one of the TTS attributes 'title', 'descrip', 'exit', 'content' | ||
| 20811 | # or 'command', and string is a single string comprising one or more received lines of | ||
| 20812 | # text, joined together. The hash is emptied at the start of the call to | ||
| 20813 | # $self->processAnchor, filled up as required, and then the strings are read out in the | ||
| 20814 | # correct order, if required | ||
| 20815 | $self->{ttsToReadHash} = {}; | ||
| 20816 | |||
| 20817 | # If MXP is turned on and is returning the standard tag properties 'RoomName', 'RoomDesc', | ||
| 20818 | # 'RoomExit' and 'RoomNum', this flag is set to TRUE (and the task searches for these | ||
| 20819 | # tag properties rather than searching for anchor lines as usual) | ||
| 20820 | $self->{useMxpFlag} = FALSE; | ||
| 20821 | # A hash of MXP standard tag properties. The keys are the four properties recognised by the | ||
| 20822 | # Locator Task | ||
| 20823 | # The Locator task expects the tags to be used in a group, representing a single room | ||
| 20824 | # statement. The way the group is handled, by default is unsophisticated: for example, if | ||
| 20825 | # the task sees two successive 'RoomName' tags, that must represent two room statements. | ||
| 20826 | # Likewise, if the task has analysed all of the received text, that must represent the end | ||
| 20827 | # of the room statement, even if all four types of tag were not found | ||
| 20828 | # The world profile can optionally specify the tags marking the beginning and/or end of the | ||
| 20829 | # group. If either (or both) are defined, the handling is a little more robust | ||
| 20830 | $self->{mxpPropHash} = { | ||
| 20831 | 'RoomName' => undef, | ||
| 20832 | 'RoomDesc' => undef, | ||
| 20833 | 'RoomExit' => undef, | ||
| 20834 | 'RoomNum' => undef, | ||
| 20835 | }; | ||
| 20836 | # The tagged text, when received, is stored temporarily in this hash. The keys are the same | ||
| 20837 | # as those in $self->mxpPropHash; the corresponding values are the tagged text. When a | ||
| 20838 | # room statement is processed, the hash is emptied | ||
| 20839 | $self->{mxpPropCurrentHash} = {}; | ||
| 20840 | # The line number at which tagged text was added to an empty $self->currentMxpPropHash | ||
| 20841 | # (undef if the hash is empty) | ||
| 20842 | $self->{mxpPropStartLine} = undef; | ||
| 20843 | |||
| 20844 | # On some worlds, the part of the room statement containing the verbose description can | ||
| 20845 | # contain lines that are actually part of the room's contents, for example the third line | ||
| 20846 | # in: | ||
| 20847 | # | ||
| 20848 | # You are in a vast forest. The trees and thick vegetation press in from... | ||
| 20849 | # canopy overhead. The forest is impassably thick southward. | ||
| 20850 | # There is a sign here you can read. | ||
| 20851 | # Obvious exits: south, north, east, northeast, northwest | ||
| 20852 | # | ||
| 20853 | # When those lines are found, their replacement strings (defined in the world profile, | ||
| 20854 | # e.g. 'A sign is here') are temporarily stored in this IV until the same room's contents | ||
| 20855 | # can be processed | ||
| 20856 | $self->{tempContentsList} = []; | ||
| 20857 | |||
| 20858 | # Whenever a world command is sent, GA::Session->updateCmdBuffer calls this task, and the | ||
| 20859 | # following IVs are set | ||
| 20860 | # A list of all GA::Buffer::Cmd objects which haven't yet been checked, some of which might | ||
| 20861 | # be movement commands | ||
| 20862 | $self->{cmdObjList} = []; | ||
| 20863 | # A subset of $self_>cmdObjList, containing all GA::Buffer::Cmd objects which the session | ||
| 20864 | # has already decided are look/glance or movement commands. The number of room | ||
| 20865 | # descriptions expected by the Locator is the number of objects in this list | ||
| 20866 | $self->{moveList} = []; | ||
| 20867 | # The GA::Buffer::Cmd that is thought to have caused the most recent move from one room to | ||
| 20868 | # another (actually, the last one removed from $self->moveList); set to 'undef' if the | ||
| 20869 | # last move was a result of unknown command(s) | ||
| 20870 | $self->{prevMoveObj} = undef; | ||
| 20871 | # The direction of the most recent move, taken from $self->prevMoveObj; set to 'undef' if | ||
| 20872 | # unknown | ||
| 20873 | $self->{prevMove} = undef; | ||
| 20874 | # When $self->add_cmdObj is called, this IV is set (or reset). If $self->moveList is empty | ||
| 20875 | # at that time, this IV is set to GA::Session->displayBufferCount, which represents the | ||
| 20876 | # buffer number of the first line of text received from the world in response to the | ||
| 20877 | # command. If $self->moveList is not empty at that time, it's reset to 'undef' | ||
| 20878 | # (The IV is used for auto-processing new failed exit messages) | ||
| 20879 | $self->{prevCmdBufferNum} = undef; | ||
| 20880 | # Flag set to TRUE whenever a failed exit is detected by this task (any code can set this | ||
| 20881 | # flag to FALSE using $self->reset_failExitFlag, and then check the flag regularly, | ||
| 20882 | # waiting to see when a failed exit is next detected) | ||
| 20883 | $self->{failExitFlag} = FALSE; | ||
| 20884 | # Flag set to TRUE whenever an involuntary exit is detected by this task, meaning the | ||
| 20885 | # character's current location is no longer known (any code can set this flag to FALSE, | ||
| 20886 | # using $self->reset_involuntaryExitFlag, and then check the flag regularly, waiting to | ||
| 20887 | # see when an involuntary exit is next detected) | ||
| 20888 | $self->{involuntaryExitFlag} = FALSE; | ||
| 20889 | # Arrival tag: for the ';drive' (etc) commands, when the character moves along a pre-defined | ||
| 20890 | # route and the room at the end of the route has a tag specified by the ';drive' (etc) | ||
| 20891 | # command, that tag is stored here. (When this task's ->moveList becomes empty, that | ||
| 20892 | # current room object is given this tag if it doesn't already have a tag). If set to | ||
| 20893 | # 'undef', no tag setting necessary | ||
| 20894 | $self->{arrivalTag} = undef; | ||
| 20895 | |||
| 20896 | # When the task is reset because a current profile has changed, the task searches backwards, | ||
| 20897 | # from the most recent line received, looking for a room statement. However, if the task | ||
| 20898 | # is reset using the ';resetlocator' command, we don't want this behaviour - the task must | ||
| 20899 | # wait for the user to move, or type a look/glance command | ||
| 20900 | # ';resetlocator' sets this flag to TRUE to prevent the task, when it is reset, from | ||
| 20901 | # searching already-received lines for room descriptions | ||
| 20902 | $self->{manualResetFlag} = FALSE; | ||
| 20903 | # After a manual reset, it's a bit of effort for the user to set the automapper's current | ||
| 20904 | # room. This IV can be used to reduce the effort | ||
| 20905 | # 'do_nothing' - do nothing after a manual reset; user must type 'look', 'north' etc | ||
| 20906 | # to get a room statement, then the automapper's current room can be set | ||
| 20907 | # 'search_back' - (behaviour before v1.0.568) - search backwards, from the most recent | ||
| 20908 | # line received, looking for a room statement - as if the task had just started | ||
| 20909 | # 'send_look' - send a standard 'look' command to the world, which the task can | ||
| 20910 | # interpret | ||
| 20911 | $self->{autoLookMode} = 'search_back'; | ||
| 20912 | |||
| 20913 | # Task window customisation | ||
| 20914 | # Maximum number of characters of the verbose room description to display in the task | ||
| 20915 | # window ('undef' or 0 to display the whole description) | ||
| 20916 | $self->{winDescripLimit} = 200; | ||
| 20917 | # Flag set to TRUE if multiple corpses should be shown on a single line; set to FALSE if | ||
| 20918 | # each corpse should be shown on a separate line | ||
| 20919 | $self->{combineCorpseFlag} = TRUE; | ||
| 20920 | # Flag set to TRUE if multiple body parts (detached arms, legs, etc) are shown on a single | ||
| 20921 | # line (the same line as corpses); set to FALSE if each body part shown on a separate line | ||
| 20922 | $self->{combineBodyPartFlag} = TRUE; | ||
| 20923 | |||
| 20924 | # Bless task | ||
| 20925 | bless $self, $class; | ||
| 20926 | |||
| 20927 | # For all tasks that aren't temporary... | ||
| 20928 | if ($taskType) { | ||
| 20929 | |||
| 20930 | # Check that the task doesn't belong to a disabled plugin (in which case, it can't be | ||
| 20931 | # added to any current, initial or custom tasklist) | ||
| 20932 | if (! $self->checkPlugins()) { | ||
| 20933 | |||
| 20934 | return undef; | ||
| 20935 | } | ||
| 20936 | |||
| 20937 | # Set the parent file object | ||
| 20938 | $self->setParentFileObj($session, $taskType, $profName, $profCategory); | ||
| 20939 | |||
| 20940 | # Create entries in tasklists, if possible | ||
| 20941 | if (! $self->updateTaskLists($session)) { | ||
| 20942 | |||
| 20943 | return undef; | ||
| 20944 | } | ||
| 20945 | } | ||
| 20946 | |||
| 20947 | # Task creation complete | ||
| 20948 | return $self; | ||
| 20949 | } | ||
| 20950 | |||
| 20951 | sub clone { | ||
| 20952 | |||
| 20953 | # Create a clone of an existing task | ||
| 20954 | # Usually used upon connection to a world, when every task in the initial tasklists must | ||
| 20955 | # be cloned into a new object, representing a task in the current tasklist | ||
| 20956 | # (Also used when cloning a profile object, since all the tasks in its initial tasklist must | ||
| 20957 | # also be cloned) | ||
| 20958 | # | ||
| 20959 | # Expected arguments | ||
| 20960 | # $session - The parent GA::Session (not stored as an IV) | ||
| 20961 | # $taskType - Which tasklist this task is being created into - 'current' for the current | ||
| 20962 | # tasklist (tasks which are actually running now), 'initial' (tasks which | ||
| 20963 | # should be run when the user connects to the world). Custom tasks aren't | ||
| 20964 | # cloned (at the moment) | ||
| 20965 | # | ||
| 20966 | # Optional arguments | ||
| 20967 | # $profName - ($taskType = 'initial') name of the profile in whose initial tasklist the | ||
| 20968 | # existing task is stored | ||
| 20969 | # $profCategory | ||
| 20970 | # - ($taskType = 'initial') which category the profile falls under (i.e. | ||
| 20971 | # 'world', 'race', 'char', etc) | ||
| 20972 | # | ||
| 20973 | # Return values | ||
| 20974 | # 'undef' on improper arguments or if the task can't be cloned | ||
| 20975 | # Blessed reference to the newly-created object on success | ||
| 20976 | |||
| 20977 | my ($self, $session, $taskType, $profName, $profCategory, $check) = @_; | ||
| 20978 | |||
| 20979 | # Check for improper arguments | ||
| 20980 | if ( | ||
| 20981 | ! defined $session || ! defined $taskType || defined $check | ||
| 20982 | || ($taskType ne 'current' && $taskType ne 'initial') | ||
| 20983 | || ($taskType eq 'initial' && (! defined $profName || ! defined $profCategory)) | ||
| 20984 | ) { | ||
| 20985 | return $axmud::CLIENT->writeImproper($self->_objClass . '->clone', @_); | ||
| 20986 | } | ||
| 20987 | |||
| 20988 | # For initial tasks, check that $profName exists | ||
| 20989 | if ( | ||
| 20990 | $taskType eq 'initial' | ||
| 20991 | && defined $profName | ||
| 20992 | && ! $session->ivExists('profHash', $profName) | ||
| 20993 | ) { | ||
| 20994 | return $axmud::CLIENT->writeError( | ||
| 20995 | 'Can\'t create cloned task because \'' . $profName . '\' profile doesn\'t exist', | ||
| 20996 | $self->_objClass . '->clone', | ||
| 20997 | ); | ||
| 20998 | } | ||
| 20999 | |||
| 21000 | # Check that the task doesn't belong to a disabled plugin (in which case, it can't be | ||
| 21001 | # cloned) | ||
| 21002 | if (! $self->checkPlugins()) { | ||
| 21003 | |||
| 21004 | return undef; | ||
| 21005 | } | ||
| 21006 | |||
| 21007 | # Create the new task, using default settings and parameters | ||
| 21008 | my $clone = $self->_objClass->new($session, $taskType, $profName, $profCategory); | ||
| 21009 | |||
| 21010 | # Most of the cloned task's settings have default values, but a few are copied from the | ||
| 21011 | # original | ||
| 21012 | $self->cloneTaskSettings($clone); | ||
| 21013 | |||
| 21014 | # Give the new (cloned) task the same initial parameters as the original one | ||
| 21015 | $clone->{roomCount} = $self->roomCount; | ||
| 21016 | $clone->{lastBufferLine} = $self->lastBufferLine; | ||
| 21017 | $clone->{lastAnchorLine} = $self->lastAnchorLine; | ||
| 21018 | $clone->{lastStatementEndLine} = $self->lastStatementEndLine; | ||
| 21019 | $clone->{lastStatementStartLine} | ||
| 21020 | = $self->lastStatementStartLine; | ||
| 21021 | $clone->{restartBufferLine} = $self->restartBufferLine; | ||
| 21022 | $clone->{roomObj} = $self->roomObj; | ||
| 21023 | $clone->{prevRoomObj} = $self->prevRoomObj; | ||
| 21024 | $clone->{modelNumber} = $self->modelNumber; | ||
| 21025 | $clone->{weatherHash} = {$self->weatherHash}; | ||
| 21026 | $clone->{showParsedFlag} = $self->showParsedFlag; | ||
| 21027 | |||
| 21028 | $clone->{ttsToReadHash} = {$self->ttsToReadHash}; | ||
| 21029 | |||
| 21030 | $clone->{useMxpFlag} = $self->useMxpFlag; | ||
| 21031 | $clone->{mxpPropHash} = {$self->mxpPropHash}; | ||
| 21032 | $clone->{mxpPropCurrentHash} = {$self->mxpPropCurrentHash}; | ||
| 21033 | $clone->{mxpPropStartLine} = $self->mxpPropStartLine; | ||
| 21034 | |||
| 21035 | $clone->{tempContentsList} = [$self->tempContentsList]; | ||
| 21036 | |||
| 21037 | $clone->{cmdObjList} = [$self->cmdObjList]; | ||
| 21038 | $clone->{moveList} = [$self->moveList]; | ||
| 21039 | $clone->{prevMoveObj} = $self->prevMoveObj; | ||
| 21040 | $clone->{prevMove} = $self->prevMove; | ||
| 21041 | $clone->{prevCmdBufferNum} = $self->prevCmdBufferNum; | ||
| 21042 | $clone->{failExitFlag} = $self->failExitFlag; | ||
| 21043 | $clone->{involuntaryExitFlag} = $self->involuntaryExitFlag; | ||
| 21044 | $clone->{arrivalTag} = $self->arrivalTag; | ||
| 21045 | |||
| 21046 | $clone->{manualResetFlag} = $self->manualResetFlag; | ||
| 21047 | $clone->{autoLookMode} = $self->autoLookMode; | ||
| 21048 | |||
| 21049 | $clone->{winDescripLimit} = $self->winDescripLimit; | ||
| 21050 | $clone->{combineCorpseFlag} = $self->combineCorpseFlag; | ||
| 21051 | $clone->{combineBodyPartFlag} = $self->combineBodyPartFlag; | ||
| 21052 | |||
| 21053 | # Cloning complete | ||
| 21054 | return $clone; | ||
| 21055 | } | ||
| 21056 | |||
| 21057 | sub preserve { | ||
| 21058 | |||
| 21059 | # Called by $self->main whenever this task is reset, in order to preserve some if its task | ||
| 21060 | # parameters (but not necessarily all of them) | ||
| 21061 | # | ||
| 21062 | # Expected arguments | ||
| 21063 | # $newTask - The new task which has been created, to which some of this task's instance | ||
| 21064 | # variables might have to be transferred | ||
| 21065 | # | ||
| 21066 | # Return values | ||
| 21067 | # 'undef' on improper arguments, or if $newTask isn't in the GA::Session's current | ||
| 21068 | # tasklist | ||
| 21069 | # 1 on success | ||
| 21070 | |||
| 21071 | my ($self, $newTask, $check) = @_; | ||
| 21072 | |||
| 21073 | # Check for improper arguments | ||
| 21074 | if (! defined $newTask || defined $check) { | ||
| 21075 | |||
| 21076 | return $axmud::CLIENT->writeImproper($self->_objClass . '->preserve', @_); | ||
| 21077 | } | ||
| 21078 | |||
| 21079 | # Check the task is in the current tasklist | ||
| 21080 | if (! $self->session->ivExists('currentTaskHash', $newTask->uniqueName)) { | ||
| 21081 | |||
| 21082 | return $self->writeWarning( | ||
| 21083 | '\'' . $self->uniqueName . '\' task missing from the current tasklist', | ||
| 21084 | $self->_objClass . '->preserve', | ||
| 21085 | ); | ||
| 21086 | } | ||
| 21087 | |||
| 21088 | # Preserve some task parameters (the others are left with their default settings, some of | ||
| 21089 | # which will be re-initialised in stage 2) | ||
| 21090 | |||
| 21091 | # Preserve the flag that indicates a manual reset | ||
| 21092 | $newTask->ivPoke('manualResetFlag', $self->manualResetFlag); | ||
| 21093 | $newTask->ivPoke('autoLookMode', $self->autoLookMode); | ||
| 21094 | # Preserve the description size limit | ||
| 21095 | $newTask->ivPoke('winDescripLimit', $self->winDescripLimit); | ||
| 21096 | # Preserve the corpse/body part flags | ||
| 21097 | $newTask->ivPoke('combineCorpseFlag', $self->combineCorpseFlag); | ||
| 21098 | $newTask->ivPoke('combineBodyPartFlag', $self->combineBodyPartFlag); | ||
| 21099 | $newTask->ivPoke('showParsedFlag', $self->showParsedFlag); | ||
| 21100 | $newTask->ivPoke('autoLookMode', $self->autoLookMode); | ||
| 21101 | |||
| 21102 | return 1; | ||
| 21103 | } | ||
| 21104 | |||
| 21105 | # sub setParentFileObj {} # Inherited from generic task | ||
| 21106 | |||
| 21107 | # sub updateTaskLists {} # Inherited from generic task | ||
| 21108 | |||
| 21109 | sub ttsReadAttrib { | ||
| 21110 | |||
| 21111 | # Called by GA::Cmd::Read->do and PermRead->do | ||
| 21112 | # Users can use the client command ';read' to interact with individual tasks, typically | ||
| 21113 | # getting them to read out information (e.g. the Status task can read out current health | ||
| 21114 | # points) | ||
| 21115 | # The ';read' command is in the form ';read <attribute>' or ';read <attribute> <value>'. | ||
| 21116 | # The ';read' command looks up the <attribute> in GA::Client->ttsAttribHash, which tells | ||
| 21117 | # it which task to call | ||
| 21118 | # | ||
| 21119 | # Expected arguments | ||
| 21120 | # $attrib - The TTS attribute specified by the calling function. Must be one of the | ||
| 21121 | # keys in $self->ttsAttribHash | ||
| 21122 | # | ||
| 21123 | # Optional arguments | ||
| 21124 | # $value - The value specified by the calling function (or 'undef' if none was | ||
| 21125 | # specified) | ||
| 21126 | # $noReadFlag - Set to TRUE when called by GA::Cmd::PermRead->do, in which case only this | ||
| 21127 | # task's hash of attributes is updated. If set to FALSE (or 'undef'), | ||
| 21128 | # something is usually read aloud, too | ||
| 21129 | # | ||
| 21130 | # Return values | ||
| 21131 | # 'undef' on improper arguments or if the $attrib doesn't exist in this task's | ||
| 21132 | # ->ttsConfig | ||
| 21133 | # 1 otherwise | ||
| 21134 | |||
| 21135 | my ($self, $attrib, $value, $noReadFlag, $check) = @_; | ||
| 21136 | |||
| 21137 | # Local variables | ||
| 21138 | my ($string, $number); | ||
| 21139 | |||
| 21140 | # Check for improper arguments | ||
| 21141 | if (! defined $attrib || defined $check) { | ||
| 21142 | |||
| 21143 | return $axmud::CLIENT->writeImproper($self->_objClass . '->ttsReadAttrib', @_); | ||
| 21144 | } | ||
| 21145 | |||
| 21146 | # TTS attributes are case-insensitive | ||
| 21147 | $attrib = lc($attrib); | ||
| 21148 | |||
| 21149 | # Check that the specified attribute is actually used by this task (';read' or ';permread' | ||
| 21150 | # should carry out this check, but better safe than sorry) | ||
| 21151 | if (! $self->ivExists('ttsAttribHash', $attrib)) { | ||
| 21152 | |||
| 21153 | return undef; | ||
| 21154 | |||
| 21155 | } elsif ($noReadFlag) { | ||
| 21156 | |||
| 21157 | # When called by GA::Cmd::PermRead->do, don't read out anything, just update the hash of | ||
| 21158 | # attributes (when appropriate) | ||
| 21159 | |||
| 21160 | # (no attributes require an update) | ||
| 21161 | |||
| 21162 | return 1; | ||
| 21163 | |||
| 21164 | } else { | ||
| 21165 | |||
| 21166 | # Custom behaviour for this task | ||
| 21167 | |||
| 21168 | # Can't do anything if the current room isn't known | ||
| 21169 | if (! $self->roomObj) { | ||
| 21170 | |||
| 21171 | $self->ttsQuick('The Locator task doesn\'t know anything about the current room'); | ||
| 21172 | |||
| 21173 | # Locator task attributes | ||
| 21174 | } elsif ($attrib eq 'title') { | ||
| 21175 | |||
| 21176 | # Read the current room's title, if known | ||
| 21177 | if (! $self->roomObj->titleList) { | ||
| 21178 | |||
| 21179 | $self->ttsQuick('The current room\'s title is not known'); | ||
| 21180 | |||
| 21181 | } else { | ||
| 21182 | |||
| 21183 | # There should only be one title in ->$roomObj | ||
| 21184 | $self->ttsQuick('Room title: ' . $self->roomObj->ivFirst('titleList')); | ||
| 21185 | } | ||
| 21186 | |||
| 21187 | } elsif ($attrib eq 'descrip' || $attrib eq 'description') { | ||
| 21188 | |||
| 21189 | # Read the room description, if known | ||
| 21190 | if (! $self->roomObj->descripHash) { | ||
| 21191 | |||
| 21192 | $self->ttsQuick('The current room\'s description is not known'); | ||
| 21193 | |||
| 21194 | } else { | ||
| 21195 | |||
| 21196 | # Decide which description to use. There should only be one in $self->roomObj, | ||
| 21197 | # so use the first one found | ||
| 21198 | OUTER: foreach my $key ($self->roomObj->descripHash) { | ||
| 21199 | |||
| 21200 | $string = $self->roomObj->ivShow('descripHash', $key); | ||
| 21201 | last OUTER; | ||
| 21202 | } | ||
| 21203 | |||
| 21204 | # If the user specified a maximum number of characters as $value, use it | ||
| 21205 | if ( | ||
| 21206 | defined $value | ||
| 21207 | && $axmud::CLIENT->intCheck($value, 1, ((length $string) + 1)) | ||
| 21208 | ) { | ||
| 21209 | $number = index($string, ' ', $value); | ||
| 21210 | if ($number != -1) { | ||
| 21211 | |||
| 21212 | $string = substr($string, 0, ($number)); | ||
| 21213 | } | ||
| 21214 | } | ||
| 21215 | |||
| 21216 | $self->ttsQuick('Room description: ' . $string); | ||
| 21217 | } | ||
| 21218 | |||
| 21219 | } elsif ($attrib eq 'exit' || $attrib eq 'exits') { | ||
| 21220 | |||
| 21221 | # Read the exit list, if known | ||
| 21222 | if (! $self->roomObj->sortedExitList) { | ||
| 21223 | |||
| 21224 | $self->ttsQuick('The current room has no exits'); | ||
| 21225 | |||
| 21226 | } else { | ||
| 21227 | |||
| 21228 | $self->ttsQuick('Exits: ' . join(', ', $self->roomObj->sortedExitList)); | ||
| 21229 | } | ||
| 21230 | |||
| 21231 | } elsif ($attrib eq 'content' || $attrib eq 'contents') { | ||
| 21232 | |||
| 21233 | # Read the contents list, if known | ||
| 21234 | if (! $self->roomObj->tempObjList) { | ||
| 21235 | |||
| 21236 | $self->ttsQuick('The current room is empty'); | ||
| 21237 | |||
| 21238 | } else { | ||
| 21239 | |||
| 21240 | $string = ''; | ||
| 21241 | foreach my $obj ($self->roomObj->tempObjList) { | ||
| 21242 | |||
| 21243 | $string .= ', ' . $obj->baseString; | ||
| 21244 | } | ||
| 21245 | |||
| 21246 | $self->ttsQuick('Contents: ' . $string); | ||
| 21247 | } | ||
| 21248 | } | ||
| 21249 | |||
| 21250 | # Operation complete | ||
| 21251 | return 1; | ||
| 21252 | } | ||
| 21253 | } | ||
| 21254 | |||
| 21255 | # sub ttsSwitchFlagAttrib {} # Inherited from generic task | ||
| 21256 | |||
| 21257 | # sub ttsSetAlertAttrib {} # Inherited from generic task | ||
| 21258 | |||
| 21259 | ################## | ||
| 21260 | # Task windows | ||
| 21261 | |||
| 21262 | # sub toggleWin {} # Inherited from generic task | ||
| 21263 | |||
| 21264 | # sub openWin {} # Inherited from generic task | ||
| 21265 | |||
| 21266 | # sub closeWin {} # Inherited from generic task | ||
| 21267 | |||
| 21268 | ################## | ||
| 21269 | # Methods | ||
| 21270 | |||
| 21271 | # sub main {} # Inherited from generic task | ||
| 21272 | |||
| 21273 | sub doShutdown { | ||
| 21274 | |||
| 21275 | # Called by $self->main, just before the task completes a shutdown | ||
| 21276 | # | ||
| 21277 | # Expected arguments | ||
| 21278 | # (none besides $self) | ||
| 21279 | # | ||
| 21280 | # Return values | ||
| 21281 | # 'undef' on improper arguments | ||
| 21282 | # 1 otherwise | ||
| 21283 | |||
| 21284 | my ($self, $check) = @_; | ||
| 21285 | |||
| 21286 | # Check for improper arguments | ||
| 21287 | if (defined $check) { | ||
| 21288 | |||
| 21289 | return $axmud::CLIENT->writeImproper($self->_objClass . '->doShutdown', @_); | ||
| 21290 | } | ||
| 21291 | |||
| 21292 | # Go through all tasks in the current tasklist, sending shutdown messages to any of them | ||
| 21293 | # that require the Locator task | ||
| 21294 | foreach my $taskObj ($self->session->ivValues('currentTaskHash')) { | ||
| 21295 | |||
| 21296 | # (Locator task doesn't have its ->requireLocatorFlag set, so we don't need to check | ||
| 21297 | # whether $obj is the same task as $self) | ||
| 21298 | if ($taskObj->requireLocatorFlag) { | ||
| 21299 | |||
| 21300 | # Tell the other task to shut down | ||
| 21301 | $taskObj->set_shutdownFlag(TRUE); | ||
| 21302 | } | ||
| 21303 | } | ||
| 21304 | |||
| 21305 | # If the automapper is running, it must be informed when the Locator task shuts down | ||
| 21306 | if ($self->session->mapWin) { | ||
| 21307 | |||
| 21308 | $self->session->mapWin->setMode('wait'); | ||
| 21309 | $self->session->mapObj->setCurrentRoom(); | ||
| 21310 | } | ||
| 21311 | |||
| 21312 | return 1; | ||
| 21313 | } | ||
| 21314 | |||
| 21315 | sub doReset { | ||
| 21316 | |||
| 21317 | # Called just before the task completes a reset | ||
| 21318 | # For process tasks, called by $self->main. For activity tasks, called by $self->reset | ||
| 21319 | # | ||
| 21320 | # Resets the automapper's current room, so the user see a 'Lost after a move in an unknown | ||
| 21321 | # direction' message after typing ';resettask locator' | ||
| 21322 | # | ||
| 21323 | # Expected arguments | ||
| 21324 | # $newTaskObj - The replacement task object | ||
| 21325 | # | ||
| 21326 | # Return values | ||
| 21327 | # 'undef' on improper arguments | ||
| 21328 | # 1 otherwise | ||
| 21329 | |||
| 21330 | my ($self, $newTaskObj, $check) = @_; | ||
| 21331 | |||
| 21332 | # Check for improper arguments | ||
| 21333 | if (! defined $newTaskObj || defined $check) { | ||
| 21334 | |||
| 21335 | return $axmud::CLIENT->writeImproper($self->_objClass . '->doReset', @_); | ||
| 21336 | } | ||
| 21337 | |||
| 21338 | # Update the automapper | ||
| 21339 | if ($self->session->mapObj->currentRoom) { | ||
| 21340 | |||
| 21341 | $self->session->mapObj->setCurrentRoom(); | ||
| 21342 | } | ||
| 21343 | |||
| 21344 | return 1; | ||
| 21345 | } | ||
| 21346 | |||
| 21347 | sub doFirstStage { | ||
| 21348 | |||
| 21349 | # Called by $self->main, just before the task completes the first stage ($self->stage) | ||
| 21350 | # | ||
| 21351 | # Expected arguments | ||
| 21352 | # (none besides $self) | ||
| 21353 | # | ||
| 21354 | # Return values | ||
| 21355 | # 'undef' on improper arguments | ||
| 21356 | # 1 otherwise | ||
| 21357 | |||
| 21358 | my ($self, $check) = @_; | ||
| 21359 | |||
| 21360 | # Check for improper arguments | ||
| 21361 | if (defined $check) { | ||
| 21362 | |||
| 21363 | return $axmud::CLIENT->writeImproper($self->_objClass . '->doFirstStage', @_); | ||
| 21364 | } | ||
| 21365 | |||
| 21366 | # Display a holding message in the task window, if necessary | ||
| 21367 | $self->insertText('<waiting for first room statement>', 'empty'); | ||
| 21368 | |||
| 21369 | return 1; | ||
| 21370 | } | ||
| 21371 | |||
| 21372 | sub doStage { | ||
| 21373 | |||
| 21374 | # Called by $self->main to process all stages (except stage 1) | ||
| 21375 | # | ||
| 21376 | # Expected arguments | ||
| 21377 | # (none besides $self) | ||
| 21378 | # | ||
| 21379 | # Return values | ||
| 21380 | # 'undef' on improper arguments or if this function sets that task's ->status IV to | ||
| 21381 | # 'finished' or sets its ->shutdownFlag to TRUE | ||
| 21382 | # Otherwise, we normally return the new value of $self->stage | ||
| 21383 | |||
| 21384 | my ($self, $check) = @_; | ||
| 21385 | |||
| 21386 | # Check for improper arguments | ||
| 21387 | if (defined $check) { | ||
| 21388 | |||
| 21389 | return $axmud::CLIENT->writeImproper($self->_objClass . '->doStage', @_); | ||
| 21390 | } | ||
| 21391 | |||
| 21392 | if ($self->stage == 2) { | ||
| 21393 | |||
| 21394 | # When the task is reset because a current profile has changed (or because of the | ||
| 21395 | # ';resettask' command), the task searches backwards, from the most recent line | ||
| 21396 | # received, looking for a room statement. | ||
| 21397 | # However, if the task is reset using the ';resetlocator' command, the behaviour | ||
| 21398 | # depends on the setting of $self->autoLookMode | ||
| 21399 | # 'do_nothing' - do nothing after a manual reset; user must type 'look', 'north' etc | ||
| 21400 | # to get a room statement, then the automapper's current room can be set (the task | ||
| 21401 | # only checks lines received after this moment) | ||
| 21402 | # 'search_back' - (behaviour before v1.0.568) - search backwards, from the most recent | ||
| 21403 | # line received, looking for a room statement - as if the task had just started | ||
| 21404 | # 'send_look' - send a standard 'look' command to the world, which the task can | ||
| 21405 | # interpret (the task only checks lines received after this moment) | ||
| 21406 | if ($self->manualResetFlag && $self->autoLookMode ne 'search_back') { | ||
| 21407 | |||
| 21408 | # Only search text in the display buffer, which appears after this task is started | ||
| 21409 | # (deduct one, because the Locator task starts searching AFTER the line | ||
| 21410 | # described by $self->lastBufferLine) | ||
| 21411 | $self->ivPoke('lastBufferLine', $self->session->displayBufferLast - 1); | ||
| 21412 | $self->ivPoke('manualResetFlag', FALSE); | ||
| 21413 | |||
| 21414 | if ($self->autoLookMode eq 'send_look') { | ||
| 21415 | |||
| 21416 | $self->session->sendModCmd('look'); | ||
| 21417 | } | ||
| 21418 | |||
| 21419 | if ($axmud::CLIENT->debugLocatorFlag) { | ||
| 21420 | |||
| 21421 | $self->writeDebug( | ||
| 21422 | 'LOCATOR 101: Manual reset, will start searching at line ' | ||
| 21423 | . $self->lastBufferLine, | ||
| 21424 | ); | ||
| 21425 | } | ||
| 21426 | |||
| 21427 | } else { | ||
| 21428 | |||
| 21429 | # Search the whole display buffer | ||
| 21430 | $self->ivPoke('lastBufferLine', 0); | ||
| 21431 | |||
| 21432 | # (Don't show debug message if no text has been received from the world yet) | ||
| 21433 | if ($axmud::CLIENT->debugLocatorFlag && $self->session->displayBufferCount) { | ||
| 21434 | |||
| 21435 | $self->writeDebug( | ||
| 21436 | 'LOCATOR 102: Auto reset, will start searching at line ' | ||
| 21437 | . $self->lastBufferLine, | ||
| 21438 | ); | ||
| 21439 | } | ||
| 21440 | } | ||
| 21441 | |||
| 21442 | return $self->ivPoke('stage', 3); | ||
| 21443 | |||
| 21444 | } elsif ($self->stage == 3) { | ||
| 21445 | |||
| 21446 | my ( | ||
| 21447 | $worldObj, $modelObj, $bufferLast, $bufferObj, $restartLine, $startLineNum, | ||
| 21448 | $stopLineNum, $step, $lastRoomObj, $lastDestRoomObj, | ||
| 21449 | @sortedList, | ||
| 21450 | ); | ||
| 21451 | |||
| 21452 | # Stage 3 of the task analyses each line of text received from the world, looking for | ||
| 21453 | # anchor lines and lines which match the patterns for failed exits, involuntary exits, | ||
| 21454 | # dark rooms and unspecified rooms. These patterns are defined by the current world | ||
| 21455 | # profile | ||
| 21456 | # | ||
| 21457 | # A room 'statement' is all the lines of text that comprise a description of a room, | ||
| 21458 | # including the list of exits and the lists of things currently in the room, including | ||
| 21459 | # portables, decorations, others characters and minions | ||
| 21460 | # An 'anchor line' is one that marks the surrounding lines as being part of a room | ||
| 21461 | # statement. It's usually the room's list of exits, but almost any kind of line can be | ||
| 21462 | # set as the anchor line | ||
| 21463 | # The world profile normally defines two kinds of anchor lines - one for verbose (long) | ||
| 21464 | # room statements, another for brief room statements (which might be only one or two | ||
| 21465 | # lines long) | ||
| 21466 | # | ||
| 21467 | # Failed exit patterns are seen when a movement is attempted, but fails for some reason | ||
| 21468 | # (often because a door is locked or closed) | ||
| 21469 | # Involuntary exit patterns are seen when the character is moved from one room to | ||
| 21470 | # another involuntarily | ||
| 21471 | # Dark room patterns are a special kind of anchor line that tell us we're in a dark | ||
| 21472 | # room; they usually contain no information about the room itself - but at least we | ||
| 21473 | # know that a movement command was successful | ||
| 21474 | # Unspecified room patterns are another special kind of anchor line, used in the same | ||
| 21475 | # circumstances (but when the room is not dark) | ||
| 21476 | # | ||
| 21477 | # MXP offers custom elements which can define standard tag properties, among them | ||
| 21478 | # 'RoomName', 'RoomDesc', 'RoomExit', 'RoomNum'. As soon as one of these tag | ||
| 21479 | # properties is found, the task stops looking for anchor lines, and uses these tag | ||
| 21480 | # properties instead. (It still checks for failed exit patterns, etc) | ||
| 21481 | # When any of the four tag properties is found, the task keeps searching for more tag | ||
| 21482 | # properties until (1) an identical tag property is found (which means the start of | ||
| 21483 | # another room statement), or (2) all four tag properties are found (which means the | ||
| 21484 | # end of the current room statement) or (3) the task runs out of lines (which means | ||
| 21485 | # the end of the current room statement) | ||
| 21486 | # | ||
| 21487 | # The GA::Session's display buffer is analysed in these situations: | ||
| 21488 | # (1) This task has just started (or has just been reset), and needs to find its first | ||
| 21489 | # room statement | ||
| 21490 | # (2) The display buffer has been updated with at least one new line since the last | ||
| 21491 | # anchor line was found, and that line ends with a newline character | ||
| 21492 | |||
| 21493 | # Import IVs | ||
| 21494 | $worldObj = $self->session->currentWorld; | ||
| 21495 | $modelObj = $self->session->worldModelObj; | ||
| 21496 | $bufferLast = $self->session->displayBufferLast; | ||
| 21497 | |||
| 21498 | # Check the last display buffer line. If it's not marked as ending with a newline | ||
| 21499 | # character, this task should not process it (yet) | ||
| 21500 | if (defined $bufferLast) { | ||
| 21501 | |||
| 21502 | $bufferObj = $self->session->ivShow('displayBufferHash', $bufferLast); | ||
| 21503 | if ($bufferObj && ! $bufferObj->newLineFlag) { | ||
| 21504 | |||
| 21505 | $bufferLast--; | ||
| 21506 | } | ||
| 21507 | } | ||
| 21508 | |||
| 21509 | if ($bufferLast && $self->lastBufferLine < $bufferLast) { | ||
| 21510 | |||
| 21511 | # Decide which portion of display buffer to analayse | ||
| 21512 | # Situation 1 - move backwards, from the end of the display buffer (we only | ||
| 21513 | # care about the most recent anchor line) | ||
| 21514 | # Situation 2 - move forwards, starting with the line immediately after the | ||
| 21515 | # last line analysed, the previous time the display buffer was | ||
| 21516 | # checked (recorded in $self->lastBufferLine) | ||
| 21517 | $restartLine = $startLineNum = $self->lastBufferLine + 1; | ||
| 21518 | $stopLineNum = $bufferLast; | ||
| 21519 | # If the display buffer has just been reduced in size by the user, $startLineNum may | ||
| 21520 | # be outside the buffer | ||
| 21521 | if ($startLineNum < $self->session->displayBufferFirst) { | ||
| 21522 | |||
| 21523 | $startLineNum = $self->session->displayBufferFirst; | ||
| 21524 | } | ||
| 21525 | |||
| 21526 | if ($axmud::CLIENT->debugLocatorFlag) { | ||
| 21527 | |||
| 21528 | $self->writeDebug( | ||
| 21529 | 'LOCATOR 111: Start #' . $startLineNum . ', stop #' . $stopLineNum, | ||
| 21530 | ); | ||
| 21531 | } | ||
| 21532 | |||
| 21533 | if ( | ||
| 21534 | ! $self->roomCount | ||
| 21535 | # (In basic mapping mode, always move forwards) | ||
| 21536 | && ! $worldObj->basicMappingFlag | ||
| 21537 | ) { | ||
| 21538 | # Situation 1 - move backwards from the end of the display buffer | ||
| 21539 | ($stopLineNum, $startLineNum) = ($startLineNum, $stopLineNum); | ||
| 21540 | $step = -1; | ||
| 21541 | |||
| 21542 | if ($axmud::CLIENT->debugLocatorFlag) { | ||
| 21543 | |||
| 21544 | $self->writeDebug('LOCATOR 112: Reversing search'); | ||
| 21545 | } | ||
| 21546 | |||
| 21547 | } else { | ||
| 21548 | |||
| 21549 | # Situation 2 - move forwards from after the most recently analysed line | ||
| 21550 | $step = 1; | ||
| 21551 | } | ||
| 21552 | |||
| 21553 | # Compose a list of buffer line numbers which we have to process | ||
| 21554 | OUTER: for ( | ||
| 21555 | my $lineNum = $startLineNum; | ||
| 21556 | $lineNum != ($stopLineNum + $step); | ||
| 21557 | $lineNum+= $step | ||
| 21558 | ) { | ||
| 21559 | push (@sortedList, $lineNum); | ||
| 21560 | } | ||
| 21561 | |||
| 21562 | # Now analyse each line in the display buffer between $startLineNum and | ||
| 21563 | # $stopLineNum, looking for anchor lines and failed exit, involuntary exit, dark | ||
| 21564 | # room and unspecified room patterns | ||
| 21565 | do { | ||
| 21566 | |||
| 21567 | my ($lineNum, $bufferObj, $cmdObj, $roomObj, $destRoomObj, $result); | ||
| 21568 | |||
| 21569 | $lineNum = shift @sortedList; | ||
| 21570 | $bufferObj = $self->session->ivShow('displayBufferHash', $lineNum); | ||
| 21571 | |||
| 21572 | # Get the first command GA::Buffer::Cmd in $self->moveList, if any ($cmdObj | ||
| 21573 | # remains set to 'undef', if there are none) | ||
| 21574 | $cmdObj = $self->ivIndex('moveList', 0); | ||
| 21575 | |||
| 21576 | # Get the automapper's current room again (in case it has changed since the | ||
| 21577 | # last call to ->processLine | ||
| 21578 | if (! $self->modelNumber) { | ||
| 21579 | |||
| 21580 | # Automapper object doesn't have a current room set | ||
| 21581 | $lastRoomObj = undef; | ||
| 21582 | $lastDestRoomObj = undef; | ||
| 21583 | |||
| 21584 | } elsif (! $lastRoomObj || $self->modelNumber != $lastRoomObj->number) { | ||
| 21585 | |||
| 21586 | # This is the first iteration of the loop, or the current room has changed | ||
| 21587 | # since the previous iteration of this loop | ||
| 21588 | $roomObj = $modelObj->ivShow('modelHash', $self->modelNumber); | ||
| 21589 | |||
| 21590 | # If $cmdObj is set, work out the likely destination room for a move in that | ||
| 21591 | # direction | ||
| 21592 | if ($cmdObj && $cmdObj->moveFlag) { | ||
| 21593 | |||
| 21594 | $destRoomObj = $self->session->mapObj->identifyDestination($cmdObj); | ||
| 21595 | } | ||
| 21596 | |||
| 21597 | # ($destRoomObj may be 'undef') | ||
| 21598 | $lastDestRoomObj = $destRoomObj; | ||
| 21599 | |||
| 21600 | } else { | ||
| 21601 | |||
| 21602 | # The current room hasn't changed since the previous iteration of this loop | ||
| 21603 | $roomObj = $lastRoomObj; | ||
| 21604 | $destRoomObj = $lastDestRoomObj; | ||
| 21605 | } | ||
| 21606 | |||
| 21607 | if ($axmud::CLIENT->debugLocatorFlag) { | ||
| 21608 | |||
| 21609 | $self->writeDebug('LOCATOR 121: Processing line ' . $lineNum); | ||
| 21610 | } | ||
| 21611 | |||
| 21612 | $result = $self->processLine( | ||
| 21613 | $worldObj, | ||
| 21614 | $modelObj, | ||
| 21615 | $lineNum, | ||
| 21616 | $bufferObj, | ||
| 21617 | $stopLineNum, | ||
| 21618 | $restartLine, | ||
| 21619 | $roomObj, # May be 'undef' | ||
| 21620 | $cmdObj, # May be 'undef' | ||
| 21621 | $destRoomObj, # May be 'undef' | ||
| 21622 | ); | ||
| 21623 | |||
| 21624 | if (! defined $result) { | ||
| 21625 | |||
| 21626 | # No more lines should be analysed until some more text is received from | ||
| 21627 | # the world (could also be an error) | ||
| 21628 | @sortedList = (); | ||
| 21629 | |||
| 21630 | } elsif ($result == -1) { | ||
| 21631 | |||
| 21632 | # Repeat this line ($self->processLine can only process one room statement | ||
| 21633 | # at once, and two have been detected) | ||
| 21634 | unshift(@sortedList, $lineNum); | ||
| 21635 | |||
| 21636 | } else { | ||
| 21637 | |||
| 21638 | # After extracting a room statement, start analysing lines after the end | ||
| 21639 | # (but, in situation 1, stop analysing after the first statement found) | ||
| 21640 | if ($step == -1 && $self->roomCount) { | ||
| 21641 | |||
| 21642 | # Situation 1 | ||
| 21643 | @sortedList = (); | ||
| 21644 | |||
| 21645 | } elsif ($step == 1 && @sortedList && defined $self->lastStatementEndLine) { | ||
| 21646 | |||
| 21647 | # Situation 2. The next line to be analysed is the first line after the | ||
| 21648 | # room statement we've just analysed | ||
| 21649 | # Walk the list, eliminating any lines up to and including the end of | ||
| 21650 | # the statement | ||
| 21651 | # NB If the world profile's ->basicMappingFlag is TRUE, $step will be 1 | ||
| 21652 | # but $self->lastStatementEndLine will be 'undef', so we had to check | ||
| 21653 | # for that | ||
| 21654 | do { | ||
| 21655 | |||
| 21656 | my $item = $sortedList[0]; | ||
| 21657 | |||
| 21658 | if ($item <= $self->lastStatementEndLine) { | ||
| 21659 | |||
| 21660 | shift @sortedList; | ||
| 21661 | } | ||
| 21662 | |||
| 21663 | } until (! @sortedList || $sortedList[0] > $self->lastStatementEndLine); | ||
| 21664 | } | ||
| 21665 | } | ||
| 21666 | |||
| 21667 | } until (! @sortedList); | ||
| 21668 | |||
| 21669 | # Analysis complete. Remember the last line that was due to be searched; the next | ||
| 21670 | # time $self->main is called, the analysis will begin on the following line | ||
| 21671 | # Exception: if $self->restartBufferLine is set, we're still waiting for the second | ||
| 21672 | # part of a room statement, in which case, the next analysis will begin on the | ||
| 21673 | # same line as before | ||
| 21674 | if ($self->restartBufferLine) { | ||
| 21675 | |||
| 21676 | $self->ivPoke('lastBufferLine', $self->restartBufferLine - 1); | ||
| 21677 | $self->ivUndef('restartBufferLine'); | ||
| 21678 | |||
| 21679 | } elsif ($step == -1) { | ||
| 21680 | |||
| 21681 | $self->ivPoke('lastBufferLine', $startLineNum); | ||
| 21682 | |||
| 21683 | } else { | ||
| 21684 | |||
| 21685 | $self->ivPoke('lastBufferLine', $stopLineNum); | ||
| 21686 | } | ||
| 21687 | |||
| 21688 | if ($axmud::CLIENT->debugLocatorFlag) { | ||
| 21689 | |||
| 21690 | $self->writeDebug( | ||
| 21691 | 'LOCATOR 131: On next task loop, will examine line ' | ||
| 21692 | . ($self->lastBufferLine + 1), | ||
| 21693 | ); | ||
| 21694 | } | ||
| 21695 | } | ||
| 21696 | |||
| 21697 | # Repeat this stage indefinitely | ||
| 21698 | return $self->ivPoke('stage', 3); | ||
| 21699 | |||
| 21700 | } else { | ||
| 21701 | |||
| 21702 | # The task stage has somehow been set to an invalid value | ||
| 21703 | return $self->invalidStage(); | ||
| 21704 | } | ||
| 21705 | } | ||
| 21706 | |||
| 21707 | # Component methods | ||
| 21708 | |||
| 21709 | sub convertLines { | ||
| 21710 | |||
| 21711 | # Called by $self->doStage (at stage 3) to convert a list of display buffer line numbers, | ||
| 21712 | # e.g. (92, 93, 94, 95) or (5, 4, 3, 2, 1) into a list of strings, each one containing | ||
| 21713 | # a line of text for $self->processLine to analyse | ||
| 21714 | # | ||
| 21715 | # Expected arguments | ||
| 21716 | # @lineList - A list of numbers of display buffer lines | ||
| 21717 | # | ||
| 21718 | # Return values | ||
| 21719 | # An empty list on improper arguments | ||
| 21720 | # Otherwise, returns a list in the form | ||
| 21721 | # (line_number, line_text, line_number, line_text) | ||
| 21722 | # For combined lines, the line number of the first line is used | ||
| 21723 | |||
| 21724 | my ($self, @lineList) = @_; | ||
| 21725 | |||
| 21726 | # Local variables | ||
| 21727 | my (@emptyList, @returnArray); | ||
| 21728 | |||
| 21729 | # Check for improper arguments | ||
| 21730 | if (! @lineList) { | ||
| 21731 | |||
| 21732 | return $axmud::CLIENT->writeImproper($self->_objClass . '->convertLines', @_); | ||
| 21733 | } | ||
| 21734 | |||
| 21735 | do { | ||
| 21736 | |||
| 21737 | my ($lineNum, $bufferObj, $lineText, $exitFlag); | ||
| 21738 | |||
| 21739 | $lineNum = shift @lineList; | ||
| 21740 | # Get the corresponding line object and the line of text that it displayed in | ||
| 21741 | # the 'main' window (after being modified by any triggers) | ||
| 21742 | $bufferObj = $self->session->ivShow('displayBufferHash', $lineNum); | ||
| 21743 | if ($bufferObj) { | ||
| 21744 | |||
| 21745 | $lineText = $bufferObj->modLine; | ||
| 21746 | if ($lineText && $lineText =~ m/\w/ && @lineList) { | ||
| 21747 | |||
| 21748 | do { | ||
| 21749 | |||
| 21750 | my ($nextLine, $nextLineObj); | ||
| 21751 | |||
| 21752 | # Check any following lines of text | ||
| 21753 | $nextLine = $lineList[0]; | ||
| 21754 | if ($nextLine =~ m/^\s*[[:lower:]]/) { | ||
| 21755 | |||
| 21756 | $nextLine = shift @lineList; | ||
| 21757 | $nextLineObj = $self->session->ivShow('displayBufferHash', $nextLine); | ||
| 21758 | |||
| 21759 | } else { | ||
| 21760 | |||
| 21761 | # Don't check any more following lines for lines that begin a-z | ||
| 21762 | $exitFlag = TRUE; | ||
| 21763 | } | ||
| 21764 | |||
| 21765 | } until ($exitFlag || ! @lineList); | ||
| 21766 | } | ||
| 21767 | |||
| 21768 | push (@returnArray, $lineNum, $lineText); | ||
| 21769 | } | ||
| 21770 | |||
| 21771 | } until (! @lineList); | ||
| 21772 | |||
| 21773 | return @returnArray; | ||
| 21774 | } | ||
| 21775 | |||
| 21776 | sub processLine { | ||
| 21777 | |||
| 21778 | # Called by $self->doStage (at stage 3) to analyse a single line from the display buffer | ||
| 21779 | # | ||
| 21780 | # Expected arguments | ||
| 21781 | # $worldObj - Shortcut to $self->session->currentWorld | ||
| 21782 | # $modelObj - Shortcut to $self->session->worldModelObj | ||
| 21783 | # $lineNum - The display buffer number of the line being analysed | ||
| 21784 | # $bufferObj - $lineNum's corresponding display buffer object | ||
| 21785 | # $stopLineNum - The display buffer number of last line that can be analysed during | ||
| 21786 | # this task loop (might be the same as $lineNum. If we're checking | ||
| 21787 | # lines from beginning to end, it might be higher than $lineNum; if | ||
| 21788 | # we're checking lines from end to beginning, it might be lower than | ||
| 21789 | # $lineNum) | ||
| 21790 | # $restartLineNum - The display buffer number of the first line being analysed during this | ||
| 21791 | # task loop (might be the same as $lineNum) | ||
| 21792 | # | ||
| 21793 | # Optional arguments | ||
| 21794 | # $mapRoomObj - The automapper's current room object, if known (otherwise 'undef') | ||
| 21795 | # $cmdObj - The first GA::Buffer::Cmd object in $self->moveList that stores a | ||
| 21796 | # movement command ('undef' if there are none, or if $mapRoomObj is | ||
| 21797 | # not defined) | ||
| 21798 | # $destRoomObj - If $cmdObj is set, the likely destination room for that movement, if | ||
| 21799 | # known ('undef' otherwise) | ||
| 21800 | # | ||
| 21801 | # Return values | ||
| 21802 | # 'undef' on improper arguments, if there's an error or if no more lines should be | ||
| 21803 | # analysed until some more text is received from the world | ||
| 21804 | # -1 if the current line should be processed again, in a new call to this function (see | ||
| 21805 | # PART 12 code for the reasons why) | ||
| 21806 | # 1 otherwise | ||
| 21807 | |||
| 21808 | my ( | ||
| 21809 | $self, $worldObj, $modelObj, $lineNum, $bufferObj, $stopLineNum, $restartLineNum, | ||
| 21810 | $mapRoomObj, $cmdObj, $destRoomObj, $check, | ||
| 21811 | ) = @_; | ||
| 21812 | |||
| 21813 | # Local variables | ||
| 21814 | my ( | ||
| 21815 | $lineText, $existsFlag, $failExitFlag, $foundFailPattern, $moveDir, | ||
| 21816 | $involuntaryExitFlag, $involuntaryValue, $specialFlag, $followCmd, $followFlag, | ||
| 21817 | $followAnchorFlag, $newCmdObj, $ghostRoomObj, $exitNum, $exitObj, $updateFlag, | ||
| 21818 | $tempRoomObj, $anchorFlag, $promptFlag, $missionObj, | ||
| 21819 | @followPatternList, @followAnchorPatternList, @unspecifiedList, @promptList, | ||
| 21820 | %tempMxpPropHash, | ||
| 21821 | ); | ||
| 21822 | |||
| 21823 | # Check for improper arguments | ||
| 21824 | if ( | ||
| 21825 | ! defined $worldObj || ! defined $modelObj || ! defined $lineNum || ! defined $bufferObj | ||
| 21826 | || ! defined $stopLineNum || ! defined $restartLineNum || defined $check | ||
| 21827 | ) { | ||
| 21828 | return $axmud::CLIENT->writeImproper($self->_objClass . '->processLine', @_); | ||
| 21829 | } | ||
| 21830 | |||
| 21831 | # We check the received line, after it has been modified by triggers, etc | ||
| 21832 | $lineText = $bufferObj->modLine; | ||
| 21833 | # Check the current world's override hash once per call | ||
| 21834 | $existsFlag = $worldObj->ivExists('mxpOverrideHash', 'room'); | ||
| 21835 | |||
| 21836 | # PART 1 | ||
| 21837 | # Check this line against those which are definitely not anchor lines (these patterns mostly | ||
| 21838 | # used in basic mapping mode, when worlds echo back the movement command, as in MUD1 / | ||
| 21839 | # British Legends) | ||
| 21840 | OUTER: foreach my $pattern ($worldObj->notAnchorPatternList) { | ||
| 21841 | |||
| 21842 | if ($lineText =~ m/$pattern/) { | ||
| 21843 | |||
| 21844 | if ($axmud::CLIENT->debugLocatorFlag) { | ||
| 21845 | |||
| 21846 | $self->writeDebug( | ||
| 21847 | 'LOCATOR 201: Found a no-anchor line matching: ' . $pattern, | ||
| 21848 | ); | ||
| 21849 | } | ||
| 21850 | |||
| 21851 | # Ask ->doStage the continue analysis with the following line | ||
| 21852 | return 1; | ||
| 21853 | } | ||
| 21854 | } | ||
| 21855 | |||
| 21856 | # PART 2 | ||
| 21857 | # If the current location is known, look for that room's own failed exit pattern list | ||
| 21858 | # (assuming that we've already found the first room statement) | ||
| 21859 | if ($mapRoomObj && $self->roomCount) { | ||
| 21860 | |||
| 21861 | OUTER: foreach my $pattern ($mapRoomObj->failExitPatternList) { | ||
| 21862 | |||
| 21863 | if ($lineText =~ m/$pattern/) { | ||
| 21864 | |||
| 21865 | if ($axmud::CLIENT->debugLocatorFlag) { | ||
| 21866 | |||
| 21867 | $self->writeDebug( | ||
| 21868 | 'LOCATOR 211: Found room\'s own failed exit pattern: ' . $pattern, | ||
| 21869 | ); | ||
| 21870 | } | ||
| 21871 | |||
| 21872 | # $lineText contains one of the room's own failed exit patterns | ||
| 21873 | $failExitFlag = TRUE; | ||
| 21874 | # If one failed exit found on a line, don't need to check for others | ||
| 21875 | $foundFailPattern = $pattern; | ||
| 21876 | |||
| 21877 | last OUTER; | ||
| 21878 | } | ||
| 21879 | } | ||
| 21880 | } | ||
| 21881 | |||
| 21882 | # PART 3 | ||
| 21883 | # If none of the current room's own failed exit patterns are found, look for failed exit | ||
| 21884 | # patterns defined by the current world profile | ||
| 21885 | if (! $failExitFlag) { | ||
| 21886 | |||
| 21887 | OUTER: foreach my $pattern ( | ||
| 21888 | $worldObj->doorPatternList, | ||
| 21889 | $worldObj->lockedPatternList, | ||
| 21890 | $worldObj->failExitPatternList, | ||
| 21891 | ) { | ||
| 21892 | if ($lineText =~ m/$pattern/) { | ||
| 21893 | |||
| 21894 | if ($axmud::CLIENT->debugLocatorFlag) { | ||
| 21895 | |||
| 21896 | $self->writeDebug( | ||
| 21897 | 'LOCATOR 221: Found failed exit pattern: ' . $pattern, | ||
| 21898 | ); | ||
| 21899 | } | ||
| 21900 | |||
| 21901 | # $lineText contains one of the failed exit patterns | ||
| 21902 | $failExitFlag = TRUE; | ||
| 21903 | |||
| 21904 | # If we're still looking for the first room statement, we have to give up now | ||
| 21905 | if (! $self->roomCount) { | ||
| 21906 | |||
| 21907 | return $self->haltAnalysis('fail_exit'); # Returns 'undef' | ||
| 21908 | |||
| 21909 | } else { | ||
| 21910 | |||
| 21911 | # If one failed exit found on a line, don't need to check for | ||
| 21912 | # others | ||
| 21913 | $foundFailPattern = $pattern; | ||
| 21914 | |||
| 21915 | last OUTER; | ||
| 21916 | } | ||
| 21917 | } | ||
| 21918 | } | ||
| 21919 | } | ||
| 21920 | |||
| 21921 | # PART 4 | ||
| 21922 | # React to a failed exit pattern from parts 2-3 | ||
| 21923 | if ($failExitFlag) { | ||
| 21924 | |||
| 21925 | if ($cmdObj) { | ||
| 21926 | |||
| 21927 | # Remove the command object that represents the first movement command in | ||
| 21928 | # $self->moveList | ||
| 21929 | $self->removeFirstMove($cmdObj); | ||
| 21930 | |||
| 21931 | # Find the direction of the failed move, if known (otherwise, $moveDir remains set | ||
| 21932 | # to 'undef') | ||
| 21933 | if ($cmdObj->moveDir) { | ||
| 21934 | $moveDir = $cmdObj->moveDir; | ||
| 21935 | } elsif ($cmdObj->assistedFlag && $cmdObj->assistedExitObj) { | ||
| 21936 | $moveDir = $cmdObj->assistedExitObj->dir; | ||
| 21937 | } | ||
| 21938 | } | ||
| 21939 | |||
| 21940 | # Set flag that other parts of the Axmud code can consult frequently, to see if there's | ||
| 21941 | # been a failed exit or not | ||
| 21942 | $self->ivPoke('failExitFlag', TRUE); | ||
| 21943 | |||
| 21944 | # Refresh the task window (if it's open and enabled) - if the direction of the failed | ||
| 21945 | # exit is one of the current room's known exits, the exit is marked with an asterisk | ||
| 21946 | if ($self->taskWinFlag) { | ||
| 21947 | |||
| 21948 | $self->refreshWin($moveDir); | ||
| 21949 | } | ||
| 21950 | |||
| 21951 | # Inform the automapper of the failed exit so it can decide what to do | ||
| 21952 | $self->session->mapObj->failedExitSeen($foundFailPattern, $moveDir); | ||
| 21953 | } | ||
| 21954 | |||
| 21955 | # PART 5 | ||
| 21956 | # If the current location is known, look for that room's own involuntary / repulse exit | ||
| 21957 | # patterns (assuming that we've already found the first room statement, but don't look if | ||
| 21958 | # a failed exit pattern already found) | ||
| 21959 | # NB Although room model objects have separate involuntary / repulse pattern lists, | ||
| 21960 | # the Locator task treats them in the same way | ||
| 21961 | if (! $failExitFlag && $mapRoomObj && $self->roomCount) { | ||
| 21962 | |||
| 21963 | OUTER: foreach my $pattern ($mapRoomObj->ivKeys('involuntaryExitPatternHash')) { | ||
| 21964 | |||
| 21965 | if ($lineText =~ m/$pattern/) { | ||
| 21966 | |||
| 21967 | if ($axmud::CLIENT->debugLocatorFlag) { | ||
| 21968 | |||
| 21969 | $self->writeDebug( | ||
| 21970 | 'LOCATOR 231: Found room\'s own involuntary exit pattern: ' . $pattern, | ||
| 21971 | ); | ||
| 21972 | } | ||
| 21973 | |||
| 21974 | # $lineText contains one of the room's own involuntary exit patterns | ||
| 21975 | $involuntaryExitFlag = TRUE; | ||
| 21976 | $involuntaryValue = $mapRoomObj->ivShow('involuntaryExitPatternHash', $pattern); | ||
| 21977 | # If one involuntary exit found on a line, don't need to check for others | ||
| 21978 | last OUTER; | ||
| 21979 | } | ||
| 21980 | } | ||
| 21981 | |||
| 21982 | if (! $involuntaryExitFlag) { | ||
| 21983 | |||
| 21984 | OUTER: foreach my $pattern ($mapRoomObj->ivKeys('repulseExitPatternHash')) { | ||
| 21985 | |||
| 21986 | if ($lineText =~ m/$pattern/) { | ||
| 21987 | |||
| 21988 | if ($axmud::CLIENT->debugLocatorFlag) { | ||
| 21989 | |||
| 21990 | $self->writeDebug( | ||
| 21991 | 'LOCATOR 232: Found room\'s own repulse exit pattern: ' . $pattern, | ||
| 21992 | ); | ||
| 21993 | } | ||
| 21994 | |||
| 21995 | # $lineText contains one of the room's own repulse exit patterns, which the | ||
| 21996 | # task treats as just another involuntary exit | ||
| 21997 | $involuntaryExitFlag = TRUE; | ||
| 21998 | $involuntaryValue | ||
| 21999 | = $mapRoomObj->ivShow('repulseExitPatternHash', $pattern); | ||
| 22000 | |||
| 22001 | # The movement command described by $cmdObj was rejected by the world, so | ||
| 22002 | # we need to discard it | ||
| 22003 | if ($cmdObj) { | ||
| 22004 | |||
| 22005 | $self->removeFirstMove($cmdObj); | ||
| 22006 | $cmdObj = undef; | ||
| 22007 | } | ||
| 22008 | |||
| 22009 | # If one involuntary exit found on a line, don't need to check for others | ||
| 22010 | last OUTER; | ||
| 22011 | } | ||
| 22012 | } | ||
| 22013 | } | ||
| 22014 | } | ||
| 22015 | |||
| 22016 | # PART 6 | ||
| 22017 | # Look out for the world profile's involuntary exit patterns (but don't look if a failed or | ||
| 22018 | # involuntary exit pattern already found) | ||
| 22019 | if (! $failExitFlag && ! $involuntaryExitFlag) { | ||
| 22020 | |||
| 22021 | OUTER: foreach my $pattern ($worldObj->involuntaryExitPatternList) { | ||
| 22022 | |||
| 22023 | if ($lineText =~ m/$pattern/) { | ||
| 22024 | |||
| 22025 | if ($axmud::CLIENT->debugLocatorFlag) { | ||
| 22026 | |||
| 22027 | $self->writeDebug( | ||
| 22028 | 'LOCATOR 241: Found involuntary exit pattern: ' . $pattern, | ||
| 22029 | ); | ||
| 22030 | } | ||
| 22031 | |||
| 22032 | # $lineText contains one of the involuntary exit patterns, meaning the character | ||
| 22033 | # has moved (usually after fleeing a fight at the point of death), and that | ||
| 22034 | # the current location is now unknown | ||
| 22035 | $involuntaryExitFlag = TRUE; | ||
| 22036 | |||
| 22037 | # If we're still looking for the first room statement, we have to give up now | ||
| 22038 | if (! $self->roomCount) { | ||
| 22039 | |||
| 22040 | return $self->haltAnalysis('involuntary'); # Returns 'undef' | ||
| 22041 | |||
| 22042 | } else { | ||
| 22043 | |||
| 22044 | # If one failed involuntary exit found on a line, don't need to check for | ||
| 22045 | # others | ||
| 22046 | last OUTER; | ||
| 22047 | } | ||
| 22048 | } | ||
| 22049 | } | ||
| 22050 | } | ||
| 22051 | |||
| 22052 | # PART 7 | ||
| 22053 | # React to an involuntary/repulse exit pattern from parts 5-6 | ||
| 22054 | if (defined $involuntaryValue) { | ||
| 22055 | |||
| 22056 | # If defined, $involuntaryValue is the involuntary/repulse exit pattern's corresponding | ||
| 22057 | # direction or destination room | ||
| 22058 | if ($self->session->worldModelObj->ivExists('modelHash', $involuntaryValue)) { | ||
| 22059 | |||
| 22060 | # Create a temporary command buffer object, treating the move as if the user had | ||
| 22061 | # typed a teleport command to the destination room whose model number is | ||
| 22062 | # $involuntaryValue | ||
| 22063 | $cmdObj = Games::Axmud::Buffer::Cmd->new( | ||
| 22064 | $self->session, | ||
| 22065 | 'session', | ||
| 22066 | # Not a real world command, but an involuntary movement | ||
| 22067 | -1, | ||
| 22068 | 'teleport', # A fake world command | ||
| 22069 | $self->session->sessionTime, | ||
| 22070 | ); | ||
| 22071 | |||
| 22072 | $cmdObj->addTeleport($involuntaryValue); | ||
| 22073 | |||
| 22074 | } else { | ||
| 22075 | |||
| 22076 | # $involuntaryValue can be a custom or standard direction. If standard, convert it | ||
| 22077 | # to custom | ||
| 22078 | if ($self->session->currentDict->ivExists('primaryDirHash', $involuntaryValue)) { | ||
| 22079 | |||
| 22080 | $involuntaryValue = $self->session->currentDict->ivShow( | ||
| 22081 | 'primaryDirHash', | ||
| 22082 | $involuntaryValue, | ||
| 22083 | ); | ||
| 22084 | } | ||
| 22085 | |||
| 22086 | # Create a temporary command buffer object, as if the user had a typed a command in | ||
| 22087 | # the direction $involuntaryValue, which is assumed to lead to a destination room | ||
| 22088 | $cmdObj = Games::Axmud::Buffer::Cmd->new( | ||
| 22089 | $self->session, | ||
| 22090 | 'session', | ||
| 22091 | # Not a real world command, but an involuntary move | ||
| 22092 | -1, | ||
| 22093 | $involuntaryValue, | ||
| 22094 | $self->session->sessionTime, | ||
| 22095 | ); | ||
| 22096 | |||
| 22097 | $cmdObj->addMove(); | ||
| 22098 | } | ||
| 22099 | |||
| 22100 | # Update $self->cmdObjList and ->moveList | ||
| 22101 | $self->add_cmdObj($cmdObj); | ||
| 22102 | |||
| 22103 | # Treat this as an anchor line | ||
| 22104 | $updateFlag = TRUE; | ||
| 22105 | |||
| 22106 | # Remember the position in the display buffer of the most recent anchor line found | ||
| 22107 | $self->ivPoke('lastAnchorLine', $lineNum); | ||
| 22108 | $self->ivPoke('lastStatementEndLine', $lineNum); | ||
| 22109 | $self->ivPoke('lastStatementStartLine', $lineNum); | ||
| 22110 | |||
| 22111 | # Archive the previous current room object (if there was one) | ||
| 22112 | if ($self->roomObj) { | ||
| 22113 | |||
| 22114 | $self->ivPoke('prevRoomObj', $self->roomObj); | ||
| 22115 | } | ||
| 22116 | |||
| 22117 | # Create a non-model object for this room | ||
| 22118 | $tempRoomObj = Games::Axmud::ModelObj::Room->new( | ||
| 22119 | $self->session, | ||
| 22120 | 'temporary', | ||
| 22121 | 'non_model', | ||
| 22122 | ); | ||
| 22123 | |||
| 22124 | $self->ivPoke('roomObj', $tempRoomObj); # Even if $tempRoomObj is 'undef' | ||
| 22125 | |||
| 22126 | # Mark this non-model room as (currently) unspecified | ||
| 22127 | $self->roomObj->ivPoke('unspecifiedFlag', TRUE); | ||
| 22128 | |||
| 22129 | } elsif ($involuntaryExitFlag) { | ||
| 22130 | |||
| 22131 | if ($cmdObj) { | ||
| 22132 | |||
| 22133 | # Remove the command object that represents the first movement command in | ||
| 22134 | # $self->moveList | ||
| 22135 | $self->removeFirstMove($cmdObj); | ||
| 22136 | } | ||
| 22137 | |||
| 22138 | # Direction of move is unknown | ||
| 22139 | $self->ivUndef('prevMoveObj'); | ||
| 22140 | $self->ivUndef('prevMove'); | ||
| 22141 | # Current location is unknown | ||
| 22142 | $self->ivUndef('roomObj'); | ||
| 22143 | |||
| 22144 | # Set flag that other parts of the Axmud code can consult frequently, to see if there's | ||
| 22145 | # been an involuntary exit or not | ||
| 22146 | $self->ivPoke('involuntaryExitFlag', TRUE); | ||
| 22147 | |||
| 22148 | # Update the task window (if it's open and enabled) - it displays a 'location unknown' | ||
| 22149 | # message | ||
| 22150 | if ($self->taskWinFlag) { | ||
| 22151 | |||
| 22152 | $self->refreshWin(); | ||
| 22153 | } | ||
| 22154 | |||
| 22155 | # Inform the automapper of the involuntary exit so it can decide what to do | ||
| 22156 | $self->session->mapObj->involuntaryExitSeen(); | ||
| 22157 | } | ||
| 22158 | |||
| 22159 | # PARTS 8-10 | ||
| 22160 | # Look for a special departure/follow/follow anchor pattern | ||
| 22161 | if (! $failExitFlag && ! $involuntaryExitFlag) { | ||
| 22162 | |||
| 22163 | # PART 8 | ||
| 22164 | # Look for special departure patterns | ||
| 22165 | if ($mapRoomObj && $self->roomCount) { | ||
| 22166 | |||
| 22167 | OUTER: foreach my $pattern ($mapRoomObj->specialDepartPatternList) { | ||
| 22168 | |||
| 22169 | if ($lineText =~ m/$pattern/) { | ||
| 22170 | |||
| 22171 | # $line contains one of the current room's special departure patterns, | ||
| 22172 | # meaning the character has moved, but that the world is not going to send | ||
| 22173 | # a room statement for the new room | ||
| 22174 | # Treat it as an unspecified room (and therefore an anchor line) | ||
| 22175 | |||
| 22176 | if ($axmud::CLIENT->debugLocatorFlag) { | ||
| 22177 | |||
| 22178 | $self->session->writeDebug( | ||
| 22179 | 'LOCATOR 251: Found special departure pattern (anchor): ' | ||
| 22180 | . $pattern, | ||
| 22181 | ); | ||
| 22182 | } | ||
| 22183 | |||
| 22184 | $specialFlag = TRUE; | ||
| 22185 | last OUTER; | ||
| 22186 | } | ||
| 22187 | } | ||
| 22188 | } | ||
| 22189 | |||
| 22190 | # PART 9 | ||
| 22191 | # Look for follow patterns | ||
| 22192 | @followPatternList = $worldObj->followPatternList; | ||
| 22193 | if (! $specialFlag && @followPatternList) { | ||
| 22194 | |||
| 22195 | # Check this line against follow patterns, in which a new room statement is | ||
| 22196 | # expected after a line like 'You follow the orc to the north' | ||
| 22197 | do { | ||
| 22198 | |||
| 22199 | my ( | ||
| 22200 | $pattern, $grpNum, $result, | ||
| 22201 | @grpStringList, | ||
| 22202 | ); | ||
| 22203 | |||
| 22204 | $pattern = shift @followPatternList; | ||
| 22205 | $grpNum = shift @followPatternList; | ||
| 22206 | |||
| 22207 | $result = @grpStringList = ($lineText =~ m/$pattern/); | ||
| 22208 | |||
| 22209 | # The direction of travel (e.g. 'north') should be in @grpStringList, at index | ||
| 22210 | # number $grpNum | ||
| 22211 | if ($result && scalar (@grpStringList) >= $grpNum) { | ||
| 22212 | |||
| 22213 | # $line contains one of the current room's follow patterns, meaning | ||
| 22214 | # the character has moved and that the world is going to send a room | ||
| 22215 | # statement for the new room | ||
| 22216 | if ($axmud::CLIENT->debugLocatorFlag) { | ||
| 22217 | |||
| 22218 | $self->session->writeDebug( | ||
| 22219 | 'LOCATOR 252: Found follow pattern: ' . $pattern, | ||
| 22220 | ); | ||
| 22221 | } | ||
| 22222 | |||
| 22223 | # NB The GA::Session converts all world commands to lower case, so we'll do | ||
| 22224 | # the same here | ||
| 22225 | $grpNum--; | ||
| 22226 | $followCmd = lc($grpStringList[$grpNum]); | ||
| 22227 | |||
| 22228 | # Leave the loop early | ||
| 22229 | @followPatternList = (); | ||
| 22230 | $followFlag = TRUE; | ||
| 22231 | } | ||
| 22232 | |||
| 22233 | } until (! @followPatternList); | ||
| 22234 | } | ||
| 22235 | |||
| 22236 | # PART 10 | ||
| 22237 | # Look for follow anchor patterns | ||
| 22238 | @followAnchorPatternList = $worldObj->followAnchorPatternList; | ||
| 22239 | if (! $specialFlag && ! $followFlag && @followAnchorPatternList) { | ||
| 22240 | |||
| 22241 | # Check this line against follow anchor patterns, in which no new room statement is | ||
| 22242 | # expected after a line like 'You follow the orc to the north', so this line must | ||
| 22243 | # be treated as the anchor | ||
| 22244 | do { | ||
| 22245 | |||
| 22246 | my ( | ||
| 22247 | $pattern, $grpNum, $result, | ||
| 22248 | @grpStringList, | ||
| 22249 | ); | ||
| 22250 | |||
| 22251 | $pattern = shift @followAnchorPatternList; | ||
| 22252 | $grpNum = shift @followAnchorPatternList; | ||
| 22253 | |||
| 22254 | $result = @grpStringList = ($lineText =~ m/$pattern/); | ||
| 22255 | |||
| 22256 | # The direction of travel (e.g. 'north') should be in @grpStringList, at index | ||
| 22257 | # number $grpNum | ||
| 22258 | if ($result && scalar (@grpStringList) >= $grpNum) { | ||
| 22259 | |||
| 22260 | # $line contains one of the current room's follow anchor patterns, meaning | ||
| 22261 | # the character has moved, but that the world is not going to send a room | ||
| 22262 | # statement for the new room | ||
| 22263 | # Treat it as an unspecified room (and therefore an anchor line) | ||
| 22264 | |||
| 22265 | if ($axmud::CLIENT->debugLocatorFlag) { | ||
| 22266 | |||
| 22267 | $self->session->writeDebug( | ||
| 22268 | 'LOCATOR 253: Found follow pattern (anchor): ' . $pattern, | ||
| 22269 | ); | ||
| 22270 | } | ||
| 22271 | |||
| 22272 | # NB The GA::Session converts all world commands to lower case, so we'll do | ||
| 22273 | # the same here | ||
| 22274 | $grpNum--; | ||
| 22275 | $followCmd = lc($grpStringList[$grpNum]); | ||
| 22276 | |||
| 22277 | # Leave the loop early | ||
| 22278 | @followPatternList = (); | ||
| 22279 | $followAnchorFlag = TRUE; | ||
| 22280 | } | ||
| 22281 | |||
| 22282 | } until (! @followAnchorPatternList); | ||
| 22283 | } | ||
| 22284 | |||
| 22285 | # PARTS 8-10 | ||
| 22286 | # React to special departure/follow/follow anchor patterns | ||
| 22287 | if ($specialFlag || $followFlag || $followAnchorFlag) { | ||
| 22288 | |||
| 22289 | if ($followCmd) { | ||
| 22290 | |||
| 22291 | # Code borrowed from GA::Session->updateCmdBuffer. The Locator task is rather | ||
| 22292 | # unsophisticated in the way it handles follows; it attempts to use the raw | ||
| 22293 | # direction as a movement command, without checking assisted moves, redirect | ||
| 22294 | # mode commands, or anything like that | ||
| 22295 | |||
| 22296 | # Create a new object for this world command | ||
| 22297 | $newCmdObj = Games::Axmud::Buffer::Cmd->new( | ||
| 22298 | $self->session, | ||
| 22299 | 'session', | ||
| 22300 | # Not a real world command, but an involuntary follow | ||
| 22301 | -1, | ||
| 22302 | $followCmd, | ||
| 22303 | $self->session->sessionTime, | ||
| 22304 | ); | ||
| 22305 | |||
| 22306 | $newCmdObj->addFollow($followAnchorFlag); | ||
| 22307 | |||
| 22308 | # Update the automapper's ghost room, if it is set | ||
| 22309 | $ghostRoomObj = $self->session->mapObj->ghostRoom; | ||
| 22310 | # If there is a ghost room, and it has an exit in this direction... | ||
| 22311 | if ($ghostRoomObj && $ghostRoomObj->ivExists('exitNumHash', $followCmd)) { | ||
| 22312 | |||
| 22313 | $exitNum = $ghostRoomObj->ivShow('exitNumHash', $followCmd); | ||
| 22314 | $exitObj = $modelObj->ivShow('exitModelHash', $exitNum); | ||
| 22315 | # The new ghost room is the exit's destination room (may be set to | ||
| 22316 | # 'undef') | ||
| 22317 | if ($exitObj->destRoom) { | ||
| 22318 | |||
| 22319 | # Set the automapper's ghost room | ||
| 22320 | $self->session->mapObj->setGhostRoom( | ||
| 22321 | $modelObj->ivShow('modelHash', $exitObj->destRoom), | ||
| 22322 | ); | ||
| 22323 | } | ||
| 22324 | } | ||
| 22325 | |||
| 22326 | # Update $self->cmdObjList and ->moveList | ||
| 22327 | $self->add_cmdObj($newCmdObj); | ||
| 22328 | } | ||
| 22329 | |||
| 22330 | if ($specialFlag || $followAnchorFlag) { | ||
| 22331 | |||
| 22332 | # Treat this as an anchor line | ||
| 22333 | $updateFlag = TRUE; | ||
| 22334 | |||
| 22335 | # Remember the position in the display buffer of the most recent anchor line | ||
| 22336 | # found | ||
| 22337 | $self->ivPoke('lastAnchorLine', $lineNum); | ||
| 22338 | $self->ivPoke('lastStatementEndLine', $lineNum); | ||
| 22339 | $self->ivPoke('lastStatementStartLine', $lineNum); | ||
| 22340 | |||
| 22341 | # Archive the previous current room object (if there was one) | ||
| 22342 | if ($self->roomObj) { | ||
| 22343 | |||
| 22344 | $self->ivPoke('prevRoomObj', $self->roomObj); | ||
| 22345 | } | ||
| 22346 | |||
| 22347 | # Create a non-model object for this room | ||
| 22348 | $tempRoomObj = Games::Axmud::ModelObj::Room->new( | ||
| 22349 | $self->session, | ||
| 22350 | 'temporary', | ||
| 22351 | 'non_model', | ||
| 22352 | ); | ||
| 22353 | |||
| 22354 | $self->ivPoke('roomObj', $tempRoomObj); # Even if $tempRoomObj is 'undef' | ||
| 22355 | |||
| 22356 | # Mark this non-model room as (currently) unspecified | ||
| 22357 | $self->roomObj->ivPoke('unspecifiedFlag', TRUE); | ||
| 22358 | } | ||
| 22359 | |||
| 22360 | # In the remainder of this function, it's easier to just check for $specialFlag, | ||
| 22361 | # rather than checking for all of $specialFlag, $followFlag and $followAnchorFlag | ||
| 22362 | $specialFlag = TRUE; | ||
| 22363 | } | ||
| 22364 | } | ||
| 22365 | |||
| 22366 | # PART 11 | ||
| 22367 | # Look for dark/unspecified room patterns that take the place of an anchor (unless a failed | ||
| 22368 | # exit, involuntary exit, special departure pattern or a verbose/short verbose/brief | ||
| 22369 | # anchor has already been found) | ||
| 22370 | if (! $failExitFlag && ! $involuntaryExitFlag && ! $specialFlag) { | ||
| 22371 | |||
| 22372 | # Look for dark room patterns | ||
| 22373 | OUTER: foreach my $pattern ($worldObj->darkRoomPatternList) { | ||
| 22374 | |||
| 22375 | if ($lineText =~ m/$pattern/) { | ||
| 22376 | |||
| 22377 | if ($axmud::CLIENT->debugLocatorFlag) { | ||
| 22378 | |||
| 22379 | $self->writeDebug( | ||
| 22380 | 'LOCATOR 261: Found dark room pattern (anchor): ' . $pattern, | ||
| 22381 | ); | ||
| 22382 | } | ||
| 22383 | |||
| 22384 | # A dark room pattern (anchor) was found on this line | ||
| 22385 | $updateFlag = TRUE; | ||
| 22386 | |||
| 22387 | # Remember the position in the display buffer of the most recent anchor line | ||
| 22388 | # found | ||
| 22389 | $self->ivPoke('lastAnchorLine', $lineNum); | ||
| 22390 | $self->ivPoke('lastStatementEndLine', $lineNum); | ||
| 22391 | $self->ivPoke('lastStatementStartLine', $lineNum); | ||
| 22392 | |||
| 22393 | # Archive the previous current room object (if there was one) | ||
| 22394 | if ($self->roomObj) { | ||
| 22395 | |||
| 22396 | $self->ivPoke('prevRoomObj', $self->roomObj); | ||
| 22397 | } | ||
| 22398 | |||
| 22399 | # Create a non-model object for this room | ||
| 22400 | $tempRoomObj = Games::Axmud::ModelObj::Room->new( | ||
| 22401 | $self->session, | ||
| 22402 | 'temporary', | ||
| 22403 | 'non_model', | ||
| 22404 | ); | ||
| 22405 | |||
| 22406 | $self->ivPoke('roomObj', $tempRoomObj); # Even if $tempRoomObj is 'undef' | ||
| 22407 | |||
| 22408 | # Mark this non-model room as (currently) dark | ||
| 22409 | $self->roomObj->ivPoke('currentlyDarkFlag', TRUE); | ||
| 22410 | $specialFlag = TRUE; | ||
| 22411 | } | ||
| 22412 | } | ||
| 22413 | |||
| 22414 | # Look for unspecified room patterns | ||
| 22415 | if (! $specialFlag) { | ||
| 22416 | |||
| 22417 | # Check the room's unspecified patterns first, then the world's unspecified patterns | ||
| 22418 | if ($destRoomObj) { | ||
| 22419 | |||
| 22420 | push (@unspecifiedList, $destRoomObj->unspecifiedPatternList); | ||
| 22421 | } | ||
| 22422 | |||
| 22423 | push (@unspecifiedList, $worldObj->unspecifiedRoomPatternList); | ||
| 22424 | INNER: foreach my $pattern (@unspecifiedList) { | ||
| 22425 | |||
| 22426 | if ($lineText =~ m/$pattern/) { | ||
| 22427 | |||
| 22428 | if ($axmud::CLIENT->debugLocatorFlag) { | ||
| 22429 | |||
| 22430 | $self->writeDebug( | ||
| 22431 | 'LOCATOR 262: Unspecified room pattern (anchor): ' . $pattern, | ||
| 22432 | ); | ||
| 22433 | } | ||
| 22434 | |||
| 22435 | # An unspecified room pattern (anchor) was found on this line | ||
| 22436 | $updateFlag = TRUE; | ||
| 22437 | |||
| 22438 | # Remember the position in the display buffer of the most recent anchor line | ||
| 22439 | # found | ||
| 22440 | $self->ivPoke('lastAnchorLine', $lineNum); | ||
| 22441 | $self->ivPoke('lastStatementEndLine', $lineNum); | ||
| 22442 | $self->ivPoke('lastStatementStartLine', $lineNum); | ||
| 22443 | |||
| 22444 | # Archive the previous current room object (if there was one) | ||
| 22445 | if ($self->roomObj) { | ||
| 22446 | |||
| 22447 | $self->ivPoke('prevRoomObj', $self->roomObj); | ||
| 22448 | } | ||
| 22449 | |||
| 22450 | # Create a non-model object for this room | ||
| 22451 | $tempRoomObj = Games::Axmud::ModelObj::Room->new( | ||
| 22452 | $self->session, | ||
| 22453 | 'temporary', | ||
| 22454 | 'non_model', | ||
| 22455 | ); | ||
| 22456 | |||
| 22457 | $self->ivPoke('roomObj', $tempRoomObj); # Even if $tempRoomObj is 'undef' | ||
| 22458 | |||
| 22459 | # Mark this non-model room as (currently) unspecified | ||
| 22460 | $self->roomObj->ivPoke('unspecifiedFlag', TRUE); | ||
| 22461 | $specialFlag = TRUE; | ||
| 22462 | } | ||
| 22463 | } | ||
| 22464 | } | ||
| 22465 | |||
| 22466 | if ($specialFlag && ! $self->roomCount) { | ||
| 22467 | |||
| 22468 | # First room statement found (even though it's a dark or unspecified room) - in | ||
| 22469 | # future, search forwards, not backwards | ||
| 22470 | $self->ivPoke('roomCount', 1); | ||
| 22471 | # Make sure the move lists are empty | ||
| 22472 | $self->ivEmpty('cmdObjList'); | ||
| 22473 | $self->ivEmpty('moveList'); | ||
| 22474 | $self->ivUndef('prevCmdBufferNum'); | ||
| 22475 | # Display information about the room statement in the task window (if it's open and | ||
| 22476 | # enabled) | ||
| 22477 | if ($self->taskWinFlag) { | ||
| 22478 | |||
| 22479 | $self->refreshWin(); | ||
| 22480 | } | ||
| 22481 | |||
| 22482 | # Don't look for any more room statements until some more text is received from the | ||
| 22483 | # world | ||
| 22484 | return undef; | ||
| 22485 | } | ||
| 22486 | } | ||
| 22487 | |||
| 22488 | # PART 12 | ||
| 22489 | # If allowed, look for an MXP tag property (one of the keys in $self->mxpPropHash, namely | ||
| 22490 | # 'RoomName', 'RoomDesc', 'RoomExit', 'RoomNum') | ||
| 22491 | if ( | ||
| 22492 | ! $failExitFlag | ||
| 22493 | && ! $involuntaryExitFlag | ||
| 22494 | && ! $specialFlag | ||
| 22495 | && ( | ||
| 22496 | (! $existsFlag && $axmud::CLIENT->allowMxpRoomFlag) | ||
| 22497 | || ($existsFlag && $worldObj->ivShow('mxpOverrideHash', 'room')) | ||
| 22498 | ) | ||
| 22499 | ) { | ||
| 22500 | OUTER: foreach my $prop ($bufferObj->ivKeys('mxpFlagTextHash')) { | ||
| 22501 | |||
| 22502 | my $text = $bufferObj->ivShow('mxpFlagTextHash', $prop); | ||
| 22503 | |||
| 22504 | if ($self->ivExists('mxpPropHash', $prop)) { | ||
| 22505 | |||
| 22506 | # When the first tag property is found, stop searching for anchor lines | ||
| 22507 | # altogether | ||
| 22508 | if (! $self->useMxpFlag) { | ||
| 22509 | |||
| 22510 | $self->ivPoke('useMxpFlag', TRUE); | ||
| 22511 | } | ||
| 22512 | |||
| 22513 | # Temporarily store the tagged text. An <ELEMENT>...</ELEMENT> construction | ||
| 22514 | # could appear more than once on the same line, so watch out for that | ||
| 22515 | if (! defined $tempMxpPropHash{$prop}) { | ||
| 22516 | |||
| 22517 | $tempMxpPropHash{$prop} = $text; | ||
| 22518 | |||
| 22519 | } elsif ($prop eq 'RoomExit') { | ||
| 22520 | |||
| 22521 | # Tell $self->setRoomFromMxp that these are separate exits by using a | ||
| 22522 | # newline character | ||
| 22523 | $tempMxpPropHash{$prop} = $tempMxpPropHash{$prop} . "\n" . $text; | ||
| 22524 | |||
| 22525 | } else { | ||
| 22526 | |||
| 22527 | $tempMxpPropHash{$prop} = $tempMxpPropHash{$prop} . " " . $text; | ||
| 22528 | } | ||
| 22529 | } | ||
| 22530 | } | ||
| 22531 | |||
| 22532 | # Special case: if no rooms have been processed yet and we're moving through the buffer | ||
| 22533 | # from bottom to top, and if start/stop tags are defined, keep searching for a line | ||
| 22534 | # containing those tags (and in the meantime, store any other tags we find) | ||
| 22535 | if ( | ||
| 22536 | ! $self->roomCount | ||
| 22537 | && %tempMxpPropHash | ||
| 22538 | && ($worldObj->mxpRoomTagStart || $worldObj->mxpRoomTagStop) | ||
| 22539 | ) { | ||
| 22540 | foreach my $key (keys %tempMxpPropHash) { | ||
| 22541 | |||
| 22542 | $self->ivAdd('mxpPropCurrentHash', $key, $tempMxpPropHash{$key}); | ||
| 22543 | if ($worldObj->mxpRoomTagStart && $key eq $worldObj->mxpRoomTagStart) { | ||
| 22544 | |||
| 22545 | $self->ivPoke('mxpPropStartLine', $lineNum); | ||
| 22546 | } | ||
| 22547 | } | ||
| 22548 | |||
| 22549 | if ( | ||
| 22550 | ( | ||
| 22551 | ! $worldObj->mxpRoomTagStart | ||
| 22552 | || $self->ivExists('mxpPropCurrentHash', $worldObj->mxpRoomTagStart) | ||
| 22553 | ) && ( | ||
| 22554 | ! $worldObj->mxpRoomTagStop | ||
| 22555 | || $self->ivExists('mxpPropCurrentHash', $worldObj->mxpRoomTagStop) | ||
| 22556 | ) | ||
| 22557 | ) { | ||
| 22558 | # The start and/or stop tag has just been found, so process the first room | ||
| 22559 | # statement | ||
| 22560 | $self->prepareMxpProperties($lineNum, $worldObj); | ||
| 22561 | $anchorFlag = TRUE; | ||
| 22562 | } | ||
| 22563 | |||
| 22564 | # (Take no further action in this PART) | ||
| 22565 | %tempMxpPropHash = (); | ||
| 22566 | } | ||
| 22567 | |||
| 22568 | # If the current world profile has specified tags marking the beginning and/or end of a | ||
| 22569 | # room statement, the Locator Task is more likely to be able to catch the whole room | ||
| 22570 | # statement (so check for that first) | ||
| 22571 | # If not, then proceed with dumb handling of MXP tag properties (we'll do the best we | ||
| 22572 | # can with what we've got) | ||
| 22573 | if ( | ||
| 22574 | %tempMxpPropHash | ||
| 22575 | && $worldObj->mxpRoomTagStart | ||
| 22576 | && exists $tempMxpPropHash{$worldObj->mxpRoomTagStart} | ||
| 22577 | ) { | ||
| 22578 | # A room statement starts on this line | ||
| 22579 | # If $self->mxpPropCurrentHash is already storing tagged text, then that represents | ||
| 22580 | # a previous room statement, which can now be processed | ||
| 22581 | if ($self->mxpPropCurrentHash) { | ||
| 22582 | |||
| 22583 | # Process the previous room statement | ||
| 22584 | $self->prepareMxpProperties($lineNum, $worldObj); | ||
| 22585 | # Return -1 to force $self->doStage to call this function for the same line | ||
| 22586 | # again, this time processing the room statement that starts on this line | ||
| 22587 | return -1; | ||
| 22588 | } | ||
| 22589 | |||
| 22590 | if (! $worldObj->mxpRoomTagStop || ! $self->roomCount) { | ||
| 22591 | |||
| 22592 | # Dumb handling of MXP room tags, because the world profile doesn't specify | ||
| 22593 | # ->mxpRoomTagStart or ->mxpRoomTagStop | ||
| 22594 | $anchorFlag = TRUE; | ||
| 22595 | |||
| 22596 | # Search more lines, looking for more MXP tag properties until (1) an identical | ||
| 22597 | # tag property is found (which means the start of another room statement), or | ||
| 22598 | # (2) all four tag properties are found (which means the end of the current | ||
| 22599 | # room statement) or (3) the task runs out of lines (which means the end of | ||
| 22600 | # the current room statement), or (4) more than 32 lines without a tag | ||
| 22601 | # property are checked | ||
| 22602 | if (! $self->roomCount) { | ||
| 22603 | |||
| 22604 | # (Still looking for first statement, but just for now, don't search lines | ||
| 22605 | # in reverse order) | ||
| 22606 | $self->processMxpProperties( | ||
| 22607 | $stopLineNum, | ||
| 22608 | $lineNum, | ||
| 22609 | $worldObj, | ||
| 22610 | %tempMxpPropHash, | ||
| 22611 | ); | ||
| 22612 | |||
| 22613 | } else { | ||
| 22614 | |||
| 22615 | $self->processMxpProperties( | ||
| 22616 | $lineNum, | ||
| 22617 | $stopLineNum, | ||
| 22618 | $worldObj, | ||
| 22619 | %tempMxpPropHash, | ||
| 22620 | ); | ||
| 22621 | } | ||
| 22622 | |||
| 22623 | } else { | ||
| 22624 | |||
| 22625 | # Store the new tagged text, and wait for the end of the statement | ||
| 22626 | foreach my $key (keys %tempMxpPropHash) { | ||
| 22627 | |||
| 22628 | $self->ivAdd('mxpPropCurrentHash', $key, $tempMxpPropHash{$key}); | ||
| 22629 | } | ||
| 22630 | |||
| 22631 | $self->ivPoke('mxpPropStartLine', $lineNum); | ||
| 22632 | } | ||
| 22633 | |||
| 22634 | # (Take no further action in this PART) | ||
| 22635 | %tempMxpPropHash = (); | ||
| 22636 | } | ||
| 22637 | |||
| 22638 | if ( | ||
| 22639 | %tempMxpPropHash | ||
| 22640 | && $worldObj->mxpRoomTagStop | ||
| 22641 | && exists $tempMxpPropHash{$worldObj->mxpRoomTagStop} | ||
| 22642 | ) { | ||
| 22643 | # A room statement stops on this line | ||
| 22644 | # If this line contains the same type of tagged text as seen on previous lines, | ||
| 22645 | # then that represents a previous room statement, which can now be processed | ||
| 22646 | foreach my $key (keys %tempMxpPropHash) { | ||
| 22647 | |||
| 22648 | if ($self->ivExists('mxpPropCurrentHash', $key)) { | ||
| 22649 | |||
| 22650 | # Process the previous room statement | ||
| 22651 | $self->prepareMxpProperties($lineNum, $worldObj); | ||
| 22652 | # Return -1 to force $self->doStage to call this function for the same line | ||
| 22653 | # again, this time processing the room statement that stops on this line | ||
| 22654 | return -1; | ||
| 22655 | } | ||
| 22656 | } | ||
| 22657 | |||
| 22658 | # (This condition will be true, if the room statement starts and stops on the same | ||
| 22659 | # line) | ||
| 22660 | if (! $self->mxpPropCurrentHash) { | ||
| 22661 | |||
| 22662 | $self->ivPoke('mxpPropStartLine', $lineNum); | ||
| 22663 | } | ||
| 22664 | |||
| 22665 | # Store the new tagged text | ||
| 22666 | foreach my $key (keys %tempMxpPropHash) { | ||
| 22667 | |||
| 22668 | $self->ivAdd('mxpPropCurrentHash', $key, $tempMxpPropHash{$key}); | ||
| 22669 | } | ||
| 22670 | |||
| 22671 | # Process the new room statement | ||
| 22672 | $self->prepareMxpProperties($lineNum, $worldObj); | ||
| 22673 | $anchorFlag = TRUE; | ||
| 22674 | |||
| 22675 | # (Take no further action in this PART) | ||
| 22676 | %tempMxpPropHash = (); | ||
| 22677 | } | ||
| 22678 | |||
| 22679 | if ( | ||
| 22680 | %tempMxpPropHash | ||
| 22681 | && ($worldObj->mxpRoomTagStart || $worldObj->mxpRoomTagStop) | ||
| 22682 | ) { | ||
| 22683 | # The world profile specifies the tags which mark the beginning and/or end of a room | ||
| 22684 | # statement, but only some of the other MXP tag properties were found on this line | ||
| 22685 | OUTER: foreach my $key (keys %tempMxpPropHash) { | ||
| 22686 | |||
| 22687 | if ($self->ivExists('mxpPropCurrentHash', $key)) { | ||
| 22688 | |||
| 22689 | # Process the previous room statement | ||
| 22690 | $self->prepareMxpProperties($lineNum, $worldObj); | ||
| 22691 | $anchorFlag = TRUE; | ||
| 22692 | |||
| 22693 | last OUTER; | ||
| 22694 | } | ||
| 22695 | } | ||
| 22696 | |||
| 22697 | # Store the new tagged text | ||
| 22698 | foreach my $key (keys %tempMxpPropHash) { | ||
| 22699 | |||
| 22700 | $self->ivAdd('mxpPropCurrentHash', $key, $tempMxpPropHash{$key}); | ||
| 22701 | } | ||
| 22702 | |||
| 22703 | # (Take no further action in this PART) | ||
| 22704 | %tempMxpPropHash = (); | ||
| 22705 | } | ||
| 22706 | |||
| 22707 | if (%tempMxpPropHash) { | ||
| 22708 | |||
| 22709 | # Dumb handling of MXP room tags, because the world profile doesn't specify | ||
| 22710 | # ->mxpRoomTagStart or ->mxpRoomTagStop | ||
| 22711 | $anchorFlag = TRUE; | ||
| 22712 | |||
| 22713 | # Search more lines, looking for more MXP tag properties until (1) an identical tag | ||
| 22714 | # property is found (which means the start of another room statement), or (2) all | ||
| 22715 | # four tag properties are found (which means the end of the current room | ||
| 22716 | # statement) or (3) the task runs out of lines (which means the end of the | ||
| 22717 | # current room statement), or (4) more than 32 lines without a tag property are | ||
| 22718 | # checked | ||
| 22719 | $self->processMxpProperties( | ||
| 22720 | $lineNum, | ||
| 22721 | $stopLineNum, | ||
| 22722 | $worldObj, | ||
| 22723 | %tempMxpPropHash, | ||
| 22724 | ); | ||
| 22725 | } | ||
| 22726 | } | ||
| 22727 | |||
| 22728 | # PARTS 13-16 | ||
| 22729 | # Look for an anchor line (unless a failed exit, involuntary exit, special departure pattern | ||
| 22730 | # or an MXP room tag has already been found) | ||
| 22731 | if (! $failExitFlag && ! $involuntaryExitFlag && ! $specialFlag && ! $anchorFlag) { | ||
| 22732 | |||
| 22733 | # PART 13 | ||
| 22734 | # In Basic mapping mode, if this task is expecting room statements, then accept any line | ||
| 22735 | # that's not a failed exit, involuntary exit, special departure, command prompt or | ||
| 22736 | # empty line | ||
| 22737 | if ( | ||
| 22738 | ! $anchorFlag | ||
| 22739 | && ! $self->useMxpFlag | ||
| 22740 | && $worldObj->basicMappingFlag | ||
| 22741 | && $self->moveList | ||
| 22742 | ) { | ||
| 22743 | push (@promptList, | ||
| 22744 | '^\s*$', # Empty line | ||
| 22745 | $worldObj->cmdPromptPatternList, # Recognisable command prompts | ||
| 22746 | ); | ||
| 22747 | |||
| 22748 | OUTER: foreach my $pattern (@promptList) { | ||
| 22749 | |||
| 22750 | if ($lineText =~ m/$pattern/) { | ||
| 22751 | |||
| 22752 | $promptFlag = TRUE; # Treat empty lines and prompts the same way | ||
| 22753 | last OUTER; | ||
| 22754 | } | ||
| 22755 | } | ||
| 22756 | |||
| 22757 | # Basic mapping anchor found | ||
| 22758 | if (! $promptFlag && $axmud::CLIENT->debugLocatorFlag) { | ||
| 22759 | |||
| 22760 | $self->session->writeDebug( | ||
| 22761 | 'LOCATOR 281: Found basic mapping anchor line', | ||
| 22762 | ); | ||
| 22763 | } | ||
| 22764 | |||
| 22765 | # If room statement components have been specified in either of the three lists, | ||
| 22766 | # try to extract those components (stopping after the first successful | ||
| 22767 | # extraction) | ||
| 22768 | if (! $promptFlag && $worldObj->verboseComponentList) { | ||
| 22769 | |||
| 22770 | # (Check termination pattern - see comments in PART 13) | ||
| 22771 | if ( | ||
| 22772 | $worldObj->verboseFinalPattern | ||
| 22773 | && ( | ||
| 22774 | ! $self->findTerminationPattern( | ||
| 22775 | $lineNum, | ||
| 22776 | $worldObj, | ||
| 22777 | $worldObj->verboseFinalPattern, | ||
| 22778 | ) | ||
| 22779 | ) | ||
| 22780 | ) { | ||
| 22781 | # (None found) | ||
| 22782 | $self->ivPoke('restartBufferLine', $restartLineNum); | ||
| 22783 | return undef; | ||
| 22784 | |||
| 22785 | } elsif ($self->processAnchor($lineNum, $worldObj, 'verbose')) { | ||
| 22786 | |||
| 22787 | $anchorFlag = TRUE; | ||
| 22788 | if ($axmud::CLIENT->debugLocatorFlag) { | ||
| 22789 | |||
| 22790 | $self->session->writeDebug( | ||
| 22791 | 'LOCATOR 282: Processed verbose component list', | ||
| 22792 | ); | ||
| 22793 | } | ||
| 22794 | } | ||
| 22795 | } | ||
| 22796 | |||
| 22797 | if (! $promptFlag && ! $anchorFlag && $worldObj->shortComponentList) { | ||
| 22798 | |||
| 22799 | # (Check termination pattern - see comments in PART 13) | ||
| 22800 | if ( | ||
| 22801 | $worldObj->shortFinalPattern | ||
| 22802 | && ( | ||
| 22803 | ! $self->findTerminationPattern( | ||
| 22804 | $lineNum, | ||
| 22805 | $worldObj, | ||
| 22806 | $worldObj->shortFinalPattern, | ||
| 22807 | ) | ||
| 22808 | ) | ||
| 22809 | ) { | ||
| 22810 | # (None found) | ||
| 22811 | $self->ivPoke('restartBufferLine', $restartLineNum); | ||
| 22812 | return undef; | ||
| 22813 | |||
| 22814 | } elsif ($self->processAnchor($lineNum, $worldObj, 'short')) { | ||
| 22815 | |||
| 22816 | $anchorFlag = TRUE; | ||
| 22817 | if ($axmud::CLIENT->debugLocatorFlag) { | ||
| 22818 | |||
| 22819 | $self->session->writeDebug( | ||
| 22820 | 'LOCATOR 283: Processed short verbose component list', | ||
| 22821 | ); | ||
| 22822 | } | ||
| 22823 | } | ||
| 22824 | } | ||
| 22825 | |||
| 22826 | if (! $promptFlag && ! $anchorFlag && $worldObj->briefComponentList) { | ||
| 22827 | |||
| 22828 | # (Check termination pattern - see comments in PART 13) | ||
| 22829 | if ( | ||
| 22830 | $worldObj->briefFinalPattern | ||
| 22831 | && ( | ||
| 22832 | ! $self->findTerminationPattern( | ||
| 22833 | $lineNum, | ||
| 22834 | $worldObj, | ||
| 22835 | $worldObj->briefFinalPattern, | ||
| 22836 | ) | ||
| 22837 | ) | ||
| 22838 | ) { | ||
| 22839 | # (None found) | ||
| 22840 | $self->ivPoke('restartBufferLine', $restartLineNum); | ||
| 22841 | return undef; | ||
| 22842 | |||
| 22843 | } elsif ($self->processAnchor($lineNum, $worldObj, 'brief')) { | ||
| 22844 | |||
| 22845 | $anchorFlag = TRUE; | ||
| 22846 | if ($axmud::CLIENT->debugLocatorFlag) { | ||
| 22847 | |||
| 22848 | $self->session->writeDebug( | ||
| 22849 | 'LOCATOR 284: Processed brief component list', | ||
| 22850 | ); | ||
| 22851 | } | ||
| 22852 | } | ||
| 22853 | } | ||
| 22854 | |||
| 22855 | if (! $promptFlag && ! $anchorFlag) { | ||
| 22856 | |||
| 22857 | if (! $self->processAnchor($lineNum, $worldObj, 'basic')) { | ||
| 22858 | |||
| 22859 | $self->writeDebug('LOCATOR 285: Unable to process basic mapping anchor'); | ||
| 22860 | |||
| 22861 | } else { | ||
| 22862 | |||
| 22863 | # (Call to ->processAnchor didn't end in failure - an unlikely situation) | ||
| 22864 | $anchorFlag = TRUE; | ||
| 22865 | } | ||
| 22866 | } | ||
| 22867 | } | ||
| 22868 | |||
| 22869 | # PART 14 | ||
| 22870 | # Look for a verbose anchor line | ||
| 22871 | if (! $promptFlag && ! $anchorFlag && ! $self->useMxpFlag) { | ||
| 22872 | |||
| 22873 | OUTER: foreach my $pattern ($worldObj->verboseAnchorPatternList) { | ||
| 22874 | |||
| 22875 | if ($lineText =~ m/$pattern/) { | ||
| 22876 | |||
| 22877 | # Verbose anchor found | ||
| 22878 | if ($axmud::CLIENT->debugLocatorFlag) { | ||
| 22879 | |||
| 22880 | $self->session->writeDebug( | ||
| 22881 | 'LOCATOR 291: Found verbose anchor pattern: ' . $pattern, | ||
| 22882 | ); | ||
| 22883 | } | ||
| 22884 | |||
| 22885 | # If a termination pattern has been specified, check remaining lines in the | ||
| 22886 | # display buffer until either that line is found, or another anchor is | ||
| 22887 | # found | ||
| 22888 | if ( | ||
| 22889 | $worldObj->verboseFinalPattern | ||
| 22890 | && ( | ||
| 22891 | ! $self->findTerminationPattern( | ||
| 22892 | $lineNum, | ||
| 22893 | $worldObj, | ||
| 22894 | $worldObj->verboseFinalPattern, | ||
| 22895 | ) | ||
| 22896 | ) | ||
| 22897 | ) { | ||
| 22898 | # No termination pattern found, probably because it's a long room | ||
| 22899 | # statement and some part of it hasn't been received yet. Wait until | ||
| 22900 | # the next task before trying again | ||
| 22901 | $self->ivPoke('restartBufferLine', $restartLineNum); | ||
| 22902 | return undef; | ||
| 22903 | } | ||
| 22904 | |||
| 22905 | # If any anchor check patterns have been specified, check that nearby lines | ||
| 22906 | # match those patterns | ||
| 22907 | if (! $self->checkAnchor($lineNum, $worldObj, 'verbose')) { | ||
| 22908 | |||
| 22909 | if ($axmud::CLIENT->debugLocatorFlag) { | ||
| 22910 | |||
| 22911 | $self->writeDebug( | ||
| 22912 | 'LOCATOR 292: Anchor check patterns do not match nearby lines', | ||
| 22913 | ); | ||
| 22914 | } | ||
| 22915 | |||
| 22916 | last OUTER; | ||
| 22917 | } | ||
| 22918 | |||
| 22919 | # Can we extract the rest of the components? If not, ignore the anchor | ||
| 22920 | if ($self->processAnchor($lineNum, $worldObj, 'verbose')) { | ||
| 22921 | |||
| 22922 | $anchorFlag = TRUE; | ||
| 22923 | |||
| 22924 | } elsif ($axmud::CLIENT->debugLocatorFlag) { | ||
| 22925 | |||
| 22926 | $self->writeDebug('LOCATOR 293: Unable to process verbose anchor'); | ||
| 22927 | } | ||
| 22928 | |||
| 22929 | last OUTER; | ||
| 22930 | } | ||
| 22931 | } | ||
| 22932 | } | ||
| 22933 | |||
| 22934 | # PART 15 | ||
| 22935 | # Look for a short verbose anchor line | ||
| 22936 | if (! $promptFlag && ! $anchorFlag && ! $self->useMxpFlag) { | ||
| 22937 | |||
| 22938 | OUTER: foreach my $pattern ($worldObj->shortAnchorPatternList) { | ||
| 22939 | |||
| 22940 | if ($lineText =~ m/$pattern/) { | ||
| 22941 | |||
| 22942 | # Short verbose anchor found | ||
| 22943 | if ($axmud::CLIENT->debugLocatorFlag) { | ||
| 22944 | |||
| 22945 | $self->writeDebug( | ||
| 22946 | 'LOCATOR 301: Found short verbose anchor pattern: ' . $pattern, | ||
| 22947 | ); | ||
| 22948 | } | ||
| 22949 | |||
| 22950 | # If a termination pattern has been specified, check remaining lines in the | ||
| 22951 | # display buffer until either that line is found, or another anchor is | ||
| 22952 | # found | ||
| 22953 | if ( | ||
| 22954 | $worldObj->shortFinalPattern | ||
| 22955 | && ( | ||
| 22956 | ! $self->findTerminationPattern( | ||
| 22957 | $lineNum, | ||
| 22958 | $worldObj, | ||
| 22959 | $worldObj->shortFinalPattern, | ||
| 22960 | ) | ||
| 22961 | ) | ||
| 22962 | ) { | ||
| 22963 | # No termination pattern found, probably because it's a long room | ||
| 22964 | # statement and some part of it hasn't been received yet. Wait until | ||
| 22965 | # the next task loop before trying again | ||
| 22966 | $self->ivPoke('restartBufferLine', $restartLineNum); | ||
| 22967 | return undef; | ||
| 22968 | } | ||
| 22969 | |||
| 22970 | # If any anchor check patterns have been specified, check that nearby lines | ||
| 22971 | # match those patterns | ||
| 22972 | if (! $self->checkAnchor($lineNum, $worldObj, 'short')) { | ||
| 22973 | |||
| 22974 | if ($axmud::CLIENT->debugLocatorFlag) { | ||
| 22975 | |||
| 22976 | $self->writeDebug( | ||
| 22977 | 'LOCATOR 302: Anchor check patterns do not match nearby lines', | ||
| 22978 | ); | ||
| 22979 | } | ||
| 22980 | |||
| 22981 | last OUTER; | ||
| 22982 | } | ||
| 22983 | |||
| 22984 | # Can we extract the rest of the components? If not, ignore the anchor | ||
| 22985 | if ($self->processAnchor($lineNum, $worldObj, 'short')) { | ||
| 22986 | |||
| 22987 | $anchorFlag = TRUE; | ||
| 22988 | |||
| 22989 | } elsif ($axmud::CLIENT->debugLocatorFlag) { | ||
| 22990 | |||
| 22991 | $self->writeDebug( | ||
| 22992 | 'LOCATOR 303: Unable to process short verbose anchor', | ||
| 22993 | ); | ||
| 22994 | } | ||
| 22995 | |||
| 22996 | last OUTER; | ||
| 22997 | } | ||
| 22998 | } | ||
| 22999 | } | ||
| 23000 | |||
| 23001 | # PART 16 | ||
| 23002 | # Look for a brief anchor line | ||
| 23003 | if (! $promptFlag && ! $anchorFlag && ! $self->useMxpFlag) { | ||
| 23004 | |||
| 23005 | OUTER: foreach my $pattern ($worldObj->briefAnchorPatternList) { | ||
| 23006 | |||
| 23007 | if ($lineText =~ m/$pattern/) { | ||
| 23008 | |||
| 23009 | # Brief anchor found | ||
| 23010 | if ($axmud::CLIENT->debugLocatorFlag) { | ||
| 23011 | |||
| 23012 | $self->writeDebug( | ||
| 23013 | 'LOCATOR 311: Found brief anchor pattern: ' . $pattern, | ||
| 23014 | ); | ||
| 23015 | } | ||
| 23016 | |||
| 23017 | # If a termination pattern has been specified, check remaining lines in the | ||
| 23018 | # display buffer until either that line is found, or another anchor is | ||
| 23019 | # found | ||
| 23020 | if ( | ||
| 23021 | $worldObj->briefFinalPattern | ||
| 23022 | && ( | ||
| 23023 | ! $self->findTerminationPattern( | ||
| 23024 | $lineNum, | ||
| 23025 | $worldObj, | ||
| 23026 | $worldObj->briefFinalPattern, | ||
| 23027 | ) | ||
| 23028 | ) | ||
| 23029 | ) { | ||
| 23030 | # No termination pattern found, probably because it's a long room | ||
| 23031 | # statement and some part of it hasn't been received yet. Wait until | ||
| 23032 | # the next task loop before trying again | ||
| 23033 | $self->ivPoke('restartBufferLine', $restartLineNum); | ||
| 23034 | return undef; | ||
| 23035 | } | ||
| 23036 | |||
| 23037 | # If any anchor check patterns have been specified, check that nearby lines | ||
| 23038 | # match those patterns | ||
| 23039 | if (! $self->checkAnchor($lineNum, $worldObj, 'brief')) { | ||
| 23040 | |||
| 23041 | if ($axmud::CLIENT->debugLocatorFlag) { | ||
| 23042 | |||
| 23043 | $self->writeDebug( | ||
| 23044 | 'LOCATOR 312: Anchor check patterns do not match nearby lines', | ||
| 23045 | ); | ||
| 23046 | } | ||
| 23047 | |||
| 23048 | last OUTER; | ||
| 23049 | } | ||
| 23050 | |||
| 23051 | # Can we extract the rest of the components? If not, ignore the anchor | ||
| 23052 | if ($self->processAnchor($lineNum, $worldObj, 'brief')) { | ||
| 23053 | |||
| 23054 | $anchorFlag = TRUE; | ||
| 23055 | |||
| 23056 | } elsif ($axmud::CLIENT->debugLocatorFlag) { | ||
| 23057 | |||
| 23058 | $self->writeDebug( | ||
| 23059 | 'LOCATOR 313: Unable to process brief anchor', | ||
| 23060 | ); | ||
| 23061 | } | ||
| 23062 | |||
| 23063 | last OUTER; | ||
| 23064 | } | ||
| 23065 | } | ||
| 23066 | } | ||
| 23067 | } | ||
| 23068 | |||
| 23069 | # (Parts 12-16) | ||
| 23070 | if ($anchorFlag) { | ||
| 23071 | |||
| 23072 | $updateFlag = TRUE; | ||
| 23073 | # Remember the position in the display buffer of the most recent anchor line found | ||
| 23074 | $self->ivPoke('lastAnchorLine', $lineNum); | ||
| 23075 | |||
| 23076 | if (! $self->roomCount) { | ||
| 23077 | |||
| 23078 | # First room statement found - in future, search forwards, not backwards | ||
| 23079 | $self->ivPoke('roomCount', 1); | ||
| 23080 | |||
| 23081 | # Special case: if the automapper object's ->currentRoom has already been set | ||
| 23082 | # (usually because the user opens the Automapper window and sets the current | ||
| 23083 | # room there), $self->modelNumber will already be set | ||
| 23084 | # In that case, see if the room has a room tag and, if so, display it | ||
| 23085 | if ($self->modelNumber) { | ||
| 23086 | |||
| 23087 | if ( | ||
| 23088 | ! $self->session->worldModelObj->ivExists( | ||
| 23089 | 'modelHash', | ||
| 23090 | $self->modelNumber, | ||
| 23091 | ) | ||
| 23092 | ) { | ||
| 23093 | # Room doesn't exist in the model (rather unlikely) | ||
| 23094 | $self->ivUndef('modelNumber'); | ||
| 23095 | |||
| 23096 | } else { | ||
| 23097 | |||
| 23098 | $mapRoomObj = $self->session->worldModelObj->ivShow( | ||
| 23099 | 'modelHash', | ||
| 23100 | $self->modelNumber, | ||
| 23101 | ); | ||
| 23102 | |||
| 23103 | # Make sure it's a room | ||
| 23104 | if ($mapRoomObj->category ne 'room') { | ||
| 23105 | |||
| 23106 | $self->ivUndef('modelNumber'); | ||
| 23107 | |||
| 23108 | } elsif ($mapRoomObj->roomTag) { | ||
| 23109 | |||
| 23110 | # Set the room tag of this task's non-model room to match | ||
| 23111 | $self->roomObj->ivPoke('roomTag', $mapRoomObj->roomTag); | ||
| 23112 | } | ||
| 23113 | } | ||
| 23114 | |||
| 23115 | } else { | ||
| 23116 | |||
| 23117 | # Otherwise, make sure the move lists are empty | ||
| 23118 | $self->ivEmpty('cmdObjList'); | ||
| 23119 | $self->ivEmpty('moveList'); | ||
| 23120 | $self->ivUndef('prevCmdBufferNum'); | ||
| 23121 | } | ||
| 23122 | |||
| 23123 | # Display information about the room statement in the task window (if it's open | ||
| 23124 | # and enabled) | ||
| 23125 | if ($self->taskWinFlag) { | ||
| 23126 | |||
| 23127 | $self->refreshWin(); | ||
| 23128 | } | ||
| 23129 | |||
| 23130 | # Don't look for any more room statements until some more text is received from | ||
| 23131 | # the world | ||
| 23132 | # Exception: if the automapper has a current room set and we're updating the | ||
| 23133 | # world model (the Automapper window is in 'update' mode, or the automapper | ||
| 23134 | # object's ->trackAloneFlag is set), then we need to process PART 16, in order | ||
| 23135 | # to update the current room | ||
| 23136 | if ( | ||
| 23137 | ! $self->session->mapObj->currentRoom | ||
| 23138 | || ! ( | ||
| 23139 | ($self->session->mapWin && $self->session->mapWin->mode eq 'update') | ||
| 23140 | || $self->session->mapObj->trackAloneFlag | ||
| 23141 | ) | ||
| 23142 | ) { | ||
| 23143 | return undef; | ||
| 23144 | } | ||
| 23145 | } | ||
| 23146 | } | ||
| 23147 | |||
| 23148 | # PART 17 | ||
| 23149 | # If an anchor line has been found, need to decide which command object in $self->cmdObjList | ||
| 23150 | # was responsible for it | ||
| 23151 | if ($updateFlag) { | ||
| 23152 | |||
| 23153 | $self->ivIncrement('roomCount'); | ||
| 23154 | $self->ivUndef('modelNumber'); | ||
| 23155 | |||
| 23156 | # $cmdObj represents a look/glance command or a movement command (including redirect | ||
| 23157 | # mode commands, assisted moves and teleport commands). We'll assume that it was | ||
| 23158 | # responsible for the room statement whose anchor line appears on this line | ||
| 23159 | if ($cmdObj) { | ||
| 23160 | |||
| 23161 | $self->removeFirstMove($cmdObj); | ||
| 23162 | } | ||
| 23163 | |||
| 23164 | # Are the command lists empty of look/glance/movement commands? | ||
| 23165 | if (! $cmdObj) { | ||
| 23166 | |||
| 23167 | # The move list is empty. Inform the automapper of a move in an unknown direction | ||
| 23168 | # and let it work out where the character is now | ||
| 23169 | $self->session->mapObj->moveUnknownDirSeen(); | ||
| 23170 | |||
| 23171 | # Is it a look/glance command? | ||
| 23172 | } elsif ($cmdObj->lookFlag || $cmdObj->glanceFlag) { | ||
| 23173 | |||
| 23174 | # If the previous room object had a room tag and the new room object doesn't have | ||
| 23175 | # one (yet), it should be given the same tag (so that the look/glance command | ||
| 23176 | # doesn't cancel a tag assigned to the room by the user) | ||
| 23177 | if ( | ||
| 23178 | $self->prevRoomObj | ||
| 23179 | && $self->prevRoomObj->roomTag | ||
| 23180 | && ! $self->roomObj->roomTag | ||
| 23181 | ) { | ||
| 23182 | $self->roomObj->ivPoke('roomTag', $self->prevRoomObj->roomTag); | ||
| 23183 | } | ||
| 23184 | |||
| 23185 | # Inform the automapper object in case the room statement contains new information | ||
| 23186 | $self->session->mapObj->lookGlanceSeen($cmdObj); | ||
| 23187 | |||
| 23188 | # Is it a teleport? | ||
| 23189 | } elsif ($cmdObj->teleportFlag) { | ||
| 23190 | |||
| 23191 | if ($cmdObj->teleportDestRoom) { | ||
| 23192 | |||
| 23193 | # Inform the automapper of a move to a known destination room | ||
| 23194 | $self->session->mapObj->teleportSeen($cmdObj); | ||
| 23195 | |||
| 23196 | } else { | ||
| 23197 | |||
| 23198 | # Treat this as a normal move in an unknown direction | ||
| 23199 | $self->session->mapObj->moveUnknownDirSeen(); | ||
| 23200 | } | ||
| 23201 | |||
| 23202 | # Is it a movement direction? | ||
| 23203 | } else { | ||
| 23204 | |||
| 23205 | # Inform the automapper object | ||
| 23206 | $self->session->mapObj->moveKnownDirSeen($cmdObj); | ||
| 23207 | |||
| 23208 | # Store the direction of movement so it's available to anything that wants to know | ||
| 23209 | if ($cmdObj->redirectFlag || $cmdObj->assistedFlag) { | ||
| 23210 | $self->ivPoke('prevMove', 'cmd'); | ||
| 23211 | } else { | ||
| 23212 | $self->ivPoke('prevMove', $cmdObj->moveDir); | ||
| 23213 | } | ||
| 23214 | |||
| 23215 | # Also store the buffer object itself, in case anything wants more details about | ||
| 23216 | # the move | ||
| 23217 | $self->ivPoke('prevMoveObj', $cmdObj); | ||
| 23218 | } | ||
| 23219 | |||
| 23220 | # Display information about the room statement in the task window (if it's open and | ||
| 23221 | # enabled) | ||
| 23222 | if ($self->taskWinFlag) { | ||
| 23223 | |||
| 23224 | $self->refreshWin(); | ||
| 23225 | } | ||
| 23226 | |||
| 23227 | # Also, if there's a current mission running that's on a Locator break, we need to | ||
| 23228 | # inform the mission whenever $self->moveList becomes empty (i.e. no more room | ||
| 23229 | # statements are expected) | ||
| 23230 | if (! $self->moveList && ! $self->session->excessCmdList) { | ||
| 23231 | |||
| 23232 | $missionObj = $self->session->currentMission; | ||
| 23233 | if ($missionObj && $missionObj->breakType && $missionObj->breakType eq 'locator') { | ||
| 23234 | |||
| 23235 | $missionObj->taskReady($self->session); | ||
| 23236 | } | ||
| 23237 | } | ||
| 23238 | } | ||
| 23239 | |||
| 23240 | # Analysis complete | ||
| 23241 | return 1; | ||
| 23242 | } | ||
| 23243 | |||
| 23244 | sub findTerminationPattern { | ||
| 23245 | |||
| 23246 | # Called by $self->processLine (at stage 3) when an anchor line is found and when the world | ||
| 23247 | # profile defines a termination pattern (which means that the whole room statement has | ||
| 23248 | # been received - it is normally not necessary to check, except at MUDs with long room | ||
| 23249 | # statements, where the verbose description appears after the anchor line) | ||
| 23250 | # Checks the remaining lines in the display buffer, looking for either another anchor line, | ||
| 23251 | # or a line matching the specified termination pattern. | ||
| 23252 | # | ||
| 23253 | # Expected arguments | ||
| 23254 | # $lineNum - The display buffer number of the anchor line | ||
| 23255 | # $worldObj - Shortcut to the current world profile object | ||
| 23256 | # $termPattern - The specified termination pattern, matching either | ||
| 23257 | # $worldObj->verboseFinalPattern, ->shortFinalPattern or | ||
| 23258 | # ->briefFinalPattern | ||
| 23259 | # | ||
| 23260 | # Return values | ||
| 23261 | # 'undef' on improper arguments or if the expected termination pattern (or another anchor | ||
| 23262 | # line) isn't found in the remaining display buffer | ||
| 23263 | # 1 if either the expected termination pattern or another anchor line is found | ||
| 23264 | |||
| 23265 | my ($self, $lineNum, $worldObj, $termPattern, $check) = @_; | ||
| 23266 | |||
| 23267 | # Local variables | ||
| 23268 | my @patternList; | ||
| 23269 | |||
| 23270 | # Check for improper arguments | ||
| 23271 | if (! defined $lineNum || ! defined $worldObj || ! defined $termPattern || defined $check) { | ||
| 23272 | |||
| 23273 | return $axmud::CLIENT->writeImproper($self->_objClass . '->findTerminationPattern', @_); | ||
| 23274 | } | ||
| 23275 | |||
| 23276 | # If $lineNum is the last line in the display buffer, then of course there's no need to | ||
| 23277 | # search beyond it | ||
| 23278 | if ($lineNum >= $self->session->displayBufferLast) { | ||
| 23279 | |||
| 23280 | return undef; | ||
| 23281 | } | ||
| 23282 | |||
| 23283 | # Compile a list of patterns matching anchor lines (verbose, short verbose and brief). We | ||
| 23284 | # can add the termination pattern, too | ||
| 23285 | @patternList = ( | ||
| 23286 | $termPattern, | ||
| 23287 | $worldObj->verboseAnchorPatternList, | ||
| 23288 | $worldObj->shortAnchorPatternList, | ||
| 23289 | $worldObj->briefAnchorPatternList, | ||
| 23290 | ); | ||
| 23291 | |||
| 23292 | for (my $line = ($lineNum + 1); $line <= $self->session->displayBufferLast; $line++) { | ||
| 23293 | |||
| 23294 | my ($bufferObj, $lineText); | ||
| 23295 | |||
| 23296 | $bufferObj = $self->session->ivShow('displayBufferHash', $line); | ||
| 23297 | $lineText = $bufferObj->modLine; | ||
| 23298 | |||
| 23299 | foreach my $pattern (@patternList) { | ||
| 23300 | |||
| 23301 | if ($lineText =~ m/$pattern/) { | ||
| 23302 | |||
| 23303 | # Success! The room statement is complete | ||
| 23304 | if ($axmud::CLIENT->debugMaxLocatorFlag) { | ||
| 23305 | |||
| 23306 | $self->writeDebug( | ||
| 23307 | 'LOCATOR 401: Found anchor line matching termination pattern \'' | ||
| 23308 | . $pattern . '\'', | ||
| 23309 | ); | ||
| 23310 | } | ||
| 23311 | |||
| 23312 | return 1; | ||
| 23313 | } | ||
| 23314 | } | ||
| 23315 | } | ||
| 23316 | |||
| 23317 | # The room statement is not complete | ||
| 23318 | return undef; | ||
| 23319 | } | ||
| 23320 | |||
| 23321 | sub processMxpProperties { | ||
| 23322 | |||
| 23323 | # Called by $self->processLine (at stage 3) when an MXP tag property is found | ||
| 23324 | # Searches successive lines for more tag properties until (1) an identical tag property is | ||
| 23325 | # found (which means the start of another room statement), or (2) all four tag properties | ||
| 23326 | # are found (which means the end of the current room statement), or (3) the task runs out | ||
| 23327 | # of lines (which means the end of the current room statement), or (4) more than 8 | ||
| 23328 | # lines without a tag property are checked | ||
| 23329 | # | ||
| 23330 | # Expected arguments | ||
| 23331 | # $lineNum - The display buffer number of the line containing an MXP tag property, | ||
| 23332 | # the first matching line found for the current room statement | ||
| 23333 | # $stopLineNum - The display buffer number of last line that can be analysed during | ||
| 23334 | # this task loop (might be the same as $lineNum. If we're checking | ||
| 23335 | # lines from beginning to end, it might be higher than $lineNum; if | ||
| 23336 | # we're checking lines from end to beginning, it might be lower than | ||
| 23337 | # $lineNum) | ||
| 23338 | # $worldObj - Shortcut to the current world profile object | ||
| 23339 | # %mxpPropHash - A hash of MXP tag properties (should not be empty), in the form | ||
| 23340 | # $mxpPropHash{tag} = string | ||
| 23341 | # | ||
| 23342 | # Return values | ||
| 23343 | # 'undef' on improper arguments | ||
| 23344 | # 1 otherwise | ||
| 23345 | |||
| 23346 | my ($self, $lineNum, $stopLineNum, $worldObj, %mxpPropHash) = @_; | ||
| 23347 | |||
| 23348 | # Local variables | ||
| 23349 | my ($roomObj, $step, $maxLines, $origLineNum, $matchCount, $loopCount, $useLine, $prevProp); | ||
| 23350 | |||
| 23351 | # Check for improper arguments | ||
| 23352 | if (! defined $lineNum || ! defined $stopLineNum || ! defined $worldObj || ! %mxpPropHash) { | ||
| 23353 | |||
| 23354 | return $axmud::CLIENT->writeImproper($self->_objClass . '->processMxpProperties', @_); | ||
| 23355 | } | ||
| 23356 | |||
| 23357 | # Reset the list of lines to be converted to text-to-speech; this hash should only contain | ||
| 23358 | # the lines that we might want to read out | ||
| 23359 | $self->ivEmpty('ttsToReadHash'); | ||
| 23360 | |||
| 23361 | # Create a non-model object for this room | ||
| 23362 | $roomObj = Games::Axmud::ModelObj::Room->new( | ||
| 23363 | $self->session, | ||
| 23364 | 'temporary', | ||
| 23365 | 'non_model', | ||
| 23366 | ); | ||
| 23367 | |||
| 23368 | # Move backwards or forwards (default) in the display buffer | ||
| 23369 | if ($stopLineNum < $lineNum) { | ||
| 23370 | $step = -1; | ||
| 23371 | } else { | ||
| 23372 | $step = 1; | ||
| 23373 | } | ||
| 23374 | |||
| 23375 | # Don't carry on forever. (Before v2.1.062, the limit was 8 lines) | ||
| 23376 | $maxLines = 32; | ||
| 23377 | |||
| 23378 | # Check each line in turn | ||
| 23379 | $origLineNum = $lineNum; | ||
| 23380 | $matchCount = 0; | ||
| 23381 | $loopCount = 0; | ||
| 23382 | |||
| 23383 | do { | ||
| 23384 | |||
| 23385 | my ( | ||
| 23386 | $bufferObj, | ||
| 23387 | %newHash, | ||
| 23388 | ); | ||
| 23389 | |||
| 23390 | $lineNum += $step; | ||
| 23391 | $loopCount++; | ||
| 23392 | $bufferObj = $self->session->ivShow('displayBufferHash', $lineNum); | ||
| 23393 | # Sanity check | ||
| 23394 | if (! $bufferObj) { | ||
| 23395 | |||
| 23396 | # Apply the room statement text we've gathered so far | ||
| 23397 | $self->setRoomFromMxp($worldObj, $roomObj, $origLineNum, $lineNum, %mxpPropHash); | ||
| 23398 | # Store the lines at which the room statement starts/ends | ||
| 23399 | if ($step < 0) { | ||
| 23400 | |||
| 23401 | $self->ivPoke('lastStatementStartLine', $lineNum - 1); | ||
| 23402 | $self->ivPoke('lastStatementEndLine', $origLineNum); | ||
| 23403 | |||
| 23404 | } else { | ||
| 23405 | |||
| 23406 | $self->ivPoke('lastStatementStartLine', $origLineNum); | ||
| 23407 | $self->ivPoke('lastStatementEndLine', $lineNum - 1); | ||
| 23408 | } | ||
| 23409 | |||
| 23410 | # Do logfiles, TTS, etc | ||
| 23411 | return $self->confirmMxpProperties($worldObj, $roomObj, %mxpPropHash); | ||
| 23412 | } | ||
| 23413 | |||
| 23414 | # Compile a list of MXP tag properties on this line, only using those properties | ||
| 23415 | # that the task wants to use | ||
| 23416 | foreach my $prop ($bufferObj->ivKeys('mxpFlagTextHash')) { | ||
| 23417 | |||
| 23418 | my $text = $bufferObj->ivShow('mxpFlagTextHash', $prop); | ||
| 23419 | |||
| 23420 | if ($self->ivExists('mxpPropHash', $prop)) { | ||
| 23421 | |||
| 23422 | # The task wants to use this property | ||
| 23423 | |||
| 23424 | # If this property was found on a previous line, then this line is the start of | ||
| 23425 | # a new room statement | ||
| 23426 | # However, if this property was found on the previous line, then it's not the | ||
| 23427 | # start of a new room statement (e.g. <RoomExit>...</RoomExit> might appear on | ||
| 23428 | # several consecutive lines) | ||
| 23429 | # NB The first line of a room statement was analysed by the calling function, | ||
| 23430 | # and it may possibly have contained two or more relevant tags. The calling | ||
| 23431 | # function doesn't tell us which tag appeared last in that first line, so we | ||
| 23432 | # don't know what the value of $prevProp would have been, if that line had | ||
| 23433 | # been analysed by this function. To keep things simple, we assume that first | ||
| 23434 | # line did not contain a complete room statement in a single line, and we do | ||
| 23435 | # that by checking that $loopCount > 1 | ||
| 23436 | if ( | ||
| 23437 | exists $mxpPropHash{$prop} | ||
| 23438 | && $loopCount > 1 | ||
| 23439 | && $prevProp | ||
| 23440 | && $prevProp ne $prop | ||
| 23441 | ) { | ||
| 23442 | # Apply the room statement text we've gathered so far | ||
| 23443 | $self->setRoomFromMxp($worldObj, $roomObj, %mxpPropHash); | ||
| 23444 | # Store the lines at which the room statement starts/ends | ||
| 23445 | if ($step < 0) { | ||
| 23446 | |||
| 23447 | $self->ivPoke('lastStatementStartLine', $lineNum - 1); | ||
| 23448 | $self->ivPoke('lastStatementEndLine', $origLineNum); | ||
| 23449 | |||
| 23450 | } else { | ||
| 23451 | |||
| 23452 | $self->ivPoke('lastStatementStartLine', $origLineNum); | ||
| 23453 | $self->ivPoke('lastStatementEndLine', $lineNum - 1); | ||
| 23454 | } | ||
| 23455 | |||
| 23456 | # Do logfiles, TTS, etc | ||
| 23457 | return $self->confirmMxpProperties($worldObj, $roomObj, %mxpPropHash); | ||
| 23458 | |||
| 23459 | } else { | ||
| 23460 | |||
| 23461 | $prevProp = $prop; | ||
| 23462 | |||
| 23463 | # Guard against the possibility that, for example, a | ||
| 23464 | # <RoomName>...</RoomName> construction might appear more than once on a | ||
| 23465 | # line (which we don't treat as a new room statement, but a continuation | ||
| 23466 | # of the existing one) | ||
| 23467 | if (! exists $newHash{$prop}) { | ||
| 23468 | |||
| 23469 | $newHash{$prop} = $text; | ||
| 23470 | |||
| 23471 | } elsif ($prop eq 'RoomExit') { | ||
| 23472 | |||
| 23473 | # Tell $self->setRoomFromMxp that these are separate exits by using a | ||
| 23474 | # newline character | ||
| 23475 | $newHash{$prop} = $newHash{$prop} . "\n" . $text; | ||
| 23476 | |||
| 23477 | } else { | ||
| 23478 | |||
| 23479 | $newHash{$prop} = $newHash{$prop} . " " . $text; | ||
| 23480 | } | ||
| 23481 | } | ||
| 23482 | } | ||
| 23483 | } | ||
| 23484 | |||
| 23485 | if (! %newHash) { | ||
| 23486 | |||
| 23487 | $prevProp = undef; | ||
| 23488 | |||
| 23489 | # No MXP tag properties found on this line | ||
| 23490 | $matchCount++; | ||
| 23491 | |||
| 23492 | } else { | ||
| 23493 | |||
| 23494 | $useLine = $lineNum; | ||
| 23495 | |||
| 23496 | # Add the tag properties found on this line to those found on previous lines | ||
| 23497 | foreach my $prop (keys %newHash) { | ||
| 23498 | |||
| 23499 | if (! exists $mxpPropHash{$prop}) { | ||
| 23500 | |||
| 23501 | $mxpPropHash{$prop} = $newHash{$prop}; | ||
| 23502 | |||
| 23503 | } else { | ||
| 23504 | |||
| 23505 | $mxpPropHash{$prop} = $mxpPropHash{$prop} . " " . $newHash{$prop}; | ||
| 23506 | } | ||
| 23507 | } | ||
| 23508 | } | ||
| 23509 | |||
| 23510 | # Give up after many lines without a tag property | ||
| 23511 | } until ($matchCount >= $maxLines); | ||
| 23512 | |||
| 23513 | # Apply the room statement text we've gathered so far | ||
| 23514 | $self->setRoomFromMxp($worldObj, $roomObj, %mxpPropHash); | ||
| 23515 | |||
| 23516 | # Store the lines at which the room statement starts/ends | ||
| 23517 | if (! defined $useLine) { | ||
| 23518 | |||
| 23519 | # No additional lines found, besides $origLineNum | ||
| 23520 | $useLine = $origLineNum; | ||
| 23521 | } | ||
| 23522 | |||
| 23523 | if ($step < 0) { | ||
| 23524 | |||
| 23525 | $self->ivPoke('lastStatementStartLine', $useLine); | ||
| 23526 | $self->ivPoke('lastStatementEndLine', $origLineNum); | ||
| 23527 | |||
| 23528 | } else { | ||
| 23529 | |||
| 23530 | $self->ivPoke('lastStatementStartLine', $origLineNum); | ||
| 23531 | $self->ivPoke('lastStatementEndLine', $useLine); | ||
| 23532 | } | ||
| 23533 | |||
| 23534 | # Do logfiles, TTS, etc | ||
| 23535 | return $self->confirmMxpProperties($worldObj, $roomObj, %mxpPropHash); | ||
| 23536 | } | ||
| 23537 | |||
| 23538 | sub prepareMxpProperties { | ||
| 23539 | |||
| 23540 | # Simplified version of $self->processMxpProperties() | ||
| 23541 | # In some situations, the MXP tag properties defining a whole room statement have been | ||
| 23542 | # captured, so there's no need to check other lines. In that case, this function is | ||
| 23543 | # called instead to process the tagged text we already have | ||
| 23544 | # | ||
| 23545 | # Expected arguments | ||
| 23546 | # $lineNum - The display buffer number of the line containing the last MXP tag | ||
| 23547 | # property for a room statement (matching the line being processed by | ||
| 23548 | # the calling function, $self->processLine) | ||
| 23549 | # $worldObj - Shortcut to the current world profile object | ||
| 23550 | # | ||
| 23551 | # Return values | ||
| 23552 | # 'undef' on improper arguments | ||
| 23553 | # 1 otherwise | ||
| 23554 | |||
| 23555 | my ($self, $lineNum, $worldObj, $check) = @_; | ||
| 23556 | |||
| 23557 | # Local variables | ||
| 23558 | my $roomObj; | ||
| 23559 | |||
| 23560 | # Check for improper arguments | ||
| 23561 | if (! defined $lineNum || ! defined $worldObj || defined $check) { | ||
| 23562 | |||
| 23563 | return $axmud::CLIENT->writeImproper($self->_objClass . '->prepareMxpProperties', @_); | ||
| 23564 | } | ||
| 23565 | |||
| 23566 | # Reset the list of lines to be converted to text-to-speech; this hash should only | ||
| 23567 | # contain the lines that we might want to read out | ||
| 23568 | $self->ivEmpty('ttsToReadHash'); | ||
| 23569 | |||
| 23570 | # Create a non-model object for this room | ||
| 23571 | $roomObj = Games::Axmud::ModelObj::Room->new( | ||
| 23572 | $self->session, | ||
| 23573 | 'temporary', | ||
| 23574 | 'non_model', | ||
| 23575 | ); | ||
| 23576 | |||
| 23577 | # Apply the room statement text we've gathered so far | ||
| 23578 | $self->setRoomFromMxp($worldObj, $roomObj, $self->mxpPropCurrentHash); | ||
| 23579 | |||
| 23580 | # Store the lines at which the room statement starts/ends | ||
| 23581 | # (If the start line isn't known, for some reason, use $lineNum as both a start/stop line, | ||
| 23582 | # as an emergency fallback) | ||
| 23583 | if (! defined $self->mxpPropStartLine) { | ||
| 23584 | $self->ivPoke('lastStatementStartLine', $lineNum); | ||
| 23585 | } else { | ||
| 23586 | $self->ivPoke('lastStatementStartLine', $self->mxpPropStartLine); | ||
| 23587 | } | ||
| 23588 | |||
| 23589 | $self->ivPoke('lastStatementEndLine', $lineNum); | ||
| 23590 | |||
| 23591 | # Do logfiles, TTS, etc | ||
| 23592 | return $self->confirmMxpProperties($worldObj, $roomObj, $self->mxpPropCurrentHash); | ||
| 23593 | } | ||
| 23594 | |||
| 23595 | sub confirmMxpProperties { | ||
| 23596 | |||
| 23597 | # Called by $self->processMxpProperties and ->prepareMxpProperties, after a room statement | ||
| 23598 | # is extracted | ||
| 23599 | # Handles logfiles, TTS etc, duplicating code also found in ->processAnchor | ||
| 23600 | # | ||
| 23601 | # Expected arguments | ||
| 23602 | # $worldObj - Shortcut to the current world profile object | ||
| 23603 | # $roomObj - The non-model room object created by the calling function | ||
| 23604 | # %mxpPropHash - A hash of MXP tag properties (should not be empty), in the form | ||
| 23605 | # $mxpPropHash{tag} = string | ||
| 23606 | # | ||
| 23607 | # Return values | ||
| 23608 | # 'undef' on improper arguments | ||
| 23609 | # 1 otherwise | ||
| 23610 | |||
| 23611 | my ($self, $worldObj, $roomObj, %mxpPropHash) = @_; | ||
| 23612 | |||
| 23613 | # Check for improper arguments | ||
| 23614 | if (! defined $worldObj || ! defined $roomObj || ! %mxpPropHash) { | ||
| 23615 | |||
| 23616 | return $axmud::CLIENT->writeImproper($self->_objClass . '->confirmMxpProperties', @_); | ||
| 23617 | } | ||
| 23618 | |||
| 23619 | if ($axmud::CLIENT->debugLocatorFlag) { | ||
| 23620 | |||
| 23621 | $self->writeDebug( | ||
| 23622 | 'LOCATOR 451: Start of statement set to line #' . $self->lastStatementStartLine, | ||
| 23623 | ); | ||
| 23624 | |||
| 23625 | $self->writeDebug( | ||
| 23626 | 'LOCATOR 452: End of statement set to line #' . $self->lastStatementEndLine, | ||
| 23627 | ); | ||
| 23628 | } | ||
| 23629 | |||
| 23630 | # Archive the previous current room object (if there was one)... | ||
| 23631 | if ($self->roomObj) { | ||
| 23632 | |||
| 23633 | $self->ivPoke('prevRoomObj', $self->roomObj); | ||
| 23634 | } | ||
| 23635 | |||
| 23636 | # ...and store the new one | ||
| 23637 | $self->ivPoke('roomObj', $roomObj); | ||
| 23638 | |||
| 23639 | # Write details of the whole room statement to logfiles. (Unusual step - to save time, | ||
| 23640 | # check that this logfile is actually being written, before doing the messy business of | ||
| 23641 | # consulting the display buffer) | ||
| 23642 | # NB Obviously, don't bother in basic mapping mode, if no room statement components have | ||
| 23643 | # been specified ($type = 'basic') | ||
| 23644 | if ($worldObj->ivShow('logPrefHash', 'rooms')) { | ||
| 23645 | |||
| 23646 | for ( | ||
| 23647 | my $thisLineNum = $self->lastStatementStartLine; | ||
| 23648 | $thisLineNum <= $self->lastStatementEndLine; | ||
| 23649 | $thisLineNum++ | ||
| 23650 | ) { | ||
| 23651 | my $bufferObj = $self->session->ivShow('displayBufferHash', $thisLineNum); | ||
| 23652 | if ($bufferObj) { | ||
| 23653 | |||
| 23654 | $axmud::CLIENT->writeLog( | ||
| 23655 | $self->session, | ||
| 23656 | FALSE, # Not a 'standard' logfile | ||
| 23657 | $bufferObj->modLine, | ||
| 23658 | FALSE, # Don't precede with a newline character | ||
| 23659 | TRUE, # Use final newline character | ||
| 23660 | 'rooms', # Write to this logfile | ||
| 23661 | ); | ||
| 23662 | } | ||
| 23663 | } | ||
| 23664 | |||
| 23665 | # Add a blank line, so that the logfile isn't a wall of text | ||
| 23666 | $axmud::CLIENT->writeLog( | ||
| 23667 | $self->session, | ||
| 23668 | FALSE, # Not a 'standard' logfile | ||
| 23669 | '', | ||
| 23670 | FALSE, # Don't precede with a newline character | ||
| 23671 | TRUE, # Use final newline character | ||
| 23672 | 'rooms', # Write to this logfile | ||
| 23673 | ); | ||
| 23674 | } | ||
| 23675 | |||
| 23676 | # Write details of the verbose description to logfiles (if allowed, and if the verbose | ||
| 23677 | # statement was captured) | ||
| 23678 | if (defined $mxpPropHash{'RoomDesc'}) { | ||
| 23679 | |||
| 23680 | $axmud::CLIENT->writeLog( | ||
| 23681 | $self->session, | ||
| 23682 | FALSE, # Not a 'standard' logfile | ||
| 23683 | $mxpPropHash{'RoomDesc'}, | ||
| 23684 | FALSE, # Don't precede with a newline character | ||
| 23685 | TRUE, # Use final newline character | ||
| 23686 | 'descrips', # Write to this logfile | ||
| 23687 | ); | ||
| 23688 | |||
| 23689 | # Add a blank line, so that the logfile isn't a wall of text | ||
| 23690 | $axmud::CLIENT->writeLog( | ||
| 23691 | $self->session, | ||
| 23692 | FALSE, # Not a 'standard' logfile | ||
| 23693 | '', | ||
| 23694 | FALSE, # Don't precede with a newline character | ||
| 23695 | TRUE, # Use final newline character | ||
| 23696 | 'descrips', # Write to this logfile | ||
| 23697 | ); | ||
| 23698 | } | ||
| 23699 | |||
| 23700 | # Do text-to-speech, if required | ||
| 23701 | if ( | ||
| 23702 | $self->ivShow('ttsFlagAttribHash', 'title') | ||
| 23703 | && $self->ivShow('ttsToReadHash', 'title') | ||
| 23704 | ) { | ||
| 23705 | $self->ttsQuick($self->ivShow('ttsToReadHash', 'title')); | ||
| 23706 | } | ||
| 23707 | |||
| 23708 | if ( | ||
| 23709 | ( | ||
| 23710 | $self->ivShow('ttsFlagAttribHash', 'descrip') | ||
| 23711 | || $self->ivShow('ttsFlagAttribHash', 'description') | ||
| 23712 | ) && $self->ivShow('ttsToReadHash', 'descrip') | ||
| 23713 | ) { | ||
| 23714 | $self->ttsQuick($self->ivShow('ttsToReadHash', 'descrip')); | ||
| 23715 | } | ||
| 23716 | |||
| 23717 | if ( | ||
| 23718 | ( | ||
| 23719 | $self->ivShow('ttsFlagAttribHash', 'exit') | ||
| 23720 | || $self->ivShow('ttsFlagAttribHash', 'exits') | ||
| 23721 | ) && $self->ivShow('ttsToReadHash', 'exit') | ||
| 23722 | ) { | ||
| 23723 | $self->ttsQuick($self->ivShow('ttsToReadHash', 'exit')); | ||
| 23724 | } | ||
| 23725 | |||
| 23726 | if ( | ||
| 23727 | ( | ||
| 23728 | $self->ivShow('ttsFlagAttribHash', 'content') | ||
| 23729 | || $self->ivShow('ttsFlagAttribHash', 'contents') | ||
| 23730 | ) && $self->ivShow('ttsToReadHash', 'content') | ||
| 23731 | ) { | ||
| 23732 | $self->ttsQuick($self->ivShow('ttsToReadHash', 'content')); | ||
| 23733 | } | ||
| 23734 | |||
| 23735 | if ( | ||
| 23736 | ( | ||
| 23737 | $self->ivShow('ttsFlagAttribHash', 'command') | ||
| 23738 | || $self->ivShow('ttsFlagAttribHash', 'cmd') | ||
| 23739 | ) && $self->ivShow('ttsToReadHash', 'command') | ||
| 23740 | ) { | ||
| 23741 | $self->ttsQuick($self->ivShow('ttsToReadHash', 'command')); | ||
| 23742 | } | ||
| 23743 | |||
| 23744 | # Show debug messages, if required | ||
| 23745 | if ($axmud::CLIENT->debugLocatorFlag) { | ||
| 23746 | |||
| 23747 | $self->session->writeDebug( | ||
| 23748 | 'LOCATOR 271: Found MXP tag properties ' | ||
| 23749 | . join('/', sort {$a cmp $b} (keys %mxpPropHash)), | ||
| 23750 | ); | ||
| 23751 | } | ||
| 23752 | |||
| 23753 | # Reset IVs, ready for the next room statement | ||
| 23754 | $self->ivEmpty('mxpPropCurrentHash'); | ||
| 23755 | $self->ivUndef('mxpPropStartLine'); | ||
| 23756 | |||
| 23757 | # Anchor line processing complete | ||
| 23758 | return 1; | ||
| 23759 | } | ||
| 23760 | |||
| 23761 | sub checkAnchor { | ||
| 23762 | |||
| 23763 | # Called by $self->processLine (at stage 3) when an anchor line is found | ||
| 23764 | # The world profile can specify some patterns used to check the anchor line really is an | ||
| 23765 | # anchor line, by checking that other nearby lines match specified patterns | ||
| 23766 | # If any check patterns have been specified, checks the received text against them. If any | ||
| 23767 | # of the lines at specified offsets don't match the pattern, the test fails (and the | ||
| 23768 | # anchor line is not used as an anchor line). If no check patterns have been specified, | ||
| 23769 | # the test succeeds (and the anchor line is used as normal) | ||
| 23770 | # | ||
| 23771 | # Expected arguments | ||
| 23772 | # $lineNum - The display buffer number of the anchor line | ||
| 23773 | # $worldObj - Shortcut to the current world profile object | ||
| 23774 | # $type - The anchor type 'verbose', 'short' for short verbose anchors, 'brief' or | ||
| 23775 | # 'basic' in basic mapping mode | ||
| 23776 | # | ||
| 23777 | # Return values | ||
| 23778 | # 'undef' on improper arguments or if the test fails | ||
| 23779 | # 1 if the test succeeds | ||
| 23780 | |||
| 23781 | my ($self, $lineNum, $worldObj, $type, $check) = @_; | ||
| 23782 | |||
| 23783 | # Local variables | ||
| 23784 | my ( | ||
| 23785 | $iv, | ||
| 23786 | @list, | ||
| 23787 | ); | ||
| 23788 | |||
| 23789 | # Check for improper arguments | ||
| 23790 | if (! defined $lineNum || ! defined $worldObj || ! defined $type || defined $check) { | ||
| 23791 | |||
| 23792 | return $axmud::CLIENT->writeImproper($self->_objClass . '->checkAnchor', @_); | ||
| 23793 | } | ||
| 23794 | |||
| 23795 | # Import the IV | ||
| 23796 | $iv = $type . 'AnchorCheckList'; # e.g. ->verboseAnchorCheckList | ||
| 23797 | @list = $worldObj->$iv; | ||
| 23798 | if (! @list) { | ||
| 23799 | |||
| 23800 | # If no check patterns were specified, the test succeeds (the anchor line can be used) | ||
| 23801 | return 1; | ||
| 23802 | } | ||
| 23803 | |||
| 23804 | # Check each specified pattern on the specified line (an offset of -1 means 'check the line | ||
| 23805 | # before the anchor line', 2 means 'check the line 2 lines after the anchor line' and 0, | ||
| 23806 | # though discouraged, means 'check the anchor line itself) | ||
| 23807 | do { | ||
| 23808 | |||
| 23809 | my ($offset, $pattern, $bufferObj); | ||
| 23810 | |||
| 23811 | $offset = shift @list; | ||
| 23812 | $pattern = shift @list; | ||
| 23813 | |||
| 23814 | $bufferObj = $self->session->ivShow('displayBufferHash', ($lineNum + $offset)); | ||
| 23815 | if ( | ||
| 23816 | # Specified line not received yet (or never existed, if $thisLineNum is negative) | ||
| 23817 | ! $bufferObj | ||
| 23818 | # Specified line doesn't match the pattern | ||
| 23819 | || (! ($bufferObj->modLine =~ m/$pattern/)) | ||
| 23820 | ) { | ||
| 23821 | # Test fails, and the anchor line can't be used | ||
| 23822 | if ($axmud::CLIENT->debugMaxLocatorFlag) { | ||
| 23823 | |||
| 23824 | $self->writeDebug( | ||
| 23825 | 'LOCATOR 501: Anchor check pattern \'' . $pattern . '\' doesn\'t match line' | ||
| 23826 | . $bufferObj->number, | ||
| 23827 | ); | ||
| 23828 | } | ||
| 23829 | |||
| 23830 | return undef; | ||
| 23831 | } | ||
| 23832 | |||
| 23833 | } until (! @list); | ||
| 23834 | |||
| 23835 | # All specified patterns match their specified lines, so the test succeeds and the anchor | ||
| 23836 | # line can be used | ||
| 23837 | return 1; | ||
| 23838 | } | ||
| 23839 | |||
| 23840 | sub processAnchor { | ||
| 23841 | |||
| 23842 | # Called by $self->processLine (at stage 3) when an anchor line is found | ||
| 23843 | # The world profile contains a list of room statement components; this function splits the | ||
| 23844 | # list in two (either side of the 'anchor' component), and calls $self->extractComponents | ||
| 23845 | # to process each component in turn | ||
| 23846 | # | ||
| 23847 | # Expected arguments | ||
| 23848 | # $lineNum - The display buffer number of the anchor line | ||
| 23849 | # $worldObj - Shortcut to the current world profile object | ||
| 23850 | # $type - The anchor type 'verbose', 'short' for short verbose anchors, 'brief' or | ||
| 23851 | # 'basic' in basic mapping mode | ||
| 23852 | # - NB In 'basic' mapping mode, this function is still called with $type set | ||
| 23853 | # to 'verbose', 'short' or 'brief', if those room statement components | ||
| 23854 | # have been specified. If none are specified, or if some components are | ||
| 23855 | # specified but could not be extracted in earlier calls to this function, | ||
| 23856 | # only then is this function called with $type set to 'basic') | ||
| 23857 | # | ||
| 23858 | # Return values | ||
| 23859 | # 'undef' on improper arguments, or if the components of the room statement can't be | ||
| 23860 | # extracted | ||
| 23861 | # 1 otherwise | ||
| 23862 | |||
| 23863 | my ($self, $lineNum, $worldObj, $type, $check) = @_; | ||
| 23864 | |||
| 23865 | # Local variables | ||
| 23866 | my ( | ||
| 23867 | $anchorOffset, $anchorFlag, $roomObj, $result, $successFlag, $firstLineNum, | ||
| 23868 | $lastLineNum, $otherLineNum, $hashRef1, $hashRef2, | ||
| 23869 | @componentList, @beforeList, @afterList, | ||
| 23870 | %posnHash, %noExtractHash, %oldWeatherHash, | ||
| 23871 | ); | ||
| 23872 | |||
| 23873 | # Check for improper arguments | ||
| 23874 | if (! defined $lineNum || ! defined $worldObj || ! defined $type || defined $check) { | ||
| 23875 | |||
| 23876 | return $axmud::CLIENT->writeImproper($self->_objClass . '->processAnchor', @_); | ||
| 23877 | } | ||
| 23878 | |||
| 23879 | # Reset the list of lines to be converted to text-to-speech; this hash should only | ||
| 23880 | # contain the lines that we might want to read out | ||
| 23881 | $self->ivEmpty('ttsToReadHash'); | ||
| 23882 | |||
| 23883 | # Import the list of room statement components | ||
| 23884 | if ($type eq 'basic') { | ||
| 23885 | |||
| 23886 | # (@componentList is purposely empty, so this function will not attempt to extract any | ||
| 23887 | # components - see the comments at the top of this function) | ||
| 23888 | $anchorOffset = 0; # Anchor line doesn't share its line with any component | ||
| 23889 | |||
| 23890 | } else { | ||
| 23891 | |||
| 23892 | if ($type eq 'verbose') { | ||
| 23893 | |||
| 23894 | @componentList = $worldObj->verboseComponentList; | ||
| 23895 | $anchorOffset = $worldObj->verboseAnchorOffset; | ||
| 23896 | |||
| 23897 | } elsif ($type eq 'short') { | ||
| 23898 | |||
| 23899 | @componentList = $worldObj->shortComponentList; | ||
| 23900 | $anchorOffset = $worldObj->shortAnchorOffset; | ||
| 23901 | |||
| 23902 | } elsif ($type eq 'brief') { | ||
| 23903 | |||
| 23904 | @componentList = $worldObj->briefComponentList; | ||
| 23905 | $anchorOffset = $worldObj->briefAnchorOffset; | ||
| 23906 | } | ||
| 23907 | |||
| 23908 | # In basic mapping mode, while trying to extract room statement components, the offset | ||
| 23909 | # must be +1 (anchor line shares a line with the first line of the statement) | ||
| 23910 | if ($worldObj->basicMappingFlag) { | ||
| 23911 | |||
| 23912 | $anchorOffset = 1; | ||
| 23913 | } | ||
| 23914 | |||
| 23915 | if (! @componentList) { | ||
| 23916 | |||
| 23917 | # No components to extract (or invalid $type); so ignore this form of room statement | ||
| 23918 | return undef; | ||
| 23919 | } | ||
| 23920 | |||
| 23921 | # The component list consists of component names. Most of them are keys in | ||
| 23922 | # GA::Profile::World->componentHash, but the name 'anchor' is not | ||
| 23923 | # Divide the component list into two - all the components before the 'anchor' line (in | ||
| 23924 | # reverse order), and all the components after it | ||
| 23925 | foreach my $component (@componentList) { | ||
| 23926 | |||
| 23927 | if ($component eq 'anchor') { | ||
| 23928 | $anchorFlag = TRUE; | ||
| 23929 | } elsif ($anchorFlag) { | ||
| 23930 | push (@afterList, $component); | ||
| 23931 | } else { | ||
| 23932 | unshift (@beforeList, $component); | ||
| 23933 | } | ||
| 23934 | } | ||
| 23935 | |||
| 23936 | if (! $anchorFlag || (! @beforeList && ! @afterList)) { | ||
| 23937 | |||
| 23938 | # The one compulsory component, 'anchor', is missing from @componentList; or there | ||
| 23939 | # are no components beside the 'anchor' component. Can't continue | ||
| 23940 | return undef; | ||
| 23941 | } | ||
| 23942 | } | ||
| 23943 | |||
| 23944 | # In anticipation of a successful extraction, create a non-model object for this room | ||
| 23945 | $roomObj = Games::Axmud::ModelObj::Room->new( | ||
| 23946 | $self->session, | ||
| 23947 | 'temporary', | ||
| 23948 | 'non_model', | ||
| 23949 | ); | ||
| 23950 | |||
| 23951 | # $self->roomObj hasn't been set yet, but we still need to reset $self->weatherHash, as it's | ||
| 23952 | # about to be re-filled | ||
| 23953 | # Keep a copy of the existing contents, in case extraction fails (in which case we can | ||
| 23954 | # restore the existing contents) | ||
| 23955 | %oldWeatherHash = $self->weatherHash; | ||
| 23956 | $self->ivEmpty('weatherHash'); | ||
| 23957 | |||
| 23958 | # Extract the components that come before the anchor line (if any) | ||
| 23959 | if (@beforeList) { | ||
| 23960 | |||
| 23961 | # $self->extractComponents returns the first and last line of all the extracted | ||
| 23962 | # components, as well as the line numbers which comprise each component, stores as a | ||
| 23963 | # hash reference in the form | ||
| 23964 | # $posnHash{component_name} = reference_to_list_of_line_numbers | ||
| 23965 | ($successFlag, $firstLineNum, $otherLineNum, $hashRef1) = $self->extractComponents( | ||
| 23966 | $lineNum, | ||
| 23967 | $worldObj, | ||
| 23968 | $roomObj, | ||
| 23969 | $anchorOffset, | ||
| 23970 | -1, | ||
| 23971 | \%noExtractHash, | ||
| 23972 | @beforeList, | ||
| 23973 | ); | ||
| 23974 | |||
| 23975 | # Attempted to extract a non-optional component, but failed | ||
| 23976 | if (! $successFlag) { | ||
| 23977 | |||
| 23978 | $self->ivPoke('weatherHash', %oldWeatherHash); | ||
| 23979 | |||
| 23980 | return undef; | ||
| 23981 | |||
| 23982 | # If no components were extracted, because none were specified or because all | ||
| 23983 | # specified components were optional, and were not found, then $firstLineNum | ||
| 23984 | # won't be set | ||
| 23985 | } elsif (! defined $firstLineNum) { | ||
| 23986 | |||
| 23987 | # First line is the anchor line | ||
| 23988 | $firstLineNum = $lineNum; | ||
| 23989 | |||
| 23990 | # All components extracted successfully | ||
| 23991 | } else { | ||
| 23992 | |||
| 23993 | %posnHash = %$hashRef1; | ||
| 23994 | } | ||
| 23995 | |||
| 23996 | } else { | ||
| 23997 | |||
| 23998 | # First line is the anchor line | ||
| 23999 | $firstLineNum = $lineNum; | ||
| 24000 | } | ||
| 24001 | |||
| 24002 | # Extract the components that come after the anchor line (if any) | ||
| 24003 | if (@afterList) { | ||
| 24004 | |||
| 24005 | # The return values need to be combined with the values returned in the earlier call | ||
| 24006 | # to ->extractComponents | ||
| 24007 | ($successFlag, $otherLineNum, $lastLineNum, $hashRef2) = $self->extractComponents( | ||
| 24008 | $lineNum, | ||
| 24009 | $worldObj, | ||
| 24010 | $roomObj, | ||
| 24011 | $anchorOffset, | ||
| 24012 | 1, | ||
| 24013 | \%noExtractHash, | ||
| 24014 | @afterList, | ||
| 24015 | ); | ||
| 24016 | |||
| 24017 | # Attempted to extract a non-optional component, but failed | ||
| 24018 | if (! $successFlag) { | ||
| 24019 | |||
| 24020 | $self->ivPoke('weatherHash', %oldWeatherHash); | ||
| 24021 | |||
| 24022 | return undef; | ||
| 24023 | |||
| 24024 | # If no components were extracted, because none were specified or because all specified | ||
| 24025 | # components were optional, and were not found, then $otherLineNum won't be set | ||
| 24026 | } elsif (! defined $lastLineNum) { | ||
| 24027 | |||
| 24028 | # Last line is the anchor line | ||
| 24029 | $lastLineNum = $lineNum; | ||
| 24030 | |||
| 24031 | # All components extracted successfully | ||
| 24032 | } else { | ||
| 24033 | |||
| 24034 | # Combine this hash with the previous one, if there was one | ||
| 24035 | %posnHash = (%posnHash, %$hashRef2); | ||
| 24036 | } | ||
| 24037 | |||
| 24038 | } else { | ||
| 24039 | |||
| 24040 | # Last line is the anchor line | ||
| 24041 | $lastLineNum = $lineNum; | ||
| 24042 | } | ||
| 24043 | |||
| 24044 | # Extraction successful. Store the line at which this room statement ends (required by | ||
| 24045 | # $self->checkLineValid and others). | ||
| 24046 | # NB In basic mapping mode, if no room statement components have been specified (and | ||
| 24047 | # therefore $type = 'basic'), we'll assume that the first line processed after a movement | ||
| 24048 | # command is the first and last line of the room statement. Since we're not extracting | ||
| 24049 | # any components, we don't actually care where the statement starts or ends | ||
| 24050 | $self->ivPoke('lastStatementEndLine', $lastLineNum); | ||
| 24051 | # Nothing uses $firstLineNum at the moment, but we'll store it anyway | ||
| 24052 | $self->ivPoke('lastStatementStartLine', $firstLineNum); | ||
| 24053 | if ($axmud::CLIENT->debugLocatorFlag) { | ||
| 24054 | |||
| 24055 | $self->writeDebug( | ||
| 24056 | 'LOCATOR 511: Start of statement set to line #' . $self->lastStatementStartLine, | ||
| 24057 | ); | ||
| 24058 | |||
| 24059 | $self->writeDebug( | ||
| 24060 | 'LOCATOR 512: End of statement set to line #' . $self->lastStatementEndLine, | ||
| 24061 | ); | ||
| 24062 | } | ||
| 24063 | |||
| 24064 | # Archive the previous current room object (if there was one)... | ||
| 24065 | if ($self->roomObj) { | ||
| 24066 | |||
| 24067 | $self->ivPoke('prevRoomObj', $self->roomObj); | ||
| 24068 | } | ||
| 24069 | |||
| 24070 | # ...and store the new one | ||
| 24071 | $self->ivPoke('roomObj', $roomObj); | ||
| 24072 | |||
| 24073 | # Write details of the whole room statement to logfiles. (Unusual step - to save time, | ||
| 24074 | # check that this logfile is actually being written, before doing the messy business of | ||
| 24075 | # consulting the display buffer) | ||
| 24076 | # NB Obviously, don't bother in basic mapping mode, if no room statement components have | ||
| 24077 | # been specified ($type = 'basic') | ||
| 24078 | if ($type ne 'basic' && $worldObj->ivShow('logPrefHash', 'rooms')) { | ||
| 24079 | |||
| 24080 | for (my $thisLineNum = $firstLineNum; $thisLineNum <= $lastLineNum; $thisLineNum++) { | ||
| 24081 | |||
| 24082 | my $bufferObj = $self->session->ivShow('displayBufferHash', $thisLineNum); | ||
| 24083 | if ($bufferObj) { | ||
| 24084 | |||
| 24085 | $axmud::CLIENT->writeLog( | ||
| 24086 | $self->session, | ||
| 24087 | FALSE, # Not a 'standard' logfile | ||
| 24088 | $bufferObj->modLine, | ||
| 24089 | FALSE, # Don't precede with a newline character | ||
| 24090 | TRUE, # Use final newline character | ||
| 24091 | 'rooms', # Write to this logfile | ||
| 24092 | ); | ||
| 24093 | } | ||
| 24094 | } | ||
| 24095 | |||
| 24096 | # Add a blank line, so that the logfile isn't a wall of text | ||
| 24097 | $axmud::CLIENT->writeLog( | ||
| 24098 | $self->session, | ||
| 24099 | FALSE, # Not a 'standard' logfile | ||
| 24100 | '', | ||
| 24101 | FALSE, # Don't precede with a newline character | ||
| 24102 | TRUE, # Use final newline character | ||
| 24103 | 'rooms', # Write to this logfile | ||
| 24104 | ); | ||
| 24105 | } | ||
| 24106 | |||
| 24107 | # Write details of the verbose description to logfiles (if allowed, and if the verbose | ||
| 24108 | # statement was captured) | ||
| 24109 | foreach my $compName (keys %posnHash) { | ||
| 24110 | |||
| 24111 | my ($compObj, $listRef); | ||
| 24112 | |||
| 24113 | $compObj = $worldObj->ivShow('componentHash', $compName); | ||
| 24114 | $listRef = $posnHash{$compName}; | ||
| 24115 | |||
| 24116 | if ($compObj->type eq 'verb_descrip' && $worldObj->ivShow('logPrefHash', 'descrips')) { | ||
| 24117 | |||
| 24118 | foreach my $lineNum (@$listRef) { | ||
| 24119 | |||
| 24120 | my $bufferObj = $self->session->ivShow('displayBufferHash', $lineNum); | ||
| 24121 | if ($bufferObj) { | ||
| 24122 | |||
| 24123 | $axmud::CLIENT->writeLog( | ||
| 24124 | $self->session, | ||
| 24125 | FALSE, # Not a 'standard' logfile | ||
| 24126 | $bufferObj->modLine, | ||
| 24127 | FALSE, # Don't precede with a newline character | ||
| 24128 | TRUE, # Use final newline character | ||
| 24129 | 'descrips', # Write to this logfile | ||
| 24130 | ); | ||
| 24131 | } | ||
| 24132 | } | ||
| 24133 | |||
| 24134 | # Add a blank line, so that the logfile isn't a wall of text | ||
| 24135 | $axmud::CLIENT->writeLog( | ||
| 24136 | $self->session, | ||
| 24137 | FALSE, # Not a 'standard' logfile | ||
| 24138 | '', | ||
| 24139 | FALSE, # Don't precede with a newline character | ||
| 24140 | TRUE, # Use final newline character | ||
| 24141 | 'descrips', # Write to this logfile | ||
| 24142 | ); | ||
| 24143 | |||
| 24144 | } elsif ( | ||
| 24145 | ($compObj->type eq 'verb_content' || $compObj->type eq 'brief_content') | ||
| 24146 | && $worldObj->ivShow('logPrefHash', 'contents') | ||
| 24147 | ) { | ||
| 24148 | foreach my $lineNum (@$listRef) { | ||
| 24149 | |||
| 24150 | my $bufferObj = $self->session->ivShow('displayBufferHash', $lineNum); | ||
| 24151 | if ($bufferObj) { | ||
| 24152 | |||
| 24153 | $axmud::CLIENT->writeLog( | ||
| 24154 | $self->session, | ||
| 24155 | FALSE, # Not a 'standard' logfile | ||
| 24156 | $bufferObj->modLine, | ||
| 24157 | FALSE, # Don't precede with a newline character | ||
| 24158 | TRUE, # Use final newline character | ||
| 24159 | 'contents', # Write to this logfile | ||
| 24160 | ); | ||
| 24161 | } | ||
| 24162 | } | ||
| 24163 | |||
| 24164 | # Add a blank line, so that the logfile isn't a wall of text | ||
| 24165 | $axmud::CLIENT->writeLog( | ||
| 24166 | $self->session, | ||
| 24167 | FALSE, # Not a 'standard' logfile | ||
| 24168 | '', | ||
| 24169 | FALSE, # Don't precede with a newline character | ||
| 24170 | TRUE, # Use final newline character | ||
| 24171 | 'contents', # Write to this logfile | ||
| 24172 | ); | ||
| 24173 | } | ||
| 24174 | } | ||
| 24175 | |||
| 24176 | # Do text-to-speech, if required | ||
| 24177 | if ( | ||
| 24178 | $self->ivShow('ttsFlagAttribHash', 'title') | ||
| 24179 | && $self->ivShow('ttsToReadHash', 'title') | ||
| 24180 | ) { | ||
| 24181 | $self->ttsQuick($self->ivShow('ttsToReadHash', 'title')); | ||
| 24182 | } | ||
| 24183 | |||
| 24184 | if ( | ||
| 24185 | ( | ||
| 24186 | $self->ivShow('ttsFlagAttribHash', 'descrip') | ||
| 24187 | || $self->ivShow('ttsFlagAttribHash', 'description') | ||
| 24188 | ) && $self->ivShow('ttsToReadHash', 'descrip') | ||
| 24189 | ) { | ||
| 24190 | $self->ttsQuick($self->ivShow('ttsToReadHash', 'descrip')); | ||
| 24191 | } | ||
| 24192 | |||
| 24193 | if ( | ||
| 24194 | ( | ||
| 24195 | $self->ivShow('ttsFlagAttribHash', 'exit') | ||
| 24196 | || $self->ivShow('ttsFlagAttribHash', 'exits') | ||
| 24197 | ) && $self->ivShow('ttsToReadHash', 'exit') | ||
| 24198 | ) { | ||
| 24199 | $self->ttsQuick($self->ivShow('ttsToReadHash', 'exit')); | ||
| 24200 | } | ||
| 24201 | |||
| 24202 | if ( | ||
| 24203 | ( | ||
| 24204 | $self->ivShow('ttsFlagAttribHash', 'content') | ||
| 24205 | || $self->ivShow('ttsFlagAttribHash', 'contents') | ||
| 24206 | ) && $self->ivShow('ttsToReadHash', 'content') | ||
| 24207 | ) { | ||
| 24208 | $self->ttsQuick($self->ivShow('ttsToReadHash', 'content')); | ||
| 24209 | } | ||
| 24210 | |||
| 24211 | if ( | ||
| 24212 | ( | ||
| 24213 | $self->ivShow('ttsFlagAttribHash', 'command') | ||
| 24214 | || $self->ivShow('ttsFlagAttribHash', 'cmd') | ||
| 24215 | ) && $self->ivShow('ttsToReadHash', 'command') | ||
| 24216 | ) { | ||
| 24217 | $self->ttsQuick($self->ivShow('ttsToReadHash', 'command')); | ||
| 24218 | } | ||
| 24219 | |||
| 24220 | # Anchor line processing complete | ||
| 24221 | return 1; | ||
| 24222 | } | ||
| 24223 | |||
| 24224 | sub extractComponents { | ||
| 24225 | |||
| 24226 | # Called by $self->processAnchor (at stage 3) with a list of room statement components | ||
| 24227 | # that occur either before, or after, the anchor line | ||
| 24228 | # Processes each component in turn | ||
| 24229 | # | ||
| 24230 | # Expected arguments | ||
| 24231 | # $lineNum - The display buffer number of the anchor line | ||
| 24232 | # $worldObj - Shortcut to the current world profile object | ||
| 24233 | # $roomObj - A non-model room object in which we store information gathered from | ||
| 24234 | # each successfully-extracted component | ||
| 24235 | # $anchorOffset - The anchor line's relationship with other components in the component | ||
| 24236 | # list: -1 if the anchor line shares a line with the component before | ||
| 24237 | # it; +1 if the anchor line shares a line with the component after it; | ||
| 24238 | # 0 if the anchor line does not share its line with any component | ||
| 24239 | # $step - The direction in which to move through the display buffer: 1 to move | ||
| 24240 | # forwards (for components that appear after the anchor line), -1 to | ||
| 24241 | # move backwards (for components that appear before the anchor line) | ||
| 24242 | # $noExtractHashRef | ||
| 24243 | # - Hash of room components which should NOT be extracted, because a | ||
| 24244 | # previous component has already been successfully extracted. Hash | ||
| 24245 | # reference in the form | ||
| 24246 | # $$noExtractHashRef{component_name} = previous_component_name; | ||
| 24247 | # | ||
| 24248 | # Optional arguments | ||
| 24249 | # @componentList - A list of component names (keys in GA::Profile::World->componentHash) | ||
| 24250 | # in the order in which they appear in the room statement. If there | ||
| 24251 | # are no components before (or after) the anchor line, will be an | ||
| 24252 | # empty list | ||
| 24253 | # | ||
| 24254 | # Return values | ||
| 24255 | # An empty list on improper arguments | ||
| 24256 | # An empty list if any of the non-optional components in @componentList can't be extracted | ||
| 24257 | # (including when a component with exits contains a recognised non-delimiter) | ||
| 24258 | # If no components are extracted (because none were specified, or because only optional | ||
| 24259 | # components are specified, and none of them are found), returns a list in the form | ||
| 24260 | # (success_flag) | ||
| 24261 | # If at least one component is extracted, returns a list in the form | ||
| 24262 | # ( | ||
| 24263 | # success_flag, first_line_of_first_component, last_line_of_last_component, | ||
| 24264 | # hash_reference, | ||
| 24265 | # ) | ||
| 24266 | # ...where 'hash_reference' is a reference to a hash in the form | ||
| 24267 | # $posnHash{component_name} = reference_to_list_of_line_numbers | ||
| 24268 | |||
| 24269 | my ( | ||
| 24270 | $self, $lineNum, $worldObj, $roomObj, $anchorOffset, $step, $noExtractHashRef, | ||
| 24271 | @componentList, | ||
| 24272 | ) = @_; | ||
| 24273 | |||
| 24274 | # Local variables | ||
| 24275 | my ( | ||
| 24276 | $nextLineNum, $firstLineNum, $lastLineNum, | ||
| 24277 | @emptyList, | ||
| 24278 | %componentHash, %posnHash, %noExtractHash, | ||
| 24279 | ); | ||
| 24280 | |||
| 24281 | # Check for improper arguments | ||
| 24282 | if ( | ||
| 24283 | ! defined $lineNum || ! defined $worldObj || ! defined $roomObj | ||
| 24284 | || ! defined $anchorOffset || ! defined $step || ! defined $noExtractHashRef | ||
| 24285 | ) { | ||
| 24286 | $axmud::CLIENT->writeImproper($self->_objClass . '->extractComponents', @_); | ||
| 24287 | return @emptyList; | ||
| 24288 | } | ||
| 24289 | |||
| 24290 | if (! @componentList) { | ||
| 24291 | |||
| 24292 | # No components extracted, because none were specified. The TRUE value means that we | ||
| 24293 | # didn't encounter an error | ||
| 24294 | return TRUE; | ||
| 24295 | } | ||
| 24296 | |||
| 24297 | # Import the world profile's component hash (for quick lookup) | ||
| 24298 | %componentHash = $worldObj->componentHash; | ||
| 24299 | |||
| 24300 | # Cycle through components until we have processed all components in @componentList, or | ||
| 24301 | # until we run out of lines, or until a non-optional component can't be extracted | ||
| 24302 | do { | ||
| 24303 | |||
| 24304 | my ( | ||
| 24305 | $component, $componentObj, $newLineNum, $type, $result, | ||
| 24306 | @lineNumList, @bufferObjList, @lineTextList, @lineOffsetList, | ||
| 24307 | %emptyHash, | ||
| 24308 | ); | ||
| 24309 | |||
| 24310 | # Next component to extract | ||
| 24311 | $component = shift @componentList; | ||
| 24312 | # Get the component object, which tells us how to extract all the display buffer lines | ||
| 24313 | # for this component | ||
| 24314 | $componentObj = $componentHash{$component}; | ||
| 24315 | |||
| 24316 | if (! $componentObj) { | ||
| 24317 | |||
| 24318 | if ($axmud::CLIENT->debugLocatorFlag) { | ||
| 24319 | |||
| 24320 | $self->writeDebug( | ||
| 24321 | 'LOCATOR 551: Component object \'' . $component . '\' not found', | ||
| 24322 | ); | ||
| 24323 | } | ||
| 24324 | |||
| 24325 | } elsif ( | ||
| 24326 | exists $$noExtractHashRef{$component} | ||
| 24327 | || exists $$noExtractHashRef{$componentObj->type} | ||
| 24328 | ) { | ||
| 24329 | # A previously-extracted component specifies that this component must not be | ||
| 24330 | # extracted | ||
| 24331 | |||
| 24332 | if ($axmud::CLIENT->debugLocatorFlag) { | ||
| 24333 | |||
| 24334 | $self->writeDebug( | ||
| 24335 | 'LOCATOR 552: Component object \'' . $component . '\' not extracted, as a' | ||
| 24336 | . ' previously-extracted component (\'' . $$noExtractHashRef{$component} | ||
| 24337 | . '\') forbids it', | ||
| 24338 | ); | ||
| 24339 | } | ||
| 24340 | |||
| 24341 | } else { | ||
| 24342 | |||
| 24343 | if ($axmud::CLIENT->debugLocatorFlag) { | ||
| 24344 | |||
| 24345 | $self->writeDebug( | ||
| 24346 | 'LOCATOR 553: Processing component \'' . $component . '\' (type \'' | ||
| 24347 | . $componentObj->type . '\')', | ||
| 24348 | ); | ||
| 24349 | } | ||
| 24350 | |||
| 24351 | # If this is the first component to be extracted, decide whether the component's | ||
| 24352 | # first line is on the anchor line, or whether it is immediately before/after it | ||
| 24353 | if (! defined $nextLineNum) { | ||
| 24354 | |||
| 24355 | if ( | ||
| 24356 | ($anchorOffset == 1 && $step == 1) | ||
| 24357 | || ($anchorOffset == -1 && $step == -1) | ||
| 24358 | ) { | ||
| 24359 | # Anchor line shares a line with the first component in @componentList | ||
| 24360 | $nextLineNum = $lineNum; | ||
| 24361 | |||
| 24362 | } else { | ||
| 24363 | |||
| 24364 | # Anchor line is before/after the first component | ||
| 24365 | $nextLineNum = $lineNum + $step; | ||
| 24366 | } | ||
| 24367 | } | ||
| 24368 | |||
| 24369 | # Extract the lines for this component | ||
| 24370 | ($newLineNum, @lineNumList) = $self->extractLines( | ||
| 24371 | $worldObj, | ||
| 24372 | $componentObj, | ||
| 24373 | $nextLineNum, | ||
| 24374 | $step, | ||
| 24375 | ); | ||
| 24376 | |||
| 24377 | if ($axmud::CLIENT->debugLocatorFlag) { | ||
| 24378 | |||
| 24379 | if (! @lineNumList) { | ||
| 24380 | |||
| 24381 | $self->writeDebug('LOCATOR 554: Extracted lines: 0'); | ||
| 24382 | |||
| 24383 | } else { | ||
| 24384 | |||
| 24385 | $self->writeDebug( | ||
| 24386 | 'LOCATOR 555: Extracted lines: ' . scalar @lineNumList . ': ' | ||
| 24387 | . join(' ', @lineNumList), | ||
| 24388 | ); | ||
| 24389 | } | ||
| 24390 | } | ||
| 24391 | |||
| 24392 | if (! @lineNumList && $componentObj->minSize) { | ||
| 24393 | |||
| 24394 | # Failed to extract a component that is not optional | ||
| 24395 | if ($axmud::CLIENT->debugLocatorFlag) { | ||
| 24396 | |||
| 24397 | $self->writeDebug( | ||
| 24398 | 'LOCATOR 561: Failed to extract a non-optional component', | ||
| 24399 | ); | ||
| 24400 | } | ||
| 24401 | |||
| 24402 | return @emptyList; | ||
| 24403 | |||
| 24404 | } elsif (! defined $newLineNum && @componentList) { | ||
| 24405 | |||
| 24406 | # Run out of lines before extracting all components. If any of them are not | ||
| 24407 | # optional, we have to give up | ||
| 24408 | foreach my $name (@componentList) { | ||
| 24409 | |||
| 24410 | my $obj = $componentHash{$name}; | ||
| 24411 | if ($obj && $obj->minSize) { | ||
| 24412 | |||
| 24413 | if ($axmud::CLIENT->debugLocatorFlag) { | ||
| 24414 | |||
| 24415 | $self->writeDebug( | ||
| 24416 | 'LOCATOR 562: Ran out of lines before extracting all non-' | ||
| 24417 | . 'OPTIONAL components', | ||
| 24418 | ); | ||
| 24419 | } | ||
| 24420 | |||
| 24421 | return @emptyList; | ||
| 24422 | } | ||
| 24423 | } | ||
| 24424 | |||
| 24425 | } else { | ||
| 24426 | |||
| 24427 | # Start looking for the next component on $newLineNum. If the call to | ||
| 24428 | # $self->extractLines failed, $newLineNum will be 'undef' | ||
| 24429 | $nextLineNum = $newLineNum; | ||
| 24430 | |||
| 24431 | if ($axmud::CLIENT->debugLocatorFlag) { | ||
| 24432 | |||
| 24433 | if ($nextLineNum) { | ||
| 24434 | |||
| 24435 | $self->writeDebug( | ||
| 24436 | 'LOCATOR 563: Next line to check: #' . $nextLineNum, | ||
| 24437 | ); | ||
| 24438 | |||
| 24439 | } elsif (! defined $nextLineNum) { | ||
| 24440 | |||
| 24441 | $self->writeDebug( | ||
| 24442 | 'LOCATOR 564: Next line to check: (not received yet)', | ||
| 24443 | ); | ||
| 24444 | |||
| 24445 | } else { | ||
| 24446 | |||
| 24447 | $self->writeDebug( | ||
| 24448 | 'LOCATOR 565: Next line to check: (reached top of buffer)', | ||
| 24449 | ); | ||
| 24450 | } | ||
| 24451 | } | ||
| 24452 | } | ||
| 24453 | |||
| 24454 | # Process the lines in @lineList (if any), updating the room model object, $roomObj | ||
| 24455 | if (@lineNumList) { | ||
| 24456 | |||
| 24457 | # Temporarily store the first line of the first component, and the last line of | ||
| 24458 | # the last component (for log-writing purposes), and the position of the | ||
| 24459 | # component | ||
| 24460 | if (! defined $firstLineNum || $lineNumList[0] < $firstLineNum) { | ||
| 24461 | |||
| 24462 | $firstLineNum = $lineNumList[0]; | ||
| 24463 | } | ||
| 24464 | |||
| 24465 | if (! defined $lastLineNum || $lineNumList[-1] > $lastLineNum) { | ||
| 24466 | |||
| 24467 | $lastLineNum = $lineNumList[-1]; | ||
| 24468 | } | ||
| 24469 | |||
| 24470 | $posnHash{$componentObj->name} = \@lineNumList; | ||
| 24471 | |||
| 24472 | # If we're searching backwards, reverse the order of the line numbers in | ||
| 24473 | # @lineNumList, so that they appear in the same order they were sent | ||
| 24474 | if ($step == -1) { | ||
| 24475 | |||
| 24476 | @lineNumList = reverse (@lineNumList); | ||
| 24477 | } | ||
| 24478 | |||
| 24479 | # Convert the list of display buffer line numbers into a list of display buffer | ||
| 24480 | # objects (@bufferObjList, a list of Axmud colour/style tags and the offsets | ||
| 24481 | # at which they occur (@lineOffsetList), and a list of display buffer objects | ||
| 24482 | # (@bufferObjList); | ||
| 24483 | foreach my $lineNum (@lineNumList) { | ||
| 24484 | |||
| 24485 | my ( | ||
| 24486 | $bufferObj, $modText, | ||
| 24487 | %modOffsetHash, %offsetHash, | ||
| 24488 | ); | ||
| 24489 | |||
| 24490 | $bufferObj = $self->session->ivShow('displayBufferHash', $lineNum); | ||
| 24491 | if ($bufferObj) { | ||
| 24492 | |||
| 24493 | if ($componentObj->useTextColour) { | ||
| 24494 | |||
| 24495 | ($modText, %modOffsetHash) | ||
| 24496 | = $self->trimColouredText($bufferObj, $componentObj); | ||
| 24497 | |||
| 24498 | if (defined $modText) { | ||
| 24499 | |||
| 24500 | push (@bufferObjList, $bufferObj); | ||
| 24501 | push (@lineTextList, $modText); | ||
| 24502 | push (@lineOffsetList, \%modOffsetHash); | ||
| 24503 | } | ||
| 24504 | |||
| 24505 | } else { | ||
| 24506 | |||
| 24507 | push (@bufferObjList, $bufferObj); | ||
| 24508 | push (@lineTextList, $bufferObj->modLine); | ||
| 24509 | |||
| 24510 | # (Don't want anything to modify the buffer object's offset hash, so | ||
| 24511 | # dereference then reference the hash) | ||
| 24512 | %offsetHash = $bufferObj->offsetHash; | ||
| 24513 | push (@lineOffsetList, \%offsetHash); | ||
| 24514 | } | ||
| 24515 | } | ||
| 24516 | } | ||
| 24517 | |||
| 24518 | # If none of the lines contained text of the right colour (where applicable), | ||
| 24519 | # treat the component as if it contained no text | ||
| 24520 | if (! @lineTextList) { | ||
| 24521 | |||
| 24522 | push (@bufferObjList, undef); | ||
| 24523 | push (@lineTextList, ''); | ||
| 24524 | push (@lineOffsetList, \%emptyHash); | ||
| 24525 | |||
| 24526 | # Treat the lines as a single line, if the component's flag is set | ||
| 24527 | } elsif (@lineTextList > 1 && $componentObj->combineLinesFlag) { | ||
| 24528 | |||
| 24529 | $self->combineLines(\@lineTextList, \@lineOffsetList); | ||
| 24530 | # The buffer object is required for its ->previousTagList IV, so we can | ||
| 24531 | # simply return the first buffer object | ||
| 24532 | @bufferObjList = ($bufferObjList[0]); | ||
| 24533 | } | ||
| 24534 | |||
| 24535 | # Ignore the first n characters of the line, if the component's IV is set (but | ||
| 24536 | # not if ->useTextColour is set) | ||
| 24537 | if (! $componentObj->useTextColour && $componentObj->ignoreFirstChars) { | ||
| 24538 | |||
| 24539 | $self->reduceLineFromStart( | ||
| 24540 | \@lineTextList, | ||
| 24541 | \@lineOffsetList, | ||
| 24542 | $componentObj->ignoreFirstChars, | ||
| 24543 | ); | ||
| 24544 | } | ||
| 24545 | |||
| 24546 | # Use only the first n characters of the line, if the component's IV is set (but | ||
| 24547 | # not if ->useTextColour or ->ignoreFirstChars is set) | ||
| 24548 | if ( | ||
| 24549 | ! $componentObj->useTextColour | ||
| 24550 | && ! $componentObj->ignoreFirstChars | ||
| 24551 | && $componentObj->useFirstChars | ||
| 24552 | ) { | ||
| 24553 | $self->reduceLineFromEnd( | ||
| 24554 | \@lineTextList, | ||
| 24555 | \@lineOffsetList, | ||
| 24556 | $componentObj->useFirstChars, | ||
| 24557 | ); | ||
| 24558 | } | ||
| 24559 | |||
| 24560 | # Use only the group substrings from a matching pattern, if the component's IV | ||
| 24561 | # is set and its regex matches the line (but not if ->useTextColour, | ||
| 24562 | # ->ignoreFirstChars or ->useFirstChars are set) | ||
| 24563 | if ( | ||
| 24564 | ! $componentObj->useTextColour | ||
| 24565 | && ! $componentObj->ignoreFirstChars | ||
| 24566 | && ! $componentObj->useFirstChars | ||
| 24567 | && $componentObj->usePatternGroups | ||
| 24568 | ) { | ||
| 24569 | $self->reduceLineUsingRegex( | ||
| 24570 | \@lineTextList, | ||
| 24571 | \@lineOffsetList, | ||
| 24572 | $componentObj->usePatternGroups, | ||
| 24573 | ); | ||
| 24574 | } | ||
| 24575 | |||
| 24576 | # Process the lines. The functions which process exit lines will return 'undef' | ||
| 24577 | # if the line(s) contain non-delimiters; all the functions will return 'undef' | ||
| 24578 | # on improper arguments | ||
| 24579 | $type = $componentObj->type; | ||
| 24580 | if ($type eq 'verb_title' || $type eq 'brief_title') { | ||
| 24581 | |||
| 24582 | $result = $self->setRoomTitle($roomObj, @lineTextList); | ||
| 24583 | |||
| 24584 | } elsif ($type eq 'verb_descrip') { | ||
| 24585 | |||
| 24586 | $result = $self->setRoomDescrip($roomObj, @lineTextList); | ||
| 24587 | |||
| 24588 | } elsif ($type eq 'verb_exit') { | ||
| 24589 | |||
| 24590 | $result = $self->setRoomExit( | ||
| 24591 | $worldObj, | ||
| 24592 | $roomObj, | ||
| 24593 | 'verbose', | ||
| 24594 | \@bufferObjList, | ||
| 24595 | \@lineTextList, | ||
| 24596 | \@lineOffsetList, | ||
| 24597 | ); | ||
| 24598 | |||
| 24599 | } elsif ($type eq 'verb_content' || $type eq 'brief_content') { | ||
| 24600 | |||
| 24601 | $result = $self->setRoomContent($roomObj, @lineTextList); | ||
| 24602 | |||
| 24603 | } elsif ($type eq 'verb_special') { | ||
| 24604 | |||
| 24605 | $result = $self->setRoomVerbSpecial($worldObj, $roomObj, @lineTextList); | ||
| 24606 | |||
| 24607 | } elsif ($type eq 'brief_exit') { | ||
| 24608 | |||
| 24609 | $result = $self->setRoomExit( | ||
| 24610 | $worldObj, | ||
| 24611 | $roomObj, | ||
| 24612 | 'brief', | ||
| 24613 | \@bufferObjList, | ||
| 24614 | \@lineTextList, | ||
| 24615 | \@lineOffsetList, | ||
| 24616 | ); | ||
| 24617 | |||
| 24618 | } elsif ($type eq 'brief_title_exit') { | ||
| 24619 | |||
| 24620 | $result = $self->setRoomTitleExit( | ||
| 24621 | $worldObj, | ||
| 24622 | $roomObj, | ||
| 24623 | TRUE, | ||
| 24624 | \@bufferObjList, | ||
| 24625 | \@lineTextList, | ||
| 24626 | \@lineOffsetList, | ||
| 24627 | ); | ||
| 24628 | |||
| 24629 | } elsif ($type eq 'brief_exit_title') { | ||
| 24630 | |||
| 24631 | $result = $self->setRoomTitleExit( | ||
| 24632 | $worldObj, | ||
| 24633 | $roomObj, | ||
| 24634 | FALSE, | ||
| 24635 | \@bufferObjList, | ||
| 24636 | \@lineTextList, | ||
| 24637 | \@lineOffsetList, | ||
| 24638 | ); | ||
| 24639 | |||
| 24640 | } elsif ($type eq 'room_cmd') { | ||
| 24641 | |||
| 24642 | $result = $self->setRoomCmd($worldObj, $roomObj, @lineTextList); | ||
| 24643 | |||
| 24644 | } elsif ($type eq 'mudlib_path') { | ||
| 24645 | |||
| 24646 | $result = $self->setRoomMudlibPath($roomObj, @lineTextList); | ||
| 24647 | |||
| 24648 | } elsif ($type eq 'weather') { | ||
| 24649 | |||
| 24650 | $result = $self->setRoomWeather($componentObj, @lineTextList); | ||
| 24651 | |||
| 24652 | } elsif ($type eq 'anchor' || $type eq 'ignore_line' || $type eq 'custom') { | ||
| 24653 | |||
| 24654 | # These components don't have a function, so there is no error flag to set | ||
| 24655 | $result = TRUE; | ||
| 24656 | } | ||
| 24657 | |||
| 24658 | if (! $result) { | ||
| 24659 | |||
| 24660 | if ($axmud::CLIENT->debugLocatorFlag) { | ||
| 24661 | |||
| 24662 | $self->writeDebug( | ||
| 24663 | 'LOCATOR 571: Unable to set up the \'' . $componentObj->name | ||
| 24664 | . '\' component', | ||
| 24665 | ); | ||
| 24666 | } | ||
| 24667 | |||
| 24668 | return @emptyList; | ||
| 24669 | } | ||
| 24670 | |||
| 24671 | # Component extracted. If it specifies any other components which shouldn't now | ||
| 24672 | # be extracted, add them to our hash | ||
| 24673 | foreach my $otherComponent ($componentObj->noExtractList) { | ||
| 24674 | |||
| 24675 | $$noExtractHashRef{$otherComponent} = $component; | ||
| 24676 | } | ||
| 24677 | } | ||
| 24678 | } | ||
| 24679 | |||
| 24680 | # (@componentList is empty if we have processed all components; $nextLineNum is undefined | ||
| 24681 | # if we have run out of lines) | ||
| 24682 | } until (! @componentList || ! defined $nextLineNum); | ||
| 24683 | |||
| 24684 | if ($firstLineNum) { | ||
| 24685 | |||
| 24686 | # All components extracted. For log-writing purposes, return the boundaries of the | ||
| 24687 | # room statement and the positions of each extracted component | ||
| 24688 | return (TRUE, $firstLineNum, $lastLineNum, \%posnHash); | ||
| 24689 | |||
| 24690 | } else { | ||
| 24691 | |||
| 24692 | # No components extracted, but all specified components were optional. The TRUE value | ||
| 24693 | # means we didn't encounter an error | ||
| 24694 | return TRUE; | ||
| 24695 | } | ||
| 24696 | } | ||
| 24697 | |||
| 24698 | sub extractLines { | ||
| 24699 | |||
| 24700 | # Called by $self->extractComponents (at stage 3) to extract a single room statement | ||
| 24701 | # component, consisting of 1 or more lines from the display buffer | ||
| 24702 | # The specified GA::Obj::Component tells us how many lines to extract | ||
| 24703 | # | ||
| 24704 | # Expected arguments | ||
| 24705 | # $worldObj - The current world profile | ||
| 24706 | # $componentObj - The GA::Obj::Component that tells us how many lines to extract | ||
| 24707 | # $firstLineNum - The number of the first display buffer line to check | ||
| 24708 | # $step - The direction in which to check lines: -1 to move backwards through | ||
| 24709 | # the display buffer, 1 to move forwards | ||
| 24710 | # | ||
| 24711 | # Return values | ||
| 24712 | # An empty list on improper arguments or if we run out lines while extracting valid lines | ||
| 24713 | # Otherwise, a list in the form | ||
| 24714 | # (next_line, line_list) | ||
| 24715 | # ...where: | ||
| 24716 | # 'next_line' - The next line in the display buffer after (or before) this component, | ||
| 24717 | # which should be checked by the next call to ->extractLines (set to | ||
| 24718 | # 'undef' if we run out of lines) | ||
| 24719 | # 'line_list' - A list of display buffer line numbers in the order in which they were | ||
| 24720 | # received from the world, regardless of $step (earliest line first). | ||
| 24721 | # If the component can't be extracted, an empty list | ||
| 24722 | |||
| 24723 | my ($self, $worldObj, $componentObj, $firstLineNum, $step, $check) = @_; | ||
| 24724 | |||
| 24725 | # Local variables | ||
| 24726 | my ( | ||
| 24727 | $firstLineText, $firstLineObj, $thisLineNum, $thisLineText, | ||
| 24728 | @emptyList, @lineList, @resultList, | ||
| 24729 | ); | ||
| 24730 | |||
| 24731 | # Check for improper arguments | ||
| 24732 | if ( | ||
| 24733 | ! defined $worldObj || ! defined $componentObj || ! defined $firstLineNum | ||
| 24734 | || ! defined $step || defined $check | ||
| 24735 | ) { | ||
| 24736 | $axmud::CLIENT->writeImproper($self->_objClass . '->extractLines', @_); | ||
| 24737 | return @emptyList; | ||
| 24738 | } | ||
| 24739 | |||
| 24740 | # Check that the buffer line $firstLineNum actually exists, and that it hasn't already been | ||
| 24741 | # checked by this task | ||
| 24742 | ($firstLineText, $firstLineObj) = $self->checkLineValid($firstLineNum); | ||
| 24743 | if (! defined $firstLineText) { | ||
| 24744 | |||
| 24745 | if ($axmud::CLIENT->debugLocatorFlag) { | ||
| 24746 | |||
| 24747 | $self->writeDebug( | ||
| 24748 | 'LOCATOR 601: Component \'' . $componentObj->name . '\' not found: first line' | ||
| 24749 | . ' not valid', | ||
| 24750 | ); | ||
| 24751 | } | ||
| 24752 | |||
| 24753 | return @emptyList; | ||
| 24754 | } | ||
| 24755 | |||
| 24756 | # Part 1 - fixed size | ||
| 24757 | # ------------------- | ||
| 24758 | |||
| 24759 | # If the ->size IV is a positive integer, our task is easy - we just return a fixed | ||
| 24760 | # number of lines | ||
| 24761 | if ($componentObj->size) { | ||
| 24762 | |||
| 24763 | # (Set a variable containing a hypothetical previous line, so that we can use simple | ||
| 24764 | # 'for' loops) | ||
| 24765 | $thisLineNum = $firstLineNum - $step; | ||
| 24766 | |||
| 24767 | OUTER: for (my $count = 1; $count <= $componentObj->size; $count++) { | ||
| 24768 | |||
| 24769 | $thisLineNum += $step; | ||
| 24770 | if (! $self->checkLineValid($thisLineNum)) { | ||
| 24771 | |||
| 24772 | # We have run out of lines, so the component is not found (return $firstLineNum | ||
| 24773 | # so that the next component to be extracted, if any, starts on the same line | ||
| 24774 | # as this one) | ||
| 24775 | if ($axmud::CLIENT->debugLocatorFlag) { | ||
| 24776 | |||
| 24777 | $self->writeDebug( | ||
| 24778 | 'LOCATOR 611: Component \'' . $componentObj->name . '\' not found: ran' | ||
| 24779 | . ' out of lines (->extractLines part 1)', | ||
| 24780 | ); | ||
| 24781 | } | ||
| 24782 | |||
| 24783 | return $firstLineNum; | ||
| 24784 | |||
| 24785 | } else { | ||
| 24786 | |||
| 24787 | push (@lineList, $thisLineNum); | ||
| 24788 | } | ||
| 24789 | } | ||
| 24790 | |||
| 24791 | # The next line to check is the line before/after this one | ||
| 24792 | $thisLineNum += $step; | ||
| 24793 | # Return the list of lines comprising this component. | ||
| 24794 | return ($thisLineNum, @lineList); | ||
| 24795 | } | ||
| 24796 | |||
| 24797 | # Part 2 - special contents | ||
| 24798 | # ------------------------- | ||
| 24799 | |||
| 24800 | # For 'verb_special' components, our task is easy - check every line until we find one which | ||
| 24801 | # doesn't contain one of the special patterns | ||
| 24802 | if ($componentObj->type eq 'verb_special') { | ||
| 24803 | |||
| 24804 | # (Set a variable containing a hypothetical previous line, so that we can use simple | ||
| 24805 | # 'for' loops) | ||
| 24806 | $thisLineNum = $firstLineNum - $step; | ||
| 24807 | |||
| 24808 | OUTER: for (my $count = 1; $count >= $componentObj->size; $count++) { | ||
| 24809 | |||
| 24810 | $thisLineNum += $step; | ||
| 24811 | ($thisLineText) = $self->checkLineValid($thisLineNum); | ||
| 24812 | if (! defined $thisLineText) { | ||
| 24813 | |||
| 24814 | # We have run out of lines, so returning all matching lines so far (if any) | ||
| 24815 | push (@lineList, $thisLineNum); | ||
| 24816 | |||
| 24817 | } else { | ||
| 24818 | |||
| 24819 | INNER: foreach my $pattern ($worldObj->ivKeys('specialPatternHash')) { | ||
| 24820 | |||
| 24821 | if ($thisLineText =~ m/$pattern/) { | ||
| 24822 | |||
| 24823 | # Use this line | ||
| 24824 | push (@lineList, $thisLineNum); | ||
| 24825 | next OUTER; | ||
| 24826 | } | ||
| 24827 | } | ||
| 24828 | |||
| 24829 | # No special patterns matched; end the search here. The next component starts | ||
| 24830 | # searching on $thisLineNum | ||
| 24831 | if ($axmud::CLIENT->debugLocatorFlag) { | ||
| 24832 | |||
| 24833 | $self->writeDebug( | ||
| 24834 | 'LOCATOR 621: Component \'' . $componentObj->name . '\' not found: no' | ||
| 24835 | . ' special patterns matched (->extractLines part 2)', | ||
| 24836 | ); | ||
| 24837 | } | ||
| 24838 | |||
| 24839 | return ($thisLineNum, @lineList); | ||
| 24840 | } | ||
| 24841 | } | ||
| 24842 | |||
| 24843 | # The next line to check is the line before/after this one | ||
| 24844 | $thisLineNum += $step; | ||
| 24845 | # Return the list of lines comprising this component. | ||
| 24846 | return ($thisLineNum, @lineList); | ||
| 24847 | } | ||
| 24848 | |||
| 24849 | # Part 3 - start patterns/tags | ||
| 24850 | # ---------------------------- | ||
| 24851 | |||
| 24852 | # ->startPatternList contains patterns matching the first buffer line | ||
| 24853 | # ->startTagList contains tags found in the first buffer line | ||
| 24854 | # ->startTagMode can specify that the line should contain no colour/style tags | ||
| 24855 | if ( | ||
| 24856 | $componentObj->startPatternList | ||
| 24857 | || $componentObj->startTagList | ||
| 24858 | || $componentObj->startTagMode ne 'default' | ||
| 24859 | ) { | ||
| 24860 | if ( | ||
| 24861 | ! $self->testLine( | ||
| 24862 | $firstLineText, | ||
| 24863 | $firstLineObj, | ||
| 24864 | $componentObj, | ||
| 24865 | 'startPatternList', | ||
| 24866 | 'startTagList', | ||
| 24867 | 'startAllFlag', | ||
| 24868 | 'startTagMode', | ||
| 24869 | ) | ||
| 24870 | ) { | ||
| 24871 | # Can't extract the component. Return $firstLineNum so that the next component to be | ||
| 24872 | # extracted, if any, starts on the same line as this one) | ||
| 24873 | if ($axmud::CLIENT->debugLocatorFlag) { | ||
| 24874 | |||
| 24875 | $self->writeDebug( | ||
| 24876 | 'LOCATOR 631: Component \'' . $componentObj->name . '\' not found: first' | ||
| 24877 | . ' start patterns/tags test failed (->extractLines part 3)', | ||
| 24878 | ); | ||
| 24879 | } | ||
| 24880 | |||
| 24881 | return $firstLineNum; | ||
| 24882 | } | ||
| 24883 | } | ||
| 24884 | |||
| 24885 | # ->startNoPatternList contains patterns NOT matching the first buffer line | ||
| 24886 | # ->startTagList contains tags NOT found in the first buffer line | ||
| 24887 | # ->startTagMode can specify that the line should NOT contain no colour/style tags | ||
| 24888 | if ( | ||
| 24889 | $componentObj->startNoPatternList | ||
| 24890 | || $componentObj->startNoTagList | ||
| 24891 | || $componentObj->startNoTagMode ne 'default' | ||
| 24892 | ) { | ||
| 24893 | if ( | ||
| 24894 | $self->testLine( | ||
| 24895 | $firstLineText, | ||
| 24896 | $firstLineObj, | ||
| 24897 | $componentObj, | ||
| 24898 | 'startNoPatternList', | ||
| 24899 | 'startNoTagList', | ||
| 24900 | 'startNoAllFlag', | ||
| 24901 | 'startNoTagMode', | ||
| 24902 | ) | ||
| 24903 | ) { | ||
| 24904 | # Can't extract the component. Return $firstLineNum so that the next component to be | ||
| 24905 | # extracted, if any, starts on the same line as this one) | ||
| 24906 | if ($axmud::CLIENT->debugLocatorFlag) { | ||
| 24907 | |||
| 24908 | $self->writeDebug( | ||
| 24909 | 'LOCATOR 641: Component \'' . $componentObj->name . '\' not found: second' | ||
| 24910 | . ' start patterns/tags test failed (->extractLines part 3)', | ||
| 24911 | ); | ||
| 24912 | } | ||
| 24913 | |||
| 24914 | return $firstLineNum; | ||
| 24915 | } | ||
| 24916 | } | ||
| 24917 | |||
| 24918 | # Parts 4-5 | ||
| 24919 | # --------- | ||
| 24920 | # The rest of the analysis depends on the value of $componentObj->extractLines | ||
| 24921 | if ($componentObj->analyseMode eq 'check_line') { | ||
| 24922 | |||
| 24923 | # Mode 0 - Check each line, one at a time, against all patterns/tags | ||
| 24924 | @resultList = $self->extractByLine( | ||
| 24925 | $componentObj, | ||
| 24926 | $firstLineNum, | ||
| 24927 | $step, | ||
| 24928 | ); | ||
| 24929 | |||
| 24930 | } else { | ||
| 24931 | |||
| 24932 | # Mode 1 - Check each pattern/tag, one at a time, against all lines | ||
| 24933 | @resultList = $self->extractByPatternTag( | ||
| 24934 | $componentObj, | ||
| 24935 | $firstLineNum, | ||
| 24936 | $step, | ||
| 24937 | ); | ||
| 24938 | } | ||
| 24939 | |||
| 24940 | # @resultList is in the form ($thisLineNum, @lineList), but $thisLineNum might be 'undef' | ||
| 24941 | if (defined $resultList[0] || scalar @resultList > 1) { | ||
| 24942 | |||
| 24943 | $thisLineNum = shift @resultList; | ||
| 24944 | push (@lineList, @resultList); | ||
| 24945 | } | ||
| 24946 | |||
| 24947 | # Stop here | ||
| 24948 | return ($thisLineNum, @lineList); | ||
| 24949 | } | ||
| 24950 | |||
| 24951 | sub extractByLine { | ||
| 24952 | |||
| 24953 | # Called by $self->extractLines for a component whose ->analyseMode is set to 'check_line' | ||
| 24954 | # (Check each line, one at a time, against all patterns/tags) | ||
| 24955 | # | ||
| 24956 | # Expected arguments | ||
| 24957 | # $componentObj - The GA::Obj::Component object | ||
| 24958 | # $firstLineNum - The number of the first display buffer line to check | ||
| 24959 | # $step - The direction in which to check lines: -1 to move backwards through | ||
| 24960 | # the display buffer, 1 to move forwards | ||
| 24961 | # | ||
| 24962 | # Return values | ||
| 24963 | # An empty list on improper arguments or if we run out lines while extracting valid lines | ||
| 24964 | # Otherwise, a list in the form | ||
| 24965 | # (next_line, line_list) | ||
| 24966 | # ...where: | ||
| 24967 | # 'next_line' - The next line in the display buffer after (or before) this component, | ||
| 24968 | # which should be checked by the next call to ->extractLines (set to | ||
| 24969 | # 'undef' if we run out of lines) | ||
| 24970 | # 'line_list' - A list of display buffer line numbers in the order in which they were | ||
| 24971 | # received from the world, regardless of $step (earliest line first). | ||
| 24972 | # If the component can't be extracted, an empty list | ||
| 24973 | |||
| 24974 | my ($self, $componentObj, $firstLineNum, $step, $check) = @_; | ||
| 24975 | |||
| 24976 | # Local variables | ||
| 24977 | my ( | ||
| 24978 | $thisLineNum, $thisLineText, $thisLineObj, $upperCount, $otherCount, $nextLineNum, | ||
| 24979 | $nextLineText, $nextLineObj, | ||
| 24980 | @lineList, | ||
| 24981 | ); | ||
| 24982 | |||
| 24983 | # (Set a variable containing a hypothetical previous line, so that we can use simple 'for' | ||
| 24984 | # loops) | ||
| 24985 | $thisLineNum = $firstLineNum - $step; | ||
| 24986 | |||
| 24987 | # Check each line, one at a time, against all patterns/tags | ||
| 24988 | OUTER: for (my $count = 1; $count <= $componentObj->maxSize; $count++) { | ||
| 24989 | |||
| 24990 | $thisLineNum += $step; | ||
| 24991 | ($thisLineText, $thisLineObj) = $self->checkLineValid($thisLineNum); | ||
| 24992 | if (! defined $thisLineText) { | ||
| 24993 | |||
| 24994 | return (undef, @lineList); | ||
| 24995 | } | ||
| 24996 | |||
| 24997 | # Part 4 (removed in v1.0.317) | ||
| 24998 | # ---------------------------- | ||
| 24999 | |||
| 25000 | # Part 5 | ||
| 25001 | # ------ | ||
| 25002 | |||
| 25003 | $upperCount = 0; | ||
| 25004 | $otherCount = 0; | ||
| 25005 | |||
| 25006 | if ( | ||
| 25007 | $componentObj->skipPatternList | ||
| 25008 | || $componentObj->skipTagList | ||
| 25009 | || $componentObj->skipTagMode ne 'default' | ||
| 25010 | ) { | ||
| 25011 | if ( | ||
| 25012 | $self->testLine( | ||
| 25013 | $thisLineText, | ||
| 25014 | $thisLineObj, | ||
| 25015 | $componentObj, | ||
| 25016 | 'skipPatternList', | ||
| 25017 | 'skipTagList', | ||
| 25018 | 'skipAllFlag', | ||
| 25019 | 'skipTagMode', | ||
| 25020 | ) | ||
| 25021 | ) { | ||
| 25022 | if ($axmud::CLIENT->debugMaxLocatorFlag) { | ||
| 25023 | |||
| 25024 | $self->writeDebug( | ||
| 25025 | 'LOCATOR 651: Skipping line ' . $thisLineNum . ' after ->testLine call' | ||
| 25026 | . ' succeeded', | ||
| 25027 | ); | ||
| 25028 | } | ||
| 25029 | |||
| 25030 | next OUTER; | ||
| 25031 | } | ||
| 25032 | } | ||
| 25033 | |||
| 25034 | # Some component object IVs require us to check the next line after (before) this one | ||
| 25035 | $nextLineNum = $thisLineNum + $step; | ||
| 25036 | ($nextLineText, $nextLineObj) = $self->checkLineValid($nextLineNum); | ||
| 25037 | |||
| 25038 | if (defined $nextLineText) { | ||
| 25039 | |||
| 25040 | if ( | ||
| 25041 | $componentObj->stopBeforePatternList | ||
| 25042 | || $componentObj->stopBeforeTagList | ||
| 25043 | || $componentObj->stopBeforeTagMode ne 'default' | ||
| 25044 | ) { | ||
| 25045 | if ( | ||
| 25046 | $self->testLine( | ||
| 25047 | $nextLineText, | ||
| 25048 | $nextLineObj, | ||
| 25049 | $componentObj, | ||
| 25050 | 'stopBeforePatternList', | ||
| 25051 | 'stopBeforeTagList', | ||
| 25052 | 'stopBeforeAllFlag', | ||
| 25053 | 'stopBeforeTagMode', | ||
| 25054 | ) | ||
| 25055 | ) { | ||
| 25056 | # The component stops at this line | ||
| 25057 | push (@lineList, $thisLineNum); | ||
| 25058 | # The next line to check is the line before/after this one. Return the list | ||
| 25059 | # of lines comprising this component | ||
| 25060 | return ($nextLineNum, @lineList); | ||
| 25061 | } | ||
| 25062 | } | ||
| 25063 | |||
| 25064 | if ( | ||
| 25065 | $componentObj->stopBeforeNoPatternList | ||
| 25066 | || $componentObj->stopBeforeNoTagList | ||
| 25067 | || $componentObj->stopBeforeNoTagMode ne 'default' | ||
| 25068 | ) { | ||
| 25069 | if ( | ||
| 25070 | ! $self->testLine( | ||
| 25071 | $nextLineText, | ||
| 25072 | $nextLineObj, | ||
| 25073 | $componentObj, | ||
| 25074 | 'stopBeforeNoPatternList', | ||
| 25075 | 'stopBeforeNoTagList', | ||
| 25076 | 'stopBeforeNoAllFlag', | ||
| 25077 | 'stopBeforeNoTagMode', | ||
| 25078 | ) | ||
| 25079 | ) { | ||
| 25080 | # The component stops at this line | ||
| 25081 | push (@lineList, $thisLineNum); | ||
| 25082 | # The next line to check is the line before/after this one. Return the list | ||
| 25083 | # of lines comprising this component | ||
| 25084 | return ($nextLineNum, @lineList); | ||
| 25085 | } | ||
| 25086 | } | ||
| 25087 | } | ||
| 25088 | |||
| 25089 | if ( | ||
| 25090 | $componentObj->stopAtPatternList | ||
| 25091 | || $componentObj->stopAtTagList | ||
| 25092 | || $componentObj->stopAtTagMode ne 'default' | ||
| 25093 | ) { | ||
| 25094 | if ( | ||
| 25095 | $self->testLine( | ||
| 25096 | $thisLineText, | ||
| 25097 | $thisLineObj, | ||
| 25098 | $componentObj, | ||
| 25099 | 'stopAtPatternList', | ||
| 25100 | 'stopAtTagList', | ||
| 25101 | 'stopAtAllFlag', | ||
| 25102 | 'stopAtTagMode', | ||
| 25103 | ) | ||
| 25104 | ) { | ||
| 25105 | # The component stops at this line | ||
| 25106 | push (@lineList, $thisLineNum); | ||
| 25107 | # The next line to check is the line before/after this one. Return the list | ||
| 25108 | # of lines comprising this component | ||
| 25109 | return ($nextLineNum, @lineList); | ||
| 25110 | } | ||
| 25111 | } | ||
| 25112 | |||
| 25113 | if ( | ||
| 25114 | $componentObj->stopAtNoPatternList | ||
| 25115 | || $componentObj->stopAtNoTagList | ||
| 25116 | || $componentObj->stopAtNoTagMode ne 'default' | ||
| 25117 | ) { | ||
| 25118 | if ( | ||
| 25119 | ! $self->testLine( | ||
| 25120 | $thisLineText, | ||
| 25121 | $thisLineObj, | ||
| 25122 | $componentObj, | ||
| 25123 | 'stopAtNoPatternList', | ||
| 25124 | 'stopAtNoTagList', | ||
| 25125 | 'stopAtNoAllFlag', | ||
| 25126 | 'stopAtNoTagMode', | ||
| 25127 | ) | ||
| 25128 | ) { | ||
| 25129 | # The component stops at this line | ||
| 25130 | push (@lineList, $thisLineNum); | ||
| 25131 | # The next line to check is the line before/after this one. Return the list | ||
| 25132 | # of lines comprising this component | ||
| 25133 | return ($nextLineNum, @lineList); | ||
| 25134 | } | ||
| 25135 | } | ||
| 25136 | |||
| 25137 | # Count lines which start with an upper-case letter (and those which don't start with | ||
| 25138 | # an alphanumeric character that's not a capital). If we've reached the limit, stop | ||
| 25139 | # at this line | ||
| 25140 | if ($componentObj->upperCount) { | ||
| 25141 | |||
| 25142 | if ($thisLineText =~ m/^[[:upper:]]/) { | ||
| 25143 | |||
| 25144 | $upperCount++; | ||
| 25145 | |||
| 25146 | if ($upperCount >= $componentObj->upperCount) { | ||
| 25147 | |||
| 25148 | # The component stops at this line | ||
| 25149 | push (@lineList, $thisLineNum); | ||
| 25150 | # The next line to check is the line before/after this one. Return the list | ||
| 25151 | # of lines comprising this component | ||
| 25152 | return ($nextLineNum, @lineList); | ||
| 25153 | } | ||
| 25154 | } | ||
| 25155 | } | ||
| 25156 | |||
| 25157 | if ($componentObj->otherCount) { | ||
| 25158 | |||
| 25159 | if ($thisLineText =~ m/^[[:lower:]0-9\_]/) { | ||
| 25160 | |||
| 25161 | $otherCount++; | ||
| 25162 | |||
| 25163 | if ($otherCount >= $componentObj->otherCount) { | ||
| 25164 | |||
| 25165 | # The component stops at this line | ||
| 25166 | push (@lineList, $thisLineNum); | ||
| 25167 | # The next line to check is the line before/after this one. Return the list | ||
| 25168 | # of lines comprising this component | ||
| 25169 | return ($nextLineNum, @lineList); | ||
| 25170 | } | ||
| 25171 | } | ||
| 25172 | } | ||
| 25173 | |||
| 25174 | # The ->stopBeforeMode and ->stopAtMode IVs detail other instances in which we should | ||
| 25175 | # stop | ||
| 25176 | if (defined $nextLineText && $componentObj->stopBeforeMode ne 'default') { | ||
| 25177 | |||
| 25178 | if ( | ||
| 25179 | # 'no_char' - Stop one line before the first line containing no characters at | ||
| 25180 | # all | ||
| 25181 | ($componentObj->stopBeforeMode eq 'no_char' && ! ($nextLineText =~ m/\S/)) | ||
| 25182 | # 'no_letter_num' - Stop one line before the first line containing no | ||
| 25183 | # alphanumeric characters | ||
| 25184 | || ( | ||
| 25185 | $componentObj->stopBeforeMode eq 'no_letter_num' | ||
| 25186 | && ! ($nextLineText =~ m/\w/) | ||
| 25187 | ) | ||
| 25188 | # 'no_start_letter_num' - Stop one line before the first line which doesn't | ||
| 25189 | # start with an alpha-numeric character | ||
| 25190 | || ( | ||
| 25191 | $componentObj->stopBeforeMode eq 'no_start_letter_num' | ||
| 25192 | && ! ($nextLineText =~ m/^\w/) | ||
| 25193 | ) | ||
| 25194 | # 'no_tag' - Stop one line before the first line containing no Axmud colour/ | ||
| 25195 | # style tags at all (not including the dummy style tags like 'bold', | ||
| 25196 | # 'reverse_off' and 'attribs_off') | ||
| 25197 | || ( | ||
| 25198 | $componentObj->stopBeforeMode eq 'no_tag' | ||
| 25199 | && ! $self->checkLineTags($nextLineObj) | ||
| 25200 | ) | ||
| 25201 | # 'has_letter_num' - Stop one line before the first line which DOES contain | ||
| 25202 | # alphanumeric characters | ||
| 25203 | || ( | ||
| 25204 | $componentObj->stopBeforeMode eq 'has_letter_num' | ||
| 25205 | && ($nextLineText =~ m/\w/) | ||
| 25206 | ) | ||
| 25207 | # 'has_start_letter_num' - Stop one line before the first line which DOES start | ||
| 25208 | # with an alphanumeric characters | ||
| 25209 | || ( | ||
| 25210 | $componentObj->stopBeforeMode eq 'has_start_letter_num' | ||
| 25211 | && ($nextLineText =~ m/^\w/) | ||
| 25212 | ) | ||
| 25213 | # 'has_tag' - Stop one line before the first line which DOES contain an Axmud | ||
| 25214 | # colour/style tag (not including the dummy style tags like 'bold', | ||
| 25215 | # 'reverse_off' and 'attribs_off') | ||
| 25216 | || ( | ||
| 25217 | $componentObj->stopBeforeMode eq 'has_tag' | ||
| 25218 | && $self->checkLineTags($nextLineObj) | ||
| 25219 | ) | ||
| 25220 | ) { | ||
| 25221 | # The component stops at this line | ||
| 25222 | push (@lineList, $thisLineNum); | ||
| 25223 | # The next line to check is the line before/after this one. Return the list of | ||
| 25224 | # lines comprising this component | ||
| 25225 | return ($nextLineNum, @lineList); | ||
| 25226 | } | ||
| 25227 | } | ||
| 25228 | |||
| 25229 | if ($componentObj->stopAtMode ne 'default') { | ||
| 25230 | |||
| 25231 | if ( | ||
| 25232 | # 'no_char' - Stop at the first line containing no characters at all | ||
| 25233 | ($componentObj->stopAtMode eq 'no_char' && ! ($thisLineText =~ m/\S/)) | ||
| 25234 | # 'no_letter_num' - Stop at the first line containing no alphanumeric characters | ||
| 25235 | || ($componentObj->stopAtMode eq 'no_letter_num' && ! ($thisLineText =~ m/\w/)) | ||
| 25236 | # 'no_start_letter_num' - Stop at the first line which doesn't start with an | ||
| 25237 | # alphanumeric character | ||
| 25238 | || ( | ||
| 25239 | $componentObj->stopAtMode eq 'no_start_letter_num' | ||
| 25240 | && ! ($thisLineText =~ m/^\w/) | ||
| 25241 | ) | ||
| 25242 | # 'no_tag' - Stop at the first line containing no Axmud colour/style tags at all | ||
| 25243 | # (not including the dummy style tags like 'bold', 'reverse_off' and | ||
| 25244 | # 'attribs_off') | ||
| 25245 | || ( | ||
| 25246 | $componentObj->stopAtMode eq 'no_tag' | ||
| 25247 | && ! $self->checkLineTags($thisLineObj) | ||
| 25248 | ) | ||
| 25249 | # 'has_letter_num' - Stop at the first line which DOES contain alphanumeric | ||
| 25250 | # characters | ||
| 25251 | || ( | ||
| 25252 | $componentObj->stopAtMode eq 'has_letter_num' | ||
| 25253 | && ($thisLineText =~ m/\w/) | ||
| 25254 | ) | ||
| 25255 | # 'has_start_letter_num' - Stop at the first line which DOES start with an | ||
| 25256 | # alphanumeric characters | ||
| 25257 | || ( | ||
| 25258 | $componentObj->stopAtMode eq 'has_start_letter_num' | ||
| 25259 | && ($thisLineText =~ m/^\w/) | ||
| 25260 | ) | ||
| 25261 | # 'has_tag' - Stop at the first line which DOES contain an Axmud colour/style | ||
| 25262 | # tag (not including the dummy style tags like 'bold', 'reverse_off' and | ||
| 25263 | # 'attribs_off') | ||
| 25264 | || ( | ||
| 25265 | $componentObj->stopAtMode eq 'has_tag' | ||
| 25266 | && $self->checkLineTags($thisLineObj) | ||
| 25267 | ) | ||
| 25268 | ) { | ||
| 25269 | # The component stops at this line | ||
| 25270 | push (@lineList, $thisLineNum); | ||
| 25271 | # The next line to check is the line before/after this one. Return the list of | ||
| 25272 | # lines comprising this component | ||
| 25273 | return ($nextLineNum, @lineList); | ||
| 25274 | } | ||
| 25275 | } | ||
| 25276 | |||
| 25277 | # Otherwise, use this line | ||
| 25278 | push (@lineList, $thisLineNum); | ||
| 25279 | } | ||
| 25280 | |||
| 25281 | # Stop here. We have reached this point because we have reached the line limit specified by | ||
| 25282 | # $componentObj->maxSize; the next line to check should be the line before/after this one | ||
| 25283 | $thisLineNum += $step; | ||
| 25284 | |||
| 25285 | return ($thisLineNum, @lineList); | ||
| 25286 | } | ||
| 25287 | |||
| 25288 | sub extractByPatternTag { | ||
| 25289 | |||
| 25290 | # Called by $self->extractLines for a component whose ->analyseMode is set to | ||
| 25291 | # 'check_pattern_tag' (check each pattern/tag, one at a time, against all lines) | ||
| 25292 | # | ||
| 25293 | # Expected arguments | ||
| 25294 | # $componentObj - The GA::Obj::Component object | ||
| 25295 | # $firstLineNum - The number of the first display buffer line to check | ||
| 25296 | # $step - The direction in which to check lines: -1 to move backwards through | ||
| 25297 | # the display buffer, 1 to move forwards | ||
| 25298 | # | ||
| 25299 | # Return values | ||
| 25300 | # An empty list on improper arguments or if we run out lines while extracting valid lines | ||
| 25301 | # Otherwise, a list in the form | ||
| 25302 | # (next_line, line_list) | ||
| 25303 | # ...where: | ||
| 25304 | # 'next_line' - The next line in the display buffer after (or before) this component, | ||
| 25305 | # which should be checked by the next call to ->extractLines (set to | ||
| 25306 | # 'undef' if we run out of lines) | ||
| 25307 | # 'line_list' - A list of display buffer line numbers in the order in which they were | ||
| 25308 | # received from the world, regardless of $step (earliest line first). | ||
| 25309 | # If the component can't be extracted, an empty list | ||
| 25310 | |||
| 25311 | my ($self, $componentObj, $firstLineNum, $step, $check) = @_; | ||
| 25312 | |||
| 25313 | # Local variables | ||
| 25314 | my ( | ||
| 25315 | $thisLineNum, $thisLineText, $thisLineObj, $upperCount, $otherCount, $nextLineNum, | ||
| 25316 | $nextLineText, $nextLineObj, | ||
| 25317 | @lineList, | ||
| 25318 | ); | ||
| 25319 | |||
| 25320 | # Part 4 (removed in v1.0.317) | ||
| 25321 | # ---------------------------- | ||
| 25322 | |||
| 25323 | # Part 5 | ||
| 25324 | # ------ | ||
| 25325 | |||
| 25326 | # (Set a variable containing a hypothetical previous line, so that we can use simple 'for' | ||
| 25327 | # loops) | ||
| 25328 | $thisLineNum = $firstLineNum - $step; | ||
| 25329 | $upperCount = 0; | ||
| 25330 | $otherCount = 0; | ||
| 25331 | |||
| 25332 | OUTER: for (my $count = 1; $count <= $componentObj->maxSize; $count++) { | ||
| 25333 | |||
| 25334 | $thisLineNum += $step; | ||
| 25335 | ($thisLineText, $thisLineObj) = $self->checkLineValid($thisLineNum); | ||
| 25336 | if (! defined $thisLineText) { | ||
| 25337 | |||
| 25338 | # We have run out of lines. Return the lines already extracted; it's up to the | ||
| 25339 | # calling function to check whether we have too few lines | ||
| 25340 | return (undef, @lineList); | ||
| 25341 | } | ||
| 25342 | |||
| 25343 | if ( | ||
| 25344 | $componentObj->skipPatternList | ||
| 25345 | || $componentObj->skipTagList | ||
| 25346 | || $componentObj->skipTagMode ne 'default' | ||
| 25347 | ) { | ||
| 25348 | if ( | ||
| 25349 | $self->testLine( | ||
| 25350 | $thisLineText, | ||
| 25351 | $thisLineObj, | ||
| 25352 | $componentObj, | ||
| 25353 | 'skipPatternList', | ||
| 25354 | 'skipTagList', | ||
| 25355 | 'skipAllFlag', | ||
| 25356 | 'skipTagMode', | ||
| 25357 | ) | ||
| 25358 | ) { | ||
| 25359 | # Skip this line | ||
| 25360 | next OUTER; | ||
| 25361 | } | ||
| 25362 | } | ||
| 25363 | |||
| 25364 | # Some component object IVs require us to check the next line after (before) this one | ||
| 25365 | $nextLineNum = $thisLineNum + $step; | ||
| 25366 | ($nextLineText, $nextLineObj) = $self->checkLineValid($nextLineNum); | ||
| 25367 | |||
| 25368 | if (defined $nextLineText) { | ||
| 25369 | |||
| 25370 | if ( | ||
| 25371 | $componentObj->stopBeforePatternList | ||
| 25372 | || $componentObj->stopBeforeTagList | ||
| 25373 | || $componentObj->stopBeforeTagMode ne 'default' | ||
| 25374 | ) { | ||
| 25375 | if ( | ||
| 25376 | $self->testLine( | ||
| 25377 | $nextLineText, | ||
| 25378 | $nextLineObj, | ||
| 25379 | $componentObj, | ||
| 25380 | 'stopBeforePatternList', | ||
| 25381 | 'stopBeforeTagList', | ||
| 25382 | 'stopBeforeAllFlag', | ||
| 25383 | 'stopBeforeTagMode', | ||
| 25384 | ) | ||
| 25385 | ) { | ||
| 25386 | # The component stops at this line | ||
| 25387 | push (@lineList, $thisLineNum); | ||
| 25388 | # The next line to check is the line before/after this one. Return the list | ||
| 25389 | # of lines comprising this component | ||
| 25390 | return ($nextLineNum, @lineList); | ||
| 25391 | } | ||
| 25392 | } | ||
| 25393 | |||
| 25394 | if ( | ||
| 25395 | $componentObj->stopBeforeNoPatternList | ||
| 25396 | || $componentObj->stopBeforeNoTagList | ||
| 25397 | || $componentObj->stopBeforeNoTagMode ne 'default' | ||
| 25398 | ) { | ||
| 25399 | if ( | ||
| 25400 | ! $self->testLine( | ||
| 25401 | $nextLineText, | ||
| 25402 | $nextLineObj, | ||
| 25403 | $componentObj, | ||
| 25404 | 'stopBeforeNoPatternList', | ||
| 25405 | 'stopBeforeNoTagList', | ||
| 25406 | 'stopBeforeNoAllFlag', | ||
| 25407 | 'stopBeforeNoTagMode', | ||
| 25408 | ) | ||
| 25409 | ) { | ||
| 25410 | # The component stops at this line | ||
| 25411 | push (@lineList, $thisLineNum); | ||
| 25412 | # The next line to check is the line before/after this one. Return the list | ||
| 25413 | # of lines comprising this component | ||
| 25414 | return ($nextLineNum, @lineList); | ||
| 25415 | } | ||
| 25416 | } | ||
| 25417 | } | ||
| 25418 | |||
| 25419 | if ( | ||
| 25420 | $componentObj->stopAtPatternList | ||
| 25421 | || $componentObj->stopAtTagList | ||
| 25422 | || $componentObj->stopAtTagMode ne 'default' | ||
| 25423 | ) { | ||
| 25424 | if ( | ||
| 25425 | $self->testLine( | ||
| 25426 | $thisLineText, | ||
| 25427 | $thisLineObj, | ||
| 25428 | $componentObj, | ||
| 25429 | 'stopAtPatternList', | ||
| 25430 | 'stopAtTagList', | ||
| 25431 | 'stopAtAllFlag', | ||
| 25432 | 'stopAtTagMode', | ||
| 25433 | ) | ||
| 25434 | ) { | ||
| 25435 | # The component stops at this line | ||
| 25436 | push (@lineList, $thisLineNum); | ||
| 25437 | # The next line to check is the line before/after this one. Return the list | ||
| 25438 | # of lines comprising this component | ||
| 25439 | return ($nextLineNum, @lineList); | ||
| 25440 | } | ||
| 25441 | } | ||
| 25442 | |||
| 25443 | if ( | ||
| 25444 | $componentObj->stopAtNoPatternList | ||
| 25445 | || $componentObj->stopAtNoTagList | ||
| 25446 | || $componentObj->stopAtNoTagMode ne 'default' | ||
| 25447 | ) { | ||
| 25448 | if ( | ||
| 25449 | ! $self->testLine( | ||
| 25450 | $thisLineText, | ||
| 25451 | $thisLineObj, | ||
| 25452 | $componentObj, | ||
| 25453 | 'stopAtNoPatternList', | ||
| 25454 | 'stopAtNoTagList', | ||
| 25455 | 'stopAtNoAllFlag', | ||
| 25456 | 'stopAtNoTagMode', | ||
| 25457 | ) | ||
| 25458 | ) { | ||
| 25459 | # The component stops at this line | ||
| 25460 | push (@lineList, $thisLineNum); | ||
| 25461 | # The next line to check is the line before/after this one. Return the list | ||
| 25462 | # of lines comprising this component | ||
| 25463 | return ($nextLineNum, @lineList); | ||
| 25464 | } | ||
| 25465 | } | ||
| 25466 | |||
| 25467 | # Count lines which start with an upper-case letter (and those which don't start with | ||
| 25468 | # an alphanumeric character that's not a capital). If we've reached the limit, stop | ||
| 25469 | # at this line | ||
| 25470 | if ($componentObj->upperCount) { | ||
| 25471 | |||
| 25472 | if ($thisLineText =~ m/^[[:upper:]]/) { | ||
| 25473 | |||
| 25474 | $upperCount++; | ||
| 25475 | |||
| 25476 | if ($upperCount >= $componentObj->upperCount) { | ||
| 25477 | |||
| 25478 | # The component stops at this line | ||
| 25479 | push (@lineList, $thisLineNum); | ||
| 25480 | # The next line to check is the line before/after this one. Return the list | ||
| 25481 | # of lines comprising this component | ||
| 25482 | return ($nextLineNum, @lineList); | ||
| 25483 | } | ||
| 25484 | } | ||
| 25485 | } | ||
| 25486 | |||
| 25487 | if ($componentObj->otherCount) { | ||
| 25488 | |||
| 25489 | if ($thisLineText =~ m/^[[:lower:]0-9\_]/) { | ||
| 25490 | |||
| 25491 | $otherCount++; | ||
| 25492 | |||
| 25493 | if ($otherCount >= $componentObj->otherCount) { | ||
| 25494 | |||
| 25495 | # The component stops at this line | ||
| 25496 | push (@lineList, $thisLineNum); | ||
| 25497 | # The next line to check is the line before/after this one. Return the list | ||
| 25498 | # of lines comprising this component | ||
| 25499 | return ($nextLineNum, @lineList); | ||
| 25500 | } | ||
| 25501 | } | ||
| 25502 | } | ||
| 25503 | |||
| 25504 | # The ->stopBeforeMode and ->stopAtMode IVs detail other instances in which we should | ||
| 25505 | # stop | ||
| 25506 | if (defined $nextLineText && $componentObj->stopBeforeMode) { | ||
| 25507 | |||
| 25508 | if ( | ||
| 25509 | # 'no_char' - Stop one line before the first line containing no characters at | ||
| 25510 | # all | ||
| 25511 | ($componentObj->stopBeforeMode eq 'no_char' && ! ($nextLineText =~ m/\S/)) | ||
| 25512 | # 'no_letter_num' - Stop one line before the first line containing no | ||
| 25513 | # alphanumeric characters | ||
| 25514 | || ( | ||
| 25515 | $componentObj->stopBeforeMode eq 'no_letter_num' | ||
| 25516 | && ! ($nextLineText =~ m/\w/) | ||
| 25517 | ) | ||
| 25518 | # 'no_start_letter_num' - Stop one line before the first line which doesn't | ||
| 25519 | # start with an alpha-numeric character | ||
| 25520 | || ( | ||
| 25521 | $componentObj->stopBeforeMode eq 'no_start_letter_num' | ||
| 25522 | && ! ($nextLineText =~ m/^\w/) | ||
| 25523 | ) | ||
| 25524 | # 'no_tag' - Stop one line before the first line containing no Axmud colour/ | ||
| 25525 | # style tags at all (not including the dummy style tags like 'bold', | ||
| 25526 | # 'reverse_off' and 'attribs_off') | ||
| 25527 | || ( | ||
| 25528 | $componentObj->stopBeforeMode eq 'no_tag' | ||
| 25529 | && ! $self->checkLineTags($nextLineObj) | ||
| 25530 | ) | ||
| 25531 | # 'has_letter_num' - Stop one line before the first line which DOES contain | ||
| 25532 | # alphanumeric characters | ||
| 25533 | || ( | ||
| 25534 | $componentObj->stopBeforeMode eq 'has_letter_num' | ||
| 25535 | && ($nextLineText =~ m/\w/) | ||
| 25536 | ) | ||
| 25537 | # 'has_start_letter_num' - Stop one line before the first line which DOES start | ||
| 25538 | # with an alphanumeric characters | ||
| 25539 | || ( | ||
| 25540 | $componentObj->stopBeforeMode eq 'has_start_letter_num' | ||
| 25541 | && ($nextLineText =~ m/^\w/) | ||
| 25542 | ) | ||
| 25543 | # 'has_tag' - Stop one line before the first line which DOES contain an Axmud | ||
| 25544 | # colour/style tag (not including the dummy style tags like 'bold', | ||
| 25545 | # 'reverse_off' and 'attribs_off') | ||
| 25546 | || ( | ||
| 25547 | $componentObj->stopBeforeMode eq 'has_tag' | ||
| 25548 | && $self->checkLineTags($nextLineObj) | ||
| 25549 | ) | ||
| 25550 | ) { | ||
| 25551 | # The component stops at this line | ||
| 25552 | push (@lineList, $thisLineNum); | ||
| 25553 | # The next line to check is the line before/after this one. Return the list of | ||
| 25554 | # lines comprising this component | ||
| 25555 | return ($nextLineNum, @lineList); | ||
| 25556 | } | ||
| 25557 | } | ||
| 25558 | |||
| 25559 | if ($componentObj->stopAtMode) { | ||
| 25560 | |||
| 25561 | if ( | ||
| 25562 | # 'no_char' - Stop at the first line containing no characters at all | ||
| 25563 | ($componentObj->stopAtMode eq 'no_char' && ! ($thisLineText =~ m/\S/)) | ||
| 25564 | # 'no_letter_num' - Stop at the first line containing no alphanumeric characters | ||
| 25565 | || ($componentObj->stopAtMode eq 'no_letter_num' && ! ($thisLineText =~ m/\w/)) | ||
| 25566 | # 'no_start_letter_num' - Stop at the first line which doesn't start with an | ||
| 25567 | # alphanumeric character | ||
| 25568 | || ( | ||
| 25569 | $componentObj->stopAtMode eq 'no_start_letter_num' | ||
| 25570 | && ! ($thisLineText =~ m/^\w/) | ||
| 25571 | ) | ||
| 25572 | # 'no_tag' - Stop at the first line containing no Axmud colour/style tags at all | ||
| 25573 | # (not including the dummy style tags like 'bold', 'reverse_off' and | ||
| 25574 | # 'attribs_off') | ||
| 25575 | || ( | ||
| 25576 | $componentObj->stopAtMode eq 'no_tag' | ||
| 25577 | && ! $self->checkLineTags($thisLineObj) | ||
| 25578 | ) | ||
| 25579 | # 'has_letter_num' - Stop at the first line which DOES contain alphanumeric | ||
| 25580 | # characters | ||
| 25581 | || ( | ||
| 25582 | $componentObj->stopAtMode eq 'has_letter_num' | ||
| 25583 | && ($thisLineText =~ m/\w/) | ||
| 25584 | ) | ||
| 25585 | # 'has_start_letter_num' - Stop at the first line which DOES start with an | ||
| 25586 | # alphanumeric characters | ||
| 25587 | || ( | ||
| 25588 | $componentObj->stopAtMode eq 'has_start_letter_num' | ||
| 25589 | && ($thisLineText =~ m/^\w/) | ||
| 25590 | ) | ||
| 25591 | # 'has_tag' - Stop at the first line which DOES contain an Axmud colour/style | ||
| 25592 | # tag (not including the dummy style tags like 'bold', 'reverse_off' and | ||
| 25593 | # 'attribs_off') | ||
| 25594 | || ( | ||
| 25595 | $componentObj->stopAtMode eq 'has_tag' | ||
| 25596 | && $self->checkLineTags($thisLineObj) | ||
| 25597 | ) | ||
| 25598 | ) { | ||
| 25599 | # The component stops at this line | ||
| 25600 | push (@lineList, $thisLineNum); | ||
| 25601 | # The next line to check is the line before/after this one. Return the list of | ||
| 25602 | # lines comprising this component | ||
| 25603 | return ($nextLineNum, @lineList); | ||
| 25604 | } | ||
| 25605 | } | ||
| 25606 | |||
| 25607 | # Otherwise, use this line | ||
| 25608 | push (@lineList, $thisLineNum); | ||
| 25609 | } | ||
| 25610 | |||
| 25611 | # Stop here. We have reached this point because we have reached the line limit specified by | ||
| 25612 | # $componentObj->maxSize; the next line to check should be the line before/after this one | ||
| 25613 | $thisLineNum += $step; | ||
| 25614 | return ($thisLineNum, @lineList); | ||
| 25615 | } | ||
| 25616 | |||
| 25617 | sub testLine { | ||
| 25618 | |||
| 25619 | # Called by $self->extractLines, ->extractByLine and ->extractByPatternTag to test how | ||
| 25620 | # many of a single type of pattern/tag are found in a single line | ||
| 25621 | # Some room statement components demand that all specified patterns must be matched and all | ||
| 25622 | # specified tags must be found in the line. Other components specify that only one | ||
| 25623 | # specified pattern or tag need be found in the line | ||
| 25624 | # NB If the component's ->useInitialTagsFlag, this function behaves as if the colours/ | ||
| 25625 | # styles that were applied (i.e. displayed) at the beginning of the line are the only | ||
| 25626 | # tags on the line | ||
| 25627 | # Returns the result of the test in both situations | ||
| 25628 | # | ||
| 25629 | # Expected arguments | ||
| 25630 | # $lineText - The text of the line to check | ||
| 25631 | # $bufferObj - The corresponding GA::Buffer::Display object | ||
| 25632 | # $componentObj - The GA::Obj::Component object to which this line might be assigned, | ||
| 25633 | # if all tests are successful | ||
| 25634 | # $patternListIV - One of the component object's IVs, e.g. 'startPatternList' | ||
| 25635 | # $tagListIV - One of the component object's IVs, e.g. 'startTagList' | ||
| 25636 | # $allFlagIV - One of the component object's IVs, e.g. 'startAllFlag' | ||
| 25637 | # $tagModeIV - One of the component object's IVs, e.g. 'startTagMode' | ||
| 25638 | # | ||
| 25639 | # Return values | ||
| 25640 | # 'undef' on improper arguments or if the test fails | ||
| 25641 | # 1 if the test succeeds | ||
| 25642 | |||
| 25643 | my ( | ||
| 25644 | $self, $lineText, $bufferObj, $componentObj, $patternListIV, $tagListIV, $allFlagIV, | ||
| 25645 | $tagModeIV, $check | ||
| 25646 | ) = @_; | ||
| 25647 | |||
| 25648 | # Local variables | ||
| 25649 | my ( | ||
| 25650 | $count, $mode, $colourCount, $styleCount, $specialFlag, | ||
| 25651 | %tagHash, %otherTagHash, | ||
| 25652 | ); | ||
| 25653 | |||
| 25654 | # Check for improper arguments | ||
| 25655 | if ( | ||
| 25656 | ! defined $lineText || ! defined $bufferObj || ! defined $componentObj | ||
| 25657 | || ! defined $patternListIV || ! defined $tagListIV || ! defined $allFlagIV | ||
| 25658 | || ! defined $tagModeIV || defined $check | ||
| 25659 | ) { | ||
| 25660 | return $axmud::CLIENT->writeImproper($self->_objClass . '->testLine', @_); | ||
| 25661 | } | ||
| 25662 | |||
| 25663 | $count = 0; | ||
| 25664 | $mode = $componentObj->$tagModeIV; | ||
| 25665 | |||
| 25666 | # Check for patterns, if they are specified | ||
| 25667 | OUTER: foreach my $pattern ($componentObj->$patternListIV) { | ||
| 25668 | |||
| 25669 | if ($lineText =~ m/$pattern/) { | ||
| 25670 | |||
| 25671 | if ($axmud::CLIENT->debugMaxLocatorFlag) { | ||
| 25672 | |||
| 25673 | $self->writeDebug( | ||
| 25674 | 'LOCATOR 701: Line ' . $bufferObj->number . ' matches pattern \'' . $pattern | ||
| 25675 | . '\', IVs: \'' . $patternListIV . '\', etc (->testLine)', | ||
| 25676 | ); | ||
| 25677 | } | ||
| 25678 | |||
| 25679 | $count++; | ||
| 25680 | if (! $componentObj->$allFlagIV) { | ||
| 25681 | |||
| 25682 | last OUTER; | ||
| 25683 | } | ||
| 25684 | } | ||
| 25685 | } | ||
| 25686 | |||
| 25687 | # If there were no matching patterns (or if the component specifies that we must match | ||
| 25688 | # both patterns and Axmud colour/style tags), then check for Axmud colour/style tags, if | ||
| 25689 | # they are specified | ||
| 25690 | if (! $count || $componentObj->$allFlagIV) { | ||
| 25691 | |||
| 25692 | # Compile a hash of relevant colour/style tags | ||
| 25693 | |||
| 25694 | # Use only colours/styles that applied at the beginning of the line, including those | ||
| 25695 | # which are still in effect from previous lines | ||
| 25696 | if ($componentObj->useInitialTagsFlag && ! $componentObj->useExplicitTagsFlag) { | ||
| 25697 | |||
| 25698 | # Save a bit of time, by only processing the condition just above, once | ||
| 25699 | $specialFlag = TRUE; | ||
| 25700 | |||
| 25701 | foreach my $tag ($bufferObj->initialTagList) { | ||
| 25702 | |||
| 25703 | my $type; | ||
| 25704 | |||
| 25705 | $tagHash{$tag} = undef; | ||
| 25706 | |||
| 25707 | # If this is a standard colour tag and the component is bold-insensitive, we | ||
| 25708 | # add two entries to a parallel hash, so we can check 'RED' against this | ||
| 25709 | # parallel hash, and get a match against either 'red' or 'RED' | ||
| 25710 | ($type) = $axmud::CLIENT->checkColourTags($tag, 'standard'); | ||
| 25711 | if ($type && ! $componentObj->boldSensitiveFlag) { | ||
| 25712 | |||
| 25713 | $otherTagHash{lc($tag)} = undef; | ||
| 25714 | $otherTagHash{uc($tag)} = undef; | ||
| 25715 | |||
| 25716 | } else { | ||
| 25717 | |||
| 25718 | $otherTagHash{$tag} = undef; | ||
| 25719 | } | ||
| 25720 | } | ||
| 25721 | |||
| 25722 | # For other combinations of ->useInitialTagsFlag and ->useExplicitTagsFlag, we have to | ||
| 25723 | # let $self->findTag do the hard work | ||
| 25724 | } else { | ||
| 25725 | |||
| 25726 | %tagHash = $bufferObj->tagHash; | ||
| 25727 | } | ||
| 25728 | |||
| 25729 | # Count the number of relevant colour/style tags | ||
| 25730 | OUTER: foreach my $tag (keys %tagHash) { | ||
| 25731 | |||
| 25732 | my $type; | ||
| 25733 | |||
| 25734 | if ($axmud::CLIENT->debugMaxLocatorFlag) { | ||
| 25735 | |||
| 25736 | $self->writeDebug( | ||
| 25737 | 'LOCATOR 711: Line ' . $bufferObj->number . ' uses colour/style tag \'' | ||
| 25738 | . $tag . '\' (->testLine)', | ||
| 25739 | ); | ||
| 25740 | } | ||
| 25741 | |||
| 25742 | ($type) = $axmud::CLIENT->checkColourTags($tag); | ||
| 25743 | if ($type) { | ||
| 25744 | $colourCount++; # It's a colour tag | ||
| 25745 | } else { | ||
| 25746 | $styleCount++; # It's a style tag | ||
| 25747 | } | ||
| 25748 | } | ||
| 25749 | |||
| 25750 | # Here, what is relevant depends on the setting of $mode, set from | ||
| 25751 | # $componentObj->$tagModeIV | ||
| 25752 | if ( | ||
| 25753 | # Mode 'no_colour' - line contains no colour tags | ||
| 25754 | ($mode eq 'no_colour' && ! $colourCount) | ||
| 25755 | # Mode 'no_style' - line contains no style tags (not including dummy tags) | ||
| 25756 | || ($mode eq 'no_style' && ! $styleCount) | ||
| 25757 | # Mode 'no_colour_style' - line contains no colour or style tags | ||
| 25758 | || ($mode eq 'no_colour_style' && (! $colourCount) && (! $styleCount)) | ||
| 25759 | ) { | ||
| 25760 | if ($count == scalar $componentObj->$patternListIV) { | ||
| 25761 | |||
| 25762 | # We have the right number of patterns, and the right number of tags, so the | ||
| 25763 | # test has succeeded | ||
| 25764 | if ($axmud::CLIENT->debugMaxLocatorFlag) { | ||
| 25765 | |||
| 25766 | $self->writeDebug( | ||
| 25767 | 'LOCATOR 721: Line ' . $bufferObj->number | ||
| 25768 | . ' matches required patterns/tags (->testLine)', | ||
| 25769 | ); | ||
| 25770 | } | ||
| 25771 | |||
| 25772 | return TRUE; | ||
| 25773 | |||
| 25774 | } else { | ||
| 25775 | |||
| 25776 | # Otherwise, all tags are now accounted for (the test might have succeeded or | ||
| 25777 | # failed; we'll apply the usual test at the end of the function) | ||
| 25778 | $count += scalar $componentObj->$tagListIV; | ||
| 25779 | } | ||
| 25780 | |||
| 25781 | } elsif ($mode eq 'default') { | ||
| 25782 | |||
| 25783 | # Mode 'default' - line may contain colour and/or style tags, depending on the | ||
| 25784 | # contents of $componentObj->$tagListIV | ||
| 25785 | |||
| 25786 | # For mode 'default', we have to check each tag individually | ||
| 25787 | OUTER: foreach my $tag ($componentObj->$tagListIV) { | ||
| 25788 | |||
| 25789 | if ( | ||
| 25790 | # Use only colours/styles that applied at the beginning of the line, | ||
| 25791 | # including those which are still in effect from previous lines | ||
| 25792 | ($specialFlag && exists $otherTagHash{$tag}) | ||
| 25793 | # For other combinations of ->useInitialTagsFlag and ->useExplicitTagsFlag, | ||
| 25794 | # we have to let $self->findTag do the hard work | ||
| 25795 | || (! $specialFlag) && $self->findTag($componentObj, $bufferObj, $tag) | ||
| 25796 | ) { | ||
| 25797 | $count++; | ||
| 25798 | if (! $componentObj->$allFlagIV) { | ||
| 25799 | |||
| 25800 | last OUTER; | ||
| 25801 | } | ||
| 25802 | } | ||
| 25803 | } | ||
| 25804 | } | ||
| 25805 | } | ||
| 25806 | |||
| 25807 | if ( | ||
| 25808 | # No matching patterns/tags found | ||
| 25809 | ! $count | ||
| 25810 | # Not enough matching patterns/tags found | ||
| 25811 | || ( | ||
| 25812 | $componentObj->$allFlagIV | ||
| 25813 | && $count < ( | ||
| 25814 | scalar $componentObj->$patternListIV | ||
| 25815 | + scalar $componentObj->$tagListIV | ||
| 25816 | ) | ||
| 25817 | ) | ||
| 25818 | ) { | ||
| 25819 | # Test failed | ||
| 25820 | if ($axmud::CLIENT->debugMaxLocatorFlag) { | ||
| 25821 | |||
| 25822 | $self->writeDebug( | ||
| 25823 | 'LOCATOR 731: Line ' . $bufferObj->number . ', no matching patterns/tags found' | ||
| 25824 | . ' for IVs \'' . $patternListIV . '\', \'' . $tagListIV . '\', etc', | ||
| 25825 | ); | ||
| 25826 | } | ||
| 25827 | |||
| 25828 | return undef; | ||
| 25829 | |||
| 25830 | } else { | ||
| 25831 | |||
| 25832 | # Test successful | ||
| 25833 | return 1; | ||
| 25834 | } | ||
| 25835 | } | ||
| 25836 | |||
| 25837 | sub findTag { | ||
| 25838 | |||
| 25839 | # Called by $self->testLine | ||
| 25840 | # Given a display buffer line and an Axmud colour/style tag, see if the tag is present in | ||
| 25841 | # the object's tag hash | ||
| 25842 | # | ||
| 25843 | # Expected arguments | ||
| 25844 | # $componentObj - The GA::Obj::Component object which is currently being extracted | ||
| 25845 | # $bufferObj - The display buffer object corresponding to the line of received text | ||
| 25846 | # which is being checked, to see if it belongs to this component | ||
| 25847 | # $tag - The tag to find | ||
| 25848 | # | ||
| 25849 | # Return values | ||
| 25850 | # 'undef' on improper arguments or if the tag is not present | ||
| 25851 | # 1 if the tag is present | ||
| 25852 | |||
| 25853 | my ($self, $componentObj, $bufferObj, $tag, $check) = @_; | ||
| 25854 | |||
| 25855 | # Local variables | ||
| 25856 | my ( | ||
| 25857 | $boldFlag, $otherBoldFlag, $currentText, $currentUnderlay, $colourType, | ||
| 25858 | @offsetList, | ||
| 25859 | %offsetHash, %tagHash, | ||
| 25860 | ); | ||
| 25861 | |||
| 25862 | # Check for improper arguments | ||
| 25863 | if (! defined $componentObj || ! defined $bufferObj || ! defined $tag || defined $check) { | ||
| 25864 | |||
| 25865 | return $axmud::CLIENT->writeImproper($self->_objClass . '->findTag', @_); | ||
| 25866 | } | ||
| 25867 | |||
| 25868 | # Import the buffer object's hashes of tags | ||
| 25869 | %offsetHash = $bufferObj->offsetHash; | ||
| 25870 | %tagHash = $bufferObj->tagHash; | ||
| 25871 | |||
| 25872 | # Work out if $tag is a standard bold colour tag (not an RGB/xterm colour tag) | ||
| 25873 | ($colourType) = $axmud::CLIENT->checkColourTags($tag); | ||
| 25874 | if ($axmud::CLIENT->checkBoldTags($tag)) { | ||
| 25875 | |||
| 25876 | $boldFlag = TRUE; | ||
| 25877 | } | ||
| 25878 | |||
| 25879 | # For style tags, we can check the buffer object's tag hash directly | ||
| 25880 | if (! $colourType) { | ||
| 25881 | |||
| 25882 | if (exists $tagHash{$tag}) { | ||
| 25883 | return 1; | ||
| 25884 | } else { | ||
| 25885 | return undef; | ||
| 25886 | } | ||
| 25887 | } | ||
| 25888 | |||
| 25889 | # If the component specifies that standard normal/bold colour tags are interchangeable, | ||
| 25890 | # convert bold colour tags like 'RED'/'UL_RED' to normal colour tags like 'red'/'ul_red' | ||
| 25891 | if ($colourType && ! $componentObj->boldSensitiveFlag) { | ||
| 25892 | |||
| 25893 | $tag = lc($tag); | ||
| 25894 | } | ||
| 25895 | |||
| 25896 | # Get the colours that apply at the start of the line | ||
| 25897 | if (! $componentObj->useInitialTagsFlag && ! $componentObj->useExplicitTagsFlag) { | ||
| 25898 | |||
| 25899 | OUTER: foreach my $startTag ($bufferObj->previousTagList) { | ||
| 25900 | |||
| 25901 | if ($axmud::CLIENT->checkTextTags($startTag)) { | ||
| 25902 | $currentText = $startTag; | ||
| 25903 | } elsif ($axmud::CLIENT->checkUnderlayTags($startTag)) { | ||
| 25904 | $currentUnderlay = $startTag; | ||
| 25905 | } | ||
| 25906 | |||
| 25907 | if ($currentText && $currentUnderlay) { | ||
| 25908 | |||
| 25909 | # Only one of each can exist in ->previousTagList, so we can stop searching now | ||
| 25910 | last OUTER; | ||
| 25911 | } | ||
| 25912 | } | ||
| 25913 | |||
| 25914 | if (! defined $currentText && ! defined $currentUnderlay) { | ||
| 25915 | |||
| 25916 | # No colour tags were applied at the end of the last line, so the colours actually | ||
| 25917 | # displayed are the 'main' window's default colours (usually white) | ||
| 25918 | $currentText = $self->session->currentTabObj->textViewObj->textColour; | ||
| 25919 | $currentUnderlay = $self->session->currentTabObj->textViewObj->underlayColour; | ||
| 25920 | } | ||
| 25921 | |||
| 25922 | } else { | ||
| 25923 | |||
| 25924 | # Using an empty string, rather than 'undef', lets us apply lc() and uc() to the string, | ||
| 25925 | # without checking that it's defined | ||
| 25926 | $currentText = ''; | ||
| 25927 | $currentUnderlay = ''; | ||
| 25928 | } | ||
| 25929 | |||
| 25930 | # Now, go through the offsets at which tags occur, in order, looking for the colour $tag | ||
| 25931 | $otherBoldFlag = FALSE; | ||
| 25932 | if ($componentObj->useInitialTagsFlag) { | ||
| 25933 | |||
| 25934 | # Eliminate everything but the entry for offset 0 (if it exists) | ||
| 25935 | if (exists $offsetHash{0}) { | ||
| 25936 | %offsetHash = (0, $offsetHash{0}); | ||
| 25937 | } else { | ||
| 25938 | %offsetHash = (); | ||
| 25939 | } | ||
| 25940 | } | ||
| 25941 | |||
| 25942 | OUTER: foreach my $offset (sort {$a <=> $b} (keys %offsetHash)) { | ||
| 25943 | |||
| 25944 | my $listRef = $offsetHash{$offset}; | ||
| 25945 | |||
| 25946 | foreach my $otherTag (@$listRef) { | ||
| 25947 | |||
| 25948 | my ($otherType, $underlayFlag); | ||
| 25949 | |||
| 25950 | if ($otherTag eq 'bold') { | ||
| 25951 | |||
| 25952 | # Convert 'blue' to 'BLUE', etc. Don't worry whether it's an xterm or RGB colour | ||
| 25953 | # tag, as they are both case-insensitive | ||
| 25954 | # 'bold' tags don't apply to underlay colours, of course | ||
| 25955 | $currentText = uc($currentText); | ||
| 25956 | $otherBoldFlag = TRUE; | ||
| 25957 | |||
| 25958 | } elsif ($otherTag eq 'bold_off' || $otherTag eq 'attribs_off') { | ||
| 25959 | |||
| 25960 | $currentText = lc($currentText); | ||
| 25961 | $otherBoldFlag = FALSE; | ||
| 25962 | |||
| 25963 | } else { | ||
| 25964 | |||
| 25965 | ($otherType, $underlayFlag) = $axmud::CLIENT->checkColourTags($otherTag); | ||
| 25966 | if ($otherType) { | ||
| 25967 | |||
| 25968 | if (! $underlayFlag) { | ||
| 25969 | |||
| 25970 | $currentText = $otherTag; | ||
| 25971 | if ($otherBoldFlag && $otherType eq 'standard' && ! $underlayFlag) { | ||
| 25972 | |||
| 25973 | $currentText = uc($currentText); | ||
| 25974 | } | ||
| 25975 | |||
| 25976 | } else { | ||
| 25977 | |||
| 25978 | $currentUnderlay = $otherTag; | ||
| 25979 | } | ||
| 25980 | } | ||
| 25981 | } | ||
| 25982 | } | ||
| 25983 | |||
| 25984 | if ( | ||
| 25985 | ( | ||
| 25986 | $currentText # A colour tag was either initially applied, or actually found | ||
| 25987 | && ( | ||
| 25988 | (! $componentObj->boldSensitiveFlag && lc($currentText) eq lc($tag)) | ||
| 25989 | || ($boldFlag && $currentText eq uc($tag)) | ||
| 25990 | || (! $boldFlag && $currentText eq $tag) | ||
| 25991 | ) | ||
| 25992 | ) | ||
| 25993 | || ($currentUnderlay && lc ($currentUnderlay) eq lc($tag)) | ||
| 25994 | ) { | ||
| 25995 | # Success! | ||
| 25996 | return 1; | ||
| 25997 | } | ||
| 25998 | } | ||
| 25999 | |||
| 26000 | # The bold colour tag wasn't found on this line | ||
| 26001 | return undef; | ||
| 26002 | } | ||
| 26003 | |||
| 26004 | sub getColoursAtStart { | ||
| 26005 | |||
| 26006 | # Called by $self->setRoomExit | ||
| 26007 | # Gets the text and underlay colours that apply at the start of a line | ||
| 26008 | # | ||
| 26009 | # Expected arguments | ||
| 26010 | # $bufferObj - The display buffer object which stores the line | ||
| 26011 | # | ||
| 26012 | # Expected arguments | ||
| 26013 | # | ||
| 26014 | # Return values | ||
| 26015 | # An empty list on improper arguments | ||
| 26016 | # Otherwise, returns a list in the form (text_colour_tag, underlay_colour_tag) | ||
| 26017 | |||
| 26018 | my ($self, $bufferObj, $check) = @_; | ||
| 26019 | |||
| 26020 | # Local variables | ||
| 26021 | my ( | ||
| 26022 | $text, $underlay, | ||
| 26023 | @emptyList, | ||
| 26024 | ); | ||
| 26025 | |||
| 26026 | # Check for improper arguments | ||
| 26027 | if (! defined $bufferObj || defined $check) { | ||
| 26028 | |||
| 26029 | $axmud::CLIENT->writeImproper($self->_objClass . '->getColoursAtStart', @_); | ||
| 26030 | return @emptyList; | ||
| 26031 | } | ||
| 26032 | |||
| 26033 | # Get the colours that apply at the start of the line | ||
| 26034 | OUTER: foreach my $startTag ($bufferObj->previousTagList) { | ||
| 26035 | |||
| 26036 | if ($axmud::CLIENT->checkTextTags($startTag)) { | ||
| 26037 | $text = $startTag; | ||
| 26038 | } elsif ($axmud::CLIENT->checkUnderlayTags($startTag)) { | ||
| 26039 | $underlay = $startTag; | ||
| 26040 | } | ||
| 26041 | |||
| 26042 | if ($text && $underlay) { | ||
| 26043 | |||
| 26044 | # Only one of each can exist in ->previousTagList, so we can stop searching now | ||
| 26045 | last OUTER; | ||
| 26046 | } | ||
| 26047 | } | ||
| 26048 | |||
| 26049 | if (! defined $text) { | ||
| 26050 | |||
| 26051 | # No colour tags were applied at the end of the last line, so the colours actually | ||
| 26052 | # displayed are the 'main' window's default colours (usually white) | ||
| 26053 | $text = $self->session->currentTabObj->textViewObj->textColour; | ||
| 26054 | } | ||
| 26055 | |||
| 26056 | if (! defined $underlay) { | ||
| 26057 | |||
| 26058 | $underlay = $self->session->currentTabObj->textViewObj->underlayColour; | ||
| 26059 | } | ||
| 26060 | |||
| 26061 | return ($text, $underlay); | ||
| 26062 | } | ||
| 26063 | |||
| 26064 | sub getColoursAtPosn { | ||
| 26065 | |||
| 26066 | # Called by $self->setRoomExit | ||
| 26067 | # The calling function is analysing a line of received text, but that line might have been | ||
| 26068 | # modified | ||
| 26069 | # For any modifications made, the hash of Axmud colour/style tags at each offset has also | ||
| 26070 | # been updated | ||
| 26071 | # This function works out the text and underlay tags that apply to a specified offset, and | ||
| 26072 | # returns them | ||
| 26073 | # | ||
| 26074 | # Expected arguments | ||
| 26075 | # $currentText - The Axmud text colour tag which applies either at the beginning of | ||
| 26076 | # the line, or before the first offset remaining in %offsetHash | ||
| 26077 | # $currentUnderlay | ||
| 26078 | # - The Axmud underlay colour tag which applies either at the beginning of | ||
| 26079 | # the line, or before the first offset remaining in %offsetHash | ||
| 26080 | # $currentBoldFlag | ||
| 26081 | # - Set to TRUE and FALSE by the presence/absence of 'bold' tags (default | ||
| 26082 | # value is FALSE) | ||
| 26083 | # $offset - Update the text and underlay colours using those that apply at this | ||
| 26084 | # offset | ||
| 26085 | # %offsetHash - Hash of Axmud colour/style tags, equivalent to $bufferObj->offsetHash, | ||
| 26086 | # but whose offsets have been updated as the line has been modified by | ||
| 26087 | # the calling function | ||
| 26088 | # | ||
| 26089 | # Return values | ||
| 26090 | # An empty list on improper arguments | ||
| 26091 | # Otherwise, returns a list in the form | ||
| 26092 | # ( | ||
| 26093 | # modified_text_colour_tag, modified_underlay_colour_tag, modified_bold_flag, | ||
| 26094 | # modified_offset_hash, | ||
| 26095 | # ) | ||
| 26096 | |||
| 26097 | my ($self, $currentText, $currentUnderlay, $currentBoldFlag, $offset, %offsetHash) = @_; | ||
| 26098 | |||
| 26099 | # Local variables | ||
| 26100 | my @emptyList; | ||
| 26101 | |||
| 26102 | # Check for improper arguments | ||
| 26103 | if ( | ||
| 26104 | ! defined $currentText && ! defined $currentUnderlay && ! defined $currentBoldFlag | ||
| 26105 | && ! defined $offset | ||
| 26106 | ) { | ||
| 26107 | $axmud::CLIENT->writeImproper($self->_objClass . '->getColoursAtPosn', @_); | ||
| 26108 | return @emptyList; | ||
| 26109 | } | ||
| 26110 | |||
| 26111 | # Go through each offset in %offsetHash until we reach the specified one, updating | ||
| 26112 | # $currentText and $currentUnderlay as we go | ||
| 26113 | foreach my $thisOffset (sort {$a <=> $b} (keys %offsetHash)) { | ||
| 26114 | |||
| 26115 | my $listRef; | ||
| 26116 | |||
| 26117 | if ($thisOffset > $offset) { | ||
| 26118 | |||
| 26119 | # We already have the colours that apply at the specified offset | ||
| 26120 | return ($currentText, $currentUnderlay, $currentBoldFlag, %offsetHash); | ||
| 26121 | } | ||
| 26122 | |||
| 26123 | $listRef = $offsetHash{$thisOffset}; | ||
| 26124 | foreach my $otherTag (@$listRef) { | ||
| 26125 | |||
| 26126 | my ($otherType, $underlayFlag); | ||
| 26127 | |||
| 26128 | if ($otherTag eq 'bold') { | ||
| 26129 | |||
| 26130 | # Convert 'blue' to 'BLUE', etc. Don't worry whether it's an xterm or RGB colour | ||
| 26131 | # tag, as they are both case-insensitive | ||
| 26132 | # 'bold' tags don't apply to underlay colours, of course | ||
| 26133 | $currentText = uc($currentText); | ||
| 26134 | $currentBoldFlag = TRUE; | ||
| 26135 | |||
| 26136 | } elsif ($otherTag eq 'bold_off' || $otherTag eq 'attribs_off') { | ||
| 26137 | |||
| 26138 | $currentText = lc($currentText); | ||
| 26139 | $currentBoldFlag = FALSE; | ||
| 26140 | |||
| 26141 | } else { | ||
| 26142 | |||
| 26143 | ($otherType, $underlayFlag) = $axmud::CLIENT->checkColourTags($otherTag); | ||
| 26144 | if ($otherType) { | ||
| 26145 | |||
| 26146 | if (! $underlayFlag) { | ||
| 26147 | |||
| 26148 | $currentText = $otherTag; | ||
| 26149 | if ($currentBoldFlag && $otherType eq 'standard' && ! $underlayFlag) { | ||
| 26150 | |||
| 26151 | $currentText = uc($currentText); | ||
| 26152 | } | ||
| 26153 | |||
| 26154 | } else { | ||
| 26155 | |||
| 26156 | $currentUnderlay = $otherTag; | ||
| 26157 | } | ||
| 26158 | } | ||
| 26159 | } | ||
| 26160 | } | ||
| 26161 | |||
| 26162 | # Once we've got the colour tags for this offset, we don't need to check it again | ||
| 26163 | delete $offsetHash{$thisOffset}; | ||
| 26164 | } | ||
| 26165 | |||
| 26166 | # Operation complete | ||
| 26167 | return ($currentText, $currentUnderlay, $currentBoldFlag, %offsetHash); | ||
| 26168 | } | ||
| 26169 | |||
| 26170 | sub trimColouredText { | ||
| 26171 | |||
| 26172 | # Called by $self->extractComponents when processing a component which has its | ||
| 26173 | # ->useTextColour IV set to any Axmud colour or underlay tag | ||
| 26174 | # Checks the text of a single display buffer line, and removes any text whose colour doesn't | ||
| 26175 | # match the colour specified by ->useTextColour. Updates the buffer object's hash of | ||
| 26176 | # offsets where Axmud colour/style tags are found to match the modified text | ||
| 26177 | # | ||
| 26178 | # NB If the component's ->boldSensitiveFlag is not set, normal and bold colours are treated | ||
| 26179 | # the same way | ||
| 26180 | # | ||
| 26181 | # Expected arguments | ||
| 26182 | # $bufferObj - A GA::Buffer::Display object. Normally the task would use the text in | ||
| 26183 | # $bufferObj->modLine; this function returns an alternative modified | ||
| 26184 | # line with all the escape sequences stripped away, and with any text | ||
| 26185 | # of the wrong colour also stripped away | ||
| 26186 | # $componentObj - The GA::Obj::Component object for this line | ||
| 26187 | # | ||
| 26188 | # Return values | ||
| 26189 | # An empty list on improper arguments or if there is no text on the line that uses the | ||
| 26190 | # component's specified colour tag | ||
| 26191 | # Otherwise, returns a list in the form | ||
| 26192 | # (modified_text, modified_offset_hash) | ||
| 26193 | |||
| 26194 | my ($self, $bufferObj, $componentObj, $check) = @_; | ||
| 26195 | |||
| 26196 | # Local variables | ||
| 26197 | my ( | ||
| 26198 | $tag, $lineLen, $boldFlag, $currentText, $currentUnderlay, $modText, | ||
| 26199 | @emptyList, @useOffsetList, @disposeOffsetList, | ||
| 26200 | %offsetHash, %modOffsetHash, | ||
| 26201 | ); | ||
| 26202 | |||
| 26203 | # Check for improper arguments | ||
| 26204 | if (! defined $bufferObj || ! defined $componentObj || defined $check) { | ||
| 26205 | |||
| 26206 | $axmud::CLIENT->writeImproper($self->_objClass . '->trimColouredText', @_); | ||
| 26207 | return @emptyList; | ||
| 26208 | } | ||
| 26209 | |||
| 26210 | # We only want to keep text using this Axmud colour tag | ||
| 26211 | $tag = $componentObj->useTextColour; | ||
| 26212 | # Set the line length once, for quick lookup | ||
| 26213 | $lineLen = length($bufferObj->modLine); | ||
| 26214 | |||
| 26215 | # Import the buffer object's hash of Axmud colour/style tags, which is in the form | ||
| 26216 | # $offsetHash{offset} = reference_to_list_of_tags_that_occur_there | ||
| 26217 | %offsetHash = $bufferObj->offsetHash; | ||
| 26218 | |||
| 26219 | # Get the colours that apply at the start of the line | ||
| 26220 | OUTER: foreach my $startTag ($bufferObj->previousTagList) { | ||
| 26221 | |||
| 26222 | if ($axmud::CLIENT->checkTextTags($startTag)) { | ||
| 26223 | $currentText = $startTag; | ||
| 26224 | } elsif ($axmud::CLIENT->checkUnderlayTags($startTag)) { | ||
| 26225 | $currentUnderlay = $startTag; | ||
| 26226 | } | ||
| 26227 | |||
| 26228 | if ($currentText && $currentUnderlay) { | ||
| 26229 | |||
| 26230 | # Only one of each can exist in ->previousTagList, so we can stop searching now | ||
| 26231 | last OUTER; | ||
| 26232 | } | ||
| 26233 | } | ||
| 26234 | |||
| 26235 | if (! defined $currentText) { | ||
| 26236 | |||
| 26237 | # No text colour tags were applied at the end of the last line, so the colours actually | ||
| 26238 | # displayed are the textview object's default colours (usually white) | ||
| 26239 | $currentText = $self->session->currentTabObj->textViewObj->textColour; | ||
| 26240 | } | ||
| 26241 | |||
| 26242 | if (! defined $currentUnderlay) { | ||
| 26243 | |||
| 26244 | # Ditto for underlays | ||
| 26245 | $currentUnderlay = $self->session->currentTabObj->textViewObj->underlayColour; | ||
| 26246 | } | ||
| 26247 | |||
| 26248 | if ($currentText eq $tag || $currentUnderlay eq $tag) { | ||
| 26249 | |||
| 26250 | # Items in @useOffsetList are list references. Each list reference contain two items (a | ||
| 26251 | # start offset and a stop offset), marking a portion of the text in the colour we're | ||
| 26252 | # searching for | ||
| 26253 | # The following line assumes the previous line's colour applies to the whole of this | ||
| 26254 | # line. If any more colour tags are found, we'll replace the 'stop' offset | ||
| 26255 | push (@useOffsetList, [0, $lineLen]); | ||
| 26256 | } | ||
| 26257 | |||
| 26258 | # Now, go through the offsets at which tags occur, looking for occurences of $tag | ||
| 26259 | @disposeOffsetList = sort {$a <=> $b} (keys %offsetHash); | ||
| 26260 | foreach my $offset (@disposeOffsetList) { | ||
| 26261 | |||
| 26262 | my ($tagListRef, $otherType, $underlayFlag, $miniListRef); | ||
| 26263 | |||
| 26264 | $tagListRef = $offsetHash{$offset}; | ||
| 26265 | |||
| 26266 | foreach my $otherTag (@$tagListRef) { | ||
| 26267 | |||
| 26268 | if ($otherTag eq 'bold') { | ||
| 26269 | |||
| 26270 | $boldFlag = TRUE; | ||
| 26271 | $currentText = uc($currentText); | ||
| 26272 | |||
| 26273 | } elsif ($otherTag eq 'bold_off') { | ||
| 26274 | |||
| 26275 | $boldFlag = FALSE; | ||
| 26276 | $currentText = lc($currentText); | ||
| 26277 | |||
| 26278 | } elsif ($otherTag eq 'attribs_off') { | ||
| 26279 | |||
| 26280 | $boldFlag = FALSE; | ||
| 26281 | $currentText = $self->session->currentTabObj->textViewObj->textColour; | ||
| 26282 | |||
| 26283 | } else { | ||
| 26284 | |||
| 26285 | ($otherType, $underlayFlag) = $axmud::CLIENT->checkColourTags($otherTag); | ||
| 26286 | if ($otherType) { | ||
| 26287 | |||
| 26288 | if (! $underlayFlag) { | ||
| 26289 | $currentText = $otherTag; | ||
| 26290 | } else { | ||
| 26291 | $currentUnderlay = $otherTag; | ||
| 26292 | } | ||
| 26293 | |||
| 26294 | if ($boldFlag && $otherType eq 'standard' && ! $underlayFlag) { | ||
| 26295 | |||
| 26296 | $currentText = uc($otherTag); | ||
| 26297 | } | ||
| 26298 | } | ||
| 26299 | } | ||
| 26300 | } | ||
| 26301 | |||
| 26302 | # Items in @useOffsetList are list references. Each list reference contain two items (a | ||
| 26303 | # start offset and a stop offset), marking a portion of the text in the colour we're | ||
| 26304 | # searching for | ||
| 26305 | if ( | ||
| 26306 | ( | ||
| 26307 | $currentText | ||
| 26308 | && ( | ||
| 26309 | $currentText eq $tag | ||
| 26310 | || (! $componentObj->boldSensitiveFlag && lc($currentText) eq lc($tag)) | ||
| 26311 | ) | ||
| 26312 | ) || ( | ||
| 26313 | $currentUnderlay | ||
| 26314 | && ( | ||
| 26315 | $currentUnderlay eq $tag | ||
| 26316 | || (! $componentObj->boldSensitiveFlag && lc($currentUnderlay) eq lc($tag)) | ||
| 26317 | ) | ||
| 26318 | ) | ||
| 26319 | ) { | ||
| 26320 | $miniListRef = $useOffsetList[-1]; | ||
| 26321 | # v1.2.043 - the line below appears to be an error, but I'm not sure yet | ||
| 26322 | # if (! defined $miniListRef || ! defined $$miniListRef[1]) { | ||
| 26323 | if (! defined $miniListRef || defined $$miniListRef[1]) { | ||
| 26324 | |||
| 26325 | # This is a 'start' | ||
| 26326 | $miniListRef = [$offset, $lineLen]; | ||
| 26327 | push (@useOffsetList, $miniListRef); | ||
| 26328 | } | ||
| 26329 | |||
| 26330 | } elsif ( | ||
| 26331 | ( | ||
| 26332 | $currentText | ||
| 26333 | && ( | ||
| 26334 | ($componentObj->boldSensitiveFlag && $currentText ne $tag) | ||
| 26335 | || (! $componentObj->boldSensitiveFlag && lc($currentText) ne lc($tag)) | ||
| 26336 | ) | ||
| 26337 | ) || ( | ||
| 26338 | $currentUnderlay | ||
| 26339 | && ( | ||
| 26340 | ($componentObj->boldSensitiveFlag && $currentUnderlay ne $tag) | ||
| 26341 | || (! $componentObj->boldSensitiveFlag && lc($currentUnderlay) ne lc($tag)) | ||
| 26342 | ) | ||
| 26343 | ) | ||
| 26344 | ) { | ||
| 26345 | $miniListRef = $useOffsetList[-1]; | ||
| 26346 | if (defined $miniListRef) { | ||
| 26347 | |||
| 26348 | # A 'start' and 'stop' could occur at the same offset, in which case they cancel | ||
| 26349 | # each other at | ||
| 26350 | if (defined $$miniListRef[0] && $$miniListRef[0] == $offset) { | ||
| 26351 | |||
| 26352 | pop @useOffsetList; | ||
| 26353 | |||
| 26354 | } elsif (! defined $$miniListRef[1] || $$miniListRef[1] > $offset) { | ||
| 26355 | # This is a 'stop', which replaces any 'stop' from later in the line (such | ||
| 26356 | # as one we added to @useOffsetList near the beginning of this function) | ||
| 26357 | $$miniListRef[1] = $offset; | ||
| 26358 | } | ||
| 26359 | } | ||
| 26360 | } | ||
| 26361 | } | ||
| 26362 | |||
| 26363 | if (! @useOffsetList) { | ||
| 26364 | |||
| 26365 | # Line contained no text of the right colour | ||
| 26366 | return @emptyList; | ||
| 26367 | } | ||
| 26368 | |||
| 26369 | # Compile a string consisting of all the line portions in the right colour. Also update | ||
| 26370 | # %offsetHash so that it matches the modified string | ||
| 26371 | $modText = ''; | ||
| 26372 | do { | ||
| 26373 | |||
| 26374 | my ($miniListRef, $start, $stop); | ||
| 26375 | |||
| 26376 | $miniListRef = shift @useOffsetList; | ||
| 26377 | $start = shift @$miniListRef; | ||
| 26378 | $stop = shift @$miniListRef; | ||
| 26379 | |||
| 26380 | OUTER: foreach my $offset (@disposeOffsetList) { | ||
| 26381 | |||
| 26382 | if ($offset < $start) { | ||
| 26383 | |||
| 26384 | # This offset occurs before $start, so ignore it | ||
| 26385 | shift @disposeOffsetList; | ||
| 26386 | next OUTER; | ||
| 26387 | |||
| 26388 | } elsif ($offset <= $stop) { | ||
| 26389 | |||
| 26390 | # This offset occurs within the text of the right colour, so preserve its | ||
| 26391 | # Axmud colour/style tags at their new position | ||
| 26392 | shift @disposeOffsetList; | ||
| 26393 | $modOffsetHash{$offset - length($modText)} = $offsetHash{$offset}; | ||
| 26394 | |||
| 26395 | } else { | ||
| 26396 | |||
| 26397 | # This offset occurs after $stop; process it on the next do... loop | ||
| 26398 | last OUTER; | ||
| 26399 | } | ||
| 26400 | } | ||
| 26401 | |||
| 26402 | if (! defined $stop) { | ||
| 26403 | $modText .= substr($bufferObj->modLine, $start); | ||
| 26404 | } elsif ($stop > $start) { | ||
| 26405 | $modText .= substr($bufferObj->modLine, $start, ($stop - $start)); | ||
| 26406 | } | ||
| 26407 | |||
| 26408 | } until (! @useOffsetList); | ||
| 26409 | |||
| 26410 | return ($modText, %modOffsetHash); | ||
| 26411 | } | ||
| 26412 | |||
| 26413 | sub combineLines { | ||
| 26414 | |||
| 26415 | # Called by $self->extractComponents when processing a component which has its | ||
| 26416 | # ->combineLinesFlag IV set | ||
| 26417 | # Combines the text of the lines into a single string. Also combines the hashes of offsets | ||
| 26418 | # where Axmud colour/style tags occur into a single hash matching the single string | ||
| 26419 | # | ||
| 26420 | # Expected arguments | ||
| 26421 | # $lineTextListRef - Reference to a list of strings, each representing text on a single | ||
| 26422 | # line | ||
| 26423 | # $lineOffsetListRef - Reference to a corresponding list of hash references, containing | ||
| 26424 | # offsets on each line where Axmud colour/style tags occur. Those | ||
| 26425 | # hashes are in the form | ||
| 26426 | # $hash{offset} = reference_to_list_of_Axmud_colour_&_style_tags | ||
| 26427 | # | ||
| 26428 | # Return values | ||
| 26429 | # 'undef' on improper arguments | ||
| 26430 | # 1 otherwise (for which the contents of the two list references have been modifed) | ||
| 26431 | |||
| 26432 | my ($self, $lineTextListRef, $lineOffsetListRef, $check) = @_; | ||
| 26433 | |||
| 26434 | # Local variables | ||
| 26435 | my ( | ||
| 26436 | $modText, | ||
| 26437 | %modOffsetHash, | ||
| 26438 | ); | ||
| 26439 | |||
| 26440 | # Check for improper arguments | ||
| 26441 | if (! defined $lineTextListRef || ! defined $lineOffsetListRef || defined $check) { | ||
| 26442 | |||
| 26443 | return $axmud::CLIENT->writeImproper($self->_objClass . '->combineLines', @_); | ||
| 26444 | } | ||
| 26445 | |||
| 26446 | if (@$lineTextListRef) { | ||
| 26447 | |||
| 26448 | $modText = ''; | ||
| 26449 | |||
| 26450 | do { | ||
| 26451 | |||
| 26452 | my ($text, $hashRef); | ||
| 26453 | |||
| 26454 | $text = shift @$lineTextListRef; | ||
| 26455 | $hashRef = shift @$lineOffsetListRef; | ||
| 26456 | |||
| 26457 | foreach my $offset (keys %$hashRef) { | ||
| 26458 | |||
| 26459 | $modOffsetHash{$offset + length($modText)} = $$hashRef{$offset}; | ||
| 26460 | } | ||
| 26461 | |||
| 26462 | if ($modText eq '') { | ||
| 26463 | $modText = $text; | ||
| 26464 | } else { | ||
| 26465 | $modText .= ' ' . $text; | ||
| 26466 | } | ||
| 26467 | |||
| 26468 | } until (! @$lineTextListRef); | ||
| 26469 | } | ||
| 26470 | |||
| 26471 | # Update the list references supplied as arguments, so we don't need to return them as | ||
| 26472 | # values | ||
| 26473 | @$lineTextListRef = ($modText); | ||
| 26474 | @$lineOffsetListRef = (\%modOffsetHash); | ||
| 26475 | |||
| 26476 | return 1; | ||
| 26477 | } | ||
| 26478 | |||
| 26479 | sub reduceLineFromStart { | ||
| 26480 | |||
| 26481 | # Called by $self->extractComponents when processing a component which has its | ||
| 26482 | # ->ignoreFirstChars IV set | ||
| 26483 | # Removes the first n characters from each line (leaving an empty string, if necessary). | ||
| 26484 | # Also updates the hashes of offsets where Axmud colour/style tags occur to match the | ||
| 26485 | # modified strings | ||
| 26486 | # | ||
| 26487 | # Expected arguments | ||
| 26488 | # $lineTextListRef - Reference to a list of strings, each representing text on a single | ||
| 26489 | # line | ||
| 26490 | # $lineOffsetListRef - Reference to a corresponding list of hash references, containing | ||
| 26491 | # offsets on each line where Axmud colour/style tags occur. Those | ||
| 26492 | # hashes are in the form | ||
| 26493 | # $hash{offset} = reference_to_list_of_Axmud_colour_&_style_tags | ||
| 26494 | # $number - The number of characters to remove from the beginning of each | ||
| 26495 | # line | ||
| 26496 | # | ||
| 26497 | # Return values | ||
| 26498 | # 'undef' on improper arguments | ||
| 26499 | # 1 otherwise (for which the contents of the two list references have been modifed) | ||
| 26500 | |||
| 26501 | my ($self, $lineTextListRef, $lineOffsetListRef, $number, $check) = @_; | ||
| 26502 | |||
| 26503 | # Local variables | ||
| 26504 | my (@modLineTextList, @modLineOffsetList); | ||
| 26505 | |||
| 26506 | # Check for improper arguments | ||
| 26507 | if ( | ||
| 26508 | ! defined $lineTextListRef || ! defined $lineOffsetListRef || ! defined $number | ||
| 26509 | || defined $check | ||
| 26510 | ) { | ||
| 26511 | return $axmud::CLIENT->writeImproper($self->_objClass . '->reduceLineFromStart', @_); | ||
| 26512 | } | ||
| 26513 | |||
| 26514 | if (@$lineTextListRef) { | ||
| 26515 | |||
| 26516 | do { | ||
| 26517 | |||
| 26518 | my ( | ||
| 26519 | $text, $hashRef, | ||
| 26520 | %modHash, | ||
| 26521 | ); | ||
| 26522 | |||
| 26523 | $text = shift @$lineTextListRef; | ||
| 26524 | $hashRef = shift @$lineOffsetListRef; | ||
| 26525 | |||
| 26526 | if (length ($text) >= $number) { | ||
| 26527 | $text = substr($text, $number); | ||
| 26528 | } else { | ||
| 26529 | $text = ''; | ||
| 26530 | } | ||
| 26531 | |||
| 26532 | foreach my $offset (keys %$hashRef) { | ||
| 26533 | |||
| 26534 | if ($offset >= $number) { | ||
| 26535 | |||
| 26536 | $modHash{$offset - $number} = $$hashRef{$offset}; | ||
| 26537 | } | ||
| 26538 | } | ||
| 26539 | |||
| 26540 | push (@modLineTextList, $text); | ||
| 26541 | push (@modLineOffsetList, \%modHash); | ||
| 26542 | |||
| 26543 | } until (! @$lineTextListRef); | ||
| 26544 | } | ||
| 26545 | |||
| 26546 | # Update the list references supplied as arguments, so we don't need to return them as | ||
| 26547 | # values | ||
| 26548 | @$lineTextListRef = @modLineTextList; | ||
| 26549 | @$lineOffsetListRef = @modLineOffsetList; | ||
| 26550 | |||
| 26551 | return 1; | ||
| 26552 | } | ||
| 26553 | |||
| 26554 | sub reduceLineFromEnd { | ||
| 26555 | |||
| 26556 | # Called by $self->extractComponents when processing a component which has its | ||
| 26557 | # ->useFirstChars IV set | ||
| 26558 | # Removes everything after the first n characters from each line. Also updates the hashes of | ||
| 26559 | # offsets where Axmud colour/style tags occur to match the modified strings | ||
| 26560 | # | ||
| 26561 | # Expected arguments | ||
| 26562 | # $lineTextListRef - Reference to a list of strings, each representing text on a single | ||
| 26563 | # line | ||
| 26564 | # $lineOffsetListRef - Reference to a corresponding list of hash references, containing | ||
| 26565 | # offsets on each line where Axmud colour/style tags occur. Those | ||
| 26566 | # hashes are in the form | ||
| 26567 | # $hash{offset} = reference_to_list_of_Axmud_colour_&_style_tags | ||
| 26568 | # $number - The number of characters to preserve at the beginning of each line | ||
| 26569 | # | ||
| 26570 | # Return values | ||
| 26571 | # 'undef' on improper arguments | ||
| 26572 | # 1 otherwise (for which the contents of the two list references have been modifed) | ||
| 26573 | |||
| 26574 | my ($self, $lineTextListRef, $lineOffsetListRef, $number, $check) = @_; | ||
| 26575 | |||
| 26576 | # Local variables | ||
| 26577 | my (@modLineTextList, @modLineOffsetList); | ||
| 26578 | |||
| 26579 | # Check for improper arguments | ||
| 26580 | if ( | ||
| 26581 | ! defined $lineTextListRef || ! defined $lineOffsetListRef || ! defined $number | ||
| 26582 | || defined $check | ||
| 26583 | ) { | ||
| 26584 | return $axmud::CLIENT->writeImproper($self->_objClass . '->reduceLineFromEnd', @_); | ||
| 26585 | } | ||
| 26586 | |||
| 26587 | if (@$lineTextListRef) { | ||
| 26588 | |||
| 26589 | do { | ||
| 26590 | |||
| 26591 | my ( | ||
| 26592 | $text, $hashRef, | ||
| 26593 | %modHash, | ||
| 26594 | ); | ||
| 26595 | |||
| 26596 | $text = shift @$lineTextListRef; | ||
| 26597 | $hashRef = shift @$lineOffsetListRef; | ||
| 26598 | |||
| 26599 | if (length ($text) >= $number) { | ||
| 26600 | |||
| 26601 | $text = substr($text, 0, $number); | ||
| 26602 | } | ||
| 26603 | |||
| 26604 | foreach my $offset (keys %$hashRef) { | ||
| 26605 | |||
| 26606 | if ($offset < $number) { | ||
| 26607 | |||
| 26608 | $modHash{$offset} = $$hashRef{$offset}; | ||
| 26609 | } | ||
| 26610 | } | ||
| 26611 | |||
| 26612 | push (@modLineTextList, $text); | ||
| 26613 | push (@modLineOffsetList, \%modHash); | ||
| 26614 | |||
| 26615 | } until (! @$lineTextListRef); | ||
| 26616 | } | ||
| 26617 | |||
| 26618 | # Update the list references supplied as arguments, so we don't need to return them as | ||
| 26619 | # values | ||
| 26620 | @$lineTextListRef = @modLineTextList; | ||
| 26621 | @$lineOffsetListRef = @modLineOffsetList; | ||
| 26622 | |||
| 26623 | return 1; | ||
| 26624 | } | ||
| 26625 | |||
| 26626 | sub reduceLineUsingRegex { | ||
| 26627 | |||
| 26628 | # Called by $self->extractComponents when processing a component which has its | ||
| 26629 | # ->usePatternGroups IV set | ||
| 26630 | # Tests a regex against each line. If the lines matches, this function removes everything | ||
| 26631 | # except the group substrings. Also updates the hashes of offsets where Axmud colour/style | ||
| 26632 | # tags occur to match the modified strings | ||
| 26633 | # | ||
| 26634 | # Expected arguments | ||
| 26635 | # $lineTextListRef - Reference to a list of strings, each representing text on a single | ||
| 26636 | # line | ||
| 26637 | # $lineOffsetListRef - Reference to a corresponding list of hash references, containing | ||
| 26638 | # offsets on each line where Axmud colour/style tags occur. Those | ||
| 26639 | # hashes are in the form | ||
| 26640 | # $hash{offset} = reference_to_list_of_Axmud_colour_&_style_tags | ||
| 26641 | # $regex - The regex to use (which is assumed to contain at least one | ||
| 26642 | # substring) | ||
| 26643 | # | ||
| 26644 | # Return values | ||
| 26645 | # 'undef' on improper arguments | ||
| 26646 | # 1 otherwise (for which the contents of the two list references have been modifed) | ||
| 26647 | |||
| 26648 | my ($self, $lineTextListRef, $lineOffsetListRef, $regex, $check) = @_; | ||
| 26649 | |||
| 26650 | # Local variables | ||
| 26651 | my (@modLineTextList, @modLineOffsetList); | ||
| 26652 | |||
| 26653 | # Check for improper arguments | ||
| 26654 | if ( | ||
| 26655 | ! defined $lineTextListRef || ! defined $lineOffsetListRef || ! defined $regex | ||
| 26656 | || defined $check | ||
| 26657 | ) { | ||
| 26658 | return $axmud::CLIENT->writeImproper($self->_objClass . '->reduceLineUsingRegex', @_); | ||
| 26659 | } | ||
| 26660 | |||
| 26661 | if (@$lineTextListRef) { | ||
| 26662 | |||
| 26663 | do { | ||
| 26664 | |||
| 26665 | my ( | ||
| 26666 | $text, $modText, $hashRef, | ||
| 26667 | @grpStringList, @matchMinusList, @matchPlusList, @discardList, | ||
| 26668 | %modOffsetHash, | ||
| 26669 | ); | ||
| 26670 | |||
| 26671 | $text = shift @$lineTextListRef; | ||
| 26672 | $hashRef = shift @$lineOffsetListRef; | ||
| 26673 | |||
| 26674 | @grpStringList = ($text =~ m/$regex/); | ||
| 26675 | if (@grpStringList) { | ||
| 26676 | |||
| 26677 | @matchMinusList = @-; | ||
| 26678 | @matchPlusList = @+; | ||
| 26679 | |||
| 26680 | $modText = join('', @grpStringList); | ||
| 26681 | # In case the combined group substrings contain no text, restore the | ||
| 26682 | # original line | ||
| 26683 | if ($modText eq '') { | ||
| 26684 | |||
| 26685 | push (@modLineTextList, $text); | ||
| 26686 | push (@modLineOffsetList, $hashRef); | ||
| 26687 | |||
| 26688 | } else { | ||
| 26689 | |||
| 26690 | # Now update the hashes that contain the offsets on each line where Axmud | ||
| 26691 | # colour/style tags occur | ||
| 26692 | # @matchMinusList contains the offsets where each group substring in | ||
| 26693 | # @grpStringList occurs, and @matchPlusList contains the offsets | ||
| 26694 | # immediately after the group substring | ||
| 26695 | # e.g. You are in a twisty maze of passages | ||
| 26696 | # ^^^^^^^^^^^ | ||
| 26697 | # 0123456789012345678901234567890123456789 | ||
| 26698 | # Group substring 'twisty maze', offsets are 13 and 24 | ||
| 26699 | |||
| 26700 | # The first element in each list are the offets of the whole matching | ||
| 26701 | # portion of $text, so we can discard them immediately | ||
| 26702 | shift @matchMinusList; | ||
| 26703 | shift @matchPlusList; | ||
| 26704 | # The offsets at which Axmud colour/style tags occur can be discarded from | ||
| 26705 | # this list as they're processed | ||
| 26706 | @discardList = sort {$a <=> $b} (keys %$hashRef); | ||
| 26707 | $modText = ''; | ||
| 26708 | |||
| 26709 | do { | ||
| 26710 | |||
| 26711 | my ($start, $stop, $string); | ||
| 26712 | |||
| 26713 | $start = shift @matchMinusList; | ||
| 26714 | $stop = shift @matchPlusList; | ||
| 26715 | $string = shift @grpStringList; | ||
| 26716 | |||
| 26717 | OUTER: foreach my $offset (@discardList) { | ||
| 26718 | |||
| 26719 | if ($offset < $start) { | ||
| 26720 | |||
| 26721 | # This offset occurs before $start, so ignore it | ||
| 26722 | shift @discardList; | ||
| 26723 | next OUTER; | ||
| 26724 | |||
| 26725 | } elsif ($offset <= $stop) { | ||
| 26726 | |||
| 26727 | # This offset occurs within group substring, so preserve its | ||
| 26728 | # Axmud colour/style tags at their new position | ||
| 26729 | shift @discardList; | ||
| 26730 | $modOffsetHash{$offset - length($modText)} = $$hashRef{$offset}; | ||
| 26731 | |||
| 26732 | } else { | ||
| 26733 | |||
| 26734 | # This offset occurs after $stop; process it on the next do... | ||
| 26735 | # loop | ||
| 26736 | last OUTER; | ||
| 26737 | } | ||
| 26738 | } | ||
| 26739 | |||
| 26740 | # Combined the group substrings into a single string as we go, so we | ||
| 26741 | # know how to adjust the offsets in %hashRef | ||
| 26742 | $modText .= $string; | ||
| 26743 | |||
| 26744 | } until (! @matchMinusList); | ||
| 26745 | |||
| 26746 | push (@modLineTextList, $modText); | ||
| 26747 | push (@modLineOffsetList, \%modOffsetHash); | ||
| 26748 | } | ||
| 26749 | |||
| 26750 | } else { | ||
| 26751 | |||
| 26752 | # Line doesn't match, so preserve the whole line | ||
| 26753 | push (@modLineTextList, $text); | ||
| 26754 | push (@modLineOffsetList, $hashRef); | ||
| 26755 | } | ||
| 26756 | |||
| 26757 | } until (! @$lineTextListRef); | ||
| 26758 | } | ||
| 26759 | |||
| 26760 | # Update the list references supplied as arguments, so we don't need to return them as | ||
| 26761 | # values | ||
| 26762 | @$lineTextListRef = @modLineTextList; | ||
| 26763 | @$lineOffsetListRef = @modLineOffsetList; | ||
| 26764 | |||
| 26765 | return 1; | ||
| 26766 | } | ||
| 26767 | |||
| 26768 | sub checkLineValid { | ||
| 26769 | |||
| 26770 | # Called by $self->extractLines | ||
| 26771 | # Given a display buffer line number, check that it isn't outside the display buffer (i.e. | ||
| 26772 | # that the line actually exists), and is not within the bounds of a previously-found room | ||
| 26773 | # statement | ||
| 26774 | # | ||
| 26775 | # Expected arguments | ||
| 26776 | # $lineNum - The display buffer line number to check | ||
| 26777 | # | ||
| 26778 | # Return values | ||
| 26779 | # An empty list on improper arguments, if the buffer line is within a previously-found | ||
| 26780 | # room statement or if the buffer line doesn't exist | ||
| 26781 | # Otherwise returns a list in the form | ||
| 26782 | # (text_buffer_line, corresponding_text_buffer_object) | ||
| 26783 | |||
| 26784 | my ($self, $lineNum, $check) = @_; | ||
| 26785 | |||
| 26786 | # Local variables | ||
| 26787 | my ( | ||
| 26788 | $bufferObj, | ||
| 26789 | @emptyList, | ||
| 26790 | ); | ||
| 26791 | |||
| 26792 | # Check for improper arguments | ||
| 26793 | if (! defined $lineNum || defined $check) { | ||
| 26794 | |||
| 26795 | $axmud::CLIENT->writeImproper($self->_objClass . '->checkLineValid', @_); | ||
| 26796 | return @emptyList; | ||
| 26797 | } | ||
| 26798 | |||
| 26799 | if ( | ||
| 26800 | $self->roomCount | ||
| 26801 | && $self->lastStatementEndLine | ||
| 26802 | && $lineNum <= $self->lastStatementEndLine | ||
| 26803 | ) { | ||
| 26804 | # Line already searched | ||
| 26805 | return @emptyList; | ||
| 26806 | } | ||
| 26807 | |||
| 26808 | # Get the corresponding GA::Buffer::Display object | ||
| 26809 | $bufferObj = $self->session->ivShow('displayBufferHash', $lineNum); | ||
| 26810 | if (! $bufferObj) { | ||
| 26811 | |||
| 26812 | # Line doesn't exist | ||
| 26813 | return @emptyList; | ||
| 26814 | |||
| 26815 | } else { | ||
| 26816 | |||
| 26817 | # Return the text of the line | ||
| 26818 | return ($bufferObj->modLine, $bufferObj); | ||
| 26819 | } | ||
| 26820 | } | ||
| 26821 | |||
| 26822 | sub checkLineTags { | ||
| 26823 | |||
| 26824 | # Called by $self->extractLines | ||
| 26825 | # Given a display buffer line object, checks the contents of the object's ->tagHash. If the | ||
| 26826 | # hash contains any Axmud colour/style tags (not including the dummy tags like 'bold', | ||
| 26827 | # 'reverse_off' and 'attribs_off'), returns 1 | ||
| 26828 | # | ||
| 26829 | # Expected arguments | ||
| 26830 | # $lineObj - The GA::Buffer::Display to check | ||
| 26831 | # | ||
| 26832 | # Return values | ||
| 26833 | # 'undef' on improper arguments or if the object contains no Axmud colour/style tags | ||
| 26834 | # (besides the dummy tags like 'bold', 'reverse_off' and 'attribs_off') | ||
| 26835 | # 1 otherwise | ||
| 26836 | |||
| 26837 | my ($self, $lineObj, $check) = @_; | ||
| 26838 | |||
| 26839 | # Check for improper arguments | ||
| 26840 | if (! defined $lineObj || defined $check) { | ||
| 26841 | |||
| 26842 | return $axmud::CLIENT->writeImproper($self->_objClass . '->checkLineTags', @_); | ||
| 26843 | } | ||
| 26844 | |||
| 26845 | foreach my $tag ($lineObj->ivKeys('tagHash')) { | ||
| 26846 | |||
| 26847 | if (! $axmud::CLIENT->ivExists('constDummyTagHash', $tag)) { | ||
| 26848 | |||
| 26849 | # The object contains at least one Axmud colour/style tag | ||
| 26850 | return 1; | ||
| 26851 | } | ||
| 26852 | } | ||
| 26853 | |||
| 26854 | # The object contains no Axmud colour/style tags (apart from dummy tags, if any) | ||
| 26855 | return undef; | ||
| 26856 | } | ||
| 26857 | |||
| 26858 | sub haltAnalysis { | ||
| 26859 | |||
| 26860 | # Called by $self->processLine (at stage 3) when the task is looking for its first room | ||
| 26861 | # statement, but finds a failed exit pattern or an involuntary exit pattern | ||
| 26862 | # | ||
| 26863 | # Expected arguments | ||
| 26864 | # $type - 'fail_exit' or 'involuntary' | ||
| 26865 | # | ||
| 26866 | # Return values | ||
| 26867 | # 'undef' | ||
| 26868 | |||
| 26869 | my ($self, $type, $check) = @_; | ||
| 26870 | |||
| 26871 | # Check for improper arguments | ||
| 26872 | if (! defined $type || ($type ne 'fail_exit' && $type ne 'involuntary') || defined $check) { | ||
| 26873 | |||
| 26874 | return $axmud::CLIENT->writeImproper($self->_objClass . '->haltAnalysis', @_); | ||
| 26875 | } | ||
| 26876 | |||
| 26877 | # Empty the command lists, since none of them matter now | ||
| 26878 | $self->ivEmpty('moveList'); | ||
| 26879 | $self->ivEmpty('cmdObjList'); | ||
| 26880 | $self->ivUndef('prevCmdBufferNum'); | ||
| 26881 | |||
| 26882 | # Set flags that other parts of the Axmud code can consult frequently, to see if there's | ||
| 26883 | # been a failed exit (etc) or not | ||
| 26884 | if ($type eq 'fail_exit') { | ||
| 26885 | $self->ivPoke('failExitFlag', TRUE); | ||
| 26886 | } elsif ($type eq 'involuntary') { | ||
| 26887 | $self->ivPoke('involuntaryExitFlag', TRUE); | ||
| 26888 | } | ||
| 26889 | |||
| 26890 | # Update the task window | ||
| 26891 | if ($self->taskWinFlag) { | ||
| 26892 | |||
| 26893 | $self->refreshWin(); | ||
| 26894 | } | ||
| 26895 | |||
| 26896 | # Don't search any more lines for anchor lines until the next task loop | ||
| 26897 | return undef; | ||
| 26898 | } | ||
| 26899 | |||
| 26900 | sub removeFirstMove { | ||
| 26901 | |||
| 26902 | # Called by $self->processLine (at stage 3) | ||
| 26903 | # Whenever a world command is sent, a GA::Buffer::Cmd object is created, and that object | ||
| 26904 | # is stored in $self->cmdObjList. In most cases, each world command gets its own buffer | ||
| 26905 | # object, but for assisted moves, a sequence of one or more world commands (comprising a | ||
| 26906 | # single assisted move) is assigned to a single buffer object | ||
| 26907 | # If it's a look, glance or movement command, the object is also stored in $self->moveList | ||
| 26908 | # (movement commands include redirect mode commands and assisted moves) | ||
| 26909 | # | ||
| 26910 | # The calling function can specify a GA::Buffer::Cmd object, which should exist in | ||
| 26911 | # $self->cmdObjList, and be the first item in $self->moveList. If so, remove everything in | ||
| 26912 | # both lists up to (and including) that object | ||
| 26913 | # If the calling function doesn't specify a GA::Buffer::Cmd object, empty both lists (as we | ||
| 26914 | # have no further use for their contents) | ||
| 26915 | # | ||
| 26916 | # Expected arguments | ||
| 26917 | # (none besides $self) | ||
| 26918 | # | ||
| 26919 | # Optional arguments | ||
| 26920 | # $cmdObj - The GA::Buffer::Cmd object to remove (or 'undef' to empty both lists) | ||
| 26921 | # | ||
| 26922 | # Return values | ||
| 26923 | # 'undef' on improper arguments or if there's an error | ||
| 26924 | # 1 otherwise | ||
| 26925 | |||
| 26926 | my ($self, $cmdObj, $check) = @_; | ||
| 26927 | |||
| 26928 | # Local variables | ||
| 26929 | my ( | ||
| 26930 | $matchFlag, | ||
| 26931 | @cmdObjList, @moveList, | ||
| 26932 | ); | ||
| 26933 | |||
| 26934 | # Check for improper arguments | ||
| 26935 | if (defined $check) { | ||
| 26936 | |||
| 26937 | return $axmud::CLIENT->writeImproper($self->_objClass . '->removeFirstMove', @_); | ||
| 26938 | } | ||
| 26939 | |||
| 26940 | if (! $cmdObj) { | ||
| 26941 | |||
| 26942 | # Just empty both lists | ||
| 26943 | $self->ivEmpty('cmdObjList'); | ||
| 26944 | $self->ivEmpty('moveList'); | ||
| 26945 | $self->ivUndef('prevCmdBufferNum'); | ||
| 26946 | |||
| 26947 | # Update the task window's title bar (if open) | ||
| 26948 | $self->prepareTitleBar(); | ||
| 26949 | |||
| 26950 | return 1; | ||
| 26951 | } | ||
| 26952 | |||
| 26953 | # Import the move lists | ||
| 26954 | @cmdObjList = $self->cmdObjList; | ||
| 26955 | @moveList = $self->moveList; | ||
| 26956 | |||
| 26957 | # First check @cmdObjList | ||
| 26958 | OUTER: for (my $count = 0; $count < scalar @cmdObjList; $count++) { | ||
| 26959 | |||
| 26960 | my $thisObj = $cmdObjList[$count]; | ||
| 26961 | |||
| 26962 | if ($thisObj eq $cmdObj) { | ||
| 26963 | |||
| 26964 | # Object representing a movement command found | ||
| 26965 | $matchFlag = TRUE; | ||
| 26966 | # Remove it from the list | ||
| 26967 | splice (@cmdObjList, 0, ($count + 1)); | ||
| 26968 | |||
| 26969 | last OUTER; | ||
| 26970 | } | ||
| 26971 | } | ||
| 26972 | |||
| 26973 | if (! $matchFlag || $moveList[0] ne $cmdObj) { | ||
| 26974 | |||
| 26975 | $self->writeError( | ||
| 26976 | 'Command object lists do not match', | ||
| 26977 | $self->_objClass . '->removeFirstMove', | ||
| 26978 | ); | ||
| 26979 | |||
| 26980 | # Empty both lists, to prevent a whole stream of errors | ||
| 26981 | $self->ivEmpty('cmdObjList'); | ||
| 26982 | $self->ivEmpty('moveList'); | ||
| 26983 | $self->ivUndef('prevCmdBufferNum'); | ||
| 26984 | |||
| 26985 | # Update the task window's title bar (if open) | ||
| 26986 | $self->prepareTitleBar(); | ||
| 26987 | |||
| 26988 | return undef; | ||
| 26989 | |||
| 26990 | } else { | ||
| 26991 | |||
| 26992 | # Object representing a movement command found (in both lists). Restore IVs | ||
| 26993 | $self->ivPoke('cmdObjList', @cmdObjList); | ||
| 26994 | $self->ivPoke('moveList', splice(@moveList, 1)); | ||
| 26995 | $self->ivUndef('prevCmdBufferNum'); | ||
| 26996 | |||
| 26997 | # Update the task window's title bar (if open) | ||
| 26998 | $self->prepareTitleBar(); | ||
| 26999 | |||
| 27000 | return 1; | ||
| 27001 | } | ||
| 27002 | } | ||
| 27003 | |||
| 27004 | # Room methods | ||
| 27005 | |||
| 27006 | sub setRoomTitle { | ||
| 27007 | |||
| 27008 | # Called by $self->extractComponents (at stage 3) | ||
| 27009 | # Adds titles to the non-model room | ||
| 27010 | # | ||
| 27011 | # Expected arguments | ||
| 27012 | # $roomObj - A GA::ModelObj::Room object | ||
| 27013 | # @lineList - A list of lines comprising the room statement components 'verb_title' or | ||
| 27014 | # 'brief_title' | ||
| 27015 | # | ||
| 27016 | # Return values | ||
| 27017 | # 'undef' on improper arguments | ||
| 27018 | # 1 otherwise | ||
| 27019 | |||
| 27020 | my ($self, $roomObj, @lineList) = @_; | ||
| 27021 | |||
| 27022 | # Local variables | ||
| 27023 | my @modList; | ||
| 27024 | |||
| 27025 | # Check for improper arguments | ||
| 27026 | if (! defined $roomObj || ! @lineList) { | ||
| 27027 | |||
| 27028 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setRoomTitle', @_); | ||
| 27029 | } | ||
| 27030 | |||
| 27031 | # Preserve the original @lineList (required for TTS); | ||
| 27032 | $self->ivAdd('ttsToReadHash', 'title', join(' ', @lineList)); | ||
| 27033 | |||
| 27034 | # Eliminate any empty lines (containing no non-whitespace characters) | ||
| 27035 | foreach my $line (@lineList) { | ||
| 27036 | |||
| 27037 | if ($line =~ m/\S/) { | ||
| 27038 | |||
| 27039 | # Also eliminate extraneous whitespace, including in the middle of lines | ||
| 27040 | $line = $axmud::CLIENT->trimWhitespace($line, TRUE); | ||
| 27041 | push (@modList, $line); | ||
| 27042 | } | ||
| 27043 | } | ||
| 27044 | |||
| 27045 | if (@modList) { | ||
| 27046 | |||
| 27047 | # Update the room's title list | ||
| 27048 | $roomObj->ivPush('titleList', @modList); | ||
| 27049 | } | ||
| 27050 | |||
| 27051 | return 1; | ||
| 27052 | } | ||
| 27053 | |||
| 27054 | sub setRoomDescrip { | ||
| 27055 | |||
| 27056 | # Called by $self->extractComponents (at stage 3) | ||
| 27057 | # Adds (verbose) descriptions to the non-model room | ||
| 27058 | # | ||
| 27059 | # Expected arguments | ||
| 27060 | # $roomObj - A GA::ModelObj::Room object | ||
| 27061 | # @lineList - A list of lines comprising the room statement component 'verb_descrip' | ||
| 27062 | # | ||
| 27063 | # Return values | ||
| 27064 | # 'undef' on improper arguments | ||
| 27065 | # 1 otherwise | ||
| 27066 | |||
| 27067 | my ($self, $roomObj, @lineList) = @_; | ||
| 27068 | |||
| 27069 | # Local variables | ||
| 27070 | my @modList; | ||
| 27071 | |||
| 27072 | # Check for improper arguments | ||
| 27073 | if (! defined $roomObj || ! @lineList) { | ||
| 27074 | |||
| 27075 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setRoomDescrip', @_); | ||
| 27076 | } | ||
| 27077 | |||
| 27078 | # Preserve the original @lineList (required for TTS); | ||
| 27079 | $self->ivAdd('ttsToReadHash', 'descrip', join(' ', @lineList)); | ||
| 27080 | |||
| 27081 | # Eliminate any empty lines (containing no non-whitespace characters) | ||
| 27082 | foreach my $line (@lineList) { | ||
| 27083 | |||
| 27084 | if ($line =~ m/\S/) { | ||
| 27085 | |||
| 27086 | # Also eliminate extraneous whitespace, including in the middle of lines | ||
| 27087 | $line = $axmud::CLIENT->trimWhitespace($line, TRUE); | ||
| 27088 | push (@modList, $line); | ||
| 27089 | } | ||
| 27090 | } | ||
| 27091 | |||
| 27092 | if (@modList) { | ||
| 27093 | |||
| 27094 | # Update the room's verbose description hash | ||
| 27095 | $roomObj->ivAdd( | ||
| 27096 | 'descripHash', | ||
| 27097 | $self->session->worldModelObj->lightStatus, | ||
| 27098 | join(' ', @modList), | ||
| 27099 | ); | ||
| 27100 | } | ||
| 27101 | |||
| 27102 | return 1; | ||
| 27103 | } | ||
| 27104 | |||
| 27105 | sub setRoomExit { | ||
| 27106 | |||
| 27107 | # Called by $self->extractComponents (at stage 3); also called by $self->setRoomTitleExit | ||
| 27108 | # Adds a list of verbose or brief exits to the non-model room | ||
| 27109 | # | ||
| 27110 | # Expected arguments | ||
| 27111 | # $worldObj - The current world profile | ||
| 27112 | # $roomObj - A GA::ModelObj::Room object | ||
| 27113 | # $mode - 'verbose' or 'brief' | ||
| 27114 | # $bufferObjListRef - Reference to a list of display buffer objects, one for each line | ||
| 27115 | # in the extracted component | ||
| 27116 | # $lineTextListRef - Reference to a corresponding list of strings, each representing | ||
| 27117 | # text on a single line | ||
| 27118 | # $lineOffsetListRef - Reference to a corresponding list of hash references, containing | ||
| 27119 | # offsets on each line where Axmud colour/style tags occur. Those | ||
| 27120 | # hashes are in the form | ||
| 27121 | # $hash{offset} = reference_to_list_of_Axmud_colour_&_style_tags | ||
| 27122 | # | ||
| 27123 | # Return values | ||
| 27124 | # 'undef' on improper arguments, if any line in $lineTextListRef is invalid or if | ||
| 27125 | # $lineTextListRef is empty | ||
| 27126 | # 1 otherwise | ||
| 27127 | |||
| 27128 | my ( | ||
| 27129 | $self, $worldObj, $roomObj, $mode, $bufferObjListRef, $lineTextListRef, | ||
| 27130 | $lineOffsetListRef, $check, | ||
| 27131 | ) = @_; | ||
| 27132 | |||
| 27133 | # Local variables | ||
| 27134 | my ( | ||
| 27135 | $delimIV, $nonDelimIV, $leftMarkerIV, $rightMarkerIV, $splitCharIV, | ||
| 27136 | @bufferObjList, @lineTextList, @lineOffsetList, @markerList, @exitList, @finalList, | ||
| 27137 | %checkHash, %duplicateHash, | ||
| 27138 | ); | ||
| 27139 | |||
| 27140 | # Check for improper arguments | ||
| 27141 | if ( | ||
| 27142 | ! defined $worldObj || ! defined $roomObj || ! defined $mode | ||
| 27143 | || ! defined $bufferObjListRef || ! defined $lineTextListRef | ||
| 27144 | || ! defined $lineOffsetListRef || defined $check | ||
| 27145 | ) { | ||
| 27146 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setRoomExit', @_); | ||
| 27147 | } | ||
| 27148 | |||
| 27149 | # Set which IVs to use, depending on $mode | ||
| 27150 | if ($mode eq 'verbose') { | ||
| 27151 | |||
| 27152 | $delimIV = 'verboseExitDelimiterList'; | ||
| 27153 | $nonDelimIV = 'verboseExitNonDelimiterList'; | ||
| 27154 | $leftMarkerIV = 'verboseExitLeftMarkerList'; | ||
| 27155 | $rightMarkerIV = 'verboseExitRightMarkerList'; | ||
| 27156 | $splitCharIV = 'verboseExitSplitCharFlag'; | ||
| 27157 | |||
| 27158 | } else { | ||
| 27159 | |||
| 27160 | $delimIV = 'briefExitDelimiterList'; | ||
| 27161 | $nonDelimIV = 'briefExitNonDelimiterList'; | ||
| 27162 | $leftMarkerIV = 'briefExitLeftMarkerList'; | ||
| 27163 | $rightMarkerIV = 'briefExitRightMarkerList'; | ||
| 27164 | $splitCharIV = 'briefExitSplitCharFlag'; | ||
| 27165 | } | ||
| 27166 | |||
| 27167 | # For convenience, dereference the arguments | ||
| 27168 | @bufferObjList = @$bufferObjListRef; | ||
| 27169 | @lineTextList = @$lineTextListRef; | ||
| 27170 | @lineOffsetList = @$lineOffsetListRef; | ||
| 27171 | if (! @lineTextList) { | ||
| 27172 | |||
| 27173 | # Nothing to process | ||
| 27174 | return undef; | ||
| 27175 | } | ||
| 27176 | |||
| 27177 | # Preserve the original @lineTextList (required for TTS); | ||
| 27178 | $self->ivAdd('ttsToReadHash', 'exit', join(' ', @lineTextList)); | ||
| 27179 | |||
| 27180 | # Remove left/right markers, if any, from each line in @lineTextList. (It's up to the user | ||
| 27181 | # to create left-marker regexes that start with '^' and right-marker regexes that end with | ||
| 27182 | # '$') | ||
| 27183 | @markerList = ( | ||
| 27184 | $worldObj->$leftMarkerIV, | ||
| 27185 | $worldObj->$rightMarkerIV, | ||
| 27186 | ); | ||
| 27187 | |||
| 27188 | if (@markerList) { | ||
| 27189 | |||
| 27190 | for (my $count = 0; $count < (scalar @lineTextList); $count++) { | ||
| 27191 | |||
| 27192 | my ( | ||
| 27193 | $text, $modText, $hashRef, $modFlag, | ||
| 27194 | %modHash, | ||
| 27195 | ); | ||
| 27196 | |||
| 27197 | $modText = $text = $lineTextList[$count]; | ||
| 27198 | $hashRef = $lineOffsetList[$count]; | ||
| 27199 | %modHash = %$hashRef; | ||
| 27200 | |||
| 27201 | foreach my $marker (@markerList) { | ||
| 27202 | |||
| 27203 | my ( | ||
| 27204 | $newText, $start, $stop, $len, | ||
| 27205 | %newHash, | ||
| 27206 | ); | ||
| 27207 | |||
| 27208 | $newText = $modText; | ||
| 27209 | |||
| 27210 | if ($newText =~ s/$marker//) { | ||
| 27211 | |||
| 27212 | $start = $-[0]; | ||
| 27213 | $stop = $+[0]; | ||
| 27214 | $len = $stop - $start; | ||
| 27215 | |||
| 27216 | # Update the hash of offsets where Axmud colour/style tags occur to match | ||
| 27217 | # the modified text | ||
| 27218 | foreach my $offset (keys %modHash) { | ||
| 27219 | |||
| 27220 | if ($offset < $start) { | ||
| 27221 | $newHash{$offset} = $modHash{$offset}; | ||
| 27222 | } elsif ($offset >= $stop) { | ||
| 27223 | $newHash{$offset - $len} = $modHash{$offset}; | ||
| 27224 | } | ||
| 27225 | } | ||
| 27226 | |||
| 27227 | $modText = $newText; | ||
| 27228 | %modHash = %newHash; | ||
| 27229 | $modFlag = TRUE; | ||
| 27230 | } | ||
| 27231 | } | ||
| 27232 | |||
| 27233 | if ($modFlag) { | ||
| 27234 | |||
| 27235 | # At least one substitution was made | ||
| 27236 | $lineTextList[$count] = $modText; | ||
| 27237 | $lineOffsetList[$count] = \%modHash; | ||
| 27238 | } | ||
| 27239 | } | ||
| 27240 | } | ||
| 27241 | |||
| 27242 | # Check that no lines contain any non-delimiters (forbidden substrings) | ||
| 27243 | foreach my $line (@lineTextList) { | ||
| 27244 | |||
| 27245 | foreach my $delim ($worldObj->$nonDelimIV) { | ||
| 27246 | |||
| 27247 | if (index ($line, $delim) > -1) { | ||
| 27248 | |||
| 27249 | # Invalid line; don't process any exits | ||
| 27250 | return undef; | ||
| 27251 | } | ||
| 27252 | } | ||
| 27253 | } | ||
| 27254 | |||
| 27255 | # Replace any exit aliases with their substitutions (e.g. substitute 'compass' for | ||
| 27256 | # 'n s e w nw ne sw se' | ||
| 27257 | if ($worldObj->exitAliasHash) { | ||
| 27258 | |||
| 27259 | for (my $count = 0; $count < (scalar @lineTextList); $count++) { | ||
| 27260 | |||
| 27261 | my ( | ||
| 27262 | $text, $modText, $hashRef, $modFlag, | ||
| 27263 | %modHash, | ||
| 27264 | ); | ||
| 27265 | |||
| 27266 | $modText = $text = $lineTextList[$count]; | ||
| 27267 | $hashRef = $lineOffsetList[$count]; | ||
| 27268 | %modHash = %$hashRef; | ||
| 27269 | |||
| 27270 | foreach my $pattern ($worldObj->ivKeys('exitAliasHash')) { | ||
| 27271 | |||
| 27272 | my ( | ||
| 27273 | $substitution, $newText, $start, $stop, $diff, | ||
| 27274 | %newHash, | ||
| 27275 | ); | ||
| 27276 | |||
| 27277 | $substitution = $worldObj->ivShow('exitAliasHash', $pattern); | ||
| 27278 | $newText = $modText; | ||
| 27279 | |||
| 27280 | if ($newText =~ s/$pattern/$substitution/i) { | ||
| 27281 | |||
| 27282 | $start = $-[0]; | ||
| 27283 | $stop = $+[0]; | ||
| 27284 | $diff = length($newText) - length($modText); | ||
| 27285 | |||
| 27286 | # Update the hash of offsets where Axmud colour/style tags occur to match | ||
| 27287 | # the modified text. Any colour/style tags which occured inside the | ||
| 27288 | # substituted text are lost | ||
| 27289 | foreach my $offset (keys %modHash) { | ||
| 27290 | |||
| 27291 | if ($offset < $start) { | ||
| 27292 | $newHash{$offset} = $modHash{$offset}; | ||
| 27293 | } elsif ($offset >= $stop) { | ||
| 27294 | $newHash{$offset + $diff} = $modHash{$offset}; | ||
| 27295 | } | ||
| 27296 | } | ||
| 27297 | |||
| 27298 | $modText = $newText; | ||
| 27299 | %modHash = %newHash; | ||
| 27300 | $modFlag = TRUE; | ||
| 27301 | } | ||
| 27302 | } | ||
| 27303 | |||
| 27304 | if ($modFlag) { | ||
| 27305 | |||
| 27306 | # At least one substitution was made | ||
| 27307 | $lineTextList[$count] = $modText; | ||
| 27308 | $lineOffsetList[$count] = \%modHash; | ||
| 27309 | } | ||
| 27310 | } | ||
| 27311 | } | ||
| 27312 | |||
| 27313 | # In case the delimiter interferes with exit state strings, remove anything matching the | ||
| 27314 | # pattern(s), and treat that portion as an exit | ||
| 27315 | # Compose a list, @exitList, in groups of 3, in the form | ||
| 27316 | # (exit_string, text_colour, underlay_colour...) | ||
| 27317 | if ($worldObj->exitStatePatternList) { | ||
| 27318 | |||
| 27319 | for (my $count = 0; $count < (scalar @lineTextList); $count++) { | ||
| 27320 | |||
| 27321 | my ( | ||
| 27322 | $bufferObj, $text, $modText, $hashRef, $modFlag, | ||
| 27323 | %modHash, | ||
| 27324 | ); | ||
| 27325 | |||
| 27326 | $bufferObj = $bufferObjList[$count]; | ||
| 27327 | $modText = $text = $lineTextList[$count]; | ||
| 27328 | $hashRef = $lineOffsetList[$count]; | ||
| 27329 | %modHash = %$hashRef; | ||
| 27330 | |||
| 27331 | foreach my $pattern ($worldObj->exitStatePatternList) { | ||
| 27332 | |||
| 27333 | my ( | ||
| 27334 | $substitution, $newText, $exitFlag, | ||
| 27335 | %newHash, | ||
| 27336 | ); | ||
| 27337 | |||
| 27338 | $substitution = $worldObj->ivShow('exitAliasHash', $pattern); | ||
| 27339 | $newText = $modText; | ||
| 27340 | |||
| 27341 | # Use a do... loop, as we might need to remove several exits from the same line | ||
| 27342 | do { | ||
| 27343 | |||
| 27344 | my ($start, $stop, $len); | ||
| 27345 | |||
| 27346 | $exitFlag = FALSE; | ||
| 27347 | |||
| 27348 | if ($newText =~ s/($pattern)//) { | ||
| 27349 | |||
| 27350 | $start = $-[0]; | ||
| 27351 | $stop = $+[0]; | ||
| 27352 | $len = $stop - $start; | ||
| 27353 | |||
| 27354 | # Get the text/underlay colours which apply to the offset $start, so we | ||
| 27355 | # can add them to @exitList alongside $1, the exit itself | ||
| 27356 | push (@exitList, | ||
| 27357 | $1, | ||
| 27358 | $self->getColoursAtPosn( | ||
| 27359 | $self->getColoursAtStart($bufferObj), | ||
| 27360 | FALSE, # No 'bold' tag detected yet | ||
| 27361 | $start, | ||
| 27362 | %modHash, | ||
| 27363 | ), | ||
| 27364 | ); | ||
| 27365 | |||
| 27366 | # Update the hash of offsets where Axmud colour/style tags occur to | ||
| 27367 | # match the modified text. Any colour/style tags which occured inside | ||
| 27368 | # the substituted text are lost | ||
| 27369 | foreach my $offset (keys %modHash) { | ||
| 27370 | |||
| 27371 | if ($offset < $start) { | ||
| 27372 | $newHash{$offset} = $modHash{$offset}; | ||
| 27373 | } elsif ($offset >= $stop) { | ||
| 27374 | $newHash{$offset - $len} = $modHash{$offset}; | ||
| 27375 | } | ||
| 27376 | } | ||
| 27377 | |||
| 27378 | $modText = $newText; | ||
| 27379 | %modHash = %newHash; | ||
| 27380 | $modFlag = TRUE; | ||
| 27381 | } | ||
| 27382 | |||
| 27383 | } until (! $exitFlag); | ||
| 27384 | } | ||
| 27385 | |||
| 27386 | if ($modFlag) { | ||
| 27387 | |||
| 27388 | # At least one substitution was made | ||
| 27389 | $lineTextList[$count] = $modText; | ||
| 27390 | $lineOffsetList[$count] = \%modHash; | ||
| 27391 | } | ||
| 27392 | } | ||
| 27393 | } | ||
| 27394 | |||
| 27395 | # Now extract exits from every line in turn | ||
| 27396 | OUTER: for (my $count = 0; $count < (scalar @lineTextList); $count++) { | ||
| 27397 | |||
| 27398 | my ( | ||
| 27399 | $bufferObj, $text, $hashRef, $offset, $textColour, $underlayColour, $boldFlag, | ||
| 27400 | $stopFlag, | ||
| 27401 | %newHash, | ||
| 27402 | ); | ||
| 27403 | |||
| 27404 | $bufferObj = $bufferObjList[$count]; | ||
| 27405 | $text = $lineTextList[$count]; | ||
| 27406 | $hashRef = $lineOffsetList[$count]; | ||
| 27407 | $offset = 0; | ||
| 27408 | |||
| 27409 | ($textColour, $underlayColour) = $self->getColoursAtStart($bufferObj); | ||
| 27410 | $boldFlag = FALSE; | ||
| 27411 | |||
| 27412 | # $text should now be in the general form | ||
| 27413 | # <exit><delimiter><exit><delimiter><exit>... | ||
| 27414 | do { | ||
| 27415 | |||
| 27416 | my ($posn, $delim, $exitString); | ||
| 27417 | |||
| 27418 | # Find the position of the first delimiter at $offset or after | ||
| 27419 | foreach my $thisDelim ($worldObj->$delimIV) { | ||
| 27420 | |||
| 27421 | my $thisPosn = index(substr($text, $offset), $thisDelim); | ||
| 27422 | if ($thisPosn >= 0) { | ||
| 27423 | |||
| 27424 | if (! defined $posn || $posn > $thisPosn) { | ||
| 27425 | |||
| 27426 | $posn = $thisPosn; | ||
| 27427 | $delim = $thisDelim; | ||
| 27428 | } | ||
| 27429 | } | ||
| 27430 | } | ||
| 27431 | |||
| 27432 | if (! defined $posn) { | ||
| 27433 | |||
| 27434 | # $text, from $offset onwards, contains no delimiters | ||
| 27435 | push (@exitList, substr($text, $offset)); | ||
| 27436 | |||
| 27437 | ($textColour, $underlayColour, $boldFlag, %newHash) = $self->getColoursAtPosn( | ||
| 27438 | $textColour, | ||
| 27439 | $underlayColour, | ||
| 27440 | $boldFlag, | ||
| 27441 | $offset, | ||
| 27442 | %$hashRef, | ||
| 27443 | ), | ||
| 27444 | |||
| 27445 | push (@exitList, $textColour, $underlayColour); | ||
| 27446 | %$hashRef = %newHash; | ||
| 27447 | $stopFlag = TRUE; | ||
| 27448 | |||
| 27449 | } else { | ||
| 27450 | |||
| 27451 | # $text contains an offset an exit between $offset and ($offset + $posn) | ||
| 27452 | push (@exitList, substr($text, $offset, $posn)); | ||
| 27453 | |||
| 27454 | ($textColour, $underlayColour, $boldFlag, %newHash) = $self->getColoursAtPosn( | ||
| 27455 | $textColour, | ||
| 27456 | $underlayColour, | ||
| 27457 | $boldFlag, | ||
| 27458 | $offset, | ||
| 27459 | %$hashRef, | ||
| 27460 | ), | ||
| 27461 | |||
| 27462 | push (@exitList, $textColour, $underlayColour); | ||
| 27463 | %$hashRef = %newHash; | ||
| 27464 | |||
| 27465 | # On the next iteration of this loop, check from the start of the next exit | ||
| 27466 | # string | ||
| 27467 | $offset += $posn + length($delim); | ||
| 27468 | } | ||
| 27469 | |||
| 27470 | } until ($stopFlag); | ||
| 27471 | } | ||
| 27472 | |||
| 27473 | # Improve the exits in @exitList | ||
| 27474 | if (@exitList) { | ||
| 27475 | |||
| 27476 | do { | ||
| 27477 | |||
| 27478 | my ($exitString, $currentText, $currentUnderlay, $modString, $replace); | ||
| 27479 | |||
| 27480 | $exitString = shift @exitList; | ||
| 27481 | $currentText = shift @exitList; | ||
| 27482 | $currentUnderlay = shift @exitList; | ||
| 27483 | |||
| 27484 | # Remove any leading/trailing whitespace from strings in @exitList, convert | ||
| 27485 | # multiple-character whitespace into single-character whitespace | ||
| 27486 | $modString = lc($axmud::CLIENT->trimWhitespace($exitString, TRUE)); | ||
| 27487 | |||
| 27488 | # Ignore any strings that are now empty strings | ||
| 27489 | if (defined $modString && $modString ne '') { | ||
| 27490 | |||
| 27491 | # Deal with duplicate exits. In some situations, we can replace it with | ||
| 27492 | # something else | ||
| 27493 | if ( | ||
| 27494 | exists $checkHash{$modString} | ||
| 27495 | && defined $worldObj->duplicateReplaceString | ||
| 27496 | ) { | ||
| 27497 | # For worlds like Two Towers, a duplicate 'east' exit is normally one which | ||
| 27498 | # can be substituted for something like 'swim east', in which case | ||
| 27499 | # $replace will be something like 'swim @@@' | ||
| 27500 | $replace = $worldObj->duplicateReplaceString; | ||
| 27501 | $replace =~ s/@@@/$modString/g; | ||
| 27502 | $modString = $replace; | ||
| 27503 | # After the non-model exit object is created, we'll mark it as a hidden exit | ||
| 27504 | $duplicateHash{$modString} = undef; | ||
| 27505 | } | ||
| 27506 | |||
| 27507 | # If $modString is still a duplicate, just ignore it | ||
| 27508 | if (! exists $checkHash{$modString}) { | ||
| 27509 | |||
| 27510 | # Split the exit into single letters, if required | ||
| 27511 | if ($worldObj->$splitCharIV) { | ||
| 27512 | |||
| 27513 | foreach my $char (split('', $modString)) { | ||
| 27514 | |||
| 27515 | # Still eliminate duplicate exits | ||
| 27516 | if (! exists $checkHash{$char}) { | ||
| 27517 | |||
| 27518 | # The code assumes that any colour tag applying to the beginning | ||
| 27519 | # of the exit applies to all of it; in this case, it applies | ||
| 27520 | # to every character in the split string | ||
| 27521 | push (@finalList, $char, $currentText, $currentUnderlay); | ||
| 27522 | } | ||
| 27523 | } | ||
| 27524 | |||
| 27525 | } else { | ||
| 27526 | |||
| 27527 | push (@finalList, $modString, $currentText, $currentUnderlay); | ||
| 27528 | } | ||
| 27529 | |||
| 27530 | $checkHash{$modString} = undef; | ||
| 27531 | } | ||
| 27532 | } | ||
| 27533 | |||
| 27534 | } until (! @exitList); | ||
| 27535 | } | ||
| 27536 | |||
| 27537 | # Now, for each exit in @finalList, create a non-exit model object, and add it to the room | ||
| 27538 | # model object | ||
| 27539 | if (! $self->processExits($worldObj, $roomObj, @finalList)) { | ||
| 27540 | |||
| 27541 | return undef; | ||
| 27542 | } | ||
| 27543 | |||
| 27544 | # Any duplicate exits that were converted (e.g. east > swim east) must be marked as hidden | ||
| 27545 | # exits, so that the imaginary 'swim east' direction doesn't conflict with the | ||
| 27546 | # corresponding room's list of exits in a map | ||
| 27547 | foreach my $string (keys %duplicateHash) { | ||
| 27548 | |||
| 27549 | my $exitObj = $roomObj->ivShow('exitNumHash', $string); | ||
| 27550 | $exitObj->ivPoke('hiddenFlag', TRUE); | ||
| 27551 | } | ||
| 27552 | |||
| 27553 | return 1; | ||
| 27554 | } | ||
| 27555 | |||
| 27556 | sub setRoomContent { | ||
| 27557 | |||
| 27558 | # Called by $self->extractComponents (at stage 3). Also called by $self->setRoomVerbSpecial | ||
| 27559 | # Extracts the non-model room's (temporary) list of contents | ||
| 27560 | # | ||
| 27561 | # Expected arguments | ||
| 27562 | # $roomObj - A GA::ModelObj::Room object | ||
| 27563 | # @lineList - A list of lines comprising the room statement components 'verb_content' | ||
| 27564 | # or 'brief_content' | ||
| 27565 | # | ||
| 27566 | # Return values | ||
| 27567 | # 'undef' on improper arguments | ||
| 27568 | # 1 otherwise | ||
| 27569 | |||
| 27570 | my ($self, $roomObj, @lineList) = @_; | ||
| 27571 | |||
| 27572 | # Local variables | ||
| 27573 | my ( | ||
| 27574 | $dictObj, $string, | ||
| 27575 | @objList, | ||
| 27576 | ); | ||
| 27577 | |||
| 27578 | # Check for improper arguments | ||
| 27579 | if (! defined $roomObj || ! @lineList) { | ||
| 27580 | |||
| 27581 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setRoomVerbContent', @_); | ||
| 27582 | } | ||
| 27583 | |||
| 27584 | # Preserve the original @lineList (required for TTS); | ||
| 27585 | $self->ivAdd('ttsToReadHash', 'content', join(' ', @lineList)); | ||
| 27586 | |||
| 27587 | # Import the current dictionary (for convenience) | ||
| 27588 | $dictObj = $self->session->currentDict; | ||
| 27589 | |||
| 27590 | # Extract a list of model objects by parsing each line | ||
| 27591 | @objList = $self->session->worldModelObj->parseObj( | ||
| 27592 | $self->session, | ||
| 27593 | FALSE, # Treat '5 coins' as 5 separate objects | ||
| 27594 | @lineList, | ||
| 27595 | ); | ||
| 27596 | |||
| 27597 | if (@objList) { | ||
| 27598 | |||
| 27599 | # Update the non-model room object | ||
| 27600 | $roomObj->ivPush('tempObjList', @objList); | ||
| 27601 | } | ||
| 27602 | |||
| 27603 | # Store the contents lines themselves, if the flag is set | ||
| 27604 | if ($self->session->currentWorld->collectContentsFlag) { | ||
| 27605 | |||
| 27606 | foreach my $line (@lineList) { | ||
| 27607 | |||
| 27608 | my $thisLine; | ||
| 27609 | |||
| 27610 | # Don't store lines containing no alphanumeric characters | ||
| 27611 | if ($line =~ m/\w/) { | ||
| 27612 | |||
| 27613 | # Remove all leading/trailing whitespace, and reduce any whitespace in the | ||
| 27614 | # middle to a single character (and reduce everything to lower case, | ||
| 27615 | # because that's what $self->session->worldModelObj->parseObj uses) | ||
| 27616 | $thisLine = lc($axmud::CLIENT->trimWhitespace($line, TRUE)); | ||
| 27617 | # If the line starts or ends with non-alphanumeric characters (especially | ||
| 27618 | # punctuation at the end of the line), remove them | ||
| 27619 | $thisLine =~ s/^\W+//; | ||
| 27620 | $thisLine =~ s/\W+$//; | ||
| 27621 | |||
| 27622 | if ($thisLine && ! $dictObj->ivExists('contentsLinesHash', $thisLine)) { | ||
| 27623 | |||
| 27624 | $dictObj->ivAdd('contentsLinesHash', $thisLine, undef); | ||
| 27625 | } | ||
| 27626 | } | ||
| 27627 | } | ||
| 27628 | } | ||
| 27629 | |||
| 27630 | return 1; | ||
| 27631 | } | ||
| 27632 | |||
| 27633 | sub setRoomVerbSpecial { | ||
| 27634 | |||
| 27635 | # Called by $self->extractComponents (at stage 3) | ||
| 27636 | # Extracts lines in the 'verb_special' component and converts them to parseable lines | ||
| 27637 | # (e.g. converts '^There is a sign here you can read\.' to 'A sign is here') | ||
| 27638 | # | ||
| 27639 | # Expected arguments | ||
| 27640 | # $worldObj - The current world profile | ||
| 27641 | # $roomObj - A GA::ModelObj::Room object | ||
| 27642 | # @lineList - A list of lines comprising the room statement component 'verb_special' | ||
| 27643 | # | ||
| 27644 | # Return values | ||
| 27645 | # 'undef' on improper arguments or if no matching lines are converted | ||
| 27646 | # 1 otherwise | ||
| 27647 | |||
| 27648 | my ($self, $worldObj, $roomObj, @lineList) = @_; | ||
| 27649 | |||
| 27650 | # Local variables | ||
| 27651 | my (@specialList, @modList); | ||
| 27652 | |||
| 27653 | # Check for improper arguments | ||
| 27654 | if (! defined $worldObj || ! defined $roomObj || ! @lineList) { | ||
| 27655 | |||
| 27656 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setRoomVerbSpecial', @_); | ||
| 27657 | } | ||
| 27658 | |||
| 27659 | # Import the hash of special patterns (for quick lookup) | ||
| 27660 | @specialList = $worldObj->ivKeys('specialPatternHash'); | ||
| 27661 | |||
| 27662 | # Check each line in turn, looking for lines that match a pattern in %specialHash. Ignore | ||
| 27663 | # any non-matching lines | ||
| 27664 | OUTER: foreach my $line (@lineList) { | ||
| 27665 | |||
| 27666 | INNER: foreach my $pattern (@specialList) { | ||
| 27667 | |||
| 27668 | if ($line =~ $pattern) { | ||
| 27669 | |||
| 27670 | # Replace the whole line | ||
| 27671 | push (@modList, $worldObj->ivShow('specialPatternHash', $pattern)); | ||
| 27672 | next OUTER; | ||
| 27673 | } | ||
| 27674 | } | ||
| 27675 | } | ||
| 27676 | |||
| 27677 | # If any lines were replaced, treat them as ordinary contents lines | ||
| 27678 | if (@modList) { | ||
| 27679 | |||
| 27680 | return $self->setRoomContent($roomObj, @modList); | ||
| 27681 | |||
| 27682 | } else { | ||
| 27683 | |||
| 27684 | # No lines converted | ||
| 27685 | return undef; | ||
| 27686 | } | ||
| 27687 | } | ||
| 27688 | |||
| 27689 | sub setRoomTitleExit { | ||
| 27690 | |||
| 27691 | # Called by $self->extractComponents (at stage 3) | ||
| 27692 | # Processes a line that contains both a room's title and brief list of exits | ||
| 27693 | # | ||
| 27694 | # Expected arguments | ||
| 27695 | # $worldObj - The current world profile | ||
| 27696 | # $roomObj - A GA::ModelObj::Room object | ||
| 27697 | # $flag - If set to TRUE, the line should contain the room title, followed | ||
| 27698 | # by the list of brief exits (as the title of this function | ||
| 27699 | # suggests). If set to FALSE, the list of brief exits comes before | ||
| 27700 | # the title | ||
| 27701 | # $bufferObjListRef - Reference to a list of display buffer objects, one for each line | ||
| 27702 | # in the extracted component | ||
| 27703 | # $lineTextListRef - Reference to a corresponding list of strings, each representing | ||
| 27704 | # text on a single line | ||
| 27705 | # $lineOffsetListRef - Reference to a corresponding list of hash references, containing | ||
| 27706 | # offsets on each line where Axmud colour/style tags occur. Those | ||
| 27707 | # hashes are in the form | ||
| 27708 | # $hash{offset} = reference_to_list_of_Axmud_colour_&_style_tags | ||
| 27709 | # | ||
| 27710 | # Return values | ||
| 27711 | # 'undef' on improper arguments or if any line in @lineList is invalid | ||
| 27712 | # 1 otherwise | ||
| 27713 | |||
| 27714 | my ( | ||
| 27715 | $self, $worldObj, $roomObj, $flag, $bufferObjListRef, $lineTextListRef, | ||
| 27716 | $lineOffsetListRef, $check, | ||
| 27717 | ) = @_; | ||
| 27718 | |||
| 27719 | # Local variables | ||
| 27720 | my ( | ||
| 27721 | $bufferObj, $text, $hashRef, $title, $exitString, | ||
| 27722 | @bufferObjList, @lineTextList, @lineOffsetList, | ||
| 27723 | ); | ||
| 27724 | |||
| 27725 | # Check for improper arguments | ||
| 27726 | if ( | ||
| 27727 | ! defined $worldObj || ! defined $roomObj || ! defined $flag | ||
| 27728 | || ! defined $bufferObjListRef || ! defined $lineTextListRef | ||
| 27729 | || ! defined $lineOffsetListRef || defined $check | ||
| 27730 | ) { | ||
| 27731 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setRoomTitleExit', @_); | ||
| 27732 | } | ||
| 27733 | |||
| 27734 | # Ignore everything except the first line | ||
| 27735 | $bufferObj = $$bufferObjListRef[0]; | ||
| 27736 | $text = $$lineTextListRef[0]; | ||
| 27737 | $hashRef = $$lineOffsetListRef[0]; | ||
| 27738 | |||
| 27739 | if ($flag) { | ||
| 27740 | |||
| 27741 | # The line appears in the form <title> <list of exits> | ||
| 27742 | # Find the position of the first left marker; everything to the left of that is the | ||
| 27743 | # room title | ||
| 27744 | OUTER: foreach my $marker ($worldObj->briefExitLeftMarkerList) { | ||
| 27745 | |||
| 27746 | my %newHash; | ||
| 27747 | |||
| 27748 | if ($text =~ m/$marker/) { | ||
| 27749 | |||
| 27750 | $title = $`; | ||
| 27751 | $exitString = substr($text, length($title)); | ||
| 27752 | |||
| 27753 | # Update offsets in the hash of Axmud colour/style tags | ||
| 27754 | foreach my $offset (keys %$hashRef) { | ||
| 27755 | |||
| 27756 | if ($offset >= length ($title)) { | ||
| 27757 | |||
| 27758 | $newHash{$offset - length($title)} = $$hashRef{$offset}; | ||
| 27759 | } | ||
| 27760 | } | ||
| 27761 | |||
| 27762 | $hashRef = \%newHash; | ||
| 27763 | |||
| 27764 | last OUTER; | ||
| 27765 | } | ||
| 27766 | } | ||
| 27767 | |||
| 27768 | } else { | ||
| 27769 | |||
| 27770 | # The line appears in the form <list of exits> <title> | ||
| 27771 | # Find the position of the first right marker; everything to the right of that is the | ||
| 27772 | # room title | ||
| 27773 | OUTER: foreach my $marker ($worldObj->briefExitRightMarkerList) { | ||
| 27774 | |||
| 27775 | my %newHash; | ||
| 27776 | |||
| 27777 | if ($text =~ m/$marker/) { | ||
| 27778 | |||
| 27779 | $title = $'; | ||
| 27780 | $exitString = $` . $&; | ||
| 27781 | |||
| 27782 | # Update offsets in the hash of Axmud colour/style tags | ||
| 27783 | foreach my $offset (keys %$hashRef) { | ||
| 27784 | |||
| 27785 | if ($offset < length ($exitString)) { | ||
| 27786 | |||
| 27787 | $newHash{$offset} = $$hashRef{$offset}; | ||
| 27788 | } | ||
| 27789 | } | ||
| 27790 | |||
| 27791 | $hashRef = \%newHash; | ||
| 27792 | |||
| 27793 | last OUTER; | ||
| 27794 | } | ||
| 27795 | } | ||
| 27796 | } | ||
| 27797 | |||
| 27798 | if (! $title && ! $exitString) { | ||
| 27799 | |||
| 27800 | # The exit string is more important, so use the whole line as the exit string | ||
| 27801 | $exitString = $text; | ||
| 27802 | } | ||
| 27803 | |||
| 27804 | # Process the title (if found) | ||
| 27805 | if ($title) { | ||
| 27806 | |||
| 27807 | $self->setRoomTitle($roomObj, $title); | ||
| 27808 | |||
| 27809 | # Preserve the list of exits (required for TTS); | ||
| 27810 | $self->ivAdd('ttsToReadHash', 'title', $title); | ||
| 27811 | } | ||
| 27812 | |||
| 27813 | if ($exitString) { | ||
| 27814 | |||
| 27815 | # (Again, only the first line is used) | ||
| 27816 | @bufferObjList = ($bufferObj); | ||
| 27817 | @lineTextList = ($exitString); | ||
| 27818 | @lineOffsetList = ($hashRef); | ||
| 27819 | |||
| 27820 | if ( | ||
| 27821 | ! $self->setRoomExit( | ||
| 27822 | $worldObj, | ||
| 27823 | $roomObj, | ||
| 27824 | 'brief', | ||
| 27825 | \@bufferObjList, | ||
| 27826 | \@lineTextList, | ||
| 27827 | \@lineOffsetList, | ||
| 27828 | ) | ||
| 27829 | ) { | ||
| 27830 | # The line is invalid (contains non-delimiters) | ||
| 27831 | return undef; | ||
| 27832 | } | ||
| 27833 | } | ||
| 27834 | |||
| 27835 | return 1; | ||
| 27836 | } | ||
| 27837 | |||
| 27838 | sub setRoomCmd { | ||
| 27839 | |||
| 27840 | # Called by $self->extractComponents (at stage 3) | ||
| 27841 | # Adds a list of room commands to the non-model room | ||
| 27842 | # | ||
| 27843 | # Expected arguments | ||
| 27844 | # $worldObj - The current world profile | ||
| 27845 | # $roomObj - A GA::ModelObj::Room object | ||
| 27846 | # @lineList - A list of lines comprising the room statement component 'room_cmd' | ||
| 27847 | # | ||
| 27848 | # Return values | ||
| 27849 | # 'undef' on improper arguments or if any line in @lineList is invalid | ||
| 27850 | # 1 otherwise | ||
| 27851 | |||
| 27852 | my ($self, $worldObj, $roomObj, @lineList) = @_; | ||
| 27853 | |||
| 27854 | # Local variables | ||
| 27855 | my ( | ||
| 27856 | @markerList, @cmdList, @modList, @finalList, | ||
| 27857 | %cmdHash, | ||
| 27858 | ); | ||
| 27859 | |||
| 27860 | # Check for improper arguments | ||
| 27861 | if (! defined $worldObj || ! defined $roomObj || ! @lineList) { | ||
| 27862 | |||
| 27863 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setRoomCmd', @_); | ||
| 27864 | } | ||
| 27865 | |||
| 27866 | # Preserve the original @lineList (required for TTS); | ||
| 27867 | $self->ivAdd('ttsToReadHash', 'command', join(' ', @lineList)); | ||
| 27868 | |||
| 27869 | # Check that no lines contain any non-delimiters (forbidden substrings) | ||
| 27870 | foreach my $line (@lineList) { | ||
| 27871 | |||
| 27872 | foreach my $delim ($worldObj->roomCmdNonDelimiterList) { | ||
| 27873 | |||
| 27874 | if (index ($line, $delim) > -1) { | ||
| 27875 | |||
| 27876 | # Invalid line; don't process any room commands | ||
| 27877 | return undef; | ||
| 27878 | } | ||
| 27879 | } | ||
| 27880 | } | ||
| 27881 | |||
| 27882 | # Remove left/right markers, if any, from each line in @lineList. (It's up to the user to | ||
| 27883 | # create left-marker regexes that start with '^' and right-marker regexes that end with | ||
| 27884 | # '$') | ||
| 27885 | @markerList = ( | ||
| 27886 | $worldObj->roomCmdLeftMarkerList, | ||
| 27887 | $worldObj->roomCmdRightMarkerList, | ||
| 27888 | ); | ||
| 27889 | |||
| 27890 | foreach my $line (@lineList) { | ||
| 27891 | |||
| 27892 | foreach my $marker (@markerList) { | ||
| 27893 | |||
| 27894 | $line =~ s/$marker//; | ||
| 27895 | } | ||
| 27896 | } | ||
| 27897 | |||
| 27898 | # Now extract room commands from every line in turn | ||
| 27899 | foreach my $line (@lineList) { | ||
| 27900 | |||
| 27901 | my @thisList = ($line); | ||
| 27902 | |||
| 27903 | # Sort in reverse order of length, otherwise unexpected problems might occur | ||
| 27904 | foreach my $delim ($worldObj->roomCmdDelimiterList) { | ||
| 27905 | |||
| 27906 | my @tempList = @thisList; | ||
| 27907 | @thisList = (); | ||
| 27908 | |||
| 27909 | foreach my $item (@tempList) { | ||
| 27910 | |||
| 27911 | my $offset; | ||
| 27912 | |||
| 27913 | # Can't use Perl split(), because $delim is not a regex | ||
| 27914 | do { | ||
| 27915 | |||
| 27916 | $offset = index($item, $delim); | ||
| 27917 | if ($offset >= 0) { | ||
| 27918 | |||
| 27919 | push (@thisList, substr($item, 0, $offset)); | ||
| 27920 | $item = substr($item, ($offset + length($delim))); | ||
| 27921 | |||
| 27922 | } else { | ||
| 27923 | |||
| 27924 | push (@thisList, $item); | ||
| 27925 | } | ||
| 27926 | |||
| 27927 | } until ($offset < 0); | ||
| 27928 | } | ||
| 27929 | } | ||
| 27930 | |||
| 27931 | push (@cmdList, @thisList); | ||
| 27932 | } | ||
| 27933 | |||
| 27934 | # Remove any leading/trailing whitespace from strings in @cmdList, convert multiple- | ||
| 27935 | # character whitespace into single-character whitespace, convert capitals to lower case, | ||
| 27936 | # and remove empty strings | ||
| 27937 | foreach my $cmd (@cmdList) { | ||
| 27938 | |||
| 27939 | $cmd = $axmud::CLIENT->trimWhitespace($cmd, TRUE); | ||
| 27940 | if ($cmd) { | ||
| 27941 | |||
| 27942 | push (@modList, lc($cmd)); | ||
| 27943 | } | ||
| 27944 | } | ||
| 27945 | |||
| 27946 | # Split the commands(s) into single letters, if required | ||
| 27947 | if ($worldObj->roomCmdSplitCharFlag) { | ||
| 27948 | |||
| 27949 | @cmdList = @modList; | ||
| 27950 | @modList = (); | ||
| 27951 | foreach my $cmd (@cmdList) { | ||
| 27952 | |||
| 27953 | push (@modList, split('', $cmd)); | ||
| 27954 | } | ||
| 27955 | } | ||
| 27956 | |||
| 27957 | # Combine the commands in the non-model room (if any have been added following an earlier | ||
| 27958 | # call to this function) with @modList, and eliminate duplicates | ||
| 27959 | |||
| 27960 | # Go through @modList, eliminating duplicates | ||
| 27961 | foreach my $cmd ($roomObj->roomCmdList, @modList) { | ||
| 27962 | |||
| 27963 | if (! exists $cmdHash{$cmd}) { | ||
| 27964 | |||
| 27965 | $cmdHash{$cmd} = undef; | ||
| 27966 | push (@finalList, $cmd); | ||
| 27967 | } | ||
| 27968 | } | ||
| 27969 | |||
| 27970 | # Update the non-model room object | ||
| 27971 | $roomObj->ivPush('roomCmdList', @finalList); | ||
| 27972 | $roomObj->ivPoke('tempRoomCmdList', $roomObj->roomCmdList); | ||
| 27973 | |||
| 27974 | # Operation complete | ||
| 27975 | return 1; | ||
| 27976 | } | ||
| 27977 | |||
| 27978 | sub setRoomMudlibPath { | ||
| 27979 | |||
| 27980 | # Called by $self->extractComponents (at stage 3) | ||
| 27981 | # Adds a mudlib path to the non-model room | ||
| 27982 | # | ||
| 27983 | # Expected arguments | ||
| 27984 | # $roomObj - A GA::ModelObj::Room object | ||
| 27985 | # @lineList - A list of lines comprising the room statement component 'mudlib_path'; | ||
| 27986 | # should contain only one line. Only the first non-empty line is used | ||
| 27987 | # | ||
| 27988 | # Return values | ||
| 27989 | # 'undef' on improper arguments or if @lineList doesn't contain the mudlib path | ||
| 27990 | # 1 otherwise | ||
| 27991 | |||
| 27992 | my ($self, $roomObj, @lineList) = @_; | ||
| 27993 | |||
| 27994 | # Check for improper arguments | ||
| 27995 | if (! defined $roomObj || ! @lineList) { | ||
| 27996 | |||
| 27997 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setRoomMudlibPath', @_); | ||
| 27998 | } | ||
| 27999 | |||
| 28000 | # Find the first non-empty line, and use it | ||
| 28001 | foreach my $line (@lineList) { | ||
| 28002 | |||
| 28003 | if ($line =~ m/\S/) { | ||
| 28004 | |||
| 28005 | # Remove leading/trailing whitespace | ||
| 28006 | $line = $axmud::CLIENT->trimWhitespace($line); | ||
| 28007 | # Set the room's mudlib path | ||
| 28008 | $roomObj->ivPoke('sourceCodePath', $line); | ||
| 28009 | |||
| 28010 | return 1; | ||
| 28011 | } | ||
| 28012 | } | ||
| 28013 | |||
| 28014 | # Mudlib path not found | ||
| 28015 | return undef; | ||
| 28016 | } | ||
| 28017 | |||
| 28018 | sub setRoomWeather { | ||
| 28019 | |||
| 28020 | # Called by $self->extractComponents (at stage 3) | ||
| 28021 | # Adds text describing the weather, the time of day and so on to a task hash used to display | ||
| 28022 | # that information in the task window | ||
| 28023 | # (The text isn't anywhere stored in the world model) | ||
| 28024 | # | ||
| 28025 | # Expected arguments | ||
| 28026 | # $componentObj - The GA::Obj::Component of the type 'weather' | ||
| 28027 | # @lineList - A list of lines comprising that room statement component | ||
| 28028 | # | ||
| 28029 | # Return values | ||
| 28030 | # 'undef' on improper arguments or if the lines in @lineList contain no non-space | ||
| 28031 | # characters | ||
| 28032 | # 1 otherwise | ||
| 28033 | |||
| 28034 | my ($self, $componentObj, @lineList) = @_; | ||
| 28035 | |||
| 28036 | # Local variables | ||
| 28037 | my ( | ||
| 28038 | $string, | ||
| 28039 | @newList, | ||
| 28040 | ); | ||
| 28041 | |||
| 28042 | # Check for improper arguments | ||
| 28043 | if (! defined $componentObj || ! @lineList) { | ||
| 28044 | |||
| 28045 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setRoomWeather', @_); | ||
| 28046 | } | ||
| 28047 | |||
| 28048 | # Merge the lines into a single string, ignoring any empty lines | ||
| 28049 | foreach my $line (@lineList) { | ||
| 28050 | |||
| 28051 | if ($line =~ m/\S/) { | ||
| 28052 | |||
| 28053 | # Remove leading/trailing whitespace. The TRUE flag means to remove multiple space | ||
| 28054 | # characters in the middle of the line, too | ||
| 28055 | $line = $axmud::CLIENT->trimWhitespace($line, TRUE); | ||
| 28056 | push (@newList, $line); | ||
| 28057 | } | ||
| 28058 | } | ||
| 28059 | |||
| 28060 | if (! @newList) { | ||
| 28061 | |||
| 28062 | # No non-space characters found, so there's nothing to display | ||
| 28063 | return undef; | ||
| 28064 | |||
| 28065 | } else { | ||
| 28066 | |||
| 28067 | # If the room statement contains (for some reason) multiple 'weather' components with | ||
| 28068 | # the same name, merge them all | ||
| 28069 | if ($self->ivExists('weatherHash', $componentObj->name)) { | ||
| 28070 | |||
| 28071 | unshift (@newList, $self->ivShow('weatherHash', $componentObj->name)); | ||
| 28072 | } | ||
| 28073 | |||
| 28074 | # Store the merged string | ||
| 28075 | $self->ivAdd('weatherHash', $componentObj->name, join(' ', @newList)); | ||
| 28076 | |||
| 28077 | return 1; | ||
| 28078 | } | ||
| 28079 | } | ||
| 28080 | |||
| 28081 | sub setRoomFromMxp { | ||
| 28082 | |||
| 28083 | # Called by $self->processMxpProperties (at stage 3) | ||
| 28084 | # Sets the room title, description, exit list and remote number, if the world has used | ||
| 28085 | # MXP tag properties to specify them | ||
| 28086 | # | ||
| 28087 | # Expected arguments | ||
| 28088 | # $worldObj - Shortcut to the current world profile object | ||
| 28089 | # $roomObj - A GA::ModelObj::Room object | ||
| 28090 | # %mxpPropHash - A hash of MXP tag properties (should not be empty), in the form | ||
| 28091 | # $mxpPropHash{tag} = string | ||
| 28092 | # | ||
| 28093 | # Return values | ||
| 28094 | # 'undef' on improper arguments | ||
| 28095 | # 1 otherwise | ||
| 28096 | |||
| 28097 | my ($self, $worldObj, $roomObj, %mxpPropHash) = @_; | ||
| 28098 | |||
| 28099 | # Local variables | ||
| 28100 | my ( | ||
| 28101 | $title, $descrip, $exitString, $offset, $stopFlag, $num, | ||
| 28102 | @exitList, @modList, | ||
| 28103 | ); | ||
| 28104 | |||
| 28105 | # Check for improper arguments | ||
| 28106 | if (! defined $worldObj || ! defined $roomObj || ! %mxpPropHash) { | ||
| 28107 | |||
| 28108 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setRoomFromMxp', @_); | ||
| 28109 | } | ||
| 28110 | |||
| 28111 | # Set the room title, if specified | ||
| 28112 | $title = $mxpPropHash{'RoomName'}; | ||
| 28113 | if (defined $title) { | ||
| 28114 | |||
| 28115 | $title = $axmud::CLIENT->trimWhitespace($title); | ||
| 28116 | $roomObj->ivPush('titleList', $title); | ||
| 28117 | $self->ivAdd('ttsToReadHash', 'title', $title); | ||
| 28118 | } | ||
| 28119 | |||
| 28120 | $descrip = $mxpPropHash{'RoomDesc'}; | ||
| 28121 | if (defined $descrip) { | ||
| 28122 | |||
| 28123 | $descrip = $axmud::CLIENT->trimWhitespace($descrip); | ||
| 28124 | $roomObj->ivAdd('descripHash', $self->session->worldModelObj->lightStatus, $descrip); | ||
| 28125 | $self->ivAdd('ttsToReadHash', 'descrip', $descrip); | ||
| 28126 | } | ||
| 28127 | |||
| 28128 | $exitString = $mxpPropHash{'RoomExit'}; | ||
| 28129 | if (defined $exitString) { | ||
| 28130 | |||
| 28131 | # This code is borrowed from $self->setRoomExit, removing most of its features, and | ||
| 28132 | # just splitting the string using known delimiters | ||
| 28133 | $offset = 0; | ||
| 28134 | |||
| 28135 | # Split $exitString into a list of exits, using the normal delimiters specified by the | ||
| 28136 | # current world profile | ||
| 28137 | do { | ||
| 28138 | |||
| 28139 | my ($posn, $delim); | ||
| 28140 | |||
| 28141 | # Find the position of the first delimiter at $offset or after | ||
| 28142 | foreach my $thisDelim ( | ||
| 28143 | $worldObj->verboseExitDelimiterList, | ||
| 28144 | $worldObj->briefExitDelimiterList, | ||
| 28145 | ) { | ||
| 28146 | my $thisPosn = index(substr($exitString, $offset), $thisDelim); | ||
| 28147 | if ($thisPosn >= 0) { | ||
| 28148 | |||
| 28149 | if (! defined $posn || $posn > $thisPosn) { | ||
| 28150 | |||
| 28151 | $posn = $thisPosn; | ||
| 28152 | $delim = $thisDelim; | ||
| 28153 | } | ||
| 28154 | } | ||
| 28155 | } | ||
| 28156 | |||
| 28157 | if (! defined $posn) { | ||
| 28158 | |||
| 28159 | # $exitString, from $offset onwards, contains no delimiters | ||
| 28160 | push (@exitList, substr($exitString, $offset)); | ||
| 28161 | $stopFlag = TRUE; | ||
| 28162 | |||
| 28163 | } else { | ||
| 28164 | |||
| 28165 | # $text contains an offset an exit between $offset and ($offset + $posn) | ||
| 28166 | push (@exitList, substr($exitString, $offset, $posn)); | ||
| 28167 | # On the next iteration of this loop, check from the start of the next exit | ||
| 28168 | # string | ||
| 28169 | $offset += $posn + length($delim); | ||
| 28170 | } | ||
| 28171 | |||
| 28172 | } until ($stopFlag); | ||
| 28173 | |||
| 28174 | # Remove any leading/trailing whitespace | ||
| 28175 | # Also, convert the list into groups of three, which is the format $self->processExits | ||
| 28176 | # is expecting. This function doesn't test the exit colours, so just behave as if the | ||
| 28177 | # default colour was used | ||
| 28178 | foreach my $exit (@exitList) { | ||
| 28179 | |||
| 28180 | push ( | ||
| 28181 | @modList, | ||
| 28182 | $axmud::CLIENT->trimWhitespace($exit), | ||
| 28183 | $axmud::CLIENT->constTextColour, | ||
| 28184 | $axmud::CLIENT->constUnderlayColour, | ||
| 28185 | ); | ||
| 28186 | } | ||
| 28187 | |||
| 28188 | # Create exit objects for each exit | ||
| 28189 | $self->processExits($worldObj, $roomObj, @modList); | ||
| 28190 | } | ||
| 28191 | |||
| 28192 | $num = $mxpPropHash{'RoomNum'}; | ||
| 28193 | if (defined $num) { | ||
| 28194 | |||
| 28195 | $num = $axmud::CLIENT->trimWhitespace($num); | ||
| 28196 | $roomObj->ivAdd('protocolRoomHash', 'vnum', $num); | ||
| 28197 | } | ||
| 28198 | |||
| 28199 | return 1; | ||
| 28200 | } | ||
| 28201 | |||
| 28202 | # Room supplementary methods | ||
| 28203 | |||
| 28204 | sub processExits { | ||
| 28205 | |||
| 28206 | # Called by $self->setRoomExit | ||
| 28207 | # Given a non-model room object and a list of exits, sorts the exits into the standard order | ||
| 28208 | # and creates exit objects for each exit | ||
| 28209 | # Processes any exit states and removes any substrings matching exit remove patterns | ||
| 28210 | # | ||
| 28211 | # Expected arguments | ||
| 28212 | # $worldObj - The current world profile | ||
| 28213 | # $roomObj - A GA::ModelObj::Room object | ||
| 28214 | # | ||
| 28215 | # Optional arguments | ||
| 28216 | # @exitList - A list of exits and the Axmud colour tags applied to the first | ||
| 28217 | # characters. List in groups of 3, in the form | ||
| 28218 | # (exit_string, text_colour, underlay_colour) | ||
| 28219 | # - Might be an empty list, if the room statement contained a line like | ||
| 28220 | # 'Obvious exits: none', or if 'none' is one the world profile's | ||
| 28221 | # non-delimiter strings (stored in ->verboseExitNonDelimiterList or | ||
| 28222 | # ->briefExitNonDelimiterList) | ||
| 28223 | # | ||
| 28224 | # Return values | ||
| 28225 | # 'undef' on improper arguments or if @exitList contains an invalid exit | ||
| 28226 | # 1 otherwise | ||
| 28227 | |||
| 28228 | my ($self, $worldObj, $roomObj, @exitList) = @_; | ||
| 28229 | |||
| 28230 | # Local variables | ||
| 28231 | my ( | ||
| 28232 | $dictObj, $wmObj, | ||
| 28233 | @objList, @sortedList, | ||
| 28234 | ); | ||
| 28235 | |||
| 28236 | # Check for improper arguments | ||
| 28237 | if (! defined $worldObj || ! defined $roomObj) { | ||
| 28238 | |||
| 28239 | return $axmud::CLIENT->writeImproper($self->_objClass . '->processExits', @_); | ||
| 28240 | } | ||
| 28241 | |||
| 28242 | # If no exits were specified (e.g. 'Obvious exits: none'), there are no exit objects to add | ||
| 28243 | if (! @exitList) { | ||
| 28244 | |||
| 28245 | return 1; | ||
| 28246 | } | ||
| 28247 | |||
| 28248 | # Import the current dictionary and world model object | ||
| 28249 | $dictObj = $self->session->currentDict; | ||
| 28250 | $wmObj = $self->session->worldModelObj; | ||
| 28251 | |||
| 28252 | # For each exit, create a non-exit model object | ||
| 28253 | do { | ||
| 28254 | |||
| 28255 | my ( | ||
| 28256 | $exitString, $textColour, $underlayColour, $info, $state, $modString, $assisted, | ||
| 28257 | $exitObj, | ||
| 28258 | ); | ||
| 28259 | |||
| 28260 | $exitString = shift @exitList; | ||
| 28261 | $textColour = shift @exitList; | ||
| 28262 | $underlayColour = shift @exitList; | ||
| 28263 | |||
| 28264 | # If any parts of the exit match a pattern in $worldObj->exitInfoPatternList, remove | ||
| 28265 | # them (but keep the first group substring, if any) | ||
| 28266 | INNER: foreach my $pattern ($worldObj->exitInfoPatternList) { | ||
| 28267 | |||
| 28268 | if ($exitString =~ m/$pattern/) { | ||
| 28269 | |||
| 28270 | $info = $1; | ||
| 28271 | $exitString =~ s/$pattern//; | ||
| 28272 | last INNER; | ||
| 28273 | } | ||
| 28274 | } | ||
| 28275 | |||
| 28276 | # If any parts of the exit match a pattern in $worldObj->exitRemovePatternList, remove | ||
| 28277 | # them | ||
| 28278 | foreach my $pattern ($worldObj->exitRemovePatternList) { | ||
| 28279 | |||
| 28280 | $exitString =~ s/$pattern//gi; | ||
| 28281 | } | ||
| 28282 | |||
| 28283 | # Ignore the exit if all characters have been removed | ||
| 28284 | if ($exitString ne '') { | ||
| 28285 | |||
| 28286 | # Remove any exit state strings from exits (verbose and brief) | ||
| 28287 | ($state, $modString) = $wmObj->checkExitState($worldObj, $exitString); | ||
| 28288 | |||
| 28289 | # GA::Profile::World->exitStateTagHash uses the value 'ignore' for any exit state | ||
| 28290 | # strings which should be ignored (and for which GA::Obj::Exit->exitState should | ||
| 28291 | # keep its default value of 'normal' | ||
| 28292 | if ($state eq 'ignore') { | ||
| 28293 | |||
| 28294 | $state = 'normal'; | ||
| 28295 | } | ||
| 28296 | |||
| 28297 | # An exit state can also be indicated by an Axmud colour tag (don't apply this test | ||
| 28298 | # if an exit state has already been detected) | ||
| 28299 | if ($state eq 'normal') { | ||
| 28300 | |||
| 28301 | INNER: foreach my $tag ($worldObj->ivKeys('exitStateTagHash')) { | ||
| 28302 | |||
| 28303 | if ($tag eq $textColour || $tag eq $underlayColour) { | ||
| 28304 | |||
| 28305 | $state = $worldObj->ivShow('exitStateTagHash', $tag); | ||
| 28306 | last INNER; | ||
| 28307 | } | ||
| 28308 | } | ||
| 28309 | } | ||
| 28310 | |||
| 28311 | # Deal with custom strings | ||
| 28312 | if (! $axmud::CLIENT->ivExists('constExitStateHash', $state)) { | ||
| 28313 | |||
| 28314 | # $state is a custom string which should be used as the exit's assisted move, | ||
| 28315 | # once it is has been created | ||
| 28316 | $assisted = $state; | ||
| 28317 | $state = 'normal'; | ||
| 28318 | |||
| 28319 | # If this custom string contains the @@@ sequence, substitute that sequence for | ||
| 28320 | # the exit direction (i.e. convert 'swim @@@' into 'swim east') | ||
| 28321 | $assisted =~ s/@@@/$modString/g; | ||
| 28322 | } | ||
| 28323 | |||
| 28324 | # Unabbreviate custom primary/recognised secondary abbreviated directions | ||
| 28325 | $modString = $dictObj->unabbrevDir($modString); | ||
| 28326 | |||
| 28327 | # Create an exit object for this exit | ||
| 28328 | $exitObj = Games::Axmud::Obj::Exit->new( | ||
| 28329 | $self->session, | ||
| 28330 | $modString, # Nominal direction with state symbols (if any) removed | ||
| 28331 | 'non_model', # Non-exit model object | ||
| 28332 | ); | ||
| 28333 | |||
| 28334 | if (! $exitObj) { | ||
| 28335 | |||
| 28336 | # Line was probably mis-identified as containing exits | ||
| 28337 | return undef; | ||
| 28338 | |||
| 28339 | } else { | ||
| 28340 | |||
| 28341 | push (@objList, $exitObj); | ||
| 28342 | |||
| 28343 | # Set the exit type, info and state | ||
| 28344 | $exitObj->ivPoke('exitType', $dictObj->ivShow('combDirHash', $modString)); | ||
| 28345 | $exitObj->ivPoke('exitInfo', $info); # May be 'undef' | ||
| 28346 | $exitObj->ivPoke('exitState', $state); # May be 'normal' | ||
| 28347 | |||
| 28348 | if (defined $assisted) { | ||
| 28349 | |||
| 28350 | $exitObj->ivAdd( | ||
| 28351 | 'assistedHash', | ||
| 28352 | $self->session->currentWorld->name, | ||
| 28353 | $assisted, | ||
| 28354 | ); | ||
| 28355 | } | ||
| 28356 | } | ||
| 28357 | } | ||
| 28358 | |||
| 28359 | } until (! @exitList); | ||
| 28360 | |||
| 28361 | # Sort @objList into the standard order (i.e. north before south, etc) | ||
| 28362 | @sortedList = $dictObj->sortExitObjs(@objList); | ||
| 28363 | |||
| 28364 | # Update the specified room object | ||
| 28365 | foreach my $exitObj (@sortedList) { | ||
| 28366 | |||
| 28367 | $roomObj->ivPush('sortedExitList', $exitObj->dir); | ||
| 28368 | $roomObj->ivAdd('exitNumHash', $exitObj->dir, $exitObj); | ||
| 28369 | } | ||
| 28370 | |||
| 28371 | # Sorting complete | ||
| 28372 | return 1; | ||
| 28373 | } | ||
| 28374 | |||
| 28375 | sub chooseDescrip { | ||
| 28376 | |||
| 28377 | # Called by $self->refreshWin | ||
| 28378 | # Each room model object can contain 0, 1 or more (verbose) descriptions. This function | ||
| 28379 | # chooses the most useful one. | ||
| 28380 | # If there's a description matching the current light status, that description is returned | ||
| 28381 | # Otherwise, searches the customisable list of light statues and returns the first | ||
| 28382 | # description matching a value in the list | ||
| 28383 | # If no matching descriptions are found (because none of the room's descriptions matches a | ||
| 28384 | # recognised light status), returns 'undef' | ||
| 28385 | # | ||
| 28386 | # Expected arguments | ||
| 28387 | # $roomObj - blessed reference of the room object to check | ||
| 28388 | # | ||
| 28389 | # Return values | ||
| 28390 | # 'undef' on improper arguments or if no matching description is found | ||
| 28391 | # Otherwise, returns the chosen description (a string) | ||
| 28392 | |||
| 28393 | my ($self, $roomObj, $check) = @_; | ||
| 28394 | |||
| 28395 | # Local variables | ||
| 28396 | my ( | ||
| 28397 | $modelObj, | ||
| 28398 | %hash, | ||
| 28399 | ); | ||
| 28400 | |||
| 28401 | # Check for improper arguments | ||
| 28402 | if (! defined $roomObj || defined $check) { | ||
| 28403 | |||
| 28404 | $axmud::CLIENT->writeImproper($self->_objClass . '->chooseDescrip', @_); | ||
| 28405 | } | ||
| 28406 | |||
| 28407 | # Import the world model object | ||
| 28408 | $modelObj = $self->session->worldModelObj; | ||
| 28409 | # Import the verbose description hash | ||
| 28410 | %hash = $roomObj->descripHash; | ||
| 28411 | |||
| 28412 | # If a description matching the current light status exists, return it | ||
| 28413 | if (exists $hash{$modelObj->lightStatus}) { | ||
| 28414 | |||
| 28415 | return $hash{$modelObj->lightStatus}; | ||
| 28416 | |||
| 28417 | } else { | ||
| 28418 | |||
| 28419 | # Otherwise, return the first verbose description matching a recognised light status | ||
| 28420 | foreach my $status ($modelObj->lightStatusList) { | ||
| 28421 | |||
| 28422 | if (exists $hash{$status}) { | ||
| 28423 | |||
| 28424 | return $hash{$status}; | ||
| 28425 | } | ||
| 28426 | } | ||
| 28427 | |||
| 28428 | # No matching description found | ||
| 28429 | return undef; | ||
| 28430 | } | ||
| 28431 | } | ||
| 28432 | |||
| 28433 | # Other methods | ||
| 28434 | |||
| 28435 | sub refreshWin { | ||
| 28436 | |||
| 28437 | # Called by $self->processLine, ->haltAnalysis and ->set_updateFromMsdp | ||
| 28438 | # Refreshes the task window (if it is open) | ||
| 28439 | # | ||
| 28440 | # Expected arguments | ||
| 28441 | # (none besides $self) | ||
| 28442 | # | ||
| 28443 | # Optional arguments | ||
| 28444 | # $failedExit - If a failed exit was detected, $self->processLine sends the direction of | ||
| 28445 | # the movement command that it thinks caused the failed exit. If the | ||
| 28446 | # direction matches one of the room's known exits, we can mark it as | ||
| 28447 | # (temporarily) unavailable | ||
| 28448 | # | ||
| 28449 | # Return values | ||
| 28450 | # 'undef' on improper arguments, or if the task window isn't open | ||
| 28451 | # 1 otherwise | ||
| 28452 | |||
| 28453 | my ($self, $failedExit, $check) = @_; | ||
| 28454 | |||
| 28455 | # Local variables | ||
| 28456 | my ( | ||
| 28457 | $dictObj, $roomID, $nextTag, $verboseDescrip, $exitString, $roomCmdString, $corpseCount, | ||
| 28458 | $bodyPartCount, $protocolRoomString, $protocolExitString, $colour, $posn, $before, | ||
| 28459 | $after, | ||
| 28460 | @titleList, @sortedExitList, @objList, @modObjList, @charList, @minionList, | ||
| 28461 | @sentientList, @creatureList, @corpseList, @otherList, @newOtherList, @moveList, | ||
| 28462 | %exitNumHash, %otherHash, %protocolRoomHash, %protocolExitHash, | ||
| 28463 | ); | ||
| 28464 | |||
| 28465 | # Check for improper arguments | ||
| 28466 | if (defined $check) { | ||
| 28467 | |||
| 28468 | return $axmud::CLIENT->writeImproper($self->_objClass . '->refreshWin', @_); | ||
| 28469 | } | ||
| 28470 | |||
| 28471 | # Don't do anything if the task window isn't open | ||
| 28472 | if (! $self->taskWinFlag) { | ||
| 28473 | |||
| 28474 | return undef; | ||
| 28475 | } | ||
| 28476 | |||
| 28477 | # Import the current dictonary (for convenience) | ||
| 28478 | $dictObj = $self->session->currentDict; | ||
| 28479 | |||
| 28480 | # Import the lists and hashes for display, if they've been set ($self->roomObj may not be | ||
| 28481 | # set if there's been a failed exit) | ||
| 28482 | if ($self->roomObj) { | ||
| 28483 | |||
| 28484 | @titleList = $self->roomObj->titleList; | ||
| 28485 | @sortedExitList = $self->roomObj->sortedExitList; | ||
| 28486 | %exitNumHash = $self->roomObj->exitNumHash; | ||
| 28487 | @objList = $self->roomObj->tempObjList; | ||
| 28488 | |||
| 28489 | # Import protocol data hashes (for speed) | ||
| 28490 | %protocolRoomHash = $self->roomObj->protocolRoomHash; | ||
| 28491 | %protocolExitHash = $self->roomObj->protocolExitHash; | ||
| 28492 | } | ||
| 28493 | |||
| 28494 | # Set the task window's title bar (if open) to show the number of expected room statements | ||
| 28495 | $self->prepareTitleBar(); | ||
| 28496 | # If ->arrivalTag has been set (by one of the route commands, e.g. ';go') and if the current | ||
| 28497 | # room is known and the room doesn't already have a tag, name the room with the supplied | ||
| 28498 | # tag | ||
| 28499 | if (! $self->moveList && $self->arrivalTag && $self->roomObj && ! $self->roomObj->roomTag) { | ||
| 28500 | |||
| 28501 | $self->roomObj->ivPoke('roomTag', $self->arrivalTag); | ||
| 28502 | $self->ivEmpty('arrivalTag'); | ||
| 28503 | } | ||
| 28504 | |||
| 28505 | # If the room has a tag and/or its world model number is known, display them first | ||
| 28506 | if ($self->roomObj && $self->roomObj->roomTag) { | ||
| 28507 | |||
| 28508 | # If the automapper displays all tags in upper-case, so should the Locator task | ||
| 28509 | if ($self->session->worldModelObj->capitalisedRoomTagFlag) { | ||
| 28510 | $roomID = uc($self->roomObj->roomTag); | ||
| 28511 | } else { | ||
| 28512 | $roomID = $self->roomObj->roomTag; | ||
| 28513 | } | ||
| 28514 | } | ||
| 28515 | |||
| 28516 | if ($self->modelNumber) { | ||
| 28517 | |||
| 28518 | if ($roomID) { | ||
| 28519 | |||
| 28520 | $roomID .= ' '; | ||
| 28521 | } | ||
| 28522 | |||
| 28523 | $roomID .= '#' . $self->modelNumber; | ||
| 28524 | } | ||
| 28525 | |||
| 28526 | if ($roomID) { | ||
| 28527 | |||
| 28528 | # If the automapper's current location isn't set, the room's tag must have been set | ||
| 28529 | # following a command like ';drive' or ';quick'. If so, display the text in blue, so | ||
| 28530 | # that the user can see it's not a tag used by a room in the world model | ||
| 28531 | if ( | ||
| 28532 | ! $self->session->mapObj->currentRoom | ||
| 28533 | && $self->roomObj | ||
| 28534 | && $self->roomObj->roomTag | ||
| 28535 | ) { | ||
| 28536 | $self->insertText('[' . $roomID . '] ', 'empty', 'BLUE'); | ||
| 28537 | |||
| 28538 | } else { | ||
| 28539 | |||
| 28540 | $self->insertText('[' . $roomID . '] ', 'empty', 'RED'); | ||
| 28541 | } | ||
| 28542 | |||
| 28543 | # The room title/verbose descrips should use the 'echo' argument to continue writing | ||
| 28544 | # immediately after the $roomID string | ||
| 28545 | $nextTag = 'echo'; | ||
| 28546 | |||
| 28547 | } else { | ||
| 28548 | |||
| 28549 | # The verbose/brief descrips should use the 'empty' argument to empty the task window | ||
| 28550 | $nextTag = 'empty'; | ||
| 28551 | } | ||
| 28552 | |||
| 28553 | # Show a special message if the current location isn't known, or if the room is dark | ||
| 28554 | if (! $self->roomObj) { | ||
| 28555 | |||
| 28556 | if (! $self->modelNumber) { | ||
| 28557 | $self->insertText('<location unknown>', $nextTag, 'RED'); | ||
| 28558 | } else { | ||
| 28559 | $self->insertText('<waiting for room statement>', $nextTag, 'RED'); | ||
| 28560 | } | ||
| 28561 | |||
| 28562 | return 1; | ||
| 28563 | |||
| 28564 | } elsif ($self->roomObj->currentlyDarkFlag) { | ||
| 28565 | |||
| 28566 | $self->insertText('<dark room>', $nextTag, 'RED'); | ||
| 28567 | return 1; | ||
| 28568 | |||
| 28569 | } elsif ($self->roomObj->unspecifiedFlag) { | ||
| 28570 | |||
| 28571 | $self->insertText('<unspecified room>', $nextTag, 'RED'); | ||
| 28572 | return 1; | ||
| 28573 | } | ||
| 28574 | |||
| 28575 | # Display protocol room/exit data reported by the server, if available | ||
| 28576 | if (%protocolRoomHash || %protocolExitHash) { | ||
| 28577 | |||
| 28578 | if (exists $protocolExitHash{'vnum'}) { | ||
| 28579 | |||
| 28580 | $protocolRoomString = '#' . $protocolRoomHash{'vnum'}; | ||
| 28581 | } | ||
| 28582 | |||
| 28583 | if (exists $protocolRoomHash{'xpos'}) { | ||
| 28584 | |||
| 28585 | if ($protocolRoomString) { | ||
| 28586 | $protocolRoomString .= ' X:' . $protocolRoomHash{'xpos'}; | ||
| 28587 | } else { | ||
| 28588 | $protocolRoomString = 'X:' . $protocolRoomHash{'xpos'}; | ||
| 28589 | } | ||
| 28590 | } | ||
| 28591 | |||
| 28592 | if (exists $protocolRoomHash{'ypos'}) { | ||
| 28593 | |||
| 28594 | if ($protocolRoomString) { | ||
| 28595 | $protocolRoomString .= ' Y:' . $protocolRoomHash{'ypos'}; | ||
| 28596 | } else { | ||
| 28597 | $protocolRoomString = 'Y:' . $protocolRoomHash{'ypos'}; | ||
| 28598 | } | ||
| 28599 | } | ||
| 28600 | |||
| 28601 | if (exists $protocolRoomHash{'zpos'}) { | ||
| 28602 | |||
| 28603 | if ($protocolRoomString) { | ||
| 28604 | $protocolRoomString .= ' Z:' . $protocolRoomHash{'zpos'}; | ||
| 28605 | } else { | ||
| 28606 | $protocolRoomString = 'Z:' . $protocolRoomHash{'zpos'}; | ||
| 28607 | } | ||
| 28608 | } | ||
| 28609 | |||
| 28610 | if (exists $protocolRoomHash{'terrain'}) { | ||
| 28611 | |||
| 28612 | if ($protocolRoomString) { | ||
| 28613 | $protocolRoomString .= ' T:' . $protocolRoomHash{'terrain'}; | ||
| 28614 | } else { | ||
| 28615 | $protocolRoomString = 'T:' . $protocolRoomHash{'terrain'}; | ||
| 28616 | } | ||
| 28617 | } | ||
| 28618 | |||
| 28619 | if (%protocolExitHash) { | ||
| 28620 | |||
| 28621 | if ($protocolRoomString) { | ||
| 28622 | $protocolRoomString .= ' E:'; | ||
| 28623 | } else { | ||
| 28624 | $protocolRoomString = 'E:'; | ||
| 28625 | } | ||
| 28626 | |||
| 28627 | foreach my $abbrevDir (sort {lc($a) cmp lc($b)} (keys %protocolExitHash)) { | ||
| 28628 | |||
| 28629 | my $destRoomNum = $protocolExitHash{$abbrevDir}; | ||
| 28630 | |||
| 28631 | if ($protocolExitString) { | ||
| 28632 | $protocolExitString .= ' ' . $abbrevDir . '>' . $destRoomNum; | ||
| 28633 | } else { | ||
| 28634 | $protocolExitString = $abbrevDir . '>' . $destRoomNum; | ||
| 28635 | } | ||
| 28636 | } | ||
| 28637 | |||
| 28638 | $protocolRoomString .= $protocolExitString; | ||
| 28639 | } | ||
| 28640 | |||
| 28641 | $self->insertText($protocolRoomString, $nextTag, 'YELLOW'); | ||
| 28642 | $nextTag = 'before'; | ||
| 28643 | } | ||
| 28644 | |||
| 28645 | # Decide which verbose description to use | ||
| 28646 | $verboseDescrip = $self->chooseDescrip($self->roomObj); | ||
| 28647 | |||
| 28648 | # Apply limit to size of verbose description, if necessary | ||
| 28649 | if ( | ||
| 28650 | $self->winDescripLimit | ||
| 28651 | && $verboseDescrip | ||
| 28652 | && length ($verboseDescrip) > $self->winDescripLimit | ||
| 28653 | ) { | ||
| 28654 | # Reduce the size of the verbose description | ||
| 28655 | $verboseDescrip = substr($verboseDescrip, 0, $self->winDescripLimit) ; | ||
| 28656 | # Remove incomplete words at the end | ||
| 28657 | $verboseDescrip =~ s/\w+$//; | ||
| 28658 | # Then remove any whitespace that preceded it | ||
| 28659 | $verboseDescrip =~ s/\s+$//; | ||
| 28660 | # Then remove the first non-alphanumeric character (want to remove commas and full | ||
| 28661 | # stops, but don't want to remove a sequence of such characters, which might be | ||
| 28662 | # important) | ||
| 28663 | $verboseDescrip =~ s/\W$//; | ||
| 28664 | # Some descrips contain a lot of whitespace (e.g. one containing a menu). In this | ||
| 28665 | # window, we want to reduce all whitespace to a single space | ||
| 28666 | $verboseDescrip =~ s/\s{1,}/ /g; | ||
| 28667 | # Finally, add an ellipsis | ||
| 28668 | $verboseDescrip .= '...'; | ||
| 28669 | } | ||
| 28670 | |||
| 28671 | # Display room title description (in red), if known | ||
| 28672 | # Display verbose room description (in white), if known | ||
| 28673 | if (@titleList) { | ||
| 28674 | |||
| 28675 | $self->insertText($titleList[0], $nextTag, 'RED'); | ||
| 28676 | if (defined $verboseDescrip) { | ||
| 28677 | |||
| 28678 | $self->insertText($verboseDescrip, 'white'); | ||
| 28679 | } | ||
| 28680 | |||
| 28681 | } elsif (defined $verboseDescrip) { | ||
| 28682 | |||
| 28683 | $self->insertText($verboseDescrip, $nextTag, 'white'); | ||
| 28684 | |||
| 28685 | } else { | ||
| 28686 | |||
| 28687 | $self->insertText('<description unknown>', $nextTag, 'white'); | ||
| 28688 | } | ||
| 28689 | |||
| 28690 | # If the room's source code path is known, display it | ||
| 28691 | if ($self->roomObj && $self->roomObj->sourceCodePath) { | ||
| 28692 | |||
| 28693 | $self->insertText($self->roomObj->sourceCodePath, 'yellow'); | ||
| 28694 | } | ||
| 28695 | |||
| 28696 | # Display list of exits (in cyan), if known | ||
| 28697 | if (defined $sortedExitList[0]) { | ||
| 28698 | |||
| 28699 | foreach my $exit (@sortedExitList) { | ||
| 28700 | |||
| 28701 | my ($modExit, $autoDir, $exitNum, $exitObj); | ||
| 28702 | |||
| 28703 | # If it's a secondary direction that's been mapped onto a primary direction, | ||
| 28704 | # display the primary direction too | ||
| 28705 | $modExit = $exit; | ||
| 28706 | $autoDir = $dictObj->ivShow('secondaryAutoHash', $exit); | ||
| 28707 | if (defined $autoDir) { | ||
| 28708 | |||
| 28709 | $modExit .= '/' . $dictObj->ivShow('primaryDirHash', $autoDir); | ||
| 28710 | } | ||
| 28711 | |||
| 28712 | if (defined $failedExit && $exit eq $failedExit) { | ||
| 28713 | |||
| 28714 | # This is probably the direction that caused a failed exit string to appear. | ||
| 28715 | # Mark it. | ||
| 28716 | $modExit = '*' . $modExit; | ||
| 28717 | } | ||
| 28718 | |||
| 28719 | # Find the corresponding exit model object | ||
| 28720 | if ($self->roomObj) { | ||
| 28721 | |||
| 28722 | if ($self->roomObj->modelFlag) { | ||
| 28723 | |||
| 28724 | $exitNum = $exitNumHash{$exit}; | ||
| 28725 | $exitObj = $self->session->worldModelObj->ivShow('modelHash', $exitNum); | ||
| 28726 | |||
| 28727 | } else { | ||
| 28728 | |||
| 28729 | $exitObj = $exitNumHash{$exit}; | ||
| 28730 | } | ||
| 28731 | } | ||
| 28732 | |||
| 28733 | if ($exitObj && $exitObj->exitState) { | ||
| 28734 | |||
| 28735 | if ($exitObj->exitState eq 'open') { | ||
| 28736 | $modExit .= '[O]'; # Open | ||
| 28737 | } elsif ($exitObj->exitState eq 'closed') { | ||
| 28738 | $modExit .= '[C]'; # Closed | ||
| 28739 | } elsif ($exitObj->exitState eq 'locked') { | ||
| 28740 | $modExit .= '[L]'; # Locked | ||
| 28741 | } elsif ($exitObj->exitState eq 'secret') { | ||
| 28742 | $modExit .= '[S]'; # Secret | ||
| 28743 | } elsif ($exitObj->exitState eq 'secret_open') { | ||
| 28744 | $modExit .= '[SO]'; # Secret and open | ||
| 28745 | } elsif ($exitObj->exitState eq 'secret_closed') { | ||
| 28746 | $modExit .= '[SC]'; # Secret and closed | ||
| 28747 | } elsif ($exitObj->exitState eq 'secret_locked') { | ||
| 28748 | $modExit .= '[SL]'; # Secret and locked | ||
| 28749 | } elsif ($exitObj->exitState eq 'impass') { | ||
| 28750 | $modExit .= '[I]'; # Impassable | ||
| 28751 | } elsif ($exitObj->exitState eq 'dark') { | ||
| 28752 | $modExit .= '[D]'; # Dest room is dark | ||
| 28753 | } elsif ($exitObj->exitState eq 'danger') { | ||
| 28754 | $modExit .= '[!]'; # Dest room is dangerous | ||
| 28755 | } elsif ($exitObj->exitState eq 'emphasis') { | ||
| 28756 | $modExit .= '+'; # Dest room is emphasised | ||
| 28757 | } elsif ($exitObj->exitState eq 'other') { | ||
| 28758 | $modExit .= '[-]'; # Other | ||
| 28759 | } | ||
| 28760 | } | ||
| 28761 | |||
| 28762 | if ($exitObj && $exitObj->assistedHash) { | ||
| 28763 | |||
| 28764 | $modExit .= '@'; | ||
| 28765 | } | ||
| 28766 | |||
| 28767 | if (! $exitString) { | ||
| 28768 | $exitString = $modExit; | ||
| 28769 | } else { | ||
| 28770 | $exitString .= ', '.$modExit; | ||
| 28771 | } | ||
| 28772 | } | ||
| 28773 | |||
| 28774 | $self->insertText($exitString, 'cyan'); | ||
| 28775 | |||
| 28776 | } else { | ||
| 28777 | |||
| 28778 | $self->insertText('<unknown exits>', 'cyan'); | ||
| 28779 | } | ||
| 28780 | |||
| 28781 | # If the debug flag is set, display everything on the move list, just underneath the exit | ||
| 28782 | # list | ||
| 28783 | if ($axmud::CLIENT->debugMoveListFlag) { | ||
| 28784 | |||
| 28785 | if ($self->moveList) { | ||
| 28786 | |||
| 28787 | # ->moveList contains a list of GA::Buffer::Cmd objects. Compile a list of the | ||
| 28788 | # commands they represent | ||
| 28789 | foreach my $obj ($self->moveList) { | ||
| 28790 | |||
| 28791 | push (@moveList, $obj->cmd); | ||
| 28792 | } | ||
| 28793 | |||
| 28794 | $self->insertText('[ML: ' . join(' ', @moveList) . ']', 'RED'); | ||
| 28795 | |||
| 28796 | } else { | ||
| 28797 | |||
| 28798 | $self->insertText('[ML: empty]', 'RED'); | ||
| 28799 | } | ||
| 28800 | } | ||
| 28801 | |||
| 28802 | # Display list of room commands, if set | ||
| 28803 | if ($self->roomObj->roomCmdList) { | ||
| 28804 | |||
| 28805 | foreach my $roomCmd ($self->roomObj->roomCmdList) { | ||
| 28806 | |||
| 28807 | if (! $roomCmdString) { | ||
| 28808 | |||
| 28809 | $roomCmdString = $roomCmd; | ||
| 28810 | |||
| 28811 | } else { | ||
| 28812 | |||
| 28813 | $roomCmdString .= ', ' . $roomCmd; | ||
| 28814 | } | ||
| 28815 | } | ||
| 28816 | |||
| 28817 | $self->insertText($roomCmdString, 'green'); | ||
| 28818 | } | ||
| 28819 | |||
| 28820 | # Display weather (etc) information, if set | ||
| 28821 | if ($self->weatherHash) { | ||
| 28822 | |||
| 28823 | foreach my $key (sort {lc($a) cmp lc($b)} ($self->ivKeys('weatherHash'))) { | ||
| 28824 | |||
| 28825 | $self->insertText( | ||
| 28826 | ucfirst($key) . ': ' . $self->ivShow('weatherHash', $key), | ||
| 28827 | 'yellow', | ||
| 28828 | ); | ||
| 28829 | } | ||
| 28830 | } | ||
| 28831 | |||
| 28832 | # If the flags are set, we need to remove all the corpses/body parts from @objList, so they | ||
| 28833 | # can be displayed on a single line | ||
| 28834 | if ($self->combineCorpseFlag || $self->combineBodyPartFlag) { | ||
| 28835 | |||
| 28836 | foreach my $obj (@objList) { | ||
| 28837 | |||
| 28838 | if ( | ||
| 28839 | $self->combineCorpseFlag | ||
| 28840 | && $obj->category eq 'portable' | ||
| 28841 | && $obj->type eq 'corpse' | ||
| 28842 | ) { | ||
| 28843 | $corpseCount++; | ||
| 28844 | |||
| 28845 | } elsif ( | ||
| 28846 | $self->combineBodyPartFlag | ||
| 28847 | && $obj->category eq 'portable' | ||
| 28848 | && $obj->type eq 'bodypart' | ||
| 28849 | ) { | ||
| 28850 | $bodyPartCount++; | ||
| 28851 | |||
| 28852 | } else { | ||
| 28853 | |||
| 28854 | # Not a corpse or body part, so display on its own line | ||
| 28855 | push (@modObjList, $obj); | ||
| 28856 | } | ||
| 28857 | } | ||
| 28858 | } | ||
| 28859 | # @objList should contain only those things displayed on their own line | ||
| 28860 | @objList = @modObjList; | ||
| 28861 | |||
| 28862 | # Now, sort @objList by category - in the order characters, minions, sentients, creatures, | ||
| 28863 | # everything else, finally corpses | ||
| 28864 | foreach my $obj (@objList) { | ||
| 28865 | |||
| 28866 | if ($obj->category eq 'char') { | ||
| 28867 | |||
| 28868 | push (@charList, $obj); | ||
| 28869 | |||
| 28870 | } elsif ($obj->category eq 'minion') { | ||
| 28871 | |||
| 28872 | push (@minionList, $obj); | ||
| 28873 | |||
| 28874 | } elsif ($obj->category eq 'sentient') { | ||
| 28875 | |||
| 28876 | push (@sentientList, $obj); | ||
| 28877 | |||
| 28878 | } elsif ($obj->category eq 'creature') { | ||
| 28879 | |||
| 28880 | push (@creatureList, $obj); | ||
| 28881 | |||
| 28882 | } elsif ( | ||
| 28883 | $obj->category eq 'portable' | ||
| 28884 | && ($obj->type eq 'corpse' || $obj->type eq 'bodypart') | ||
| 28885 | ) { | ||
| 28886 | push (@corpseList, $obj); | ||
| 28887 | |||
| 28888 | } else { | ||
| 28889 | |||
| 28890 | push (@otherList, $obj); | ||
| 28891 | } | ||
| 28892 | } | ||
| 28893 | |||
| 28894 | # If there are five torches in @otherList, we'd prefer to display them on a single line, | ||
| 28895 | # like we do with corpses. (We don't display multiple orcs, for example, on a single line | ||
| 28896 | # because the task marks which ones are alive, and which are dead) | ||
| 28897 | # ->combineDuplicates compiles a hash in the form | ||
| 28898 | # $otherHash{blessed_reference_to_non_model_object} = multiple | ||
| 28899 | # In this example, it will return a hash containing one key-value pair. The key will be the | ||
| 28900 | # first object in @otherList, the corresponding value will be 5 | ||
| 28901 | %otherHash = $self->combineDuplicates(@otherList); | ||
| 28902 | # The keys of %otherHash are stringified blessed references, so we need to modify @otherList | ||
| 28903 | # to eliminate the duplicates that don't appear in %otherHash | ||
| 28904 | foreach my $obj (@otherList) { | ||
| 28905 | |||
| 28906 | if (exists $otherHash{$obj}) { | ||
| 28907 | |||
| 28908 | push (@newOtherList, $obj); | ||
| 28909 | } | ||
| 28910 | } | ||
| 28911 | |||
| 28912 | # Sort alphabetically the sub-lists | ||
| 28913 | @charList = sort {lc($a->noun) cmp lc($b->noun)} (@charList); | ||
| 28914 | @minionList = sort {lc($a->noun) cmp lc($b->noun)} (@minionList); | ||
| 28915 | @sentientList = sort {lc($a->noun) cmp lc($b->noun)} (@sentientList); | ||
| 28916 | @creatureList = sort {lc($a->noun) cmp lc($b->noun)} (@creatureList); | ||
| 28917 | @otherList = sort {lc($a->noun) cmp lc($b->noun)} (@otherList); | ||
| 28918 | @corpseList = sort {lc($a->noun) cmp lc($b->noun)} (@corpseList); | ||
| 28919 | # Re-combine into a single list, in order | ||
| 28920 | @objList = ( | ||
| 28921 | @charList, | ||
| 28922 | @minionList, | ||
| 28923 | @sentientList, | ||
| 28924 | @creatureList, | ||
| 28925 | @newOtherList, | ||
| 28926 | @corpseList, | ||
| 28927 | ); | ||
| 28928 | |||
| 28929 | # Display the room contents, if known | ||
| 28930 | foreach my $obj (@objList) { | ||
| 28931 | |||
| 28932 | my ( | ||
| 28933 | $nounString, $otherNounString, $adjString, $unknownWordString, $multiple, $column, | ||
| 28934 | @wordList, @newWordList, | ||
| 28935 | ); | ||
| 28936 | |||
| 28937 | # Convert lists into strings, with each word separated by a space | ||
| 28938 | $nounString = $obj->noun; | ||
| 28939 | |||
| 28940 | if (exists $otherHash{$obj}) { | ||
| 28941 | |||
| 28942 | # Use the multiple supplied in the call to ->combineDuplicates | ||
| 28943 | $multiple = $otherHash{$obj}; | ||
| 28944 | |||
| 28945 | } else { | ||
| 28946 | |||
| 28947 | # Use the object's actual multiple | ||
| 28948 | $multiple = $obj->multiple; | ||
| 28949 | } | ||
| 28950 | |||
| 28951 | # The world model's ->parseObj can take a copy of an 'unknown' word (not a recognised | ||
| 28952 | # noun or adjective) and make it the noun, such that the same word appears as both the | ||
| 28953 | # main noun, and in the unknown word list | ||
| 28954 | # As a result, we only want to show the noun word once, whatever it is | ||
| 28955 | @wordList = $obj->otherNounList; | ||
| 28956 | @newWordList = (); | ||
| 28957 | |||
| 28958 | foreach my $word (@wordList) { | ||
| 28959 | |||
| 28960 | if ($word ne $nounString) { | ||
| 28961 | |||
| 28962 | push (@newWordList, $word); | ||
| 28963 | } | ||
| 28964 | } | ||
| 28965 | $otherNounString = join(' ', @newWordList); | ||
| 28966 | |||
| 28967 | @wordList = ($obj->adjList, $obj->pseudoAdjList); | ||
| 28968 | @newWordList = (); | ||
| 28969 | foreach my $word (@wordList) { | ||
| 28970 | |||
| 28971 | if ($word ne $nounString) { | ||
| 28972 | |||
| 28973 | push (@newWordList, $word); | ||
| 28974 | } | ||
| 28975 | } | ||
| 28976 | $adjString = join(' ', @newWordList); | ||
| 28977 | |||
| 28978 | @wordList = $obj->unknownWordList; | ||
| 28979 | @newWordList = (); | ||
| 28980 | foreach my $word (@wordList) { | ||
| 28981 | |||
| 28982 | if ($word ne $nounString) { | ||
| 28983 | |||
| 28984 | push (@newWordList, $word); | ||
| 28985 | } | ||
| 28986 | } | ||
| 28987 | $unknownWordString = join(' ', @newWordList); | ||
| 28988 | |||
| 28989 | # Display the information, in a single line, in different colours | ||
| 28990 | # (Some strings surrounded by square brackets, empty strings aren't displayed at all) | ||
| 28991 | # (* means a being that's still alive, - a being that's been killed) | ||
| 28992 | if ( | ||
| 28993 | $obj->category eq 'char' | ||
| 28994 | || $obj->category eq 'minion' | ||
| 28995 | || $obj->category eq 'sentient' | ||
| 28996 | || $obj->category eq 'creature' | ||
| 28997 | ) { | ||
| 28998 | if ($obj->aliveFlag) { | ||
| 28999 | $column = '*'; | ||
| 29000 | } else { | ||
| 29001 | $column = '-'; | ||
| 29002 | } | ||
| 29003 | |||
| 29004 | } else { | ||
| 29005 | |||
| 29006 | $column = ' '; | ||
| 29007 | } | ||
| 29008 | |||
| 29009 | # Highlight player characters and minions | ||
| 29010 | if ($obj->category eq 'char') { | ||
| 29011 | |||
| 29012 | $colour = 'RED'; | ||
| 29013 | |||
| 29014 | } elsif ($obj->category eq 'minion') { | ||
| 29015 | |||
| 29016 | if ($obj->ownMinionFlag) { | ||
| 29017 | $colour = 'CYAN'; | ||
| 29018 | } else { | ||
| 29019 | $colour = 'GREN'; | ||
| 29020 | } | ||
| 29021 | |||
| 29022 | } else { | ||
| 29023 | |||
| 29024 | $colour = 'white'; | ||
| 29025 | } | ||
| 29026 | |||
| 29027 | if (! $self->showParsedFlag) { | ||
| 29028 | |||
| 29029 | # Show the object before it was parsed, highlighing the noun in yellow | ||
| 29030 | $posn = index($obj->baseString, $obj->noun); | ||
| 29031 | |||
| 29032 | if ($posn == -1 || $colour ne 'white' || $obj->noun eq '') { | ||
| 29033 | |||
| 29034 | # The actual noun seems to be missing, for some reason | ||
| 29035 | # Also, don't highlight the noun if it's a player character or minion | ||
| 29036 | $self->insertText($column . $obj->baseString, $colour); | ||
| 29037 | |||
| 29038 | } else { | ||
| 29039 | |||
| 29040 | $before = substr($obj->baseString, 0, $posn); | ||
| 29041 | if ($before ne '') { | ||
| 29042 | |||
| 29043 | $self->insertText($column . $before, 'white'); | ||
| 29044 | |||
| 29045 | $self->insertText( | ||
| 29046 | substr($obj->baseString, $posn, length($obj->noun)), | ||
| 29047 | 'echo', | ||
| 29048 | 'yellow', | ||
| 29049 | ); | ||
| 29050 | |||
| 29051 | } else { | ||
| 29052 | |||
| 29053 | $self->insertText( | ||
| 29054 | $column . substr($obj->baseString, $posn, length($obj->noun)), | ||
| 29055 | 'yellow', | ||
| 29056 | ); | ||
| 29057 | } | ||
| 29058 | |||
| 29059 | $after = substr($obj->baseString, ($posn + length($obj->noun))); | ||
| 29060 | if ($after ne '') { | ||
| 29061 | |||
| 29062 | $self->insertText($after, 'echo', 'white'); | ||
| 29063 | } | ||
| 29064 | } | ||
| 29065 | |||
| 29066 | } else { | ||
| 29067 | |||
| 29068 | # Show information about the object after it was parsed | ||
| 29069 | $self->insertText($column . $nounString, $colour); | ||
| 29070 | |||
| 29071 | if ($otherNounString) { | ||
| 29072 | |||
| 29073 | $self->insertText(' ' . $otherNounString, 'echo', 'yellow'); | ||
| 29074 | } | ||
| 29075 | |||
| 29076 | if ($adjString) { | ||
| 29077 | |||
| 29078 | $self->insertText(' ' . $adjString, 'echo', 'green'); | ||
| 29079 | } | ||
| 29080 | |||
| 29081 | if ($unknownWordString) { | ||
| 29082 | |||
| 29083 | $self->insertText(' ' . $unknownWordString, 'echo', 'magenta'); | ||
| 29084 | } | ||
| 29085 | } | ||
| 29086 | |||
| 29087 | if ($multiple != 1 && $multiple > 0) { # So, can include 0.333, 0.5, etc | ||
| 29088 | |||
| 29089 | $self->insertText(' [' . $multiple . ']', 'echo', 'white'); | ||
| 29090 | |||
| 29091 | } elsif ($multiple == -1) { | ||
| 29092 | |||
| 29093 | $self->insertText(' [m]', 'echo', 'white'); | ||
| 29094 | } | ||
| 29095 | } | ||
| 29096 | |||
| 29097 | # Display the number of corpses/body parts, if they were removed from @objList | ||
| 29098 | if ($corpseCount) { | ||
| 29099 | |||
| 29100 | $self->insertText('-corpse', 'red'); | ||
| 29101 | if ($corpseCount > 1 || $bodyPartCount) { | ||
| 29102 | |||
| 29103 | $self->insertText(' [' . $corpseCount . ']', 'echo', 'red'); | ||
| 29104 | } | ||
| 29105 | } | ||
| 29106 | |||
| 29107 | if ($bodyPartCount) { | ||
| 29108 | |||
| 29109 | if ($corpseCount) { | ||
| 29110 | $self->insertText(' body part', 'echo', 'red'); | ||
| 29111 | } else { | ||
| 29112 | $self->insertText(' body part', 'red'); | ||
| 29113 | } | ||
| 29114 | |||
| 29115 | if ($bodyPartCount > 1 || $corpseCount) { | ||
| 29116 | |||
| 29117 | $self->insertText(' [' . $bodyPartCount . ']', 'echo', 'red'); | ||
| 29118 | } | ||
| 29119 | } | ||
| 29120 | |||
| 29121 | return 1; | ||
| 29122 | } | ||
| 29123 | |||
| 29124 | sub prepareTitleBar { | ||
| 29125 | |||
| 29126 | # Called by various functions, including $self->refreshWin | ||
| 29127 | # Prepares text to display in the task window's title bar (if open), and then displays it | ||
| 29128 | # | ||
| 29129 | # Expected arguments | ||
| 29130 | # (none besides $self) | ||
| 29131 | # | ||
| 29132 | # Return values | ||
| 29133 | # 'undef' on improper arguments | ||
| 29134 | # 1 otherwise | ||
| 29135 | |||
| 29136 | my ($self, $check) = @_; | ||
| 29137 | |||
| 29138 | # Check for improper arguments | ||
| 29139 | if (defined $check) { | ||
| 29140 | |||
| 29141 | return $axmud::CLIENT->writeImproper($self->_objClass . '->prepareTitleBar', @_); | ||
| 29142 | } | ||
| 29143 | |||
| 29144 | # v1.1.093 The number of expected room statements is no longer displayed in the automapper | ||
| 29145 | # window | ||
| 29146 | if (! $self->moveList) { | ||
| 29147 | |||
| 29148 | # No more moves expected. To make the title bar more pleasant to look out, display a | ||
| 29149 | # hyphen rather than nothing | ||
| 29150 | $self->setTaskWinTitle(' - ', TRUE); | ||
| 29151 | # # Also update the Automapper window's title bar, if it's open | ||
| 29152 | # if ($self->session->mapWin) { | ||
| 29153 | # | ||
| 29154 | # $self->session->mapWin->setWinTitle(); | ||
| 29155 | # } | ||
| 29156 | |||
| 29157 | } else { | ||
| 29158 | |||
| 29159 | $self->setTaskWinTitle(' ' . scalar $self->moveList . ' ', TRUE); | ||
| 29160 | # # Also update the Automapper window's title bar, if it's open (and not in 'wait' mode) | ||
| 29161 | # if ($self->session->mapWin && $self->session->mapWin->mode ne 'wait') { | ||
| 29162 | # | ||
| 29163 | # $self->session->mapWin->setWinTitle(' (' . scalar $self->moveList . ')'); | ||
| 29164 | # } | ||
| 29165 | } | ||
| 29166 | |||
| 29167 | return 1; | ||
| 29168 | } | ||
| 29169 | |||
| 29170 | sub combineDuplicates { | ||
| 29171 | |||
| 29172 | # Called by $self->refreshWin | ||
| 29173 | # If there are five torches in the room, we want to display them on a single line, but if | ||
| 29174 | # there are five orcs in the room, we want to display them on separate lines so the user | ||
| 29175 | # can see which are alive and which are dead | ||
| 29176 | # This function is called with a list of all the objects in the current room's | ||
| 29177 | # ->tempObjList which aren't alive and aren't corpses or body parts | ||
| 29178 | # It compares the objects in the list against each other, trying to eliminate duplicates. | ||
| 29179 | # However, we can't set an object's ->multiple, because ->refreshWin (and therefore this | ||
| 29180 | # function) might be called more than once; instead, we return a hash in the form | ||
| 29181 | # $hash{blessed_reference_to_non_model_object} = multiple | ||
| 29182 | # When an object is processed, its blessed reference is added to the hash, with the | ||
| 29183 | # corresponding multiple set to 1 | ||
| 29184 | # When an object is processed that matches one already in the hash, the object is eliminated | ||
| 29185 | # and the hash object's multiple is increased | ||
| 29186 | # | ||
| 29187 | # Expected arguments | ||
| 29188 | # (none besides $self) | ||
| 29189 | # | ||
| 29190 | # Optional arguments | ||
| 29191 | # @objList - A list of objects from the current room's ->tempObjList (which may be | ||
| 29192 | # empty) | ||
| 29193 | # | ||
| 29194 | # Return values | ||
| 29195 | # The hash of objects described above (in which duplicates have been removed) | ||
| 29196 | |||
| 29197 | my ($self, @objList) = @_; | ||
| 29198 | |||
| 29199 | # Local variables | ||
| 29200 | my (%emptyHash, %newHash, %unStringHash); | ||
| 29201 | |||
| 29202 | # (No check for improper arguments) | ||
| 29203 | |||
| 29204 | # The list of objects can be empty | ||
| 29205 | if (! @objList) { | ||
| 29206 | |||
| 29207 | return %emptyHash; | ||
| 29208 | } | ||
| 29209 | |||
| 29210 | # Otherwise, process each item in @objList in turn | ||
| 29211 | # The first item is added to %newHash | ||
| 29212 | # Subsequent items are compared against the items in %newHash. If the subsequent item is a | ||
| 29213 | # duplicate of anything already in %newHash, it is eliminated. Otherwise, it is added to | ||
| 29214 | # %newHash | ||
| 29215 | # (Actually, we use a second hash so that we can translate the stringified blessed | ||
| 29216 | # references stored as keys in %newHash into the actual blessed references) | ||
| 29217 | do { | ||
| 29218 | |||
| 29219 | my ($obj, $flag); | ||
| 29220 | |||
| 29221 | $obj = shift @objList; | ||
| 29222 | |||
| 29223 | # Don't try to combine duplicates of objects whose ->multiple is already not 1 | ||
| 29224 | if ($obj->multiple == 1) { | ||
| 29225 | |||
| 29226 | # Compare this item against every object in @newList | ||
| 29227 | OUTER: foreach my $newObj (values %unStringHash) { | ||
| 29228 | |||
| 29229 | # Are the two objects exactly the same? | ||
| 29230 | if ($self->session->worldModelObj->objCompare(100, $obj, $newObj)) { | ||
| 29231 | |||
| 29232 | # We have a match. The keys in %newHash are non-model objects; the | ||
| 29233 | # corresponding values are the number of things this object represents | ||
| 29234 | $newHash{$newObj} = $newHash{$newObj} + 1; | ||
| 29235 | $flag = TRUE; | ||
| 29236 | |||
| 29237 | last OUTER; | ||
| 29238 | } | ||
| 29239 | } | ||
| 29240 | } | ||
| 29241 | |||
| 29242 | if (! $flag) { | ||
| 29243 | |||
| 29244 | # $obj isn't a duplicate of anything already in %newHash, so add it to the hash | ||
| 29245 | $newHash{$obj} = 1; | ||
| 29246 | # (Need an un-stringified version of the object, too) | ||
| 29247 | $unStringHash{$obj} = $obj; | ||
| 29248 | } | ||
| 29249 | |||
| 29250 | } until (! @objList); | ||
| 29251 | |||
| 29252 | return %newHash; | ||
| 29253 | } | ||
| 29254 | |||
| 29255 | sub countLivingObjects { | ||
| 29256 | |||
| 29257 | # Can be called by anything | ||
| 29258 | # Counts the number of (known) living objects in the current room | ||
| 29259 | # | ||
| 29260 | # Expected arguments | ||
| 29261 | # (none besides $self) | ||
| 29262 | # | ||
| 29263 | # Optional arguments | ||
| 29264 | # $minionFlag - If set to TRUE, minions are ignored. If set to FALSE (or 'undef'), | ||
| 29265 | # minions are included | ||
| 29266 | # | ||
| 29267 | # Return values | ||
| 29268 | # 'undef' on improper arguments or if the current room isn't known | ||
| 29269 | # Otherwise returns the number of objects whose ->aliveFlag is TRUE (includes 'character', | ||
| 29270 | # 'minion', 'sentient', 'creature' objects and perhaps also some 'custom' objects). | ||
| 29271 | # The number returned may be 0 | ||
| 29272 | |||
| 29273 | my ($self, $minionFlag, $check) = @_; | ||
| 29274 | |||
| 29275 | # Local variables | ||
| 29276 | my $count; | ||
| 29277 | |||
| 29278 | # Check for improper arguments | ||
| 29279 | if (defined $check) { | ||
| 29280 | |||
| 29281 | return $axmud::CLIENT->writeImproper($self->_objClass . '->countLivingObjects', @_); | ||
| 29282 | } | ||
| 29283 | |||
| 29284 | if (! $self->roomObj || ! $self->roomObj->tempObjList) { | ||
| 29285 | |||
| 29286 | # No objects to count | ||
| 29287 | return 0; | ||
| 29288 | } | ||
| 29289 | |||
| 29290 | # Count the living objects | ||
| 29291 | $count = 0; | ||
| 29292 | foreach my $obj ($self->roomObj->tempObjList) { | ||
| 29293 | |||
| 29294 | if ( | ||
| 29295 | $obj->aliveFlag | ||
| 29296 | && (! $minionFlag || $obj->category ne 'minion') | ||
| 29297 | ) { | ||
| 29298 | $count++; | ||
| 29299 | } | ||
| 29300 | } | ||
| 29301 | |||
| 29302 | return $count; | ||
| 29303 | } | ||
| 29304 | |||
| 29305 | sub resetModelRoom { | ||
| 29306 | |||
| 29307 | # Called by GA::Obj::WorldModel->deleteRooms and GA::Obj::Map->openWin | ||
| 29308 | # Resets the room model object number stored by the task, when it is known (so that the task | ||
| 29309 | # no longer knows the automapper's current room) | ||
| 29310 | # | ||
| 29311 | # Expected arguments | ||
| 29312 | # (none besides $self) | ||
| 29313 | # | ||
| 29314 | # Return values | ||
| 29315 | # 'undef' on improper arguments | ||
| 29316 | # 1 otherwise | ||
| 29317 | |||
| 29318 | my ($self, $check) = @_; | ||
| 29319 | |||
| 29320 | # Check for improper arguments | ||
| 29321 | if (defined $check) { | ||
| 29322 | |||
| 29323 | return $axmud::CLIENT->writeImproper($self->_objClass . '->resetModelRoom', @_); | ||
| 29324 | } | ||
| 29325 | |||
| 29326 | # Update IVs | ||
| 29327 | $self->ivUndef('modelNumber'); | ||
| 29328 | if ($self->roomObj && $self->roomObj->roomTag) { | ||
| 29329 | |||
| 29330 | $self->roomObj->ivUndef('roomTag'); | ||
| 29331 | } | ||
| 29332 | |||
| 29333 | # Update the task window | ||
| 29334 | $self->refreshWin(); | ||
| 29335 | |||
| 29336 | return 1; | ||
| 29337 | } | ||
| 29338 | |||
| 29339 | sub resetMoveList { | ||
| 29340 | |||
| 29341 | # Called by GA::Win::Map->addFailedExitCallback or by any other function | ||
| 29342 | # Resets the two IVs which tell the task how many room statements to expect, and then | ||
| 29343 | # updates the task window | ||
| 29344 | # | ||
| 29345 | # Expected arguments | ||
| 29346 | # (none besides $self) | ||
| 29347 | # | ||
| 29348 | # Return values | ||
| 29349 | # 'undef' on improper arguments | ||
| 29350 | # 1 otherwise | ||
| 29351 | |||
| 29352 | my ($self, $check) = @_; | ||
| 29353 | |||
| 29354 | # Check for improper arguments | ||
| 29355 | if (defined $check) { | ||
| 29356 | |||
| 29357 | return $axmud::CLIENT->writeImproper($self->_objClass . '->resetModelRoom', @_); | ||
| 29358 | } | ||
| 29359 | |||
| 29360 | # Update IVs | ||
| 29361 | $self->ivEmpty('cmdObjList'); | ||
| 29362 | $self->ivEmpty('moveList'); | ||
| 29363 | $self->ivUndef('prevCmdBufferNum'); | ||
| 29364 | # Update the task window | ||
| 29365 | $self->refreshWin(); | ||
| 29366 | |||
| 29367 | return 1; | ||
| 29368 | } | ||
| 29369 | |||
| 29370 | sub usePseudoStatement { | ||
| 29371 | |||
| 29372 | # Called by GA::Obj::Map->setCurrentRoom and ->pseudoWorldCmd when the current session's | ||
| 29373 | # status is 'offline' | ||
| 29374 | # The calling function has constructed a pseudo-statement - an approximation of the text | ||
| 29375 | # sent by the world, when the character visits the automapper's current room | ||
| 29376 | # Update this task's IVs, as if $self->processLine had spotted a room statement in the text | ||
| 29377 | # actually received from the world | ||
| 29378 | # | ||
| 29379 | # Expected arguments | ||
| 29380 | # $dictObj - The session's current dictionary | ||
| 29381 | # $modelRoomObj - The automapper's current room (a GA::ModelObj::Room object) | ||
| 29382 | # $anchorLine - The display buffer line which is the pseudo-statement's anchor line | ||
| 29383 | # (matches a key in GA::Session->displayBufferHash) | ||
| 29384 | # | ||
| 29385 | # Return values | ||
| 29386 | # 'undef' on improper arguments | ||
| 29387 | # 1 otherwise | ||
| 29388 | |||
| 29389 | my ($self, $dictObj, $modelRoomObj, $anchorLine, $check) = @_; | ||
| 29390 | |||
| 29391 | # Local variables | ||
| 29392 | my $tempRoomObj; | ||
| 29393 | |||
| 29394 | # Check for improper arguments | ||
| 29395 | if ( | ||
| 29396 | ! defined $dictObj || ! defined $modelRoomObj || ! defined $anchorLine | ||
| 29397 | || defined $check | ||
| 29398 | ) { | ||
| 29399 | return $axmud::CLIENT->writeImproper($self->_objClass . '->usePseudoStatement', @_); | ||
| 29400 | } | ||
| 29401 | |||
| 29402 | # $self->processLines should not look for anchor lines in any of the text 'received' from | ||
| 29403 | # the world | ||
| 29404 | $self->ivPoke('lastBufferLine', $self->session->displayBufferLast); | ||
| 29405 | $self->ivPoke('lastAnchorLine', $anchorLine); | ||
| 29406 | $self->ivPoke('lastStatementEndLine', $self->session->displayBufferLast); | ||
| 29407 | # (Use the same line as the 'start' of the room statement, while in offline mode. Luckily, | ||
| 29408 | # nothing uses ->lastStatementStartLine at the moment) | ||
| 29409 | $self->ivPoke('lastStatementStartLine', $self->session->displayBufferLast); | ||
| 29410 | |||
| 29411 | # Create a new non-model room, whose properties will be set to match $modelRoomObj | ||
| 29412 | $tempRoomObj = Games::Axmud::ModelObj::Room->new( | ||
| 29413 | $self->session, | ||
| 29414 | 'temporary', | ||
| 29415 | 'non_model', | ||
| 29416 | ); | ||
| 29417 | |||
| 29418 | # Store it as the Locator task's current room | ||
| 29419 | $self->ivPoke('roomObj', $tempRoomObj); | ||
| 29420 | $self->ivPoke('modelNumber', $modelRoomObj->number); | ||
| 29421 | |||
| 29422 | # Update its properties | ||
| 29423 | $tempRoomObj->ivPoke('titleList', $modelRoomObj->titleList); | ||
| 29424 | $tempRoomObj->ivPoke('descripHash', $modelRoomObj->descripHash); | ||
| 29425 | |||
| 29426 | # (For non-model rooms, ->sortedExitList shouldn't contain hidden exits) | ||
| 29427 | foreach my $exitName ($modelRoomObj->sortedExitList) { | ||
| 29428 | |||
| 29429 | my ($exitNum, $exitObj, $pseudoExitObj); | ||
| 29430 | |||
| 29431 | $exitNum = $modelRoomObj->ivShow('exitNumHash', $exitName); | ||
| 29432 | $exitObj = $self->session->worldModelObj->ivShow('exitModelHash', $exitNum); | ||
| 29433 | |||
| 29434 | if (! $exitObj->hiddenFlag) { | ||
| 29435 | |||
| 29436 | $tempRoomObj->ivPush('sortedExitList', $exitName); | ||
| 29437 | } | ||
| 29438 | |||
| 29439 | $pseudoExitObj = $self->clonePseudoExit($exitObj); | ||
| 29440 | if ($pseudoExitObj) { | ||
| 29441 | |||
| 29442 | $tempRoomObj->ivAdd('exitNumHash', $exitName, $pseudoExitObj); | ||
| 29443 | } | ||
| 29444 | } | ||
| 29445 | |||
| 29446 | # (Create a list of 'temporary' objects from $modelRoomObj's (permanent) child object list) | ||
| 29447 | foreach my $childNum ($modelRoomObj->ivKeys('childHash')) { | ||
| 29448 | |||
| 29449 | my ( | ||
| 29450 | $childObj, | ||
| 29451 | @thisList, | ||
| 29452 | ); | ||
| 29453 | |||
| 29454 | $childObj = $self->session->worldModelObj->ivShow('modelHash', $childNum); | ||
| 29455 | |||
| 29456 | # There is no world model object-cloning code, so we'll cheat and use each object's | ||
| 29457 | # original base string (e.g. 'big hairy orc') and process the string to create a new | ||
| 29458 | # non-model object | ||
| 29459 | @thisList = $self->session->worldModelObj->parseObj( | ||
| 29460 | $self->session, | ||
| 29461 | TRUE, # Treat '5 coins' as a single object | ||
| 29462 | $childObj->baseString, | ||
| 29463 | ); | ||
| 29464 | |||
| 29465 | if (@thisList) { | ||
| 29466 | |||
| 29467 | $tempRoomObj->ivPush('tempObjList', @thisList); | ||
| 29468 | } | ||
| 29469 | } | ||
| 29470 | |||
| 29471 | # (Code adapated from $self->processLine, parts 8-10) | ||
| 29472 | if (! $self->roomCount) { | ||
| 29473 | |||
| 29474 | # First room statement found - in future, search forwards, not backwards | ||
| 29475 | $self->ivPoke('roomCount', 1); | ||
| 29476 | |||
| 29477 | # If the room has a room tag, display it | ||
| 29478 | if ($modelRoomObj->roomTag) { | ||
| 29479 | |||
| 29480 | $self->roomObj->ivPoke('roomTag', $modelRoomObj->roomTag); | ||
| 29481 | } | ||
| 29482 | } | ||
| 29483 | |||
| 29484 | # Display information about the pseudo-room statement in the task window (if it's open and | ||
| 29485 | # enabled) | ||
| 29486 | if ($self->taskWinFlag) { | ||
| 29487 | |||
| 29488 | $self->refreshWin(); | ||
| 29489 | } | ||
| 29490 | |||
| 29491 | return 1; | ||
| 29492 | } | ||
| 29493 | |||
| 29494 | sub clonePseudoExit { | ||
| 29495 | |||
| 29496 | # Called by $self->usePseudoStatement to create a non-model exit for the non-model room | ||
| 29497 | # stored in $self->roomObj, based on the properties of a model exit | ||
| 29498 | # | ||
| 29499 | # Expected arguments | ||
| 29500 | # $modelExitObj - The exit to clone | ||
| 29501 | # | ||
| 29502 | # Return values | ||
| 29503 | # 'undef' on improper arguments | ||
| 29504 | # Otherwise, returns the blessed reference of the new non-model exit object | ||
| 29505 | |||
| 29506 | my ($self, $modelExitObj, $check) = @_; | ||
| 29507 | |||
| 29508 | # Local variables | ||
| 29509 | my $cloneExitObj; | ||
| 29510 | |||
| 29511 | # Check for improper arguments | ||
| 29512 | if (! defined $modelExitObj || defined $check) { | ||
| 29513 | |||
| 29514 | return $axmud::CLIENT->writeImproper($self->_objClass . '->clonePseudoExit', @_); | ||
| 29515 | } | ||
| 29516 | |||
| 29517 | # Create a non-model exit object | ||
| 29518 | $cloneExitObj = Games::Axmud::Obj::Exit->new( | ||
| 29519 | $self->session, | ||
| 29520 | $modelExitObj->dir, # Nominal direction | ||
| 29521 | 'non_model', # Non-exit model object | ||
| 29522 | ); | ||
| 29523 | |||
| 29524 | # Clone the model exit's properties | ||
| 29525 | $cloneExitObj->ivPoke('exitType', $modelExitObj->exitType); | ||
| 29526 | $cloneExitObj->ivPoke('hiddenFlag', $modelExitObj->hiddenFlag); | ||
| 29527 | $cloneExitObj->ivPoke('exitOrnament', $modelExitObj->exitOrnament); | ||
| 29528 | $cloneExitObj->ivPoke('exitState', $modelExitObj->exitState); | ||
| 29529 | $cloneExitObj->ivPoke('exitInfo', $modelExitObj->exitInfo); | ||
| 29530 | |||
| 29531 | return $cloneExitObj; | ||
| 29532 | } | ||
| 29533 | |||
| 29534 | sub insertLook { | ||
| 29535 | |||
| 29536 | # Called by GA::Cmd::InsertLook->do | ||
| 29537 | # Updates the task's IVs as if the user had typed 'look', so that the task is expecting an | ||
| 29538 | # extra room statement | ||
| 29539 | # Useful at worlds which send unsolicited room statements (e.g. EmpireMud, at dawn and | ||
| 29540 | # dusk). The user can set up a trigger to look out for these events. The trigger response | ||
| 29541 | # should be to use the client command ';insertlook', which calls this function | ||
| 29542 | # | ||
| 29543 | # Expected arguments | ||
| 29544 | # (none besides $self) | ||
| 29545 | # | ||
| 29546 | # Return values | ||
| 29547 | # 'undef' on improper arguments or if there's an error | ||
| 29548 | # 1 otherwise | ||
| 29549 | |||
| 29550 | my ($self, $check) = @_; | ||
| 29551 | |||
| 29552 | # Local variables | ||
| 29553 | my ($cage, $bufferObj); | ||
| 29554 | |||
| 29555 | # Check for improper arguments | ||
| 29556 | if (defined $check) { | ||
| 29557 | |||
| 29558 | return $axmud::CLIENT->writeImproper($self->_objClass . '->insertLook', @_); | ||
| 29559 | } | ||
| 29560 | |||
| 29561 | # Get the session's highest-priority command cage | ||
| 29562 | $cage = $self->session->findHighestCage('cmd'); | ||
| 29563 | |||
| 29564 | # Create a fake buffer object | ||
| 29565 | $bufferObj = Games::Axmud::Buffer::Cmd->new( | ||
| 29566 | $self->session, | ||
| 29567 | 'session', | ||
| 29568 | # Not a real world command | ||
| 29569 | -1, | ||
| 29570 | $self->session->findCmd('look'), | ||
| 29571 | $self->session->sessionTime, | ||
| 29572 | ); | ||
| 29573 | |||
| 29574 | if (! $bufferObj) { | ||
| 29575 | |||
| 29576 | return undef; | ||
| 29577 | |||
| 29578 | } else { | ||
| 29579 | |||
| 29580 | $bufferObj->interpretCmd($cage); | ||
| 29581 | $self->add_cmdObj($bufferObj); | ||
| 29582 | |||
| 29583 | return 1; | ||
| 29584 | } | ||
| 29585 | } | ||
| 29586 | |||
| 29587 | sub insertFailedExit { | ||
| 29588 | |||
| 29589 | # Called by GA::Cmd::InsertFailedExit->do, when there is exactly one item in $self->moveList | ||
| 29590 | # (meaning that the task is expecting a single room statement after a movement or look/ | ||
| 29591 | # glance command) | ||
| 29592 | # Looks at the first line of text received from the world after the movement/look/glance | ||
| 29593 | # command was sent, and assumes it's a failed message, updating the task's own IVs | ||
| 29594 | # accordingly (so it's no longer expecting a room statement) | ||
| 29595 | # Optionally adds that message to the list in the current world or current room | ||
| 29596 | # | ||
| 29597 | # Expected arguments | ||
| 29598 | # $mode - 'room' to update the current room's list of failed exit messages, 'world' | ||
| 29599 | # to update the current world profile's list, or 'update' to update neither | ||
| 29600 | # list | ||
| 29601 | # | ||
| 29602 | # Return values | ||
| 29603 | # 'undef' on improper arguments or if there's an error | ||
| 29604 | # 1 otherwise | ||
| 29605 | |||
| 29606 | my ($self, $mode, $check) = @_; | ||
| 29607 | |||
| 29608 | # Local variables | ||
| 29609 | my ($bufferObj, $text, $regex); | ||
| 29610 | |||
| 29611 | # Check for improper arguments | ||
| 29612 | if ( | ||
| 29613 | ! defined $mode | ||
| 29614 | || ($mode ne 'room' && $mode ne 'world' && $mode ne 'update') | ||
| 29615 | || defined $check | ||
| 29616 | ) { | ||
| 29617 | return $axmud::CLIENT->writeImproper($self->_objClass . '->insertFailedExit', @_); | ||
| 29618 | } | ||
| 29619 | |||
| 29620 | # Check we're expecting a single room statement from a single move/look/glance command | ||
| 29621 | if ((scalar $self->moveList) != 1 && defined $self->prevCmdBufferNum) { | ||
| 29622 | |||
| 29623 | return undef; | ||
| 29624 | |||
| 29625 | # $self->prevCmdBufferNum specifies the buffer number of the first line of text received | ||
| 29626 | # from the world after that command was processed. Check it's actually been received | ||
| 29627 | } elsif (! $self->session->ivExists('displayBufferHash', $self->prevCmdBufferNum)) { | ||
| 29628 | |||
| 29629 | return undef; | ||
| 29630 | } | ||
| 29631 | |||
| 29632 | # Retrieve the line of text, shorten it to a reasonable size (currently 40 characters) and | ||
| 29633 | # convert it to a regex | ||
| 29634 | $bufferObj = $self->session->ivShow('displayBufferHash', $self->prevCmdBufferNum); | ||
| 29635 | $text = substr($bufferObj->stripLine, 0, 40); | ||
| 29636 | if ($text eq '') { | ||
| 29637 | |||
| 29638 | return undef; | ||
| 29639 | } | ||
| 29640 | |||
| 29641 | $regex = '^' . quotemeta($text); | ||
| 29642 | |||
| 29643 | # Update failed exit lists, if required too | ||
| 29644 | if ($mode eq 'room' && $self->session->mapObj->currentRoom) { | ||
| 29645 | $self->session->mapObj->currentRoom->ivPush('failExitPatternList', $regex); | ||
| 29646 | } elsif ($mode eq 'world') { | ||
| 29647 | $self->session->currentWorld->ivPush('failExitPatternList', $regex); | ||
| 29648 | } | ||
| 29649 | |||
| 29650 | # The task is no longer expecting any room statements | ||
| 29651 | $self->resetMoveList(); | ||
| 29652 | |||
| 29653 | return 1; | ||
| 29654 | } | ||
| 29655 | |||
| 29656 | sub useRoomCmd { | ||
| 29657 | |||
| 29658 | # Called by GA::Cmd::RoomCommand->do | ||
| 29659 | # Removes the first room command from the current room's list, executes it as a world | ||
| 29660 | # command, then moves it to the end of the list (so room commands can be executed in a | ||
| 29661 | # continuous cycle) | ||
| 29662 | # | ||
| 29663 | # Expected arguments | ||
| 29664 | # (none besides $self) | ||
| 29665 | # | ||
| 29666 | # Return values | ||
| 29667 | # 'undef' on improper arguments, if there is no current room or if the current room has | ||
| 29668 | # no room commands | ||
| 29669 | # Otherwise returns the room command executed | ||
| 29670 | |||
| 29671 | my ($self, $check) = @_; | ||
| 29672 | |||
| 29673 | # Local variables | ||
| 29674 | my $cmd; | ||
| 29675 | |||
| 29676 | # Check for improper arguments | ||
| 29677 | if (defined $check) { | ||
| 29678 | |||
| 29679 | return $axmud::CLIENT->writeImproper($self->_objClass . '->useRoomCmd', @_); | ||
| 29680 | } | ||
| 29681 | |||
| 29682 | if (! $self->roomObj || ! $self->roomObj->tempRoomCmdList) { | ||
| 29683 | |||
| 29684 | return undef; | ||
| 29685 | } | ||
| 29686 | |||
| 29687 | $cmd = $self->roomObj->ivShift('tempRoomCmdList'); | ||
| 29688 | $self->session->worldCmd($cmd); | ||
| 29689 | $self->roomObj->ivPush('tempRoomCmdList', $cmd); | ||
| 29690 | |||
| 29691 | return $cmd; | ||
| 29692 | } | ||
| 29693 | |||
| 29694 | ################## | ||
| 29695 | # Response methods | ||
| 29696 | |||
| 29697 | ################## | ||
| 29698 | # Accessors - set | ||
| 29699 | |||
| 29700 | sub set_arrivalTag { | ||
| 29701 | |||
| 29702 | my ($self, $tag, $check) = @_; | ||
| 29703 | |||
| 29704 | # Check for improper arguments | ||
| 29705 | if (defined $check) { # ($arrivalTag can be 'undef') | ||
| 29706 | |||
| 29707 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_arrivalTag', @_); | ||
| 29708 | } | ||
| 29709 | |||
| 29710 | $self->ivPoke('arrivalTag', $tag); | ||
| 29711 | |||
| 29712 | return 1; | ||
| 29713 | } | ||
| 29714 | |||
| 29715 | sub add_cmdObj { | ||
| 29716 | |||
| 29717 | my ($self, $obj, $check) = @_; | ||
| 29718 | |||
| 29719 | # Check for improper arguments | ||
| 29720 | if (! defined $obj || defined $check) { | ||
| 29721 | |||
| 29722 | return $axmud::CLIENT->writeImproper($self->_objClass . '->add_cmdObj', @_); | ||
| 29723 | } | ||
| 29724 | |||
| 29725 | # If no room statements are expected, store the display buffer number of the first line of | ||
| 29726 | # text that will be received after the command is sent to the world | ||
| 29727 | if (! $self->moveList) { | ||
| 29728 | $self->ivPoke('prevCmdBufferNum', $self->session->displayBufferCount); | ||
| 29729 | } else { | ||
| 29730 | $self->ivUndef('prevCmdBufferNum'); | ||
| 29731 | } | ||
| 29732 | |||
| 29733 | $self->ivPush('cmdObjList', $obj); | ||
| 29734 | if ($obj->lookFlag || $obj->glanceFlag || $obj->moveFlag || $obj->followFlag) { | ||
| 29735 | |||
| 29736 | # It's a look, glance or movement command (including redirect mode commands and | ||
| 29737 | # assisted moves) | ||
| 29738 | $self->ivPush('moveList', $obj); | ||
| 29739 | # Update the task window's title bar (if open) | ||
| 29740 | $self->prepareTitleBar(); | ||
| 29741 | } | ||
| 29742 | |||
| 29743 | return 1; | ||
| 29744 | } | ||
| 29745 | |||
| 29746 | sub reset_failExitFlag { | ||
| 29747 | |||
| 29748 | my ($self, $check) = @_; | ||
| 29749 | |||
| 29750 | # Check for improper arguments | ||
| 29751 | if (defined $check) { | ||
| 29752 | |||
| 29753 | return $axmud::CLIENT->writeImproper($self->_objClass . '->reset_failExitFlag', @_); | ||
| 29754 | } | ||
| 29755 | |||
| 29756 | $self->ivPoke('failExitFlag', FALSE); | ||
| 29757 | |||
| 29758 | return 1; | ||
| 29759 | } | ||
| 29760 | |||
| 29761 | sub reset_involuntaryExitFlag { | ||
| 29762 | |||
| 29763 | my ($self, $check) = @_; | ||
| 29764 | |||
| 29765 | # Check for improper arguments | ||
| 29766 | if (defined $check) { | ||
| 29767 | |||
| 29768 | return $axmud::CLIENT->writeImproper( | ||
| 29769 | $self->_objClass . '->reset_involuntaryExitFlag', | ||
| 29770 | @_, | ||
| 29771 | ); | ||
| 29772 | } | ||
| 29773 | |||
| 29774 | $self->ivPoke('involuntaryExitFlag', FALSE); | ||
| 29775 | |||
| 29776 | return 1; | ||
| 29777 | } | ||
| 29778 | |||
| 29779 | sub set_lastBufferLine { | ||
| 29780 | |||
| 29781 | my ($self, $line, $check) = @_; | ||
| 29782 | |||
| 29783 | # Check for improper arguments | ||
| 29784 | if (! defined $line || defined $check) { | ||
| 29785 | |||
| 29786 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_lastBufferLine', @_); | ||
| 29787 | } | ||
| 29788 | |||
| 29789 | $self->ivPoke('lastBufferLine', $line); | ||
| 29790 | |||
| 29791 | return 1; | ||
| 29792 | } | ||
| 29793 | |||
| 29794 | sub set_manualResetFlag { | ||
| 29795 | |||
| 29796 | my ($self, $flag, $check) = @_; | ||
| 29797 | |||
| 29798 | # Check for improper arguments | ||
| 29799 | if (! defined $flag || defined $check) { | ||
| 29800 | |||
| 29801 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_manualResetFlag', @_); | ||
| 29802 | } | ||
| 29803 | |||
| 29804 | if ($flag) { | ||
| 29805 | $self->ivPoke('manualResetFlag', TRUE); | ||
| 29806 | } else { | ||
| 29807 | $self->ivPoke('manualResetFlag', FALSE); | ||
| 29808 | } | ||
| 29809 | |||
| 29810 | return 1; | ||
| 29811 | } | ||
| 29812 | |||
| 29813 | sub set_modelNumber { | ||
| 29814 | |||
| 29815 | my ($self, $number, $check) = @_; | ||
| 29816 | |||
| 29817 | # Check for improper arguments | ||
| 29818 | if (defined $check) { | ||
| 29819 | |||
| 29820 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_modelNumber', @_); | ||
| 29821 | } | ||
| 29822 | |||
| 29823 | # Update IVs | ||
| 29824 | $self->ivPoke('modelNumber', $number); # Can be 'undef' | ||
| 29825 | |||
| 29826 | return 1; | ||
| 29827 | } | ||
| 29828 | |||
| 29829 | sub set_updateFromMsdp { | ||
| 29830 | |||
| 29831 | # Called by GA::Session->processMsdpData | ||
| 29832 | # When the server (world) reports an MSDP variable and its value, the session calls this | ||
| 29833 | # function, so that we can update the Locator task's mapping variables (where appropriate) | ||
| 29834 | # | ||
| 29835 | # Expected arguments | ||
| 29836 | # $var - An MSDP variable, e.g. ROOM (the calling function shouldn't send other | ||
| 29837 | # variables, but if it does, this function ignores them) | ||
| 29838 | # $val - The corresponding value; may be a scalar, or a list/hash reference | ||
| 29839 | # $flag - Set to TRUE if this is a generic MSDP variable, FALSE if it is a custom | ||
| 29840 | # MSDP variable | ||
| 29841 | # | ||
| 29842 | # Return values | ||
| 29843 | # 'undef' on improper arguments | ||
| 29844 | # 1 on success | ||
| 29845 | |||
| 29846 | my ($self, $var, $val, $flag, $check) = @_; | ||
| 29847 | |||
| 29848 | # Local variables | ||
| 29849 | my ( | ||
| 29850 | $mode, | ||
| 29851 | %hash, %roomHash, %exitHash, | ||
| 29852 | ); | ||
| 29853 | |||
| 29854 | # Check for improper arguments | ||
| 29855 | if (! defined $var || ! defined $val || ! defined $flag || defined $check) { | ||
| 29856 | |||
| 29857 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_updateFromMsdp', @_); | ||
| 29858 | } | ||
| 29859 | |||
| 29860 | if ($axmud::CLIENT->debugMsdpFlag) { | ||
| 29861 | |||
| 29862 | $self->session->writeDebug('LOCATOR MSDP: var ' . $var . ', val ' . $val); | ||
| 29863 | } | ||
| 29864 | |||
| 29865 | # Protect against the world sending nested arrays/tables when we're expecting a scalar | ||
| 29866 | if (ref $val eq 'ARRAY') { | ||
| 29867 | $mode = 'array'; | ||
| 29868 | } elsif (ref $val eq 'HASH') { | ||
| 29869 | $mode = 'hash'; | ||
| 29870 | } else { | ||
| 29871 | $mode = 'scalar'; | ||
| 29872 | } | ||
| 29873 | |||
| 29874 | # At the moment, only the generic variables 'ROOM' is used; the corresponding value should | ||
| 29875 | # be a hash reference | ||
| 29876 | if ($flag && $var eq 'ROOM' && $mode eq 'hash') { | ||
| 29877 | |||
| 29878 | %hash = %$val; | ||
| 29879 | |||
| 29880 | foreach my $thisKey (keys %hash) { | ||
| 29881 | |||
| 29882 | my ( | ||
| 29883 | $thisValue, | ||
| 29884 | %coordHash, %dirHash, | ||
| 29885 | ); | ||
| 29886 | |||
| 29887 | $thisValue = $hash{$thisKey}; | ||
| 29888 | |||
| 29889 | if ($thisKey eq 'VNUM') { | ||
| 29890 | |||
| 29891 | $roomHash{'vnum'} = $thisValue; | ||
| 29892 | |||
| 29893 | } elsif ($thisKey eq 'NAME') { | ||
| 29894 | |||
| 29895 | $roomHash{'name'} = $thisValue; | ||
| 29896 | |||
| 29897 | } elsif ($thisKey eq 'AREA') { | ||
| 29898 | |||
| 29899 | $roomHash{'area'} = $thisValue; | ||
| 29900 | |||
| 29901 | } elsif ($thisKey eq 'COORDS') { | ||
| 29902 | |||
| 29903 | # $thisValue is a nested table | ||
| 29904 | %coordHash = %$thisValue; | ||
| 29905 | |||
| 29906 | foreach my $thatKey (keys %coordHash) { | ||
| 29907 | |||
| 29908 | my $thatValue = $coordHash{$thatKey}; | ||
| 29909 | |||
| 29910 | if ($thatKey eq 'X') { | ||
| 29911 | $roomHash{'xpos'} = $thatValue; | ||
| 29912 | } elsif ($thatKey eq 'Y') { | ||
| 29913 | $roomHash{'ypos'} = $thatValue; | ||
| 29914 | } elsif ($thatKey eq 'Z') { | ||
| 29915 | $roomHash{'zpos'} = $thatValue; | ||
| 29916 | } | ||
| 29917 | } | ||
| 29918 | |||
| 29919 | } elsif ($thisKey eq 'TERRAIN') { | ||
| 29920 | |||
| 29921 | $roomHash{'terrain'} = $thisValue; | ||
| 29922 | |||
| 29923 | } elsif ($thisKey eq 'EXITS') { | ||
| 29924 | |||
| 29925 | # $thisValue is a nested table | ||
| 29926 | %dirHash = %$thisValue; | ||
| 29927 | |||
| 29928 | foreach my $thatKey (keys %dirHash) { | ||
| 29929 | |||
| 29930 | my $thatValue = $dirHash{$thatKey}; | ||
| 29931 | |||
| 29932 | # $exitHash{abbrev_dir} = destination_room_vnum | ||
| 29933 | $exitHash{$thatKey} = $thatValue; | ||
| 29934 | } | ||
| 29935 | } | ||
| 29936 | } | ||
| 29937 | |||
| 29938 | # Update IVs; if no ROOM data was delivered, %roomHash and %exitHash will be empty | ||
| 29939 | if ($self->roomObj) { | ||
| 29940 | |||
| 29941 | $self->roomObj->ivPoke('protocolRoomHash', %roomHash); | ||
| 29942 | $self->roomObj->ivPoke('protocolExitHash', %exitHash); | ||
| 29943 | } | ||
| 29944 | } | ||
| 29945 | |||
| 29946 | # Refresh the task window (in case the room's MSDP data arrives after the room statement | ||
| 29947 | # has been processed) | ||
| 29948 | $self->refreshWin(); | ||
| 29949 | |||
| 29950 | return 1; | ||
| 29951 | } | ||
| 29952 | |||
| 29953 | ################## | ||
| 29954 | # Accessors - task settings - get | ||
| 29955 | |||
| 29956 | # The accessors for task settings are inherited from the generic task | ||
| 29957 | |||
| 29958 | ################## | ||
| 29959 | # Accessors - task parameters - get | ||
| 29960 | |||
| 29961 | sub roomCount | ||
| 29962 | { $_[0]->{roomCount} } | ||
| 29963 | sub lastBufferLine | ||
| 29964 | { $_[0]->{lastBufferLine} } | ||
| 29965 | sub lastAnchorLine | ||
| 29966 | { $_[0]->{lastAnchorLine} } | ||
| 29967 | sub lastStatementEndLine | ||
| 29968 | { $_[0]->{lastStatementEndLine} } | ||
| 29969 | sub lastStatementStartLine | ||
| 29970 | { $_[0]->{lastStatementStartLine} } | ||
| 29971 | sub restartBufferLine | ||
| 29972 | { $_[0]->{restartBufferLine} } | ||
| 29973 | sub roomObj | ||
| 29974 | { $_[0]->{roomObj} } | ||
| 29975 | sub prevRoomObj | ||
| 29976 | { $_[0]->{prevRoomObj} } | ||
| 29977 | sub modelNumber | ||
| 29978 | { $_[0]->{modelNumber} } | ||
| 29979 | sub weatherHash | ||
| 29980 | { my $self = shift; return %{$self->{weatherHash}}; } | ||
| 29981 | sub showParsedFlag | ||
| 29982 | { $_[0]->{showParsedFlag} } | ||
| 29983 | |||
| 29984 | sub ttsToReadHash | ||
| 29985 | { my $self = shift; return %{$self->{ttsToReadHash}}; } | ||
| 29986 | |||
| 29987 | sub useMxpFlag | ||
| 29988 | { $_[0]->{useMxpFlag} } | ||
| 29989 | sub mxpPropHash | ||
| 29990 | { my $self = shift; return %{$self->{mxpPropHash}}; } | ||
| 29991 | sub mxpPropCurrentHash | ||
| 29992 | { my $self = shift; return %{$self->{mxpPropCurrentHash}}; } | ||
| 29993 | sub mxpPropStartLine | ||
| 29994 | { $_[0]->{mxpPropStartLine} } | ||
| 29995 | |||
| 29996 | sub tempContentsList | ||
| 29997 | { my $self = shift; return @{$self->{tempContentsList}}; } | ||
| 29998 | |||
| 29999 | sub cmdObjList | ||
| 30000 | { my $self = shift; return @{$self->{cmdObjList}}; } | ||
| 30001 | sub moveList | ||
| 30002 | { my $self = shift; return @{$self->{moveList}}; } | ||
| 30003 | sub prevMoveObj | ||
| 30004 | { $_[0]->{prevMoveObj} } | ||
| 30005 | sub prevMove | ||
| 30006 | { $_[0]->{prevMove} } | ||
| 30007 | sub prevCmdBufferNum | ||
| 30008 | { $_[0]->{prevCmdBufferNum} } | ||
| 30009 | sub failExitFlag | ||
| 30010 | { $_[0]->{failExitFlag} } | ||
| 30011 | sub involuntaryExitFlag | ||
| 30012 | { $_[0]->{involuntaryExitFlag} } | ||
| 30013 | sub arrivalTag | ||
| 30014 | { $_[0]->{arrivalTag} } | ||
| 30015 | |||
| 30016 | sub manualResetFlag | ||
| 30017 | { $_[0]->{manualResetFlag} } | ||
| 30018 | sub autoLookMode | ||
| 30019 | { $_[0]->{autoLookMode} } | ||
| 30020 | |||
| 30021 | sub winDescripLimit | ||
| 30022 | { $_[0]->{winDescripLimit} } | ||
| 30023 | sub combineCorpseFlag | ||
| 30024 | { $_[0]->{combineCorpseFlag} } | ||
| 30025 | sub combineBodyPartFlag | ||
| 30026 | { $_[0]->{combineBodyPartFlag} } | ||
| 30027 | } | ||
| 30028 | |||
| 30029 | { package Games::Axmud::Task::MapCheck; | ||
| 30030 | |||
| 30031 | use strict; | ||
| 30032 | use warnings; | ||
| 30033 | # use diagnostics; | ||
| 30034 | |||
| 30035 | use Glib qw(TRUE FALSE); | ||
| 30036 | |||
| 30037 | our @ISA = qw(Games::Axmud::Generic::Task Games::Axmud); | ||
| 30038 | |||
| 30039 | ################## | ||
| 30040 | # Constructors | ||
| 30041 | |||
| 30042 | sub new { | ||
| 30043 | |||
| 30044 | # Creates a new instance of the MapCheck task | ||
| 30045 | # | ||
| 30046 | # Expected arguments | ||
| 30047 | # $session - The parent GA::Session (not stored as an IV) | ||
| 30048 | # | ||
| 30049 | # Optional arguments | ||
| 30050 | # $taskType - Which tasklist this task is being created into - 'current' for the current | ||
| 30051 | # tasklist (tasks which are actually running now), 'initial' (tasks which | ||
| 30052 | # should be run when the user connects to the world), 'custom' (tasks with | ||
| 30053 | # customised initial parameters, which are run when the user demands). If | ||
| 30054 | # set to 'undef', this is a temporary task, created in order to access the | ||
| 30055 | # default values stored in IVs, that will not be added to any tasklist | ||
| 30056 | # $profName - ($taskType = 'current', when called by $self->clone) Name of the | ||
| 30057 | # profile from whose initial tasklist this task was created ('undef' if | ||
| 30058 | # none) | ||
| 30059 | # - ($taskType = 'initial') name of the profile in whose initial tasklist this | ||
| 30060 | # task will be. If 'undef', the global initial tasklist is used | ||
| 30061 | # - ($taskType = 'custom') 'undef' | ||
| 30062 | # $profCategory | ||
| 30063 | # - ($taskType = 'current', 'initial') which category the profile falls undef | ||
| 30064 | # (i.e. 'world', 'race', 'char', etc, or 'undef' if no profile) | ||
| 30065 | # - ($taskType = 'custom') 'undef' | ||
| 30066 | # $customName | ||
| 30067 | # - ($taskType = 'current', 'initial') 'undef' | ||
| 30068 | # - ($taskType = 'custom') the custom task name, matching a key in | ||
| 30069 | # GA::Session->customTaskHash | ||
| 30070 | # | ||
| 30071 | # Return values | ||
| 30072 | # 'undef' on improper arguments or if the task can't be added to the specified tasklist | ||
| 30073 | # Blessed reference to the newly-created object on success | ||
| 30074 | |||
| 30075 | my ($class, $session, $taskType, $profName, $profCategory, $customName, $check) = @_; | ||
| 30076 | |||
| 30077 | # Check for improper arguments | ||
| 30078 | if (! defined $class || ! defined $session || defined $check) { | ||
| 30079 | |||
| 30080 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 30081 | } | ||
| 30082 | |||
| 30083 | if ($taskType) { | ||
| 30084 | |||
| 30085 | # For initial tasks, check that $profName exists | ||
| 30086 | if ( | ||
| 30087 | $taskType eq 'initial' | ||
| 30088 | && defined $profName | ||
| 30089 | && ! $session->ivExists('profHash', $profName) | ||
| 30090 | ) { | ||
| 30091 | return $session->writeError( | ||
| 30092 | 'Can\'t create new task because \'' . $profName . '\' profile doesn\'t exist', | ||
| 30093 | $class . '->new', | ||
| 30094 | ); | ||
| 30095 | |||
| 30096 | # For custom tasks, check that $customName doesn't already exist | ||
| 30097 | } elsif ( | ||
| 30098 | $taskType eq 'custom' | ||
| 30099 | && $axmud::CLIENT->ivExists('customTaskHash', $customName) | ||
| 30100 | ) { | ||
| 30101 | return $session->writeError( | ||
| 30102 | 'Can\'t create new custom task because \'' . $customName . '\' is already being' | ||
| 30103 | . ' used', | ||
| 30104 | $class . '->new', | ||
| 30105 | ); | ||
| 30106 | |||
| 30107 | } elsif ($taskType ne 'current' && $taskType ne 'initial' && $taskType ne 'custom') { | ||
| 30108 | |||
| 30109 | return $session->writeError( | ||
| 30110 | 'Can\'t create new task because \'' . $taskType . '\' is an invalid tasklist', | ||
| 30111 | $class . '->new', | ||
| 30112 | ); | ||
| 30113 | } | ||
| 30114 | } | ||
| 30115 | |||
| 30116 | # Task settings | ||
| 30117 | my $self = Games::Axmud::Generic::Task->new( | ||
| 30118 | $session, | ||
| 30119 | $taskType, | ||
| 30120 | $profName, | ||
| 30121 | $profCategory, | ||
| 30122 | $customName, | ||
| 30123 | ); | ||
| 30124 | |||
| 30125 | $self->{_objName} = 'map_check_task'; | ||
| 30126 | $self->{_objClass} = $class; | ||
| 30127 | $self->{_parentFile} = undef; # Set below | ||
| 30128 | $self->{_parentWorld} = undef; # Set below | ||
| 30129 | $self->{_privFlag} = TRUE, # All IVs are private | ||
| 30130 | |||
| 30131 | $self->{name} = 'map_check_task'; | ||
| 30132 | $self->{prettyName} = 'MapCheck'; | ||
| 30133 | $self->{shortName} = 'MC'; | ||
| 30134 | $self->{shortCutIV} = undef; | ||
| 30135 | |||
| 30136 | $self->{category} = 'process'; | ||
| 30137 | $self->{descrip} = 'Display summary of automapper window drawing activities'; | ||
| 30138 | $self->{jealousyFlag} = TRUE; | ||
| 30139 | $self->{requireLocatorFlag} = FALSE; | ||
| 30140 | $self->{profSensitivityFlag} = FALSE; | ||
| 30141 | $self->{storableFlag} = TRUE; | ||
| 30142 | $self->{delayTime} = 0; | ||
| 30143 | $self->{allowWinFlag} = TRUE; | ||
| 30144 | $self->{requireWinFlag} = TRUE; | ||
| 30145 | $self->{startWithWinFlag} = TRUE; | ||
| 30146 | $self->{winPreferList} = ['pane', 'grid']; | ||
| 30147 | $self->{winmap} = 'basic_fill'; | ||
| 30148 | $self->{winUpdateFunc} = undef; | ||
| 30149 | $self->{tabMode} = 'simple'; | ||
| 30150 | $self->{monochromeFlag} = FALSE; | ||
| 30151 | $self->{noScrollFlag} = TRUE; | ||
| 30152 | $self->{ttsFlag} = FALSE; | ||
| 30153 | $self->{ttsConfig} = undef; | ||
| 30154 | $self->{ttsAttribHash} = {}; | ||
| 30155 | $self->{ttsFlagAttribHash} = {}; | ||
| 30156 | $self->{ttsAlertAttribHash} = {}; | ||
| 30157 | $self->{status} = 'wait_init'; | ||
| 30158 | # $self->{activeFlag} = TRUE; # Task can't be activated/disactivated | ||
| 30159 | |||
| 30160 | # Task parameters | ||
| 30161 | # (none for this task) | ||
| 30162 | |||
| 30163 | # Bless task | ||
| 30164 | bless $self, $class; | ||
| 30165 | |||
| 30166 | # For all tasks that aren't temporary... | ||
| 30167 | if ($taskType) { | ||
| 30168 | |||
| 30169 | # Check that the task doesn't belong to a disabled plugin (in which case, it can't be | ||
| 30170 | # added to any current, initial or custom tasklist) | ||
| 30171 | if (! $self->checkPlugins()) { | ||
| 30172 | |||
| 30173 | return undef; | ||
| 30174 | } | ||
| 30175 | |||
| 30176 | # Set the parent file object | ||
| 30177 | $self->setParentFileObj($session, $taskType, $profName, $profCategory); | ||
| 30178 | |||
| 30179 | # Create entries in tasklists, if possible | ||
| 30180 | if (! $self->updateTaskLists($session)) { | ||
| 30181 | |||
| 30182 | return undef; | ||
| 30183 | } | ||
| 30184 | } | ||
| 30185 | |||
| 30186 | # Task creation complete | ||
| 30187 | return $self; | ||
| 30188 | } | ||
| 30189 | |||
| 30190 | # sub clone {} # Inherited from generic task | ||
| 30191 | |||
| 30192 | # sub preserve {} # Inherited from generic task | ||
| 30193 | |||
| 30194 | # sub setParentFileObj {} # Inherited from generic task | ||
| 30195 | |||
| 30196 | # sub updateTaskLists {} # Inherited from generic task | ||
| 30197 | |||
| 30198 | # sub ttsReadAttrib {} # Inherited from generic task | ||
| 30199 | |||
| 30200 | # sub ttsSwitchFlagAttrib {} # Inherited from generic task | ||
| 30201 | |||
| 30202 | # sub ttsSetAlertAttrib {} # Inherited from generic task | ||
| 30203 | |||
| 30204 | ################## | ||
| 30205 | # Task windows | ||
| 30206 | |||
| 30207 | # sub toggleWin {} # Inherited from generic task | ||
| 30208 | |||
| 30209 | # sub openWin {} # Inherited from generic task | ||
| 30210 | |||
| 30211 | # sub closeWin {} # Inherited from generic task | ||
| 30212 | |||
| 30213 | ################## | ||
| 30214 | # Methods | ||
| 30215 | |||
| 30216 | # sub main {} # Inherited from generic task | ||
| 30217 | |||
| 30218 | # sub doShutdown {} # Inherited from generic task | ||
| 30219 | |||
| 30220 | # sub doReset {} # Inherited from generic task | ||
| 30221 | |||
| 30222 | # sub doFirstStage {} # Inherited from generic task | ||
| 30223 | |||
| 30224 | sub doStage { | ||
| 30225 | |||
| 30226 | # Called by $self->main to process all stages (except stage 1) | ||
| 30227 | # | ||
| 30228 | # Expected arguments | ||
| 30229 | # (none besides $self) | ||
| 30230 | # | ||
| 30231 | # Return values | ||
| 30232 | # 'undef' on improper arguments or if this function sets that task's ->status IV to | ||
| 30233 | # 'finished' or sets its ->shutdownFlag to TRUE | ||
| 30234 | # Otherwise, we normally return the new value of $self->stage | ||
| 30235 | |||
| 30236 | my ($self, $check) = @_; | ||
| 30237 | |||
| 30238 | # Check for improper arguments | ||
| 30239 | if (defined $check) { | ||
| 30240 | |||
| 30241 | return $axmud::CLIENT->writeImproper($self->_objClass . '->doStage', @_); | ||
| 30242 | } | ||
| 30243 | |||
| 30244 | if ($self->stage == 2) { | ||
| 30245 | |||
| 30246 | if (! $self->session->mapWin) { | ||
| 30247 | |||
| 30248 | # Continue waiting | ||
| 30249 | return $self->ivPoke('stage', 2); | ||
| 30250 | |||
| 30251 | } else { | ||
| 30252 | |||
| 30253 | return $self->ivPoke('stage', 3); | ||
| 30254 | } | ||
| 30255 | |||
| 30256 | } elsif ($self->stage == 3) { | ||
| 30257 | |||
| 30258 | my ( | ||
| 30259 | $mapWin, $string, | ||
| 30260 | @lineList, | ||
| 30261 | ); | ||
| 30262 | |||
| 30263 | # Import the automapper window (for convenience) | ||
| 30264 | $mapWin = $self->session->mapWin; | ||
| 30265 | |||
| 30266 | # On every spin of the task loop, update the task window (if it is still open) | ||
| 30267 | if (! $mapWin) { | ||
| 30268 | |||
| 30269 | # Clear the task window, and wait for the automapper window to re-open | ||
| 30270 | $self->insertQuick(); | ||
| 30271 | |||
| 30272 | return $self->ivPoke('stage', 2); | ||
| 30273 | |||
| 30274 | } elsif ($self->taskWinFlag) { | ||
| 30275 | |||
| 30276 | # Add the header | ||
| 30277 | push (@lineList, | ||
| 30278 | 'MAPCHECK (Time ' . sprintf("%.3f", $self->session->sessionTime) . ')', | ||
| 30279 | ); | ||
| 30280 | |||
| 30281 | $string = ' Current region: '; | ||
| 30282 | |||
| 30283 | if (! defined $mapWin->currentRegionmap) { | ||
| 30284 | $string .= 'not set'; | ||
| 30285 | } else { | ||
| 30286 | $string .= $mapWin->currentRegionmap->name; | ||
| 30287 | } | ||
| 30288 | |||
| 30289 | push (@lineList, $string); | ||
| 30290 | |||
| 30291 | $string = ' Recent regions: '; | ||
| 30292 | if (! $mapWin->recentRegionList) { | ||
| 30293 | $string .= 'not set'; | ||
| 30294 | } else { | ||
| 30295 | $string .= join('/', $mapWin->recentRegionList); | ||
| 30296 | } | ||
| 30297 | |||
| 30298 | push (@lineList, $string); | ||
| 30299 | |||
| 30300 | if (! $mapWin->parchmentHash) { | ||
| 30301 | |||
| 30302 | push (@lineList, 'Regions drawn: (none)'); | ||
| 30303 | |||
| 30304 | } else { | ||
| 30305 | |||
| 30306 | push ( | ||
| 30307 | @lineList, | ||
| 30308 | 'Regions drawn: ' . (scalar $mapWin->ivKeys('parchmentHash')), | ||
| 30309 | ); | ||
| 30310 | |||
| 30311 | foreach my $name (sort {lc($a) cmp lc($b)} ($mapWin->ivKeys('parchmentHash'))) { | ||
| 30312 | |||
| 30313 | if (! $mapWin->ivExists('parchmentReadyHash', $name)) { | ||
| 30314 | push (@lineList, ' ' . $name); | ||
| 30315 | } else { | ||
| 30316 | push (@lineList, ' * ' . $name); | ||
| 30317 | } | ||
| 30318 | } | ||
| 30319 | } | ||
| 30320 | |||
| 30321 | push (@lineList, 'Region queue: ' . (scalar $mapWin->parchmentQueueList)); | ||
| 30322 | foreach my $obj ($mapWin->parchmentQueueList) { | ||
| 30323 | |||
| 30324 | my $count = $obj->ivPairs('queueRoomEchoHash') | ||
| 30325 | + $obj->ivPairs('queueRoomBoxHash') | ||
| 30326 | + $obj->ivPairs('queueRoomTextHash') | ||
| 30327 | + $obj->ivPairs('queueRoomExitHash') | ||
| 30328 | + $obj->ivPairs('queueRoomInfoHash') | ||
| 30329 | + $obj->ivPairs('queueLabelHash'); | ||
| 30330 | |||
| 30331 | push ( | ||
| 30332 | @lineList, | ||
| 30333 | ' ' . $obj->name . ' : ' . $count, | ||
| 30334 | ' Ec ' . $obj->ivPairs('queueRoomEchoHash') | ||
| 30335 | . ' Bo ' . $obj->ivPairs('queueRoomBoxHash') | ||
| 30336 | . ' Te ' . $obj->ivPairs('queueRoomTextHash') | ||
| 30337 | . ' Ex ' . $obj->ivPairs('queueRoomExitHash') | ||
| 30338 | . ' In ' . $obj->ivPairs('queueRoomInfoHash') | ||
| 30339 | . ' La ' . $obj->ivPairs('queueLabelHash') | ||
| 30340 | ); | ||
| 30341 | } | ||
| 30342 | |||
| 30343 | # Display the list in the task window | ||
| 30344 | $self->insertQuick(join("\n", @lineList)); | ||
| 30345 | } | ||
| 30346 | |||
| 30347 | # Repeat this stage indefinitely | ||
| 30348 | return $self->ivPoke('stage', 3); | ||
| 30349 | |||
| 30350 | } else { | ||
| 30351 | |||
| 30352 | # The task stage has somehow been set to an invalid value | ||
| 30353 | return $self->invalidStage(); | ||
| 30354 | } | ||
| 30355 | } | ||
| 30356 | |||
| 30357 | ################## | ||
| 30358 | # Response methods | ||
| 30359 | |||
| 30360 | ################## | ||
| 30361 | # Accessors - set | ||
| 30362 | |||
| 30363 | ################## | ||
| 30364 | # Accessors - task settings - get | ||
| 30365 | |||
| 30366 | # The accessors for task settings are inherited from the generic task | ||
| 30367 | |||
| 30368 | ################## | ||
| 30369 | # Accessors - task parameters - get | ||
| 30370 | |||
| 30371 | # No task parameters | ||
| 30372 | } | ||
| 30373 | |||
| 30374 | { package Games::Axmud::Task::Notepad; | ||
| 30375 | |||
| 30376 | use strict; | ||
| 30377 | use warnings; | ||
| 30378 | # use diagnostics; | ||
| 30379 | |||
| 30380 | use Glib qw(TRUE FALSE); | ||
| 30381 | |||
| 30382 | our @ISA = qw(Games::Axmud::Generic::Task Games::Axmud); | ||
| 30383 | |||
| 30384 | ################## | ||
| 30385 | # Constructors | ||
| 30386 | |||
| 30387 | sub new { | ||
| 30388 | |||
| 30389 | # Creates a new instance of the Notepad task | ||
| 30390 | # | ||
| 30391 | # Expected arguments | ||
| 30392 | # $session - The parent GA::Session (not stored as an IV) | ||
| 30393 | # | ||
| 30394 | # Optional arguments | ||
| 30395 | # $taskType - Which tasklist this task is being created into - 'current' for the current | ||
| 30396 | # tasklist (tasks which are actually running now), 'initial' (tasks which | ||
| 30397 | # should be run when the user connects to the world), 'custom' (tasks with | ||
| 30398 | # customised initial parameters, which are run when the user demands). If | ||
| 30399 | # set to 'undef', this is a temporary task, created in order to access the | ||
| 30400 | # default values stored in IVs, that will not be added to any tasklist | ||
| 30401 | # $profName - ($taskType = 'current', when called by $self->clone) Name of the | ||
| 30402 | # profile from whose initial tasklist this task was created ('undef' if | ||
| 30403 | # none) | ||
| 30404 | # - ($taskType = 'initial') name of the profile in whose initial tasklist this | ||
| 30405 | # task will be. If 'undef', the global initial tasklist is used | ||
| 30406 | # - ($taskType = 'custom') 'undef' | ||
| 30407 | # $profCategory | ||
| 30408 | # - ($taskType = 'current', 'initial') which category the profile falls undef | ||
| 30409 | # (i.e. 'world', 'race', 'char', etc, or 'undef' if no profile) | ||
| 30410 | # - ($taskType = 'custom') 'undef' | ||
| 30411 | # $customName | ||
| 30412 | # - ($taskType = 'current', 'initial') 'undef' | ||
| 30413 | # - ($taskType = 'custom') the custom task name, matching a key in | ||
| 30414 | # GA::Session->customTaskHash | ||
| 30415 | # | ||
| 30416 | # Return values | ||
| 30417 | # 'undef' on improper arguments or if the task can't be added to the specified tasklist | ||
| 30418 | # Blessed reference to the newly-created object on success | ||
| 30419 | |||
| 30420 | my ($class, $session, $taskType, $profName, $profCategory, $customName, $check) = @_; | ||
| 30421 | |||
| 30422 | # Check for improper arguments | ||
| 30423 | if (! defined $class || ! defined $session || defined $check) { | ||
| 30424 | |||
| 30425 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 30426 | } | ||
| 30427 | |||
| 30428 | if ($taskType) { | ||
| 30429 | |||
| 30430 | # For initial tasks, check that $profName exists | ||
| 30431 | if ( | ||
| 30432 | $taskType eq 'initial' | ||
| 30433 | && defined $profName | ||
| 30434 | && ! $session->ivExists('profHash', $profName) | ||
| 30435 | ) { | ||
| 30436 | return $session->writeError( | ||
| 30437 | 'Can\'t create new task because \'' . $profName . '\' profile doesn\'t exist', | ||
| 30438 | $class . '->new', | ||
| 30439 | ); | ||
| 30440 | |||
| 30441 | # For custom tasks, check that $customName doesn't already exist | ||
| 30442 | } elsif ( | ||
| 30443 | $taskType eq 'custom' | ||
| 30444 | && $axmud::CLIENT->ivExists('customTaskHash', $customName) | ||
| 30445 | ) { | ||
| 30446 | return $session->writeError( | ||
| 30447 | 'Can\'t create new custom task because \'' . $customName . '\' is already being' | ||
| 30448 | . ' used', | ||
| 30449 | $class . '->new', | ||
| 30450 | ); | ||
| 30451 | |||
| 30452 | } elsif ($taskType ne 'current' && $taskType ne 'initial' && $taskType ne 'custom') { | ||
| 30453 | |||
| 30454 | return $session->writeError( | ||
| 30455 | 'Can\'t create new task because \'' . $taskType . '\' is an invalid tasklist', | ||
| 30456 | $class . '->new', | ||
| 30457 | ); | ||
| 30458 | } | ||
| 30459 | } | ||
| 30460 | |||
| 30461 | # Task settings | ||
| 30462 | my $self = Games::Axmud::Generic::Task->new( | ||
| 30463 | $session, | ||
| 30464 | $taskType, | ||
| 30465 | $profName, | ||
| 30466 | $profCategory, | ||
| 30467 | $customName, | ||
| 30468 | ); | ||
| 30469 | |||
| 30470 | $self->{_objName} = 'notepad_task'; | ||
| 30471 | $self->{_objClass} = $class; | ||
| 30472 | $self->{_parentFile} = undef; # Set below | ||
| 30473 | $self->{_parentWorld} = undef; # Set below | ||
| 30474 | $self->{_privFlag} = TRUE, # All IVs are private | ||
| 30475 | |||
| 30476 | $self->{name} = 'notepad_task'; | ||
| 30477 | $self->{prettyName} = 'Notepad'; | ||
| 30478 | $self->{shortName} = 'Np'; | ||
| 30479 | $self->{shortCutIV} = 'notepadTask'; # Axmud built-in jealous task | ||
| 30480 | |||
| 30481 | $self->{category} = 'activity'; | ||
| 30482 | $self->{descrip} = 'Shows persistent notes for each current profile'; | ||
| 30483 | $self->{jealousyFlag} = TRUE; | ||
| 30484 | $self->{requireLocatorFlag} = FALSE; | ||
| 30485 | $self->{profSensitivityFlag} = TRUE; | ||
| 30486 | $self->{storableFlag} = TRUE; | ||
| 30487 | $self->{delayTime} = 0; | ||
| 30488 | $self->{allowWinFlag} = TRUE; | ||
| 30489 | $self->{requireWinFlag} = TRUE; | ||
| 30490 | $self->{startWithWinFlag} = TRUE; | ||
| 30491 | $self->{winPreferList} = ['pseudo', 'grid']; | ||
| 30492 | $self->{winmap} = 'basic_empty'; | ||
| 30493 | $self->{winUpdateFunc} = undef; | ||
| 30494 | $self->{tabMode} = undef; | ||
| 30495 | $self->{monochromeFlag} = FALSE; | ||
| 30496 | $self->{noScrollFlag} = FALSE; | ||
| 30497 | $self->{ttsFlag} = FALSE; | ||
| 30498 | $self->{ttsConfig} = undef; | ||
| 30499 | $self->{ttsAttribHash} = {}; | ||
| 30500 | $self->{ttsFlagAttribHash} = {}; | ||
| 30501 | $self->{ttsAlertAttribHash} = {}; | ||
| 30502 | $self->{status} = 'wait_init'; | ||
| 30503 | # $self->{activeFlag} = TRUE; # Task can't be activated/disactivated | ||
| 30504 | |||
| 30505 | # Task parameters | ||
| 30506 | # | ||
| 30507 | # Table objects created for various Gtk3 widgets, stored here because various functions | ||
| 30508 | # need them | ||
| 30509 | $self->{textTableObj} = undef; | ||
| 30510 | $self->{comboTableObj} = undef; | ||
| 30511 | |||
| 30512 | # When the task starts (or is reset), the current contents of all current profiles' | ||
| 30513 | # ->notepadList IVs are stored in this hash, so that if the user clicks the 'Restore | ||
| 30514 | # notes' button, the contents of the textview can be magically reset to what it was, when | ||
| 30515 | # the task started. Hash in the form | ||
| 30516 | # $profNoteHash{profile_name} = reference_to_list_of_notes | ||
| 30517 | $self->{profNoteHash} = {}; | ||
| 30518 | |||
| 30519 | # Bless task | ||
| 30520 | bless $self, $class; | ||
| 30521 | |||
| 30522 | # For all tasks that aren't temporary... | ||
| 30523 | if ($taskType) { | ||
| 30524 | |||
| 30525 | # Check that the task doesn't belong to a disabled plugin (in which case, it can't be | ||
| 30526 | # added to any current, initial or custom tasklist) | ||
| 30527 | if (! $self->checkPlugins()) { | ||
| 30528 | |||
| 30529 | return undef; | ||
| 30530 | } | ||
| 30531 | |||
| 30532 | # Set the parent file object | ||
| 30533 | $self->setParentFileObj($session, $taskType, $profName, $profCategory); | ||
| 30534 | |||
| 30535 | # Create entries in tasklists, if possible | ||
| 30536 | if (! $self->updateTaskLists($session)) { | ||
| 30537 | |||
| 30538 | return undef; | ||
| 30539 | } | ||
| 30540 | } | ||
| 30541 | |||
| 30542 | # Task creation complete | ||
| 30543 | return $self; | ||
| 30544 | } | ||
| 30545 | |||
| 30546 | sub clone { | ||
| 30547 | |||
| 30548 | # Create a clone of an existing task | ||
| 30549 | # Usually used upon connection to a world, when every task in the initial tasklists must | ||
| 30550 | # be cloned into a new object, representing a task in the current tasklist | ||
| 30551 | # (Also used when cloning a profile object, since all the tasks in its initial tasklist must | ||
| 30552 | # also be cloned) | ||
| 30553 | # | ||
| 30554 | # Expected arguments | ||
| 30555 | # $session - The parent GA::Session (not stored as an IV) | ||
| 30556 | # $taskType - Which tasklist this task is being created into - 'current' for the current | ||
| 30557 | # tasklist (tasks which are actually running now), 'initial' (tasks which | ||
| 30558 | # should be run when the user connects to the world). Custom tasks aren't | ||
| 30559 | # cloned (at the moment) | ||
| 30560 | # | ||
| 30561 | # Optional arguments | ||
| 30562 | # $profName - ($taskType = 'initial') name of the profile in whose initial tasklist the | ||
| 30563 | # existing task is stored | ||
| 30564 | # $profCategory | ||
| 30565 | # - ($taskType = 'initial') which category the profile falls under (i.e. | ||
| 30566 | # 'world', 'race', 'char', etc) | ||
| 30567 | # | ||
| 30568 | # Return values | ||
| 30569 | # 'undef' on improper arguments or if the task can't be cloned | ||
| 30570 | # Blessed reference to the newly-created object on success | ||
| 30571 | |||
| 30572 | my ($self, $session, $taskType, $profName, $profCategory, $check) = @_; | ||
| 30573 | |||
| 30574 | # Check for improper arguments | ||
| 30575 | if ( | ||
| 30576 | ! defined $session || ! defined $taskType || defined $check | ||
| 30577 | || ($taskType ne 'current' && $taskType ne 'initial') | ||
| 30578 | || ($taskType eq 'initial' && (! defined $profName || ! defined $profCategory)) | ||
| 30579 | ) { | ||
| 30580 | return $axmud::CLIENT->writeImproper($self->_objClass . '->clone', @_); | ||
| 30581 | } | ||
| 30582 | |||
| 30583 | # For initial tasks, check that $profName exists | ||
| 30584 | if ( | ||
| 30585 | $taskType eq 'initial' | ||
| 30586 | && defined $profName | ||
| 30587 | && ! $session->ivExists('profHash', $profName) | ||
| 30588 | ) { | ||
| 30589 | return $axmud::CLIENT->writeError( | ||
| 30590 | 'Can\'t create cloned task because \'' . $profName . '\' profile doesn\'t exist', | ||
| 30591 | $self->_objClass . '->clone', | ||
| 30592 | ); | ||
| 30593 | } | ||
| 30594 | |||
| 30595 | # Check that the task doesn't belong to a disabled plugin (in which case, it can't be | ||
| 30596 | # cloned) | ||
| 30597 | if (! $self->checkPlugins()) { | ||
| 30598 | |||
| 30599 | return undef; | ||
| 30600 | } | ||
| 30601 | |||
| 30602 | # Create the new task, using default settings and parameters | ||
| 30603 | my $clone = $self->_objClass->new($session, $taskType, $profName, $profCategory); | ||
| 30604 | |||
| 30605 | # Most of the cloned task's settings have default values, but a few are copied from the | ||
| 30606 | # original | ||
| 30607 | $self->cloneTaskSettings($clone); | ||
| 30608 | |||
| 30609 | # Give the new (cloned) task the same initial parameters as the original one | ||
| 30610 | $clone->{textTableObj} = $self->textTableObj; | ||
| 30611 | $clone->{comboTableObj} = $self->comboTableObj; | ||
| 30612 | |||
| 30613 | $clone->{profNoteHash} = {$self->profNoteHash}; | ||
| 30614 | |||
| 30615 | # Cloning complete | ||
| 30616 | return $clone; | ||
| 30617 | } | ||
| 30618 | |||
| 30619 | # sub preserve {} # Inherited from generic task | ||
| 30620 | |||
| 30621 | # sub setParentFileObj {} # Inherited from generic task | ||
| 30622 | |||
| 30623 | # sub updateTaskLists {} # Inherited from generic task | ||
| 30624 | |||
| 30625 | # sub ttsReadAttrib {} # Inherited from generic task | ||
| 30626 | |||
| 30627 | # sub ttsSwitchFlagAttrib {} # Inherited from generic task | ||
| 30628 | |||
| 30629 | # sub ttsSetAlertAttrib {} # Inherited from generic task | ||
| 30630 | |||
| 30631 | ################## | ||
| 30632 | # Task windows | ||
| 30633 | |||
| 30634 | # sub toggleWin {} # Inherited from generic task | ||
| 30635 | |||
| 30636 | # sub openWin {} # Inherited from generic task | ||
| 30637 | |||
| 30638 | # sub closeWin {} # Inherited from generic task | ||
| 30639 | |||
| 30640 | ################## | ||
| 30641 | # Methods | ||
| 30642 | |||
| 30643 | # sub init {} # Inherited from generic task | ||
| 30644 | |||
| 30645 | sub doInit { | ||
| 30646 | |||
| 30647 | # Called by $self->init, just before the task completes its setup ($self->init) | ||
| 30648 | # | ||
| 30649 | # Expected arguments | ||
| 30650 | # (none besides $self) | ||
| 30651 | # | ||
| 30652 | # Return values | ||
| 30653 | # 'undef' on improper arguments | ||
| 30654 | # 1 otherwise | ||
| 30655 | |||
| 30656 | my ($self, $check) = @_; | ||
| 30657 | |||
| 30658 | # Check for improper arguments | ||
| 30659 | if (defined $check) { | ||
| 30660 | |||
| 30661 | return $axmud::CLIENT->writeImproper($self->_objClass . '->doInit', @_); | ||
| 30662 | } | ||
| 30663 | |||
| 30664 | # Store the current state of all current profiles' ->notepadList, so that if the user clicks | ||
| 30665 | # the 'Restore notes' button, the contents of the textview can be magically reset to what | ||
| 30666 | # it was, when the task started | ||
| 30667 | foreach my $profObj ($self->session->ivValues('currentProfHash')) { | ||
| 30668 | |||
| 30669 | my @list = $profObj->notepadList; | ||
| 30670 | |||
| 30671 | $self->ivAdd('profNoteHash', $profObj->name, \@list); | ||
| 30672 | } | ||
| 30673 | |||
| 30674 | # If the task has recently been updated, quickest way to update the window is to remove all | ||
| 30675 | # the current table objects, before creating new ones | ||
| 30676 | if ($self->hasResetFlag) { | ||
| 30677 | |||
| 30678 | if (! defined $self->winObj->tableStripObj->removeAllTableObjs()) { | ||
| 30679 | |||
| 30680 | # Operation failed; task must close | ||
| 30681 | $self->ivPoke('shutdownFlag', TRUE); | ||
| 30682 | return 1; | ||
| 30683 | } | ||
| 30684 | } | ||
| 30685 | |||
| 30686 | # Create widgets for the task | ||
| 30687 | $self->createWidgets(); | ||
| 30688 | |||
| 30689 | return 1; | ||
| 30690 | } | ||
| 30691 | |||
| 30692 | # sub doShutdown {} # Inherited from generic task | ||
| 30693 | |||
| 30694 | # sub doReset {} # Inherited from generic task | ||
| 30695 | |||
| 30696 | sub createWidgets { | ||
| 30697 | |||
| 30698 | # Set up the widgets used in the task window | ||
| 30699 | # | ||
| 30700 | # Expected arguments | ||
| 30701 | # (none besides $self) | ||
| 30702 | # | ||
| 30703 | # Return values | ||
| 30704 | # 'undef' on improper arguments | ||
| 30705 | # 1 otherwise | ||
| 30706 | |||
| 30707 | my ($self, $check) = @_; | ||
| 30708 | |||
| 30709 | # Local variables | ||
| 30710 | my ( | ||
| 30711 | $string, $textTableObj, $comboTableObj, | ||
| 30712 | @comboList, | ||
| 30713 | %profHash, | ||
| 30714 | ); | ||
| 30715 | |||
| 30716 | # Check for improper arguments | ||
| 30717 | if (defined $check) { | ||
| 30718 | |||
| 30719 | return $axmud::CLIENT->writeImproper($self->_objClass . '->createWidgets', @_); | ||
| 30720 | } | ||
| 30721 | |||
| 30722 | # Add a textview to display the notes | ||
| 30723 | if ($self->session->currentWorld->notepadList) { | ||
| 30724 | $string = join("\n", $self->session->currentWorld->notepadList); | ||
| 30725 | } else { | ||
| 30726 | $string = ''; | ||
| 30727 | } | ||
| 30728 | |||
| 30729 | # I experimented with the table coordinates to stop the combobox/buttons appearing too | ||
| 30730 | # high. For unknown reasons, the best arrangement is to leave a one-row gap between the | ||
| 30731 | # textview and the combobox/buttons beneath it | ||
| 30732 | $textTableObj = $self->winObj->tableStripObj->addTableObj( | ||
| 30733 | 'Games::Axmud::Table::TextView', | ||
| 30734 | 0, 59, 0, 57, | ||
| 30735 | undef, | ||
| 30736 | # Init settings | ||
| 30737 | 'func' => $self->getMethodRef('textViewCallback'), | ||
| 30738 | 'text' => $string, | ||
| 30739 | 'edit_flag' => TRUE, | ||
| 30740 | 'colour_scheme' => 'edit', | ||
| 30741 | 'spacing' => 0, | ||
| 30742 | ); | ||
| 30743 | |||
| 30744 | # Add a combo to switch between profiles, displaying a list of current profiles in reverse | ||
| 30745 | # priority order (so that the current world is always at the top) | ||
| 30746 | $self->winObj->tableStripObj->addTableObj( | ||
| 30747 | 'Games::Axmud::Table::Label', | ||
| 30748 | 0, 4, 58, 59, | ||
| 30749 | undef, | ||
| 30750 | # Init settings | ||
| 30751 | 'text' => 'Profile: ', | ||
| 30752 | ); | ||
| 30753 | |||
| 30754 | %profHash = $self->session->currentProfHash; | ||
| 30755 | foreach my $category ($self->session->profPriorityList) { | ||
| 30756 | |||
| 30757 | my $profObj = $profHash{$category}; | ||
| 30758 | |||
| 30759 | if (defined $profObj) { | ||
| 30760 | |||
| 30761 | delete $profHash{$category}; | ||
| 30762 | push (@comboList, $profObj->name); | ||
| 30763 | } | ||
| 30764 | } | ||
| 30765 | |||
| 30766 | @comboList = reverse @comboList; # Current world to top of list | ||
| 30767 | foreach my $profObj (sort {lc($a->name) cmp lc($b->name)} (values %profHash)) { | ||
| 30768 | |||
| 30769 | push (@comboList, $profObj->name); | ||
| 30770 | } | ||
| 30771 | |||
| 30772 | $comboTableObj = $self->winObj->tableStripObj->addTableObj( | ||
| 30773 | 'Games::Axmud::Table::ComboBox', | ||
| 30774 | 5, 24, 58, 59, | ||
| 30775 | undef, | ||
| 30776 | # Init settings | ||
| 30777 | 'func' => $self->getMethodRef('comboCallback'), | ||
| 30778 | 'list_ref' => \@comboList, | ||
| 30779 | ); | ||
| 30780 | |||
| 30781 | # Add buttons - one to empty the textview of notes, another to restore the displayed notes | ||
| 30782 | # to what they were, when the task started (or was last reset) | ||
| 30783 | $self->winObj->tableStripObj->addTableObj( | ||
| 30784 | 'Games::Axmud::Table::Button', | ||
| 30785 | 30, 39, 58, 59, | ||
| 30786 | undef, | ||
| 30787 | # Init settings | ||
| 30788 | 'func' => $self->getMethodRef('clipboardCallback'), | ||
| 30789 | 'text' => 'Paste', | ||
| 30790 | 'tooltips' => 'Insert any selected text in the session\'s default tab', | ||
| 30791 | ); | ||
| 30792 | |||
| 30793 | $self->winObj->tableStripObj->addTableObj( | ||
| 30794 | 'Games::Axmud::Table::Button', | ||
| 30795 | 40, 49, 58, 59, | ||
| 30796 | undef, | ||
| 30797 | # Init settings | ||
| 30798 | 'func' => $self->getMethodRef('emptyCallback'), | ||
| 30799 | 'text' => 'Empty', | ||
| 30800 | 'tooltips' => 'Empty the notes for this profile', | ||
| 30801 | ); | ||
| 30802 | |||
| 30803 | $self->winObj->tableStripObj->addTableObj( | ||
| 30804 | 'Games::Axmud::Table::Button', | ||
| 30805 | 50, 59, 58, 59, | ||
| 30806 | undef, | ||
| 30807 | # Init settings | ||
| 30808 | 'func' => $self->getMethodRef('restoreCallback'), | ||
| 30809 | 'text' => 'Restore', | ||
| 30810 | 'tooltips' => 'Restore the notes that existed when this task started', | ||
| 30811 | ); | ||
| 30812 | |||
| 30813 | # Store the widgets created, so that callbacks can access them | ||
| 30814 | $self->ivPoke('textTableObj', $textTableObj); | ||
| 30815 | $self->ivPoke('comboTableObj', $comboTableObj); | ||
| 30816 | |||
| 30817 | # Display all the widgets | ||
| 30818 | $self->winObj->winShowAll($self->_objClass . '->createWidgets'); | ||
| 30819 | |||
| 30820 | return 1; | ||
| 30821 | } | ||
| 30822 | |||
| 30823 | ################## | ||
| 30824 | # Response methods | ||
| 30825 | |||
| 30826 | sub textViewCallback { | ||
| 30827 | |||
| 30828 | # Called by a ->signal_connect in a GA::Table::TextView object when the user edits the | ||
| 30829 | # textview's contents | ||
| 30830 | # Stores the textview's contents in the selected profile's IV | ||
| 30831 | # | ||
| 30832 | # Expected arguments | ||
| 30833 | # $tableObj - The GA::Table::TextView object for the textview | ||
| 30834 | # $textView - The actual Gtk3::TextView edited | ||
| 30835 | # $buffer - The textview's Gtk3::Buffer | ||
| 30836 | # $id - The callback ID; in this case, an empty string | ||
| 30837 | # $text - The contents of the buffer (a string containing one or more lines | ||
| 30838 | # separated by newline characters) | ||
| 30839 | # | ||
| 30840 | # Return values | ||
| 30841 | # 'undef' on improper arguments | ||
| 30842 | # 1 otherwise | ||
| 30843 | |||
| 30844 | my ($self, $tableObj, $textView, $buffer, $id, $text, $check) = @_; | ||
| 30845 | |||
| 30846 | # Local variables | ||
| 30847 | my ($profile, $profObj); | ||
| 30848 | |||
| 30849 | # Check for improper arguments | ||
| 30850 | if ( | ||
| 30851 | ! defined $tableObj || ! defined $textView || ! defined $buffer || ! defined $id | ||
| 30852 | || ! defined $text || defined $check | ||
| 30853 | ) { | ||
| 30854 | return $axmud::CLIENT->writeImproper($self->_objClass . '->textViewCallback', @_); | ||
| 30855 | } | ||
| 30856 | |||
| 30857 | # Get the combobox's active profile | ||
| 30858 | $profile = $self->comboTableObj->get_text(); | ||
| 30859 | $profObj = $self->session->ivShow('profHash', $profile); | ||
| 30860 | |||
| 30861 | # Update the selected profile's IV | ||
| 30862 | if ($profObj) { | ||
| 30863 | |||
| 30864 | if ($text) { | ||
| 30865 | $profObj->ivPoke('notepadList', split("\n", $text)); | ||
| 30866 | } else { | ||
| 30867 | $profObj->ivEmpty('notepadList'); | ||
| 30868 | } | ||
| 30869 | } | ||
| 30870 | |||
| 30871 | return 1; | ||
| 30872 | } | ||
| 30873 | |||
| 30874 | sub comboCallback { | ||
| 30875 | |||
| 30876 | # Called by a ->signal_connect in a GA::Table::Button object when the user selects a | ||
| 30877 | # profile in the combobox | ||
| 30878 | # Updates the contents of the textview to show notes for that profile | ||
| 30879 | # | ||
| 30880 | # Expected arguments | ||
| 30881 | # $tableObj - The GA::Table::ComboBox object for the combobox | ||
| 30882 | # $comboBox - The actual Gtk3::ComboBox used | ||
| 30883 | # $id - The callback ID; in this case, an empty string | ||
| 30884 | # $profile - The selected world profile | ||
| 30885 | # | ||
| 30886 | # Return values | ||
| 30887 | # 'undef' on improper arguments | ||
| 30888 | # 1 otherwise | ||
| 30889 | |||
| 30890 | my ($self, $tableObj, $comboBox, $id, $profile, $check) = @_; | ||
| 30891 | |||
| 30892 | # Local variables | ||
| 30893 | my $profObj; | ||
| 30894 | |||
| 30895 | # Check for improper arguments | ||
| 30896 | if ( | ||
| 30897 | ! defined $tableObj || ! defined $comboBox || ! defined $id || ! defined $profile | ||
| 30898 | || defined $check | ||
| 30899 | ) { | ||
| 30900 | return $axmud::CLIENT->writeImproper($self->_objClass . '->comboCallback', @_); | ||
| 30901 | } | ||
| 30902 | |||
| 30903 | # Get the corresponding profile object | ||
| 30904 | $profObj = $self->session->ivShow('profHash', $profile); | ||
| 30905 | |||
| 30906 | # Update the textview | ||
| 30907 | if ($profObj) { | ||
| 30908 | |||
| 30909 | $self->textTableObj->set_text(join("\n", $profObj->notepadList)); | ||
| 30910 | } | ||
| 30911 | |||
| 30912 | return 1; | ||
| 30913 | } | ||
| 30914 | |||
| 30915 | sub clipboardCallback { | ||
| 30916 | |||
| 30917 | # Called by a ->signal_connect in a GA::Table::Button object when the user clicks on the | ||
| 30918 | # 'Empty notes' button | ||
| 30919 | # Pastes the contents of the clipboard into the textview | ||
| 30920 | # | ||
| 30921 | # Expected arguments | ||
| 30922 | # $tableObj - The GA::Table::Button object for the button | ||
| 30923 | # $button - The actual Gtk3::Button clicked | ||
| 30924 | # $id - The callback ID; in this case, a keycode | ||
| 30925 | # | ||
| 30926 | # Return values | ||
| 30927 | # 'undef' on improper arguments | ||
| 30928 | # 1 otherwise | ||
| 30929 | |||
| 30930 | my ($self, $tableObj, $button, $id, $check) = @_; | ||
| 30931 | |||
| 30932 | # Local variables | ||
| 30933 | my ($textViewObj, $startIter, $endIter, $slice); | ||
| 30934 | |||
| 30935 | # Check for improper arguments | ||
| 30936 | if (! defined $tableObj || ! defined $button || ! defined $id || defined $check) { | ||
| 30937 | |||
| 30938 | return $axmud::CLIENT->writeImproper($self->_objClass . '->clipboardCallback', @_); | ||
| 30939 | } | ||
| 30940 | |||
| 30941 | $textViewObj = $self->session->defaultTabObj->textViewObj; | ||
| 30942 | ($startIter, $endIter) = $textViewObj->buffer->get_selection_bounds(); | ||
| 30943 | if (defined $endIter) { | ||
| 30944 | |||
| 30945 | $slice = $textViewObj->buffer->get_slice($startIter, $endIter, FALSE); | ||
| 30946 | |||
| 30947 | if (defined $slice && $slice ne '') { | ||
| 30948 | |||
| 30949 | $self->textTableObj->insert_text($slice); | ||
| 30950 | } | ||
| 30951 | |||
| 30952 | return 1; | ||
| 30953 | } | ||
| 30954 | } | ||
| 30955 | |||
| 30956 | sub emptyCallback { | ||
| 30957 | |||
| 30958 | # Called by a ->signal_connect in a GA::Table::Button object when the user clicks on the | ||
| 30959 | # 'Empty' button | ||
| 30960 | # Empties the textview and updates the selected profile's IV | ||
| 30961 | # | ||
| 30962 | # Expected arguments | ||
| 30963 | # $tableObj - The GA::Table::Button object for the button | ||
| 30964 | # $button - The actual Gtk3::Button clicked | ||
| 30965 | # $id - The callback ID; in this case, a keycode | ||
| 30966 | # | ||
| 30967 | # Return values | ||
| 30968 | # 'undef' on improper arguments | ||
| 30969 | # 1 otherwise | ||
| 30970 | |||
| 30971 | my ($self, $tableObj, $button, $id, $check) = @_; | ||
| 30972 | |||
| 30973 | # Check for improper arguments | ||
| 30974 | if (! defined $tableObj || ! defined $button || ! defined $id || defined $check) { | ||
| 30975 | |||
| 30976 | return $axmud::CLIENT->writeImproper($self->_objClass . '->emptyCallback', @_); | ||
| 30977 | } | ||
| 30978 | |||
| 30979 | # Empty the textview | ||
| 30980 | $self->textTableObj->set_text(); | ||
| 30981 | |||
| 30982 | return 1; | ||
| 30983 | } | ||
| 30984 | |||
| 30985 | sub restoreCallback { | ||
| 30986 | |||
| 30987 | # Called by a ->signal_connect in a GA::Table::Button object when the user clicks on the | ||
| 30988 | # 'Restore' button | ||
| 30989 | # Restores the notes displayed in the textview for the current profile, when the task | ||
| 30990 | # started (or was last reset) | ||
| 30991 | # | ||
| 30992 | # Expected arguments | ||
| 30993 | # $tableObj - The GA::Table::Button object for the button | ||
| 30994 | # $button - The actual Gtk3::Button clicked | ||
| 30995 | # $id - The callback ID; in this case, a keycode | ||
| 30996 | # | ||
| 30997 | # Return values | ||
| 30998 | # 'undef' on improper arguments | ||
| 30999 | # 1 otherwise | ||
| 31000 | |||
| 31001 | my ($self, $tableObj, $button, $id, $check) = @_; | ||
| 31002 | |||
| 31003 | # Local variables | ||
| 31004 | my $listRef; | ||
| 31005 | |||
| 31006 | # Check for improper arguments | ||
| 31007 | if (! defined $tableObj || ! defined $button || ! defined $id || defined $check) { | ||
| 31008 | |||
| 31009 | return $axmud::CLIENT->writeImproper($self->_objClass . '->restoreCallback', @_); | ||
| 31010 | } | ||
| 31011 | |||
| 31012 | # Reset the textview | ||
| 31013 | $listRef = $self->ivShow('profNoteHash', $self->comboTableObj->get_text()); | ||
| 31014 | if (defined $listRef) { | ||
| 31015 | |||
| 31016 | $self->textTableObj->set_text(join("\n", @$listRef)); | ||
| 31017 | } | ||
| 31018 | |||
| 31019 | return 1; | ||
| 31020 | } | ||
| 31021 | |||
| 31022 | ################## | ||
| 31023 | # Accessors - set | ||
| 31024 | |||
| 31025 | ################## | ||
| 31026 | # Accessors - task settings - get | ||
| 31027 | |||
| 31028 | # The accessors for task settings are inherited from the generic task | ||
| 31029 | |||
| 31030 | ################## | ||
| 31031 | # Accessors - task parameters - get | ||
| 31032 | |||
| 31033 | sub textTableObj | ||
| 31034 | { $_[0]->{textTableObj} } | ||
| 31035 | sub comboTableObj | ||
| 31036 | { $_[0]->{comboTableObj} } | ||
| 31037 | |||
| 31038 | sub profNoteHash | ||
| 31039 | { my $self = shift; return %{$self->{profNoteHash}}; } | ||
| 31040 | } | ||
| 31041 | |||
| 31042 | { package Games::Axmud::Task::RawText; | ||
| 31043 | |||
| 31044 | use strict; | ||
| 31045 | use warnings; | ||
| 31046 | # use diagnostics; | ||
| 31047 | |||
| 31048 | use Glib qw(TRUE FALSE); | ||
| 31049 | |||
| 31050 | our @ISA = qw(Games::Axmud::Generic::Task Games::Axmud); | ||
| 31051 | |||
| 31052 | ################## | ||
| 31053 | # Constructors | ||
| 31054 | |||
| 31055 | sub new { | ||
| 31056 | |||
| 31057 | # Creates a new instance of the RawText task | ||
| 31058 | # | ||
| 31059 | # Expected arguments | ||
| 31060 | # $session - The parent GA::Session (not stored as an IV) | ||
| 31061 | # | ||
| 31062 | # Optional arguments | ||
| 31063 | # $taskType - Which tasklist this task is being created into - 'current' for the current | ||
| 31064 | # tasklist (tasks which are actually running now), 'initial' (tasks which | ||
| 31065 | # should be run when the user connects to the world), 'custom' (tasks with | ||
| 31066 | # customised initial parameters, which are run when the user demands). If | ||
| 31067 | # set to 'undef', this is a temporary task, created in order to access the | ||
| 31068 | # default values stored in IVs, that will not be added to any tasklist | ||
| 31069 | # $profName - ($taskType = 'current', when called by $self->clone) Name of the | ||
| 31070 | # profile from whose initial tasklist this task was created ('undef' if | ||
| 31071 | # none) | ||
| 31072 | # - ($taskType = 'initial') name of the profile in whose initial tasklist this | ||
| 31073 | # task will be. If 'undef', the global initial tasklist is used | ||
| 31074 | # - ($taskType = 'custom') 'undef' | ||
| 31075 | # $profCategory | ||
| 31076 | # - ($taskType = 'current', 'initial') which category the profile falls undef | ||
| 31077 | # (i.e. 'world', 'race', 'char', etc, or 'undef' if no profile) | ||
| 31078 | # - ($taskType = 'custom') 'undef' | ||
| 31079 | # $customName | ||
| 31080 | # - ($taskType = 'current', 'initial') 'undef' | ||
| 31081 | # - ($taskType = 'custom') the custom task name, matching a key in | ||
| 31082 | # GA::Session->customTaskHash | ||
| 31083 | # | ||
| 31084 | # Return values | ||
| 31085 | # 'undef' on improper arguments or if the task can't be added to the specified tasklist | ||
| 31086 | # Blessed reference to the newly-created object on success | ||
| 31087 | |||
| 31088 | my ($class, $session, $taskType, $profName, $profCategory, $customName, $check) = @_; | ||
| 31089 | |||
| 31090 | # Check for improper arguments | ||
| 31091 | if (! defined $class || ! defined $session || defined $check) { | ||
| 31092 | |||
| 31093 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 31094 | } | ||
| 31095 | |||
| 31096 | if ($taskType) { | ||
| 31097 | |||
| 31098 | # For initial tasks, check that $profName exists | ||
| 31099 | if ( | ||
| 31100 | $taskType eq 'initial' | ||
| 31101 | && defined $profName | ||
| 31102 | && ! $session->ivExists('profHash', $profName) | ||
| 31103 | ) { | ||
| 31104 | return $session->writeError( | ||
| 31105 | 'Can\'t create new task because \'' . $profName . '\' profile doesn\'t exist', | ||
| 31106 | $class . '->new', | ||
| 31107 | ); | ||
| 31108 | |||
| 31109 | # For custom tasks, check that $customName doesn't already exist | ||
| 31110 | } elsif ( | ||
| 31111 | $taskType eq 'custom' | ||
| 31112 | && $axmud::CLIENT->ivExists('customTaskHash', $customName) | ||
| 31113 | ) { | ||
| 31114 | return $session->writeError( | ||
| 31115 | 'Can\'t create new custom task because \'' . $customName . '\' is already being' | ||
| 31116 | . ' used', | ||
| 31117 | $class . '->new', | ||
| 31118 | ); | ||
| 31119 | |||
| 31120 | } elsif ($taskType ne 'current' && $taskType ne 'initial' && $taskType ne 'custom') { | ||
| 31121 | |||
| 31122 | return $session->writeError( | ||
| 31123 | 'Can\'t create new task because \'' . $taskType . '\' is an invalid tasklist', | ||
| 31124 | $class . '->new', | ||
| 31125 | ); | ||
| 31126 | } | ||
| 31127 | } | ||
| 31128 | |||
| 31129 | # Task settings | ||
| 31130 | my $self = Games::Axmud::Generic::Task->new( | ||
| 31131 | $session, | ||
| 31132 | $taskType, | ||
| 31133 | $profName, | ||
| 31134 | $profCategory, | ||
| 31135 | $customName, | ||
| 31136 | ); | ||
| 31137 | |||
| 31138 | $self->{_objName} = 'raw_text_task'; | ||
| 31139 | $self->{_objClass} = $class; | ||
| 31140 | $self->{_parentFile} = undef; # Set below | ||
| 31141 | $self->{_parentWorld} = undef; # Set below | ||
| 31142 | $self->{_privFlag} = TRUE, # All IVs are private | ||
| 31143 | |||
| 31144 | $self->{name} = 'raw_text_task'; | ||
| 31145 | $self->{prettyName} = 'RawText'; | ||
| 31146 | $self->{shortName} = 'RT'; | ||
| 31147 | $self->{shortCutIV} = 'rawTextTask'; # Axmud built-in jealous task | ||
| 31148 | |||
| 31149 | $self->{category} = 'activity'; | ||
| 31150 | $self->{descrip} = 'Displays all incoming text, including escape sequences'; | ||
| 31151 | $self->{jealousyFlag} = TRUE; | ||
| 31152 | $self->{requireLocatorFlag} = FALSE; | ||
| 31153 | $self->{profSensitivityFlag} = FALSE; | ||
| 31154 | $self->{storableFlag} = TRUE; | ||
| 31155 | $self->{delayTime} = 0; | ||
| 31156 | $self->{allowWinFlag} = TRUE; | ||
| 31157 | $self->{requireWinFlag} = TRUE; | ||
| 31158 | $self->{startWithWinFlag} = TRUE; | ||
| 31159 | $self->{winPreferList} = ['pane', 'grid']; | ||
| 31160 | $self->{winmap} = 'basic_fill'; | ||
| 31161 | $self->{winUpdateFunc} = undef; | ||
| 31162 | $self->{tabMode} = 'simple'; | ||
| 31163 | $self->{monochromeFlag} = FALSE; | ||
| 31164 | $self->{noScrollFlag} = FALSE; | ||
| 31165 | $self->{ttsFlag} = FALSE; | ||
| 31166 | $self->{ttsConfig} = undef; | ||
| 31167 | $self->{ttsAttribHash} = {}; | ||
| 31168 | $self->{ttsFlagAttribHash} = {}; | ||
| 31169 | $self->{ttsAlertAttribHash} = {}; | ||
| 31170 | $self->{status} = 'wait_init'; | ||
| 31171 | # $self->{activeFlag} = TRUE; # Task can't be activated/disactivated | ||
| 31172 | |||
| 31173 | # Task parameters | ||
| 31174 | # (none) | ||
| 31175 | |||
| 31176 | # Bless task | ||
| 31177 | bless $self, $class; | ||
| 31178 | |||
| 31179 | # For all tasks that aren't temporary... | ||
| 31180 | if ($taskType) { | ||
| 31181 | |||
| 31182 | # Check that the task doesn't belong to a disabled plugin (in which case, it can't be | ||
| 31183 | # added to any current, initial or custom tasklist) | ||
| 31184 | if (! $self->checkPlugins()) { | ||
| 31185 | |||
| 31186 | return undef; | ||
| 31187 | } | ||
| 31188 | |||
| 31189 | # Set the parent file object | ||
| 31190 | $self->setParentFileObj($session, $taskType, $profName, $profCategory); | ||
| 31191 | |||
| 31192 | # Create entries in tasklists, if possible | ||
| 31193 | if (! $self->updateTaskLists($session)) { | ||
| 31194 | |||
| 31195 | return undef; | ||
| 31196 | } | ||
| 31197 | } | ||
| 31198 | |||
| 31199 | # Task creation complete | ||
| 31200 | return $self; | ||
| 31201 | } | ||
| 31202 | |||
| 31203 | # sub clone {} # Inherited from generic task | ||
| 31204 | |||
| 31205 | # sub preserve {} # Inherited from generic task | ||
| 31206 | |||
| 31207 | # sub setParentFileObj {} # Inherited from generic task | ||
| 31208 | |||
| 31209 | # sub updateTaskLists {} # Inherited from generic task | ||
| 31210 | |||
| 31211 | # sub ttsReadAttrib {} # Inherited from generic task | ||
| 31212 | |||
| 31213 | # sub ttsSwitchFlagAttrib {} # Inherited from generic task | ||
| 31214 | |||
| 31215 | # sub ttsSetAlertAttrib {} # Inherited from generic task | ||
| 31216 | |||
| 31217 | ################## | ||
| 31218 | # Task windows | ||
| 31219 | |||
| 31220 | # sub toggleWin {} # Inherited from generic task | ||
| 31221 | |||
| 31222 | # sub openWin {} # Inherited from generic task | ||
| 31223 | |||
| 31224 | # sub closeWin {} # Inherited from generic task | ||
| 31225 | |||
| 31226 | ################## | ||
| 31227 | # Methods | ||
| 31228 | |||
| 31229 | # sub init {} # Inherited from generic task | ||
| 31230 | |||
| 31231 | sub doInit { | ||
| 31232 | |||
| 31233 | # Called by $self->init, just before the task completes its setup ($self->init) | ||
| 31234 | # If raw text (from before the login sequence was completed) is waiting to be displayed in | ||
| 31235 | # this task's window, display it | ||
| 31236 | # | ||
| 31237 | # Expected arguments | ||
| 31238 | # (none besides $self) | ||
| 31239 | # | ||
| 31240 | # Return values | ||
| 31241 | # 'undef' on improper arguments | ||
| 31242 | # 1 otherwise | ||
| 31243 | |||
| 31244 | my ($self, $check) = @_; | ||
| 31245 | |||
| 31246 | # Local variables | ||
| 31247 | my @list; | ||
| 31248 | |||
| 31249 | # Check for improper arguments | ||
| 31250 | if (defined $check) { | ||
| 31251 | |||
| 31252 | return $axmud::CLIENT->writeImproper($self->_objClass . '->doInit', @_); | ||
| 31253 | } | ||
| 31254 | |||
| 31255 | @list = $self->session->rawTextBufferList; | ||
| 31256 | |||
| 31257 | if ($self->winObj && @list) { | ||
| 31258 | |||
| 31259 | do { | ||
| 31260 | |||
| 31261 | my ($count, $packetText); | ||
| 31262 | |||
| 31263 | $count = shift @list; | ||
| 31264 | $packetText = shift @list; | ||
| 31265 | |||
| 31266 | $self->insertText('<' . $count . '>', 'WHITE', 'ul_red', 'echo'); | ||
| 31267 | |||
| 31268 | foreach my $string (split(m/\n/, $packetText)) { | ||
| 31269 | |||
| 31270 | $self->insertText($string, 'after'); | ||
| 31271 | } | ||
| 31272 | |||
| 31273 | } until (! @list); | ||
| 31274 | } | ||
| 31275 | |||
| 31276 | $self->session->reset_rawTextBufferList(); | ||
| 31277 | |||
| 31278 | return 1; | ||
| 31279 | } | ||
| 31280 | |||
| 31281 | # sub doShutdown {} # Inherited from generic task | ||
| 31282 | |||
| 31283 | # sub doReset {} # Inherited from generic task | ||
| 31284 | |||
| 31285 | ################## | ||
| 31286 | # Response methods | ||
| 31287 | |||
| 31288 | ################## | ||
| 31289 | # Accessors - set | ||
| 31290 | |||
| 31291 | ################## | ||
| 31292 | # Accessors - task settings - get | ||
| 31293 | |||
| 31294 | # The accessors for task settings are inherited from the generic task | ||
| 31295 | |||
| 31296 | ################## | ||
| 31297 | # Accessors - task parameters - get | ||
| 31298 | } | ||
| 31299 | |||
| 31300 | { package Games::Axmud::Task::RawToken; | ||
| 31301 | |||
| 31302 | use strict; | ||
| 31303 | use warnings; | ||
| 31304 | # use diagnostics; | ||
| 31305 | |||
| 31306 | use Glib qw(TRUE FALSE); | ||
| 31307 | |||
| 31308 | our @ISA = qw(Games::Axmud::Generic::Task Games::Axmud); | ||
| 31309 | |||
| 31310 | ################## | ||
| 31311 | # Constructors | ||
| 31312 | |||
| 31313 | sub new { | ||
| 31314 | |||
| 31315 | # Creates a new instance of the RawToken task | ||
| 31316 | # | ||
| 31317 | # Expected arguments | ||
| 31318 | # $session - The parent GA::Session (not stored as an IV) | ||
| 31319 | # | ||
| 31320 | # Optional arguments | ||
| 31321 | # $taskType - Which tasklist this task is being created into - 'current' for the current | ||
| 31322 | # tasklist (tasks which are actually running now), 'initial' (tasks which | ||
| 31323 | # should be run when the user connects to the world), 'custom' (tasks with | ||
| 31324 | # customised initial parameters, which are run when the user demands). If | ||
| 31325 | # set to 'undef', this is a temporary task, created in order to access the | ||
| 31326 | # default values stored in IVs, that will not be added to any tasklist | ||
| 31327 | # $profName - ($taskType = 'current', when called by $self->clone) Name of the | ||
| 31328 | # profile from whose initial tasklist this task was created ('undef' if | ||
| 31329 | # none) | ||
| 31330 | # - ($taskType = 'initial') name of the profile in whose initial tasklist this | ||
| 31331 | # task will be. If 'undef', the global initial tasklist is used | ||
| 31332 | # - ($taskType = 'custom') 'undef' | ||
| 31333 | # $profCategory | ||
| 31334 | # - ($taskType = 'current', 'initial') which category the profile falls undef | ||
| 31335 | # (i.e. 'world', 'race', 'char', etc, or 'undef' if no profile) | ||
| 31336 | # - ($taskType = 'custom') 'undef' | ||
| 31337 | # $customName | ||
| 31338 | # - ($taskType = 'current', 'initial') 'undef' | ||
| 31339 | # - ($taskType = 'custom') the custom task name, matching a key in | ||
| 31340 | # GA::Session->customTaskHash | ||
| 31341 | # | ||
| 31342 | # Return values | ||
| 31343 | # 'undef' on improper arguments or if the task can't be added to the specified tasklist | ||
| 31344 | # Blessed reference to the newly-created object on success | ||
| 31345 | |||
| 31346 | my ($class, $session, $taskType, $profName, $profCategory, $customName, $check) = @_; | ||
| 31347 | |||
| 31348 | # Check for improper arguments | ||
| 31349 | if (! defined $class || ! defined $session || defined $check) { | ||
| 31350 | |||
| 31351 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 31352 | } | ||
| 31353 | |||
| 31354 | if ($taskType) { | ||
| 31355 | |||
| 31356 | # For initial tasks, check that $profName exists | ||
| 31357 | if ( | ||
| 31358 | $taskType eq 'initial' | ||
| 31359 | && defined $profName | ||
| 31360 | && ! $session->ivExists('profHash', $profName) | ||
| 31361 | ) { | ||
| 31362 | return $session->writeError( | ||
| 31363 | 'Can\'t create new task because \'' . $profName . '\' profile doesn\'t exist', | ||
| 31364 | $class . '->new', | ||
| 31365 | ); | ||
| 31366 | |||
| 31367 | # For custom tasks, check that $customName doesn't already exist | ||
| 31368 | } elsif ( | ||
| 31369 | $taskType eq 'custom' | ||
| 31370 | && $axmud::CLIENT->ivExists('customTaskHash', $customName) | ||
| 31371 | ) { | ||
| 31372 | return $session->writeError( | ||
| 31373 | 'Can\'t create new custom task because \'' . $customName . '\' is already being' | ||
| 31374 | . ' used', | ||
| 31375 | $class . '->new', | ||
| 31376 | ); | ||
| 31377 | |||
| 31378 | } elsif ($taskType ne 'current' && $taskType ne 'initial' && $taskType ne 'custom') { | ||
| 31379 | |||
| 31380 | return $session->writeError( | ||
| 31381 | 'Can\'t create new task because \'' . $taskType . '\' is an invalid tasklist', | ||
| 31382 | $class . '->new', | ||
| 31383 | ); | ||
| 31384 | } | ||
| 31385 | } | ||
| 31386 | |||
| 31387 | # Task settings | ||
| 31388 | my $self = Games::Axmud::Generic::Task->new( | ||
| 31389 | $session, | ||
| 31390 | $taskType, | ||
| 31391 | $profName, | ||
| 31392 | $profCategory, | ||
| 31393 | $customName, | ||
| 31394 | ); | ||
| 31395 | |||
| 31396 | $self->{_objName} = 'raw_token_task'; | ||
| 31397 | $self->{_objClass} = $class; | ||
| 31398 | $self->{_parentFile} = undef; # Set below | ||
| 31399 | $self->{_parentWorld} = undef; # Set below | ||
| 31400 | $self->{_privFlag} = TRUE, # All IVs are private | ||
| 31401 | |||
| 31402 | $self->{name} = 'raw_token_task'; | ||
| 31403 | $self->{prettyName} = 'RawToken'; | ||
| 31404 | $self->{shortName} = 'Rn'; | ||
| 31405 | $self->{shortCutIV} = 'rawTokenTask'; # Axmud built-in jealous task | ||
| 31406 | |||
| 31407 | $self->{category} = 'activity'; | ||
| 31408 | $self->{descrip} = 'Displays all incoming text, split into tokens'; | ||
| 31409 | $self->{jealousyFlag} = TRUE; | ||
| 31410 | $self->{requireLocatorFlag} = FALSE; | ||
| 31411 | $self->{profSensitivityFlag} = FALSE; | ||
| 31412 | $self->{storableFlag} = TRUE; | ||
| 31413 | $self->{delayTime} = 0; | ||
| 31414 | $self->{allowWinFlag} = TRUE; | ||
| 31415 | $self->{requireWinFlag} = TRUE; | ||
| 31416 | $self->{startWithWinFlag} = TRUE; | ||
| 31417 | $self->{winPreferList} = ['pane', 'grid']; | ||
| 31418 | $self->{winmap} = 'basic_fill'; | ||
| 31419 | $self->{winUpdateFunc} = undef; | ||
| 31420 | $self->{tabMode} = 'simple'; | ||
| 31421 | $self->{monochromeFlag} = FALSE; | ||
| 31422 | $self->{noScrollFlag} = FALSE; | ||
| 31423 | $self->{ttsFlag} = FALSE; | ||
| 31424 | $self->{ttsConfig} = undef; | ||
| 31425 | $self->{ttsAttribHash} = {}; | ||
| 31426 | $self->{ttsFlagAttribHash} = {}; | ||
| 31427 | $self->{ttsAlertAttribHash} = {}; | ||
| 31428 | $self->{status} = 'wait_init'; | ||
| 31429 | # $self->{activeFlag} = TRUE; # Task can't be activated/disactivated | ||
| 31430 | |||
| 31431 | # Task parameters | ||
| 31432 | # If TRUE, tokens are displayed one-per-line. If FALSE, tokens are displayed in their real | ||
| 31433 | # lines (i.e., a new line is started after a newline token is displayed) | ||
| 31434 | $self->{splitLineFlag} = FALSE; | ||
| 31435 | # If TRUE, the token type is displayed alongside the token itself. If FALSE, only the token | ||
| 31436 | # is displayed | ||
| 31437 | $self->{showTypeFlag} = FALSE; | ||
| 31438 | # If TRUE, the packet number is displayed. If FALSE, it's not displayed | ||
| 31439 | $self->{countPacketFlag} = FALSE; | ||
| 31440 | |||
| 31441 | # Bless task | ||
| 31442 | bless $self, $class; | ||
| 31443 | |||
| 31444 | # For all tasks that aren't temporary... | ||
| 31445 | if ($taskType) { | ||
| 31446 | |||
| 31447 | # Check that the task doesn't belong to a disabled plugin (in which case, it can't be | ||
| 31448 | # added to any current, initial or custom tasklist) | ||
| 31449 | if (! $self->checkPlugins()) { | ||
| 31450 | |||
| 31451 | return undef; | ||
| 31452 | } | ||
| 31453 | |||
| 31454 | # Set the parent file object | ||
| 31455 | $self->setParentFileObj($session, $taskType, $profName, $profCategory); | ||
| 31456 | |||
| 31457 | # Create entries in tasklists, if possible | ||
| 31458 | if (! $self->updateTaskLists($session)) { | ||
| 31459 | |||
| 31460 | return undef; | ||
| 31461 | } | ||
| 31462 | } | ||
| 31463 | |||
| 31464 | # Task creation complete | ||
| 31465 | return $self; | ||
| 31466 | } | ||
| 31467 | |||
| 31468 | sub clone { | ||
| 31469 | |||
| 31470 | # Create a clone of an existing task | ||
| 31471 | # Usually used upon connection to a world, when every task in the initial tasklists must | ||
| 31472 | # be cloned into a new object, representing a task in the current tasklist | ||
| 31473 | # (Also used when cloning a profile object, since all the tasks in its initial tasklist must | ||
| 31474 | # also be cloned) | ||
| 31475 | # | ||
| 31476 | # Expected arguments | ||
| 31477 | # $session - The parent GA::Session (not stored as an IV) | ||
| 31478 | # $taskType - Which tasklist this task is being created into - 'current' for the current | ||
| 31479 | # tasklist (tasks which are actually running now), 'initial' (tasks which | ||
| 31480 | # should be run when the user connects to the world). Custom tasks aren't | ||
| 31481 | # cloned (at the moment) | ||
| 31482 | # | ||
| 31483 | # Optional arguments | ||
| 31484 | # $profName - ($taskType = 'initial') name of the profile in whose initial tasklist the | ||
| 31485 | # existing task is stored | ||
| 31486 | # $profCategory | ||
| 31487 | # - ($taskType = 'initial') which category the profile falls under (i.e. | ||
| 31488 | # 'world', 'race', 'char', etc) | ||
| 31489 | # | ||
| 31490 | # Return values | ||
| 31491 | # 'undef' on improper arguments or if the task can't be cloned | ||
| 31492 | # Blessed reference to the newly-created object on success | ||
| 31493 | |||
| 31494 | my ($self, $session, $taskType, $profName, $profCategory, $check) = @_; | ||
| 31495 | |||
| 31496 | # Check for improper arguments | ||
| 31497 | if ( | ||
| 31498 | ! defined $session || ! defined $taskType || defined $check | ||
| 31499 | || ($taskType ne 'current' && $taskType ne 'initial') | ||
| 31500 | || ($taskType eq 'initial' && (! defined $profName || ! defined $profCategory)) | ||
| 31501 | ) { | ||
| 31502 | return $axmud::CLIENT->writeImproper($self->_objClass . '->clone', @_); | ||
| 31503 | } | ||
| 31504 | |||
| 31505 | # For initial tasks, check that $profName exists | ||
| 31506 | if ( | ||
| 31507 | $taskType eq 'initial' | ||
| 31508 | && defined $profName | ||
| 31509 | && ! $session->ivExists('profHash', $profName) | ||
| 31510 | ) { | ||
| 31511 | return $axmud::CLIENT->writeError( | ||
| 31512 | 'Can\'t create cloned task because \'' . $profName . '\' profile doesn\'t exist', | ||
| 31513 | $self->_objClass . '->clone', | ||
| 31514 | ); | ||
| 31515 | } | ||
| 31516 | |||
| 31517 | # Check that the task doesn't belong to a disabled plugin (in which case, it can't be | ||
| 31518 | # cloned) | ||
| 31519 | if (! $self->checkPlugins()) { | ||
| 31520 | |||
| 31521 | return undef; | ||
| 31522 | } | ||
| 31523 | |||
| 31524 | # Create the new task, using default settings and parameters | ||
| 31525 | my $clone = $self->_objClass->new($session, $taskType, $profName, $profCategory); | ||
| 31526 | |||
| 31527 | # Most of the cloned task's settings have default values, but a few are copied from the | ||
| 31528 | # original | ||
| 31529 | $self->cloneTaskSettings($clone); | ||
| 31530 | |||
| 31531 | # Give the new (cloned) task the same initial parameters as the original one | ||
| 31532 | $clone->{splitLineFlag} = $self->splitLineFlag; | ||
| 31533 | $clone->{showTypeFlag} = $self->showTypeFlag; | ||
| 31534 | $clone->{countPacketFlag} = $self->countPacketFlag; | ||
| 31535 | |||
| 31536 | # Cloning complete | ||
| 31537 | return $clone; | ||
| 31538 | } | ||
| 31539 | |||
| 31540 | sub preserve { | ||
| 31541 | |||
| 31542 | # Called by $self->main whenever this task is reset, in order to preserve some if its task | ||
| 31543 | # parameters (but not necessarily all of them) | ||
| 31544 | # | ||
| 31545 | # Expected arguments | ||
| 31546 | # $newTask - The new task which has been created, to which some of this task's instance | ||
| 31547 | # variables might have to be transferred | ||
| 31548 | # | ||
| 31549 | # Return values | ||
| 31550 | # 'undef' on improper arguments, or if $newTask isn't in the GA::Session's current | ||
| 31551 | # tasklist | ||
| 31552 | # 1 on success | ||
| 31553 | |||
| 31554 | my ($self, $newTask, $check) = @_; | ||
| 31555 | |||
| 31556 | # Check for improper arguments | ||
| 31557 | if (! defined $newTask || defined $check) { | ||
| 31558 | |||
| 31559 | return $axmud::CLIENT->writeImproper($self->_objClass . '->preserve', @_); | ||
| 31560 | } | ||
| 31561 | |||
| 31562 | # Check the task is in the current tasklist | ||
| 31563 | if (! $self->session->ivExists('currentTaskHash', $newTask->uniqueName)) { | ||
| 31564 | |||
| 31565 | return $self->writeWarning( | ||
| 31566 | '\'' . $self->uniqueName . '\' task missing from the current tasklist', | ||
| 31567 | $self->_objClass . '->preserve', | ||
| 31568 | ); | ||
| 31569 | } | ||
| 31570 | |||
| 31571 | # Preserve some task parameters (the others are left with their default settings, some of | ||
| 31572 | # which will be re-initialised in stage 2) | ||
| 31573 | |||
| 31574 | # Preserve the display flags | ||
| 31575 | $newTask->ivPoke('splitLineFlag', $self->splitLineFlag); | ||
| 31576 | $newTask->ivPoke('showTypeFlag', $self->showTypeFlag); | ||
| 31577 | $newTask->ivPoke('countPacketFlag', $self->countPacketFlag); | ||
| 31578 | |||
| 31579 | return 1; | ||
| 31580 | } | ||
| 31581 | |||
| 31582 | # sub setParentFileObj {} # Inherited from generic task | ||
| 31583 | |||
| 31584 | # sub ttsReadAttrib {} # Inherited from generic task | ||
| 31585 | |||
| 31586 | # sub ttsSwitchFlagAttrib {} # Inherited from generic task | ||
| 31587 | |||
| 31588 | # sub ttsSetAlertAttrib {} # Inherited from generic task | ||
| 31589 | |||
| 31590 | ################## | ||
| 31591 | # Task windows | ||
| 31592 | |||
| 31593 | # sub toggleWin {} # Inherited from generic task | ||
| 31594 | |||
| 31595 | # sub openWin {} # Inherited from generic task | ||
| 31596 | |||
| 31597 | # sub closeWin {} # Inherited from generic task | ||
| 31598 | |||
| 31599 | ################## | ||
| 31600 | # Methods | ||
| 31601 | |||
| 31602 | # sub init {} # Inherited from generic task | ||
| 31603 | |||
| 31604 | sub doInit { | ||
| 31605 | |||
| 31606 | # Called by $self->init, just before the task completes its setup ($self->init) | ||
| 31607 | # If raw tokens (from before the login sequence was completed) are waiting to be displayed | ||
| 31608 | # in this task's window, display them | ||
| 31609 | # | ||
| 31610 | # Expected arguments | ||
| 31611 | # (none besides $self) | ||
| 31612 | # | ||
| 31613 | # Return values | ||
| 31614 | # 'undef' on improper arguments | ||
| 31615 | # 1 otherwise | ||
| 31616 | |||
| 31617 | my ($self, $check) = @_; | ||
| 31618 | |||
| 31619 | # Local variables | ||
| 31620 | my ( | ||
| 31621 | $newlineFlag, | ||
| 31622 | @list, | ||
| 31623 | ); | ||
| 31624 | |||
| 31625 | # Check for improper arguments | ||
| 31626 | if (defined $check) { | ||
| 31627 | |||
| 31628 | return $axmud::CLIENT->writeImproper($self->_objClass . '->doInit', @_); | ||
| 31629 | } | ||
| 31630 | |||
| 31631 | @list = $self->session->rawTokenBufferList; | ||
| 31632 | $newlineFlag = FALSE; | ||
| 31633 | |||
| 31634 | if ($self->winObj && @list) { | ||
| 31635 | |||
| 31636 | do { | ||
| 31637 | |||
| 31638 | my ($count, $listRef); | ||
| 31639 | |||
| 31640 | $count = shift @list; | ||
| 31641 | $listRef = shift @list; | ||
| 31642 | |||
| 31643 | if ($self->countPacketFlag) { | ||
| 31644 | |||
| 31645 | $self->insertText('<' . $count . '>', 'WHITE', 'ul_red'); | ||
| 31646 | } | ||
| 31647 | |||
| 31648 | if (@$listRef) { | ||
| 31649 | |||
| 31650 | # @$listRef is in the form (type, argument, type, argument...) where | ||
| 31651 | # 'argument' is usually the token itself | ||
| 31652 | do { | ||
| 31653 | |||
| 31654 | $newlineFlag = $self->displayRawToken( | ||
| 31655 | shift @$listRef, | ||
| 31656 | shift @$listRef, | ||
| 31657 | $newlineFlag, | ||
| 31658 | ); | ||
| 31659 | |||
| 31660 | } until (! @$listRef); | ||
| 31661 | } | ||
| 31662 | |||
| 31663 | } until (! @list); | ||
| 31664 | } | ||
| 31665 | |||
| 31666 | $self->session->reset_rawTokenBufferList(); | ||
| 31667 | |||
| 31668 | return 1; | ||
| 31669 | } | ||
| 31670 | |||
| 31671 | # sub doShutdown {} # Inherited from generic task | ||
| 31672 | |||
| 31673 | # sub doReset {} # Inherited from generic task | ||
| 31674 | |||
| 31675 | sub displayRawToken { | ||
| 31676 | |||
| 31677 | # Called by GA::Session->displayRawIncomingData to display a single raw token | ||
| 31678 | # Also called by $self->doInit | ||
| 31679 | # | ||
| 31680 | # Expected arguments | ||
| 31681 | # $type - The token type | ||
| 31682 | # $arg - Usually the contents of the token itself (but might also be a list | ||
| 31683 | # reference) | ||
| 31684 | # $newlineFlag - A value preserved between successive calls to this function | ||
| 31685 | # | ||
| 31686 | # Return values | ||
| 31687 | # 'undef' on improper arguments | ||
| 31688 | # Otherwise returns the new value of $newlineFlag (TRUE or FALSE), ready for the next call | ||
| 31689 | # to this function | ||
| 31690 | |||
| 31691 | my ($self, $type, $arg, $newlineFlag, $check) = @_; | ||
| 31692 | |||
| 31693 | # Local variables | ||
| 31694 | my ( | ||
| 31695 | $colour, $listRef, $listRef2, | ||
| 31696 | @argList, | ||
| 31697 | ); | ||
| 31698 | |||
| 31699 | # Check for improper arguments | ||
| 31700 | if (! defined $type || ! defined $arg || defined $check) { | ||
| 31701 | |||
| 31702 | return $axmud::CLIENT->writeImproper($self->_objClass . '->displayRawToken', @_); | ||
| 31703 | } | ||
| 31704 | |||
| 31705 | $colour = $self->session->ivShow('constRawHash', $type); | ||
| 31706 | |||
| 31707 | if ($self->showTypeFlag) { | ||
| 31708 | |||
| 31709 | push (@argList, | ||
| 31710 | '[' . $type . ']', | ||
| 31711 | [ | ||
| 31712 | 'RED', | ||
| 31713 | ], | ||
| 31714 | ); | ||
| 31715 | } | ||
| 31716 | |||
| 31717 | # If $type is 'ctrl' or 'seq', then $arg is a reference to a list; otherwise it's a token | ||
| 31718 | if ($type eq 'ctrl' || $type eq 'seq') { | ||
| 31719 | |||
| 31720 | push (@argList, | ||
| 31721 | $$arg[0], | ||
| 31722 | [ | ||
| 31723 | $colour, | ||
| 31724 | ], | ||
| 31725 | ); | ||
| 31726 | |||
| 31727 | } elsif ($type eq 'nl') { | ||
| 31728 | |||
| 31729 | push (@argList, | ||
| 31730 | 'NEWLINE', | ||
| 31731 | [ | ||
| 31732 | $colour, | ||
| 31733 | ], | ||
| 31734 | ); | ||
| 31735 | |||
| 31736 | } elsif ($type eq 'ga') { | ||
| 31737 | |||
| 31738 | push (@argList, | ||
| 31739 | 'GOAHEAD', | ||
| 31740 | [ | ||
| 31741 | $colour, | ||
| 31742 | ], | ||
| 31743 | ); | ||
| 31744 | |||
| 31745 | } else { | ||
| 31746 | |||
| 31747 | push (@argList, | ||
| 31748 | $arg, | ||
| 31749 | [ | ||
| 31750 | $colour, | ||
| 31751 | ], | ||
| 31752 | ); | ||
| 31753 | } | ||
| 31754 | |||
| 31755 | if (! $newlineFlag) { | ||
| 31756 | |||
| 31757 | $listRef = $argList[1]; | ||
| 31758 | push (@$listRef, 'echo'); | ||
| 31759 | |||
| 31760 | } else { | ||
| 31761 | |||
| 31762 | $newlineFlag = FALSE; | ||
| 31763 | } | ||
| 31764 | |||
| 31765 | # If the token type is displayed, must display the second string on the same line as the | ||
| 31766 | # first | ||
| 31767 | $listRef2 = $argList[3]; | ||
| 31768 | if (defined $listRef2) { | ||
| 31769 | |||
| 31770 | push (@$listRef2, 'echo'); | ||
| 31771 | } | ||
| 31772 | |||
| 31773 | # If a newline token has just been displayed, don't add 'echo' on the next iteration of the | ||
| 31774 | # calling function's do loop | ||
| 31775 | if ($type eq 'nl') { | ||
| 31776 | |||
| 31777 | $newlineFlag = TRUE; | ||
| 31778 | } | ||
| 31779 | |||
| 31780 | # Display this token in the task window | ||
| 31781 | $self->insertMultipleText(@argList); | ||
| 31782 | |||
| 31783 | return $newlineFlag; | ||
| 31784 | } | ||
| 31785 | |||
| 31786 | ################## | ||
| 31787 | # Response methods | ||
| 31788 | |||
| 31789 | ################## | ||
| 31790 | # Accessors - set | ||
| 31791 | |||
| 31792 | ################## | ||
| 31793 | # Accessors - task settings - get | ||
| 31794 | |||
| 31795 | # The accessors for task settings are inherited from the generic task | ||
| 31796 | |||
| 31797 | ################## | ||
| 31798 | # Accessors - task parameters - get | ||
| 31799 | |||
| 31800 | sub splitLineFlag | ||
| 31801 | { $_[0]->{splitLineFlag} } | ||
| 31802 | sub showTypeFlag | ||
| 31803 | { $_[0]->{showTypeFlag} } | ||
| 31804 | sub countPacketFlag | ||
| 31805 | { $_[0]->{countPacketFlag} } | ||
| 31806 | } | ||
| 31807 | |||
| 31808 | { package Games::Axmud::Task::Script; | ||
| 31809 | |||
| 31810 | use strict; | ||
| 31811 | use warnings; | ||
| 31812 | # use diagnostics; | ||
| 31813 | |||
| 31814 | use Glib qw(TRUE FALSE); | ||
| 31815 | |||
| 31816 | our @ISA = qw(Games::Axmud::Generic::Task Games::Axmud); | ||
| 31817 | |||
| 31818 | ################## | ||
| 31819 | # Constructors | ||
| 31820 | |||
| 31821 | sub new { | ||
| 31822 | |||
| 31823 | # Creates a new instances of the Script task | ||
| 31824 | # | ||
| 31825 | # Expected arguments | ||
| 31826 | # $session - The parent GA::Session (not stored as an IV) | ||
| 31827 | # | ||
| 31828 | # Optional arguments | ||
| 31829 | # $taskType - Which tasklist this task is being created into - 'current' for the current | ||
| 31830 | # tasklist (tasks which are actually running now), 'initial' (tasks which | ||
| 31831 | # should be run when the user connects to the world), 'custom' (tasks with | ||
| 31832 | # customised initial parameters, which are run when the user demands). If | ||
| 31833 | # set to 'undef', this is a temporary task, created in order to access the | ||
| 31834 | # default values stored in IVs, that will not be added to any tasklist | ||
| 31835 | # $profName - ($taskType = 'current', when called by $self->clone) Name of the | ||
| 31836 | # profile from whose initial tasklist this task was created ('undef' if | ||
| 31837 | # none) | ||
| 31838 | # - ($taskType = 'initial') name of the profile in whose initial tasklist this | ||
| 31839 | # task will be. If 'undef', the global initial tasklist is used | ||
| 31840 | # - ($taskType = 'custom') 'undef' | ||
| 31841 | # $profCategory | ||
| 31842 | # - ($taskType = 'current', 'initial') which category the profile falls undef | ||
| 31843 | # (i.e. 'world', 'race', 'char', etc, or 'undef' if no profile) | ||
| 31844 | # - ($taskType = 'custom') 'undef' | ||
| 31845 | # $customName | ||
| 31846 | # - ($taskType = 'current', 'initial') 'undef' | ||
| 31847 | # - ($taskType = 'custom') the custom task name, matching a key in | ||
| 31848 | # GA::Session->customTaskHash | ||
| 31849 | # | ||
| 31850 | # Return values | ||
| 31851 | # 'undef' on improper arguments or if the task can't be added to the specified tasklist | ||
| 31852 | # Blessed reference to the newly-created object on success | ||
| 31853 | |||
| 31854 | my ($class, $session, $taskType, $profName, $profCategory, $customName, $check) = @_; | ||
| 31855 | |||
| 31856 | # Check for improper arguments | ||
| 31857 | if (! defined $class || ! defined $session || defined $check) { | ||
| 31858 | |||
| 31859 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 31860 | } | ||
| 31861 | |||
| 31862 | if ($taskType) { | ||
| 31863 | |||
| 31864 | # For initial tasks, check that $profName exists | ||
| 31865 | if ( | ||
| 31866 | $taskType eq 'initial' | ||
| 31867 | && defined $profName | ||
| 31868 | && ! $session->ivExists('profHash', $profName) | ||
| 31869 | ) { | ||
| 31870 | return $session->writeError( | ||
| 31871 | 'Can\'t create new task because \'' . $profName . '\' profile doesn\'t exist', | ||
| 31872 | $class . '->new', | ||
| 31873 | ); | ||
| 31874 | |||
| 31875 | # For custom tasks, check that $customName doesn't already exist | ||
| 31876 | } elsif ( | ||
| 31877 | $taskType eq 'custom' | ||
| 31878 | && $axmud::CLIENT->ivExists('customTaskHash', $customName) | ||
| 31879 | ) { | ||
| 31880 | return $session->writeError( | ||
| 31881 | 'Can\'t create new custom task because \'' . $customName . '\' is already being' | ||
| 31882 | . ' used', | ||
| 31883 | $class . '->new', | ||
| 31884 | ); | ||
| 31885 | |||
| 31886 | } elsif ($taskType ne 'current' && $taskType ne 'initial' && $taskType ne 'custom') { | ||
| 31887 | |||
| 31888 | return $session->writeError( | ||
| 31889 | 'Can\'t create new task because \'' . $taskType . '\' is an invalid tasklist', | ||
| 31890 | $class . '->new', | ||
| 31891 | ); | ||
| 31892 | } | ||
| 31893 | } | ||
| 31894 | |||
| 31895 | # Task settings | ||
| 31896 | my $self = Games::Axmud::Generic::Task->new( | ||
| 31897 | $session, | ||
| 31898 | $taskType, | ||
| 31899 | $profName, | ||
| 31900 | $profCategory, | ||
| 31901 | $customName, | ||
| 31902 | ); | ||
| 31903 | |||
| 31904 | $self->{_objName} = 'script_task'; | ||
| 31905 | $self->{_objClass} = $class; | ||
| 31906 | $self->{_parentFile} = undef; # Set below | ||
| 31907 | $self->{_parentWorld} = undef; # Set below | ||
| 31908 | $self->{_privFlag} = TRUE, # All IVs are private | ||
| 31909 | |||
| 31910 | $self->{name} = 'script_task'; | ||
| 31911 | $self->{prettyName} = 'Script'; | ||
| 31912 | $self->{shortName} = 'Sc'; | ||
| 31913 | $self->{shortCutIV} = undef; # Built-in task, but not jealous | ||
| 31914 | |||
| 31915 | $self->{category} = 'process'; | ||
| 31916 | $self->{descrip} = 'Runs ' . $axmud::BASIC_ARTICLE . ' script as a task'; | ||
| 31917 | $self->{jealousyFlag} = FALSE; | ||
| 31918 | $self->{requireLocatorFlag} = FALSE; | ||
| 31919 | $self->{profSensitivityFlag} = FALSE; | ||
| 31920 | $self->{storableFlag} = FALSE; | ||
| 31921 | $self->{delayTime} = 0; | ||
| 31922 | $self->{allowWinFlag} = TRUE; | ||
| 31923 | $self->{requireWinFlag} = FALSE; | ||
| 31924 | $self->{startWithWinFlag} = FALSE; | ||
| 31925 | $self->{winPreferList} = ['entry', 'grid']; | ||
| 31926 | $self->{winmap} = 'entry_fill'; | ||
| 31927 | $self->{winUpdateFunc} = undef; | ||
| 31928 | $self->{tabMode} = 'simple'; | ||
| 31929 | $self->{monochromeFlag} = FALSE; | ||
| 31930 | $self->{noScrollFlag} = FALSE; | ||
| 31931 | $self->{ttsFlag} = FALSE; | ||
| 31932 | $self->{ttsConfig} = undef; | ||
| 31933 | $self->{ttsAttribHash} = {}; | ||
| 31934 | $self->{ttsFlagAttribHash} = {}; | ||
| 31935 | $self->{ttsAlertAttribHash} = {}; | ||
| 31936 | $self->{status} = 'wait_init'; | ||
| 31937 | # $self->{activeFlag} = TRUE; # Task can't be activated/disactivated | ||
| 31938 | |||
| 31939 | # Task parameters | ||
| 31940 | # | ||
| 31941 | # How many steps the Axbasic script can complete, before returning control to this task | ||
| 31942 | # (if set to 0, the script runs until it encounteres a PAUSE, BREAK or END statement. | ||
| 31943 | # Otherwise, control is eventually returned to this task, and the script resumes | ||
| 31944 | # execution on the next task loop) | ||
| 31945 | $self->{stepMax} = 100; | ||
| 31946 | # The name of the Axbasic script to run (e.g. 'test'); after calling $self->new, the calling | ||
| 31947 | # function must call $self->set_scriptName to set it | ||
| 31948 | $self->{scriptName} = undef; | ||
| 31949 | # The corresponding AB::Script | ||
| 31950 | $self->{scriptObj} = undef; | ||
| 31951 | |||
| 31952 | # When statements like WAITTRIG are executed, the name of the active interface that we're | ||
| 31953 | # waiting for. When the interface fires (or the timeout occurs), this IV is reset to | ||
| 31954 | # 'undef' | ||
| 31955 | $self->{waitForInterface} = undef; | ||
| 31956 | # When statements like WAITHP are executed, details about which task and which statistic | ||
| 31957 | # we're waiting for. These values are set by a call to $self->setUpMonitoring() | ||
| 31958 | # The task to monitor ('locator', 'status' or 'task' for a new task that's been created by | ||
| 31959 | # the Axbasic script; 'undef' if not waiting for a task) | ||
| 31960 | $self->{monitorTask} = undef; | ||
| 31961 | # The statistic, stored by that task, to monitor | ||
| 31962 | $self->{monitorStatistic} = undef; | ||
| 31963 | # The minimum value that the statistic should reach before resuming the Axbasic script; a | ||
| 31964 | # percentage value in the range 0-100 (not necessary for every statement which sets up | ||
| 31965 | # monitoring) | ||
| 31966 | $self->{monitorTarget} = undef; | ||
| 31967 | # An optional timeout, in seconds, after which the Axbasic script resumes execution anyway | ||
| 31968 | $self->{monitorTimeOut} = undef; | ||
| 31969 | |||
| 31970 | # When the ADDGAUGE statement is executed, this task creates 'main' window gauges (each | ||
| 31971 | # controlled by a GA::Obj::Gauge object) | ||
| 31972 | # All of this task's gauges are displayed on the same gauge level, exclusive to the task, | ||
| 31973 | # which is created if it doesn't exist | ||
| 31974 | # Shortcut to the strip object (GA::Strip::GaugeBox) which handles gauges in this session's | ||
| 31975 | # 'main' window; set whenever this task adds it first gauge | ||
| 31976 | $self->{gaugeStripObj} = undef; | ||
| 31977 | # The unique number of the gauge level object for this task (matches a key in | ||
| 31978 | # GA::Strip::GaugeBox->gaugeLevelHash). Set to 'undef' if this task currently has no | ||
| 31979 | # gauges | ||
| 31980 | $self->{gaugeLevel} = undef; | ||
| 31981 | # A hash of gauges created by ADDGAUGE and ADDCONGAUGE statements. Hash in the form | ||
| 31982 | # $gaugeHash{unique_number} = gauge_object | ||
| 31983 | # ...where 'unique_number' is the gauge number specified by the ADDGAUGE/ADDCONGAUGE | ||
| 31984 | # statement (not related to GA::Obj::Gauge->number) and 'gauge_object' is the | ||
| 31985 | # corresponding GA::Obj::Gauge object | ||
| 31986 | $self->{gaugeHash} = {}; | ||
| 31987 | # A hash of status bars created by ADDSTATUS and ADDCONSTATUS statements. Status bars are | ||
| 31988 | # displayed in the 'main' window's gauge box, in exactly the same way as gauges, except | ||
| 31989 | # that unlike gauges, they are drawn as text only. Hash in the form | ||
| 31990 | # $statusBarHash{unique_number} = gauge_object | ||
| 31991 | # ...where 'unique_number' is the status bar number specified by the ADDSTATUS/ | ||
| 31992 | # ADDCONSTATUS statement (not related to GA::Obj::Gauge->number, or the gauge numbers used | ||
| 31993 | # as keys in $self->gaugeHash) and 'gauge_object' is the corresponding GA::Obj::Gauge | ||
| 31994 | # object | ||
| 31995 | $self->{statusBarHash} = {}; | ||
| 31996 | |||
| 31997 | # The equivalent IVs for the WINADDGAUGE and WINADDCONGAUGE statements, for gauges in the | ||
| 31998 | # task window | ||
| 31999 | $self->{taskWinGaugeStripObj} = undef; | ||
| 32000 | $self->{taskWinGaugeLevel} = undef; | ||
| 32001 | $self->{taskWinGaugeHash} = {}; | ||
| 32002 | $self->{taskWinStatusBarHash} = {}; | ||
| 32003 | |||
| 32004 | # Flag set to TRUE when this task is started with ;runscripttask -w (set to FALSE otherwise) | ||
| 32005 | # In 'forced window' mode, the task opens an 'entry' task window before starting to execute | ||
| 32006 | # the script. Then, it notifies the AB::Script that output from all PRINT statements must | ||
| 32007 | # be diverted to the window. This allows the user to run old BASIC scripts - which | ||
| 32008 | # obviously don't know how to open Axmud task windows - in their own window, away from the | ||
| 32009 | # 'main' window | ||
| 32010 | $self->{forcedWinFlag} = FALSE; | ||
| 32011 | |||
| 32012 | # Bless task | ||
| 32013 | bless $self, $class; | ||
| 32014 | |||
| 32015 | # For all tasks that aren't temporary... | ||
| 32016 | if ($taskType) { | ||
| 32017 | |||
| 32018 | # Check that the task doesn't belong to a disabled plugin (in which case, it can't be | ||
| 32019 | # added to any current, initial or custom tasklist) | ||
| 32020 | if (! $self->checkPlugins()) { | ||
| 32021 | |||
| 32022 | return undef; | ||
| 32023 | } | ||
| 32024 | |||
| 32025 | # Set the parent file object | ||
| 32026 | $self->setParentFileObj($session, $taskType, $profName, $profCategory); | ||
| 32027 | |||
| 32028 | # Create entries in tasklists, if possible | ||
| 32029 | if (! $self->updateTaskLists($session)) { | ||
| 32030 | |||
| 32031 | return undef; | ||
| 32032 | } | ||
| 32033 | } | ||
| 32034 | |||
| 32035 | # Task creation complete | ||
| 32036 | return $self; | ||
| 32037 | } | ||
| 32038 | |||
| 32039 | sub clone { | ||
| 32040 | |||
| 32041 | # Create a clone of an existing task | ||
| 32042 | # Usually used upon connection to a world, when every task in the initial tasklists must | ||
| 32043 | # be cloned into a new object, representing a task in the current tasklist | ||
| 32044 | # (Also used when cloning a profile object, since all the tasks in its initial tasklist must | ||
| 32045 | # also be cloned) | ||
| 32046 | # | ||
| 32047 | # Expected arguments | ||
| 32048 | # $session - The parent GA::Session (not stored as an IV) | ||
| 32049 | # $taskType - Which tasklist this task is being created into - 'current' for the current | ||
| 32050 | # tasklist (tasks which are actually running now), 'initial' (tasks which | ||
| 32051 | # should be run when the user connects to the world). Custom tasks aren't | ||
| 32052 | # cloned (at the moment) | ||
| 32053 | # | ||
| 32054 | # Optional arguments | ||
| 32055 | # $profName - ($taskType = 'initial') name of the profile in whose initial tasklist the | ||
| 32056 | # existing task is stored | ||
| 32057 | # $profCategory | ||
| 32058 | # - ($taskType = 'initial') which category the profile falls under (i.e. | ||
| 32059 | # 'world', 'race', 'char', etc) | ||
| 32060 | # | ||
| 32061 | # Return values | ||
| 32062 | # 'undef' on improper arguments or if the task can't be cloned | ||
| 32063 | # Blessed reference to the newly-created object on success | ||
| 32064 | |||
| 32065 | my ($self, $session, $taskType, $profName, $profCategory, $check) = @_; | ||
| 32066 | |||
| 32067 | # Check for improper arguments | ||
| 32068 | if ( | ||
| 32069 | ! defined $session || ! defined $taskType || defined $check | ||
| 32070 | || ($taskType ne 'current' && $taskType ne 'initial') | ||
| 32071 | || ($taskType eq 'initial' && (! defined $profName || ! defined $profCategory)) | ||
| 32072 | ) { | ||
| 32073 | return $axmud::CLIENT->writeImproper($self->_objClass . '->clone', @_); | ||
| 32074 | } | ||
| 32075 | |||
| 32076 | # For initial tasks, check that $profName exists | ||
| 32077 | if ( | ||
| 32078 | $taskType eq 'initial' | ||
| 32079 | && defined $profName | ||
| 32080 | && ! $session->ivExists('profHash', $profName) | ||
| 32081 | ) { | ||
| 32082 | return $axmud::CLIENT->writeError( | ||
| 32083 | 'Can\'t create cloned task because \'' . $profName . '\' profile doesn\'t exist', | ||
| 32084 | $self->_objClass . '->clone', | ||
| 32085 | ); | ||
| 32086 | } | ||
| 32087 | |||
| 32088 | # Check that the task doesn't belong to a disabled plugin (in which case, it can't be | ||
| 32089 | # cloned) | ||
| 32090 | if (! $self->checkPlugins()) { | ||
| 32091 | |||
| 32092 | return undef; | ||
| 32093 | } | ||
| 32094 | |||
| 32095 | # Create the new task, using default settings and parameters | ||
| 32096 | my $clone = $self->_objClass->new($session, $taskType, $profName, $profCategory); | ||
| 32097 | |||
| 32098 | # Most of the cloned task's settings have default values, but a few are copied from the | ||
| 32099 | # original | ||
| 32100 | $self->cloneTaskSettings($clone); | ||
| 32101 | |||
| 32102 | # Give the new (cloned) task the same initial parameters as the original one | ||
| 32103 | $clone->{stepMax} = $self->stepMax; | ||
| 32104 | $clone->{scriptName} = $self->scriptName; | ||
| 32105 | $clone->{scriptObj} = $self->scriptObj; | ||
| 32106 | |||
| 32107 | $clone->{waitForInterface} = $self->waitForInterface; | ||
| 32108 | $clone->{monitorTask} = $self->monitorTask; | ||
| 32109 | $clone->{monitorStatistic} = $self->monitorStatistic; | ||
| 32110 | $clone->{monitorTarget} = $self->monitorTarget; | ||
| 32111 | $clone->{monitorTimeOut} = $self->monitorTimeOut; | ||
| 32112 | |||
| 32113 | $clone->{gaugeStripObj} = $self->gaugeStripObj; | ||
| 32114 | $clone->{gaugeLevel} = $self->gaugeLevel; | ||
| 32115 | $clone->{gaugeHash} = {$self->gaugeHash}; | ||
| 32116 | $clone->{statusBarHash} = {$self->statusBarHash}; | ||
| 32117 | |||
| 32118 | $clone->{taskWinGaugeStripObj} = $self->taskWinGaugeStripObj; | ||
| 32119 | $clone->{taskWinGaugeLevel} = $self->taskWinGaugeLevel; | ||
| 32120 | $clone->{taskWinGaugeHash} = {$self->taskWinGaugeHash}; | ||
| 32121 | $clone->{taskWinStatusBarHash} = {$self->taskWinStatusBarHash}; | ||
| 32122 | |||
| 32123 | $clone->{forcedWinFlag} = $self->forcedWinFlag; | ||
| 32124 | |||
| 32125 | # Cloning complete | ||
| 32126 | return $clone; | ||
| 32127 | } | ||
| 32128 | |||
| 32129 | sub preserve { | ||
| 32130 | |||
| 32131 | # Called by $self->main whenever this task is reset, in order to preserve some if its task | ||
| 32132 | # parameters (but not necessarily all of them) | ||
| 32133 | # | ||
| 32134 | # Expected arguments | ||
| 32135 | # $newTask - The new task which has been created, to which some of this task's instance | ||
| 32136 | # variables might have to be transferred | ||
| 32137 | # | ||
| 32138 | # Return values | ||
| 32139 | # 'undef' on improper arguments, or if $newTask isn't in the GA::Session's current | ||
| 32140 | # tasklist | ||
| 32141 | # 1 on success | ||
| 32142 | |||
| 32143 | my ($self, $newTask, $check) = @_; | ||
| 32144 | |||
| 32145 | # Check for improper arguments | ||
| 32146 | if (! defined $newTask || defined $check) { | ||
| 32147 | |||
| 32148 | return $axmud::CLIENT->writeImproper($self->_objClass . '->preserve', @_); | ||
| 32149 | } | ||
| 32150 | |||
| 32151 | # Check the task is in the current tasklist | ||
| 32152 | if (! $self->session->ivExists('currentTaskHash', $newTask->uniqueName)) { | ||
| 32153 | |||
| 32154 | return $self->writeWarning( | ||
| 32155 | '\'' . $self->uniqueName . '\' task missing from the current tasklist', | ||
| 32156 | $self->_objClass . '->preserve', | ||
| 32157 | ); | ||
| 32158 | } | ||
| 32159 | |||
| 32160 | # Preserve some task parameters (the others are left with their default settings, some of | ||
| 32161 | # which will be re-initialised in stage 2) | ||
| 32162 | |||
| 32163 | # Preserve the maximum number of steps per task loop | ||
| 32164 | $newTask->ivPoke('stepMax', $self->stepMax); | ||
| 32165 | # Preserve the name of the Axbasic script to run (from the beginning) | ||
| 32166 | $newTask->ivPoke('scriptName', $self->scriptName); | ||
| 32167 | |||
| 32168 | # Preserve 'forced window' mode; if the old task was started with a ';runscripttask -w', the | ||
| 32169 | # new task should also be forced to open a task window | ||
| 32170 | $newTask->ivPoke('forcedWindowFlag', $self->forcedWindowFlag); | ||
| 32171 | |||
| 32172 | return 1; | ||
| 32173 | } | ||
| 32174 | |||
| 32175 | # sub setParentFileObj {} # Inherited from generic task | ||
| 32176 | |||
| 32177 | # sub updateTaskLists {} # Inherited from generic task | ||
| 32178 | |||
| 32179 | # sub ttsReadAttrib {} # Inherited from generic task | ||
| 32180 | |||
| 32181 | # sub ttsSwitchFlagAttrib {} # Inherited from generic task | ||
| 32182 | |||
| 32183 | # sub ttsSetAlertAttrib {} # Inherited from generic task | ||
| 32184 | |||
| 32185 | ################## | ||
| 32186 | # Task windows | ||
| 32187 | |||
| 32188 | # sub toggleWin {} # Inherited from generic task | ||
| 32189 | |||
| 32190 | sub openWin { | ||
| 32191 | |||
| 32192 | # Called by the task's ->main method or by its ->toggleWin method | ||
| 32193 | # Tries to open each type of task window in $self->winPreferList, halting at the first | ||
| 32194 | # successful attempt (or when all attempts fail) | ||
| 32195 | # | ||
| 32196 | # Expected arguments | ||
| 32197 | # (none besides self) | ||
| 32198 | # | ||
| 32199 | # Optional arguments | ||
| 32200 | # $winmap - The winmap to use in a 'grid' window or a pseudo-window (matches a key in | ||
| 32201 | # GA::Client->winmapHash). If 'undef', $self->winmap is used | ||
| 32202 | # @preferList - The types of task window to try to open. If not an empty list, this list | ||
| 32203 | # is used rather than $self->winPreferList | ||
| 32204 | # | ||
| 32205 | # Return values | ||
| 32206 | # 'undef' on improper arguments, if $winmap doesn't exist (when specified, checked even if | ||
| 32207 | # a 'grid' window isn't opened) or if a task window is not opened | ||
| 32208 | # 1 if a window is opened | ||
| 32209 | |||
| 32210 | my ($self, $winmap, @preferList) = @_; | ||
| 32211 | |||
| 32212 | # (No improper arguments to check) | ||
| 32213 | |||
| 32214 | # Most of the code is in the generic function | ||
| 32215 | if ($self->Games::Axmud::Generic::Task::openWin($winmap, @preferList)) { | ||
| 32216 | |||
| 32217 | # Set a customised window title | ||
| 32218 | $self->setTitle(); | ||
| 32219 | |||
| 32220 | return 1; | ||
| 32221 | |||
| 32222 | } else { | ||
| 32223 | |||
| 32224 | return undef; | ||
| 32225 | } | ||
| 32226 | } | ||
| 32227 | |||
| 32228 | # sub closeWin {} # Inherited from generic task | ||
| 32229 | |||
| 32230 | ################## | ||
| 32231 | # Methods | ||
| 32232 | |||
| 32233 | # sub main {} # Inherited from generic task | ||
| 32234 | |||
| 32235 | sub doShutdown { | ||
| 32236 | |||
| 32237 | # Called just before the task completes a shutdown | ||
| 32238 | # For process tasks, called by $self->main. For activity tasks, called by $self->shutdown | ||
| 32239 | # | ||
| 32240 | # Expected arguments | ||
| 32241 | # (none besides $self) | ||
| 32242 | # | ||
| 32243 | # Return values | ||
| 32244 | # 'undef' on improper arguments | ||
| 32245 | # 1 otherwise | ||
| 32246 | |||
| 32247 | my ($self, $check) = @_; | ||
| 32248 | |||
| 32249 | # Check for improper arguments | ||
| 32250 | if (defined $check) { | ||
| 32251 | |||
| 32252 | return $axmud::CLIENT->writeImproper($self->_objClass . '->doShutdown', @_); | ||
| 32253 | } | ||
| 32254 | |||
| 32255 | # If the Axbasic script is running, destroy any non-persistent interfaces it has created | ||
| 32256 | if (defined $self->scriptObj) { | ||
| 32257 | |||
| 32258 | $self->scriptObj->destroyOwnInterfaces(); | ||
| 32259 | } | ||
| 32260 | |||
| 32261 | # If any main wnidow gauges/status bars have been created, destroy them | ||
| 32262 | if ($self->gaugeStripObj && ($self->gaugeHash || $self->statusBarHash)) { | ||
| 32263 | |||
| 32264 | $self->gaugeStripObj->removeGauges( | ||
| 32265 | $self->session, | ||
| 32266 | FALSE, | ||
| 32267 | $self->ivValues('gaugeHash'), | ||
| 32268 | $self->ivValues('statusBarHash'), | ||
| 32269 | ); | ||
| 32270 | |||
| 32271 | $self->gaugeStripObj->removeGaugeLevel($self->session, $self->gaugeLevel); | ||
| 32272 | } | ||
| 32273 | |||
| 32274 | return 1; | ||
| 32275 | } | ||
| 32276 | |||
| 32277 | sub doReset { | ||
| 32278 | |||
| 32279 | # Called by $self->main, just before the task completes a reset | ||
| 32280 | # | ||
| 32281 | # This function does nothing, so tasks that need to do something special during a reset | ||
| 32282 | # should have their own ->doReset function | ||
| 32283 | # | ||
| 32284 | # Expected arguments | ||
| 32285 | # $newTaskObj - The replacement task object | ||
| 32286 | # | ||
| 32287 | # Return values | ||
| 32288 | # 'undef' on improper arguments | ||
| 32289 | # 1 otherwise | ||
| 32290 | |||
| 32291 | my ($self, $newTaskObj, $check) = @_; | ||
| 32292 | |||
| 32293 | # Check for improper arguments | ||
| 32294 | if (! defined $newTaskObj || defined $check) { | ||
| 32295 | |||
| 32296 | return $axmud::CLIENT->writeImproper($self->_objClass . '->doReset', @_); | ||
| 32297 | } | ||
| 32298 | |||
| 32299 | # If any main window gauges/status bars have been created, destroy them | ||
| 32300 | if ($self->gaugeStripObj && ($self->gaugeHash || $self->statusBarHash)) { | ||
| 32301 | |||
| 32302 | $self->gaugeStripObj->removeGauges( | ||
| 32303 | $self->session, | ||
| 32304 | FALSE, | ||
| 32305 | $self->ivValues('gaugeHash'), | ||
| 32306 | $self->ivValues('statusBarHash'), | ||
| 32307 | ); | ||
| 32308 | |||
| 32309 | $self->gaugeStripObj->removeGaugeLevel($self->session, $self->gaugeLevel); | ||
| 32310 | } | ||
| 32311 | |||
| 32312 | return 1; | ||
| 32313 | } | ||
| 32314 | |||
| 32315 | sub doFirstStage { | ||
| 32316 | |||
| 32317 | # Called by $self->main, just before the task completes the first stage ($self->stage) | ||
| 32318 | # In 'forced window' mode, opens an 'entry' task window | ||
| 32319 | # | ||
| 32320 | # Expected arguments | ||
| 32321 | # (none besides $self) | ||
| 32322 | # | ||
| 32323 | # Return values | ||
| 32324 | # 'undef' on improper arguments | ||
| 32325 | # 1 otherwise | ||
| 32326 | |||
| 32327 | my ($self, $check) = @_; | ||
| 32328 | |||
| 32329 | # Check for improper arguments | ||
| 32330 | if (defined $check) { | ||
| 32331 | |||
| 32332 | return $axmud::CLIENT->writeImproper($self->_objClass . '->doFirstStage', @_); | ||
| 32333 | } | ||
| 32334 | |||
| 32335 | # In 'forced window' mode, a task window must always be open (so that PRINT statements can | ||
| 32336 | # be diverted there) | ||
| 32337 | if ($self->forcedWinFlag) { | ||
| 32338 | |||
| 32339 | # A window must now be open all the time for this task | ||
| 32340 | $self->ivPoke('requireWinFlag', TRUE); | ||
| 32341 | # Open an task window with an entry box | ||
| 32342 | $self->openWin($self->winmap, 'entry_fill', 'pane', 'grid'); | ||
| 32343 | } | ||
| 32344 | |||
| 32345 | return 1; | ||
| 32346 | } | ||
| 32347 | |||
| 32348 | sub doStage { | ||
| 32349 | |||
| 32350 | # Called by $self->main to process all stages (except stage 1) | ||
| 32351 | # | ||
| 32352 | # Expected arguments | ||
| 32353 | # (none besides $self) | ||
| 32354 | # | ||
| 32355 | # Return values | ||
| 32356 | # 'undef' on improper arguments or if this function sets that task's ->status IV to | ||
| 32357 | # 'finished' or sets its ->shutdownFlag to TRUE | ||
| 32358 | # Otherwise, we normally return the new value of $self->stage | ||
| 32359 | |||
| 32360 | my ($self, $check) = @_; | ||
| 32361 | |||
| 32362 | # Check for improper arguments | ||
| 32363 | if (defined $check) { | ||
| 32364 | |||
| 32365 | return $axmud::CLIENT->writeImproper($self->_objClass . '->doStage', @_); | ||
| 32366 | } | ||
| 32367 | |||
| 32368 | if ($self->stage == 2) { | ||
| 32369 | |||
| 32370 | my ($rawObj, $standardPath, $path, $scriptObj); | ||
| 32371 | |||
| 32372 | # Quick check that the task has been supplied with an Axbasic script name | ||
| 32373 | if (! defined $self->scriptName) { | ||
| 32374 | |||
| 32375 | $self->session->writeError( | ||
| 32376 | '\'' . $self->uniqueName . '\' task : no script specified; task is halting', | ||
| 32377 | $self->_objClass . '->doStage', | ||
| 32378 | ); | ||
| 32379 | |||
| 32380 | $self->ivPoke('shutdownFlag', TRUE); | ||
| 32381 | return undef; | ||
| 32382 | } | ||
| 32383 | |||
| 32384 | # Check each directory in the GA::Client's list, looking for a file matching | ||
| 32385 | # $self->scriptName (but first check in the standard directory) | ||
| 32386 | $standardPath = $axmud::DATA_DIR . '/scripts/' . $self->scriptName . '.bas'; | ||
| 32387 | if (-e $standardPath) { | ||
| 32388 | |||
| 32389 | $path = $standardPath; | ||
| 32390 | |||
| 32391 | } else { | ||
| 32392 | |||
| 32393 | OUTER: foreach my $dir ($axmud::CLIENT->scriptDirList) { | ||
| 32394 | |||
| 32395 | my $thisPath = $dir . '/' . $self->scriptName . '.bas'; | ||
| 32396 | if (-e $thisPath) { | ||
| 32397 | |||
| 32398 | $path = $thisPath; | ||
| 32399 | last OUTER; | ||
| 32400 | } | ||
| 32401 | } | ||
| 32402 | } | ||
| 32403 | |||
| 32404 | if (! $path) { | ||
| 32405 | |||
| 32406 | $self->session->writeError( | ||
| 32407 | '\'' . $self->uniqueName . '\' task : can\'t find the ' . $axmud::BASIC_NAME | ||
| 32408 | . ' script \'' . $self->scriptName . '\'', | ||
| 32409 | $self->_objClass . '->doStage', | ||
| 32410 | ); | ||
| 32411 | |||
| 32412 | $self->ivPoke('shutdownFlag', TRUE); | ||
| 32413 | return undef; | ||
| 32414 | } | ||
| 32415 | |||
| 32416 | # Start the script | ||
| 32417 | $path = $axmud::DATA_DIR . '/scripts/' . $self->scriptName . '.bas'; | ||
| 32418 | |||
| 32419 | # Create a raw script object | ||
| 32420 | $rawObj = Language::Axbasic::RawScript->new($self->session, $self->scriptName); | ||
| 32421 | if (! defined $rawObj) { | ||
| 32422 | |||
| 32423 | $self->session->writeError( | ||
| 32424 | '\'' . $self->uniqueName . '\' task : can\'t initialise the ' | ||
| 32425 | . $axmud::BASIC_NAME . ' script \'' . $self->scriptName . '\'', | ||
| 32426 | $self->_objClass . '->doStage', | ||
| 32427 | ); | ||
| 32428 | |||
| 32429 | $self->ivPoke('shutdownFlag', TRUE); | ||
| 32430 | return undef; | ||
| 32431 | } | ||
| 32432 | |||
| 32433 | # Instruct the raw script object to load the .bas script in the 'scripts' directory | ||
| 32434 | if (! $rawObj->loadFile($path)) { | ||
| 32435 | |||
| 32436 | $self->session->writeError( | ||
| 32437 | '\'' . $self->uniqueName . '\' task : can\'t load the ' . $axmud::BASIC_NAME | ||
| 32438 | . ' script \'' . $self->scriptName . '\'', | ||
| 32439 | $self->_objClass . '->doStage', | ||
| 32440 | ); | ||
| 32441 | |||
| 32442 | $self->ivPoke('shutdownFlag', TRUE); | ||
| 32443 | return undef; | ||
| 32444 | } | ||
| 32445 | |||
| 32446 | # Create a AB::Script object, which processes the raw script, removing extraneous | ||
| 32447 | # whitespace, empty lines, comments, etc | ||
| 32448 | $scriptObj = Language::Axbasic::Script->new($self->session, $rawObj); | ||
| 32449 | if (! $scriptObj) { | ||
| 32450 | |||
| 32451 | $self->session->writeError( | ||
| 32452 | '\'' . $self->uniqueName . '\' task : can\'t process the ' . $axmud::BASIC_NAME | ||
| 32453 | . ' script \'' . $self->scriptName . '\'', | ||
| 32454 | $self->_objClass . '->doStage', | ||
| 32455 | ); | ||
| 32456 | |||
| 32457 | $self->ivPoke('shutdownFlag', TRUE); | ||
| 32458 | return undef; | ||
| 32459 | } | ||
| 32460 | |||
| 32461 | # The AB::Script object was created | ||
| 32462 | $self->ivPoke('scriptObj', $scriptObj); | ||
| 32463 | # Inform the AB::Script object that it's being run by this task | ||
| 32464 | $scriptObj->set_task($self); | ||
| 32465 | |||
| 32466 | # If 'forced window' mode is on, inform the script | ||
| 32467 | if ($self->forcedWinFlag) { | ||
| 32468 | |||
| 32469 | $scriptObj->set_forcedWinFlag(TRUE); | ||
| 32470 | } | ||
| 32471 | |||
| 32472 | # Move on to the next stage | ||
| 32473 | return $self->ivPoke('stage', 3); | ||
| 32474 | |||
| 32475 | } elsif ($self->stage == 3) { | ||
| 32476 | |||
| 32477 | # If the stage was 4 on the previous task loop, the IVs used for monitoring another | ||
| 32478 | # task are still set. Reset them. | ||
| 32479 | if (defined $self->monitorTask) { | ||
| 32480 | |||
| 32481 | $self->ivUndef('monitorTask'); | ||
| 32482 | $self->ivUndef('monitorStatistic'); | ||
| 32483 | $self->ivUndef('monitorTarget'); | ||
| 32484 | $self->ivUndef('monitorTimeOut'); | ||
| 32485 | |||
| 32486 | # After a pause, the script's step count (how many statements to execute before | ||
| 32487 | # taking a short break) needs to be reset | ||
| 32488 | $self->scriptObj->ivPoke('stepCount', 0); | ||
| 32489 | } | ||
| 32490 | |||
| 32491 | # If the Axbasic script is waiting for a response to an INPUT statement, do nothing | ||
| 32492 | if ($self->scriptObj->scriptStatus eq 'wait_input') { | ||
| 32493 | |||
| 32494 | # The Axbasic script is still waiting for a response; repeat this stage | ||
| 32495 | return $self->ivPoke('stage', 3); | ||
| 32496 | } | ||
| 32497 | |||
| 32498 | # Execute the script | ||
| 32499 | if (! $self->scriptObj->implement()) { | ||
| 32500 | |||
| 32501 | # If the script's ->implementFlag is set, it is still processing a previous call | ||
| 32502 | # (from an earlier spin of the task loop). Wait until the next spin | ||
| 32503 | if ($self->scriptObj->implementFlag) { | ||
| 32504 | |||
| 32505 | return $self->ivPoke('stage', 3); | ||
| 32506 | |||
| 32507 | } else { | ||
| 32508 | |||
| 32509 | $self->session->writeError( | ||
| 32510 | '\'' . $self->uniqueName . '\' task : execution of the ' | ||
| 32511 | . $axmud::BASIC_NAME . ' script \'' . $self->scriptName . '\' failed', | ||
| 32512 | $self->_objClass . '->doStage', | ||
| 32513 | ); | ||
| 32514 | |||
| 32515 | $self->ivPoke('shutdownFlag', TRUE); | ||
| 32516 | return undef; | ||
| 32517 | } | ||
| 32518 | |||
| 32519 | } elsif ( | ||
| 32520 | $self->scriptObj->scriptStatus eq 'paused' | ||
| 32521 | || $self->scriptObj->scriptStatus eq 'wait_input' | ||
| 32522 | ) { | ||
| 32523 | # Programme is paused, or waiting for input. Wait for it to un-pause/receive input | ||
| 32524 | return $self->ivPoke('stage', 3); | ||
| 32525 | |||
| 32526 | } elsif (defined $self->monitorTask) { | ||
| 32527 | |||
| 32528 | # A statement like WAITHP is waiting for this task to monitor some statistic or | ||
| 32529 | # other, before resuming execution of the Axbasic programme | ||
| 32530 | # If a timeout was specified, set it now | ||
| 32531 | if (defined $self->monitorTimeOut) { | ||
| 32532 | |||
| 32533 | $self->ivPoke( | ||
| 32534 | 'checkTime', | ||
| 32535 | ($self->session->sessionTime + $self->monitorTimeOut), | ||
| 32536 | ); | ||
| 32537 | } | ||
| 32538 | |||
| 32539 | # The monitoring takes place in stage 4 | ||
| 32540 | return $self->ivPoke('stage', 4); | ||
| 32541 | |||
| 32542 | } else { | ||
| 32543 | |||
| 32544 | # Script execution has finished | ||
| 32545 | $self->session->writeText( | ||
| 32546 | '\'' . $self->uniqueName . '\' task : execution of the ' . $axmud::BASIC_NAME | ||
| 32547 | . ' script \'' . $self->scriptName . '\' complete', | ||
| 32548 | ); | ||
| 32549 | |||
| 32550 | $self->ivPoke('shutdownFlag', TRUE); | ||
| 32551 | return undef; | ||
| 32552 | } | ||
| 32553 | |||
| 32554 | } elsif ($self->stage == 4) { | ||
| 32555 | |||
| 32556 | my ($otherTaskObj, $charObj, $current); | ||
| 32557 | |||
| 32558 | # If either the task or the statistic to monitor is unrecognised, simply go back to | ||
| 32559 | # stage 3 (resumes execution of the Axbasic programme) as an emergency fallback | ||
| 32560 | # The four IVs used in monitoring other tasks are reset at the beginning of stage 3, | ||
| 32561 | # regarless of how monitoring terminates | ||
| 32562 | |||
| 32563 | # If a timeout was specified, decide whether it's time to give up waiting | ||
| 32564 | if (defined $self->monitorTimeOut && $self->checkTime < $self->session->sessionTime) { | ||
| 32565 | |||
| 32566 | # Resume execution | ||
| 32567 | return $self->ivPoke('stage', 3); | ||
| 32568 | } | ||
| 32569 | |||
| 32570 | # If the task to monitor is no longer set, resume execution | ||
| 32571 | if (! defined $self->monitorTask) { | ||
| 32572 | |||
| 32573 | return $self->ivPoke('stage', 3); | ||
| 32574 | |||
| 32575 | # Monitor a new task that's been created by the Axbasic script | ||
| 32576 | } elsif ($self->monitorTask eq 'task') { | ||
| 32577 | |||
| 32578 | if (! $self->session->ivExists('currentTaskHash', $self->monitorStatistic)) { | ||
| 32579 | |||
| 32580 | # The new task has terminated. Resume execution | ||
| 32581 | return $self->ivPoke('stage', 3); | ||
| 32582 | |||
| 32583 | } else { | ||
| 32584 | |||
| 32585 | # Continue waiting for the new task to terminate | ||
| 32586 | return $self->ivPoke('stage', 4); | ||
| 32587 | } | ||
| 32588 | |||
| 32589 | # Monitor a pre-existing task, waiting for it to get activated | ||
| 32590 | } elsif ($self->monitorTask eq 'task_active') { | ||
| 32591 | |||
| 32592 | $otherTaskObj = $self->session->ivShow('currentTaskHash', $self->monitorStatistic); | ||
| 32593 | if (! $otherTaskObj) { | ||
| 32594 | |||
| 32595 | # The monitored task has terminated (unexpectedly). Wait for a new instance of | ||
| 32596 | # that task to start and become active (which may happen if | ||
| 32597 | # $self->monitorStatistic is a generic task name like 'locator_task', but will | ||
| 32598 | # never happen if it's a unique task name like 'locator_task_54' | ||
| 32599 | return $self->ivPoke('stage', 4); | ||
| 32600 | } | ||
| 32601 | |||
| 32602 | if ($otherTaskObj->activeFlag) { | ||
| 32603 | |||
| 32604 | # The new task has become active. Resume execution of the Axbasic script | ||
| 32605 | return $self->ivPoke('stage', 3); | ||
| 32606 | |||
| 32607 | } else { | ||
| 32608 | |||
| 32609 | # Continue waiting for the new task to become active | ||
| 32610 | return $self->ivPoke('stage', 4); | ||
| 32611 | } | ||
| 32612 | |||
| 32613 | # Monitor a pre-existing task, waiting for it to get disactivated | ||
| 32614 | } elsif ($self->monitorTask eq 'task_not_active') { | ||
| 32615 | |||
| 32616 | $otherTaskObj = $self->session->ivShow('currentTaskHash', $self->monitorStatistic); | ||
| 32617 | if (! $otherTaskObj || ! $otherTaskObj->activeFlag) { | ||
| 32618 | |||
| 32619 | # The monitored task has been disactivatd, or has terminated (unexpectedly). In | ||
| 32620 | # either case, resume execution of the Axbasic script | ||
| 32621 | return $self->ivPoke('stage', 3); | ||
| 32622 | |||
| 32623 | } else { | ||
| 32624 | |||
| 32625 | # Continue waiting for the new task to become disactivated | ||
| 32626 | return $self->ivPoke('stage', 4); | ||
| 32627 | } | ||
| 32628 | |||
| 32629 | # Monitor a new task that's been created by the Axbasic script | ||
| 32630 | } elsif ($self->monitorTask eq 'task') { | ||
| 32631 | |||
| 32632 | if (! $self->session->ivExists('currentTaskHash', $self->monitorStatistic)) { | ||
| 32633 | |||
| 32634 | # The new task has terminated. Resume execution of the Axbasic script | ||
| 32635 | return $self->ivPoke('stage', 3); | ||
| 32636 | |||
| 32637 | } else { | ||
| 32638 | |||
| 32639 | # Continue waiting for the new task to terminate | ||
| 32640 | return $self->ivPoke('stage', 4); | ||
| 32641 | } | ||
| 32642 | |||
| 32643 | # Monitor the Locator task | ||
| 32644 | } elsif ($self->monitorTask eq 'locator') { | ||
| 32645 | |||
| 32646 | $otherTaskObj = $self->session->locatorTask; | ||
| 32647 | |||
| 32648 | # Must resume execution of the Axbasic script if the Locator task is no longer | ||
| 32649 | # running... | ||
| 32650 | if (! $otherTaskObj) { | ||
| 32651 | |||
| 32652 | return $self->ivPoke('stage', 3); | ||
| 32653 | |||
| 32654 | # If the Locator task is still setting up, wait for it to finish | ||
| 32655 | } elsif ($otherTaskObj->stage < 3) { | ||
| 32656 | |||
| 32657 | return $self->ivPoke('stage', 4); | ||
| 32658 | |||
| 32659 | # Monitor arrivals | ||
| 32660 | } elsif ($self->monitorStatistic eq 'arrive') { | ||
| 32661 | |||
| 32662 | if ( | ||
| 32663 | ! $otherTaskObj->roomObj | ||
| 32664 | || (! $otherTaskObj->moveList && ! $self->session->excessCmdList) | ||
| 32665 | ) { | ||
| 32666 | # Locator doesn't know about the current location, or is not expecting any | ||
| 32667 | # more room descriptions. Resume execution of this task | ||
| 32668 | return $self->ivPoke('stage', 3); | ||
| 32669 | |||
| 32670 | } else { | ||
| 32671 | |||
| 32672 | # Locator still waiting for arrival | ||
| 32673 | return $self->ivPoke('stage', 4); | ||
| 32674 | } | ||
| 32675 | |||
| 32676 | } else { | ||
| 32677 | |||
| 32678 | # Unrecognised statistic | ||
| 32679 | return $self->ivPoke('stage', 3); | ||
| 32680 | } | ||
| 32681 | |||
| 32682 | # Monitor the Status task | ||
| 32683 | } elsif ($self->monitorTask eq 'status') { | ||
| 32684 | |||
| 32685 | # Since v1.1.263, the health/magic/energy/guild/social point IVs have moved to the | ||
| 32686 | # character profile, but are still being updated by the Status task | ||
| 32687 | # For that reason, we need to check both the profile and the task | ||
| 32688 | |||
| 32689 | $otherTaskObj = $self->session->statusTask; | ||
| 32690 | $charObj = $self->session->currentChar; | ||
| 32691 | |||
| 32692 | # Must resume execution of the Axbasic script if the Status task is no longer | ||
| 32693 | # running (or if no current character profile exists) | ||
| 32694 | if (! $otherTaskObj || ! $charObj) { | ||
| 32695 | |||
| 32696 | return $self->ivPoke('stage', 3); | ||
| 32697 | |||
| 32698 | # If the Status task is still setting up, wait for it to finish | ||
| 32699 | } elsif ($otherTaskObj->stage < 3) { | ||
| 32700 | |||
| 32701 | return $self->ivPoke('stage', 4); | ||
| 32702 | |||
| 32703 | # Monitor health points (HP) | ||
| 32704 | } elsif ($self->monitorStatistic eq 'hp') { | ||
| 32705 | |||
| 32706 | if ( | ||
| 32707 | ! defined $charObj->healthPoints | ||
| 32708 | || ! defined $charObj->healthPointsMax | ||
| 32709 | # Can't divide by zero | ||
| 32710 | || ! $charObj->healthPointsMax | ||
| 32711 | ) { | ||
| 32712 | # Statistic not known; resume execution | ||
| 32713 | return $self->ivPoke('stage', 3); | ||
| 32714 | } | ||
| 32715 | |||
| 32716 | $current = 100 * ($charObj->healthPoints / $charObj->healthPointsMax); | ||
| 32717 | if ($current >= $self->monitorTarget) { | ||
| 32718 | |||
| 32719 | # HP has recovered; resume execution | ||
| 32720 | return $self->ivPoke('stage', 3); | ||
| 32721 | |||
| 32722 | } else { | ||
| 32723 | |||
| 32724 | # Continue waiting for HP to recover | ||
| 32725 | return $self->ivPoke('stage', 4); | ||
| 32726 | } | ||
| 32727 | |||
| 32728 | # Monitor magic points (MP) | ||
| 32729 | } elsif ($self->monitorStatistic eq 'mp') { | ||
| 32730 | |||
| 32731 | if ( | ||
| 32732 | ! defined $charObj->magicPoints | ||
| 32733 | || ! defined $charObj->magicPointsMax | ||
| 32734 | # Can't divide by zero | ||
| 32735 | || ! $charObj->magicPointsMax | ||
| 32736 | ) { | ||
| 32737 | # Statistic not known; resume execution | ||
| 32738 | return $self->ivPoke('stage', 3); | ||
| 32739 | } | ||
| 32740 | |||
| 32741 | $current = 100 * ($charObj->magicPoints / $charObj->magicPointsMax); | ||
| 32742 | if ($current >= $self->monitorTarget) { | ||
| 32743 | |||
| 32744 | # MP has recovered; resume execution | ||
| 32745 | return $self->ivPoke('stage', 3); | ||
| 32746 | |||
| 32747 | } else { | ||
| 32748 | |||
| 32749 | # Continue waiting for MP to recover | ||
| 32750 | return $self->ivPoke('stage', 4); | ||
| 32751 | } | ||
| 32752 | |||
| 32753 | # Monitor energy points (EP) | ||
| 32754 | } elsif ($self->monitorStatistic eq 'ep') { | ||
| 32755 | |||
| 32756 | if ( | ||
| 32757 | ! defined $charObj->energyPoints | ||
| 32758 | || ! defined $charObj->energyPointsMax | ||
| 32759 | # Can't divide by zero | ||
| 32760 | || ! $charObj->energyPointsMax | ||
| 32761 | ) { | ||
| 32762 | # Statistic not known; resume execution | ||
| 32763 | return $self->ivPoke('stage', 3); | ||
| 32764 | } | ||
| 32765 | |||
| 32766 | $current = 100 * ($charObj->energyPoints / $charObj->energyPointsMax); | ||
| 32767 | if ($current >= $self->monitorTarget) { | ||
| 32768 | |||
| 32769 | # EP has recovered; resume execution | ||
| 32770 | return $self->ivPoke('stage', 3); | ||
| 32771 | |||
| 32772 | } else { | ||
| 32773 | |||
| 32774 | # Continue waiting for EP to recover | ||
| 32775 | return $self->ivPoke('stage', 4); | ||
| 32776 | } | ||
| 32777 | |||
| 32778 | # Monitor guild points (GP) | ||
| 32779 | } elsif ($self->monitorStatistic eq 'gp') { | ||
| 32780 | |||
| 32781 | if ( | ||
| 32782 | ! defined $charObj->guildPoints | ||
| 32783 | || ! defined $charObj->guildPointsMax | ||
| 32784 | # Can't divide by zero | ||
| 32785 | || ! $charObj->guildPointsMax | ||
| 32786 | ) { | ||
| 32787 | # Statistic not known; resume execution | ||
| 32788 | return $self->ivPoke('stage', 3); | ||
| 32789 | } | ||
| 32790 | |||
| 32791 | $current = 100 * ($charObj->guildPoints / $charObj->guildPointsMax); | ||
| 32792 | if ($current >= $self->monitorTarget) { | ||
| 32793 | |||
| 32794 | # GP has recovered; resume execution | ||
| 32795 | return $self->ivPoke('stage', 3); | ||
| 32796 | |||
| 32797 | } else { | ||
| 32798 | |||
| 32799 | # Continue waiting for GP to recover | ||
| 32800 | return $self->ivPoke('stage', 4); | ||
| 32801 | } | ||
| 32802 | |||
| 32803 | # Monitor social points (SP) | ||
| 32804 | } elsif ($self->monitorStatistic eq 'sp') { | ||
| 32805 | |||
| 32806 | if ( | ||
| 32807 | ! defined $charObj->socialPoints | ||
| 32808 | || ! defined $charObj->socialPointsMax | ||
| 32809 | # Can't divide by zero | ||
| 32810 | || ! $charObj->socialPointsMax | ||
| 32811 | ) { | ||
| 32812 | # Statistic not known; resume execution | ||
| 32813 | return $self->ivPoke('stage', 3); | ||
| 32814 | } | ||
| 32815 | |||
| 32816 | $current = 100 * ($charObj->socialPoints / $charObj->socialPointsMax); | ||
| 32817 | if ($current >= $self->monitorTarget) { | ||
| 32818 | |||
| 32819 | # SP has recovered; resume execution | ||
| 32820 | return $self->ivPoke('stage', 3); | ||
| 32821 | |||
| 32822 | } else { | ||
| 32823 | |||
| 32824 | # Continue waiting for SP to recover | ||
| 32825 | return $self->ivPoke('stage', 4); | ||
| 32826 | } | ||
| 32827 | |||
| 32828 | # Monitor current experience points (XP) | ||
| 32829 | } elsif ($self->monitorStatistic eq 'xp_current') { | ||
| 32830 | |||
| 32831 | if (! defined $charObj->xpCurrent) { | ||
| 32832 | |||
| 32833 | # Statistic not known; resume execution | ||
| 32834 | return $self->ivPoke('stage', 3); | ||
| 32835 | |||
| 32836 | } elsif ($self->xpCurrent >= $self->monitorTarget) { | ||
| 32837 | |||
| 32838 | # XP has recovered; resume execution | ||
| 32839 | return $self->ivPoke('stage', 3); | ||
| 32840 | |||
| 32841 | } else { | ||
| 32842 | |||
| 32843 | # Continue waiting for XP to recover | ||
| 32844 | return $self->ivPoke('stage', 4); | ||
| 32845 | } | ||
| 32846 | |||
| 32847 | # Monitor experience points (XP) to next level | ||
| 32848 | } elsif ($self->monitorStatistic eq 'xp_next_level') { | ||
| 32849 | |||
| 32850 | if (! defined $charObj->xpNextLevel) { | ||
| 32851 | |||
| 32852 | # Statistic not known; resume execution | ||
| 32853 | return $self->ivPoke('stage', 3); | ||
| 32854 | |||
| 32855 | } elsif ($self->xpNextLevel <= $self->monitorTarget) { | ||
| 32856 | |||
| 32857 | # XP has recovered; resume execution | ||
| 32858 | return $self->ivPoke('stage', 3); | ||
| 32859 | |||
| 32860 | } else { | ||
| 32861 | |||
| 32862 | # Continue waiting for XP to recover | ||
| 32863 | return $self->ivPoke('stage', 4); | ||
| 32864 | } | ||
| 32865 | |||
| 32866 | # Monitor total experience points (XP) | ||
| 32867 | } elsif ($self->monitorStatistic eq 'xp_total') { | ||
| 32868 | |||
| 32869 | if (! defined $charObj->xpTotal) { | ||
| 32870 | |||
| 32871 | # Statistic not known; resume execution | ||
| 32872 | return $self->ivPoke('stage', 3); | ||
| 32873 | |||
| 32874 | } elsif ($self->xpTotal >= $self->monitorTarget) { | ||
| 32875 | |||
| 32876 | # XP has recovered; resume execution | ||
| 32877 | return $self->ivPoke('stage', 3); | ||
| 32878 | |||
| 32879 | } else { | ||
| 32880 | |||
| 32881 | # Continue waiting for XP to recover | ||
| 32882 | return $self->ivPoke('stage', 4); | ||
| 32883 | } | ||
| 32884 | |||
| 32885 | # Monitor life status | ||
| 32886 | } elsif ( | ||
| 32887 | $self->monitorStatistic eq 'alive' || $self->monitorStatistic eq 'sleep' | ||
| 32888 | || $self->monitorStatistic eq 'passout' || $self->monitorStatistic eq 'dead' | ||
| 32889 | ) { | ||
| 32890 | if ($charObj->lifeStatus eq $self->monitorStatistic) { | ||
| 32891 | |||
| 32892 | # Life status matches; resume execution | ||
| 32893 | return $self->ivPoke('stage', 3); | ||
| 32894 | |||
| 32895 | } else { | ||
| 32896 | |||
| 32897 | # Continue waiting for the right life status | ||
| 32898 | return $self->ivPoke('stage', 4); | ||
| 32899 | } | ||
| 32900 | |||
| 32901 | } else { | ||
| 32902 | |||
| 32903 | # Unrecognised statistic | ||
| 32904 | return $self->ivPoke('stage', 3); | ||
| 32905 | } | ||
| 32906 | |||
| 32907 | # Can't monitor any tasks but the four specified above | ||
| 32908 | } else { | ||
| 32909 | |||
| 32910 | return $self->ivPoke('stage', 3); | ||
| 32911 | } | ||
| 32912 | |||
| 32913 | } else { | ||
| 32914 | |||
| 32915 | # The task stage has somehow been set to an invalid value | ||
| 32916 | return $self->invalidStage(); | ||
| 32917 | } | ||
| 32918 | } | ||
| 32919 | |||
| 32920 | sub setUpMonitoring { | ||
| 32921 | |||
| 32922 | # Called by several Axbasic statements to set this task's IVs, used when the task is | ||
| 32923 | # monitoring another task (such as the Status task), waiting for a statistic stored by the | ||
| 32924 | # other task to change to a certain desired value (after which, execution of the Axbasic | ||
| 32925 | # script resumes) | ||
| 32926 | # | ||
| 32927 | # Expected arguments | ||
| 32928 | # $task - The task to monitor ('locator', 'attack', 'status', 'divert') | ||
| 32929 | # $statistic - The statistic to monitor, stored as an IV by that task | ||
| 32930 | # | ||
| 32931 | # Optional arguments | ||
| 32932 | # $target - The minimum value that the statistic should reach before resuming the | ||
| 32933 | # Axbasic script; a percentage value in the range 0-100 (not necessary | ||
| 32934 | # for every statement which sets up monitoring) | ||
| 32935 | # $timeOut - An optional timeout, in seconds, after which the Axbasic script resumes | ||
| 32936 | # execution anyway | ||
| 32937 | # | ||
| 32938 | # Return values | ||
| 32939 | # 'undef' on improper arguments | ||
| 32940 | # 1 otherwise | ||
| 32941 | |||
| 32942 | my ($self, $task, $statistic, $target, $timeOut, $check) = @_; | ||
| 32943 | |||
| 32944 | # Check for improper arguments | ||
| 32945 | if (! defined $task || ! defined $statistic || defined $check) { | ||
| 32946 | |||
| 32947 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setUpMonitoring', @_); | ||
| 32948 | } | ||
| 32949 | |||
| 32950 | # Set the IVs | ||
| 32951 | $self->ivPoke('monitorTask', $task); | ||
| 32952 | $self->ivPoke('monitorStatistic', $statistic); | ||
| 32953 | $self->ivPoke('monitorTarget', $target); # May be 'undef' | ||
| 32954 | $self->ivPoke('monitorTimeOut', $timeOut); # May be 'undef' | ||
| 32955 | |||
| 32956 | # Return control to the LA::Script, which in turn returns control to $self->doStage, stage | ||
| 32957 | # 3; the next task loop will be stage 4, which does the actual monitoring | ||
| 32958 | return 1; | ||
| 32959 | } | ||
| 32960 | |||
| 32961 | sub resetInterface { | ||
| 32962 | |||
| 32963 | # Called by LA::Statement::deliface->implement, when it deletes an interface | ||
| 32964 | # Also called by $self->interfaceWaitSeen when the (temporary) interface fires | ||
| 32965 | # | ||
| 32966 | # This function checks whether it's the same interface stored by this task and, if so, | ||
| 32967 | # updates IVs | ||
| 32968 | # | ||
| 32969 | # Expected arguments | ||
| 32970 | # (none besides $self) | ||
| 32971 | # | ||
| 32972 | # Optional arguments | ||
| 32973 | # $interfaceObj - The interface which has been removed. Set when called by | ||
| 32974 | # LA::Statement::deliface->implement, but 'undef' when called by | ||
| 32975 | # $self->interfaceWaitSeen | ||
| 32976 | # | ||
| 32977 | # Return values | ||
| 32978 | # 'undef' on improper arguments | ||
| 32979 | # 1 otherwise | ||
| 32980 | |||
| 32981 | my ($self, $interfaceObj, $check) = @_; | ||
| 32982 | |||
| 32983 | # Check for improper arguments | ||
| 32984 | if (defined $check) { | ||
| 32985 | |||
| 32986 | return $axmud::CLIENT->writeImproper($self->_objClass . '->interfaceObj', @_); | ||
| 32987 | } | ||
| 32988 | |||
| 32989 | # (For calls from AB::Statement::deliface, need to check it's the right interface) | ||
| 32990 | if (! defined $interfaceObj || $self->waitForInterface eq $interfaceObj->name) { | ||
| 32991 | |||
| 32992 | # Update this task's IVs | ||
| 32993 | $self->ivUndef('waitForInterface'); | ||
| 32994 | $self->ivPoke('checkTime', 0); | ||
| 32995 | |||
| 32996 | # Unpause the task. Execution of the script resumes on the next task loop | ||
| 32997 | if ($self->status eq 'paused') { | ||
| 32998 | |||
| 32999 | if (defined $self->resumeStatus) { | ||
| 33000 | $self->ivPoke('status', $self->resumeStatus); | ||
| 33001 | } else { | ||
| 33002 | $self->ivPoke('status', 'running'); # Defaults | ||
| 33003 | } | ||
| 33004 | |||
| 33005 | $self->ivPoke('stage', 3); | ||
| 33006 | $self->ivUndef('resumeStatus'); | ||
| 33007 | } | ||
| 33008 | } | ||
| 33009 | |||
| 33010 | return 1; | ||
| 33011 | } | ||
| 33012 | |||
| 33013 | sub pauseUntil { | ||
| 33014 | |||
| 33015 | # Called by LA::Statement::pause->implement and ::waittrig->implement | ||
| 33016 | # | ||
| 33017 | # Pauses this task. If a time is specified, sets the time at which the task should resume | ||
| 33018 | # | ||
| 33019 | # Expected arguments | ||
| 33020 | # (none besides $self) | ||
| 33021 | # | ||
| 33022 | # Optional arguments | ||
| 33023 | # $time - The time at which the task should resume (matches GA::Session->sessionTime). | ||
| 33024 | # 'undef' when called by LA::Statement::waittrig->implement, for a WAITTRIG | ||
| 33025 | # statement with no timeout (in which case, the task is paused indefinitely) | ||
| 33026 | # | ||
| 33027 | # Return values | ||
| 33028 | # 'undef' on improper arguments | ||
| 33029 | # 1 otherwise | ||
| 33030 | |||
| 33031 | my ($self, $time, $check) = @_; | ||
| 33032 | |||
| 33033 | # Check for improper arguments | ||
| 33034 | if (defined $check) { | ||
| 33035 | |||
| 33036 | return $axmud::CLIENT->writeImproper($self->_objClass . '->pauseUntil', @_); | ||
| 33037 | } | ||
| 33038 | |||
| 33039 | # Pause the task | ||
| 33040 | $self->ivPoke('resumeStatus', $self->status); | ||
| 33041 | $self->ivPoke('status', 'paused'); | ||
| 33042 | # Set the time at which the task will resume | ||
| 33043 | if (defined $time) { | ||
| 33044 | |||
| 33045 | $self->ivPoke('checkTime', $time); | ||
| 33046 | } | ||
| 33047 | |||
| 33048 | return 1; | ||
| 33049 | } | ||
| 33050 | |||
| 33051 | sub insertPrint { | ||
| 33052 | |||
| 33053 | # Called by LA::Statement::print->implement and ::writewin->implement | ||
| 33054 | # Inserts some text into the task window. If any of the optional arguments specify Axmud | ||
| 33055 | # colour tags and if the window is using its own colour scheme, change the colour scheme | ||
| 33056 | # back to default (allowing the coloured text to be seen) | ||
| 33057 | # | ||
| 33058 | # Expected arguments | ||
| 33059 | # (none besides $self) | ||
| 33060 | # | ||
| 33061 | # Optional arguments | ||
| 33062 | # $text - The text to write. If undefined, the text <<undef>> is written | ||
| 33063 | # @args - List of arguments, in any order: | ||
| 33064 | # - 'empty' (empties the buffer before writing $text) | ||
| 33065 | # - 'before' (prepends a newline character to $text) | ||
| 33066 | # - 'after' (appends a newline character to $text) | ||
| 33067 | # - 'echo' (does not prepend/append a newline character, overrides | ||
| 33068 | # 'before' and 'after' if they are specified) | ||
| 33069 | # - one or more Axmud colour tags. Only the first text colour (e.g. 'red') | ||
| 33070 | # is used, and only the first underlay colour ('UL_RED') is used | ||
| 33071 | # - one or more Axmud style tags (e.g. 'italics', 'strike', etc) | ||
| 33072 | # | ||
| 33073 | # Notes | ||
| 33074 | # If both 'echo' and either of 'before'/'after' are specified (or if neither is | ||
| 33075 | # specified), a newline character is NOT appended | ||
| 33076 | # | ||
| 33077 | # Return values | ||
| 33078 | # 'undef' on improper arguments or if the task window isn't open | ||
| 33079 | # 1 otherwise | ||
| 33080 | |||
| 33081 | my ($self, $text, @args) = @_; | ||
| 33082 | |||
| 33083 | # (No improper arguments to check) | ||
| 33084 | |||
| 33085 | # If the task window (a 'grid' window or a pseudo-window inside the session's 'main' window) | ||
| 33086 | # isn't open, don't need to create widgets | ||
| 33087 | if (! $self->winObj) { | ||
| 33088 | |||
| 33089 | return undef; | ||
| 33090 | } | ||
| 33091 | |||
| 33092 | # If $self->monochromeFlag is set, inspect the contents of @args. If it contains any colour | ||
| 33093 | # tags, the window no longer uses a monochrome colour scheme | ||
| 33094 | if ($self->monochromeFlag) { | ||
| 33095 | |||
| 33096 | OUTER: foreach my $item (@args) { | ||
| 33097 | |||
| 33098 | my ($type) = $axmud::CLIENT->checkColourTags($item); | ||
| 33099 | if ($type) { | ||
| 33100 | |||
| 33101 | # It's a valid colour tag. Reset the window's colour scheme | ||
| 33102 | $self->defaultTabObj->paneObj->removeMonochrome($self->defaultTabObj); | ||
| 33103 | |||
| 33104 | last OUTER; | ||
| 33105 | } | ||
| 33106 | } | ||
| 33107 | } | ||
| 33108 | |||
| 33109 | # Pass the arguments on to the task window | ||
| 33110 | $self->insertText($text, @args); | ||
| 33111 | |||
| 33112 | return 1; | ||
| 33113 | } | ||
| 33114 | |||
| 33115 | sub paintWin { | ||
| 33116 | |||
| 33117 | # Called by LA::Statement::paintwin->implement | ||
| 33118 | # Changes the window's colour scheme (and sets a flag, if the window didn't already have its | ||
| 33119 | # own colour scheme) | ||
| 33120 | # | ||
| 33121 | # Expected arguments | ||
| 33122 | # (none besides $self) | ||
| 33123 | # | ||
| 33124 | # Optional arguments | ||
| 33125 | # $colour - The Axmud colour tag to use. Underlay tags are acceptable. If 'undef', the | ||
| 33126 | # default colour scheme is used (and the window is marked as NOT having | ||
| 33127 | # its own colour scheme) | ||
| 33128 | # | ||
| 33129 | # Return values | ||
| 33130 | # 'undef' on improper arguments or if the task window isn't open | ||
| 33131 | # 1 otherwise | ||
| 33132 | |||
| 33133 | my ($self, $colour, $check) = @_; | ||
| 33134 | |||
| 33135 | # Check for improper arguments | ||
| 33136 | if (defined $check) { | ||
| 33137 | |||
| 33138 | return $axmud::CLIENT->writeImproper($self->_objClass . '->paintWin', @_); | ||
| 33139 | } | ||
| 33140 | |||
| 33141 | # If the task window (a 'grid' window or a pseudo-window inside the session's 'main' window) | ||
| 33142 | # isn't open, don't need to create widgets | ||
| 33143 | if (! $self->winObj) { | ||
| 33144 | |||
| 33145 | return undef; | ||
| 33146 | } | ||
| 33147 | |||
| 33148 | if ($colour) { | ||
| 33149 | $self->defaultTabObj->paneObj->applyMonochrome($self->defaultTabObj, $colour); | ||
| 33150 | } else { | ||
| 33151 | $self->defaultTabObj->paneObj->removeMonochrome($self->defaultTabObj); | ||
| 33152 | } | ||
| 33153 | |||
| 33154 | return 1; | ||
| 33155 | } | ||
| 33156 | |||
| 33157 | sub setTitle { | ||
| 33158 | |||
| 33159 | # Called by $self->openWin and LA::Statement::settitle->implement | ||
| 33160 | # Sets the task window's title to include the task name and the script name | ||
| 33161 | # | ||
| 33162 | # Expected arguments | ||
| 33163 | # (none besides $self) | ||
| 33164 | # | ||
| 33165 | # Optional arguments | ||
| 33166 | # $text - The text to use as the window's title (if an empty string or 'undef', a | ||
| 33167 | # default title is used) | ||
| 33168 | # | ||
| 33169 | # Return values | ||
| 33170 | # 'undef' on improper arguments | ||
| 33171 | # 1 otherwise | ||
| 33172 | |||
| 33173 | my ($self, $text, $check) = @_; | ||
| 33174 | |||
| 33175 | # Check for improper arguments | ||
| 33176 | if (defined $check) { | ||
| 33177 | |||
| 33178 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setTitle', @_); | ||
| 33179 | } | ||
| 33180 | |||
| 33181 | # Reset the title | ||
| 33182 | if (defined $text && $text ne '') { | ||
| 33183 | $self->setTaskWinTitle($text); | ||
| 33184 | } else { | ||
| 33185 | $self->setTaskWinTitle($self->prettyName . ' (' . $self->scriptName . ')'); | ||
| 33186 | } | ||
| 33187 | |||
| 33188 | return 1; | ||
| 33189 | } | ||
| 33190 | |||
| 33191 | sub addMainWinGauge { | ||
| 33192 | |||
| 33193 | # Called by LA::Statement::addgauge->implement or ::addcongauge->implement | ||
| 33194 | # Adds a 'main' window gauge, creating a new gauge level if one doesn't already exist for | ||
| 33195 | # this task | ||
| 33196 | # | ||
| 33197 | # Expected arguments | ||
| 33198 | # $number - A local gauge number for this task | ||
| 33199 | # (not related to GA::Obj::Gauge->number). The Language::Axbasic script | ||
| 33200 | # can specify any integer number >= 0. If this task has already created a | ||
| 33201 | # gauge with that local number, it is replaced | ||
| 33202 | # $label - The label to use. If it's an empty string, this function assigns its own | ||
| 33203 | # label | ||
| 33204 | # $addFlag - Flag matching GA::Obj::Gauge->addFlag. FALSE when called by ADDGAUGE | ||
| 33205 | # statements, TRUE when called by ADDCONGAUGE statements | ||
| 33206 | # | ||
| 33207 | # Optional arguments | ||
| 33208 | # $fullCol - The colour of the full portion of the gauge. Must be an Axmud colour tag | ||
| 33209 | # (including standard, xterm and RGB tags). If an empty string, 'undef' or | ||
| 33210 | # an invalid colour tag, the default gauge colour is used | ||
| 33211 | # $emptyCol - The colour of the empty portion of the gauge | ||
| 33212 | # $labelCol - The colour of the label | ||
| 33213 | # | ||
| 33214 | # Return values | ||
| 33215 | # 'undef' on improper arguments or if the gauge can't be added | ||
| 33216 | # 1 otherwise | ||
| 33217 | |||
| 33218 | my ($self, $number, $label, $addFlag, $fullCol, $emptyCol, $labelCol, $check) = @_; | ||
| 33219 | |||
| 33220 | # Local variables | ||
| 33221 | my ($stripObj, $level, $gaugeObj, $fullType, $emptyType, $labelType); | ||
| 33222 | |||
| 33223 | # Check for improper arguments | ||
| 33224 | if ( | ||
| 33225 | ! defined $number || ! defined $label || ! defined $addFlag || defined $check | ||
| 33226 | ) { | ||
| 33227 | return $axmud::CLIENT->writeImproper($self->_objClass . '->addMainWinGauge', @_); | ||
| 33228 | } | ||
| 33229 | |||
| 33230 | # Find the GA::Strip::GaugeBox object for the session's 'main' window (which is the | ||
| 33231 | # window we'll use), if we don't already have it | ||
| 33232 | if (! $self->gaugeStripObj) { | ||
| 33233 | |||
| 33234 | $stripObj = $self->session->mainWin->ivShow( | ||
| 33235 | 'firstStripHash', | ||
| 33236 | 'Games::Axmud::Strip::GaugeBox', | ||
| 33237 | ); | ||
| 33238 | |||
| 33239 | if (! $stripObj) { | ||
| 33240 | |||
| 33241 | return undef; | ||
| 33242 | |||
| 33243 | } else { | ||
| 33244 | |||
| 33245 | $self->ivPoke('gaugeStripObj', $stripObj); | ||
| 33246 | } | ||
| 33247 | } | ||
| 33248 | |||
| 33249 | # Add a gauge level for this task, if one doesn't already exist | ||
| 33250 | if (! defined $self->gaugeLevel) { | ||
| 33251 | |||
| 33252 | # The TRUE flag means 'don't draw it yet' | ||
| 33253 | $level = $self->gaugeStripObj->addGaugeLevel($self->session, TRUE); | ||
| 33254 | if (! defined $level) { | ||
| 33255 | |||
| 33256 | return undef; | ||
| 33257 | |||
| 33258 | } else { | ||
| 33259 | |||
| 33260 | $self->ivPoke('gaugeLevel', $level); | ||
| 33261 | } | ||
| 33262 | } | ||
| 33263 | |||
| 33264 | # If this task has already created a gauge with the local number $number, remove it | ||
| 33265 | if ($self->ivExists('gaugeHash', $number)) { | ||
| 33266 | |||
| 33267 | $self->gaugeStripObj->removeGauges( | ||
| 33268 | $self->session, | ||
| 33269 | TRUE, | ||
| 33270 | $self->ivShow('gaugeHash', $number), | ||
| 33271 | ); | ||
| 33272 | } | ||
| 33273 | |||
| 33274 | # Convert the specified colour tags into RGB colour tags (or use default colours, if the | ||
| 33275 | # specified tags are invalid) | ||
| 33276 | if (defined $fullCol) { | ||
| 33277 | |||
| 33278 | ($fullType) = $axmud::CLIENT->checkColourTags($fullCol); | ||
| 33279 | } | ||
| 33280 | |||
| 33281 | if (! $fullType) { | ||
| 33282 | $fullCol = $self->gaugeStripObj->gaugeFullColour; | ||
| 33283 | } else { | ||
| 33284 | $fullCol = $axmud::CLIENT->returnRGBColour($fullCol); | ||
| 33285 | } | ||
| 33286 | |||
| 33287 | if (defined $emptyCol) { | ||
| 33288 | |||
| 33289 | ($emptyType) = $axmud::CLIENT->checkColourTags($emptyCol); | ||
| 33290 | } | ||
| 33291 | |||
| 33292 | if (! $emptyType) { | ||
| 33293 | $emptyCol = $self->gaugeStripObj->gaugeEmptyColour; | ||
| 33294 | } else { | ||
| 33295 | $emptyCol = $axmud::CLIENT->returnRGBColour($emptyCol); | ||
| 33296 | } | ||
| 33297 | |||
| 33298 | if (defined $labelCol) { | ||
| 33299 | |||
| 33300 | ($labelType) = $axmud::CLIENT->checkColourTags($labelCol); | ||
| 33301 | if (! $labelType) { | ||
| 33302 | $labelCol = $self->gaugeStripObj->gaugeLabelColour; | ||
| 33303 | } else { | ||
| 33304 | $labelCol = $axmud::CLIENT->returnRGBColour($labelCol); | ||
| 33305 | } | ||
| 33306 | } | ||
| 33307 | |||
| 33308 | # Assign a label, if none was specified | ||
| 33309 | if ($label eq '') { | ||
| 33310 | |||
| 33311 | $label = 'Gauge ' . $number; | ||
| 33312 | } | ||
| 33313 | |||
| 33314 | # Add the gauge | ||
| 33315 | $gaugeObj = $self->gaugeStripObj->addGauge( | ||
| 33316 | $self->session, | ||
| 33317 | $self->gaugeLevel, | ||
| 33318 | undef, | ||
| 33319 | undef, | ||
| 33320 | $addFlag, | ||
| 33321 | $label, | ||
| 33322 | $fullCol, | ||
| 33323 | $emptyCol, | ||
| 33324 | $labelCol, | ||
| 33325 | TRUE, | ||
| 33326 | ); | ||
| 33327 | |||
| 33328 | if ($gaugeObj) { | ||
| 33329 | |||
| 33330 | $self->ivAdd('gaugeHash', $number, $gaugeObj); | ||
| 33331 | } | ||
| 33332 | |||
| 33333 | $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->addMainWinGauge'); | ||
| 33334 | |||
| 33335 | return 1; | ||
| 33336 | } | ||
| 33337 | |||
| 33338 | sub deleteMainWinGauge { | ||
| 33339 | |||
| 33340 | # Called by LA::Statement::delgauge->implement | ||
| 33341 | # Deletes a 'main' window gauge, removing the gauge level if there are no gauges/status bars | ||
| 33342 | # left for this task | ||
| 33343 | # | ||
| 33344 | # Expected arguments | ||
| 33345 | # $number - A local gauge number for this task, matching a key in $self->gaugeHash | ||
| 33346 | # (not related to GA::Obj::Gauge->number) | ||
| 33347 | # | ||
| 33348 | # Return values | ||
| 33349 | # 'undef' on improper arguments | ||
| 33350 | # 1 otherwise | ||
| 33351 | |||
| 33352 | my ($self, $number, $check) = @_; | ||
| 33353 | |||
| 33354 | # Check for improper arguments | ||
| 33355 | if (! defined $number || defined $check) { | ||
| 33356 | |||
| 33357 | return $axmud::CLIENT->writeImproper($self->_objClass . '->deleteMainWinGauge', @_); | ||
| 33358 | } | ||
| 33359 | |||
| 33360 | # Delete the gauge with this local $number, if it exists | ||
| 33361 | if ($self->ivExists('gaugeHash', $number)) { | ||
| 33362 | |||
| 33363 | $self->gaugeStripObj->removeGauges( | ||
| 33364 | $self->session, | ||
| 33365 | FALSE, | ||
| 33366 | $self->ivShow('gaugeHash', $number), | ||
| 33367 | ); | ||
| 33368 | |||
| 33369 | $self->ivDelete('gaugeHash', $number); | ||
| 33370 | |||
| 33371 | # If there are no more gauges/status bars left for this task, remove the gauge level | ||
| 33372 | # assigned to it | ||
| 33373 | if (! $self->gaugeHash && ! $self->statusBarHash) { | ||
| 33374 | |||
| 33375 | $self->gaugeStripObj->removeGaugeLevel($self->session, $self->gaugeLevel); | ||
| 33376 | } | ||
| 33377 | } | ||
| 33378 | |||
| 33379 | return 1; | ||
| 33380 | } | ||
| 33381 | |||
| 33382 | sub setMainWinGauge { | ||
| 33383 | |||
| 33384 | # Called by LA::Statement::setgauge->implement | ||
| 33385 | # Sets the values displayed by the gauge, and tells the gauge box to re-draw its gauges | ||
| 33386 | # | ||
| 33387 | # Expected arguments | ||
| 33388 | # $number - A local gauge number for this task, matching a key in $self->gaugeHash | ||
| 33389 | # (not related to GA::Obj::Gauge->number) | ||
| 33390 | # | ||
| 33391 | # Optional arguments | ||
| 33392 | # $val - The value to use for the full portion of the gauge. Can be set to 'undef' | ||
| 33393 | # if the value supplied by the Axbasic script wasn't a valid decimal | ||
| 33394 | # number | ||
| 33395 | # $maxVal - The value to use for the empty portion of the gauge. Can also be set to | ||
| 33396 | # 'undef' | ||
| 33397 | # | ||
| 33398 | # Return values | ||
| 33399 | # 'undef' on improper arguments | ||
| 33400 | # 1 otherwise | ||
| 33401 | |||
| 33402 | my ($self, $number, $val, $maxVal, $check) = @_; | ||
| 33403 | |||
| 33404 | # Local variables | ||
| 33405 | my $gaugeObj; | ||
| 33406 | |||
| 33407 | # Check for improper arguments | ||
| 33408 | if (! defined $number || defined $check) { | ||
| 33409 | |||
| 33410 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setMainWinGauge', @_); | ||
| 33411 | } | ||
| 33412 | |||
| 33413 | $gaugeObj = $self->ivShow('gaugeHash', $number); | ||
| 33414 | # If the gauge with this local $number exists... | ||
| 33415 | if ($gaugeObj) { | ||
| 33416 | |||
| 33417 | $gaugeObj->ivPoke('value', $val); | ||
| 33418 | $gaugeObj->ivPoke('maxValue', $maxVal); | ||
| 33419 | |||
| 33420 | $self->gaugeStripObj->updateGauges(); | ||
| 33421 | } | ||
| 33422 | |||
| 33423 | return 1; | ||
| 33424 | } | ||
| 33425 | |||
| 33426 | sub addMainWinStatusBar { | ||
| 33427 | |||
| 33428 | # Called by LA::Statement::addstatus->implement or ::addconstatus->implement | ||
| 33429 | # Adds a 'main' window status bar, creating a new gauge level if one doesn't already exist | ||
| 33430 | # for this task | ||
| 33431 | # | ||
| 33432 | # Expected arguments | ||
| 33433 | # $number - A local status bar number for this task | ||
| 33434 | # (not related to GA::Obj::Gauge->number). The Axbasic script can specify | ||
| 33435 | # any integer number >= 0. If this task has already created a status bar | ||
| 33436 | # with that local number, it is replaced | ||
| 33437 | # $label - The label to use. If it's an empty string, this function assigns its own | ||
| 33438 | # label | ||
| 33439 | # $addFlag - Flag matching GA::Obj::Gauge->addFlag. FALSE when called by ADDSTATUS | ||
| 33440 | # statements, TRUE when called by ADDCONSTATUS statements | ||
| 33441 | # | ||
| 33442 | # Return values | ||
| 33443 | # 'undef' on improper arguments or if the gauge can't be added | ||
| 33444 | # 1 otherwise | ||
| 33445 | |||
| 33446 | my ($self, $number, $label, $addFlag, $check) = @_; | ||
| 33447 | |||
| 33448 | # Local variables | ||
| 33449 | my ($stripObj, $level, $gaugeObj); | ||
| 33450 | |||
| 33451 | # Check for improper arguments | ||
| 33452 | if (! defined $number || ! defined $label || ! defined $addFlag || defined $check) { | ||
| 33453 | |||
| 33454 | return $axmud::CLIENT->writeImproper($self->_objClass . '->addMainWinStatusBar', @_); | ||
| 33455 | } | ||
| 33456 | |||
| 33457 | # Find the GA::Strip::GaugeBox object for the session's 'main' window (which is the window | ||
| 33458 | # we'll use), if we don't already have it | ||
| 33459 | if (! $self->gaugeStripObj) { | ||
| 33460 | |||
| 33461 | $stripObj = $self->session->mainWin->ivShow( | ||
| 33462 | 'firstStripHash', | ||
| 33463 | 'Games::Axmud::Strip::GaugeBox', | ||
| 33464 | ); | ||
| 33465 | |||
| 33466 | if (! $stripObj) { | ||
| 33467 | |||
| 33468 | return undef; | ||
| 33469 | |||
| 33470 | } else { | ||
| 33471 | |||
| 33472 | $self->ivPoke('gaugeStripObj', $stripObj); | ||
| 33473 | } | ||
| 33474 | } | ||
| 33475 | |||
| 33476 | # Add a gauge level for this task, if one doesn't already exist | ||
| 33477 | if (! defined $self->gaugeLevel) { | ||
| 33478 | |||
| 33479 | # The TRUE flag means 'don't draw it yet' | ||
| 33480 | $level = $self->gaugeStripObj->addGaugeLevel($self->session, TRUE); | ||
| 33481 | if (! defined $level) { | ||
| 33482 | |||
| 33483 | return undef; | ||
| 33484 | |||
| 33485 | } else { | ||
| 33486 | |||
| 33487 | $self->ivPoke('gaugeLevel', $level); | ||
| 33488 | } | ||
| 33489 | } | ||
| 33490 | |||
| 33491 | # If this task has already created a status bar with the local number $number, remove it | ||
| 33492 | if ($self->ivExists('statusBarHash', $number)) { | ||
| 33493 | |||
| 33494 | $self->gaugeStripObj->removeGauges( | ||
| 33495 | $self->session, | ||
| 33496 | FALSE, | ||
| 33497 | $self->ivShow('statusBarHash', $number), | ||
| 33498 | ); | ||
| 33499 | } | ||
| 33500 | |||
| 33501 | # Assign a label, if none was specified | ||
| 33502 | if ($label eq '') { | ||
| 33503 | |||
| 33504 | $label = 'Bar ' . $number; | ||
| 33505 | } | ||
| 33506 | |||
| 33507 | # Add the status bar | ||
| 33508 | $gaugeObj = $self->gaugeStripObj->addTextGauge( | ||
| 33509 | $self->session, | ||
| 33510 | $self->gaugeLevel, | ||
| 33511 | undef, | ||
| 33512 | undef, | ||
| 33513 | $addFlag, | ||
| 33514 | $label, | ||
| 33515 | ); | ||
| 33516 | |||
| 33517 | if ($gaugeObj) { | ||
| 33518 | |||
| 33519 | $self->ivAdd('statusBarHash', $number, $gaugeObj); | ||
| 33520 | } | ||
| 33521 | |||
| 33522 | $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->addMainWinStatusBar'); | ||
| 33523 | |||
| 33524 | return 1; | ||
| 33525 | } | ||
| 33526 | |||
| 33527 | sub deleteMainWinStatusBar { | ||
| 33528 | |||
| 33529 | # Called by LA::Statement::delstatus->implement | ||
| 33530 | # Deletes a 'main' window status bar, removing the gauge level if there are no gauges/status | ||
| 33531 | # bars left for this task | ||
| 33532 | # | ||
| 33533 | # Expected arguments | ||
| 33534 | # $number - A local status bar number for this task, matching a key in | ||
| 33535 | # $self->statusBarHash (not related to GA::Obj::Gauge->number) | ||
| 33536 | # | ||
| 33537 | # Return values | ||
| 33538 | # 'undef' on improper arguments | ||
| 33539 | # 1 otherwise | ||
| 33540 | |||
| 33541 | my ($self, $number, $check) = @_; | ||
| 33542 | |||
| 33543 | # Check for improper arguments | ||
| 33544 | if (! defined $number || defined $check) { | ||
| 33545 | |||
| 33546 | return $axmud::CLIENT->writeImproper($self->_objClass . '->deleteMainWinStatusBar', @_); | ||
| 33547 | } | ||
| 33548 | |||
| 33549 | # Delete the status bar with this local $number, if it exists | ||
| 33550 | if ($self->ivExists('statusBarHash', $number)) { | ||
| 33551 | |||
| 33552 | $self->gaugeStripObj->removeGauges( | ||
| 33553 | $self->session, | ||
| 33554 | FALSE, | ||
| 33555 | $self->ivShow('statusBarHash', $number), | ||
| 33556 | ); | ||
| 33557 | |||
| 33558 | $self->ivDelete('statusBarHash', $number); | ||
| 33559 | |||
| 33560 | # If there are no more gauges/status bars left for this task, remove the gauge level | ||
| 33561 | # assigned to it | ||
| 33562 | if (! $self->gaugeHash && ! $self->statusBarHash) { | ||
| 33563 | |||
| 33564 | $self->gaugeStripObj->removeGaugeLevel($self->session, $self->gaugeLevel); | ||
| 33565 | } | ||
| 33566 | } | ||
| 33567 | |||
| 33568 | return 1; | ||
| 33569 | } | ||
| 33570 | |||
| 33571 | sub setMainWinStatusBar { | ||
| 33572 | |||
| 33573 | # Called by LA::Statement::setstatus->implement | ||
| 33574 | # Sets the values displayed by the status bar, and tells the 'main' window to re-draw its | ||
| 33575 | # gauges/status bars | ||
| 33576 | # | ||
| 33577 | # Expected arguments | ||
| 33578 | # $number - A local status bar number for this task, matching a key in | ||
| 33579 | # $self->statusBarHash (not related to GA::Obj::Gauge->number) | ||
| 33580 | # | ||
| 33581 | # Optional arguments | ||
| 33582 | # $val - The value to use that's the equivalent of the full portion of a | ||
| 33583 | # (graphical) gauge. Can be set to 'undef' if the value supplied by the | ||
| 33584 | # Axbasic script wasn't a valid decimal number | ||
| 33585 | # $maxVal - The value to use that's the equivalent of the empty portion of a | ||
| 33586 | # (graphical) gauge. Can also be set to 'undef' | ||
| 33587 | # | ||
| 33588 | # Return values | ||
| 33589 | # 'undef' on improper arguments | ||
| 33590 | # 1 otherwise | ||
| 33591 | |||
| 33592 | my ($self, $number, $val, $maxVal, $check) = @_; | ||
| 33593 | |||
| 33594 | # Local variables | ||
| 33595 | my $gaugeObj; | ||
| 33596 | |||
| 33597 | # Check for improper arguments | ||
| 33598 | if (! defined $number || defined $check) { | ||
| 33599 | |||
| 33600 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setMainWinStatusBar', @_); | ||
| 33601 | } | ||
| 33602 | |||
| 33603 | $gaugeObj = $self->ivShow('statusBarHash', $number); | ||
| 33604 | # If the status bar with this local $number exists... | ||
| 33605 | if ($gaugeObj) { | ||
| 33606 | |||
| 33607 | $gaugeObj->ivPoke('value', $val); | ||
| 33608 | $gaugeObj->ivPoke('maxValue', $maxVal); | ||
| 33609 | |||
| 33610 | $self->gaugeStripObj->updateGauges(); | ||
| 33611 | } | ||
| 33612 | |||
| 33613 | return 1; | ||
| 33614 | } | ||
| 33615 | |||
| 33616 | sub addTaskWinGauge { | ||
| 33617 | |||
| 33618 | # Called by LA::Statement::winaddgauge->implement or ::winaddcongauge->implement | ||
| 33619 | # Adds a task window gauge, creating a new gauge level if one doesn't already exist for | ||
| 33620 | # this task | ||
| 33621 | # | ||
| 33622 | # Expected arguments | ||
| 33623 | # $number - A local gauge number for this task | ||
| 33624 | # (not related to GA::Obj::Gauge->number). The Language::Axbasic script | ||
| 33625 | # can specify any integer number >= 0. If this task has already created a | ||
| 33626 | # gauge with that local number, it is replaced | ||
| 33627 | # $label - The label to use. If it's an empty string, this function assigns its own | ||
| 33628 | # label | ||
| 33629 | # $addFlag - Flag matching GA::Obj::Gauge->addFlag. FALSE when called by WINADDGAUGE | ||
| 33630 | # statements, TRUE when called by WINADDCONGAUGE statements | ||
| 33631 | # | ||
| 33632 | # Optional arguments | ||
| 33633 | # $fullCol - The colour of the full portion of the gauge. Must be an Axmud colour tag | ||
| 33634 | # (including standard, xterm and RGB tags). If an empty string, 'undef' or | ||
| 33635 | # an invalid colour tag, the default gauge colour is used | ||
| 33636 | # $emptyCol - The colour of the empty portion of the gauge | ||
| 33637 | # $labelCol - The colour of the label | ||
| 33638 | # | ||
| 33639 | # Return values | ||
| 33640 | # 'undef' on improper arguments or if the gauge can't be added | ||
| 33641 | # 1 otherwise | ||
| 33642 | |||
| 33643 | my ($self, $number, $label, $addFlag, $fullCol, $emptyCol, $labelCol, $check) = @_; | ||
| 33644 | |||
| 33645 | # Local variables | ||
| 33646 | my ($stripObj, $level, $gaugeObj, $fullType, $emptyType, $labelType); | ||
| 33647 | |||
| 33648 | # Check for improper arguments | ||
| 33649 | if ( | ||
| 33650 | ! defined $number || ! defined $label || ! defined $addFlag || defined $check | ||
| 33651 | ) { | ||
| 33652 | return $axmud::CLIENT->writeImproper($self->_objClass . '->addTaskWinGauge', @_); | ||
| 33653 | } | ||
| 33654 | |||
| 33655 | # The standard winmaps used by tasks don't provide gauges, so insert one ourselves | ||
| 33656 | if (! $self->taskWinGaugeStripObj) { | ||
| 33657 | |||
| 33658 | $stripObj = $self->winObj->addStripObj('Games::Axmud::Strip::GaugeBox'); | ||
| 33659 | if (! $stripObj) { | ||
| 33660 | |||
| 33661 | return undef; | ||
| 33662 | |||
| 33663 | } else { | ||
| 33664 | |||
| 33665 | $self->ivPoke('taskWinGaugeStripObj', $stripObj); | ||
| 33666 | } | ||
| 33667 | } | ||
| 33668 | |||
| 33669 | # Add a gauge level for this task, if one doesn't already exist | ||
| 33670 | if (! defined $self->taskWinGaugeLevel) { | ||
| 33671 | |||
| 33672 | # The TRUE flag means 'don't draw it yet' | ||
| 33673 | $level = $self->taskWinGaugeStripObj->addGaugeLevel($self->session, TRUE); | ||
| 33674 | if (! defined $level) { | ||
| 33675 | |||
| 33676 | return undef; | ||
| 33677 | |||
| 33678 | } else { | ||
| 33679 | |||
| 33680 | $self->ivPoke('taskWinGaugeLevel', $level); | ||
| 33681 | } | ||
| 33682 | } | ||
| 33683 | |||
| 33684 | # If this task has already created a gauge with the local number $number, remove it | ||
| 33685 | if ($self->ivExists('taskWinGaugeHash', $number)) { | ||
| 33686 | |||
| 33687 | $self->taskWinGaugeStripObj->removeGauges( | ||
| 33688 | $self->session, | ||
| 33689 | TRUE, | ||
| 33690 | $self->ivShow('taskWinGaugeHash', $number), | ||
| 33691 | ); | ||
| 33692 | } | ||
| 33693 | |||
| 33694 | # Convert the specified colour tags into RGB colour tags (or use default colours, if the | ||
| 33695 | # specified tags are invalid) | ||
| 33696 | if (defined $fullCol) { | ||
| 33697 | |||
| 33698 | ($fullType) = $axmud::CLIENT->checkColourTags($fullCol); | ||
| 33699 | } | ||
| 33700 | |||
| 33701 | if (! $fullType) { | ||
| 33702 | $fullCol = $self->taskWinGaugeStripObj->gaugeFullColour; | ||
| 33703 | } else { | ||
| 33704 | $fullCol = $axmud::CLIENT->returnRGBColour($fullCol); | ||
| 33705 | } | ||
| 33706 | |||
| 33707 | if (defined $emptyCol) { | ||
| 33708 | |||
| 33709 | ($emptyType) = $axmud::CLIENT->checkColourTags($emptyCol); | ||
| 33710 | } | ||
| 33711 | |||
| 33712 | if (! $emptyType) { | ||
| 33713 | $emptyCol = $self->taskWinGaugeStripObj->gaugeEmptyColour; | ||
| 33714 | } else { | ||
| 33715 | $emptyCol = $axmud::CLIENT->returnRGBColour($emptyCol); | ||
| 33716 | } | ||
| 33717 | |||
| 33718 | if (defined $labelCol) { | ||
| 33719 | |||
| 33720 | ($labelType) = $axmud::CLIENT->checkColourTags($labelCol); | ||
| 33721 | if (! $labelType) { | ||
| 33722 | $labelCol = $self->taskWinGaugeStripObj->gaugeLabelColour; | ||
| 33723 | } else { | ||
| 33724 | $labelCol = $axmud::CLIENT->returnRGBColour($labelCol); | ||
| 33725 | } | ||
| 33726 | } | ||
| 33727 | |||
| 33728 | # Assign a label, if none was specified | ||
| 33729 | if ($label eq '') { | ||
| 33730 | |||
| 33731 | $label = 'Gauge ' . $number; | ||
| 33732 | } | ||
| 33733 | |||
| 33734 | # Add the gauge | ||
| 33735 | $gaugeObj = $self->taskWinGaugeStripObj->addGauge( | ||
| 33736 | $self->session, | ||
| 33737 | $self->taskWinGaugeLevel, | ||
| 33738 | undef, | ||
| 33739 | undef, | ||
| 33740 | $addFlag, | ||
| 33741 | $label, | ||
| 33742 | $fullCol, | ||
| 33743 | $emptyCol, | ||
| 33744 | $labelCol, | ||
| 33745 | TRUE, | ||
| 33746 | ); | ||
| 33747 | |||
| 33748 | if ($gaugeObj) { | ||
| 33749 | |||
| 33750 | $self->ivAdd('taskWinGaugeHash', $number, $gaugeObj); | ||
| 33751 | } | ||
| 33752 | |||
| 33753 | $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->addTaskWinGauge'); | ||
| 33754 | |||
| 33755 | return 1; | ||
| 33756 | } | ||
| 33757 | |||
| 33758 | sub deleteTaskWinGauge { | ||
| 33759 | |||
| 33760 | # Called by LA::Statement::windelgauge->implement | ||
| 33761 | # Deletes a task window gauge, removing the gauge level if there are no gauges/status bars | ||
| 33762 | # left for this task | ||
| 33763 | # | ||
| 33764 | # Expected arguments | ||
| 33765 | # $number - A local gauge number for this task, matching a key in | ||
| 33766 | # $self->taskWinGaugeHash (not related to GA::Obj::Gauge->number) | ||
| 33767 | # | ||
| 33768 | # Return values | ||
| 33769 | # 'undef' on improper arguments | ||
| 33770 | # 1 otherwise | ||
| 33771 | |||
| 33772 | my ($self, $number, $check) = @_; | ||
| 33773 | |||
| 33774 | # Check for improper arguments | ||
| 33775 | if (! defined $number || defined $check) { | ||
| 33776 | |||
| 33777 | return $axmud::CLIENT->writeImproper($self->_objClass . '->deleteTaskWinGauge', @_); | ||
| 33778 | } | ||
| 33779 | |||
| 33780 | # Delete the gauge with this local $number, if it exists | ||
| 33781 | if ($self->ivExists('taskWinGaugeHash', $number)) { | ||
| 33782 | |||
| 33783 | $self->taskWinGaugeStripObj->removeGauges( | ||
| 33784 | $self->session, | ||
| 33785 | FALSE, | ||
| 33786 | $self->ivShow('taskWinGaugeHash', $number), | ||
| 33787 | ); | ||
| 33788 | |||
| 33789 | $self->ivDelete('taskWinGaugeHash', $number); | ||
| 33790 | |||
| 33791 | # If there are no more gauges/status bars left for this task, remove the gauge level | ||
| 33792 | # assigned to it | ||
| 33793 | if (! $self->taskWinGaugeHash && ! $self->taskWinStatusBarHash) { | ||
| 33794 | |||
| 33795 | $self->taskWinGaugeStripObj->removeGaugeLevel( | ||
| 33796 | $self->session, $self->taskWinGaugeLevel, | ||
| 33797 | ); | ||
| 33798 | } | ||
| 33799 | } | ||
| 33800 | |||
| 33801 | return 1; | ||
| 33802 | } | ||
| 33803 | |||
| 33804 | sub setTaskWinGauge { | ||
| 33805 | |||
| 33806 | # Called by LA::Statement::winsetgauge->implement | ||
| 33807 | # Sets the values displayed by the gauge, and tells the gauge box to re-draw its gauges | ||
| 33808 | # | ||
| 33809 | # Expected arguments | ||
| 33810 | # $number - A local gauge number for this task, matching a key in | ||
| 33811 | # $self->taskWinGaugeHash (not related to GA::Obj::Gauge->number) | ||
| 33812 | # | ||
| 33813 | # Optional arguments | ||
| 33814 | # $val - The value to use for the full portion of the gauge. Can be set to 'undef' | ||
| 33815 | # if the value supplied by the Axbasic script wasn't a valid decimal | ||
| 33816 | # number | ||
| 33817 | # $maxVal - The value to use for the empty portion of the gauge. Can also be set to | ||
| 33818 | # 'undef' | ||
| 33819 | # | ||
| 33820 | # Return values | ||
| 33821 | # 'undef' on improper arguments | ||
| 33822 | # 1 otherwise | ||
| 33823 | |||
| 33824 | my ($self, $number, $val, $maxVal, $check) = @_; | ||
| 33825 | |||
| 33826 | # Local variables | ||
| 33827 | my $gaugeObj; | ||
| 33828 | |||
| 33829 | # Check for improper arguments | ||
| 33830 | if (! defined $number || defined $check) { | ||
| 33831 | |||
| 33832 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setTaskWinGauge', @_); | ||
| 33833 | } | ||
| 33834 | |||
| 33835 | $gaugeObj = $self->ivShow('taskWinGaugeHash', $number); | ||
| 33836 | # If the gauge with this local $number exists... | ||
| 33837 | if ($gaugeObj) { | ||
| 33838 | |||
| 33839 | $gaugeObj->ivPoke('value', $val); | ||
| 33840 | $gaugeObj->ivPoke('maxValue', $maxVal); | ||
| 33841 | |||
| 33842 | $self->taskWinGaugeStripObj->updateGauges(); | ||
| 33843 | } | ||
| 33844 | |||
| 33845 | return 1; | ||
| 33846 | } | ||
| 33847 | |||
| 33848 | sub addTaskWinStatusBar { | ||
| 33849 | |||
| 33850 | # Called by LA::Statement::winaddstatus->implement or ::winaddconstatus->implement | ||
| 33851 | # Adds a task window status bar, creating a new gauge level if one doesn't already exist for | ||
| 33852 | # this task | ||
| 33853 | # | ||
| 33854 | # Expected arguments | ||
| 33855 | # $number - A local status bar number for this task | ||
| 33856 | # (not related to GA::Obj::Gauge->number). The Axbasic script can specify | ||
| 33857 | # any integer number >= 0. If this task has already created a status bar | ||
| 33858 | # with that local number, it is replaced | ||
| 33859 | # $label - The label to use. If it's an empty string, this function assigns its own | ||
| 33860 | # label | ||
| 33861 | # $addFlag - Flag matching GA::Obj::Gauge->addFlag. FALSE when called by WINADDSTATUS | ||
| 33862 | # statements, TRUE when called by WINADDCONSTATUS statements | ||
| 33863 | # | ||
| 33864 | # Return values | ||
| 33865 | # 'undef' on improper arguments or if the gauge can't be added | ||
| 33866 | # 1 otherwise | ||
| 33867 | |||
| 33868 | my ($self, $number, $label, $addFlag, $check) = @_; | ||
| 33869 | |||
| 33870 | # Local variables | ||
| 33871 | my ($stripObj, $level, $gaugeObj); | ||
| 33872 | |||
| 33873 | # Check for improper arguments | ||
| 33874 | if (! defined $number || ! defined $label || ! defined $addFlag || defined $check) { | ||
| 33875 | |||
| 33876 | return $axmud::CLIENT->writeImproper($self->_objClass . '->addTaskWinStatusBar', @_); | ||
| 33877 | } | ||
| 33878 | |||
| 33879 | # The standard winmaps used by tasks don't provide gauges, so insert one ourselves | ||
| 33880 | if (! $self->taskWinGaugeStripObj) { | ||
| 33881 | |||
| 33882 | $stripObj = $self->winObj->addStripObj('Games::Axmud::Strip::GaugeBox'); | ||
| 33883 | if (! $stripObj) { | ||
| 33884 | |||
| 33885 | return undef; | ||
| 33886 | |||
| 33887 | } else { | ||
| 33888 | |||
| 33889 | $self->ivPoke('taskWinGaugeStripObj', $stripObj); | ||
| 33890 | } | ||
| 33891 | } | ||
| 33892 | |||
| 33893 | # Add a gauge level for this task, if one doesn't already exist | ||
| 33894 | if (! defined $self->taskWinGaugeLevel) { | ||
| 33895 | |||
| 33896 | # The TRUE flag means 'don't draw it yet' | ||
| 33897 | $level = $self->taskWinGaugeStripObj->addGaugeLevel($self->session, TRUE); | ||
| 33898 | if (! defined $level) { | ||
| 33899 | |||
| 33900 | return undef; | ||
| 33901 | |||
| 33902 | } else { | ||
| 33903 | |||
| 33904 | $self->ivPoke('taskWinGaugeLevel', $level); | ||
| 33905 | } | ||
| 33906 | } | ||
| 33907 | |||
| 33908 | # If this task has already created a status bar with the local number $number, remove it | ||
| 33909 | if ($self->ivExists('taskWinStatusBarHash', $number)) { | ||
| 33910 | |||
| 33911 | $self->taskWinGaugeStripObj->removeGauges( | ||
| 33912 | $self->session, | ||
| 33913 | FALSE, | ||
| 33914 | $self->ivShow('taskWinStatusBarHash', $number), | ||
| 33915 | ); | ||
| 33916 | } | ||
| 33917 | |||
| 33918 | # Assign a label, if none was specified | ||
| 33919 | if ($label eq '') { | ||
| 33920 | |||
| 33921 | $label = 'Bar ' . $number; | ||
| 33922 | } | ||
| 33923 | |||
| 33924 | # Add the status bar | ||
| 33925 | $gaugeObj = $self->taskWinGaugeStripObj->addTextGauge( | ||
| 33926 | $self->session, | ||
| 33927 | $self->taskWinGaugeLevel, | ||
| 33928 | undef, | ||
| 33929 | undef, | ||
| 33930 | $addFlag, | ||
| 33931 | $label, | ||
| 33932 | ); | ||
| 33933 | |||
| 33934 | if ($gaugeObj) { | ||
| 33935 | |||
| 33936 | $self->ivAdd('taskWinStatusBarHash', $number, $gaugeObj); | ||
| 33937 | } | ||
| 33938 | |||
| 33939 | $axmud::CLIENT->desktopObj->updateWidgets($self->_objClass . '->addTaskWinStatusBar'); | ||
| 33940 | |||
| 33941 | return 1; | ||
| 33942 | } | ||
| 33943 | |||
| 33944 | sub deleteTaskWinStatusBar { | ||
| 33945 | |||
| 33946 | # Called by LA::Statement::windelstatus->implement | ||
| 33947 | # Deletes a task window status bar, removing the gauge level if there are no gauges/status | ||
| 33948 | # bars left for this task | ||
| 33949 | # | ||
| 33950 | # Expected arguments | ||
| 33951 | # $number - A local status bar number for this task, matching a key in | ||
| 33952 | # $self->taskWinStatusBarHash (not related to GA::Obj::Gauge->number) | ||
| 33953 | # | ||
| 33954 | # Return values | ||
| 33955 | # 'undef' on improper arguments | ||
| 33956 | # 1 otherwise | ||
| 33957 | |||
| 33958 | my ($self, $number, $check) = @_; | ||
| 33959 | |||
| 33960 | # Check for improper arguments | ||
| 33961 | if (! defined $number || defined $check) { | ||
| 33962 | |||
| 33963 | return $axmud::CLIENT->writeImproper($self->_objClass . '->deleteTaskWinStatusBar', @_); | ||
| 33964 | } | ||
| 33965 | |||
| 33966 | # Delete the status bar with this local $number, if it exists | ||
| 33967 | if ($self->ivExists('taskWinStatusBarHash', $number)) { | ||
| 33968 | |||
| 33969 | $self->taskWinGaugeStripObj->removeGauges( | ||
| 33970 | $self->session, | ||
| 33971 | FALSE, | ||
| 33972 | $self->ivShow('taskWinStatusBarHash', $number), | ||
| 33973 | ); | ||
| 33974 | |||
| 33975 | $self->ivDelete('taskWinStatusBarHash', $number); | ||
| 33976 | |||
| 33977 | # If there are no more gauges/status bars left for this task, remove the gauge level | ||
| 33978 | # assigned to it | ||
| 33979 | if (! $self->taskWinGaugeHash && ! $self->taskWinStatusBarHash) { | ||
| 33980 | |||
| 33981 | $self->taskWinGaugeStripObj->removeGaugeLevel( | ||
| 33982 | $self->session, $self->taskWinGaugeLevel, | ||
| 33983 | ); | ||
| 33984 | } | ||
| 33985 | } | ||
| 33986 | |||
| 33987 | return 1; | ||
| 33988 | } | ||
| 33989 | |||
| 33990 | sub setTaskWinStatusBar { | ||
| 33991 | |||
| 33992 | # Called by LA::Statement::winsetstatus->implement | ||
| 33993 | # Sets the values displayed by the status bar, and tells the 'main' window to re-draw its | ||
| 33994 | # gauges/status bars | ||
| 33995 | # | ||
| 33996 | # Expected arguments | ||
| 33997 | # $number - A local status bar number for this task, matching a key in | ||
| 33998 | # $self->taskWinStatusBarHash (not related to GA::Obj::Gauge->number) | ||
| 33999 | # | ||
| 34000 | # Optional arguments | ||
| 34001 | # $val - The value to use that's the equivalent of the full portion of a | ||
| 34002 | # (graphical) gauge. Can be set to 'undef' if the value supplied by the | ||
| 34003 | # Axbasic script wasn't a valid decimal number | ||
| 34004 | # $maxVal - The value to use that's the equivalent of the empty portion of a | ||
| 34005 | # (graphical) gauge. Can also be set to 'undef' | ||
| 34006 | # | ||
| 34007 | # Return values | ||
| 34008 | # 'undef' on improper arguments | ||
| 34009 | # 1 otherwise | ||
| 34010 | |||
| 34011 | my ($self, $number, $val, $maxVal, $check) = @_; | ||
| 34012 | |||
| 34013 | # Local variables | ||
| 34014 | my $gaugeObj; | ||
| 34015 | |||
| 34016 | # Check for improper arguments | ||
| 34017 | if (! defined $number || defined $check) { | ||
| 34018 | |||
| 34019 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setTaskWinStatusBar', @_); | ||
| 34020 | } | ||
| 34021 | |||
| 34022 | $gaugeObj = $self->ivShow('taskWinStatusBarHash', $number); | ||
| 34023 | # If the status bar with this local $number exists... | ||
| 34024 | if ($gaugeObj) { | ||
| 34025 | |||
| 34026 | $gaugeObj->ivPoke('value', $val); | ||
| 34027 | $gaugeObj->ivPoke('maxValue', $maxVal); | ||
| 34028 | |||
| 34029 | $self->taskWinGaugeStripObj->updateGauges(); | ||
| 34030 | } | ||
| 34031 | |||
| 34032 | return 1; | ||
| 34033 | } | ||
| 34034 | |||
| 34035 | ################## | ||
| 34036 | # Response methods | ||
| 34037 | |||
| 34038 | sub interfaceWaitSeen { | ||
| 34039 | |||
| 34040 | # Called by GA::Session->processLineSegment, after that function has called ->checkTriggers; | ||
| 34041 | # or by GA::Session->checkAliases, ->checkMacros (etc) | ||
| 34042 | # | ||
| 34043 | # The Axbasic statement WAITTRIG causes the script to create a trigger to wait for a | ||
| 34044 | # particular pattern in the text received from the world | ||
| 34045 | # e.g. The door swings open! | ||
| 34046 | # | ||
| 34047 | # When the pattern is found, the script resumes. WAITALIAS, WAITMACRO, WAITTIMER and | ||
| 34048 | # WAITHOOK behave in similar ways | ||
| 34049 | # This function updates IVs and resumes this task, which should be paused. Group substrings | ||
| 34050 | # (for triggers/aliases) and additional data (for timers/hooks) are ignored | ||
| 34051 | # | ||
| 34052 | # Expected arguments | ||
| 34053 | # $session - The calling function's GA::Session | ||
| 34054 | # $interfaceNum - The number of the active trigger interface that fired | ||
| 34055 | # @ignoreList - Any other data supplied by the calling function is added to this list | ||
| 34056 | # and ignored | ||
| 34057 | # | ||
| 34058 | # Return values | ||
| 34059 | # 'undef' on improper arguments or if $session is the wrong session | ||
| 34060 | # 1 otherwise | ||
| 34061 | |||
| 34062 | my ($self, $session, $interfaceNum, @ignoreList) = @_; | ||
| 34063 | |||
| 34064 | # Local variables | ||
| 34065 | my $obj; | ||
| 34066 | |||
| 34067 | # Check for improper arguments | ||
| 34068 | if (! defined $session || ! defined $interfaceNum ) { | ||
| 34069 | |||
| 34070 | return $axmud::CLIENT->writeImproper($self->_objClass . '->interfaceWaitSeen', @_); | ||
| 34071 | } | ||
| 34072 | |||
| 34073 | # Basic check - the trigger should belong to the right session | ||
| 34074 | if ($session ne $self->session) { | ||
| 34075 | |||
| 34076 | return undef; | ||
| 34077 | } | ||
| 34078 | |||
| 34079 | # (Standard code commented out, because the temporary interface has already deleted itself) | ||
| 34080 | # # Get the interface object itself | ||
| 34081 | # $obj = $session->ivShow('interfaceNumHash', $interfaceNum); | ||
| 34082 | # if (! $obj) { | ||
| 34083 | # | ||
| 34084 | # return undef; | ||
| 34085 | # } | ||
| 34086 | |||
| 34087 | # Respond to the fired interface | ||
| 34088 | |||
| 34089 | # Update the AB::Script's list of dependent interfaces to remove the one that has just | ||
| 34090 | # fired (it's a temporary interface which the GA::Session is going to delete soon) | ||
| 34091 | $self->scriptObj->updateInterfaces($self->waitForInterface); | ||
| 34092 | # After a pause, the script's step count (how many statements to execute before taking a | ||
| 34093 | # short break) needs to be reset | ||
| 34094 | $self->scriptObj->set_stepCount(0); | ||
| 34095 | |||
| 34096 | # Update this task's IVs | ||
| 34097 | $self->resetInterface(); | ||
| 34098 | |||
| 34099 | return 1; | ||
| 34100 | } | ||
| 34101 | |||
| 34102 | sub triggerNotifySeen { | ||
| 34103 | |||
| 34104 | # Called by GA::Session->processLineSegment, after that function has called ->checkTriggers | ||
| 34105 | # | ||
| 34106 | # The Axbasic statement SETTRIG causes the script to create a trigger to notice a particular | ||
| 34107 | # pattern in the text received from the world | ||
| 34108 | # e.g. The orc attacks you | ||
| 34109 | # | ||
| 34110 | # If SETTRIG specified a second script to run, this function runs it. Otherwise, this | ||
| 34111 | # function notifies the script that the pattern was found | ||
| 34112 | # | ||
| 34113 | # The trigger interface has the following properties in ->propertyHash: | ||
| 34114 | # new_script - The name of the second script to run (only used in calls to | ||
| 34115 | # $self->triggerExecSeen, 'undef' in calls to this function) | ||
| 34116 | # | ||
| 34117 | # Expected arguments (standard args from GA::Session->checkTriggers) | ||
| 34118 | # $session - The calling function's GA::Session | ||
| 34119 | # $interfaceNum - The number of the active trigger interface that fired | ||
| 34120 | # $line - The line of text received from the world | ||
| 34121 | # $stripLine - $line, with all escape sequences removed | ||
| 34122 | # $modLine - $stripLine, possibly modified by previously-checked triggers | ||
| 34123 | # $grpStringListRef | ||
| 34124 | # - Reference to a list of group substrings from the pattern match | ||
| 34125 | # (equivalent of @_) | ||
| 34126 | # $matchMinusListRef | ||
| 34127 | # - Reference to a list of matched substring offsets (equivalent of @-) | ||
| 34128 | # $matchPlusListRef | ||
| 34129 | # - Reference to a list of matched substring offsets (equivalent of @+) | ||
| 34130 | # | ||
| 34131 | # Return values | ||
| 34132 | # 'undef' on improper arguments, or if $session is the wrong session or if the interface | ||
| 34133 | # object can't be found | ||
| 34134 | # 1 otherwise | ||
| 34135 | |||
| 34136 | my ( | ||
| 34137 | $self, $session, $interfaceNum, $line, $stripLine, $modLine, $grpStringListRef, | ||
| 34138 | $matchMinusListRef, $matchPlusListRef, $check, | ||
| 34139 | ) = @_; | ||
| 34140 | |||
| 34141 | # Local variables | ||
| 34142 | my ($obj, $scriptName); | ||
| 34143 | |||
| 34144 | # Check for improper arguments | ||
| 34145 | if ( | ||
| 34146 | ! defined $session || ! defined $interfaceNum || ! defined $line || ! defined $stripLine | ||
| 34147 | || ! defined $modLine || ! defined $grpStringListRef || ! defined $matchMinusListRef | ||
| 34148 | || ! defined $matchPlusListRef || defined $check | ||
| 34149 | ) { | ||
| 34150 | return $axmud::CLIENT->writeImproper($self->_objClass . '->triggerNotifySeen', @_); | ||
| 34151 | } | ||
| 34152 | |||
| 34153 | # Basic check - the trigger should belong to the right session | ||
| 34154 | if ($session ne $self->session) { | ||
| 34155 | |||
| 34156 | return undef; | ||
| 34157 | } | ||
| 34158 | |||
| 34159 | # Get the interface object itself | ||
| 34160 | $obj = $session->ivShow('interfaceNumHash', $interfaceNum); | ||
| 34161 | if (! $obj) { | ||
| 34162 | |||
| 34163 | return undef; | ||
| 34164 | } | ||
| 34165 | |||
| 34166 | # Respond to the fired trigger | ||
| 34167 | $scriptName = $obj->ivShow('propertyHash', 'new_script'); | ||
| 34168 | if ($scriptName) { | ||
| 34169 | |||
| 34170 | # SETTRIG statement specified a second script to run | ||
| 34171 | return $self->session->pseudoCmd('runscript ' . $scriptName); | ||
| 34172 | |||
| 34173 | } else { | ||
| 34174 | |||
| 34175 | # No second script to to run. Notify the Axbasic programme that one of its dependent | ||
| 34176 | # triggers has fired | ||
| 34177 | $self->scriptObj->interfaceNotification($obj, $modLine, @$grpStringListRef); | ||
| 34178 | |||
| 34179 | return 1; | ||
| 34180 | } | ||
| 34181 | } | ||
| 34182 | |||
| 34183 | sub aliasNotifySeen { | ||
| 34184 | |||
| 34185 | # Called by GA::Session->checkAliases | ||
| 34186 | # | ||
| 34187 | # The Axbasic statement SETALIAS causes the script to create an alias to notice when a | ||
| 34188 | # particular world command is entered | ||
| 34189 | # e.g. The orc attacks you | ||
| 34190 | # | ||
| 34191 | # If SETALIAS specified a second script to run, this function runs it. Otherwise, this | ||
| 34192 | # function notifies the script that the matching command was processed. (The world command | ||
| 34193 | # is not sent to the world, as normal) | ||
| 34194 | # | ||
| 34195 | # The alias interface has the following properties in ->propertyHash: | ||
| 34196 | # new_script - The name of the second script to run (only used in calls to | ||
| 34197 | # $self->aliasExecSeen, 'undef' in calls to this function) | ||
| 34198 | # | ||
| 34199 | # Expected arguments (standard args from GA::Session->checkAliases) | ||
| 34200 | # $session - The calling function's GA::Session | ||
| 34201 | # $interfaceNum - The number of the active alias interface that fired | ||
| 34202 | # $worldCmd - The world command that caused the alias to fire | ||
| 34203 | # | ||
| 34204 | # Optional arguments | ||
| 34205 | # @groupStringList - A list of group substrings from the pattern match (equivalent of @_, | ||
| 34206 | # may be an empty list) | ||
| 34207 | # | ||
| 34208 | # Return values | ||
| 34209 | # 'undef' on improper arguments, or if $session is the wrong session or if the interface | ||
| 34210 | # object can't be found | ||
| 34211 | # 1 otherwise | ||
| 34212 | |||
| 34213 | my ($self, $session, $interfaceNum, $worldCmd, @groupStringList) = @_; | ||
| 34214 | |||
| 34215 | # Local variables | ||
| 34216 | my ($obj, $scriptName); | ||
| 34217 | |||
| 34218 | # Check for improper arguments | ||
| 34219 | if (! defined $session || ! defined $interfaceNum || ! defined $worldCmd) { | ||
| 34220 | |||
| 34221 | return $axmud::CLIENT->writeImproper($self->_objClass . '->aliasNotifySeen', @_); | ||
| 34222 | } | ||
| 34223 | |||
| 34224 | # Basic check - the alias should belong to the right session | ||
| 34225 | if ($session ne $self->session) { | ||
| 34226 | |||
| 34227 | return undef; | ||
| 34228 | } | ||
| 34229 | |||
| 34230 | # Get the interface object itself | ||
| 34231 | $obj = $session->ivShow('interfaceNumHash', $interfaceNum); | ||
| 34232 | if (! $obj) { | ||
| 34233 | |||
| 34234 | return undef; | ||
| 34235 | } | ||
| 34236 | |||
| 34237 | # Respond to the fired alias | ||
| 34238 | $scriptName = $obj->ivShow('propertyHash', 'new_script'); | ||
| 34239 | if ($scriptName) { | ||
| 34240 | |||
| 34241 | # SETALIAS statement specified a second script to run | ||
| 34242 | return $self->session->pseudoCmd('runscript ' . $scriptName); | ||
| 34243 | |||
| 34244 | } else { | ||
| 34245 | |||
| 34246 | # No second script to run. Notify the Axbasic programme that one of its dependent | ||
| 34247 | # aliases has fired | ||
| 34248 | $self->scriptObj->interfaceNotification($obj, $worldCmd, @groupStringList); | ||
| 34249 | } | ||
| 34250 | |||
| 34251 | return 1; | ||
| 34252 | } | ||
| 34253 | |||
| 34254 | sub macroNotifySeen { | ||
| 34255 | |||
| 34256 | # Called by GA::Session->checkMacros | ||
| 34257 | # | ||
| 34258 | # The Axbasic statement SETMACRO causes the script to create a macro to notice a keypress or | ||
| 34259 | # a combination of keypresses | ||
| 34260 | # e.g. 'ctrl f1' | ||
| 34261 | # | ||
| 34262 | # If SETMACRO specified a second script to run, this function runs it. Otherwise, this | ||
| 34263 | # function notifies the script that the keycode string was processed (and only the script | ||
| 34264 | # will do something in response) | ||
| 34265 | # | ||
| 34266 | # The macro interface has the following properties in ->propertyHash: | ||
| 34267 | # new_script - The name of the second script to run (only used in calls to | ||
| 34268 | # $self->macroExecSeen, 'undef' in calls to this function) | ||
| 34269 | # | ||
| 34270 | # Expected arguments (standard args from GA::Session->checkMacros) | ||
| 34271 | # $session - The calling function's GA::Session | ||
| 34272 | # $interfaceNum - The number of the active macro interface that fired | ||
| 34273 | # $keycodeString - The keycode string for keypress(es) that caused the macro to fire | ||
| 34274 | # | ||
| 34275 | # Return values | ||
| 34276 | # 'undef' on improper arguments, or if $session is the wrong session or if the interface | ||
| 34277 | # object can't be found | ||
| 34278 | # 1 otherwise | ||
| 34279 | |||
| 34280 | my ($self, $session, $interfaceNum, $keycodeString, $check) = @_; | ||
| 34281 | |||
| 34282 | # Local variables | ||
| 34283 | my ($obj, $scriptName); | ||
| 34284 | |||
| 34285 | # Check for improper arguments | ||
| 34286 | if ( | ||
| 34287 | ! defined $session || ! defined $interfaceNum || ! defined $keycodeString | ||
| 34288 | || defined $check | ||
| 34289 | ) { | ||
| 34290 | return $axmud::CLIENT->writeImproper($self->_objClass . '->macroNotifySeen', @_); | ||
| 34291 | } | ||
| 34292 | |||
| 34293 | # Basic check - the macro should belong to the right session | ||
| 34294 | if ($session ne $self->session) { | ||
| 34295 | |||
| 34296 | return undef; | ||
| 34297 | } | ||
| 34298 | |||
| 34299 | # Get the interface object itself | ||
| 34300 | $obj = $session->ivShow('interfaceNumHash', $interfaceNum); | ||
| 34301 | if (! $obj) { | ||
| 34302 | |||
| 34303 | return undef; | ||
| 34304 | } | ||
| 34305 | |||
| 34306 | # Respond to the fired macro | ||
| 34307 | $scriptName = $obj->ivShow('propertyHash', 'new_script'); | ||
| 34308 | if ($scriptName) { | ||
| 34309 | |||
| 34310 | # SETMACRO statement specified a second script to run | ||
| 34311 | return $self->session->pseudoCmd('runscript ' . $scriptName); | ||
| 34312 | |||
| 34313 | } else { | ||
| 34314 | |||
| 34315 | # No second script to to run. Notify the Axbasic programme that one of its dependent | ||
| 34316 | # macros has fired | ||
| 34317 | $self->scriptObj->interfaceNotification($obj, $keycodeString); | ||
| 34318 | |||
| 34319 | return 1; | ||
| 34320 | } | ||
| 34321 | } | ||
| 34322 | |||
| 34323 | sub timerNotifySeen { | ||
| 34324 | |||
| 34325 | # Called by GA::Session->checkTimers | ||
| 34326 | # | ||
| 34327 | # The Axbasic statement SETTIMER causes the script to notice when a timer it has created has | ||
| 34328 | # fired | ||
| 34329 | # | ||
| 34330 | # If SETTIMER specified a second script to run, this function runs it. Otherwise, this | ||
| 34331 | # function notifies the script that the timer has fired (and only the script will do | ||
| 34332 | # something in response) | ||
| 34333 | # | ||
| 34334 | # The timer interfaces have the following properties in ->propertyHash: | ||
| 34335 | # new_script - The name of the second script to run (only used in calls to | ||
| 34336 | # $self->timerExecSeen, 'undef' in calls to this function) | ||
| 34337 | # | ||
| 34338 | # Expected arguments (standard args from GA::Session->checkTimers) | ||
| 34339 | # $session - The calling function's GA::Session | ||
| 34340 | # $interfaceNum - The number of the active timer interface that fired | ||
| 34341 | # $sessionTime - The value of GA::Session->sessionTime when the hook fired | ||
| 34342 | # $otherTime - For timers whose stimulus is an interval, the time (matches | ||
| 34343 | # GA::Session->sessionTime) at which the timer was due to fire. This | ||
| 34344 | # value will be less than or the same as $sessionTime. For timers | ||
| 34345 | # whose stimulus is a clock time (in the form HH:MM firing once a day, | ||
| 34346 | # or 99:MM firing once an hour, at MM minutes past the hour), the | ||
| 34347 | # stimulus itself | ||
| 34348 | # | ||
| 34349 | # Return values | ||
| 34350 | # 'undef' on improper arguments, or if $session is the wrong session or if the interface | ||
| 34351 | # object can't be found | ||
| 34352 | # 1 otherwise | ||
| 34353 | |||
| 34354 | my ($self, $session, $interfaceNum, $sessionTime, $otherTime, $check) = @_; | ||
| 34355 | |||
| 34356 | # Local variables | ||
| 34357 | my ($obj, $scriptName); | ||
| 34358 | |||
| 34359 | # Check for improper arguments | ||
| 34360 | if ( | ||
| 34361 | ! defined $session || ! defined $interfaceNum || ! defined $sessionTime | ||
| 34362 | || ! defined $otherTime || defined $check | ||
| 34363 | ) { | ||
| 34364 | return $axmud::CLIENT->writeImproper($self->_objClass . '->timerNotifySeen', @_); | ||
| 34365 | } | ||
| 34366 | |||
| 34367 | # Basic check - the timer should belong to the right session | ||
| 34368 | if ($session ne $self->session) { | ||
| 34369 | |||
| 34370 | return undef; | ||
| 34371 | } | ||
| 34372 | |||
| 34373 | # Get the interface object itself | ||
| 34374 | $obj = $session->ivShow('interfaceNumHash', $interfaceNum); | ||
| 34375 | if (! $obj) { | ||
| 34376 | |||
| 34377 | return undef; | ||
| 34378 | } | ||
| 34379 | |||
| 34380 | # Respond to the fired timer | ||
| 34381 | $scriptName = $obj->ivShow('propertyHash', 'new_script'); | ||
| 34382 | if ($scriptName) { | ||
| 34383 | |||
| 34384 | # SETTIMER statement specified a second script to run | ||
| 34385 | return $self->session->pseudoCmd('runscript ' . $scriptName); | ||
| 34386 | |||
| 34387 | } else { | ||
| 34388 | |||
| 34389 | # No second script to to run. Notify the Axbasic programme that one of its dependent | ||
| 34390 | # timers has fired | ||
| 34391 | $self->scriptObj->interfaceNotification($obj, $sessionTime, $otherTime); | ||
| 34392 | |||
| 34393 | return 1; | ||
| 34394 | } | ||
| 34395 | } | ||
| 34396 | |||
| 34397 | sub hookNotifySeen { | ||
| 34398 | |||
| 34399 | # Called by GA::Session->checkHooks | ||
| 34400 | # | ||
| 34401 | # The Axbasic statement SETHOOK causes the script to create a hook to notice when a hook | ||
| 34402 | # event has taken place | ||
| 34403 | # e.g. 'system_text' | ||
| 34404 | # | ||
| 34405 | # If SETHOOK specified a second script to run, this function runs it. Otherwise, this | ||
| 34406 | # function notifies the script that the hook event has occured (and only the script wull | ||
| 34407 | # do something in response) | ||
| 34408 | # | ||
| 34409 | # The hook interface has the following properties in ->propertyHash: | ||
| 34410 | # new_script - The name of the second script to run (only used in calls to | ||
| 34411 | # $self->hookExecSeen, 'undef' in calls to this function) | ||
| 34412 | # | ||
| 34413 | # Expected arguments (standard args from GA::Session->checkHooks) | ||
| 34414 | # $session - The calling function's GA::Session | ||
| 34415 | # $interfaceNum - The number of the active hook interface that fired | ||
| 34416 | # $hookEvent - The associated hook event | ||
| 34417 | # | ||
| 34418 | # Optional arguments | ||
| 34419 | # $hookVar - Hook data for this hook event, or 'undef' if the hook event doesn't | ||
| 34420 | # provide hook data | ||
| 34421 | # $hookVal - Additional hook data for this hook event, or 'undef' if the hook | ||
| 34422 | # even doesn't provide additional data | ||
| 34423 | # | ||
| 34424 | # Return values | ||
| 34425 | # 'undef' on improper arguments, or if $session is the wrong session or if the interface | ||
| 34426 | # object can't be found | ||
| 34427 | # 1 otherwise | ||
| 34428 | |||
| 34429 | my ($self, $session, $interfaceNum, $hookEvent, $hookVar, $hookVal, $check) = @_; | ||
| 34430 | |||
| 34431 | # Local variables | ||
| 34432 | my ($obj, $scriptName); | ||
| 34433 | |||
| 34434 | # Check for improper arguments | ||
| 34435 | if ( | ||
| 34436 | ! defined $session || ! defined $interfaceNum || ! defined $hookEvent || defined $check | ||
| 34437 | ) { | ||
| 34438 | return $axmud::CLIENT->writeImproper($self->_objClass . '->hookNotifySeen', @_); | ||
| 34439 | } | ||
| 34440 | |||
| 34441 | # Basic check - the hook should belong to the right session | ||
| 34442 | if ($session ne $self->session) { | ||
| 34443 | |||
| 34444 | return undef; | ||
| 34445 | } | ||
| 34446 | |||
| 34447 | # Get the interface object itself | ||
| 34448 | $obj = $session->ivShow('interfaceNumHash', $interfaceNum); | ||
| 34449 | if (! $obj) { | ||
| 34450 | |||
| 34451 | return undef; | ||
| 34452 | } | ||
| 34453 | |||
| 34454 | # Respond to the fired hook | ||
| 34455 | $scriptName = $obj->ivShow('propertyHash', 'new_script'); | ||
| 34456 | if ($scriptName) { | ||
| 34457 | |||
| 34458 | # SETHOOK statement specified a second script to run | ||
| 34459 | return $self->session->pseudoCmd('runscript ' . $scriptName); | ||
| 34460 | |||
| 34461 | } else { | ||
| 34462 | |||
| 34463 | # No second script to to run. Notify the Axbasic programme that one of its dependent | ||
| 34464 | # hooks has fired | ||
| 34465 | $self->scriptObj->interfaceNotification($obj, $hookEvent, $hookVar, $hookVal); | ||
| 34466 | |||
| 34467 | return 1; | ||
| 34468 | } | ||
| 34469 | } | ||
| 34470 | |||
| 34471 | sub entryCallback { | ||
| 34472 | |||
| 34473 | # Usually called by ->signal_connect in GA::Strip::Entry->setEntrySignals or in | ||
| 34474 | # GA::Table::Entry->setActivateEvent, when the user types something in the strip/table | ||
| 34475 | # object's Gtk3::Entry and presses RETURN | ||
| 34476 | # If the script is paused (->scriptStatus is 'paused') and is expecting input (->inputList | ||
| 34477 | # is not empty), send the typed value to be stored in one of the script's variables | ||
| 34478 | # Then, if no more input is expected, resume executing the script | ||
| 34479 | # | ||
| 34480 | # Expected arguments | ||
| 34481 | # $obj - The strip or table object whose Gtk3::Entry was used | ||
| 34482 | # $entry - The Gtk3::Entry itself | ||
| 34483 | # | ||
| 34484 | # Optional arguments | ||
| 34485 | # $id - A value passed to the table object that identifies the particular | ||
| 34486 | # Gtk3::Entry used (in case the table object uses multiple entries). By | ||
| 34487 | # default, $self->openWin sets $id to the same as $self->uniqueName; | ||
| 34488 | # could be an 'undef' value otherwise | ||
| 34489 | # $text - The text typed in the entry by the user (should not be 'undef') | ||
| 34490 | |||
| 34491 | my ($self, $obj, $entry, $id, $text, $check) = @_; | ||
| 34492 | |||
| 34493 | # Local variables | ||
| 34494 | my $result; | ||
| 34495 | |||
| 34496 | # Check for improper arguments | ||
| 34497 | if (! defined $obj || ! defined $entry || defined $check) { | ||
| 34498 | |||
| 34499 | return $axmud::CLIENT->writeImproper($self->_objClass . '->entryCallback', @_); | ||
| 34500 | } | ||
| 34501 | |||
| 34502 | if ($self->winObj && $self->scriptObj->inputList) { | ||
| 34503 | |||
| 34504 | # Display the last typed value in the task window | ||
| 34505 | $self->insertText($text, 'echo'); | ||
| 34506 | |||
| 34507 | # Pass the typed value on to the script | ||
| 34508 | if ($self->scriptObj->setInputData($text)) { | ||
| 34509 | |||
| 34510 | # If no more input is expected... | ||
| 34511 | if ( | ||
| 34512 | $self->scriptObj->scriptStatus eq 'wait_input' | ||
| 34513 | && ! $self->scriptObj->inputList | ||
| 34514 | ) { | ||
| 34515 | # The next text displayed should be on a new line (since the user pressed | ||
| 34516 | # RETURN) | ||
| 34517 | $self->insertText('', 'before'); | ||
| 34518 | # Allow execution to resume | ||
| 34519 | $self->scriptObj->implement(); | ||
| 34520 | } | ||
| 34521 | } | ||
| 34522 | } | ||
| 34523 | |||
| 34524 | return 1; | ||
| 34525 | } | ||
| 34526 | |||
| 34527 | ################## | ||
| 34528 | # Accessors - set | ||
| 34529 | |||
| 34530 | sub set_scriptName { | ||
| 34531 | |||
| 34532 | # Called by GA::Session->setupLogin and ->startInitScripts | ||
| 34533 | # Should be called immediately after calling $self->new | ||
| 34534 | |||
| 34535 | my ($self, $name, $check) = @_; | ||
| 34536 | |||
| 34537 | # Check for improper arguments | ||
| 34538 | if (! defined $name || defined $check) { | ||
| 34539 | |||
| 34540 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_scriptName', @_); | ||
| 34541 | } | ||
| 34542 | |||
| 34543 | # Only set the IV once | ||
| 34544 | if (! defined $self->scriptName) { | ||
| 34545 | |||
| 34546 | $self->ivPoke('scriptName', $name); | ||
| 34547 | } | ||
| 34548 | |||
| 34549 | return 1; | ||
| 34550 | } | ||
| 34551 | |||
| 34552 | ################## | ||
| 34553 | # Accessors - task settings - get | ||
| 34554 | |||
| 34555 | # The accessors for task settings are inherited from the generic task | ||
| 34556 | |||
| 34557 | ################## | ||
| 34558 | # Accessors - task parameters - get | ||
| 34559 | |||
| 34560 | sub stepMax | ||
| 34561 | { $_[0]->{stepMax} } | ||
| 34562 | sub scriptName | ||
| 34563 | { $_[0]->{scriptName} } | ||
| 34564 | sub scriptObj | ||
| 34565 | { $_[0]->{scriptObj} } | ||
| 34566 | |||
| 34567 | sub waitForInterface | ||
| 34568 | { $_[0]->{waitForInterface} } | ||
| 34569 | sub monitorTask | ||
| 34570 | { $_[0]->{monitorTask} } | ||
| 34571 | sub monitorStatistic | ||
| 34572 | { $_[0]->{monitorStatistic} } | ||
| 34573 | sub monitorTarget | ||
| 34574 | { $_[0]->{monitorTarget} } | ||
| 34575 | sub monitorTimeOut | ||
| 34576 | { $_[0]->{monitorTimeOut} } | ||
| 34577 | |||
| 34578 | sub gaugeStripObj | ||
| 34579 | { $_[0]->{gaugeStripObj} } | ||
| 34580 | sub gaugeLevel | ||
| 34581 | { $_[0]->{gaugeLevel} } | ||
| 34582 | sub gaugeHash | ||
| 34583 | { my $self = shift; return %{$self->{gaugeHash}}; } | ||
| 34584 | sub statusBarHash | ||
| 34585 | { my $self = shift; return %{$self->{statusBarHash}}; } | ||
| 34586 | |||
| 34587 | sub taskWinGaugeStripObj | ||
| 34588 | { $_[0]->{taskWinGaugeStripObj} } | ||
| 34589 | sub taskWinGaugeLevel | ||
| 34590 | { $_[0]->{taskWinGaugeLevel} } | ||
| 34591 | sub taskWinGaugeHash | ||
| 34592 | { my $self = shift; return %{$self->{taskWinGaugeHash}}; } | ||
| 34593 | sub taskWinStatusBarHash | ||
| 34594 | { my $self = shift; return %{$self->{taskWinStatusBarHash}}; } | ||
| 34595 | |||
| 34596 | sub forcedWinFlag | ||
| 34597 | { $_[0]->{forcedWinFlag} } | ||
| 34598 | } | ||
| 34599 | |||
| 34600 | { package Games::Axmud::Task::Status; | ||
| 34601 | |||
| 34602 | use strict; | ||
| 34603 | use warnings; | ||
| 34604 | # use diagnostics; | ||
| 34605 | |||
| 34606 | use Glib qw(TRUE FALSE); | ||
| 34607 | |||
| 34608 | our @ISA = qw(Games::Axmud::Generic::Task Games::Axmud); | ||
| 34609 | |||
| 34610 | ################## | ||
| 34611 | # Constructors | ||
| 34612 | |||
| 34613 | sub new { | ||
| 34614 | |||
| 34615 | # Creates a new instances of the Status task | ||
| 34616 | # | ||
| 34617 | # Expected arguments | ||
| 34618 | # $session - The parent GA::Session (not stored as an IV) | ||
| 34619 | # | ||
| 34620 | # Optional arguments | ||
| 34621 | # $taskType - Which tasklist this task is being created into - 'current' for the current | ||
| 34622 | # tasklist (tasks which are actually running now), 'initial' (tasks which | ||
| 34623 | # should be run when the user connects to the world), 'custom' (tasks with | ||
| 34624 | # customised initial parameters, which are run when the user demands). If | ||
| 34625 | # set to 'undef', this is a temporary task, created in order to access the | ||
| 34626 | # default values stored in IVs, that will not be added to any tasklist | ||
| 34627 | # $profName - ($taskType = 'current', when called by $self->clone) Name of the | ||
| 34628 | # profile from whose initial tasklist this task was created ('undef' if | ||
| 34629 | # none) | ||
| 34630 | # - ($taskType = 'initial') name of the profile in whose initial tasklist this | ||
| 34631 | # task will be. If 'undef', the global initial tasklist is used | ||
| 34632 | # - ($taskType = 'custom') 'undef' | ||
| 34633 | # $profCategory | ||
| 34634 | # - ($taskType = 'current', 'initial') which category the profile falls undef | ||
| 34635 | # (i.e. 'world', 'race', 'char', etc, or 'undef' if no profile) | ||
| 34636 | # - ($taskType = 'custom') 'undef' | ||
| 34637 | # $customName | ||
| 34638 | # - ($taskType = 'current', 'initial') 'undef' | ||
| 34639 | # - ($taskType = 'custom') the custom task name, matching a key in | ||
| 34640 | # GA::Session->customTaskHash | ||
| 34641 | # | ||
| 34642 | # Return values | ||
| 34643 | # 'undef' on improper arguments or if the task can't be added to the specified tasklist | ||
| 34644 | # Blessed reference to the newly-created object on success | ||
| 34645 | |||
| 34646 | my ($class, $session, $taskType, $profName, $profCategory, $customName, $check) = @_; | ||
| 34647 | |||
| 34648 | # Check for improper arguments | ||
| 34649 | if (! defined $class || ! defined $session || defined $check) { | ||
| 34650 | |||
| 34651 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 34652 | } | ||
| 34653 | |||
| 34654 | if ($taskType) { | ||
| 34655 | |||
| 34656 | # For initial tasks, check that $profName exists | ||
| 34657 | if ( | ||
| 34658 | $taskType eq 'initial' | ||
| 34659 | && defined $profName | ||
| 34660 | && ! $session->ivExists('profHash', $profName) | ||
| 34661 | ) { | ||
| 34662 | return $session->writeError( | ||
| 34663 | 'Can\'t create new task because \'' . $profName . '\' profile doesn\'t exist', | ||
| 34664 | $class . '->new', | ||
| 34665 | ); | ||
| 34666 | |||
| 34667 | # For custom tasks, check that $customName doesn't already exist | ||
| 34668 | } elsif ( | ||
| 34669 | $taskType eq 'custom' | ||
| 34670 | && $axmud::CLIENT->ivExists('customTaskHash', $customName) | ||
| 34671 | ) { | ||
| 34672 | return $session->writeError( | ||
| 34673 | 'Can\'t create new custom task because \'' . $customName . '\' is already being' | ||
| 34674 | . ' used', | ||
| 34675 | $class . '->new', | ||
| 34676 | ); | ||
| 34677 | |||
| 34678 | } elsif ($taskType ne 'current' && $taskType ne 'initial' && $taskType ne 'custom') { | ||
| 34679 | |||
| 34680 | return $session->writeError( | ||
| 34681 | 'Can\'t create new task because \'' . $taskType . '\' is an invalid tasklist', | ||
| 34682 | $class . '->new', | ||
| 34683 | ); | ||
| 34684 | } | ||
| 34685 | } | ||
| 34686 | |||
| 34687 | # Task settings | ||
| 34688 | my $self = Games::Axmud::Generic::Task->new( | ||
| 34689 | $session, | ||
| 34690 | $taskType, | ||
| 34691 | $profName, | ||
| 34692 | $profCategory, | ||
| 34693 | $customName, | ||
| 34694 | ); | ||
| 34695 | |||
| 34696 | $self->{_objName} = 'status_task'; | ||
| 34697 | $self->{_objClass} = $class; | ||
| 34698 | $self->{_parentFile} = undef; # Set below | ||
| 34699 | $self->{_parentWorld} = undef; # Set below | ||
| 34700 | $self->{_privFlag} = TRUE, # All IVs are private | ||
| 34701 | |||
| 34702 | $self->{name} = 'status_task'; | ||
| 34703 | $self->{prettyName} = 'Status'; | ||
| 34704 | $self->{shortName} = 'St'; | ||
| 34705 | $self->{shortCutIV} = 'statusTask'; # Axmud built-in jealous task | ||
| 34706 | |||
| 34707 | $self->{category} = 'process'; | ||
| 34708 | $self->{descrip} = 'Intercept information about current character\'s status'; | ||
| 34709 | $self->{jealousyFlag} = TRUE; | ||
| 34710 | $self->{requireLocatorFlag} = FALSE; | ||
| 34711 | $self->{profSensitivityFlag} = TRUE; | ||
| 34712 | $self->{storableFlag} = TRUE; | ||
| 34713 | $self->{delayTime} = 0; | ||
| 34714 | $self->{allowWinFlag} = TRUE; | ||
| 34715 | $self->{requireWinFlag} = FALSE; | ||
| 34716 | $self->{startWithWinFlag} = TRUE; | ||
| 34717 | $self->{winPreferList} = ['pane', 'grid']; | ||
| 34718 | $self->{winmap} = 'basic_fill'; | ||
| 34719 | $self->{tabMode} = 'simple'; | ||
| 34720 | $self->{winUpdateFunc} = 'refreshWin'; | ||
| 34721 | $self->{monochromeFlag} = TRUE; | ||
| 34722 | $self->{noScrollFlag} = TRUE; | ||
| 34723 | $self->{ttsFlag} = TRUE; | ||
| 34724 | $self->{ttsConfig} = 'status'; | ||
| 34725 | $self->{ttsAttribHash} = { | ||
| 34726 | 'status' => undef, | ||
| 34727 | 'life' => undef, | ||
| 34728 | 'lives' => undef, | ||
| 34729 | 'health' => undef, | ||
| 34730 | 'magic' => undef, | ||
| 34731 | 'energy' => undef, | ||
| 34732 | 'guild' => undef, | ||
| 34733 | 'social' => undef, | ||
| 34734 | 'xp' => undef, | ||
| 34735 | 'experience' => undef, | ||
| 34736 | 'level' => undef, | ||
| 34737 | 'align' => undef, | ||
| 34738 | 'alignment' => undef, | ||
| 34739 | 'age' => undef, | ||
| 34740 | 'time' => undef, | ||
| 34741 | 'bank' => undef, | ||
| 34742 | 'purse' => undef, | ||
| 34743 | }; | ||
| 34744 | $self->{ttsFlagAttribHash} = { | ||
| 34745 | 'life' => FALSE, | ||
| 34746 | }, | ||
| 34747 | $self->{ttsAlertAttribHash} = { | ||
| 34748 | 'healthup' => undef, | ||
| 34749 | 'healthdown' => undef, | ||
| 34750 | 'magicup' => undef, | ||
| 34751 | 'magicdown' => undef, | ||
| 34752 | 'energyup' => undef, | ||
| 34753 | 'energydown' => undef, | ||
| 34754 | 'guildup' => undef, | ||
| 34755 | 'guilddown' => undef, | ||
| 34756 | 'socialup' => undef, | ||
| 34757 | 'socialdown' => undef, | ||
| 34758 | }; | ||
| 34759 | $self->{status} = 'wait_init'; | ||
| 34760 | # ->activeFlag set to TRUE if the task should actively send commands to the world to gather | ||
| 34761 | # data about the character's status every few seconds; set to FALSE if the task should | ||
| 34762 | # passively collect status data | ||
| 34763 | # When TRUE, the task uses gagged triggers by default (lines of text received from the world | ||
| 34764 | # containing data are not displayed in the 'main' window). When FALSE, un-gagged triggers | ||
| 34765 | # are used by default and the received lines are displayed in the 'main' window | ||
| 34766 | # However, whether to use gagged triggers (or not) mostly depends on the current world | ||
| 34767 | # profile, which can choose to overrule the Status task most of the time (or not) | ||
| 34768 | # Triggers for bar patterns and stat patterns are not affected by $self->activeFlag because | ||
| 34769 | # they have their own gag settings | ||
| 34770 | # Triggers relating to $self->lifeStatus (e.g. 'You die', 'You fall asleep', 'You wake up' | ||
| 34771 | # etc) are never gagged | ||
| 34772 | $self->{activeFlag} = FALSE; # Task can be activated/disactivated | ||
| 34773 | |||
| 34774 | # Task parameters | ||
| 34775 | # | ||
| 34776 | # If ->activeFlag = TRUE, a hash of the commands that should be sent to the world, and how | ||
| 34777 | # often they should be sent. Hash in the form | ||
| 34778 | # $cmdHash{command} = interval | ||
| 34779 | $self->{cmdHash} = {}; | ||
| 34780 | # If ->activeFlag = TRUE, the names of any dependent timers created. Hash in the form | ||
| 34781 | # $timerHash{command} = dependent_timer_object | ||
| 34782 | $self->{timerHash} = {}; | ||
| 34783 | |||
| 34784 | # Flag set to TRUE every time the task's window should be updated, and set back to FALSE | ||
| 34785 | # when it is actually updated | ||
| 34786 | $self->{updateFlag} = FALSE; | ||
| 34787 | # Flag set to TRUE every time the life status changes (so that the background colour of the | ||
| 34788 | # task window can be changed), set back to FALSE once the background colour has actually | ||
| 34789 | # been changed | ||
| 34790 | $self->{lifeStatusChangeFlag} = FALSE; | ||
| 34791 | # Flag set to TRUE every time the character's health points change from one band to another | ||
| 34792 | # (which means the task window's background colour must change) - bands are 0-10%, 11-30%, | ||
| 34793 | # 31-50%, 51-100% | ||
| 34794 | $self->{healthChangeFlag} = FALSE; | ||
| 34795 | # If this flag is set to TRUE, the task attempts to convert time strings (e.g. 'twenty past | ||
| 34796 | # two in the morning') into a 24-hour clock time using the current dictionary. The flag | ||
| 34797 | # is set to TRUE at stage 2 if the current dictionary provides enough vocabulary | ||
| 34798 | $self->{convertTimeFlag} = FALSE; | ||
| 34799 | |||
| 34800 | # When this flag is TRUE, the background colour of the task window changes, depending on | ||
| 34801 | # whether the character is alive, dead, asleep (etc) and also depending on how many health | ||
| 34802 | # points the character has. If FALSE, the colour scheme never changes | ||
| 34803 | $self->{allowColourFlag} = TRUE; | ||
| 34804 | # The colours to use. Each value must be a standard Axmud colour tag | ||
| 34805 | # Which window background colour to use when character is alive | ||
| 34806 | $self->{aliveColour} = 'GREEN'; | ||
| 34807 | # Which colour to use when alive, but health points below 50% | ||
| 34808 | $self->{alive50Colour} = 'YELLOW'; | ||
| 34809 | # Which colour to use when alive, but health points below 30% | ||
| 34810 | $self->{alive30Colour} = 'yellow'; | ||
| 34811 | # Which colour to use when alive, but health points below 10% | ||
| 34812 | $self->{alive10Colour} = 'RED'; | ||
| 34813 | # Which window background colour to use when character is asleep | ||
| 34814 | $self->{asleepColour} = 'cyan'; | ||
| 34815 | # Which window background colour to use when character is passed out | ||
| 34816 | $self->{passedOutColour} = 'magenta'; | ||
| 34817 | # Which window background colour to use when character is dead | ||
| 34818 | $self->{deadColour} = 'black'; | ||
| 34819 | |||
| 34820 | # The Status task tracks five types of variable - character, fixed, pseudo, local, counter | ||
| 34821 | # and custom | ||
| 34822 | # Status task variables have a name_in_this_form. Names must be unique; a custom variable | ||
| 34823 | # called 'xp_current' can't be created because there's already a character variable with | ||
| 34824 | # that name | ||
| 34825 | # Character, fixed, local and pseudo variable names are fixed; variable names can't be added | ||
| 34826 | # or removed from the set specified by the constant IVs below | ||
| 34827 | # | ||
| 34828 | # For character variables like 'health_points', 'xp_current' and 'life_status', values are | ||
| 34829 | # stored in the current character profile as soon as they are received | ||
| 34830 | # For fixed variables, values are retrieved from the current character profile, and some of | ||
| 34831 | # those values are updated by this task; but the values are not modified directly by | ||
| 34832 | # incoming text (for example, when a line matches a pattern in | ||
| 34833 | # GA::Profile::World->groupPatternList) | ||
| 34834 | # For pseudo variables, $self->getValue compiles a value from other values, whenever | ||
| 34835 | # required (so the values are stored in any Status task IV) | ||
| 34836 | # For local variables, values are stored in this task (and are lost, when the task halts) | ||
| 34837 | # For counter variables, a current value stored in the character profile is compared against | ||
| 34838 | # some baseline value (which is stored in $self->counterBaseHash) | ||
| 34839 | # Custom variables are created just by specifying them, for example, if | ||
| 34840 | # GA::Profile::World->groupPatternList refers to a custom variable called 'my_var', as | ||
| 34841 | # soon as a line of text is received matching the pattern, an entry for 'my_var' is | ||
| 34842 | # created in $self->customVarHash | ||
| 34843 | # | ||
| 34844 | # A hash of character variables, and their corresponding GA::Profile::Char IV | ||
| 34845 | $self->{constCharVarHash} = { | ||
| 34846 | # Character's health/magic/energy/guild/social points | ||
| 34847 | 'health_points' => 'healthPoints', | ||
| 34848 | 'health_points_max' => 'healthPointsMax', | ||
| 34849 | 'magic_points' => 'magicPoints', | ||
| 34850 | 'magic_points_max' => 'magicPointsMax', | ||
| 34851 | 'energy_points' => 'energyPoints', | ||
| 34852 | 'energy_points_max' => 'energyPointsMax', | ||
| 34853 | 'guild_points' => 'guildPoints', | ||
| 34854 | 'guild_points_max' => 'guildPointsMax', | ||
| 34855 | 'social_points' => 'socialPoints', | ||
| 34856 | 'social_points_max' => 'socialPointsMax', | ||
| 34857 | # eXperience Points (XP), Quest Points (QP) and a spare set of variables for worlds | ||
| 34858 | # which use some other point system for levelling, Other Points (OP) | ||
| 34859 | 'xp_current' => 'xpCurrent', | ||
| 34860 | 'xp_next_level' => 'xpNextLevel', | ||
| 34861 | 'xp_total' => 'xpTotal', | ||
| 34862 | 'qp_current' => 'qpCurrent', | ||
| 34863 | 'qp_next_level' => 'qpNextLevel', | ||
| 34864 | 'qp_total' => 'qpTotal', | ||
| 34865 | 'op_current' => 'opCurrent', | ||
| 34866 | 'op_next_level' => 'opNextLevel', | ||
| 34867 | 'op_total' => 'opTotal', | ||
| 34868 | # Character's level and alignment | ||
| 34869 | 'level' => 'level', | ||
| 34870 | 'alignment' => 'alignment', # Not numeric | ||
| 34871 | # Local and remote wimpy (the maximum local wimpy is a fixed value) | ||
| 34872 | 'local_wimpy' => 'localWimpy', | ||
| 34873 | 'remote_wimpy' => 'remoteWimpy', | ||
| 34874 | 'remote_wimpy_max' => 'remoteWimpyMax', | ||
| 34875 | # Character's age (in the unit specified by the pseudo value 'age_unit') | ||
| 34876 | 'age' => 'age', | ||
| 34877 | # Character's wealth | ||
| 34878 | 'bank_balance' => 'bankBalance', | ||
| 34879 | 'purse_contents' => 'purseContents', | ||
| 34880 | # Character's lives | ||
| 34881 | 'life_count' => 'lifeCount', | ||
| 34882 | 'life_max' => 'lifeMax', | ||
| 34883 | }; | ||
| 34884 | # A hash of fixed variables, and their corresponding GA::Profile::Char IV | ||
| 34885 | $self->{constFixedVarHash} = { | ||
| 34886 | # Character's deaths and life status | ||
| 34887 | 'death_count' => 'deathCount', | ||
| 34888 | 'life_status' => 'lifeStatus', # Not numeric | ||
| 34889 | # The local wimpy maximum is always 100 | ||
| 34890 | 'local_wimpy_max' => 'constLocalWimpyMax', | ||
| 34891 | # Fight counts | ||
| 34892 | 'fight_count' => 'fightCount', | ||
| 34893 | 'kill_count' => 'killCount', | ||
| 34894 | 'wimpy_count' => 'wimpyCount', | ||
| 34895 | 'fight_defeat_count' => 'fightDefeatCount', | ||
| 34896 | # Interaction counts | ||
| 34897 | 'interact_count' => 'interactCount', | ||
| 34898 | 'interact_success_count' => 'interactSuccessCount', | ||
| 34899 | 'interact_fail_count' => 'interactFailCount', | ||
| 34900 | 'interact_fight_count' => 'interactFightCount', | ||
| 34901 | 'interact_disaster_count' => 'interactDisasterCount', | ||
| 34902 | # Unresolved fight/interaction counts | ||
| 34903 | 'flee_count' => 'fleeCount', | ||
| 34904 | 'escape_count' => 'escapeCount', | ||
| 34905 | }; | ||
| 34906 | # A hash of pseudo variables. The value is generated by $self->getValue as and when required | ||
| 34907 | $self->{constPseudoVarHash} = { | ||
| 34908 | # 'world', 'guild', 'race', 'char' are the names of the current world, guild, race and | ||
| 34909 | # character | ||
| 34910 | 'world' => undef, | ||
| 34911 | 'guild' => undef, | ||
| 34912 | 'race' => undef, | ||
| 34913 | 'char' => undef, | ||
| 34914 | # A summary of character's affects and stats, stored in $self->affectHash and ->statHash | ||
| 34915 | 'affects' => undef, | ||
| 34916 | 'stats' => undef, | ||
| 34917 | # The value stored in Games::Axmud::Profile::World->charAgeUnit | ||
| 34918 | 'age_unit' => undef, | ||
| 34919 | # 'money_count' is the sum of 'bank_balance' and 'purse_contents' | ||
| 34920 | 'money_count' => undef, | ||
| 34921 | # 'coward_count' is the sum of 'flee_count' and 'escape_count' | ||
| 34922 | 'coward_count' => undef, | ||
| 34923 | # A short list of currently running standard tasks (e.g. '{St Lc}' for Status, Locator) | ||
| 34924 | 'task' => undef, | ||
| 34925 | # Show whether the Status task is active, or not | ||
| 34926 | 'task_active' => undef, | ||
| 34927 | # The user's (real) time | ||
| 34928 | 'local_time' => undef, | ||
| 34929 | # The session time, retrieved from GA::Session->sessionTime | ||
| 34930 | 'session_time' => undef, | ||
| 34931 | # Values combining values from $self->counterVarHash | ||
| 34932 | 'temp_xp_average' => undef, | ||
| 34933 | 'temp_money_count' => undef, | ||
| 34934 | 'temp_timer' => undef, | ||
| 34935 | # Strings displaying several fight/interaction values together as a single string | ||
| 34936 | 'fight_string' => undef, | ||
| 34937 | 'interact_string' => undef, | ||
| 34938 | 'coward_string' => undef, | ||
| 34939 | 'temp_fight_string' => undef, | ||
| 34940 | 'temp_interact_string' => undef, | ||
| 34941 | 'temp_coward_string' => undef, | ||
| 34942 | }; | ||
| 34943 | # Hash of local variables; current values for each variable are stored in | ||
| 34944 | # $self->localVarHash | ||
| 34945 | $self->{constLocalVarHash} = { | ||
| 34946 | # The time according to the connected world (fictional and real) | ||
| 34947 | 'time' => undef, | ||
| 34948 | 'remote_time' => undef, | ||
| 34949 | # Details about the current opponent (for worlds that supply them); including their | ||
| 34950 | # relative strength (normally gathered via a 'consider' command) | ||
| 34951 | 'opp_name' => undef, | ||
| 34952 | 'opp_level' => undef, | ||
| 34953 | 'opp_health' => undef, | ||
| 34954 | 'opp_health_max' => undef, | ||
| 34955 | 'opp_strength' => undef, | ||
| 34956 | }; | ||
| 34957 | # Hash of counter variables. Values stored in the current character profile are compared | ||
| 34958 | # against some baseline value (stored in $self->counterBaseHash and set by a call to | ||
| 34959 | # $self->reset_counters) | ||
| 34960 | # The ';resetcounter' command, in its call to $self->reset_counter, adds some or all of | ||
| 34961 | # the keys in this hash to $self->counterVarHash/->counterBaseHash, which sets the | ||
| 34962 | # counter 'running' | ||
| 34963 | $self->{constCounterVarHash} = { | ||
| 34964 | 'temp_fight_count' => undef, | ||
| 34965 | 'temp_kill_count' => undef, | ||
| 34966 | 'temp_wimpy_count' => undef, | ||
| 34967 | 'temp_fight_defeat_count' => undef, | ||
| 34968 | 'temp_interact_count' => undef, | ||
| 34969 | 'temp_interact_success_count' | ||
| 34970 | => undef, | ||
| 34971 | 'temp_interact_fail_count' => undef, | ||
| 34972 | 'temp_interact_fight_count' => undef, | ||
| 34973 | 'temp_interact_disaster_count' | ||
| 34974 | => undef, | ||
| 34975 | 'temp_escape_count' => undef, | ||
| 34976 | 'temp_flee_count' => undef, | ||
| 34977 | 'temp_xp_count' => undef, | ||
| 34978 | 'temp_quest_count' => undef, | ||
| 34979 | 'temp_bank_count' => undef, | ||
| 34980 | 'temp_purse_count' => undef, | ||
| 34981 | }; | ||
| 34982 | # Hash of variables which are used to set counter variables. The keys are a subset of keys | ||
| 34983 | # in $self->constCharVarHash and ->constFixedVarHash; the values are all keys that appear | ||
| 34984 | # in $self->constCounterVarHash | ||
| 34985 | $self->{constCounterRevHash} = { | ||
| 34986 | # from ->constCharVarHash | ||
| 34987 | 'xp_total' => 'temp_xp_count', | ||
| 34988 | 'qp_total' => 'temp_quest_count', | ||
| 34989 | 'bank_balance' => 'temp_bank_count', | ||
| 34990 | 'purse_contents' => 'temp_purse_count', | ||
| 34991 | # from ->constFixedVarHash | ||
| 34992 | 'fight_count' => 'temp_fight_count', | ||
| 34993 | 'kill_count' => 'temp_kill_count', | ||
| 34994 | 'wimpy_count' => 'temp_wimpy_count', | ||
| 34995 | 'fight_defeat_count' => 'temp_fight_defeat_count', | ||
| 34996 | 'interact_count' => 'temp_interact_count', | ||
| 34997 | 'interact_success_count' => 'temp_interact_success_count', | ||
| 34998 | 'interact_fail_count' => 'temp_interact_fail_count', | ||
| 34999 | 'interact_fight_count' => 'temp_interact_fight_count', | ||
| 35000 | 'interact_disaster_count' => 'temp_interact_disaster_count', | ||
| 35001 | 'flee_count' => 'temp_flee_count', | ||
| 35002 | 'escape_count' => 'temp_escape_count', | ||
| 35003 | }; | ||
| 35004 | # Hash of variables that require calls to $self->checkHealthChange and/or | ||
| 35005 | # ->checkPointsChange | ||
| 35006 | $self->{constPointHash} = { | ||
| 35007 | 'health_points' => undef, | ||
| 35008 | 'health_points_max' => undef, | ||
| 35009 | 'magic_points' => undef, | ||
| 35010 | 'magic_points_max' => undef, | ||
| 35011 | 'energy_points' => undef, | ||
| 35012 | 'energy_points_max' => undef, | ||
| 35013 | 'guild_points' => undef, | ||
| 35014 | 'guild_points_max' => undef, | ||
| 35015 | 'social_points' => undef, | ||
| 35016 | 'social_points_max' => undef, | ||
| 35017 | }; | ||
| 35018 | |||
| 35019 | # A hash of local variables and their corresponding values, initialised by $self->doStage | ||
| 35020 | # (at stage 2) | ||
| 35021 | $self->{localVarHash} = {}; | ||
| 35022 | # A hash of custom variables and their corresponding values | ||
| 35023 | $self->{customVarHash} = {}; | ||
| 35024 | |||
| 35025 | # A hash of counter variables and their corresponding values, initialised by | ||
| 35026 | # $self->reset_counters | ||
| 35027 | # The call to that function sets one or more of the counters 'running', add some or all of | ||
| 35028 | # the variables stored as keys in $self->constCounterVarHash to these two hashes | ||
| 35029 | # A hash of counter variables and their corresponding values, relative to some baseline | ||
| 35030 | # value | ||
| 35031 | $self->{counterVarHash} = {}; | ||
| 35032 | # A hash of counter variables and their corresponding baseline values | ||
| 35033 | $self->{counterBaseHash} = {}; | ||
| 35034 | # Is the fight counter running? (TRUE yes, FALSE no; this IV is a shortcut to checking | ||
| 35035 | # whether some counter variables exist in $self->counterVarHash, or not) | ||
| 35036 | $self->{fightCountFlag} = FALSE; | ||
| 35037 | # Is the interaction counter running? (TRUE yes, FALSE no; this IV is a shortcut to checking | ||
| 35038 | # whether some counter variables exist in $self->counterVarHash, or not) | ||
| 35039 | $self->{interactCountFlag} = FALSE; | ||
| 35040 | # The time at which any counter was last reset (matches GA::Session->sessionTime) | ||
| 35041 | $self->{counterStartTime} = 0; | ||
| 35042 | |||
| 35043 | # Hash of spells (etc) that currently affect the character, in the form | ||
| 35044 | # $affectHash{spell} = undef | ||
| 35045 | $self->{affectHash} = {}; | ||
| 35046 | # Hash of character's current stats, including bonuses/penalties. Hash in the form | ||
| 35047 | # ->statHash{stat} = value | ||
| 35048 | $self->{statHash} = {}; | ||
| 35049 | |||
| 35050 | # Flag set to TRUE if the value of some variables should be displayed in the 'main' window's | ||
| 35051 | # gauge box | ||
| 35052 | $self->{gaugeFlag} = FALSE; | ||
| 35053 | # Shortcut to the strip object (GA::Strip::GaugeBox) which handles gauges in this | ||
| 35054 | # session's 'main' window; set whenever this task adds it first gauge | ||
| 35055 | $self->{gaugeStripObj} = undef; | ||
| 35056 | # If $self->gaugeFlag is TRUE, the unique number of the GA::Obj::GaugeLevel object created | ||
| 35057 | # for this task (representing a horizontal strip of gauges, of which there can be 1 or | ||
| 35058 | # more strips within the gauge box) | ||
| 35059 | $self->{gaugeLevel} = undef; | ||
| 35060 | # Flag set to TRUE if numerical values should be displayed on top of the gauges | ||
| 35061 | $self->{gaugeValueFlag} = TRUE; | ||
| 35062 | # List of GA::Obj::Gauge objects created by this task, each one corresponding to a gauge | ||
| 35063 | # in the 'main' window | ||
| 35064 | $self->{gaugeObjList} = []; | ||
| 35065 | # Flag set to TRUE in some calls to $self->set_updateFromMsdp, in which the 'main' window | ||
| 35066 | # gauges (if visible) must be reset, not just redrawn | ||
| 35067 | $self->{gaugeResetFlag} = FALSE; | ||
| 35068 | |||
| 35069 | # A hash used for TTS alerts. The keys are TTS alert attributes for this task; the | ||
| 35070 | # corresponding values are: | ||
| 35071 | # -1 - the last alert message was a warning, that the points have fallen below a | ||
| 35072 | # certain minimum | ||
| 35073 | # +1 - the last alert message was a confirmation, that the points have recovered | ||
| 35074 | # above a certain minimum | ||
| 35075 | # 0 - no alert message has been read out yet | ||
| 35076 | # NB The initial value is 1; if the player connects to the world and their health points | ||
| 35077 | # (for example) are very low, tell them immediately, but no need to tell them if their | ||
| 35078 | # health points are very high | ||
| 35079 | $self->{ttsPointsAlertHash} = { | ||
| 35080 | 'health' => 1, | ||
| 35081 | 'magic' => 1, | ||
| 35082 | 'energy' => 1, | ||
| 35083 | 'guild' => 1, | ||
| 35084 | 'social' => 1, | ||
| 35085 | }; | ||
| 35086 | # Every time $self->checkPointsChange decides it's time to issue an alert, the TTS alert | ||
| 35087 | # message to read out is stored here. The message isn't actually read out until | ||
| 35088 | # $self->doStage is called, so that if the code receives (for example) a new | ||
| 35089 | # ->healthPoints score just before receiving a new ->healthPointsMax score, the task | ||
| 35090 | # doesn't erroneously read out an alert | ||
| 35091 | # This hash gets reset by ->doStage, at stage 4, just after reading out any alerts | ||
| 35092 | $self->{ttsPointsAlertMsgHash} = { | ||
| 35093 | 'health' => undef, | ||
| 35094 | 'magic' => undef, | ||
| 35095 | 'energy' => undef, | ||
| 35096 | 'guild' => undef, | ||
| 35097 | 'social' => undef, | ||
| 35098 | }; | ||
| 35099 | # Parallel hash telling us whether the alert message to be read is a 'high' or 'low'; each | ||
| 35100 | # key's corresponding value is set to -1 or +1, and that value is used to set | ||
| 35101 | # $self->ttsPointsAlertHash | ||
| 35102 | $self->{ttsPointsAlertTypeHash} = { | ||
| 35103 | 'health' => undef, | ||
| 35104 | 'magic' => undef, | ||
| 35105 | 'energy' => undef, | ||
| 35106 | 'guild' => undef, | ||
| 35107 | 'social' => undef, | ||
| 35108 | }; | ||
| 35109 | |||
| 35110 | # Bless task | ||
| 35111 | bless $self, $class; | ||
| 35112 | |||
| 35113 | # For all tasks that aren't temporary... | ||
| 35114 | if ($taskType) { | ||
| 35115 | |||
| 35116 | # Check that the task doesn't belong to a disabled plugin (in which case, it can't be | ||
| 35117 | # added to any current, initial or custom tasklist) | ||
| 35118 | if (! $self->checkPlugins()) { | ||
| 35119 | |||
| 35120 | return undef; | ||
| 35121 | } | ||
| 35122 | |||
| 35123 | # Set the parent file object | ||
| 35124 | $self->setParentFileObj($session, $taskType, $profName, $profCategory); | ||
| 35125 | |||
| 35126 | # Create entries in tasklists, if possible | ||
| 35127 | if (! $self->updateTaskLists($session)) { | ||
| 35128 | |||
| 35129 | return undef; | ||
| 35130 | } | ||
| 35131 | } | ||
| 35132 | |||
| 35133 | # Task creation complete | ||
| 35134 | return $self; | ||
| 35135 | } | ||
| 35136 | |||
| 35137 | sub clone { | ||
| 35138 | |||
| 35139 | # Create a clone of an existing task | ||
| 35140 | # Usually used upon connection to a world, when every task in the initial tasklists must | ||
| 35141 | # be cloned into a new object, representing a task in the current tasklist | ||
| 35142 | # (Also used when cloning a profile object, since all the tasks in its initial tasklist must | ||
| 35143 | # also be cloned) | ||
| 35144 | # | ||
| 35145 | # Expected arguments | ||
| 35146 | # $session - The parent GA::Session (not stored as an IV) | ||
| 35147 | # $taskType - Which tasklist this task is being created into - 'current' for the current | ||
| 35148 | # tasklist (tasks which are actually running now), 'initial' (tasks which | ||
| 35149 | # should be run when the user connects to the world). Custom tasks aren't | ||
| 35150 | # cloned (at the moment) | ||
| 35151 | # | ||
| 35152 | # Optional arguments | ||
| 35153 | # $profName - ($taskType = 'initial') name of the profile in whose initial tasklist the | ||
| 35154 | # existing task is stored | ||
| 35155 | # $profCategory | ||
| 35156 | # - ($taskType = 'initial') which category the profile falls under (i.e. | ||
| 35157 | # 'world', 'race', 'char', etc) | ||
| 35158 | # | ||
| 35159 | # Return values | ||
| 35160 | # 'undef' on improper arguments or if the task can't be cloned | ||
| 35161 | # Blessed reference to the newly-created object on success | ||
| 35162 | |||
| 35163 | my ($self, $session, $taskType, $profName, $profCategory, $check) = @_; | ||
| 35164 | |||
| 35165 | # Check for improper arguments | ||
| 35166 | if ( | ||
| 35167 | ! defined $session || ! defined $taskType || defined $check | ||
| 35168 | || ($taskType ne 'current' && $taskType ne 'initial') | ||
| 35169 | || ($taskType eq 'initial' && (! defined $profName || ! defined $profCategory)) | ||
| 35170 | ) { | ||
| 35171 | return $axmud::CLIENT->writeImproper($self->_objClass . '->clone', @_); | ||
| 35172 | } | ||
| 35173 | |||
| 35174 | # For initial tasks, check that $profName exists | ||
| 35175 | if ( | ||
| 35176 | $taskType eq 'initial' | ||
| 35177 | && defined $profName | ||
| 35178 | && ! $session->ivExists('profHash', $profName) | ||
| 35179 | ) { | ||
| 35180 | return $axmud::CLIENT->writeError( | ||
| 35181 | 'Can\'t create cloned task because \'' . $profName . '\' profile doesn\'t exist', | ||
| 35182 | $self->_objClass . '->clone', | ||
| 35183 | ); | ||
| 35184 | } | ||
| 35185 | |||
| 35186 | # Check that the task doesn't belong to a disabled plugin (in which case, it can't be | ||
| 35187 | # cloned) | ||
| 35188 | if (! $self->checkPlugins()) { | ||
| 35189 | |||
| 35190 | return undef; | ||
| 35191 | } | ||
| 35192 | |||
| 35193 | # Create the new task, using default settings and parameters | ||
| 35194 | my $clone = $self->_objClass->new($session, $taskType, $profName, $profCategory); | ||
| 35195 | |||
| 35196 | # Most of the cloned task's settings have default values, but a few are copied from the | ||
| 35197 | # original | ||
| 35198 | $self->cloneTaskSettings($clone); | ||
| 35199 | |||
| 35200 | # Give the new (cloned) task the same initial parameters as the original one | ||
| 35201 | $clone->{cmdHash} = {$self->cmdHash}; | ||
| 35202 | $clone->{timerHash} = {$self->timerHash}; | ||
| 35203 | |||
| 35204 | $clone->{updateFlag} = $self->updateFlag; | ||
| 35205 | $clone->{lifeStatusChangeFlag} = $self->lifeStatusChangeFlag; | ||
| 35206 | $clone->{healthChangeFlag} = $self->healthChangeFlag; | ||
| 35207 | $clone->{convertTimeFlag} = $self->convertTimeFlag; | ||
| 35208 | |||
| 35209 | $clone->{allowColourFlag} = $self->allowColourFlag; | ||
| 35210 | $clone->{aliveColour} = $self->aliveColour; | ||
| 35211 | $clone->{alive50Colour} = $self->alive50Colour; | ||
| 35212 | $clone->{alive30Colour} = $self->alive30Colour; | ||
| 35213 | $clone->{alive10Colour} = $self->alive10Colour; | ||
| 35214 | $clone->{asleepColour} = $self->asleepColour; | ||
| 35215 | $clone->{passedOutColour} = $self->passedOutColour; | ||
| 35216 | $clone->{deadColour} = $self->deadColour; | ||
| 35217 | |||
| 35218 | # (The constant hashes retain their own values) | ||
| 35219 | |||
| 35220 | $clone->{localVarHash} = {$self->localVarHash}; | ||
| 35221 | $clone->{customVarHash} = {$self->customVarHash}; | ||
| 35222 | |||
| 35223 | $clone->{counterVarHash} = {$self->counterVarHash}; | ||
| 35224 | $clone->{counterBaseHash} = {$self->counterBaseHash}; | ||
| 35225 | $clone->{fightCountFlag} = $self->fightCountFlag; | ||
| 35226 | $clone->{interactCountFlag} = $self->interactCountFlag; | ||
| 35227 | $clone->{counterStartTime} = $self->counterStartTime; | ||
| 35228 | |||
| 35229 | $clone->{affectHash} = {$self->affectHash}; | ||
| 35230 | $clone->{statHash} = {$self->statHash}; | ||
| 35231 | |||
| 35232 | $clone->{gaugeFlag} = $self->gaugeFlag; | ||
| 35233 | $clone->{gaugeStripObj} = $self->gaugeStripObj; | ||
| 35234 | $clone->{gaugeLevel} = $self->gaugeLevel; | ||
| 35235 | $clone->{gaugeValueFlag} = $self->gaugeValueFlag; | ||
| 35236 | $clone->{gaugeObjList} = [$self->gaugeObjList]; | ||
| 35237 | $clone->{gaugeResetFlag} = $self->gaugeResetFlag; | ||
| 35238 | |||
| 35239 | $clone->{ttsPointsAlertHash} = {$self->ttsPointsAlertHash}; | ||
| 35240 | $clone->{ttsPointsAlertMsgHash} = {$self->ttsPointsAlertMsgHash}; | ||
| 35241 | $clone->{ttsPointsAlertTypeHash} | ||
| 35242 | = {$self->ttsPointsAlertTypeHash}; | ||
| 35243 | |||
| 35244 | # Cloning complete | ||
| 35245 | return $clone; | ||
| 35246 | } | ||
| 35247 | |||
| 35248 | sub preserve { | ||
| 35249 | |||
| 35250 | # Called by $self->main whenever this task is reset, in order to preserve some if its task | ||
| 35251 | # parameters (but not necessarily all of them) | ||
| 35252 | # | ||
| 35253 | # Expected arguments | ||
| 35254 | # $newTask - The new task which has been created, to which some of this task's instance | ||
| 35255 | # variables might have to be transferred | ||
| 35256 | # | ||
| 35257 | # Return values | ||
| 35258 | # 'undef' on improper arguments, or if $newTask isn't in the GA::Session's current | ||
| 35259 | # tasklist | ||
| 35260 | # 1 on success | ||
| 35261 | |||
| 35262 | my ($self, $newTask, $check) = @_; | ||
| 35263 | |||
| 35264 | # Check for improper arguments | ||
| 35265 | if (! defined $newTask || defined $check) { | ||
| 35266 | |||
| 35267 | return $axmud::CLIENT->writeImproper($self->_objClass . '->preserve', @_); | ||
| 35268 | } | ||
| 35269 | |||
| 35270 | # Check the task is in the current tasklist | ||
| 35271 | if (! $self->session->ivExists('currentTaskHash', $newTask->uniqueName)) { | ||
| 35272 | |||
| 35273 | return $self->writeWarning( | ||
| 35274 | '\'' . $self->uniqueName . '\' task missing from the current tasklist', | ||
| 35275 | $self->_objClass . '->preserve', | ||
| 35276 | ); | ||
| 35277 | } | ||
| 35278 | |||
| 35279 | # Preserve some task parameters (the others are left with their default settings, some of | ||
| 35280 | # which will be re-initialised in stage 2) | ||
| 35281 | |||
| 35282 | # Preserve the list of commands to send | ||
| 35283 | $newTask->ivPoke('cmdHash', $self->cmdHash); | ||
| 35284 | # Preserve the background colour scheme | ||
| 35285 | $newTask->ivPoke('allowColourFlag', $self->allowColourFlag); | ||
| 35286 | $newTask->ivPoke('aliveColour', $self->aliveColour); | ||
| 35287 | $newTask->ivPoke('alive50Colour', $self->alive50Colour); | ||
| 35288 | $newTask->ivPoke('alive30Colour', $self->alive30Colour); | ||
| 35289 | $newTask->ivPoke('alive10Colour', $self->alive10Colour); | ||
| 35290 | $newTask->ivPoke('asleepColour', $self->asleepColour); | ||
| 35291 | $newTask->ivPoke('passedOutColour', $self->passedOutColour); | ||
| 35292 | $newTask->ivPoke('deadColour', $self->deadColour); | ||
| 35293 | # Preserve the counters | ||
| 35294 | $newTask->ivPoke('counterVarHash', $self->counterVarHash); | ||
| 35295 | $newTask->ivPoke('counterBaseHash', $self->counterBaseHash); | ||
| 35296 | $newTask->ivPoke('fightCountFlag', $self->fightCountFlag); | ||
| 35297 | $newTask->ivPoke('interactCountFlag', $self->interactCountFlag); | ||
| 35298 | $newTask->ivPoke('counterStartTime', $self->counterStartTime); | ||
| 35299 | # Preserve some gauge variables | ||
| 35300 | $newTask->ivPoke('gaugeFlag', $self->gaugeFlag); | ||
| 35301 | $newTask->ivPoke('gaugeValueFlag', $self->gaugeFlag); | ||
| 35302 | |||
| 35303 | return 1; | ||
| 35304 | } | ||
| 35305 | |||
| 35306 | # sub setParentFileObj {} # Inherited from generic task | ||
| 35307 | |||
| 35308 | # sub updateTaskLists {} # Inherited from generic task | ||
| 35309 | |||
| 35310 | sub ttsReadAttrib { | ||
| 35311 | |||
| 35312 | # Called by GA::Cmd::Read->do and PermRead->do | ||
| 35313 | # Users can use the client command ';read' to interact with individual tasks, typically | ||
| 35314 | # getting them to read out information (e.g. the Status task can read out current health | ||
| 35315 | # points) | ||
| 35316 | # The ';read' command is in the form ';read <attribute>' or ';read <attribute> <value>'. | ||
| 35317 | # The ';read' command looks up the <attribute> in GA::Client->ttsAttribHash, which tells | ||
| 35318 | # it which task to call | ||
| 35319 | # | ||
| 35320 | # Expected arguments | ||
| 35321 | # $attrib - The TTS attribute specified by the calling function. Must be one of the | ||
| 35322 | # keys in $self->ttsAttribHash | ||
| 35323 | # | ||
| 35324 | # Optional arguments | ||
| 35325 | # $value - The value specified by the calling function (or 'undef' if none was | ||
| 35326 | # specified) | ||
| 35327 | # $noReadFlag - Set to TRUE when called by GA::Cmd::PermRead->do, in which case only this | ||
| 35328 | # task's hash of attributes is updated. If set to FALSE (or 'undef'), | ||
| 35329 | # something is usually read aloud, too | ||
| 35330 | # | ||
| 35331 | # Return values | ||
| 35332 | # 'undef' on improper arguments, if the current character profile isn't set or if the | ||
| 35333 | # $attrib doesn't exist in this task's ->ttsConfig | ||
| 35334 | # 1 otherwise | ||
| 35335 | |||
| 35336 | my ($self, $attrib, $value, $noReadFlag, $check) = @_; | ||
| 35337 | |||
| 35338 | # Local variables | ||
| 35339 | my ($charObj, $string, $iv, $ivMax, $time); | ||
| 35340 | |||
| 35341 | # Check for improper arguments | ||
| 35342 | if (! defined $attrib || defined $check) { | ||
| 35343 | |||
| 35344 | return $axmud::CLIENT->writeImproper($self->_objClass . '->ttsReadAttrib', @_); | ||
| 35345 | } | ||
| 35346 | |||
| 35347 | # Import the current character | ||
| 35348 | $charObj = $self->session->currentChar; | ||
| 35349 | if (! $charObj) { | ||
| 35350 | |||
| 35351 | return undef; | ||
| 35352 | } | ||
| 35353 | |||
| 35354 | # TTS attributes are case-insensitive | ||
| 35355 | $attrib = lc($attrib); | ||
| 35356 | |||
| 35357 | # Check that the specified attribute is actually used by this task (';read' or ';permread' | ||
| 35358 | # should carry out this check, but better safe than sorry) | ||
| 35359 | if (! $self->ivExists('ttsAttribHash', $attrib)) { | ||
| 35360 | |||
| 35361 | return undef; | ||
| 35362 | |||
| 35363 | } elsif ($noReadFlag) { | ||
| 35364 | |||
| 35365 | # When called by GA::Cmd::PermRead->do, don't read out anything, just update the hash | ||
| 35366 | # of attributes (when appropriate) | ||
| 35367 | |||
| 35368 | # (no attributes require an update) | ||
| 35369 | |||
| 35370 | return 1; | ||
| 35371 | |||
| 35372 | } else { | ||
| 35373 | |||
| 35374 | # Custom behaviour for this task | ||
| 35375 | |||
| 35376 | if ($attrib eq 'status') { | ||
| 35377 | |||
| 35378 | if (! $charObj->lifeStatus) { | ||
| 35379 | $string = 'Life status: not set'; | ||
| 35380 | } else { | ||
| 35381 | $string = 'Life status: ' . $charObj->lifeStatus; | ||
| 35382 | } | ||
| 35383 | |||
| 35384 | } elsif ($attrib eq 'life' || $attrib eq 'lives') { | ||
| 35385 | |||
| 35386 | if ( | ||
| 35387 | ! defined $charObj->lifeCount | ||
| 35388 | && ! defined $charObj->deathCount | ||
| 35389 | && ! defined $charObj->lifeMax | ||
| 35390 | ) { | ||
| 35391 | $string = 'Lives: not set'; | ||
| 35392 | |||
| 35393 | } else { | ||
| 35394 | |||
| 35395 | if (! defined $charObj->lifeCount) { | ||
| 35396 | $string = 'Lives: not set, '; | ||
| 35397 | } else { | ||
| 35398 | $string = 'Lives: ' . $charObj->lifeCount . ', '; | ||
| 35399 | } | ||
| 35400 | |||
| 35401 | if (! defined $charObj->lifeMax) { | ||
| 35402 | $string .= 'maximum: not set, '; | ||
| 35403 | } else { | ||
| 35404 | $string .= 'maximum: ' . $charObj->lifeMax . ', '; | ||
| 35405 | } | ||
| 35406 | |||
| 35407 | if (! defined $charObj->deathCount) { | ||
| 35408 | $string .= 'deaths: not set.'; | ||
| 35409 | } else { | ||
| 35410 | $string .= 'deaths: ' . $charObj->deathCount . '.'; | ||
| 35411 | } | ||
| 35412 | } | ||
| 35413 | |||
| 35414 | } elsif ( | ||
| 35415 | $attrib eq 'health' | ||
| 35416 | || $attrib eq 'magic' | ||
| 35417 | || $attrib eq 'energy' | ||
| 35418 | || $attrib eq 'guild' | ||
| 35419 | || $attrib eq 'social' | ||
| 35420 | ) { | ||
| 35421 | $iv = $attrib . 'Points'; # e.g. ->healthPoints | ||
| 35422 | $ivMax = $attrib . 'PointsMax'; # e.g. ->healthPointsMax | ||
| 35423 | |||
| 35424 | if (! defined $charObj->$iv && ! defined $charObj->$ivMax) { | ||
| 35425 | |||
| 35426 | $string = ucfirst($attrib) . ' points: not set'; | ||
| 35427 | |||
| 35428 | } else { | ||
| 35429 | |||
| 35430 | if (! defined $charObj->$iv) { | ||
| 35431 | $string = ucfirst($attrib) . ' points: not set, '; | ||
| 35432 | } else { | ||
| 35433 | $string = ucfirst($attrib) . ' points: ' . $charObj->$iv . ', '; | ||
| 35434 | } | ||
| 35435 | |||
| 35436 | if (! defined $charObj->$ivMax) { | ||
| 35437 | $string .= 'maximum: not set.'; | ||
| 35438 | } else { | ||
| 35439 | $string .= 'maximum: ' . $charObj->$ivMax . '.'; | ||
| 35440 | } | ||
| 35441 | } | ||
| 35442 | |||
| 35443 | } elsif ($attrib eq 'xp' || $attrib eq 'experience') { | ||
| 35444 | |||
| 35445 | if ( | ||
| 35446 | ! defined $charObj->xpCurrent | ||
| 35447 | && ! defined $charObj->xpNextLevel | ||
| 35448 | && ! defined $charObj->xpTotal | ||
| 35449 | ) { | ||
| 35450 | $string = 'Experience: not set'; | ||
| 35451 | |||
| 35452 | } else { | ||
| 35453 | |||
| 35454 | if (! defined $charObj->xpCurrent) { | ||
| 35455 | $string = 'Experience points: not set. '; | ||
| 35456 | } else { | ||
| 35457 | $string = 'Experience points: ' . $charObj->xpCurrent . '. '; | ||
| 35458 | } | ||
| 35459 | |||
| 35460 | # Not all worlds use ->xpNextLevel and ->xpTotal | ||
| 35461 | if (defined $charObj->xpNextLevel) { | ||
| 35462 | |||
| 35463 | $string .= 'To next level: ' . $charObj->xpNextLevel . '. '; | ||
| 35464 | } | ||
| 35465 | |||
| 35466 | if (defined $charObj->xpTotal) { | ||
| 35467 | |||
| 35468 | $string .= 'Total: ' . $charObj->xpTotal . '. '; | ||
| 35469 | } | ||
| 35470 | } | ||
| 35471 | |||
| 35472 | } elsif ($attrib eq 'level') { | ||
| 35473 | |||
| 35474 | if (! $charObj->level) { | ||
| 35475 | $string = 'Level: not set'; | ||
| 35476 | } else { | ||
| 35477 | $string = 'Level: ' . $charObj->level; | ||
| 35478 | } | ||
| 35479 | |||
| 35480 | } elsif ($attrib eq 'align' || $attrib eq 'alignment') { | ||
| 35481 | |||
| 35482 | if (! $charObj->alignment) { | ||
| 35483 | $string = 'Alignment: not set'; | ||
| 35484 | } else { | ||
| 35485 | $string = 'Alignment: ' . $charObj->alignment; | ||
| 35486 | } | ||
| 35487 | |||
| 35488 | } elsif ($attrib eq 'age') { | ||
| 35489 | |||
| 35490 | if (! $charObj->age) { | ||
| 35491 | $string = 'Age: not set'; | ||
| 35492 | } else { | ||
| 35493 | $string = 'Age: ' . $charObj->age; | ||
| 35494 | } | ||
| 35495 | |||
| 35496 | } elsif ($attrib eq 'time') { | ||
| 35497 | |||
| 35498 | $time = $self->getValue('time'); | ||
| 35499 | |||
| 35500 | if (! $time) { | ||
| 35501 | $string = 'Game time: not set'; | ||
| 35502 | } else { | ||
| 35503 | $string = 'Game time: ' . $time; | ||
| 35504 | } | ||
| 35505 | |||
| 35506 | } elsif ($attrib eq 'bank') { | ||
| 35507 | |||
| 35508 | if (! $charObj->bankBalance) { | ||
| 35509 | $string = 'Bank balance: not set'; | ||
| 35510 | } else { | ||
| 35511 | $string = 'Bank balance: ' . $charObj->bankBalance; | ||
| 35512 | } | ||
| 35513 | |||
| 35514 | } elsif ($attrib eq 'purse') { | ||
| 35515 | |||
| 35516 | if (! $charObj->age) { | ||
| 35517 | $string = 'Purse contents: not set'; | ||
| 35518 | } else { | ||
| 35519 | $string = 'Purse contents: ' . $charObj->bankBalance; | ||
| 35520 | } | ||
| 35521 | } | ||
| 35522 | |||
| 35523 | # Read out the string | ||
| 35524 | if (! $string) { | ||
| 35525 | $self->ttsQuick('General text-to-speech error'); | ||
| 35526 | } else { | ||
| 35527 | $self->ttsQuick($string); | ||
| 35528 | } | ||
| 35529 | |||
| 35530 | # Operation complete | ||
| 35531 | return 1; | ||
| 35532 | } | ||
| 35533 | } | ||
| 35534 | |||
| 35535 | # sub ttsSwitchFlagAttrib {} # Inherited from generic task | ||
| 35536 | |||
| 35537 | sub ttsSetAlertAttrib { | ||
| 35538 | |||
| 35539 | # Called by GA::Cmd::Alert->do and PermAlert->do | ||
| 35540 | # Users can use the client command ';alert' to interact with individual tasks, typically | ||
| 35541 | # instructing them to read out information some time later (e.g. the Status task can read | ||
| 35542 | # out an alert when health points drop below a certain level or recover to a certain | ||
| 35543 | # level) | ||
| 35544 | # The ';alert' command is in the form ';alert <alert_attribute>' or | ||
| 35545 | # ';alert <alert_attribute> <value>'. The ';alert' command looks up the <alert_attribute> | ||
| 35546 | # in GA::Client->ttsAlertAttribHash, which tells it which task to call | ||
| 35547 | # | ||
| 35548 | # Expected arguments | ||
| 35549 | # $alertAttrib - The TTS attribute specified by the calling function. Must be one of | ||
| 35550 | # the keys in $self->ttsAttribHash | ||
| 35551 | # | ||
| 35552 | # Optional arguments | ||
| 35553 | # $value - The value specified by the calling function (or 'undef' if none was | ||
| 35554 | # specified) | ||
| 35555 | # $noSpecialFlag - Set to TRUE when called by GA::Cmd::PermAlert->do, in which case only | ||
| 35556 | # this task's hash of alert attributes is updated. Otherwise set to | ||
| 35557 | # FALSE (or 'undef'), in which case other things can happen when an | ||
| 35558 | # alert is set. For all built-in tasks, there is no difference in | ||
| 35559 | # behaviour | ||
| 35560 | # | ||
| 35561 | # Return values | ||
| 35562 | # 'undef' on improper arguments or if the $attrib doesn't exist in this task's | ||
| 35563 | # ->ttsAlertAttribHash | ||
| 35564 | # Otherwise returns a confirmation message for the calling function to display | ||
| 35565 | |||
| 35566 | my ($self, $alertAttrib, $value, $noSpecialFlag, $check) = @_; | ||
| 35567 | |||
| 35568 | # Local variables | ||
| 35569 | my ( | ||
| 35570 | $msg, | ||
| 35571 | @typeList, | ||
| 35572 | ); | ||
| 35573 | |||
| 35574 | # Check for improper arguments | ||
| 35575 | if (! defined $alertAttrib || defined $check) { | ||
| 35576 | |||
| 35577 | return $axmud::CLIENT->writeImproper($self->_objClass . '->ttsSetAlertAttrib', @_); | ||
| 35578 | } | ||
| 35579 | |||
| 35580 | # TTS attributes are case-insensitive | ||
| 35581 | $alertAttrib = lc($alertAttrib); | ||
| 35582 | |||
| 35583 | # Check that the specified attribute is actually used by this task (';alert' should carry | ||
| 35584 | # out this check, but better safe than sorry) | ||
| 35585 | if (! $self->ivExists('ttsAlertAttribHash', $alertAttrib)) { | ||
| 35586 | |||
| 35587 | return undef; | ||
| 35588 | |||
| 35589 | } else { | ||
| 35590 | |||
| 35591 | # If a current task performs some kind of action, when an alert attribute is set, the | ||
| 35592 | # code for the action should be placed here. (Tasks in the global initial tasklist | ||
| 35593 | # can't perform an action, of course.) | ||
| 35594 | if (! $noSpecialFlag) { | ||
| 35595 | |||
| 35596 | # (no actions to perform) | ||
| 35597 | } | ||
| 35598 | |||
| 35599 | # Custom behaviour for this task | ||
| 35600 | |||
| 35601 | @typeList = ('health', 'magic', 'energy', 'guild', 'social'); | ||
| 35602 | foreach my $type (@typeList) { | ||
| 35603 | |||
| 35604 | # (e.g. 'healthup', 'healthdown') | ||
| 35605 | if ($alertAttrib eq $type . 'up' || $alertAttrib eq $type . 'down') { | ||
| 35606 | |||
| 35607 | if (! $axmud::CLIENT->intCheck($value, 0, 100)) { | ||
| 35608 | |||
| 35609 | # Use a default minimum/maximum percentage | ||
| 35610 | if ($alertAttrib eq $type . 'down') { | ||
| 35611 | $value = 20; | ||
| 35612 | } else { | ||
| 35613 | $value = 90; | ||
| 35614 | } | ||
| 35615 | } | ||
| 35616 | |||
| 35617 | $self->ivAdd('ttsAlertAttribHash', $alertAttrib, $value); | ||
| 35618 | |||
| 35619 | $msg = 'Text-to-speech ' . $type . ' alert set at '; | ||
| 35620 | |||
| 35621 | if ($alertAttrib eq $type . 'down') { | ||
| 35622 | $msg .= 'minimum '; | ||
| 35623 | } else { | ||
| 35624 | $msg .= 'maximum '; | ||
| 35625 | } | ||
| 35626 | |||
| 35627 | $msg .= $value . '% percent'; | ||
| 35628 | } | ||
| 35629 | } | ||
| 35630 | |||
| 35631 | return $msg; | ||
| 35632 | } | ||
| 35633 | } | ||
| 35634 | |||
| 35635 | ################## | ||
| 35636 | # Task windows | ||
| 35637 | |||
| 35638 | # sub toggleWin {} # Inherited from generic task | ||
| 35639 | |||
| 35640 | sub openWin { | ||
| 35641 | |||
| 35642 | # Called by the task's ->main method or by its ->toggleWin method | ||
| 35643 | # Open a task window for this task | ||
| 35644 | # | ||
| 35645 | # Expected arguments | ||
| 35646 | # (none besides self) | ||
| 35647 | # | ||
| 35648 | # Optional arguments | ||
| 35649 | # $winmap - The winmap to use in the task window (matches a key in | ||
| 35650 | # GA::Client->winmapHash). If 'undef', $self->winmap is used | ||
| 35651 | # | ||
| 35652 | # Return values | ||
| 35653 | # 'undef' on improper arguments, if $winmap (when specified) doesn't exist or if a window | ||
| 35654 | # is not opened | ||
| 35655 | # 1 if a window is opened | ||
| 35656 | |||
| 35657 | my ($self, $winmap, $check) = @_; | ||
| 35658 | |||
| 35659 | # Check for improper arguments | ||
| 35660 | if (defined $check) { | ||
| 35661 | |||
| 35662 | return $axmud::CLIENT->writeImproper($self->_objClass . '->openWin', @_); | ||
| 35663 | } | ||
| 35664 | |||
| 35665 | # Most of the code is in the generic function | ||
| 35666 | $self->Games::Axmud::Generic::Task::openWin($winmap); | ||
| 35667 | |||
| 35668 | # Set the update flag, so that the task window will display its first text on the next task | ||
| 35669 | # loop (in case the task was running without a window, and its window has just been | ||
| 35670 | # opened) | ||
| 35671 | $self->ivPoke('updateFlag', TRUE); | ||
| 35672 | # Set the life status flag, so that the correct background colour is also displayed | ||
| 35673 | $self->ivPoke('lifeStatusChangeFlag', TRUE); | ||
| 35674 | |||
| 35675 | return 1; | ||
| 35676 | } | ||
| 35677 | |||
| 35678 | # sub closeWin {} # Inherited from generic task | ||
| 35679 | |||
| 35680 | ################## | ||
| 35681 | # Methods | ||
| 35682 | |||
| 35683 | # sub main {} # Inherited from generic task | ||
| 35684 | |||
| 35685 | sub doShutdown { | ||
| 35686 | |||
| 35687 | # Called by $self->main, just before the task completes a shutdown | ||
| 35688 | # | ||
| 35689 | # Expected arguments | ||
| 35690 | # (none besides $self) | ||
| 35691 | # | ||
| 35692 | # Return values | ||
| 35693 | # 'undef' on improper arguments | ||
| 35694 | # 1 otherwise | ||
| 35695 | |||
| 35696 | my ($self, $check) = @_; | ||
| 35697 | |||
| 35698 | # Check for improper arguments | ||
| 35699 | if (defined $check) { | ||
| 35700 | |||
| 35701 | return $axmud::CLIENT->writeImproper($self->_objClass . '->doShutdown', @_); | ||
| 35702 | } | ||
| 35703 | |||
| 35704 | # Delete the independent timers created by this task (independent interfaces are not | ||
| 35705 | # automatically deleted when a task ends, unlike dependent interfaces, which are deleted) | ||
| 35706 | $self->disactivate(); | ||
| 35707 | |||
| 35708 | # Remove any 'main' window gauges. (Assuming that nothing else is putting gauges on this | ||
| 35709 | # task's ->gaugeLevel, then GA::Strip::GaugeBox->removeGaugeLevel will automatically be | ||
| 35710 | # called) | ||
| 35711 | if ($self->gaugeObjList) { | ||
| 35712 | |||
| 35713 | # The FALSE argument means 'don't keep an empty gauge level' | ||
| 35714 | $self->gaugeStripObj->removeGauges($self->session, FALSE, $self->gaugeObjList); | ||
| 35715 | } | ||
| 35716 | |||
| 35717 | return 1; | ||
| 35718 | } | ||
| 35719 | |||
| 35720 | sub doReset { | ||
| 35721 | |||
| 35722 | # Called by $self->main, just before the task completes a reset | ||
| 35723 | # | ||
| 35724 | # Expected arguments | ||
| 35725 | # $newTaskObj - The replacement task object (not required by this function) | ||
| 35726 | # | ||
| 35727 | # Return values | ||
| 35728 | # 'undef' on improper arguments | ||
| 35729 | # 1 otherwise | ||
| 35730 | |||
| 35731 | my ($self, $newTaskObj, $check) = @_; | ||
| 35732 | |||
| 35733 | # Check for improper arguments | ||
| 35734 | if (! defined $newTaskObj || defined $check) { | ||
| 35735 | |||
| 35736 | return $axmud::CLIENT->writeImproper($self->_objClass . '->doReset', @_); | ||
| 35737 | } | ||
| 35738 | |||
| 35739 | # Delete the independent timers created by this task (independent interfaces are not | ||
| 35740 | # automatically deleted when a task ends, unlike dependent interfaces, which are deleted) | ||
| 35741 | $self->disactivate(); | ||
| 35742 | |||
| 35743 | # Remove any 'main' window gauges | ||
| 35744 | if ($self->gaugeObjList) { | ||
| 35745 | |||
| 35746 | $self->gaugeStripObj->removeGaugeLevel($self->session, $self->gaugeLevel); | ||
| 35747 | } | ||
| 35748 | |||
| 35749 | return 1; | ||
| 35750 | } | ||
| 35751 | |||
| 35752 | sub doFirstStage { | ||
| 35753 | |||
| 35754 | # Called by $self->main, just before the task completes the first stage ($self->stage) | ||
| 35755 | # | ||
| 35756 | # Expected arguments | ||
| 35757 | # (none besides $self) | ||
| 35758 | # | ||
| 35759 | # Return values | ||
| 35760 | # 'undef' on improper arguments | ||
| 35761 | # 1 otherwise | ||
| 35762 | |||
| 35763 | my ($self, $check) = @_; | ||
| 35764 | |||
| 35765 | # Local variables | ||
| 35766 | my $msg; | ||
| 35767 | |||
| 35768 | # Check for improper arguments | ||
| 35769 | if (defined $check) { | ||
| 35770 | |||
| 35771 | return $axmud::CLIENT->writeImproper($self->_objClass . '->doFirstStage', @_); | ||
| 35772 | } | ||
| 35773 | |||
| 35774 | # Display a holding message in the task window, if necessary | ||
| 35775 | if (! $self->session->loginFlag && ! $self->session->currentChar) { | ||
| 35776 | $msg = '<waiting for login and current character>'; | ||
| 35777 | } elsif (! $self->session->loginFlag) { | ||
| 35778 | $msg = '<waiting for login>'; | ||
| 35779 | } elsif (! $self->session->currentChar) { | ||
| 35780 | $msg = '<waiting for current character>'; | ||
| 35781 | } | ||
| 35782 | |||
| 35783 | if ($msg) { | ||
| 35784 | |||
| 35785 | # Empty the task window, and show the message | ||
| 35786 | $self->insertText($msg, 'empty'); | ||
| 35787 | } | ||
| 35788 | |||
| 35789 | return 1; | ||
| 35790 | } | ||
| 35791 | |||
| 35792 | sub doStage { | ||
| 35793 | |||
| 35794 | # Called by $self->main to process all stages (except stage 1) | ||
| 35795 | # | ||
| 35796 | # Expected arguments | ||
| 35797 | # (none besides $self) | ||
| 35798 | # | ||
| 35799 | # Return values | ||
| 35800 | # 'undef' on improper arguments or if this function sets that task's ->status IV to | ||
| 35801 | # 'finished' or sets its ->shutdownFlag to TRUE | ||
| 35802 | # Otherwise, we normally return the new value of $self->stage | ||
| 35803 | |||
| 35804 | my ($self, $check) = @_; | ||
| 35805 | |||
| 35806 | # Check for improper arguments | ||
| 35807 | if (defined $check) { | ||
| 35808 | |||
| 35809 | return $axmud::CLIENT->writeImproper($self->_objClass . '->doStage', @_); | ||
| 35810 | } | ||
| 35811 | |||
| 35812 | if ($self->stage == 2) { | ||
| 35813 | |||
| 35814 | # Can't do anything until the current character has been set (we check for logins at | ||
| 35815 | # stage 3) | ||
| 35816 | if (! $self->session->currentChar) { | ||
| 35817 | |||
| 35818 | # Repeat this stage indefinitely | ||
| 35819 | return $self->ivPoke('stage', 2); | ||
| 35820 | } | ||
| 35821 | |||
| 35822 | # Initialise the hash of local variables | ||
| 35823 | $self->ivPoke('localVarHash', $self->constLocalVarHash); | ||
| 35824 | |||
| 35825 | # Initialise this task's own ->statHash | ||
| 35826 | $self->ivPoke('statHash', $self->session->currentWorld->statHash); | ||
| 35827 | |||
| 35828 | # Decide whether to try to convert time strings (e.g. 'twenty past two in the morning') | ||
| 35829 | # into 24-hour clock strings using the current dictionary | ||
| 35830 | # If the dictionary's clock string lists are empty, don't try to convert time strings | ||
| 35831 | if ( | ||
| 35832 | $self->session->currentDict->clockDayHash | ||
| 35833 | || $self->session->currentDict->clockHourHash | ||
| 35834 | || $self->session->currentDict->clockMinuteHash | ||
| 35835 | ) { | ||
| 35836 | $self->ivPoke('convertTimeFlag', TRUE); | ||
| 35837 | } else { | ||
| 35838 | $self->ivPoke('convertTimeFlag', FALSE); | ||
| 35839 | } | ||
| 35840 | |||
| 35841 | # Set the update flag, so that the task window will display its first text on the next | ||
| 35842 | # task loop | ||
| 35843 | $self->ivPoke('updateFlag', TRUE); | ||
| 35844 | # Set the life status flag, so that the correct background colour is also displayed | ||
| 35845 | $self->ivPoke('lifeStatusChangeFlag', TRUE); | ||
| 35846 | |||
| 35847 | # Create 'main' window gauges (if allowed) | ||
| 35848 | $self->resetGauges(); | ||
| 35849 | |||
| 35850 | # Create triggers to capture statistics from the world | ||
| 35851 | $self->resetTriggers(); | ||
| 35852 | |||
| 35853 | # Trigger creation complete | ||
| 35854 | return $self->ivPoke('stage', 3); | ||
| 35855 | |||
| 35856 | } elsif ($self->stage == 3) { | ||
| 35857 | |||
| 35858 | my $charObj; | ||
| 35859 | |||
| 35860 | # Can't do anything until the current character has been set, and has logged in to the | ||
| 35861 | # world | ||
| 35862 | $charObj = $self->session->currentChar; | ||
| 35863 | if (! $charObj || ! $self->session->loginFlag) { | ||
| 35864 | |||
| 35865 | # Don't start sending commands, or updating the status screen, until login is | ||
| 35866 | # complete. Repeat this stage indefinitely until that time | ||
| 35867 | return $self->ivPoke('stage', 3); | ||
| 35868 | |||
| 35869 | } else { | ||
| 35870 | |||
| 35871 | if ($charObj) { | ||
| 35872 | |||
| 35873 | # Get the list of commands the task can send to the world (usually 'score', | ||
| 35874 | # 'time' etc) every few seconds | ||
| 35875 | $self->ivPoke('cmdHash', $charObj->statusCmdHash); | ||
| 35876 | |||
| 35877 | # Set this task's active flag to the value stored in the character profile | ||
| 35878 | if (defined $charObj->statusCmdFlag) { | ||
| 35879 | |||
| 35880 | $self->ivPoke('activeFlag', $charObj->statusCmdFlag); | ||
| 35881 | } | ||
| 35882 | } | ||
| 35883 | |||
| 35884 | # If the task is in 'active' mode, we can start sending commands to the world | ||
| 35885 | if ($self->activeFlag) { | ||
| 35886 | |||
| 35887 | # (However, don't auto-activate when the session is connected to a world in | ||
| 35888 | # 'offline' mode) | ||
| 35889 | if ($self->session->status eq 'offline') { | ||
| 35890 | |||
| 35891 | $self->ivPoke('activeFlag', FALSE); | ||
| 35892 | |||
| 35893 | } else { | ||
| 35894 | |||
| 35895 | $self->activate(); | ||
| 35896 | } | ||
| 35897 | } | ||
| 35898 | |||
| 35899 | return $self->ivPoke('stage', 4); | ||
| 35900 | } | ||
| 35901 | |||
| 35902 | } elsif ($self->stage == 4) { | ||
| 35903 | |||
| 35904 | # Every time the task loop runs, perform any necessary updates | ||
| 35905 | |||
| 35906 | # Read out a TTS message, if required | ||
| 35907 | if ($self->lifeStatusChangeFlag) { | ||
| 35908 | |||
| 35909 | if ($self->ivShow('ttsFlagAttribHash', 'life')) { | ||
| 35910 | |||
| 35911 | if ($self->lifeStatus eq 'sleep') { | ||
| 35912 | $self->ttsQuick('Life status set to: asleep'); | ||
| 35913 | } elsif ($self->lifeStatus eq 'passout') { | ||
| 35914 | $self->ttsQuick('Life status set to: passed out'); | ||
| 35915 | } else { | ||
| 35916 | $self->ttsQuick('Life status set to: ' . $self->lifeStatus); | ||
| 35917 | } | ||
| 35918 | } | ||
| 35919 | } | ||
| 35920 | |||
| 35921 | # If there have been any data updates... | ||
| 35922 | if ($self->updateFlag || $self->lifeStatusChangeFlag) { | ||
| 35923 | |||
| 35924 | # Update the task window (if it is still open) | ||
| 35925 | if ($self->taskWinFlag) { | ||
| 35926 | |||
| 35927 | $self->refreshWin(); | ||
| 35928 | |||
| 35929 | } else { | ||
| 35930 | |||
| 35931 | # Update 'main' window gauges; this function call is normally made from | ||
| 35932 | # ->refreshWin. It looks inelegant not to call ->setGauges right here, in all | ||
| 35933 | # circumstances, but doing it this way means that anything can call | ||
| 35934 | # ->refreshWin | ||
| 35935 | if (! $self->gaugeResetFlag) { | ||
| 35936 | |||
| 35937 | $self->setGauges(); | ||
| 35938 | |||
| 35939 | } else { | ||
| 35940 | |||
| 35941 | # New custom variable has been added. Gauges must be reset, not just | ||
| 35942 | # redrawn | ||
| 35943 | $self->resetGauges(); | ||
| 35944 | } | ||
| 35945 | |||
| 35946 | $self->ivPoke('updateFlag', FALSE); | ||
| 35947 | $self->ivPoke('lifeStatusChangeFlag', FALSE); | ||
| 35948 | $self->ivPoke('gaugeResetFlag', FALSE); | ||
| 35949 | } | ||
| 35950 | } | ||
| 35951 | |||
| 35952 | # Read out any TTS alert messages | ||
| 35953 | foreach my $attrib (sort {$a cmp $b} ($self->ivKeys('ttsPointsAlertMsgHash'))) { | ||
| 35954 | |||
| 35955 | if ($self->ivShow('ttsPointsAlertMsgHash', $attrib)) { | ||
| 35956 | |||
| 35957 | # Read the stored alert message | ||
| 35958 | $self->ttsQuick($self->ivShow('ttsPointsAlertMsgHash', $attrib)); | ||
| 35959 | # Don't read consecutive alert messages of the same type | ||
| 35960 | $self->ivAdd( | ||
| 35961 | 'ttsPointsAlertHash', | ||
| 35962 | $attrib, | ||
| 35963 | $self->ivShow('ttsPointsAlertTypeHash', $attrib), | ||
| 35964 | ); | ||
| 35965 | } | ||
| 35966 | } | ||
| 35967 | |||
| 35968 | # Reset the alert message hashes, so that each message is read only once | ||
| 35969 | $self->ivPoke( | ||
| 35970 | 'ttsPointsAlertMsgHash', | ||
| 35971 | 'health' => undef, | ||
| 35972 | 'magic' => undef, | ||
| 35973 | 'energy' => undef, | ||
| 35974 | 'guild' => undef, | ||
| 35975 | 'social' => undef, | ||
| 35976 | ); | ||
| 35977 | # (This IV has the same default state) | ||
| 35978 | $self->ivPoke('ttsPointsAlertTypeHash', $self->ttsPointsAlertMsgHash); | ||
| 35979 | |||
| 35980 | # Repeat this stage indefinitely | ||
| 35981 | return $self->ivPoke('stage', 4); | ||
| 35982 | |||
| 35983 | } else { | ||
| 35984 | |||
| 35985 | # The task stage has somehow been set to an invalid value | ||
| 35986 | return $self->invalidStage(); | ||
| 35987 | } | ||
| 35988 | } | ||
| 35989 | |||
| 35990 | sub activate { | ||
| 35991 | |||
| 35992 | # Called by $self->main or GA::Cmd::ActivateStatusTask->do | ||
| 35993 | # Starts sending commands to the world (such as 'score', 'sc' etc) every few seconds in | ||
| 35994 | # order to keep the Status task's IVs up to date | ||
| 35995 | # | ||
| 35996 | # Expected arguments | ||
| 35997 | # (none besides $self) | ||
| 35998 | # | ||
| 35999 | # Return values | ||
| 36000 | # 'undef' on improper arguments | ||
| 36001 | # 1 otherwise | ||
| 36002 | |||
| 36003 | my ($self, $check) = @_; | ||
| 36004 | |||
| 36005 | # Local variables | ||
| 36006 | my %cmdHash; | ||
| 36007 | |||
| 36008 | # Check for improper arguments | ||
| 36009 | if (defined $check) { | ||
| 36010 | |||
| 36011 | return $axmud::CLIENT->writeImproper($self->_objClass . '->activate', @_); | ||
| 36012 | } | ||
| 36013 | |||
| 36014 | # Import the hash of commands and corresponding time intervals | ||
| 36015 | %cmdHash = $self->cmdHash; | ||
| 36016 | foreach my $cmd (keys %cmdHash) { | ||
| 36017 | |||
| 36018 | my ($interval, $timerObj); | ||
| 36019 | |||
| 36020 | $interval = $cmdHash{$cmd}; | ||
| 36021 | |||
| 36022 | # Each command should be sent for the first time right now, in order to update the | ||
| 36023 | # task window as quickly as possible | ||
| 36024 | $self->session->worldCmd($cmd); | ||
| 36025 | |||
| 36026 | # Create independent timers to send the command to the world every few seconds | ||
| 36027 | $timerObj = $self->session->createIndependentInterface( | ||
| 36028 | 'timer', | ||
| 36029 | $interval, # Stimulus | ||
| 36030 | $cmd, # Response | ||
| 36031 | ); | ||
| 36032 | |||
| 36033 | # Remember the interface object, so it can be deleted when the task shuts down | ||
| 36034 | # (actually, when $self->disactivate is called) | ||
| 36035 | $self->ivAdd('timerHash', $cmd, $timerObj); | ||
| 36036 | } | ||
| 36037 | |||
| 36038 | # Mark the task as being in 'active' mode | ||
| 36039 | $self->ivPoke('activeFlag', TRUE); | ||
| 36040 | # Reset the task's triggers, using this flag to set each trigger as 'gagged' (or not) as | ||
| 36041 | # appropriate | ||
| 36042 | $self->resetTriggers(); | ||
| 36043 | |||
| 36044 | $self->refreshWin(); | ||
| 36045 | |||
| 36046 | return 1; | ||
| 36047 | } | ||
| 36048 | |||
| 36049 | sub disactivate { | ||
| 36050 | |||
| 36051 | # Called by $self->main or GA::Cmd::DisactivateStatusTask->do | ||
| 36052 | # Stops sending commands to the world (usually 'score', 'sc' etc) every few seconds | ||
| 36053 | # | ||
| 36054 | # Expected arguments | ||
| 36055 | # (none besides $self) | ||
| 36056 | # | ||
| 36057 | # Return values | ||
| 36058 | # 'undef' on improper arguments | ||
| 36059 | # 1 otherwise | ||
| 36060 | |||
| 36061 | my ($self, $check) = @_; | ||
| 36062 | |||
| 36063 | # Check for improper arguments | ||
| 36064 | if (defined $check) { | ||
| 36065 | |||
| 36066 | return $axmud::CLIENT->writeImproper($self->_objClass . '->disactivate', @_); | ||
| 36067 | } | ||
| 36068 | |||
| 36069 | # Import the hash of independent timer interfaces | ||
| 36070 | foreach my $obj ($self->ivValues('timerHash')) { | ||
| 36071 | |||
| 36072 | # Delete the timer. The TRUE argument means 'don't show an error message if the | ||
| 36073 | # interface has already been deleted (probably during a disconnection)' | ||
| 36074 | $self->session->deleteInterface($obj->name, TRUE); | ||
| 36075 | } | ||
| 36076 | |||
| 36077 | $self->ivEmpty('timerHash'); | ||
| 36078 | |||
| 36079 | # Mark the task as being in 'disactivated' mode | ||
| 36080 | $self->ivPoke('activeFlag', FALSE); | ||
| 36081 | # Reset the task's triggers, using this flag to set each trigger as 'gagged' (or not) as | ||
| 36082 | # appropriate (but don't bother if the task is shutting down) | ||
| 36083 | if (! $self->shutdownFlag) { | ||
| 36084 | |||
| 36085 | $self->resetTriggers(); | ||
| 36086 | } | ||
| 36087 | |||
| 36088 | $self->refreshWin(); | ||
| 36089 | |||
| 36090 | return 1; | ||
| 36091 | } | ||
| 36092 | |||
| 36093 | sub refreshWin { | ||
| 36094 | |||
| 36095 | # Called by $self->doStage, stage 4 | ||
| 36096 | # Displays information about the current location in the task window | ||
| 36097 | # | ||
| 36098 | # Expected arguments | ||
| 36099 | # (none besides $self) | ||
| 36100 | # | ||
| 36101 | # Return values | ||
| 36102 | # 'undef' on improper arguments | ||
| 36103 | # 1 on success | ||
| 36104 | |||
| 36105 | my ($self, $check) = @_; | ||
| 36106 | |||
| 36107 | # Local variables | ||
| 36108 | my ( | ||
| 36109 | $charObj, $health, $colour, | ||
| 36110 | @formatList, | ||
| 36111 | ); | ||
| 36112 | |||
| 36113 | # Check for improper arguments | ||
| 36114 | if (defined $check) { | ||
| 36115 | |||
| 36116 | return $axmud::CLIENT->writeImproper($self->_objClass . '->refreshWin', @_); | ||
| 36117 | } | ||
| 36118 | |||
| 36119 | # This function can be called by $self->disactivate, when Axmud closes down, in which case | ||
| 36120 | # there might not be a window still open. If that's the case, there's nothing for this | ||
| 36121 | # function to do | ||
| 36122 | # Also nothing to do if there's no current character profile | ||
| 36123 | $charObj = $self->session->currentChar; | ||
| 36124 | if (! $self->taskWinFlag || ! $charObj) { | ||
| 36125 | |||
| 36126 | return undef; | ||
| 36127 | } | ||
| 36128 | |||
| 36129 | # If there's been a change in life status, or if the character's health points have moved | ||
| 36130 | # into a new band, then the task window's background colour must also be changed | ||
| 36131 | if ( | ||
| 36132 | $self->allowColourFlag | ||
| 36133 | && ($self->lifeStatusChangeFlag || $self->healthChangeFlag) | ||
| 36134 | ) { | ||
| 36135 | if ($charObj->lifeStatus eq 'alive') { | ||
| 36136 | |||
| 36137 | # If either ->healthPoints or ->healthPointsMax not known, assume health is 100% | ||
| 36138 | if ( | ||
| 36139 | ! defined $charObj->healthPoints | ||
| 36140 | || ! defined $charObj->healthPointsMax | ||
| 36141 | || $charObj->healthPointsMax == 0 | ||
| 36142 | ) { | ||
| 36143 | $colour = $self->aliveColour; | ||
| 36144 | |||
| 36145 | } else { | ||
| 36146 | |||
| 36147 | $health = $charObj->healthPoints / $charObj->healthPointsMax; | ||
| 36148 | if ($health <= 0.10) { | ||
| 36149 | $colour = $self->alive10Colour; | ||
| 36150 | } elsif ($health <= 0.30) { | ||
| 36151 | $colour = $self->alive30Colour; | ||
| 36152 | } elsif ($health <= 0.50) { | ||
| 36153 | $colour = $self->alive50Colour; | ||
| 36154 | } else { | ||
| 36155 | $colour = $self->aliveColour; | ||
| 36156 | } | ||
| 36157 | } | ||
| 36158 | |||
| 36159 | } elsif ($charObj->lifeStatus eq 'sleep') { | ||
| 36160 | |||
| 36161 | $colour = $self->asleepColour; | ||
| 36162 | |||
| 36163 | } elsif ($charObj->lifeStatus eq 'passout') { | ||
| 36164 | |||
| 36165 | $colour = $self->passedOutColour; | ||
| 36166 | |||
| 36167 | } elsif ($charObj->lifeStatus eq 'dead') { | ||
| 36168 | |||
| 36169 | $colour = $self->deadColour; | ||
| 36170 | |||
| 36171 | } else { | ||
| 36172 | |||
| 36173 | # Just in case $lifeStatus has been set to a valid value, use the default colour | ||
| 36174 | $colour = $self->aliveColour; | ||
| 36175 | } | ||
| 36176 | |||
| 36177 | # Set the background colour | ||
| 36178 | $self->defaultTabObj->paneObj->applyMonochrome($self->defaultTabObj, $colour); | ||
| 36179 | |||
| 36180 | # Update the title bar | ||
| 36181 | if ($charObj->lifeStatus eq 'sleep') { | ||
| 36182 | $self->setTaskWinTitle('(SLEEP)', TRUE); | ||
| 36183 | } elsif ($charObj->lifeStatus eq 'passout') { | ||
| 36184 | $self->setTaskWinTitle('(PASSED OUT)', TRUE); | ||
| 36185 | } elsif ($charObj->lifeStatus eq 'dead') { | ||
| 36186 | $self->setTaskWinTitle('(DEAD)', TRUE); | ||
| 36187 | } else { | ||
| 36188 | $self->setTaskWinTitle(); | ||
| 36189 | } | ||
| 36190 | |||
| 36191 | # Update IVs | ||
| 36192 | $self->ivPoke('lifeStatusChangeFlag', FALSE); | ||
| 36193 | $self->ivPoke('healthChangeFlag', FALSE); | ||
| 36194 | } | ||
| 36195 | |||
| 36196 | # Get the text to display in the window, with all variables (in the form @variable_name@) | ||
| 36197 | # replaced by their corresponding values | ||
| 36198 | @formatList = $self->processFormatList(); | ||
| 36199 | # Display the resulting text | ||
| 36200 | $self->insertQuick(join("\n", @formatList)); | ||
| 36201 | # Mark the task window as updated | ||
| 36202 | $self->ivPoke('updateFlag', FALSE); | ||
| 36203 | |||
| 36204 | # Set the values displayed by any 'main' window gauges and redraw them (if visible) | ||
| 36205 | if (! $self->gaugeResetFlag) { | ||
| 36206 | |||
| 36207 | $self->setGauges(); | ||
| 36208 | |||
| 36209 | } else { | ||
| 36210 | |||
| 36211 | # New custom variable has been added. Gauges must be reset, not just redrawn | ||
| 36212 | $self->resetGauges(); | ||
| 36213 | $self->ivPoke('gaugeResetFlag', FALSE); | ||
| 36214 | } | ||
| 36215 | |||
| 36216 | return 1; | ||
| 36217 | } | ||
| 36218 | |||
| 36219 | sub processFormatList { | ||
| 36220 | |||
| 36221 | # Called by $self->refreshWin | ||
| 36222 | # Taking the current world profile's ->statusFormatList as a template, replaces all | ||
| 36223 | # variables with their corresponding values | ||
| 36224 | # Variables are in the form @variable@, where 'variable' is one of the keys in | ||
| 36225 | # $self->constCharVarHash, ->constFixedVarHash, ->constPseudoVarHash, ->localVarHash or | ||
| 36226 | # ->customVarHash | ||
| 36227 | # | ||
| 36228 | # Expected arguments | ||
| 36229 | # (none besides $self) | ||
| 36230 | # | ||
| 36231 | # Return values | ||
| 36232 | # An empty list on improper arguments, or if the task is forced to shut down here | ||
| 36233 | # Otherwise, returns the modified @displayList | ||
| 36234 | |||
| 36235 | my ($self, $taskString, $check) = @_; | ||
| 36236 | |||
| 36237 | # Local variables | ||
| 36238 | my (@emptyList, @lineList); | ||
| 36239 | |||
| 36240 | # Check for improper arguments | ||
| 36241 | if (defined $check) { | ||
| 36242 | |||
| 36243 | $axmud::CLIENT->writeImproper($self->_objClass . '->processFormatList', @_); | ||
| 36244 | return @emptyList; | ||
| 36245 | } | ||
| 36246 | |||
| 36247 | @lineList = $self->session->currentWorld->statusFormatList; | ||
| 36248 | foreach my $line (@lineList) { | ||
| 36249 | |||
| 36250 | my @matchList; | ||
| 36251 | |||
| 36252 | # Get a list of variables in the form @variable@ | ||
| 36253 | @matchList = $line =~ m/\@([\w\_]+)\@/g; | ||
| 36254 | |||
| 36255 | foreach my $varName (@matchList) { | ||
| 36256 | |||
| 36257 | my $value = $self->getValue($varName); | ||
| 36258 | |||
| 36259 | if (! defined $value) { | ||
| 36260 | |||
| 36261 | # Unrecognised variable, or a variable whose corresponding value is not set; | ||
| 36262 | # replace the variable with a ? | ||
| 36263 | $line =~ s/\@$varName\@/?/; | ||
| 36264 | |||
| 36265 | } elsif ($varName eq 'purse_contents' || $varName eq 'bank_balance') { | ||
| 36266 | |||
| 36267 | # (For a cash value like $10.50, make sure we display 10.50 not 10.5) | ||
| 36268 | $value = $self->roundCashValue($value, TRUE); | ||
| 36269 | |||
| 36270 | # Replace the variable with the corresponding value | ||
| 36271 | $line =~ s/\@$varName\@/$value/; | ||
| 36272 | |||
| 36273 | } else { | ||
| 36274 | |||
| 36275 | # Commify a numeric value | ||
| 36276 | if ($axmud::CLIENT->floatCheck($value)) { | ||
| 36277 | |||
| 36278 | $value = $axmud::CLIENT->commify($value); | ||
| 36279 | } | ||
| 36280 | |||
| 36281 | # Replace the variable with the corresponding value | ||
| 36282 | $line =~ s/\@$varName\@/$value/; | ||
| 36283 | } | ||
| 36284 | } | ||
| 36285 | } | ||
| 36286 | |||
| 36287 | return @lineList; | ||
| 36288 | } | ||
| 36289 | |||
| 36290 | sub getValue { | ||
| 36291 | |||
| 36292 | # Can be called by anything | ||
| 36293 | # $self->constCharVarHash, ->constFixedVarHash, ->constPseudoVarHash, ->localVarHash or | ||
| 36294 | # ->customVarHash specify a set of variables recognised by this task | ||
| 36295 | # Given one of those variables, returns the corresponding value; either one stored somewhere | ||
| 36296 | # else (typically in the current character profile), as an IV in this task, or a value | ||
| 36297 | # generated by this function | ||
| 36298 | # | ||
| 36299 | # Expected arguments | ||
| 36300 | # $var - One of the variables stored as a key in the hashes above, e.g. 'health_points' | ||
| 36301 | # | ||
| 36302 | # Return values | ||
| 36303 | # 'undef' on improper arguments, if $var is not stored as a key in the hashes above, or if | ||
| 36304 | # the variable's corresponding value is not set (i.e. is 'undef') | ||
| 36305 | # Otherwise returns the variable's corresponding value | ||
| 36306 | |||
| 36307 | my ($self, $var, $check) = @_; | ||
| 36308 | |||
| 36309 | # Local variables | ||
| 36310 | my ( | ||
| 36311 | $charObj, $iv, $string, $number, | ||
| 36312 | @taskList, | ||
| 36313 | %taskHash, | ||
| 36314 | ); | ||
| 36315 | |||
| 36316 | # Check for improper arguments | ||
| 36317 | if (! defined $var || defined $check) { | ||
| 36318 | |||
| 36319 | return $axmud::CLIENT->writeImproper($self->_objClass . '->getValue', @_); | ||
| 36320 | } | ||
| 36321 | |||
| 36322 | # Import the current character (for convenience) | ||
| 36323 | $charObj = $self->session->currentChar; | ||
| 36324 | $string = ''; | ||
| 36325 | $number = 0; | ||
| 36326 | |||
| 36327 | # Character values | ||
| 36328 | if ($self->ivExists('constCharVarHash', $var)) { | ||
| 36329 | |||
| 36330 | # Get the character profile IV, and return its value | ||
| 36331 | $iv = $self->ivShow('constCharVarHash', $var); | ||
| 36332 | |||
| 36333 | if ($charObj && exists $charObj->{$iv}) { | ||
| 36334 | return $charObj->$iv; | ||
| 36335 | } else { | ||
| 36336 | return undef; | ||
| 36337 | } | ||
| 36338 | |||
| 36339 | # Fixed values | ||
| 36340 | } elsif ($self->ivExists('constFixedVarHash', $var)) { | ||
| 36341 | |||
| 36342 | # Get the character profile IV, and return its value | ||
| 36343 | $iv = $self->ivShow('constFixedVarHash', $var); | ||
| 36344 | |||
| 36345 | if ($charObj && exists $charObj->{$iv}) { | ||
| 36346 | return $charObj->$iv; | ||
| 36347 | } else { | ||
| 36348 | return undef; | ||
| 36349 | } | ||
| 36350 | |||
| 36351 | # Local variables | ||
| 36352 | } elsif ($self->ivExists('localVarHash', $var)) { | ||
| 36353 | |||
| 36354 | return $self->ivShow('localVarHash', $var); | ||
| 36355 | |||
| 36356 | # Counter variables | ||
| 36357 | } elsif ($self->ivExists('counterVarHash', $var)) { | ||
| 36358 | |||
| 36359 | if ($self->fightCountFlag || $self->interactCountFlag) { | ||
| 36360 | |||
| 36361 | $string = $self->ivShow('counterVarHash', $var); | ||
| 36362 | } | ||
| 36363 | |||
| 36364 | if (! defined $string || $string eq '') { | ||
| 36365 | return '(off)'; | ||
| 36366 | } else { | ||
| 36367 | return $string; | ||
| 36368 | } | ||
| 36369 | |||
| 36370 | } elsif ($self->ivExists('constCounterVarHash', $var)) { | ||
| 36371 | |||
| 36372 | # No counters are running | ||
| 36373 | return '(off)'; | ||
| 36374 | |||
| 36375 | # Custom variables | ||
| 36376 | } elsif ($self->ivExists('customVarHash', $var)) { | ||
| 36377 | |||
| 36378 | return $self->ivShow('customVarHash', $var); | ||
| 36379 | |||
| 36380 | # Pseudo variables | ||
| 36381 | } elsif ($self->ivExists('constPseudoVarHash', $var)) { | ||
| 36382 | |||
| 36383 | if ($var eq 'world') { | ||
| 36384 | |||
| 36385 | return $self->session->currentWorld->name; | ||
| 36386 | |||
| 36387 | } elsif ($var eq 'guild') { | ||
| 36388 | |||
| 36389 | if ($self->session->currentGuild) { | ||
| 36390 | return $self->session->currentGuild->name; | ||
| 36391 | } else { | ||
| 36392 | return undef; | ||
| 36393 | } | ||
| 36394 | |||
| 36395 | } elsif ($var eq 'race') { | ||
| 36396 | |||
| 36397 | if ($self->session->currentRace) { | ||
| 36398 | return $self->session->currentRace->name; | ||
| 36399 | } else { | ||
| 36400 | return undef; | ||
| 36401 | } | ||
| 36402 | |||
| 36403 | } elsif ($var eq 'char') { | ||
| 36404 | |||
| 36405 | if ($charObj) { | ||
| 36406 | return $charObj->name; | ||
| 36407 | } else { | ||
| 36408 | return undef; | ||
| 36409 | } | ||
| 36410 | |||
| 36411 | } elsif ($var eq 'affects') { | ||
| 36412 | |||
| 36413 | foreach my $affect (sort {lc($a) cmp lc($b)} ($self->ivKeys('affectHash'))) { | ||
| 36414 | |||
| 36415 | $string .= substr($affect, 0, 3) . ' '; | ||
| 36416 | } | ||
| 36417 | |||
| 36418 | # Remove the final trailing space, if there is one | ||
| 36419 | $string =~ s/\s+$//; | ||
| 36420 | |||
| 36421 | return $string; | ||
| 36422 | |||
| 36423 | } elsif ($var eq 'stats') { | ||
| 36424 | |||
| 36425 | # If the current world's ->statOrderList is set, display stats in that order. | ||
| 36426 | # Otherwise, display them alphabetically | ||
| 36427 | if ($self->session->currentWorld->statOrderList) { | ||
| 36428 | |||
| 36429 | # Display in the order specified by the world profile | ||
| 36430 | foreach my $stat ($self->session->currentWorld->statOrderList) { | ||
| 36431 | |||
| 36432 | if ($self->ivExists('statHash', $stat)) { | ||
| 36433 | |||
| 36434 | $string .= substr($stat, 0, 3) . ': ' | ||
| 36435 | . $self->ivShow('statHash', $stat) . ' '; | ||
| 36436 | } | ||
| 36437 | } | ||
| 36438 | |||
| 36439 | } else { | ||
| 36440 | |||
| 36441 | # Display alphabetically | ||
| 36442 | foreach my $stat (sort {lc($a) cmp lc($b)} ($self->ivKeys('statHash'))) { | ||
| 36443 | |||
| 36444 | $string .= substr($stat, 0, 3) . ': ' | ||
| 36445 | . $self->ivShow('statHash', $stat) . ' '; | ||
| 36446 | } | ||
| 36447 | } | ||
| 36448 | |||
| 36449 | # Remove the final trailing space, if there is one | ||
| 36450 | $string =~ s/\s+$//; | ||
| 36451 | |||
| 36452 | return $string; | ||
| 36453 | |||
| 36454 | } elsif ($var eq 'age_unit') { | ||
| 36455 | |||
| 36456 | $string = $self->session->currentWorld->charAgeUnit; | ||
| 36457 | # (Convert the unit to a plural, if possible) | ||
| 36458 | if ($self->session->currentDict->ivExists('timePluralHash', $string)) { | ||
| 36459 | |||
| 36460 | $string = $self->session->currentDict->ivShow('timePluralHash', $string); | ||
| 36461 | } | ||
| 36462 | |||
| 36463 | return $string; | ||
| 36464 | |||
| 36465 | } elsif ($var eq 'money_count') { | ||
| 36466 | |||
| 36467 | if (! $charObj) { | ||
| 36468 | |||
| 36469 | return undef; | ||
| 36470 | |||
| 36471 | } else { | ||
| 36472 | |||
| 36473 | if (defined $charObj->bankBalance) { | ||
| 36474 | |||
| 36475 | $number += $charObj->bankBalance; | ||
| 36476 | } | ||
| 36477 | |||
| 36478 | if (defined $charObj->purseContents) { | ||
| 36479 | |||
| 36480 | $number += $charObj->purseContents; | ||
| 36481 | } | ||
| 36482 | |||
| 36483 | return $number; | ||
| 36484 | } | ||
| 36485 | |||
| 36486 | } elsif ($var eq 'coward_count') { | ||
| 36487 | |||
| 36488 | if (! $charObj) { | ||
| 36489 | |||
| 36490 | return undef; | ||
| 36491 | |||
| 36492 | } else { | ||
| 36493 | |||
| 36494 | if (defined $charObj->fleeCount) { | ||
| 36495 | |||
| 36496 | $number += $charObj->fleeCount; | ||
| 36497 | } | ||
| 36498 | |||
| 36499 | if (defined $charObj->escapeCount) { | ||
| 36500 | |||
| 36501 | $number += $charObj->escapeCount; | ||
| 36502 | } | ||
| 36503 | |||
| 36504 | return $number; | ||
| 36505 | } | ||
| 36506 | |||
| 36507 | } elsif ($var eq 'task') { | ||
| 36508 | |||
| 36509 | # Create a string representing the tasks in the current tasklist, with one addition | ||
| 36510 | # for each type of that's running | ||
| 36511 | foreach my $taskObj ($self->session->ivValues('currentTaskHash')) { | ||
| 36512 | |||
| 36513 | $taskHash{$taskObj->shortName} = undef; | ||
| 36514 | } | ||
| 36515 | |||
| 36516 | @taskList = sort {lc($a) cmp lc($b)} (keys %taskHash); | ||
| 36517 | $string = '[' . join(' ', @taskList) . ']'; | ||
| 36518 | |||
| 36519 | return $string; | ||
| 36520 | |||
| 36521 | } elsif ($var eq 'task_active') { | ||
| 36522 | |||
| 36523 | if (! $self->activeFlag) { | ||
| 36524 | return '[NOT ACTIVE]'; | ||
| 36525 | } else { | ||
| 36526 | return '[ACTIVE]'; | ||
| 36527 | } | ||
| 36528 | |||
| 36529 | } elsif ($var eq 'local_time') { | ||
| 36530 | |||
| 36531 | return $axmud::CLIENT->localTime; | ||
| 36532 | |||
| 36533 | } elsif ($var eq 'session_time') { | ||
| 36534 | |||
| 36535 | return $self->session->sessionTime; | ||
| 36536 | |||
| 36537 | } elsif ($var eq 'temp_xp_average') { | ||
| 36538 | |||
| 36539 | my ($xp, $kill, $success); | ||
| 36540 | |||
| 36541 | if ($self->fightCountFlag || $self->interactCountFlag) { | ||
| 36542 | |||
| 36543 | $xp = $self->getCounterValue('temp_xp_count'); | ||
| 36544 | $kill = $self->getCounterValue('temp_kill_count'); | ||
| 36545 | $success = $self->getCounterValue('temp_interact_success_count'); | ||
| 36546 | |||
| 36547 | if ($xp && ($kill + $success) > 0) { | ||
| 36548 | |||
| 36549 | $string = int($xp / ($kill + $success)); | ||
| 36550 | } | ||
| 36551 | } | ||
| 36552 | |||
| 36553 | if ($string eq '') { | ||
| 36554 | return 'n/a'; | ||
| 36555 | } else { | ||
| 36556 | return $string; | ||
| 36557 | } | ||
| 36558 | |||
| 36559 | } elsif ($var eq 'temp_money_count') { | ||
| 36560 | |||
| 36561 | if ($self->fightCountFlag || $self->interactCountFlag) { | ||
| 36562 | |||
| 36563 | $number = $self->getCounterValue('temp_bank_count') | ||
| 36564 | + $self->getCounterValue('temp_purse_count'); | ||
| 36565 | |||
| 36566 | } | ||
| 36567 | |||
| 36568 | return $number; | ||
| 36569 | |||
| 36570 | } elsif ($var eq 'temp_timer') { | ||
| 36571 | |||
| 36572 | if ($self->fightCountFlag || $self->interactCountFlag) { | ||
| 36573 | |||
| 36574 | $string = int ( | ||
| 36575 | ($self->session->sessionTime - $self->counterStartTime) | ||
| 36576 | / 60 # Both values in seconds, so convert to minutes | ||
| 36577 | ); | ||
| 36578 | |||
| 36579 | } else { | ||
| 36580 | |||
| 36581 | $string = '(off)'; | ||
| 36582 | } | ||
| 36583 | |||
| 36584 | return $string; | ||
| 36585 | |||
| 36586 | } elsif ($var eq 'fight_string') { | ||
| 36587 | |||
| 36588 | if (! $charObj) { | ||
| 36589 | |||
| 36590 | return undef; | ||
| 36591 | |||
| 36592 | } else { | ||
| 36593 | |||
| 36594 | $string = 'Fig: ' . $axmud::CLIENT->commify($charObj->fightCount) | ||
| 36595 | . ' Kl: ' . $axmud::CLIENT->commify($charObj->killCount) | ||
| 36596 | . ' Wy: ' . $axmud::CLIENT->commify($charObj->wimpyCount) | ||
| 36597 | . ' Df: ' . $axmud::CLIENT->commify($charObj->fightDefeatCount); | ||
| 36598 | |||
| 36599 | return $string; | ||
| 36600 | } | ||
| 36601 | |||
| 36602 | } elsif ($var eq 'interact_string') { | ||
| 36603 | |||
| 36604 | if (! $charObj) { | ||
| 36605 | |||
| 36606 | return undef; | ||
| 36607 | |||
| 36608 | } else { | ||
| 36609 | |||
| 36610 | $string = 'Int: ' . $axmud::CLIENT->commify($charObj->interactCount) | ||
| 36611 | . ' Sc: ' . $axmud::CLIENT->commify($charObj->interactSuccessCount) | ||
| 36612 | . ' Fl: ' . $axmud::CLIENT->commify($charObj->interactFailCount) | ||
| 36613 | . ' Ft: ' . $axmud::CLIENT->commify($charObj->interactFightCount) | ||
| 36614 | . ' Ds: ' . $axmud::CLIENT->commify($charObj->interactDisasterCount); | ||
| 36615 | |||
| 36616 | return $string; | ||
| 36617 | } | ||
| 36618 | |||
| 36619 | } elsif ($var eq 'coward_string') { | ||
| 36620 | |||
| 36621 | if (! $charObj) { | ||
| 36622 | |||
| 36623 | return undef; | ||
| 36624 | |||
| 36625 | } else { | ||
| 36626 | |||
| 36627 | $string = 'Esc: ' . $axmud::CLIENT->commify($charObj->escapeCount) | ||
| 36628 | . ' Fl: ' . $axmud::CLIENT->commify($charObj->fleeCount); | ||
| 36629 | |||
| 36630 | return $string; | ||
| 36631 | } | ||
| 36632 | |||
| 36633 | } elsif ($var eq 'temp_fight_string') { | ||
| 36634 | |||
| 36635 | if (! $self->fightCountFlag) { | ||
| 36636 | |||
| 36637 | return '(Fight count off)'; | ||
| 36638 | } | ||
| 36639 | |||
| 36640 | $string = 'Fig: ' | ||
| 36641 | . $axmud::CLIENT->commify($self->getCounterValue('temp_fight_count')) | ||
| 36642 | . ' Kl: ' | ||
| 36643 | . $axmud::CLIENT->commify($self->getCounterValue('temp_kill_count')) | ||
| 36644 | . ' Wy: ' | ||
| 36645 | . $axmud::CLIENT->commify($self->getCounterValue('temp_wimpy_count')) | ||
| 36646 | . ' Df: ' | ||
| 36647 | . $axmud::CLIENT->commify($self->getCounterValue('temp_fight_defeat_count')); | ||
| 36648 | |||
| 36649 | return $string; | ||
| 36650 | |||
| 36651 | } elsif ($var eq 'temp_interact_string') { | ||
| 36652 | |||
| 36653 | if (! $self->interactCountFlag) { | ||
| 36654 | |||
| 36655 | return '(Interact count off)'; | ||
| 36656 | } | ||
| 36657 | |||
| 36658 | $string = 'Int: ' | ||
| 36659 | . $axmud::CLIENT->commify($self->getCounterValue('temp_interact_count')) | ||
| 36660 | . ' Sc: ' | ||
| 36661 | . $axmud::CLIENT->commify($self->getCounterValue('temp_interact_success_count')) | ||
| 36662 | . ' Fl: ' | ||
| 36663 | . $axmud::CLIENT->commify($self->getCounterValue('temp_interact_fail_count')) | ||
| 36664 | . ' Ft: ' | ||
| 36665 | . $axmud::CLIENT->commify($self->getCounterValue('temp_interact_fight_count')) | ||
| 36666 | . ' Ds: ' | ||
| 36667 | . $axmud::CLIENT->commify( | ||
| 36668 | $self->getCounterValue('temp_interact_disaster_count'), | ||
| 36669 | ); | ||
| 36670 | |||
| 36671 | return $string; | ||
| 36672 | |||
| 36673 | } elsif ($var eq 'temp_coward_string') { | ||
| 36674 | |||
| 36675 | if (! $self->fightCountFlag && ! $self->interactCountFlag) { | ||
| 36676 | |||
| 36677 | return '(Coward count off)'; | ||
| 36678 | } | ||
| 36679 | |||
| 36680 | $string = 'Esc: ' | ||
| 36681 | . $axmud::CLIENT->commify($self->getCounterValue('temp_escape_count')) | ||
| 36682 | . ' Fl: ' | ||
| 36683 | . $axmud::CLIENT->commify($self->getCounterValue('temp_flee_count')); | ||
| 36684 | |||
| 36685 | return $string; | ||
| 36686 | |||
| 36687 | } else { | ||
| 36688 | |||
| 36689 | # Emergency failsafe (this shouldn't be executed) | ||
| 36690 | return undef; | ||
| 36691 | } | ||
| 36692 | |||
| 36693 | } else { | ||
| 36694 | |||
| 36695 | # Unrecognised variable | ||
| 36696 | return undef; | ||
| 36697 | } | ||
| 36698 | } | ||
| 36699 | |||
| 36700 | sub getCounterValue { | ||
| 36701 | |||
| 36702 | # Called by $self->getValue to extract a numerical value from $self->counterVarHash, or 0 if | ||
| 36703 | # the value isn't defined (for use in sums and concatenated strings) | ||
| 36704 | # | ||
| 36705 | # Expected arguments | ||
| 36706 | # $var - A variable stored as a key in $self->counterVarHash, e.g. | ||
| 36707 | # 'temp_fight_count' | ||
| 36708 | # | ||
| 36709 | # Return values | ||
| 36710 | # 'undef' on improper arguments | ||
| 36711 | # Otherwise the specified variable's value (or 0 if the variable's value is 'undef') | ||
| 36712 | |||
| 36713 | my ($self, $var, $check) = @_; | ||
| 36714 | |||
| 36715 | # Local variables | ||
| 36716 | my $val; | ||
| 36717 | |||
| 36718 | # Check for improper arguments | ||
| 36719 | if (defined $check) { | ||
| 36720 | |||
| 36721 | return $axmud::CLIENT->writeImproper($self->_objClass . '->getCounterValue', @_); | ||
| 36722 | } | ||
| 36723 | |||
| 36724 | $val = $self->ivShow('counterVarHash', $var); | ||
| 36725 | if (! defined $val) { | ||
| 36726 | |||
| 36727 | $val = 0; | ||
| 36728 | } | ||
| 36729 | |||
| 36730 | return $val; | ||
| 36731 | } | ||
| 36732 | |||
| 36733 | sub setValue { | ||
| 36734 | |||
| 36735 | # Called by several functions in this task, but can be called by anything (especially by | ||
| 36736 | # any code that wants to update the task and the current character profile at the same | ||
| 36737 | # time) | ||
| 36738 | # Sets a character, local or custom variable. Any related counter variable is updated at | ||
| 36739 | # the same time | ||
| 36740 | # Fixed, pseudo and counter variables are ignored, if specified directly | ||
| 36741 | # | ||
| 36742 | # Expected arguments | ||
| 36743 | # $var - A character, local or custom variable (stored as a key in | ||
| 36744 | # $self->constCharVarHash, ->localVarHash or ->customVarHash) | ||
| 36745 | # | ||
| 36746 | # Optional arguments | ||
| 36747 | # $val - The value to set (can be 'undef') | ||
| 36748 | # | ||
| 36749 | # Return values | ||
| 36750 | # 'undef' on improper arguments, if $var is not a recognised character/local/custom | ||
| 36751 | # variable, or if $val should be stored in the current character profile, but no such | ||
| 36752 | # profile exists | ||
| 36753 | # 1 otherwise | ||
| 36754 | |||
| 36755 | my ($self, $var, $val, $check) = @_; | ||
| 36756 | |||
| 36757 | # Local variables | ||
| 36758 | my ($charObj, $iv, $oppVar, $baseVal, $attrib); | ||
| 36759 | |||
| 36760 | # Check for improper arguments | ||
| 36761 | if (! defined $var || defined $check) { | ||
| 36762 | |||
| 36763 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setValue', @_); | ||
| 36764 | } | ||
| 36765 | |||
| 36766 | # Ignore fixed, pseudo and counter variables | ||
| 36767 | if ( | ||
| 36768 | $self->ivExists('constFixedVarHash', $var) | ||
| 36769 | || $self->ivExists('constPseudoVarHash', $var) | ||
| 36770 | || $self->ivExists('constCounterVarHash', $var) | ||
| 36771 | ) { | ||
| 36772 | return undef; | ||
| 36773 | } | ||
| 36774 | |||
| 36775 | # Import the current character profile (for convenience) | ||
| 36776 | $charObj = $self->session->currentChar; | ||
| 36777 | |||
| 36778 | # For the variables 'health_points'/'health_points_max', the task window's background colour | ||
| 36779 | # must be set before setting the IV (so the previous and new values can be compared) | ||
| 36780 | if ($charObj) { | ||
| 36781 | |||
| 36782 | if ($var eq 'health_points') { | ||
| 36783 | |||
| 36784 | $self->checkHealthChange($val, $charObj->healthPointsMax); | ||
| 36785 | |||
| 36786 | } elsif ($var eq 'health_points_max') { | ||
| 36787 | |||
| 36788 | $self->checkHealthChange($charObj->healthPoints, $val); | ||
| 36789 | } | ||
| 36790 | } | ||
| 36791 | |||
| 36792 | # Set character variables (stored in the current character) | ||
| 36793 | if ($charObj && $self->ivExists('constCharVarHash', $var)) { | ||
| 36794 | |||
| 36795 | $iv = $self->ivShow('constCharVarHash', $var); | ||
| 36796 | |||
| 36797 | # Update the current character profile | ||
| 36798 | $charObj->ivPoke($iv, $val); | ||
| 36799 | |||
| 36800 | # Set local variables (stored in this task's IVs) | ||
| 36801 | } elsif ($self->ivExists('localVarHash', $var)) { | ||
| 36802 | |||
| 36803 | $self->ivAdd('localVarHash', $var, $val); | ||
| 36804 | |||
| 36805 | # Set custom variables (stored in this task's IVs; the custom variable is created if it | ||
| 36806 | # doesn't exist already) | ||
| 36807 | } else { | ||
| 36808 | |||
| 36809 | $self->ivAdd('localVarHash', $var, $val); | ||
| 36810 | } | ||
| 36811 | |||
| 36812 | # Update counters | ||
| 36813 | if ($self->ivExists('constCounterRevHash', $var)) { | ||
| 36814 | |||
| 36815 | # e.g. convert 'temp_xp_count' to 'xp_total' | ||
| 36816 | $oppVar = $self->ivShow('constCounterRevHash', $var); | ||
| 36817 | |||
| 36818 | if ($self->ivExists('constCharVarHash', $oppVar)) { | ||
| 36819 | $iv = $self->ivShow('constCharVarHash', $oppVar); | ||
| 36820 | } elsif ($self->ivExists('constFixedVarHash', $oppVar)) { | ||
| 36821 | $iv = $self->ivShow('constFixedVarHash', $oppVar); | ||
| 36822 | } | ||
| 36823 | |||
| 36824 | # If the right counter is running, $var will exist in $self->counterVarHash; otherwise | ||
| 36825 | # it won't | ||
| 36826 | if ($iv && $self->ivExists('counterVarHash', $var)) { | ||
| 36827 | |||
| 36828 | $baseVal = $charObj->$iv; | ||
| 36829 | |||
| 36830 | if (! defined $val || ! defined $baseVal) { | ||
| 36831 | $self->ivAdd('counterVarHash', $var, undef); | ||
| 36832 | } else { | ||
| 36833 | $self->ivAdd('counterVarHash', $var, ($val - $baseVal)); | ||
| 36834 | } | ||
| 36835 | } | ||
| 36836 | } | ||
| 36837 | |||
| 36838 | # For changes to health/magic/energy/guild/social points, Check whether it's necessary to | ||
| 36839 | # read a TTS alert | ||
| 36840 | if ($self->ivExists('constPointHash', $var)) { | ||
| 36841 | |||
| 36842 | ($attrib) = split(/\_/, $var); | ||
| 36843 | $self->checkPointsChange($attrib); # e.g. 'health' | ||
| 36844 | } | ||
| 36845 | |||
| 36846 | # The task window must be updated on the next task loop | ||
| 36847 | $self->ivPoke('updateFlag', TRUE); | ||
| 36848 | |||
| 36849 | return 1; | ||
| 36850 | } | ||
| 36851 | |||
| 36852 | sub resetGauges { | ||
| 36853 | |||
| 36854 | # Called by $self->doStage, at stage 2/4 or, $self->refreshWin or $self->set_gaugeFlag | ||
| 36855 | # Sets up gauge(s) for this session's 'main' window, displaying data gathered by this task | ||
| 36856 | # | ||
| 36857 | # Expected arguments | ||
| 36858 | # (none besides $self) | ||
| 36859 | # | ||
| 36860 | # Return values | ||
| 36861 | # 'undef' on improper arguments, if the current character profile isn't set or if this | ||
| 36862 | # task isn't allowed to create gauges | ||
| 36863 | # 1 otherwise | ||
| 36864 | |||
| 36865 | my ($self, $check) = @_; | ||
| 36866 | |||
| 36867 | # Local variables | ||
| 36868 | my ( | ||
| 36869 | $charObj, $stripObj, $level, | ||
| 36870 | @formatList, | ||
| 36871 | ); | ||
| 36872 | |||
| 36873 | # Check for improper arguments | ||
| 36874 | if (defined $check) { | ||
| 36875 | |||
| 36876 | return $axmud::CLIENT->writeImproper($self->_objClass . '->resetGauges', @_); | ||
| 36877 | } | ||
| 36878 | |||
| 36879 | # Do nothing if this task shouldn't create gauges | ||
| 36880 | if (! $self->gaugeFlag) { | ||
| 36881 | |||
| 36882 | return undef; | ||
| 36883 | } | ||
| 36884 | |||
| 36885 | # Import the current character profile (for convenience) | ||
| 36886 | $charObj = $self->session->currentChar; | ||
| 36887 | if (! $charObj) { | ||
| 36888 | |||
| 36889 | return undef; | ||
| 36890 | } | ||
| 36891 | |||
| 36892 | # Find the GA::Strip::GaugeBox object for the session's 'main' window (which is the window | ||
| 36893 | # we'll use), if we don't already have it | ||
| 36894 | if (! $self->gaugeStripObj) { | ||
| 36895 | |||
| 36896 | $stripObj = $self->session->mainWin->ivShow( | ||
| 36897 | 'firstStripHash', | ||
| 36898 | 'Games::Axmud::Strip::GaugeBox', | ||
| 36899 | ); | ||
| 36900 | |||
| 36901 | if (! $stripObj) { | ||
| 36902 | |||
| 36903 | return undef; | ||
| 36904 | |||
| 36905 | } else { | ||
| 36906 | |||
| 36907 | $self->ivPoke('gaugeStripObj', $stripObj); | ||
| 36908 | } | ||
| 36909 | |||
| 36910 | } else { | ||
| 36911 | |||
| 36912 | $stripObj = $self->gaugeStripObj; | ||
| 36913 | } | ||
| 36914 | |||
| 36915 | # Get a list containing the format of the gauges to display | ||
| 36916 | @formatList = $self->session->currentWorld->gaugeFormatList; | ||
| 36917 | |||
| 36918 | # If any gauges have already been drawn, destroy them | ||
| 36919 | if ($self->gaugeObjList) { | ||
| 36920 | |||
| 36921 | if (! @formatList) { | ||
| 36922 | |||
| 36923 | # Don't keep an emtpy gauge level | ||
| 36924 | $stripObj->removeGauges($self->session, FALSE, $self->gaugeObjList); | ||
| 36925 | |||
| 36926 | } else { | ||
| 36927 | |||
| 36928 | # Do keep an empty gauge level | ||
| 36929 | $stripObj->removeGauges($self->session, TRUE, $self->gaugeObjList); | ||
| 36930 | } | ||
| 36931 | } | ||
| 36932 | |||
| 36933 | $self->ivEmpty('gaugeObjList'); | ||
| 36934 | |||
| 36935 | # Import information about gauges controlled by this task (for convenience) | ||
| 36936 | if (@formatList) { | ||
| 36937 | |||
| 36938 | # If no gauge level has been created for this task, create one (so that gauges | ||
| 36939 | # controlled by other code appear on different levels) | ||
| 36940 | # NB $self->gaugeLevel will be defined if this task has just been reset | ||
| 36941 | if (! defined $self->gaugeLevel) { | ||
| 36942 | |||
| 36943 | $self->ivPoke('gaugeLevel', $stripObj->addGaugeLevel($self->session)); | ||
| 36944 | } | ||
| 36945 | |||
| 36946 | do { | ||
| 36947 | |||
| 36948 | my ( | ||
| 36949 | $var, $maxVar, $addFlag, $label, $fullCol, $emptyCol, $labelCol, $varIV, | ||
| 36950 | $maxVarIV, $customKey, $maxCustomKey, $value, $maxValue, $gaugeObj, | ||
| 36951 | ); | ||
| 36952 | |||
| 36953 | $var = shift @formatList; | ||
| 36954 | $maxVar = shift @formatList; | ||
| 36955 | $addFlag = shift @formatList; | ||
| 36956 | $label = shift @formatList; | ||
| 36957 | $fullCol = shift @formatList; | ||
| 36958 | $emptyCol = shift @formatList; | ||
| 36959 | $labelCol = shift @formatList; | ||
| 36960 | |||
| 36961 | # Convert $var/$maxVar (e.g. 'health_points', 'health_points_max') into current | ||
| 36962 | # character profile IVs (e.g. ->healthPoints, ->healthPointsMax) or, for custom | ||
| 36963 | # variables, the corresponding values stored in $self->customVarHash | ||
| 36964 | if ($self->ivExists('constCharVarHash', $var)) { | ||
| 36965 | |||
| 36966 | $varIV = $self->ivShow('constCharVarHash', $var); | ||
| 36967 | $value = $charObj->$varIV; | ||
| 36968 | |||
| 36969 | } elsif ($self->ivExists('constFixedVarHash', $var)) { | ||
| 36970 | |||
| 36971 | $varIV = $self->ivShow('constFixedVarHash', $var); | ||
| 36972 | $value = $charObj->$varIV; | ||
| 36973 | |||
| 36974 | } elsif ($self->ivExists('customVarHash', $var)) { | ||
| 36975 | |||
| 36976 | $customKey = $var; | ||
| 36977 | $value = $self->ivShow('customVarHash', $var); | ||
| 36978 | } | ||
| 36979 | |||
| 36980 | if ($self->ivExists('constCharVarHash', $maxVar)) { | ||
| 36981 | |||
| 36982 | $maxVarIV = $self->ivShow('constCharVarHash', $maxVar); | ||
| 36983 | $maxValue = $charObj->$maxVarIV; | ||
| 36984 | |||
| 36985 | } elsif ($self->ivExists('constFixedVarHash', $maxVar)) { | ||
| 36986 | |||
| 36987 | $maxVarIV = $self->ivShow('constFixedVarHash', $maxVar); | ||
| 36988 | $maxValue = $charObj->$maxVarIV; | ||
| 36989 | |||
| 36990 | } elsif ($self->ivExists('customVarHash', $maxVar)) { | ||
| 36991 | |||
| 36992 | $maxCustomKey = $maxVar; | ||
| 36993 | $maxValue = $self->ivShow('customVarHash', $maxVar); | ||
| 36994 | } | ||
| 36995 | |||
| 36996 | if (defined $value && defined $maxValue && $addFlag) { | ||
| 36997 | |||
| 36998 | $maxValue += $value; | ||
| 36999 | } | ||
| 37000 | |||
| 37001 | # Sanity check: $var and $maxVar must point at real character profile IVs, or real | ||
| 37002 | # keys in $self->customVarHash, but the other values can be 'undef' | ||
| 37003 | if ( | ||
| 37004 | (defined $varIV && defined $maxVarIV) | ||
| 37005 | || (defined $customKey && defined $maxCustomKey) | ||
| 37006 | ) { | ||
| 37007 | # Create a new gauge | ||
| 37008 | $gaugeObj = $stripObj->addGauge( | ||
| 37009 | $self->session, | ||
| 37010 | $self->gaugeLevel, | ||
| 37011 | $value, | ||
| 37012 | $maxValue, | ||
| 37013 | $addFlag, | ||
| 37014 | $label, | ||
| 37015 | $fullCol, | ||
| 37016 | $emptyCol, | ||
| 37017 | $labelCol, | ||
| 37018 | $self->gaugeValueFlag, | ||
| 37019 | ); | ||
| 37020 | |||
| 37021 | if ($gaugeObj) { | ||
| 37022 | |||
| 37023 | $self->ivPush('gaugeObjList', $gaugeObj); | ||
| 37024 | # (The values in the key-value pairs might be 'undef') | ||
| 37025 | $gaugeObj->ivAdd('privateHash', 'var_iv', $varIV); | ||
| 37026 | $gaugeObj->ivAdd('privateHash', 'max_var_iv', $maxVarIV); | ||
| 37027 | $gaugeObj->ivAdd('privateHash', 'custom_key', $customKey); | ||
| 37028 | $gaugeObj->ivAdd('privateHash', 'max_custom_key', $maxCustomKey); | ||
| 37029 | } | ||
| 37030 | } | ||
| 37031 | |||
| 37032 | } until (! @formatList); | ||
| 37033 | } | ||
| 37034 | |||
| 37035 | return 1; | ||
| 37036 | } | ||
| 37037 | |||
| 37038 | sub setGauges { | ||
| 37039 | |||
| 37040 | # Called by $self->refreshWin | ||
| 37041 | # If this task is controlling any gauges in the 'main' window, tell the associated | ||
| 37042 | # GA::Obj::Gauge object of the values currently stored by this task, then tell the 'main' | ||
| 37043 | # window to redraw the gauges | ||
| 37044 | # | ||
| 37045 | # Expected arguments | ||
| 37046 | # (none besides $self) | ||
| 37047 | # | ||
| 37048 | # Return values | ||
| 37049 | # 'undef' on improper arguments | ||
| 37050 | # 1 otherwise | ||
| 37051 | |||
| 37052 | my ($self, $check) = @_; | ||
| 37053 | |||
| 37054 | # Local variables | ||
| 37055 | my $charObj; | ||
| 37056 | |||
| 37057 | # Check for improper arguments | ||
| 37058 | if (defined $check) { | ||
| 37059 | |||
| 37060 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setGauges', @_); | ||
| 37061 | } | ||
| 37062 | |||
| 37063 | # Import the current character profile (for convenience) | ||
| 37064 | $charObj = $self->session->currentChar; | ||
| 37065 | |||
| 37066 | # Do nothing if this task shouldn't create gauges or if there's no current character profile | ||
| 37067 | if (! $charObj || ! $self->gaugeFlag || ! $self->gaugeStripObj) { | ||
| 37068 | |||
| 37069 | return undef; | ||
| 37070 | } | ||
| 37071 | |||
| 37072 | foreach my $gaugeObj ($self->gaugeObjList) { | ||
| 37073 | |||
| 37074 | my ($varIV, $maxVarIV, $customKey, $maxCustomKey, $value, $maxValue); | ||
| 37075 | |||
| 37076 | $varIV = $gaugeObj->ivShow('privateHash', 'var_iv'); | ||
| 37077 | $maxVarIV = $gaugeObj->ivShow('privateHash', 'max_var_iv'); | ||
| 37078 | $customKey = $gaugeObj->ivShow('privateHash', 'custom_key'); | ||
| 37079 | $maxCustomKey = $gaugeObj->ivShow('privateHash', 'max_custom_key'); | ||
| 37080 | |||
| 37081 | # (Custom variables take precedence over 'standard' variables with the same name) | ||
| 37082 | if (defined $customKey && defined $maxCustomKey) { | ||
| 37083 | |||
| 37084 | $value = $self->ivShow('customVarHash', $customKey); | ||
| 37085 | $maxValue = $self->ivShow('customVarHash', $maxCustomKey); | ||
| 37086 | |||
| 37087 | } elsif (defined $varIV && defined $maxVarIV) { | ||
| 37088 | |||
| 37089 | $value = $charObj->$varIV; | ||
| 37090 | $maxValue = $charObj->$maxVarIV; | ||
| 37091 | } | ||
| 37092 | |||
| 37093 | if (defined $value && defined $maxValue && $gaugeObj->addFlag) { | ||
| 37094 | |||
| 37095 | $maxValue += $value; | ||
| 37096 | } | ||
| 37097 | |||
| 37098 | $gaugeObj->ivPoke('value', $value); | ||
| 37099 | $gaugeObj->ivPoke('maxValue', $maxValue); | ||
| 37100 | } | ||
| 37101 | |||
| 37102 | $self->gaugeStripObj->updateGauges(); | ||
| 37103 | |||
| 37104 | return 1; | ||
| 37105 | } | ||
| 37106 | |||
| 37107 | sub resetTriggers { | ||
| 37108 | |||
| 37109 | # Called by $self->main, stage 2, to create (dependent) triggers that capture values from | ||
| 37110 | # the world | ||
| 37111 | # Also called by $self->activate and $self->disactivate to recreate those triggers, with the | ||
| 37112 | # gag settings set to match the task's 'active' or 'disactivated' status | ||
| 37113 | # | ||
| 37114 | # Expected arguments | ||
| 37115 | # (none besides $self) | ||
| 37116 | # | ||
| 37117 | # Return values | ||
| 37118 | # 'undef' on improper arguments | ||
| 37119 | # 1 otherwise | ||
| 37120 | |||
| 37121 | my ($self, $check) = @_; | ||
| 37122 | |||
| 37123 | # Local variables | ||
| 37124 | my ( | ||
| 37125 | $worldObj, | ||
| 37126 | @list, | ||
| 37127 | ); | ||
| 37128 | |||
| 37129 | # Check for improper arguments | ||
| 37130 | if (defined $check) { | ||
| 37131 | |||
| 37132 | return $axmud::CLIENT->writeImproper($self->_objClass . '->resetTriggers', @_); | ||
| 37133 | } | ||
| 37134 | |||
| 37135 | # Import the current world | ||
| 37136 | $worldObj = $self->session->currentWorld; | ||
| 37137 | |||
| 37138 | # If triggers have already been created for this task, remove them before replacing them | ||
| 37139 | # with new triggers | ||
| 37140 | $self->session->tidyInterfaces($self); | ||
| 37141 | |||
| 37142 | # Bar patterns | ||
| 37143 | # e.g. HP (----------) SP (##########) | ||
| 37144 | @list = $worldObj->barPatternList; | ||
| 37145 | OUTER: while (@list) { | ||
| 37146 | |||
| 37147 | my ($pattern, $grpNum, $varType, $gag, $barString, $maxBars, $interfaceObj, $flag); | ||
| 37148 | |||
| 37149 | # The pattern to match | ||
| 37150 | $pattern = shift @list; | ||
| 37151 | # Which group substring contains the data we need | ||
| 37152 | $grpNum = shift @list; | ||
| 37153 | # 'health', 'magic', 'energy', 'guild', 'social', 'xp', 'qp', 'op' | ||
| 37154 | $varType = shift @list; | ||
| 37155 | # 'hide' to use a gag trigger, 'show' to use a non-gag trigger, 'choose' to let | ||
| 37156 | # $self->activeFlag decide | ||
| 37157 | $gag = shift @list; | ||
| 37158 | # The string which represents 1 unit, e.g. '=' or '*' | ||
| 37159 | $barString = shift @list; | ||
| 37160 | # How many units equal the maximum | ||
| 37161 | $maxBars = shift @list; | ||
| 37162 | |||
| 37163 | # Check that @list doesn't contain missing or extra arguments | ||
| 37164 | if (! defined $maxBars || ($gag ne 'show' && $gag ne 'hide' && $gag ne 'choose')) { | ||
| 37165 | |||
| 37166 | $self->writeWarning( | ||
| 37167 | 'Missing or invalid arguments in current world profile\'s ->barPatternList IV', | ||
| 37168 | $self->_objClass . '->resetTriggers', | ||
| 37169 | ); | ||
| 37170 | |||
| 37171 | last OUTER; | ||
| 37172 | } | ||
| 37173 | |||
| 37174 | if ($gag eq 'show') { | ||
| 37175 | $flag = FALSE; | ||
| 37176 | } elsif ($gag eq 'hide') { | ||
| 37177 | $flag = TRUE; | ||
| 37178 | } else { | ||
| 37179 | $flag = $self->activeFlag; | ||
| 37180 | } | ||
| 37181 | |||
| 37182 | # Create the dependent trigger interface | ||
| 37183 | $interfaceObj = $self->session->createDependentInterface( | ||
| 37184 | 'trigger', | ||
| 37185 | $pattern, | ||
| 37186 | $self, | ||
| 37187 | 'barPatternSeen', | ||
| 37188 | 'gag', | ||
| 37189 | $flag, | ||
| 37190 | ); | ||
| 37191 | |||
| 37192 | if (! $interfaceObj) { | ||
| 37193 | |||
| 37194 | $self->writeWarning( | ||
| 37195 | 'Couldn\'t create trigger for current world profile\'s ->barPatternList IV', | ||
| 37196 | $self->_objClass . '->resetTriggers', | ||
| 37197 | ); | ||
| 37198 | |||
| 37199 | last OUTER; | ||
| 37200 | |||
| 37201 | } else { | ||
| 37202 | |||
| 37203 | # Give the trigger some properties that will help $self->barPatternSeen to decide | ||
| 37204 | # what to do when the trigger fires (specifically, which group substring contains | ||
| 37205 | # the data, and which IV to update with it) | ||
| 37206 | $interfaceObj->ivAdd('propertyHash', 'grp_num', $grpNum); | ||
| 37207 | $interfaceObj->ivAdd('propertyHash', 'var_type', $varType); | ||
| 37208 | $interfaceObj->ivAdd('propertyHash', 'bar_string', $barString); | ||
| 37209 | $interfaceObj->ivAdd('propertyHash', 'max_bars', $maxBars); | ||
| 37210 | } | ||
| 37211 | } | ||
| 37212 | |||
| 37213 | # Group substring patterns | ||
| 37214 | # e.g. '^(.*)\((.*)\) health points and (.*)\((.*)\) social points\.$' | ||
| 37215 | # (...when all we want is nth group substring) | ||
| 37216 | @list = $worldObj->groupPatternList; | ||
| 37217 | OUTER: while (@list) { | ||
| 37218 | |||
| 37219 | my ($pattern, $grpNum, $varType, $gag, $interfaceObj, $flag); | ||
| 37220 | |||
| 37221 | # The pattern to match | ||
| 37222 | $pattern = shift @list; | ||
| 37223 | # Which group substring contains the data we need | ||
| 37224 | $grpNum = shift @list; | ||
| 37225 | # 'health_points', 'health_points_max', 'magic_points', 'magic_points_max', | ||
| 37226 | # 'energy_points', 'energy_points_max', 'guild_points', 'guild_points_max', | ||
| 37227 | # 'social_points', 'social_points_max', 'xp_current', 'xp_total', 'level', | ||
| 37228 | # 'life_count', 'death_count', 'life_max', 'local_wimpy', 'remote_wimpy', | ||
| 37229 | # 'remote_wimpy_max', 'bank_balance', 'purse_contents' | ||
| 37230 | $varType = shift @list; | ||
| 37231 | # 'hide' to use a gag trigger, 'show' to use a non-gag trigger, 'choose' to let | ||
| 37232 | # $self->activeFlag decide | ||
| 37233 | # Create trigger, first checking that the pattern list doesn't contain missing or extra | ||
| 37234 | # arguments | ||
| 37235 | $gag = shift @list; | ||
| 37236 | |||
| 37237 | # Check that @list doesn't contain missing or extra arguments | ||
| 37238 | if (! defined $gag || ($gag ne 'show' && $gag ne 'hide' && $gag ne 'choose')) { | ||
| 37239 | |||
| 37240 | $self->writeWarning( | ||
| 37241 | 'Missing or invalid arguments in world profile\'s ->groupPatternList IV', | ||
| 37242 | $self->_objClass . '->resetTriggers', | ||
| 37243 | ); | ||
| 37244 | |||
| 37245 | last OUTER; | ||
| 37246 | } | ||
| 37247 | |||
| 37248 | if ($gag eq 'show') { | ||
| 37249 | $flag = FALSE; | ||
| 37250 | } elsif ($gag eq 'hide') { | ||
| 37251 | $flag = TRUE; | ||
| 37252 | } else { | ||
| 37253 | $flag = $self->activeFlag; | ||
| 37254 | } | ||
| 37255 | |||
| 37256 | # Create the dependent trigger interface | ||
| 37257 | $interfaceObj = $self->session->createDependentInterface( | ||
| 37258 | 'trigger', | ||
| 37259 | $pattern, | ||
| 37260 | $self, | ||
| 37261 | 'groupPatternSeen', | ||
| 37262 | 'gag', | ||
| 37263 | $flag, | ||
| 37264 | ); | ||
| 37265 | |||
| 37266 | if (! $interfaceObj) { | ||
| 37267 | |||
| 37268 | $self->writeWarning( | ||
| 37269 | 'Couldn\'t create trigger for current world profile\'s ->groupPatternList IV', | ||
| 37270 | $self->_objClass . '->resetTriggers', | ||
| 37271 | ); | ||
| 37272 | |||
| 37273 | last OUTER; | ||
| 37274 | |||
| 37275 | } else { | ||
| 37276 | |||
| 37277 | # Give the trigger some properties that will help $self->barPatternSeen to decide | ||
| 37278 | # what to do when the trigger fires (specifically, which group substring contains | ||
| 37279 | # the data, and which IV to update with it) | ||
| 37280 | $interfaceObj->ivAdd('propertyHash', 'grp_num', $grpNum); | ||
| 37281 | $interfaceObj->ivAdd('propertyHash', 'var_type', $varType); | ||
| 37282 | } | ||
| 37283 | } | ||
| 37284 | |||
| 37285 | # Affect patterns | ||
| 37286 | # e.g. '(Curse) (Invisibility)' | ||
| 37287 | @list = $worldObj->affectPatternList; | ||
| 37288 | OUTER: while (@list) { | ||
| 37289 | |||
| 37290 | my ($pattern, $grpNum, $gag, $interfaceObj, $flag); | ||
| 37291 | |||
| 37292 | # The pattern to match | ||
| 37293 | $pattern = shift @list; | ||
| 37294 | # Which group substring contains the data we need | ||
| 37295 | $grpNum = shift @list; | ||
| 37296 | # 'hide' to use a gag trigger, 'show' to use a non-gag trigger, 'choose' to let | ||
| 37297 | # $self->activeFlag decide | ||
| 37298 | $gag = shift @list; | ||
| 37299 | |||
| 37300 | # Check that @list doesn't contain missing or extra arguments | ||
| 37301 | if (! defined $gag || ($gag ne 'show' && $gag ne 'hide' && $gag ne 'choose')) { | ||
| 37302 | |||
| 37303 | $self->writeWarning( | ||
| 37304 | 'Missing or invalid arguments in current world profile\'s' | ||
| 37305 | . ' ->affectPatternList IV', | ||
| 37306 | $self->_objClass . '->resetTriggers', | ||
| 37307 | ); | ||
| 37308 | |||
| 37309 | last OUTER; | ||
| 37310 | } | ||
| 37311 | |||
| 37312 | if ($gag eq 'show') { | ||
| 37313 | $flag = FALSE; | ||
| 37314 | } elsif ($gag eq 'hide') { | ||
| 37315 | $flag = TRUE; | ||
| 37316 | } else { | ||
| 37317 | $flag = $self->activeFlag; | ||
| 37318 | } | ||
| 37319 | |||
| 37320 | # Create the dependent trigger interface | ||
| 37321 | $interfaceObj = $self->session->createDependentInterface( | ||
| 37322 | 'trigger', | ||
| 37323 | $pattern, | ||
| 37324 | $self, | ||
| 37325 | 'affectPatternSeen', | ||
| 37326 | 'gag', | ||
| 37327 | $flag, | ||
| 37328 | ); | ||
| 37329 | |||
| 37330 | if (! $interfaceObj) { | ||
| 37331 | |||
| 37332 | $self->writeWarning( | ||
| 37333 | 'Couldn\'t create trigger for current world profile\'s ->affectPatternList' | ||
| 37334 | . ' IV', | ||
| 37335 | $self->_objClass . '->resetTriggers', | ||
| 37336 | ); | ||
| 37337 | |||
| 37338 | last OUTER; | ||
| 37339 | |||
| 37340 | } else { | ||
| 37341 | |||
| 37342 | # Give the trigger some properties that will help $self->affectPatternSeen to decide | ||
| 37343 | # what to do when the trigger fires (specifically, which group substring contains | ||
| 37344 | # the data, and which IV to update with it) | ||
| 37345 | $interfaceObj->ivAdd('propertyHash', 'grp_num', $grpNum); | ||
| 37346 | } | ||
| 37347 | } | ||
| 37348 | |||
| 37349 | # Stat patterns | ||
| 37350 | # e.g. 'Int (.*) Dex (.*) Con (.*)' | ||
| 37351 | @list = $worldObj->statPatternList; | ||
| 37352 | OUTER: while (@list) { | ||
| 37353 | |||
| 37354 | my ($pattern, $grpNum, $statType, $gag, $interfaceObj, $flag); | ||
| 37355 | |||
| 37356 | # The pattern to match | ||
| 37357 | $pattern = shift @list; | ||
| 37358 | # Which group substring contains the data we need | ||
| 37359 | $grpNum = shift @list; | ||
| 37360 | # A key in the world profile's stat hash (e.g. 'int', 'con', 'dex') | ||
| 37361 | $statType = shift @list; | ||
| 37362 | # 'hide' to use a gag trigger, 'show' to use a non-gag trigger, 'choose' to let | ||
| 37363 | # $self->activeFlag decide | ||
| 37364 | $gag = shift @list; | ||
| 37365 | |||
| 37366 | # Check that @list doesn't contain missing or extra arguments | ||
| 37367 | if (! defined $gag || ($gag ne 'show' && $gag ne 'hide' && $gag ne 'choose')) { | ||
| 37368 | |||
| 37369 | $self->writeWarning( | ||
| 37370 | 'Missing or invalid arguments in current world profile\'s ->statPatternList' | ||
| 37371 | . ' IV', | ||
| 37372 | $self->_objClass . '->resetTriggers', | ||
| 37373 | ); | ||
| 37374 | |||
| 37375 | last OUTER; | ||
| 37376 | } | ||
| 37377 | |||
| 37378 | if ($gag eq 'show') { | ||
| 37379 | $flag = FALSE; | ||
| 37380 | } elsif ($gag eq 'hide') { | ||
| 37381 | $flag = TRUE; | ||
| 37382 | } else { | ||
| 37383 | $flag = $self->activeFlag; | ||
| 37384 | } | ||
| 37385 | |||
| 37386 | # Create the dependent trigger interface | ||
| 37387 | $interfaceObj = $self->session->createDependentInterface( | ||
| 37388 | 'trigger', | ||
| 37389 | $pattern, | ||
| 37390 | $self, | ||
| 37391 | 'statPatternSeen', | ||
| 37392 | 'gag', | ||
| 37393 | $flag, | ||
| 37394 | ); | ||
| 37395 | |||
| 37396 | if (! $interfaceObj) { | ||
| 37397 | |||
| 37398 | $self->writeWarning( | ||
| 37399 | 'Couldn\'t create trigger for current world profile\'s ->statPatternList IV', | ||
| 37400 | $self->_objClass . '->resetTriggers', | ||
| 37401 | ); | ||
| 37402 | |||
| 37403 | last OUTER; | ||
| 37404 | |||
| 37405 | } else { | ||
| 37406 | |||
| 37407 | # Give the trigger some properties that will help $self->statPatternSeen to decide | ||
| 37408 | # what to do when the trigger fires (specifically, which group substring contains | ||
| 37409 | # the data, and which IV to update with it) | ||
| 37410 | $interfaceObj->ivAdd('propertyHash', 'grp_num', $grpNum); | ||
| 37411 | $interfaceObj->ivAdd('propertyHash', 'stat_type', $statType); | ||
| 37412 | } | ||
| 37413 | } | ||
| 37414 | |||
| 37415 | # Age patterns | ||
| 37416 | OUTER: foreach my $pattern ($worldObj->agePatternList) { | ||
| 37417 | |||
| 37418 | # Create the dependent trigger interface | ||
| 37419 | my $interfaceObj = $self->session->createDependentInterface( | ||
| 37420 | 'trigger', | ||
| 37421 | $pattern, | ||
| 37422 | $self, | ||
| 37423 | 'ageSeen', | ||
| 37424 | 'gag', | ||
| 37425 | $self->activeFlag, | ||
| 37426 | ); | ||
| 37427 | |||
| 37428 | if (! $interfaceObj) { | ||
| 37429 | |||
| 37430 | $self->writeWarning( | ||
| 37431 | 'Couldn\'t create trigger for current world profile\'s ->agePatternList IV', | ||
| 37432 | $self->_objClass . '->resetTriggers', | ||
| 37433 | ); | ||
| 37434 | |||
| 37435 | last OUTER; | ||
| 37436 | } | ||
| 37437 | } | ||
| 37438 | |||
| 37439 | # Time patterns | ||
| 37440 | OUTER: foreach my $pattern ($worldObj->timePatternList) { | ||
| 37441 | |||
| 37442 | # Create the dependent trigger interface | ||
| 37443 | my $interfaceObj = $self->session->createDependentInterface( | ||
| 37444 | 'trigger', | ||
| 37445 | $pattern, | ||
| 37446 | $self, | ||
| 37447 | 'timeSeen', | ||
| 37448 | 'gag', | ||
| 37449 | $self->activeFlag, | ||
| 37450 | ); | ||
| 37451 | |||
| 37452 | if (! $interfaceObj) { | ||
| 37453 | |||
| 37454 | $self->writeWarning( | ||
| 37455 | 'Couldn\'t create trigger for current world profile\'s ->timePatternList IV', | ||
| 37456 | $self->_objClass . '->resetTriggers', | ||
| 37457 | ); | ||
| 37458 | |||
| 37459 | last OUTER; | ||
| 37460 | } | ||
| 37461 | } | ||
| 37462 | |||
| 37463 | # Patterns produced in the course of gathering status data that should be ignored (i.e. a | ||
| 37464 | # gagged trigger prevents them from being displayed in the 'main' window) | ||
| 37465 | if ($self->activeFlag) { | ||
| 37466 | |||
| 37467 | OUTER: foreach my $pattern ($worldObj->statusIgnorePatternList) { | ||
| 37468 | |||
| 37469 | # Create the dependent trigger interface | ||
| 37470 | my $interfaceObj = $self->session->createDependentInterface( | ||
| 37471 | 'trigger', | ||
| 37472 | $pattern, | ||
| 37473 | $self, | ||
| 37474 | 'ignorePatternSeen', | ||
| 37475 | 'gag', | ||
| 37476 | $self->activeFlag, | ||
| 37477 | ); | ||
| 37478 | |||
| 37479 | if (! $interfaceObj) { | ||
| 37480 | |||
| 37481 | $self->writeWarning( | ||
| 37482 | 'Couldn\'t create trigger for current world profile\'s' | ||
| 37483 | . ' ->statusIgnorePatternList IV', | ||
| 37484 | $self->_objClass . '->resetTriggers', | ||
| 37485 | ); | ||
| 37486 | |||
| 37487 | last OUTER; | ||
| 37488 | } | ||
| 37489 | } | ||
| 37490 | } | ||
| 37491 | |||
| 37492 | # Create triggers to capture changes in life status | ||
| 37493 | |||
| 37494 | # Fall asleep patterns | ||
| 37495 | OUTER: foreach my $pattern ($worldObj->fallAsleepPatternList) { | ||
| 37496 | |||
| 37497 | # Create the dependent trigger interface | ||
| 37498 | my $interfaceObj = $self->session->createDependentInterface( | ||
| 37499 | 'trigger', | ||
| 37500 | $pattern, | ||
| 37501 | $self, | ||
| 37502 | 'asleepSeen', | ||
| 37503 | 'gag', | ||
| 37504 | FALSE, | ||
| 37505 | ); | ||
| 37506 | |||
| 37507 | if (! $interfaceObj) { | ||
| 37508 | |||
| 37509 | $self->writeWarning( | ||
| 37510 | 'Couldn\'t create trigger for current world profile\'s' | ||
| 37511 | . ' ->fallAsleepPatternList IV', | ||
| 37512 | $self->_objClass . '->resetTriggers', | ||
| 37513 | ); | ||
| 37514 | |||
| 37515 | last OUTER; | ||
| 37516 | } | ||
| 37517 | } | ||
| 37518 | |||
| 37519 | # Wake up patterns | ||
| 37520 | OUTER: foreach my $pattern ($worldObj->wakeUpPatternList) { | ||
| 37521 | |||
| 37522 | # Create the dependent trigger interface | ||
| 37523 | my $interfaceObj = $self->session->createDependentInterface( | ||
| 37524 | 'trigger', | ||
| 37525 | $pattern, | ||
| 37526 | $self, | ||
| 37527 | 'wakeUpSeen', | ||
| 37528 | 'gag', | ||
| 37529 | FALSE, | ||
| 37530 | ); | ||
| 37531 | |||
| 37532 | if (! $interfaceObj) { | ||
| 37533 | |||
| 37534 | $self->writeWarning( | ||
| 37535 | 'Couldn\'t create trigger for current world profile\'s ->wakeUpPatternList' | ||
| 37536 | . ' IV', | ||
| 37537 | $self->_objClass . '->resetTriggers', | ||
| 37538 | ); | ||
| 37539 | |||
| 37540 | last OUTER; | ||
| 37541 | } | ||
| 37542 | } | ||
| 37543 | |||
| 37544 | # Passed out patterns | ||
| 37545 | OUTER: foreach my $pattern ($worldObj->passedOutPatternList) { | ||
| 37546 | |||
| 37547 | # Create the dependent trigger interface | ||
| 37548 | my $interfaceObj = $self->session->createDependentInterface( | ||
| 37549 | 'trigger', | ||
| 37550 | $pattern, | ||
| 37551 | $self, | ||
| 37552 | 'passedOutSeen', | ||
| 37553 | 'gag', | ||
| 37554 | FALSE, | ||
| 37555 | ); | ||
| 37556 | |||
| 37557 | if (! $interfaceObj) { | ||
| 37558 | |||
| 37559 | $self->writeWarning( | ||
| 37560 | 'Couldn\'t create trigger for current world profile\'s' | ||
| 37561 | . ' ->passedOutPatternList IV', | ||
| 37562 | $self->_objClass . '->resetTriggers', | ||
| 37563 | ); | ||
| 37564 | |||
| 37565 | last OUTER; | ||
| 37566 | } | ||
| 37567 | } | ||
| 37568 | |||
| 37569 | # Come around patterns | ||
| 37570 | OUTER: foreach my $pattern ($worldObj->comeAroundPatternList) { | ||
| 37571 | |||
| 37572 | # Create the dependent trigger interface | ||
| 37573 | my $interfaceObj = $self->session->createDependentInterface( | ||
| 37574 | 'trigger', | ||
| 37575 | $pattern, | ||
| 37576 | $self, | ||
| 37577 | 'comeAroundSeen', | ||
| 37578 | 'gag', | ||
| 37579 | FALSE, | ||
| 37580 | ); | ||
| 37581 | |||
| 37582 | if (! $interfaceObj) { | ||
| 37583 | |||
| 37584 | $self->writeWarning( | ||
| 37585 | 'Couldn\'t create trigger for current world profile\'s' | ||
| 37586 | . ' ->comeAroundPatternList IV', | ||
| 37587 | $self->_objClass . '->resetTriggers', | ||
| 37588 | ); | ||
| 37589 | |||
| 37590 | last OUTER; | ||
| 37591 | } | ||
| 37592 | } | ||
| 37593 | |||
| 37594 | # Death patterns | ||
| 37595 | OUTER: foreach my $pattern ($worldObj->deathPatternList) { | ||
| 37596 | |||
| 37597 | # Create the dependent trigger interface | ||
| 37598 | my $interfaceObj = $self->session->createDependentInterface( | ||
| 37599 | 'trigger', | ||
| 37600 | $pattern, | ||
| 37601 | $self, | ||
| 37602 | 'deadSeen', | ||
| 37603 | 'gag', | ||
| 37604 | FALSE, | ||
| 37605 | ); | ||
| 37606 | |||
| 37607 | if (! $interfaceObj) { | ||
| 37608 | |||
| 37609 | $self->writeWarning( | ||
| 37610 | 'Couldn\'t create trigger for current world profile\'s ->deathPatternList' | ||
| 37611 | . ' IV', | ||
| 37612 | $self->_objClass . '->resetTriggers', | ||
| 37613 | ); | ||
| 37614 | |||
| 37615 | last OUTER; | ||
| 37616 | } | ||
| 37617 | } | ||
| 37618 | |||
| 37619 | # Resurrection patterns | ||
| 37620 | OUTER: foreach my $pattern ($worldObj->resurrectPatternList) { | ||
| 37621 | |||
| 37622 | # Create the dependent trigger interface | ||
| 37623 | my $interfaceObj = $self->session->createDependentInterface( | ||
| 37624 | 'trigger', | ||
| 37625 | $pattern, | ||
| 37626 | $self, | ||
| 37627 | 'resurrectedSeen', | ||
| 37628 | 'gag', | ||
| 37629 | FALSE, | ||
| 37630 | ); | ||
| 37631 | |||
| 37632 | if (! $interfaceObj) { | ||
| 37633 | |||
| 37634 | $self->writeWarning( | ||
| 37635 | 'Couldn\'t create trigger for current world profile\'s' | ||
| 37636 | . ' ->resurrectPatternList IV', | ||
| 37637 | $self->_objClass . '->resetTriggers', | ||
| 37638 | ); | ||
| 37639 | |||
| 37640 | last OUTER; | ||
| 37641 | } | ||
| 37642 | } | ||
| 37643 | |||
| 37644 | # Trigger reset complete | ||
| 37645 | return 1; | ||
| 37646 | } | ||
| 37647 | |||
| 37648 | sub convertAge { | ||
| 37649 | |||
| 37650 | # Called by $self->ageSeen | ||
| 37651 | # Converts a list of strings representing the character's age (e.g. 'five months, two days | ||
| 37652 | # and one hour') into a single number, representing the character's age in the standard | ||
| 37653 | # unit (e.g. 'day', 'second', 'century') specified by the world profile | ||
| 37654 | # | ||
| 37655 | # Expected arguments | ||
| 37656 | # @lines - A list of lines (most of the time, contains only one line) | ||
| 37657 | # | ||
| 37658 | # Return values | ||
| 37659 | # 'undef' on improper arguments or if the lines couldn't be converted | ||
| 37660 | # Otherwise, returns the character's age in the standard unit | ||
| 37661 | |||
| 37662 | my ($self, @lines) = @_; | ||
| 37663 | |||
| 37664 | # Local variables | ||
| 37665 | my ( | ||
| 37666 | $dictObj, $totalSeconds, $converter, $age, $charUnit, | ||
| 37667 | @andOrList, | ||
| 37668 | %timeHash, %convertHash, | ||
| 37669 | ); | ||
| 37670 | |||
| 37671 | # Check for improper arguments | ||
| 37672 | if (! @lines) { | ||
| 37673 | |||
| 37674 | return $axmud::CLIENT->writeImproper($self->_objClass . '->convertAge', @_); | ||
| 37675 | } | ||
| 37676 | |||
| 37677 | # Import the current dictinary and its and/or list | ||
| 37678 | $dictObj = $self->session->currentDict; | ||
| 37679 | @andOrList = ($dictObj->andList, $dictObj->orList); | ||
| 37680 | |||
| 37681 | # Examine each line in turn. If later ones repeat data contained in earlier ones, the later | ||
| 37682 | # ones overwrite the earlier ones | ||
| 37683 | OUTER: foreach my $line (@lines) { | ||
| 37684 | |||
| 37685 | my (@wordList); | ||
| 37686 | |||
| 37687 | # Convert any capital letters into lower-case letters | ||
| 37688 | $line = lc($line); | ||
| 37689 | # Remove non-word characters (such as commas and full stops), replacing them with | ||
| 37690 | # spaces | ||
| 37691 | $line =~ s/\W/ /g; | ||
| 37692 | |||
| 37693 | # Remove the words for 'and' and 'or' | ||
| 37694 | foreach my $word (@andOrList) { | ||
| 37695 | |||
| 37696 | $line =~ s/$word//g; | ||
| 37697 | } | ||
| 37698 | |||
| 37699 | # Split $line into distinct words | ||
| 37700 | @wordList = split(m/\s+/, $line); | ||
| 37701 | INNER: while (@wordList) { | ||
| 37702 | |||
| 37703 | my ($number, $unit, $integer, $singleUnit); | ||
| 37704 | |||
| 37705 | # We hope that the first two words remaining in @wordList are a number and a time | ||
| 37706 | # unit | ||
| 37707 | $number = shift @wordList; | ||
| 37708 | $unit = shift @wordList; | ||
| 37709 | if (! defined $unit) { | ||
| 37710 | |||
| 37711 | |||
| 37712 | # If no unit specified, use the world profile's standard unit | ||
| 37713 | if ($self->session->currentWorld->charAgeUnit) { | ||
| 37714 | |||
| 37715 | $unit = $self->session->currentWorld->charAgeUnit; | ||
| 37716 | |||
| 37717 | } else { | ||
| 37718 | |||
| 37719 | # (We found a number, but not a time unit) | ||
| 37720 | last INNER; | ||
| 37721 | } | ||
| 37722 | } | ||
| 37723 | |||
| 37724 | if ($number =~ m/\D/) { | ||
| 37725 | |||
| 37726 | # If number contains non-digit characters, see if it's a known number word | ||
| 37727 | if ($dictObj->ivExists('numberHash', $number)) { | ||
| 37728 | |||
| 37729 | $integer = $dictObj->ivShow('numberHash', $number); | ||
| 37730 | |||
| 37731 | } else { | ||
| 37732 | |||
| 37733 | # This isn't a recognised number word. Move on to the next line | ||
| 37734 | next OUTER; | ||
| 37735 | } | ||
| 37736 | |||
| 37737 | } else { | ||
| 37738 | |||
| 37739 | $integer = $number; | ||
| 37740 | } | ||
| 37741 | |||
| 37742 | # See if the time unit is one recognised by the dictionary, and if so, make sure | ||
| 37743 | # it's in the singular form | ||
| 37744 | if ($dictObj->ivExists('reverseTimeHash', $unit)) { | ||
| 37745 | $singleUnit = $dictObj->ivShow('reverseTimeHash', $unit); | ||
| 37746 | } elsif ($dictObj->ivExists('reverseTimePluralHash', $unit)) { | ||
| 37747 | $singleUnit = $dictObj->ivShow('reverseTimePluralHash', $unit); | ||
| 37748 | } | ||
| 37749 | |||
| 37750 | # If both $integer and $singleUnit have been set, we can be confident that the | ||
| 37751 | # original $number and $unit were valid values | ||
| 37752 | if (defined $integer && defined $singleUnit) { | ||
| 37753 | |||
| 37754 | # e.g. $timeHash{'second'} = 15; | ||
| 37755 | # e.g. $timeHash{'century'} = 2; | ||
| 37756 | $timeHash{$singleUnit} = $integer; | ||
| 37757 | } | ||
| 37758 | } | ||
| 37759 | } | ||
| 37760 | |||
| 37761 | # Convert the characters's total age into seconds | ||
| 37762 | %convertHash = ( | ||
| 37763 | 'second' => 1, | ||
| 37764 | 'minute' => 60, | ||
| 37765 | 'hour' => 3600, # 1 hour = 3600 seconds | ||
| 37766 | 'day' => 86400, | ||
| 37767 | 'week' => 604800, | ||
| 37768 | 'month' => 2419200, | ||
| 37769 | 'year' => 31536000, | ||
| 37770 | 'decade' => 315360000, | ||
| 37771 | 'century' => 3153600000, | ||
| 37772 | 'millennium' => 31536000000, | ||
| 37773 | ); | ||
| 37774 | |||
| 37775 | $totalSeconds = 0; | ||
| 37776 | foreach my $unit (keys %timeHash) { | ||
| 37777 | |||
| 37778 | $totalSeconds += ($timeHash{$unit} * $convertHash{$unit}); | ||
| 37779 | } | ||
| 37780 | |||
| 37781 | if (! %timeHash) { | ||
| 37782 | |||
| 37783 | # No age found | ||
| 37784 | return undef; | ||
| 37785 | } | ||
| 37786 | |||
| 37787 | # Convert $totalSeconds into the time unit specified by the world profile (default value is | ||
| 37788 | # usually 'day') | ||
| 37789 | $charUnit = $self->session->currentWorld->charAgeUnit; | ||
| 37790 | if (! exists $convertHash{$charUnit}) { | ||
| 37791 | |||
| 37792 | # Character's age unit is not recognised (or not set) | ||
| 37793 | return undef; | ||
| 37794 | |||
| 37795 | } else { | ||
| 37796 | |||
| 37797 | # Convert $totalSeconds to a value in the unit $charUnit (e.g. 'day') | ||
| 37798 | $age = $totalSeconds / $convertHash{$charUnit}; | ||
| 37799 | # Finally, reduce $age to a maximum of two decimal places | ||
| 37800 | $age = (int($age * 100)) / 100; | ||
| 37801 | |||
| 37802 | # Return the character's age in the time unit specified by the world profile | ||
| 37803 | return $age; | ||
| 37804 | } | ||
| 37805 | } | ||
| 37806 | |||
| 37807 | sub convertTime { | ||
| 37808 | |||
| 37809 | # Called by $self->timeSeen | ||
| 37810 | # Converts a string (e.g. 'half-past two in the afternoon') into a 24-hour digital time | ||
| 37811 | # | ||
| 37812 | # Expected arguments | ||
| 37813 | # $longTime - The string to convert | ||
| 37814 | # | ||
| 37815 | # Return values | ||
| 37816 | # An empty list on improper arguments or if the time can't be converted | ||
| 37817 | # Otherwise, a list containing the 24 hour time, in the form ($hours, $minutes) | ||
| 37818 | |||
| 37819 | my ($self, $longTime, $check) = @_; | ||
| 37820 | |||
| 37821 | # Local variables | ||
| 37822 | my ( | ||
| 37823 | $dictObj, $minutes, $hours, $successFlag, | ||
| 37824 | @emptyList, | ||
| 37825 | %dayHash, %hourHash, %minuteHash, | ||
| 37826 | ); | ||
| 37827 | |||
| 37828 | # Check for improper arguments | ||
| 37829 | if (! defined $longTime || defined $check) { | ||
| 37830 | |||
| 37831 | $axmud::CLIENT->writeImproper($self->_objClass . '->convertTime', @_); | ||
| 37832 | return @emptyList; | ||
| 37833 | } | ||
| 37834 | |||
| 37835 | # Import the current dictinary and some of its vocabulary lsits | ||
| 37836 | $dictObj = $self->session->currentDict; | ||
| 37837 | %dayHash = $dictObj->clockDayHash; | ||
| 37838 | %hourHash = $dictObj->clockHourHash; | ||
| 37839 | %minuteHash = $dictObj->clockMinuteHash; | ||
| 37840 | |||
| 37841 | $hours = 0; | ||
| 37842 | $minutes = 0; | ||
| 37843 | |||
| 37844 | # Remove a.m. / p.m. strings | ||
| 37845 | OUTER: foreach my $key (keys %dayHash) { | ||
| 37846 | |||
| 37847 | if ($longTime =~ m/$key/i) { | ||
| 37848 | |||
| 37849 | # %dayHash{$key} = 0 for a.m., 1 for p.m., so $hours is set to 0 or 12 | ||
| 37850 | $hours = ($dayHash{$key} * 12); | ||
| 37851 | # Remove the matched string, and don't continue looking for a.m./p.m. strings | ||
| 37852 | $longTime =~ s/$key//; | ||
| 37853 | last OUTER; | ||
| 37854 | } | ||
| 37855 | } | ||
| 37856 | |||
| 37857 | # Remove minute strings before hour strings (or 'five past' will be mistaken for 'five | ||
| 37858 | # o'clock') | ||
| 37859 | OUTER: foreach my $key (keys %minuteHash) { | ||
| 37860 | |||
| 37861 | if ($longTime =~ m/$key/i) { | ||
| 37862 | |||
| 37863 | # If $minuteHash{$key} is a negative value, it's a time like 'quarter to eleven', | ||
| 37864 | # and the value of $hours, 11, should be one less (10) | ||
| 37865 | if ($minuteHash{$key} < 0) { | ||
| 37866 | |||
| 37867 | $hours--; | ||
| 37868 | $minutes = $minuteHash{$key} * (-1); | ||
| 37869 | |||
| 37870 | } else { | ||
| 37871 | |||
| 37872 | $minutes = $minuteHash{$key}; | ||
| 37873 | } | ||
| 37874 | |||
| 37875 | # Remove the matched string, and don't continue looking for minute strings | ||
| 37876 | $longTime =~ s/$key//; | ||
| 37877 | |||
| 37878 | last OUTER; | ||
| 37879 | } | ||
| 37880 | } | ||
| 37881 | |||
| 37882 | # Remove hour strings | ||
| 37883 | $successFlag = FALSE; | ||
| 37884 | OUTER: foreach my $key (keys %hourHash) { | ||
| 37885 | |||
| 37886 | if ($longTime =~ m/$key/i) { | ||
| 37887 | |||
| 37888 | # If it's a.m., $hours = 0; if it's p.m., $hours already equals 12, so this | ||
| 37889 | # converts $hours into a 24-hour clock value | ||
| 37890 | $hours = $hours + $hourHash{$key}; | ||
| 37891 | # If $hours may have been set to -1 above; that's the equivalent of 23 in the | ||
| 37892 | # 24-hour clock | ||
| 37893 | if ($hours == -1) { | ||
| 37894 | |||
| 37895 | $hours = 23; | ||
| 37896 | } | ||
| 37897 | |||
| 37898 | # Remove the matched string, and don't continue looking for hour strings | ||
| 37899 | $longTime =~ s/$key//; | ||
| 37900 | $successFlag = TRUE; | ||
| 37901 | |||
| 37902 | last OUTER; | ||
| 37903 | } | ||
| 37904 | } | ||
| 37905 | |||
| 37906 | if (! $successFlag) { | ||
| 37907 | |||
| 37908 | # The 'hours' component not found (it doesn't matter too much if the 'minutes' component | ||
| 37909 | # wasn't found | ||
| 37910 | return @emptyList; | ||
| 37911 | |||
| 37912 | } else { | ||
| 37913 | |||
| 37914 | # Conversion complete | ||
| 37915 | return ($hours, $minutes); | ||
| 37916 | } | ||
| 37917 | } | ||
| 37918 | |||
| 37919 | sub checkHealthChange { | ||
| 37920 | |||
| 37921 | # Called by $self->setValue | ||
| 37922 | # When the character's health points (GA::Profile::Char->healthPoints) or maximum health | ||
| 37923 | # points (GA::Profile::Char->healthPointsMax) change, it might be necessary to change the | ||
| 37924 | # background colour of the window | ||
| 37925 | # If the world doesn't explicitly state when the character wakes up after falling asleep, | ||
| 37926 | # when they come around after passing out, or when they resurrect after dying, it might | ||
| 37927 | # also be necessary to change the life status to 'alive' if the character's health points | ||
| 37928 | # score is read | ||
| 37929 | # This function decides whether it's necessary, and sets $self->healthChangeFlag to TRUE if | ||
| 37930 | # so | ||
| 37931 | # | ||
| 37932 | # Expected arguments | ||
| 37933 | # $hp - The new health points value | ||
| 37934 | # $hpMax - The new maximum health points value | ||
| 37935 | # | ||
| 37936 | # Return values | ||
| 37937 | # 'undef' on improper arguments, if there's no current character set or if the task | ||
| 37938 | # window's background colour doesn't have to be changed | ||
| 37939 | # 1 if the colour should be changed | ||
| 37940 | |||
| 37941 | my ($self, $hp, $hpMax, $check) = @_; | ||
| 37942 | |||
| 37943 | # Local variables | ||
| 37944 | my ($charObj, $old, $new); | ||
| 37945 | |||
| 37946 | # Check for improper arguments | ||
| 37947 | if (! defined $hp || ! defined $hpMax || defined $check) { | ||
| 37948 | |||
| 37949 | return $axmud::CLIENT->writeImproper($self->_objClass . '->checkHealthChange', @_); | ||
| 37950 | } | ||
| 37951 | |||
| 37952 | # Do nothing if there's no current character set | ||
| 37953 | $charObj = $self->session->currentChar; | ||
| 37954 | if (! $charObj) { | ||
| 37955 | |||
| 37956 | return undef; | ||
| 37957 | } | ||
| 37958 | |||
| 37959 | # If the character's life status isn't 'alive' and the override flag is set, the character | ||
| 37960 | # is no longer asleep, passed out or dead. Change the life status to 'alive' again | ||
| 37961 | if ( | ||
| 37962 | $charObj->lifeStatus ne 'alive' | ||
| 37963 | && $self->session->currentWorld->lifeStatusOverrideFlag | ||
| 37964 | ) { | ||
| 37965 | $charObj->ivPoke('lifeStatus', 'alive'); | ||
| 37966 | |||
| 37967 | # The task window's background colour should be changed | ||
| 37968 | return $self->ivPoke('healthChangeFlag', TRUE); | ||
| 37969 | |||
| 37970 | # Otherwise, only consider changing the background colour, if the relevant IVs are non-zero | ||
| 37971 | } elsif ($self->allowColourFlag && $charObj->healthPoints && $charObj->healthPointsMax) { | ||
| 37972 | |||
| 37973 | # Get the character's healt points as a percentage of the maximum | ||
| 37974 | $old = $charObj->healthPoints / $charObj->healthPointsMax; | ||
| 37975 | $new = $hp / $hpMax; | ||
| 37976 | |||
| 37977 | if ( | ||
| 37978 | ( | ||
| 37979 | $new > 0.50 && $old <= 0.50 | ||
| 37980 | ) || ( | ||
| 37981 | $new > 0.30 && $new <= 0.50 && ($old <= 0.30 || $old > 0.50) | ||
| 37982 | ) || ( | ||
| 37983 | $new > 0.10 && $new <= 0.10 && ($old <= 0.10 || $old > 0.30) | ||
| 37984 | ) || ( | ||
| 37985 | $new <= 0.10 && $old > 0.10 | ||
| 37986 | ) | ||
| 37987 | ) { | ||
| 37988 | # The task window's background colour should be changed | ||
| 37989 | return $self->ivPoke('healthChangeFlag', TRUE); | ||
| 37990 | } | ||
| 37991 | } | ||
| 37992 | |||
| 37993 | # No change to the background colour | ||
| 37994 | return undef; | ||
| 37995 | } | ||
| 37996 | |||
| 37997 | sub checkPointsChange { | ||
| 37998 | |||
| 37999 | # Called by $self->setValue | ||
| 38000 | # When the character's health/magic/energy/guild/social points change, check whether it's | ||
| 38001 | # time to read out a TTS alert message and, if so, add the message to | ||
| 38002 | # $self->ttsPointsAlertMsgHash | ||
| 38003 | # All messages are then read out by $self->doStage (stage 4), and ->ttsPointsAlertMsgHash | ||
| 38004 | # is reset; in this way, we don't erroneously read out an alert message if the code | ||
| 38005 | # receives (for example) a new 'health_points' value before a new 'health_points_max' | ||
| 38006 | # value | ||
| 38007 | # | ||
| 38008 | # Expected arguments | ||
| 38009 | # $attrib - Which points total has changed: 'health', 'magic', 'energy', 'guild', | ||
| 38010 | # 'social' | ||
| 38011 | # | ||
| 38012 | # Return values | ||
| 38013 | # 'undef' on improper arguments, if there's no current character set or if nothing is to | ||
| 38014 | # be read out | ||
| 38015 | # 1 if an alert message is to be read out (whether the user hears anything, or not, will | ||
| 38016 | # depend on the usual TTS variables) | ||
| 38017 | |||
| 38018 | my ($self, $attrib, $check) = @_; | ||
| 38019 | |||
| 38020 | # Local variables | ||
| 38021 | my ($charObj, $iv, $current, $ivMax, $max, $percent); | ||
| 38022 | |||
| 38023 | # Check for improper arguments | ||
| 38024 | if ( | ||
| 38025 | ! defined $attrib | ||
| 38026 | || ( | ||
| 38027 | $attrib ne 'health' && $attrib ne 'magic' && $attrib ne 'energy' | ||
| 38028 | && $attrib ne 'guild' && $attrib ne 'social' | ||
| 38029 | ) || defined $check | ||
| 38030 | ) { | ||
| 38031 | return $axmud::CLIENT->writeImproper($self->_objClass . '->checkPointsChange', @_); | ||
| 38032 | } | ||
| 38033 | |||
| 38034 | # Do nothing if there's no current character set | ||
| 38035 | $charObj = $self->session->currentChar; | ||
| 38036 | if (! $charObj) { | ||
| 38037 | |||
| 38038 | return undef; | ||
| 38039 | } | ||
| 38040 | |||
| 38041 | # Get the current and maximum points | ||
| 38042 | $iv = $attrib . 'Points'; | ||
| 38043 | $current = $charObj->$iv; | ||
| 38044 | $ivMax = $attrib . 'PointsMax'; | ||
| 38045 | $max = $charObj->$ivMax; | ||
| 38046 | |||
| 38047 | if (! defined $current || ! defined $max || $max == 0) { | ||
| 38048 | |||
| 38049 | # Points percentage not currently known | ||
| 38050 | return undef; | ||
| 38051 | } | ||
| 38052 | |||
| 38053 | # Set the points percentage, in a range 0-100% | ||
| 38054 | $percent = ($current / $max) * 100; | ||
| 38055 | # Protect ourselves against unexpected errors | ||
| 38056 | if ($percent < 0) { | ||
| 38057 | $percent = 0; | ||
| 38058 | } elsif ($percent > 100) { | ||
| 38059 | $percent = 100; | ||
| 38060 | } else { | ||
| 38061 | $percent = int($percent); | ||
| 38062 | } | ||
| 38063 | |||
| 38064 | if ( | ||
| 38065 | # The user has specified that an alert should be read out, if the points recover above | ||
| 38066 | # a certain value | ||
| 38067 | defined $self->ivShow('ttsAlertAttribHash', $attrib . 'up') # .e.g 'healthup' | ||
| 38068 | # The points have recovered to that value | ||
| 38069 | && $percent >= $self->ivShow('ttsAlertAttribHash', $attrib . 'up') | ||
| 38070 | # No alert for these points have yet been read out, or the last alert read out was for | ||
| 38071 | # a low value | ||
| 38072 | && $self->ivShow('ttsPointsAlertHash', $attrib) != 1 | ||
| 38073 | ) { | ||
| 38074 | # Set the alert to be read... | ||
| 38075 | $self->ivAdd( | ||
| 38076 | 'ttsPointsAlertMsgHash', | ||
| 38077 | $attrib, | ||
| 38078 | ucfirst($attrib) . ' points have recovered to ' . $percent . '%', | ||
| 38079 | ); | ||
| 38080 | |||
| 38081 | # ...and the type of alert that shouldn't be read consecutively | ||
| 38082 | $self->ivAdd('ttsPointsAlertTypeHash', $attrib, 1); | ||
| 38083 | |||
| 38084 | return 1; | ||
| 38085 | |||
| 38086 | } elsif ( | ||
| 38087 | # The user has specified that an alert should be read out, if the points fall below | ||
| 38088 | # a certain value | ||
| 38089 | defined $self->ivShow('ttsAlertAttribHash', $attrib . 'down') # .e.g 'healthdown' | ||
| 38090 | # The points have fallen to that value | ||
| 38091 | && $percent <= $self->ivShow('ttsAlertAttribHash', $attrib . 'down') | ||
| 38092 | # No alert for these points have yet been read out, or the last alert read out was for | ||
| 38093 | # a high value | ||
| 38094 | && $self->ivShow('ttsPointsAlertHash', $attrib) != -1 | ||
| 38095 | ) { | ||
| 38096 | # Set the alert to be read... | ||
| 38097 | $self->ivAdd( | ||
| 38098 | 'ttsPointsAlertMsgHash', | ||
| 38099 | $attrib, | ||
| 38100 | ucfirst($attrib) . ' points have fallen to ' . $percent . '%', | ||
| 38101 | ); | ||
| 38102 | |||
| 38103 | # ...and the type of alert that shouldn't be read consecutively | ||
| 38104 | $self->ivAdd('ttsPointsAlertTypeHash', $attrib, -1); | ||
| 38105 | |||
| 38106 | return 1; | ||
| 38107 | |||
| 38108 | } else { | ||
| 38109 | |||
| 38110 | # Don't read out an alert | ||
| 38111 | return undef; | ||
| 38112 | } | ||
| 38113 | } | ||
| 38114 | |||
| 38115 | sub roundCashValue { | ||
| 38116 | |||
| 38117 | # Called by $self->set_cashValues and ->processFormatList | ||
| 38118 | # Prevent Perl rounding errors by rounding a cash value to the number of decimal places | ||
| 38119 | # specified by GA::Profile::World->currencyRounding | ||
| 38120 | # | ||
| 38121 | # Expected arguments | ||
| 38122 | # $value - An integer or floating point value, e.g. 1.124 | ||
| 38123 | # | ||
| 38124 | # Optional arguments | ||
| 38125 | # $formatFlag - TRUE when called by $self->->processFormatList, in which case we use | ||
| 38126 | # sprintf() to return a cash value to the correct number of decimal places (e.g. | ||
| 38127 | # returns 10.50, not 10.5) | ||
| 38128 | |||
| 38129 | # Return values | ||
| 38130 | # 'undef' on improper arguments | ||
| 38131 | # Otherwise returns the rounded value | ||
| 38132 | |||
| 38133 | my ($self, $value, $formatFlag, $check) = @_; | ||
| 38134 | |||
| 38135 | # Local variables | ||
| 38136 | my ($rounding, $string); | ||
| 38137 | |||
| 38138 | # Check for improper arguments | ||
| 38139 | if (! defined $value || defined $check) { | ||
| 38140 | |||
| 38141 | return $axmud::CLIENT->writeImproper($self->_objClass . '->roundCashValue', @_); | ||
| 38142 | } | ||
| 38143 | |||
| 38144 | $rounding = $self->session->currentWorld->currencyRounding; | ||
| 38145 | |||
| 38146 | # (If the world profile's ->currencyRounding is set to -1, we don't round anything) | ||
| 38147 | if ($rounding == -1) { | ||
| 38148 | |||
| 38149 | return $value; | ||
| 38150 | |||
| 38151 | } elsif ($formatFlag) { | ||
| 38152 | |||
| 38153 | $string = "%." . $rounding . "f"; # e.g. %.3f | ||
| 38154 | $value = sprintf($string, $value); | ||
| 38155 | # This sometimes produces a value like 7, sometimes like 7.000; make sure integers are | ||
| 38156 | # displayed like integers | ||
| 38157 | if ((int $value) == $value) { | ||
| 38158 | |||
| 38159 | $value = int $value; | ||
| 38160 | } | ||
| 38161 | |||
| 38162 | return $value; | ||
| 38163 | |||
| 38164 | } else { | ||
| 38165 | |||
| 38166 | return Math::Round::nearest((10 ** ($rounding * -1)), $value); | ||
| 38167 | } | ||
| 38168 | } | ||
| 38169 | |||
| 38170 | ################## | ||
| 38171 | # Response methods | ||
| 38172 | |||
| 38173 | sub barPatternSeen { | ||
| 38174 | |||
| 38175 | # Called by GA::Session->checkTriggers | ||
| 38176 | # | ||
| 38177 | # This task's ->resetTriggers function creates some triggers to capture bar pattern strings | ||
| 38178 | # e.g. HP (----------) SP (##########) | ||
| 38179 | # | ||
| 38180 | # The world profile's bar pattern list occurs in groups of 6 elements, representing | ||
| 38181 | # [0] - the pattern to match | ||
| 38182 | # [1] - which group substring contains the data we need | ||
| 38183 | # [2] - 'health', 'magic', 'energy', 'guild', 'social', 'xp_current', 'xp_next_level', | ||
| 38184 | # 'qp_current', 'qp_next_level', 'op_current', 'op_next_level' | ||
| 38185 | # [3] - the string which represents 1 unit, e.g. '*' | ||
| 38186 | # [4] - how many units equal the maximum | ||
| 38187 | # [5] - 'hide' to use a gag trigger, 'show' to use a non-gag trigger, 'no_trigger' not to | ||
| 38188 | # create a trigger (if the pattern to match already exists, higher up the list, we | ||
| 38189 | # only need a single trigger to detect it) | ||
| 38190 | # | ||
| 38191 | # The trigger interfaces have the following properties in ->propertyHash: | ||
| 38192 | # grp_num - which group substring contains the data we need (same as [1] ) | ||
| 38193 | # var_type - 'health', 'magic', 'energy', 'guild', 'social', 'xp_current', | ||
| 38194 | # 'xp_next_level', 'qp_current', 'qp_next_level', 'op_current', | ||
| 38195 | # 'op_next_level' (same as [2] ) | ||
| 38196 | # bar_string - the string which represents 1 unit, e.g. '*' (same as [3] ) | ||
| 38197 | # max_bars - how many units equal the maximum (same as [4] ) | ||
| 38198 | # | ||
| 38199 | # This function counts the bars in the appropriate group substring and updates the task's | ||
| 38200 | # IVs | ||
| 38201 | # | ||
| 38202 | # Expected arguments (standard args from GA::Session->checkTriggers) | ||
| 38203 | # $session - The calling function's GA::Session | ||
| 38204 | # $interfaceNum - The number of the active trigger interface that fired | ||
| 38205 | # $line - The line of text received from the world | ||
| 38206 | # $stripLine - $line, with all escape sequences removed | ||
| 38207 | # $modLine - $stripLine, possibly modified by previously-checked triggers | ||
| 38208 | # $grpStringListRef | ||
| 38209 | # - Reference to a list of group substrings from the pattern match | ||
| 38210 | # (equivalent of @_) | ||
| 38211 | # $matchMinusListRef | ||
| 38212 | # - Reference to a list of matched substring offsets (equivalent of @-) | ||
| 38213 | # $matchPlusListRef | ||
| 38214 | # - Reference to a list of matched substring offsets (equivalent of @+) | ||
| 38215 | # | ||
| 38216 | # Return values | ||
| 38217 | # 'undef' on improper arguments, or if $session is the wrong session or if the interface | ||
| 38218 | # object can't be found | ||
| 38219 | # 1 otherwise | ||
| 38220 | |||
| 38221 | my ( | ||
| 38222 | $self, $session, $interfaceNum, $line, $stripLine, $modLine, $grpStringListRef, | ||
| 38223 | $matchMinusListRef, $matchPlusListRef, $check, | ||
| 38224 | ) = @_; | ||
| 38225 | |||
| 38226 | # Local variables | ||
| 38227 | my ($obj, $grpNum, $varType, $barString, $maxBars, $grpString, $numBars); | ||
| 38228 | |||
| 38229 | # Check for improper arguments | ||
| 38230 | if ( | ||
| 38231 | ! defined $session || ! defined $interfaceNum || ! defined $line || ! defined $stripLine | ||
| 38232 | || ! defined $modLine || ! defined $grpStringListRef || ! defined $matchMinusListRef | ||
| 38233 | || ! defined $matchPlusListRef || defined $check | ||
| 38234 | ) { | ||
| 38235 | return $axmud::CLIENT->writeImproper($self->_objClass . '->barPatternSeen', @_); | ||
| 38236 | } | ||
| 38237 | |||
| 38238 | # Basic check - the trigger should belong to the right session | ||
| 38239 | if ($session ne $self->session) { | ||
| 38240 | |||
| 38241 | return undef; | ||
| 38242 | } | ||
| 38243 | |||
| 38244 | # Get the interface object itself | ||
| 38245 | $obj = $session->ivShow('interfaceNumHash', $interfaceNum); | ||
| 38246 | if (! $obj) { | ||
| 38247 | |||
| 38248 | return undef; | ||
| 38249 | } | ||
| 38250 | |||
| 38251 | # Respond to the fired trigger | ||
| 38252 | |||
| 38253 | # Import the trigger's properties | ||
| 38254 | $grpNum = $obj->ivShow('propertyHash', 'grp_num'); | ||
| 38255 | $varType = $obj->ivShow('propertyHash', 'var_type'); | ||
| 38256 | $barString = $obj->ivShow('propertyHash', 'bar_string'); | ||
| 38257 | $maxBars = $obj->ivShow('propertyHash', 'max_bars'); | ||
| 38258 | # Get the correct group substring | ||
| 38259 | $grpString = $$grpStringListRef[$grpNum]; | ||
| 38260 | # Count the number of bars | ||
| 38261 | $numBars = () = $grpString =~ m/$barString/g; | ||
| 38262 | |||
| 38263 | # Update the task's instance variables | ||
| 38264 | if ($varType eq 'health') { | ||
| 38265 | |||
| 38266 | $self->setValue('health_points_max', $maxBars); | ||
| 38267 | $self->setValue('health_points', $numBars); | ||
| 38268 | |||
| 38269 | } elsif ($varType eq 'magic') { | ||
| 38270 | |||
| 38271 | $self->setValue('magic_points_max', $maxBars); | ||
| 38272 | $self->setValue('magic_points', $numBars); | ||
| 38273 | |||
| 38274 | } elsif ($varType eq 'energy') { | ||
| 38275 | |||
| 38276 | $self->setValue('energy_points_max', $maxBars); | ||
| 38277 | $self->setValue('energy_points', $numBars); | ||
| 38278 | |||
| 38279 | } elsif ($varType eq 'guild') { | ||
| 38280 | |||
| 38281 | $self->setValue('guild_points_max', $maxBars); | ||
| 38282 | $self->setValue('guild_points', $numBars); | ||
| 38283 | |||
| 38284 | } elsif ($varType eq 'social') { | ||
| 38285 | |||
| 38286 | $self->setValue('social_points_max', $maxBars); | ||
| 38287 | $self->setValue('social_points', $numBars); | ||
| 38288 | |||
| 38289 | } elsif ($varType eq 'xp_current') { | ||
| 38290 | |||
| 38291 | $self->setValue('xp_total', $maxBars); | ||
| 38292 | $self->setValue('xp_current', $numBars); | ||
| 38293 | |||
| 38294 | } elsif ($varType eq 'xp_next_level') { | ||
| 38295 | |||
| 38296 | $self->setValue('xp_total', $maxBars); | ||
| 38297 | $self->setValue('xp_next_level', $numBars); | ||
| 38298 | |||
| 38299 | } elsif ($varType eq 'qp_current') { | ||
| 38300 | |||
| 38301 | $self->setValue('qp_total', $maxBars); | ||
| 38302 | $self->setValue('qp_current', $numBars); | ||
| 38303 | |||
| 38304 | } elsif ($varType eq 'qp_next_level') { | ||
| 38305 | |||
| 38306 | $self->setValue('qp_total', $maxBars); | ||
| 38307 | $self->setValue('qp_next_level', $numBars); | ||
| 38308 | |||
| 38309 | } elsif ($varType eq 'op_current') { | ||
| 38310 | |||
| 38311 | $self->setValue('op_total', $maxBars); | ||
| 38312 | $self->setValue('op_current', $numBars); | ||
| 38313 | |||
| 38314 | } elsif ($varType eq 'op_next_level') { | ||
| 38315 | |||
| 38316 | $self->setValue('op_total', $maxBars); | ||
| 38317 | $self->setValue('op_next_level', $numBars); | ||
| 38318 | } | ||
| 38319 | |||
| 38320 | return 1; | ||
| 38321 | } | ||
| 38322 | |||
| 38323 | sub groupPatternSeen { | ||
| 38324 | |||
| 38325 | # Called by GA::Session->checkTriggers | ||
| 38326 | # | ||
| 38327 | # This task's ->resetTriggers function creates some triggers to capture strings matching | ||
| 38328 | # patterns containing group substrings, only one of which we want | ||
| 38329 | # e.g. '^Hp: (.*) Gp: (.*) Xp: (.*) Sp: (.*)$' | ||
| 38330 | # | ||
| 38331 | # The world profile's group pattern list occurs in groups of 4 elements, representing | ||
| 38332 | # [0] - the pattern to match | ||
| 38333 | # [1] - which group substring contains the data we need | ||
| 38334 | # [2] - a Status task variable; must be a character, local or custom variable | ||
| 38335 | # [3] - 'hide' to use a gag trigger, 'show' to use a non-gag trigger, 'choose' to let the | ||
| 38336 | # Status task choose | ||
| 38337 | # | ||
| 38338 | # The trigger interfaces have the following properties in ->propertyHash: | ||
| 38339 | # grp_num - which group substring contains the data we need (same as [1] ) | ||
| 38340 | # var_type - 'health_points', etc (same as [2] ) | ||
| 38341 | # | ||
| 38342 | # This function checks the appropriate group substring and updates IVs. If var_type is | ||
| 38343 | # 'health_points', also checks whether the character's health points have changed from one | ||
| 38344 | # band to another (requiring a change in the task window's background colour) | ||
| 38345 | # | ||
| 38346 | # Expected arguments (standard args from GA::Session->checkTriggers) | ||
| 38347 | # $session - The calling function's GA::Session | ||
| 38348 | # $interfaceNum - The number of the active trigger interface that fired | ||
| 38349 | # $line - The line of text received from the world | ||
| 38350 | # $stripLine - $line, with all escape sequences removed | ||
| 38351 | # $modLine - $stripLine, possibly modified by previously-checked triggers | ||
| 38352 | # $grpStringListRef | ||
| 38353 | # - Reference to a list of group substrings from the pattern match | ||
| 38354 | # (equivalent of @_) | ||
| 38355 | # $matchMinusListRef | ||
| 38356 | # - Reference to a list of matched substring offsets (equivalent of @-) | ||
| 38357 | # $matchPlusListRef | ||
| 38358 | # - Reference to a list of matched substring offsets (equivalent of @+) | ||
| 38359 | # | ||
| 38360 | # Return values | ||
| 38361 | # 'undef' on improper arguments, or if $session is the wrong session, if the interface | ||
| 38362 | # object can't be found, if the variable can't be set or if the variable's new value | ||
| 38363 | # can't be extracted from the string | ||
| 38364 | # 1 otherwise | ||
| 38365 | |||
| 38366 | my ( | ||
| 38367 | $self, $session, $interfaceNum, $line, $stripLine, $modLine, $grpStringListRef, | ||
| 38368 | $matchMinusListRef, $matchPlusListRef, $check, | ||
| 38369 | ) = @_; | ||
| 38370 | |||
| 38371 | # Local variables | ||
| 38372 | my ($obj, $grpNum, $varType, $newValue); | ||
| 38373 | |||
| 38374 | # Check for improper arguments | ||
| 38375 | if ( | ||
| 38376 | ! defined $session || ! defined $interfaceNum || ! defined $line || ! defined $stripLine | ||
| 38377 | || ! defined $modLine || ! defined $grpStringListRef || ! defined $matchMinusListRef | ||
| 38378 | || ! defined $matchPlusListRef || defined $check | ||
| 38379 | ) { | ||
| 38380 | return $axmud::CLIENT->writeImproper( | ||
| 38381 | $self->_objClass . '->groupPatternSeen', | ||
| 38382 | @_, | ||
| 38383 | ); | ||
| 38384 | } | ||
| 38385 | |||
| 38386 | # Basic check - the trigger should belong to the right session | ||
| 38387 | if ($session ne $self->session) { | ||
| 38388 | |||
| 38389 | return undef; | ||
| 38390 | } | ||
| 38391 | |||
| 38392 | # Get the interface object itself | ||
| 38393 | $obj = $session->ivShow('interfaceNumHash', $interfaceNum); | ||
| 38394 | if (! $obj) { | ||
| 38395 | |||
| 38396 | return undef; | ||
| 38397 | } | ||
| 38398 | |||
| 38399 | # Respond to the fired trigger | ||
| 38400 | |||
| 38401 | # Import the trigger's properties | ||
| 38402 | $grpNum = $obj->ivShow('propertyHash', 'grp_num'); | ||
| 38403 | $varType = $obj->ivShow('propertyHash', 'var_type'); | ||
| 38404 | # Get the corresponding IV's new value | ||
| 38405 | $newValue = $$grpStringListRef[$grpNum]; | ||
| 38406 | if (! defined $newValue) { | ||
| 38407 | |||
| 38408 | # IV's new value couldn't be extracted from the string | ||
| 38409 | return undef; | ||
| 38410 | |||
| 38411 | } else { | ||
| 38412 | |||
| 38413 | # Remove any leading or trailing whitespace | ||
| 38414 | $newValue = $axmud::CLIENT->trimWhitespace($newValue); | ||
| 38415 | |||
| 38416 | # Update IVs | ||
| 38417 | if (! $self->setValue($varType, $newValue)) { | ||
| 38418 | |||
| 38419 | return undef; | ||
| 38420 | |||
| 38421 | } else { | ||
| 38422 | |||
| 38423 | return 1; | ||
| 38424 | } | ||
| 38425 | } | ||
| 38426 | } | ||
| 38427 | |||
| 38428 | sub affectPatternSeen { | ||
| 38429 | |||
| 38430 | # Called by GA::Session->checkTriggers | ||
| 38431 | # | ||
| 38432 | # This task's ->resetTriggers function creates some triggers to capture strings matching | ||
| 38433 | # spells (etc) affecting the character | ||
| 38434 | # e.g. 'Spells: Curse Invisibility' | ||
| 38435 | # | ||
| 38436 | # The world profile's affect pattern list occurs in groups of 4 elements, representing | ||
| 38437 | # [0] - the pattern to match | ||
| 38438 | # [1] - which group substring contains the data we need | ||
| 38439 | # [2] - 'hide' to use a gag trigger, 'show' to use a non-gag trigger, 'choose' to let the | ||
| 38440 | # Status task choose | ||
| 38441 | # | ||
| 38442 | # The trigger interfaces have the following properties in ->propertyHash: | ||
| 38443 | # grp_num - which group substring contains the data we need (same as [1] ) | ||
| 38444 | # | ||
| 38445 | # This function checks the appropriate group substring and updates IVs | ||
| 38446 | # | ||
| 38447 | # Expected arguments (standard args from GA::Session->checkTriggers) | ||
| 38448 | # $session - The calling function's GA::Session | ||
| 38449 | # $interfaceNum - The number of the active trigger interface that fired | ||
| 38450 | # $line - The line of text received from the world | ||
| 38451 | # $stripLine - $line, with all escape sequences removed | ||
| 38452 | # $modLine - $stripLine, possibly modified by previously-checked triggers | ||
| 38453 | # $grpStringListRef | ||
| 38454 | # - Reference to a list of group substrings from the pattern match | ||
| 38455 | # (equivalent of @_) | ||
| 38456 | # $matchMinusListRef | ||
| 38457 | # - Reference to a list of matched substring offsets (equivalent of @-) | ||
| 38458 | # $matchPlusListRef | ||
| 38459 | # - Reference to a list of matched substring offsets (equivalent of @+) | ||
| 38460 | # | ||
| 38461 | # Return values | ||
| 38462 | # 'undef' on improper arguments, or if $session is the wrong session, if the interface | ||
| 38463 | # object can't be found, if the corresponding IV can't be found or if the IV's | ||
| 38464 | # new value can't be extracted from the string | ||
| 38465 | # 1 otherwise | ||
| 38466 | |||
| 38467 | my ( | ||
| 38468 | $self, $session, $interfaceNum, $line, $stripLine, $modLine, $grpStringListRef, | ||
| 38469 | $matchMinusListRef, $matchPlusListRef, $check, | ||
| 38470 | ) = @_; | ||
| 38471 | |||
| 38472 | # Local variables | ||
| 38473 | my ( | ||
| 38474 | $obj, $grpNum, $newValue, | ||
| 38475 | @affectList, | ||
| 38476 | %affectHash, | ||
| 38477 | ); | ||
| 38478 | |||
| 38479 | # Check for improper arguments | ||
| 38480 | if ( | ||
| 38481 | ! defined $session || ! defined $interfaceNum || ! defined $line || ! defined $stripLine | ||
| 38482 | || ! defined $modLine || ! defined $grpStringListRef || ! defined $matchMinusListRef | ||
| 38483 | || ! defined $matchPlusListRef || defined $check | ||
| 38484 | ) { | ||
| 38485 | return $axmud::CLIENT->writeImproper( | ||
| 38486 | $self->_objClass . '->affectPatternSeen', | ||
| 38487 | @_, | ||
| 38488 | ); | ||
| 38489 | } | ||
| 38490 | |||
| 38491 | # Basic check - the trigger should belong to the right session | ||
| 38492 | if ($session ne $self->session) { | ||
| 38493 | |||
| 38494 | return undef; | ||
| 38495 | } | ||
| 38496 | |||
| 38497 | # Get the interface object itself | ||
| 38498 | $obj = $session->ivShow('interfaceNumHash', $interfaceNum); | ||
| 38499 | if (! $obj) { | ||
| 38500 | |||
| 38501 | return undef; | ||
| 38502 | } | ||
| 38503 | |||
| 38504 | # Respond to the fired trigger | ||
| 38505 | |||
| 38506 | # Import the trigger's properties | ||
| 38507 | $grpNum = $obj->ivShow('propertyHash', 'grp_num'); | ||
| 38508 | # The value 0 means that the character is not affected by any spells (etc) | ||
| 38509 | if ($grpNum) { | ||
| 38510 | |||
| 38511 | # Get the corresponding IV's new value | ||
| 38512 | $newValue = $$grpStringListRef[$grpNum]; | ||
| 38513 | if (! defined $newValue) { | ||
| 38514 | |||
| 38515 | # IV's new value couldn't be extracted from the string | ||
| 38516 | return undef; | ||
| 38517 | } | ||
| 38518 | |||
| 38519 | # Every word in $newValue is an affect (or spell) | ||
| 38520 | @affectList = split(/\s+/, $newValue); | ||
| 38521 | foreach my $affect (@affectList) { | ||
| 38522 | |||
| 38523 | $affectHash{$affect} = undef; | ||
| 38524 | } | ||
| 38525 | } | ||
| 38526 | |||
| 38527 | # Update this task's hash. Any affect not captured by this trigger is therefore removed | ||
| 38528 | # from the task's hash; if $grpNum was 0, the task's hash is emptied | ||
| 38529 | $self->ivPoke('affectHash', %affectHash); | ||
| 38530 | |||
| 38531 | # The task window must be updated on the next task loop | ||
| 38532 | $self->ivPoke('updateFlag', TRUE); | ||
| 38533 | |||
| 38534 | return 1; | ||
| 38535 | } | ||
| 38536 | |||
| 38537 | sub statPatternSeen { | ||
| 38538 | |||
| 38539 | # Called by GA::Session->checkTriggers | ||
| 38540 | # | ||
| 38541 | # This task's ->resetTriggers function creates some triggers to capture strings matching | ||
| 38542 | # the character's current stats | ||
| 38543 | # e.g. 'Strength: 10 Dexterity: 15 Constitution: 13 Intelligence: 6 Wisdom: 4' | ||
| 38544 | # | ||
| 38545 | # The world profile's stat pattern list occurs in groups of 4 elements, representing | ||
| 38546 | # [0] - the pattern to match | ||
| 38547 | # [1] - which group substring contains the data we need | ||
| 38548 | # [2] - a key in the stat hash (e.g. 'int', 'con', 'dex') | ||
| 38549 | # [3] - 'hide' to use a gag trigger, 'show' to use a non-gag trigger, 'choose' to let the | ||
| 38550 | # Status task choose | ||
| 38551 | # | ||
| 38552 | # The trigger interfaces have the following properties in ->propertyHash: | ||
| 38553 | # grp_num - which group substring contains the data we need (same as [1] ) | ||
| 38554 | # stat_type - 'Strength', 'dex', 'foobar' (same as [2] ) | ||
| 38555 | # | ||
| 38556 | # This function checks the appropriate group substring and updates IVs | ||
| 38557 | # | ||
| 38558 | # Expected arguments (standard args from GA::Session->checkTriggers) | ||
| 38559 | # $session - The calling function's GA::Session | ||
| 38560 | # $interfaceNum - The number of the active trigger interface that fired | ||
| 38561 | # $line - The line of text received from the world | ||
| 38562 | # $stripLine - $line, with all escape sequences removed | ||
| 38563 | # $modLine - $stripLine, possibly modified by previously-checked triggers | ||
| 38564 | # $grpStringListRef | ||
| 38565 | # - Reference to a list of group substrings from the pattern match | ||
| 38566 | # (equivalent of @_) | ||
| 38567 | # $matchMinusListRef | ||
| 38568 | # - Reference to a list of matched substring offsets (equivalent of @-) | ||
| 38569 | # $matchPlusListRef | ||
| 38570 | # - Reference to a list of matched substring offsets (equivalent of @+) | ||
| 38571 | # | ||
| 38572 | # Return values | ||
| 38573 | # 'undef' on improper arguments, or if $session is the wrong session, if the interface | ||
| 38574 | # object can't be found, if the corresponding IV can't be found or if the IV's | ||
| 38575 | # new value can't be extracted from the string | ||
| 38576 | # 1 otherwise | ||
| 38577 | |||
| 38578 | my ( | ||
| 38579 | $self, $session, $interfaceNum, $line, $stripLine, $modLine, $grpStringListRef, | ||
| 38580 | $matchMinusListRef, $matchPlusListRef, $check, | ||
| 38581 | ) = @_; | ||
| 38582 | |||
| 38583 | # Local variables | ||
| 38584 | my ($obj, $grpNum, $statType, $newValue); | ||
| 38585 | |||
| 38586 | # Check for improper arguments | ||
| 38587 | if ( | ||
| 38588 | ! defined $session || ! defined $interfaceNum || ! defined $line || ! defined $stripLine | ||
| 38589 | || ! defined $modLine || ! defined $grpStringListRef || ! defined $matchMinusListRef | ||
| 38590 | || ! defined $matchPlusListRef || defined $check | ||
| 38591 | ) { | ||
| 38592 | return $axmud::CLIENT->writeImproper( | ||
| 38593 | $self->_objClass . '->statPatternSeen', | ||
| 38594 | @_, | ||
| 38595 | ); | ||
| 38596 | } | ||
| 38597 | |||
| 38598 | # Basic check - the trigger should belong to the right session | ||
| 38599 | if ($session ne $self->session) { | ||
| 38600 | |||
| 38601 | return undef; | ||
| 38602 | } | ||
| 38603 | |||
| 38604 | # Get the interface object itself | ||
| 38605 | $obj = $session->ivShow('interfaceNumHash', $interfaceNum); | ||
| 38606 | if (! $obj) { | ||
| 38607 | |||
| 38608 | return undef; | ||
| 38609 | } | ||
| 38610 | |||
| 38611 | # Respond to the fired trigger | ||
| 38612 | |||
| 38613 | # Import the trigger's properties | ||
| 38614 | $grpNum = $obj->ivShow('propertyHash', 'grp_num'); | ||
| 38615 | $statType = $obj->ivShow('propertyHash', 'stat_type'); | ||
| 38616 | # Get the corresponding IV's new value | ||
| 38617 | $newValue = $$grpStringListRef[$grpNum]; | ||
| 38618 | if (! defined $newValue) { | ||
| 38619 | |||
| 38620 | # IV's new value couldn't be extracted from the string | ||
| 38621 | return undef; | ||
| 38622 | |||
| 38623 | } else { | ||
| 38624 | |||
| 38625 | # Remove any leading or trailing whitespace | ||
| 38626 | $newValue = $axmud::CLIENT->trimWhitespace($newValue); | ||
| 38627 | } | ||
| 38628 | |||
| 38629 | # Update the task's instance variables | ||
| 38630 | if (! $self->ivExists('statHash', $statType)) { | ||
| 38631 | |||
| 38632 | # Unrecognised stat | ||
| 38633 | return undef; | ||
| 38634 | |||
| 38635 | } else { | ||
| 38636 | |||
| 38637 | # Replace the stat's value | ||
| 38638 | $self->ivAdd('statHash', $statType, $newValue); | ||
| 38639 | $self->ivPoke('updateFlag', TRUE); | ||
| 38640 | |||
| 38641 | return 1; | ||
| 38642 | } | ||
| 38643 | } | ||
| 38644 | |||
| 38645 | sub ageSeen { | ||
| 38646 | |||
| 38647 | # Called by GA::Session->checkTriggers | ||
| 38648 | # | ||
| 38649 | # This task's ->resetTriggers function creates some triggers to capture age strings. All | ||
| 38650 | # group substrings are used, but ->propertyHash isn't used | ||
| 38651 | # | ||
| 38652 | # The world profile defines a list of patterns that tells us the character's age | ||
| 38653 | # e.g. 'You are 15 hours, 39 minutes and 7 seconds old.' | ||
| 38654 | # ...might match the pattern '^You are (.*) old\.' | ||
| 38655 | # The function extracts the age from the whole list of group substrings and produces the | ||
| 38656 | # character's age in a single value, expressed in the world profile's standard age unit | ||
| 38657 | # (default is 'day') | ||
| 38658 | # If extraction is successful, it updates IVs | ||
| 38659 | # | ||
| 38660 | # Expected arguments (standard args from GA::Session->checkTriggers) | ||
| 38661 | # $session - The calling function's GA::Session | ||
| 38662 | # $interfaceNum - The number of the active trigger interface that fired | ||
| 38663 | # $line - The line of text received from the world | ||
| 38664 | # $stripLine - $line, with all escape sequences removed | ||
| 38665 | # $modLine - $stripLine, possibly modified by previously-checked triggers | ||
| 38666 | # $grpStringListRef | ||
| 38667 | # - Reference to a list of group substrings from the pattern match | ||
| 38668 | # (equivalent of @_) | ||
| 38669 | # $matchMinusListRef | ||
| 38670 | # - Reference to a list of matched substring offsets (equivalent of @-) | ||
| 38671 | # $matchPlusListRef | ||
| 38672 | # - Reference to a list of matched substring offsets (equivalent of @+) | ||
| 38673 | # | ||
| 38674 | # Return values | ||
| 38675 | # 'undef' on improper arguments, or if $session is the wrong session, if the interface | ||
| 38676 | # object can't be found or if the age can't be converted | ||
| 38677 | # 1 otherwise | ||
| 38678 | |||
| 38679 | my ( | ||
| 38680 | $self, $session, $interfaceNum, $line, $stripLine, $modLine, $grpStringListRef, | ||
| 38681 | $matchMinusListRef, $matchPlusListRef, $check, | ||
| 38682 | ) = @_; | ||
| 38683 | |||
| 38684 | # Local variables | ||
| 38685 | my ( | ||
| 38686 | $obj, $age, | ||
| 38687 | @list, | ||
| 38688 | ); | ||
| 38689 | |||
| 38690 | # Check for improper arguments | ||
| 38691 | if ( | ||
| 38692 | ! defined $session || ! defined $interfaceNum || ! defined $line || ! defined $stripLine | ||
| 38693 | || ! defined $modLine || ! defined $grpStringListRef || ! defined $matchMinusListRef | ||
| 38694 | || ! defined $matchPlusListRef || defined $check | ||
| 38695 | ) { | ||
| 38696 | return $axmud::CLIENT->writeImproper($self->_objClass . '->ageSeen', @_); | ||
| 38697 | } | ||
| 38698 | |||
| 38699 | # Basic check - the trigger should belong to the right session | ||
| 38700 | if ($session ne $self->session) { | ||
| 38701 | |||
| 38702 | return undef; | ||
| 38703 | } | ||
| 38704 | |||
| 38705 | # Get the interface object itself | ||
| 38706 | $obj = $session->ivShow('interfaceNumHash', $interfaceNum); | ||
| 38707 | if (! $obj) { | ||
| 38708 | |||
| 38709 | return undef; | ||
| 38710 | } | ||
| 38711 | |||
| 38712 | # Respond to the fired trigger | ||
| 38713 | |||
| 38714 | # Get all the group substrings, removing index #0, which contains the whole matched string | ||
| 38715 | shift @$grpStringListRef; | ||
| 38716 | |||
| 38717 | $age = $self->convertAge(@$grpStringListRef); | ||
| 38718 | if (! defined $age) { | ||
| 38719 | |||
| 38720 | # Conversion failed | ||
| 38721 | return undef; | ||
| 38722 | |||
| 38723 | } else { | ||
| 38724 | |||
| 38725 | # Character's age was successfully converted | ||
| 38726 | $self->setValue('age', $age); | ||
| 38727 | $self->ivPoke('updateFlag', TRUE); | ||
| 38728 | |||
| 38729 | return 1; | ||
| 38730 | } | ||
| 38731 | } | ||
| 38732 | |||
| 38733 | sub timeSeen { | ||
| 38734 | |||
| 38735 | # Called by GA::Session->checkTriggers | ||
| 38736 | # | ||
| 38737 | # This task's ->resetTriggers function creates some triggers to capture time strings. Only | ||
| 38738 | # the first group substring is used, but ->propertyHash isn't needed | ||
| 38739 | # | ||
| 38740 | # Useful for worlds that have a local game time that reads something like 'It is half past | ||
| 38741 | # two in the morning' | ||
| 38742 | # The function extracts the time from the first group substring and converts it into a | ||
| 38743 | # string containing the time in the 24-hour clock (e.g. '02:45'), if possible, before | ||
| 38744 | # storing the converted time as $self->time | ||
| 38745 | # However, if self->convertTimeFlag is FALSE, no conversion is attempted (and the first | ||
| 38746 | # group substring is stored as $self->time) | ||
| 38747 | # If extraction is successful, it updates IVs | ||
| 38748 | # | ||
| 38749 | # Expected arguments (standard args from GA::Session->checkTriggers) | ||
| 38750 | # $session - The calling function's GA::Session | ||
| 38751 | # $interfaceNum - The number of the active trigger interface that fired | ||
| 38752 | # $line - The line of text received from the world | ||
| 38753 | # $stripLine - $line, with all escape sequences removed | ||
| 38754 | # $modLine - $stripLine, possibly modified by previously-checked triggers | ||
| 38755 | # $grpStringListRef | ||
| 38756 | # - Reference to a list of group substrings from the pattern match | ||
| 38757 | # (equivalent of @_) | ||
| 38758 | # $matchMinusListRef | ||
| 38759 | # - Reference to a list of matched substring offsets (equivalent of @-) | ||
| 38760 | # $matchPlusListRef | ||
| 38761 | # - Reference to a list of matched substring offsets (equivalent of @+) | ||
| 38762 | # | ||
| 38763 | # Return values | ||
| 38764 | # 'undef' on improper arguments, or if $session is the wrong session or if the interface | ||
| 38765 | # object can't be found | ||
| 38766 | # 1 otherwise | ||
| 38767 | |||
| 38768 | my ( | ||
| 38769 | $self, $session, $interfaceNum, $line, $stripLine, $modLine, $grpStringListRef, | ||
| 38770 | $matchMinusListRef, $matchPlusListRef, $check, | ||
| 38771 | ) = @_; | ||
| 38772 | |||
| 38773 | # Local variables | ||
| 38774 | my ($obj, $grpNum, $hours, $minutes); | ||
| 38775 | |||
| 38776 | # Check for improper arguments | ||
| 38777 | if ( | ||
| 38778 | ! defined $session || ! defined $interfaceNum || ! defined $line || ! defined $stripLine | ||
| 38779 | || ! defined $modLine || ! defined $grpStringListRef || ! defined $matchMinusListRef | ||
| 38780 | || ! defined $matchPlusListRef || defined $check | ||
| 38781 | ) { | ||
| 38782 | return $axmud::CLIENT->writeImproper($self->_objClass . '->timeSeen', @_); | ||
| 38783 | } | ||
| 38784 | |||
| 38785 | # Basic check - the trigger should belong to the right session | ||
| 38786 | if ($session ne $self->session) { | ||
| 38787 | |||
| 38788 | return undef; | ||
| 38789 | } | ||
| 38790 | |||
| 38791 | # Get the interface object itself | ||
| 38792 | $obj = $session->ivShow('interfaceNumHash', $interfaceNum); | ||
| 38793 | if (! $obj) { | ||
| 38794 | |||
| 38795 | return undef; | ||
| 38796 | } | ||
| 38797 | |||
| 38798 | # Respond to the fired trigger | ||
| 38799 | $grpNum = $$grpStringListRef[1]; | ||
| 38800 | if ($self->convertTimeFlag) { | ||
| 38801 | |||
| 38802 | ($hours, $minutes) = $self->convertTime($grpNum); | ||
| 38803 | } | ||
| 38804 | |||
| 38805 | # If the call to ->convertTime failed (or if no conversion was attempted), $hours is still | ||
| 38806 | # set to 'undef' | ||
| 38807 | if (! defined $hours) { | ||
| 38808 | |||
| 38809 | $self->setValue('time', $grpNum); | ||
| 38810 | |||
| 38811 | # Long time string was successfully converted into a shorter string | ||
| 38812 | } else { | ||
| 38813 | |||
| 38814 | $self->setValue('time', sprintf('%02d:%02d', $hours, $minutes)); | ||
| 38815 | } | ||
| 38816 | |||
| 38817 | $self->ivPoke('updateFlag', TRUE); | ||
| 38818 | |||
| 38819 | return 1; | ||
| 38820 | } | ||
| 38821 | |||
| 38822 | sub ignorePatternSeen { | ||
| 38823 | |||
| 38824 | # Called by GA::Session->checkTriggers | ||
| 38825 | # | ||
| 38826 | # This task's ->resetTriggers function creates some triggers to capture ignorable strings. | ||
| 38827 | # Group substrings and ->propertyHash aren't used. | ||
| 38828 | # | ||
| 38829 | # When commands like 'score', 'time' and 'stats' are sent to the world and $self->activeFlag | ||
| 38830 | # is set to TRUE (meaning, don't display the response in the 'main' window), the world may | ||
| 38831 | # display several lines in response, some of which may not contain any useful data | ||
| 38832 | # The current world's 'ignore patterns' create triggers which gag those lines and redirect | ||
| 38833 | # them to this function - just in case they are needed (for debugging purposes) | ||
| 38834 | # | ||
| 38835 | # Expected arguments (standard args from GA::Session->checkTriggers) | ||
| 38836 | # $session - The calling function's GA::Session | ||
| 38837 | # $interfaceNum - The number of the active trigger interface that fired | ||
| 38838 | # $line - The line of text received from the world | ||
| 38839 | # $stripLine - $line, with all escape sequences removed | ||
| 38840 | # $modLine - $stripLine, possibly modified by previously-checked triggers | ||
| 38841 | # $grpStringListRef | ||
| 38842 | # - Reference to a list of group substrings from the pattern match | ||
| 38843 | # (equivalent of @_) | ||
| 38844 | # $matchMinusListRef | ||
| 38845 | # - Reference to a list of matched substring offsets (equivalent of @-) | ||
| 38846 | # $matchPlusListRef | ||
| 38847 | # - Reference to a list of matched substring offsets (equivalent of @+) | ||
| 38848 | # | ||
| 38849 | # Return values | ||
| 38850 | # 'undef' on improper arguments, or if $session is the wrong session or if the interface | ||
| 38851 | # object can't be found | ||
| 38852 | # 1 otherwise | ||
| 38853 | |||
| 38854 | my ( | ||
| 38855 | $self, $session, $interfaceNum, $line, $stripLine, $modLine, $grpStringListRef, | ||
| 38856 | $matchMinusListRef, $matchPlusListRef, $check, | ||
| 38857 | ) = @_; | ||
| 38858 | |||
| 38859 | # Local variables | ||
| 38860 | my $obj; | ||
| 38861 | |||
| 38862 | # Check for improper arguments | ||
| 38863 | if ( | ||
| 38864 | ! defined $session || ! defined $interfaceNum || ! defined $line || ! defined $stripLine | ||
| 38865 | || ! defined $modLine || ! defined $grpStringListRef || ! defined $matchMinusListRef | ||
| 38866 | || ! defined $matchPlusListRef || defined $check | ||
| 38867 | ) { | ||
| 38868 | return $axmud::CLIENT->writeImproper($self->_objClass . '->ignorePatternSeen', @_); | ||
| 38869 | } | ||
| 38870 | |||
| 38871 | # Basic check - the trigger should belong to the right session | ||
| 38872 | if ($session ne $self->session) { | ||
| 38873 | |||
| 38874 | return undef; | ||
| 38875 | } | ||
| 38876 | |||
| 38877 | # Get the interface object itself | ||
| 38878 | $obj = $session->ivShow('interfaceNumHash', $interfaceNum); | ||
| 38879 | if (! $obj) { | ||
| 38880 | |||
| 38881 | return undef; | ||
| 38882 | } | ||
| 38883 | |||
| 38884 | # Respond to the fired trigger (this function does nothing) | ||
| 38885 | # ... | ||
| 38886 | |||
| 38887 | return 1; | ||
| 38888 | } | ||
| 38889 | |||
| 38890 | sub asleepSeen { | ||
| 38891 | |||
| 38892 | # Called by GA::Session->checkTriggers | ||
| 38893 | # | ||
| 38894 | # This task's ->resetTriggers function creates some triggers to capture character falling | ||
| 38895 | # asleep strings. Group substrings and ->propertyHash aren't used. | ||
| 38896 | # | ||
| 38897 | # Updates some IVs, writes to the logfile which monitors characters falling asleep, and | ||
| 38898 | # plays a sound effect (if allowed) | ||
| 38899 | # | ||
| 38900 | # Expected arguments (standard args from GA::Session->checkTriggers) | ||
| 38901 | # $session - The calling function's GA::Session | ||
| 38902 | # $interfaceNum - The number of the active trigger interface that fired | ||
| 38903 | # $line - The line of text received from the world | ||
| 38904 | # $stripLine - $line, with all escape sequences removed | ||
| 38905 | # $modLine - $stripLine, possibly modified by previously-checked triggers | ||
| 38906 | # $grpStringListRef | ||
| 38907 | # - Reference to a list of group substrings from the pattern match | ||
| 38908 | # (equivalent of @_) | ||
| 38909 | # $matchMinusListRef | ||
| 38910 | # - Reference to a list of matched substring offsets (equivalent of @-) | ||
| 38911 | # $matchPlusListRef | ||
| 38912 | # - Reference to a list of matched substring offsets (equivalent of @+) | ||
| 38913 | # | ||
| 38914 | # Return values | ||
| 38915 | # 'undef' on improper arguments, or if $session is the wrong session or if the interface | ||
| 38916 | # object can't be found | ||
| 38917 | # 1 otherwise | ||
| 38918 | |||
| 38919 | my ( | ||
| 38920 | $self, $session, $interfaceNum, $line, $stripLine, $modLine, $grpStringListRef, | ||
| 38921 | $matchMinusListRef, $matchPlusListRef, $check, | ||
| 38922 | ) = @_; | ||
| 38923 | |||
| 38924 | # Local variables | ||
| 38925 | my ( | ||
| 38926 | $obj, $charObj, $start, $stop, | ||
| 38927 | @writeList, | ||
| 38928 | ); | ||
| 38929 | |||
| 38930 | # Check for improper arguments | ||
| 38931 | if ( | ||
| 38932 | ! defined $session || ! defined $interfaceNum || ! defined $line || ! defined $stripLine | ||
| 38933 | || ! defined $modLine || ! defined $grpStringListRef || ! defined $matchMinusListRef | ||
| 38934 | || ! defined $matchPlusListRef || defined $check | ||
| 38935 | ) { | ||
| 38936 | return $axmud::CLIENT->writeImproper($self->_objClass . '->asleepSeen', @_); | ||
| 38937 | } | ||
| 38938 | |||
| 38939 | # Basic check - the trigger should belong to the right session | ||
| 38940 | if ($session ne $self->session) { | ||
| 38941 | |||
| 38942 | return undef; | ||
| 38943 | } | ||
| 38944 | |||
| 38945 | # Get the interface object itself | ||
| 38946 | $obj = $session->ivShow('interfaceNumHash', $interfaceNum); | ||
| 38947 | if (! $obj) { | ||
| 38948 | |||
| 38949 | return undef; | ||
| 38950 | } | ||
| 38951 | |||
| 38952 | # Respond to the fired trigger | ||
| 38953 | |||
| 38954 | # Import the current character profile | ||
| 38955 | $charObj = $self->session->currentChar; | ||
| 38956 | |||
| 38957 | # If the character is not already asleep... | ||
| 38958 | if ($charObj && $charObj->lifeStatus ne 'sleep') { | ||
| 38959 | |||
| 38960 | $charObj->ivPoke('lifeStatus', 'sleep'); | ||
| 38961 | |||
| 38962 | # The next time the task window is updated, its background colour will change | ||
| 38963 | $self->ivPoke('lifeStatusChangeFlag', TRUE); | ||
| 38964 | |||
| 38965 | if ($session->currentWorld->ivShow('logPrefHash', 'sleep')) { | ||
| 38966 | |||
| 38967 | # Record lines that lead up to this event, and mark future lines to be recorded | ||
| 38968 | push (@writeList, 'CHARACTER SLEEP DETECTED'); | ||
| 38969 | push (@writeList, '------------------------'); | ||
| 38970 | |||
| 38971 | if ($axmud::CLIENT->statusEventBeforeCount && $session->displayBufferCount) { | ||
| 38972 | |||
| 38973 | if ($session->displayBufferCount < $axmud::CLIENT->statusEventBeforeCount) { | ||
| 38974 | |||
| 38975 | $start = 0, | ||
| 38976 | $stop = $session->displayBufferLast; | ||
| 38977 | |||
| 38978 | } else { | ||
| 38979 | |||
| 38980 | $start = $session->displayBufferLast | ||
| 38981 | - $axmud::CLIENT->statusEventBeforeCount + 1; | ||
| 38982 | $stop = $session->displayBufferLast; | ||
| 38983 | } | ||
| 38984 | |||
| 38985 | for (my $lineNum = $start; $lineNum <= $stop; $lineNum++) { | ||
| 38986 | |||
| 38987 | my $bufferObj = $session->ivShow('displayBufferHash', $lineNum); | ||
| 38988 | |||
| 38989 | if ($session->ivExists('displayBufferHash', $lineNum)) { | ||
| 38990 | |||
| 38991 | push (@writeList, $bufferObj->modLine); | ||
| 38992 | } | ||
| 38993 | } | ||
| 38994 | } | ||
| 38995 | |||
| 38996 | # Write previously-received lines to the logfile (if possible) | ||
| 38997 | foreach my $string (@writeList) { | ||
| 38998 | |||
| 38999 | $axmud::CLIENT->writeLog( | ||
| 39000 | $session, | ||
| 39001 | FALSE, # Not a 'standard' logfile | ||
| 39002 | $string, | ||
| 39003 | FALSE, # Don't precede with a newline character | ||
| 39004 | TRUE, # Use final newline character | ||
| 39005 | 'sleep', # Write to this logfile | ||
| 39006 | ); | ||
| 39007 | } | ||
| 39008 | |||
| 39009 | # Mark how many lines after the current one should be written to the same logfile | ||
| 39010 | if ($axmud::CLIENT->statusEventAfterCount) { | ||
| 39011 | |||
| 39012 | $session->set_logAsleepUntilLine( | ||
| 39013 | $session->displayBufferLast + $axmud::CLIENT->statusEventAfterCount, | ||
| 39014 | ); | ||
| 39015 | } | ||
| 39016 | } | ||
| 39017 | |||
| 39018 | # Play a sound effect (if allowed) | ||
| 39019 | $axmud::CLIENT->playSound('notify'); | ||
| 39020 | |||
| 39021 | # If there is a current mission, it must be told to give up | ||
| 39022 | if ($session->currentMission) { | ||
| 39023 | |||
| 39024 | $session->currentMission->statusTaskChange($charObj->lifeStatus); | ||
| 39025 | } | ||
| 39026 | } | ||
| 39027 | |||
| 39028 | return 1; | ||
| 39029 | } | ||
| 39030 | |||
| 39031 | sub wakeUpSeen { | ||
| 39032 | |||
| 39033 | # Called by GA::Session->checkTriggers | ||
| 39034 | # | ||
| 39035 | # This task's ->resetTriggers function creates some triggers to capture character | ||
| 39036 | # resurrection strings. Group substrings and ->propertyHash aren't used | ||
| 39037 | # | ||
| 39038 | # Updates some IVs and writes to the logfile which monitors character resurrections | ||
| 39039 | # | ||
| 39040 | # Expected arguments (standard args from GA::Session->checkTriggers) | ||
| 39041 | # $session - The calling function's GA::Session | ||
| 39042 | # $interfaceNum - The number of the active trigger interface that fired | ||
| 39043 | # $line - The line of text received from the world | ||
| 39044 | # $stripLine - $line, with all escape sequences removed | ||
| 39045 | # $modLine - $stripLine, possibly modified by previously-checked triggers | ||
| 39046 | # $grpStringListRef | ||
| 39047 | # - Reference to a list of group substrings from the pattern match | ||
| 39048 | # (equivalent of @_) | ||
| 39049 | # $matchMinusListRef | ||
| 39050 | # - Reference to a list of matched substring offsets (equivalent of @-) | ||
| 39051 | # $matchPlusListRef | ||
| 39052 | # - Reference to a list of matched substring offsets (equivalent of @+) | ||
| 39053 | # | ||
| 39054 | # Return values | ||
| 39055 | # 'undef' on improper arguments, or if $session is the wrong session or if the interface | ||
| 39056 | # object can't be found | ||
| 39057 | # 1 otherwise | ||
| 39058 | |||
| 39059 | my ( | ||
| 39060 | $self, $session, $interfaceNum, $line, $stripLine, $modLine, $grpStringListRef, | ||
| 39061 | $matchMinusListRef, $matchPlusListRef, $check, | ||
| 39062 | ) = @_; | ||
| 39063 | |||
| 39064 | # Local variables | ||
| 39065 | my ($obj, $charObj); | ||
| 39066 | |||
| 39067 | # Check for improper arguments | ||
| 39068 | if ( | ||
| 39069 | ! defined $session || ! defined $interfaceNum || ! defined $line || ! defined $stripLine | ||
| 39070 | || ! defined $modLine || ! defined $grpStringListRef || ! defined $matchMinusListRef | ||
| 39071 | || ! defined $matchPlusListRef || defined $check | ||
| 39072 | ) { | ||
| 39073 | return $axmud::CLIENT->writeImproper($self->_objClass . '->wakeUpSeen', @_); | ||
| 39074 | } | ||
| 39075 | |||
| 39076 | # Basic check - the trigger should belong to the right session | ||
| 39077 | if ($session ne $self->session) { | ||
| 39078 | |||
| 39079 | return undef; | ||
| 39080 | } | ||
| 39081 | |||
| 39082 | # Get the interface object itself | ||
| 39083 | $obj = $session->ivShow('interfaceNumHash', $interfaceNum); | ||
| 39084 | if (! $obj) { | ||
| 39085 | |||
| 39086 | return undef; | ||
| 39087 | } | ||
| 39088 | |||
| 39089 | # Respond to the fired trigger | ||
| 39090 | |||
| 39091 | # Import the current character profile | ||
| 39092 | $charObj = $self->session->currentChar; | ||
| 39093 | |||
| 39094 | # If the character is not already alive... | ||
| 39095 | if ($charObj && $charObj->lifeStatus ne 'alive') { | ||
| 39096 | |||
| 39097 | $charObj->ivPoke('lifeStatus', 'alive'); | ||
| 39098 | |||
| 39099 | # The next time the task window is updated, its background colour will change | ||
| 39100 | $self->ivPoke('lifeStatusChangeFlag', TRUE); | ||
| 39101 | } | ||
| 39102 | |||
| 39103 | return 1; | ||
| 39104 | } | ||
| 39105 | |||
| 39106 | sub passedOutSeen { | ||
| 39107 | |||
| 39108 | # Called by GA::Session->checkTriggers | ||
| 39109 | # | ||
| 39110 | # This task's ->resetTriggers function creates some triggers to capture characer passing | ||
| 39111 | # out strings. Group substrings and ->propertyHash aren't used | ||
| 39112 | # | ||
| 39113 | # Updates some IVs, writes to the logfile which monitors characters passing out, and plays | ||
| 39114 | # a sound effect (if allowed) | ||
| 39115 | # | ||
| 39116 | # Expected arguments (standard args from GA::Session->checkTriggers) | ||
| 39117 | # $session - The calling function's GA::Session | ||
| 39118 | # $interfaceNum - The number of the active trigger interface that fired | ||
| 39119 | # $line - The line of text received from the world | ||
| 39120 | # $stripLine - $line, with all escape sequences removed | ||
| 39121 | # $modLine - $stripLine, possibly modified by previously-checked triggers | ||
| 39122 | # $grpStringListRef | ||
| 39123 | # - Reference to a list of group substrings from the pattern match | ||
| 39124 | # (equivalent of @_) | ||
| 39125 | # $matchMinusListRef | ||
| 39126 | # - Reference to a list of matched substring offsets (equivalent of @-) | ||
| 39127 | # $matchPlusListRef | ||
| 39128 | # - Reference to a list of matched substring offsets (equivalent of @+) | ||
| 39129 | # | ||
| 39130 | # Return values | ||
| 39131 | # 'undef' on improper arguments, or if $session is the wrong session or if the interface | ||
| 39132 | # object can't be found | ||
| 39133 | # 1 otherwise | ||
| 39134 | |||
| 39135 | my ( | ||
| 39136 | $self, $session, $interfaceNum, $line, $stripLine, $modLine, $grpStringListRef, | ||
| 39137 | $matchMinusListRef, $matchPlusListRef, $check, | ||
| 39138 | ) = @_; | ||
| 39139 | |||
| 39140 | # Local variables | ||
| 39141 | my ( | ||
| 39142 | $obj, $charObj, $start, $stop, | ||
| 39143 | @writeList, | ||
| 39144 | ); | ||
| 39145 | |||
| 39146 | # Check for improper arguments | ||
| 39147 | if ( | ||
| 39148 | ! defined $session || ! defined $interfaceNum || ! defined $line || ! defined $stripLine | ||
| 39149 | || ! defined $modLine || ! defined $grpStringListRef || ! defined $matchMinusListRef | ||
| 39150 | || ! defined $matchPlusListRef || defined $check | ||
| 39151 | ) { | ||
| 39152 | return $axmud::CLIENT->writeImproper($self->_objClass . '->passedOutSeen', @_); | ||
| 39153 | } | ||
| 39154 | |||
| 39155 | # Basic check - the trigger should belong to the right session | ||
| 39156 | if ($session ne $self->session) { | ||
| 39157 | |||
| 39158 | return undef; | ||
| 39159 | } | ||
| 39160 | |||
| 39161 | # Get the interface object itself | ||
| 39162 | $obj = $session->ivShow('interfaceNumHash', $interfaceNum); | ||
| 39163 | if (! $obj) { | ||
| 39164 | |||
| 39165 | return undef; | ||
| 39166 | } | ||
| 39167 | |||
| 39168 | # Respond to the fired trigger | ||
| 39169 | |||
| 39170 | # Import the current character profile | ||
| 39171 | $charObj = $self->session->currentChar; | ||
| 39172 | |||
| 39173 | # If the character is not already passed out... | ||
| 39174 | if ($charObj && $charObj->lifeStatus ne 'passout') { | ||
| 39175 | |||
| 39176 | $charObj->ivPoke('lifeStatus', 'passout'); | ||
| 39177 | |||
| 39178 | # The next time the task window is updated, its background colour will change | ||
| 39179 | $self->ivPoke('lifeStatusChangeFlag', TRUE); | ||
| 39180 | |||
| 39181 | if ($session->currentWorld->ivShow('logPrefHash', 'passout')) { | ||
| 39182 | |||
| 39183 | # Record lines that lead up to this event, and mark future lines to be recorded | ||
| 39184 | push (@writeList, 'CHARACTER PASS OUT DETECTED'); | ||
| 39185 | push (@writeList, '---------------------------'); | ||
| 39186 | |||
| 39187 | if ($axmud::CLIENT->statusEventBeforeCount && $session->displayBufferCount) { | ||
| 39188 | |||
| 39189 | if ($session->displayBufferCount < $axmud::CLIENT->statusEventBeforeCount) { | ||
| 39190 | |||
| 39191 | $start = 0, | ||
| 39192 | $stop = $session->displayBufferLast; | ||
| 39193 | |||
| 39194 | } else { | ||
| 39195 | |||
| 39196 | $start = $session->displayBufferLast | ||
| 39197 | - $axmud::CLIENT->statusEventBeforeCount + 1; | ||
| 39198 | $stop = $session->displayBufferLast; | ||
| 39199 | } | ||
| 39200 | |||
| 39201 | for (my $lineNum = $start; $lineNum <= $stop; $lineNum++) { | ||
| 39202 | |||
| 39203 | my $bufferObj = $session->ivShow('displayBufferHash', $lineNum); | ||
| 39204 | |||
| 39205 | if ($session->ivExists('displayBufferHash', $lineNum)) { | ||
| 39206 | |||
| 39207 | push (@writeList, $bufferObj->modLine); | ||
| 39208 | } | ||
| 39209 | } | ||
| 39210 | } | ||
| 39211 | |||
| 39212 | # Write previously-received lines to the logfile (if possible) | ||
| 39213 | foreach my $string (@writeList) { | ||
| 39214 | |||
| 39215 | $axmud::CLIENT->writeLog( | ||
| 39216 | $session, | ||
| 39217 | FALSE, # Not a 'standard' logfile | ||
| 39218 | $string, | ||
| 39219 | FALSE, # Don't precede with a newline character | ||
| 39220 | TRUE, # Use final newline character | ||
| 39221 | 'passout', # Write to this logfile | ||
| 39222 | ); | ||
| 39223 | } | ||
| 39224 | |||
| 39225 | # Mark how many lines after the current one should be written to the same logfile | ||
| 39226 | if ($axmud::CLIENT->statusEventAfterCount) { | ||
| 39227 | |||
| 39228 | $session->set_logPassedOutUntilLine( | ||
| 39229 | $session->displayBufferLast + $axmud::CLIENT->statusEventAfterCount, | ||
| 39230 | ); | ||
| 39231 | } | ||
| 39232 | } | ||
| 39233 | |||
| 39234 | # Play a sound effect (if allowed) | ||
| 39235 | $axmud::CLIENT->playSound('notify'); | ||
| 39236 | |||
| 39237 | # If there is a current mission, it must be told to give up | ||
| 39238 | if ($session->currentMission) { | ||
| 39239 | |||
| 39240 | $session->currentMission->statusTaskChange($charObj->lifeStatus); | ||
| 39241 | } | ||
| 39242 | } | ||
| 39243 | |||
| 39244 | return 1; | ||
| 39245 | } | ||
| 39246 | |||
| 39247 | sub comeAroundSeen { | ||
| 39248 | |||
| 39249 | # Called by GA::Session->checkTriggers | ||
| 39250 | # | ||
| 39251 | # This task's ->resetTriggers function creates some triggers to capture character coming | ||
| 39252 | # around strings. Group substrings and ->propertyHash aren't used. | ||
| 39253 | # | ||
| 39254 | # Updates some IVs and writes to the logfile which monitors character revivals | ||
| 39255 | # | ||
| 39256 | # Expected arguments (standard args from GA::Session->checkTriggers) | ||
| 39257 | # $session - The calling function's GA::Session | ||
| 39258 | # $interfaceNum - The number of the active trigger interface that fired | ||
| 39259 | # $line - The line of text received from the world | ||
| 39260 | # $stripLine - $line, with all escape sequences removed | ||
| 39261 | # $modLine - $stripLine, possibly modified by previously-checked triggers | ||
| 39262 | # $grpStringListRef | ||
| 39263 | # - Reference to a list of group substrings from the pattern match | ||
| 39264 | # (equivalent of @_) | ||
| 39265 | # $matchMinusListRef | ||
| 39266 | # - Reference to a list of matched substring offsets (equivalent of @-) | ||
| 39267 | # $matchPlusListRef | ||
| 39268 | # - Reference to a list of matched substring offsets (equivalent of @+) | ||
| 39269 | # | ||
| 39270 | # Return values | ||
| 39271 | # 'undef' on improper arguments, or if $session is the wrong session or if the interface | ||
| 39272 | # object can't be found | ||
| 39273 | # 1 otherwise | ||
| 39274 | |||
| 39275 | my ( | ||
| 39276 | $self, $session, $interfaceNum, $line, $stripLine, $modLine, $grpStringListRef, | ||
| 39277 | $matchMinusListRef, $matchPlusListRef, $check, | ||
| 39278 | ) = @_; | ||
| 39279 | |||
| 39280 | # Local variables | ||
| 39281 | my ($obj, $charObj); | ||
| 39282 | |||
| 39283 | # Check for improper arguments | ||
| 39284 | if ( | ||
| 39285 | ! defined $session || ! defined $interfaceNum || ! defined $line || ! defined $stripLine | ||
| 39286 | || ! defined $modLine || ! defined $grpStringListRef || ! defined $matchMinusListRef | ||
| 39287 | || ! defined $matchPlusListRef || defined $check | ||
| 39288 | ) { | ||
| 39289 | return $axmud::CLIENT->writeImproper($self->_objClass . '->resurrectSeen', @_); | ||
| 39290 | } | ||
| 39291 | |||
| 39292 | # Basic check - the trigger should belong to the right session | ||
| 39293 | if ($session ne $self->session) { | ||
| 39294 | |||
| 39295 | return undef; | ||
| 39296 | } | ||
| 39297 | |||
| 39298 | # Get the interface object itself | ||
| 39299 | $obj = $session->ivShow('interfaceNumHash', $interfaceNum); | ||
| 39300 | if (! $obj) { | ||
| 39301 | |||
| 39302 | return undef; | ||
| 39303 | } | ||
| 39304 | |||
| 39305 | # Respond to the fired trigger | ||
| 39306 | |||
| 39307 | # Import the current character profile | ||
| 39308 | $charObj = $self->session->currentChar; | ||
| 39309 | |||
| 39310 | # If the character is not already alive... | ||
| 39311 | if ($charObj && $charObj->lifeStatus ne 'alive') { | ||
| 39312 | |||
| 39313 | $charObj->ivPoke('lifeStatus', 'alive'); | ||
| 39314 | |||
| 39315 | # The next time the task window is updated, its background colour will change | ||
| 39316 | $self->ivPoke('lifeStatusChangeFlag', TRUE); | ||
| 39317 | } | ||
| 39318 | |||
| 39319 | return 1; | ||
| 39320 | } | ||
| 39321 | |||
| 39322 | sub deadSeen { | ||
| 39323 | |||
| 39324 | # Called by GA::Session->checkTriggers | ||
| 39325 | # | ||
| 39326 | # This task's ->resetTriggers function creates some triggers to capture character death | ||
| 39327 | # strings. Group substrings and ->propertyHash aren't used | ||
| 39328 | # | ||
| 39329 | # Updates some IVs, writes to the logfile which monitors character deaths, and plays a | ||
| 39330 | # sound effect (if allowed) | ||
| 39331 | # | ||
| 39332 | # Expected arguments (standard args from GA::Session->checkTriggers) | ||
| 39333 | # $session - The calling function's GA::Session | ||
| 39334 | # $interfaceNum - The number of the active trigger interface that fired | ||
| 39335 | # $line - The line of text received from the world | ||
| 39336 | # $stripLine - $line, with all escape sequences removed | ||
| 39337 | # $modLine - $stripLine, possibly modified by previously-checked triggers | ||
| 39338 | # $grpStringListRef | ||
| 39339 | # - Reference to a list of group substrings from the pattern match | ||
| 39340 | # (equivalent of @_) | ||
| 39341 | # $matchMinusListRef | ||
| 39342 | # - Reference to a list of matched substring offsets (equivalent of @-) | ||
| 39343 | # $matchPlusListRef | ||
| 39344 | # - Reference to a list of matched substring offsets (equivalent of @+) | ||
| 39345 | # | ||
| 39346 | # Return values | ||
| 39347 | # 'undef' on improper arguments, or if $session is the wrong session or if the interface | ||
| 39348 | # object can't be found | ||
| 39349 | # 1 otherwise | ||
| 39350 | |||
| 39351 | my ( | ||
| 39352 | $self, $session, $interfaceNum, $line, $stripLine, $modLine, $grpStringListRef, | ||
| 39353 | $matchMinusListRef, $matchPlusListRef, $check, | ||
| 39354 | ) = @_; | ||
| 39355 | |||
| 39356 | # Local variables | ||
| 39357 | my ( | ||
| 39358 | $obj, $charObj, $start, $stop, | ||
| 39359 | @writeList, | ||
| 39360 | ); | ||
| 39361 | |||
| 39362 | # Check for improper arguments | ||
| 39363 | if ( | ||
| 39364 | ! defined $session || ! defined $interfaceNum || ! defined $line || ! defined $stripLine | ||
| 39365 | || ! defined $modLine || ! defined $grpStringListRef || ! defined $matchMinusListRef | ||
| 39366 | || ! defined $matchPlusListRef || defined $check | ||
| 39367 | ) { | ||
| 39368 | return $axmud::CLIENT->writeImproper($self->_objClass . '->deadSeen', @_); | ||
| 39369 | } | ||
| 39370 | |||
| 39371 | # Basic check - the trigger should belong to the right session | ||
| 39372 | if ($session ne $self->session) { | ||
| 39373 | |||
| 39374 | return undef; | ||
| 39375 | } | ||
| 39376 | |||
| 39377 | # Get the interface object itself | ||
| 39378 | $obj = $session->ivShow('interfaceNumHash', $interfaceNum); | ||
| 39379 | if (! $obj) { | ||
| 39380 | |||
| 39381 | return undef; | ||
| 39382 | } | ||
| 39383 | |||
| 39384 | # Respond to the fired trigger | ||
| 39385 | |||
| 39386 | # Import the current character profile | ||
| 39387 | $charObj = $self->session->currentChar; | ||
| 39388 | |||
| 39389 | # If the character is not already dead... | ||
| 39390 | if ($charObj->lifeStatus ne 'dead') { | ||
| 39391 | |||
| 39392 | $charObj->ivPoke('lifeStatus', 'dead'); | ||
| 39393 | |||
| 39394 | # The next time the task window is updated, its background colour will change | ||
| 39395 | $self->ivPoke('lifeStatusChangeFlag', TRUE); | ||
| 39396 | |||
| 39397 | if ($session->currentWorld->ivShow('logPrefHash', 'dead')) { | ||
| 39398 | |||
| 39399 | # Record lines that lead up to this event, and mark future lines to be recorded | ||
| 39400 | push (@writeList, 'CHARACTER DEATH DETECTED'); | ||
| 39401 | push (@writeList, '------------------------'); | ||
| 39402 | |||
| 39403 | if ($axmud::CLIENT->statusEventBeforeCount && $session->displayBufferCount) { | ||
| 39404 | |||
| 39405 | if ($session->displayBufferCount < $axmud::CLIENT->statusEventBeforeCount) { | ||
| 39406 | |||
| 39407 | $start = 0, | ||
| 39408 | $stop = $session->displayBufferLast; | ||
| 39409 | |||
| 39410 | } else { | ||
| 39411 | |||
| 39412 | $start = $session->displayBufferLast | ||
| 39413 | - $axmud::CLIENT->statusEventBeforeCount + 1; | ||
| 39414 | $stop = $session->displayBufferLast; | ||
| 39415 | } | ||
| 39416 | |||
| 39417 | for (my $lineNum = $start; $lineNum <= $stop; $lineNum++) { | ||
| 39418 | |||
| 39419 | my $bufferObj = $session->ivShow('displayBufferHash', $lineNum); | ||
| 39420 | |||
| 39421 | if ($session->ivExists('displayBufferHash', $lineNum)) { | ||
| 39422 | |||
| 39423 | push (@writeList, $bufferObj->modLine); | ||
| 39424 | } | ||
| 39425 | } | ||
| 39426 | } | ||
| 39427 | |||
| 39428 | # Write previously-received lines to the logfile (if possible) | ||
| 39429 | foreach my $string (@writeList) { | ||
| 39430 | |||
| 39431 | $axmud::CLIENT->writeLog( | ||
| 39432 | $session, | ||
| 39433 | FALSE, # Not a 'standard' logfile | ||
| 39434 | $string, | ||
| 39435 | FALSE, # Don't precede with a newline character | ||
| 39436 | TRUE, # Use final newline character | ||
| 39437 | 'dead', # Write to this logfile | ||
| 39438 | ); | ||
| 39439 | } | ||
| 39440 | |||
| 39441 | # Mark how many lines after the current one should be written to the same logfile | ||
| 39442 | if ($axmud::CLIENT->statusEventAfterCount) { | ||
| 39443 | |||
| 39444 | $session->set_logDeadUntilLine( | ||
| 39445 | $session->displayBufferLast + $axmud::CLIENT->statusEventAfterCount, | ||
| 39446 | ); | ||
| 39447 | } | ||
| 39448 | } | ||
| 39449 | |||
| 39450 | # Play a sound effect (if allowed) | ||
| 39451 | $axmud::CLIENT->playSound('death'); | ||
| 39452 | |||
| 39453 | # If there is a current mission, it must be told to give up | ||
| 39454 | if ($session->currentMission) { | ||
| 39455 | |||
| 39456 | $session->currentMission->statusTaskChange($charObj->lifeStatus); | ||
| 39457 | } | ||
| 39458 | } | ||
| 39459 | |||
| 39460 | return 1; | ||
| 39461 | } | ||
| 39462 | |||
| 39463 | sub resurrectedSeen { | ||
| 39464 | |||
| 39465 | # Called by GA::Session->checkTriggers | ||
| 39466 | # | ||
| 39467 | # This task's ->resetTriggers function creates some triggers to capture character | ||
| 39468 | # resurrection strings. Group substrings and ->propertyHash aren't used. | ||
| 39469 | # | ||
| 39470 | # Updates some IVs and writes to the logfile which monitors character resurrections | ||
| 39471 | # | ||
| 39472 | # Expected arguments (standard args from GA::Session->checkTriggers) | ||
| 39473 | # $session - The calling function's GA::Session | ||
| 39474 | # $interfaceNum - The number of the active trigger interface that fired | ||
| 39475 | # $line - The line of text received from the world | ||
| 39476 | # $stripLine - $line, with all escape sequences removed | ||
| 39477 | # $modLine - $stripLine, possibly modified by previously-checked triggers | ||
| 39478 | # $grpStringListRef | ||
| 39479 | # - Reference to a list of group substrings from the pattern match | ||
| 39480 | # (equivalent of @_) | ||
| 39481 | # $matchMinusListRef | ||
| 39482 | # - Reference to a list of matched substring offsets (equivalent of @-) | ||
| 39483 | # $matchPlusListRef | ||
| 39484 | # - Reference to a list of matched substring offsets (equivalent of @+) | ||
| 39485 | # | ||
| 39486 | # Return values | ||
| 39487 | # 'undef' on improper arguments, or if $session is the wrong session or if the interface | ||
| 39488 | # object can't be found | ||
| 39489 | # 1 otherwise | ||
| 39490 | |||
| 39491 | my ( | ||
| 39492 | $self, $session, $interfaceNum, $line, $stripLine, $modLine, $grpStringListRef, | ||
| 39493 | $matchMinusListRef, $matchPlusListRef, $check, | ||
| 39494 | ) = @_; | ||
| 39495 | |||
| 39496 | # Local variables | ||
| 39497 | my ($obj, $charObj); | ||
| 39498 | |||
| 39499 | # Check for improper arguments | ||
| 39500 | if ( | ||
| 39501 | ! defined $session || ! defined $interfaceNum || ! defined $line || ! defined $stripLine | ||
| 39502 | || ! defined $modLine || ! defined $grpStringListRef || ! defined $matchMinusListRef | ||
| 39503 | || ! defined $matchPlusListRef || defined $check | ||
| 39504 | ) { | ||
| 39505 | return $axmud::CLIENT->writeImproper($self->_objClass . '->resurrectedSeen', @_); | ||
| 39506 | } | ||
| 39507 | |||
| 39508 | # Basic check - the trigger should belong to the right session | ||
| 39509 | if ($session ne $self->session) { | ||
| 39510 | |||
| 39511 | return undef; | ||
| 39512 | } | ||
| 39513 | |||
| 39514 | # Get the interface object itself | ||
| 39515 | $obj = $session->ivShow('interfaceNumHash', $interfaceNum); | ||
| 39516 | if (! $obj) { | ||
| 39517 | |||
| 39518 | return undef; | ||
| 39519 | } | ||
| 39520 | |||
| 39521 | # Respond to the fired trigger | ||
| 39522 | |||
| 39523 | # Import the current character profile | ||
| 39524 | $charObj = $self->session->currentChar; | ||
| 39525 | |||
| 39526 | # If the character is not already alive... | ||
| 39527 | if ($charObj && $charObj->lifeStatus ne 'alive') { | ||
| 39528 | |||
| 39529 | $charObj->ivPoke('lifeStatus', 'alive'); | ||
| 39530 | |||
| 39531 | # The next time the task window is updated, its background colour will change | ||
| 39532 | $self->ivPoke('lifeStatusChangeFlag', TRUE); | ||
| 39533 | } | ||
| 39534 | |||
| 39535 | return 1; | ||
| 39536 | } | ||
| 39537 | |||
| 39538 | ################## | ||
| 39539 | # Accessors - set | ||
| 39540 | |||
| 39541 | sub set_cashValues { | ||
| 39542 | |||
| 39543 | # Called by GA::Task::Inventory->updateQuestStats | ||
| 39544 | # Sets the Status task's cash IVs | ||
| 39545 | # | ||
| 39546 | # Expected arguments | ||
| 39547 | # $type - Which type of pattern the Inventory task spotted: 'purse', 'deposit', | ||
| 39548 | # 'deposit_only', 'withdraw', 'withdraw_only', 'balance', 'empty_purse' | ||
| 39549 | # or 'empty_bank' | ||
| 39550 | # $cashValue - The equivalent cash value, in the standard denomination specified by the | ||
| 39551 | # current world profile, of the pattern | ||
| 39552 | # | ||
| 39553 | # Return values | ||
| 39554 | # 'undef' on improper arguments or if there is no current character profile | ||
| 39555 | # 1 on success | ||
| 39556 | |||
| 39557 | my ($self, $type, $cashValue, $check) = @_; | ||
| 39558 | |||
| 39559 | # Local variables | ||
| 39560 | my ($charObj, $purse, $bank, $string); | ||
| 39561 | |||
| 39562 | # Check for improper arguments | ||
| 39563 | if ( | ||
| 39564 | ! defined $type || ! defined $cashValue | ||
| 39565 | || ( | ||
| 39566 | $type ne 'purse' | ||
| 39567 | && $type ne 'deposit' | ||
| 39568 | && $type ne 'deposit_only' | ||
| 39569 | && $type ne 'withdraw' | ||
| 39570 | && $type ne 'withdraw_only' | ||
| 39571 | && $type ne 'balance' | ||
| 39572 | && $type ne 'empty_purse' | ||
| 39573 | && $type ne 'empty_bank' | ||
| 39574 | ) || defined $check | ||
| 39575 | ) { | ||
| 39576 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_cashValues', @_); | ||
| 39577 | } | ||
| 39578 | |||
| 39579 | # Import the current character profile (for convenience) | ||
| 39580 | $charObj = $self->session->currentChar; | ||
| 39581 | if (! $charObj) { | ||
| 39582 | |||
| 39583 | return undef; | ||
| 39584 | } | ||
| 39585 | |||
| 39586 | # Prevent Perl rounding errors by rounding the value (if the world profile's | ||
| 39587 | # ->currencyRounding is set to -1, we don't round anything) | ||
| 39588 | $cashValue = $self->roundCashValue($cashValue); | ||
| 39589 | # Get the current purse contents/bank balance, using a zero value if they're not defined | ||
| 39590 | $purse = $charObj->purseContents; | ||
| 39591 | if (! defined $purse) { | ||
| 39592 | |||
| 39593 | $purse = 0; | ||
| 39594 | } | ||
| 39595 | |||
| 39596 | $bank = $charObj->bankBalance; | ||
| 39597 | if (! defined $bank) { | ||
| 39598 | |||
| 39599 | $bank = 0; | ||
| 39600 | } | ||
| 39601 | |||
| 39602 | if ($type eq 'empty_purse') { | ||
| 39603 | |||
| 39604 | # Character is carrying no money | ||
| 39605 | $self->setValue('purse_contents', 0); | ||
| 39606 | |||
| 39607 | } elsif ($type eq 'empty_bank') { | ||
| 39608 | |||
| 39609 | # Bank account is empty | ||
| 39610 | $self->setValue('bank_balance', 0); | ||
| 39611 | |||
| 39612 | } elsif ($type eq 'purse') { | ||
| 39613 | |||
| 39614 | # The character is carrying this much money | ||
| 39615 | $self->setValue('purse_contents', $cashValue); | ||
| 39616 | |||
| 39617 | } elsif ($type eq 'withdraw') { | ||
| 39618 | |||
| 39619 | # The character has withdrawn some money from their bank account | ||
| 39620 | $self->setValue('bank_balance', ($bank - $cashValue)); | ||
| 39621 | $self->setValue('purse_contents', ($purse + $cashValue)); | ||
| 39622 | # Play a sound effect (if allowed) | ||
| 39623 | $axmud::CLIENT->playSound('withdraw'); | ||
| 39624 | |||
| 39625 | } elsif ($type eq 'withdraw_only') { | ||
| 39626 | |||
| 39627 | # The character has withdrawn some money from their bank account, but we only update the | ||
| 39628 | # ->purseContents | ||
| 39629 | $self->setValue('purse_contents', ($purse + $cashValue)); | ||
| 39630 | # Play a sound effect (if allowed) | ||
| 39631 | $axmud::CLIENT->playSound('withdraw'); | ||
| 39632 | |||
| 39633 | } elsif ($type eq 'deposit') { | ||
| 39634 | |||
| 39635 | # The character has withdrawn some money from their bank account | ||
| 39636 | $self->setValue('bank_balance', ($bank + $cashValue)); | ||
| 39637 | $self->setValue('purse_contents', ($purse - $cashValue)); | ||
| 39638 | # Play a sound effect (if allowed) | ||
| 39639 | $axmud::CLIENT->playSound('deposit'); | ||
| 39640 | |||
| 39641 | } elsif ($type eq 'deposit_only') { | ||
| 39642 | |||
| 39643 | # The character has withdrawn some money from their bank account, but we only update the | ||
| 39644 | # ->purseContents | ||
| 39645 | $self->setValue('purse_contents', ($purse - $cashValue)); | ||
| 39646 | # Play a sound effect (if allowed) | ||
| 39647 | $axmud::CLIENT->playSound('deposit'); | ||
| 39648 | |||
| 39649 | } elsif ($type eq 'balance') { | ||
| 39650 | |||
| 39651 | # The character has this much money in their bank account | ||
| 39652 | $self->setValue('bank_balance', $cashValue); | ||
| 39653 | } | ||
| 39654 | |||
| 39655 | return 1; | ||
| 39656 | } | ||
| 39657 | |||
| 39658 | sub reset_counters { | ||
| 39659 | |||
| 39660 | # Called by GA::Cmd::ResetCounter->do | ||
| 39661 | # Resets some or all of the Status task's temporary counters | ||
| 39662 | # | ||
| 39663 | # Expected arguments | ||
| 39664 | # @list - A list of single-letter strings specifying which counters to reset: | ||
| 39665 | # 'a' for all counters | ||
| 39666 | # 'f' for the fight counter, 'i' for the interaction counter, 'x' for the xp | ||
| 39667 | # counter | ||
| 39668 | # 'q' for the quest counter, 'm' for the bank and purse counters, 'b' for the | ||
| 39669 | # bank counter, 'p' for the purse counter | ||
| 39670 | # | ||
| 39671 | # Return values | ||
| 39672 | # 'undef' on improper arguments or if no current character profile is set | ||
| 39673 | # 1 on success | ||
| 39674 | |||
| 39675 | my ($self, @list) = @_; | ||
| 39676 | |||
| 39677 | # Local variables | ||
| 39678 | my $charObj; | ||
| 39679 | |||
| 39680 | # Check for improper arguments | ||
| 39681 | if (! @list) { | ||
| 39682 | |||
| 39683 | return $axmud::CLIENT->writeImproper($self->_objClass . '->reset_counters', @_); | ||
| 39684 | } | ||
| 39685 | |||
| 39686 | # Import the current character profile (for convenience) | ||
| 39687 | $charObj = $self->session->currentChar; | ||
| 39688 | if (! $charObj) { | ||
| 39689 | |||
| 39690 | return undef; | ||
| 39691 | } | ||
| 39692 | |||
| 39693 | foreach my $counter (@list) { | ||
| 39694 | |||
| 39695 | if ($counter eq 'a' || $counter eq 'f') { | ||
| 39696 | |||
| 39697 | $self->ivPoke('fightCountFlag', TRUE); | ||
| 39698 | |||
| 39699 | $self->ivAdd('counterVarHash', 'temp_fight_count', 0); | ||
| 39700 | $self->ivAdd('counterBaseHash', 'temp_fight_count', $charObj->fightCount); | ||
| 39701 | |||
| 39702 | $self->ivAdd('counterVarHash', 'temp_kill_count', 0); | ||
| 39703 | $self->ivAdd('counterBaseHash', 'temp_kill_count', $charObj->killCount); | ||
| 39704 | |||
| 39705 | $self->ivAdd('counterVarHash', 'temp_wimpy_count', 0); | ||
| 39706 | $self->ivAdd('counterBaseHash', 'temp_wimpy_count', $charObj->wimpyCount); | ||
| 39707 | |||
| 39708 | $self->ivAdd('counterVarHash', 'temp_fight_defeat_count', 0); | ||
| 39709 | $self->ivAdd('counterBaseHash', ' | ||
| 39710 | temp_fight_defeat_count', | ||
| 39711 | $charObj->fightDefeatCount, | ||
| 39712 | ); | ||
| 39713 | } | ||
| 39714 | |||
| 39715 | if ($counter eq 'a' || $counter eq 'i') { | ||
| 39716 | |||
| 39717 | $self->ivPoke('interactCountFlag', TRUE); | ||
| 39718 | |||
| 39719 | $self->ivAdd('counterVarHash', 'temp_interact_count', 0); | ||
| 39720 | $self->ivAdd('counterBaseHash', 'temp_interact_count', $charObj->interactCount); | ||
| 39721 | |||
| 39722 | $self->ivAdd('counterVarHash', 'temp_interact_success_count', 0); | ||
| 39723 | $self->ivAdd( | ||
| 39724 | 'counterBaseHash', | ||
| 39725 | 'temp_interact_success_count', | ||
| 39726 | $charObj->interactSuccessCount, | ||
| 39727 | ); | ||
| 39728 | |||
| 39729 | $self->ivAdd('counterVarHash', 'temp_interact_fail_count', 0); | ||
| 39730 | $self->ivAdd( | ||
| 39731 | 'counterBaseHash', | ||
| 39732 | 'temp_interact_fail_count', | ||
| 39733 | $charObj->interactFailCount, | ||
| 39734 | ); | ||
| 39735 | |||
| 39736 | $self->ivAdd('counterVarHash', 'temp_interact_fight_count', 0); | ||
| 39737 | $self->ivAdd( | ||
| 39738 | 'counterBaseHash', | ||
| 39739 | 'temp_interact_fight_count', | ||
| 39740 | $charObj->interactFightCount, | ||
| 39741 | ); | ||
| 39742 | |||
| 39743 | $self->ivAdd('counterVarHash', 'temp_interact_disaster_count', 0); | ||
| 39744 | $self->ivAdd( | ||
| 39745 | 'counterBaseHash', | ||
| 39746 | 'temp_interact_disaster_count', | ||
| 39747 | $charObj->interactDisasterCount, | ||
| 39748 | ); | ||
| 39749 | } | ||
| 39750 | |||
| 39751 | if ($counter eq 'a' || $counter eq 'f' || $counter eq 'i') { | ||
| 39752 | |||
| 39753 | $self->ivAdd('counterVarHash', 'temp_flee_count', 0); | ||
| 39754 | $self->ivAdd('counterBaseHash', 'temp_flee_count', $charObj->fleeCount); | ||
| 39755 | |||
| 39756 | $self->ivAdd('counterVarHash', 'temp_escape_count', 0); | ||
| 39757 | $self->ivAdd('counterBaseHash', 'temp_escape_count', $charObj->escapeCount); | ||
| 39758 | } | ||
| 39759 | |||
| 39760 | if ($counter eq 'a' || $counter eq 'x') { | ||
| 39761 | |||
| 39762 | $self->ivAdd('counterVarHash', 'temp_xp_count', 0); | ||
| 39763 | |||
| 39764 | if (defined $charObj->xpTotal) { | ||
| 39765 | $self->ivAdd('counterBaseHash', 'temp_xp_count', $charObj->xpTotal); | ||
| 39766 | } else { | ||
| 39767 | $self->ivAdd('counterBaseHash', 'temp_xp_count', 0); | ||
| 39768 | } | ||
| 39769 | } | ||
| 39770 | |||
| 39771 | if ($counter eq 'a' || $counter eq 'q') { | ||
| 39772 | |||
| 39773 | $self->ivAdd('counterVarHash', 'temp_quest_count', 0); | ||
| 39774 | |||
| 39775 | if (defined $charObj->qpTotal) { | ||
| 39776 | $self->ivAdd('counterBaseHash', 'temp_quest_count', $charObj->qpTotal); | ||
| 39777 | } else { | ||
| 39778 | $self->ivAdd('counterBaseHash', 'temp_quest_count', 0); | ||
| 39779 | } | ||
| 39780 | } | ||
| 39781 | |||
| 39782 | if ($counter eq 'a' || $counter eq 'm' || $counter eq 'b') { | ||
| 39783 | |||
| 39784 | $self->ivAdd('counterVarHash', 'temp_bank_count', 0); | ||
| 39785 | |||
| 39786 | if (defined $charObj->bankBalance) { | ||
| 39787 | $self->ivAdd('counterBaseHash', 'temp_bank_count', $charObj->bankBalance); | ||
| 39788 | } else { | ||
| 39789 | $self->ivAdd('counterBaseHash', 'temp_bank_count', 0); | ||
| 39790 | } | ||
| 39791 | } | ||
| 39792 | |||
| 39793 | if ($counter eq 'a' || $counter eq 'm' || $counter eq 'p') { | ||
| 39794 | |||
| 39795 | $self->ivAdd('counterVarHash', 'temp_purse_count', 0); | ||
| 39796 | |||
| 39797 | if (defined $charObj->purseContents) { | ||
| 39798 | $self->ivAdd('counterBaseHash', 'temp_purse_count', $charObj->purseContents); | ||
| 39799 | } else { | ||
| 39800 | $self->ivAdd('counterBaseHash', 'temp_purse_count', 0); | ||
| 39801 | } | ||
| 39802 | } | ||
| 39803 | |||
| 39804 | if ($counter eq 'a' || $counter eq 'f' || $counter eq 'i') { | ||
| 39805 | |||
| 39806 | $self->ivPoke('counterStartTime', $self->session->sessionTime); | ||
| 39807 | } | ||
| 39808 | } | ||
| 39809 | |||
| 39810 | # Update the task window | ||
| 39811 | $self->ivPoke('updateFlag', TRUE); | ||
| 39812 | |||
| 39813 | # Reset complete | ||
| 39814 | return 1; | ||
| 39815 | } | ||
| 39816 | |||
| 39817 | sub inc_fightCount { | ||
| 39818 | |||
| 39819 | my ($self, $check) = @_; | ||
| 39820 | |||
| 39821 | # Local variables | ||
| 39822 | my $charObj; | ||
| 39823 | |||
| 39824 | # Check for improper arguments | ||
| 39825 | if (defined $check) { | ||
| 39826 | |||
| 39827 | return $axmud::CLIENT->writeImproper($self->_objClass . '->inc_fightCount', @_); | ||
| 39828 | } | ||
| 39829 | |||
| 39830 | $charObj = $self->session->currentChar; | ||
| 39831 | if ($charObj) { | ||
| 39832 | |||
| 39833 | # These are fixed variables, so update the current character profile directly | ||
| 39834 | $charObj->ivIncrement('fightCount'); | ||
| 39835 | $charObj->ivIncrement('killCount'); | ||
| 39836 | |||
| 39837 | # Update counters (if the right counter is running) | ||
| 39838 | if ($self->fightCountFlag) { | ||
| 39839 | |||
| 39840 | $self->ivIncHash('counterVarHash', 'temp_fight_count'); | ||
| 39841 | $self->ivIncHash('counterVarHash', 'temp_kill_count'); | ||
| 39842 | } | ||
| 39843 | |||
| 39844 | # Update the task window | ||
| 39845 | $self->ivPoke('updateFlag', TRUE); | ||
| 39846 | } | ||
| 39847 | |||
| 39848 | return 1; | ||
| 39849 | } | ||
| 39850 | |||
| 39851 | sub add_fights { | ||
| 39852 | |||
| 39853 | my ($self, $fightCount, $killCount, $wimpyCount, $fightDefeatCount, $check) = @_; | ||
| 39854 | |||
| 39855 | # Local variables | ||
| 39856 | my $charObj; | ||
| 39857 | |||
| 39858 | # Check for improper arguments | ||
| 39859 | if ( | ||
| 39860 | ! defined $fightCount || ! defined $killCount || ! defined $wimpyCount | ||
| 39861 | || ! defined $fightDefeatCount || defined $check | ||
| 39862 | ) { | ||
| 39863 | return $axmud::CLIENT->writeImproper($self->_objClass . '->add_fights', @_); | ||
| 39864 | } | ||
| 39865 | |||
| 39866 | $charObj = $self->session->currentChar; | ||
| 39867 | if ($charObj) { | ||
| 39868 | |||
| 39869 | # These are fixed variables, so update the current character profile directly | ||
| 39870 | $charObj->ivPoke('fightCount', $charObj->fightCount + $fightCount); | ||
| 39871 | $charObj->ivPoke('killCount', $charObj->killCount + $killCount); | ||
| 39872 | $charObj->ivPoke('wimpyCount', $charObj->wimpyCount + $wimpyCount); | ||
| 39873 | $charObj->ivPoke('fightDefeatCount', $charObj->fightDefeatCount + $fightDefeatCount); | ||
| 39874 | |||
| 39875 | # Update counters (if the right counter is running) | ||
| 39876 | if ($self->fightCountFlag) { | ||
| 39877 | |||
| 39878 | $self->ivAdd( | ||
| 39879 | 'counterVarHash', | ||
| 39880 | 'temp_fight_count', | ||
| 39881 | $self->ivShow('counterVarHash', 'temp_fight_count') + $fightCount, | ||
| 39882 | ); | ||
| 39883 | |||
| 39884 | $self->ivAdd( | ||
| 39885 | 'counterVarHash', | ||
| 39886 | 'temp_kill_count', | ||
| 39887 | $self->ivShow('counterVarHash', 'temp_kill_count') + $killCount, | ||
| 39888 | ); | ||
| 39889 | |||
| 39890 | $self->ivAdd( | ||
| 39891 | 'counterVarHash', | ||
| 39892 | 'temp_wimpy_count', | ||
| 39893 | $self->ivShow('counterVarHash', 'temp_wimpy_count') + $wimpyCount, | ||
| 39894 | ); | ||
| 39895 | |||
| 39896 | $self->ivAdd( | ||
| 39897 | 'counterVarHash', | ||
| 39898 | 'temp_fight_defeat_count', | ||
| 39899 | $self->ivShow('counterVarHash', 'temp_fight_defeat_count') + $fightDefeatCount, | ||
| 39900 | ); | ||
| 39901 | } | ||
| 39902 | |||
| 39903 | # Update the task window | ||
| 39904 | $self->ivPoke('updateFlag', TRUE); | ||
| 39905 | } | ||
| 39906 | |||
| 39907 | return 1; | ||
| 39908 | } | ||
| 39909 | |||
| 39910 | sub add_fleesEscapes { | ||
| 39911 | |||
| 39912 | my ($self, $fleeCount, $escapeCount, $check) = @_; | ||
| 39913 | |||
| 39914 | # Local variables | ||
| 39915 | my $charObj; | ||
| 39916 | |||
| 39917 | # Check for improper arguments | ||
| 39918 | if (! defined $fleeCount || ! defined $escapeCount || defined $check) { | ||
| 39919 | |||
| 39920 | return $axmud::CLIENT->writeImproper($self->_objClass . '->add_fleesEscapes', @_); | ||
| 39921 | } | ||
| 39922 | |||
| 39923 | $charObj = $self->session->currentChar; | ||
| 39924 | if ($charObj) { | ||
| 39925 | |||
| 39926 | # These are fixed variables, so update the current character profile directly | ||
| 39927 | $charObj->ivPoke('fleeCount', $charObj->fleeCount + $fleeCount); | ||
| 39928 | $charObj->ivPoke('escapeCount', $charObj->escapeCount + $escapeCount); | ||
| 39929 | |||
| 39930 | # Update counters (if the right counter is running) | ||
| 39931 | if ($self->ivExists('counterVarHash', 'temp_escape_count')) { | ||
| 39932 | |||
| 39933 | $self->ivAdd( | ||
| 39934 | 'counterVarHash', | ||
| 39935 | 'temp_escape_count', | ||
| 39936 | $self->ivShow('counterVarHash', 'temp_escape_count') + $escapeCount, | ||
| 39937 | ); | ||
| 39938 | } | ||
| 39939 | |||
| 39940 | if ($self->ivExists('counterVarHash', 'temp_flee_count')) { | ||
| 39941 | |||
| 39942 | $self->ivAdd( | ||
| 39943 | 'counterVarHash', | ||
| 39944 | 'temp_flee_count', | ||
| 39945 | $self->ivShow('counterVarHash', 'temp_flee_count') + $fleeCount, | ||
| 39946 | ); | ||
| 39947 | } | ||
| 39948 | |||
| 39949 | # Update the task window | ||
| 39950 | $self->ivPoke('updateFlag', TRUE); | ||
| 39951 | } | ||
| 39952 | |||
| 39953 | return 1; | ||
| 39954 | } | ||
| 39955 | |||
| 39956 | sub set_gaugeFlag { | ||
| 39957 | |||
| 39958 | my ($self, $flag, $check) = @_; | ||
| 39959 | |||
| 39960 | # Check for improper arguments | ||
| 39961 | if (! defined $flag || defined $check) { | ||
| 39962 | |||
| 39963 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_gaugeFlag', @_); | ||
| 39964 | } | ||
| 39965 | |||
| 39966 | if ($flag && ! $self->gaugeFlag) { | ||
| 39967 | |||
| 39968 | $self->ivPoke('gaugeFlag', TRUE); | ||
| 39969 | if ($self->stage >= 2) { | ||
| 39970 | |||
| 39971 | $self->resetGauges(); | ||
| 39972 | } | ||
| 39973 | |||
| 39974 | } elsif (! $flag && $self->gaugeFlag) { | ||
| 39975 | |||
| 39976 | if (defined $self->gaugeLevel) { | ||
| 39977 | |||
| 39978 | $self->gaugeStripObj->removeGaugeLevel($self->session, $self->gaugeLevel); | ||
| 39979 | } | ||
| 39980 | |||
| 39981 | $self->ivPoke('gaugeFlag', FALSE); | ||
| 39982 | $self->ivUndef('gaugeStripObj'); | ||
| 39983 | $self->ivUndef('gaugeLevel'); | ||
| 39984 | $self->ivEmpty('gaugeObjList'); | ||
| 39985 | } | ||
| 39986 | |||
| 39987 | return 1; | ||
| 39988 | } | ||
| 39989 | |||
| 39990 | sub set_gaugeValueFlag { | ||
| 39991 | |||
| 39992 | my ($self, $flag, $check) = @_; | ||
| 39993 | |||
| 39994 | # Check for improper arguments | ||
| 39995 | if (! defined $flag || defined $check) { | ||
| 39996 | |||
| 39997 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_gaugeValueFlag', @_); | ||
| 39998 | } | ||
| 39999 | |||
| 40000 | if ($flag && ! $self->gaugeValueFlag) { | ||
| 40001 | |||
| 40002 | $self->ivPoke('gaugeValueFlag', TRUE); | ||
| 40003 | foreach my $gaugeObj ($self->gaugeObjList) { | ||
| 40004 | |||
| 40005 | $gaugeObj->ivPoke('labelFlag', TRUE); | ||
| 40006 | } | ||
| 40007 | |||
| 40008 | } elsif (! $flag && $self->gaugeFlag) { | ||
| 40009 | |||
| 40010 | $self->ivPoke('gaugeValueFlag', FALSE); | ||
| 40011 | foreach my $gaugeObj ($self->gaugeObjList) { | ||
| 40012 | |||
| 40013 | $gaugeObj->ivPoke('labelFlag', FALSE); | ||
| 40014 | } | ||
| 40015 | } | ||
| 40016 | |||
| 40017 | if ($self->gaugeFlag) { | ||
| 40018 | |||
| 40019 | $self->setGauges(); | ||
| 40020 | } | ||
| 40021 | |||
| 40022 | return 1; | ||
| 40023 | } | ||
| 40024 | |||
| 40025 | sub add_interactions { | ||
| 40026 | |||
| 40027 | my ( | ||
| 40028 | $self, $interactCount, $interactSuccessCount, $interactFailCount, $interactFightCount, | ||
| 40029 | $interactDisasterCount, $check | ||
| 40030 | ) = @_; | ||
| 40031 | |||
| 40032 | # Local variables | ||
| 40033 | my $charObj; | ||
| 40034 | |||
| 40035 | # Check for improper arguments | ||
| 40036 | if ( | ||
| 40037 | ! defined $interactCount || ! defined $interactSuccessCount | ||
| 40038 | || ! defined $interactFailCount || ! defined $interactFightCount | ||
| 40039 | || ! defined $interactDisasterCount || defined $check | ||
| 40040 | ) { | ||
| 40041 | return $axmud::CLIENT->writeImproper($self->_objClass . '->add_interactions', @_); | ||
| 40042 | } | ||
| 40043 | |||
| 40044 | $charObj = $self->session->currentChar; | ||
| 40045 | if ($charObj) { | ||
| 40046 | |||
| 40047 | # These are fixed variables, so update the current character profile directly | ||
| 40048 | $charObj->ivPoke | ||
| 40049 | ('interactCount', | ||
| 40050 | $charObj->interactCount + $interactCount, | ||
| 40051 | ); | ||
| 40052 | |||
| 40053 | $charObj->ivPoke( | ||
| 40054 | 'interactSuccessCount', | ||
| 40055 | $charObj->interactSuccessCount + $interactSuccessCount, | ||
| 40056 | ); | ||
| 40057 | |||
| 40058 | $charObj->ivPoke( | ||
| 40059 | 'interactFailCount', | ||
| 40060 | $charObj->interactFailCount + $interactFailCount, | ||
| 40061 | ); | ||
| 40062 | |||
| 40063 | $charObj->ivPoke( | ||
| 40064 | 'interactFightCount', | ||
| 40065 | $charObj->interactFightCount + $interactFightCount, | ||
| 40066 | ); | ||
| 40067 | |||
| 40068 | $charObj->ivPoke( | ||
| 40069 | 'interactDisasterCount', | ||
| 40070 | $charObj->interactDisasterCount + $interactDisasterCount, | ||
| 40071 | ); | ||
| 40072 | |||
| 40073 | # Update counters (if the right counter is running) | ||
| 40074 | if ($self->interactCountFlag) { | ||
| 40075 | |||
| 40076 | $self->ivAdd( | ||
| 40077 | 'counterVarHash', | ||
| 40078 | 'temp_interact_count', | ||
| 40079 | $self->ivShow('counterVarHash', 'temp_interact_count') + $interactCount, | ||
| 40080 | ); | ||
| 40081 | |||
| 40082 | $self->ivAdd( | ||
| 40083 | 'counterVarHash', | ||
| 40084 | 'temp_interact_success_count', | ||
| 40085 | $self->ivShow('counterVarHash', 'temp_interact_success_count') | ||
| 40086 | + $interactSuccessCount, | ||
| 40087 | ); | ||
| 40088 | |||
| 40089 | $self->ivAdd( | ||
| 40090 | 'counterVarHash', | ||
| 40091 | 'temp_interact_fail_count', | ||
| 40092 | $self->ivShow('counterVarHash', 'temp_interact_fail_count') | ||
| 40093 | + $interactFailCount, | ||
| 40094 | ); | ||
| 40095 | |||
| 40096 | $self->ivAdd( | ||
| 40097 | 'counterVarHash', | ||
| 40098 | 'temp_interact_fight_count', | ||
| 40099 | $self->ivShow('counterVarHash', 'temp_interact_fight_count') | ||
| 40100 | + $interactFightCount, | ||
| 40101 | ); | ||
| 40102 | |||
| 40103 | $self->ivAdd( | ||
| 40104 | 'counterVarHash', | ||
| 40105 | 'temp_interact_disaster_count', | ||
| 40106 | $self->ivShow('counterVarHash', 'temp_interact_disaster_count') | ||
| 40107 | + $interactDisasterCount, | ||
| 40108 | ); | ||
| 40109 | } | ||
| 40110 | |||
| 40111 | |||
| 40112 | # Update the task window | ||
| 40113 | $self->ivPoke('updateFlag', TRUE); | ||
| 40114 | } | ||
| 40115 | |||
| 40116 | return 1; | ||
| 40117 | } | ||
| 40118 | |||
| 40119 | sub inc_interactSuccessCount { | ||
| 40120 | |||
| 40121 | my ($self, $check) = @_; | ||
| 40122 | |||
| 40123 | # Local variables | ||
| 40124 | my $charObj; | ||
| 40125 | |||
| 40126 | # Check for improper arguments | ||
| 40127 | if (defined $check) { | ||
| 40128 | |||
| 40129 | return $axmud::CLIENT->writeImproper( | ||
| 40130 | $self->_objClass . '->inc_interactSuccessCount', | ||
| 40131 | @_, | ||
| 40132 | ); | ||
| 40133 | } | ||
| 40134 | |||
| 40135 | $charObj = $self->session->currentChar; | ||
| 40136 | if ($charObj) { | ||
| 40137 | |||
| 40138 | # These are fixed variables, so update the current character profile directly | ||
| 40139 | $charObj->ivIncrement('interactCount'); | ||
| 40140 | $charObj->ivIncrement('interactSuccessCount'); | ||
| 40141 | |||
| 40142 | # Update counters (if the right counter is running) | ||
| 40143 | if ($self->interactCountFlag) { | ||
| 40144 | |||
| 40145 | $self->ivIncHash('counterVarHash', 'temp_interact_count'); | ||
| 40146 | $self->ivIncHash('counterVarHash', 'temp_interact_success_count'); | ||
| 40147 | } | ||
| 40148 | |||
| 40149 | # Update the task window | ||
| 40150 | $self->ivPoke('updateFlag', TRUE); | ||
| 40151 | } | ||
| 40152 | |||
| 40153 | return 1; | ||
| 40154 | } | ||
| 40155 | |||
| 40156 | sub inc_interactFailCount { | ||
| 40157 | |||
| 40158 | my ($self, $check) = @_; | ||
| 40159 | |||
| 40160 | # Local variables | ||
| 40161 | my $charObj; | ||
| 40162 | |||
| 40163 | # Check for improper arguments | ||
| 40164 | if (defined $check) { | ||
| 40165 | |||
| 40166 | return $axmud::CLIENT->writeImproper($self->_objClass . '->inc_interactFailCount', @_); | ||
| 40167 | } | ||
| 40168 | |||
| 40169 | $charObj = $self->session->currentChar; | ||
| 40170 | if ($charObj) { | ||
| 40171 | |||
| 40172 | # These are fixed variables, so update the current character profile directly | ||
| 40173 | $charObj->ivIncrement('interactCount'); | ||
| 40174 | $charObj->ivIncrement('interactFailCount'); | ||
| 40175 | |||
| 40176 | # Update counters (if the right counter is running) | ||
| 40177 | if ($self->interactCountFlag) { | ||
| 40178 | |||
| 40179 | $self->ivIncHash('counterVarHash', 'temp_interact_count'); | ||
| 40180 | $self->ivIncHash('counterVarHash', 'temp_interact_fail_count'); | ||
| 40181 | } | ||
| 40182 | |||
| 40183 | # Update the task window | ||
| 40184 | $self->ivPoke('updateFlag', TRUE); | ||
| 40185 | } | ||
| 40186 | |||
| 40187 | return 1; | ||
| 40188 | } | ||
| 40189 | |||
| 40190 | sub inc_interactFightCount { | ||
| 40191 | |||
| 40192 | my ($self, $check) = @_; | ||
| 40193 | |||
| 40194 | # Local variables | ||
| 40195 | my $charObj; | ||
| 40196 | |||
| 40197 | # Check for improper arguments | ||
| 40198 | if (defined $check) { | ||
| 40199 | |||
| 40200 | return $axmud::CLIENT->writeImproper($self->_objClass . '->inc_interactFightCount', @_); | ||
| 40201 | } | ||
| 40202 | |||
| 40203 | $charObj = $self->session->currentChar; | ||
| 40204 | if ($charObj) { | ||
| 40205 | |||
| 40206 | # These are fixed variables, so update the current character profile directly | ||
| 40207 | $charObj->ivIncrement('interactCount'); | ||
| 40208 | $charObj->ivIncrement('interactFightCount'); | ||
| 40209 | |||
| 40210 | # Update counters (if the right counter is running) | ||
| 40211 | if ($self->interactCountFlag) { | ||
| 40212 | |||
| 40213 | $self->ivIncHash('counterVarHash', 'temp_interact_count'); | ||
| 40214 | $self->ivIncHash('counterVarHash', 'temp_interact_fight_count'); | ||
| 40215 | } | ||
| 40216 | |||
| 40217 | # Update the task window | ||
| 40218 | $self->ivPoke('updateFlag', TRUE); | ||
| 40219 | } | ||
| 40220 | |||
| 40221 | return 1; | ||
| 40222 | } | ||
| 40223 | |||
| 40224 | sub inc_interactDisasterCount { | ||
| 40225 | |||
| 40226 | my ($self, $check) = @_; | ||
| 40227 | |||
| 40228 | # Local variables | ||
| 40229 | my $charObj; | ||
| 40230 | |||
| 40231 | # Check for improper arguments | ||
| 40232 | if (defined $check) { | ||
| 40233 | |||
| 40234 | return $axmud::CLIENT->writeImproper( | ||
| 40235 | $self->_objClass . '->inc_interactDisasterCount', | ||
| 40236 | @_, | ||
| 40237 | ); | ||
| 40238 | } | ||
| 40239 | |||
| 40240 | $charObj = $self->session->currentChar; | ||
| 40241 | if ($charObj) { | ||
| 40242 | |||
| 40243 | # These are fixed variables, so update the current character profile directly | ||
| 40244 | $charObj->ivIncrement('interactCount'); | ||
| 40245 | $charObj->ivIncrement('interactDisasterCount'); | ||
| 40246 | |||
| 40247 | # Update counters (if the right counter is running) | ||
| 40248 | if ($self->interactCountFlag) { | ||
| 40249 | |||
| 40250 | $self->ivIncHash('counterVarHash', 'temp_interact_count'); | ||
| 40251 | $self->ivIncHash('counterVarHash', 'temp_interact_disaster_count'); | ||
| 40252 | } | ||
| 40253 | |||
| 40254 | # Update the task window | ||
| 40255 | $self->ivPoke('updateFlag', TRUE); | ||
| 40256 | } | ||
| 40257 | |||
| 40258 | # Update the task window | ||
| 40259 | $self->ivPoke('updateFlag', TRUE); | ||
| 40260 | |||
| 40261 | return 1; | ||
| 40262 | } | ||
| 40263 | |||
| 40264 | sub set_lifeStatusChangeFlag { | ||
| 40265 | |||
| 40266 | my ($self, $check) = @_; | ||
| 40267 | |||
| 40268 | # Check for improper arguments | ||
| 40269 | if (defined $check) { | ||
| 40270 | |||
| 40271 | return $axmud::CLIENT->writeImproper( | ||
| 40272 | $self->_objClass . '->set_lifeStatusChangeFlag', | ||
| 40273 | @_, | ||
| 40274 | ); | ||
| 40275 | } | ||
| 40276 | |||
| 40277 | $self->ivPoke('lifeStatusChangeFlag', TRUE); | ||
| 40278 | |||
| 40279 | return 1; | ||
| 40280 | } | ||
| 40281 | |||
| 40282 | sub update_profiles { | ||
| 40283 | |||
| 40284 | my ($self, $check) = @_; | ||
| 40285 | |||
| 40286 | # Check for improper arguments | ||
| 40287 | if (defined $check) { | ||
| 40288 | |||
| 40289 | return $axmud::CLIENT->writeImproper($self->_objClass . '->update_profiles', @_); | ||
| 40290 | } | ||
| 40291 | |||
| 40292 | if ($self->fightCountFlag || $self->interactCountFlag) { | ||
| 40293 | |||
| 40294 | $self->reset_counters('a'); | ||
| 40295 | $self->set_fightCountFlag(FALSE); | ||
| 40296 | $self->set_interactCountFlag(FALSE); | ||
| 40297 | } | ||
| 40298 | |||
| 40299 | return 1; | ||
| 40300 | } | ||
| 40301 | |||
| 40302 | sub set_updateFlag { | ||
| 40303 | |||
| 40304 | my ($self, $flag, $check) = @_; | ||
| 40305 | |||
| 40306 | # Check for improper arguments | ||
| 40307 | if (! defined $flag || defined $check) { | ||
| 40308 | |||
| 40309 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_updateFlag', @_); | ||
| 40310 | } | ||
| 40311 | |||
| 40312 | if ($flag) { | ||
| 40313 | $self->ivPoke('updateFlag', TRUE); | ||
| 40314 | } else { | ||
| 40315 | $self->ivPoke('updateFlag', FALSE); | ||
| 40316 | } | ||
| 40317 | |||
| 40318 | return 1; | ||
| 40319 | } | ||
| 40320 | |||
| 40321 | sub set_updateFromMsdp { | ||
| 40322 | |||
| 40323 | # Called by GA::Session->processMsdpData | ||
| 40324 | # When the server (world) reports an MSDP variable and its value, the session calls this | ||
| 40325 | # function, so that we can update the Status task's variables (where appropriate) | ||
| 40326 | # The task's variables are updated even if the task is disactivated (but only at stage 4) | ||
| 40327 | # | ||
| 40328 | # Expected arguments | ||
| 40329 | # $var - An MSDP variable, e.g. EXPERIENCE | ||
| 40330 | # $val - The corresponding value; may be a scalar, or a list/hash reference | ||
| 40331 | # $flag - Set to TRUE if this is a generic MSDP variable, FALSE if it is a custom | ||
| 40332 | # MSDP variable | ||
| 40333 | # | ||
| 40334 | # Return values | ||
| 40335 | # 'undef' on improper arguments | ||
| 40336 | # 1 on success | ||
| 40337 | |||
| 40338 | my ($self, $var, $val, $flag, $check) = @_; | ||
| 40339 | |||
| 40340 | # Local variables | ||
| 40341 | my ( | ||
| 40342 | $mode, | ||
| 40343 | @list, | ||
| 40344 | %msdpHash, %hash, | ||
| 40345 | ); | ||
| 40346 | |||
| 40347 | # Check for improper arguments | ||
| 40348 | if (! defined $var || ! defined $val || ! defined $flag || defined $check) { | ||
| 40349 | |||
| 40350 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_updateFromMsdp', @_); | ||
| 40351 | } | ||
| 40352 | |||
| 40353 | if ($axmud::CLIENT->debugMsdpFlag) { | ||
| 40354 | |||
| 40355 | $self->session->writeDebug('STATUS MSDP: var ' . $var . ', val ' . $val); | ||
| 40356 | } | ||
| 40357 | |||
| 40358 | # Protect against the world sending nested arrays/tables when we're expecting a scalar | ||
| 40359 | if (ref $val eq 'ARRAY') { | ||
| 40360 | $mode = 'array'; | ||
| 40361 | } elsif (ref $val eq 'HASH') { | ||
| 40362 | $mode = 'hash'; | ||
| 40363 | } else { | ||
| 40364 | $mode = undef; | ||
| 40365 | } | ||
| 40366 | |||
| 40367 | # Import the current world profile's hash of MSDP variabless, in the form | ||
| 40368 | # $msdpHash{MSDP_VARIABLE} = status_task_variable_name | ||
| 40369 | %msdpHash = $self->session->currentWorld->msdpStatusVarHash; | ||
| 40370 | |||
| 40371 | # Deal with any MSDP variables for which the world profile provides a Status task variable | ||
| 40372 | if (exists $msdpHash{$var}) { | ||
| 40373 | |||
| 40374 | $self->setValue($msdpHash{$var}, $val); | ||
| 40375 | # If 'main' window gauges are open, they must be reset, not just redrawn | ||
| 40376 | $self->ivPoke('gaugeResetFlag', TRUE); | ||
| 40377 | |||
| 40378 | # Otherwise, only generic MSDP variables for the categories 'Character', 'Combat' and | ||
| 40379 | # 'World' are used | ||
| 40380 | } elsif ($flag) { | ||
| 40381 | |||
| 40382 | if ($var eq 'AFFECTS') { | ||
| 40383 | |||
| 40384 | # $val should be a list reference; but if it's a scalar, that's ok too (but don't | ||
| 40385 | # accept a hash reference) | ||
| 40386 | if (defined $mode && $mode eq 'array') { | ||
| 40387 | @list = %$val; | ||
| 40388 | } elsif (! $mode) { | ||
| 40389 | push (@list, $val); | ||
| 40390 | } | ||
| 40391 | |||
| 40392 | if (@list) { | ||
| 40393 | |||
| 40394 | # Replace any existing affects in $self->affectHash | ||
| 40395 | foreach my $affect (@list) { | ||
| 40396 | |||
| 40397 | $hash{$affect} = undef; | ||
| 40398 | } | ||
| 40399 | |||
| 40400 | $self->ivPoke('affectHash', %hash); | ||
| 40401 | } | ||
| 40402 | |||
| 40403 | } elsif ($var eq 'ALIGNMENT' && ! $mode) { | ||
| 40404 | $self->setValue('alignment', $val); | ||
| 40405 | } elsif ($var eq 'EXPERIENCE' && ! $mode) { | ||
| 40406 | $self->setValue('xp_current', $val); | ||
| 40407 | } elsif ($var eq 'EXPERIENCE_MAX' && ! $mode) { | ||
| 40408 | $self->setValue('xp_total', $val); | ||
| 40409 | } elsif ($var eq 'EXPERIENCE_TNL' && ! $mode) { | ||
| 40410 | $self->setValue('xp_next_level', $val); | ||
| 40411 | } elsif ($var eq 'EXPERIENCE_TNL_MAX' && ! $mode) { | ||
| 40412 | $self->setValue('xp_total', $val); | ||
| 40413 | } elsif ($var eq 'HEALTH' && ! $mode) { | ||
| 40414 | $self->setValue('health_points', $val); | ||
| 40415 | } elsif ($var eq 'HEALTH_MAX' && ! $mode) { | ||
| 40416 | $self->setValue('health_points_max', $val); | ||
| 40417 | } elsif ($var eq 'LEVEL' && ! $mode) { | ||
| 40418 | $self->setValue('level', $val); | ||
| 40419 | } elsif ($var eq 'MANA' && ! $mode) { | ||
| 40420 | $self->setValue('magic_points', $val); | ||
| 40421 | } elsif ($var eq 'MANA_MAX' && ! $mode) { | ||
| 40422 | $self->setValue('magic_points_max', $val); | ||
| 40423 | } elsif ($var eq 'MONEY' && ! $mode) { | ||
| 40424 | $self->setValue('purse_contents', $val); | ||
| 40425 | } elsif ($var eq 'MOVEMENT' && ! $mode) { | ||
| 40426 | $self->setValue('energy_points', $val); | ||
| 40427 | } elsif ($var eq 'MOVEMENT_MAX' && ! $mode) { | ||
| 40428 | $self->setValue('energy_points_max', $val); | ||
| 40429 | } elsif ($var eq 'OPPONENT_LEVEL' && ! $mode) { | ||
| 40430 | $self->setValue('opp_level', $val); | ||
| 40431 | } elsif ($var eq 'OPPONENT_HEALTH' && ! $mode) { | ||
| 40432 | $self->setValue('opp_health', $val); | ||
| 40433 | } elsif ($var eq 'OPPONENT_HEALTH_MAX' && ! $mode) { | ||
| 40434 | $self->setValue('opp_health_max', $val); | ||
| 40435 | } elsif ($var eq 'OPPONENT_NAME' && ! $mode) { | ||
| 40436 | $self->setValue('opp_name', $val); | ||
| 40437 | } elsif ($var eq 'OPPONENT_STRENGTH' && ! $mode) { | ||
| 40438 | $self->setValue('opp_strength', $val); | ||
| 40439 | } elsif ($var eq 'WORLD_TIME' && ! $mode) { | ||
| 40440 | $self->setValue('time', $val); | ||
| 40441 | } | ||
| 40442 | } | ||
| 40443 | |||
| 40444 | # (Regardless of whether an IV was updated, or not, mark the task window to be updated) | ||
| 40445 | $self->ivPoke('updateFlag', TRUE); | ||
| 40446 | |||
| 40447 | return 1; | ||
| 40448 | } | ||
| 40449 | |||
| 40450 | ################## | ||
| 40451 | # Accessors - task settings - get | ||
| 40452 | |||
| 40453 | # The accessors for task settings are inherited from the generic task | ||
| 40454 | |||
| 40455 | ################## | ||
| 40456 | # Accessors - task parameters - get | ||
| 40457 | |||
| 40458 | sub cmdHash | ||
| 40459 | { my $self = shift; return %{$self->{cmdHash}}; } | ||
| 40460 | sub timerHash | ||
| 40461 | { my $self = shift; return %{$self->{timerHash}}; } | ||
| 40462 | |||
| 40463 | sub updateFlag | ||
| 40464 | { $_[0]->{updateFlag} } | ||
| 40465 | sub lifeStatusChangeFlag | ||
| 40466 | { $_[0]->{lifeStatusChangeFlag} } | ||
| 40467 | sub healthChangeFlag | ||
| 40468 | { $_[0]->{healthChangeFlag} } | ||
| 40469 | sub convertTimeFlag | ||
| 40470 | { $_[0]->{convertTimeFlag} } | ||
| 40471 | |||
| 40472 | sub allowColourFlag | ||
| 40473 | { $_[0]->{allowColourFlag} } | ||
| 40474 | sub aliveColour | ||
| 40475 | { $_[0]->{aliveColour} } | ||
| 40476 | sub alive50Colour | ||
| 40477 | { $_[0]->{alive50Colour} } | ||
| 40478 | sub alive30Colour | ||
| 40479 | { $_[0]->{alive30Colour} } | ||
| 40480 | sub alive10Colour | ||
| 40481 | { $_[0]->{alive10Colour} } | ||
| 40482 | sub asleepColour | ||
| 40483 | { $_[0]->{asleepColour} } | ||
| 40484 | sub passedOutColour | ||
| 40485 | { $_[0]->{passedOutColour} } | ||
| 40486 | sub deadColour | ||
| 40487 | { $_[0]->{deadColour} } | ||
| 40488 | |||
| 40489 | sub constCharVarHash | ||
| 40490 | { my $self = shift; return %{$self->{constCharVarHash}}; } | ||
| 40491 | sub constFixedVarHash | ||
| 40492 | { my $self = shift; return %{$self->{constFixedVarHash}}; } | ||
| 40493 | sub constPseudoVarHash | ||
| 40494 | { my $self = shift; return %{$self->{constPseudoVarHash}}; } | ||
| 40495 | sub constLocalVarHash | ||
| 40496 | { my $self = shift; return %{$self->{constLocalVarHash}}; } | ||
| 40497 | sub constCounterVarHash | ||
| 40498 | { my $self = shift; return %{$self->{constCounterVarHash}}; } | ||
| 40499 | sub constCounterRevHash | ||
| 40500 | { my $self = shift; return %{$self->{constCounterRevHash}}; } | ||
| 40501 | sub constPointHash | ||
| 40502 | { my $self = shift; return %{$self->{constPointHash}}; } | ||
| 40503 | |||
| 40504 | sub localVarHash | ||
| 40505 | { my $self = shift; return %{$self->{localVarHash}}; } | ||
| 40506 | sub customVarHash | ||
| 40507 | { my $self = shift; return %{$self->{customVarHash}}; } | ||
| 40508 | |||
| 40509 | sub counterVarHash | ||
| 40510 | { my $self = shift; return %{$self->{counterVarHash}}; } | ||
| 40511 | sub counterBaseHash | ||
| 40512 | { my $self = shift; return %{$self->{counterBaseHash}}; } | ||
| 40513 | sub fightCountFlag | ||
| 40514 | { $_[0]->{fightCountFlag} } | ||
| 40515 | sub interactCountFlag | ||
| 40516 | { $_[0]->{interactCountFlag} } | ||
| 40517 | sub counterStartTime | ||
| 40518 | { $_[0]->{counterStartTime} } | ||
| 40519 | |||
| 40520 | sub affectHash | ||
| 40521 | { my $self = shift; return %{$self->{affectHash}}; } | ||
| 40522 | sub statHash | ||
| 40523 | { my $self = shift; return %{$self->{statHash}}; } | ||
| 40524 | |||
| 40525 | sub gaugeFlag | ||
| 40526 | { $_[0]->{gaugeFlag} } | ||
| 40527 | sub gaugeStripObj | ||
| 40528 | { $_[0]->{gaugeStripObj} } | ||
| 40529 | sub gaugeLevel | ||
| 40530 | { $_[0]->{gaugeLevel} } | ||
| 40531 | sub gaugeValueFlag | ||
| 40532 | { $_[0]->{gaugeValueFlag} } | ||
| 40533 | sub gaugeObjList | ||
| 40534 | { my $self = shift; return @{$self->{gaugeObjList}}; } | ||
| 40535 | sub gaugeResetFlag | ||
| 40536 | { $_[0]->{gaugeResetFlag} } | ||
| 40537 | |||
| 40538 | sub ttsPointsAlertHash | ||
| 40539 | { my $self = shift; return %{$self->{ttsPointsAlertHash}}; } | ||
| 40540 | sub ttsPointsAlertMsgHash | ||
| 40541 | { my $self = shift; return %{$self->{ttsPointsAlertMsgHash}}; } | ||
| 40542 | sub ttsPointsAlertTypeHash | ||
| 40543 | { my $self = shift; return %{$self->{ttsPointsAlertTypeHash}}; } | ||
| 40544 | } | ||
| 40545 | |||
| 40546 | { package Games::Axmud::Task::System; | ||
| 40547 | |||
| 40548 | use strict; | ||
| 40549 | use warnings; | ||
| 40550 | # use diagnostics; | ||
| 40551 | |||
| 40552 | use Glib qw(TRUE FALSE); | ||
| 40553 | |||
| 40554 | our @ISA = qw(Games::Axmud::Generic::Task Games::Axmud); | ||
| 40555 | |||
| 40556 | ################## | ||
| 40557 | # Constructors | ||
| 40558 | |||
| 40559 | sub new { | ||
| 40560 | |||
| 40561 | # Creates a new instance of the System task | ||
| 40562 | # | ||
| 40563 | # Expected arguments | ||
| 40564 | # $session - The parent GA::Session (not stored as an IV) | ||
| 40565 | # | ||
| 40566 | # Optional arguments | ||
| 40567 | # $taskType - Which tasklist this task is being created into - 'current' for the current | ||
| 40568 | # tasklist (tasks which are actually running now), 'initial' (tasks which | ||
| 40569 | # should be run when the user connects to the world), 'custom' (tasks with | ||
| 40570 | # customised initial parameters, which are run when the user demands). If | ||
| 40571 | # set to 'undef', this is a temporary task, created in order to access the | ||
| 40572 | # default values stored in IVs, that will not be added to any tasklist | ||
| 40573 | # $profName - ($taskType = 'current', when called by $self->clone) Name of the | ||
| 40574 | # profile from whose initial tasklist this task was created ('undef' if | ||
| 40575 | # none) | ||
| 40576 | # - ($taskType = 'initial') name of the profile in whose initial tasklist this | ||
| 40577 | # task will be. If 'undef', the global initial tasklist is used | ||
| 40578 | # - ($taskType = 'custom') 'undef' | ||
| 40579 | # $profCategory | ||
| 40580 | # - ($taskType = 'current', 'initial') which category the profile falls undef | ||
| 40581 | # (i.e. 'world', 'race', 'char', etc, or 'undef' if no profile) | ||
| 40582 | # - ($taskType = 'custom') 'undef' | ||
| 40583 | # $customName | ||
| 40584 | # - ($taskType = 'current', 'initial') 'undef' | ||
| 40585 | # - ($taskType = 'custom') the custom task name, matching a key in | ||
| 40586 | # GA::Session->customTaskHash | ||
| 40587 | # | ||
| 40588 | # Return values | ||
| 40589 | # 'undef' on improper arguments or if the task can't be added to the specified tasklist | ||
| 40590 | # Blessed reference to the newly-created object on success | ||
| 40591 | |||
| 40592 | my ($class, $session, $taskType, $profName, $profCategory, $customName, $check) = @_; | ||
| 40593 | |||
| 40594 | # Check for improper arguments | ||
| 40595 | if (! defined $class || ! defined $session || defined $check) { | ||
| 40596 | |||
| 40597 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 40598 | } | ||
| 40599 | |||
| 40600 | if ($taskType) { | ||
| 40601 | |||
| 40602 | # For initial tasks, check that $profName exists | ||
| 40603 | if ( | ||
| 40604 | $taskType eq 'initial' | ||
| 40605 | && defined $profName | ||
| 40606 | && ! $session->ivExists('profHash', $profName) | ||
| 40607 | ) { | ||
| 40608 | return $session->writeError( | ||
| 40609 | 'Can\'t create new task because \'' . $profName . '\' profile doesn\'t exist', | ||
| 40610 | $class . '->new', | ||
| 40611 | ); | ||
| 40612 | |||
| 40613 | # For custom tasks, check that $customName doesn't already exist | ||
| 40614 | } elsif ( | ||
| 40615 | $taskType eq 'custom' | ||
| 40616 | && $axmud::CLIENT->ivExists('customTaskHash', $customName) | ||
| 40617 | ) { | ||
| 40618 | return $session->writeError( | ||
| 40619 | 'Can\'t create new custom task because \'' . $customName . '\' is already being' | ||
| 40620 | . ' used', | ||
| 40621 | $class . '->new', | ||
| 40622 | ); | ||
| 40623 | |||
| 40624 | } elsif ($taskType ne 'current' && $taskType ne 'initial' && $taskType ne 'custom') { | ||
| 40625 | |||
| 40626 | return $session->writeError( | ||
| 40627 | 'Can\'t create new task because \'' . $taskType . '\' is an invalid tasklist', | ||
| 40628 | $class . '->new', | ||
| 40629 | ); | ||
| 40630 | } | ||
| 40631 | } | ||
| 40632 | |||
| 40633 | # Task settings | ||
| 40634 | my $self = Games::Axmud::Generic::Task->new( | ||
| 40635 | $session, | ||
| 40636 | $taskType, | ||
| 40637 | $profName, | ||
| 40638 | $profCategory, | ||
| 40639 | $customName, | ||
| 40640 | ); | ||
| 40641 | |||
| 40642 | $self->{_objName} = 'system_task'; | ||
| 40643 | $self->{_objClass} = $class; | ||
| 40644 | $self->{_parentFile} = undef; # Set below | ||
| 40645 | $self->{_parentWorld} = undef; # Set below | ||
| 40646 | $self->{_privFlag} = TRUE, # All IVs are private | ||
| 40647 | |||
| 40648 | $self->{name} = 'system_task'; | ||
| 40649 | $self->{prettyName} = 'System'; | ||
| 40650 | $self->{shortName} = 'Sy'; | ||
| 40651 | $self->{shortCutIV} = 'systemTask'; # Axmud built-in jealous task | ||
| 40652 | |||
| 40653 | $self->{category} = 'activity'; | ||
| 40654 | $self->{descrip} = 'Diverts system messages into a new window'; | ||
| 40655 | $self->{jealousyFlag} = TRUE; | ||
| 40656 | $self->{requireLocatorFlag} = FALSE; | ||
| 40657 | $self->{profSensitivityFlag} = FALSE; | ||
| 40658 | $self->{storableFlag} = TRUE; | ||
| 40659 | $self->{delayTime} = 0; | ||
| 40660 | $self->{allowWinFlag} = TRUE; | ||
| 40661 | $self->{requireWinFlag} = TRUE; | ||
| 40662 | $self->{startWithWinFlag} = TRUE; | ||
| 40663 | $self->{winPreferList} = ['pane', 'grid']; | ||
| 40664 | $self->{winmap} = 'basic_fill'; | ||
| 40665 | $self->{winUpdateFunc} = undef; | ||
| 40666 | $self->{tabMode} = 'simple'; | ||
| 40667 | $self->{monochromeFlag} = FALSE; | ||
| 40668 | $self->{noScrollFlag} = FALSE; | ||
| 40669 | $self->{ttsFlag} = FALSE; | ||
| 40670 | $self->{ttsConfig} = undef; | ||
| 40671 | $self->{ttsAttribHash} = {}; | ||
| 40672 | $self->{ttsFlagAttribHash} = {}; | ||
| 40673 | $self->{ttsAlertAttribHash} = {}; | ||
| 40674 | $self->{status} = 'wait_init'; | ||
| 40675 | # $self->{activeFlag} = TRUE; # Task can't be activated/disactivated | ||
| 40676 | |||
| 40677 | # Task parameters | ||
| 40678 | |||
| 40679 | # (Ordinary) system message mode: 'original' - ordinary system messages stay in the 'main' | ||
| 40680 | # window, 'both' - ordinary system messages shown in both the 'main' window and the task | ||
| 40681 | # window, 'task' - ordinary system messages shown only in the task window | ||
| 40682 | $self->{systemMode} = 'both'; | ||
| 40683 | # Error message mode: 'original' - error messages stay in the 'main' window, 'both' - error | ||
| 40684 | # messages shown in both the 'main' window and the task window, 'task' - error messages | ||
| 40685 | # shown only in the task window | ||
| 40686 | $self->{errorMode} = 'both'; | ||
| 40687 | # Warning message mode: 'original' - warning messages stay in the 'main' window, 'both' - | ||
| 40688 | # warning messages shown in both the 'main' window and the task window, 'task' - error | ||
| 40689 | # messages shown only in the task window | ||
| 40690 | $self->{warningMode} = 'both'; | ||
| 40691 | # Debug message mode: 'original' - debug messages stay in the 'main' window, 'both' - debug | ||
| 40692 | # messages shown in both the 'main' window and the task window, 'task' - debug messages | ||
| 40693 | # shown only in the task window | ||
| 40694 | $self->{debugMode} = 'both'; | ||
| 40695 | # Improper arguments mode: 'original' - improper arguments messages stay in the 'main' | ||
| 40696 | # window, 'both' - messages shown in both the 'main' window and the task window, 'task' - | ||
| 40697 | # messages shown only in the task window | ||
| 40698 | $self->{improperMode} = 'both'; | ||
| 40699 | |||
| 40700 | # If set to TRUE, messages are shown in the same colour in both the 'main' and task window. | ||
| 40701 | # If FALSE, the task window uses default colours | ||
| 40702 | $self->{colourFlag} = TRUE; | ||
| 40703 | |||
| 40704 | # Bless task | ||
| 40705 | bless $self, $class; | ||
| 40706 | |||
| 40707 | # For all tasks that aren't temporary... | ||
| 40708 | if ($taskType) { | ||
| 40709 | |||
| 40710 | # Check that the task doesn't belong to a disabled plugin (in which case, it can't be | ||
| 40711 | # added to any current, initial or custom tasklist) | ||
| 40712 | if (! $self->checkPlugins()) { | ||
| 40713 | |||
| 40714 | return undef; | ||
| 40715 | } | ||
| 40716 | |||
| 40717 | # Set the parent file object | ||
| 40718 | $self->setParentFileObj($session, $taskType, $profName, $profCategory); | ||
| 40719 | |||
| 40720 | # Create entries in tasklists, if possible | ||
| 40721 | if (! $self->updateTaskLists($session)) { | ||
| 40722 | |||
| 40723 | return undef; | ||
| 40724 | } | ||
| 40725 | } | ||
| 40726 | |||
| 40727 | # Task creation complete | ||
| 40728 | return $self; | ||
| 40729 | } | ||
| 40730 | |||
| 40731 | sub clone { | ||
| 40732 | |||
| 40733 | # Create a clone of an existing task | ||
| 40734 | # Usually used upon connection to a world, when every task in the initial tasklists must | ||
| 40735 | # be cloned into a new object, representing a task in the current tasklist | ||
| 40736 | # (Also used when cloning a profile object, since all the tasks in its initial tasklist must | ||
| 40737 | # also be cloned) | ||
| 40738 | # | ||
| 40739 | # Expected arguments | ||
| 40740 | # $session - The parent GA::Session (not stored as an IV) | ||
| 40741 | # $taskType - Which tasklist this task is being created into - 'current' for the current | ||
| 40742 | # tasklist (tasks which are actually running now), 'initial' (tasks which | ||
| 40743 | # should be run when the user connects to the world). Custom tasks aren't | ||
| 40744 | # cloned (at the moment) | ||
| 40745 | # | ||
| 40746 | # Optional arguments | ||
| 40747 | # $profName - ($taskType = 'initial') name of the profile in whose initial tasklist the | ||
| 40748 | # existing task is stored | ||
| 40749 | # $profCategory | ||
| 40750 | # - ($taskType = 'initial') which category the profile falls under (i.e. | ||
| 40751 | # 'world', 'race', 'char', etc) | ||
| 40752 | # | ||
| 40753 | # Return values | ||
| 40754 | # 'undef' on improper arguments or if the task can't be cloned | ||
| 40755 | # Blessed reference to the newly-created object on success | ||
| 40756 | |||
| 40757 | my ($self, $session, $taskType, $profName, $profCategory, $check) = @_; | ||
| 40758 | |||
| 40759 | # Check for improper arguments | ||
| 40760 | if ( | ||
| 40761 | ! defined $session || ! defined $taskType || defined $check | ||
| 40762 | || ($taskType ne 'current' && $taskType ne 'initial') | ||
| 40763 | || ($taskType eq 'initial' && (! defined $profName || ! defined $profCategory)) | ||
| 40764 | ) { | ||
| 40765 | return $axmud::CLIENT->writeImproper($self->_objClass . '->clone', @_); | ||
| 40766 | } | ||
| 40767 | |||
| 40768 | # For initial tasks, check that $profName exists | ||
| 40769 | if ( | ||
| 40770 | $taskType eq 'initial' | ||
| 40771 | && defined $profName | ||
| 40772 | && ! $session->ivExists('profHash', $profName) | ||
| 40773 | ) { | ||
| 40774 | return $axmud::CLIENT->writeError( | ||
| 40775 | 'Can\'t create cloned task because \'' . $profName . '\' profile doesn\'t exist', | ||
| 40776 | $self->_objClass . '->clone', | ||
| 40777 | ); | ||
| 40778 | } | ||
| 40779 | |||
| 40780 | # Check that the task doesn't belong to a disabled plugin (in which case, it can't be | ||
| 40781 | # cloned) | ||
| 40782 | if (! $self->checkPlugins()) { | ||
| 40783 | |||
| 40784 | return undef; | ||
| 40785 | } | ||
| 40786 | |||
| 40787 | # Create the new task, using default settings and parameters | ||
| 40788 | my $clone = $self->_objClass->new($session, $taskType, $profName, $profCategory); | ||
| 40789 | |||
| 40790 | # Most of the cloned task's settings have default values, but a few are copied from the | ||
| 40791 | # original | ||
| 40792 | $self->cloneTaskSettings($clone); | ||
| 40793 | |||
| 40794 | # Give the new (cloned) task the same initial parameters as the original one | ||
| 40795 | $clone->{systemMode} = $self->systemMode; | ||
| 40796 | $clone->{errorMode} = $self->errorMode; | ||
| 40797 | $clone->{warningMode} = $self->warningMode; | ||
| 40798 | $clone->{debugMode} = $self->debugMode; | ||
| 40799 | $clone->{improperMode} = $self->improperMode; | ||
| 40800 | |||
| 40801 | $clone->{colourFlag} = $self->colourFlag; | ||
| 40802 | |||
| 40803 | # Cloning complete | ||
| 40804 | return $clone; | ||
| 40805 | } | ||
| 40806 | |||
| 40807 | sub preserve { | ||
| 40808 | |||
| 40809 | # Called by $self->main whenever this task is reset, in order to preserve some if its task | ||
| 40810 | # parameters (but not necessarily all of them) | ||
| 40811 | # | ||
| 40812 | # Expected arguments | ||
| 40813 | # $newTask - The new task which has been created, to which some of this task's instance | ||
| 40814 | # variables might have to be transferred | ||
| 40815 | # | ||
| 40816 | # Return values | ||
| 40817 | # 'undef' on improper arguments, or if $newTask isn't in the GA::Session's current | ||
| 40818 | # tasklist | ||
| 40819 | # 1 on success | ||
| 40820 | |||
| 40821 | my ($self, $newTask, $check) = @_; | ||
| 40822 | |||
| 40823 | # Check for improper arguments | ||
| 40824 | if (! defined $newTask || defined $check) { | ||
| 40825 | |||
| 40826 | return $axmud::CLIENT->writeImproper($self->_objClass . '->preserve', @_); | ||
| 40827 | } | ||
| 40828 | |||
| 40829 | # Check the task is in the current tasklist | ||
| 40830 | if (! $self->session->ivExists('currentTaskHash', $newTask->uniqueName)) { | ||
| 40831 | |||
| 40832 | return $self->writeWarning( | ||
| 40833 | '\'' . $self->uniqueName . '\' task missing from the current tasklist', | ||
| 40834 | $self->_objClass . '->preserve', | ||
| 40835 | ); | ||
| 40836 | } | ||
| 40837 | |||
| 40838 | # Preserve some task parameters (the others are left with their default settings, some of | ||
| 40839 | # which will be re-initialised in stage 2) | ||
| 40840 | |||
| 40841 | # Preserve display modes | ||
| 40842 | $newTask->ivPoke('systemMode', $self->systemMode); | ||
| 40843 | $newTask->ivPoke('errorMode', $self->errorMode); | ||
| 40844 | $newTask->ivPoke('warningMode', $self->warningMode); | ||
| 40845 | $newTask->ivPoke('debugMode', $self->debugMode); | ||
| 40846 | $newTask->ivPoke('improperMode', $self->improperMode); | ||
| 40847 | |||
| 40848 | $newTask->ivPoke('colourFlag', $self->colourFlag); | ||
| 40849 | |||
| 40850 | return 1; | ||
| 40851 | } | ||
| 40852 | |||
| 40853 | # sub setParentFileObj {} # Inherited from generic task | ||
| 40854 | |||
| 40855 | # sub updateTaskLists {} # Inherited from generic task | ||
| 40856 | |||
| 40857 | # sub ttsReadAttrib {} # Inherited from generic task | ||
| 40858 | |||
| 40859 | # sub ttsSwitchFlagAttrib {} # Inherited from generic task | ||
| 40860 | |||
| 40861 | # sub ttsSetAlertAttrib {} # Inherited from generic task | ||
| 40862 | |||
| 40863 | ################## | ||
| 40864 | # Task windows | ||
| 40865 | |||
| 40866 | # sub toggleWin {} # Inherited from generic task | ||
| 40867 | |||
| 40868 | # sub openWin {} # Inherited from generic task | ||
| 40869 | |||
| 40870 | # sub closeWin {} # Inherited from generic task | ||
| 40871 | |||
| 40872 | ################## | ||
| 40873 | # Methods | ||
| 40874 | |||
| 40875 | # sub init {} # Inherited from generic task | ||
| 40876 | |||
| 40877 | sub doInit { | ||
| 40878 | |||
| 40879 | # Called by $self->init, just before the task completes its setup ($self->init) | ||
| 40880 | # | ||
| 40881 | # Expected arguments | ||
| 40882 | # (none besides $self) | ||
| 40883 | # | ||
| 40884 | # Return values | ||
| 40885 | # 'undef' on improper arguments | ||
| 40886 | # 1 otherwise | ||
| 40887 | |||
| 40888 | my ($self, $check) = @_; | ||
| 40889 | |||
| 40890 | # Check for improper arguments | ||
| 40891 | if (defined $check) { | ||
| 40892 | |||
| 40893 | return $axmud::CLIENT->writeImproper($self->_objClass . '->doInit', @_); | ||
| 40894 | } | ||
| 40895 | |||
| 40896 | # GA::Obj::TextView->showSystemText can be called several times to display parts of a | ||
| 40897 | # system message line; for example, to include a link in a part of it | ||
| 40898 | # To make those calls the same in both the 'main' and task windows, we've got to use the | ||
| 40899 | # same setting of ->newLineDefault that 'main' windows use | ||
| 40900 | $self->defaultTabObj->textViewObj->set_newLineDefault('after'); | ||
| 40901 | |||
| 40902 | return 1; | ||
| 40903 | } | ||
| 40904 | |||
| 40905 | # sub doShutdown {} # Inherited from generic task | ||
| 40906 | |||
| 40907 | # sub doReset {} # Inherited from generic task | ||
| 40908 | |||
| 40909 | ################## | ||
| 40910 | # Response methods | ||
| 40911 | |||
| 40912 | sub showSystemText { | ||
| 40913 | |||
| 40914 | # Called by GA::Obj::TextView->showSystemText | ||
| 40915 | # Displays an odrinary system message in the task window (in addition to, or instead of, | ||
| 40916 | # displaying it in the 'main' window) | ||
| 40917 | # | ||
| 40918 | # Expected arguments | ||
| 40919 | # $msg - The system message to display | ||
| 40920 | # | ||
| 40921 | # Optional arguments | ||
| 40922 | # @args - The optional list of arguments supplied to the original | ||
| 40923 | # GA::Obj::TextView->showSystemText call, e.g. ('echo', 'blue') | ||
| 40924 | # | ||
| 40925 | # Return values | ||
| 40926 | # 'undef' | ||
| 40927 | |||
| 40928 | my ($self, $msg, @args) = @_; | ||
| 40929 | |||
| 40930 | # Check for improper arguments | ||
| 40931 | if (! defined $msg) { | ||
| 40932 | |||
| 40933 | return $axmud::CLIENT->writeImproper($self->_objClass . '->showSystemText', @_); | ||
| 40934 | } | ||
| 40935 | |||
| 40936 | # Show the error message | ||
| 40937 | if (! $self->colourFlag) { | ||
| 40938 | return $self->insertText($msg, @args); | ||
| 40939 | } else { | ||
| 40940 | return $self->insertText($msg, $axmud::CLIENT->customShowSystemTextColour, @args); | ||
| 40941 | } | ||
| 40942 | } | ||
| 40943 | |||
| 40944 | sub showError { | ||
| 40945 | |||
| 40946 | # Called by GA::Obj::TextView->showError | ||
| 40947 | # Displays an error message in the task window (in addition to, or instead of, displaying | ||
| 40948 | # it in the 'main' window) | ||
| 40949 | # | ||
| 40950 | # Expected arguments | ||
| 40951 | # $msg - The error message to display | ||
| 40952 | # | ||
| 40953 | # Return values | ||
| 40954 | # 'undef' | ||
| 40955 | |||
| 40956 | my ($self, $msg, $check) = @_; | ||
| 40957 | |||
| 40958 | # Check for improper arguments | ||
| 40959 | if (! defined $msg || defined $check) { | ||
| 40960 | |||
| 40961 | return $axmud::CLIENT->writeImproper($self->_objClass . '->showError', @_); | ||
| 40962 | } | ||
| 40963 | |||
| 40964 | # Show the error message | ||
| 40965 | if (! $self->colourFlag) { | ||
| 40966 | return $self->insertText($msg); | ||
| 40967 | } else { | ||
| 40968 | return $self->insertText($msg, $axmud::CLIENT->customShowErrorColour); | ||
| 40969 | } | ||
| 40970 | } | ||
| 40971 | |||
| 40972 | sub showWarning { | ||
| 40973 | |||
| 40974 | # Called by GA::Obj::TextView->showWarning | ||
| 40975 | # Displays a warning message in the task window (in addition to, or instead of, displaying | ||
| 40976 | # it in the 'main' window) | ||
| 40977 | # | ||
| 40978 | # Expected arguments | ||
| 40979 | # $msg - The warning message to display | ||
| 40980 | # | ||
| 40981 | # Return values | ||
| 40982 | # 'undef' | ||
| 40983 | |||
| 40984 | my ($self, $msg, $check) = @_; | ||
| 40985 | |||
| 40986 | # Check for improper arguments | ||
| 40987 | if (! defined $msg || defined $check) { | ||
| 40988 | |||
| 40989 | return $axmud::CLIENT->writeImproper($self->_objClass . '->showWarning', @_); | ||
| 40990 | } | ||
| 40991 | |||
| 40992 | # Show the warning message | ||
| 40993 | if (! $self->colourFlag) { | ||
| 40994 | return $self->insertText($msg); | ||
| 40995 | } else { | ||
| 40996 | return $self->insertText($msg, $axmud::CLIENT->customShowWarningColour); | ||
| 40997 | } | ||
| 40998 | } | ||
| 40999 | |||
| 41000 | sub showDebug { | ||
| 41001 | |||
| 41002 | # Called by GA::Obj::TextView->showDebug | ||
| 41003 | # Displays a debug message in the task window (in addition to, or instead of, displaying | ||
| 41004 | # it in the 'main' window) | ||
| 41005 | # | ||
| 41006 | # Expected arguments | ||
| 41007 | # $msg - The debug message to display | ||
| 41008 | # | ||
| 41009 | # Return values | ||
| 41010 | # 'undef' | ||
| 41011 | |||
| 41012 | my ($self, $msg, $check) = @_; | ||
| 41013 | |||
| 41014 | # Check for improper arguments | ||
| 41015 | if (! defined $msg || defined $check) { | ||
| 41016 | |||
| 41017 | return $axmud::CLIENT->writeImproper($self->_objClass . '->showDebug', @_); | ||
| 41018 | } | ||
| 41019 | |||
| 41020 | # Show the debug message | ||
| 41021 | if (! $self->colourFlag) { | ||
| 41022 | return $self->insertText($msg); | ||
| 41023 | } else { | ||
| 41024 | return $self->insertText($msg, $axmud::CLIENT->customShowDebugColour); | ||
| 41025 | } | ||
| 41026 | } | ||
| 41027 | |||
| 41028 | sub showImproper { | ||
| 41029 | |||
| 41030 | # Called by GA::Obj::TextView->showImproper | ||
| 41031 | # Displays an improper arguments message in the task window (in addition to, or instead of, | ||
| 41032 | # it in the 'main' window) | ||
| 41033 | # | ||
| 41034 | # Expected arguments | ||
| 41035 | # $msg - The message to display | ||
| 41036 | # | ||
| 41037 | # Return values | ||
| 41038 | # 'undef' | ||
| 41039 | |||
| 41040 | my ($self, $msg, $check) = @_; | ||
| 41041 | |||
| 41042 | # Check for improper arguments | ||
| 41043 | if (! defined $msg || defined $check) { | ||
| 41044 | |||
| 41045 | return $axmud::CLIENT->writeImproper($self->_objClass . '->showImproper', @_); | ||
| 41046 | } | ||
| 41047 | |||
| 41048 | # Show the message | ||
| 41049 | if (! $self->colourFlag) { | ||
| 41050 | return $self->insertText($msg); | ||
| 41051 | } else { | ||
| 41052 | return $self->insertText($msg, $axmud::CLIENT->customShowImproperColour); | ||
| 41053 | } | ||
| 41054 | } | ||
| 41055 | |||
| 41056 | ################## | ||
| 41057 | # Accessors - set | ||
| 41058 | |||
| 41059 | sub set_mode { | ||
| 41060 | |||
| 41061 | # Called by GA::Cmd::SetSystemMode->do | ||
| 41062 | |||
| 41063 | my ($self, $type, $mode, $check) = @_; | ||
| 41064 | |||
| 41065 | # Check for improper arguments | ||
| 41066 | if ( | ||
| 41067 | ! defined $type | ||
| 41068 | || ( | ||
| 41069 | $type ne 'system' && $type ne 'error' && $type ne 'warning' && $type ne 'debug' | ||
| 41070 | && $type ne 'improper' | ||
| 41071 | ) | ||
| 41072 | || ! defined $mode | ||
| 41073 | || ($mode ne 'original' && $mode ne 'both' && $mode ne 'task') | ||
| 41074 | || defined $check | ||
| 41075 | ) { | ||
| 41076 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_mode', @_); | ||
| 41077 | } | ||
| 41078 | |||
| 41079 | # Update IVs | ||
| 41080 | if ($type eq 'system') { | ||
| 41081 | $self->ivPoke('systemMode', $mode); | ||
| 41082 | } elsif ($type eq 'error') { | ||
| 41083 | $self->ivPoke('errorMode', $mode); | ||
| 41084 | } elsif ($type eq 'warning') { | ||
| 41085 | $self->ivPoke('warningMode', $mode); | ||
| 41086 | } elsif ($type eq 'debug') { | ||
| 41087 | $self->ivPoke('debugMode', $mode); | ||
| 41088 | } elsif ($type eq 'improper') { | ||
| 41089 | $self->ivPoke('improperMode', $mode); | ||
| 41090 | } | ||
| 41091 | } | ||
| 41092 | |||
| 41093 | ################## | ||
| 41094 | # Accessors - task settings - get | ||
| 41095 | |||
| 41096 | # The accessors for task settings are inherited from the generic task | ||
| 41097 | |||
| 41098 | ################## | ||
| 41099 | # Accessors - task parameters - get | ||
| 41100 | |||
| 41101 | sub systemMode | ||
| 41102 | { $_[0]->{systemMode} } | ||
| 41103 | sub errorMode | ||
| 41104 | { $_[0]->{errorMode} } | ||
| 41105 | sub warningMode | ||
| 41106 | { $_[0]->{warningMode} } | ||
| 41107 | sub debugMode | ||
| 41108 | { $_[0]->{debugMode} } | ||
| 41109 | sub improperMode | ||
| 41110 | { $_[0]->{improperMode} } | ||
| 41111 | |||
| 41112 | sub colourFlag | ||
| 41113 | { $_[0]->{colourFlag} } | ||
| 41114 | } | ||
| 41115 | |||
| 41116 | { package Games::Axmud::Task::TaskList; | ||
| 41117 | |||
| 41118 | use strict; | ||
| 41119 | use warnings; | ||
| 41120 | # use diagnostics; | ||
| 41121 | |||
| 41122 | use Glib qw(TRUE FALSE); | ||
| 41123 | |||
| 41124 | our @ISA = qw(Games::Axmud::Generic::Task Games::Axmud); | ||
| 41125 | |||
| 41126 | ################## | ||
| 41127 | # Constructors | ||
| 41128 | |||
| 41129 | sub new { | ||
| 41130 | |||
| 41131 | # Creates a new instance of the TaskList task | ||
| 41132 | # | ||
| 41133 | # Expected arguments | ||
| 41134 | # $session - The parent GA::Session (not stored as an IV) | ||
| 41135 | # | ||
| 41136 | # Optional arguments | ||
| 41137 | # $taskType - Which tasklist this task is being created into - 'current' for the current | ||
| 41138 | # tasklist (tasks which are actually running now), 'initial' (tasks which | ||
| 41139 | # should be run when the user connects to the world), 'custom' (tasks with | ||
| 41140 | # customised initial parameters, which are run when the user demands). If | ||
| 41141 | # set to 'undef', this is a temporary task, created in order to access the | ||
| 41142 | # default values stored in IVs, that will not be added to any tasklist | ||
| 41143 | # $profName - ($taskType = 'current', when called by $self->clone) Name of the | ||
| 41144 | # profile from whose initial tasklist this task was created ('undef' if | ||
| 41145 | # none) | ||
| 41146 | # - ($taskType = 'initial') name of the profile in whose initial tasklist this | ||
| 41147 | # task will be. If 'undef', the global initial tasklist is used | ||
| 41148 | # - ($taskType = 'custom') 'undef' | ||
| 41149 | # $profCategory | ||
| 41150 | # - ($taskType = 'current', 'initial') which category the profile falls undef | ||
| 41151 | # (i.e. 'world', 'race', 'char', etc, or 'undef' if no profile) | ||
| 41152 | # - ($taskType = 'custom') 'undef' | ||
| 41153 | # $customName | ||
| 41154 | # - ($taskType = 'current', 'initial') 'undef' | ||
| 41155 | # - ($taskType = 'custom') the custom task name, matching a key in | ||
| 41156 | # GA::Session->customTaskHash | ||
| 41157 | # | ||
| 41158 | # Return values | ||
| 41159 | # 'undef' on improper arguments or if the task can't be added to the specified tasklist | ||
| 41160 | # Blessed reference to the newly-created object on success | ||
| 41161 | |||
| 41162 | my ($class, $session, $taskType, $profName, $profCategory, $customName, $check) = @_; | ||
| 41163 | |||
| 41164 | # Check for improper arguments | ||
| 41165 | if (! defined $class || ! defined $session || defined $check) { | ||
| 41166 | |||
| 41167 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 41168 | } | ||
| 41169 | |||
| 41170 | if ($taskType) { | ||
| 41171 | |||
| 41172 | # For initial tasks, check that $profName exists | ||
| 41173 | if ( | ||
| 41174 | $taskType eq 'initial' | ||
| 41175 | && defined $profName | ||
| 41176 | && ! $session->ivExists('profHash', $profName) | ||
| 41177 | ) { | ||
| 41178 | return $session->writeError( | ||
| 41179 | 'Can\'t create new task because \'' . $profName . '\' profile doesn\'t exist', | ||
| 41180 | $class . '->new', | ||
| 41181 | ); | ||
| 41182 | |||
| 41183 | # For custom tasks, check that $customName doesn't already exist | ||
| 41184 | } elsif ( | ||
| 41185 | $taskType eq 'custom' | ||
| 41186 | && $axmud::CLIENT->ivExists('customTaskHash', $customName) | ||
| 41187 | ) { | ||
| 41188 | return $session->writeError( | ||
| 41189 | 'Can\'t create new custom task because \'' . $customName . '\' is already being' | ||
| 41190 | . ' used', | ||
| 41191 | $class . '->new', | ||
| 41192 | ); | ||
| 41193 | |||
| 41194 | } elsif ($taskType ne 'current' && $taskType ne 'initial' && $taskType ne 'custom') { | ||
| 41195 | |||
| 41196 | return $session->writeError( | ||
| 41197 | 'Can\'t create new task because \'' . $taskType . '\' is an invalid tasklist', | ||
| 41198 | $class . '->new', | ||
| 41199 | ); | ||
| 41200 | } | ||
| 41201 | } | ||
| 41202 | |||
| 41203 | # Task settings | ||
| 41204 | my $self = Games::Axmud::Generic::Task->new( | ||
| 41205 | $session, | ||
| 41206 | $taskType, | ||
| 41207 | $profName, | ||
| 41208 | $profCategory, | ||
| 41209 | $customName, | ||
| 41210 | ); | ||
| 41211 | |||
| 41212 | $self->{_objName} = 'tasklist_task'; | ||
| 41213 | $self->{_objClass} = $class; | ||
| 41214 | $self->{_parentFile} = undef; # Set below | ||
| 41215 | $self->{_parentWorld} = undef; # Set below | ||
| 41216 | $self->{_privFlag} = TRUE, # All IVs are private | ||
| 41217 | |||
| 41218 | $self->{name} = 'tasklist_task'; | ||
| 41219 | $self->{prettyName} = 'TaskList'; | ||
| 41220 | $self->{shortName} = 'Tl'; | ||
| 41221 | $self->{shortCutIV} = 'taskListTask'; # Axmud built-in jealous task | ||
| 41222 | |||
| 41223 | $self->{category} = 'process'; | ||
| 41224 | $self->{descrip} = 'Display a constantly-updated list of current tasks'; | ||
| 41225 | $self->{jealousyFlag} = TRUE; | ||
| 41226 | $self->{requireLocatorFlag} = FALSE; | ||
| 41227 | $self->{profSensitivityFlag} = FALSE; | ||
| 41228 | $self->{storableFlag} = TRUE; | ||
| 41229 | $self->{delayTime} = 0; | ||
| 41230 | $self->{allowWinFlag} = TRUE; | ||
| 41231 | $self->{requireWinFlag} = TRUE; | ||
| 41232 | $self->{startWithWinFlag} = TRUE; | ||
| 41233 | $self->{winPreferList} = ['pane', 'grid']; | ||
| 41234 | $self->{winmap} = 'basic_fill'; | ||
| 41235 | $self->{winUpdateFunc} = undef; | ||
| 41236 | $self->{tabMode} = 'simple'; | ||
| 41237 | $self->{monochromeFlag} = FALSE; | ||
| 41238 | $self->{noScrollFlag} = TRUE; | ||
| 41239 | $self->{ttsFlag} = FALSE; | ||
| 41240 | $self->{ttsConfig} = undef; | ||
| 41241 | $self->{ttsAttribHash} = {}; | ||
| 41242 | $self->{ttsFlagAttribHash} = {}; | ||
| 41243 | $self->{ttsAlertAttribHash} = {}; | ||
| 41244 | $self->{status} = 'wait_init'; | ||
| 41245 | # $self->{activeFlag} = TRUE; # Task can't be activated/disactivated | ||
| 41246 | |||
| 41247 | # Task parameters | ||
| 41248 | # (none for this task) | ||
| 41249 | |||
| 41250 | # Bless task | ||
| 41251 | bless $self, $class; | ||
| 41252 | |||
| 41253 | # For all tasks that aren't temporary... | ||
| 41254 | if ($taskType) { | ||
| 41255 | |||
| 41256 | # Check that the task doesn't belong to a disabled plugin (in which case, it can't be | ||
| 41257 | # added to any current, initial or custom tasklist) | ||
| 41258 | if (! $self->checkPlugins()) { | ||
| 41259 | |||
| 41260 | return undef; | ||
| 41261 | } | ||
| 41262 | |||
| 41263 | # Set the parent file object | ||
| 41264 | $self->setParentFileObj($session, $taskType, $profName, $profCategory); | ||
| 41265 | |||
| 41266 | # Create entries in tasklists, if possible | ||
| 41267 | if (! $self->updateTaskLists($session)) { | ||
| 41268 | |||
| 41269 | return undef; | ||
| 41270 | } | ||
| 41271 | } | ||
| 41272 | |||
| 41273 | # Task creation complete | ||
| 41274 | return $self; | ||
| 41275 | } | ||
| 41276 | |||
| 41277 | # sub clone {} # Inherited from generic task | ||
| 41278 | |||
| 41279 | # sub preserve {} # Inherited from generic task | ||
| 41280 | |||
| 41281 | # sub setParentFileObj {} # Inherited from generic task | ||
| 41282 | |||
| 41283 | # sub updateTaskLists {} # Inherited from generic task | ||
| 41284 | |||
| 41285 | # sub ttsReadAttrib {} # Inherited from generic task | ||
| 41286 | |||
| 41287 | # sub ttsSwitchFlagAttrib {} # Inherited from generic task | ||
| 41288 | |||
| 41289 | # sub ttsSetAlertAttrib {} # Inherited from generic task | ||
| 41290 | |||
| 41291 | ################## | ||
| 41292 | # Task windows | ||
| 41293 | |||
| 41294 | # sub toggleWin {} # Inherited from generic task | ||
| 41295 | |||
| 41296 | # sub openWin {} # Inherited from generic task | ||
| 41297 | |||
| 41298 | # sub closeWin {} # Inherited from generic task | ||
| 41299 | |||
| 41300 | ################## | ||
| 41301 | # Methods | ||
| 41302 | |||
| 41303 | # sub main {} # Inherited from generic task | ||
| 41304 | |||
| 41305 | # sub doShutdown {} # Inherited from generic task | ||
| 41306 | |||
| 41307 | # sub doReset {} # Inherited from generic task | ||
| 41308 | |||
| 41309 | # sub doFirstStage {} # Inherited from generic task | ||
| 41310 | |||
| 41311 | sub doStage { | ||
| 41312 | |||
| 41313 | # Called by $self->main to process all stages (except stage 1) | ||
| 41314 | # | ||
| 41315 | # Expected arguments | ||
| 41316 | # (none besides $self) | ||
| 41317 | # | ||
| 41318 | # Return values | ||
| 41319 | # 'undef' on improper arguments or if this function sets that task's ->status IV to | ||
| 41320 | # 'finished' or sets its ->shutdownFlag to TRUE | ||
| 41321 | # Otherwise, we normally return the new value of $self->stage | ||
| 41322 | |||
| 41323 | my ($self, $check) = @_; | ||
| 41324 | |||
| 41325 | # Check for improper arguments | ||
| 41326 | if (defined $check) { | ||
| 41327 | |||
| 41328 | return $axmud::CLIENT->writeImproper($self->_objClass . '->doStage', @_); | ||
| 41329 | } | ||
| 41330 | |||
| 41331 | if ($self->stage == 2) { | ||
| 41332 | |||
| 41333 | # Stage 2 normally checks that the character has logged in to the world, and then sets | ||
| 41334 | # some IVs to initial values | ||
| 41335 | # There's nothing for the TaskList task to do on stage 2, so move on to the next stage | ||
| 41336 | return $self->ivPoke('stage', 3); | ||
| 41337 | |||
| 41338 | } elsif ($self->stage == 3) { | ||
| 41339 | |||
| 41340 | my @lineList; | ||
| 41341 | |||
| 41342 | # On every spin of the task loop, update the task window (if it is still open) | ||
| 41343 | if ($self->taskWinFlag) { | ||
| 41344 | |||
| 41345 | # Add the header | ||
| 41346 | push (@lineList, | ||
| 41347 | 'TASKLIST (Time ' . sprintf("%.3f", $self->session->sessionTime) . ')', | ||
| 41348 | ); | ||
| 41349 | |||
| 41350 | push (@lineList, ' Task (unique) name Stage Status'); | ||
| 41351 | |||
| 41352 | # Add the remaining lines, one for each task | ||
| 41353 | foreach my $taskName ( | ||
| 41354 | sort {lc($a) cmp lc($b)} ($self->session->ivKeys('currentTaskHash')) | ||
| 41355 | ) { | ||
| 41356 | my ($taskObj, $stage, $column); | ||
| 41357 | |||
| 41358 | # Blessed ref of the task | ||
| 41359 | $taskObj = $self->session->ivShow('currentTaskHash', $taskName); | ||
| 41360 | |||
| 41361 | if ($taskObj->category eq 'process') { | ||
| 41362 | $stage = $taskObj->stage; | ||
| 41363 | } else { | ||
| 41364 | $stage = '-'; | ||
| 41365 | } | ||
| 41366 | |||
| 41367 | if (! defined $stage) { | ||
| 41368 | |||
| 41369 | # Avoids error in sprintf() func below | ||
| 41370 | $stage = ''; | ||
| 41371 | } | ||
| 41372 | |||
| 41373 | if ($taskObj->activeFlag) { | ||
| 41374 | $column = '*'; | ||
| 41375 | } else { | ||
| 41376 | $column = ' '; | ||
| 41377 | } | ||
| 41378 | $column .= substr($taskObj->category, 0, 1); | ||
| 41379 | |||
| 41380 | push (@lineList, | ||
| 41381 | sprintf( | ||
| 41382 | '%-2.2s %-24.24s %-6.6s %-20.20s', | ||
| 41383 | $column, | ||
| 41384 | $taskObj->uniqueName, | ||
| 41385 | $stage, | ||
| 41386 | $taskObj->status, | ||
| 41387 | ), | ||
| 41388 | ); | ||
| 41389 | } | ||
| 41390 | |||
| 41391 | # Display the list in the task window | ||
| 41392 | $self->insertQuick(join("\n", @lineList)); | ||
| 41393 | } | ||
| 41394 | |||
| 41395 | # Repeat this stage indefinitely | ||
| 41396 | return $self->ivPoke('stage', 3); | ||
| 41397 | |||
| 41398 | } else { | ||
| 41399 | |||
| 41400 | # The task stage has somehow been set to an invalid value | ||
| 41401 | return $self->invalidStage(); | ||
| 41402 | } | ||
| 41403 | } | ||
| 41404 | |||
| 41405 | ################## | ||
| 41406 | # Response methods | ||
| 41407 | |||
| 41408 | ################## | ||
| 41409 | # Accessors - set | ||
| 41410 | |||
| 41411 | ################## | ||
| 41412 | # Accessors - task settings - get | ||
| 41413 | |||
| 41414 | # The accessors for task settings are inherited from the generic task | ||
| 41415 | |||
| 41416 | ################## | ||
| 41417 | # Accessors - task parameters - get | ||
| 41418 | |||
| 41419 | # No task parameters | ||
| 41420 | } | ||
| 41421 | |||
| 41422 | { package Games::Axmud::Task::Watch; | ||
| 41423 | |||
| 41424 | use strict; | ||
| 41425 | use warnings; | ||
| 41426 | # use diagnostics; | ||
| 41427 | |||
| 41428 | use Glib qw(TRUE FALSE); | ||
| 41429 | |||
| 41430 | our @ISA = qw(Games::Axmud::Generic::Task Games::Axmud); | ||
| 41431 | |||
| 41432 | ################## | ||
| 41433 | # Constructors | ||
| 41434 | |||
| 41435 | sub new { | ||
| 41436 | |||
| 41437 | # Creates a new instances of the Watch task | ||
| 41438 | # | ||
| 41439 | # Expected arguments | ||
| 41440 | # $session - The parent GA::Session (not stored as an IV) | ||
| 41441 | # | ||
| 41442 | # Optional arguments | ||
| 41443 | # $taskType - Which tasklist this task is being created into - 'current' for the current | ||
| 41444 | # tasklist (tasks which are actually running now), 'initial' (tasks which | ||
| 41445 | # should be run when the user connects to the world), 'custom' (tasks with | ||
| 41446 | # customised initial parameters, which are run when the user demands). If | ||
| 41447 | # set to 'undef', this is a temporary task, created in order to access the | ||
| 41448 | # default values stored in IVs, that will not be added to any tasklist | ||
| 41449 | # $profName - ($taskType = 'current', when called by $self->clone) Name of the | ||
| 41450 | # profile from whose initial tasklist this task was created ('undef' if | ||
| 41451 | # none) | ||
| 41452 | # - ($taskType = 'initial') name of the profile in whose initial tasklist this | ||
| 41453 | # task will be. If 'undef', the global initial tasklist is used | ||
| 41454 | # - ($taskType = 'custom') 'undef' | ||
| 41455 | # $profCategory | ||
| 41456 | # - ($taskType = 'current', 'initial') which category the profile falls undef | ||
| 41457 | # (i.e. 'world', 'race', 'char', etc, or 'undef' if no profile) | ||
| 41458 | # - ($taskType = 'custom') 'undef' | ||
| 41459 | # $customName | ||
| 41460 | # - ($taskType = 'current', 'initial') 'undef' | ||
| 41461 | # - ($taskType = 'custom') the custom task name, matching a key in | ||
| 41462 | # GA::Session->customTaskHash | ||
| 41463 | # | ||
| 41464 | # Return values | ||
| 41465 | # 'undef' on improper arguments or if the task can't be added to the specified tasklist | ||
| 41466 | # Blessed reference to the newly-created object on success | ||
| 41467 | |||
| 41468 | my ($class, $session, $taskType, $profName, $profCategory, $customName, $check) = @_; | ||
| 41469 | |||
| 41470 | # Check for improper arguments | ||
| 41471 | if (! defined $class || ! defined $session || defined $check) { | ||
| 41472 | |||
| 41473 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 41474 | } | ||
| 41475 | |||
| 41476 | if ($taskType) { | ||
| 41477 | |||
| 41478 | # For initial tasks, check that $profName exists | ||
| 41479 | if ( | ||
| 41480 | $taskType eq 'initial' | ||
| 41481 | && defined $profName | ||
| 41482 | && ! $session->ivExists('profHash', $profName) | ||
| 41483 | ) { | ||
| 41484 | return $session->writeError( | ||
| 41485 | 'Can\'t create new task because \'' . $profName . '\' profile doesn\'t exist', | ||
| 41486 | $class . '->new', | ||
| 41487 | ); | ||
| 41488 | |||
| 41489 | # For custom tasks, check that $customName doesn't already exist | ||
| 41490 | } elsif ( | ||
| 41491 | $taskType eq 'custom' | ||
| 41492 | && $axmud::CLIENT->ivExists('customTaskHash', $customName) | ||
| 41493 | ) { | ||
| 41494 | return $session->writeError( | ||
| 41495 | 'Can\'t create new custom task because \'' . $customName . '\' is already being' | ||
| 41496 | . ' used', | ||
| 41497 | $class . '->new', | ||
| 41498 | ); | ||
| 41499 | |||
| 41500 | } elsif ($taskType ne 'current' && $taskType ne 'initial' && $taskType ne 'custom') { | ||
| 41501 | |||
| 41502 | return $session->writeError( | ||
| 41503 | 'Can\'t create new task because \'' . $taskType . '\' is an invalid tasklist', | ||
| 41504 | $class . '->new', | ||
| 41505 | ); | ||
| 41506 | } | ||
| 41507 | } | ||
| 41508 | |||
| 41509 | # Task settings | ||
| 41510 | my $self = Games::Axmud::Generic::Task->new( | ||
| 41511 | $session, | ||
| 41512 | $taskType, | ||
| 41513 | $profName, | ||
| 41514 | $profCategory, | ||
| 41515 | $customName, | ||
| 41516 | ); | ||
| 41517 | |||
| 41518 | $self->{_objName} = 'watch_task'; | ||
| 41519 | $self->{_objClass} = $class; | ||
| 41520 | $self->{_parentFile} = undef; # Set below | ||
| 41521 | $self->{_parentWorld} = undef; # Set below | ||
| 41522 | $self->{_privFlag} = TRUE, # All IVs are private | ||
| 41523 | |||
| 41524 | $self->{name} = 'watch_task'; | ||
| 41525 | $self->{prettyName} = 'Watch'; | ||
| 41526 | $self->{shortName} = 'Wa'; | ||
| 41527 | $self->{shortCutIV} = 'watchTask'; # Axmud built-in jealous task | ||
| 41528 | |||
| 41529 | $self->{category} = 'process'; | ||
| 41530 | $self->{descrip} = 'Displays Channels/Chat/Divert task activity'; | ||
| 41531 | $self->{jealousyFlag} = TRUE; | ||
| 41532 | $self->{requireLocatorFlag} = FALSE; | ||
| 41533 | $self->{profSensitivityFlag} = FALSE; | ||
| 41534 | $self->{storableFlag} = TRUE; | ||
| 41535 | $self->{delayTime} = 0; | ||
| 41536 | $self->{allowWinFlag} = TRUE; | ||
| 41537 | $self->{requireWinFlag} = TRUE; | ||
| 41538 | $self->{startWithWinFlag} = TRUE; | ||
| 41539 | $self->{winPreferList} = ['pane', 'grid']; | ||
| 41540 | $self->{winmap} = 'basic_fill'; | ||
| 41541 | $self->{winUpdateFunc} = undef; | ||
| 41542 | $self->{tabMode} = 'simple'; | ||
| 41543 | $self->{monochromeFlag} = TRUE; | ||
| 41544 | $self->{noScrollFlag} = FALSE; | ||
| 41545 | $self->{ttsFlag} = TRUE; | ||
| 41546 | $self->{ttsConfig} = 'watch'; | ||
| 41547 | $self->{ttsAttribHash} = {}; | ||
| 41548 | $self->{ttsFlagAttribHash} = { | ||
| 41549 | 'watch' => FALSE, | ||
| 41550 | }; | ||
| 41551 | $self->{ttsAlertAttribHash} = {}; | ||
| 41552 | $self->{status} = 'wait_init'; | ||
| 41553 | # $self->{activeFlag} = TRUE; # Task can't be activated/disactivated | ||
| 41554 | |||
| 41555 | # Task parameters | ||
| 41556 | # | ||
| 41557 | # The normal background colour for the window (set when the window is enabled) - set to one | ||
| 41558 | # of Axmud's standard colour tags or 'undef' to use the default colour | ||
| 41559 | $self->{defaultColour} = undef; | ||
| 41560 | # The background colour for the task window changes for a few seconds, every time an update | ||
| 41561 | # is displayed in it. These IVs are set to one of Axmud's standard colour tags | ||
| 41562 | # The colour to use for Channels task activity | ||
| 41563 | $self->{channelsAlertColour} = 'YELLOW'; | ||
| 41564 | # The colour to use for Chat task activity | ||
| 41565 | $self->{chatAlertColour} = 'MAGENTA'; | ||
| 41566 | # The colour to use for Divert task activity | ||
| 41567 | $self->{divertAlertColour} = 'GREEN'; | ||
| 41568 | |||
| 41569 | # When an activity notification is received, how many seconds to use the alert background | ||
| 41570 | # colour | ||
| 41571 | $self->{channelsAlertInterval} = 10; | ||
| 41572 | $self->{chatAlertInterval} = 5; | ||
| 41573 | $self->{divertAlertInterval} = 10; | ||
| 41574 | |||
| 41575 | # When an update is received, the time at which the alert background colour should be | ||
| 41576 | # replaced by the default background colour (matches GA::Session->sessionTime). Usually | ||
| 41577 | # set to 'undef', which means the default background colour is visible | ||
| 41578 | $self->{resetTime} = undef; | ||
| 41579 | # Flag set to TRUE the first time an updated is received (set to FALSE if no update has | ||
| 41580 | # been received) | ||
| 41581 | $self->{firstTextFlag} = FALSE; | ||
| 41582 | |||
| 41583 | # Bless task | ||
| 41584 | bless $self, $class; | ||
| 41585 | |||
| 41586 | # For all tasks that aren't temporary... | ||
| 41587 | if ($taskType) { | ||
| 41588 | |||
| 41589 | # Check that the task doesn't belong to a disabled plugin (in which case, it can't be | ||
| 41590 | # added to any current, initial or custom tasklist) | ||
| 41591 | if (! $self->checkPlugins()) { | ||
| 41592 | |||
| 41593 | return undef; | ||
| 41594 | } | ||
| 41595 | |||
| 41596 | # Set the parent file object | ||
| 41597 | $self->setParentFileObj($session, $taskType, $profName, $profCategory); | ||
| 41598 | |||
| 41599 | # Create entries in tasklists, if possible | ||
| 41600 | if (! $self->updateTaskLists($session)) { | ||
| 41601 | |||
| 41602 | return undef; | ||
| 41603 | } | ||
| 41604 | } | ||
| 41605 | |||
| 41606 | # Task creation complete | ||
| 41607 | return $self; | ||
| 41608 | } | ||
| 41609 | |||
| 41610 | sub clone { | ||
| 41611 | |||
| 41612 | # Create a clone of an existing task | ||
| 41613 | # Usually used upon connection to a world, when every task in the initial tasklists must | ||
| 41614 | # be cloned into a new object, representing a task in the current tasklist | ||
| 41615 | # (Also used when cloning a profile object, since all the tasks in its initial tasklist must | ||
| 41616 | # also be cloned) | ||
| 41617 | # | ||
| 41618 | # Expected arguments | ||
| 41619 | # $session - The parent GA::Session (not stored as an IV) | ||
| 41620 | # $taskType - Which tasklist this task is being created into - 'current' for the current | ||
| 41621 | # tasklist (tasks which are actually running now), 'initial' (tasks which | ||
| 41622 | # should be run when the user connects to the world). Custom tasks aren't | ||
| 41623 | # cloned (at the moment) | ||
| 41624 | # | ||
| 41625 | # Optional arguments | ||
| 41626 | # $profName - ($taskType = 'initial') name of the profile in whose initial tasklist the | ||
| 41627 | # existing task is stored | ||
| 41628 | # $profCategory | ||
| 41629 | # - ($taskType = 'initial') which category the profile falls under (i.e. | ||
| 41630 | # 'world', 'race', 'char', etc) | ||
| 41631 | # | ||
| 41632 | # Return values | ||
| 41633 | # 'undef' on improper arguments | ||
| 41634 | # Blessed reference to the newly-created object on success | ||
| 41635 | |||
| 41636 | my ($self, $session, $taskType, $profName, $profCategory, $check) = @_; | ||
| 41637 | |||
| 41638 | # Check for improper arguments | ||
| 41639 | if ( | ||
| 41640 | ! defined $session || ! defined $taskType || defined $check | ||
| 41641 | || ($taskType ne 'current' && $taskType ne 'initial') | ||
| 41642 | || ($taskType eq 'initial' && (! defined $profName || ! defined $profCategory)) | ||
| 41643 | ) { | ||
| 41644 | return $axmud::CLIENT->writeImproper($self->_objClass . '->clone', @_); | ||
| 41645 | } | ||
| 41646 | |||
| 41647 | # For initial tasks, check that $profName exists | ||
| 41648 | if ( | ||
| 41649 | $taskType eq 'initial' | ||
| 41650 | && defined $profName | ||
| 41651 | && ! $session->ivExists('profHash', $profName) | ||
| 41652 | ) { | ||
| 41653 | return $axmud::CLIENT->writeError( | ||
| 41654 | 'Can\'t create cloned task because \'' . $profName . '\' profile doesn\'t exist', | ||
| 41655 | $self->_objClass . '->clone', | ||
| 41656 | ); | ||
| 41657 | } | ||
| 41658 | |||
| 41659 | # Create the new task, using default settings and parameters | ||
| 41660 | my $clone = $self->_objClass->new($session, $taskType, $profName, $profCategory); | ||
| 41661 | |||
| 41662 | # Most of the cloned task's settings have default values, but a few are copied from the | ||
| 41663 | # original | ||
| 41664 | $self->cloneTaskSettings($clone); | ||
| 41665 | |||
| 41666 | # Give the new (cloned) task the same initial parameters as the original one | ||
| 41667 | $clone->{defaultColour} = $self->defaultColour; | ||
| 41668 | $clone->{channelsAlertColour} = $self->channelsAlertColour; | ||
| 41669 | $clone->{chatAlertColour} = $self->chatAlertColour; | ||
| 41670 | $clone->{divertAlertColour} = $self->divertAlertColour; | ||
| 41671 | |||
| 41672 | $clone->{channelsAlertInterval} = $self->channelsAlertInterval; | ||
| 41673 | $clone->{chatAlertInterval} = $self->chatAlertInterval; | ||
| 41674 | $clone->{divertAlertInterval} = $self->divertAlertInterval; | ||
| 41675 | |||
| 41676 | $clone->{resetTime} = $self->resetTime; | ||
| 41677 | $clone->{firstTextFlag} = $self->firstTextFlag; | ||
| 41678 | |||
| 41679 | # Cloning complete | ||
| 41680 | return $clone; | ||
| 41681 | } | ||
| 41682 | |||
| 41683 | sub preserve { | ||
| 41684 | |||
| 41685 | # Called by $self->main whenever this task is reset, in order to preserve some if its task | ||
| 41686 | # parameters (but not necessarily all of them) | ||
| 41687 | # | ||
| 41688 | # Expected arguments | ||
| 41689 | # $newTask - The new task which has been created, to which some of this task's instance | ||
| 41690 | # variables might have to be transferred | ||
| 41691 | # | ||
| 41692 | # Return values | ||
| 41693 | # 'undef' on improper arguments, or if $newTask isn't in the GA::Session's current | ||
| 41694 | # tasklist | ||
| 41695 | # 1 on success | ||
| 41696 | |||
| 41697 | my ($self, $newTask, $check) = @_; | ||
| 41698 | |||
| 41699 | # Check for improper arguments | ||
| 41700 | if (! defined $newTask || defined $check) { | ||
| 41701 | |||
| 41702 | return $axmud::CLIENT->writeImproper($self->_objClass . '->preserve', @_); | ||
| 41703 | } | ||
| 41704 | |||
| 41705 | # Check the task is in the current tasklist | ||
| 41706 | if (! $self->session->ivExists('currentTaskHash', $newTask->uniqueName)) { | ||
| 41707 | |||
| 41708 | return $self->writeWarning( | ||
| 41709 | '\'' . $self->uniqueName . '\' task missing from the current tasklist', | ||
| 41710 | $self->_objClass . '->preserve', | ||
| 41711 | ); | ||
| 41712 | } | ||
| 41713 | |||
| 41714 | # Preserve some task parameters (the others are left with their default settings, some of | ||
| 41715 | # which will be re-initialised in stage 2) | ||
| 41716 | |||
| 41717 | # Preserve the background colours | ||
| 41718 | $newTask->ivPoke('defaultColour', $self->defaultColour); | ||
| 41719 | $newTask->ivPoke('channelsAlertColour', $self->channelsAlertColour); | ||
| 41720 | $newTask->ivPoke('chatAlertColour', $self->chatAlertColour); | ||
| 41721 | $newTask->ivPoke('divertAlertColour', $self->divertAlertColour); | ||
| 41722 | # Preserve intervals before resetting the background colour | ||
| 41723 | $newTask->ivPoke('channelsAlertInterval', $self->channelsAlertInterval); | ||
| 41724 | $newTask->ivPoke('chatAlertInterval', $self->chatAlertInterval); | ||
| 41725 | $newTask->ivPoke('divertAlertInterval', $self->divertAlertInterval); | ||
| 41726 | |||
| 41727 | return 1; | ||
| 41728 | } | ||
| 41729 | |||
| 41730 | # sub setParentFileObj {} # Inherited from generic task | ||
| 41731 | |||
| 41732 | # sub updateTaskLists {} # Inherited from generic task | ||
| 41733 | |||
| 41734 | # sub ttsReadAttrib {} # Inherited from generic task | ||
| 41735 | |||
| 41736 | # sub ttsSwitchFlagAttrib {} # Inherited from generic task | ||
| 41737 | |||
| 41738 | # sub ttsSetAlertAttrib {} # Inherited from generic task | ||
| 41739 | |||
| 41740 | ################## | ||
| 41741 | # Task windows | ||
| 41742 | |||
| 41743 | # sub toggleWin {} # Inherited from generic task | ||
| 41744 | |||
| 41745 | # sub openWin {} # Inherited from generic task | ||
| 41746 | |||
| 41747 | # sub closeWin {} # Inherited from generic task | ||
| 41748 | |||
| 41749 | ################## | ||
| 41750 | # Methods | ||
| 41751 | |||
| 41752 | # sub main {} # Inherited from generic task | ||
| 41753 | |||
| 41754 | # sub doShutdown {} # Inherited from generic task | ||
| 41755 | |||
| 41756 | sub doReset { | ||
| 41757 | |||
| 41758 | # Called just before the task completes a reset | ||
| 41759 | # For process tasks, called by $self->main. For activity tasks, called by $self->reset | ||
| 41760 | # | ||
| 41761 | # This function does nothing, so tasks that need to do something special during a reset | ||
| 41762 | # should have their own ->doReset function | ||
| 41763 | # | ||
| 41764 | # Expected arguments | ||
| 41765 | # $newTaskObj - The replacement task object | ||
| 41766 | # | ||
| 41767 | # Return values | ||
| 41768 | # 'undef' on improper arguments | ||
| 41769 | # 1 otherwise | ||
| 41770 | |||
| 41771 | my ($self, $newTaskObj, $check) = @_; | ||
| 41772 | |||
| 41773 | # Check for improper arguments | ||
| 41774 | if (! defined $newTaskObj || defined $check) { | ||
| 41775 | |||
| 41776 | return $axmud::CLIENT->writeImproper($self->_objClass . '->doReset', @_); | ||
| 41777 | } | ||
| 41778 | |||
| 41779 | # In case the task window is currently a different colour when the task is reset, set it | ||
| 41780 | # back to the default colour | ||
| 41781 | if ($self->defaultTabObj) { | ||
| 41782 | |||
| 41783 | $self->defaultTabObj->paneObj->applyMonochrome( | ||
| 41784 | $self->defaultTabObj, | ||
| 41785 | $self->defaultColour, | ||
| 41786 | ); | ||
| 41787 | } | ||
| 41788 | |||
| 41789 | return 1; | ||
| 41790 | } | ||
| 41791 | |||
| 41792 | # sub doFirstStage {} # Inherited from generic task | ||
| 41793 | |||
| 41794 | sub doStage { | ||
| 41795 | |||
| 41796 | # Called by $self->main to process all stages (except stage 1) | ||
| 41797 | # | ||
| 41798 | # Expected arguments | ||
| 41799 | # (none besides $self) | ||
| 41800 | # | ||
| 41801 | # Return values | ||
| 41802 | # 'undef' on improper arguments or if this function sets that task's ->status IV to | ||
| 41803 | # 'finished' or sets its ->shutdownFlag to TRUE | ||
| 41804 | # Otherwise, we normally return the new value of $self->stage | ||
| 41805 | |||
| 41806 | my ($self, $check) = @_; | ||
| 41807 | |||
| 41808 | # Check for improper arguments | ||
| 41809 | if (defined $check) { | ||
| 41810 | |||
| 41811 | return $axmud::CLIENT->writeImproper($self->_objClass . '->doStage', @_); | ||
| 41812 | } | ||
| 41813 | |||
| 41814 | if ($self->stage == 2) { | ||
| 41815 | |||
| 41816 | # (Nothing to do; for compatibility with the Divert task, we'll let Stage 3 be the | ||
| 41817 | # repeating loop) | ||
| 41818 | |||
| 41819 | return $self->ivPoke('stage', 3); | ||
| 41820 | |||
| 41821 | } elsif ($self->stage == 3) { | ||
| 41822 | |||
| 41823 | if (defined $self->resetTime && $self->resetTime <= $self->session->sessionTime) { | ||
| 41824 | |||
| 41825 | # The delay, started the last time an update was received, is over. Revert the task | ||
| 41826 | # window to its original background colour | ||
| 41827 | $self->defaultTabObj->paneObj->applyMonochrome( | ||
| 41828 | $self->defaultTabObj, | ||
| 41829 | $self->defaultColour, | ||
| 41830 | ); | ||
| 41831 | |||
| 41832 | $self->ivPoke('resetTime', undef); | ||
| 41833 | } | ||
| 41834 | |||
| 41835 | # Repeat this stage indefinitely | ||
| 41836 | return $self->ivPoke('stage', 3); | ||
| 41837 | |||
| 41838 | } else { | ||
| 41839 | |||
| 41840 | # The task stage has somehow been set to an invalid value | ||
| 41841 | return $self->invalidStage(); | ||
| 41842 | } | ||
| 41843 | } | ||
| 41844 | |||
| 41845 | sub displayText { | ||
| 41846 | |||
| 41847 | # Calledy by GA::Task::Channels->displayText, GA::Task::Chat->writeText or | ||
| 41848 | # GA::Task::Divert->displayText | ||
| 41849 | # Whenever text is displayed in any Channels, Chat or Divert task window, in any session, it | ||
| 41850 | # is sent to this function in every Watch task in every session | ||
| 41851 | # | ||
| 41852 | # Expected arguments | ||
| 41853 | # $type - Calling task type: 'chat', 'channels' or 'divert' | ||
| 41854 | # $world - The calling session's current world | ||
| 41855 | # | ||
| 41856 | # Optional arguments | ||
| 41857 | # $char - The calling session's current character ('undef' if no current character) | ||
| 41858 | # $msg - The message to display. If 'undef', no text is displayed in the task | ||
| 41859 | # window, but the background colour is still changed | ||
| 41860 | # | ||
| 41861 | # Return values | ||
| 41862 | # 'undef' on improper arguments or if the task window isn't open | ||
| 41863 | # 1 otherwise | ||
| 41864 | |||
| 41865 | my ($self, $type, $world, $char, $msg, $check) = @_; | ||
| 41866 | |||
| 41867 | # Local variables | ||
| 41868 | my ($time, $text); | ||
| 41869 | |||
| 41870 | # Check for improper arguments | ||
| 41871 | if ( | ||
| 41872 | ! defined $type || ($type ne 'channels' && $type ne 'chat' && $type ne 'divert') | ||
| 41873 | || ! defined $world || defined $check | ||
| 41874 | ) { | ||
| 41875 | return $axmud::CLIENT->writeImproper($self->_objClass . '->displayText', @_); | ||
| 41876 | } | ||
| 41877 | |||
| 41878 | # Don't do anything if the task window isn't open | ||
| 41879 | if (! $self->taskWinFlag) { | ||
| 41880 | |||
| 41881 | return undef; | ||
| 41882 | } | ||
| 41883 | |||
| 41884 | # Change the task window's background colour, and set the interval at which the background | ||
| 41885 | # colour will revert to the default | ||
| 41886 | if ($type eq 'channels') { | ||
| 41887 | |||
| 41888 | $time = $self->session->sessionTime + $self->channelsAlertInterval; | ||
| 41889 | $self->defaultTabObj->paneObj->applyMonochrome( | ||
| 41890 | $self->defaultTabObj, | ||
| 41891 | $self->channelsAlertColour, | ||
| 41892 | ); | ||
| 41893 | |||
| 41894 | } elsif ($type eq 'chat') { | ||
| 41895 | |||
| 41896 | $time = $self->session->sessionTime + $self->chatAlertInterval; | ||
| 41897 | $self->defaultTabObj->paneObj->applyMonochrome( | ||
| 41898 | $self->defaultTabObj, | ||
| 41899 | $self->chatAlertColour, | ||
| 41900 | ); | ||
| 41901 | |||
| 41902 | } elsif ($type eq 'divert') { | ||
| 41903 | |||
| 41904 | $time = $self->session->sessionTime + $self->divertAlertInterval; | ||
| 41905 | $self->defaultTabObj->paneObj->applyMonochrome( | ||
| 41906 | $self->defaultTabObj, | ||
| 41907 | $self->divertAlertColour, | ||
| 41908 | ); | ||
| 41909 | } | ||
| 41910 | |||
| 41911 | # (Different types of update have different intervals; don't change the time at which | ||
| 41912 | # the window reverts if the new interval finishes before the existing one) | ||
| 41913 | if (! $self->resetTime || $self->resetTime < $time) { | ||
| 41914 | |||
| 41915 | $self->ivPoke('resetTime', $time); | ||
| 41916 | } | ||
| 41917 | |||
| 41918 | # Display the message (if there is one) | ||
| 41919 | $text = ''; | ||
| 41920 | if ($char) { | ||
| 41921 | |||
| 41922 | $text .= $char . '@'; | ||
| 41923 | } | ||
| 41924 | |||
| 41925 | $text .= $world . ': '; | ||
| 41926 | |||
| 41927 | if ($msg) { | ||
| 41928 | $text .= $msg; | ||
| 41929 | } else { | ||
| 41930 | $text .= '<no-text alert>'; | ||
| 41931 | } | ||
| 41932 | |||
| 41933 | if (! $self->firstTextFlag) { | ||
| 41934 | |||
| 41935 | # This is the first message to be displayed in the task window; need to remove any | ||
| 41936 | # holding messages | ||
| 41937 | $self->insertWithLinks($text, 'empty'); | ||
| 41938 | $self->ivPoke('firstTextFlag', TRUE); | ||
| 41939 | |||
| 41940 | } else { | ||
| 41941 | |||
| 41942 | $self->insertWithLinks($text); | ||
| 41943 | } | ||
| 41944 | |||
| 41945 | # Read out a TTS message, if required | ||
| 41946 | if ($self->ivShow('ttsFlagAttribHash', 'watch') && $msg) { | ||
| 41947 | |||
| 41948 | if ($char) { | ||
| 41949 | $text = 'Watch. ' . $char . ' at ' . $world . '. '; | ||
| 41950 | } else { | ||
| 41951 | $text = 'Watch at ' . $world . '. '; | ||
| 41952 | } | ||
| 41953 | |||
| 41954 | $self->ttsQuick($text . $msg); | ||
| 41955 | } | ||
| 41956 | |||
| 41957 | return 1; | ||
| 41958 | } | ||
| 41959 | |||
| 41960 | sub resetWin { | ||
| 41961 | |||
| 41962 | # Called by GA::Cmd::EmptyWatchWindow->do | ||
| 41963 | # Resets the task window - removes any text, and sets the background colour back to the | ||
| 41964 | # default | ||
| 41965 | # | ||
| 41966 | # Expected arguments | ||
| 41967 | # (none besides $self) | ||
| 41968 | # | ||
| 41969 | # Return values | ||
| 41970 | # 'undef' on improper arguments | ||
| 41971 | # 1 otherwise | ||
| 41972 | |||
| 41973 | my ($self, $check) = @_; | ||
| 41974 | |||
| 41975 | # Check for improper arguments | ||
| 41976 | if (defined $check) { | ||
| 41977 | |||
| 41978 | return $axmud::CLIENT->writeImproper($self->_objClass . '->resetWin', @_); | ||
| 41979 | } | ||
| 41980 | |||
| 41981 | if ($self->taskWinFlag) { | ||
| 41982 | |||
| 41983 | # Empty the window of text | ||
| 41984 | $self->clearBuffer(); | ||
| 41985 | |||
| 41986 | # Use the default background colour | ||
| 41987 | if ($self->defaultTabObj) { | ||
| 41988 | |||
| 41989 | $self->defaultTabObj->paneObj->applyMonochrome( | ||
| 41990 | $self->defaultTabObj, | ||
| 41991 | $self->defaultColour, | ||
| 41992 | ); | ||
| 41993 | |||
| 41994 | $self->ivPoke('resetTime', undef); | ||
| 41995 | } | ||
| 41996 | |||
| 41997 | # If the window's urgency hint is set, then reset it | ||
| 41998 | if ($self->winObj) { | ||
| 41999 | |||
| 42000 | $self->winObj->resetUrgent(); | ||
| 42001 | } | ||
| 42002 | } | ||
| 42003 | |||
| 42004 | return 1; | ||
| 42005 | } | ||
| 42006 | |||
| 42007 | ################## | ||
| 42008 | # Accessors - set | ||
| 42009 | |||
| 42010 | ################## | ||
| 42011 | # Accessors - task settings - get | ||
| 42012 | |||
| 42013 | # The accessors for task settings are inherited from the generic task | ||
| 42014 | |||
| 42015 | ################## | ||
| 42016 | # Accessors - task parameters - get | ||
| 42017 | |||
| 42018 | sub defaultColour | ||
| 42019 | { $_[0]->{defaultColour} } | ||
| 42020 | sub channelsAlertColour | ||
| 42021 | { $_[0]->{channelsAlertColour} } | ||
| 42022 | sub chatAlertColour | ||
| 42023 | { $_[0]->{chatAlertColour} } | ||
| 42024 | sub divertAlertColour | ||
| 42025 | { $_[0]->{divertAlertColour} } | ||
| 42026 | |||
| 42027 | sub channelsAlertInterval | ||
| 42028 | { $_[0]->{channelsAlertInterval} } | ||
| 42029 | sub chatAlertInterval | ||
| 42030 | { $_[0]->{chatAlertInterval} } | ||
| 42031 | sub divertAlertInterval | ||
| 42032 | { $_[0]->{divertAlertInterval} } | ||
| 42033 | |||
| 42034 | sub resetTime | ||
| 42035 | { $_[0]->{resetTime} } | ||
| 42036 | sub firstTextFlag | ||
| 42037 | { $_[0]->{firstTextFlag} } | ||
| 42038 | } | ||
| 42039 | |||
| 42040 | # Package must return a true value | ||
| 42041 | 1 |