mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 12:48:00 +00:00
- Added AF_ZoneAffecting for things like Draw, Discard, Mill etc.
- Created Draw AbilityFactory - Converted Yawgmoth's Bargain to use Draw
This commit is contained in:
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -5522,6 +5522,7 @@ src/forge/AbilityFactory_Fetch.java -text svneol=native#text/plain
|
||||
src/forge/AbilityFactory_PermanentState.java -text svneol=native#text/plain
|
||||
src/forge/AbilityFactory_Pump.java -text svneol=native#text/plain
|
||||
src/forge/AbilityFactory_Regenerate.java -text svneol=native#text/plain
|
||||
src/forge/AbilityFactory_ZoneAffecting.java -text svneol=native#text/plain
|
||||
src/forge/Ability_Activated.java svneol=native#text/plain
|
||||
src/forge/Ability_Cost.java -text svneol=native#text/plain
|
||||
src/forge/Ability_Mana.java -text svneol=native#text/plain
|
||||
|
||||
@@ -2,6 +2,7 @@ Name:Yawgmoth's Bargain
|
||||
ManaCost:4 B B
|
||||
Types:Enchantment
|
||||
Text:Skip your draw step.
|
||||
A:AB$Draw|Cost$PayLife<1>|NumCards$1|SpellDescription$Draw a card.
|
||||
SVar:RemAIDeck:True
|
||||
SVar:Rarity:Rare
|
||||
SVar:Picture:http://www.wizards.com/global/images/magic/general/yawgmoths_bargain.jpg
|
||||
|
||||
@@ -259,6 +259,14 @@ public class AbilityFactory {
|
||||
}
|
||||
}
|
||||
|
||||
if (API.equals("Draw")){
|
||||
if (isAb)
|
||||
SA = AbilityFactory_ZoneAffecting.createAbilityDraw(this);
|
||||
if (isSp){
|
||||
SA = AbilityFactory_ZoneAffecting.createSpellDraw(this);
|
||||
}
|
||||
}
|
||||
|
||||
// *********************************************
|
||||
// set universal properties of the SpellAbility
|
||||
if (hasSpDesc)
|
||||
|
||||
150
src/forge/AbilityFactory_ZoneAffecting.java
Normal file
150
src/forge/AbilityFactory_ZoneAffecting.java
Normal file
@@ -0,0 +1,150 @@
|
||||
package forge;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
|
||||
public class AbilityFactory_ZoneAffecting {
|
||||
public static SpellAbility createAbilityDraw(final AbilityFactory AF){
|
||||
final SpellAbility abDraw = new Ability_Activated(AF.getHostCard(), AF.getAbCost(), AF.getAbTgt()){
|
||||
private static final long serialVersionUID = 5445572699000471299L;
|
||||
|
||||
final AbilityFactory af = AF;
|
||||
|
||||
@Override
|
||||
public String getStackDescription(){
|
||||
// when getStackDesc is called, just build exactly what is happening
|
||||
Player player = af.getAbTgt() == null ? getActivatingPlayer() : getTargetPlayer();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.append(getSourceCard().getName());
|
||||
sb.append(" - ");
|
||||
sb.append(player.toString());
|
||||
sb.append(" draws (");
|
||||
sb.append(af.getMapParams().get("NumCards"));
|
||||
sb.append(")");
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public boolean canPlay(){
|
||||
// super takes care of AdditionalCosts
|
||||
return super.canPlay();
|
||||
}
|
||||
|
||||
public boolean canPlayAI()
|
||||
{
|
||||
return drawCanPlayAI(af,this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resolve() {
|
||||
drawResolve(af, this);
|
||||
}
|
||||
|
||||
};
|
||||
return abDraw;
|
||||
}
|
||||
|
||||
public static SpellAbility createSpellDraw(final AbilityFactory AF){
|
||||
final SpellAbility spDraw = new Spell(AF.getHostCard(), AF.getAbCost(), AF.getAbTgt()){
|
||||
private static final long serialVersionUID = -4990932993654533449L;
|
||||
|
||||
final AbilityFactory af = AF;
|
||||
|
||||
public boolean canPlay(){
|
||||
// super takes care of AdditionalCosts
|
||||
return super.canPlay();
|
||||
}
|
||||
|
||||
public boolean canPlayAI()
|
||||
{
|
||||
return drawCanPlayAI(af, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resolve() {
|
||||
drawResolve(af, this);
|
||||
}
|
||||
|
||||
};
|
||||
return spDraw;
|
||||
}
|
||||
|
||||
public static boolean drawCanPlayAI(final AbilityFactory af, SpellAbility sa){
|
||||
// AI cannot use this properly until he can use SAs during Humans turn
|
||||
if (!ComputerUtil.canPayCost(sa))
|
||||
return false;
|
||||
|
||||
Target tgt = af.getAbTgt();
|
||||
Card source = sa.getSourceCard();
|
||||
Ability_Cost abCost = af.getAbCost();
|
||||
HashMap<String,String> params = af.getMapParams();
|
||||
|
||||
if (abCost != null){
|
||||
// AI currently disabled for these costs
|
||||
if (abCost.getSacCost()){
|
||||
return false;
|
||||
}
|
||||
if (abCost.getLifeCost()){
|
||||
if (AllZone.ComputerPlayer.getLife() < 5)
|
||||
return false;
|
||||
}
|
||||
if (abCost.getDiscardCost()) return false;
|
||||
|
||||
if (abCost.getSubCounter()) return false;
|
||||
|
||||
}
|
||||
|
||||
if (tgt != null){
|
||||
// todo: handle deciding what X would be around here for Braingeyser type cards
|
||||
int numCards = 1;
|
||||
if (params.containsKey("NumCards"))
|
||||
numCards = Integer.parseInt(params.get("NumCards"));
|
||||
|
||||
if (numCards >= AllZoneUtil.getCardsInZone(Constant.Zone.Library, AllZone.HumanPlayer).size()){
|
||||
// Deck the Human? DO IT!
|
||||
sa.setTargetPlayer(AllZone.ComputerPlayer);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (numCards >= AllZoneUtil.getCardsInZone(Constant.Zone.Library, AllZone.ComputerPlayer).size()){
|
||||
// Don't deck your self
|
||||
return false;
|
||||
}
|
||||
|
||||
sa.setTargetPlayer(AllZone.ComputerPlayer);
|
||||
}
|
||||
|
||||
Random r = new Random();
|
||||
boolean randomReturn = r.nextFloat() <= Math.pow(.6667, source.getAbilityUsed());
|
||||
|
||||
// some other variables here, like handsize vs. maxHandSize
|
||||
|
||||
return randomReturn;
|
||||
}
|
||||
|
||||
public static void drawResolve(final AbilityFactory af, final SpellAbility sa){
|
||||
HashMap<String,String> params = af.getMapParams();
|
||||
|
||||
Card source = sa.getSourceCard();
|
||||
|
||||
int numCards = Integer.parseInt(params.get("NumCards"));
|
||||
Player player;
|
||||
|
||||
Player target = sa.getTargetPlayer();
|
||||
|
||||
if (af.getAbTgt() == null)
|
||||
player = sa.getActivatingPlayer();
|
||||
else if(CardFactoryUtil.canTarget(source, target))
|
||||
player = target;
|
||||
else // Fizzle?
|
||||
return;
|
||||
|
||||
player.drawCards(numCards);
|
||||
|
||||
String DrawBack = params.get("SubAbility");
|
||||
if (af.hasSubAbility())
|
||||
CardFactoryUtil.doDrawBack(DrawBack, 0, source.getController(), source.getController().getOpponent(), source.getController(), source, null, sa);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -8230,48 +8230,6 @@ public class CardFactory implements NewConstants {
|
||||
card.addSpellAbility(nightSoil);
|
||||
}//*************** END ************ END **************************
|
||||
|
||||
|
||||
//*************** START *********** START **************************
|
||||
else if(cardName.equals("Yawgmoth's Bargain")) {
|
||||
final SpellAbility ability = new Ability(card, "0") {
|
||||
@Override
|
||||
public void resolve() {
|
||||
card.getController().drawCard();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlayAI() {
|
||||
return false;
|
||||
}
|
||||
};//SpellAbility
|
||||
|
||||
ability.setDescription("Pay 1 life: Draw a card.");
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(card.getName()).append(" - Pay 1 life: Draw a card.");
|
||||
ability.setStackDescription(sb.toString());
|
||||
|
||||
card.addSpellAbility(ability);
|
||||
|
||||
//instead of paying mana, pay life and add to stack
|
||||
//Input showMessage() is always the first method called
|
||||
Input payLife = new Input() {
|
||||
|
||||
private static final long serialVersionUID = 8660593629867722192L;
|
||||
|
||||
@Override
|
||||
public void showMessage() {
|
||||
boolean paid = card.getController().payLife(1, card);
|
||||
|
||||
//this order is very important, do not change
|
||||
stop();
|
||||
if (paid)
|
||||
AllZone.Stack.push(ability);
|
||||
}
|
||||
};//Input
|
||||
ability.setBeforePayMana(payLife);
|
||||
}//*************** END ************ END **************************
|
||||
|
||||
|
||||
//*************** START *********** START **************************
|
||||
else if(cardName.equals("Necropotence")) {
|
||||
|
||||
Reference in New Issue
Block a user