Games-Axmud

 view release on metacpan or  search on metacpan

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

                        # This cage is the superior of the previous one
                        push (@sortedList, $cageName);
                        $sortedHash{$cageName} = $unsortedHash{$cageName};
                        delete $unsortedHash{$cageName};

                        $lastCage = $cageName;
                        $failFlag = FALSE;
                        last INNER;
                    }
                }
            }
        }

        # Final step - cage names can be up to 42 characters. Go throught the whole sorted list and
        #   work out the length of the longest cage name. If it's 32 characters or less, can display
        #   cages in 2 columns; otherwise we'll have to display them in one column
        OUTER: foreach my $cage (@sortedList) {

            if (length($cage) > 32) {

                $longFlag = TRUE;
                last OUTER;
            }
        }

        # As usual, don't display a list, if the list is empty...
        if (! @sortedList) {

            return $self->complete($session, $standardCmd, 'The cage list is empty');
        }

        # Display header
        $session->writeText(
            'List of ' . $type . ' cages (inferiors listed first) (* = current, x = unattached)',
        );

        if (! $longFlag) {

            $session->writeText('   Cage name                        Inferior cage');
        }

        # Display list
        $level = 0;
        foreach my $cage (@sortedList) {

            my ($obj, $gap, $inferiorObj, $string);

            $obj = $sortedHash{$cage};

            if ($session->ivExists('currentCageHash', $obj->name)) {
                $gap = ' * ';
            } else {
                $gap = '   ';
            }

            $inferiorObj = $session->ivShow('inferiorCageHash', $cage);
            if ($inferiorObj) {

                $level++;
                $string = '';
                # Display strings in a cascade, depending on the number of inferiors they have
                for (my $count = 0; $count < $level; $count++) {

                    $string .= ' ';
                }

                if ($longFlag) {

                    $session->writeText($gap . $string . sprintf('%-42.42s', $cage));

                } else {

                    $session->writeText(
                        $gap . $string . sprintf(
                            '%-32.32s %-32.32s',
                            $cage,
                            $inferiorObj->name,
                        )
                    );
                }

            } else {

                $level = 0;

                if ($longFlag) {
                    $session->writeText($gap . sprintf('%-42.42s', $cage));
                } else {
                    $session->writeText($gap . sprintf('%-32.32s (No inferior cage)', $cage));
                }
            }
        }

        # Display anything remaining in %unsortedHash (just in case)
        @unsortedList = sort {lc($a) cmp lc($b)} (keys %unsortedHash);
        foreach my $cage (@unsortedList) {

            my ($obj, $inferiorObj, $inferiorName);

            $obj = $unsortedHash{$cage};
            $inferiorObj = $session->ivShow('inferiorCageHash', $obj->name);
            if ($inferiorObj) {
                $inferiorName = $inferiorObj->name;
            } else {
                $inferiorName = '';
            }

            $session->writeText(
                ' x ' . sprintf(
                    '%-32.32s %-32.32s',
                    $unsortedHash{$cage}->name,
                    $inferiorName,
                )
            );
        }

        # Display footer
        if (@sortedList == 1) {

            return $self->complete($session, $standardCmd, 'List displayed (1 cage found)');



( run in 3.079 seconds using v1.01-cache-2.11-cpan-2398b32b56e )