auto-remove tokens

This commit is contained in:
Chr1Z93 2023-04-03 12:56:47 +02:00
parent dce5c1749b
commit 7b8750a178
2 changed files with 27 additions and 1 deletions

1
SCED.wiki Submodule

@ -0,0 +1 @@
Subproject commit 01065bfc202457c2c2edc4e8fa9a2385a4e3ecd5

View File

@ -567,6 +567,7 @@ function onCollisionEnter(collision_info)
if isInDeckZone(object) then if isInDeckZone(object) then
tokenManager.resetTokensSpawned(object) tokenManager.resetTokensSpawned(object)
removeTokensFromObject(object)
elseif shouldSpawnTokens(object) then elseif shouldSpawnTokens(object) then
spawnTokensFor(object) spawnTokensFor(object)
end end
@ -577,28 +578,35 @@ function onCollisionExit(collision_info)
if collision_info.collision_object.getName() == "Dream-Enhancing Serum" then isDES = false end if collision_info.collision_object.getName() == "Dream-Enhancing Serum" then isDES = false end
end end
-- checks if tokens should be spawned for the provided card
function shouldSpawnTokens(card) function shouldSpawnTokens(card)
if card.is_face_down then if card.is_face_down then
return false return false
end end
local localCardPos = self.positionToLocal(card.getPosition()) local localCardPos = self.positionToLocal(card.getPosition())
local metadata = JSON.decode(card.getGMNotes()) local metadata = JSON.decode(card.getGMNotes())
-- If no metadata we don't know the type, so only spawn in the main area -- If no metadata we don't know the type, so only spawn in the main area
if metadata == nil then if metadata == nil then
return inArea(localCardPos, MAIN_PLAY_AREA) return inArea(localCardPos, MAIN_PLAY_AREA)
end end
-- Spawn tokens for assets and events on the main area, and all encounter types in the threat area
-- Spawn tokens for assets and events on the main area
if inArea(localCardPos, MAIN_PLAY_AREA) if inArea(localCardPos, MAIN_PLAY_AREA)
and (metadata.type == "Asset" and (metadata.type == "Asset"
or metadata.type == "Event") then or metadata.type == "Event") then
return true return true
end end
-- Spawn tokens for all encounter types in the threat area
if inArea(localCardPos, THREAT_AREA) if inArea(localCardPos, THREAT_AREA)
and (metadata.type == "Treachery" and (metadata.type == "Treachery"
or metadata.type == "Enemy" or metadata.type == "Enemy"
or metadata.weakness) then or metadata.weakness) then
return true return true
end end
return false return false
end end
@ -609,14 +617,17 @@ end
function resetTokensIfInDeckZone(container, object) function resetTokensIfInDeckZone(container, object)
if isInDeckZone(container) then if isInDeckZone(container) then
tokenManager.resetTokensSpawned(object) tokenManager.resetTokensSpawned(object)
removeTokensFromObject(container)
end end
end end
-- checks if an object is in this mats deckzone
function isInDeckZone(checkObject) function isInDeckZone(checkObject)
local deckZone = getObjectFromGUID(zoneID) local deckZone = getObjectFromGUID(zoneID)
if deckZone == nil then if deckZone == nil then
return false return false
end end
for _, obj in ipairs(deckZone.getObjects()) do for _, obj in ipairs(deckZone.getObjects()) do
if obj == checkObject then if obj == checkObject then
return true return true
@ -626,6 +637,20 @@ function isInDeckZone(checkObject)
return false return false
end end
-- removes tokens from the provided card/deck
function removeTokensFromObject(object)
for _, v in ipairs(searchArea(object.getPosition(), { 3, 1, 4 })) do
local obj = v.hit_object
if obj.getGUID() ~= "4ee1f2" and
obj ~= self and
obj.type ~= "Deck" and
obj.type ~= "Card" and
not tokenChecker.isChaosToken(obj) then
TRASHCAN.putObject(obj)
end
end
end
--------------------------------------------------------- ---------------------------------------------------------
-- investigator ID grabbing and skill tracker -- investigator ID grabbing and skill tracker
--------------------------------------------------------- ---------------------------------------------------------