Example #1
0
  /** {@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);
      }
    }
  }
Example #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;
  }