abGainLife[Tgt] keyword
Post MTG Forge Related Programming Questions Here
Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins
1 post
• Page 1 of 1
abGainLife[Tgt] keyword
by Rob Cashwalker » 25 Mar 2010, 01:26
Nothing surprising... just the usual....
Cards:
Cards:
- Code: Select all
Braidwood Cup
3
Artifact
no text
abGainLife T:1
Fountain of Youth
0
Artifact
no text
abGainLife 2 T:1
Marble Chalice
2 W
Artifact
no text
abGainLife T:1
Mournful Zombie
2 B
Creature Zombie
no text
2/1
abGainLifeTgt W T:1
Silent Attendant
2 W
Creature Human Cleric
no text
0/2
abGainLife T:1
Starlight Invoker
1 W
Creature Human Cleric Mutant
no text
1/3
abGainLife 7 W:5
Tanglebloom
1
Artifact
no text
abGainLife 1 T:1
Tower of Eons
4
Artifact
no text
abGainLife 8 T:10
Wellwisher
1 G
Creature Elf
no text
1/1
abGainLife T:X:You gain 1 life for each Elf on the battlefield.
SVar:X:Count$TypeOnBattlefield.Elf
- Code: Select all
if (hasKeyword(card, "abGainLife") != -1)
{
int n = hasKeyword(card, "abGainLife");
if (n != -1)
{
String parse = card.getKeyword().get(n).toString();
card.removeIntrinsicKeyword(parse);
String k[] = parse.split(":");
final boolean Tgt[] = {false};
Tgt[0] = k[0].contains("Tgt");
String tmpCost = "";
if (Tgt[0])
tmpCost = k[0].substring(13);
else
tmpCost = k[0].substring(10);
boolean tapCost = false;
boolean tapOnlyCost = false;
if (tmpCost.contains("T"))
{
tapCost = true;
tmpCost = tmpCost.replace("T", "").trim();
if (tmpCost.length() == 0)
tapOnlyCost = true;
}
final String manaCost = tmpCost;
final int NumLife[] = {-1};
final String NumLifeX[] = {"none"};
if (k[1].matches("X"))
{
String x = card.getSVar(k[1]);
if (x.startsWith("Count$"))
{
String kk[] = x.split("\\$");
NumLifeX[0] = kk[1];
}
}
else if (k[1].matches("[0-9][0-9]?"))
NumLife[0] = Integer.parseInt(k[1]);
// drawbacks and descriptions
final String DrawBack[] = {"none"};
final String spDesc[] = {"none"};
final String stDesc[] = {"none"};
if (k.length > 2)
{
if (k[2].contains("Drawback$"))
{
String kk[] = k[2].split("\\$");
DrawBack[0] = kk[1];
if (k.length > 3)
spDesc[0] = k[3];
if (k.length > 4)
stDesc[0] = k[4];
}
else
{
if (k.length > 2)
spDesc[0] = k[2];
if (k.length > 3)
stDesc[0] = k[3];
}
}
else
{
if (Tgt[0] == true)
{
spDesc[0] = "Target player gains " + NumLife[0] + " life.";
stDesc[0] = cardName + " - target player gains life";
}
else
{
spDesc[0] = "You gain " + NumLife[0] + " life.";
stDesc[0] = cardName + " - you gain life";
}
}
if (!tapCost)
{
final SpellAbility abGainLife = new Ability_Activated(card, manaCost)
{
private static final long serialVersionUID = -936369754466156082L;
public int getNumLife()
{
if (NumLife[0] != -1)
return NumLife[0];
if (! NumLifeX[0].equals("none"))
return CardFactoryUtil.xCount(card, NumLifeX[0]);
return 0;
}
public boolean canPlayAI()
{
Random r = new Random();
boolean rr = false; // prevent run-away activations - first time will always return true
if (r.nextFloat() <= Math.pow(.6667, card.getAbilityUsed()))
rr = true;
if (Tgt[0] == true)
setTargetPlayer(Constant.Player.Computer);
if (AllZone.Computer_Life.getLife() < 10)
return true && rr;
else
return ((r.nextFloat() < .6667) && rr);
}
public void resolve()
{
int nlife = getNumLife();
String TgtPlayer;
if (Tgt[0] == true)
TgtPlayer = getTargetPlayer();
else
TgtPlayer = card.getController();
AllZone.GameAction.addLife(TgtPlayer, nlife);
if (!DrawBack[0].equals("none"))
CardFactoryUtil.doDrawBack(DrawBack[0], nlife, card.getController(), AllZone.GameAction.getOpponent(card.getController()), TgtPlayer, card, null);
}//resolve()
};//SpellAbility
if (Tgt[0] == true)
abGainLife.setBeforePayMana(CardFactoryUtil.input_targetPlayer(abGainLife));
abGainLife.setDescription(manaCost + ": " + spDesc[0]);
abGainLife.setStackDescription(stDesc[0]);
card.addSpellAbility(abGainLife);
}
else
{
final SpellAbility abGainLife = new Ability_Tap(card)
{
private static final long serialVersionUID = -3661692584660594012L;
public int getNumLife()
{
if (NumLife[0] != -1)
return NumLife[0];
if (! NumLifeX[0].equals("none"))
return CardFactoryUtil.xCount(card, NumLifeX[0]);
return 0;
}
public boolean canPlayAI()
{
boolean att = !CardFactoryUtil.AI_doesCreatureAttack(card);
if (Tgt[0] == true)
setTargetPlayer(Constant.Player.Computer);
if (AllZone.Computer_Life.getLife() < 10)
return true && att;
else
{
Random r = new Random();
return ((r.nextFloat() < .6667) && att);
}
}
public void resolve()
{
int nlife = getNumLife();
String TgtPlayer;
if (Tgt[0] == true)
TgtPlayer = getTargetPlayer();
else
TgtPlayer = card.getController();
AllZone.GameAction.addLife(TgtPlayer, nlife);
if (!DrawBack[0].equals("none"))
CardFactoryUtil.doDrawBack(DrawBack[0], nlife, card.getController(), AllZone.GameAction.getOpponent(card.getController()), TgtPlayer, card, null);
}//resolve()
};//SpellAbility
if (Tgt[0] == true)
abGainLife.setBeforePayMana(CardFactoryUtil.input_targetPlayer(abGainLife));
if (tapOnlyCost)
abGainLife.setDescription("Tap: " + spDesc[0]);
else
{
abGainLife.setDescription(manaCost + ", tap: " + spDesc[0]);
abGainLife.setManaCost(manaCost);
}
abGainLife.setStackDescription(stDesc[0]);
card.addSpellAbility(abGainLife);
}
}
}// abGainLife
The Force will be with you, Always.
-
Rob Cashwalker - Programmer
- Posts: 2167
- Joined: 09 Sep 2008, 15:09
- Location: New York
- Has thanked: 5 times
- Been thanked: 40 times
1 post
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 22 guests