Index: java/com/l2jserver/gameserver/model/actor/instance/L2FactionQuestManagerInstance.java
===================================================================
--- java/com/l2jserver/gameserver/model/actor/instance/L2FactionQuestManagerInstance.java (revision 0)
+++ java/com/l2jserver/gameserver/model/actor/instance/L2FactionQuestManagerInstance.java (revision 0)
@@ -0,0 +1,113 @@
+/*
+ * 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.model.actor.instance;
+
+import com.l2jserver.gameserver.ai.CtrlIntention;
+import com.l2jserver.gameserver.instancemanager.FactionManager;
+import com.l2jserver.gameserver.model.entity.faction.Faction;
+import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
+import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
+import com.l2jserver.gameserver.templates.chars.L2NpcTemplate;
+
+/**
+ * @author evill33t
+ */
+public class L2FactionQuestManagerInstance extends L2NpcInstance
+{
+ public L2FactionQuestManagerInstance(int objectId, L2NpcTemplate template)
+ {
+ super(objectId, template);
+ }
+
+ @Override
+ public void onAction (L2PcInstance player)
+ {
+ if (!canTarget(player)) return;
+
+ // Check if the L2PcInstance already target the L2NpcInstance
+ if (this != player.getTarget())
+ {
+ // Set the target of the L2PcInstance player
+ player.setTarget(this);
+ }
+ else
+ {
+ // Calculate the distance between the L2PcInstance and the L2NpcInstance
+ if (!canInteract(player))
+ {
+ // Notify the L2PcInstance AI with AI_INTENTION_INTERACT
+ player.getAI().setIntention(CtrlIntention.AI_INTENTION_INTERACT, this);
+ }
+ else
+ {
+ showMessageWindow(player);
+ }
+ }
+ // Send a Server->Client ActionFailed to the L2PcInstance in order to avoid that the client wait another packet
+ player.sendPacket(ActionFailed.STATIC_PACKET);
+ }
+
+ private void showMessageWindow(L2PcInstance player)
+ {
+ int factionId = getTemplate().getNpcFaction();
+ String factionName = getTemplate().getNpcFactionName();
+ String filename = "data/html/npcdefault.htm";
+ String replace = null;
+
+ if (factionId != 0)
+ {
+ filename = "data/html/faction/" + String.valueOf(factionId) + "/start.htm";
+ replace = getName();
+ }
+ sendHtmlMessage(player, filename, replace, factionName);
+ }
+
+ @Override
+ public void onBypassFeedback(L2PcInstance player, String command)
+ {
+ // Standard msg
+ int factionId = getTemplate().getNpcFaction();
+ Faction faction = FactionManager.getInstance().getFactions(factionId);
+ int factionPrice = faction.getPrice();
+ String filename = "data/html/npcdefault.htm";
+ String factionName = getTemplate().getNpcFactionName();
+ String replace = null;
+
+ if (factionId != 0)
+ {
+ String path = "data/html/faction" + String.valueOf(factionId) + "/";
+ replace = String.valueOf(factionPrice);
+
+ if (player.getNPCFaction() != null)
+ {
+ // Quest stuff here
+ }
+ else if (command.startsWith("Join"))
+ filename = path + "wrong.htm";
+ }
+ sendHtmlMessage(player, filename, replace, factionName);
+ }
+
+ private void sendHtmlMessage(L2PcInstance player, String filename, String replace, String factionName)
+ {
+ NpcHtmlMessage html = new NpcHtmlMessage(1);
+ html.setFile(filename, factionName);
+ html.replace("%objectId%", String.valueOf(getObjectId()));
+ html.replace("%replace%", replace);
+ html.replace("%npcname%", getName());
+ html.replace("%factionName%", factionName);
+ player.sendPacket(html);
+ }
+}
Index: java/com/l2jserver/gameserver/instancemanager/FactionQuestManager.java
===================================================================
--- java/com/l2jserver/gameserver/instancemanager/FactionQuestManager.java (revision 0)
+++ java/com/l2jserver/gameserver/instancemanager/FactionQuestManager.java (revision 0)
@@ -0,0 +1,128 @@
+/*
+ * 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 java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.util.logging.Logger;
+
+import javolution.util.FastList;
+
+import com.l2jserver.L2DatabaseFactory;
+import com.l2jserver.gameserver.model.entity.faction.Faction;
+import com.l2jserver.gameserver.model.entity.faction.FactionQuest;
+
+/**
+ * @author evill33t
+ *
+ */
+public class FactionQuestManager
+{
+ private static Logger _log = Logger.getLogger(Faction.class.getName());
+
+ private static final class SingletonHolder
+ {
+ private static final FactionQuestManager INSTANCE = new FactionQuestManager();
+ }
+
+ public static FactionQuestManager getInstance()
+ {
+ return SingletonHolder.INSTANCE;
+ }
+
+ // =========================================================
+ // Data Field
+ private FastList<FactionQuest> _quests;
+
+ // =========================================================
+ // Constructor
+ public FactionQuestManager()
+ {
+ load();
+ }
+
+ // =========================================================
+ // Method - Public
+ public final void reload()
+ {
+ getFactionQuests().clear();
+ load();
+ }
+
+ // =========================================================
+ // Method - Private
+ private final void load()
+ {
+ Connection con = null;
+ try
+ {
+ PreparedStatement statement;
+ ResultSet rs;
+
+ con = L2DatabaseFactory.getInstance().getConnection();
+
+ statement = con.prepareStatement("Select id, faction_id, name, description, reward, mobid, amount, min_level from faction_quests order by id");
+ rs = statement.executeQuery();
+ while (rs.next())
+ {
+ getFactionQuests().add(
+ new FactionQuest(rs.getInt("id"), rs.getInt("faction_id"), rs.getString("name"), rs.getString("description"), rs.getInt("reward"), rs
+ .getInt("mobid"), rs.getInt("amount"), rs.getInt("min_level")));
+ }
+
+ statement.close();
+
+ _log.info("Loaded: " + getFactionQuests().size() + " factionquests");
+ }
+ catch (Exception e)
+ {
+ _log.warning("Exception: FactionQuestManager.load(): " + e.getMessage());
+ }
+ finally
+ {
+ L2DatabaseFactory.close(con);
+ }
+ }
+
+ // =========================================================
+ // Property - Public
+ public final FactionQuest getFactionQuest(int questId)
+ {
+ int index = getFactionQuestIndex(questId);
+ if (index >= 0)
+ return getFactionQuests().get(index);
+ return null;
+ }
+
+ public final int getFactionQuestIndex(int questId)
+ {
+ FactionQuest quest;
+ for (int i = 0; i < getFactionQuests().size(); i++)
+ {
+ quest = getFactionQuests().get(i);
+ if (quest != null && quest.getId() == questId)
+ return i;
+ }
+ return -1;
+ }
+
+ public final FastList<FactionQuest> getFactionQuests()
+ {
+ if (_quests == null)
+ _quests = new FastList<FactionQuest>();
+ return _quests;
+ }
+}
Index: java/com/l2jserver/gameserver/instancemanager/FactionManager.java
===================================================================
--- java/com/l2jserver/gameserver/instancemanager/FactionManager.java (revision 0)
+++ java/com/l2jserver/gameserver/instancemanager/FactionManager.java (revision 0)
@@ -0,0 +1,140 @@
+/*
+ * 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 java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+
+import javolution.util.FastList;
+import javolution.util.FastMap;
+
+import java.util.logging.Logger;
+
+import com.l2jserver.L2DatabaseFactory;
+import com.l2jserver.gameserver.model.entity.faction.Faction;
+
+/**
+ * @author evill33t
+ *
+ */
+public class FactionManager
+{
+ private static Logger _log = Logger.getLogger(Faction.class.getName());
+
+ private static final class SingletonHolder
+ {
+ private static final FactionManager INSTANCE = new FactionManager();
+ }
+
+ public static FactionManager getInstance()
+ {
+ return SingletonHolder.INSTANCE;
+ }
+
+ private FactionManager()
+ {
+ _log.info("Initializing FactionManager");
+ load();
+ }
+
+ // =========================================================
+ // Data Field
+ private FastList<Faction> _factions;
+ private FastList<String> _listTitles = new FastList<String>();
+
+ // =========================================================
+ // Method - Public
+ public void reload()
+ {
+ getFactions().clear();
+ getFactionTitles().clear();
+ load();
+ }
+
+ // =========================================================
+ // Method - Private
+ private final void load()
+ {
+ Connection con = null;
+ try
+ {
+ PreparedStatement statement;
+ ResultSet rs;
+
+ con = L2DatabaseFactory.getInstance().getConnection();
+
+ statement = con.prepareStatement("Select id from factions order by id");
+ rs = statement.executeQuery();
+
+ while (rs.next())
+ {
+ Faction faction = new Faction(rs.getInt("id"));
+ getFactions().add(faction);
+ for (FastMap.Entry<Integer, String> e = faction.getTitle().head(), end = faction.getTitle().tail(); (e = e.getNext()) != end;)
+ _listTitles.add(e.getValue().toLowerCase());
+ faction = null;
+ }
+
+ statement.close();
+
+ _log.info("Loaded: " + getFactions().size() + " faction(s)");
+ }
+ catch (Exception e)
+ {
+ _log.warning("Exception: FactionsManager.load(): " + e.getMessage());
+ }
+ finally
+ {
+ L2DatabaseFactory.close(con);
+ }
+ }
+
+ // =========================================================
+ // Property - Public
+ public final Faction getFactions(int FactionId)
+ {
+ int index = getFactionIndex(FactionId);
+ if (index >= 0)
+ return getFactions().get(index);
+ return null;
+ }
+
+ public final int getFactionIndex(int FactionId)
+ {
+ Faction faction;
+ for (int i = 0; i < getFactions().size(); i++)
+ {
+ faction = getFactions().get(i);
+ if (faction != null && faction.getId() == FactionId)
+ return i;
+ }
+ return -1;
+ }
+
+ public final FastList<Faction> getFactions()
+ {
+ if (_factions == null)
+ _factions = new FastList<Faction>();
+ return _factions;
+ }
+
+ public final FastList<String> getFactionTitles()
+ {
+ if (_listTitles == null)
+ _listTitles = new FastList<String>();
+ return _listTitles;
+ }
+}
Index: java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java
===================================================================
--- java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java (revision 4014)
+++ java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java (working copy)
@@ -143,6 +143,7 @@
import com.l2jserver.gameserver.model.entity.L2Event;
import com.l2jserver.gameserver.model.entity.Siege;
import com.l2jserver.gameserver.model.entity.TvTEvent;
+import com.l2jserver.gameserver.model.entity.faction.FactionMember;
import com.l2jserver.gameserver.model.itemcontainer.Inventory;
import com.l2jserver.gameserver.model.itemcontainer.ItemContainer;
import com.l2jserver.gameserver.model.itemcontainer.PcInventory;
@@ -868,6 +869,9 @@
private int _engageid = 0;
private boolean _marryrequest = false;
private boolean _marryaccepted = false;
+
+ // Faction Engine
+ private FactionMember _faction;
/** Skill casting information (used to queue when several skills are cast in a short time) **/
public class SkillDat
@@ -5642,9 +5646,21 @@
)
)
increasePvpKills(target);
+ // Give the faction pvp points
+ if (Config.FACTION_ENABLED && targetPlayer.getSide() != getSide() && targetPlayer.getSide() != 0 && getSide() != 0 && Config.FACTION_KILL_REWARD)
+ increaseFactionKillPoints(targetPlayer.getLevel(), false);
else
// Target player doesn't have pvp flag set
{
+ // Check factions
+ if (Config.FACTION_ENABLED && targetPlayer.getSide() != getSide() && targetPlayer.getSide() != 0 && getSide() != 0 && Config.FACTION_KILL_REWARD)
+ {
+ // Give faction pk points
+ increaseFactionKillPoints(targetPlayer.getLevel(), true);
+ // No karma
+ return;
+ }
+
// check about wars
if (targetPlayer.getClan() != null && getClan() != null
&& getClan().isAtWarWith(targetPlayer.getClanId())
@@ -5671,6 +5687,20 @@
}
}
}
+
+ /**
+ * Increase the faction points depending on level
+ * PK Kills give half the points of a PVP Kill
+ */
+ public void increaseFactionKillPoints(int level, boolean pk)
+ {
+ int points;
+ points = (level / getLevel()) * (Config.FACTION_KILL_RATE / 100);
+ if (pk)
+ points /= 2;
+ _faction.addFactionPoints(points);
+ sendMessage("You earned " + String.valueOf(points) + " Facion Points");
+ }
/**
* Increase the pvp kills count and send the info to the player
@@ -12722,7 +12752,48 @@
{
_combatFlagEquippedId = value;
}
+
+ public void setNPCFaction(FactionMember fm)
+ {
+ _faction = fm;
+ }
+ public FactionMember getNPCFaction()
+ {
+ return _faction;
+ }
+
+ public boolean removeNPCFactionPoints(int factionPoints)
+ {
+ if (_faction != null)
+ {
+ if (_faction.getFactionPoints() < factionPoints)
+ return false;
+ _faction.reduceFactionPoints(factionPoints);
+ return true;
+ }
+ return false;
+ }
+
+ public int getNPCFactionPoints()
+ {
+ return _faction.getFactionPoints();
+ }
+
+ public int getSide()
+ {
+ return _faction.getSide();
+ }
+
+ public void quitNPCFaction()
+ {
+ if (_faction != null)
+ {
+ _faction.quitFaction();
+ _faction = null;
+ }
+ }
+
public boolean getCharmOfCourage()
{
return _charmOfCourage;
Index: java/com/l2jserver/L2DatabaseFactory.java
===================================================================
--- java/com/l2jserver/L2DatabaseFactory.java (revision 4014)
+++ java/com/l2jserver/L2DatabaseFactory.java (working copy)
@@ -210,6 +210,21 @@
return _instance;
}
+ public static void close(Connection con)
+ {
+ if (con == null)
+ return;
+
+ try
+ {
+ con.close();
+ }
+ catch (SQLException e)
+ {
+ _log.warning("L2DatabaseFactory: Failed to close database connection!");
+ }
+ }
+
public Connection getConnection() //throws SQLException
{
Connection con = null;
Index: java/com/l2jserver/gameserver/model/L2Object.java
===================================================================
--- java/com/l2jserver/gameserver/model/L2Object.java (revision 4014)
+++ java/com/l2jserver/gameserver/model/L2Object.java (working copy)
@@ -251,7 +251,7 @@
// =========================================================
// Event - Public
- public final void onAction(L2PcInstance player)
+ public void onAction(L2PcInstance player)
{
onAction(player, true);
}
Index: java/com/l2jserver/Config.java
===================================================================
--- java/com/l2jserver/Config.java (revision 4014)
+++ java/com/l2jserver/Config.java (working copy)
@@ -662,6 +662,10 @@
public static List<String> L2JMOD_MULTILANG_ALLOWED = new ArrayList<String>();
public static String L2JMOD_MULTILANG_DEFAULT;
public static boolean L2JMOD_MULTILANG_VOICED_ALLOW;
+ public static boolean FACTION_ENABLED = false;
+ public static boolean FACTION_KILL_REWARD = false;
+ public static int FACTION_KILL_RATE = 1000;
+ public static int FACTION_QUEST_RATE = 1;
//--------------------------------------------------
// NPC Settings
@@ -1962,6 +1966,11 @@
TVT_EVENT_RUNNING_TIME = Integer.parseInt(L2JModSettings.getProperty("TvTEventRunningTime", "1800"));
TVT_EVENT_PARTICIPATION_NPC_ID = Integer.parseInt(L2JModSettings.getProperty("TvTEventParticipationNpcId", "0"));
+ FACTION_ENABLED = Boolean.parseBoolean(L2JModSettings.getProperty("FactionEnabled", "false"));
+ FACTION_KILL_REWARD = Boolean.parseBoolean(L2JModSettings.getProperty("FactionKillReward", "false"));
+ FACTION_KILL_RATE = Integer.parseInt(L2JModSettings.getProperty("FactionKillRate", "1000"));
+ FACTION_QUEST_RATE = Integer.parseInt(L2JModSettings.getProperty("FactionQuestRate", "1"));
+
L2JMOD_ALLOW_WEDDING = Boolean.parseBoolean(L2JModSettings.getProperty("AllowWedding", "False"));
L2JMOD_WEDDING_PRICE = Integer.parseInt(L2JModSettings.getProperty("WeddingPrice", "250000000"));
L2JMOD_WEDDING_PUNISH_INFIDELITY = Boolean.parseBoolean(L2JModSettings.getProperty("WeddingPunishInfidelity", "True"));
Index: java/com/l2jserver/gameserver/model/actor/L2Character.java
===================================================================
--- java/com/l2jserver/gameserver/model/actor/L2Character.java (revision 4014)
+++ java/com/l2jserver/gameserver/model/actor/L2Character.java (working copy)
@@ -42,6 +42,7 @@
import com.l2jserver.gameserver.handler.ISkillHandler;
import com.l2jserver.gameserver.handler.SkillHandler;
import com.l2jserver.gameserver.instancemanager.DimensionalRiftManager;
+import com.l2jserver.gameserver.instancemanager.FactionManager;
import com.l2jserver.gameserver.instancemanager.InstanceManager;
import com.l2jserver.gameserver.instancemanager.TownManager;
import com.l2jserver.gameserver.model.ChanceSkillList;
@@ -2456,6 +2457,15 @@
/** Set the Title of the L2Character. */
public final void setTitle(String value)
{
+ if (Config.FACTION_ENABLED)
+ {
+ if (FactionManager.getInstance().getFactionTitles().contains(value.toLowerCase()) && !value.isEmpty())
+ {
+ sendMessage("Title protected by Faction System");
+ return;
+ }
+ }
+
if (value == null)
_title = "";
else
Index: java/config/l2jmods.properties
===================================================================
--- java/config/l2jmods.properties (revision 4014)
+++ java/config/l2jmods.properties (working copy)
@@ -355,3 +355,12 @@
# Default: True
MultiLangVoiceCommand = True
+# -------------------------------------------------------
+# evil33t's faction engine
+# -------------------------------------------------------
+# Do not change the values below!!
+# Only if you really know what you're doing!
+FactionEnabled = False
+FactionKillReward = False
+FactionKillRate = 1000
+FactionQuestRate = 1
Index: java/com/l2jserver/gameserver/templates/chars/L2NpcTemplate.java
===================================================================
--- java/com/l2jserver/gameserver/templates/chars/L2NpcTemplate.java (revision 4014)
+++ java/com/l2jserver/gameserver/templates/chars/L2NpcTemplate.java (working copy)
@@ -71,6 +71,8 @@
public final int enchantEffect;
public final int absorbLevel;
public final AbsorbCrystalType absorbType;
+ private int npcFaction;
+ private String npcFactionName;
public Race race;
public final String jClass;
public final boolean dropherb;
@@ -215,6 +217,8 @@
enchantEffect = set.getInteger("enchant");
absorbLevel = set.getInteger("absorb_level", 0);
absorbType = AbsorbCrystalType.valueOf(set.getString("absorb_type"));
+ npcFaction = set.getInteger("NPCFaction", 0);
+ npcFactionName = set.getString("NPCFactionName", "Devine Clan").intern();
race = null;
dropherb = set.getBool("drop_herbs", false);
//_npcStatsSet = set;
@@ -529,7 +533,30 @@
}
}
+ public int getNpcFaction()
+ {
+ return npcFaction;
+ }
+
+ public void setNpcFaction(int npcFaction)
+ {
+ npcFaction = npcFaction;
+ }
+
+ public String getNpcFactionName()
+ {
+ return npcFactionName;
+ }
+
/**
+ * @param factionName the nPCFactionName to set
+ */
+ public void setNPCFactionName(String factionName)
+ {
+ npcFactionName = (factionName == null ? "Devine Clan" : factionName);
+ }
+
+ /**
* Checks if obj can be assigned to the Class represented by clazz.<br>
* This is true if, and only if, obj is the same class represented by clazz,
* or a subclass of it or obj implements the interface represented by clazz.
Index: java/com/l2jserver/gameserver/model/entity/faction/FactionMember.java
===================================================================
--- java/com/l2jserver/gameserver/model/entity/faction/FactionMember.java (revision 0)
+++ java/com/l2jserver/gameserver/model/entity/faction/FactionMember.java (revision 0)
@@ -0,0 +1,217 @@
+/*
+ * 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.model.entity.faction;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+
+import java.util.logging.Logger;
+
+import com.l2jserver.L2DatabaseFactory;
+import com.l2jserver.gameserver.instancemanager.FactionManager;
+
+/**
+ * @author evill33t
+ *
+ */
+public class FactionMember
+{
+ private static Logger _log = Logger.getLogger(Faction.class.getName());
+
+ // =========================================================
+ // Data Field
+ private int _playerId = 0;
+ private int _factionId = 0;
+ private int _factionPoints = 0;
+ private int _contributions = 0;
+ private long _joinDate;
+ private int _side;
+
+
+ // =========================================================
+ // Constructor
+ public FactionMember(int playerId)
+ {
+ _playerId = playerId;
+
+ Connection con = null;
+ try
+ {
+ PreparedStatement statement;
+ ResultSet rs;
+
+ con = L2DatabaseFactory.getInstance().getConnection();
+
+ statement = con.prepareStatement("Select * from faction_members where player_id = ?");
+ statement.setInt(1, _playerId);
+ rs = statement.executeQuery();
+
+ while (rs.next())
+ {
+ _factionId = rs.getInt("faction_id");
+ _factionPoints = rs.getInt("faction_points");
+ _contributions = rs.getInt("contributions");
+ _joinDate = rs.getLong("join_date");
+ Faction faction = FactionManager.getInstance().getFactions(_factionId);
+ if(faction!=null)
+ {
+ _side = faction.getSide();
+ }
+
+ }
+ statement.close();
+ }
+ catch (Exception e)
+ {
+ _log.warning("Exception: FactionMember.load(): " + e.getMessage());
+ }
+ finally
+ {
+ L2DatabaseFactory.close(con);
+ }
+ }
+
+ public FactionMember(int playerId, int factionId)
+ {
+ _playerId = playerId;
+ _factionId = factionId;
+ _factionPoints = 0;
+ _contributions = 0;
+ _joinDate = System.currentTimeMillis();
+ Connection con = null;
+ try
+ {
+ con = L2DatabaseFactory.getInstance().getConnection();
+ PreparedStatement statement;
+ statement = con.prepareStatement("INSERT INTO faction_members (player_id, faction_id, faction_points, contributions, join_date) VALUES (?, ?, 0, 0, ?)");
+ statement.setInt(1, _playerId);
+ statement.setInt(2, _factionId);
+ statement.setLong(3, _joinDate);
+ statement.execute();
+ statement.close();
+ }
+ catch (Exception e)
+ {
+ _log.warning("");
+ }
+ finally
+ {
+ L2DatabaseFactory.close(con);
+ }
+ }
+
+ public void quitFaction()
+ {
+ Connection con = null;
+ _factionId = 0;
+ _factionPoints = 0;
+ _contributions = 0;
+ try
+ {
+ con = L2DatabaseFactory.getInstance().getConnection();
+ PreparedStatement statement;
+
+ statement = con.prepareStatement("DELETE FROM faction_members WHERE player_id=?");
+ statement.setInt(1, _playerId);
+ statement.execute();
+ statement.close();
+ }
+ catch (Exception e)
+ {
+ _log.warning("Exception: FactionMember.quitFaction(): " + e.getMessage());
+ }
+ finally
+ {
+ L2DatabaseFactory.close(con);
+ }
+ }
+
+ private void updateDb()
+ {
+ Connection con = null;
+ try
+ {
+ con = L2DatabaseFactory.getInstance().getConnection();
+ PreparedStatement statement;
+
+ statement = con.prepareStatement("UPDATE faction_members SET faction_points=?,contributions=?,faction_id=? WHERE player_id=?");
+ statement.setInt(1, _factionPoints);
+ statement.setInt(2, _contributions);
+ statement.setInt(3, _factionId);
+ statement.setInt(4, _playerId);
+ statement.execute();
+ statement.close();
+ }
+ catch (Exception e)
+ {
+ _log.warning("Exception: FactionMember.updateDb(): " + e.getMessage());
+ }
+ finally
+ {
+ L2DatabaseFactory.close(con);
+ }
+ }
+
+ public void addFactionPoints(int amount)
+ {
+ _factionPoints += amount;
+ updateDb();
+ }
+
+ public void addContributions(int amount)
+ {
+ _contributions += amount;
+ updateDb();
+ }
+
+
+ public boolean reduceFactionPoints(int amount)
+ {
+ if(amount<getFactionPoints())
+ {
+ _factionPoints -= amount;
+ updateDb();
+ return true;
+ }
+
+ return false;
+ }
+
+ public void setFactionPoints(int amount)
+ {
+ _factionPoints = amount;
+ updateDb();
+ }
+
+ public void setContribution(int amount)
+ {
+ _factionPoints = amount;
+ updateDb();
+ }
+
+ public void setFactionId(int factionId)
+ {
+ _factionId = factionId;
+ updateDb();
+ }
+
+ public final int getPlayerId() { return _playerId; }
+ public final int getFactionId() { return _factionId; }
+ public final int getSide() { return _side; }
+ public final int getFactionPoints() { return _factionPoints; }
+ public final int getContributions() { return _contributions; }
+ public final long getJoinDate() { return _joinDate; }
+}
Index: java/com/l2jserver/gameserver/model/actor/instance/L2FactionManagerInstance.java
===================================================================
--- java/com/l2jserver/gameserver/model/actor/instance/L2FactionManagerInstance.java (revision 0)
+++ java/com/l2jserver/gameserver/model/actor/instance/L2FactionManagerInstance.java (revision 0)
@@ -0,0 +1,153 @@
+/*
+ * 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.model.actor.instance;
+
+import com.l2jserver.gameserver.ai.CtrlIntention;
+import com.l2jserver.gameserver.instancemanager.FactionManager;
+import com.l2jserver.gameserver.model.entity.faction.Faction;
+import com.l2jserver.gameserver.model.entity.faction.FactionMember;
+import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
+import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
+import com.l2jserver.gameserver.templates.chars.L2NpcTemplate;
+
+/**
+ * @author evill33t
+ */
+public class L2FactionManagerInstance extends L2NpcInstance
+{
+ public L2FactionManagerInstance(int objectId, L2NpcTemplate template)
+ {
+ super(objectId, template);
+ }
+
+ @Override
+ public void onAction(L2PcInstance player)
+ {
+ if (!canTarget(player)) return;
+
+ // Check if the L2PcInstance already target the L2NpcInstance
+ if (this != player.getTarget())
+ {
+ // Set the target of the L2PcInstance player
+ player.setTarget(this);
+ }
+ else
+ {
+ // Calculate the distance between the L2PcInstance and the L2NpcInstance
+ if (!canInteract(player))
+ {
+ // Notify the L2PcInstance AI with AI_INTENTION_INTERACT
+ player.getAI().setIntention(CtrlIntention.AI_INTENTION_INTERACT, this);
+ }
+ else
+ {
+ showMessageWindow(player);
+ }
+ }
+ // Send a Server->Client ActionFailed to the L2PcInstance in order to avoid that the client wait another packet
+ player.sendPacket(ActionFailed.STATIC_PACKET);
+ }
+
+ private void showMessageWindow(L2PcInstance player)
+ {
+ int factionId = getTemplate().getNpcFaction();
+ String filename = "data/html/npcdefault.htm";
+ String factionName = getTemplate().getNpcFactionName();
+ String replace = null;
+
+ if (factionId != 0)
+ {
+ filename = "data/html/custom/faction/" + String.valueOf(factionId) + "/start.htm";
+ replace = getName();
+ }
+ sendHtmlMessage(player, filename, replace, factionName);
+ }
+
+ @Override
+ public void onBypassFeedback(L2PcInstance player, String command)
+ {
+ // Standard msg
+ String filename = "data/html/npcdefault.htm";
+ String factionName = getTemplate().getNpcFactionName();
+ int factionId = getTemplate().getNpcFaction();
+ Faction faction = FactionManager.getInstance().getFactions(factionId);
+ int factionPrice = faction.getPrice();
+ String replace = null;
+
+ if (factionId != 0)
+ {
+ String path = "data/html/custom/faction/" + String.valueOf(factionId) + "/";
+ replace = String.valueOf(factionPrice);
+
+ if (player.getNPCFaction() != null)
+ {
+ if(player.getNPCFaction().getSide()!=faction.getSide())
+ filename = path + "already.htm";
+ else
+ filename = path + "switch.htm";
+ }
+ else if (command.startsWith("Join"))
+ filename = path + "join.htm";
+ else if (command.startsWith("Accept"))
+ {
+ if (player.getNPCFaction() == null)
+ {
+ if (player.getAdena() < factionPrice)
+ filename = path + "noadena.htm";
+ else
+ {
+ player.getInventory().reduceAdena("Faction", factionPrice, player, null);
+ player.setNPCFaction(new FactionMember(player.getObjectId(),factionId));
+ filename = path + "accepted.htm";
+ }
+ }
+ else
+ {
+ player.getNPCFaction().setFactionId(factionId);
+ filename = path + "switched.htm";
+ }
+ }
+ else if (command.startsWith("Decline"))
+ filename = path + "declined.htm";
+ else if (command.startsWith("AskQuit"))
+ filename = path + "askquit.htm";
+ else if (command.startsWith("Story"))
+ filename = path + "story.htm";
+ else if (command.startsWith("Quit"))
+ {
+ player.quitNPCFaction();
+ filename = path + "quited.htm";
+ }
+ else if (command.startsWith("Quest"))
+ {
+ filename = path + "quest.htm";
+ }
+ else if (command.startsWith("FactionShop"))
+ filename = path + "shop.htm";
+ }
+ sendHtmlMessage(player, filename, replace, factionName);
+ }
+
+ private void sendHtmlMessage(L2PcInstance player, String filename, String replace, String factionName)
+ {
+ NpcHtmlMessage html = new NpcHtmlMessage(1);
+ html.setFile(filename, filename);
+ html.replace("%objectId%", String.valueOf(getObjectId()));
+ html.replace("%replace%", replace);
+ html.replace("%npcname%", getName());
+ html.replace("%factionName%", factionName);
+ player.sendPacket(html);
+ }
+}
Index: java/com/l2jserver/gameserver/model/entity/faction/Faction.java
===================================================================
--- java/com/l2jserver/gameserver/model/entity/faction/Faction.java (revision 0)
+++ java/com/l2jserver/gameserver/model/entity/faction/Faction.java (revision 0)
@@ -0,0 +1,147 @@
+/*
+ * 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.model.entity.faction;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+
+import javolution.util.FastList;
+import javolution.util.FastMap;
+
+import java.util.logging.Logger;
+
+import com.l2jserver.L2DatabaseFactory;
+
+/**
+ * @author evill33t
+ *
+ */
+public class Faction
+{
+ private static Logger _log = Logger.getLogger(Faction.class.getName());
+
+ private int _Id = 0;
+ private String _name = null;
+ private float _points = 0;
+ private int _joinprice = 0;
+ private int _side = 0; // 0 = Neutral 1 = Good 2 = Evil
+ private final FastList<Integer> _list_classes = new FastList<Integer>();
+ private final FastList<Integer> _list_npcs = new FastList<Integer>();
+ private final FastMap<Integer, String> _list_title = new FastMap<Integer, String>();
+
+ public Faction(int factionId)
+ {
+ _Id = factionId;
+ String _classlist = "";
+ String _npclist = "";
+ String _titlelist = "";
+ int _tside = 0;
+
+ Connection con = null;
+ try
+ {
+ PreparedStatement statement;
+ ResultSet rs;
+
+ con = L2DatabaseFactory.getInstance().getConnection();
+
+ statement = con.prepareStatement("Select * from factions where id = ?");
+ statement.setInt(1, getId());
+ rs = statement.executeQuery();
+
+ while (rs.next())
+ {
+ _name = rs.getString("name");
+ _joinprice = rs.getInt("price");
+ _classlist = rs.getString("allowed_classes");
+ _titlelist = rs.getString("titlelist");
+ _npclist = rs.getString("npcs");
+ _points = rs.getFloat("points");
+ _tside = rs.getInt("side");
+ }
+ statement.close();
+
+ if (_tside <= 2)
+ _side = _tside;
+
+ if (_classlist.length() > 0)
+ for (String id : _classlist.split(","))
+ _list_classes.add(Integer.parseInt(id));
+
+ if (_npclist.length() > 0)
+ for (String id : _npclist.split(","))
+ _list_npcs.add(Integer.parseInt(id));
+
+ if (_titlelist.length() > 0)
+ for (String id : _titlelist.split(";"))
+ _list_title.put(Integer.valueOf(id.split(",")[0]),id.split(",")[1]);
+ }
+ catch (Exception e)
+ {
+ _log.warning("Exception: Faction load: " + e.getMessage());
+ }
+ finally
+ {
+ L2DatabaseFactory.close(con);
+ }
+ }
+
+ private void updateDB()
+ {
+ Connection con = null;
+ try
+ {
+ PreparedStatement statement;
+
+ con = L2DatabaseFactory.getInstance().getConnection();
+
+ statement = con.prepareStatement("update factions set points = ? where id = ?");
+ statement.setFloat(1, _points);
+ statement.setInt(2, _Id);
+ statement.execute();
+ statement.close();
+ }
+ catch (Exception e)
+ {
+ _log.warning("Exception: Faction.load(): " + e.getMessage());
+ }
+ finally
+ {
+ L2DatabaseFactory.close(con);
+ }
+ }
+
+ public void addPoints(int points)
+ {
+ _points+=points;
+ updateDB();
+ }
+
+ public void clearPoints()
+ {
+ _points = 0;
+ updateDB();
+ }
+
+ public final int getId() { return _Id; }
+ public final String getName() { return _name; }
+ public final float getPoints() { return _points; }
+ public final FastList<Integer> getClassList(){ return _list_classes; }
+ public final FastList<Integer> getNpcList(){ return _list_npcs; }
+ public final FastMap<Integer, String> getTitle(){ return _list_title; }
+ public final int getPrice() { return _joinprice; }
+ public final int getSide() { return _side; }
+}
Index: java/com/l2jserver/gameserver/model/entity/faction/FactionQuest.java
===================================================================
--- java/com/l2jserver/gameserver/model/entity/faction/FactionQuest.java (revision 0)
+++ java/com/l2jserver/gameserver/model/entity/faction/FactionQuest.java (revision 0)
@@ -0,0 +1,116 @@
+/*
+ * 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.model.entity.faction;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+
+import java.util.logging.Logger;
+
+import com.l2jserver.Config;
+import com.l2jserver.L2DatabaseFactory;
+import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
+
+/**
+ * @author evill33t
+ *
+ */
+public class FactionQuest
+{
+ private static Logger _log = Logger.getLogger(Faction.class.getName());
+
+ private final int _questId;
+ private static int _factionId;
+ private static String _name;
+ private static String _descr;
+ private static int _reward;
+ private static int _mobId;
+ private static int _amount;
+ private static int _minLevel;
+
+ public FactionQuest(int questId, int factionId, String name, String descr, int reward, int mobId, int amount, int minLevel)
+ {
+ _questId = questId;
+ _factionId = factionId;
+ _name = name;
+ _descr = descr;
+ _reward = reward;
+ _mobId = mobId;
+ _amount = amount;
+ _minLevel = minLevel;
+ }
+
+ public int getId() { return _questId; }
+ public static String getName() { return _name; }
+ public static String getDescr() { return _descr;}
+ public static int getReward() { return _reward;}
+ public static int getAmount() { return _amount;}
+ public static int getMobId() { return _mobId;}
+ public static int getFactionId() { return _factionId;}
+ public static int getMinLevel() { return _minLevel;}
+
+ public static void createFactionQuest(L2PcInstance player,int factionQuestId)
+ {
+ Connection con = null;
+ try
+ {
+ con = L2DatabaseFactory.getInstance().getConnection();
+ PreparedStatement statement;
+ statement = con.prepareStatement("INSERT INTO character_faction_quests (char_id,faction_quest_id) VALUES (?,?)");
+ statement.setInt (1, player.getObjectId());
+ statement.setInt (2, factionQuestId);
+ statement.executeUpdate();
+ statement.close();
+ }
+ catch (Exception e)
+ {
+ _log.warning( "could not insert char faction quest:");
+ }
+ finally
+ {
+ L2DatabaseFactory.close(con);
+ }
+ }
+
+ public static void endFactionQuest(L2PcInstance player,int factionQuestId)
+ {
+ player.sendMessage(getName()+" completed.");
+ player.getNPCFaction().addFactionPoints(getReward()*Config.FACTION_QUEST_RATE);
+ deleteFactionQuest(player,factionQuestId);
+ }
+
+ public static void deleteFactionQuest(L2PcInstance player,int factionQuestId)
+ {
+ Connection con = null;
+ try
+ {
+ con = L2DatabaseFactory.getInstance().getConnection();
+ PreparedStatement statement;
+ statement = con.prepareStatement("DELETE FROM character_faction_quests WHERE char_id=? AND faction_quest_id=?");
+ statement.setInt (1, player.getObjectId());
+ statement.setInt (2, factionQuestId);
+ statement.executeUpdate();
+ statement.close();
+ }
+ catch (Exception e)
+ {
+ _log.warning( "could not delete char faction quest:");
+ }
+ finally
+ {
+ L2DatabaseFactory.close(con);
+ }
+ }
+}