forked from External/mage
Refactor damage with power effect, added checking for wrong targets;
This commit is contained in:
parent
62530b3880
commit
4a004a27b3
16 changed files with 212 additions and 131 deletions
|
|
@ -0,0 +1,73 @@
|
|||
package mage.abilities.effects.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.Mode;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.constants.Outcome;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
|
||||
/**
|
||||
* @author JayDi85
|
||||
*/
|
||||
public class DamageWithPowerFromOneToAnotherTargetEffect extends OneShotEffect {
|
||||
|
||||
String firstTargetName;
|
||||
|
||||
public DamageWithPowerFromOneToAnotherTargetEffect() {
|
||||
this((String) null);
|
||||
}
|
||||
|
||||
public DamageWithPowerFromOneToAnotherTargetEffect(String firstTargetName) {
|
||||
super(Outcome.Damage);
|
||||
this.firstTargetName = firstTargetName;
|
||||
}
|
||||
|
||||
public DamageWithPowerFromOneToAnotherTargetEffect(final DamageWithPowerFromOneToAnotherTargetEffect effect) {
|
||||
super(effect);
|
||||
this.firstTargetName = effect.firstTargetName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
if (source.getTargets().size() != 2) {
|
||||
throw new IllegalStateException("It must have two targets, but found " + source.getTargets().size());
|
||||
}
|
||||
|
||||
Permanent myPermanent = game.getPermanentOrLKIBattlefield(getTargetPointer().getFirst(game, source));
|
||||
Permanent anotherPermanent = game.getPermanent(source.getTargets().get(1).getFirstTarget());
|
||||
Player anotherPlayer = game.getPlayer(source.getTargets().get(1).getFirstTarget());
|
||||
|
||||
if (myPermanent != null && anotherPermanent != null) {
|
||||
anotherPermanent.damage(myPermanent.getPower().getValue(), myPermanent.getId(), game, false, true);
|
||||
return true;
|
||||
} else if (myPermanent != null && anotherPlayer != null) {
|
||||
anotherPlayer.damage(myPermanent.getPower().getValue(), myPermanent.getId(), game, false, true);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DamageWithPowerFromOneToAnotherTargetEffect copy() {
|
||||
return new DamageWithPowerFromOneToAnotherTargetEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText(Mode mode) {
|
||||
if (staticText != null && !staticText.isEmpty()) {
|
||||
return staticText;
|
||||
}
|
||||
|
||||
if (mode.getTargets().size() != 2) {
|
||||
throw new IllegalStateException("It must have two targets, but found " + mode.getTargets().size());
|
||||
}
|
||||
|
||||
// Target creature you control deals damage equal to its power to target creature you don't control
|
||||
String sb = (this.firstTargetName != null ? this.firstTargetName : "Target " + mode.getTargets().get(0).getTargetName()) +
|
||||
" deals damage equal to its power to target " +
|
||||
mode.getTargets().get(1).getTargetName();
|
||||
return sb;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue