RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
WellOfGoodwill.java
1package com.osroyale.content;
2
3
4import com.osroyale.Config;
5import com.osroyale.game.task.impl.DoubleExperienceEvent;
6import com.osroyale.game.world.World;
7import com.osroyale.game.world.entity.mob.player.Player;
8import com.osroyale.game.world.entity.mob.player.PlayerRight;
9import com.osroyale.game.world.items.Item;
10import com.osroyale.net.packet.out.SendMessage;
11import com.osroyale.net.packet.out.SendProgressBar;
12import com.osroyale.net.packet.out.SendString;
13import com.osroyale.util.Utility;
14
15import java.util.Iterator;
16import java.util.Objects;
17import java.util.TreeSet;
18
60
61public class WellOfGoodwill {
62
64 public static int CONTRIBUTION;
65
66 public static int activeTime = -1;
67 public static boolean active;
68
69
71 public static TreeSet<Contributor> contributors = new TreeSet<>();
72
74 public static String lastContributor;
75
76
78 public static final int MAXIMUM = 15_000_000;
79
81 public static void open(Player player) {
82 int progress = (int) Utility.getPercentageAmount(CONTRIBUTION, MAXIMUM);
83 int id = 43708;
84 int count = 0;
85
86 Iterator<Contributor> iterator = contributors.iterator();
87 while (count++ < 3 && iterator.hasNext()) {
88 Contributor contributor = iterator.next();
89 String rank = contributor.rank.getCrownText();
90 player.send(new SendString("Latest contributor:", 43711));
91 player.send(new SendString(rank + "<col=ffb83f>" + contributor.name + "</col> (" + Utility.formatDigits(contributor.contribution) + ")", id++));
92 }
93
94 for (int index = count; index < 3; index++) {
95 player.send(new SendString("", id + index));
96 }
97
98 if (isActive())
99 player.send(new SendMessage("The well will be active for " + (30 - activeTime) + " minutes."));
100
101 player.send(new SendProgressBar(43706, progress));
102 player.send(new SendString(lastContributor == null ? "" : lastContributor, 43712));
103 player.send(new SendString(progress + "%", 43717));
104 player.interfaceManager.open(43700);
105 }
106
108 public static void contribute(Player player, int amount) {
109 /* if (PlayerRight.isAdministrator(player)) {
110 player.message("Fuck off pleb");
111 return;
112 }
113*/
114 if (Config.DOUBLE_EXPERIENCE) {
115 player.message("Double experience is currently active which has temporarily disabled the wog.");
116 return;
117 }
118
119 if (amount < 100_000) {
120 player.message("You must contribute at least 100k into the well.");
121 return;
122 }
123
124 if (isActive()) {
125 player.message("The well is currently active and does not need", "any contribution.");
126 return;
127 }
128
129 if (amount > MAXIMUM - CONTRIBUTION) {
130 amount = MAXIMUM - CONTRIBUTION;
131 }
132
133 if (!player.inventory.contains(new Item(995, amount))) {
134 player.message("You do not have the required funds to contribute!");
135 return;
136 }
137
138 player.inventory.remove(new Item(995, amount));
139 CONTRIBUTION += amount;
140
141 add(player.getName(), player.right, amount);
142 lastContributor = PlayerRight.getCrown(player) + " <col=ffb83f>" + player.getName() + "</col> (" + Utility.formatDigits(amount) + ")";
143
144 player.message("Thank you! Your contribution of " + Utility.formatDigits(amount) + "gp to the well is appreciated!");
145
146 if (amount >= 250000) {
147 World.sendMessage("<col=2b58a0>WOG</col>: " + PlayerRight.getCrown(player) + "<col=2b58a0>" + player.getName() + "</col> has just contributed <col=2b58a0>" + Utility.formatDigits(amount) + "</col> coins.");
148 }
149
150 if (CONTRIBUTION >= MAXIMUM) activate();
151 open(player);
152 }
153
155 public static void activate() {
156 activeTime = 0;
158 World.sendMessage("<col=2b58a0>WOG</col>: The well has been fully replenished. 30 minutes of double XP is active.");
159 active = true;
160 }
161
162 public static void add(String name, PlayerRight rank, int amount) {
163 Contributor contributor = new Contributor(name, rank, amount);
164 for (Iterator<Contributor> iterator = contributors.iterator(); iterator.hasNext(); ) {
165 Contributor other = iterator.next();
166 if (contributor.name.equals(other.name)) {
167 contributor.add(other.contribution);
168 iterator.remove();
169 break;
170 }
171 }
172 contributors.add(contributor);
173 }
174
175 public static boolean isActive() {
176 return activeTime != -1;
177 }
178 public static String isActivated() {
179 return "Active";
180 }
181
182 public static class Contributor implements Comparable<Contributor> {
183 public final String name;
184 public final PlayerRight rank;
185 public int contribution;
186
187 Contributor(String name, PlayerRight rank, int contribution) {
188 this.name = name;
189 this.rank = rank;
190 this.contribution = contribution;
191 }
192
193 public void add(int amount) {
194 contribution += amount;
195 }
196
197 @Override
198 public int compareTo(Contributor other) {
199 return other.contribution - contribution;
200 }
201
202 @Override
203 public int hashCode() {
204 return Objects.hash(name, contribution);
205 }
206
207 @Override
208 public boolean equals(Object obj) {
209 if (obj == this) return true;
210 if (obj instanceof Contributor) {
211 Contributor other = (Contributor) obj;
212 return name.equals(other.name) && contribution == other.contribution;
213 }
214 return false;
215 }
216
217 @Override
218 public String toString() {
219 return name + " -- " + contribution;
220 }
221 }
225 public static String getInformation() {
226 return !active ? "Not Active" : isActivated();
227 }
228
229}
static TreeSet< Contributor > contributors
static void open(Player player)
static void contribute(Player player, int amount)
static void sendMessage(String... messages)
Definition World.java:433
static void schedule(Task task)
Definition World.java:284
static String formatDigits(final int amount)
Definition Utility.java:78
static double getPercentageAmount(int progress, int total)
Definition Utility.java:73