[LCI] Implement Thousand Moons Smithy // Barracks of the Thousand

This commit is contained in:
Susucre 2023-11-19 17:15:11 +01:00
parent 69ec0e8946
commit f45c9e8ee9
7 changed files with 447 additions and 0 deletions

View file

@ -0,0 +1,77 @@
package mage.abilities.common;
import mage.MageObjectReference;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.Effect;
import mage.constants.Zone;
import mage.filter.FilterSpell;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.stack.Spell;
import mage.target.targetpointer.FixedTarget;
import mage.watchers.common.ManaPaidObjectSourceWatcher;
/**
* @author Susucr
*/
public class CastSpellPaidBySourceTriggeredAbility extends TriggeredAbilityImpl {
private final FilterSpell filter;
private final boolean setTargetPointer;
public CastSpellPaidBySourceTriggeredAbility(Effect effect, FilterSpell filter, boolean setTargetPointer) {
super(Zone.BATTLEFIELD, effect);
setTriggerPhrase("Whenever you cast " + filter.getMessage() + " using mana produced by {this}, ");
addWatcher(new ManaPaidObjectSourceWatcher());
this.filter = filter;
this.setTargetPointer = setTargetPointer;
}
protected CastSpellPaidBySourceTriggeredAbility(final CastSpellPaidBySourceTriggeredAbility ability) {
super(ability);
this.filter = ability.filter;
this.setTargetPointer = ability.setTargetPointer;
}
@Override
public CastSpellPaidBySourceTriggeredAbility copy() {
return new CastSpellPaidBySourceTriggeredAbility(this);
}
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.SPELL_CAST;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (!controllerId.equals(event.getPlayerId())) {
return false;
}
Spell spell = game.getSpell(event.getTargetId());
if (spell == null || !this.filter.match(spell, controllerId, this, game)) {
return false;
}
ManaPaidObjectSourceWatcher watcher = game.getState().getWatcher(ManaPaidObjectSourceWatcher.class);
if (watcher == null) {
return false;
}
if (!watcher.checkManaFromSourceWasUsedToPay(
new MageObjectReference(sourceId, game),
new MageObjectReference(spell.getSourceId(), game)
)) {
return false;
}
if (setTargetPointer) {
this.getAllEffects().setTargetPointer(new FixedTarget(spell.getId(), game));
}
return true;
}
}

View file

@ -0,0 +1,49 @@
package mage.game.permanent.token;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount;
import mage.abilities.effects.common.continuous.SetBasePowerToughnessSourceEffect;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.filter.common.FilterControlledPermanent;
import mage.filter.predicate.Predicates;
/**
* @author Susucr
*/
public final class GnomeSoldierStarStarToken extends TokenImpl {
private static final FilterControlledPermanent filter = new FilterControlledPermanent();
static {
filter.add(Predicates.or(
CardType.ARTIFACT.getPredicate(),
CardType.CREATURE.getPredicate()
));
}
private static final DynamicValue xValue = new PermanentsOnBattlefieldCount(filter);
public GnomeSoldierStarStarToken() {
super("Gnome Soldier Token", "white Gnome Soldier artifact creature token with "
+ "\"this creature's power and toughness are each equal to the number of artifacts and/or creatures you control.\"");
cardType.add(CardType.ARTIFACT);
cardType.add(CardType.CREATURE);
subtype.add(SubType.GNOME);
subtype.add(SubType.SOLDIER);
color.setWhite(true);
this.addAbility(new SimpleStaticAbility(new SetBasePowerToughnessSourceEffect(
xValue
).setText("this creature's power and toughness are each equal to the number of artifacts and/or creatures you control")));
}
protected GnomeSoldierStarStarToken(final GnomeSoldierStarStarToken token) {
super(token);
}
public GnomeSoldierStarStarToken copy() {
return new GnomeSoldierStarStarToken(this);
}
}

View file

@ -0,0 +1,54 @@
package mage.watchers.common;
import mage.MageObject;
import mage.MageObjectReference;
import mage.constants.WatcherScope;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.ManaPaidEvent;
import mage.watchers.Watcher;
import java.util.*;
/**
* @author Susucr
*/
public class ManaPaidObjectSourceWatcher extends Watcher {
// what is paid -> set of all MageObject sources used to pay for the mana.
private final Map<MageObjectReference, Set<MageObjectReference>> payMap = new HashMap<>();
public ManaPaidObjectSourceWatcher() {
super(WatcherScope.GAME);
}
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() != GameEvent.EventType.MANA_PAID) {
return;
}
ManaPaidEvent manaEvent = (ManaPaidEvent) event;
UUID paid = manaEvent.getSourcePaidId();
MageObject sourceObject = manaEvent.getSourceObject();
if (paid == null || sourceObject == null) {
return;
}
payMap
.computeIfAbsent(new MageObjectReference(paid, game), x -> new HashSet<>())
.add(new MageObjectReference(sourceObject, game));
}
public boolean checkManaFromSourceWasUsedToPay(MageObjectReference sourceOfMana, MageObjectReference paidObject) {
return payMap
.getOrDefault(paidObject, Collections.emptySet())
.contains(sourceOfMana);
}
@Override
public void reset() {
payMap.clear();
super.reset();
}
}