Files
WulaFallenEmpireRW/Source/WulaFallenEmpire/Ability/WULA_AbilityEnergyLance/CompAbilityEffect_EnergyLance.cs
ProjectKoi-Kalo\Kalo 98a0400c78 WulaFallenEmpireSettings.cs - 添加了 public bool enableDebugLogs = false; 字段和保存配置
 WulaLog.cs - 修改了DebugEnabled属性,仅检查enableDebugLogs设置(不检查DevMode)
 WulaFallenEmpireMod.cs - 在DoSettingsWindowContents中添加了UI复选框,显示"Enable Debug Logs"选项
 替换了所有848个Log.Message/Error/Warning调用为WulaLog.Debug()
2025-12-15 13:05:50 +08:00

123 lines
4.0 KiB
C#

using RimWorld;
using Verse;
using UnityEngine;
namespace WulaFallenEmpire
{
public class CompAbilityEffect_EnergyLance : CompAbilityEffect_WithDest
{
public new CompProperties_AbilityEnergyLance Props => (CompProperties_AbilityEnergyLance)props;
public override void Apply(LocalTargetInfo target, LocalTargetInfo dest)
{
base.Apply(target, dest);
if (parent.pawn == null || parent.pawn.Map == null)
return;
try
{
// 使用配置的光束类型
ThingDef lanceDef = Props.energyLanceDef ?? ThingDef.Named("EnergyLance");
// 创建EnergyLance
EnergyLance.MakeEnergyLance(
lanceDef,
target.Cell,
dest.Cell,
parent.pawn.Map,
Props.moveDistance,
Props.useFixedDistance,
Props.durationTicks,
parent.pawn
);
WulaLog.Debug($"[EnergyLance] Started {lanceDef.defName} from {target.Cell} to {dest.Cell}");
}
catch (System.Exception ex)
{
WulaLog.Debug($"[EnergyLance] Error starting EnergyLance: {ex}");
}
}
// 绘制预览保持不变
public new void DrawHighlight(LocalTargetInfo target)
{
if (selectedTarget.IsValid)
{
DrawBeamPathPreview(selectedTarget.Cell, target.Cell);
}
else
{
GenDraw.DrawTargetHighlight(target);
}
}
private void DrawBeamPathPreview(IntVec3 startCell, IntVec3 endCell)
{
Map map = parent.pawn.Map;
Vector3 startPos = startCell.ToVector3();
Vector3 direction = (endCell.ToVector3() - startPos).normalized;
Vector3 actualEndPos;
if (Props.useFixedDistance)
{
actualEndPos = startPos + direction * Props.moveDistance;
}
else
{
actualEndPos = endCell.ToVector3();
}
IntVec3 actualEndCell = new IntVec3(
Mathf.RoundToInt(actualEndPos.x),
Mathf.RoundToInt(actualEndPos.y),
Mathf.RoundToInt(actualEndPos.z)
);
DrawBeamLine(startCell, actualEndCell);
GenDraw.DrawTargetHighlight(startCell);
GenDraw.DrawTargetHighlight(actualEndCell);
DrawEffectRadiusPreview(startCell);
DrawEffectRadiusPreview(actualEndCell);
}
private void DrawBeamLine(IntVec3 startCell, IntVec3 endCell)
{
Vector3 startPos = startCell.ToVector3Shifted();
Vector3 endPos = endCell.ToVector3Shifted();
GenDraw.DrawLineBetween(startPos, endPos, SimpleColor.Yellow, 0.3f);
}
private void DrawEffectRadiusPreview(IntVec3 center)
{
Map map = parent.pawn.Map;
GenDraw.DrawRadiusRing(center, 15f, Color.yellow);
}
public override string ExtraLabelMouseAttachment(LocalTargetInfo target)
{
if (selectedTarget.IsValid)
{
string beamType = Props.energyLanceDef?.label ?? "EnergyLance";
return $"选择{beamType}方向\n移动距离: {Props.moveDistance}格\n模式: {(Props.useFixedDistance ? "" : "")}";
}
else
{
return "选择光束起点";
}
}
public override TargetingParameters targetParams => new TargetingParameters
{
canTargetLocations = true,
canTargetPawns = false,
canTargetBuildings = false,
canTargetItems = false,
mapObjectTargetsMustBeAutoAttackable = false
};
}
}