mirror of
https://github.com/magefree/mage.git
synced 2025-12-24 20:41:58 -08:00
Moved some custom "Cast only" effects to the framework.
This commit is contained in:
parent
e2c8b8f583
commit
f4a9a66974
22 changed files with 421 additions and 678 deletions
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package mage.abilities.common;
|
||||
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.abilities.effects.common.ruleModifying.CastOnlyDuringPhaseStepSourceEffect;
|
||||
import mage.constants.PhaseStep;
|
||||
import mage.constants.TurnPhase;
|
||||
import mage.constants.Zone;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public class CastOnlyDuringPhaseStepSourceAbility extends SimpleStaticAbility {
|
||||
|
||||
public CastOnlyDuringPhaseStepSourceAbility(TurnPhase turnPhase) {
|
||||
this(turnPhase, null, null);
|
||||
}
|
||||
|
||||
public CastOnlyDuringPhaseStepSourceAbility(TurnPhase turnPhase, Condition condition) {
|
||||
this(turnPhase, null, condition);
|
||||
}
|
||||
|
||||
public CastOnlyDuringPhaseStepSourceAbility(PhaseStep phaseStep) {
|
||||
this(null, phaseStep, null);
|
||||
}
|
||||
|
||||
public CastOnlyDuringPhaseStepSourceAbility(PhaseStep phaseStep, Condition condition) {
|
||||
this(null, phaseStep, condition);
|
||||
}
|
||||
|
||||
public CastOnlyDuringPhaseStepSourceAbility(TurnPhase turnPhase, PhaseStep phaseStep, Condition condition) {
|
||||
this(turnPhase, phaseStep, condition, null);
|
||||
}
|
||||
|
||||
public CastOnlyDuringPhaseStepSourceAbility(TurnPhase turnPhase, PhaseStep phaseStep, Condition condition, String effectText) {
|
||||
super(Zone.BATTLEFIELD, new CastOnlyDuringPhaseStepSourceEffect(turnPhase, phaseStep, condition));
|
||||
this.setRuleAtTheTop(true);
|
||||
if (effectText != null) {
|
||||
getEffects().get(0).setText(effectText);
|
||||
}
|
||||
}
|
||||
|
||||
private CastOnlyDuringPhaseStepSourceAbility(final CastOnlyDuringPhaseStepSourceAbility ability) {
|
||||
super(ability);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CastOnlyDuringPhaseStepSourceAbility copy() {
|
||||
return new CastOnlyDuringPhaseStepSourceAbility(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package mage.abilities.condition.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.constants.PhaseStep;
|
||||
import mage.game.Game;
|
||||
|
||||
/**
|
||||
* This condtion does not check that the turnPhase is combat. You have to check
|
||||
* this if needed on another place.
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public class AfterBlockersAreDeclaredCondition implements Condition {
|
||||
|
||||
private static final AfterBlockersAreDeclaredCondition fInstance = new AfterBlockersAreDeclaredCondition();
|
||||
|
||||
public static Condition getInstance() {
|
||||
return fInstance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
return !(game.getStep().getType().equals(PhaseStep.BEGIN_COMBAT)
|
||||
|| game.getStep().getType().equals(PhaseStep.DECLARE_ATTACKERS));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "after blockers are declared";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package mage.abilities.condition.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.constants.PhaseStep;
|
||||
import mage.game.Game;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public class AfterUpkeepStepCondtion implements Condition {
|
||||
|
||||
private static final AfterUpkeepStepCondtion fInstance = new AfterUpkeepStepCondtion();
|
||||
|
||||
public static Condition getInstance() {
|
||||
return fInstance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
return !(game.getStep().getType().equals(PhaseStep.UNTAP)
|
||||
|| game.getStep().getType().equals(PhaseStep.UPKEEP));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "after upkeep step";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package mage.abilities.condition.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.game.Game;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public class BeforeAttackersAreDeclaredCondition implements Condition {
|
||||
|
||||
private static final BeforeAttackersAreDeclaredCondition fInstance = new BeforeAttackersAreDeclaredCondition();
|
||||
|
||||
public static Condition getInstance() {
|
||||
return fInstance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
return !game.getTurn().isDeclareAttackersStepStarted();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "before attackers are declared";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package mage.abilities.condition.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.constants.PhaseStep;
|
||||
import mage.game.Game;
|
||||
|
||||
/**
|
||||
* This condtion does not check that the turnPhase is combat. You have to check
|
||||
* this if needed on another place.
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public class BeforeBlockersAreDeclaredCondition implements Condition {
|
||||
|
||||
private static final BeforeBlockersAreDeclaredCondition fInstance = new BeforeBlockersAreDeclaredCondition();
|
||||
|
||||
public static Condition getInstance() {
|
||||
return fInstance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
return !(game.getStep().getType().equals(PhaseStep.DECLARE_BLOCKERS)
|
||||
|| game.getStep().getType().equals(PhaseStep.FIRST_COMBAT_DAMAGE)
|
||||
|| game.getStep().getType().equals(PhaseStep.COMBAT_DAMAGE)
|
||||
|| game.getStep().getType().equals(PhaseStep.END_COMBAT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "before blockers are declared";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package mage.abilities.condition.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.game.Game;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public class OnOpponentsTurnCondition implements Condition {
|
||||
|
||||
private static final OnOpponentsTurnCondition fInstance = new OnOpponentsTurnCondition();
|
||||
|
||||
public static Condition getInstance() {
|
||||
return fInstance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
return !game.getOpponents(source.getControllerId()).contains(game.getActivePlayerId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "on an opponent's turn";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package mage.abilities.effects.common.ruleModifying;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.abilities.effects.ContinuousRuleModifyingEffectImpl;
|
||||
import mage.constants.Duration;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.PhaseStep;
|
||||
import mage.constants.TurnPhase;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public class CastOnlyDuringPhaseStepSourceEffect extends ContinuousRuleModifyingEffectImpl {
|
||||
|
||||
private final TurnPhase turnPhase;
|
||||
private final PhaseStep phaseStep;
|
||||
private final Condition condition;
|
||||
|
||||
public CastOnlyDuringPhaseStepSourceEffect(TurnPhase turnPhase, PhaseStep phaseStep, Condition condition) {
|
||||
super(Duration.EndOfGame, Outcome.Detriment);
|
||||
this.turnPhase = turnPhase;
|
||||
this.phaseStep = phaseStep;
|
||||
this.condition = condition;
|
||||
setText();
|
||||
}
|
||||
|
||||
private CastOnlyDuringPhaseStepSourceEffect(final CastOnlyDuringPhaseStepSourceEffect effect) {
|
||||
super(effect);
|
||||
this.turnPhase = effect.turnPhase;
|
||||
this.phaseStep = effect.phaseStep;
|
||||
this.condition = effect.condition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checksEventType(GameEvent event, Game game) {
|
||||
return GameEvent.EventType.CAST_SPELL.equals(event.getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean applies(GameEvent event, Ability source, Game game) {
|
||||
if (event.getSourceId().equals(source.getSourceId())) {
|
||||
return (turnPhase == null || !game.getPhase().getType().equals(turnPhase))
|
||||
&& (phaseStep == null || !game.getTurn().getStepType().equals(phaseStep))
|
||||
&& (condition == null || !condition.apply(game, source));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CastOnlyDuringPhaseStepSourceEffect copy() {
|
||||
return new CastOnlyDuringPhaseStepSourceEffect(this);
|
||||
}
|
||||
|
||||
private String setText() {
|
||||
StringBuilder sb = new StringBuilder("cast {this} only during ");
|
||||
if (turnPhase != null) {
|
||||
sb.append(turnPhase.toString());
|
||||
}
|
||||
if (phaseStep != null) {
|
||||
sb.append("the ").append(phaseStep.getStepText());
|
||||
}
|
||||
if (condition != null) {
|
||||
sb.append(" ").append(condition.toString());
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue