- Changes to Thopter Foundry

- Added initial AIPreference code.
- Changed MagicStack.push to .add outside of MagicStack
This commit is contained in:
jendave
2011-08-06 10:23:13 +00:00
parent 9d0aff4cf4
commit 926947e1ab
8 changed files with 58 additions and 105 deletions

View File

@@ -2,6 +2,7 @@ Name:Thopter Foundry
ManaCost:WB U ManaCost:WB U
Types:Artifact Types:Artifact
Text:no text Text:no text
SVar:AIPreference:SacCost$Permanent.namedSword of the Meek
SVar:Rarity:Uncommon SVar:Rarity:Uncommon
SVar:Picture:http://www.wizards.com/global/images/magic/general/thopter_foundry.jpg SVar:Picture:http://www.wizards.com/global/images/magic/general/thopter_foundry.jpg
End End

View File

@@ -8304,7 +8304,7 @@ public class CardFactory implements NewConstants {
//this order is very important, do not change //this order is very important, do not change
stop(); stop();
if (paid) if (paid)
AllZone.Stack.push(ability); AllZone.Stack.add(ability);
} }
};//Input };//Input
ability.setBeforePayMana(payLife); ability.setBeforePayMana(payLife);
@@ -8775,7 +8775,7 @@ public class CardFactory implements NewConstants {
@Override @Override
public void showMessage() { public void showMessage() {
AllZone.Stack.push(ability2); AllZone.Stack.add(ability2);
stop(); stop();
}//showMessage() }//showMessage()
}); });
@@ -10205,99 +10205,35 @@ public class CardFactory implements NewConstants {
//*************** START *********** START ************************** //*************** START *********** START **************************
else if(cardName.equals("Thopter Foundry")) { else if(cardName.equals("Thopter Foundry")) {
final Player player = card.getController();
final SpellAbility ability = new Ability(card, "1") {
@Override
public void chooseTargetAI() {
Card c;
PlayerZone play = AllZone.getZone(Constant.Zone.Play, player);
CardList meek = new CardList();
meek.addAll(play.getCards());
meek = meek.getName("Sword of the Meek");
if(meek.size() >= 1) c = meek.get(0);
else c = getArtifact();
if(c != null) setTargetCard(c);
}
public Card getArtifact() {
//target creature that is going to attack
PlayerZone play = AllZone.getZone(Constant.Zone.Play, player);
CardList arts = new CardList();
arts.addAll(play.getCards());
arts = arts.filter(new CardListFilter() {
public boolean addCard(Card c) {
return c.isArtifact()
&& !c.isToken()
&& (CardUtil.getConvertedManaCost(c.getManaCost()) <= 1 && !c.equals(card) || c.getName().equals(
"Sword of the Meek"));
}
});
if(arts.size() > 0) {
arts.shuffle();
return arts.get(0);
} else return null;
}
Ability_Cost abCost = new Ability_Cost("1 Sac<1/Artifact.nonToken>", cardName, true);
final SpellAbility ability = new Ability_Activated(card, abCost, null) {
private static final long serialVersionUID = 1L;
@Override @Override
public boolean canPlayAI() { public boolean canPlayAI() {
String phase = AllZone.Phase.getPhase(); String phase = AllZone.Phase.getPhase();
return phase.equals(Constant.Phase.Main2) && getArtifact() != null; return phase.equals(Constant.Phase.Main2);
} }
@Override @Override
public void resolve() { public void resolve() {
Card c = getTargetCard();
if(AllZone.GameAction.isCardInPlay(c)) {
AllZone.GameAction.sacrifice(c);
makeToken(); makeToken();
card.getController().gainLife(1, card); card.getController().gainLife(1, card);
}
}//resolve }//resolve
public void makeToken() { public void makeToken() {
CardFactoryUtil.makeToken("Thopter", "U 1 1 Thopter", card.getController(), "U", new String[] { CardFactoryUtil.makeToken("Thopter", "U 1 1 Thopter", getActivatingPlayer(), "U", new String[] {
"Artifact", "Creature", "Thopter"}, 1, 1, new String[] {"Flying"}); "Artifact", "Creature", "Thopter"}, 1, 1, new String[] {"Flying"});
} }
}; };
Input runtime = new Input() {
private static final long serialVersionUID = 3557158378851031238L;
@Override
public void showMessage() {
PlayerZone play = AllZone.getZone(Constant.Zone.Play, player);
CardList arts = new CardList();
arts.addAll(play.getCards());
arts = arts.filter(new CardListFilter() {
public boolean addCard(Card c) {
return c.isArtifact() && !c.isToken();
}
});
stopSetNext(CardFactoryUtil.input_targetSpecific(ability, arts,
"Select a non-token Artifact to sacrifice", false, false));
}//showMessage()
};//Input
card.addSpellAbility(ability); card.addSpellAbility(ability);
ability.setDescription("1, Sacrifice a nontoken artifact: Put a 1/1 blue Thopter artifact creature token with flying onto the battlefield. You gain 1 life."); ability.setDescription("1, Sacrifice a nontoken artifact: Put a 1/1 blue Thopter artifact creature token with flying onto the battlefield. You gain 1 life.");
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append(card.getName()).append(" - Put a 1/1 blue Thopter artifact creature token with flying onto the battlefield. You gain 1 life."); sb.append(card.getName()).append(" - Put a 1/1 blue Thopter artifact creature token with flying onto the battlefield. You gain 1 life.");
ability.setStackDescription(sb.toString()); ability.setStackDescription(sb.toString());
ability.setBeforePayMana(runtime);
}//*************** END ************ END ************************** }//*************** END ************ END **************************

View File

@@ -2770,7 +2770,7 @@ public class CardFactoryUtil {
if(card.isCreature() && zone.is(Constant.Zone.Play) && canTarget(spell, card)) { if(card.isCreature() && zone.is(Constant.Zone.Play) && canTarget(spell, card)) {
spell.setTargetCard(card); spell.setTargetCard(card);
spell.getSourceCard().tap(); spell.getSourceCard().tap();
AllZone.Stack.push(spell); AllZone.Stack.add(spell);
stop(); stop();
} }
} }
@@ -2803,7 +2803,7 @@ public class CardFactoryUtil {
&& card.getKeyword().contains(keyword)) { && card.getKeyword().contains(keyword)) {
spell.setTargetCard(card); spell.setTargetCard(card);
spell.getSourceCard().tap(); spell.getSourceCard().tap();
AllZone.Stack.push(spell); AllZone.Stack.add(spell);
stop(); stop();
} }
} }
@@ -2933,7 +2933,7 @@ public class CardFactoryUtil {
&& !card.getKeyword().contains("Shroud")) { && !card.getKeyword().contains("Shroud")) {
spell.setTargetCard(card); spell.setTargetCard(card);
spell.getSourceCard().tap(); spell.getSourceCard().tap();
AllZone.Stack.push(spell); AllZone.Stack.add(spell);
stop(); stop();
} }
} }

View File

@@ -1041,7 +1041,7 @@ public class CardFactory_Creatures {
list = list.getName(card.getName()); list = list.getName(card.getName());
list.get(0).getController().discard(list.get(0), ability); list.get(0).getController().discard(list.get(0), ability);
AllZone.Stack.push(ability); AllZone.Stack.add(ability);
stop(); stop();
} }
}; };
@@ -1112,7 +1112,7 @@ public class CardFactory_Creatures {
list = list.getName(card.getName()); list = list.getName(card.getName());
list.get(0).getController().discard(list.get(0), ability); list.get(0).getController().discard(list.get(0), ability);
AllZone.Stack.push(ability); AllZone.Stack.add(ability);
stop(); stop();
} }
}; };
@@ -1173,7 +1173,7 @@ public class CardFactory_Creatures {
list = list.getName(card.getName()); list = list.getName(card.getName());
list.get(0).getController().discard(list.get(0), ability); list.get(0).getController().discard(list.get(0), ability);
AllZone.Stack.push(ability); AllZone.Stack.add(ability);
stop(); stop();
} }
}; };
@@ -8400,7 +8400,7 @@ public class CardFactory_Creatures {
else if(ability.canPlayAI()) { else if(ability.canPlayAI()) {
ability.chooseTargetAI(); ability.chooseTargetAI();
//need to add this to the stack //need to add this to the stack
AllZone.Stack.push(ability); AllZone.Stack.add(ability);
} }
}//execute() }//execute()

View File

