forked from External/mage
1a. Make `costs`, `manaCosts`, and `manaCostsToPay` private in `AbilityImpl` with access through getters/setters 1b. fix cost adjuster for imprinted cards affected by the above 2a. Lazy instantiation for rarely used `data` field in `TargetPointerImpl` 3a. Pre-allocate certain array sizes in `Modes` and `CostsImpl` 4a. Make `manaTemplate` private in `BasicManaEffect`, copy when passing outside the class 4b. Don't copy `manaTemplate` in copy constructor since it doesn't change 4c. Add comments explaining copy usage for `manaTemplate` 4d. Remove redundant variable assignment and make fields final --------- Co-authored-by: xenohedron <xenohedron@users.noreply.github.com>
91 lines
2.9 KiB
Java
91 lines
2.9 KiB
Java
package mage.abilities.keyword;
|
|
|
|
import mage.abilities.ActivatedAbilityImpl;
|
|
import mage.abilities.costs.Cost;
|
|
import mage.abilities.costs.mana.GenericManaCost;
|
|
import mage.abilities.effects.common.AttachEffect;
|
|
import mage.constants.Outcome;
|
|
import mage.constants.TimingRule;
|
|
import mage.constants.Zone;
|
|
import mage.target.Target;
|
|
import mage.target.common.TargetControlledCreaturePermanent;
|
|
|
|
/**
|
|
* @author BetaSteward_at_googlemail.com
|
|
*/
|
|
public class EquipAbility extends ActivatedAbilityImpl {
|
|
|
|
private String costReduceText = null;
|
|
private final boolean showAbilityHint;
|
|
|
|
public EquipAbility(int cost) {
|
|
this(cost, true);
|
|
}
|
|
|
|
public EquipAbility(int cost, boolean showAbilityHint) {
|
|
this(Outcome.AddAbility, new GenericManaCost(cost), showAbilityHint);
|
|
}
|
|
|
|
public EquipAbility(Outcome outcome, Cost cost) {
|
|
this(outcome, cost, true);
|
|
}
|
|
|
|
public EquipAbility(Outcome outcome, Cost cost, boolean showAbilityHint) {
|
|
this(outcome, cost, new TargetControlledCreaturePermanent(), showAbilityHint);
|
|
}
|
|
|
|
public EquipAbility(Outcome outcome, Cost cost, Target target) {
|
|
this(outcome, cost, target, true);
|
|
}
|
|
|
|
public EquipAbility(Outcome outcome, Cost cost, Target target, boolean showAbilityHint) {
|
|
super(Zone.BATTLEFIELD, new AttachEffect(outcome, "Equip"), cost);
|
|
this.addTarget(target);
|
|
this.timing = TimingRule.SORCERY;
|
|
this.showAbilityHint = showAbilityHint;
|
|
}
|
|
|
|
protected EquipAbility(final EquipAbility ability) {
|
|
super(ability);
|
|
this.costReduceText = ability.costReduceText;
|
|
this.showAbilityHint = ability.showAbilityHint;
|
|
}
|
|
|
|
public void setCostReduceText(String text) {
|
|
this.costReduceText = text;
|
|
}
|
|
|
|
@Override
|
|
public EquipAbility copy() {
|
|
return new EquipAbility(this);
|
|
}
|
|
|
|
@Override
|
|
public String getRule() {
|
|
String targetText = getTargets().get(0) != null ? getTargets().get(0).getFilter().getMessage() : "creature";
|
|
String reminderText = " <i>(" + getManaCosts().getText() + ": Attach to target " + targetText + ". Equip only as a sorcery.)</i>";
|
|
|
|
StringBuilder sb = new StringBuilder("Equip");
|
|
if (!targetText.equals("creature you control")) {
|
|
sb.append(' ').append(targetText);
|
|
}
|
|
String costText = getCosts().getText();
|
|
if (costText != null && !costText.isEmpty()) {
|
|
sb.append("—").append(costText).append('.');
|
|
} else {
|
|
sb.append(' ');
|
|
}
|
|
sb.append(getManaCosts().getText());
|
|
if (costReduceText != null && !costReduceText.isEmpty()) {
|
|
sb.append(". ");
|
|
sb.append(costReduceText);
|
|
}
|
|
if (maxActivationsPerTurn == 1) {
|
|
sb.append(". Activate only once each turn.");
|
|
}
|
|
if (showAbilityHint) {
|
|
sb.append(reminderText);
|
|
}
|
|
return sb.toString();
|
|
}
|
|
}
|