mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 04:08:01 +00:00
Support updating mana for player view
This commit is contained in:
@@ -53,20 +53,9 @@ import java.util.List;
|
||||
* @version $Id$
|
||||
*/
|
||||
public class ManaPool implements Iterable<Mana> {
|
||||
|
||||
private final Player owner;
|
||||
private final Multimap<Byte, Mana> floatingMana = ArrayListMultimap.create();
|
||||
|
||||
/** Constant <code>map</code>. */
|
||||
private final Player owner;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Constructor for ManaPool.
|
||||
* </p>
|
||||
*
|
||||
* @param player
|
||||
* a {@link forge.game.player.Player} object.
|
||||
*/
|
||||
public ManaPool(final Player player) {
|
||||
owner = player;
|
||||
restoreColorReplacements();
|
||||
@@ -79,20 +68,13 @@ public class ManaPool implements Iterable<Mana> {
|
||||
|
||||
public void addMana(final Mana mana) {
|
||||
floatingMana.put(mana.getColor(), mana);
|
||||
owner.updateManaForView();
|
||||
owner.getGame().fireEvent(new GameEventManaPool(owner, EventValueChangeType.Added, mana));
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* addManaToFloating.
|
||||
* </p>
|
||||
*
|
||||
* @param manaList
|
||||
* a {@link java.util.ArrayList} object.
|
||||
*/
|
||||
public final void add(final Iterable<Mana> manaList) {
|
||||
for (final Mana m : manaList) {
|
||||
this.addMana(m);
|
||||
addMana(m);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,17 +103,9 @@ public class ManaPool implements Iterable<Mana> {
|
||||
if (totalMana() == safeMana) {
|
||||
return false; //won't lose floating mana if all mana is of colors that aren't going to be emptied
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* clearPool.
|
||||
*
|
||||
* @return - the amount of mana removed this way
|
||||
* </p>
|
||||
*/
|
||||
public final List<Mana> clearPool(boolean isEndOfPhase) {
|
||||
// isEndOfPhase parameter: true = end of phase, false = mana drain effect
|
||||
List<Mana> cleared = new ArrayList<Mana>();
|
||||
@@ -157,75 +131,62 @@ public class ManaPool implements Iterable<Mana> {
|
||||
}
|
||||
|
||||
for (Byte b : keys) {
|
||||
Collection<Mana> cm = floatingMana.get(b);
|
||||
if (isEndOfPhase && !owner.getGame().getPhaseHandler().is(PhaseType.CLEANUP)) {
|
||||
final List<Mana> pMana = new ArrayList<Mana>();
|
||||
for (final Mana mana : floatingMana.get(b)) {
|
||||
for (final Mana mana : cm) {
|
||||
if (mana.getManaAbility()!= null && mana.getManaAbility().isPersistentMana()) {
|
||||
pMana.add(mana);
|
||||
}
|
||||
}
|
||||
floatingMana.get(b).removeAll(pMana);
|
||||
cm.removeAll(pMana);
|
||||
if (convertToColorless) {
|
||||
convertManaColor(b, MagicColor.COLORLESS);
|
||||
floatingMana.get(b).addAll(pMana);
|
||||
} else {
|
||||
cleared.addAll(floatingMana.get(b));
|
||||
floatingMana.get(b).clear();
|
||||
cm.addAll(pMana);
|
||||
}
|
||||
else {
|
||||
cleared.addAll(cm);
|
||||
cm.clear();
|
||||
floatingMana.putAll(b, pMana);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (convertToColorless) {
|
||||
convertManaColor(b, MagicColor.COLORLESS);
|
||||
} else {
|
||||
cleared.addAll(floatingMana.get(b));
|
||||
floatingMana.get(b).clear();
|
||||
}
|
||||
else {
|
||||
cleared.addAll(cm);
|
||||
cm.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
owner.updateManaForView();
|
||||
owner.getGame().fireEvent(new GameEventManaPool(owner, EventValueChangeType.Cleared, null));
|
||||
return cleared;
|
||||
}
|
||||
|
||||
private void convertManaColor(final byte originalColor, final byte toColor) {
|
||||
List<Mana> convert = new ArrayList<Mana>();
|
||||
for (Mana m : floatingMana.get(originalColor)) {
|
||||
Collection<Mana> cm = floatingMana.get(originalColor);
|
||||
for (Mana m : cm) {
|
||||
convert.add(new Mana(toColor, m.getSourceCard(), m.getManaAbility()));
|
||||
}
|
||||
floatingMana.get(originalColor).clear();
|
||||
cm.clear();
|
||||
floatingMana.putAll(toColor, convert);
|
||||
owner.updateManaForView();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* removeManaFrom.
|
||||
* </p>
|
||||
*
|
||||
* @param mana
|
||||
* a {@link forge.game.mana.Mana} object.
|
||||
*/
|
||||
private void removeMana(final Mana mana) {
|
||||
Collection<Mana> cm = floatingMana.get(mana.getColor());
|
||||
if (cm.remove(mana)) {
|
||||
owner.updateManaForView();
|
||||
owner.getGame().fireEvent(new GameEventManaPool(owner, EventValueChangeType.Removed, mana));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* subtractManaFromAbility.
|
||||
* </p>
|
||||
*
|
||||
* @param saPaidFor
|
||||
* a {@link forge.game.spellability.SpellAbility} object.
|
||||
* @param manaCost
|
||||
* a {@link forge.game.mana.ManaCostBeingPaid} object.
|
||||
* @return a {@link forge.game.mana.ManaCostBeingPaid} object.
|
||||
*/
|
||||
|
||||
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 = saPaidFor.getPayingManaAbilities();
|
||||
AbilityManaPart abManaPart = saPayment.getManaPartRecursive();
|
||||
|
||||
@@ -240,9 +201,9 @@ public class ManaPool implements Iterable<Mana> {
|
||||
public boolean tryPayCostWithColor(byte colorCode, SpellAbility saPaidFor, ManaCostBeingPaid manaCost) {
|
||||
Mana manaFound = null;
|
||||
String restriction = manaCost.getSourceRestriction();
|
||||
Collection<Mana> coloredMana = this.floatingMana.get(colorCode);
|
||||
Collection<Mana> cm = floatingMana.get(colorCode);
|
||||
|
||||
for (final Mana mana : coloredMana) {
|
||||
for (final Mana mana : cm) {
|
||||
if (mana.getManaAbility() != null && !mana.getManaAbility().meetsManaRestrictions(saPaidFor)) {
|
||||
continue;
|
||||
}
|
||||
@@ -254,12 +215,12 @@ public class ManaPool implements Iterable<Mana> {
|
||||
manaFound = mana;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
boolean result = manaFound != null && tryPayCostWithMana(saPaidFor, manaCost, manaFound);
|
||||
if(result)
|
||||
|
||||
if (manaFound != null && tryPayCostWithMana(saPaidFor, manaCost, manaFound)) {
|
||||
saPaidFor.getPayingMana().add(0, manaFound);
|
||||
return result;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean tryPayCostWithMana(final SpellAbility sa, ManaCostBeingPaid manaCost, final Mana mana) {
|
||||
@@ -267,7 +228,7 @@ public class ManaPool implements Iterable<Mana> {
|
||||
return false;
|
||||
}
|
||||
manaCost.payMana(mana, this);
|
||||
this.removeMana(mana);
|
||||
removeMana(mana);
|
||||
if (mana.addsNoCounterMagic(sa) && sa.getHostCard() != null) {
|
||||
sa.getHostCard().setCanCounter(false);
|
||||
}
|
||||
@@ -312,13 +273,6 @@ public class ManaPool implements Iterable<Mana> {
|
||||
return floatingMana.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* totalMana.
|
||||
* </p>
|
||||
*
|
||||
* @return a int.
|
||||
*/
|
||||
public final int totalMana() {
|
||||
return floatingMana.values().size();
|
||||
}
|
||||
@@ -328,7 +282,7 @@ public class ManaPool implements Iterable<Mana> {
|
||||
if (ma == null) {
|
||||
return false;
|
||||
}
|
||||
if (this.floatingMana.isEmpty()) {
|
||||
if (floatingMana.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -337,7 +291,7 @@ public class ManaPool implements Iterable<Mana> {
|
||||
boolean manaNotAccountedFor = false;
|
||||
// loop over mana produced by mana ability
|
||||
for (Mana mana : ma.getLastManaProduced()) {
|
||||
Collection<Mana> poolLane = this.floatingMana.get(mana.getColor());
|
||||
Collection<Mana> poolLane = floatingMana.get(mana.getColor());
|
||||
|
||||
if (poolLane != null && poolLane.contains(mana)) {
|
||||
removeFloating.add(mana);
|
||||
@@ -355,7 +309,7 @@ public class ManaPool implements Iterable<Mana> {
|
||||
}
|
||||
|
||||
for (int k = 0; k < removeFloating.size(); k++) {
|
||||
this.removeMana(removeFloating.get(k));
|
||||
removeMana(removeFloating.get(k));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -369,7 +323,7 @@ public class ManaPool implements Iterable<Mana> {
|
||||
sa.getHostCard().setCanCounter(true);
|
||||
}
|
||||
for (final Mana m : manaPaid) {
|
||||
this.addMana(m);
|
||||
addMana(m);
|
||||
}
|
||||
manaPaid.clear();
|
||||
|
||||
@@ -381,7 +335,7 @@ public class ManaPool implements Iterable<Mana> {
|
||||
|
||||
for (final SpellAbility am : payingAbilities) {
|
||||
// Recursively refund abilities that were used.
|
||||
this.refundManaPaid(am);
|
||||
refundManaPaid(am);
|
||||
}
|
||||
|
||||
payingAbilities.clear();
|
||||
@@ -401,18 +355,21 @@ public class ManaPool implements Iterable<Mana> {
|
||||
// Fix the index without hardcodes
|
||||
int rowIdx = MagicColor.getIndexOfFirstColor(originalColor);
|
||||
rowIdx = rowIdx < 0 ? identityMatrix.length - 1 : rowIdx;
|
||||
if (additive)
|
||||
if (additive) {
|
||||
colorConversionMatrix[rowIdx] |= replacementColor;
|
||||
else
|
||||
}
|
||||
else {
|
||||
colorRestrictionMatrix[rowIdx] &= replacementColor;
|
||||
}
|
||||
}
|
||||
|
||||
public void restoreColorReplacements() {
|
||||
for(int i = 0; i < colorConversionMatrix.length; i++)
|
||||
colorConversionMatrix[i] = identityMatrix[i];
|
||||
|
||||
for(int i = 0; i < colorRestrictionMatrix.length; i++)
|
||||
public void restoreColorReplacements() {
|
||||
for (int i = 0; i < colorConversionMatrix.length; i++) {
|
||||
colorConversionMatrix[i] = identityMatrix[i];
|
||||
}
|
||||
for (int i = 0; i < colorRestrictionMatrix.length; i++) {
|
||||
colorRestrictionMatrix[i] = MagicColor.ALL_COLORS;
|
||||
}
|
||||
}
|
||||
|
||||
public byte getPossibleColorUses(byte color) {
|
||||
@@ -427,10 +384,11 @@ public class ManaPool implements Iterable<Mana> {
|
||||
|
||||
public boolean canPayForShardWithColor(ManaCostShard shard, byte color) {
|
||||
byte line = getPossibleColorUses(color);
|
||||
for(int i = 0; i < MagicColor.NUMBER_OR_COLORS; i++) {
|
||||
for (int i = 0; i < MagicColor.NUMBER_OR_COLORS; i++) {
|
||||
byte outColor = MagicColor.WUBRG[i];
|
||||
if (( line & outColor) != 0 && shard.canBePaidWithManaOfColor(outColor))
|
||||
if ((line & outColor) != 0 && shard.canBePaidWithManaOfColor(outColor)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return shard.canBePaidWithManaOfColor((byte)0);
|
||||
}
|
||||
|
||||
@@ -1424,6 +1424,9 @@ public class Player extends GameEntity implements Comparable<Player> {
|
||||
public final ManaPool getManaPool() {
|
||||
return manaPool;
|
||||
}
|
||||
public void updateManaForView() {
|
||||
view.updateMana(this);
|
||||
}
|
||||
|
||||
public final int getNumPowerSurgeLands() {
|
||||
return numPowerSurgeLands;
|
||||
|
||||
Reference in New Issue
Block a user