Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.rs2server.rs2.content;
- import java.util.Random;
- import org.rs2server.rs2.model.GameObject;
- import org.rs2server.rs2.model.Player;
- import org.rs2server.rs2.model.World;
- import org.rs2server.rs2.model.container.Equipment;
- import org.rs2server.rs2.tickable.Tickable;
- /**
- * @author Jimmy Frix
- *
- */
- public class WebHandler {
- private static int cursor = 0;
- public static Web[] cachedWebs = new Web[5];
- public static void knockDownWeb(final Player player, GameObject object) {
- final Web web = getWeb(object);
- int id = -1;
- for (int i : usableWeapons) {
- if (player.getInventory().get(Equipment.SLOT_WEAPON).getId() == i) {
- id = i;
- break;
- }
- }
- if (id == -1) {
- player.getActionSender().sendMessage("Only a sharp blade can cut through this sticky web.");
- return;
- }
- player.playAnimation(player.getAttackAnimation());
- World.getWorld().submit(new Tickable(1) {
- @Override
- public void execute() {
- this.stop();
- if (random.nextInt(3) != 0) {
- player.getActionSender().sendMessage("You fail to cut through it.");
- return;
- } else {
- player.getActionSender().sendMessage("You slash the web apart");
- replaceWeb(web);
- }
- }
- });
- }
- public static void replaceWeb(Web web) {
- }
- public static Web getWeb(GameObject object) {
- Web web = null;
- for (Web w : cachedWebs) {
- if (w != null && w.getObject().getLocation().equals(object.getLocation())) {
- web = w;
- break;
- }
- }
- if (web == null) {
- web = new Web(object);
- cachedWebs[cursor] = web;
- cursor++;
- }
- return web;
- }
- public static class Web {
- /** Whether the web has been knocked down or not. */
- private boolean knockedDown = false;
- /** The game object instance for the web. */
- private GameObject object;
- public Web(GameObject object) {
- this.object = object;
- }
- public boolean isKnockedDown() {
- return knockedDown;
- }
- public GameObject getObject() {
- return object;
- }
- public void setKnockedDown(boolean b) {
- knockedDown = b;
- }
- }
- private static final Random random = new Random();
- private static final int[] usableWeapons = new int[] {
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement