Games-Axmud

 view release on metacpan or  search on metacpan

lib/Games/Axmud/Task.pm  view on Meta::CPAN

            foreach my $obj (@objList) {

                if (
                    $self->combineCorpseFlag
                    && $obj->category eq 'portable'
                    && $obj->type eq 'corpse'
                ) {
                    $corpseCount++;

                } elsif (
                    $self->combineBodyPartFlag
                    && $obj->category eq 'portable'
                    && $obj->type eq 'bodypart'
                ) {
                    $bodyPartCount++;

                } else {

                    # Not a corpse or body part, so display on its own line
                    push (@modObjList, $obj);
                }
            }
        }
        # @objList should contain only those things displayed on their own line
        @objList = @modObjList;

        # Now, sort @objList by category - in the order characters, minions, sentients, creatures,
        #   everything else, finally corpses
        foreach my $obj (@objList) {

            if ($obj->category eq 'char') {

                push (@charList, $obj);

            } elsif ($obj->category eq 'minion') {

                push (@minionList, $obj);

            } elsif ($obj->category eq 'sentient') {

                push (@sentientList, $obj);

            } elsif ($obj->category eq 'creature') {

                push (@creatureList, $obj);

            } elsif (
                $obj->category eq 'portable'
                && ($obj->type eq 'corpse' || $obj->type eq 'bodypart')
            ) {
                push (@corpseList, $obj);

            } else {

                push (@otherList, $obj);
            }
        }

        # If there are five torches in @otherList, we'd prefer to display them on a single line,
        #   like we do with corpses. (We don't display multiple orcs, for example, on a single line
        #   because the task marks which ones are alive, and which are dead)
        # ->combineDuplicates compiles a hash in the form
        #   $otherHash{blessed_reference_to_non_model_object} = multiple
        # In this example, it will return a hash containing one key-value pair. The key will be the
        #   first object in @otherList, the corresponding value will be 5
        %otherHash = $self->combineDuplicates(@otherList);
        # The keys of %otherHash are stringified blessed references, so we need to modify @otherList
        #   to eliminate the duplicates that don't appear in %otherHash
        foreach my $obj (@otherList) {

            if (exists $otherHash{$obj}) {

                push (@newOtherList, $obj);
            }
        }

        # Sort alphabetically the sub-lists
        @charList = sort {lc($a->noun) cmp lc($b->noun)} (@charList);
        @minionList = sort {lc($a->noun) cmp lc($b->noun)} (@minionList);
        @sentientList = sort {lc($a->noun) cmp lc($b->noun)} (@sentientList);
        @creatureList = sort {lc($a->noun) cmp lc($b->noun)} (@creatureList);
        @otherList = sort {lc($a->noun) cmp lc($b->noun)} (@otherList);
        @corpseList = sort {lc($a->noun) cmp lc($b->noun)} (@corpseList);
        # Re-combine into a single list, in order
        @objList = (
            @charList,
            @minionList,
            @sentientList,
            @creatureList,
            @newOtherList,
            @corpseList,
        );

        # Display the room contents, if known
        foreach my $obj (@objList) {

            my (
                $nounString, $otherNounString, $adjString, $unknownWordString, $multiple, $column,
                @wordList, @newWordList,
            );

            # Convert lists into strings, with each word separated by a space
            $nounString = $obj->noun;

            if (exists $otherHash{$obj}) {

                # Use the multiple supplied in the call to ->combineDuplicates
                $multiple = $otherHash{$obj};

            } else {

                # Use the object's actual multiple
                $multiple = $obj->multiple;
            }

            # The world model's ->parseObj can take a copy of an 'unknown' word (not a recognised
            #   noun or adjective) and make it the noun, such that the same word appears as both the
            #   main noun, and in the unknown word list
            # As a result, we only want to show the noun word once, whatever it is
            @wordList = $obj->otherNounList;
            @newWordList = ();

            foreach my $word (@wordList) {

                if ($word ne $nounString) {

                    push (@newWordList, $word);
                }
            }
            $otherNounString = join(' ', @newWordList);

            @wordList = ($obj->adjList, $obj->pseudoAdjList);
            @newWordList = ();
            foreach my $word (@wordList) {

                if ($word ne $nounString) {

                    push (@newWordList, $word);
                }
            }
            $adjString = join(' ', @newWordList);

            @wordList = $obj->unknownWordList;
            @newWordList = ();
            foreach my $word (@wordList) {

                if ($word ne $nounString) {

                    push (@newWordList, $word);
                }
            }
            $unknownWordString = join(' ', @newWordList);

            # Display the information, in a single line, in different colours
            #   (Some strings surrounded by square brackets, empty strings aren't displayed at all)
            #   (* means a being that's still alive, - a being that's been killed)
            if (
                $obj->category eq 'char'
                || $obj->category eq 'minion'
                || $obj->category eq 'sentient'
                || $obj->category eq 'creature'
            ) {
                if ($obj->aliveFlag) {
                    $column = '*';
                } else {
                    $column = '-';
                }

            } else {

                $column = ' ';
            }

            # Highlight player characters and minions
            if ($obj->category eq 'char') {

                $colour = 'RED';

            } elsif ($obj->category eq 'minion') {

                if ($obj->ownMinionFlag) {
                    $colour = 'CYAN';
                } else {
                    $colour = 'GREN';
                }

            } else {

                $colour = 'white';
            }

            if (! $self->showParsedFlag) {

                # Show the object before it was parsed, highlighing the noun in yellow
                $posn = index($obj->baseString, $obj->noun);

                if ($posn == -1 || $colour ne 'white' || $obj->noun eq '') {

                    # The actual noun seems to be missing, for some reason
                    # Also, don't highlight the noun if it's a player character or minion
                    $self->insertText($column . $obj->baseString, $colour);

                } else {

                    $before = substr($obj->baseString, 0, $posn);
                    if ($before ne '') {

                        $self->insertText($column . $before, 'white');

                        $self->insertText(
                            substr($obj->baseString, $posn, length($obj->noun)),
                            'echo',
                            'yellow',
                        );

                    } else {

                        $self->insertText(
                            $column . substr($obj->baseString, $posn, length($obj->noun)),
                            'yellow',
                        );
                    }

lib/Games/Axmud/Task.pm  view on Meta::CPAN

            if ($bodyPartCount > 1 || $corpseCount) {

                $self->insertText(' [' . $bodyPartCount . ']', 'echo', 'red');
            }
        }

        return 1;
    }

    sub prepareTitleBar {

        # Called by various functions, including $self->refreshWin
        # Prepares text to display in the task window's title bar (if open), and then displays it
        #
        # Expected arguments
        #   (none besides $self)
        #
        # Return values
        #   'undef' on improper arguments
        #   1 otherwise

        my ($self, $check) = @_;

        # Check for improper arguments
        if (defined $check) {

            return $axmud::CLIENT->writeImproper($self->_objClass . '->prepareTitleBar', @_);
        }

        # v1.1.093 The number of expected room statements is no longer displayed in the automapper
        #   window
        if (! $self->moveList) {

            # No more moves expected. To make the title bar more pleasant to look out, display a
            #   hyphen rather than nothing
            $self->setTaskWinTitle(' - ', TRUE);
#            # Also update the Automapper window's title bar, if it's open
#            if ($self->session->mapWin) {
#
#                $self->session->mapWin->setWinTitle();
#            }

        } else {

            $self->setTaskWinTitle(' ' . scalar $self->moveList . ' ', TRUE);
#            # Also update the Automapper window's title bar, if it's open (and not in 'wait' mode)
#            if ($self->session->mapWin && $self->session->mapWin->mode ne 'wait') {
#
#                $self->session->mapWin->setWinTitle(' (' . scalar $self->moveList . ')');
#            }
        }

        return 1;
    }

    sub combineDuplicates {

        # Called by $self->refreshWin
        # If there are five torches in the room, we want to display them on a single line, but if
        #   there are five orcs in the room, we want to display them on separate lines so the user
        #   can see which are alive and which are dead
        # This function is called with a list of all the objects in the current room's
        #   ->tempObjList which aren't alive and aren't corpses or body parts
        # It compares the objects in the list against each other, trying to eliminate duplicates.
        #   However, we can't set an object's ->multiple, because ->refreshWin (and therefore this
        #   function) might be called more than once; instead, we return a hash in the form
        #   $hash{blessed_reference_to_non_model_object} = multiple
        # When an object is processed, its blessed reference is added to the hash, with the
        #   corresponding multiple set to 1
        # When an object is processed that matches one already in the hash, the object is eliminated
        #   and the hash object's multiple is increased
        #
        # Expected arguments
        #   (none besides $self)
        #
        # Optional arguments
        #   @objList    - A list of objects from the current room's ->tempObjList (which may be
        #                   empty)
        #
        # Return values
        #   The hash of objects described above (in which duplicates have been removed)

        my ($self, @objList) = @_;

        # Local variables
        my (%emptyHash, %newHash, %unStringHash);

        # (No check for improper arguments)

        # The list of objects can be empty
        if (! @objList) {

            return %emptyHash;
        }

        # Otherwise, process each item in @objList in turn
        # The first item is added to %newHash
        # Subsequent items are compared against the items in %newHash. If the subsequent item is a
        #   duplicate of anything already in %newHash, it is eliminated. Otherwise, it is added to
        #   %newHash
        # (Actually, we use a second hash so that we can translate the stringified blessed
        #   references stored as keys in %newHash into the actual blessed references)
        do {

            my ($obj, $flag);

            $obj = shift @objList;

            # Don't try to combine duplicates of objects whose ->multiple is already not 1
            if ($obj->multiple == 1) {

                # Compare this item against every object in @newList
                OUTER: foreach my $newObj (values %unStringHash) {

                    # Are the two objects exactly the same?
                    if ($self->session->worldModelObj->objCompare(100, $obj, $newObj)) {

                        # We have a match. The keys in %newHash are non-model objects; the
                        #   corresponding values are the number of things this object represents
                        $newHash{$newObj} = $newHash{$newObj} + 1;
                        $flag = TRUE;

                        last OUTER;
                    }
                }
            }

            if (! $flag) {

                # $obj isn't a duplicate of anything already in %newHash, so add it to the hash
                $newHash{$obj} = 1;
                # (Need an un-stringified version of the object, too)
                $unStringHash{$obj} = $obj;
            }

        } until (! @objList);

        return %newHash;
    }

    sub countLivingObjects {

        # Can be called by anything
        # Counts the number of (known) living objects in the current room
        #
        # Expected arguments
        #   (none besides $self)
        #
        # Optional arguments
        #   $minionFlag     - If set to TRUE, minions are ignored. If set to FALSE (or 'undef'),
        #                       minions are included
        #
        # Return values
        #   'undef' on improper arguments or if the current room isn't known
        #   Otherwise returns the number of objects whose ->aliveFlag is TRUE (includes 'character',
        #       'minion', 'sentient', 'creature' objects and perhaps also some 'custom' objects).
        #       The number returned may be 0

        my ($self, $minionFlag, $check) = @_;

        # Local variables
        my $count;

        # Check for improper arguments
        if (defined $check) {

            return $axmud::CLIENT->writeImproper($self->_objClass . '->countLivingObjects', @_);
        }

        if (! $self->roomObj || ! $self->roomObj->tempObjList) {

            # No objects to count
            return 0;
        }

        # Count the living objects
        $count = 0;
        foreach my $obj ($self->roomObj->tempObjList) {

            if (
                $obj->aliveFlag
                && (! $minionFlag || $obj->category ne 'minion')
            ) {
                $count++;
            }
        }

        return $count;
    }

    sub resetModelRoom {

        # Called by GA::Obj::WorldModel->deleteRooms and GA::Obj::Map->openWin
        # Resets the room model object number stored by the task, when it is known (so that the task
        #   no longer knows the automapper's current room)
        #
        # Expected arguments
        #   (none besides $self)
        #
        # Return values
        #   'undef' on improper arguments
        #   1 otherwise

        my ($self, $check) = @_;

        # Check for improper arguments
        if (defined $check) {

            return $axmud::CLIENT->writeImproper($self->_objClass . '->resetModelRoom', @_);
        }

        # Update IVs
        $self->ivUndef('modelNumber');
        if ($self->roomObj && $self->roomObj->roomTag) {

            $self->roomObj->ivUndef('roomTag');
        }

        # Update the task window
        $self->refreshWin();

        return 1;
    }

    sub resetMoveList {

        # Called by GA::Win::Map->addFailedExitCallback or by any other function
        # Resets the two IVs which tell the task how many room statements to expect, and then
        #   updates the task window
        #
        # Expected arguments
        #   (none besides $self)
        #
        # Return values
        #   'undef' on improper arguments
        #   1 otherwise

        my ($self, $check) = @_;

        # Check for improper arguments
        if (defined $check) {

lib/Games/Axmud/Task.pm  view on Meta::CPAN


                # Monitor current experience points (XP)
                } elsif ($self->monitorStatistic eq 'xp_current') {

                    if (! defined $charObj->xpCurrent) {

                        # Statistic not known; resume execution
                        return $self->ivPoke('stage', 3);

                    } elsif ($self->xpCurrent >= $self->monitorTarget) {

                        # XP has recovered; resume execution
                        return $self->ivPoke('stage', 3);

                    } else {

                        # Continue waiting for XP to recover
                        return $self->ivPoke('stage', 4);
                    }

                # Monitor experience points (XP) to next level
                } elsif ($self->monitorStatistic eq 'xp_next_level') {

                    if (! defined $charObj->xpNextLevel) {

                        # Statistic not known; resume execution
                        return $self->ivPoke('stage', 3);

                    } elsif ($self->xpNextLevel <= $self->monitorTarget) {

                        # XP has recovered; resume execution
                        return $self->ivPoke('stage', 3);

                    } else {

                        # Continue waiting for XP to recover
                        return $self->ivPoke('stage', 4);
                    }

                # Monitor total experience points (XP)
                } elsif ($self->monitorStatistic eq 'xp_total') {

                    if (! defined $charObj->xpTotal) {

                        # Statistic not known; resume execution
                        return $self->ivPoke('stage', 3);

                    } elsif ($self->xpTotal >= $self->monitorTarget) {

                        # XP has recovered; resume execution
                        return $self->ivPoke('stage', 3);

                    } else {

                        # Continue waiting for XP to recover
                        return $self->ivPoke('stage', 4);
                    }

                # Monitor life status
                } elsif (
                    $self->monitorStatistic eq 'alive' || $self->monitorStatistic eq 'sleep'
                    || $self->monitorStatistic eq 'passout' || $self->monitorStatistic eq 'dead'
                ) {
                    if ($charObj->lifeStatus eq $self->monitorStatistic) {

                        # Life status matches; resume execution
                        return $self->ivPoke('stage', 3);

                    } else {

                        # Continue waiting for the right life status
                        return $self->ivPoke('stage', 4);
                    }

                } else {

                    # Unrecognised statistic
                    return $self->ivPoke('stage', 3);
                }

            # Can't monitor any tasks but the four specified above
            } else {

                return $self->ivPoke('stage', 3);
            }

        } else {

            # The task stage has somehow been set to an invalid value
            return $self->invalidStage();
        }
    }

    sub setUpMonitoring {

        # Called by several Axbasic statements to set this task's IVs, used when the task is
        #   monitoring another task (such as the Status task), waiting for a statistic stored by the
        #   other task to change to a certain desired value (after which, execution of the Axbasic
        #   script resumes)
        #
        # Expected arguments
        #   $task       - The task to monitor ('locator', 'attack', 'status', 'divert')
        #   $statistic  - The statistic to monitor, stored as an IV by that task
        #
        # Optional arguments
        #   $target     - The minimum value that the statistic should reach before resuming the
        #                   Axbasic script; a percentage value in the range 0-100 (not necessary
        #                   for every statement which sets up monitoring)
        #   $timeOut    - An optional timeout, in seconds, after which the Axbasic script resumes
        #                   execution anyway
        #
        # Return values
        #   'undef' on improper arguments
        #   1 otherwise

        my ($self, $task, $statistic, $target, $timeOut, $check) = @_;

        # Check for improper arguments
        if (! defined $task || ! defined $statistic || defined $check) {

            return $axmud::CLIENT->writeImproper($self->_objClass . '->setUpMonitoring', @_);

lib/Games/Axmud/Task.pm  view on Meta::CPAN

            'bank'                      => undef,
            'purse'                     => undef,
        };
        $self->{ttsFlagAttribHash}      = {
            'life'                      => FALSE,
        },
        $self->{ttsAlertAttribHash}     = {
            'healthup'                  => undef,
            'healthdown'                => undef,
            'magicup'                   => undef,
            'magicdown'                 => undef,
            'energyup'                  => undef,
            'energydown'                => undef,
            'guildup'                   => undef,
            'guilddown'                 => undef,
            'socialup'                  => undef,
            'socialdown'                => undef,
        };
        $self->{status}                 = 'wait_init';
        # ->activeFlag set to TRUE if the task should actively send commands to the world to gather
        #   data about the character's status every few seconds; set to FALSE if the task should
        #   passively collect status data
        # When TRUE, the task uses gagged triggers by default (lines of text received from the world
        #   containing data are not displayed in the 'main' window). When FALSE, un-gagged triggers
        #   are used by default and the received lines are displayed in the 'main' window
        # However, whether to use gagged triggers (or not) mostly depends on the current world
        #   profile, which can choose to overrule the Status task most of the time (or not)
        # Triggers for bar patterns and stat patterns are not affected by $self->activeFlag because
        #   they have their own gag settings
        # Triggers relating to $self->lifeStatus (e.g. 'You die', 'You fall asleep', 'You wake up'
        #   etc) are never gagged
        $self->{activeFlag}             = FALSE;    # Task can be activated/disactivated

        # Task parameters
        #
        # If ->activeFlag = TRUE, a hash of the commands that should be sent to the world, and how
        #   often they should be sent. Hash in the form
        #       $cmdHash{command} = interval
        $self->{cmdHash}                = {};
        # If ->activeFlag = TRUE, the names of any dependent timers created. Hash in the form
        #   $timerHash{command} = dependent_timer_object
        $self->{timerHash}              = {};

        # Flag set to TRUE every time the task's window should be updated, and set back to FALSE
        #   when it is actually updated
        $self->{updateFlag}             = FALSE;
        # Flag set to TRUE every time the life status changes (so that the background colour of the
        #   task window can be changed), set back to FALSE once the background colour has actually
        #   been changed
        $self->{lifeStatusChangeFlag}   = FALSE;
        # Flag set to TRUE every time the character's health points change from one band to another
        #   (which means the task window's background colour must change) - bands are 0-10%, 11-30%,
        #   31-50%, 51-100%
        $self->{healthChangeFlag}       = FALSE;
        # If this flag is set to TRUE, the task attempts to convert time strings (e.g. 'twenty past
        #   two in the morning') into a 24-hour clock time using the current dictionary. The flag
        #   is set to TRUE at stage 2 if the current dictionary provides enough vocabulary
        $self->{convertTimeFlag}        = FALSE;

        # When this flag is TRUE, the background colour of the task window changes, depending on
        #   whether the character is alive, dead, asleep (etc) and also depending on how many health
        #   points the character has. If FALSE, the colour scheme never changes
        $self->{allowColourFlag}        = TRUE;
        # The colours to use. Each value must be a standard Axmud colour tag
        # Which window background colour to use when character is alive
        $self->{aliveColour}            = 'GREEN';
        # Which colour to use when alive, but health points below 50%
        $self->{alive50Colour}          = 'YELLOW';
        # Which colour to use when alive, but health points below 30%
        $self->{alive30Colour}          = 'yellow';
        # Which colour to use when alive, but health points below 10%
        $self->{alive10Colour}          = 'RED';
        # Which window background colour to use when character is asleep
        $self->{asleepColour}           = 'cyan';
        # Which window background colour to use when character is passed out
        $self->{passedOutColour}        = 'magenta';
        # Which window background colour to use when character is dead
        $self->{deadColour}             = 'black';

        # The Status task tracks five types of variable - character, fixed, pseudo, local, counter
        #   and custom
        # Status task variables have a name_in_this_form. Names must be unique; a custom variable
        #   called 'xp_current' can't be created because there's already a character variable with
        #   that name
        # Character, fixed, local and pseudo variable names are fixed; variable names can't be added
        #   or removed from the set specified by the constant IVs below
        #
        # For character variables like 'health_points', 'xp_current' and 'life_status', values are
        #   stored in the current character profile as soon as they are received
        # For fixed variables, values are retrieved from the current character profile, and some of
        #   those values are updated by this task; but the values are not modified directly by
        #   incoming text (for example, when a line matches a pattern in
        #   GA::Profile::World->groupPatternList)
        # For pseudo variables, $self->getValue compiles a value from other values, whenever
        #   required (so the values are stored in any Status task IV)
        # For local variables, values are stored in this task (and are lost, when the task halts)
        # For counter variables, a current value stored in the character profile is compared against
        #   some baseline value (which is stored in $self->counterBaseHash)
        # Custom variables are created just by specifying them, for example, if
        #   GA::Profile::World->groupPatternList refers to a custom variable called 'my_var', as
        #   soon as a line of text is received matching the pattern, an entry for 'my_var' is
        #   created in $self->customVarHash
        #
        # A hash of character variables, and their corresponding GA::Profile::Char IV
        $self->{constCharVarHash}       = {
            # Character's health/magic/energy/guild/social points
            'health_points'             => 'healthPoints',
            'health_points_max'         => 'healthPointsMax',
            'magic_points'              => 'magicPoints',
            'magic_points_max'          => 'magicPointsMax',
            'energy_points'             => 'energyPoints',
            'energy_points_max'         => 'energyPointsMax',
            'guild_points'              => 'guildPoints',
            'guild_points_max'          => 'guildPointsMax',
            'social_points'             => 'socialPoints',
            'social_points_max'         => 'socialPointsMax',
            # eXperience Points (XP), Quest Points (QP) and a spare set of variables for worlds
            #   which use some other point system for levelling, Other Points (OP)
            'xp_current'                => 'xpCurrent',
            'xp_next_level'             => 'xpNextLevel',
            'xp_total'                  => 'xpTotal',
            'qp_current'                => 'qpCurrent',
            'qp_next_level'             => 'qpNextLevel',
            'qp_total'                  => 'qpTotal',
            'op_current'                => 'opCurrent',
            'op_next_level'             => 'opNextLevel',
            'op_total'                  => 'opTotal',
            # Character's level and alignment
            'level'                     => 'level',
            'alignment'                 => 'alignment',             # Not numeric
            # Local and remote wimpy (the maximum local wimpy is a fixed value)
            'local_wimpy'               => 'localWimpy',

lib/Games/Axmud/Task.pm  view on Meta::CPAN

        #                   cloned (at the moment)
        #
        # Optional arguments
        #   $profName   - ($taskType = 'initial') name of the profile in whose initial tasklist the
        #                   existing task is stored
        #   $profCategory
        #               - ($taskType = 'initial') which category the profile falls under (i.e.
        #                   'world', 'race', 'char', etc)
        #
        # Return values
        #   'undef' on improper arguments or if the task can't be cloned
        #   Blessed reference to the newly-created object on success

        my ($self, $session, $taskType, $profName, $profCategory, $check) = @_;

        # Check for improper arguments
        if (
            ! defined $session || ! defined $taskType || defined $check
            || ($taskType ne 'current' && $taskType ne 'initial')
            || ($taskType eq 'initial' && (! defined $profName || ! defined $profCategory))
        ) {
            return $axmud::CLIENT->writeImproper($self->_objClass . '->clone', @_);
        }

        # For initial tasks, check that $profName exists
        if (
            $taskType eq 'initial'
            && defined $profName
            && ! $session->ivExists('profHash', $profName)
        ) {
            return $axmud::CLIENT->writeError(
                'Can\'t create cloned task because \'' . $profName . '\' profile doesn\'t exist',
                $self->_objClass . '->clone',
            );
        }

        # Check that the task doesn't belong to a disabled plugin (in which case, it can't be
        #   cloned)
        if (! $self->checkPlugins()) {

            return undef;
        }

        # Create the new task, using default settings and parameters
        my $clone = $self->_objClass->new($session, $taskType, $profName, $profCategory);

        # Most of the cloned task's settings have default values, but a few are copied from the
        #   original
        $self->cloneTaskSettings($clone);

        # Give the new (cloned) task the same initial parameters as the original one
        $clone->{cmdHash}               = {$self->cmdHash};
        $clone->{timerHash}             = {$self->timerHash};

        $clone->{updateFlag}            = $self->updateFlag;
        $clone->{lifeStatusChangeFlag}  = $self->lifeStatusChangeFlag;
        $clone->{healthChangeFlag}      = $self->healthChangeFlag;
        $clone->{convertTimeFlag}       = $self->convertTimeFlag;

        $clone->{allowColourFlag}       = $self->allowColourFlag;
        $clone->{aliveColour}           = $self->aliveColour;
        $clone->{alive50Colour}         = $self->alive50Colour;
        $clone->{alive30Colour}         = $self->alive30Colour;
        $clone->{alive10Colour}         = $self->alive10Colour;
        $clone->{asleepColour}          = $self->asleepColour;
        $clone->{passedOutColour}       = $self->passedOutColour;
        $clone->{deadColour}            = $self->deadColour;

        # (The constant hashes retain their own values)

        $clone->{localVarHash}          = {$self->localVarHash};
        $clone->{customVarHash}         = {$self->customVarHash};

        $clone->{counterVarHash}        = {$self->counterVarHash};
        $clone->{counterBaseHash}       = {$self->counterBaseHash};
        $clone->{fightCountFlag}        = $self->fightCountFlag;
        $clone->{interactCountFlag}     = $self->interactCountFlag;
        $clone->{counterStartTime}      = $self->counterStartTime;

        $clone->{affectHash}            = {$self->affectHash};
        $clone->{statHash}              = {$self->statHash};

        $clone->{gaugeFlag}             = $self->gaugeFlag;
        $clone->{gaugeStripObj}         = $self->gaugeStripObj;
        $clone->{gaugeLevel}            = $self->gaugeLevel;
        $clone->{gaugeValueFlag}        = $self->gaugeValueFlag;
        $clone->{gaugeObjList}          = [$self->gaugeObjList];
        $clone->{gaugeResetFlag}        = $self->gaugeResetFlag;

        $clone->{ttsPointsAlertHash}    = {$self->ttsPointsAlertHash};
        $clone->{ttsPointsAlertMsgHash} = {$self->ttsPointsAlertMsgHash};
        $clone->{ttsPointsAlertTypeHash}
                                        = {$self->ttsPointsAlertTypeHash};

        # Cloning complete
        return $clone;
    }

    sub preserve {

        # Called by $self->main whenever this task is reset, in order to preserve some if its task
        #   parameters (but not necessarily all of them)
        #
        # Expected arguments
        #   $newTask    - The new task which has been created, to which some of this task's instance
        #                   variables might have to be transferred
        #
        # Return values
        #   'undef' on improper arguments, or if $newTask isn't in the GA::Session's current
        #       tasklist
        #   1 on success

        my ($self, $newTask, $check) = @_;

        # Check for improper arguments
        if (! defined $newTask || defined $check) {

            return $axmud::CLIENT->writeImproper($self->_objClass . '->preserve', @_);
        }

        # Check the task is in the current tasklist
        if (! $self->session->ivExists('currentTaskHash', $newTask->uniqueName)) {

            return $self->writeWarning(
                '\'' . $self->uniqueName . '\' task missing from the current tasklist',
                $self->_objClass . '->preserve',
            );
        }

        # Preserve some task parameters (the others are left with their default settings, some of
        #   which will be re-initialised in stage 2)

        # Preserve the list of commands to send
        $newTask->ivPoke('cmdHash', $self->cmdHash);
        # Preserve the background colour scheme
        $newTask->ivPoke('allowColourFlag', $self->allowColourFlag);
        $newTask->ivPoke('aliveColour', $self->aliveColour);
        $newTask->ivPoke('alive50Colour', $self->alive50Colour);
        $newTask->ivPoke('alive30Colour', $self->alive30Colour);
        $newTask->ivPoke('alive10Colour', $self->alive10Colour);
        $newTask->ivPoke('asleepColour', $self->asleepColour);
        $newTask->ivPoke('passedOutColour', $self->passedOutColour);
        $newTask->ivPoke('deadColour', $self->deadColour);
        # Preserve the counters
        $newTask->ivPoke('counterVarHash', $self->counterVarHash);
        $newTask->ivPoke('counterBaseHash', $self->counterBaseHash);
        $newTask->ivPoke('fightCountFlag', $self->fightCountFlag);
        $newTask->ivPoke('interactCountFlag', $self->interactCountFlag);
        $newTask->ivPoke('counterStartTime', $self->counterStartTime);
        # Preserve some gauge variables
        $newTask->ivPoke('gaugeFlag', $self->gaugeFlag);
        $newTask->ivPoke('gaugeValueFlag', $self->gaugeFlag);

        return 1;
    }

#   sub setParentFileObj {}     # Inherited from generic task

#   sub updateTaskLists {}      # Inherited from generic task

    sub ttsReadAttrib {

        # Called by GA::Cmd::Read->do and PermRead->do
        # Users can use the client command ';read' to interact with individual tasks, typically
        #   getting them to read out information (e.g. the Status task can read out current health
        #   points)
        # The ';read' command is in the form ';read <attribute>' or ';read <attribute> <value>'.
        #   The ';read' command looks up the <attribute> in GA::Client->ttsAttribHash, which tells
        #   it which task to call
        #
        # Expected arguments
        #   $attrib     - The TTS attribute specified by the calling function. Must be one of the
        #                   keys in $self->ttsAttribHash
        #
        # Optional arguments
        #   $value      - The value specified by the calling function (or 'undef' if none was
        #                   specified)
        #   $noReadFlag - Set to TRUE when called by GA::Cmd::PermRead->do, in which case only this
        #                   task's hash of attributes is updated. If set to FALSE (or 'undef'),
        #                   something is usually read aloud, too
        #
        # Return values
        #   'undef' on improper arguments, if the current character profile isn't set or if the
        #       $attrib doesn't exist in this task's ->ttsConfig
        #   1 otherwise

        my ($self, $attrib, $value, $noReadFlag, $check) = @_;

        # Local variables
        my ($charObj, $string, $iv, $ivMax, $time);

        # Check for improper arguments
        if (! defined $attrib || defined $check) {

            return $axmud::CLIENT->writeImproper($self->_objClass . '->ttsReadAttrib', @_);
        }

        # Import the current character
        $charObj = $self->session->currentChar;
        if (! $charObj) {

lib/Games/Axmud/Task.pm  view on Meta::CPAN

        }

        $self->ivEmpty('timerHash');

        # Mark the task as being in 'disactivated' mode
        $self->ivPoke('activeFlag', FALSE);
        # Reset the task's triggers, using this flag to set each trigger as 'gagged' (or not) as
        #   appropriate (but don't bother if the task is shutting down)
        if (! $self->shutdownFlag) {

            $self->resetTriggers();
        }

        $self->refreshWin();

        return 1;
    }

    sub refreshWin {

        # Called by $self->doStage, stage 4
        # Displays information about the current location in the task window
        #
        # Expected arguments
        #   (none besides $self)
        #
        # Return values
        #   'undef' on improper arguments
        #   1 on success

        my ($self, $check) = @_;

        # Local variables
        my (
            $charObj, $health, $colour,
            @formatList,
        );

        # Check for improper arguments
        if (defined $check) {

            return $axmud::CLIENT->writeImproper($self->_objClass . '->refreshWin', @_);
        }

        # This function can be called by $self->disactivate, when Axmud closes down, in which case
        #   there might not be a window still open. If that's the case, there's nothing for this
        #   function to do
        # Also nothing to do if there's no current character profile
        $charObj = $self->session->currentChar;
        if (! $self->taskWinFlag || ! $charObj) {

            return undef;
        }

        # If there's been a change in life status, or if the character's health points have moved
        #   into a new band, then the task window's background colour must also be changed
        if (
            $self->allowColourFlag
            && ($self->lifeStatusChangeFlag || $self->healthChangeFlag)
        ) {
            if ($charObj->lifeStatus eq 'alive') {

                # If either ->healthPoints or ->healthPointsMax not known, assume health is 100%
                if (
                    ! defined $charObj->healthPoints
                    || ! defined $charObj->healthPointsMax
                    || $charObj->healthPointsMax == 0
                ) {
                    $colour = $self->aliveColour;

                } else {

                    $health = $charObj->healthPoints / $charObj->healthPointsMax;
                    if ($health <= 0.10) {
                        $colour = $self->alive10Colour;
                    } elsif ($health <= 0.30) {
                        $colour = $self->alive30Colour;
                    } elsif ($health <= 0.50) {
                        $colour = $self->alive50Colour;
                    } else {
                        $colour = $self->aliveColour;
                    }
                }

            } elsif ($charObj->lifeStatus eq 'sleep') {

                $colour = $self->asleepColour;

            } elsif ($charObj->lifeStatus eq 'passout') {

                $colour = $self->passedOutColour;

            } elsif ($charObj->lifeStatus eq 'dead') {

                $colour = $self->deadColour;

            } else {

                # Just in case $lifeStatus has been set to a valid value, use the default colour
                $colour = $self->aliveColour;
            }

            # Set the background colour
            $self->defaultTabObj->paneObj->applyMonochrome($self->defaultTabObj, $colour);

            # Update the title bar
            if ($charObj->lifeStatus eq 'sleep') {
                $self->setTaskWinTitle('(SLEEP)', TRUE);
            } elsif ($charObj->lifeStatus eq 'passout') {
                $self->setTaskWinTitle('(PASSED OUT)', TRUE);
            } elsif ($charObj->lifeStatus eq 'dead') {
                $self->setTaskWinTitle('(DEAD)', TRUE);
            } else {
                $self->setTaskWinTitle();
            }

            # Update IVs
            $self->ivPoke('lifeStatusChangeFlag', FALSE);
            $self->ivPoke('healthChangeFlag', FALSE);
        }

        # Get the text to display in the window, with all variables (in the form @variable_name@)
        #   replaced by their corresponding values
        @formatList = $self->processFormatList();
        # Display the resulting text
        $self->insertQuick(join("\n", @formatList));
        # Mark the task window as updated
        $self->ivPoke('updateFlag', FALSE);

        # Set the values displayed by any 'main' window gauges and redraw them (if visible)
        if (! $self->gaugeResetFlag) {

            $self->setGauges();

        } else {

            # New custom variable has been added. Gauges must be reset, not just redrawn
            $self->resetGauges();
            $self->ivPoke('gaugeResetFlag', FALSE);
       }

        return 1;
    }

    sub processFormatList {

        # Called by $self->refreshWin
        # Taking the current world profile's ->statusFormatList as a template, replaces all
        #   variables with their corresponding values
        # Variables are in the form @variable@, where 'variable' is one of the keys in
        #   $self->constCharVarHash, ->constFixedVarHash, ->constPseudoVarHash, ->localVarHash or
        #   ->customVarHash
        #
        # Expected arguments
        #   (none besides $self)
        #
        # Return values
        #   An empty list on improper arguments, or if the task is forced to shut down here
        #   Otherwise, returns the modified @displayList

lib/Games/Axmud/Task.pm  view on Meta::CPAN

                    $hours--;
                    $minutes = $minuteHash{$key} * (-1);

                } else {

                    $minutes = $minuteHash{$key};
                }

                # Remove the matched string, and don't continue looking for minute strings
                $longTime =~ s/$key//;

                last OUTER;
            }
        }

        # Remove hour strings
        $successFlag = FALSE;
        OUTER: foreach my $key (keys %hourHash) {

            if ($longTime =~ m/$key/i) {

                # If it's a.m., $hours = 0; if it's p.m., $hours already equals 12, so this
                #   converts $hours into a 24-hour clock value
                $hours = $hours + $hourHash{$key};
                # If $hours may have been set to -1 above; that's the equivalent of 23 in the
                #   24-hour clock
                if ($hours == -1) {

                    $hours = 23;
                }

                # Remove the matched string, and don't continue looking for hour strings
                $longTime =~ s/$key//;
                $successFlag = TRUE;

                last OUTER;
            }
        }

        if (! $successFlag) {

            # The 'hours' component not found (it doesn't matter too much if the 'minutes' component
            #   wasn't found
            return @emptyList;

        } else {

            # Conversion complete
            return ($hours, $minutes);
        }
    }

    sub checkHealthChange {

        # Called by $self->setValue
        # When the character's health points (GA::Profile::Char->healthPoints) or maximum health
        #   points (GA::Profile::Char->healthPointsMax) change, it might be necessary to change the
        #   background colour of the window
        # If the world doesn't explicitly state when the character wakes up after falling asleep,
        #   when they come around after passing out, or when they resurrect after dying, it might
        #   also be necessary to change the life status to 'alive' if the character's health points
        #   score is read
        # This function decides whether it's necessary, and sets $self->healthChangeFlag to TRUE if
        #   so
        #
        # Expected arguments
        #   $hp     - The new health points value
        #   $hpMax  - The new maximum health points value
        #
        # Return values
        #   'undef' on improper arguments, if there's no current character set or if the task
        #       window's background colour doesn't have to be changed
        #   1 if the colour should be changed

        my ($self, $hp, $hpMax, $check) = @_;

        # Local variables
        my ($charObj, $old, $new);

        # Check for improper arguments
        if (! defined $hp || ! defined $hpMax || defined $check) {

            return $axmud::CLIENT->writeImproper($self->_objClass . '->checkHealthChange', @_);
        }

        # Do nothing if there's no current character set
        $charObj = $self->session->currentChar;
        if (! $charObj) {

            return undef;
        }

        # If the character's life status isn't 'alive' and the override flag is set, the character
        #   is no longer asleep, passed out or dead. Change the life status to 'alive' again
        if (
            $charObj->lifeStatus ne 'alive'
            && $self->session->currentWorld->lifeStatusOverrideFlag
        ) {
            $charObj->ivPoke('lifeStatus', 'alive');

            # The task window's background colour should be changed
            return $self->ivPoke('healthChangeFlag', TRUE);

        # Otherwise, only consider changing the background colour, if the relevant IVs are non-zero
        } elsif ($self->allowColourFlag && $charObj->healthPoints && $charObj->healthPointsMax) {

            # Get the character's healt points as a percentage of the maximum
            $old = $charObj->healthPoints / $charObj->healthPointsMax;
            $new = $hp / $hpMax;

            if (
                (
                    $new > 0.50 && $old <= 0.50
                ) || (
                    $new > 0.30 && $new <= 0.50 && ($old <= 0.30 || $old > 0.50)
                ) || (
                    $new > 0.10 && $new <= 0.10 && ($old <= 0.10 || $old > 0.30)
                ) || (
                    $new <= 0.10 && $old > 0.10
                )
            ) {
                # The task window's background colour should be changed
                return $self->ivPoke('healthChangeFlag', TRUE);
            }
        }

        # No change to the background colour
        return undef;
    }

    sub checkPointsChange {

        # Called by $self->setValue
        # When the character's health/magic/energy/guild/social points change, check whether it's
        #   time to read out a TTS alert message and, if so, add the message to
        #   $self->ttsPointsAlertMsgHash
        # All messages are then read out by $self->doStage (stage 4), and ->ttsPointsAlertMsgHash
        #   is reset; in this way, we don't erroneously read out an alert message if the code
        #   receives (for example) a new 'health_points' value before a new 'health_points_max'
        #   value
        #
        # Expected arguments
        #   $attrib     - Which points total has changed: 'health', 'magic', 'energy', 'guild',
        #                   'social'
        #
        # Return values
        #   'undef' on improper arguments, if there's no current character set or if nothing is to
        #       be read out
        #   1 if an alert message is to be read out (whether the user hears anything, or not, will
        #       depend on the usual TTS variables)

        my ($self, $attrib, $check) = @_;

        # Local variables
        my ($charObj, $iv, $current, $ivMax, $max, $percent);

        # Check for improper arguments
        if (
            ! defined $attrib

lib/Games/Axmud/Task.pm  view on Meta::CPAN

        #
        # This task's ->resetTriggers function creates some triggers to capture character
        #   resurrection strings. Group substrings and ->propertyHash aren't used
        #
        # Updates some IVs and writes to the logfile which monitors character resurrections
        #
        # Expected arguments (standard args from GA::Session->checkTriggers)
        #   $session        - The calling function's GA::Session
        #   $interfaceNum   - The number of the active trigger interface that fired
        #   $line           - The line of text received from the world
        #   $stripLine      - $line, with all escape sequences removed
        #   $modLine        - $stripLine, possibly modified by previously-checked triggers
        #   $grpStringListRef
        #                   - Reference to a list of group substrings from the pattern match
        #                       (equivalent of @_)
        #   $matchMinusListRef
        #                   - Reference to a list of matched substring offsets (equivalent of @-)
        #   $matchPlusListRef
        #                   - Reference to a list of matched substring offsets (equivalent of @+)
        #
        # Return values
        #   'undef' on improper arguments, or if $session is the wrong session or if the interface
        #       object can't be found
        #   1 otherwise

        my (
            $self, $session, $interfaceNum, $line, $stripLine, $modLine, $grpStringListRef,
            $matchMinusListRef, $matchPlusListRef, $check,
        ) = @_;

        # Local variables
        my ($obj, $charObj);

        # Check for improper arguments
        if (
            ! defined $session || ! defined $interfaceNum || ! defined $line || ! defined $stripLine
            || ! defined $modLine || ! defined $grpStringListRef || ! defined $matchMinusListRef
            || ! defined $matchPlusListRef || defined $check
        ) {
            return $axmud::CLIENT->writeImproper($self->_objClass . '->wakeUpSeen', @_);
        }

        # Basic check - the trigger should belong to the right session
        if ($session ne $self->session) {

            return undef;
        }

        # Get the interface object itself
        $obj = $session->ivShow('interfaceNumHash', $interfaceNum);
        if (! $obj) {

            return undef;
        }

        # Respond to the fired trigger

        # Import the current character profile
        $charObj = $self->session->currentChar;

        # If the character is not already alive...
        if ($charObj && $charObj->lifeStatus ne 'alive') {

            $charObj->ivPoke('lifeStatus', 'alive');

            # The next time the task window is updated, its background colour will change
            $self->ivPoke('lifeStatusChangeFlag', TRUE);
        }

        return 1;
    }

    sub passedOutSeen {

        # Called by GA::Session->checkTriggers
        #
        # This task's ->resetTriggers function creates some triggers to capture characer passing
        #   out strings. Group substrings and ->propertyHash aren't used
        #
        # Updates some IVs, writes to the logfile which monitors characters passing out, and plays
        #   a sound effect (if allowed)
        #
        # Expected arguments (standard args from GA::Session->checkTriggers)
        #   $session        - The calling function's GA::Session
        #   $interfaceNum   - The number of the active trigger interface that fired
        #   $line           - The line of text received from the world
        #   $stripLine      - $line, with all escape sequences removed
        #   $modLine        - $stripLine, possibly modified by previously-checked triggers
        #   $grpStringListRef
        #                   - Reference to a list of group substrings from the pattern match
        #                       (equivalent of @_)
        #   $matchMinusListRef
        #                   - Reference to a list of matched substring offsets (equivalent of @-)
        #   $matchPlusListRef
        #                   - Reference to a list of matched substring offsets (equivalent of @+)
        #
        # Return values
        #   'undef' on improper arguments, or if $session is the wrong session or if the interface
        #       object can't be found
        #   1 otherwise

        my (
            $self, $session, $interfaceNum, $line, $stripLine, $modLine, $grpStringListRef,
            $matchMinusListRef, $matchPlusListRef, $check,
        ) = @_;

        # Local variables
        my (
            $obj, $charObj, $start, $stop,
            @writeList,
        );

        # Check for improper arguments
        if (
            ! defined $session || ! defined $interfaceNum || ! defined $line || ! defined $stripLine
            || ! defined $modLine || ! defined $grpStringListRef || ! defined $matchMinusListRef
            || ! defined $matchPlusListRef || defined $check
        ) {
            return $axmud::CLIENT->writeImproper($self->_objClass . '->passedOutSeen', @_);
        }

        # Basic check - the trigger should belong to the right session
        if ($session ne $self->session) {

lib/Games/Axmud/Task.pm  view on Meta::CPAN

        #
        # This task's ->resetTriggers function creates some triggers to capture character coming
        #   around strings. Group substrings and ->propertyHash aren't used.
        #
        # Updates some IVs and writes to the logfile which monitors character revivals
        #
        # Expected arguments (standard args from GA::Session->checkTriggers)
        #   $session        - The calling function's GA::Session
        #   $interfaceNum   - The number of the active trigger interface that fired
        #   $line           - The line of text received from the world
        #   $stripLine      - $line, with all escape sequences removed
        #   $modLine        - $stripLine, possibly modified by previously-checked triggers
        #   $grpStringListRef
        #                   - Reference to a list of group substrings from the pattern match
        #                       (equivalent of @_)
        #   $matchMinusListRef
        #                   - Reference to a list of matched substring offsets (equivalent of @-)
        #   $matchPlusListRef
        #                   - Reference to a list of matched substring offsets (equivalent of @+)
        #
        # Return values
        #   'undef' on improper arguments, or if $session is the wrong session or if the interface
        #       object can't be found
        #   1 otherwise

        my (
            $self, $session, $interfaceNum, $line, $stripLine, $modLine, $grpStringListRef,
            $matchMinusListRef, $matchPlusListRef, $check,
        ) = @_;

        # Local variables
        my ($obj, $charObj);

        # Check for improper arguments
        if (
            ! defined $session || ! defined $interfaceNum || ! defined $line || ! defined $stripLine
            || ! defined $modLine || ! defined $grpStringListRef || ! defined $matchMinusListRef
            || ! defined $matchPlusListRef || defined $check
        ) {
            return $axmud::CLIENT->writeImproper($self->_objClass . '->resurrectSeen', @_);
        }

        # Basic check - the trigger should belong to the right session
        if ($session ne $self->session) {

            return undef;
        }

        # Get the interface object itself
        $obj = $session->ivShow('interfaceNumHash', $interfaceNum);
        if (! $obj) {

            return undef;
        }

        # Respond to the fired trigger

        # Import the current character profile
        $charObj = $self->session->currentChar;

        # If the character is not already alive...
        if ($charObj && $charObj->lifeStatus ne 'alive') {

            $charObj->ivPoke('lifeStatus', 'alive');

            # The next time the task window is updated, its background colour will change
            $self->ivPoke('lifeStatusChangeFlag', TRUE);
        }

        return 1;
    }

    sub deadSeen {

        # Called by GA::Session->checkTriggers
        #
        # This task's ->resetTriggers function creates some triggers to capture character death
        #   strings. Group substrings and ->propertyHash aren't used
        #
        # Updates some IVs, writes to the logfile which monitors character deaths, and plays a
        #   sound effect (if allowed)
        #
        # Expected arguments (standard args from GA::Session->checkTriggers)
        #   $session        - The calling function's GA::Session
        #   $interfaceNum   - The number of the active trigger interface that fired
        #   $line           - The line of text received from the world
        #   $stripLine      - $line, with all escape sequences removed
        #   $modLine        - $stripLine, possibly modified by previously-checked triggers
        #   $grpStringListRef
        #                   - Reference to a list of group substrings from the pattern match
        #                       (equivalent of @_)
        #   $matchMinusListRef
        #                   - Reference to a list of matched substring offsets (equivalent of @-)
        #   $matchPlusListRef
        #                   - Reference to a list of matched substring offsets (equivalent of @+)
        #
        # Return values
        #   'undef' on improper arguments, or if $session is the wrong session or if the interface
        #       object can't be found
        #   1 otherwise

        my (
            $self, $session, $interfaceNum, $line, $stripLine, $modLine, $grpStringListRef,
            $matchMinusListRef, $matchPlusListRef, $check,
        ) = @_;

        # Local variables
        my (
            $obj, $charObj, $start, $stop,
            @writeList,
        );

        # Check for improper arguments
        if (
            ! defined $session || ! defined $interfaceNum || ! defined $line || ! defined $stripLine
            || ! defined $modLine || ! defined $grpStringListRef || ! defined $matchMinusListRef
            || ! defined $matchPlusListRef || defined $check
        ) {
            return $axmud::CLIENT->writeImproper($self->_objClass . '->deadSeen', @_);
        }

        # Basic check - the trigger should belong to the right session
        if ($session ne $self->session) {

lib/Games/Axmud/Task.pm  view on Meta::CPAN

        #
        # This task's ->resetTriggers function creates some triggers to capture character
        #   resurrection strings. Group substrings and ->propertyHash aren't used.
        #
        # Updates some IVs and writes to the logfile which monitors character resurrections
        #
        # Expected arguments (standard args from GA::Session->checkTriggers)
        #   $session        - The calling function's GA::Session
        #   $interfaceNum   - The number of the active trigger interface that fired
        #   $line           - The line of text received from the world
        #   $stripLine      - $line, with all escape sequences removed
        #   $modLine        - $stripLine, possibly modified by previously-checked triggers
        #   $grpStringListRef
        #                   - Reference to a list of group substrings from the pattern match
        #                       (equivalent of @_)
        #   $matchMinusListRef
        #                   - Reference to a list of matched substring offsets (equivalent of @-)
        #   $matchPlusListRef
        #                   - Reference to a list of matched substring offsets (equivalent of @+)
        #
        # Return values
        #   'undef' on improper arguments, or if $session is the wrong session or if the interface
        #       object can't be found
        #   1 otherwise

        my (
            $self, $session, $interfaceNum, $line, $stripLine, $modLine, $grpStringListRef,
            $matchMinusListRef, $matchPlusListRef, $check,
        ) = @_;

        # Local variables
        my ($obj, $charObj);

        # Check for improper arguments
        if (
            ! defined $session || ! defined $interfaceNum || ! defined $line || ! defined $stripLine
            || ! defined $modLine || ! defined $grpStringListRef || ! defined $matchMinusListRef
            || ! defined $matchPlusListRef || defined $check
        ) {
            return $axmud::CLIENT->writeImproper($self->_objClass . '->resurrectedSeen', @_);
        }

        # Basic check - the trigger should belong to the right session
        if ($session ne $self->session) {

            return undef;
        }

        # Get the interface object itself
        $obj = $session->ivShow('interfaceNumHash', $interfaceNum);
        if (! $obj) {

            return undef;
        }

        # Respond to the fired trigger

        # Import the current character profile
        $charObj = $self->session->currentChar;

        # If the character is not already alive...
        if ($charObj && $charObj->lifeStatus ne 'alive') {

            $charObj->ivPoke('lifeStatus', 'alive');

            # The next time the task window is updated, its background colour will change
            $self->ivPoke('lifeStatusChangeFlag', TRUE);
        }

        return 1;
    }

    ##################
    # Accessors - set

    sub set_cashValues {

        # Called by GA::Task::Inventory->updateQuestStats
        # Sets the Status task's cash IVs
        #
        # Expected arguments
        #   $type       - Which type of pattern the Inventory task spotted: 'purse', 'deposit',
        #                   'deposit_only', 'withdraw', 'withdraw_only', 'balance', 'empty_purse'
        #                   or 'empty_bank'
        #   $cashValue  - The equivalent cash value, in the standard denomination specified by the
        #                   current world profile, of the pattern
        #
        # Return values
        #   'undef' on improper arguments or if there is no current character profile
        #   1 on success

        my ($self, $type, $cashValue, $check) = @_;

        # Local variables
        my ($charObj, $purse, $bank, $string);

        # Check for improper arguments
        if (
            ! defined $type || ! defined $cashValue
            || (
                $type ne 'purse'
                && $type ne 'deposit'
                && $type ne 'deposit_only'
                && $type ne 'withdraw'
                && $type ne 'withdraw_only'
                && $type ne 'balance'
                && $type ne 'empty_purse'
                && $type ne 'empty_bank'
            ) || defined $check
        ) {
            return $axmud::CLIENT->writeImproper($self->_objClass . '->set_cashValues', @_);
        }

        # Import the current character profile (for convenience)
        $charObj = $self->session->currentChar;
        if (! $charObj) {

            return undef;
        }

        # Prevent Perl rounding errors by rounding the value (if the world profile's
        #   ->currencyRounding is set to -1, we don't round anything)
        $cashValue = $self->roundCashValue($cashValue);
        # Get the current purse contents/bank balance, using a zero value if they're not defined

lib/Games/Axmud/Task.pm  view on Meta::CPAN

                $self->setValue('health_points', $val);
            } elsif ($var eq 'HEALTH_MAX' && ! $mode) {
                $self->setValue('health_points_max', $val);
            } elsif ($var eq 'LEVEL' && ! $mode) {
                $self->setValue('level', $val);
            } elsif ($var eq 'MANA' && ! $mode) {
                $self->setValue('magic_points', $val);
            } elsif ($var eq 'MANA_MAX' && ! $mode) {
                $self->setValue('magic_points_max', $val);
            } elsif ($var eq 'MONEY' && ! $mode) {
                $self->setValue('purse_contents', $val);
            } elsif ($var eq 'MOVEMENT' && ! $mode) {
                $self->setValue('energy_points', $val);
            } elsif ($var eq 'MOVEMENT_MAX' && ! $mode) {
                $self->setValue('energy_points_max', $val);
            } elsif ($var eq 'OPPONENT_LEVEL' && ! $mode) {
                $self->setValue('opp_level', $val);
            } elsif ($var eq 'OPPONENT_HEALTH' && ! $mode) {
                $self->setValue('opp_health', $val);
            } elsif ($var eq 'OPPONENT_HEALTH_MAX' && ! $mode) {
                $self->setValue('opp_health_max', $val);
            } elsif ($var eq 'OPPONENT_NAME' && ! $mode) {
                $self->setValue('opp_name', $val);
            } elsif ($var eq 'OPPONENT_STRENGTH' && ! $mode) {
                $self->setValue('opp_strength', $val);
            } elsif ($var eq 'WORLD_TIME' && ! $mode) {
                $self->setValue('time', $val);
            }
        }

        # (Regardless of whether an IV was updated, or not, mark the task window to be updated)
        $self->ivPoke('updateFlag', TRUE);

        return 1;
    }

    ##################
    # Accessors - task settings - get

    # The accessors for task settings are inherited from the generic task

    ##################
    # Accessors - task parameters - get

    sub cmdHash
        { my $self = shift; return %{$self->{cmdHash}}; }
    sub timerHash
        { my $self = shift; return %{$self->{timerHash}}; }

    sub updateFlag
        { $_[0]->{updateFlag} }
    sub lifeStatusChangeFlag
        { $_[0]->{lifeStatusChangeFlag} }
    sub healthChangeFlag
        { $_[0]->{healthChangeFlag} }
    sub convertTimeFlag
        { $_[0]->{convertTimeFlag} }

    sub allowColourFlag
        { $_[0]->{allowColourFlag} }
    sub aliveColour
        { $_[0]->{aliveColour} }
    sub alive50Colour
        { $_[0]->{alive50Colour} }
    sub alive30Colour
        { $_[0]->{alive30Colour} }
    sub alive10Colour
        { $_[0]->{alive10Colour} }
    sub asleepColour
        { $_[0]->{asleepColour} }
    sub passedOutColour
        { $_[0]->{passedOutColour} }
    sub deadColour
        { $_[0]->{deadColour} }

    sub constCharVarHash
        { my $self = shift; return %{$self->{constCharVarHash}}; }
    sub constFixedVarHash
        { my $self = shift; return %{$self->{constFixedVarHash}}; }
    sub constPseudoVarHash
        { my $self = shift; return %{$self->{constPseudoVarHash}}; }
    sub constLocalVarHash
        { my $self = shift; return %{$self->{constLocalVarHash}}; }
    sub constCounterVarHash
        { my $self = shift; return %{$self->{constCounterVarHash}}; }
    sub constCounterRevHash
        { my $self = shift; return %{$self->{constCounterRevHash}}; }
    sub constPointHash
        { my $self = shift; return %{$self->{constPointHash}}; }

    sub localVarHash
        { my $self = shift; return %{$self->{localVarHash}}; }
    sub customVarHash
        { my $self = shift; return %{$self->{customVarHash}}; }

    sub counterVarHash
        { my $self = shift; return %{$self->{counterVarHash}}; }
    sub counterBaseHash
        { my $self = shift; return %{$self->{counterBaseHash}}; }
    sub fightCountFlag
        { $_[0]->{fightCountFlag} }
    sub interactCountFlag
        { $_[0]->{interactCountFlag} }
    sub counterStartTime
        { $_[0]->{counterStartTime} }

    sub affectHash
        { my $self = shift; return %{$self->{affectHash}}; }
    sub statHash
        { my $self = shift; return %{$self->{statHash}}; }

    sub gaugeFlag
        { $_[0]->{gaugeFlag} }
    sub gaugeStripObj
        { $_[0]->{gaugeStripObj} }
    sub gaugeLevel
        { $_[0]->{gaugeLevel} }
    sub gaugeValueFlag
        { $_[0]->{gaugeValueFlag} }
    sub gaugeObjList
        { my $self = shift; return @{$self->{gaugeObjList}}; }
    sub gaugeResetFlag
        { $_[0]->{gaugeResetFlag} }

    sub ttsPointsAlertHash
        { my $self = shift; return %{$self->{ttsPointsAlertHash}}; }
    sub ttsPointsAlertMsgHash
        { my $self = shift; return %{$self->{ttsPointsAlertMsgHash}}; }



( run in 1.620 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )