| 1 | # Copyright (C) 2011-2021 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 | ################## | ||
| 216 | # Accessors - set | ||
| 217 | |||
| 218 | sub set_callClass { | ||
| 219 | |||
| 220 | my ($self, $callClass, $check) = @_; | ||
| 221 | |||
| 222 | # Check for improper arguments | ||
| 223 | if (! defined $callClass || defined $check) { | ||
| 224 | |||
| 225 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_callClass', @_); | ||
| 226 | } | ||
| 227 | |||
| 228 | $self->ivPoke('callClass', $callClass); | ||
| 229 | |||
| 230 | return 1; | ||
| 231 | } | ||
| 232 | |||
| 233 | sub set_callMethod { | ||
| 234 | |||
| 235 | my ($self, $callMethod, $check) = @_; | ||
| 236 | |||
| 237 | # Check for improper arguments | ||
| 238 | if (! defined $callMethod || defined $check) { | ||
| 239 | |||
| 240 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_callMethod', @_); | ||
| 241 | } | ||
| 242 | |||
| 243 | $self->ivPoke('callMethod', $callMethod); | ||
| 244 | |||
| 245 | return 1; | ||
| 246 | } | ||
| 247 | |||
| 248 | sub set_enabledFlag { | ||
| 249 | |||
| 250 | my ($self, $flag, $check) = @_; | ||
| 251 | |||
| 252 | # Check for improper arguments | ||
| 253 | if (! defined $flag || defined $check) { | ||
| 254 | |||
| 255 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_enabledFlag', @_); | ||
| 256 | } | ||
| 257 | |||
| 258 | if ($flag) { | ||
| 259 | |||
| 260 | if (! $self->enabledFlag) { | ||
| 261 | |||
| 262 | # Disabled timers need to have some IVs set when they become enabled | ||
| 263 | $self->becomeEnabled(); | ||
| 264 | } | ||
| 265 | |||
| 266 | $self->ivPoke('enabledFlag', TRUE); | ||
| 267 | |||
| 268 | } else { | ||
| 269 | |||
| 270 | $self->ivPoke('enabledFlag', FALSE); | ||
| 271 | } | ||
| 272 | |||
| 273 | return 1; | ||
| 274 | } | ||
| 275 | |||
| 276 | sub set_number { | ||
| 277 | |||
| 278 | my ($self, $number, $check) = @_; | ||
| 279 | |||
| 280 | # Check for improper arguments | ||
| 281 | if (! defined $number || defined $check) { | ||
| 282 | |||
| 283 | return $axmud::CLIENT->writeImproper($self->_objClass . '->set_number', @_); | ||
| 284 | } | ||
| 285 | |||
| 286 | $self->ivPoke('number', $number); | ||
| 287 | |||
| 288 | return 1; | ||
| 289 | } | ||
| 290 | |||
| 291 | sub add_property { | ||
| 292 | |||
| 293 | my ($self, $key, $value, $check) = @_; | ||
| 294 | |||
| 295 | # Check for improper arguments | ||
| 296 | if (! defined $key || ! defined $value || defined $check) { | ||
| 297 | |||
| 298 | return $axmud::CLIENT->writeImproper($self->_objClass . '->add_property', @_); | ||
| 299 | } | ||
| 300 | |||
| 301 | # Update IVs | ||
| 302 | $self->ivAdd('propertyHash', $key, $value); | ||
| 303 | |||
| 304 | return 1; | ||
| 305 | } | ||
| 306 | |||
| 307 | ################## | ||
| 308 | # Accessors - get | ||
| 309 | |||
| 310 | sub session | ||
| 311 | { $_[0]->{session} } | ||
| 312 | sub parent | ||
| 313 | { $_[0]->{parent} } | ||
| 314 | |||
| 315 | sub name | ||
| 316 | { $_[0]->{name} } | ||
| 317 | sub number | ||
| 318 | { $_[0]->{number} } | ||
| 319 | sub category | ||
| 320 | { $_[0]->{category} } | ||
| 321 | sub indepFlag | ||
| 322 | { $_[0]->{indepFlag} } | ||
| 323 | |||
| 324 | sub stimulus | ||
| 325 | { $_[0]->{stimulus} } | ||
| 326 | sub response | ||
| 327 | { $_[0]->{response} } | ||
| 328 | sub enabledFlag | ||
| 329 | { $_[0]->{enabledFlag} } | ||
| 330 | |||
| 331 | sub attribHash | ||
| 332 | { my $self = shift; return %{$self->{attribHash}}; } | ||
| 333 | |||
| 334 | sub assocProf | ||
| 335 | { $_[0]->{assocProf} } | ||
| 336 | sub assocProfCategory | ||
| 337 | { $_[0]->{assocProfCategory} } | ||
| 338 | |||
| 339 | sub callClass | ||
| 340 | { $_[0]->{callClass} } | ||
| 341 | sub callMethod | ||
| 342 | { $_[0]->{callMethod} } | ||
| 343 | |||
| 344 | sub propertyHash | ||
| 345 | { my $self = shift; return %{$self->{propertyHash}}; } | ||
| 346 | } | ||
| 347 | |||
| 348 | { package Games::Axmud::Interface::Trigger; | ||
| 349 | |||
| 350 | use strict; | ||
| 351 | use warnings; | ||
| 352 | use diagnostics; | ||
| 353 | |||
| 354 | use Glib qw(TRUE FALSE); | ||
| 355 | |||
| 356 | our @ISA = qw(Games::Axmud::Generic::Interface Games::Axmud); | ||
| 357 | |||
| 358 | ################## | ||
| 359 | # Constructors | ||
| 360 | |||
| 361 | sub new { | ||
| 362 | |||
| 363 | # Creates a new instance of the trigger object | ||
| 364 | # | ||
| 365 | # Axmud interfaces are triggers, aliases, macros, timers and hooks. Depending on which | ||
| 366 | # profiles are current ones, and how many current profiles have interfaces with the same | ||
| 367 | # name, an interface can be 'active' or 'inactive' | ||
| 368 | # | ||
| 369 | # This object represents an 'inactive' trigger. It is stored in a cage, attached to a | ||
| 370 | # particular profile | ||
| 371 | # When the profile becomes a current profile, and provided that there are no other superior | ||
| 372 | # profiles which have a trigger with the same ->name, the trigger becomes 'active' | ||
| 373 | # When a trigger becomes active, GA::Session creates a GA::Interface::Active object, copying | ||
| 374 | # it into its registries of active interfaces | ||
| 375 | # When the trigger becomes inactive again, the GA::Interface::Active object is destroyed | ||
| 376 | # (but this object continues to exist throughout) | ||
| 377 | # | ||
| 378 | # Expected arguments | ||
| 379 | # $session - The GA::Session which created this object (not stored as an IV) | ||
| 380 | # $name - A name for the trigger which is unique within its cage, but which | ||
| 381 | # could be the same as the name of other triggers in other cages | ||
| 382 | # (e.g. 'mytrigger') (max 32 chars) | ||
| 383 | # $stimulus - The stimulus (a pattern, for triggers) | ||
| 384 | # $response - The response (an action, for triggers) | ||
| 385 | # | ||
| 386 | # Optional arguments | ||
| 387 | # $enabledFlag - A flag, TRUE if (when the trigger becomes active) it is responsive, | ||
| 388 | # FALSE if it does nothing (if 'undef', the attribute is set to TRUE). | ||
| 389 | # | ||
| 390 | # Return values | ||
| 391 | # 'undef' on improper arguments or if $name, $stimulus, $response or $enabledFlag are | ||
| 392 | # invalid values | ||
| 393 | # Blessed reference to the newly-created object on success | ||
| 394 | |||
| 395 | my ($class, $session, $name, $stimulus, $response, $enabledFlag, $check) = @_; | ||
| 396 | |||
| 397 | # Local variables | ||
| 398 | my $flag; | ||
| 399 | |||
| 400 | # Check for improper arguments | ||
| 401 | if ( | ||
| 402 | ! defined $class || ! defined $session || ! defined $name || ! defined $stimulus | ||
| 403 | || ! defined $response || defined $check | ||
| 404 | ) { | ||
| 405 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 406 | } | ||
| 407 | |||
| 408 | # Translate all values of $enabledFlag into TRUE of FALSE | ||
| 409 | if (! defined $enabledFlag || $enabledFlag) { | ||
| 410 | $flag = TRUE; # Default is TRUE | ||
| 411 | } else { | ||
| 412 | $flag = FALSE; | ||
| 413 | } | ||
| 414 | |||
| 415 | # Setup | ||
| 416 | my $self = { | ||
| 417 | _objName => $name, | ||
| 418 | _objClass => $class, | ||
| 419 | _parentFile => 'otherprof', | ||
| 420 | _parentWorld => $session->currentWorld->name, | ||
| 421 | _privFlag => TRUE, # All IVs are private | ||
| 422 | |||
| 423 | # Interface category | ||
| 424 | # ------------------ | ||
| 425 | |||
| 426 | category => 'trigger', # Shortcut to $self->_objClass | ||
| 427 | |||
| 428 | # Standard interface attributes | ||
| 429 | # ----------------------------- | ||
| 430 | |||
| 431 | name => $name, # Max 32 chars | ||
| 432 | stimulus => $stimulus, # A pattern | ||
| 433 | response => $response, # Instruction (or pattern/substitution) | ||
| 434 | enabledFlag => $flag, | ||
| 435 | |||
| 436 | # Trigger attributes | ||
| 437 | # ------------------ | ||
| 438 | |||
| 439 | # Current values for each trigger attribute (initially set to defaults) | ||
| 440 | attribHash => { | ||
| 441 | 'ignore_response' => FALSE, | ||
| 442 | 'splitter' => FALSE, | ||
| 443 | 'split_after' => FALSE, | ||
| 444 | 'keep_splitting' => FALSE, | ||
| 445 | 'rewriter' => FALSE, | ||
| 446 | 'rewrite_global' => FALSE, | ||
| 447 | 'ignore_case' => TRUE, | ||
| 448 | 'gag' => FALSE, | ||
| 449 | 'gag_log' => FALSE, | ||
| 450 | 'need_prompt' => FALSE, | ||
| 451 | 'need_login' => FALSE, | ||
| 452 | 'keep_checking' => TRUE, | ||
| 453 | 'default_pane' => TRUE, | ||
| 454 | 'pane_name' => '', | ||
| 455 | 'temporary' => FALSE, | ||
| 456 | 'cooldown' => 0, | ||
| 457 | 'style_mode' => 0, | ||
| 458 | 'style_text' => '', | ||
| 459 | 'style_underlay' => '', | ||
| 460 | 'style_italics' => 0, | ||
| 461 | 'style_underline' => 0, | ||
| 462 | 'style_blink_slow' => 0, | ||
| 463 | 'style_blink_fast' => 0, | ||
| 464 | 'style_strike' => 0, | ||
| 465 | 'style_link' => 0, | ||
| 466 | }, | ||
| 467 | |||
| 468 | # Ordering | ||
| 469 | # -------- | ||
| 470 | |||
| 471 | # A hash of inactive trigger names. When this trigger becomes active, all other active | ||
| 472 | # triggers are checked. If their corresponding inactive triggers have names which | ||
| 473 | # appear in this list, then the active trigger corresponding to this object is | ||
| 474 | # placed BEFORE them in the ordered list of active triggers. Hash in the form | ||
| 475 | # $beforeHash{inactive_trigger_name} = undef | ||
| 476 | beforeHash => {}, | ||
| 477 | # Hash of inactive trigger names; if corresponding active triggers exist, this object's | ||
| 478 | # active trigger is placed AFTER them. (NB If ->beforeHash and ->afterHash conflict, | ||
| 479 | # then ->beforeHash is ignored and ->afterHash is used) | ||
| 480 | afterHash => {}, | ||
| 481 | }; | ||
| 482 | |||
| 483 | # Bless the object into existence | ||
| 484 | bless $self, $class; | ||
| 485 | return $self; | ||
| 486 | } | ||
| 487 | |||
| 488 | sub clone { | ||
| 489 | |||
| 490 | # Creates a clone of an existing interface; only used when the parent cage is cloned | ||
| 491 | # | ||
| 492 | # Expected arguments | ||
| 493 | # $profName - The parent profile's name (e.g. matches the object's ->name) | ||
| 494 | # | ||
| 495 | # Return values | ||
| 496 | # 'undef' on improper arguments | ||
| 497 | # Blessed reference to the newly-created object on success | ||
| 498 | |||
| 499 | my ($self, $profName, $check) = @_; | ||
| 500 | |||
| 501 | # Check for improper arguments | ||
| 502 | if (! defined $profName || defined $check) { | ||
| 503 | |||
| 504 | return $axmud::CLIENT->writeImproper($self->_objClass . '->clone', @_); | ||
| 505 | } | ||
| 506 | |||
| 507 | # Setup | ||
| 508 | my $clone = { | ||
| 509 | _objName => $self->_objName, | ||
| 510 | _objClass => $self->_objClass, | ||
| 511 | _parentFile => 'otherprof', | ||
| 512 | _parentWorld => $profName, | ||
| 513 | _privFlag => TRUE, # All IVs are private | ||
| 514 | |||
| 515 | # Interface category | ||
| 516 | # ------------------ | ||
| 517 | |||
| 518 | category => $self->category, | ||
| 519 | |||
| 520 | # Standard interface attributes | ||
| 521 | # ----------------------------- | ||
| 522 | |||
| 523 | name => $self->name, | ||
| 524 | stimulus => $self->stimulus, | ||
| 525 | response => $self->response, | ||
| 526 | enabledFlag => $self->enabledFlag, | ||
| 527 | |||
| 528 | # Trigger attributes | ||
| 529 | # ------------------ | ||
| 530 | |||
| 531 | attribHash => {$self->attribHash}, | ||
| 532 | |||
| 533 | # Ordering | ||
| 534 | # -------- | ||
| 535 | |||
| 536 | beforeHash => {$self->beforeHash}, | ||
| 537 | afterHash => {$self->afterHash}, | ||
| 538 | }; | ||
| 539 | |||
| 540 | # Bless the cloned object into existence | ||
| 541 | bless $clone, $self->_objClass; | ||
| 542 | return $clone; | ||
| 543 | } | ||
| 544 | |||
| 545 | ################## | ||
| 546 | # Methods | ||
| 547 | |||
| 548 | ################## | ||
| 549 | # Accessors - set | ||
| 550 | |||
| 551 | ################## | ||
| 552 | # Accessors - get | ||
| 553 | |||
| 554 | sub category | ||
| 555 | { $_[0]->{category} } | ||
| 556 | |||
| 557 | sub name | ||
| 558 | { $_[0]->{name} } | ||
| 559 | sub stimulus | ||
| 560 | { $_[0]->{stimulus} } | ||
| 561 | sub response | ||
| 562 | { $_[0]->{response} } | ||
| 563 | sub enabledFlag | ||
| 564 | { $_[0]->{enabledFlag} } | ||
| 565 | |||
| 566 | sub attribHash | ||
| 567 | { my $self = shift; return %{$self->{attribHash}}; } | ||
| 568 | |||
| 569 | sub beforeHash | ||
| 570 | { my $self = shift; return %{$self->{beforeHash}}; } | ||
| 571 | sub afterHash | ||
| 572 | { my $self = shift; return %{$self->{afterHash}}; } | ||
| 573 | } | ||
| 574 | |||
| 575 | { package Games::Axmud::Interface::Alias; | ||
| 576 | |||
| 577 | use strict; | ||
| 578 | use warnings; | ||
| 579 | use diagnostics; | ||
| 580 | |||
| 581 | use Glib qw(TRUE FALSE); | ||
| 582 | |||
| 583 | our @ISA = qw(Games::Axmud::Generic::Interface Games::Axmud); | ||
| 584 | |||
| 585 | ################## | ||
| 586 | # Constructors | ||
| 587 | |||
| 588 | sub new { | ||
| 589 | |||
| 590 | # Creates a new instance of the alias object | ||
| 591 | # | ||
| 592 | # Axmud interfaces are triggers, aliases, macros, timers and hooks. Depending on which | ||
| 593 | # profiles are current ones, and how many current profiles have interfaces with the same | ||
| 594 | # name, an interface can be 'active' or 'inactive' | ||
| 595 | # | ||
| 596 | # This object represents an 'inactive' alias. It is stored in a cage, attached to a | ||
| 597 | # particular profile | ||
| 598 | # When the profile becomes a current profile, and provided that there are no other superior | ||
| 599 | # profiles which have an alias with the same ->name, the alias becomes 'active' | ||
| 600 | # When an alias becomes active, GA::Session creates a GA::Interface::Active object, copying | ||
| 601 | # it into its registries of active interfaces | ||
| 602 | # When the alias becomes inactive again, the GA::Interface::Active object is destroyed (but | ||
| 603 | # this object continues to exist throughout) | ||
| 604 | # | ||
| 605 | # Expected argument | ||
| 606 | # $session - The GA::Session which created this object (not stored as an IV) | ||
| 607 | # $name - A name for the alias which is unique within its cage, but which could | ||
| 608 | # be the same as the name of other aliases in other cages (e.g. | ||
| 609 | # 'myalias') (max 32 chars) | ||
| 610 | # $stimulus - The stimulus (a pattern, for aliases) | ||
| 611 | # $response - The response (a substitution, for aliases) | ||
| 612 | # | ||
| 613 | # Optional arguments | ||
| 614 | # $enabledFlag - A flag, TRUE if (when the alias becomes active) it is responsive, | ||
| 615 | # FALSE if it does nothing (if 'undef', the attribute is set to TRUE) | ||
| 616 | # | ||
| 617 | # Return values | ||
| 618 | # 'undef' on improper arguments | ||
| 619 | # Blessed reference to the newly-created object on success | ||
| 620 | |||
| 621 | my ($class, $session, $name, $stimulus, $response, $enabledFlag, $check) = @_; | ||
| 622 | |||
| 623 | # Local variables | ||
| 624 | my $flag; | ||
| 625 | |||
| 626 | # Check for improper arguments | ||
| 627 | if ( | ||
| 628 | ! defined $class || ! defined $session || ! defined $name || ! defined $stimulus | ||
| 629 | || ! defined $response || defined $check | ||
| 630 | ) { | ||
| 631 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 632 | } | ||
| 633 | |||
| 634 | # Translate all values of $enabledFlag into TRUE of FALSE | ||
| 635 | if (! defined $enabledFlag || $enabledFlag) { | ||
| 636 | $flag = TRUE; # Default is TRUE | ||
| 637 | } else { | ||
| 638 | $flag = FALSE; | ||
| 639 | } | ||
| 640 | |||
| 641 | # Setup | ||
| 642 | my $self = { | ||
| 643 | _objName => $name, | ||
| 644 | _objClass => $class, | ||
| 645 | _parentFile => 'otherprof', | ||
| 646 | _parentWorld => $session->currentWorld->name, | ||
| 647 | _privFlag => TRUE, # All IVs are private | ||
| 648 | |||
| 649 | # Interface category | ||
| 650 | # ------------------ | ||
| 651 | |||
| 652 | category => 'alias', # Shortcut to $self->_objClass | ||
| 653 | |||
| 654 | # Standard interface attributes | ||
| 655 | # ----------------------------- | ||
| 656 | |||
| 657 | name => $name, # Max 32 chars | ||
| 658 | stimulus => $stimulus, # A pattern | ||
| 659 | response => $response, # A substitution | ||
| 660 | enabledFlag => $flag, | ||
| 661 | |||
| 662 | # Alias attributes | ||
| 663 | # ---------------- | ||
| 664 | |||
| 665 | # Current values for each alias attribute (initially set to defaults) | ||
| 666 | attribHash => { | ||
| 667 | 'ignore_case' => TRUE, | ||
| 668 | 'keep_checking' => FALSE, | ||
| 669 | 'temporary' => FALSE, | ||
| 670 | 'cooldown' => 0, | ||
| 671 | }, | ||
| 672 | |||
| 673 | # Ordering | ||
| 674 | # -------- | ||
| 675 | |||
| 676 | # A hash of inactive alias names. When this alias becomes active, all other active | ||
| 677 | # aliases are checked. If their corresponding inactive aliases have names which | ||
| 678 | # appear in this list, then the active alias corresponding to this object is | ||
| 679 | # placed BEFORE them in the ordered list of active aliases. Hash in the form | ||
| 680 | # $beforeHash{inactive_trigger_name} = undef | ||
| 681 | beforeHash => {}, | ||
| 682 | # Hash of inactive alias names; if corresponding active aliases exist, this object's | ||
| 683 | # active alias is placed AFTER them | ||
| 684 | afterHash => {}, | ||
| 685 | }; | ||
| 686 | |||
| 687 | # Bless the object into existence | ||
| 688 | bless $self, $class; | ||
| 689 | return $self; | ||
| 690 | } | ||
| 691 | |||
| 692 | sub clone { | ||
| 693 | |||
| 694 | # Creates a clone of an existing interface; only used when the parent cage is cloned | ||
| 695 | # | ||
| 696 | # Expected arguments | ||
| 697 | # $profName - The parent profile's name (e.g. matches the object's ->name) | ||
| 698 | # | ||
| 699 | # Return values | ||
| 700 | # 'undef' on improper arguments | ||
| 701 | # Blessed reference to the newly-created object on success | ||
| 702 | |||
| 703 | my ($self, $profName, $check) = @_; | ||
| 704 | |||
| 705 | # Check for improper arguments | ||
| 706 | if (! defined $profName || defined $check) { | ||
| 707 | |||
| 708 | return $axmud::CLIENT->writeImproper($self->_objClass . '->clone', @_); | ||
| 709 | } | ||
| 710 | |||
| 711 | # Setup | ||
| 712 | my $clone = { | ||
| 713 | _objName => $self->_objName, | ||
| 714 | _objClass => $self->_objClass, | ||
| 715 | _parentFile => 'otherprof', | ||
| 716 | _parentWorld => $profName, | ||
| 717 | _privFlag => TRUE, # All IVs are private | ||
| 718 | |||
| 719 | # Interface category | ||
| 720 | # ------------------ | ||
| 721 | |||
| 722 | category => $self->category, | ||
| 723 | |||
| 724 | # Standard interface attributes | ||
| 725 | # ----------------------------- | ||
| 726 | |||
| 727 | name => $self->name, | ||
| 728 | stimulus => $self->stimulus, | ||
| 729 | response => $self->response, | ||
| 730 | enabledFlag => $self->enabledFlag, | ||
| 731 | |||
| 732 | # Alias attributes | ||
| 733 | # ---------------- | ||
| 734 | |||
| 735 | attribHash => {$self->attribHash}, | ||
| 736 | |||
| 737 | # Ordering | ||
| 738 | # -------- | ||
| 739 | |||
| 740 | beforeHash => {$self->beforeHash}, | ||
| 741 | afterHash => {$self->afterHash}, | ||
| 742 | }; | ||
| 743 | |||
| 744 | # Bless the cloned object into existence | ||
| 745 | bless $clone, $self->_objClass; | ||
| 746 | return $clone; | ||
| 747 | } | ||
| 748 | |||
| 749 | ################## | ||
| 750 | # Methods | ||
| 751 | |||
| 752 | ################## | ||
| 753 | # Accessors - set | ||
| 754 | |||
| 755 | ################## | ||
| 756 | # Accessors - get | ||
| 757 | |||
| 758 | sub category | ||
| 759 | { $_[0]->{category} } | ||
| 760 | |||
| 761 | sub name | ||
| 762 | { $_[0]->{name} } | ||
| 763 | sub stimulus | ||
| 764 | { $_[0]->{stimulus} } | ||
| 765 | sub response | ||
| 766 | { $_[0]->{response} } | ||
| 767 | sub enabledFlag | ||
| 768 | { $_[0]->{enabledFlag} } | ||
| 769 | |||
| 770 | sub attribHash | ||
| 771 | { my $self = shift; return %{$self->{attribHash}}; } | ||
| 772 | |||
| 773 | sub beforeHash | ||
| 774 | { my $self = shift; return %{$self->{beforeHash}}; } | ||
| 775 | sub afterHash | ||
| 776 | { my $self = shift; return %{$self->{afterHash}}; } | ||
| 777 | } | ||
| 778 | |||
| 779 | { package Games::Axmud::Interface::Macro; | ||
| 780 | |||
| 781 | use strict; | ||
| 782 | use warnings; | ||
| 783 | use diagnostics; | ||
| 784 | |||
| 785 | use Glib qw(TRUE FALSE); | ||
| 786 | |||
| 787 | our @ISA = qw(Games::Axmud::Generic::Interface Games::Axmud); | ||
| 788 | |||
| 789 | ################## | ||
| 790 | # Constructors | ||
| 791 | |||
| 792 | sub new { | ||
| 793 | |||
| 794 | # Creates a new instance of the macro object | ||
| 795 | # | ||
| 796 | # Axmud interfaces are triggers, aliases, macros, timers and hooks. Depending on which | ||
| 797 | # profiles are current ones, and how many current profiles have interfaces with the same | ||
| 798 | # name, an interface can be 'active' or 'inactive' | ||
| 799 | # | ||
| 800 | # This object represents an 'inactive' macro. It is stored in a cage, attached to a | ||
| 801 | # particular profile | ||
| 802 | # When the profile becomes a current profile, and provided that there are no other superior | ||
| 803 | # profiles which have a macro with the same ->name, the macro becomes 'active' | ||
| 804 | # When a macro becomes active, GA::Session creates a GA::Interface::Active object, | ||
| 805 | # copying it into its registries of active interfaces. | ||
| 806 | # When the macro becomes inactive again, the GA::Interface::Active object is destroyed (but | ||
| 807 | # this object continues to exist throughout) | ||
| 808 | # | ||
| 809 | # Expected arguments | ||
| 810 | # $session - The GA::Session which created this object (not stored as an IV) | ||
| 811 | # $name - A name for the macro which is unique within its cage, but which could | ||
| 812 | # be the same as the name of other macros in other cages (e.g. | ||
| 813 | # 'mymacro') (max 32 chars) | ||
| 814 | # $stimulus - The stimulus (a key, for macros) | ||
| 815 | # $response - The response (an action, for macros) | ||
| 816 | # | ||
| 817 | # Optional arguments | ||
| 818 | # $enabledFlag - A flag, TRUE if (when the macro becomes active) it is responsive, | ||
| 819 | # FALSE if it does nothing (if 'undef', the attribute is set to TRUE) | ||
| 820 | # | ||
| 821 | # Return values | ||
| 822 | # 'undef' on improper arguments | ||
| 823 | # Blessed reference to the newly-created object on success | ||
| 824 | |||
| 825 | my ($class, $session, $name, $stimulus, $response, $enabledFlag, $check) = @_; | ||
| 826 | |||
| 827 | # Local variables | ||
| 828 | my $flag; | ||
| 829 | |||
| 830 | # Check for improper arguments | ||
| 831 | if ( | ||
| 832 | ! defined $class || ! defined $session || ! defined $name || ! defined $stimulus | ||
| 833 | || ! defined $response || defined $check | ||
| 834 | ) { | ||
| 835 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 836 | } | ||
| 837 | |||
| 838 | # Translate all values of $enabledFlag into TRUE of FALSE | ||
| 839 | if (! defined $enabledFlag || $enabledFlag) { | ||
| 840 | $flag = TRUE; # Default is TRUE | ||
| 841 | } else { | ||
| 842 | $flag = FALSE; | ||
| 843 | } | ||
| 844 | |||
| 845 | # Setup | ||
| 846 | my $self = { | ||
| 847 | _objName => $name, | ||
| 848 | _objClass => $class, | ||
| 849 | _parentFile => 'otherprof', | ||
| 850 | _parentWorld => $session->currentWorld->name, | ||
| 851 | _privFlag => TRUE, # All IVs are private | ||
| 852 | |||
| 853 | # Interface category | ||
| 854 | # ------------------ | ||
| 855 | |||
| 856 | category => 'macro', # Shortcut to $self->_objClass | ||
| 857 | |||
| 858 | # Standard interface attributes | ||
| 859 | # ----------------------------- | ||
| 860 | |||
| 861 | name => $name, # Max 32 chars | ||
| 862 | stimulus => $stimulus, # An Axmud standard keycode | ||
| 863 | response => $response, # An instruction | ||
| 864 | enabledFlag => $flag, | ||
| 865 | |||
| 866 | # Macro attributes | ||
| 867 | # ---------------- | ||
| 868 | |||
| 869 | # Current values for each macro attribute (initially set to defaults) | ||
| 870 | attribHash => { | ||
| 871 | 'temporary' => FALSE, | ||
| 872 | 'cooldown' => 0, | ||
| 873 | }, | ||
| 874 | |||
| 875 | # Ordering | ||
| 876 | # -------- | ||
| 877 | |||
| 878 | # A hash of inactive macro names. When this macro becomes active, all other active mac | ||
| 879 | # macros are checked. If their corresponding inactive macros have names which appear | ||
| 880 | # in this list, then the active macro corresponding to this object is placed BEFORE | ||
| 881 | # them in the ordered list of active macros. Hash in the form | ||
| 882 | # $beforeHash{inactive_macro_name} = undef | ||
| 883 | beforeHash => {}, | ||
| 884 | # Hash of inactive macro names; if corresponding active macros exist, this object's | ||
| 885 | # active macro is placed AFTER them | ||
| 886 | afterHash => {}, | ||
| 887 | }; | ||
| 888 | |||
| 889 | # Bless the object into existence | ||
| 890 | bless $self, $class; | ||
| 891 | return $self; | ||
| 892 | } | ||
| 893 | |||
| 894 | sub clone { | ||
| 895 | |||
| 896 | # Creates a clone of an existing interface; only used when the parent cage is cloned | ||
| 897 | # | ||
| 898 | # Expected arguments | ||
| 899 | # $profName - The parent profile's name (e.g. matches the object's ->name) | ||
| 900 | # | ||
| 901 | # Return values | ||
| 902 | # 'undef' on improper arguments | ||
| 903 | # Blessed reference to the newly-created object on success | ||
| 904 | |||
| 905 | my ($self, $profName, $check) = @_; | ||
| 906 | |||
| 907 | # Check for improper arguments | ||
| 908 | if (! defined $profName || defined $check) { | ||
| 909 | |||
| 910 | return $axmud::CLIENT->writeImproper($self->_objClass . '->clone', @_); | ||
| 911 | } | ||
| 912 | |||
| 913 | # Setup | ||
| 914 | my $clone = { | ||
| 915 | _objName => $self->_objName, | ||
| 916 | _objClass => $self->_objClass, | ||
| 917 | _parentFile => 'otherprof', | ||
| 918 | _parentWorld => $profName, | ||
| 919 | _privFlag => TRUE, # All IVs are private | ||
| 920 | |||
| 921 | # Interface category | ||
| 922 | # ------------------ | ||
| 923 | |||
| 924 | category => $self->category, | ||
| 925 | |||
| 926 | # Standard interface attributes | ||
| 927 | # ----------------------------- | ||
| 928 | |||
| 929 | name => $self->name, | ||
| 930 | stimulus => $self->stimulus, | ||
| 931 | response => $self->response, | ||
| 932 | enabledFlag => $self->enabledFlag, | ||
| 933 | |||
| 934 | # Macro attributes | ||
| 935 | # ---------------- | ||
| 936 | |||
| 937 | attribHash => {$self->attribHash}, | ||
| 938 | |||
| 939 | # Ordering | ||
| 940 | # -------- | ||
| 941 | |||
| 942 | beforeHash => {$self->beforeHash}, | ||
| 943 | afterHash => {$self->afterHash}, | ||
| 944 | }; | ||
| 945 | |||
| 946 | # Bless the cloned object into existence | ||
| 947 | bless $clone, $self->_objClass; | ||
| 948 | return $clone; | ||
| 949 | } | ||
| 950 | |||
| 951 | ################## | ||
| 952 | # Methods | ||
| 953 | |||
| 954 | ################## | ||
| 955 | # Accessors - set | ||
| 956 | |||
| 957 | ################## | ||
| 958 | # Accessors - get | ||
| 959 | |||
| 960 | sub category | ||
| 961 | { $_[0]->{category} } | ||
| 962 | |||
| 963 | sub name | ||
| 964 | { $_[0]->{name} } | ||
| 965 | sub stimulus | ||
| 966 | { $_[0]->{stimulus} } | ||
| 967 | sub response | ||
| 968 | { $_[0]->{response} } | ||
| 969 | sub enabledFlag | ||
| 970 | { $_[0]->{enabledFlag} } | ||
| 971 | |||
| 972 | sub attribHash | ||
| 973 | { my $self = shift; return %{$self->{attribHash}}; } | ||
| 974 | |||
| 975 | sub beforeHash | ||
| 976 | { my $self = shift; return %{$self->{beforeHash}}; } | ||
| 977 | sub afterHash | ||
| 978 | { my $self = shift; return %{$self->{afterHash}}; } | ||
| 979 | } | ||
| 980 | |||
| 981 | { package Games::Axmud::Interface::Timer; | ||
| 982 | |||
| 983 | use strict; | ||
| 984 | use warnings; | ||
| 985 | use diagnostics; | ||
| 986 | |||
| 987 | use Glib qw(TRUE FALSE); | ||
| 988 | |||
| 989 | our @ISA = qw(Games::Axmud::Generic::Interface Games::Axmud); | ||
| 990 | |||
| 991 | ################## | ||
| 992 | # Constructors | ||
| 993 | |||
| 994 | sub new { | ||
| 995 | |||
| 996 | # Creates a new instance of the timer object | ||
| 997 | # | ||
| 998 | # Axmud interfaces are triggers, aliases, macros, timers and hooks. Depending on which | ||
| 999 | # profiles are current ones, and how many current profiles have interfaces with the same | ||
| 1000 | # name, an interface can be 'active' or 'inactive' | ||
| 1001 | # | ||
| 1002 | # This object represents an 'inactive' timer. It is stored in a cage, attached to a | ||
| 1003 | # particular profile | ||
| 1004 | # When the profile becomes a current profile, and provided that there are no other superior | ||
| 1005 | # profiles which have a timer with the same ->name, the timer becomes 'active' | ||
| 1006 | # When a timer becomes active, GA::Session creates a GA::Interface::Active object, | ||
| 1007 | # copying it into its registries of active interfaces | ||
| 1008 | # When the timer becomes inactive again, the GA::Interface::Active object is destroyed (but | ||
| 1009 | # this object continues to exist throughout) | ||
| 1010 | # | ||
| 1011 | # Expected arguments | ||
| 1012 | # $session - The GA::Session which created this object (not stored as an IV) | ||
| 1013 | # $name - A name for the timer which is unique within its cage, but which could | ||
| 1014 | # be the same as the name of other timers in other cages (e.g. | ||
| 1015 | # 'mytimer') (max 32 chars) | ||
| 1016 | # $stimulus - The stimulus (an interval or 24-hour clock time, for timers) | ||
| 1017 | # $response - The response (an action, for timers) | ||
| 1018 | # | ||
| 1019 | # Optional arguments | ||
| 1020 | # $enabledFlag - A flag, TRUE if (when the timer becomes active) it is responsive, | ||
| 1021 | # FALSE if it does nothing (if 'undef', the attribute is set to TRUE) | ||
| 1022 | # | ||
| 1023 | # Return values | ||
| 1024 | # 'undef' on improper arguments | ||
| 1025 | # Blessed reference to the newly-created object on success | ||
| 1026 | |||
| 1027 | my ($class, $session, $name, $stimulus, $response, $enabledFlag, $check) = @_; | ||
| 1028 | |||
| 1029 | # Local variables | ||
| 1030 | my $flag; | ||
| 1031 | |||
| 1032 | # Check for improper arguments | ||
| 1033 | if ( | ||
| 1034 | ! defined $class || ! defined $session || ! defined $name || ! defined $stimulus | ||
| 1035 | || ! defined $response || defined $check | ||
| 1036 | ) { | ||
| 1037 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 1038 | } | ||
| 1039 | |||
| 1040 | # Translate all values of $enabledFlag into TRUE of FALSE | ||
| 1041 | if (! defined $enabledFlag || $enabledFlag) { | ||
| 1042 | $flag = TRUE; # Default is TRUE | ||
| 1043 | } else { | ||
| 1044 | $flag = FALSE; | ||
| 1045 | } | ||
| 1046 | |||
| 1047 | # Setup | ||
| 1048 | my $self = { | ||
| 1049 | _objName => $name, | ||
| 1050 | _objClass => $class, | ||
| 1051 | _parentFile => 'otherprof', | ||
| 1052 | _parentWorld => $session->currentWorld->name, | ||
| 1053 | _privFlag => TRUE, # All IVs are private | ||
| 1054 | |||
| 1055 | # Interface category | ||
| 1056 | # ------------------ | ||
| 1057 | |||
| 1058 | category => 'timer', # Shortcut to $self->_objClass | ||
| 1059 | |||
| 1060 | # Standard interface attributes | ||
| 1061 | # ----------------------------- | ||
| 1062 | |||
| 1063 | name => $name, # Max 32 chars | ||
| 1064 | stimulus => $stimulus, # An interval or 24-hour clock time | ||
| 1065 | response => $response, # An instruction | ||
| 1066 | enabledFlag => $flag, | ||
| 1067 | |||
| 1068 | # Timer attributes | ||
| 1069 | # ------------------ | ||
| 1070 | |||
| 1071 | # Current values for each timer attribute (initially set to defaults) | ||
| 1072 | attribHash => { | ||
| 1073 | 'count' => -1, | ||
| 1074 | 'initial_delay' => 0, | ||
| 1075 | 'random_delay' => FALSE, | ||
| 1076 | 'random_min' => 0, | ||
| 1077 | 'wait_login' => TRUE, | ||
| 1078 | 'temporary' => FALSE, | ||
| 1079 | }, | ||
| 1080 | |||
| 1081 | # Ordering | ||
| 1082 | # -------- | ||
| 1083 | |||
| 1084 | # A hash of inactive timer names. When this timer becomes active, all other active | ||
| 1085 | # timers are checked. If their corresponding inactive timers have names which appear | ||
| 1086 | # in this list, then the active timer corresponding to this object is placed BEFORE | ||
| 1087 | # them in the ordered list of active timers. Hash in the form | ||
| 1088 | # $beforeHash{inactive_timer_name} = undef | ||
| 1089 | beforeHash => {}, | ||
| 1090 | # Hash of inactive timer names; if corresponding active timers exist, this object's | ||
| 1091 | # active timer is placed AFTER them | ||
| 1092 | afterHash => {}, | ||
| 1093 | }; | ||
| 1094 | |||
| 1095 | # Bless the object into existence | ||
| 1096 | bless $self, $class; | ||
| 1097 | return $self; | ||
| 1098 | } | ||
| 1099 | |||
| 1100 | sub clone { | ||
| 1101 | |||
| 1102 | # Creates a clone of an existing interface; only used when the parent cage is cloned | ||
| 1103 | # | ||
| 1104 | # Expected arguments | ||
| 1105 | # $profName - The parent profile's name (e.g. matches the object's ->name) | ||
| 1106 | # | ||
| 1107 | # Return values | ||
| 1108 | # 'undef' on improper arguments | ||
| 1109 | # Blessed reference to the newly-created object on success | ||
| 1110 | |||
| 1111 | my ($self, $profName, $check) = @_; | ||
| 1112 | |||
| 1113 | # Check for improper arguments | ||
| 1114 | if (! defined $profName || defined $check) { | ||
| 1115 | |||
| 1116 | return $axmud::CLIENT->writeImproper($self->_objClass . '->clone', @_); | ||
| 1117 | } | ||
| 1118 | |||
| 1119 | # Setup | ||
| 1120 | my $clone = { | ||
| 1121 | _objName => $self->_objName, | ||
| 1122 | _objClass => $self->_objClass, | ||
| 1123 | _parentFile => 'otherprof', | ||
| 1124 | _parentWorld => $profName, | ||
| 1125 | _privFlag => TRUE, # All IVs are private | ||
| 1126 | |||
| 1127 | # Interface category | ||
| 1128 | # ------------------ | ||
| 1129 | |||
| 1130 | category => $self->category, | ||
| 1131 | |||
| 1132 | # Standard interface attributes | ||
| 1133 | # ----------------------------- | ||
| 1134 | |||
| 1135 | name => $self->name, | ||
| 1136 | stimulus => $self->stimulus, | ||
| 1137 | response => $self->response, | ||
| 1138 | enabledFlag => $self->enabledFlag, | ||
| 1139 | |||
| 1140 | # Timer attributes | ||
| 1141 | # ---------------- | ||
| 1142 | |||
| 1143 | attribHash => {$self->attribHash}, | ||
| 1144 | |||
| 1145 | # Ordering | ||
| 1146 | # -------- | ||
| 1147 | |||
| 1148 | beforeHash => {$self->beforeHash}, | ||
| 1149 | afterHash => {$self->afterHash}, | ||
| 1150 | }; | ||
| 1151 | |||
| 1152 | # Bless the cloned object into existence | ||
| 1153 | bless $clone, $self->_objClass; | ||
| 1154 | return $clone; | ||
| 1155 | } | ||
| 1156 | |||
| 1157 | ################## | ||
| 1158 | # Methods | ||
| 1159 | |||
| 1160 | ################## | ||
| 1161 | # Accessors - set | ||
| 1162 | |||
| 1163 | ################## | ||
| 1164 | # Accessors - get | ||
| 1165 | |||
| 1166 | sub category | ||
| 1167 | { $_[0]->{category} } | ||
| 1168 | |||
| 1169 | sub name | ||
| 1170 | { $_[0]->{name} } | ||
| 1171 | sub stimulus | ||
| 1172 | { $_[0]->{stimulus} } | ||
| 1173 | sub response | ||
| 1174 | { $_[0]->{response} } | ||
| 1175 | sub enabledFlag | ||
| 1176 | { $_[0]->{enabledFlag} } | ||
| 1177 | |||
| 1178 | sub attribHash | ||
| 1179 | { my $self = shift; return %{$self->{attribHash}}; } | ||
| 1180 | |||
| 1181 | sub beforeHash | ||
| 1182 | { my $self = shift; return %{$self->{beforeHash}}; } | ||
| 1183 | sub afterHash | ||
| 1184 | { my $self = shift; return %{$self->{afterHash}}; } | ||
| 1185 | } | ||
| 1186 | |||
| 1187 | { package Games::Axmud::Interface::Hook; | ||
| 1188 | |||
| 1189 | use strict; | ||
| 1190 | use warnings; | ||
| 1191 | use diagnostics; | ||
| 1192 | |||
| 1193 | use Glib qw(TRUE FALSE); | ||
| 1194 | |||
| 1195 | our @ISA = qw(Games::Axmud::Generic::Interface Games::Axmud); | ||
| 1196 | |||
| 1197 | ################## | ||
| 1198 | # Constructors | ||
| 1199 | |||
| 1200 | sub new { | ||
| 1201 | |||
| 1202 | # Creates a new instance of the hook object | ||
| 1203 | # | ||
| 1204 | # Axmud interfaces are triggers, aliases, macros, timers and hooks. Depending on which | ||
| 1205 | # profiles are current ones, and how many current profiles have interfaces with the same | ||
| 1206 | # name, an interface can be 'active' or 'inactive' | ||
| 1207 | # | ||
| 1208 | # This object represents an 'inactive' hook. It is stored in a cage, attached to a | ||
| 1209 | # particular profile | ||
| 1210 | # When the profile becomes a current profile, and provided that there are no other superior | ||
| 1211 | # profiles which have a hook with the same ->name, the hook becomes 'active' | ||
| 1212 | # When a hook becomes active, GA::Session creates a GA::Interface::Active object, copying | ||
| 1213 | # it into its registries of active interfaces | ||
| 1214 | # When the hook becomes inactive again, the GA::Interface::Active object is destroyed (but | ||
| 1215 | # this object continues to exist throughout) | ||
| 1216 | # | ||
| 1217 | # Expected arguments | ||
| 1218 | # $session - The GA::Session which created this object (not stored as an IV) | ||
| 1219 | # $name - A name for the hook which is unique within its cage, but which could | ||
| 1220 | # be the same as the name of other hooks in other cages (e.g. | ||
| 1221 | # 'myhook') (max 32 chars) | ||
| 1222 | # $stimulus - The stimulus (an event, for hooks) | ||
| 1223 | # $response - The response (an action, for hooks) | ||
| 1224 | # | ||
| 1225 | # Optional arguments | ||
| 1226 | # $enabledFlag - A flag, TRUE if (when the hook becomes active) it is responsive, | ||
| 1227 | # FALSE if it does nothing (if 'undef', the attribute is set to TRUE) | ||
| 1228 | # | ||
| 1229 | # Return values | ||
| 1230 | # 'undef' on improper arguments | ||
| 1231 | # Blessed reference to the newly-created object on success | ||
| 1232 | |||
| 1233 | my ($class, $session, $name, $stimulus, $response, $enabledFlag, $check) = @_; | ||
| 1234 | |||
| 1235 | # Local variables | ||
| 1236 | my $flag; | ||
| 1237 | |||
| 1238 | # Check for improper arguments | ||
| 1239 | if ( | ||
| 1240 | ! defined $class || ! defined $session || ! defined $name || ! defined $stimulus | ||
| 1241 | || ! defined $response || defined $check | ||
| 1242 | ) { | ||
| 1243 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 1244 | } | ||
| 1245 | |||
| 1246 | # Translate all values of $enabledFlag into TRUE of FALSE | ||
| 1247 | if (! defined $enabledFlag || $enabledFlag) { | ||
| 1248 | $flag = TRUE; # Default is TRUE | ||
| 1249 | } else { | ||
| 1250 | $flag = FALSE; | ||
| 1251 | } | ||
| 1252 | |||
| 1253 | # Setup | ||
| 1254 | my $self = { | ||
| 1255 | _objName => $name, | ||
| 1256 | _objClass => $class, | ||
| 1257 | _parentFile => 'otherprof', | ||
| 1258 | _parentWorld => $session->currentWorld->name, | ||
| 1259 | _privFlag => TRUE, # All IVs are private | ||
| 1260 | |||
| 1261 | # Interface category | ||
| 1262 | # ------------------ | ||
| 1263 | |||
| 1264 | category => 'hook', # Shortcut to $self->_objClass | ||
| 1265 | |||
| 1266 | # Standard interface attributes | ||
| 1267 | # ----------------------------- | ||
| 1268 | |||
| 1269 | name => $name, # Max 32 chars | ||
| 1270 | stimulus => $stimulus, # A hook event | ||
| 1271 | response => $response, # An instruction | ||
| 1272 | enabledFlag => $flag, | ||
| 1273 | |||
| 1274 | # Hook attributes | ||
| 1275 | # --------------- | ||
| 1276 | |||
| 1277 | # Current values for each hook attribute (initially set to defaults) | ||
| 1278 | attribHash => { | ||
| 1279 | 'temporary' => FALSE, | ||
| 1280 | 'cooldown' => 0, | ||
| 1281 | }, | ||
| 1282 | |||
| 1283 | # Ordering | ||
| 1284 | # -------- | ||
| 1285 | |||
| 1286 | # A hash of inactive hook names. When this hook becomes active, all other active hooks | ||
| 1287 | # are checked. If their corresponding inactive hooks have names which appear in this | ||
| 1288 | # list, then the active hook corresponding to this object is placed BEFORE them in the | ||
| 1289 | # ordered list of active hooks. Hash in the form | ||
| 1290 | # $beforeHash{inactive_hook_name} = undef | ||
| 1291 | beforeHash => {}, | ||
| 1292 | # Hash of inactive hook names; if corresponding active hooks exist, this object's | ||
| 1293 | # active hook is placed AFTER them | ||
| 1294 | afterHash => {}, | ||
| 1295 | }; | ||
| 1296 | |||
| 1297 | # Bless the object into existence | ||
| 1298 | bless $self, $class; | ||
| 1299 | return $self; | ||
| 1300 | } | ||
| 1301 | |||
| 1302 | sub clone { | ||
| 1303 | |||
| 1304 | # Creates a clone of an existing interface; only used when the parent cage is cloned | ||
| 1305 | # | ||
| 1306 | # Expected arguments | ||
| 1307 | # $profName - The parent profile's name (e.g. matches the object's ->name) | ||
| 1308 | # | ||
| 1309 | # Return values | ||
| 1310 | # 'undef' on improper arguments | ||
| 1311 | # Blessed reference to the newly-created object on success | ||
| 1312 | |||
| 1313 | my ($self, $profName, $check) = @_; | ||
| 1314 | |||
| 1315 | # Check for improper arguments | ||
| 1316 | if (! defined $profName || defined $check) { | ||
| 1317 | |||
| 1318 | return $axmud::CLIENT->writeImproper($self->_objClass . '->clone', @_); | ||
| 1319 | } | ||
| 1320 | |||
| 1321 | # Setup | ||
| 1322 | my $clone = { | ||
| 1323 | _objName => $self->_objName, | ||
| 1324 | _objClass => $self->_objClass, | ||
| 1325 | _parentFile => 'otherprof', | ||
| 1326 | _parentWorld => $profName, | ||
| 1327 | _privFlag => TRUE, # All IVs are private | ||
| 1328 | |||
| 1329 | # Interface category | ||
| 1330 | # ------------------ | ||
| 1331 | |||
| 1332 | category => $self->category, | ||
| 1333 | |||
| 1334 | # Standard interface attributes | ||
| 1335 | # ----------------------------- | ||
| 1336 | |||
| 1337 | name => $self->name, | ||
| 1338 | stimulus => $self->stimulus, | ||
| 1339 | response => $self->response, | ||
| 1340 | enabledFlag => $self->enabledFlag, | ||
| 1341 | |||
| 1342 | # Hook attributes | ||
| 1343 | # --------------- | ||
| 1344 | |||
| 1345 | attribHash => {$self->attribHash}, | ||
| 1346 | |||
| 1347 | # Ordering | ||
| 1348 | # -------- | ||
| 1349 | |||
| 1350 | beforeHash => {$self->beforeHash}, | ||
| 1351 | afterHash => {$self->afterHash}, | ||
| 1352 | }; | ||
| 1353 | |||
| 1354 | # Bless the cloned object into existence | ||
| 1355 | bless $clone, $self->_objClass; | ||
| 1356 | return $clone; | ||
| 1357 | } | ||
| 1358 | |||
| 1359 | ################## | ||
| 1360 | # Methods | ||
| 1361 | |||
| 1362 | ################## | ||
| 1363 | # Accessors - set | ||
| 1364 | |||
| 1365 | ################## | ||
| 1366 | # Accessors - get | ||
| 1367 | |||
| 1368 | sub category | ||
| 1369 | { $_[0]->{category} } | ||
| 1370 | |||
| 1371 | sub name | ||
| 1372 | { $_[0]->{name} } | ||
| 1373 | sub stimulus | ||
| 1374 | { $_[0]->{stimulus} } | ||
| 1375 | sub response | ||
| 1376 | { $_[0]->{response} } | ||
| 1377 | sub enabledFlag | ||
| 1378 | { $_[0]->{enabledFlag} } | ||
| 1379 | |||
| 1380 | sub attribHash | ||
| 1381 | { my $self = shift; return %{$self->{attribHash}}; } | ||
| 1382 | |||
| 1383 | sub beforeHash | ||
| 1384 | { my $self = shift; return %{$self->{beforeHash}}; } | ||
| 1385 | sub afterHash | ||
| 1386 | { my $self = shift; return %{$self->{afterHash}}; } | ||
| 1387 | } | ||
| 1388 | |||
| 1389 | # Package must return a true value | ||
| 1390 | 1 |