RuneHive-Game
Loading...
Searching...
No Matches
FiremakingAction.java
Go to the documentation of this file.
1package com.runehive.content.skill.impl.firemaking;
2
3import com.runehive.Config;
4import com.runehive.content.activity.randomevent.RandomEventHandler;
5import com.runehive.content.clanchannel.content.ClanTaskKey;
6import com.runehive.content.pet.PetData;
7import com.runehive.content.pet.Pets;
8import com.runehive.content.prestige.PrestigePerk;
9import com.runehive.content.skill.impl.DestructionSkillAction;
10import com.runehive.content.skillcape.SkillCape;
11import com.runehive.game.Animation;
12import com.runehive.game.task.Task;
13import com.runehive.game.world.World;
14import com.runehive.game.world.entity.mob.player.Player;
15import com.runehive.game.world.entity.skill.Skill;
16import com.runehive.game.world.items.Item;
17import com.runehive.game.world.items.ground.GroundItem;
18import com.runehive.game.world.object.CustomGameObject;
19import com.runehive.game.world.position.Area;
20import com.runehive.game.world.region.Region;
21import com.runehive.net.packet.out.SendMessage;
22import com.runehive.util.RandomUtils;
23import com.runehive.util.Utility;
24
25import java.util.Optional;
26
27/**
28 * Handles the firemaking action.
29 *
30 * @author Daniel
31 */
32public final class FiremakingAction extends DestructionSkillAction {
33 private final Item item;
35
37 super(player, Optional.empty(), false);
38 this.item = item;
39 this.firemaking = firemaking;
40 }
41
42 @Override
43 public boolean canInit() {
44 if (getMob().skills.getMaxLevel(Skill.FIREMAKING) < firemaking.getLevel()) {
45 getMob().getPlayer().message("You need a firemaking level of " + firemaking.getLevel() + " to light this log!");
46 return false;
47 }
49 getMob().getPlayer().message("You can not burn a fire here! ");
50 return false;
51 }
52 Region region = getMob().getRegion();
53 if (region.containsObject(getMob().getPosition())) {
54 getMob().getPlayer().send(new SendMessage("You can't light a fire here!"));
55 return false;
56 }
57 return true;
58 }
59
60 @Override
61 public Optional<SkillAnimation> animation() {
62 return Optional.empty();
63 }
64
65 @Override
66 public double experience() {
67 return firemaking.getExperience() * Config.FIREMAKING_MODIFICATION;
68 }
69
70 @Override
71 public int skill() {
72 return Skill.FIREMAKING;
73 }
74
75 @Override
76 public void init() {
77 if (getMob().isPlayer()) {
78 getMob().getPlayer().send(new SendMessage("You attempt to light the log."));
79 }
80 getMob().animate(new Animation(733));
81 }
82
83 @Override
84 public double successFactor() {
85 return 100 - firemaking.getLevel();
86 }
87
88 @Override
89 public void onDestruct(boolean success) {
90 if (success) {
91 Player player = (Player) getMob();
92 final boolean saveLog = SkillCape.isEquipped(player, SkillCape.FIREMAKING) && Utility.random(1, 3) == 1;
93 if (!saveLog) {
94 player.inventory.remove(item);
95 }
96 player.takeStep();
97
99 player.inventory.remove(firemaking.getLog(), 1);
101 }
102
105 Pets.onReward(player, PetData.PHOENIX.getItem(), 8562);
106 CustomGameObject object = new CustomGameObject(5249, player.getPosition());
107 object.register();
108
110 player.forClan(channel -> channel.activateTask(ClanTaskKey.BURN_WILLOW_LOG, getMob().getName()));
111 }
112
113 World.schedule(new Task(180) {
114 @Override
115 protected void execute() {
116 GroundItem.createGlobal(player, new Item(592), object.getPosition());
117 object.unregister();
118 cancel();
119 }
120 });
121 }
122 }
123
124 @Override
125 public void onCancel(boolean logout) {
126 Player player = (Player) getMob();
127 player.animate(new Animation(65535));
128 }
129
130 @Override
131 public String getName() {
132 return "Firemaking";
133 }
134
135 @Override
137 return item;
138 }
139}
The class that contains setting-related constants for the server.
Definition Config.java:24
static final double FIREMAKING_MODIFICATION
The experience modification for firemaking.
Definition Config.java:256
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
boolean hasPerk(PrestigePerk perk)
final void execute()
A function representing the unit of work that will be carried out.
DestructionSkillAction(Mob mob, Optional< Position > position, boolean instant)
Creates a new DestructionSkillAction.
Optional< SkillAnimation > animation()
The skill animation to execute.
int skill()
The skill we should hand to experience to.
void onCancel(boolean logout)
A function executed on cancellation.
double experience()
The experience given from this action.
FiremakingAction(Player player, Item item, FiremakingData firemaking)
Item destructItem()
The item that will be removed upon destruction.
void init()
Any functionality that should be handled when this action is submitted.
boolean canInit()
Determines if this action can be initialized.
void onDestruct(boolean success)
The method executed upon destruction of the item.
Class that models a single animation used by an entity.
T getMob()
Gets the player.
Definition Action.java:44
synchronized final void cancel()
Cancels all subsequent executions.
Definition Task.java:113
Task(boolean instant, int delay)
Creates a new Task.
Definition Task.java:41
Represents the game world.
Definition World.java:46
static void schedule(Task task)
Submits a new event.
Definition World.java:247
This class represents a character controlled by a player.
Definition Player.java:125
void forClan(Consumer< ClanChannel > action)
Definition Player.java:568
Represents a trainable and usable skill.
Definition Skill.java:18
static final int FIREMAKING
The firemaking skill id.
Definition Skill.java:54
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
boolean remove(Item item)
Attempts to withdraw item from this container.
Represents a single Ground item on the world map.
static void createGlobal(Player player, Item item)
Creates a new GroundItem object for a player and an item.
Represents a static game object loaded from the map fs.
Handles checking if mobs are in a certain area.
Definition Area.java:13
static boolean inEdgeville(Interactable entity)
Definition Area.java:121
static boolean inWilderness(Position position)
Definition Area.java:272
Represents a single region.
Definition Region.java:21
boolean containsObject(int height, GameObject object)
Definition Region.java:168
The OutgoingPacket that sends a message to a Players chatbox in the client.
A static-util class that provides additional functionality for generating pseudo-random numbers.
static boolean success(double value)
Determines if a pseudorandomly generated double rounded to two decimal places is below or equal to va...
Handles miscellaneous methods.
Definition Utility.java:27
static int random(int bound)
Definition Utility.java:239
Holds the data for pets.
Definition PetData.java:14
Handles the perk rewards from prestiging.
static boolean isEquipped(Player player, SkillCape cape)