RuneHive-Game
Loading...
Searching...
No Matches
TitleManager.java
Go to the documentation of this file.
1package com.runehive.content.tittle;
2
3import com.runehive.game.world.entity.mob.UpdateFlag;
4import com.runehive.game.world.entity.mob.player.Player;
5import com.runehive.net.packet.out.*;
6import com.runehive.util.Utility;
7
8/**
9 * Handles unlocking player titles.
10 *
11 * @author Daniel
12 */
13public class TitleManager {
14
15 /** The base button identification. */
16 private final static int BUTTON_IDENTIFICATION = -26485;
17
18 /** Opens the title itemcontainer. */
19 public static void open(Player player) {
20 refresh(player);
21 player.interfaceManager.open(39_000);
22 }
23
24 /** Handles clicking buttons on the title itemcontainer. */
25 public static boolean click(Player player, int button) {
26 int ordinal = (button - BUTTON_IDENTIFICATION) / 2;
27 if (Title.forOrdinal(ordinal).isPresent()) {
28 player.attributes.set("PLAYER_TITLE_KEY", ordinal);
29 refresh(player);
30 return true;
31 }
32 return false;
33 }
34
35 /** Handles refreshing (send all strings and data) the itemcontainer. */
36 public static void refresh(Player player) {
37 int ordinal = player.attributes.get("PLAYER_TITLE_KEY", Integer.class);
38 int string = 39_052;
39 int config = 750;
40 Title view = null;
41
42 for (Title title : Title.values()) {
43 if (title.ordinal() == ordinal) {
44 view = title;
45 }
46 player.send(new SendString((title.ordinal() == ordinal ? "<col=DEB07A>" : "<col=A8865E>") + title.getTitle().getTitle(), string));
47 player.send(new SendTooltip("View title: <col=db9423>" + title.getTitle().getTitle() + "</col>", string - 1));
48 player.send(new SendConfig(config, title.activated(player) ? 1 : 0));
49 string += 2;
50 config += 2;
51 }
52
53 if (view == null) {
54 return;
55 }
56
57 String color = Integer.toHexString(view.getTitle().getColor());
58 int scroll = Title.values().length * 26;
59
60 for (int index = 0; index < view.getRequirement().length; index++) {
61 player.send(new SendString(view.getRequirement()[index], 39006 + index));
62 }
63 player.send(new SendString("<col=" + (view.activated(player) ? "A1D490>- UNLOCKED -" : "E34F52>- LOCKED -"), 39019));
64 player.send(new SendString("<col=" + color + ">" + view.getTitle().getTitle() + "<col=DEB07A> " + Utility.formatName(player.getName()), 39_003));
65 player.send(new SendScrollbar(39_050, scroll));
66 }
67
68 /** Handles a player redeeming a title. */
69 public static void redeem(Player player) {
70 int ordinal = player.attributes.get("PLAYER_TITLE_KEY", Integer.class);
71 if (Title.forOrdinal(ordinal).isPresent()) {
72 Title title = Title.forOrdinal(ordinal).get();
73 if (!title.activated(player)) {
74 player.send(new SendMessage("You have not activated this title yet!"));
75 return;
76 }
77
78 player.playerTitle = title.getTitle();
80 player.send(new SendMessage("You have successfully redeemed your title."));
81 }
82 }
83
84 /** Handles reseting the player title. */
85 public static void reset(Player player) {
86 player.playerTitle = PlayerTitle.empty();
88 player.send(new SendMessage("You have successfully reset your title."));
89 }
90}
static PlayerTitle empty()
Creates an empty player title.
Handles unlocking player titles.
static void refresh(Player player)
Handles refreshing (send all strings and data) the itemcontainer.
static void reset(Player player)
Handles reseting the player title.
static void redeem(Player player)
Handles a player redeeming a title.
static void open(Player player)
Opens the title itemcontainer.
static final int BUTTON_IDENTIFICATION
The base button identification.
static boolean click(Player player, int button)
Handles clicking buttons on the title itemcontainer.
final EnumSet< UpdateFlag > updateFlags
Definition Mob.java:94
final GenericAttributes attributes
Definition Mob.java:95
void open(int identification)
Opens an interface for the player.
This class represents a character controlled by a player.
Definition Player.java:125
String getName()
Gets the name of this entity.
Definition Player.java:774
The OutgoingPacket responsible for changing settings on a client.
The OutgoingPacket that sends a message to a Players chatbox in the client.
The OutgoingPacket that sends a string to a Players itemcontainer in the client.
Handles miscellaneous methods.
Definition Utility.java:27
static String formatName(final String input)
Definition Utility.java:645
public< K, E > E get(K key)
Gets a generic attribute.
public< K, E > void set(K key, E attribute)
Sets a generic attribute.
Holds all the title data that can be redeemed using the title interface.
Definition Title.java:15
static Optional< Title > forOrdinal(int ordinal)
Definition Title.java:126