| 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::Cage::XXX | ||
| 16 | # The code that handles a cage | ||
| 17 | |||
| 18 | { package Games::Axmud::Cage::Cmd; | ||
| 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::Cage Games::Axmud); | ||
| 27 | |||
| 28 | ################## | ||
| 29 | # Constructors | ||
| 30 | |||
| 31 | sub new { | ||
| 32 | |||
| 33 | # Creates a new instance of the command cage | ||
| 34 | # | ||
| 35 | # Expected arguments | ||
| 36 | # $session - The calling function's GA::Session (not stored as an IV) | ||
| 37 | # $profName - The parent profile's name (e.g. matches the object's ->name) | ||
| 38 | # $profCategory - The profile's category (e.g. 'world', 'guild', 'faction' etc) | ||
| 39 | # | ||
| 40 | # Return values | ||
| 41 | # 'undef' on improper arguments or if the cage already seems to exist | ||
| 42 | # Blessed reference to the newly-created object on success | ||
| 43 | |||
| 44 | my ($class, $session, $profName, $profCategory, $check) = @_; | ||
| 45 | |||
| 46 | # Local variables | ||
| 47 | my $name; | ||
| 48 | |||
| 49 | # Check for improper arguments | ||
| 50 | if ( | ||
| 51 | ! defined $class || ! defined $session || ! defined $profName || ! defined $profCategory | ||
| 52 | || defined $check | ||
| 53 | ) { | ||
| 54 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 55 | } | ||
| 56 | |||
| 57 | # Compose the cage's unique name | ||
| 58 | $name = 'cmd_' . $profCategory . '_' . $profName; | ||
| 59 | |||
| 60 | # Check that $name is valid and not already in use by another profile | ||
| 61 | if (! $axmud::CLIENT->nameCheck($name, 42)) { | ||
| 62 | |||
| 63 | return $axmud::CLIENT->writeError( | ||
| 64 | 'Registry naming error: invalid name \'' . $name . '\'', | ||
| 65 | $class . '->new', | ||
| 66 | ); | ||
| 67 | |||
| 68 | } elsif ($session->ivExists('cageHash', $name)) { | ||
| 69 | |||
| 70 | return $axmud::CLIENT->writeError( | ||
| 71 | 'Registry naming error: cage \'' . $name . '\' already exists', | ||
| 72 | $class . '->new', | ||
| 73 | ); | ||
| 74 | } | ||
| 75 | |||
| 76 | # Setup | ||
| 77 | my $self = { | ||
| 78 | _objName => $name, | ||
| 79 | _objClass => $class, | ||
| 80 | _parentFile => 'otherprof', | ||
| 81 | _parentWorld => $session->currentWorld->name, | ||
| 82 | _privFlag => FALSE, # All IVs are public | ||
| 83 | |||
| 84 | # Standard cage IVs | ||
| 85 | # ----------------- | ||
| 86 | |||
| 87 | name => $name, | ||
| 88 | cageType => 'cmd', | ||
| 89 | standardFlag => TRUE, # This is a built-in Axmud cage | ||
| 90 | profName => $profName, | ||
| 91 | profCategory => $profCategory, | ||
| 92 | |||
| 93 | # Command cage IVs | ||
| 94 | # ---------------- | ||
| 95 | |||
| 96 | # Hash of standard commands and their replacements for the parent profile, in the form | ||
| 97 | # $commandHash{standard_command} = replacement_command | ||
| 98 | # | ||
| 99 | # Any word in the replacement_command can be changed (or 'interpolated') by the code | ||
| 100 | # that wants to send a command to the world, but the words 'object', 'direction', | ||
| 101 | # 'victim', 'text', 'menu' and 'number' are almost always interpolated | ||
| 102 | # e.g. ->commandHash{'climb'} = 'climb object' | ||
| 103 | # e.g. ->commandHash{'throw_dir'} = 'throw object direction' | ||
| 104 | # If a standard command isn't available at this world, the replacement_command should be | ||
| 105 | # set to an empty string. | ||
| 106 | # e.g. ->commandHash{'wake'} = '' | ||
| 107 | # If this cage should consult a lower-priority cage to get the replacement command, the | ||
| 108 | # replacement_command should be set to undef. | ||
| 109 | cmdHash => {}, # Set below | ||
| 110 | # Hash of common words (nouns and pronouns) which should be automatically interpolated | ||
| 111 | # For example, the standard command 'buy' has a replacement command 'buy object' which | ||
| 112 | # is usually interpolated into something like 'buy torch', but the command 'kill all' | ||
| 113 | # contains a very common object - 'all' - which should be automatically interpolated | ||
| 114 | wordHash => {}, # Set below | ||
| 115 | |||
| 116 | # A list of the standard commands used for movement (usually, those which include | ||
| 117 | # 'direction' in the replacement_command). Used by GA::Buffer::Cmd->interpretCmd to | ||
| 118 | # detect when a movement command has taken place | ||
| 119 | moveCmdList => [ | ||
| 120 | 'go_dir', | ||
| 121 | 'run', | ||
| 122 | 'walk', | ||
| 123 | 'fly', | ||
| 124 | 'swim', | ||
| 125 | 'dive', | ||
| 126 | 'sail', | ||
| 127 | 'ride', | ||
| 128 | 'drive', | ||
| 129 | 'creep', | ||
| 130 | 'sneak', | ||
| 131 | 'squeeze', | ||
| 132 | 'move', | ||
| 133 | 'go', | ||
| 134 | ], | ||
| 135 | }; | ||
| 136 | |||
| 137 | # Bless the object into existence | ||
| 138 | bless $self, $class; | ||
| 139 | |||
| 140 | # Set the contents of the command cage's IVs | ||
| 141 | $self->setup(); | ||
| 142 | |||
| 143 | return $self; | ||
| 144 | } | ||
| 145 | |||
| 146 | sub clone { | ||
| 147 | |||
| 148 | # Creates a clone of an existing command cage | ||
| 149 | # | ||
| 150 | # Expected arguments | ||
| 151 | # $session - The calling function's GA::Session (not stored as an IV) | ||
| 152 | # $profName - The parent profile's name (e.g. matches the object's ->name) | ||
| 153 | # $profCategory - The profile's category (e.g. 'world', 'guild', 'faction' etc) | ||
| 154 | # | ||
| 155 | # Return values | ||
| 156 | # 'undef' on improper arguments or if the cage already seems to exist | ||
| 157 | # Blessed reference to the newly-created object on success | ||
| 158 | |||
| 159 | my ($self, $session, $profName, $profCategory, $check) = @_; | ||
| 160 | |||
| 161 | # Local variables | ||
| 162 | my $name; | ||
| 163 | |||
| 164 | # Check for improper arguments | ||
| 165 | if ( | ||
| 166 | ! defined $session || ! defined $profName || ! defined $profCategory | ||
| 167 | || defined $check | ||
| 168 | ) { | ||
| 169 | return $axmud::CLIENT->writeImproper($self->_objClass . '->clone', @_); | ||
| 170 | } | ||
| 171 | |||
| 172 | # Compose the cage's unique name | ||
| 173 | $name = 'cmd_' . $profCategory . '_' . $profName; | ||
| 174 | |||
| 175 | # Check that $name is valid and not already in use by another profile | ||
| 176 | if (! $axmud::CLIENT->nameCheck($name, 42)) { | ||
| 177 | |||
| 178 | return $axmud::CLIENT->writeError( | ||
| 179 | 'Registry naming error: invalid name \'' . $name . '\'', | ||
| 180 | $self->_objClass . '->clone', | ||
| 181 | ); | ||
| 182 | |||
| 183 | } elsif ($session->ivExists('cageHash', $name)) { | ||
| 184 | |||
| 185 | return $axmud::CLIENT->writeError( | ||
| 186 | 'Registry naming error: cage \'' . $name . '\' already exists', | ||
| 187 | $self->_objClass . '->clone', | ||
| 188 | ); | ||
| 189 | } | ||
| 190 | |||
| 191 | # Setup | ||
| 192 | my $clone = { | ||
| 193 | _objName => $name, | ||
| 194 | _objClass => $self->_objClass, | ||
| 195 | _parentFile => 'otherprof', | ||
| 196 | _parentWorld => undef, | ||
| 197 | _privFlag => FALSE, # All IVs are public | ||
| 198 | |||
| 199 | # Standard cage IVs | ||
| 200 | # ----------------- | ||
| 201 | |||
| 202 | name => $name, | ||
| 203 | cageType => 'cmd', | ||
| 204 | standardFlag => TRUE, # This is a built-in Axmud cage | ||
| 205 | profName => $profName, | ||
| 206 | profCategory => $profCategory, | ||
| 207 | |||
| 208 | # Command cage IVs | ||
| 209 | # ---------------- | ||
| 210 | |||
| 211 | cmdHash => {$self->cmdHash}, | ||
| 212 | wordHash => {$self->wordHash}, | ||
| 213 | |||
| 214 | moveCmdList => [$self->moveCmdList], | ||
| 215 | }; | ||
| 216 | |||
| 217 | # Bless the cloned object into existence | ||
| 218 | bless $clone, $self->_objClass; | ||
| 219 | return $clone; | ||
| 220 | } | ||
| 221 | |||
| 222 | ################## | ||
| 223 | # Methods | ||
| 224 | |||
| 225 | sub setup { | ||
| 226 | |||
| 227 | # Called by $self->new | ||
| 228 | # Sets the contents of the command cage's IVs | ||
| 229 | # | ||
| 230 | # Expected arguments | ||
| 231 | # (none besides $self) | ||
| 232 | # | ||
| 233 | # Return values | ||
| 234 | # 'undef' on improper arguments | ||
| 235 | # 1 otherwise | ||
| 236 | |||
| 237 | my ($self, $check) = @_; | ||
| 238 | |||
| 239 | # Local variables | ||
| 240 | my ( | ||
| 241 | @list, | ||
| 242 | %cmdHash, %wordHash, | ||
| 243 | ); | ||
| 244 | |||
| 245 | # Check for improper arguments | ||
| 246 | if (defined $check) { | ||
| 247 | |||
| 248 | return $axmud::CLIENT->writeImproper($self->_objClass . '->setup', @_); | ||
| 249 | } | ||
| 250 | |||
| 251 | # Standard commands and their replacements | ||
| 252 | @list = ( | ||
| 253 | # NB If new standard commands are added, the GA::Buffer::Cmd->interpretCmd function | ||
| 254 | # may need to be modified | ||
| 255 | |||
| 256 | # connect to world | ||
| 257 | connect => 'connect name password', | ||
| 258 | # send maximum columns to world | ||
| 259 | cols => 'cols number', | ||
| 260 | # send maximum rows to world | ||
| 261 | rows => 'rows number', | ||
| 262 | # send termtype (e.g. ansi) to world | ||
| 263 | term => 'term text', | ||
| 264 | |||
| 265 | # Turns on verbose descriptions | ||
| 266 | verbose => 'brief off', | ||
| 267 | # Turns on brief descriptions | ||
| 268 | brief => 'brief on', | ||
| 269 | |||
| 270 | # get full room description | ||
| 271 | look => 'look', | ||
| 272 | short_look => 'l', | ||
| 273 | # get brief room description | ||
| 274 | glance => 'glance', | ||
| 275 | short_glance => 'gl', | ||
| 276 | # get inventory | ||
| 277 | inventory => 'inventory', | ||
| 278 | # search room for hidden objects | ||
| 279 | search => 'search', | ||
| 280 | # examine object | ||
| 281 | examine => 'examine object', | ||
| 282 | |||
| 283 | # run in a direction | ||
| 284 | run => 'run direction', | ||
| 285 | # walk in a direction | ||
| 286 | walk => 'walk direction', | ||
| 287 | # fly in a sirection | ||
| 288 | fly => 'fly direction', | ||
| 289 | # swim in a direction | ||
| 290 | swim => 'swim direction', | ||
| 291 | # dive in a direction | ||
| 292 | dive => 'dive direction', | ||
| 293 | # sail in a direction | ||
| 294 | sail => 'sail direction', | ||
| 295 | # ride in a direction | ||
| 296 | ride => 'ride direction', | ||
| 297 | # drive in a direction | ||
| 298 | drive => 'drive direction', | ||
| 299 | # creep into new room, becoming invisible there | ||
| 300 | creep => 'creep direction', | ||
| 301 | # sneak from the current room, so that the disappearance isn't seen by other beings | ||
| 302 | sneak => 'sneak direction', | ||
| 303 | # squeeze through a small exit | ||
| 304 | squeeze => 'squeeze direction', | ||
| 305 | # go in a direction | ||
| 306 | go_dir => 'go direction', | ||
| 307 | # move in a direction (general-purpose command for any verb not covered above) | ||
| 308 | # move => 'move direction', | ||
| 309 | # (Disabled by default, so 'move box' isn't confused as a movement) | ||
| 310 | move => '', | ||
| 311 | # (For any world in which it's possible to type 'north' to move - a direction, without | ||
| 312 | # a verb - this special standard command covers it. The value should either be | ||
| 313 | # 'direction' - if it's possible to type 'north' in order to move - or an empty | ||
| 314 | # string, if not) | ||
| 315 | go => 'direction', | ||
| 316 | # Special teleportation command, used when the game allows teleportation (reaching a | ||
| 317 | # destination location from many different departure locations). The 'room' word can | ||
| 318 | # be the name used by the world. If the world model has a room with an identical | ||
| 319 | # room tag, that's the assumed target destination; otherwise the target destination | ||
| 320 | # is unknown | ||
| 321 | teleport => 'teleport room', | ||
| 322 | |||
| 323 | # become hidden | ||
| 324 | hide => 'hide', | ||
| 325 | # become unhidden | ||
| 326 | unhide => 'unhide', | ||
| 327 | # climb | ||
| 328 | climb => 'climb', | ||
| 329 | # climb something | ||
| 330 | climb_obj => 'climb object', | ||
| 331 | # jump | ||
| 332 | jump => 'jump', | ||
| 333 | # jump into something | ||
| 334 | jump_obj => 'jump into object', | ||
| 335 | |||
| 336 | # pick something up | ||
| 337 | get => 'get object', | ||
| 338 | # drop something | ||
| 339 | drop => 'drop object', | ||
| 340 | # put something in something | ||
| 341 | put => 'put object in target', | ||
| 342 | # give something to target | ||
| 343 | give_to => 'give object to target', | ||
| 344 | # get something from something | ||
| 345 | get_from => 'get object from target', | ||
| 346 | |||
| 347 | # loot a (single) corpse - get a single object from the corpse | ||
| 348 | loot => 'get object from target', | ||
| 349 | # loot a (single) corpse - get everything from the corpse | ||
| 350 | loot_corpse => 'get all from corpse', | ||
| 351 | # loot a room (use empty string if it's not possible to do 'loot all corpses' with a | ||
| 352 | # single command at this world) | ||
| 353 | loot_room => 'get all from corpses', | ||
| 354 | # rob a (single) corpse - get all cash from the corpse, but leave its possessions intact | ||
| 355 | rob_corpse => 'get coins from corpse', | ||
| 356 | # rob a room | ||
| 357 | rob_room => 'get coins from corpses', | ||
| 358 | # dispose of a (single) corpse | ||
| 359 | dispose_corpse => 'bury corpse', | ||
| 360 | # dispose of every corpses in a room | ||
| 361 | dispose_room => 'bury corpses', | ||
| 362 | |||
| 363 | # throw something | ||
| 364 | throw => 'throw object', | ||
| 365 | # throw object in a direction | ||
| 366 | throw_dir => 'throw object direction', | ||
| 367 | # wave something | ||
| 368 | wave => 'wave object', | ||
| 369 | # wave something at someone | ||
| 370 | wave_victim => 'wave object at victim', | ||
| 371 | # read something | ||
| 372 | read => 'read object', | ||
| 373 | # write something | ||
| 374 | write => 'write text', | ||
| 375 | # write something on something | ||
| 376 | write_on => 'write text on object', | ||
| 377 | |||
| 378 | # run away when health reaches certain level | ||
| 379 | wimpy => 'wimpy number', | ||
| 380 | |||
| 381 | # wield, wear and hold all items | ||
| 382 | equip => 'equip', | ||
| 383 | # stop wielding, wearing and holding all items | ||
| 384 | unequip => 'unequip', | ||
| 385 | # wield a weapon | ||
| 386 | wield => 'wield object', | ||
| 387 | # unwield a weapon | ||
| 388 | unwield => 'lower object', | ||
| 389 | # wear something | ||
| 390 | wear => 'wear object', | ||
| 391 | # stop wearing something | ||
| 392 | unwear => 'remove object', | ||
| 393 | # hold something | ||
| 394 | hold => 'hold object', | ||
| 395 | # stop holding something | ||
| 396 | unhold => 'remove object', | ||
| 397 | |||
| 398 | # attacks - kill target | ||
| 399 | kill => 'kill victim', | ||
| 400 | # kill target using a guild command | ||
| 401 | guild_kill => 'kill victim', | ||
| 402 | # kill target using a race command | ||
| 403 | race_kill => 'kill victim', | ||
| 404 | # attacks - interact with a target (e.g. 'mug victim') | ||
| 405 | interact => 'mug victim', | ||
| 406 | # interact with target using a guild command | ||
| 407 | guild_interact => 'mug victim', | ||
| 408 | # interact with target using a race command | ||
| 409 | race_interact => 'mug victim', | ||
| 410 | |||
| 411 | # say something | ||
| 412 | say => 'say text', | ||
| 413 | # say something to someone | ||
| 414 | say_to => 'say to victim text', | ||
| 415 | # ask something something | ||
| 416 | ask => 'ask victim text', | ||
| 417 | # ask something about something | ||
| 418 | ask_about => 'ask victim about text', | ||
| 419 | # tell someone something | ||
| 420 | tell => 'tell victim text', | ||
| 421 | # tell someone about something | ||
| 422 | tell_about => 'tell victim text', | ||
| 423 | # shout something to all connected characters | ||
| 424 | shout => 'shout text', | ||
| 425 | # say something rude | ||
| 426 | swear => 'damn', | ||
| 427 | |||
| 428 | # read help files | ||
| 429 | help => 'help text', | ||
| 430 | # verbose score | ||
| 431 | score => 'score', | ||
| 432 | # brief score | ||
| 433 | sc => 'sc', | ||
| 434 | # get character's stats (e.g. 'dex', 'int', 'con', etc) | ||
| 435 | stats => 'stats', | ||
| 436 | # character's current level | ||
| 437 | level => 'level', | ||
| 438 | # list of connected characters | ||
| 439 | who => 'who', | ||
| 440 | # game time | ||
| 441 | time => 'time', | ||
| 442 | # real-world time | ||
| 443 | date => 'date', | ||
| 444 | # disconnect | ||
| 445 | quit => 'quit', | ||
| 446 | # set world's termtype | ||
| 447 | term => 'term text', | ||
| 448 | |||
| 449 | # eat something | ||
| 450 | eat => 'eat object', | ||
| 451 | # drink something | ||
| 452 | drink => 'drink object', | ||
| 453 | # go to sleep | ||
| 454 | sleep => 'sleep', | ||
| 455 | # wake up | ||
| 456 | wake => 'wake', | ||
| 457 | |||
| 458 | # cost of advancing a skill | ||
| 459 | cost => 'cost text', | ||
| 460 | # cost of advancing all skills | ||
| 461 | cost_all => 'cost all', | ||
| 462 | # advance a skill | ||
| 463 | advance => 'advance text', | ||
| 464 | |||
| 465 | # tie something | ||
| 466 | tie => 'tie object', | ||
| 467 | # tie something to something else | ||
| 468 | tie_to => 'tie object to object', | ||
| 469 | # untie something | ||
| 470 | untie => 'untie object', | ||
| 471 | # untie something from something else | ||
| 472 | untie_from => 'untie object from object', | ||
| 473 | |||
| 474 | # deposit some money into bank | ||
| 475 | deposit => 'deposit number text coins', | ||
| 476 | # deposit all money | ||
| 477 | deposit_all => 'deposit coins', | ||
| 478 | # deposit all coins of a certain type | ||
| 479 | deposit_type => 'deposit text coins', | ||
| 480 | # withdraw some money from bank | ||
| 481 | withdraw => 'withdraw number text coins', | ||
| 482 | # withdraw all money from bank | ||
| 483 | withdraw_all => 'withdraw coins', | ||
| 484 | # withdraw all coins of a certain type | ||
| 485 | withdraw_type => 'withdraw text coins', | ||
| 486 | # get bank balance | ||
| 487 | balance => 'balance', | ||
| 488 | # open account at bank | ||
| 489 | open_account => 'open account', | ||
| 490 | # close account at bank | ||
| 491 | close_account => 'close account', | ||
| 492 | |||
| 493 | # open a door | ||
| 494 | open => 'open door', | ||
| 495 | # e.g. 'open southwest door' | ||
| 496 | open_dir => 'open direction door', | ||
| 497 | close => 'close door', | ||
| 498 | close_dir => 'close direction door', | ||
| 499 | unlock => 'unlock direction door', | ||
| 500 | unlock_with => 'unlock direction door with keys', | ||
| 501 | lock => 'lock direction door', | ||
| 502 | lock_with => 'lock direction door with keys', | ||
| 503 | pick => 'pick direction door', | ||
| 504 | pick_with => 'pick direction door with lockpick', | ||
| 505 | break => 'break direction door', | ||
| 506 | break_with => 'break direction door with crowbar', | ||
| 507 | |||
| 508 | # follow someone | ||
| 509 | follow => 'follow victim', | ||
| 510 | # stop following someone | ||
| 511 | unfollow => 'unfollow victim', | ||
| 512 | # allow someone to follow | ||
| 513 | consent => 'consent victim', | ||
| 514 | # stop someone from following you | ||
| 515 | lose => 'lose victim', | ||
| 516 | # list people following you | ||
| 517 | followers => 'followers', | ||
| 518 | # protect someone (tank) | ||
| 519 | protect => 'protect victim', | ||
| 520 | # stop protecting someone | ||
| 521 | unprotect => 'unprotect victim', | ||
| 522 | |||
| 523 | # summon guild minions | ||
| 524 | summon => 'summon', | ||
| 525 | # summon specific guild minion | ||
| 526 | summon_victim => 'summon victim', | ||
| 527 | # fighter guild commands | ||
| 528 | resize => 'resize object', | ||
| 529 | repair => 'repair object', | ||
| 530 | # cleric guild commands | ||
| 531 | bury => 'bury object', | ||
| 532 | recite => 'recite text', | ||
| 533 | meditate => 'meditate text', | ||
| 534 | # bard guild commands | ||
| 535 | sing => 'sing text', | ||
| 536 | # wizard guild commands | ||
| 537 | cast => 'cast text', | ||
| 538 | memorise => 'memorise text', | ||
| 539 | |||
| 540 | # buy something | ||
| 541 | buy => 'buy object', | ||
| 542 | # sell something | ||
| 543 | sell => 'sell object', | ||
| 544 | # sell everything | ||
| 545 | sell_all => 'sell all', | ||
| 546 | # value something | ||
| 547 | value => 'value object', | ||
| 548 | # get information about something for sale | ||
| 549 | browse => 'browse object', | ||
| 550 | # list things for sale | ||
| 551 | list => 'list', | ||
| 552 | # list of things for sale at pub/cafe | ||
| 553 | read_menu => 'read menu', | ||
| 554 | ); | ||
| 555 | |||
| 556 | do { | ||
| 557 | |||
| 558 | my $standard = shift @list; | ||
| 559 | my $replacement = shift @list; | ||
| 560 | |||
| 561 | if ($self->profCategory eq 'world') { | ||
| 562 | |||
| 563 | $cmdHash{$standard} = $replacement; | ||
| 564 | |||
| 565 | } else { | ||
| 566 | |||
| 567 | # Higher-priority cage have 'undef' as replacements so that the cage belonging to | ||
| 568 | # the next profile in the priority list can be consulted | ||
| 569 | $cmdHash{$standard} = undef; | ||
| 570 | } | ||
| 571 | |||
| 572 | } until (! @list); | ||
| 573 | |||
| 574 | # Other words and their replacement words | ||
| 575 | @list = ( | ||
| 576 | # The word for 'all' | ||
| 577 | all => 'all', | ||
| 578 | # The world's word for 'all non-player characters' | ||
| 579 | mall => 'mall', | ||
| 580 | # The word for coin | ||
| 581 | coin => 'coin', | ||
| 582 | # The word for coins | ||
| 583 | coins => 'coins', | ||
| 584 | # The word for your character | ||
| 585 | me => 'me', | ||
| 586 | # The word for all characters in your group (not available on most worlds) | ||
| 587 | us => 'us', | ||
| 588 | # The word for any object, used in context (not available on most worlds) | ||
| 589 | it => 'it', | ||
| 590 | # The word for any group of objects, used in context (not available on most worlds) | ||
| 591 | them => 'them', | ||
| 592 | ); | ||
| 593 | |||
| 594 | do { | ||
| 595 | |||
| 596 | my $standard = shift @list; | ||
| 597 | my $replacement = shift @list; | ||
| 598 | |||
| 599 | if ($self->profCategory eq 'world') { | ||
| 600 | |||
| 601 | $wordHash{$standard} = $replacement; | ||
| 602 | |||
| 603 | } else { | ||
| 604 | |||
| 605 | # Higher-priority cage have 'undef' as replacements so that the cage belonging to | ||
| 606 | # the next profile in the priority list can be consulted | ||
| 607 | $wordHash{$standard} = undef; | ||
| 608 | } | ||
| 609 | |||
| 610 | } until (! @list); | ||
| 611 | |||
| 612 | # Update IVs | ||
| 613 | $self->{cmdHash} = \%cmdHash; | ||
| 614 | $self->{wordHash} = \%wordHash; | ||
| 615 | |||
| 616 | return 1; | ||
| 617 | } | ||
| 618 | |||
| 619 | ################## | ||
| 620 | # Accessors - set | ||
| 621 | |||
| 622 | ################## | ||
| 623 | # Accessors - get | ||
| 624 | |||
| 625 | # NB These methods set/return the cage's ACTUAL command hash. To get/set values from this hash | ||
| 626 | # AND/OR its inferiors, use the generic cage's ->ivXXX functions | ||
| 627 | sub cmdHash | ||
| 628 | { my $self = shift; return %{$self->{cmdHash}}; } | ||
| 629 | sub wordHash | ||
| 630 | { my $self = shift; return %{$self->{wordHash}}; } | ||
| 631 | |||
| 632 | sub moveCmdList | ||
| 633 | { my $self = shift; return @{$self->{moveCmdList}}; } | ||
| 634 | } | ||
| 635 | |||
| 636 | { package Games::Axmud::Cage::Trigger; | ||
| 637 | |||
| 638 | use strict; | ||
| 639 | use warnings; | ||
| 640 | # use diagnostics; | ||
| 641 | |||
| 642 | use Glib qw(TRUE FALSE); | ||
| 643 | |||
| 644 | our @ISA = qw( | ||
| 645 | Games::Axmud::Generic::InterfaceCage Games::Axmud::Generic::Cage | ||
| 646 | Games::Axmud | ||
| 647 | ); | ||
| 648 | |||
| 649 | ################## | ||
| 650 | # Constructors | ||
| 651 | |||
| 652 | ################## | ||
| 653 | # Methods | ||
| 654 | |||
| 655 | ################## | ||
| 656 | # Accessors - set | ||
| 657 | |||
| 658 | ################## | ||
| 659 | # Accessors - get | ||
| 660 | } | ||
| 661 | |||
| 662 | { package Games::Axmud::Cage::Alias; | ||
| 663 | |||
| 664 | use strict; | ||
| 665 | use warnings; | ||
| 666 | # use diagnostics; | ||
| 667 | |||
| 668 | use Glib qw(TRUE FALSE); | ||
| 669 | |||
| 670 | our @ISA = qw( | ||
| 671 | Games::Axmud::Generic::InterfaceCage Games::Axmud::Generic::Cage | ||
| 672 | Games::Axmud | ||
| 673 | ); | ||
| 674 | |||
| 675 | ################## | ||
| 676 | # Constructors | ||
| 677 | |||
| 678 | ################## | ||
| 679 | # Methods | ||
| 680 | |||
| 681 | ################## | ||
| 682 | # Accessors - set | ||
| 683 | |||
| 684 | ################## | ||
| 685 | # Accessors - get | ||
| 686 | } | ||
| 687 | |||
| 688 | { package Games::Axmud::Cage::Macro; | ||
| 689 | |||
| 690 | use strict; | ||
| 691 | use warnings; | ||
| 692 | # use diagnostics; | ||
| 693 | |||
| 694 | use Glib qw(TRUE FALSE); | ||
| 695 | |||
| 696 | our @ISA = qw( | ||
| 697 | Games::Axmud::Generic::InterfaceCage Games::Axmud::Generic::Cage | ||
| 698 | Games::Axmud | ||
| 699 | ); | ||
| 700 | |||
| 701 | ################## | ||
| 702 | # Constructors | ||
| 703 | |||
| 704 | ################## | ||
| 705 | # Methods | ||
| 706 | |||
| 707 | ################## | ||
| 708 | # Accessors - set | ||
| 709 | |||
| 710 | ################## | ||
| 711 | # Accessors - get | ||
| 712 | } | ||
| 713 | |||
| 714 | { package Games::Axmud::Cage::Timer; | ||
| 715 | |||
| 716 | use strict; | ||
| 717 | use warnings; | ||
| 718 | # use diagnostics; | ||
| 719 | |||
| 720 | use Glib qw(TRUE FALSE); | ||
| 721 | |||
| 722 | our @ISA = qw( | ||
| 723 | Games::Axmud::Generic::InterfaceCage Games::Axmud::Generic::Cage | ||
| 724 | Games::Axmud | ||
| 725 | ); | ||
| 726 | |||
| 727 | ################## | ||
| 728 | # Constructors | ||
| 729 | |||
| 730 | ################## | ||
| 731 | # Methods | ||
| 732 | |||
| 733 | ################## | ||
| 734 | # Accessors - set | ||
| 735 | |||
| 736 | ################## | ||
| 737 | # Accessors - get | ||
| 738 | } | ||
| 739 | |||
| 740 | { package Games::Axmud::Cage::Hook; | ||
| 741 | |||
| 742 | use strict; | ||
| 743 | use warnings; | ||
| 744 | # use diagnostics; | ||
| 745 | |||
| 746 | use Glib qw(TRUE FALSE); | ||
| 747 | |||
| 748 | our @ISA = qw( | ||
| 749 | Games::Axmud::Generic::InterfaceCage Games::Axmud::Generic::Cage | ||
| 750 | Games::Axmud | ||
| 751 | ); | ||
| 752 | |||
| 753 | ################## | ||
| 754 | # Constructors | ||
| 755 | |||
| 756 | ################## | ||
| 757 | # Methods | ||
| 758 | |||
| 759 | ################## | ||
| 760 | # Accessors - set | ||
| 761 | |||
| 762 | ################## | ||
| 763 | # Accessors - get | ||
| 764 | } | ||
| 765 | |||
| 766 | { package Games::Axmud::Cage::Route; | ||
| 767 | |||
| 768 | use strict; | ||
| 769 | use warnings; | ||
| 770 | # use diagnostics; | ||
| 771 | |||
| 772 | use Glib qw(TRUE FALSE); | ||
| 773 | |||
| 774 | our @ISA = qw(Games::Axmud::Generic::Cage Games::Axmud); | ||
| 775 | |||
| 776 | ################## | ||
| 777 | # Constructors | ||
| 778 | |||
| 779 | sub new { | ||
| 780 | |||
| 781 | # Creates a new instance of the route cage | ||
| 782 | # | ||
| 783 | # Expected arguments | ||
| 784 | # $session - The calling function's GA::Session (not stored as an IV) | ||
| 785 | # $profName - The parent profile's name (e.g. matches the object's ->name) | ||
| 786 | # $profCategory - The profile's category (e.g. 'world', 'guild', 'faction' etc) | ||
| 787 | # | ||
| 788 | # Return values | ||
| 789 | # 'undef' on improper arguments or if the cage already seems to exist | ||
| 790 | # Blessed reference to the newly-created object on success | ||
| 791 | |||
| 792 | my ($class, $session, $profName, $profCategory, $check) = @_; | ||
| 793 | |||
| 794 | # Local variables | ||
| 795 | my $name; | ||
| 796 | |||
| 797 | # Check for improper arguments | ||
| 798 | if ( | ||
| 799 | ! defined $class || ! defined $session || ! defined $profName || ! defined $profCategory | ||
| 800 | || defined $check | ||
| 801 | ) { | ||
| 802 | return $axmud::CLIENT->writeImproper($class . '->new', @_); | ||
| 803 | } | ||
| 804 | |||
| 805 | # Compose the cage's unique name | ||
| 806 | $name = 'route_' . $profCategory . '_' . $profName; | ||
| 807 | |||
| 808 | # Check that $name is valid and not already in use by another profile | ||
| 809 | if (! $axmud::CLIENT->nameCheck($name, 42)) { | ||
| 810 | |||
| 811 | return $axmud::CLIENT->writeError( | ||
| 812 | 'Registry naming error: invalid name \'' . $name . '\'', | ||
| 813 | $class . '->new', | ||
| 814 | ); | ||
| 815 | |||
| 816 | } elsif ($session->ivExists('cageHash', $name)) { | ||
| 817 | |||
| 818 | return $axmud::CLIENT->writeError( | ||
| 819 | 'Registry naming error: cage \'' . $name . '\' already exists', | ||
| 820 | $class . '->new', | ||
| 821 | ); | ||
| 822 | } | ||
| 823 | |||
| 824 | # Setup | ||
| 825 | my $self = { | ||
| 826 | _objName => $name, | ||
| 827 | _objClass => $class, | ||
| 828 | _parentFile => 'otherprof', | ||
| 829 | _parentWorld => $session->currentWorld->name, | ||
| 830 | _privFlag => FALSE, # All IVs are public | ||
| 831 | |||
| 832 | # Standard cage IVs | ||
| 833 | # ----------------- | ||
| 834 | |||
| 835 | name => $name, | ||
| 836 | cageType => 'route', | ||
| 837 | standardFlag => TRUE, # This is a built-in Axmud cage | ||
| 838 | profName => $profName, | ||
| 839 | profCategory => $profCategory, | ||
| 840 | |||
| 841 | # Route cage IVs | ||
| 842 | # -------------- | ||
| 843 | |||
| 844 | # Hash of GA::Obj::Route (stores a fixed route between two rooms, or a fixed circuit | ||
| 845 | # starting and stopping at the same room). Hash in the form | ||
| 846 | # | ||
| 847 | # $routeHash{r_start-room-tag@@@stop-room-tag} = blessed_reference_to_route_object | ||
| 848 | # (for road routes, where 'start-room-tag' and 'stop-room-tag' are strings | ||
| 849 | # matching GA::Obj::Route->startRoom and ->stopRoom) | ||
| 850 | # $routeHash{q_start-room-tag@@@stop-room-tag} = blessed_reference_to_route_object | ||
| 851 | # (for quick routes, where 'start-room-tag' and 'stop-room-tag' are strings | ||
| 852 | # matching GA::Obj::Route->startRoom and ->stopRoom) | ||
| 853 | # $routeHash{c_start-room-tag@@@circuit-name} = blessed_reference_to_route_object | ||
| 854 | # (for circuit routes, where 'start-room-tag' matches GA::Obj::Route->startRoom | ||
| 855 | # and 'circuit-name' matches GA::Obj::Route->circuitName) | ||
| 856 | routeHash => {}, | ||
| 857 | }; | ||
| 858 | |||
| 859 | # Bless the object into existence | ||
| 860 | bless $self, $class; | ||
| 861 | |||
| 862 | return $self; | ||
| 863 | } | ||
| 864 | |||
| 865 | sub clone { | ||
| 866 | |||
| 867 | # Creates a clone of an existing route cage | ||
| 868 | # | ||
| 869 | # Expected arguments | ||
| 870 | # $session - The calling function's GA::Session (not stored as an IV) | ||
| 871 | # $profName - The parent profile's name (e.g. matches the object's ->name) | ||
| 872 | # $profCategory - The profile's category (e.g. 'world', 'guild', 'faction' etc) | ||
| 873 | # | ||
| 874 | # Return values | ||
| 875 | # 'undef' on improper arguments or if the cage already seems to exist | ||
| 876 | # Blessed reference to the newly-created object on success | ||
| 877 | |||
| 878 | my ($self, $session, $profName, $profCategory, $check) = @_; | ||
| 879 | |||
| 880 | # Local variables | ||
| 881 | my $name; | ||
| 882 | |||
| 883 | # Check for improper arguments | ||
| 884 | if ( | ||
| 885 | ! defined $session || ! defined $profName || ! defined $profCategory | ||
| 886 | || defined $check | ||
| 887 | ) { | ||
| 888 | return $axmud::CLIENT->writeImproper($self->_objClass . '->clone', @_); | ||
| 889 | } | ||
| 890 | |||
| 891 | # Compose the cage's unique name | ||
| 892 | $name = 'route_' . $profCategory . '_' . $profName; | ||
| 893 | |||
| 894 | # Check that $name is valid and not already in use by another profile | ||
| 895 | if (! $axmud::CLIENT->nameCheck($name, 42)) { | ||
| 896 | |||
| 897 | return $axmud::CLIENT->writeError( | ||
| 898 | 'Registry naming error: invalid name \'' . $name . '\'', | ||
| 899 | $self->_objClass . '->clone', | ||
| 900 | ); | ||
| 901 | |||
| 902 | } elsif ($session->ivExists('cageHash', $name)) { | ||
| 903 | |||
| 904 | return $axmud::CLIENT->writeError( | ||
| 905 | 'Registry naming error: cage \'' . $name . '\' already exists', | ||
| 906 | $self->_objClass . '->clone', | ||
| 907 | ); | ||
| 908 | } | ||
| 909 | |||
| 910 | # Setup | ||
| 911 | my $clone = { | ||
| 912 | _objName => $name, | ||
| 913 | _objClass => $self->_objClass, | ||
| 914 | _parentFile => 'otherprof', | ||
| 915 | _parentWorld => undef, | ||
| 916 | _privFlag => FALSE, # All IVs are public | ||
| 917 | |||
| 918 | # Standard cage IVs | ||
| 919 | # ----------------- | ||
| 920 | |||
| 921 | name => $name, | ||
| 922 | cageType => 'route', | ||
| 923 | standardFlag => TRUE, # This is a built-in Axmud cage | ||
| 924 | profName => $profName, | ||
| 925 | profCategory => $profCategory, | ||
| 926 | |||
| 927 | # Route cage IVs | ||
| 928 | # -------------- | ||
| 929 | |||
| 930 | routeHash => {$self->routeHash}, | ||
| 931 | }; | ||
| 932 | |||
| 933 | # Bless the cloned object into existence | ||
| 934 | bless $clone, $self->_objClass; | ||
| 935 | return $clone; | ||
| 936 | } | ||
| 937 | |||
| 938 | ################## | ||
| 939 | # Methods | ||
| 940 | |||
| 941 | ################## | ||
| 942 | # Accessors - set | ||
| 943 | |||
| 944 | ################## | ||
| 945 | # Accessors - get | ||
| 946 | |||
| 947 | # NB These methods set/return the cage's ACTUAL route hash. To get/set values from this hash | ||
| 948 | # AND/OR its inferiors, use the generic cage's ->ivXXX functions | ||
| 949 | sub routeHash | ||
| 950 | { my $self = shift; return %{$self->{routeHash}}; } | ||
| 951 | } | ||
| 952 | |||
| 953 | # Package must return a true value | ||
| 954 | 1 |