RuneHive-Game
Loading...
Searching...
No Matches
ChestAction.java
Go to the documentation of this file.
1package com.runehive.game.action.impl;
2
3import com.runehive.content.ActivityLog;
4import com.runehive.game.world.items.Item;
5import com.runehive.net.packet.out.SendMessage;
6import com.runehive.game.Animation;
7import com.runehive.game.action.Action;
8import com.runehive.game.action.policy.WalkablePolicy;
9import com.runehive.game.world.entity.mob.player.Player;
10import com.runehive.content.achievement.AchievementHandler;
11import com.runehive.content.achievement.AchievementKey;
12
13/**
14 * Handles opening a chest.
15 *
16 * @author Daniel
17 */
18public final class ChestAction extends Action<Player> {
19 private final int key;
20 private final Item[] items;
21
22 public ChestAction(Player player, int key, Item... items) {
23 super(player, 1);
24 this.key = key;
25 this.items = items;
26 }
27
28 @Override
29 protected boolean canSchedule() {
30 if (!getMob().inventory.hasCapacityFor(items)) {
31 getMob().message("You do not have enough free inventory spaces to do this!");
32 return false;
33 }
34 return true;
35 }
36
37 @Override
38 protected void onSchedule() {
39 getMob().locking.lock(2);
40 getMob().inventory.remove(key, 1);
41 getMob().animate(new Animation(881));
42 getMob().send(new SendMessage("You attempt to unlock the chest..."));
43 }
44
45 @Override
46 public void execute() {
47 cancel();
48 }
49
50 @Override
51 protected void onCancel(boolean logout) {
52 getMob().inventory.addOrDrop(items);
53 getMob().send(new SendMessage("...you find a few items inside of the chest.", true));
54
55 if (key == 989) {
56 getMob().activityLogger.add(ActivityLog.CRYSTAL_CHEST);
58 } else if (key == 20608) {
59 getMob().activityLogger.add(ActivityLog.BLOOD_MONEY_CHEST);
60 }
61 }
62
63 @Override
64 public String getName() {
65 return "chest action";
66 }
67
68 @Override
69 public boolean prioritized() {
70 return false;
71 }
72
73 @Override
77}
static void activate(Player player, AchievementKey achievement)
Activates the achievement for the individual player.
Class that models a single animation used by an entity.
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
WalkablePolicy getWalkablePolicy()
Gets the WalkablePolicy of this action.
void execute()
A function representing the unit of work that will be carried out.
void onSchedule()
A function executed on registration.
String getName()
Gets the name of this action.
boolean canSchedule()
A function executed on registration.
ChestAction(Player player, int key, Item... items)
boolean prioritized()
Determines if this action is prioritized.
void onCancel(boolean logout)
A function executed on cancellation.
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
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 activity log class.
A queue policy determines whether the action can occur while walking.
NON_WALKABLE
This indicates actions cannot occur while walking.