Jump to content
  • 0

[q] siege manager npc


Question

4 answers to this question

Recommended Posts

  • 0
Posted

Take a look into l2jserver.gameserver.model.actor.instance, I think there should be something like L2SiegeManagerInstance.

  • 0
Posted

i found SiegeManager.java in gameserver.instancemanager but i can't see anything useful :-?

 

 

/*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
* 
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
* 
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.gameserver.instancemanager;

import gnu.trove.TIntObjectHashMap;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.List;
import java.util.Properties;
import java.util.StringTokenizer;
import java.util.logging.Level;
import java.util.logging.Logger;

import javolution.util.FastList;

import com.l2jserver.Config;
import com.l2jserver.L2DatabaseFactory;
import com.l2jserver.gameserver.datatables.SkillTable;
import com.l2jserver.gameserver.model.L2Clan;
import com.l2jserver.gameserver.model.L2Object;
import com.l2jserver.gameserver.model.L2Skill;
import com.l2jserver.gameserver.model.Location;
import com.l2jserver.gameserver.model.actor.L2Character;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.model.entity.Castle;
import com.l2jserver.gameserver.model.entity.Siege;

public class SiegeManager
{
private static final Logger _log = Logger.getLogger(SiegeManager.class.getName());

public static final SiegeManager getInstance()
{
	return SingletonHolder._instance;
}

// =========================================================
// Data Field
private int _attackerMaxClans = 500; // Max number of clans
private int _attackerRespawnDelay = 0; // Time in ms. Changeable in siege.config
private int _defenderMaxClans = 500; // Max number of clans

// Siege settings
private TIntObjectHashMap<FastList<SiegeSpawn>> _artefactSpawnList;
private TIntObjectHashMap<FastList<SiegeSpawn>> _controlTowerSpawnList;
private TIntObjectHashMap<FastList<SiegeSpawn>> _flameTowerSpawnList;

private int _flagMaxCount = 1; // Changeable in siege.config
private int _siegeClanMinLevel = 5; // Changeable in siege.config
private int _siegeLength = 120; // Time in minute. Changeable in siege.config
private int _bloodAllianceReward = 0; // Number of Blood Alliance items reward for successful castle defending

// =========================================================
// Constructor
private SiegeManager()
{
	_log.info("Initializing SiegeManager");
	load();
}

// =========================================================
// Method - Public
public final void addSiegeSkills(L2PcInstance character)
{
	for (L2Skill sk : SkillTable.getInstance().getSiegeSkills(character.isNoble(), character.getClan().getHasCastle() > 0))
	{
		character.addSkill(sk, false);
	}
}

/**
 * Return true if character summon<BR><BR>
 * @param activeChar The L2Character of the character can summon
 */
public final boolean checkIfOkToSummon(L2Character activeChar, boolean isCheckOnly)
{
	if (!(activeChar instanceof L2PcInstance))
		return false;

	String text = "";
	L2PcInstance player = (L2PcInstance) activeChar;
	Castle castle = CastleManager.getInstance().getCastle(player);

	if (castle == null || castle.getCastleId() <= 0)
		text = "You must be on castle ground to summon this";
	else if (!castle.getSiege().getIsInProgress())
		text = "You can only summon this during a siege.";
	else if (player.getClanId() != 0 && castle.getSiege().getAttackerClan(player.getClanId()) == null)
		text = "You can only summon this as a registered attacker.";
	else
		return true;

	if (!isCheckOnly)
		player.sendMessage(text);
	return false;
}

/**
 * Return true if the clan is registered or owner of a castle<BR><BR>
 * @param clan The L2Clan of the player
 */
public final boolean checkIsRegistered(L2Clan clan, int castleid)
{
	if (clan == null)
		return false;

	if (clan.getHasCastle() > 0)
		return true;

	Connection con = null;
	boolean register = false;
	try
	{
		con = L2DatabaseFactory.getInstance().getConnection();
		PreparedStatement statement = con.prepareStatement("SELECT clan_id FROM siege_clans where clan_id=? and castle_id=?");
		statement.setInt(1, clan.getClanId());
		statement.setInt(2, castleid);
		ResultSet rs = statement.executeQuery();

		while (rs.next())
		{
			register = true;
			break;
		}

		rs.close();
		statement.close();
	}
	catch (Exception e)
	{
		_log.log(Level.WARNING, "Exception: checkIsRegistered(): " + e.getMessage() ,e);
	}
	finally
	{
		L2DatabaseFactory.close(con);
	}
	return register;
}

public final void removeSiegeSkills(L2PcInstance character)
{
	for (L2Skill sk : SkillTable.getInstance().getSiegeSkills(character.isNoble(), character.getClan().getHasCastle() > 0))
	{
		character.removeSkill(sk);
	}
}

// =========================================================
// Method - Private
private final void load()
{
	InputStream is = null;
	try
	{
		is = new FileInputStream(new File(Config.SIEGE_CONFIGURATION_FILE));
		Properties siegeSettings = new Properties();
		siegeSettings.load(is);

		// Siege setting
		_attackerMaxClans = Integer.decode(siegeSettings.getProperty("AttackerMaxClans", "500"));
		_attackerRespawnDelay = Integer.decode(siegeSettings.getProperty("AttackerRespawn", "0"));
		_defenderMaxClans = Integer.decode(siegeSettings.getProperty("DefenderMaxClans", "500"));
		_flagMaxCount = Integer.decode(siegeSettings.getProperty("MaxFlags", "1"));
		_siegeClanMinLevel = Integer.decode(siegeSettings.getProperty("SiegeClanMinLevel", "5"));
		_siegeLength = Integer.decode(siegeSettings.getProperty("SiegeLength", "120"));
		_bloodAllianceReward = Integer.decode(siegeSettings.getProperty("BloodAllianceReward", "0"));

		// Siege spawns settings
		_controlTowerSpawnList = new TIntObjectHashMap<FastList<SiegeSpawn>>();
		_artefactSpawnList = new TIntObjectHashMap<FastList<SiegeSpawn>>();
		_flameTowerSpawnList = new TIntObjectHashMap<FastList<SiegeSpawn>>();

		for (Castle castle : CastleManager.getInstance().getCastles())
		{
			FastList<SiegeSpawn> _controlTowersSpawns = new FastList<SiegeSpawn>();

			for (int i = 1; i < 0xFF; i++)
			{
				String _spawnParams = siegeSettings.getProperty(castle.getName() + "ControlTower" + i, "");

				if (_spawnParams.isEmpty())
					break;

				StringTokenizer st = new StringTokenizer(_spawnParams.trim(), ",");

				try
				{
					int x = Integer.parseInt(st.nextToken());
					int y = Integer.parseInt(st.nextToken());
					int z = Integer.parseInt(st.nextToken());
					int npc_id = Integer.parseInt(st.nextToken());
					int hp = Integer.parseInt(st.nextToken());

					_controlTowersSpawns.add(new SiegeSpawn(castle.getCastleId(), x, y, z, 0, npc_id, hp));
				}
				catch (Exception e)
				{
					_log.warning("Error while loading control tower(s) for " + castle.getName() + " castle.");
				}
			}

			FastList<SiegeSpawn> _flameTowersSpawns = new FastList<SiegeSpawn>();

			for (int i = 1; i < 0xFF; i++)
			{
				String _spawnParams = siegeSettings.getProperty(castle.getName() + "FlameTower" + i, "");

				if (_spawnParams.isEmpty())
					break;

				StringTokenizer st = new StringTokenizer(_spawnParams.trim(), ",");

				try
				{
					int x = Integer.parseInt(st.nextToken());
					int y = Integer.parseInt(st.nextToken());
					int z = Integer.parseInt(st.nextToken());
					int npc_id = Integer.parseInt(st.nextToken());
					int hp = Integer.parseInt(st.nextToken());

					_flameTowersSpawns.add(new SiegeSpawn(castle.getCastleId(), x, y, z, 0, npc_id, hp));
				}
				catch (Exception e)
				{
					_log.warning("Error while loading artefact(s) for " + castle.getName() + " castle.");
				}
			}

			FastList<SiegeSpawn> _artefactSpawns = new FastList<SiegeSpawn>();

			for (int i = 1; i < 0xFF; i++)
			{
				String _spawnParams = siegeSettings.getProperty(castle.getName() + "Artefact" + i, "");

				if (_spawnParams.isEmpty())
					break;

				StringTokenizer st = new StringTokenizer(_spawnParams.trim(), ",");

				try
				{
					int x = Integer.parseInt(st.nextToken());
					int y = Integer.parseInt(st.nextToken());
					int z = Integer.parseInt(st.nextToken());
					int heading = Integer.parseInt(st.nextToken());
					int npc_id = Integer.parseInt(st.nextToken());

					_artefactSpawns.add(new SiegeSpawn(castle.getCastleId(), x, y, z, heading, npc_id));
				}
				catch (Exception e)
				{
					_log.warning("Error while loading artefact(s) for " + castle.getName() + " castle.");
				}
			}

			_controlTowerSpawnList.put(castle.getCastleId(), _controlTowersSpawns);
			_artefactSpawnList.put(castle.getCastleId(), _artefactSpawns);
			_flameTowerSpawnList.put(castle.getCastleId(), _flameTowersSpawns);
		}

	}
	catch (Exception e)
	{
		//_initialized = false;
		_log.log(Level.WARNING, "Error while loading siege data: " + e.getMessage(), e);
	}
	finally
	{
		try
		{
			is.close();
		}
		catch (Exception e)
		{
		}
	}
}

