Example #1
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);
    }
  }
Example #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;
  }
  @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 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);
    }
  }
 @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 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 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;
  }
Example #8
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);
    }
  }
 /**
  * @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 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;
  }
Example #14
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...
  }
Example #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());
          }
        }
      }
    }
  }
Example #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;
  }
  @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;
    }
  }
  @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;
  }
  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);
  }
  @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!");
    }
  }