Advertisement
StinkyMadness

BossEvent aCis377

Dec 30th, 2018
1,904
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 6.33 KB | None | 0 0
  1. ### Eclipse Workspace Patch 1.0
  2. #P aCis_datapack
  3. Index: data/xml/BossEvent.xml
  4. ===================================================================
  5. --- data/xml/BossEvent.xml  (revision 0)
  6. +++ data/xml/BossEvent.xml  (revision 0)
  7. @@ -0,0 +1,15 @@
  8. +<?xml version="1.0" encoding="utf-8"?>
  9. +<list>
  10. +   <Boss id="20445">
  11. +       <announce onSpawn="Raidboss %s has been spawned on the world."/>
  12. +       <spawnLoc x="-71624" y="258648" z="-3096" />
  13. +       <despawn after="5"/> <!-- minutes -->
  14. +       <scheduleSpawnTime val="15:50;15:51;15:52" />
  15. +   </Boss>
  16. +   <Boss id="20172">
  17. +       <announce onSpawn="Raidboss %s has been spawned on the world."/>
  18. +       <spawnLoc x="-71480" y="258504" z="-3104" />
  19. +       <despawn after="5"/> <!-- minutes -->
  20. +       <scheduleSpawnTime val="15:53;15:54;15:55" />
  21. +   </Boss>
  22. +</list>
  23. \ No newline at end of file
  24. #P aCis_gameserver
  25. Index: java/net/sf/l2j/gameserver/data/xml/BossEventData.java
  26. ===================================================================
  27. --- java/net/sf/l2j/gameserver/data/xml/BossEventData.java  (revision 0)
  28. +++ java/net/sf/l2j/gameserver/data/xml/BossEventData.java  (revision 0)
  29. @@ -0,0 +1,65 @@
  30. +package net.sf.l2j.gameserver.data.xml;
  31. +
  32. +import java.nio.file.Path;
  33. +import java.util.ArrayList;
  34. +import java.util.List;
  35. +
  36. +import net.sf.l2j.commons.data.xml.IXmlReader;
  37. +
  38. +import net.sf.l2j.gameserver.model.event.BossEvent;
  39. +import net.sf.l2j.gameserver.templates.StatsSet;
  40. +
  41. +import org.w3c.dom.Document;
  42. +import org.w3c.dom.NamedNodeMap;
  43. +
  44. +/**
  45. + * @author StinkyMadness
  46. + */
  47. +public class BossEventData implements IXmlReader
  48. +{
  49. +   private static final List<StatsSet> data = new ArrayList<>();
  50. +  
  51. +   protected BossEventData()
  52. +   {
  53. +       load();
  54. +   }
  55. +  
  56. +   @Override
  57. +   public void load()
  58. +   {
  59. +       parseFile("./data/xml/BossEvent.xml");
  60. +   }
  61. +  
  62. +   @Override
  63. +   public void parseDocument(Document doc, Path path)
  64. +   {
  65. +      
  66. +       forEach(doc, "list", listNode -> forEach(listNode, "Boss", bossNode ->
  67. +       {
  68. +           final StatsSet set = parseAttributes(bossNode);
  69. +           forEach(bossNode, "announce", messageNode -> set.set("announceOnSpawn", parseString(messageNode.getAttributes(), "onSpawn")));
  70. +           forEach(bossNode, "spawnLoc", positionNode ->
  71. +           {
  72. +               final NamedNodeMap attrs = positionNode.getAttributes();
  73. +               set.set("posX", parseInteger(attrs, "x"));
  74. +               set.set("posY", parseInteger(attrs, "y"));
  75. +               set.set("posZ", parseInteger(attrs, "z"));
  76. +           });
  77. +           forEach(bossNode, "despawn", messageNode -> set.set("despawnTime", parseInteger(messageNode.getAttributes(), "after")));
  78. +           forEach(bossNode, "scheduleSpawnTime", spawnTimeNode -> set.set("spawnDateData", parseString(spawnTimeNode.getAttributes(), "val")));
  79. +           data.add(set);
  80. +       }));
  81. +      
  82. +       data.forEach(BossEvent::new);
  83. +   }
  84. +  
  85. +   public static BossEventData getInstance()
  86. +   {
  87. +       return SingletonHolder.INSTANCE;
  88. +   }
  89. +  
  90. +   private static class SingletonHolder
  91. +   {
  92. +       protected static final BossEventData INSTANCE = new BossEventData();
  93. +   }
  94. +}
  95. \ No newline at end of file
  96. Index: java/net/sf/l2j/gameserver/model/event/BossEvent.java
  97. ===================================================================
  98. --- java/net/sf/l2j/gameserver/model/event/BossEvent.java   (revision 0)
  99. +++ java/net/sf/l2j/gameserver/model/event/BossEvent.java   (revision 0)
  100. @@ -0,0 +1,95 @@
  101. +package net.sf.l2j.gameserver.model.event;
  102. +
  103. +import java.util.ArrayList;
  104. +import java.util.Arrays;
  105. +import java.util.Calendar;
  106. +import java.util.List;
  107. +import java.util.concurrent.ScheduledFuture;
  108. +import java.util.concurrent.TimeUnit;
  109. +import java.util.logging.Level;
  110. +import java.util.logging.Logger;
  111. +
  112. +import net.sf.l2j.commons.concurrent.ThreadPool;
  113. +
  114. +import net.sf.l2j.gameserver.data.SpawnTable;
  115. +import net.sf.l2j.gameserver.data.xml.NpcData;
  116. +import net.sf.l2j.gameserver.model.L2Spawn;
  117. +import net.sf.l2j.gameserver.model.actor.Npc;
  118. +import net.sf.l2j.gameserver.model.actor.template.NpcTemplate;
  119. +import net.sf.l2j.gameserver.model.location.Location;
  120. +import net.sf.l2j.gameserver.templates.StatsSet;
  121. +import net.sf.l2j.gameserver.util.Broadcast;
  122. +
  123. +/**
  124. + * @author StinkyMadness
  125. + */
  126. +public class BossEvent implements Runnable
  127. +{
  128. +   private final static Logger _log = Logger.getLogger(BossEvent.class.getName());
  129. +   private final int _bossId;
  130. +   private final String _onSpawnMessage;
  131. +   private final Location _spawnLoc;
  132. +   private final int _despawnTime;
  133. +   private final List<ScheduledFuture<?>> _scheduler = new ArrayList<>();
  134. +  
  135. +   public BossEvent(StatsSet set)
  136. +   {
  137. +       _bossId = set.getInteger("id");
  138. +       _onSpawnMessage = set.getString("announceOnSpawn", "");
  139. +       _spawnLoc = new Location(set.getInteger("posX"), set.getInteger("posY"), set.getInteger("posZ"));
  140. +       _despawnTime = set.getInteger("despawnTime", 0);
  141. +       executeScheduler(set.getString("spawnDateData"));
  142. +   }
  143. +  
  144. +   private void executeScheduler(String string)
  145. +   {
  146. +       Arrays.asList(string.split(";")).forEach(date ->
  147. +       {
  148. +           _scheduler.add(ThreadPool.scheduleAtFixedRate(this, parseDate(date), TimeUnit.DAYS.toMillis(1)));
  149. +       });
  150. +   }
  151. +  
  152. +   @Override
  153. +   public void run()
  154. +   {
  155. +       spawnRaidBoss();
  156. +   }
  157. +  
  158. +   private void spawnRaidBoss()
  159. +   {
  160. +       try
  161. +       {
  162. +           final NpcTemplate template = NpcData.getInstance().getTemplate(_bossId);
  163. +           final L2Spawn spawn = new L2Spawn(template);
  164. +           spawn.setLoc(_spawnLoc.getX(), _spawnLoc.getY(), _spawnLoc.getZ(), 0);
  165. +           spawn.setRespawnState(false);
  166. +           SpawnTable.getInstance().addNewSpawn(spawn, false);
  167. +           final Npc _raidBoss = spawn.doSpawn(false);
  168. +          
  169. +           if (!_onSpawnMessage.isEmpty())
  170. +               Broadcast.announceToOnlinePlayers(String.format(_onSpawnMessage, _raidBoss.getName()), true);
  171. +           if (_despawnTime != 0)
  172. +               _raidBoss.scheduleDespawn(TimeUnit.MINUTES.toMillis(_despawnTime));
  173. +       }
  174. +       catch (Exception e)
  175. +       {
  176. +           _log.log(Level.WARNING, "BossEvent: spawnRaidboss() exception: " + e.getMessage(), e);
  177. +           return;
  178. +       }
  179. +   }
  180. +  
  181. +   private static long parseDate(String str)
  182. +   {
  183. +       final String[] split = str.split(":");
  184. +       final Calendar calendar = Calendar.getInstance();
  185. +       calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(split[0]));
  186. +       calendar.set(Calendar.MINUTE, Integer.parseInt(split[1]));
  187. +       calendar.set(Calendar.SECOND, 0);
  188. +      
  189. +       if (calendar.getTimeInMillis() <= System.currentTimeMillis())
  190. +           calendar.add(Calendar.DATE, 1);
  191. +      
  192. +       return calendar.getTimeInMillis() - System.currentTimeMillis();
  193. +   }
  194. +}
  195. \ No newline at end of file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement