Пример #1
0
  @Override
  public void act(Player player, Item parentItem, Item targetItem) {
    if (!player.getInventory().decreaseByObjectId(parentItem.getObjectId(), 1)) {
      return;
    }
    if (targetItem.getItemSkinTemplate().isItemDyePermitted()) {
      if (getColorBGRA() == 0) {
        targetItem.setItemColor(0);
        targetItem.setColorExpireTime(0);
      } else {
        targetItem.setItemColor(parentItem.getItemTemplate().getTemplateId());
        if (minutes != null) {
          targetItem.setColorExpireTime((int) (System.currentTimeMillis() / 1000 + minutes * 60));
        }
      }

      // item is equipped, so need broadcast packet
      if (player.getEquipment().getEquippedItemByObjId(targetItem.getObjectId()) != null) {
        PacketSendUtility.broadcastPacket(
            player,
            new SM_UPDATE_PLAYER_APPEARANCE(
                player.getObjectId(), player.getEquipment().getEquippedForApparence()),
            true);
        player.getEquipment().setPersistentState(PersistentState.UPDATE_REQUIRED);
      } // item is not equipped
      else {
        player.getInventory().setPersistentState(PersistentState.UPDATE_REQUIRED);
      }

      ItemPacketService.updateItemAfterInfoChange(player, targetItem);
    }
  }
Пример #2
0
  public void moveItem(
      Player player, int itemObjId, int sourceStorageType, int destinationStorageType, int slot) {
    Storage sourceStorage = player.getStorage(sourceStorageType);
    Item item = player.getStorage(sourceStorageType).getItemByObjId(itemObjId);

    if (item == null) return;

    item.setEquipmentSlot(slot);

    if (sourceStorageType == destinationStorageType) return;

    Storage destinationStorage = player.getStorage(destinationStorageType);
    List<Item> existingItems =
        destinationStorage.getItemsByItemId(item.getItemTemplate().getTemplateId());

    int count = item.getItemCount();
    int maxStackCount = item.getItemTemplate().getMaxStackCount();

    for (Item existingItem : existingItems) {
      if (count == 0) break;

      int freeCount = maxStackCount - existingItem.getItemCount();
      if (count <= freeCount) {
        existingItem.increaseItemCount(count);
        count = 0;
        sendDeleteItemPacket(player, sourceStorageType, item.getObjectId());
        sourceStorage.removeFromBag(item, true);

      } else {
        existingItem.increaseItemCount(freeCount);
        count -= freeCount;
      }
      sendStorageUpdatePacket(player, destinationStorageType, existingItem);
    }

    while (!destinationStorage.isFull() && count > 0) {
      // item count still more than maxStack value
      if (count > maxStackCount) {
        count -= maxStackCount;
        Item newitem = newItem(item.getItemTemplate().getTemplateId(), maxStackCount);
        newitem = destinationStorage.putToBag(newitem);
        sendStorageUpdatePacket(player, destinationStorageType, newitem);

      } else {
        item.setItemCount(count);
        sourceStorage.removeFromBag(item, false);
        sendDeleteItemPacket(player, sourceStorageType, item.getObjectId());
        Item newitem = destinationStorage.putToBag(item);
        sendStorageUpdatePacket(player, destinationStorageType, newitem);

        count = 0;
      }
    }

    if (count > 0) // if storage is full and some items left
    {
      item.setItemCount(count);
      sendUpdateItemPacket(player, sourceStorageType, item);
    }
  }
Пример #3
0
 private void removeStigma(QuestEnv env) {
   Player player = env.getPlayer();
   for (Item item : player.getEquipment().getEquippedItemsByItemId(getStoneId(player))) {
     player.getEquipment().unEquipItem(item.getObjectId(), 0);
   }
   removeQuestItem(env, getStoneId(player), 1);
 }
