CostyKiller

Flag of Protection Ai and core mods

Oct 9th, 2020
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 15.14 KB | None | 0 0
  1. Index: dist/game/data/scripts/ai/others/CastleFlagOfProtection/CastleFlagOfProtection-01.html
  2. ===================================================================
  3. --- dist/game/data/scripts/ai/others/CastleFlagOfProtection/CastleFlagOfProtection-01.html  (nonexistent)
  4. +++ dist/game/data/scripts/ai/others/CastleFlagOfProtection/CastleFlagOfProtection-01.html  (working copy)
  5. @@ -0,0 +1,3 @@
  6. +<html><body>Flag of Protection:<br>
  7. +(Only characters who are performing For Victory sub quest, from the Exalted, One Who Shatters the Limit quest may take the reward.)<br><br>
  8. +</body></html>
  9. \ No newline at end of file
  10. Index: dist/game/data/scripts/ai/others/CastleFlagOfProtection/CastleFlagOfProtection.html
  11. ===================================================================
  12. --- dist/game/data/scripts/ai/others/CastleFlagOfProtection/CastleFlagOfProtection.html (nonexistent)
  13. +++ dist/game/data/scripts/ai/others/CastleFlagOfProtection/CastleFlagOfProtection.html (working copy)
  14. @@ -0,0 +1,6 @@
  15. +<html><body>Flag of Protection:<br>
  16. +(It's a Flag of Protection with the symbol of the castle. It's the same as what Merlot mentioned)<br><br>
  17. +<center>
  18. +<Button ALIGN=LEFT ICON="NORMAL" action="bypass -h Quest Q10825_ForVictory mark">"I'll take this."</Button>
  19. +</center>
  20. +</body></html>
  21. \ No newline at end of file
  22. Index: dist/game/data/scripts/ai/others/CastleFlagOfProtection/CastleFlagOfProtection.java
  23. ===================================================================
  24. --- dist/game/data/scripts/ai/others/CastleFlagOfProtection/CastleFlagOfProtection.java (nonexistent)
  25. +++ dist/game/data/scripts/ai/others/CastleFlagOfProtection/CastleFlagOfProtection.java (working copy)
  26. @@ -0,0 +1,67 @@
  27. +/*
  28. + * This file is part of the L2J Mobius project.
  29. + *
  30. + * This program is free software: you can redistribute it and/or modify
  31. + * it under the terms of the GNU General Public License as published by
  32. + * the Free Software Foundation, either version 3 of the License, or
  33. + * (at your option) any later version.
  34. + *
  35. + * This program is distributed in the hope that it will be useful,
  36. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  37. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  38. + * General Public License for more details.
  39. + *
  40. + * You should have received a copy of the GNU General Public License
  41. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  42. + */
  43. +package ai.others.CastleFlagOfProtection;
  44. +
  45. +import org.l2jmobius.gameserver.model.actor.Npc;
  46. +import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
  47. +import org.l2jmobius.gameserver.model.quest.QuestState;
  48. +
  49. +import ai.AbstractNpcAI;
  50. +
  51. +/**
  52. + * Castle Flag of Protection AI.
  53. + * @author CostyKiller
  54. + */
  55. +public class CastleFlagOfProtection extends AbstractNpcAI
  56. +{
  57. +   // Flag of Protection NPCs
  58. +   private static final int FLAG_GLUDIO = 36741; // 1 Gludio Castle
  59. +   private static final int FLAG_DION = 36742; // 2 Dion Castle
  60. +   private static final int FLAG_GIRAN = 36743; // 3 Giran Castle
  61. +   private static final int FLAG_OREN = 36744; // 4 Oren Castle
  62. +   private static final int FLAG_ADEN = 36745; // 5 Aden Castle
  63. +   private static final int FLAG_INNADRIL = 36746; // 6 Innadril Castle
  64. +   private static final int FLAG_GODDARD = 36747; // 7 Goddard Castle
  65. +   private static final int FLAG_RUNE = 36748; // 8 Rune Castle
  66. +   private static final int FLAG_SCHUTTGART = 36749; // 9 Schuttgart Castle
  67. +  
  68. +   private CastleFlagOfProtection()
  69. +   {
  70. +       addFirstTalkId(FLAG_GLUDIO, FLAG_DION, FLAG_GIRAN, FLAG_OREN, FLAG_ADEN, FLAG_INNADRIL, FLAG_GODDARD, FLAG_RUNE, FLAG_SCHUTTGART);
  71. +   }
  72. +  
  73. +   @Override
  74. +   public String onFirstTalk(Npc npc, PlayerInstance player)
  75. +   {
  76. +       String htmltext;
  77. +       final QuestState qs = player.getQuestState("Q10825_ForVictory");
  78. +       if (((qs != null) && qs.isCond(1)))
  79. +       {
  80. +           htmltext = "CastleFlagOfProtection.html";
  81. +       }
  82. +       else
  83. +       {
  84. +           htmltext = "CastleFlagOfProtection-01.html";
  85. +       }
  86. +       return htmltext;
  87. +   }
  88. +  
  89. +   public static void main(String[] args)
  90. +   {
  91. +       new CastleFlagOfProtection();
  92. +   }
  93. +}
  94. \ No newline at end of file
  95. Index: java/org/l2jmobius/gameserver/instancemanager/SiegeFlagOfProtectionManager.java
  96. ===================================================================
  97. --- java/org/l2jmobius/gameserver/instancemanager/SiegeFlagOfProtectionManager.java (nonexistent)
  98. +++ java/org/l2jmobius/gameserver/instancemanager/SiegeFlagOfProtectionManager.java (working copy)
  99. @@ -0,0 +1,311 @@
  100. +/*
  101. + * This file is part of the L2J Mobius project.
  102. + *
  103. + * This program is free software: you can redistribute it and/or modify
  104. + * it under the terms of the GNU General Public License as published by
  105. + * the Free Software Foundation, either version 3 of the License, or
  106. + * (at your option) any later version.
  107. + *
  108. + * This program is distributed in the hope that it will be useful,
  109. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  110. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  111. + * General Public License for more details.
  112. + *
  113. + * You should have received a copy of the GNU General Public License
  114. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  115. + */
  116. +package org.l2jmobius.gameserver.instancemanager;
  117. +
  118. +import java.util.Map;
  119. +import java.util.Set;
  120. +import java.util.concurrent.ConcurrentHashMap;
  121. +import java.util.logging.Level;
  122. +import java.util.logging.Logger;
  123. +
  124. +import org.l2jmobius.gameserver.model.Location;
  125. +import org.l2jmobius.gameserver.model.Spawn;
  126. +import org.l2jmobius.gameserver.model.entity.Castle;
  127. +import org.l2jmobius.gameserver.model.events.AbstractScript;
  128. +
  129. +/**
  130. + * Siege Flag Of Protection Manager.
  131. + * @author CostyKiller
  132. + */
  133. +public class SiegeFlagOfProtectionManager
  134. +{
  135. +   private static final Logger LOGGER = Logger.getLogger(SiegeFlagOfProtectionManager.class.getName());
  136. +   private static final Map<Integer, Set<Spawn>> _flagSpawn = new ConcurrentHashMap<>();
  137. +  
  138. +   // Flag of Protection NPCs
  139. +   private static final int FLAG_GLUDIO = 36741; // 1 Gludio Castle
  140. +   private static final int FLAG_DION = 36742; // 2 Dion Castle
  141. +   private static final int FLAG_GIRAN = 36743; // 3 Giran Castle
  142. +   private static final int FLAG_OREN = 36744; // 4 Oren Castle
  143. +   private static final int FLAG_ADEN = 36745; // 5 Aden Castle
  144. +   private static final int FLAG_INNADRIL = 36746; // 6 Innadril Castle
  145. +   private static final int FLAG_GODDARD = 36747; // 7 Goddard Castle
  146. +   private static final int FLAG_RUNE = 36748; // 8 Rune Castle
  147. +   private static final int FLAG_SCHUTTGART = 36749; // 9 Schuttgart Castle
  148. +  
  149. +   // Flag Spawn Positions
  150. +   private static final Location[] FLAG_LOC_GLUDIO =
  151. +   {
  152. +       new Location(-18488, 111080, -2575), // Front
  153. +       new Location(-17736, 107272, -2567), // Back
  154. +       new Location(-18568, 112328, -2509) // Tower
  155. +   };
  156. +   private static final Location[] FLAG_LOC_DION =
  157. +   {
  158. +       new Location(22440, 158632, -2776), // Front
  159. +       new Location(21752, 162488, -2764), // Back
  160. +       new Location(22536, 157432, -2703) // Tower
  161. +   };
  162. +   private static final Location[] FLAG_LOC_GIRAN =
  163. +   {
  164. +       new Location(114840, 144712, -2641), // Front
  165. +       new Location(118664, 145432, -2646), // Back
  166. +       new Location(113608, 144632, -2576) // Tower
  167. +   };
  168. +   private static final Location[] FLAG_LOC_OREN =
  169. +   {
  170. +       new Location(80904, 36824, -2368), // Front
  171. +       new Location(84728, 37512, -2364), // Back
  172. +       new Location(79672, 36728, -2303) // Tower
  173. +   };
  174. +   private static final Location[] FLAG_LOC_ADEN =
  175. +   {
  176. +       new Location(147464, 7240, -472), // Front
  177. +       new Location(149608, 8296, -472), // Right
  178. +       new Location(145304, 8296, -472), // Left
  179. +       new Location(148696, 1832, -472), // Right back
  180. +       new Location(146136, 1848, -472) // Left back
  181. +   };
  182. +   private static final Location[] FLAG_LOC_INNADRIL =
  183. +   {
  184. +       new Location(116392, 247464, -864), // Front
  185. +       new Location(115704, 251272, -862), // Back
  186. +       new Location(116488, 246200, -799) // Tower
  187. +   };
  188. +   private static final Location[] FLAG_LOC_GODDARD =
  189. +   {
  190. +       new Location(147320, -46072, -2087), // Front
  191. +       new Location(148056, -46600, -2386), // Right
  192. +       new Location(146888, -46568, -2386) // Left
  193. +   };
  194. +   private static final Location[] FLAG_LOC_RUNE =
  195. +   {
  196. +       new Location(15960, -48840, -1072), // Front
  197. +       new Location(16616, -50328, -643), // Right
  198. +       new Location(16616, -47976, -642), // Left
  199. +       new Location(13768, -52120, -961), // Right back
  200. +       new Location(13720, -46184, -954) // Left back
  201. +   };
  202. +   private static final Location[] FLAG_LOC_SCHUTTGART =
  203. +   {
  204. +       new Location(77704, -150104, -355), // Front
  205. +       new Location(78168, -150680, -654), // Right
  206. +       new Location(76968, -150632, -654) // Left
  207. +   };
  208. +  
  209. +   protected SiegeFlagOfProtectionManager()
  210. +   {
  211. +   }
  212. +  
  213. +   /**
  214. +    * Loads all flags of protection for all castles.
  215. +    * @param castle
  216. +    */
  217. +   public void loadFlags(Castle castle)
  218. +   {
  219. +       Spawn spawn = null;
  220. +       switch (castle.getResidenceId())
  221. +       {
  222. +           case 1:
  223. +           {
  224. +               try
  225. +               {
  226. +                   spawn = new Spawn(FLAG_GLUDIO);
  227. +                   spawn.setXYZ(AbstractScript.getRandomEntry(FLAG_LOC_GLUDIO));
  228. +                   getSpawnedFlags(castle.getResidenceId()).add(spawn);
  229. +               }
  230. +               catch (ClassNotFoundException | NoSuchMethodException | ClassCastException e)
  231. +               {
  232. +                   e.printStackTrace();
  233. +               }
  234. +               break;
  235. +           }
  236. +           case 2:
  237. +           {
  238. +               try
  239. +               {
  240. +                   spawn = new Spawn(FLAG_DION);
  241. +                   spawn.setXYZ(AbstractScript.getRandomEntry(FLAG_LOC_DION));
  242. +                   getSpawnedFlags(castle.getResidenceId()).add(spawn);
  243. +               }
  244. +               catch (ClassNotFoundException | NoSuchMethodException | ClassCastException e)
  245. +               {
  246. +                   e.printStackTrace();
  247. +               }
  248. +               break;
  249. +           }
  250. +           case 3:
  251. +           {
  252. +               try
  253. +               {
  254. +                   spawn = new Spawn(FLAG_GIRAN);
  255. +                   spawn.setXYZ(AbstractScript.getRandomEntry(FLAG_LOC_GIRAN));
  256. +                   getSpawnedFlags(castle.getResidenceId()).add(spawn);
  257. +               }
  258. +               catch (ClassNotFoundException | NoSuchMethodException | ClassCastException e)
  259. +               {
  260. +                   e.printStackTrace();
  261. +               }
  262. +               break;
  263. +           }
  264. +           case 4:
  265. +           {
  266. +               try
  267. +               {
  268. +                   spawn = new Spawn(FLAG_OREN);
  269. +                   spawn.setXYZ(AbstractScript.getRandomEntry(FLAG_LOC_OREN));
  270. +                   getSpawnedFlags(castle.getResidenceId()).add(spawn);
  271. +               }
  272. +               catch (ClassNotFoundException | NoSuchMethodException | ClassCastException e)
  273. +               {
  274. +                   e.printStackTrace();
  275. +               }
  276. +               break;
  277. +           }
  278. +           case 5:
  279. +           {
  280. +               try
  281. +               {
  282. +                   spawn = new Spawn(FLAG_ADEN);
  283. +                   spawn.setXYZ(AbstractScript.getRandomEntry(FLAG_LOC_ADEN));
  284. +                   getSpawnedFlags(castle.getResidenceId()).add(spawn);
  285. +               }
  286. +               catch (ClassNotFoundException | NoSuchMethodException | ClassCastException e)
  287. +               {
  288. +                   e.printStackTrace();
  289. +               }
  290. +               break;
  291. +           }
  292. +           case 6:
  293. +           {
  294. +               try
  295. +               {
  296. +                   spawn = new Spawn(FLAG_INNADRIL);
  297. +                   spawn.setXYZ(AbstractScript.getRandomEntry(FLAG_LOC_INNADRIL));
  298. +                   getSpawnedFlags(castle.getResidenceId()).add(spawn);
  299. +               }
  300. +               catch (ClassNotFoundException | NoSuchMethodException | ClassCastException e)
  301. +               {
  302. +                   e.printStackTrace();
  303. +               }
  304. +               break;
  305. +           }
  306. +           case 7:
  307. +           {
  308. +               try
  309. +               {
  310. +                   spawn = new Spawn(FLAG_GODDARD);
  311. +                   spawn.setXYZ(AbstractScript.getRandomEntry(FLAG_LOC_GODDARD));
  312. +                   getSpawnedFlags(castle.getResidenceId()).add(spawn);
  313. +               }
  314. +               catch (ClassNotFoundException | NoSuchMethodException | ClassCastException e)
  315. +               {
  316. +                   e.printStackTrace();
  317. +               }
  318. +               break;
  319. +           }
  320. +           case 8:
  321. +           {
  322. +               try
  323. +               {
  324. +                   spawn = new Spawn(FLAG_RUNE);
  325. +                   spawn.setXYZ(AbstractScript.getRandomEntry(FLAG_LOC_RUNE));
  326. +                   getSpawnedFlags(castle.getResidenceId()).add(spawn);
  327. +               }
  328. +               catch (ClassNotFoundException | NoSuchMethodException | ClassCastException e)
  329. +               {
  330. +                   e.printStackTrace();
  331. +               }
  332. +               break;
  333. +           }
  334. +           case 9:
  335. +           {
  336. +               try
  337. +               {
  338. +                   spawn = new Spawn(FLAG_SCHUTTGART);
  339. +                   spawn.setXYZ(AbstractScript.getRandomEntry(FLAG_LOC_SCHUTTGART));
  340. +                   getSpawnedFlags(castle.getResidenceId()).add(spawn);
  341. +               }
  342. +               catch (ClassNotFoundException | NoSuchMethodException | ClassCastException e)
  343. +               {
  344. +                   e.printStackTrace();
  345. +               }
  346. +               break;
  347. +           }
  348. +       }
  349. +   }
  350. +  
  351. +   /**
  352. +    * Spawn flag of protection for castle.
  353. +    * @param castle the castle instance
  354. +    */
  355. +   public void spawnFlag(Castle castle)
  356. +   {
  357. +       try
  358. +       {
  359. +           loadFlags(castle);
  360. +          
  361. +           for (Spawn spawn : getSpawnedFlags(castle.getResidenceId()))
  362. +           {
  363. +               if (spawn != null)
  364. +               {
  365. +                   spawn.doSpawn();
  366. +               }
  367. +           }
  368. +       }
  369. +       catch (Exception e)
  370. +       {
  371. +           LOGGER.log(Level.SEVERE, "Error spawning flag of protection for castle " + castle.getName(), e);
  372. +       }
  373. +   }
  374. +  
  375. +   /**
  376. +    * Unspawn flag of protection for castle.
  377. +    * @param castle the castle instance
  378. +    */
  379. +   public void unspawnFlag(Castle castle)
  380. +   {
  381. +       for (Spawn spawn : getSpawnedFlags(castle.getResidenceId()))
  382. +       {
  383. +           if ((spawn != null) && (spawn.getLastSpawn() != null))
  384. +           {
  385. +               spawn.stopRespawn();
  386. +               spawn.getLastSpawn().doDie(spawn.getLastSpawn());
  387. +           }
  388. +       }
  389. +       getSpawnedFlags(castle.getResidenceId()).clear();
  390. +   }
  391. +  
  392. +   public Set<Spawn> getSpawnedFlags(int castleId)
  393. +   {
  394. +       return _flagSpawn.computeIfAbsent(castleId, key -> ConcurrentHashMap.newKeySet());
  395. +   }
  396. +  
  397. +   /**
  398. +    * Gets the single instance of {@code SiegeFlagOfProtectionManager}.
  399. +    * @return single instance of {@code SiegeFlagOfProtectionManager}
  400. +    */
  401. +   public static SiegeFlagOfProtectionManager getInstance()
  402. +   {
  403. +       return SingletonHolder.INSTANCE;
  404. +   }
  405. +  
  406. +   private static class SingletonHolder
  407. +   {
  408. +       protected static final SiegeFlagOfProtectionManager INSTANCE = new SiegeFlagOfProtectionManager();
  409. +   }
  410. +}
  411. Index: java/org/l2jmobius/gameserver/model/entity/Siege.java
  412. ===================================================================
  413. --- java/org/l2jmobius/gameserver/model/entity/Siege.java   (revision 7680)
  414. +++ java/org/l2jmobius/gameserver/model/entity/Siege.java   (working copy)
  415. @@ -40,6 +40,7 @@
  416.  import org.l2jmobius.gameserver.enums.SiegeTeleportWhoType;
  417.  import org.l2jmobius.gameserver.enums.TeleportWhereType;
  418.  import org.l2jmobius.gameserver.instancemanager.CastleManager;
  419. +import org.l2jmobius.gameserver.instancemanager.SiegeFlagOfProtectionManager;
  420.  import org.l2jmobius.gameserver.instancemanager.SiegeGuardManager;
  421.  import org.l2jmobius.gameserver.instancemanager.SiegeManager;
  422.  import org.l2jmobius.gameserver.model.PlayerCondOverride;
  423. @@ -329,6 +330,7 @@
  424.             saveCastleSiege(); // Save castle specific data
  425.             clearSiegeClan(); // Clear siege clan from db
  426.             removeTowers(); // Remove all towers from this castle
  427. +           SiegeFlagOfProtectionManager.getInstance().unspawnFlag(getCastle()); // Remove spawned flag of protection
  428.             SiegeGuardManager.getInstance().unspawnSiegeGuard(getCastle()); // Remove all spawned siege guard from this castle
  429.             if (_castle.getOwnerId() > 0)
  430.             {
  431. @@ -503,6 +505,7 @@
  432.             spawnControlTower(); // Spawn control tower
  433.             spawnFlameTower(); // Spawn control tower
  434.             _castle.spawnDoor(); // Spawn door
  435. +           SiegeFlagOfProtectionManager.getInstance().spawnFlag(getCastle()); // Spawn flag of protection
  436.             spawnSiegeGuard(); // Spawn siege guard
  437.             SiegeGuardManager.getInstance().deleteTickets(getCastle().getResidenceId()); // remove the tickets from the ground
  438.             _castle.getZone().setSiegeInstance(this);
Add Comment
Please, Sign In to add comment