RuneHive-Game
Loading...
Searching...
No Matches
MageArena.java
Go to the documentation of this file.
1package com.runehive.content.activity.impl.magearena;
2
3import com.runehive.content.ActivityLog;
4import com.runehive.content.activity.Activity;
5import com.runehive.content.activity.ActivityDeathType;
6import com.runehive.content.activity.ActivityType;
7import com.runehive.content.activity.panel.ActivityPanel;
8import com.runehive.content.skill.impl.magic.teleport.Teleportation;
9import com.runehive.content.skill.impl.magic.teleport.TeleportationData;
10import com.runehive.game.Animation;
11import com.runehive.game.Graphic;
12import com.runehive.game.world.World;
13import com.runehive.game.world.entity.combat.hit.Hit;
14import com.runehive.game.world.entity.mob.Direction;
15import com.runehive.game.world.entity.mob.Mob;
16import com.runehive.game.world.entity.mob.npc.Npc;
17import com.runehive.game.world.entity.mob.npc.NpcDeath;
18import com.runehive.game.world.entity.mob.player.Player;
19import com.runehive.game.world.items.Item;
20import com.runehive.game.world.pathfinding.TraversalMap;
21import com.runehive.game.world.position.Area;
22import com.runehive.game.world.position.Position;
23import com.runehive.net.packet.out.SendMessage;
24import com.runehive.util.Utility;
25
26import java.util.HashMap;
27import java.util.HashSet;
28import java.util.Map;
29import java.util.Set;
30
31/**
32 * The Kolodion's mage arena activity.
33 *
34 * @author Daniel
35 */
36public class MageArena extends Activity {
37 /** The spawn boundaries. */
38 private static final Position[] BOUNDARIES = Utility.getInnerBoundaries(new Position(3105, 3934, 0), 8, 8);
39
40 /** The stages of the activity. */
41 private enum Stage {
43 }
44
45 /** The player instance. */
46 private final Player player;
47
48 /** The amount of npcs the player has killed. */
49 private int killed;
50
51 /** The amount of points the player has been awarded. */
52 private int points;
53
54 /** Activity completion flag. */
56
57 /** Holds all the monsters of the activity. */
58 private Map<Integer, Npc> monsters = new HashMap<>();
59
60 /** Constructs a new <code>MageArena</code>. */
62 super(5, instance);
63 this.player = player;
64 }
65
66 /** Creates a new <code>MageArena</code> activity. */
67 public static MageArena create(Player player) {
68 MageArena activity = new MageArena(player, player.playerAssistant.instance());
69 player.move(new Position(3105, 3934, 0));
70 player.gameRecord.start();
71 activity.add(player);
72 activity.resetCooldown();
73 return activity;
74 }
75
76 /** Gets the next best available position. */
79 while (!TraversalMap.isTraversable(available, Direction.NORTH, false)) {
80 available = Utility.randomElement(BOUNDARIES);
81 }
82 return available;
83 }
84
85 /** Handles the meteors. */
86 private void meteors() {
87 if (Utility.random(1, 3) == 2) {
88 Position center = new Position(player.getX() - 2, player.getY() - 2, player.getHeight());
89 Position[] bounds = Utility.getInnerBoundaries(center, 5, 5);
90 Set<Position> meteors = new HashSet<>();
91 for (Position bound : bounds) {
92 if (Utility.random(100) > 55) {
93 meteors.add(bound);
94 }
95 }
96 for (Position meteor : meteors) {
97 World.sendGraphic(new Graphic(659), meteor, getInstance());
98 World.schedule(1, () -> {
99 if (player.getPosition().equals(meteor))
100 player.damage(new Hit(Utility.random(5, 12)));
101 });
102 }
103 }
104 }
105
106 @Override
107 protected void start() {
108 switch (stage) {
109 case INITIALIZE:
110 for (int index = 0; index < 3; index++) {
111 int id = index == 0 ? 1157 : (index == 1 ? 1160 : 1158);
112 Npc monster = new Npc(id, getAvailablePosition());
113 monster.owner = player;
114 monsters.put(id, monster);
115 add(monster);
116 }
118 cooldown(1);
119 break;
120 case FIGHTING:
121 for (Npc monster : monsters.values()) {
122 if (!monster.getCombat().isAttacking(player)) {
123 monster.getCombat().attack(player);
124 continue;
125 }
126 if (monster.getCombat().isUnderAttackBy(player) && Utility.random(5, 15) == 5) {
127 monster.speak("ARGHHH!");
128 World.sendGraphic(new Graphic(1213), player.getPosition(), getInstance());
129 player.damage(new Hit(Utility.random(1, 5)));
130 Teleportation.activateOverride(monster, getAvailablePosition(), TeleportationData.MODERN, () -> monster.getCombat().attack(player));
131 }
132 }
133 meteors();
135 break;
136 case FINISH:
137 finish();
138 break;
139 }
140 }
141
142 @Override
143 public void finish() {
144 long time = player.gameRecord.end(ActivityType.KOLODION_ARENA);
145 cleanup();
146 remove(player);
148 player.move(new Position(2540, 4715, 0));
149
150 player.animate(Animation.RESET, true);
151 player.graphic(Graphic.RESET, true);
152
153 if (stage == Stage.FINISH) {
154 points += 30;
155 player.send(new SendMessage("You have completed Kolodion's arena. Final time: @red@" + Utility.getTime(time) + "</col>. Earned Points: @red@" + points + "</col>."));
156 player.activityLogger.add(ActivityLog.KOLODIONS_MINIGAME);
157 player.completedMageArena = true;
158 }
159
160 player.mageArenaPoints += points;
161 }
162
163 @Override
164 public void cleanup() {
165 for (Npc monster : monsters.values()) {
166 monsters.remove(monster);
167 remove(monster);
168 }
169 }
170
171 @Override
172 public void onLogout(Player player) {
173 finish();
174 }
175
176 @Override
179 finish();
180 }
181
182 @Override
183 public boolean canTeleport(Player player) {
184 player.send(new SendMessage("You can not teleport out of this activity."));
185 return true;
186 }
187
188 @Override
189 public void update() {
190 int progress = (int) Utility.getPercentageAmount(killed, 3);
191 String clock = "Time: <col=FF5500>" + Utility.getTime(System.currentTimeMillis() - player.gameRecord.time) + "</col>";
192 String remain = "Monsters Left: <col=FF5500>" + (3 - killed) + "</col>";
193 String gained = "Points Gained: <col=FF5500>" + points + "</col>";
194 Item[] items = {new Item(2412), new Item(2413), new Item(2414)};
195 ActivityPanel.update(player, progress, "Mage's Arena", "Progress:", Utility.randomElement(items), clock, remain, gained);
196 }
197
198 @Override
199 public void onDeath(Mob mob) {
200 if (mob.isPlayer()) {
201 mob.animate(Animation.RESET, true);
202 mob.graphic(Graphic.RESET, true);
203 finish();
204 return;
205 }
206 if (monsters.containsKey(mob.id)) {
207 killed++;
208 points += Utility.random(15, 20);
209 monsters.remove(mob.id);
210 World.schedule(new NpcDeath(mob.getNpc()));
211 }
212 if (monsters.isEmpty()) {
214 cooldown(10);
215 return;
216 }
218 }
219
220 @Override
222 return ActivityDeathType.SAFE;
223 }
224
225 @Override
228 }
229}
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.
static final int FINISH
The 'finish' cooldown id.
Definition Activity.java:37
int instance
The activity instance level.
Definition Activity.java:46
int getInstance()
Gets this activity's instance level.
void add(Mob mob)
Adds a mob to the activity.
int killed
The amount of npcs the player has killed.
Map< Integer, Npc > monsters
Holds all the monsters of the activity.
int points
The amount of points the player has been awarded.
Position getAvailablePosition()
Gets the next best available position.
void onDeath(Mob mob)
Called when the player die.
void cleanup()
Cleans up the activity when finished.
void onRegionChange(Player player)
Called when the player changes region.
void onLogout(Player player)
Called when the player logs out.
MageArena(Player player, int instance)
Constructs a new MageArena.
static MageArena create(Player player)
Creates a new MageArena activity.
boolean canTeleport(Player player)
Called when the player attempts to teleport.
static final Position[] BOUNDARIES
The spawn boundaries.
void start()
Starts the next activity stage.
static void update(Player player, int amount, String title, String footer, String... strings)
Sends all the information for the activity panel.
static void clear(Player player)
Clears the activity panel.
static void activateOverride(Mob mob, Position position, TeleportationData teleport)
Class that models a single animation used by an entity.
static final Animation RESET
Represents a single graphic that can be used by entities.
Definition Graphic.java:10
static final Graphic RESET
Definition Graphic.java:17
Represents the game world.
Definition World.java:46
static void schedule(Task task)
Submits a new event.
Definition World.java:247
static void sendGraphic(Graphic graphic, Position position, int instance)
Sends a graphic to the world.
Definition World.java:268
A Hit object holds the damage amount and hitsplat data.
Definition Hit.java:10
Handles the mob class.
Definition Mob.java:66
final boolean isPlayer()
Check if an entity is a player.
Definition Mob.java:564
Optional< Graphic > graphic
Definition Mob.java:91
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 container class that represents an item that can be interacted with.
Definition Item.java:21
Contains traversal data for a set of regions.
static boolean isTraversable(Position from, Direction direction, int size)
Tests whether or not a specified position is traversable in the specified direction.
Handles checking if mobs are in a certain area.
Definition Area.java:13
static boolean inkolodionArena(Entity entity)
Definition Area.java:145
Represents a single tile on the game world.
Definition Position.java:14
The OutgoingPacket that sends a message to a Players chatbox in the client.
Handles miscellaneous methods.
Definition Utility.java:27
static int random(int bound)
Definition Utility.java:239
static double getPercentageAmount(int progress, int total)
Gets a percentage amount.
Definition Utility.java:36
static< T > T randomElement(Collection< T > collection)
Picks a random element out of any array type.
Definition Utility.java:248
static Position[] getInnerBoundaries(Position position, int width, int length)
Definition Utility.java:621
static String getTime()
Gets the current server time and formats it.
Definition Utility.java:141
The activity log class.
Holds all activity types that are timed.
Represents the enumerated directions an entity can walk or face.