Пример #4
0
 @Override
 public void act(Player player, Item parentItem, HouseObject<?> targetHouseObject) {
   if (!player.getInventory().decreaseByObjectId(parentItem.getObjectId(), 1)) {
     return;
   }
   if (color.equals("no")) {
     targetHouseObject.setColor(null);
   } else {
     targetHouseObject.setColor(Integer.parseInt(color, 16));
   }
   float x = targetHouseObject.getX();
   float y = targetHouseObject.getY();
   float z = targetHouseObject.getZ();
   int rotation = targetHouseObject.getRotation();
   PacketSendUtility.sendPacket(player, new SM_HOUSE_EDIT(7, 0, targetHouseObject.getObjectId()));
   PacketSendUtility.sendPacket(
       player, new SM_HOUSE_EDIT(5, targetHouseObject.getObjectId(), x, y, z, rotation));
   targetHouseObject.spawn();
   int objectName = targetHouseObject.getObjectTemplate().getNameId();
   if (color.equals("no")) {
     PacketSendUtility.sendPacket(
         player, SM_SYSTEM_MESSAGE.STR_MSG_ITEM_PAINT_REMOVE_SUCCEED(objectName));
   } else {
     int paintName = parentItem.getItemTemplate().getNameId();
     PacketSendUtility.sendPacket(
         player, SM_SYSTEM_MESSAGE.STR_MSG_ITEM_PAINT_SUCCEED(objectName, paintName));
   }
 }
  @Override
  public HandlerResult onItemUseEvent(final QuestEnv env, Item item) {
    final Player player = env.getPlayer();
    final int itemObjId = item.getObjectId();
    final int id = item.getItemTemplate().getTemplateId();
    QuestState qs = player.getQuestStateList().getQuestState(questId);

    if (id != 182201765) {
      return HandlerResult.UNKNOWN;
    }

    if (qs != null) {
      if (qs.getStatus() == QuestStatus.COMPLETE) {
        removeQuestItem(env, 182201765, 1);
        return HandlerResult.FAILED;
      }
    }

    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;
  }
  @Override
  public HandlerResult onItemUseEvent(final QuestEnv env, Item item) {
    final Player player = env.getPlayer();
    final QuestState qs = player.getQuestStateList().getQuestState(questId);
    final int id = item.getItemTemplate().getTemplateId();
    final int itemObjId = item.getObjectId();

    if (id != 182206726) {
      return HandlerResult.UNKNOWN;
    }
    PacketSendUtility.broadcastPacket(
        player, new SM_ITEM_USAGE_ANIMATION(player.getObjectId(), itemObjId, id, 1000, 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);
                removeQuestItem(env, 182206726, 1);
                qs.setStatus(QuestStatus.REWARD);
                updateQuestStatus(env);
              }
            },
            1000);
    return HandlerResult.SUCCESS;
  }
  @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 != 182204123) {
      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;
  }
Пример #8
0
  @Override
  public boolean onItemUseEvent(QuestEnv env, Item item) {
    final Player player = env.getPlayer();
    final int id = item.getItemTemplate().getTemplateId();
    final int itemObjId = item.getObjectId();

    if (id != 182200007) return false;
    if (!zoneService.isInsideZone(player, ZoneName.ITEMUSE_Q1006)) return false;
    final QuestState qs = player.getQuestStateList().getQuestState(questId);
    if (qs == null) return false;
    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);
                player.getInventory().removeFromBagByObjectId(itemObjId, 1);
                itemService.addItems(
                    player, Collections.singletonList(new QuestItems(182200008, 1)));
                qs.setQuestVarById(0, 2);
                updateQuestStatus(player, qs);
              }
            },
            3000);
    return true;
  }
Пример #9
0
 /**
  * @param itemObjId
  * @return Item
  */
 public Item getItemFromStorageByItemObjId(int itemObjId) {
   for (Item item : storageItems) {
     if (item.getObjectId() == itemObjId) {
       return item;
     }
   }
   return null;
 }
Пример #10
0
  /**
   * @param objId
   * @return int
   */
  public int getSlotIdByObjId(int objId) {
    for (Item item : storageItems) {
      if (item.getObjectId() == objId) {
        return item.getEquipmentSlot();
      }
    }

    return -1;
  }
