LordPanic

LuckyChests.java

Sep 21st, 2021 (edited)
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.15 KB | None | 0 0
  1. package net.sf.l2j.gameserver.custom.events.luckychest;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Iterator;
  5. import java.util.List;
  6. import java.util.concurrent.Future;
  7. import java.util.logging.Logger;
  8.  
  9. import net.sf.l2j.commons.random.Rnd;
  10.  
  11. import net.sf.l2j.gameserver.custom.events.Event;
  12. import net.sf.l2j.gameserver.data.NpcTable;
  13. import net.sf.l2j.gameserver.model.L2Spawn;
  14. import net.sf.l2j.gameserver.model.WorldObject;
  15. import net.sf.l2j.gameserver.model.actor.Npc;
  16. import net.sf.l2j.gameserver.model.actor.instance.Player;
  17. import net.sf.l2j.gameserver.model.actor.template.NpcTemplate;
  18. import net.sf.l2j.gameserver.model.location.SpawnLocation;
  19. import net.sf.l2j.gameserver.util.Broadcast;
  20.  
  21. /**
  22.  * @author LordPanic
  23.  *
  24.  */
  25. public class LuckyChests
  26. {
  27.     private static final Logger _log = Logger.getLogger(WorldObject.class.getName());
  28.     private final List<Npc> _boxList = new ArrayList<>();  
  29.    
  30.     private final static int boxID = 50062;
  31.        
  32.     //add the item to give for reward
  33.     private final static int rewardItemID = 0;
  34.     //add the quantity of reward items
  35.     private final static int itemQuantity = 0; 
  36.    
  37.     //lucky chests spawn locs currently 4, add as many as u want.
  38.     private static final SpawnLocation[] BOX_SPAWNS =
  39.     {
  40.         new SpawnLocation(82648 + Rnd.get(-30, 30), 148344 + Rnd.get(-30, 30), -3464, 0),
  41.         new SpawnLocation(82648 + Rnd.get(-30, 30), 148344 + Rnd.get(-30, 30), -3464, 0),
  42.         new SpawnLocation(82648 + Rnd.get(-30, 30), 148344 + Rnd.get(-30, 30), -3464, 0),
  43.         new SpawnLocation(82648 + Rnd.get(-30, 30), 148344 + Rnd.get(-30, 30), -3464, 0)
  44.     };
  45.    
  46.     public static LuckyChests getInstance()
  47.     {
  48.         return SingletonHolder._instance;
  49.     }
  50.  
  51.    
  52.     public void start()
  53.     {
  54.         startSpawns();     
  55.     }
  56.  
  57.     public void stop()
  58.     {
  59.         deleteSpawns();    
  60.     }
  61.  
  62.     public void soloRewards(Player player)
  63.     {
  64.         player.getInventory().addItem("Lucky Chest", rewardItemID, itemQuantity, player, player);      
  65.     }
  66.  
  67.     public void startSpawns()
  68.     {
  69.         for (SpawnLocation loc : BOX_SPAWNS)
  70.         {
  71.             try {                  
  72.                 final NpcTemplate template = NpcTable.getInstance().getTemplate(boxID);
  73.                 final L2Spawn spawn = new L2Spawn(template);
  74.                 spawn.setLoc(loc.getX(),loc.getY(),loc.getZ(), 0);
  75.                 final Npc mob = spawn.doSpawn(true);
  76.                 mob.setIsInvul(true);
  77.                 _boxList.add(mob);
  78.                 }catch(Exception e) {
  79.                     _log.info("[Lucky Chest]: Couldn't spawn Lucky Box's.");
  80.                 }          
  81.         }              
  82.         Broadcast.announceToOnlinePlayers("[Lucky Chest]: Spawned ["+_boxList.size()+"].", true);
  83.     }
  84.  
  85.  
  86.     public void deleteSpawns()
  87.     {
  88.         for (Npc chest : _boxList) {
  89.             chest.deleteMe();
  90.         }
  91.         _boxList.clear();
  92.     }
  93.    
  94.     public void removeluckyBox(int boxid) {
  95.         for(Iterator<Npc> iterator = _boxList.iterator(); iterator.hasNext();) {
  96.             Npc mob = iterator.next();
  97.             if(mob.getObjectId() == boxid) {                           
  98.                 iterator.remove();
  99.                 Broadcast.announceToOnlinePlayers("[Lucky Chest]: ["+_boxList.size()+"] left.", true);             
  100.             }
  101.             //TODO if(_boxList.isEmpty()){ teleport players back and end the event }
  102.         }      
  103.     }
  104.    
  105.     private static class SingletonHolder
  106.     {
  107.         protected static final LuckyChests _instance = new LuckyChests();
  108.     }
  109.    
  110. }
  111.  
Add Comment
Please, Sign In to add comment