當前位置: 首頁>>代碼示例>>Java>>正文


Java Role.getMaximumCount方法代碼示例

本文整理匯總了Java中net.sf.freecol.common.model.Role.getMaximumCount方法的典型用法代碼示例。如果您正苦於以下問題:Java Role.getMaximumCount方法的具體用法?Java Role.getMaximumCount怎麽用?Java Role.getMaximumCount使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在net.sf.freecol.common.model.Role的用法示例。


在下文中一共展示了Role.getMaximumCount方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: equipForRole

import net.sf.freecol.common.model.Role; //導入方法依賴的package包/類
/**
 * Equips this AI unit for a particular role.
 *
 * The unit must be at a location where the required goods are available
 * (possibly requiring a purchase, which may fail due to lack of gold
 * or boycotts in effect).
 *
 * @param role The {@code Role} to equip for identifier.
 * @return True if the role change was successful.
 */
public boolean equipForRole(Role role) {
    final Player player = unit.getOwner();
    Location loc = Location.upLoc(unit.getLocation());
    if (!(loc instanceof UnitLocation)) return false;
    int count = role.getMaximumCount();
    if (count > 0) {
        for (; count > 0; count--) {
            List<AbstractGoods> req = unit.getGoodsDifference(role, count);
            try {
                int price = ((UnitLocation)loc).priceGoods(req);
                if (player.checkGold(price)) break;
            } catch (FreeColException fce) {
                continue;
            }
        }
        if (count <= 0) return false;
    }
    return AIMessage.askEquipForRole(this, role, count)
        && unit.getRole() == role && unit.getRoleCount() == count;
}
 
開發者ID:FreeCol,項目名稱:freecol,代碼行數:31,代碼來源:AIUnit.java

示例2: addRoleItems

import net.sf.freecol.common.model.Role; //導入方法依賴的package包/類
/**
 * Add menu items for role manipulation for a unit.
 *
 * Note "clear speciality" is here too to keep it well separated from
 * other items.
 *
 * @param unitLabel The {@code UnitLabel} specifying the unit.
 * @return True if menu items were added and a separator is now needed.
 */
private boolean addRoleItems(final UnitLabel unitLabel) {
    final Specification spec = freeColClient.getGame().getSpecification();
    final Unit unit = unitLabel.getUnit();
    final Role role = unit.getRole();
    final int roleCount = unit.getRoleCount();
    boolean separatorNeeded = false;

    UnitLocation uloc = (unit.isInEurope()) ? unit.getOwner().getEurope()
        : unit.getSettlement();
    if (uloc == null) return false;
    for (Role r : transform(unit.getAvailableRoles(null),
                            r2 -> r2 != role)) {
        JMenuItem newItem;
        if (r.isDefaultRole()) { // Always valid
            newItem = createRoleItem(unitLabel, role, roleCount, r, 0, 0);
        } else {
            newItem = null;
            for (int count = r.getMaximumCount(); count > 0; count--) {
                List<AbstractGoods> req = unit.getGoodsDifference(r, count);
                try {
                    int price = uloc.priceGoods(req);
                    if (unit.getOwner().checkGold(price)) {
                        newItem = createRoleItem(unitLabel, role, roleCount,
                                                 r, count, price);
                        break;
                    }
                } catch (FreeColException fce) {
                    continue;
                }
            }
        }
        if (newItem != null) {
            this.add(newItem);
            separatorNeeded = true;
        }
    }

    UnitTypeChange uc = unit.getUnitChange(UnitChangeType.CLEAR_SKILL);
    if (uc != null) {
        if (separatorNeeded) this.addSeparator();
        JMenuItem menuItem = Utility.localizedMenuItem("quickActionMenu.clearSpeciality",
            new ImageIcon(gui.getImageLibrary().getTinyUnitImage(uc.to)));
        menuItem.setActionCommand(UnitAction.CLEAR_SPECIALITY.toString());
        menuItem.addActionListener(unitLabel);
        this.add(menuItem);
        if (unit.getLocation() instanceof Building
            && !((Building)unit.getLocation()).canAddType(uc.to)) {
            menuItem.setEnabled(false);
        }
        separatorNeeded = true;
    }
    return separatorNeeded;
}
 
開發者ID:FreeCol,項目名稱:freecol,代碼行數:63,代碼來源:QuickActionMenu.java

示例3: serverHandler

import net.sf.freecol.common.model.Role; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public ChangeSet serverHandler(FreeColServer freeColServer,
                               ServerPlayer serverPlayer) {
    final Game game = freeColServer.getGame();
    final String unitId = getStringAttribute(UNIT_TAG);
    final String roleId = getStringAttribute(ROLE_TAG);
    final String countString = getStringAttribute(COUNT_TAG);

    Unit unit;
    try {
        unit = serverPlayer.getOurFreeColGameObject(unitId, Unit.class);
    } catch (Exception e) {
        return serverPlayer.clientError(e.getMessage());
    }
    if (unit.isInEurope()) {
        ; // Always OK
    } else if (!unit.hasTile()) {
        return serverPlayer.clientError("Unit is not on the map: "
            + unitId);
    } else if (unit.getSettlement() == null) {
        return serverPlayer.clientError("Unit is not in a settlement: "
            + unitId);
    }

    Role role = game.getSpecification().getRole(roleId);
    if (role == null) {
        return serverPlayer.clientError("Not a role: " + roleId);
    }
    int count;
    try {
        count = Integer.parseInt(countString);
    } catch (NumberFormatException nfe) {
        return serverPlayer.clientError("Role count is not an integer: "
            + countString);
    }
    if (count < 0 || count > role.getMaximumCount()) {
        return serverPlayer.clientError("Invalid role count: "
            + countString);
    }

    // Proceed to equip.
    return igc(freeColServer)
        .equipForRole(serverPlayer, unit, role, count);
}
 
開發者ID:FreeCol,項目名稱:freecol,代碼行數:48,代碼來源:EquipForRoleMessage.java


注:本文中的net.sf.freecol.common.model.Role.getMaximumCount方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。