- Added requested card Volcano Hellion.

This commit is contained in:
Jeff 2017-07-20 11:15:58 -05:00
parent 44e85ca351
commit 7ffcf39260
3 changed files with 184 additions and 34 deletions

View file

@ -24,8 +24,7 @@
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
*/
package mage.abilities.keyword;
import java.util.UUID;
@ -36,6 +35,7 @@ import mage.abilities.costs.Cost;
import mage.abilities.costs.Costs;
import mage.abilities.costs.CostsImpl;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome;
import mage.constants.Zone;
@ -54,12 +54,25 @@ public class EchoAbility extends TriggeredAbilityImpl {
protected boolean echoPaid;
protected Costs<Cost> echoCosts = new CostsImpl<>();
private boolean manaEcho = true;
private DynamicValue amount;
private String rule;
public EchoAbility(String manaString) {
super(Zone.BATTLEFIELD, new EchoEffect(new ManaCostsImpl(manaString)), false);
this.echoPaid = false;
this.echoCosts.add(new ManaCostsImpl(manaString));
this.lastController = null;
this.rule = null;
}
public EchoAbility(DynamicValue amount, String rule) {
super(Zone.BATTLEFIELD, new EchoEffect(amount), false);
this.amount = amount;
this.echoPaid = false;
this.echoCosts.add(costs);
this.lastController = null;
this.manaEcho = true;
this.rule = rule;
}
public EchoAbility(Cost echoCost) {
@ -68,6 +81,7 @@ public class EchoAbility extends TriggeredAbilityImpl {
this.echoCosts.add(echoCost);
this.manaEcho = false;
this.lastController = null;
this.rule = null;
}
public EchoAbility(final EchoAbility ability) {
@ -76,6 +90,8 @@ public class EchoAbility extends TriggeredAbilityImpl {
this.echoCosts = ability.echoCosts.copy();
this.manaEcho = ability.manaEcho;
this.lastController = ability.lastController;
this.amount = ability.amount;
this.rule = ability.rule;
}
@Override
@ -85,7 +101,8 @@ public class EchoAbility extends TriggeredAbilityImpl {
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD || event.getType() == GameEvent.EventType.UPKEEP_STEP_PRE;
return event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD
|| event.getType() == GameEvent.EventType.UPKEEP_STEP_PRE;
}
@Override
@ -93,20 +110,21 @@ public class EchoAbility extends TriggeredAbilityImpl {
// reset the echo paid state back, if creature enteres the battlefield
if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD
&& event.getTargetId().equals(this.getSourceId())) {
this.echoPaid = false;
}
if (event.getType() == GameEvent.EventType.UPKEEP_STEP_PRE) {
if(lastController != null){
if(!lastController.equals(this.controllerId)){
if (lastController != null) {
if (!lastController.equals(this.controllerId)) {
this.echoPaid = false;
}
}
// remember the last controller
lastController = this.getControllerId();
// if echo not paid yet, controller has to pay
if (event.getPlayerId().equals(this.controllerId) &&
lastController.equals(this.controllerId) && !this.echoPaid){
if (event.getPlayerId().equals(this.controllerId)
&& lastController.equals(this.controllerId)
&& !this.echoPaid) {
this.echoPaid = true;
return true;
}
@ -116,45 +134,66 @@ public class EchoAbility extends TriggeredAbilityImpl {
@Override
public String getRule() {
StringBuilder sb = new StringBuilder("Echo");
if (manaEcho) {
sb.append(' ');
StringBuilder sb = new StringBuilder();
if (rule != null) {
sb.append(rule);
} else {
sb.append("&mdash;");
sb = new StringBuilder("Echo");
if (manaEcho) {
sb.append(' ');
} else {
sb.append("&mdash;");
}
if (echoCosts != null) {
sb.append(echoCosts.getText());
}
}
sb.append(echoCosts.getText());
sb.append(" <i>(At the beginning of your upkeep, if this came under your control since the beginning of your last upkeep, sacrifice it unless you pay its echo cost.)</i>");
return sb.toString();
}
}
class EchoEffect extends OneShotEffect {
protected Cost cost;
protected DynamicValue amount;
public EchoEffect(Cost costs) {
super(Outcome.Sacrifice);
this.cost = costs;
}
this.amount = null;
}
public EchoEffect(DynamicValue amount) {
super(Outcome.Sacrifice);
this.amount = amount;
this.cost = null;
}
public EchoEffect(final EchoEffect effect) {
super(effect);
this.cost = effect.cost;
this.amount = effect.amount;
}
@Override
public boolean apply(Game game, Ability source) {
if (amount != null) {
cost = new ManaCostsImpl(Integer.toString(amount.calculate(game, source, this)));
}
Player controller = game.getPlayer(source.getControllerId());
if (controller != null && source.getSourceObjectIfItStillExists(game) != null) {
if (controller.chooseUse(Outcome.Benefit, "Pay " + cost.getText() /* + " or sacrifice " + permanent.getName() */ + '?', source, game)) {
cost.clearPaid();
if (cost.pay(source, game, source.getSourceId(), source.getControllerId(), false, null)) {
return true;
}
}
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
permanent.sacrifice(source.getSourceId(), game);
if (controller != null
&& source.getSourceObjectIfItStillExists(game) != null) {
if (controller.chooseUse(Outcome.Benefit, "Pay " + cost.getText() + '?', source, game)) {
cost.clearPaid();
if (cost.pay(source, game, source.getSourceId(), source.getControllerId(), false, null)) {
return true;
}
}
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
permanent.sacrifice(source.getSourceId(), game);
}
return true;
}
return false;
@ -167,17 +206,16 @@ class EchoEffect extends OneShotEffect {
@Override
public String getText(Mode mode) {
StringBuilder sb = new StringBuilder("sacrifice {this} unless you ");
String costText = cost.getText();
if (costText.toLowerCase().startsWith("discard")) {
sb.append(costText.substring(0, 1).toLowerCase());
sb.append(costText.substring(1));
}
else {
sb.append("pay ").append(costText);
}
StringBuilder sb = new StringBuilder("sacrifice {this} unless you ");
String costText = cost.getText();
if (costText.toLowerCase().startsWith("discard")) {
sb.append(costText.substring(0, 1).toLowerCase());
sb.append(costText.substring(1));
} else {
sb.append("pay ").append(costText);
}
return sb.toString();
return sb.toString();
}
}