Advertisement
Kijan

KDM UI Lua

Feb 22nd, 2019
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 19.92 KB | None | 0 0
  1. function onLoad()
  2.    gameBox = getObjectFromGUID(Global.getTable('bags').gameBox.guid)
  3. end
  4.  
  5. function showMenu(player, value, id)
  6.    local found = value:find("|")
  7.    if found == nil then
  8.       Global.UI.show(value)
  9.    else
  10.       Global.UI.hide(value:sub(found + 1))
  11.       Global.UI.show(value:sub(1, found - 1))
  12.    end
  13. end
  14.  
  15. function closeMenu(player, value, id)
  16.    Global.UI.hide(value)
  17. end
  18.  
  19. function campaign(player, value, id)
  20.    local campaigns = {}
  21.    local bag_toLoad = nil
  22.    campaigns["People of the Bloom"] = {lang_toLoad = "Language", deck_toLoad_1 = "Starting Innovation Deck", deck_toLoad_2 = "Consequences"}
  23.    campaigns["People of the Dark"] = {lang_toLoad = "Language", deck_toLoad_1 = "Starting Innovation Deck", deck_toLoad_2 = "Consequences"}
  24.    campaigns["People of the Lantern"] = {lang_toLoad = "Language", deck_toLoad_1 = "Starting Innovation Deck", deck_toLoad_2 = "Consequences"}
  25.    campaigns["People of the Skull"] = {lang_toLoad = "Language", deck_toLoad_1 = "Starting Innovation Deck", deck_toLoad_2 = "Consequences"}
  26.    campaigns["People of the Soil"] = {lang_toLoad = "Language", deck_toLoad_1 = "Starting Innovation Deck", deck_toLoad_2 = "Consequences"}
  27.    campaigns["People of the Stars"] = {lang_toLoad = "Dragon Speech", deck_toLoad_1 = "Starting Innovation Deck (Stars)", deck_toLoad_2 = "Consequences (Stars)"}
  28.    campaigns["People of the Sun"] = {lang_toLoad = "Sun Language", deck_toLoad_1 = "Starting Innovation Deck (Other)", deck_toLoad_2 = "Consequences (Sun)"}
  29.  
  30.    broadcastToAll("Loading...", {1, 1, 1})
  31.    for _, obj in ipairs(gameBox.getObjects()) do
  32.       local name = obj.name
  33.       if name == value then
  34.  
  35.          bag_toLoad = gameBox.takeObject({
  36.             position = {26.07, 1.91, - 4.89},
  37.             rotation = {0, 0, 0},
  38.             guid = obj.guid,
  39.             smooth = false
  40.          })
  41.       end
  42.       if obj.name == campaigns[value].deck_toLoad_1 then
  43.          gameBox.takeObject({position = { - 60.96, 3.5, - 11.91}, rotation = {0.00, 180.07, 180.00}, guid = obj.guid, smooth = false})
  44.       elseif obj.name == campaigns[value].deck_toLoad_2 then
  45.          gameBox.takeObject({position = { - 83.76, 3.5, - 11.91}, rotation = {0.00, 180.07, 180.00}, guid = obj.guid, smooth = false})
  46.       elseif obj.name == campaigns[value].lang_toLoad then
  47.          gameBox.takeObject({position = { - 72.30, 9.00, 24.91}, rotation = {8.12, 179.98, 0.00}, guid = obj.guid, smooth = false})
  48.       end
  49.    end
  50.    if bag_toLoad == nil then
  51.       broadcastToAll(value .. " Box not found!", {1, 0, 0})
  52.    else
  53.       Wait.condition(function() get_from_campaign(bag_toLoad) end, function() return checkLoaded(bag_toLoad) end)
  54.    end
  55. end
  56.  
  57. function get_from_campaign(bag_toLoad)
  58.    local terrainOffset = 1
  59.    local strangeOffset = 1
  60.    for _, obj in pairs(bag_toLoad.getObjects()) do
  61.       local name = obj.name
  62.       local desc = obj.description
  63.       if name == "Lantern Hoard"
  64.       or name == "Skull Totem"
  65.       or name == "Forest Gate"
  66.       or name == "Throne"
  67.       or name == "The Sun"
  68.       or name == "Thorny Mangrove"
  69.       or name == "Sacred Grove" then
  70.          bag_toLoad.takeObject({position = {72.28, 4.48, - 2.20}, rotation = {11.11, 179.97, 179.99}, guid = obj.guid, smooth = false})
  71.  
  72.       elseif string.find(name, "Survivor Bag") then
  73.          bag_toLoad.takeObject({position = {0.00, 2.56, - 45.00}, rotation = {17.60, 179.94, 359.98}, guid = obj.guid, smooth = false}).lock()
  74.  
  75.       elseif string.find(name, "P1") then
  76.          bag_toLoad.takeObject({position = { - 33.20, 1.63, - 35.90}, rotation = {3.12, 179.85, 359.99}, guid = obj.guid, smooth = false})
  77.       elseif string.find(name, "P2") then
  78.          bag_toLoad.takeObject({position = { - 15.88, 1.63, - 35.90}, rotation = {3.12, 179.85, 359.99}, guid = obj.guid, smooth = false})
  79.       elseif string.find(name, "P3") then
  80.          bag_toLoad.takeObject({position = {11.28, 1.63, - 35.90}, rotation = {3.12, 179.85, 359.99}, guid = obj.guid, smooth = false})
  81.       elseif string.find(name, "P4") then
  82.          bag_toLoad.takeObject({position = {28.31, 1.63, - 35.90}, rotation = {3.12, 179.85, 359.99}, guid = obj.guid, smooth = false})
  83.  
  84.       elseif string.find(name, "Unamed Settlement") then
  85.          bag_toLoad.takeObject({position = { - 0.28, 16.76, 63.78}, rotation = {32.00, 180.00, 0.00}, guid = obj.guid, smooth = false}).lock()
  86.       end
  87.  
  88.       if string.find(desc, "terrain") then
  89.          terr_pos = {x = 23.79, y = -8.79, z = -104.54}
  90.          bag_toLoad.takeObject({
  91.             position = {terr_pos.x, terr_pos.y + terrainOffset, terr_pos.z},
  92.             rotation = {0, 180, 180},
  93.             smooth = false,
  94.             guid = obj.guid
  95.          })
  96.          terrainOffset = terrainOffset + 1
  97.       end
  98.  
  99.       if string.find(desc, "strange") then
  100.          strange_pos = {x = 76.77, y = 3.00, z = -10.14}
  101.          bag_toLoad.takeObject({
  102.             position = {strange_pos.x, strange_pos.y + strangeOffset, strange_pos.z},
  103.             rotation = {0, 180, 180},
  104.             smooth = false,
  105.             guid = obj.guid
  106.          })
  107.          strangeOffset = strangeOffset + 1
  108.       end
  109.    end
  110.    broadcastToAll(bag_toLoad.getName() .. " Loaded", {1, 1, 1})
  111.    bag_toLoad.destruct()
  112. end
  113.  
  114. function expansion(player, value, id)
  115.    local bag_toLoad = nil
  116.    for _, obj in ipairs(gameBox.getObjects()) do
  117.       local name = obj.name
  118.       if name == value then
  119.          bag_toLoad = gameBox.takeObject({
  120.             position = {26.07, 1.91, - 4.89},
  121.             rotation = {0, 0, 0},
  122.             guid = obj.guid,
  123.             smooth = false
  124.          })
  125.       end
  126.    end
  127.  
  128.    if bag_toLoad == nil then
  129.       broadcastToAll(value .. " Box not found!", {1, 0, 0})
  130.    else
  131.       Wait.condition(function() get_from_expansion(bag_toLoad) end, function() return checkLoaded(bag_toLoad) end)
  132.    end
  133. end
  134.  
  135. function get_from_expansion(bag_toLoad)
  136.    local offsets = {disorder = 1, fa = 1, sfa = 1, strange = 1, innovation = 1, terrain = 1, tactics = 1, se = 1}
  137.    local dis_pos = {x = -1.1, y = 2, z = -54.92}
  138.    local fa_pos = {x = 1.09, y = 2, z = -54.92}
  139.    local sfa_pos = {x = 3.29, y = 2, z = -54.92}
  140.    local strange_pos = {x = 76.77, y = 2.00, z = -10.14}
  141.    local inn_pos = {x = -83.71, y = 3.14, z = -11.84}
  142.    local terr_pos = {x = 23.79, y = -8.59, z = -104.54}
  143.    local tact_pos = {x = -5.56, y = 2.00, z = -53.03}
  144.    local se_pos = {x = -79.26, y = 8.43, z = 19.67}
  145.    for _, obj in ipairs(bag_toLoad.getObjects()) do
  146.       local name = obj.name
  147.       local desc = obj.description
  148.       print(name)
  149.       if string.find(desc, "disorder") then
  150.          bag_toLoad.takeObject({
  151.             position = {dis_pos.x, dis_pos.y + offsets.disorder, dis_pos.z},
  152.             rotation = {0, 180, 0},
  153.             smooth = false,
  154.             guid = obj.guid
  155.          })
  156.          offsets.disorder = offsets.disorder + 1
  157.       elseif string.find(desc, "fighting art") then
  158.          bag_toLoad.takeObject({
  159.             position = {fa_pos.x, fa_pos.y + offsets.fa, fa_pos.z},
  160.             rotation = {0, 180, 0},
  161.             smooth = false,
  162.             guid = obj.guid
  163.          })
  164.          offsets.fa = offsets.fa + 1
  165.       elseif string.find(desc, "secret fighting art") then
  166.          bag_toLoad.takeObject({
  167.             position = {fa_pos.x, fa_pos.y + offsets.sfa, fa_pos.z},
  168.             rotation = {0, 180, 0},
  169.             smooth = false,
  170.             guid = obj.guid
  171.          })
  172.          offsets.sfa = offsets.sfa + 1
  173.       elseif string.find(desc, "strange") then
  174.          bag_toLoad.takeObject({
  175.             position = {strange_pos.x, strange_pos.y + offsets.strange, strange_pos.z},
  176.             rotation = {0, 180, 180},
  177.             smooth = false,
  178.             guid = obj.guid
  179.          })
  180.          offsets.strange = offsets.strange + 1
  181.       elseif string.find(desc, "innovation") then
  182.          bag_toLoad.takeObject({
  183.             position = {inn_pos.x, inn_pos.y + offsets.innovation, inn_pos.z},
  184.             rotation = {0, 180, 180},
  185.             smooth = false,
  186.             guid = obj.guid
  187.          })
  188.          offsets.innovation = offsets.innovation + 1
  189.       elseif string.find(desc, "terrain") then
  190.          bag_toLoad.takeObject({
  191.             position = {terr_pos.x, terr_pos.y + offsets.terrain, terr_pos.z},
  192.             rotation = {0, 180, 180},
  193.             smooth = false,
  194.             guid = obj.guid
  195.          })
  196.          offsets.terrain = offsets.terrain + 1
  197.       elseif string.find(desc, "tactics") then
  198.          bag_toLoad.takeObject({
  199.             position = {tact_pos.x, tact_pos.y + offsets.tactics, tact_pos.z},
  200.             rotation = {0, 180, 180},
  201.             smooth = false,
  202.             guid = obj.guid
  203.          })
  204.          offsets.tactics = offsets.tactics + 1
  205.       elseif desc == "settlement event" then
  206.          bag_toLoad.takeObject({
  207.             position = {se_pos.x, se_pos.y + offsets.se, se_pos.z},
  208.             rotation = {10.89, 180, 180},
  209.             smooth = false,
  210.             guid = obj.guid
  211.          })
  212.          offsets.se = offsets.se + 1
  213.          -- loads Gorm Climate next to SE deck
  214.       elseif desc == "settlement event 2" then
  215.          bag_toLoad.takeObject({
  216.             position = { - 75.94, 7.37, 19.66},
  217.             rotation = {10.89, 180, 0},
  218.             smooth = false,
  219.             guid = obj.guid
  220.          })
  221.       end
  222.    end
  223.    local event_label_rot = {32.00, 180.00, 0.00}
  224.    for _, obj in ipairs(bag_toLoad.getObjects()) do
  225.       local name = obj.name
  226.       if name == "The Approaching Storm" then
  227.          bag_toLoad.takeObject({position = { - 4.11, 21.67, 72.63}, rotation = event_label_rot, smooth = false, guid = obj.guid}).lock()
  228.  
  229.       elseif name == "Young Rivals" then
  230.          bag_toLoad.takeObject({position = { - 4.13, 21.42, 72.01}, rotation = event_label_rot, smooth = false, guid = obj.guid}).lock()
  231.  
  232.       elseif name == "A Crone's Tale" then
  233.          bag_toLoad.takeObject({position = { - 4.65, 20.46, 70.57}, rotation = event_label_rot, smooth = false, guid = obj.guid}).lock()
  234.  
  235.       elseif name == "The Hanged Man" then
  236.          bag_toLoad.takeObject({position = { - 1.03, 20.46, 70.57}, rotation = event_label_rot, smooth = false, guid = obj.guid}).lock()
  237.  
  238.       elseif name == "It's Already Here" then
  239.          bag_toLoad.takeObject({position = { - 6.39, 20.10, 70.11}, rotation = event_label_rot, smooth = false, guid = obj.guid}).lock()
  240.  
  241.       elseif name == "An Uninvited Guest" then
  242.          bag_toLoad.takeObject({position = { - 2.68, 20.10, 70.11}, rotation = event_label_rot, smooth = false, guid = obj.guid}).lock()
  243.  
  244.       elseif name == "Glowing Crater" then
  245.          bag_toLoad.takeObject({position = { - 7.11, 19.46, 69.10}, rotation = event_label_rot, smooth = false, guid = obj.guid}).lock()
  246.  
  247.       elseif name == "Promise Under the Sun" then
  248.          bag_toLoad.takeObject({position = { - 3.55, 19.46, 69.10}, rotation = event_label_rot, smooth = false, guid = obj.guid}).lock()
  249.  
  250.       elseif name == "Rumbling in the Dark" then
  251.          bag_toLoad.takeObject({position = {0.06, 19.46, 69.10}, rotation = event_label_rot, smooth = false, guid = obj.guid}).lock()
  252.  
  253.       elseif name == "Silver City" then
  254.          bag_toLoad.takeObject({position = { - 1.97, 17.90, 66.55}, rotation = event_label_rot, smooth = false, guid = obj.guid}).lock()
  255.  
  256.       elseif name == "Object of Desire" then
  257.          bag_toLoad.takeObject({position = {24.93, 0.99, - 14.32}, rotation = {0, 180, 180}, smooth = false, guid = obj.guid})
  258.       end
  259.    end
  260. end
  261.  
  262. function promo(player, value, id)
  263.    print(value)
  264. end
  265.  
  266. function theme(player, value, id)
  267.    local objs = getAllObjects()
  268.    for _, obj in ipairs(objs) do
  269.       if obj.getDescription() ~= nil then
  270.          if string.find(obj.getDescription(), "theme") then
  271.             obj.AssetBundle.playLoopingEffect(tonumber(value))
  272.          end
  273.       end
  274.    end
  275.    local tok = getObjectFromGUID(Global.getTable('user_settings').current_theme.guid)
  276.    tok.setDescription(value)
  277. end
  278.  
  279. function font(player, value, id)
  280.    local fonts = {Croz = 0, Duer = 1, Gob = 2, God = 3, Haunt = 4, Hit = 5, Just = 6, Mag = 7, Mid = 8, Morph = 9, Pap = 10, Silv = 11, Star = 12, Stone = 13}
  281.    local bag = getObjectFromGUID(Global.getTable('bags').fontBox.guid)
  282.    local objs = getAllObjects()
  283.    local states = {reaction = 0, wound = 0}
  284.    for _, obj in ipairs(objs) do
  285.       local desc = obj.getDescription()
  286.       local name = obj.getName()
  287.       if string.find(desc, "font") then
  288.          if string.find(name, "Reactions") then
  289.             states.reaction = obj.AssetBundle.getLoopingEffectIndex()
  290.             bag.putObject(obj)
  291.          elseif string.find(name, "Wound") then
  292.             states.wound = obj.AssetBundle.getLoopingEffectIndex()
  293.             bag.putObject(obj)
  294.          else
  295.             obj.AssetBundle.playLoopingEffect(fonts[value])
  296.          end
  297.       end
  298.    end
  299.  
  300.    Wait.time(
  301.       function()
  302.          for _, font in ipairs(bag.getObjects()) do
  303.             if string.find(font.name, value) then
  304.                if string.find(font.name, "Wounds") then
  305.                   local obj = bag.takeObject({position = {0, 0.8, 0}, rotation = {0, 0, 0}, smooth = false, guid = font.guid})
  306.                   obj.lock()
  307.                   Wait.condition(function() obj.AssetBundle.playLoopingEffect(states.wound) end, function() return checkLoaded(obj) end)
  308.                elseif string.find(font.name, "Reactions") then
  309.                   local obj = bag.takeObject({position = {0, 0.8, 0}, rotation = {0, 0, 0}, smooth = false, guid = font.guid})
  310.                   obj.lock()
  311.                   Wait.condition(function() obj.AssetBundle.playLoopingEffect(states.reaction) end, function() return checkLoaded(obj) end)
  312.                end
  313.             end
  314.          end
  315.       end,
  316.    1)
  317.  
  318.    local tok = getObjectFromGUID(Global.getTable('user_settings').current_font.guid)
  319.    tok.setDescription(fonts[value])
  320.  
  321.    -- local zone = getObjectFromGUID(Global.getTable('zonesDestruct').zoneShowdown.guid)
  322.    -- for _, font in ipairs(zone.getObjects()) do
  323.    --
  324.    -- end
  325. end
  326.  
  327. function gameMode(player, value, id)
  328.    local current_difficulty = getObjectFromGUID(Global.getTable('user_settings').current_mode.guid)
  329.    if value == "Easy Mode" then
  330.       -- monster starts showdown with 2 wounds
  331.       -- extra resources
  332.       -- survivors die at 7 bleeding tokens instead of 5
  333.       extraBleed1 = "d7a48a"
  334.       extraBleed2 = "4de12c"
  335.       extraBleed3 = "e51595"
  336.       extraBleed4 = "a40619"
  337.       remove_death_mode_irreplaceable()
  338.       current_difficulty.setDescription("easy mode")
  339.    elseif value == "Quick Mode" then
  340.       -- each survivor starts with +1 str -- in function add
  341.       -- monster starts with +1 dmg at start of showdown -- in function startShowdown
  342.       -- survivors die when they have 3 bleeding tokens -- in function onObjectEnterZone > on common grid code
  343.       -- when the monster suffers a wound it suffers an additional wound -- NOT DONE YET
  344.       remove_death_mode_irreplaceable()
  345.       current_difficulty.setDescription("quick mode")
  346.    elseif value == "Death Mode" then
  347.       -- all gear is irreplaceable -- in function onObjectEnterZone > on common grid code
  348.       -- monster gains +1 dmg at start of showdown -- in function startShowdown
  349.       current_difficulty.setDescription("death mode")
  350.    elseif value == "Hero Mode" then
  351.    end
  352. end
  353.  
  354. function remove_death_mode_irreplaceable()
  355.    -- Iterate over all player zones
  356.    local playerZones = {
  357.       red = getObjectFromGUID(Global.getTable('zones').zoneP1.guid),
  358.       yellow = getObjectFromGUID(Global.getTable('zones').zoneP2.guid),
  359.       green = getObjectFromGUID(Global.getTable('zones').zoneP3.guid),
  360.       blue = getObjectFromGUID(Global.getTable('zones').zoneP4.guid)
  361.    }
  362.    for zoneKey, zoneGUIDtable in pairs(playerZones) do
  363.       local zoneGUID = zoneGUIDtable.guid
  364.       local zone = getObjectFromGUID(zoneGUID)
  365.       local objectsInZone = zone.getObjects()
  366.       for _, obj in ipairs(objectsInZone) do
  367.          local desc = obj.getDescription()
  368.          if string.find(desc, "death mode irreplaceable") then
  369.             local new_desc = string.gsub(desc, "death mode irreplaceable", "")
  370.             obj.setDescription(new_desc)
  371.          end
  372.       end
  373.    end
  374. end
  375.  
  376. function avatar(player, value, id)
  377.    print(value)
  378. end
  379.  
  380. function sigil(player, value, id)
  381.    print(value)
  382. end
  383.  
  384. function lighting(player, value, id)
  385.    local found = value:find("|")
  386.    if found == nil then
  387.       return
  388.    end
  389.  
  390.    local lightBox = getObjectFromGUID(Global.getTable('bags').lightBox.guid)
  391.    local zoneShowdown = getObjectFromGUID(Global.getTable('zonesDestruct').zoneShowdown.guid)
  392.    local gameBox = getObjectFromGUID(Global.getTable('bags').gameBox.guid)
  393.  
  394.    local category = value:sub(1, found - 1)
  395.    local option = value:sub(found + 1)
  396.  
  397.    local pos = lightBox.getPosition()
  398.  
  399.    if category == "main" then
  400.       store_current_light("Main Lighting Color")
  401.       for _, light in ipairs(lightBox.getObjects()) do
  402.          if light.name == option
  403.          and string.find(light.description, option) then
  404.             main_light = lightBox.takeObject({
  405.                position = {pos.x, pos.y + 10, pos.z},
  406.                rotation = {0, 0, 0},
  407.                smooth = false,
  408.                guid = light.guid,
  409.             })
  410.             set_light_position(main_light)
  411.          end
  412.       end
  413.       broadcastToAll("Main Lights set to " .. option, {1, 1, 1})
  414.    elseif category == "dice" then
  415.       store_current_light("Dice Tray Lighting Color")
  416.       for _, light in ipairs(lightBox.getObjects()) do
  417.          if light.name == option
  418.          and string.find(light.description, option) then
  419.             main_light = lightBox.takeObject({
  420.                position = {pos.x, pos.y + 10, pos.z},
  421.                rotation = {0, 0, 0},
  422.                smooth = false,
  423.                guid = light.guid,
  424.             })
  425.             set_light_position(main_light)
  426.          end
  427.       end
  428.       broadcastToAll("Dice Tray Lights set to " .. option, {1, 1, 1})
  429.    elseif category == "lighting" then
  430.       broadcastToAll("Lighting is Turned " .. option, {1,1,1})
  431.  
  432.       if option == "off" then
  433.          for _, light in ipairs(zoneShowdown.getObjects()) do
  434.             if string.find(light.getDescription(), "light bundle") then
  435.                light.setPosition({pos.x, pos.y + 2, pos.z})
  436.                lightBox.putObject(light)
  437.             end
  438.          end
  439.       else
  440.          -- Lighting on HERE
  441.       end
  442.    elseif category == "effects" then
  443.       -- Effects on and off--- on and off is in the option variable
  444.    end
  445. end
  446.  
  447. function store_current_light(light_toStore)
  448.    local zoneShowdown = getObjectFromGUID(Global.getTable('zonesDestruct').zoneShowdown.guid)
  449.    local lightBox = getObjectFromGUID(Global.getTable('bags').lightBox.guid)
  450.     local pos = lightBox.getPosition()
  451.     for _, light in ipairs(zoneShowdown.getObjects()) do
  452.         if light.getName() == light_toStore and string.find(light.getDescription(), "light bundle") then
  453.             light.setPosition({pos.x, pos.y + 2, pos.z})
  454.             lightBox.putObject(light)
  455.         end
  456.     end
  457. end
  458.  
  459. function set_light_position(main_light)
  460.     if main_light ~= nil then
  461.       local current_phase = getObjectFromGUID(Global.getTable('user_settings').current_phase.guid)
  462.         main_light.setPosition({0,0.8,0})
  463.         main_light.setLock(true)
  464.         if main_light.getName() == "Main Lighting Color" then
  465.             local desc = current_phase.getDescription()
  466.             if desc == "hunt phase" then
  467.                 main_light.AssetBundle.playLoopingEffect(1)
  468.             elseif desc == "showdown phase" then
  469.                 main_light.AssetBundle.playLoopingEffect(2)
  470.             elseif desc == "settlement phase" then
  471.                 main_light.AssetBundle.playLoopingEffect(3)
  472.             else
  473.                 main_light.AssetBundle.playLoopingEffect(0)
  474.             end
  475.         elseif main_light.getName() == "Dice Tray Lighting Color" then
  476.             main_light.AssetBundle.playLoopingEffect(0)
  477.         end
  478.     end
  479. end
  480.  
  481. -- Check if an object is fully loaded
  482. function checkLoaded(obj)
  483.    if not obj.loading_custom and not obj.spawning then
  484.       return true
  485.    end
  486.    return false
  487. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement