📄 client.java
字号:
} /** * Change whose turn it is. */ protected void changeTurnIndex(int index) { game.setTurnIndex(index); } /** * Send mode-change data to the server */ public void sendModeChange(int nEntity, int nEquip, int nMode) { Object[] data = { new Integer(nEntity), new Integer(nEquip), new Integer(nMode)}; send(new Packet(Packet.COMMAND_ENTITY_MODECHANGE, data)); } /** * Send system mode-change data to the server */ public void sendSystemModeChange(int nEntity, int nSystem, int nMode) { Object[] data = { new Integer(nEntity), new Integer(nSystem), new Integer(nMode)}; send(new Packet(Packet.COMMAND_ENTITY_SYSTEMMODECHANGE, data)); } /** * Send mode-change data to the server */ public void sendAmmoChange(int nEntity, int nWeapon, int nAmmo) { Object[] data = { new Integer(nEntity), new Integer(nWeapon), new Integer(nAmmo)}; send(new Packet(Packet.COMMAND_ENTITY_AMMOCHANGE, data)); } /** * Send movement data for the given entity to the server. */ public void moveEntity(int id, MovePath md) { Object[] data = new Object[2]; data[0] = new Integer(id); data[1] = md; send(new Packet(Packet.COMMAND_ENTITY_MOVE, data)); } /** * Maintain backwards compatability. * * @param id - the <code>int</code> ID of the deployed entity * @param c - the <code>Coords</code> where the entity should be deployed * @param nFacing - the <code>int</code> direction the entity should face */ public void deploy(int id, Coords c, int nFacing) { this.deploy(id, c, nFacing, new Vector(),false); } /** * BC with old version * * @param id - the <code>int</code> ID of the deployed entity * @param c - the <code>Coords</code> where the entity should be deployed * @param nFacing - the <code>int</code> direction the entity should face * @param loadedUnits - a <code>List</code> of units that start the game * being transported byt the deployed entity. */ public void deploy(int id, Coords c, int nFacing, Vector loadedUnits) { deploy(id,c,nFacing,loadedUnits,false); } /** * Deploy an entity at the given coordinates, with the given facing, * and starting with the given units already loaded. * * @param id - the <code>int</code> ID of the deployed entity * @param c - the <code>Coords</code> where the entity should be deployed * @param nFacing - the <code>int</code> direction the entity should face * @param loadedUnits - a <code>List</code> of units that start the game * being transported byt the deployed entity. * @param assaultDrop - true if deployment is an assault drop */ public void deploy(int id, Coords c, int nFacing, Vector loadedUnits, boolean assaultDrop) { int packetCount = 5 + loadedUnits.size(); int index = 0; Object[] data = new Object[packetCount]; data[index++] = new Integer(id); data[index++] = c; data[index++] = new Integer(nFacing); data[index++] = new Integer(loadedUnits.size()); data[index++] = new Boolean(assaultDrop); Enumeration iter = loadedUnits.elements(); while (iter.hasMoreElements()) { data[index++] = new Integer(((Entity) iter.nextElement()).getId()); } send(new Packet(Packet.COMMAND_ENTITY_DEPLOY, data)); } /** * Send a weapon fire command to the server. */ public void sendAttackData(int aen, Vector attacks) { Object[] data = new Object[2]; data[0] = new Integer(aen); data[1] = attacks; send(new Packet(Packet.COMMAND_ENTITY_ATTACK, data)); } /** * Send the game options to the server */ public void sendGameOptions(String password, Vector options) { final Object[] data = new Object[2]; data[0] = password; data[1] = options; send(new Packet(Packet.COMMAND_SENDING_GAME_SETTINGS, data)); } /** * Send the game settings to the server */ public void sendMapSettings(MapSettings settings) { send(new Packet(Packet.COMMAND_SENDING_MAP_SETTINGS, settings)); } /** * Send the game settings to the server */ public void sendMapQuery(MapSettings query) { send(new Packet(Packet.COMMAND_QUERY_MAP_SETTINGS, query)); } /** * Broadcast a general chat message from the local player */ public void sendChat(String message) { send(new Packet(Packet.COMMAND_CHAT, message)); } /** * Sends a "player done" message to the server. */ public synchronized void sendDone(boolean done) { send(new Packet(Packet.COMMAND_PLAYER_READY, new Boolean(done))); } /** * Sends a "reroll initiative" message to the server. */ public void sendRerollInitiativeRequest() { send(new Packet(Packet.COMMAND_REROLL_INITIATIVE)); } /** * Sends the info associated with the local player. */ public void sendPlayerInfo() { Player player = game.getPlayer(local_pn); PreferenceManager.getClientPreferences().setLastPlayerColor(player.getColorIndex()); PreferenceManager.getClientPreferences().setLastPlayerCategory(player.getCamoCategory()); PreferenceManager.getClientPreferences().setLastPlayerCamoName(player.getCamoFileName()); send(new Packet(Packet.COMMAND_PLAYER_UPDATE, player)); } /** * Sends an "add entity" packet */ public void sendAddEntity(Entity entity) { checkDuplicateNamesDuringAdd(entity); send(new Packet(Packet.COMMAND_ENTITY_ADD, entity)); } /** * Sends an "deploy minefields" packet */ public void sendDeployMinefields(Vector minefields) { send(new Packet(Packet.COMMAND_DEPLOY_MINEFIELDS, minefields)); } /** * Sends a "set Artillery Autohit Hexes" packet */ public void sendArtyAutoHitHexes(Vector hexes) { send(new Packet(Packet.COMMAND_SET_ARTYAUTOHITHEXES, hexes)); } /** * Sends an "update entity" packet */ public void sendUpdateEntity(Entity entity) { send(new Packet(Packet.COMMAND_ENTITY_UPDATE, entity)); } /** * Sends a "delete entity" packet */ public void sendDeleteEntity(int id) { checkDuplicateNamesDuringDelete(id); send(new Packet(Packet.COMMAND_ENTITY_REMOVE, new Integer(id))); } /** * Receives player information from the message packet. */ protected void receivePlayerInfo(Packet c) { int pindex = c.getIntValue(0); Player newPlayer = (Player) c.getObject(1); if (getPlayer(newPlayer.getId()) == null) { game.addPlayer(pindex, newPlayer); } else { game.setPlayer(pindex, newPlayer); } PreferenceManager.getClientPreferences().setLastPlayerColor(newPlayer.getColorIndex()); PreferenceManager.getClientPreferences().setLastPlayerCategory(newPlayer.getCamoCategory()); PreferenceManager.getClientPreferences().setLastPlayerCamoName(newPlayer.getCamoFileName()); } /** * Loads the turn list from the data in the packet */ protected void receiveTurns(Packet packet) { game.setTurnVector((Vector) packet.getObject(0)); } /** * Loads the board from the data in the net command. */ protected void receiveBoard(Packet c) { Board newBoard = (Board) c.getObject(0); game.setBoard(newBoard); } /** * Loads the entities from the data in the net command. */ protected void receiveEntities(Packet c) { Vector newEntities = (Vector) c.getObject(0); Vector newOutOfGame = (Vector) c.getObject(1); // Replace the entities in the game. game.setEntitiesVector(newEntities); if (newOutOfGame != null) { game.setOutOfGameEntitiesVector(newOutOfGame); } } /** * Loads entity update data from the data in the net command. */ protected void receiveEntityUpdate(Packet c) { int eindex = c.getIntValue(0); Entity entity = (Entity) c.getObject(1); Vector movePath = (Vector) c.getObject(2); // Replace this entity in the game. game.setEntity(eindex, entity, movePath); } protected void receiveEntityAdd(Packet packet) { int entityId = packet.getIntValue(0); Entity entity = (Entity) packet.getObject(1); // Add the entity to the game. game.addEntity(entityId, entity); } protected void receiveEntityRemove(Packet packet) { int entityId = packet.getIntValue(0); int condition = packet.getIntValue(1); // Move the unit to its final resting place. game.removeEntity(entityId, condition); } protected void receiveEntityVisibilityIndicator(Packet packet) { Entity e = game.getEntity(packet.getIntValue(0)); if (e != null) { // we may not have this entity due to double blind e.setSeenByEnemy(packet.getBooleanValue(1)); e.setVisibleToEnemy(packet.getBooleanValue(2)); //this next call is only needed sometimes, but we'll just // call it everytime game.processGameEvent(new GameEntityChangeEvent(this,e)); } } protected void receiveDeployMinefields(Packet packet) { game.addMinefields((Vector) packet.getObject(0)); } protected void receiveSendingMinefields(Packet packet) { game.setMinefields((Vector) packet.getObject(0)); } protected void receiveRevealMinefield(Packet packet) { game.addMinefield((Minefield) packet.getObject(0)); } protected void receiveRemoveMinefield(Packet packet) { game.removeMinefield((Minefield) packet.getObject(0)); } protected void receiveBuildingUpdateCF(Packet packet) { game.getBoard().updateBuildingCF((Vector) packet.getObject(0)); } protected void receiveBuildingCollapse(Packet packet) { game.getBoard().collapseBuilding((Vector) packet.getObject(0)); } /** * Loads entity firing data from the data in the net command */ protected void receiveAttack(Packet c) { Vector vector = (Vector) c.getObject(0); int charge = c.getIntValue(1); boolean addAction = true; for (Enumeration i = vector.elements(); i.hasMoreElements();) { EntityAction ea = (EntityAction) i.nextElement(); int entityId = ea.getEntityId(); if (ea instanceof TorsoTwistAction && game.hasEntity(entityId)) { TorsoTwistAction tta = (TorsoTwistAction) ea; Entity entity = game.getEntity(entityId); entity.setSecondaryFacing(tta.getFacing()); } else if (ea instanceof FlipArmsAction && game.hasEntity(entityId)) { FlipArmsAction faa = (FlipArmsAction) ea; Entity entity = game.getEntity(entityId); entity.setArmsFlipped(faa.getIsFlipped()); } else if (ea instanceof DodgeAction && game.hasEntity(entityId)) { Entity entity = game.getEntity(entityId); entity.dodging = true; addAction = false; } else if (ea instanceof AttackAction) { // The equipment type of a club needs to be restored. if (ea instanceof ClubAttackAction) { ClubAttackAction caa = (ClubAttackAction) ea; Mounted club = caa.getClub(); club.restore(); } } if (addAction) { // track in the appropriate list if (charge == 0) { game.addAction(ea); } else if (charge == 1) { game.addCharge((AttackAction) ea); } else { game.addLayMinefieldAction((LayMinefieldAction)ea); } } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -