Exemple #1
0
  /**
   * Writes manastones : 6C - statenum mask, 6H - value
   *
   * @param item
   */
  private void writeItemStones(ByteBuffer buf) {
    Item item = parent.item;
    int count = 0;

    if (item.hasManaStones()) {
      Set<ManaStone> itemStones = item.getItemStones();

      for (ManaStone itemStone : itemStones) {
        if (count == 6) break;

        StatFunction modifier = itemStone.getFirstModifier();
        if (modifier != null) {
          count++;
          writeH(buf, modifier.getName().getItemStoneMask());
        }
      }
      skip(buf, (6 - count) * 2);
      count = 0;
      for (ManaStone itemStone : itemStones) {
        if (count == 6) break;

        StatFunction modifier = itemStone.getFirstModifier();
        if (modifier != null) {
          count++;
          writeH(buf, modifier.getValue());
        }
      }
      skip(buf, (6 - count) * 2);
    } else {
      skip(buf, 24);
    }
    // for now max 6 stones - write some junk
  }
  public static void fusionWeapons(Player player, int firstItemUniqueId, int secondItemUniqueId) {
    Item firstItem = player.getInventory().getItemByObjId(firstItemUniqueId);
    if (firstItem == null)
      firstItem = player.getEquipment().getEquippedItemByObjId(firstItemUniqueId);

    Item secondItem = player.getInventory().getItemByObjId(secondItemUniqueId);
    if (secondItem == null)
      secondItem = player.getEquipment().getEquippedItemByObjId(secondItemUniqueId);

    /*
     * Need to have items in bag, and target the fusion NPC
     */
    if (firstItem == null || secondItem == null || !(player.getTarget() instanceof Npc)) return;
    if (!MathUtil.isIn3dRange(player.getTarget(), player, 10)) return;
    /*
     * Both have to be 2h weapons
     */
    if (!firstItem.getItemTemplate().isWeapon() || !secondItem.getItemTemplate().isWeapon()) {
      Logger.getLogger(ArmsfusionService.class)
          .info("[AUDIT]Player: " + player.getName() + " trying to fusion non-weapon. Hacking!");
      return;
    }
    if (firstItem.getItemTemplate().getWeaponType() == null
        || secondItem.getItemTemplate().getWeaponType() == null) return;
    else {
      switch (firstItem.getItemTemplate().getWeaponType()) {
        case DAGGER_1H:
        case MACE_1H:
        case SWORD_1H:
        case TOOLHOE_1H:
          Logger.getLogger(ArmsfusionService.class)
              .info("[AUDIT]Player: " + player.getName() + " trying to fusion 1h weapon. Hacking!");
          return;
      }
      switch (secondItem.getItemTemplate().getWeaponType()) {
        case DAGGER_1H:
        case MACE_1H:
        case SWORD_1H:
        case TOOLHOE_1H:
          Logger.getLogger(ArmsfusionService.class)
              .info("[AUDIT]Player: " + player.getName() + " trying to fusion 1h weapon. Hacking!");
          return;
      }
    }

    // check if both items are fusionable
    if (!firstItem.getItemTemplate().isCanFuse() || !secondItem.getItemTemplate().isCanFuse())
      return;

    double rarity = rarityRate(firstItem.getItemTemplate().getItemQuality());
    double priceRate = player.getPrices().getGlobalPrices(player.getCommonData().getRace()) * .01;
    double taxRate = player.getPrices().getTaxes(player.getCommonData().getRace()) * .01;
    int priceMod = player.getPrices().getGlobalPricesModifier() * 2;
    int level = firstItem.getItemTemplate().getLevel();
    int price = (int) (priceMod * priceRate * taxRate * rarity * level * level);
    log.debug(
        "Rarity: "
            + rarity
            + " Price Rate: "
            + priceRate
            + " Tax Rate: "
            + taxRate
            + " Price Mod: "
            + priceMod
            + " Weapon Level: "
            + level);
    log.debug("Price: " + price);

    if (player.getInventory().getKinahItem().getItemCount() < price) {
      PacketSendUtility.sendPacket(
          player,
          SM_SYSTEM_MESSAGE.STR_COMPOUND_ERROR_NOT_ENOUGH_MONEY(
              firstItem.getNameID(), secondItem.getNameID()));
      return;
    }

    /*
     * Fusioned weapons must have same type
     */
    if (firstItem.getItemTemplate().getWeaponType()
        != secondItem.getItemTemplate().getWeaponType()) {
      PacketSendUtility.sendPacket(player, SM_SYSTEM_MESSAGE.STR_COMPOUND_ERROR_DIFFERENT_TYPE);
      return;
    }

    /*
     * Second weapon must have inferior or equal lvl. in relation to first weapon
     */
    if (secondItem.getItemTemplate().getLevel() > firstItem.getItemTemplate().getLevel()) {
      PacketSendUtility.sendPacket(
          player, SM_SYSTEM_MESSAGE.STR_COMPOUND_ERROR_MAIN_REQUIRE_HIGHER_LEVEL);
      return;
    }

    boolean decreaseResult = player.getInventory().decreaseKinah(price);
    if (!decreaseResult) return;

    boolean removeResult = player.getInventory().removeFromBagByObjectId(secondItemUniqueId, 1);
    if (!removeResult) return;

    firstItem.setFusionedItem(secondItem.getItemTemplate().getTemplateId());

    ItemService.removeAllFusionStone(player, firstItem);

    if (secondItem.hasOptionalSocket()) {
      firstItem.setOptionalFusionSocket(secondItem.getOptionalSocket());
    } else {
      firstItem.setOptionalFusionSocket(0);
    }

    Set<ManaStone> manastones = secondItem.getItemStones();
    for (ManaStone stone : manastones) ItemService.addFusionStone(firstItem, stone.getItemId());

    if (firstItem.getPersistentState() != PersistentState.NEW
        && firstItem.getPersistentState() != PersistentState.UPDATE_REQUIRED)
      firstItem.setPersistentState(PersistentState.UPDATE_REQUIRED);

    DAOManager.getDAO(InventoryDAO.class).store(firstItem, player.getObjectId());

    PacketSendUtility.sendPacket(player, new SM_DELETE_ITEM(secondItemUniqueId));

    PacketSendUtility.sendPacket(player, new SM_UPDATE_ITEM(firstItem));

    PacketSendUtility.sendPacket(
        player,
        SM_SYSTEM_MESSAGE.STR_COMPOUND_SUCCESS(firstItem.getNameID(), secondItem.getNameID()));
  }