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