Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.rs.game.player.content;
- import com.rs.game.Animation;
- import com.rs.game.ForceTalk;
- import com.rs.game.Graphics;
- import com.rs.game.World;
- import com.rs.game.item.Item;
- import com.rs.game.npc.NPC;
- import com.rs.game.player.Player;
- import com.rs.game.tasks.WorldTask;
- import com.rs.game.tasks.WorldTasksManager;
- import com.rs.utils.Colors;
- import com.rs.utils.RiggedGamblingCaps;
- import com.rs.utils.RiggedGamblingCaps.GambleCapObject;
- import com.rs.utils.Utils;
- public class RiggedDicing {
- private static int chance = 55, gamble = 100;
- public static final int GAMBLER_NPC_ID = 659;
- private static final int MAX_COINS_CAP = 3, MAX_ITEMS_CAP = 3;
- public static final int COINS_HOURS_LIMIT = 2, ITEMS_HOURS_LIMIT = 2;
- public static boolean isOkitem(Player player, Item item) {
- if (!ItemConstants.isTradeable(item)) {
- player.closeInterfaces();
- sendNPCMessage(player, "You are not allowed to gamble untradable items!");
- return false;
- }
- if (item.getDefinitions().getTipitPrice() < 5_000_000) {
- player.closeInterfaces();
- sendNPCMessage(player, "Item price is too low to gamble, try something over 5M..");
- return false;
- }
- return true;
- }
- public static void GambleItem(Player player, Item item, int amount) {
- if (isItemCap(player)) {
- return;
- }
- if (!isOkitem(player, item)) {
- return;
- }
- if (player.getInventory().getFreeSlots() < amount * 2) {
- player.closeInterfaces();
- sendNPCMessage(player, "You do not have sufficient space available, bank some items and try again.");
- return;
- }
- if (player.isLocked()) {
- player.closeInterfaces();
- sendNPCMessage(player, "Please finish what you are doing first.");
- return;
- }
- for (NPC npc : World.getNPCs()) {
- if (npc.getId() == GAMBLER_NPC_ID) {
- npc.setNextAnimation(new Animation(11900));
- npc.setNextGraphics(new Graphics(2075));
- npc.setNextForceTalk(new ForceTalk("Rolling..."));
- }
- }
- player.getInventory().deleteItem(new Item(item.getId(), amount));
- player.lock(3);
- sendNPCMessage(player, "Rolling... <br>Goodluck!");
- WorldTasksManager.schedule(new WorldTask() {
- int loop;
- @Override
- public void run() {
- sendNPCMessage(player, "Rolling... <br>Goodluck!");
- if (loop == 3) {
- stop();
- Roll(100);
- player.getInterfaceManager().closeChatBoxInterface();
- Check(player, item, amount);
- }
- loop++;
- }
- }, 0, 1);
- handleItemGambleCap(player);
- }
- public static void GambleMoney(Player player, int money) {
- if (isCoinsCap(player)) {
- return;
- }
- if (money < 1_000_000 || money > 50_000_000) {
- player.closeInterfaces();
- sendNPCMessage(player, "<col=ff0000>Min: 1M - Max: 50M! to increase your limits, upgrade your donor rank!");
- return;
- }
- if (!player.hasMoney(money)) {
- player.closeInterfaces();
- sendNPCMessage(player, "You don't have the money to do that.");
- return;
- }
- if (player.hasMoney(Integer.MAX_VALUE - money) || player.hasMoney(Integer.MAX_VALUE)) {
- sendNPCMessage(player, "You cannot do that, try banking some GP.");
- return;
- }
- if (player.isLocked()) {
- player.closeInterfaces();
- sendNPCMessage(player, "Please finish what you are doing first.");
- return;
- }
- for (NPC npc : World.getNPCs()) {
- if (npc.getId() == GAMBLER_NPC_ID) {
- npc.setNextAnimation(new Animation(11900));
- npc.setNextGraphics(new Graphics(2075));
- npc.setNextForceTalk(new ForceTalk("Rolling..."));
- }
- }
- player.takeMoney(money);
- player.lock(3);
- sendNPCMessage(player, "Rolling... <br>Goodluck!");
- WorldTasksManager.schedule(new WorldTask() {
- int loop;
- @Override
- public void run() {
- sendNPCMessage(player, "Rolling... <br>Goodluck!");
- if (loop == 3) {
- stop();
- Roll(100);
- player.getInterfaceManager().closeChatBoxInterface();
- Check(player, money);
- }
- loop++;
- }
- }, 0, 1);
- handleCoinsCap(player);
- }
- private static void Check(Player player, Item item, int amount) {
- if (!isWinner()) {
- for (NPC npc : World.getNPCs()) {
- if (npc.getId() == GAMBLER_NPC_ID) {
- WorldTasksManager.schedule(new WorldTask() {
- @Override
- public void run() {
- sendNPCMessage(player,
- "<col=ff0000>Rolled " + getNumberRolled() + ", Unlucky " + player.getDisplayName()
- + ", you have lost the bet of " + amount * 2 + "x " + item.getName() + ".");
- npc.setNextForceTalk(new ForceTalk("<col=ff0000>Rolled " + getNumberRolled() + ", Unlucky "
- + player.getDisplayName() + ", you have lost the bet of " + amount * 2 + "x "
- + item.getName() + "."));
- }
- }, 0);
- }
- }
- player.sm("You lost! :( You rolled <col=ff0000>" + getNumberRolled() + "</col>. Had you rolled <col=ff0000>"
- + (chance - getNumberRolled()) + "</col> more you would have won.");
- return;
- }
- int betWealth = item.getDefinitions().getTipitPrice() * amount * 2;
- if (betWealth >= 250_000_000) {
- World.sendWorldMessage("<img=7><col=FF0033>Server: " + player.getDisplayName() + " won "
- + Utils.formatAmount2(betWealth) + " bet from Gambling.", false);
- }
- for (NPC npc : World.getNPCs()) {
- if (npc.getId() == GAMBLER_NPC_ID) {
- WorldTasksManager.schedule(new WorldTask() {
- @Override
- public void run() {
- sendNPCMessage(player,
- "Rolled " + getNumberRolled() + "</col>, and congratulations " + player.getDisplayName()
- + ", you have won " + amount * 2 + "x " + item.getName() + ".");
- npc.setNextForceTalk(new ForceTalk(
- "Rolled " + getNumberRolled() + ", and congratulations " + player.getDisplayName()
- + ", you have won " + amount * 2 + "x " + item.getName() + "."));
- }
- }, 0);
- }
- }
- player.setNextGraphics(new Graphics(743));
- player.addItem(new Item(item.getId(), amount * 2));
- sendNPCMessage(player, "<col=ff000>You rolled " + getNumberRolled() + ", Congratulations. You have won "
- + amount * 2 + "x " + item.getName() + ".");
- return;
- }
- private static void Check(Player player, int money) {
- if (!isWinner()) {
- for (NPC npc : World.getNPCs()) {
- if (npc.getId() == GAMBLER_NPC_ID) {
- WorldTasksManager.schedule(new WorldTask() {
- @Override
- public void run() {
- sendNPCMessage(player,
- "Rolled " + getNumberRolled() + ", Unlucky " + player.getDisplayName()
- + ", you have lost the bet of " + Prize(money) + " coins.");
- npc.setNextForceTalk(
- new ForceTalk("Rolled " + getNumberRolled() + ", Unlucky " + player.getDisplayName()
- + ", you have lost the bet of " + Prize(money) + " coins."));
- }
- }, 0);
- }
- }
- player.sm("You lost! :( You rolled <col=ff0000>" + getNumberRolled() + "</col>. Had you rolled <col=ff0000>"
- + (chance - getNumberRolled()) + "</col> more you would have won.");
- return;
- }
- if (Prize(money) >= 250_000_000) {
- World.sendWorldMessage("<img=7><col=FF0033>Server: " + player.getDisplayName() + " won "
- + Utils.getFormattedNumber((Prize(money) / 2)) + " coins from Gambling.", false);
- }
- for (NPC npc : World.getNPCs()) {
- if (npc.getId() == GAMBLER_NPC_ID) {
- WorldTasksManager.schedule(new WorldTask() {
- @Override
- public void run() {
- sendNPCMessage(player,
- "<col=00ff00>Rolled " + getNumberRolled() + "</col>, and congratulations "
- + player.getDisplayName() + ", you have won "
- + Utils.getFormattedNumber((Prize(money) / 2)) + " coins.");
- npc.setNextForceTalk(new ForceTalk("<col=00ff00>Rolled " + getNumberRolled()
- + ", and congratulations " + player.getDisplayName() + ", you have won "
- + Utils.getFormattedNumber((Prize(money) / 2)) + " coins."));
- }
- }, 0);
- }
- }
- player.setNextGraphics(new Graphics(743));
- player.getMoneyPouch().addMoney(Prize(money), false);
- sendNPCMessage(player, "<col=ff000>You rolled " + getNumberRolled() + ", Congratulations. You have won "
- + Utils.getFormattedNumber((Prize(money) / 2), ',') + " GP.");
- return;
- }
- private static int Prize(int value) {
- return value * 2;
- }
- private static int getNumberRolled() {
- return gamble;
- }
- private static boolean isWinner() {
- return gamble >= chance;
- }
- private static int Roll(int amount) {
- gamble = Utils.random(amount);
- return gamble;
- }
- private static void sendNPCMessage(Player player, String message) {
- player.getDialogueManager().startDialogue("SimpleNPCMessage", GAMBLER_NPC_ID, message);
- }
- private static void handleCoinsCap(Player player) {
- if (!player.isVIPMember()) {
- GambleCapObject object = null;
- boolean exists = false;
- for (GambleCapObject o : RiggedGamblingCaps.getList()) {
- if (o.getMacAdress().equalsIgnoreCase(player.getCurrentMac())) {
- object = o;
- exists = true;
- break;
- }
- }
- if (!exists) {
- object = new GambleCapObject(player);
- RiggedGamblingCaps.addNewObject(object);
- }
- object.setCoinsGamble(object.getCoinsGamble() + 1);
- if (object.getCoinsGamble() == MAX_COINS_CAP) {
- object.setCoinsGamble(0);
- object.setCoinsCap(Utils.currentTimeMillis() + (RiggedDicing.COINS_HOURS_LIMIT * 60 * 60 * 1000));
- player.sm("You have reached your maximum GP gamble plays for now!");
- } else {
- player.sm("You have completed " + Colors.RED + object.getCoinsGamble() + "</col>/" + MAX_COINS_CAP
- + "; you still have " + Colors.RED + (MAX_COINS_CAP - object.getCoinsGamble())
- + " money gambe plays left.");
- }
- RiggedGamblingCaps.save();
- }
- }
- private static boolean isCoinsCap(Player player) {
- for (GambleCapObject object : RiggedGamblingCaps.getList()) {
- if (object.getMacAdress().equalsIgnoreCase(player.getCurrentMac())) {
- if (object.getCoinsCap() > Utils.currentTimeMillis()) {
- sendNPCMessage(player, "You have reached your maximum stakes now, Try again after </col>"
- + Utils.getTimeRemaining(object.getCoinsCap()) + ".");
- return true;
- }
- }
- }
- return false;
- }
- private static void handleItemGambleCap(Player player) {
- if (!player.isVIPMember()) {
- GambleCapObject object = null;
- boolean exists = false;
- for (GambleCapObject o : RiggedGamblingCaps.getList()) {
- if (o.getMacAdress().equalsIgnoreCase(player.getCurrentMac())) {
- object = o;
- exists = true;
- break;
- }
- }
- if (!exists) {
- object = new GambleCapObject(player);
- RiggedGamblingCaps.addNewObject(object);
- }
- object.setItemsGamble(object.getItemsGamble() + 1);
- if (object.getItemsGamble() == MAX_ITEMS_CAP) {
- object.setItemsGamble(0);
- object.setItemsCap(Utils.currentTimeMillis() + (RiggedDicing.ITEMS_HOURS_LIMIT * 60 * 60 * 1000));
- player.sm("You have reached your maximum item gamble plays for now!");
- } else {
- player.sm("You have completed " + Colors.RED + object.getItemsGamble() + "</col>/" + MAX_ITEMS_CAP
- + "; you still have " + Colors.RED + (MAX_ITEMS_CAP - object.getItemsGamble())
- + " item gamble plays left.");
- }
- RiggedGamblingCaps.save();
- }
- }
- private static boolean isItemCap(Player player) {
- for (GambleCapObject object : RiggedGamblingCaps.getList()) {
- if (object.getMacAdress().equalsIgnoreCase(player.getCurrentMac())) {
- if (object.getItemsCap() > Utils.currentTimeMillis()) {
- sendNPCMessage(player, "You have reached your maximum stakes now, Try again after </col>"
- + Utils.getTimeRemaining(object.getItemsCap()) + ".");
- return true;
- }
- }
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement