mirror of
https://github.com/magefree/mage.git
synced 2026-01-26 21:29:17 -08:00
Rework how Training events are handled (#11748)
* Replace training GameEvent with custom TriggeredAbility
This commit is contained in:
parent
079b78628a
commit
c4e0d64428
3 changed files with 22 additions and 36 deletions
|
|
@ -13,12 +13,15 @@ import mage.constants.CardType;
|
|||
import mage.constants.Outcome;
|
||||
import mage.constants.SubType;
|
||||
import mage.constants.Zone;
|
||||
import mage.counters.CounterType;
|
||||
import mage.filter.StaticFilters;
|
||||
import mage.filter.common.FilterCreaturePermanent;
|
||||
import mage.filter.predicate.mageobject.AnotherPredicate;
|
||||
import mage.game.ExileZone;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.stack.StackAbility;
|
||||
import mage.game.stack.StackObject;
|
||||
import mage.players.Player;
|
||||
import mage.target.common.TargetCardInGraveyardBattlefieldOrStack;
|
||||
import mage.util.CardUtil;
|
||||
|
|
@ -86,11 +89,27 @@ class SaviorOfOllenbockTriggeredAbility extends TriggeredAbilityImpl {
|
|||
|
||||
@Override
|
||||
public boolean checkEventType(GameEvent event, Game game) {
|
||||
return event.getType() == GameEvent.EventType.TRAINED_CREATURE;
|
||||
return event.getType() == GameEvent.EventType.COUNTER_ADDED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
// 20240202 - 702.149c
|
||||
// Some creatures with training have abilities that trigger when they train.
|
||||
// "When this creature trains" means "When a resolving training ability puts a +1/+1 counter on this creature."
|
||||
if (!event.getData().equals(CounterType.P1P1.getName())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
StackObject stackObject = game.getStack().getStackObject(event.getSourceId());
|
||||
if (!(stackObject instanceof StackAbility)) {
|
||||
return false;
|
||||
}
|
||||
Ability ability = stackObject.getStackAbility();
|
||||
if (!(ability instanceof TrainingAbility)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return event.getTargetId().equals(getSourceId());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,10 +2,8 @@ package mage.abilities.keyword;
|
|||
|
||||
import mage.MageInt;
|
||||
import mage.MageObject;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.TriggeredAbilityImpl;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.constants.Outcome;
|
||||
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
|
||||
import mage.constants.Zone;
|
||||
import mage.counters.CounterType;
|
||||
import mage.game.Game;
|
||||
|
|
@ -20,7 +18,7 @@ import java.util.Objects;
|
|||
public class TrainingAbility extends TriggeredAbilityImpl {
|
||||
|
||||
public TrainingAbility() {
|
||||
super(Zone.BATTLEFIELD, new TrainingAbilityEffect());
|
||||
super(Zone.BATTLEFIELD, new AddCountersSourceEffect(CounterType.P1P1.createInstance()));
|
||||
}
|
||||
|
||||
private TrainingAbility(final TrainingAbility ability) {
|
||||
|
|
@ -60,33 +58,3 @@ public class TrainingAbility extends TriggeredAbilityImpl {
|
|||
"with greater power, put a +1/+1 counter on this creature.)</i>";
|
||||
}
|
||||
}
|
||||
|
||||
class TrainingAbilityEffect extends OneShotEffect {
|
||||
|
||||
TrainingAbilityEffect() {
|
||||
super(Outcome.Neutral);
|
||||
}
|
||||
|
||||
private TrainingAbilityEffect(final TrainingAbilityEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrainingAbilityEffect copy() {
|
||||
return new TrainingAbilityEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Permanent permanent = source.getSourcePermanentIfItStillExists(game);
|
||||
if (permanent == null) {
|
||||
return false;
|
||||
}
|
||||
permanent.addCounters(CounterType.P1P1.createInstance(), source, game);
|
||||
game.fireEvent(GameEvent.getEvent(
|
||||
GameEvent.EventType.TRAINED_CREATURE,
|
||||
source.getSourceId(), source, source.getControllerId()
|
||||
));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -470,7 +470,6 @@ public class GameEvent implements Serializable {
|
|||
EVOLVED_CREATURE,
|
||||
EMBALMED_CREATURE,
|
||||
ETERNALIZED_CREATURE,
|
||||
TRAINED_CREATURE,
|
||||
ATTACH, ATTACHED,
|
||||
UNATTACH, UNATTACHED,
|
||||
/* ATTACH, ATTACHED,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue