This commit is contained in:
Tourswen
2025-11-11 00:09:05 +08:00
parent 2711f90cd8
commit d5f3277fd6
33 changed files with 1677 additions and 198 deletions

View File

@@ -0,0 +1,83 @@
using RimWorld;
using Verse;
using UnityEngine;
using System.Collections.Generic;
namespace WulaFallenEmpire
{
public class CompAbilityEffect_CallSkyfaller : CompAbilityEffect
{
public new CompProperties_AbilityCallSkyfaller Props => (CompProperties_AbilityCallSkyfaller)props;
public override void Apply(LocalTargetInfo target, LocalTargetInfo dest)
{
base.Apply(target, dest);
if (parent.pawn == null || parent.pawn.Map == null || !target.IsValid)
return;
try
{
// 创建延时召唤
CallSkyfallerDelayed(target.Cell);
Log.Message($"[CallSkyfaller] Scheduled skyfaller at {target.Cell} with {Props.delayTicks} ticks delay");
}
catch (System.Exception ex)
{
Log.Error($"[CallSkyfaller] Error calling skyfaller: {ex}");
}
}
private void CallSkyfallerDelayed(IntVec3 targetCell)
{
// 使用延时动作来召唤skyfaller
parent.pawn.Map.GetComponent<MapComponent_SkyfallerDelayed>()?
.ScheduleSkyfaller(Props.skyfallerDef, targetCell, Props.delayTicks, parent.pawn);
}
// 绘制预览效果
public override void DrawEffectPreview(LocalTargetInfo target)
{
base.DrawEffectPreview(target);
if (parent.pawn == null || parent.pawn.Map == null || !target.IsValid)
return;
try
{
// 绘制圆形预览区域
DrawCircularPreview(target.Cell);
}
catch (System.Exception)
{
// 忽略预览绘制错误
}
}
private void DrawCircularPreview(IntVec3 center)
{
Map map = parent.pawn.Map;
// 获取圆形区域内的所有单元格
var previewCells = GenRadial.RadialCellsAround(center, Props.previewRadius, true);
// 绘制预览区域
foreach (var cell in previewCells)
{
if (cell.InBounds(map))
{
GenDraw.DrawFieldEdges(new List<IntVec3> { cell }, Props.previewColor, 0.2f);
}
}
// 绘制目标点高亮
GenDraw.DrawTargetHighlight(center);
}
public override string ExtraLabelMouseAttachment(LocalTargetInfo target)
{
return $"召唤空投舱: {Props.delayTicks}刻后到达";
}
}
}

View File

@@ -0,0 +1,22 @@
using RimWorld;
using Verse;
using UnityEngine;
namespace WulaFallenEmpire
{
public class CompProperties_AbilityCallSkyfaller : CompProperties_AbilityEffect
{
// 基础配置
public int delayTicks = 120; // 延时(刻)
public ThingDef skyfallerDef; // 使用的 Skyfaller
// 预览配置
public float previewRadius = 5f; // 预览半径
public Color previewColor = new Color(1f, 0.5f, 0.1f, 0.3f); // 预览颜色
public CompProperties_AbilityCallSkyfaller()
{
this.compClass = typeof(CompAbilityEffect_CallSkyfaller);
}
}
}

View File

@@ -0,0 +1,81 @@
using RimWorld;
using Verse;
using System.Collections.Generic;
namespace WulaFallenEmpire
{
public class MapComponent_SkyfallerDelayed : MapComponent
{
private List<DelayedSkyfaller> scheduledSkyfallers = new List<DelayedSkyfaller>();
public MapComponent_SkyfallerDelayed(Map map) : base(map) { }
public void ScheduleSkyfaller(ThingDef skyfallerDef, IntVec3 targetCell, int delayTicks, Pawn caster = null)
{
scheduledSkyfallers.Add(new DelayedSkyfaller
{
skyfallerDef = skyfallerDef,
targetCell = targetCell,
spawnTick = Find.TickManager.TicksGame + delayTicks,
caster = caster
});
}
public override void MapComponentTick()
{
base.MapComponentTick();
int currentTick = Find.TickManager.TicksGame;
// 检查并执行到期的召唤
for (int i = scheduledSkyfallers.Count - 1; i >= 0; i--)
{
var skyfaller = scheduledSkyfallers[i];
if (currentTick >= skyfaller.spawnTick)
{
SpawnSkyfaller(skyfaller);
scheduledSkyfallers.RemoveAt(i);
}
}
}
private void SpawnSkyfaller(DelayedSkyfaller delayedSkyfaller)
{
try
{
if (delayedSkyfaller.skyfallerDef != null && delayedSkyfaller.targetCell.IsValid && delayedSkyfaller.targetCell.InBounds(map))
{
Skyfaller skyfaller = SkyfallerMaker.MakeSkyfaller(delayedSkyfaller.skyfallerDef);
GenSpawn.Spawn(skyfaller, delayedSkyfaller.targetCell, map);
Log.Message($"[DelayedSkyfaller] Spawned skyfaller at {delayedSkyfaller.targetCell}");
}
}
catch (System.Exception ex)
{
Log.Error($"[DelayedSkyfaller] Error spawning skyfaller: {ex}");
}
}
public override void ExposeData()
{
base.ExposeData();
Scribe_Collections.Look(ref scheduledSkyfallers, "scheduledSkyfallers", LookMode.Deep);
}
}
public class DelayedSkyfaller : IExposable
{
public ThingDef skyfallerDef;
public IntVec3 targetCell;
public int spawnTick;
public Pawn caster;
public void ExposeData()
{
Scribe_Defs.Look(ref skyfallerDef, "skyfallerDef");
Scribe_Values.Look(ref targetCell, "targetCell");
Scribe_Values.Look(ref spawnTick, "spawnTick");
Scribe_References.Look(ref caster, "caster");
}
}
}