RuneHive-Game
Loading...
Searching...
No Matches
Runecraft.java
Go to the documentation of this file.
1package com.runehive.content.skill.impl.runecrafting;
2
3import com.runehive.Config;
4import com.runehive.content.achievement.AchievementHandler;
5import com.runehive.content.achievement.AchievementKey;
6import com.runehive.content.activity.randomevent.RandomEventHandler;
7import com.runehive.content.clanchannel.content.ClanTaskKey;
8import com.runehive.content.event.impl.ItemInteractionEvent;
9import com.runehive.content.event.impl.ObjectInteractionEvent;
10import com.runehive.content.pet.PetData;
11import com.runehive.content.pet.Pets;
12import com.runehive.game.Animation;
13import com.runehive.game.Graphic;
14import com.runehive.game.world.World;
15import com.runehive.game.world.entity.mob.player.Player;
16import com.runehive.game.world.entity.skill.Skill;
17import com.runehive.game.world.items.Item;
18import com.runehive.game.world.object.GameObject;
19import com.runehive.net.packet.out.SendMessage;
20import com.runehive.util.Utility;
21
22/**
23 * Handles the runecrafting skill.
24 *
25 * @author Daniel
26 */
27public class Runecraft extends Skill {
28
29 public Runecraft(int level, double experience) {
30 super(Skill.RUNECRAFTING, level, experience);
31 }
32
33 @Override
34 protected double modifier() {
36 }
37
38 @Override
39 protected boolean clickItem(Player player, ItemInteractionEvent event) {
40 Item item = event.getItem();
41
43
44 if (pouch == null) {
45 return false;
46 }
47
48 int opcode = event.getOpcode();
49
50 switch (opcode) {
51 case 0:
52 player.runecraftPouch.deposit(pouch);
53 break;
54 case 1:
55 player.runecraftPouch.withdraw(pouch);
56 break;
57 }
58 return true;
59 }
60
61 @Override
62 protected boolean clickObject(Player player, ObjectInteractionEvent event) {
63
64 if (event.getOpcode() != 0) {
65 return false;
66 }
67
68 GameObject object = event.getObject();
69
70 if (click(player, object)) {
71 return true;
72 }
73
74 if (!RunecraftData.forId(object.getId()).isPresent()) {
75 return false;
76 }
77
78 RunecraftData rune = RunecraftData.forId(object.getId()).get();
79
80 int essence = getEssence(player);
81
82 if (player.skills.getLevel(Skill.RUNECRAFTING) < rune.getLevel()) {
83 player.send(new SendMessage("You need a runecrafting level of " + rune.getLevel() + " to do this!"));
84 return true;
85 }
86
87 if (essence == -1) {
88 player.send(new SendMessage("You do not have any essence!"));
89 return true;
90 }
91
92 int amount = player.inventory.computeAmountForId(essence);
93 int multiplier = multiplier(player, rune);
94
95 player.locking.lock(2);
96
97 if (rune == RunecraftData.OURNIA) {
98 player.animate(new Animation(791));
99 player.graphic(new Graphic(186));
100 player.inventory.remove(new Item(essence, amount), -1, true);
101
102 World.schedule(1, () -> {
103 for (int index = 0; index < amount; index++) {
105
106 while (data == RunecraftData.OURNIA) {
107 data = Utility.randomElement(RunecraftData.values());
108 }
109
110 player.inventory.add(data.getRunes(), multiplier(player, data) * 2);
111 player.skills.addExperience(Skill.RUNECRAFTING, data.getExperience() * modifier());
112 }
113
116 Pets.onReward(player, PetData.RIFT_GUARDIAN.getItem(), 9000);
118 });
119 return true;
120 }
121
122 craft(player, essence, amount, rune);
123
124 World.schedule(1, () -> {
125 player.inventory.add(rune.getRunes(), amount * multiplier);
127 Pets.onReward(player, PetData.RIFT_GUARDIAN.getItem(), 9000);
129 });
130 return true;
131 }
132
133
134 private void craft(Player player, int essence, int amount, RunecraftData rune) {
135 if (player.skills.getLevel(Skill.RUNECRAFTING) < rune.getLevel()) {
136 player.send(new SendMessage("You need a runecrafting level of " + rune.getLevel() + " to do this!"));
137 return;
138 }
139
140 if (essence == -1) {
141 player.send(new SendMessage("You do not have any essence!"));
142 return;
143 }
144 player.animate(new Animation(791));
145 player.graphic(new Graphic(186));
146 player.inventory.remove(new Item(essence, amount), -1, true);
147 player.skills.addExperience(Skill.RUNECRAFTING, (rune.getExperience() * amount) * modifier());
149
150 if (rune == RunecraftData.BLOOD) {
151 player.forClan(channel -> channel.activateTask(ClanTaskKey.BLOOD_RUNE, player.getName(), amount));
152 } else if (rune == RunecraftData.DEATH) {
153 player.forClan(channel -> channel.activateTask(ClanTaskKey.DEATH_RUNE, player.getName(), amount));
154 }
155 }
156
157 /** Handles teleporting to various runecrafting altars. */
158 private boolean click(Player player, GameObject object) {
159 if (!RunecraftTeleport.forId(object.getId()).isPresent()) {
160 return false;
161 }
162
163 RunecraftTeleport teleport = RunecraftTeleport.forId(object.getId()).get();
164 player.move(teleport.getPosition());
165 System.out.println("reached here");
166 return true;
167 }
168
169 /** Gets the essence identification from player. */
170 private int getEssence(Player player) {
171 return player.inventory.contains(1436) ? 1436 : (player.inventory.contains(7936) ? 7936 : -1);
172 }
173
174 /** The runecrafting multiplier. */
175 private int multiplier(Player player, RunecraftData rune) {
176 int multiplier = 1;
177 for (int i = 0; i < rune.getMultiplier().length; i++) {
178 if (player.skills.getLevel(Skill.RUNECRAFTING) >= rune.getMultiplier()[i]) {
179 multiplier++;
180 }
181 }
182 return multiplier;
183 }
184}
The class that contains setting-related constants for the server.
Definition Config.java:24
static final double RUNECRAFTING_MODIFICATION
The experience modification for runecrafting.
Definition Config.java:277
static void activate(Player player, AchievementKey achievement)
Activates the achievement for the individual player.
Handles spawning, rewarding and picking up of pets.
Definition Pets.java:27
static void onReward(Player player, int item, int chance)
Handles calculating the chance of a player receiving a skilling pet.
Definition Pets.java:33
void craft(Player player, int essence, int amount, RunecraftData rune)
boolean clickItem(Player player, ItemInteractionEvent event)
boolean click(Player player, GameObject object)
Handles teleporting to various runecrafting altars.
int getEssence(Player player)
Gets the essence identification from player.
int multiplier(Player player, RunecraftData rune)
The runecrafting multiplier.
boolean clickObject(Player player, ObjectInteractionEvent event)
void deposit(RunecraftPouchData pouch)
Deposits essence into the player's runecraft pouch.
void withdraw(RunecraftPouchData pouch)
Withdraws essence from the player's rune essence pouch.
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 the game world.
Definition World.java:46
static void schedule(Task task)
Submits a new event.
Definition World.java:247
void move(Position position)
Moves the mob to a set position.
Definition Mob.java:340
Optional< Graphic > graphic
Definition Mob.java:91
This class represents a character controlled by a player.
Definition Player.java:125
void forClan(Consumer< ClanChannel > action)
Definition Player.java:568
String getName()
Gets the name of this entity.
Definition Player.java:774
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.
int getLevel(int id)
Gets the level of a 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
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 add(Item item)
Attempts to deposit item into this container.
boolean contains(int id)
Determines if this container contains id.
The OutgoingPacket that sends a message to a Players chatbox in the client.
Handles miscellaneous methods.
Definition Utility.java:27
static< T > T randomElement(Collection< T > collection)
Picks a random element out of any array type.
Definition Utility.java:248
Holds the data for pets.
Definition PetData.java:14
double getExperience()
Gets the experience rewarded.
static Optional< RunecraftData > forId(int id)
Gets the runecrafting data based on the object.
static RunecraftPouchData forItem(int item)
Gets the runecrafting pouch data based on the item identification.
static Optional< RunecraftTeleport > forId(int id)
Gets the runecrafting teleport data based on the object identification.