new Keyword: abUntapTgt
Post MTG Forge Related Programming Questions Here
Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins
new Keyword: abUntapTgt
by slapshot5 » 07 Oct 2010, 14:07
I checked in code for a new keyword: abUntapTgt
Code:
- Code: Select all
abUntapTgt {Ability Cost}:{Valid Cards}:{Description}
Code:
- Code: Select all
// Generic untap target ___ activated ability
//abUntapTgt {Ability_Cost}:{Valid Targets}:{Description}
if (hasKeyword(card, "abUntapTgt") != -1)
{
int n = hasKeyword(card, "abUntapTgt");
String parse = card.getKeyword().get(n).toString();
card.removeIntrinsicKeyword(parse);
String k[] = parse.split(":");
String tmpCost = k[0].substring(10);
final Ability_Cost abCost = new Ability_Cost(tmpCost, card.getName(), true);
final Target untapTargets = new Target("TgtV");
final String Tgts[] = k[1].split(",");
untapTargets.setValidTgts(Tgts);
final String abDesc[] = {"none"};
abDesc[0] = k[2];
String tmpDesc = abDesc[0].substring(13);
int i = tmpDesc.indexOf(".");
tmpDesc = tmpDesc.substring(0, i);
untapTargets.setVTSelection("Select target " + tmpDesc + " to untap.");
abDesc[0] = abCost.toString() + abDesc[0];
final SpellAbility AbUntapTgt = new Ability_Activated(card, abCost, untapTargets) {
@Override
public boolean canPlayAI() {
if (!ComputerUtil.canPayCost(this))
return false;
CardList hCards = getTargets();
Random r = new Random();
boolean rr = false;
if (r.nextFloat() <= Math.pow(.6667, card.getAbilityUsed()))
rr = true;
if(hCards.size() > 0) {
Card c = null;
CardList dChoices = new CardList();
for(int i = 0; i < Tgts.length; i++) {
if (Tgts[i].startsWith("Creature")) {
c = CardFactoryUtil.AI_getBestCreature(hCards);
if (c != null)
dChoices.add(c);
}
CardListUtil.sortByTextLen(hCards);
dChoices.add(hCards.get(0));
CardListUtil.sortCMC(hCards);
dChoices.add(hCards.get(0));
}
c = dChoices.get(CardUtil.getRandomIndex(dChoices));
setTargetCard(c);
return rr;
}
return false;
}
CardList getTargets() {
CardList tmpList = AllZoneUtil.getPlayerCardsInPlay(Constant.Player.Human);
tmpList = tmpList.getValidCards(Tgts);
tmpList = tmpList.getTargetableCards(card);
return tmpList;
}
@Override
public boolean canPlay() {
Cost_Payment pay = new Cost_Payment(abCost, this);
return (pay.canPayAdditionalCosts() && CardFactoryUtil.canUseAbility(card) && super.canPlay());
}
@Override
public void resolve() {
Card tgtC = getTargetCard();
if(AllZone.GameAction.isCardInPlay(tgtC)
&& CardFactoryUtil.canTarget(card, tgtC)) {
tgtC.untap();
}
}
}; //AbTapTgt
AbUntapTgt.setDescription(abDesc[0]);
card.addSpellAbility(AbUntapTgt);
}//End abUntapTgt
- Code: Select all
Name:Ley Druid
ManaCost:2 G
Types:Creature Human Druid
Text:no text
PT:1/1
K:abUntapTgt T:Land:Untap target land.
SVar:RemAIDeck:True
SVar:Rarity:Uncommon
SVar:Picture:http://www.wizards.com/global/images/magic/general/ley_druid.jpg
End
- slapshot5
- Programmer
- Posts: 1391
- Joined: 03 Jan 2010, 17:47
- Location: Mac OS X
- Has thanked: 25 times
- Been thanked: 68 times
Re: new Keyword: abUntapTgt
by friarsol » 07 Oct 2010, 14:39
I don't see the specific line just quickly looking through the code. Will the AI try to untap things that are already untapped?
- friarsol
- Global Moderator
- Posts: 7593
- Joined: 15 May 2010, 04:20
- Has thanked: 243 times
- Been thanked: 965 times
Re: new Keyword: abUntapTgt
by slapshot5 » 08 Oct 2010, 03:53
I guess in my brain that was handled by getValidTargets(). I've now added a filter for untapped cards.friarsol wrote:I don't see the specific line just quickly looking through the code. Will the AI try to untap things that are already untapped?
-slapshot5
- slapshot5
- Programmer
- Posts: 1391
- Joined: 03 Jan 2010, 17:47
- Location: Mac OS X
- Has thanked: 25 times
- Been thanked: 68 times
Re: new Keyword: abUntapTgt
by friarsol » 08 Oct 2010, 04:09
Yea sometimes I think functions do things they don't too. Does abTapTgt need a check for untapped stuff?
- friarsol
- Global Moderator
- Posts: 7593
- Joined: 15 May 2010, 04:20
- Has thanked: 243 times
- Been thanked: 965 times
Re: new Keyword: abUntapTgt
by slapshot5 » 08 Oct 2010, 04:13
I put those checks in at the same time I did abUntapTgt.friarsol wrote:Yea sometimes I think functions do things they don't too. Does abTapTgt need a check for untapped stuff?
- slapshot5
- Programmer
- Posts: 1391
- Joined: 03 Jan 2010, 17:47
- Location: Mac OS X
- Has thanked: 25 times
- Been thanked: 68 times
Re: new Keyword: abUntapTgt
by friarsol » 08 Oct 2010, 04:30
Figured you would. Just thought I'd double check.
- friarsol
- Global Moderator
- Posts: 7593
- Joined: 15 May 2010, 04:20
- Has thanked: 243 times
- Been thanked: 965 times
6 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 41 guests