RuneHive-Game
Loading...
Searching...
No Matches
WallSafe.java
Go to the documentation of this file.
1package com.runehive.content.skill.impl.thieving;
2
3import com.runehive.Config;
4import com.runehive.net.packet.out.SendMessage;
5import com.runehive.game.Animation;
6import com.runehive.game.action.Action;
7import com.runehive.game.action.policy.WalkablePolicy;
8import com.runehive.game.world.entity.combat.hit.Hit;
9import com.runehive.game.world.entity.mob.player.Player;
10import com.runehive.game.world.entity.skill.Skill;
11import com.runehive.game.world.items.Item;
12import com.runehive.util.Utility;
13
14/**
15 * Handles the wall safe thieving.
16 *
17 * @author Daniel
18 */
19public class WallSafe {
20
21 /** Holds all the rewards. */
22 private static final Item REWARD[] = {
23 new Item(1617), new Item(1619), new Item(1621), new Item(1623),
24 new Item(1623), new Item(995, 20), new Item(995, 40)
25 };
26
27 /** Handles thieving from the wall safe. */
28 static void thieve(Player player) {
29 if (player.skills.getMaxLevel(Skill.THIEVING) < 50) {
30 player.dialogueFactory.sendStatement("You need a thieving level of 50 to do this!").execute();
31 return;
32 }
33 if (player.inventory.remaining() == 0) {
34 player.dialogueFactory.sendStatement("You do not have inventory spaces to do this!").execute();
35 return;
36 }
37 if (player.skills.get(Skill.THIEVING).isDoingSkill()) {
38 return;
39 }
40 player.action.execute(crack(player), true);
41 }
42
43 /** Gets the thieving rate. */
44 private static int rate(Player player) {
45 boolean stethoscope = player.inventory.contains(new Item(5560));
46 int calculation = stethoscope ? Utility.random(5) : (Utility.random(11) + 20);
47 int calculated = (10 - (int) Math.floor(player.skills.getMaxLevel(Skill.THIEVING) / 10) + calculation) / 2;
48 return calculated <= 0 ? 1 : (calculated > 10 ? 10 : calculated);
49 }
50
51 /** The wallsafe fail chance. */
52 public static int chance(Player player) {
53 return (Utility.random((int) Math.floor(player.skills.getMaxLevel(Skill.THIEVING / 10) + 1)));
54 }
55
56 /** The wallsafe crack action. */
57 private static Action<Player> crack(Player player) {
58 return new Action<Player>(player, 3, true) {
59 int rate = rate(player);
60 int tick = 0;
61
62 @Override
63 public void execute() {
64 if (tick++ != rate) {
65 player.animate(new Animation(881));
66 return;
67 }
68
69 if (chance(player) == 0) {
70 player.animate(new Animation(404));
71 player.send(new SendMessage("You slip and trigger a trap!"));
72 player.damage(new Hit(Utility.random(1, 5)));
73 cancel();
74 return;
75 }
76
77 player.send(new SendMessage("You get some loot."));
80 cancel();
81 }
82
83 @Override
84 protected void onSchedule() {
86 player.send(new SendMessage("You attempt to crack the safe... "));
87 }
88
89 @Override
90 protected void onCancel(boolean logout) {
91 player.skills.get(Skill.THIEVING).setDoingSkill(false);
92 }
93
94 @Override
95 public String getName() {
96 return "Wallsafe crack";
97 }
98
99 @Override
100 public boolean prioritized() {
101 return false;
102 }
103
104 @Override
105 public WalkablePolicy getWalkablePolicy() {
107 }
108 };
109 }
110}
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
final DialogueFactory execute()
Retrieves the next dialogue in the chain and executes it.
final DialogueFactory sendStatement(String... lines)
Appends a StatementDialogue to the current dialogue chain.
static int chance(Player player)
The wallsafe fail chance.
Definition WallSafe.java:52
static final Item REWARD[]
Holds all the rewards.
Definition WallSafe.java:22
static Action< Player > crack(Player player)
The wallsafe crack action.
Definition WallSafe.java:57
static void thieve(Player player)
Handles thieving from the wall safe.
Definition WallSafe.java:28
static int rate(Player player)
Gets the thieving rate.
Definition WallSafe.java:44
Class that models a single animation used by an entity.
Represents an action an entity can execute.
Definition Action.java:12
public< A extends Action<?> > void execute(A action)
A Hit object holds the damage amount and hitsplat data.
Definition Hit.java:10
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
void setDoingSkill(boolean doingSkill)
Definition Skill.java:489
void addExperience(int id, double experience)
Adds experience to a given skill.
int getMaxLevel(int id)
Gets the highest possible level of a skill.
Skill get(int id)
Gets the skill for an id.
The container class that represents an item that can be interacted with.
Definition Item.java:21
boolean add(Item item)
Attempts to deposit item into this container.
boolean contains(int id)
Determines if this container contains id.
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
A queue policy determines whether the action can occur while walking.
NON_WALKABLE
This indicates actions cannot occur while walking.