mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 12:18:00 +00:00
Combat.getAttackers() returns a list - code became less complicated
This commit is contained in:
@@ -26,7 +26,6 @@ import java.util.List;
|
|||||||
import com.google.code.jyield.Generator;
|
import com.google.code.jyield.Generator;
|
||||||
import com.google.code.jyield.Yieldable;
|
import com.google.code.jyield.Yieldable;
|
||||||
|
|
||||||
import forge.card.EditionInfo;
|
|
||||||
import forge.card.spellability.SpellAbility;
|
import forge.card.spellability.SpellAbility;
|
||||||
import forge.util.MyRandom;
|
import forge.util.MyRandom;
|
||||||
|
|
||||||
@@ -134,29 +133,6 @@ public class CardList implements Iterable<Card> {
|
|||||||
this.list = new ArrayList<Card>(size);
|
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>
|
* <p>
|
||||||
* getColor.
|
* getColor.
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import java.util.Collection;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -479,15 +480,8 @@ public class Combat {
|
|||||||
*
|
*
|
||||||
* @return an array of {@link forge.Card} objects.
|
* @return an array of {@link forge.Card} objects.
|
||||||
*/
|
*/
|
||||||
public final Card[] getAttackers() {
|
public final List<Card> getAttackers() {
|
||||||
final CardList out = new CardList();
|
return new ArrayList<Card>(this.map.keySet());
|
||||||
final Iterator<Card> it = this.map.keySet().iterator();
|
|
||||||
|
|
||||||
while (it.hasNext()) {
|
|
||||||
out.add(it.next());
|
|
||||||
}
|
|
||||||
|
|
||||||
return out.toArray();
|
|
||||||
} // getAttackers()
|
} // getAttackers()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -710,18 +710,16 @@ public class CombatUtil {
|
|||||||
*/
|
*/
|
||||||
public static boolean canAttack(final Card c, final Combat combat) {
|
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 Card card : AllZoneUtil.getCardsIn(Constant.Zone.Battlefield)) {
|
||||||
for (final String keyword : card.getKeyword()) {
|
for (final String keyword : card.getKeyword()) {
|
||||||
if (keyword.equals("No more than one creature can attack each combat.")
|
if (keyword.equals("No more than one creature can attack each combat.") && cntAttackers > 0 ) {
|
||||||
&& (combat.getAttackers().length > 0)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (keyword.equals("No more than two creatures can attack each combat.")
|
if (keyword.equals("No more than two creatures can attack each combat.") && cntAttackers > 1) {
|
||||||
&& (combat.getAttackers().length > 1)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (keyword.equals("No more than two creatures can attack you each combat.")
|
if (keyword.equals("No more than two creatures can attack you each combat.") && cntAttackers > 1
|
||||||
&& (combat.getAttackers().length > 1)
|
|
||||||
&& card.getController().getOpponent().isPlayer(c.getController())) {
|
&& card.getController().getOpponent().isPlayer(c.getController())) {
|
||||||
return false;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((combat.getAttackers().length > 0) && AllZoneUtil.isCardInPlay("Dueling Grounds")) {
|
if (cntAttackers > 0 && AllZoneUtil.isCardInPlay("Dueling Grounds")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package forge;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import com.esotericsoftware.minlog.Log;
|
import com.esotericsoftware.minlog.Log;
|
||||||
|
|
||||||
@@ -286,8 +287,8 @@ public class ComputerAIGeneral implements Computer {
|
|||||||
|
|
||||||
AllZone.setCombat(ComputerUtil.getAttackers());
|
AllZone.setCombat(ComputerUtil.getAttackers());
|
||||||
|
|
||||||
final Card[] att = AllZone.getCombat().getAttackers();
|
final List<Card> att = AllZone.getCombat().getAttackers();
|
||||||
if (att.length > 0) {
|
if (!att.isEmpty()) {
|
||||||
AllZone.getPhaseHandler().setCombat(true);
|
AllZone.getPhaseHandler().setCombat(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -649,7 +649,7 @@ public class ComputerUtilAttack {
|
|||||||
// ****************
|
// ****************
|
||||||
|
|
||||||
// Exalted
|
// Exalted
|
||||||
if ((combat.getAttackers().length == 0)
|
if ((combat.getAttackers().isEmpty())
|
||||||
&& ((this.countExaltedBonus(AllZone.getComputerPlayer()) >= 3)
|
&& ((this.countExaltedBonus(AllZone.getComputerPlayer()) >= 3)
|
||||||
|| AllZoneUtil.isCardInPlay("Rafiq of the Many", AllZone.getComputerPlayer())
|
|| AllZoneUtil.isCardInPlay("Rafiq of the Many", AllZone.getComputerPlayer())
|
||||||
|| (AllZone.getComputerPlayer().getCardsIn(Zone.Battlefield, "Battlegrace Angel").size() >= 2) || ((AllZone
|
|| (AllZone.getComputerPlayer().getCardsIn(Zone.Battlefield, "Battlegrace Angel").size() >= 2) || ((AllZone
|
||||||
|
|||||||
@@ -330,7 +330,7 @@ public final class AbilityFactoryAnimate {
|
|||||||
// don't use instant speed animate abilities outside humans
|
// don't use instant speed animate abilities outside humans
|
||||||
// Combat_Declare_Attackers_InstantAbility step
|
// Combat_Declare_Attackers_InstantAbility step
|
||||||
if ((!AllZone.getPhaseHandler().is(Constant.Phase.COMBAT_DECLARE_ATTACKERS_INSTANT_ABILITY) || (AllZone.getCombat()
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -398,7 +398,7 @@ public class AbilityFactoryPump {
|
|||||||
if (phase.isAfter(Constant.Phase.COMBAT_DECLARE_ATTACKERS)
|
if (phase.isAfter(Constant.Phase.COMBAT_DECLARE_ATTACKERS)
|
||||||
&& phase.isBefore(Constant.Phase.MAIN2)
|
&& phase.isBefore(Constant.Phase.MAIN2)
|
||||||
&& phase.isPlayerTurn(AllZone.getHumanPlayer())
|
&& phase.isPlayerTurn(AllZone.getHumanPlayer())
|
||||||
&& AllZone.getCombat().getAttackers().length > 0
|
&& !AllZone.getCombat().getAttackers().isEmpty()
|
||||||
&& CombatUtil.canBlock(c, AllZone.getCombat())
|
&& CombatUtil.canBlock(c, AllZone.getCombat())
|
||||||
&& CombatUtil.lifeInDanger(AllZone.getCombat())) {
|
&& CombatUtil.lifeInDanger(AllZone.getCombat())) {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ import forge.Card;
|
|||||||
import forge.CardList;
|
import forge.CardList;
|
||||||
import forge.CardListFilter;
|
import forge.CardListFilter;
|
||||||
import forge.CardUtil;
|
import forge.CardUtil;
|
||||||
import forge.Combat;
|
|
||||||
import forge.CombatUtil;
|
import forge.CombatUtil;
|
||||||
import forge.Command;
|
import forge.Command;
|
||||||
import forge.CommandArgs;
|
import forge.CommandArgs;
|
||||||
@@ -360,8 +359,7 @@ public class CardFactoryUtil {
|
|||||||
* @return a boolean.
|
* @return a boolean.
|
||||||
*/
|
*/
|
||||||
public static boolean doesCreatureAttackAI(final Card card) {
|
public static boolean doesCreatureAttackAI(final Card card) {
|
||||||
final Combat combat = ComputerUtil.getAttackers();
|
final List<Card> att = ComputerUtil.getAttackers().getAttackers();
|
||||||
final Card[] att = combat.getAttackers();
|
|
||||||
for (final Card element : att) {
|
for (final Card element : att) {
|
||||||
if (element.equals(card)) {
|
if (element.equals(card)) {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ public class InputAttack extends Input {
|
|||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
public final void selectButtonOK() {
|
public final void selectButtonOK() {
|
||||||
if (AllZone.getCombat().getAttackers().length > 0) {
|
if (!AllZone.getCombat().getAttackers().isEmpty()) {
|
||||||
AllZone.getPhaseHandler().setCombat(true);
|
AllZone.getPhaseHandler().setCombat(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import java.util.ArrayList;
|
|||||||
import forge.AllZone;
|
import forge.AllZone;
|
||||||
import forge.ButtonUtil;
|
import forge.ButtonUtil;
|
||||||
import forge.Card;
|
import forge.Card;
|
||||||
import forge.CardUtil;
|
|
||||||
import forge.CombatUtil;
|
import forge.CombatUtil;
|
||||||
import forge.Command;
|
import forge.Command;
|
||||||
import forge.Constant;
|
import forge.Constant;
|
||||||
@@ -102,7 +101,7 @@ public class InputBlock extends Input {
|
|||||||
@Override
|
@Override
|
||||||
public final void selectCard(final Card card, final PlayerZone zone) {
|
public final void selectCard(final Card card, final PlayerZone zone) {
|
||||||
// is attacking?
|
// is attacking?
|
||||||
if (CardUtil.toList(AllZone.getCombat().getAttackers()).contains(card)) {
|
if (AllZone.getCombat().getAttackers().contains(card)) {
|
||||||
this.currentAttacker = card;
|
this.currentAttacker = card;
|
||||||
} else if (zone.is(Constant.Zone.Battlefield, AllZone.getHumanPlayer()) && card.isCreature()
|
} else if (zone.is(Constant.Zone.Battlefield, AllZone.getHumanPlayer()) && card.isCreature()
|
||||||
&& CombatUtil.canBlock(this.currentAttacker, card, AllZone.getCombat())
|
&& CombatUtil.canBlock(this.currentAttacker, card, AllZone.getCombat())
|
||||||
|
|||||||
@@ -221,7 +221,7 @@ public class InputControl extends MyObservable implements java.io.Serializable {
|
|||||||
this.aiInput.getComputer().declareBlockers();
|
this.aiInput.getComputer().declareBlockers();
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
if (this.model.getGameState().getCombat().getAttackers().length == 0) {
|
if (this.model.getGameState().getCombat().getAttackers().isEmpty()) {
|
||||||
// no active attackers, skip the Blocking phase
|
// no active attackers, skip the Blocking phase
|
||||||
this.model.getGameState().getPhaseHandler().setNeedToNextPhase(true);
|
this.model.getGameState().getPhaseHandler().setNeedToNextPhase(true);
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -355,7 +355,7 @@ public class ViewTabber extends JPanel {
|
|||||||
final Border border = new MatteBorder(0, 0, 0, 0, FSkin.getColor(FSkin.Colors.CLR_BORDERS));
|
final Border border = new MatteBorder(0, 0, 0, 0, FSkin.getColor(FSkin.Colors.CLR_BORDERS));
|
||||||
|
|
||||||
this.vtpTabber.getAllVTabs().get(ControlTabber.COMBAT_PANEL)
|
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);
|
final JTextArea tar = new JTextArea(s);
|
||||||
tar.setOpaque(false);
|
tar.setOpaque(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user