- Fix for GainLife Drawback

- Added LoseLife SubAbility handling
- Converted Death Cultist to SubAbility
This commit is contained in:
jendave
2011-08-06 11:06:14 +00:00
parent 1cdf7b3ef4
commit 77b87147c1
3 changed files with 85 additions and 30 deletions

View File

@@ -1,9 +1,10 @@
Name:Death Cultist Name:Death Cultist
ManaCost:B ManaCost:B
Types:Creature Human Wizard Types:Creature Human Wizard
Text:Sacrifice Death Cultist: Target player loses 1 life and you gain 1 life. Text:no text
PT:1/1 PT:1/1
A:AB$LoseLife | Cost$ Sac<1/CARDNAME> | ValidTgts$ player | TgtPrompt$ Target a player to lose a life | LifeAmount$ 1 | SubAbility$ YouGainLife/1 | SpellDescription$ Target player loses 1 life. A:AB$LoseLife | Cost$ Sac<1/CARDNAME> | ValidTgts$ player | TgtPrompt$ Target a player to lose a life | LifeAmount$ 1 | SubAbility$ SVar=DB1 | SpellDescription$ Target player loses 1 life and you gain 1 life.
SVar:DB1:DB$GainLife | LifeAmount$ 1
SVar:Rarity:Common SVar:Rarity:Common
SVar:Picture:http://www.wizards.com/global/images/magic/general/death_cultist.jpg SVar:Picture:http://www.wizards.com/global/images/magic/general/death_cultist.jpg
End End

View File

@@ -244,7 +244,7 @@ public class AbilityFactory {
else if (isSp) else if (isSp)
SA = AbilityFactory_AlterLife.createSpellGainLife(this); SA = AbilityFactory_AlterLife.createSpellGainLife(this);
else if (isDb) else if (isDb)
SA = AbilityFactory_AlterLife.createSpellGainLife(this); SA = AbilityFactory_AlterLife.createDrawbackGainLife(this);
if(hasSubAbility()) if(hasSubAbility())
SA.setSubAbility(getSubAbility()); SA.setSubAbility(getSubAbility());
} }
@@ -252,9 +252,13 @@ public class AbilityFactory {
if (API.equals("LoseLife")){ if (API.equals("LoseLife")){
if (isAb) if (isAb)
SA = AbilityFactory_AlterLife.createAbilityLoseLife(this); SA = AbilityFactory_AlterLife.createAbilityLoseLife(this);
if (isSp){ else if (isSp){
SA = AbilityFactory_AlterLife.createSpellLoseLife(this); SA = AbilityFactory_AlterLife.createSpellLoseLife(this);
} }
else if (isDb)
SA = AbilityFactory_AlterLife.createDrawbackLoseLife(this);
if(hasSubAbility())
SA.setSubAbility(getSubAbility());
} }
if (API.equals("Fog")){ if (API.equals("Fog")){

View File

@@ -123,17 +123,7 @@ public class AbilityFactory_AlterLife {
@Override @Override
public String getStackDescription(){ public String getStackDescription(){
// when getStackDesc is called, just build exactly what is happening // when getStackDesc is called, just build exactly what is happening
StringBuilder sb = new StringBuilder(); return loseLifeStackDescription(af, this);
String name = af.getHostCard().getName();
int amount = calculateAmount(af.getHostCard(), params.get("LifeAmount"), this);
Player player = getActivatingPlayer().getOpponent();
if (af.getAbTgt() != null)
player = getTargetPlayer();
sb.append(name).append(" - ").append(player).append(" loses ").append(amount).append(" life.");
return sb.toString();
} }
public boolean canPlay(){ public boolean canPlay(){
@@ -159,7 +149,7 @@ public class AbilityFactory_AlterLife {
} }
public static SpellAbility createSpellLoseLife(final AbilityFactory AF){ public static SpellAbility createSpellLoseLife(final AbilityFactory AF){
final SpellAbility abLoseLife = new Spell(AF.getHostCard(), AF.getAbCost(), AF.getAbTgt()){ final SpellAbility spLoseLife = new Spell(AF.getHostCard(), AF.getAbCost(), AF.getAbTgt()){
private static final long serialVersionUID = -2966932725306192437L; private static final long serialVersionUID = -2966932725306192437L;
final AbilityFactory af = AF; final AbilityFactory af = AF;
@@ -168,16 +158,7 @@ public class AbilityFactory_AlterLife {
@Override @Override
public String getStackDescription(){ public String getStackDescription(){
// when getStackDesc is called, just build exactly what is happening // when getStackDesc is called, just build exactly what is happening
StringBuilder sb = new StringBuilder(); return loseLifeStackDescription(af, this);
String name = af.getHostCard().getName();
int amount = calculateAmount(af.getHostCard(), params.get("LifeAmount"), this);
Player player = getActivatingPlayer().getOpponent();
if (af.getAbTgt() != null)
player = getTargetPlayer();
sb.append(name).append(" - ").append(player).append(" loses ").append(amount).append(" life.");
return sb.toString();
} }
public boolean canPlay(){ public boolean canPlay(){
@@ -199,7 +180,42 @@ public class AbilityFactory_AlterLife {
loseLifeResolve(af, this, amount); loseLifeResolve(af, this, amount);
} }
}; };
return abLoseLife; return spLoseLife;
}
public static SpellAbility createDrawbackLoseLife(final AbilityFactory AF){
final SpellAbility dbLoseLife = new Ability_Sub(AF.getHostCard(), AF.getAbTgt()){
private static final long serialVersionUID = -2966932725306192437L;
final AbilityFactory af = AF;
final HashMap<String,String> params = af.getMapParams();
@Override
public String getStackDescription(){
// when getStackDesc is called, just build exactly what is happening
return loseLifeStackDescription(af, this);
}
public boolean canPlayAI()
{
// if X depends on abCost, the AI needs to choose which card he would sacrifice first
// then call xCount with that card to properly calculate the amount
// Or choosing how many to sacrifice
return loseLifeCanPlayAI(af, this, params.get("LifeAmount"));
}
@Override
public void resolve() {
int amount = calculateAmount(af.getHostCard(), params.get("LifeAmount"), this);
loseLifeResolve(af, this, amount);
}
@Override
public boolean chkAI_Drawback() {
return true;
}
};
return dbLoseLife;
} }
@@ -248,6 +264,30 @@ public class AbilityFactory_AlterLife {
return sb.toString(); return sb.toString();
} }
static String loseLifeStackDescription(AbilityFactory af, SpellAbility sa){
StringBuilder sb = new StringBuilder();
int amount = calculateAmount(af.getHostCard(), af.getMapParams().get("LifeAmount"), sa);
Player player = sa.getActivatingPlayer().getOpponent();
if (!(sa instanceof Ability_Sub))
sb.append(sa.getSourceCard().getName()).append(" - ");
else
sb.append(" ");
if (af.getAbTgt() != null)
player = sa.getTargetPlayer();
sb.append(player).append(" loses ").append(amount).append(" life.");
Ability_Sub abSub = sa.getSubAbility();
if (abSub != null) {
abSub.setParent(sa);
sb.append(abSub.getStackDescription());
}
return sb.toString();
}
public static boolean gainLifeCanPlayAI(final AbilityFactory af, final SpellAbility sa, final String amountStr){ public static boolean gainLifeCanPlayAI(final AbilityFactory af, final SpellAbility sa, final String amountStr){
Random r = new Random(); Random r = new Random();
Ability_Cost abCost = sa.getPayCosts(); Ability_Cost abCost = sa.getPayCosts();
@@ -375,7 +415,6 @@ public class AbilityFactory_AlterLife {
public static void loseLifeResolve(final AbilityFactory af, final SpellAbility sa, int lifeAmount){ public static void loseLifeResolve(final AbilityFactory af, final SpellAbility sa, int lifeAmount){
HashMap<String,String> params = af.getMapParams(); HashMap<String,String> params = af.getMapParams();
String DrawBack = params.get("SubAbility");
Card card = af.getHostCard(); Card card = af.getHostCard();
ArrayList<Player> tgtPlayers; ArrayList<Player> tgtPlayers;
@@ -392,7 +431,18 @@ public class AbilityFactory_AlterLife {
if (tgt == null || p.canTarget(af.getHostCard())) if (tgt == null || p.canTarget(af.getHostCard()))
p.loseLife(lifeAmount, sa.getSourceCard()); p.loseLife(lifeAmount, sa.getSourceCard());
if (af.hasSubAbility()){
Ability_Sub abSub = sa.getSubAbility();
if (abSub != null){
if (abSub.getParent() == null)
abSub.setParent(sa);
abSub.resolve();
}
else{
String DrawBack = params.get("SubAbility");
if (af.hasSubAbility()) if (af.hasSubAbility())
CardFactoryUtil.doDrawBack(DrawBack, lifeAmount, card.getController(), card.getController().getOpponent(), tgtPlayers.get(0), card, null, sa); CardFactoryUtil.doDrawBack(DrawBack, lifeAmount, card.getController(), card.getController().getOpponent(), tgtPlayers.get(0), card, null, sa);
} }
}
}
} }