1
This commit is contained in:
@@ -83,22 +83,34 @@ namespace WulaFallenEmpire
|
||||
}
|
||||
}
|
||||
|
||||
private void PlayTransformEffects(IntVec3 position, Map map)
|
||||
{
|
||||
//// 播放转换视觉效果
|
||||
//for (int i = 0; i < 3; i++)
|
||||
//{
|
||||
// MoteMaker.ThrowSmoke(position.ToVector3Shifted() + new Vector3(0, 0, 0.5f), map, 1.5f);
|
||||
// MoteMaker.ThrowLightningGlow(position.ToVector3Shifted(), map, 2f);
|
||||
//}
|
||||
|
||||
//// 播放音效
|
||||
//SoundDefOf.PsychicPulseGlobal.PlayOneShot(new TargetInfo(position, map));
|
||||
}
|
||||
|
||||
public void TransformToPawn()
|
||||
{
|
||||
if (Recycler == null || !parent.Spawned)
|
||||
return;
|
||||
|
||||
Map map = parent.Map;
|
||||
IntVec3 position = parent.Position;
|
||||
Faction faction = parent.Faction;
|
||||
|
||||
// 记录建筑定义用于后续更新
|
||||
ThingDef buildingDef = parent.def;
|
||||
// 消耗存储的机械族
|
||||
if (!Recycler.ConsumeMechanoids(Props.requiredCapacity))
|
||||
{
|
||||
Messages.Message("WULA_NotEnoughMechs".Translate(), MessageTypeDefOf.RejectInput);
|
||||
return;
|
||||
}
|
||||
|
||||
// 生成目标Pawn
|
||||
PawnGenerationRequest request = new PawnGenerationRequest(
|
||||
Props.targetPawnKind,
|
||||
@@ -111,9 +123,8 @@ namespace WulaFallenEmpire
|
||||
canGeneratePawnRelations: false,
|
||||
mustBeCapableOfViolence: true
|
||||
);
|
||||
|
||||
Pawn newPawn = PawnGenerator.GeneratePawn(request);
|
||||
|
||||
|
||||
// 关键修改:传递当前的机械族数量(6个)
|
||||
var transformComp = newPawn.GetComp<CompTransformIntoBuilding>();
|
||||
if (transformComp != null)
|
||||
@@ -136,37 +147,24 @@ namespace WulaFallenEmpire
|
||||
// 传递建筑定义和机械族数量
|
||||
transformComp.SetRestoreData(parent.def, Props.requiredCapacity);
|
||||
}
|
||||
|
||||
// 移除建筑
|
||||
parent.DeSpawn(DestroyMode.Vanish);
|
||||
|
||||
|
||||
// 生成Pawn
|
||||
GenSpawn.Spawn(newPawn, position, map, WipeMode.Vanish);
|
||||
|
||||
|
||||
// 选中新生成的Pawn
|
||||
if (Find.Selector.IsSelected(parent))
|
||||
{
|
||||
Find.Selector.Select(newPawn);
|
||||
}
|
||||
|
||||
Messages.Message("WULA_BuildingTransformedToPawn".Translate(parent.Label, newPawn.LabelCap, Props.requiredCapacity),
|
||||
Messages.Message("WULA_BuildingTransformedToPawn".Translate(parent.Label, newPawn.LabelCap, Props.requiredCapacity),
|
||||
MessageTypeDefOf.PositiveEvent);
|
||||
|
||||
|
||||
// 播放转换效果
|
||||
PlayTransformEffects(position, map);
|
||||
}
|
||||
|
||||
private void PlayTransformEffects(IntVec3 position, Map map)
|
||||
{
|
||||
//// 播放转换视觉效果
|
||||
//for (int i = 0; i < 3; i++)
|
||||
//{
|
||||
// MoteMaker.ThrowSmoke(position.ToVector3Shifted() + new Vector3(0, 0, 0.5f), map, 1.5f);
|
||||
// MoteMaker.ThrowLightningGlow(position.ToVector3Shifted(), map, 2f);
|
||||
//}
|
||||
|
||||
//// 播放音效
|
||||
//SoundDefOf.PsychicPulseGlobal.PlayOneShot(new TargetInfo(position, map));
|
||||
Log.Message($"[TransformSystem] Building -> Pawn transformation completed at {position}. Path grid updated.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,6 @@ namespace WulaFallenEmpire
|
||||
|
||||
// 显示恢复的机械族数量
|
||||
sb.AppendLine();
|
||||
sb.Append("WULA_RestoreMechCount".Translate(restoreMechCount));
|
||||
|
||||
// 显示目标建筑的最大存储容量
|
||||
var recyclerProps = restoreBuildingDef.GetCompProperties<CompProperties_MechanoidRecycler>();
|
||||
@@ -195,88 +194,6 @@ namespace WulaFallenEmpire
|
||||
return false;
|
||||
}
|
||||
|
||||
public void TransformToBuilding()
|
||||
{
|
||||
if (Pawn == null || !Pawn.Spawned)
|
||||
return;
|
||||
|
||||
Map map = Pawn.Map;
|
||||
IntVec3 desiredPosition = Pawn.Position;
|
||||
Faction faction = Pawn.Faction;
|
||||
|
||||
// 确定要生成的建筑类型
|
||||
ThingDef buildingDef = restoreBuildingDef ?? Props.targetBuildingDef;
|
||||
if (buildingDef == null)
|
||||
{
|
||||
Messages.Message("WULA_CannotDetermineBuildingType".Translate(), MessageTypeDefOf.RejectInput);
|
||||
return;
|
||||
}
|
||||
|
||||
// 最终校验(排除被转换的Pawn本身)
|
||||
string failReason;
|
||||
if (!TransformValidationUtility.CanPlaceBuildingAt(buildingDef, desiredPosition, map, faction, Pawn, out failReason))
|
||||
{
|
||||
// 尝试寻找附近的位置
|
||||
IntVec3 alternativePosition;
|
||||
if (TryFindNearbyValidPosition(out alternativePosition, out failReason))
|
||||
{
|
||||
desiredPosition = alternativePosition;
|
||||
Messages.Message("WULA_DeployingAtNearbyPosition".Translate(desiredPosition), MessageTypeDefOf.NeutralEvent);
|
||||
}
|
||||
else
|
||||
{
|
||||
Messages.Message("WULA_CannotDeployBuilding".Translate(failReason), MessageTypeDefOf.RejectInput);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 移除Pawn
|
||||
Pawn.DeSpawn(DestroyMode.Vanish);
|
||||
|
||||
// 生成建筑
|
||||
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>();
|
||||
if (transformComp == null)
|
||||
{
|
||||
// 动态添加组件
|
||||
var compProps = new CompProperties_TransformAtFullCapacity
|
||||
{
|
||||
targetPawnKind = Pawn.kindDef
|
||||
};
|
||||
transformComp = new CompTransformAtFullCapacity();
|
||||
transformComp.parent = newBuilding;
|
||||
transformComp.props = compProps;
|
||||
newBuilding.AllComps.Add(transformComp);
|
||||
transformComp.Initialize(compProps);
|
||||
}
|
||||
|
||||
// 选中新生成的建筑
|
||||
if (Find.Selector.IsSelected(Pawn))
|
||||
{
|
||||
Find.Selector.Select(newBuilding);
|
||||
}
|
||||
|
||||
Messages.Message("WULA_PawnDeployedAsBuilding".Translate(Pawn.LabelCap, newBuilding.Label, restoreMechCount),
|
||||
MessageTypeDefOf.PositiveEvent);
|
||||
|
||||
// 播放转换效果
|
||||
PlayTransformEffects(desiredPosition, map);
|
||||
|
||||
// 清除缓存
|
||||
lastValidationResult = null;
|
||||
lastValidationReason = null;
|
||||
}
|
||||
|
||||
private void PlayTransformEffects(IntVec3 position, Map map)
|
||||
{
|
||||
// 播放转换视觉效果
|
||||
@@ -298,5 +215,80 @@ namespace WulaFallenEmpire
|
||||
lastValidationResult = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void TransformToBuilding()
|
||||
{
|
||||
if (Pawn == null || !Pawn.Spawned)
|
||||
return;
|
||||
Map map = Pawn.Map;
|
||||
IntVec3 desiredPosition = Pawn.Position;
|
||||
Faction faction = Pawn.Faction;
|
||||
// 确定要生成的建筑类型
|
||||
ThingDef buildingDef = restoreBuildingDef ?? Props.targetBuildingDef;
|
||||
if (buildingDef == null)
|
||||
{
|
||||
Messages.Message("WULA_CannotDetermineBuildingType".Translate(), MessageTypeDefOf.RejectInput);
|
||||
return;
|
||||
}
|
||||
// 最终校验(排除被转换的Pawn本身)
|
||||
string failReason;
|
||||
if (!TransformValidationUtility.CanPlaceBuildingAt(buildingDef, desiredPosition, map, faction, Pawn, out failReason))
|
||||
{
|
||||
// 尝试寻找附近的位置
|
||||
IntVec3 alternativePosition;
|
||||
if (TryFindNearbyValidPosition(out alternativePosition, out failReason))
|
||||
{
|
||||
desiredPosition = alternativePosition;
|
||||
Messages.Message("WULA_DeployingAtNearbyPosition".Translate(desiredPosition), MessageTypeDefOf.NeutralEvent);
|
||||
}
|
||||
else
|
||||
{
|
||||
Messages.Message("WULA_CannotDeployBuilding".Translate(failReason), MessageTypeDefOf.RejectInput);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// 移除Pawn
|
||||
Pawn.DeSpawn(DestroyMode.Vanish);
|
||||
// 生成建筑
|
||||
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>();
|
||||
if (transformComp == null)
|
||||
{
|
||||
// 动态添加组件
|
||||
var compProps = new CompProperties_TransformAtFullCapacity
|
||||
{
|
||||
targetPawnKind = Pawn.kindDef
|
||||
};
|
||||
transformComp = new CompTransformAtFullCapacity();
|
||||
transformComp.parent = newBuilding;
|
||||
transformComp.props = compProps;
|
||||
newBuilding.AllComps.Add(transformComp);
|
||||
transformComp.Initialize(compProps);
|
||||
}
|
||||
// 选中新生成的建筑
|
||||
if (Find.Selector.IsSelected(Pawn))
|
||||
{
|
||||
Find.Selector.Select(newBuilding);
|
||||
}
|
||||
Messages.Message("WULA_PawnDeployedAsBuilding".Translate(Pawn.LabelCap, newBuilding.Label, restoreMechCount),
|
||||
MessageTypeDefOf.PositiveEvent);
|
||||
|
||||
// 播放转换效果
|
||||
PlayTransformEffects(desiredPosition, map);
|
||||
|
||||
// 清除缓存
|
||||
lastValidationResult = null;
|
||||
lastValidationReason = null;
|
||||
|
||||
Log.Message($"[TransformSystem] Pawn -> Building transformation completed at {desiredPosition}. Path grid updated.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user