重构自主机械体系统:增强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:
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using RimWorld;
|
||||
using UnityEngine;
|
||||
using Verse;
|
||||
using Verse.AI;
|
||||
|
||||
@@ -30,14 +31,6 @@ namespace WulaFallenEmpire
|
||||
}
|
||||
}
|
||||
|
||||
// 新增:自主工作模式枚举
|
||||
public enum AutonomousWorkMode
|
||||
{
|
||||
Work, // 工作模式:通过 thinktree 寻找工作
|
||||
Recharge, // 充电模式:优先充电,完成后休眠
|
||||
Shutdown // 关机模式:立即休眠
|
||||
}
|
||||
|
||||
public class CompProperties_AutonomousMech : CompProperties
|
||||
{
|
||||
public bool enableAutonomousDrafting = true;
|
||||
@@ -50,6 +43,8 @@ namespace WulaFallenEmpire
|
||||
public float criticalEnergyThreshold = 0.1f; // 临界能量阈值
|
||||
public float rechargeCompleteThreshold = 0.9f; // 充电完成阈值
|
||||
|
||||
public DroneWorkModeDef initialWorkMode;
|
||||
|
||||
public CompProperties_AutonomousMech()
|
||||
{
|
||||
compClass = typeof(CompAutonomousMech);
|
||||
@@ -62,7 +57,7 @@ namespace WulaFallenEmpire
|
||||
|
||||
public Pawn MechPawn => parent as Pawn;
|
||||
|
||||
private AutonomousWorkMode currentWorkMode = AutonomousWorkMode.Work;
|
||||
private DroneWorkModeDef currentWorkMode;
|
||||
private bool wasLowEnergy = false; // 记录上次是否处于低能量状态
|
||||
|
||||
public bool CanBeAutonomous
|
||||
@@ -147,7 +142,7 @@ namespace WulaFallenEmpire
|
||||
}
|
||||
}
|
||||
|
||||
public AutonomousWorkMode CurrentWorkMode => currentWorkMode;
|
||||
public DroneWorkModeDef CurrentWorkMode => currentWorkMode;
|
||||
|
||||
// 新增:能量状态检查方法
|
||||
public float GetEnergyLevel()
|
||||
@@ -164,6 +159,11 @@ namespace WulaFallenEmpire
|
||||
{
|
||||
base.PostSpawnSetup(respawningAfterLoad);
|
||||
|
||||
if (currentWorkMode == null)
|
||||
{
|
||||
currentWorkMode = Props.initialWorkMode ?? WulaDefOf.Work;
|
||||
}
|
||||
|
||||
// 确保使用独立战斗系统
|
||||
InitializeAutonomousCombat();
|
||||
}
|
||||
@@ -208,10 +208,10 @@ namespace WulaFallenEmpire
|
||||
if (isLowEnergyNow)
|
||||
{
|
||||
// 进入低能量状态
|
||||
if (currentWorkMode == AutonomousWorkMode.Work)
|
||||
if (currentWorkMode == WulaDefOf.Work)
|
||||
{
|
||||
// 自动切换到充电模式
|
||||
SetWorkMode(AutonomousWorkMode.Recharge);
|
||||
SetWorkMode(WulaDefOf.Recharge);
|
||||
Messages.Message("WULA_LowEnergySwitchToRecharge".Translate(MechPawn.LabelCap),
|
||||
MechPawn, MessageTypeDefOf.CautionInput);
|
||||
}
|
||||
@@ -219,10 +219,10 @@ namespace WulaFallenEmpire
|
||||
else
|
||||
{
|
||||
// 恢复能量状态
|
||||
if (currentWorkMode == AutonomousWorkMode.Recharge && IsFullyCharged)
|
||||
if (currentWorkMode == WulaDefOf.Recharge && IsFullyCharged)
|
||||
{
|
||||
// 充满电后自动切换回工作模式
|
||||
SetWorkMode(AutonomousWorkMode.Work);
|
||||
SetWorkMode(WulaDefOf.Work);
|
||||
Messages.Message("WULA_FullyChargedSwitchToWork".Translate(MechPawn.LabelCap),
|
||||
MechPawn, MessageTypeDefOf.PositiveEvent);
|
||||
}
|
||||
@@ -232,12 +232,12 @@ namespace WulaFallenEmpire
|
||||
}
|
||||
|
||||
// 临界能量警告
|
||||
if (IsCriticalEnergy && currentWorkMode != AutonomousWorkMode.Recharge && currentWorkMode != AutonomousWorkMode.Shutdown)
|
||||
if (IsCriticalEnergy && currentWorkMode != WulaDefOf.Recharge && currentWorkMode != WulaDefOf.Shutdown)
|
||||
{
|
||||
Messages.Message("WULA_CriticalEnergyLevels".Translate(MechPawn.LabelCap),
|
||||
MechPawn, MessageTypeDefOf.ThreatBig);
|
||||
// 强制切换到充电模式
|
||||
SetWorkMode(AutonomousWorkMode.Recharge);
|
||||
SetWorkMode(WulaDefOf.Recharge);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -249,77 +249,11 @@ namespace WulaFallenEmpire
|
||||
// 工作模式切换按钮
|
||||
if (CanWorkAutonomously)
|
||||
{
|
||||
string energyInfo = "WULA_EnergyInfo".Translate(GetEnergyLevel().ToStringPercent());
|
||||
yield return new Command_Action
|
||||
{
|
||||
defaultLabel = "WULA_Mech_WorkMode".Translate(GetCurrentWorkModeDisplay()) + energyInfo,
|
||||
defaultDesc = GetWorkModeDescription(),
|
||||
icon = GetWorkModeIcon(),
|
||||
action = () => ShowWorkModeMenu()
|
||||
};
|
||||
yield return new DroneGizmo(this);
|
||||
}
|
||||
}
|
||||
|
||||
// 修改:返回包含能量信息的描述
|
||||
private string GetWorkModeDescription()
|
||||
{
|
||||
string baseDesc = "WULA_Switch_Mech_WorkMode".Translate();
|
||||
string energyInfo = "WULA_CurrentEnergy".Translate(GetEnergyLevel().ToStringPercent());
|
||||
|
||||
if (IsLowEnergy)
|
||||
energyInfo += "WULA_EnergyLow".Translate();
|
||||
if (IsCriticalEnergy)
|
||||
energyInfo += "WULA_EnergyCritical".Translate();
|
||||
|
||||
return baseDesc + "\n" + energyInfo;
|
||||
}
|
||||
|
||||
// 新增:根据能量状态返回不同的图标
|
||||
private UnityEngine.Texture2D GetWorkModeIcon()
|
||||
{
|
||||
if (IsCriticalEnergy)
|
||||
return TexCommand.DesirePower;
|
||||
else if (IsLowEnergy)
|
||||
return TexCommand.ToggleVent;
|
||||
else
|
||||
return TexCommand.Attack;
|
||||
}
|
||||
|
||||
private string GetCurrentWorkModeDisplay()
|
||||
{
|
||||
switch (currentWorkMode)
|
||||
{
|
||||
case AutonomousWorkMode.Work:
|
||||
return "WULA_WorkMode_Work".Translate();
|
||||
case AutonomousWorkMode.Recharge:
|
||||
return "WULA_WorkMode_Recharge".Translate();
|
||||
case AutonomousWorkMode.Shutdown:
|
||||
return "WULA_WorkMode_Shutdown".Translate();
|
||||
default:
|
||||
return "WULA_WorkMode_Unknown".Translate();
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowWorkModeMenu()
|
||||
{
|
||||
List<FloatMenuOption> list = new List<FloatMenuOption>();
|
||||
|
||||
// 工作模式
|
||||
list.Add(new FloatMenuOption("WULA_WorkMode_Work_Desc".Translate(),
|
||||
() => SetWorkMode(AutonomousWorkMode.Work)));
|
||||
|
||||
// 充电模式
|
||||
list.Add(new FloatMenuOption("WULA_WorkMode_Recharge_Desc".Translate(),
|
||||
() => SetWorkMode(AutonomousWorkMode.Recharge)));
|
||||
|
||||
// 休眠模式
|
||||
list.Add(new FloatMenuOption("WULA_WorkMode_Shutdown_Desc".Translate(),
|
||||
() => SetWorkMode(AutonomousWorkMode.Shutdown)));
|
||||
|
||||
Find.WindowStack.Add(new FloatMenu(list));
|
||||
}
|
||||
|
||||
private void SetWorkMode(AutonomousWorkMode mode)
|
||||
public void SetWorkMode(DroneWorkModeDef mode)
|
||||
{
|
||||
currentWorkMode = mode;
|
||||
|
||||
@@ -329,8 +263,7 @@ namespace WulaFallenEmpire
|
||||
MechPawn.jobs.StopAll();
|
||||
}
|
||||
|
||||
string modeName = GetCurrentWorkModeDisplay();
|
||||
Messages.Message("WULA_SwitchedToMode".Translate(MechPawn.LabelCap, modeName),
|
||||
Messages.Message("WULA_SwitchedToMode".Translate(MechPawn.LabelCap, mode.label),
|
||||
MechPawn, MessageTypeDefOf.NeutralEvent);
|
||||
}
|
||||
|
||||
@@ -352,13 +285,13 @@ namespace WulaFallenEmpire
|
||||
if (MechPawn.Drafted)
|
||||
return "WULA_Autonomous_Drafted".Translate() + energyInfo;
|
||||
else
|
||||
return "WULA_Autonomous_Mode".Translate(GetCurrentWorkModeDisplay()) + energyInfo;
|
||||
return "WULA_Autonomous_Mode".Translate(currentWorkMode?.label ?? "Unknown") + energyInfo;
|
||||
}
|
||||
|
||||
public override void PostExposeData()
|
||||
{
|
||||
base.PostExposeData();
|
||||
Scribe_Values.Look(ref currentWorkMode, "currentWorkMode", AutonomousWorkMode.Work);
|
||||
Scribe_Defs.Look(ref currentWorkMode, "currentWorkMode");
|
||||
Scribe_Values.Look(ref wasLowEnergy, "wasLowEnergy", false);
|
||||
}
|
||||
}
|
||||
|
||||
115
Source/WulaFallenEmpire/Pawn/WULA_AutonomousMech/DroneGizmo.cs
Normal file
115
Source/WulaFallenEmpire/Pawn/WULA_AutonomousMech/DroneGizmo.cs
Normal file
@@ -0,0 +1,115 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using Verse;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
[StaticConstructorOnStartup]
|
||||
public class DroneGizmo : Gizmo
|
||||
{
|
||||
private CompAutonomousMech comp;
|
||||
private HashSet<CompAutonomousMech> groupedComps;
|
||||
|
||||
private static readonly Texture2D BarTex = SolidColorMaterials.NewSolidColorTexture(new Color(0.34f, 0.42f, 0.43f));
|
||||
private static readonly Texture2D BarHighlightTex = SolidColorMaterials.NewSolidColorTexture(new Color(0.43f, 0.54f, 0.55f));
|
||||
private static readonly Texture2D EmptyBarTex = SolidColorMaterials.NewSolidColorTexture(new Color(0.03f, 0.035f, 0.05f));
|
||||
// private static readonly Texture2D DragBarTex = SolidColorMaterials.NewSolidColorTexture(new Color(0.74f, 0.97f, 0.8f));
|
||||
|
||||
// private static bool draggingBar;
|
||||
|
||||
public DroneGizmo(CompAutonomousMech comp)
|
||||
{
|
||||
this.comp = comp;
|
||||
}
|
||||
|
||||
public override float GetWidth(float maxWidth)
|
||||
{
|
||||
return 160f;
|
||||
}
|
||||
|
||||
public override GizmoResult GizmoOnGUI(Vector2 topLeft, float maxWidth, GizmoRenderParms parms)
|
||||
{
|
||||
Rect rect = new Rect(topLeft.x, topLeft.y, GetWidth(maxWidth), 75f);
|
||||
Rect rect2 = rect.ContractedBy(10f);
|
||||
Widgets.DrawWindowBackground(rect);
|
||||
|
||||
string text = "WULA_AutonomousMech".Translate();
|
||||
Rect rect3 = new Rect(rect2.x, rect2.y, rect2.width, Text.CalcHeight(text, rect2.width) + 8f);
|
||||
Text.Font = GameFont.Small;
|
||||
Widgets.Label(rect3, text);
|
||||
|
||||
Rect rect4 = new Rect(rect2.x, rect3.yMax, rect2.width, rect2.height - rect3.height);
|
||||
DraggableBarForGroup(rect4);
|
||||
|
||||
Text.Anchor = TextAnchor.MiddleCenter;
|
||||
string energyText = comp.GetEnergyLevel().ToStringPercent();
|
||||
Widgets.Label(rect4, energyText);
|
||||
Text.Anchor = TextAnchor.UpperLeft;
|
||||
|
||||
TooltipHandler.TipRegion(rect4, () => "WULA_EnergyInfo".Translate(energyText), Gen.HashCombineInt(comp.GetHashCode(), 34242419));
|
||||
|
||||
// Work Mode Button
|
||||
Rect rect6 = new Rect(rect2.x + rect2.width - 24f, rect2.y, 24f, 24f);
|
||||
if (Widgets.ButtonImageFitted(rect6, comp.CurrentWorkMode?.uiIcon ?? BaseContent.BadTex))
|
||||
{
|
||||
Find.WindowStack.Add(new FloatMenu(GetWorkModeOptions(comp, groupedComps).ToList()));
|
||||
}
|
||||
TooltipHandler.TipRegion(rect6, "WULA_Switch_Mech_WorkMode".Translate());
|
||||
Widgets.DrawHighlightIfMouseover(rect6);
|
||||
|
||||
return new GizmoResult(GizmoState.Clear);
|
||||
}
|
||||
|
||||
private void DraggableBarForGroup(Rect rect)
|
||||
{
|
||||
// We are not actually dragging the energy level, but maybe a threshold?
|
||||
// For now, just display the energy level.
|
||||
// If we want to set recharge threshold, we need a property in CompAutonomousMech for that.
|
||||
// Assuming we want to visualize energy level:
|
||||
|
||||
Widgets.FillableBar(rect, comp.GetEnergyLevel(), BarTex, EmptyBarTex, false);
|
||||
}
|
||||
|
||||
public static IEnumerable<FloatMenuOption> GetWorkModeOptions(CompAutonomousMech comp, HashSet<CompAutonomousMech> groupedComps = null)
|
||||
{
|
||||
foreach (DroneWorkModeDef mode in DefDatabase<DroneWorkModeDef>.AllDefs.OrderBy(d => d.uiOrder))
|
||||
{
|
||||
yield return new FloatMenuOption(mode.LabelCap, delegate
|
||||
{
|
||||
comp.SetWorkMode(mode);
|
||||
if (groupedComps != null)
|
||||
{
|
||||
foreach (CompAutonomousMech groupedComp in groupedComps)
|
||||
{
|
||||
groupedComp.SetWorkMode(mode);
|
||||
}
|
||||
}
|
||||
}, mode.uiIcon, Color.white);
|
||||
}
|
||||
}
|
||||
|
||||
public override bool GroupsWith(Gizmo other)
|
||||
{
|
||||
return other is DroneGizmo;
|
||||
}
|
||||
|
||||
public override void MergeWith(Gizmo other)
|
||||
{
|
||||
base.MergeWith(other);
|
||||
if (other is DroneGizmo droneGizmo)
|
||||
{
|
||||
if (groupedComps == null)
|
||||
{
|
||||
groupedComps = new HashSet<CompAutonomousMech>();
|
||||
}
|
||||
groupedComps.Add(droneGizmo.comp);
|
||||
if (droneGizmo.groupedComps != null)
|
||||
{
|
||||
groupedComps.AddRange(droneGizmo.groupedComps);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using UnityEngine;
|
||||
using Verse;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
public class DroneWorkModeDef : Def
|
||||
{
|
||||
[NoTranslate]
|
||||
public string iconPath;
|
||||
|
||||
public Texture2D uiIcon;
|
||||
|
||||
public int uiOrder;
|
||||
|
||||
public override void PostLoad()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(iconPath))
|
||||
{
|
||||
LongEventHandler.ExecuteWhenFinished(delegate
|
||||
{
|
||||
uiIcon = ContentFinder<Texture2D>.Get(iconPath);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
using System.Collections.Generic;
|
||||
using RimWorld;
|
||||
using Verse;
|
||||
using Verse.AI;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
public class JobDriver_DroneSelfShutdown : JobDriver
|
||||
{
|
||||
public const TargetIndex RestSpotIndex = TargetIndex.A;
|
||||
|
||||
public override bool TryMakePreToilReservations(bool errorOnFailed)
|
||||
{
|
||||
return pawn.Reserve(base.TargetA, job, 1, -1, null, errorOnFailed);
|
||||
}
|
||||
|
||||
protected override IEnumerable<Toil> MakeNewToils()
|
||||
{
|
||||
yield return Toils_Goto.GotoCell(TargetIndex.A, PathEndMode.OnCell);
|
||||
Toil layDown = SelfShutdown();
|
||||
layDown.PlaySoundAtStart(SoundDefOf.MechSelfShutdown);
|
||||
yield return layDown;
|
||||
}
|
||||
|
||||
public static Toil SelfShutdown()
|
||||
{
|
||||
Toil layDown = ToilMaker.MakeToil("WULA_DroneSelfShutdown");
|
||||
layDown.initAction = delegate
|
||||
{
|
||||
Pawn actor = layDown.actor;
|
||||
actor.pather?.StopDead();
|
||||
JobDriver curDriver = actor.jobs.curDriver;
|
||||
actor.jobs.posture = PawnPosture.Standing;
|
||||
actor.mindState.lastBedDefSleptIn = null;
|
||||
curDriver.asleep = true;
|
||||
};
|
||||
layDown.defaultCompleteMode = ToilCompleteMode.Never;
|
||||
layDown.AddFinishAction(delegate
|
||||
{
|
||||
layDown.actor.jobs.curDriver.asleep = false;
|
||||
});
|
||||
return layDown;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using RimWorld;
|
||||
using Verse;
|
||||
using Verse.AI;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
public class JobGiver_DroneSelfShutdown : ThinkNode_JobGiver
|
||||
{
|
||||
protected override Job TryGiveJob(Pawn pawn)
|
||||
{
|
||||
if (RCellFinder.TryFindNearbyMechSelfShutdownSpot(pawn.Position, pawn, pawn.Map, out var result, allowForbidden: true))
|
||||
{
|
||||
Job job = JobMaker.MakeJob(WulaDefOf.WULA_DroneSelfShutdown, result);
|
||||
job.forceSleep = true;
|
||||
return job;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using RimWorld;
|
||||
using UnityEngine;
|
||||
using Verse;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
[StaticConstructorOnStartup]
|
||||
public class PawnColumnWorker_DroneEnergy : PawnColumnWorker
|
||||
{
|
||||
private const int Width = 120;
|
||||
|
||||
private const int BarPadding = 4;
|
||||
|
||||
public static readonly Texture2D EnergyBarTex = SolidColorMaterials.NewSolidColorTexture(new Color32(252, byte.MaxValue, byte.MaxValue, 65));
|
||||
|
||||
public override void DoCell(Rect rect, Pawn pawn, PawnTable table)
|
||||
{
|
||||
CompAutonomousMech comp = pawn.TryGetComp<CompAutonomousMech>();
|
||||
if (comp == null || !comp.CanBeAutonomous)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Widgets.FillableBar(rect.ContractedBy(4f), comp.GetEnergyLevel(), EnergyBarTex, BaseContent.ClearTex, doBorder: false);
|
||||
Text.Font = GameFont.Small;
|
||||
Text.Anchor = TextAnchor.MiddleCenter;
|
||||
Widgets.Label(rect, comp.GetEnergyLevel().ToStringPercent());
|
||||
Text.Anchor = TextAnchor.UpperLeft;
|
||||
Text.Font = GameFont.Small;
|
||||
}
|
||||
|
||||
public override int GetMinWidth(PawnTable table)
|
||||
{
|
||||
return Mathf.Max(base.GetMinWidth(table), 120);
|
||||
}
|
||||
|
||||
public override int GetMaxWidth(PawnTable table)
|
||||
{
|
||||
return Mathf.Min(base.GetMaxWidth(table), GetMinWidth(table));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using System.Linq;
|
||||
using RimWorld;
|
||||
using UnityEngine;
|
||||
using Verse;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
public class PawnColumnWorker_DroneWorkMode : PawnColumnWorker_Icon
|
||||
{
|
||||
protected override int Padding => 0;
|
||||
|
||||
public override void DoCell(Rect rect, Pawn pawn, PawnTable table)
|
||||
{
|
||||
CompAutonomousMech comp = pawn.TryGetComp<CompAutonomousMech>();
|
||||
if (comp == null || !comp.CanBeAutonomous)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (Widgets.ButtonInvisible(rect))
|
||||
{
|
||||
Find.WindowStack.Add(new FloatMenu(DroneGizmo.GetWorkModeOptions(comp).ToList()));
|
||||
}
|
||||
base.DoCell(rect, pawn, table);
|
||||
}
|
||||
|
||||
protected override Texture2D GetIconFor(Pawn pawn)
|
||||
{
|
||||
return pawn?.TryGetComp<CompAutonomousMech>()?.CurrentWorkMode?.uiIcon;
|
||||
}
|
||||
|
||||
protected override string GetIconTip(Pawn pawn)
|
||||
{
|
||||
string text = pawn.TryGetComp<CompAutonomousMech>()?.CurrentWorkMode?.description;
|
||||
if (!text.NullOrEmpty())
|
||||
{
|
||||
return text;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ namespace WulaFallenEmpire
|
||||
{
|
||||
public class ThinkNode_ConditionalAutonomousWorkMode : ThinkNode_Conditional
|
||||
{
|
||||
public AutonomousWorkMode requiredMode = AutonomousWorkMode.Work;
|
||||
public DroneWorkModeDef requiredMode;
|
||||
|
||||
protected override bool Satisfied(Pawn pawn)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
using Verse;
|
||||
using Verse.AI;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
public class ThinkNode_ConditionalLowEnergy_Drone : ThinkNode_Conditional
|
||||
{
|
||||
protected override bool Satisfied(Pawn pawn)
|
||||
{
|
||||
CompAutonomousMech compDrone = pawn.TryGetComp<CompAutonomousMech>();
|
||||
if (compDrone != null && compDrone.IsLowEnergy)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using RimWorld;
|
||||
using Verse;
|
||||
using Verse.AI;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
public class ThinkNode_ConditionalWorkMode_Drone : ThinkNode_Conditional
|
||||
{
|
||||
public DroneWorkModeDef workMode;
|
||||
|
||||
public override ThinkNode DeepCopy(bool resolve = true)
|
||||
{
|
||||
ThinkNode_ConditionalWorkMode_Drone thinkNode_ConditionalWorkMode_Drone = (ThinkNode_ConditionalWorkMode_Drone)base.DeepCopy(resolve);
|
||||
thinkNode_ConditionalWorkMode_Drone.workMode = workMode;
|
||||
return thinkNode_ConditionalWorkMode_Drone;
|
||||
}
|
||||
|
||||
protected override bool Satisfied(Pawn pawn)
|
||||
{
|
||||
if (!pawn.RaceProps.IsMechanoid || pawn.Faction != Faction.OfPlayer)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
CompAutonomousMech compDrone = pawn.TryGetComp<CompAutonomousMech>();
|
||||
if (compDrone == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return compDrone.CurrentWorkMode == workMode;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user