/*:ja
 * @plugindesc 
 */
const PN_cgBase = 185;              
var PN_cgPac = PN_cgBase + 1;     
var PN_cgCcTxt = PN_cgPac + 1;    
var PN_cgura = PN_cgCcTxt + 1;    
var PN_cgEn = PN_cgura + 5;       
var PN_cgOpnBtn = PN_cgEn + 3;    
var PN_cgOonTxt = PN_cgOpnBtn + 1; 
var PN_cgMoTxt = PN_cgOonTxt + 1; 
var PN_cgMoWaku = PN_cgMoTxt + 1; 
var PN_cgSetu = PN_cgMoWaku + 1;  
var PN_cgCmp = PN_cgSetu + 10;    
var PN_cgNew = PN_cgCmp + 1;  
const VN_PackOpenCount = 976; 
let CardGetPNSetting = function () {
    if (!Pack5OpenFlg) {
        PN_cgPac = PN_cgBase + 1;     
        PN_cgCcTxt = PN_cgPac + 1;    
        PN_cgura = PN_cgCcTxt + 1;    
        PN_cgEn = PN_cgura + 5;       
        PN_cgOpnBtn = PN_cgEn + 3;    
        PN_cgOonTxt = PN_cgOpnBtn + 1; 
        PN_cgMoTxt = PN_cgOonTxt + 1; 
        PN_cgMoWaku = PN_cgMoTxt + 1; 
        PN_cgSetu = PN_cgMoWaku + 1;  
        PN_cgCmp = PN_cgSetu + 10;    
        PN_cgNew = PN_cgCmp + 1;  
    } else {
        PN_cgPac = PN_cgBase + 1;     
        PN_cgCcTxt = PN_cgPac + 5;    
        PN_cgura = PN_cgCcTxt + 1;    
        PN_cgEn = PN_cgura + 15;       
        PN_cgOpnBtn = PN_cgEn + 15;    
        PN_cgOonTxt = PN_cgOpnBtn + 1; 
        PN_cgMoTxt = PN_cgOonTxt + 1; 
        PN_cgMoWaku = PN_cgMoTxt + 1; 
        PN_cgSetu = PN_cgMoWaku + 1;  
        PN_cgCmp = PN_cgSetu + 10;    
        PN_cgNew = PN_cgCmp + 1;  
    }
}
let Pack_Data = []; 
let Pack_DataFlg = false;
let Pack_Data_NUpdateSc = Game_Interpreter.prototype.NUpdateSc;
Game_Interpreter.prototype.NUpdateSc = function () {
    Pack_Data_NUpdateSc.call(this);
    if (!Pack_DataFlg) {
        Pack_Data = [];
        $Nupu_GameSetting.packDatas.forEach( ckData => {
            var setArr = [ckData.itemId , []];
            for (let i = 0; i < ckData.packCardDatas.length; i++) {
                for (let j = 0; j < ckData.packCardDatas[i].count; j++) {
                    setArr[1].push(ckData.packCardDatas[i].id);
                }
            }
            Pack_Data.push(setArr);
        });
        Pack_DataFlg = true;
    }
}
let NCGet_ini = Game_System.prototype.initialize;
Game_System.prototype.initialize = function () { 
    NCGet_ini.call(this);
    this.PackJsonFlg = true;    
    this.PackSeed = [];     
    this.PackRemCar = [];   
    for (let i = 0; i <= $Nupu_GameSetting.packDatas.length - 1; i++) {
        this.PackRemCar.push([$Nupu_GameSetting.packDatas[i].itemId , []]);
        $Nupu_GameSetting.packDatas[i].packCardDatas.forEach( addData => {
            for (let j = 0; j < addData.count; j++) {
                this.PackRemCar[i][1].push(addData.id);
            }
        });
    }
    this.PackOpenData = []; 
    this.FearyDescEnd = false; 
};
let FearyCardNos = []; 
let PackData_NUpdateSc = Game_Interpreter.prototype.NUpdateSc;
Game_Interpreter.prototype.NUpdateSc = function () {
    PackData_NUpdateSc.call(this);
    if ($gameSystem.PackJsonFlg == undefined) {
        $gameSystem.PackJsonFlg = true;
        $gameSystem.PackSeed = [];
        $gameSystem.PackRemCar = [];
        for (let i = 0; i <= $Nupu_GameSetting.packDatas.length - 1; i++) {
            $gameSystem.PackRemCar.push([$Nupu_GameSetting.packDatas[i].itemId , []]);
            $Nupu_GameSetting.packDatas[i].packCardDatas.forEach( addData => {
                for (let j = 0; j < addData.count; j++) {
                    $gameSystem.PackRemCar[i][1].push(addData.id);
                }
            });
        }
        $gameSystem.PackOpenData = []; 
    }
    if (FearyCardNos.length == 0) {
        for (let i = 500; i < 800; i++) {
            let cardData = $dataWeapons[i];
            if (MetaChecker(cardData , "Tag" , "") == "フェアリー") {
                FearyCardNos.push(i);
            }
        }
    }
    if (!$gameSystem.FearyDescEnd) {
        for (let i = 0; i < FearyCardNos.length; i++) {
            if ($gameParty.hasItem($dataWeapons[FearyCardNos[i]], false)) {
                this.AddMail設定ツールNo(39);
                $gameSystem.FearyDescEnd = true;
                break;
            }
        }
    }
}
let CG_PicPath = MenuUIPath + "Item/Card/";
let _PackId = 0;
let _PackSeed = 0; 
/** @type {SeedRand} */
let _PRand = null; 
let _CardViewFlg = false;   
let Pack5OpenFlg = false;   
let CGet_Mode = 0;          
let CGet_Flame = 0;         
let CGet_ViewFlg = function() {
    return _CardViewFlg;
}
Game_Interpreter.prototype.CGet_Start = function(_SetPackId) {
    CardGetPNSetting(); 
    _CardViewFlg = true;
    CGet_Mode = 1;
    _cubeRote = 1;
    _PackId = _SetPackId;
    this.SeedSet(); 
    _PRand = new SeedRand(_PackSeed); 
    this.CGet_Mode1_View();
}
Game_Interpreter.prototype.First_SeedSet = function () {
    for (let i = 0; i <= Pack_Data.length - 1; i++) {
        _PackId = Pack_Data[i][0];
        this.SeedSet(); 
    }
}
Game_Interpreter.prototype.SeedSet = function () {
    _PackSeed = -1;
    for (let i = 0; i <= $gameSystem.PackSeed.length - 1; i++) {
        if ($gameSystem.PackSeed[i][0] == _PackId) {
            _PackSeed = $gameSystem.PackSeed[i][1]; 
            _PRand = new SeedRand(_PackSeed);       
            $gameSystem.PackSeed[i][1] = Math.floor(_PRand.random() * 1000000);
            break;
        }
    }
    if (_PackSeed == -1) {
        _PackSeed = Math.floor(Math.random() * 1000000);
        $gameSystem.PackSeed.push([_PackId, _PackSeed]);
    }
}
let CG_NUpdate = Game_Interpreter.prototype.NUpdate;
Game_Interpreter.prototype.NUpdate = function () {
    CG_NUpdate.call(this);
    if (_CardViewFlg) {     
        this.CGet_Update();
    }
}
Game_Interpreter.prototype.CGet_Update = function () {
    switch (CGet_Mode){
        case 1: 
            this.CGet_Mode1_Update();
            break;
        case 2: 
            this.CGet_Mode2_Update();
            break;
        case 3: 
            this.CGet_Mode3_Update();
            break;
    }
    CGet_Flame++;
}
let _cubeRote = 0; 
Game_Interpreter.prototype.CGet_Mode1_View = function () {
    CGet_Flame = 0; 
    cGetMode1_Pack5OpenFlame = 0;
    this.SetPictFIn(PN_cgBase, CG_PicPath + "cback", 0, 0, 0, 0, 15);
    let _cubeStr = $dataItems[_PackId].meta["CubePic"];
    let _PN_cgCcTxt = PN_cgCcTxt;
    if (Pack5OpenFlg) {
        $gameVariables.setValue(VN_PackOpenCount , $gameVariables.value(VN_PackOpenCount) + 4);
        this.SetPictFInC(PN_cgPac + 0, CG_PicPath + _cubeStr, 615, 395, 0, -10, 15);
        this.SetPictFInC(PN_cgPac + 1, CG_PicPath + _cubeStr, 615 + 116, 395 + 56, 0, -10, 15);
        this.SetPictFInC(PN_cgPac + 2, CG_PicPath + _cubeStr, 615 - 116, 395 + 56, 0, -10, 15);
        this.SetPictFInC(PN_cgPac + 3, CG_PicPath + _cubeStr, 615 + 116, 395 - 72, 0, -10, 15);
        this.SetPictFInC(PN_cgPac + 4, CG_PicPath + _cubeStr, 615 - 116, 395 - 72, 0, -10, 15);
        for (let i = 0; i < 5; i++) {
            this.AnglePict(PN_cgPac + i, 10);
        }
    } else {
        this.SetPictFInC(PN_cgPac, CG_PicPath + _cubeStr, 615, 395, 0, -10, 15);
        this.AnglePict(PN_cgPac, 10);
    }
    D_Text_Cng_font = "Makinas";
    this.SetPicStrC(_PN_cgCcTxt, "クリックで開封", 33, 614, 551, 0);
    this.MovePict(_PN_cgCcTxt, true, true, 15);
    D_Text_Cng_font = "";
    this.SetPtcSc2Top("CCube", 588, 350, 15);
    this.SetPtcSc2Top("CCubeBack", true, true, 16);
};
let cGetMode1_Pack5OpenFlame = 0;
let cGetMode1_Pack5OpenCount = 0;
Game_Interpreter.prototype.CGet_Mode1_Update = function () {
    if (cGetMode1_Pack5OpenFlame > 0) {
        cGetMode1_Pack5OpenFlame++;
        if (cGetMode1_Pack5OpenFlame % 10 == 9) {
            cGetMode1_Pack5OpenCount++;
            this.PlaySe(CG_SePath + "cube_Open");
            let ptcX = 620;
            let ptcY = 390;
            switch (cGetMode1_Pack5OpenCount) {
                case 1: ptcX += 116; ptcY += 56;
                    break;
                case 2: ptcX -= 116; ptcY += 56;
                    break;
                case 3: ptcX += 116; ptcY -= 72;
                    break;
                case 4: ptcX -= 116; ptcY -= 72;
                    break;
            }
            this.PlayPtcScTop("CGClick", ptcX, ptcY);
            this.MovePict(PN_cgPac + cGetMode1_Pack5OpenCount, true, true, 15,0,200,200);
            if (cGetMode1_Pack5OpenCount == 4) {
                this.CGet_Mode2_View();
                this.StopPtcSc2(15);
                CGet_Mode = 2;
                this.DelPict(PN_cgCcTxt);
            }
        }
        return;
    }
    if (!Pack5OpenFlg)
        this.AnglePict(PN_cgPac, -50 + Math.sin(CGet_Flame / 1000) * 100);
    else {
        for (let i = 0; i < 5; i++) {
            this.AnglePict(PN_cgPac + i, -50 + Math.sin(CGet_Flame / 1000) * 100);
        }
    }
    if (CGet_Flame > 30) { 
        if (TouchInput.isTriggered()) { 
            this.PlaySe(CG_SePath + "cube_Open");
            this.PlayPtcScTop("CGClick", 620, 390);
            this.MovePict(PN_cgPac, true, true, 15,0,200,200);
            if (!Pack5OpenFlg){
                this.CGet_Mode2_View();
                this.StopPtcSc2(15);
                CGet_Mode = 2;
                this.DelPict(PN_cgCcTxt);
            } else {
                cGetMode1_Pack5OpenFlame = 1;
                cGetMode1_Pack5OpenCount = 0;
            }
        }
    }
}
class OpenCClass {
    constructor(_cNo) {
        this._cNo = _cNo;    
        this._rea = Number($dataWeapons[_cNo].meta["Rea"]);
        this._uraflm = -1;    
        this._opflm = -1;    
        this._setopflm = 0;  
        this._oflg = false;  
        switch (this._rea) {
            case 0: 
                this._setopflm = 8;
                break;
            case 1: 
                this._setopflm = 11;
                break;
            case 2: 
                this._setopflm = 60;
                break
            case 3: 
                this._setopflm = 120;
                break;
        }
    }
}
let cg_OCardArr = [];   
let cg_COpenFlame = 0;  
let cg_ONo = -1;        
let _Rea0Arr = []; 
let _Rea1Arr = []; 
let _Rea2Arr = []; 
let _Rea3Arr = []; 
let _Pack確率 = [50 , 30 , 13 , 7];
Game_Interpreter.prototype.CGCardSet = function () {
    _Rea0Arr = []; _Rea1Arr = []; _Rea2Arr = []; _Rea3Arr = [];
    let _CardArr = [];
    for (let i = 0; i <= Pack_Data.length - 1; i++) {
        if (_PackId == Pack_Data[i][0]) {
            _CardArr = Pack_Data[i][1].slice();
        }
    }
    cg_OCardArr = [];
    let getMaisu = 3;
    if (Pack5OpenFlg) getMaisu = 15;
    for (let i = 0; i <= getMaisu - 1; i++) {
        cg_OCardArr.push(_PackCardIDGet(_PackId));
    }
    for (let i = 0; i <= $gameSystem.PackSeed.length - 1; i++) {
        if ($gameSystem.PackSeed[i][0] == _PackId) {
            $gameSystem.PackSeed[i][1] = Math.floor(_PRand.random() * 10000000);
            break;
        }
    }
    for (let i = 0; i <= cg_OCardArr.length - 1; i++) {
        $gameParty.gainItem($dataWeapons[cg_OCardArr[i]._cNo], 1); 
    }
}
let _PackCardIDGet = function (_PackId) {
    let _random = Math.random();
    for (let i = 0; i <= $gameSystem.PackRemCar.length - 1; i++) {
        if($gameSystem.PackRemCar[i][0] == _PackId) {
            if($gameSystem.PackRemCar[i][1].length == 0) { 
                Pack_Data.forEach( packArr => {
                    if (packArr[0] == _PackId) {
                        $gameSystem.PackRemCar[i][1] = CopyArr(packArr[1]);
                        return;
                    }
                });
            }
            let _getNo = Math.floor($gameSystem.PackRemCar[i][1].length * _random);
            let _RtnCardId = $gameSystem.PackRemCar[i][1][_getNo];
            $gameSystem.PackRemCar[i][1].splice(_getNo , 1);
            try {
                var rtnData = new OpenCClass(_RtnCardId);
                return rtnData;
            } catch (e) {
                console.log("sss");
            }
        }
    }
}
let ArrRndGet = function (_Arr) {
    let _ckNo = Math.floor(_PRand.random() * _Arr.length);
    return _Arr[_ckNo];
}
const packOpenZureY = -20;
Game_Interpreter.prototype.CGet_Mode2_View = function () {
    CGet_Flame = 0;
    cg_COpenFlame = 0;
    _cg_UraUpFlm = 0
    this.CGCardSet();
    for (let i = 0; i <= 4 - 1; i++) {
        ImageManager.loadBitmap("", CardPicPath + "wk_Rea" + i, null, false);
    }
    for (let i = 0; i <= cg_OCardArr.length - 1; i++) {
        let _cgLoadPic = CardPicPath + cg_OCardArr[i]._cNo;
        ImageManager.loadBitmap("", _cgLoadPic, null, false);
    }
    ImageManager.loadBitmap("", CardPicPath + "CEn1", null, false);
    if (!Pack5OpenFlg) {
        this.SetPictC(PN_cgura + 0, CG_PicPath + "cgura", 320 + (265 * 0), 420 + packOpenZureY, 0);
        this.SetPictC(PN_cgura + 1, CG_PicPath + "cgura", 320 + (265 * 1), 420 + packOpenZureY, 0);
        this.SetPictC(PN_cgura + 2, CG_PicPath + "cgura", 320 + (265 * 2), 420 + packOpenZureY, 0);
    } else {
        for (let i = 0; i <= 15 - 1; i++) {
            let posX = Math.floor(i / 3);
            let posY = i % 3;
            let cardPar = 55; 
            this.SetPictC(PN_cgura + i, CG_PicPath + "cgura",
                280 + (144 * posX), 178 + (186 * posY) + packOpenZureY, 0 , cardPar , cardPar);
        }
    }
}
let _cg_UraUpFlm = 0; 
let cGetTouchFlame = 60;
Game_Interpreter.prototype.CGet_Mode2_Update = function () {
    if (!Pack5OpenFlg) {
        cGetTouchFlame = 60;
        for (let i = 0; i <= 3 - 1; i++) {
            if (CGet_Flame == 20 + (10 * i))
                this.MovePict(PN_cgura + i, true, 420, 15, 255);
        }
    } else {
        cGetTouchFlame = 100;
        for (let i = 0; i <= 15 - 1; i++) {
            if (CGet_Flame == 20 + (5 * i)) {
                let posY = i % 3;
                let setY = 178 + (186 * posY);
                this.MovePict(PN_cgura + i, true, setY, 15, 255 , true , true);
            }
        }
    }
    if (CGet_Flame == cGetTouchFlame - 30) {
        D_Text_Cng_font = "Makinas";
        if (!Pack5OpenFlg) {
            this.SetPicStrC(PN_cgCcTxt, "タッチで表に", 33, 585, 645, 0);
        } else {
            this.SetPicStrC(PN_cgCcTxt, "タッチで表に（残15）", 33, 555, 688, 0);
        }
        this.MovePict(PN_cgCcTxt, true, true, 30);
        D_Text_Cng_font = "";
    }
    if (CGet_Flame == cGetTouchFlame - 1){
        if (!Pack5OpenFlg) {
            for (let i = 0; i <= cg_OCardArr.length - 1; i++) {
                if (cg_OCardArr[i]._rea == 2) {
                    this.SetPtcSc2Top("CCSR", 320 + (265 * i), 410, 20 + i);
                }
                if (cg_OCardArr[i]._rea == 3) {
                    this.SetPtcSc2Top("CCSSR_B", 320 + (265 * i), 410, 20 + i);
                }
            }
        } else {
            for (let i = 0; i <= cg_OCardArr.length - 1; i++) {
                let posX = Math.floor(i / 3);
                let posY = i % 3;
                if (cg_OCardArr[i]._rea == 2) {
                    this.SetPtcSc2Top("CCSR", 280 + (144 * posX), 178 + (186 * posY), 20 + i);
                }
                if (cg_OCardArr[i]._rea == 3) {
                    this.SetPtcSc2Top("CCSSR_B", 280 + (144 * posX), 178 + (186 * posY), 20 + i);
                }
            }
        }
    }
    if (CGet_Flame > cGetTouchFlame) {
        let _cgTCArr = [PN_cgura + 0, PN_cgura + 1, PN_cgura + 2];
        if (Pack5OpenFlg) {
            _cgTCArr = [];
            for (let i = 0; i < 15; i++) _cgTCArr.push(PN_cgura + i);
        }
        let _OverNo = overPointerCkArr(_cgTCArr);
        let _cgEflg1 = true;
        let _opnCnt = 0;
        for (let i = 0; i <= cg_OCardArr.length - 1; i++) {
            if (cg_OCardArr[i]._opflm != 0)　{
                _cgEflg1 = false;
            }
            if (!cg_OCardArr[i]._oflg) _opnCnt++;
        }
        if (_cgEflg1) {
            CGet_Mode = 3;
            this.CGet_Mode3_View();
        } else {
            if (Pack5OpenFlg) {
                this.SetPicStrC(PN_cgCcTxt, "タッチで表に（残" + _opnCnt + "）", 33, 555, 688, 255);
            }
        }
        if (_OverNo != -1) {
            let _ckNo = _OverNo - PN_cgura;
            if (TouchInput.isPressed() && !cg_OCardArr[_ckNo]._oflg) {
                this.StopPtcSc2(20 + _ckNo);
                cg_OCardArr[_ckNo]._oflg = true; 
                cg_OCardArr[_ckNo]._uraflm = 8;
                this.MovePict(PN_cgura + _ckNo, true, true, cg_OCardArr[_ckNo]._uraflm, true, 0, true);
                cg_OCardArr[_ckNo]._opflm = cg_OCardArr[_ckNo]._setopflm;
            }
        }
        this.CGet_COpenUpdate();
    }
}
Game_Interpreter.prototype.CGet_NewImgSet = function (No) {
}
let NewCardGetCk = function (_CardNo) {
}
Game_Interpreter.prototype.CGet_COpenUpdate = function () {
    for (let i = 0; i <= cg_OCardArr.length - 1; i++) {
        if (!cg_OCardArr[i]._oflg) continue;
        if (cg_OCardArr[i]._uraflm > 0){
            cg_OCardArr[i]._uraflm--;
        }else{
            if (cg_OCardArr[i]._opflm > 0) {
                let _cgNFlame = 0;
                let posX = 320 + (265 * i);
                let posY = 410;
                let cardPar = 100;
                if (Pack5OpenFlg) {
                    posX = 280 + (144 * Math.floor(i / 3));
                    posY = 178 + (186 * (i % 3));
                    cardPar = 55;
                }
                let _newFlg = ($gameSystem.GetCard.indexOf(cg_OCardArr[i]._cNo) == -1);
                if (_newFlg) { 
                    $gameSystem.GetCard.push(cg_OCardArr[i]._cNo); 
                    $gameSystem.NewCard.push(cg_OCardArr[i]._cNo); 
                    var newPosX = posX; var newPosY = posY;
                    if (Pack5OpenFlg) {
                        newPosY += 70;
                    } else {
                        newPosY += 140;
                    }
                    this.SetPictC(PN_cgNew + i, CG_PicPath + "NewTxt"
                        , newPosX, newPosY, 0,0,cardPar);
                    if (cg_OCardArr[i]._rea == 3) {
                        this.MovePict(PN_cgNew + i, true, true, 100 , 255 , cardPar , cardPar); 
                    } else {
                        this.MovePict(PN_cgNew + i, true, true, 30 , 255 , cardPar , cardPar); 
                    }
                }
                switch (cg_OCardArr[i]._rea) {
                    case 0: 
                        if (cg_OCardArr[i]._opflm == cg_OCardArr[i]._setopflm) { 
                            this.CardPicDrawC(cg_OCardArr[i]._cNo, PN_cgura + i, PN_Cmp, posX, posY, 0, 0, cardPar);
                            this.PlayPtcSc2Top("CCRea0", posX, posY); 
                            this.MovePict(PN_cgura + i, true, true, cg_OCardArr[i]._setopflm , 255 , cardPar , cardPar); 
                            this.PlaySe(CG_SePath + "Rea0");
                        }
                        break;
                    case 1: 
                        if (cg_OCardArr[i]._opflm == cg_OCardArr[i]._setopflm) { 
                            this.CardPicDrawC(cg_OCardArr[i]._cNo, PN_cgura + i, PN_Cmp, posX, posY , 0, 0, cardPar);
                            this.PlayPtcSc2Top("CCRea1", posX, posY ); 
                            this.MovePict(PN_cgura + i, true, true, cg_OCardArr[i]._setopflm , 255 , cardPar , cardPar); 
                            PicAnimeLCLoop(50);
                            this.PlayPicAnimeC(PN_cgEn + i, CardPicPath + "CEn1", 11, 2, posX, posY , 255 , cardPar , cardPar);
                            this.PlaySe(CG_SePath + "Rea1");
                        }
                        break;
                    case 2: 
                        if (cg_OCardArr[i]._opflm == cg_OCardArr[i]._setopflm) { 
                            this.CardPicDrawC(cg_OCardArr[i]._cNo, PN_cgura + i, PN_Cmp, posX, posY, 0, 0, cardPar);
                            this.PlayPtcSc2Top("CCRea2", posX, posY);     
                            this.SetPtcSc2Top("CCSR", posX, posY,20 + i);   
                            this.MovePict(PN_cgura + i,
                                true, true, 8, 255, cardPar * 1.2, cardPar * 1.2);  
                            PicAnimeLCLoop(50);
                            this.PlayPicAnimeC(PN_cgEn + i, CardPicPath + "CEn1", 11, 2,
                                posX, posY, 0, cardPar * 1.2, cardPar * 1.2);
                            this.PlaySe(CG_SePath + "Rea2");
                        }
                        _cgNFlame = cg_OCardArr[i]._setopflm - 8; 
                        if (cg_OCardArr[i]._opflm == _cgNFlame) {
                            this.MovePict(PN_cgura + i, true, true, _cgNFlame , 255 , cardPar , cardPar);
                            this.MovePict(PN_cgEn + i, true, true, _cgNFlame , 255 , cardPar , cardPar);
                        }
                        break;
                    case 3: 
                        if (cg_OCardArr[i]._opflm == cg_OCardArr[i]._setopflm) { 
                            this.CardPicDrawC(cg_OCardArr[i]._cNo, PN_cgura + i, PN_Cmp, posX, posY, 0, 0, cardPar);
                            this.PlayPtcSc2Top("CCRea3", posX, posY);     
                            this.PlayPtcSc2Top("CCRea3_b", posX, posY);     
                            this.SetPtcSc2Top("CCSSR", posX, posY, 20 + i);   
                            this.MovePict(PN_cgura + i, true, true, 8, 255, 180, cardPar * 1.8);  
                            PicAnimeLCLoop(35);
                            this.PlayPicAnimeC(PN_cgEn + i, CardPicPath + "CEn1", 11, 2,
                                posX, posY, 0, cardPar * 1.8, cardPar * 1.8);
                            this.PlaySe(CG_SePath + "Rea3");
                        }
                        _cgNFlame = cg_OCardArr[i]._setopflm - 8; 
                        if (cg_OCardArr[i]._opflm == _cgNFlame) {
                            this.MovePict(PN_cgura + i, true, true, _cgNFlame , 255 , cardPar , cardPar);
                            this.MovePict(PN_cgEn + i, true, true, _cgNFlame , 255 , cardPar , cardPar);
                        }
                        break;
                }
                cg_OCardArr[i]._opflm--;
            }
        }
    }
}
Game_Interpreter.prototype.CGet_Mode3_View = function () {
    CGet_Flame = 0;
    D_Text_Cng_font = "Makinas";
    let zureY = 0;
    if (Pack5OpenFlg) zureY = 60;
    this.SetPicStrC(PN_cgCcTxt, "クリックで終了", 33, 585, 645 + zureY, 0);
    this.MovePict(PN_cgCcTxt, true, true, 30);
    this.SetPicStrC(PN_cgMoTxt, "マウスオーバーで効果確認", 22, 585, 685 + zureY, 0);
    this.MovePict(PN_cgMoTxt, true, true, 30);
    if ($gameParty.numItems($dataItems[_PackId]) >= 1 || !$dataItems[_PackId].consumable) {
        let skipFlg = false;
        if (Pack5OpenFlg && $gameParty.numItems($dataItems[_PackId]) < 5) skipFlg = true;
        if (!skipFlg) {
            this.SetPictC(PN_cgOpnBtn, CardPicPath + "OpenBtn", 906, 660 + zureY, 0);
            this.MovePict(PN_cgOpnBtn, true, true, 15);
            let _owSet = "\\ow[1]";
            this.SetPicStrC(PN_cgOonTxt, _owSet + "残り：" + $gameParty.numItems($dataItems[_PackId]), 17, 906, 680 + zureY, 0);
            if (!$dataItems[_PackId].consumable) {
                this.SetPicStrC(PN_cgOonTxt, _owSet +  "残り：" + "無限", 17, 900, 677 + zureY, 0);
            }
            this.MovePict(PN_cgOonTxt, true, true, 15);
        }
    }
    D_Text_Cng_font = "";
}
let CGet_Mode3BefSelectNo = -1;
let CGet_Mode3_Update_BefDrawNo = -1;
Game_Interpreter.prototype.CGet_Mode3_Update = function () {
    if (CGet_Flame > 30) {
        this.PicCngColor(PN_cgOpnBtn);
        if (overPointerCk(PN_cgOpnBtn)) {
            this.PicCngColor(PN_cgOpnBtn, [150, 150, 150, 0]);
        }
        if (!Pack5OpenFlg) {
            let _cgTCArr = [PN_cgura + 0, PN_cgura + 1, PN_cgura + 2];
            let _OverNo = overPointerCkArr(_cgTCArr);
            if (_OverNo != -1) {
                D_Text_Cng_font = "Makinas";
                let _ckNo = _OverNo - PN_cgura;
                if (CGet_Mode3_Update_BefDrawNo != _ckNo) {
                    for (let i = PN_cgMoWaku; i <= PN_cgSetu + 6; i++) {
                        this.DelPict(i);
                    }
                    CGet_Mode3_Update_BefDrawNo = _ckNo;
                }
                let _CkCard = $dataWeapons[cg_OCardArr[_ckNo]._cNo];
                let _setStr = "";
                let _SetX = 320 + (265 * _ckNo) - 242;
                let _SetY = 440 - 435;
                this.SetPict(PN_cgMoWaku, CardPicPath + "Card_Setu", _SetX, _SetY);
                this.SetPicStr(PN_cgSetu + 0, _CkCard.name, 28, _SetX + 40, _SetY + 26);
                _setStr = "コスト：" + _CkCard.meta["Cost"];
                this.SetPicStr(PN_cgSetu + 1, _setStr, 22, _SetX + 310, _SetY + 32);
                _setStr = _CkCard.description;
                this.SetPicStr(PN_cgSetu + 2, _setStr, 20, _SetX + 40, _SetY + 68);
                this.SetPicStr(PN_cgSetu + 3, "効果：", 20, _SetX + 40, _SetY + 100);
                let _SetuArr = this.CardSetuGet(cg_OCardArr[_ckNo]._cNo); 
                for (let i = 0; i <= _SetuArr.length - 1; i++) {
                    this.SetPicStr(PN_cgSetu + 4 + i, _SetuArr[i], 20,
                        _SetX + 40, _SetY + 132 + (26 * i));
                }
                D_Text_Cng_font = "";
            } else {
                for (let i = PN_cgMoWaku; i <= PN_cgSetu + 6; i++) {
                    this.DelPict(i);
                }
            }
        } else {
            let _cgTCArr = [];
            for (let i = 0; i < 15; i++) _cgTCArr.push(PN_cgura + i);
            let _OverNo = overPointerCkArr(_cgTCArr);
            if (_OverNo != -1) {
                let _ckNo = _OverNo - PN_cgura;
                if (CGet_Mode3BefSelectNo != _ckNo) this.de_MiniSyosaiDel(PN_cgNew + 15);
                CGet_Mode3BefSelectNo = _ckNo;
                let posX = 280 + (144 * Math.floor(_ckNo / 3));
                let posY = 178 + (186 * (_ckNo % 3));
                deMiniPictFlg = true;
                this.de_MiniSyosai(cg_OCardArr[_ckNo]._cNo , posX + 60 , posY , PN_cgNew + 15);
            } else {
                this.de_MiniSyosaiDel(PN_cgNew + 15);
            }
        }
        if (TouchInput.isTriggered() || TouchInput.isCancelled()) {
            this.de_MiniSyosaiDel(PN_cgNew + 15);
            for (let i = 0; i <= cg_OCardArr.length - 1; i++) {
                this.StopPtcSc2(20 + i);
            }
            if (overPointerCk(PN_cgOpnBtn)) {
                let item = $dataItems[_PackId];
                let actor = $gameParty.leader();
                actor.useItem(item); 
                $gameVariables.setValue(VN_PackOpenCount , $gameVariables.value(VN_PackOpenCount) + 1);
                if (Pack5OpenFlg) {
                    actor.useItem(item);
                    actor.useItem(item);
                    actor.useItem(item);
                    actor.useItem(item);
                    $gameVariables.setValue(VN_PackOpenCount , $gameVariables.value(VN_PackOpenCount) + 4);
                }
                this.CGet_AllPictDell(PN_cgCcTxt);
                this.PlayPtcScTop("CGClick", 620, 390);
                this.MovePict(PN_cgPac, true, true, 15, 0, 200, 200);
                this.CGet_Mode2_View();
                this.StopPtcSc2(15);
                CGet_Mode = 2;
                this.PlaySe(CG_SePath + "cube_Open");
            } else {
                this.StopPtcSc2(16);
                this.CGet_AllFadeOut();
                _CardViewFlg = false;
                CGet_Mode3_Update_BefDrawNo = -1;
            }
        }
    }
}
//カード取得で使ったピクチャを全て削除(185～250まで)
Game_Interpreter.prototype.CGet_AllPictDell = function (_No) {
    _No = typeof _No !== 'undefined' ? _No : PN_cgBase;
    for (let i = _No; i <= PN_cgNew + 15; i++) {
        MovePict(i , true, true, 15 , 0 , true , true);
    }
}
Game_Interpreter.prototype.CGet_AllFadeOut = function (_No) {
    _No = typeof _No !== 'undefined' ? _No : PN_cgBase;
    for (let i = _No; i <= PN_cgNew + 15; i++) {
        FOutPict(i, 15);
    }
}
