mirror of
https://github.com/correl/mage.git
synced 2024-11-15 03:00:16 +00:00
* Oath of Kaya - fixed that it doesn't triggers on attacks;
This commit is contained in:
parent
9ad7c4c83d
commit
e51b054249
3 changed files with 126 additions and 52 deletions
|
@ -3,7 +3,6 @@ package mage.cards.o;
|
|||
import mage.abilities.Ability;
|
||||
import mage.abilities.TriggeredAbilityImpl;
|
||||
import mage.abilities.common.EntersBattlefieldTriggeredAbility;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.abilities.effects.common.DamageTargetEffect;
|
||||
import mage.abilities.effects.common.GainLifeEffect;
|
||||
import mage.cards.CardImpl;
|
||||
|
@ -18,8 +17,6 @@ import mage.players.Player;
|
|||
import mage.target.common.TargetAnyTarget;
|
||||
import mage.target.targetpointer.FixedTarget;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
|
@ -38,7 +35,8 @@ public final class OathOfKaya extends CardImpl {
|
|||
ability.addTarget(new TargetAnyTarget());
|
||||
this.addAbility(ability);
|
||||
|
||||
// Whenever an opponent attacks a planeswalker you control with one or more creatures, Oath of Kaya deals 2 damage to that player and you gain 2 life.
|
||||
// Whenever an opponent attacks a planeswalker you control with one or more creatures,
|
||||
// Oath of Kaya deals 2 damage to that player and you gain 2 life.
|
||||
this.addAbility(new OathOfKayaTriggeredAbility());
|
||||
}
|
||||
|
||||
|
@ -53,54 +51,14 @@ public final class OathOfKaya extends CardImpl {
|
|||
}
|
||||
|
||||
class OathOfKayaTriggeredAbility extends TriggeredAbilityImpl {
|
||||
private final Set<UUID> attackedThisCombat = new HashSet();
|
||||
|
||||
OathOfKayaTriggeredAbility() {
|
||||
super(Zone.BATTLEFIELD, null, false);
|
||||
public OathOfKayaTriggeredAbility() {
|
||||
super(Zone.BATTLEFIELD, new DamageTargetEffect(2), false);
|
||||
this.addEffect(new GainLifeEffect(2));
|
||||
}
|
||||
|
||||
private OathOfKayaTriggeredAbility(final OathOfKayaTriggeredAbility ability) {
|
||||
public OathOfKayaTriggeredAbility(final OathOfKayaTriggeredAbility ability) {
|
||||
super(ability);
|
||||
this.attackedThisCombat.addAll(ability.attackedThisCombat);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkEventType(GameEvent event, Game game) {
|
||||
return event.getType() == GameEvent.EventType.ATTACKER_DECLARED
|
||||
|| event.getType() == GameEvent.EventType.DECLARE_ATTACKERS_STEP_POST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
if (event.getType() == GameEvent.EventType.DECLARE_ATTACKERS_STEP_POST) {
|
||||
this.attackedThisCombat.clear();
|
||||
return false;
|
||||
}
|
||||
Player player = game.getPlayer(getSourceId());
|
||||
if (player == null) {
|
||||
return false;
|
||||
}
|
||||
for (UUID attackerId : game.getCombat().getAttackers()) {
|
||||
Permanent attacker = game.getPermanent(attackerId);
|
||||
if (attacker == null) {
|
||||
continue;
|
||||
}
|
||||
UUID defendingPlayerId = game.getCombat().getDefendingPlayerId(attackerId, game);
|
||||
UUID defenderId = game.getCombat().getDefenderId(attackerId);
|
||||
if (defendingPlayerId.equals(defenderId)
|
||||
|| attackedThisCombat.contains(defenderId)
|
||||
|| !player.hasOpponent(defendingPlayerId, game)) {
|
||||
continue;
|
||||
}
|
||||
attackedThisCombat.add(defenderId);
|
||||
this.getEffects().clear();
|
||||
Effect effect = new DamageTargetEffect(2);
|
||||
effect.setTargetPointer(new FixedTarget(attacker.getControllerId(), game));
|
||||
this.addEffect(effect);
|
||||
this.addEffect(new GainLifeEffect(2));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -109,8 +67,32 @@ class OathOfKayaTriggeredAbility extends TriggeredAbilityImpl {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getRule() {
|
||||
return "Whenever an opponent attacks a planeswalker you control with one or more creatures, " +
|
||||
"{this} deals 2 damage to that player and you gain 2 life.";
|
||||
public boolean checkEventType(GameEvent event, Game game) {
|
||||
return event.getType() == GameEvent.EventType.DECLARED_ATTACKERS;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
Player you = game.getPlayer(this.getControllerId());
|
||||
if (you == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (game.getCombat().isPlaneswalkerAttacked(you.getId(), game)) {
|
||||
for (UUID attacker : game.getCombat().getAttackers()) {
|
||||
Permanent attackingPermanent = game.getPermanent(attacker);
|
||||
if (attackingPermanent != null && attackingPermanent.isCreature()) {
|
||||
getEffects().setTargetPointer(new FixedTarget(attackingPermanent.getControllerId(), game));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRule() {
|
||||
return "Whenever an opponent attacks a planeswalker you control with one or more creatures, "
|
||||
+ "{this} deals 2 damage to that player and you gain 2 life.";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
package org.mage.test.cards.abilities.other;
|
||||
|
||||
import mage.constants.PhaseStep;
|
||||
import mage.constants.Zone;
|
||||
import mage.counters.CounterType;
|
||||
import org.junit.Test;
|
||||
import org.mage.test.serverside.base.CardTestPlayerBase;
|
||||
|
||||
/**
|
||||
* @author JayDi85
|
||||
*/
|
||||
public class OathOfKayaTest extends CardTestPlayerBase {
|
||||
|
||||
@Test
|
||||
public void test_AttackingPlayer() {
|
||||
// Whenever an opponent attacks a planeswalker you control with one or more creatures,
|
||||
// Oath of Kaya deals 2 damage to that player and you gain 2 life.
|
||||
addCard(Zone.BATTLEFIELD, playerB, "Oath of Kaya", 1);
|
||||
//
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Grizzly Bears", 2); // 2/2
|
||||
addCard(Zone.BATTLEFIELD, playerB, "Liliana, Dreadhorde General", 1);
|
||||
|
||||
attack(1, playerA, "Grizzly Bears", playerB);
|
||||
|
||||
setStrictChooseMode(true);
|
||||
setStopAt(1, PhaseStep.END_TURN);
|
||||
execute();
|
||||
assertAllCommandsUsed();
|
||||
|
||||
assertCounterCount(playerB, "Liliana, Dreadhorde General", CounterType.LOYALTY, 6);
|
||||
assertLife(playerA, 20);
|
||||
assertLife(playerB, 20 - 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_AttackingPlaneswalker() {
|
||||
// Whenever an opponent attacks a planeswalker you control with one or more creatures,
|
||||
// Oath of Kaya deals 2 damage to that player and you gain 2 life.
|
||||
addCard(Zone.BATTLEFIELD, playerB, "Oath of Kaya", 1);
|
||||
//
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Grizzly Bears", 2); // 2/2
|
||||
addCard(Zone.BATTLEFIELD, playerB, "Liliana, Dreadhorde General", 1);
|
||||
|
||||
attack(1, playerA, "Grizzly Bears", "Liliana, Dreadhorde General");
|
||||
attack(1, playerA, "Grizzly Bears", "Liliana, Dreadhorde General");
|
||||
|
||||
setStrictChooseMode(true);
|
||||
setStopAt(1, PhaseStep.END_TURN);
|
||||
execute();
|
||||
assertAllCommandsUsed();
|
||||
|
||||
assertCounterCount(playerB, "Liliana, Dreadhorde General", CounterType.LOYALTY, 6 - 2 * 2);
|
||||
assertLife(playerA, 20 - 2);
|
||||
assertLife(playerB, 20 + 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_AttackingTwoPlaneswalkers() {
|
||||
// Whenever an opponent attacks a planeswalker you control with one or more creatures,
|
||||
// Oath of Kaya deals 2 damage to that player and you gain 2 life.
|
||||
addCard(Zone.BATTLEFIELD, playerB, "Oath of Kaya", 1);
|
||||
//
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Grizzly Bears", 2); // 2/2
|
||||
addCard(Zone.BATTLEFIELD, playerB, "Liliana, Dreadhorde General", 1);
|
||||
addCard(Zone.BATTLEFIELD, playerB, "Vivien, Champion of the Wilds", 1);
|
||||
|
||||
attack(1, playerA, "Grizzly Bears", "Liliana, Dreadhorde General");
|
||||
attack(1, playerA, "Grizzly Bears", "Vivien, Champion of the Wilds");
|
||||
|
||||
setStrictChooseMode(true);
|
||||
setStopAt(1, PhaseStep.END_TURN);
|
||||
execute();
|
||||
assertAllCommandsUsed();
|
||||
|
||||
assertCounterCount(playerB, "Liliana, Dreadhorde General", CounterType.LOYALTY, 6 - 2);
|
||||
assertCounterCount(playerB, "Vivien, Champion of the Wilds", CounterType.LOYALTY, 4 - 2);
|
||||
assertLife(playerA, 20 - 2);
|
||||
assertLife(playerB, 20 + 2);
|
||||
}
|
||||
}
|
|
@ -1539,6 +1539,18 @@ public class Combat implements Serializable, Copyable<Combat> {
|
|||
return false;
|
||||
}
|
||||
|
||||
public boolean isPlaneswalkerAttacked(UUID defenderId, Game game) {
|
||||
for (CombatGroup group : groups) {
|
||||
if (group.defenderIsPlaneswalker) {
|
||||
Permanent permanent = game.getPermanent(group.getDefenderId());
|
||||
if (permanent.isControlledBy(defenderId)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param attackerId
|
||||
* @return uuid of defending player or planeswalker
|
||||
|
|
Loading…
Reference in a new issue