Class LegionServerSide

  • All Implemented Interfaces:
    java.lang.Comparable<LegionServerSide>

    public final class LegionServerSide
    extends Legion
    implements java.lang.Comparable<LegionServerSide>
    Class Legion represents a Titan stack of Creatures and its stack marker.
    Author:
    David Ripton, Romain Dolbeau
    • Field Detail

      • LOGGER

        private static final java.util.logging.Logger LOGGER
      • parent

        private final Legion parent
      • startingHex

        private MasterHex startingHex
        The label of the starting hex of the last move.
    • Constructor Detail

      • LegionServerSide

        public LegionServerSide​(java.lang.String markerId,
                                Legion parent,
                                MasterHex currentHex,
                                MasterHex startingHex,
                                Player player,
                                GameServerSide game,
                                CreatureType... creatureTypes)
        Creates a new Legion instance. Not that this class does not constraint the number of creatures. In a normal Titan game it is between 0 and 8 creatures, but this class does not enforce this. TODO the game parameter should be redundant since it should be the same as player.getGame()
    • Method Detail

      • getPointValue

        public int getPointValue()
        Description copied from class: Legion
        TODO unify between the two derived classes if possible -- the handling of Titans is quite different, although it should have the same result
        Specified by:
        getPointValue in class Legion
      • askAcquirablesDecisions

        public void askAcquirablesDecisions()
        For each acquirable decision, ask the client to choose one of the possible acquirables.
      • getBattleTally

        int getBattleTally()
      • clearBattleTally

        void clearBattleTally()
      • clearBattleInfo

        void clearBattleInfo()
      • addToBattleTally

        void addToBattleTally​(int points)
      • addBattleTallyToPoints

        void addBattleTallyToPoints()
      • getMarkerName

        public java.lang.String getMarkerName()
      • getMarkerName

        public static java.lang.String getMarkerName​(java.lang.String markerId)
      • getLongMarkerName

        public static java.lang.String getLongMarkerName​(java.lang.String markerId)
      • getLongMarkerName

        public java.lang.String getLongMarkerName()
      • getParent

        public Legion getParent()
      • getPlayer

        public PlayerServerSide getPlayer()
        Description copied from class: Legion
        Retrieves the player this legion belongs to.
        Overrides:
        getPlayer in class Legion
        Returns:
        The matching player. Never null.
      • remove

        void remove​(boolean returnCrittersToStacks,
                    boolean updateHistory)
        Eliminate this legion.
      • remove

        void remove()
      • prepareToRemove

        void prepareToRemove​(boolean returnCrittersToStacks,
                             boolean updateHistory)
        Do the cleanup required before this legion can be removed.
      • hasConventionalMove

        boolean hasConventionalMove()
      • undoMove

        void undoMove()
      • commitMove

        void commitMove()
        Called at end of player turn.
      • canRecruit

        boolean canRecruit()
        hasMoved() is a separate check, so that this function can be used in battle as well as during the muster phase. TODO move up
      • undoRecruit

        void undoRecruit()
      • editRemoveCreature

        void editRemoveCreature​(CreatureType creature)
      • undoReinforcement

        void undoReinforcement()
      • canSummonAngel

        boolean canSummonAngel()
        Return true if this legion can summon. TODO likely candidate for pulling up
      • addCreature

        boolean addCreature​(CreatureType creature,
                            boolean takeFromStack)
        Add a creature to this legion. If takeFromStack is true, then do this only if such a creature remains in the stacks, and decrement the number of this creature type remaining.
      • removeCreature

        CreatureType removeCreature​(int i,
                                    boolean returnToStack,
                                    boolean disbandIfEmpty)
        Remove the creature in position i in the legion. Return the removed creature. Put immortal creatures back on the stack and others to the Graveyard if returnImmortalToStack is true.
      • removeCreature

        CreatureType removeCreature​(CreatureType creature,
                                    boolean returnImmortalToStack,
                                    boolean disbandIfEmpty)
        Remove the first creature matching the passed creature's type from the legion. Return the removed creature.
      • prepareToRemoveCritter

        void prepareToRemoveCritter​(Creature critter,
                                    boolean returnToStacks,
                                    boolean updateHistory)
        Do the cleanup associated with removing the critter from this legion. Do not actually remove it, to prevent co-modification errors. Do not disband the legion if empty, since the critter has not actually been removed.
      • getCreatures

        public java.util.List<CreatureServerSide> getCreatures()
        Description copied from class: Legion
        TODO should be an unmodifiable List, but can't at the moment since both derived classes and users might still expect to change it TODO should be List, but subtypes are still covariant
        Overrides:
        getCreatures in class Legion
      • getCritterByTag

        CreatureServerSide getCritterByTag​(int tag)
        Return the first critter with a matching tag.
      • moveToTop

        boolean moveToTop​(CreatureServerSide critter)
        Move critter to the first position in the critters list. Return true if it was moved.
      • getCritter

        Creature getCritter​(CreatureType creatureType)
        Gets the first critter in this legion with the same creature type as the passed creature.
      • sortCritters

        void sortCritters()
        Sort critters into descending order of importance. TODO maybe a SortedSet would be better instead of sorting every now and then
      • recombine

        void recombine​(Legion legion,
                       boolean remove)
        Recombine this legion into another legion. Only remove this legion from the Player if remove is true. If it's false, the caller is responsible for removing this legion, which can avoid concurrent access problems. Someone needs to call MasterBoard.alignLegions() on the remaining legion's hexLabel after the recombined legion is actually removed.
      • split

        LegionServerSide split​(java.util.List<CreatureType> creatures,
                               java.lang.String newMarkerId)
        Split off creatures into a new legion using legion marker markerId. (Or the first available marker, if markerId is null.) Return the new legion, or null if there's an error.
      • listTeleportingLords

        java.util.List<CreatureType> listTeleportingLords​(MasterHex hex)
        List the lords eligible to teleport this legion to hexLabel.
      • compareTo

        public int compareTo​(LegionServerSide other)
        Legions are sorted in descending order of total point value, with the titan legion always coming first. TODO This is inconsistent with equals() which means the Comparable contract is not fulfilled. Probably better of in a Comparator in any case.
        Specified by:
        compareTo in interface java.lang.Comparable<LegionServerSide>