String baseKey=E.match.getPlayerBaseKey(E.player);
String cardKey = baseKey + "CARD_VECTOR";
Vector cardsPlayed = (Vector) E.aiPlayer.getObjectData(cardKey);
if (cardsPlayed == null) cardsPlayed = new Vector();
CardList cardsPlayedList = new CardList();
for (int t = 0; t <cardsPlayed.size(); t++)
{
Card cc = (Card) cardsPlayed.elementAt(t);
cardsPlayedList.addCard(cc);
}
//#import "scripts\Allround\AIHelperScript.java"
AIHelper.checkMoodChange(E.match, E.player);
// bRet indicates Phase done - if not set to true at some stage
// computer will sit in an endless loop and
// repeatedly load and run Script!
String landKey="TMP_KEY_"+E.match.getRound()+"landPlayed";
E.D.addLog("EAI: Computer entered main script.",debugLevel);
CombatFormation sorceryAction = (CombatFormation) E.aiPlayer.getObjectData(baseKey+"SORCERY_COMBO");
E.D.addLog("EAI: Enter Main: sorceryAction: "+sorceryAction,debugLevel);
E.aiPlayer.removeObjectData(baseKey+"SORCERY_TARGET");
if (sorceryAction != null)
{
E.D.addLog("EAI: Continue sorcery combo",debugLevel);
Card spell = handleSorcery(sorceryAction, baseKey);
E.D.addLog("EAI: Spell: "+spell, debugLevel);
if (spell != null ) //?
{
return playCard(spell,cardsPlayed, cardKey, E.aiPlayer);
}
else
{
return true;
}
}
// try playing a land - if available
if( (E.match.getPhase() == Match.PHASE_MAIN1) || (E.match.getPhase() == Match.PHASE_MAIN2))
{
E.D.addLog("EAI: Entering Main",debugLevel);
// first thing we do
boolean landPlayed = E.aiPlayer.getBoolData(landKey);
E.D.addLog("EAI: (Boolean) landPlayed = "+landPlayed,debugLevel);
if (!landPlayed)
{
E.D.addLog("EAI: Entering land not played yet",debugLevel);
// to show we "tried" playing a land, not that we actually played one
E.aiPlayer.setBoolData(landKey, true);
CardList hand = E.match.getHand(E.player);
hand = hand.removeList(cardsPlayedList);
CardList handLands = hand.getSubListByType("Land");
E.D.addLog("EAI: Lands in hand: " +handLands.size(),debugLevel);
if (handLands.size()>0)
{
int intelligence = E.aiPlayer.mStrategie.getIntelligence();
int landPlayMood = E.match.getLand(E.player).size()-2+(intelligence/2);
if (landPlayMood>10)
{
int prob = 12 - (landPlayMood);
if (prob < 0) prob = 0;
int randy = csa.Global.getRand().nextInt(10);
E.D.addLog("EAI: Check landplay: randy = "+randy+" prob = "+prob,debugLevel);
if (randy>=prob )
{
boolean skip = false;
// todo check if enough lands of EVERY usefull color are present (2? at least?)
int manaBlack = E.match.getLand(E.player).getSubListBySubType("Swamp").size();
int manaRed = E.match.getLand(E.player).getSubListBySubType("Mountain").size();
int manaWhite = E.match.getLand(E.player).getSubListBySubType("Plains").size();
int manaBlue = E.match.getLand(E.player).getSubListBySubType("Island").size();
int manaGreen = E.match.getLand(E.player).getSubListBySubType("Forest").size();
if ((manaBlack < 3) && (handLands.getSubListBySubType("Swamp").size()>0) ) skip = true;
if ((manaRed < 3) && (handLands.getSubListBySubType("Mountain").size()>0) ) skip = true;
if ((manaWhite < 3) && (handLands.getSubListBySubType("Plains").size()>0) ) skip = true;
if ((manaBlue < 3) && (handLands.getSubListBySubType("Island").size()>0) ) skip = true;
if ((manaGreen < 3) && (handLands.getSubListBySubType("Forest").size()>0) ) skip = true;
if (AIHelper.enoughLands(E.match.getLand(E.player).size(), hand ))
if (!skip)
landPlayed=true;
}
}
if (!landPlayed)
{
// simple AI - play first land!
String color = AIHelper.getColorOfLessFrequence(E.match.getLand(E.player), handLands);
CardList handlands = handLands.getSubListByColor(color);
Card aLand;
if (handlands.size() > 0)
aLand = handlands.getCard(0);
else
aLand = handLands.getCard(csa.Global.getRand().nextInt(handLands.size()));
return playCard(aLand,cardsPlayed, cardKey, E.aiPlayer);
}
else
{
E.D.addLog("EAI: Lands saved! " +handLands.size(),debugLevel);
}
}
// indicate we are finished for now and
// that we want to be called again, when land was playout out by E.match
// which is done after we "returned
}
else
{
E.D.addLog("EAI: Entering land played already",debugLevel);
}
// here
E.D.addLog("EAI: Checking what to play in Main",debugLevel);
// try playing a creature
// if that means communication - I don´t know what will happen
// lets come to us one at a time...
CardList lands = E.match.getLand(E.player);
CardList hand = E.match.getHand(E.player);
hand = hand.removeList(cardsPlayedList);
CardList creatureHand = hand.getSubListByType("Creature");
CardList sorceriesHand = hand.getSubListByType("Sorcery");
CardList possibleCreatures = AIHelper.onlyEnoughMana(creatureHand, lands);
CardList possibleSorceries = AIHelper.onlyEnoughMana(sorceriesHand, lands);
CardList goodSorceries = new CardList();
CardList goodCreatures = new CardList();
for (int i=0; i < possibleSorceries.size();i++)
{
Card card = possibleSorceries.getCard(i);
if (AIHelper.sorceryHintMakesSenseNow(E.player, E.match, card))
{
goodSorceries.addCard(card);
}
}
for (int i=0; i < possibleCreatures.size();i++)
{
Card card = possibleCreatures.getCard(i);
if (AIHelper.sorceryHintMakesSenseNow(E.player, E.match, card))
{
goodCreatures.addCard(card);
}
}
if(E.match.getPhase() == Match.PHASE_MAIN2)
E.aiPlayer.removeObjectData(E.match.getPlayerBaseKey(E.player, false)+"ATTACKER_CHECK");
// no buffs in second phase - what good should they be after attacking is done?
CardList newGood = new CardList();
if (E.match.getPhase() == Match.PHASE_MAIN2)
{
for (int i=0; i < goodSorceries.size();i++)
{
Card card = goodSorceries.getCard(i);
if (!AIHelper.isBufCard(card))
{
newGood.addCard(card);
}
}
goodSorceries = newGood;
}
// these are cards for land/ color needs which are not in any deck right now
goodSorceries = goodSorceries.removeList(AIHelper.getUnUseableHandCard(goodSorceries,Match.match, E.player));
goodSorceries = AIHelper.adjustListWithCardNeeds(goodSorceries, true, "MAIN", E.match, E.player);
goodCreatures = AIHelper.adjustListWithCardNeeds(goodCreatures, true, "MAIN", E.match, E.player);
goodSorceries.sortListByManaCost();
E.D.addLog("EAI: Good sorceries: "+ goodSorceries,1);
possibleCreatures.sortListByManaCost();
E.D.addLog("EAI: Good creatures: "+ goodCreatures,1);
// CardList opponentCreatures = E.match.getBattlefieldOpponent(E.player);
// CardList myCreatures = E.match.getBattlefield(E.player);
CardList joinList = new CardList();
joinList.addList(goodSorceries);
joinList.addList(goodCreatures);
AIHelper.sorceryAction = null;
AIHelper.isCastSeeking = true;
Card selectedCard = AIHelper.selectGoodCard(joinList, true, null, true, false, E.match, E.player);