mirror of
https://github.com/magefree/mage.git
synced 2025-12-26 13:32:06 -08:00
Fix BecomesBlockedAttachedTriggeredAbility (#9325)
This commit is contained in:
parent
4b511775db
commit
516ac042a2
13 changed files with 134 additions and 433 deletions
|
|
@ -9,7 +9,7 @@ import mage.game.events.GameEvent;
|
|||
import mage.game.permanent.Permanent;
|
||||
import mage.target.targetpointer.FixedTarget;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author L_J
|
||||
|
|
@ -39,16 +39,21 @@ public class BecomesBlockedAttachedTriggeredAbility extends TriggeredAbilityImpl
|
|||
|
||||
@Override
|
||||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
Permanent permanent = Optional
|
||||
.ofNullable(getSourcePermanentOrLKI(game))
|
||||
.map(Permanent::getAttachedTo)
|
||||
.map(game::getPermanent)
|
||||
.orElse(null);
|
||||
if (permanent == null) {
|
||||
Permanent enchantment = getSourcePermanentOrLKI(game);
|
||||
UUID blockedId = event.getTargetId();
|
||||
if (enchantment == null || !blockedId.equals(enchantment.getAttachedTo())) {
|
||||
return false;
|
||||
}
|
||||
if (setTargetPointer == SetTargetPointer.PERMANENT) {
|
||||
this.getEffects().setTargetPointer(new FixedTarget(permanent, game));
|
||||
switch (setTargetPointer) {
|
||||
case PERMANENT:
|
||||
getEffects().setTargetPointer(new FixedTarget(blockedId, game));
|
||||
break;
|
||||
case PLAYER:
|
||||
UUID playerId = game.getCombat().getDefendingPlayerId(blockedId, game);
|
||||
if (playerId != null) {
|
||||
getEffects().setTargetPointer(new FixedTarget(playerId));
|
||||
}
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
package mage.abilities.effects.common.continuous;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
|
|
@ -16,21 +15,17 @@ import mage.game.events.GameEvent;
|
|||
|
||||
public class AssignNoCombatDamageSourceEffect extends ReplacementEffectImpl {
|
||||
|
||||
private boolean partOfOptionalEffect;
|
||||
|
||||
public AssignNoCombatDamageSourceEffect(Duration duration) {
|
||||
this(duration, false);
|
||||
}
|
||||
|
||||
public AssignNoCombatDamageSourceEffect(Duration duration, boolean partOfOptionalEffect) {
|
||||
super(duration, Outcome.PreventDamage);
|
||||
this.partOfOptionalEffect = partOfOptionalEffect;
|
||||
staticText = setText();
|
||||
staticText = setText(partOfOptionalEffect);
|
||||
}
|
||||
|
||||
public AssignNoCombatDamageSourceEffect(final AssignNoCombatDamageSourceEffect effect) {
|
||||
super(effect);
|
||||
this.partOfOptionalEffect = effect.partOfOptionalEffect;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -65,12 +60,8 @@ public class AssignNoCombatDamageSourceEffect extends ReplacementEffectImpl {
|
|||
return event.getSourceId().equals(source.getSourceId()) && damageEvent.isCombatDamage();
|
||||
}
|
||||
|
||||
private String setText() {
|
||||
String text = "";
|
||||
if(partOfOptionalEffect) {
|
||||
text = "If you do, ";
|
||||
}
|
||||
text += "{this} assigns no combat damage";
|
||||
private String setText(boolean partOfOptionalEffect) {
|
||||
String text = (partOfOptionalEffect ? "If you do, " : "") + "{this} assigns no combat damage";
|
||||
switch(duration) {
|
||||
case EndOfTurn:
|
||||
text += " this turn";
|
||||
|
|
|
|||
|
|
@ -0,0 +1,61 @@
|
|||
package mage.abilities.effects.common.continuous;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.effects.ReplacementEffectImpl;
|
||||
import mage.constants.Duration;
|
||||
import mage.constants.Outcome;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.DamageEvent;
|
||||
import mage.game.events.GameEvent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author awjackson
|
||||
*/
|
||||
|
||||
public class AssignNoCombatDamageTargetEffect extends ReplacementEffectImpl {
|
||||
|
||||
public AssignNoCombatDamageTargetEffect() {
|
||||
this(Duration.EndOfTurn, "if you do, it assigns no combat damage this turn");
|
||||
}
|
||||
|
||||
public AssignNoCombatDamageTargetEffect(Duration duration, String text) {
|
||||
super(duration, Outcome.PreventDamage);
|
||||
staticText = text;
|
||||
}
|
||||
|
||||
public AssignNoCombatDamageTargetEffect(final AssignNoCombatDamageTargetEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AssignNoCombatDamageTargetEffect copy() {
|
||||
return new AssignNoCombatDamageTargetEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checksEventType(GameEvent event, Game game) {
|
||||
switch (event.getType()) {
|
||||
case DAMAGE_PERMANENT:
|
||||
case DAMAGE_PLAYER:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean applies(GameEvent event, Ability source, Game game) {
|
||||
return ((DamageEvent) event).isCombatDamage() && event.getSourceId().equals(targetPointer.getFirst(game, source));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue