mirror of
https://github.com/correl/mage.git
synced 2024-11-16 03:00:12 +00:00
Added new Event EMPTY_MANA_POOL. Added selective remove method to ManaPool. New DynamicValue that counts ManaType of ManaPool.
This commit is contained in:
parent
dff4161784
commit
73d7d3d86e
4 changed files with 94 additions and 2 deletions
|
@ -0,0 +1,71 @@
|
||||||
|
package mage.abilities.dynamicvalue.common;
|
||||||
|
|
||||||
|
import mage.Constants.ManaType;
|
||||||
|
import mage.abilities.Ability;
|
||||||
|
import mage.abilities.dynamicvalue.DynamicValue;
|
||||||
|
import mage.game.Game;
|
||||||
|
import mage.players.Player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author LevelX2
|
||||||
|
*/
|
||||||
|
public class ManaTypeInManaPoolCount implements DynamicValue {
|
||||||
|
|
||||||
|
private ManaType manaType;
|
||||||
|
|
||||||
|
public ManaTypeInManaPoolCount(ManaType manaType) {
|
||||||
|
this.manaType = manaType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ManaTypeInManaPoolCount(final ManaTypeInManaPoolCount dynamicValue) {
|
||||||
|
this.manaType = dynamicValue.manaType;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int calculate(Game game, Ability sourceAbility) {
|
||||||
|
int amount = 0;
|
||||||
|
Player player = game.getPlayer(sourceAbility.getControllerId());
|
||||||
|
if (player != null) {
|
||||||
|
amount = player.getManaPool().get(manaType);
|
||||||
|
}
|
||||||
|
return amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DynamicValue clone() {
|
||||||
|
return new ManaTypeInManaPoolCount(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "1";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMessage() {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
switch (manaType) {
|
||||||
|
case BLACK:
|
||||||
|
sb.append("black");
|
||||||
|
break;
|
||||||
|
case GREEN:
|
||||||
|
sb.append("green");
|
||||||
|
break;
|
||||||
|
case RED:
|
||||||
|
sb.append("red");
|
||||||
|
break;
|
||||||
|
case BLUE:
|
||||||
|
sb.append("blue");
|
||||||
|
break;
|
||||||
|
case WHITE:
|
||||||
|
sb.append("white");
|
||||||
|
break;
|
||||||
|
case COLORLESS:
|
||||||
|
sb.append("colorless");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
sb.append(" mana in your mana pool");
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
}
|
|
@ -789,10 +789,12 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
|
||||||
public void emptyManaPools() {
|
public void emptyManaPools() {
|
||||||
if (!replaceEvent(new GameEvent(GameEvent.EventType.EMPTY_MANA_POOLS, null, null, null))) {
|
if (!replaceEvent(new GameEvent(GameEvent.EventType.EMPTY_MANA_POOLS, null, null, null))) {
|
||||||
for (Player player: getPlayers().values()) {
|
for (Player player: getPlayers().values()) {
|
||||||
|
if (!replaceEvent(new GameEvent(GameEvent.EventType.EMPTY_MANA_POOL, player.getId(), null, player.getId()))) {
|
||||||
player.getManaPool().emptyPool();
|
player.getManaPool().emptyPool();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void applyEffects() {
|
public synchronized void applyEffects() {
|
||||||
|
|
|
@ -74,7 +74,7 @@ public class GameEvent {
|
||||||
END_PHASE, END_PHASE_PRE, END_PHASE_POST,
|
END_PHASE, END_PHASE_PRE, END_PHASE_POST,
|
||||||
END_TURN_STEP_PRE, END_TURN_STEP, END_TURN_STEP_POST,
|
END_TURN_STEP_PRE, END_TURN_STEP, END_TURN_STEP_POST,
|
||||||
CLEANUP_STEP_PRE, CLEANUP_STEP, CLEANUP_STEP_POST,
|
CLEANUP_STEP_PRE, CLEANUP_STEP, CLEANUP_STEP_POST,
|
||||||
EMPTY_MANA_POOLS,
|
EMPTY_MANA_POOLS, EMPTY_MANA_POOL,
|
||||||
AT_END_OF_TURN,
|
AT_END_OF_TURN,
|
||||||
|
|
||||||
//player events
|
//player events
|
||||||
|
|
|
@ -38,6 +38,7 @@ import mage.game.Game;
|
||||||
import mage.game.events.GameEvent;
|
import mage.game.events.GameEvent;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.lang.reflect.Array;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -129,6 +130,24 @@ public class ManaPool implements Serializable {
|
||||||
return get(ManaType.COLORLESS);
|
return get(ManaType.COLORLESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int emptyManaType(List<ManaType> manaTypeArray) {
|
||||||
|
int total = count();
|
||||||
|
Iterator<ManaPoolItem> it = manaItems.iterator();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
ManaPoolItem item = it.next();
|
||||||
|
for (ManaType manaType: manaTypeArray) {
|
||||||
|
if (item.get(manaType) > 0) {
|
||||||
|
total += item.get(manaType);
|
||||||
|
item.remove(manaType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (item.count() == 0) {
|
||||||
|
it.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
public int emptyPool() {
|
public int emptyPool() {
|
||||||
int total = count();
|
int total = count();
|
||||||
manaItems.clear();
|
manaItems.clear();
|
||||||
|
|
Loading…
Reference in a new issue