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

Method clearPool

forge-game/src/main/java/forge/game/mana/ManaPool.java:119–175  ·  view source on GitHub ↗
(boolean isEndOfPhase)

Source from the content-addressed store, hash-verified

117 }
118
119 public final List<Mana> clearPool(boolean isEndOfPhase) {
120 // isEndOfPhase parameter: true = end of phase, false = mana drain effect
121 List<Mana> cleared = Lists.newArrayList();
122 if (floatingMana.isEmpty()) { return cleared; }
123
124 Byte convertTo = null;
125
126 // TODO move this lower in case all mana would be persistent
127 final Map<AbilityKey, Object> runParams = AbilityKey.mapFromAffected(owner);
128 runParams.put(AbilityKey.Mana, "C");
129 switch (owner.getGame().getReplacementHandler().run(ReplacementType.LoseMana, runParams)) {
130 case NotReplaced:
131 break;
132 case Skipped:
133 return cleared;
134 default:
135 convertTo = ManaAtom.fromName((String) runParams.get(AbilityKey.Mana));
136 break;
137
138 }
139
140 final List<Byte> keys = Lists.newArrayList(floatingMana.keySet());
141 if (isEndOfPhase) {
142 keys.removeAll(StaticAbilityUnspentMana.getManaToKeep(owner));
143 }
144 if (convertTo != null) {
145 keys.remove(convertTo);
146 }
147
148 for (Byte b : keys) {
149 Collection<Mana> cm = floatingMana.get(b);
150 final List<Mana> pMana = Lists.newArrayList();
151 if (isEndOfPhase && !owner.getGame().getPhaseHandler().is(PhaseType.CLEANUP)) {
152 for (final Mana mana : cm) {
153 if (mana.isPersistentMana()) {
154 pMana.add(mana);
155 }
156 if (mana.isCombatMana() && !owner.getGame().getPhaseHandler().is(PhaseType.COMBAT_END)) {
157 pMana.add(mana);
158 }
159 }
160 }
161 cm.removeAll(pMana);
162 if (convertTo != null) {
163 convertManaColor(b, convertTo);
164 cm.addAll(pMana);
165 } else {
166 cleared.addAll(cm);
167 cm.clear();
168 floatingMana.putAll(b, pMana);
169 }
170 }
171
172 owner.updateManaForView();
173 owner.getGame().fireEvent(new GameEventManaPool(owner, EventValueChangeType.Cleared, null));
174 return cleared;
175 }
176

Callers 3

updateManaPoolMethod · 0.80
resolveMethod · 0.80
onPhaseEndMethod · 0.80

Calls 15

mapFromAffectedMethod · 0.95
fromNameMethod · 0.95
getManaToKeepMethod · 0.95
convertManaColorMethod · 0.95
getReplacementHandlerMethod · 0.80
getPhaseHandlerMethod · 0.80
updateManaForViewMethod · 0.80
isEmptyMethod · 0.65
runMethod · 0.65
getGameMethod · 0.65
getMethod · 0.65
isMethod · 0.65

Tested by

no test coverage detected