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.
|
* subtractManaFromAbility.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param sa
|
* @param saPaidFor
|
||||||
* a {@link forge.card.spellability.SpellAbility} object.
|
* a {@link forge.card.spellability.SpellAbility} object.
|
||||||
* @param manaCost
|
* @param manaCost
|
||||||
* a {@link forge.card.mana.ManaCostBeingPaid} object.
|
* a {@link forge.card.mana.ManaCostBeingPaid} object.
|
||||||
* @param ma
|
* @param saPayment
|
||||||
* a {@link forge.card.spellability.AbilityMana} object.
|
* a {@link forge.card.spellability.AbilityMana} object.
|
||||||
* @return a {@link forge.card.mana.ManaCostBeingPaid} 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
|
// Mana restriction must be checked before this method is called
|
||||||
|
|
||||||
final List<SpellAbility> paidAbs = sa.getPayingManaAbilities();
|
final List<SpellAbility> paidAbs = saPaidFor.getPayingManaAbilities();
|
||||||
SpellAbility tail = ma;
|
AbilityManaPart abManaPart = saPayment.getManaPartRecursive();
|
||||||
AbilityManaPart abManaPart = null;
|
|
||||||
while(abManaPart == null && tail != null) {
|
|
||||||
abManaPart = tail.getManaPart();
|
|
||||||
tail = tail.getSubAbility();
|
|
||||||
}
|
|
||||||
|
|
||||||
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()) {
|
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;
|
return manaPart;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean isManaAbility() {
|
public final AbilityManaPart getManaPartRecursive() {
|
||||||
SpellAbility tail = this;
|
SpellAbility tail = this;
|
||||||
boolean manaProducing = false;
|
while (tail != null) {
|
||||||
// Check whether spell or ability first
|
if(tail.manaPart != null)
|
||||||
if (this.isSpell()) {
|
return tail.manaPart;
|
||||||
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.
|
|
||||||
}
|
|
||||||
|
|
||||||
tail = tail.getSubAbility();
|
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) {
|
protected final void setManaPart(AbilityManaPart manaPart) {
|
||||||
|
|||||||
@@ -117,15 +117,10 @@ public abstract class InputPayManaBase extends InputSyncronizedBase implements I
|
|||||||
for (SpellAbility ma : card.getManaAbility()) {
|
for (SpellAbility ma : card.getManaAbility()) {
|
||||||
ma.setActivatingPlayer(player);
|
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 (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 (ma.isAbility() && ma.getRestrictions().isInstantSpeed()) continue;
|
||||||
if (!m.meetsManaRestrictions(saPaidFor)) continue;
|
if (!m.meetsManaRestrictions(saPaidFor)) continue;
|
||||||
|
|
||||||
@@ -165,7 +160,7 @@ public abstract class InputPayManaBase extends InputSyncronizedBase implements I
|
|||||||
// express Mana Choice
|
// express Mana Choice
|
||||||
final ArrayList<SpellAbility> colorMatches = new ArrayList<SpellAbility>();
|
final ArrayList<SpellAbility> colorMatches = new ArrayList<SpellAbility>();
|
||||||
for (SpellAbility sa : abilities) {
|
for (SpellAbility sa : abilities) {
|
||||||
if (colorNeeded != 0 && abilityProducesManaColor(sa, colorNeeded))
|
if (colorNeeded != 0 && abilityProducesManaColor(sa, sa.getManaPartRecursive(), colorNeeded))
|
||||||
colorMatches.add(sa);
|
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);
|
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);
|
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");
|
// System.out.println("Chosen sa=" + chosen + " of " + chosen.getSourceCard() + " to pay mana");
|
||||||
Runnable proc = new Runnable() {
|
Runnable proc = new Runnable() {
|
||||||
@@ -213,11 +202,10 @@ public abstract class InputPayManaBase extends InputSyncronizedBase implements I
|
|||||||
* a {@link java.lang.String} object.
|
* a {@link java.lang.String} object.
|
||||||
* @return a boolean.
|
* @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) {
|
if (neededColor == 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
AbilityManaPart m = am.getManaPart();
|
|
||||||
|
|
||||||
if (m.isAnyMana()) {
|
if (m.isAnyMana()) {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -214,7 +214,9 @@ public class ComputerUtilMana {
|
|||||||
|
|
||||||
private static void setExpressColorChoice(final SpellAbility sa, final Player ai, ManaCostBeingPaid cost,
|
private static void setExpressColorChoice(final SpellAbility sa, final Player ai, ManaCostBeingPaid cost,
|
||||||
ManaCostShard toPay, SpellAbility saPayment) {
|
ManaCostShard toPay, SpellAbility saPayment) {
|
||||||
if ( saPayment.getManaPart().isComboMana() )
|
|
||||||
|
AbilityManaPart m = saPayment.getManaPart();
|
||||||
|
if ( m.isComboMana() )
|
||||||
getComboManaChoice(ai, saPayment, sa, cost);
|
getComboManaChoice(ai, saPayment, sa, cost);
|
||||||
else if (saPayment.getApi() == ApiType.ManaReflected) {
|
else if (saPayment.getApi() == ApiType.ManaReflected) {
|
||||||
System.out.println("Evaluate reflected mana of: " + saPayment.getSourceCard());
|
System.out.println("Evaluate reflected mana of: " + saPayment.getSourceCard());
|
||||||
@@ -222,11 +224,11 @@ public class ComputerUtilMana {
|
|||||||
|
|
||||||
for(byte c : MagicColor.WUBRG) {
|
for(byte c : MagicColor.WUBRG) {
|
||||||
if (toPay.canBePaidWithManaOfColor(c) && reflected.contains(MagicColor.toLongString(c))) {
|
if (toPay.canBePaidWithManaOfColor(c) && reflected.contains(MagicColor.toLongString(c))) {
|
||||||
saPayment.getManaPart().setExpressChoice(MagicColor.toShortString(c));
|
m.setExpressChoice(MagicColor.toShortString(c));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if ( saPayment.getManaPart().isAnyMana()) {
|
} else if ( m.isAnyMana()) {
|
||||||
byte colorChoice = 0;
|
byte colorChoice = 0;
|
||||||
if (toPay.isOr2Colorless())
|
if (toPay.isOr2Colorless())
|
||||||
colorChoice = toPay.getColorMask();
|
colorChoice = toPay.getColorMask();
|
||||||
@@ -236,7 +238,7 @@ public class ComputerUtilMana {
|
|||||||
break;
|
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
|
manaMap.add(ManaAtom.COLORLESS, m); // add to colorless source list
|
||||||
|
AbilityManaPart mp = m.getManaPart();
|
||||||
|
|
||||||
Set<String> reflectedColors = CardUtil.getReflectableManaColors(m);
|
Set<String> reflectedColors = CardUtil.getReflectableManaColors(m);
|
||||||
// find possible colors
|
// 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);
|
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);
|
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);
|
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);
|
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);
|
manaMap.add(ManaAtom.GREEN, m);
|
||||||
}
|
}
|
||||||
if (m.getManaPart().isSnow()) {
|
if (mp.isSnow()) {
|
||||||
manaMap.add(ManaAtom.IS_SNOW, m);
|
manaMap.add(ManaAtom.IS_SNOW, m);
|
||||||
}
|
}
|
||||||
} // end of mana abilities loop
|
} // end of mana abilities loop
|
||||||
|
|||||||
@@ -170,14 +170,8 @@ public class EventVisualizer {
|
|||||||
for (SpellAbility sa : manaProduced) {
|
for (SpellAbility sa : manaProduced) {
|
||||||
|
|
||||||
// Find mana ability if it is somewhere in tail
|
// 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")) {
|
if (manaColors.contains("B")) {
|
||||||
return SoundEffectType.BlackLand;
|
return SoundEffectType.BlackLand;
|
||||||
|
|||||||
Reference in New Issue
Block a user