Class Client

All Implemented Interfaces:
IClient
Direct Known Subclasses:
BotClient, HeadlessClient

public class Client extends AbstractClient
This class is instantiated for each client and for each bot running on that client. non-local clients are not also instantiated on the local server.
  • Field Details

    • game

      protected final Game game
      The game state object: this object is not ever replaced during a game, only updated. A reference can therefore be cached by other objects.
  • Constructor Details

    • Client

      public Client(String name, String host, int port)
  • Method Details

    • getGame

      public Game getGame()
      Description copied from interface: IClient
      Returns the game of this client as a game-type independent IGame. Note that the game object is only updated, not replaced and a reference to it can therefore be kept.
      Returns:
      The game of this client
    • getEntity

      public Entity getEntity(int id)
    • getSelectedEntities

      public Iterator<Entity> getSelectedEntities(EntitySelector selector)
      Returns an Enumeration of the entities that match the selection criteria.
    • getFirstEntityNum

      public int getFirstEntityNum()
      Returns the number of first selectable entity
    • getNextEntityNum

      public int getNextEntityNum(int entityId)
      Returns the number of the next selectable entity after the one given
    • getPrevEntityNum

      public int getPrevEntityNum(int entityId)
      Returns the number of the previous selectable entity after the one given
    • getFirstDeployableEntityNum

      public int getFirstDeployableEntityNum()
      Returns the number of the first deployable entity
    • getNextDeployableEntityNum

      public int getNextDeployableEntityNum(int entityId)
      Returns the number of the next deployable entity
    • getBoard

      public Board getBoard()
      Shortcut to game.board
    • getBoard

      @Nullable public Board getBoard(int boardId)
      Returns the board with the given boardId or null if the game does not have a board of that boardId. Shortcut to game.getBoard(int).
      Parameters:
      boardId - The board's ID
      Returns:
      The board with the given ID
      See Also:
    • getEntitiesVector

      public List<Entity> getEntitiesVector()
      Returns an enumeration of the entities in game.entities
    • getMapSettings

      public MapSettings getMapSettings()
    • changePhase

      public void changePhase(GamePhase phase)
      Changes the game phase, and the displays that go along with it.
      Overrides:
      changePhase in class AbstractClient
      Parameters:
      phase - the phase switching from.
    • isMyTurn

      public boolean isMyTurn()
      Returns:
      True when the currently active turn is a turn for the local player
    • getMyTurn

      public GameTurn getMyTurn()
    • receiveTurns

      protected void receiveTurns(Packet packet) throws InvalidPacketDataException
      Loads the turn list from the data in the packet
      Throws:
      InvalidPacketDataException
    • canUnloadStranded

      public boolean canUnloadStranded()
      Can I unload entities stranded on immobile transports?
    • deploy

      public void deploy(int id, Coords coords, int boardId, int nFacing, int elevation, List<Entity> loadedUnits, boolean assaultDrop)
      Deploy an entity at the given coordinates, with the given facing, and starting with the given units already loaded.
      Parameters:
      id - the ID of the deployed entity
      coords - the Coords where the entity should be deployed
      nFacing - the direction the entity should face
      loadedUnits - a List of units that start the game being transported by the deployed entity.
      assaultDrop - true if deployment is an assault drop
    • sendPlayerPickedPassThrough

      public void sendPlayerPickedPassThrough(Integer targetId, Integer attackerId, Coords pos)
      For ground to air attacks, the ground unit targets the closest hex in the air units flight path. In the case of several equidistant hexes, the attacker gets to choose. This method updates the server with the users choice.
      Parameters:
      targetId - The target ID
      attackerId - The attacker Entity ID
      pos - The selected hex
    • sendAttackData

      public void sendAttackData(int aen, Vector<EntityAction> attacks)
      Send a weapon fire command to the server.
    • sendPrePhaseData

      public void sendPrePhaseData(int aen)
      Send s done with prephase turn
    • sendGhostTargetAction

      public void sendGhostTargetAction(int sourceEntityId, int equipmentId, int targetEntityId)
      Send a ghost target action to the server (Standard mode, TO:AR rules). The server performs the Piloting+3 roll and derives friendliness from entity ownership.
      Parameters:
      sourceEntityId - the entity generating the ghost target
      equipmentId - the equipment number on the source entity
      targetEntityId - the entity being targeted
    • sendGameOptions

      public void sendGameOptions(String password, Vector<IBasicOption> options)
      Send the game options to the server
    • sendMapSettings

      public void sendMapSettings(MapSettings settings)
      Send the new map selection to the server
    • sendMapDimensions

      public void sendMapDimensions(MapSettings settings)
      Send the new map dimensions to the server
    • sendPlanetaryConditions

      public void sendPlanetaryConditions(PlanetaryConditions conditions)
      Send the planetary Conditions to the server
    • sendLobbyBoardGenerationRequest

      public void sendLobbyBoardGenerationRequest()
      Asks the server to build the game board from the current map settings and broadcast it to all clients while still in the lobby, so that all players can see the battlefield that will actually be played.
    • sendRerollInitiativeRequest

      public void sendRerollInitiativeRequest()
      Sends a "reroll initiative" message to the server.
    • sendResetRoundDeployment

      public void sendResetRoundDeployment()
      Reset round deployment packet
    • sendEntityWeaponOrderUpdate

      public void sendEntityWeaponOrderUpdate(Entity entity)
    • sendAddEntity

      public void sendAddEntity(List<Entity> entities)
      Sends an "add entity" packet that contains a collection of Entity objects.
      Parameters:
      entities - The collection of Entity objects to add. This should ideally be an ArrayList<Entity>, but other kinds of List will be converted to an ArrayList.
    • sendAddSquadron

      public void sendAddSquadron(FighterSquadron fighterSquadron, Collection<Integer> fighterIds)
      Sends an "add squadron" packet
    • sendDeployMinefields

      public void sendDeployMinefields(Vector<Minefield> minefields)
      Sends an "deploy minefields" packet
    • sendDeployFortifications

      public void sendDeployFortifications(Vector<BoardLocation> fortifiedHexes)
      Sends a "deploy fortifications" packet carrying the hex locations the player is fortifying.
    • sendDeployGroundObjects

      public void sendDeployGroundObjects(Map<Coords,List<ICarryable>> groundObjects)
      Sends an updated state of ground objects (i.e. cargo etc.)
    • sendArtyAutoHitHexes

      public void sendArtyAutoHitHexes(List<BoardLocation> hexes)
      Sends a "set Artillery AutoHit Hexes" packet
    • sendUpdateEntity

      public void sendUpdateEntity(Entity entity)
      Sends an "update entity" packet
    • sendUpdateEntity

      public void sendUpdateEntity(Collection<Entity> entities)
      Sends a packet containing multiple entity updates. Should only be used in the lobby phase.
    • sendDamageEdit

      public void sendDamageEdit(DamageEditSpec spec)
      Sends a gamemaster's damage editor edits for the server to apply to its own copy of the unit. Unlike sendUpdateEntity(Entity) this carries only the edited values, so the server's unit keeps every piece of state the editor does not touch.
    • sendChangeOwner

      public void sendChangeOwner(Collection<Entity> entities, int newOwnerId)
      Sends a packet containing multiple entity updates. Should only be used in the lobby phase.
    • sendDeploymentUnload

      public void sendDeploymentUnload(Entity loader, Entity loaded)
      Sends an "update entity" packet
    • sendDeleteEntity

      public void sendDeleteEntity(int id)
      Sends a "delete entity" packet
    • sendDeleteEntities

      public void sendDeleteEntities(List<Integer> ids)
      Sends an update to the server to delete the entities of the given ids.
    • sendLoadEntity

      public void sendLoadEntity(int id, int loaderId, int bayNumber)
      Sends a "load entity" packet
    • sendTowEntity

      public void sendTowEntity(int id, int tractorId)
      Sends a "tow entity" packet
    • sendBuildTrain

      public void sendBuildTrain(int tractorId, List<Integer> trailerIds)
      Sends a "build train" packet, connecting a tractor and several trailers in one operation. The server validates the whole chain and applies it in full or not at all, so a rejected request leaves every unit unattached.
      Parameters:
      tractorId - the powered tractor that will head the train
      trailerIds - the trailers to hitch behind it, ordered front to back
    • sendExplodeBuilding

      public void sendExplodeBuilding(DemolitionCharge charge)
    • receiveEntities

      protected void receiveEntities(Packet packet) throws InvalidPacketDataException
      Loads the entities from the data in the net command.
      Throws:
      InvalidPacketDataException
    • receiveForceUpdate

      protected void receiveForceUpdate(Packet packet) throws InvalidPacketDataException
      Receives a force-related update containing affected forces and affected entities
      Throws:
      InvalidPacketDataException
    • receiveForcesDelete

      protected void receiveForcesDelete(Packet packet) throws InvalidPacketDataException
      Receives a server packet commanding deletion of forces. Only valid in the lobby phase.
      Throws:
      InvalidPacketDataException
    • receiveEntityUpdate

      protected void receiveEntityUpdate(Packet packet) throws InvalidPacketDataException
      Loads entity update data from the data in the net command.
      Throws:
      InvalidPacketDataException
    • receiveEntitiesUpdate

      protected void receiveEntitiesUpdate(Packet packet) throws InvalidPacketDataException
      Update multiple entities from the server. Used only in the lobby phase.
      Throws:
      InvalidPacketDataException
    • receiveEntityRemove

      protected void receiveEntityRemove(Packet packet) throws InvalidPacketDataException
      Throws:
      InvalidPacketDataException
    • receiveEntityVisibilityIndicator

      protected void receiveEntityVisibilityIndicator(Packet packet) throws InvalidPacketDataException
      Throws:
      InvalidPacketDataException
    • receiveUpdateGroundObjects

      protected void receiveUpdateGroundObjects(Packet packet) throws InvalidPacketDataException
      Throws:
      InvalidPacketDataException
    • receiveUpdateIndustrialElevators

      protected void receiveUpdateIndustrialElevators(Packet packet)
    • receiveDeployMinefields

      protected void receiveDeployMinefields(Packet packet) throws InvalidPacketDataException
      Throws:
      InvalidPacketDataException
    • receiveSendingMinefields

      protected void receiveSendingMinefields(Packet packet) throws InvalidPacketDataException
      Throws:
      InvalidPacketDataException
    • receiveIlluminatedHexes

      protected void receiveIlluminatedHexes(Packet packet) throws InvalidPacketDataException
      Throws:
      InvalidPacketDataException
    • receiveUpdateCutHexes

      protected void receiveUpdateCutHexes(Packet packet) throws InvalidPacketDataException
      Throws:
      InvalidPacketDataException
    • receiveRevealMinefield

      protected void receiveRevealMinefield(Packet packet) throws InvalidPacketDataException
      Throws:
      InvalidPacketDataException
    • receiveRemoveMinefield

      protected void receiveRemoveMinefield(Packet packet) throws InvalidPacketDataException
      Throws:
      InvalidPacketDataException
    • receiveUpdateMinefields

      protected void receiveUpdateMinefields(Packet packet) throws InvalidPacketDataException
      Throws:
      InvalidPacketDataException
    • receiveBuildingAdd

      protected void receiveBuildingAdd(Packet packet) throws InvalidPacketDataException
      Throws:
      InvalidPacketDataException
    • receiveBuildingUpdate

      protected void receiveBuildingUpdate(Packet packet) throws InvalidPacketDataException
      Throws:
      InvalidPacketDataException
    • receiveBuildingRemove

      protected void receiveBuildingRemove(Packet packet) throws InvalidPacketDataException
      Throws:
      InvalidPacketDataException
    • receiveBuildingCollapse

      protected void receiveBuildingCollapse(Packet packet) throws InvalidPacketDataException
      Throws:
      InvalidPacketDataException
    • receiveAttack

      protected void receiveAttack(Packet packet) throws InvalidPacketDataException
      Loads entity firing data from the data in the net command
      Throws:
      InvalidPacketDataException
    • receiveReport

      public String receiveReport(List<Report> reports)
    • cacheImgTag

      protected void cacheImgTag(Entity entity)
      Hashtable for storing img tags containing base64Text src.
    • sendNovaChange

      public void sendNovaChange(int id, String net)
      Send a Nova CEWS update packet
    • sendVariableRangeTargetingModeChange

      public void sendVariableRangeTargetingModeChange(int entityId, VariableRangeTargetingMode mode)
      Send a Variable Range Targeting mode change packet (BMM pg. 86). Mode changes are applied at the start of the next round.
      Parameters:
      entityId - the ID of the entity changing modes
      mode - the new VariableRangeTargetingMode to apply next round
    • sendUnitAbandonmentAnnouncement

      public void sendUnitAbandonmentAnnouncement(int entityId)
      Sends a unit abandonment announcement to the server. For Meks (TacOps:AR p.165): Must be prone and shutdown. For Vehicles (TacOps): Can be abandoned anytime. The abandonment will execute during the End Phase of the following turn.
      Parameters:
      entityId - the ID of the unit announcing abandonment
    • sendSpecialHexDisplayAppend

      public void sendSpecialHexDisplayAppend(Coords c, int boardId, SpecialHexDisplay shd)
    • sendSpecialHexDisplayDelete

      public void sendSpecialHexDisplayDelete(Coords c, int boardId, SpecialHexDisplay shd)
    • sendBotSettingsToServer

      protected void sendBotSettingsToServer()
      Hook invoked when the server greets this client, allowing a bot client to push its behavior settings to the server. Non-bot clients have no settings to send, so this default implementation does nothing; bot clients override it.
    • handleGameSpecificPacket

      protected boolean handleGameSpecificPacket(Packet packet)
      Description copied from class: AbstractClient
      Handles any Packets that are specific to the game type (TW, AS...). When implementing this, make sure that this doesn't do duplicate actions with AbstractClient.handleGameIndependentPacket(Packet) - but packets may be handled in both methods (all packets traverse both methods).

      When making changes, do not forget to update Precognition which is a Client clone but unfortunately not a subclass.

      Specified by:
      handleGameSpecificPacket in class AbstractClient
      Parameters:
      packet - The packet to handle
      Returns:
      True when the packet has been handled
    • sendDominoCFRResponse

      public void sendDominoCFRResponse(MovePath mp)
    • sendAMSAssignCFRResponse

      public void sendAMSAssignCFRResponse(int[] waaIndex)
    • sendAPDSAssignCFRResponse

      public void sendAPDSAssignCFRResponse(Integer waaIndex)
    • sendHiddenPBSCFRResponse

      public void sendHiddenPBSCFRResponse(Vector<EntityAction> attacks)
    • sendTelemissileTargetCFRResponse

      public void sendTelemissileTargetCFRResponse(int index)
    • sendTAGTargetCFRResponse

      public void sendTAGTargetCFRResponse(int index)
    • getAvailableMapSizes

      public Set<BoardDimensions> getAvailableMapSizes()
    • sendForceParent

      public void sendForceParent(Collection<Force> forceList, int newParentId)
      Sends the given forces to the server to be made top-level forces.
    • sendChangeTeam

      public void sendChangeTeam(Vector<Player> players, int newTeamId)
      Sends a packet containing multiple entity updates. Should only be used in the lobby phase.
    • sendUpdateForce

      public void sendUpdateForce(Collection<Force> changedForces, Collection<Entity> changedEntities)
      Sends an "Update force" packet
    • sendUpdateForce

      public void sendUpdateForce(Collection<Force> changedForces)
      Sends an "Update force" packet
    • sendAddEntitiesToForce

      public void sendAddEntitiesToForce(Collection<Entity> entities, int forceId)
      Sends a packet instructing the server to add the given entities to the given force. The server will handle this; the client does not have to implement the change.
    • sendAssignForceFull

      public void sendAssignForceFull(Collection<Force> forceList, int newOwnerId)
      Sends a packet instructing the server to add the given entities to the given force. The server will handle this; the client does not have to implement the change.
    • sendDeleteForces

      public void sendDeleteForces(List<Force> toDelete)
      Sends a packet to the Server requesting to delete the given forces.
    • sendAddForce

      public void sendAddForce(Force force, Collection<Entity> entities)
      Sends an "Add force" packet
    • sendCustomInit

      @Deprecated(since="0.51.0", forRemoval=true) public void sendCustomInit(Player player)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Sends an "update custom initiative" packet
    • getSkillGenerator

      public AbstractSkillGenerator getSkillGenerator()
    • setSkillGenerator

      public void setSkillGenerator(AbstractSkillGenerator skillGenerator)
    • sendUnloadStranded

      public void sendUnloadStranded(int... entityIds)
      Send command to unload stranded entities to the server
    • changeTurnIndex

      protected void changeTurnIndex(int index, int prevPlayerId)
      Change whose turn it is.
    • sendModeChange

      public void sendModeChange(int nEntity, int nEquip, int nMode)
      Send mode-change data to the server
    • sendChargeLevelChange

      public void sendChargeLevelChange(int nEntity, int nEquip, int nChargeLevel)
      Send charge-change data to the server
    • sendDeployBridge

      public void sendDeployBridge(int entityId, int equipNum)
      Declares that the given unit is deploying one of its Bridge-Layer (AVLB) bridges (TM p.242 / TW). The server validates eligibility and computes the target hex (directly in front, along the unit's facing); the bridge is placed at the end of the following turn if the unit stays stationary.
      Parameters:
      entityId - the unit declaring the deployment
      equipNum - the equipment index of the specific bridgelayer to deploy (a unit may carry more than one)
    • sendMountFacingChange

      public void sendMountFacingChange(int nEntity, int nEquip, int nFacing)
      Send mount-facing-change data to the server
    • sendCalledShotChange

      public void sendCalledShotChange(int entityId, int equipmentNum, int calledShot)
      Send called shot change data to the server.
      Parameters:
      entityId - the id of the entity whose weapon is changing
      equipmentNum - the equipment number of the weapon
      calledShot - the new called shot, one of the CalledShot CALLED_ constants
    • sendSystemModeChange

      @Deprecated(since="0.51.0", forRemoval=true) public void sendSystemModeChange(int nEntity, int nSystem, int nMode)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Send system mode-change data to the server
    • sendAmmoChange

      public void sendAmmoChange(int entityId, int weaponId, int ammoId, int ammoCarrierId, int reason)
      Send ammo-change data to the server.
      Parameters:
      entityId - the unit that owns the weapon being reloaded
      weaponId - the equipment number of the weapon on that unit
      ammoId - the equipment number of the ammo bin on the carrying unit
      ammoCarrierId - the unit that owns the ammo bin. This is the same as entityId unless the bin belongs to a directly connected trailer sharing ammo with this unit.
      reason - the report message id explaining the change, or 0 for no report
    • sendSensorChange

      public void sendSensorChange(int nEntity, int nSensor)
      Send sensor-change data to the server
    • sendSinksChange

      public void sendSinksChange(int nEntity, int activeSinks)
      Send sinks-change data to the server
    • sendActivateHidden

      public void sendActivateHidden(int nEntity, GamePhase phase)
      Send activate hidden data to the server
    • moveEntity

      public void moveEntity(int id, MovePath md)
      Send movement data for the given entity to the server.
    • sendLoadGame

      public void sendLoadGame(File f)
      sends a load game file to the server