新机械体
This commit is contained in:
@@ -4,6 +4,7 @@ using System.Text;
|
||||
using UnityEngine;
|
||||
using Verse;
|
||||
using Verse.AI;
|
||||
using LudeonTK;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
@@ -222,6 +223,23 @@ namespace WulaFallenEmpire
|
||||
}
|
||||
|
||||
yield return spawnCommand;
|
||||
|
||||
// 开发模式按钮:立即结束冷却
|
||||
if (Prefs.DevMode && IsCooldownActive)
|
||||
{
|
||||
Command_Action devCommand = new Command_Action
|
||||
{
|
||||
defaultLabel = "Dev: 立即结束冷却",
|
||||
defaultDesc = "立即结束转换冷却时间",
|
||||
action = () =>
|
||||
{
|
||||
// 将生成时间设置为足够早,使冷却立即结束
|
||||
spawnTick = Find.TickManager.TicksGame - (24 * 2500 + 1);
|
||||
Messages.Message("转换冷却已立即结束", MessageTypeDefOf.SilentInput);
|
||||
}
|
||||
};
|
||||
yield return devCommand;
|
||||
}
|
||||
}
|
||||
|
||||
// 回收附近机械族
|
||||
@@ -334,6 +352,22 @@ namespace WulaFallenEmpire
|
||||
return Mathf.Max(0, remainingTicks / 2500f);
|
||||
}
|
||||
|
||||
// 开发模式方法:立即结束冷却
|
||||
[DebugAction("机械族回收器", "立即结束冷却", actionType = DebugActionType.Action, allowedGameStates = AllowedGameStates.Playing)]
|
||||
public static void DevEndCooldown()
|
||||
{
|
||||
Building_MechanoidRecycler selectedRecycler = Find.Selector.SingleSelectedThing as Building_MechanoidRecycler;
|
||||
if (selectedRecycler != null)
|
||||
{
|
||||
selectedRecycler.spawnTick = Find.TickManager.TicksGame - (24 * 2500 + 1);
|
||||
Messages.Message("转换冷却已立即结束", MessageTypeDefOf.SilentInput);
|
||||
}
|
||||
else
|
||||
{
|
||||
Messages.Message("请先选择一个机械族回收器", MessageTypeDefOf.RejectInput);
|
||||
}
|
||||
}
|
||||
|
||||
public override void ExposeData()
|
||||
{
|
||||
base.ExposeData();
|
||||
|
||||
@@ -6,6 +6,7 @@ namespace WulaFallenEmpire
|
||||
public class Skyfaller_PrefabSpawner : Skyfaller
|
||||
{
|
||||
public string prefabDefName;
|
||||
private Faction prefabFaction; // 缓存派系信息
|
||||
|
||||
protected override void SpawnThings()
|
||||
{
|
||||
@@ -23,8 +24,30 @@ namespace WulaFallenEmpire
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取派系信息
|
||||
Faction faction = GetPrefabFaction();
|
||||
|
||||
// Correct parameter order based on compiler error: prefabDef, map, position, rotation
|
||||
PrefabUtility.SpawnPrefab(prefabDef, base.Map, base.Position, base.Rotation);
|
||||
PrefabUtility.SpawnPrefab(prefabDef, base.Map, base.Position, base.Rotation, faction);
|
||||
}
|
||||
|
||||
private Faction GetPrefabFaction()
|
||||
{
|
||||
// 如果已经缓存了派系信息,直接返回
|
||||
if (prefabFaction != null)
|
||||
return prefabFaction;
|
||||
|
||||
// 检查是否有 CompSkyfallerFaction 组件
|
||||
var factionComp = this.TryGetComp<CompSkyfallerFaction>();
|
||||
if (factionComp != null)
|
||||
{
|
||||
prefabFaction = factionComp.GetFactionForPrefab();
|
||||
return prefabFaction;
|
||||
}
|
||||
|
||||
// 如果没有组件,默认使用玩家派系
|
||||
prefabFaction = Faction.OfPlayer;
|
||||
return prefabFaction;
|
||||
}
|
||||
|
||||
public override void ExposeData()
|
||||
@@ -33,4 +56,4 @@ namespace WulaFallenEmpire
|
||||
Scribe_Values.Look(ref prefabDefName, "prefabDefName");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
using RimWorld;
|
||||
using Verse;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
public class CompProperties_SkyfallerFaction : CompProperties
|
||||
{
|
||||
public FactionDef factionDef;
|
||||
public bool usePlayerFactionIfNull = true; // 如果 factionDef 为 null 时使用玩家派系
|
||||
|
||||
public CompProperties_SkyfallerFaction()
|
||||
{
|
||||
compClass = typeof(CompSkyfallerFaction);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using RimWorld;
|
||||
using Verse;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
public class CompSkyfallerFaction : ThingComp
|
||||
{
|
||||
public CompProperties_SkyfallerFaction Props => (CompProperties_SkyfallerFaction)props;
|
||||
|
||||
public Faction GetFactionForPrefab()
|
||||
{
|
||||
// 如果指定了派系定义,使用该派系
|
||||
if (Props.factionDef != null)
|
||||
{
|
||||
Faction faction = Find.FactionManager.FirstFactionOfDef(Props.factionDef);
|
||||
if (faction != null)
|
||||
return faction;
|
||||
}
|
||||
|
||||
// 如果没有指定派系定义,根据设置决定
|
||||
if (Props.usePlayerFactionIfNull)
|
||||
{
|
||||
return Faction.OfPlayer;
|
||||
}
|
||||
|
||||
// 如果都不满足,返回 null(使用默认行为)
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -114,12 +114,12 @@ namespace WulaFallenEmpire
|
||||
|
||||
Pawn newPawn = PawnGenerator.GeneratePawn(request);
|
||||
|
||||
// 添加转换组件,只传递建筑定义,不传递数量
|
||||
// 关键修改:传递当前的机械族数量(6个)
|
||||
var transformComp = newPawn.GetComp<CompTransformIntoBuilding>();
|
||||
if (transformComp != null)
|
||||
{
|
||||
// 只设置建筑定义,不设置恢复数量
|
||||
transformComp.SetRestoreData(parent.def);
|
||||
// 传递建筑定义和机械族数量
|
||||
transformComp.SetRestoreData(parent.def, Props.requiredCapacity);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -133,8 +133,8 @@ namespace WulaFallenEmpire
|
||||
transformComp.props = compProps;
|
||||
newPawn.AllComps.Add(transformComp);
|
||||
transformComp.Initialize(compProps);
|
||||
// 只设置建筑定义,不设置恢复数量
|
||||
transformComp.SetRestoreData(parent.def);
|
||||
// 传递建筑定义和机械族数量
|
||||
transformComp.SetRestoreData(parent.def, Props.requiredCapacity);
|
||||
}
|
||||
|
||||
// 移除建筑
|
||||
@@ -149,7 +149,8 @@ namespace WulaFallenEmpire
|
||||
Find.Selector.Select(newPawn);
|
||||
}
|
||||
|
||||
Messages.Message("WULA_BuildingTransformedToPawn".Translate(parent.Label, newPawn.LabelCap), MessageTypeDefOf.PositiveEvent);
|
||||
Messages.Message("WULA_BuildingTransformedToPawn".Translate(parent.Label, newPawn.LabelCap, Props.requiredCapacity),
|
||||
MessageTypeDefOf.PositiveEvent);
|
||||
|
||||
// 播放转换效果
|
||||
PlayTransformEffects(position, map);
|
||||
|
||||
@@ -11,8 +11,9 @@ namespace WulaFallenEmpire
|
||||
private CompProperties_TransformIntoBuilding Props => (CompProperties_TransformIntoBuilding)props;
|
||||
private Pawn Pawn => (Pawn)parent;
|
||||
|
||||
// 恢复数据 - 只存储建筑定义,不存储数量
|
||||
// 恢复数据 - 存储建筑定义和机械族数量
|
||||
private ThingDef restoreBuildingDef;
|
||||
private int restoreMechCount = 6; // 默认6个,符合你的需求
|
||||
|
||||
// 缓存校验结果
|
||||
private bool? lastValidationResult = null;
|
||||
@@ -28,13 +29,14 @@ namespace WulaFallenEmpire
|
||||
{
|
||||
base.PostExposeData();
|
||||
Scribe_Defs.Look(ref restoreBuildingDef, "restoreBuildingDef");
|
||||
// 移除存储数量的保存
|
||||
Scribe_Values.Look(ref restoreMechCount, "restoreMechCount", 6); // 默认6个
|
||||
}
|
||||
|
||||
// 设置恢复数据 - 只设置建筑定义
|
||||
public void SetRestoreData(ThingDef buildingDef)
|
||||
// 设置恢复数据 - 设置建筑定义和机械族数量
|
||||
public void SetRestoreData(ThingDef buildingDef, int mechCount = 6)
|
||||
{
|
||||
restoreBuildingDef = buildingDef;
|
||||
restoreMechCount = mechCount;
|
||||
}
|
||||
|
||||
public override IEnumerable<Gizmo> CompGetGizmosExtra()
|
||||
@@ -73,6 +75,10 @@ namespace WulaFallenEmpire
|
||||
sb.AppendLine();
|
||||
sb.Append("WULA_WillRestoreTo".Translate(restoreBuildingDef.LabelCap));
|
||||
|
||||
// 显示恢复的机械族数量
|
||||
sb.AppendLine();
|
||||
sb.Append("WULA_RestoreMechCount".Translate(restoreMechCount));
|
||||
|
||||
// 显示目标建筑的最大存储容量
|
||||
var recyclerProps = restoreBuildingDef.GetCompProperties<CompProperties_MechanoidRecycler>();
|
||||
if (recyclerProps != null)
|
||||
@@ -231,8 +237,12 @@ namespace WulaFallenEmpire
|
||||
Building newBuilding = (Building)GenSpawn.Spawn(buildingDef, desiredPosition, map, WipeMode.Vanish);
|
||||
newBuilding.SetFaction(faction);
|
||||
|
||||
// 不再恢复机械族计数,新建筑为空状态
|
||||
// 如果需要,可以在这里设置初始状态,但不再传递之前的数量
|
||||
// 关键修改:恢复机械族数量
|
||||
var recycler = newBuilding as Building_MechanoidRecycler;
|
||||
if (recycler != null)
|
||||
{
|
||||
recycler.SetMechanoidCount(restoreMechCount);
|
||||
}
|
||||
|
||||
// 添加建筑转换组件
|
||||
var transformComp = newBuilding.TryGetComp<CompTransformAtFullCapacity>();
|
||||
@@ -256,7 +266,8 @@ namespace WulaFallenEmpire
|
||||
Find.Selector.Select(newBuilding);
|
||||
}
|
||||
|
||||
Messages.Message("WULA_PawnDeployedAsBuilding".Translate(Pawn.LabelCap, newBuilding.Label), MessageTypeDefOf.PositiveEvent);
|
||||
Messages.Message("WULA_PawnDeployedAsBuilding".Translate(Pawn.LabelCap, newBuilding.Label, restoreMechCount),
|
||||
MessageTypeDefOf.PositiveEvent);
|
||||
|
||||
// 播放转换效果
|
||||
PlayTransformEffects(desiredPosition, map);
|
||||
|
||||
@@ -124,6 +124,8 @@
|
||||
<Compile Include="BuildingComp\WULA_SkyfallerCaller\CompProperties_PrefabSkyfallerCaller.cs" />
|
||||
<Compile Include="BuildingComp\WULA_SkyfallerCaller\Skyfaller_PrefabSpawner.cs" />
|
||||
<Compile Include="BuildingComp\WULA_SkyfallerCaller\WulaSkyfallerWorldComponent.cs" />
|
||||
<Compile Include="BuildingComp\WULA_SkyfallerCaller\WULA_SkyfallerFactioncs\CompProperties_SkyfallerFaction.cs" />
|
||||
<Compile Include="BuildingComp\WULA_SkyfallerCaller\WULA_SkyfallerFactioncs\CompSkyfallerFaction.cs" />
|
||||
<Compile Include="BuildingComp\WULA_StorageTurret\CompProperties_StorageTurret.cs" />
|
||||
<Compile Include="BuildingComp\WULA_StorageTurret\CompStorageTurret.cs" />
|
||||
<Compile Include="BuildingComp\WULA_TransformAtFullCapacity\CompProperties_TransformAtFullCapacity.cs" />
|
||||
|
||||
Reference in New Issue
Block a user