Files
WulaFallenEmpireRW/Source/WulaFallenEmpire/BuildingComp/WULA_Shuttle/Building_PocketMapExit.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

167 lines
6.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using RimWorld;
using Verse;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using System.Reflection;
namespace WulaFallenEmpire
{
/// <summary>
/// 口袋空间退出点建筑 - 继承自MapPortal以获得完整的双向传送功能
/// </summary>
public class Building_PocketMapExit : MapPortal
{
/// <summary>目标地图</summary>
public Map targetMap;
/// <summary>目标位置</summary>
public IntVec3 targetPos;
/// <summary>父穿梭机</summary>
public Building_ArmedShuttleWithPocket parentShuttle;
public override void ExposeData()
{
base.ExposeData();
Scribe_References.Look(ref targetMap, "targetMap");
Scribe_Values.Look(ref targetPos, "targetPos");
Scribe_References.Look(ref parentShuttle, "parentShuttle");
}
/// <summary>
/// 重写获取其他地图返回主地图模仿原版MapPortal.GetOtherMap
/// </summary>
public override Map GetOtherMap()
{
// 动态更新目标地图,处理穿梭机移动的情况
UpdateTargetFromParentShuttle();
return targetMap;
}
/// <summary>
/// 重写获取目标位置返回主地图上的穿梭机位置模仿原版MapPortal.GetDestinationLocation
/// </summary>
public override IntVec3 GetDestinationLocation()
{
// 动态更新目标位置,处理穿梭机移动的情况
UpdateTargetFromParentShuttle();
return targetPos;
}
/// <summary>
/// 从父穿梭机动态更新目标位置,处理穿梭机移动的情况
/// </summary>
private void UpdateTargetFromParentShuttle()
{
if (parentShuttle != null && parentShuttle.Spawned)
{
// 如果穿梭机还在地图上,更新目标位置
if (targetMap != parentShuttle.Map || targetPos != parentShuttle.Position)
{
targetMap = parentShuttle.Map;
targetPos = parentShuttle.Position;
WulaLog.Debug($"[WULA] Updated exit target to shuttle location: {targetMap?.uniqueID} at {targetPos}");
}
}
else if (parentShuttle != null && !parentShuttle.Spawned)
{
// 穿梭机不在地图上(可能在飞行中)
// 保持原有目标,但记录警告
if (this.IsHashIntervalTick(2500)) // 每隔一段时间检查一次
{
WulaLog.Debug($"[WULA] Parent shuttle is not spawned, exit target may be outdated. Last known: {targetMap?.uniqueID} at {targetPos}");
}
}
}
/// <summary>
/// 重写是否可进入检查目标地图是否存在及传送状态模仿原版MapPortal.IsEnterable
/// </summary>
public override bool IsEnterable(out string reason)
{
if (targetMap == null)
{
reason = "WULA.PocketSpace.NoTargetMap".Translate();
return false;
}
// 检查父穿梭机的传送状态
if (parentShuttle != null)
{
// 使用反射获取 transportDisabled 字段值
var transportDisabledField = typeof(Building_ArmedShuttleWithPocket).GetField("transportDisabled",
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
if (transportDisabledField != null)
{
bool transportDisabled = (bool)transportDisabledField.GetValue(parentShuttle);
if (transportDisabled)
{
reason = "WULA.PocketSpace.TransportDisabled".Translate();
return false;
}
}
}
reason = "";
return true;
}
/// <summary>
/// 重写进入事件处理从口袋空间退出到主地图模仿原版MapPortal.OnEntered
/// </summary>
public override void OnEntered(Pawn pawn)
{
// 不调用 base.OnEntered因为我们不需要原版的通知机制
// 直接处理退出逻辑
if (targetMap != null && pawn.Spawned)
{
ExitPocketSpace(pawn);
}
}
/// <summary>
/// 重写进入按钮文本
/// </summary>
public override string EnterString => "WULA.PocketSpace.ExitToMainMap".Translate();
/// <summary>
/// 重写进入按钮图标,使用装载按钮的贴图
/// </summary>
protected override Texture2D EnterTex => ContentFinder<Texture2D>.Get("UI/Commands/LoadTransporter");
/// <summary>
/// 单个人员退出口袋空间简化版本利用MapPortal功能
/// </summary>
private void ExitPocketSpace(Pawn pawn)
{
if (targetMap == null || !pawn.Spawned) return;
try
{
// 在目标地图找一个安全位置
IntVec3 exitPos = CellFinder.RandomClosewalkCellNear(targetPos, targetMap, 3, p => p.Standable(targetMap));
// 传送人员
pawn.DeSpawn();
GenPlace.TryPlaceThing(pawn, exitPos, targetMap, ThingPlaceMode.Near);
// 切换到主地图
if (pawn.IsColonistPlayerControlled)
{
Current.Game.CurrentMap = targetMap;
Find.CameraDriver.JumpToCurrentMapLoc(exitPos);
}
Messages.Message("WULA.PocketSpace.ExitSuccess".Translate(pawn.LabelShort), MessageTypeDefOf.PositiveEvent);
}
catch (System.Exception ex)
{
WulaLog.Debug($"[WULA] Error exiting pocket space: {ex}");
}
}
}
}