mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 03:38:01 +00:00
- Moved Unless cost to AbilityFactory making it available for all AFs.
This commit is contained in:
@@ -6909,4 +6909,20 @@ public class GameActionUtil {
|
|||||||
}//end getAffectedCards()
|
}//end getAffectedCards()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
public static void doPowerSink(Player p) {
|
||||||
|
//get all lands with mana abilities
|
||||||
|
CardList lands = AllZoneUtil.getPlayerLandsInPlay(p);
|
||||||
|
lands = lands.filter(new CardListFilter() {
|
||||||
|
public boolean addCard(Card c) {
|
||||||
|
return c.getManaAbility().size() > 0;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
//tap them
|
||||||
|
for(Card c:lands) c.tap();
|
||||||
|
|
||||||
|
//empty mana pool
|
||||||
|
if(p.isHuman()) AllZone.ManaPool.clearPool();
|
||||||
|
}
|
||||||
|
|
||||||
}//end class GameActionUtil
|
}//end class GameActionUtil
|
||||||
|
|||||||
@@ -7,9 +7,13 @@ import forge.AllZone;
|
|||||||
import forge.AllZoneUtil;
|
import forge.AllZoneUtil;
|
||||||
import forge.Card;
|
import forge.Card;
|
||||||
import forge.CardList;
|
import forge.CardList;
|
||||||
|
import forge.Command;
|
||||||
|
import forge.ComputerUtil;
|
||||||
import forge.Constant;
|
import forge.Constant;
|
||||||
|
import forge.GameActionUtil;
|
||||||
import forge.Player;
|
import forge.Player;
|
||||||
import forge.card.cardFactory.CardFactoryUtil;
|
import forge.card.cardFactory.CardFactoryUtil;
|
||||||
|
import forge.card.spellability.Ability;
|
||||||
import forge.card.spellability.Ability_Sub;
|
import forge.card.spellability.Ability_Sub;
|
||||||
import forge.card.spellability.Cost;
|
import forge.card.spellability.Cost;
|
||||||
import forge.card.spellability.SpellAbility;
|
import forge.card.spellability.SpellAbility;
|
||||||
@@ -1279,14 +1283,70 @@ public class AbilityFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void passUnlessCost(final SpellAbility sa) {
|
||||||
|
Card source = sa.getSourceCard();
|
||||||
|
AbilityFactory af = sa.getAbilityFactory();
|
||||||
|
final HashMap<String,String> params = af.getMapParams();
|
||||||
|
|
||||||
|
//Nothing to do
|
||||||
|
if (params.get("UnlessCost") == null) {
|
||||||
|
sa.resolve();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//The player who has the chance to cancel the ability
|
||||||
|
String pays = params.containsKey("UnlessPayer") ? params.get("UnlessPayer") : "Opponent";
|
||||||
|
Player payer = getDefinedPlayers(sa.getSourceCard(), pays, sa).get(0);
|
||||||
|
|
||||||
|
//The cost
|
||||||
|
String unlessCost = params.get("UnlessCost").trim();
|
||||||
|
if(unlessCost.equals("X"))
|
||||||
|
unlessCost = Integer.toString(CardFactoryUtil.xCount(source, source.getSVar("X")));
|
||||||
|
// Above xCount should probably be changed to a AF.calculateAmount
|
||||||
|
|
||||||
|
Ability ability = new Ability(source, unlessCost) {
|
||||||
|
@Override
|
||||||
|
public void resolve() {
|
||||||
|
;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
final Command unpaidCommand = new Command() {
|
||||||
|
private static final long serialVersionUID = 8094833091127334678L;
|
||||||
|
|
||||||
|
public void execute() {
|
||||||
|
if(params.containsKey("PowerSink")) GameActionUtil.doPowerSink(AllZone.HumanPlayer);
|
||||||
|
sa.resolve();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if(payer.isHuman()) {
|
||||||
|
GameActionUtil.payManaDuringAbilityResolve(source + "\r\n", ability.getManaCost(),
|
||||||
|
Command.Blank, unpaidCommand);
|
||||||
|
} else {
|
||||||
|
if(ComputerUtil.canPayCost(ability)) {
|
||||||
|
ComputerUtil.playNoStack(ability); //Unless cost was payed - no resolve
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if(params.containsKey("PowerSink")) GameActionUtil.doPowerSink(AllZone.ComputerPlayer);
|
||||||
|
sa.resolve();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void resolve(SpellAbility sa) {
|
public static void resolve(SpellAbility sa) {
|
||||||
if (sa == null) return;
|
if (sa == null) return;
|
||||||
AbilityFactory af = sa.getAbilityFactory();
|
AbilityFactory af = sa.getAbilityFactory();
|
||||||
HashMap<String,String> params = af.getMapParams();
|
HashMap<String,String> params = af.getMapParams();
|
||||||
|
|
||||||
|
|
||||||
//check conditions
|
//check conditions
|
||||||
if (AbilityFactory.checkConditional(params, sa))
|
if (AbilityFactory.checkConditional(params, sa)) {
|
||||||
sa.resolve();
|
if (params.get("UnlessCost") == null)
|
||||||
|
sa.resolve();
|
||||||
|
else passUnlessCost(sa);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//try to resolve subabilities (see null check above)
|
//try to resolve subabilities (see null check above)
|
||||||
Ability_Sub abSub = sa.getSubAbility();
|
Ability_Sub abSub = sa.getSubAbility();
|
||||||
|
|||||||
@@ -295,44 +295,7 @@ public class AbilityFactory_CounterMagic {
|
|||||||
Card tgtSACard = tgtSA.getSourceCard();
|
Card tgtSACard = tgtSA.getSourceCard();
|
||||||
if (AllZone.Stack.contains(tgtSA) && !tgtSACard.keywordsContain("CARDNAME can't be countered.")){
|
if (AllZone.Stack.contains(tgtSA) && !tgtSACard.keywordsContain("CARDNAME can't be countered.")){
|
||||||
|
|
||||||
// TODO: Unless Cost should be generalized for all AFS
|
removeFromStack(tgtSA,sa);
|
||||||
if(unlessCost != null) {
|
|
||||||
String unlessCostFinal = unlessCost;
|
|
||||||
if(unlessCost.equals("X"))
|
|
||||||
unlessCostFinal = Integer.toString(CardFactoryUtil.xCount(af.getHostCard(), af.getHostCard().getSVar("X")));
|
|
||||||
// Above xCount should probably be changed to a AF.calculateAmount
|
|
||||||
|
|
||||||
Ability ability = new Ability(af.getHostCard(), unlessCostFinal) {
|
|
||||||
@Override
|
|
||||||
public void resolve() {
|
|
||||||
;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
final Command unpaidCommand = new Command() {
|
|
||||||
private static final long serialVersionUID = 8094833091127334678L;
|
|
||||||
|
|
||||||
public void execute() {
|
|
||||||
removeFromStack(tgtSA, sa);
|
|
||||||
if(params.containsKey("PowerSink")) doPowerSink(AllZone.HumanPlayer);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if(tgtSA.getActivatingPlayer().isHuman()) {
|
|
||||||
GameActionUtil.payManaDuringAbilityResolve(af.getHostCard() + "\r\n", ability.getManaCost(),
|
|
||||||
Command.Blank, unpaidCommand);
|
|
||||||
} else {
|
|
||||||
if(ComputerUtil.canPayCost(ability)) {
|
|
||||||
ComputerUtil.playNoStack(ability);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
removeFromStack(tgtSA,sa);
|
|
||||||
if(params.containsKey("PowerSink")) doPowerSink(AllZone.ComputerPlayer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
removeFromStack(tgtSA,sa);
|
|
||||||
|
|
||||||
// Destroy Permanent may be able to be turned into a SubAbility
|
// Destroy Permanent may be able to be turned into a SubAbility
|
||||||
if(tgtSA.isAbility() && params.containsKey("DestroyPermanent")) {
|
if(tgtSA.isAbility() && params.containsKey("DestroyPermanent")) {
|
||||||
@@ -350,21 +313,6 @@ public class AbilityFactory_CounterMagic {
|
|||||||
}
|
}
|
||||||
}//end counterResolve
|
}//end counterResolve
|
||||||
|
|
||||||
private void doPowerSink(Player p) {
|
|
||||||
//get all lands with mana abilities
|
|
||||||
CardList lands = AllZoneUtil.getPlayerLandsInPlay(p);
|
|
||||||
lands = lands.filter(new CardListFilter() {
|
|
||||||
public boolean addCard(Card c) {
|
|
||||||
return c.getManaAbility().size() > 0;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
//tap them
|
|
||||||
for(Card c:lands) c.tap();
|
|
||||||
|
|
||||||
//empty mana pool
|
|
||||||
if(p.isHuman()) AllZone.ManaPool.clearPool();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String counterStackDescription(AbilityFactory af, SpellAbility sa) {
|
private String counterStackDescription(AbilityFactory af, SpellAbility sa) {
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|||||||
Reference in New Issue
Block a user