Implemented Akim, the Soaring Wind, and new CreatedTokenEvent (#6431)

* Implemented Akim, the Soaring Wind, and new CreatedTokenEvent, that can be used to for TriggeredEvents.

* Formatting, and added Condition to Akim triggered Ability.

* Added Condition and ConditionHint to Akim.
This commit is contained in:
AsterAether 2020-04-22 04:20:11 +02:00 committed by GitHub
parent c066ad41e8
commit e1fd213e0f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 193 additions and 1 deletions

View file

@ -0,0 +1,175 @@
package mage.cards.a;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.TriggeredAbility;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.condition.Condition;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.common.CreateTokenEffect;
import mage.abilities.effects.common.continuous.GainAbilityControlledEffect;
import mage.abilities.hint.ConditionHint;
import mage.abilities.keyword.DoubleStrikeAbility;
import mage.abilities.keyword.FlyingAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.*;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.permanent.TokenPredicate;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.game.permanent.PermanentToken;
import mage.game.permanent.token.BirdToken;
import mage.players.Player;
import mage.watchers.Watcher;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
/**
* @author AsterAether
*/
public final class AkimTheSoaringWind extends CardImpl {
private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("Creature tokens");
static {
filter.add(TokenPredicate.instance);
}
public AkimTheSoaringWind(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{2}{U}{R}{W}");
this.addSuperType(SuperType.LEGENDARY);
this.subtype.add(SubType.BIRD);
this.subtype.add(SubType.DINOSAUR);
this.power = new MageInt(3);
this.toughness = new MageInt(4);
// Flying
this.addAbility(FlyingAbility.getInstance());
// Whenever you create one or more tokens for the first time each turn, create a 1/1 white Bird creature token with flying.
this.addAbility(
new AkimTheSoaringTokenAbility()
.addHint(new ConditionHint(AkimTheSoaringWindCondition.instance,
"You create one or more tokens for the first time each turn")),
new AkimTheSoaringWindWatcher()
);
// {3}{U}{R}{W}: Creature tokens you control gain double strike until end of turn.
this.addAbility(new SimpleActivatedAbility(
new GainAbilityControlledEffect(
DoubleStrikeAbility.getInstance(),
Duration.EndOfTurn,
filter,
false),
new ManaCostsImpl("{3}{U}{R}{W}"))
);
}
private AkimTheSoaringWind(final AkimTheSoaringWind card) {
super(card);
}
@Override
public AkimTheSoaringWind copy() {
return new AkimTheSoaringWind(this);
}
}
enum AkimTheSoaringWindCondition implements Condition {
instance;
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
AkimTheSoaringWindWatcher watcher = game.getState().getWatcher(AkimTheSoaringWindWatcher.class);
return watcher != null && watcher.firstToken(controller.getId());
}
@Override
public String toString() {
return "you create one or more tokens for the first time each turn";
}
}
class AkimTheSoaringTokenAbility extends TriggeredAbilityImpl {
public AkimTheSoaringTokenAbility() {
super(Zone.BATTLEFIELD, new CreateTokenEffect(new BirdToken(), 1), false);
}
public AkimTheSoaringTokenAbility(final AkimTheSoaringTokenAbility ability) {
super(ability);
}
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.CREATED_TOKEN;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (!AkimTheSoaringWindCondition.instance.apply(game, this)) {
return false;
}
Permanent permanent = game.getPermanent(event.getTargetId());
return permanent != null && permanent.isControlledBy(this.getControllerId());
}
@Override
public TriggeredAbility copy() {
return new AkimTheSoaringTokenAbility(this);
}
@Override
public String getRule() {
return "Whenever you create one or more tokens for the first time each turn, "
+ "create a 1/1 white Bird creature token with flying.";
}
}
class AkimTheSoaringWindWatcher extends Watcher {
public enum TokenState {
NoToken,
FirstToken,
MoreThanOneToken
}
private final Map<UUID, TokenState> playerIds = new HashMap<>();
AkimTheSoaringWindWatcher() {
super(WatcherScope.GAME);
}
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() != GameEvent.EventType.CREATED_TOKEN) {
return;
}
Permanent permanent = game.getPermanent(event.getTargetId());
if (permanent instanceof PermanentToken) {
if (!playerIds.containsKey(permanent.getControllerId())) {
playerIds.put(permanent.getControllerId(), TokenState.FirstToken);
} else {
playerIds.put(permanent.getControllerId(), TokenState.MoreThanOneToken);
}
}
}
@Override
public void reset() {
playerIds.clear();
}
boolean firstToken(UUID playerId) {
return playerIds.getOrDefault(playerId, TokenState.NoToken) == TokenState.FirstToken;
}
}

View file

@ -38,6 +38,7 @@ public final class Commander2020Edition extends ExpansionSet {
cards.add(new SetCardInfo("Aerial Responder", 72, Rarity.UNCOMMON, mage.cards.a.AerialResponder.class));
cards.add(new SetCardInfo("Agitator Ant", 49, Rarity.RARE, mage.cards.a.AgitatorAnt.class));
cards.add(new SetCardInfo("Ajani Unyielding", 201, Rarity.MYTHIC, mage.cards.a.AjaniUnyielding.class));
cards.add(new SetCardInfo("Akim, the Soaring Wind", 6, Rarity.MYTHIC, mage.cards.a.AkimTheSoaringWind.class));
cards.add(new SetCardInfo("Akroma's Vengeance", 74, Rarity.RARE, mage.cards.a.AkromasVengeance.class));
cards.add(new SetCardInfo("Akroma, Angel of Wrath", 73, Rarity.MYTHIC, mage.cards.a.AkromaAngelOfWrath.class));
cards.add(new SetCardInfo("Alesha, Who Smiles at Death", 143, Rarity.RARE, mage.cards.a.AleshaWhoSmilesAtDeath.class));

View file

@ -0,0 +1,12 @@
package mage.game.events;
import mage.game.permanent.PermanentToken;
import java.util.UUID;
public class CreatedTokenEvent extends GameEvent {
public CreatedTokenEvent(UUID sourceId, PermanentToken tokenPerm) {
super(EventType.CREATED_TOKEN, tokenPerm.getId(), sourceId, tokenPerm.getControllerId());
}
}

View file

@ -316,7 +316,7 @@ public class GameEvent implements Serializable {
*/
LOST_CONTROL,
GAIN_CONTROL, GAINED_CONTROL,
CREATE_TOKEN,
CREATE_TOKEN, CREATED_TOKEN,
/* REGENERATE
targetId id of the creature to regenerate
sourceId sourceId of the effect doing the regeneration

View file

@ -8,6 +8,7 @@ import mage.cards.Card;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.CreateTokenEvent;
import mage.game.events.CreatedTokenEvent;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.events.ZoneChangeEvent;
@ -208,6 +209,9 @@ public abstract class TokenImpl extends MageObjectImpl implements Token {
((TokenImpl) token).lastAddedTokenId = permanent.getId();
}
game.addSimultaneousEvent(new ZoneChangeEvent(permanent, permanent.getControllerId(), Zone.OUTSIDE, Zone.BATTLEFIELD));
if (permanent instanceof PermanentToken) {
game.addSimultaneousEvent(new CreatedTokenEvent(event.getSourceId(), (PermanentToken) permanent));
}
if (attacking && game.getCombat() != null && game.getActivePlayerId().equals(permanent.getControllerId())) {
game.getCombat().addAttackingCreature(permanent.getId(), game, attackedPlayer);
}