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:确保自主机械体始终可控,防止在没有监管者时失去控制。
* 修复了机械体缺少监管者警报的误报问题。
23 lines
769 B
C#
23 lines
769 B
C#
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();
|
|
}
|
|
}
|
|
} |