本文整理汇总了Java中net.sf.freecol.server.model.NativeTradeSession类的典型用法代码示例。如果您正苦于以下问题:Java NativeTradeSession类的具体用法?Java NativeTradeSession怎么用?Java NativeTradeSession使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NativeTradeSession类属于net.sf.freecol.server.model包,在下文中一共展示了NativeTradeSession类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deliverGiftToSettlement
import net.sf.freecol.server.model.NativeTradeSession; //导入依赖的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;
}