From 547d79a7da19b79c493d9ce6a7317896c27f38c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nil256=20=28=E3=81=AB=E3=82=8B=E3=81=AB=E3=81=93=E3=82=8D?= =?UTF-8?q?=29?= <95995630+Fennene@users.noreply.github.com> Date: Sat, 8 Oct 2022 17:02:53 +0900 Subject: [PATCH 1/6] Add Hook "IsItemFindable" to ItemChecklist.cs --- ItemChecklist.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ItemChecklist.cs b/ItemChecklist.cs index 85f2445..988715b 100644 --- a/ItemChecklist.cs +++ b/ItemChecklist.cs @@ -21,6 +21,7 @@ public class ItemChecklist : Mod internal static UserInterface ItemChecklistInterface; internal ItemChecklistUI ItemChecklistUI; internal event Action OnNewItem; + internal event Func OnIsItemFindable; public override void Load() { @@ -85,6 +86,12 @@ public override object Call(params object[] args) OnNewItem += callback; return "RegisterSuccess"; } + else if (message == "RegisterForIsItemFindable") + { + Func blackListChecker = args[1] as Func; + OnIsItemFindable += blackListChecker; + return "RegisterSuccess"; + } else { Logger.Error("ItemChecklist Call Error: Unknown Message: " + message); @@ -101,6 +108,11 @@ internal void NewItem(int type) { OnNewItem?.Invoke(type); } + + internal void IsItemFindable(int type, Player player) + { + OnIsItemFindable?.Invoke(type, player); + } } public class ItemChecklistSystem : ModSystem From bbc347d1915d6a192c2117ffaf1edb72c27d8d2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nil256=20=28=E3=81=AB=E3=82=8B=E3=81=AB=E3=81=93=E3=82=8D?= =?UTF-8?q?=29?= <95995630+Fennene@users.noreply.github.com> Date: Sat, 8 Oct 2022 17:04:54 +0900 Subject: [PATCH 2/6] Invoke IsItemFindable() in ItemChecklistPlayer --- ItemChecklistPlayer.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ItemChecklistPlayer.cs b/ItemChecklistPlayer.cs index 9835804..7ffd8f3 100644 --- a/ItemChecklistPlayer.cs +++ b/ItemChecklistPlayer.cs @@ -62,6 +62,13 @@ public override void OnEnterWorld(Player player) ItemChecklistUI.showCompleted = showCompletedPreference; ItemChecklist.instance.ItemChecklistUI.RefreshPreferences(); ItemChecklist.instance.ItemChecklistUI.UpdateNeeded(); + for (var i = 0; i < ItemLoader.ItemCount; i++) + { + if (!ItemChecklist.instance.IsItemFindable(i, player)) + { + findableItems[i] = false; + } + } } // Do I need to use Initialize? I think so because of cloning. From 85110b477c5e38729e6a93a7f94852c7ff41bf86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nil256=20=28=E3=81=AB=E3=82=8B=E3=81=AB=E3=81=93=E3=82=8D?= =?UTF-8?q?=29?= <95995630+Fennene@users.noreply.github.com> Date: Sat, 8 Oct 2022 17:14:10 +0900 Subject: [PATCH 3/6] Fix Hook "IsItemFindable", return boolean --- ItemChecklist.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ItemChecklist.cs b/ItemChecklist.cs index 988715b..5819bb9 100644 --- a/ItemChecklist.cs +++ b/ItemChecklist.cs @@ -109,9 +109,13 @@ internal void NewItem(int type) OnNewItem?.Invoke(type); } - internal void IsItemFindable(int type, Player player) + internal bool IsItemFindable(int type, Player player) { - OnIsItemFindable?.Invoke(type, player); + if (OnIsItemFindable == null) + { + return true; + } + return OnIsItemFindable.Invoke(type, player); } } From 531835d3744b8ab8b66b9127638fa3f7aa1b8fd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nil256=20=28=E3=81=AB=E3=82=8B=E3=81=AB=E3=81=93=E3=82=8D?= =?UTF-8?q?=29?= <95995630+Fennene@users.noreply.github.com> Date: Sat, 8 Oct 2022 21:06:35 +0900 Subject: [PATCH 4/6] Add ModCall "ModifyFindableFlag" and "IsFindable" --- ItemChecklist.cs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/ItemChecklist.cs b/ItemChecklist.cs index 5819bb9..37cc1dd 100644 --- a/ItemChecklist.cs +++ b/ItemChecklist.cs @@ -92,6 +92,26 @@ public override object Call(params object[] args) OnIsItemFindable += blackListChecker; return "RegisterSuccess"; } + else if (message == "ModifyFindableFlag") + { + if (Main.gameMenu) + { + return "NotInGame"; + } + int type = args[1] as int; + bool findable = args[2] as bool; + Main.LocalPlayer.GetModPlayer().findableItems[type] = findable; + return "ModifySuccess"; + } + else if (message == "IsFindable") + { + if (Main.gameMenu) + { + return null; + } + int type = args[1] as int; + return Main.LocalPlayer.GetModPlayer().findableItems[type]; + } else { Logger.Error("ItemChecklist Call Error: Unknown Message: " + message); From 9f7184e6a9cef560277fc8a3e03e0ecd2a16a7c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nil256=20=28=E3=81=AB=E3=82=8B=E3=81=AB=E3=81=93=E3=82=8D?= =?UTF-8?q?=29?= <95995630+Fennene@users.noreply.github.com> Date: Sat, 8 Oct 2022 21:18:19 +0900 Subject: [PATCH 5/6] Another method "RegisterUnfindableItems" 01 --- ItemChecklist.cs | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/ItemChecklist.cs b/ItemChecklist.cs index 37cc1dd..cf06278 100644 --- a/ItemChecklist.cs +++ b/ItemChecklist.cs @@ -21,13 +21,14 @@ public class ItemChecklist : Mod internal static UserInterface ItemChecklistInterface; internal ItemChecklistUI ItemChecklistUI; internal event Action OnNewItem; - internal event Func OnIsItemFindable; + internal List UnfindableItems; public override void Load() { // Latest uses ItemID.Sets.IsAMaterial, added 0.10.1.5 instance = this; ToggleChecklistHotKey = KeybindLoader.RegisterKeybind(this, "Toggle Item Checklist", "I"); + UnfindableItems = new List(); MagicStorageIntegration.Load(); if (!Main.dedServ) @@ -45,6 +46,7 @@ public override void Unload() instance = null; ToggleChecklistHotKey = null; ItemChecklistInterface = null; + UnfindableItems = null; MagicStorageIntegration.Unload(); UIElements.UICheckbox.checkboxTexture = null; @@ -86,10 +88,20 @@ public override object Call(params object[] args) OnNewItem += callback; return "RegisterSuccess"; } - else if (message == "RegisterForIsItemFindable") + else if (message == "RegisterUnfindableItems") { - Func blackListChecker = args[1] as Func; - OnIsItemFindable += blackListChecker; + int[] unfindableItems = args[1] as int[]; + for (var i = 0; i < unfindableItems; i++) + { + if (unfindableItems[i] < 0 || unfindableItems[i] > ItemLoader.ItemCount) + { + throw new IndexOutOfRangeException("Attempted to register item type out of range"); + } + if (!UnfindableItems.Contains(unfindableItems[i]) + { + UnfindableItems.Add(unfindableItems[i]); + } + } return "RegisterSuccess"; } else if (message == "ModifyFindableFlag") @@ -128,15 +140,6 @@ internal void NewItem(int type) { OnNewItem?.Invoke(type); } - - internal bool IsItemFindable(int type, Player player) - { - if (OnIsItemFindable == null) - { - return true; - } - return OnIsItemFindable.Invoke(type, player); - } } public class ItemChecklistSystem : ModSystem From 6b86c1e8ac798912b6449e4deb67e15ff9782081 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nil256=20=28=E3=81=AB=E3=82=8B=E3=81=AB=E3=81=93=E3=82=8D?= =?UTF-8?q?=29?= <95995630+Fennene@users.noreply.github.com> Date: Sat, 8 Oct 2022 21:20:17 +0900 Subject: [PATCH 6/6] Another method "RegisterUnfindableItems" 02 --- ItemChecklistPlayer.cs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/ItemChecklistPlayer.cs b/ItemChecklistPlayer.cs index 7ffd8f3..0657e99 100644 --- a/ItemChecklistPlayer.cs +++ b/ItemChecklistPlayer.cs @@ -62,13 +62,6 @@ public override void OnEnterWorld(Player player) ItemChecklistUI.showCompleted = showCompletedPreference; ItemChecklist.instance.ItemChecklistUI.RefreshPreferences(); ItemChecklist.instance.ItemChecklistUI.UpdateNeeded(); - for (var i = 0; i < ItemLoader.ItemCount; i++) - { - if (!ItemChecklist.instance.IsItemFindable(i, player)) - { - findableItems[i] = false; - } - } } // Do I need to use Initialize? I think so because of cloning. @@ -81,7 +74,7 @@ public override void Initialize() findableItems = new bool[ItemLoader.ItemCount]; for (int i = 0; i < ItemLoader.ItemCount; i++) { - if (i > 0 && !ItemID.Sets.Deprecated[i] && ItemLoader.GetItem(i) is not Terraria.ModLoader.Default.UnloadedItem && ItemChecklistUI.vanillaIDsInSortOrder != null && ItemChecklistUI.vanillaIDsInSortOrder[i] != -1) // TODO, is this guaranteed? + if (i > 0 && !ItemID.Sets.Deprecated[i] && ItemLoader.GetItem(i) is not Terraria.ModLoader.Default.UnloadedItem && ItemChecklistUI.vanillaIDsInSortOrder != null && ItemChecklistUI.vanillaIDsInSortOrder[i] != -1 && !ItemChecklist.instance.UnfindableItems.Contains(i)) // TODO, is this guaranteed? { totalItemsToFind++; findableItems[i] = true;