Example #1
0
  /**
   * Adda mercenary ticket.
   *
   * <ul>
   *   <li>find the npc that needs to be saved in the mercenary spawns, given this item
   *   <li>Use the passed character's location info to add the spawn
   *   <li>create a copy of the item to drop in the world returns the id of the mercenary npc that
   *       was added to the spawn returns -1 if this fails.
   * </ul>
   *
   * @param itemId
   * @param activeChar
   * @return
   */
  public int addTicket(int itemId, L2PcInstance activeChar) {
    int x = activeChar.getX();
    int y = activeChar.getY();
    int z = activeChar.getZ();
    int heading = activeChar.getHeading();

    Castle castle = CastleManager.getInstance().getCastle(activeChar);
    if (castle == null) // this should never happen at this point
    return -1;

    for (int i = 0; i < ITEM_IDS.length; i++) {
      if (ITEM_IDS[i] == itemId) // Find the index of the item used
      {
        spawnMercenary(NPC_IDS[i], x, y, z, 3000);

        // Hire merc for this castle. NpcId is at the same index as the item used.
        castle.getSiege().getSiegeGuardManager().hireMerc(x, y, z, heading, NPC_IDS[i]);

        // create the ticket in the gameworld
        ItemInstance dropticket = new ItemInstance(IdFactory.getInstance().getNextId(), itemId);
        dropticket.setLocation(ItemInstance.ItemLocation.INVENTORY);
        dropticket.setDestroyProtected(true);
        dropticket.dropMe(activeChar, x, y, z);
        L2World.getInstance().storeObject(dropticket); // add to the world
        // and keep track of this ticket in the list
        _droppedTickets.add(dropticket);

        return NPC_IDS[i];
      }
    }
    return -1;
  }
Example #2
0
  private static void spawnMercenary(int npcId, int x, int y, int z, int despawnDelay) {
    NpcTemplate template = NpcTable.getInstance().getTemplate(npcId);
    if (template != null) {
      final L2SiegeGuardInstance npc =
          new L2SiegeGuardInstance(IdFactory.getInstance().getNextId(), template);
      npc.setCurrentHpMp(npc.getMaxHp(), npc.getMaxMp());
      npc.setDecayed(false);
      npc.spawnMe(x, y, (z + 20));

      if (despawnDelay > 0) npc.scheduleDespawn(despawnDelay);
    }
  }
Example #3
0
  private static final void load() {
    try (Connection con = L2DatabaseFactory.getInstance().getConnection()) {
      PreparedStatement statement =
          con.prepareStatement("SELECT * FROM castle_siege_guards WHERE isHired=1");
      ResultSet rs = statement.executeQuery();

      int npcId;
      int itemId;
      int x, y, z;

      // start index to begin the search for the itemId corresponding to this NPC :
      // a) skip unnecessary iterations in the search loop
      // b) avoid finding the wrong itemId whenever tickets of different spawn the same npc!
      int startindex = 0;

      while (rs.next()) {
        npcId = rs.getInt("npcId");
        x = rs.getInt("x");
        y = rs.getInt("y");
        z = rs.getInt("z");

        Castle castle = CastleManager.getInstance().getCastle(x, y, z);
        if (castle != null) startindex = 10 * (castle.getCastleId() - 1);

        // find the FIRST ticket itemId with spawns the saved NPC in the saved location
        for (int i = startindex; i < NPC_IDS.length; i++) {
          if (NPC_IDS[i] == npcId) // Find the index of the item used
          {
            // only handle tickets if a siege is not ongoing in this npc's castle
            if (castle != null && !(castle.getSiege().isInProgress())) {
              itemId = ITEM_IDS[i];
              // create the ticket in the gameworld
              ItemInstance dropticket =
                  new ItemInstance(IdFactory.getInstance().getNextId(), itemId);
              dropticket.setLocation(ItemInstance.ItemLocation.INVENTORY);
              dropticket.setDestroyProtected(true);
              dropticket.dropMe(null, x, y, z);
              L2World.getInstance().storeObject(dropticket);
              _droppedTickets.add(dropticket);
            }
            break;
          }
        }
      }
      rs.close();
      statement.close();
    } catch (Exception e) {
      _log.log(Level.WARNING, "Exception: loadMercenaryData(): " + e.getMessage(), e);
    }
    _log.info("MercTicketManager: Loaded " + _droppedTickets.size() + " tickets.");
  }