mirror of
https://github.com/correl/mage.git
synced 2025-01-12 19:25:44 +00:00
Start implementing OrTriggeredAbility
This commit is contained in:
parent
39ec630c45
commit
65d67d48fd
2 changed files with 87 additions and 2 deletions
|
@ -11,6 +11,7 @@ import mage.abilities.effects.common.DestroyAttachedToEffect;
|
|||
import mage.abilities.effects.common.SacrificeSourceEffect;
|
||||
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
|
||||
import mage.abilities.effects.common.counter.RemoveCounterSourceEffect;
|
||||
import mage.abilities.meta.OrTriggeredAbility;
|
||||
import mage.constants.*;
|
||||
import mage.counters.CounterType;
|
||||
import mage.game.Game;
|
||||
|
@ -46,8 +47,9 @@ public final class OrcishMine extends CardImpl {
|
|||
this.addAbility(new EntersBattlefieldAbility(new AddCountersSourceEffect(CounterType.ORE.createInstance(3)), "with three ore counters on it"));
|
||||
|
||||
// At the beginning of your upkeep or whenever enchanted land becomes tapped, remove an ore counter from Orcish Mine.
|
||||
this.addAbility(new BeginningOfUpkeepTriggeredAbility(new RemoveCounterSourceEffect(CounterType.ORE.createInstance()), TargetController.YOU, false));
|
||||
this.addAbility(new BecomesTappedAttachedTriggeredAbility(new RemoveCounterSourceEffect(CounterType.ORE.createInstance()), "enchanted land", false));
|
||||
this.addAbility(new OrTriggeredAbility(Zone.BATTLEFIELD, new RemoveCounterSourceEffect(CounterType.ORE.createInstance()),
|
||||
new BeginningOfUpkeepTriggeredAbility(null, TargetController.YOU, false),
|
||||
new BecomesTappedAttachedTriggeredAbility(null, "enchanted land")));
|
||||
|
||||
// When the last ore counter is removed from Orcish Mine, destroy enchanted land and Orcish Mine deals 2 damage to that land's controller.
|
||||
this.addAbility(new OrcishMineAbility());
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
package mage.abilities.meta;
|
||||
|
||||
import mage.abilities.TriggeredAbility;
|
||||
import mage.abilities.TriggeredAbilityImpl;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
|
||||
public class OrTriggeredAbility extends TriggeredAbilityImpl {
|
||||
|
||||
private TriggeredAbility[] triggeredAbilities;
|
||||
|
||||
private final String ruleTrigger;
|
||||
|
||||
public OrTriggeredAbility(Zone zone, Effect effect, TriggeredAbility... abilities) {
|
||||
this(zone, effect, false, null, abilities);
|
||||
}
|
||||
|
||||
public OrTriggeredAbility(Zone zone, Effect effect, boolean optional, String ruleTrigger, TriggeredAbility... abilities) {
|
||||
super(zone, effect, optional);
|
||||
this.triggeredAbilities = abilities;
|
||||
this.ruleTrigger = ruleTrigger;
|
||||
for (TriggeredAbility ability : triggeredAbilities){
|
||||
//Remove useless data
|
||||
ability.getEffects().clear();
|
||||
ability.setSourceId(this.getSourceId());
|
||||
ability.setControllerId(this.getControllerId());
|
||||
}
|
||||
}
|
||||
|
||||
public OrTriggeredAbility(OrTriggeredAbility ability) {
|
||||
super(ability);
|
||||
this.triggeredAbilities = ability.triggeredAbilities;
|
||||
this.ruleTrigger = ability.ruleTrigger;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean checkEventType(GameEvent event, Game game) {
|
||||
boolean toRet = false;
|
||||
for (TriggeredAbility ability : triggeredAbilities){
|
||||
toRet = toRet || ability.checkEventType(event, game);
|
||||
}
|
||||
if (toRet){
|
||||
System.out.println("Correct event type ("+event.getType()+")");
|
||||
}
|
||||
return toRet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
boolean toRet = false;
|
||||
for (TriggeredAbility ability : triggeredAbilities){
|
||||
toRet = toRet || ability.checkTrigger(event, game);
|
||||
}
|
||||
return toRet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrTriggeredAbility copy() {
|
||||
return new OrTriggeredAbility(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRule() {
|
||||
if (ruleTrigger != null && !ruleTrigger.isEmpty()) {
|
||||
return ruleTrigger + super.getRule();
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (triggeredAbilities[0].getRule().length() > 0) {
|
||||
sb.append(triggeredAbilities[0].getRule().substring(0, 1).toUpperCase())
|
||||
.append(triggeredAbilities[0].getRule().substring(1).toLowerCase());
|
||||
}
|
||||
|
||||
for (int i = 1; i < (triggeredAbilities.length - 1); i++){
|
||||
sb.append(triggeredAbilities[i].getRule().toLowerCase());
|
||||
}
|
||||
|
||||
sb.append(" or ").append(triggeredAbilities[triggeredAbilities.length - 1].getRule().toLowerCase());
|
||||
return sb.toString()+super.getRule();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue