get given abilities and given pt of equipment from its static ability

master
melvin 2011-10-03 14:37:15 +08:00
parent 404298cf24
commit 5248c642b8
1 changed files with 20 additions and 10 deletions

View File

@ -5,29 +5,39 @@ import magic.model.MagicGame;
import magic.model.MagicPermanent; import magic.model.MagicPermanent;
import magic.model.MagicPlayer; import magic.model.MagicPlayer;
import magic.model.MagicPowerToughness; import magic.model.MagicPowerToughness;
import magic.model.mstatic.MagicStatic;
public class MagicEquipTargetPicker extends MagicTargetPicker<MagicPermanent> { public class MagicEquipTargetPicker extends MagicTargetPicker<MagicPermanent> {
private final MagicCardDefinition cdef; private final long givenAbilityFlags;
private final MagicPowerToughness givenPT;
public MagicEquipTargetPicker(final MagicCardDefinition cardDefinition) { public MagicEquipTargetPicker(final MagicCardDefinition cardDefinition) {
cdef = cardDefinition; // determine given ability and given pt of equipment from list of static abilities
long ability = 0;
MagicPowerToughness pt = new MagicPowerToughness(0,0);
for (final MagicStatic mstatic : cardDefinition.getStatics()) {
ability = mstatic.getAbilityFlags(MagicGame.getInstance(), MagicPermanent.NONE, ability);
mstatic.getPowerToughness(MagicGame.getInstance(), MagicPermanent.NONE, pt);
}
givenAbilityFlags = ability;
givenPT = pt;
} }
@Override @Override
protected int getTargetScore(final MagicGame game,final MagicPlayer player,final MagicPermanent permanent) { protected int getTargetScore(final MagicGame game,final MagicPlayer player,final MagicPermanent permanent) {
// Penalty when allready equipped. // penalty when already equipped
int penalty=permanent.isEquipped()?3:0; int penalty = permanent.isEquipped() ? 3 : 0;
// Penalty when there is an overlap between abilities. // penalty when there is an overlap between abilities.
final long abilityFlags = cdef.getAbilityFlags(); if ((permanent.getAllAbilityFlags(game) & givenAbilityFlags) != 0) {
if ((permanent.getAllAbilityFlags(game)&abilityFlags)!=0) {
penalty+=6; penalty+=6;
} }
final MagicPowerToughness pt = permanent.getPowerToughness(game); final MagicPowerToughness pt = permanent.getPowerToughness(game);
final MagicPowerToughness equipPT = cdef.genPowerToughness(game,player); final boolean defensive = givenPT.toughness() > givenPT.power();
final boolean defensive = equipPT.toughness() > equipPT.power();
// Defensive // Defensive
if (defensive) { if (defensive) {