mirror of
https://github.com/magefree/mage.git
synced 2026-01-26 21:29:17 -08:00
[CMM] Implement Onakke Oathkeeper (#10693)
* [CMM] Implement Onakke Oathkeeper * take authorship of new file * cleanup and extend CantAttackYouUnlessPayAllEffect. * further cleanup * cleanup * add Duration to CantAttackYouUnlessPayAllEffect constructors, cleanup two more text generation. * fix duration text
This commit is contained in:
parent
792be8a859
commit
f476c6864b
17 changed files with 210 additions and 74 deletions
|
|
@ -6,42 +6,68 @@ import mage.abilities.costs.Cost;
|
|||
import mage.abilities.effects.PayCostToAttackBlockEffectImpl;
|
||||
import mage.constants.Duration;
|
||||
import mage.constants.Outcome;
|
||||
import mage.filter.StaticFilters;
|
||||
import mage.filter.common.FilterCreaturePermanent;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
||||
/**
|
||||
* @author LevelX2
|
||||
* @author LevelX2, Susucr
|
||||
*/
|
||||
public class CantAttackYouUnlessPayAllEffect extends PayCostToAttackBlockEffectImpl {
|
||||
|
||||
public enum Scope {
|
||||
YOU_AND_CONTROLLED_PLANESWALKERS(true, true,
|
||||
"you or planeswalkers you control", "of those creatures"),
|
||||
YOU_ONLY(true, false,
|
||||
"you", "creature they control that's attacking you"),
|
||||
CONTROLLED_PLANESWALKERS_ONLY(false, true,
|
||||
"planeswalkers you control", "creature they control that's attacking a planeswalker you control");
|
||||
|
||||
final boolean attackingYou;
|
||||
final boolean attackingControlledPlaneswalkers;
|
||||
// text replacing [!] in "[...] can't attack [!] unless [...] pays ..."
|
||||
final String firstText;
|
||||
// text replacing [!] in "unless their controller pays [...] for each [!]"
|
||||
final String secondText;
|
||||
|
||||
Scope(boolean attackingYou, boolean attackingControlledPlaneswalkers, String firstText, String secondText) {
|
||||
this.attackingYou = attackingYou;
|
||||
this.attackingControlledPlaneswalkers = attackingControlledPlaneswalkers;
|
||||
this.firstText = firstText;
|
||||
this.secondText = secondText;
|
||||
}
|
||||
}
|
||||
|
||||
private final FilterCreaturePermanent filterCreaturePermanent;
|
||||
private final boolean payAlsoForAttackingPlaneswalker;
|
||||
private final Scope scope; // Describe which attacked objects this effect cares about.
|
||||
|
||||
public CantAttackYouUnlessPayAllEffect(Cost cost) {
|
||||
this(cost, false);
|
||||
public CantAttackYouUnlessPayAllEffect(Duration duration, Cost cost) {
|
||||
this(duration, cost, Scope.YOU_ONLY);
|
||||
}
|
||||
|
||||
public CantAttackYouUnlessPayAllEffect(Cost cost, boolean payAlsoForAttackingPlaneswalker) {
|
||||
this(cost, payAlsoForAttackingPlaneswalker, null);
|
||||
public CantAttackYouUnlessPayAllEffect(Duration duration, Cost cost, Scope scope) {
|
||||
this(duration, cost, scope, StaticFilters.FILTER_PERMANENT_CREATURES);
|
||||
}
|
||||
|
||||
public CantAttackYouUnlessPayAllEffect(Cost cost, boolean payAlsoForAttackingPlaneswalker, FilterCreaturePermanent filter) {
|
||||
super(Duration.WhileOnBattlefield, Outcome.Detriment, RestrictType.ATTACK, cost);
|
||||
this.payAlsoForAttackingPlaneswalker = payAlsoForAttackingPlaneswalker;
|
||||
public CantAttackYouUnlessPayAllEffect(Duration duration, Cost cost, Scope scope, FilterCreaturePermanent filter) {
|
||||
super(duration, Outcome.Detriment, RestrictType.ATTACK, cost);
|
||||
this.scope = scope;
|
||||
this.filterCreaturePermanent = filter;
|
||||
staticText = (filterCreaturePermanent == null ? "Creatures" : filterCreaturePermanent.getMessage())
|
||||
+ " can't attack you "
|
||||
+ (payAlsoForAttackingPlaneswalker ? "or a planeswalker you control " : "")
|
||||
+ "unless their controller pays "
|
||||
+ (cost == null ? "" : cost.getText())
|
||||
+ " for each creature they control that's attacking you";
|
||||
|
||||
String durationText = duration.toString();
|
||||
staticText = (durationText.isEmpty() ? "" : durationText + ", ")
|
||||
+ filterCreaturePermanent.getMessage()
|
||||
+ " can't attack " + scope.firstText
|
||||
+ " unless their controller pays "
|
||||
+ cost.getText()
|
||||
+ " for each " + scope.secondText;
|
||||
}
|
||||
|
||||
public CantAttackYouUnlessPayAllEffect(final CantAttackYouUnlessPayAllEffect effect) {
|
||||
protected CantAttackYouUnlessPayAllEffect(final CantAttackYouUnlessPayAllEffect effect) {
|
||||
super(effect);
|
||||
this.payAlsoForAttackingPlaneswalker = effect.payAlsoForAttackingPlaneswalker;
|
||||
this.scope = effect.scope;
|
||||
this.filterCreaturePermanent = effect.filterCreaturePermanent;
|
||||
}
|
||||
|
||||
|
|
@ -54,16 +80,17 @@ public class CantAttackYouUnlessPayAllEffect extends PayCostToAttackBlockEffectI
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// attack target is controlling player
|
||||
if (source.isControlledBy(event.getTargetId())) {
|
||||
if (scope.attackingYou && source.isControlledBy(event.getTargetId())) {
|
||||
return true;
|
||||
}
|
||||
// or attack target is a planeswalker of the controlling player
|
||||
if (payAlsoForAttackingPlaneswalker) {
|
||||
if (scope.attackingControlledPlaneswalkers) {
|
||||
Permanent permanent = game.getPermanent(event.getTargetId());
|
||||
if (permanent != null
|
||||
&& permanent.isPlaneswalker(game)
|
||||
&& permanent.isControlledBy(source.getControllerId())) {
|
||||
&& permanent.isPlaneswalker(game)
|
||||
&& permanent.isControlledBy(source.getControllerId())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue