Share Pastebin
Guest
Public paste!

Coyote

By: a guest | Mar 21st, 2010 | Syntax: Java | Size: 44.83 KB | Hits: 699 | Expires: Never
Copy text to clipboard
  1. Index: java/com/l2jserver/gameserver/model/actor/instance/L2FactionQuestManagerInstance.java
  2. ===================================================================
  3. --- java/com/l2jserver/gameserver/model/actor/instance/L2FactionQuestManagerInstance.java       (revision 0)
  4. +++ java/com/l2jserver/gameserver/model/actor/instance/L2FactionQuestManagerInstance.java       (revision 0)
  5. @@ -0,0 +1,113 @@
  6. +/*
  7. + * This program is free software: you can redistribute it and/or modify it under
  8. + * the terms of the GNU General Public License as published by the Free Software
  9. + * Foundation, either version 3 of the License, or (at your option) any later
  10. + * version.
  11. + *
  12. + * This program is distributed in the hope that it will be useful, but WITHOUT
  13. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  14. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  15. + * details.
  16. + *
  17. + * You should have received a copy of the GNU General Public License along with
  18. + * this program. If not, see <http://www.gnu.org/licenses/>.
  19. + */
  20. +package com.l2jserver.gameserver.model.actor.instance;
  21. +
  22. +import com.l2jserver.gameserver.ai.CtrlIntention;
  23. +import com.l2jserver.gameserver.instancemanager.FactionManager;
  24. +import com.l2jserver.gameserver.model.entity.faction.Faction;
  25. +import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  26. +import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  27. +import com.l2jserver.gameserver.templates.chars.L2NpcTemplate;
  28. +
  29. +/**
  30. + * @author evill33t
  31. + */
  32. +public class L2FactionQuestManagerInstance extends L2NpcInstance
  33. +{
  34. +    public L2FactionQuestManagerInstance(int objectId, L2NpcTemplate template)
  35. +    {
  36. +        super(objectId, template);
  37. +    }
  38. +
  39. +       @Override
  40. +       public void onAction (L2PcInstance player)
  41. +       {
  42. +               if (!canTarget(player)) return;
  43. +
  44. +               // Check if the L2PcInstance already target the L2NpcInstance
  45. +               if (this != player.getTarget())
  46. +               {
  47. +                       // Set the target of the L2PcInstance player
  48. +                       player.setTarget(this);
  49. +               }
  50. +               else
  51. +               {
  52. +                       // Calculate the distance between the L2PcInstance and the L2NpcInstance
  53. +                       if (!canInteract(player))
  54. +                       {
  55. +                               // Notify the L2PcInstance AI with AI_INTENTION_INTERACT
  56. +                               player.getAI().setIntention(CtrlIntention.AI_INTENTION_INTERACT, this);
  57. +                       }
  58. +                       else
  59. +                       {
  60. +                               showMessageWindow(player);
  61. +                       }
  62. +               }
  63. +               // Send a Server->Client ActionFailed to the L2PcInstance in order to avoid that the client wait another packet
  64. +               player.sendPacket(ActionFailed.STATIC_PACKET);
  65. +       }
  66. +    
  67. +    private void showMessageWindow(L2PcInstance player)
  68. +    {
  69. +        int factionId = getTemplate().getNpcFaction();
  70. +        String factionName = getTemplate().getNpcFactionName();
  71. +        String filename = "data/html/npcdefault.htm";
  72. +        String replace = null;
  73. +
  74. +        if (factionId != 0)
  75. +        {
  76. +            filename = "data/html/faction/" + String.valueOf(factionId)  +  "/start.htm";
  77. +            replace = getName();
  78. +        }
  79. +        sendHtmlMessage(player, filename, replace, factionName);
  80. +    }
  81. +    
  82. +    @Override
  83. +    public void onBypassFeedback(L2PcInstance player, String command)
  84. +    {
  85. +        // Standard msg
  86. +        int factionId = getTemplate().getNpcFaction();
  87. +        Faction faction = FactionManager.getInstance().getFactions(factionId);
  88. +        int factionPrice = faction.getPrice();
  89. +        String filename = "data/html/npcdefault.htm";
  90. +        String factionName = getTemplate().getNpcFactionName();
  91. +        String replace = null;
  92. +
  93. +        if (factionId != 0)
  94. +        {
  95. +            String path = "data/html/faction" + String.valueOf(factionId) + "/";
  96. +            replace = String.valueOf(factionPrice);
  97. +            
  98. +            if (player.getNPCFaction() != null)
  99. +            {
  100. +                // Quest stuff here
  101. +            }
  102. +            else if (command.startsWith("Join"))
  103. +                filename = path + "wrong.htm";
  104. +        }
  105. +        sendHtmlMessage(player, filename, replace, factionName);
  106. +    }
  107. +
  108. +    private void sendHtmlMessage(L2PcInstance player, String filename, String replace, String factionName)
  109. +    {
  110. +        NpcHtmlMessage html = new NpcHtmlMessage(1);
  111. +        html.setFile(filename, factionName);
  112. +        html.replace("%objectId%", String.valueOf(getObjectId()));
  113. +        html.replace("%replace%", replace);
  114. +        html.replace("%npcname%", getName());
  115. +        html.replace("%factionName%", factionName);
  116. +        player.sendPacket(html);
  117. +    }
  118. +}
  119. Index: java/com/l2jserver/gameserver/instancemanager/FactionQuestManager.java
  120. ===================================================================
  121. --- java/com/l2jserver/gameserver/instancemanager/FactionQuestManager.java      (revision 0)
  122. +++ java/com/l2jserver/gameserver/instancemanager/FactionQuestManager.java      (revision 0)
  123. @@ -0,0 +1,128 @@
  124. +/*
  125. + * This program is free software: you can redistribute it and/or modify it under
  126. + * the terms of the GNU General Public License as published by the Free Software
  127. + * Foundation, either version 3 of the License, or (at your option) any later
  128. + * version.
  129. + *
  130. + * This program is distributed in the hope that it will be useful, but WITHOUT
  131. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  132. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  133. + * details.
  134. + *
  135. + * You should have received a copy of the GNU General Public License along with
  136. + * this program. If not, see <http://www.gnu.org/licenses/>.
  137. + */
  138. +package com.l2jserver.gameserver.instancemanager;
  139. +
  140. +import java.sql.Connection;
  141. +import java.sql.PreparedStatement;
  142. +import java.sql.ResultSet;
  143. +import java.util.logging.Logger;
  144. +
  145. +import javolution.util.FastList;
  146. +
  147. +import com.l2jserver.L2DatabaseFactory;
  148. +import com.l2jserver.gameserver.model.entity.faction.Faction;
  149. +import com.l2jserver.gameserver.model.entity.faction.FactionQuest;
  150. +
  151. +/**
  152. + * @author evill33t
  153. + *
  154. + */
  155. +public class FactionQuestManager
  156. +{
  157. +       private static Logger _log = Logger.getLogger(Faction.class.getName());
  158. +      
  159. +       private static final class SingletonHolder
  160. +       {
  161. +               private static final FactionQuestManager INSTANCE = new FactionQuestManager();
  162. +       }
  163. +      
  164. +       public static FactionQuestManager getInstance()
  165. +       {
  166. +               return SingletonHolder.INSTANCE;
  167. +       }
  168. +      
  169. +       // =========================================================
  170. +       // Data Field
  171. +       private FastList<FactionQuest>  _quests;
  172. +
  173. +       // =========================================================
  174. +       // Constructor
  175. +       public FactionQuestManager()
  176. +       {
  177. +               load();
  178. +       }
  179. +
  180. +       // =========================================================
  181. +       // Method - Public
  182. +       public final void reload()
  183. +       {
  184. +               getFactionQuests().clear();
  185. +               load();
  186. +       }
  187. +
  188. +       // =========================================================
  189. +       // Method - Private
  190. +       private final void load()
  191. +       {
  192. +               Connection con = null;
  193. +               try
  194. +               {
  195. +                       PreparedStatement statement;
  196. +                       ResultSet rs;
  197. +
  198. +                       con = L2DatabaseFactory.getInstance().getConnection();
  199. +
  200. +                       statement = con.prepareStatement("Select id, faction_id, name, description, reward, mobid, amount, min_level from faction_quests order by id");
  201. +                       rs = statement.executeQuery();
  202. +                       while (rs.next())
  203. +                       {
  204. +                               getFactionQuests().add(
  205. +                                               new FactionQuest(rs.getInt("id"), rs.getInt("faction_id"), rs.getString("name"), rs.getString("description"), rs.getInt("reward"), rs
  206. +                                                               .getInt("mobid"), rs.getInt("amount"), rs.getInt("min_level")));
  207. +                       }
  208. +
  209. +                       statement.close();
  210. +
  211. +                       _log.info("Loaded: " + getFactionQuests().size() + " factionquests");
  212. +               }
  213. +               catch (Exception e)
  214. +               {
  215. +                       _log.warning("Exception: FactionQuestManager.load(): " + e.getMessage());
  216. +               }
  217. +               finally
  218. +               {
  219. +                       L2DatabaseFactory.close(con);
  220. +               }
  221. +       }
  222. +
  223. +       // =========================================================
  224. +       // Property - Public
  225. +       public final FactionQuest getFactionQuest(int questId)
  226. +       {
  227. +               int index = getFactionQuestIndex(questId);
  228. +               if (index >= 0)
  229. +                       return getFactionQuests().get(index);
  230. +               return null;
  231. +       }
  232. +
  233. +       public final int getFactionQuestIndex(int questId)
  234. +       {
  235. +               FactionQuest quest;
  236. +               for (int i = 0; i < getFactionQuests().size(); i++)
  237. +               {
  238. +                       quest = getFactionQuests().get(i);
  239. +                       if (quest != null && quest.getId() == questId)
  240. +                               return i;
  241. +               }
  242. +               return -1;
  243. +       }
  244. +
  245. +       public final FastList<FactionQuest> getFactionQuests()
  246. +       {
  247. +               if (_quests == null)
  248. +                       _quests = new FastList<FactionQuest>();
  249. +               return _quests;
  250. +       }
  251. +}
  252. Index: java/com/l2jserver/gameserver/instancemanager/FactionManager.java
  253. ===================================================================
  254. --- java/com/l2jserver/gameserver/instancemanager/FactionManager.java   (revision 0)
  255. +++ java/com/l2jserver/gameserver/instancemanager/FactionManager.java   (revision 0)
  256. @@ -0,0 +1,140 @@
  257. +/*
  258. + * This program is free software: you can redistribute it and/or modify it under
  259. + * the terms of the GNU General Public License as published by the Free Software
  260. + * Foundation, either version 3 of the License, or (at your option) any later
  261. + * version.
  262. + *
  263. + * This program is distributed in the hope that it will be useful, but WITHOUT
  264. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  265. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  266. + * details.
  267. + *
  268. + * You should have received a copy of the GNU General Public License along with
  269. + * this program. If not, see <http://www.gnu.org/licenses/>.
  270. + */
  271. +package com.l2jserver.gameserver.instancemanager;
  272. +
  273. +import java.sql.Connection;
  274. +import java.sql.PreparedStatement;
  275. +import java.sql.ResultSet;
  276. +
  277. +import javolution.util.FastList;
  278. +import javolution.util.FastMap;
  279. +
  280. +import java.util.logging.Logger;
  281. +
  282. +import com.l2jserver.L2DatabaseFactory;
  283. +import com.l2jserver.gameserver.model.entity.faction.Faction;
  284. +
  285. +/**
  286. + * @author evill33t
  287. + *
  288. + */
  289. +public class FactionManager
  290. +{
  291. +       private static Logger _log = Logger.getLogger(Faction.class.getName());
  292. +      
  293. +       private static final class SingletonHolder
  294. +       {
  295. +               private static final FactionManager INSTANCE = new FactionManager();
  296. +       }
  297. +      
  298. +       public static FactionManager getInstance()
  299. +       {
  300. +               return SingletonHolder.INSTANCE;
  301. +       }
  302. +      
  303. +       private FactionManager()
  304. +       {
  305. +               _log.info("Initializing FactionManager");
  306. +               load();
  307. +       }
  308. +
  309. +       // =========================================================
  310. +       // Data Field
  311. +       private FastList<Faction>       _factions;
  312. +       private FastList<String>        _listTitles     = new FastList<String>();
  313. +
  314. +       // =========================================================
  315. +       // Method - Public
  316. +       public void reload()
  317. +       {
  318. +               getFactions().clear();
  319. +               getFactionTitles().clear();
  320. +               load();
  321. +       }
  322. +
  323. +       // =========================================================
  324. +       // Method - Private
  325. +       private final void load()
  326. +       {
  327. +               Connection con = null;
  328. +               try
  329. +               {
  330. +                       PreparedStatement statement;
  331. +                       ResultSet rs;
  332. +
  333. +                       con = L2DatabaseFactory.getInstance().getConnection();
  334. +
  335. +                       statement = con.prepareStatement("Select id from factions order by id");
  336. +                       rs = statement.executeQuery();
  337. +
  338. +                       while (rs.next())
  339. +                       {
  340. +                               Faction faction = new Faction(rs.getInt("id"));
  341. +                               getFactions().add(faction);
  342. +                               for (FastMap.Entry<Integer, String> e = faction.getTitle().head(), end = faction.getTitle().tail(); (e = e.getNext()) != end;)
  343. +                                       _listTitles.add(e.getValue().toLowerCase());
  344. +                               faction = null;
  345. +                       }
  346. +
  347. +                       statement.close();
  348. +
  349. +                       _log.info("Loaded: " + getFactions().size() + " faction(s)");
  350. +               }
  351. +               catch (Exception e)
  352. +               {
  353. +                       _log.warning("Exception: FactionsManager.load(): " + e.getMessage());
  354. +               }
  355. +               finally
  356. +               {
  357. +                       L2DatabaseFactory.close(con);
  358. +               }
  359. +       }
  360. +
  361. +       // =========================================================
  362. +       // Property - Public
  363. +       public final Faction getFactions(int FactionId)
  364. +       {
  365. +               int index = getFactionIndex(FactionId);
  366. +               if (index >= 0)
  367. +                       return getFactions().get(index);
  368. +               return null;
  369. +       }
  370. +
  371. +       public final int getFactionIndex(int FactionId)
  372. +       {
  373. +               Faction faction;
  374. +               for (int i = 0; i < getFactions().size(); i++)
  375. +               {
  376. +                       faction = getFactions().get(i);
  377. +                       if (faction != null && faction.getId() == FactionId)
  378. +                               return i;
  379. +               }
  380. +               return -1;
  381. +       }
  382. +
  383. +       public final FastList<Faction> getFactions()
  384. +       {
  385. +               if (_factions == null)
  386. +                       _factions = new FastList<Faction>();
  387. +               return _factions;
  388. +       }
  389. +
  390. +       public final FastList<String> getFactionTitles()
  391. +       {
  392. +               if (_listTitles == null)
  393. +                       _listTitles = new FastList<String>();
  394. +               return _listTitles;
  395. +       }
  396. +}
  397. Index: java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java
  398. ===================================================================
  399. --- java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java        (revision 4014)
  400. +++ java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java        (working copy)
  401. @@ -143,6 +143,7 @@
  402.  import com.l2jserver.gameserver.model.entity.L2Event;
  403.  import com.l2jserver.gameserver.model.entity.Siege;
  404.  import com.l2jserver.gameserver.model.entity.TvTEvent;
  405. +import com.l2jserver.gameserver.model.entity.faction.FactionMember;
  406.  import com.l2jserver.gameserver.model.itemcontainer.Inventory;
  407.  import com.l2jserver.gameserver.model.itemcontainer.ItemContainer;
  408.  import com.l2jserver.gameserver.model.itemcontainer.PcInventory;
  409. @@ -868,6 +869,9 @@
  410.         private int _engageid = 0;
  411.         private boolean _marryrequest = false;
  412.         private boolean _marryaccepted = false;
  413. +      
  414. +       // Faction Engine
  415. +       private FactionMember _faction;
  416.  
  417.      /** Skill casting information (used to queue when several skills are cast in a short time) **/
  418.      public class SkillDat
  419. @@ -5642,9 +5646,21 @@
  420.                                 )
  421.                 )
  422.                         increasePvpKills(target);
  423. +               // Give the faction pvp points
  424. +               if (Config.FACTION_ENABLED && targetPlayer.getSide() != getSide() && targetPlayer.getSide() != 0 && getSide() != 0 && Config.FACTION_KILL_REWARD)
  425. +                       increaseFactionKillPoints(targetPlayer.getLevel(), false);
  426.                 else
  427.                 // Target player doesn't have pvp flag set
  428.                 {
  429. +                       // Check factions
  430. +                       if (Config.FACTION_ENABLED && targetPlayer.getSide() != getSide() && targetPlayer.getSide() != 0 && getSide() != 0 && Config.FACTION_KILL_REWARD)
  431. +                       {
  432. +                               // Give faction pk points
  433. +                               increaseFactionKillPoints(targetPlayer.getLevel(), true);
  434. +                               // No karma
  435. +                               return;
  436. +                       }
  437. +                      
  438.                         // check about wars
  439.                         if (targetPlayer.getClan() != null && getClan() != null
  440.                                         && getClan().isAtWarWith(targetPlayer.getClanId())
  441. @@ -5671,6 +5687,20 @@
  442.                         }
  443.                 }
  444.         }
  445. +      
  446. +       /**
  447. +        * Increase the faction points depending on level
  448. +        * PK Kills give half the points of a PVP Kill
  449. +        */
  450. +       public void increaseFactionKillPoints(int level, boolean pk)
  451. +       {
  452. +               int points;
  453. +               points = (level / getLevel()) * (Config.FACTION_KILL_RATE / 100);
  454. +               if (pk)
  455. +                       points /= 2;
  456. +               _faction.addFactionPoints(points);
  457. +               sendMessage("You earned " + String.valueOf(points) + " Facion Points");
  458. +       }
  459.  
  460.         /**
  461.          * Increase the pvp kills count and send the info to the player
  462. @@ -12722,7 +12752,48 @@
  463.      {
  464.          _combatFlagEquippedId = value;
  465.      }
  466. +    
  467. +    public void setNPCFaction(FactionMember fm)
  468. +       {
  469. +               _faction = fm;
  470. +       }
  471.  
  472. +       public FactionMember getNPCFaction()
  473. +       {
  474. +               return _faction;
  475. +       }
  476. +
  477. +       public boolean removeNPCFactionPoints(int factionPoints)
  478. +       {
  479. +               if (_faction != null)
  480. +               {
  481. +                       if (_faction.getFactionPoints() < factionPoints)
  482. +                               return false;
  483. +                       _faction.reduceFactionPoints(factionPoints);
  484. +                       return true;
  485. +               }
  486. +               return false;
  487. +       }
  488. +
  489. +       public int getNPCFactionPoints()
  490. +       {
  491. +               return _faction.getFactionPoints();
  492. +       }
  493. +
  494. +       public int getSide()
  495. +       {
  496. +               return _faction.getSide();
  497. +       }
  498. +
  499. +       public void quitNPCFaction()
  500. +       {
  501. +               if (_faction != null)
  502. +               {
  503. +                       _faction.quitFaction();
  504. +                       _faction = null;
  505. +               }
  506. +       }
  507. +
  508.         public boolean getCharmOfCourage()
  509.         {
  510.                 return _charmOfCourage;
  511. Index: java/com/l2jserver/L2DatabaseFactory.java
  512. ===================================================================
  513. --- java/com/l2jserver/L2DatabaseFactory.java   (revision 4014)
  514. +++ java/com/l2jserver/L2DatabaseFactory.java   (working copy)
  515. @@ -210,6 +210,21 @@
  516.                 return _instance;
  517.         }
  518.        
  519. +       public static void close(Connection con)
  520. +       {
  521. +               if (con == null)
  522. +                       return;
  523. +              
  524. +               try
  525. +               {
  526. +                       con.close();
  527. +               }
  528. +               catch (SQLException e)
  529. +               {
  530. +                       _log.warning("L2DatabaseFactory: Failed to close database connection!");
  531. +               }
  532. +       }
  533. +      
  534.         public Connection getConnection() //throws SQLException
  535.         {
  536.                 Connection con = null;
  537. Index: java/com/l2jserver/gameserver/model/L2Object.java
  538. ===================================================================
  539. --- java/com/l2jserver/gameserver/model/L2Object.java   (revision 4014)
  540. +++ java/com/l2jserver/gameserver/model/L2Object.java   (working copy)
  541. @@ -251,7 +251,7 @@
  542.  
  543.      // =========================================================
  544.      // Event - Public
  545. -    public final void onAction(L2PcInstance player)
  546. +    public void onAction(L2PcInstance player)
  547.      {
  548.         onAction(player, true);
  549.      }
  550. Index: java/com/l2jserver/Config.java
  551. ===================================================================
  552. --- java/com/l2jserver/Config.java      (revision 4014)
  553. +++ java/com/l2jserver/Config.java      (working copy)
  554. @@ -662,6 +662,10 @@
  555.         public static List<String> L2JMOD_MULTILANG_ALLOWED = new ArrayList<String>();
  556.         public static String L2JMOD_MULTILANG_DEFAULT;
  557.         public static boolean L2JMOD_MULTILANG_VOICED_ALLOW;
  558. +       public static boolean   FACTION_ENABLED         = false;
  559. +       public static boolean   FACTION_KILL_REWARD     = false;
  560. +       public static int               FACTION_KILL_RATE       = 1000;
  561. +       public static int               FACTION_QUEST_RATE      = 1;
  562.  
  563.         //--------------------------------------------------
  564.         // NPC Settings
  565. @@ -1962,6 +1966,11 @@
  566.                                         TVT_EVENT_RUNNING_TIME = Integer.parseInt(L2JModSettings.getProperty("TvTEventRunningTime", "1800"));
  567.                                         TVT_EVENT_PARTICIPATION_NPC_ID = Integer.parseInt(L2JModSettings.getProperty("TvTEventParticipationNpcId", "0"));
  568.  
  569. +                                       FACTION_ENABLED         = Boolean.parseBoolean(L2JModSettings.getProperty("FactionEnabled", "false"));
  570. +                                       FACTION_KILL_REWARD     = Boolean.parseBoolean(L2JModSettings.getProperty("FactionKillReward", "false"));
  571. +                                       FACTION_KILL_RATE       = Integer.parseInt(L2JModSettings.getProperty("FactionKillRate", "1000"));
  572. +                                       FACTION_QUEST_RATE      = Integer.parseInt(L2JModSettings.getProperty("FactionQuestRate", "1"));
  573. +                                      
  574.                                         L2JMOD_ALLOW_WEDDING = Boolean.parseBoolean(L2JModSettings.getProperty("AllowWedding", "False"));
  575.                                         L2JMOD_WEDDING_PRICE = Integer.parseInt(L2JModSettings.getProperty("WeddingPrice", "250000000"));
  576.                                         L2JMOD_WEDDING_PUNISH_INFIDELITY = Boolean.parseBoolean(L2JModSettings.getProperty("WeddingPunishInfidelity", "True"));
  577. Index: java/com/l2jserver/gameserver/model/actor/L2Character.java
  578. ===================================================================
  579. --- java/com/l2jserver/gameserver/model/actor/L2Character.java  (revision 4014)
  580. +++ java/com/l2jserver/gameserver/model/actor/L2Character.java  (working copy)
  581. @@ -42,6 +42,7 @@
  582.  import com.l2jserver.gameserver.handler.ISkillHandler;
  583.  import com.l2jserver.gameserver.handler.SkillHandler;
  584.  import com.l2jserver.gameserver.instancemanager.DimensionalRiftManager;
  585. +import com.l2jserver.gameserver.instancemanager.FactionManager;
  586.  import com.l2jserver.gameserver.instancemanager.InstanceManager;
  587.  import com.l2jserver.gameserver.instancemanager.TownManager;
  588.  import com.l2jserver.gameserver.model.ChanceSkillList;
  589. @@ -2456,6 +2457,15 @@
  590.         /** Set the Title of the L2Character. */
  591.         public final void setTitle(String value)
  592.         {
  593. +               if (Config.FACTION_ENABLED)
  594. +               {
  595. +                       if (FactionManager.getInstance().getFactionTitles().contains(value.toLowerCase()) && !value.isEmpty())
  596. +                       {
  597. +                               sendMessage("Title protected by Faction System");
  598. +                               return;
  599. +                       }
  600. +               }
  601. +              
  602.                 if (value == null)
  603.                         _title = "";
  604.                 else
  605. Index: java/config/l2jmods.properties
  606. ===================================================================
  607. --- java/config/l2jmods.properties      (revision 4014)
  608. +++ java/config/l2jmods.properties      (working copy)
  609. @@ -355,3 +355,12 @@
  610.  # Default: True
  611.  MultiLangVoiceCommand = True
  612.  
  613. +# -------------------------------------------------------
  614. +# evil33t's faction engine
  615. +# -------------------------------------------------------
  616. +# Do not change the values below!!
  617. +# Only if you really know what you're doing!
  618. +FactionEnabled = False
  619. +FactionKillReward = False
  620. +FactionKillRate = 1000
  621. +FactionQuestRate = 1
  622. Index: java/com/l2jserver/gameserver/templates/chars/L2NpcTemplate.java
  623. ===================================================================
  624. --- java/com/l2jserver/gameserver/templates/chars/L2NpcTemplate.java    (revision 4014)
  625. +++ java/com/l2jserver/gameserver/templates/chars/L2NpcTemplate.java    (working copy)
  626. @@ -71,6 +71,8 @@
  627.         public final int enchantEffect;
  628.         public final int absorbLevel;
  629.         public final AbsorbCrystalType absorbType;
  630. +       private int npcFaction;
  631. +       private String npcFactionName;
  632.         public Race race;
  633.         public final String jClass;
  634.         public final boolean dropherb;
  635. @@ -215,6 +217,8 @@
  636.                 enchantEffect = set.getInteger("enchant");
  637.                 absorbLevel = set.getInteger("absorb_level", 0);
  638.                 absorbType = AbsorbCrystalType.valueOf(set.getString("absorb_type"));
  639. +               npcFaction = set.getInteger("NPCFaction", 0);
  640. +               npcFactionName = set.getString("NPCFactionName", "Devine Clan").intern();
  641.                 race = null;
  642.                 dropherb = set.getBool("drop_herbs", false);
  643.                 //_npcStatsSet = set;
  644. @@ -529,7 +533,30 @@
  645.                 }
  646.         }
  647.        
  648. +       public int getNpcFaction()
  649. +       {
  650. +               return npcFaction;
  651. +       }
  652. +
  653. +       public void setNpcFaction(int npcFaction)
  654. +       {
  655. +               npcFaction = npcFaction;
  656. +       }
  657. +
  658. +       public String getNpcFactionName()
  659. +       {
  660. +               return npcFactionName;
  661. +       }
  662. +      
  663.         /**
  664. +        * @param factionName the nPCFactionName to set
  665. +        */
  666. +       public void setNPCFactionName(String factionName)
  667. +       {
  668. +               npcFactionName = (factionName == null ? "Devine Clan" : factionName);
  669. +       }
  670. +      
  671. +       /**
  672.          * Checks if obj can be assigned to the Class represented by clazz.<br>
  673.          * This is true if, and only if, obj is the same class represented by clazz,
  674.          * or a subclass of it or obj implements the interface represented by clazz.
  675. Index: java/com/l2jserver/gameserver/model/entity/faction/FactionMember.java
  676. ===================================================================
  677. --- java/com/l2jserver/gameserver/model/entity/faction/FactionMember.java       (revision 0)
  678. +++ java/com/l2jserver/gameserver/model/entity/faction/FactionMember.java       (revision 0)
  679. @@ -0,0 +1,217 @@
  680. +/*
  681. + * This program is free software: you can redistribute it and/or modify it under
  682. + * the terms of the GNU General Public License as published by the Free Software
  683. + * Foundation, either version 3 of the License, or (at your option) any later
  684. + * version.
  685. + *
  686. + * This program is distributed in the hope that it will be useful, but WITHOUT
  687. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  688. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  689. + * details.
  690. + *
  691. + * You should have received a copy of the GNU General Public License along with
  692. + * this program. If not, see <http://www.gnu.org/licenses/>.
  693. + */
  694. +package com.l2jserver.gameserver.model.entity.faction;
  695. +
  696. +import java.sql.Connection;
  697. +import java.sql.PreparedStatement;
  698. +import java.sql.ResultSet;
  699. +
  700. +import java.util.logging.Logger;
  701. +
  702. +import com.l2jserver.L2DatabaseFactory;
  703. +import com.l2jserver.gameserver.instancemanager.FactionManager;
  704. +
  705. +/**
  706. + * @author evill33t
  707. + *
  708. + */
  709. +public class FactionMember
  710. +{
  711. +       private static Logger _log = Logger.getLogger(Faction.class.getName());
  712. +    
  713. +    // =========================================================
  714. +    // Data Field
  715. +    private int _playerId                      = 0;
  716. +    private int _factionId                     = 0;
  717. +    private int _factionPoints                 = 0;
  718. +    private int _contributions                 = 0;
  719. +    private long _joinDate;
  720. +    private int _side;
  721. +
  722. +
  723. +    // =========================================================
  724. +    // Constructor
  725. +    public FactionMember(int playerId)
  726. +    {
  727. +        _playerId = playerId;
  728. +        
  729. +        Connection con = null;
  730. +        try
  731. +        {
  732. +            PreparedStatement statement;
  733. +            ResultSet rs;
  734. +
  735. +            con = L2DatabaseFactory.getInstance().getConnection();
  736. +
  737. +            statement = con.prepareStatement("Select * from faction_members where player_id = ?");
  738. +            statement.setInt(1, _playerId);
  739. +            rs = statement.executeQuery();
  740. +
  741. +            while (rs.next())
  742. +            {
  743. +                _factionId = rs.getInt("faction_id");
  744. +                _factionPoints = rs.getInt("faction_points");
  745. +                _contributions = rs.getInt("contributions");
  746. +                _joinDate = rs.getLong("join_date");
  747. +                Faction faction = FactionManager.getInstance().getFactions(_factionId);
  748. +                if(faction!=null)
  749. +                {
  750. +                    _side = faction.getSide();
  751. +                }
  752. +                
  753. +            }
  754. +            statement.close();
  755. +        }
  756. +        catch (Exception e)
  757. +        {
  758. +            _log.warning("Exception: FactionMember.load(): " + e.getMessage());
  759. +        }
  760. +        finally
  761. +        {
  762. +            L2DatabaseFactory.close(con);
  763. +        }
  764. +    }
  765. +    
  766. +    public FactionMember(int playerId, int factionId)
  767. +    {
  768. +        _playerId = playerId;
  769. +        _factionId = factionId;
  770. +        _factionPoints = 0;
  771. +        _contributions = 0;
  772. +        _joinDate = System.currentTimeMillis();
  773. +        Connection con = null;
  774. +        try
  775. +        {
  776. +            con = L2DatabaseFactory.getInstance().getConnection();
  777. +            PreparedStatement statement;
  778. +            statement = con.prepareStatement("INSERT INTO faction_members (player_id, faction_id, faction_points, contributions, join_date) VALUES (?, ?, 0, 0, ?)");
  779. +            statement.setInt(1, _playerId);
  780. +            statement.setInt(2, _factionId);
  781. +            statement.setLong(3, _joinDate);
  782. +            statement.execute();
  783. +            statement.close();
  784. +        }
  785. +        catch (Exception e)
  786. +        {
  787. +            _log.warning("");
  788. +        }
  789. +        finally
  790. +        {
  791. +            L2DatabaseFactory.close(con);
  792. +        }
  793. +    }
  794. +    
  795. +    public void quitFaction()
  796. +    {
  797. +        Connection con = null;
  798. +        _factionId = 0;
  799. +        _factionPoints = 0;
  800. +        _contributions = 0;
  801. +        try
  802. +        {
  803. +            con = L2DatabaseFactory.getInstance().getConnection();
  804. +            PreparedStatement statement;
  805. +            
  806. +            statement = con.prepareStatement("DELETE FROM faction_members WHERE player_id=?");
  807. +            statement.setInt(1, _playerId);
  808. +            statement.execute();
  809. +            statement.close();
  810. +        }
  811. +        catch (Exception e)
  812. +        {
  813. +            _log.warning("Exception: FactionMember.quitFaction(): " + e.getMessage());
  814. +        }
  815. +        finally
  816. +        {
  817. +            L2DatabaseFactory.close(con);
  818. +        }
  819. +    }
  820. +    
  821. +    private void updateDb()
  822. +    {
  823. +        Connection con = null;
  824. +        try
  825. +        {
  826. +            con = L2DatabaseFactory.getInstance().getConnection();
  827. +            PreparedStatement statement;
  828. +            
  829. +            statement = con.prepareStatement("UPDATE faction_members SET faction_points=?,contributions=?,faction_id=? WHERE player_id=?");
  830. +            statement.setInt(1, _factionPoints);
  831. +            statement.setInt(2, _contributions);
  832. +            statement.setInt(3, _factionId);
  833. +            statement.setInt(4, _playerId);
  834. +            statement.execute();
  835. +            statement.close();
  836. +        }
  837. +        catch (Exception e)
  838. +        {
  839. +            _log.warning("Exception: FactionMember.updateDb(): " + e.getMessage());
  840. +        }
  841. +        finally
  842. +        {
  843. +            L2DatabaseFactory.close(con);
  844. +        }
  845. +    }
  846. +    
  847. +    public void addFactionPoints(int amount)
  848. +    {
  849. +        _factionPoints += amount;
  850. +        updateDb();
  851. +    }
  852. +
  853. +    public void addContributions(int amount)
  854. +    {
  855. +        _contributions += amount;
  856. +        updateDb();
  857. +    }
  858. +    
  859. +    
  860. +    public boolean reduceFactionPoints(int amount)
  861. +    {
  862. +        if(amount<getFactionPoints())
  863. +        {
  864. +            _factionPoints -= amount;
  865. +            updateDb();
  866. +            return true;
  867. +        }
  868. +
  869. +        return false;
  870. +    }
  871. +    
  872. +    public void setFactionPoints(int amount)
  873. +    {
  874. +        _factionPoints = amount;
  875. +        updateDb();
  876. +    }
  877. +
  878. +    public void setContribution(int amount)
  879. +    {
  880. +        _factionPoints = amount;
  881. +        updateDb();
  882. +    }
  883. +
  884. +    public void setFactionId(int factionId)
  885. +    {
  886. +        _factionId = factionId;
  887. +        updateDb();
  888. +    }
  889. +
  890. +    public final int getPlayerId() { return _playerId; }
  891. +    public final int getFactionId() { return _factionId; }
  892. +    public final int getSide() { return _side; }
  893. +    public final int getFactionPoints() { return _factionPoints; }
  894. +    public final int getContributions() { return _contributions; }
  895. +    public final long getJoinDate() { return _joinDate; }
  896. +}
  897. Index: java/com/l2jserver/gameserver/model/actor/instance/L2FactionManagerInstance.java
  898. ===================================================================
  899. --- java/com/l2jserver/gameserver/model/actor/instance/L2FactionManagerInstance.java    (revision 0)
  900. +++ java/com/l2jserver/gameserver/model/actor/instance/L2FactionManagerInstance.java    (revision 0)
  901. @@ -0,0 +1,153 @@
  902. +/*
  903. + * This program is free software: you can redistribute it and/or modify it under
  904. + * the terms of the GNU General Public License as published by the Free Software
  905. + * Foundation, either version 3 of the License, or (at your option) any later
  906. + * version.
  907. + *
  908. + * This program is distributed in the hope that it will be useful, but WITHOUT
  909. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  910. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  911. + * details.
  912. + *
  913. + * You should have received a copy of the GNU General Public License along with
  914. + * this program. If not, see <http://www.gnu.org/licenses/>.
  915. + */
  916. +package com.l2jserver.gameserver.model.actor.instance;
  917. +
  918. +import com.l2jserver.gameserver.ai.CtrlIntention;
  919. +import com.l2jserver.gameserver.instancemanager.FactionManager;
  920. +import com.l2jserver.gameserver.model.entity.faction.Faction;
  921. +import com.l2jserver.gameserver.model.entity.faction.FactionMember;
  922. +import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  923. +import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  924. +import com.l2jserver.gameserver.templates.chars.L2NpcTemplate;
  925. +
  926. +/**
  927. + * @author evill33t
  928. + */
  929. +public class L2FactionManagerInstance extends L2NpcInstance
  930. +{
  931. +    public L2FactionManagerInstance(int objectId, L2NpcTemplate template)
  932. +    {
  933. +        super(objectId, template);
  934. +    }
  935. +
  936. +       @Override
  937. +       public void onAction(L2PcInstance player)
  938. +       {
  939. +               if (!canTarget(player)) return;
  940. +
  941. +               // Check if the L2PcInstance already target the L2NpcInstance
  942. +               if (this != player.getTarget())
  943. +               {
  944. +                       // Set the target of the L2PcInstance player
  945. +                       player.setTarget(this);
  946. +               }
  947. +               else
  948. +               {
  949. +                       // Calculate the distance between the L2PcInstance and the L2NpcInstance
  950. +                       if (!canInteract(player))
  951. +                       {
  952. +                               // Notify the L2PcInstance AI with AI_INTENTION_INTERACT
  953. +                               player.getAI().setIntention(CtrlIntention.AI_INTENTION_INTERACT, this);
  954. +                       }
  955. +                       else
  956. +                       {
  957. +                               showMessageWindow(player);
  958. +                       }
  959. +               }
  960. +               // Send a Server->Client ActionFailed to the L2PcInstance in order to avoid that the client wait another packet
  961. +               player.sendPacket(ActionFailed.STATIC_PACKET);
  962. +       }
  963. +
  964. +    private void showMessageWindow(L2PcInstance player)
  965. +    {
  966. +        int factionId = getTemplate().getNpcFaction();
  967. +        String filename = "data/html/npcdefault.htm";
  968. +        String factionName = getTemplate().getNpcFactionName();
  969. +        String replace = null;
  970. +
  971. +        if (factionId != 0)
  972. +        {
  973. +            filename = "data/html/custom/faction/" + String.valueOf(factionId)  +  "/start.htm";
  974. +            replace = getName();
  975. +        }
  976. +        sendHtmlMessage(player, filename, replace, factionName);
  977. +    }
  978. +    
  979. +    @Override
  980. +    public void onBypassFeedback(L2PcInstance player, String command)
  981. +    {
  982. +        // Standard msg
  983. +        String filename = "data/html/npcdefault.htm";
  984. +        String factionName = getTemplate().getNpcFactionName();
  985. +        int factionId = getTemplate().getNpcFaction();
  986. +        Faction faction = FactionManager.getInstance().getFactions(factionId);
  987. +        int factionPrice = faction.getPrice();
  988. +        String replace = null;
  989. +
  990. +        if (factionId != 0)
  991. +        {
  992. +            String path = "data/html/custom/faction/" + String.valueOf(factionId) + "/";
  993. +            replace = String.valueOf(factionPrice);
  994. +            
  995. +            if (player.getNPCFaction() != null)
  996. +            {
  997. +                if(player.getNPCFaction().getSide()!=faction.getSide())
  998. +                    filename = path + "already.htm";
  999. +                else
  1000. +                    filename = path + "switch.htm";
  1001. +            }
  1002. +            else if (command.startsWith("Join"))
  1003. +                filename = path + "join.htm";
  1004. +            else if (command.startsWith("Accept"))
  1005. +            {
  1006. +                if (player.getNPCFaction() == null)
  1007. +                {
  1008. +                    if (player.getAdena() < factionPrice)
  1009. +                        filename = path + "noadena.htm";
  1010. +                    else
  1011. +                    {
  1012. +                        player.getInventory().reduceAdena("Faction", factionPrice, player, null);
  1013. +                        player.setNPCFaction(new FactionMember(player.getObjectId(),factionId));
  1014. +                        filename = path + "accepted.htm";
  1015. +                    }
  1016. +                }
  1017. +                else
  1018. +                {
  1019. +                    player.getNPCFaction().setFactionId(factionId);
  1020. +                    filename = path + "switched.htm";
  1021. +                }
  1022. +            }
  1023. +            else if (command.startsWith("Decline"))
  1024. +                filename = path + "declined.htm";
  1025. +            else if (command.startsWith("AskQuit"))
  1026. +                filename = path + "askquit.htm";
  1027. +            else if (command.startsWith("Story"))
  1028. +                filename = path + "story.htm";
  1029. +            else if (command.startsWith("Quit"))
  1030. +            {
  1031. +                player.quitNPCFaction();
  1032. +                filename = path + "quited.htm";
  1033. +            }
  1034. +            else if (command.startsWith("Quest"))
  1035. +            {
  1036. +                filename = path + "quest.htm";
  1037. +            }
  1038. +            else if (command.startsWith("FactionShop"))
  1039. +                filename = path + "shop.htm";
  1040. +        }
  1041. +        sendHtmlMessage(player, filename, replace, factionName);
  1042. +    }
  1043. +
  1044. +    private void sendHtmlMessage(L2PcInstance player, String filename, String replace, String factionName)
  1045. +    {
  1046. +        NpcHtmlMessage html = new NpcHtmlMessage(1);
  1047. +        html.setFile(filename, filename);
  1048. +        html.replace("%objectId%", String.valueOf(getObjectId()));
  1049. +        html.replace("%replace%", replace);
  1050. +        html.replace("%npcname%", getName());
  1051. +        html.replace("%factionName%", factionName);
  1052. +        player.sendPacket(html);
  1053. +    }
  1054. +}
  1055. Index: java/com/l2jserver/gameserver/model/entity/faction/Faction.java
  1056. ===================================================================
  1057. --- java/com/l2jserver/gameserver/model/entity/faction/Faction.java     (revision 0)
  1058. +++ java/com/l2jserver/gameserver/model/entity/faction/Faction.java     (revision 0)
  1059. @@ -0,0 +1,147 @@
  1060. +/*
  1061. + * This program is free software: you can redistribute it and/or modify it under
  1062. + * the terms of the GNU General Public License as published by the Free Software
  1063. + * Foundation, either version 3 of the License, or (at your option) any later
  1064. + * version.
  1065. + *
  1066. + * This program is distributed in the hope that it will be useful, but WITHOUT
  1067. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  1068. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  1069. + * details.
  1070. + *
  1071. + * You should have received a copy of the GNU General Public License along with
  1072. + * this program. If not, see <http://www.gnu.org/licenses/>.
  1073. + */
  1074. +package com.l2jserver.gameserver.model.entity.faction;
  1075. +
  1076. +import java.sql.Connection;
  1077. +import java.sql.PreparedStatement;
  1078. +import java.sql.ResultSet;
  1079. +
  1080. +import javolution.util.FastList;
  1081. +import javolution.util.FastMap;
  1082. +
  1083. +import java.util.logging.Logger;
  1084. +
  1085. +import com.l2jserver.L2DatabaseFactory;
  1086. +
  1087. +/**
  1088. + * @author evill33t
  1089. + *
  1090. + */
  1091. +public class Faction
  1092. +{
  1093. +    private static Logger _log = Logger.getLogger(Faction.class.getName());
  1094. +    
  1095. +    private int _Id                             = 0;
  1096. +    private String _name                        = null;
  1097. +    private float _points                       = 0;
  1098. +    private int _joinprice                      = 0;
  1099. +    private int _side                           = 0; // 0 = Neutral 1 = Good 2 = Evil
  1100. +    private final FastList<Integer> _list_classes     = new FastList<Integer>();
  1101. +    private final FastList<Integer> _list_npcs        = new FastList<Integer>();
  1102. +    private final FastMap<Integer, String> _list_title = new FastMap<Integer, String>();
  1103. +    
  1104. +       public Faction(int factionId)
  1105. +    {
  1106. +        _Id                                    = factionId;
  1107. +        String _classlist      = "";
  1108. +        String _npclist                = "";
  1109. +        String _titlelist      = "";
  1110. +        int _tside                     = 0;
  1111. +        
  1112. +        Connection con = null;
  1113. +        try
  1114. +        {
  1115. +            PreparedStatement statement;
  1116. +            ResultSet rs;
  1117. +
  1118. +            con = L2DatabaseFactory.getInstance().getConnection();
  1119. +
  1120. +            statement = con.prepareStatement("Select * from factions where id = ?");
  1121. +            statement.setInt(1, getId());
  1122. +            rs = statement.executeQuery();
  1123. +
  1124. +            while (rs.next())
  1125. +            {
  1126. +                _name = rs.getString("name");
  1127. +                _joinprice = rs.getInt("price");
  1128. +                _classlist = rs.getString("allowed_classes");
  1129. +                _titlelist = rs.getString("titlelist");
  1130. +                _npclist = rs.getString("npcs");
  1131. +                _points = rs.getFloat("points");
  1132. +                _tside = rs.getInt("side");
  1133. +            }
  1134. +            statement.close();
  1135. +            
  1136. +            if (_tside <= 2)
  1137. +                _side = _tside;
  1138. +            
  1139. +            if (_classlist.length() > 0)
  1140. +                for (String id : _classlist.split(","))
  1141. +                    _list_classes.add(Integer.parseInt(id));
  1142. +
  1143. +            if (_npclist.length() > 0)
  1144. +                for (String id : _npclist.split(","))
  1145. +                    _list_npcs.add(Integer.parseInt(id));
  1146. +            
  1147. +            if (_titlelist.length() > 0)
  1148. +                for (String id : _titlelist.split(";"))
  1149. +                    _list_title.put(Integer.valueOf(id.split(",")[0]),id.split(",")[1]);
  1150. +        }
  1151. +        catch (Exception e)
  1152. +        {
  1153. +            _log.warning("Exception: Faction load: " + e.getMessage());
  1154. +        }
  1155. +        finally
  1156. +        {
  1157. +            L2DatabaseFactory.close(con);
  1158. +        }
  1159. +    }
  1160. +    
  1161. +    private void updateDB()
  1162. +    {
  1163. +        Connection con = null;
  1164. +        try
  1165. +        {
  1166. +            PreparedStatement statement;
  1167. +
  1168. +            con = L2DatabaseFactory.getInstance().getConnection();
  1169. +
  1170. +            statement = con.prepareStatement("update factions set points = ? where id = ?");
  1171. +            statement.setFloat(1, _points);
  1172. +            statement.setInt(2, _Id);
  1173. +            statement.execute();
  1174. +            statement.close();
  1175. +        }
  1176. +        catch (Exception e)
  1177. +        {
  1178. +            _log.warning("Exception: Faction.load(): " + e.getMessage());
  1179. +        }
  1180. +        finally
  1181. +        {
  1182. +            L2DatabaseFactory.close(con);
  1183. +        }
  1184. +    }
  1185. +    
  1186. +    public void addPoints(int points)
  1187. +    {
  1188. +        _points+=points;
  1189. +        updateDB();
  1190. +    }
  1191. +
  1192. +    public void clearPoints()
  1193. +    {
  1194. +        _points = 0;
  1195. +        updateDB();
  1196. +    }
  1197. +
  1198. +    public final int getId() { return _Id; }
  1199. +    public final String getName() { return _name; }
  1200. +    public final float getPoints() { return _points; }
  1201. +    public final FastList<Integer> getClassList(){ return _list_classes; }
  1202. +    public final FastList<Integer> getNpcList(){ return _list_npcs; }
  1203. +    public final FastMap<Integer, String> getTitle(){ return _list_title; }
  1204. +    public final int getPrice() { return _joinprice; }
  1205. +    public final int getSide() { return _side; }
  1206. +}
  1207. Index: java/com/l2jserver/gameserver/model/entity/faction/FactionQuest.java
  1208. ===================================================================
  1209. --- java/com/l2jserver/gameserver/model/entity/faction/FactionQuest.java        (revision 0)
  1210. +++ java/com/l2jserver/gameserver/model/entity/faction/FactionQuest.java        (revision 0)
  1211. @@ -0,0 +1,116 @@
  1212. +/*
  1213. + * This program is free software: you can redistribute it and/or modify it under
  1214. + * the terms of the GNU General Public License as published by the Free Software
  1215. + * Foundation, either version 3 of the License, or (at your option) any later
  1216. + * version.
  1217. + *
  1218. + * This program is distributed in the hope that it will be useful, but WITHOUT
  1219. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  1220. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  1221. + * details.
  1222. + *
  1223. + * You should have received a copy of the GNU General Public License along with
  1224. + * this program. If not, see <http://www.gnu.org/licenses/>.
  1225. + */
  1226. +package com.l2jserver.gameserver.model.entity.faction;
  1227. +
  1228. +import java.sql.Connection;
  1229. +import java.sql.PreparedStatement;
  1230. +
  1231. +import java.util.logging.Logger;
  1232. +
  1233. +import com.l2jserver.Config;
  1234. +import com.l2jserver.L2DatabaseFactory;
  1235. +import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  1236. +
  1237. +/**
  1238. + * @author evill33t
  1239. + *
  1240. + */
  1241. +public class FactionQuest
  1242. +{
  1243. +       private static Logger _log = Logger.getLogger(Faction.class.getName());
  1244. +
  1245. +    private final int _questId;
  1246. +    private static int _factionId;
  1247. +    private static String _name;
  1248. +    private static String _descr;
  1249. +    private static int _reward;
  1250. +    private static int _mobId;
  1251. +    private static int _amount;
  1252. +    private static int _minLevel;
  1253. +    
  1254. +    public FactionQuest(int questId, int factionId, String name, String descr, int reward, int mobId, int amount, int minLevel)
  1255. +    {
  1256. +        _questId = questId;
  1257. +        _factionId = factionId;
  1258. +        _name = name;
  1259. +        _descr = descr;
  1260. +        _reward = reward;
  1261. +        _mobId = mobId;
  1262. +        _amount = amount;
  1263. +        _minLevel = minLevel;
  1264. +    }
  1265. +    
  1266. +    public int getId() { return _questId; }
  1267. +    public static String getName() { return _name; }
  1268. +    public static String getDescr() { return _descr;}
  1269. +    public static int getReward() { return _reward;}
  1270. +    public static int getAmount() { return _amount;}
  1271. +    public static int getMobId() { return _mobId;}
  1272. +    public static int getFactionId() { return _factionId;}
  1273. +    public static int getMinLevel() { return _minLevel;}
  1274. +
  1275. +    public static void createFactionQuest(L2PcInstance player,int factionQuestId)
  1276. +    {
  1277. +        Connection con = null;
  1278. +        try
  1279. +        {
  1280. +            con = L2DatabaseFactory.getInstance().getConnection();
  1281. +            PreparedStatement statement;
  1282. +            statement = con.prepareStatement("INSERT INTO character_faction_quests (char_id,faction_quest_id) VALUES (?,?)");
  1283. +            statement.setInt (1, player.getObjectId());
  1284. +            statement.setInt (2, factionQuestId);
  1285. +            statement.executeUpdate();
  1286. +            statement.close();
  1287. +        }
  1288. +        catch (Exception e)
  1289. +        {
  1290. +            _log.warning( "could not insert char faction quest:");
  1291. +        }
  1292. +        finally
  1293. +        {
  1294. +            L2DatabaseFactory.close(con);
  1295. +        }
  1296. +    }
  1297. +
  1298. +    public static void endFactionQuest(L2PcInstance player,int factionQuestId)
  1299. +    {
  1300. +        player.sendMessage(getName()+" completed.");
  1301. +        player.getNPCFaction().addFactionPoints(getReward()*Config.FACTION_QUEST_RATE);
  1302. +        deleteFactionQuest(player,factionQuestId);
  1303. +    }
  1304. +    
  1305. +    public static void deleteFactionQuest(L2PcInstance player,int factionQuestId)
  1306. +    {
  1307. +        Connection con = null;
  1308. +        try
  1309. +        {
  1310. +            con = L2DatabaseFactory.getInstance().getConnection();
  1311. +            PreparedStatement statement;
  1312. +            statement = con.prepareStatement("DELETE FROM character_faction_quests WHERE char_id=? AND faction_quest_id=?");
  1313. +            statement.setInt (1, player.getObjectId());
  1314. +            statement.setInt (2, factionQuestId);
  1315. +            statement.executeUpdate();
  1316. +            statement.close();
  1317. +        }
  1318. +        catch (Exception e)
  1319. +        {
  1320. +            _log.warning( "could not delete char faction quest:");
  1321. +        }
  1322. +        finally
  1323. +        {
  1324. +            L2DatabaseFactory.close(con);
  1325. +        }
  1326. +    }
  1327. +}