/** {@inheritDoc} dc */
  @Override
  protected void writeImpl(AionConnection con, ByteBuffer buf) {
    writeH(
        buf,
        mode); // Drop to storage animation (bit mask). 1 - min animation; 17 - Like "Drop" to inv
    // without message in chat; 25 - full anim with surrounding "new" border and message
    // in chat
    writeH(buf, size); // number of entries
    for (Item item : items) {
      writeGeneralInfo(buf, item);

      ItemTemplate itemTemplate = item.getItemTemplate();

      if (itemTemplate.getTemplateId() == ItemId.KINAH.value()) {
        writeKinah(buf, item);
        writeC(buf, 0);
      } else if (itemTemplate.isWeapon()) {
        writeWeaponInfo(buf, item);
        writeH(buf, item.isEquipped() ? 255 : item.getEquipmentSlot());
        writeC(buf, 0);
      } else if (itemTemplate.isArmor()) {
        writeArmorInfo(buf, item);
        writeH(buf, item.isEquipped() ? 255 : item.getEquipmentSlot());
        writeC(buf, 0);
      } else if (itemTemplate.isStigma()) {
        writeStigmaInfo(buf, item);
      } else {
        writeGeneralItemInfo(buf, item);
        writeH(buf, item.isEquipped() ? 255 : item.getEquipmentSlot());
        writeC(buf, 0);
      }
    }
  }
Exemple #2
0
  /**
   * This method is used for creating new players
   *
   * @param playerCommonData
   * @param playerAppearance
   * @param account
   * @return Player
   */
  public static Player newPlayer(
      PlayerCommonData playerCommonData, PlayerAppearance playerAppearance, Account account) {
    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(), 0);
    playerCommonData.setPosition(position);

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

    // Starting skills
    newPlayer.setSkillList(new PlayerSkillList());
    SkillLearnService.addNewSkills(newPlayer);

    // Starting items
    PlayerCreationData playerCreationData =
        playerInitialData.getPlayerCreationData(playerCommonData.getPlayerClass());
    Storage playerInventory = new PlayerStorage(StorageType.CUBE);
    Storage regularWarehouse = new PlayerStorage(StorageType.REGULAR_WAREHOUSE);
    Storage accountWarehouse = new PlayerStorage(StorageType.ACCOUNT_WAREHOUSE);
    Equipment equipment = new Equipment(newPlayer);
    if (playerCreationData != null) { // player transfer
      List<ItemType> items = playerCreationData.getItems();
      for (ItemType itemType : items) {
        int itemId = itemType.getTemplate().getTemplateId();
        Item item = ItemFactory.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();

        if ((itemTemplate.isArmor() || itemTemplate.isWeapon())
            && !(equipment.isSlotEquipped(itemTemplate.getItemSlot()))) {
          item.setEquipped(true);
          ItemSlot[] itemSlots = ItemSlot.getSlotsFor(itemTemplate.getItemSlot());
          item.setEquipmentSlot(itemSlots[0].getSlotIdMask());
          equipment.onLoadHandler(item);
        } else playerInventory.onLoadHandler(item);
      }
    }
    newPlayer.setStorage(playerInventory, StorageType.CUBE);
    newPlayer.setStorage(regularWarehouse, StorageType.REGULAR_WAREHOUSE);
    newPlayer.setStorage(accountWarehouse, StorageType.ACCOUNT_WAREHOUSE);
    newPlayer.setEquipment(equipment);
    newPlayer.setMailbox(new Mailbox(newPlayer));

    for (int petBagId = 32; petBagId < 36; petBagId++) {
      Storage petBag = new PlayerStorage(StorageType.getStorageTypeById(petBagId));
      newPlayer.setStorage(petBag, StorageType.getStorageTypeById(petBagId));
    }

    /** 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;
  }
Exemple #3
0
 @Override
 public boolean accept(ItemTemplate template) {
   return template.isClassSpecific(playerClass);
 }
Exemple #4
0
  @Override
  public void act(final Player player, final Item parentItem, Item targetItem) {

    final Storage storage = player.getInventory();
    ItemTemplate stoneTemplate = ItemService.getItemTemplate(parentItem.getItemId());

    if (stoneTemplate.getAid() != 0) {
      int aid = stoneTemplate.getAid();
      final int item = DataManager.ASSEMBLY_DATA.findaid(aid);
      final AssemblyTemplate assembly = DataManager.ASSEMBLY_DATA.getAssemblyTemplate(item);
      part = assembly.getPart();
      for (int i = assembly.getParts_count(); i-- > 0; ) {
        long count = storage.getItemCountByItemId(part.get(i).getId());
        if (storage.getFreeSlots() < count - 1) {
          PacketSendUtility.sendPacket(player, SM_SYSTEM_MESSAGE.STR_MSG_FULL_INVENTORY);
          break;
        }
        if (count == 0) {
          PacketSendUtility.sendPacket(player, SM_SYSTEM_MESSAGE.ASSEMBLY_ITEM_NOT_ENOUGH);
          break;
        } else {

          PacketSendUtility.sendPacket(
              player,
              new SM_ITEM_USAGE_ANIMATION(
                  player.getObjectId(),
                  parentItem.getObjectId(),
                  parentItem.getItemTemplate().getTemplateId(),
                  5000,
                  0,
                  0));
          player.getController().cancelTask(TaskId.ITEM_USE);
          player
              .getController()
              .addTask(
                  TaskId.ITEM_USE,
                  ThreadPoolManager.getInstance()
                      .schedule(
                          new Runnable() {

                            @Override
                            public void run() {
                              PacketSendUtility.sendPacket(
                                  player,
                                  new SM_ITEM_USAGE_ANIMATION(
                                      player.getObjectId(),
                                      parentItem.getObjectId(),
                                      parentItem.getItemTemplate().getTemplateId(),
                                      0,
                                      1,
                                      0));
                              for (int t = assembly.getParts_count(); t-- > 0; ) {
                                player.getInventory().decreaseByItemId(part.get(t).getId(), 1);
                              }
                              ItemService.addItem(player, item, 1);
                            }
                          },
                          5000));

          PacketSendUtility.sendPacket(player, SM_SYSTEM_MESSAGE.ASSEMBLY_ITEM_SUCCEEDED);
          break;
        }
      }
    }
  }