📄 targetingphasedisplay.java
字号:
butDone.setEnabled(false); setFlipArmsEnabled(false); setFireModeEnabled(false); setNextTargetEnabled(false); } /** * Fire Mode - Adds a Fire Mode Change to the current Attack Action */ private void changeMode() { int wn = clientgui.mechD.wPan.getSelectedWeaponNum(); // Do nothing we have no unit selected. if (null == ce()) { return; } // If the weapon does not have modes, just exit. Mounted m = ce().getEquipment(wn); if (m == null || !m.getType().hasModes()) { return; } // send change to the server int nMode = m.switchMode(); client.sendModeChange(cen, wn, nMode); // notify the player if (m.getType().hasInstantModeSwitch()) { clientgui.systemMessage(Messages.getString("FiringDisplay.switched", new Object[]{m.getName(), m.curMode().getDisplayableName()})); //$NON-NLS-1$ } else { clientgui.systemMessage(Messages.getString("FiringDisplay.willSwitch", new Object[]{m.getName(), m.pendingMode().getDisplayableName()})); //$NON-NLS-1$ } updateTarget(); clientgui.mechD.wPan.displayMech(ce()); clientgui.mechD.wPan.selectWeapon(wn); } /** * Called when the current entity is done firing. Send out our attack * queue to the server. */ private void ready() { if (attacks.isEmpty() && GUIPreferences.getInstance().getNagForNoAction()) { // comfirm this action String title = Messages.getString("TargetingPhaseDisplay.DontFireDialog.title"); //$NON-NLS-1$ String body = Messages.getString("TargetingPhaseDisplay.DontFireDialog.message"); //$NON-NLS-1$ ConfirmDialog response = clientgui.doYesNoBotherDialog(title, body); if (!response.getShowAgain()) { GUIPreferences.getInstance().setNagForNoAction(false); } if (!response.getAnswer()) { return; } } // stop further input (hopefully) disableButtons(); // remove temporary attacks from game & board removeTempAttacks(); // send out attacks client.sendAttackData(cen, attacks); // clear queue attacks.removeAllElements(); // Clear the menu bar. clientgui.getMenuBar().setEntity(null); // close aimed shot display, if any } private void doSearchlight() { // validate if (ce() == null || target == null) { throw new IllegalArgumentException("current searchlight parameters are invalid"); //$NON-NLS-1$ } if (!SearchlightAttackAction.isPossible(client.game, cen, target, null)) return; //create and queue a searchlight action SearchlightAttackAction saa = new SearchlightAttackAction(cen, target.getTargetType(), target.getTargetId()); attacks.addElement(saa); // and add it into the game, temporarily client.game.addAction(saa); clientgui.bv.addAttack(saa); clientgui.bv.repaint(100L); clientgui.minimap.drawMap(); //refresh weapon panel, as bth will have changed updateTarget(); } /** * Adds a weapon attack with the currently selected weapon to the attack * queue. */ private void fire() { // get the selected weaponnum int weaponNum = clientgui.mechD.wPan.getSelectedWeaponNum(); Mounted mounted = ce().getEquipment(weaponNum); // validate if (ce() == null || target == null || mounted == null || !(mounted.getType() instanceof WeaponType)) { throw new IllegalArgumentException("current fire parameters are invalid"); //$NON-NLS-1$ } // declare searchlight, if possible if (GUIPreferences.getInstance().getAutoDeclareSearchlight()) { doSearchlight(); } WeaponAttackAction waa = new WeaponAttackAction(cen, target.getTargetType(), target.getTargetId(), weaponNum); if (null != mounted.getLinked() && ((WeaponType) mounted.getType()).getAmmoType() != AmmoType.T_NA) { Mounted ammoMount = mounted.getLinked(); waa.setAmmoId(ce().getEquipmentNum(ammoMount)); if (((AmmoType) ammoMount.getType()).getMunitionType() == AmmoType.M_VIBRABOMB_IV) { VibrabombSettingDialog vsd = new VibrabombSettingDialog(clientgui.frame); vsd.setVisible(true); waa.setOtherAttackInfo(vsd.getSetting()); } } // add the attack to our temporary queue attacks.addElement(waa); // and add it into the game, temporarily client.game.addAction(waa); clientgui.bv.addAttack(waa); clientgui.bv.repaint(100L); clientgui.minimap.drawMap(); // set the weapon as used mounted.setUsedThisRound(true); // find the next available weapon int nextWeapon = ce().getNextWeapon(weaponNum); // check; if there are no ready weapons, you're done. if (nextWeapon == -1 && GUIPreferences.getInstance().getAutoEndFiring()) { ready(); return; } // otherwise, display firing info for the next weapon clientgui.mechD.wPan.displayMech(ce()); clientgui.mechD.wPan.selectWeapon(nextWeapon); updateTarget(); } /** * Skips to the next weapon */ private void nextWeapon() { int nextWeapon = ce().getNextWeapon(clientgui.mechD.wPan.getSelectedWeaponNum()); // if there's no next weapon, forget about it if (nextWeapon == -1) { return; } clientgui.mechD.wPan.displayMech(ce()); clientgui.mechD.wPan.selectWeapon(nextWeapon); updateTarget(); } /** * Removes all current fire */ private void clearAttacks() { // We may not have an entity selected yet (race condition). if (ce() == null) { return; } // remove attacks, set weapons available again Enumeration i = attacks.elements(); while (i.hasMoreElements()) { Object o = i.nextElement(); if (o instanceof WeaponAttackAction) { WeaponAttackAction waa = (WeaponAttackAction) o; ce().getEquipment(waa.getWeaponId()).setUsedThisRound(false); } } attacks.removeAllElements(); // remove temporary attacks from game & board removeTempAttacks(); // restore any other movement to default ce().setSecondaryFacing(ce().getFacing()); ce().setArmsFlipped(false); } /** * Removes temp attacks from the game and board */ private void removeTempAttacks() { // remove temporary attacks from game & board client.game.removeActionsFor(cen); clientgui.bv.removeAttacksFor(cen); clientgui.bv.repaint(100L); } /** * Refeshes all displays. */ private void refreshAll() { if (ce() == null) { return; } clientgui.bv.redrawEntity(ce()); clientgui.mechD.displayEntity(ce()); clientgui.mechD.showPanel("weapons"); //$NON-NLS-1$ clientgui.mechD.wPan.selectWeapon(ce().getFirstWeapon()); updateTarget(); } /** * Targets something */ void target(Targetable t) { target = t; updateTarget(); } /** * Targets something */ protected void updateTarget() { setFireEnabled(false); // make sure we're showing the current entity in the mech display if (ce() != null && !ce().equals(clientgui.mechD.getCurrentEntity())) { clientgui.mechD.displayEntity(ce()); } // update target panel final int weaponId = clientgui.mechD.wPan.getSelectedWeaponNum(); if (target != null && weaponId != -1) { ToHitData toHit; toHit = WeaponAttackAction.toHit(client.game, cen, target, weaponId, Mech.LOC_NONE, 0); clientgui.mechD.wPan.wTargetR.setText(target.getDisplayName()); clientgui.mechD.wPan.wRangeR.setText("" + ce().getPosition().distance(target.getPosition())); //$NON-NLS-1$ Mounted m = ce().getEquipment(weaponId); if (m.isUsedThisRound()) { clientgui.mechD.wPan.wToHitR.setText(Messages.getString("TargetingPhaseDisplay.alreadyFired")); //$NON-NLS-1$ setFireEnabled(false); } else if (m.getType().hasFlag(WeaponType.F_AUTO_TARGET)) { clientgui.mechD.wPan.wToHitR.setText(Messages.getString("TargetingPhaseDisplay.autoFiringWeapon")); //$NON-NLS-1$ setFireEnabled(false); } else if (toHit.getValue() == ToHitData.IMPOSSIBLE) { clientgui.mechD.wPan.wToHitR.setText(toHit.getValueAsString()); setFireEnabled(false); } else if (toHit.getValue() == ToHitData.AUTOMATIC_FAIL) { clientgui.mechD.wPan.wToHitR.setText(toHit.getValueAsString()); setFireEnabled(true); } else { clientgui.mechD.wPan.wToHitR.setText(toHit.getValueAsString() + " (" + Compute.oddsAbove(toHit.getValue()) + "%)"); //$NON-NLS-1$ //$NON-NLS-2$ setFireEnabled(true); } clientgui.mechD.wPan.toHitText.setText(toHit.getDesc()); setSkipEnabled(true); } else { clientgui.mechD.wPan.wTargetR.setText("---"); //$NON-NLS-1$ clientgui.mechD.wPan.wRangeR.setText("---"); //$NON-NLS-1$ clientgui.mechD.wPan.wToHitR.setText("---"); //$NON-NLS-1$ clientgui.mechD.wPan.toHitText.setText(""); //$NON-NLS-1$ } updateSearchlight(); } /** * Torso twist in the proper direction. */ private void torsoTwist(Coords target) { int direction = ce().getFacing(); if (null != target) direction = ce().clipSecondaryFacing(ce().getPosition().direction(target)); if (direction != ce().getSecondaryFacing()) { clearAttacks(); attacks.addElement(new TorsoTwistAction(cen, direction)); ce().setSecondaryFacing(direction); refreshAll(); } } /** * Torso twist to the left or right * * @param target An <code>int</code> specifying wether we're twisting left or right, * 0 if we're twisting to the left, 1 if to the right. */ private void torsoTwist(int target) { int direction = ce().getSecondaryFacing(); if (target == 0) { clearAttacks(); direction = ce().clipSecondaryFacing((direction + 5) % 6); attacks.addElement(new TorsoTwistAction(cen, direction)); ce().setSecondaryFacing(direction); refreshAll(); } else if (target == 1) { clearAttacks(); direction = ce().clipSecondaryFacing((direction + 7) % 6); attacks.addElement(new TorsoTwistAction(cen, direction)); ce().setSecondaryFacing(direction); refreshAll(); } } /** * Cache the list of visible targets. This is used for the 'next target' button. * <p/> * We'll sort it by range to us. */ private void cacheVisibleTargets() { clearVisibleTargets(); Vector vec = client.game.getValidTargets(ce()); Comparator sortComp = new Comparator() { public int compare(Object x, Object y) { Entity entX = (Entity) x; Entity entY = (Entity) y; int rangeToX = ce().getPosition().distance(entX.getPosition()); int rangeToY = ce().getPosition().distance(entY.getPosition()); if (rangeToX == rangeToY) return entX.getId() < entY.getId() ? -1 : 1; return rangeToX < rangeToY ? -1 : 1; } }; TreeSet tree = new TreeSet(sortComp); visibleTargets = new Entity[vec.size()]; for (int i = 0; i < vec.size(); i++) { tree.add(vec.elementAt(i)); } Iterator it = tree.iterator(); int count = 0; while (it.hasNext()) { visibleTargets[count++] = (Entity) it.next(); } setNextTargetEnabled(visibleTargets.length > 0); } private void clearVisibleTargets() { visibleTargets = null; lastTargetID = -1; setNextTargetEnabled(false); } /** * Get the next target. Return null if we don't have any targets. */ private Entity getNextTarget() { if (null == visibleTargets) return null; lastTargetID++; if (lastTargetID >= visibleTargets.length) lastTargetID = 0; return visibleTargets[lastTargetID]; } /**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -