本文整理汇总了Java中net.sf.freecol.server.model.Session.lookup方法的典型用法代码示例。如果您正苦于以下问题:Java Session.lookup方法的具体用法?Java Session.lookup怎么用?Java Session.lookup使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.freecol.server.model.Session
的用法示例。
在下文中一共展示了Session.lookup方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: diplomacy
import net.sf.freecol.server.model.Session; //导入方法依赖的package包/类
/**
* Diplomacy.
*
* @param serverPlayer The {@code ServerPlayer} that is trading.
* @param ourColony Our {@code Colony}.
* @param otherUnit The other {@code Unit} that is trading.
* @param agreement The {@code DiplomaticTrade} to consider.
* @return A {@code ChangeSet} encapsulating this action.
*/
public ChangeSet diplomacy(ServerPlayer serverPlayer, Colony ourColony,
Unit otherUnit, DiplomaticTrade agreement) {
ChangeSet cs = new ChangeSet();
DiplomacySession session
= Session.lookup(DiplomacySession.class,
DiplomacySession.makeDiplomacySessionKey(otherUnit, ourColony));
if (session == null) {
return serverPlayer.clientError("Missing cu-diplomacy session for "
+ otherUnit.getId() + "/" + ourColony.getId()
+ " with " + agreement);
} else {
logger.info("Continuing diplomacy session: " + session
+ " from " + ourColony);
}
ServerPlayer otherPlayer = (ServerPlayer)otherUnit.getOwner();
serverPlayer.csDiplomacy(session, agreement, cs);
getGame().sendToOthers(serverPlayer, cs);
return cs;
}
示例2: monarchAction
import net.sf.freecol.server.model.Session; //导入方法依赖的package包/类
/**
* Respond to a monarch action.
*
* @param serverPlayer The {@code ServerPlayer} that is to respond.
* @param action The {@code MonarchAction} to respond to.
* @param result The player response.
* @return A {@code ChangeSet} containing the response.
*/
public ChangeSet monarchAction(ServerPlayer serverPlayer,
MonarchAction action, boolean result) {
MonarchSession session = Session.lookup(MonarchSession.class,
serverPlayer.getId(), "");
if (session == null) {
return serverPlayer.clientError("Bogus monarch action: " + action);
} else if (action != session.getAction()) {
return serverPlayer.clientError("Session action mismatch, "
+ session.getAction() + " expected: " + action);
}
ChangeSet cs = new ChangeSet();
session.complete(result, cs);
return cs;
}
示例3: lootCargo
import net.sf.freecol.server.model.Session; //导入方法依赖的package包/类
/**
* Loot cargo.
*
* Note loser is passed by identifier, as by the time we get here
* the unit may have been sunk.
*
* @param serverPlayer The {@code ServerPlayer} that owns the winner.
* @param winner The {@code Unit} that looting.
* @param loserId The object identifier of the {@code Unit}
* that is looted.
* @param loot The {@code Goods} to loot.
* @return A {@code ChangeSet} encapsulating this action.
*/
public ChangeSet lootCargo(ServerPlayer serverPlayer, Unit winner,
String loserId, List<Goods> loot) {
LootSession session = Session.lookup(LootSession.class,
winner.getId(), loserId);
if (session == null) {
return serverPlayer.clientError("Bogus looting!");
}
if (!winner.hasSpaceLeft()) {
return serverPlayer.clientError("No space to loot to: "
+ winner.getId());
}
ChangeSet cs = new ChangeSet();
List<Goods> available = session.getCapture();
if (loot == null) { // Initial inquiry
cs.add(See.only(serverPlayer),
new LootCargoMessage(winner, loserId, available));
} else {
for (Goods g : loot) {
if (!available.contains(g)) {
return serverPlayer.clientError("Invalid loot: " + g);
}
available.remove(g);
if (!winner.canAdd(g)) {
return serverPlayer.clientError("Loot failed: " + g);
}
winner.add(g);
}
// Others can see cargo capacity change.
session.complete(cs);
cs.add(See.perhaps(), winner);
getGame().sendToOthers(serverPlayer, cs);
}
return cs;
}
示例4: deliverGiftToSettlement
import net.sf.freecol.server.model.Session; //导入方法依赖的package包/类
/**
* Deliver gift to settlement.
* Note that this includes both European and native gifts.
*
* @param serverPlayer The {@code ServerPlayer} that is delivering.
* @param unit The {@code Unit} that is delivering.
* @param settlement The {@code Settlement} to deliver to.
* @param goods The {@code Goods} to deliver.
* @return A {@code ChangeSet} encapsulating this action.
*/
public ChangeSet deliverGiftToSettlement(ServerPlayer serverPlayer,
Unit unit, Settlement settlement,
Goods goods) {
NativeTradeSession session
= Session.lookup(NativeTradeSession.class, unit, settlement);
if (session == null) {
return serverPlayer.clientError("Trying to deliver gift without opening a session");
}
NativeTrade nt = session.getNativeTrade();
if (!nt.getGift()) {
return serverPlayer.clientError("Trying to deliver gift in a session where gift giving is not allowed: " + unit + " " + settlement + " " + session);
}
ChangeSet cs = new ChangeSet();
Tile tile = settlement.getTile();
GoodsLocation.moveGoods(unit, goods.getType(), goods.getAmount(), settlement);
cs.add(See.perhaps(), unit);
if (settlement instanceof ServerIndianSettlement) {
ServerIndianSettlement sis = (ServerIndianSettlement)settlement;
final int alarmBonus = -Math.round(sis.getPriceToBuy(goods)
* 0.001f * getGame().getSpecification()
.getPercentage(GameOptions.ALARM_BONUS_GIFT));
csVisit(serverPlayer, sis, 0, cs);
sis.csModifyAlarm(serverPlayer, alarmBonus, true, cs);
sis.updateWantedGoods();
tile.updateIndianSettlement(serverPlayer);
cs.add(See.only(serverPlayer), tile);
}
nt.setGift(true);
// Inform the receiver of the gift.
ModelMessage m = new ModelMessage(MessageType.GIFT_GOODS,
"deliverGift.goods",
settlement, goods.getType())
.addStringTemplate("%player%", serverPlayer.getNationLabel())
.addNamed("%type%", goods)
.addAmount("%amount%", goods.getAmount())
.addName("%settlement%", settlement.getName());
cs.addMessage(serverPlayer, m);
ServerPlayer receiver = (ServerPlayer) settlement.getOwner();
if (receiver.isConnected() && settlement instanceof Colony) {
cs.add(See.only(receiver), unit);
cs.add(See.only(receiver), settlement);
cs.addMessage(receiver, m);
}
logger.info("Gift delivered by unit: " + unit.getId()
+ " to settlement: " + settlement.getName());
// Others can see unit capacity, receiver gets it own items.
getGame().sendToOthers(serverPlayer, cs);
return cs;
}