From a9694fd3b7080deec027408cab1b3f03e8f25579 Mon Sep 17 00:00:00 2001 From: hejiajun107 Date: Wed, 15 Jun 2022 13:12:08 +0800 Subject: [PATCH] Convert.Unload --- .../Kraotos/MyExtension/ConvertUnload.cs | 72 +++++++++++++++++++ .../Extension/MyExtension/MyTechnoExt.cs | 1 + 2 files changed, 73 insertions(+) create mode 100644 DynamicPatcher/Projects/Extension/Kraotos/MyExtension/ConvertUnload.cs diff --git a/DynamicPatcher/Projects/Extension/Kraotos/MyExtension/ConvertUnload.cs b/DynamicPatcher/Projects/Extension/Kraotos/MyExtension/ConvertUnload.cs new file mode 100644 index 0000000..2cecd5a --- /dev/null +++ b/DynamicPatcher/Projects/Extension/Kraotos/MyExtension/ConvertUnload.cs @@ -0,0 +1,72 @@ +using DynamicPatcher; +using Extension.Utilities; +using PatcherYRpp; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Extension.Ext +{ + public partial class TechnoExt + { + private bool needConvertWhenLanding = false; + private bool landed = false; + private string FloatingType; + private string LandingType; + + + public unsafe void UnitClass_Init_Convert_Unload() + { + if (string.IsNullOrEmpty(Type.ConvertUnloadTo)) return; + needConvertWhenLanding = true; + FloatingType = OwnerObject.Ref.Type.Ref.Base.Base.ID; + LandingType = Type.ConvertUnloadTo; + + OnUpdateAction += UnitClass_Update_Convert_Unload; + } + + public unsafe void UnitClass_Update_Convert_Unload() + { + if (!needConvertWhenLanding) return; + var mission = OwnerObject.Convert(); + + if (landed == false) + { + if (mission.Ref.CurrentMission == Mission.Unload) + { + OwnerObject.Convert().Ref.Type = TechnoTypeClass.ABSTRACTTYPE_ARRAY.Find(LandingType).Convert(); + landed = true; + } + } + else + { + if (mission.Ref.CurrentMission == Mission.Move) + { + OwnerObject.Convert().Ref.Type = TechnoTypeClass.ABSTRACTTYPE_ARRAY.Find(FloatingType).Convert(); + landed = false; + } + } + } + + } + + public partial class TechnoTypeExt + { + public string ConvertUnloadTo; + + /// + /// + /// + /// + /// + private void ReadConvertUnloadData(INIReader reader, string section) + { + if (string.IsNullOrEmpty(ConvertUnloadTo)) + { + reader.ReadNormal(section, "Convert.Unload", ref ConvertUnloadTo); + } + } + } +} diff --git a/DynamicPatcher/Projects/Extension/MyExtension/MyTechnoExt.cs b/DynamicPatcher/Projects/Extension/MyExtension/MyTechnoExt.cs index 25d0b2e..0cab79c 100644 --- a/DynamicPatcher/Projects/Extension/MyExtension/MyTechnoExt.cs +++ b/DynamicPatcher/Projects/Extension/MyExtension/MyTechnoExt.cs @@ -72,6 +72,7 @@ public void OnInit() case AbstractType.Unit: UnitClass_Init_JumpjetFacingToTarget(); UnitClass_Init_UnitDeployFireOnce(); + UnitClass_Init_Convert_Unload(); break; case AbstractType.Aircraft: AircraftClass_Init_AircraftDive();