This commit is contained in:
2025-11-21 11:50:58 +08:00
parent 4a44ad5005
commit 635d587a9b
16 changed files with 936 additions and 130 deletions

View File

@@ -21,9 +21,6 @@ namespace WulaFallenEmpire
Map map = parent.pawn.MapHeld;
if (map == null) return;
// 播放发射特效(在施法者位置)- 在释放瞬间播放
//PlayCastEffecter(target, map);
// 获取扇形区域内的所有单元格
List<IntVec3> affectedCells = AffectedCells(target);
@@ -56,38 +53,15 @@ namespace WulaFallenEmpire
// 为每个受影响的目标播放命中效果器并处理效果
foreach (Thing affectedThing in affectedTargets)
{
PlayHitEffecter(affectedThing, map);
// 只对建筑和Pawn播放命中特效
if (affectedThing is Building || affectedThing is Pawn)
{
PlayHitEffecter(affectedThing, map);
}
ProcessTarget(affectedThing);
}
}
private void PlayCastEffecter(LocalTargetInfo target, Map map)
{
try
{
if (Props.castEffecter == null) return;
// 在释放瞬间创建效果器,确保正确的方向
Effecter effecter = Props.castEffecter.Spawn(Pawn.Position, target.Cell, map);
if (Props.castEffecterMaintainTicks > 0)
{
// 使用与参考代码相同的方法来维持效果器
parent.AddEffecterToMaintain(effecter, Pawn.Position, target.Cell, Props.castEffecterMaintainTicks, map);
}
else
{
effecter.Cleanup();
}
Log.Message($"[AreaDestruction] Played cast effecter from {Pawn.Position} to {target.Cell}");
}
catch (System.Exception ex)
{
Log.Warning($"[AreaDestruction] Error playing cast effecter: {ex.Message}");
}
}
private void PlayHitEffecter(Thing target, Map map)
{
try
@@ -99,7 +73,6 @@ namespace WulaFallenEmpire
Vector3 directionFromCaster = (target.Position.ToVector3Shifted() - Pawn.Position.ToVector3Shifted()).normalized;
// 计算反向位置:目标位置 + 反向向量 * 距离
// 这样特效会从目标位置向施法者的反方向播放
IntVec3 reversePosition = target.Position + new IntVec3(
Mathf.RoundToInt(-directionFromCaster.x * 2f),
0,
@@ -110,7 +83,6 @@ namespace WulaFallenEmpire
reversePosition = reversePosition.ClampInsideMap(map);
// 使用两个位置参数来设置效果器方向
// 从目标位置到反向位置,这样特效会向施法者反方向播放
Effecter effecter = Props.hitEffecter.Spawn(target.Position, reversePosition, map);
if (Props.hitEffecterMaintainTicks > 0)
@@ -123,7 +95,8 @@ namespace WulaFallenEmpire
effecter.Cleanup();
}
Log.Message($"[AreaDestruction] Played hit effecter on {target.Label} at {target.Position} with reverse direction to {reversePosition}");
// 可选:记录日志用于调试
// Log.Message($"[AreaDestruction] Played hit effecter on {target.Label} at {target.Position}");
}
catch (System.Exception ex)
{
@@ -156,10 +129,15 @@ namespace WulaFallenEmpire
{
DestroyAllBodyParts(targetPawn);
}
// 其他类型的物体(如物品、植物等)不进行处理
}
private bool ShouldAffectThing(Thing thing)
{
// 只影响建筑和Pawn
if (!(thing is Building) && !(thing is Pawn))
return false;
// 检查是否影响施法者自己
if (thing == Pawn && !Props.affectCaster)
return false;
@@ -190,7 +168,8 @@ namespace WulaFallenEmpire
// 直接销毁建筑
building.Destroy(DestroyMode.Vanish);
Log.Message($"[AreaDestruction] Destroyed building: {buildingInfo}");
// 可选:记录日志用于调试
// Log.Message($"[AreaDestruction] Destroyed building: {buildingInfo}");
}
catch (System.Exception ex)
{
@@ -213,7 +192,7 @@ namespace WulaFallenEmpire
int partsDestroyed = 0;
foreach (var bodyPartRecord in bodyPartRecords)
{
// 跳过核心部位以避免立即死亡(可选,根据需求调整)
// 跳过核心部位以避免立即死亡
if (IsCoreBodyPart(bodyPartRecord)) continue;
// 检查该部位是否已经缺失
@@ -231,7 +210,8 @@ namespace WulaFallenEmpire
// 检查pawn是否还"活着"(没有核心部位缺失时可能还能存活)
CheckPawnViability(targetPawn);
Log.Message($"[AreaDestruction] Destroyed {partsDestroyed} body parts on {pawnInfo}");
// 可选:记录日志用于调试
// Log.Message($"[AreaDestruction] Destroyed {partsDestroyed} body parts on {pawnInfo}");
}
}
catch (System.Exception ex)
@@ -290,7 +270,7 @@ namespace WulaFallenEmpire
List<Thing> thingList = cell.GetThingList(Pawn.Map);
for (int i = 0; i < thingList.Count; i++)
{
if (thingList[i].Faction == Pawn.Faction)
if (thingList[i] is Pawn pawn && pawn.Faction == Pawn.Faction)
{
return false;
}

View File

@@ -0,0 +1,108 @@
using RimWorld;
using Verse;
namespace WulaFallenEmpire
{
public class CompAbilityEffect_SpawnAligned : CompAbilityEffect_Spawn
{
public new CompProperties_AbilitySpawnAligned Props => (CompProperties_AbilitySpawnAligned)props;
public override void Apply(LocalTargetInfo target, LocalTargetInfo dest)
{
base.Apply(target, dest);
// 获取刚刚生成的物品
Thing spawnedThing = target.Cell.GetFirstThing(parent.pawn.Map, Props.thingDef);
if (spawnedThing != null && Props.alignFaction)
{
AlignThingFaction(spawnedThing);
}
}
/// <summary>
/// 将生成的物品与施法者阵营对齐
/// </summary>
private void AlignThingFaction(Thing spawnedThing)
{
Faction casterFaction = parent.pawn.Faction;
// 处理生物
if (spawnedThing is Pawn spawnedPawn)
{
AlignPawnFaction(spawnedPawn, casterFaction);
}
// 处理建筑
else if (spawnedThing is Building building)
{
AlignBuildingFaction(building, casterFaction);
}
// 处理其他有阵营的物品
else
{
AlignThingWithCompsFaction(spawnedThing, casterFaction);
}
}
/// <summary>
/// 对齐生物阵营
/// </summary>
private void AlignPawnFaction(Pawn pawn, Faction casterFaction)
{
// 设置生物阵营
if (pawn.Faction != casterFaction)
{
pawn.SetFaction(casterFaction);
}
// 如果是野生动物,尝试驯服
if (pawn.Faction == null && pawn.RaceProps.Animal && casterFaction == Faction.OfPlayer)
{
pawn.SetFaction(casterFaction);
}
}
/// <summary>
/// 对齐建筑阵营
/// </summary>
private void AlignThingWithCompsFaction(Thing thing, Faction casterFaction)
{
if (thing.Faction != casterFaction)
{
thing.SetFaction(casterFaction);
}
}
/// <summary>
/// 对齐建筑阵营
/// </summary>
private void AlignBuildingFaction(Building building, Faction casterFaction)
{
if (building.Faction != casterFaction)
{
building.SetFaction(casterFaction);
}
}
public override bool Valid(LocalTargetInfo target, bool throwMessages = false)
{
// 先调用基类的验证
if (!base.Valid(target, throwMessages))
{
return false;
}
// 额外的阵营检查
if (Props.alignFaction && parent.pawn.Faction == null)
{
if (throwMessages)
{
Messages.Message("CannotSpawnAlignedWithoutFaction".Translate(),
parent.pawn, MessageTypeDefOf.RejectInput, false);
}
return false;
}
return true;
}
}
}

View File

@@ -0,0 +1,16 @@
using RimWorld;
using Verse;
namespace WulaFallenEmpire
{
public class CompProperties_AbilitySpawnAligned : CompProperties_AbilitySpawn
{
// 是否将生成的物品与施法者阵营对齐
public bool alignFaction = true;
public CompProperties_AbilitySpawnAligned()
{
compClass = typeof(CompAbilityEffect_SpawnAligned);
}
}
}

View File

@@ -0,0 +1,229 @@
using System.Collections.Generic;
using RimWorld;
using UnityEngine;
using Verse;
using Verse.Sound;
namespace WulaFallenEmpire
{
public class CompAbilityEffect_TeleportSelf : CompAbilityEffect
{
public static string SkipUsedSignalTag = "CompAbilityEffect.SkipUsed";
public new CompProperties_AbilityTeleportSelf Props => (CompProperties_AbilityTeleportSelf)props;
public override IEnumerable<PreCastAction> GetPreCastActions()
{
yield return new PreCastAction
{
action = delegate(LocalTargetInfo target, LocalTargetInfo dest)
{
Pawn caster = parent.pawn;
Map map = caster.Map;
// 使用自定义或默认的入口特效
if (Props.customEntryFleck != null)
{
// 自定义入口粒子效果
FleckMaker.Static(caster.Position, map, Props.customEntryFleck);
}
else
{
// 默认入口粒子效果
FleckMaker.Static(caster.Position, map, FleckDefOf.PsycastSkipFlashEntry);
}
// 使用自定义或默认的出口特效
if (Props.customExitFleck != null)
{
// 自定义出口粒子效果
FleckMaker.Static(target.Cell, map, Props.customExitFleck);
// 如果需要更大的效果,可以创建多个粒子
if (Props.effectScale > 1.5f)
{
for (int i = 0; i < Mathf.FloorToInt(Props.effectScale); i++)
{
Vector3 offset = new Vector3(Rand.Range(-0.5f, 0.5f), 0f, Rand.Range(-0.5f, 0.5f));
FleckMaker.Static(target.Cell.ToVector3Shifted() + offset, map, Props.customExitFleck);
}
}
}
else
{
// 默认出口粒子效果
FleckMaker.Static(target.Cell, map, FleckDefOf.PsycastSkipInnerExit);
FleckMaker.Static(target.Cell, map, FleckDefOf.PsycastSkipOuterRingExit);
}
// 播放传送音效
SoundDefOf.Psycast_Skip_Entry.PlayOneShot(new TargetInfo(caster.Position, map));
SoundDefOf.Psycast_Skip_Exit.PlayOneShot(new TargetInfo(target.Cell, map));
},
ticksAwayFromCast = 5
};
}
public override void Apply(LocalTargetInfo target, LocalTargetInfo dest)
{
base.Apply(target, dest);
if (!target.IsValid)
{
return;
}
Pawn caster = parent.pawn;
Map map = caster.Map;
// 使用自定义或默认的入口效果器
EffecterDef entryEffecter = Props.customEntryEffecter ?? EffecterDefOf.Skip_Entry;
Effecter entryEffect = entryEffecter.Spawn(caster, map);
// 应用效果缩放
if (Props.effectScale != 1.0f && entryEffect is Effecter effect)
{
// 这里可以添加效果缩放的逻辑
// 注意Effecter类可能没有直接的缩放属性需要根据具体实现调整
}
parent.AddEffecterToMaintain(entryEffect, caster.Position, 60);
// 使用自定义或默认的出口效果器
EffecterDef exitEffecter = Props.customExitEffecter ?? EffecterDefOf.Skip_Exit;
Effecter exitEffect = exitEffecter.Spawn(target.Cell, map);
parent.AddEffecterToMaintain(exitEffect, target.Cell, 60);
// 唤醒可能休眠的组件
caster.TryGetComp<CompCanBeDormant>()?.WakeUp();
// 执行传送
caster.Position = target.Cell;
caster.Notify_Teleported();
// 如果是玩家阵营,解除战争迷雾
if ((caster.Faction == Faction.OfPlayer || caster.IsPlayerControlled) && caster.Position.Fogged(map))
{
FloodFillerFog.FloodUnfog(caster.Position, map);
}
// 传送后眩晕
caster.stances.stunner.StunFor(Props.stunTicks.RandomInRange, caster, addBattleLog: false, showMote: false);
// 发送传送信号
SendSkipUsedSignal(caster.Position, caster);
// 播放到达时的喧嚣效果
if (Props.destClamorType != null)
{
// 根据效果缩放调整喧嚣半径
float adjustedRadius = Props.destClamorRadius * Props.effectScale;
GenClamor.DoClamor(caster, target.Cell, adjustedRadius, Props.destClamorType);
}
}
public override bool Valid(LocalTargetInfo target, bool showMessages = true)
{
// 检查目的地是否有效
if (!CanTeleportTo(target.Cell, parent.pawn.Map))
{
if (showMessages)
{
Messages.Message("CannotTeleportToLocation".Translate(),
new LookTargets(target.Cell, parent.pawn.Map),
MessageTypeDefOf.RejectInput);
}
return false;
}
return base.Valid(target, showMessages);
}
/// <summary>
/// 检查是否可以命中目标
/// </summary>
public bool CanHitTarget(LocalTargetInfo target)
{
// 检查是否在范围内
if (Props.range > 0f && target.Cell.DistanceTo(parent.pawn.Position) > Props.range)
{
return false;
}
// 检查视线(如果需要)
if (Props.requireLineOfSight && !GenSight.LineOfSight(parent.pawn.Position, target.Cell, parent.pawn.Map))
{
return false;
}
// 检查是否可以传送到该位置
return CanTeleportTo(target.Cell, parent.pawn.Map);
}
/// <summary>
/// 检查是否可以传送到指定位置
/// </summary>
private bool CanTeleportTo(IntVec3 cell, Map map)
{
if (!cell.InBounds(map))
return false;
// 检查战争迷雾
if (!Props.canTeleportToFogged && cell.Fogged(map))
return false;
// 检查屋顶
if (!Props.canTeleportToRoofed && map.roofGrid.Roofed(cell))
return false;
// 检查是否可站立
if (!cell.Standable(map))
return false;
// 检查是否有障碍物
Building edifice = cell.GetEdifice(map);
if (edifice != null && edifice.def.surfaceType != SurfaceType.Item &&
edifice.def.surfaceType != SurfaceType.Eat && !(edifice is Building_Door { Open: not false }))
{
return false;
}
// 检查是否有物品阻挡
List<Thing> thingList = cell.GetThingList(map);
for (int i = 0; i < thingList.Count; i++)
{
if (thingList[i].def.category == ThingCategory.Item)
{
return false;
}
}
return true;
}
public override string ExtraLabelMouseAttachment(LocalTargetInfo target)
{
if (!CanHitTarget(target))
{
return "CannotTeleportToLocation".Translate();
}
return base.ExtraLabelMouseAttachment(target);
}
public override void DrawEffectPreview(LocalTargetInfo target)
{
// 绘制传送目的地的预览
GenDraw.DrawTargetHighlight(target);
// 绘制传送范围
if (Props.range > 0)
{
GenDraw.DrawRadiusRing(parent.pawn.Position, Props.range);
}
}
public static void SendSkipUsedSignal(LocalTargetInfo target, Thing initiator)
{
Find.SignalManager.SendSignal(new Signal(SkipUsedSignalTag, target.Named("POSITION"), initiator.Named("SUBJECT")));
}
}
}

View File

@@ -0,0 +1,33 @@
using RimWorld;
using Verse;
namespace WulaFallenEmpire
{
public class CompProperties_AbilityTeleportSelf : CompProperties_AbilityEffect
{
public float range = 12f;
public IntRange stunTicks = new IntRange(30, 60);
public float maxBodySize = 2f;
// 到达时的喧嚣效果
public ClamorDef destClamorType;
public float destClamorRadius = 2f;
// 传送限制
public bool requireLineOfSight = true;
public bool canTeleportToFogged = true;
public bool canTeleportToRoofed = true;
// 自定义效果器 - 为大型生物设计
public EffecterDef customEntryEffecter;
public EffecterDef customExitEffecter;
public FleckDef customEntryFleck;
public FleckDef customExitFleck;
public float effectScale = 1.0f; // 效果缩放比例
public CompProperties_AbilityTeleportSelf()
{
compClass = typeof(CompAbilityEffect_TeleportSelf);
}
}
}