mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 04:38:00 +00:00
no changes, just fixing some very odd indentation in Eclipse.
This commit is contained in:
@@ -1,23 +1,23 @@
|
||||
|
||||
package forge;
|
||||
package forge;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
|
||||
public class AbilityFactory_DealDamage {
|
||||
private AbilityFactory AF = null;
|
||||
public class AbilityFactory_DealDamage {
|
||||
private AbilityFactory AF = null;
|
||||
|
||||
private String damage;
|
||||
private String damage;
|
||||
|
||||
public AbilityFactory_DealDamage(AbilityFactory newAF)
|
||||
{
|
||||
AF = newAF;
|
||||
public AbilityFactory_DealDamage(AbilityFactory newAF)
|
||||
{
|
||||
AF = newAF;
|
||||
|
||||
damage = AF.getMapParams().get("NumDmg");
|
||||
damage = AF.getMapParams().get("NumDmg");
|
||||
|
||||
// Note: TgtOpp should not be used, Please use ValidTgts$ Opponent instead
|
||||
}
|
||||
// Note: TgtOpp should not be used, Please use ValidTgts$ Opponent instead
|
||||
}
|
||||
|
||||
public SpellAbility getAbility() {
|
||||
final SpellAbility abDamage = new Ability_Activated(AF.getHostCard(), AF.getAbCost(), AF.getAbTgt()) {
|
||||
@@ -195,105 +195,105 @@ import java.util.Random;
|
||||
return dbDamageAll;
|
||||
}
|
||||
|
||||
private int getNumDamage(SpellAbility saMe) {
|
||||
return AbilityFactory.calculateAmount(saMe.getSourceCard(), damage, saMe);
|
||||
}
|
||||
private int getNumDamage(SpellAbility saMe) {
|
||||
return AbilityFactory.calculateAmount(saMe.getSourceCard(), damage, saMe);
|
||||
}
|
||||
|
||||
private boolean shouldTgtP(int d, final boolean noPrevention) {
|
||||
int restDamage = d;
|
||||
private boolean shouldTgtP(int d, final boolean noPrevention) {
|
||||
int restDamage = d;
|
||||
|
||||
if (!noPrevention)
|
||||
restDamage = AllZone.HumanPlayer.staticDamagePrevention(restDamage, AF.getHostCard(), false);
|
||||
if (!noPrevention)
|
||||
restDamage = AllZone.HumanPlayer.staticDamagePrevention(restDamage, AF.getHostCard(), false);
|
||||
|
||||
if (restDamage == 0) return false;
|
||||
if (restDamage == 0) return false;
|
||||
|
||||
PlayerZone compHand = AllZone.getZone(Constant.Zone.Hand, AllZone.ComputerPlayer);
|
||||
CardList hand = new CardList(compHand.getCards());
|
||||
PlayerZone compHand = AllZone.getZone(Constant.Zone.Hand, AllZone.ComputerPlayer);
|
||||
CardList hand = new CardList(compHand.getCards());
|
||||
|
||||
if(AF.isSpell() && hand.size() > 7) // anti-discard-at-EOT
|
||||
return true;
|
||||
if(AF.isSpell() && hand.size() > 7) // anti-discard-at-EOT
|
||||
return true;
|
||||
|
||||
if(AllZone.HumanPlayer.getLife() - restDamage < 10) // if damage from this spell would drop the human to less than 10 life
|
||||
return true;
|
||||
if(AllZone.HumanPlayer.getLife() - restDamage < 10) // if damage from this spell would drop the human to less than 10 life
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private Card chooseTgtC(final int d, final boolean noPrevention) {
|
||||
CardList hPlay = AllZoneUtil.getPlayerCardsInPlay(AllZone.HumanPlayer);
|
||||
hPlay = hPlay.getValidCards(AF.getAbTgt().getValidTgts(), AllZone.ComputerPlayer, AF.getHostCard());
|
||||
private Card chooseTgtC(final int d, final boolean noPrevention) {
|
||||
CardList hPlay = AllZoneUtil.getPlayerCardsInPlay(AllZone.HumanPlayer);
|
||||
hPlay = hPlay.getValidCards(AF.getAbTgt().getValidTgts(), AllZone.ComputerPlayer, AF.getHostCard());
|
||||
|
||||
hPlay = hPlay.filter(new CardListFilter() {
|
||||
public boolean addCard(Card c) {
|
||||
int restDamage = d;
|
||||
if (!noPrevention)
|
||||
restDamage = c.staticDamagePrevention(d,AF.getHostCard(),false);
|
||||
// will include creatures already dealt damage
|
||||
return c.getKillDamage() <= restDamage && CardFactoryUtil.canTarget(AF.getHostCard(), c)
|
||||
&& !c.getKeyword().contains("Indestructible") && !(c.getSVar("SacMe").length() > 0);
|
||||
}
|
||||
});
|
||||
hPlay = hPlay.filter(new CardListFilter() {
|
||||
public boolean addCard(Card c) {
|
||||
int restDamage = d;
|
||||
if (!noPrevention)
|
||||
restDamage = c.staticDamagePrevention(d,AF.getHostCard(),false);
|
||||
// will include creatures already dealt damage
|
||||
return c.getKillDamage() <= restDamage && CardFactoryUtil.canTarget(AF.getHostCard(), c)
|
||||
&& !c.getKeyword().contains("Indestructible") && !(c.getSVar("SacMe").length() > 0);
|
||||
}
|
||||
});
|
||||
|
||||
if(hPlay.size() > 0) {
|
||||
Card best = CardFactoryUtil.AI_getBestCreature(hPlay);
|
||||
return best;
|
||||
}
|
||||
if(hPlay.size() > 0) {
|
||||
Card best = CardFactoryUtil.AI_getBestCreature(hPlay);
|
||||
return best;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean doCanPlayAI(SpellAbility saMe)
|
||||
{
|
||||
int dmg = getNumDamage(saMe);
|
||||
boolean rr = AF.isSpell();
|
||||
private boolean doCanPlayAI(SpellAbility saMe)
|
||||
{
|
||||
int dmg = getNumDamage(saMe);
|
||||
boolean rr = AF.isSpell();
|
||||
|
||||
// temporarily disabled until better AI
|
||||
if (AF.getAbCost().getSacCost()) {
|
||||
if(AllZone.HumanPlayer.getLife() - dmg > 0) // only if damage from this ability would kill the human
|
||||
return false;
|
||||
}
|
||||
if (AF.getAbCost().getSubCounter()) {
|
||||
// +1/+1 counters only if damage from this ability would kill the human, otherwise ok
|
||||
if(AllZone.HumanPlayer.getLife() - dmg > 0 && AF.getAbCost().getCounterType().equals(Counters.P1P1))
|
||||
return false;
|
||||
}
|
||||
if (AF.getAbCost().getLifeCost()) {
|
||||
if(AllZone.HumanPlayer.getLife() - dmg > 0) // only if damage from this ability would kill the human
|
||||
return false;
|
||||
}
|
||||
// temporarily disabled until better AI
|
||||
if (AF.getAbCost().getSacCost()) {
|
||||
if(AllZone.HumanPlayer.getLife() - dmg > 0) // only if damage from this ability would kill the human
|
||||
return false;
|
||||
}
|
||||
if (AF.getAbCost().getSubCounter()) {
|
||||
// +1/+1 counters only if damage from this ability would kill the human, otherwise ok
|
||||
if(AllZone.HumanPlayer.getLife() - dmg > 0 && AF.getAbCost().getCounterType().equals(Counters.P1P1))
|
||||
return false;
|
||||
}
|
||||
if (AF.getAbCost().getLifeCost()) {
|
||||
if(AllZone.HumanPlayer.getLife() - dmg > 0) // only if damage from this ability would kill the human
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ComputerUtil.canPayCost(saMe))
|
||||
return false;
|
||||
if (!ComputerUtil.canPayCost(saMe))
|
||||
return false;
|
||||
|
||||
// TODO handle proper calculation of X values based on Cost
|
||||
// TODO handle proper calculation of X values based on Cost
|
||||
|
||||
// todo: this should only happen during Players EOT or if Stuffy is going to die
|
||||
if(AF.getHostCard().equals("Stuffy Doll")) {
|
||||
return true;
|
||||
}
|
||||
// todo: this should only happen during Players EOT or if Stuffy is going to die
|
||||
if(AF.getHostCard().equals("Stuffy Doll")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (AF.isAbility())
|
||||
{
|
||||
Random r = new Random(); // prevent run-away activations
|
||||
if(r.nextFloat() <= Math.pow(.6667, AF.getHostCard().getAbilityUsed()))
|
||||
rr = true;
|
||||
}
|
||||
if (AF.isAbility())
|
||||
{
|
||||
Random r = new Random(); // prevent run-away activations
|
||||
if(r.nextFloat() <= Math.pow(.6667, AF.getHostCard().getAbilityUsed()))
|
||||
rr = true;
|
||||
}
|
||||
|
||||
boolean bFlag = damageTargetAI(saMe);
|
||||
if (!bFlag)
|
||||
return false;
|
||||
boolean bFlag = damageTargetAI(saMe);
|
||||
if (!bFlag)
|
||||
return false;
|
||||
|
||||
Ability_Sub subAb = saMe.getSubAbility();
|
||||
if (subAb != null)
|
||||
rr &= subAb.chkAI_Drawback();
|
||||
return rr;
|
||||
Ability_Sub subAb = saMe.getSubAbility();
|
||||
if (subAb != null)
|
||||
rr &= subAb.chkAI_Drawback();
|
||||
return rr;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private boolean damageTargetAI(SpellAbility saMe) {
|
||||
int dmg = getNumDamage(saMe);
|
||||
Target tgt = AF.getAbTgt();
|
||||
HashMap<String,String> params = AF.getMapParams();
|
||||
HashMap<String,String> params = AF.getMapParams();
|
||||
|
||||
boolean noPrevention = params.containsKey("NoPrevention");
|
||||
|
||||
@@ -311,7 +311,7 @@ import java.util.Random;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -359,168 +359,168 @@ import java.util.Random;
|
||||
return true;
|
||||
}
|
||||
|
||||
private String damageStackDescription(AbilityFactory af, SpellAbility sa){
|
||||
// when damageStackDescription is called, just build exactly what is happening
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String name = af.getHostCard().toString();
|
||||
int dmg = getNumDamage(sa);
|
||||
private String damageStackDescription(AbilityFactory af, SpellAbility sa){
|
||||
// when damageStackDescription is called, just build exactly what is happening
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String name = af.getHostCard().toString();
|
||||
int dmg = getNumDamage(sa);
|
||||
|
||||
ArrayList<Object> tgts;
|
||||
if(sa.getTarget() == null)
|
||||
tgts = AbilityFactory.getDefinedObjects(sa.getSourceCard(), af.getMapParams().get("Defined"), sa);
|
||||
else
|
||||
tgts = sa.getTarget().getTargets();
|
||||
ArrayList<Object> tgts;
|
||||
if(sa.getTarget() == null)
|
||||
tgts = AbilityFactory.getDefinedObjects(sa.getSourceCard(), af.getMapParams().get("Defined"), sa);
|
||||
else
|
||||
tgts = sa.getTarget().getTargets();
|
||||
|
||||
if (!(sa instanceof Ability_Sub))
|
||||
sb.append(name).append(" - ");
|
||||
if (!(sa instanceof Ability_Sub))
|
||||
sb.append(name).append(" - ");
|
||||
|
||||
sb.append("Deals ").append(dmg).append(" damage to ");
|
||||
sb.append("Deals ").append(dmg).append(" damage to ");
|
||||
|
||||
for(int i = 0; i < tgts.size(); i++){
|
||||
if (i != 0)
|
||||
sb.append(" ");
|
||||
for(int i = 0; i < tgts.size(); i++){
|
||||
if (i != 0)
|
||||
sb.append(" ");
|
||||
|
||||
Object o = tgts.get(0);
|
||||
if (o instanceof Card || o instanceof Player)
|
||||
sb.append(o.toString());
|
||||
}
|
||||
Object o = tgts.get(0);
|
||||
if (o instanceof Card || o instanceof Player)
|
||||
sb.append(o.toString());
|
||||
}
|
||||
|
||||
sb.append(". ");
|
||||
sb.append(". ");
|
||||
|
||||
if (sa.getSubAbility() != null){
|
||||
sb.append(sa.getSubAbility().getStackDescription());
|
||||
}
|
||||
if (sa.getSubAbility() != null){
|
||||
sb.append(sa.getSubAbility().getStackDescription());
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private void doResolve(SpellAbility saMe)
|
||||
{
|
||||
int dmg = getNumDamage(saMe);
|
||||
HashMap<String,String> params = AF.getMapParams();
|
||||
private void doResolve(SpellAbility saMe)
|
||||
{
|
||||
int dmg = getNumDamage(saMe);
|
||||
HashMap<String,String> params = AF.getMapParams();
|
||||
|
||||
boolean noPrevention = params.containsKey("NoPrevention");
|
||||
boolean noPrevention = params.containsKey("NoPrevention");
|
||||
|
||||
ArrayList<Object> tgts;
|
||||
if(saMe.getTarget() == null)
|
||||
tgts = AbilityFactory.getDefinedObjects(saMe.getSourceCard(), params.get("Defined"), saMe);
|
||||
else
|
||||
tgts = saMe.getTarget().getTargets();
|
||||
ArrayList<Object> tgts;
|
||||
if(saMe.getTarget() == null)
|
||||
tgts = AbilityFactory.getDefinedObjects(saMe.getSourceCard(), params.get("Defined"), saMe);
|
||||
else
|
||||
tgts = saMe.getTarget().getTargets();
|
||||
|
||||
boolean targeted = (AF.getAbTgt() != null);
|
||||
boolean targeted = (AF.getAbTgt() != null);
|
||||
|
||||
for(Object o : tgts){
|
||||
if (o instanceof Card){
|
||||
Card c = (Card)o;
|
||||
if(AllZone.GameAction.isCardInPlay(c) && (!targeted || CardFactoryUtil.canTarget(AF.getHostCard(), c))) {
|
||||
if (noPrevention)
|
||||
c.addDamageWithoutPrevention(dmg, AF.getHostCard());
|
||||
else
|
||||
c.addDamage(dmg, AF.getHostCard());
|
||||
}
|
||||
for(Object o : tgts){
|
||||
if (o instanceof Card){
|
||||
Card c = (Card)o;
|
||||
if(AllZone.GameAction.isCardInPlay(c) && (!targeted || CardFactoryUtil.canTarget(AF.getHostCard(), c))) {
|
||||
if (noPrevention)
|
||||
c.addDamageWithoutPrevention(dmg, AF.getHostCard());
|
||||
else
|
||||
c.addDamage(dmg, AF.getHostCard());
|
||||
}
|
||||
|
||||
}
|
||||
else if (o instanceof Player){
|
||||
Player p = (Player) o;
|
||||
if (!targeted || p.canTarget(AF.getHostCard())) {
|
||||
if (noPrevention)
|
||||
p.addDamageWithoutPrevention(dmg, AF.getHostCard());
|
||||
else
|
||||
p.addDamage(dmg, AF.getHostCard());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (o instanceof Player){
|
||||
Player p = (Player) o;
|
||||
if (!targeted || p.canTarget(AF.getHostCard())) {
|
||||
if (noPrevention)
|
||||
p.addDamageWithoutPrevention(dmg, AF.getHostCard());
|
||||
else
|
||||
p.addDamage(dmg, AF.getHostCard());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (AF.hasSubAbility()){
|
||||
Ability_Sub abSub = saMe.getSubAbility();
|
||||
if (abSub != null){
|
||||
abSub.resolve();
|
||||
}
|
||||
else{
|
||||
Object obj = tgts.get(0);
|
||||
if (AF.hasSubAbility()){
|
||||
Ability_Sub abSub = saMe.getSubAbility();
|
||||
if (abSub != null){
|
||||
abSub.resolve();
|
||||
}
|
||||
else{
|
||||
Object obj = tgts.get(0);
|
||||
|
||||
Player pl = null;
|
||||
Card c = null;
|
||||
Player pl = null;
|
||||
Card c = null;
|
||||
|
||||
if (obj instanceof Card){
|
||||
c = (Card)obj;
|
||||
pl = c.getController();
|
||||
}
|
||||
else{
|
||||
pl = (Player)obj;
|
||||
}
|
||||
CardFactoryUtil.doDrawBack(params.get("SubAbility"), dmg, AF.getHostCard().getController(),
|
||||
AF.getHostCard().getController().getOpponent(), pl, AF.getHostCard(), c, saMe);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (obj instanceof Card){
|
||||
c = (Card)obj;
|
||||
pl = c.getController();
|
||||
}
|
||||
else{
|
||||
pl = (Player)obj;
|
||||
}
|
||||
CardFactoryUtil.doDrawBack(params.get("SubAbility"), dmg, AF.getHostCard().getController(),
|
||||
AF.getHostCard().getController().getOpponent(), pl, AF.getHostCard(), c, saMe);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void damageAllResolve(final AbilityFactory af, final SpellAbility sa){
|
||||
HashMap<String,String> params = af.getMapParams();
|
||||
String DrawBack = params.get("SubAbility");
|
||||
Card card = sa.getSourceCard();
|
||||
private void damageAllResolve(final AbilityFactory af, final SpellAbility sa){
|
||||
HashMap<String,String> params = af.getMapParams();
|
||||
String DrawBack = params.get("SubAbility");
|
||||
Card card = sa.getSourceCard();
|
||||
|
||||
int dmg = getNumDamage(sa);
|
||||
int dmg = getNumDamage(sa);
|
||||
|
||||
String valid = "";
|
||||
String players = "";
|
||||
String valid = "";
|
||||
String players = "";
|
||||
|
||||
if(params.containsKey("ValidCards"))
|
||||
valid = params.get("ValidCards");
|
||||
if(params.containsKey("ValidPlayers"))
|
||||
players = params.get("ValidPlayers");
|
||||
if(params.containsKey("ValidCards"))
|
||||
valid = params.get("ValidCards");
|
||||
if(params.containsKey("ValidPlayers"))
|
||||
players = params.get("ValidPlayers");
|
||||
|
||||
CardList list = AllZoneUtil.getCardsInPlay();
|
||||
list = list.getValidCards(valid.split(","), card.getController(), card);
|
||||
CardList list = AllZoneUtil.getCardsInPlay();
|
||||
list = list.getValidCards(valid.split(","), card.getController(), card);
|
||||
|
||||
for(Card c:list) c.addDamage(dmg, card);
|
||||
for(Card c:list) c.addDamage(dmg, card);
|
||||
|
||||
if(players.equals("All")) {
|
||||
for(Player p:AllZoneUtil.getPlayersInGame()) {
|
||||
p.addDamage(dmg, card);
|
||||
}
|
||||
}
|
||||
else if(players.equals("EachOpponent")) {
|
||||
for(Player p:AllZoneUtil.getOpponents(card.getController())) p.addDamage(dmg, card);
|
||||
}
|
||||
else if(players.equals("Self"))
|
||||
card.getController().addDamage(dmg, card);
|
||||
else {
|
||||
//anything else to go here?
|
||||
}
|
||||
if(players.equals("All")) {
|
||||
for(Player p:AllZoneUtil.getPlayersInGame()) {
|
||||
p.addDamage(dmg, card);
|
||||
}
|
||||
}
|
||||
else if(players.equals("EachOpponent")) {
|
||||
for(Player p:AllZoneUtil.getOpponents(card.getController())) p.addDamage(dmg, card);
|
||||
}
|
||||
else if(players.equals("Self"))
|
||||
card.getController().addDamage(dmg, card);
|
||||
else {
|
||||
//anything else to go here?
|
||||
}
|
||||
|
||||
if (af.hasSubAbility()){
|
||||
Ability_Sub abSub = sa.getSubAbility();
|
||||
if (abSub != null){
|
||||
abSub.resolve();
|
||||
}
|
||||
else
|
||||
CardFactoryUtil.doDrawBack(DrawBack, 0, card.getController(), card.getController().getOpponent(), card.getController(), card, null, sa);
|
||||
}
|
||||
}
|
||||
if (af.hasSubAbility()){
|
||||
Ability_Sub abSub = sa.getSubAbility();
|
||||
if (abSub != null){
|
||||
abSub.resolve();
|
||||
}
|
||||
else
|
||||
CardFactoryUtil.doDrawBack(DrawBack, 0, card.getController(), card.getController().getOpponent(), card.getController(), card, null, sa);
|
||||
}
|
||||
}
|
||||
|
||||
private String damageAllStackDescription(final AbilityFactory af, SpellAbility sa){
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String name = af.getHostCard().getName();
|
||||
HashMap<String,String> params = af.getMapParams();
|
||||
String desc = "";
|
||||
if(params.containsKey("ValidDescription"))
|
||||
desc = params.get("ValidDescription");
|
||||
int dmg = getNumDamage(sa);
|
||||
private String damageAllStackDescription(final AbilityFactory af, SpellAbility sa){
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String name = af.getHostCard().getName();
|
||||
HashMap<String,String> params = af.getMapParams();
|
||||
String desc = "";
|
||||
if(params.containsKey("ValidDescription"))
|
||||
desc = params.get("ValidDescription");
|
||||
int dmg = getNumDamage(sa);
|
||||
|
||||
sb.append(name).append(" - Deals "+dmg+" to "+desc);
|
||||
sb.append(name).append(" - Deals "+dmg+" to "+desc);
|
||||
|
||||
Ability_Sub abSub = sa.getSubAbility();
|
||||
if (abSub != null) {
|
||||
sb.append(abSub.getStackDescription());
|
||||
}
|
||||
Ability_Sub abSub = sa.getSubAbility();
|
||||
if (abSub != null) {
|
||||
sb.append(abSub.getStackDescription());
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private boolean damageAllCanPlayAI(final AbilityFactory af, final SpellAbility sa){
|
||||
return false;
|
||||
/*
|
||||
private boolean damageAllCanPlayAI(final AbilityFactory af, final SpellAbility sa){
|
||||
return false;
|
||||
/*
|
||||
// AI needs to be expanded, since this function can be pretty complex based on what the expected targets could be
|
||||
Random r = new Random();
|
||||
Ability_Cost abCost = sa.getPayCosts();
|
||||
@@ -575,6 +575,6 @@ import java.util.Random;
|
||||
chance &= subAb.chkAI_Drawback();
|
||||
|
||||
return ((r.nextFloat() < .6667) && chance);
|
||||
*/
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user