Damage Creature or Player Ability Code
Post MTG Forge Related Programming Questions Here
Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins
Damage Creature or Player Ability Code
by Rob Cashwalker » 02 Jun 2009, 03:14
Prodigal Sorcerer & Anaba Shaman and a bunch of others....
abDamageCP {mana/T}:{damage}
abDamageCP {mana/T}:{damage}
- Code: Select all
private final int shouldAbDamageCP(Card c) {
ArrayList<String> a = c.getKeyword();
for (int i = 0; i < a.size(); i++)
{
if (a.get(i).toString().startsWith("abDamageCP"))
return i;
}
return -1;
}
- Code: Select all
if (shouldAbDamageCP(card) != -1)
{
int n = shouldAbDamageCP(card);
if (n != -1)
{
String parse = card.getKeyword().get(n).toString();
card.removeIntrinsicKeyword(parse);
String k[] = parse.split(":");
String tmpCost = k[0].substring(10);
final int dmg[] = new int[1];
dmg[0] = Integer.parseInt(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 = cardName + " deals " + dmg + " damage to target creature or player.";
final String Desc = tempDesc;
if (! tapCost)
{
final SpellAbility ability = new Ability_Activated(card, manaCost)
{
private static final long serialVersionUID = -7560349014757367722L;
public boolean canPlayAI()
{
Random r = new Random();
if (r.nextFloat() <= Math.pow(.6667, card.getAbilityUsed()))
return true;
else
return false;
}
public void chooseTargetAI()
{
CardList list = CardFactoryUtil.AI_getHumanCreature(1, card, true);
list.shuffle();
if(list.isEmpty() || AllZone.Human_Life.getLife() < 5 + dmg[0])
setTargetPlayer(Constant.Player.Human);
else
setTargetCard(list.get(0));
}//chooseTargetAI
public void resolve()
{
if(getTargetCard() != null)
{
if(AllZone.GameAction.isCardInPlay(getTargetCard()) && CardFactoryUtil.canTarget(card, getTargetCard()) )
getTargetCard().addDamage(dmg[0]);
}
else
AllZone.GameAction.getPlayerLife(getTargetPlayer()).subtractLife(dmg[0]);
}//resolve()
};//Ability_Activated
ability.setDescription(manaCost + ": " + Desc);
ability.setBeforePayMana(CardFactoryUtil.input_targetCreaturePlayer(ability, true));
card.addSpellAbility(ability);
}//!tapCost
if (tapOnlyCost == true)
{
final Ability_Tap ability = new Ability_Tap(card)
{
private static final long serialVersionUID = -7560349014757367722L;
public void chooseTargetAI()
{
CardList list = CardFactoryUtil.AI_getHumanCreature(1, card, true);
list.shuffle();
if(list.isEmpty() || AllZone.Human_Life.getLife() < 5 + dmg[0])
setTargetPlayer(Constant.Player.Human);
else
setTargetCard(list.get(0));
}//chooseTargetAI
public void resolve()
{
if(getTargetCard() != null)
{
if(AllZone.GameAction.isCardInPlay(getTargetCard()) && CardFactoryUtil.canTarget(card, getTargetCard()) )
getTargetCard().addDamage(dmg[0]);
}
else
AllZone.GameAction.getPlayerLife(getTargetPlayer()).subtractLife(dmg[0]);
}//resolve()
};//Ability_Tap
ability.setDescription("tap: " + Desc);
ability.setBeforePayMana(CardFactoryUtil.input_targetCreaturePlayer(ability, true));
card.addSpellAbility(ability);
}//tapOnlyCost
if (! tapOnlyCost && tapCost)
{
final SpellAbility ability = new Ability_Tap(card, manaCost)
{
private static final long serialVersionUID = -7560349014757367722L;
public void chooseTargetAI()
{
CardList list = CardFactoryUtil.AI_getHumanCreature(1, card, true);
list.shuffle();
if(list.isEmpty() || AllZone.Human_Life.getLife() < 5 + dmg[0])
setTargetPlayer(Constant.Player.Human);
else
setTargetCard(list.get(0));
}//chooseTargetAI
public void resolve()
{
if(getTargetCard() != null)
{
if(AllZone.GameAction.isCardInPlay(getTargetCard()) && CardFactoryUtil.canTarget(card, getTargetCard()) )
getTargetCard().addDamage(dmg[0]);
}
else
AllZone.GameAction.getPlayerLife(getTargetPlayer()).subtractLife(dmg[0]);
}//resolve()
};//Ability_Tap
ability.setDescription(manaCost + ", tap: " + Desc);
ability.setBeforePayMana(CardFactoryUtil.input_targetCreaturePlayer(ability, true));
card.addSpellAbility(ability);
}//!tapOnlyCost && tapCost
}//n
}//AbDamageCP
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
Re: Damage Creature or Player Ability Code
by DennisBergkamp » 02 Jun 2009, 03:29
Nice job, Rob! I'll add this
-
DennisBergkamp - AI Programmer
- Posts: 2602
- Joined: 09 Sep 2008, 15:46
- Has thanked: 0 time
- Been thanked: 0 time
Re: Damage Creature or Player Ability Code
by DennisBergkamp » 04 Jun 2009, 17:22
And I thought you could only get abdamage by doing too many sit-ups
Anyway, I've just tested this with Prodigal Sorcerer, and it works fine except for its card text:
"tap: Prodigal Sorcerer deals [I@ccc96 damage to target creature or player."
EDIT: ahh, the Desc string should append dmg[0] instead of dmg
Anyway, I've just tested this with Prodigal Sorcerer, and it works fine except for its card text:
"tap: Prodigal Sorcerer deals [I@ccc96 damage to target creature or player."
EDIT: ahh, the Desc string should append dmg[0] instead of dmg
-
DennisBergkamp - AI Programmer
- Posts: 2602
- Joined: 09 Sep 2008, 15:46
- Has thanked: 0 time
- Been thanked: 0 time
Re: Damage Creature or Player Ability Code
by mtgrares » 04 Jun 2009, 18:13
Great work rob.
I've done that mistake many times.EDIT: ahh, the Desc string should append dmg[0] instead of dmg
- mtgrares
- DEVELOPER
- Posts: 1352
- Joined: 08 Sep 2008, 22:10
- Has thanked: 3 times
- Been thanked: 12 times
4 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 22 guests