Combat.getAttackers() returns a list - code became less complicated

This commit is contained in:
Maxmtg
2012-02-29 05:48:29 +00:00
parent 7f2e5c74b6
commit 055c6b5d2c
12 changed files with 20 additions and 54 deletions

View File

@@ -26,7 +26,6 @@ import java.util.List;
import com.google.code.jyield.Generator;
import com.google.code.jyield.Yieldable;
import forge.card.EditionInfo;
import forge.card.spellability.SpellAbility;
import forge.util.MyRandom;
@@ -134,29 +133,6 @@ public class CardList implements Iterable<Card> {
this.list = new ArrayList<Card>(size);
}
/**
* <p>
* Get any cards that exist in the passed in sets list.
* </p>
*
* @param sets
* a {@link java.util.ArrayList} object.
* @return a {@link forge.CardList} object.
*/
public final CardList getSets(final ArrayList<String> sets) {
final CardList list = new CardList();
for (final Card c : this) {
for (final EditionInfo set : c.getSets()) {
if (sets.contains(set.toString())) {
list.add(c);
break;
}
}
}
return list;
} // getSets()
/**
* <p>
* getColor.

View File

@@ -22,6 +22,7 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
@@ -479,15 +480,8 @@ public class Combat {
*
* @return an array of {@link forge.Card} objects.
*/
public final Card[] getAttackers() {
final CardList out = new CardList();
final Iterator<Card> it = this.map.keySet().iterator();
while (it.hasNext()) {
out.add(it.next());
}
return out.toArray();
public final List<Card> getAttackers() {
return new ArrayList<Card>(this.map.keySet());
} // getAttackers()
/**

View File

@@ -710,18 +710,16 @@ public class CombatUtil {
*/
public static boolean canAttack(final Card c, final Combat combat) {
int cntAttackers = combat.getAttackers().size();
for (final Card card : AllZoneUtil.getCardsIn(Constant.Zone.Battlefield)) {
for (final String keyword : card.getKeyword()) {
if (keyword.equals("No more than one creature can attack each combat.")
&& (combat.getAttackers().length > 0)) {
if (keyword.equals("No more than one creature can attack each combat.") && cntAttackers > 0 ) {
return false;
}
if (keyword.equals("No more than two creatures can attack each combat.")
&& (combat.getAttackers().length > 1)) {
if (keyword.equals("No more than two creatures can attack each combat.") && cntAttackers > 1) {
return false;
}
if (keyword.equals("No more than two creatures can attack you each combat.")
&& (combat.getAttackers().length > 1)
if (keyword.equals("No more than two creatures can attack you each combat.") && cntAttackers > 1
&& card.getController().getOpponent().isPlayer(c.getController())) {
return false;
}
@@ -731,11 +729,11 @@ public class CombatUtil {
}
}
if ((combat.getAttackers().length > 0) && c.hasKeyword("CARDNAME can only attack alone.")) {
if (cntAttackers > 0 && c.hasKeyword("CARDNAME can only attack alone.")) {
return false;
}
if ((combat.getAttackers().length > 0) && AllZoneUtil.isCardInPlay("Dueling Grounds")) {
if (cntAttackers > 0 && AllZoneUtil.isCardInPlay("Dueling Grounds")) {
return false;
}

View File

@@ -19,6 +19,7 @@ package forge;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import com.esotericsoftware.minlog.Log;
@@ -286,8 +287,8 @@ public class ComputerAIGeneral implements Computer {
AllZone.setCombat(ComputerUtil.getAttackers());
final Card[] att = AllZone.getCombat().getAttackers();
if (att.length > 0) {
final List<Card> att = AllZone.getCombat().getAttackers();
if (!att.isEmpty()) {
AllZone.getPhaseHandler().setCombat(true);
}

View File

@@ -649,7 +649,7 @@ public class ComputerUtilAttack {
// ****************
// Exalted
if ((combat.getAttackers().length == 0)
if ((combat.getAttackers().isEmpty())
&& ((this.countExaltedBonus(AllZone.getComputerPlayer()) >= 3)
|| AllZoneUtil.isCardInPlay("Rafiq of the Many", AllZone.getComputerPlayer())
|| (AllZone.getComputerPlayer().getCardsIn(Zone.Battlefield, "Battlegrace Angel").size() >= 2) || ((AllZone

View File

@@ -330,7 +330,7 @@ public final class AbilityFactoryAnimate {
// don't use instant speed animate abilities outside humans
// Combat_Declare_Attackers_InstantAbility step
if ((!AllZone.getPhaseHandler().is(Constant.Phase.COMBAT_DECLARE_ATTACKERS_INSTANT_ABILITY) || (AllZone.getCombat()
.getAttackers().length == 0)) && AllZone.getPhaseHandler().isPlayerTurn(AllZone.getHumanPlayer())) {
.getAttackers().isEmpty())) && AllZone.getPhaseHandler().isPlayerTurn(AllZone.getHumanPlayer())) {
return false;
}

View File

@@ -398,7 +398,7 @@ public class AbilityFactoryPump {
if (phase.isAfter(Constant.Phase.COMBAT_DECLARE_ATTACKERS)
&& phase.isBefore(Constant.Phase.MAIN2)
&& phase.isPlayerTurn(AllZone.getHumanPlayer())
&& AllZone.getCombat().getAttackers().length > 0
&& !AllZone.getCombat().getAttackers().isEmpty()
&& CombatUtil.canBlock(c, AllZone.getCombat())
&& CombatUtil.lifeInDanger(AllZone.getCombat())) {
return true;

View File

@@ -35,7 +35,6 @@ import forge.Card;
import forge.CardList;
import forge.CardListFilter;
import forge.CardUtil;
import forge.Combat;
import forge.CombatUtil;
import forge.Command;
import forge.CommandArgs;
@@ -360,8 +359,7 @@ public class CardFactoryUtil {
* @return a boolean.
*/
public static boolean doesCreatureAttackAI(final Card card) {
final Combat combat = ComputerUtil.getAttackers();
final Card[] att = combat.getAttackers();
final List<Card> att = ComputerUtil.getAttackers().getAttackers();
for (final Card element : att) {
if (element.equals(card)) {
return true;

View File

@@ -76,7 +76,7 @@ public class InputAttack extends Input {
/** {@inheritDoc} */
@Override
public final void selectButtonOK() {
if (AllZone.getCombat().getAttackers().length > 0) {
if (!AllZone.getCombat().getAttackers().isEmpty()) {
AllZone.getPhaseHandler().setCombat(true);
}

View File

@@ -22,7 +22,6 @@ import java.util.ArrayList;
import forge.AllZone;
import forge.ButtonUtil;
import forge.Card;
import forge.CardUtil;
import forge.CombatUtil;
import forge.Command;
import forge.Constant;
@@ -102,7 +101,7 @@ public class InputBlock extends Input {
@Override
public final void selectCard(final Card card, final PlayerZone zone) {
// is attacking?
if (CardUtil.toList(AllZone.getCombat().getAttackers()).contains(card)) {
if (AllZone.getCombat().getAttackers().contains(card)) {
this.currentAttacker = card;
} else if (zone.is(Constant.Zone.Battlefield, AllZone.getHumanPlayer()) && card.isCreature()
&& CombatUtil.canBlock(this.currentAttacker, card, AllZone.getCombat())

View File

@@ -221,7 +221,7 @@ public class InputControl extends MyObservable implements java.io.Serializable {
this.aiInput.getComputer().declareBlockers();
return null;
} else {
if (this.model.getGameState().getCombat().getAttackers().length == 0) {
if (this.model.getGameState().getCombat().getAttackers().isEmpty()) {
// no active attackers, skip the Blocking phase
this.model.getGameState().getPhaseHandler().setNeedToNextPhase(true);
return null;

View File

@@ -355,7 +355,7 @@ public class ViewTabber extends JPanel {
final Border border = new MatteBorder(0, 0, 0, 0, FSkin.getColor(FSkin.Colors.CLR_BORDERS));
this.vtpTabber.getAllVTabs().get(ControlTabber.COMBAT_PANEL)
.setText("Combat : " + AllZone.getCombat().getAttackers().length);
.setText("Combat : " + AllZone.getCombat().getAttackers().size());
final JTextArea tar = new JTextArea(s);
tar.setOpaque(false);