Skip to content

Commit

Permalink
chore: code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
xhayper committed Jun 16, 2024
1 parent f5b0f71 commit 0f98211
Show file tree
Hide file tree
Showing 15 changed files with 194 additions and 196 deletions.
20 changes: 10 additions & 10 deletions COTL_API/CustomFollowerCommand/CustomFollowerCommandPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,35 @@ public partial class CustomFollowerCommandManager
[HarmonyPrefix]
private static bool CommandItem_GetTitle(CommandItem __instance, Follower follower, ref string __result)
{
if (!CustomFollowerCommandList.ContainsKey(__instance.Command)) return true;
__result = CustomFollowerCommandList[__instance.Command].GetTitle(follower);
if (!CustomFollowerCommandList.TryGetValue(__instance.Command, out var value)) return true;
__result = value.GetTitle(follower);
return false;
}

[HarmonyPatch(typeof(CommandItem), nameof(CommandItem.IsAvailable))]
[HarmonyPrefix]
private static bool CommandItem_IsAvailable(CommandItem __instance, Follower follower, ref bool __result)
{
if (!CustomFollowerCommandList.ContainsKey(__instance.Command)) return true;
__result = CustomFollowerCommandList[__instance.Command].IsAvailable(follower);
if (!CustomFollowerCommandList.TryGetValue(__instance.Command, out var value)) return true;
__result = value.IsAvailable(follower);
return false;
}

[HarmonyPatch(typeof(CommandItem), nameof(CommandItem.GetDescription))]
[HarmonyPrefix]
private static bool CommandItem_GetDescription(CommandItem __instance, Follower follower, ref string __result)
{
if (!CustomFollowerCommandList.ContainsKey(__instance.Command)) return true;
__result = CustomFollowerCommandList[__instance.Command].GetDescription(follower);
if (!CustomFollowerCommandList.TryGetValue(__instance.Command, out var value)) return true;
__result = value.GetDescription(follower);
return false;
}

[HarmonyPatch(typeof(CommandItem), nameof(CommandItem.GetLockedDescription))]
[HarmonyPrefix]
private static bool CommandItem_GetLockedDescription(CommandItem __instance, Follower follower, ref string __result)
{
if (!CustomFollowerCommandList.ContainsKey(__instance.Command)) return true;
__result = CustomFollowerCommandList[__instance.Command].GetLockedDescription(follower);
if (!CustomFollowerCommandList.TryGetValue(__instance.Command, out var value)) return true;
__result = value.GetLockedDescription(follower);
return false;
}

