Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function onload()
- --Disables interactable status of objects with GUID in list
- for _, guid in ipairs(interactableDisableList) do
- local obj = getObjectFromGUID(guid)
- if obj then obj.interactable = false end
- end
- --Identify core objects
- spellstoneBag = getObjectFromGUID("f2cfdb")
- gameBoard = getObjectFromGUID("dc281c")
- --Bits to trigger button creation
- spawnScrollButtons()
- spawnLifeButtons()
- end
- --New Round
- --Find players and order them, trigger coroutine
- function buttonClick_newRound(_, clickerColor)
- --Get and organize which players are seated
- local seatedPlayers = getSeatedPlayers()
- --seatedPlayers = playerOrderGuideList --DEBUG LINE------------------------
- --seatedPlayers = {"White", "Green"} --DEBUG LINE--------------------------
- --Activates coroutine to take clear/deal/display actions
- if #seatedPlayers > 1 then
- coroutine_blindfold_all(clickerColor)
- if lockout_scriptIsDealing ~= true then
- lockout_scriptIsDealing = true
- coroutine_newRound(orderTurnList(seatedPlayers))
- else
- broadcastToColor("The script is currently moving tiles. Please wait.", clickerColor, {1,0.1,0.1})
- end
- else
- broadcastToAll("2-5 players needed.", {1,0.1,0.1})
- end
- end
- --Handles dealing to all players, placing 4 hidden tiles, revealed tokens
- function coroutine_newRound(seatedPlayers)
- function embeddedCoroutine()
- --Return all tokens to bag
- local spellstonesReturning = false
- for _, obj in ipairs(getAllObjects()) do
- if obj.getName() == "Spellstone" then
- spellstoneBag.putObject(obj)
- spellstonesReturning = true
- wait(0.05)
- end
- end
- if spellstonesReturning == true then
- wait(1)
- end
- --Shuffle bag
- spellstoneBag.shuffle()
- --Deal 5 tokens to each seated player
- for _, color in ipairs(seatedPlayers) do
- for i, zoneGUID in ipairs(colorToScriptZoneList[color]) do
- sendSpellstoneToPad(scriptZoneToPadList[zoneGUID], i)
- wait(0.2)
- end
- end
- --Place 4 face-down tokens
- for i=0, 3 do
- local pos = {-5.48+2.5*i, 1, 10.9}
- spellstoneBag.takeObject({position=pos, rotation={90,0,0}})
- wait(0.2)
- end
- --If 2/3 player game then put 12/6 tokens out on the board
- if #seatedPlayers <= 3 then
- revealedSpellstoneList = {}
- local pos = gameBoard.getPosition()
- local rot = gameBoard.getRotation()
- local numberOfStonesToPull = 12
- if #seatedPlayers == 3 then
- numberOfStonesToPull = 6
- end
- for i=1, numberOfStonesToPull do
- local placementPos = findGlobalPosWithLocalDirection(pos, rot, 8, 360/numberOfStonesToPull * i)
- placementPos.y = placementPos.y + 8
- spellstoneBag.takeObject({
- position=placementPos, rotation={0,180,0},
- callback="callback_newRound", callback_owner=Global
- })
- wait(0.05)
- end
- end
- --Refreshes life to 6 points
- for buttonPadGUID, entry in pairs(lifeTokenReferenceList) do
- local tokenCount = countAllLifeTokens(entry.zone)
- if tokenCount < 6 then
- for i=1, 6-tokenCount do
- buttonClick_more(getObjectFromGUID(buttonPadGUID))
- end
- end
- end
- lockout_scriptIsDealing = false
- return 1
- end
- startLuaCoroutine(Global, "embeddedCoroutine")
- end
- function callback_newRound(spellstone)
- --Get spellstone value
- local spellstoneValue = spellstone.getVar("spellstoneValue")
- --Track how many of this spellstone have been revealed/placed
- if revealedSpellstoneList[tostring(spellstoneValue)] ~= nil then
- revealedSpellstoneList[tostring(spellstoneValue)] = revealedSpellstoneList[tostring(spellstoneValue)] + 1
- else
- revealedSpellstoneList[tostring(spellstoneValue)] = 1
- end
- --Relative position where the #1 token goes
- local startingPos = {-2.964, 0.18, -7.289}
- --Adjusting startPos for this tile based on its spellstoneValue and how many
- startingPos[1] = startingPos[1] + 1.15 * (revealedSpellstoneList[tostring(spellstoneValue)] - 1)
- startingPos[2] = startingPos[2] + 0
- startingPos[3] = startingPos[3] + 2.062 * (spellstoneValue - 1)
- --Convert pos to global coordinate system
- local rot = gameBoard.getRotation()
- rot.y = rot.y+180
- offsetPos = findLocalPos(startingPos, gameBoard.getPosition(), rot)
- spellstone.setPositionSmooth(offsetPos)
- rot.y = rot.y+90
- spellstone.setRotationSmooth(rot)
- end
- --Deal
- --Triggers dealing
- function buttonClick_deal(_, clickerColor)
- if clickerColor ~= "Black" then
- if lockout_scriptIsDealing ~= true then
- lockout_scriptIsDealing = true
- coroutine_deal(clickerColor)
- else
- broadcastToColor("The script is currently moving tiles. Please wait.", clickerColor, {1,0.1,0.1})
- end
- else
- broadcastToColor("You cannot have spellstones dealt to you in the GM (Black) seat.", clickerColor, {1,0.1,0.1})
- end
- end
- --Deals tile to 1 of 5 spots if a spot is missing a spellstone
- function coroutine_deal(clickerColor)
- function embeddedCoroutine()
- coroutine_blindfold_clicker(clickerColor)
- for i, zoneGUID in ipairs(colorToScriptZoneList[clickerColor]) do
- if #spellstoneBag.getObjects() > 0 then
- if isZoneHoldingASpellstone(getObjectFromGUID(zoneGUID)) == false then
- sendSpellstoneToPad(scriptZoneToPadList[zoneGUID], i)
- wait(0.2)
- end
- else
- broadcastToAll("Spellstone Bag is [u]empty[/u]!", {1,1,1})
- lockout_scriptIsDealing = nil
- return 1
- end
- end
- lockout_scriptIsDealing = nil
- return 1
- end
- startLuaCoroutine(Global, "embeddedCoroutine")
- end
- --Blindfold
- --Triggers blindfolding
- function buttonClick_blindfold(_, clickerColor)
- if #getSeatedPlayers() > 1 then
- coroutine_blindfold(clickerColor)
- else
- broadcastToAll("There are no players to blindfold.", {1,0.1,0.1})
- end
- end
- --Blindfolds all players, counts down 5 seconds, then removes blindfolds
- function coroutine_blindfold_all(clickerColor)
- function embeddedCoroutine()
- local seatedPlayers = getSeatedPlayers()
- --Initial blindfolding
- for _, color in ipairs(orderTurnList(seatedPlayers)) do
- if Player[color].blindfolded == false then
- Player[color].blindfolded = true
- end
- end
- --Countdown
- broadcastToAll("Blindfold will be removed after setup...", {1,1,1})
- wait(5)
- --Removal
- for _, color in ipairs(orderTurnList(seatedPlayers)) do
- if Player[color].blindfolded == true then
- Player[color].blindfolded = false
- end
- end
- return 1
- end
- startLuaCoroutine(Global, "embeddedCoroutine")
- end
- --Blindfolds Clicker, counts down 2 seconds, then removes blindfolds
- function coroutine_blindfold_clicker(clickerColor)
- function embeddedCoroutine()
- local seatedPlayers = getSeatedPlayers()
- --Initial blindfolding
- for _, color in ipairs(orderTurnList(seatedPlayers)) do
- if color == clickerColor then
- if Player[color].blindfolded == false then
- Player[color].blindfolded = true
- end
- end
- end
- --Countdown
- broadcastToAll("Blindfold will be removed in 2...", {1,1,1})
- wait(1)
- broadcastToAll("Blindfold will be removed in 1...", {1,1,1})
- wait(1)
- --Removal
- for _, color in ipairs(orderTurnList(seatedPlayers)) do
- if Player[color].blindfolded == true then
- Player[color].blindfolded = false
- end
- end
- return 1
- end
- startLuaCoroutine(Global, "embeddedCoroutine")
- end
- --Blindfolds everyone except clicker, counts down 3 seconds, then removes blindfolds
- function coroutine_blindfold(clickerColor)
- function embeddedCoroutine()
- local seatedPlayers = getSeatedPlayers()
- --Initial blindfolding
- for _, color in ipairs(orderTurnList(seatedPlayers)) do
- if color ~= clickerColor then
- if Player[color].blindfolded == false then
- Player[color].blindfolded = true
- end
- end
- end
- --Countdown
- broadcastToAll("Blindfold will be removed in 3...", {1,1,1})
- wait(1)
- broadcastToAll("Blindfold will be removed in 2...", {1,1,1})
- wait(1)
- broadcastToAll("Blindfold will be removed in 1...", {1,1,1})
- wait(1)
- --Removal
- for _, color in ipairs(orderTurnList(seatedPlayers)) do
- if Player[color].blindfolded == true then
- Player[color].blindfolded = false
- end
- end
- return 1
- end
- startLuaCoroutine(Global, "embeddedCoroutine")
- end
- --Health counters
- --Lowers Health
- function buttonClick_less(buttonPad)
- buttonPad.AssetBundle.playTriggerEffect(0)
- local buttonPadGUID = buttonPad.getGUID()
- local zoneGUID = lifeTokenReferenceList[buttonPadGUID].zone
- local lifeToken, quantity = findALifeToken(zoneGUID)
- if quantity == -1 then
- destroyObject(lifeToken)
- elseif quantity ~= nil then
- local pos = lifeToken.getPosition()
- pos.y = pos.y-2
- lifeToken.takeObject({
- position=pos, callback="callback_delete", callback_owner=Global
- })
- end
- end
- --Raises health
- function buttonClick_more(buttonPad)
- buttonPad.AssetBundle.playTriggerEffect(1)
- local buttonPadGUID = buttonPad.getGUID()
- local zoneGUID = lifeTokenReferenceList[buttonPadGUID].zone
- local lifeToken, quantity = findALifeToken(zoneGUID)
- quantity = countAllLifeTokens(zoneGUID)
- if lifeToken == nil then
- local tokenBag = getObjectFromGUID(lifeTokenReferenceList[buttonPadGUID].bag)
- local bagPos = tokenBag.getPosition()
- bagPos.y = 0.86
- local bagRot = tokenBag.getRotation()
- tokenBag.takeObject({position=bagPos, rotation=bagRot})
- elseif quantity < 6 then
- local pos = lifeToken.getPosition()
- local rot = lifeToken.getRotation()
- getObjectFromGUID(lifeTokenReferenceList[buttonPadGUID].bag).takeObject({
- position=pos, rotation=rot
- })
- end
- end
- --Pad highlighting
- --Turns the pad white if a spellstone enters its script zone
- function onObjectEnterScriptingZone(enteredZone, enteringObj)
- if enteringObj.getName() == "Spellstone" then
- local enteredZoneGUID = enteredZone.getGUID()
- local pad = getObjectFromGUID(scriptZoneToPadList[enteredZoneGUID])
- if pad ~= nil then
- pad.setColorTint({1,1,1})
- end
- end
- end
- --Turns the pad (almost) black if a spellstone leaves (and there isn't one now)
- function onObjectLeaveScriptingZone(leftZone, leavingObj)
- if leavingObj.getName() == "Spellstone" then
- if isZoneHoldingASpellstone(leftZone) == false then
- local leftZoneGUID = leftZone.getGUID()
- local pad = getObjectFromGUID(scriptZoneToPadList[leftZoneGUID])
- if pad ~= nil then
- pad.setColorTint({0.1,0.1,0.1})
- end
- end
- end
- end
- --Action taking utility
- --Re-orders getSeatedPlayers default order to match table
- function orderTurnList(list)
- local orderedList = {}
- for _, orderColor in ipairs(playerOrderGuideList) do
- for _, listColor in ipairs(list) do
- if orderColor == listColor then
- table.insert(orderedList, orderColor)
- end
- end
- end
- return orderedList
- end
- --Gives a tile to a pad. i is index of the scriptzone in colorToScriptZoneList
- function sendSpellstoneToPad(padGUID, i)
- local pad = getObjectFromGUID(padGUID)
- local padPos = rotateLocalCoordinates({(-i+3)*2.25,2,0}, pad)
- local padRot = pad.getRotation()
- padRot = {padRot.x+90, padRot.y+180, padRot.z+180}
- spellstoneBag.takeObject({
- position=padPos, rotation=padRot,
- callback="callback_turnSpellstoneFaceUp", callback_owner=Global
- })
- end
- --Callback tied to sendSpellstoneToPad,
- function callback_turnSpellstoneFaceUp(spellstone)
- local rot = spellstone.getRotation()
- rot = {rot.x-90, rot.y+180, rot.z}
- spellstone.setRotationSmooth(rot, false, true)
- end
- --Coroutine delay, in seconds
- function wait(time)
- local start = os.time()
- repeat coroutine.yield(0) until os.time() > start + time
- end
- --Destroys an object on callback
- function callback_delete(obj)
- destroyObject(obj)
- end
- --Information finding utility
- function isZoneHoldingASpellstone(zone)
- for _, obj in ipairs(zone.getObjects()) do
- if obj.getName() == "Spellstone" then
- return true
- end
- end
- return false
- end
- --Used to rotate a set of coordinates by an angle
- function rotateLocalCoordinates(desiredPos, obj)
- local objPos, objRot = obj.getPosition(), obj.getRotation()
- local angle = -math.rad(objRot.y)
- local x = desiredPos[1] * math.cos(angle) - desiredPos[3] * math.sin(angle)
- local z = desiredPos[1] * math.sin(angle) + desiredPos[3] * math.cos(angle)
- return {objPos.x+x, objPos.y+desiredPos[2], objPos.z+z}
- end
- --Used to set positions around a centerl point
- function findGlobalPosWithLocalDirection(oPos, oRot, distance, angle)
- local posX = oPos.x + math.sin( math.rad(angle+oRot.y) ) * distance
- local posY = oPos.y
- local posZ = oPos.z + math.cos( math.rad(angle+oRot.y) ) * distance
- return {x=posX, y=posY, z=posZ}
- end
- --Converts a local position to a global position
- --RelativePos is local coords, oPos is current object pos, oRot current obj rot
- function findLocalPos(relativePos, oPos, oRot)
- local rotationAmount = math.rad(oRot.y*-1)
- local posX = oPos.x + relativePos[1] * math.cos(rotationAmount) - relativePos[3] * math.sin(rotationAmount)
- local posY = oPos.y + relativePos[2]
- local posZ = oPos.z + relativePos[1] * math.sin(rotationAmount) + relativePos[3] * math.cos(rotationAmount)
- return {x=posX, y=posY, z=posZ}
- end
- --Finds the first instance of a life token in a zone from zone GUID
- function findALifeToken(zoneGUID)
- for _, obj in ipairs(getObjectFromGUID(zoneGUID).getObjects()) do
- if obj.getName() == "Life Tokens" then
- return obj, obj.getQuantity()
- end
- end
- return nil
- end
- --Just counts life tikens
- function countAllLifeTokens(zoneGUID)
- local tokenCount = 0
- for _, obj in ipairs(getObjectFromGUID(zoneGUID).getObjects()) do
- if obj.getName() == "Life Tokens" then
- if obj.getQuantity() == -1 then
- tokenCount = tokenCount + 1
- else
- tokenCount = tokenCount + obj.getQuantity()
- end
- end
- end
- return tokenCount
- end
- --Button creation
- function spawnScrollButtons()
- local scroll_newRound = getObjectFromGUID("a6a4c0")
- local scroll_deal = getObjectFromGUID("1770c0")
- local scroll_blindfold = getObjectFromGUID("e7bc49")
- scroll_newRound.createButton({
- click_function="buttonClick_newRound", function_owner=Global,
- position={0,-0.6,1.75}, height=800, width=2500, color={1,1,1,0}
- })
- scroll_deal.createButton({
- click_function="buttonClick_deal", function_owner=Global,
- position={0,-0.6,1.75}, height=800, width=2500, color={1,1,1,0}
- })
- scroll_blindfold.createButton({
- click_function="buttonClick_blindfold", function_owner=Global,
- position={0,-0.6,1.75}, height=800, width=2500, color={1,1,1,0}
- })
- end
- function spawnLifeButtons()
- for guid in pairs(lifeTokenReferenceList) do
- local params = {height=180, width=180, function_owner=Global, color={1,1,1,0}}
- params.click_function, params.position = "buttonClick_less", {-0.27,0.2,0.03}
- getObjectFromGUID(guid).createButton(params)
- params.click_function, params.position = "buttonClick_more", {0.27,0.2,0.03}
- getObjectFromGUID(guid).createButton(params)
- end
- end
- --Data tables
- --Dealing order, as laid out on table
- playerOrderGuideList = {"Green", "Blue", "White", "Pink", "Purple"}
- --Ties a color name to their 5 tile script zones, left to right
- colorToScriptZoneList = {
- ["Green"] = {"5f6baf", "94af37", "1c7474", "fc7045", "e2face"},
- ["Blue"] = {"feb32a", "99cb1c", "f96d51", "603106", "f69374"},
- ["White"] = {"e2d636", "a5eac4", "27319c", "f856b1", "02a81d"},
- ["Pink"] = {"2408ba", "d514ab", "22d306", "301f22", "76be60"},
- ["Purple"] = {"cea4c9", "155f96", "0aba98", "486c81", "3858e6"},
- }
- --Guids to tie script zones to their spell stone pad
- --Does the set of 5 first, then the 4. Left to right, top to bottom
- scriptZoneToPadList = {
- --Green
- ["5f6baf"]="281449", ["94af37"]="c7285a", ["1c7474"]="61a321",
- ["fc7045"]="378343", ["e2face"]="c2114c", ["ca3f49"]="a47001",
- ["726f90"]="371c20", ["9b01b6"]="2b1610", ["5dda92"]="ee931d",
- --Blue
- ["feb32a"]="d3a59f", ["99cb1c"]="ce9f20", ["f96d51"]="5c2598",
- ["603106"]="57e8d7", ["f69374"]="242504", ["abb37b"]="6693d3",
- ["5ea7ad"]="43f3ff", ["0bfa2c"]="10cde4", ["9474ce"]="eb4db6",
- --White
- ["e2d636"]="86f187", ["a5eac4"]="4f5c81", ["27319c"]="2910cf",
- ["f856b1"]="597ccd", ["02a81d"]="b1a44b", ["0dcada"]="fcee6c",
- ["0ec88d"]="139597", ["57f7d7"]="e5a089", ["de9ad9"]="a83951",
- --Pink
- ["2408ba"]="b616b8", ["d514ab"]="82cab0", ["22d306"]="8661db",
- ["301f22"]="ff0cee", ["76be60"]="1ac0b7", ["e5c2b4"]="22300e",
- ["b3a75a"]="df5785", ["c42239"]="b7eb72", ["a95cd2"]="9932fa",
- --Purple
- ["cea4c9"]="2ab839", ["155f96"]="128aef", ["0aba98"]="eedae0",
- ["486c81"]="9e4770", ["3858e6"]="c4fe6f", ["864c30"]="d3cbe4",
- ["87b349"]="db0151", ["0987bf"]="00e9a9", ["94b4b3"]="cbfb46",
- }
- --Connects each health pad guid to a color, script zone and infinite bag
- lifeTokenReferenceList = {
- ["bf3212"] = {color="Green", zone="0738e4", bag="9e3d2f"},
- ["018c13"] = {color="Blue", zone="e5e4cd", bag="09c07b"},
- ["3c4efa"] = {color="White", zone="b6f261", bag="b69327"},
- ["281155"] = {color="Pink", zone="9ebf3a", bag="d182c6"},
- ["800a9c"] = {color="Purple", zone="5b28a2", bag="c6c51a"},
- }
- --Objects that have their interactable status disabled, except pads
- interactableDisableList = {
- "c5eee8","dff734","0727e2","182984","7e98cb","488c78","61bd57","008144",
- "eb99b6","a2f765","80f098","41a8fc","bb0458", "b52e0c", "bf3212", "018c13", "3c4efa", "281155", "800a9c"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement