Advertisement
Guest User

GvE - Core

a guest
Aug 11th, 2010
1,035
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 67.77 KB | None | 0 0
  1. ### Eclipse Workspace Patch 1.0
  2. #P Game
  3. Index: java/realtek/gameserver/network/clientpackets/RequestRestartPoint.java
  4. ===================================================================
  5. --- java/realtek/gameserver/network/clientpackets/RequestRestartPoint.java  (revision 718)
  6. +++ java/realtek/gameserver/network/clientpackets/RequestRestartPoint.java  (working copy)
  7. @@ -22,6 +22,7 @@
  8.  
  9.  import realtek.gameserver.ThreadPoolManager;
  10.  import realtek.gameserver.datatables.MapRegionTable;
  11. +import realtek.gameserver.events.engines.gve.GvEEvent;
  12.  import realtek.gameserver.events.engines.tvt.TvTEvent;
  13.  import realtek.gameserver.instancemanager.CastleManager;
  14.  import realtek.gameserver.instancemanager.ClanHallManager;
  15. @@ -172,6 +173,9 @@
  16.         if (TvTEvent.isStarted() && TvTEvent.isPlayerParticipant(activeChar.getObjectId()))
  17.             return;
  18.  
  19. +       if (GvEEvent.isStarted() && GvEEvent.isPlayerParticipant(activeChar.getName()))
  20. +           return;
  21. +
  22.         //SystemMessage sm2 = new SystemMessage(SystemMessage.S1_S2);
  23.         //sm2.addString("type:"+requestedPointType);
  24.         //activeChar.sendPacket(sm2);
  25. Index: java/realtek/gameserver/model/actor/instance/L2GvENpcInstance.java
  26. ===================================================================
  27. --- java/realtek/gameserver/model/actor/instance/L2GvENpcInstance.java  (revision 0)
  28. +++ java/realtek/gameserver/model/actor/instance/L2GvENpcInstance.java  (revision 0)
  29. @@ -0,0 +1,84 @@
  30. +/*
  31. + * This program is free software; you can redistribute it and/or modify
  32. + * it under the terms of the GNU General Public License as published by
  33. + * the Free Software Foundation; either version 2, or (at your option)
  34. + * any later version.
  35. + *
  36. + * This program is distributed in the hope that it will be useful,
  37. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  38. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  39. + * GNU General Public License for more details.
  40. + *
  41. + * You should have received a copy of the GNU General Public License
  42. + * along with this program; if not, write to the Free Software
  43. + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  44. + * 02111-1307, USA.
  45. + *
  46. + * [URL]http://www.gnu.org/copyleft/gpl.html[/URL]
  47. + */
  48. +package realtek.gameserver.model.actor.instance;
  49. +
  50. +import realtek.Config;
  51. +import realtek.gameserver.cache.HtmCache;
  52. +import realtek.gameserver.events.engines.gve.GvEEvent;
  53. +import realtek.gameserver.network.serverpackets.ActionFailed;
  54. +import realtek.gameserver.network.serverpackets.NpcHtmlMessage;
  55. +import realtek.gameserver.templates.L2NpcTemplate;
  56. +
  57. +public class L2GvENpcInstance extends L2NpcInstance
  58. +{
  59. +   public L2GvENpcInstance(int objectId, L2NpcTemplate template)
  60. +   {
  61. +       super(objectId, template);
  62. +   }
  63. +
  64. +   @Override
  65. +   public void onBypassFeedback(L2PcInstance playerInstance, String command)
  66. +   {
  67. +       GvEEvent.onBypass(command, playerInstance);
  68. +   }
  69. +
  70. +   @Override
  71. +   public void showChatWindow(L2PcInstance playerInstance, int val)
  72. +   {
  73. +       if (playerInstance == null)
  74. +           return;
  75. +       if (GvEEvent.isParticipating())
  76. +       {
  77. +           String htmFile = "data/html/mods/";
  78. +           if (!GvEEvent.isPlayerParticipant(playerInstance.getName()))
  79. +               htmFile += "GvEEventParticipation";
  80. +           else
  81. +               htmFile += "GvEEventRemoveParticipation";
  82. +           htmFile += ".htm";
  83. +           String htmContent = HtmCache.getInstance().getHtm(htmFile);
  84. +           if (htmContent != null)
  85. +           {
  86. +               int[] teamsPlayerCounts = GvEEvent.getTeamsPlayerCounts();
  87. +               NpcHtmlMessage npcHtmlMessage = new NpcHtmlMessage(getObjectId());
  88. +               npcHtmlMessage.setHtml(htmContent);
  89. +               npcHtmlMessage.replace("%objectId%", String.valueOf(getObjectId()));
  90. +               npcHtmlMessage.replace("%team1name%", Config.GVE_EVENT_TEAM_1_NAME);
  91. +               npcHtmlMessage.replace("%team1playercount%", String.valueOf(teamsPlayerCounts[0]));
  92. +               npcHtmlMessage.replace("%team2name%", Config.GVE_EVENT_TEAM_2_NAME);
  93. +               npcHtmlMessage.replace("%team2playercount%", String.valueOf(teamsPlayerCounts[1]));
  94. +               playerInstance.sendPacket(npcHtmlMessage);
  95. +           }
  96. +       }
  97. +       else if (GvEEvent.isStarting() || GvEEvent.isStarted())
  98. +       {
  99. +           String htmFile = "data/html/mods/GvEEventStatus.htm";
  100. +           String htmContent = HtmCache.getInstance().getHtm(htmFile);
  101. +           if (htmContent != null)
  102. +           {
  103. +               NpcHtmlMessage npcHtmlMessage = new NpcHtmlMessage(getObjectId());
  104. +               npcHtmlMessage.setHtml(htmContent);
  105. +               // npcHtmlMessage.replace("%objectId%", String.valueOf(getObjectId()));
  106. +               npcHtmlMessage.replace("%team1name%", Config.GVE_EVENT_TEAM_1_NAME);
  107. +               npcHtmlMessage.replace("%team2name%", Config.GVE_EVENT_TEAM_2_NAME);
  108. +               playerInstance.sendPacket(npcHtmlMessage);
  109. +           }
  110. +       }
  111. +       playerInstance.sendPacket(ActionFailed.STATIC_PACKET);
  112. +   }
  113. +}
  114. \ No newline at end of file
  115. Index: Settings/Modifications/Events.ini
  116. ===================================================================
  117. --- Settings/Modifications/Events.ini   (revision 718)
  118. +++ Settings/Modifications/Events.ini   (working copy)
  119. @@ -93,6 +93,60 @@
  120.  # Example: 1504,1;1500,1;1501,1;1085,3
  121.  TvTEventMageBuffs =
  122.  
  123. +# -----------------------------
  124. +# GvE Event Engine
  125. +# -----------------------------
  126. +# Enable GvEEvent
  127. +GvEEventEnabled = false
  128. +
  129. +# Time Between TvT events (in minutes, 300 = 5 hours)
  130. +GvEEventInterval = 300
  131. +
  132. +#  Registration timer (in minutes) from start of event.
  133. +GvEEventParticipationTime = 60
  134. +
  135. +#  Event running time, in minutes
  136. +GvEEventRunningTime = 20
  137. +
  138. +# TvT Event NPC Details (create a custom npc of type L2GvENpc)
  139. +GvEEventParticipationNpcId = 70011
  140. +GvEEventParticipationNpcCoordinates = 83425,148585,-3406
  141. +
  142. +# Minimum amount of players allowed in each team
  143. +GvEEventMinPlayersInTeams = 1
  144. +GvEEventMaxPlayersInTeams = 20
  145. +
  146. +# Level rules
  147. +GvEEventMinPlayerLevel = 1
  148. +GvEEventMaxPlayerLevel = 80
  149. +
  150. +# Teleport delay Timers (in seconds)
  151. +GvEEventRespawnTeleportDelay = 10
  152. +GvEEventStartLeaveTeleportDelay = 10
  153. +
  154. +# First Team Details (name, start and death x,y,z tp point)
  155. +GvEEventTeam1Name = Good
  156. +GvEEventTeam1Coordinates = 148695,46725,-3414
  157. +
  158. +# Second Team Details (name, start and death x,y,z tp point)
  159. +GvEEventTeam2Name = Evil
  160. +GvEEventTeam2Coordinates = 149999,46728,-3414
  161. +
  162. +# Reward for winning team
  163. +# itemId,amount;itemId,amount;itemId,amount;...
  164. +# no ";" at the start or end
  165. +GvEEventReward = 57,100000;5575,1000
  166. +
  167. +# GvEEvent Rules
  168. +GvEEventTargetTeamMembersAllowed = true
  169. +GvEEventPotionsAllowed = false
  170. +GvEEventSummonByItemAllowed = false
  171. +
  172. +# Door id's to close/open on start/end
  173. +# ex.: 1;2;3;4;5;6
  174. +# no ";" at the start or end
  175. +GvEEventDoorsCloseOpenOnStartEnd =
  176. +
  177. # -------------------------------------
  178. # Engine Not Done !
  179. # -------------------------------------
  180. Index: java/realtek/gameserver/events/engines/gve/GvETeleporter.java
  181. ===================================================================
  182. --- java/realtek/gameserver/events/engines/gve/GvETeleporter.java   (revision 0)
  183. +++ java/realtek/gameserver/events/engines/gve/GvETeleporter.java   (revision 0)
  184. @@ -0,0 +1,88 @@
  185. +/*
  186. + * This program is free software; you can redistribute it and/or modify
  187. + * it under the terms of the GNU General Public License as published by
  188. + * the Free Software Foundation; either version 2, or (at your option)
  189. + * any later version.
  190. + *
  191. + * This program is distributed in the hope that it will be useful,
  192. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  193. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  194. + * GNU General Public License for more details.
  195. + *
  196. + * You should have received a copy of the GNU General Public License
  197. + * along with this program; if not, write to the Free Software
  198. + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  199. + * 02111-1307, USA.
  200. + *
  201. + * [URL]http://www.gnu.org/copyleft/gpl.html[/URL]
  202. + */
  203. +package realtek.gameserver.events.engines.gve;
  204. +
  205. +import realtek.Config;
  206. +import realtek.gameserver.ThreadPoolManager;
  207. +import realtek.gameserver.model.L2Effect;
  208. +import realtek.gameserver.model.L2Summon;
  209. +import realtek.gameserver.model.actor.instance.L2PcInstance;
  210. +
  211. +/**
  212. + * @author Realtek
  213. + */
  214. +public class GvETeleporter implements Runnable
  215. +{
  216. +   /** The instance of the player to teleport */
  217. +   private L2PcInstance _playerInstance;
  218. +   /** Coordinates of the spot to teleport to */
  219. +   private int[] _coordinates = new int[3];
  220. +   /** Admin removed this player from event */
  221. +   private boolean _adminRemove;
  222. +
  223. +   /**
  224. +    * Initialize the teleporter and start the delayed task
  225. +    *
  226. +    * @param playerInstance
  227. +    * @param coordinates
  228. +    * @param reAdd
  229. +    */
  230. +   public GvETeleporter(L2PcInstance playerInstance, int[] coordinates, boolean fastSchedule, boolean adminRemove)
  231. +   {
  232. +       _playerInstance = playerInstance;
  233. +       _coordinates = coordinates;
  234. +       _adminRemove = adminRemove;
  235. +       // in config as seconds
  236. +       long delay = (GvEEvent.isStarted() ? Config.GVE_EVENT_RESPAWN_TELEPORT_DELAY : Config.GVE_EVENT_START_LEAVE_TELEPORT_DELAY) * 1000;
  237. +       if (fastSchedule)
  238. +           delay = 0;
  239. +       ThreadPoolManager.getInstance().scheduleGeneral(this, delay);
  240. +   }
  241. +
  242. +   /**
  243. +    * The task method to teleport the player<br>
  244. +    * 1. Unsummon pet if there is one 2. Remove all effects 3. Revive and full heal the player 4. Teleport the player 5. Broadcast status and user info
  245. +    *
  246. +    * @see java.lang.Runnable#run()
  247. +    */
  248. +   public void run()
  249. +   {
  250. +       if (_playerInstance == null)
  251. +           return;
  252. +       L2Summon summon = _playerInstance.getPet();
  253. +       if (summon != null)
  254. +           summon.unSummon(_playerInstance);
  255. +       for (L2Effect effect : _playerInstance.getAllEffects())
  256. +       {
  257. +           if (effect != null)
  258. +               effect.exit();
  259. +       }
  260. +       _playerInstance.doRevive();
  261. +       _playerInstance.setCurrentCp(_playerInstance.getMaxCp());
  262. +       _playerInstance.setCurrentHp(_playerInstance.getMaxHp());
  263. +       _playerInstance.setCurrentMp(_playerInstance.getMaxMp());
  264. +       _playerInstance.teleToLocation(_coordinates[0], _coordinates[1], _coordinates[2], false);
  265. +       if (GvEEvent.isStarted() && !_adminRemove)
  266. +           _playerInstance.setTeam(GvEEvent.getParticipantTeamId(_playerInstance.getName()) + 1);
  267. +       else
  268. +           _playerInstance.setTeam(0);
  269. +       _playerInstance.broadcastStatusUpdate();
  270. +       _playerInstance.broadcastUserInfo();
  271. +   }
  272. +}
  273. Index: java/realtek/gameserver/handler/voicedcommandhandlers/Wedding.java
  274. ===================================================================
  275. --- java/realtek/gameserver/handler/voicedcommandhandlers/Wedding.java  (revision 718)
  276. +++ java/realtek/gameserver/handler/voicedcommandhandlers/Wedding.java  (working copy)
  277. @@ -13,6 +13,7 @@
  278. import realtek.gameserver.ThreadPoolManager;
  279. import realtek.gameserver.ai.CtrlIntention;
  280. import realtek.gameserver.datatables.SkillTable;
  281. +import realtek.gameserver.events.engines.gve.GvEEvent;
  282. import realtek.gameserver.events.engines.tvt.TvTEvent;
  283. import realtek.gameserver.handler.ihandlers.IVoicedCommandHandler;
  284. import realtek.gameserver.instancemanager.CastleManager;
  285. @@ -326,6 +327,11 @@
  286.             activeChar.sendMessage("[Wedding Manager]: You are in the dimensional rift.");
  287.             return false;
  288.         }
  289. +        else if (!GvEEvent.onEscapeUse(activeChar.getName()))
  290. +        {
  291. +           activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  292. +           return false;
  293. +        }
  294.         else if (!TvTEvent.onEscapeUse(activeChar.getObjectId()))
  295.         {
  296.             activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  297. Index: java/realtek/gameserver/handler/itemhandlers/SummonItems.java
  298. ===================================================================
  299. --- java/realtek/gameserver/handler/itemhandlers/SummonItems.java   (revision 718)
  300. +++ java/realtek/gameserver/handler/itemhandlers/SummonItems.java   (working copy)
  301. @@ -31,6 +31,7 @@
  302. import realtek.gameserver.datatables.SummonItemsData;
  303. import realtek.gameserver.events.engines.CTF;
  304. import realtek.gameserver.events.engines.TvT;
  305. +import realtek.gameserver.events.engines.gve.GvEEvent;
  306. import realtek.gameserver.events.engines.tvt.TvTEvent;
  307. import realtek.gameserver.handler.ihandlers.IItemHandler;
  308. import realtek.gameserver.idfactory.IdFactory;
  309. @@ -66,6 +67,9 @@
  310.         if (!TvTEvent.onItemSummon(playable.getObjectId()))
  311.             return;
  312.  
  313. +       if (!GvEEvent.onItemSummon(playable.getName()))
  314. +           return;
  315. +
  316.         if (activeChar._inEventTvT && TvT._started && !Config.TVT_ALLOW_SUMMON)
  317.         {
  318.             activeChar.sendMessage("You are not allowed to summon by items in event.");
  319. Index: java/realtek/Config.java
  320. ===================================================================
  321. --- java/realtek/Config.java    (revision 718)
  322. +++ java/realtek/Config.java    (working copy)
  323. @@ -369,7 +369,6 @@
  324.     public static boolean               CUSTOM_DROPLIST_TABLE;
  325.     public static boolean               CUSTOM_MERCHANT_TABLES;
  326.  
  327. -
  328.     /** Options */
  329.     public static String               DEFAULT_GLOBAL_CHAT;
  330.     public static String               DEFAULT_TRADE_CHAT;
  331. @@ -679,6 +678,27 @@
  332.     public static int                  TVT_EVENT_EFFECTS_REMOVAL;
  333.     public static TIntIntHashMap       TVT_EVENT_FIGHTER_BUFFS;
  334.     public static TIntIntHashMap       TVT_EVENT_MAGE_BUFFS;
  335. +   public static boolean              GVE_EVENT_ENABLED;
  336. +   public static String[]             GVE_EVENT_INTERVAL;
  337. +    public static int                  GVE_EVENT_PARTICIPATION_TIME;
  338. +    public static int                  GVE_EVENT_RUNNING_TIME;
  339. +    public static int                  GVE_EVENT_PARTICIPATION_NPC_ID;
  340. +    public static int[]                GVE_EVENT_PARTICIPATION_NPC_COORDINATES = new int[3];
  341. +    public static int                  GVE_EVENT_MIN_PLAYERS_IN_TEAMS;
  342. +    public static int                  GVE_EVENT_MAX_PLAYERS_IN_TEAMS;
  343. +    public static int                  GVE_EVENT_RESPAWN_TELEPORT_DELAY;
  344. +    public static int                  GVE_EVENT_START_LEAVE_TELEPORT_DELAY;
  345. +    public static String               GVE_EVENT_TEAM_1_NAME;
  346. +    public static int[]                GVE_EVENT_TEAM_1_COORDINATES = new int[3];
  347. +    public static String               GVE_EVENT_TEAM_2_NAME;
  348. +    public static int[]                GVE_EVENT_TEAM_2_COORDINATES = new int[3];
  349. +    public static List<int[]>          GVE_EVENT_REWARDS = new FastList<int[]>();
  350. +    public static boolean              GVE_EVENT_TARGET_TEAM_MEMBERS_ALLOWED;
  351. +    public static boolean              GVE_EVENT_POTIONS_ALLOWED;
  352. +    public static boolean              GVE_EVENT_SUMMON_BY_ITEM_ALLOWED;
  353. +    public static List<Integer>        GVE_EVENT_DOOR_IDS = new FastList<Integer>();
  354. +    public static byte                 GVE_EVENT_MIN_LVL;
  355. +    public static byte                 GVE_EVENT_MAX_LVL;
  356.  
  357.     // ------------------------------------------------------ //
  358.     //                       NOT DONE                         //
  359. @@ -1867,6 +1887,111 @@
  360.                     }
  361.                 }
  362.  
  363. +               GVE_EVENT_ENABLED                            = Boolean.parseBoolean(Events.getProperty("GvEEventEnabled", "False"));
  364. +                GVE_EVENT_INTERVAL                           = Events.getProperty("GvEEventInterval", "20:00").split(",");
  365. +                GVE_EVENT_PARTICIPATION_TIME                 = Integer.parseInt(Events.getProperty("GvEEventParticipationTime", "3600"));
  366. +                GVE_EVENT_RUNNING_TIME                       = Integer.parseInt(Events.getProperty("GvEEventRunningTime", "1800"));
  367. +                GVE_EVENT_PARTICIPATION_NPC_ID               = Integer.parseInt(Events.getProperty("GvEEventParticipationNpcId", "0"));
  368. +
  369. +
  370. +                if (GVE_EVENT_PARTICIPATION_NPC_ID == 0)
  371. +                {
  372. +                    GVE_EVENT_ENABLED = false;
  373. +                    System.out.println("GvEEventEngine[Config.load()]: invalid config property -> GvEEventParticipationNpcId");
  374. +                }
  375. +                else
  376. +                {
  377. +                    String[] propertySplit                = Events.getProperty("GvEEventParticipationNpcCoordinates", "0,0,0").split(",");
  378. +
  379. +                    if (propertySplit.length < 3)
  380. +                    {
  381. +                        GVE_EVENT_ENABLED = false;
  382. +                        System.out.println("GvEEventEngine[Config.load()]: invalid config property -> GvEEventParticipationNpcCoordinates");
  383. +                    }
  384. +                    else
  385. +                    {
  386. +                        GVE_EVENT_PARTICIPATION_NPC_COORDINATES[0]  = Integer.parseInt(propertySplit[0]);
  387. +                        GVE_EVENT_PARTICIPATION_NPC_COORDINATES[1]  = Integer.parseInt(propertySplit[1]);
  388. +                        GVE_EVENT_PARTICIPATION_NPC_COORDINATES[2]  = Integer.parseInt(propertySplit[2]);
  389. +
  390. +                        GVE_EVENT_MIN_PLAYERS_IN_TEAMS              = Integer.parseInt(Events.getProperty("GvEEventMinPlayersInTeams", "1"));
  391. +                        GVE_EVENT_MAX_PLAYERS_IN_TEAMS              = Integer.parseInt(Events.getProperty("GvEEventMaxPlayersInTeams", "20"));
  392. +                        GVE_EVENT_MIN_LVL                          = (byte)Integer.parseInt(Events.getProperty("GvEEventMinPlayerLevel", "1"));
  393. +                        GVE_EVENT_MAX_LVL                          = (byte)Integer.parseInt(Events.getProperty("GvEEventMaxPlayerLevel", "80"));
  394. +                        GVE_EVENT_RESPAWN_TELEPORT_DELAY            = Integer.parseInt(Events.getProperty("GvEEventRespawnTeleportDelay", "20"));
  395. +                        GVE_EVENT_START_LEAVE_TELEPORT_DELAY        = Integer.parseInt(Events.getProperty("GvEEventStartLeaveTeleportDelay", "20"));
  396. +
  397. +                        GVE_EVENT_TEAM_1_NAME                       = Events.getProperty("GvEEventTeam1Name", "Team1");
  398. +                        propertySplit                               = Events.getProperty("GvEEventTeam1Coordinates", "0,0,0").split(",");
  399. +
  400. +                        if (propertySplit.length < 3)
  401. +                        {
  402. +                            GVE_EVENT_ENABLED = false;
  403. +                            System.out.println("GvEEventEngine[Config.load()]: invalid config property -> GvEEventTeam1Coordinates");
  404. +                        }
  405. +                        else
  406. +                        {
  407. +                            GVE_EVENT_TEAM_1_COORDINATES[0]    = Integer.parseInt(propertySplit[0]);
  408. +                            GVE_EVENT_TEAM_1_COORDINATES[1]    = Integer.parseInt(propertySplit[1]);
  409. +                            GVE_EVENT_TEAM_1_COORDINATES[2]    = Integer.parseInt(propertySplit[2]);
  410. +
  411. +                            GVE_EVENT_TEAM_2_NAME            = Events.getProperty("GvEEventTeam2Name", "Team2");
  412. +                            propertySplit                    = Events.getProperty("GvEEventTeam2Coordinates", "0,0,0").split(",");
  413. +
  414. +                            if (propertySplit.length < 3)
  415. +                            {
  416. +                                GVE_EVENT_ENABLED= false;
  417. +                                System.out.println("GvEEventEngine[Config.load()]: invalid config property -> GvEEventTeam2Coordinates");
  418. +                            }
  419. +                            else
  420. +                            {
  421. +                                GVE_EVENT_TEAM_2_COORDINATES[0]    = Integer.parseInt(propertySplit[0]);
  422. +                                GVE_EVENT_TEAM_2_COORDINATES[1]    = Integer.parseInt(propertySplit[1]);
  423. +                                GVE_EVENT_TEAM_2_COORDINATES[2]    = Integer.parseInt(propertySplit[2]);
  424. +                                propertySplit                    = Events.getProperty("GvEEventReward", "57,100000").split(";");
  425. +
  426. +                                for (String reward : propertySplit)
  427. +                                {
  428. +                                   String[] rewardSplit = reward.split(",");
  429. +
  430. +                                   if (rewardSplit.length != 2)
  431. +                                       System.out.println("GvEEventEngine[Config.load()]: invalid config property -> GvEEventReward \"" + reward + "\"");
  432. +                                   else
  433. +                                   {
  434. +                                       try
  435. +                                       {
  436. +                                           GVE_EVENT_REWARDS.add(new int[]{Integer.valueOf(rewardSplit[0]), Integer.valueOf(rewardSplit[1])});
  437. +                                       }
  438. +                                       catch (NumberFormatException nfe)
  439. +                                       {
  440. +                                           if (!reward.equals(""))
  441. +                                               System.out.println("GvEEventEngine[Config.load()]: invalid config property -> GvEEventReward \"" + reward + "\"");
  442. +                                       }
  443. +                                   }
  444. +                                }
  445. +
  446. +                                GVE_EVENT_TARGET_TEAM_MEMBERS_ALLOWED  = Boolean.parseBoolean(Events.getProperty("GvEEventTargetTeamMembersAllowed", "true"));
  447. +                               GVE_EVENT_POTIONS_ALLOWED               = Boolean.parseBoolean(Events.getProperty("GvEEventPotionsAllowed", "false"));
  448. +                               GVE_EVENT_SUMMON_BY_ITEM_ALLOWED        = Boolean.parseBoolean(Events.getProperty("GvEEventSummonByItemAllowed", "false"));
  449. +                               propertySplit                           = Events.getProperty("GvEEventDoorsCloseOpenOnStartEnd", "").split(";");
  450. +
  451. +                               for (String door : propertySplit)
  452. +                               {
  453. +                                   try
  454. +                                   {
  455. +                                       GVE_EVENT_DOOR_IDS.add(Integer.valueOf(door));
  456. +                                   }
  457. +                                   catch (NumberFormatException nfe)
  458. +                                   {
  459. +                                       if (!door.equals(""))
  460. +                                           System.out.println("GvEEventEngine[Config.load()]: invalid config property -> GvEEventDoorsCloseOpenOnStartEnd \"" + door + "\"");
  461. +                                   }
  462. +                               }
  463. +                            }
  464. +                        }
  465. +                    }
  466. +                }
  467. +
  468.                 // ------------------------------------------------------ //
  469.                 //                       NOT DONE                         //
  470.                 // ------------------------------------------------------ //
  471. @@ -2507,6 +2632,11 @@
  472.         else if (pName.equalsIgnoreCase("TvTEventParticipationTime")) TVT_EVENT_PARTICIPATION_TIME = Integer.parseInt(pValue);
  473.         else if (pName.equalsIgnoreCase("TvTEventRunningTime")) TVT_EVENT_RUNNING_TIME = Integer.parseInt(pValue);
  474.         else if (pName.equalsIgnoreCase("TvTEventParticipationNpcId")) TVT_EVENT_PARTICIPATION_NPC_ID = Integer.parseInt(pValue);
  475. +       else if (pName.equalsIgnoreCase("GvEEventEnabled")) GVE_EVENT_ENABLED = Boolean.parseBoolean(pValue);
  476. +       else if (pName.equalsIgnoreCase("GvEEventInterval")) GVE_EVENT_INTERVAL = pValue.split(",");
  477. +       else if (pName.equalsIgnoreCase("GvEEventParticipationTime")) GVE_EVENT_PARTICIPATION_TIME = Integer.parseInt(pValue);
  478. +       else if (pName.equalsIgnoreCase("GvEEventRunningTime")) GVE_EVENT_RUNNING_TIME = Integer.parseInt(pValue);
  479. +       else if (pName.equalsIgnoreCase("GvEEventParticipationNpcId")) GVE_EVENT_PARTICIPATION_NPC_ID = Integer.parseInt(pValue);
  480.         else return false;
  481.         return true;
  482.     }
  483. Index: java/realtek/gameserver/Olympiad.java
  484. ===================================================================
  485. --- java/realtek/gameserver/Olympiad.java   (revision 718)
  486. +++ java/realtek/gameserver/Olympiad.java   (working copy)
  487. @@ -44,6 +44,7 @@
  488. import realtek.L2DatabaseFactory;
  489. import realtek.gameserver.datatables.HeroSkillTable;
  490. import realtek.gameserver.datatables.SkillTable;
  491. +import realtek.gameserver.events.engines.gve.GvEEvent;
  492. import realtek.gameserver.events.engines.tvt.TvTEvent;
  493. import realtek.gameserver.instancemanager.OlympiadStadiaManager;
  494. import realtek.gameserver.model.Inventory;
  495. @@ -427,6 +428,12 @@
  496.             return false;
  497.         }
  498.  
  499. +        if (GvEEvent.isPlayerParticipant(noble.getName()))
  500. +       {
  501. +           noble.sendMessage("You can't join olympiad while participating on GvE Event.");
  502. +           return false;
  503. +       }
  504. +
  505.         if (!noble.isNoble())
  506.         {
  507.             sm = new SystemMessage(SystemMessageId.ONLY_NOBLESS_CAN_PARTICIPATE_IN_THE_OLYMPIAD);
  508. Index: java/realtek/gameserver/GameServer.java
  509. ===================================================================
  510. --- java/realtek/gameserver/GameServer.java (revision 705)
  511. +++ java/realtek/gameserver/GameServer.java (working copy)
  512. @@ -65,6 +65,7 @@
  513. import realtek.gameserver.datatables.SummonItemsData;
  514. import realtek.gameserver.datatables.TeleportLocationTable;
  515. import realtek.gameserver.datatables.ZoneData;
  516. +import realtek.gameserver.events.engines.gve.manager.GvEManager;
  517. import realtek.gameserver.events.engines.tvt.manager.TvTManager;
  518. import realtek.gameserver.events.games.ArenaLeaderboard;
  519. import realtek.gameserver.events.games.CraftLeaderboard;
  520. @@ -402,6 +403,7 @@
  521.         if (Config.VOTE_EVENT)
  522.             VoteManager.getInstance();
  523.         TvTManager.getInstance();
  524. +        GvEManager.getInstance();
  525.  
  526.         Util.printSection("Status");
  527.         _log.info("Loading automatic online players status...");
  528. Index: java/realtek/gameserver/model/actor/instance/L2PcInstance.java
  529. ===================================================================
  530. --- java/realtek/gameserver/model/actor/instance/L2PcInstance.java  (revision 718)
  531. +++ java/realtek/gameserver/model/actor/instance/L2PcInstance.java  (working copy)
  532. @@ -69,6 +69,7 @@
  533. import realtek.gameserver.datatables.SkillTreeTable;
  534. import realtek.gameserver.events.engines.CTF;
  535. import realtek.gameserver.events.engines.TvT;
  536. +import realtek.gameserver.events.engines.gve.GvEEvent;
  537. import realtek.gameserver.events.engines.tvt.TvTEvent;
  538. import realtek.gameserver.events.games.ArenaLeaderboard;
  539. import realtek.gameserver.handler.ItemHandler;
  540. @@ -4383,6 +4384,7 @@
  541.             L2PcInstance pk = null;
  542.  
  543.             TvTEvent.onKill(killer, this);
  544. +           GvEEvent.onKill(killer, this);
  545.  
  546.             if (_inEventTvT)
  547.             {
  548. @@ -7272,6 +7274,10 @@
  549.         if (TvTEvent.isStarted() && TvTEvent.isPlayerParticipant(getObjectId()))
  550.             return true;
  551.  
  552. +       // Check if the attacker is in GvE and GvE is started
  553. +       if (GvEEvent.isStarted() && GvEEvent.isPlayerParticipant(getName()))
  554. +           return true;
  555. +
  556.         // Check if the attacker is not in the same clan
  557.         if (getClan() != null && attacker != null && getClan().isMember(attacker.getName()))
  558.             return false;
  559. @@ -10006,6 +10012,16 @@
  560.             _log.log(Level.SEVERE, "deleteMe()", e);
  561.         }
  562.  
  563. +       // GvE Event removal
  564. +       try
  565. +       {
  566. +           GvEEvent.onLogout(this);
  567. +       }
  568. +       catch (Exception e)
  569. +       {
  570. +           _log.log(Level.SEVERE, "deleteMe()", e);
  571. +       }
  572. +
  573.         // Update database with items in its freight and remove them from the world
  574.         try { getFreight().deleteMe(); } catch (Throwable t) {_log.log(Level.SEVERE, "deleteMe()", t); }
  575.  
  576. @@ -10532,6 +10548,9 @@
  577.             if (!TvTEvent.isInactive() && TvTEvent.isPlayerParticipant(getObjectId()))
  578.                 TvTEvent.removeParticipant(getObjectId());
  579.  
  580. +            if (!GvEEvent.isInactive() && GvEEvent.isPlayerParticipant(getName()))
  581. +                GvEEvent.removeParticipant(getName());
  582. +
  583.             // Open a Html message to inform the player
  584.             NpcHtmlMessage htmlMsg = new NpcHtmlMessage(0);
  585.             String jailInfos = HtmCache.getInstance().getHtm("data/html/jail_in.htm");
  586. @@ -10691,6 +10710,7 @@
  587.         if(Rnd.get(100) <= Config.DEATH_PENALTY_CHANCE
  588.                 && !(killer instanceof L2PcInstance) && !(this.isGM())
  589.                 && !(TvTEvent.isStarted() && TvTEvent.isPlayerParticipant(getObjectId()))
  590. +               && !(GvEEvent.isStarted() && GvEEvent.isPlayerParticipant(getName()))
  591.                 && !(this.getCharmOfLuck() && (killer instanceof L2BossInstance || killer instanceof L2RaidBossInstance)))
  592.            
  593.             increaseDeathPenaltyBuffLevel();
  594. Index: java/realtek/gameserver/handler/itemhandlers/Potions.java
  595. ===================================================================
  596. --- java/realtek/gameserver/handler/itemhandlers/Potions.java   (revision 718)
  597. +++ java/realtek/gameserver/handler/itemhandlers/Potions.java   (working copy)
  598. @@ -26,6 +26,7 @@
  599. import realtek.gameserver.datatables.SkillTable;
  600. import realtek.gameserver.events.engines.CTF;
  601. import realtek.gameserver.events.engines.TvT;
  602. +import realtek.gameserver.events.engines.gve.GvEEvent;
  603. import realtek.gameserver.events.engines.tvt.TvTEvent;
  604. import realtek.gameserver.handler.ihandlers.IItemHandler;
  605. import realtek.gameserver.model.L2Effect;
  606. @@ -111,13 +112,19 @@
  607.             return;
  608.         }
  609.  
  610. -       if (TvTEvent.isPlayerParticipant(activeChar.getObjectId()))
  611. +       if (Config.TVT_EVENT_POTIONS_ALLOWED && TvTEvent.isPlayerParticipant(activeChar.getObjectId()))
  612.         {
  613.             activeChar.sendMessage("You cannot use potions in event.");
  614.             playable.sendPacket(ActionFailed.STATIC_PACKET);
  615.             return;
  616.         }
  617.  
  618. +       if (!GvEEvent.onPotionUse(playable.getName()))
  619. +       {
  620. +           playable.sendPacket(ActionFailed.STATIC_PACKET);
  621. +           return;
  622. +       }
  623. +
  624.         if (activeChar.isInOlympiadMode())
  625.         {
  626.             activeChar.sendPacket(new SystemMessage(SystemMessageId.THIS_ITEM_IS_NOT_AVAILABLE_FOR_THE_OLYMPIAD_EVENT));
  627. Index: java/realtek/gameserver/events/engines/gve/GvEEvent.java
  628. ===================================================================
  629. --- java/realtek/gameserver/events/engines/gve/GvEEvent.java    (revision 0)
  630. +++ java/realtek/gameserver/events/engines/gve/GvEEvent.java    (revision 0)
  631. @@ -0,0 +1,691 @@
  632. +/*
  633. + * This program is free software; you can redistribute it and/or modify
  634. + * it under the terms of the GNU General Public License as published by
  635. + * the Free Software Foundation; either version 2, or (at your option)
  636. + * any later version.
  637. + *
  638. + * This program is distributed in the hope that it will be useful,
  639. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  640. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  641. + * GNU General Public License for more details.
  642. + *
  643. + * You should have received a copy of the GNU General Public License
  644. + * along with this program; if not, write to the Free Software
  645. + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  646. + * 02111-1307, USA.
  647. + *
  648. + * [URL]http://www.gnu.org/copyleft/gpl.html[/URL]
  649. + */
  650. +package realtek.gameserver.events.engines.gve;
  651. +
  652. +import realtek.Config;
  653. +import realtek.gameserver.datatables.DoorTable;
  654. +import realtek.gameserver.datatables.NpcTable;
  655. +import realtek.gameserver.datatables.SpawnTable;
  656. +import realtek.gameserver.model.L2Character;
  657. +import realtek.gameserver.model.L2Spawn;
  658. +import realtek.gameserver.model.L2Summon;
  659. +import realtek.gameserver.model.L2World;
  660. +import realtek.gameserver.model.actor.instance.L2DoorInstance;
  661. +import realtek.gameserver.model.actor.instance.L2NpcInstance;
  662. +import realtek.gameserver.model.actor.instance.L2PcInstance;
  663. +import realtek.gameserver.model.actor.instance.L2PetInstance;
  664. +import realtek.gameserver.model.actor.instance.L2SummonInstance;
  665. +import realtek.gameserver.network.serverpackets.MagicSkillUser;
  666. +import realtek.gameserver.network.serverpackets.NpcHtmlMessage;
  667. +import realtek.gameserver.templates.L2NpcTemplate;
  668. +import realtek.util.Rnd;
  669. +
  670. +/**
  671. + * @author Realtek
  672. + */
  673. +public class GvEEvent
  674. +{
  675. +   enum EventState
  676. +   {
  677. +       INACTIVE,
  678. +       INACTIVATING,
  679. +       PARTICIPATING,
  680. +       STARTING,
  681. +       STARTED,
  682. +       REWARDING
  683. +   }
  684. +
  685. +   /** The teams of the GvE Event<br> */
  686. +   private static GvEEventTeam[] _teams = new GvEEventTeam[2]; // event only allow max 2 teams
  687. +   /** The state of the GvE Event<br> */
  688. +   private static EventState _state = EventState.INACTIVE;
  689. +   /** The spawn of the participation npc<br> */
  690. +   private static L2Spawn _npcSpawn = null;
  691. +   /** the npc instance of the participation npc<br> */
  692. +   private static L2NpcInstance _lastNpcSpawn = null;
  693. +
  694. +   /**
  695. +    * No instance of this class!<br>
  696. +    */
  697. +   private GvEEvent()
  698. +   {
  699. +   }
  700. +
  701. +   /**
  702. +    * Teams initializing<br>
  703. +    */
  704. +   public static void init()
  705. +   {
  706. +       _teams[0] = new GvEEventTeam(Config.GVE_EVENT_TEAM_1_NAME, Config.GVE_EVENT_TEAM_1_COORDINATES);
  707. +       _teams[1] = new GvEEventTeam(Config.GVE_EVENT_TEAM_2_NAME, Config.GVE_EVENT_TEAM_2_COORDINATES);
  708. +   }
  709. +
  710. +   /**
  711. +    * Starts the participation of the GvE Event<br>
  712. +    * 1. Get L2NpcTemplate by Config.GvE _EVENT_PARTICIPATION_NPC_ID<br>
  713. +    * 2. Try to spawn a new npc of it<br>
  714. +    * <br>
  715. +    *
  716. +    * @return boolean<br>
  717. +    */
  718. +   public static boolean startParticipation()
  719. +   {
  720. +       L2NpcTemplate tmpl = NpcTable.getInstance().getTemplate(Config.GVE_EVENT_PARTICIPATION_NPC_ID);
  721. +       if (tmpl == null)
  722. +       {
  723. +           System.out.println("GvE EventEngine[GvE Event.startParticipation()]: L2NpcTemplate is a NullPointer -> Invalid npc id in configs?");
  724. +           return false;
  725. +       }
  726. +       try
  727. +       {
  728. +           _npcSpawn = new L2Spawn(tmpl);
  729. +           _npcSpawn.setLocx(Config.GVE_EVENT_PARTICIPATION_NPC_COORDINATES[0]);
  730. +           _npcSpawn.setLocy(Config.GVE_EVENT_PARTICIPATION_NPC_COORDINATES[1]);
  731. +           _npcSpawn.setLocz(Config.GVE_EVENT_PARTICIPATION_NPC_COORDINATES[2]);
  732. +           _npcSpawn.setAmount(1);
  733. +           _npcSpawn.setHeading(0);
  734. +           _npcSpawn.setRespawnDelay(1);
  735. +           // later no need to delete spawn from db, we don't store it (false)
  736. +           SpawnTable.getInstance().addNewSpawn(_npcSpawn, false);
  737. +           _npcSpawn.init();
  738. +           _lastNpcSpawn = _npcSpawn.getLastSpawn();
  739. +           _lastNpcSpawn.setCurrentHp(_lastNpcSpawn.getMaxHp());
  740. +           _lastNpcSpawn.setTitle("GvE Event Participation");
  741. +           _lastNpcSpawn.isAggressive();
  742. +           _lastNpcSpawn.decayMe();
  743. +           _lastNpcSpawn.spawnMe(_npcSpawn.getLastSpawn().getX(), _npcSpawn.getLastSpawn().getY(), _npcSpawn.getLastSpawn().getZ());
  744. +           _lastNpcSpawn.broadcastPacket(new MagicSkillUser(_lastNpcSpawn, _lastNpcSpawn, 1034, 1, 1, 1));
  745. +       }
  746. +       catch (Exception e)
  747. +       {
  748. +           System.out.println("GvEEventEngine[GvEEvent.startParticipation()]: exception: " + e);
  749. +           return false;
  750. +       }
  751. +       setState(EventState.PARTICIPATING);
  752. +       return true;
  753. +   }
  754. +
  755. +   /**
  756. +    * Starts the GvEEvent fight<br>
  757. +    * 1. Set state EventState.STARTING<br>
  758. +    * 2. Close doors specified in configs<br>
  759. +    * 3. Abort if not enought participants(return false)<br>
  760. +    * 4. Set state EventState.STARTED<br>
  761. +    * 5. Teleport all participants to team spot<br>
  762. +    * <br>
  763. +    *
  764. +    * @return boolean<br>
  765. +    */
  766. +   public static boolean startFight()
  767. +   {
  768. +       setState(EventState.STARTING);
  769. +       // not enought participants
  770. +       if (_teams[0].getParticipatedPlayerCount() < Config.GVE_EVENT_MIN_PLAYERS_IN_TEAMS || _teams[1].getParticipatedPlayerCount() < Config.GVE_EVENT_MIN_PLAYERS_IN_TEAMS)
  771. +       {
  772. +           setState(EventState.INACTIVE);
  773. +           _teams[0].cleanMe();
  774. +           _teams[1].cleanMe();
  775. +           unSpawnNpc();
  776. +           return false;
  777. +       }
  778. +       closeDoors();
  779. +       setState(EventState.STARTED); // set state to STARTED here, so GvEEventTeleporter know to teleport to team spot
  780. +       // teleport all participants to there team spot
  781. +       for (GvEEventTeam team : _teams)
  782. +       {
  783. +           for (String playerName : team.getParticipatedPlayerNames())
  784. +           {
  785. +               L2PcInstance playerInstance = team.getParticipatedPlayers().get(playerName);
  786. +               if (playerInstance == null)
  787. +                   continue;
  788. +               // implements Runnable and starts itself in constructor
  789. +               new GvETeleporter(playerInstance, team.getCoordinates(), false, false);
  790. +           }
  791. +       }
  792. +       return true;
  793. +   }
  794. +
  795. +   /**
  796. +    * Calculates the GvEEvent reward<br>
  797. +    * 1. If both teams are at a tie(points equals), send it as system message to all participants, if one of the teams have 0 participants left online abort rewarding<br>
  798. +    * 2. Wait till teams are not at a tie anymore<br>
  799. +    * 3. Set state EvcentState.REWARDING<br>
  800. +    * 4. Reward team with more points<br>
  801. +    * 5. Show win html to wining team participants<br>
  802. +    * <br>
  803. +    *
  804. +    * @return String<br>
  805. +    */
  806. +   public static String calculateRewards()
  807. +   {
  808. +       return "GvE Event: The massacre finished.";
  809. +   }
  810. +
  811. +   /**
  812. +    * Stops the GvEEvent fight<br>
  813. +    * 1. Set state EventState.INACTIVATING<br>
  814. +    * 2. Remove GvE npc from world<br>
  815. +    * 3. Open doors specified in configs<br>
  816. +    * 4. Teleport all participants back to participation npc location<br>
  817. +    * 5. Teams cleaning<br>
  818. +    * 6. Set state EventState.INACTIVE<br>
  819. +    */
  820. +   public static void stopFight()
  821. +   {
  822. +       setState(EventState.INACTIVATING);
  823. +       unSpawnNpc();
  824. +       openDoors();
  825. +       for (GvEEventTeam team : _teams)
  826. +       {
  827. +           for (String playerName : team.getParticipatedPlayerNames())
  828. +           {
  829. +               L2PcInstance playerInstance = team.getParticipatedPlayers().get(playerName);
  830. +               if (playerInstance == null)
  831. +                   continue;
  832. +               new GvETeleporter(playerInstance, Config.GVE_EVENT_PARTICIPATION_NPC_COORDINATES, false, false);
  833. +           }
  834. +       }
  835. +       _teams[0].cleanMe();
  836. +       _teams[1].cleanMe();
  837. +       setState(EventState.INACTIVE);
  838. +   }
  839. +
  840. +   /**
  841. +    * Adds a player to a GvEEvent team<br>
  842. +    * 1. Calculate the id of the team in which the player should be added<br>
  843. +    * 2. Add the player to the calculated team<br>
  844. +    * <br>
  845. +    *
  846. +    * @param playerInstance
  847. +    * <br>
  848. +    * @return boolean<br>
  849. +    */
  850. +   public static synchronized boolean addParticipant(L2PcInstance playerInstance)
  851. +   {
  852. +       if (playerInstance == null)
  853. +           return false;
  854. +       byte teamId = 0;
  855. +       if (_teams[0].getParticipatedPlayerCount() == _teams[1].getParticipatedPlayerCount())
  856. +           teamId = (byte) (Rnd.get(2));
  857. +       else
  858. +           teamId = (byte) (_teams[0].getParticipatedPlayerCount() > _teams[1].getParticipatedPlayerCount() ? 1 : 0);
  859. +       return _teams[teamId].addPlayer(playerInstance);
  860. +   }
  861. +
  862. +   /**
  863. +    * Removes a GvEEvent player from it's team<br>
  864. +    * 1. Get team id of the player<br>
  865. +    * 2. Remove player from it's team<br>
  866. +    * <br>
  867. +    *
  868. +    * @param playerName
  869. +    * <br>
  870. +    * @return boolean<br>
  871. +    */
  872. +   public static boolean removeParticipant(String playerName)
  873. +   {
  874. +       byte teamId = getParticipantTeamId(playerName);
  875. +       if (teamId == -1)
  876. +           return false;
  877. +       _teams[teamId].removePlayer(playerName);
  878. +       return true;
  879. +   }
  880. +
  881. +   /**
  882. +    * Send a SystemMessage to all participated players<br>
  883. +    * 1. Send the message to all players of team number one<br>
  884. +    * 2. Send the message to all players of team number two<br>
  885. +    * <br>
  886. +    *
  887. +    * @param message
  888. +    * <br>
  889. +    */
  890. +   public static void sysMsgToAllParticipants(String message)
  891. +   {
  892. +       for (L2PcInstance playerInstance : _teams[0].getParticipatedPlayers().values())
  893. +       {
  894. +           if (playerInstance != null)
  895. +               playerInstance.sendMessage(message);
  896. +       }
  897. +       for (L2PcInstance playerInstance : _teams[1].getParticipatedPlayers().values())
  898. +       {
  899. +           if (playerInstance != null)
  900. +               playerInstance.sendMessage(message);
  901. +       }
  902. +   }
  903. +
  904. +   /**
  905. +    * Close doors specified in configs
  906. +    */
  907. +   private static void closeDoors()
  908. +   {
  909. +       for (int doorId : Config.GVE_EVENT_DOOR_IDS)
  910. +       {
  911. +           L2DoorInstance doorInstance = DoorTable.getInstance().getDoor(doorId);
  912. +           if (doorInstance != null)
  913. +               doorInstance.closeMe();
  914. +       }
  915. +   }
  916. +
  917. +   /**
  918. +    * Open doors specified in configs
  919. +    */
  920. +   private static void openDoors()
  921. +   {
  922. +       for (int doorId : Config.GVE_EVENT_DOOR_IDS)
  923. +       {
  924. +           L2DoorInstance doorInstance = DoorTable.getInstance().getDoor(doorId);
  925. +           if (doorInstance != null)
  926. +               doorInstance.openMe();
  927. +       }
  928. +   }
  929. +
  930. +   /**
  931. +    * UnSpawns the GvEEvent npc
  932. +    */
  933. +   private static void unSpawnNpc()
  934. +   {
  935. +       _lastNpcSpawn.deleteMe();
  936. +       _npcSpawn.stopRespawn();
  937. +       _npcSpawn = null;
  938. +       _lastNpcSpawn = null;
  939. +   }
  940. +
  941. +   /**
  942. +    * Called when a player logs in<br>
  943. +    * <br>
  944. +    *
  945. +    * @param playerInstance
  946. +    * <br>
  947. +    */
  948. +   public static void onLogin(L2PcInstance playerInstance)
  949. +   {
  950. +       if (playerInstance == null || (!isStarting() && !isStarted()))
  951. +           return;
  952. +       byte teamId = getParticipantTeamId(playerInstance.getName());
  953. +       if (teamId == -1)
  954. +           return;
  955. +       _teams[teamId].addPlayer(playerInstance);
  956. +       new GvETeleporter(playerInstance, _teams[teamId].getCoordinates(), true, false);
  957. +   }
  958. +
  959. +   /**
  960. +    * Called when a player logs out<br>
  961. +    * <br>
  962. +    *
  963. +    * @param playerInstance
  964. +    * <br>
  965. +    */
  966. +   public static void onLogout(L2PcInstance playerInstance)
  967. +   {
  968. +       if (playerInstance == null || (!isStarting() && !isStarted()))
  969. +           return;
  970. +       removeParticipant(playerInstance.getName());
  971. +   }
  972. +
  973. +   /**
  974. +    * Called on every bypass by npc of type L2GvEEventNpc<br>
  975. +    * Needs synchronization cause of the max player check<br>
  976. +    * <br>
  977. +    *
  978. +    * @param command
  979. +    * <br>
  980. +    * @param playerInstance
  981. +    * <br>
  982. +    */
  983. +   public static synchronized void onBypass(String command, L2PcInstance playerInstance)
  984. +   {
  985. +       if (playerInstance == null)
  986. +           return;
  987. +      
  988. +       if (command.equals("gve_remove_from_event"))
  989. +       {
  990. +           NpcHtmlMessage npcHtmlMessage = new NpcHtmlMessage(0);
  991. +           npcHtmlMessage.setHtml("<html><head><title>GvE Event</title></head><body>You are now teleported out of the event and you can join again whenever you want.</body></html>");
  992. +           playerInstance.sendPacket(npcHtmlMessage);
  993. +           removeParticipant(playerInstance.getName());
  994. +           playerInstance.teleToLocation(0, 0, 0, false);
  995. +       }
  996. +      
  997. +       if (command.equals("gve_event_participation"))
  998. +       {
  999. +           NpcHtmlMessage npcHtmlMessage = new NpcHtmlMessage(0);
  1000. +           int playerLevel = playerInstance.getLevel();
  1001. +           if (playerInstance.isCursedWeaponEquiped())
  1002. +               npcHtmlMessage.setHtml("<html><head><title>GvE Event</title></head><body>Cursed weapon owners are not allowed to participate.</body></html>");
  1003. +           else if (playerInstance.getKarma() > 0)
  1004. +               npcHtmlMessage.setHtml("<html><head><title>GvE Event</title></head><body>Chaotic players are not allowed to participate.</body></html>");
  1005. +           else if (_teams[0].getParticipatedPlayerCount() >= Config.GVE_EVENT_MAX_PLAYERS_IN_TEAMS && _teams[1].getParticipatedPlayerCount() >= Config.GVE_EVENT_MAX_PLAYERS_IN_TEAMS)
  1006. +               npcHtmlMessage.setHtml("<html><head><title>GvE Event</title></head><body>Sorry ,this faction is full!Choose the other one.</body></html>");
  1007. +           else if (playerLevel < Config.GVE_EVENT_MIN_LVL || playerLevel > Config.GVE_EVENT_MAX_LVL)
  1008. +               npcHtmlMessage.setHtml("<html><head><title>GvE Event</title></head><body>Only players from level " + Config.GVE_EVENT_MIN_LVL + " to level " + Config.GVE_EVENT_MAX_LVL + " are allowed tro participate.</body></html>");
  1009. +           else if (_teams[0].getParticipatedPlayerCount() > 19 && _teams[1].getParticipatedPlayerCount() > 19)
  1010. +               npcHtmlMessage.setHtml("<html><head><title>GvE Event</title></head><body>The factions are full! Maximum of " + Config.GVE_EVENT_MAX_PLAYERS_IN_TEAMS + "  player are allowed in one faction.</body></html>");
  1011. +           else if (addParticipant(playerInstance))
  1012. +               npcHtmlMessage.setHtml("<html><head><title>GvE Event</title></head><body>You are on the registration list now.</body></html>");
  1013. +           else
  1014. +               // addParticipant returned false cause playerInstance == null
  1015. +               return;
  1016. +           playerInstance.sendPacket(npcHtmlMessage);
  1017. +       }
  1018. +       else if (command.equals("gve_event_remove_participation"))
  1019. +       {
  1020. +           removeParticipant(playerInstance.getName());
  1021. +           NpcHtmlMessage npcHtmlMessage = new NpcHtmlMessage(0);
  1022. +           npcHtmlMessage.setHtml("<html><head><title>GvE Event</title></head><body>You are not longer on the registration list.</body></html>");
  1023. +           playerInstance.sendPacket(npcHtmlMessage);
  1024. +       }
  1025. +   }
  1026. +
  1027. +   /**
  1028. +    * Called on every onAction in L2PcIstance<br>
  1029. +    * <br>
  1030. +    *
  1031. +    * @param playerName
  1032. +    * <br>
  1033. +    * @param targetPlayerName
  1034. +    * <br>
  1035. +    * @return boolean<br>
  1036. +    */
  1037. +   public static boolean onAction(String playerName, String targetPlayerName)
  1038. +   {
  1039. +       if (!isStarted())
  1040. +           return true;
  1041. +       L2PcInstance playerInstance = L2World.getInstance().getPlayer(playerName);
  1042. +       if (playerInstance == null)
  1043. +           return false;
  1044. +       if (playerInstance.isGM())
  1045. +           return true;
  1046. +       byte playerTeamId = getParticipantTeamId(playerName);
  1047. +       byte targetPlayerTeamId = getParticipantTeamId(targetPlayerName);
  1048. +       if ((playerTeamId != -1 && targetPlayerTeamId == -1) || (playerTeamId == -1 && targetPlayerTeamId != -1))
  1049. +           return false;
  1050. +       if (playerTeamId != -1 && targetPlayerTeamId != -1 && playerTeamId == targetPlayerTeamId && !Config.GVE_EVENT_TARGET_TEAM_MEMBERS_ALLOWED)
  1051. +           return false;
  1052. +       return true;
  1053. +   }
  1054. +
  1055. +   /**
  1056. +    * Called on every potion use<br>
  1057. +    * <br>
  1058. +    *
  1059. +    * @param playerName
  1060. +    * <br>
  1061. +    * @return boolean<br>
  1062. +    */
  1063. +   public static boolean onPotionUse(String playerName)
  1064. +   {
  1065. +       if (!isStarted())
  1066. +           return true;
  1067. +       if (isPlayerParticipant(playerName) && !Config.GVE_EVENT_POTIONS_ALLOWED)
  1068. +           return false;
  1069. +       return true;
  1070. +   }
  1071. +
  1072. +   /**
  1073. +    * Called on every escape use(thanks to nbd)<br>
  1074. +    * <br>
  1075. +    *
  1076. +    * @param playerName
  1077. +    * <br>
  1078. +    * @return boolean<br>
  1079. +    */
  1080. +   public static boolean onEscapeUse(String playerName)
  1081. +   {
  1082. +       if (!isStarted())
  1083. +           return true;
  1084. +       if (isPlayerParticipant(playerName))
  1085. +           return false;
  1086. +       return true;
  1087. +   }
  1088. +
  1089. +   /**
  1090. +    * Called on every summon item use<br>
  1091. +    * <br>
  1092. +    *
  1093. +    * @param playerName
  1094. +    * <br>
  1095. +    * @return boolean<br>
  1096. +    */
  1097. +   public static boolean onItemSummon(String playerName)
  1098. +   {
  1099. +       if (!isStarted())
  1100. +           return true;
  1101. +       if (isPlayerParticipant(playerName) && !Config.GVE_EVENT_SUMMON_BY_ITEM_ALLOWED)
  1102. +           return false;
  1103. +       return true;
  1104. +   }
  1105. +
  1106. +   /**
  1107. +    * Is called when a player is killed<br>
  1108. +    * <br>
  1109. +    *
  1110. +    * @param killerCharacter
  1111. +    * <br>
  1112. +    * @param killedPlayerInstance
  1113. +    * <br>
  1114. +    */
  1115. +   public static void onKill(L2Character killerCharacter, L2PcInstance killedPlayerInstance)
  1116. +   {
  1117. +       if (killerCharacter == null || killedPlayerInstance == null || (!(killerCharacter instanceof L2PcInstance) && !(killerCharacter instanceof L2PetInstance) && !(killerCharacter instanceof L2SummonInstance)) || !isStarted())
  1118. +           return;
  1119. +       L2PcInstance killerPlayerInstance = null;
  1120. +       if (killerCharacter instanceof L2PetInstance || killerCharacter instanceof L2SummonInstance)
  1121. +       {
  1122. +           killerPlayerInstance = ((L2Summon) killerCharacter).getOwner();
  1123. +           if (killerPlayerInstance == null)
  1124. +               return;
  1125. +       }
  1126. +       else
  1127. +           killerPlayerInstance = (L2PcInstance) killerCharacter;
  1128. +       String playerName = killerPlayerInstance.getName();
  1129. +       byte killerTeamId = getParticipantTeamId(playerName);
  1130. +       playerName = killedPlayerInstance.getName();
  1131. +       byte killedTeamId = getParticipantTeamId(playerName);
  1132. +       if (killerTeamId != -1 && killedTeamId != -1 && killerTeamId != killedTeamId)
  1133. +           killerPlayerInstance.addItem("Loot", 767, 1, killerPlayerInstance, true);
  1134. +       if (killedTeamId != -1)
  1135. +           new GvETeleporter(killedPlayerInstance, _teams[killedTeamId].getCoordinates(), false, false);
  1136. +   }
  1137. +
  1138. +   /**
  1139. +    * Sets the GvEEvent state<br>
  1140. +    * <br>
  1141. +    *
  1142. +    * @param state
  1143. +    * <br>
  1144. +    */
  1145. +   private static void setState(EventState state)
  1146. +   {
  1147. +       synchronized (_state)
  1148. +       {
  1149. +           _state = state;
  1150. +       }
  1151. +   }
  1152. +
  1153. +   /**
  1154. +    * Is GvEEvent inactive?<br>
  1155. +    * <br>
  1156. +    *
  1157. +    * @return boolean<br>
  1158. +    */
  1159. +   public static boolean isInactive()
  1160. +   {
  1161. +       boolean isInactive;
  1162. +       synchronized (_state)
  1163. +       {
  1164. +           isInactive = _state == EventState.INACTIVE;
  1165. +       }
  1166. +       return isInactive;
  1167. +   }
  1168. +
  1169. +   /**
  1170. +    * Is GvEEvent in inactivating?<br>
  1171. +    * <br>
  1172. +    *
  1173. +    * @return boolean<br>
  1174. +    */
  1175. +   public static boolean isInactivating()
  1176. +   {
  1177. +       boolean isInactivating;
  1178. +       synchronized (_state)
  1179. +       {
  1180. +           isInactivating = _state == EventState.INACTIVATING;
  1181. +       }
  1182. +       return isInactivating;
  1183. +   }
  1184. +
  1185. +   /**
  1186. +    * Is GvEEvent in participation?<br>
  1187. +    * <br>
  1188. +    *
  1189. +    * @return boolean<br>
  1190. +    */
  1191. +   public static boolean isParticipating()
  1192. +   {
  1193. +       boolean isParticipating;
  1194. +       synchronized (_state)
  1195. +       {
  1196. +           isParticipating = _state == EventState.PARTICIPATING;
  1197. +       }
  1198. +       return isParticipating;
  1199. +   }
  1200. +
  1201. +   /**
  1202. +    * Is GvEEvent starting?<br>
  1203. +    * <br>
  1204. +    *
  1205. +    * @return boolean<br>
  1206. +    */
  1207. +   public static boolean isStarting()
  1208. +   {
  1209. +       boolean isStarting;
  1210. +       synchronized (_state)
  1211. +       {
  1212. +           isStarting = _state == EventState.STARTING;
  1213. +       }
  1214. +       return isStarting;
  1215. +   }
  1216. +
  1217. +   /**
  1218. +    * Is GvEEvent started?<br>
  1219. +    * <br>
  1220. +    *
  1221. +    * @return boolean<br>
  1222. +    */
  1223. +   public static boolean isStarted()
  1224. +   {
  1225. +       boolean isStarted;
  1226. +       synchronized (_state)
  1227. +       {
  1228. +           isStarted = _state == EventState.STARTED;
  1229. +       }
  1230. +       return isStarted;
  1231. +   }
  1232. +
  1233. +   /**
  1234. +    * Is GvEEvent rewadrding?<br>
  1235. +    * <br>
  1236. +    *
  1237. +    * @return boolean<br>
  1238. +    */
  1239. +   public static boolean isRewarding()
  1240. +   {
  1241. +       boolean isRewarding;
  1242. +       synchronized (_state)
  1243. +       {
  1244. +           isRewarding = _state == EventState.REWARDING;
  1245. +       }
  1246. +       return isRewarding;
  1247. +   }
  1248. +
  1249. +   /**
  1250. +    * Returns the team id of a player, if player is not participant it returns -1<br>
  1251. +    * <br>
  1252. +    *
  1253. +    * @param playerName
  1254. +    * <br>
  1255. +    * @return byte<br>
  1256. +    */
  1257. +   public static byte getParticipantTeamId(String playerName)
  1258. +   {
  1259. +       return (byte) (_teams[0].containsPlayer(playerName) ? 0 : (_teams[1].containsPlayer(playerName) ? 1 : -1));
  1260. +   }
  1261. +
  1262. +   /**
  1263. +    * Returns the team coordinates in which the player is in, if player is not in a team return null<br>
  1264. +    * <br>
  1265. +    *
  1266. +    * @param playerName
  1267. +    * <br>
  1268. +    * @return int[]<br>
  1269. +    */
  1270. +   public static int[] getParticipantTeamCoordinates(String playerName)
  1271. +   {
  1272. +       return _teams[0].containsPlayer(playerName) ? _teams[0].getCoordinates() : (_teams[1].containsPlayer(playerName) ? _teams[1].getCoordinates() : null);
  1273. +   }
  1274. +
  1275. +   /**
  1276. +    * Is given player participant of the event?<br>
  1277. +    * <br>
  1278. +    *
  1279. +    * @param playerName
  1280. +    * <br>
  1281. +    * @return boolean<br>
  1282. +    */
  1283. +   public static boolean isPlayerParticipant(String playerName)
  1284. +   {
  1285. +       return _teams[0].containsPlayer(playerName) || _teams[1].containsPlayer(playerName);
  1286. +   }
  1287. +
  1288. +   /**
  1289. +    * Returns participated player count<br>
  1290. +    * <br>
  1291. +    *
  1292. +    * @return int<br>
  1293. +    */
  1294. +   public static int getParticipatedPlayersCount()
  1295. +   {
  1296. +       return _teams[0].getParticipatedPlayerCount() + _teams[1].getParticipatedPlayerCount();
  1297. +   }
  1298. +
  1299. +   /**
  1300. +    * Returns teams names<br>
  1301. +    * <br>
  1302. +    *
  1303. +    * @return String[]<br>
  1304. +    */
  1305. +   public static String[] getTeamNames()
  1306. +   {
  1307. +       return new String[] { _teams[0].getName(), _teams[1].getName() };
  1308. +   }
  1309. +
  1310. +   /**
  1311. +    * Returns player count of both teams<br>
  1312. +    * <br>
  1313. +    *
  1314. +    * @return int[]<br>
  1315. +    */
  1316. +   public static int[] getTeamsPlayerCounts()
  1317. +   {
  1318. +       return new int[] { _teams[0].getParticipatedPlayerCount(), _teams[1].getParticipatedPlayerCount() };
  1319. +   }
  1320. +
  1321. +
  1322. +}
  1323. Index: java/realtek/gameserver/network/clientpackets/EnterWorld.java
  1324. ===================================================================
  1325. --- java/realtek/gameserver/network/clientpackets/EnterWorld.java   (revision 718)
  1326. +++ java/realtek/gameserver/network/clientpackets/EnterWorld.java   (working copy)
  1327. @@ -35,6 +35,7 @@
  1328. import realtek.gameserver.datatables.MapRegionTable;
  1329. import realtek.gameserver.events.engines.CTF;
  1330. import realtek.gameserver.events.engines.TvT;
  1331. +import realtek.gameserver.events.engines.gve.GvEEvent;
  1332. import realtek.gameserver.events.engines.tvt.TvTEvent;
  1333. import realtek.gameserver.handler.AdminCommandHandler;
  1334. import realtek.gameserver.instancemanager.CastleManager;
  1335. @@ -420,6 +421,7 @@
  1336.         }
  1337.  
  1338.         TvTEvent.onLogin(activeChar);
  1339. +        GvEEvent.onLogin(activeChar);
  1340.  
  1341.         RegionBBSManager.getInstance().changeCommunityBoard();
  1342.         CrownManager.getInstance().checkCrowns(activeChar);
  1343. Index: java/realtek/gameserver/handler/itemhandlers/Scrolls.java
  1344. ===================================================================
  1345. --- java/realtek/gameserver/handler/itemhandlers/Scrolls.java   (revision 718)
  1346. +++ java/realtek/gameserver/handler/itemhandlers/Scrolls.java   (working copy)
  1347. @@ -18,6 +18,7 @@
  1348. package realtek.gameserver.handler.itemhandlers;
  1349.  
  1350. import realtek.gameserver.datatables.SkillTable;
  1351. +import realtek.gameserver.events.engines.gve.GvEEvent;
  1352. import realtek.gameserver.events.engines.tvt.TvTEvent;
  1353. import realtek.gameserver.handler.ihandlers.IItemHandler;
  1354. import realtek.gameserver.model.L2ItemInstance;
  1355. @@ -69,6 +70,12 @@
  1356.             return;
  1357.         }
  1358.  
  1359. +       if (GvEEvent.isPlayerParticipant(activeChar.getName()))
  1360. +       {
  1361. +           playable.sendPacket(ActionFailed.STATIC_PACKET);
  1362. +           return;
  1363. +       }
  1364. +
  1365.         if (activeChar.isInOlympiadMode())
  1366.         {
  1367.             activeChar.sendPacket(new SystemMessage(SystemMessageId.THIS_ITEM_IS_NOT_AVAILABLE_FOR_THE_OLYMPIAD_EVENT));
  1368. Index: java/realtek/gameserver/handler/itemhandlers/ScrollOfResurrection.java
  1369. ===================================================================
  1370. --- java/realtek/gameserver/handler/itemhandlers/ScrollOfResurrection.java  (revision 718)
  1371. +++ java/realtek/gameserver/handler/itemhandlers/ScrollOfResurrection.java  (working copy)
  1372. @@ -19,6 +19,7 @@
  1373. package realtek.gameserver.handler.itemhandlers;
  1374.  
  1375. import realtek.gameserver.datatables.SkillTable;
  1376. +import realtek.gameserver.events.engines.gve.GvEEvent;
  1377. import realtek.gameserver.events.engines.tvt.TvTEvent;
  1378. import realtek.gameserver.handler.ihandlers.IItemHandler;
  1379. import realtek.gameserver.instancemanager.CastleManager;
  1380. @@ -70,6 +71,11 @@
  1381.             playable.sendPacket(ActionFailed.STATIC_PACKET);
  1382.             return;
  1383.         }
  1384. +        if (GvEEvent.isPlayerParticipant(activeChar.getName()))
  1385. +       {
  1386. +           playable.sendPacket(ActionFailed.STATIC_PACKET);
  1387. +           return;
  1388. +       }
  1389.  
  1390.         int itemId = item.getItemId();
  1391.         //boolean blessedScroll = (itemId != 737);
  1392. Index: java/realtek/gameserver/events/engines/gve/GvEEventTeam.java
  1393. ===================================================================
  1394. --- java/realtek/gameserver/events/engines/gve/GvEEventTeam.java    (revision 0)
  1395. +++ java/realtek/gameserver/events/engines/gve/GvEEventTeam.java    (revision 0)
  1396. @@ -0,0 +1,193 @@
  1397. +/*
  1398. + * This program is free software; you can redistribute it and/or modify
  1399. + * it under the terms of the GNU General Public License as published by
  1400. + * the Free Software Foundation; either version 2, or (at your option)
  1401. + * any later version.
  1402. + *
  1403. + * This program is distributed in the hope that it will be useful,
  1404. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1405. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1406. + * GNU General Public License for more details.
  1407. + *
  1408. + * You should have received a copy of the GNU General Public License
  1409. + * along with this program; if not, write to the Free Software
  1410. + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  1411. + * 02111-1307, USA.
  1412. + *
  1413. + * [URL]http://www.gnu.org/copyleft/gpl.html[/URL]
  1414. + */
  1415. +package realtek.gameserver.events.engines.gve;
  1416. +
  1417. +import java.util.Map;
  1418. +import java.util.Vector;
  1419. +
  1420. +import javolution.util.FastMap;
  1421. +import realtek.gameserver.model.actor.instance.L2PcInstance;
  1422. +
  1423. +/**
  1424. + * @author Realtek
  1425. + */
  1426. +public class GvEEventTeam
  1427. +{
  1428. +   /** The name of the team<br> */
  1429. +   private String _name;
  1430. +   /** The team spot coordinated<br> */
  1431. +   private int[] _coordinates = new int[3];
  1432. +   /** Name and instance of all participated players in FastMap<br> */
  1433. +   private Map<String, L2PcInstance> _participatedPlayers = new FastMap<String, L2PcInstance>();
  1434. +   /** Name of all participated players in Vector<br> */
  1435. +   private Vector<String> _participatedPlayerNames = new Vector<String>();
  1436. +
  1437. +   /**
  1438. +    * C'tor initialize the team<br>
  1439. +    * <br>
  1440. +    *
  1441. +    * @param name
  1442. +    * <br>
  1443. +    * @param coordinates
  1444. +    * <br>
  1445. +    */
  1446. +   public GvEEventTeam(String name, int[] coordinates)
  1447. +   {
  1448. +       _name = name;
  1449. +       _coordinates = coordinates;
  1450. +   }
  1451. +
  1452. +   /**
  1453. +    * Adds a player to the team<br>
  1454. +    * <br>
  1455. +    *
  1456. +    * @param playerInstance
  1457. +    * <br>
  1458. +    * @return boolean<br>
  1459. +    */
  1460. +   public boolean addPlayer(L2PcInstance playerInstance)
  1461. +   {
  1462. +       if (playerInstance == null)
  1463. +           return false;
  1464. +       synchronized (_participatedPlayers)
  1465. +       {
  1466. +           String playerName = playerInstance.getName();
  1467. +           _participatedPlayers.put(playerName, playerInstance);
  1468. +           if (!_participatedPlayerNames.contains(playerName))
  1469. +               _participatedPlayerNames.add(playerName);
  1470. +       }
  1471. +       return true;
  1472. +   }
  1473. +
  1474. +   /**
  1475. +    * Removes a player from the team<br>
  1476. +    * <br>
  1477. +    *
  1478. +    * @param playerName
  1479. +    * <br>
  1480. +    */
  1481. +   public void removePlayer(String playerName)
  1482. +   {
  1483. +       synchronized (_participatedPlayers)
  1484. +       {
  1485. +           _participatedPlayers.remove(playerName);
  1486. +           _participatedPlayerNames.remove(playerName);
  1487. +       }
  1488. +   }
  1489. +
  1490. +   /**
  1491. +    * Cleanup the team and make it ready for adding players again<br>
  1492. +    */
  1493. +   public void cleanMe()
  1494. +   {
  1495. +       _participatedPlayers.clear();
  1496. +       _participatedPlayerNames.clear();
  1497. +       _participatedPlayers = new FastMap<String, L2PcInstance>();
  1498. +       _participatedPlayerNames = new Vector<String>();
  1499. +
  1500. +   }
  1501. +
  1502. +   /**
  1503. +    * Is given player in this team?<br>
  1504. +    * <br>
  1505. +    *
  1506. +    * @param playerName
  1507. +    * <br>
  1508. +    * @return boolean<br>
  1509. +    */
  1510. +   public boolean containsPlayer(String playerName)
  1511. +   {
  1512. +       boolean containsPlayer;
  1513. +       synchronized (_participatedPlayers)
  1514. +       {
  1515. +           containsPlayer = _participatedPlayerNames.contains(playerName);
  1516. +       }
  1517. +       return containsPlayer;
  1518. +   }
  1519. +
  1520. +   /**
  1521. +    * Returns the name of the team<br>
  1522. +    * <br>
  1523. +    *
  1524. +    * @return String<br>
  1525. +    */
  1526. +   public String getName()
  1527. +   {
  1528. +       return _name;
  1529. +   }
  1530. +
  1531. +   /**
  1532. +    * Returns the coordinates of the team spot<br>
  1533. +    * <br>
  1534. +    *
  1535. +    * @return int[]<br>
  1536. +    */
  1537. +   public int[] getCoordinates()
  1538. +   {
  1539. +       return _coordinates;
  1540. +   }
  1541. +
  1542. +   /**
  1543. +    * Returns name and instance of all participated players in FastMap<br>
  1544. +    * <br>
  1545. +    *
  1546. +    * @return Map<String, L2PcInstance><br>
  1547. +    */
  1548. +   public Map<String, L2PcInstance> getParticipatedPlayers()
  1549. +   {
  1550. +       Map<String, L2PcInstance> participatedPlayers = null;
  1551. +       synchronized (_participatedPlayers)
  1552. +       {
  1553. +           participatedPlayers = _participatedPlayers;
  1554. +       }
  1555. +       return participatedPlayers;
  1556. +   }
  1557. +
  1558. +   /**
  1559. +    * Returns name of all participated players in Vector<br>
  1560. +    * <br>
  1561. +    *
  1562. +    * @return Vector<String><br>
  1563. +    */
  1564. +   public Vector<String> getParticipatedPlayerNames()
  1565. +   {
  1566. +       Vector<String> participatedPlayerNames = null;
  1567. +       synchronized (_participatedPlayers)
  1568. +       {
  1569. +           participatedPlayerNames = _participatedPlayerNames;
  1570. +       }
  1571. +       return participatedPlayerNames;
  1572. +   }
  1573. +
  1574. +   /**
  1575. +    * Returns player count of this team<br>
  1576. +    * <br>
  1577. +    *
  1578. +    * @return int<br>
  1579. +    */
  1580. +   public int getParticipatedPlayerCount()
  1581. +   {
  1582. +       int participatedPlayerCount;
  1583. +       synchronized (_participatedPlayers)
  1584. +       {
  1585. +           participatedPlayerCount = _participatedPlayers.size();
  1586. +       }
  1587. +       return participatedPlayerCount;
  1588. +   }
  1589. +}
  1590. \ No newline at end of file
  1591. Index: java/realtek/gameserver/handler/itemhandlers/ScrollOfEscape.java
  1592. ===================================================================
  1593. --- java/realtek/gameserver/handler/itemhandlers/ScrollOfEscape.java    (revision 718)
  1594. +++ java/realtek/gameserver/handler/itemhandlers/ScrollOfEscape.java    (working copy)
  1595. @@ -24,6 +24,7 @@
  1596. import realtek.gameserver.ai.CtrlIntention;
  1597. import realtek.gameserver.datatables.MapRegionTable;
  1598. import realtek.gameserver.datatables.SkillTable;
  1599. +import realtek.gameserver.events.engines.gve.GvEEvent;
  1600. import realtek.gameserver.events.engines.tvt.TvTEvent;
  1601. import realtek.gameserver.handler.ihandlers.IItemHandler;
  1602. import realtek.gameserver.instancemanager.CastleManager;
  1603. @@ -71,6 +72,12 @@
  1604.             return;
  1605.         }
  1606.  
  1607. +        if (!GvEEvent.onEscapeUse(activeChar.getName()))
  1608. +        {
  1609. +           activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  1610. +           return;
  1611. +        }
  1612. +
  1613.         if (activeChar.isSitting())
  1614.         {
  1615.             activeChar.sendPacket(new SystemMessage(SystemMessageId.CANT_MOVE_SITTING));
  1616. Index: java/realtek/gameserver/handler/usercommandhandlers/Escape.java
  1617. ===================================================================
  1618. --- java/realtek/gameserver/handler/usercommandhandlers/Escape.java (revision 718)
  1619. +++ java/realtek/gameserver/handler/usercommandhandlers/Escape.java (working copy)
  1620. @@ -24,6 +24,7 @@
  1621. import realtek.gameserver.ai.CtrlIntention;
  1622. import realtek.gameserver.datatables.MapRegionTable;
  1623. import realtek.gameserver.datatables.SkillTable;
  1624. +import realtek.gameserver.events.engines.gve.GvEEvent;
  1625. import realtek.gameserver.events.engines.tvt.TvTEvent;
  1626. import realtek.gameserver.handler.ihandlers.IUserCommandHandler;
  1627. import realtek.gameserver.model.L2Skill;
  1628. @@ -57,6 +58,12 @@
  1629.             return false;
  1630.         }
  1631.  
  1632. +        if (!GvEEvent.onEscapeUse(activeChar.getName()))
  1633. +       {
  1634. +           activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  1635. +           return false;
  1636. +       }
  1637. +
  1638.         int unstuckTimer = (activeChar.getAccessLevel() >=REQUIRED_LEVEL? 5000 : Config.UNSTUCK_INTERVAL*1000 );
  1639.  
  1640.         // Check to see if the player is in a festival.
  1641. Index: java/realtek/gameserver/events/engines/gve/manager/GvEManager.java
  1642. ===================================================================
  1643. --- java/realtek/gameserver/events/engines/gve/manager/GvEManager.java  (revision 0)
  1644. +++ java/realtek/gameserver/events/engines/gve/manager/GvEManager.java  (revision 0)
  1645. @@ -0,0 +1,298 @@
  1646. +/*
  1647. + * This program is free software: you can redistribute it and/or modify it under
  1648. + * the terms of the GNU General Public License as published by the Free Software
  1649. + * Foundation, either version 3 of the License, or (at your option) any later
  1650. + * version.
  1651. + *
  1652. + * This program is distributed in the hope that it will be useful, but WITHOUT
  1653. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  1654. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  1655. + * details.
  1656. + *
  1657. + * You should have received a copy of the GNU General Public License along with
  1658. + * this program. If not, see <http://www.gnu.org/licenses/>.
  1659. + */
  1660. +package realtek.gameserver.events.engines.gve.manager;
  1661. +
  1662. +import java.util.Calendar;
  1663. +import java.util.concurrent.ScheduledFuture;
  1664. +import java.util.logging.Logger;
  1665. +
  1666. +import realtek.Config;
  1667. +import realtek.gameserver.Announcements;
  1668. +import realtek.gameserver.ThreadPoolManager;
  1669. +import realtek.gameserver.events.engines.gve.GvEEvent;
  1670. +
  1671. +
  1672. +/**
  1673. + * @author FBIagent
  1674. + */
  1675. +public class GvEManager
  1676. +{
  1677. +   protected static final Logger _log = Logger.getLogger(GvEManager.class.getName());
  1678. +  
  1679. +   /** Task for event cycles<br> */
  1680. +   private GvEStartTask _task;
  1681. +  
  1682. +   /**
  1683. +    * New instance only by getInstance()<br>
  1684. +    */
  1685. +   private GvEManager()
  1686. +   {
  1687. +       if (Config.GVE_EVENT_ENABLED)
  1688. +       {
  1689. +           GvEEvent.init();
  1690. +          
  1691. +           this.scheduleEventStart();
  1692. +           _log.info("GvE Event - Started.");
  1693. +       }
  1694. +       else
  1695. +       {
  1696. +           _log.info("GvE Event - Event Disabled.");
  1697. +       }
  1698. +   }
  1699. +  
  1700. +   /**
  1701. +    * Initialize new/Returns the one and only instance<br><br>
  1702. +    *
  1703. +    * @return GvEManager<br>
  1704. +    */
  1705. +   public static GvEManager getInstance()
  1706. +   {
  1707. +       return SingletonHolder._instance;
  1708. +   }
  1709. +  
  1710. +   /**
  1711. +    * Starts GvEStartTask
  1712. +    */
  1713. +   public void scheduleEventStart()
  1714. +   {
  1715. +       try
  1716. +       {
  1717. +           Calendar currentTime = Calendar.getInstance();
  1718. +           Calendar nextStartTime = null;
  1719. +           Calendar testStartTime = null;
  1720. +           for (String timeOfDay : Config.GVE_EVENT_INTERVAL)
  1721. +           {
  1722. +               // Creating a Calendar object from the specified interval value
  1723. +               testStartTime = Calendar.getInstance();
  1724. +               testStartTime.setLenient(true);
  1725. +               String[] splitTimeOfDay = timeOfDay.split(":");
  1726. +               testStartTime.set(Calendar.HOUR_OF_DAY, Integer.parseInt(splitTimeOfDay[0]));
  1727. +               testStartTime.set(Calendar.MINUTE, Integer.parseInt(splitTimeOfDay[1]));
  1728. +               // If the date is in the past, make it the next day (Example: Checking for "1:00", when the time is 23:57.)
  1729. +               if (testStartTime.getTimeInMillis() < currentTime.getTimeInMillis())
  1730. +               {
  1731. +                   testStartTime.add(Calendar.DAY_OF_MONTH, 1);
  1732. +               }
  1733. +               // Check for the test date to be the minimum (smallest in the specified list)
  1734. +               if (nextStartTime == null || testStartTime.getTimeInMillis() < nextStartTime.getTimeInMillis())
  1735. +               {
  1736. +                   nextStartTime = testStartTime;
  1737. +               }
  1738. +           }
  1739. +           _task = new GvEStartTask(nextStartTime.getTimeInMillis());
  1740. +           ThreadPoolManager.getInstance().executeTask(_task);
  1741. +       }
  1742. +       catch (Exception e)
  1743. +       {
  1744. +           _log.warning("GvEEventEngine[GvEManager.scheduleEventStart()]: Error figuring out a start time. Check GvEEventInterval in config file.");
  1745. +       }
  1746. +   }
  1747. +  
  1748. +   /**
  1749. +    * Method to start participation
  1750. +    */
  1751. +   public void startReg()
  1752. +   {
  1753. +       if (!GvEEvent.startParticipation())
  1754. +       {
  1755. +           Announcements.getInstance().announceToAll("GvE Event: Event was cancelled.");
  1756. +           _log.warning("GvEEventEngine[GvEManager.run()]: Error spawning event npc for participation.");
  1757. +          
  1758. +           this.scheduleEventStart();
  1759. +       }
  1760. +       else
  1761. +       {
  1762. +           Announcements.getInstance().announceToAll("GvE Event: Registration opened for " + Config.GVE_EVENT_PARTICIPATION_TIME
  1763. +                   + " minute(s).");
  1764. +          
  1765. +           // schedule registration end
  1766. +           _task.setStartTime(System.currentTimeMillis() + 60000L * Config.GVE_EVENT_PARTICIPATION_TIME);
  1767. +           ThreadPoolManager.getInstance().executeTask(_task);
  1768. +       }
  1769. +   }
  1770. +  
  1771. +   /**
  1772. +    * Method to start the fight
  1773. +    */
  1774. +   public void startEvent()
  1775. +   {
  1776. +       if (!GvEEvent.startFight())
  1777. +       {
  1778. +           Announcements.getInstance().announceToAll("GvE Event: Event cancelled due to lack of Participation.");
  1779. +           _log.info("GvEEventEngine[GvEManager.run()]: Lack of registration, abort event.");
  1780. +          
  1781. +           this.scheduleEventStart();
  1782. +       }
  1783. +       else
  1784. +       {
  1785. +           GvEEvent.sysMsgToAllParticipants("GvE Event: Teleporting participants to an arena in "
  1786. +                   + Config.GVE_EVENT_START_LEAVE_TELEPORT_DELAY + " second(s).");
  1787. +           _task.setStartTime(System.currentTimeMillis() + 60000L * Config.GVE_EVENT_RUNNING_TIME);
  1788. +           ThreadPoolManager.getInstance().executeTask(_task);
  1789. +       }
  1790. +   }
  1791. +  
  1792. +   /**
  1793. +    * Method to end the event and reward
  1794. +    */
  1795. +   public void endEvent()
  1796. +   {
  1797. +       Announcements.getInstance().announceToAll(GvEEvent.calculateRewards());
  1798. +       GvEEvent.sysMsgToAllParticipants("GvE Event: Teleporting back to the registration npc in "
  1799. +               + Config.GVE_EVENT_START_LEAVE_TELEPORT_DELAY + " second(s).");
  1800. +       GvEEvent.stopFight();
  1801. +      
  1802. +       this.scheduleEventStart();
  1803. +   }
  1804. +  
  1805. +   public void skipDelay()
  1806. +   {
  1807. +       if (_task.nextRun.cancel(false))
  1808. +       {
  1809. +           _task.setStartTime(System.currentTimeMillis());
  1810. +           ThreadPoolManager.getInstance().executeTask(_task);
  1811. +       }
  1812. +   }
  1813. +  
  1814. +   /**
  1815. +    * Class for GvE cycles
  1816. +    */
  1817. +   class GvEStartTask implements Runnable
  1818. +   {
  1819. +       private long _startTime;
  1820. +       public ScheduledFuture<?> nextRun;
  1821. +      
  1822. +       public GvEStartTask(long startTime)
  1823. +       {
  1824. +           _startTime = startTime;
  1825. +       }
  1826. +      
  1827. +       public void setStartTime(long startTime)
  1828. +       {
  1829. +           _startTime = startTime;
  1830. +       }
  1831. +      
  1832. +       /**
  1833. +        * @see java.lang.Runnable#run()
  1834. +        */
  1835. +       public void run()
  1836. +       {
  1837. +           int delay = (int) Math.round((_startTime - System.currentTimeMillis()) / 1000.0);
  1838. +          
  1839. +           if (delay > 0)
  1840. +           {
  1841. +               this.announce(delay);
  1842. +           }
  1843. +          
  1844. +           int nextMsg = 0;
  1845. +           if (delay > 3600)
  1846. +           {
  1847. +               nextMsg = delay - 3600;
  1848. +           }
  1849. +           else if (delay > 1800)
  1850. +           {
  1851. +               nextMsg = delay - 1800;
  1852. +           }
  1853. +           else if (delay > 900)
  1854. +           {
  1855. +               nextMsg = delay - 900;
  1856. +           }
  1857. +           else if (delay > 600)
  1858. +           {
  1859. +               nextMsg = delay - 600;
  1860. +           }
  1861. +           else if (delay > 300)
  1862. +           {
  1863. +               nextMsg = delay - 300;
  1864. +           }
  1865. +           else if (delay > 60)
  1866. +           {
  1867. +               nextMsg = delay - 60;
  1868. +           }
  1869. +           else if (delay > 5)
  1870. +           {
  1871. +               nextMsg = delay - 5;
  1872. +           }
  1873. +           else if (delay > 0)
  1874. +           {
  1875. +               nextMsg = delay;
  1876. +           }
  1877. +           else
  1878. +           {
  1879. +               // start
  1880. +               if (GvEEvent.isInactive())
  1881. +               {
  1882. +                   GvEManager.this.startReg();
  1883. +               }
  1884. +               else if (GvEEvent.isParticipating())
  1885. +               {
  1886. +                   GvEManager.this.startEvent();
  1887. +               }
  1888. +               else
  1889. +               {
  1890. +                   GvEManager.this.endEvent();
  1891. +               }
  1892. +           }
  1893. +          
  1894. +           if (delay > 0)
  1895. +           {
  1896. +               nextRun = ThreadPoolManager.getInstance().scheduleGeneral(this, nextMsg * 1000);
  1897. +           }
  1898. +       }
  1899. +      
  1900. +       private void announce(long time)
  1901. +       {
  1902. +           if (time >= 3600 && time % 3600 == 0)
  1903. +           {
  1904. +               if (GvEEvent.isParticipating())
  1905. +               {
  1906. +                   Announcements.getInstance().announceToAll("GvE Event: " + (time / 60 / 60) + " hour(s) until registration is closed!");
  1907. +               }
  1908. +               else if (GvEEvent.isStarted())
  1909. +               {
  1910. +                   GvEEvent.sysMsgToAllParticipants("GvE Event: " + (time / 60 / 60) + " hour(s) until event is finished!");
  1911. +               }
  1912. +           }
  1913. +           else if (time >= 60)
  1914. +           {
  1915. +               if (GvEEvent.isParticipating())
  1916. +               {
  1917. +                   Announcements.getInstance().announceToAll("GvE Event: " + (time / 60) + " minute(s) until registration is closed!");
  1918. +               }
  1919. +               else if (GvEEvent.isStarted())
  1920. +               {
  1921. +                   GvEEvent.sysMsgToAllParticipants("GvE Event: " + (time / 60) + " minute(s) until the event is finished!");
  1922. +               }
  1923. +           }
  1924. +           else
  1925. +           {
  1926. +               if (GvEEvent.isParticipating())
  1927. +               {
  1928. +                   Announcements.getInstance().announceToAll("GvE Event: " + time + " second(s) until registration is closed!");
  1929. +               }
  1930. +               else if (GvEEvent.isStarted())
  1931. +               {
  1932. +                   GvEEvent.sysMsgToAllParticipants("GvE Event: " + time + " second(s) until the event is finished!");
  1933. +               }
  1934. +           }
  1935. +       }
  1936. +   }
  1937. +  
  1938. +   @SuppressWarnings("synthetic-access")
  1939. +   private static class SingletonHolder
  1940. +   {
  1941. +       protected static final GvEManager _instance = new GvEManager();
  1942. +   }
  1943. +}
  1944. \ No newline at end of file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement