RuneHive-Game
Loading...
Searching...
No Matches
WellOfGoodwill.java
Go to the documentation of this file.
1package com.runehive.content;
2
3
4import com.runehive.Config;
5import com.runehive.game.task.impl.DoubleExperienceEvent;
6import com.runehive.game.world.World;
7import com.runehive.game.world.entity.mob.player.Player;
8import com.runehive.game.world.entity.mob.player.PlayerRight;
9import com.runehive.game.world.items.Item;
10import com.runehive.net.packet.out.SendMessage;
11import com.runehive.net.packet.out.SendProgressBar;
12import com.runehive.net.packet.out.SendString;
13import com.runehive.util.Utility;
14
15import java.util.Iterator;
16import java.util.Objects;
17import java.util.TreeSet;
18
19/**
20 * Handles contribution towards the well of goodwill.
21 *
22 * @author Daniel.
23 */
24public class WellOfGoodwill {
25
26 /** The current contribution amount for the well. */
27 public static int CONTRIBUTION;
28
29 public static int activeTime = -1;
30 public static boolean active;
31
32
33 /** The array list of contributors. */
34 public static TreeSet<Contributor> contributors = new TreeSet<>();
35
36 /** The last contributor to the well. */
37 public static String lastContributor;
38
39
40 /** The maximum contribution limit for the well. */
41 public static final int MAXIMUM = 15_000_000;
42
43 /** Opens the well itemcontainer. */
44 public static void open(Player player) {
45 int progress = (int) Utility.getPercentageAmount(CONTRIBUTION, MAXIMUM);
46 int id = 43708;
47 int count = 0;
48
49 Iterator<Contributor> iterator = contributors.iterator();
50 while (count++ < 3 && iterator.hasNext()) {
51 Contributor contributor = iterator.next();
52 String rank = contributor.rank.getCrownText();
53 player.send(new SendString("Latest contributor:", 43711));
54 player.send(new SendString(rank + "<col=ffb83f>" + contributor.name + "</col> (" + Utility.formatDigits(contributor.contribution) + ")", id++));
55 }
56
57 for (int index = count; index < 3; index++) {
58 player.send(new SendString("", id + index));
59 }
60
61 if (isActive())
62 player.send(new SendMessage("The well will be active for " + (30 - activeTime) + " minutes."));
63
64 player.send(new SendProgressBar(43706, progress));
65 player.send(new SendString(lastContributor == null ? "" : lastContributor, 43712));
66 player.send(new SendString(progress + "%", 43717));
67 player.interfaceManager.open(43700);
68 }
69
70 /** Handles contributing to the well. */
71 public static void contribute(Player player, int amount) {
72 /* if (PlayerRight.isAdministrator(player)) {
73 player.message("Administrators cannot contribute.");
74 return;
75 }
76*/
78 player.message("Double experience is currently active which has temporarily disabled the wog.");
79 return;
80 }
81
82 if (amount < 100_000) {
83 player.message("You must contribute at least 100k into the well.");
84 return;
85 }
86
87 if (isActive()) {
88 player.message("The well is currently active and does not need", "any contribution.");
89 return;
90 }
91
92 if (amount > MAXIMUM - CONTRIBUTION) {
93 amount = MAXIMUM - CONTRIBUTION;
94 }
95
96 if (!player.inventory.contains(new Item(995, amount))) {
97 player.message("You do not have the required funds to contribute!");
98 return;
99 }
100
101 player.inventory.remove(new Item(995, amount));
102 CONTRIBUTION += amount;
103
104 add(player.getName(), player.right, amount);
105 lastContributor = PlayerRight.getCrown(player) + " <col=ffb83f>" + player.getName() + "</col> (" + Utility.formatDigits(amount) + ")";
106
107 player.message("Thank you! Your contribution of " + Utility.formatDigits(amount) + "gp to the well is appreciated!");
108
109 if (amount >= 250000) {
110 World.sendMessage("<col=2b58a0>WOG</col>: " + PlayerRight.getCrown(player) + "<col=2b58a0>" + player.getName() + "</col> has just contributed <col=2b58a0>" + Utility.formatDigits(amount) + "</col> coins.");
111 }
112
113 if (CONTRIBUTION >= MAXIMUM) activate();
114 open(player);
115 }
116
117 /** Handles activating the well. */
118 public static void activate() {
119 activeTime = 0;
121 World.sendMessage("<col=2b58a0>WOG</col>: The well has been fully replenished. 30 minutes of double XP is active.");
122 active = true;
123 }
124
125 public static void add(String name, PlayerRight rank, int amount) {
126 Contributor contributor = new Contributor(name, rank, amount);
127 for (Iterator<Contributor> iterator = contributors.iterator(); iterator.hasNext(); ) {
128 Contributor other = iterator.next();
129 if (contributor.name.equals(other.name)) {
130 contributor.add(other.contribution);
131 iterator.remove();
132 break;
133 }
134 }
135 contributors.add(contributor);
136 }
137
138 public static boolean isActive() {
139 return activeTime != -1;
140 }
141 public static String isActivated() {
142 return "Active";
143 }
144
145 public static class Contributor implements Comparable<Contributor> {
146 public final String name;
147 public final PlayerRight rank;
148 public int contribution;
149
151 this.name = name;
152 this.rank = rank;
153 this.contribution = contribution;
154 }
155
156 public void add(int amount) {
157 contribution += amount;
158 }
159
160 @Override
161 public int compareTo(Contributor other) {
162 return other.contribution - contribution;
163 }
164
165 @Override
166 public int hashCode() {
167 return Objects.hash(name, contribution);
168 }
169
170 @Override
171 public boolean equals(Object obj) {
172 if (obj == this) return true;
173 if (obj instanceof Contributor) {
174 Contributor other = (Contributor) obj;
175 return name.equals(other.name) && contribution == other.contribution;
176 }
177 return false;
178 }
179
180 @Override
181 public String toString() {
182 return name + " -- " + contribution;
183 }
184 }
185 /**
186 * The information displayed on information tab.
187 */
188 public static String getInformation() {
189 return !active ? "Not Active" : isActivated();
190 }
191
192}
The class that contains setting-related constants for the server.
Definition Config.java:24
static boolean DOUBLE_EXPERIENCE
Definition Config.java:139
Contributor(String name, PlayerRight rank, int contribution)
Handles contribution towards the well of goodwill.
static String lastContributor
The last contributor to the well.
static void activate()
Handles activating the well.
static void contribute(Player player, int amount)
Handles contributing to the well.
static final int MAXIMUM
The maximum contribution limit for the well.
static int CONTRIBUTION
The current contribution amount for the well.
static TreeSet< Contributor > contributors
The array list of contributors.
static void add(String name, PlayerRight rank, int amount)
static String getInformation()
The information displayed on information tab.
static void open(Player player)
Opens the well itemcontainer.
An randomevent which starts double experience for 1 hour.
Represents the game world.
Definition World.java:46
static void schedule(Task task)
Submits a new event.
Definition World.java:247
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
The container class that represents an item that can be interacted with.
Definition Item.java:21
boolean remove(Item item)
Attempts to withdraw item from this container.
boolean contains(int id)
Determines if this container contains id.
The OutgoingPacket that sends a message to a Players chatbox in the client.
Handles sending the progress bar data to 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 double getPercentageAmount(int progress, int total)
Gets a percentage amount.
Definition Utility.java:36
static String getCrown(Player player)
Gets the crown display.