RuneHive-Game
Loading...
Searching...
No Matches
BuryBoneAction.java
Go to the documentation of this file.
1package com.runehive.game.action.impl;
2
3import com.runehive.Config;
4import com.runehive.content.skillcape.SkillCape;
5import com.runehive.content.achievement.AchievementHandler;
6import com.runehive.content.achievement.AchievementKey;
7import com.runehive.content.skill.SkillAction;
8import com.runehive.content.skill.impl.prayer.BoneData;
9import com.runehive.game.Animation;
10import com.runehive.game.action.policy.WalkablePolicy;
11import com.runehive.game.world.entity.mob.player.Player;
12import com.runehive.game.world.entity.skill.Skill;
13import com.runehive.game.world.items.Item;
14import com.runehive.net.packet.out.SendMessage;
15
16import java.util.Optional;
17
18/**
19 * Handles burying a bone.
20 *
21 * @author Michael | Chex
22 */
23public final class BuryBoneAction extends SkillAction {
24 private final int slot;
25 private final Item item;
26 private final BoneData bone;
27
28 public BuryBoneAction(Player player, BoneData bone, int slot) {
29 super(player, Optional.empty(), true);
30 this.slot = slot;
31 this.bone = bone;
32 this.item = player.inventory.get(slot);
33 }
34
35 @Override
36 public boolean canInit() {
37 return getMob().skills.getSkills()[skill()].stopwatch.elapsed(1200);
38 }
39
40 @Override
41 public void init() {
42
43 }
44
45 @Override
46 public void onExecute() {
47 getMob().animate(new Animation(827));
48 Player player = getMob().getPlayer();
49 player.inventory.remove(item, slot, true);
51 player.send(new SendMessage("You bury the " + item.getName() + "."));
53
54 if (player.equipment.hasAmulet() && player.equipment.getAmuletSlot().getId() == 22111) {
55 int current = player.skills.getLevel(Skill.PRAYER);
56 int maximum = player.skills.getMaxLevel(Skill.PRAYER);
57
58 if (current < maximum) {
59 int points = bone.getBoneAmulet();
60
61 if (current + points > maximum) {
62 points = maximum - current;
63 }
64
65 player.skills.get(Skill.PRAYER).addLevel(points);
66 player.skills.refresh(Skill.PRAYER);
67 player.message("You feel your " + player.equipment.getAmuletSlot().getName() + " vibrate as you bury the bone.");
68 }
69 }
70
71 cancel();
72 }
73
74 @Override
75 public void onCancel(boolean logout) {
76 getMob().skills.getSkills()[skill()].stopwatch.reset();
77 }
78
79 @Override
80 public Optional<SkillAnimation> animation() {
81 return Optional.empty();
82 }
83
84 @Override
85 public double experience() {
86 double exp = (bone.getExperience() * Config.PRAYER_MODIFICATION);
87 if (SkillCape.isEquipped(getMob().getPlayer(), SkillCape.PRAYER)) {
88 exp *= 2.0;
89 }
90 return exp;
91 }
92
93 @Override
94 public int skill() {
95 return Skill.PRAYER;
96 }
97
98 @Override
99 public String getName() {
100 return "Bone bury";
101 }
102
103 @Override
104 public boolean prioritized() {
105 return false;
106 }
107
108 @Override
112}
The class that contains setting-related constants for the server.
Definition Config.java:24
static final double PRAYER_MODIFICATION
The experience modification for prayer.
Definition Config.java:274
static void activate(Player player, AchievementKey achievement)
Activates the achievement for the individual player.
SkillAction(Mob mob, Optional< Position > position, int delay, boolean instant)
Creates a new Action randomevent.
Class that models a single animation used by an entity.
T getMob()
Gets the player.
Definition Action.java:44
int skill()
The skill we should hand to experience to.
double experience()
The experience given from this action.
void onCancel(boolean logout)
A function executed on cancellation.
boolean prioritized()
Determines if this action is prioritized.
boolean canInit()
Determines if this action can be initialized.
WalkablePolicy getWalkablePolicy()
Gets the WalkablePolicy of this action.
void init()
Any functionality that should be handled when this action is submitted.
String getName()
Gets the name of this action.
Optional< SkillAnimation > animation()
The skill animation to execute.
void onExecute()
The method which is called on intervals of the specified #delay;.
BuryBoneAction(Player player, BoneData bone, int slot)
synchronized final void cancel()
Cancels all subsequent executions.
Definition Task.java:113
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 PRAYER
The prayer skill id.
Definition Skill.java:36
void addLevel(int amount)
Adds levels to this skill by the given amount.
Definition Skill.java:316
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.
void refresh()
Refreshes all the skills for the mob.
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
boolean remove(Item item)
Attempts to withdraw item from this container.
final Item get(int index)
Gets the Item located on index.
The OutgoingPacket that sends a message to a Players chatbox in the client.
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.