RuneHive-Game
Loading...
Searching...
No Matches
ShootingStar.java
Go to the documentation of this file.
1package com.runehive.content.shootingstar;
2
3import com.runehive.content.skill.impl.mining.PickaxeData;
4import com.runehive.game.task.Task;
5import com.runehive.game.world.World;
6import com.runehive.game.world.entity.mob.player.Player;
7import com.runehive.game.world.entity.skill.Skill;
8import com.runehive.game.world.items.Item;
9import com.runehive.game.world.object.GameObject;
10import org.apache.logging.log4j.LogManager;
11import org.apache.logging.log4j.Logger;
12
13public class ShootingStar {
14
15 private static final Logger logger = LogManager.getLogger(ShootingStar.class);
16
17 /**
18 * Checks if the star has been found before
19 */
20 public static boolean starHasBeenFound = false;
21
22 /**
23 * The current data of the shooting star
24 */
26
27 /**
28 * Ticks till the next shooting star will spawn
29 */
30 public static int starTick = 30;
31
32 /**
33 * Handles the mine option of the shooting star
34 * @param player
35 */
36 public static void mine(Player player, GameObject o) {
37 if(!starHasBeenFound) {
38 starHasBeenFound = true;
39 player.dialogueFactory.sendStatement("Congratulations! You were the first person to find this star!").execute();
40 player.skills.addExperience(14, 10000);
41 return;
42 }
43
44 PickaxeData pickaxe = PickaxeData.getBestPickaxe(player).orElse(null);
45
46 if(pickaxe == null) {
47 player.message("You don't have a pickaxe.");
48 return;
49 }
50
51 if (!player.skills.get(Skill.MINING).reqLevel(pickaxe.level)) {
52 player.message("You need a level of " + pickaxe.level + " to use this pickaxe!");
53 return;
54 }
55
56 if(!player.skills.get(Skill.MINING).reqLevel(shootingStarData.getMiningLevel())) {
57 player.dialogueFactory.sendStatement("You need a Mining level of " + shootingStarData.getMiningLevel() + " to mine here.").execute();
58 return;
59 }
60
61 if(!player.inventory.hasCapacityFor(new Item(25527))) {
62 player.message("Not enough space in your inventory.");
63 return;
64 }
65
66 player.message("You swing your pick at the rock.");
67
68 player.animate(pickaxe.animation);
69
70 player.action.execute(new ShootingStarAction(player, pickaxe, o));
71 player.skills.get(Skill.MINING).setDoingSkill(true);
72 }
73
74 /**
75 * Handles prospecting the shooting star
76 * @param player
77 */
78 public static void prospect(Player player) {
79 if(!starHasBeenFound) {
80 starHasBeenFound = true;
81 player.dialogueFactory.sendStatement("Congratulations! You were the first person to find this star!", "You have been granted 10,000 mining xp!").execute();
82 player.skills.addExperience(14, 10000);
83 return;
84 }
85
86 player.dialogueFactory.sendStatement("This is a size-"+(shootingStarData.starLevel + 1)+" star. A Mining level of at least "+shootingStarData.getMiningLevel()+" is required to", "mine this layer. It has been mined "+shootingStarData.getPercentage()+"% of the way to the next layer.").execute();
87 }
88
89 /**
90 * Handles initializing the shooting stars event
91 */
92 public static void init() {
93 logger.info("Loaded Shooting Stars event.");
94 World.schedule(new Task(1) {
95 @Override
96 protected void execute() {
97 starTick--;
98 if(starTick <= 0) {
99 if(shootingStarData != null) {
100 shootingStarData.destruct();
101 starHasBeenFound = false;
102 }
103
105 World.sendMessage("@red@A shooting star has just crashed " + shootingStarData.getHint() +" " + shootingStarData.getLocationName() + "!");
106 // DiscordPlugin.sendSimpleMessage("A shooting star has just crashed " + shootingStarData.getHint() +" " + shootingStarData.getLocationName() + "!");
107 //4 Hours in ticks
108 starTick = 24_000;
109 }
110 }
111
112 @Override
113 protected void onCancel(boolean logout) {
114 }
115 });
116 }
117}
final DialogueFactory execute()
Retrieves the next dialogue in the chain and executes it.
final DialogueFactory sendStatement(String... lines)
Appends a StatementDialogue to the current dialogue chain.
static void prospect(Player player)
Handles prospecting the shooting star.
static void init()
Handles initializing the shooting stars event.
static boolean starHasBeenFound
Checks if the star has been found before.
static void mine(Player player, GameObject o)
Handles the mine option of the shooting star.
static int starTick
Ticks till the next shooting star will spawn.
static ShootingStarData shootingStarData
The current data of the shooting star.
public< A extends Action<?> > void execute(A action)
A game representing a cyclic unit of work.
Definition Task.java:11
Represents the game world.
Definition World.java:46
static void schedule(Task task)
Submits a new event.
Definition World.java:247
static void sendMessage(String... messages)
Sends a global message.
Definition World.java:396
This class represents a character controlled by a player.
Definition Player.java:125
Represents a trainable and usable skill.
Definition Skill.java:18
boolean reqLevel(int level)
Determines if your level is greater than or equal to level.
Definition Skill.java:270
static final int MINING
The mining skill id.
Definition Skill.java:63
void setDoingSkill(boolean doingSkill)
Definition Skill.java:489
void addExperience(int id, double experience)
Adds experience to a given skill.
Skill get(int id)
Gets the skill for an id.
The container class that represents an item that can be interacted with.
Definition Item.java:21
final boolean hasCapacityFor(Item... item)
Determines if this container has the capacity for item.
static Optional< PickaxeData > getBestPickaxe(Player player)
Gets the definition for this pickaxe.