- Added Protection keywords to players.

This commit is contained in:
Sloth
2011-10-30 10:26:00 +00:00
parent eecb51425c
commit 7b118a45d8
5 changed files with 55 additions and 5 deletions

View File

@@ -7354,7 +7354,7 @@ public class Card extends GameEntity implements Comparable<Card> {
int restDamage = damageIn;
if (CardFactoryUtil.hasProtectionFrom(source, this)) {
if (hasProtectionFrom(source)) {
return 0;
}
@@ -8008,7 +8008,8 @@ public class Card extends GameEntity implements Comparable<Card> {
getCharacteristics().setCardColorsOverridden(cardColorsOverridden0);
}
public final boolean hasProtectionFrom(Card source) {
@Override
public boolean hasProtectionFrom(Card source) {
if (source == null) {
return false;
}

View File

@@ -771,7 +771,7 @@ public class CardList implements Iterable<Card> {
public final CardList getUnprotectedCards(final Card source) {
return this.filter(new CardListFilter() {
public boolean addCard(final Card c) {
return !CardFactoryUtil.hasProtectionFrom(source, c);
return !c.hasProtectionFrom(source);
}
});
}

View File

@@ -905,7 +905,8 @@ public class GameAction {
if (tgt.canOnlyTgtOpponent() && !c.getController().getOpponent().isPlayer(pl)) {
invalid = true;
} else {
// TODO Check Player Protection once it's added.
if(pl.hasProtectionFrom(c))
invalid = true;
}
if (invalid) {
c.unEnchantEntity(pl);

View File

@@ -408,6 +408,10 @@ public abstract class GameEntity extends MyObservable {
enchantedBy.get(i).unEnchantEntity(this);
}
}
public boolean hasProtectionFrom(Card source) {
return false;
}
// //////////////////////////////
//

View File

@@ -532,6 +532,10 @@ public abstract class Player extends GameEntity {
if (AllZoneUtil.isCardInPlay("Leyline of Punishment")) {
return damage;
}
if (hasProtectionFrom(source)) {
return 0;
}
int restDamage = damage;
@@ -924,12 +928,52 @@ public abstract class Player extends GameEntity {
*/
@Override
public final boolean canTarget(final SpellAbility sa) {
if (hasKeyword("Shroud") || (!this.isPlayer(sa.getActivatingPlayer()) && hasKeyword("Hexproof"))) {
if (hasKeyword("Shroud")
|| (!this.isPlayer(sa.getActivatingPlayer()) && hasKeyword("Hexproof"))
|| hasProtectionFrom(sa.getSourceCard())) {
return false;
}
return true;
}
@Override
public boolean hasProtectionFrom(Card source) {
if (getKeywords() != null) {
final ArrayList<String> list = getKeywords();
String kw = "";
for (int i = 0; i < list.size(); i++) {
kw = list.get(i);
if (kw.equals("Protection from white") && source.isWhite()) {
return true;
}
if (kw.equals("Protection from blue") && source.isBlue()) {
return true;
}
if (kw.equals("Protection from black") && source.isBlack()) {
return true;
}
if (kw.equals("Protection from red") && source.isRed()) {
return true;
}
if (kw.equals("Protection from green") && source.isGreen()) {
return true;
}
if (kw.startsWith("Protection:")) { // uses isValid
final String characteristic = kw.split(":")[1];
final String[] characteristics = characteristic.split(",");
if (source.isValid(characteristics, this, null)) {
return true;
}
}
}
}
return false;
}
/**
* <p>