Skip to content

Commit

Permalink
Fixed some tag search bugs, and added unlock support to old spawner
Browse files Browse the repository at this point in the history
  • Loading branch information
devyndamonster committed Feb 13, 2022
1 parent 58c0e5d commit 062621f
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 21 deletions.
19 changes: 19 additions & 0 deletions Scripts/ObjectTemplates/UnlockedItemSaveData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,21 @@ public class UnlockedItemSaveData
{
public bool UnlockAll = false;
public bool AutoUnlockNonRewards = true;
public ItemUnlockMode UnlockMode;
public List<string> UnlockedItemIDs = new List<string>();

public UnlockedItemSaveData() { }

public UnlockedItemSaveData(ItemUnlockMode unlockMode)
{
UnlockMode = unlockMode;

if(unlockMode == ItemUnlockMode.Unlockathon)
{
AutoUnlockNonRewards = false;
}
}

public bool IsItemUnlocked(string itemID)
{
return UnlockAll || UnlockedItemIDs.Contains(itemID);
Expand All @@ -27,4 +40,10 @@ public bool UnlockItem(string itemID)
return false;
}
}

public enum ItemUnlockMode
{
Normal,
Unlockathon
}
}
16 changes: 15 additions & 1 deletion Scripts/OtherLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class OtherLoader : StratumPlugin
public static ConfigEntry<bool> EnableLogging;
public static ConfigEntry<bool> LogLoading;
public static ConfigEntry<bool> AddUnloadButton;
public static ConfigEntry<ItemUnlockMode> UnlockMode;

public static int MaxActiveLoaders = 0;

Expand Down Expand Up @@ -120,6 +121,13 @@ private void LoadConfigFile()
"When true, and sodalite is installed, you'll have a wristmenu button that unloads all modded asset bundles for testing"
);

UnlockMode = Config.Bind(
"General",
"UnlockMode",
ItemUnlockMode.Normal,
"When set to Unlockathon, all items will start out locked, and you must unlock items by finding them in game"
);


MaxActiveLoaders = MaxActiveLoadersConfig.Value;
}
Expand All @@ -134,7 +142,8 @@ private void InitUnlockSaveData()

if (!File.Exists(UnlockedItemSaveDataPath))
{
UnlockSaveData = new UnlockedItemSaveData();
UnlockSaveData = new UnlockedItemSaveData(UnlockMode.Value);

SaveUnlockedItemsData();
}

Expand All @@ -151,6 +160,11 @@ public static void LoadUnlockedItemsData()
{
string unlockJson = File.ReadAllText(UnlockedItemSaveDataPath);
UnlockSaveData = JsonConvert.DeserializeObject<UnlockedItemSaveData>(unlockJson);

if(UnlockSaveData.UnlockMode != UnlockMode.Value)
{
UnlockSaveData = new UnlockedItemSaveData(UnlockMode.Value);
}
}
catch (Exception ex)
{
Expand Down
96 changes: 96 additions & 0 deletions Scripts/Patches/ItemSpawnerPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,102 @@ private static bool DrawTilesCategoryPatch(ItemSpawnerID.EItemCategory Category,
}


[HarmonyPatch(typeof(ItemSpawnerUI), "Draw_Tiles_SubCategory")]
[HarmonyPrefix]
private static bool DrawTilesSubCategoryPatch(ItemSpawnerID.ESubCategory SubCategory, ItemSpawnerUI __instance)
{
int num = 0;
bool sandboxMode = !GM.CurrentSceneSettings.UsesUnlockSystem;
List<ItemSpawnerID> availableInSubCategory = IM.GetAvailableInSubCategory(SubCategory);

for (int i = __instance.m_curPage * 10; i < availableInSubCategory.Count; i++)
{
if (num < Mathf.Min(10 + __instance.m_curPage * 10, 10))
{

//Handle the case where the item is not unlocked globally
if(availableInSubCategory[i].MainObject != null &&
!OtherLoader.UnlockSaveData.IsItemUnlocked(availableInSubCategory[i].MainObject.ItemID))
{
__instance.Tiles_SelectionPage[num].gameObject.SetActive(true);
__instance.Tiles_SelectionPage[num].Image.sprite = OtherLoader.LockIcon;
__instance.Tiles_SelectionPage[num].Text.text = "???";
__instance.Tiles_SelectionPage[num].Item = availableInSubCategory[i];

__instance.Tiles_SelectionPage[num].IsSpawnable = false;
__instance.Tiles_SelectionPage[num].LockedCorner.gameObject.SetActive(false);

}

//If item is unlocked globally, just perform normal logic
else
{
__instance.Tiles_SelectionPage[num].gameObject.SetActive(true);
__instance.Tiles_SelectionPage[num].Image.sprite = availableInSubCategory[i].Sprite;
__instance.Tiles_SelectionPage[num].Text.text = availableInSubCategory[i].DisplayName;
__instance.Tiles_SelectionPage[num].Item = availableInSubCategory[i];

if (GM.Omni.OmniUnlocks.IsEquipmentUnlocked(__instance.Tiles_SelectionPage[num].Item, sandboxMode))
{
__instance.Tiles_SelectionPage[num].IsSpawnable = true;
__instance.Tiles_SelectionPage[num].LockedCorner.gameObject.SetActive(false);
}
else
{
__instance.Tiles_SelectionPage[num].IsSpawnable = false;
__instance.Tiles_SelectionPage[num].LockedCorner.gameObject.SetActive(true);
}
}

num++;
}
}
for (int j = num; j < __instance.Tiles_SelectionPage.Length; j++)
{
__instance.Tiles_SelectionPage[j].gameObject.SetActive(false);
}

return false;
}



[HarmonyPatch(typeof(ItemSpawnerUI), "ButtonPress_SelectionTile")]
[HarmonyPrefix]
private static bool SelectTilePatch(int i, ItemSpawnerUI __instance)
{
if (__instance.refireTick > 0f)
{
return false;
}
__instance.ButtonPress(0);
switch (__instance.m_curMode)
{
case ItemSpawnerUI.ItemSpawnerPageMode.Home:
__instance.m_curCategory = __instance.Tiles_SelectionPage[i].Category;
__instance.SetMode_Category();
break;
case ItemSpawnerUI.ItemSpawnerPageMode.Category:
__instance.m_curSubCategory = __instance.Tiles_SelectionPage[i].SubCategory;
__instance.SetMode_SubCategory();
break;
case ItemSpawnerUI.ItemSpawnerPageMode.SubCategory:

if(__instance.Tiles_SelectionPage[i].Item.MainObject != null &&
OtherLoader.UnlockSaveData.IsItemUnlocked(__instance.Tiles_SelectionPage[i].Item.MainObject.ItemID))
{
__instance.m_curID = __instance.Tiles_SelectionPage[i].Item;
__instance.m_IDSelectedForSpawn = __instance.Tiles_SelectionPage[i].Item;
__instance.SetMode_Details();
}

break;
}

return false;
}



[HarmonyPatch(typeof(ItemSpawnerUI), "ButtonPress_Next")]
[HarmonyPrefix]
Expand Down
37 changes: 17 additions & 20 deletions Scripts/Patches/ItemSpawnerV2Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,15 @@ private static bool RedrawListPatch(ItemSpawnerV2 __instance)

private static Dictionary<FVRObject, ItemSpawnerEntry> GetEntryPairsFromQuery(List<string> itemIDs, Dictionary<TagType, List<string>> tagQuery)
{
/*
OtherLogger.Log("Performing Tag Saerch!", OtherLogger.LogType.General);
foreach (KeyValuePair<TagType, List<string>> pair in tagQuery)
{
OtherLogger.Log("Tag Type: " + pair.Key.ToString() + ", Values: " + String.Join(",", pair.Value.ToArray()), OtherLogger.LogType.General);
}
*/

//Create a dictionary and populate it with items that have an FVRObject and a spawner entry
Dictionary<FVRObject, ItemSpawnerEntry> entryDic = new Dictionary<FVRObject, ItemSpawnerEntry>();
for (int i = 0; i < itemIDs.Count; i++)
Expand Down Expand Up @@ -768,8 +777,6 @@ private static Dictionary<FVRObject, ItemSpawnerEntry> GetEntryPairsFromQuery(Li

else if (item.Category == FVRObject.ObjectCategory.Attachment && !ShouldIncludeAttachment(item, tagQuery)) continue;

else if (item.Category == FVRObject.ObjectCategory.Magazine && !ShouldIncludeMagazine(item, tagQuery)) continue;

entryDic[item] = entry;
}

Expand All @@ -787,6 +794,14 @@ private static bool ShouldIncludeGeneral(FVRObject item, ItemSpawnerEntry entry,

if (tagQuery[TagType.ModTag].Count > 0 && !entry.ModTags.Any(o => tagQuery[TagType.ModTag].Contains(o.ToString()))) return false;

if (tagQuery[TagType.Caliber].Count > 0 && (!item.UsesRoundTypeFlag || !tagQuery[TagType.Caliber].Contains(item.RoundType.ToString()))) return false;

if (tagQuery[TagType.MagazineType].Count > 0 && !tagQuery[TagType.MagazineType].Contains(item.MagazineType.ToString())) return false;

if (tagQuery[TagType.CountryOfOrigin].Count > 0 && !tagQuery[TagType.CountryOfOrigin].Contains(item.TagFirearmCountryOfOrigin.ToString())) return false;

if (tagQuery[TagType.IntroductionYear].Count > 0 && !tagQuery[TagType.IntroductionYear].Contains(item.TagFirearmFirstYear.ToString())) return false;

return true;
}

Expand All @@ -798,14 +813,6 @@ private static bool ShouldIncludeFirearm(FVRObject item, Dictionary<TagType, Lis

if (tagQuery[TagType.RoundClass].Count > 0 && !tagQuery[TagType.RoundClass].Contains(item.TagFirearmRoundPower.ToString())) return false;

if (tagQuery[TagType.CountryOfOrigin].Count > 0 && !tagQuery[TagType.CountryOfOrigin].Contains(item.TagFirearmCountryOfOrigin.ToString())) return false;

if (tagQuery[TagType.IntroductionYear].Count > 0 && !tagQuery[TagType.IntroductionYear].Contains(item.TagFirearmFirstYear.ToString())) return false;

if (tagQuery[TagType.MagazineType].Count > 0 && !tagQuery[TagType.MagazineType].Contains(item.MagazineType.ToString())) return false;

if (tagQuery[TagType.Caliber].Count > 0 && (!item.UsesRoundTypeFlag || !tagQuery[TagType.Caliber].Contains(item.RoundType.ToString()))) return false;

if (tagQuery[TagType.FiringMode].Count > 0 && !item.TagFirearmFiringModes.Any(o => tagQuery[TagType.FiringMode].Contains(o.ToString()))) return false;

if (tagQuery[TagType.FeedOption].Count > 0 && !item.TagFirearmFeedOption.Any(o => tagQuery[TagType.FeedOption].Contains(o.ToString()))) return false;
Expand All @@ -815,7 +822,6 @@ private static bool ShouldIncludeFirearm(FVRObject item, Dictionary<TagType, Lis
return true;
}


private static bool ShouldIncludeAttachment(FVRObject item, Dictionary<TagType, List<string>> tagQuery)
{
if (tagQuery[TagType.AttachmentFeature].Count > 0 && !tagQuery[TagType.AttachmentFeature].Contains(item.TagAttachmentFeature.ToString())) return false;
Expand All @@ -826,15 +832,6 @@ private static bool ShouldIncludeAttachment(FVRObject item, Dictionary<TagType,
}


private static bool ShouldIncludeMagazine(FVRObject item, Dictionary<TagType, List<string>> tagQuery)
{
if (tagQuery[TagType.MagazineType].Count > 0 && !tagQuery[TagType.MagazineType].Contains(item.MagazineType.ToString())) return false;

return true;
}






Expand Down

0 comments on commit 062621f

Please sign in to comment.