Expand Down Expand Up @@ -131,9 +131,9 @@ private static bool interaction_FollowerInteraction_OnFollowerCommandFinalized(
private static bool FontImageNames_IconForCommand(FollowerCommands followerCommands,
ref string __result)
{
if (!CustomFollowerCommandList.ContainsKey(followerCommands)) return true;
if (!CustomFollowerCommandList.TryGetValue(followerCommands, out var value)) return true;

__result = CustomFollowerCommandList[followerCommands].CommandStringIcon();
__result = value.CommandStringIcon();

return false;
}
Expand Down
76 changes: 38 additions & 38 deletions COTL_API/CustomInventory/Patches/CustomInventoryPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public static partial class CustomItemManager
[HarmonyPostfix]
private static void ItemInfoCard_Configure(ItemInfoCard __instance, InventoryItem.ITEM_TYPE config)
{
if (!CustomItemList.ContainsKey(config)) return;
if (!CustomItemList.TryGetValue(config, out var value)) return;

__instance._itemHeader.text = CustomItemList[config].Name();
__instance._itemHeader.text = value.Name();
__instance._itemLore.text = CustomItemList[config].Lore();
__instance._itemDescription.text = CustomItemList[config].Description();
}
Expand Down Expand Up @@ -62,17 +62,17 @@ where item.CanBeGivenToFollower
private static bool FollowerCommandItems_GiftCommandItem_GetTitle(FollowerCommandItems.GiftCommandItem __instance,
Follower follower, ref string __result)
{
if (!CustomItemList.ContainsKey(__instance._itemType)) return true;
__result = CustomItemList[__instance._itemType].GiftTitle(follower);
if (!CustomItemList.TryGetValue(__instance._itemType, out var value)) return true;
__result = value.GiftTitle(follower);
return false;
}

[HarmonyPatch(typeof(FontImageNames), nameof(FontImageNames.GetIconByType))]
[HarmonyPrefix]
private static bool FontImageNames_GetIconByType(InventoryItem.ITEM_TYPE Type, ref string __result)
{
if (!CustomItemList.ContainsKey(Type)) return true;
__result = CustomItemList[Type].InventoryStringIcon();
if (!CustomItemList.TryGetValue(Type, out var value)) return true;
__result = value.InventoryStringIcon();
return false;
}

Expand All @@ -81,53 +81,53 @@ private static bool FontImageNames_GetIconByType(InventoryItem.ITEM_TYPE Type, r
[HarmonyPrefix]
private static bool InventoryIconMapping_GetImage(InventoryItem.ITEM_TYPE type, ref Sprite __result)
{
if (!CustomItemList.ContainsKey(type)) return true;
__result = CustomItemList[type].InventoryIcon;
if (!CustomItemList.TryGetValue(type, out var value)) return true;
__result = value.InventoryIcon;
return false;
}

[HarmonyPatch(typeof(InventoryItem), nameof(InventoryItem.Name))]
[HarmonyPrefix]
private static bool InventoryItem_Name(InventoryItem.ITEM_TYPE Type, ref string __result)
{
if (!CustomItemList.ContainsKey(Type)) return true;
__result = CustomItemList[Type].Name();
if (!CustomItemList.TryGetValue(Type, out var value)) return true;
__result = value.Name();
return false;
}

[HarmonyPatch(typeof(InventoryItem), nameof(InventoryItem.LocalizedName))]
[HarmonyPrefix]
private static bool InventoryItem_LocalizedName(InventoryItem.ITEM_TYPE Type, ref string __result)
{
if (!CustomItemList.ContainsKey(Type)) return true;
__result = CustomItemList[Type].LocalizedName();
if (!CustomItemList.TryGetValue(Type, out var value)) return true;
__result = value.LocalizedName();
return false;
}

[HarmonyPatch(typeof(InventoryItem), nameof(InventoryItem.Description))]
[HarmonyPrefix]
private static bool InventoryItem_Description(InventoryItem.ITEM_TYPE Type, ref string __result)
{
if (!CustomItemList.ContainsKey(Type)) return true;
__result = CustomItemList[Type].Description();
if (!CustomItemList.TryGetValue(Type, out var value)) return true;
__result = value.Description();
return false;
}

[HarmonyPatch(typeof(InventoryItem), nameof(InventoryItem.LocalizedDescription))]
[HarmonyPrefix]
private static bool InventoryItem_LocalizedDescription(InventoryItem.ITEM_TYPE Type, ref string __result)
{
if (!CustomItemList.ContainsKey(Type)) return true;
__result = CustomItemList[Type].LocalizedDescription();
if (!CustomItemList.TryGetValue(Type, out var value)) return true;
__result = value.LocalizedDescription();
return false;
}

[HarmonyPatch(typeof(InventoryItem), nameof(InventoryItem.Lore))]
[HarmonyPrefix]
private static bool InventoryItem_Lore(InventoryItem.ITEM_TYPE Type, ref string __result)
{
if (!CustomItemList.ContainsKey(Type)) return true;
__result = CustomItemList[Type].Lore();
if (!CustomItemList.TryGetValue(Type, out var value)) return true;
__result = value.Lore();
return false;
}

Expand All @@ -136,80 +136,80 @@ private static bool InventoryItem_Lore(InventoryItem.ITEM_TYPE Type, ref string
private static bool InventoryItem_ItemCategory(InventoryItem.ITEM_TYPE type,
ref InventoryItem.ITEM_CATEGORIES __result)
{
if (!CustomItemList.ContainsKey(type)) return true;
__result = CustomItemList[type].ItemCategory;
if (!CustomItemList.TryGetValue(type, out var value)) return true;
__result = value.ItemCategory;
return false;
}

[HarmonyPatch(typeof(InventoryItem), nameof(InventoryItem.GetSeedType))]
[HarmonyPrefix]
private static bool InventoryItem_GetSeedType(InventoryItem.ITEM_TYPE type, ref InventoryItem.ITEM_TYPE __result)
{
if (!CustomItemList.ContainsKey(type)) return true;
__result = CustomItemList[type].SeedType;
if (!CustomItemList.TryGetValue(type, out var value)) return true;
__result = value.SeedType;
return false;
}

[HarmonyPatch(typeof(InventoryItem), nameof(InventoryItem.FuelWeight), typeof(InventoryItem.ITEM_TYPE))]
[HarmonyPrefix]
private static bool InventoryItem_FuelWeight(InventoryItem.ITEM_TYPE type, ref int __result)
{
if (!CustomItemList.ContainsKey(type)) return true;
__result = CustomItemList[type].FuelWeight;
if (!CustomItemList.TryGetValue(type, out var value)) return true;
__result = value.FuelWeight;
return false;
}

[HarmonyPatch(typeof(InventoryItem), nameof(InventoryItem.FoodSatitation))]
[HarmonyPrefix]
private static bool InventoryItem_FoodSatitation(InventoryItem.ITEM_TYPE Type, ref int __result)
{
if (!CustomItemList.ContainsKey(Type)) return true;
__result = CustomItemList[Type].FoodSatitation;
if (!CustomItemList.TryGetValue(Type, out var value)) return true;
__result = value.FoodSatitation;
return false;
}

[HarmonyPatch(typeof(InventoryItem), nameof(InventoryItem.IsFish))]
[HarmonyPrefix]
private static bool InventoryItem_IsFish(InventoryItem.ITEM_TYPE Type, ref bool __result)
{
if (!CustomItemList.ContainsKey(Type)) return true;
__result = CustomItemList[Type].IsFish;
if (!CustomItemList.TryGetValue(Type, out var value)) return true;
__result = value.IsFish;
return false;
}

[HarmonyPatch(typeof(InventoryItem), nameof(InventoryItem.IsFood))]
[HarmonyPrefix]
private static bool InventoryItem_IsFood(InventoryItem.ITEM_TYPE Type, ref bool __result)
{
if (!CustomItemList.ContainsKey(Type)) return true;
__result = CustomItemList[Type].IsFood;
if (!CustomItemList.TryGetValue(Type, out var value)) return true;
__result = value.IsFood;
return false;
}

[HarmonyPatch(typeof(InventoryItem), nameof(InventoryItem.IsBigFish))]
[HarmonyPrefix]
private static bool InventoryItem_IsBigFish(InventoryItem.ITEM_TYPE Type, ref bool __result)
{
if (!CustomItemList.ContainsKey(Type)) return true;
__result = CustomItemList[Type].IsBigFish;
if (!CustomItemList.TryGetValue(Type, out var value)) return true;
__result = value.IsBigFish;
return false;
}

[HarmonyPatch(typeof(InventoryItem), nameof(InventoryItem.CanBeGivenToFollower))]
[HarmonyPrefix]
private static bool InventoryItem_CanBeGivenToFollower(InventoryItem.ITEM_TYPE Type, ref bool __result)
{
if (!CustomItemList.ContainsKey(Type)) return true;
__result = CustomItemList[Type].CanBeGivenToFollower;
if (!CustomItemList.TryGetValue(Type, out var value)) return true;
__result = value.CanBeGivenToFollower;
return false;
}

[HarmonyPatch(typeof(InventoryItem), nameof(InventoryItem.CapacityString))]
[HarmonyPrefix]
private static bool InventoryItem_CapacityString(InventoryItem.ITEM_TYPE type, int minimum, ref string __result)
{
if (!CustomItemList.ContainsKey(type)) return true;
__result = CustomItemList[type].CapacityString(minimum);
if (!CustomItemList.TryGetValue(type, out var value)) return true;
__result = value.CapacityString(minimum);
return false;
}

Expand All @@ -228,9 +228,9 @@ private static bool InventoryItem_GiveToFollowerCallbacks(InventoryItem.ITEM_TYP
if (!CustomItemList.ContainsKey(Type)) return true;
__result = (follower, type, callback) =>
{
if (!CustomItemList.ContainsKey(type))
if (!CustomItemList.TryGetValue(type, out var value))
InventoryItem.GiveToFollowerCallbacks(type)(follower, type, callback);
else CustomItemList[type].OnGiftTo(follower, callback);
else value.OnGiftTo(follower, callback);
};
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions COTL_API/CustomInventory/Patches/CustomItemRefineryPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ public static void UIRefineryMenuController_Show(ref UIMenuBase __instance)
[HarmonyPatch(typeof(RefineryInfoCard), nameof(RefineryInfoCard.Configure), typeof(InventoryItem.ITEM_TYPE))]
public static void RefineryInfoCard_Configure(ref RefineryInfoCard __instance, ref InventoryItem.ITEM_TYPE config)
{
if (!CustomItemList.ContainsKey(config)) return;
if (!CustomItemList.TryGetValue(config, out var value)) return;

__instance._descriptionText.text = CustomItemList[config].LocalizedDescription();
__instance._descriptionText.text = value.LocalizedDescription();
__instance._headerText.text = CustomItemList[config].LocalizedName();
}
}
8 changes: 4 additions & 4 deletions COTL_API/CustomLocalization/CustomLocalizationPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ private static bool TermData_GetTranslation(ref string __result, TermData __inst
}

var lang = SettingsManager.Settings.Game.Language;
if (!LocalizationMap.ContainsKey(lang)) return true;
if (!LocalizationMap[lang].ContainsKey(__instance.Term)) return true;
if (!LocalizationMap.TryGetValue(lang, out var value)) return true;
if (!value.ContainsKey(__instance.Term)) return true;
__result = LocalizationMap[lang][__instance.Term];

return false;
Expand All @@ -32,8 +32,8 @@ private static bool TermData_GetTranslation(ref string __result, TermData __inst
private static bool LanguageSourceData_TryGetTranslation(string term, ref string Translation, ref bool __result)
{
var lang = SettingsManager.Settings.Game.Language;
if (!LocalizationMap.ContainsKey(lang)) return true;
if (!LocalizationMap[lang].ContainsKey(term)) return true;
if (!LocalizationMap.TryGetValue(lang, out var value)) return true;
if (!value.ContainsKey(term)) return true;
Translation = LocalizationMap[lang][term];
__result = true;

Expand Down
14 changes: 7 additions & 7 deletions COTL_API/CustomMission/CustomMissionPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,33 +67,33 @@ public static void MissionInfoCard_Configure(ref MissionInfoCard __instance, ref
[HarmonyPatch(typeof(InventoryItem), nameof(InventoryItem.LocalizedName), typeof(InventoryItem.ITEM_TYPE))]
public static void PrefixPatchesOne(ref InventoryItem.ITEM_TYPE Type)
{
if (CustomMissionList.ContainsKey(Type)) Type = CustomMissionList[Type].RewardType;
if (CustomMissionList.TryGetValue(Type, out var value)) Type = value.RewardType;
}

[HarmonyPrefix]
[HarmonyPatch(typeof(MissionaryManager), nameof(MissionaryManager.GetDurationDeterministic))]
public static void MissionaryManager_GetDurationDeterministic(ref InventoryItem.ITEM_TYPE type)
{
if (CustomMissionList.ContainsKey(type)) type = CustomMissionList[type].RewardType;
if (CustomMissionList.TryGetValue(type, out var value)) type = value.RewardType;
}

[HarmonyPrefix]
[HarmonyPatch(typeof(Inventory), nameof(Inventory.GetItemQuantity), typeof(InventoryItem.ITEM_TYPE))]
public static void Inventory_GetItemQuantity(ref InventoryItem.ITEM_TYPE itemType)
{
if (CustomMissionList.ContainsKey(itemType)) itemType = CustomMissionList[itemType].RewardType;
if (CustomMissionList.TryGetValue(itemType, out var value)) itemType = value.RewardType;
}

[HarmonyPrefix]
[HarmonyPatch(typeof(MissionaryManager), nameof(MissionaryManager.GetChance))]
public static bool MissionaryManager_GetChance(ref float __result, InventoryItem.ITEM_TYPE type,
FollowerInfo followerInfo, StructureBrain.TYPES missionaryType)
{
if (!CustomMissionList.ContainsKey(type)) return true;
if (!CustomMissionList.TryGetValue(type, out var value)) return true;


var baseChanceMultiplier =
MissionaryManager.GetBaseChanceMultiplier(CustomMissionList[type].RewardType, followerInfo);
MissionaryManager.GetBaseChanceMultiplier(value.RewardType, followerInfo);
var random = new Random((int)(followerInfo.ID + CustomMissionList[type].RewardType));

__result = Mathf.Clamp(
Expand All @@ -108,9 +108,9 @@ public static bool MissionaryManager_GetChance(ref float __result, InventoryItem
[HarmonyPatch(typeof(MissionaryManager), nameof(MissionaryManager.GetRewardRange))]
public static bool MissionaryManager_GetRewardRange(ref IntRange __result, InventoryItem.ITEM_TYPE type)
{
if (!CustomMissionList.ContainsKey(type)) return true;
if (!CustomMissionList.TryGetValue(type, out var value)) return true;

__result = CustomMissionList[type].RewardRange;
__result = value.RewardRange;
return false;
}

Expand Down
1 change: 0 additions & 1 deletion COTL_API/CustomObjectives/CustomObjectivePatches.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Reflection.Emit;
using HarmonyLib;
using MMTools;

Expand Down
8 changes: 4 additions & 4 deletions COTL_API/CustomRelics/CustomRelicPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ private static bool LocalizationManager_GetTranslation(string Term, ref string _
[HarmonyPrefix]
private static bool RelicData_GetChargeCategory(RelicType relicType, ref RelicChargeCategory __result)
{
if (!CustomRelicDataList.ContainsKey(relicType)) return true;
if (!CustomRelicDataList.TryGetValue(relicType, out var value)) return true;

__result = CustomRelicDataList[relicType].GetChargeCategory();
__result = value.GetChargeCategory();

return false;
}
Expand All @@ -50,9 +50,9 @@ private static bool RelicData_GetChargeCategory(RelicType relicType, ref RelicCh
[HarmonyPrefix]
private static bool RelicData_GetChargeCategory(RelicData relicData, ref RelicChargeCategory __result)
{
if (!CustomRelicDataList.ContainsKey(relicData.RelicType)) return true;
if (!CustomRelicDataList.TryGetValue(relicData.RelicType, out var value)) return true;

__result = CustomRelicDataList[relicData.RelicType].GetChargeCategory();
__result = value.GetChargeCategory();

return false;
}
Expand Down
Loading

0 comments on commit 0f98211

Please sign in to comment.