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