// =========================================================
// Property - Public
public final FastList<SiegeSpawn> getArtefactSpawnList(int _castleId)
{
	return _artefactSpawnList.get(_castleId);
}

public final FastList<SiegeSpawn> getControlTowerSpawnList(int _castleId)
{
	return _controlTowerSpawnList.get(_castleId);
}

public final FastList<SiegeSpawn> getFlameTowerSpawnList(int _castleId)
{
	return _flameTowerSpawnList.get(_castleId);
}

public final int getAttackerMaxClans()
{
	return _attackerMaxClans;
}

public final int getAttackerRespawnDelay()
{
	return _attackerRespawnDelay;
}

public final int getDefenderMaxClans()
{
	return _defenderMaxClans;
}

public final int getFlagMaxCount()
{
	return _flagMaxCount;
}

public final Siege getSiege(L2Object activeObject)
{
	return getSiege(activeObject.getX(), activeObject.getY(), activeObject.getZ());
}

public final Siege getSiege(int x, int y, int z)
{
	for (Castle castle : CastleManager.getInstance().getCastles())
		if (castle.getSiege().checkIfInZone(x, y, z))
			return castle.getSiege();
	return null;
}

public final int getSiegeClanMinLevel()
{
	return _siegeClanMinLevel;
}

public final int getSiegeLength()
{
	return _siegeLength;
}

public final int getBloodAllianceReward()
{
	return _bloodAllianceReward;
}

public final List<Siege> getSieges()
{
	FastList<Siege> sieges = new FastList<Siege>();
	for (Castle castle : CastleManager.getInstance().getCastles())
		sieges.add(castle.getSiege());
	return sieges;
}

public class SiegeSpawn
{
	Location _location;
	private int _npcId;
	private int _heading;
	private int _castleId;
	private int _hp;

	public SiegeSpawn(int castle_id, int x, int y, int z, int heading, int npc_id)
	{
		_castleId = castle_id;
		_location = new Location(x, y, z, heading);
		_heading = heading;
		_npcId = npc_id;
	}

	public SiegeSpawn(int castle_id, int x, int y, int z, int heading, int npc_id, int hp)
	{
		_castleId = castle_id;
		_location = new Location(x, y, z, heading);
		_heading = heading;
		_npcId = npc_id;
		_hp = hp;
	}

	public int getCastleId()
	{
		return _castleId;
	}

	public int getNpcId()
	{
		return _npcId;
	}

	public int getHeading()
	{
		return _heading;
	}

	public int getHp()
	{
		return _hp;
	}

	public Location getLocation()
	{
		return _location;
	}
}

@SuppressWarnings("synthetic-access")
private static class SingletonHolder
{
	protected static final SiegeManager _instance = new SiegeManager();
}
}

 

 

edit: and in siege.java i found

 

/** Display list of registered clans */
public void listRegisterClan(L2PcInstance player)
{
	player.sendPacket(new SiegeInfo(getCastle()));
}

/**
 * Register clan as attacker<BR><BR>
 * @param player The L2PcInstance of the player trying to register
 */
public void registerAttacker(L2PcInstance player)
{
	registerAttacker(player, false);
}

public void registerAttacker(L2PcInstance player, boolean force)
{
	if (player.getClan() == null)
		return;
	int allyId = 0;
	if (getCastle().getOwnerId() != 0)
		allyId = ClanTable.getInstance().getClan(getCastle().getOwnerId()).getAllyId();
	if (allyId != 0)
	{
		if (player.getClan().getAllyId() == allyId && !force)
		{
			player.sendPacket(new SystemMessage(SystemMessageId.CANNOT_ATTACK_ALLIANCE_CASTLE));
			return;
		}
	}
	if (force || checkIfCanRegister(player, ATTACKER))
		saveSiegeClan(player.getClan(), ATTACKER, false); // Save to database
}

/**
 * Register clan as defender<BR><BR>
 * @param player The L2PcInstance of the player trying to register
 */
public void registerDefender(L2PcInstance player)
{
	registerDefender(player, false);
}

  • 0
