diff --git a/scripts/autotracking/archipelago.lua b/scripts/autotracking/archipelago.lua index 6ce5e55..792e1ad 100644 --- a/scripts/autotracking/archipelago.lua +++ b/scripts/autotracking/archipelago.lua @@ -22,6 +22,11 @@ CUR_INDEX = -1 LOCAL_ITEMS = {} GLOBAL_ITEMS = {} +ALL_LOCATIONS = {} + +MANUAL_CHECKED = true +ROOM_SEED = "default" + -- gets the data storage key for hints for the current player -- returns nil when not connected to AP function getHintDataStorageKey() @@ -104,6 +109,40 @@ function apply_slot_data(slot_data) -- put any code here that slot_data should affect (toggling setting items for example) end +function preOnClear() + PLAYER_ID = Archipelago.PlayerNumber or -1 + TEAM_NUMBER = Archipelago.TeamNumber or 0 + if Archipelago.PlayerNumber > -1 then + if #ALL_LOCATIONS > 0 then + ALL_LOCATIONS = {} + end + for _, value in pairs(Archipelago.MissingLocations) do + table.insert(ALL_LOCATIONS, #ALL_LOCATIONS + 1, value) + end + + for _, value in pairs(Archipelago.CheckedLocations) do + table.insert(ALL_LOCATIONS, #ALL_LOCATIONS + 1, value) + end + end + + local custom_storage_item = Tracker:FindObjectForCode("manual_location_storage") + local seed_base = (Archipelago.Seed or tostring(#ALL_LOCATIONS)).."_"..Archipelago.TeamNumber.."_"..Archipelago.PlayerNumber + if ROOM_SEED == "default" or ROOM_SEED ~= seed_base then -- seed is default or from previous connection + + ROOM_SEED = seed_base + if #custom_storage_item.ItemState.MANUAL_LOCATIONS > 10 then + custom_storage_item.ItemState.MANUAL_LOCATIONS[custom_storage_item.ItemState.MANUAL_LOCATIONS_ORDER[1]] = nil + table.remove(custom_storage_item.ItemState.MANUAL_LOCATIONS_ORDER, 1) + end + if custom_storage_item.ItemState.MANUAL_LOCATIONS[ROOM_SEED] == nil then + custom_storage_item.ItemState.MANUAL_LOCATIONS[ROOM_SEED] = {} + table.insert(custom_storage_item.ItemState.MANUAL_LOCATIONS_ORDER, ROOM_SEED) + end + else -- seed is from previous connection + -- do nothing + end +end + -- called right after an AP slot is connected function onClear(slot_data) -- use bulk update to pause logic updates until we are done resetting all items/locations @@ -111,6 +150,15 @@ function onClear(slot_data) if AUTOTRACKER_ENABLE_DEBUG_LOGGING_AP then print(string.format("called onClear, slot_data:\n%s", dump_table(slot_data))) end + + MANUAL_CHECKED = false + local custom_storage_item = Tracker:FindObjectForCode("manual_location_storage") + if custom_storage_item == nil then + CreateLuaManualLocationStorage("manual_location_storage") + custom_storage_item = Tracker:FindObjectForCode("manual_location_storage") + end + preOnClear() + CUR_INDEX = -1 -- reset locations for _, mapping_entry in pairs(LOCATION_MAPPING) do @@ -124,7 +172,11 @@ function onClear(slot_data) if location_code:sub(1, 1) == "@" then local obj = Tracker:FindObjectForCode(location_code) if obj then - obj.AvailableChestCount = obj.ChestCount + if custom_storage_item.ItemState.MANUAL_LOCATIONS[ROOM_SEED][obj.FullID] then + obj.AvailableChestCount = custom_storage_item.ItemState.MANUAL_LOCATIONS[ROOM_SEED][obj.FullID] + else + obj.AvailableChestCount = obj.ChestCount + end if obj.Highlight then obj.Highlight = Highlight.None end @@ -178,6 +230,7 @@ function onClear(slot_data) -- gets the current value for the data storage keys -- triggers callback in the Retrieved handler when result is received Archipelago:Get(data_strorage_keys) + MANUAL_CHECKED = true Tracker.BulkUpdate = false end @@ -237,10 +290,12 @@ function onItem(index, item_id, item_name, player_number) if PopVersion < "0.20.1" or AutoTracker:GetConnectionState("SNES") == 3 then -- add snes interface functions for local item tracking here end + MANUAL_CHECKED = true end -- called when a location gets cleared function onLocation(location_id, location_name) + MANUAL_CHECKED = false if AUTOTRACKER_ENABLE_DEBUG_LOGGING_AP then print(string.format("called onLocation: %s, %s", location_id, location_name)) end diff --git a/scripts/custom_items/manual_marked_storage.lua b/scripts/custom_items/manual_marked_storage.lua new file mode 100644 index 0000000..2e393a1 --- /dev/null +++ b/scripts/custom_items/manual_marked_storage.lua @@ -0,0 +1,62 @@ +local function SaveManualLocationStorageFunc(self) -- executed on pack close or during export for each item + return { + MANUAL_LOCATIONS = self.ItemState.MANUAL_LOCATIONS, + MANUAL_LOCATIONS_ORDER = self.ItemState.MANUAL_LOCATIONS_ORDER, + Name = self.Name, + Icon = self.Icon + } +end + +local function LoadManualLocationStorageFunc(self, data) --executed on pack load + if data ~= nil and self.Name == data.Name then + self.ItemState.MANUAL_LOCATIONS = data.MANUAL_LOCATIONS + self.ItemState.MANUAL_LOCATIONS_ORDER = data.MANUAL_LOCATIONS_ORDER + self.Icon = ImageReference:FromPackRelativePath(data.Icon) + else + end +end + +local function OnLeftClickFunc(self) +end +local function OnRightClickFunc(self) +end +local function OnMiddleClickFunc(self) +end + +local function CanProvideCodeFunc(self, code) + return code == self.Name +end + +local function ProvidesCodeFunc(self, code) + if CanProvideCodeFunc(self, code) then + return 1 + end + return 0 +end + +function CreateLuaManualLocationStorage(name) + local self = ScriptHost:CreateLuaItem() + + self.Name = name --code -- + self.Icon = ImageReference:FromPackRelativePath("/images/items/closed_Chest.png") + self.ItemState = { + MANUAL_LOCATIONS = { + ["default"] = {} + }, + MANUAL_LOCATIONS_ORDER = {} + } + + self.CanProvideCodeFunc = CanProvideCodeFunc + self.OnLeftClickFunc = OnLeftClickFunc + self.OnRightClickFunc = OnRightClickFunc + self.OnMiddleClickFunc = OnMiddleClickFunc + self.ProvidesCodeFunc = ProvidesCodeFunc + -- self.AdvanceToCodeFunc = AdvanceToCodeFunc + self.SaveFunc = SaveManualLocationStorageFunc + self.LoadFunc = LoadManualLocationStorageFunc + -- self.PropertyChangedFunc = PropertyChangedFunc + -- self.ItemState = ItemState + return self +end + +CreateLuaManualLocationStorage("manual_location_storage") \ No newline at end of file diff --git a/scripts/init.lua b/scripts/init.lua index ba208d4..35409ed 100644 --- a/scripts/init.lua +++ b/scripts/init.lua @@ -22,6 +22,7 @@ ScriptHost:LoadScript("scripts/logic/logic.lua") ScriptHost:LoadScript("scripts/custom_items/class.lua") ScriptHost:LoadScript("scripts/custom_items/progressiveTogglePlus.lua") ScriptHost:LoadScript("scripts/custom_items/progressiveTogglePlusWrapper.lua") +ScriptHost:LoadScript("scripts/custom_items/manual_marked_storage.lua") -- Items Tracker:AddItems("items/items.jsonc") @@ -42,3 +43,5 @@ Tracker:AddLayouts("layouts/broadcast.jsonc") if PopVersion and PopVersion >= "0.18.0" then ScriptHost:LoadScript("scripts/autotracking.lua") end + +ScriptHost:AddOnLocationSectionChangedHandler("location_section_change_handler", LocationHandler) diff --git a/scripts/logic/logic.lua b/scripts/logic/logic.lua index 3100d0d..596e458 100644 --- a/scripts/logic/logic.lua +++ b/scripts/logic/logic.lua @@ -12,4 +12,27 @@ function has_more_then_n_consumable(n) return 1 -- 1 => access is in logic end return 0 -- 0 => no access +end + +-- handler function for the custom lua item that stores manually marked off locations +function LocationHandler(location) + if MANUAL_CHECKED then + local custom_storage_item = Tracker:FindObjectForCode("manual_location_storage") + if not custom_storage_item then + return + end + if Archipelago.PlayerNumber == -1 then -- not connected + if ROOM_SEED ~= "default" then -- seed is from previous connection + ROOM_SEED = "default" + custom_storage_item.ItemState.MANUAL_LOCATIONS["default"] = {} + else -- seed is default + end + end + local full_path = location.FullID + if location.AvailableChestCount < location.ChestCount then --add to list + custom_storage_item.ItemState.MANUAL_LOCATIONS[ROOM_SEED][full_path] = location.AvailableChestCount + else --remove from list or set back to max chestcount + custom_storage_item.ItemState.MANUAL_LOCATIONS[ROOM_SEED][full_path] = nil + end + end end \ No newline at end of file