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