@Override
  public HandlerResult onItemUseEvent(final QuestEnv env, Item item) {
    final Player player = env.getPlayer();
    final int id = item.getItemTemplate().getTemplateId();
    final int itemObjId = item.getObjectId();

    if (id != 182208043) return HandlerResult.UNKNOWN;
    PacketSendUtility.broadcastPacket(
        player, new SM_ITEM_USAGE_ANIMATION(player.getObjectId(), itemObjId, id, 3000, 0, 0), true);
    ThreadPoolManager.getInstance()
        .schedule(
            new Runnable() {

              @Override
              public void run() {
                PacketSendUtility.broadcastPacket(
                    player,
                    new SM_ITEM_USAGE_ANIMATION(player.getObjectId(), itemObjId, id, 0, 1, 0),
                    true);
                sendQuestDialog(env, 4);
              }
            },
            3000);
    return HandlerResult.SUCCESS;
  }
  /**
   * @param itemTemplate
   * @param slot
   * @param cgs
   */
  private static void onItemEquipment(Item item, CreatureGameStats<?> cgs) {
    ItemTemplate itemTemplate = item.getItemTemplate();
    long slot = item.getEquipmentSlot();
    List<StatFunction> modifiers = itemTemplate.getModifiers();
    if (modifiers == null) {
      return;
    }

    List<StatFunction> allModifiers = null;

    if ((slot & ItemSlot.MAIN_OR_SUB.getSlotIdMask()) != 0) {
      allModifiers = wrapModifiers(item, modifiers);
      if (item.hasFusionedItem()) {
        // add all bonus modifiers according to rules
        ItemTemplate fusionedItemTemplate = item.getFusionedItemTemplate();
        WeaponType weaponType = fusionedItemTemplate.getWeaponType();
        List<StatFunction> fusionedItemModifiers = fusionedItemTemplate.getModifiers();
        if (fusionedItemModifiers != null) {
          allModifiers.addAll(wrapModifiers(item, fusionedItemModifiers));
        }
        // add 10% of Magic Boost and Attack
        WeaponStats weaponStats = fusionedItemTemplate.getWeaponStats();
        if (weaponStats != null) {
          int boostMagicalSkill = Math.round(0.1f * weaponStats.getBoostMagicalSkill());
          int attack = Math.round(0.1f * weaponStats.getMeanDamage());
          if (weaponType == WeaponType.ORB_2H
              || weaponType == WeaponType.BOOK_2H
              || weaponType == WeaponType.GUN_1H
              || weaponType == WeaponType.KEYBLADE_2H
              || weaponType == WeaponType.CANNON_2H
              || weaponType == WeaponType.HARP_2H) {
            allModifiers.add(new StatAddFunction(StatEnum.MAGICAL_ATTACK, attack, false));
            allModifiers.add(
                new StatAddFunction(StatEnum.BOOST_MAGICAL_SKILL, boostMagicalSkill, false));
          } else allModifiers.add(new StatAddFunction(StatEnum.PHYSICAL_ATTACK, attack, false));
        }
      }
    } else {
      WeaponStats weaponStat = itemTemplate.getWeaponStats();
      if (weaponStat != null) {
        allModifiers = wrapModifiersW(item, modifiers);
      } else allModifiers = modifiers;
    }

    item.setCurrentModifiers(allModifiers);
    cgs.addEffect(item, allModifiers);
  }
 @Override
 public HandlerResult onItemUseEvent(QuestEnv env, Item item) {
   final Player player = env.getPlayer();
   final int id = item.getItemTemplate().getTemplateId();
   if (id == 182213191) {
     QuestState qs = player.getQuestStateList().getQuestState(questId);
     if (qs != null && qs.getStatus() == QuestStatus.START) {
       qs.setQuestVar(1);
       qs.setStatus(QuestStatus.REWARD);
       updateQuestStatus(env);
     }
   }
   return HandlerResult.UNKNOWN;
 }
  private static List<StatFunction> wrapModifiersW(Item item, List<StatFunction> modifiers) {
    List<StatFunction> allModifiers = new ArrayList<StatFunction>();
    ItemTemplate itemTemplate = item.getItemTemplate();
    WeaponStats weaponStats = itemTemplate.getWeaponStats();
    for (StatFunction modifier : modifiers) {
      switch (modifier.getName()) {
        default:
          allModifiers.add(modifier);
      }
    }
    allModifiers.add(new StatAddFunction(StatEnum.PARRY, weaponStats.getParry(), false));
    allModifiers.add(
        new StatAddFunction(StatEnum.MAGICAL_ACCURACY, weaponStats.getMagicalAccuracy(), false));
    allModifiers.add(
        new StatAddFunction(StatEnum.PHYSICAL_ACCURACY, weaponStats.getPhysicalAccuracy(), false));

    return allModifiers;
  }
示例#5
0
  /** {@inheritDoc} */
  @Override
  protected void runImpl() {
    Player player = getConnection().getActivePlayer();

    if (player.isProtectionActive()) {
      player.getController().stopProtectionActiveTask();
    }

    Item item = player.getInventory().getItemByObjId(uniqueItemId);
    Item targetItem = player.getInventory().getItemByObjId(targetItemId);
    HouseObject<?> targetHouseObject = null;

    if (item == null) {
      log.warn(
          String.format(
              "CHECKPOINT: null item use action: %d %d", player.getObjectId(), uniqueItemId));
      return;
    }

    if (targetItem == null) targetItem = player.getEquipment().getEquippedItemByObjId(targetItemId);
    if (targetItem == null && player.getHouseRegistry() != null)
      targetHouseObject = player.getHouseRegistry().getObjectByObjId(targetItemId);

    if (item.getItemTemplate().getTemplateId() == 165000001
        && targetItem.getItemTemplate().canExtract()) {
      PacketSendUtility.sendPacket(player, SM_SYSTEM_MESSAGE.STR_ITEM_COLOR_ERROR);
      return;
    }

    // check use item multicast delay exploit cast (spam)
    if (player.isCasting()) {
      // PacketSendUtility.sendMessage(this.getOwner(),
      // "You must wait until cast time finished to use skill again.");
      player.getController().cancelCurrentSkill();
      // On retail the item is cancelling the current skill and then procs normally
      // return;
    }

    if (!RestrictionsManager.canUseItem(player, item)) return;

    if (item.getItemTemplate().getRace() != Race.PC_ALL
        && item.getItemTemplate().getRace() != player.getRace()) {
      PacketSendUtility.sendPacket(player, SM_SYSTEM_MESSAGE.STR_CANNOT_USE_ITEM_INVALID_RACE);
      return;
    }

    int requiredLevel =
        item.getItemTemplate().getRequiredLevel(player.getCommonData().getPlayerClass());
    if (requiredLevel == -1) {
      PacketSendUtility.sendPacket(player, SM_SYSTEM_MESSAGE.STR_CANNOT_USE_ITEM_INVALID_CLASS);
      return;
    }

    if (requiredLevel > player.getLevel()) {
      PacketSendUtility.sendPacket(
          player,
          SM_SYSTEM_MESSAGE.STR_CANNOT_USE_ITEM_TOO_LOW_LEVEL_MUST_BE_THIS_LEVEL(
              item.getNameId(), requiredLevel));
      return;
    }

    HandlerResult result =
        QuestEngine.getInstance().onItemUseEvent(new QuestEnv(null, player, 0, 0), item);
    if (result == HandlerResult.FAILED) return; // don't remove item

    ItemActions itemActions = item.getItemTemplate().getActions();
    ArrayList<AbstractItemAction> actions = new ArrayList<AbstractItemAction>();

    if (itemActions == null) {
      PacketSendUtility.sendPacket(player, SM_SYSTEM_MESSAGE.STR_ITEM_IS_NOT_USABLE);
      return;
    }

    for (AbstractItemAction itemAction : itemActions.getItemActions()) {
      // check if the item can be used before placing it on the cooldown list.
      if (targetHouseObject != null && itemAction instanceof IHouseObjectDyeAction) {
        IHouseObjectDyeAction action = (IHouseObjectDyeAction) itemAction;
        if (action != null && action.canAct(player, item, targetHouseObject))
          actions.add(itemAction);
      } else if (itemAction.canAct(player, item, targetItem)) actions.add(itemAction);
    }

    if (actions.size() == 0) {
      PacketSendUtility.sendPacket(player, SM_SYSTEM_MESSAGE.STR_ITEM_IS_NOT_USABLE);
      return;
    }

    // Store Item CD in server Player variable.
    // Prevents potion spamming, and relogging to use kisks/aether jelly/long CD items.
    ItemUseLimits limits = item.getItemTemplate().getUseLimits();
    if (player.isItemUseDisabled(limits)) {
      PacketSendUtility.sendPacket(player, SM_SYSTEM_MESSAGE.STR_ITEM_CANT_USE_UNTIL_DELAY_TIME);
      return;
    }

    if (limits.getGenderPermitted() != null && limits.getGenderPermitted() != player.getGender()) {
      PacketSendUtility.sendPacket(player, SM_SYSTEM_MESSAGE.STR_CANNOT_USE_ITEM_INVALID_GENDER);
      return;
    }
    int useDelay = player.getItemCooldown(item.getItemTemplate());
    if (useDelay > 0) {
      player.addItemCoolDown(
          item.getItemTemplate().getUseLimits().getDelayId(),
          System.currentTimeMillis() + useDelay,
          useDelay / 1000);
    }

    // notify item use observer
    player.getObserveController().notifyItemuseObservers(item);

    for (AbstractItemAction itemAction : actions) {
      if (targetHouseObject != null && itemAction instanceof IHouseObjectDyeAction) {
        IHouseObjectDyeAction action = (IHouseObjectDyeAction) itemAction;
        action.act(player, item, targetHouseObject);
      } else if (type == 6) {

        // Multi Returns Items (Scroll Teleporter)
        if (itemAction instanceof MultiReturnAction) {
          MultiReturnAction action = (MultiReturnAction) itemAction;
          int SelectedMapIndex = returnId;
          action.act(player, item, SelectedMapIndex);
        }
      } else {
        itemAction.act(player, item, targetItem);
      }
    }
    PacketSendUtility.sendPacket(
        player,
        SM_SYSTEM_MESSAGE.STR_USE_ITEM(new DescriptionId(item.getItemTemplate().getNameId())));
  }
  /**
   * @param item
   * @param cgs
   */
  public static void onItemEquipment(Item item, Player owner) {
    owner.getController().cancelUseItem();
    ItemTemplate itemTemplate = item.getItemTemplate();

    onItemEquipment(item, owner.getGameStats());

    // Check if belongs to ItemSet
    if (itemTemplate.isItemSet()) {
      recalculateItemSet(itemTemplate.getItemSet(), owner, item.getItemTemplate().isWeapon());
    }
    if (item.hasManaStones()) addStonesStats(item, item.getItemStones(), owner.getGameStats());

    if (item.hasFusionStones()) addStonesStats(item, item.getFusionStones(), owner.getGameStats());
    IdianStone idianStone = item.getIdianStone();

    if (idianStone != null
        && (owner.getEquipment().getOffHandWeapon() != item
            || item.getItemTemplate().isTwoHandWeapon())) {
      idianStone.onEquip(owner);
    }
    addGodstoneEffect(owner, item);
    RandomStats randomStats = item.getRandomStats();
    if (randomStats != null) {
      randomStats.onEquip(owner);
    }
    if (item.getConditioningInfo() != null) {
      owner.getObserveController().addObserver(item.getConditioningInfo());
      item.getConditioningInfo().setPlayer(owner);
    }
    if (item.getItemTemplate().isStigma()) StigmaService.recheckHiddenStigma(owner);
    EnchantService.onItemEquip(owner, item);
  }
 /** @param item */
 private static void removeGodstoneEffect(Player player, Item item) {
   if (item.getGodStone() != null) {
     item.getGodStone().onUnEquip(player);
   }
 }
  /**
   * @param item
   * @param owner
   */
  public static void onItemUnequipment(Item item, Player owner) {
    owner.getController().cancelUseItem();

    ItemTemplate itemTemplate = item.getItemTemplate();
    // Check if belongs to ItemSet
    if (itemTemplate.isItemSet()) {
      recalculateItemSet(itemTemplate.getItemSet(), owner, item.getItemTemplate().isWeapon());
    }

    owner.getGameStats().endEffect(item);

    if (item.hasManaStones()) removeStoneStats(item.getItemStones(), owner.getGameStats());

    if (item.hasFusionStones()) removeStoneStats(item.getFusionStones(), owner.getGameStats());

    if (item.getConditioningInfo() != null) {
      owner.getObserveController().removeObserver(item.getConditioningInfo());
      item.getConditioningInfo().setPlayer(null);
    }
    IdianStone idianStone = item.getIdianStone();
    if (idianStone != null) {
      idianStone.onUnEquip(owner);
    }
    removeGodstoneEffect(owner, item);
    RandomStats randomStats = item.getRandomStats();

    if (randomStats != null) {
      randomStats.onUnEquip(owner);
    }
  }