From dc8d35bf38ddae30500cb96db2b4c0fd1c65917c Mon Sep 17 00:00:00 2001 From: Future <1609605489@qq.com> Date: Wed, 28 Feb 2024 11:09:23 +0800 Subject: [PATCH] update implicit transfer --- .../CompModularizationWeapon.cs | 47 ++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/RW_ModularizationWeapon/CompModularizationWeapon.cs b/RW_ModularizationWeapon/CompModularizationWeapon.cs index 012ec9a..02b4fdf 100644 --- a/RW_ModularizationWeapon/CompModularizationWeapon.cs +++ b/RW_ModularizationWeapon/CompModularizationWeapon.cs @@ -749,7 +749,52 @@ public static implicit operator Thing(CompModularizationWeapon node) public static implicit operator CompModularizationWeapon(Thing thing) { - return thing?.TryGetComp(); + List comps = (thing as ThingWithComps)?.AllComps; + if (comps == null || comps.Count < 2 || ((CompChildNodeProccesser)thing) == null) return null; + + CompNoCompMarker marker = comps[1] as CompNoCompMarker; + if (marker != null) return null; + CompModularizationWeapon result = comps[1] as CompModularizationWeapon; + int i = 2; + if (result != null) return result; + else + { + for (; i < comps.Count; i++) + { + result = comps[i] as CompModularizationWeapon; + if (result != null) break; + } + } + if (result != null) + { + comps.RemoveAt(i); + comps.Insert(1, result); + } + else + { + i = 2; + for (; i < comps.Count; i++) + { + marker = comps[i] as CompNoCompMarker; + if (marker != null) break; + } + if (marker != null) + { + comps.RemoveAt(i); + comps.Insert(1, marker); + } + else + { + marker = new CompNoCompMarker(); + comps.Insert(1, marker); + } + } + return result; + } + + internal class CompNoCompMarker : ThingComp + { + } #endregion