RuneHive-Game
Loading...
Searching...
No Matches
SlayerOfferings.java
Go to the documentation of this file.
1package com.runehive.content.skill.impl.slayer;
2
3import com.runehive.Config;
4import com.runehive.game.world.entity.mob.player.Player;
5import com.runehive.game.world.entity.skill.Skill;
6import com.runehive.game.world.items.Item;
7import com.runehive.util.Utility;
8
9/**
10 * Handles selling offering slayer rewards.
11 *
12 * @author Daniel
13 */
14public class SlayerOfferings {
15
16 public static void offer(Player player) {
17 int points = 0;
18 double experience = 0;
19
20 for (Item item : player.inventory) {
21 if (item == null)
22 continue;
23 OfferingData offering = OfferingData.forItem(item.getId());
24 if (offering == null)
25 continue;
26 points += offering.getPoints();
27 experience += offering.getExperience();
28 }
29
30 if (points == 0 && experience == 0) {
31 player.dialogueFactory.sendNpcChat(6797, "You have no offerings for me!").execute();
32 return;
33 }
34
35 player.dialogueFactory.sendNpcChat(6797, "I will give you " + points + " slayer points &", Utility.formatDigits(experience) + " experience for your offerings.", "Do you accept?");
36 player.dialogueFactory.sendOption("Yes", () -> confirm(player),"No", () -> player.dialogueFactory.clear());
37 player.dialogueFactory.execute();
38 }
39
40 private static void confirm(Player player) {
41 int points = 0;
42 double experience = 0;
43
44 for (Item item : player.inventory) {
45 if (item == null)
46 continue;
47 OfferingData offering = OfferingData.forItem(item.getId());
48 if (offering == null)
49 continue;
50 points += offering.getPoints();
51 experience += offering.getExperience();
52 player.inventory.remove(item);
53 }
54
55 player.message("Your offerings were accepted!");
56 player.slayer.setPoints(player.slayer.getPoints() + points);
57 player.skills.addExperience(Skill.SLAYER, experience);
58 player.dialogueFactory.clear();
59 }
60
61 public enum OfferingData {
62 ANCIENT_SHARD(19677, 1, 1350),
63 TOTEM_BASE(19679, 1, 1350),
64 TOTEM_MIDDLE(19681, 1, 1350),
65 TOTEM_TOP(19683, 1, 1350),
66 TOTEM(19685, 1, 1350),
67 ENSOULED_GOBLIN_HEAD(13447, 1, 1000),
68 ENSOULED_GOBLIN_HEAD_II(13448, 1, 1000),
69 ENSOULED_MONKEY_HEAD(13450, 1, 1000),
70 ENSOULED_MONKEY_HEAD_II(13451, 1, 1000),
71 ENSOULED_IMP_HEAD(13453, 1, 1000),
72 ENSOULED_IMP_HEAD_II(13454, 1, 1000),
73 ENSOULED_MINOTAUR_HEAD(13456, 1, 1000),
75 ENSOULED_SCORPION_HEAD(13459, 1, 1000),
77 ENSOULED_BEAR_HEAD(13462, 1, 1000),
78 ENSOULED_BEAR_HEAD_II(13463, 1, 1000),
79 ENSOULED_UNICORN_HEAD(13465, 1, 1000),
80 ENSOULED_UNICORN_HEAD_II(13466, 1, 1000),
81 ENSOULED_DOG_HEAD(13468, 1, 1000),
82 ENSOULED_DOG_HEAD_II(13469, 1, 1000),
85 ENSOULED_GIANT_HEAD(13474, 1, 1000),
86 ENSOULED_GIANT_HEAD_II(13475, 1, 1000),
87 ENSOULED_OGRE_HEAD(13477, 1, 1000),
88 ENSOULED_OGRE_HEAD_II(13478, 1, 1000),
89 ENSOULED_ELF_HEAD(13480, 1, 1000),
90 ENSOULED_ELF_HEAD_II(13481, 1, 1000),
91 ENSOULED_TROLL_HEAD(13483, 1, 1000),
92 ENSOULED_TROLL_HEAD_II(13484, 1, 1000),
93 ENSOULED_HORROR_HEAD(13486, 1, 1000),
94 ENSOULED_HORROR_HEAD_II(13487, 1, 1000),
95 ENSOULED_KALPHITE_HEAD(13489, 1, 1000),
97 ENSOULED_DAGANNOTH_HEAD(13492, 1, 1000),
99 ENSOULED_BLOODVELD_HEAD(13495, 1, 1000),
101 ENSOULED_TZHAAR_HEAD(13498, 1, 1000),
102 ENSOULED_TZHAAR_HEAD_II(13499, 1, 1000),
103 ENSOULED_DEMON_HEAD(13501, 1, 1000),
104 ENSOULED_DEMON_HEAD_II(13502, 1, 1000),
105 ENSOULED_AVIANSIE_HEAD(13504, 1, 1000),
107 ENSOULED_ABYSSAL_HEAD(13507, 1, 1000),
109 ENSOULED_DRAGON_HEAD(13511, 1, 1000),
110 ENSOULED_DRAGON_HEAD_II(13510, 1, 1000);
111
112 private final int item;
113 private final int points;
114 private final int experience;
115
116 /** Constructs a new <code>OfferingData<code>. */
118 this.item = item;
119 this.points = points;
120 this.experience = experience;
121 }
122
123 public int getItem() {
124 return item;
125 }
126
127 public int getPoints() {
128 return points;
129 }
130
131 public double getExperience() {
132 return experience;
133 }
134
135 public static OfferingData forItem(int item) {
136 for (OfferingData offering : values()) {
137 if (offering.getItem() == item)
138 return offering;
139 }
140 return null;
141 }
142 }
143}
final DialogueFactory execute()
Retrieves the next dialogue in the chain and executes it.
void clear()
Clears the current dialogue chain.
final DialogueFactory sendNpcChat(int id, String... lines)
Appends an NpcDialogue to the current dialogue chain.
final DialogueFactory sendOption(String option1, Runnable action1, String option2, Runnable action2)
Appends the OptionDialogue onto the current dialogue chain.
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 SLAYER
The slayer skill id.
Definition Skill.java:75
void addExperience(int id, double experience)
Adds experience to a given skill.
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.
Handles miscellaneous methods.
Definition Utility.java:27
static String formatDigits(final int amount)
Formats digits for integers.
Definition Utility.java:41
OfferingData(int item, int points, int experience)
Constructs a new OfferingData.