RuneHive-Game
Loading...
Searching...
No Matches
RoyaltyProgram.java
Go to the documentation of this file.
1package com.runehive.content;
2
3import com.runehive.game.world.World;
4import com.runehive.game.world.entity.mob.player.Player;
5import com.runehive.game.world.entity.mob.player.PlayerRight;
6import com.runehive.game.world.items.Item;
7import com.runehive.game.world.items.ItemDefinition;
8import com.runehive.game.world.position.Area;
9import com.runehive.net.packet.out.SendItemOnInterface;
10import com.runehive.net.packet.out.SendMessage;
11import com.runehive.net.packet.out.SendScrollbar;
12import com.runehive.net.packet.out.SendString;
13import com.runehive.util.MessageColor;
14import com.runehive.util.Utility;
15
16import java.util.Arrays;
17import java.util.Optional;
18
19
20
21/**
22 * Created by Daniel on 2017-07-13.
23 */
24public class RoyaltyProgram {
25
26 /** Holds all the RoyaltyReward data. */
27 public enum RoyaltyReward {
28 /* ONE(1, new Item(4587, 1)), // LOBSTER
29 THIRTEEN(13, new Item(560, 17500)), // DEATH RUNE
30 TWENTY_FIVE(25, new Item(7158, 1)), // DRAGON 2H
31 THIRTY_EIGHT(38, new Item(4588, 5)), // DRAGON SCIMITAR
32 FIFTY(50, new Item(537, 300)), // DRAGON BONES
33 SIXTY_SEVEN(67, new Item(12934, 1500)), // ZULRAH_SCALES
34 SEVENTY_FIVE(75, new Item(11936, 500)), // DARK CRAB
35 EIGHTY_EIGHT(88, new Item(995, 999_000)), // COINS
36 ONE_HUNDRED(100, new Item(6199, 1)); // MYSTERY BOX*/
37 ;
38 private final int level;
39 private final Item reward;
40
42 this.level = level;
43 this.reward = reward;
44 }
45
46 public int getLevel() {
47 return level;
48 }
49
50 public Item getReward() {
51 return reward;
52 }
53
54 public static Optional<RoyaltyReward> forLevel(int level) {
55 return Arrays.stream(values()).filter(a -> a.level == level).findAny();
56 }
57
58 public static Optional<RoyaltyReward> forOrdinal(int ordinal) {
59 return Arrays.stream(values()).filter(a -> a.ordinal() == ordinal).findAny();
60 }
61 }
62
63 /** Handles the royalty program reward. */
64 public static void append(Player player) {
65 append(player, 1);
66 }
67
68 /** Handles the royalty program reward. */
69 public static void append(Player player, int increment) {
70 player.royalty += increment;
71 String suffix = increment > 1 ? "s" : "";
72
73 int royalty = player.royalty;
74 boolean levelUp = royalty >= 100;
75
76 if (levelUp) {
77 player.royaltyLevel++;
78 player.royalty = 0;
79 World.sendMessage("<col=9E4629> RP: " + PlayerRight.getCrown(player) + "<col=9E4629>" + player.getName()
80 + "</col> has just reached prestige <col=9E4629>" + player.royaltyLevel + "</col>.");
81 }
82
83 player.send(new SendMessage("You have just received <col=9E4629>" + increment + "</col> royalty point"
84 + (suffix) + ". You now have <col=9E4629>" + player.royalty + "</col> point"
85 + (player.royalty > 1 ? "s" : "") + " and are level <col=9E4629>" + player.royaltyLevel + "</col>."));
86
87 if (!RoyaltyReward.forLevel(royalty).isPresent())
88 return;
89
90 RoyaltyReward reward = RoyaltyReward.forLevel(royalty).get();
91 int item = reward.getReward().getId();
92 int amount = reward.getReward().getAmount() * player.royaltyLevel;
93 String name = ItemDefinition.get(item).getName();
94 player.inventory.addOrDrop(new Item(item, amount));
95 player.send(
96 new SendMessage("You have been rewarded with " + amount + " " + name + ".", MessageColor.DARK_GREEN));
97 }
98
99 /** Opens the Royalty Reward Program itemcontainer. */
100 public static void open(Player player) {
101
102 if (Area.inWilderness(player)) {
103 player.dialogueFactory.sendStatement("You can not open a Royalty Program while in the wilderness!")
104 .execute();
105 return;
106 }
107
108 if (player.getCombat().inCombat()) {
109 player.dialogueFactory.sendStatement("You can not open a Royalty Program while in combat!").execute();
110 return;
111 }
112
113 if (player.playerAssistant.busy()) {
114 player.dialogueFactory.sendStatement("You can not open a Royalty Program right now!").execute();
115 return;
116
117 }
118
119 else {
120
121 int size = RoyaltyReward.values().length;
122 // Item[] items = new Item[size + 3];
123
124 for (int index = 0, string = 37116; index < size; index++) {
125 RoyaltyReward perk = RoyaltyReward.forOrdinal(index).get();
126 Item item = perk.getReward();
127 int amount = player.royaltyLevel == 0 ? perk.getReward().getAmount()
128 : perk.getReward().getAmount() * player.royaltyLevel;
129
130 // items[index + 3] = new Item(item.getId(), amount);
131 player.send(new SendString("<col=3c50b2>Level: " + perk.getLevel(), string++));
132 player.send(new SendString("<col=347043>" + Utility.formatDigits(amount) + "x " + item.getName(),
133 string++));
134 }
135
136 player.send(new SendString("The Program rewards players for their activity in game. Every 30", 37111));
137 player.send(
138 new SendString("minutes everyone is awarded 1 point. Points accumulate until 100 where", 37112));
139 player.send(
140 new SendString("you gain a prestige level, points will be reset and you will be eligible", 37113));
141 player.send(
142 new SendString("for the rewards again. Reward amounts are multiplied by prestige level.", 37114));
143 player.send(new SendString("", 37115));
144 player.send(new SendString("RP: " + player.royalty + "\\nLevel:" + player.royaltyLevel, 37107));
145 player.send(new SendString("Royalty Program", 37103));
146 player.send(new SendScrollbar(37110, size * 50));
147 // player.send(new SendItemOnInterface(37199, items));
148 player.interfaceManager.open(37100);
149 }
150 }
151}
Created by Daniel on 2017-07-13.
static void open(Player player)
Opens the Royalty Reward Program itemcontainer.
static void append(Player player)
Handles the royalty program reward.
static void append(Player player, int increment)
Handles the royalty program reward.
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.
Represents the game world.
Definition World.java:46
static void sendMessage(String... messages)
Sends a global message.
Definition World.java:396
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
Combat< Player > getCombat()
The combat of the mob.
Definition Player.java:759
Represents all of an in-game Item's attributes.
static ItemDefinition get(int id)
Gets an item definition.
The container class that represents an item that can be interacted with.
Definition Item.java:21
final int getId()
Gets the identification of this item.
Definition Item.java:324
final int getAmount()
Gets the quantity of this item.
Definition Item.java:342
void addOrDrop(List< Item > items)
Attempts to deposit an item to the players inventory, if there is no space it'll bank the item instea...
Handles checking if mobs are in a certain area.
Definition Area.java:13
static boolean inWilderness(Position position)
Definition Area.java:272
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 formatDigits(final int amount)
Formats digits for integers.
Definition Utility.java:41
static Optional< RoyaltyReward > forLevel(int level)
static Optional< RoyaltyReward > forOrdinal(int ordinal)
static String getCrown(Player player)
Gets the crown display.
Holds an enum of colors for ease.