[LTC] Implement Gilraen, Dunedain Protector (#10728)

* [LTC] Implement Gilraen, Dunedain Protector

* add tests on Gilraen

* apply review
This commit is contained in:
Susucre 2023-08-12 22:16:02 +02:00 committed by GitHub
parent eef8f508e4
commit 2d53668c96
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 317 additions and 190 deletions

View file

@ -0,0 +1,72 @@
package mage.abilities.effects;
import mage.MageObjectReference;
import mage.abilities.Ability;
import mage.cards.Card;
import mage.cards.MeldCard;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.counters.Counter;
import mage.counters.Counters;
import mage.game.Game;
import mage.players.Player;
public class ReturnMORToBattlefieldUnderOwnerControlWithCounterEffect extends OneShotEffect {
private final MageObjectReference objectToReturn;
private final Counters counters;
private final String counterText;
public ReturnMORToBattlefieldUnderOwnerControlWithCounterEffect(
MageObjectReference objectToReturn,
Counter counter,
String counterText
) {
this(objectToReturn, new Counters().addCounter(counter), counterText);
}
public ReturnMORToBattlefieldUnderOwnerControlWithCounterEffect(
MageObjectReference objectToReturn,
Counters counters,
String counterText
) {
super(Outcome.PutCardInPlay);
this.objectToReturn = objectToReturn;
this.counters = counters.copy();
this.counterText = counterText;
this.staticText = "return that card to the battlefield with " + counterText + " on it";
}
private ReturnMORToBattlefieldUnderOwnerControlWithCounterEffect(
final ReturnMORToBattlefieldUnderOwnerControlWithCounterEffect effect
) {
super(effect);
this.objectToReturn = effect.objectToReturn;
this.counters = effect.counters.copy();
this.counterText = effect.counterText;
}
@Override
public ReturnMORToBattlefieldUnderOwnerControlWithCounterEffect copy() {
return new ReturnMORToBattlefieldUnderOwnerControlWithCounterEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Card card = game.getCard(objectToReturn.getSourceId());
if (card != null && objectToReturn.refersTo(card, game)) {
Player owner = game.getPlayer(card.getOwnerId());
if (owner != null) {
if (card instanceof MeldCard) {
MeldCard meldCard = (MeldCard) card;
game.setEnterWithCounters(meldCard.getTopHalfCard().getId(), counters);
game.setEnterWithCounters(meldCard.getBottomHalfCard().getId(), counters);
} else {
game.setEnterWithCounters(objectToReturn.getSourceId(), counters);
}
owner.moveCards(card, Zone.BATTLEFIELD, source, game, false, false, true, null);
}
}
return true;
}
}

View file

@ -25,19 +25,20 @@ public class Counters extends HashMap<String, Counter> implements Serializable {
return new Counters(this);
}
public void addCounter(String name, int amount) {
public Counters addCounter(String name, int amount) {
putIfAbsent(name, new Counter(name));
this.get(name).add(amount);
return this;
}
public void addCounter(Counter counter) {
public Counters addCounter(Counter counter) {
if (!containsKey(counter.name)) {
put(counter.name, counter);
} else {
get(counter.name).add(counter.getCount());
}
return this;
}
public boolean removeCounter(String name) {