Advertisement
StinkyMadness

Automatic Random Zone Changer

Dec 26th, 2018
929
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 11.36 KB | None | 0 0
  1. ### Eclipse Workspace Patch 1.0
  2. #P aCis_datapack
  3. Index: data/xml/zones/RandomZone.xml
  4. ===================================================================
  5. --- data/xml/zones/RandomZone.xml   (revision 0)
  6. +++ data/xml/zones/RandomZone.xml   (revision 0)
  7. @@ -0,0 +1,19 @@
  8. +<?xml version="1.0" encoding="UTF-8"?>
  9. +<list>
  10. +   <zone shape="Cuboid" minZ="-3752" maxZ="-352"><!-- gludin_pvp -->
  11. +       <stat name="id" val="1" />
  12. +       <stat name="name" val="Gludin Arena" />
  13. +       <stat name="time" val="30" /><!-- time in seconds -->
  14. +       <stat name="locs" val="-88339,141802,-3649;-87894,142231,-3649" />
  15. +       <node X="-88411" Y="141732" />
  16. +       <node X="-87429" Y="142708" />
  17. +   </zone>
  18. +   <zone shape="Cuboid" minZ="-3850" maxZ="-350"><!-- giran_pvp_battle -->
  19. +       <stat name="id" val="2" />
  20. +       <stat name="name" val="Giran Arena" />
  21. +       <stat name="time" val="30" /><!-- time in seconds -->
  22. +       <stat name="locs" val="73306,142440,-3775;72646,142403,-3775" />
  23. +       <node X="72493" Y="142263" />
  24. +       <node X="73493" Y="143261" />
  25. +   </zone>
  26. +</list>
  27. \ No newline at end of file
  28. #P aCis_gameserver
  29. Index: java/net/sf/l2j/gameserver/GameServer.java
  30. ===================================================================
  31. --- java/net/sf/l2j/gameserver/GameServer.java  (revision 31)
  32. +++ java/net/sf/l2j/gameserver/GameServer.java  (working copy)
  33. @@ -100,6 +100,7 @@
  34.  import net.sf.l2j.gameserver.taskmanager.MovementTaskManager;
  35.  import net.sf.l2j.gameserver.taskmanager.PvpFlagTaskManager;
  36.  import net.sf.l2j.gameserver.taskmanager.RandomAnimationTaskManager;
  37. +import net.sf.l2j.gameserver.taskmanager.RandomZoneTaskManager;
  38.  import net.sf.l2j.gameserver.taskmanager.ShadowItemTaskManager;
  39.  import net.sf.l2j.gameserver.taskmanager.WaterTaskManager;
  40.  import net.sf.l2j.gameserver.xmlfactory.XMLDocumentFactory;
  41. @@ -221,6 +222,7 @@
  42.         RandomAnimationTaskManager.getInstance();
  43.         ShadowItemTaskManager.getInstance();
  44.         WaterTaskManager.getInstance();
  45. +       RandomZoneTaskManager.getInstance();
  46.        
  47.         StringUtil.printSection("Seven Signs");
  48.         SevenSigns.getInstance().spawnSevenSignsNPC();
  49. Index: java/net/sf/l2j/gameserver/model/actor/instance/Gatekeeper.java
  50. ===================================================================
  51. --- java/net/sf/l2j/gameserver/model/actor/instance/Gatekeeper.java (revision 30)
  52. +++ java/net/sf/l2j/gameserver/model/actor/instance/Gatekeeper.java (working copy)
  53. @@ -12,6 +12,7 @@
  54.  import net.sf.l2j.gameserver.network.SystemMessageId;
  55.  import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
  56.  import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
  57. +import net.sf.l2j.gameserver.taskmanager.RandomZoneTaskManager;
  58.  
  59.  /**
  60.   * An instance type extending {@link Folk}, used for teleporters.<br>
  61. @@ -135,6 +136,8 @@
  62.             }
  63.             showChatWindow(player, val);
  64.         }
  65. +       else if (command.startsWith("pvp"))
  66. +           player.teleToLocation(RandomZoneTaskManager.getInstance().getCurrentZone().getLoc(), 25);
  67.         else
  68.             super.onBypassFeedback(player, command);
  69.     }
  70. Index: java/net/sf/l2j/gameserver/model/zone/ZoneId.java
  71. ===================================================================
  72. --- java/net/sf/l2j/gameserver/model/zone/ZoneId.java   (revision 30)
  73. +++ java/net/sf/l2j/gameserver/model/zone/ZoneId.java   (working copy)
  74. @@ -21,7 +21,8 @@
  75.     CAST_ON_ARTIFACT(16),
  76.     NO_RESTART(17),
  77.     SCRIPT(18),
  78. -   BOSS(19);
  79. +   BOSS(19),
  80. +   RANDOM(20);
  81.    
  82.     private final int _id;
  83.    
  84. Index: java/net/sf/l2j/gameserver/model/zone/type/RandomZone.java
  85. ===================================================================
  86. --- java/net/sf/l2j/gameserver/model/zone/type/RandomZone.java  (revision 0)
  87. +++ java/net/sf/l2j/gameserver/model/zone/type/RandomZone.java  (revision 0)
  88. @@ -0,0 +1,78 @@
  89. +package net.sf.l2j.gameserver.model.zone.type;
  90. +
  91. +import java.util.ArrayList;
  92. +import java.util.List;
  93. +
  94. +import net.sf.l2j.commons.random.Rnd;
  95. +
  96. +import net.sf.l2j.gameserver.model.actor.Creature;
  97. +import net.sf.l2j.gameserver.model.location.Location;
  98. +import net.sf.l2j.gameserver.model.zone.SpawnZoneType;
  99. +import net.sf.l2j.gameserver.model.zone.ZoneId;
  100. +
  101. +/**
  102. + * @author StinkyMadness
  103. + */
  104. +public class RandomZone extends SpawnZoneType
  105. +{
  106. +   private int _id;
  107. +   private String _name;
  108. +   private int _time;
  109. +   private List<Location> _locations = new ArrayList<>();
  110. +  
  111. +   public RandomZone(int id)
  112. +   {
  113. +       super(id);
  114. +   }
  115. +  
  116. +   @Override
  117. +   public void setParameter(String name, String value)
  118. +   {
  119. +       if (name.equals("id"))
  120. +           _id = Integer.parseInt(value);
  121. +       else if (name.equals("name"))
  122. +           _name = value;
  123. +       else if (name.equals("time"))
  124. +           _time = Integer.parseInt(value);
  125. +       else if (name.equals("locs"))
  126. +       {
  127. +           for (String locs : value.split(";"))
  128. +               _locations.add(new Location(Integer.valueOf(locs.split(",")[0]), Integer.valueOf(locs.split(",")[1]), Integer.valueOf(locs.split(",")[2])));
  129. +       }
  130. +       else
  131. +           super.setParameter(name, value);
  132. +   }
  133. +  
  134. +   @Override
  135. +   protected void onEnter(Creature character)
  136. +   {
  137. +       character.setInsideZone(ZoneId.RANDOM, true);
  138. +   }
  139. +  
  140. +   @Override
  141. +   protected void onExit(Creature character)
  142. +   {
  143. +       character.setInsideZone(ZoneId.RANDOM, false);
  144. +   }
  145. +  
  146. +   @Override
  147. +   public int getId()
  148. +   {
  149. +       return _id;
  150. +   }
  151. +  
  152. +   public String getName()
  153. +   {
  154. +       return _name;
  155. +   }
  156. +  
  157. +   public int getTime()
  158. +   {
  159. +       return _time;
  160. +   }
  161. +  
  162. +   public Location getLoc()
  163. +   {
  164. +       return _locations.get(Rnd.get(0, _locations.size() - 1));
  165. +   }
  166. +}
  167. \ No newline at end of file
  168. Index: java/net/sf/l2j/gameserver/network/clientpackets/EnterWorld.java
  169. ===================================================================
  170. --- java/net/sf/l2j/gameserver/network/clientpackets/EnterWorld.java    (revision 30)
  171. +++ java/net/sf/l2j/gameserver/network/clientpackets/EnterWorld.java    (working copy)
  172. @@ -57,6 +57,7 @@
  173.  import net.sf.l2j.gameserver.scripting.Quest;
  174.  import net.sf.l2j.gameserver.scripting.QuestState;
  175.  import net.sf.l2j.gameserver.taskmanager.GameTimeTaskManager;
  176. +import net.sf.l2j.gameserver.taskmanager.RandomZoneTaskManager;
  177.  
  178.  public class EnterWorld extends L2GameClientPacket
  179.  {
  180. @@ -322,6 +323,9 @@
  181.         if (!player.isGM() && (!player.isInSiege() || player.getSiegeState() < 2) && player.isInsideZone(ZoneId.SIEGE))
  182.             player.teleToLocation(TeleportType.TOWN);
  183.        
  184. +       if (!player.isGM() && player.isInsideZone(ZoneId.RANDOM))
  185. +           player.teleToLocation(RandomZoneTaskManager.getInstance().getCurrentZone().getLoc(), 25);
  186. +      
  187.         player.sendPacket(ActionFailed.STATIC_PACKET);
  188.     }
  189.    
  190. Index: java/net/sf/l2j/gameserver/network/clientpackets/RequestRestartPoint.java
  191. ===================================================================
  192. --- java/net/sf/l2j/gameserver/network/clientpackets/RequestRestartPoint.java   (revision 30)
  193. +++ java/net/sf/l2j/gameserver/network/clientpackets/RequestRestartPoint.java   (working copy)
  194. @@ -14,6 +14,8 @@
  195.  import net.sf.l2j.gameserver.model.entity.Siege.SiegeSide;
  196.  import net.sf.l2j.gameserver.model.location.Location;
  197.  import net.sf.l2j.gameserver.model.pledge.Clan;
  198. +import net.sf.l2j.gameserver.model.zone.ZoneId;
  199. +import net.sf.l2j.gameserver.taskmanager.RandomZoneTaskManager;
  200.  
  201.  public final class RequestRestartPoint extends L2GameClientPacket
  202.  {
  203. @@ -117,6 +119,12 @@
  204.         // Fixed.
  205.         else if (_requestType == 4)
  206.         {
  207. +           if (!player.isGM() && player.isInsideZone(ZoneId.RANDOM))
  208. +           {
  209. +               loc = RandomZoneTaskManager.getInstance().getCurrentZone().getLoc();
  210. +               return;
  211. +           }
  212. +          
  213.             if (!player.isGM() && !player.isFestivalParticipant())
  214.                 return;
  215.            
  216. Index: java/net/sf/l2j/gameserver/network/serverpackets/Die.java
  217. ===================================================================
  218. --- java/net/sf/l2j/gameserver/network/serverpackets/Die.java   (revision 30)
  219. +++ java/net/sf/l2j/gameserver/network/serverpackets/Die.java   (working copy)
  220. @@ -7,6 +7,7 @@
  221.  import net.sf.l2j.gameserver.model.entity.Siege;
  222.  import net.sf.l2j.gameserver.model.entity.Siege.SiegeSide;
  223.  import net.sf.l2j.gameserver.model.pledge.Clan;
  224. +import net.sf.l2j.gameserver.model.zone.ZoneId;
  225.  
  226.  public class Die extends L2GameServerPacket
  227.  {
  228. @@ -27,7 +28,7 @@
  229.         if (cha instanceof Player)
  230.         {
  231.             Player player = (Player) cha;
  232. -           _allowFixedRes = player.getAccessLevel().allowFixedRes();
  233. +           _allowFixedRes = player.getAccessLevel().allowFixedRes() || player.isInsideZone(ZoneId.RANDOM);
  234.             _clan = player.getClan();
  235.            
  236.         }
  237. Index: java/net/sf/l2j/gameserver/taskmanager/RandomZoneTaskManager.java
  238. ===================================================================
  239. --- java/net/sf/l2j/gameserver/taskmanager/RandomZoneTaskManager.java   (revision 0)
  240. +++ java/net/sf/l2j/gameserver/taskmanager/RandomZoneTaskManager.java   (revision 0)
  241. @@ -0,0 +1,105 @@
  242. +package net.sf.l2j.gameserver.taskmanager;
  243. +
  244. +import net.sf.l2j.commons.concurrent.ThreadPool;
  245. +import net.sf.l2j.commons.random.Rnd;
  246. +
  247. +import net.sf.l2j.gameserver.data.manager.ZoneManager;
  248. +import net.sf.l2j.gameserver.model.World;
  249. +import net.sf.l2j.gameserver.model.actor.instance.Player;
  250. +import net.sf.l2j.gameserver.model.zone.ZoneId;
  251. +import net.sf.l2j.gameserver.model.zone.type.RandomZone;
  252. +import net.sf.l2j.gameserver.util.Broadcast;
  253. +
  254. +/**
  255. + * @author StinkyMadness
  256. + */
  257. +public final class RandomZoneTaskManager implements Runnable
  258. +{
  259. +   private int _zoneId;
  260. +   private int _timer;
  261. +  
  262. +   public RandomZoneTaskManager()
  263. +   {
  264. +       if (getTotalZones() > 1)
  265. +           ThreadPool.scheduleAtFixedRate(this, 1000, 1000);
  266. +   }
  267. +  
  268. +   @Override
  269. +   public void run()
  270. +   {
  271. +       if (_timer > 0)
  272. +           _timer--;
  273. +       else
  274. +           selectNextZone();
  275. +      
  276. +       switch (_timer)
  277. +       {
  278. +           case 0:
  279. +               Broadcast.announceToOnlinePlayers("PvP zone will has been changed.", true);
  280. +               Broadcast.announceToOnlinePlayers("Current zone : " + getCurrentZone().getName(), true);
  281. +               for (Player player : World.getInstance().getPlayers())
  282. +                   if (player != null && player.isOnline() && player.isInsideZone(ZoneId.RANDOM))
  283. +                       player.teleToLocation(getCurrentZone().getLoc(), 50);
  284. +               break;
  285. +           case 5:
  286. +           case 15:
  287. +           case 30:
  288. +               Broadcast.announceToOnlinePlayers("PvP zone will change in " + _timer + " second(s).", true);
  289. +               break;
  290. +           case 60:
  291. +           case 300:
  292. +           case 600:
  293. +           case 900:
  294. +           case 1800:
  295. +               Broadcast.announceToOnlinePlayers("PvP zone will change in " + _timer / 60 + " minute(s).", true);
  296. +               break;
  297. +           case 3600:
  298. +           case 7200:
  299. +               Broadcast.announceToOnlinePlayers("PvP zone will change in " + (_timer / 60) / 60 + " hour(s).", true);
  300. +               break;
  301. +       }
  302. +   }
  303. +  
  304. +   public int getZoneId()
  305. +   {
  306. +       return _zoneId;
  307. +   }
  308. +  
  309. +   public void selectNextZone()
  310. +   {
  311. +       int nextZoneId = Rnd.get(1, getTotalZones());
  312. +       while (getZoneId() == nextZoneId)
  313. +           nextZoneId = Rnd.get(1, getTotalZones());
  314. +       _zoneId = nextZoneId;
  315. +      
  316. +       _timer = getCurrentZone().getTime() + 10;
  317. +   }
  318. +  
  319. +   public final RandomZone getCurrentZone()
  320. +   {
  321. +       return ZoneManager.getInstance().getAllZones(RandomZone.class).stream().filter(t -> t.getId() == getZoneId()).findFirst().orElse(null);
  322. +   }
  323. +  
  324. +   public static int getTotalZones()
  325. +   {
  326. +       int size = 0;
  327. +       for (RandomZone i : ZoneManager.getInstance().getAllZones(RandomZone.class))
  328. +       {
  329. +           if (i == null)
  330. +               continue;
  331. +          
  332. +           size++;
  333. +       }
  334. +       return size;
  335. +   }
  336. +  
  337. +   public static final RandomZoneTaskManager getInstance()
  338. +   {
  339. +       return SingletonHolder.INSTANCE;
  340. +   }
  341. +  
  342. +   private static class SingletonHolder
  343. +   {
  344. +       protected static final RandomZoneTaskManager INSTANCE = new RandomZoneTaskManager();
  345. +   }
  346. +}
  347. \ No newline at end of file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement