RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
MiningAction.java
1package com.osroyale.content.skill.impl.mining;
2
3import com.osroyale.Config;
4import com.osroyale.content.achievement.AchievementHandler;
5import com.osroyale.content.achievement.AchievementKey;
6import com.osroyale.content.activity.randomevent.RandomEventHandler;
7import com.osroyale.content.clanchannel.content.ClanTaskKey;
8import com.osroyale.content.pet.PetData;
9import com.osroyale.content.pet.Pets;
10import com.osroyale.content.prestige.PrestigePerk;
11import com.osroyale.content.skill.impl.smithing.SmeltingData;
12import com.osroyale.content.skillcape.SkillCape;
13import com.osroyale.game.Animation;
14import com.osroyale.game.action.Action;
15import com.osroyale.game.action.policy.WalkablePolicy;
16import com.osroyale.game.task.impl.ObjectReplacementEvent;
17import com.osroyale.game.world.World;
18import com.osroyale.game.world.entity.mob.player.Player;
19import com.osroyale.game.world.entity.skill.Skill;
20import com.osroyale.game.world.items.Item;
21import com.osroyale.game.world.items.containers.equipment.Equipment;
22import com.osroyale.game.world.object.GameObject;
23import com.osroyale.game.world.position.Area;
24import com.osroyale.net.packet.out.SendMessage;
25import com.osroyale.util.RandomUtils;
26import com.osroyale.util.Utility;
27
28
32public class MiningAction extends Action<Player> {
33 private final GameObject object;
34 private final OreData ore;
35 private final PickaxeData pickaxe;
36
37 MiningAction(Player player, GameObject object, OreData ore, PickaxeData pickaxe) {
38 super(player, 3, false);
39 this.object = object;
40 this.ore = ore;
41 this.pickaxe = pickaxe;
42 }
43
44 private boolean mine() {
45 if(!getMob().equipment.containsAny(Equipment.PICKAXES) && !getMob().inventory.containsAny(Equipment.PICKAXES)) {
46 getMob().message("You need a pickaxe to mine this rock.");
47 getMob().animate(Animation.RESET);
48 return false;
49 }
50 if (getMob().inventory.getFreeSlots() == 0) {
51 getMob().dialogueFactory.sendStatement("You can't carry anymore ore.").execute();
52 getMob().animate(Animation.RESET);
53 return false;
54 }
55 getMob().animate(pickaxe.animation);
56
57 if (Mining.success(getMob(), ore, pickaxe)) {
58 if (object == null || !object.active()) {
59 return false;
60 }
61
62 int harvest = ore.ore;
63 boolean gem = harvest == -1;
64
65 if (gem) {
66 harvest = Mining.GEM_ITEMS.next().getId();
67 }
68
69 SmeltingData smeltingData = SmeltingData.getSmeltData(harvest);
70 boolean combust = smeltingData != null && pickaxe == PickaxeData.INFERNO_ADZE && Utility.random(3) == 0;
71
72 if(!combust) {
73 if (harvest == 453 && getMob().inventory.contains(24480) && getMob().coalBag.container.hasCapacityFor(new Item(harvest)))
74 getMob().coalBag.container.add(new Item(harvest));
75 else
76 getMob().inventory.add(harvest, 1);
77 } else {
78 harvest = smeltingData.produced[0].getId();// Bar
79 getMob().skills.addExperience(Skill.SMITHING, ore.infernalExperience * Config.SMITHING_MODIFICATION);
80 getMob().inventory.add(harvest, 1);
81 }
82
83 getMob().skills.addExperience(Skill.MINING, ore.experience * Config.MINING_MODIFICATION);
84 getMob().playerAssistant.activateSkilling(1);
85 RandomEventHandler.trigger(getMob());
86 Pets.onReward(getMob(), PetData.ROCK_GOLEM);
88
89 if (ore == OreData.RUNITE) {
90 getMob().forClan(channel -> channel.activateTask(ClanTaskKey.RUNITE_ORES, getMob().getName()));
91 }
92
93 if ((SkillCape.isEquipped(getMob(), SkillCape.MINING) || getMob().prestige.hasPerk(PrestigePerk.THE_ROCK)) && RandomUtils.success(.10)) {
94 getMob().inventory.addOrDrop(new Item(harvest, 1));
95 }
96
97 if (!gem) { handleCelestialRing(harvest); }
98
99 int base_chance = ore.ordinal() * 45;
100 int modified_chance = /*getMob().equipment.isWearingChargedGlory() ? (int) (base_chance / 2.2) :*/ base_chance;
101
102 if (Utility.random(modified_chance) == 1) {
103 if (getMob().inventory.getFreeSlots() != 0 && !gem) {
104 Item item = Mining.GEM_ITEMS.next();
105 getMob().inventory.add(item);
106 getMob().send(new SendMessage("You have found " + Utility.getAOrAn(item.getName()) + " " + item.getName() + "."));
108 }
109 }
110
111 if (object.active() && (!ore.equals(OreData.RUNE_ESSENCE) && Utility.random(8) <= 0 && !Area.inSuperDonatorZone(object) && !Area.inRegularDonatorZone(object))) {
112 this.cancel();
113 getMob().resetAnimation();
114 object.getGenericAttributes().set("ores", -1);
115 getMob().skills.get(Skill.MINING).setDoingSkill(false);
116 getMob().animate(Animation.RESET, true);
117 World.schedule(new ObjectReplacementEvent(object, ore.replacement, ore.respawn, () -> {
118 object.getGenericAttributes().set("ores", ore.oreCount);
119 }));
120 }
121 }
122 return true;
123 }
124
125 private void handleCelestialRing(int oreId) {
126 if (!getMob().equipment.containsAny(25541, 25545)) {
127 return;
128 }
129
130 if (getMob().celestialRingCharges <= 0) {
131 getMob().equipment.replace(25541, 25539, true);
132 return;
133 }
134
135 if (Utility.hasOneOutOf(10)) {
136 if(oreId == 453 && getMob().inventory.contains(24480) && getMob().coalBag.container.hasCapacityFor(new Item(oreId))) {
137 getMob().coalBag.container.add(new Item(oreId));
138 } else {
139 getMob().inventory.add(oreId, 1);
140 }
141 getMob().skills.addExperience(Skill.MINING, ore.experience * Config.MINING_MODIFICATION);
142 getMob().message("You receive an additional ore from your Celestial ring.");
143 }
144
145 //always remove a charge, even if additional ore is not received
146 getMob().celestialRingCharges--;
147 }
148
149 @Override
150 protected boolean canSchedule() {
151 return !getMob().skills.get(Skill.MINING).isDoingSkill();
152 }
153
154 @Override
155 protected void onSchedule() {
156 if (!object.getGenericAttributes().has("ores")) {
157 object.getGenericAttributes().set("ores", ore.oreCount);
158 }
159
160 getMob().animate(pickaxe.animation);
161 }
162
163 @Override
164 public void execute() {
165 if (!getMob().skills.get(Skill.MINING).isDoingSkill()) {
166 cancel();
167 return;
168 }
169 if (object == null || !object.active() || object.getGenericAttributes() == null) {
170 cancel();
171 return;
172 }
173
174 if (!mine()) {
175 cancel();
176 }
177 }
178
179 @Override
180 protected void onCancel(boolean logout) {
181 getMob().resetFace();
182 getMob().skills.get(Skill.MINING).setDoingSkill(false);
183 }
184
185 @Override
189
190 @Override
191 public String getName() {
192 return "mining-action";
193 }
194}
static final double MINING_MODIFICATION
Definition Config.java:313
static final double SMITHING_MODIFICATION
Definition Config.java:331
static void activate(Player player, AchievementKey achievement)
static void onReward(Player player, int item, int chance)
Definition Pets.java:70
Action(T mob, int delay, boolean instant)
Definition Action.java:24
synchronized final void cancel()
Definition Task.java:147
static void schedule(Task task)
Definition World.java:284
static String getAOrAn(String nextWord)
Definition Utility.java:153