mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 19:28:01 +00:00
Checkstyle fixes in AF_Protection
This commit is contained in:
@@ -20,7 +20,11 @@ import javax.swing.JOptionPane;
|
||||
* @author dennis.r.friedrichsen (slapshot5 on slightlymagic.net)
|
||||
* @version $Id$
|
||||
*/
|
||||
public class AbilityFactory_Protection {
|
||||
public final class AbilityFactory_Protection {
|
||||
|
||||
private AbilityFactory_Protection() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getSpellProtection.</p>
|
||||
@@ -30,7 +34,7 @@ public class AbilityFactory_Protection {
|
||||
*/
|
||||
public static SpellAbility createSpellProtection(final AbilityFactory af) {
|
||||
SpellAbility spProtect = new Spell(af.getHostCard(), af.getAbCost(), af.getAbTgt()) {
|
||||
private static final long serialVersionUID = 4678736312735724916L;
|
||||
private static final long serialVersionUID = 4678736312735724916L;
|
||||
|
||||
@Override
|
||||
public boolean canPlayAI() {
|
||||
@@ -45,8 +49,8 @@ public class AbilityFactory_Protection {
|
||||
@Override
|
||||
public void resolve() {
|
||||
protectResolve(af, this);
|
||||
}//resolve
|
||||
};//SpellAbility
|
||||
} //resolve
|
||||
}; //SpellAbility
|
||||
|
||||
return spProtect;
|
||||
}
|
||||
@@ -74,15 +78,15 @@ public class AbilityFactory_Protection {
|
||||
@Override
|
||||
public void resolve() {
|
||||
protectResolve(af, this);
|
||||
}//resolve()
|
||||
} //resolve()
|
||||
|
||||
@Override
|
||||
public boolean doTrigger(boolean mandatory) {
|
||||
public boolean doTrigger(final boolean mandatory) {
|
||||
return protectTriggerAI(af, this, mandatory);
|
||||
}
|
||||
|
||||
|
||||
};//SpellAbility
|
||||
}; //SpellAbility
|
||||
|
||||
return abProtect;
|
||||
}
|
||||
@@ -110,7 +114,7 @@ public class AbilityFactory_Protection {
|
||||
@Override
|
||||
public void resolve() {
|
||||
protectResolve(af, this);
|
||||
}//resolve
|
||||
} //resolve
|
||||
|
||||
@Override
|
||||
public boolean chkAI_Drawback() {
|
||||
@@ -118,38 +122,42 @@ public class AbilityFactory_Protection {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doTrigger(boolean mandatory) {
|
||||
public boolean doTrigger(final boolean mandatory) {
|
||||
return protectTriggerAI(af, this, mandatory);
|
||||
}
|
||||
};//SpellAbility
|
||||
}; //SpellAbility
|
||||
|
||||
return dbProtect;
|
||||
}
|
||||
|
||||
private static boolean hasProtectionFrom(Card card, String color) {
|
||||
private static boolean hasProtectionFrom(final Card card, final String color) {
|
||||
ArrayList<String> onlyColors = new ArrayList<String>(Arrays.asList(Constant.Color.onlyColors));
|
||||
|
||||
//make sure we have a valid color
|
||||
if(!onlyColors.contains(color)) return false;
|
||||
if (!onlyColors.contains(color)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String protection = "Protection from " + color;
|
||||
if(card.hasKeyword(protection)) return true;
|
||||
else return false;
|
||||
|
||||
return card.hasKeyword(protection);
|
||||
}
|
||||
|
||||
private static boolean hasProtectionFromAny(Card card, ArrayList<String> colors) {
|
||||
private static boolean hasProtectionFromAny(final Card card, final ArrayList<String> colors) {
|
||||
boolean protect = false;
|
||||
for(String color : colors) {
|
||||
for (String color : colors) {
|
||||
protect |= hasProtectionFrom(card, color);
|
||||
}
|
||||
return protect;
|
||||
}
|
||||
|
||||
private static boolean hasProtectionFromAll(Card card, ArrayList<String> colors) {
|
||||
private static boolean hasProtectionFromAll(final Card card, final ArrayList<String> colors) {
|
||||
boolean protect = true;
|
||||
if(colors.size() < 1) return false;
|
||||
if (colors.size() < 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for(String color : colors) {
|
||||
for (String color : colors) {
|
||||
protect &= hasProtectionFrom(card, color);
|
||||
}
|
||||
return protect;
|
||||
@@ -161,40 +169,51 @@ public class AbilityFactory_Protection {
|
||||
* @param af a {@link forge.card.abilityFactory.AbilityFactory} object.
|
||||
* @return a {@link forge.CardList} object.
|
||||
*/
|
||||
private static CardList getProtectCreatures(AbilityFactory af, SpellAbility sa) {
|
||||
private static CardList getProtectCreatures(final AbilityFactory af, final SpellAbility sa) {
|
||||
final Card hostCard = af.getHostCard();
|
||||
final ArrayList<String> gains = getProtectionList(hostCard, af.getMapParams());
|
||||
|
||||
CardList list = AllZoneUtil.getCreaturesInPlay(AllZone.getComputerPlayer());
|
||||
list = list.filter(new CardListFilter() {
|
||||
public boolean addCard(Card c) {
|
||||
if(!CardFactoryUtil.canTarget(hostCard, c))
|
||||
public boolean addCard(final Card c) {
|
||||
if (!CardFactoryUtil.canTarget(hostCard, c)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//Don't add duplicate protections
|
||||
if(hasProtectionFromAll(c, gains)) return false;
|
||||
if (hasProtectionFromAll(c, gains)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//will the creature attack (only relevant for sorcery speed)?
|
||||
if(CardFactoryUtil.AI_doesCreatureAttack(c) && AllZone.getPhase().isBefore(Constant.Phase.Combat_Declare_Attackers)
|
||||
if (CardFactoryUtil.AI_doesCreatureAttack(c)
|
||||
&& AllZone.getPhase().isBefore(Constant.Phase.Combat_Declare_Attackers)
|
||||
&& AllZone.getPhase().isPlayerTurn(AllZone.getComputerPlayer()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//is the creature blocking and unable to destroy the attacker or would be destroyed itself?
|
||||
if(c.isBlocking() && (CombatUtil.blockerWouldBeDestroyed(c)
|
||||
if (c.isBlocking() && (CombatUtil.blockerWouldBeDestroyed(c)
|
||||
|| CombatUtil.attackerWouldBeDestroyed(AllZone.getCombat().getAttackerBlockedBy(c))))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//is the creature in blocked and the blocker would survive
|
||||
if(AllZone.getPhase().isAfter(Constant.Phase.Combat_Declare_Blockers) && AllZone.getCombat().isAttacking(c)
|
||||
if (AllZone.getPhase().isAfter(Constant.Phase.Combat_Declare_Blockers)
|
||||
&& AllZone.getCombat().isAttacking(c)
|
||||
&& AllZone.getCombat().isBlocked(c)
|
||||
&& CombatUtil.blockerWouldBeDestroyed(AllZone.getCombat().getBlockers(c).get(0)))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
});
|
||||
return list;
|
||||
}//getProtectCreatures()
|
||||
} //getProtectCreatures()
|
||||
|
||||
/**
|
||||
* <p>protectCanPlayAI.</p>
|
||||
@@ -203,57 +222,64 @@ public class AbilityFactory_Protection {
|
||||
* @param sa a {@link forge.card.spellability.SpellAbility} object.
|
||||
* @return a boolean.
|
||||
*/
|
||||
private static boolean protectCanPlayAI(AbilityFactory af, SpellAbility sa) {
|
||||
HashMap<String,String> params = af.getMapParams();
|
||||
private static boolean protectCanPlayAI(final AbilityFactory af, final SpellAbility sa) {
|
||||
HashMap<String, String> params = af.getMapParams();
|
||||
Card hostCard = af.getHostCard();
|
||||
// if there is no target and host card isn't in play, don't activate
|
||||
if(af.getAbTgt() == null && !AllZoneUtil.isCardInPlay(hostCard))
|
||||
if (af.getAbTgt() == null && !AllZoneUtil.isCardInPlay(hostCard)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Cost cost = sa.getPayCosts();
|
||||
|
||||
// temporarily disabled until better AI
|
||||
if (!CostUtil.checkLifeCost(cost, hostCard, 4))
|
||||
if (!CostUtil.checkLifeCost(cost, hostCard, 4)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!CostUtil.checkDiscardCost(cost, hostCard))
|
||||
if (!CostUtil.checkDiscardCost(cost, hostCard)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!CostUtil.checkCreatureSacrificeCost(cost, hostCard))
|
||||
if (!CostUtil.checkCreatureSacrificeCost(cost, hostCard)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!CostUtil.checkRemoveCounterCost(cost, hostCard))
|
||||
if (!CostUtil.checkRemoveCounterCost(cost, hostCard)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Phase Restrictions
|
||||
if(AllZone.getStack().size() == 0 && AllZone.getPhase().isBefore(Constant.Phase.Combat_FirstStrikeDamage)) {
|
||||
if (AllZone.getStack().size() == 0 && AllZone.getPhase().isBefore(Constant.Phase.Combat_FirstStrikeDamage)) {
|
||||
// Instant-speed protections should not be cast outside of combat when the stack is empty
|
||||
if(!AbilityFactory.isSorcerySpeed(sa))
|
||||
return false;
|
||||
if (!AbilityFactory.isSorcerySpeed(sa)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if(AllZone.getStack().size() > 0) {
|
||||
// TODO: protection something only if the top thing on the stack will kill it via damage or destroy
|
||||
else if (AllZone.getStack().size() > 0) {
|
||||
// TODO protection something only if the top thing on the stack will kill it via damage or destroy
|
||||
return false;
|
||||
}
|
||||
|
||||
if(af.getAbTgt() == null || !af.getAbTgt().doesTarget()) {
|
||||
if (af.getAbTgt() == null || !af.getAbTgt().doesTarget()) {
|
||||
ArrayList<Card> cards = AbilityFactory.getDefinedCards(sa.getSourceCard(), params.get("Defined"), sa);
|
||||
|
||||
if(cards.size() == 0)
|
||||
return false;
|
||||
if (cards.size() == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
// when this happens we need to expand AI to consider if its ok for everything?
|
||||
for (Card card : cards) {
|
||||
// TODO: if AI doesn't control Card and Pump is a Curse, than maybe use?
|
||||
// TODO if AI doesn't control Card and Pump is a Curse, than maybe use?
|
||||
|
||||
}*/
|
||||
} else {
|
||||
return protectTgtAI(af, sa, false);
|
||||
}
|
||||
else
|
||||
return protectTgtAI(af, sa, false);
|
||||
|
||||
return false;
|
||||
}//protectPlayAI()
|
||||
} //protectPlayAI()
|
||||
|
||||
/**
|
||||
* <p>protectTgtAI.</p>
|
||||
@@ -263,9 +289,10 @@ public class AbilityFactory_Protection {
|
||||
* @param mandatory a boolean.
|
||||
* @return a boolean.
|
||||
*/
|
||||
private static boolean protectTgtAI(AbilityFactory af, SpellAbility sa, boolean mandatory) {
|
||||
if (!mandatory && AllZone.getPhase().isAfter(Constant.Phase.Combat_Declare_Blockers_InstantAbility))
|
||||
private static boolean protectTgtAI(final AbilityFactory af, final SpellAbility sa, final boolean mandatory) {
|
||||
if (!mandatory && AllZone.getPhase().isAfter(Constant.Phase.Combat_Declare_Blockers_InstantAbility)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Card source = sa.getSourceCard();
|
||||
|
||||
@@ -284,27 +311,34 @@ public class AbilityFactory_Protection {
|
||||
* Or, add protection (to make it unblockable) when Compy is attacking.
|
||||
*/
|
||||
|
||||
if(AllZone.getStack().size() == 0) {
|
||||
if (AllZone.getStack().size() == 0) {
|
||||
// If the cost is tapping, don't activate before declare attack/block
|
||||
if(sa.getPayCosts() != null && sa.getPayCosts().getTap()) {
|
||||
if(AllZone.getPhase().isBefore(Constant.Phase.Combat_Declare_Attackers) && AllZone.getPhase().isPlayerTurn(AllZone.getComputerPlayer()))
|
||||
if (sa.getPayCosts() != null && sa.getPayCosts().getTap()) {
|
||||
if (AllZone.getPhase().isBefore(Constant.Phase.Combat_Declare_Attackers)
|
||||
&& AllZone.getPhase().isPlayerTurn(AllZone.getComputerPlayer())) {
|
||||
list.remove(sa.getSourceCard());
|
||||
if(AllZone.getPhase().isBefore(Constant.Phase.Combat_Declare_Blockers) && AllZone.getPhase().isPlayerTurn(AllZone.getHumanPlayer()))
|
||||
}
|
||||
if (AllZone.getPhase().isBefore(Constant.Phase.Combat_Declare_Blockers)
|
||||
&& AllZone.getPhase().isPlayerTurn(AllZone.getHumanPlayer()))
|
||||
{
|
||||
list.remove(sa.getSourceCard());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(list.isEmpty())
|
||||
if (list.isEmpty()) {
|
||||
return mandatory && protectMandatoryTarget(af, sa, mandatory);
|
||||
}
|
||||
|
||||
while(tgt.getNumTargeted() < tgt.getMaxTargets(source, sa)) {
|
||||
while (tgt.getNumTargeted() < tgt.getMaxTargets(source, sa)) {
|
||||
Card t = null;
|
||||
//boolean goodt = false;
|
||||
|
||||
if(list.isEmpty()) {
|
||||
if(tgt.getNumTargeted() < tgt.getMinTargets(source, sa) || tgt.getNumTargeted() == 0) {
|
||||
if(mandatory)
|
||||
if (list.isEmpty()) {
|
||||
if (tgt.getNumTargeted() < tgt.getMinTargets(source, sa) || tgt.getNumTargeted() == 0) {
|
||||
if (mandatory) {
|
||||
return protectMandatoryTarget(af, sa, mandatory);
|
||||
}
|
||||
|
||||
tgt.resetTargets();
|
||||
return false;
|
||||
@@ -321,7 +355,7 @@ public class AbilityFactory_Protection {
|
||||
}
|
||||
|
||||
return true;
|
||||
}//protectTgtAI()
|
||||
} //protectTgtAI()
|
||||
|
||||
/**
|
||||
* <p>protectMandatoryTarget.</p>
|
||||
@@ -331,90 +365,99 @@ public class AbilityFactory_Protection {
|
||||
* @param mandatory a boolean.
|
||||
* @return a boolean.
|
||||
*/
|
||||
private static boolean protectMandatoryTarget(AbilityFactory af, SpellAbility sa, boolean mandatory) {
|
||||
final HashMap<String,String> params = af.getMapParams();
|
||||
private static boolean protectMandatoryTarget(final AbilityFactory af, final SpellAbility sa,
|
||||
final boolean mandatory)
|
||||
{
|
||||
final HashMap<String, String> params = af.getMapParams();
|
||||
final Card host = af.getHostCard();
|
||||
|
||||
CardList list = AllZoneUtil.getCardsInPlay();
|
||||
Target tgt = sa.getTarget();
|
||||
list = list.getValidCards(tgt.getValidTgts(), sa.getActivatingPlayer(), sa.getSourceCard());
|
||||
|
||||
if(list.size() < tgt.getMinTargets(sa.getSourceCard(), sa)) {
|
||||
if (list.size() < tgt.getMinTargets(sa.getSourceCard(), sa)) {
|
||||
tgt.resetTargets();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Remove anything that's already been targeted
|
||||
for(Card c : tgt.getTargetCards())
|
||||
for (Card c : tgt.getTargetCards()) {
|
||||
list.remove(c);
|
||||
}
|
||||
|
||||
CardList pref = list.getController(AllZone.getComputerPlayer());
|
||||
pref = pref.filter(new CardListFilter() {
|
||||
public boolean addCard(Card c) {
|
||||
public boolean addCard(final Card c) {
|
||||
return !hasProtectionFromAll(c, getProtectionList(host, params));
|
||||
}
|
||||
});
|
||||
CardList pref2 = list.getController(AllZone.getComputerPlayer());
|
||||
pref = pref.filter(new CardListFilter() {
|
||||
public boolean addCard(Card c) {
|
||||
public boolean addCard(final Card c) {
|
||||
return !hasProtectionFromAny(c, getProtectionList(host, params));
|
||||
}
|
||||
});
|
||||
CardList forced = list.getController(AllZone.getHumanPlayer());
|
||||
Card source = sa.getSourceCard();
|
||||
|
||||
while(tgt.getNumTargeted() < tgt.getMaxTargets(source, sa)) {
|
||||
if(pref.isEmpty())
|
||||
while (tgt.getNumTargeted() < tgt.getMaxTargets(source, sa)) {
|
||||
if (pref.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
|
||||
Card c;
|
||||
if(pref.getNotType("Creature").size() == 0)
|
||||
if (pref.getNotType("Creature").size() == 0) {
|
||||
c = CardFactoryUtil.AI_getBestCreature(pref);
|
||||
else
|
||||
} else {
|
||||
c = CardFactoryUtil.AI_getMostExpensivePermanent(pref, source, true);
|
||||
}
|
||||
|
||||
pref.remove(c);
|
||||
|
||||
tgt.addTarget(c);
|
||||
}
|
||||
|
||||
while(tgt.getNumTargeted() < tgt.getMaxTargets(source, sa)) {
|
||||
if(pref2.isEmpty())
|
||||
while (tgt.getNumTargeted() < tgt.getMaxTargets(source, sa)) {
|
||||
if (pref2.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
|
||||
Card c;
|
||||
if(pref2.getNotType("Creature").size() == 0)
|
||||
if (pref2.getNotType("Creature").size() == 0) {
|
||||
c = CardFactoryUtil.AI_getBestCreature(pref2);
|
||||
else
|
||||
} else {
|
||||
c = CardFactoryUtil.AI_getMostExpensivePermanent(pref2, source, true);
|
||||
}
|
||||
|
||||
pref2.remove(c);
|
||||
|
||||
tgt.addTarget(c);
|
||||
}
|
||||
|
||||
while(tgt.getNumTargeted() < tgt.getMinTargets(source, sa)) {
|
||||
if(forced.isEmpty())
|
||||
while (tgt.getNumTargeted() < tgt.getMinTargets(source, sa)) {
|
||||
if (forced.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
|
||||
Card c;
|
||||
if(forced.getNotType("Creature").size() == 0)
|
||||
if (forced.getNotType("Creature").size() == 0) {
|
||||
c = CardFactoryUtil.AI_getWorstCreature(forced);
|
||||
else
|
||||
} else {
|
||||
c = CardFactoryUtil.AI_getCheapestPermanent(forced, source, true);
|
||||
}
|
||||
|
||||
forced.remove(c);
|
||||
|
||||
tgt.addTarget(c);
|
||||
}
|
||||
|
||||
if(tgt.getNumTargeted() < tgt.getMinTargets(sa.getSourceCard(), sa)) {
|
||||
if (tgt.getNumTargeted() < tgt.getMinTargets(sa.getSourceCard(), sa)) {
|
||||
tgt.resetTargets();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}//protectMandatoryTarget()
|
||||
} //protectMandatoryTarget()
|
||||
|
||||
/**
|
||||
* <p>protectTriggerAI.</p>
|
||||
@@ -424,20 +467,22 @@ public class AbilityFactory_Protection {
|
||||
* @param mandatory a boolean.
|
||||
* @return a boolean.
|
||||
*/
|
||||
private static boolean protectTriggerAI(AbilityFactory af, SpellAbility sa, boolean mandatory) {
|
||||
if(!ComputerUtil.canPayCost(sa))
|
||||
private static boolean protectTriggerAI(final AbilityFactory af, final SpellAbility sa, final boolean mandatory) {
|
||||
if (!ComputerUtil.canPayCost(sa)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(sa.getTarget() == null) {
|
||||
if(mandatory)
|
||||
if (sa.getTarget() == null) {
|
||||
if (mandatory) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return protectTgtAI(af, sa, mandatory);
|
||||
}
|
||||
|
||||
return true;
|
||||
}//protectTriggerAI
|
||||
} //protectTriggerAI
|
||||
|
||||
/**
|
||||
* <p>protectDrawbackAI.</p>
|
||||
@@ -446,19 +491,19 @@ public class AbilityFactory_Protection {
|
||||
* @param sa a {@link forge.card.spellability.SpellAbility} object.
|
||||
* @return a boolean.
|
||||
*/
|
||||
private static boolean protectDrawbackAI(AbilityFactory af, SpellAbility sa) {
|
||||
private static boolean protectDrawbackAI(final AbilityFactory af, final SpellAbility sa) {
|
||||
Card host = af.getHostCard();
|
||||
|
||||
if(af.getAbTgt() == null || !af.getAbTgt().doesTarget()) {
|
||||
if(host.isCreature()) {
|
||||
if (af.getAbTgt() == null || !af.getAbTgt().doesTarget()) {
|
||||
if (host.isCreature()) {
|
||||
//TODO
|
||||
}
|
||||
}
|
||||
else
|
||||
} else {
|
||||
return protectTgtAI(af, sa, false);
|
||||
}
|
||||
|
||||
return true;
|
||||
}//protectDrawbackAI()
|
||||
} //protectDrawbackAI()
|
||||
|
||||
/**
|
||||
* <p>protectStackDescription.</p>
|
||||
@@ -467,8 +512,8 @@ public class AbilityFactory_Protection {
|
||||
* @param sa a {@link forge.card.spellability.SpellAbility} object.
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
private static String protectStackDescription(AbilityFactory af, SpellAbility sa) {
|
||||
HashMap<String,String> params = af.getMapParams();
|
||||
private static String protectStackDescription(final AbilityFactory af, final SpellAbility sa) {
|
||||
HashMap<String, String> params = af.getMapParams();
|
||||
Card host = af.getHostCard();
|
||||
|
||||
final ArrayList<String> gains = getProtectionList(host, params);
|
||||
@@ -479,56 +524,70 @@ public class AbilityFactory_Protection {
|
||||
|
||||
ArrayList<Card> tgtCards;
|
||||
Target tgt = af.getAbTgt();
|
||||
if(tgt != null)
|
||||
tgtCards = tgt.getTargetCards();
|
||||
else
|
||||
tgtCards = AbilityFactory.getDefinedCards(sa.getSourceCard(), params.get("Defined"), sa);
|
||||
if (tgt != null) {
|
||||
tgtCards = tgt.getTargetCards();
|
||||
} else {
|
||||
tgtCards = AbilityFactory.getDefinedCards(sa.getSourceCard(), params.get("Defined"), sa);
|
||||
}
|
||||
|
||||
if(tgtCards.size() > 0) {
|
||||
if (tgtCards.size() > 0) {
|
||||
|
||||
if(sa instanceof Ability_Sub)
|
||||
sb.append(" ");
|
||||
else
|
||||
sb.append(host).append(" - ");
|
||||
if (sa instanceof Ability_Sub) {
|
||||
sb.append(" ");
|
||||
} else {
|
||||
sb.append(host).append(" - ");
|
||||
}
|
||||
|
||||
Iterator<Card> it = tgtCards.iterator();
|
||||
while (it.hasNext()) {
|
||||
Card tgtC = it.next();
|
||||
if (tgtC.isFaceDown()) sb.append("Morph");
|
||||
else sb.append(tgtC);
|
||||
if (tgtC.isFaceDown()) {
|
||||
sb.append("Morph");
|
||||
} else {
|
||||
sb.append(tgtC);
|
||||
}
|
||||
|
||||
if (it.hasNext()) sb.append(", ");
|
||||
if (it.hasNext()) {
|
||||
sb.append(", ");
|
||||
}
|
||||
}
|
||||
|
||||
sb.append(" gain");
|
||||
if(tgtCards.size() == 1) sb.append("s");
|
||||
if (tgtCards.size() == 1) {
|
||||
sb.append("s");
|
||||
}
|
||||
sb.append(" protection from ");
|
||||
|
||||
if(choose) sb.append("your choice of ");
|
||||
if (choose) {
|
||||
sb.append("your choice of ");
|
||||
}
|
||||
|
||||
for(int i = 0; i < gains.size(); i++) {
|
||||
if (i != 0)
|
||||
sb.append(", ");
|
||||
for (int i = 0; i < gains.size(); i++) {
|
||||
if (i != 0) {
|
||||
sb.append(", ");
|
||||
}
|
||||
|
||||
if (i == gains.size() - 1)
|
||||
sb.append(joiner).append(" ");
|
||||
if (i == gains.size() - 1) {
|
||||
sb.append(joiner).append(" ");
|
||||
}
|
||||
|
||||
sb.append(gains.get(i));
|
||||
}
|
||||
|
||||
if(!params.containsKey("Permanent"))
|
||||
sb.append(" until end of turn");
|
||||
if (!params.containsKey("Permanent")) {
|
||||
sb.append(" until end of turn");
|
||||
}
|
||||
|
||||
sb.append(".");
|
||||
}
|
||||
|
||||
Ability_Sub abSub = sa.getSubAbility();
|
||||
if(abSub != null) {
|
||||
if (abSub != null) {
|
||||
sb.append(abSub.getStackDescription());
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}//protectStackDescription()
|
||||
} //protectStackDescription()
|
||||
|
||||
/**
|
||||
* <p>protectResolve.</p>
|
||||
@@ -536,18 +595,20 @@ public class AbilityFactory_Protection {
|
||||
* @param af a {@link forge.card.abilityFactory.AbilityFactory} object.
|
||||
* @param sa a {@link forge.card.spellability.SpellAbility} object.
|
||||
*/
|
||||
private static void protectResolve(AbilityFactory af, SpellAbility sa) {
|
||||
HashMap<String,String> params = af.getMapParams();
|
||||
private static void protectResolve(final AbilityFactory af, final SpellAbility sa) {
|
||||
HashMap<String, String> params = af.getMapParams();
|
||||
final Card host = af.getHostCard();
|
||||
|
||||
boolean isChoice = params.get("Gains").contains("Choice");
|
||||
ArrayList<String> choices = getProtectionList(host, params);
|
||||
final ArrayList<String> gains = new ArrayList<String>();
|
||||
if(isChoice) {
|
||||
if(sa.getActivatingPlayer().isHuman()) {
|
||||
if (isChoice) {
|
||||
if (sa.getActivatingPlayer().isHuman()) {
|
||||
Object o = GuiUtils.getChoice("Choose a protection", choices.toArray());
|
||||
|
||||
if(null == o) return;
|
||||
if (null == o) {
|
||||
return;
|
||||
}
|
||||
String choice = (String) o;
|
||||
gains.add(choice);
|
||||
}
|
||||
@@ -555,15 +616,15 @@ public class AbilityFactory_Protection {
|
||||
//TODO - needs improvement
|
||||
String choice = choices.get(0);
|
||||
gains.add(choice);
|
||||
JOptionPane.showMessageDialog(null, "Computer chooses "+gains, ""+host, JOptionPane.PLAIN_MESSAGE);
|
||||
JOptionPane.showMessageDialog(null, "Computer chooses " + gains, "" + host, JOptionPane.PLAIN_MESSAGE);
|
||||
}
|
||||
} else {
|
||||
gains.addAll(choices);
|
||||
}
|
||||
else
|
||||
gains.addAll(choices);
|
||||
|
||||
ArrayList<Card> tgtCards;
|
||||
Target tgt = af.getAbTgt();
|
||||
if(tgt != null) {
|
||||
if (tgt != null) {
|
||||
tgtCards = tgt.getTargetCards();
|
||||
}
|
||||
else {
|
||||
@@ -571,55 +632,61 @@ public class AbilityFactory_Protection {
|
||||
}
|
||||
|
||||
int size = tgtCards.size();
|
||||
for(int j = 0; j < size; j++) {
|
||||
for (int j = 0; j < size; j++) {
|
||||
final Card tgtC = tgtCards.get(j);
|
||||
|
||||
// only pump things in play
|
||||
if(!AllZoneUtil.isCardInPlay(tgtC))
|
||||
if (!AllZoneUtil.isCardInPlay(tgtC)) {
|
||||
continue;
|
||||
|
||||
// if this is a target, make sure we can still target now
|
||||
if(tgt != null && !CardFactoryUtil.canTarget(host, tgtC))
|
||||
continue;
|
||||
|
||||
for(String gain : gains) {
|
||||
tgtC.addExtrinsicKeyword("Protection from "+gain);
|
||||
}
|
||||
|
||||
if(!params.containsKey("Permanent")) {
|
||||
// if this is a target, make sure we can still target now
|
||||
if (tgt != null && !CardFactoryUtil.canTarget(host, tgtC)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (String gain : gains) {
|
||||
tgtC.addExtrinsicKeyword("Protection from " + gain);
|
||||
}
|
||||
|
||||
if (!params.containsKey("Permanent")) {
|
||||
// If not Permanent, remove protection at EOT
|
||||
final Command untilEOT = new Command() {
|
||||
private static final long serialVersionUID = 7682700789217703789L;
|
||||
|
||||
public void execute() {
|
||||
if(AllZoneUtil.isCardInPlay(tgtC)) {
|
||||
if (AllZoneUtil.isCardInPlay(tgtC)) {
|
||||
for (String gain : gains) {
|
||||
tgtC.removeExtrinsicKeyword("Protection from "+gain);
|
||||
tgtC.removeExtrinsicKeyword("Protection from " + gain);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
if(params.containsKey("UntilEndOfCombat")) AllZone.getEndOfCombat().addUntil(untilEOT);
|
||||
else AllZone.getEndOfTurn().addUntil(untilEOT);
|
||||
if (params.containsKey("UntilEndOfCombat")) {
|
||||
AllZone.getEndOfCombat().addUntil(untilEOT);
|
||||
} else {
|
||||
AllZone.getEndOfTurn().addUntil(untilEOT);
|
||||
}
|
||||
}
|
||||
}
|
||||
}//protectResolve()
|
||||
} //protectResolve()
|
||||
|
||||
private static ArrayList<String> getProtectionList(Card host, HashMap<String,String> params) {
|
||||
private static ArrayList<String> getProtectionList(final Card host, final HashMap<String, String> params) {
|
||||
final ArrayList<String> gains = new ArrayList<String>();
|
||||
|
||||
String gainStr = params.get("Gains");
|
||||
if(gainStr.equals("Choice")) {
|
||||
if (gainStr.equals("Choice")) {
|
||||
String choices = params.get("Choices");
|
||||
|
||||
// Replace AnyColor with the 5 colors
|
||||
if (choices.contains("AnyColor")){
|
||||
if (choices.contains("AnyColor")) {
|
||||
gains.addAll(Arrays.asList(Constant.Color.onlyColors));
|
||||
choices = choices.replaceAll("AnyColor,?", "");
|
||||
}
|
||||
// Add any remaining choices
|
||||
if (choices.length() > 0)
|
||||
gains.addAll(Arrays.asList(choices.split(",")));
|
||||
if (choices.length() > 0) {
|
||||
gains.addAll(Arrays.asList(choices.split(",")));
|
||||
}
|
||||
}
|
||||
else {
|
||||
gains.addAll(Arrays.asList(gainStr.split(",")));
|
||||
@@ -627,20 +694,6 @@ public class AbilityFactory_Protection {
|
||||
return gains;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// *************************************************************************
|
||||
// ************************** ProtectionAll ********************************
|
||||
// *************************************************************************
|
||||
@@ -667,8 +720,8 @@ public class AbilityFactory_Protection {
|
||||
@Override
|
||||
public void resolve() {
|
||||
protectAllResolve(af, this);
|
||||
}//resolve
|
||||
};//SpellAbility
|
||||
} //resolve
|
||||
}; //SpellAbility
|
||||
|
||||
return spProtectAll;
|
||||
}
|
||||
@@ -696,15 +749,15 @@ public class AbilityFactory_Protection {
|
||||
@Override
|
||||
public void resolve() {
|
||||
protectAllResolve(af, this);
|
||||
}//resolve()
|
||||
} //resolve()
|
||||
|
||||
@Override
|
||||
public boolean doTrigger(boolean mandatory) {
|
||||
public boolean doTrigger(final boolean mandatory) {
|
||||
return protectAllTriggerAI(af, this, mandatory);
|
||||
}
|
||||
|
||||
|
||||
};//SpellAbility
|
||||
}; //SpellAbility
|
||||
|
||||
return abProtectAll;
|
||||
}
|
||||
@@ -732,7 +785,7 @@ public class AbilityFactory_Protection {
|
||||
@Override
|
||||
public void resolve() {
|
||||
protectAllResolve(af, this);
|
||||
}//resolve
|
||||
} //resolve
|
||||
|
||||
@Override
|
||||
public boolean chkAI_Drawback() {
|
||||
@@ -740,10 +793,10 @@ public class AbilityFactory_Protection {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doTrigger(boolean mandatory) {
|
||||
public boolean doTrigger(final boolean mandatory) {
|
||||
return protectAllTriggerAI(af, this, mandatory);
|
||||
}
|
||||
};//SpellAbility
|
||||
}; //SpellAbility
|
||||
|
||||
return dbProtectAll;
|
||||
}
|
||||
@@ -755,29 +808,34 @@ public class AbilityFactory_Protection {
|
||||
* @param sa a {@link forge.card.spellability.SpellAbility} object.
|
||||
* @return a boolean.
|
||||
*/
|
||||
private static boolean protectAllCanPlayAI(AbilityFactory af, SpellAbility sa) {
|
||||
private static boolean protectAllCanPlayAI(final AbilityFactory af, final SpellAbility sa) {
|
||||
Card hostCard = af.getHostCard();
|
||||
// if there is no target and host card isn't in play, don't activate
|
||||
if(af.getAbTgt() == null && !AllZoneUtil.isCardInPlay(hostCard))
|
||||
if (af.getAbTgt() == null && !AllZoneUtil.isCardInPlay(hostCard)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Cost cost = sa.getPayCosts();
|
||||
|
||||
// temporarily disabled until better AI
|
||||
if (!CostUtil.checkLifeCost(cost, hostCard, 4))
|
||||
if (!CostUtil.checkLifeCost(cost, hostCard, 4)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!CostUtil.checkDiscardCost(cost, hostCard))
|
||||
if (!CostUtil.checkDiscardCost(cost, hostCard)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!CostUtil.checkSacrificeCost(cost, hostCard))
|
||||
if (!CostUtil.checkSacrificeCost(cost, hostCard)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!CostUtil.checkRemoveCounterCost(cost, hostCard))
|
||||
if (!CostUtil.checkRemoveCounterCost(cost, hostCard)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}//protectAllCanPlayAI()
|
||||
} //protectAllCanPlayAI()
|
||||
|
||||
/**
|
||||
* <p>protectAllTriggerAI.</p>
|
||||
@@ -787,12 +845,15 @@ public class AbilityFactory_Protection {
|
||||
* @param mandatory a boolean.
|
||||
* @return a boolean.
|
||||
*/
|
||||
private static boolean protectAllTriggerAI(AbilityFactory af, SpellAbility sa, boolean mandatory) {
|
||||
if(!ComputerUtil.canPayCost(sa))
|
||||
private static boolean protectAllTriggerAI(final AbilityFactory af, final SpellAbility sa,
|
||||
final boolean mandatory)
|
||||
{
|
||||
if (!ComputerUtil.canPayCost(sa)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}//protectAllTriggerAI
|
||||
} //protectAllTriggerAI
|
||||
|
||||
/**
|
||||
* <p>protectAllDrawbackAI.</p>
|
||||
@@ -801,9 +862,9 @@ public class AbilityFactory_Protection {
|
||||
* @param sa a {@link forge.card.spellability.SpellAbility} object.
|
||||
* @return a boolean.
|
||||
*/
|
||||
private static boolean protectAllDrawbackAI(AbilityFactory af, SpellAbility sa) {
|
||||
private static boolean protectAllDrawbackAI(final AbilityFactory af, final SpellAbility sa) {
|
||||
return protectAllTriggerAI(af, sa, false);
|
||||
}//protectAllDrawbackAI()
|
||||
} //protectAllDrawbackAI()
|
||||
|
||||
/**
|
||||
* <p>protectAllStackDescription.</p>
|
||||
@@ -812,43 +873,46 @@ public class AbilityFactory_Protection {
|
||||
* @param sa a {@link forge.card.spellability.SpellAbility} object.
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
private static String protectAllStackDescription(AbilityFactory af, SpellAbility sa) {
|
||||
HashMap<String,String> params = af.getMapParams();
|
||||
private static String protectAllStackDescription(final AbilityFactory af, final SpellAbility sa) {
|
||||
HashMap<String, String> params = af.getMapParams();
|
||||
Card host = af.getHostCard();
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
ArrayList<Card> tgtCards;
|
||||
Target tgt = af.getAbTgt();
|
||||
if(tgt != null)
|
||||
tgtCards = tgt.getTargetCards();
|
||||
else
|
||||
tgtCards = AbilityFactory.getDefinedCards(sa.getSourceCard(), params.get("Defined"), sa);
|
||||
if (tgt != null) {
|
||||
tgtCards = tgt.getTargetCards();
|
||||
} else {
|
||||
tgtCards = AbilityFactory.getDefinedCards(sa.getSourceCard(), params.get("Defined"), sa);
|
||||
}
|
||||
|
||||
if(tgtCards.size() > 0) {
|
||||
if (tgtCards.size() > 0) {
|
||||
|
||||
if(sa instanceof Ability_Sub)
|
||||
sb.append(" ");
|
||||
else
|
||||
sb.append(host).append(" - ");
|
||||
if (sa instanceof Ability_Sub) {
|
||||
sb.append(" ");
|
||||
} else {
|
||||
sb.append(host).append(" - ");
|
||||
}
|
||||
|
||||
if (params.containsKey("SpellDescription")) {
|
||||
sb.append(params.get("SpellDescription"));
|
||||
} else {
|
||||
sb.append("Valid card gain protection");
|
||||
if(!params.containsKey("Permanent"))
|
||||
sb.append(" until end of turn");
|
||||
if (!params.containsKey("Permanent")) {
|
||||
sb.append(" until end of turn");
|
||||
}
|
||||
sb.append(".");
|
||||
}
|
||||
}
|
||||
|
||||
Ability_Sub abSub = sa.getSubAbility();
|
||||
if(abSub != null) {
|
||||
if (abSub != null) {
|
||||
sb.append(abSub.getStackDescription());
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}//protectStackDescription()
|
||||
} //protectStackDescription()
|
||||
|
||||
/**
|
||||
* <p>protectAllResolve.</p>
|
||||
@@ -856,18 +920,20 @@ public class AbilityFactory_Protection {
|
||||
* @param af a {@link forge.card.abilityFactory.AbilityFactory} object.
|
||||
* @param sa a {@link forge.card.spellability.SpellAbility} object.
|
||||
*/
|
||||
private static void protectAllResolve(AbilityFactory af, SpellAbility sa) {
|
||||
HashMap<String,String> params = af.getMapParams();
|
||||
private static void protectAllResolve(final AbilityFactory af, final SpellAbility sa) {
|
||||
HashMap<String, String> params = af.getMapParams();
|
||||
final Card host = af.getHostCard();
|
||||
|
||||
boolean isChoice = params.get("Gains").contains("Choice");
|
||||
ArrayList<String> choices = getProtectionList(host, params);
|
||||
final ArrayList<String> gains = new ArrayList<String>();
|
||||
if(isChoice) {
|
||||
if(sa.getActivatingPlayer().isHuman()) {
|
||||
if (isChoice) {
|
||||
if (sa.getActivatingPlayer().isHuman()) {
|
||||
Object o = GuiUtils.getChoice("Choose a protection", choices.toArray());
|
||||
|
||||
if(null == o) return;
|
||||
if (null == o) {
|
||||
return;
|
||||
}
|
||||
String choice = (String) o;
|
||||
gains.add(choice);
|
||||
}
|
||||
@@ -875,41 +941,44 @@ public class AbilityFactory_Protection {
|
||||
//TODO - needs improvement
|
||||
String choice = choices.get(0);
|
||||
gains.add(choice);
|
||||
JOptionPane.showMessageDialog(null, "Computer chooses "+gains, ""+host, JOptionPane.PLAIN_MESSAGE);
|
||||
JOptionPane.showMessageDialog(null, "Computer chooses " + gains, "" + host, JOptionPane.PLAIN_MESSAGE);
|
||||
}
|
||||
} else {
|
||||
gains.addAll(choices);
|
||||
}
|
||||
else
|
||||
gains.addAll(choices);
|
||||
|
||||
String valid = params.get("ValidCards");
|
||||
CardList list = AllZoneUtil.getCardsInPlay();
|
||||
list = list.getValidCards(valid, sa.getActivatingPlayer(), host);
|
||||
|
||||
|
||||
for(final Card tgtC : list) {
|
||||
if(AllZoneUtil.isCardInPlay(tgtC)) {
|
||||
for(String gain : gains) {
|
||||
tgtC.addExtrinsicKeyword("Protection from "+gain);
|
||||
for (final Card tgtC : list) {
|
||||
if (AllZoneUtil.isCardInPlay(tgtC)) {
|
||||
for (String gain : gains) {
|
||||
tgtC.addExtrinsicKeyword("Protection from " + gain);
|
||||
}
|
||||
|
||||
if(!params.containsKey("Permanent")) {
|
||||
if (!params.containsKey("Permanent")) {
|
||||
// If not Permanent, remove protection at EOT
|
||||
final Command untilEOT = new Command() {
|
||||
private static final long serialVersionUID = -6573962672873853565L;
|
||||
|
||||
public void execute() {
|
||||
if(AllZoneUtil.isCardInPlay(tgtC)) {
|
||||
if (AllZoneUtil.isCardInPlay(tgtC)) {
|
||||
for (String gain : gains) {
|
||||
tgtC.removeExtrinsicKeyword("Protection from "+gain);
|
||||
tgtC.removeExtrinsicKeyword("Protection from " + gain);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
if(params.containsKey("UntilEndOfCombat")) AllZone.getEndOfCombat().addUntil(untilEOT);
|
||||
else AllZone.getEndOfTurn().addUntil(untilEOT);
|
||||
if (params.containsKey("UntilEndOfCombat")) {
|
||||
AllZone.getEndOfCombat().addUntil(untilEOT);
|
||||
} else {
|
||||
AllZone.getEndOfTurn().addUntil(untilEOT);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}//protectAllResolve()
|
||||
} //protectAllResolve()
|
||||
|
||||
}//end class AbilityFactory_Protection
|
||||
} //end class AbilityFactory_Protection
|
||||
|
||||
Reference in New Issue
Block a user