Skip to content

Commit

Permalink
[WHO] added Ace's Baseball Bat, consolidate related code (#11387)
Browse files Browse the repository at this point in the history
* TalruumPiper use MustBeBlockedByAllSourceEffect

* Both of Bident Of Thassa's abilities can be made generic

* Goblin Diplomats use generic class (with custom text)

* create MustBeBlockedByAtLeastOneAttachedEffect common effect

* Add Ace's Baseball Bat
  • Loading branch information
ssk97 authored Nov 4, 2023
1 parent 0fbeb10 commit 52bb2c5
Show file tree
Hide file tree
Showing 9 changed files with 225 additions and 280 deletions.
86 changes: 86 additions & 0 deletions Mage.Sets/src/mage/cards/a/AcesBaseballBat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package mage.cards.a;

import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.condition.Condition;
import mage.abilities.costs.mana.GenericManaCost;
import mage.abilities.decorator.ConditionalContinuousEffect;
import mage.abilities.effects.common.combat.MustBeBlockedByAtLeastOneAttachedEffect;
import mage.abilities.effects.common.continuous.BoostEquippedEffect;
import mage.abilities.effects.common.continuous.GainAbilityAttachedEffect;
import mage.abilities.keyword.EquipAbility;
import mage.abilities.keyword.FirstStrikeAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.*;
import mage.filter.common.FilterControlledCreaturePermanent;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.target.common.TargetControlledCreaturePermanent;

import java.util.UUID;

/**
* @author notgreat
*/
public final class AcesBaseballBat extends CardImpl {

private static final FilterControlledCreaturePermanent filterLegendary
= new FilterControlledCreaturePermanent("legendary creature");
static {
filterLegendary.add(SuperType.LEGENDARY.getPredicate());
}

private static final FilterControlledCreaturePermanent filterDalek
= new FilterControlledCreaturePermanent("a Dalek");
static {
filterDalek.add(SubType.DALEK.getPredicate());
}

public AcesBaseballBat(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{2}");
this.supertype.add(SuperType.LEGENDARY);
this.subtype.add(SubType.EQUIPMENT);

// Equipped creature gets +3/+0
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostEquippedEffect(3, 0)));

// As long as equipped creature is attacking, it has first strike and must be blocked by a Dalek if able.
Ability ability = new SimpleStaticAbility(new ConditionalContinuousEffect(
new GainAbilityAttachedEffect(FirstStrikeAbility.getInstance(), AttachmentType.EQUIPMENT),
AttachedToAttackingCondition.instance, "As long as equipped creature is attacking, it has first strike"));
ability.addEffect(new MustBeBlockedByAtLeastOneAttachedEffect(filterDalek).concatBy("and"));
this.addAbility(ability);

// Equip legendary creature (1)
this.addAbility(new EquipAbility(Outcome.AddAbility, new GenericManaCost(1), new TargetControlledCreaturePermanent(filterLegendary), false));

// Equip {3}
this.addAbility(new EquipAbility(Outcome.AddAbility, new GenericManaCost(3), false));
}

private AcesBaseballBat(final AcesBaseballBat card) {
super(card);
}

@Override
public AcesBaseballBat copy() {
return new AcesBaseballBat(this);
}
}
enum AttachedToAttackingCondition implements Condition {
instance;

@Override
public boolean apply(Game game, Ability source) {
Permanent attachment = game.getPermanent(source.getSourceId());
if (attachment == null || attachment.getAttachedTo() == null) {
return false;
}
Permanent attachedTo = game.getPermanent(attachment.getAttachedTo());
if (attachedTo == null) {
return false;
}
return attachedTo.isAttacking();
}
}
92 changes: 10 additions & 82 deletions Mage.Sets/src/mage/cards/b/BidentOfThassa.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,20 @@

import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.common.DealsDamageToAPlayerAllTriggeredAbility;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.RequirementEffect;
import mage.abilities.effects.common.DrawCardSourceControllerEffect;
import mage.abilities.effects.common.combat.AttacksIfAbleAllEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.SuperType;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.DamagedPlayerEvent;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.permanent.Permanent;
import mage.constants.SetTargetPointer;
import mage.filter.StaticFilters;

/**
*
Expand All @@ -33,9 +30,13 @@ public BidentOfThassa(UUID ownerId, CardSetInfo setInfo) {


// Whenever a creature you control deals combat damage to a player, you may draw a card.
this.addAbility(new BidentOfThassaTriggeredAbility());
this.addAbility(new DealsDamageToAPlayerAllTriggeredAbility(
new DrawCardSourceControllerEffect(1),
StaticFilters.FILTER_CONTROLLED_A_CREATURE,
true, SetTargetPointer.NONE, true
));
// {1}{U}, {T}: Creatures your opponents control attack this turn if able.
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new BidentOfThassaMustAttackEffect(), new ManaCostsImpl<>("{1}{U}"));
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new AttacksIfAbleAllEffect(StaticFilters.FILTER_OPPONENTS_PERMANENT_CREATURES,Duration.EndOfTurn), new ManaCostsImpl<>("{1}{U}"));
ability.addCost(new TapSourceCost());
this.addAbility(ability);
}
Expand All @@ -49,76 +50,3 @@ public BidentOfThassa copy() {
return new BidentOfThassa(this);
}
}

class BidentOfThassaTriggeredAbility extends TriggeredAbilityImpl {

public BidentOfThassaTriggeredAbility() {
super(Zone.BATTLEFIELD, new DrawCardSourceControllerEffect(1), true);
}

private BidentOfThassaTriggeredAbility(final BidentOfThassaTriggeredAbility ability) {
super(ability);
}

@Override
public BidentOfThassaTriggeredAbility copy() {
return new BidentOfThassaTriggeredAbility(this);
}

@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.DAMAGED_PLAYER;
}

@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (((DamagedPlayerEvent) event).isCombatDamage()) {
Permanent creature = game.getPermanent(event.getSourceId());
if (creature != null && creature.isControlledBy(controllerId)) {
return true;
}
}
return false;
}

@Override
public String getRule() {
return " Whenever a creature you control deals combat damage to a player, you may draw a card.";
}
}

class BidentOfThassaMustAttackEffect extends RequirementEffect {

public BidentOfThassaMustAttackEffect() {
super(Duration.EndOfTurn);
staticText = "Creatures your opponents control attack this turn if able";
}

private BidentOfThassaMustAttackEffect(final BidentOfThassaMustAttackEffect effect) {
super(effect);
}

@Override
public BidentOfThassaMustAttackEffect copy() {
return new BidentOfThassaMustAttackEffect(this);
}

@Override
public boolean applies(Permanent permanent, Ability source, Game game) {
if (game.getOpponents(source.getControllerId()).contains(permanent.getControllerId())) {
return true;
}
return false;
}

@Override
public boolean mustAttack(Game game) {
return true;
}

@Override
public boolean mustBlock(Game game) {
return false;
}

}
46 changes: 6 additions & 40 deletions Mage.Sets/src/mage/cards/g/GoblinDiplomats.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@

import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.effects.RequirementEffect;
import mage.abilities.effects.common.combat.AttacksIfAbleAllEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.constants.Duration;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.filter.StaticFilters;

/**
*
Expand All @@ -30,7 +28,10 @@ public GoblinDiplomats(UUID ownerId, CardSetInfo setInfo) {
this.toughness = new MageInt(1);

// {T}: Each creature attacks this turn if able.
this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new GoblinDiplomatsEffect(), new TapSourceCost()));
this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD,
new AttacksIfAbleAllEffect(StaticFilters.FILTER_PERMANENT_ALL_CREATURES, Duration.EndOfTurn)
.setText("Each creature attacks this turn if able"),
new TapSourceCost()));

}

Expand All @@ -43,38 +44,3 @@ public GoblinDiplomats copy() {
return new GoblinDiplomats(this);
}
}

class GoblinDiplomatsEffect extends RequirementEffect {

public GoblinDiplomatsEffect() {
super(Duration.EndOfTurn);
this.staticText = "Each creature attacks this turn if able";
}

private GoblinDiplomatsEffect(final GoblinDiplomatsEffect effect) {
super(effect);
}

@Override
public GoblinDiplomatsEffect copy() {
return new GoblinDiplomatsEffect(this);
}

@Override
public boolean applies(Permanent permanent, Ability source, Game game) {
if (permanent != null) {
return true;
}
return false;
}

@Override
public boolean mustAttack(Game game) {
return true;
}

@Override
public boolean mustBlock(Game game) {
return false;
}
}
56 changes: 2 additions & 54 deletions Mage.Sets/src/mage/cards/p/PredatoryImpetus.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@

import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.RequirementEffect;
import mage.abilities.effects.common.AttachEffect;
import mage.abilities.effects.common.combat.GoadAttachedEffect;
import mage.abilities.effects.common.combat.MustBeBlockedByAtLeastOneAttachedEffect;
import mage.abilities.effects.common.continuous.BoostEnchantedEffect;
import mage.abilities.keyword.EnchantAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.SubType;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.target.TargetPermanent;
import mage.target.common.TargetCreaturePermanent;

Expand All @@ -39,7 +36,7 @@ public PredatoryImpetus(UUID ownerId, CardSetInfo setInfo) {

// Enchanted creature gets +3/+3, must be blocked if able, and is goaded.
ability = new SimpleStaticAbility(new BoostEnchantedEffect(3, 3));
ability.addEffect(new PredatoryImpetusEffect());
ability.addEffect(new MustBeBlockedByAtLeastOneAttachedEffect().concatBy(","));
ability.addEffect(new GoadAttachedEffect().concatBy(","));
this.addAbility(ability);
}
Expand All @@ -53,52 +50,3 @@ public PredatoryImpetus copy() {
return new PredatoryImpetus(this);
}
}

class PredatoryImpetusEffect extends RequirementEffect {

PredatoryImpetusEffect() {
super(Duration.WhileOnBattlefield);
staticText = ", must be blocked if able";
}

private PredatoryImpetusEffect(final PredatoryImpetusEffect effect) {
super(effect);
}

@Override
public boolean applies(Permanent permanent, Ability source, Game game) {
Permanent attachment = game.getPermanent(source.getSourceId());
if (attachment == null || attachment.getAttachedTo() == null) {
return false;
}
Permanent attachedCreature = game.getPermanent(attachment.getAttachedTo());
return attachedCreature != null && attachedCreature.isAttacking()
&& permanent.canBlock(attachment.getAttachedTo(), game);
}

@Override
public boolean mustAttack(Game game) {
return false;
}

@Override
public boolean mustBlock(Game game) {
return false;
}

@Override
public UUID mustBlockAttackerIfElseUnblocked(Ability source, Game game) {
Permanent attachment = game.getPermanent(source.getSourceId());
return attachment == null ? null : attachment.getAttachedTo();
}

@Override
public int getMinNumberOfBlockers() {
return 1;
}

@Override
public PredatoryImpetusEffect copy() {
return new PredatoryImpetusEffect(this);
}
}
Loading

0 comments on commit 52bb2c5

Please sign in to comment.