mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 12:18:00 +00:00
I believe this would break ai's mana payment
This commit is contained in:
@@ -46,11 +46,11 @@ public class ComputerUtilMana {
|
|||||||
|
|
||||||
public static boolean canPayManaCost(ManaCostBeingPaid cost, final SpellAbility sa, final Player ai) {
|
public static boolean canPayManaCost(ManaCostBeingPaid cost, final SpellAbility sa, final Player ai) {
|
||||||
cost = new ManaCostBeingPaid(cost); //check copy of cost so it doesn't modify the exist cost being paid
|
cost = new ManaCostBeingPaid(cost); //check copy of cost so it doesn't modify the exist cost being paid
|
||||||
return payManaCost(cost, sa, ai, true, 0, true, true);
|
return payManaCost(cost, sa, ai, true, 0, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean payManaCost(ManaCostBeingPaid cost, final SpellAbility sa, final Player ai) {
|
public static boolean payManaCost(ManaCostBeingPaid cost, final SpellAbility sa, final Player ai) {
|
||||||
return payManaCost(cost, sa, ai, false, 0, true, false);
|
return payManaCost(cost, sa, ai, false, 0, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean canPayManaCost(final SpellAbility sa, final Player ai, final int extraMana) {
|
public static boolean canPayManaCost(final SpellAbility sa, final Player ai, final int extraMana) {
|
||||||
@@ -67,6 +67,17 @@ public class ComputerUtilMana {
|
|||||||
return payManaCost(sa, ai, false, 0, true);
|
return payManaCost(sa, ai, false, 0, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void refundMana(List<Mana> manaSpent, Player ai, SpellAbility sa) {
|
||||||
|
if (sa.getHostCard() != null) {
|
||||||
|
sa.getHostCard().setCanCounter(true);
|
||||||
|
}
|
||||||
|
for (final Mana m : manaSpent) {
|
||||||
|
ai.getManaPool().addMana(m);
|
||||||
|
}
|
||||||
|
manaSpent.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* payManaCost.
|
* payManaCost.
|
||||||
@@ -87,11 +98,12 @@ public class ComputerUtilMana {
|
|||||||
*/
|
*/
|
||||||
private static boolean payManaCost(final SpellAbility sa, final Player ai, final boolean test, final int extraMana, boolean checkPlayable) {
|
private static boolean payManaCost(final SpellAbility sa, final Player ai, final boolean test, final int extraMana, boolean checkPlayable) {
|
||||||
ManaCostBeingPaid cost = ComputerUtilMana.calculateManaCost(sa, test, extraMana);
|
ManaCostBeingPaid cost = ComputerUtilMana.calculateManaCost(sa, test, extraMana);
|
||||||
return payManaCost(cost, sa, ai, test, extraMana, checkPlayable, true);
|
return payManaCost(cost, sa, ai, test, extraMana, checkPlayable);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean payManaCost(final ManaCostBeingPaid cost, final SpellAbility sa, final Player ai, final boolean test, final int extraMana, boolean checkPlayable, boolean clearManaPaid) {
|
private static boolean payManaCost(final ManaCostBeingPaid cost, final SpellAbility sa, final Player ai, final boolean test, final int extraMana, boolean checkPlayable) {
|
||||||
adjustManaCostToAvoidNegEffects(cost, sa.getHostCard(), ai);
|
adjustManaCostToAvoidNegEffects(cost, sa.getHostCard(), ai);
|
||||||
|
List<Mana> manaSpentToPay = test ? new ArrayList<Mana>() : sa.getPayingMana();
|
||||||
|
|
||||||
final ManaPool manapool = ai.getManaPool();
|
final ManaPool manapool = ai.getManaPool();
|
||||||
List<ManaCostShard> unpaidShards = cost.getUnpaidShards();
|
List<ManaCostShard> unpaidShards = cost.getUnpaidShards();
|
||||||
@@ -108,17 +120,18 @@ public class ComputerUtilMana {
|
|||||||
continue; // no matching mana in the pool
|
continue; // no matching mana in the pool
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if ( ai.getManaPool().tryPayCostWithMana(sa, cost, mana) && !test)
|
if (ai.getManaPool().tryPayCostWithMana(sa, cost, mana)) {
|
||||||
sa.getPayingMana().add(mana);
|
manaSpentToPay.add(mana);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cost.isPaid()) {
|
if (cost.isPaid()) {
|
||||||
// refund any mana taken from mana pool when test
|
// refund any mana taken from mana pool when test
|
||||||
if (clearManaPaid) {
|
if(test)
|
||||||
manapool.clearManaPaid(sa, test);
|
refundMana(manaSpentToPay, ai, sa);
|
||||||
}
|
|
||||||
handleOfferingsAI(sa, test, cost.isPaid());
|
handleOfferingsAI(sa, test, cost.isPaid());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -126,9 +139,8 @@ public class ComputerUtilMana {
|
|||||||
// arrange all mana abilities by color produced.
|
// arrange all mana abilities by color produced.
|
||||||
final Multimap<Integer, SpellAbility> manaAbilityMap = ComputerUtilMana.groupSourcesByManaColor(ai, checkPlayable);
|
final Multimap<Integer, SpellAbility> manaAbilityMap = ComputerUtilMana.groupSourcesByManaColor(ai, checkPlayable);
|
||||||
if (manaAbilityMap.isEmpty()) {
|
if (manaAbilityMap.isEmpty()) {
|
||||||
if (clearManaPaid) {
|
refundMana(manaSpentToPay, ai, sa);
|
||||||
manapool.clearManaPaid(sa, test);
|
|
||||||
}
|
|
||||||
handleOfferingsAI(sa, test, cost.isPaid());
|
handleOfferingsAI(sa, test, cost.isPaid());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -236,9 +248,6 @@ public class ComputerUtilMana {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (clearManaPaid) {
|
|
||||||
manapool.clearManaPaid(sa, test);
|
|
||||||
}
|
|
||||||
handleOfferingsAI(sa, test, cost.isPaid());
|
handleOfferingsAI(sa, test, cost.isPaid());
|
||||||
|
|
||||||
// if (DEBUG_MANA_PAYMENT) {
|
// if (DEBUG_MANA_PAYMENT) {
|
||||||
@@ -248,6 +257,7 @@ public class ComputerUtilMana {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
if (!cost.isPaid()) {
|
if (!cost.isPaid()) {
|
||||||
|
refundMana(manaSpentToPay, ai, sa);
|
||||||
if (test) {
|
if (test) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -257,6 +267,9 @@ public class ComputerUtilMana {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (test)
|
||||||
|
refundMana(manaSpentToPay, ai, sa);
|
||||||
|
|
||||||
sa.getHostCard().setColorsPaid(cost.getColorsPaid());
|
sa.getHostCard().setColorsPaid(cost.getColorsPaid());
|
||||||
// if (sa instanceof Spell_Permanent) // should probably add this
|
// if (sa instanceof Spell_Permanent) // should probably add this
|
||||||
sa.getHostCard().setSunburstValue(cost.getSunburst());
|
sa.getHostCard().setSunburstValue(cost.getSunburst());
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ public class CostPartMana extends CostPart {
|
|||||||
@Override
|
@Override
|
||||||
public boolean payAsDecided(Player payer, PaymentDecision pd, SpellAbility sa) {
|
public boolean payAsDecided(Player payer, PaymentDecision pd, SpellAbility sa) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
payer.getManaPool().clearManaPaid(sa, false);
|
sa.clearManaPaid();
|
||||||
|
|
||||||
// decision not used here, the whole payment is interactive!
|
// decision not used here, the whole payment is interactive!
|
||||||
return payer.getController().payManaCost(this, sa);
|
return payer.getController().payManaCost(this, sa);
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ public class ManaPool implements Iterable<Mana> {
|
|||||||
return ofColor == null ? 0 : ofColor.size();
|
return ofColor == null ? 0 : ofColor.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addMana(final Mana mana) {
|
public void addMana(final Mana mana) {
|
||||||
floatingMana.put(mana.getColor(), mana);
|
floatingMana.put(mana.getColor(), mana);
|
||||||
owner.getGame().fireEvent(new GameEventManaPool(owner, EventValueChangeType.Added, mana));
|
owner.getGame().fireEvent(new GameEventManaPool(owner, EventValueChangeType.Added, mana));
|
||||||
}
|
}
|
||||||
@@ -233,31 +233,6 @@ public class ManaPool implements Iterable<Mana> {
|
|||||||
return floatingMana.values().size();
|
return floatingMana.values().size();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* clearPay.
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @param ability
|
|
||||||
* a {@link forge.game.spellability.SpellAbility} object.
|
|
||||||
* @param refund
|
|
||||||
* a boolean.
|
|
||||||
*/
|
|
||||||
public final void clearManaPaid(final SpellAbility ability, final boolean refund) {
|
|
||||||
final List<Mana> manaPaid = ability.getPayingMana();
|
|
||||||
ability.getPayingManaAbilities().clear();
|
|
||||||
// move non-undoable paying mana back to floating
|
|
||||||
if (refund) {
|
|
||||||
if (ability.getHostCard() != null) {
|
|
||||||
ability.getHostCard().setCanCounter(true);
|
|
||||||
}
|
|
||||||
for (final Mana m : manaPaid) {
|
|
||||||
this.addMana(m);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
manaPaid.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
//Account for mana part of ability when undoing it
|
//Account for mana part of ability when undoing it
|
||||||
public boolean accountFor(final AbilityManaPart ma) {
|
public boolean accountFor(final AbilityManaPart ma) {
|
||||||
if (ma == null) {
|
if (ma == null) {
|
||||||
|
|||||||
@@ -480,6 +480,10 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit
|
|||||||
return this.payingMana;
|
return this.payingMana;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final void clearManaPaid() {
|
||||||
|
payingMana.clear();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* getPayingManaAbilities.
|
* getPayingManaAbilities.
|
||||||
|
|||||||
@@ -82,8 +82,6 @@ public class InputPayManaSimple extends InputPayMana {
|
|||||||
player.payLife(this.phyLifeToLose, this.originalCard);
|
player.payLife(this.phyLifeToLose, this.originalCard);
|
||||||
}
|
}
|
||||||
if (!this.saPaidFor.getHostCard().isCopiedSpell()) {
|
if (!this.saPaidFor.getHostCard().isCopiedSpell()) {
|
||||||
player.getManaPool().clearManaPaid(this.saPaidFor, false);
|
|
||||||
|
|
||||||
if (this.saPaidFor.isSpell()) {
|
if (this.saPaidFor.isSpell()) {
|
||||||
this.saPaidFor.setHostCard(game.getAction().moveToStack(this.originalCard));
|
this.saPaidFor.setHostCard(game.getAction().moveToStack(this.originalCard));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -627,7 +627,7 @@ public class HumanPlay {
|
|||||||
prompt = source + "\n" + promptCurrent;
|
prompt = source + "\n" + promptCurrent;
|
||||||
}
|
}
|
||||||
|
|
||||||
p.getManaPool().clearManaPaid(sourceAbility, false);
|
sourceAbility.clearManaPaid();
|
||||||
boolean paid = p.getController().payManaCost(cost.getCostMana(), sourceAbility);
|
boolean paid = p.getController().payManaCost(cost.getCostMana(), sourceAbility);
|
||||||
if (!paid) {
|
if (!paid) {
|
||||||
p.getManaPool().refundManaPaid(sourceAbility);
|
p.getManaPool().refundManaPaid(sourceAbility);
|
||||||
|
|||||||
Reference in New Issue
Block a user