Advertisement
Kijan

Attack

Mar 17th, 2019
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 15.97 KB | None | 0 0
  1. -- Sets the default spd and acc to these values
  2. attackValues = {speed = 0, accuracy = 0}
  3. monsterStats = {
  4.    {name = "White Lion", speed = 2, accuracy = 2},
  5.    {name = "Screaming Antelope", speed = 1, accuracy = 2},
  6.    {name = "Butcher", speed = 2, accuracy = 4},
  7.    {name = "King's Man", speed = 3, accuracy = 3},
  8.    {name = "Phoenix", speed = 2, accuracy = 2},
  9.    {name = "The Hand", speed = 2, accuracy = 2},
  10.    {name = "The Watcher", speed = 4, accuracy = 2},
  11.    {name = "Dragon King", speed = 2, accuracy = 2},
  12.    {name = "Dung Beetle Knight", speed = 3, accuracy = 3},
  13.    {name = "Flower Knight", speed = 3, accuracy = 2},
  14.    {name = "Gorm", speed = 2, accuracy = 2},
  15.    {name = "Lion God", speed = 2, accuracy = 3},
  16.    {name = "Lion Knight", speed = 4, accuracy = 2},
  17.    {name = "Lonely Tree", speed = 3, accuracy = 3},
  18.    {name = "Manhunter", speed = 1, accuracy = 4},
  19.    {name = "Slenderman", speed = 3, accuracy = 4},
  20.    {name = "Spidicules", speed = 2, accuracy = 2},
  21.    {name = "Sunstalker", speed = 3, accuracy = 4},
  22.    {name = "The Tyrant", speed = 2, accuracy = 3}
  23. }
  24.  
  25. playerTable = {
  26.    P1 = {
  27.       playerName = "Player One", sigil = "", fontColor = nil, name = "", grid = Global.getTable("grids").red.guid,
  28.       pos_toSpawn = { - 5.85, 4.34, - 7.22}, surv_pos_toMove = { - 5.85, 5, - 7.22}
  29.    },
  30.    P2 = {
  31.       playerName = "Player Two", sigil = "", fontColor = nil, name = "", grid = Global.getTable("grids").yellow.guid,
  32.       pos_toSpawn = { - 2.82, 4.34, - 7.22}, surv_pos_toMove = { - 2.82, 5, - 7.22}
  33.    },
  34.    P3 = {
  35.       playerName = "Player Three", sigil = "", fontColor = nil, name = "", grid = Global.getTable("grids").green.guid,
  36.       pos_toSpawn = {2.34, 4.34, - 7.21}, surv_pos_toMove = {2.34, 5, - 7.21}
  37.    },
  38.    P4 = {
  39.       playerName = "Player Four", sigil = "", fontColor = nil, name = "", grid = Global.getTable("grids").blue.guid,
  40.       pos_toSpawn = {5.55, 4.34, - 7.22}, surv_pos_toMove = {5.55, 5, - 7.22}
  41.    }
  42. }
  43.  
  44. function onLoad()
  45.    initCustomButtons()
  46.    spawnedDice = {}
  47.    zoneShowdown = getObjectFromGUID(Global.getTable('zonesDestruct').zoneShowdown.guid)
  48.    zoneInjuryBoard = getObjectFromGUID(Global.getTable('zones').zoneInjuryBoard.guid)
  49. end
  50.  
  51. -- Buttons ---------------------------------------------------------------------
  52. function initCustomButtons()
  53.    setupButton("Attack", 0, - 0.6)
  54.    setupButton("Priority", - 7.5, - 0.6)
  55.    setupButton("Move Monster", - 8, 11.2, "moveMonster")
  56.    setupButton("Bird's Eye View", 0, - 10, "birds_eye_view")
  57.    setupButton("Remove Priority", 7.5, - 0.6, "remove_priorityTargetToken")
  58. end
  59.  
  60. function createButtons_damage_display()
  61.    local btn_params = {}
  62.    btn_params.width = 0
  63.    btn_params.height = 0
  64.    btn_params.font_size = 600
  65.    btn_params.font_color = {0.5, 0.5, 0.5}
  66.    btn_params.click_function = "removeOnClear"
  67.  
  68.    btn_params.label = "Damage"
  69.    btn_params.position = {88.5, 7.3, 54.1}
  70.    self.createButton(btn_params)
  71.  
  72.    btn_params.label = "Damage"
  73.    btn_params.position = { - 88.8, 7.3, 54.1}
  74.    self.createButton(btn_params)
  75.  
  76.    bonus_damage = tostring(getObjectFromGUID(Global.getTable("boards").modTable.guid).call("getStats", {"damage"}))
  77.    btn_params.font_size = 800
  78.    btn_params.label = "+ " .. bonus_damage
  79.    btn_params.position = { - 88.9, 7.8, 52.9}
  80.    self.createButton(btn_params)
  81.  
  82.    btn_params.label = "+ " .. bonus_damage
  83.    btn_params.position = {88.3, 7.8, 52.9}
  84.    self.createButton(btn_params)
  85. end
  86.  
  87. function setupButton(name, x, z, click_function)
  88.    local button_parameters = {}
  89.    button_parameters.height = 700
  90.    button_parameters.width = 3500
  91.    button_parameters.font_size = 700
  92.    button_parameters.label = name
  93.    button_parameters.color = {1, 1, 1, 0}
  94.    button_parameters.rotation = { - 15, 0, 0}
  95.    button_parameters.position = {x, 0.85, z}
  96.    button_parameters.function_owner = self
  97.  
  98.    if click_function then
  99.       button_parameters.click_function = click_function
  100.    else
  101.       self.setVar(name, function() showMenu(name) end)
  102.       button_parameters.click_function = name
  103.    end
  104.  
  105.    self.createButton(button_parameters)
  106. end
  107.  
  108. -- Priority Target Token -------------------------------------------------------
  109. function remove_priorityTargetToken()
  110.    for _, object in ipairs(zoneShowdown.getObjects()) do
  111.       if object.getName() == "Priority Target" then
  112.          if string.find(object.getDescription(), "permanent") then
  113.             broadcastToAll("A Survivor has the Priority Target Permanently ~ From a Game Effect", {1, 1, 1})
  114.             broadcastToAll("\\u{2612}  Cannot Be Removed  \\u{2612} ", {1, 1, 1})
  115.          else
  116.             object.destroy()
  117.          end
  118.       end
  119.    end
  120. end
  121.  
  122. function removeButton_removePriority()
  123.    broadcastToAll("This function was deprecated, remove the calling function", {1, 1, 1})
  124. end
  125.  
  126. function removeButton_gainPriority()
  127.    broadcastToAll("This function was deprecated, remove the calling function", {1, 1, 1})
  128. end
  129.  
  130. -- Dice Roller Functions -------------------------------------------------------
  131. function spawnDice(id)
  132.    local number = attackValues.speed
  133.    local step = 0.7
  134.    if tonumber(attackValues.speed) < 1 then
  135.       number = 1
  136.    end
  137.    local pointerPosition = {x = 22.18, y = 3, z = -28.3}
  138.    if id == "P1" or id == "P2" then
  139.       pointerPosition = {x = -22.18, y = 3, z = -28.3}
  140.    end
  141.  
  142.    pointerPosition.x = pointerPosition.x - (number < 5 and ((number - 1)%4)*step/2 or 1.5*step)
  143.    pointerPosition.z = pointerPosition.z - math.floor(number/4)*step/2
  144.  
  145.    for i = 0, number-1 do
  146.       local posX = pointerPosition.x + (i%4)*step
  147.       local posY = pointerPosition.y
  148.       local posZ = pointerPosition.z + math.floor(i/4)*step
  149.       self.takeObject({
  150.          position = {posX, posY + 2, posZ},
  151.          callback = 'rollTheDice',
  152.          callback_owner = self,
  153.          params = {num = number}
  154.       })
  155.    end
  156. end
  157.  
  158. function rollTheDice(obj, params)
  159.    table.insert(spawnedDice, obj.guid)
  160.    obj.setScale({0.55, 0.55, 0.55})
  161.    local oldDiceCount = #spawnedDice - params.num
  162.    if #spawnedDice == (params.num + oldDiceCount) then
  163.       startLuaCoroutine(self, "watchDice")
  164.    end
  165.    obj.roll()
  166. end
  167.  
  168. function clearDice()
  169.    for i, v in pairs(spawnedDice) do
  170.       local die = getObjectFromGUID(v)
  171.       if die ~= nil then destroyObject(die) end
  172.    end
  173.    spawnedDice = {}
  174.    local zones = {
  175.       a = getObjectFromGUID(Global.getTable('zones').zone_HL_roller_L.guid),
  176.       b = getObjectFromGUID(Global.getTable('zones').zoneLeft_drawnHit.guid),
  177.       c = getObjectFromGUID(Global.getTable('zones').zone_HL_roller_R.guid),
  178.       d = getObjectFromGUID(Global.getTable('zones').zoneRight_drawnHit.guid),
  179.    }
  180.  
  181.    for zoneKey, zoneGUIDtable in pairs(zones) do
  182.       local zoneGUID = zoneGUIDtable.guid
  183.       local zone = getObjectFromGUID(zoneGUID)
  184.       local objectsInZone = zone.getObjects()
  185.       for _, obj in ipairs(objectsInZone) do
  186.          if obj.tag == "Dice" then
  187.             obj.destroy()
  188.          end
  189.       end
  190.    end
  191.    for _, v in pairs(self.getButtons()) do
  192.       if v.click_function == "removeOnClear" then
  193.          self.removeButton(v.index)
  194.       end
  195.    end
  196. end
  197.  
  198. function watchDice()
  199.    local startTime = os.time()
  200.    repeat
  201.       local restingCount = 0
  202.       for i, dieGUID in ipairs(spawnedDice) do
  203.          local die = getObjectFromGUID(dieGUID)
  204.          if die ~= nil then
  205.             if not die or die.resting == true then
  206.                restingCount = restingCount + 1
  207.                if die.getValue() > attackValues.accuracy - 1 then
  208.                   die.setColorTint({1, 0, 0})
  209.                   hasBloodThirsty = false
  210.                   for _, card in ipairs(zoneInjuryBoard.getObjects()) do
  211.                      if card.getName() == "Bloodthirsty" then
  212.                         hasBloodThirsty = true
  213.                      end
  214.                   end
  215.                else
  216.                   die.setColorTint({0.1, 0.1, 0.1})
  217.                end
  218.             end
  219.          end
  220.       end
  221.       if hasBloodThirsty then
  222.          broadcastToAll("Bloodthirsty ~ If you suffer damage from this attack, place a token on Bloodthirsty", {1, 1, 1})
  223.       end
  224.       coroutine.yield(0)
  225.    until restingCount == #spawnedDice or os.time() > startTime + 6
  226.    return 1
  227. end
  228.  
  229. function showMenu(action)
  230.    Global.UI.setAttribute("AttackRoller", "action", action)
  231.    if action == "Attack" then
  232.       Global.UI.setAttribute("AttackText", "text", "Select a survivor to be attacked.")
  233.       Global.UI.setAttribute("AditionalText", "text", "Spd               Acc")
  234.       Global.UI.setAttribute("Priority", "active", "false")
  235.       Global.UI.setAttribute("spd", "text", getMonster("spd"))
  236.       Global.UI.setAttribute("acc", "text", getMonster("acc"))
  237.    elseif action == "Priority" then
  238.       Global.UI.setAttribute("AttackText", "text", "Select a survivor to gain the Priority Token.")
  239.       Global.UI.setAttribute("AditionalText", "text", "? Permanent ?")
  240.       Global.UI.setAttribute("Attack", "active", "false")
  241.    end
  242.    for k, v in pairs(playerTable) do
  243.       local token = getObjectFromGUID(Global.getTable('user_settings')["settings_" .. k .. "_token"].guid)
  244.       playerTable[k].sigil = token.getName()
  245.       playerTable[k].fontColor = token.getColorTint()
  246.       for _, obj in ipairs(getObjectFromGUID(Global.getTable('zones')["zone" .. k].guid).getObjects()) do
  247.          if string.find(obj.getDescription(), "SurvivorSheet") then
  248.             playerTable[k].name = obj.getName()
  249.             Global.UI.setAttribute(k, "text", v.sigil .. "  " .. v.name .. "  " .. v.sigil)
  250.             Global.UI.setAttribute(k, "textColor", "rgb(" .. v.fontColor.r .. "," .. v.fontColor.g .. "," .. v.fontColor.b .. ")")
  251.          end
  252.       end
  253.    end
  254.    Global.UI.setAttribute(action, "active", "true")
  255.    Global.UI.show("AttackRoller")
  256. end
  257.  
  258. function selectSurvivor(player, value, id)
  259.    if Global.UI.getAttribute("AttackRoller", "action") == "Attack" then
  260.       local hasWireFighting = false
  261.       local grid = getObjectFromGUID(playerTable[id].grid)
  262.       local zonePlayer = getObjectFromGUID(Global.getTable('zones')["zone" .. id].guid)
  263.       local role = nil
  264.       local isInsane = false
  265.       local hitsOn2 = false
  266.       attackValues.speed = tonumber(Global.UI.getAttribute("spd", "text")) + getObjectFromGUID(Global.getTable("boards").modTable.guid).call("getStats", {"speed"})
  267.       attackValues.accuracy = tonumber(Global.UI.getAttribute("acc", "text")) - getObjectFromGUID(Global.getTable("boards").modTable.guid).call("getStats", {"accuracy"}) + getObjectFromGUID(grid.getVar("FullCharSheetGUID")).call("getStats", {"evasion"})
  268.       for _, object in ipairs(zonePlayer.getObjects()) do
  269.          if object.getName() == "Flower Knight Helm" and object.getRotation().z > 165 then
  270.             broadcastToColor("Flower Knight Helm ~ The Monster Suffers (-1) Speed attacking you", player.color, playerTable[id].fontColor)
  271.             attackValues.speed = attackValues.speed - 1
  272.          end
  273.          if object.getName() == "isInsane" and object.getRotation().z > 165 and object.getRotation().z < 195 then
  274.             isInsane = true
  275.          end
  276.       end -- end
  277.  
  278.       local insanity_value = getObjectFromGUID(grid.getVar("FullCharSheetGUID")).call("getStats", {"insanity"})
  279.       if insanity_value >= 3 then
  280.          isInsane = true
  281.       end
  282.       for _, card in ipairs(zoneInjuryBoard.getObjects()) do
  283.          if card.getName() == "Wire-Fighting" then
  284.             grid.call("return_role")
  285.             role = grid.getVar("role")
  286.          end
  287.          if string.find(card.getName(), "Embrace the Eons") then
  288.             attackValues.accuracy = 2
  289.          end
  290.          if card.getName() == "Deep Paralysis" then
  291.             broadcastToAll("Deep Paralysis ~ You are Insane ~ Slenderman gained (+2) Speed ", msg_color)
  292.             attackValues.speed = attackValues.speed + 2
  293.          end
  294.       end
  295.  
  296.       move_camera(player.color, ((id == "P1" or id == "P2") and { - 22.19, 1.79, - 32.23} or {21.94, 1.84, - 32.23}), 60, 13)
  297.  
  298.       if role == "Villain" then
  299.          local tokSpawner = getObjectFromGUID(Global.getTable('tokSpawn').pos_mov.guid)
  300.          tokSpawner.setVar("phase", "endOfMonsterTurn")
  301.          broadcastToAll("Wire-Fighting ~ The Lion Knight gained (+5) Movement for its next activation for attacking the Villain", {1, 1, 1})
  302.          Wait.time(function() tokSpawner.call('spawn_token') end, 0.5, 5)
  303.       end
  304.  
  305.       clearDice()
  306.  
  307.       Wait.time(function() spawnDice(id) end, 1.2)
  308.       createButtons_damage_display()
  309.    else
  310.       local zoneShowdown = getObjectFromGUID(Global.getTable('zonesDestruct').zoneShowdown.guid)
  311.       local hasPriority = false
  312.       local priority_target = nil
  313.       for _, tok in ipairs(zoneShowdown.getObjects()) do
  314.          if tok.getName() == "Priority Target" then
  315.             hasPriority = true
  316.             priority_target = tok
  317.             if string.find(tok.getDescription(), "permanent") then
  318.                broadcastToAll("A Survivor already has the Priority Target Permanently ~ From a Game Effect", {1, 1, 1})
  319.                return
  320.             end
  321.          end
  322.       end
  323.  
  324.       for _, surv in ipairs(zoneShowdown.getObjects()) do
  325.          if surv.getName() == playerTable[id].playerName then
  326.             local pos = surv.getPosition()
  327.             if hasPriority then
  328.                surv.translate({0, 2, 0})
  329.                priority_target.setPosition(pos)
  330.             else
  331.                local obj = getObjectFromGUID(Global.getTable('main_tokens').priority_token.guid)
  332.                local objPos = obj.getPosition()
  333.                priority_target = obj.clone({position = objPos})
  334.                surv.translate({0, 2, 0})
  335.                priority_target.setPosition(pos)
  336.             end
  337.          end
  338.       end
  339.    end
  340.    Global.UI.hide("AttackRoller")
  341. end
  342.  
  343. function changeCounter(player, value, id)
  344.    local counterID = id:sub(1, 3)
  345.    local addRemove = (id:sub(4) == "-") and - 1 or 1
  346.    Global.UI.setAttribute(counterID, "text", tonumber(Global.UI.getAttribute(counterID, "text")) + addRemove)
  347. end
  348.  
  349. -- Utility Functions -----------------------------------------------------------
  350. function birds_eye_view(object, player_color)
  351.    move_camera(player_color, {0, 0.6, 0.68}, 55, 30)
  352. end
  353.  
  354. function moveMonster(object, player_color)
  355.    for _, object in ipairs(zoneShowdown.getObjects()) do
  356.       local desc = object.getDescription()
  357.       if string.find(desc, "monster") and string.find(desc, "figurine") then
  358.          move_camera(player_color, object.getPosition(), 55, 10)
  359.       end
  360.    end
  361. end
  362.  
  363. function getMonster(stat)
  364.    local monsterCards = getAllObjects(getObjectFromGUID(Global.getTable("zones").zoneAIBoard.guid))
  365.    local found = nil
  366.    local sub = ""
  367.    for _, v in pairs(monsterCards) do
  368.       found = v.getName():find(" Basic Action Card")
  369.       if found then
  370.          sub = v:getName():sub(1, found - 1)
  371.          for _, u in pairs(monsterStats) do
  372.             if sub == u.name then
  373.                if stat == "spd" then
  374.                   return u.speed
  375.                else
  376.                   return u.accuracy
  377.                end
  378.             end
  379.          end
  380.       end
  381.    end
  382.    return 2
  383. end
  384.  
  385. function dud() end
  386. function removeOnClear() end
  387.  
  388. function playerLookAt(player_color, position)
  389.    local parameters = {}
  390.    parameters.position = position
  391.    parameters.yaw = 0
  392.    parameters.pitch = 60
  393.    parameters.distance = 15
  394.    if( player_color ~= nil ) then
  395.       Player[player_color].lookAt(parameters)
  396.    end
  397. end
  398.  
  399. function move_camera(player_color, position, pitch, dist)
  400.    local parameters = {}
  401.    parameters.position = position
  402.    parameters.yaw = 0
  403.    parameters.pitch = pitch
  404.    parameters.distance = dist
  405.    if player_color ~= nil then
  406.       Player[player_color].lookAt(parameters)
  407.    end
  408. end
  409.  
  410. function isCampaignLoaded()
  411.    for _, object in ipairs(getObjectFromGUID(Global.getTable('zones').zoneSettlement.guid).getObjects()) do
  412.       local desc = object.getDescription()
  413.       if string.find(desc, "SettlementSheet") then
  414.          return true
  415.       end
  416.    end
  417.    return false
  418. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement