Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.37 KB | None | 0 0
  1. package com.arlania.world.content;
  2.  
  3. import com.arlania.model.Item;
  4. import com.arlania.util.Misc;
  5. import com.arlania.world.entity.impl.player.Player;
  6. import com.google.common.collect.ImmutableSet;
  7. import com.google.common.collect.Sets;
  8.  
  9. import java.util.ArrayList;
  10. import java.util.Collections;
  11. import java.util.EnumSet;
  12. import java.util.List;
  13.  
  14. public class SlotMachine {
  15.  
  16.  
  17. public static final int INTERFACE_ID = 29030;
  18.  
  19. private static final int REWARD_SLOT = 29036;
  20.  
  21. private static final int SLOTS_ITEM_CONTAINER = 29033;
  22.  
  23. private static final int RESULT_STRING = 29047;
  24. private static final int WINNER_ITEM = 3981;
  25. private static final int LOSER_ITEM = 6570;
  26.  
  27. //we could make it construct this list everytime, but instead we'll just cache it and shuffle it.
  28. private static final List<Item> WINNING = List.of(new Item[]{new Item(WINNER_ITEM), new Item(WINNER_ITEM), new Item(WINNER_ITEM)});
  29. private static final List<Item> LOSING = List.of(new Item[]{new Item(WINNER_ITEM), new Item(WINNER_ITEM), new Item(LOSER_ITEM)});
  30. private static final List<Item> LOSING1 = List.of(new Item[]{new Item(WINNER_ITEM), new Item(LOSER_ITEM), new Item(LOSER_ITEM)});
  31. private static final List<Item> LOSING2 = List.of(new Item[]{new Item(LOSER_ITEM), new Item(LOSER_ITEM), new Item(LOSER_ITEM)});
  32.  
  33.  
  34. private static final List<List<Item>> LOSER_LISTS = List.of(LOSING, LOSING1, LOSING2);
  35.  
  36. private static final String LOSER_MESSAGE = "@red@Bad luck! Try again";
  37. private static final String WINNER_MESSAGE = "@gr1@Winner! Congratulations";
  38.  
  39.  
  40. public static void openInterface(Player player) {
  41. if(!player.getClickDelay().elapsed(600)) {
  42. return;
  43. }
  44. player.getPacketSender().sendItemsOnInterface(SLOTS_ITEM_CONTAINER, 3, List.of(new Item[]{new Item(688, 0), new Item(688, 0), new Item(688, 0)}), true);
  45. player.getPacketSender().sendInterface(INTERFACE_ID);
  46. }
  47.  
  48. private static void resetInterface(Player player) {
  49.  
  50. }
  51.  
  52. public static void roll(Player player) {
  53.  
  54.  
  55. if(!player.getInventory().containsAny(691, 692, 693)) {
  56. player.sendMessage("You don't have any slot tickets!");
  57. return;
  58. }
  59. player.getPacketSender().sendItemOnInterface(REWARD_SLOT, 0, 0);
  60.  
  61. SlotGameType type = SlotGameType.getType(player);
  62. if(type == null)
  63. return;
  64. boolean winner = false;
  65. if(Misc.getRandom(100) <= type.getRarity()) {
  66. winner = true;
  67. }
  68. player.getInventory().delete(type.getId(), 1);
  69. player.getPacketSender().sendFrame126(RESULT_STRING, winner ? WINNER_MESSAGE : LOSER_MESSAGE);
  70. if(winner) {
  71. player.getPacketSender().sendItemsOnInterface(SLOTS_ITEM_CONTAINER, 3, WINNING, true);
  72. player.getPacketSender().sendItemOnInterface(REWARD_SLOT, 11694, 0);
  73. } else {
  74. List<Item> list = new ArrayList<>(Misc.randomElement(LOSER_LISTS));
  75. Collections.shuffle(list);
  76. player.getPacketSender().sendItemsOnInterface(SLOTS_ITEM_CONTAINER, 3, list, true);
  77. }
  78. }
  79.  
  80.  
  81. private static void reward(Player player, SlotGameType type) {
  82.  
  83. }
  84.  
  85. private boolean canUse(Player player) {
  86. return player.getInventory().containsAny(691, 692, 693);
  87. }
  88.  
  89.  
  90. public enum SlotGameType {
  91. TIER_1(691,10),
  92. TIER_2(692, 10),
  93. TIER_3(693, 10);
  94.  
  95. private int id;
  96. private int rarity;
  97.  
  98. SlotGameType(int id, int rarity) {
  99. this.id = id;
  100. this.rarity = rarity;
  101. }
  102.  
  103. public int getId() {
  104. return id;
  105. }
  106.  
  107. public int getRarity() {
  108. return rarity;
  109. }
  110.  
  111. public static final ImmutableSet<SlotGameType> VALUES = Sets.immutableEnumSet(EnumSet.allOf(SlotGameType.class));
  112.  
  113.  
  114. public static SlotGameType of(int id) {
  115. for(SlotGameType type : VALUES) {
  116. if(id == type.getId())
  117. return type;
  118. }
  119. return null;
  120. }
  121. private static SlotGameType getType(Player player) {
  122.  
  123. for(SlotGameType type : SlotGameType.VALUES) {
  124. if(player.getInventory().contains(type.getId()))
  125. return type;
  126. }
  127.  
  128. return null;
  129. }
  130. }
  131.  
  132.  
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement