本文整理汇总了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;
}
示例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;
}
示例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);
}