Advertisement
Guilemouse

TTS: Abraca What?! Blindfold Buff

Dec 3rd, 2020 (edited)
510
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 19.06 KB | None | 0 0
  1. function onload()
  2.     --Disables interactable status of objects with GUID in list
  3.     for _, guid in ipairs(interactableDisableList) do
  4.         local obj = getObjectFromGUID(guid)
  5.         if obj then obj.interactable = false end
  6.     end
  7.  
  8.     --Identify core objects
  9.     spellstoneBag = getObjectFromGUID("f2cfdb")
  10.     gameBoard = getObjectFromGUID("dc281c")
  11.  
  12.     --Bits to trigger button creation
  13.     spawnScrollButtons()
  14.     spawnLifeButtons()
  15. end
  16.  
  17.  
  18. --New Round
  19.  
  20.  
  21. --Find players and order them, trigger coroutine
  22. function buttonClick_newRound(_, clickerColor)
  23.     --Get and organize which players are seated
  24.     local seatedPlayers = getSeatedPlayers()
  25.     --seatedPlayers = playerOrderGuideList --DEBUG LINE------------------------
  26.     --seatedPlayers = {"White", "Green"} --DEBUG LINE--------------------------
  27.     --Activates coroutine to take clear/deal/display actions
  28.     if #seatedPlayers > 1 then
  29.         coroutine_blindfold_all(clickerColor)
  30.         if lockout_scriptIsDealing ~= true then
  31.             lockout_scriptIsDealing = true
  32.             coroutine_newRound(orderTurnList(seatedPlayers))
  33.         else
  34.             broadcastToColor("The script is currently moving tiles. Please wait.", clickerColor, {1,0.1,0.1})
  35.         end
  36.     else
  37.         broadcastToAll("2-5 players needed.", {1,0.1,0.1})
  38.     end
  39. end
  40.  
  41. --Handles dealing to all players, placing 4 hidden tiles, revealed tokens
  42. function coroutine_newRound(seatedPlayers)
  43.     function embeddedCoroutine()
  44.         --Return all tokens to bag
  45.         local spellstonesReturning = false
  46.         for _, obj in ipairs(getAllObjects()) do
  47.             if obj.getName() == "Spellstone" then
  48.                 spellstoneBag.putObject(obj)
  49.                 spellstonesReturning = true
  50.                 wait(0.05)
  51.             end
  52.         end
  53.         if spellstonesReturning == true then
  54.             wait(1)
  55.         end
  56.         --Shuffle bag
  57.         spellstoneBag.shuffle()
  58.         --Deal 5 tokens to each seated player
  59.         for _, color in ipairs(seatedPlayers) do
  60.             for i, zoneGUID in ipairs(colorToScriptZoneList[color]) do
  61.                 sendSpellstoneToPad(scriptZoneToPadList[zoneGUID], i)
  62.                 wait(0.2)
  63.             end
  64.         end
  65.         --Place 4 face-down tokens
  66.         for i=0, 3 do
  67.             local pos = {-5.48+2.5*i, 1, 10.9}
  68.             spellstoneBag.takeObject({position=pos, rotation={90,0,0}})
  69.             wait(0.2)
  70.         end
  71.         --If 2/3 player game then put 12/6 tokens out on the board
  72.         if #seatedPlayers <= 3 then
  73.             revealedSpellstoneList = {}
  74.             local pos = gameBoard.getPosition()
  75.             local rot = gameBoard.getRotation()
  76.             local numberOfStonesToPull = 12
  77.             if #seatedPlayers == 3 then
  78.                 numberOfStonesToPull = 6
  79.             end
  80.             for i=1, numberOfStonesToPull do
  81.                 local placementPos = findGlobalPosWithLocalDirection(pos, rot, 8, 360/numberOfStonesToPull * i)
  82.                 placementPos.y = placementPos.y + 8
  83.                 spellstoneBag.takeObject({
  84.                     position=placementPos, rotation={0,180,0},
  85.                     callback="callback_newRound", callback_owner=Global
  86.                 })
  87.                 wait(0.05)
  88.             end
  89.         end
  90.         --Refreshes life to 6 points
  91.         for buttonPadGUID, entry in pairs(lifeTokenReferenceList) do
  92.             local tokenCount = countAllLifeTokens(entry.zone)
  93.             if tokenCount < 6 then
  94.                 for i=1, 6-tokenCount do
  95.                     buttonClick_more(getObjectFromGUID(buttonPadGUID))
  96.                 end
  97.             end
  98.         end
  99.  
  100.         lockout_scriptIsDealing = false
  101.         return 1
  102.     end
  103.     startLuaCoroutine(Global, "embeddedCoroutine")
  104. end
  105.  
  106. function callback_newRound(spellstone)
  107.     --Get spellstone value
  108.     local spellstoneValue = spellstone.getVar("spellstoneValue")
  109.     --Track how many of this spellstone have been revealed/placed
  110.     if revealedSpellstoneList[tostring(spellstoneValue)] ~= nil then
  111.         revealedSpellstoneList[tostring(spellstoneValue)] = revealedSpellstoneList[tostring(spellstoneValue)] + 1
  112.     else
  113.         revealedSpellstoneList[tostring(spellstoneValue)] = 1
  114.     end
  115.     --Relative position where the #1 token goes
  116.     local startingPos = {-2.964, 0.18, -7.289}
  117.     --Adjusting startPos for this tile based on its spellstoneValue and how many
  118.     startingPos[1] = startingPos[1] + 1.15 * (revealedSpellstoneList[tostring(spellstoneValue)] - 1)
  119.     startingPos[2] = startingPos[2] + 0
  120.     startingPos[3] = startingPos[3] + 2.062 * (spellstoneValue - 1)
  121.     --Convert pos to global coordinate system
  122.     local rot = gameBoard.getRotation()
  123.     rot.y = rot.y+180
  124.     offsetPos = findLocalPos(startingPos, gameBoard.getPosition(), rot)
  125.     spellstone.setPositionSmooth(offsetPos)
  126.     rot.y = rot.y+90
  127.     spellstone.setRotationSmooth(rot)
  128. end
  129.  
  130.  
  131. --Deal
  132.  
  133.  
  134. --Triggers dealing
  135. function buttonClick_deal(_, clickerColor)
  136.     if clickerColor ~= "Black" then
  137.         if lockout_scriptIsDealing ~= true then
  138.             lockout_scriptIsDealing = true
  139.             coroutine_deal(clickerColor)
  140.         else
  141.             broadcastToColor("The script is currently moving tiles. Please wait.", clickerColor, {1,0.1,0.1})
  142.         end
  143.     else
  144.         broadcastToColor("You cannot have spellstones dealt to you in the GM (Black) seat.", clickerColor, {1,0.1,0.1})
  145.     end
  146. end
  147.  
  148. --Deals tile to 1 of 5 spots if a spot is missing a spellstone
  149. function coroutine_deal(clickerColor)
  150.     function embeddedCoroutine()
  151.         coroutine_blindfold_clicker(clickerColor)
  152.         for i, zoneGUID in ipairs(colorToScriptZoneList[clickerColor]) do
  153.             if #spellstoneBag.getObjects() > 0 then
  154.                 if isZoneHoldingASpellstone(getObjectFromGUID(zoneGUID)) == false then
  155.                     sendSpellstoneToPad(scriptZoneToPadList[zoneGUID], i)
  156.                     wait(0.2)
  157.                 end
  158.             else
  159.                 broadcastToAll("Spellstone Bag is [u]empty[/u]!", {1,1,1})
  160.                 lockout_scriptIsDealing = nil
  161.                 return 1
  162.             end
  163.         end
  164.         lockout_scriptIsDealing = nil
  165.         return 1
  166.     end
  167.     startLuaCoroutine(Global, "embeddedCoroutine")
  168. end
  169.  
  170.  
  171. --Blindfold
  172.  
  173.  
  174. --Triggers blindfolding
  175. function buttonClick_blindfold(_, clickerColor)
  176.     if #getSeatedPlayers() > 1 then
  177.         coroutine_blindfold(clickerColor)
  178.     else
  179.         broadcastToAll("There are no players to blindfold.", {1,0.1,0.1})
  180.     end
  181. end
  182.  
  183. --Blindfolds all players, counts down 5 seconds, then removes blindfolds
  184. function coroutine_blindfold_all(clickerColor)
  185.     function embeddedCoroutine()
  186.         local seatedPlayers = getSeatedPlayers()
  187.         --Initial blindfolding
  188.         for _, color in ipairs(orderTurnList(seatedPlayers)) do
  189.             if Player[color].blindfolded == false then
  190.                 Player[color].blindfolded = true
  191.             end
  192.         end
  193.         --Countdown
  194.         broadcastToAll("Blindfold will be removed after setup...", {1,1,1})
  195.         wait(5)
  196.         --Removal
  197.         for _, color in ipairs(orderTurnList(seatedPlayers)) do
  198.             if Player[color].blindfolded == true then
  199.                 Player[color].blindfolded = false
  200.             end
  201.         end
  202.         return 1
  203.     end
  204.     startLuaCoroutine(Global, "embeddedCoroutine")
  205. end
  206.  
  207. --Blindfolds Clicker, counts down 2 seconds, then removes blindfolds
  208. function coroutine_blindfold_clicker(clickerColor)
  209.     function embeddedCoroutine()
  210.         local seatedPlayers = getSeatedPlayers()
  211.         --Initial blindfolding
  212.         for _, color in ipairs(orderTurnList(seatedPlayers)) do
  213.             if color == clickerColor then
  214.                 if Player[color].blindfolded == false then
  215.                     Player[color].blindfolded = true
  216.                 end
  217.             end
  218.         end
  219.         --Countdown
  220.         broadcastToAll("Blindfold will be removed in 2...", {1,1,1})
  221.         wait(1)
  222.         broadcastToAll("Blindfold will be removed in 1...", {1,1,1})
  223.         wait(1)
  224.         --Removal
  225.         for _, color in ipairs(orderTurnList(seatedPlayers)) do
  226.             if Player[color].blindfolded == true then
  227.                 Player[color].blindfolded = false
  228.             end
  229.         end
  230.         return 1
  231.     end
  232.     startLuaCoroutine(Global, "embeddedCoroutine")
  233. end
  234.  
  235. --Blindfolds everyone except clicker, counts down 3 seconds, then removes blindfolds
  236. function coroutine_blindfold(clickerColor)
  237.     function embeddedCoroutine()
  238.         local seatedPlayers = getSeatedPlayers()
  239.         --Initial blindfolding
  240.         for _, color in ipairs(orderTurnList(seatedPlayers)) do
  241.             if color ~= clickerColor then
  242.                 if Player[color].blindfolded == false then
  243.                     Player[color].blindfolded = true
  244.                 end
  245.             end
  246.         end
  247.         --Countdown
  248.         broadcastToAll("Blindfold will be removed in 3...", {1,1,1})
  249.         wait(1)
  250.         broadcastToAll("Blindfold will be removed in 2...", {1,1,1})
  251.         wait(1)
  252.         broadcastToAll("Blindfold will be removed in 1...", {1,1,1})
  253.         wait(1)
  254.         --Removal
  255.         for _, color in ipairs(orderTurnList(seatedPlayers)) do
  256.             if Player[color].blindfolded == true then
  257.                 Player[color].blindfolded = false
  258.             end
  259.         end
  260.         return 1
  261.     end
  262.     startLuaCoroutine(Global, "embeddedCoroutine")
  263. end
  264.  
  265.  
  266. --Health counters
  267.  
  268.  
  269. --Lowers Health
  270. function buttonClick_less(buttonPad)
  271.     buttonPad.AssetBundle.playTriggerEffect(0)
  272.     local buttonPadGUID = buttonPad.getGUID()
  273.     local zoneGUID = lifeTokenReferenceList[buttonPadGUID].zone
  274.     local lifeToken, quantity = findALifeToken(zoneGUID)
  275.     if quantity == -1 then
  276.         destroyObject(lifeToken)
  277.     elseif quantity ~= nil then
  278.         local pos = lifeToken.getPosition()
  279.         pos.y = pos.y-2
  280.         lifeToken.takeObject({
  281.             position=pos, callback="callback_delete", callback_owner=Global
  282.         })
  283.     end
  284. end
  285.  
  286. --Raises health
  287. function buttonClick_more(buttonPad)
  288.     buttonPad.AssetBundle.playTriggerEffect(1)
  289.     local buttonPadGUID = buttonPad.getGUID()
  290.     local zoneGUID = lifeTokenReferenceList[buttonPadGUID].zone
  291.     local lifeToken, quantity = findALifeToken(zoneGUID)
  292.     quantity = countAllLifeTokens(zoneGUID)
  293.     if lifeToken == nil then
  294.         local tokenBag = getObjectFromGUID(lifeTokenReferenceList[buttonPadGUID].bag)
  295.         local bagPos = tokenBag.getPosition()
  296.         bagPos.y = 0.86
  297.         local bagRot = tokenBag.getRotation()
  298.         tokenBag.takeObject({position=bagPos, rotation=bagRot})
  299.     elseif quantity < 6 then
  300.         local pos = lifeToken.getPosition()
  301.         local rot = lifeToken.getRotation()
  302.         getObjectFromGUID(lifeTokenReferenceList[buttonPadGUID].bag).takeObject({
  303.             position=pos, rotation=rot
  304.         })
  305.     end
  306. end
  307.  
  308.  
  309. --Pad highlighting
  310.  
  311.  
  312. --Turns the pad white if a spellstone enters its script zone
  313. function onObjectEnterScriptingZone(enteredZone, enteringObj)
  314.     if enteringObj.getName() == "Spellstone" then
  315.         local enteredZoneGUID = enteredZone.getGUID()
  316.         local pad = getObjectFromGUID(scriptZoneToPadList[enteredZoneGUID])
  317.         if pad ~= nil then
  318.             pad.setColorTint({1,1,1})
  319.         end
  320.     end
  321. end
  322.  
  323. --Turns the pad (almost) black if a spellstone leaves (and there isn't one now)
  324. function onObjectLeaveScriptingZone(leftZone, leavingObj)
  325.     if leavingObj.getName() == "Spellstone" then
  326.         if isZoneHoldingASpellstone(leftZone) == false then
  327.             local leftZoneGUID = leftZone.getGUID()
  328.             local pad = getObjectFromGUID(scriptZoneToPadList[leftZoneGUID])
  329.             if pad ~= nil then
  330.                 pad.setColorTint({0.1,0.1,0.1})
  331.             end
  332.         end
  333.     end
  334. end
  335.  
  336.  
  337. --Action taking utility
  338.  
  339.  
  340. --Re-orders getSeatedPlayers default order to match table
  341. function orderTurnList(list)
  342.     local orderedList = {}
  343.     for _, orderColor in ipairs(playerOrderGuideList) do
  344.         for _, listColor in ipairs(list) do
  345.             if orderColor == listColor then
  346.                 table.insert(orderedList, orderColor)
  347.             end
  348.         end
  349.     end
  350.     return orderedList
  351. end
  352.  
  353. --Gives a tile to a pad. i is index of the scriptzone in colorToScriptZoneList
  354. function sendSpellstoneToPad(padGUID, i)
  355.     local pad = getObjectFromGUID(padGUID)
  356.     local padPos = rotateLocalCoordinates({(-i+3)*2.25,2,0}, pad)
  357.     local padRot = pad.getRotation()
  358.     padRot = {padRot.x+90, padRot.y+180, padRot.z+180}
  359.     spellstoneBag.takeObject({
  360.         position=padPos, rotation=padRot,
  361.         callback="callback_turnSpellstoneFaceUp", callback_owner=Global
  362.     })
  363. end
  364.  
  365. --Callback tied to sendSpellstoneToPad,
  366. function callback_turnSpellstoneFaceUp(spellstone)
  367.     local rot = spellstone.getRotation()
  368.     rot = {rot.x-90, rot.y+180, rot.z}
  369.     spellstone.setRotationSmooth(rot, false, true)
  370. end
  371.  
  372. --Coroutine delay, in seconds
  373. function wait(time)
  374.     local start = os.time()
  375.     repeat coroutine.yield(0) until os.time() > start + time
  376. end
  377.  
  378. --Destroys an object on callback
  379. function callback_delete(obj)
  380.     destroyObject(obj)
  381. end
  382.  
  383.  
  384. --Information finding utility
  385.  
  386.  
  387. function isZoneHoldingASpellstone(zone)
  388.     for _, obj in ipairs(zone.getObjects()) do
  389.         if obj.getName() == "Spellstone" then
  390.             return true
  391.         end
  392.     end
  393.     return false
  394. end
  395.  
  396. --Used to rotate a set of coordinates by an angle
  397. function rotateLocalCoordinates(desiredPos, obj)
  398.     local objPos, objRot = obj.getPosition(), obj.getRotation()
  399.     local angle = -math.rad(objRot.y)
  400.     local x = desiredPos[1] * math.cos(angle) - desiredPos[3] * math.sin(angle)
  401.     local z = desiredPos[1] * math.sin(angle) + desiredPos[3] * math.cos(angle)
  402.     return {objPos.x+x, objPos.y+desiredPos[2], objPos.z+z}
  403. end
  404.  
  405. --Used to set positions around a centerl point
  406. function findGlobalPosWithLocalDirection(oPos, oRot, distance, angle)
  407.     local posX = oPos.x + math.sin( math.rad(angle+oRot.y) ) * distance
  408.     local posY = oPos.y
  409.     local posZ = oPos.z + math.cos( math.rad(angle+oRot.y) ) * distance
  410.     return {x=posX, y=posY, z=posZ}
  411. end
  412.  
  413. --Converts a local position to a global position
  414. --RelativePos is local coords, oPos is current object pos, oRot current obj rot
  415. function findLocalPos(relativePos, oPos, oRot)
  416.     local rotationAmount = math.rad(oRot.y*-1)
  417.     local posX = oPos.x + relativePos[1] * math.cos(rotationAmount) - relativePos[3] * math.sin(rotationAmount)
  418.     local posY = oPos.y + relativePos[2]
  419.     local posZ = oPos.z + relativePos[1] * math.sin(rotationAmount) + relativePos[3] * math.cos(rotationAmount)
  420.     return {x=posX, y=posY, z=posZ}
  421. end
  422.  
  423. --Finds the first instance of a life token in a zone from zone GUID
  424. function findALifeToken(zoneGUID)
  425.     for _, obj in ipairs(getObjectFromGUID(zoneGUID).getObjects()) do
  426.         if obj.getName() == "Life Tokens" then
  427.             return obj, obj.getQuantity()
  428.         end
  429.     end
  430.     return nil
  431. end
  432.  
  433. --Just counts life tikens
  434. function countAllLifeTokens(zoneGUID)
  435.     local tokenCount = 0
  436.     for _, obj in ipairs(getObjectFromGUID(zoneGUID).getObjects()) do
  437.         if obj.getName() == "Life Tokens" then
  438.             if obj.getQuantity() == -1 then
  439.                 tokenCount = tokenCount + 1
  440.             else
  441.                 tokenCount = tokenCount + obj.getQuantity()
  442.             end
  443.         end
  444.     end
  445.     return tokenCount
  446. end
  447.  
  448. --Button creation
  449.  
  450.  
  451. function spawnScrollButtons()
  452.     local scroll_newRound = getObjectFromGUID("a6a4c0")
  453.     local scroll_deal = getObjectFromGUID("1770c0")
  454.     local scroll_blindfold = getObjectFromGUID("e7bc49")
  455.     scroll_newRound.createButton({
  456.         click_function="buttonClick_newRound", function_owner=Global,
  457.         position={0,-0.6,1.75}, height=800, width=2500, color={1,1,1,0}
  458.     })
  459.     scroll_deal.createButton({
  460.         click_function="buttonClick_deal", function_owner=Global,
  461.         position={0,-0.6,1.75}, height=800, width=2500, color={1,1,1,0}
  462.     })
  463.     scroll_blindfold.createButton({
  464.         click_function="buttonClick_blindfold", function_owner=Global,
  465.         position={0,-0.6,1.75}, height=800, width=2500, color={1,1,1,0}
  466.     })
  467. end
  468.  
  469. function spawnLifeButtons()
  470.     for guid in pairs(lifeTokenReferenceList) do
  471.         local params = {height=180, width=180, function_owner=Global, color={1,1,1,0}}
  472.         params.click_function, params.position = "buttonClick_less", {-0.27,0.2,0.03}
  473.         getObjectFromGUID(guid).createButton(params)
  474.         params.click_function, params.position = "buttonClick_more", {0.27,0.2,0.03}
  475.         getObjectFromGUID(guid).createButton(params)
  476.     end
  477. end
  478.  
  479.  
  480. --Data tables
  481.  
  482.  
  483. --Dealing order, as laid out on table
  484. playerOrderGuideList = {"Green", "Blue", "White", "Pink", "Purple"}
  485.  
  486. --Ties a color name to their 5 tile script zones, left to right
  487. colorToScriptZoneList = {
  488.     ["Green"] = {"5f6baf", "94af37", "1c7474", "fc7045", "e2face"},
  489.     ["Blue"] = {"feb32a", "99cb1c", "f96d51", "603106", "f69374"},
  490.     ["White"] = {"e2d636", "a5eac4", "27319c", "f856b1", "02a81d"},
  491.     ["Pink"] = {"2408ba", "d514ab", "22d306", "301f22", "76be60"},
  492.     ["Purple"] = {"cea4c9", "155f96", "0aba98", "486c81", "3858e6"},
  493. }
  494.  
  495. --Guids to tie script zones to their spell stone pad
  496. --Does the set of 5 first, then the 4. Left to right, top to bottom
  497. scriptZoneToPadList = {
  498.     --Green
  499.     ["5f6baf"]="281449", ["94af37"]="c7285a", ["1c7474"]="61a321",
  500.     ["fc7045"]="378343", ["e2face"]="c2114c", ["ca3f49"]="a47001",
  501.     ["726f90"]="371c20", ["9b01b6"]="2b1610", ["5dda92"]="ee931d",
  502.     --Blue
  503.     ["feb32a"]="d3a59f", ["99cb1c"]="ce9f20", ["f96d51"]="5c2598",
  504.     ["603106"]="57e8d7", ["f69374"]="242504", ["abb37b"]="6693d3",
  505.     ["5ea7ad"]="43f3ff", ["0bfa2c"]="10cde4", ["9474ce"]="eb4db6",
  506.     --White
  507.     ["e2d636"]="86f187", ["a5eac4"]="4f5c81", ["27319c"]="2910cf",
  508.     ["f856b1"]="597ccd", ["02a81d"]="b1a44b", ["0dcada"]="fcee6c",
  509.     ["0ec88d"]="139597", ["57f7d7"]="e5a089", ["de9ad9"]="a83951",
  510.     --Pink
  511.     ["2408ba"]="b616b8", ["d514ab"]="82cab0", ["22d306"]="8661db",
  512.     ["301f22"]="ff0cee", ["76be60"]="1ac0b7", ["e5c2b4"]="22300e",
  513.     ["b3a75a"]="df5785", ["c42239"]="b7eb72", ["a95cd2"]="9932fa",
  514.     --Purple
  515.     ["cea4c9"]="2ab839", ["155f96"]="128aef", ["0aba98"]="eedae0",
  516.     ["486c81"]="9e4770", ["3858e6"]="c4fe6f", ["864c30"]="d3cbe4",
  517.     ["87b349"]="db0151", ["0987bf"]="00e9a9", ["94b4b3"]="cbfb46",
  518. }
  519.  
  520. --Connects each health pad guid to a color, script zone and infinite bag
  521. lifeTokenReferenceList = {
  522.     ["bf3212"] = {color="Green", zone="0738e4", bag="9e3d2f"},
  523.     ["018c13"] = {color="Blue", zone="e5e4cd", bag="09c07b"},
  524.     ["3c4efa"] = {color="White", zone="b6f261", bag="b69327"},
  525.     ["281155"] = {color="Pink", zone="9ebf3a", bag="d182c6"},
  526.     ["800a9c"] = {color="Purple", zone="5b28a2", bag="c6c51a"},
  527. }
  528.  
  529. --Objects that have their interactable status disabled, except pads
  530. interactableDisableList = {
  531.     "c5eee8","dff734","0727e2","182984","7e98cb","488c78","61bd57","008144",
  532.     "eb99b6","a2f765","80f098","41a8fc","bb0458", "b52e0c", "bf3212", "018c13", "3c4efa", "281155", "800a9c"
  533. }
  534.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement