155 lines
4.8 KiB
C#
155 lines
4.8 KiB
C#
using RimWorld;
|
|
using Verse;
|
|
using System.Collections.Generic;
|
|
using Verse.AI;
|
|
using UnityEngine;
|
|
using AlienRace;
|
|
using System; // 添加 System 命名空间用于 Action 类型
|
|
using System.Text; // 添加 System.Text 命名空间用于 StringBuilder
|
|
using System.Linq; // 添加 System.Linq 命名空间用于 Any() 方法
|
|
|
|
namespace ArachnaeSwarm
|
|
{
|
|
public class CompProperties_PowerArmorStation : CompProperties
|
|
{
|
|
public ThingDef apparelDef;
|
|
public bool enableRaceRestrictionCheck = true;
|
|
public string customRestrictionMessage;
|
|
|
|
public CompProperties_PowerArmorStation()
|
|
{
|
|
compClass = typeof(CompPowerArmorStation);
|
|
}
|
|
}
|
|
|
|
public class CompPowerArmorStation : ThingComp
|
|
{
|
|
public CompProperties_PowerArmorStation Props => (CompProperties_PowerArmorStation)props;
|
|
|
|
public override void CompTick()
|
|
{
|
|
base.CompTick();
|
|
var fuelComp = parent.GetComp<CompRefuelableNutrition>();
|
|
if (fuelComp != null)
|
|
{
|
|
fuelComp.currentConsumptionRate = 0f;
|
|
}
|
|
}
|
|
|
|
// 使用 Alien Race 框架提供的静态方法检查装备限制
|
|
private AcceptanceReport CheckRaceRestriction(Pawn pawn, ThingDef apparelDef)
|
|
{
|
|
if (pawn == null || apparelDef == null)
|
|
return true;
|
|
|
|
if (!Props.enableRaceRestrictionCheck)
|
|
return true;
|
|
|
|
// 使用 Alien Race 框架的 CanWear 方法
|
|
bool canWear = RaceRestrictionSettings.CanWear(apparelDef, pawn.def);
|
|
|
|
if (!canWear)
|
|
{
|
|
if (!Props.customRestrictionMessage.NullOrEmpty())
|
|
{
|
|
return Props.customRestrictionMessage.Translate(pawn.def.label, apparelDef.label);
|
|
}
|
|
|
|
return "ARA_PowerArmorForbiddenByRace".Translate(pawn.def.label, apparelDef.label);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public AcceptanceReport CanPawnEnter(Pawn pawn)
|
|
{
|
|
// 基础可达性检查
|
|
if (!pawn.CanReserveAndReach(parent, PathEndMode.InteractionCell, Danger.Deadly))
|
|
{
|
|
return "CannotReach".Translate();
|
|
}
|
|
|
|
if (Props.apparelDef == null)
|
|
{
|
|
return "ARA_NoApparelDefined".Translate();
|
|
}
|
|
|
|
// 使用 Alien Race 框架的方法检查种族限制
|
|
AcceptanceReport raceCheck = CheckRaceRestriction(pawn, Props.apparelDef);
|
|
if (!raceCheck.Accepted)
|
|
{
|
|
return raceCheck;
|
|
}
|
|
|
|
// 检查是否已经穿戴了同类型装备
|
|
if (pawn.apparel?.WornApparel?.Any(a => a.def == Props.apparelDef) == true)
|
|
{
|
|
return "ARA_AlreadyWearingSameApparel".Translate(Props.apparelDef.label);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public override IEnumerable<FloatMenuOption> CompFloatMenuOptions(Pawn selPawn)
|
|
{
|
|
foreach (FloatMenuOption option in base.CompFloatMenuOptions(selPawn))
|
|
{
|
|
yield return option;
|
|
}
|
|
|
|
if (Props.apparelDef == null)
|
|
{
|
|
yield break;
|
|
}
|
|
|
|
AcceptanceReport canEnter = CanPawnEnter(selPawn);
|
|
|
|
string label = "ARA_EnterPowerArmor".Translate(parent.Label);
|
|
if (!canEnter.Accepted)
|
|
{
|
|
label += ": " + canEnter.Reason;
|
|
}
|
|
|
|
Action enterAction = null;
|
|
if (canEnter.Accepted)
|
|
{
|
|
enterAction = () =>
|
|
{
|
|
Job job = JobMaker.MakeJob(DefDatabase<JobDef>.GetNamed("ARA_EnterPowerArmor"), parent);
|
|
selPawn.jobs.TryTakeOrderedJob(job, JobTag.Misc);
|
|
};
|
|
}
|
|
|
|
yield return new FloatMenuOption(label, enterAction)
|
|
{
|
|
Disabled = !canEnter.Accepted
|
|
};
|
|
}
|
|
|
|
public override string CompInspectStringExtra()
|
|
{
|
|
StringBuilder sb = new StringBuilder();
|
|
string baseString = base.CompInspectStringExtra();
|
|
|
|
if (!string.IsNullOrEmpty(baseString))
|
|
sb.Append(baseString);
|
|
|
|
if (Props.apparelDef != null)
|
|
{
|
|
if (sb.Length > 0)
|
|
sb.AppendLine();
|
|
|
|
sb.Append("ARA_PowerArmorStationApparel".Translate(Props.apparelDef.label));
|
|
|
|
if (Props.enableRaceRestrictionCheck)
|
|
{
|
|
sb.AppendLine();
|
|
sb.Append("ARA_RaceRestrictionEnabled".Translate());
|
|
}
|
|
}
|
|
|
|
return sb.ToString();
|
|
}
|
|
}
|
|
}
|