コード例 #1
0
  @Override
  public void execute(CGGemPunchConfirm message) {
    Player player = message.getPlayer();
    if (player == null) {
      return;
    }

    Human human = player.getHuman();
    if (human == null) {
      return;
    }

    // 判断功能是否开放
    if (!gameFuncService.gameFuncIsOpen(human, GameFuncType.GEM_EMBED, true)) {
      return;
    }

    HumanBagManager bagManager = human.getBagManager();
    BagType equipBagType = BagType.indexOf(message.getEquipBagType());
    int equipBagIndex = message.getEquipBagIndex();
    Item equipItem = bagManager.getItem(equipBagType, equipBagIndex);

    // 判断选中装备的合法性
    if (equipItem == null || !equipItem.isEquip()) {
      return;
    }

    if (!equipItem.canGemPunch()) {
      human.sendErrorMessage(LangConstants.MAX_HOLE);
      return;
    }

    EquipItemFeature itemFeature = (EquipItemFeature) equipItem.getFeature();
    int itemId = itemFeature.getNextGemPunchItemId();
    SimpleCommonItem commonItem = CommonItemBuilder.genSimpleCommonItem(itemId);
    if (commonItem == null) {
      return;
    }
    int itemNum = itemFeature.getNextGemPunchItemNum();

    GCGemPunchConfirm gcMsg = new GCGemPunchConfirm();
    gcMsg.setItemName(commonItem.getName());
    gcMsg.setItemNum(itemNum);
    human.sendMessage(gcMsg);
  }
コード例 #2
0
  @Override
  public void execute(CGSellShopItem message) {
    Player player = message.getPlayer();
    if (player == null) {
      return;
    }

    Human human = player.getHuman();
    if (human == null) {
      return;
    }

    // 判断功能是否开放
    if (!gameFuncService.gameFuncIsOpen(human, GameFuncType.SHOP, true)) {
      return;
    }

    BagType bagType = BagType.indexOf(message.getBagType());
    int bagIndex = message.getBagIndex();
    Item item = human.getBagManager().getItem(bagType, bagIndex);
    if (item == null) {
      return;
    }

    // 判断物品是否可以出售
    ItemTemplate itemTemplate = templateManager.getItemTemplate(item.getItemId());
    if (itemTemplate == null || !itemTemplate.canSell()) {
      human.sendErrorMessage(LangConstants.CAN_NOT_SELL_ITEM);
      return;
    }

    int num = message.getNum();
    if (num < 1) {
      return;
    }

    if (item.getOverlapNum() < num) {
      return;
    }
    int sellPrice = item.getSellCurrencyNum();
    if (item.isEquip()) {
      EquipItemFeature feature = (EquipItemFeature) item.getFeature();
      if (feature.isEquiped()) {
        human.sendErrorMessage(LangConstants.CAN_NOT_SELL);
        return;
      }
      EquipUpgradeTemplate upgradeTemplate =
          GameServerAssist.getEquipUpgradeTemplateManager()
              .getEquipUpgradeTemplate(item.getItemId(), feature.getLevel());
      if (upgradeTemplate != null) {
        sellPrice = upgradeTemplate.getSellPrice();
      }
    }

    human
        .getWallet()
        .addMoney(
            CurrencyType.indexOf(item.getSellCurrencyType()),
            sellPrice * num,
            true,
            MoneyLogReason.SHOP_SELL,
            "");

    human
        .getBagManager()
        .removeItem(item.getBagType(), item.getBagIndex(), num, ItemLogReason.SHOP_SELL, "");
  }