LOCATIONS = { { name = "Blasted Heath", position = Vector({-17.12, 1.62, -0.03}) }, { name = "Devil's Hop Yard", position = Vector({-17.12, 1.62, -7.70}) }, { name = "Dunwich Village", position = Vector({-23.68, 1.63, 7.57}) }, { name = "Ten-Acre Meadow", position = Vector({-23.68, 1.63, -0.03}) }, { name = "Whateley Ruins", position = Vector({-23.68, 1.63, -7.70}) }, { name = "Cold Spring Glen", position = Vector({-30.22, 1.64, -0.03}) } } BORDER_COLORS = { Color(230/255, 159/255, 0), Color(0, 158/255, 115/255), Color(0, 114/255, 178/255), Color(213/255, 94/255, 0), Color(204/255, 121/255, 167/255) } SET_ASIDE = { position = {-5.75, 1.54, 19.25}, rotation = { x=0, y=270, z=0 } } PLAYAREA = { position = {-27.92, 4.04, -0.20}, rotation = {0.00, 90, 0.00}, scale = {37.63, 5.10, 37.19} } function onLoad(save_state) self.createButton({ label="Set Up", click_function="setup", function_owner=self, position={0,0.1,-0.6}, height=120, width=400, scale={x=1.75, y=1.75, z=1.75}, font_size=80 }) self.createButton({ label="Move\nBroods", click_function="moveBroods", function_owner=self, position={0,0.1,0.4}, height=240, width=400, scale={x=1.75, y=1.75, z=1.75}, font_size=80 }) math.randomseed(os.time()) end function setup(_obj, _color, alt_click) if SETUP_DONE then return end findLocations() locationCards = {} for k,loc in pairs(locationMap) do local chosen = math.random(2) local guid = loc.guids[chosen] local card = getObjectFromGUID(loc.guids[3 - chosen]) card.setPosition(SET_ASIDE.position) card.setRotation({0, 270, 0}) card = getObjectFromGUID(guid) card.setPosition(loc.position) card.setRotation({0, 270, 0}) locationCards[loc.name] = guid end SETUP_DONE = true end function getPlayAreaObjects() return Physics.cast({ origin = PLAYAREA.position, direction = { x=0, y=1, z=0 }, type = 3, size = PLAYAREA.scale, orientation = PLAYAREA.rotation }) end function findLocations() locationMap = {} for i,loc in ipairs(LOCATIONS) do loc.guids = {} locationMap[loc.name] = loc end local objs = getPlayAreaObjects() for i,v in ipairs(objs) do local obj = v.hit_object local loc = locationMap[obj.getName()] if loc ~= nil then table.insert(loc.guids, obj.getGUID()) end end end function moveBroods(obj, color, alt_click) local objs = getPlayAreaObjects() local broods = {} for i,v in ipairs(objs) do local obj = v.hit_object if obj.getName() == "Brood of Yog-Sothoth" then obj.setVar("helperGuid", self.getGUID()) table.insert(broods, obj) end end if #broods == 0 then printToColor("No broods found in play area", color) return end -- clear location highlights for name,loc in pairs(locationCards) do local obj = getObjectFromGUID(loc) if obj ~= nil then obj.setVectorLines({}) end end locationBorders = {} for i,brood in ipairs(broods) do local j = math.random(6) local loc = LOCATIONS[j].name brood.setVar("targetLocation", loc) brood.setVar("colorIndex", i) drawBorder(brood, { i }) if locationBorders[loc] == nil then locationBorders[loc] = {} end table.insert(locationBorders[loc], i ) printToAll("Move brood once toward " .. loc, BORDER_COLORS[i]) end for loc,border in pairs(locationBorders) do drawBorder(locationCards[loc], border) end end function drawBorder(card, colorIndexes) if type(card) == "string" then card = getObjectFromGUID(card) if card == nil then return end end local bounds = card.getBoundsNormalized() local xSize = bounds.size.x / 2 local zSize = bounds.size.z / 2 local borders = {} for i,index in ipairs(colorIndexes) do local color = BORDER_COLORS[index] table.insert(borders, { points = { { 0 - xSize, 0, 0 - zSize }, { 0 + xSize, 0, 0 - zSize }, { 0 + xSize, 0, 0 + zSize }, { 0 - xSize, 0, 0 + zSize }, { 0 - xSize, 0, 0 - zSize } }, color = color, thickness = 0.1, rotation = {0,0,0} }) xSize = xSize + 0.12 zSize = zSize + 0.12 end card.setVectorLines(borders) end function removeBorder(params) local loc = params.location local card = locationCards[loc] local indexes = locationBorders[loc] for i,index in ipairs(indexes) do if index == params.colorIndex then table.remove(indexes, i) break end end drawBorder(card, indexes) end