Пример #11
0
  // necessary overloading to not change AbstractItemAction
  public void act(
      final Player player,
      final Item parentItem,
      final Item targetItem,
      final Item supplementItem) {
    PacketSendUtility.sendPacket(
        player,
        new SM_ITEM_USAGE_ANIMATION(
            player.getObjectId(),
            parentItem.getObjectId(),
            parentItem.getItemTemplate().getTemplateId(),
            5000,
            0,
            0));
    player.cancelTask(TaskId.ITEM_USE);
    player.addNewTask(
        TaskId.ITEM_USE,
        ThreadPoolManager.getInstance()
            .schedule(
                new Runnable() {
                  @Override
                  public void run() {

                    int itemId = parentItem.getItemTemplate().getTemplateId();
                    if (itemId > 166000000 && itemId < 167000000) {
                      boolean result =
                          EnchantService.enchantItem(
                              player, parentItem, targetItem, supplementItem);
                      PacketSendUtility.sendPacket(
                          player,
                          new SM_ITEM_USAGE_ANIMATION(
                              player.getObjectId(),
                              parentItem.getObjectId(),
                              parentItem.getItemTemplate().getTemplateId(),
                              0,
                              result ? 1 : 2,
                              0));
                    } else {
                      boolean result =
                          EnchantService.socketManastone(
                              player, parentItem, targetItem, supplementItem);
                      PacketSendUtility.sendPacket(
                          player,
                          new SM_ITEM_USAGE_ANIMATION(
                              player.getObjectId(),
                              parentItem.getObjectId(),
                              parentItem.getItemTemplate().getTemplateId(),
                              0,
                              result ? 1 : 2,
                              0));
                    }
                  }
                },
                5000));
  }
  @Override
  public void act(Player player, Item parentItem, Item targetItem) {
    if (!player.getInventory().decreaseByObjectId(parentItem.getObjectId(), 1)) {
      return;
    }
    ItemTemplate itemTemplate = parentItem.getItemTemplate();
    PacketSendUtility.broadcastPacket(
        player,
        new SM_ITEM_USAGE_ANIMATION(
            player.getObjectId(), parentItem.getObjectId(), itemTemplate.getTemplateId()),
        true);

    switch (storage) {
      case CUBE:
        CubeExpandService.expand(player, false);
        break;
      case WAREHOUSE:
        WarehouseService.expand(player);
        break;
    }
  }
Пример #13
0
  @Override
  public boolean onItemUseEvent(QuestEnv env, Item item) {
    final Player player = env.getPlayer();
    final int id = item.getItemTemplate().getTemplateId();
    final int itemObjId = item.getObjectId();

    final QuestState qs = player.getQuestStateList().getQuestState(questId);
    if (qs != null && qs.getStatus() != QuestStatus.NONE) return false;
    if (id != 182200214) return false;

    PacketSendUtility.broadcastPacket(
        player, new SM_ITEM_USAGE_ANIMATION(player.getObjectId(), itemObjId, id, 20, 1, 0), true);
    sendQuestDialog(player, 0, 4);

    return true;
  }
Пример #14
0
  /**
   * Used to split item into 2 items
   *
   * @param player
   * @param itemObjId
   * @param splitAmount
   * @param slotNum
   * @param sourceStorageType
   * @param desetinationStorageType
   */
  public void splitItem(
      Player player,
      int itemObjId,
      int splitAmount,
      int slotNum,
      int sourceStorageType,
      int destinationStorageType) {
    Storage sourceStorage = player.getStorage(sourceStorageType);
    Storage destinationStorage = player.getStorage(destinationStorageType);

    Item itemToSplit = sourceStorage.getItemByObjId(itemObjId);
    if (itemToSplit == null) {
      itemToSplit = sourceStorage.getKinahItem();
      if (itemToSplit.getObjectId() != itemObjId || itemToSplit == null) {
        log.warn(
            String.format(
                "CHECKPOINT: attempt to split null item %d %d %d",
                itemObjId, splitAmount, slotNum));
        return;
      }
    }

    // To move kinah from inventory to warehouse and vise versa client using split item packet
    if (itemToSplit.getItemTemplate().isKinah()) {
      moveKinah(player, sourceStorage, splitAmount);
      return;
    }

    int oldItemCount = itemToSplit.getItemCount() - splitAmount;

    if (itemToSplit.getItemCount() < splitAmount || oldItemCount == 0) return;

    Item newItem = newItem(itemToSplit.getItemTemplate().getTemplateId(), splitAmount);
    newItem.setEquipmentSlot(slotNum);
    if (destinationStorage.putToBag(newItem) != null) {
      itemToSplit.decreaseItemCount(splitAmount);

      List<Item> itemsToUpdate = new ArrayList<Item>();
      itemsToUpdate.add(newItem);

      sendStorageUpdatePacket(player, destinationStorageType, itemsToUpdate.get(0));

      sendUpdateItemPacket(player, sourceStorageType, itemToSplit);
    } else {
      releaseItemId(newItem);
    }
  }
Пример #15
0
  /**
   * Loads item stones from DB for each item in a list if item is ARMOR or WEAPON
   *
   * @param itemList
   */
  public void loadItemStones(Player player) {
    List<Item> itemList = new ArrayList<Item>();
    itemList.addAll(player.getStorage(StorageType.CUBE.getId()).getStorageItems());
    itemList.addAll(player.getStorage(StorageType.REGULAR_WAREHOUSE.getId()).getStorageItems());
    itemList.addAll(player.getStorage(StorageType.ACCOUNT_WAREHOUSE.getId()).getStorageItems());
    itemList.addAll(player.getEquipment().getEquippedItems());

    for (Item item : itemList) {
      if (item.getItemTemplate().isArmor() || item.getItemTemplate().isWeapon()) {
        item.setItemStones(DAOManager.getDAO(ItemStoneListDAO.class).load(item.getObjectId()));

        // if item equipped - apply stats of item stone
        if (item.isEquipped()
            && item.getEquipmentSlot() != ItemSlot.MAIN_OFF_HAND.getSlotIdMask()
            && item.getEquipmentSlot() != ItemSlot.SUB_OFF_HAND.getSlotIdMask()) {
          for (ItemStone itemStone : item.getItemStones()) {
            ItemEquipmentListener.addStoneStats(itemStone, player.getGameStats());
          }
        }
      }
    }
  }
Пример #16
0
  /**
   * Used to merge 2 items in inventory
   *
   * @param player
   * @param sourceItemObjId
   * @param itemAmount
   * @param destinationObjId
   */
  public void mergeItems(
      Player player,
      int sourceItemObjId,
      int itemAmount,
      int destinationObjId,
      int sourceStorageType,
      int destinationStorageType) {
    if (itemAmount == 0) return;

    Storage sourceStorage = player.getStorage(sourceStorageType);
    Storage destinationStorage = player.getStorage(destinationStorageType);

    Item sourceItem = sourceStorage.getItemByObjId(sourceItemObjId);
    Item destinationItem = destinationStorage.getItemByObjId(destinationObjId);

    if (sourceItem == null || destinationItem == null) return; // Invalid object id provided

    if (sourceItem.getItemTemplate().getTemplateId()
        != destinationItem.getItemTemplate().getTemplateId()) return; // Invalid item type

    if (sourceItem.getItemCount() < itemAmount) return; // Invalid item amount

    if (sourceItem.getItemCount() == itemAmount) {
      destinationItem.increaseItemCount(itemAmount);
      sourceStorage.removeFromBag(sourceItem, true);

      sendDeleteItemPacket(player, sourceStorageType, sourceItem.getObjectId());

      sendUpdateItemPacket(player, destinationStorageType, destinationItem);

    } else if (sourceItem.getItemCount() > itemAmount) {
      sourceItem.decreaseItemCount(itemAmount);
      destinationItem.increaseItemCount(itemAmount);

      sendUpdateItemPacket(player, sourceStorageType, sourceItem);

      sendUpdateItemPacket(player, destinationStorageType, destinationItem);
    } else return; // cant happen in theory, but...
  }
  @Override
  public boolean onItemUseEvent(QuestEnv env, Item item) {
    final Player player = env.getPlayer();
    final int id = item.getItemTemplate().getTemplateId();
    final int itemObjId = item.getObjectId();

    if (id != 182200501) return false;
    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(player, 0, 4);
              }
            },
            3000);
    return true;
  }
Пример #18
0
  /** Apply effects and perform actions specified in skill template */
  protected void endCast() {
    if (!effector.isCasting() || isCancelled) return;

    // if target out of range
    if (skillTemplate == null) return;

    // Check if target is out of skill range
    Properties properties = skillTemplate.getProperties();
    if (properties != null && !properties.endCastValidate(this)) {
      effector.getController().cancelCurrentSkill();
      return;
    }

    if (!validateEffectedList()) {
      effector.getController().cancelCurrentSkill();
      return;
    }

    if (!preUsageCheck()) {
      return;
    }

    effector.setCasting(null);

    if (this.getSkillTemplate().isDeityAvatar() && effector instanceof Player) {
      AbyssService.rankerSkillAnnounce((Player) effector, this.getSkillTemplate().getNameId());
    }

    /** try removing item, if its not possible return to prevent exploits */
    if (effector instanceof Player && skillMethod == SkillMethod.ITEM) {
      Item item = ((Player) effector).getInventory().getItemByObjId(this.itemObjectId);
      if (item == null) return;
      if (item.getActivationCount() > 1) {
        item.setActivationCount(item.getActivationCount() - 1);
      } else {
        if (!((Player) effector)
            .getInventory()
            .decreaseByObjectId(item.getObjectId(), 1, ItemUpdateType.DEC_USE)) return;
      }
    }
    /** Create effects and precalculate result */
    int spellStatus = 0;
    int dashStatus = 0;
    int resistCount = 0;
    boolean blockedChain = false;
    boolean blockedStance = false;
    final List<Effect> effects = new ArrayList<Effect>();
    if (skillTemplate.getEffects() != null) {
      boolean blockAOESpread = false;
      for (Creature effected : effectedList) {
        Effect effect = new Effect(this, effected, 0, itemTemplate);
        if (effected instanceof Player) {
          if (effect.getEffectResult() == EffectResult.CONFLICT) blockedStance = true;
        }
        // Force RESIST status if AOE spell spread must be blocked
        if (blockAOESpread) effect.setAttackStatus(AttackStatus.RESIST);
        effect.initialize();
        final int worldId = effector.getWorldId();
        final int instanceId = effector.getInstanceId();
        effect.setWorldPosition(worldId, instanceId, x, y, z);

        effects.add(effect);
        spellStatus = effect.getSpellStatus().getId();
        dashStatus = effect.getDashStatus().getId();

        // Block AOE propagation if firstTarget resists the spell
        if ((!blockAOESpread)
            && (effect.getAttackStatus() == AttackStatus.RESIST)
            && (isTargetAOE())) blockAOESpread = true;

        if (effect.getAttackStatus() == AttackStatus.RESIST
            || effect.getAttackStatus() == AttackStatus.DODGE) {
          resistCount++;
        }
      }

      if (resistCount == effectedList.size()) {
        blockedChain = true;
        blockedPenaltySkill = true;
      }

      // exception for point point skills(example Ice Sheet)
      if (effectedList.isEmpty() && this.isPointPointSkill()) {
        Effect effect = new Effect(this, null, 0, itemTemplate);
        effect.initialize();
        final int worldId = effector.getWorldId();
        final int instanceId = effector.getInstanceId();
        effect.setWorldPosition(worldId, instanceId, x, y, z);
        effects.add(effect);
        spellStatus = effect.getSpellStatus().getId();
      }
    }

    if (effector instanceof Player && skillMethod == SkillMethod.CAST) {
      Player playerEffector = (Player) effector;
      if (playerEffector.getController().isUnderStance()) {
        playerEffector.getController().stopStance();
      }
      if (skillTemplate.isStance() && !blockedStance) {
        playerEffector.getController().startStance(skillTemplate.getSkillId());
      }
    }

    boolean setCooldowns = true;
    if (effector instanceof Player) {
      if (this.isMulticast()
          && ((Player) effector)
                  .getChainSkills()
                  .getChainCount((Player) effector, this.getSkillTemplate(), this.chainCategory)
              != 0) {
        setCooldowns = false;
      }
    }

    // Check Chain Skill Trigger Rate
    if (CustomConfig.SKILL_CHAIN_TRIGGERRATE) {
      int chainProb = skillTemplate.getChainSkillProb();
      if (this.chainCategory != null && !blockedChain) {
        this.chainSuccess = Rnd.get(90) < chainProb;
      }
    } else {
      this.chainSuccess = true;
    }

    /** set variables for chaincondition check */
    if (effector instanceof Player && this.chainSuccess && this.chainCategory != null) {
      ((Player) effector).getChainSkills().addChainSkill(this.chainCategory, this.isMulticast());
    }

    /** Perform necessary actions (use mp,dp items etc) */
    Actions skillActions = skillTemplate.getActions();
    if (skillActions != null) {
      for (Action action : skillActions.getActions()) {
        if (!action.act(this)) return;
      }
    }

    if (effector instanceof Player) {
      QuestEnv env = new QuestEnv(effector.getTarget(), (Player) effector, 0, 0);
      QuestEngine.getInstance().onUseSkill(env, skillTemplate.getSkillId());
    }

    if (setCooldowns) this.setCooldowns();

    if (hitTime == 0) applyEffect(effects);
    else {
      ThreadPoolManager.getInstance()
          .schedule(
              new Runnable() {

                @Override
                public void run() {
                  applyEffect(effects);
                }
              },
              hitTime);
    }
    if (skillMethod == SkillMethod.CAST
        || skillMethod == SkillMethod.ITEM
        || skillMethod == SkillMethod.CHARGE) sendCastspellEnd(spellStatus, dashStatus, effects);

    endCondCheck();

    if (effector instanceof Npc)
      SkillAttackManager.afterUseSkill((NpcAI2) ((Npc) effector).getAi2());
  }
Пример #19
0
 /**
  * Releases item id if item was not used by caller
  *
  * @param item
  */
 public void releaseItemId(Item item) {
   aionObjectsIDFactory.releaseId(item.getObjectId());
 }