diff --git a/objects/InvestigatorSkillTracker.af7ed7.json b/objects/InvestigatorSkillTracker.af7ed7.json index 9291108c..0fb9a205 100644 --- a/objects/InvestigatorSkillTracker.af7ed7.json +++ b/objects/InvestigatorSkillTracker.af7ed7.json @@ -33,8 +33,8 @@ "IgnoreFoW": false, "LayoutGroupSortIndex": 0, "Locked": true, + "LuaScript": "require(\"playermat/InvestigatorSkillTracker\")", "LuaScriptState": "[1,1,1,1]", - "LuaScript_path": "InvestigatorSkillTracker.af7ed7.ttslua", "MeasureMovement": false, "Name": "Custom_Token", "Nickname": "Investigator Skill Tracker", diff --git a/objects/InvestigatorSkillTracker.af7ed7.ttslua b/objects/InvestigatorSkillTracker.af7ed7.ttslua deleted file mode 100644 index fb3d612d..00000000 --- a/objects/InvestigatorSkillTracker.af7ed7.ttslua +++ /dev/null @@ -1 +0,0 @@ -require("playermat/InvestigatorSkillTracker") diff --git a/objects/InvestigatorSkillTracker.b4a5f7.json b/objects/InvestigatorSkillTracker.b4a5f7.json index 96e0c0ee..b39bed96 100644 --- a/objects/InvestigatorSkillTracker.b4a5f7.json +++ b/objects/InvestigatorSkillTracker.b4a5f7.json @@ -33,8 +33,8 @@ "IgnoreFoW": false, "LayoutGroupSortIndex": 0, "Locked": true, + "LuaScript": "require(\"playermat/InvestigatorSkillTracker\")", "LuaScriptState": "[1,1,1,1]", - "LuaScript_path": "InvestigatorSkillTracker.b4a5f7.ttslua", "MeasureMovement": false, "Name": "Custom_Token", "Nickname": "Investigator Skill Tracker", diff --git a/objects/InvestigatorSkillTracker.b4a5f7.ttslua b/objects/InvestigatorSkillTracker.b4a5f7.ttslua deleted file mode 100644 index fb3d612d..00000000 --- a/objects/InvestigatorSkillTracker.b4a5f7.ttslua +++ /dev/null @@ -1 +0,0 @@ -require("playermat/InvestigatorSkillTracker") diff --git a/objects/InvestigatorSkillTracker.e598c2.json b/objects/InvestigatorSkillTracker.e598c2.json index c2b58bf5..2d45c21c 100644 --- a/objects/InvestigatorSkillTracker.e598c2.json +++ b/objects/InvestigatorSkillTracker.e598c2.json @@ -33,8 +33,8 @@ "IgnoreFoW": false, "LayoutGroupSortIndex": 0, "Locked": true, + "LuaScript": "require(\"playermat/InvestigatorSkillTracker\")", "LuaScriptState": "[1,1,1,1]", - "LuaScript_path": "InvestigatorSkillTracker.e598c2.ttslua", "MeasureMovement": false, "Name": "Custom_Token", "Nickname": "Investigator Skill Tracker", diff --git a/objects/InvestigatorSkillTracker.e598c2.ttslua b/objects/InvestigatorSkillTracker.e598c2.ttslua deleted file mode 100644 index fb3d612d..00000000 --- a/objects/InvestigatorSkillTracker.e598c2.ttslua +++ /dev/null @@ -1 +0,0 @@ -require("playermat/InvestigatorSkillTracker") diff --git a/objects/InvestigatorSkillTracker.e74881.json b/objects/InvestigatorSkillTracker.e74881.json index e0e70988..a6f3386d 100644 --- a/objects/InvestigatorSkillTracker.e74881.json +++ b/objects/InvestigatorSkillTracker.e74881.json @@ -33,8 +33,8 @@ "IgnoreFoW": false, "LayoutGroupSortIndex": 0, "Locked": true, + "LuaScript": "require(\"playermat/InvestigatorSkillTracker\")", "LuaScriptState": "[1,1,1,1]", - "LuaScript_path": "InvestigatorSkillTracker.e74881.ttslua", "MeasureMovement": false, "Name": "Custom_Token", "Nickname": "Investigator Skill Tracker", diff --git a/objects/InvestigatorSkillTracker.e74881.ttslua b/objects/InvestigatorSkillTracker.e74881.ttslua deleted file mode 100644 index fb3d612d..00000000 --- a/objects/InvestigatorSkillTracker.e74881.ttslua +++ /dev/null @@ -1 +0,0 @@ -require("playermat/InvestigatorSkillTracker") diff --git a/objects/Playermat1White.8b081b.ttslua b/objects/Playermat1White.8b081b.ttslua index 6ca92838..0cfef19b 100644 --- a/objects/Playermat1White.8b081b.ttslua +++ b/objects/Playermat1White.8b081b.ttslua @@ -8,8 +8,8 @@ PLAY_ZONE_SCALE = { x = 36, y = 5.1, z = 14.5 } DRAW_DECK_POSITION = { x = -54.8, y = 2.5, z = 4.29 } DISCARD_PILE_POSITION = { x = -58.9, y = 4, z = 4.29 } -TRASHCAN = getObjectFromGUID("147e80") -STAT_TRACKER = getObjectFromGUID("e598c2") -RESOURCE_COUNTER = getObjectFromGUID("4406f0") +TRASHCAN_GUID = "147e80" +STAT_TRACKER_GUID = "e598c2" +RESOURCE_COUNTER_GUID = "4406f0" require("playermat/Playmat") diff --git a/objects/Playermat2Orange.bd0ff4.ttslua b/objects/Playermat2Orange.bd0ff4.ttslua index d33d35dc..f964b530 100644 --- a/objects/Playermat2Orange.bd0ff4.ttslua +++ b/objects/Playermat2Orange.bd0ff4.ttslua @@ -8,8 +8,8 @@ PLAY_ZONE_SCALE = { x = 36, y = 5.1, z = 14.5 } DRAW_DECK_POSITION = { x = -54.86, y = 2.5, z = -27.82 } DISCARD_PILE_POSITION = { x = -58.96, y = 4, z = -27.82 } -TRASHCAN = getObjectFromGUID("f7b6c8") -STAT_TRACKER = getObjectFromGUID("b4a5f7") -RESOURCE_COUNTER = getObjectFromGUID("816d84") +TRASHCAN_GUID = "f7b6c8" +STAT_TRACKER_GUID = "b4a5f7" +RESOURCE_COUNTER_GUID = "816d84" require("playermat/Playmat") diff --git a/objects/Playermat3Green.383d8b.ttslua b/objects/Playermat3Green.383d8b.ttslua index 4cf61742..09e4e56b 100644 --- a/objects/Playermat3Green.383d8b.ttslua +++ b/objects/Playermat3Green.383d8b.ttslua @@ -8,8 +8,8 @@ PLAY_ZONE_SCALE = { x = 30, y = 5, z = 14.5 } DRAW_DECK_POSITION = { x = -37.26, y = 2.5, z = 26.4 } DISCARD_PILE_POSITION = { x = -37.26, y = 4, z = 30.50 } -TRASHCAN = getObjectFromGUID("5f896a") -STAT_TRACKER = getObjectFromGUID("af7ed7") -RESOURCE_COUNTER = getObjectFromGUID("cd15ac") +TRASHCAN_GUID = "5f896a" +STAT_TRACKER_GUID = "af7ed7" +RESOURCE_COUNTER_GUID = "cd15ac" require("playermat/Playmat") diff --git a/objects/Playermat4Red.0840d5.ttslua b/objects/Playermat4Red.0840d5.ttslua index 7c7e5f88..eca5aa77 100644 --- a/objects/Playermat4Red.0840d5.ttslua +++ b/objects/Playermat4Red.0840d5.ttslua @@ -8,8 +8,8 @@ PLAY_ZONE_SCALE = { x = 30, y = 5, z = 14.5 } DRAW_DECK_POSITION = { x = -13.78, y = 2.5, z = -26.37 } DISCARD_PILE_POSITION = { x = -13.78, y = 4, z = -30.48 } -TRASHCAN = getObjectFromGUID("4b8594") -STAT_TRACKER = getObjectFromGUID("e74881") -RESOURCE_COUNTER = getObjectFromGUID("a4b60d") +TRASHCAN_GUID = "4b8594" +STAT_TRACKER_GUID = "e74881" +RESOURCE_COUNTER_GUID = "a4b60d" require("playermat/Playmat") diff --git a/src/playermat/Playmat.ttslua b/src/playermat/Playmat.ttslua index 890a856c..644c853e 100644 --- a/src/playermat/Playmat.ttslua +++ b/src/playermat/Playmat.ttslua @@ -1,7 +1,3 @@ ---------------------------------------------------------- --- general setup (identical for each playmat) ---------------------------------------------------------- - -- set true to enable debug logging and show Physics.cast() local DEBUG = false @@ -21,11 +17,13 @@ local DISCARD_BUTTON_OFFSETS = { } local PLAY_ZONE_ROTATION = self.getRotation() -activeInvestigatorId = "00000" ---------------------------------------------------------- --- general code (identical for each playmat) ---------------------------------------------------------- +local TRASHCAN +local STAT_TRACKER +local RESOURCE_COUNTER + +-- global variable so it can be reset by the Clean Up Helper +activeInvestigatorId = "00000" function onSave() return JSON.encode({zoneID = zoneID, playerColor = PLAYER_COLOR, activeInvestigatorId = activeInvestigatorId}) end @@ -35,6 +33,10 @@ function onLoad(save_state) PLAYER_CARDS = DATA_HELPER.getTable('PLAYER_CARD_DATA') PLAYER_CARD_TOKEN_OFFSETS = DATA_HELPER.getTable('PLAYER_CARD_TOKEN_OFFSETS') + TRASHCAN = getObjectFromGUID(TRASHCAN_GUID) + STAT_TRACKER = getObjectFromGUID(STAT_TRACKER_GUID) + RESOURCE_COUNTER = getObjectFromGUID(RESOURCE_COUNTER_GUID) + for i = 1, 6 do makeDiscardButton(DISCARD_BUTTON_OFFSETS[i], {-3.85, 3, 10.38}, i) end @@ -203,7 +205,9 @@ function doUpkeep(_, color, alt_click) if notes.uses ~= nil then local count = notes.uses[1].count local replenish = notes.uses[1].replenish - if count and replenish then replenishTokens(obj, count, replenish) end + if count and replenish then + replenishTokens(obj, count, replenish) + end end end elseif obj.getDescription() == "Action Token" and obj.is_face_down then @@ -216,9 +220,9 @@ function doUpkeep(_, color, alt_click) if activeInvestigatorId ~= nil then local miniId = string.match(activeInvestigatorId, "%d%d%d%d%d") .. "-m" for _, obj in ipairs(getObjects()) do - if obj.tag == "Card" then + if obj.tag == "Card" and obj.is_face_down then local notes = JSON.decode(obj.getGMNotes()) - if obj.is_face_down and notes ~= nil and notes.type == "Minicard" and (notes.id == miniId or notes.id == "09080-m") then + if notes ~= nil and notes.type == "Minicard" and (notes.id == miniId or notes.id == "09080-m") then obj.flip() end end @@ -236,11 +240,16 @@ function doUpkeep(_, color, alt_click) -- draw a card (with handling for Patrice and Forced Learning) if activeInvestigatorId == "06005" then - local handSize = #Player[PLAYER_COLOR].getHandObjects() - if handSize >= 5 then return end - local cardsToDraw = 5 - handSize - printToColor("Drawing " .. cardsToDraw .. " cards (Patrice)", messageColor) - drawCardsWithReshuffle(cardsToDraw) + if forcedLearning then + printToColor("Wow, did you really take 'Versatile' to play Patrice with 'Forced Learning'? Choose which draw replacement effect takes priority and draw cards accordingly.", messageColor) + else + local handSize = #Player[PLAYER_COLOR].getHandObjects() + if handSize < 5 then + local cardsToDraw = 5 - handSize + printToColor("Drawing " .. cardsToDraw .. " cards (Patrice)", messageColor) + drawCardsWithReshuffle(cardsToDraw) + end + end elseif forcedLearning then printToColor("Drawing 2 cards, discard 1 (Forced Learning)", messageColor) drawCardsWithReshuffle(2) @@ -257,7 +266,6 @@ end -- draw X cards (shuffle discards if necessary) function drawCardsWithReshuffle(numCards) - if type(numCards) ~= "number" then numCards = 1 end getDrawDiscardDecks() -- Norman Withers handling @@ -456,10 +464,8 @@ function spawnTokensFor(object) spawnTokenGroup(object, token, tokenCount) else local data = getPlayerCardData(object) - if data == nil then error('attempt to spawn tokens for ' .. object.getName() .. ': no token data') end token = data['tokenType'] tokenCount = data['tokenCount'] - log(object.getName() .. '[' .. object.getDescription() .. ']' .. ' : ' .. data['tokenType'] .. ' : ' .. data['tokenCount']) log("Spawning tokens for "..object.getName()..'['..object.getDescription()..']: '..tokenCount.."x "..token) spawnTokenGroup(object, token, tokenCount) end @@ -530,10 +536,10 @@ function maybeUpdateActiveInvestigator(card) for _, obj in ipairs(search) do local obj = obj.hit_object if obj.getDescription() == "Action Token" and obj.getStateId() > 0 then - if self.positionToLocal(obj.getPosition()).x > -0.95 then + if obj.getScale().x < 0.4 then small_token = obj else - objState(obj, state_table[notes.class]) + setObjectState(obj, state_table[notes.class]) end end end @@ -541,26 +547,26 @@ function maybeUpdateActiveInvestigator(card) -- update the small token with special action for certain investigators -- Ursula Downs: Investigate action if activeInvestigatorId == "04002" then - objState(small_token, 8) + setObjectState(small_token, 8) -- Daisy Walker (only for normal front, not parallel): Tome action - elseif activeInvestigatorId == "01002" or activeInvestigatorId == "01002-r" or activeInvestigatorId == "01002-pb" then - objState(small_token, 9) + elseif activeInvestigatorId == "01002" or activeInvestigatorId == "01502" or activeInvestigatorId == "01002-pb" then + setObjectState(small_token, 9) -- Tony Morgan: Engage/Fight action elseif activeInvestigatorId == "06003" then - objState(small_token, 10) + setObjectState(small_token, 10) -- Finn Edwards: Evade action elseif activeInvestigatorId == "04003" then - objState(small_token, 11) + setObjectState(small_token, 11) -- Bob Jenkins: Play Item action elseif activeInvestigatorId == "08016" then - objState(small_token, 14) + setObjectState(small_token, 14) else - objState(small_token, state_table[notes.class]) + setObjectState(small_token, state_table[notes.class]) end end end -function objState(obj, stateId) +function setObjectState(obj, stateId) if obj.getStateId() ~= stateId then obj.setState(stateId) end end @@ -580,6 +586,8 @@ function spawnToken(position, tokenType) Global.call('spawnToken', {position, tokenType, PLAY_ZONE_ROTATION}) end +-- called by custom data helpers to add player card data +---@param args table Contains only one entry, the GUID of the custom data helper function updatePlayerCards(args) local custom_data_helper = getObjectFromGUID(args[1]) data_player_cards = custom_data_helper.getTable("PLAYER_CARD_DATA")