RuneHive-Game
Loading...
Searching...
No Matches
BloodChestEvent.java
Go to the documentation of this file.
1package com.runehive.content.bloodmoney;
2
3import com.runehive.game.task.Task;
4import com.runehive.game.world.World;
5
6import java.util.Map;
7import java.util.NavigableMap;
8import java.util.TreeMap;
9import java.util.concurrent.TimeUnit;
10
11/**
12 * Handles the blood chest event.
13 *
14 * @author Daniel
15 */
16public class BloodChestEvent extends Task {
17
18 /** Constructs a new <code>BloodChestEvent</code>. */
19
20 private NavigableMap<Double, String> timeToMessage;
21
22 public BloodChestEvent() {
23 super(100);
24 timeToMessage = new TreeMap<>();
25 timeToMessage.put(1.0, "<icon=0><col=FF0000> Blood Money Chest will vanish in 1 hour!");
26 timeToMessage.put(0.5, "<icon=0><col=FF0000> Blood Money Chest will vanish in 30 minutes!");
27 timeToMessage.put(0.25, "<icon=0><col=FF0000> Blood Money Chest will vanish in 15 minutes!");
28 timeToMessage.put(0.0833, "<icon=0><col=FF0000> Blood Money Chest will vanish in 5 minutes!");
29 }
30
31
32 @Override
33 public void execute() {
35 if (BloodMoneyChest.stopwatch.elapsedTime(TimeUnit.HOURS) >= 4) {
38 }
39 return;
40 }
41
42 double hoursPassed = BloodMoneyChest.stopwatch.elapsedTime(TimeUnit.HOURS);
43
44 if (hoursPassed >= 4) {
47 } else {
48 double hoursRemaining = 4 - hoursPassed;
49 Map.Entry<Double, String> messageEntry = timeToMessage.floorEntry(hoursRemaining);
50 if (messageEntry != null && hoursRemaining <= messageEntry.getKey()) {
51 String message = messageEntry.getValue();
52 World.sendMessage(message);
53 System.out.println("Sent message: " + message);
54 timeToMessage.remove(messageEntry.getKey());
55 }
56 }
57 }
58}
NavigableMap< Double, String > timeToMessage
Constructs a new BloodChestEvent.
void execute()
A function representing the unit of work that will be carried out.
static final Stopwatch stopwatch
The stopwatch for this event.
static void finish(boolean unlocked)
Handles finishing the blood money chet.
static void spawn()
Handles spawning the blood money chest.
static boolean active
The state of the blood money chest.
Task(boolean instant, int delay)
Creates a new Task.
Definition Task.java:41
Represents the game world.
Definition World.java:46
static void sendMessage(String... messages)
Sends a global message.
Definition World.java:396
long elapsedTime(TimeUnit unit)