Posted

Either you're blind, idiot, or a blind idiot, but read what ^Wyatt said.

 

If you want any L2SiegeNpcInstance show all castle you have to create (or generate) an HTM with all castles names, and for loop on it. As you (perhaps) will see, L2SiegeNpcInstance is linked to one castle (better said, on the castle zone the NPC belongs).

 

With a for loop on castles you can both generate your HTM with castle names + generates HTM bypasses and finally show the correct castle.

 

It's probably chinese for you and you will whine you don't understand a shit (as you already can't read a single answer), whatever, I answered and the next step is to explain all from A to Z, which I won't do. If you move on (you made a 'pélerinage' to Saint Jacques de Compostelle and a miracle came) and got somes codes you block on, I'm here.

 

Finally if you think I'm agressive, buy a brain to read answers and I won't be.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Posts

    • Please note:i will provide you with forum address for registration once buyer sends money(my commission) to forum guarantor's payment details. You can register on forum in any day and in any time,which are convenient for you,send code word in private message to forum guarantor(you will receive code word from buyer). If buyer does not purchase your product,you will need to wait private message(answer) from forum guarantor to compare code word. I will invite you in "forum deal". I will add your name,which you registered on forum,in "forum deal". Then you write in "forum deal": "buyer did not purchase product" and add code word(you will have this right according to clause in forum questionnaire). Forum guarantor will refund buyer((in full amount). If buyer purchases your product,buyer notifies forum guarantor and forum guarantor will send money to my payment details.   Sports exercise machines,jacuzzi,building materials,cosmetics,perfumes,shoes,clothing,furniture,bags,televisions,music centers,telephones,laptops,tablet computers,refrigerators,washing machines,microwaves,fans.  
    • Here is a L2JMobius Classic Interlude FULL server. The share includes full server source+datapack, patch, interface and the P110 client. The original build is L2JMobius. However it was bought from a user called "ClassicLude (https://classic-lude.org/)" which is also a huge scammer, selling free Mobius files for $500. I could not believe someone actually bought this, yet here we are.    Unfortunately the admin is a scammer and refused to pay his remaining balance of over $150 to me since he is too busy "working for Bill Gates" and opening the next big mega mall in ChatGPT city therefore not having enough money. The server itself garnered a massive 30 players so I can't really tell you if this is usable. Knowing its backstory and that it is Mobius based i can surmise that it is NOT suitable for serious users. This build is the result of typical AI slop and vibecode "admins" thinking they just "one shotted L2J" because they discovered how to prompt an agent.   I have made the following changes, some of which were regrettably butchered by the admin after he discovered how to download Cursor. Not much more was done due to the absolute displeasure and misery of having to work on a Mobius server.   - Updated files to JDK 22 - Added l2 reborn community board - Added preview system for skins including mounts/agathions - Added AIO npc (buffer/store/teleporter) - Added QuickVar system - Added Ranking system (pvp/pk/online/level and moar) - Added raid boss list on community board - Added drop search+shift click with itemtooltip on community board and npc - Added l2 reborn styled flash windows and window borders and L2UI_CT1 - Added custom donate coin icon in the store swf - Fixed some random bugs like Hot Springs monsters not giving the disease     Links Source+Datapack: https://drive.google.com/file/d/1uMaTzSxKtnLxXC-VoZyHYW_OXq7Oof5L/view?usp=sharing Interface+Compiler+Client tools: https://drive.google.com/file/d/14IJWyYSDOjMycHnJ749H9dRXuv2JeYK3/view?usp=sharing Full Client: https://drive.google.com/file/d/1P7Yd9wI0XcWlLMFDPSdfTZgWhW_9JEii/view?usp=sharing
    • I logged in with this system, maybe its the patch shared by greenhope i don't remember i just downloaded it because i love C3 but no l2j or l2off c3 is good everything is buggy and this one too, also it has no geodata and i don't know if it has geoengine because i didn't see the config for it in the config folder. If someone had the latest l2jvn maybe it could be more stable but i don't think so at least without the source, if someone has it to share it that would be good  https://www.mediafire.com/file/mzodnsyi9qn4ap7/patch+560+for+c3.rar/file
    • We are certainly not an ambulance, but we will definitely cure you of blacklists and empty pockets. Live freely with SX! Each of you will receive a trial version of SX to familiarize yourself with the product, all you have to do is post in this thread
  • Topics

×
×
  • Create New...

Important Information

This community uses essential cookies to function properly. Non-essential cookies and third-party services are used only with your consent. Read our Privacy Policy and We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue..