各种修改

This commit is contained in:
Tourswen
2025-10-02 17:07:09 +08:00
parent 5d7d88e4ad
commit 09579a936f
24 changed files with 543 additions and 443 deletions

View File

@@ -3,12 +3,8 @@
"WorkspaceRootPath": "E:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\",
"Documents": [
{
"AbsoluteMoniker": "D:0:0:{EAE0DB6B-E282-C812-7F5A-6D13E9D24581}|ArachnaeSwarm.csproj|E:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\jobdriver_carryprisonertonutrientvat.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{EAE0DB6B-E282-C812-7F5A-6D13E9D24581}|ArachnaeSwarm.csproj|solutionrelative:jobdriver_carryprisonertonutrientvat.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
},
{
"AbsoluteMoniker": "D:0:0:{EAE0DB6B-E282-C812-7F5A-6D13E9D24581}|ArachnaeSwarm.csproj|e:\\steamlibrary\\steamapps\\common\\rimworld\\mods\\arachnaeswarm\\source\\arachnaeswarm\\building_comps\\ara_nutrientvat\\building_nutrientvat.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{EAE0DB6B-E282-C812-7F5A-6D13E9D24581}|ArachnaeSwarm.csproj|solutionrelative:building_comps\\ara_nutrientvat\\building_nutrientvat.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
"AbsoluteMoniker": "D:0:0:{EAE0DB6B-E282-C812-7F5A-6D13E9D24581}|ArachnaeSwarm.csproj|e:\\steamlibrary\\steamapps\\common\\rimworld\\mods\\arachnaeswarm\\source\\arachnaeswarm\\building_comps\\wula_mutifuelspawner\\comprefuelablenutrition_withkey.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{EAE0DB6B-E282-C812-7F5A-6D13E9D24581}|ArachnaeSwarm.csproj|solutionrelative:building_comps\\wula_mutifuelspawner\\comprefuelablenutrition_withkey.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
}
],
"DocumentGroupContainers": [
@@ -27,27 +23,14 @@
{
"$type": "Document",
"DocumentIndex": 0,
"Title": "JobDriver_CarryPrisonerToNutrientVat.cs",
"DocumentMoniker": "E:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\JobDriver_CarryPrisonerToNutrientVat.cs",
"RelativeDocumentMoniker": "JobDriver_CarryPrisonerToNutrientVat.cs",
"ToolTip": "E:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\JobDriver_CarryPrisonerToNutrientVat.cs",
"RelativeToolTip": "JobDriver_CarryPrisonerToNutrientVat.cs",
"ViewState": "AgIAAAAAAAAAAAAAAAAAABwAAAAYAAAAAAAAAA==",
"Title": "CompRefuelableNutrition_WithKey.cs",
"DocumentMoniker": "E:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\Building_Comps\\WULA_MutiFuelSpawner\\CompRefuelableNutrition_WithKey.cs",
"RelativeDocumentMoniker": "Building_Comps\\WULA_MutiFuelSpawner\\CompRefuelableNutrition_WithKey.cs",
"ToolTip": "E:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\Building_Comps\\WULA_MutiFuelSpawner\\CompRefuelableNutrition_WithKey.cs",
"RelativeToolTip": "Building_Comps\\WULA_MutiFuelSpawner\\CompRefuelableNutrition_WithKey.cs",
"ViewState": "AgIAABwAAAAAAAAAAAAUwFsAAAAcAAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2025-10-01T07:37:06.309Z",
"EditorCaption": ""
},
{
"$type": "Document",
"DocumentIndex": 1,
"Title": "Building_NutrientVat.cs",
"DocumentMoniker": "E:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\Building_Comps\\ARA_NutrientVat\\Building_NutrientVat.cs",
"RelativeDocumentMoniker": "Building_Comps\\ARA_NutrientVat\\Building_NutrientVat.cs",
"ToolTip": "E:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\Building_Comps\\ARA_NutrientVat\\Building_NutrientVat.cs",
"RelativeToolTip": "Building_Comps\\ARA_NutrientVat\\Building_NutrientVat.cs",
"ViewState": "AgIAAAAAAAAAAAAAAAAAAAkAAAAXAAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2025-10-01T07:14:25.565Z",
"WhenOpened": "2025-10-02T06:18:10.518Z",
"EditorCaption": ""
}
]

View File

@@ -104,7 +104,7 @@ namespace ArachnaeSwarm
}
}
// 自动构建 ProcessDef 列表的方法
// 自动构建 ProcessDef 列表的方法 - 修改后扫描所有物品
private void BuildProcessList()
{
_cachedProcesses = new List<ProcessDef>();
@@ -112,54 +112,51 @@ namespace ArachnaeSwarm
// 扫描所有定义了 CompExtraIncubationInfo 的物品
foreach (ThingDef thingDef in DefDatabase<ThingDef>.AllDefs)
{
// 检查是否是服装或武器
if (thingDef.IsApparel || thingDef.IsWeapon)
// 移除 IsApparel 和 IsWeapon 的限制,扫描所有物品
var incubationCompProps = thingDef.GetCompProperties<CompProperties_ExtraIncubationInfo>();
if (incubationCompProps != null)
{
var incubationCompProps = thingDef.GetCompProperties<CompProperties_ExtraIncubationInfo>();
if (incubationCompProps != null)
bool isMatch = false;
if (!incubationCompProps.cocoonDefs.NullOrEmpty())
{
bool isMatch = false;
if (!incubationCompProps.cocoonDefs.NullOrEmpty())
isMatch = incubationCompProps.cocoonDefs.Contains(parent.def);
}
else if (incubationCompProps.cocoonDef != null)
{
isMatch = incubationCompProps.cocoonDef == parent.def;
}
if (isMatch)
{
// 获取研究前提 - 从 recipeMaker 中获取
ResearchProjectDef researchPrerequisite = null;
// 方法1从 recipeMaker.researchPrerequisite 获取
if (thingDef.recipeMaker?.researchPrerequisite != null)
{
isMatch = incubationCompProps.cocoonDefs.Contains(parent.def);
researchPrerequisite = thingDef.recipeMaker.researchPrerequisite;
}
else if (incubationCompProps.cocoonDef != null)
// 方法2从 recipeMaker.researchPrerequisites 获取第一个
else if (thingDef.recipeMaker?.researchPrerequisites?.Count > 0)
{
isMatch = incubationCompProps.cocoonDef == parent.def;
researchPrerequisite = thingDef.recipeMaker.researchPrerequisites[0];
}
// 方法3从 thingDef.researchPrerequisites 获取(备用)
else if (thingDef.researchPrerequisites?.Count > 0)
{
researchPrerequisite = thingDef.researchPrerequisites[0];
}
if (isMatch)
// 创建 ProcessDef
ProcessDef process = new ProcessDef
{
// 获取研究前提 - 从 recipeMaker 中获取
ResearchProjectDef researchPrerequisite = null;
// 方法1从 recipeMaker.researchPrerequisite 获取
if (thingDef.recipeMaker?.researchPrerequisite != null)
{
researchPrerequisite = thingDef.recipeMaker.researchPrerequisite;
}
// 方法2从 recipeMaker.researchPrerequisites 获取第一个
else if (thingDef.recipeMaker?.researchPrerequisites?.Count > 0)
{
researchPrerequisite = thingDef.recipeMaker.researchPrerequisites[0];
}
// 方法3从 thingDef.researchPrerequisites 获取(备用)
else if (thingDef.researchPrerequisites?.Count > 0)
{
researchPrerequisite = thingDef.researchPrerequisites[0];
}
thingDef = thingDef,
productionTicks = GetIncubationTimeTicks(thingDef),
totalNutritionNeeded = GetIncubationCost(thingDef),
requiredResearch = researchPrerequisite
};
// 创建 ProcessDef
ProcessDef process = new ProcessDef
{
thingDef = thingDef,
productionTicks = GetIncubationTimeTicks(thingDef),
totalNutritionNeeded = GetIncubationCost(thingDef),
requiredResearch = researchPrerequisite
};
_cachedProcesses.Add(process);
}
_cachedProcesses.Add(process);
}
}
}

View File

@@ -10,7 +10,6 @@ namespace ArachnaeSwarm
public CompProperties_RefuelableNutrition()
{
compClass = typeof(CompRefuelableNutrition);
// 默认启用这些Gizmo除非在XML中明确设置为false
this.targetFuelLevelConfigurable = true;
this.showAllowAutoRefuelToggle = true;
}
@@ -23,10 +22,44 @@ namespace ArachnaeSwarm
public float NutritionStored => Fuel;
public new CompProperties_RefuelableNutrition Props => (CompProperties_RefuelableNutrition)props;
public override void PostSpawnSetup(bool respawningAfterLoad)
{
base.PostSpawnSetup(respawningAfterLoad);
// 确保自动补充目标燃料水平正确设置
if (TargetFuelLevel <= 0f || respawningAfterLoad)
{
SetTargetFuelLevelFromAutoRefuelPercent();
}
}
public override void PostExposeData()
{
base.PostExposeData();
// 在加载后确保目标燃料水平正确
if (Scribe.mode == LoadSaveMode.PostLoadInit)
{
SetTargetFuelLevelFromAutoRefuelPercent();
}
}
private void SetTargetFuelLevelFromAutoRefuelPercent()
{
// 使用 autoRefuelPercent 设置目标燃料水平
if (Props.autoRefuelPercent > 0f)
{
TargetFuelLevel = Props.fuelCapacity * Props.autoRefuelPercent;
}
else
{
// 默认设置为满容量
TargetFuelLevel = Props.fuelCapacity;
}
}
public override void CompTick()
{
// 调用基类的Tick让它处理真空等情况。
// 基类的燃料消耗逻辑将因为 fuelConsumptionRate 为0而无效。
base.CompTick();
// 我们自己的动态消耗逻辑
@@ -92,6 +125,7 @@ namespace ArachnaeSwarm
if (Props.targetFuelLevelConfigurable)
{
text += "\n" + "ConfiguredTargetFuelLevel".Translate(TargetFuelLevel.ToStringDecimalIfSmall());
text += " (" + "AutoRefuelPercent".Translate((Props.autoRefuelPercent * 100f).ToString("F0") + "%)");
}
return text;
@@ -105,4 +139,4 @@ namespace ArachnaeSwarm
}
}
}
}
}

View File

@@ -2,23 +2,25 @@ using RimWorld;
using Verse;
using System.Reflection;
using HarmonyLib;
using System.Collections.Generic;
using System.Linq;
namespace ArachnaeSwarm
{
public class CompProperties_RefuelableNutrition_WithKey : CompProperties_RefuelableNutrition
{
public string saveKeysPrefix;
// 修改:禁止的具体物品定义列表
public List<ThingDef> disallowedThingDefs;
public CompProperties_RefuelableNutrition_WithKey()
{
compClass = typeof(CompRefuelableNutrition_WithKey);
}
}
public class CompRefuelableNutrition_WithKey : CompRefuelableNutrition, IFuelSource
{
public new CompProperties_RefuelableNutrition_WithKey Props => (CompProperties_RefuelableNutrition_WithKey)props;
public override void PostExposeData()
{
string prefix = Props.saveKeysPrefix;
@@ -28,22 +30,19 @@ namespace ArachnaeSwarm
base.PostExposeData();
return;
}
// --- Accessing private fields from CompRefuelable (base of CompRefuelableNutrition) ---
FieldInfo fuelField = AccessTools.Field(typeof(CompRefuelable), "fuel");
FieldInfo configuredTargetFuelLevelField = AccessTools.Field(typeof(CompRefuelable), "configuredTargetFuelLevel");
FieldInfo allowAutoRefuelField = AccessTools.Field(typeof(CompRefuelable), "allowAutoRefuel");
// Get current values
float currentFuel = (float)fuelField.GetValue(this);
float currentConfiguredLevel = (float)configuredTargetFuelLevelField.GetValue(this);
bool currentAllowAuto = (bool)allowAutoRefuelField.GetValue(this);
// Scribe with prefix
Scribe_Values.Look(ref currentFuel, prefix + "_fuel", 0f);
Scribe_Values.Look(ref currentConfiguredLevel, prefix + "_configuredTargetFuelLevel", -1f);
Scribe_Values.Look(ref currentAllowAuto, prefix + "_allowAutoRefuel", true);
// Set values back if loading
if (Scribe.mode == LoadSaveMode.LoadingVars)
{
@@ -51,14 +50,65 @@ namespace ArachnaeSwarm
configuredTargetFuelLevelField.SetValue(this, currentConfiguredLevel);
allowAutoRefuelField.SetValue(this, currentAllowAuto);
}
// --- Accessing private fields from CompRefuelableNutrition ---
// (Assuming there are any. If not, this part is not needed)
// Example:
// FieldInfo someOtherField = AccessTools.Field(typeof(CompRefuelableNutrition), "someOtherPrivateField");
// ... and so on
}
// 重写燃料处理方法,添加物品类型限制
public new void Refuel(List<Thing> fuelThings)
{
// 过滤掉禁止物品类型的物品
List<Thing> allowedFuelThings = new List<Thing>();
List<Thing> disallowedFuelThings = new List<Thing>();
foreach (var thing in fuelThings)
{
if (IsFuelAllowed(thing))
{
allowedFuelThings.Add(thing);
}
else
{
disallowedFuelThings.Add(thing);
}
}
// 如果有被禁止的物品,给出提示
if (disallowedFuelThings.Count > 0)
{
string disallowedNames = string.Join(", ", disallowedFuelThings.Select(t => t.LabelCap));
Messages.Message("CannotUseDisallowedFuel".Translate(disallowedNames, parent.LabelCap), disallowedFuelThings, MessageTypeDefOf.RejectInput);
}
// 只对允许的物品调用基类的Refuel方法
if (allowedFuelThings.Count > 0)
{
base.Refuel(allowedFuelThings);
}
}
// 检查燃料是否被允许
private bool IsFuelAllowed(Thing fuel)
{
// 检查是否在禁止的物品类型列表中
if (IsInDisallowedThingDefs(fuel))
return false;
return true;
}
// 检查物品是否在禁止的物品类型列表中
private bool IsInDisallowedThingDefs(Thing thing)
{
if (Props.disallowedThingDefs == null || Props.disallowedThingDefs.Count == 0)
return false;
return Props.disallowedThingDefs.Contains(thing.def);
}
// 可选:重写燃料描述以显示限制信息
public override string CompInspectStringExtra()
{
string baseString = base.CompInspectStringExtra();
if (Props.disallowedThingDefs != null && Props.disallowedThingDefs.Count > 0)
{
string thingNames = string.Join(", ", Props.disallowedThingDefs.Select(d => d.label));
return baseString + $"\n{"DisallowedItems".Translate()}: {thingNames}";
}
return baseString;
}
public new void Notify_UsedThisTick()
{
if (Props.consumeFuelOnlyWhenUsed)
@@ -67,4 +117,5 @@ namespace ArachnaeSwarm
}
}
}
}