/** * 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; }
@Override protected void runImpl() { final L2PcInstance activeChar = getClient().getActiveChar(); if (activeChar == null) return; // Check if the player has a clan if (activeChar.getClan() == null) return; final Castle castle = CastleManager.getInstance().getCastleById(_castleId); if (castle == null) return; // Check if leader of the clan who owns the castle? if ((castle.getOwnerId() != activeChar.getClanId()) || (!activeChar.isClanLeader())) return; final L2Clan clan = ClanTable.getInstance().getClan(_clanId); if (clan == null) return; if (!castle.getSiege().getIsRegistrationOver()) { if (_approved == 1) { if (castle.getSiege().checkIsDefenderWaiting(clan)) castle.getSiege().approveSiegeDefenderClan(_clanId); else return; } else { if ((castle.getSiege().checkIsDefenderWaiting(clan)) || (castle.getSiege().checkIsDefender(clan))) castle.getSiege().removeSiegeClan(_clanId); } } // Update the defender list activeChar.sendPacket(new SiegeDefenderList(castle)); }
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."); }
@Override public boolean useAdminCommand(String command, L2PcInstance activeChar) { StringTokenizer st = new StringTokenizer(command, " "); command = st.nextToken(); // Get actual command // Get castle Castle castle = null; ClanHall clanhall = null; if (command.startsWith("admin_clanhall")) clanhall = ClanHallManager.getInstance().getClanHallById(Integer.parseInt(st.nextToken())); else if (st.hasMoreTokens()) castle = CastleManager.getInstance().getCastle(st.nextToken()); if (clanhall == null && (castle == null || castle.getCastleId() < 0)) { showCastleSelectPage(activeChar); return true; } L2Object target = activeChar.getTarget(); L2PcInstance player = null; if (target instanceof L2PcInstance) player = (L2PcInstance) target; if (castle != null) { if (command.equalsIgnoreCase("admin_add_attacker")) { if (player == null) activeChar.sendPacket(SystemMessageId.TARGET_IS_INCORRECT); else castle.getSiege().registerAttacker(player); } else if (command.equalsIgnoreCase("admin_add_defender")) { if (player == null) activeChar.sendPacket(SystemMessageId.TARGET_IS_INCORRECT); else castle.getSiege().registerDefender(player); } else if (command.equalsIgnoreCase("admin_add_guard")) { try { int npcId = Integer.parseInt(st.nextToken()); castle.getSiege().getSiegeGuardManager().addSiegeGuard(activeChar, npcId); } catch (Exception e) { activeChar.sendMessage("Usage: //add_guard npcId"); } } else if (command.equalsIgnoreCase("admin_clear_siege_list")) { castle.getSiege().clearSiegeClan(); } else if (command.equalsIgnoreCase("admin_endsiege")) { castle.getSiege().endSiege(); } else if (command.equalsIgnoreCase("admin_list_siege_clans")) { castle.getSiege().listRegisterClan(activeChar); return true; } else if (command.equalsIgnoreCase("admin_move_defenders")) { activeChar.sendPacket(SystemMessage.sendString("Not implemented yet.")); } else if (command.equalsIgnoreCase("admin_setcastle")) { if (player == null || player.getClan() == null) activeChar.sendPacket(SystemMessageId.TARGET_IS_INCORRECT); else if (player.getClan().hasCastle()) activeChar.sendMessage(player.getName() + "'s clan already owns a castle."); else castle.setOwner(player.getClan()); } else if (command.equalsIgnoreCase("admin_removecastle")) { L2Clan clan = ClanTable.getInstance().getClan(castle.getOwnerId()); if (clan != null) castle.removeOwner(clan); else activeChar.sendMessage("Unable to remove castle for this clan."); } else if (command.equalsIgnoreCase("admin_spawn_doors")) { castle.spawnDoors(false); } else if (command.equalsIgnoreCase("admin_startsiege")) { castle.getSiege().startSiege(); } showSiegePage(activeChar, castle.getName()); } else if (clanhall != null) { if (command.equalsIgnoreCase("admin_clanhallset")) { if (player == null || player.getClan() == null) activeChar.sendPacket(SystemMessageId.TARGET_IS_INCORRECT); else if (!ClanHallManager.getInstance().isFree(clanhall.getId())) activeChar.sendMessage("This ClanHall isn't free!"); else if (!player.getClan().hasHideout()) { ClanHallManager.getInstance().setOwner(clanhall.getId(), player.getClan()); if (AuctionManager.getInstance().getAuction(clanhall.getId()) != null) AuctionManager.getInstance().getAuction(clanhall.getId()).deleteAuctionFromDB(); } else activeChar.sendMessage("You have already a ClanHall!"); } else if (command.equalsIgnoreCase("admin_clanhalldel")) { if (!ClanHallManager.getInstance().isFree(clanhall.getId())) { ClanHallManager.getInstance().setFree(clanhall.getId()); AuctionManager.getInstance().initNPC(clanhall.getId()); } else activeChar.sendMessage("This ClanHall is already Free!"); } else if (command.equalsIgnoreCase("admin_clanhallopendoors")) { clanhall.openCloseDoors(true); } else if (command.equalsIgnoreCase("admin_clanhallclosedoors")) { clanhall.openCloseDoors(false); } else if (command.equalsIgnoreCase("admin_clanhallteleportself")) { L2ClanHallZone zone = clanhall.getZone(); if (zone != null) activeChar.teleToLocation(zone.getSpawnLoc(), 0); } showClanHallPage(activeChar, clanhall); } return true; }