From b433b6aa2970567062eb1afdac627d513b802fe6 Mon Sep 17 00:00:00 2001 From: linkaixiang Date: Thu, 13 Oct 2022 08:49:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=8A=9F=E6=B3=95=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LKXModsGongFaGridCost/Main.cs | 37 +++++++++++--- LKXModsGongFaGridCostBackend/Main.cs | 73 ++++++++++++++++++++++------ 2 files changed, 89 insertions(+), 21 deletions(-) diff --git a/LKXModsGongFaGridCost/Main.cs b/LKXModsGongFaGridCost/Main.cs index 93c5b60..6517588 100644 --- a/LKXModsGongFaGridCost/Main.cs +++ b/LKXModsGongFaGridCost/Main.cs @@ -1,12 +1,13 @@ using Config; using Config.Common; +using GameData.Domains.CombatSkill; using HarmonyLib; using System.Collections.Generic; using TaiwuModdingLib.Core.Plugin; namespace LKXModsGongFaGridCost { - [PluginConfig("LKXModsGongFaGridCost", "LKX", "0.0.1")] + [PluginConfig("LKXModsGongFaGridCost", "LKX", "0.2.3")] public class Run : TaiwuRemakePlugin { private Harmony harmony; @@ -38,18 +39,41 @@ public override void Initialize() harmony = Harmony.CreateAndPatchAll(typeof(Run)); } + private static bool enableGridCost; private static int gridCost; - private static int genericGrid; + + //private static bool enableGenericGrid; + //private static int genericGrid; + + private static bool enableBaseGrid; private static int baseNeigongGrid; + private static int baseCuipoGrid; + private static int baseQingyingGrid; + private static int baseHutiGrid; + private static int baseQiqiaoGrid; public override void OnModSettingUpdate() { Loaded = false; + ModManager.GetSetting(ModIdStr, "enableGridCost", ref enableGridCost); + ModManager.GetSetting(ModIdStr, "enableBaseGrid", ref enableBaseGrid); + //ModManager.GetSetting(ModIdStr, "enableGenericGrid", ref enableGenericGrid); ModManager.GetSetting(ModIdStr, "gridCost", ref gridCost); - ModManager.GetSetting(ModIdStr, "genericGrid", ref genericGrid); + //ModManager.GetSetting(ModIdStr, "genericGrid", ref genericGrid); ModManager.GetSetting(ModIdStr, "baseNeigongGrid", ref baseNeigongGrid); + ModManager.GetSetting(ModIdStr, "baseCuipoGrid", ref baseCuipoGrid); + ModManager.GetSetting(ModIdStr, "baseQingyingGrid", ref baseQingyingGrid); + ModManager.GetSetting(ModIdStr, "baseHutiGrid", ref baseHutiGrid); + ModManager.GetSetting(ModIdStr, "baseQiqiaoGrid", ref baseQiqiaoGrid); CombatSkill.Instance.GetAllKeys(); - GlobalConfig.Instance.CombatSkillInitialEquipSlotCounts[0] = (sbyte)baseNeigongGrid; + if (enableBaseGrid) + { + GlobalConfig.Instance.CombatSkillInitialEquipSlotCounts[CombatSkillEquipType.Neigong] = (sbyte)baseNeigongGrid; + GlobalConfig.Instance.CombatSkillInitialEquipSlotCounts[CombatSkillEquipType.Attack] = (sbyte)baseCuipoGrid; + GlobalConfig.Instance.CombatSkillInitialEquipSlotCounts[CombatSkillEquipType.Agile] = (sbyte)baseQingyingGrid; + GlobalConfig.Instance.CombatSkillInitialEquipSlotCounts[CombatSkillEquipType.Defense] = (sbyte)baseHutiGrid; + GlobalConfig.Instance.CombatSkillInitialEquipSlotCounts[CombatSkillEquipType.Assist] = (sbyte)baseQiqiaoGrid; + } } /// @@ -65,10 +89,9 @@ public static void PatchSkill(ref List ____dataArray) } foreach (CombatSkillItem item in ____dataArray) { - typeof(CombatSkillItem).GetField("GridCost").SetValue(item, (sbyte)gridCost); - if (item.Type == GameData.Domains.CombatSkill.CombatSkillType.Neigong) + if (enableGridCost && item.GridCost > gridCost) { - typeof(CombatSkillItem).GetField("GenericGrid").SetValue(item, (sbyte)genericGrid); + typeof(CombatSkillItem).GetField("GridCost").SetValue(item, (sbyte)gridCost); } } diff --git a/LKXModsGongFaGridCostBackend/Main.cs b/LKXModsGongFaGridCostBackend/Main.cs index 2d76746..523c9f7 100644 --- a/LKXModsGongFaGridCostBackend/Main.cs +++ b/LKXModsGongFaGridCostBackend/Main.cs @@ -7,10 +7,11 @@ using GameData.Domains.Combat; using GameData.Domains.CombatSkill; using System; +using GameData.Common; namespace LKXModsGongFaGridCostBackend { - [PluginConfig("LKXModsGongFaGridCostBackend", "LKX", "0.0.1")] + [PluginConfig("LKXModsGongFaGridCostBackend", "LKX", "0.2.3")] public class Run : TaiwuRemakePlugin { private Harmony harmony; @@ -35,18 +36,42 @@ public override void Initialize() harmony = Harmony.CreateAndPatchAll(typeof(Run)); } + private static bool enableGridCost; private static int gridCost; - private static int genericGrid; + + //private static bool enableGenericGrid; + //private static int genericGrid; + + private static bool enableBaseGrid; private static int baseNeigongGrid; + private static int baseCuipoGrid; + private static int baseQingyingGrid; + private static int baseHutiGrid; + private static int baseQiqiaoGrid; public override void OnModSettingUpdate() { Loaded = false; + DomainManager.Mod.GetSetting(ModIdStr, "enableGridCost", ref enableGridCost); + //DomainManager.Mod.GetSetting(ModIdStr, "enableGenericGrid", ref enableGenericGrid); DomainManager.Mod.GetSetting(ModIdStr, "gridCost", ref gridCost); - DomainManager.Mod.GetSetting(ModIdStr, "genericGrid", ref genericGrid); + //DomainManager.Mod.GetSetting(ModIdStr, "genericGrid", ref genericGrid); + + DomainManager.Mod.GetSetting(ModIdStr, "enableBaseGrid", ref enableBaseGrid); DomainManager.Mod.GetSetting(ModIdStr, "baseNeigongGrid", ref baseNeigongGrid); + DomainManager.Mod.GetSetting(ModIdStr, "baseCuipoGrid", ref baseCuipoGrid); + DomainManager.Mod.GetSetting(ModIdStr, "baseQingyingGrid", ref baseQingyingGrid); + DomainManager.Mod.GetSetting(ModIdStr, "baseHutiGrid", ref baseHutiGrid); + DomainManager.Mod.GetSetting(ModIdStr, "baseQiqiaoGrid", ref baseQiqiaoGrid); Config.CombatSkill.Instance.GetAllKeys(); - GlobalConfig.Instance.CombatSkillInitialEquipSlotCounts[0] = (sbyte)baseNeigongGrid; + if (enableBaseGrid) + { + GlobalConfig.Instance.CombatSkillInitialEquipSlotCounts[CombatSkillEquipType.Neigong] = (sbyte)baseNeigongGrid; + GlobalConfig.Instance.CombatSkillInitialEquipSlotCounts[CombatSkillEquipType.Attack] = (sbyte)baseCuipoGrid; + GlobalConfig.Instance.CombatSkillInitialEquipSlotCounts[CombatSkillEquipType.Agile] = (sbyte)baseQingyingGrid; + GlobalConfig.Instance.CombatSkillInitialEquipSlotCounts[CombatSkillEquipType.Defense] = (sbyte)baseHutiGrid; + GlobalConfig.Instance.CombatSkillInitialEquipSlotCounts[CombatSkillEquipType.Assist] = (sbyte)baseQiqiaoGrid; + } } /// @@ -63,10 +88,9 @@ public static void CombatSkill_GetAllKeys_Patch(Config.CombatSkill __instance, r } foreach (CombatSkillItem item in ____dataArray) { - typeof(CombatSkillItem).GetField("GridCost").SetValue(item, (sbyte)gridCost); - if (item.Type == GameData.Domains.CombatSkill.CombatSkillType.Neigong) + if(enableGridCost && item.GridCost > gridCost) { - typeof(CombatSkillItem).GetField("GenericGrid").SetValue(item, (sbyte)genericGrid); + typeof(CombatSkillItem).GetField("GridCost").SetValue(item, (sbyte)gridCost); } } @@ -79,8 +103,20 @@ public static void CombatDomain_UpdateSkillNeedMobilityCanUse_Patch(CombatCharac CombatSkillCollection combatSkillCollection = (CombatSkillCollection)AccessTools.Field(typeof(CombatSkillDomain), "_combatSkills").GetValue(DomainManager.CombatSkill); foreach (CombatSkillKey combatSkillKey in (character.IsAlly ? ____selfSkillDataDict : ____enemySkillDataDict).Keys) { - bool flag = !combatSkillCollection.ContainsKey(combatSkillKey) && !character.IsAlly; - if (flag) + if (!combatSkillCollection.ContainsKey(combatSkillKey) && !character.IsAlly) + { + ____enemySkillDataDict.Remove(combatSkillKey); + } + } + } + + [HarmonyPrefix, HarmonyPatch(typeof(CombatDomain), "UpdateSkillCanUse", new Type[] {typeof(CombatCharacter), typeof(short), typeof(DataContext) })] + public static void CombatDomain_UpdateSkillCanUse_Patch(CombatCharacter character, short skillId, DataContext context, ref Dictionary ____selfSkillDataDict, ref Dictionary ____enemySkillDataDict) + { + CombatSkillCollection combatSkillCollection = (CombatSkillCollection)AccessTools.Field(typeof(CombatSkillDomain), "_combatSkills").GetValue(DomainManager.CombatSkill); + foreach (CombatSkillKey combatSkillKey in (character.IsAlly ? ____selfSkillDataDict : ____enemySkillDataDict).Keys) + { + if (!combatSkillCollection.ContainsKey(combatSkillKey) && !character.IsAlly) { ____enemySkillDataDict.Remove(combatSkillKey); } @@ -93,13 +129,22 @@ public static void CombatDomain_UpdateSkillNeedMobilityCanUse_Patch(CombatCharac /// /// [HarmonyPostfix, HarmonyPatch(typeof(GameData.Domains.Character.CharacterDomain), "GetCombatSkillSlotCounts")] - public unsafe static void CharacterDomain_GetCombatSkillSlotCounts_Patch(GameData.Domains.Character.CharacterDomain __instance, ref sbyte[] __result) + public static void CharacterDomain_GetCombatSkillSlotCounts_Patch(GameData.Domains.Character.CharacterDomain __instance, ref sbyte[] __result) { - __result[0] = (sbyte)baseNeigongGrid; - if (__result[0] > GameData.Domains.Character.CombatSkillHelper.MaxSlotCounts[0]) + //只修改技能格子会导致报错。这次更新后不在出现这样的问题,取消该处修改。 + + /*if (enableBaseGrid) { - __result[0] = GameData.Domains.Character.CombatSkillHelper.MaxSlotCounts[0]; - } + __result[CombatSkillEquipType.Neigong] = (sbyte)baseNeigongGrid; + __result[CombatSkillEquipType.Attack] = (sbyte)baseCuipoGrid; + __result[CombatSkillEquipType.Agile] = (sbyte)baseQingyingGrid; + __result[CombatSkillEquipType.Defense] = (sbyte)baseHutiGrid; + __result[CombatSkillEquipType.Assist] = (sbyte)baseQiqiaoGrid; + for(int i = 0; i < GameData.Domains.Character.CombatSkillHelper.MaxSlotCounts.Length; i++) + { + __result[i] = GameData.Domains.Character.CombatSkillHelper.MaxSlotCounts[i]; + } + }*/ } } }