mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 03:08:02 +00:00
removed some old code from counters
Players have getAllies/Opponents methods
This commit is contained in:
@@ -22,6 +22,7 @@ import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Random;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
@@ -1294,7 +1295,7 @@ public class AbilityFactoryCounters {
|
||||
|
||||
@Override
|
||||
public boolean canPlayAI() {
|
||||
return AbilityFactoryCounters.proliferateShouldPlayAI(this);
|
||||
return AbilityFactoryCounters.proliferateShouldPlayAI(getActivatingPlayer(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1332,7 +1333,7 @@ public class AbilityFactoryCounters {
|
||||
|
||||
@Override
|
||||
public boolean canPlayAI() {
|
||||
return AbilityFactoryCounters.proliferateShouldPlayAI(this);
|
||||
return AbilityFactoryCounters.proliferateShouldPlayAI(getActivatingPlayer(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1376,7 +1377,7 @@ public class AbilityFactoryCounters {
|
||||
|
||||
@Override
|
||||
public boolean canPlayAI() {
|
||||
return AbilityFactoryCounters.proliferateShouldPlayAI(this);
|
||||
return AbilityFactoryCounters.proliferateShouldPlayAI(getActivatingPlayer(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1391,7 +1392,7 @@ public class AbilityFactoryCounters {
|
||||
|
||||
@Override
|
||||
public boolean chkAIDrawback() {
|
||||
return AbilityFactoryCounters.proliferateShouldPlayAI(this);
|
||||
return AbilityFactoryCounters.proliferateShouldPlayAI(getActivatingPlayer(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1441,14 +1442,16 @@ public class AbilityFactoryCounters {
|
||||
* a {@link forge.card.spellability.SpellAbility} object.
|
||||
* @return a boolean.
|
||||
*/
|
||||
private static boolean proliferateShouldPlayAI(final SpellAbility sa) {
|
||||
private static boolean proliferateShouldPlayAI(final Player ai, final SpellAbility sa) {
|
||||
boolean chance = true;
|
||||
final AbilitySub subAb = sa.getSubAbility();
|
||||
if (subAb != null && !subAb.chkAIDrawback()) {
|
||||
return false;
|
||||
}
|
||||
List<Card> hperms = AllZone.getHumanPlayer().getCardsIn(ZoneType.Battlefield);
|
||||
List<Card> cperms = AllZone.getComputerPlayer().getCardsIn(ZoneType.Battlefield);
|
||||
|
||||
|
||||
|
||||
List<Card> cperms = ai.getCardsIn(ZoneType.Battlefield);
|
||||
cperms = CardLists.filter(cperms, new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean apply(final Card crd) {
|
||||
@@ -1461,6 +1464,7 @@ public class AbilityFactoryCounters {
|
||||
}
|
||||
});
|
||||
|
||||
List<Card> hperms = ai.getOpponent().getCardsIn(ZoneType.Battlefield);
|
||||
hperms = CardLists.filter(hperms, new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean apply(final Card crd) {
|
||||
@@ -1473,7 +1477,7 @@ public class AbilityFactoryCounters {
|
||||
}
|
||||
});
|
||||
|
||||
if ((cperms.size() == 0) && (hperms.size() == 0) && (AllZone.getHumanPlayer().getPoisonCounters() == 0)) {
|
||||
if ((cperms.size() == 0) && (hperms.size() == 0) && (ai.getOpponent().getPoisonCounters() == 0)) {
|
||||
return false;
|
||||
}
|
||||
return chance;
|
||||
@@ -1512,13 +1516,17 @@ public class AbilityFactoryCounters {
|
||||
* @param sa
|
||||
* a {@link forge.card.spellability.SpellAbility} object.
|
||||
*/
|
||||
private static void proliferateResolve(final AbilityFactory af, final SpellAbility sa) {
|
||||
List<Card> hperms = AllZone.getHumanPlayer().getCardsIn(ZoneType.Battlefield);
|
||||
List<Card> cperms = AllZone.getComputerPlayer().getCardsIn(ZoneType.Battlefield);
|
||||
|
||||
if (sa.getSourceCard().getController().isHuman()) {
|
||||
cperms.addAll(hperms);
|
||||
final List<Card> unchosen = cperms;
|
||||
private static void proliferateResolve(final AbilityFactory af, final SpellAbility sa) {
|
||||
Player controller = sa.getSourceCard().getController();
|
||||
if (controller.isHuman())
|
||||
proliferateResolveHuman(af, sa);
|
||||
else
|
||||
proliferateResolveAI(controller, af, sa);
|
||||
}
|
||||
|
||||
private static void proliferateResolveHuman(final AbilityFactory af, final SpellAbility sa) {
|
||||
final List<Card> unchosen = AllZoneUtil.getCardsIn(ZoneType.Battlefield);
|
||||
AllZone.getInputControl().setInput(new Input() {
|
||||
private static final long serialVersionUID = -1779224307654698954L;
|
||||
|
||||
@@ -1557,110 +1565,91 @@ public class AbilityFactoryCounters {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean selComputer = false;
|
||||
private boolean selHuman = false;
|
||||
List<Player> players = AllZone.getPlayersInGame();
|
||||
|
||||
@Override
|
||||
public void selectPlayer(final Player player) {
|
||||
if (player.isHuman() && (!this.selHuman)) {
|
||||
this.selHuman = true;
|
||||
if (AllZone.getHumanPlayer().getPoisonCounters() > 0) {
|
||||
AllZone.getHumanPlayer().addPoisonCounters(1, sa.getSourceCard());
|
||||
}
|
||||
}
|
||||
if (player.isComputer() && (!this.selComputer)) {
|
||||
this.selComputer = true;
|
||||
if (AllZone.getComputerPlayer().getPoisonCounters() > 0) {
|
||||
AllZone.getComputerPlayer().addPoisonCounters(1, sa.getSourceCard());
|
||||
if (players.indexOf(player) >= 0)
|
||||
{
|
||||
players.remove(player); // no second selection
|
||||
if (player.getPoisonCounters() > 0) {
|
||||
player.addPoisonCounters(1, sa.getSourceCard());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
} else { // Compy
|
||||
cperms = CardLists.filter(cperms, new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean apply(final Card crd) {
|
||||
for (final Counters c1 : Counters.values()) {
|
||||
if (crd.getCounters(c1) != 0) {
|
||||
if (!CardFactoryUtil.isNegativeCounter(c1)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
hperms = CardLists.filter(hperms, new Predicate<Card>() {
|
||||
|
||||
|
||||
private static void proliferateResolveAI(final Player ai, final AbilityFactory af, final SpellAbility sa) {
|
||||
final List<Player> allies = ai.getAllies();
|
||||
allies.add(ai);
|
||||
final List<Player> enemies = ai.getOpponents();
|
||||
final Predicate<Card> predProliferate = new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean apply(final Card crd) {
|
||||
for (final Counters c1 : Counters.values()) {
|
||||
if (crd.getCounters(c1) != 0) {
|
||||
if (CardFactoryUtil.isNegativeCounter(c1)) {
|
||||
public boolean apply(Card crd) {
|
||||
for (final Entry<Counters, Integer> c1 : crd.getCounters().entrySet()) {
|
||||
if ( CardFactoryUtil.isNegativeCounter(c1.getKey()) && enemies.contains(crd.getController()))
|
||||
return true;
|
||||
if ( !CardFactoryUtil.isNegativeCounter(c1.getKey()) && allies.contains(crd.getController()))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
List<Card> cardsToProliferate = CardLists.filter(AllZoneUtil.getCardsIn(ZoneType.Battlefield), predProliferate);
|
||||
List<Player> playersToPoison = new ArrayList<Player>();
|
||||
for( Player e : enemies ) {
|
||||
if ( e.getPoisonCounters() > 0 )
|
||||
playersToPoison.add(e);
|
||||
}
|
||||
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append("<html>Proliferate: <br>Computer selects ");
|
||||
if ((cperms.size() == 0) && (hperms.size() == 0) && (AllZone.getHumanPlayer().getPoisonCounters() == 0)) {
|
||||
sb.append("<html>Proliferate. Computer selects:<br>");
|
||||
if (cardsToProliferate.isEmpty() && playersToPoison.isEmpty()) {
|
||||
sb.append("<b>nothing</b>.");
|
||||
} else {
|
||||
if (cperms.size() > 0) {
|
||||
sb.append("<br>From Computer's permanents: <br><b>");
|
||||
for (final Card c : cperms) {
|
||||
sb.append(c);
|
||||
sb.append(" ");
|
||||
}
|
||||
for( Card c : cardsToProliferate ) {
|
||||
sb.append(c.getController().getName());
|
||||
sb.append("'s <b>");
|
||||
sb.append(c.getName());
|
||||
sb.append("</b><br>");
|
||||
}
|
||||
if (hperms.size() > 0) {
|
||||
sb.append("<br>From Human's permanents: <br><b>");
|
||||
for (final Card c : cperms) {
|
||||
sb.append(c);
|
||||
sb.append(" ");
|
||||
|
||||
if( !playersToPoison.isEmpty() ) {
|
||||
sb.append("<br>The following players: <br>");
|
||||
}
|
||||
for( Player p : playersToPoison ) {
|
||||
sb.append("<b>");
|
||||
sb.append(p.getName());
|
||||
sb.append("</b><br>");
|
||||
}
|
||||
if (AllZone.getHumanPlayer().getPoisonCounters() > 0) {
|
||||
sb.append("<b>Human Player</b>.");
|
||||
}
|
||||
} // else
|
||||
sb.append("</html>");
|
||||
|
||||
// add a counter of one counter type, if it would benefit the
|
||||
// computer
|
||||
for (final Card c : cperms) {
|
||||
for (final Counters c1 : Counters.values()) {
|
||||
if (c.getCounters(c1) != 0 && !CardFactoryUtil.isNegativeCounter(c1)) {
|
||||
c.addCounter(c1, 1);
|
||||
for (final Card c : cardsToProliferate) {
|
||||
for (final Entry<Counters, Integer> c1 : c.getCounters().entrySet()) {
|
||||
if ( CardFactoryUtil.isNegativeCounter(c1.getKey()) && enemies.contains(c.getController()))
|
||||
{
|
||||
c.addCounter(c1.getKey(), 1);
|
||||
break;
|
||||
}
|
||||
if ( !CardFactoryUtil.isNegativeCounter(c1.getKey()) && allies.contains(c.getController()))
|
||||
{
|
||||
c.addCounter(c1.getKey(), 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// add a counter of one counter type, if it would screw over the
|
||||
// player
|
||||
for (final Card c : hperms) {
|
||||
for (final Counters c1 : Counters.values()) {
|
||||
if (c.getCounters(c1) != 0 && CardFactoryUtil.isNegativeCounter(c1)) {
|
||||
c.addCounter(c1, 1);
|
||||
break;
|
||||
for(final Player p : playersToPoison ) {
|
||||
p.addPoisonCounters(1, sa.getSourceCard());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// give human a poison counter, if he has one
|
||||
if (AllZone.getHumanPlayer().getPoisonCounters() > 0) {
|
||||
AllZone.getHumanPlayer().addPoisonCounters(1, sa.getSourceCard());
|
||||
}
|
||||
|
||||
} // comp
|
||||
}
|
||||
|
||||
// *******************************************
|
||||
// ********** PutCounterAll ******************
|
||||
|
||||
@@ -21,8 +21,6 @@ import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import forge.AllZone;
|
||||
import forge.Card;
|
||||
|
||||
import forge.CardLists;
|
||||
@@ -72,24 +70,12 @@ public class AIPlayer extends Player {
|
||||
super(myName, myLife, myPoisonCounters);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getOpponent.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link forge.game.player.Player} object.
|
||||
*/
|
||||
@Override
|
||||
public final Player getOpponent() {
|
||||
return AllZone.getHumanPlayer();
|
||||
}
|
||||
|
||||
// //////////////
|
||||
// /
|
||||
// / Methods to ease transition to Abstract Player class
|
||||
// /
|
||||
// /////////////
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* isHuman.
|
||||
|
||||
@@ -68,18 +68,6 @@ public class HumanPlayer extends Player {
|
||||
super(myName, myLife, myPoisonCounters);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getOpponent.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link forge.game.player.Player} object.
|
||||
*/
|
||||
@Override
|
||||
public final Player getOpponent() {
|
||||
return AllZone.getComputerPlayer();
|
||||
}
|
||||
|
||||
// //////////////
|
||||
// /
|
||||
// / Methods to ease transition to Abstract Player class
|
||||
|
||||
@@ -29,6 +29,7 @@ import java.util.Random;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
@@ -244,12 +245,38 @@ public abstract class Player extends GameEntity implements Comparable<Player> {
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getOpponent.
|
||||
* getOpponent. WILL BE DEPRECATED
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link forge.game.player.Player} object.
|
||||
*/
|
||||
public abstract Player getOpponent();
|
||||
public final Player getOpponent() {
|
||||
Predicate<Player> enemy = com.google.common.base.Predicates.not(Player.Predicates.isType(this.getType()));
|
||||
return Iterables.find(Singletons.getModel().getGameState().getPlayers(), enemy);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* returns all opponents
|
||||
* Should keep player relations somewhere in the match structure
|
||||
* @return
|
||||
*/
|
||||
public final List<Player> getOpponents() {
|
||||
Predicate<Player> enemy = com.google.common.base.Predicates.not(Player.Predicates.isType(this.getType()));
|
||||
return Lists.newArrayList(Iterables.filter(Singletons.getModel().getGameState().getPlayers(), enemy));
|
||||
}
|
||||
|
||||
/**
|
||||
* returns allied players
|
||||
* Should keep player relations somewhere in the match structure
|
||||
* @return
|
||||
*/
|
||||
public final List<Player> getAllies() {
|
||||
Predicate<Player> enemy = Player.Predicates.isType(this.getType());
|
||||
return Lists.newArrayList(Iterables.filter(Singletons.getModel().getGameState().getPlayers(), enemy));
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ////////////////////////
|
||||
//
|
||||
@@ -2698,6 +2725,18 @@ public abstract class Player extends GameEntity implements Comparable<Player> {
|
||||
this.deck = deck;
|
||||
}
|
||||
|
||||
public static class Predicates {
|
||||
|
||||
public static Predicate<Player> isType(final PlayerType type) {
|
||||
return new Predicate<Player>() {
|
||||
@Override
|
||||
public boolean apply(Player input){
|
||||
return input.getType() == type;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static class Accessors {
|
||||
public static Function<Player, Integer> FN_GET_LIFE = new Function<Player, Integer>(){
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user