Advertisement
Guest User

Forge - canBlock() method

a guest
Sep 17th, 2010
681
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 12.29 KB | None | 0 0
  1.     public static boolean canBlock(Card attacker, Card blocker) {
  2.        
  3.         if(attacker == null || blocker == null) return false;
  4.        
  5.         if(!canBlockProtection(attacker, blocker)) return false;
  6.        
  7.         //rare case:
  8.         if(blocker.getKeyword().contains("Shadow")
  9.                 && blocker.getKeyword().contains(
  10.                         "CARDNAME can block creatures with shadow as though they didn't have shadow.")) return false;
  11.        
  12.         if(attacker.getKeyword().contains("Shadow")
  13.                 && !blocker.getKeyword().contains("Shadow")
  14.                 && !blocker.getKeyword().contains(
  15.                         "CARDNAME can block creatures with shadow as though they didn't have shadow.")) return false;
  16.        
  17.         if(!attacker.getKeyword().contains("Shadow") && blocker.getKeyword().contains("Shadow")) return false;
  18.        
  19. //      if(attacker.getNetAttack() <= 2 && blocker.getName().equals("Sunweb")) return false;
  20. //      if(attacker.getNetAttack() >= 2 && blocker.getName().equals("Ironclaw Orcs")) return false;
  21.  
  22.         // CARDNAME can't block creatures with power ...
  23.  
  24.         int powerLimit[] = {0};
  25.         int keywordPosition = 0;
  26.         boolean hasKeyword = false;
  27.        
  28.         ArrayList<String> blockerKeywords = blocker.getKeyword();
  29.         for (int i = 0; i < blockerKeywords.size(); i++) {
  30.             if (blockerKeywords.get(i).toString().startsWith("CARDNAME can't block creatures with power")) {
  31.                 hasKeyword = true;
  32.                 keywordPosition = i;
  33.             }
  34.         }
  35.        
  36.         if (attacker.getKeyword().contains("Creatures with power less than CARDNAME's power can't block it.") &&
  37.                 attacker.getNetAttack() > blocker.getNetAttack()) return false;
  38.        
  39.         if (hasKeyword) {    // The keyword "CARDNAME can't block creatures with power" ... is present
  40.             String tmpString = blocker.getKeyword().get(keywordPosition).toString();
  41.             String asSeparateWords[]  = tmpString.trim().split(" ");
  42.            
  43.             if (asSeparateWords.length >= 9) {
  44.                 if (asSeparateWords[6].matches("[0-9][0-9]?")) {
  45.                     powerLimit[0] = Integer.parseInt((asSeparateWords[6]).trim());
  46.                    
  47.                     if (attacker.getNetAttack() >= powerLimit[0] && blocker.getKeyword().contains
  48.                             ("CARDNAME can't block creatures with power " + powerLimit[0] + " or greater.")) return false;
  49.                     if (attacker.getNetAttack() <= powerLimit[0] && blocker.getKeyword().contains
  50.                             ("CARDNAME can't block creatures with power " + powerLimit[0] + " or less.")) return false;
  51.                 }
  52.             }
  53.            
  54.             if (attacker.getNetAttack() > blocker.getNetAttack()
  55.                     && blocker.getKeyword().contains("CARDNAME can't block creatures with power greater than CARDNAME's power.")) return false;
  56.             if (attacker.getNetAttack() >= blocker.getNetDefense()
  57.                     && blocker.getKeyword().contains("CARDNAME can't block creatures with power equal to or greater than CARDNAME's toughness.")) return false;
  58.            
  59.                
  60.            
  61.         }// hasKeyword CARDNAME can't block creatures with power ...
  62.        
  63.         // CARDNAME can't be blocked by creatures with power ...
  64.        
  65.  
  66.         int powerLimit2[] = {0};
  67.         int keywordPosition2 = 0;
  68.         boolean hasKeyword2 = false;
  69.        
  70.         ArrayList<String> attackerKeywords = attacker.getKeyword();
  71.         for (int i = 0; i < attackerKeywords.size(); i++) {
  72.             if (attackerKeywords.get(i).toString().startsWith("CARDNAME can't be blocked by creatures with power")) {
  73.                 hasKeyword2 = true;
  74.                 keywordPosition2 = i;
  75.             }
  76.         }
  77.        
  78.         if (hasKeyword2) {    // The keyword "CARDNAME can't be blocked by creatures with power" ... is present
  79.             String tmpString = attacker.getKeyword().get(keywordPosition2).toString();
  80.             String asSeparateWords[] = tmpString.trim().split(" ");
  81.        
  82.             if (asSeparateWords.length >= 9) {
  83.                 if (asSeparateWords[8].matches("[0-9][0-9]?")) {
  84.                     powerLimit2[0] = Integer.parseInt((asSeparateWords[8]).trim());
  85.        
  86.                     if (blocker.getNetAttack() >= powerLimit2[0] && attacker.getKeyword().contains
  87.                         ("CARDNAME can't be blocked by creatures with power " + powerLimit2[0] + " or greater.")) return false;
  88.                     if (blocker.getNetAttack() <= powerLimit2[0] && attacker.getKeyword().contains
  89.                         ("CARDNAME can't be blocked by creatures with power " + powerLimit2[0] + " or less.")) return false;
  90.                 }
  91.             }
  92.        
  93.             if (blocker.getNetAttack() > attacker.getNetAttack() &&
  94.                     blocker.getKeyword().contains("CARDNAME can't be blocked by creatures with power greater than CARDNAME's power.")) return false;
  95.             if (blocker.getNetAttack() >= attacker.getNetDefense() &&
  96.                     blocker.getKeyword().contains("CARDNAME can't be blocked by creatures with power equal to or greater than CARDNAME's toughness.")) return false;
  97.        
  98.         }// hasKeyword CARDNAME can't be blocked by creatures with power ...
  99.  
  100.         PlayerZone blkPZ = AllZone.getZone(Constant.Zone.Play, blocker.getController());
  101.         CardList blkCL = new CardList(blkPZ.getCards());
  102.         CardList temp = new CardList();
  103.        
  104.         if(attacker.getKeyword().contains("Plainswalk")) {
  105.             temp = blkCL.getType("Plains");
  106.             if(!temp.isEmpty()) return false;
  107.         }
  108.        
  109.         if(attacker.getKeyword().contains("Islandwalk")) {
  110.             temp = blkCL.getType("Island");
  111.             if(!temp.isEmpty()) return false;
  112.         }
  113.        
  114.         if(attacker.getKeyword().contains("Swampwalk")) {
  115.             temp = blkCL.getType("Swamp");
  116.             if(!temp.isEmpty()) return false;
  117.         }
  118.        
  119.         if(attacker.getKeyword().contains("Mountainwalk")) {
  120.             temp = blkCL.getType("Mountain");
  121.             if(!temp.isEmpty()) return false;
  122.         }
  123.        
  124.         if(attacker.getKeyword().contains("Forestwalk")) {
  125.             temp = blkCL.getType("Forest");
  126.             if(!temp.isEmpty()) return false;
  127.         }
  128.        
  129.         if(attacker.getKeyword().contains("Legendary landwalk")) {
  130.             temp = blkCL.filter(new CardListFilter() {
  131.                 public boolean addCard(Card c) {
  132.                     return c.isLand() && c.getType().contains("Legendary");
  133.                 }
  134.             });
  135.             if(!temp.isEmpty()) return false;
  136.         }
  137.        
  138.         if(attacker.getKeyword().contains("Nonbasic landwalk")) {
  139.             temp = blkCL.filter(new CardListFilter() {
  140.                 public boolean addCard(Card c) {
  141.                     return c.isLand() && !c.isBasicLand();
  142.                 }
  143.             });
  144.             if(!temp.isEmpty()) return false;
  145.         }
  146.        
  147.  
  148.         if(blocker.getKeyword().contains("CARDNAME can block only creatures with flying.")
  149.                 && !attacker.getKeyword().contains("Flying")) return false;
  150.        
  151.         if (attacker.getKeyword().contains("CARDNAME can't be blocked by creatures with flying.")
  152.                 && blocker.getKeyword().contains("Flying")) return false;
  153.        
  154.         if(attacker.getKeyword().contains("Unblockable")) return false;
  155.        
  156.         if(blocker.getKeyword().contains("CARDNAME can't block.")
  157.                 || blocker.getKeyword().contains("CARDNAME can't attack or block.")) return false;
  158.        
  159.         if(attacker.getKeyword().contains("Flying")) {
  160.             if(!blocker.getKeyword().contains("Flying")
  161.                     && !blocker.getKeyword().contains("CARDNAME can block creatures with flying.")
  162.                     && !blocker.getKeyword().contains("Reach")) return false;
  163.         }
  164.        
  165.         if(attacker.getKeyword().contains("CARDNAME can't be blocked except by creatures with flying.")
  166.                 && !blocker.getKeyword().contains("Flying")) return false;
  167.        
  168.  
  169.         if(attacker.getKeyword().contains("Horsemanship")) {
  170.             if(!blocker.getKeyword().contains("Horsemanship")) return false;
  171.         }
  172.        
  173.         if(attacker.getName().equals("Taoist Warrior") || attacker.getName().equals("Zuo Ci, the Mocking Sage")) {
  174.             if(blocker.getKeyword().contains("Horsemanship")) return false;
  175.         }
  176.        
  177.         if(attacker.getKeyword().contains("Fear")) {
  178.             if(!blocker.getType().contains("Artifact")
  179.                     && !CardUtil.getColors(blocker).contains(Constant.Color.Black) /*&&
  180.                                                                                    !CardUtil.getColors(blocker).contains(Constant.Color.Colorless) */) //should not include colorless, right?
  181.             return false;
  182.         }
  183.        
  184.         if (attacker.getKeyword().contains("CARDNAME can't be blocked by white creatures."))
  185.         {
  186.             if (!CardUtil.getColors(blocker).contains(Constant.Color.White))
  187.                 return false;
  188.         }
  189.        
  190.         if(attacker.getKeyword().contains("Intimidate")) {
  191.             if(!blocker.getType().contains("Artifact") && !CardFactoryUtil.sharesColorWith(attacker, blocker)) return false;
  192.         }
  193.        
  194.         if(attacker.getName().equals("Barrenton Cragtreads")) {
  195.             if(CardUtil.getColors(blocker).contains(Constant.Color.Red)) return false;
  196.         }
  197.        
  198.         if(attacker.getName().equals("Wanderbrine Rootcutters")) {
  199.             if(CardUtil.getColors(blocker).contains(Constant.Color.Green)) return false;
  200.         }
  201.        
  202.         if(/*attacker.getName().equals("Amrou Seekers")*/ attacker.getKeyword().contains("CARDNAME can't be blocked except by artifact creatures and/or white creatures.")) {
  203.             if(!blocker.getType().contains("Artifact")
  204.                     && !CardUtil.getColors(blocker).contains(Constant.Color.White)) return false;
  205.         }
  206.        
  207.         if(attacker.getName().equals("Skirk Shaman")) {
  208.             if(!blocker.getType().contains("Artifact")
  209.                     && !CardUtil.getColors(blocker).contains(Constant.Color.Red)) return false;
  210.         }
  211.        
  212.         if(attacker.getName().equals("Manta Ray")) {
  213.             if(!CardUtil.getColors(blocker).contains(Constant.Color.Blue)) return false;
  214.         }
  215.        
  216.         if(attacker.getKeyword().contains("CARDNAME can't be blocked except by black creatures.")) {
  217.             if(!CardUtil.getColors(blocker).contains(Constant.Color.Black))return false;
  218.         }
  219.        
  220. //      if(attacker.getName().equals("Goldmeadow Dodger")) return blocker.getNetAttack() < 4;
  221.        
  222. //      if(attacker.getName().equals("Juggernaut") && blocker.getType().contains("Wall")) return false;
  223.        
  224.         if (attacker.getKeyword().contains("CARDNAME can't be blocked by Walls.") && blocker.getType().contains("Wall")) return false;
  225.        
  226.         if (attacker.getKeyword().contains("CARDNAME can't be blocked except by Walls.") && !blocker.getType().contains("Wall")) return false;
  227.        
  228.         if (attacker.getKeyword().contains("CARDNAME can't be blocked except by Walls and/or creatures with flying.") &&
  229.                 !(blocker.getType().contains("Wall") || blocker.getKeyword().contains("Flying"))) return false;
  230.        
  231.         if (blocker.getCounters(Counters.BRIBERY) > 0 && isCardInPlay("Gwafa Hazid, Profiteer"))
  232.             return false;
  233.        
  234.         if (isCardInPlay("Kulrath Knight"))
  235.         {
  236.             CardList all = new CardList();
  237.             all.addAll(AllZone.getZone(Constant.Zone.Play, Constant.Player.Human).getCards());
  238.             all.addAll(AllZone.getZone(Constant.Zone.Play, Constant.Player.Computer). getCards());
  239.            
  240.             all = all.getName("Kulrath Knight");
  241.             for (int i=0; i<all.size(); i++)
  242.             {
  243.                 Card cKK = all.get(i);
  244.                 String oppKK = AllZone.GameAction.getOpponent(cKK.getController());
  245.                
  246.                 if (blocker.getController().equals(oppKK) && blocker.hasCounters())
  247.                     return false;
  248.             }
  249.         }
  250.        
  251.         return true;
  252.     }//canBlock()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement