RuneHive-Game
Loading...
Searching...
No Matches
PickpocketAction.java
Go to the documentation of this file.
1package com.runehive.content.skill.impl.thieving;
2
3import com.runehive.Config;
4import com.runehive.game.Animation;
5import com.runehive.game.action.Action;
6import com.runehive.game.action.policy.WalkablePolicy;
7import com.runehive.game.world.entity.combat.hit.Hit;
8import com.runehive.game.world.entity.mob.data.LockType;
9import com.runehive.game.world.entity.mob.npc.Npc;
10import com.runehive.game.world.entity.mob.player.Player;
11import com.runehive.game.world.entity.skill.Skill;
12import com.runehive.game.world.position.Area;
13import com.runehive.net.packet.out.SendMessage;
14import com.runehive.util.Utility;
15
16/**
17 * Handles the pickpocketing action.
18 *
19 * @author Daniel
20 */
21public final class PickpocketAction extends Action<Player> {
22 /** The pickpocket data. */
24
25 /** The npc being pickpocketed. */
26 private final Npc npc;
27
28 /** Constructs a new <code>PickpocketData</code>. */
30 super(player, 3);
31 this.npc = npc;
32 this.pickpocket = pickpocket;
33 }
34
35 /** The failure rate for pickpocketing. */
36 private int failureRate(Player player) {
37 double f1 = pickpocket.getLevel() / 10;
38 double f2 = 100 / ((player.skills.getMaxLevel(Skill.THIEVING) + 1) - pickpocket.getLevel());
39 return (int) Math.floor((f2 + f1) / 2);
40 }
41
42 @Override
43 public void execute() {
44 boolean failed = Utility.random(100) < failureRate(getMob());
45
46 if (failed) {
47 npc.interact(getMob());
48 npc.face(npc.faceDirection);
49 npc.animate(new Animation(422));
50 npc.speak("What do you think you're doing?");
51 getMob().action.clearNonWalkableActions();
52 getMob().damage(new Hit(Utility.random(pickpocket.getDamage())));
53 getMob().locking.lock(pickpocket.getStun(), LockType.STUN);
54 getMob().send(new SendMessage("You failed to pickpocketing the " + npc.getName() + "."));
55 cancel();
56 return;
57 }
58
59 double experience = Area.inSuperDonatorZone(getMob()) || Area.inRegularDonatorZone(getMob()) ? pickpocket.getExperience() * 2 : pickpocket.getExperience();
60 getMob().skills.addExperience(Skill.THIEVING, experience * Config.THIEVING_MODIFICATION);
61 getMob().send(new SendMessage("You have successfully pickpocket the " + npc.getName() + "."));
62 getMob().inventory.add(Utility.randomElement(pickpocket.getLoot()));
63 getMob().locking.unlock();
64 cancel();
65 }
66
67 @Override
68 public String getName() {
69 return "Thieving pickpocket";
70 }
71
72 @Override
73 public boolean prioritized() {
74 return false;
75 }
76
77 @Override
81}
The class that contains setting-related constants for the server.
Definition Config.java:24
static final double THIEVING_MODIFICATION
The experience modification for thieving.
Definition Config.java:286
int failureRate(Player player)
The failure rate for pickpocketing.
PickpocketAction(Player player, Npc npc, PickpocketData pickpocket)
Constructs a new PickpocketData.
final PickpocketData pickpocket
The pickpocket data.
void execute()
A function representing the unit of work that will be carried out.
WalkablePolicy getWalkablePolicy()
Gets the WalkablePolicy of this action.
boolean prioritized()
Determines if this action is prioritized.
Class that models a single animation used by an entity.
T getMob()
Gets the player.
Definition Action.java:44
Action(T mob, int delay, boolean instant)
Creates a new Action randomevent.
Definition Action.java:24
synchronized final void cancel()
Cancels all subsequent executions.
Definition Task.java:113
A Hit object holds the damage amount and hitsplat data.
Definition Hit.java:10
Represents a non-player character in the in-game world.
Definition Npc.java:29
This class represents a character controlled by a player.
Definition Player.java:125
Represents a trainable and usable skill.
Definition Skill.java:18
static final int THIEVING
The thieving skill id.
Definition Skill.java:72
int getMaxLevel(int id)
Gets the highest possible level of a skill.
Handles checking if mobs are in a certain area.
Definition Area.java:13
static boolean inRegularDonatorZone(Interactable entity)
Definition Area.java:151
static boolean inSuperDonatorZone(Interactable entity)
Definition Area.java:148
The OutgoingPacket that sends a message to a Players chatbox in the client.
Handles miscellaneous methods.
Definition Utility.java:27
static int random(int bound)
Definition Utility.java:239
static< T > T randomElement(Collection< T > collection)
Picks a random element out of any array type.
Definition Utility.java:248
Holds all the data for pickpocketing Npcs.
A queue policy determines whether the action can occur while walking.
NON_WALKABLE
This indicates actions cannot occur while walking.