MCPcopy Create free account
hub / github.com/Card-Forge/forge / ManaPool

Class ManaPool

forge-game/src/main/java/forge/game/mana/ManaPool.java:49–372  ·  view source on GitHub ↗

ManaPool class. @author Forge @version $Id$

Source from the content-addressed store, hash-verified

47 * @version $Id$
48 */
49public class ManaPool extends ManaConversionMatrix implements Iterable<Mana> {
50 private final Player owner;
51 private final ArrayListMultimap<Byte, Mana> floatingMana = ArrayListMultimap.create();
52
53 public ManaPool(final Player player) {
54 owner = player;
55 restoreColorReplacements();
56 }
57
58 public final int getAmountOfColor(final byte color) {
59 Collection<Mana> ofColor = floatingMana.get(color);
60 return ofColor == null ? 0 : ofColor.size();
61 }
62
63 public void addManaNoEvent(final Mana mana) {
64 floatingMana.put(mana.getColor(), mana);
65 }
66
67 public final void addMana(final Mana... manaList) {
68 addMana(Arrays.asList(manaList));
69 }
70 public final void addMana(final Iterable<Mana> manaList) {
71 Set<MagicColor.Color> colors = EnumSet.noneOf(MagicColor.Color.class);
72 for (final Mana m : manaList) {
73 floatingMana.put(m.getColor(), m);
74 colors.add(MagicColor.Color.fromByte(m.getColor()));
75 }
76 if (!colors.isEmpty()) {
77 owner.updateManaForView();
78 owner.getGame().fireEvent(new GameEventManaPool(owner, EventValueChangeType.Added, colors));
79 }
80 }
81
82 /**
83 * <p>
84 * willManaBeLostAtEndOfPhase.
85 *
86 * @return - whether floating mana will be lost if the current phase ended right now
87 * </p>
88 */
89 public final boolean willManaBeLostAtEndOfPhase() {
90 if (floatingMana.isEmpty()) {
91 return false;
92 }
93
94 final Map<AbilityKey, Object> runParams = AbilityKey.mapFromAffected(owner);
95 if (!owner.getGame().getReplacementHandler().getReplacementList(ReplacementType.LoseMana, runParams, ReplacementLayer.Other).isEmpty()) {
96 return false;
97 }
98
99 int safeMana = 0;
100 for (final byte c : StaticAbilityUnspentMana.getManaToKeep(owner)) {
101 safeMana += getAmountOfColor(c);
102 }
103
104 // TODO isPersistentMana
105
106 return totalMana() != safeMana; //won't lose floating mana if all mana is of colors that aren't going to be emptied

Callers

nothing calls this directly

Calls 1

createMethod · 0.65

Tested by

no test coverage detected