RuneHive-Game
Loading...
Searching...
No Matches
Thieving.java
Go to the documentation of this file.
1package com.runehive.content.skill.impl.thieving;
2
3import com.runehive.Config;
4import com.runehive.content.activity.randomevent.RandomEventHandler;
5import com.runehive.content.clanchannel.content.ClanTaskKey;
6import com.runehive.content.dialogue.Expression;
7import com.runehive.content.event.impl.NpcInteractionEvent;
8import com.runehive.content.event.impl.ObjectInteractionEvent;
9import com.runehive.content.pet.PetData;
10import com.runehive.content.pet.Pets;
11import com.runehive.content.skillcape.SkillCape;
12import com.runehive.game.Animation;
13import com.runehive.game.world.World;
14import com.runehive.game.world.entity.combat.hit.Hit;
15import com.runehive.game.world.entity.mob.data.LockType;
16import com.runehive.game.world.entity.mob.npc.Npc;
17import com.runehive.game.world.entity.mob.player.Player;
18import com.runehive.game.world.entity.mob.player.PlayerRight;
19import com.runehive.game.world.entity.skill.Skill;
20import com.runehive.game.world.items.Item;
21import com.runehive.game.world.object.GameObject;
22import com.runehive.game.world.position.Area;
23import com.runehive.net.packet.out.SendMessage;
24import com.runehive.util.Utility;
25
26/**
27 * Handles the thieving skill.
28 *
29 * @author Daniel
30 */
31public class Thieving extends Skill {
32
33 public Thieving(int level, double experience) {
34 super(Skill.THIEVING, level, experience);
35 }
36
37 /**
38 * The failure rate for pickpocketing.
39 */
40 private int failureRate(PickpocketData pickpocket, Player player) {
41 double f1 = (double) pickpocket.getLevel() / 10;
42 double f2 = (double) 100 / ((player.skills.getMaxLevel(Skill.THIEVING) + 1) - pickpocket.getLevel());
43 return (int) Math.floor((f2 + f1) / 2);
44 }
45
46 @Override
47 protected double modifier() {
49 }
50
51 @Override
52 protected boolean clickNpc(Player player, NpcInteractionEvent event) {
53 if (event.getOpcode() != 1) {
54 return false;
55 }
56
57 Npc npc = event.getNpc();
58 PickpocketData pickpocket = PickpocketData.forId(npc.id);
59
60 if (pickpocket == null) {
61 return false;
62 }
63
64 if (player.skills.get(THIEVING).isDoingSkill()) {
65 return true;
66 }
67
68 if (player.skills.getLevel(Skill.THIEVING) < pickpocket.getLevel()) {
69 player.send(new SendMessage("You need a thieving level of " + pickpocket.getLevel() + " to do this!"));
70 return true;
71 }
72
73 boolean failed = Utility.random(100) < failureRate(pickpocket, player);
74
75 player.animate(new Animation(881));
76 player.locking.lock(1, LockType.MASTER);
77 player.skills.get(THIEVING).setDoingSkill(true);
78 player.send(new SendMessage("You attempt to pickpocket the " + npc.getName() + "..."));
79
80 World.schedule(2, () -> {
81 if (failed) {
82 npc.animate(new Animation(422));
83 npc.speak("What do you think you're doing?");
84 player.locking.lock(pickpocket.getStun(), LockType.STUN);
85 player.damage(new Hit(Utility.random(pickpocket.getDamage())));
86 player.send(new SendMessage("You failed to pickpocketing the " + npc.getName() + "."));
87 return;
88 }
89
90 double experience = Area.inSuperDonatorZone(player) || Area.inRegularDonatorZone(player) ? pickpocket.getExperience() * 2 : pickpocket.getExperience();
91
92 player.skills.get(THIEVING).setDoingSkill(false);
93 player.inventory.add(Utility.randomElement(pickpocket.getLoot()));
94 player.send(new SendMessage("You have successfully pickpocket the " + npc.getName() + "."));
97 Pets.onReward(player, PetData.ROCKY);
99 });
100 return true;
101 }
102
103 @Override
104 protected boolean clickObject(Player player, ObjectInteractionEvent event) {
105 if (event.getOpcode() == 0 && event.getObject().getId() == 7236) {
106 WallSafe.thieve(player);
107 return true;
108 }
109
110 if (event.getOpcode() != 1) {
111 return false;
112 }
113
114 GameObject object = event.getObject();
115
116 if (!StallData.forId(object.getId()).isPresent()) {
117 return false;
118 }
119
120 StallData stall = StallData.forId(object.getId()).get();
121
122 if (!player.inventory.hasCapacityFor(stall.getItem())) {
123 player.send(new SendMessage("You need at least 1 free inventory space to do this!"));
124 return true;
125 }
126
127 if (player.skills.get(THIEVING).getLevel() < stall.getLevel()) {
128 player.send(new SendMessage("You need a thieving level of " + stall.getLevel() + " to steal from this stall."));
129 return true;
130 }
131
132 if (player.skills.get(THIEVING).isDoingSkill()) {
133 return true;
134 }
135
136 int base_chance = 50;
137 int modified_chance = (int) (PlayerRight.isDonator(player) ? base_chance * 2.3
138 : SkillCape.isEquipped(player, SkillCape.THIEVING) ? 2.2 : base_chance);
139 boolean failed = Utility.random(modified_chance) == 0;
140
141 player.animate(new Animation(832));
142 player.locking.lock(1, LockType.MASTER);
143 player.skills.get(THIEVING).setDoingSkill(true);
144
145 World.schedule(3, () -> {
147 double newExperience = Area.inSuperDonatorZone(player) || Area.inRegularDonatorZone(player)? experience * 2 : experience;
148
149 if (failed) {
150 player.damage(new Hit(Utility.random(3, 6)));
151 player.speak("Ouch!");
152 player.send(new SendMessage("You failed to thieve from the stall and were instead inflicted pain!"));
153 return;
154 }
155
156 player.inventory.add(stall.getItem());
157
158 if (PlayerRight.isSuper(player) && Utility.random(0, 10) > 8) {
159 player.inventory.addOrDrop(stall.getItem());
160 }
161
162 player.skills.get(THIEVING).setDoingSkill(false);
163 player.skills.addExperience(THIEVING, newExperience);
164 player.forClan(channel -> channel.activateTask(ClanTaskKey.THIEVING_STALL, player.getName()));
165 Pets.onReward(player, PetData.ROCKY);
168 });
169 return true;
170 }
171
172 public static void exchange(Player player) {
173 int amount = 0, count = 0;
174
175 for (Item item : player.inventory.toArray()) {
176 if (StallData.isReward(item) && player.inventory.remove(item, -1, false)) {
177 amount += StallData.getValue(item);
178 count++;
179 }
180 }
181
182 if (count == 0) {
183 player.dialogueFactory.sendNpcChat(3439, Expression.ANGRY, "You do not have any items of which I am interested", "in purchasing.").execute();
184 return;
185 }
186
187 if (player.inventory.add(new Item(Config.CURRENCY, amount))) {
188 player.send(new SendMessage("You have exchanged " + count + " goods for " + Utility.formatDigits(amount) + " coins."));
189 player.inventory.refresh();
190 return;
191 }
192
193 player.send(new SendMessage("You have no items which the merchant would like to purchase."));
194 }
195}
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
static final int CURRENCY
The currency identification of the server.
Definition Config.java:175
final DialogueFactory execute()
Retrieves the next dialogue in the chain and executes it.
final DialogueFactory sendNpcChat(int id, String... lines)
Appends an NpcDialogue to the current dialogue chain.
Handles spawning, rewarding and picking up of pets.
Definition Pets.java:27
static void onReward(Player player, int item, int chance)
Handles calculating the chance of a player receiving a skilling pet.
Definition Pets.java:33
boolean clickNpc(Player player, NpcInteractionEvent event)
Definition Thieving.java:52
int failureRate(PickpocketData pickpocket, Player player)
The failure rate for pickpocketing.
Definition Thieving.java:40
boolean clickObject(Player player, ObjectInteractionEvent event)
static void thieve(Player player)
Handles thieving from the wall safe.
Definition WallSafe.java:28
Class that models a single animation used by an entity.
Represents the game world.
Definition World.java:46
static void schedule(Task task)
Submits a new event.
Definition World.java:247
A Hit object holds the damage amount and hitsplat data.
Definition Hit.java:10
void speak(String forceChat)
Sets the mob's forced chat.
Definition Mob.java:127
Represents a non-player character in the in-game world.
Definition Npc.java:29
String getName()
Gets the name of this entity.
Definition Npc.java:166
This class represents a character controlled by a player.
Definition Player.java:125
void forClan(Consumer< ClanChannel > action)
Definition Player.java:568
String getName()
Gets the name of this entity.
Definition Player.java:774
double experience
The current skill experience.
Definition Skill.java:179
int getLevel()
Gets the current skill level.
Definition Skill.java:205
int level
The current level of the skill.
Definition Skill.java:173
static final int THIEVING
The thieving skill id.
Definition Skill.java:72
void setDoingSkill(boolean doingSkill)
Definition Skill.java:489
Skill(int skill, int level, double experience)
Constructs a new Skill.
Definition Skill.java:184
void addExperience(int id, double experience)
Adds experience to a given skill.
int getLevel(int id)
Gets the level of a 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 remove(Item item)
Attempts to withdraw item from this container.
boolean add(Item item)
Attempts to deposit item into this container.
final boolean hasCapacityFor(Item... item)
Determines if this container has the capacity for item.
final Item[] toArray()
Returns a shallow copy of the backing array.
void refresh()
Refreshes the players inventory.
void addOrDrop(List< Item > items)
Attempts to deposit an item to the players inventory, if there is no space it'll bank the item instea...
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 String formatDigits(final int amount)
Formats digits for integers.
Definition Utility.java:41
static< T > T randomElement(Collection< T > collection)
Picks a random element out of any array type.
Definition Utility.java:248
Represents the expressions of entities for dialogue.
Holds the data for pets.
Definition PetData.java:14
Holds all the data for pickpocketing Npcs.
static PickpocketData forId(int npc)
Gets the pickpocket data for npc.
double getExperience()
Gets the experience rewarded.
Holds all the data for thieving stalls.
int getExperience()
Gets the experience rewarded.
static boolean isReward(Item item)
Checks if the item is a reward.
static Optional< StallData > forId(int id)
Gets the stall data base off object identification.
static boolean isEquipped(Player player, SkillCape cape)
static boolean isDonator(Player player)
Checks if the player has donator status.
static boolean isSuper(Player player)
Checks if the player has super donator status.