Allies list added to player, all relations (like isOpponent) will be based on it

This commit is contained in:
Maxmtg
2013-05-20 20:49:33 +00:00
parent 3fd671c7e7
commit 13dc9fedd9
6 changed files with 41 additions and 41 deletions

View File

@@ -22,6 +22,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;
import com.google.common.eventbus.EventBus;
@@ -87,16 +88,16 @@ public class GameState {
/**
* Constructor.
* @param players2
* @param players2.entrySet()
* @param match0
* @param input
*/
public GameState(Iterable<LobbyPlayer> players2, GameType t, MatchController match0) { /* no more zones to map here */
public GameState(Map<LobbyPlayer, PlayerStartConditions> players2, GameType t, MatchController match0) { /* no more zones to map here */
type = t;
match = match0;
List<Player> players = new ArrayList<Player>();
for (LobbyPlayer p : players2) {
Player pl = p.getPlayer(this);
for (Entry<LobbyPlayer, PlayerStartConditions> kv : players2.entrySet()) {
Player pl = kv.getKey().getPlayer(this);
players.add(pl);
ingamePlayers.add(pl);
}

View File

@@ -139,7 +139,7 @@ public class MatchController {
public void startRound() {
inputQueue = new InputQueue(this);
currentGame = new GameState(players.keySet(), gameType, this);
currentGame = new GameState(players, gameType, this);
try {
attachUiToMatch(this, FControl.SINGLETON_INSTANCE.getLobby().getGuiPlayer());

View File

@@ -61,4 +61,12 @@ public class MatchStartHelper {
return players;
}
public void setAllies(final LobbyPlayer p1, final LobbyPlayer p2) {
PlayerStartConditions psc1 = players.get(p1);
PlayerStartConditions psc2 = players.get(p2);
psc1.addAlly(p2);
psc2.addAlly(p1);
}
}

View File

@@ -2,8 +2,10 @@ package forge.game;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import forge.deck.Deck;
import forge.game.player.LobbyPlayer;
import forge.game.player.Player;
import forge.item.CardPrinted;
import forge.item.IPaperCard;
@@ -20,6 +22,7 @@ public class PlayerStartConditions {
private Iterable<? extends IPaperCard> cardsInCommand = null;
private Iterable<? extends IPaperCard> schemes = null;
private Iterable<CardPrinted> planes = null;
private List<LobbyPlayer> allies = new ArrayList<LobbyPlayer>();
public PlayerStartConditions(Deck deck0) {
originalDeck = deck0;
@@ -82,6 +85,11 @@ public class PlayerStartConditions {
this.cardsInCommand = function;
}
public void addAlly(LobbyPlayer ally) {
if(!allies.contains(ally))
allies.add(ally);
}
/**
* @return the schemes
*/

View File

@@ -26,7 +26,6 @@ import java.util.List;
import java.util.Map;
import java.util.Random;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
@@ -54,6 +53,7 @@ import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target;
import forge.card.staticability.StaticAbility;
import forge.card.trigger.TriggerType;
import forge.control.FControl;
import forge.game.GameActionUtil;
import forge.game.GameState;
import forge.game.GlobalRuleChange;
@@ -163,6 +163,7 @@ public class Player extends GameEntity implements Comparable<Player> {
private PlayerStatistics stats = new PlayerStatistics();
protected PlayerController controller;
private final LobbyPlayer lobbyPlayer;
private final List<LobbyPlayer> allies = new ArrayList<LobbyPlayer>();
private Card activeScheme = null;
@@ -214,7 +215,7 @@ public class Player extends GameEntity implements Comparable<Player> {
public boolean isHuman() { return getType() == PlayerType.HUMAN; }
@Deprecated
public boolean isComputer() { return getType() == PlayerType.COMPUTER; }
public PlayerType getType() {
private PlayerType getType() {
return getLobbyPlayer().getType();
}
@@ -264,18 +265,11 @@ public class Player extends GameEntity implements Comparable<Player> {
* @return a {@link forge.game.player.Player} object.
*/
public final Player getOpponent() {
Player otherType = null;
Player justAnyone = null;
for (Player p : game.getPlayers()) {
if (p == this) {
continue;
if (p == this || allies.contains(p.getLobbyPlayer())) { continue; }
return p;
}
justAnyone = p;
if (otherType == null && p.getType() != this.getType()) {
otherType = p;
}
}
return otherType != null ? otherType : justAnyone;
throw new IllegalStateException("No opponents left ingame for " + this);
}
/**
@@ -287,9 +281,7 @@ public class Player extends GameEntity implements Comparable<Player> {
public final List<Player> getOpponents() {
List<Player> result = new ArrayList<Player>();
for (Player p : game.getPlayers()) {
if (p == this || p.getType() == this.getType()) {
continue;
}
if (p == this || allies.contains(p.getLobbyPlayer())) { continue; }
result.add(p);
}
return result;
@@ -303,9 +295,7 @@ public class Player extends GameEntity implements Comparable<Player> {
public final List<Player> getAllies() {
List<Player> result = new ArrayList<Player>();
for (Player p : game.getPlayers()) {
if (p == this || p.getType() != this.getType()) {
continue;
}
if( allies.contains(p.getLobbyPlayer()))
result.add(p);
}
return result;
@@ -1814,7 +1804,8 @@ public class Player extends GameEntity implements Comparable<Player> {
}
// Dev Mode
if (Singletons.getModel().getPreferences().getPrefBoolean(FPref.DEV_UNLIMITED_LAND) && this.getType() == PlayerType.HUMAN && Preferences.DEV_MODE) {
if (this == FControl.SINGLETON_INSTANCE.getPlayer() && Preferences.DEV_MODE &&
Singletons.getModel().getPreferences().getPrefBoolean(FPref.DEV_UNLIMITED_LAND)) {
return true;
}
@@ -2703,13 +2694,6 @@ public class Player extends GameEntity implements Comparable<Player> {
}
};
public static Function<Player, PlayerType> FN_GET_TYPE = new Function<Player, PlayerType>() {
@Override
public PlayerType apply(Player input) {
return input.getType();
}
};
public static Function<Player, String> FN_GET_NAME = new Function<Player, String>() {
@Override
public String apply(Player input) {
@@ -2920,11 +2904,7 @@ public class Player extends GameEntity implements Comparable<Player> {
* @return
*/
public boolean isOpponentOf(Player other) {
if (other.equals(getOpponent())) {
return true;
}
return other.getType() != this.getType();
return other != this && !allies.contains(other.getLobbyPlayer());
}

View File

@@ -221,18 +221,21 @@ public enum CSubmenuArchenemy implements ICDoc {
Lobby lobby = Singletons.getControl().getLobby();
MatchStartHelper helper = new MatchStartHelper();
List<LobbyPlayer> allies = new ArrayList<LobbyPlayer>();
for (int i = 0; i < view.getNumPlayers(); i++) {
LobbyPlayer player = i == 0 ? lobby.getGuiPlayer() : lobby.getAiPlayer();
if (i == 0) {
LobbyPlayer player = lobby.getGuiPlayer();
helper.addArchenemy(player, playerDecks.get(i), schemes);
helper.getPlayerMap().get(player).setStartingLife(10 + (10 * (view.getNumPlayers() - 1)));
} else {
LobbyPlayer player = lobby.getAiPlayer();
allies.add(player);
helper.addPlayer(player, playerDecks.get(i));
}
}
for(int i = 0; i < allies.size(); i++)
for(int j = i+1; i < allies.size(); j++)
helper.setAllies(allies.get(i), allies.get(j));
final MatchController mc = new MatchController(GameType.Archenemy, helper.getPlayerMap());
FThreads.invokeInEdtLater(new Runnable(){