@@ -93,7 +93,7 @@ class CardFactory_Planeswalkers {
check = AllZone.Phase.getTurn(); check = AllZone.Phase.getTurn();
turn[0] = AllZone.Phase.getTurn(); turn[0] = AllZone.Phase.getTurn();
AllZone.Stack.push(ability2); AllZone.Stack.add(ability2);
} }
stop(); stop();
}//showMessage() }//showMessage()
@@ -183,7 +183,7 @@ class CardFactory_Planeswalkers {
if(check != AllZone.Phase.getTurn()) { if(check != AllZone.Phase.getTurn()) {
check = AllZone.Phase.getTurn(); check = AllZone.Phase.getTurn();
turn[0] = AllZone.Phase.getTurn(); turn[0] = AllZone.Phase.getTurn();
AllZone.Stack.push(ability3); AllZone.Stack.add(ability3);
} }
stop(); stop();
}//showMessage() }//showMessage()
@@ -228,7 +228,7 @@ class CardFactory_Planeswalkers {
if(check != AllZone.Phase.getTurn()) { if(check != AllZone.Phase.getTurn()) {
check = AllZone.Phase.getTurn(); check = AllZone.Phase.getTurn();
turn[0] = AllZone.Phase.getTurn(); turn[0] = AllZone.Phase.getTurn();
AllZone.Stack.push(ability1); AllZone.Stack.add(ability1);
} }
stop(); stop();
}//showMessage() }//showMessage()
@@ -329,7 +329,7 @@ class CardFactory_Planeswalkers {
turn[0] = AllZone.Phase.getTurn(); turn[0] = AllZone.Phase.getTurn();
AllZone.Stack.push(ability2); AllZone.Stack.add(ability2);
} }
stop(); stop();
}//showMessage() }//showMessage()
@@ -403,7 +403,7 @@ class CardFactory_Planeswalkers {
if(check != AllZone.Phase.getTurn()) { if(check != AllZone.Phase.getTurn()) {
check = AllZone.Phase.getTurn(); check = AllZone.Phase.getTurn();
turn[0] = AllZone.Phase.getTurn(); turn[0] = AllZone.Phase.getTurn();
AllZone.Stack.push(ability3); AllZone.Stack.add(ability3);
} }
stop(); stop();
}//showMessage() }//showMessage()
@@ -476,7 +476,7 @@ class CardFactory_Planeswalkers {
if(check != AllZone.Phase.getTurn()) { if(check != AllZone.Phase.getTurn()) {
check = AllZone.Phase.getTurn(); check = AllZone.Phase.getTurn();
turn[0] = AllZone.Phase.getTurn(); turn[0] = AllZone.Phase.getTurn();
AllZone.Stack.push(ability1); AllZone.Stack.add(ability1);
} }
stop(); stop();
}//showMessage() }//showMessage()
@@ -607,7 +607,7 @@ class CardFactory_Planeswalkers {
if(check != AllZone.Phase.getTurn()) { if(check != AllZone.Phase.getTurn()) {
check = AllZone.Phase.getTurn(); check = AllZone.Phase.getTurn();
turn[0] = AllZone.Phase.getTurn(); turn[0] = AllZone.Phase.getTurn();
AllZone.Stack.push(ability3); AllZone.Stack.add(ability3);
} }
stop(); stop();
}//showMessage() }//showMessage()
@@ -702,7 +702,7 @@ class CardFactory_Planeswalkers {
turn[0] = AllZone.Phase.getTurn(); turn[0] = AllZone.Phase.getTurn();
AllZone.Stack.push(ability2); AllZone.Stack.add(ability2);
} }
stop(); stop();
}//showMessage() }//showMessage()
@@ -787,7 +787,7 @@ class CardFactory_Planeswalkers {
if(check != AllZone.Phase.getTurn()) { if(check != AllZone.Phase.getTurn()) {
check = AllZone.Phase.getTurn(); check = AllZone.Phase.getTurn();
turn[0] = AllZone.Phase.getTurn(); turn[0] = AllZone.Phase.getTurn();
AllZone.Stack.push(ability1); AllZone.Stack.add(ability1);
} }
stop(); stop();
}//showMessage() }//showMessage()
@@ -911,7 +911,7 @@ class CardFactory_Planeswalkers {
if(check != AllZone.Phase.getTurn()) { if(check != AllZone.Phase.getTurn()) {
check = AllZone.Phase.getTurn(); check = AllZone.Phase.getTurn();
turn[0] = AllZone.Phase.getTurn(); turn[0] = AllZone.Phase.getTurn();
AllZone.Stack.push(ability2); AllZone.Stack.add(ability2);
} }
stop(); stop();
}//showMessage() }//showMessage()
@@ -955,7 +955,7 @@ class CardFactory_Planeswalkers {
if(check != AllZone.Phase.getTurn()) { if(check != AllZone.Phase.getTurn()) {
check = AllZone.Phase.getTurn(); check = AllZone.Phase.getTurn();
turn[0] = AllZone.Phase.getTurn(); turn[0] = AllZone.Phase.getTurn();
AllZone.Stack.push(ability3); AllZone.Stack.add(ability3);
} }
stop(); stop();
}//showMessage() }//showMessage()
@@ -1001,7 +1001,7 @@ class CardFactory_Planeswalkers {
if(check != AllZone.Phase.getTurn()) { if(check != AllZone.Phase.getTurn()) {
check = AllZone.Phase.getTurn(); check = AllZone.Phase.getTurn();
turn[0] = AllZone.Phase.getTurn(); turn[0] = AllZone.Phase.getTurn();
AllZone.Stack.push(ability1); AllZone.Stack.add(ability1);
} }
stop(); stop();
}//showMessage() }//showMessage()
@@ -1119,7 +1119,7 @@ class CardFactory_Planeswalkers {
if(check != AllZone.Phase.getTurn()) { if(check != AllZone.Phase.getTurn()) {
check = AllZone.Phase.getTurn(); check = AllZone.Phase.getTurn();
turn[0] = AllZone.Phase.getTurn(); turn[0] = AllZone.Phase.getTurn();
AllZone.Stack.push(ability2); AllZone.Stack.add(ability2);
} }
stop(); stop();
}//showMessage() }//showMessage()
@@ -1181,7 +1181,7 @@ class CardFactory_Planeswalkers {
if(check != AllZone.Phase.getTurn()) { if(check != AllZone.Phase.getTurn()) {
check = AllZone.Phase.getTurn(); check = AllZone.Phase.getTurn();
turn[0] = AllZone.Phase.getTurn(); turn[0] = AllZone.Phase.getTurn();
AllZone.Stack.push(ability3); AllZone.Stack.add(ability3);
} }
stop(); stop();
}//showMessage() }//showMessage()
@@ -1667,7 +1667,7 @@ class CardFactory_Planeswalkers {
check = AllZone.Phase.getTurn(); check = AllZone.Phase.getTurn();
turn[0] = AllZone.Phase.getTurn(); turn[0] = AllZone.Phase.getTurn();
AllZone.Stack.push(ability2); AllZone.Stack.add(ability2);
stop(); stop();
} }
} }
@@ -1752,7 +1752,7 @@ class CardFactory_Planeswalkers {
check = AllZone.Phase.getTurn(); check = AllZone.Phase.getTurn();
turn[0] = AllZone.Phase.getTurn(); turn[0] = AllZone.Phase.getTurn();
AllZone.Stack.push(ability3); AllZone.Stack.add(ability3);
stop(); stop();
} }
} }
@@ -2004,7 +2004,7 @@ class CardFactory_Planeswalkers {
{ {
check = AllZone.Phase.getTurn(); check = AllZone.Phase.getTurn();
turn[0] = AllZone.Phase.getTurn(); turn[0] = AllZone.Phase.getTurn();
AllZone.Stack.push(ability1); AllZone.Stack.add(ability1);
} }
stop(); stop();
}//showMessage() }//showMessage()
@@ -2516,7 +2516,7 @@ class CardFactory_Planeswalkers {
check = AllZone.Phase.getTurn(); check = AllZone.Phase.getTurn();
turn[0] = AllZone.Phase.getTurn(); turn[0] = AllZone.Phase.getTurn();
AllZone.Stack.push(ability1); AllZone.Stack.add(ability1);
stop(); stop();
} }
} }
@@ -3156,7 +3156,7 @@ class CardFactory_Planeswalkers {
if(check != AllZone.Phase.getTurn()) { if(check != AllZone.Phase.getTurn()) {
check = AllZone.Phase.getTurn(); check = AllZone.Phase.getTurn();
turn[0] = AllZone.Phase.getTurn(); turn[0] = AllZone.Phase.getTurn();
AllZone.Stack.push(ability3); AllZone.Stack.add(ability3);
} }
stop(); stop();
}//showMessage() }//showMessage()
@@ -3200,7 +3200,7 @@ class CardFactory_Planeswalkers {
if(check != AllZone.Phase.getTurn()) { if(check != AllZone.Phase.getTurn()) {
check = AllZone.Phase.getTurn(); check = AllZone.Phase.getTurn();
turn[0] = AllZone.Phase.getTurn(); turn[0] = AllZone.Phase.getTurn();
AllZone.Stack.push(ability1); AllZone.Stack.add(ability1);
} }
stop(); stop();
}//showMessage() }//showMessage()
@@ -3243,7 +3243,7 @@ class CardFactory_Planeswalkers {
if(check != AllZone.Phase.getTurn()) { if(check != AllZone.Phase.getTurn()) {
check = AllZone.Phase.getTurn(); check = AllZone.Phase.getTurn();
turn[0] = AllZone.Phase.getTurn(); turn[0] = AllZone.Phase.getTurn();
AllZone.Stack.push(ability2); AllZone.Stack.add(ability2);
} }
stop(); stop();
}//showMessage() }//showMessage()
@@ -3394,7 +3394,7 @@ class CardFactory_Planeswalkers {
if(check != AllZone.Phase.getTurn()) { if(check != AllZone.Phase.getTurn()) {
check = AllZone.Phase.getTurn(); check = AllZone.Phase.getTurn();
turn[0] = AllZone.Phase.getTurn(); turn[0] = AllZone.Phase.getTurn();
AllZone.Stack.push(ability3); AllZone.Stack.add(ability3);
} }
stop(); stop();
}//showMessage() }//showMessage()

View File

@@ -612,6 +612,17 @@ public class ComputerUtil
} }
} }
static public Card getCardPreference(Card activate, String pref, CardList typeList){
String[] prefValid = activate.getSVar("AIPreference").split("\\$");
if (prefValid[0].equals(pref)){
CardList prefList = typeList.getValidCards(prefValid[1].split(","));
if (prefList.size() != 0){
prefList.shuffle();
return prefList.get(0);
}
}
return null;
}
static public Card chooseSacrificeType(String type, Card activate, Card target){ static public Card chooseSacrificeType(String type, Card activate, Card target){
PlayerZone play = AllZone.getZone(Constant.Zone.Play, AllZone.ComputerPlayer); PlayerZone play = AllZone.getZone(Constant.Zone.Play, AllZone.ComputerPlayer);
@@ -623,6 +634,10 @@ public class ComputerUtil
if (typeList.size() == 0) if (typeList.size() == 0)
return null; return null;
Card prefCard = getCardPreference(activate, "SacCost", typeList);
if (prefCard != null)
return prefCard;
CardListUtil.sortAttackLowFirst(typeList); CardListUtil.sortAttackLowFirst(typeList);
return typeList.get(0); return typeList.get(0);
} }

View File

@@ -6843,7 +6843,7 @@ public class GameActionUtil {
};// Ability };// Ability
ability.setStackDescription("Squee gets returned from graveyard to hand."); ability.setStackDescription("Squee gets returned from graveyard to hand.");
AllZone.Stack.push(ability); AllZone.Stack.add(ability);
} // if creatures > 0 } // if creatures > 0
} }
@@ -13985,7 +13985,7 @@ public class GameActionUtil {
}; };
ability.setStackDescription("Baru, Fist of Krosa - creatures get +1/+1 until end of turn."); ability.setStackDescription("Baru, Fist of Krosa - creatures get +1/+1 until end of turn.");
if(!all.getName("Baru, Fist of Krosa").isEmpty()) AllZone.Stack.push(ability); if(!all.getName("Baru, Fist of Krosa").isEmpty()) AllZone.Stack.add(ability);
}// outer for }// outer for
old = current; old = current;
@@ -14064,7 +14064,7 @@ public class GameActionUtil {
ability.setStackDescription(sb.toString()); ability.setStackDescription(sb.toString());
if(n[0] != 0) { if(n[0] != 0) {
AllZone.Stack.push(ability); AllZone.Stack.add(ability);
} }
}// outer for }// outer for

View File

@@ -396,7 +396,8 @@ public class MagicStack extends MyObservable {
return stack.size(); return stack.size();
} }
public void push(SpellAbility sp) { // Push should only be used by add.
private void push(SpellAbility sp) {
if (null == sp.getActivatingPlayer()) { if (null == sp.getActivatingPlayer()) {
sp.setActivatingPlayer(sp.getSourceCard().getController()); sp.setActivatingPlayer(sp.getSourceCard().getController());
System.out.println(sp.getSourceCard().getName() + " - activatingPlayer not set before adding to stack."); System.out.println(sp.getSourceCard().getName() + " - activatingPlayer not set before adding to stack.");
@@ -490,7 +491,7 @@ public class MagicStack extends MyObservable {
} }
} }
} else { } else {
// Spell fizzles, alert player? // TODO: Spell fizzles, what's the best way to alert player?
Log.debug(c.getName() + " ability fizzles."); Log.debug(c.getName() + " ability fizzles.");
} }