RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
Thieving.java
1package com.osroyale.content.skill.impl.thieving;
2
3import com.osroyale.Config;
4import com.osroyale.content.activity.randomevent.RandomEventHandler;
5import com.osroyale.content.clanchannel.content.ClanTaskKey;
6import com.osroyale.content.dialogue.Expression;
7import com.osroyale.content.event.impl.NpcInteractionEvent;
8import com.osroyale.content.event.impl.ObjectInteractionEvent;
9import com.osroyale.content.pet.PetData;
10import com.osroyale.content.pet.Pets;
11import com.osroyale.content.skillcape.SkillCape;
12import com.osroyale.game.Animation;
13import com.osroyale.game.world.World;
14import com.osroyale.game.world.entity.combat.hit.Hit;
15import com.osroyale.game.world.entity.mob.data.LockType;
16import com.osroyale.game.world.entity.mob.npc.Npc;
17import com.osroyale.game.world.entity.mob.player.Player;
18import com.osroyale.game.world.entity.mob.player.PlayerRight;
19import com.osroyale.game.world.entity.skill.Skill;
20import com.osroyale.game.world.items.Item;
21import com.osroyale.game.world.object.GameObject;
22import com.osroyale.game.world.position.Area;
23import com.osroyale.net.packet.out.SendMessage;
24import com.osroyale.util.Utility;
25
56
57public class Thieving extends Skill {
58
59 public Thieving(int level, double experience) {
60 super(Skill.THIEVING, level, experience);
61 }
62
66 private int failureRate(PickpocketData pickpocket, Player player) {
67 double f1 = (double) pickpocket.getLevel() / 10;
68 double f2 = (double) 100 / ((player.skills.getMaxLevel(Skill.THIEVING) + 1) - pickpocket.getLevel());
69 return (int) Math.floor((f2 + f1) / 2);
70 }
71
72 @Override
73 protected double modifier() {
75 }
76
77 @Override
78 protected boolean clickNpc(Player player, NpcInteractionEvent event) {
79 if (event.getOpcode() != 1) {
80 return false;
81 }
82
83 Npc npc = event.getNpc();
84 PickpocketData pickpocket = PickpocketData.forId(npc.id);
85
86 if (pickpocket == null) {
87 return false;
88 }
89
90 if (player.skills.get(THIEVING).isDoingSkill()) {
91 return true;
92 }
93
94 if (player.skills.getLevel(Skill.THIEVING) < pickpocket.getLevel()) {
95 player.send(new SendMessage("You need a thieving level of " + pickpocket.getLevel() + " to do this!"));
96 return true;
97 }
98
99 boolean failed = Utility.random(100) < failureRate(pickpocket, player);
100
101 player.animate(new Animation(881));
102 player.locking.lock(1, LockType.MASTER);
103 player.skills.get(THIEVING).setDoingSkill(true);
104 player.send(new SendMessage("You attempt to pickpocket the " + npc.getName() + "..."));
105
106 World.schedule(2, () -> {
107 if (failed) {
108 npc.animate(new Animation(422));
109 npc.speak("What do you think you're doing?");
110 player.locking.lock(pickpocket.getStun(), LockType.STUN);
111 player.damage(new Hit(Utility.random(pickpocket.getDamage())));
112 player.send(new SendMessage("You failed to pickpocketing the " + npc.getName() + "."));
113 return;
114 }
115
116 double experience = Area.inSuperDonatorZone(player) || Area.inRegularDonatorZone(player) ? pickpocket.getExperience() * 2 : pickpocket.getExperience();
117
118 player.skills.get(THIEVING).setDoingSkill(false);
119 player.inventory.add(Utility.randomElement(pickpocket.getLoot()));
120 player.send(new SendMessage("You have successfully pickpocket the " + npc.getName() + "."));
121 player.skills.addExperience(Skill.THIEVING, experience * Config.THIEVING_MODIFICATION);
122 RandomEventHandler.trigger(player);
123 Pets.onReward(player, PetData.ROCKY);
124 player.playerAssistant.activateSkilling(1);
125 });
126 return true;
127 }
128
129 @Override
130 protected boolean clickObject(Player player, ObjectInteractionEvent event) {
131 if (event.getOpcode() == 0 && event.getObject().getId() == 7236) {
132 WallSafe.thieve(player);
133 return true;
134 }
135
136 if (event.getOpcode() != 1) {
137 return false;
138 }
139
140 GameObject object = event.getObject();
141
142 if (!StallData.forId(object.getId()).isPresent()) {
143 return false;
144 }
145
146 StallData stall = StallData.forId(object.getId()).get();
147
148 if (!player.inventory.hasCapacityFor(stall.getItem())) {
149 player.send(new SendMessage("You need at least 1 free inventory space to do this!"));
150 return true;
151 }
152
153 if (player.skills.get(THIEVING).getLevel() < stall.getLevel()) {
154 player.send(new SendMessage("You need a thieving level of " + stall.getLevel() + " to steal from this stall."));
155 return true;
156 }
157
158 if (player.skills.get(THIEVING).isDoingSkill()) {
159 return true;
160 }
161
162 int base_chance = 50;
163 int modified_chance = (int) (PlayerRight.isDonator(player) ? base_chance * 2.3
164 : SkillCape.isEquipped(player, SkillCape.THIEVING) ? 2.2 : base_chance);
165 boolean failed = Utility.random(modified_chance) == 0;
166
167 player.animate(new Animation(832));
168 player.locking.lock(1, LockType.MASTER);
169 player.skills.get(THIEVING).setDoingSkill(true);
170
171 World.schedule(3, () -> {
172 double experience = stall.getExperience() * Config.THIEVING_MODIFICATION;
173 double newExperience = Area.inSuperDonatorZone(player) || Area.inRegularDonatorZone(player)? experience * 2 : experience;
174
175 if (failed) {
176 player.damage(new Hit(Utility.random(3, 6)));
177 player.speak("Ouch!");
178 player.send(new SendMessage("You failed to thieve from the stall and were instead inflicted pain!"));
179 return;
180 }
181
182 player.inventory.add(stall.getItem());
183
184 if (PlayerRight.isSuper(player) && Utility.random(0, 10) > 8) {
185 player.inventory.addOrDrop(stall.getItem());
186 }
187
188 player.skills.get(THIEVING).setDoingSkill(false);
189 player.skills.addExperience(THIEVING, newExperience);
190 player.forClan(channel -> channel.activateTask(ClanTaskKey.THIEVING_STALL, player.getName()));
191 Pets.onReward(player, PetData.ROCKY);
192 RandomEventHandler.trigger(player);
193 player.playerAssistant.activateSkilling(1);
194 });
195 return true;
196 }
197
198 public static void exchange(Player player) {
199 int amount = 0, count = 0;
200
201 for (Item item : player.inventory.toArray()) {
202 if (StallData.isReward(item) && player.inventory.remove(item, -1, false)) {
203 amount += StallData.getValue(item);
204 count++;
205 }
206 }
207
208 if (count == 0) {
209 player.dialogueFactory.sendNpcChat(3439, Expression.ANGRY, "You do not have any items of which I am interested", "in purchasing.").execute();
210 return;
211 }
212
213 if (player.inventory.add(new Item(Config.CURRENCY, amount))) {
214 player.send(new SendMessage("You have exchanged " + count + " goods for " + Utility.formatDigits(amount) + " coins."));
215 player.inventory.refresh();
216 return;
217 }
218
219 player.send(new SendMessage("You have no items which the merchant would like to purchase."));
220 }
221}
static final double THIEVING_MODIFICATION
Definition Config.java:328
static final int CURRENCY
Definition Config.java:213
final DialogueFactory sendNpcChat(int id, String... lines)
static void onReward(Player player, int item, int chance)
Definition Pets.java:70
static void schedule(Task task)
Definition World.java:284
void speak(String forceChat)
Definition Mob.java:164
Skill(int skill, int level, double experience)
Definition Skill.java:221
void addExperience(int id, double experience)
static String formatDigits(final int amount)
Definition Utility.java:78
static< T > T randomElement(Collection< T > collection)
Definition Utility.java:285
static Optional< StallData > forId(int id)