Advertisement
Bounen

Untitled

May 12th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.01 KB | None | 0 0
  1. package red.man10.mappstore.apps;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.entity.Player;
  5. import red.man10.mappstore.DynamicMapRenderer;
  6. import java.util.HashMap;
  7. import java.util.Random;
  8. import java.awt.*;
  9. import org.bukkit.World;
  10. import org.bukkit.Sound;
  11.  
  12. public class BounensSlots {
  13. ////////////////////////////////////////////
  14. // App name (must be unique)
  15. // アプリ名:ユニークな必要があります
  16. static String appName = "Bounen";
  17. ////////////////////////////////////////////
  18. // 変数 管理
  19. static Graphics2D g;
  20. static int mapId;
  21. static int amount;
  22. static Player clickplayer;
  23.  
  24. static int slot_mode = 0;//0=回してない 1=回してる途中 2=回し終えたあと
  25. static int slot_seconds;
  26. static int hit;
  27. static int hit_number;
  28. static int hit_chance;
  29. static int slots_number;
  30.  
  31. static String slot_name;
  32. static String picture[] = new String[3];
  33. static int slot_picture[] = new int[30];
  34. static int rool_time[] = new int[3];
  35. static int slot_picture_amount;
  36. static String slot_images[] = new String[30];
  37. static String slot_back;
  38.  
  39. ///////////////////////////////
  40. // Data
  41. ///////////////////////////////
  42. static class MappData {
  43. int data;
  44. int amount;
  45. Player clickplayer;
  46. int slot_mode;
  47. static int coin_use;
  48. static int hit_coin;
  49. int slot_seconds;
  50. int hit;
  51. int hit_number;
  52. int rool_time[];
  53. int slot_images[];
  54. int slot_picture[];
  55. String picture[];
  56.  
  57. String slot_name;
  58. String slot_back;
  59. int slot_picture_amount;
  60.  
  61.  
  62. }
  63.  
  64. static HashMap<Integer, BounensSlots.MappData> hashMap = new HashMap<Integer, BounensSlots.MappData>();
  65.  
  66. // 読み込み
  67. static MappData loadData(int mapId) {
  68. MappData data = hashMap.get(mapId);
  69. if (data == null) {
  70. data = new MappData();
  71. }
  72. return data;
  73. }
  74.  
  75. // 保存
  76. static MappData saveData(int mapId, MappData data) {
  77. return hashMap.put(mapId, data);
  78. }
  79.  
  80.  
  81. ///////////////////////////////////////////////////////
  82. // Call this function to register the your app
  83. // アプリを登録するためにこの関数をコールしてください
  84. static public void register() {
  85. /////////////////////////////////////////////////
  86. // Display touch event
  87. // ディスプレイがタッチされた時の処理
  88. DynamicMapRenderer.registerDisplayTouchEvent(appName, (String key, int mapId, Player player, int x, int y) -> {
  89. Graphics2D gr = DynamicMapRenderer.getGraphics(mapId);
  90. if (gr == null) {
  91. return false;
  92. }
  93.  
  94. gr.setColor(Color.RED);
  95. gr.drawLine(x, y, x, y);
  96.  
  97. return true;
  98. });
  99.  
  100. /////////////////////////////////////////////////
  101. // Button (nearby map) clicked event
  102. DynamicMapRenderer.registerButtonEvent(appName, (String key, int mapId, Player player) -> {
  103. Graphics2D g = DynamicMapRenderer.getGraphics(mapId);
  104. if (g == null) {
  105. return false;
  106. }
  107. MappData m = loadData(mapId);
  108.  
  109. m.slot_mode=0;
  110. m.clickplayer = player;
  111. m.clickplayer.sendMessage("§b§l[Bounen'§f§lsSlot]§a"+mapId);
  112. //スロットを回そうとするときの処理
  113. if (m.slot_mode == 0) {
  114. new slot_datas().slots_datas(0);
  115. m.slot_mode = 1;
  116. m.clickplayer.sendMessage("§b§l[Bounen'§f§lsSlot]§aスロットを回しました!");
  117. saveData(mapId, m);
  118.  
  119. ////////////////////
  120. //当たったかどうか判定
  121. if (new Random().nextInt(10000) <= hit_chance) {
  122. m.hit = 1;
  123. m.hit_number = new Random().nextInt(m.slot_picture_amount);
  124. }else{
  125. m.clickplayer.sendMessage("§b§l[Bounen'§f§lsSlot]§cこのスロットは回されています!");
  126. }
  127. }
  128.  
  129. saveData(mapId, m);
  130. return true;
  131. });
  132.  
  133. /////////////////////////////////////////////////
  134. // drawing logic
  135. DynamicMapRenderer.register(appName, 30, (String key, int mapId, Graphics2D g) -> {
  136. MappData m = loadData(mapId);
  137. //////////////////////
  138. //スロット 回転途中の処理
  139. if (m.slot_mode == 1) {
  140. m.slot_seconds = m.slot_seconds + 1;
  141. if (m.slot_seconds >= m.rool_time[2] + 1) {
  142. // Bukkit.broadcastMessage("§b§l[Bounen'§f§lsSlot]§3デバッグ:3");
  143. m.slot_mode = 2;
  144. m.hit = 0;
  145. //当たり
  146. if (m.picture[0].equalsIgnoreCase(m.picture[1]) && m.picture[1].equalsIgnoreCase(m.picture[2])) {
  147. m.clickplayer.sendMessage("§b§l[Bounen'§f§lsSlot]§e§lおめでとうございます! コイン" + m.hit_coin + "枚獲得!");
  148. m.amount = m.amount + m.hit_coin;//あたり追加
  149. DynamicMapRenderer.drawImage(g, m.picture[2] + "", 82, 32, 32, 32);
  150.  
  151. World w = m.clickplayer.getWorld();//sounds
  152. w.playSound(m.clickplayer.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 2, 1);
  153. return true;
  154. }
  155. else {//ハズレ
  156. m.clickplayer.sendMessage("§b§l[Bounen'§f§lsSlot]§b§lハズレ");
  157. }
  158. }
  159.  
  160.  
  161. //絵柄
  162. if (m.slot_seconds <= m.rool_time[0]) {
  163. BounensSlots.slot_picture(0);
  164. }
  165. if (m.slot_seconds <= m.rool_time[1]) {
  166. BounensSlots.slot_picture(1);
  167. }
  168. if (m.slot_seconds <= m.rool_time[2]) {
  169. BounensSlots.slot_picture(2);
  170. }
  171. //Sounds
  172. World w = m.clickplayer.getWorld();
  173. w.playSound(m.clickplayer.getLocation(), Sound.BLOCK_DISPENSER_FAIL, 1, 2);
  174.  
  175. }
  176. /////////////
  177. //スロット 描画
  178. // if (m.slot_mode == 1 || m.slot_mode == 2) {
  179. Bukkit.broadcastMessage("§b§l[Bounen'§f§lsSlot]§3mapId:"+mapId+" mode:"+slot_mode);
  180. DynamicMapRenderer.drawImage(g, m.slot_back + "", 0, 0, 128, 128);
  181.  
  182. g.setColor(Color.BLACK);
  183. g.setFont(new Font("SansSerif", Font.BOLD, 10));
  184. g.drawString("[" + m.slot_name + "]", 0, 85);
  185. g.drawString("1 play: " + m.coin_use + "枚", 0, 98);
  186. g.drawString("当たり: " + m.hit_coin + "枚", 0, 111);
  187.  
  188. g.setColor(Color.DARK_GRAY);
  189. g.fillRect(13, 24, 103, 49);//52
  190. g.setColor(Color.GRAY);
  191. g.fillRect(13, 26, 103, 45);//50
  192. g.setColor(Color.LIGHT_GRAY);
  193. g.fillRect(13, 29, 103, 39);//48
  194. g.setColor(Color.WHITE);
  195. g.fillRect(13, 32, 103, 33);//46
  196.  
  197. g.setFont(new Font("SansSerif", Font.BOLD, 16));
  198. g.setColor(Color.YELLOW);
  199. g.drawString("所持コイン: " + m.amount, 0, 124);
  200.  
  201. DynamicMapRenderer.drawImage(g, m.picture[0] + "", 14, 32, 32, 32);
  202. DynamicMapRenderer.drawImage(g, m.picture[1] + "", 48, 32, 32, 32);
  203. DynamicMapRenderer.drawImage(g, m.picture[2] + "", 82, 32, 32, 32);
  204. if(m.slot_mode==2){m.slot_mode=0;}
  205. return true;
  206. /* }
  207. if (m.slot_mode == 0) {
  208. return false;
  209. }
  210. saveData(mapId, m);
  211. return false;*/
  212. });
  213. }
  214.  
  215. static public void slot_picture(int in_amount) {
  216. MappData m = loadData(mapId);
  217.  
  218. int randomNumber = new Random().nextInt(m.slot_picture_amount);
  219. picture[in_amount]=""+m.slot_images[randomNumber];
  220. //当選 絵柄を揃える処理
  221. if(hit==1 && (m.slot_seconds==m.rool_time[0] || m.slot_seconds==m.rool_time[1] || m.slot_seconds>=m.rool_time[2])){
  222. if (m.slot_seconds == m.rool_time[0]) { m.picture[0] = new String("" + m.slot_images[m.hit_number]).toString(); }
  223. if (m.slot_seconds == m.rool_time[1]) { m.picture[1] = new String("" + m.slot_images[m.hit_number]).toString(); }
  224. if (m.slot_seconds >= m.rool_time[2]) { m.picture[2] = new String("" + m.slot_images[m.hit_number]).toString(); }
  225. }
  226.  
  227. saveData(mapId,m);
  228. }
  229.  
  230. }
  231. class slot_datas{
  232. public void slots_datas(int slots_number){
  233. BounensSlots.MappData m = BounensSlots.loadData(BounensSlots.mapId);
  234. switch (slots_number){
  235. case 0:
  236. m.slot_name="βスロット";
  237. m.slot_back="bounenslot_fairy";
  238. BounensSlots.hit_chance=10000;// <hit_chans>/10000の確率で当たる
  239.  
  240. m.slot_picture_amount=4;//使う絵柄の枚数
  241. BounensSlots.slot_images[0]="bounenslot_diamond_hoe";//0から1としてカウントしてね
  242. BounensSlots.slot_images[1]="bounenslot_bread";//サイズ 16*16 or 32*32
  243. BounensSlots.slot_images[2]="bounenslot_wheat";
  244. BounensSlots.slot_images[3]="bounenslot_seeds_wheat";
  245.  
  246. m.coin_use=1;//回す時に使う枚数
  247. m.hit_coin=2;//当たりの枚数
  248.  
  249. m.rool_time[0]=30;//ロールが回る時間 左
  250. m.rool_time[1]=60;//ロールが回る時間 中
  251. m.rool_time[2]=90;//ロールが回る時間 右
  252. }
  253. BounensSlots.saveData(BounensSlots.mapId, m);
  254.  
  255. }
  256. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement