mirror of
https://github.com/magefree/mage.git
synced 2026-01-26 21:29:17 -08:00
[BLB] Implement Camellia, the Seedmiser. (#12751)
* [BLB] Implement Camellia, the Seedmiser. Also implemented SacrificedPermanentBatchEvent, SacrificeOneOrMorePermanentsTriggeredAbility, and refactored existing Whenever you sacrifice one or more [filter] abilities to use the new SacrificeOneOrMorePermanentsTriggeredAbility (even though as they all only trigger once per turn and technically function correctly with the old SacrificePermanentTriggeredAbility. * Fix accidental newline.
This commit is contained in:
parent
c937856adf
commit
3c419a857f
10 changed files with 244 additions and 12 deletions
|
|
@ -0,0 +1,126 @@
|
|||
package mage.abilities.common;
|
||||
|
||||
import mage.abilities.TriggeredAbilityImpl;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.constants.SetTargetPointer;
|
||||
import mage.constants.TargetController;
|
||||
import mage.constants.Zone;
|
||||
import mage.filter.FilterPermanent;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.events.SacrificedPermanentBatchEvent;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
import mage.target.targetpointer.FixedTargets;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @author TheElk801, xenohedron
|
||||
*/
|
||||
public class SacrificeOneOrMorePermanentsTriggeredAbility extends TriggeredAbilityImpl {
|
||||
|
||||
private final FilterPermanent filter;
|
||||
private final SetTargetPointer setTargetPointer;
|
||||
|
||||
private final TargetController sacrificingPlayer;
|
||||
|
||||
/**
|
||||
* Whenever you sacrifice one or more "[filter]", "[effect]".
|
||||
* zone = battlefield, setTargetPointer = NONE, optional = false
|
||||
*/
|
||||
public SacrificeOneOrMorePermanentsTriggeredAbility(Effect effect, FilterPermanent filter) {
|
||||
this(Zone.BATTLEFIELD, effect, filter, TargetController.YOU, SetTargetPointer.NONE, false);
|
||||
}
|
||||
|
||||
public SacrificeOneOrMorePermanentsTriggeredAbility(Zone zone, Effect effect, FilterPermanent filter,
|
||||
TargetController sacrificingPlayer,
|
||||
SetTargetPointer setTargetPointer, boolean optional) {
|
||||
super(zone, effect, optional);
|
||||
if (Zone.BATTLEFIELD.match(zone)) {
|
||||
setLeavesTheBattlefieldTrigger(true);
|
||||
}
|
||||
this.filter = filter;
|
||||
this.setTargetPointer = setTargetPointer;
|
||||
this.sacrificingPlayer = sacrificingPlayer;
|
||||
setTriggerPhrase(generateTriggerPhrase());
|
||||
}
|
||||
|
||||
protected SacrificeOneOrMorePermanentsTriggeredAbility(final SacrificeOneOrMorePermanentsTriggeredAbility ability) {
|
||||
super(ability);
|
||||
this.filter = ability.filter;
|
||||
this.setTargetPointer = ability.setTargetPointer;
|
||||
this.sacrificingPlayer = ability.sacrificingPlayer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SacrificeOneOrMorePermanentsTriggeredAbility copy() {
|
||||
return new SacrificeOneOrMorePermanentsTriggeredAbility(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkEventType(GameEvent event, Game game) {
|
||||
return event.getType() == GameEvent.EventType.SACRIFICED_PERMANENT_BATCH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
ArrayList<Permanent> matchingPermanents = new ArrayList<>();
|
||||
for (GameEvent sEvent : ((SacrificedPermanentBatchEvent) event).getEvents()) {
|
||||
Permanent permanent = game.getPermanentOrLKIBattlefield(sEvent.getTargetId());
|
||||
if (permanent != null && filter.match(permanent, getControllerId(), this, game)) {
|
||||
switch (sacrificingPlayer) {
|
||||
case YOU:
|
||||
if (!sEvent.getPlayerId().equals(getControllerId())) {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case OPPONENT:
|
||||
Player controller = game.getPlayer(getControllerId());
|
||||
if (controller == null || !controller.hasOpponent(sEvent.getPlayerId(), game)) {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case ANY:
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unsupported TargetController in SacrificePermanentTriggeredAbility: " + sacrificingPlayer);
|
||||
}
|
||||
matchingPermanents.add(permanent);
|
||||
}
|
||||
}
|
||||
if (matchingPermanents.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
this.getEffects().setValue("sacrificedPermanents", matchingPermanents);
|
||||
switch (setTargetPointer) {
|
||||
case PERMANENT:
|
||||
this.getEffects().setTargetPointer(new FixedTargets(matchingPermanents, game));
|
||||
break;
|
||||
case NONE:
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unsupported SetTargetPointer in SacrificePermanentTriggeredAbility: " + setTargetPointer);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private String generateTriggerPhrase() {
|
||||
String targetControllerText;
|
||||
switch (sacrificingPlayer) {
|
||||
case YOU:
|
||||
targetControllerText = "you sacrifice one or more ";
|
||||
break;
|
||||
case OPPONENT:
|
||||
targetControllerText = "an opponent sacrifices one or more ";
|
||||
break;
|
||||
case ANY:
|
||||
targetControllerText = "one or more players sacrifices one or more ";
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unsupported TargetController in SacrificePermanentTriggeredAbility: " + sacrificingPlayer);
|
||||
}
|
||||
return getWhen() + targetControllerText + filter.getMessage() + ", ";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -930,6 +930,24 @@ public class GameState implements Serializable, Copyable<GameState> {
|
|||
}
|
||||
}
|
||||
|
||||
public void addSimultaneousSacrificedPermanentToBatch(GameEvent sacrificedEvent, Game game) {
|
||||
// Combine multiple sacrificed permanent events in the single event (batch)
|
||||
|
||||
// existing batch
|
||||
boolean isBatchUsed = false;
|
||||
for (GameEvent event : simultaneousEvents) {
|
||||
if (event instanceof SacrificedPermanentBatchEvent) {
|
||||
((SacrificedPermanentBatchEvent) event).addEvent(sacrificedEvent);
|
||||
isBatchUsed = true;
|
||||
}
|
||||
}
|
||||
|
||||
// new batch
|
||||
if (!isBatchUsed) {
|
||||
addSimultaneousEvent(new SacrificedPermanentBatchEvent(sacrificedEvent), game);
|
||||
}
|
||||
}
|
||||
|
||||
public void addSimultaneousLifeLossToBatch(LifeLostEvent lifeLossEvent, Game game) {
|
||||
// Combine multiple life loss events in the single event (batch)
|
||||
// see GameEvent.LOST_LIFE_BATCH
|
||||
|
|
|
|||
|
|
@ -514,7 +514,7 @@ public class GameEvent implements Serializable {
|
|||
flag true if no regeneration is allowed
|
||||
*/
|
||||
DESTROYED_PERMANENT,
|
||||
SACRIFICE_PERMANENT, SACRIFICED_PERMANENT,
|
||||
SACRIFICE_PERMANENT, SACRIFICED_PERMANENT, SACRIFICED_PERMANENT_BATCH,
|
||||
FIGHTED_PERMANENT,
|
||||
BATCH_FIGHT,
|
||||
EXPLOITED_CREATURE,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
package mage.game.events;
|
||||
|
||||
public class SacrificedPermanentBatchEvent extends BatchEvent<GameEvent> {
|
||||
|
||||
public SacrificedPermanentBatchEvent(GameEvent sacrificedEvent) {
|
||||
super(EventType.SACRIFICED_PERMANENT_BATCH, false, false, false, sacrificedEvent);
|
||||
}
|
||||
}
|
||||
|
|
@ -1421,7 +1421,9 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
|
|||
if (player != null) {
|
||||
game.informPlayers(player.getLogName() + " sacrificed " + this.getLogName() + CardUtil.getSourceLogName(game, source));
|
||||
}
|
||||
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.SACRIFICED_PERMANENT, objectId, source, controllerId));
|
||||
GameEvent sacrificedEvent = GameEvent.getEvent(GameEvent.EventType.SACRIFICED_PERMANENT, objectId, source, controllerId);
|
||||
game.fireEvent(sacrificedEvent);
|
||||
game.getState().addSimultaneousSacrificedPermanentToBatch(sacrificedEvent, game);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue