Search in sources :

Example 1 with SOCChangeFace

use of soc.message.SOCChangeFace in project JSettlers2 by jdmonin.

the class SOCGameHandler method sitDown_sendPrivateInfo.

// javadoc inherited from GameHandler
public void sitDown_sendPrivateInfo(final SOCGame ga, final Connection c, final int pn) {
    final String gaName = ga.getName();
    final SOCPlayer pl = ga.getPlayer(pn);
    /**
     * send all the private information
     */
    SOCResourceSet resources = pl.getResources();
    // CLAY, ORE, SHEEP, WHEAT, WOOD, UNKNOWN
    final int[] counts = resources.getAmounts(true);
    if (c.getVersion() >= SOCPlayerElements.MIN_VERSION)
        srv.messageToPlayer(c, new SOCPlayerElements(gaName, pn, SOCPlayerElement.SET, ELEM_RESOURCES_WITH_UNKNOWN, counts));
    else
        for (int i = 0; i < counts.length; ++i) srv.messageToPlayer(c, new SOCPlayerElement(gaName, pn, SOCPlayerElement.SET, ELEM_RESOURCES_WITH_UNKNOWN[i], counts[i]));
    SOCInventory cardsInv = pl.getInventory();
    final boolean cliVersionNew = (c.getVersion() >= SOCDevCardConstants.VERSION_FOR_NEW_TYPES);
    /**
     * remove the unknown cards
     */
    final SOCDevCardAction cardUnknown = (cliVersionNew) ? new SOCDevCardAction(gaName, pn, SOCDevCardAction.PLAY, SOCDevCardConstants.UNKNOWN) : new SOCDevCardAction(gaName, pn, SOCDevCardAction.PLAY, SOCDevCardConstants.UNKNOWN_FOR_VERS_1_X);
    for (int i = cardsInv.getTotal(); i > 0; --i) {
        srv.messageToPlayer(c, cardUnknown);
    }
    /**
     * send all new dev cards first, then all playable, then all kept (VP cards)
     */
    for (int dcState = SOCInventory.NEW; dcState <= SOCInventory.KEPT; ++dcState) {
        final int dcAge = (dcState == SOCInventory.NEW) ? SOCInventory.NEW : SOCInventory.OLD;
        final int addCmd = (dcAge == SOCInventory.NEW) ? SOCDevCardAction.ADD_NEW : SOCDevCardAction.ADD_OLD;
        for (final SOCInventoryItem card : cardsInv.getByState(dcState)) {
            final SOCMessage addMsg;
            if (card instanceof SOCDevCard) {
                final int dcType = card.itype;
                if (cliVersionNew || (dcType != SOCDevCardConstants.KNIGHT))
                    addMsg = new SOCDevCardAction(gaName, pn, addCmd, dcType);
                else
                    addMsg = new SOCDevCardAction(gaName, pn, addCmd, SOCDevCardConstants.KNIGHT_FOR_VERS_1_X);
            } else {
                // None yet
                System.err.println("L1385: Unrecognized inventory item type " + card.getClass());
                addMsg = null;
            }
            if (addMsg != null)
                srv.messageToPlayer(c, addMsg);
        }
    // for (card)
    }
    // for (dcState)
    /**
     * send game state info such as requests for discards
     */
    sendGameState(ga);
    if ((ga.getCurrentDice() == 7) && pl.getNeedToDiscard()) {
        srv.messageToPlayer(c, new SOCDiscardRequest(gaName, pl.getResources().getTotal() / 2));
    } else if (ga.hasSeaBoard) {
        final int numGoldRes = pl.getNeedToPickGoldHexResources();
        if (numGoldRes > 0)
            srv.messageToPlayer(c, new SOCSimpleRequest(gaName, pn, SOCSimpleRequest.PROMPT_PICK_RESOURCES, numGoldRes));
    }
    /**
     * send what face this player is using
     */
    srv.messageToGame(gaName, new SOCChangeFace(gaName, pn, pl.getFaceId()));
}
Also used : SOCMessage(soc.message.SOCMessage) SOCDiscardRequest(soc.message.SOCDiscardRequest) SOCPlayerElements(soc.message.SOCPlayerElements) SOCChangeFace(soc.message.SOCChangeFace) SOCSimpleRequest(soc.message.SOCSimpleRequest) SOCPlayerElement(soc.message.SOCPlayerElement) SOCDevCardAction(soc.message.SOCDevCardAction)

Aggregations

SOCChangeFace (soc.message.SOCChangeFace)1 SOCDevCardAction (soc.message.SOCDevCardAction)1 SOCDiscardRequest (soc.message.SOCDiscardRequest)1 SOCMessage (soc.message.SOCMessage)1 SOCPlayerElement (soc.message.SOCPlayerElement)1 SOCPlayerElements (soc.message.SOCPlayerElements)1 SOCSimpleRequest (soc.message.SOCSimpleRequest)1