Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package red.man10.mappstore.apps;
- import org.bukkit.Bukkit;
- import org.bukkit.entity.Player;
- import red.man10.mappstore.DynamicMapRenderer;
- import java.util.HashMap;
- import java.util.Random;
- import java.awt.*;
- import org.bukkit.World;
- import org.bukkit.Sound;
- public class BounensSlots {
- ////////////////////////////////////////////
- // App name (must be unique)
- // アプリ名:ユニークな必要があります
- static String appName = "Bounen";
- ////////////////////////////////////////////
- // 変数 管理
- static Graphics2D g;
- static int mapId;
- static int amount;
- static Player clickplayer;
- static int slot_mode = 0;//0=回してない 1=回してる途中 2=回し終えたあと
- static int slot_seconds;
- static int hit;
- static int hit_number;
- static int hit_chance;
- static int slots_number;
- static String slot_name;
- static String picture[] = new String[3];
- static int slot_picture[] = new int[30];
- static int rool_time[] = new int[3];
- static int slot_picture_amount;
- static String slot_images[] = new String[30];
- static String slot_back;
- ///////////////////////////////
- // Data
- ///////////////////////////////
- static class MappData {
- int data;
- int amount;
- Player clickplayer;
- int slot_mode;
- static int coin_use;
- static int hit_coin;
- int slot_seconds;
- int hit;
- int hit_number;
- int rool_time[];
- int slot_images[];
- int slot_picture[];
- String picture[];
- String slot_name;
- String slot_back;
- int slot_picture_amount;
- }
- static HashMap<Integer, BounensSlots.MappData> hashMap = new HashMap<Integer, BounensSlots.MappData>();
- // 読み込み
- static MappData loadData(int mapId) {
- MappData data = hashMap.get(mapId);
- if (data == null) {
- data = new MappData();
- }
- return data;
- }
- // 保存
- static MappData saveData(int mapId, MappData data) {
- return hashMap.put(mapId, data);
- }
- ///////////////////////////////////////////////////////
- // Call this function to register the your app
- // アプリを登録するためにこの関数をコールしてください
- static public void register() {
- /////////////////////////////////////////////////
- // Display touch event
- // ディスプレイがタッチされた時の処理
- DynamicMapRenderer.registerDisplayTouchEvent(appName, (String key, int mapId, Player player, int x, int y) -> {
- Graphics2D gr = DynamicMapRenderer.getGraphics(mapId);
- if (gr == null) {
- return false;
- }
- gr.setColor(Color.RED);
- gr.drawLine(x, y, x, y);
- return true;
- });
- /////////////////////////////////////////////////
- // Button (nearby map) clicked event
- DynamicMapRenderer.registerButtonEvent(appName, (String key, int mapId, Player player) -> {
- Graphics2D g = DynamicMapRenderer.getGraphics(mapId);
- if (g == null) {
- return false;
- }
- MappData m = loadData(mapId);
- m.slot_mode=0;
- m.clickplayer = player;
- m.clickplayer.sendMessage("§b§l[Bounen'§f§lsSlot]§a"+mapId);
- //スロットを回そうとするときの処理
- if (m.slot_mode == 0) {
- new slot_datas().slots_datas(0);
- m.slot_mode = 1;
- m.clickplayer.sendMessage("§b§l[Bounen'§f§lsSlot]§aスロットを回しました!");
- saveData(mapId, m);
- ////////////////////
- //当たったかどうか判定
- if (new Random().nextInt(10000) <= hit_chance) {
- m.hit = 1;
- m.hit_number = new Random().nextInt(m.slot_picture_amount);
- }else{
- m.clickplayer.sendMessage("§b§l[Bounen'§f§lsSlot]§cこのスロットは回されています!");
- }
- }
- saveData(mapId, m);
- return true;
- });
- /////////////////////////////////////////////////
- // drawing logic
- DynamicMapRenderer.register(appName, 30, (String key, int mapId, Graphics2D g) -> {
- MappData m = loadData(mapId);
- //////////////////////
- //スロット 回転途中の処理
- if (m.slot_mode == 1) {
- m.slot_seconds = m.slot_seconds + 1;
- if (m.slot_seconds >= m.rool_time[2] + 1) {
- // Bukkit.broadcastMessage("§b§l[Bounen'§f§lsSlot]§3デバッグ:3");
- m.slot_mode = 2;
- m.hit = 0;
- //当たり
- if (m.picture[0].equalsIgnoreCase(m.picture[1]) && m.picture[1].equalsIgnoreCase(m.picture[2])) {
- m.clickplayer.sendMessage("§b§l[Bounen'§f§lsSlot]§e§lおめでとうございます! コイン" + m.hit_coin + "枚獲得!");
- m.amount = m.amount + m.hit_coin;//あたり追加
- DynamicMapRenderer.drawImage(g, m.picture[2] + "", 82, 32, 32, 32);
- World w = m.clickplayer.getWorld();//sounds
- w.playSound(m.clickplayer.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 2, 1);
- return true;
- }
- else {//ハズレ
- m.clickplayer.sendMessage("§b§l[Bounen'§f§lsSlot]§b§lハズレ");
- }
- }
- //絵柄
- if (m.slot_seconds <= m.rool_time[0]) {
- BounensSlots.slot_picture(0);
- }
- if (m.slot_seconds <= m.rool_time[1]) {
- BounensSlots.slot_picture(1);
- }
- if (m.slot_seconds <= m.rool_time[2]) {
- BounensSlots.slot_picture(2);
- }
- //Sounds
- World w = m.clickplayer.getWorld();
- w.playSound(m.clickplayer.getLocation(), Sound.BLOCK_DISPENSER_FAIL, 1, 2);
- }
- /////////////
- //スロット 描画
- // if (m.slot_mode == 1 || m.slot_mode == 2) {
- Bukkit.broadcastMessage("§b§l[Bounen'§f§lsSlot]§3mapId:"+mapId+" mode:"+slot_mode);
- DynamicMapRenderer.drawImage(g, m.slot_back + "", 0, 0, 128, 128);
- g.setColor(Color.BLACK);
- g.setFont(new Font("SansSerif", Font.BOLD, 10));
- g.drawString("[" + m.slot_name + "]", 0, 85);
- g.drawString("1 play: " + m.coin_use + "枚", 0, 98);
- g.drawString("当たり: " + m.hit_coin + "枚", 0, 111);
- g.setColor(Color.DARK_GRAY);
- g.fillRect(13, 24, 103, 49);//52
- g.setColor(Color.GRAY);
- g.fillRect(13, 26, 103, 45);//50
- g.setColor(Color.LIGHT_GRAY);
- g.fillRect(13, 29, 103, 39);//48
- g.setColor(Color.WHITE);
- g.fillRect(13, 32, 103, 33);//46
- g.setFont(new Font("SansSerif", Font.BOLD, 16));
- g.setColor(Color.YELLOW);
- g.drawString("所持コイン: " + m.amount, 0, 124);
- DynamicMapRenderer.drawImage(g, m.picture[0] + "", 14, 32, 32, 32);
- DynamicMapRenderer.drawImage(g, m.picture[1] + "", 48, 32, 32, 32);
- DynamicMapRenderer.drawImage(g, m.picture[2] + "", 82, 32, 32, 32);
- if(m.slot_mode==2){m.slot_mode=0;}
- return true;
- /* }
- if (m.slot_mode == 0) {
- return false;
- }
- saveData(mapId, m);
- return false;*/
- });
- }
- static public void slot_picture(int in_amount) {
- MappData m = loadData(mapId);
- int randomNumber = new Random().nextInt(m.slot_picture_amount);
- picture[in_amount]=""+m.slot_images[randomNumber];
- //当選 絵柄を揃える処理
- if(hit==1 && (m.slot_seconds==m.rool_time[0] || m.slot_seconds==m.rool_time[1] || m.slot_seconds>=m.rool_time[2])){
- if (m.slot_seconds == m.rool_time[0]) { m.picture[0] = new String("" + m.slot_images[m.hit_number]).toString(); }
- if (m.slot_seconds == m.rool_time[1]) { m.picture[1] = new String("" + m.slot_images[m.hit_number]).toString(); }
- if (m.slot_seconds >= m.rool_time[2]) { m.picture[2] = new String("" + m.slot_images[m.hit_number]).toString(); }
- }
- saveData(mapId,m);
- }
- }
- class slot_datas{
- public void slots_datas(int slots_number){
- BounensSlots.MappData m = BounensSlots.loadData(BounensSlots.mapId);
- switch (slots_number){
- case 0:
- m.slot_name="βスロット";
- m.slot_back="bounenslot_fairy";
- BounensSlots.hit_chance=10000;// <hit_chans>/10000の確率で当たる
- m.slot_picture_amount=4;//使う絵柄の枚数
- BounensSlots.slot_images[0]="bounenslot_diamond_hoe";//0から1としてカウントしてね
- BounensSlots.slot_images[1]="bounenslot_bread";//サイズ 16*16 or 32*32
- BounensSlots.slot_images[2]="bounenslot_wheat";
- BounensSlots.slot_images[3]="bounenslot_seeds_wheat";
- m.coin_use=1;//回す時に使う枚数
- m.hit_coin=2;//当たりの枚数
- m.rool_time[0]=30;//ロールが回る時間 左
- m.rool_time[1]=60;//ロールが回る時間 中
- m.rool_time[2]=90;//ロールが回る時間 右
- }
- BounensSlots.saveData(BounensSlots.mapId, m);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement