暂存
This commit is contained in:
@@ -5,23 +5,99 @@ namespace ArachnaeSwarm
|
||||
{
|
||||
public class Building_Morphable : Building
|
||||
{
|
||||
public override void Destroy(DestroyMode mode)
|
||||
private CompMorphable compMorphable;
|
||||
|
||||
public override void SpawnSetup(Map map, bool respawningAfterLoad)
|
||||
{
|
||||
var comp = this.GetComp<CompMorphable>();
|
||||
if (comp != null && comp.StoredPawn != null)
|
||||
base.SpawnSetup(map, respawningAfterLoad);
|
||||
this.compMorphable = GetComp<CompMorphable>();
|
||||
}
|
||||
|
||||
public override string Label
|
||||
{
|
||||
get
|
||||
{
|
||||
Pawn pawn = comp.StoredPawn;
|
||||
if (compMorphable?.StoredPawn != null)
|
||||
{
|
||||
return $"{base.Label} ({compMorphable.StoredPawn.LabelShort})";
|
||||
}
|
||||
return base.Label;
|
||||
}
|
||||
}
|
||||
|
||||
public override string GetInspectString()
|
||||
{
|
||||
string text = base.GetInspectString();
|
||||
if (compMorphable?.StoredPawn != null)
|
||||
{
|
||||
if (!text.NullOrEmpty())
|
||||
{
|
||||
text += "\n";
|
||||
}
|
||||
text += "StoredPawn".Translate() + ": " + compMorphable.StoredPawn.LabelShort;
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
public override void PreApplyDamage(ref DamageInfo dinfo, out bool absorbed)
|
||||
{
|
||||
// 先让基类处理,我们不打断正常流程
|
||||
base.PreApplyDamage(ref dinfo, out absorbed);
|
||||
if (absorbed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// 如果建筑即将被摧毁,则由Destroy方法处理,避免重复逻辑
|
||||
if (this.HitPoints - dinfo.Amount <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (compMorphable?.StoredPawn != null)
|
||||
{
|
||||
Pawn pawn = compMorphable.StoredPawn;
|
||||
float damageProportion = dinfo.Amount / this.def.statBases.GetStatValueFromList(StatDefOf.MaxHitPoints, 500f);
|
||||
|
||||
// --- 立即强制解除变形 ---
|
||||
Map map = this.Map;
|
||||
IntVec3 position = this.Position;
|
||||
|
||||
// 在建筑消失前,先把Pawn生成出来
|
||||
// 1. 将Pawn放回地图
|
||||
GenSpawn.Spawn(pawn, position, map, WipeMode.Vanish);
|
||||
PawnComponentsUtility.AddComponentsForSpawn(pawn);
|
||||
|
||||
// 如果是被武力摧毁,给玩家一个提示
|
||||
if (mode == DestroyMode.KillFinalize)
|
||||
// 2. 对Pawn施加等比例伤害
|
||||
float pawnDamage = pawn.MaxHitPoints * damageProportion;
|
||||
DamageInfo pawnDinfo = new DamageInfo(dinfo.Def, pawnDamage, dinfo.ArmorPenetrationInt, dinfo.Angle, dinfo.Instigator, null, dinfo.Weapon, dinfo.Category, dinfo.IntendedTarget);
|
||||
pawn.TakeDamage(pawnDinfo);
|
||||
|
||||
Messages.Message("PawnTransformer_ForcedRevert".Translate(pawn.Named("PAWN")), pawn, MessageTypeDefOf.NegativeEvent);
|
||||
|
||||
// 3. 移除建筑
|
||||
// 注意:这里不调用base.Destroy(),以避免循环和重复的恢复逻辑
|
||||
this.Destroy(DestroyMode.Vanish);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Destroy(DestroyMode mode)
|
||||
{
|
||||
// 只有在建筑还存在于地图上时,才执行恢复逻辑
|
||||
if (this.Spawned)
|
||||
{
|
||||
if (compMorphable != null && compMorphable.StoredPawn != null)
|
||||
{
|
||||
Messages.Message("PawnTransformer_BuildingDestroyed".Translate(pawn.Named("PAWN"), this.Named("BUILDING")), pawn, MessageTypeDefOf.NegativeEvent);
|
||||
Pawn pawn = compMorphable.StoredPawn;
|
||||
Map map = this.Map;
|
||||
IntVec3 position = this.Position;
|
||||
|
||||
GenSpawn.Spawn(pawn, position, map, WipeMode.Vanish);
|
||||
PawnComponentsUtility.AddComponentsForSpawn(pawn);
|
||||
|
||||
if (mode == DestroyMode.KillFinalize)
|
||||
{
|
||||
Messages.Message("PawnTransformer_BuildingDestroyed".Translate(pawn.Named("PAWN"), this.Named("BUILDING")), pawn, MessageTypeDefOf.NegativeEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
base.Destroy(mode);
|
||||
|
||||
@@ -33,17 +33,6 @@ namespace ArachnaeSwarm
|
||||
Building building = (Building)GenSpawn.Spawn(Props.buildingDef, position, map, WipeMode.Vanish);
|
||||
building.SetFaction(pawn.Faction);
|
||||
|
||||
if (pawn.Name != null)
|
||||
{
|
||||
building.TryGetComp<CompAssignableToPawn>()?.TryAssignPawn(pawn);
|
||||
}
|
||||
|
||||
var container = building.GetComp<CompThingContainer>();
|
||||
if (container != null)
|
||||
{
|
||||
container.GetDirectlyHeldThings().TryAdd(pawn);
|
||||
}
|
||||
|
||||
var newMorphComp = building.GetComp<CompMorphable>();
|
||||
if (newMorphComp != null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user