Merge pull request #248 from argonui/remove-tokens-from-discard
Automatically remove tokens on discarded cards
This commit is contained in:
commit
6ea4e6f0dc
@ -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,21 @@ 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
|
||||||
|
-- don't remove the table surface, self, any decks/cards or chaos tokens
|
||||||
|
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
|
||||||
---------------------------------------------------------
|
---------------------------------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user