mirror of
https://github.com/magefree/mage.git
synced 2026-01-26 21:29:17 -08:00
refactored DamagedPlayerThisTurnPredicate
This commit is contained in:
parent
13d76bfc06
commit
3f0547a7fa
3 changed files with 23 additions and 87 deletions
|
|
@ -1,26 +1,29 @@
|
|||
|
||||
package mage.cards.r;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.abilities.effects.common.DestroyAllEffect;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.cards.CardSetInfo;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.TargetController;
|
||||
import mage.filter.common.FilterCreaturePermanent;
|
||||
import mage.filter.predicate.permanent.DamagedPlayerThisTurnPredicate;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Plopman
|
||||
*/
|
||||
public final class Retaliate extends CardImpl {
|
||||
private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("creatures that dealt damage to you this turn");
|
||||
|
||||
private static final FilterCreaturePermanent filter
|
||||
= new FilterCreaturePermanent("creatures that dealt damage to you this turn");
|
||||
|
||||
static {
|
||||
filter.add(new DamagedPlayerThisTurnPredicate(TargetController.YOU));
|
||||
filter.add(TargetController.YOU.getDamagedPlayerThisTurnPredicate());
|
||||
}
|
||||
|
||||
public Retaliate(UUID ownerId, CardSetInfo setInfo) {
|
||||
super(ownerId,setInfo,new CardType[]{CardType.INSTANT},"{2}{W}{W}");
|
||||
super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{2}{W}{W}");
|
||||
|
||||
// Destroy all creatures that dealt damage to you this turn.
|
||||
this.getSpellAbility().addEffect(new DestroyAllEffect(filter));
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
|
||||
package mage.cards.s;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.SimpleActivatedAbility;
|
||||
import mage.abilities.common.SimpleStaticAbility;
|
||||
|
|
@ -11,37 +10,42 @@ import mage.abilities.effects.common.DestroyTargetEffect;
|
|||
import mage.abilities.effects.common.continuous.BoostControlledEffect;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.cards.CardSetInfo;
|
||||
import mage.constants.*;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Duration;
|
||||
import mage.constants.SuperType;
|
||||
import mage.constants.TargetController;
|
||||
import mage.filter.common.FilterCreaturePermanent;
|
||||
import mage.filter.predicate.permanent.DamagedPlayerThisTurnPredicate;
|
||||
import mage.target.Target;
|
||||
import mage.target.common.TargetCreaturePermanent;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public final class SpearOfHeliod extends CardImpl {
|
||||
|
||||
private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("creature that dealt damage to you this turn");
|
||||
private static final FilterCreaturePermanent filter
|
||||
= new FilterCreaturePermanent("creature that dealt damage to you this turn");
|
||||
|
||||
static {
|
||||
filter.add(new DamagedPlayerThisTurnPredicate(TargetController.YOU));
|
||||
filter.add(TargetController.YOU.getDamagedPlayerThisTurnPredicate());
|
||||
}
|
||||
|
||||
public SpearOfHeliod(UUID ownerId, CardSetInfo setInfo) {
|
||||
super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT,CardType.ARTIFACT},"{1}{W}{W}");
|
||||
super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT, CardType.ARTIFACT}, "{1}{W}{W}");
|
||||
addSuperType(SuperType.LEGENDARY);
|
||||
|
||||
|
||||
// Creatures you control get +1/+1.
|
||||
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostControlledEffect(1,1, Duration.WhileOnBattlefield)));
|
||||
this.addAbility(new SimpleStaticAbility(new BoostControlledEffect(1, 1, Duration.WhileOnBattlefield)));
|
||||
|
||||
// {1}{W}{W}, {T}: Destroy target creature that dealt damage to you this turn.
|
||||
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new DestroyTargetEffect(), new ManaCostsImpl("{1}{W}{W}"));
|
||||
Ability ability = new SimpleActivatedAbility(new DestroyTargetEffect(), new ManaCostsImpl("{1}{W}{W}"));
|
||||
ability.addCost(new TapSourceCost());
|
||||
Target target = new TargetCreaturePermanent(filter);
|
||||
ability.addTarget(target);
|
||||
this.addAbility(ability);
|
||||
|
||||
}
|
||||
|
||||
public SpearOfHeliod(final SpearOfHeliod card) {
|
||||
|
|
|
|||
|
|
@ -1,71 +0,0 @@
|
|||
|
||||
package mage.filter.predicate.permanent;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.constants.TargetController;
|
||||
import mage.filter.predicate.ObjectPlayer;
|
||||
import mage.filter.predicate.ObjectPlayerPredicate;
|
||||
import mage.game.Controllable;
|
||||
import mage.game.Game;
|
||||
import mage.watchers.common.PlayerDamagedBySourceWatcher;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public class DamagedPlayerThisTurnPredicate implements ObjectPlayerPredicate<ObjectPlayer<Controllable>> {
|
||||
|
||||
private final TargetController controller;
|
||||
|
||||
public DamagedPlayerThisTurnPredicate(TargetController controller) {
|
||||
this.controller = controller;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(ObjectPlayer<Controllable> input, Game game) {
|
||||
Controllable object = input.getObject();
|
||||
UUID playerId = input.getPlayerId();
|
||||
|
||||
switch (controller) {
|
||||
case YOU:
|
||||
PlayerDamagedBySourceWatcher watcher = game.getState().getWatcher(PlayerDamagedBySourceWatcher.class, playerId);
|
||||
if (watcher != null) {
|
||||
return watcher.hasSourceDoneDamage(object.getId(), game);
|
||||
}
|
||||
break;
|
||||
case OPPONENT:
|
||||
for (UUID opponentId : game.getOpponents(playerId)) {
|
||||
watcher = game.getState().getWatcher(PlayerDamagedBySourceWatcher.class, opponentId);
|
||||
if (watcher != null) {
|
||||
return watcher.hasSourceDoneDamage(object.getId(), game);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case NOT_YOU:
|
||||
for (UUID notYouId : game.getState().getPlayersInRange(playerId, game)) {
|
||||
if (!notYouId.equals(playerId)) {
|
||||
watcher = game.getState().getWatcher(PlayerDamagedBySourceWatcher.class, notYouId);
|
||||
if (watcher != null) {
|
||||
return watcher.hasSourceDoneDamage(object.getId(), game);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ANY:
|
||||
for (UUID anyId : game.getState().getPlayersInRange(playerId, game)) {
|
||||
watcher = game.getState().getWatcher(PlayerDamagedBySourceWatcher.class, anyId);
|
||||
if (watcher != null) {
|
||||
return watcher.hasSourceDoneDamage(object.getId(), game);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Damaged player (" + controller.toString() + ')';
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue