Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * This piece of work is apart of the server Rome.
- */
- package org.hyperion.rs2.action.impl;
- import org.hyperion.rs2.event.Event;
- import org.hyperion.rs2.model.*;
- import org.hyperion.rs2.model.combat.Combat;
- import org.hyperion.rs2.util.Misc;
- import java.util.HashMap;
- import java.util.Map;
- /**
- * An action for pickpocketing or thieving from a stall.
- *
- * @author Arham Siddiqui
- */
- public class ThievingAction extends HarvestingAction {
- /**
- * The delay.
- */
- private static final int DELAY = 1000;
- /**
- * The factor.
- */
- private static final double FACTOR = 0.5;
- /**
- * Whether or not this action grants periodic rewards.
- */
- private static final boolean PERIODIC = false;
- /**
- * The type of stall.
- */
- private static Stall stall;
- /**
- * The type of NPC.
- */
- private static Thievable thievable;
- /**
- * The object clicked.
- */
- private GameObject gameObject;
- /**
- * The random number to generate. The reason this is not local is due to this being in two methods and I would like
- * them to both use the same item (just for verification that we are not adding 1 item yet checking for 2).
- */
- private int random = 0;
- /**
- * Creates the harvesting action for the specified player.
- *
- * @param player The player to create the action for.
- * @param gameObject The object clicked.
- * @param thievingType The type of thieving enum (Stall or ...).
- */
- public ThievingAction(Player player, GameObject gameObject, Object thievingType) {
- super(player, gameObject.getLocation());
- this.gameObject = gameObject;
- if (thievingType instanceof Stall) {
- stall = (Stall) thievingType;
- } else if (thievingType instanceof Thievable) {
- thievable = (Thievable) thievingType;
- }
- }
- @Override
- public long getHarvestDelay() {
- return DELAY;
- }
- @Override
- public boolean getPeriodicRewards() {
- return PERIODIC;
- }
- @Override
- public void init() {
- /*
- * Is the stall null? The reason I am asking this is because I am setting something specifically for the stall
- * enum (Hint: <code>stall.getProducts()</code>).
- */
- if (stall != null) {
- /*
- * If the stall is not null, set the random number to the stall's possible item (by randomizing the length
- * of the products array.
- */
- random = Misc.random(stall.getProducts().length - 1);
- }
- /*
- * Is the stall not null and can we add the item we plan to add?
- */
- if (stall != null && getPlayer().getInventory().hasRoomFor(stall.getProducts()[random])) {
- // TODO Use the doingEmote boolean.
- /*
- * If the stall is not null and we can add the item we plan to add, is the stall's capacity greater than 0?
- */
- if (gameObject.getCapacity() > 0) {
- /*
- * If the stall's capacity is greater than 0, decrement the capacity in the stall.
- */
- gameObject.decrementCapacity(1);
- }
- /*
- * Is the capacity now 0 after decrementing it?
- */
- if (gameObject.getCapacity() == 0) {
- /**
- * If the capacity now is 0, send the empty stall object.
- */
- for (Player player : getPlayer().getRegion().getPlayers()) {
- WorldObjectManager.addObject(new WorldObject(634, gameObject.getLocation().getX(), gameObject.getLocation().getY(), gameObject.getLocation().getZ(), gameObject.getRotation(), gameObject.getType(), -1, 100));
- }
- /*
- * Now, lets send the event for the World which will respawn this stall. The reason for this * 1000 is
- * due to 1 second being 1000 milliseconds, and for your ease, I made the stall's respawn times by
- * seconds and not milliseconds (just incase you ever would like to add more stalls (if I missed any or
- * you are loading higher revision data)).
- */
- World.getWorld().submit(new Event(stall.getRespawnTime() * 600) {
- @Override
- public void execute() {
- /**
- * This will load all the players in the region and send the new, remade game object.
- */
- for (Player player : getPlayer().getRegion().getPlayers()) {
- WorldObjectManager.addObject(new WorldObject(gameObject.getDefinition().getId(), gameObject.getLocation().getX(), gameObject.getLocation().getY(), gameObject.getLocation().getZ(), gameObject.getRotation(), gameObject.getType(), -1, 100));
- }
- /*
- * Sets the capacity. You might be wondering why I did TWO randoms. Well, the reason
- * is that I am going to randomize a randomized number. This gives more precise numbers.
- */
- gameObject.setCapacity(Misc.random(Misc.random(10, 15)));
- }
- });
- }
- /*
- * Now that we have gotten the respawning and capacities taken care of, lets now focus on the NPCs around
- * the areas and the shopkeeper who will not talk to you if you have theft their shop within the past 20
- * minutes.
- *
- * TODO If you have theft their stall within the past 20 minutes, do not let the shopkeeper talk to them.
- */
- /*
- * First, lets load the NPCs in the region.
- */
- for (NPC npc : getPlayer().getRegion().getNpcs()) {
- /*
- * Is the NPC's definition not null and does the name (lower cased) contain "guard"?
- */
- if (npc.getDefinition() != null && npc.getDefinition().getName().toLowerCase().contains("guard")) {
- /*
- * If the NPC's definition is not null and the name (lower cased) contains "guard", is the NPC is
- * within the distance of 5 tiles to the player?
- */
- if (npc.getLocation().isWithinDistance(npc, getPlayer(), 5)) {
- /*
- * If the NPC is within the distance of 5 tiles to the player, add the attacking action and send
- * the yell text, "Hey! Get your hands off there!"
- */
- if (getPlayer().getLocation().isWithinInteractionDistance(npc.getLocation())) {
- getPlayer().getActionQueue().addAction(new AttackAction(npc, getPlayer(), Combat.AttackType.MELEE));
- npc.setForceChat("Hey! Get your hands off there!");
- this.stop();
- }
- }
- }
- }
- } else if (stall != null) {
- if (!getPlayer().getInventory().hasRoomFor(stall.getProducts()[random])) {
- /*
- * Else, if we cannot add the item, send the message, "You don't have enough space in your inventory."
- */
- getPlayer().getActionSender().sendMessage("You don't have enough space in your inventory.");
- }
- }
- }
- @Override
- public int getCycles() {
- return 1;
- }
- @Override
- public double getFactor() {
- return FACTOR;
- }
- @Override
- public Item getHarvestedItem() {
- if (stall != null && getPlayer().getInventory().hasRoomFor(stall.getProducts()[random])) {
- return stall.getProducts()[Misc.random(stall.getProducts().length - 1)];
- }
- return null;
- }
- @Override
- public double getExperience() {
- if (stall != null) {
- return stall.getExperience();
- }
- return 0;
- }
- @Override
- public Animation getAnimation() {
- if (stall != null) {
- return Animation.STEALING_STALL;
- } else if (thievable != null) {
- return Animation.THIEVING_NPC;
- }
- return null;
- }
- @Override
- public int getSkill() {
- return Skills.THIEVING;
- }
- /**
- * Represents the type of Stall.
- */
- public enum Stall {
- /**
- * Silk stall.
- */
- SILK_STALL(new Item[]{new Item(950)}, 20, 24, 6, new int[]{2560}),
- /**
- * Fur stall.
- */
- FUR_STALL(new Item[]{new Item(958), new Item(6814)}, 35, 36, 12, new int[]{2563});
- /**
- * A map of object ids to stalls.
- */
- private static Map<Integer, Stall> stall = new HashMap<Integer, Stall>();
- /**
- * The products of the stall.
- */
- private Item[] products;
- /**
- * The level required to thieve from this stall.
- */
- private int level;
- /**
- * The experience given from this stall.
- */
- private double experience;
- /**
- * The amount of time it takes for this stall to respawn.
- */
- private int respawnTime;
- /**
- * The objects that are related to this stall.
- */
- private int[] objects;
- /**
- * Creates the stall.
- *
- * @param products The products on the stall that can be stolen.
- * @param level The required level to thieve from this stall.
- * @param experience The experience given from this stall.
- * @param respawnTime The amount of time it takes for this stall to respawn (in seconds).
- * @param objects The objects that are related to this stall.
- */
- private Stall(Item[] products, int level, double experience, int respawnTime, int[] objects) {
- this.products = products;
- this.level = level;
- this.experience = experience;
- this.objects = objects;
- }
- /**
- * Gets a stall by an object id.
- *
- * @param object The object id.
- * @return The stall, or <code>null</code> if the object is not a stall.
- */
- public static Stall forId(int object) {
- return stall.get(object);
- }
- /**
- * Populates the list.
- */
- static {
- for (Stall stalls : Stall.values()) {
- for (int object : stalls.objects) {
- stall.put(object, stalls);
- }
- }
- }
- /**
- * Gets the products on the stall that can be stolen.
- *
- * @return The products on the stall.
- */
- public Item[] getProducts() {
- return products;
- }
- /**
- * Gets the level required to thieve from this stall.
- *
- * @return The level required to thieve from this stall.
- */
- public int getLevel() {
- return level;
- }
- /**
- * Gets the experience given from the stall.
- *
- * @return The experience given from the stall.
- */
- public double getExperience() {
- return experience;
- }
- /**
- * Gets the amount of time it takes for this stall to respawn.
- *
- * @return The amount of time it takes for this stall to respawn (in seconds).
- */
- public int getRespawnTime() {
- return respawnTime;
- }
- /**
- * Gets the objects that are related to this skill.
- *
- * @return The objects that are related to this skill.
- */
- public int[] getObjects() {
- return objects;
- }
- }
- /**
- * Represents the type of Thievable.
- */
- public enum Thievable {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement