2019-04-28 16:01:33 UNSELECTED

Unknown type code

Copy Copied! Full
--簡略化 STAT = vci.state ASET = vci.assets --Unityの駒の名称 CUBE_STR = { "hu1", "hu2", "hu3", "hu4", "hu5", "hu6", "hu7", "hu8", "hu9", "hu10", "hu11", "hu12", "hu13", "hu14", "hu15", "hu16", "hu17", "hu18", "hisya1", "hisya2", "kaku1", "kaku2", "kyou1", "kyou2", "kyou3", "kyou4", "kei1", "kei2", "kei3", "kei4", "gin1", "gin2", "gin3", "gin4", "kin1", "kin2", "kin3", "kin4", "gyoku1", "ou1" } --Unityの補助駒の名称 CUBE_STR2 = { "hu0", "hisya0", "kaku0", "kyou0", "kei0", "gin0", "kin0", "gyoku0", "ou0" } --盤面のどこに何の駒があるか BOARD_NUM = { 23, 27, 31, 35, 39, 36, 32, 28, 24, 0, 19, 0, 0, 0, 0, 0, 21, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 0, 22, 0, 0, 0, 0, 0, 20, 0, 26, 30, 34, 38, 40, 37, 33, 29, 25 } --初期化用 BOARD_NUM_CPY = { 23, 27, 31, 35, 39, 36, 32, 28, 24, 0, 19, 0, 0, 0, 0, 0, 21, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 0, 22, 0, 0, 0, 0, 0, 20, 0, 26, 30, 34, 38, 40, 37, 33, 29, 25 } --駒の移動可能位置の計算値保持 BOARD_POSSIBLE = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } --どの方向向いてるか ANG_NUM = { 90, 90, 90, 90, 90, 90, 90, 90, 90, 270, 270, 270, 270, 270, 270, 270, 270, 270, 90, 270, 90, 270, 90, 90, 270, 270, 90, 90, 270, 270, 90, 90, 270, 270, 90, 90, 270, 270, 90, 270 } --初期化用 ANG_NUM_CPY = { 90, 90, 90, 90, 90, 90, 90, 90, 90, 270, 270, 270, 270, 270, 270, 270, 270, 270, 90, 270, 90, 270, 90, 90, 270, 270, 90, 90, 270, 270, 90, 90, 270, 270, 90, 90, 270, 270, 90, 270 } --成っているか URA_FLG = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } --初期化用 URA_FLG_CPY = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } FIRST_FLG = true --初期化 STAT.Set("FIRST_FLG", FIRST_FLG) TARG_NUM = 0 --掴んだ番号 STAT.Set("TARG_NUM", TARG_NUM) GRIP_FLG = false --グリップ STAT.Set("GRIP_FLG", GRIP_FLG) USE_FLG = false --使用 STAT.Set("USE_FLG", USE_FLG) BORD_NUM = 0 --盤上の番号 STAT.Set("BORD_NUM", BORD_NUM) GAMEEND_FLG = false --全初期化 STAT.Set("GAMEEND_FLG", GAMEEND_FLG) NARU_FLG = false --成るかのフラグ STAT.Set("NARU_FLG", NARU_FLG) FIRST_FLG_FLG = false --全初期化 STAT.Set("FIRST_FLG_FLG", FIRST_FLG_FLG) min = 0 --移動位置 ---アイテムを生成したユーザーで毎フレーム呼ばれる function update() end ---アイテムを生成したユーザーで毎フレーム呼ばれる function updateAll() FIRST_FLG = STAT.Get("FIRST_FLG") FIRST_FLG_FLG = STAT.Get("FIRST_FLG_FLG") GRIP_FLG = STAT.Get("GRIP_FLG") TARG_NUM = STAT.Get("TARG_NUM") BORD_NUM = STAT.Get("BORD_NUM") GAMEEND_FLG = STAT.Get("GAMEEND_FLG") USE_FLG = STAT.Get("USE_FLG") NARU_FLG = STAT.Get("NARU_FLG") if FIRST_FLG == true then --駒の位置初期化 if FIRST_FLG_FLG == false then for i = 1, #BOARD_NUM do BOARD_NUM[i] = BOARD_NUM_CPY[i] end for i = 1, #ANG_NUM do ANG_NUM[i] = ANG_NUM_CPY[i] URA_FLG[i] = URA_FLG_CPY[i] end FIRST_FLG_FLG = true end Move_STROBJ() FIRST_FLG = false end if GAMEEND_FLG == false then --握っている if GRIP_FLG == true then min = 0 --移動位置 min_loc = 0.06 --最近傍距離 --盤に置いてある駒だったらtrue:とった駒の配置ならばfalse flg = false for i = 1, #BOARD_NUM do if BOARD_NUM[i] == BOARD_NUM[BORD_NUM] then flg = true end end --移動可能位置初期化 for i = 1, #BOARD_POSSIBLE do BOARD_POSSIBLE[i] = 0 end Koma() --駒計算 --補助駒配置位置決定 for i = 1, #BOARD_NUM do if flg == false then --駒の置いてあるとこ以外に補助駒配置 if BOARD_NUM[i] == 0 then Hozyo(i) end else --移動可能なところに補助駒配置 if BOARD_POSSIBLE[i] == 1 then Hozyo(i) end end end --補助駒配置位置 if min > 0 then OBJ = ASET.GetSubItem("Board") POS = OBJ.GetPosition() ANG = Vector3.Angle(Vector3.__new(0, 0, 1), OBJ.GetForward()) if OBJ.GetForward().x < 0 then ANG = -1 * ANG end sho = (-4 + math.floor((min - 1) / 9)) / 9 ama = (-4 + (min - 1) % 9) / 9 if TARG_NUM < 19 then OBJ = ASET.GetSubItem("hu0") elseif TARG_NUM < 21 then OBJ = ASET.GetSubItem("hisya0") elseif TARG_NUM < 23 then OBJ = ASET.GetSubItem("kaku0") elseif TARG_NUM < 27 then OBJ = ASET.GetSubItem("kyou0") elseif TARG_NUM < 31 then OBJ = ASET.GetSubItem("kei0") elseif TARG_NUM < 35 then OBJ = ASET.GetSubItem("gin0") elseif TARG_NUM < 39 then OBJ = ASET.GetSubItem("kin0") elseif TARG_NUM < 40 then OBJ = ASET.GetSubItem("gyoku0") elseif TARG_NUM < 41 then OBJ = ASET.GetSubItem("ou0") end if OBJ.IsMine == true then ANG2 = Vector3.Angle(Vector3.__new(0, 0, 1), Vector3.__new(sho, 0, ama).normalized) if sho < 0 then ANG2 = -1 * ANG2 end pow1 = sho * sho pow2 = ama * ama OBJ.SetPosition( Vector3.__new( POS.x + math.sqrt(pow1 + pow2) * math.sin(math.pi * (ANG2 - ANG) / 180), POS.y + 0.11, POS.z - math.sqrt(pow1 + pow2) * math.cos(math.pi * (ANG2 - ANG) / 180) ) ) OBJ.SetRotation(Quaternion.Euler(0, ANG + ANG_NUM[TARG_NUM], URA_FLG[TARG_NUM])) end end end --使用した if USE_FLG == true then USE_FLG=false --駒の番号ある if TARG_NUM > 0 then --盤上の駒である if flg == true then --最近傍位置がある if min > 0 then --BOARD_NUM[min]=0だった if ANG_NUM[BOARD_NUM[min]] == nil then BOARD_NUM[min] = BOARD_NUM[BORD_NUM] BOARD_NUM[BORD_NUM] = 0 else --相手の駒をとる if not (ANG_NUM[BOARD_NUM[min]] == ANG_NUM[BOARD_NUM[BORD_NUM]]) then ANG_NUM[BOARD_NUM[min]] = ANG_NUM[BOARD_NUM[BORD_NUM]] URA_FLG[BOARD_NUM[min]] = 0 BOARD_NUM[min] = BOARD_NUM[BORD_NUM] BOARD_NUM[BORD_NUM] = 0 end end --成るかどうか if (ANG_NUM[BOARD_NUM[min]] == 90) and (min > 54) and (NARU_FLG == true) then URA_FLG[BOARD_NUM[min]] = 180 elseif (ANG_NUM[BOARD_NUM[min]] == 270) and (min < 28) and (NARU_FLG == true) then URA_FLG[BOARD_NUM[min]] = 180 end end else --盤外のものを盤上に if min > 0 then BOARD_NUM[min] = TARG_NUM end end end end end STAT.Set("FIRST_FLG", FIRST_FLG) STAT.Set("FIRST_FLG_FLG",FIRST_FLG_FLG) STAT.Set("GAMEEND_FLG",GAMEEND_FLG) STAT.Set("USE_FLG",USE_FLG) end function onCollisionExit(it, h) Velo_Ang_Zero(it) end function onUse(use) if use == "Capsule" then FIRST_FLG = true STAT.Set("FIRST_FLG", FIRST_FLG) FIRST_FLG_FLG = false STAT.Set("FIRST_FLG_FLG", FIRST_FLG_FLG) end --駒を掴み使用したら GRIP_FLG = STAT.Get("GRIP_FLG") if GRIP_FLG == true then for i = 1, #CUBE_STR do if use == CUBE_STR[i] then USE_FLG = true STAT.Set("USE_FLG", USE_FLG) end end end end function onGrab(tar) --駒握った処理 for i = 1, #CUBE_STR do if tar == CUBE_STR[i] then TARG_NUM = i GRIP_FLG = true STAT.Set("TARG_NUM", TARG_NUM) STAT.Set("GRIP_FLG", GRIP_FLG) for i2 = 1, #BOARD_NUM do BORD_NUM = 0 if i == BOARD_NUM[i2] then BORD_NUM = i2 end STAT.Set("BORD_NUM", BORD_NUM) if BORD_NUM > 0 then break end end break end end --成る処理 if tar == "Permission" then NARU_FLG = true STAT.Set("NARU_FLG", NARU_FLG) end end function onUngrab(tar) FIRST_FLG = true STAT.Set("FIRST_FLG", FIRST_FLG) for i = 1, #CUBE_STR do if tar == CUBE_STR[i] then TARG_NUM = 0 GRIP_FLG = false STAT.Set("TARG_NUM", TARG_NUM) STAT.Set("GRIP_FLG", GRIP_FLG) BORD_NUM = 0 STAT.Set("BORD_NUM", BORD_NUM) break end end if tar == "Permission" then NARU_FLG = false STAT.Set("NARU_FLG", NARU_FLG) end Velo_Ang_Zero(tar) end --角度と力0 function Velo_Ang_Zero(item) OBJ = ASET.GetSubItem(item) OBJ.SetVelocity(Vector3.__new(0, 0, 0)) OBJ.SetAngularVelocity(Vector3.__new(0, 0, 0)) if item == "Board" then ANG = Vector3.Angle(Vector3.__new(0, 0, 1), OBJ.GetForward()) if OBJ.GetForward().x < 0 then ANG = -1 * ANG end OBJ.SetRotation(Quaternion.Euler(0, ANG, 0)) end end --駒をBOARD_NUMに従い配置 function Move_STROBJ() OBJ = ASET.GetSubItem("Board") POS = OBJ.GetPosition() ANG = Vector3.Angle(Vector3.__new(0, 0, 1), OBJ.GetForward()) if OBJ.GetForward().x < 0 then ANG = -1 * ANG end for i = 1, #BOARD_NUM do if BOARD_NUM[i] > 0 then OBJS = ASET.GetSubItem(CUBE_STR[BOARD_NUM[i]]) if OBJS.IsMine == true then sho = (-4 + math.floor((i - 1) / 9)) / 9 ama = (-4 + (i - 1) % 9) / 9 ANG2 = Vector3.Angle(Vector3.__new(0, 0, 1), Vector3.__new(sho, 0, ama).normalized) if sho < 0 then ANG2 = -1 * ANG2 end pow1 = sho * sho pow2 = ama * ama OBJS.SetPosition( Vector3.__new( POS.x + math.sqrt(pow1 + pow2) * math.sin(math.pi * (ANG2 - ANG) / 180), POS.y + 0.06, POS.z - math.sqrt(pow1 + pow2) * math.cos(math.pi * (ANG2 - ANG) / 180) ) ) OBJS.SetRotation(Quaternion.Euler(0, ANG + ANG_NUM[BOARD_NUM[i]], URA_FLG[BOARD_NUM[i]])) end end end --補助駒 for i = 1, #CUBE_STR2 do OBJS = ASET.GetSubItem(CUBE_STR2[i]) OBJS.SetPosition(Vector3.__new(POS.x, 0, POS.z)) end num1 = 1 num2 = 1 for i = 1, #CUBE_STR do --盤に配置されて入ればfalse flg = true for i2 = 1, #BOARD_NUM do if BOARD_NUM[i2] == i then flg = false break end end --盤外の駒を並べる if flg == true then if ANG_NUM[i] == 90 then OBJ = ASET.GetSubItem("Board") POS = OBJ.GetPosition() ANG = Vector3.Angle(Vector3.__new(0, 0, 1), OBJ.GetForward()) if OBJ.GetForward().x < 0 then ANG = -1 * ANG end OBJS = ASET.GetSubItem(CUBE_STR[i]) if OBJS.IsMine == true then sho = (-4 + math.floor((num1 - 18 - 1) / 9)) / 9 ama = (-4 + (num1 - 18 - 1) % 9) / 9 ANG2 = Vector3.Angle(Vector3.__new(0, 0, 1), Vector3.__new(sho, 0, ama).normalized) if sho < 0 then ANG2 = -1 * ANG2 end pow1 = sho * sho pow2 = ama * ama OBJS.SetPosition( Vector3.__new( POS.x + math.sqrt(pow1 + pow2) * math.sin(math.pi * (ANG2 - ANG) / 180), POS.y + 0.06, POS.z - math.sqrt(pow1 + pow2) * math.cos(math.pi * (ANG2 - ANG) / 180) ) ) OBJS.SetRotation(Quaternion.Euler(0, ANG + ANG_NUM[i], URA_FLG[i])) end num1 = num1 + 1 else OBJ = ASET.GetSubItem("Board") POS = OBJ.GetPosition() ANG = Vector3.Angle(Vector3.__new(0, 0, 1), OBJ.GetForward()) if OBJ.GetForward().x < 0 then ANG = -1 * ANG end OBJS = ASET.GetSubItem(CUBE_STR[i]) if OBJS.IsMine == true then sho = (-4 + math.floor((num2 + #BOARD_NUM + 17 - 1) / 9)) / 9 ama = (-4 + (num2 + #BOARD_NUM + 17 - 1) % 9) / 9 ANG2 = Vector3.Angle(Vector3.__new(0, 0, 1), Vector3.__new(sho, 0, ama).normalized) if sho < 0 then ANG2 = -1 * ANG2 end pow1 = sho * sho pow2 = ama * ama OBJS.SetPosition( Vector3.__new( POS.x + math.sqrt(pow1 + pow2) * math.sin(math.pi * (ANG2 - ANG) / 180), POS.y + 0.06, POS.z - math.sqrt(pow1 + pow2) * math.cos(math.pi * (ANG2 - ANG) / 180) ) ) OBJS.SetRotation(Quaternion.Euler(0, ANG + ANG_NUM[i], URA_FLG[i])) end num2 = num2 + 1 end end end end --補助駒計算 function Hozyo(i) OBJ = ASET.GetSubItem("Board") POS = OBJ.GetPosition() ANG = Vector3.Angle(Vector3.__new(0, 0, 1), OBJ.GetForward()) if OBJ.GetForward().x < 0 then ANG = -1 * ANG end sho = (-4 + math.floor((i - 1) / 9)) / 9 ama = (-4 + (i - 1) % 9) / 9 OBJ = ASET.GetSubItem(CUBE_STR[TARG_NUM]) ANG2 = Vector3.Angle(Vector3.__new(0, 0, 1), Vector3.__new(sho, 0, ama).normalized) if sho < 0 then ANG2 = -1 * ANG2 end pow1 = sho * sho pow2 = ama * ama POS2 = POS POS2.Set( POS.x + math.sqrt(pow1 + pow2) * math.sin(math.pi * (ANG2 - ANG) / 180), POS.y + 0.06, POS.z - math.sqrt(pow1 + pow2) * math.cos(math.pi * (ANG2 - ANG) / 180) ) POS = OBJ.GetPosition() loc = math.sqrt((POS.x - POS2.x) * (POS.x - POS2.x) + (POS.z - POS2.z) * (POS.z - POS2.z)) if min_loc > loc then min_loc = loc min = i end end --駒処理 function Koma() --盤に置いてある駒だったらtrue:とった駒の配置ならばfalse if flg == true then --歩 if TARG_NUM < 19 then --飛車 if URA_FLG[TARG_NUM] == 0 then if ANG_NUM[TARG_NUM] == 90 then hosei = 9 else hosei = -9 end if ((BORD_NUM + hosei) <= #BOARD_NUM) and ((BORD_NUM + hosei) > 0) then BOARD_POSSIBLE[BORD_NUM + hosei] = 1 if ANG_NUM[BOARD_NUM[BORD_NUM]] == ANG_NUM[BOARD_NUM[BORD_NUM + hosei]] then BOARD_POSSIBLE[BORD_NUM + hosei] = 0 end end else if ANG_NUM[TARG_NUM] == 90 then for i = 1, 4 do if i == 1 then hosei = 7 for i2 = 1, 3 do if ((BORD_NUM + hosei + i2) <= #BOARD_NUM) and ((BORD_NUM + hosei + i2) > 0) and (math.floor(1 + (BORD_NUM - 1) / 9) == math.floor((BORD_NUM - 1 + hosei + i2) / 9)) then BOARD_POSSIBLE[BORD_NUM + hosei + i2] = 1 if ANG_NUM[BOARD_NUM[BORD_NUM]] == ANG_NUM[BOARD_NUM[BORD_NUM + hosei + i2]] then BOARD_POSSIBLE[BORD_NUM + hosei + i2] = 0 end end end elseif i == 2 then hosei = -1 if ((BORD_NUM + hosei) <= #BOARD_NUM) and ((BORD_NUM + hosei) > 0) and (math.floor((BORD_NUM - 1) / 9) == math.floor((BORD_NUM - 1 + hosei) / 9)) then BOARD_POSSIBLE[BORD_NUM + hosei] = 1 if ANG_NUM[BOARD_NUM[BORD_NUM]] == ANG_NUM[BOARD_NUM[BORD_NUM + hosei]] then BOARD_POSSIBLE[BORD_NUM + hosei] = 0 end end elseif i == 3 then hosei = 1 if ((BORD_NUM + hosei) <= #BOARD_NUM) and ((BORD_NUM + hosei) > 0) and (math.floor((BORD_NUM - 1) / 9) == math.floor((BORD_NUM - 1 + hosei) / 9)) then BOARD_POSSIBLE[BORD_NUM + hosei] = 1 if ANG_NUM[BOARD_NUM[BORD_NUM]] == ANG_NUM[BOARD_NUM[BORD_NUM + hosei]] then BOARD_POSSIBLE[BORD_NUM + hosei] = 0 end end elseif i == 4 then hosei = -9 if ((BORD_NUM + hosei) <= #BOARD_NUM) and ((BORD_NUM + hosei) > 0) and (math.floor(-1 + (BORD_NUM - 1) / 9) == math.floor((BORD_NUM - 1 + hosei) / 9)) then BOARD_POSSIBLE[BORD_NUM + hosei] = 1 if ANG_NUM[BOARD_NUM[BORD_NUM]] == ANG_NUM[BOARD_NUM[BORD_NUM + hosei]] then BOARD_POSSIBLE[BORD_NUM + hosei] = 0 end end end end else for i = 1, 4 do if i == 1 then hosei = 7 for i2 = 1, 3 do if ((BORD_NUM - hosei - i2) <= #BOARD_NUM) and ((BORD_NUM - hosei - i2) > 0) and (math.floor(-1 + (BORD_NUM - 1) / 9) == math.floor((BORD_NUM - 1 - hosei - i2) / 9)) then BOARD_POSSIBLE[BORD_NUM - hosei - i2] = 1 if ANG_NUM[BOARD_NUM[BORD_NUM]] == ANG_NUM[BOARD_NUM[BORD_NUM - hosei - i2]] then BOARD_POSSIBLE[BORD_NUM - hosei - i2] = 0 end end end elseif i == 2 then hosei = -1 if ((BORD_NUM - hosei) <= #BOARD_NUM) and ((BORD_NUM - hosei) > 0) and (math.floor((BORD_NUM - 1) / 9) == math.floor((BORD_NUM - 1 - hosei) / 9)) then BOARD_POSSIBLE[BORD_NUM - hosei] = 1 if ANG_NUM[BOARD_NUM[BORD_NUM]] == ANG_NUM[BOARD_NUM[BORD_NUM - hosei]] then BOARD_POSSIBLE[BORD_NUM - hosei] = 0 end end elseif i == 3 then hosei = 1 if ((BORD_NUM - hosei) <= #BOARD_NUM) and ((BORD_NUM - hosei) > 0) and (math.floor((BORD_NUM - 1) / 9) == math.floor((BORD_NUM - 1 - hosei) / 9)) then BOARD_POSSIBLE[BORD_NUM - hosei] = 1 if ANG_NUM[BOARD_NUM[BORD_NUM]] == ANG_NUM[BOARD_NUM[BORD_NUM - hosei]] then BOARD_POSSIBLE[BORD_NUM - hosei] = 0 end end elseif i == 4 then hosei = -9 if ((BORD_NUM - hosei) <= #BOARD_NUM) and ((BORD_NUM - hosei) > 0) and (math.floor(1 + (BORD_NUM - 1) / 9) == math.floor((BORD_NUM - 1 - hosei) / 9)) then BOARD_POSSIBLE[BORD_NUM - hosei] = 1 if ANG_NUM[BOARD_NUM[BORD_NUM]] == ANG_NUM[BOARD_NUM[BORD_NUM - hosei]] then BOARD_POSSIBLE[BORD_NUM - hosei] = 0 end end end end end end BOARD_POSSIBLE[BORD_NUM] = 1