const PN_DiceBack = 460;
const PN_DiceWin = PN_DiceBack + 1;
const PN_Dice_Anime = PN_DiceWin + 1;
const PN_Dice_StopUI = PN_Dice_Anime + 1;
const VN_ダイス結果 = 46;
var DicePic = "pictures/Dice/";
//ダイス用クラス(10面)
class NDice {
    constructor(DicePicName) {
        this.PicName = DicePicName;
        this.RollFlg = true; 
        this.RndNo = 0; 
        this.KekkaNo = 0; 
        this.Kekka = 0; 
        this.RndMax = 4; 
        this.RollSpan = 4; 
        this.CellCount = this.RndMax + 10; 
    }
}
NDice.prototype.Rolling = function (_Timer) {
    if (_Timer % this.RollSpan == 0) {
        while (true) {
            var _setrnd = Math.floor(Math.random() * (this.RndMax));
            if (_setrnd != this.RndNo) {
                this.RndNo = _setrnd;
                break; 
            }
        }
    }
}
NDice.prototype.RollKekka = function () {
    this.RollFlg = false; 
    this.Kekka = Math.floor(Math.random() * 10); 
    this.KekkaNo = this.RndMax + this.Kekka; 
}
var _RollDice;
var Dice_X = 570;
var Dice_Y = 272;
var DicePs = new Pos2D(Dice_X , Dice_Y);
var Dice_flame = 0; 
const Dice_FInFlame = 10;
Game_Interpreter.prototype.N_DiceRoll_Start = function () {
    DicePs = new Pos2D(Dice_X , Dice_Y);
    Dice_flame = 0; 
    Dice_Click_flame = 0;
    _RollDice = new NDice("PN_Dice_Anime");
    this.SetPictFIn( PN_DiceBack , "Black" , 0 , 0 , 0 , 0 , Dice_FInFlame , 150);
    this.SetPictFIn( PN_DiceWin , DicePic + "PN_DiceWin" , DicePs._x , DicePs._y , 0 , 0 , Dice_FInFlame , 255);
    this.PicAnimeCellC( PN_Dice_Anime , DicePic + _RollDice.PicName , _RollDice.CellCount , _RollDice.RndMax ,
         DicePs._x + 158 , DicePs._y + 80 , 0 , 50 , 50);
    this.MovePict( PN_Dice_Anime , DicePs._x + 158 , DicePs._y + 80 , Dice_FInFlame , 255 , true , true);
}
var Dice_Click_flame = 0; 
Game_Interpreter.prototype.N_DiceRoll_Update = function () {
    if(Dice_Click_flame > 0) {
        if(Dice_Click_flame > 10){
            if(TouchInput.isTriggered() || Input.isTriggered('ok')) { 
                this.FOutPictSpan(PN_DiceBack , PN_Dice_StopUI , 15); 
                $gameVariables.setValue(VN_ダイス結果 , _RollDice.Kekka)
                return false; 
            }
        }
        Dice_Click_flame++;
        return true;
    }
    if(Dice_flame == Dice_FInFlame + 25) {
        this.SetPictFIn( PN_Dice_StopUI , DicePic + "PN_Dice_StopUI" , DicePs._x , DicePs._y , 0 , -30 , 15 , 255);
        this.PlayBgs("DiceLoop");
    }
    if(Dice_flame > Dice_FInFlame + 30) {
        _RollDice.Rolling(Dice_flame);
        this.PicAnimeCellC( PN_Dice_Anime , DicePic + _RollDice.PicName , _RollDice.CellCount , _RollDice.RndNo ,
             DicePs._x + 158 , DicePs._y + 80 , 255 , 50 , 50);
        if(TouchInput.isTriggered() || Input.isTriggered('ok')) { 
            AudioManager.fadeOutBgs(1); //(1)は秒数指定
            this.PlaySe("DiceRoll");
            Dice_Click_flame = 1;
            _RollDice.RollKekka(); 
            this.PicAnimeCellC( PN_Dice_Anime , DicePic + _RollDice.PicName , _RollDice.CellCount , _RollDice.KekkaNo ,
                DicePs._x + 158 , DicePs._y + 80 , 255 , 50 , 50);
                this.SetPictFIn( PN_Dice_StopUI , DicePic + "PN_Dice_EndUI" , DicePs._x , DicePs._y , 0 , 0 , 5 , 255);
        }
    }
    Dice_flame++;
    return true; 
}
