Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.49 KB | None | 0 0
  1. package com.rs.game.player.content;
  2.  
  3. import com.rs.game.Animation;
  4. import com.rs.game.ForceTalk;
  5. import com.rs.game.Graphics;
  6. import com.rs.game.World;
  7. import com.rs.game.item.Item;
  8. import com.rs.game.npc.NPC;
  9. import com.rs.game.player.Player;
  10. import com.rs.game.tasks.WorldTask;
  11. import com.rs.game.tasks.WorldTasksManager;
  12. import com.rs.utils.Colors;
  13. import com.rs.utils.RiggedGamblingCaps;
  14. import com.rs.utils.RiggedGamblingCaps.GambleCapObject;
  15. import com.rs.utils.Utils;
  16.  
  17. public class RiggedDicing {
  18.  
  19. private static int chance = 55, gamble = 100;
  20.  
  21. public static final int GAMBLER_NPC_ID = 659;
  22.  
  23. private static final int MAX_COINS_CAP = 3, MAX_ITEMS_CAP = 3;
  24. public static final int COINS_HOURS_LIMIT = 2, ITEMS_HOURS_LIMIT = 2;
  25.  
  26. public static boolean isOkitem(Player player, Item item) {
  27. if (!ItemConstants.isTradeable(item)) {
  28. player.closeInterfaces();
  29. sendNPCMessage(player, "You are not allowed to gamble untradable items!");
  30. return false;
  31. }
  32. if (item.getDefinitions().getTipitPrice() < 5_000_000) {
  33. player.closeInterfaces();
  34. sendNPCMessage(player, "Item price is too low to gamble, try something over 5M..");
  35. return false;
  36. }
  37. return true;
  38. }
  39.  
  40. public static void GambleItem(Player player, Item item, int amount) {
  41. if (isItemCap(player)) {
  42. return;
  43. }
  44. if (!isOkitem(player, item)) {
  45. return;
  46. }
  47. if (player.getInventory().getFreeSlots() < amount * 2) {
  48. player.closeInterfaces();
  49. sendNPCMessage(player, "You do not have sufficient space available, bank some items and try again.");
  50. return;
  51. }
  52. if (player.isLocked()) {
  53. player.closeInterfaces();
  54. sendNPCMessage(player, "Please finish what you are doing first.");
  55. return;
  56. }
  57. for (NPC npc : World.getNPCs()) {
  58. if (npc.getId() == GAMBLER_NPC_ID) {
  59. npc.setNextAnimation(new Animation(11900));
  60. npc.setNextGraphics(new Graphics(2075));
  61. npc.setNextForceTalk(new ForceTalk("Rolling..."));
  62. }
  63. }
  64. player.getInventory().deleteItem(new Item(item.getId(), amount));
  65. player.lock(3);
  66. sendNPCMessage(player, "Rolling... <br>Goodluck!");
  67. WorldTasksManager.schedule(new WorldTask() {
  68. int loop;
  69.  
  70. @Override
  71. public void run() {
  72. sendNPCMessage(player, "Rolling... <br>Goodluck!");
  73. if (loop == 3) {
  74. stop();
  75. Roll(100);
  76. player.getInterfaceManager().closeChatBoxInterface();
  77. Check(player, item, amount);
  78. }
  79. loop++;
  80. }
  81. }, 0, 1);
  82. handleItemGambleCap(player);
  83. }
  84.  
  85. public static void GambleMoney(Player player, int money) {
  86. if (isCoinsCap(player)) {
  87. return;
  88. }
  89. if (money < 1_000_000 || money > 50_000_000) {
  90. player.closeInterfaces();
  91. sendNPCMessage(player, "<col=ff0000>Min: 1M - Max: 50M! to increase your limits, upgrade your donor rank!");
  92. return;
  93. }
  94. if (!player.hasMoney(money)) {
  95. player.closeInterfaces();
  96. sendNPCMessage(player, "You don't have the money to do that.");
  97. return;
  98. }
  99. if (player.hasMoney(Integer.MAX_VALUE - money) || player.hasMoney(Integer.MAX_VALUE)) {
  100. sendNPCMessage(player, "You cannot do that, try banking some GP.");
  101. return;
  102. }
  103. if (player.isLocked()) {
  104. player.closeInterfaces();
  105. sendNPCMessage(player, "Please finish what you are doing first.");
  106. return;
  107. }
  108. for (NPC npc : World.getNPCs()) {
  109. if (npc.getId() == GAMBLER_NPC_ID) {
  110. npc.setNextAnimation(new Animation(11900));
  111. npc.setNextGraphics(new Graphics(2075));
  112. npc.setNextForceTalk(new ForceTalk("Rolling..."));
  113. }
  114. }
  115. player.takeMoney(money);
  116. player.lock(3);
  117. sendNPCMessage(player, "Rolling... <br>Goodluck!");
  118. WorldTasksManager.schedule(new WorldTask() {
  119. int loop;
  120.  
  121. @Override
  122. public void run() {
  123. sendNPCMessage(player, "Rolling... <br>Goodluck!");
  124. if (loop == 3) {
  125. stop();
  126. Roll(100);
  127. player.getInterfaceManager().closeChatBoxInterface();
  128. Check(player, money);
  129. }
  130. loop++;
  131. }
  132. }, 0, 1);
  133. handleCoinsCap(player);
  134. }
  135.  
  136. private static void Check(Player player, Item item, int amount) {
  137. if (!isWinner()) {
  138. for (NPC npc : World.getNPCs()) {
  139. if (npc.getId() == GAMBLER_NPC_ID) {
  140. WorldTasksManager.schedule(new WorldTask() {
  141.  
  142. @Override
  143. public void run() {
  144. sendNPCMessage(player,
  145. "<col=ff0000>Rolled " + getNumberRolled() + ", Unlucky " + player.getDisplayName()
  146. + ", you have lost the bet of " + amount * 2 + "x " + item.getName() + ".");
  147. npc.setNextForceTalk(new ForceTalk("<col=ff0000>Rolled " + getNumberRolled() + ", Unlucky "
  148. + player.getDisplayName() + ", you have lost the bet of " + amount * 2 + "x "
  149. + item.getName() + "."));
  150. }
  151. }, 0);
  152. }
  153. }
  154. player.sm("You lost! :( You rolled <col=ff0000>" + getNumberRolled() + "</col>. Had you rolled <col=ff0000>"
  155. + (chance - getNumberRolled()) + "</col> more you would have won.");
  156. return;
  157. }
  158. int betWealth = item.getDefinitions().getTipitPrice() * amount * 2;
  159. if (betWealth >= 250_000_000) {
  160. World.sendWorldMessage("<img=7><col=FF0033>Server: " + player.getDisplayName() + " won "
  161. + Utils.formatAmount2(betWealth) + " bet from Gambling.", false);
  162. }
  163. for (NPC npc : World.getNPCs()) {
  164. if (npc.getId() == GAMBLER_NPC_ID) {
  165. WorldTasksManager.schedule(new WorldTask() {
  166.  
  167. @Override
  168. public void run() {
  169. sendNPCMessage(player,
  170. "Rolled " + getNumberRolled() + "</col>, and congratulations " + player.getDisplayName()
  171. + ", you have won " + amount * 2 + "x " + item.getName() + ".");
  172. npc.setNextForceTalk(new ForceTalk(
  173. "Rolled " + getNumberRolled() + ", and congratulations " + player.getDisplayName()
  174. + ", you have won " + amount * 2 + "x " + item.getName() + "."));
  175. }
  176. }, 0);
  177. }
  178. }
  179. player.setNextGraphics(new Graphics(743));
  180. player.addItem(new Item(item.getId(), amount * 2));
  181. sendNPCMessage(player, "<col=ff000>You rolled " + getNumberRolled() + ", Congratulations. You have won "
  182. + amount * 2 + "x " + item.getName() + ".");
  183. return;
  184. }
  185.  
  186. private static void Check(Player player, int money) {
  187. if (!isWinner()) {
  188. for (NPC npc : World.getNPCs()) {
  189. if (npc.getId() == GAMBLER_NPC_ID) {
  190. WorldTasksManager.schedule(new WorldTask() {
  191. @Override
  192. public void run() {
  193. sendNPCMessage(player,
  194. "Rolled " + getNumberRolled() + ", Unlucky " + player.getDisplayName()
  195. + ", you have lost the bet of " + Prize(money) + " coins.");
  196. npc.setNextForceTalk(
  197. new ForceTalk("Rolled " + getNumberRolled() + ", Unlucky " + player.getDisplayName()
  198. + ", you have lost the bet of " + Prize(money) + " coins."));
  199. }
  200. }, 0);
  201. }
  202. }
  203. player.sm("You lost! :( You rolled <col=ff0000>" + getNumberRolled() + "</col>. Had you rolled <col=ff0000>"
  204. + (chance - getNumberRolled()) + "</col> more you would have won.");
  205. return;
  206. }
  207. if (Prize(money) >= 250_000_000) {
  208. World.sendWorldMessage("<img=7><col=FF0033>Server: " + player.getDisplayName() + " won "
  209. + Utils.getFormattedNumber((Prize(money) / 2)) + " coins from Gambling.", false);
  210. }
  211. for (NPC npc : World.getNPCs()) {
  212. if (npc.getId() == GAMBLER_NPC_ID) {
  213. WorldTasksManager.schedule(new WorldTask() {
  214. @Override
  215. public void run() {
  216. sendNPCMessage(player,
  217. "<col=00ff00>Rolled " + getNumberRolled() + "</col>, and congratulations "
  218. + player.getDisplayName() + ", you have won "
  219. + Utils.getFormattedNumber((Prize(money) / 2)) + " coins.");
  220. npc.setNextForceTalk(new ForceTalk("<col=00ff00>Rolled " + getNumberRolled()
  221. + ", and congratulations " + player.getDisplayName() + ", you have won "
  222. + Utils.getFormattedNumber((Prize(money) / 2)) + " coins."));
  223. }
  224. }, 0);
  225. }
  226. }
  227. player.setNextGraphics(new Graphics(743));
  228. player.getMoneyPouch().addMoney(Prize(money), false);
  229. sendNPCMessage(player, "<col=ff000>You rolled " + getNumberRolled() + ", Congratulations. You have won "
  230. + Utils.getFormattedNumber((Prize(money) / 2), ',') + " GP.");
  231. return;
  232. }
  233.  
  234. private static int Prize(int value) {
  235. return value * 2;
  236. }
  237.  
  238. private static int getNumberRolled() {
  239. return gamble;
  240. }
  241.  
  242. private static boolean isWinner() {
  243. return gamble >= chance;
  244. }
  245.  
  246. private static int Roll(int amount) {
  247. gamble = Utils.random(amount);
  248. return gamble;
  249. }
  250.  
  251. private static void sendNPCMessage(Player player, String message) {
  252. player.getDialogueManager().startDialogue("SimpleNPCMessage", GAMBLER_NPC_ID, message);
  253. }
  254.  
  255. private static void handleCoinsCap(Player player) {
  256. if (!player.isVIPMember()) {
  257. GambleCapObject object = null;
  258. boolean exists = false;
  259. for (GambleCapObject o : RiggedGamblingCaps.getList()) {
  260. if (o.getMacAdress().equalsIgnoreCase(player.getCurrentMac())) {
  261. object = o;
  262. exists = true;
  263. break;
  264. }
  265. }
  266. if (!exists) {
  267. object = new GambleCapObject(player);
  268. RiggedGamblingCaps.addNewObject(object);
  269. }
  270. object.setCoinsGamble(object.getCoinsGamble() + 1);
  271. if (object.getCoinsGamble() == MAX_COINS_CAP) {
  272. object.setCoinsGamble(0);
  273. object.setCoinsCap(Utils.currentTimeMillis() + (RiggedDicing.COINS_HOURS_LIMIT * 60 * 60 * 1000));
  274. player.sm("You have reached your maximum GP gamble plays for now!");
  275. } else {
  276. player.sm("You have completed " + Colors.RED + object.getCoinsGamble() + "</col>/" + MAX_COINS_CAP
  277. + "; you still have " + Colors.RED + (MAX_COINS_CAP - object.getCoinsGamble())
  278. + " money gambe plays left.");
  279. }
  280. RiggedGamblingCaps.save();
  281. }
  282. }
  283.  
  284. private static boolean isCoinsCap(Player player) {
  285. for (GambleCapObject object : RiggedGamblingCaps.getList()) {
  286. if (object.getMacAdress().equalsIgnoreCase(player.getCurrentMac())) {
  287. if (object.getCoinsCap() > Utils.currentTimeMillis()) {
  288. sendNPCMessage(player, "You have reached your maximum stakes now, Try again after </col>"
  289. + Utils.getTimeRemaining(object.getCoinsCap()) + ".");
  290. return true;
  291. }
  292. }
  293. }
  294. return false;
  295. }
  296.  
  297. private static void handleItemGambleCap(Player player) {
  298. if (!player.isVIPMember()) {
  299. GambleCapObject object = null;
  300. boolean exists = false;
  301. for (GambleCapObject o : RiggedGamblingCaps.getList()) {
  302. if (o.getMacAdress().equalsIgnoreCase(player.getCurrentMac())) {
  303. object = o;
  304. exists = true;
  305. break;
  306. }
  307. }
  308. if (!exists) {
  309. object = new GambleCapObject(player);
  310. RiggedGamblingCaps.addNewObject(object);
  311. }
  312. object.setItemsGamble(object.getItemsGamble() + 1);
  313. if (object.getItemsGamble() == MAX_ITEMS_CAP) {
  314. object.setItemsGamble(0);
  315. object.setItemsCap(Utils.currentTimeMillis() + (RiggedDicing.ITEMS_HOURS_LIMIT * 60 * 60 * 1000));
  316. player.sm("You have reached your maximum item gamble plays for now!");
  317. } else {
  318. player.sm("You have completed " + Colors.RED + object.getItemsGamble() + "</col>/" + MAX_ITEMS_CAP
  319. + "; you still have " + Colors.RED + (MAX_ITEMS_CAP - object.getItemsGamble())
  320. + " item gamble plays left.");
  321. }
  322. RiggedGamblingCaps.save();
  323. }
  324. }
  325.  
  326. private static boolean isItemCap(Player player) {
  327. for (GambleCapObject object : RiggedGamblingCaps.getList()) {
  328. if (object.getMacAdress().equalsIgnoreCase(player.getCurrentMac())) {
  329. if (object.getItemsCap() > Utils.currentTimeMillis()) {
  330. sendNPCMessage(player, "You have reached your maximum stakes now, Try again after </col>"
  331. + Utils.getTimeRemaining(object.getItemsCap()) + ".");
  332. return true;
  333. }
  334. }
  335. }
  336. return false;
  337. }
  338. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement