RuneHive-Game
Loading...
Searching...
No Matches
BoneSacrifice.java
Go to the documentation of this file.
1package com.runehive.content.skill.impl.prayer;
2
3import com.runehive.Config;
4import com.runehive.content.skillcape.SkillCape;
5import com.runehive.content.activity.randomevent.RandomEventHandler;
6import com.runehive.content.dialogue.ChatBoxItemDialogue;
7import com.runehive.content.event.impl.ItemInteractionEvent;
8import com.runehive.content.event.impl.ItemOnObjectInteractionEvent;
9import com.runehive.game.Animation;
10import com.runehive.game.Graphic;
11import com.runehive.game.action.Action;
12import com.runehive.game.action.impl.BuryBoneAction;
13import com.runehive.game.action.impl.ScatterAshAction;
14import com.runehive.game.action.policy.WalkablePolicy;
15import com.runehive.game.world.World;
16import com.runehive.game.world.entity.mob.player.Player;
17import com.runehive.game.world.entity.skill.Skill;
18import com.runehive.game.world.items.Item;
19import com.runehive.game.world.items.ItemDefinition;
20import com.runehive.game.world.object.GameObject;
21import com.runehive.game.world.position.Position;
22import com.runehive.net.packet.out.SendInputAmount;
23import com.runehive.net.packet.out.SendMessage;
24import com.runehive.util.Utility;
25
26/**
27 * Handles sacrificing bones to an altar.
28 *
29 * @author Daniel
30 */
31public class BoneSacrifice extends Skill {
32
33 public BoneSacrifice(int level, double experience) {
34 super(Skill.PRAYER, level, experience);
35 }
36
37 @Override
38 protected double modifier() {
40 }
41
42 @Override
43 protected boolean clickItem(Player player, ItemInteractionEvent event) {
44 if (event.getOpcode() != 0)
45 return false;
46 Item item = event.getItem();
47 int slot = event.getSlot();
48 if (!BoneData.forId(item.getId()).isPresent() && !AshData.forId(item.getId()).isPresent())
49 return false;
50 if (AshData.forId(item.getId()).isPresent()) {
51 AshData ashes = AshData.forId(item.getId()).get();
52 new ScatterAshAction(player, ashes, slot).start();
53 return true;
54 }
55 BoneData bone = BoneData.forId(item.getId()).get();
56 new BuryBoneAction(player, bone, slot).start();
57 return true;
58 }
59
60 @Override
61 protected boolean useItem(Player player, ItemOnObjectInteractionEvent event) {
62 Item item = event.getItem();
63 GameObject object = event.getObject();
64 if (object.getId() != 409 && object.getId() != 411) {
65 return false;
66 }
67 if (!BoneData.forId(item.getId()).isPresent())
68 return false;
69 BoneData bone = BoneData.forId(item.getId()).get();
70
71 if (player.inventory.computeAmountForId(bone.getId()) == 0) {
72 player.action.execute(sacrifice(player, object.getPosition(), bone, 1), true);
73 } else {
74 ChatBoxItemDialogue.sendInterface(player, 1746, bone.getId(), 0, -5, 170);
75 player.chatBoxItemDialogue = new ChatBoxItemDialogue(player) {
76 @Override
77 public void firstOption(Player player) {
78 player.action.execute(sacrifice(player, object.getPosition(), bone, 1), true);
79 }
80
81 @Override
82 public void secondOption(Player player) {
83 player.action.execute(sacrifice(player, object.getPosition(), bone, 5), true);
84 }
85
86 @Override
87 public void thirdOption(Player player) {
88 player.send(new SendInputAmount("Enter the amount of bones you would like to sacrifice", 10, input -> player.action.execute(sacrifice(player, object.getPosition(), bone, Integer.parseInt(input)), true)));
89 }
90
91 @Override
92 public void fourthOption(Player player) {
93 player.action.execute(sacrifice(player, object.getPosition(), bone, 28), true);
94 }
95 };
96 }
97 return true;
98 }
99
100 private Action<Player> sacrifice(Player player, Position position, BoneData bone, int amount) {
101 return new Action<Player>(player, 4, true) {
102 int ticks = 0;
103
104 @Override
105 public void execute() {
106 if (!player.inventory.contains(bone.getId())) {
107 cancel();
108 return;
109 }
110 Graphic graphic = new Graphic(624, true);
111 World.sendGraphic(graphic, position, player.instance);
112 player.animate(new Animation(645, 5));
113 if (player.getPosition().inLocation(Position.create(2946, 3816), Position.create(2959, 3831), true)) {
114 int rnd = Utility.random(100);
115 if (rnd <= 50) {
116 player.send(new SendMessage("You sacrifice the " + ItemDefinition.get(bone.getId()).getName() + " ."));
117 player.inventory.remove(bone.getId(), 1);
118 }
119 if (rnd > 50) {
120 player.message("You've saved a bone due to sacrificing in the wilderness..");
121 }
122 } else {
123 player.inventory.remove(bone.getId(), 1);
124 }
125
126 double exp = bone.getExperience() * (modifier() * 1.8);
127 if (SkillCape.isEquipped(player, SkillCape.PRAYER)) {
128 exp *= 2.0;
129 }
130
131 player.skills.addExperience(Skill.PRAYER, exp);
133 if (++ticks == amount) {
134 cancel();
135 }
136 }
137
138 @Override
139 public String getName() {
140 return "Bone sacrifice";
141 }
142
143 @Override
144 public boolean prioritized() {
145 return false;
146 }
147
148 @Override
149 public WalkablePolicy getWalkablePolicy() {
151 }
152 };
153 }
154
155}
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 sendInterface(Player player, int interfaceId, Item item, int zoom)
final void start()
Attempts to start the skill.
boolean useItem(Player player, ItemOnObjectInteractionEvent event)
Action< Player > sacrifice(Player player, Position position, BoneData bone, int amount)
boolean clickItem(Player player, ItemInteractionEvent event)
Class that models a single animation used by an entity.
Represents a single graphic that can be used by entities.
Definition Graphic.java:10
Represents an action an entity can execute.
Definition Action.java:12
public< A extends Action<?> > void execute(A action)
Represents the game world.
Definition World.java:46
static void sendGraphic(Graphic graphic, Position position, int instance)
Sends a graphic to the world.
Definition World.java:268
This class represents a character controlled by a player.
Definition Player.java:125
static String getName(int skill)
Gets the name for a skill id.
Definition Skill.java:465
double experience
The current skill experience.
Definition Skill.java:179
int level
The current level of the skill.
Definition Skill.java:173
Skill(int skill, int level, double experience)
Constructs a new Skill.
Definition Skill.java:184
void addExperience(int id, double experience)
Adds experience to a given skill.
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
final int getId()
Gets the identification of this item.
Definition Item.java:324
final int computeAmountForId(int id)
Computes the total quantity of the Items in this container with id.
boolean remove(Item item)
Attempts to withdraw item from this container.
boolean contains(int id)
Determines if this container contains id.
Represents a single tile on the game world.
Definition Position.java:14
boolean inLocation(Position southWest, Position northEast, boolean inclusive)
static Position create(int x, int y, int z)
Creates a location.
The OutgoingPacket that sends a message to a Players chatbox in the client.
Handles miscellaneous methods.
Definition Utility.java:27
static int random(int bound)
Definition Utility.java:239
static Optional< AshData > forId(int id)
Definition AshData.java:32
static Optional< BoneData > forId(int id)
Gets the bone data based on the item.
Definition BoneData.java:59
int getId()
Gets the id of the bone.
Definition BoneData.java:42
double getExperience()
Gets the experience of the bone.
Definition BoneData.java:50
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.