RuneHive-Game
Loading...
Searching...
No Matches
RandomEvent.java
Go to the documentation of this file.
1package com.runehive.content.activity.randomevent;
2
3
4import com.runehive.Config;
5import com.runehive.content.activity.Activity;
6import com.runehive.content.activity.ActivityDeathType;
7import com.runehive.content.activity.ActivityType;
8import com.runehive.game.Animation;
9import com.runehive.game.Graphic;
10import com.runehive.game.world.entity.combat.hit.Hit;
11import com.runehive.game.world.entity.mob.npc.Npc;
12import com.runehive.game.world.entity.mob.player.Player;
13import com.runehive.net.packet.out.SendMessage;
14
15/**
16 * The random event handler.
17 *
18 * @author Daniel.
19 */
20public abstract class RandomEvent extends Activity {
21
22 /** The player instance. */
23 public Player player;
24
25 /** The event npc. */
26 protected Npc eventNpc;
27
28 /** Th message count. */
29 private int count;
30
31 /** Flag if the event is angered. */
32 protected boolean angered;
33
34 /** Constructs a new <code>RandomEvent</code>. */
36 super(cooldown, player.instance);
37 this.player = player;
38 this.count = 0;
39 }
40
41 /** The event npc identification. */
42 protected abstract int eventNpcIdentification();
43
44 /** The event npc shout messages. */
45 protected abstract String[] eventNpcShout();
46
47 @Override
48 protected void start() {
49 if (count >= eventNpcShout().length) {
50 player.damage(new Hit(5));
51 finish();
52 return;
53 }
54 if (eventNpc == null) {
55 eventNpc = new Npc(eventNpcIdentification(), player.getPosition());
57 eventNpc.interact(player);
58 eventNpc.follow(player);
59 eventNpc.graphic(new Graphic(86, true));
60 eventNpc.owner = player;
61 cooldown(2);
62 return;
63 }
64 eventNpc.animate(new Animation(863));
65 eventNpc.speak(eventNpcShout()[count].replace("%name", player.getName()));
66 eventNpc.follow(player);
67 count++;
68 if (count >= eventNpcShout().length) {
69 angered = true;
70 eventNpc.graphic(new Graphic(86, true));
71 eventNpc.animate(new Animation(864));
73 player.send(new SendMessage("You have been teleported home since you've ignored the random event."));
74 cooldown(2);
75 } else {
77 }
78 }
79
80 @Override
81 public void finish() {
82 cleanup();
83 remove(player);
84 }
85
86 @Override
88 if (eventNpc != null && eventNpc.getPosition().isWithinDistance(player.getPosition(), 15)) {
90 }
91 }
92
93 @Override
94 public void onLogout(Player player) {
95 finish();
96 }
97
98 @Override
99 public void cleanup() {
100 remove(eventNpc);
101 }
102
103 @Override
107
108 @Override
111 }
112}
The class that contains setting-related constants for the server.
Definition Config.java:24
static final Position DEFAULT_POSITION
The default, i.e.
Definition Config.java:197
final int cooldown
The sequencing cooldown.
Definition Activity.java:43
Activity(int cooldown, int instance)
Constructs a new SequencedMinigame object.
Definition Activity.java:55
final void resetCooldown()
Resets the remaining ticks to the cached cooldown ticks.
void add(Mob mob)
Adds a mob to the activity.
final void finishCooldown()
Sets the cooldown flag to FINISH.
abstract int eventNpcIdentification()
The event npc identification.
void cleanup()
Cleans up the activity when finished.
boolean angered
Flag if the event is angered.
abstract String[] eventNpcShout()
The event npc shout messages.
RandomEvent(Player player, int cooldown)
Constructs a new RandomEvent.
void onLogout(Player player)
Called when the player logs out.
void onRegionChange(Player player)
Called when the player changes region.
void start()
Starts the next activity stage.
Class that models a single animation used by an entity.
Represents a single graphic that can be used by entities.
Definition Graphic.java:10
A Hit object holds the damage amount and hitsplat data.
Definition Hit.java:10
Represents a non-player character in the in-game world.
Definition Npc.java:29
This class represents a character controlled by a player.
Definition Player.java:125
The OutgoingPacket that sends a message to a Players chatbox in the client.
Holds all activity types that are timed.