mirror of
https://github.com/correl/mage.git
synced 2024-12-26 03:00:11 +00:00
Implement Premature Burial
This commit is contained in:
parent
30246732b8
commit
d43cdba805
2 changed files with 144 additions and 0 deletions
143
Mage.Sets/src/mage/cards/p/PrematureBurial.java
Normal file
143
Mage.Sets/src/mage/cards/p/PrematureBurial.java
Normal file
|
@ -0,0 +1,143 @@
|
|||
package mage.cards.p;
|
||||
|
||||
import mage.MageObject;
|
||||
import mage.MageObjectReference;
|
||||
import mage.ObjectColor;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.effects.common.DestroyTargetEffect;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.cards.CardSetInfo;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.WatcherScope;
|
||||
import mage.filter.common.FilterCreaturePermanent;
|
||||
import mage.filter.predicate.Predicates;
|
||||
import mage.filter.predicate.mageobject.ColorPredicate;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.target.common.TargetCreaturePermanent;
|
||||
import mage.watchers.Watcher;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author noahg
|
||||
*/
|
||||
public final class PrematureBurial extends CardImpl {
|
||||
|
||||
private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("nonblack creature that entered the battlefield since your last turn ended");
|
||||
|
||||
static {
|
||||
filter.add(Predicates.not(new ColorPredicate(ObjectColor.BLACK)));
|
||||
}
|
||||
|
||||
public PrematureBurial(UUID ownerId, CardSetInfo setInfo) {
|
||||
super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{1}{B}");
|
||||
|
||||
|
||||
// Destroy target nonblack creature that entered the battlefield since your last turn ended.
|
||||
this.getSpellAbility().addEffect(new DestroyTargetEffect().setText("Destroy target nonblack creature that entered the battlefield since your last turn ended."));
|
||||
this.getSpellAbility().addTarget(new ETBSinceYourLastTurnTarget(filter));
|
||||
this.getSpellAbility().addWatcher(new ETBSinceYourLastTurnWatcher());
|
||||
}
|
||||
|
||||
public PrematureBurial(final PrematureBurial card) {
|
||||
super(card);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PrematureBurial copy() {
|
||||
return new PrematureBurial(this);
|
||||
}
|
||||
}
|
||||
|
||||
class ETBSinceYourLastTurnTarget extends TargetCreaturePermanent {
|
||||
|
||||
public ETBSinceYourLastTurnTarget(FilterCreaturePermanent filter) {
|
||||
super(filter);
|
||||
this.targetName = "nonblack creature that entered the battlefield since your last turn ended";
|
||||
}
|
||||
|
||||
public ETBSinceYourLastTurnTarget(ETBSinceYourLastTurnTarget target){
|
||||
super(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTarget(UUID controllerId, UUID id, Ability source, Game game) {
|
||||
System.out.println("canTarget called");
|
||||
ETBSinceYourLastTurnWatcher watcher = (ETBSinceYourLastTurnWatcher) game.getState().getWatchers().get(ETBSinceYourLastTurnWatcher.class.getSimpleName());
|
||||
if (watcher != null){
|
||||
if (watcher.enteredSinceLastTurn(controllerId, new MageObjectReference(id, game))){
|
||||
System.out.println(game.getPermanent(id).getIdName()+" entered since the last turn.");
|
||||
return super.canTarget(controllerId, id, source, game);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) {
|
||||
MageObject targetSource = game.getObject(sourceId);
|
||||
ETBSinceYourLastTurnWatcher watcher = (ETBSinceYourLastTurnWatcher) game.getState().getWatchers().get(ETBSinceYourLastTurnWatcher.class.getSimpleName());
|
||||
for (Permanent permanent: game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) {
|
||||
if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) {
|
||||
if(watcher.enteredSinceLastTurn(sourceControllerId, new MageObjectReference(permanent.getId(), game))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ETBSinceYourLastTurnTarget copy() {
|
||||
return new ETBSinceYourLastTurnTarget(this);
|
||||
}
|
||||
}
|
||||
|
||||
class ETBSinceYourLastTurnWatcher extends Watcher {
|
||||
|
||||
private final Map<UUID, Set<MageObjectReference>> playerToETBMap;
|
||||
|
||||
public ETBSinceYourLastTurnWatcher() {
|
||||
super(ETBSinceYourLastTurnWatcher.class.getSimpleName(), WatcherScope.GAME);
|
||||
this.playerToETBMap = new HashMap<>();
|
||||
}
|
||||
|
||||
public ETBSinceYourLastTurnWatcher(ETBSinceYourLastTurnWatcher watcher) {
|
||||
super(watcher);
|
||||
this.playerToETBMap = new HashMap<>();
|
||||
for (UUID player : watcher.playerToETBMap.keySet()){
|
||||
this.playerToETBMap.put(player, new HashSet<>(watcher.playerToETBMap.get(player)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void watch(GameEvent event, Game game) {
|
||||
if (event.getType() == GameEvent.EventType.END_TURN_STEP_POST){
|
||||
System.out.println("End of turn for "+game.getPlayer(event.getPlayerId()).getName());
|
||||
playerToETBMap.put(event.getPlayerId(), new HashSet<>());
|
||||
} else if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD){
|
||||
Permanent etbPermanent = game.getPermanent(event.getTargetId());
|
||||
if (etbPermanent != null){
|
||||
System.out.println("nonnull permanent entered: "+etbPermanent.getIdName());
|
||||
for (UUID player : game.getPlayerList()){
|
||||
if (!playerToETBMap.containsKey(player)){
|
||||
playerToETBMap.put(player, new HashSet<>());
|
||||
}
|
||||
playerToETBMap.get(player).add(new MageObjectReference(etbPermanent.getBasicMageObject(game), game));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean enteredSinceLastTurn(UUID player, MageObjectReference mor){
|
||||
return playerToETBMap.get(player).contains(mor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ETBSinceYourLastTurnWatcher copy() {
|
||||
return new ETBSinceYourLastTurnWatcher(this);
|
||||
}
|
||||
}
|
|
@ -212,6 +212,7 @@ public final class TimeSpiral extends ExpansionSet {
|
|||
cards.add(new SetCardInfo("Plains", 284, Rarity.LAND, mage.cards.basiclands.Plains.class, NON_FULL_USE_VARIOUS));
|
||||
cards.add(new SetCardInfo("Plains", 285, Rarity.LAND, mage.cards.basiclands.Plains.class, NON_FULL_USE_VARIOUS));
|
||||
cards.add(new SetCardInfo("Plunder", 174, Rarity.COMMON, mage.cards.p.Plunder.class));
|
||||
cards.add(new SetCardInfo("Premature Burial", 125, Rarity.UNCOMMON, mage.cards.p.PrematureBurial.class));
|
||||
cards.add(new SetCardInfo("Primal Forcemage", 212, Rarity.UNCOMMON, mage.cards.p.PrimalForcemage.class));
|
||||
cards.add(new SetCardInfo("Prismatic Lens", 262, Rarity.COMMON, mage.cards.p.PrismaticLens.class));
|
||||
cards.add(new SetCardInfo("Psionic Sliver", 72, Rarity.RARE, mage.cards.p.PsionicSliver.class));
|
||||
|
|
Loading…
Reference in a new issue