CombatUtil: updated CantBeBlockedBy CantBlock to work with multiple instances

turn Dragon Hunter Effect into a keyword like thing to work better with Text Change
This commit is contained in:
Hanmac
2017-01-19 06:09:51 +00:00
parent 50e17d0080
commit 7c29bcf5b9
4 changed files with 47 additions and 24 deletions

View File

@@ -1508,6 +1508,11 @@ public class Card extends GameEntity implements Comparable<Card> {
sbLong.append(getName()).append(" can't be blocked.\r\n"); sbLong.append(getName()).append(" can't be blocked.\r\n");
} else if (keyword.equals("AllNonLegendaryCreatureNames")) { } else if (keyword.equals("AllNonLegendaryCreatureNames")) {
sbLong.append(getName()).append(" has all names of nonlegendary creature cards.\r\n"); sbLong.append(getName()).append(" has all names of nonlegendary creature cards.\r\n");
} else if (keyword.startsWith("IfReach")) {
String k[] = keyword.split(":");
sbLong.append(getName()).append(" can block ")
.append(CardUtil.getPluralType(k[1]))
.append(" as though it had reach.\r\n");
} }
else { else {
if ((i != 0) && (sb.length() != 0)) { if ((i != 0) && (sb.length() != 0)) {

View File

@@ -57,7 +57,7 @@ public final class CardUtil {
"Cycling", "Echo", "Kicker", "Flashback", "Madness", "Morph", "Cycling", "Echo", "Kicker", "Flashback", "Madness", "Morph",
"Affinity", "Entwine", "Splice", "Ninjutsu", "Presence", "Affinity", "Entwine", "Splice", "Ninjutsu", "Presence",
"Transmute", "Replicate", "Recover", "Suspend", "Aura swap", "Transmute", "Replicate", "Recover", "Suspend", "Aura swap",
"Fortify", "Transfigure", "Champion", "Evoke", "Prowl", "Fortify", "Transfigure", "Champion", "Evoke", "Prowl", "IfReach",
"Reinforce", "Unearth", "Level up", "Miracle", "Overload", "Reinforce", "Unearth", "Level up", "Miracle", "Overload",
"Scavenge", "Bestow", "Outlast", "Dash", "Renown", "Surge", "Emerge").build(); "Scavenge", "Bestow", "Outlast", "Dash", "Renown", "Surge", "Emerge").build();
/** List of keyword endings of keywords that could be modified by text changes. */ /** List of keyword endings of keywords that could be modified by text changes. */

View File

@@ -968,30 +968,38 @@ public class CombatUtil {
return false; return false;
} }
if (attacker.hasStartOfKeyword("CantBeBlockedBy ")) { for (String k : attacker.getKeywords()) {
final int keywordPosition = attacker.getKeywordPosition("CantBeBlockedBy "); if (k.startsWith("CantBeBlockedBy ")) {
final String parse = attacker.getKeywords().get(keywordPosition).toString(); final String[] n = k.split(" ", 2);
final String[] k = parse.split(" ", 2); final String[] restrictions = n[1].split(",");
final String[] restrictions = k[1].split(","); if (blocker.isValid(restrictions, attacker.getController(), attacker, null)) {
if (blocker.isValid(restrictions, attacker.getController(), attacker, null)) { boolean stillblock = false;
//Dragon Hunter check //Dragon Hunter check
if (!k[1].contains("withoutReach") || !attacker.getType().hasCreatureType("Dragon") if (n[1].contains("withoutReach") && blocker.hasStartOfKeyword("IfReach")) {
|| !blocker.hasKeyword("CARDNAME can block Dragons as though it had reach.")) { for (String k2 : blocker.getKeywords()) {
return false; if (k2.startsWith("IfReach")) {
} String n2[] = k2.split(":");
if (attacker.getType().hasCreatureType(n2[1])) {
stillblock = true;
break;
}
}
}
}
if (!stillblock) {
return false;
}
}
} }
} }
for (String keyword : attacker.getKeywords()) {
if (blocker.hasStartOfKeyword("CantBlock")) { if (keyword.startsWith("CantBlockCardUID")) {
final int keywordPosition = blocker.getKeywordPosition("CantBlock"); final String[] k = keyword.split("_", 2);
final String parse = blocker.getKeywords().get(keywordPosition).toString();
if (parse.startsWith("CantBlockCardUID")) {
final String[] k = parse.split("_", 2);
if (attacker.getId() == Integer.parseInt(k[1])) { if (attacker.getId() == Integer.parseInt(k[1])) {
return false; return false;
} }
} else { } else if (keyword.startsWith("CantBlock")) {
final String[] parse0 = parse.split(":"); final String[] parse0 = keyword.split(":");
final String[] k = parse0[0].split(" ", 2); final String[] k = parse0[0].split(" ", 2);
final String[] restrictions = k[1].split(","); final String[] restrictions = k[1].split(",");
if (attacker.isValid(restrictions, blocker.getController(), blocker, null)) { if (attacker.isValid(restrictions, blocker.getController(), blocker, null)) {
@@ -1005,9 +1013,19 @@ public class CombatUtil {
} }
if (attacker.hasKeyword("Flying") && !blocker.hasKeyword("Flying") && !blocker.hasKeyword("Reach")) { if (attacker.hasKeyword("Flying") && !blocker.hasKeyword("Flying") && !blocker.hasKeyword("Reach")) {
if (!attacker.getType().hasCreatureType("Dragon") || !blocker.hasKeyword("CARDNAME can block Dragons as though it had reach.")) { boolean stillblock = false;
return false; for (String k : blocker.getKeywords()) {
} if (k.startsWith("IfReach")) {
String n[] = k.split(":");
if (attacker.getType().hasCreatureType(n[1])) {
stillblock = true;
break;
}
}
}
if (!stillblock) {
return false;
}
} }
if (attacker.hasKeyword("Horsemanship") && !blocker.hasKeyword("Horsemanship")) { if (attacker.hasKeyword("Horsemanship") && !blocker.hasKeyword("Horsemanship")) {

View File

@@ -3,6 +3,6 @@ ManaCost:W
Types:Creature Human Warrior Types:Creature Human Warrior
PT:2/1 PT:2/1
K:Protection from Dragons K:Protection from Dragons
K:CARDNAME can block Dragons as though it had reach. K:IfReach:Dragon
SVar:Picture:http://www.wizards.com/global/images/magic/general/dragon_hunter.jpg SVar:Picture:http://www.wizards.com/global/images/magic/general/dragon_hunter.jpg
Oracle:Protection from Dragons\nDragon Hunter can block Dragons as though it had reach. Oracle:Protection from Dragons\nDragon Hunter can block Dragons as though it had reach.