Fixing saga implementation

Related to #4875, still need to rework how the SBA removes the saga with respect to the final trigger
This commit is contained in:
Evan Kranzler 2018-04-27 15:12:11 -04:00
parent 1583c3af08
commit 4ac6e7d86c
3 changed files with 72 additions and 59 deletions

View file

@ -32,7 +32,6 @@ import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.constants.SagaChapter;
import mage.constants.Zone;
import mage.counters.CounterType;
@ -47,17 +46,17 @@ import mage.game.stack.StackObject;
*
* @author LevelX2
*/
public class SagaAbility extends TriggeredAbilityImpl {
public class SagaAbility extends SimpleStaticAbility {
private SagaChapter maxChapter;
public SagaAbility(Card card, SagaChapter maxChapter) {
super(Zone.ALL, new AddCountersSourceEffect(CounterType.LORE.createInstance()), false);
this.usesStack = false;
super(Zone.ALL, new AddCountersSourceEffect(CounterType.LORE.createInstance()));
this.maxChapter = maxChapter;
this.setRuleVisible(false);
((CardImpl) card).addAbility(new SagaAddCounterAbility(maxChapter));
Ability ability = new EntersBattlefieldAbility(new AddCountersSourceEffect(CounterType.LORE.createInstance()));
ability.setRuleVisible(false);
card.addAbility(ability);
}
public SagaAbility(final SagaAbility ability) {
@ -65,28 +64,13 @@ public class SagaAbility extends TriggeredAbilityImpl {
this.maxChapter = ability.maxChapter;
}
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
return event.getTargetId().equals(getSourceId());
}
@Override
public String getRule() {
return "When {this} enters the battlefield, " + super.getRule();
}
public Ability addChapterEffect(Card card, SagaChapter chapter, Effect effect) {
return addChapterEffect(card, chapter, chapter, effect);
}
public Ability addChapterEffect(Card card, SagaChapter fromChapter, SagaChapter toChapter, Effect effect) {
ChapterTriggeredAbility ability = new ChapterTriggeredAbility(effect, fromChapter, toChapter);
((CardImpl) card).addAbility(ability);
card.addAbility(ability);
if (maxChapter == null || toChapter.getNumber() > maxChapter.getNumber()) {
maxChapter = toChapter;
}
@ -97,6 +81,11 @@ public class SagaAbility extends TriggeredAbilityImpl {
return maxChapter;
}
@Override
public String getRule() {
return "<i>(As this Saga enters and after your draw step, add a lore counter. Sacrifice after " + maxChapter.toString() + ".)</i> ";
}
@Override
public SagaAbility copy() {
return new SagaAbility(this);
@ -179,39 +168,39 @@ class ChapterTriggeredAbility extends TriggeredAbilityImpl {
}
}
class SagaAddCounterAbility extends TriggeredAbilityImpl {
SagaChapter maxChapter;
SagaAddCounterAbility(SagaChapter maxChapter) {
super(Zone.BATTLEFIELD, new AddCountersSourceEffect(CounterType.LORE.createInstance()), false);
this.usesStack = false;
this.maxChapter = maxChapter;
}
SagaAddCounterAbility(final SagaAddCounterAbility ability) {
super(ability);
this.maxChapter = ability.maxChapter;
}
@Override
public SagaAddCounterAbility copy() {
return new SagaAddCounterAbility(this);
}
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == EventType.PRECOMBAT_MAIN_PHASE_PRE;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
return event.getPlayerId().equals(this.controllerId);
}
@Override
public String getRule() {
return "<i>(As this Saga enters and after your draw step, add a lore counter. Sacrifice after " + maxChapter.toString() + ".)</i> ";
}
}
//class SagaAddCounterAbility extends TriggeredAbilityImpl {
//
// SagaChapter maxChapter;
//
// SagaAddCounterAbility(SagaChapter maxChapter) {
// super(Zone.BATTLEFIELD, new AddCountersSourceEffect(CounterType.LORE.createInstance()), false);
// this.usesStack = false;
// this.maxChapter = maxChapter;
// }
//
// SagaAddCounterAbility(final SagaAddCounterAbility ability) {
// super(ability);
// this.maxChapter = ability.maxChapter;
// }
//
// @Override
// public SagaAddCounterAbility copy() {
// return new SagaAddCounterAbility(this);
// }
//
// @Override
// public boolean checkEventType(GameEvent event, Game game) {
// return event.getType() == EventType.PRECOMBAT_MAIN_PHASE_PRE;
// }
//
// @Override
// public boolean checkTrigger(GameEvent event, Game game) {
// return event.getPlayerId().equals(this.controllerId);
// }
//
// @Override
// public String getRule() {
// return "<i>(As this Saga enters and after your draw step, add a lore counter. Sacrifice after " + maxChapter.toString() + ".)</i> ";
// }
//
//}

View file

@ -157,6 +157,8 @@ public interface Card extends MageObject {
Counters getCounters(GameState state);
void addAbility(Ability ability);
boolean addCounters(Counter counter, Ability source, Game game);
boolean addCounters(Counter counter, Ability source, Game game, List<UUID> appliedEffects);

View file

@ -25,11 +25,17 @@
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.game.turn;
import java.util.UUID;
import mage.constants.PhaseStep;
import mage.constants.SubType;
import mage.counters.CounterType;
import mage.filter.FilterPermanent;
import mage.filter.predicate.mageobject.SubtypePredicate;
import mage.game.Game;
import mage.game.events.GameEvent.EventType;
import mage.game.permanent.Permanent;
/**
*
@ -37,6 +43,12 @@ import mage.game.events.GameEvent.EventType;
*/
public class PreCombatMainStep extends Step {
private static final FilterPermanent filter = new FilterPermanent("Saga");
static {
filter.add(new SubtypePredicate(SubType.SAGA));
}
public PreCombatMainStep() {
super(PhaseStep.PRECOMBAT_MAIN, true);
this.stepEvent = EventType.PRECOMBAT_MAIN_STEP;
@ -48,6 +60,16 @@ public class PreCombatMainStep extends Step {
super(step);
}
@Override
public void beginStep(Game game, UUID activePlayerId) {
super.beginStep(game, activePlayerId);
for (Permanent saga : game.getBattlefield().getAllActivePermanents(filter, activePlayerId, game)) {
if (saga != null) {
saga.addCounters(CounterType.LORE.createInstance(), null, game);
}
}
}
@Override
public PreCombatMainStep copy() {
return new PreCombatMainStep(this);