Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.dark.rs2.content.gambling;
- import java.util.ArrayList;
- import java.util.List;
- import com.dark.core.util.Utility;
- import com.dark.rs2.content.dialogue.DialogueManager;
- import com.dark.rs2.content.io.PlayerSave.PlayerContainer;
- import com.dark.rs2.content.io.PlayerSaveUtil;
- import com.dark.rs2.entity.World;
- import com.dark.rs2.entity.item.Item;
- import com.dark.rs2.entity.player.Player;
- import com.dark.rs2.entity.player.net.out.impl.SendMessage;
- import com.dark.rs2.entity.player.net.out.impl.SendString;
- /**
- * Handles the Lottery
- * @author Daniel
- *
- */
- public class Lottery {
- /**
- * Players entered in the lottery
- */
- private static final List<Player> entries = new ArrayList<Player>();
- /**
- * The lottery limit
- */
- private static final int LOTTERY_LIMIT = 1_000_000_000;
- /**
- * The entry price of lottery
- */
- private static final int ENTRY_PRICE = 500_000_000;
- /**
- * Current threshold of lottery
- */
- private static int CURRENT_POT = 0;
- /**
- * The winner of lottery
- */
- private static Player winner = null;
- /**
- * Handles player entering the lottery
- * @param player
- */
- public static void enterLotter(Player player) {
- if(player.isIron()){
- DialogueManager.sendStatement(player, "You may not enter the lottery.");
- return;
- }
- if (hasEntered(player)) {
- DialogueManager.sendStatement(player, "You are already entered in the lottery!");
- return;
- }
- if (CURRENT_POT >= LOTTERY_LIMIT) {
- DialogueManager.sendStatement(player, "The lottery is currently full.");
- return;
- }
- if (!player.getInventory().hasItemAmount(995, ENTRY_PRICE)) {
- DialogueManager.sendStatement(player, "You need " + Utility.format(ENTRY_PRICE) + " coins to enter the lottery!");
- return;
- }
- player.getInventory().remove(995, ENTRY_PRICE);
- CURRENT_POT += ENTRY_PRICE;
- entries.add(player);
- //World.sendGlobalMessage("[ @blu@Powerball @bla@]A new player has entered the lottery! @blu@" + Utility.format(CURRENT_POT) + " @bla@/ @blu@" + Utility.format(LOTTERY_LIMIT) + "@bla@.");
- player.send(new SendMessage("You have entered the lotto, use ::lotto command to see the current pot information!"));
- if (CURRENT_POT == LOTTERY_LIMIT) {
- draw();
- }
- }
- /**
- * Draws the lottery
- */
- public static void draw() {
- if (entries.isEmpty()) {
- return;
- }
- winner = Utility.randomElement(entries);
- if (winner== null) {
- winner = new Player();
- winner.setUsername(name);
- if (!PlayerContainer.loadDetails(winner)) {
- System.out.println("The player '" + name + "' could not be found.");
- return;
- }
- }
- winner.send(new SendMessage("Congratulations! You have won the lottery.."));
- winner.getInventory().addOrCreateGroundItem(13204, + 900_000, true);
- return;
- // World.sendGlobalMessage("<shad=0>[ @blu@Powerball @bla@] @blu@" + winner.getUsername() + "@bla@ has just won the Powerball!");
- // winner.send(new SendMessage("The Taxman takes 100k Platinum tokens... Taxation is theft!"));
- //reset();
- }
- /**
- * Resets the lottery
- */
- public static void reset() {
- winner = null;
- CURRENT_POT = 0;
- entries.clear();
- }
- /**
- * Does an announcement for lottery
- */
- public static void announce() {
- World.sendGlobalMessage("[ @blu@Powerball @bla] The current pot is at <col=C46423>" + Utility.format(CURRENT_POT) + " </col>/ <col=C46423>" + Utility.format(LOTTERY_LIMIT) + "</col>.");
- }
- /**
- * Gets the current lottery pot
- * @return
- */
- public static int getPot() {
- return CURRENT_POT;
- }
- /**
- * Gets the current lottery limit
- * @return
- */
- public static int getLimit() {
- return LOTTERY_LIMIT;
- }
- /**
- * Gets the amount of players involved in lottery
- * @return
- */
- public static int getPlayers() {
- return entries.size();
- }
- /**
- * Checks if player has entered the lotter
- * @param player
- * @return
- */
- public static boolean hasEntered(Player player) {
- if (entries.contains(player)) {
- return true;
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement