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);
}
Aggregations