mirror of
https://github.com/magefree/mage.git
synced 2025-12-28 22:42:03 -08:00
[LTR] Implement Barrow-Blade (#10539)
* [LTR] Implement Barrow-Blade * Took ideas from Wooden Stake, Humble and Shadowspear * Play tested effects * Simpler constructor for equip * Revamped BlocksOrBlockedAttachedTriggeredAbility * New logic in `BlocksOrBlockedAttachedTriggeredAbility` * Changed `Ferocity` and `Gift Of The Woods` * Removed custom class from `Barrow Blade` * New class, revert changes in cards * Added the new class `BlocksOrBlockedByCreatureAttachedTriggeredAbility()` * Reverted changes to `BlocksOrBlockedAttachedTriggeredAbility()` but including `AttachmentType` in constructor * Reverted changes to `Ferocity` and `GiftOfTheWoods` * Changed `Barrow-Blade` to use `BlocksOrBlockedByCreatureAttachedTriggeredAbility()` * Added a few comments * Tried optimizing the IF statements in the new class but whenever I tried some condition would stop working, accepting suggestions * Null check added * Added a null check for game.getPermanent(sourceId) * Changed checks to the top to avoid unnecessary processing when encountering any null variable * Removed unnecessary import
This commit is contained in:
parent
1f0189a098
commit
6a20840f4e
6 changed files with 156 additions and 6 deletions
|
|
@ -2,6 +2,7 @@ package mage.abilities.common;
|
|||
|
||||
import mage.abilities.TriggeredAbilityImpl;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.constants.AttachmentType;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
|
|
@ -13,16 +14,22 @@ import mage.target.targetpointer.FixedTarget;
|
|||
*/
|
||||
public class BlocksOrBlockedAttachedTriggeredAbility extends TriggeredAbilityImpl {
|
||||
|
||||
public BlocksOrBlockedAttachedTriggeredAbility(Effect effect) {
|
||||
this(effect, false);
|
||||
// Type of attachment: AURA or EQUIPMENT
|
||||
private final AttachmentType attachmentType;
|
||||
|
||||
public BlocksOrBlockedAttachedTriggeredAbility(Effect effect, AttachmentType attachmentType) {
|
||||
this(effect, attachmentType, false);
|
||||
}
|
||||
public BlocksOrBlockedAttachedTriggeredAbility(Effect effect, boolean optional) {
|
||||
|
||||
public BlocksOrBlockedAttachedTriggeredAbility(Effect effect, AttachmentType attachmentType, boolean optional) {
|
||||
super(Zone.BATTLEFIELD, effect, optional);
|
||||
setTriggerPhrase("Whenever enchanted creature blocks or becomes blocked, ");
|
||||
setTriggerPhrase("Whenever " + attachmentType.verb().toLowerCase() + " creature blocks or becomes blocked, ");
|
||||
this.attachmentType = attachmentType;
|
||||
}
|
||||
|
||||
public BlocksOrBlockedAttachedTriggeredAbility(final BlocksOrBlockedAttachedTriggeredAbility ability) {
|
||||
super(ability);
|
||||
this.attachmentType = ability.attachmentType;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -0,0 +1,90 @@
|
|||
package mage.abilities.common;
|
||||
|
||||
import mage.abilities.TriggeredAbilityImpl;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.constants.AttachmentType;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.target.targetpointer.FixedTarget;
|
||||
|
||||
/**
|
||||
* @author TiagoMDG
|
||||
*/
|
||||
public class BlocksOrBlockedByCreatureAttachedTriggeredAbility extends TriggeredAbilityImpl {
|
||||
|
||||
// Type of attachment AURA or EQUIPMENT
|
||||
private final AttachmentType attachmentType;
|
||||
|
||||
// Controls if the effect should target the creature with the attachment or the blocking/blocked creature
|
||||
private final boolean selfTarget;
|
||||
|
||||
public BlocksOrBlockedByCreatureAttachedTriggeredAbility(Effect effect, AttachmentType attachmentType, boolean selfTarget) {
|
||||
this(effect, attachmentType, selfTarget, false);
|
||||
}
|
||||
|
||||
public BlocksOrBlockedByCreatureAttachedTriggeredAbility(Effect effect, AttachmentType attachmentType, boolean selfTarget, boolean optional) {
|
||||
super(Zone.BATTLEFIELD, effect, optional);
|
||||
setTriggerPhrase("Whenever " + attachmentType.verb().toLowerCase() + " creature blocks or becomes blocked, ");
|
||||
this.attachmentType = attachmentType;
|
||||
this.selfTarget = selfTarget;
|
||||
}
|
||||
|
||||
public BlocksOrBlockedByCreatureAttachedTriggeredAbility(final BlocksOrBlockedByCreatureAttachedTriggeredAbility ability) {
|
||||
super(ability);
|
||||
this.attachmentType = ability.attachmentType;
|
||||
this.selfTarget = ability.selfTarget;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkEventType(GameEvent event, Game game) {
|
||||
return event.getType() == GameEvent.EventType.BLOCKER_DECLARED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
Permanent blockingCreature = game.getPermanent(event.getSourceId());
|
||||
Permanent blockedCreature = game.getPermanent(event.getTargetId());
|
||||
Permanent attachment = game.getPermanent(sourceId);
|
||||
|
||||
if (attachment == null || blockingCreature == null || blockedCreature == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Permanent attachedCreature = game.getPermanent(attachment.getAttachedTo());
|
||||
|
||||
if (attachedCreature == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!selfTarget) {
|
||||
if (blockedCreature.equals(attachedCreature)) {
|
||||
getEffects().setTargetPointer(new FixedTarget(blockingCreature, game));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (blockingCreature.equals(attachedCreature)) {
|
||||
getEffects().setTargetPointer(new FixedTarget(blockedCreature, game));
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (blockedCreature.equals(attachedCreature)) {
|
||||
getEffects().setTargetPointer(new FixedTarget(blockedCreature, game));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (blockingCreature.equals(attachedCreature)) {
|
||||
getEffects().setTargetPointer(new FixedTarget(blockingCreature, game));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BlocksOrBlockedByCreatureAttachedTriggeredAbility copy() {
|
||||
return new BlocksOrBlockedByCreatureAttachedTriggeredAbility(this);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue