Page 1 of 1

TgtKPump

PostPosted: 28 Jun 2009, 04:23
by Rob Cashwalker
I fixed up a couple things here.

- Added the random limiter to the canPlayAI for a mana-only cost. As the ability is played it becomes less likely to be played again.
- Added a check in the getCreature() routine to avoid granting Haste to a non-sick creature.

While I only changed a few lines here and there, I figured I might as well post the whole thing.
Code: Select all
      while(shouldTgtKPumpCard(card) != -1)
      {
        int n = shouldTgtKPumpCard(card);
        if(n != -1)
        {
          String parse = card.getKeyword().get(n).toString();
          card.removeIntrinsicKeyword(parse);

          String k[] = parse.split(":");

          String tmpCost = k[0].substring(9);
          final String keyword = k[1];
         
          boolean tapCost = false;
          boolean tapOnlyCost = false;
         
          if (tmpCost.contains("T"))
          {
             tapCost = true;
             tmpCost = tmpCost.replace("T", "");
             tmpCost = tmpCost.trim();
             if (tmpCost.length() == 0)
                tapOnlyCost = true;
          }
         
          final String manaCost = tmpCost;
         
          String tempDesc = new String();
          tempDesc = "Target creature gains " + keyword + " until end of turn.";
          final String Desc = tempDesc;
         
          if (! tapCost)
          {
              final SpellAbility ability = new Ability_Activated(card, manaCost)
              {

            private static final long serialVersionUID = -1118592153328758083L;
            
            public boolean canPlayAI()
                {
                  //if(CardFactoryUtil.AI_doesCreatureAttack(card))
                  //  return false;
              CardList list = getCreature();
              if (list.isEmpty())
                 return false;
              else
              {
                 Random r = new Random();
                 if (r.nextFloat() <= Math.pow(.6667, card.getAbilityUsed()))
                    return true;
                 else
                    return false;
              }
                }
            
            
                public boolean canPlay()
                {
               
                   if (CardFactoryUtil.canUseAbility(card) && AllZone.GameAction.isCardInPlay(card)&&
                      !card.isFaceDown())
                      return true;
                   else
                      return false;
                }
                public void chooseTargetAI()
                {
                  Card target = CardFactoryUtil.AI_getBestCreature(getCreature());
                  setTargetCard(target);
                }
                CardList getCreature()
                {
                  CardList list = new CardList(AllZone.Computer_Play.getCards());
                  list = list.filter(new CardListFilter()
                  {
                    public boolean addCard(Card c)
                    {
                      return c.isCreature() &&
                            (!CardFactoryUtil.AI_doesCreatureAttack(c)) && CardFactoryUtil.canTarget(card, c) &&
                            (! c.getKeyword().contains(keyword)) &&
                            (! c.getKeyword().contains("Defender")) &&
                            (! c.hasSickness() && keyword.equals("Haste"));
                    }
                  });
                  // list.remove(card);      // if mana-only cost, allow self-target
                  return list;
                }//getCreature()
                public void resolve()
                {
                  if(AllZone.GameAction.isCardInPlay(getTargetCard()) && CardFactoryUtil.canTarget(card, getTargetCard()) )
                  {
                    final Card[] creature = new Card[1];
                    final Command EOT = new Command()
                    {
                  private static final long serialVersionUID = -8840812331316327448L;

               public void execute()
                      {
                        if(AllZone.GameAction.isCardInPlay(creature[0]))
                          creature[0].removeExtrinsicKeyword(keyword);
                      }
                    };
                    creature[0] = getTargetCard();
                    creature[0].addExtrinsicKeyword(keyword);
                    card.setAbilityUsed(card.getAbilityUsed()+1);
                    AllZone.EndOfTurn.addUntil(EOT);
                  }//if (card is in play)
                }//resolve()
              };//SpellAbility
             
              ability.setDescription(manaCost + ":" + Desc);
              ability.setStackDescription(Desc);

              ability.setBeforePayMana(CardFactoryUtil.input_targetCreature(ability));
              card.addSpellAbility(ability);
          }
          if (tapOnlyCost)
          {
              final SpellAbility ability = new Ability_Tap(card)
              {
            private static final long serialVersionUID = 5252594757468128739L;
            
            public boolean canPlayAI()
                {
                  if(CardFactoryUtil.AI_doesCreatureAttack(card))
                    return false;
                 
                  return getCreature().size() != 0;
                }
                public boolean canPlay()
                {
                   boolean sick = true;
                   
                   if (!card.hasSickness() || !card.isCreature())
                       sick = false;
                   
                   if (card.isUntapped() && CardFactoryUtil.canUseAbility(card) && AllZone.GameAction.isCardInPlay(card)
                       && !sick && !card.isFaceDown())
                      return true;
                   else
                      return false;
                }
                public void chooseTargetAI()
                {
                   card.tap();
                   Card target = CardFactoryUtil.AI_getBestCreature(getCreature());
                   setTargetCard(target);
                }
                CardList getCreature()
                {
                  CardList list = new CardList(AllZone.Computer_Play.getCards());
                  list = list.filter(new CardListFilter()
                  {
                    public boolean addCard(Card c)
                    {
                      return c.isCreature() &&
                            (!CardFactoryUtil.AI_doesCreatureAttack(c)) &&
                            (! c.getKeyword().contains(keyword)) &&
                            (! c.getKeyword().contains("Defender")) &&
                            (! c.hasSickness() && keyword.equals("Haste"));
                    }
                  });
                  list.remove(card);
                  return list;
                }//getCreature()
                public void resolve()
                {
                  if(AllZone.GameAction.isCardInPlay(getTargetCard()) && CardFactoryUtil.canTarget(card, getTargetCard()))
                  {
                    final Card[] creature = new Card[1];
                    final Command EOT = new Command()
                    {
                  private static final long serialVersionUID = 2134353417588894452L;

               public void execute()
                      {
                        if(AllZone.GameAction.isCardInPlay(creature[0]))
                          creature[0].removeExtrinsicKeyword(keyword);
                      }
                    };
                    creature[0] = getTargetCard();
                    creature[0].addExtrinsicKeyword(keyword);
                    AllZone.EndOfTurn.addUntil(EOT);
                  }//if (card is in play)
                }//resolve()
              };//SpellAbility
             
              ability.setDescription("tap:" + Desc);
              ability.setStackDescription(Desc);

              ability.setBeforePayMana(CardFactoryUtil.input_targetCreature(ability));
              card.addSpellAbility(ability);
          }
          if (! tapOnlyCost && tapCost)
          {
              final SpellAbility ability = new Ability_Tap(card, manaCost)
              {
            private static final long serialVersionUID = 7593387152288440603L;
            
            public boolean canPlayAI()
                {
                  if(CardFactoryUtil.AI_doesCreatureAttack(card))
                    return false;
                 
                  return getCreature().size() != 0;
                }
                public boolean canPlay()
                {
                   boolean sick = true;
                   
                   if (!card.hasSickness() || !card.isCreature())
                      sick = false;
                   
                   if (card.isUntapped() && CardFactoryUtil.canUseAbility(card) && AllZone.GameAction.isCardInPlay(card) &&
                     !sick && !card.isFaceDown())
                      return true;
                   else
                      return false;
                }
                public void chooseTargetAI()
                {
                   card.tap();
                   Card target = CardFactoryUtil.AI_getBestCreature(getCreature());
                   setTargetCard(target);
                }
                CardList getCreature()
                {
                  CardList list = new CardList(AllZone.Computer_Play.getCards());
                  list = list.filter(new CardListFilter()
                  {
                    public boolean addCard(Card c)
                    {
                      return c.isCreature() &&
                            (!CardFactoryUtil.AI_doesCreatureAttack(c)) &&
                            (! c.getKeyword().contains(keyword)) &&
                            (! c.getKeyword().contains("Defender")) &&
                            (! c.hasSickness() && keyword.equals("Haste"));
                    }
                  });
                  list.remove(card);
                  return list;
                }//getCreature()
                public void resolve()
                {
                  if(AllZone.GameAction.isCardInPlay(getTargetCard()) && CardFactoryUtil.canTarget(card ,getTargetCard()))
                  {
                    final Card[] creature = new Card[1];
                    final Command EOT = new Command()
                    {
                  private static final long serialVersionUID = 3532917180149273560L;

               public void execute()
                      {
                        if(AllZone.GameAction.isCardInPlay(creature[0]))
                          creature[0].removeExtrinsicKeyword(keyword);
                      }
                    };
                    creature[0] = getTargetCard();
                    creature[0].addExtrinsicKeyword(keyword);
                    AllZone.EndOfTurn.addUntil(EOT);
                  }//if (card is in play)
                }//resolve()
              };//SpellAbility
             
              ability.setDescription(manaCost + ", tap:" + Desc);
              ability.setStackDescription(Desc);

              ability.setBeforePayMana(CardFactoryUtil.input_targetCreature(ability));
              card.addSpellAbility(ability);
          }
        }
      }//while
Dennis - I'd like to request that while you're in there, please change TgtKPump to abTgtKPump to be in line with the convention. (that I suggested after I originally wrote this one) Should be a simple find/replace job in the source files and cards.txt.

Re: TgtKPump

PostPosted: 28 Jun 2009, 06:23
by DennisBergkamp
Ok Rob, sounds good :)
By the way, I'm on vacation (back home again in the Netherlands for a couple of weeks :supz: ).
I just got back, so I have a pretty bad jetlag, waking up at 6 and falling asleep at random times during the day. Anyway, I'm not sure what this means in terms of working on MTGForge (might be more, might be less).