Games-Axmud

 view release on metacpan or  search on metacpan

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

        $clone->{radioTableObj2}        = $self->radioTableObj2;
        $clone->{comboTableObj}         = $self->comboTableObj;

        $clone->{macroList}             = [$self->macroList];
        $clone->{macroHash}             = {$self->macroHash};

        $clone->{keypadDirHash}         = {$self->keypadDirHash};
        $clone->{keypadCmdHash}         = {$self->keypadCmdHash};
        $clone->{keypadHintHash}        = {$self->keypadHintHash};

        # Cloning complete
        return $clone;
    }

#   sub preserve {}             # Inherited from generic task

#   sub setParentFileObj {}     # Inherited from generic task

#   sub updateTaskLists {}      # Inherited from generic task

#   sub ttsReadAttrib {}        # Inherited from generic task

#   sub ttsSwitchFlagAttrib {}  # Inherited from generic task

#   sub ttsSetAlertAttrib {}    # Inherited from generic task

    ##################
    # Task windows

#   sub toggleWin {}            # Inherited from generic task

#   sub openWin {}              # Inherited from generic task

#   sub closeWin {}             # Inherited from generic task

    ##################
    # Methods

#   sub init {}                 # Inherited from generic task

    sub doInit {

        # Called by $self->init, just before the task completes its setup ($self->init)
        #
        # 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 . '->doInit', @_);
        }

        # Set up the keyboard macros
        $self->resetMacros();

        # If the task has recently been updated, quickest way to update the window is to remove all
        #   the current table objects, before creating new ones
        if ($self->hasResetFlag) {

            if (! defined $self->winObj->tableStripObj->removeAllTableObjs()) {

                # Operation failed; task must close
                $self->ivPoke('shutdownFlag', TRUE);
                return 1;
            }
        }

        # Draw widgets for the task window
        $self->createWidgets();

        # If the task window should start enabled, then enable it (by pseudo-clicking the second
        #   radio button)
        if ($self->enabledFlag) {

            $self->enable();
        }

        return 1;
    }

    sub doShutdown {

        # Called just before the task completes a shutdown
        # For process tasks, called by $self->main. For activity tasks, called by $self->shutdown
        #
        # Destroys any macros created by this task
        #
        # 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 . '->doShutdown', @_);
        }

        # Remove macros, ready for $self->resetMacros to be called to create new ones
        foreach my $interfaceObj ($self->macroList) {

            # The TRUE argument means 'don't show an error message if the interface doesn't exist'
            $self->session->deleteInterface($interfaceObj->name, TRUE);
        }

        return 1;
    }

    sub doReset {

        # Called just before the task completes a reset
        # For process tasks, called by $self->main. For activity tasks, called by $self->reset
        #
        # Destroys any macros created by this task
        #
        # Expected arguments
        #   $newTaskObj     - The replacement task object
        #
        # Return values
        #   'undef' on improper arguments
        #   1 otherwise

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

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

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

        # Remove macros, ready for $self->resetMacros to be called to create new ones
        foreach my $interfaceObj ($self->macroList) {

            # The TRUE argument means 'don't show an error message if the interface doesn't exist'
            $self->session->deleteInterface($interfaceObj->name, TRUE);
        }

        return 1;
    }

    sub resetMacros {

        # Called by $self->doInit to set up macros that fire when the user presses one of the keys
        #   on their keypad
        #
        # Expected arguments
        #   (none)
        #
        # Return values
        #   'undef' on improper arguments
        #   1 otherwise

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

        # Local variables
        my (
            $dictObj,
            @macroList,
            %dirHash, %cmdHash, %macroHash,
        );

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

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

        # Import the hash of standard directions (for quick lookup)
        %dirHash = $self->keypadDirHash;
        # Import the hash of keyboard commands (for quick lookup)
        %cmdHash = $self->keypadCmdHash;
        # Import the current dictionary
        $dictObj = $self->session->currentDict;

        # Create one macro (initially disabled) for each standard primary direction
        OUTER: foreach my $standardKeycode (keys %dirHash) {

            my ($standardDir, $interfaceObj);

            $standardDir = $dirHash{$standardKeycode};

            # If the value in a key-value pair is 'undef', the corresponding key (a standard
            #   keycode) isn't available to this task
            if (defined $standardDir) {

                # Create the independent macro interface
                $interfaceObj = $self->session->createIndependentInterface(
                    'macro',
                    $standardKeycode,                                   # Stimulus
                    $dictObj->ivShow('primaryDirHash', $standardDir),   # Response
                    'enabled',
                    0,
                );

                if (! $interfaceObj) {

                    $self->writeWarning(
                        'Couldn\'t create macro for the standard keycode \'' . $standardKeycode
                        . '\'',
                        $self->_objClass . '->resetMacros',
                    );

                    last OUTER;

                } else {

                    push (@macroList, $interfaceObj);
                }
            }
        }

        # Create one macro (initially disabled) for each command mentioned in
        #   $self->keypadCmdHash
        OUTER: foreach my $standardKeycode (keys %cmdHash) {

            my ($cmdString, $cmd, $interfaceObj);

            $cmdString = $cmdHash{$standardKeycode};

            # If the value in a key-value pair is 'undef', the corresponding key (a standard
            #   keycode) isn't available to this task
            if (defined $cmdString) {

                # $cmdString is in the form 'sharpen axe' (for a command to be sent unaltered), or
                #   in the form 'kill,victim,axe' (for a command to be interpolated)
                # Convert the string into the actual command to be sent (an empty string is an
                #   acceptable return value, in which case we don't create a macro so that no
                #   command is sent when the user presses the corresponding key)
                if ($cmdString =~ m/,/) {

                    $cmd = $self->session->prepareCmd(split(m/,/, $cmdString));
                }

                if (! defined $cmd) {

                    # Couldn't interpolate the command, so use the original string unaltered
                    $cmd = $cmdString;
                }

                if ($cmd) {

                    # Create the independent macro interface
                    $interfaceObj = $self->session->createIndependentInterface(
                        'macro',
                        $standardKeycode,       # Stimulus
                        $cmd,                   # Response
                        'enabled',
                        0,
                    );

                    if (! $interfaceObj) {

                        $self->writeWarning(
                            'Couldn\'t create macro for the standard keycode \'' . $standardKeycode
                            . '\'',
                            $self->_objClass . '->resetMacros',
                        );

                        last OUTER;

                    } else {

                        push (@macroList, $interfaceObj);
                        $macroHash{$standardKeycode} = $interfaceObj;
                    }
                }
            }
        }

        # Update IVs
        $self->ivPoke('macroList', @macroList);
        $self->ivPoke('macroHash', %macroHash);

        return 1;
    }

    sub createWidgets {

        # Set up the widgets used in the task window
        #
        # Expected arguments
        #   (none besides $self)
        #
        # Return values
        #   'undef' on improper arguments or if the task window isn't open
        #   1 otherwise

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

        # Local variables
        my (
            $cmd, $radioTableObj, $radioTableObj2, $comboTableObj,
            @list, @comboList,
            %dirHash, %abbrevHash, %keypadHintHash, %keypadCmdHash, %compassHash, %cmdHash,
            %cmdKeycodeHash,
        );

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

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

        # If the task window (a 'grid' window or a pseudo-window inside the session's 'main' window)
        #   isn't open, don't need to create widgets
        if (! $self->winObj) {

            return undef;
        }

        # Import the current dictionary's primary directions
        %dirHash = $self->session->currentDict->primaryDirHash;
        %abbrevHash = $self->session->currentDict->primaryAbbrevHash;
        # Import some local hashes
        %keypadHintHash = $self->keypadHintHash;
        %keypadCmdHash = $self->keypadCmdHash;

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

            } elsif ($taskType ne 'current' && $taskType ne 'initial' && $taskType ne 'custom') {

                return $session->writeError(
                    'Can\'t create new task because \'' . $taskType . '\' is an invalid tasklist',
                    $class . '->new',
                );
            }
        }

        # Task settings
        my $self = Games::Axmud::Generic::Task->new(
            $session,
            $taskType,
            $profName,
            $profCategory,
            $customName,
        );

        $self->{_objName}               = 'connections_task';
        $self->{_objClass}              = $class;
        $self->{_parentFile}            = undef;            # Set below
        $self->{_parentWorld}           = undef;            # Set below
        $self->{_privFlag}              = TRUE,             # All IVs are private

        $self->{name}                   = 'connections_task';
        $self->{prettyName}             = 'Connections';
        $self->{shortName}              = 'Co';
        $self->{shortCutIV}             = 'connectionsTask'; # Axmud built-in jealous task

        $self->{category}               = 'process';
        $self->{descrip}                = 'Display a constantly-updated list of connections';
        $self->{jealousyFlag}           = TRUE;
        $self->{requireLocatorFlag}     = FALSE;
        $self->{profSensitivityFlag}    = FALSE;
        $self->{storableFlag}           = TRUE;
        $self->{delayTime}              = 0.2;
        $self->{allowWinFlag}           = TRUE;
        $self->{requireWinFlag}         = FALSE;
        $self->{startWithWinFlag}       = TRUE;
        $self->{winPreferList}          = ['pane', 'grid'];
        $self->{winmap}                 = 'basic_fill';
        $self->{winUpdateFunc}          = undef;
        $self->{tabMode}                = 'simple';
        $self->{monochromeFlag}         = FALSE;
        $self->{noScrollFlag}           = TRUE;
        $self->{ttsFlag}                = FALSE;
        $self->{ttsConfig}              = undef;
        $self->{ttsAttribHash}          = {};
        $self->{ttsFlagAttribHash}      = {};
        $self->{ttsAlertAttribHash}     = {};
        $self->{status}                 = 'wait_init';
#       $self->{activeFlag}             = TRUE;             # Task can't be activated/disactivated

        # Task parameters
        # Flag set to TRUE if the connection/idle times for each session should be shown, FALSE if
        #   not
        $self->{showInfoFlag}           = FALSE;
        # This task creates macros to intercept CTRL+1, CTRL+2 ... CTRL+9 (or an equivalent set of
        #   keypresses). If this flag is TRUE, the macros are created enabled; if FALSE, they are
        #   created disabled
        $self->{useMacrosFlag}          = TRUE;
        # Which set of keypresses to use:
        #   'default'   - CTRL+1, CTRL+2 ... CTRL+9
        #   'simple'    - F1, F2 ... F9
        $self->{macroMode}              = 'default';
        # A list of macros created
        $self->{macroList}              = [];

        # Bless task
        bless $self, $class;

        # For all tasks that aren't temporary...
        if ($taskType) {

            # Check that the task doesn't belong to a disabled plugin (in which case, it can't be
            #   added to any current, initial or custom tasklist)
            if (! $self->checkPlugins()) {

                return undef;
            }

            # Set the parent file object
            $self->setParentFileObj($session, $taskType, $profName, $profCategory);

            # Create entries in tasklists, if possible
            if (! $self->updateTaskLists($session)) {

                return undef;
            }
        }

        # Task creation complete
        return $self;
    }

    sub clone {

        # Create a clone of an existing task
        # Usually used upon connection to a world, when every task in the initial tasklists must
        #   be cloned into a new object, representing a task in the current tasklist
        # (Also used when cloning a profile object, since all the tasks in its initial tasklist must
        #   also be cloned)
        #
        # Expected arguments
        #   $session    - The parent GA::Session (not stored as an IV)
        #   $taskType   - Which tasklist this task is being created into - 'current' for the current
        #                   tasklist (tasks which are actually running now), 'initial' (tasks which
        #                   should be run when the user connects to the world). Custom tasks aren't
        #                   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->{showInfoFlag}          = $self->showInfoFlag;
        $clone->{useMacrosFlag}         = {$self->useMacrosFlag};
        $clone->{macroMode}             = {$self->macroMode};

        # 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 command lists
        $newTask->ivPoke('showInfoFlag', $self->showInfoFlag);
        $newTask->ivPoke('useMacrosFlag', $self->useMacrosFlag);
        $newTask->ivPoke('macroMode', $self->macroMode);

        return 1;
    }

#   sub setParentFileObj {}     # Inherited from generic task

#   sub updateTaskLists {}      # Inherited from generic task

#   sub ttsReadAttrib {}        # Inherited from generic task

#   sub ttsSwitchFlagAttrib {}  # Inherited from generic task

#   sub ttsSetAlertAttrib {}    # Inherited from generic task

    ##################
    # Task windows

#   sub toggleWin {}            # Inherited from generic task

#   sub openWin {}              # Inherited from generic task

#   sub closeWin {}             # Inherited from generic task

    ##################
    # Methods

#   sub main {}                 # Inherited from generic task

#   sub doShutdown {}           # Inherited from generic task

#   sub doReset {}              # Inherited from generic task

#   sub doFirstStage {}         # Inherited from generic task

    sub doStage {

        # Called by $self->main to process all stages (except stage 1)
        #
        # Expected arguments
        #   (none besides $self)
        #
        # Return values
        #   'undef' on improper arguments or if this function sets that task's ->status IV to
        #       'finished' or sets its ->shutdownFlag to TRUE
        #   Otherwise, we normally return the new value of $self->stage

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

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

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

        if ($self->stage == 2) {

            # Create macros to intercept CTRL+1, CTRL+2 ... CTRL+9
            if (! $self->resetMacros()) {

                $self->writeError(
                    'Could not create macros for the ' . $self->prettyName . ' task, so halting',
                    $self->_objClass . '->doStage',
                );

                # Mark the task to be shutdown
                $self->ivPoke('shutdownFlag', TRUE);
                return undef;

            } else {

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

        } elsif ($self->stage == 3) {

            my ($string, $count);

            # On every spin of the task loop, update the task window (if it is open)
            if ($self->taskWinFlag) {

                # Add the header
                if ($axmud::CLIENT->shareMainWinFlag) {
                    $string = ') (* current, > visible)';
                } else {
                    $string = ') (* current)';
                }

                $self->insertText(
                    'CONNECTIONS (Time ' . int($self->session->sessionTime) . $string,
                    'empty',
                );

                if (! $self->showInfoFlag) {

                    $self->insertText('   #  World            Character        Status');

                } else {

                    $self->insertText(
                        '   #  World            Character        Status       Info',
                    );
                }

                # Add the remaining lines, one for each session
                $count = 0;
                foreach my $otherSession (
                    sort {lc($a) cmp lc($b)} ($axmud::CLIENT->ivValues('sessionHash'))
                ) {
                    my ($column, $colour, $char);

                    $count++;


                    if ($otherSession eq $self->session) {
                        $column = '*';
                    } else {
                        $column = ' ';
                    }

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

                        $column .= '> ';
                    } else {
                        $column .= '  ';
                    }

                    $self->insertText($column . sprintf('%-2.2s ', $count));

                    # Use the same colour as the 'main' window tab
                    if ($otherSession->status eq 'offline') {
                        $colour = 'magenta';
                    } elsif ($otherSession->status eq 'disconnected') {
                        $colour = 'blue';
                    } elsif ($otherSession->showNewTextFlag) {
                        $colour = 'red';
                    } else {
                        $colour = $self->defaultTabObj->textViewObj->textColour;
                    }

                    $self->insertText(
                        sprintf('%-16.16s ', $otherSession->currentWorld->name),
                        'echo',
                        $colour,
                    );

                    if ($otherSession->currentChar) {
                        $char = $otherSession->currentChar->name;
                    } else {
                        $char = '<none>';
                    }

                    $self->insertText(
                        sprintf(
                            '%-16.16s %-12.12s',
                            $char,
                            $otherSession->status,
                        ),
                        'echo',
                    );

                    if ($self->showInfoFlag) {


                        $self->insertText(
                            ' ' . $otherSession->getTimeLabelText(),
                            'echo',
                        );
                    }
                }
            }

            # Repeat this stage indefinitely
            return $self->ivPoke('stage', 3);

        } else {

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

    sub resetMacros {

        # Called by $self->doStage at stage 2 to set up macros to intercept CTRL+1, CTRL+2 ...
        #   CTRL+9 (or equivalents)
        #
        # Expected arguments
        #   (none)
        #
        # Return values
        #   'undef' on improper arguments
        #   1 otherwise

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

        # Local variables
        my @macroList;

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

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

        # Create one macro (initially disabled) for each keycode string between 1-9
        for (my $count = 1; $count <= 9; $count++) {

            my ($interfaceObj, $keycodeString);

            if ($self->macroMode eq 'simple') {
                $keycodeString = 'f' . $count;      # e.g. 'f1'
            } else {
                $keycodeString = 'ctrl ' . $count;  # e.g. 'ctrl 1';
            }

            # Create the dependent macro interface
            $interfaceObj = $self->session->createDependentInterface(
                'macro',
                $keycodeString,
                $self,
                'macroSeen',
                'enabled',
                $self->useMacrosFlag,
            );

            if (! $interfaceObj) {

                # If there's an error creating any macros, remove any macros already created
                $self->session->tidyInterfaces($self);
                return undef;

            } else {

                push (@macroList, $interfaceObj);

                # Give the trigger some properties that will give $self->macroSeen a number between
                #   1-9 (quicker than processing the interface object's IVs)
                $interfaceObj->ivAdd('propertyHash', 'number', $count);
            }
        }

        # Update IVs
        $self->ivPoke('macroList', @macroList);

        return 1;
    }

    ##################
    # Response methods

    sub macroSeen {

        # Called by GA::Session->checkMacros
        #
        # This task's ->resetMacros function creates some macros to capture CTRL+1, CTRL+2 ...
        #   CTRL+9 (or equivalents)
        #
        # If the number corresponds to a session, that session is made the visible one
        #
        # The trigger interfaces have the following properties in ->propertyHash:
        #   number          - A number between 1 and 9
        #
        # 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
        #   $keycodeString  - The keycode string, e.g. 'ctrl 1'
        #
        # 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, $keycodeString, $check) = @_;

        # Local variables
        my (
            $obj, $number, $newSession,
            @list,
        );

        # Check for improper arguments
        if (
            ! defined $session || ! defined $interfaceNum || ! defined $keycodeString
            || defined $check
        ) {
            return $axmud::CLIENT->writeImproper($self->_objClass . '->macroSeen', @_);
        }

        # 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 macro

        $number = $obj->ivShow('propertyHash', 'number');
        # Find the equivalent GA::Session. $number is a value between 1-9, representing the first
        #   nine sessions which are still running, in the order they were created
        @list = sort {$a->number <=> $b->number} ($axmud::CLIENT->ivValues('sessionHash'));
        # If there aren't enough session, $newSession will remain as 'undef'
        $newSession = $list[$number - 1];
        if (defined $newSession) {

            $newSession->defaultTabObj->paneObj->setVisibleTab($newSession->defaultTabObj);
            $newSession->mainWin->restoreFocus();
        }

        return 1;
    }

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

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

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

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

    sub showInfoFlag
        { $_[0]->{showInfoFlag} }
    sub useMacrosFlag
        { $_[0]->{useMacrosFlag} }
    sub macroMode
        { $_[0]->{macroMode} }
    sub macroList
        { my $self = shift; return @{$self->{macroList}}; }
}

{ package Games::Axmud::Task::Countdown;

    use strict;
    use warnings;
#   use diagnostics;

    use Glib qw(TRUE FALSE);

    our @ISA = qw(Games::Axmud::Generic::Task Games::Axmud);

    ##################
    # Constructors

    sub new {

        # Creates a new instance of the Countdown task
        #
        # Expected arguments
        #   $session    - The parent GA::Session (not stored as an IV)
        #
        # Optional arguments
        #   $taskType   - Which tasklist this task is being created into - 'current' for the current
        #                   tasklist (tasks which are actually running now), 'initial' (tasks which
        #                   should be run when the user connects to the world), 'custom' (tasks with
        #                   customised initial parameters, which are run when the user demands). If
        #                   set to 'undef', this is a temporary task, created in order to access the
        #                   default values stored in IVs, that will not be added to any tasklist
        #   $profName   - ($taskType = 'current', when called by $self->clone) Name of the
        #                   profile from whose initial tasklist this task was created ('undef' if
        #                   none)
        #               - ($taskType = 'initial') name of the profile in whose initial tasklist this
        #                   task will be. If 'undef', the global initial tasklist is used
        #               - ($taskType = 'custom') 'undef'
        #   $profCategory
        #               - ($taskType = 'current', 'initial') which category the profile falls undef
        #                   (i.e. 'world', 'race', 'char', etc, or 'undef' if no profile)
        #               - ($taskType = 'custom') 'undef'
        #   $customName
        #               - ($taskType = 'current', 'initial') 'undef'
        #               - ($taskType = 'custom') the custom task name, matching a key in
        #                   GA::Session->customTaskHash
        #
        # Return values
        #   'undef' on improper arguments or if the task can't be added to the specified tasklist
        #   Blessed reference to the newly-created object on success

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

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

            return $axmud::CLIENT->writeImproper($class . '->new', @_);
        }

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

                $self->taskWinGaugeStripObj->removeGaugeLevel(
                    $self->session, $self->taskWinGaugeLevel,
                );
            }
        }

        return 1;
    }

    sub setTaskWinStatusBar {

        # Called by LA::Statement::winsetstatus->implement
        # Sets the values displayed by the status bar, and tells the 'main' window to re-draw its
        #   gauges/status bars
        #
        # Expected arguments
        #   $number     - A local status bar number for this task, matching a key in
        #                   $self->taskWinStatusBarHash (not related to GA::Obj::Gauge->number)
        #
        # Optional arguments
        #   $val        - The value to use that's the equivalent of the full portion of a
        #                   (graphical) gauge. Can be set to 'undef' if the value supplied by the
        #                   Axbasic script wasn't a valid decimal number
        #   $maxVal     - The value to use that's the equivalent of the empty portion of a
        #                   (graphical) gauge. Can also be set to 'undef'
        #
        # Return values
        #   'undef' on improper arguments
        #   1 otherwise

        my ($self, $number, $val, $maxVal, $check) = @_;

        # Local variables
        my $gaugeObj;

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

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

        $gaugeObj = $self->ivShow('taskWinStatusBarHash', $number);
        # If the status bar with this local $number exists...
        if ($gaugeObj) {

            $gaugeObj->ivPoke('value', $val);
            $gaugeObj->ivPoke('maxValue', $maxVal);

            $self->taskWinGaugeStripObj->updateGauges();
        }

        return 1;
    }

    ##################
    # Response methods

    sub interfaceWaitSeen {

        # Called by GA::Session->processLineSegment, after that function has called ->checkTriggers;
        #   or by GA::Session->checkAliases, ->checkMacros (etc)
        #
        # The Axbasic statement WAITTRIG causes the script to create a trigger to wait for a
        #   particular pattern in the text received from the world
        #      e.g. The door swings open!
        #
        # When the pattern is found, the script resumes. WAITALIAS, WAITMACRO, WAITTIMER and
        #   WAITHOOK behave in similar ways
        # This function updates IVs and resumes this task, which should be paused. Group substrings
        #   (for triggers/aliases) and additional data (for timers/hooks) are ignored
        #
        # Expected arguments
        #   $session        - The calling function's GA::Session
        #   $interfaceNum   - The number of the active trigger interface that fired
        #   @ignoreList     - Any other data supplied by the calling function is added to this list
        #                       and ignored
        #
        # Return values
        #   'undef' on improper arguments or if $session is the wrong session
        #   1 otherwise

        my ($self, $session, $interfaceNum, @ignoreList) = @_;

        # Local variables
        my $obj;

        # Check for improper arguments
        if (! defined $session || ! defined $interfaceNum ) {

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

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

            return undef;
        }

        # (Standard code commented out, because the temporary interface has already deleted itself)
#        # Get the interface object itself
#        $obj = $session->ivShow('interfaceNumHash', $interfaceNum);
#        if (! $obj) {
#
#            return undef;
#        }

        # Respond to the fired interface

        # Update the AB::Script's list of dependent interfaces to remove the one that has just
        #   fired (it's a temporary interface which the GA::Session is going to delete soon)
        $self->scriptObj->updateInterfaces($self->waitForInterface);
        # After a pause, the script's step count (how many statements to execute before taking a
        #   short break) needs to be reset
        $self->scriptObj->set_stepCount(0);

        # Update this task's IVs
        $self->resetInterface();

        return 1;
    }

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

        #   new_script       - The name of the second script to run (only used in calls to
        #                       $self->aliasExecSeen, 'undef' in calls to this function)
        #
        # Expected arguments (standard args from GA::Session->checkAliases)
        #   $session         - The calling function's GA::Session
        #   $interfaceNum    - The number of the active alias interface that fired
        #   $worldCmd        - The world command that caused the alias to fire
        #
        # Optional arguments
        #   @groupStringList - A list of group substrings from the pattern match (equivalent of @_,
        #                       may be an empty list)
        #
        # 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, $worldCmd, @groupStringList) = @_;

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

        # Check for improper arguments
        if (! defined $session || ! defined $interfaceNum || ! defined $worldCmd) {

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

        # Basic check - the alias 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 alias
        $scriptName = $obj->ivShow('propertyHash', 'new_script');
        if ($scriptName) {

            # SETALIAS statement specified a second script to run
            return $self->session->pseudoCmd('runscript ' . $scriptName);

        } else {

            # No second script to run. Notify the Axbasic programme that one of its dependent
            #   aliases has fired
            $self->scriptObj->interfaceNotification($obj, $worldCmd, @groupStringList);
        }

        return 1;
    }

    sub macroNotifySeen {

        # Called by GA::Session->checkMacros
        #
        # The Axbasic statement SETMACRO causes the script to create a macro to notice a keypress or
        #   a combination of keypresses
        #      e.g. 'ctrl f1'
        #
        # If SETMACRO specified a second script to run, this function runs it. Otherwise, this
        #   function notifies the script that the keycode string was processed (and only the script
        #   will do something in response)
        #
        # The macro interface has the following properties in ->propertyHash:
        #   new_script       - The name of the second script to run (only used in calls to
        #                       $self->macroExecSeen, 'undef' in calls to this function)
        #
        # Expected arguments (standard args from GA::Session->checkMacros)
        #   $session        - The calling function's GA::Session
        #   $interfaceNum   - The number of the active macro interface that fired
        #   $keycodeString  - The keycode string for keypress(es) that caused the macro to fire
        #
        # 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, $keycodeString, $check) = @_;

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

        # Check for improper arguments
        if (
            ! defined $session || ! defined $interfaceNum || ! defined $keycodeString
            || defined $check
        ) {
            return $axmud::CLIENT->writeImproper($self->_objClass . '->macroNotifySeen', @_);
        }

        # Basic check - the macro 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 macro
        $scriptName = $obj->ivShow('propertyHash', 'new_script');
        if ($scriptName) {

            # SETMACRO statement specified a second script to run
            return $self->session->pseudoCmd('runscript ' . $scriptName);

        } else {

            # No second script to to run. Notify the Axbasic programme that one of its dependent
            #   macros has fired
            $self->scriptObj->interfaceNotification($obj, $keycodeString);

            return 1;
        }
    }

    sub timerNotifySeen {

        # Called by GA::Session->checkTimers
        #
        # The Axbasic statement SETTIMER causes the script to notice when a timer it has created has
        #   fired
        #
        # If SETTIMER specified a second script to run, this function runs it. Otherwise, this



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