[J22] Implement Alandra, Sky Dreamer (#10219)

* Alandra Sky Dreamer
DrawSecondCardTriggeredAbility refactored into DrawCardTriggeredAbility
DynamicValue support for DrawCardTriggeredAbility
DynamicValue support for BoostAllOfChosenSubtypeEffect

* cardNumber as int
static use of cardwatcher

* removing spaces

* FaerieMastermind and ZimoneAndDina using the new generic DrawCardTriggeredAbility

* AlandraSkyDreamer and DrawCardTriggeredAbility test

* renaming DrawCardTriggeredAbility to DrawNthCardTriggeredAbility

* merging the boost effects into a single ability

* merging two effects to the same ability

* text added to effects

---------

Co-authored-by: drago <drago@192.168.1.72>
This commit is contained in:
amoscatelli 2023-04-17 15:12:18 +02:00 committed by GitHub
parent c270d282d0
commit 6059422afc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 214 additions and 78 deletions

View file

@ -18,32 +18,35 @@ import java.util.*;
/**
* @author TheElk801
*/
public class DrawSecondCardTriggeredAbility extends TriggeredAbilityImpl {
public class DrawNthCardTriggeredAbility extends TriggeredAbilityImpl {
private static final Hint hint = new ValueHint(
"Cards drawn this turn", CardsDrawnThisTurnDynamicValue.instance
);
private final TargetController targetController;
private final int cardNumber;
public DrawSecondCardTriggeredAbility(Effect effect, boolean optional) {
this(effect, optional, TargetController.YOU);
public DrawNthCardTriggeredAbility(Effect effect, boolean optional, int cardNumber) {
this(effect, optional, TargetController.YOU, cardNumber);
}
public DrawSecondCardTriggeredAbility(Effect effect, boolean optional, TargetController targetController) {
this(Zone.BATTLEFIELD, effect, optional, targetController);
public DrawNthCardTriggeredAbility(Effect effect, boolean optional, TargetController targetController, int cardNumber) {
this(Zone.BATTLEFIELD, effect, optional, targetController, cardNumber);
}
public DrawSecondCardTriggeredAbility(Zone zone, Effect effect, boolean optional, TargetController targetController) {
public DrawNthCardTriggeredAbility(Zone zone, Effect effect, boolean optional, TargetController targetController, int cardNumber) {
super(zone, effect, optional);
this.addWatcher(new DrawSecondCardWatcher());
this.addWatcher(new DrawCardWatcher());
this.targetController = targetController;
this.cardNumber = cardNumber;
this.addHint(hint);
setTriggerPhrase(generateTriggerPhrase());
}
private DrawSecondCardTriggeredAbility(final DrawSecondCardTriggeredAbility ability) {
private DrawNthCardTriggeredAbility(final DrawNthCardTriggeredAbility ability) {
super(ability);
this.targetController = ability.targetController;
this.cardNumber = ability.cardNumber;
}
@Override
@ -73,7 +76,7 @@ public class DrawSecondCardTriggeredAbility extends TriggeredAbilityImpl {
default:
throw new IllegalArgumentException("TargetController " + targetController + " not supported");
}
return DrawSecondCardWatcher.checkEvent(event.getPlayerId(), event, game);
return DrawCardWatcher.checkEvent(event.getPlayerId(), event, game, cardNumber);
}
public String generateTriggerPhrase() {
@ -90,17 +93,16 @@ public class DrawSecondCardTriggeredAbility extends TriggeredAbilityImpl {
}
@Override
public DrawSecondCardTriggeredAbility copy() {
return new DrawSecondCardTriggeredAbility(this);
public DrawNthCardTriggeredAbility copy() {
return new DrawNthCardTriggeredAbility(this);
}
}
class DrawSecondCardWatcher extends Watcher {
class DrawCardWatcher extends Watcher {
private final Set<UUID> drewOnce = new HashSet<>();
private final Map<UUID, UUID> secondDrawMap = new HashMap<>();
private final Map<UUID, List<UUID>> drawMap = new HashMap<>();
DrawSecondCardWatcher() {
DrawCardWatcher() {
super(WatcherScope.GAME);
}
@ -109,21 +111,21 @@ class DrawSecondCardWatcher extends Watcher {
if (event.getType() != GameEvent.EventType.DREW_CARD) {
return;
}
if (drewOnce.contains(event.getPlayerId())) {
secondDrawMap.putIfAbsent(event.getPlayerId(), event.getId());
} else {
drewOnce.add(event.getPlayerId());
if (!drawMap.containsKey(event.getPlayerId())) {
drawMap.putIfAbsent(event.getPlayerId(), new ArrayList<>());
}
drawMap.get(event.getPlayerId()).add(event.getId());
}
@Override
public void reset() {
super.reset();
drewOnce.clear();
secondDrawMap.clear();
drawMap.clear();
}
static boolean checkEvent(UUID playerId, GameEvent event, Game game) {
return event.getId().equals(game.getState().getWatcher(DrawSecondCardWatcher.class).secondDrawMap.getOrDefault(playerId, null));
static boolean checkEvent(UUID playerId, GameEvent event, Game game, int cardNumber) {
Map<UUID, List<UUID>> drawMap = game.getState().getWatcher(DrawCardWatcher.class).drawMap;
return drawMap.containsKey(playerId) && Objects.equals(drawMap.get(playerId).size(), cardNumber) && event.getId().equals(drawMap.get(playerId).get(cardNumber - 1));
}
}

View file

@ -1,6 +1,7 @@
package mage.abilities.effects.common.continuous;
import mage.abilities.Ability;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.effects.common.ChooseCreatureTypeEffect;
import mage.constants.Duration;
import mage.constants.SubType;
@ -23,6 +24,10 @@ public class BoostAllOfChosenSubtypeEffect extends BoostAllEffect {
super(power, toughness, duration, filter, excludeSource);
}
public BoostAllOfChosenSubtypeEffect(DynamicValue power, DynamicValue toughness, Duration duration, FilterCreaturePermanent filter, boolean excludeSource) {
super(power, toughness, duration, filter, excludeSource);
}
public BoostAllOfChosenSubtypeEffect(final BoostAllOfChosenSubtypeEffect effect) {
super(effect);
this.subtype = effect.subtype;