mirror of
https://github.com/correl/mage.git
synced 2024-12-25 11:11:16 +00:00
created events for adding counters to players
This commit is contained in:
parent
a15e4bdb54
commit
cd81f4197d
12 changed files with 39 additions and 17 deletions
|
@ -92,7 +92,7 @@ class PoisonControllerEffect extends OneShotEffect<PoisonControllerEffect> {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
Player player = game.getPlayer(source.getControllerId());
|
||||
if (player != null) {
|
||||
player.getCounters().addCounter(CounterType.POISON.createInstance());
|
||||
player.addCounters(CounterType.POISON.createInstance(), game);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -102,7 +102,7 @@ class PoisonControllerTargetCreatureEffect extends OneShotEffect<PoisonControlle
|
|||
if (p != null) {
|
||||
Player player = game.getPlayer(p.getControllerId());
|
||||
if (player != null) {
|
||||
player.getCounters().addCounter(CounterType.POISON.createInstance());
|
||||
player.addCounters(CounterType.POISON.createInstance(), game);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -164,7 +164,7 @@ class VirulentWoundDelayedEffect extends OneShotEffect<VirulentWoundDelayedEffec
|
|||
if (permanent != null) {
|
||||
Player player = game.getPlayer(permanent.getControllerId());
|
||||
if (player != null) {
|
||||
player.getCounters().addCounter(CounterType.POISON.createInstance(1));
|
||||
player.addCounters(CounterType.POISON.createInstance(1), game);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ class IchorRatsEffect extends OneShotEffect<IchorRatsEffect> {
|
|||
for (UUID playerId : game.getPlayerList()) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player != null) {
|
||||
player.getCounters().addCounter(CounterType.POISON.createInstance());
|
||||
player.addCounters(CounterType.POISON.createInstance(), game);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -66,7 +66,7 @@ public class AddPoisonCounterTargetEffect extends OneShotEffect<AddPoisonCounter
|
|||
public boolean apply(Game game, Ability source) {
|
||||
Player player = game.getPlayer(targetPointer.getFirst(source));
|
||||
if (player != null) {
|
||||
player.getCounters().addCounter(CounterType.POISON.createInstance(amount));
|
||||
player.addCounters(CounterType.POISON.createInstance(amount), game);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -81,7 +81,7 @@ public class AddCountersControllerEffect extends OneShotEffect<AddCountersContro
|
|||
}
|
||||
Player player = game.getPlayer(uuid);
|
||||
if (player != null) {
|
||||
player.getCounters().addCounter(counter);
|
||||
player.addCounters(counter, game);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -70,7 +70,7 @@ public class AddCountersTargetEffect extends OneShotEffect<AddCountersTargetEffe
|
|||
} else {
|
||||
Player player = game.getPlayer(uuid);
|
||||
if (player != null) {
|
||||
player.getCounters().addCounter(counter.copy());
|
||||
player.addCounters(counter.copy(), game);
|
||||
affectedTargets ++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -105,7 +105,8 @@ public class ProliferateEffect extends OneShotEffect<ProliferateEffect> {
|
|||
if (player.getCounters().size() > 0) {
|
||||
if (player.getCounters().size() == 1) {
|
||||
for (Counter counter : player.getCounters().values()) {
|
||||
player.getCounters().addCounter(counter.getName(), 1);
|
||||
Counter newCounter = new Counter(counter.getName(), 1);
|
||||
player.addCounters(newCounter, game);
|
||||
}
|
||||
} else {
|
||||
Choice choice = new ChoiceImpl(true);
|
||||
|
@ -118,7 +119,8 @@ public class ProliferateEffect extends OneShotEffect<ProliferateEffect> {
|
|||
controller.choose(Outcome.Benefit, choice, game);
|
||||
for (Counter counter : player.getCounters().values()) {
|
||||
if (counter.getName().equals(choice.getChoice())) {
|
||||
player.getCounters().addCounter(counter.getName(), 1);
|
||||
Counter newCounter = new Counter(counter.getName(), 1);
|
||||
player.addCounters(newCounter, game);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -149,7 +149,14 @@ public class GameEvent {
|
|||
return new GameEvent(type, targetId, null, playerId);
|
||||
}
|
||||
|
||||
public EventType getType() {
|
||||
public static GameEvent getEvent(EventType type, UUID targetId, UUID playerId, String data, int amount) {
|
||||
GameEvent event = getEvent(type, targetId,playerId);
|
||||
event.setAmount(amount);
|
||||
event.setData(data);
|
||||
return event;
|
||||
}
|
||||
|
||||
public EventType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
|
|
|
@ -177,17 +177,18 @@ public abstract class PermanentImpl<T extends PermanentImpl<T>> extends CardImpl
|
|||
|
||||
@Override
|
||||
public void addCounters(String name, int amount, Game game) {
|
||||
if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.ADD_COUNTER, objectId, controllerId))) {
|
||||
GameEvent event = GameEvent.getEvent(GameEvent.EventType.ADD_COUNTER, objectId, controllerId, name, amount);
|
||||
if (!game.replaceEvent(event)) {
|
||||
counters.addCounter(name, amount);
|
||||
game.fireEvent(GameEvent.getEvent(EventType.COUNTER_ADDED, objectId, controllerId));
|
||||
game.fireEvent(GameEvent.getEvent(EventType.COUNTER_ADDED, objectId, controllerId, name, amount));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCounters(Counter counter, Game game) {
|
||||
if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.ADD_COUNTER, objectId, controllerId))) {
|
||||
if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.ADD_COUNTER, objectId, controllerId, counter.getName(), counter.getCount()))) {
|
||||
counters.addCounter(counter);
|
||||
game.fireEvent(GameEvent.getEvent(EventType.COUNTER_ADDED, objectId, controllerId));
|
||||
game.fireEvent(GameEvent.getEvent(EventType.COUNTER_ADDED, objectId, controllerId, counter.getName(), counter.getCount()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -53,6 +53,7 @@ import mage.cards.Card;
|
|||
import mage.cards.Cards;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.choices.Choice;
|
||||
import mage.counters.Counter;
|
||||
import mage.counters.Counters;
|
||||
import mage.filter.FilterAbility;
|
||||
import mage.game.events.GameEvent;
|
||||
|
@ -67,7 +68,6 @@ import mage.target.TargetAmount;
|
|||
import mage.target.TargetCard;
|
||||
import mage.target.common.TargetCardInLibrary;
|
||||
import mage.util.Copyable;
|
||||
import org.w3c.dom.UserDataHandler;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -238,4 +238,6 @@ public interface Player extends MageItem, Copyable<Player> {
|
|||
public List<Ability> getPlayable(Game game, FilterAbility filter, ManaOptions available, boolean hidden);
|
||||
public List<Ability> getPlayableOptions(Ability ability, Game game);
|
||||
|
||||
public void addCounters(Counter counter, Game game);
|
||||
|
||||
}
|
||||
|
|
|
@ -55,6 +55,7 @@ import mage.cards.Card;
|
|||
import mage.cards.Cards;
|
||||
import mage.cards.CardsImpl;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.counters.Counter;
|
||||
import mage.counters.CounterType;
|
||||
import mage.counters.Counters;
|
||||
import mage.filter.FilterAbility;
|
||||
|
@ -65,6 +66,7 @@ import mage.game.events.DamagePlayerEvent;
|
|||
import mage.game.events.DamagedPlayerEvent;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.events.GameEvent.EventType;
|
||||
import mage.game.stack.StackAbility;
|
||||
import mage.players.net.UserData;
|
||||
import mage.target.common.TargetCardInLibrary;
|
||||
|
@ -758,7 +760,7 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser
|
|||
if (actualDamage > 0) {
|
||||
Permanent source = game.getPermanent(sourceId);
|
||||
if (source != null && (source.getAbilities().containsKey(InfectAbility.getInstance().getId()))) {
|
||||
getCounters().addCounter(CounterType.POISON.createInstance(actualDamage));
|
||||
addCounters(CounterType.POISON.createInstance(actualDamage), game);
|
||||
} else {
|
||||
// fixed: damage dealt should not be equal to life lost
|
||||
// actualDamage = this.loseLife(actualDamage, game);
|
||||
|
@ -776,7 +778,15 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser
|
|||
return 0;
|
||||
}
|
||||
|
||||
protected boolean canDamage(MageObject source) {
|
||||
@Override
|
||||
public void addCounters(Counter counter, Game game) {
|
||||
if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.ADD_COUNTER, playerId, playerId, counter.getName(), counter.getCount()))) {
|
||||
counters.addCounter(counter);
|
||||
game.fireEvent(GameEvent.getEvent(EventType.COUNTER_ADDED, playerId, playerId, counter.getName(), counter.getCount()));
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean canDamage(MageObject source) {
|
||||
for (ProtectionAbility ability: abilities.getProtectionAbilities()) {
|
||||
if (!ability.canTarget(source))
|
||||
return false;
|
||||
|
|
Loading…
Reference in a new issue