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