Search in sources :

Example 1 with SOCInventory

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

the class SOCHandPanel method updateDevCards.

/**
 * Update the displayed list of player's development cards and other inventory items,
 * and enable or disable the "Play Card" button.
 *<P>
 * Enables the "Play Card" button for {@link SOCInventory#PLAYABLE PLAYABLE} cards,
 * and also for {@link SOCInventory#KEPT KEPT} cards (VP cards) so the user can
 * pick those and get a message that that they've already been played, instead of
 * wondering why they're listed but can't be played.
 *<P>
 * Updates {@link #inventory} and {@link #inventoryItems} to keep them in sync.
 * @param addedPlayable  True if the update added a dev card or item that's playable now
 */
public void updateDevCards(final boolean addedPlayable) {
    SOCInventory items = player.getInventory();
    boolean hasOldCards = false;
    synchronized (inventory.getTreeLock()) {
        inventory.removeAll();
        inventoryItems.clear();
        if (addedPlayable && !inventory.isEnabled())
            // can become disabled in game state PLACING_INV_ITEM
            inventory.setEnabled(true);
        // show all new cards first, then all playable, then all kept (VP cards)
        for (int cState = SOCInventory.NEW; cState <= SOCInventory.KEPT; ++cState) {
            final boolean isNew = (cState == SOCInventory.NEW);
            for (// almost always instanceof SOCDevCard
            final SOCInventoryItem item : // almost always instanceof SOCDevCard
            items.getByState(cState)) {
                if (isNew) {
                    inventory.add(DEVCARD_NEW + item.getItemName(game, false, strings));
                } else {
                    inventory.add(item.getItemName(game, false, strings));
                    hasOldCards = true;
                }
                inventoryItems.add(item);
            }
        }
    }
    playCardBut.setEnabled(hasOldCards && playerIsCurrent);
}
Also used : SOCInventoryItem(soc.game.SOCInventoryItem) SOCInventory(soc.game.SOCInventory)

Example 2 with SOCInventory

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

the class SOCDisplaylessPlayerClient method handleINVENTORYITEMACTION.

/**
 * Handle the "inventory item action" message by updating player inventory.
 * @param games  The hashtable of client's {@link SOCGame}s; key = game name
 * @param mes  the message
 * @return  True if this message is a "cannot play this type now" from server for our client player.
 * @since 2.0.00
 */
public static boolean handleINVENTORYITEMACTION(Hashtable<String, SOCGame> games, SOCInventoryItemAction mes) {
    SOCGame ga = games.get(mes.getGame());
    if (ga == null)
        return false;
    if ((mes.playerNumber == -1) || (mes.action == SOCInventoryItemAction.CANNOT_PLAY))
        return true;
    SOCPlayer pl = ga.getPlayer(mes.playerNumber);
    if (pl == null)
        return false;
    SOCInventory inv = pl.getInventory();
    SOCInventoryItem item = null;
    switch(mes.action) {
        case SOCInventoryItemAction.ADD_PLAYABLE:
        case SOCInventoryItemAction.ADD_OTHER:
            inv.addItem(SOCInventoryItem.createForScenario(ga, mes.itemType, (mes.action == SOCInventoryItemAction.ADD_PLAYABLE), mes.isKept, mes.isVP, mes.canCancelPlay));
            break;
        case SOCInventoryItemAction.PLAYED:
            if (mes.isKept)
                inv.keepPlayedItem(mes.itemType);
            else
                item = inv.removeItem(SOCInventory.PLAYABLE, mes.itemType);
            if (!SOCInventoryItem.isPlayForPlacement(ga, mes.itemType))
                break;
        case SOCInventoryItemAction.PLACING_EXTRA:
            if (item == null)
                item = SOCInventoryItem.createForScenario(ga, mes.itemType, true, mes.isKept, mes.isVP, mes.canCancelPlay);
            ga.setPlacingItem(item);
            break;
    }
    return false;
}
Also used : SOCInventoryItem(soc.game.SOCInventoryItem) SOCInventory(soc.game.SOCInventory) SOCPlayer(soc.game.SOCPlayer) SOCGame(soc.game.SOCGame)

Example 3 with SOCInventory

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

the class SOCRobotBrain method handleDEVCARDACTION.

/**
 * Handle a DEVCARDACTION for this game.
 * No brain-specific action.
 * @since 1.1.08
 */
private void handleDEVCARDACTION(SOCDevCardAction mes) {
    SOCInventory cardsInv = game.getPlayer(mes.getPlayerNumber()).getInventory();
    final int cardType = mes.getCardType();
    switch(mes.getAction()) {
        case SOCDevCardAction.DRAW:
            cardsInv.addDevCard(1, SOCInventory.NEW, cardType);
            break;
        case SOCDevCardAction.PLAY:
            cardsInv.removeDevCard(SOCInventory.OLD, cardType);
            break;
        case SOCDevCardAction.ADD_OLD:
            cardsInv.addDevCard(1, SOCInventory.OLD, cardType);
            break;
        case SOCDevCardAction.ADD_NEW:
            cardsInv.addDevCard(1, SOCInventory.NEW, cardType);
            break;
    }
}
Also used : SOCInventory(soc.game.SOCInventory)

Aggregations

SOCInventory (soc.game.SOCInventory)3 SOCInventoryItem (soc.game.SOCInventoryItem)2 SOCGame (soc.game.SOCGame)1 SOCPlayer (soc.game.SOCPlayer)1