| 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::Interface::XXX | ||
| 16 | # Code that handles interfaces (triggers, alias, macros, timers and hooks) | ||
| 17 | |||
| 18 | { package Games::Axmud::Interface::Active; | ||
| 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::Interface Games::Axmud); | ||
| 27 | |||
| 28 | ################## | ||
| 29 | # Constructors | ||
| 30 | |||
| 31 | sub new { | ||
| 32 | |||
| 33 | # Called by GA::Session->injectInterface, ->createIndependentInterface and | ||
| 34 | # ->createDependentInterface | ||
| 35 | # Creates a new instance of the active interface object | ||
| 36 | # | ||
| 37 | # Axmud interfaces are triggers, aliases, macros, timers and hooks. Depending on which | ||
| 38 | # profiles are current ones, and how many current profiles have interfaces with the same | ||
| 39 | # name, an interface can be 'active' or 'inactive' and 'independent' or 'dependent' | ||
| 40 | # | ||
| 41 | # 'Independent' interfaces are normally created by the user, and stored in a cage associated | ||
| 42 | # with a particular profile | ||
| 43 | # When a profile becomes a current profile, and provided that there are no other superior | ||
| 44 | # profile which have an interface with the same ->name, each of its interfaces becomes | ||
| 45 | # 'active' | ||
| 46 | # When an interface becomes active, GA::Session creates this object, copying into it the | ||
| 47 | # attributes from the parent GA::Interface::Trigger / ::Alias / ::Macro / ::Timer | ||
| 48 | # / ::Hook object | ||
| 49 | # When the interface becomes inactive again, this object gets destroyed (but the parent | ||
| 50 | # interface continues to exist) | ||
| 51 | # | ||
| 52 | # 'Dependent' interfaces are normally created by parts of the Axmud code immediately before | ||
| 53 | # this object is created. As soon as this object becomes inactive, the parent | ||
| 54 | # dependent interface is destroyed, as well. | ||
| 55 | # | ||
| 56 | # Expected arguments | ||
| 57 | # $session - The GA::Session which created this object | ||
| 58 | # $category - 'trigger', 'alias', 'macro', 'timer' or 'hook' | ||
| 59 | # $indepFlag - TRUE if the interface is 'independent' (when the interface fires, the | ||
| 60 | # response depends on the value of the parent interface's | ||
| 61 | # ->response IV) | ||
| 62 | # - FALSE if the interface is 'dependent' (when the interface fires, the | ||
| 63 | # ->response IV is ignored and, instead, a method call is made) | ||
| 64 | # | ||
| 65 | # Optional arguments | ||
| 66 | # $parent - The inactive interface (a GA::Interface::Trigger etc object) whose | ||
| 67 | # attributes are copied into this one; specified when the calling | ||
| 68 | # function is GA::Session->injectInterface. If 'undef', attributes | ||
| 69 | # must be set by the calling function | ||
| 70 | # $assocProf - The inactive interface's associated profile, specified when the | ||
| 71 | # calling function is GA::Session->injectInterface ('undef' | ||
| 72 | # otherwise) | ||
| 73 | # $assocProfCategory | ||
| 74 | # - If $assocProf is specified, its category ('undef' otherwise) | ||
| 75 | # | ||
| 76 | # | ||
| 77 | # Return values | ||
| 78 | # 'undef' on improper arguments | ||
| 79 | # Blessed reference to the newly-created object on success | ||
| 80 | |||
| 81 | my ( | ||
| 82 | $class, $session, $category, $indepFlag, $parent, $assocProf, $assocProfCategory, | ||
| 83 | $check, | ||
| 84 | ) = @_; | ||
| 85 | |||
| 86 | # Local variables | ||
| 87 | my $modelObj; | ||
| 88 | |||
| 89 | # Check for improper arguments | ||
| 90 | if ( | ||
| 91 | ! defined $class || ! defined $session || ! defined $category || ! defined $indepFlag | ||
| 92 | || defined $check | ||
| 93 | ) { | ||
| 94 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 95 | } | ||
| 96 | |||
| 97 | # Setup | ||
| 98 | my $self = { | ||
| 99 | _objName => 'active_interface', | ||
| 100 | _objClass => $class, | ||
| 101 | _parentFile => undef, # No parent file object | ||
| 102 | _parentWorld => undef, # No parent file object | ||
| 103 | _privFlag => TRUE, # All IVs are private | ||
| 104 | |||
| 105 | # Perl object components | ||
| 106 | # ---------------------- | ||
| 107 | |||
| 108 | # The parent GA::Session object | ||
| 109 | session => $session, | ||
| 110 | # The parent inactive interface (if any) | ||
| 111 | parent => $parent, | ||
| 112 | |||
| 113 | # Interface IVs | ||
| 114 | # ------------- | ||
| 115 | |||
| 116 | # A unique name (within the session) for this active interface (max 32 chars) | ||
| 117 | name => undef, # Set below or by the calling function | ||
| 118 | # The interface's number (matches a key in GA::Session->interfaceNumHash) | ||
| 119 | number => undef, # Set by GA::Session->addInterface | ||
| 120 | # The category of interface ('trigger', 'alias', 'macro', 'timer' or 'hook') | ||
| 121 | category => $category, | ||
| 122 | # TRUE if an independent interface, FALSE if dependent | ||
| 123 | indepFlag => $indepFlag, | ||
| 124 | |||
| 125 | # Standard attributes (inherited from the parent) | ||
| 126 | stimulus => undef, # Set below or by the calling function | ||
| 127 | response => undef, # Set below or by the calling function | ||
| 128 | enabledFlag => undef, # Set below or by the calling function | ||
| 129 | |||
| 130 | # Category-dependent attributes | ||
| 131 | attribHash => {}, # Set below or by the calling function | ||
| 132 | |||
| 133 | # Independent interface IVs | ||
| 134 | # Blessed reference of the associated profile (if any) | ||
| 135 | assocProf => undef, # Set below or by the calling function | ||
| 136 | # The associated profile's category (if there is an associated profile) | ||
| 137 | assocProfCategory => undef, # Set below or by the calling function | ||
| 138 | |||
| 139 | # Dependent interface IVs (used in place of ->response) | ||
| 140 | callClass => undef, # Set by the calling function | ||
| 141 | callMethod => undef, # Set by the calling function | ||
| 142 | |||
| 143 | # A hash of properties, whose keys and values can be set to anything, and checked | ||
| 144 | # by anything when the interface fires | ||
| 145 | propertyHash => {}, | ||
| 146 | }; | ||
| 147 | |||
| 148 | # Bless the object into existence | ||
| 149 | bless $self, $class; | ||
| 150 | |||
| 151 | # If a parent inactive interface was specified, copy its attributes to this object | ||
| 152 | if ($parent) { | ||
| 153 | |||
| 154 | $self->{name} = $parent->name; | ||
| 155 | $self->{stimulus} = $parent->stimulus; | ||
| 156 | $self->{response} = $parent->response; | ||
| 157 | $self->{enabledFlag} = $parent->enabledFlag; | ||
| 158 | |||
| 159 | $self->{attribHash} = {$parent->attribHash}; | ||
| 160 | |||
| 161 | $self->{assocProf} = $assocProf; | ||
| 162 | $self->{assocProfCategory} = $assocProfCategory; | ||
| 163 | |||
| 164 | } else { | ||
| 165 | |||
| 166 | # When there's no parent inactive interface, we need to set ->attribHash (so that the | ||
| 167 | # call from GA::Session->setupInterface to $self->modifyAttribs will work - the rest | ||
| 168 | # of the IVs are set by GA::Session->setupInterface) | ||
| 169 | $modelObj = $axmud::CLIENT->ivShow('interfaceModelHash', $category); | ||
| 170 | $self->{attribHash} = {$modelObj->optionalAttribHash}; | ||
| 171 | } | ||
| 172 | |||
| 173 | return $self; | ||
| 174 | } | ||
| 175 | |||
| 176 | ################## | ||
| 177 | # Methods | ||
| 178 | |||
| 179 | sub becomeEnabled { | ||
| 180 | |||
| 181 | # Called by $self->set_enabledFlag and GA::Generic::Cmd->modifyInterface | ||
| 182 | # When a disabled active timer interface becomes enabled, we need to reset a few IVs | ||
| 183 | # | ||
| 184 | # Expected arguments | ||
| 185 | # (none besides $self) | ||
| 186 | # | ||
| 187 | # Return values | ||
| 188 | # 'undef' on improper arguments | ||
| 189 | # 1 otherwise | ||
| 190 | |||
| 191 | my ($self, $check) = @_; | ||
| 192 | |||
| 193 | # Check for improper arguments | ||
| 194 | if (defined $check) { | ||
| 195 | |||
| 196 | return $axmud::CLIENT->writeImproper($self->_objClass . '->becomeEnabled', @_); | ||
| 197 | } | ||
| 198 | |||
| 199 | if ($self->category eq 'timer') { | ||
| 200 | |||
| 201 | # If the timer fires every second, but has been disabled for 30 seconds, enabling it | ||
| 202 | # will cause the timer to fire 30 times while it tries to catch up | ||
| 203 | # The next firing time should be $self->stimulus seconds after now (actually, | ||
| 204 | # $self->stimulus seconds after the last spin of the timer loop | ||
| 205 | $self->session->ivAdd( | ||
| 206 | 'timerHash', | ||
| 207 | $self->number, | ||
| 208 | ($self->session->sessionTime + $self->stimulus), | ||
| 209 | ); | ||
| 210 | } | ||
| 211 | |||
| 212 | return 1; | ||
| 213 | } | ||
| 214 | |||
| 215 | sub cloneToInactiveInterface { | ||
| 216 | |||
| 217 | # Called by GA::Generic::Cmd->importInterface | ||
| 218 | # Creates an inactive interface, cloning the attributes of this active interface | ||
| 219 | # | ||
| 220 | # Expected arguments | ||
| 221 | # $category - 'trigger', 'alias', 'macro', 'timer' or 'hook' | ||
| 222 | # | ||
| 223 | # Return values | ||
| 224 | # 'undef' on improper arguments, or if $category is invalid | ||
| 225 | # Blessed reference to the newly-created object on success | ||
| 226 | |||
| 227 | my ($self, $category, $check) = @_; | ||
| 228 | |||
| 229 | # Local variables | ||
| 230 | my ($class, $parentFile, $parentWorld); | ||
| 231 | |||
| 232 | # Check for improper arguments | ||
| 233 | if (! defined $category || defined $check) { | ||
| 234 | |||
| 235 | return $axmud::CLIENT->writeImproper( | ||
| 236 | $self->_objClass . '->cloneToInactiveInterface', | ||
| 237 | @_, | ||
| 238 | ); | ||
| 239 | } | ||
| 240 | |||
| 241 | if ($category eq 'trigger') { | ||
| 242 | $class = 'Games::Axmud::Interface::Trigger'; | ||
| 243 | } elsif ($category eq 'alias') { | ||
| 244 | $class = 'Games::Axmud::Interface::Alias'; | ||
| 245 | } elsif ($category eq 'macro') { | ||
| 246 | $class = 'Games::Axmud::Interface::Macro'; | ||
| 247 | } elsif ($category eq 'timer') { | ||
| 248 | $class = 'Games::Axmud::Interface::Timer'; | ||
| 249 | } elsif ($category eq 'hook') { | ||
| 250 | $class = 'Games::Axmud::Interface::Hook'; | ||
| 251 | } else { | ||
| 252 | return undef; | ||
| 253 | } | ||
| 254 | |||
| 255 | if ($self->assocProf) { | ||
| 256 | |||
| 257 | $parentFile = 'otherprof'; | ||
| 258 | $parentWorld = $self->assocProf; | ||
| 259 | } | ||
| 260 | |||
| 261 | # Setup | ||
| 262 | my $clone = { | ||
| 263 | _objName => $self->name, | ||
| 264 | _objClass => $class, | ||
| 265 | _parentFile => $parentFile, | ||
| 266 | _parentWorld => $self->assocProf, | ||
| 267 | _privFlag => TRUE, # All IVs are private | ||
| 268 | |||
| 269 | # Interface category | ||
| 270 | # ------------------ | ||
| 271 | |||
| 272 | category => $category, | ||
| 273 | |||
| 274 | # Standard interface attributes | ||
| 275 | # ----------------------------- | ||
| 276 | |||
| 277 | name => $self->name, | ||
| 278 | stimulus => $self->stimulus, | ||
| 279 | response => $self->response, | ||
| 280 | enabledFlag => $self->enabledFlag, | ||
| 281 | |||
| 282 | # Trigger attributes | ||
| 283 | # ------------------ | ||
| 284 | |||
| 285 | attribHash => {$self->attribHash}, | ||
| 286 | |||
| 287 | # Ordering | ||
| 288 | # -------- | ||
| 289 | |||
| 290 | beforeHash => {}, | ||
| 291 | afterHash => {}, | ||
| 292 | }; | ||
| 293 | |||
| 294 | # Bless the object into existence | ||
| 295 | bless $clone, $class; | ||
| 296 | return $clone; | ||
| 297 | } | ||
| 298 | |||
| 299 | ################## | ||
| 300 | # Accessors - set | ||
| 301 | |||
| 302 | sub set_callClass { | ||
| 303 | |||
| 304 | my ($self, $callClass, $check) = @_; | ||
| 305 | |||
| 306 | # Check for improper arguments | ||
| 307 | if (! defined $callClass || defined $check) { | ||
| 308 | |||
| 309 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_callClass', @_); | ||
| 310 | } | ||
| 311 | |||
| 312 | $self->ivPoke('callClass', $callClass); | ||
| 313 | |||
| 314 | return 1; | ||
| 315 | } | ||
| 316 | |||
| 317 | sub set_callMethod { | ||
| 318 | |||
| 319 | my ($self, $callMethod, $check) = @_; | ||
| 320 | |||
| 321 | # Check for improper arguments | ||
| 322 | if (! defined $callMethod || defined $check) { | ||
| 323 | |||
| 324 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_callMethod', @_); | ||
| 325 | } | ||
| 326 | |||
| 327 | $self->ivPoke('callMethod', $callMethod); | ||
| 328 | |||
| 329 | return 1; | ||
| 330 | } | ||
| 331 | |||
| 332 | sub set_enabledFlag { | ||
| 333 | |||
| 334 | my ($self, $flag, $check) = @_; | ||
| 335 | |||
| 336 | # Check for improper arguments | ||
| 337 | if (! defined $flag || defined $check) { | ||
| 338 | |||
| 339 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_enabledFlag', @_); | ||
| 340 | } | ||
| 341 | |||
| 342 | if ($flag) { | ||
| 343 | |||
| 344 | if (! $self->enabledFlag) { | ||
| 345 | |||
| 346 | # Disabled timers need to have some IVs set when they become enabled | ||
| 347 | $self->becomeEnabled(); | ||
| 348 | } | ||
| 349 | |||
| 350 | $self->ivPoke('enabledFlag', TRUE); | ||
| 351 | |||
| 352 | } else { | ||
| 353 | |||
| 354 | $self->ivPoke('enabledFlag', FALSE); | ||
| 355 | } | ||
| 356 | |||
| 357 | return 1; | ||
| 358 | } | ||
| 359 | |||
| 360 | sub set_number { | ||
| 361 | |||
| 362 | my ($self, $number, $check) = @_; | ||
| 363 | |||
| 364 | # Check for improper arguments | ||
| 365 | if (! defined $number || defined $check) { | ||
| 366 | |||
| 367 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_number', @_); | ||
| 368 | } | ||
| 369 | |||
| 370 | $self->ivPoke('number', $number); | ||
| 371 | |||
| 372 | return 1; | ||
| 373 | } | ||
| 374 | |||
| 375 | sub add_property { | ||
| 376 | |||
| 377 | my ($self, $key, $value, $check) = @_; | ||
| 378 | |||
| 379 | # Check for improper arguments | ||
| 380 | if (! defined $key || ! defined $value || defined $check) { | ||
| 381 | |||
| 382 | return $axmud::CLIENT->writeImproper($self->_objClass . '->add_property', @_); | ||
| 383 | } | ||
| 384 | |||
| 385 | # Update IVs | ||
| 386 | $self->ivAdd('propertyHash', $key, $value); | ||
| 387 | |||
| 388 | return 1; | ||
| 389 | } | ||
| 390 | |||
| 391 | ################## | ||
| 392 | # Accessors - get | ||
| 393 | |||
| 394 | sub session | ||
| 395 | { $_[0]->{session} } | ||
| 396 | sub parent | ||
| 397 | { $_[0]->{parent} } | ||
| 398 | |||
| 399 | sub name | ||
| 400 | { $_[0]->{name} } | ||
| 401 | sub number | ||
| 402 | { $_[0]->{number} } | ||
| 403 | sub category | ||
| 404 | { $_[0]->{category} } | ||
| 405 | sub indepFlag | ||
| 406 | { $_[0]->{indepFlag} } | ||
| 407 | |||
| 408 | sub stimulus | ||
| 409 | { $_[0]->{stimulus} } | ||
| 410 | sub response | ||
| 411 | { $_[0]->{response} } | ||
| 412 | sub enabledFlag | ||
| 413 | { $_[0]->{enabledFlag} } | ||
| 414 | |||
| 415 | sub attribHash | ||
| 416 | { my $self = shift; return %{$self->{attribHash}}; } | ||
| 417 | |||
| 418 | sub assocProf | ||
| 419 | { $_[0]->{assocProf} } | ||
| 420 | sub assocProfCategory | ||
| 421 | { $_[0]->{assocProfCategory} } | ||
| 422 | |||
| 423 | sub callClass | ||
| 424 | { $_[0]->{callClass} } | ||
| 425 | sub callMethod | ||
| 426 | { $_[0]->{callMethod} } | ||
| 427 | |||
| 428 | sub propertyHash | ||
| 429 | { my $self = shift; return %{$self->{propertyHash}}; } | ||
| 430 | } | ||
| 431 | |||
| 432 | { package Games::Axmud::Interface::Trigger; | ||
| 433 | |||
| 434 | use strict; | ||
| 435 | use warnings; | ||
| 436 | # use diagnostics; | ||
| 437 | |||
| 438 | use Glib qw(TRUE FALSE); | ||
| 439 | |||
| 440 | our @ISA = qw(Games::Axmud::Generic::Interface Games::Axmud); | ||
| 441 | |||
| 442 | ################## | ||
| 443 | # Constructors | ||
| 444 | |||
| 445 | sub new { | ||
| 446 | |||
| 447 | # Creates a new instance of the trigger object | ||
| 448 | # | ||
| 449 | # Axmud interfaces are triggers, aliases, macros, timers and hooks. Depending on which | ||
| 450 | # profiles are current ones, and how many current profiles have interfaces with the same | ||
| 451 | # name, an interface can be 'active' or 'inactive' | ||
| 452 | # | ||
| 453 | # This object represents an 'inactive' trigger. It is stored in a cage, attached to a | ||
| 454 | # particular profile | ||
| 455 | # When the profile becomes a current profile, and provided that there are no other superior | ||
| 456 | # profiles which have a trigger with the same ->name, the trigger becomes 'active' | ||
| 457 | # When a trigger becomes active, GA::Session creates a GA::Interface::Active object, copying | ||
| 458 | # it into its registries of active interfaces | ||
| 459 | # When the trigger becomes inactive again, the GA::Interface::Active object is destroyed | ||
| 460 | # (but this object continues to exist throughout) | ||
| 461 | # | ||
| 462 | # Expected arguments | ||
| 463 | # $session - The GA::Session which created this object (not stored as an IV) | ||
| 464 | # $name - A name for the trigger which is unique within its cage, but which | ||
| 465 | # could be the same as the name of other triggers in other cages | ||
| 466 | # (e.g. 'mytrigger') (max 32 chars) | ||
| 467 | # $stimulus - The stimulus (a pattern, for triggers) | ||
| 468 | # $response - The response (an action, for triggers) | ||
| 469 | # | ||
| 470 | # Optional arguments | ||
| 471 | # $enabledFlag - A flag, TRUE if (when the trigger becomes active) it is responsive, | ||
| 472 | # FALSE if it does nothing (if 'undef', the attribute is set to TRUE). | ||
| 473 | # | ||
| 474 | # Return values | ||
| 475 | # 'undef' on improper arguments or if $name, $stimulus, $response or $enabledFlag are | ||
| 476 | # invalid values | ||
| 477 | # Blessed reference to the newly-created object on success | ||
| 478 | |||
| 479 | my ($class, $session, $name, $stimulus, $response, $enabledFlag, $check) = @_; | ||
| 480 | |||
| 481 | # Local variables | ||
| 482 | my $flag; | ||
| 483 | |||
| 484 | # Check for improper arguments | ||
| 485 | if ( | ||
| 486 | ! defined $class || ! defined $session || ! defined $name || ! defined $stimulus | ||
| 487 | || ! defined $response || defined $check | ||
| 488 | ) { | ||
| 489 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 490 | } | ||
| 491 | |||
| 492 | # Translate all values of $enabledFlag into TRUE of FALSE | ||
| 493 | if (! defined $enabledFlag || $enabledFlag) { | ||
| 494 | $flag = TRUE; # Default is TRUE | ||
| 495 | } else { | ||
| 496 | $flag = FALSE; | ||
| 497 | } | ||
| 498 | |||
| 499 | # Setup | ||
| 500 | my $self = { | ||
| 501 | _objName => $name, | ||
| 502 | _objClass => $class, | ||
| 503 | _parentFile => 'otherprof', | ||
| 504 | _parentWorld => $session->currentWorld->name, | ||
| 505 | _privFlag => TRUE, # All IVs are private | ||
| 506 | |||
| 507 | # Interface category | ||
| 508 | # ------------------ | ||
| 509 | |||
| 510 | category => 'trigger', # Shortcut to $self->_objClass | ||
| 511 | |||
| 512 | # Standard interface attributes | ||
| 513 | # ----------------------------- | ||
| 514 | |||
| 515 | name => $name, # Max 32 chars | ||
| 516 | stimulus => $stimulus, # A pattern | ||
| 517 | response => $response, # Instruction (or pattern/substitution) | ||
| 518 | enabledFlag => $flag, | ||
| 519 | |||
| 520 | # Trigger attributes | ||
| 521 | # ------------------ | ||
| 522 | |||
| 523 | # Current values for each trigger attribute (initially set to defaults) | ||
| 524 | attribHash => { | ||
| 525 | 'ignore_response' => FALSE, | ||
| 526 | 'splitter' => FALSE, | ||
| 527 | 'split_after' => FALSE, | ||
| 528 | 'keep_splitting' => FALSE, | ||
| 529 | 'rewriter' => FALSE, | ||
| 530 | 'rewrite_global' => FALSE, | ||
| 531 | 'ignore_case' => TRUE, | ||
| 532 | 'gag' => FALSE, | ||
| 533 | 'gag_log' => FALSE, | ||
| 534 | 'need_prompt' => FALSE, | ||
| 535 | 'need_login' => FALSE, | ||
| 536 | 'keep_checking' => TRUE, | ||
| 537 | 'default_pane' => TRUE, | ||
| 538 | 'pane_name' => '', | ||
| 539 | 'temporary' => FALSE, | ||
| 540 | 'cooldown' => 0, | ||
| 541 | 'style_mode' => 0, | ||
| 542 | 'style_text' => '', | ||
| 543 | 'style_underlay' => '', | ||
| 544 | 'style_italics' => 0, | ||
| 545 | 'style_underline' => 0, | ||
| 546 | 'style_blink_slow' => 0, | ||
| 547 | 'style_blink_fast' => 0, | ||
| 548 | 'style_strike' => 0, | ||
| 549 | 'style_link' => 0, | ||
| 550 | }, | ||
| 551 | |||
| 552 | # Ordering | ||
| 553 | # -------- | ||
| 554 | |||
| 555 | # A hash of inactive trigger names. When this trigger becomes active, all other active | ||
| 556 | # triggers are checked. If their corresponding inactive triggers have names which | ||
| 557 | # appear in this list, then the active trigger corresponding to this object is | ||
| 558 | # placed BEFORE them in the ordered list of active triggers. Hash in the form | ||
| 559 | # $beforeHash{inactive_trigger_name} = undef | ||
| 560 | beforeHash => {}, | ||
| 561 | # Hash of inactive trigger names; if corresponding active triggers exist, this object's | ||
| 562 | # active trigger is placed AFTER them. (NB If ->beforeHash and ->afterHash conflict, | ||
| 563 | # then ->beforeHash is ignored and ->afterHash is used) | ||
| 564 | afterHash => {}, | ||
| 565 | }; | ||
| 566 | |||
| 567 | # Bless the object into existence | ||
| 568 | bless $self, $class; | ||
| 569 | return $self; | ||
| 570 | } | ||
| 571 | |||
| 572 | sub clone { | ||
| 573 | |||
| 574 | # Creates a clone of an existing interface; only used when the parent cage is cloned, or | ||
| 575 | # when interfaces are exported to the GA::Client's interface clipboard | ||
| 576 | # | ||
| 577 | # Expected arguments | ||
| 578 | # $profName - The parent profile's name (e.g. matches the object's ->name) | ||
| 579 | # | ||
| 580 | # Return values | ||
| 581 | # 'undef' on improper arguments | ||
| 582 | # Blessed reference to the newly-created object on success | ||
| 583 | |||
| 584 | my ($self, $profName, $check) = @_; | ||
| 585 | |||
| 586 | # Check for improper arguments | ||
| 587 | if (! defined $profName || defined $check) { | ||
| 588 | |||
| 589 | return $axmud::CLIENT->writeImproper($self->_objClass . '->clone', @_); | ||
| 590 | } | ||
| 591 | |||
| 592 | # Setup | ||
| 593 | my $clone = { | ||
| 594 | _objName => $self->_objName, | ||
| 595 | _objClass => $self->_objClass, | ||
| 596 | _parentFile => 'otherprof', | ||
| 597 | _parentWorld => $profName, | ||
| 598 | _privFlag => TRUE, # All IVs are private | ||
| 599 | |||
| 600 | # Interface category | ||
| 601 | # ------------------ | ||
| 602 | |||
| 603 | category => $self->category, | ||
| 604 | |||
| 605 | # Standard interface attributes | ||
| 606 | # ----------------------------- | ||
| 607 | |||
| 608 | name => $self->name, | ||
| 609 | stimulus => $self->stimulus, | ||
| 610 | response => $self->response, | ||
| 611 | enabledFlag => $self->enabledFlag, | ||
| 612 | |||
| 613 | # Trigger attributes | ||
| 614 | # ------------------ | ||
| 615 | |||
| 616 | attribHash => {$self->attribHash}, | ||
| 617 | |||
| 618 | # Ordering | ||
| 619 | # -------- | ||
| 620 | |||
| 621 | beforeHash => {$self->beforeHash}, | ||
| 622 | afterHash => {$self->afterHash}, | ||
| 623 | }; | ||
| 624 | |||
| 625 | # Bless the cloned object into existence | ||
| 626 | bless $clone, $self->_objClass; | ||
| 627 | return $clone; | ||
| 628 | } | ||
| 629 | |||
| 630 | ################## | ||
| 631 | # Methods | ||
| 632 | |||
| 633 | ################## | ||
| 634 | # Accessors - set | ||
| 635 | |||
| 636 | ################## | ||
| 637 | # Accessors - get | ||
| 638 | |||
| 639 | sub category | ||
| 640 | { $_[0]->{category} } | ||
| 641 | |||
| 642 | sub name | ||
| 643 | { $_[0]->{name} } | ||
| 644 | sub stimulus | ||
| 645 | { $_[0]->{stimulus} } | ||
| 646 | sub response | ||
| 647 | { $_[0]->{response} } | ||
| 648 | sub enabledFlag | ||
| 649 | { $_[0]->{enabledFlag} } | ||
| 650 | |||
| 651 | sub attribHash | ||
| 652 | { my $self = shift; return %{$self->{attribHash}}; } | ||
| 653 | |||
| 654 | sub beforeHash | ||
| 655 | { my $self = shift; return %{$self->{beforeHash}}; } | ||
| 656 | sub afterHash | ||
| 657 | { my $self = shift; return %{$self->{afterHash}}; } | ||
| 658 | } | ||
| 659 | |||
| 660 | { package Games::Axmud::Interface::Alias; | ||
| 661 | |||
| 662 | use strict; | ||
| 663 | use warnings; | ||
| 664 | # use diagnostics; | ||
| 665 | |||
| 666 | use Glib qw(TRUE FALSE); | ||
| 667 | |||
| 668 | our @ISA = qw(Games::Axmud::Generic::Interface Games::Axmud); | ||
| 669 | |||
| 670 | ################## | ||
| 671 | # Constructors | ||
| 672 | |||
| 673 | sub new { | ||
| 674 | |||
| 675 | # Creates a new instance of the alias object | ||
| 676 | # | ||
| 677 | # Axmud interfaces are triggers, aliases, macros, timers and hooks. Depending on which | ||
| 678 | # profiles are current ones, and how many current profiles have interfaces with the same | ||
| 679 | # name, an interface can be 'active' or 'inactive' | ||
| 680 | # | ||
| 681 | # This object represents an 'inactive' alias. It is stored in a cage, attached to a | ||
| 682 | # particular profile | ||
| 683 | # When the profile becomes a current profile, and provided that there are no other superior | ||
| 684 | # profiles which have an alias with the same ->name, the alias becomes 'active' | ||
| 685 | # When an alias becomes active, GA::Session creates a GA::Interface::Active object, copying | ||
| 686 | # it into its registries of active interfaces | ||
| 687 | # When the alias becomes inactive again, the GA::Interface::Active object is destroyed (but | ||
| 688 | # this object continues to exist throughout) | ||
| 689 | # | ||
| 690 | # Expected argument | ||
| 691 | # $session - The GA::Session which created this object (not stored as an IV) | ||
| 692 | # $name - A name for the alias which is unique within its cage, but which could | ||
| 693 | # be the same as the name of other aliases in other cages (e.g. | ||
| 694 | # 'myalias') (max 32 chars) | ||
| 695 | # $stimulus - The stimulus (a pattern, for aliases) | ||
| 696 | # $response - The response (a substitution, for aliases) | ||
| 697 | # | ||
| 698 | # Optional arguments | ||
| 699 | # $enabledFlag - A flag, TRUE if (when the alias becomes active) it is responsive, | ||
| 700 | # FALSE if it does nothing (if 'undef', the attribute is set to TRUE) | ||
| 701 | # | ||
| 702 | # Return values | ||
| 703 | # 'undef' on improper arguments | ||
| 704 | # Blessed reference to the newly-created object on success | ||
| 705 | |||
| 706 | my ($class, $session, $name, $stimulus, $response, $enabledFlag, $check) = @_; | ||
| 707 | |||
| 708 | # Local variables | ||
| 709 | my $flag; | ||
| 710 | |||
| 711 | # Check for improper arguments | ||
| 712 | if ( | ||
| 713 | ! defined $class || ! defined $session || ! defined $name || ! defined $stimulus | ||
| 714 | || ! defined $response || defined $check | ||
| 715 | ) { | ||
| 716 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 717 | } | ||
| 718 | |||
| 719 | # Translate all values of $enabledFlag into TRUE of FALSE | ||
| 720 | if (! defined $enabledFlag || $enabledFlag) { | ||
| 721 | $flag = TRUE; # Default is TRUE | ||
| 722 | } else { | ||
| 723 | $flag = FALSE; | ||
| 724 | } | ||
| 725 | |||
| 726 | # Setup | ||
| 727 | my $self = { | ||
| 728 | _objName => $name, | ||
| 729 | _objClass => $class, | ||
| 730 | _parentFile => 'otherprof', | ||
| 731 | _parentWorld => $session->currentWorld->name, | ||
| 732 | _privFlag => TRUE, # All IVs are private | ||
| 733 | |||
| 734 | # Interface category | ||
| 735 | # ------------------ | ||
| 736 | |||
| 737 | category => 'alias', # Shortcut to $self->_objClass | ||
| 738 | |||
| 739 | # Standard interface attributes | ||
| 740 | # ----------------------------- | ||
| 741 | |||
| 742 | name => $name, # Max 32 chars | ||
| 743 | stimulus => $stimulus, # A pattern | ||
| 744 | response => $response, # A substitution | ||
| 745 | enabledFlag => $flag, | ||
| 746 | |||
| 747 | # Alias attributes | ||
| 748 | # ---------------- | ||
| 749 | |||
| 750 | # Current values for each alias attribute (initially set to defaults) | ||
| 751 | attribHash => { | ||
| 752 | 'ignore_case' => TRUE, | ||
| 753 | 'keep_checking' => FALSE, | ||
| 754 | 'temporary' => FALSE, | ||
| 755 | 'cooldown' => 0, | ||
| 756 | }, | ||
| 757 | |||
| 758 | # Ordering | ||
| 759 | # -------- | ||
| 760 | |||
| 761 | # A hash of inactive alias names. When this alias becomes active, all other active | ||
| 762 | # aliases are checked. If their corresponding inactive aliases have names which | ||
| 763 | # appear in this list, then the active alias corresponding to this object is | ||
| 764 | # placed BEFORE them in the ordered list of active aliases. Hash in the form | ||
| 765 | # $beforeHash{inactive_trigger_name} = undef | ||
| 766 | beforeHash => {}, | ||
| 767 | # Hash of inactive alias names; if corresponding active aliases exist, this object's | ||
| 768 | # active alias is placed AFTER them | ||
| 769 | afterHash => {}, | ||
| 770 | }; | ||
| 771 | |||
| 772 | # Bless the object into existence | ||
| 773 | bless $self, $class; | ||
| 774 | return $self; | ||
| 775 | } | ||
| 776 | |||
| 777 | sub clone { | ||
| 778 | |||
| 779 | # Creates a clone of an existing interface; only used when the parent cage is cloned, or | ||
| 780 | # when interfaces are exported to the GA::Client's interface clipboard | ||
| 781 | # | ||
| 782 | # Expected arguments | ||
| 783 | # $profName - The parent profile's name (e.g. matches the object's ->name) | ||
| 784 | # | ||
| 785 | # Return values | ||
| 786 | # 'undef' on improper arguments | ||
| 787 | # Blessed reference to the newly-created object on success | ||
| 788 | |||
| 789 | my ($self, $profName, $check) = @_; | ||
| 790 | |||
| 791 | # Check for improper arguments | ||
| 792 | if (! defined $profName || defined $check) { | ||
| 793 | |||
| 794 | return $axmud::CLIENT->writeImproper($self->_objClass . '->clone', @_); | ||
| 795 | } | ||
| 796 | |||
| 797 | # Setup | ||
| 798 | my $clone = { | ||
| 799 | _objName => $self->_objName, | ||
| 800 | _objClass => $self->_objClass, | ||
| 801 | _parentFile => 'otherprof', | ||
| 802 | _parentWorld => $profName, | ||
| 803 | _privFlag => TRUE, # All IVs are private | ||
| 804 | |||
| 805 | # Interface category | ||
| 806 | # ------------------ | ||
| 807 | |||
| 808 | category => $self->category, | ||
| 809 | |||
| 810 | # Standard interface attributes | ||
| 811 | # ----------------------------- | ||
| 812 | |||
| 813 | name => $self->name, | ||
| 814 | stimulus => $self->stimulus, | ||
| 815 | response => $self->response, | ||
| 816 | enabledFlag => $self->enabledFlag, | ||
| 817 | |||
| 818 | # Alias attributes | ||
| 819 | # ---------------- | ||
| 820 | |||
| 821 | attribHash => {$self->attribHash}, | ||
| 822 | |||
| 823 | # Ordering | ||
| 824 | # -------- | ||
| 825 | |||
| 826 | beforeHash => {$self->beforeHash}, | ||
| 827 | afterHash => {$self->afterHash}, | ||
| 828 | }; | ||
| 829 | |||
| 830 | # Bless the cloned object into existence | ||
| 831 | bless $clone, $self->_objClass; | ||
| 832 | return $clone; | ||
| 833 | } | ||
| 834 | |||
| 835 | ################## | ||
| 836 | # Methods | ||
| 837 | |||
| 838 | ################## | ||
| 839 | # Accessors - set | ||
| 840 | |||
| 841 | ################## | ||
| 842 | # Accessors - get | ||
| 843 | |||
| 844 | sub category | ||
| 845 | { $_[0]->{category} } | ||
| 846 | |||
| 847 | sub name | ||
| 848 | { $_[0]->{name} } | ||
| 849 | sub stimulus | ||
| 850 | { $_[0]->{stimulus} } | ||
| 851 | sub response | ||
| 852 | { $_[0]->{response} } | ||
| 853 | sub enabledFlag | ||
| 854 | { $_[0]->{enabledFlag} } | ||
| 855 | |||
| 856 | sub attribHash | ||
| 857 | { my $self = shift; return %{$self->{attribHash}}; } | ||
| 858 | |||
| 859 | sub beforeHash | ||
| 860 | { my $self = shift; return %{$self->{beforeHash}}; } | ||
| 861 | sub afterHash | ||
| 862 | { my $self = shift; return %{$self->{afterHash}}; } | ||
| 863 | } | ||
| 864 | |||
| 865 | { package Games::Axmud::Interface::Macro; | ||
| 866 | |||
| 867 | use strict; | ||
| 868 | use warnings; | ||
| 869 | # use diagnostics; | ||
| 870 | |||
| 871 | use Glib qw(TRUE FALSE); | ||
| 872 | |||
| 873 | our @ISA = qw(Games::Axmud::Generic::Interface Games::Axmud); | ||
| 874 | |||
| 875 | ################## | ||
| 876 | # Constructors | ||
| 877 | |||
| 878 | sub new { | ||
| 879 | |||
| 880 | # Creates a new instance of the macro object | ||
| 881 | # | ||
| 882 | # Axmud interfaces are triggers, aliases, macros, timers and hooks. Depending on which | ||
| 883 | # profiles are current ones, and how many current profiles have interfaces with the same | ||
| 884 | # name, an interface can be 'active' or 'inactive' | ||
| 885 | # | ||
| 886 | # This object represents an 'inactive' macro. It is stored in a cage, attached to a | ||
| 887 | # particular profile | ||
| 888 | # When the profile becomes a current profile, and provided that there are no other superior | ||
| 889 | # profiles which have a macro with the same ->name, the macro becomes 'active' | ||
| 890 | # When a macro becomes active, GA::Session creates a GA::Interface::Active object, | ||
| 891 | # copying it into its registries of active interfaces. | ||
| 892 | # When the macro becomes inactive again, the GA::Interface::Active object is destroyed (but | ||
| 893 | # this object continues to exist throughout) | ||
| 894 | # | ||
| 895 | # Expected arguments | ||
| 896 | # $session - The GA::Session which created this object (not stored as an IV) | ||
| 897 | # $name - A name for the macro which is unique within its cage, but which could | ||
| 898 | # be the same as the name of other macros in other cages (e.g. | ||
| 899 | # 'mymacro') (max 32 chars) | ||
| 900 | # $stimulus - The stimulus (a key, for macros) | ||
| 901 | # $response - The response (an action, for macros) | ||
| 902 | # | ||
| 903 | # Optional arguments | ||
| 904 | # $enabledFlag - A flag, TRUE if (when the macro becomes active) it is responsive, | ||
| 905 | # FALSE if it does nothing (if 'undef', the attribute is set to TRUE) | ||
| 906 | # | ||
| 907 | # Return values | ||
| 908 | # 'undef' on improper arguments | ||
| 909 | # Blessed reference to the newly-created object on success | ||
| 910 | |||
| 911 | my ($class, $session, $name, $stimulus, $response, $enabledFlag, $check) = @_; | ||
| 912 | |||
| 913 | # Local variables | ||
| 914 | my $flag; | ||
| 915 | |||
| 916 | # Check for improper arguments | ||
| 917 | if ( | ||
| 918 | ! defined $class || ! defined $session || ! defined $name || ! defined $stimulus | ||
| 919 | || ! defined $response || defined $check | ||
| 920 | ) { | ||
| 921 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 922 | } | ||
| 923 | |||
| 924 | # Translate all values of $enabledFlag into TRUE of FALSE | ||
| 925 | if (! defined $enabledFlag || $enabledFlag) { | ||
| 926 | $flag = TRUE; # Default is TRUE | ||
| 927 | } else { | ||
| 928 | $flag = FALSE; | ||
| 929 | } | ||
| 930 | |||
| 931 | # Setup | ||
| 932 | my $self = { | ||
| 933 | _objName => $name, | ||
| 934 | _objClass => $class, | ||
| 935 | _parentFile => 'otherprof', | ||
| 936 | _parentWorld => $session->currentWorld->name, | ||
| 937 | _privFlag => TRUE, # All IVs are private | ||
| 938 | |||
| 939 | # Interface category | ||
| 940 | # ------------------ | ||
| 941 | |||
| 942 | category => 'macro', # Shortcut to $self->_objClass | ||
| 943 | |||
| 944 | # Standard interface attributes | ||
| 945 | # ----------------------------- | ||
| 946 | |||
| 947 | name => $name, # Max 32 chars | ||
| 948 | stimulus => $stimulus, # An Axmud standard keycode | ||
| 949 | response => $response, # An instruction | ||
| 950 | enabledFlag => $flag, | ||
| 951 | |||
| 952 | # Macro attributes | ||
| 953 | # ---------------- | ||
| 954 | |||
| 955 | # Current values for each macro attribute (initially set to defaults) | ||
| 956 | attribHash => { | ||
| 957 | 'temporary' => FALSE, | ||
| 958 | 'cooldown' => 0, | ||
| 959 | }, | ||
| 960 | |||
| 961 | # Ordering | ||
| 962 | # -------- | ||
| 963 | |||
| 964 | # A hash of inactive macro names. When this macro becomes active, all other active mac | ||
| 965 | # macros are checked. If their corresponding inactive macros have names which appear | ||
| 966 | # in this list, then the active macro corresponding to this object is placed BEFORE | ||
| 967 | # them in the ordered list of active macros. Hash in the form | ||
| 968 | # $beforeHash{inactive_macro_name} = undef | ||
| 969 | beforeHash => {}, | ||
| 970 | # Hash of inactive macro names; if corresponding active macros exist, this object's | ||
| 971 | # active macro is placed AFTER them | ||
| 972 | afterHash => {}, | ||
| 973 | }; | ||
| 974 | |||
| 975 | # Bless the object into existence | ||
| 976 | bless $self, $class; | ||
| 977 | return $self; | ||
| 978 | } | ||
| 979 | |||
| 980 | sub clone { | ||
| 981 | |||
| 982 | # Creates a clone of an existing interface; only used when the parent cage is cloned, or | ||
| 983 | # when interfaces are exported to the GA::Client's interface clipboard | ||
| 984 | # | ||
| 985 | # Expected arguments | ||
| 986 | # $profName - The parent profile's name (e.g. matches the object's ->name) | ||
| 987 | # | ||
| 988 | # Return values | ||
| 989 | # 'undef' on improper arguments | ||
| 990 | # Blessed reference to the newly-created object on success | ||
| 991 | |||
| 992 | my ($self, $profName, $check) = @_; | ||
| 993 | |||
| 994 | # Check for improper arguments | ||
| 995 | if (! defined $profName || defined $check) { | ||
| 996 | |||
| 997 | return $axmud::CLIENT->writeImproper($self->_objClass . '->clone', @_); | ||
| 998 | } | ||
| 999 | |||
| 1000 | # Setup | ||
| 1001 | my $clone = { | ||
| 1002 | _objName => $self->_objName, | ||
| 1003 | _objClass => $self->_objClass, | ||
| 1004 | _parentFile => 'otherprof', | ||
| 1005 | _parentWorld => $profName, | ||
| 1006 | _privFlag => TRUE, # All IVs are private | ||
| 1007 | |||
| 1008 | # Interface category | ||
| 1009 | # ------------------ | ||
| 1010 | |||
| 1011 | category => $self->category, | ||
| 1012 | |||
| 1013 | # Standard interface attributes | ||
| 1014 | # ----------------------------- | ||
| 1015 | |||
| 1016 | name => $self->name, | ||
| 1017 | stimulus => $self->stimulus, | ||
| 1018 | response => $self->response, | ||
| 1019 | enabledFlag => $self->enabledFlag, | ||
| 1020 | |||
| 1021 | # Macro attributes | ||
| 1022 | # ---------------- | ||
| 1023 | |||
| 1024 | attribHash => {$self->attribHash}, | ||
| 1025 | |||
| 1026 | # Ordering | ||
| 1027 | # -------- | ||
| 1028 | |||
| 1029 | beforeHash => {$self->beforeHash}, | ||
| 1030 | afterHash => {$self->afterHash}, | ||
| 1031 | }; | ||
| 1032 | |||
| 1033 | # Bless the cloned object into existence | ||
| 1034 | bless $clone, $self->_objClass; | ||
| 1035 | return $clone; | ||
| 1036 | } | ||
| 1037 | |||
| 1038 | ################## | ||
| 1039 | # Methods | ||
| 1040 | |||
| 1041 | ################## | ||
| 1042 | # Accessors - set | ||
| 1043 | |||
| 1044 | ################## | ||
| 1045 | # Accessors - get | ||
| 1046 | |||
| 1047 | sub category | ||
| 1048 | { $_[0]->{category} } | ||
| 1049 | |||
| 1050 | sub name | ||
| 1051 | { $_[0]->{name} } | ||
| 1052 | sub stimulus | ||
| 1053 | { $_[0]->{stimulus} } | ||
| 1054 | sub response | ||
| 1055 | { $_[0]->{response} } | ||
| 1056 | sub enabledFlag | ||
| 1057 | { $_[0]->{enabledFlag} } | ||
| 1058 | |||
| 1059 | sub attribHash | ||
| 1060 | { my $self = shift; return %{$self->{attribHash}}; } | ||
| 1061 | |||
| 1062 | sub beforeHash | ||
| 1063 | { my $self = shift; return %{$self->{beforeHash}}; } | ||
| 1064 | sub afterHash | ||
| 1065 | { my $self = shift; return %{$self->{afterHash}}; } | ||
| 1066 | } | ||
| 1067 | |||
| 1068 | { package Games::Axmud::Interface::Timer; | ||
| 1069 | |||
| 1070 | use strict; | ||
| 1071 | use warnings; | ||
| 1072 | # use diagnostics; | ||
| 1073 | |||
| 1074 | use Glib qw(TRUE FALSE); | ||
| 1075 | |||
| 1076 | our @ISA = qw(Games::Axmud::Generic::Interface Games::Axmud); | ||
| 1077 | |||
| 1078 | ################## | ||
| 1079 | # Constructors | ||
| 1080 | |||
| 1081 | sub new { | ||
| 1082 | |||
| 1083 | # Creates a new instance of the timer object | ||
| 1084 | # | ||
| 1085 | # Axmud interfaces are triggers, aliases, macros, timers and hooks. Depending on which | ||
| 1086 | # profiles are current ones, and how many current profiles have interfaces with the same | ||
| 1087 | # name, an interface can be 'active' or 'inactive' | ||
| 1088 | # | ||
| 1089 | # This object represents an 'inactive' timer. It is stored in a cage, attached to a | ||
| 1090 | # particular profile | ||
| 1091 | # When the profile becomes a current profile, and provided that there are no other superior | ||
| 1092 | # profiles which have a timer with the same ->name, the timer becomes 'active' | ||
| 1093 | # When a timer becomes active, GA::Session creates a GA::Interface::Active object, | ||
| 1094 | # copying it into its registries of active interfaces | ||
| 1095 | # When the timer becomes inactive again, the GA::Interface::Active object is destroyed (but | ||
| 1096 | # this object continues to exist throughout) | ||
| 1097 | # | ||
| 1098 | # Expected arguments | ||
| 1099 | # $session - The GA::Session which created this object (not stored as an IV) | ||
| 1100 | # $name - A name for the timer which is unique within its cage, but which could | ||
| 1101 | # be the same as the name of other timers in other cages (e.g. | ||
| 1102 | # 'mytimer') (max 32 chars) | ||
| 1103 | # $stimulus - The stimulus (an interval or 24-hour clock time, for timers) | ||
| 1104 | # $response - The response (an action, for timers) | ||
| 1105 | # | ||
| 1106 | # Optional arguments | ||
| 1107 | # $enabledFlag - A flag, TRUE if (when the timer becomes active) it is responsive, | ||
| 1108 | # FALSE if it does nothing (if 'undef', the attribute is set to TRUE) | ||
| 1109 | # | ||
| 1110 | # Return values | ||
| 1111 | # 'undef' on improper arguments | ||
| 1112 | # Blessed reference to the newly-created object on success | ||
| 1113 | |||
| 1114 | my ($class, $session, $name, $stimulus, $response, $enabledFlag, $check) = @_; | ||
| 1115 | |||
| 1116 | # Local variables | ||
| 1117 | my $flag; | ||
| 1118 | |||
| 1119 | # Check for improper arguments | ||
| 1120 | if ( | ||
| 1121 | ! defined $class || ! defined $session || ! defined $name || ! defined $stimulus | ||
| 1122 | || ! defined $response || defined $check | ||
| 1123 | ) { | ||
| 1124 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 1125 | } | ||
| 1126 | |||
| 1127 | # Translate all values of $enabledFlag into TRUE of FALSE | ||
| 1128 | if (! defined $enabledFlag || $enabledFlag) { | ||
| 1129 | $flag = TRUE; # Default is TRUE | ||
| 1130 | } else { | ||
| 1131 | $flag = FALSE; | ||
| 1132 | } | ||
| 1133 | |||
| 1134 | # Setup | ||
| 1135 | my $self = { | ||
| 1136 | _objName => $name, | ||
| 1137 | _objClass => $class, | ||
| 1138 | _parentFile => 'otherprof', | ||
| 1139 | _parentWorld => $session->currentWorld->name, | ||
| 1140 | _privFlag => TRUE, # All IVs are private | ||
| 1141 | |||
| 1142 | # Interface category | ||
| 1143 | # ------------------ | ||
| 1144 | |||
| 1145 | category => 'timer', # Shortcut to $self->_objClass | ||
| 1146 | |||
| 1147 | # Standard interface attributes | ||
| 1148 | # ----------------------------- | ||
| 1149 | |||
| 1150 | name => $name, # Max 32 chars | ||
| 1151 | stimulus => $stimulus, # An interval or 24-hour clock time | ||
| 1152 | response => $response, # An instruction | ||
| 1153 | enabledFlag => $flag, | ||
| 1154 | |||
| 1155 | # Timer attributes | ||
| 1156 | # ------------------ | ||
| 1157 | |||
| 1158 | # Current values for each timer attribute (initially set to defaults) | ||
| 1159 | attribHash => { | ||
| 1160 | 'count' => -1, | ||
| 1161 | 'initial_delay' => 0, | ||
| 1162 | 'random_delay' => FALSE, | ||
| 1163 | 'random_min' => 0, | ||
| 1164 | 'wait_login' => TRUE, | ||
| 1165 | 'temporary' => FALSE, | ||
| 1166 | }, | ||
| 1167 | |||
| 1168 | # Ordering | ||
| 1169 | # -------- | ||
| 1170 | |||
| 1171 | # A hash of inactive timer names. When this timer becomes active, all other active | ||
| 1172 | # timers are checked. If their corresponding inactive timers have names which appear | ||
| 1173 | # in this list, then the active timer corresponding to this object is placed BEFORE | ||
| 1174 | # them in the ordered list of active timers. Hash in the form | ||
| 1175 | # $beforeHash{inactive_timer_name} = undef | ||
| 1176 | beforeHash => {}, | ||
| 1177 | # Hash of inactive timer names; if corresponding active timers exist, this object's | ||
| 1178 | # active timer is placed AFTER them | ||
| 1179 | afterHash => {}, | ||
| 1180 | }; | ||
| 1181 | |||
| 1182 | # Bless the object into existence | ||
| 1183 | bless $self, $class; | ||
| 1184 | return $self; | ||
| 1185 | } | ||
| 1186 | |||
| 1187 | sub clone { | ||
| 1188 | |||
| 1189 | # Creates a clone of an existing interface; only used when the parent cage is cloned, or | ||
| 1190 | # when interfaces are exported to the GA::Client's interface clipboard | ||
| 1191 | # | ||
| 1192 | # Expected arguments | ||
| 1193 | # $profName - The parent profile's name (e.g. matches the object's ->name) | ||
| 1194 | # | ||
| 1195 | # Return values | ||
| 1196 | # 'undef' on improper arguments | ||
| 1197 | # Blessed reference to the newly-created object on success | ||
| 1198 | |||
| 1199 | my ($self, $profName, $check) = @_; | ||
| 1200 | |||
| 1201 | # Check for improper arguments | ||
| 1202 | if (! defined $profName || defined $check) { | ||
| 1203 | |||
| 1204 | return $axmud::CLIENT->writeImproper($self->_objClass . '->clone', @_); | ||
| 1205 | } | ||
| 1206 | |||
| 1207 | # Setup | ||
| 1208 | my $clone = { | ||
| 1209 | _objName => $self->_objName, | ||
| 1210 | _objClass => $self->_objClass, | ||
| 1211 | _parentFile => 'otherprof', | ||
| 1212 | _parentWorld => $profName, | ||
| 1213 | _privFlag => TRUE, # All IVs are private | ||
| 1214 | |||
| 1215 | # Interface category | ||
| 1216 | # ------------------ | ||
| 1217 | |||
| 1218 | category => $self->category, | ||
| 1219 | |||
| 1220 | # Standard interface attributes | ||
| 1221 | # ----------------------------- | ||
| 1222 | |||
| 1223 | name => $self->name, | ||
| 1224 | stimulus => $self->stimulus, | ||
| 1225 | response => $self->response, | ||
| 1226 | enabledFlag => $self->enabledFlag, | ||
| 1227 | |||
| 1228 | # Timer attributes | ||
| 1229 | # ---------------- | ||
| 1230 | |||
| 1231 | attribHash => {$self->attribHash}, | ||
| 1232 | |||
| 1233 | # Ordering | ||
| 1234 | # -------- | ||
| 1235 | |||
| 1236 | beforeHash => {$self->beforeHash}, | ||
| 1237 | afterHash => {$self->afterHash}, | ||
| 1238 | }; | ||
| 1239 | |||
| 1240 | # Bless the cloned object into existence | ||
| 1241 | bless $clone, $self->_objClass; | ||
| 1242 | return $clone; | ||
| 1243 | } | ||
| 1244 | |||
| 1245 | ################## | ||
| 1246 | # Methods | ||
| 1247 | |||
| 1248 | ################## | ||
| 1249 | # Accessors - set | ||
| 1250 | |||
| 1251 | ################## | ||
| 1252 | # Accessors - get | ||
| 1253 | |||
| 1254 | sub category | ||
| 1255 | { $_[0]->{category} } | ||
| 1256 | |||
| 1257 | sub name | ||
| 1258 | { $_[0]->{name} } | ||
| 1259 | sub stimulus | ||
| 1260 | { $_[0]->{stimulus} } | ||
| 1261 | sub response | ||
| 1262 | { $_[0]->{response} } | ||
| 1263 | sub enabledFlag | ||
| 1264 | { $_[0]->{enabledFlag} } | ||
| 1265 | |||
| 1266 | sub attribHash | ||
| 1267 | { my $self = shift; return %{$self->{attribHash}}; } | ||
| 1268 | |||
| 1269 | sub beforeHash | ||
| 1270 | { my $self = shift; return %{$self->{beforeHash}}; } | ||
| 1271 | sub afterHash | ||
| 1272 | { my $self = shift; return %{$self->{afterHash}}; } | ||
| 1273 | } | ||
| 1274 | |||
| 1275 | { package Games::Axmud::Interface::Hook; | ||
| 1276 | |||
| 1277 | use strict; | ||
| 1278 | use warnings; | ||
| 1279 | # use diagnostics; | ||
| 1280 | |||
| 1281 | use Glib qw(TRUE FALSE); | ||
| 1282 | |||
| 1283 | our @ISA = qw(Games::Axmud::Generic::Interface Games::Axmud); | ||
| 1284 | |||
| 1285 | ################## | ||
| 1286 | # Constructors | ||
| 1287 | |||
| 1288 | sub new { | ||
| 1289 | |||
| 1290 | # Creates a new instance of the hook object | ||
| 1291 | # | ||
| 1292 | # Axmud interfaces are triggers, aliases, macros, timers and hooks. Depending on which | ||
| 1293 | # profiles are current ones, and how many current profiles have interfaces with the same | ||
| 1294 | # name, an interface can be 'active' or 'inactive' | ||
| 1295 | # | ||
| 1296 | # This object represents an 'inactive' hook. It is stored in a cage, attached to a | ||
| 1297 | # particular profile | ||
| 1298 | # When the profile becomes a current profile, and provided that there are no other superior | ||
| 1299 | # profiles which have a hook with the same ->name, the hook becomes 'active' | ||
| 1300 | # When a hook becomes active, GA::Session creates a GA::Interface::Active object, copying | ||
| 1301 | # it into its registries of active interfaces | ||
| 1302 | # When the hook becomes inactive again, the GA::Interface::Active object is destroyed (but | ||
| 1303 | # this object continues to exist throughout) | ||
| 1304 | # | ||
| 1305 | # Expected arguments | ||
| 1306 | # $session - The GA::Session which created this object (not stored as an IV) | ||
| 1307 | # $name - A name for the hook which is unique within its cage, but which could | ||
| 1308 | # be the same as the name of other hooks in other cages (e.g. | ||
| 1309 | # 'myhook') (max 32 chars) | ||
| 1310 | # $stimulus - The stimulus (an event, for hooks) | ||
| 1311 | # $response - The response (an action, for hooks) | ||
| 1312 | # | ||
| 1313 | # Optional arguments | ||
| 1314 | # $enabledFlag - A flag, TRUE if (when the hook becomes active) it is responsive, | ||
| 1315 | # FALSE if it does nothing (if 'undef', the attribute is set to TRUE) | ||
| 1316 | # | ||
| 1317 | # Return values | ||
| 1318 | # 'undef' on improper arguments | ||
| 1319 | # Blessed reference to the newly-created object on success | ||
| 1320 | |||
| 1321 | my ($class, $session, $name, $stimulus, $response, $enabledFlag, $check) = @_; | ||
| 1322 | |||
| 1323 | # Local variables | ||
| 1324 | my $flag; | ||
| 1325 | |||
| 1326 | # Check for improper arguments | ||
| 1327 | if ( | ||
| 1328 | ! defined $class || ! defined $session || ! defined $name || ! defined $stimulus | ||
| 1329 | || ! defined $response || defined $check | ||
| 1330 | ) { | ||
| 1331 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 1332 | } | ||
| 1333 | |||
| 1334 | # Translate all values of $enabledFlag into TRUE of FALSE | ||
| 1335 | if (! defined $enabledFlag || $enabledFlag) { | ||
| 1336 | $flag = TRUE; # Default is TRUE | ||
| 1337 | } else { | ||
| 1338 | $flag = FALSE; | ||
| 1339 | } | ||
| 1340 | |||
| 1341 | # Setup | ||
| 1342 | my $self = { | ||
| 1343 | _objName => $name, | ||
| 1344 | _objClass => $class, | ||
| 1345 | _parentFile => 'otherprof', | ||
| 1346 | _parentWorld => $session->currentWorld->name, | ||
| 1347 | _privFlag => TRUE, # All IVs are private | ||
| 1348 | |||
| 1349 | # Interface category | ||
| 1350 | # ------------------ | ||
| 1351 | |||
| 1352 | category => 'hook', # Shortcut to $self->_objClass | ||
| 1353 | |||
| 1354 | # Standard interface attributes | ||
| 1355 | # ----------------------------- | ||
| 1356 | |||
| 1357 | name => $name, # Max 32 chars | ||
| 1358 | stimulus => $stimulus, # A hook event | ||
| 1359 | response => $response, # An instruction | ||
| 1360 | enabledFlag => $flag, | ||
| 1361 | |||
| 1362 | # Hook attributes | ||
| 1363 | # --------------- | ||
| 1364 | |||
| 1365 | # Current values for each hook attribute (initially set to defaults) | ||
| 1366 | attribHash => { | ||
| 1367 | 'temporary' => FALSE, | ||
| 1368 | 'cooldown' => 0, | ||
| 1369 | }, | ||
| 1370 | |||
| 1371 | # Ordering | ||
| 1372 | # -------- | ||
| 1373 | |||
| 1374 | # A hash of inactive hook names. When this hook becomes active, all other active hooks | ||
| 1375 | # are checked. If their corresponding inactive hooks have names which appear in this | ||
| 1376 | # list, then the active hook corresponding to this object is placed BEFORE them in the | ||
| 1377 | # ordered list of active hooks. Hash in the form | ||
| 1378 | # $beforeHash{inactive_hook_name} = undef | ||
| 1379 | beforeHash => {}, | ||
| 1380 | # Hash of inactive hook names; if corresponding active hooks exist, this object's | ||
| 1381 | # active hook is placed AFTER them | ||
| 1382 | afterHash => {}, | ||
| 1383 | }; | ||
| 1384 | |||
| 1385 | # Bless the object into existence | ||
| 1386 | bless $self, $class; | ||
| 1387 | return $self; | ||
| 1388 | } | ||
| 1389 | |||
| 1390 | sub clone { | ||
| 1391 | |||
| 1392 | # Creates a clone of an existing interface; only used when the parent cage is cloned, or | ||
| 1393 | # when interfaces are exported to the GA::Client's interface clipboard | ||
| 1394 | # | ||
| 1395 | # Expected arguments | ||
| 1396 | # $profName - The parent profile's name (e.g. matches the object's ->name) | ||
| 1397 | # | ||
| 1398 | # Return values | ||
| 1399 | # 'undef' on improper arguments | ||
| 1400 | # Blessed reference to the newly-created object on success | ||
| 1401 | |||
| 1402 | my ($self, $profName, $check) = @_; | ||
| 1403 | |||
| 1404 | # Check for improper arguments | ||
| 1405 | if (! defined $profName || defined $check) { | ||
| 1406 | |||
| 1407 | return $axmud::CLIENT->writeImproper($self->_objClass . '->clone', @_); | ||
| 1408 | } | ||
| 1409 | |||
| 1410 | # Setup | ||
| 1411 | my $clone = { | ||
| 1412 | _objName => $self->_objName, | ||
| 1413 | _objClass => $self->_objClass, | ||
| 1414 | _parentFile => 'otherprof', | ||
| 1415 | _parentWorld => $profName, | ||
| 1416 | _privFlag => TRUE, # All IVs are private | ||
| 1417 | |||
| 1418 | # Interface category | ||
| 1419 | # ------------------ | ||
| 1420 | |||
| 1421 | category => $self->category, | ||
| 1422 | |||
| 1423 | # Standard interface attributes | ||
| 1424 | # ----------------------------- | ||
| 1425 | |||
| 1426 | name => $self->name, | ||
| 1427 | stimulus => $self->stimulus, | ||
| 1428 | response => $self->response, | ||
| 1429 | enabledFlag => $self->enabledFlag, | ||
| 1430 | |||
| 1431 | # Hook attributes | ||
| 1432 | # --------------- | ||
| 1433 | |||
| 1434 | attribHash => {$self->attribHash}, | ||
| 1435 | |||
| 1436 | # Ordering | ||
| 1437 | # -------- | ||
| 1438 | |||
| 1439 | beforeHash => {$self->beforeHash}, | ||
| 1440 | afterHash => {$self->afterHash}, | ||
| 1441 | }; | ||
| 1442 | |||
| 1443 | # Bless the cloned object into existence | ||
| 1444 | bless $clone, $self->_objClass; | ||
| 1445 | return $clone; | ||
| 1446 | } | ||
| 1447 | |||
| 1448 | ################## | ||
| 1449 | # Methods | ||
| 1450 | |||
| 1451 | ################## | ||
| 1452 | # Accessors - set | ||
| 1453 | |||
| 1454 | ################## | ||
| 1455 | # Accessors - get | ||
| 1456 | |||
| 1457 | sub category | ||
| 1458 | { $_[0]->{category} } | ||
| 1459 | |||
| 1460 | sub name | ||
| 1461 | { $_[0]->{name} } | ||
| 1462 | sub stimulus | ||
| 1463 | { $_[0]->{stimulus} } | ||
| 1464 | sub response | ||
| 1465 | { $_[0]->{response} } | ||
| 1466 | sub enabledFlag | ||
| 1467 | { $_[0]->{enabledFlag} } | ||
| 1468 | |||
| 1469 | sub attribHash | ||
| 1470 | { my $self = shift; return %{$self->{attribHash}}; } | ||
| 1471 | |||
| 1472 | sub beforeHash | ||
| 1473 | { my $self = shift; return %{$self->{beforeHash}}; } | ||
| 1474 | sub afterHash | ||
| 1475 | { my $self = shift; return %{$self->{afterHash}}; } | ||
| 1476 | } | ||
| 1477 | |||
| 1478 | # Package must return a true value | ||
| 1479 | 1 |