Advertisement
Guest User

Random Zone

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