mirror of
https://github.com/correl/mage.git
synced 2024-12-25 11:11:16 +00:00
added events for adding counters
This commit is contained in:
parent
f69d9fae83
commit
18064114e0
18 changed files with 38 additions and 26 deletions
|
@ -46,7 +46,6 @@ import mage.abilities.effects.common.counter.AddCountersSourceEffect;
|
||||||
import mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect;
|
import mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect;
|
||||||
import mage.cards.CardImpl;
|
import mage.cards.CardImpl;
|
||||||
import mage.counters.CounterType;
|
import mage.counters.CounterType;
|
||||||
import mage.counters.common.PlusOneCounter;
|
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.events.GameEvent;
|
import mage.game.events.GameEvent;
|
||||||
import mage.game.events.GameEvent.EventType;
|
import mage.game.events.GameEvent.EventType;
|
||||||
|
@ -96,7 +95,7 @@ public class ProteanHydra extends CardImpl<ProteanHydra> {
|
||||||
Permanent permanent = game.getPermanent(source.getSourceId());
|
Permanent permanent = game.getPermanent(source.getSourceId());
|
||||||
if (permanent != null && source.getManaCostsToPay().getVariableCosts().size() > 0) {
|
if (permanent != null && source.getManaCostsToPay().getVariableCosts().size() > 0) {
|
||||||
int amount = source.getManaCostsToPay().getVariableCosts().get(0).getAmount();
|
int amount = source.getManaCostsToPay().getVariableCosts().get(0).getAmount();
|
||||||
permanent.addCounters(new PlusOneCounter(amount));
|
permanent.addCounters(CounterType.P1P1.createInstance(amount), game);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -141,7 +140,7 @@ public class ProteanHydra extends CardImpl<ProteanHydra> {
|
||||||
}
|
}
|
||||||
Permanent permanent = game.getPermanent(source.getSourceId());
|
Permanent permanent = game.getPermanent(source.getSourceId());
|
||||||
if (permanent != null) {
|
if (permanent != null) {
|
||||||
permanent.removeCounters("+1/+1", damage, game);
|
permanent.removeCounters(CounterType.P1P1.createInstance(damage), game);
|
||||||
}
|
}
|
||||||
return retValue;
|
return retValue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,6 @@ import mage.game.Game;
|
||||||
import mage.game.events.GameEvent;
|
import mage.game.events.GameEvent;
|
||||||
import mage.game.permanent.Permanent;
|
import mage.game.permanent.Permanent;
|
||||||
import mage.players.Player;
|
import mage.players.Player;
|
||||||
import mage.target.TargetPermanent;
|
|
||||||
import mage.target.common.TargetControlledPermanent;
|
import mage.target.common.TargetControlledPermanent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -140,7 +139,7 @@ class PhylacteryLichEffect extends OneShotEffect<PhylacteryLichEffect> {
|
||||||
if (player.choose(Outcome.Neutral, target, game)) {
|
if (player.choose(Outcome.Neutral, target, game)) {
|
||||||
Permanent permanent = game.getPermanent(target.getFirstTarget());
|
Permanent permanent = game.getPermanent(target.getFirstTarget());
|
||||||
if (permanent != null) {
|
if (permanent != null) {
|
||||||
permanent.addCounters(new Counter("phylactery"));
|
permanent.addCounters(new Counter("phylactery"), game);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,7 +81,7 @@ class BlackSunsZenithEffect extends OneShotEffect<BlackSunsZenithEffect> {
|
||||||
int amount = source.getManaCostsToPay().getVariableCosts().get(0).getAmount();
|
int amount = source.getManaCostsToPay().getVariableCosts().get(0).getAmount();
|
||||||
for (Permanent permanent : game.getBattlefield().getAllActivePermanents()) {
|
for (Permanent permanent : game.getBattlefield().getAllActivePermanents()) {
|
||||||
if (permanent != null && permanent.getCardType().contains(CardType.CREATURE)) {
|
if (permanent != null && permanent.getCardType().contains(CardType.CREATURE)) {
|
||||||
permanent.addCounters(CounterType.M1M1.createInstance(amount));
|
permanent.addCounters(CounterType.M1M1.createInstance(amount), game);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -96,7 +96,7 @@ class GlisteningOilEffect extends OneShotEffect<GlisteningOilEffect> {
|
||||||
if (enchantment != null && enchantment.getAttachedTo() != null) {
|
if (enchantment != null && enchantment.getAttachedTo() != null) {
|
||||||
Permanent creature = game.getPermanent(enchantment.getAttachedTo());
|
Permanent creature = game.getPermanent(enchantment.getAttachedTo());
|
||||||
if (creature != null) {
|
if (creature != null) {
|
||||||
creature.addCounters(CounterType.M1M1.createInstance());
|
creature.addCounters(CounterType.M1M1.createInstance(), game);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -94,7 +94,7 @@ class CarnifexDemonEffect extends OneShotEffect<CarnifexDemonEffect> {
|
||||||
if (p != null) {
|
if (p != null) {
|
||||||
for (Permanent t : game.getBattlefield().getAllActivePermanents()) {
|
for (Permanent t : game.getBattlefield().getAllActivePermanents()) {
|
||||||
if (t.getCardType().contains(CardType.CREATURE) && !t.getId().equals(source.getSourceId()))
|
if (t.getCardType().contains(CardType.CREATURE) && !t.getId().equals(source.getSourceId()))
|
||||||
t.addCounters(CounterType.M1M1.createInstance());
|
t.addCounters(CounterType.M1M1.createInstance(), game);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -94,7 +94,7 @@ class ChimericMassEffect extends OneShotEffect<ChimericMassEffect> {
|
||||||
int amount = source.getManaCostsToPay().getVariableCosts().get(0).getAmount();
|
int amount = source.getManaCostsToPay().getVariableCosts().get(0).getAmount();
|
||||||
Permanent p = game.getPermanent(source.getSourceId());
|
Permanent p = game.getPermanent(source.getSourceId());
|
||||||
if (p != null) {
|
if (p != null) {
|
||||||
p.addCounters(CounterType.CHARGE.createInstance(amount));
|
p.addCounters(CounterType.CHARGE.createInstance(amount), game);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -92,7 +92,7 @@ class ContagionEngineEffect extends OneShotEffect<ContagionEngineEffect> {
|
||||||
Player target = game.getPlayer(source.getFirstTarget());
|
Player target = game.getPlayer(source.getFirstTarget());
|
||||||
if (target != null) {
|
if (target != null) {
|
||||||
for (Permanent p : game.getBattlefield().getAllActivePermanents(new FilterCreaturePermanent(), target.getId())) {
|
for (Permanent p : game.getBattlefield().getAllActivePermanents(new FilterCreaturePermanent(), target.getId())) {
|
||||||
p.getCounters().addCounter(CounterType.M1M1.createInstance());
|
p.addCounters(CounterType.M1M1.createInstance(), game);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,7 +87,7 @@ class SigilOfDistinctionEffect extends OneShotEffect<SigilOfDistinctionEffect> {
|
||||||
int amount = source.getManaCostsToPay().getVariableCosts().get(0).getAmount();
|
int amount = source.getManaCostsToPay().getVariableCosts().get(0).getAmount();
|
||||||
Permanent p = game.getPermanent(source.getSourceId());
|
Permanent p = game.getPermanent(source.getSourceId());
|
||||||
if (p != null) {
|
if (p != null) {
|
||||||
p.addCounters(CounterType.CHARGE.createInstance(amount));
|
p.addCounters(CounterType.CHARGE.createInstance(amount), game);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -40,6 +40,7 @@ import mage.abilities.costs.common.TapSourceCost;
|
||||||
import mage.abilities.effects.OneShotEffect;
|
import mage.abilities.effects.OneShotEffect;
|
||||||
import mage.abilities.mana.GreenManaAbility;
|
import mage.abilities.mana.GreenManaAbility;
|
||||||
import mage.cards.CardImpl;
|
import mage.cards.CardImpl;
|
||||||
|
import mage.counters.CounterType;
|
||||||
import mage.counters.common.PlusOneCounter;
|
import mage.counters.common.PlusOneCounter;
|
||||||
import mage.filter.Filter;
|
import mage.filter.Filter;
|
||||||
import mage.filter.FilterPermanent;
|
import mage.filter.FilterPermanent;
|
||||||
|
@ -96,7 +97,7 @@ class OranRiefTheVastwoodEffect extends OneShotEffect<OranRiefTheVastwoodEffect>
|
||||||
filter.setUseColor(true);
|
filter.setUseColor(true);
|
||||||
for (Permanent permanent: game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game)) {
|
for (Permanent permanent: game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game)) {
|
||||||
if (permanent.getTurnsOnBattlefield() == 0) {
|
if (permanent.getTurnsOnBattlefield() == 0) {
|
||||||
permanent.addCounters(new PlusOneCounter());
|
permanent.addCounters(CounterType.P1P1.createInstance(), game);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -67,7 +67,7 @@ public class AddCountersAllEffect extends OneShotEffect<AddCountersAllEffect> {
|
||||||
List<Permanent> permanents = game.getBattlefield().getAllActivePermanents();
|
List<Permanent> permanents = game.getBattlefield().getAllActivePermanents();
|
||||||
for (Permanent permanent : permanents) {
|
for (Permanent permanent : permanents) {
|
||||||
if (filter.match(permanent, source.getSourceId(), controllerId, game)) {
|
if (filter.match(permanent, source.getSourceId(), controllerId, game)) {
|
||||||
permanent.addCounters(counter.copy());
|
permanent.addCounters(counter.copy(), game);
|
||||||
applied = true;
|
applied = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@ public class AddCountersSourceEffect extends OneShotEffect<AddCountersSourceEffe
|
||||||
Permanent permanent = game.getPermanent(source.getSourceId());
|
Permanent permanent = game.getPermanent(source.getSourceId());
|
||||||
if (permanent != null) {
|
if (permanent != null) {
|
||||||
if (counter != null) {
|
if (counter != null) {
|
||||||
permanent.addCounters(counter.copy());
|
permanent.addCounters(counter.copy(), game);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -64,7 +64,7 @@ public class AddCountersTargetEffect extends OneShotEffect<AddCountersTargetEffe
|
||||||
Permanent permanent = game.getPermanent(uuid);
|
Permanent permanent = game.getPermanent(uuid);
|
||||||
if (permanent != null) {
|
if (permanent != null) {
|
||||||
if (counter != null) {
|
if (counter != null) {
|
||||||
permanent.addCounters(counter.copy());
|
permanent.addCounters(counter.copy(), game);
|
||||||
affectedTargets ++;
|
affectedTargets ++;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -65,7 +65,7 @@ public class AddPlusOneCountersAttachedEffect extends OneShotEffect<AddPlusOneCo
|
||||||
if (enchantment != null && enchantment.getAttachedTo() != null) {
|
if (enchantment != null && enchantment.getAttachedTo() != null) {
|
||||||
Permanent creature = game.getPermanent(enchantment.getAttachedTo());
|
Permanent creature = game.getPermanent(enchantment.getAttachedTo());
|
||||||
if (creature != null) {
|
if (creature != null) {
|
||||||
creature.addCounters(new PlusOneCounter(amount));
|
creature.addCounters(new PlusOneCounter(amount), game);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -80,7 +80,7 @@ public class ProliferateEffect extends OneShotEffect<ProliferateEffect> {
|
||||||
if (permanent.getCounters().size() > 0) {
|
if (permanent.getCounters().size() > 0) {
|
||||||
if (permanent.getCounters().size() == 1) {
|
if (permanent.getCounters().size() == 1) {
|
||||||
for (Counter counter : permanent.getCounters().values()) {
|
for (Counter counter : permanent.getCounters().values()) {
|
||||||
permanent.getCounters().addCounter(counter.getName(), 1);
|
permanent.addCounters(counter.getName(), 1, game);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Choice choice = new ChoiceImpl(true);
|
Choice choice = new ChoiceImpl(true);
|
||||||
|
@ -93,7 +93,7 @@ public class ProliferateEffect extends OneShotEffect<ProliferateEffect> {
|
||||||
controller.choose(Outcome.Benefit, choice, game);
|
controller.choose(Outcome.Benefit, choice, game);
|
||||||
for (Counter counter : permanent.getCounters().values()) {
|
for (Counter counter : permanent.getCounters().values()) {
|
||||||
if (counter.getName().equals(choice.getChoice())) {
|
if (counter.getName().equals(choice.getChoice())) {
|
||||||
permanent.getCounters().addCounter(counter.getName(), 1);
|
permanent.addCounters(counter.getName(), 1, game);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ class BloodthirstEffect extends OneShotEffect<BloodthirstEffect> {
|
||||||
if (watcher.conditionMet()) {
|
if (watcher.conditionMet()) {
|
||||||
Permanent p = game.getPermanent(source.getSourceId());
|
Permanent p = game.getPermanent(source.getSourceId());
|
||||||
if (p != null) {
|
if (p != null) {
|
||||||
p.addCounters(CounterType.P1P1.createInstance(amount));
|
p.addCounters(CounterType.P1P1.createInstance(amount), game);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -110,6 +110,7 @@ public class GameEvent {
|
||||||
SACRIFICE_PERMANENT, SACRIFICED_PERMANENT,
|
SACRIFICE_PERMANENT, SACRIFICED_PERMANENT,
|
||||||
ATTACH, ATTACHED,
|
ATTACH, ATTACHED,
|
||||||
UNATTACH, UNATTACHED,
|
UNATTACH, UNATTACHED,
|
||||||
|
ADD_COUNTER, COUNTER_ADDED,
|
||||||
COUNTER_REMOVED,
|
COUNTER_REMOVED,
|
||||||
LOSE_CONTROL, LOST_CONTROL,
|
LOSE_CONTROL, LOST_CONTROL,
|
||||||
GAIN_CONTROL, GAINED_CONTROL,
|
GAIN_CONTROL, GAINED_CONTROL,
|
||||||
|
|
|
@ -77,9 +77,10 @@ public interface Permanent extends Card {
|
||||||
public int damage(int damage, UUID sourceId, Game game, boolean preventable, boolean combat);
|
public int damage(int damage, UUID sourceId, Game game, boolean preventable, boolean combat);
|
||||||
public void removeAllDamage(Game game);
|
public void removeAllDamage(Game game);
|
||||||
public Counters getCounters();
|
public Counters getCounters();
|
||||||
public void addCounters(String name, int amount);
|
public void addCounters(String name, int amount, Game game);
|
||||||
public void addCounters(Counter counter);
|
public void addCounters(Counter counter, Game game);
|
||||||
public void removeCounters(String name, int amount, Game game);
|
public void removeCounters(String name, int amount, Game game);
|
||||||
|
public void removeCounters(Counter counter, Game game);
|
||||||
public void reset(Game game);
|
public void reset(Game game);
|
||||||
public boolean destroy(UUID sourceId, Game game, boolean noRegen);
|
public boolean destroy(UUID sourceId, Game game, boolean noRegen);
|
||||||
public boolean sacrifice(UUID sourceId, Game game);
|
public boolean sacrifice(UUID sourceId, Game game);
|
||||||
|
|
|
@ -157,13 +157,19 @@ public abstract class PermanentImpl<T extends PermanentImpl<T>> extends CardImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addCounters(String name, int amount) {
|
public void addCounters(String name, int amount, Game game) {
|
||||||
counters.addCounter(name, amount);
|
if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.ADD_COUNTER, objectId, controllerId))) {
|
||||||
|
counters.addCounter(name, amount);
|
||||||
|
game.fireEvent(GameEvent.getEvent(EventType.COUNTER_ADDED, objectId, controllerId));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addCounters(Counter counter) {
|
public void addCounters(Counter counter, Game game) {
|
||||||
counters.addCounter(counter);
|
if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.ADD_COUNTER, objectId, controllerId))) {
|
||||||
|
counters.addCounter(counter);
|
||||||
|
game.fireEvent(GameEvent.getEvent(EventType.COUNTER_ADDED, objectId, controllerId));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -175,6 +181,11 @@ public abstract class PermanentImpl<T extends PermanentImpl<T>> extends CardImpl
|
||||||
game.fireEvent(event);
|
game.fireEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeCounters(Counter counter, Game game) {
|
||||||
|
removeCounters(counter.getName(), counter.getCount(), game);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getTurnsOnBattlefield() {
|
public int getTurnsOnBattlefield() {
|
||||||
return turnsOnBattlefield;
|
return turnsOnBattlefield;
|
||||||
|
@ -533,7 +544,7 @@ public abstract class PermanentImpl<T extends PermanentImpl<T>> extends CardImpl
|
||||||
Permanent source = game.getPermanent(sourceId);
|
Permanent source = game.getPermanent(sourceId);
|
||||||
if (source != null && (source.getAbilities().containsKey(InfectAbility.getInstance().getId())
|
if (source != null && (source.getAbilities().containsKey(InfectAbility.getInstance().getId())
|
||||||
|| source.getAbilities().containsKey(WitherAbility.getInstance().getId()))) {
|
|| source.getAbilities().containsKey(WitherAbility.getInstance().getId()))) {
|
||||||
addCounters(CounterType.M1M1.createInstance(actualDamage));
|
addCounters(CounterType.M1M1.createInstance(actualDamage), game);
|
||||||
} else {
|
} else {
|
||||||
this.damage += actualDamage;
|
this.damage += actualDamage;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue