[CHK] updated implementation of Hankyu

This commit is contained in:
Evan Kranzler 2022-02-24 22:07:31 -05:00
parent bf699b5559
commit 1c107cde01

View file

@ -4,11 +4,14 @@ import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.costs.Cost;
import mage.abilities.costs.CostImpl;
import mage.abilities.costs.UseAttachedCost;
import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.costs.mana.GenericManaCost;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.continuous.GainAbilityAttachedEffect;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.DamageTargetEffect;
import mage.abilities.effects.common.counter.AddCountersTargetEffect;
import mage.abilities.keyword.EquipAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
@ -16,13 +19,14 @@ import mage.constants.*;
import mage.counters.CounterType;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.common.TargetAnyTarget;
import mage.target.targetpointer.FixedTarget;
import mage.util.CardUtil;
import java.util.UUID;
/**
* @author North
* @author TheElk801
*/
public final class Hankyu extends CardImpl {
@ -30,18 +34,8 @@ public final class Hankyu extends CardImpl {
super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{1}");
this.subtype.add(SubType.EQUIPMENT);
/* Equipped creature has "{T}: Put an aim counter on Hankyu" and */
SimpleActivatedAbility ability1 = new SimpleActivatedAbility(Zone.BATTLEFIELD, new HankyuAddCounterEffect(this.getId()), new TapSourceCost());
ability1.setSourceId(this.getId()); // to know where to put the counters on
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new GainAbilityAttachedEffect(ability1, AttachmentType.EQUIPMENT)));
/* "{T}, Remove all aim counters from Hankyu: This creature deals
* damage to any target equal to the number of
* aim counters removed this way." */
SimpleActivatedAbility ability2 = new SimpleActivatedAbility(Zone.BATTLEFIELD, new HankyuDealsDamageEffect(), new TapSourceCost());
ability2.addCost(new HankyuCountersSourceCost(this.getId()));
ability2.addTarget(new TargetAnyTarget());
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new GainAbilityAttachedEffect(ability2, AttachmentType.EQUIPMENT)));
// Equipped creature has "{T}: Put an aim counter on {this}" and "{T}, Remove all aim counters from {this}: This creature deals damage to any target equal to the number of aim counters removed this way."
this.addAbility(new SimpleStaticAbility(new HankyuEffect()));
// Equip {4} ({4}: Attach to target creature you control. Equip only as a sorcery.)
this.addAbility(new EquipAbility(Outcome.BoostCreature, new GenericManaCost(4)));
@ -57,121 +51,121 @@ public final class Hankyu extends CardImpl {
}
}
class HankyuAddCounterEffect extends OneShotEffect {
class HankyuEffect extends ContinuousEffectImpl {
private UUID effectGivingEquipmentId;
public HankyuAddCounterEffect(UUID effectGivingEquipmentId) {
super(Outcome.Benefit);
this.effectGivingEquipmentId = effectGivingEquipmentId;
staticText = "Put an aim counter on Hankyu";
HankyuEffect() {
super(Duration.WhileOnBattlefield, Layer.AbilityAddingRemovingEffects_6, SubLayer.NA, Outcome.AddAbility);
staticText = "equipped creature has \"{T}: Put an aim counter on {this}\" and " +
"\"{T}, Remove all aim counters from {this}: This creature deals damage " +
"to any target equal to the number of aim counters removed this way.\"";
}
public HankyuAddCounterEffect(final HankyuAddCounterEffect effect) {
private HankyuEffect(final HankyuEffect effect) {
super(effect);
this.effectGivingEquipmentId = effect.effectGivingEquipmentId;
}
@Override
public HankyuEffect copy() {
return new HankyuEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Permanent equipment = game.getPermanent(this.effectGivingEquipmentId);
if (equipment != null) {
equipment.addCounters(CounterType.AIM.createInstance(), source.getControllerId(), source, game);
Permanent permanent = source.getSourcePermanentIfItStillExists(game);
if (permanent == null) {
return false;
}
Permanent creature = game.getPermanent(permanent.getAttachedTo());
if (creature == null) {
return false;
}
creature.addAbility(new SimpleActivatedAbility(
new AddCountersTargetEffect(CounterType.AIM.createInstance())
.setTargetPointer(new FixedTarget(permanent, game))
.setText("put an aim counter on " + permanent.getName()),
new TapSourceCost()
), source.getSourceId(), game);
Ability ability = new SimpleActivatedAbility(
new DamageTargetEffect(HankyuValue.instance)
.setText("this creature deals damage to any target equal " +
"to the number of aim counters removed this way"),
new TapSourceCost()
);
ability.addCost(new HankyuCost().setMageObjectReference(source, game));
ability.addTarget(new TargetAnyTarget());
creature.addAbility(ability, source.getSourceId(), game);
return true;
}
@Override
public HankyuAddCounterEffect copy() {
return new HankyuAddCounterEffect(this);
}
}
enum HankyuValue implements DynamicValue {
instance;
class HankyuDealsDamageEffect extends OneShotEffect {
public HankyuDealsDamageEffect() {
super(Outcome.Damage);
staticText = "This creature deals damage to any target equal to the number of aim counters removed this way";
}
public HankyuDealsDamageEffect(final HankyuDealsDamageEffect effect) {
super(effect);
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
return CardUtil.castStream(
sourceAbility.getCosts().stream(), HankyuCost.class
).mapToInt(HankyuCost::getRemovedCounters).sum();
}
@Override
public HankyuDealsDamageEffect copy() {
return new HankyuDealsDamageEffect(this);
public HankyuValue copy() {
return this;
}
@Override
public boolean apply(Game game, Ability source) {
// get the number of removed counters as damage amount
HankyuCountersSourceCost cost = (HankyuCountersSourceCost) source.getCosts().get(1);
if (cost != null) {
int damageAmount = cost.getRemovedCounters();
if (damageAmount > 0) {
Permanent permanent = game.getPermanent(source.getFirstTarget());
if (permanent != null) {
permanent.damage(damageAmount, source.getSourceId(), source, game, false, true);
}
Player player = game.getPlayer(source.getFirstTarget());
if (player != null) {
player.damage(damageAmount, source.getSourceId(), source, game);
}
}
return true;
}
return false;
public String getMessage() {
return "";
}
}
class HankyuCountersSourceCost extends CostImpl {
class HankyuCost extends UseAttachedCost {
private int removedCounters;
private UUID effectGivingEquipmentId;
private int removedCounters = 0;
public HankyuCountersSourceCost(UUID effectGivingEquipmentId) {
HankyuCost() {
super();
this.removedCounters = 0;
this.effectGivingEquipmentId = effectGivingEquipmentId;
this.text = "Remove all aim counters from Hankyu";
}
public HankyuCountersSourceCost(HankyuCountersSourceCost cost) {
private HankyuCost(final HankyuCost cost) {
super(cost);
this.effectGivingEquipmentId = cost.effectGivingEquipmentId;
this.removedCounters = cost.removedCounters;
}
@Override
public boolean canPay(Ability ability, Ability source, UUID controllerId, Game game) {
return true;
}
@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
Permanent equipment = game.getPermanent(this.effectGivingEquipmentId);
if (equipment != null) {
this.removedCounters = equipment.getCounters(game).getCount(CounterType.AIM);
if (this.removedCounters > 0) {
equipment.removeCounters("aim", this.removedCounters, source, game);
}
if (mageObjectReference == null) {
return false;
}
this.paid = true;
return true;
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent == null) {
return paid;
}
for (UUID attachmentId : permanent.getAttachments()) {
if (!this.mageObjectReference.refersTo(attachmentId, game)) {
continue;
}
int count = permanent.getCounters(game).getCount(CounterType.AIM);
permanent.removeCounters(CounterType.AIM.createInstance(count), source, game);
paid = true;
removedCounters = count;
break;
}
return paid;
}
@Override
public HankyuCountersSourceCost copy() {
return new HankyuCountersSourceCost(this);
public HankyuCost copy() {
return new HankyuCost(this);
}
@Override
public String getText() {
return "remove all aim counters from " + this.name;
}
public int getRemovedCounters() {
return this.removedCounters;
return removedCounters;
}
}