amount = mLand[(player+1)%2].size() - mLand[player].size();
count = amount;
}
}
if (hints.hasAnyHint(hintKey, new HintBundle(TY_SELF_DESTRUCT)))
{
creatureToGrave(source);
}
if (hints.hasAnyHint(hintKey, new HintBundle(TY_SELF_TO_HAND)))
{
mBattlefield[player].moveCardTo(source, mHand[player]);
removeFromAttack(source);
removeFromBlock(source);
}
// stack cards!
if ( (hints.hasAnyHint(hintKey, new HintBundle(TY_NEGATE_STACK_CARD)))
|| (hints.hasAnyHint(hintKey, new HintBundle(TY_NEGATE_STACK_ABILITY)))
|| (hints.hasAnyHint(hintKey, new HintBundle(TY_NEGATE_STACK_PLAYER_DAMAGE)))
)
{
// no checking done here!
// we negate the last card on stack
if (mStack.size()>=2)
{
EAIAction removed = mStack.elementAt(mStack.size()-2);
CardSim rCard = removed.getSCard();
int owner = rCard.owner;
if (removed.type == EAIAction.ACTION_PLAY_CARD)
{
mHand[owner].remove(rCard);
mGraveyard[owner].remove(rCard);
mLibrary[owner].remove(rCard);
mGraveyard[owner].addCard(rCard);
}
mStack.removeElementAt(mStack.size()-2);
}
}
boolean sicken = false;
if (hints.hasHint(hintKey, HintTargetRestrictions.TR_CARD_PLAYER))
{
CardSimList from = null;
CardSimList to = null;
player = source.owner;
if (hints.hasAnyHint(hintKey, new HintBundle(TY_HAND_TO_GRAVE, TY_HAND_TO_LAND, TY_HAND_TO_FIELD, TY_HAND_TO_LIBRARY, TY_HAND_TO_EXILE)))
from = mHand[player];
if (hints.hasAnyHint(hintKey, new HintBundle(TY_LAND_TO_GRAVE, TY_LAND_TO_HAND, TY_LAND_TO_LIBRARY, TY_LAND_TO_EXILE)))
from = mLand[player];
if (hints.hasAnyHint(hintKey, new HintBundle(TY_LIBRARY_TO_GRAVE, TY_LIBRARY_TO_HAND, TY_LIBRARY_TO_LAND, TY_LIBRARY_TO_FIELD, TY_LIBRARY_TO_EXILE, TY_LIBRARY_TO_LIBRARY)))
{
if ((!libShuffled)&&(hints.hasAnyHint(hintKey, new HintBundle(TY_OPENS_PLAYER_LIBRARY))))
{
initLibrary();
}
from = mLibrary[player];
}
if (hints.hasAnyHint(hintKey, new HintBundle(TY_FIELD_TO_GRAVE, TY_FIELD_TO_HAND, TY_FIELD_TO_LIBRARY, TY_FIELD_TO_EXILE)))
from = mBattlefield[player];
if (hints.hasAnyHint(hintKey, new HintBundle(TY_GRAVE_TO_HAND, TY_GRAVE_TO_FIELD, TY_GRAVE_TO_LAND, TY_GRAVE_TO_LIBRARY, TY_GRAVE_TO_EXILE)))
from = mGraveyard[player];
if (hints.hasAnyHint(hintKey, new HintBundle(TY_HAND_TO_GRAVE, TY_LAND_TO_GRAVE, TY_LIBRARY_TO_GRAVE, TY_FIELD_TO_GRAVE)))
{
to = mGraveyard[player];
}
if (hints.hasAnyHint(hintKey, new HintBundle(TY_HAND_TO_LIBRARY, TY_LAND_TO_LIBRARY, TY_GRAVE_TO_LIBRARY, TY_FIELD_TO_LIBRARY, TY_LIBRARY_TO_LIBRARY)))
to = mLibrary[player];
if (hints.hasAnyHint(hintKey, new HintBundle(TY_HAND_TO_FIELD, TY_GRAVE_TO_FIELD, TY_LIBRARY_TO_FIELD)))
{
to = mBattlefield[player];
sicken = true;
}
if (hints.hasAnyHint(hintKey, new HintBundle(TY_FIELD_TO_HAND, TY_GRAVE_TO_HAND, TY_LAND_TO_HAND, TY_LIBRARY_TO_HAND)))
to = mHand[player];
if (hints.hasAnyHint(hintKey, new HintBundle(TY_GRAVE_TO_LAND, TY_LIBRARY_TO_LAND, TY_HAND_TO_LAND)))
to = mLand[player];
if (hints.hasAnyHint(hintKey, new HintBundle(TY_HAND_TO_EXILE, TY_LAND_TO_EXILE, TY_FIELD_TO_EXILE, TY_GRAVE_TO_EXILE, TY_LIBRARY_TO_EXILE)))
to = mGraveyard[player];
if (hints.hasAnyHint(hintKey, new HintBundle(TY_LIBRARY_TOP)))
to = mLibrary[player];
if (hints.hasAnyHint(hintKey, new HintBundle(TY_LIBRARY_BOTTOM)))
to = mLibrary[player];
CardSimList fromOrg = from;
if (from != null)
from = fromOrg.copyList();
if ((from != null) && (to != null))
{
if (hints.hasAnyHint(hintKey, new HintBundle(TR_CHOICE_LIMITATION)))
{
int limit = hints.getHintValueInt(hintKey, TR_CHOICE_LIMITATION);
from = from.onlyTop(limit);
}
if (hints.hasAnyHint(hintKey, new HintBundle(TR_CARD_SELF_NOT_ALLOWED)))
{
from.remove(source);
}
String type_mustBeOneOf = hints.getHintValue(hintKey, TR_CARD_TYPE_NEED);
if (type_mustBeOneOf.length() != 0)
{
from = from.onlyWithTypes(type_mustBeOneOf);
}
String subtype_mustBeOneOf = hints.getHintValue(hintKey, TR_CARD_SUBTYPE_NEED);
if (subtype_mustBeOneOf.length() != 0)
{
from = from.onlyWithSubtypes(subtype_mustBeOneOf);
}
String color_mustBeOneOf = hints.getHintValue(hintKey, TR_CARD_COLOR_NEED);
if (color_mustBeOneOf.length() != 0)
{
from = from.onlyWithColors(color_mustBeOneOf);
}
String ability_mustBeOneOf = hints.getHintValue(hintKey, TR_CARD_ABILITY_NEED);
if (ability_mustBeOneOf.length() != 0)
from = from.onlyWithAbility(ability_mustBeOneOf);
String type_mustNotBeOneOf = hints.getHintValue(hintKey, TR_CARD_TYPE_RESTRICTION);
if (type_mustNotBeOneOf.length() != 0)
from = from.removeTypes(type_mustNotBeOneOf);
String subtype_mustNotBeOneOf = hints.getHintValue(hintKey, TR_CARD_SUBTYPE_RESTRICTION);
if (subtype_mustNotBeOneOf.length() != 0)
from = from.removeSubtypes(subtype_mustNotBeOneOf);
String color_mustNotBeOneOf = hints.getHintValue(hintKey, TR_CARD_COLOR_RESTRICTION);
if (color_mustNotBeOneOf.length() != 0)
from = from.removeColors(color_mustNotBeOneOf);
String ability_mustNotBeOneOf = hints.getHintValue(hintKey, TR_CARD_ABILITY_RESTRICTION);
if (ability_mustNotBeOneOf.length() != 0)
from = from.removeWithAbility(ability_mustNotBeOneOf);
boolean tapped_mustNotBe = hints.hasAnyHint(hintKey, new HintBundle(TR_CARD_UNTAPPED_NEED));
if (tapped_mustNotBe)
from = from.removeTapped();
boolean tapped_mustBe = hints.hasAnyHint(hintKey, new HintBundle(TR_CARD_TAPPED_NEED));
if (tapped_mustBe)
from = from.removeUnTapped();
boolean bpowerMin = hints.hasAnyHint(hintKey, new HintBundle(TR_CARD_POWER_MIN));
int ipowerMin = hints.getHintValueInt(hintKey, TR_CARD_POWER_MIN);
boolean bpowerMax = hints.hasAnyHint(hintKey, new HintBundle(TR_CARD_POWER_MAX));
int ipowerMax = hints.getHintValueInt(hintKey, TR_CARD_POWER_MAX);
boolean bfromughMin = hints.hasAnyHint(hintKey, new HintBundle(TR_CARD_TOUGHNESS_MIN));
int ifromughMin = hints.getHintValueInt(hintKey, TR_CARD_TOUGHNESS_MIN);
boolean bfromughMax = hints.hasAnyHint(hintKey, new HintBundle(TR_CARD_TOUGHNESS_MAX));
int ifromughMax = hints.getHintValueInt(hintKey, TR_CARD_TOUGHNESS_MAX);
if (bpowerMin)
{
from = from.onlyWithTypes("Creature");
from = from.onlyPowerHigher(ipowerMin-1);
}
if (bpowerMax)
{
from = from.onlyWithTypes("Creature");
from = from.onlyPowerLower(ipowerMax+1);
}
if (bfromughMin)
{
from = from.onlyWithTypes("Creature");
from = from.onlyToughnessHigher(ifromughMin-1);
}
if (bfromughMax)
{
from = from.onlyWithTypes("Creature");
from = from.onlyToughnessLower(ifromughMax+1);
}
for (int i=0; i< count; i++)
{
if (from.size() > 0)
{
CardSim tCard = from.getCard(from.size()-1);
if (from.isDummy())
tCard.owner = player;
if ((to == mGraveyard[player]) && (fromOrg == mBattlefield[player]))
{
creatureToGrave(tCard);
}
else
{
boolean done = false;
if (hints.hasAnyHint(hintKey, new HintBundle(TY_LIBRARY_BOTTOM)))
{
if (to == mLibrary[player])
{
done = true;
from.remove(tCard);
fromOrg.remove(tCard);
to.addCardFront(tCard);
}
}
if (!done)
{
if (tCard.isDummy())
{
fromOrg.remove(tCard);
to.addCard(tCard);
}
else
fromOrg.moveCardTo(tCard, to);
from.remove(tCard);
}
if (to == mGraveyard[player])
checkTriggerMoveToGrave(tCard);
removeFromAttack(tCard);
removeFromBlock(tCard);
}
if (sicken)
{
tCard.setSick(true);
}
}
}
if (hints.hasAnyHint(hintKey, new HintBundle(TY_LIBRARY_TOP)))
{
int p = player;
if(hints.hasAnyHint(hintKey, new HintBundle(HintAll.TY_LIBRARY_SHUFFLE)))
{
CardSim newCard = mLibrary[p].getCard(mLibrary[p].size()-1);
int size = mLibrary[p].size()-1;
mLibrary[p] = new CardSimList();
for (int i=0; i< size; i++)
{
mLibrary[p].addCard(Card.buildDummy(), p);
}
mLibrary[p].addCard(newCard);
}
}
else
{
int p = player;
if(hints.hasAnyHint(hintKey, new HintBundle(HintAll.TY_LIBRARY_SHUFFLE)))
{
mLibrary[p].shuffle();
}
}
}
}
if (hints.hasHint(hintKey, HintTargetRestrictions.TR_CARD_OPPONENT))
{
CardSimList from = null;
CardSimList to = null;
int tPlayer = (source.owner+1)%2;
if (hints.hasAnyHint(hintKey, new HintBundle(TY_HAND_TO_GRAVE, TY_HAND_TO_LAND, TY_HAND_TO_FIELD, TY_HAND_TO_LIBRARY, TY_HAND_TO_EXILE)))
from = mHand[tPlayer];
if (hints.hasAnyHint(hintKey, new HintBundle(TY_LAND_TO_GRAVE, TY_LAND_TO_HAND, TY_LAND_TO_LIBRARY, TY_LAND_TO_EXILE)))
from = mLand[tPlayer];
if (hints.hasAnyHint(hintKey, new HintBundle(TY_LIBRARY_TO_GRAVE, TY_LIBRARY_TO_HAND, TY_LIBRARY_TO_LAND, TY_LIBRARY_TO_FIELD, TY_LIBRARY_TO_EXILE, TY_LIBRARY_TO_LIBRARY)))
{
if ((!libShuffled)&&(hints.hasAnyHint(hintKey, new HintBundle(TY_OPENS_PLAYER_LIBRARY))))
{
initLibrary();
}
from = mLibrary[tPlayer];
}
if (hints.hasAnyHint(hintKey, new HintBundle(TY_FIELD_TO_GRAVE, TY_FIELD_TO_HAND, TY_FIELD_TO_LIBRARY, TY_FIELD_TO_EXILE)))
from = mBattlefield[tPlayer];
if (hints.hasAnyHint(hintKey, new HintBundle(TY_GRAVE_TO_HAND, TY_GRAVE_TO_FIELD, TY_GRAVE_TO_LAND, TY_GRAVE_TO_LIBRARY, TY_GRAVE_TO_EXILE)))
from = mGraveyard[tPlayer];
if (hints.hasAnyHint(hintKey, new HintBundle(TY_HAND_TO_GRAVE, TY_LAND_TO_GRAVE, TY_LIBRARY_TO_GRAVE, TY_FIELD_TO_GRAVE)))
to = mGraveyard[tPlayer];
if (hints.hasAnyHint(hintKey, new HintBundle(TY_HAND_TO_LIBRARY, TY_LAND_TO_LIBRARY, TY_GRAVE_TO_LIBRARY, TY_FIELD_TO_LIBRARY, TY_LIBRARY_TO_LIBRARY)))
to = mLibrary[tPlayer];
if (hints.hasAnyHint(hintKey, new HintBundle(TY_HAND_TO_FIELD, TY_GRAVE_TO_FIELD, TY_LIBRARY_TO_FIELD)))
{
sicken = true;
to = mBattlefield[tPlayer];
}
if (hints.hasAnyHint(hintKey, new HintBundle(TY_FIELD_TO_HAND, TY_GRAVE_TO_HAND, TY_LAND_TO_HAND, TY_LIBRARY_TO_HAND)))
to = mHand[tPlayer];
if (hints.hasAnyHint(hintKey, new HintBundle(TY_GRAVE_TO_LAND, TY_LIBRARY_TO_LAND, TY_HAND_TO_LAND)))
to = mLand[tPlayer];
if (hints.hasAnyHint(hintKey, new HintBundle(TY_HAND_TO_EXILE, TY_LAND_TO_EXILE, TY_FIELD_TO_EXILE, TY_GRAVE_TO_EXILE, TY_LIBRARY_TO_EXILE)))
to = mGraveyard[tPlayer];
if (hints.hasAnyHint(hintKey, new HintBundle(TY_LIBRARY_TOP)))
to = mLibrary[tPlayer];
if (hints.hasAnyHint(hintKey, new HintBundle(TY_LIBRARY_BOTTOM)))
to = mLibrary[tPlayer];
CardSimList fromOrg = from;
if (fromOrg != null)
from = fromOrg.copyList();
if ((from != null) && (to != null))
{
if (hints.hasAnyHint(hintKey, new HintBundle(TR_CHOICE_LIMITATION)))
{
int limit = hints.getHintValueInt(hintKey, TR_CHOICE_LIMITATION);
from = from.onlyTop(limit);
}
if (hints.hasAnyHint(hintKey, new HintBundle(TR_CARD_SELF_NOT_ALLOWED)))
{
from.remove(source);
}
String type_mustBeOneOf = hints.getHintValue(hintKey, TR_CARD_TYPE_NEED);
if (type_mustBeOneOf.length() != 0)
{
from = from.onlyWithTypes(type_mustBeOneOf);
}
String subtype_mustBeOneOf = hints.getHintValue(hintKey, TR_CARD_SUBTYPE_NEED);
if (subtype_mustBeOneOf.length() != 0)
{
from = from.onlyWithSubtypes(subtype_mustBeOneOf);
}
String color_mustBeOneOf = hints.getHintValue(hintKey, TR_CARD_COLOR_NEED);
if (color_mustBeOneOf.length() != 0)
{
from = from.onlyWithColors(color_mustBeOneOf);
}
String ability_mustBeOneOf = hints.getHintValue(hintKey, TR_CARD_ABILITY_NEED);
if (ability_mustBeOneOf.length() != 0)
from = from.onlyWithAbility(ability_mustBeOneOf);
String type_mustNotBeOneOf = hints.getHintValue(hintKey, TR_CARD_TYPE_RESTRICTION);
if (type_mustNotBeOneOf.length() != 0)
from = from.removeTypes(type_mustNotBeOneOf);
String subtype_mustNotBeOneOf = hints.getHintValue(hintKey, TR_CARD_SUBTYPE_RESTRICTION);
if (subtype_mustNotBeOneOf.length() != 0)
from = from.removeSubtypes(subtype_mustNotBeOneOf);
String color_mustNotBeOneOf = hints.getHintValue(hintKey, TR_CARD_COLOR_RESTRICTION);
if (color_mustNotBeOneOf.length() != 0)
from = from.removeColors(color_mustNotBeOneOf);
String ability_mustNotBeOneOf = hints.getHintValue(hintKey, TR_CARD_ABILITY_RESTRICTION);
if (ability_mustNotBeOneOf.length() != 0)
from = from.removeWithAbility(ability_mustNotBeOneOf);
boolean tapped_mustNotBe = hints.hasAnyHint(hintKey, new HintBundle(TR_CARD_UNTAPPED_NEED));
if (tapped_mustNotBe)
from = from.removeTapped();
boolean tapped_mustBe = hints.hasAnyHint(hintKey, new HintBundle(TR_CARD_TAPPED_NEED));
if (tapped_mustBe)
from = from.removeUnTapped();
boolean bpowerMin = hints.hasAnyHint(hintKey, new HintBundle(TR_CARD_POWER_MIN));
int ipowerMin = hints.getHintValueInt(hintKey, TR_CARD_POWER_MIN);
boolean bpowerMax = hints.hasAnyHint(hintKey, new HintBundle(TR_CARD_POWER_MAX));
int ipowerMax = hints.getHintValueInt(hintKey, TR_CARD_POWER_MAX);
boolean bfromughMin = hints.hasAnyHint(hintKey, new HintBundle(TR_CARD_TOUGHNESS_MIN));
int ifromughMin = hints.getHintValueInt(hintKey, TR_CARD_TOUGHNESS_MIN);
boolean bfromughMax = hints.hasAnyHint(hintKey, new HintBundle(TR_CARD_TOUGHNESS_MAX));
int ifromughMax = hints.getHintValueInt(hintKey, TR_CARD_TOUGHNESS_MAX);
if (bpowerMin)
{
from = from.onlyWithTypes("Creature");
from = from.onlyPowerHigher(ipowerMin-1);
}
if (bpowerMax)
{
from = from.onlyWithTypes("Creature");
from = from.onlyPowerLower(ipowerMax+1);
}
if (bfromughMin)
{
from = from.onlyWithTypes("Creature");
from = from.onlyToughnessHigher(ifromughMin-1);
}
if (bfromughMax)
{
from = from.onlyWithTypes("Creature");
from = from.onlyToughnessLower(ifromughMax+1);
}
if(hints.hasAnyHint(hintKey, new HintBundle(TY_OPPONENT_CHOSEN)))
{
// split target list in chosen and not chosen
CardSimList chosenList = new CardSimList();
CardSimList restList;// = new CardSimList();
int c = count;
// assuming source is negative effect!
from = from.sortListByCost();
while ( (c >0) && (from.size()>0) )
{
from.moveCardTo(from.getCard(0), chosenList);
c--;
}
from = chosenList;
}
for (int i=0; i< count; i++)
{
if (from.size() > 0)
{
CardSim tCard = from.getCard(from.size()-1);
if (from.isDummy())
tCard.owner = tPlayer;
if ((to == mGraveyard[tPlayer]) && (fromOrg == mBattlefield[tPlayer]))
{
creatureToGrave(tCard);
}
else
{
boolean done = false;
if (hints.hasAnyHint(hintKey, new HintBundle(TY_LIBRARY_BOTTOM)))
{
if (to == mLibrary[tPlayer])
{
done = true;
fromOrg.remove(tCard);
from.remove(tCard);
to.addCardFront(tCard);
}
}
if (!done)
{
if (tCard.isDummy())
{
fromOrg.remove(tCard);
to.addCard(tCard);
}
else
fromOrg.moveCardTo(tCard, to);
from.remove(tCard);
}
if (to == mGraveyard[tPlayer])
checkTriggerMoveToGrave(tCard);
removeFromAttack(tCard);
removeFromBlock(tCard);
}
if (sicken)
{
tCard.setSick(true);
}
}
}
if (hints.hasAnyHint(hintKey, new HintBundle(TY_LIBRARY_TOP)))
{
int p = tPlayer;
if(hints.hasAnyHint(hintKey, new HintBundle(HintAll.TY_LIBRARY_SHUFFLE)))
{
CardSim newCard = mLibrary[p].getCard(mLibrary[p].size()-1);
int size = mLibrary[p].size()-1;
mLibrary[p] = new CardSimList();
for (int i=0; i< size; i++)
{
mLibrary[p].addCard(Card.buildDummy(), p);
}
mLibrary[p].addCard(newCard);
}
}
else
{
int p = tPlayer;
if(hints.hasAnyHint(hintKey, new HintBundle(HintAll.TY_LIBRARY_SHUFFLE)))
{
mLibrary[p].shuffle();
}
}