2019-07-07 07:48:39 UNSELECTED

Unknown type code

Copy Copied! Full
--簡略化 local ASET = vci.assets local STAT = vci.state local VEC001 = Vector3.__new(0, 0, 1) --Unity駒の名称 local FRM_STR = { "Frame1", "Frame2", "Frame3", "Frame4", "Frame5", "Frame6", "Frame7", "Frame8", "Frame9", "Frame10", "Frame11", "Frame12", "Frame13", "Frame14", "Frame15", "Frame16", "Frame17", "Frame18", "Frame19", "Frame20", "Frame21", "Frame22", "Frame23", "Frame24", "Frame25", "Frame26", "Frame27", "Frame28", "Frame29", "Frame30", "Frame31", "Frame32", "Frame33", "Frame34", "Frame35", "Frame36", "Frame37", "Frame38", "Frame39", "Frame40", "Frame41", "Frame42", "Frame43", "Frame44", "Frame45", "Frame46", "Frame47", "Frame48", "Frame49", "Frame50", "Frame51", "Frame52", "Frame53", "Frame54", "Frame55", "Frame56", "Frame57", "Frame58", "Frame59", "Frame60", "Frame61", "Frame62", "Frame63", "Frame64" } --FRM_STR使用されているかどうか local FRM_FLG = { 1, 1, 1, 1, 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 } --FRM_STRに対応するサブアイテム保持 local FRM_SUBITEM = { 1, 1, 1, 1, 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 } for i = 1, #FRM_STR do FRM_SUBITEM[i] = ASET.GetSubItem(FRM_STR[i]) end local BOARD_SUBITEM = ASET.GetSubItem("Board") local FRAME100_SUBITEM = ASET.GetSubItem("Frame100") local BRACK_SUBITEM = ASET.GetSubItem("Black") local BRACK2_SUBITEM = ASET.GetSubItem("Black2") local TARG_NUM = 0 --FRM_STRの掴んだ番号 --盤面に置かれているFRM_STRの番号 local BRD_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, 1, 2, 0, 0, 0, 0, 0, 0, 3, 4, 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:黒、90:駒なし、180:白) local BRD_ANG = { 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 180, 0, 90, 90, 90, 90, 90, 90, 0, 180, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90 } local GRIP_FLG = false --グリップ判定 local USE_FLG = false --使用判定 local BLACK_FLG = false --黒カプセルが押された local WHITE_FLG = false --白カプセルが押された local RETURN_FLG = false local ang = 0 --現在駒方向 local ANG = 0 --現在の手番を表す local Mine = false --VCI所有者かどうか --ボード状態保持のため local Board = { frm_flg = {}, brd_flg = {}, brd_ang = {}, now_ang = 0, stones = 0 } local board = Board --luaでのテーブル複製 function TableCreate(table_data) local new = {} for k, v in ipairs(table_data) do new[k] = v end return new end function update() Mine = true --VCI所有者である TARG_NUM = STAT.Get("TARG_NUM") --ゲーム初期化 if WHITE_FLG or STAT.Get("WHITE_FLG") then WHITE_FLG = false BLACK_FLG = true --下も起動 ang = 0 for i = 1, #FRM_FLG do if i > 4 then FRM_FLG[i] = 0 end if i == 28 then BRD_FLG[i] = 1 BRD_ANG[i] = 180 elseif i == 37 then BRD_FLG[i] = 2 BRD_ANG[i] = 180 elseif i == 29 then BRD_FLG[i] = 3 BRD_ANG[i] = 0 elseif i == 36 then BRD_FLG[i] = 4 BRD_ANG[i] = 0 else BRD_FLG[i] = 0 BRD_ANG[i] = 90 end end STAT.Set("WHITE_FLG", WHITE_FLG) STAT.Set("BLACK_FLG", BLACK_FLG) end if RETURN_FLG or STAT.Get("RETURN_FLG") then --戻る盤面があれば if #board.frm_flg > 0 then FRM_FLG = TableCreate(board.frm_flg) BRD_FLG = TableCreate(board.brd_flg) BRD_ANG = TableCreate(board.brd_ang) ang = board.now_ang RETURN_FLG = false BLACK_FLG = true STAT.Set("RETURN_FLG", RETURN_FLG) STAT.Set("BLACK_FLG", BLACK_FLG) end end --石の置いてある数 local stones = 0 for i = 1, #FRM_FLG do if FRM_FLG[i] == 1 then stones = stones + 1 end end --石がすべて置かれている if #FRM_FLG == stones then local brd_ang = TableCreate(BRD_ANG) --並び替え local black_count = 1 --黒が最初だから変数名がこれ --白黒 for i2 = 1, 2 do --全探索 for i = 1, #brd_ang do if i2 == 1 then --黒配置 if brd_ang[i] == 0 then BRD_FLG[black_count] = black_count BRD_ANG[black_count] = 0 black_count = black_count + 1 end else --白配置 if brd_ang[i] == 180 then BRD_FLG[black_count] = black_count BRD_ANG[black_count] = 180 black_count = black_count + 1 end end end end end --配置可能場所探索 local move_table = true for i = 1, #BRD_FLG do --置かれてない場所 if BRD_FLG[i] == 0 then --その場所にangの駒を置けるかどうか if PosibleSearch22(i, ang, BRD_ANG) then move_table = false break end end end --配置可能場所がなければ次 if move_table then if ang == 0 then ang = 180 else ang = 0 end end --グリップされていたならば if GRIP_FLG or STAT.Get("GRIP_FLG") then local min = 0 --近傍マス目 local min_loc = 0.06 --最近傍距離 --現在持っている駒の位置と盤面のマス目の最近傍を求める for i = 1, #BRD_FLG do --おいてない場所なら if BRD_FLG[i] == 0 then local OBJ = BOARD_SUBITEM local POS = OBJ.GetPosition() ANG = Vector3.Angle(VEC001, OBJ.GetForward()) if OBJ.GetForward().x < 0 then ANG = -1 * ANG end local sho = (-3.5 + math.floor((i - 1) / 8)) * 0.08 local ama = (-3.5 + (i - 1) % 8) * 0.08 OBJ = FRM_SUBITEM[TARG_NUM] local ANG2 = Vector3.Angle(VEC001, 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 --luaでは配列[0]エラーになるから、それ以外の時補助の駒を動かす local OBJ = BOARD_SUBITEM local POS = OBJ.GetPosition() if min > 0 then ANG = Vector3.Angle(VEC001, OBJ.GetForward()) if OBJ.GetForward().x < 0 then ANG = -1 * ANG end local sho = (-3.5 + math.floor((min - 1) / 8)) * 0.08 local ama = (-3.5 + (min - 1) % 8) * 0.08 OBJ = FRAME100_SUBITEM local ANG2 = Vector3.Angle(VEC001, 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(ang, 0, 0)) else OBJ = BOARD_SUBITEM POS = OBJ.GetPosition() OBJ = FRAME100_SUBITEM OBJ.SetPosition(Vector3.__new(POS.x, 0, POS.z)) end --使用されたならば if USE_FLG or STAT.Get("USE_FLG") then if min > 0 then GRIP_FLG = false STAT.Set("GRIP_FLG", GRIP_FLG) --駒状態保持 board.frm_flg = TableCreate(FRM_FLG) board.brd_flg = TableCreate(BRD_FLG) board.brd_ang = TableCreate(BRD_ANG) board.now_ang = ang --駒置けるところを探す PosibleSearch(min) --駒をとれた(置けた)ならば次の人 if BRD_FLG[min] > 0 then BRD_ANG[min] = ang FRM_FLG[TARG_NUM] = 1 if ang == 0 then ang = 180 else ang = 0 end end USE_FLG = false STAT.Set("USE_FLG", USE_FLG) end end else --補助駒のみ local OBJ = BOARD_SUBITEM local POS = OBJ.GetPosition() OBJ = FRAME100_SUBITEM OBJ.SetPosition(Vector3.__new(POS.x, -10, POS.z)) end for i = 1, #FRM_FLG do if FRM_FLG[i] ~= STAT.Get(tostring(i)) then STAT.Set(tostring(i), FRM_FLG[i]) end end for i = 1, #BRD_FLG do if BRD_FLG[i] ~= STAT.Get(tostring(i + 100)) then STAT.Set(tostring(i + 100), BRD_FLG[i]) end end for i = 1, #BRD_ANG do if BRD_ANG[i] ~= STAT.Get(tostring(i + 200)) then STAT.Set(tostring(i + 200), BRD_ANG[i]) end end end local timer = 0 local timer_count = 0.6 function updateAll() if Mine then else if (os.time() - timer) > timer_count then for i = 1, #FRM_FLG do if not (STAT.Get(tostring(i)) == nil) then FRM_FLG[i] = STAT.Get(tostring(i)) end end for i = 1, #BRD_FLG do if not (STAT.Get(tostring(i)) == nil) then BRD_FLG[i] = STAT.Get(tostring(i + 100)) end end for i = 1, #BRD_ANG do if not (STAT.Get(tostring(i)) == nil) then BRD_ANG[i] = STAT.Get(tostring(i + 200)) end end timer_count = os.time() end end --駒を黒カプセル周辺に集める if BLACK_FLG or STAT.Get("BLACK_FLG") then local OBJ = BOARD_SUBITEM ANG = Vector3.Angle(VEC001, OBJ.GetForward()) if OBJ.GetForward().x < 0 then ANG = -1 * ANG end OBJ = BRACK_SUBITEM local POS = OBJ.GetPosition() local num1 = 1 local OBJS = BRACK2_SUBITEM local POSS = OBJS.GetPosition() local num2 = 1 --並べる処理 for i = 1, #FRM_FLG do --大体半分 if i <= #FRM_FLG / 2 + 1 then --未使用 if FRM_FLG[i] == 0 then OBJ = FRM_SUBITEM[i] if OBJ.IsMine then OBJ.SetPosition( Vector3.__new( POS.x + 0.04 * num1 * math.cos(-math.pi * ANG / 180), POS.y, POS.z + 0.04 * num1 * math.sin(-math.pi * ANG / 180) ) ) end end num1 = num1 + 1 else --未使用 if FRM_FLG[i] == 0 then OBJS = FRM_SUBITEM[i] if OBJS.IsMine then OBJS.SetPosition( Vector3.__new( POSS.x + (0.04 * num2 + 0.12) * math.cos(-math.pi * ANG / 180), POSS.y, POSS.z + (0.04 * num2 + 0.12) * math.sin(-math.pi * ANG / 180) ) ) end end num2 = num2 + 1 end end BLACK_FLG = false STAT.Set("BLACK_FLG", BLACK_FLG) GRIP_FLG = false STAT.Set("GRIP_FLG", GRIP_FLG) end Move_STROBJ() end function onUse(use) --駒を使用したならば for i = 1, #FRM_STR do if FRM_FLG[i] == 0 then if use == FRM_STR[i] then USE_FLG = true STAT.Set("USE_FLG", USE_FLG) end end end if use == "White" then WHITE_FLG = true STAT.Set("WHITE_FLG", WHITE_FLG) BLACK_FLG = true STAT.Set("BLACK_FLG", BLACK_FLG) end if use == "Black" or use == "Black2" then BLACK_FLG = true STAT.Set("BLACK_FLG", BLACK_FLG) end if use == "Return" then BLACK_FLG = true STAT.Set("BLACK_FLG", BLACK_FLG) local FIRST_FLG = true STAT.Set("FIRST_FLG", FIRST_FLG) RETURN_FLG = true STAT.Set("RETURN_FLG", RETURN_FLG) end end function onTriggerExit(it, h) Velo_Ang_Zero(it) end function onCollisionExit(it, h) Velo_Ang_Zero(it) end function onGrab(tar) --駒を握ったならば for i = 1, #FRM_STR do if FRM_FLG[i] == 0 then if tar == FRM_STR[i] then TARG_NUM = i GRIP_FLG = true STAT.Set("GRIP_FLG", GRIP_FLG) STAT.Set("TARG_NUM", TARG_NUM) end end end end function onUngrab(tar) --駒を離したならば for i = 1, #FRM_STR do if FRM_FLG[i] == 0 then if tar == FRM_STR[i] then TARG_NUM = 0 STAT.Set("TARG_NUM", TARG_NUM) GRIP_FLG = false STAT.Set("GRIP_FLG", GRIP_FLG) end end end Velo_Ang_Zero(tar) end function Velo_Ang_Zero(it) local OBJ = ASET.GetSubItem(it) if OBJ ~= nil then OBJ.SetVelocity(Vector3.__new(0, 0, 0)) OBJ.SetAngularVelocity(Vector3.__new(0, 0, 0)) if it == "Board" then OBJ.SetRotation(Quaternion.Euler(0, ANG, 0)) local FIRST_FLG = true STAT.Set("FIRST_FLG", FIRST_FLG) end local FIRST_FLG = true STAT.Set("FIRST_FLG", FIRST_FLG) end end --駒をBRD_FLGに従い配置 function Move_STROBJ() --駒をBRD_FLGに従い配置 for i = 1, #BRD_FLG do --駒がある if BRD_FLG[i] > 0 then local OBJ = BOARD_SUBITEM local POS = OBJ.GetPosition() ANG = Vector3.Angle(VEC001, OBJ.GetForward()) if OBJ.GetForward().x < 0 then ANG = -1 * ANG end local sho = (-3.5 + math.floor((i - 1) / 8)) * 0.08 local ama = (-3.5 + (i - 1) % 8) * 0.08 OBJ = FRM_SUBITEM[BRD_FLG[i]] if OBJ.IsMine then local ANG2 = Vector3.Angle(VEC001, 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(BRD_ANG[i], 0, 0)) end end end end --駒を置けるか探す処理 function PosibleSearch22(min, now_ang, brd_ang) --ここから横縦斜めの、駒置けるか判断する処理 local ama = (min - 1) % 8 local num = 0 local FLG = false for i = 1, 7 - ama do if not (brd_ang[min + i] == now_ang) then if brd_ang[min + i] == 90 then break else num = num + 1 end else if num > 0 then FLG = true end break end end if FLG then return true end num = 0 FLG = false for i = 1, ama do if not (brd_ang[min - i] == now_ang) then if brd_ang[min - i] == 90 then break else num = num + 1 end else if num > 0 then FLG = true end break end end if FLG then return true end local sho = math.floor((min - 1) / 8) num = 0 FLG = false for i = 1, 7 - sho do if not (brd_ang[min + i * 8] == now_ang) then if brd_ang[min + i * 8] == 90 then break else num = num + 1 end else if num > 0 then FLG = true end break end end if FLG then return true end num = 0 FLG = false for i = 1, sho do if not (brd_ang[min - i * 8] == now_ang) then if brd_ang[min - i * 8] == 90 then break else num = num + 1 end else if num > 0 then FLG = true end break end end if FLG then return true end --斜 num = 0 FLG = false local data = 0 if (7 - sho) < (7 - ama) then data = 7 - sho else data = 7 - ama end for i = 1, data do if min + i * 9 < 65 then if not (brd_ang[min + i * 9] == now_ang) then if brd_ang[min + i * 9] == 90 then break else num = num + 1 end else if num > 0 then FLG = true end break end else break end end if FLG then return true end num = 0 FLG = false if sho < ama then data = sho else data = ama end for i = 1, data do if min - i * 9 > 0 then if not (brd_ang[min - i * 9] == now_ang) then if brd_ang[min - i * 9] == 90 then break else num = num + 1 end else if num > 0 then FLG = true end break end else break end end if FLG then return true end num = 0 FLG = false if sho < (7 - ama) then data = sho else data = 7 - ama end for i = 1, data do if min - i * 7 > 0 then if not (brd_ang[min - i * 7] == now_ang) then if brd_ang[min - i * 7] == 90 then break else num = num + 1 end else if num > 0 then FLG = true end break end else break end end if FLG then return true end num = 0 FLG = false if (7 - sho) < ama then data = 7 - sho else data = ama end for i = 1, data do if min + i * 7 < 65 then if not (brd_ang[min + i * 7] == now_ang) then if brd_ang[min + i * 7] == 90 then break else num = num + 1 end else if num > 0 then FLG = true end break end else break end end if FLG then return true end return false end --駒を置けるか探す処理 function PosibleSearch(min) --ここから横縦斜めの、駒置けるか判断する処理 local ama = (min - 1) % 8 local num = 0 local FLG = false for i = 1, 7 - ama do if not (BRD_ANG[min + i] == ang) then if BRD_ANG[min + i] == 90 then break else num = num + 1 end else if num > 0 then FLG = true end break end end if FLG then for i = 1, num do BRD_ANG[min + i] = ang end BRD_FLG[min] = TARG_NUM end num = 0 FLG = false for i = 1, ama do if not (BRD_ANG[min - i] == ang) then if BRD_ANG[min - i] == 90 then break else num = num + 1 end else if num > 0 then FLG = true end break end end if FLG then for i = 1, num do BRD_ANG[min - i] = ang end BRD_FLG[min] = TARG_NUM end local sho = math.floor((min - 1) / 8) num = 0 FLG = false for i = 1, 7 - sho do if not (BRD_ANG[min + i * 8] == ang) then if BRD_ANG[min + i * 8] == 90 then break else num = num + 1 end else if num > 0 then FLG = true end break end end if FLG then for i = 1, num do BRD_ANG[min + i * 8] = ang end BRD_FLG[min] = TARG_NUM end num = 0 FLG = false for i = 1, sho do if not (BRD_ANG[min - i * 8] == ang) then if BRD_ANG[min - i * 8] == 90 then break else num = num + 1 end else if num > 0 then FLG = true end break end end if FLG then for i = 1, num do BRD_ANG[min - i * 8] = ang end BRD_FLG[min] = TARG_NUM end --斜 num = 0 FLG = false local data = 0 if (7 - sho) < (7 - ama) then data = 7 - sho else data = 7 - ama end for i = 1, data do if min + i * 9 < 65 then if not (BRD_ANG[min + i * 9] == ang) then if BRD_ANG[min + i * 9] == 90 then break else num = num + 1 end else if num > 0 then FLG = true end break end else break end end if FLG then for i = 1, num do BRD_ANG[min + i * 9] = ang end BRD_FLG[min] = TARG_NUM end num = 0 FLG = false if sho < ama then data = sho else data = ama end for i = 1, data do if min - i * 9 > 0 then if not (BRD_ANG[min - i * 9] == ang) then if BRD_ANG[min - i * 9] == 90 then break else num = num + 1 end else if num > 0 then FLG = true end break end else break end end if FLG then for i = 1, num do BRD_ANG[min - i * 9] = ang end BRD_FLG[min] = TARG_NUM end num = 0 FLG = false if sho < (7 - ama) then data = sho else data = 7 - ama end for i = 1, data do if min - i * 7 > 0 then if not (BRD_ANG[min - i * 7] == ang) then if BRD_ANG[min - i * 7] == 90 then break else num = num + 1 end else if num > 0 then FLG = true end break end else break end end if FLG then for i = 1, num do BRD_ANG[min - i * 7] = ang end BRD_FLG[min] = TARG_NUM end num = 0 FLG = false if (7 - sho) < ama then data = 7 - sho else data = ama end for i = 1, data do if min + i * 7 < 65 then if not (BRD_ANG[min + i * 7] == ang) then if BRD_ANG[min + i * 7] == 90 then break else num = num + 1 end else if num > 0 then FLG = true end break end else break end end if FLG then for i = 1, num do BRD_ANG[min + i * 7] = ang end BRD_FLG[min] = TARG_NUM end --駒をとれた(置けた)ならば次の人 if BRD_FLG[min] > 0 then -- flg = true end end