示例#1
0
  public ManaStone(int itemObjId, int itemId, int slot, PersistentState persistentState) {
    super(itemObjId, itemId, slot, ItemStoneType.MANASTONE, persistentState);

    ItemTemplate stoneTemplate = DataManager.ITEM_DATA.getItemTemplate(itemId);
    if (stoneTemplate != null && stoneTemplate.getModifiers() != null) {
      this.modifiers = stoneTemplate.getModifiers();
    }
  }
示例#2
0
  /**
   * @param itemId
   * @param itemUniqueId
   * @param count
   * @param isEquipped
   * @param slot
   * @return Loads Item instance with specified itemUniqueId
   */
  public Item loadItem(int itemId, int itemUniqueId, int count, boolean isEquipped, int slot) {
    ItemTemplate itemTemplate = DataManager.ITEM_DATA.getItemTemplate(itemId);
    if (itemTemplate == null) {
      log.error(
          "Item was not populated correctly. Item template is missing for item id: " + itemId);
    }

    return new Item(itemUniqueId, itemTemplate, count, isEquipped, slot);
  }
示例#3
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;
    }
  }
示例#4
0
 @Override
 public boolean act(Skill skill) {
   if (skill.getEffector() instanceof Player) {
     ItemTemplate item = DataManager.ITEM_DATA.getItemTemplate(itemid);
     Player player = (Player) skill.getEffector();
     Storage inventory = player.getInventory();
     if (!inventory.decreaseByItemId(itemid, count)) {
       PacketSendUtility.sendPacket(
           player,
           SM_SYSTEM_MESSAGE.STR_SKILL_NOT_ENOUGH_ITEM(new DescriptionId(item.getNameId())));
       return false;
     }
   }
   return true;
 }
示例#5
0
  /**
   * @param itemId
   * @param count
   * @return Creates new Item instance. If count is greater than template maxStackCount, count value
   *     will be cut to maximum allowed This method will return null if ItemTemplate for itemId was
   *     not found.
   */
  public Item newItem(int itemId, int count) {
    ItemTemplate itemTemplate = DataManager.ITEM_DATA.getItemTemplate(itemId);
    if (itemTemplate == null) {
      log.error(
          "Item was not populated correctly. Item template is missing for item id: " + itemId);
      return null;
    }

    int maxStackCount = itemTemplate.getMaxStackCount();
    if (count > maxStackCount && maxStackCount != 0) {
      count = maxStackCount;
    }

    // TODO if Item object will contain ownerId - item can be saved to DB before return
    return new Item(aionObjectsIDFactory.nextId(), itemTemplate, count, false, 0);
  }
示例#6
0
文件: Add.java 项目: soulxj/aion-cn
  @Override
  public void execute(Player player, String... params) {
    if ((params.length < 0) || (params.length < 1)) {
      onFail(player, null);
      return;
    }
    int itemId = 0;
    long itemCount = 1;
    Player receiver;

    try {
      String item = params[0];
      // Some item links have space before Id
      if (item.equals("[item:")) {
        item = params[1];
        Pattern id = Pattern.compile("(\\d{9})");
        Matcher result = id.matcher(item);
        if (result.find()) itemId = Integer.parseInt(result.group(1));

        if (params.length == 3) itemCount = Long.parseLong(params[2]);
      } else {
        Pattern id = Pattern.compile("\\[item:(\\d{9})");
        Matcher result = id.matcher(item);

        if (result.find()) itemId = Integer.parseInt(result.group(1));
        else itemId = Integer.parseInt(params[0]);

        if (params.length == 2) itemCount = Long.parseLong(params[1]);
      }
      receiver = player;
    } catch (NumberFormatException e) {
      receiver = World.getInstance().findPlayer(Util.convertName(params[0]));
      if (receiver == null) {
        PacketSendUtility.sendMessage(player, "Could not find a player by that name.");
        return;
      }

      try {
        String item = params[1];
        // Some item links have space before Id
        if (item.equals("[item:")) {
          item = params[2];
          Pattern id = Pattern.compile("(\\d{9})");
          Matcher result = id.matcher(item);
          if (result.find()) itemId = Integer.parseInt(result.group(1));

          if (params.length == 4) itemCount = Long.parseLong(params[3]);
        } else {
          Pattern id = Pattern.compile("\\[item:(\\d{9})");
          Matcher result = id.matcher(item);

          if (result.find()) itemId = Integer.parseInt(result.group(1));
          else itemId = Integer.parseInt(params[1]);

          if (params.length == 3) itemCount = Long.parseLong(params[2]);
        }
      } catch (NumberFormatException ex) {
        PacketSendUtility.sendMessage(player, "You must give number to itemid.");
        return;
      } catch (Exception ex2) {
        PacketSendUtility.sendMessage(player, "Occurs an error.");
        return;
      }
    }

    if (DataManager.ITEM_DATA.getItemTemplate(itemId) == null) {
      PacketSendUtility.sendMessage(player, "Item id is incorrect: " + itemId);
      return;
    }

    if (!AdminService.getInstance().canOperate(player, receiver, itemId, "command //add")) return;

    long count = ItemService.addItem(receiver, itemId, itemCount);

    if (count == 0) {
      if (player != receiver) {
        PacketSendUtility.sendMessage(
            player,
            "You successfully gave "
                + itemCount
                + " x [item:"
                + itemId
                + "] to "
                + receiver.getName()
                + ".");
        PacketSendUtility.sendMessage(
            receiver,
            "You successfully received "
                + itemCount
                + " x [item:"
                + itemId
                + "] from "
                + player.getName()
                + ".");
      } else
        PacketSendUtility.sendMessage(
            player, "You successfully received " + itemCount + " x [item:" + itemId + "]");
    } else {
      PacketSendUtility.sendMessage(player, "Item couldn't be added");
    }
  }
  @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!");
    }
  }