重构自主机械体系统:增强UI、AI和兼容性
1. **核心架构重构**:
* 将硬编码的 AutonomousWorkMode 枚举替换为基于 XML 定义的 DroneWorkModeDef,以提高扩展性。
* 定义了基础工作模式:工作、充电、休眠、自动战斗。
* 重构了 CompAutonomousMech 以支持新的 Def 系统。
2. **UI 增强**:
* 添加了 DroneGizmo:为选中的机械体提供控制面板,显示能量水平并允许切换模式。
* 添加了 PawnColumnWorker_DroneWorkMode 和 PawnColumnWorker_DroneEnergy:在机械体列表中显示工作模式图标和能量条。
* 通过 Harmony 补丁 Patch_MainTabWindow_Mechs_Pawns 将自主机械体集成到原版机械体主标签页中。
* 扩展了 PawnTableDefOf.Mechs 以包含新的自定义列。
3. **AI 与行为改进**:
* 实现了 JobDriver_DroneSelfShutdown 和 JobGiver_DroneSelfShutdown:机械体现在会在低电量或被命令时寻找安全地点休眠。
* 添加了 ThinkNode_ConditionalWorkMode_Drone 和 ThinkNode_ConditionalLowEnergy_Drone 用于行为树逻辑。
4. **兼容性与修复**:
* 添加了 Patch_MechanitorUtility_EverControllable:确保自主机械体始终可控,防止在没有监管者时失去控制。
* 修复了机械体缺少监管者警报的误报问题。
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
using HarmonyLib;
|
||||
using RimWorld;
|
||||
using RimWorld.Planet;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Verse;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
[HarmonyPatch(typeof(Alert_SubjectHasNowOverseer), "GetReport")]
|
||||
public static class Patch_Alert_SubjectHasNowOverseer
|
||||
{
|
||||
[HarmonyPostfix]
|
||||
public static void Postfix(ref AlertReport __result)
|
||||
{
|
||||
if (!__result.active)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// AlertReport 是一个结构体,没有 culprits 属性,需要通过 AllCulprits 获取
|
||||
// 并且 AlertReport 的字段是只读的或者不方便直接修改,所以我们需要重新构建
|
||||
|
||||
List<GlobalTargetInfo> allCulprits = __result.AllCulprits.ToList();
|
||||
bool changed = false;
|
||||
|
||||
for (int i = allCulprits.Count - 1; i >= 0; i--)
|
||||
{
|
||||
Pawn pawn = allCulprits[i].Thing as Pawn;
|
||||
if (pawn != null)
|
||||
{
|
||||
var comp = pawn.GetComp<CompAutonomousMech>();
|
||||
// 如果是自主机械体,且允许自主工作,则从警报列表中移除
|
||||
if (comp != null && comp.CanBeAutonomous)
|
||||
{
|
||||
allCulprits.RemoveAt(i);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 如果列表发生了变化,重新生成 AlertReport
|
||||
if (changed)
|
||||
{
|
||||
if (allCulprits.Count > 0)
|
||||
{
|
||||
__result = AlertReport.CulpritsAre(allCulprits);
|
||||
}
|
||||
else
|
||||
{
|
||||
__result = AlertReport.Inactive;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using HarmonyLib;
|
||||
using RimWorld;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Verse;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
[HarmonyPatch(typeof(MainTabWindow_Mechs), "Pawns", MethodType.Getter)]
|
||||
public static class Patch_MainTabWindow_Mechs_Pawns
|
||||
{
|
||||
[HarmonyPostfix]
|
||||
public static void Postfix(ref IEnumerable<Pawn> __result)
|
||||
{
|
||||
// 获取所有自主机械体
|
||||
var autonomousMechs = Find.CurrentMap.mapPawns.PawnsInFaction(Faction.OfPlayer)
|
||||
.Where(p => p.RaceProps.IsMechanoid && p.GetComp<CompAutonomousMech>()?.CanBeAutonomous == true);
|
||||
|
||||
// 将自主机械体合并到结果中,并去重
|
||||
__result = __result.Concat(autonomousMechs).Distinct();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using HarmonyLib;
|
||||
using RimWorld;
|
||||
using Verse;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
[HarmonyPatch(typeof(MechanitorUtility), "EverControllable")]
|
||||
public static class Patch_MechanitorUtility_EverControllable
|
||||
{
|
||||
[HarmonyPostfix]
|
||||
public static void Postfix(Pawn mech, ref bool __result)
|
||||
{
|
||||
if (!__result && mech.TryGetComp<CompAutonomousMech>() != null)
|
||||
{
|
||||
__result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user