[MAT] Implement Deification, fix access to counter removal damage checkers (#12215)

* Make ChoosePlaneswalkerTypeEffect

* Make REMOVE_COUNTER and REMOVE_COUNTERS events so they can be replaced/modified

* Deification initial attempt, need to filter for damage

* add optional damage flag to removeCounters

* wrap logs in sim check

* check that planeswalker is chosen subtype

* cast to RemoveCountersEvent and reduce indents

* use counterRemovedDueToDamage

* add tests

* make other counterRemovedDueToDamage headers public

* remove logs

* remove isSimulation check from informPlayers

* remove logger

* make chosen planeswalker type predicate

* move event modification to replaceEvent
This commit is contained in:
jimga150 2024-05-03 22:15:00 -04:00 committed by GitHub
parent 85cad4ff1e
commit 82069ef2e8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 333 additions and 3 deletions

View file

@ -0,0 +1,78 @@
package mage.abilities.effects.common;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.choices.Choice;
import mage.choices.ChoicePlaneswalkerType;
import mage.constants.Outcome;
import mage.constants.SubType;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.util.CardUtil;
import java.util.UUID;
/**
* @author jimga150
*/
// Based on ChooseCreatureTypeEffect
public class ChoosePlaneswalkerTypeEffect extends OneShotEffect {
public ChoosePlaneswalkerTypeEffect(Outcome outcome) {
super(outcome);
staticText = "choose a planeswalker type";
}
protected ChoosePlaneswalkerTypeEffect(final ChoosePlaneswalkerTypeEffect effect) {
super(effect);
}
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject mageObject = game.getPermanentEntering(source.getSourceId());
if (mageObject == null) {
mageObject = game.getObject(source);
}
if (controller != null && mageObject != null) {
Choice typeChoice = new ChoicePlaneswalkerType(mageObject);
if (controller.choose(outcome, typeChoice, game)) {
game.informPlayers(mageObject.getName() + ": " + controller.getLogName() + " has chosen " + typeChoice.getChoice());
game.getState().setValue(source.getSourceId() + "_type", SubType.byDescription(typeChoice.getChoice()));
if (mageObject instanceof Permanent) {
((Permanent) mageObject).addInfo("chosen type", CardUtil.addToolTipMarkTags("Chosen type: " + typeChoice.getChoice()), game);
}
return true;
}
}
return false;
}
@Override
public ChoosePlaneswalkerTypeEffect copy() {
return new ChoosePlaneswalkerTypeEffect(this);
}
public static SubType getChosenPlaneswalkerType(UUID objectId, Game game) {
return getChosenPlaneswalkerType(objectId, game, "_type");
}
/**
* @param objectId sourceId the effect was executed under
* @param game
* @param typePostfix special postfix if you want to store multiple choices
* from different effects
* @return
*/
public static SubType getChosenPlaneswalkerType(UUID objectId, Game game, String typePostfix) {
SubType planeswalkerType = null;
Object savedPlaneswalkerType = game.getState().getValue(objectId + typePostfix);
if (savedPlaneswalkerType != null) {
planeswalkerType = SubType.byDescription(savedPlaneswalkerType.toString());
}
return planeswalkerType;
}
}

View file

@ -0,0 +1,34 @@
package mage.filter.predicate.mageobject;
import mage.MageObject;
import mage.abilities.effects.common.ChooseCreatureTypeEffect;
import mage.abilities.effects.common.ChoosePlaneswalkerTypeEffect;
import mage.constants.SubType;
import mage.filter.predicate.ObjectSourcePlayer;
import mage.filter.predicate.ObjectSourcePlayerPredicate;
import mage.game.Game;
/**
*
* @author jimga150
*/
public enum ChosenPlaneswalkerTypePredicate implements ObjectSourcePlayerPredicate<MageObject> {
TRUE(true), FALSE(false);
private final boolean value;
ChosenPlaneswalkerTypePredicate(boolean value) {
this.value = value;
}
@Override
public boolean apply(ObjectSourcePlayer<MageObject> input, Game game) {
SubType subType = ChoosePlaneswalkerTypeEffect.getChosenPlaneswalkerType(input.getSourceId(), game);
return input.getObject().hasSubtype(subType, game) == value;
}
@Override
public String toString() {
return "Chosen Planeswalker type";
}
}

View file

@ -22,7 +22,7 @@ public class CounterRemovedEvent extends GameEvent {
this.isDamage = isDamage;
}
boolean counterRemovedDueToDamage(){
public boolean counterRemovedDueToDamage(){
return this.isDamage;
}

View file

@ -22,7 +22,7 @@ public class RemoveCounterEvent extends GameEvent {
this.isDamage = isDamage;
}
boolean counterRemovedDueToDamage(){
public boolean counterRemovedDueToDamage(){
return this.isDamage;
}

View file

@ -26,7 +26,7 @@ public class RemoveCountersEvent extends GameEvent {
this.isDamage = isDamage;
}
boolean counterRemovedDueToDamage(){
public boolean counterRemovedDueToDamage(){
return this.isDamage;
}