mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 03:38:01 +00:00
SA: added getManaPartRecursive(), replaced loops where they were
This commit is contained in:
@@ -249,28 +249,23 @@ public class ManaPool {
|
||||
* subtractManaFromAbility.
|
||||
* </p>
|
||||
*
|
||||
* @param sa
|
||||
* @param saPaidFor
|
||||
* a {@link forge.card.spellability.SpellAbility} object.
|
||||
* @param manaCost
|
||||
* a {@link forge.card.mana.ManaCostBeingPaid} object.
|
||||
* @param ma
|
||||
* @param saPayment
|
||||
* a {@link forge.card.spellability.AbilityMana} object.
|
||||
* @return a {@link forge.card.mana.ManaCostBeingPaid} object.
|
||||
*/
|
||||
public final void payManaFromAbility(final SpellAbility sa, ManaCostBeingPaid manaCost, final SpellAbility ma) {
|
||||
public final void payManaFromAbility(final SpellAbility saPaidFor, ManaCostBeingPaid manaCost, final SpellAbility saPayment) {
|
||||
// Mana restriction must be checked before this method is called
|
||||
|
||||
final List<SpellAbility> paidAbs = sa.getPayingManaAbilities();
|
||||
SpellAbility tail = ma;
|
||||
AbilityManaPart abManaPart = null;
|
||||
while(abManaPart == null && tail != null) {
|
||||
abManaPart = tail.getManaPart();
|
||||
tail = tail.getSubAbility();
|
||||
}
|
||||
final List<SpellAbility> paidAbs = saPaidFor.getPayingManaAbilities();
|
||||
AbilityManaPart abManaPart = saPayment.getManaPartRecursive();
|
||||
|
||||
paidAbs.add(ma); // assumes some part on the mana produced by the ability will get used
|
||||
paidAbs.add(saPayment); // assumes some part on the mana produced by the ability will get used
|
||||
for (final Mana mana : abManaPart.getLastManaProduced()) {
|
||||
tryPayCostWithMana(sa, manaCost, mana);
|
||||
tryPayCostWithMana(saPaidFor, manaCost, mana);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -113,33 +113,25 @@ public abstract class SpellAbility implements ISpellAbility {
|
||||
return manaPart;
|
||||
}
|
||||
|
||||
public final boolean isManaAbility() {
|
||||
public final AbilityManaPart getManaPartRecursive() {
|
||||
SpellAbility tail = this;
|
||||
boolean manaProducing = false;
|
||||
// Check whether spell or ability first
|
||||
if (this.isSpell()) {
|
||||
return false;
|
||||
}
|
||||
if(getRestrictions() != null)
|
||||
{
|
||||
if(getRestrictions().getPlaneswalker())
|
||||
{
|
||||
return false; //Loyalty ability, not a mana ability.
|
||||
}
|
||||
}
|
||||
while(tail != null) {
|
||||
if(tail.getTarget() != null) {
|
||||
return false; //Targeted ability,not a mana ability.
|
||||
}
|
||||
if(tail.getManaPart() != null)
|
||||
{
|
||||
manaProducing = true; //Can add mana to a players mana pool, possible mana ability.
|
||||
}
|
||||
|
||||
while (tail != null) {
|
||||
if(tail.manaPart != null)
|
||||
return tail.manaPart;
|
||||
tail = tail.getSubAbility();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
return manaProducing;
|
||||
public final boolean isManaAbility() {
|
||||
// Check whether spell or ability first
|
||||
if (this.isSpell())
|
||||
return false;
|
||||
|
||||
if(getRestrictions() != null && getRestrictions().getPlaneswalker())
|
||||
return false; //Loyalty ability, not a mana ability.
|
||||
|
||||
return getManaPartRecursive() != null;
|
||||
}
|
||||
|
||||
protected final void setManaPart(AbilityManaPart manaPart) {
|
||||
|
||||
@@ -117,15 +117,10 @@ public abstract class InputPayManaBase extends InputSyncronizedBase implements I
|
||||
for (SpellAbility ma : card.getManaAbility()) {
|
||||
ma.setActivatingPlayer(player);
|
||||
|
||||
AbilityManaPart m = null;
|
||||
SpellAbility tail = ma;
|
||||
while (m == null && tail != null) {
|
||||
m = tail.getManaPart();
|
||||
tail = tail.getSubAbility();
|
||||
}
|
||||
|
||||
AbilityManaPart m = ma.getManaPartRecursive();
|
||||
if (m == null || !ma.canPlay()) continue;
|
||||
if (!canUseColorless && !abilityProducesManaColor(ma, colorCanUse)) continue;
|
||||
if (!canUseColorless && !abilityProducesManaColor(ma, m, colorCanUse)) continue;
|
||||
if (ma.isAbility() && ma.getRestrictions().isInstantSpeed()) continue;
|
||||
if (!m.meetsManaRestrictions(saPaidFor)) continue;
|
||||
|
||||
@@ -165,7 +160,7 @@ public abstract class InputPayManaBase extends InputSyncronizedBase implements I
|
||||
// express Mana Choice
|
||||
final ArrayList<SpellAbility> colorMatches = new ArrayList<SpellAbility>();
|
||||
for (SpellAbility sa : abilities) {
|
||||
if (colorNeeded != 0 && abilityProducesManaColor(sa, colorNeeded))
|
||||
if (colorNeeded != 0 && abilityProducesManaColor(sa, sa.getManaPartRecursive(), colorNeeded))
|
||||
colorMatches.add(sa);
|
||||
}
|
||||
|
||||
@@ -180,14 +175,8 @@ public abstract class InputPayManaBase extends InputSyncronizedBase implements I
|
||||
}
|
||||
|
||||
final SpellAbility chosen = abilities.size() > 1 && choice ? GuiChoose.one("Choose mana ability", abilities) : abilities.get(0);
|
||||
SpellAbility subchosen = chosen;
|
||||
while(subchosen.getManaPart() == null)
|
||||
{
|
||||
subchosen = subchosen.getSubAbility();
|
||||
}
|
||||
|
||||
ColorSet colors = ColorSet.fromMask(0 == colorNeeded ? colorCanUse : colorNeeded);
|
||||
subchosen.getManaPart().setExpressChoice(colors);
|
||||
chosen.getManaPartRecursive().setExpressChoice(colors);
|
||||
|
||||
// System.out.println("Chosen sa=" + chosen + " of " + chosen.getSourceCard() + " to pay mana");
|
||||
Runnable proc = new Runnable() {
|
||||
@@ -213,11 +202,10 @@ public abstract class InputPayManaBase extends InputSyncronizedBase implements I
|
||||
* a {@link java.lang.String} object.
|
||||
* @return a boolean.
|
||||
*/
|
||||
private static boolean abilityProducesManaColor(final SpellAbility am, final byte neededColor) {
|
||||
private static boolean abilityProducesManaColor(final SpellAbility am, AbilityManaPart m, final byte neededColor) {
|
||||
if (neededColor == 0) {
|
||||
return true;
|
||||
}
|
||||
AbilityManaPart m = am.getManaPart();
|
||||
|
||||
if (m.isAnyMana()) {
|
||||
return true;
|
||||
|
||||
@@ -214,7 +214,9 @@ public class ComputerUtilMana {
|
||||
|
||||
private static void setExpressColorChoice(final SpellAbility sa, final Player ai, ManaCostBeingPaid cost,
|
||||
ManaCostShard toPay, SpellAbility saPayment) {
|
||||
if ( saPayment.getManaPart().isComboMana() )
|
||||
|
||||
AbilityManaPart m = saPayment.getManaPart();
|
||||
if ( m.isComboMana() )
|
||||
getComboManaChoice(ai, saPayment, sa, cost);
|
||||
else if (saPayment.getApi() == ApiType.ManaReflected) {
|
||||
System.out.println("Evaluate reflected mana of: " + saPayment.getSourceCard());
|
||||
@@ -222,11 +224,11 @@ public class ComputerUtilMana {
|
||||
|
||||
for(byte c : MagicColor.WUBRG) {
|
||||
if (toPay.canBePaidWithManaOfColor(c) && reflected.contains(MagicColor.toLongString(c))) {
|
||||
saPayment.getManaPart().setExpressChoice(MagicColor.toShortString(c));
|
||||
m.setExpressChoice(MagicColor.toShortString(c));
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else if ( saPayment.getManaPart().isAnyMana()) {
|
||||
} else if ( m.isAnyMana()) {
|
||||
byte colorChoice = 0;
|
||||
if (toPay.isOr2Colorless())
|
||||
colorChoice = toPay.getColorMask();
|
||||
@@ -236,7 +238,7 @@ public class ComputerUtilMana {
|
||||
break;
|
||||
}
|
||||
}
|
||||
saPayment.getManaPart().setExpressChoice(MagicColor.toShortString(colorChoice));
|
||||
m.setExpressChoice(MagicColor.toShortString(colorChoice));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -625,25 +627,26 @@ public class ComputerUtilMana {
|
||||
}
|
||||
|
||||
manaMap.add(ManaAtom.COLORLESS, m); // add to colorless source list
|
||||
AbilityManaPart mp = m.getManaPart();
|
||||
|
||||
Set<String> reflectedColors = CardUtil.getReflectableManaColors(m);
|
||||
// find possible colors
|
||||
if (m.getManaPart().canProduce("W") || reflectedColors.contains(Constant.Color.WHITE)) {
|
||||
if (mp.canProduce("W") || reflectedColors.contains(Constant.Color.WHITE)) {
|
||||
manaMap.add(ManaAtom.WHITE, m);
|
||||
}
|
||||
if (m.getManaPart().canProduce("U") || reflectedColors.contains(Constant.Color.BLUE)) {
|
||||
if (mp.canProduce("U") || reflectedColors.contains(Constant.Color.BLUE)) {
|
||||
manaMap.add(ManaAtom.BLUE, m);
|
||||
}
|
||||
if (m.getManaPart().canProduce("B") || reflectedColors.contains(Constant.Color.BLACK)) {
|
||||
if (mp.canProduce("B") || reflectedColors.contains(Constant.Color.BLACK)) {
|
||||
manaMap.add(ManaAtom.BLACK, m);
|
||||
}
|
||||
if (m.getManaPart().canProduce("R") || reflectedColors.contains(Constant.Color.RED)) {
|
||||
if (mp.canProduce("R") || reflectedColors.contains(Constant.Color.RED)) {
|
||||
manaMap.add(ManaAtom.RED, m);
|
||||
}
|
||||
if (m.getManaPart().canProduce("G") || reflectedColors.contains(Constant.Color.GREEN)) {
|
||||
if (mp.canProduce("G") || reflectedColors.contains(Constant.Color.GREEN)) {
|
||||
manaMap.add(ManaAtom.GREEN, m);
|
||||
}
|
||||
if (m.getManaPart().isSnow()) {
|
||||
if (mp.isSnow()) {
|
||||
manaMap.add(ManaAtom.IS_SNOW, m);
|
||||
}
|
||||
} // end of mana abilities loop
|
||||
|
||||
@@ -170,14 +170,8 @@ public class EventVisualizer {
|
||||
for (SpellAbility sa : manaProduced) {
|
||||
|
||||
// Find mana ability if it is somewhere in tail
|
||||
SpellAbility tail = sa;
|
||||
AbilityManaPart m = null;
|
||||
while (m == null && tail != null) {
|
||||
m = tail.getManaPart();
|
||||
tail = tail.getSubAbility();
|
||||
}
|
||||
|
||||
String manaColors = m.getOrigProduced();
|
||||
String manaColors = sa.getManaPartRecursive().getOrigProduced();
|
||||
|
||||
if (manaColors.contains("B")) {
|
||||
return SoundEffectType.BlackLand;
|
||||
|
||||
Reference in New Issue
Block a user