mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 02:30:08 -08:00
updated Fell Shepherd to not use player-scope watcher
This commit is contained in:
parent
f6f517b746
commit
dad4a3e9ff
1 changed files with 39 additions and 43 deletions
|
|
@ -1,11 +1,8 @@
|
|||
|
||||
package mage.cards.f;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import mage.MageInt;
|
||||
import mage.MageObject;
|
||||
import mage.MageObjectReference;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility;
|
||||
import mage.abilities.common.SimpleActivatedAbility;
|
||||
|
|
@ -13,21 +10,21 @@ import mage.abilities.costs.common.SacrificeTargetCost;
|
|||
import mage.abilities.costs.mana.ManaCostsImpl;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.abilities.effects.common.continuous.BoostTargetEffect;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.cards.CardSetInfo;
|
||||
import mage.cards.*;
|
||||
import mage.constants.*;
|
||||
import mage.filter.StaticFilters;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.events.GameEvent.EventType;
|
||||
import mage.game.events.ZoneChangeEvent;
|
||||
import mage.players.Player;
|
||||
import mage.target.common.TargetControlledCreaturePermanent;
|
||||
import mage.target.common.TargetCreaturePermanent;
|
||||
import mage.watchers.Watcher;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public final class FellShepherd extends CardImpl {
|
||||
|
|
@ -43,14 +40,18 @@ public final class FellShepherd extends CardImpl {
|
|||
this.addAbility(new DealsCombatDamageToAPlayerTriggeredAbility(new FellShepherdEffect(), true), new FellShepherdWatcher());
|
||||
|
||||
// {B}, Sacrifice another creature: Target creature gets -2/-2 until end of turn.
|
||||
SimpleActivatedAbility ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new BoostTargetEffect(-2, -2, Duration.EndOfTurn), new ManaCostsImpl("{B}"));
|
||||
ability.addCost(new SacrificeTargetCost(new TargetControlledCreaturePermanent(1, 1, StaticFilters.FILTER_CONTROLLED_ANOTHER_CREATURE, false)));
|
||||
SimpleActivatedAbility ability = new SimpleActivatedAbility(
|
||||
new BoostTargetEffect(-2, -2, Duration.EndOfTurn), new ManaCostsImpl("{B}")
|
||||
);
|
||||
ability.addCost(new SacrificeTargetCost(
|
||||
new TargetControlledCreaturePermanent(StaticFilters.FILTER_CONTROLLED_ANOTHER_CREATURE)
|
||||
));
|
||||
ability.addTarget(new TargetCreaturePermanent());
|
||||
this.addAbility(ability);
|
||||
|
||||
}
|
||||
|
||||
public FellShepherd(final FellShepherd card) {
|
||||
private FellShepherd(final FellShepherd card) {
|
||||
super(card);
|
||||
}
|
||||
|
||||
|
|
@ -62,16 +63,15 @@ public final class FellShepherd extends CardImpl {
|
|||
|
||||
class FellShepherdWatcher extends Watcher {
|
||||
|
||||
private Set<UUID> creatureIds = new HashSet<>();
|
||||
private final Map<UUID, Set<MageObjectReference>> playerMap = new HashMap();
|
||||
|
||||
public FellShepherdWatcher() {
|
||||
super(FellShepherdWatcher.class, WatcherScope.PLAYER);
|
||||
condition = true;
|
||||
FellShepherdWatcher() {
|
||||
super(FellShepherdWatcher.class, WatcherScope.GAME);
|
||||
}
|
||||
|
||||
public FellShepherdWatcher(final FellShepherdWatcher watcher) {
|
||||
private FellShepherdWatcher(final FellShepherdWatcher watcher) {
|
||||
super(watcher);
|
||||
this.creatureIds.addAll(watcher.creatureIds);
|
||||
this.playerMap.putAll(watcher.playerMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -79,16 +79,17 @@ class FellShepherdWatcher extends Watcher {
|
|||
return new FellShepherdWatcher(this);
|
||||
}
|
||||
|
||||
public Set<UUID> getCreaturesIds() {
|
||||
return creatureIds;
|
||||
Set<MageObjectReference> getRefSet(UUID playerId) {
|
||||
return playerMap.get(playerId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void watch(GameEvent event, Game game) {
|
||||
if (event.getType() == EventType.ZONE_CHANGE && ((ZoneChangeEvent) event).isDiesEvent()) {
|
||||
MageObject card = game.getLastKnownInformation(event.getTargetId(), Zone.BATTLEFIELD);
|
||||
if (card != null && ((Card) card).isOwnedBy(this.controllerId) && card.isCreature()) {
|
||||
creatureIds.add(card.getId());
|
||||
Card card = game.getCard(event.getTargetId());
|
||||
if (card != null && card.isCreature()) {
|
||||
playerMap.putIfAbsent(card.getOwnerId(), new HashSet());
|
||||
playerMap.get(card.getOwnerId()).add(new MageObjectReference(card, game));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -96,18 +97,18 @@ class FellShepherdWatcher extends Watcher {
|
|||
@Override
|
||||
public void reset() {
|
||||
super.reset();
|
||||
creatureIds.clear();
|
||||
playerMap.clear();
|
||||
}
|
||||
}
|
||||
|
||||
class FellShepherdEffect extends OneShotEffect {
|
||||
|
||||
public FellShepherdEffect() {
|
||||
FellShepherdEffect() {
|
||||
super(Outcome.ReturnToHand);
|
||||
this.staticText = "return to your hand all creature cards that were put into your graveyard from the battlefield this turn";
|
||||
}
|
||||
|
||||
public FellShepherdEffect(final FellShepherdEffect effect) {
|
||||
private FellShepherdEffect(final FellShepherdEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
|
|
@ -118,24 +119,19 @@ class FellShepherdEffect extends OneShotEffect {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
FellShepherdWatcher watcher = game.getState().getWatcher(FellShepherdWatcher.class, source.getControllerId());
|
||||
if (watcher != null) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (UUID creatureId : watcher.getCreaturesIds()) {
|
||||
if (game.getState().getZone(creatureId) == Zone.GRAVEYARD) {
|
||||
Card card = game.getCard(creatureId);
|
||||
if (card != null) {
|
||||
card.moveToZone(Zone.HAND, source.getSourceId(), game, false);
|
||||
sb.append(' ').append(card.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (sb.length() > 0) {
|
||||
sb.insert(0, "Fell Shepherd - returning to hand:");
|
||||
game.informPlayers(sb.toString());
|
||||
}
|
||||
return true;
|
||||
FellShepherdWatcher watcher = game.getState().getWatcher(FellShepherdWatcher.class);
|
||||
Player player = game.getPlayer(source.getControllerId());
|
||||
if (watcher == null || player == null) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
Cards cards = new CardsImpl();
|
||||
for (MageObjectReference mor : watcher.getRefSet(source.getControllerId())) {
|
||||
Card card = mor.getCard(game);
|
||||
if (card != null) {
|
||||
cards.add(card);
|
||||
}
|
||||
}
|
||||
player.moveCards(cards, Zone.HAND, source, game);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue