xiu
This commit is contained in:
@@ -0,0 +1,190 @@
|
||||
using RimWorld;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Verse;
|
||||
using Verse.Sound;
|
||||
using System.Text;
|
||||
using System.Linq;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
public class CompLaunchable_ToGlobalStorage : CompLaunchable_TransportPod
|
||||
{
|
||||
public new CompProperties_Launchable_ToGlobalStorage Props => (CompProperties_Launchable_ToGlobalStorage)this.props;
|
||||
|
||||
// 获取垃圾屏蔽组件
|
||||
public CompGarbageShield GarbageShieldComp => this.parent.GetComp<CompGarbageShield>();
|
||||
|
||||
public override IEnumerable<Gizmo> CompGetGizmosExtra()
|
||||
{
|
||||
// 移除原有的发射按钮,替换为我们自己的
|
||||
foreach (Gizmo gizmo in base.CompGetGizmosExtra())
|
||||
{
|
||||
if (gizmo is Command_Action launchCommand && (launchCommand.defaultDesc == "CommandLaunchGroupDesc".Translate() || launchCommand.defaultDesc == "CommandLaunchSingleDesc".Translate()))
|
||||
{
|
||||
continue; // 跳过原版的发射按钮
|
||||
}
|
||||
yield return gizmo;
|
||||
}
|
||||
|
||||
if (this.Transporter.LoadingInProgressOrReadyToLaunch)
|
||||
{
|
||||
Command_Action command = new Command_Action();
|
||||
command.defaultLabel = "WULA_LaunchToGlobalStorage".Translate();
|
||||
command.defaultDesc = "WULA_LaunchToGlobalStorageDesc".Translate();
|
||||
command.icon = ContentFinder<Texture2D>.Get("UI/Commands/LaunchShip");
|
||||
command.action = delegate
|
||||
{
|
||||
this.TryLaunch();
|
||||
};
|
||||
yield return command;
|
||||
}
|
||||
}
|
||||
|
||||
public void TryLaunch()
|
||||
{
|
||||
if (!this.parent.Spawned)
|
||||
{
|
||||
Log.Error("Tried to launch " + this.parent + " but it's not spawned.");
|
||||
return;
|
||||
}
|
||||
|
||||
var globalStorage = Find.World.GetComponent<GlobalStorageWorldComponent>();
|
||||
if (globalStorage == null)
|
||||
{
|
||||
Log.Error("Could not find GlobalStorageWorldComponent.");
|
||||
return;
|
||||
}
|
||||
|
||||
CompTransporter transporter = this.Transporter;
|
||||
if (transporter == null || !transporter.innerContainer.Any)
|
||||
{
|
||||
Messages.Message("WULA_NoItemsToSendToGlobalStorage".Translate(), this.parent, MessageTypeDefOf.RejectInput);
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查垃圾屏蔽 - 如果启用了垃圾屏蔽并且有禁止物品,取消发射
|
||||
if (GarbageShieldComp != null && GarbageShieldComp.GarbageShieldEnabled)
|
||||
{
|
||||
List<Thing> forbiddenItems = GarbageShieldComp.GetForbiddenItems(transporter.innerContainer);
|
||||
if (forbiddenItems.Count > 0)
|
||||
{
|
||||
// 显示取消发射消息
|
||||
StringBuilder forbiddenList = new StringBuilder();
|
||||
foreach (Thing item in forbiddenItems)
|
||||
{
|
||||
if (forbiddenList.Length > 0) forbiddenList.Append(", ");
|
||||
forbiddenList.Append($"{item.LabelCap} x{item.stackCount}");
|
||||
}
|
||||
|
||||
Messages.Message("WULA_LaunchCancelledDueToForbiddenItems".Translate(forbiddenList.ToString()),
|
||||
this.parent, MessageTypeDefOf.RejectInput);
|
||||
|
||||
// 触发垃圾屏蔽UI事件
|
||||
GarbageShieldComp.ProcessGarbageShieldTrigger(forbiddenItems);
|
||||
|
||||
return; // 取消发射
|
||||
}
|
||||
}
|
||||
|
||||
// 统计发送的物品
|
||||
int inputItemsCount = 0;
|
||||
int outputItemsCount = 0;
|
||||
StringBuilder inputItemsList = new StringBuilder();
|
||||
StringBuilder outputItemsList = new StringBuilder();
|
||||
|
||||
// 1. 将物品分类转移到相应的存储
|
||||
foreach (Thing item in transporter.innerContainer)
|
||||
{
|
||||
if (ShouldGoToOutputStorage(item))
|
||||
{
|
||||
// 发送到输出存储器
|
||||
globalStorage.AddToOutputStorage(item.def, item.stackCount);
|
||||
outputItemsCount += item.stackCount;
|
||||
if (outputItemsList.Length > 0) outputItemsList.Append(", ");
|
||||
outputItemsList.Append($"{item.LabelCap} x{item.stackCount}");
|
||||
}
|
||||
else
|
||||
{
|
||||
// 发送到输入存储器
|
||||
globalStorage.AddToInputStorage(item.def, item.stackCount);
|
||||
inputItemsCount += item.stackCount;
|
||||
if (inputItemsList.Length > 0) inputItemsList.Append(", ");
|
||||
inputItemsList.Append($"{item.LabelCap} x{item.stackCount}");
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 显示发送结果消息
|
||||
string message = BuildTransferMessage(inputItemsCount, outputItemsCount,
|
||||
inputItemsList.ToString(), outputItemsList.ToString());
|
||||
Messages.Message(message, this.parent, MessageTypeDefOf.PositiveEvent);
|
||||
|
||||
// 3. 清空容器,防止物品掉落
|
||||
transporter.innerContainer.ClearAndDestroyContents();
|
||||
|
||||
// 4. 调用基类的发射方法,让它处理动画和销毁
|
||||
base.TryLaunch(this.parent.Map.Tile, null);
|
||||
}
|
||||
|
||||
// 判断物品是否应该发送到输出存储器
|
||||
private bool ShouldGoToOutputStorage(Thing item)
|
||||
{
|
||||
// 武器
|
||||
if (item.def.IsWeapon)
|
||||
return true;
|
||||
|
||||
// 装备
|
||||
if (item.def.IsApparel)
|
||||
return true;
|
||||
|
||||
// 其他物品发送到输入存储器
|
||||
return false;
|
||||
}
|
||||
|
||||
// 构建转移消息
|
||||
private string BuildTransferMessage(int inputCount, int outputCount,
|
||||
string inputList, string outputList)
|
||||
{
|
||||
StringBuilder message = new StringBuilder();
|
||||
|
||||
if (inputCount > 0 && outputCount > 0)
|
||||
{
|
||||
// 既有输入又有输出物品
|
||||
message.Append("WULA_ItemsSentToBothStorages".Translate(inputCount, outputCount));
|
||||
if (!string.IsNullOrEmpty(inputList))
|
||||
{
|
||||
message.Append("\n").Append("WULA_InputStorageItems".Translate(inputList));
|
||||
}
|
||||
if (!string.IsNullOrEmpty(outputList))
|
||||
{
|
||||
message.Append("\n").Append("WULA_OutputStorageItems".Translate(outputList));
|
||||
}
|
||||
}
|
||||
else if (inputCount > 0)
|
||||
{
|
||||
// 只有输入物品
|
||||
message.Append("WULA_ItemsSentToInputStorage".Translate(inputCount));
|
||||
if (!string.IsNullOrEmpty(inputList))
|
||||
{
|
||||
message.Append(": ").Append(inputList);
|
||||
}
|
||||
}
|
||||
else if (outputCount > 0)
|
||||
{
|
||||
// 只有输出物品
|
||||
message.Append("WULA_ItemsSentToOutputStorage".Translate(outputCount));
|
||||
if (!string.IsNullOrEmpty(outputList))
|
||||
{
|
||||
message.Append(": ").Append(outputList);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 没有任何物品
|
||||
message.Append("WULA_NoItemsProcessed".Translate());
|
||||
}
|
||||
|
||||
return message.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
using RimWorld;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using Verse;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
public class CompProperties_GarbageShield : CompProperties
|
||||
{
|
||||
public bool garbageShieldEnabled = false; // 通过XML配置启用/禁用
|
||||
public string garbageShieldUIEventDefName; // 垃圾屏蔽触发时弹出的UI事件defName
|
||||
|
||||
public CompProperties_GarbageShield()
|
||||
{
|
||||
this.compClass = typeof(CompGarbageShield);
|
||||
}
|
||||
}
|
||||
|
||||
public class CompGarbageShield : ThingComp
|
||||
{
|
||||
public CompProperties_GarbageShield Props => (CompProperties_GarbageShield)this.props;
|
||||
|
||||
// 垃圾屏蔽状态完全由XML配置决定,不提供玩家切换
|
||||
public bool GarbageShieldEnabled => Props.garbageShieldEnabled;
|
||||
|
||||
// 检查物品是否是被禁止的垃圾物品
|
||||
public bool IsForbiddenItem(Thing thing)
|
||||
{
|
||||
if (!GarbageShieldEnabled) return false;
|
||||
|
||||
// 检查是否是殖民者
|
||||
if (thing is Pawn pawn && pawn.IsColonist)
|
||||
return true;
|
||||
|
||||
// 检查是否是尸体
|
||||
if (thing.def.IsCorpse)
|
||||
return true;
|
||||
|
||||
// 检查是否是有毒垃圾
|
||||
if (IsToxicWaste(thing))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// 获取所有禁止物品
|
||||
public List<Thing> GetForbiddenItems(ThingOwner container)
|
||||
{
|
||||
List<Thing> forbiddenItems = new List<Thing>();
|
||||
|
||||
if (!GarbageShieldEnabled) return forbiddenItems;
|
||||
|
||||
foreach (Thing item in container)
|
||||
{
|
||||
if (IsForbiddenItem(item))
|
||||
{
|
||||
forbiddenItems.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
return forbiddenItems;
|
||||
}
|
||||
|
||||
// 判断是否为有毒垃圾
|
||||
private bool IsToxicWaste(Thing thing)
|
||||
{
|
||||
// 根据物品标签、类别或定义名称判断是否为有毒垃圾
|
||||
return thing.def == ThingDefOf.Wastepack;
|
||||
}
|
||||
|
||||
// 处理垃圾屏蔽触发并触发UI事件
|
||||
public void ProcessGarbageShieldTrigger(List<Thing> forbiddenItems)
|
||||
{
|
||||
if (forbiddenItems.Count > 0 && !string.IsNullOrEmpty(Props.garbageShieldUIEventDefName))
|
||||
{
|
||||
// 弹出指定的自定义UI
|
||||
EventDef uiDef = DefDatabase<EventDef>.GetNamed(Props.garbageShieldUIEventDefName, false);
|
||||
if (uiDef != null)
|
||||
{
|
||||
Find.WindowStack.Add(new Dialog_CustomDisplay(uiDef));
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Error($"[CompGarbageShield] Could not find EventDef named '{Props.garbageShieldUIEventDefName}'.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using RimWorld;
|
||||
using Verse;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
public class CompProperties_Launchable_ToGlobalStorage : CompProperties_Launchable_TransportPod
|
||||
{
|
||||
public float fuelNeededToLaunch = 25f;
|
||||
public SoundDef launchSound;
|
||||
|
||||
// 垃圾屏蔽配置 - 通过XML控制
|
||||
public bool garbageShieldEnabled = false;
|
||||
public string garbageShieldUIEventDefName = "Wula_UI_Legion_Reply_1";
|
||||
|
||||
public CompProperties_Launchable_ToGlobalStorage()
|
||||
{
|
||||
this.compClass = typeof(CompLaunchable_ToGlobalStorage);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user