RuneHive-Game
Loading...
Searching...
No Matches
DestructionSkillAction.java
Go to the documentation of this file.
1package com.runehive.content.skill.impl;
2
3import com.runehive.net.packet.out.SendMessage;
4import com.runehive.game.action.policy.WalkablePolicy;
5import com.runehive.game.world.entity.mob.Mob;
6import com.runehive.content.skill.SkillAction;
7import com.runehive.game.world.items.Item;
8import com.runehive.game.world.items.ItemDefinition;
9import com.runehive.game.world.position.Position;
10import com.runehive.util.RandomGen;
11
12import java.util.Optional;
13
14/**
15 * The skill action that represents an action where one item is removed from an
16 * inventory and lost forever. This type of skill action is very basic and only
17 * requires that a player have the item to destruct in their inventory.
18 * <p>
19 * <p>
20 * The skills that may use this type skill action include, but are not limited
21 * to {@code PRAYER}.
22 * @author lare96 <http://github.com/lare96>
23 * @see SkillAction
24 * @see HarvestingSkillAction
25 */
26public abstract class DestructionSkillAction extends SkillAction {
27
28 private static final int SUCCESS_FACTOR = 10;
29 private final RandomGen random = new RandomGen();
30
31 /**
32 * Creates a new {@link DestructionSkillAction}.
33 * @param mob the mob this skill action is for.
34 * @param position the position the player should face.
35 * @param instant determines if this task should run instantly.
36 */
37 public DestructionSkillAction(Mob mob, Optional<Position> position, boolean instant) {
38 super(mob, position, instant);
39 }
40
41 @Override
42 public boolean canRun() {
43 String name = ItemDefinition.get(destructItem().getId()).getName();
44 if(getMob().isPlayer() && !getMob().getPlayer().inventory.contains(destructItem().getId())) {
45 getMob().getPlayer().send(new SendMessage("You do not have any " + name + " in your inventory."));
46 return false;
47 }
48 return true;
49 }
50
51 public abstract double successFactor();
52
53 @Override
54 public final void onExecute() {
55 int factor = (getMob().skills.getSkills()[skill()].getLevel() / SUCCESS_FACTOR);
56 double boost = (factor * 0.01);
57 if (random.success((successFactor() + boost))) {
58 if(getMob().isPlayer()) {
59 onDestruct(true);
60 getMob().skills.addExperience(skill(), experience());
61 this.cancel();
62 return;
63 }
64 } else {
65 onDestruct(false);
66 }
67 }
68
69 @Override
73
74 /**
75 * The method executed upon destruction of the item.
76 * @param success determines if the destruction was successful or not.
77 */
78 public void onDestruct(boolean success) {
79
80 }
81
82 /**
83 * The item that will be removed upon destruction.
84 * @return the item that will be removed.
85 */
86 public abstract Item destructItem();
87
88 @Override
89 public boolean prioritized() {
90 return false;
91 }
92}
SkillAction(Mob mob, Optional< Position > position, int delay, boolean instant)
Creates a new Action randomevent.
final Optional< Position > position
The position we should face.
abstract double experience()
The experience given from this action.
abstract int skill()
The skill we should hand to experience to.
final WalkablePolicy getWalkablePolicy()
Gets the WalkablePolicy of this action.
DestructionSkillAction(Mob mob, Optional< Position > position, boolean instant)
Creates a new DestructionSkillAction.
boolean prioritized()
Determines if this action is prioritized.
void onDestruct(boolean success)
The method executed upon destruction of the item.
abstract Item destructItem()
The item that will be removed upon destruction.
final void onExecute()
The method which is called on intervals of the specified #delay;.
boolean canRun()
Determines if the task can be ran.
T getMob()
Gets the player.
Definition Action.java:44
final T mob
The Mob associated with this ActionEvent.
Definition Action.java:15
synchronized final void cancel()
Cancels all subsequent executions.
Definition Task.java:113
final boolean instant
If execution happens instantly upon being scheduled.
Definition Task.java:14
Handles the mob class.
Definition Mob.java:66
Represents all of an in-game Item's attributes.
static ItemDefinition get(int id)
Gets an item definition.
The container class that represents an item that can be interacted with.
Definition Item.java:21
The OutgoingPacket that sends a message to a Players chatbox in the client.
The ThreadLocalRandom wrapper that provides additional functionality for generating pseudo-random num...
A queue policy determines whether the action can occur while walking.
NON_WALKABLE
This indicates actions cannot occur while walking.