Search in sources :

Example 61 with SOCPlayer

use of soc.game.SOCPlayer in project JSettlers2 by jdmonin.

the class SOCDiceResultResources method buildForGame.

/**
 * Builder for server to tell clients about players' gained resources and new total counts.
 * Only players with nonzero {@link SOCPlayer#getRolledResources()}
 * {@link SOCResourceSet#getKnownTotal() .getKnownTotal()} are included.
 * If no player gained any known resources, returns {@code null}.
 * @param ga  Game to check for rolled resources
 * @return  Message for this game's rolled resources, or {@code null} if no players gained known resources
 */
public static final SOCDiceResultResources buildForGame(final SOCGame ga) {
    ArrayList<Integer> pnum = null;
    ArrayList<SOCResourceSet> rsrc = null;
    for (int pn = 0; pn < ga.maxPlayers; ++pn) {
        if (ga.isSeatVacant(pn))
            continue;
        final SOCPlayer pp = ga.getPlayer(pn);
        final SOCResourceSet rs = pp.getRolledResources();
        if (rs.getKnownTotal() == 0)
            continue;
        if (pnum == null) {
            pnum = new ArrayList<Integer>();
            rsrc = new ArrayList<SOCResourceSet>();
        }
        pnum.add(Integer.valueOf(pn));
        rsrc.add(rs);
    }
    if (pnum == null)
        return null;
    ArrayList<Integer> rTotal = new ArrayList<Integer>();
    for (int pn : pnum) rTotal.add(Integer.valueOf(ga.getPlayer(pn).getResources().getTotal()));
    return new SOCDiceResultResources(ga.getName(), pnum, rTotal, rsrc);
}
Also used : ArrayList(java.util.ArrayList) SOCResourceSet(soc.game.SOCResourceSet) SOCPlayer(soc.game.SOCPlayer)

Aggregations

SOCPlayer (soc.game.SOCPlayer)61 SOCGame (soc.game.SOCGame)17 SOCShip (soc.game.SOCShip)12 SOCSettlement (soc.game.SOCSettlement)11 SOCRoad (soc.game.SOCRoad)9 SOCResourceSet (soc.game.SOCResourceSet)8 SOCCity (soc.game.SOCCity)7 SOCBoardLarge (soc.game.SOCBoardLarge)6 SOCFortress (soc.game.SOCFortress)5 ArrayList (java.util.ArrayList)4 SOCBoard (soc.game.SOCBoard)4 Connection (soc.server.genericServer.Connection)4 SOCInventoryItem (soc.game.SOCInventoryItem)3 SOCVillage (soc.game.SOCVillage)3 SQLException (java.sql.SQLException)2 Iterator (java.util.Iterator)2 Stack (java.util.Stack)2 SOCLRPathData (soc.game.SOCLRPathData)2 SOCPlayingPiece (soc.game.SOCPlayingPiece)2 SOCSpecialItem (soc.game.SOCSpecialItem)2