mirror of
https://github.com/correl/mage.git
synced 2024-11-15 19:19:33 +00:00
* Thirsting Axe - Fix check if equipped creature dealt combat damage to creature (fixes #2145).
This commit is contained in:
parent
57995f893e
commit
b91ef8b385
1 changed files with 51 additions and 19 deletions
|
@ -27,8 +27,12 @@
|
||||||
*/
|
*/
|
||||||
package mage.sets.eldritchmoon;
|
package mage.sets.eldritchmoon;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import mage.MageObjectReference;
|
||||||
|
import mage.abilities.Ability;
|
||||||
import mage.abilities.TriggeredAbility;
|
import mage.abilities.TriggeredAbility;
|
||||||
import mage.abilities.common.BeginningOfYourEndStepTriggeredAbility;
|
import mage.abilities.common.BeginningOfYourEndStepTriggeredAbility;
|
||||||
import mage.abilities.common.SimpleStaticAbility;
|
import mage.abilities.common.SimpleStaticAbility;
|
||||||
|
@ -36,7 +40,6 @@ import mage.abilities.condition.CompoundCondition;
|
||||||
import mage.abilities.condition.Condition;
|
import mage.abilities.condition.Condition;
|
||||||
import mage.abilities.condition.InvertCondition;
|
import mage.abilities.condition.InvertCondition;
|
||||||
import mage.abilities.condition.common.AttachedCondition;
|
import mage.abilities.condition.common.AttachedCondition;
|
||||||
import mage.abilities.condition.common.WatcherCondition;
|
|
||||||
import mage.abilities.costs.mana.GenericManaCost;
|
import mage.abilities.costs.mana.GenericManaCost;
|
||||||
import mage.abilities.decorator.ConditionalTriggeredAbility;
|
import mage.abilities.decorator.ConditionalTriggeredAbility;
|
||||||
import mage.abilities.effects.common.SacrificeEquippedEffect;
|
import mage.abilities.effects.common.SacrificeEquippedEffect;
|
||||||
|
@ -50,6 +53,7 @@ import mage.game.events.GameEvent;
|
||||||
import mage.game.permanent.Permanent;
|
import mage.game.permanent.Permanent;
|
||||||
import mage.watchers.Watcher;
|
import mage.watchers.Watcher;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Quercitron
|
* @author Quercitron
|
||||||
|
@ -67,12 +71,12 @@ public class ThirstingAxe extends CardImpl {
|
||||||
// At the beginning of your end step, if equipped creature didn't deal combat damage to a creature this turn, sacrifice it.
|
// At the beginning of your end step, if equipped creature didn't deal combat damage to a creature this turn, sacrifice it.
|
||||||
TriggeredAbility ability = new BeginningOfYourEndStepTriggeredAbility(new SacrificeEquippedEffect(), false);
|
TriggeredAbility ability = new BeginningOfYourEndStepTriggeredAbility(new SacrificeEquippedEffect(), false);
|
||||||
Condition condition = new CompoundCondition(
|
Condition condition = new CompoundCondition(
|
||||||
new AttachedCondition(),
|
AttachedCondition.getInstance(),
|
||||||
new InvertCondition(new WatcherCondition(CombatDamageToCreatureByEquippedWatcher.BASIC_KEY, WatcherScope.CARD)));
|
new InvertCondition(new EquippedDealtCombatDamageToCreatureCondition()));
|
||||||
String triggeredAbilityText = "At the beginning of your end step, if equipped creature " +
|
String triggeredAbilityText = "At the beginning of your end step, if equipped creature " +
|
||||||
"didn't deal combat damage to a creature this turn, sacrifice it.";
|
"didn't deal combat damage to a creature this turn, sacrifice it.";
|
||||||
ConditionalTriggeredAbility sacrificeTriggeredAbility = new ConditionalTriggeredAbility(ability, condition, triggeredAbilityText);
|
ConditionalTriggeredAbility sacrificeTriggeredAbility = new ConditionalTriggeredAbility(ability, condition, triggeredAbilityText);
|
||||||
this.addAbility(sacrificeTriggeredAbility, new CombatDamageToCreatureByEquippedWatcher());
|
this.addAbility(sacrificeTriggeredAbility, new CombatDamageToCreatureWatcher());
|
||||||
|
|
||||||
// Equip {2}
|
// Equip {2}
|
||||||
this.addAbility(new EquipAbility(Outcome.AddAbility, new GenericManaCost(2)));
|
this.addAbility(new EquipAbility(Outcome.AddAbility, new GenericManaCost(2)));
|
||||||
|
@ -88,34 +92,62 @@ public class ThirstingAxe extends CardImpl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class CombatDamageToCreatureByEquippedWatcher extends Watcher {
|
class EquippedDealtCombatDamageToCreatureCondition implements Condition {
|
||||||
|
|
||||||
public final static String BASIC_KEY = "CombatDamageToCreatureByEquippedWatcher";
|
@Override
|
||||||
|
public boolean apply(Game game, Ability source) {
|
||||||
public CombatDamageToCreatureByEquippedWatcher() {
|
Permanent equipment = game.getPermanent(source.getSourceId());
|
||||||
super(BASIC_KEY, WatcherScope.CARD);
|
if (equipment != null && equipment.getAttachedTo() != null) {
|
||||||
|
CombatDamageToCreatureWatcher watcher =
|
||||||
|
(CombatDamageToCreatureWatcher) game.getState().getWatchers().get(CombatDamageToCreatureWatcher.BASIC_KEY);
|
||||||
|
return watcher.dealtDamage(equipment.getAttachedTo(), equipment.getAttachedToZoneChangeCounter(), game);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CombatDamageToCreatureByEquippedWatcher(final CombatDamageToCreatureByEquippedWatcher watcher) {
|
}
|
||||||
|
|
||||||
|
class CombatDamageToCreatureWatcher extends Watcher {
|
||||||
|
|
||||||
|
// which objects dealt combat damage to creature during the turn
|
||||||
|
public final Set<MageObjectReference> dealtCombatDamageToCreature;
|
||||||
|
|
||||||
|
public final static String BASIC_KEY = "CombatDamageToCreatureWatcher";
|
||||||
|
|
||||||
|
public CombatDamageToCreatureWatcher() {
|
||||||
|
super(BASIC_KEY, WatcherScope.GAME);
|
||||||
|
dealtCombatDamageToCreature = new HashSet<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public CombatDamageToCreatureWatcher(final CombatDamageToCreatureWatcher watcher) {
|
||||||
super(watcher);
|
super(watcher);
|
||||||
|
dealtCombatDamageToCreature = new HashSet<>(watcher.dealtCombatDamageToCreature);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CombatDamageToCreatureByEquippedWatcher copy() {
|
public CombatDamageToCreatureWatcher copy() {
|
||||||
return new CombatDamageToCreatureByEquippedWatcher(this);
|
return new CombatDamageToCreatureWatcher(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void watch(GameEvent event, Game game) {
|
public void watch(GameEvent event, Game game) {
|
||||||
if (event.getType() == GameEvent.EventType.DAMAGED_CREATURE) {
|
if (event.getType() == GameEvent.EventType.DAMAGED_CREATURE) {
|
||||||
Permanent equipment = game.getPermanent(this.getSourceId());
|
|
||||||
if (equipment != null && equipment.getAttachedTo() != null) {
|
|
||||||
if (equipment.getAttachedTo().equals(event.getSourceId())) {
|
|
||||||
if (((DamagedCreatureEvent) event).isCombatDamage()) {
|
if (((DamagedCreatureEvent) event).isCombatDamage()) {
|
||||||
condition = true;
|
MageObjectReference damageSource = new MageObjectReference(event.getSourceId(), game);
|
||||||
|
dealtCombatDamageToCreature.add(damageSource);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reset() {
|
||||||
|
super.reset();
|
||||||
|
dealtCombatDamageToCreature.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean dealtDamage(UUID objectId, int zoneChangeCounter, Game game) {
|
||||||
|
MageObjectReference reference = new MageObjectReference(objectId, zoneChangeCounter, game);
|
||||||
|
return dealtCombatDamageToCreature.contains(reference);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue