CardFactory Cleaning
 Posted: 22 Jun 2009, 11:38
Posted: 22 Jun 2009, 11:38Ok, this shall be where I'll post card coding/cleanup suggestions. They will be in the format of "<cards.txt text> /n/n <suggested Factory code>", and I have three so far:
---1 Blight Sickle: At Rob's request, I shall paste a copy here:
			---1 Blight Sickle: At Rob's request, I shall paste a copy here:
- Code: Select all
- Blight Sickle
 2
 Artifact Equipment
 Equipped creature gets +1/+0 and has Wither.
- Code: Select all
- //*************** START *********** START **************************
 if (cardName.equals("Blight Sickle"))
 {
 final Ability equip = new Ability(card, "2")
 {
 public void resolve()
 {
 if (AllZone.GameAction.isCardInPlay(getTargetCard()) && CardFactoryUtil.canTarget(card, getTargetCard()) )
 {
 if (card.isEquipping())
 {
 Card crd = card.getEquipping().get(0);
 if (crd.equals(getTargetCard()) )
 return;
 
 card.unEquipCard(crd);
 }
 card.equipCard(getTargetCard());
 }
 }
 
 public boolean canPlay()
 {
 return AllZone.getZone(card).is(Constant.Zone.Play) &&
 AllZone.Phase.getActivePlayer().equals(card.getController()) &&
 !AllZone.Phase.getPhase().equals("End of Turn") &&
 !AllZone.Phase.getPhase().equals(Constant.Phase.Combat_Declare_Blockers_InstantAbility);
 }
 
 public boolean canPlayAI()
 {
 return getCreature().size() != 0 && !card.isEquipping();
 }
 
 
 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("Defender"));
 }
 });
 // list.remove(card); // if mana-only cost, allow self-target
 return list;
 }//getCreature()
 
 };//equip ability
 
 Command onEquip = new Command()
 {
 private static final long serialVersionUID = 8130682765214560887L;
 public void execute()
 {
 if (card.isEquipping())
 {
 Card crd = card.getEquipping().get(0);
 crd.addExtrinsicKeyword("Wither");
 crd.addSemiPermanentAttackBoost(1);
 }
 }//execute()
 };//Command
 
 Command onUnEquip = new Command()
 {
 private static final long serialVersionUID = 5783423127748320501L;
 public void execute()
 {
 if (card.isEquipping())
 {
 Card crd = card.getEquipping().get(0);
 crd.removeExtrinsicKeyword("Wither");
 crd.addSemiPermanentAttackBoost(-1);
 
 }
 
 }//execute()
 };//Command
 
 
 Input runtime = new Input()
 {
 private static final long serialVersionUID = -6785656229070523470L;
 public void showMessage()
 {
 //get all creatures you control
 CardList list = new CardList();
 list.addAll(AllZone.Human_Play.getCards());
 list = list.getType("Creature");
 
 stopSetNext(CardFactoryUtil.input_targetSpecific(equip, list, "Select target creature to equip", true));
 }
 };//Input
 
 equip.setBeforePayMana(runtime);
 
 equip.setDescription("Equip: 2");
 card.addSpellAbility(equip);
 
 card.setEquip(onEquip);
 card.setUnEquip(onUnEquip);
 } //*************** END ************ END **************************
- Code: Select all
- Akki Drillmaster
 2 R
 Creature Goblin Shaman
 no text
 2/2
 >TgtKPump T:Haste
- Code: Select all
- Code: Select all
- //***Keep as is:
 Sensei's Divining Top
 1
 Artifact
 no text
- Code: Select all
- else if(cardName.equals("Sensei's Divining Top"))
 {
 //ability2: Draw card, and put divining top on top of library
 final SpellAbility ability2 = new Ability_Tap(card, "0")
 {
 private static final long serialVersionUID = -2523015092351744208L;
 public void resolve()
 {
 String player = card.getController();
 String owner = card.getOwner();
 
 PlayerZone play = AllZone.getZone(Constant.Zone.Play, player);
 PlayerZone lib = AllZone.getZone(Constant.Zone.Library, owner);
 
 AllZone.GameAction.drawCard(player);
 play.remove(card);
 lib.add(card,0); //move divining top to top of library
 card.untap();
 
 }
 public boolean canPlayAI()
 {
 return false;
 }
 public boolean canPlay()
 {
 if (AllZone.getZone(card).is(Constant.Zone.Play))
 return true;
 else
 return false;
 }//canPlay()
 };//SpellAbility ability2
 ability2.setBeforePayMana(new Input()
 {
 private static final long serialVersionUID = -4773496833654414458L;
 @SuppressWarnings("unused") // check
 int check = -1;
 public void showMessage()
 {
 AllZone.Stack.push(ability2);
 stop();
 }//showMessage()
 });
 
 //ability (rearrange top 3 cards) :
 final SpellAbility ability1 = new Ability(card, "1")
 {
 public void resolve()
 {
 
 String player = card.getController();
 PlayerZone lib = AllZone.getZone(Constant.Zone.Library, player);
 
 if (lib.size() < 3)
 return;
 
 CardList topThree = new CardList();
 
 //show top 3 cards:
 topThree.add(lib.get(0));
 topThree.add(lib.get(1));
 topThree.add(lib.get(2));
 
 > for (int i=1;i<=3;i++){
 > String Title = "Put on top: ";
 > if (i==2) Title = "Put second from top: ";
 > if (i==3) Title = "Put third from top: ";
 > Object o = AllZone.Display.getChoiceOptional(Title, topThree.toArray());
 > if(o == null) break;
 > Card c_1 = (Card)o;
 > topThree.remove(c_1);
 > lib.remove(c_1);
 > lib.add(c_1,i-1);
 > }
 }
 public boolean canPlayAI()
 {
 return false;
 
 }
 public boolean canPlay()
 {
 if (AllZone.getZone(card).is(Constant.Zone.Play))
 return true;
 else
 return false;
 }//canPlay()
 };//SpellAbility ability1
 ability1.setDescription("1: Look at the top three cards of your library, then put them back in any order.");
 ability1.setStackDescription("Sensei's Divining Top - rearrange top 3 cards");
 card.addSpellAbility(ability1);
 ability1.setBeforePayMana(new Input_PayManaCost(ability1));
 ability2.setDescription("tap: Draw a card, then put Sensei's Divining Top on top of its owner's library.");
 ability2.setStackDescription("Sensei's Divining Top - draw a card, then put back on owner's library");
 ability2.setBeforePayMana(new Input_NoCost_TapAbility((Ability_Tap) ability2));
 card.addSpellAbility(ability2);
 
 }

 (I copied the saproling one):
 (I copied the saproling one):