2013-04-12 19:32:25 -07:00
|
|
|
package magic.model.action;
|
|
|
|
|
2020-01-15 12:02:42 -08:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collection;
|
|
|
|
|
2013-04-12 19:32:25 -07:00
|
|
|
import magic.model.MagicAbility;
|
|
|
|
import magic.model.MagicGame;
|
|
|
|
import magic.model.MagicLocationType;
|
2020-01-15 12:02:42 -08:00
|
|
|
import magic.model.MagicMessage;
|
2013-04-12 19:32:25 -07:00
|
|
|
import magic.model.MagicPermanent;
|
|
|
|
import magic.model.MagicPermanentState;
|
|
|
|
|
2015-04-14 03:35:43 -07:00
|
|
|
public class DestroyAction extends MagicAction {
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2018-04-07 17:59:14 -07:00
|
|
|
private final Collection<MagicPermanent> targets = new ArrayList<>();
|
2014-02-18 22:08:37 -08:00
|
|
|
private int numDestroyed = 0;
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2015-04-14 03:35:43 -07:00
|
|
|
public DestroyAction(final MagicPermanent permanent) {
|
2013-04-12 19:32:25 -07:00
|
|
|
this.targets.add(permanent);
|
|
|
|
}
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2015-04-14 03:35:43 -07:00
|
|
|
public DestroyAction(final Collection<MagicPermanent> targets) {
|
2013-04-12 19:32:25 -07:00
|
|
|
this.targets.addAll(targets);
|
|
|
|
}
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2013-04-12 19:32:25 -07:00
|
|
|
@Override
|
|
|
|
public void doAction(final MagicGame game) {
|
2018-04-07 17:59:14 -07:00
|
|
|
final Collection<MagicPermanent> toBeDestroyed = new ArrayList<>();
|
2013-04-12 19:32:25 -07:00
|
|
|
for (final MagicPermanent permanent : targets) {
|
|
|
|
boolean destroy = true;
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2013-04-12 19:32:25 -07:00
|
|
|
// Indestructible
|
|
|
|
if (destroy && permanent.hasAbility(MagicAbility.Indestructible)) {
|
|
|
|
destroy = false;
|
|
|
|
}
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2013-04-12 19:32:25 -07:00
|
|
|
// Regeneration
|
|
|
|
if (destroy && permanent.isRegenerated()) {
|
2015-10-27 11:42:04 -07:00
|
|
|
game.logAppendMessage(
|
|
|
|
permanent.getController(),
|
2016-01-30 19:31:18 -08:00
|
|
|
MagicMessage.format("%s is regenerated.", permanent)
|
2015-10-27 11:42:04 -07:00
|
|
|
);
|
2015-04-14 07:54:29 -07:00
|
|
|
game.doAction(new TapAction(permanent));
|
2015-04-14 06:10:19 -07:00
|
|
|
game.doAction(new RemoveAllDamageAction(permanent));
|
2015-04-14 06:21:39 -07:00
|
|
|
game.doAction(new RemoveFromCombatAction(permanent));
|
2015-04-13 02:22:38 -07:00
|
|
|
game.doAction(ChangeStateAction.Clear(permanent,MagicPermanentState.Regenerated));
|
2013-04-12 19:32:25 -07:00
|
|
|
destroy = false;
|
2013-06-23 18:33:35 -07:00
|
|
|
}
|
|
|
|
|
2013-04-12 19:32:25 -07:00
|
|
|
// Totem armor
|
|
|
|
if (destroy && permanent.isEnchanted()) {
|
|
|
|
for (final MagicPermanent aura : permanent.getAuraPermanents()) {
|
|
|
|
if (aura.hasAbility(MagicAbility.TotemArmor)) {
|
2015-10-27 11:42:04 -07:00
|
|
|
game.logAppendMessage(
|
|
|
|
permanent.getController(),
|
2016-01-30 19:31:18 -08:00
|
|
|
MagicMessage.format("Remove all damage from %s.", permanent)
|
2015-10-27 11:42:04 -07:00
|
|
|
);
|
2015-04-14 06:10:19 -07:00
|
|
|
game.doAction(new RemoveAllDamageAction(permanent));
|
2013-04-12 19:32:25 -07:00
|
|
|
toBeDestroyed.add(aura);
|
|
|
|
destroy = false;
|
|
|
|
//Only the first aura with totem armor will be
|
|
|
|
//destroyed. If there are multiple auras with totem
|
|
|
|
//armor, player can choose the one to be destroyed, but
|
|
|
|
//this is not implemented
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2013-04-12 19:32:25 -07:00
|
|
|
if (destroy) {
|
|
|
|
toBeDestroyed.add(permanent);
|
|
|
|
}
|
|
|
|
}
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2014-02-18 22:08:37 -08:00
|
|
|
numDestroyed = toBeDestroyed.size();
|
|
|
|
|
2013-04-12 19:32:25 -07:00
|
|
|
for (final MagicPermanent permanent : toBeDestroyed) {
|
2015-09-19 13:14:04 -07:00
|
|
|
game.logAppendMessage(
|
|
|
|
permanent.getController(),
|
2016-01-30 19:31:18 -08:00
|
|
|
MagicMessage.format("%s is destroyed.", permanent)
|
2015-09-19 13:14:04 -07:00
|
|
|
);
|
2013-06-23 18:33:35 -07:00
|
|
|
}
|
2015-05-12 19:41:48 -07:00
|
|
|
|
|
|
|
game.doAction(new RemoveAllFromPlayAction(toBeDestroyed, MagicLocationType.Graveyard));
|
2013-04-12 19:32:25 -07:00
|
|
|
}
|
|
|
|
|
2014-02-18 23:20:24 -08:00
|
|
|
public int getNumDestroyed() {
|
2014-02-18 22:08:37 -08:00
|
|
|
return numDestroyed;
|
|
|
|
}
|
|
|
|
|
2014-08-06 19:54:07 -07:00
|
|
|
public boolean isDestroyed() {
|
|
|
|
return numDestroyed == 1;
|
|
|
|
}
|
|
|
|
|
2013-04-12 19:32:25 -07:00
|
|
|
@Override
|
|
|
|
public void undoAction(final MagicGame game) {}
|
|
|
|
}
|