2019-07-07 07:38:25 UNSELECTED

Unknown type code

Copy Copied! Full
--簡略化 local STAT = vci.state local ASET = vci.assets --Unity駒の名称 local CUBE_STR = { "Cube0", "Cube1", "Cube2", "Cube3", "Cube4", "Cube5", "Cube6", "Cube7", "Cube8", "Cube9" } local CUBE_STR_SUBITEM = { "Cube0", "Cube1", "Cube2", "Cube3", "Cube4", "Cube5", "Cube6", "Cube7", "Cube8", "Cube9" } for i = 1, #CUBE_STR_SUBITEM do CUBE_STR_SUBITEM[i] = ASET.GetSubItem(CUBE_STR[i]) end --盤面のどこにどの駒があるか local BOARD_NUM = { 1, 2, 3, 4, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 8, 9, 10 } --初期化用 local BOARD_NUM_CPY = { 1, 2, 3, 4, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 8, 9, 10 } local BOARD_SUBITEM = ASET.GetSubItem("Board") local CUBE99_SUBITEM = ASET.GetSubItem("Cube99") local MAT_SUBITEM = ASET.GetSubItem("MAT") local FIRST_FLG = true --初期化 local TARG_NUM = 0 --駒の掴んだ番号 local GRIP_FLG = false --グリップ local USE_FLG = false --使用 local BORD_NUM = 0 --使用した直下の盤の番号 local CENTER_NUM = 13 --中央 local GAMEEND_FLG = false --ゲーム終了 local GAMEEND_FLG_FLG = true local Mine = false --VCI所有者かどうか ---アイテムを生成したユーザーで毎フレーム呼ばれる function updateAll() if Mine then else for i = 1, #BOARD_NUM do BOARD_NUM[i] = STAT.Get(tostring(i)) end end --配置 if FIRST_FLG or STAT.Get("FIRST_FLG") then if GAMEEND_FLG_FLG or STAT.Get("GAMEEND_FLG_FLG") then if Mine then --初期化 for i = 1, #BOARD_NUM do BOARD_NUM[i] = BOARD_NUM_CPY[i] end GAMEEND_FLG = false STAT.Set("GAMEEND_FLG", GAMEEND_FLG) GAMEEND_FLG_FLG = false STAT.Set("GAMEEND_FLG_FLG", GAMEEND_FLG_FLG) end end FIRST_FLG = false STAT.Set("FIRST_FLG", FIRST_FLG) Move_STROBJ() end end ---全ユーザーで毎フレーム呼ばれる function update() Mine = true TARG_NUM = STAT.Get("TARG_NUM") BORD_NUM = STAT.Get("BORD_NUM") --ゲームが続いてる if (GAMEEND_FLG == false) or (STAT.Get("GAMEEND_FLG") == false) then --握っている if (GRIP_FLG or STAT.Get("GRIP_FLG")) and (TARG_NUM > 0) and (BORD_NUM > 0) then local min = 0 --方向保持 local min_loc = 0.06 --最近傍の値 --方向決定 for i = 1, 4 do local hosei = 0 if i == 1 then if ((BORD_NUM + 1) <= #BOARD_NUM) and (math.floor((BORD_NUM - 1) / 5) == math.floor((BORD_NUM) / 5)) then if BOARD_NUM[BORD_NUM + 1] == 0 then hosei = 1 end end elseif i == 2 then if ((BORD_NUM - 1) > 0) and (math.floor((BORD_NUM - 1) / 5) == math.floor((BORD_NUM - 2) / 5)) then if BOARD_NUM[BORD_NUM - 1] == 0 then hosei = -1 end end elseif i == 3 then if (BORD_NUM + 5) <= #BOARD_NUM then if BOARD_NUM[BORD_NUM + 5] == 0 then hosei = 5 end end elseif i == 4 then if (BORD_NUM - 5) > 0 then if BOARD_NUM[BORD_NUM - 5] == 0 then hosei = -5 end end end --移動可能であるならば、補助マス表示 if hosei ~= 0 then local OBJ = BOARD_SUBITEM local POS = OBJ.GetPosition() local ANG = Vector3.Angle(Vector3.__new(0, 0, 1), OBJ.GetForward()) if OBJ.GetForward().x < 0 then ANG = -1 * ANG end local sho = (-2 + math.floor((BORD_NUM + hosei - 1) / 5)) * 0.14 local ama = (-2 + (BORD_NUM + hosei - 1) % 5) * 0.14 OBJ = CUBE_STR_SUBITEM[TARG_NUM] local ANG2 = Vector3.Angle(Vector3.__new(0, 0, 1), Vector3.__new(sho, 0, ama).normalized) if sho < 0 then ANG2 = -1 * ANG2 end local pow1 = sho * sho local pow2 = ama * ama local POS2 = POS POS2.Set( POS.x + math.sqrt(pow1 + pow2) * math.sin(math.pi * (ANG2 - ANG) / 180), POS.y + 0.1, POS.z - math.sqrt(pow1 + pow2) * math.cos(math.pi * (ANG2 - ANG) / 180) ) POS = OBJ.GetPosition() local 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 end local hosei = 0 --方向で補正値決定 if min > 0 then if min == 1 then hosei = 1 elseif min == 2 then hosei = -1 elseif min == 3 then hosei = 5 elseif min == 4 then hosei = -5 end end --移動したところの値を求める local num = BORD_NUM --移動したところの値 for i = 1, 4 do if (hosei == -1) or (hosei == 1) then if ((BORD_NUM + hosei * i) <= #BOARD_NUM) and ((BORD_NUM + hosei * i) > 0) and (BOARD_NUM[(BORD_NUM + hosei * i)] == 0) and (math.floor((BORD_NUM - 1) / 5) == math.floor((BORD_NUM - 1 + hosei * i) / 5)) then num = BORD_NUM + hosei * i else break end else if ((BORD_NUM + hosei * i) <= #BOARD_NUM) and ((BORD_NUM + hosei * i) > 0) and (BOARD_NUM[(BORD_NUM + hosei * i)] == 0) then num = BORD_NUM + hosei * i else break end end end --補助駒移動 if num > 0 then local OBJ = BOARD_SUBITEM local POS = OBJ.GetPosition() local ANG = Vector3.Angle(Vector3.__new(0, 0, 1), OBJ.GetForward()) if OBJ.GetForward().x < 0 then ANG = -1 * ANG end local sho = (-2 + math.floor((num - 1) / 5)) * 0.14 local ama = (-2 + (num - 1) % 5) * 0.14 OBJ = CUBE99_SUBITEM local ANG2 = Vector3.Angle(Vector3.__new(0, 0, 1), Vector3.__new(sho, 0, ama).normalized) if sho < 0 then ANG2 = -1 * ANG2 end local pow1 = sho * sho local pow2 = ama * ama OBJ.SetPosition( Vector3.__new( POS.x + math.sqrt(pow1 + pow2) * math.sin(math.pi * (ANG2 - ANG) / 180), POS.y + 0.1, POS.z - math.sqrt(pow1 + pow2) * math.cos(math.pi * (ANG2 - ANG) / 180) ) ) OBJ.SetRotation(Quaternion.Euler(0, ANG, 0)) end --使用した if USE_FLG or STAT.Get("USE_FLG") then --移動していれば if num > 0 then GRIP_FLG = false STAT.Set("GRIP_FLG", GRIP_FLG) --自位置でないならば if not (BORD_NUM == num) then BOARD_NUM[num] = BOARD_NUM[BORD_NUM] BOARD_NUM[BORD_NUM] = 0 end end USE_FLG = false STAT.Set("USE_FLG", USE_FLG) end else local OBJS = CUBE99_SUBITEM OBJS.SetPosition(Vector3.__new(0, 0, 0)) end end --ゲーム終了処理 local OBJ = BOARD_SUBITEM local POS = OBJ.GetPosition() local ANG = Vector3.Angle(Vector3.__new(0, 0, 1), OBJ.GetForward()) if OBJ.GetForward().x < 0 then ANG = -1 * ANG end local OBJS = MAT_SUBITEM if (BOARD_NUM[CENTER_NUM] == 3) or (BOARD_NUM[CENTER_NUM] == 8) then OBJS.SetPosition(Vector3.__new(POS.x, POS.y + 0.4, POS.z)) OBJS.SetRotation(Quaternion.Euler(0, ANG, 90)) local col = 0 if BOARD_NUM[CENTER_NUM] > 5 then col = Color.__new(0, 0, 0) else col = Color.__new(1, 1, 1) end ASET._ALL_SetMaterialColorFromName("MAT", col) GAMEEND_FLG = true elseif BOARD_NUM[CENTER_NUM] > 0 then OBJS.SetPosition(Vector3.__new(POS.x, POS.y + 0.4, POS.z)) OBJS.SetRotation(Quaternion.Euler(0, ANG, 90)) local col = 0 if BOARD_NUM[CENTER_NUM] > 5 then col = Color.__new(1, 1, 1) else col = Color.__new(0, 0, 0) end ASET._ALL_SetMaterialColorFromName("MAT", col) GAMEEND_FLG = true else OBJS.SetPosition(Vector3.__new(POS.x, POS.y, POS.z)) OBJS.SetRotation(Quaternion.Euler(0, ANG, 0)) end if GAMEEND_FLG ~= STAT.Get("GAMEEND_FLG") then STAT.Set("GAMEEND_FLG", GAMEEND_FLG) end for i = 1, #BOARD_NUM do if BOARD_NUM[i] ~= tostring(i) then STAT.Set(tostring(i), BOARD_NUM[i]) end end end function onUse(use) --初期化 if use == "Capsule" then FIRST_FLG = true STAT.Set("FIRST_FLG", FIRST_FLG) GAMEEND_FLG = nil STAT.Set("GAMEEND_FLG", GAMEEND_FLG) GAMEEND_FLG_FLG = true STAT.Set("GAMEEND_FLG_FLG", GAMEEND_FLG_FLG) end --グリップ中 if GRIP_FLG 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 onCollisionExit(it, h) Velo_Ang_Zero(it, false) end --掴む ---@param target string @GrabされたSubItem名 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 if i == BOARD_NUM[i2] then BORD_NUM = i2 STAT.Set("BORD_NUM", BORD_NUM) break end end break end end end function onUngrab(tar) 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) for i2 = 1, #BOARD_NUM do if i == BOARD_NUM[i2] then BORD_NUM = 0 STAT.Set("BORD_NUM", BORD_NUM) break end end break end end Velo_Ang_Zero(tar, true) end --角度と力0 function Velo_Ang_Zero(item, cube_flg) local OBJ = ASET.GetSubItem(item) if OBJ ~= nil then OBJ.SetVelocity(Vector3.__new(0, 0, 0)) OBJ.SetAngularVelocity(Vector3.__new(0, 0, 0)) if item == "Board" then local 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)) FIRST_FLG = true STAT.Set("FIRST_FLG", FIRST_FLG) end if cube_flg then for i = 1, #CUBE_STR do if item == CUBE_STR[i] then end end end FIRST_FLG = true STAT.Set("FIRST_FLG", FIRST_FLG) end end --駒をBOARD_NUMに従い配置 function Move_STROBJ() local OBJ = BOARD_SUBITEM local POS = OBJ.GetPosition() local 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 local OBJS = ASET.GetSubItem(CUBE_STR[BOARD_NUM[i]]) if OBJS.IsMine then local sho = (-2 + math.floor((i - 1) / 5)) * 0.14 local ama = (-2 + (i - 1) % 5) * 0.14 local ANG2 = Vector3.Angle(Vector3.__new(0, 0, 1), Vector3.__new(sho, 0, ama).normalized) if sho < 0 then ANG2 = -1 * ANG2 end local pow1 = sho * sho local 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, 0)) end end end local OBJS = CUBE99_SUBITEM OBJS.SetPosition(Vector3.__new(POS.x, 0, POS.z)) end