mirror of
https://github.com/correl/mage.git
synced 2024-12-26 03:00:11 +00:00
Added filter to AttacksCreatureYourControlTrigger ability, dynamic value DiscardCostCardConvertedMana added, some small fixes ti rule text generation.
This commit is contained in:
parent
cf88bb5ac3
commit
333c5017c3
4 changed files with 72 additions and 7 deletions
|
@ -31,6 +31,7 @@ package mage.abilities.common;
|
|||
import mage.Constants.Zone;
|
||||
import mage.abilities.TriggeredAbilityImpl;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.filter.common.FilterControlledCreaturePermanent;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
@ -41,23 +42,31 @@ import mage.game.permanent.Permanent;
|
|||
*/
|
||||
public class AttacksCreatureYourControlTriggeredAbility extends TriggeredAbilityImpl<AttacksCreatureYourControlTriggeredAbility> {
|
||||
|
||||
protected FilterControlledCreaturePermanent filter;
|
||||
|
||||
public AttacksCreatureYourControlTriggeredAbility(Effect effect) {
|
||||
this(effect, false);
|
||||
}
|
||||
|
||||
public AttacksCreatureYourControlTriggeredAbility(Effect effect, boolean optional) {
|
||||
this(effect, optional, new FilterControlledCreaturePermanent());
|
||||
}
|
||||
|
||||
public AttacksCreatureYourControlTriggeredAbility(Effect effect, boolean optional, FilterControlledCreaturePermanent filter) {
|
||||
super(Zone.BATTLEFIELD, effect, optional);
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
public AttacksCreatureYourControlTriggeredAbility(AttacksCreatureYourControlTriggeredAbility ability) {
|
||||
super(ability);
|
||||
this.filter = ability.filter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
if (event.getType() == GameEvent.EventType.ATTACKER_DECLARED) {
|
||||
Permanent source = game.getPermanent(event.getSourceId());
|
||||
if (source != null && source.getControllerId().equals(controllerId)) {
|
||||
Permanent sourcePermanent = game.getPermanent(event.getSourceId());
|
||||
if (sourcePermanent != null && filter.match(sourcePermanent, sourceId, controllerId, game)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +80,7 @@ public class AttacksCreatureYourControlTriggeredAbility extends TriggeredAbility
|
|||
|
||||
@Override
|
||||
public String getRule() {
|
||||
return "Whenever a creature you control attacks, " + super.getRule();
|
||||
return "Whenever a " + filter.getMessage() + " attacks, " + super.getRule();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
package mage.abilities.dynamicvalue.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.costs.Cost;
|
||||
import mage.abilities.costs.common.DiscardCardCost;
|
||||
import mage.abilities.dynamicvalue.DynamicValue;
|
||||
import mage.cards.Card;
|
||||
import mage.game.Game;
|
||||
|
||||
/**
|
||||
* @author LevelX2
|
||||
*/
|
||||
public class DiscardCostCardConvertedMana implements DynamicValue {
|
||||
|
||||
@Override
|
||||
public int calculate(Game game, Ability sourceAbility) {
|
||||
for (Cost cost: sourceAbility.getCosts()) {
|
||||
if (cost instanceof DiscardCardCost) {
|
||||
DiscardCardCost discardCost = (DiscardCardCost) cost;
|
||||
int cmc = 0;
|
||||
for (Card card :discardCost.getCards()) {
|
||||
cmc += card.getManaCost().convertedManaCost();
|
||||
}
|
||||
return cmc;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DynamicValue clone() {
|
||||
return new DiscardCostCardConvertedMana();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return "the discarded card's converted mana cost";
|
||||
}
|
||||
}
|
|
@ -11,6 +11,7 @@ import mage.game.permanent.Permanent;
|
|||
* @author LevelX2
|
||||
*/
|
||||
public class SacrificeCostCreaturesToughness implements DynamicValue {
|
||||
|
||||
@Override
|
||||
public int calculate(Game game, Ability sourceAbility) {
|
||||
for (Cost cost: sourceAbility.getCosts()) {
|
||||
|
@ -33,7 +34,7 @@ public class SacrificeCostCreaturesToughness implements DynamicValue {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "X";
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -124,12 +124,22 @@ public class DamageTargetEffect extends OneShotEffect<DamageTargetEffect> {
|
|||
sb.append(amount);
|
||||
}
|
||||
sb.append(" damage to ");
|
||||
if (targetDescription.length() > 0)
|
||||
if (targetDescription.length() > 0) {
|
||||
sb.append(targetDescription);
|
||||
else
|
||||
}
|
||||
else {
|
||||
sb.append("target ").append(mode.getTargets().get(0).getTargetName());
|
||||
}
|
||||
if (message.length() > 0) {
|
||||
sb.append(message.equals("1") ? " equal to the number of " : " for each ");
|
||||
if (message.equals("1")) {
|
||||
sb.append(" equal to the number of ");
|
||||
} else {
|
||||
if (message.startsWith("the")) {
|
||||
sb.append(" equal to ");
|
||||
} else {
|
||||
sb.append(" for each ");
|
||||
}
|
||||
}
|
||||
sb.append(message);
|
||||
}
|
||||
if (!preventable) {
|
||||
|
|
Loading…
Reference in a new issue