Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static boolean canBlock(Card attacker, Card blocker) {
- if(attacker == null || blocker == null) return false;
- if(!canBlockProtection(attacker, blocker)) return false;
- //rare case:
- if(blocker.getKeyword().contains("Shadow")
- && blocker.getKeyword().contains(
- "CARDNAME can block creatures with shadow as though they didn't have shadow.")) return false;
- if(attacker.getKeyword().contains("Shadow")
- && !blocker.getKeyword().contains("Shadow")
- && !blocker.getKeyword().contains(
- "CARDNAME can block creatures with shadow as though they didn't have shadow.")) return false;
- if(!attacker.getKeyword().contains("Shadow") && blocker.getKeyword().contains("Shadow")) return false;
- // if(attacker.getNetAttack() <= 2 && blocker.getName().equals("Sunweb")) return false;
- // if(attacker.getNetAttack() >= 2 && blocker.getName().equals("Ironclaw Orcs")) return false;
- // CARDNAME can't block creatures with power ...
- int powerLimit[] = {0};
- int keywordPosition = 0;
- boolean hasKeyword = false;
- ArrayList<String> blockerKeywords = blocker.getKeyword();
- for (int i = 0; i < blockerKeywords.size(); i++) {
- if (blockerKeywords.get(i).toString().startsWith("CARDNAME can't block creatures with power")) {
- hasKeyword = true;
- keywordPosition = i;
- }
- }
- if (attacker.getKeyword().contains("Creatures with power less than CARDNAME's power can't block it.") &&
- attacker.getNetAttack() > blocker.getNetAttack()) return false;
- if (hasKeyword) { // The keyword "CARDNAME can't block creatures with power" ... is present
- String tmpString = blocker.getKeyword().get(keywordPosition).toString();
- String asSeparateWords[] = tmpString.trim().split(" ");
- if (asSeparateWords.length >= 9) {
- if (asSeparateWords[6].matches("[0-9][0-9]?")) {
- powerLimit[0] = Integer.parseInt((asSeparateWords[6]).trim());
- if (attacker.getNetAttack() >= powerLimit[0] && blocker.getKeyword().contains
- ("CARDNAME can't block creatures with power " + powerLimit[0] + " or greater.")) return false;
- if (attacker.getNetAttack() <= powerLimit[0] && blocker.getKeyword().contains
- ("CARDNAME can't block creatures with power " + powerLimit[0] + " or less.")) return false;
- }
- }
- if (attacker.getNetAttack() > blocker.getNetAttack()
- && blocker.getKeyword().contains("CARDNAME can't block creatures with power greater than CARDNAME's power.")) return false;
- if (attacker.getNetAttack() >= blocker.getNetDefense()
- && blocker.getKeyword().contains("CARDNAME can't block creatures with power equal to or greater than CARDNAME's toughness.")) return false;
- }// hasKeyword CARDNAME can't block creatures with power ...
- // CARDNAME can't be blocked by creatures with power ...
- int powerLimit2[] = {0};
- int keywordPosition2 = 0;
- boolean hasKeyword2 = false;
- ArrayList<String> attackerKeywords = attacker.getKeyword();
- for (int i = 0; i < attackerKeywords.size(); i++) {
- if (attackerKeywords.get(i).toString().startsWith("CARDNAME can't be blocked by creatures with power")) {
- hasKeyword2 = true;
- keywordPosition2 = i;
- }
- }
- if (hasKeyword2) { // The keyword "CARDNAME can't be blocked by creatures with power" ... is present
- String tmpString = attacker.getKeyword().get(keywordPosition2).toString();
- String asSeparateWords[] = tmpString.trim().split(" ");
- if (asSeparateWords.length >= 9) {
- if (asSeparateWords[8].matches("[0-9][0-9]?")) {
- powerLimit2[0] = Integer.parseInt((asSeparateWords[8]).trim());
- if (blocker.getNetAttack() >= powerLimit2[0] && attacker.getKeyword().contains
- ("CARDNAME can't be blocked by creatures with power " + powerLimit2[0] + " or greater.")) return false;
- if (blocker.getNetAttack() <= powerLimit2[0] && attacker.getKeyword().contains
- ("CARDNAME can't be blocked by creatures with power " + powerLimit2[0] + " or less.")) return false;
- }
- }
- if (blocker.getNetAttack() > attacker.getNetAttack() &&
- blocker.getKeyword().contains("CARDNAME can't be blocked by creatures with power greater than CARDNAME's power.")) return false;
- if (blocker.getNetAttack() >= attacker.getNetDefense() &&
- blocker.getKeyword().contains("CARDNAME can't be blocked by creatures with power equal to or greater than CARDNAME's toughness.")) return false;
- }// hasKeyword CARDNAME can't be blocked by creatures with power ...
- PlayerZone blkPZ = AllZone.getZone(Constant.Zone.Play, blocker.getController());
- CardList blkCL = new CardList(blkPZ.getCards());
- CardList temp = new CardList();
- if(attacker.getKeyword().contains("Plainswalk")) {
- temp = blkCL.getType("Plains");
- if(!temp.isEmpty()) return false;
- }
- if(attacker.getKeyword().contains("Islandwalk")) {
- temp = blkCL.getType("Island");
- if(!temp.isEmpty()) return false;
- }
- if(attacker.getKeyword().contains("Swampwalk")) {
- temp = blkCL.getType("Swamp");
- if(!temp.isEmpty()) return false;
- }
- if(attacker.getKeyword().contains("Mountainwalk")) {
- temp = blkCL.getType("Mountain");
- if(!temp.isEmpty()) return false;
- }
- if(attacker.getKeyword().contains("Forestwalk")) {
- temp = blkCL.getType("Forest");
- if(!temp.isEmpty()) return false;
- }
- if(attacker.getKeyword().contains("Legendary landwalk")) {
- temp = blkCL.filter(new CardListFilter() {
- public boolean addCard(Card c) {
- return c.isLand() && c.getType().contains("Legendary");
- }
- });
- if(!temp.isEmpty()) return false;
- }
- if(attacker.getKeyword().contains("Nonbasic landwalk")) {
- temp = blkCL.filter(new CardListFilter() {
- public boolean addCard(Card c) {
- return c.isLand() && !c.isBasicLand();
- }
- });
- if(!temp.isEmpty()) return false;
- }
- if(blocker.getKeyword().contains("CARDNAME can block only creatures with flying.")
- && !attacker.getKeyword().contains("Flying")) return false;
- if (attacker.getKeyword().contains("CARDNAME can't be blocked by creatures with flying.")
- && blocker.getKeyword().contains("Flying")) return false;
- if(attacker.getKeyword().contains("Unblockable")) return false;
- if(blocker.getKeyword().contains("CARDNAME can't block.")
- || blocker.getKeyword().contains("CARDNAME can't attack or block.")) return false;
- if(attacker.getKeyword().contains("Flying")) {
- if(!blocker.getKeyword().contains("Flying")
- && !blocker.getKeyword().contains("CARDNAME can block creatures with flying.")
- && !blocker.getKeyword().contains("Reach")) return false;
- }
- if(attacker.getKeyword().contains("CARDNAME can't be blocked except by creatures with flying.")
- && !blocker.getKeyword().contains("Flying")) return false;
- if(attacker.getKeyword().contains("Horsemanship")) {
- if(!blocker.getKeyword().contains("Horsemanship")) return false;
- }
- if(attacker.getName().equals("Taoist Warrior") || attacker.getName().equals("Zuo Ci, the Mocking Sage")) {
- if(blocker.getKeyword().contains("Horsemanship")) return false;
- }
- if(attacker.getKeyword().contains("Fear")) {
- if(!blocker.getType().contains("Artifact")
- && !CardUtil.getColors(blocker).contains(Constant.Color.Black) /*&&
- !CardUtil.getColors(blocker).contains(Constant.Color.Colorless) */) //should not include colorless, right?
- return false;
- }
- if (attacker.getKeyword().contains("CARDNAME can't be blocked by white creatures."))
- {
- if (!CardUtil.getColors(blocker).contains(Constant.Color.White))
- return false;
- }
- if(attacker.getKeyword().contains("Intimidate")) {
- if(!blocker.getType().contains("Artifact") && !CardFactoryUtil.sharesColorWith(attacker, blocker)) return false;
- }
- if(attacker.getName().equals("Barrenton Cragtreads")) {
- if(CardUtil.getColors(blocker).contains(Constant.Color.Red)) return false;
- }
- if(attacker.getName().equals("Wanderbrine Rootcutters")) {
- if(CardUtil.getColors(blocker).contains(Constant.Color.Green)) return false;
- }
- if(/*attacker.getName().equals("Amrou Seekers")*/ attacker.getKeyword().contains("CARDNAME can't be blocked except by artifact creatures and/or white creatures.")) {
- if(!blocker.getType().contains("Artifact")
- && !CardUtil.getColors(blocker).contains(Constant.Color.White)) return false;
- }
- if(attacker.getName().equals("Skirk Shaman")) {
- if(!blocker.getType().contains("Artifact")
- && !CardUtil.getColors(blocker).contains(Constant.Color.Red)) return false;
- }
- if(attacker.getName().equals("Manta Ray")) {
- if(!CardUtil.getColors(blocker).contains(Constant.Color.Blue)) return false;
- }
- if(attacker.getKeyword().contains("CARDNAME can't be blocked except by black creatures.")) {
- if(!CardUtil.getColors(blocker).contains(Constant.Color.Black))return false;
- }
- // if(attacker.getName().equals("Goldmeadow Dodger")) return blocker.getNetAttack() < 4;
- // if(attacker.getName().equals("Juggernaut") && blocker.getType().contains("Wall")) return false;
- if (attacker.getKeyword().contains("CARDNAME can't be blocked by Walls.") && blocker.getType().contains("Wall")) return false;
- if (attacker.getKeyword().contains("CARDNAME can't be blocked except by Walls.") && !blocker.getType().contains("Wall")) return false;
- if (attacker.getKeyword().contains("CARDNAME can't be blocked except by Walls and/or creatures with flying.") &&
- !(blocker.getType().contains("Wall") || blocker.getKeyword().contains("Flying"))) return false;
- if (blocker.getCounters(Counters.BRIBERY) > 0 && isCardInPlay("Gwafa Hazid, Profiteer"))
- return false;
- if (isCardInPlay("Kulrath Knight"))
- {
- CardList all = new CardList();
- all.addAll(AllZone.getZone(Constant.Zone.Play, Constant.Player.Human).getCards());
- all.addAll(AllZone.getZone(Constant.Zone.Play, Constant.Player.Computer). getCards());
- all = all.getName("Kulrath Knight");
- for (int i=0; i<all.size(); i++)
- {
- Card cKK = all.get(i);
- String oppKK = AllZone.GameAction.getOpponent(cKK.getController());
- if (blocker.getController().equals(oppKK) && blocker.hasCounters())
- return false;
- }
- }
- return true;
- }//canBlock()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement