Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.20 KB | None | 0 0
  1. package org.rs2server.rs2.content;
  2.  
  3. import java.util.Random;
  4.  
  5. import org.rs2server.rs2.model.GameObject;
  6. import org.rs2server.rs2.model.Player;
  7. import org.rs2server.rs2.model.World;
  8. import org.rs2server.rs2.model.container.Equipment;
  9. import org.rs2server.rs2.tickable.Tickable;
  10.  
  11. /**
  12.  * @author Jimmy Frix
  13.  *
  14.  */
  15. public class WebHandler {
  16.  
  17.     private static int cursor = 0;
  18.  
  19.     public static Web[] cachedWebs = new Web[5];
  20.  
  21.     public static void knockDownWeb(final Player player, GameObject object) {
  22.         final Web web = getWeb(object);
  23.         int id = -1;
  24.         for (int i : usableWeapons) {
  25.             if (player.getInventory().get(Equipment.SLOT_WEAPON).getId() == i) {
  26.                 id = i;
  27.                 break;
  28.             }
  29.         }
  30.         if (id == -1) {
  31.             player.getActionSender().sendMessage("Only a sharp blade can cut through this sticky web.");
  32.             return;
  33.         }
  34.         player.playAnimation(player.getAttackAnimation());
  35.  
  36.         World.getWorld().submit(new Tickable(1) {
  37.             @Override
  38.             public void execute() {
  39.                 this.stop();
  40.                 if (random.nextInt(3) != 0) {
  41.                     player.getActionSender().sendMessage("You fail to cut through it.");
  42.                     return;
  43.                 } else {
  44.                     player.getActionSender().sendMessage("You slash the web apart");
  45.                     replaceWeb(web);
  46.                 }
  47.             }
  48.         });
  49.     }
  50.    
  51.     public static void replaceWeb(Web web) {
  52.        
  53.     }
  54.  
  55.     public static Web getWeb(GameObject object) {
  56.         Web web = null;
  57.         for (Web w : cachedWebs) {
  58.             if (w != null && w.getObject().getLocation().equals(object.getLocation())) {
  59.                 web = w;
  60.                 break;
  61.             }
  62.         }
  63.         if (web == null) {
  64.             web = new Web(object);
  65.             cachedWebs[cursor] = web;
  66.             cursor++;
  67.         }
  68.         return web;
  69.     }
  70.  
  71.     public static class Web {
  72.  
  73.         /** Whether the web has been knocked down or not. */
  74.         private boolean knockedDown = false;
  75.  
  76.         /** The game object instance for the web. */
  77.         private GameObject object;
  78.  
  79.         public Web(GameObject object) {
  80.             this.object = object;
  81.         }
  82.  
  83.         public boolean isKnockedDown() {
  84.             return knockedDown;
  85.         }
  86.  
  87.         public GameObject getObject() {
  88.             return object;
  89.         }
  90.  
  91.         public void setKnockedDown(boolean b) {
  92.             knockedDown = b;
  93.         }
  94.  
  95.     }
  96.    
  97.     private static final Random random = new Random();
  98.    
  99.     private static final int[] usableWeapons = new int[] {
  100.        
  101.     };
  102.  
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement