@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));
   }
 }
Beispiel #2
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;
  }
 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);
 }
  @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;
  }
  @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;
  }
 /**
  * @param itemObjId
  * @return Item
  */
 public Item getItemFromStorageByItemObjId(int itemObjId) {
   for (Item item : storageItems) {
     if (item.getObjectId() == itemObjId) {
       return item;
     }
   }
   return null;
 }
 /**
  * @param itemId
  * @return int
  */
 public int getSlotIdByItemId(int itemId) {
   for (Item item : storageItems) {
     ItemTemplate itemTemplate = item.getItemTemplate();
     if (itemTemplate.getTemplateId() == itemId) {
       return item.getEquipmentSlot();
     }
   }
   return -1;
 }
  /**
   * @param objId
   * @return int
   */
  public int getSlotIdByObjId(int objId) {
    for (Item item : storageItems) {
      if (item.getObjectId() == objId) {
        return item.getEquipmentSlot();
      }
    }

    return -1;
  }
 private boolean isStigmaEquipped(QuestEnv env) {
   Player player = env.getPlayer();
   for (Item i : player.getEquipment().getEquippedItemsAllStigma()) {
     if (i.getItemId() == getStoneId(player)) {
       return true;
     }
   }
   return false;
 }
  /**
   * @param itemId
   * @return Item by itemId or null if there is no such item
   */
  public Item getItemFromStorageByItemId(int itemId) {
    for (Item item : storageItems) {
      ItemTemplate itemTemplate = item.getItemTemplate();
      if (itemTemplate.getTemplateId() == itemId) {
        return item;
      }
    }

    return null;
  }
  // 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));
  }
  /**
   * This method is used for creating new players
   *
   * @param playerCommonData
   * @param playerAppearance
   * @return Player
   */
  public static Player newPlayer(
      PlayerCommonData playerCommonData, PlayerAppearance playerAppearance) {
    PlayerInitialData playerInitialData = DataManager.PLAYER_INITIAL_DATA;
    LocationData ld = playerInitialData.getSpawnLocation(playerCommonData.getRace());

    WorldPosition position =
        World.getInstance()
            .createPosition(ld.getMapId(), ld.getX(), ld.getY(), ld.getZ(), ld.getHeading());
    playerCommonData.setPosition(position);

    Player newPlayer = new Player(new PlayerController(), playerCommonData, playerAppearance);

    // Starting skills
    SkillLearnService.addNewSkills(newPlayer, true);

    // Starting items
    PlayerCreationData playerCreationData =
        playerInitialData.getPlayerCreationData(playerCommonData.getPlayerClass());

    List<ItemType> items = playerCreationData.getItems();

    Storage playerInventory = new Storage(StorageType.CUBE);
    Storage regularWarehouse = new Storage(StorageType.REGULAR_WAREHOUSE);
    Storage accountWarehouse = new Storage(StorageType.ACCOUNT_WAREHOUSE);

    Equipment equipment = new Equipment(newPlayer);
    newPlayer.setStorage(playerInventory, StorageType.CUBE);
    newPlayer.setStorage(regularWarehouse, StorageType.REGULAR_WAREHOUSE);
    newPlayer.setStorage(accountWarehouse, StorageType.ACCOUNT_WAREHOUSE);
    newPlayer.setEquipment(equipment);
    newPlayer.setMailbox(new Mailbox());

    for (ItemType itemType : items) {
      int itemId = itemType.getTemplate().getTemplateId();
      Item item = ItemService.newItem(itemId, itemType.getCount());
      if (item == null) continue;

      // When creating new player - all equipment that has slot values will be equipped
      // Make sure you will not put into xml file more items than possible to equip.
      ItemTemplate itemTemplate = item.getItemTemplate();
      item.setOwnerId(newPlayer.getObjectId());
      if (itemTemplate.isArmor() || itemTemplate.isWeapon()) {
        item.setEquipped(true);
        List<ItemSlot> itemSlots = ItemSlot.getSlotsFor(itemTemplate.getItemSlot());
        item.setEquipmentSlot(itemSlots.get(0).getSlotIdMask());
        equipment.onLoadHandler(item);
      } else ItemService.onLoadHandler(newPlayer, newPlayer.getInventory(), item);
    }
    equipment.onLoadApplyEquipmentStats();
    /** Mark inventory and equipment as UPDATE_REQUIRED to be saved during character creation */
    playerInventory.setPersistentState(PersistentState.UPDATE_REQUIRED);
    equipment.setPersistentState(PersistentState.UPDATE_REQUIRED);
    return newPlayer;
  }
  /**
   * @param itemId
   * @return list of items with specified itemId
   */
  public List<Item> getItemsFromStorageByItemId(int itemId) {
    List<Item> itemList = new ArrayList<Item>();

    for (Item item : storageItems) {
      ItemTemplate itemTemplate = item.getItemTemplate();
      if (itemTemplate.getTemplateId() == itemId) {
        itemList.add(item);
      }
    }

    return itemList;
  }
  @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);
    }
  }
Beispiel #16
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;
  }
Beispiel #17
0
  /**
   * Adds item count to player inventory I moved this method to service cause right implementation
   * of it is critical to server operation and could cause starvation of object ids.
   *
   * <p>This packet will send necessary packets to client (initialize used only from quest engine
   *
   * @param player
   * @param itemId
   * @param count - amount of item that were not added to player's inventory
   */
  public int addItem(Player player, int itemId, int count, boolean isQuestItem) {
    Storage inventory = player.getInventory();

    ItemTemplate itemTemplate = DataManager.ITEM_DATA.getItemTemplate(itemId);
    if (itemTemplate == null) return count;

    int maxStackCount = itemTemplate.getMaxStackCount();

    if (itemId == ItemId.KINAH.value()) {
      inventory.increaseKinah(count);
      return 0;
    } else {
      /** Increase count of existing items */
      List<Item> existingItems =
          inventory.getAllItemsByItemId(
              itemId); // look for existing in equipment. need for power shards.
      for (Item existingItem : existingItems) {
        if (count == 0) break;

        int freeCount = maxStackCount - existingItem.getItemCount();
        if (count <= freeCount) {
          existingItem.increaseItemCount(count);
          count = 0;
        } else {
          existingItem.increaseItemCount(freeCount);
          count -= freeCount;
        }

        updateItem(player, existingItem, false);
      }

      /** Create new stacks */
      while (!inventory.isFull() && count > 0) {
        // item count still more than maxStack value
        if (count > maxStackCount) {
          Item item = newItem(itemId, maxStackCount);
          item.setQuest(isQuestItem);
          count -= maxStackCount;
          inventory.putToBag(item);
          updateItem(player, item, true);
        } else {
          Item item = newItem(itemId, count);
          item.setQuest(isQuestItem);
          inventory.putToBag(item);
          updateItem(player, item, true);
          count = 0;
        }
      }

      return count;
    }
  }
Beispiel #18
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);
    }
  }
  @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;
    }
  }
Beispiel #20
0
  public void switchStoragesItems(
      Player player,
      int sourceStorageType,
      int sourceItemObjId,
      int replaceStorageType,
      int replaceItemObjId) {
    Storage sourceStorage = player.getStorage(sourceStorageType);
    Storage replaceStorage = player.getStorage(replaceStorageType);

    Item sourceItem = sourceStorage.getItemByObjId(sourceItemObjId);
    if (sourceItem == null) return;

    Item replaceItem = replaceStorage.getItemByObjId(replaceItemObjId);
    if (replaceItem == null) return;

    int sourceSlot = sourceItem.getEquipmentSlot();
    int replaceSlot = replaceItem.getEquipmentSlot();

    sourceItem.setEquipmentSlot(replaceSlot);
    replaceItem.setEquipmentSlot(sourceSlot);

    sourceStorage.removeFromBag(sourceItem, false);
    replaceStorage.removeFromBag(replaceItem, false);

    Item newSourceItem = sourceStorage.putToBag(replaceItem);
    Item newReplaceItem = replaceStorage.putToBag(sourceItem);

    sendDeleteItemPacket(player, sourceStorageType, sourceItemObjId);
    sendStorageUpdatePacket(player, sourceStorageType, newSourceItem);

    sendDeleteItemPacket(player, replaceStorageType, replaceItemObjId);
    sendStorageUpdatePacket(player, replaceStorageType, newReplaceItem);
  }
  @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;
  }
Beispiel #22
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());
          }
        }
      }
    }
  }
  @Override
  protected void writeImpl(AionChannelHandler cHandler) {
    writeD(playerId);

    short mask = 0;
    for (Item item : items) {
      mask |= item.getEquipmentSlot();
    }

    writeH(mask);

    for (Item item : items) {
      writeD(item.getItemSkinTemplate().getTemplateId());
      GodStone godStone = item.getGodStone();
      writeD(godStone != null ? godStone.getItemId() : 0);
      writeD(item.getItemColor());
      writeH(0x00); // unk (0x00)
    }
  }
  public static int calculateMagicalAttackDamage(
      Creature attacker, Creature target, SkillElement element, boolean isMainHand) {
    Preconditions.checkNotNull(element, "Skill element should be NONE instead of null");
    Stat2 mAttack;

    if (isMainHand) {
      mAttack = attacker.getGameStats().getMainHandMAttack();
    } else {
      mAttack = attacker.getGameStats().getOffHandMAttack();
    }

    float resultDamage = mAttack.getCurrent();

    if (attacker instanceof Player) {
      Equipment equipment = ((Player) attacker).getEquipment();
      Item weapon = equipment.getMainHandWeapon();

      if (weapon != null) {
        WeaponStats weaponStat = weapon.getItemTemplate().getWeaponStats();
        if (weaponStat == null) {
          return 0;
        }
        int totalMin = weaponStat.getMinDamage();
        int totalMax = weaponStat.getMaxDamage();
        if (totalMax - totalMin < 1) {
          log.warn("Weapon stat MIN_MAX_DAMAGE resulted average zero in main-hand calculation");
          log.warn(
              "Weapon ID: "
                  + String.valueOf(
                      equipment.getMainHandWeapon().getItemTemplate().getTemplateId()));
          log.warn("MIN_DAMAGE = " + String.valueOf(totalMin));
          log.warn("MAX_DAMAGE = " + String.valueOf(totalMax));
        }
        float knowledge = attacker.getGameStats().getKnowledge().getCurrent() * 0.01f;
        int diff = Math.round((totalMax - totalMin) * knowledge / 2);
        resultDamage =
            mAttack.getBonus()
                + getMovementModifier(attacker, StatEnum.MAGICAL_ATTACK, mAttack.getBase());
        resultDamage += Rnd.get(-diff, diff);

        if (attacker.isInState(CreatureState.POWERSHARD)) {
          Item firstShard = equipment.getMainHandPowerShard();
          Item secondShard = equipment.getOffHandPowerShard();
          if (firstShard != null) {
            equipment.usePowerShard(firstShard, 1);
            resultDamage += firstShard.getItemTemplate().getWeaponBoost();
          }

          if (secondShard != null) {
            equipment.usePowerShard(secondShard, 1);
            resultDamage += secondShard.getItemTemplate().getWeaponBoost();
          }
        }
      }
    }

    if (element != SkillElement.NONE) {
      float elementalDef =
          getMovementModifier(
              target,
              SkillElement.getResistanceForElement(element),
              target.getGameStats().getMagicalDefenseFor(element));
      resultDamage = Math.round(resultDamage * (1 - elementalDef / 1300f));
    }

    if (resultDamage <= 0) {
      resultDamage = 1;
    }

    return Math.round(resultDamage);
  }
  /**
   * @param player
   * @param target
   * @param effectTemplate
   * @param skillDamages
   * @return Damage made to target (-hp value)
   */
  public static int calculatePhysicalAttackDamage(
      Creature attacker, Creature target, boolean isMainHand) {
    Stat2 pAttack;
    if (isMainHand) {
      pAttack = attacker.getGameStats().getMainHandPAttack();
    } else {
      pAttack = ((Player) attacker).getGameStats().getOffHandPAttack();
    }
    float resultDamage = pAttack.getCurrent();
    float baseDamage = pAttack.getBase();
    if (attacker instanceof Player) {
      Equipment equipment = ((Player) attacker).getEquipment();
      Item weapon;
      if (isMainHand) {
        weapon = equipment.getMainHandWeapon();
      } else {
        weapon = equipment.getOffHandWeapon();
      }

      if (weapon != null) {
        WeaponStats weaponStat = weapon.getItemTemplate().getWeaponStats();
        if (weaponStat == null) {
          return 0;
        }
        int totalMin = weaponStat.getMinDamage();
        int totalMax = weaponStat.getMaxDamage();
        if (totalMax - totalMin < 1) {
          log.warn("Weapon stat MIN_MAX_DAMAGE resulted average zero in main-hand calculation");
          log.warn(
              "Weapon ID: "
                  + String.valueOf(
                      equipment.getMainHandWeapon().getItemTemplate().getTemplateId()));
          log.warn("MIN_DAMAGE = " + String.valueOf(totalMin));
          log.warn("MAX_DAMAGE = " + String.valueOf(totalMax));
        }
        float power = attacker.getGameStats().getPower().getCurrent() * 0.01f;
        int diff = Math.round((totalMax - totalMin) * power / 2);
        resultDamage = pAttack.getBonus() + baseDamage;

        // adjust with value from WeaponDualEffect
        // it makes lower cap of damage lower, so damage is more random on offhand
        int negativeDiff = diff;
        if (!isMainHand) {
          negativeDiff =
              (int) Math.round((200 - ((Player) attacker).getDualEffectValue()) * 0.01 * diff);
        }

        resultDamage += Rnd.get(-negativeDiff, diff);

        // add powerShard damage
        if (attacker.isInState(CreatureState.POWERSHARD)) {
          Item firstShard;
          Item secondShard = null;
          if (isMainHand) {
            firstShard = equipment.getMainHandPowerShard();
            if (weapon.getItemTemplate().isTwoHandWeapon()) {
              secondShard = equipment.getOffHandPowerShard();
            }
          } else {
            firstShard = equipment.getOffHandPowerShard();
          }

          if (firstShard != null) {
            equipment.usePowerShard(firstShard, 1);
            resultDamage += firstShard.getItemTemplate().getWeaponBoost();
          }

          if (secondShard != null) {
            equipment.usePowerShard(secondShard, 1);
            resultDamage += secondShard.getItemTemplate().getWeaponBoost();
          }
        }
      } else { // if hand attack
        int totalMin = 16;
        int totalMax = 20;

        float power = attacker.getGameStats().getPower().getCurrent() * 0.01f;
        int diff = Math.round((totalMax - totalMin) * power / 2);
        resultDamage = pAttack.getBonus() + baseDamage;
        resultDamage += Rnd.get(-diff, diff);
      }
    } else {
      int rnd = (int) (resultDamage * 0.25);
      resultDamage += Rnd.get(-rnd, rnd);
    }

    // subtract defense
    float pDef =
        target.getGameStats().getPDef().getBonus()
            + getMovementModifier(
                target, StatEnum.PHYSICAL_DEFENSE, target.getGameStats().getPDef().getBase());
    resultDamage -= (pDef * 0.10f);

    if (resultDamage <= 0) {
      resultDamage = 1;
    }

    return Math.round(resultDamage);
  }
Beispiel #26
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());
  }
Beispiel #27
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...
  }
Beispiel #28
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);
    }
  }
Beispiel #29
0
 /**
  * Releases item id if item was not used by caller
  *
  * @param item
  */
 public void releaseItemId(Item item) {
   aionObjectsIDFactory.releaseId(item.getObjectId());
 }
  @Override
  public void execute(Player player, String... params) {
    if (params.length != 2) {
      PacketSendUtility.sendMessage(player, "syntax .reskin <Old Item> <New Item>");
      return;
    }

    @SuppressWarnings("unused")
    Player target = player;
    VisibleObject creature = player.getTarget();
    if (player.getTarget() instanceof Player) {
      target = (Player) creature;
    }

    int oldItemId = 0;
    int newItemId = 0;

    try {
      String item = params[0];

      if (item.startsWith("[item:")) {
        Pattern id = Pattern.compile("\\[item:(\\d{9})");
        Matcher result = id.matcher(item);

        if (result.find()) {
          oldItemId = Integer.parseInt(result.group(1));
        } else {
          oldItemId = Integer.parseInt(params[0]);
        }
        item = params[1];
        if (item.startsWith("[item:")) {
          id = Pattern.compile("\\[item:(\\d{9})");
          result = id.matcher(item);

          if (result.find()) {
            newItemId = Integer.parseInt(result.group(1));
          } else {
            newItemId = Integer.parseInt(params[0]);
          }
        } else {
          PacketSendUtility.sendMessage(player, "syntax .reskin <Old Item> <New Item>");
          return;
        }
      } else {
        PacketSendUtility.sendMessage(player, "syntax .reskin <Old Item> <New Item>");
        return;
      }
    } catch (NumberFormatException e) {
      PacketSendUtility.sendMessage(player, "syntax .reskin <Old Item> <New Item>");
      return;
    }

    Storage storage = player.getInventory();
    List<Item> oldItems = player.getInventory().getItemsByItemId(oldItemId);
    List<Item> newItems = player.getInventory().getItemsByItemId(newItemId);
    // Iterator Ancien Item
    Iterator<Item> oldIter = oldItems.iterator();
    Item oldItem = oldIter.next();
    // Iterator Nouveau Item
    Iterator<Item> newIter = newItems.iterator();
    Item newItem = newIter.next();
    // verification que l'ancien item est dans l'inventaire
    if (oldItems.isEmpty()) {
      PacketSendUtility.sendMessage(player, "You do not have this item in your inventory.");
      return;
    }
    // verification que les items sont du même type.
    if (newItem.getItemTemplate().isWeapon() && oldItem.getItemTemplate().isWeapon()) {
      if (newItem.getItemTemplate().getWeaponType() != oldItem.getItemTemplate().getWeaponType()) {
        PacketSendUtility.sendMessage(player, "You can not remodel different types of item.");
        return;
      }
    } else if (newItem.getItemTemplate().isArmor() && oldItem.getItemTemplate().isArmor()) {
      if (newItem.getItemTemplate().getItemSlot() == oldItem.getItemTemplate().getItemSlot()) {
        if (newItem.getItemTemplate().getArmorType() != oldItem.getItemTemplate().getArmorType()) {
          PacketSendUtility.sendMessage(player, "You can not remodel different types of item.");
          return;
        }
      } else {
        PacketSendUtility.sendMessage(player, "You can not remodel different types of item.");
        return;
      }
    }

    final int tollPrice = 750;
    final long tolls = player.getClientConnection().getAccount().getToll();
    RequestResponseHandler responseHandler =
        new RequestResponseHandler(player) {
          @Override
          public void acceptRequest(Creature p2, Player p) {
            if (tolls < tollPrice) {
              PacketSendUtility.sendMessage(
                  p,
                  "You don't have enought Vote Points ("
                      + tolls
                      + "). You need : "
                      + tollPrice
                      + " Vote Points.");
              return;
            }
            p.getClientConnection().getAccount().setToll(tolls - tollPrice);
          }

          @Override
          public void denyRequest(Creature p2, Player p) {}
        };

    boolean requested = player.getResponseRequester().putRequest(902247, responseHandler);
    if (requested) {
      oldItem.setItemSkinTemplate(DataManager.ITEM_DATA.getItemTemplate(newItemId));
      storage.decreaseByItemId(newItemId, storage.getItemCountByItemId(newItemId));
      PacketSendUtility.sendBrightYellowMessage(
          player,
          "Your item " + params[0] + " just take the appearance of the item " + params[1] + ".");
      PacketSendUtility.sendMessage(
          player, "For changing the skin, you have use " + tollPrice + " Vote Points!");
    }
  }