RuneHive-Game
Loading...
Searching...
No Matches
MiningAction.java
Go to the documentation of this file.
1package com.runehive.content.skill.impl.mining;
2
3import com.runehive.Config;
4import com.runehive.content.achievement.AchievementHandler;
5import com.runehive.content.achievement.AchievementKey;
6import com.runehive.content.activity.randomevent.RandomEventHandler;
7import com.runehive.content.clanchannel.content.ClanTaskKey;
8import com.runehive.content.pet.PetData;
9import com.runehive.content.pet.Pets;
10import com.runehive.content.prestige.PrestigePerk;
11import com.runehive.content.skill.impl.smithing.SmeltingData;
12import com.runehive.content.skillcape.SkillCape;
13import com.runehive.game.Animation;
14import com.runehive.game.action.Action;
15import com.runehive.game.action.policy.WalkablePolicy;
16import com.runehive.game.task.impl.ObjectReplacementEvent;
17import com.runehive.game.world.World;
18import com.runehive.game.world.entity.mob.player.Player;
19import com.runehive.game.world.entity.skill.Skill;
20import com.runehive.game.world.items.Item;
21import com.runehive.game.world.items.containers.equipment.Equipment;
22import com.runehive.game.world.object.GameObject;
23import com.runehive.game.world.position.Area;
24import com.runehive.net.packet.out.SendMessage;
25import com.runehive.util.RandomUtils;
26import com.runehive.util.Utility;
27
28
29/**
30 * Created by Daniel on 2017-12-18.
31 */
32public class MiningAction extends Action<Player> {
33 private final GameObject object;
34 private final OreData ore;
35 private final PickaxeData pickaxe;
36
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);
88
89 if (ore == OreData.RUNITE) {
90 getMob().forClan(channel -> channel.activateTask(ClanTaskKey.RUNITE_ORES, getMob().getName()));
91 }
92
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}
The class that contains setting-related constants for the server.
Definition Config.java:24
static final double MINING_MODIFICATION
The experience modification for mining.
Definition Config.java:271
static final double SMITHING_MODIFICATION
The experience modification for smithing.
Definition Config.java:289
static void activate(Player player, AchievementKey achievement)
Activates the achievement for the individual player.
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
String getName()
Gets the name of this action.
WalkablePolicy getWalkablePolicy()
Gets the WalkablePolicy of this action.
boolean canSchedule()
A function executed on registration.
void onCancel(boolean logout)
A function executed on cancellation.
void onSchedule()
A function executed on registration.
void execute()
A function representing the unit of work that will be carried out.
MiningAction(Player player, GameObject object, OreData ore, PickaxeData pickaxe)
static final Chance< Item > GEM_ITEMS
Definition Mining.java:23
static boolean success(Player player, OreData ore, PickaxeData pickaxe)
Definition Mining.java:126
Class that models a single animation used by an entity.
static final Animation RESET
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
An randomevent which replaces an object with another object.
Represents the game world.
Definition World.java:46
static void schedule(Task task)
Submits a new event.
Definition World.java:247
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 SMITHING
The smithing skill id.
Definition Skill.java:60
static final int MINING
The mining skill id.
Definition Skill.java:63
The container class that represents an item that can be interacted with.
Definition Item.java:21
final int getId()
Gets the identification of this item.
Definition Item.java:324
The container that manages the equipment for a player.
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.
A static-util class that provides additional functionality for generating pseudo-random numbers.
static boolean success(double value)
Determines if a pseudorandomly generated double rounded to two decimal places is below or equal to va...
Handles miscellaneous methods.
Definition Utility.java:27
static int random(int bound)
Definition Utility.java:239
static boolean hasOneOutOf(double chance)
Definition Utility.java:257
static String getAOrAn(String nextWord)
A or an.
Definition Utility.java:116
Holds the data for pets.
Definition PetData.java:14
Handles the perk rewards from prestiging.
The enumerated type whose elements represent definitions for each smeltable bar.
final Item[] produced
he produced items for smelting the required items.
static boolean isEquipped(Player player, SkillCape cape)
A queue policy determines whether the action can occur while walking.
NON_WALKABLE
This indicates actions cannot occur while walking.