forked from External/mage
make batchs for milling cards (per player, all)
Rework and test the couple of existing cards triggering on mill.
This commit is contained in:
parent
4edb9ce270
commit
7c3bbed8f3
17 changed files with 452 additions and 107 deletions
|
|
@ -9,6 +9,7 @@ import mage.constants.Zone;
|
|||
import mage.filter.FilterCard;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.events.MilledCardEvent;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
|
|
@ -58,7 +59,7 @@ public class MillTriggeredAbility extends TriggeredAbilityImpl {
|
|||
default:
|
||||
throw new IllegalArgumentException("Wrong code usage. targetController not yet supported: " + targetController);
|
||||
}
|
||||
Card card = game.getCard(event.getTargetId());
|
||||
Card card = ((MilledCardEvent) event).getCard();
|
||||
return card != null && filter.match(card, getControllerId(), this, game);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,54 @@
|
|||
|
||||
package mage.abilities.common;
|
||||
|
||||
import mage.abilities.TriggeredAbilityImpl;
|
||||
import mage.abilities.dynamicvalue.common.SavedMilledValue;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.constants.Zone;
|
||||
import mage.filter.FilterCard;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.events.MilledBatchAllEvent;
|
||||
|
||||
/**
|
||||
* @author Susucr
|
||||
*/
|
||||
public class OneOrMoreMilledTriggeredAbility extends TriggeredAbilityImpl {
|
||||
|
||||
private final FilterCard filter;
|
||||
|
||||
public OneOrMoreMilledTriggeredAbility(FilterCard filter, Effect effect) {
|
||||
this(filter, effect, false);
|
||||
}
|
||||
|
||||
public OneOrMoreMilledTriggeredAbility(FilterCard filter, Effect effect, boolean optional) {
|
||||
super(Zone.BATTLEFIELD, effect, optional);
|
||||
this.setTriggerPhrase("Whenever one or more " + filter.getMessage() + " are milled, ");
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
private OneOrMoreMilledTriggeredAbility(final OneOrMoreMilledTriggeredAbility ability) {
|
||||
super(ability);
|
||||
this.filter = ability.filter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OneOrMoreMilledTriggeredAbility copy() {
|
||||
return new OneOrMoreMilledTriggeredAbility(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkEventType(GameEvent event, Game game) {
|
||||
return event.getType() == GameEvent.EventType.MILLED_CARDS_BATCH_FOR_ALL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
int count = ((MilledBatchAllEvent) event).getCards().count(filter, getControllerId(), this, game);
|
||||
if (count <= 0) {
|
||||
return false;
|
||||
}
|
||||
getEffects().setValue(SavedMilledValue.VALUE_KEY, count);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
package mage.abilities.dynamicvalue.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.dynamicvalue.DynamicValue;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.game.Game;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author Susucr
|
||||
*/
|
||||
public enum SavedMilledValue implements DynamicValue {
|
||||
MANY("many"),
|
||||
MUCH("much");
|
||||
|
||||
private final String message;
|
||||
|
||||
public static final String VALUE_KEY = "SavedMilled";
|
||||
|
||||
SavedMilledValue(String message) {
|
||||
this.message = "that " + message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int calculate(Game game, Ability sourceAbility, Effect effect) {
|
||||
return Optional.ofNullable((Integer) effect.getValue(VALUE_KEY)).orElse(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SavedMilledValue copy() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue