155 lines
3.8 KiB
Plaintext
155 lines
3.8 KiB
Plaintext
-- p1 is White, clockwise order
|
|
|
|
SET_ASIDE_POSITIONS = {
|
|
p1={ x=-64.2, y=2, z=27.2 },
|
|
p2={ x=-64.2, y=2, z=-27.2 },
|
|
p3={ x=-11, y=2, z=36 },
|
|
p4={ x=-11, y=2, z=-36}
|
|
}
|
|
|
|
DRAW_DECK_POSITIONS = {
|
|
p1={ x=-55, y=2.5, z=4.5 },
|
|
p2={ x=-55, y=2.5, z=-22.7 },
|
|
p3={ x=-37, y=2.5, z=26.5 },
|
|
p4={ x=-18.9, y=2.5, z=-26.7 }
|
|
}
|
|
|
|
HAND_ZONE_POSITIONS = {
|
|
p1={ x=-65, z=13 },
|
|
p2={ x=-65, z=-13 },
|
|
p3={ x=-28, z=36 },
|
|
p4={ x=-28, z=-36 }
|
|
}
|
|
|
|
MAT_GUIDS = {
|
|
p1="8b081b",
|
|
p2="bd0ff4",
|
|
p3="383d8b",
|
|
p4="0840d5"
|
|
}
|
|
|
|
function onLoad(save_state)
|
|
self.addContextMenuItem("Bind to my color", bindColor)
|
|
|
|
playerPosition = "p1"
|
|
playerColor = "White"
|
|
|
|
if save_state ~= nil then
|
|
local obj = JSON.decode(save_state)
|
|
if obj ~= nil and obj.playerColor ~= nil and obj.playerPosition ~= nil then
|
|
playerColor = obj.playerColor
|
|
playerPosition = obj.playerPosition
|
|
end
|
|
end
|
|
end
|
|
|
|
function onSave()
|
|
return JSON.encode({
|
|
playerColor = playerColor,
|
|
playerPosition = playerPosition
|
|
})
|
|
end
|
|
|
|
function bindColor(player_color)
|
|
playerColor = player_color
|
|
local pos = Player[playerColor].getHandTransform().position
|
|
|
|
matchingPos = nil
|
|
for k in pairs(HAND_ZONE_POSITIONS) do
|
|
zonePos = HAND_ZONE_POSITIONS[k]
|
|
if pos.x > (zonePos.x-1) and pos.x < (zonePos.x+1) and pos.z > (zonePos.z-1) and pos.z < (zonePos.z+1) then
|
|
matchingPos = k
|
|
break
|
|
end
|
|
end
|
|
|
|
if matchingPos ~= nil then
|
|
playerPosition = matchingPos
|
|
else
|
|
print("Matching hand zone was not found for " .. playerColor .. " player")
|
|
end
|
|
|
|
self.setName(playerColor .. " Search Assistant")
|
|
end
|
|
|
|
function getDrawDeck ()
|
|
mat.call("getDrawDiscardDecks")
|
|
return mat.getVar("drawDeck")
|
|
end
|
|
|
|
function shuffleDrawDeck ()
|
|
local deck = getDrawDeck()
|
|
if deck ~= nil then
|
|
deck.shuffle()
|
|
end
|
|
end
|
|
|
|
function setAside ()
|
|
local rot = mat.getRotation()
|
|
local offset = Vector(0, 0.2, 0)
|
|
local targetPos = Vector(SET_ASIDE_POSITIONS[playerPosition]) + Vector(0, 6, 0)
|
|
local hand = Player[playerColor].getHandObjects()
|
|
for i=#hand,1,-1 do
|
|
local card = hand[i]
|
|
card.setPosition(targetPos - i*offset)
|
|
card.setRotation(Vector(rot.x, rot.y, 180))
|
|
end
|
|
end
|
|
|
|
function drawSetAside ()
|
|
local objs = Physics.cast({
|
|
origin = SET_ASIDE_POSITIONS[playerPosition],
|
|
direction = { x=0, y=1, z=0 },
|
|
type = 3,
|
|
size = { 2, 5, 2}
|
|
})
|
|
for i,v in ipairs(objs) do
|
|
local obj = v.hit_object
|
|
if obj.tag == "Deck" then
|
|
Wait.time(function ()
|
|
obj.deal(#obj.getObjects(), playerColor)
|
|
end, 1)
|
|
break
|
|
end
|
|
end
|
|
end
|
|
|
|
function updateSearchNumber (player, value, id)
|
|
searchNumber = value
|
|
if searchNumber ~= nil then
|
|
searchNumber = tonumber(searchNumber)
|
|
end
|
|
end
|
|
|
|
function search (player, value, id)
|
|
if searchNumber == nil then return end
|
|
|
|
self.UI.hide("startSearch")
|
|
self.UI.show("endSearch")
|
|
mat = getObjectFromGUID(MAT_GUIDS[playerPosition])
|
|
setAside()
|
|
local deck = getDrawDeck()
|
|
Wait.time(function ()
|
|
deck.deal(searchNumber, playerColor)
|
|
end, 1)
|
|
end
|
|
|
|
function doneSearching (player, shuffle)
|
|
-- place hand back into deck and optionally shuffle
|
|
local hand = Player[playerColor].getHandObjects()
|
|
local offset = Vector(0, 0.2, 0)
|
|
local rot = mat.getRotation()
|
|
local targetPos = Vector(DRAW_DECK_POSITIONS[playerPosition]) + Vector(0, 8, 0)
|
|
for i=#hand,1,-1 do
|
|
local card = hand[i]
|
|
card.setPosition(targetPos - i*offset)
|
|
card.setRotation(Vector(rot.x, rot.y, 180))
|
|
end
|
|
if shuffle == "true" then
|
|
Wait.time(|| shuffleDrawDeck(), 2)
|
|
end
|
|
|
|
self.UI.hide("endSearch")
|
|
self.UI.show("startSearch")
|
|
drawSetAside()
|
|
end |