Index: C:/Eclipse/workspace/L2_GameServer/java/net/sf/l2j/gameserver/model/actor/instance/L2EvilBossInstance.java
===================================================================
--- C:/Eclipse/workspace/L2_GameServer/java/net/sf/l2j/gameserver/model/actor/instance/L2EvilBossInstance.java (revision 0)
+++ C:/Eclipse/workspace/L2_GameServer/java/net/sf/l2j/gameserver/model/actor/instance/L2EvilBossInstance.java (revision 0)
@@ -0,0 +1,245 @@
+/*
+ * 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 net.sf.l2j.gameserver.model.actor.instance;
+
+import java.util.logging.Logger;
+
+import net.sf.l2j.Config;
+import net.sf.l2j.gameserver.ThreadPoolManager;
+import net.sf.l2j.gameserver.ai.CtrlIntention;
+import net.sf.l2j.gameserver.ai.L2AttackableAI;
+import net.sf.l2j.gameserver.datatables.MapRegionTable;
+import net.sf.l2j.gameserver.instancemanager.CastleManager;
+import net.sf.l2j.gameserver.instancemanager.TownManager;
+import net.sf.l2j.gameserver.model.zone.L2ZoneType;
+import net.sf.l2j.gameserver.model.zone.type.L2TownZone;
+import net.sf.l2j.gameserver.model.L2CharPosition;
+import net.sf.l2j.gameserver.model.L2World;
+import net.sf.l2j.gameserver.model.L2WorldRegion;
+import net.sf.l2j.gameserver.model.actor.L2Attackable;
+import net.sf.l2j.gameserver.model.actor.L2Character;
+import net.sf.l2j.gameserver.model.actor.knownlist.EvilBossKnownList;
+import net.sf.l2j.gameserver.model.quest.Quest;
+import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
+import net.sf.l2j.gameserver.network.serverpackets.MyTargetSelected;
+import net.sf.l2j.gameserver.network.serverpackets.SocialAction;
+import net.sf.l2j.gameserver.network.serverpackets.ValidateLocation;
+import net.sf.l2j.gameserver.templates.chars.L2NpcTemplate;
+import net.sf.l2j.util.Rnd;
+
+/**
+ * This class manages all Guards in the world.
+ * It inherits all methods from L2Attackable and adds some more such as tracking PK and aggressive L2MonsterInstance.<BR><BR>
+ *
+ * @version $Revision: 1.11.2.1.2.7 $ $Date: 2005/04/06 16:13:40 $
+ */
+public final class L2EvilBossInstance extends L2Attackable
+{
+
+ @SuppressWarnings("hiding")
+ private static Logger _log = Logger.getLogger(L2EvilBossInstance.class.getName());
+
+ private static final int RETURN_INTERVAL = 60000;
+
+ public class ReturnTask implements Runnable
+ {
+ public void run()
+ {
+ if(getAI().getIntention() == CtrlIntention.AI_INTENTION_IDLE)
+ returnHome();
+ }
+ }
+
+ /**
+ * Constructor of L2EvilGuardInstance (use L2Character and L2NpcInstance constructor).<BR><BR>
+ *
+ * <B><U> Actions</U> :</B><BR><BR>
+ * <li>Call the L2Character constructor to set the _template of the L2EvilGuardInstance (copy skills from template to object and link _calculators to NPC_STD_CALCULATOR) </li>
+ * <li>Set the name of the L2EvilGuardInstance</li>
+ * <li>Create a RandomAnimation Task that will be launched after the calculated delay if the server allow it </li><BR><BR>
+ *
+ * @param objectId Identifier of the object to initialized
+ * @param L2NpcTemplate Template to apply to the NPC
+ */
+ public L2EvilBossInstance(int objectId, L2NpcTemplate template)
+ {
+ super(objectId, template);
+ getKnownList(); // init knownlist
+
+ ThreadPoolManager.getInstance().scheduleAiAtFixedRate(new ReturnTask(),RETURN_INTERVAL,RETURN_INTERVAL+Rnd.nextInt(60000));
+ }
+
+ @Override
+ public final EvilBossKnownList getKnownList()
+ {
+ if(!(super.getKnownList() instanceof EvilBossKnownList))
+ setKnownList(new EvilBossKnownList(this));
+ return (EvilBossKnownList)super.getKnownList();
+ }
+
+ /**
+ * Return True if hte attacker is a L2MonsterInstance.<BR><BR>
+ */
+ @Override
+ public boolean isAutoAttackable(L2Character attacker)
+ {
+ return attacker instanceof L2MonsterInstance;
+ }
+
+
+ /**
+ * Notify the L2EvilBossInstance to return to its home location (AI_INTENTION_MOVE_TO) and clear its _aggroList.<BR><BR>
+ */
+ public void returnHome()
+ {
+ if (!isInsideRadius(getSpawn().getLocx(), getSpawn().getLocy(), 150, false))
+ {
+ clearAggroList();
+
+ getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new L2CharPosition(getSpawn().getLocx(), getSpawn().getLocy(), getSpawn().getLocz(), 0));
+ }
+ }
+
+ /**
+ * Set the home location of its L2EvilBossInstance.<BR><BR>
+ */
+ @Override
+ public void onSpawn()
+ {
+ super.onSpawn();
+
+ // check the region where this mob is, do not activate the AI if region is inactive.
+ L2WorldRegion region = L2World.getInstance().getRegion(getX(),getY());
+ if ((region !=null) && (!region.isActive()))
+ ((L2AttackableAI) getAI()).stopAITask();
+ }
+
+ public void onDoDie()
+ {
+// if (TownManager.getClosestTown(this) == TownManager.getTown(10))
+ TownManager.getTown(10).setTownIsGood(true);
+ TownManager.getTown(10).storeFactionTowns();
+
+ }
+
+
+ /**
+ * Return the pathfile of the selected HTML file in function of the L2EvilBossInstance Identifier and of the page number.<BR><BR>
+ *
+ * <B><U> Format of the pathfile </U> :</B><BR><BR>
+ * <li> if page number = 0 : <B>data/html/guard/12006.htm</B> (npcId-page number)</li>
+ * <li> if page number > 0 : <B>data/html/guard/12006-1.htm</B> (npcId-page number)</li><BR><BR>
+ *
+ * @param npcId The Identifier of the L2NpcInstance whose text must be display
+ * @param val The number of the page to display
+ *
+ */
+ @Override
+ public String getHtmlPath(int npcId, int val)
+ {
+ String pom = "";
+ if (val == 0)
+ {
+ pom = "" + npcId;
+ }
+ else
+ {
+ pom = npcId + "-" + val;
+ }
+ return "data/html/guard/" + pom + ".htm";
+ }
+
+
+ /**
+ * Manage actions when a player click on the L2EvilBossInstance.<BR><BR>
+ *
+ * <B><U> Actions on first click on the L2EvilBossInstance (Select it)</U> :</B><BR><BR>
+ * <li>Set the L2EvilBossInstance as target of the L2PcInstance player (if necessary)</li>
+ * <li>Send a Server->Client packet MyTargetSelected to the L2PcInstance player (display the select window)</li>
+ * <li>Set the L2PcInstance Intention to AI_INTENTION_IDLE </li>
+ * <li>Send a Server->Client packet ValidateLocation to correct the L2EvilBossInstance position and heading on the client </li><BR><BR>
+ *
+ * <B><U> Actions on second click on the L2EvilBossInstance (Attack it/Interact with it)</U> :</B><BR><BR>
+ * <li>If L2PcInstance is in the _aggroList of the L2EvilBossInstance, set the L2PcInstance Intention to AI_INTENTION_ATTACK</li>
+ * <li>If L2PcInstance is NOT in the _aggroList of the L2EvilBossInstance, set the L2PcInstance Intention to AI_INTENTION_INTERACT (after a distance verification) and show message</li><BR><BR>
+ *
+ * <B><U> Example of use </U> :</B><BR><BR>
+ * <li> Client packet : Action, AttackRequest</li><BR><BR>
+ *
+ * @param player The L2PcInstance that start an action on the L2EvilBossInstance
+ *
+ */
+ @Override
+ public void onAction(L2PcInstance player)
+ {
+ if (!canTarget(player)) return;
+
+ // Check if the L2PcInstance already target the L2EvilBossInstance
+ if (getObjectId() != player.getTargetId())
+ {
+ if (Config.DEBUG) _log.fine(player.getObjectId()+": Targetted guard "+getObjectId());
+
+ // Set the target of the L2PcInstance player
+ player.setTarget(this);
+
+ // Send a Server->Client packet MyTargetSelected to the L2PcInstance player
+ // The color to display in the select window is White
+ MyTargetSelected my = new MyTargetSelected(getObjectId(), 0);
+ player.sendPacket(my);
+
+ // Send a Server->Client packet ValidateLocation to correct the L2NpcInstance position and heading on the client
+ player.sendPacket(new ValidateLocation(this));
+ }
+ else
+ {
+ // Check if the L2PcInstance is in the _aggroList of the L2EvilBossInstance
+ if (containsTarget(player))
+ {
+ if (Config.DEBUG) _log.fine(player.getObjectId()+": Attacked guard "+getObjectId());
+
+ // Set the L2PcInstance Intention to AI_INTENTION_ATTACK
+ player.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, this);
+ }
+ else
+ {
+ // Calculate the distance between the L2PcInstance and the L2NpcInstance
+ if (!canInteract(player))
+ {
+ // Set the L2PcInstance Intention to AI_INTENTION_INTERACT
+ player.getAI().setIntention(CtrlIntention.AI_INTENTION_INTERACT, this);
+ }
+ else
+ {
+ // Send a Server->Client packet SocialAction to the all L2PcInstance on the _knownPlayer of the L2NpcInstance
+ // to display a social action of the L2EvilBossInstance on their client
+ SocialAction sa = new SocialAction(getObjectId(), Rnd.nextInt(8));
+ broadcastPacket(sa);
+
+ // Open a chat window on client with the text of the L2EvilBossInstance
+ Quest[] qlsa = getTemplate().getEventQuests(Quest.QuestEventType.QUEST_START);
+ if ( (qlsa != null) && qlsa.length > 0)
+ player.setLastQuestNpcObject(getObjectId());
+ Quest[] qlst = getTemplate().getEventQuests(Quest.QuestEventType.ON_FIRST_TALK);
+ if ( (qlst != null) && qlst.length == 1)
+ qlst[0].notifyFirstTalk(this, player);
+ else
+ showChatWindow(player, 0);
+ }
+ }
+ }
+ // Send a Server->Client ActionFailed to the L2PcInstance in order to avoid that the client wait another packet
+ player.sendPacket(ActionFailed.STATIC_PACKET);
+ }
+}
Index: C:/Eclipse/workspace/L2_GameServer/java/net/sf/l2j/gameserver/model/actor/knownlist/EvilBossKnownList.java
===================================================================
--- C:/Eclipse/workspace/L2_GameServer/java/net/sf/l2j/gameserver/model/actor/knownlist/EvilBossKnownList.java (revision 0)
+++ C:/Eclipse/workspace/L2_GameServer/java/net/sf/l2j/gameserver/model/actor/knownlist/EvilBossKnownList.java (revision 0)
@@ -0,0 +1,108 @@
+/*
+ * 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 net.sf.l2j.gameserver.model.actor.knownlist;
+
+import java.util.logging.Logger;
+
+import net.sf.l2j.Config;
+import net.sf.l2j.gameserver.ai.CtrlIntention;
+import net.sf.l2j.gameserver.ai.L2CharacterAI;
+import net.sf.l2j.gameserver.model.L2Object;
+import net.sf.l2j.gameserver.model.actor.L2Character;
+import net.sf.l2j.gameserver.model.actor.instance.L2EvilBossInstance;
+import net.sf.l2j.gameserver.model.actor.instance.L2MonsterInstance;
+import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
+
+public class EvilBossKnownList extends AttackableKnownList
+{
+ private static Logger _log = Logger.getLogger(EvilBossKnownList.class.getName());
+
+ // =========================================================
+ // Data Field
+
+ // =========================================================
+ // Constructor
+ public EvilBossKnownList(L2EvilBossInstance activeChar)
+ {
+ super(activeChar);
+ }
+
+ // =========================================================
+ // Method - Public
+ @Override
+ public boolean addKnownObject(L2Object object) { return addKnownObject(object, null); }
+ @Override
+ public boolean addKnownObject(L2Object object, L2Character dropper)
+ {
+ if (!super.addKnownObject(object, dropper)) return false;
+
+ if (object instanceof L2PcInstance)
+ {
+ // Check if the object added is a L2PcInstance that owns Karma
+ L2PcInstance player = (L2PcInstance) object;
+
+ if (player.isgood() )
+ {
+ if (Config.DEBUG) _log.fine(getActiveChar().getObjectId()+": PK "+player.getObjectId()+" entered scan range");
+
+ // Set the L2GuardInstance Intention to AI_INTENTION_ACTIVE
+ if (getActiveChar().getAI().getIntention() == CtrlIntention.AI_INTENTION_IDLE)
+ getActiveChar().getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE, null);
+ }
+ }
+ else if ((Config.GUARD_ATTACK_AGGRO_MOB && getActiveChar().isInActiveRegion()) && object instanceof L2MonsterInstance)
+ {
+ // Check if the object added is an aggressive L2MonsterInstance
+ L2MonsterInstance mob = (L2MonsterInstance) object;
+
+ if (mob.isAggressive() )
+ {
+ if (Config.DEBUG) _log.fine(getActiveChar().getObjectId()+": Aggressive mob "+mob.getObjectId()+" entered scan range");
+
+ // Set the L2GuardInstance Intention to AI_INTENTION_ACTIVE
+ if (getActiveChar().getAI().getIntention() == CtrlIntention.AI_INTENTION_IDLE)
+ getActiveChar().getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE, null);
+ }
+ }
+
+ return true;
+ }
+
+ @Override
+ public boolean removeKnownObject(L2Object object)
+ {
+ if (!super.removeKnownObject(object)) return false;
+
+ // Check if the _aggroList of the L2GuardInstance is Empty
+ if (getActiveChar().noTarget())
+ {
+ //removeAllKnownObjects();
+
+ // Set the L2GuardInstance to AI_INTENTION_IDLE
+ L2CharacterAI ai = getActiveChar().getAI();
+ if (ai != null) ai.setIntention(CtrlIntention.AI_INTENTION_IDLE, null);
+ }
+
+ return true;
+ }
+
+ // =========================================================
+ // Method - Private
+
+ // =========================================================
+ // Property - Public
+ @Override
+ public final L2EvilBossInstance getActiveChar() { return (L2EvilBossInstance)super.getActiveChar(); }
+}
activeChar.sendPacket(new SystemMessage(SystemMessageId.CANNOT_INVITE_YOURSELF));
Index: C:/Eclipse/workspace/L2_GameServer/java/net/sf/l2j/gameserver/model/zone/type/L2TownZone.java
===================================================================
--- C:/Eclipse/workspace/L2_GameServer/java/net/sf/l2j/gameserver/model/zone/type/L2TownZone.java (revision 3278)
+++ C:/Eclipse/workspace/L2_GameServer/java/net/sf/l2j/gameserver/model/zone/type/L2TownZone.java (working copy)
@@ -14,7 +14,12 @@
*/
package net.sf.l2j.gameserver.model.zone.type;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+
import net.sf.l2j.Config;
+import net.sf.l2j.L2DatabaseFactory;
import net.sf.l2j.gameserver.model.actor.L2Character;
import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
import net.sf.l2j.gameserver.model.zone.L2ZoneType;
@@ -26,6 +31,11 @@
*/
public class L2TownZone extends L2ZoneType
{
+ private static final String SELECT_FROM_FACTION_TOWNS = "SELECT FactionTownId,TownIsGood,TownIsEvil FROM faction_towns";
+ private static final String UPDATE_FACTION_TOWNS = "UPDATE faction_towns SET FactionTownId=?,TownIsGood=?,TownIsEvil=?";
+ public int _FactionTownId;
+ public boolean _TownIsGood = false;
+ public boolean _TownIsEvil = false;
private String _townName;
private int _townId;
private int _redirectTownId;
@@ -181,4 +191,69 @@
{
return _isPeaceZone;
}
+ public void selectFactionTowns()
+ {
+ Connection con = null;
+ try
+ {
+ con = L2DatabaseFactory.getInstance().getConnection();
+ PreparedStatement statement = con.prepareStatement(SELECT_FROM_FACTION_TOWNS);
+ ResultSet rset = statement.executeQuery();
+ while (rset.next())
+ {
+ setTownIsGood((rset.getInt("isGood")==1)? true : false);
+ setTownIsEvil((rset.getInt("isEvil")==1)? true : false);
+ }
+ rset.close();
+ statement.close();
+
+ }
+ catch (Exception e)
+ {
+ }
+ finally
+ {
+ try { con.close(); } catch (Exception e) {}
+ }
+ }
+ public void storeFactionTowns()
+ {
+ Connection con = null;
+
+ try
+ {
+ con = L2DatabaseFactory.getInstance().getConnection();
+ PreparedStatement statement = con.prepareStatement(UPDATE_FACTION_TOWNS);
+
+ statement.setInt(1, FactionTownId());
+ statement.setInt(2, TownIsGood() ? 1 : 0);
+ statement.setInt(3, TownIsEvil() ? 1 : 0);
+ statement.execute();
+ statement.close();
+ }
+ catch (Exception e) {}
+ finally { try { con.close(); } catch (Exception e) {} }
+ }
+ public int FactionTownId()
+ {
+ return _FactionTownId;
+ }
+ public boolean TownIsGood()
+ {
+ return _TownIsGood;
+ }
+
+ public boolean TownIsEvil()
+ {
+ return _TownIsEvil;
+ }
+ public void setTownIsGood(boolean value)
+ {
+ _TownIsGood = value;
+ }
+
+ public void setTownIsEvil(boolean value)
+ {
+ _TownIsEvil = value;
+ }
}
Index: C:/Eclipse/workspace/L2_GameServer/java/net/sf/l2j/gameserver/instancemanager/TownManager.java
===================================================================
--- C:/Eclipse/workspace/L2_GameServer/java/net/sf/l2j/gameserver/instancemanager/TownManager.java (revision 3278)
+++ C:/Eclipse/workspace/L2_GameServer/java/net/sf/l2j/gameserver/instancemanager/TownManager.java (working copy)
@@ -14,6 +14,11 @@
*/
package net.sf.l2j.gameserver.instancemanager;
+//import java.sql.Connection;
+//import java.sql.PreparedStatement;
+//import java.sql.ResultSet;
+
+//import net.sf.l2j.L2DatabaseFactory;
import net.sf.l2j.gameserver.datatables.MapRegionTable;
import net.sf.l2j.gameserver.model.L2Object;
import net.sf.l2j.gameserver.model.entity.Castle;
@@ -22,6 +27,12 @@
public class TownManager
{
+/* private static final String SELECT_FROM_FACTION_TOWNS = "SELECT FactionTownId,TownIsGood,TownIsEvil FROM faction_towns";
+ private static final String UPDATE_FACTION_TOWNS = "UPDATE faction_towns SET FactionTownId=?,TownIsGood=?,TownIsEvil=? WHERE charId=?";
+ public int _FactionTownId;
+ public boolean _TownIsGood = false;
+ public boolean _TownIsEvil = false;
+*/
//private static final Logger _log = Logger.getLogger(TownManager.class.getName());
// =========================================================
@@ -247,4 +258,75 @@
}
return null;
}
+
+/* public void selectFactionTowns()
+ {
+ Connection con = null;
+ try
+ {
+ con = L2DatabaseFactory.getInstance().getConnection();
+ PreparedStatement statement = con.prepareStatement(SELECT_FROM_FACTION_TOWNS);
+ ResultSet rset = statement.executeQuery();
+ while (rset.next())
+ {
+ setTownIsGood((rset.getInt("isGood")==1)? true : false);
+ setTownIsEvil((rset.getInt("isEvil")==1)? true : false);
+ }
+ rset.close();
+ statement.close();
+
+ }
+ catch (Exception e)
+ {
+ }
+ finally
+ {
+ try { con.close(); } catch (Exception e) {}
+ }
+ }
+ public void storeFactionTowns()
+ {
+ Connection con = null;
+
+ try
+ {
+ con = L2DatabaseFactory.getInstance().getConnection();
+ PreparedStatement statement = con.prepareStatement(UPDATE_FACTION_TOWNS);
+
+ statement.setInt(1, FactionTownId());
+ statement.setInt(2, TownIsGood() ? 1 : 0);
+ statement.setInt(3, TownIsEvil() ? 1 : 0);
+ statement.execute();
+ statement.close();
+ }
+ catch (Exception e) {}
+ finally { try { con.close(); } catch (Exception e) {} }
+ }
+ public int FactionTownId()
+ {
+ return _FactionTownId;
+ }
+ public boolean TownIsGood()
+ {
+ return _TownIsGood;
+ }
+
+ public boolean TownIsEvil()
+ {
+ return _TownIsEvil;
+ }
+ public void setTownIsGood(boolean value)
+ {
+ _TownIsGood = value;
+ }
+
+ public void setTownIsEvil(boolean value)
+ {
+ _TownIsEvil = value;
+ }
+*/
+
+ /**
+ * @param i
+ */
}