220 lines
5.8 KiB
Plaintext
220 lines
5.8 KiB
Plaintext
ALL_LOCATIONS = {
|
|
"Southside",
|
|
"Rivertown",
|
|
"Merchant District",
|
|
"French Hill",
|
|
"South Church",
|
|
"Uptown",
|
|
"Hangman's Hill",
|
|
"Silver Twilight Lodge"
|
|
}
|
|
|
|
RANDOMIZED_LOCATIONS = {
|
|
{ name = "Southside", deck = "4730c6" },
|
|
{ name = "Rivertown", deck = "3f6cb7" },
|
|
{ name = "Merchant District", deck = "6ed4f6" },
|
|
{ name = "French Hill", deck = "8ff540" },
|
|
{ name = "South Church", deck = "e18226" },
|
|
{ name = "Uptown", deck = "08a5f6" },
|
|
}
|
|
|
|
SET_ASIDE = {
|
|
position = { x=-2.52, y=2, z=14.87 },
|
|
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()
|
|
self.createButton({
|
|
label="Set Up",
|
|
click_function="setup",
|
|
function_owner=self,
|
|
position={0,0.1,-0.6},
|
|
height=120,
|
|
width=300,
|
|
scale={x=1.75, y=1.75, z=1.75},
|
|
font_size=75
|
|
})
|
|
|
|
self.createButton({
|
|
label="Place Clue",
|
|
click_function="placeClue",
|
|
function_owner=self,
|
|
position={0,0.1,0},
|
|
height=120,
|
|
width=400,
|
|
scale={x=1.75, y=1.75, z=1.75},
|
|
font_size=75
|
|
})
|
|
|
|
self.createButton({
|
|
label="Add Breaches",
|
|
click_function="addBreaches",
|
|
function_owner=self,
|
|
position={0,0.1,0.6},
|
|
height=120,
|
|
width=500,
|
|
scale={x=1.75, y=1.75, z=1.75},
|
|
font_size=75
|
|
})
|
|
|
|
PLAYER_COUNTER = getObjectFromGUID('f182ee')
|
|
TOKEN_PLAYER_ONE = Global.getTable('tokenplayerone')
|
|
math.randomseed(os.time())
|
|
end
|
|
|
|
function setup(_obj, _color, alt_click)
|
|
locationData = {}
|
|
-- find Hangman's Hill and Silver Twilight Lodge
|
|
local objs = Physics.cast({
|
|
origin = PLAYAREA.position,
|
|
direction = { x=0, y=1, z=0 },
|
|
type = 3,
|
|
size = PLAYAREA.scale,
|
|
orientation = PLAYAREA.rotation
|
|
})
|
|
for i,v in ipairs(objs) do
|
|
local obj = v.hit_object
|
|
if obj.tag == "Card" then
|
|
if obj.getName() == "Hangman's Hill" then
|
|
locationData["Hangman's Hill"] = { guid = obj.getGUID(), breach = 0, clue=0 }
|
|
elseif obj.getName() == "Silver Twilight Lodge" then
|
|
locationData["Silver Twilight Lodge"] = { guid = obj.getGUID(), breach = 0, clue=0 }
|
|
end
|
|
end
|
|
end
|
|
|
|
if locationData["Hangman's Hill"] == nil or locationData["Silver Twilight Lodge"] == nil then
|
|
printToColor("Place Hangman's Hill and Silver Twilight Lodge first", _color)
|
|
return
|
|
end
|
|
|
|
for i,loc in ipairs(RANDOMIZED_LOCATIONS) do
|
|
local deck = getObjectFromGUID(loc.deck)
|
|
deck.shuffle()
|
|
for j=1,2 do
|
|
deck.takeObject({
|
|
position = SET_ASIDE.position,
|
|
rotation = SET_ASIDE.rotation
|
|
})
|
|
end
|
|
locationData[loc.name] = { guid = deck.remainder.guid, breach = 0, clue=0 }
|
|
end
|
|
|
|
local numPlayers = PLAYER_COUNTER.getVar("val")
|
|
local numLocations = 2
|
|
local numDraws = numPlayers
|
|
if numPlayers == 4 then
|
|
numDraws = 3
|
|
numLocations = 3
|
|
end
|
|
for i = 1,numDraws do
|
|
placeBreaches(numLocations)
|
|
end
|
|
|
|
self.editButton({
|
|
label="Random Location",
|
|
click_function="getRandomLocation",
|
|
function_owner=self,
|
|
position={0,0.1,-0.6},
|
|
height=120,
|
|
width=525,
|
|
scale={x=1.75, y=1.75, z=1.75},
|
|
font_size=60
|
|
})
|
|
end
|
|
|
|
function getRandomLocation()
|
|
broadcastToAll(ALL_LOCATIONS[math.random(8)])
|
|
end
|
|
|
|
function placeClue()
|
|
local index = math.random(1, #ALL_LOCATIONS)
|
|
local name = ALL_LOCATIONS[index]
|
|
local location = locationData[name]
|
|
local clue = location.clue
|
|
local pos = getObjectFromGUID(location.guid).getPosition()
|
|
local cluePos = {
|
|
x = pos.x + 0.85, y = pos.y + 1, z = pos.z - 0.8 + (0.55 * clue)
|
|
}
|
|
clue = clue + 1
|
|
if clue > 3 then clue = 0 end
|
|
location.clue = clue
|
|
printToAll("Clue placed at: " .. name)
|
|
spawnClue(cluePos)
|
|
end
|
|
|
|
function spawnClue(position)
|
|
local obj_parameters = {
|
|
position = position,
|
|
rotation = {3.87674022, -90, 0.239081308},
|
|
scale = {0.25, 1, 0.25},
|
|
type = "Custom_Tile"
|
|
}
|
|
local custom = {
|
|
thickness = 0.1,
|
|
stackable = true,
|
|
type = 2,
|
|
image = TOKEN_PLAYER_ONE.clue,
|
|
image_bottom = TOKEN_PLAYER_ONE.doom
|
|
}
|
|
|
|
local token = spawnObject(obj_parameters)
|
|
token.setCustomObject(custom)
|
|
token.use_snap_points = false
|
|
end
|
|
|
|
function addBreaches()
|
|
placeBreaches(PLAYER_COUNTER.getVar("val") + 1)
|
|
end
|
|
|
|
function placeBreaches(numBreaches)
|
|
local shuffled = { }
|
|
for i,v in ipairs(ALL_LOCATIONS) do
|
|
local pos = math.random(1, #shuffled+1)
|
|
table.insert(shuffled, pos, v)
|
|
end
|
|
|
|
printToAll("Breaches added to:")
|
|
for j = 1,numBreaches do
|
|
printToAll(shuffled[j])
|
|
local location = locationData[shuffled[j]]
|
|
local pos = getObjectFromGUID(location.guid).getPosition()
|
|
local breach = location.breach
|
|
local z = breach < 3 and (pos.z - 0.7 + (0.7 * breach)) or
|
|
(pos.z - 0.35 + (0.7 * (breach - 3)))
|
|
|
|
local breachPos = {
|
|
x = pos.x + 0.3, y = pos.y + 1, z = z
|
|
}
|
|
breach = breach + 1
|
|
if breach > 4 then breach = 0 end
|
|
location.breach = breach
|
|
spawnResource(breachPos)
|
|
end
|
|
end
|
|
|
|
function spawnResource(position)
|
|
local obj_parameters = {
|
|
position = position,
|
|
rotation = {0, 0, 0},
|
|
scale = {0.17, 0.17, 0.17},
|
|
type = "Custom_Token"
|
|
}
|
|
local custom = {
|
|
thickness = 0.3,
|
|
merge_distance = 5.0,
|
|
stackable = false,
|
|
image = TOKEN_PLAYER_ONE.resource
|
|
}
|
|
|
|
local token = spawnObject(obj_parameters)
|
|
token.setCustomObject(custom)
|
|
token.use_snap_points = false
|
|
end
|