暂存
This commit is contained in:
Binary file not shown.
@@ -24,9 +24,21 @@ namespace ArachnaeSwarm
|
||||
// return;
|
||||
// }
|
||||
|
||||
Log.Message("[夺舍] Apply方法开始执行。施法者: " + caster.LabelShort + ", 目标: " + targetPawn.LabelShort);
|
||||
|
||||
Log.Message("[夺舍] 步骤1: 创建Hediff实例...");
|
||||
Hediff_Possession hediff = (Hediff_Possession)HediffMaker.MakeHediff(HediffDef.Named("ARA_Possession"), targetPawn);
|
||||
hediff.SetCaster(caster);
|
||||
|
||||
Log.Message("[夺舍] 步骤2: 将施法者 " + caster.LabelShort + " 安全地转移到Hediff容器中...");
|
||||
// 使用标准的游戏框架方法,将施法者从其当前的持有者(地图)转移到Hediff的内部容器中。
|
||||
// 这会自动处理施法者从地图上消失的逻辑。
|
||||
caster.holdingOwner.TryTransferToContainer(caster, hediff.GetDirectlyHeldThings(), 1);
|
||||
|
||||
Log.Message("[夺舍] 步骤3: 调用Hediff的PostPossessionApply方法来执行数据覆盖...");
|
||||
// 我们创建一个新的方法来处理夺舍后的逻辑,而不是依赖PostAdd
|
||||
hediff.PostPossessionApply(caster, targetPawn);
|
||||
|
||||
Log.Message("[夺舍] 步骤4: 将Hediff添加到目标Pawn身上...");
|
||||
targetPawn.health.AddHediff(hediff);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,27 +28,19 @@ namespace ArachnaeSwarm
|
||||
return innerContainer;
|
||||
}
|
||||
|
||||
public override void PostAdd(DamageInfo? dinfo)
|
||||
// PostAdd在游戏加载时也会被调用,因此不适合放置一次性的夺舍逻辑。
|
||||
// 我们创建一个新的公共方法,由CompAbilityEffect在正确的时机调用。
|
||||
public void PostPossessionApply(Pawn caster, Pawn target)
|
||||
{
|
||||
base.PostAdd(dinfo);
|
||||
|
||||
if (this.originalCaster == null)
|
||||
{
|
||||
Log.Error("Hediff_Possession was added without an original caster.");
|
||||
return;
|
||||
}
|
||||
|
||||
// 正确的做法:从原始施法者身上“分裂”出一个副本存入容器
|
||||
// 这确保了容器里的是一个独立的对象,而不是一个会被销毁的引用
|
||||
this.innerContainer.TryAdd(this.originalCaster.SplitOff(1), true);
|
||||
PawnDataUtility.TransferSoul(this.originalCaster, this.pawn);
|
||||
|
||||
if (!this.originalCaster.Destroyed)
|
||||
{
|
||||
this.originalCaster.Destroy(DestroyMode.Vanish);
|
||||
}
|
||||
Log.Message("[夺舍] Hediff.PostPossessionApply 开始执行,施法者: " + caster.LabelShort + ", 目标: " + target.LabelShort);
|
||||
|
||||
Log.Message($"{this.pawn.LabelShort} has been possessed by {StoredCasterPawn.LabelShort}!");
|
||||
// 将施法者的引用保存下来,用于将来的重生逻辑
|
||||
this.originalCaster = caster;
|
||||
|
||||
Log.Message("[夺舍] 步骤5: 调用 TransferSoul 将灵魂从 " + caster.LabelShort + " 转移到 " + target.LabelShort);
|
||||
PawnDataUtility.TransferSoul(caster, target);
|
||||
|
||||
Log.Message($"[夺舍] {target.LabelShort} 已被 {StoredCasterPawn.LabelShort} 夺舍成功!");
|
||||
}
|
||||
|
||||
public override void Notify_PawnDied(DamageInfo? dinfo, Hediff culprit = null)
|
||||
|
||||
@@ -56,11 +56,10 @@ namespace ArachnaeSwarm
|
||||
{
|
||||
foreach (RecordDef recordDef in DefDatabase<RecordDef>.AllDefs)
|
||||
{
|
||||
// Correct way: Get value from source and add the difference to target.
|
||||
// This effectively sets the value.
|
||||
float sourceValue = soulSource.records.GetValue(recordDef);
|
||||
float targetValue = bodyTarget.records.GetValue(recordDef);
|
||||
bodyTarget.records.AddTo(recordDef, sourceValue - targetValue);
|
||||
// For Time records, we must set them directly to avoid warnings.
|
||||
// The AddTo(delta) trick works for all types and is the standard way to "set" a value.
|
||||
bodyTarget.records.AddTo(recordDef, sourceValue - bodyTarget.records.GetValue(recordDef));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user