updated DES detection for Hand Helper
This commit is contained in:
parent
dedd50aedd
commit
6c2741a9df
@ -22,7 +22,7 @@
|
||||
"ImageURL": "http://cloud-3.steamusercontent.com/ugc/1704036721123215146/E44A3B99EACF310E49E94977151A03C9A3DC7F17/",
|
||||
"WidthScale": 0
|
||||
},
|
||||
"Description": "Displays the hand size (total or by title for \"Dream Enhancing Serum\"), hover over it to briefly toggle counting method.\n\nAllows you to randomly discard a card from your hand.",
|
||||
"Description": "Displays the hand size (total or by title for \"Dream Enhancing Serum\"), hover over it to temporarily toggle counting method.\n\nWill detect if DES is present during each Upkeep.\n\nAllows you to randomly discard a card from your hand.",
|
||||
"DragSelectable": true,
|
||||
"GMNotes": "",
|
||||
"GUID": "450688",
|
||||
|
@ -39,27 +39,23 @@ function onLoad()
|
||||
updateColors()
|
||||
|
||||
-- start loop to update card count
|
||||
loopId = Wait.time(updateValue, 1, -1)
|
||||
Wait.time(updateValue, 1, -1)
|
||||
end
|
||||
|
||||
-- updates colors when object is dropped somewhere
|
||||
function onDrop() updateColors() end
|
||||
|
||||
-- toggles counting method briefly
|
||||
function onObjectHover(hover_color, obj)
|
||||
-- only continue if correct player hovers over "self"
|
||||
if obj ~= self or hover_color ~= handColor or hovering then return end
|
||||
-- toggles counting method while hovered
|
||||
function onObjectHover(hoverColor, object)
|
||||
if hoverColor ~= handColor then return end
|
||||
|
||||
-- toggle this flag so this doesn't get executed multiple times during the delay
|
||||
hovering = true
|
||||
|
||||
-- stop loop, toggle "des" and displayed value briefly, then start new loop after 2s
|
||||
Wait.stop(loopId)
|
||||
updateValue(true)
|
||||
Wait.time(function()
|
||||
loopId = Wait.time(updateValue, 1, -1)
|
||||
if object == self then
|
||||
hovering = true
|
||||
else
|
||||
hovering = false
|
||||
end, 1)
|
||||
end
|
||||
|
||||
updateValue()
|
||||
end
|
||||
|
||||
-- updates the matcolor and handcolor variable
|
||||
@ -70,7 +66,7 @@ function updateColors()
|
||||
end
|
||||
|
||||
-- count cards in hand (by name for DES)
|
||||
function updateValue(toggle)
|
||||
function updateValue()
|
||||
-- update colors if handColor doesn't own a handzone
|
||||
if Player[handColor].getHandCount() == 0 then
|
||||
updateColors()
|
||||
@ -80,18 +76,23 @@ function updateValue(toggle)
|
||||
if Player[handColor].getHandCount() == 0 then return end
|
||||
|
||||
-- get state of "Dream-Enhancing Serum" from playermat and update button label
|
||||
local des = playmatApi.isDES(matColor)
|
||||
if toggle then des = not des end
|
||||
self.editButton({ index = 1, label = "DES: " .. (des and "✓" or "✗") })
|
||||
local hasDES = playmatApi.hasDES(matColor)
|
||||
|
||||
-- get opposite value if currently hovered
|
||||
if hovering then
|
||||
hasDES = not hasDES
|
||||
end
|
||||
|
||||
self.editButton({ index = 1, label = "DES: " .. (hasDES and "✓" or "✗") })
|
||||
|
||||
-- count cards in hand
|
||||
local hand = Player[handColor].getHandObjects()
|
||||
local size = 0
|
||||
|
||||
if des then
|
||||
if hasDES then
|
||||
local cardHash = {}
|
||||
for _, obj in pairs(hand) do
|
||||
if obj.tag == "Card" then
|
||||
if obj.type == "Card" then
|
||||
local name = obj.getName()
|
||||
local title = string.match(name, '(.+)(%s%(%d+%))') or name
|
||||
cardHash[title] = true
|
||||
@ -102,12 +103,14 @@ function updateValue(toggle)
|
||||
end
|
||||
else
|
||||
for _, obj in pairs(hand) do
|
||||
if obj.tag == "Card" then size = size + 1 end
|
||||
if obj.type == "Card" then
|
||||
size = size + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- update button label and color
|
||||
self.editButton({ index = 0, font_color = des and "Green" or "White", label = size })
|
||||
self.editButton({ index = 0, font_color = hasDES and "Green" or "White", label = size })
|
||||
end
|
||||
|
||||
-- discards a random non-hidden card from hand
|
||||
|
@ -87,7 +87,7 @@ activeInvestigatorId = "00000"
|
||||
local isDrawButtonVisible = false
|
||||
|
||||
-- global variable to report "Dream-Enhancing Serum" status
|
||||
isDES = false
|
||||
hasDES = false
|
||||
|
||||
-- table of type-object reference pairs of all owned objects
|
||||
local ownedObjects = {}
|
||||
@ -167,14 +167,17 @@ end
|
||||
-- finds all objects on the playmat and associated set aside zone.
|
||||
function searchAroundSelf(filter)
|
||||
local bounds = self.getBoundsNormalized()
|
||||
|
||||
-- Increase the width to cover the set aside zone
|
||||
bounds.size.x = bounds.size.x + SEARCH_AROUND_SELF_X_BUFFER
|
||||
bounds.size.y = 1
|
||||
-- Since the cast is centered on the position, shift left or right to keep the non-set aside edge
|
||||
-- of the cast at the edge of the playmat
|
||||
-- setAsideDirection accounts for the set aside zone being on the left or right, depending on the
|
||||
-- table position of the playmat
|
||||
|
||||
-- 'setAsideDirection' accounts for the set aside zone being on the left or right,
|
||||
-- depending on the table position of the playmat
|
||||
local setAsideDirection = bounds.center.z > 0 and 1 or -1
|
||||
|
||||
-- Since the cast is centered on the position, shift left or right to keep
|
||||
-- the non-set aside edge of the cast at the edge of the playmat
|
||||
local localCenter = self.positionToLocal(bounds.center)
|
||||
localCenter.x = localCenter.x + setAsideDirection * SEARCH_AROUND_SELF_X_BUFFER / 2 / self.getScale().x
|
||||
return searchArea(self.positionToWorld(localCenter), bounds.size, filter)
|
||||
@ -287,8 +290,9 @@ function doUpkeep(_, clickedByColor, isRightClick)
|
||||
|
||||
updateMessageColor(clickedByColor)
|
||||
|
||||
-- unexhaust cards in play zone, flip action tokens and find forcedLearning
|
||||
-- unexhaust cards in play zone, flip action tokens and find Forced Learning / Dream-Enhancing Serum
|
||||
local forcedLearning = false
|
||||
hasDES = false
|
||||
local rot = self.getRotation()
|
||||
for _, obj in ipairs(searchAroundSelf()) do
|
||||
if obj.getDescription() == "Action Token" and obj.is_face_down then
|
||||
@ -315,9 +319,11 @@ function doUpkeep(_, clickedByColor, isRightClick)
|
||||
obj.setRotation({ rot.x, rot.y + yRotDiff, rot.z })
|
||||
end
|
||||
|
||||
-- detect forced learning to handle card drawing accordingly
|
||||
-- detect Forced Learning to handle card drawing accordingly
|
||||
if cardMetadata.id == "08031" then
|
||||
forcedLearning = true
|
||||
elseif cardMetadata.id == "06159" then
|
||||
hasDES = true
|
||||
end
|
||||
|
||||
-- maybe replenish uses on certain cards
|
||||
@ -750,9 +756,6 @@ function onCollisionEnter(collisionInfo)
|
||||
-- only continue for cards
|
||||
if object.type ~= "Card" then return end
|
||||
|
||||
-- detect if "Dream-Enhancing Serum" is placed
|
||||
if object.getName() == "Dream-Enhancing Serum" then isDES = true end
|
||||
|
||||
maybeUpdateActiveInvestigator(object)
|
||||
syncCustomizableMetadata(object)
|
||||
|
||||
@ -765,11 +768,6 @@ function onCollisionEnter(collisionInfo)
|
||||
end
|
||||
end
|
||||
|
||||
-- detect if "Dream-Enhancing Serum" is removed
|
||||
function onCollisionExit(collisionInfo)
|
||||
if collisionInfo.collision_object.getName() == "Dream-Enhancing Serum" then isDES = false end
|
||||
end
|
||||
|
||||
-- checks if tokens should be spawned for the provided card
|
||||
function shouldSpawnTokens(card)
|
||||
if card.is_face_down then
|
||||
|
@ -49,9 +49,9 @@ do
|
||||
|
||||
-- Returns if there is the card "Dream-Enhancing Serum" on the requested playmat
|
||||
---@param matColor string Color of the playmat - White, Orange, Green or Red (does not support "All")
|
||||
PlaymatApi.isDES = function(matColor)
|
||||
PlaymatApi.hasDES = function(matColor)
|
||||
for _, mat in pairs(getMatForColor(matColor)) do
|
||||
return mat.getVar("isDES")
|
||||
return mat.getVar("hasDES")
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user