人格核心
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// 在 Building_GlobalWorkTable.cs 中移除材质相关代码
|
||||
// 在 Building_GlobalWorkTable.cs 中添加材质处理逻辑
|
||||
using RimWorld;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -17,6 +17,13 @@ namespace WulaFallenEmpire
|
||||
private int lastProcessTick = -1;
|
||||
private const int ProcessInterval = 1;
|
||||
|
||||
// 材质映射定义
|
||||
private static readonly Dictionary<StuffCategoryDef, ThingDef> StuffCategoryMapping = new Dictionary<StuffCategoryDef, ThingDef>
|
||||
{
|
||||
{ StuffCategoryDefOf.Metallic, ThingDefOf.Plasteel }, // 金属类 -> 玻璃钢
|
||||
{ StuffCategoryDefOf.Fabric, ThingDefOf_WULA.Hyperweave } // 布革类 -> 超织物
|
||||
};
|
||||
|
||||
public Building_GlobalWorkTable()
|
||||
{
|
||||
globalOrderStack = new GlobalProductionOrderStack(this);
|
||||
@@ -214,7 +221,7 @@ namespace WulaFallenEmpire
|
||||
if (!validSpots.Contains(cell) && cell.Standable(map))
|
||||
{
|
||||
validSpots.Add(cell);
|
||||
|
||||
|
||||
if (validSpots.Count >= maxSpots)
|
||||
break;
|
||||
}
|
||||
@@ -224,7 +231,7 @@ namespace WulaFallenEmpire
|
||||
return validSpots;
|
||||
}
|
||||
|
||||
// 简化:分配物品到空投舱,移除材质相关代码
|
||||
// 新增:分配物品到空投舱,包含材质处理
|
||||
private List<List<Thing>> DistributeItemsToPods(GlobalStorageWorldComponent storage, int podCount)
|
||||
{
|
||||
List<List<Thing>> podContents = new List<List<Thing>>();
|
||||
@@ -264,8 +271,7 @@ namespace WulaFallenEmpire
|
||||
while (remainingCount > 0)
|
||||
{
|
||||
int stackSize = Mathf.Min(remainingCount, thingDef.stackLimit);
|
||||
Thing thing = ThingMaker.MakeThing(thingDef); // 不再传递材质参数
|
||||
thing.stackCount = stackSize;
|
||||
Thing thing = CreateThingWithMaterial(thingDef, stackSize);
|
||||
allItems.Add(thing);
|
||||
remainingCount -= stackSize;
|
||||
}
|
||||
@@ -292,6 +298,57 @@ namespace WulaFallenEmpire
|
||||
return podContents;
|
||||
}
|
||||
|
||||
// 新增:创建物品并应用材质规则
|
||||
private Thing CreateThingWithMaterial(ThingDef thingDef, int stackCount)
|
||||
{
|
||||
// 检查物品是否需要材质
|
||||
if (thingDef.MadeFromStuff)
|
||||
{
|
||||
// 获取物品可用的材质类别
|
||||
var stuffCategories = thingDef.stuffCategories;
|
||||
if (stuffCategories != null && stuffCategories.Count > 0)
|
||||
{
|
||||
// 检查是否有金属类材质需求
|
||||
var metallicCategory = stuffCategories.FirstOrDefault(sc =>
|
||||
sc.defName == "Metallic" || sc.defName.Contains("Metallic"));
|
||||
|
||||
// 检查是否有布革类材质需求
|
||||
var fabricCategory = stuffCategories.FirstOrDefault(sc =>
|
||||
sc.defName == "Fabric" || sc.defName.Contains("Fabric") ||
|
||||
sc.defName == "Leathery" || sc.defName.Contains("Leather"));
|
||||
|
||||
// 应用材质规则
|
||||
ThingDef selectedStuff = null;
|
||||
|
||||
if (metallicCategory != null)
|
||||
{
|
||||
// 金属类 -> 玻璃钢
|
||||
selectedStuff = ThingDefOf.Plasteel;
|
||||
Log.Message($"[Material Rule] {thingDef.defName} requires metallic, using Plasteel");
|
||||
}
|
||||
else if (fabricCategory != null)
|
||||
{
|
||||
// 布革类 -> 超织物
|
||||
selectedStuff = ThingDefOf_WULA.Hyperweave;
|
||||
Log.Message($"[Material Rule] {thingDef.defName} requires fabric/leather, using Hyperweave");
|
||||
}
|
||||
|
||||
// 创建带有指定材质的物品
|
||||
if (selectedStuff != null)
|
||||
{
|
||||
Thing thing = ThingMaker.MakeThing(thingDef, selectedStuff);
|
||||
thing.stackCount = stackCount;
|
||||
return thing;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 默认情况:创建无材质的物品
|
||||
Thing defaultThing = ThingMaker.MakeThing(thingDef);
|
||||
defaultThing.stackCount = stackCount;
|
||||
return defaultThing;
|
||||
}
|
||||
|
||||
// 在 Building_GlobalWorkTable.cs 中修改 GetRandomPawnKindForType 方法
|
||||
private PawnKindDef GetRandomPawnKindForType(ThingDef pawnType)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// GlobalProductionOrder.cs (移除所有材质相关代码)
|
||||
// GlobalProductionOrder.cs (修复成本计算,使用产物的costList)
|
||||
using RimWorld;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -62,13 +62,47 @@ namespace WulaFallenEmpire
|
||||
}
|
||||
}
|
||||
|
||||
// 简化:HasEnoughResources 方法,移除材质检查
|
||||
// 新增:获取产物的成本列表
|
||||
private Dictionary<ThingDef, int> GetProductCostList()
|
||||
{
|
||||
var costDict = new Dictionary<ThingDef, int>();
|
||||
|
||||
if (ProductDef?.costList != null)
|
||||
{
|
||||
foreach (var cost in ProductDef.costList)
|
||||
{
|
||||
if (costDict.ContainsKey(cost.thingDef))
|
||||
costDict[cost.thingDef] += cost.count;
|
||||
else
|
||||
costDict[cost.thingDef] = cost.count;
|
||||
}
|
||||
}
|
||||
|
||||
return costDict;
|
||||
}
|
||||
|
||||
// 修复:HasEnoughResources 方法,使用产物的costList
|
||||
public bool HasEnoughResources()
|
||||
{
|
||||
var globalStorage = Find.World.GetComponent<GlobalStorageWorldComponent>();
|
||||
if (globalStorage == null) return false;
|
||||
|
||||
// 只检查固定消耗(costList)
|
||||
// 首先检查产物的costList(对于武器等物品)
|
||||
var productCostList = GetProductCostList();
|
||||
if (productCostList.Count > 0)
|
||||
{
|
||||
foreach (var kvp in productCostList)
|
||||
{
|
||||
int requiredCount = kvp.Value;
|
||||
int availableCount = globalStorage.GetInputStorageCount(kvp.Key);
|
||||
|
||||
if (availableCount < requiredCount)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// 如果没有costList,则回退到配方的ingredients(对于加工类配方)
|
||||
foreach (var ingredient in recipe.ingredients)
|
||||
{
|
||||
bool hasEnoughForThisIngredient = false;
|
||||
@@ -92,13 +126,25 @@ namespace WulaFallenEmpire
|
||||
return true;
|
||||
}
|
||||
|
||||
// 简化:ConsumeResources 方法,移除材质消耗
|
||||
// 修复:ConsumeResources 方法,使用产物的costList
|
||||
public bool ConsumeResources()
|
||||
{
|
||||
var globalStorage = Find.World.GetComponent<GlobalStorageWorldComponent>();
|
||||
if (globalStorage == null) return false;
|
||||
|
||||
// 只消耗固定资源(costList)
|
||||
// 首先消耗产物的costList(对于武器等物品)
|
||||
var productCostList = GetProductCostList();
|
||||
if (productCostList.Count > 0)
|
||||
{
|
||||
foreach (var kvp in productCostList)
|
||||
{
|
||||
if (!globalStorage.RemoveFromInputStorage(kvp.Key, kvp.Value))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// 如果没有costList,则消耗配方的ingredients(对于加工类配方)
|
||||
foreach (var ingredient in recipe.ingredients)
|
||||
{
|
||||
bool consumedThisIngredient = false;
|
||||
@@ -125,22 +171,25 @@ namespace WulaFallenEmpire
|
||||
return true;
|
||||
}
|
||||
|
||||
// 简化:GetIngredientsTooltip 方法,只显示固定消耗
|
||||
// 修复:GetIngredientsTooltip 方法,显示正确的成本信息
|
||||
public string GetIngredientsTooltip()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.AppendLine(recipe.LabelCap);
|
||||
sb.AppendLine();
|
||||
|
||||
// 固定消耗(costList)
|
||||
sb.AppendLine("WULA_FixedIngredients".Translate() + ":");
|
||||
var globalStorage = Find.World.GetComponent<GlobalStorageWorldComponent>();
|
||||
|
||||
foreach (var ingredient in recipe.ingredients)
|
||||
// 首先显示产物的costList(对于武器等物品)
|
||||
var productCostList = GetProductCostList();
|
||||
if (productCostList.Count > 0)
|
||||
{
|
||||
foreach (var thingDef in ingredient.filter.AllowedThingDefs)
|
||||
sb.AppendLine("WULA_FixedIngredients".Translate() + ":");
|
||||
|
||||
foreach (var kvp in productCostList)
|
||||
{
|
||||
int requiredCount = ingredient.CountRequiredOfFor(thingDef, recipe);
|
||||
ThingDef thingDef = kvp.Key;
|
||||
int requiredCount = kvp.Value;
|
||||
int availableCount = globalStorage?.GetInputStorageCount(thingDef) ?? 0;
|
||||
|
||||
string itemDisplay = $"{requiredCount} {thingDef.LabelCap}";
|
||||
@@ -155,6 +204,31 @@ namespace WulaFallenEmpire
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 如果没有costList,显示配方的ingredients(对于加工类配方)
|
||||
sb.AppendLine("WULA_FixedIngredients".Translate() + ":");
|
||||
|
||||
foreach (var ingredient in recipe.ingredients)
|
||||
{
|
||||
foreach (var thingDef in ingredient.filter.AllowedThingDefs)
|
||||
{
|
||||
int requiredCount = ingredient.CountRequiredOfFor(thingDef, recipe);
|
||||
int availableCount = globalStorage?.GetInputStorageCount(thingDef) ?? 0;
|
||||
|
||||
string itemDisplay = $"{requiredCount} {thingDef.LabelCap}";
|
||||
|
||||
if (availableCount >= requiredCount)
|
||||
{
|
||||
sb.AppendLine($" <color=green>{itemDisplay}</color>");
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.AppendLine($" <color=red>{itemDisplay}</color>");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 产品
|
||||
sb.AppendLine();
|
||||
|
||||
@@ -0,0 +1,296 @@
|
||||
// HediffCompProperties_SwitchableHediff.cs
|
||||
using RimWorld;
|
||||
using Verse;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System.Text;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
public class HediffCompProperties_SwitchableHediff : HediffCompProperties
|
||||
{
|
||||
// 可切换的hediff列表
|
||||
public List<HediffDef> availableHediffs = new List<HediffDef>();
|
||||
|
||||
// 默认选择的hediff索引
|
||||
public int defaultHediffIndex = 0;
|
||||
|
||||
// Gizmo图标路径
|
||||
public string gizmoIconPath = "UI/Commands/Default";
|
||||
|
||||
// 是否显示当前状态的提示
|
||||
public bool showStatusInGizmo = true;
|
||||
|
||||
// 可自定义的标签和描述
|
||||
public string switchLabel = "WULA_SwitchableHediff_SwitchLabel"; // 默认翻译键
|
||||
public string switchDesc = "WULA_SwitchableHediff_SwitchDesc"; // 默认翻译键
|
||||
public string statusLabel = "WULA_SwitchableHediff_StatusLabel"; // 默认翻译键
|
||||
public string statusDesc = "WULA_SwitchableHediff_StatusDesc"; // 默认翻译键
|
||||
|
||||
public HediffCompProperties_SwitchableHediff()
|
||||
{
|
||||
compClass = typeof(HediffComp_SwitchableHediff);
|
||||
}
|
||||
}
|
||||
|
||||
public class HediffComp_SwitchableHediff : HediffComp
|
||||
{
|
||||
public HediffCompProperties_SwitchableHediff Props => (HediffCompProperties_SwitchableHediff)props;
|
||||
|
||||
// 当前选择的hediff索引
|
||||
private int currentHediffIndex = -1;
|
||||
|
||||
// 当前激活的hediff引用
|
||||
private Hediff activeHediff;
|
||||
|
||||
public override void CompPostMake()
|
||||
{
|
||||
base.CompPostMake();
|
||||
|
||||
// 初始化当前选择
|
||||
if (currentHediffIndex == -1 && Props.availableHediffs.Count > 0)
|
||||
{
|
||||
currentHediffIndex = Props.defaultHediffIndex;
|
||||
if (currentHediffIndex >= Props.availableHediffs.Count)
|
||||
currentHediffIndex = 0;
|
||||
|
||||
// 应用初始hediff
|
||||
ApplySelectedHediff();
|
||||
}
|
||||
}
|
||||
|
||||
// 应用当前选择的hediff
|
||||
private void ApplySelectedHediff()
|
||||
{
|
||||
// 移除之前激活的hediff
|
||||
if (activeHediff != null && Pawn.health.hediffSet.hediffs.Contains(activeHediff))
|
||||
{
|
||||
Pawn.health.RemoveHediff(activeHediff);
|
||||
}
|
||||
activeHediff = null;
|
||||
|
||||
// 应用新的hediff
|
||||
if (currentHediffIndex >= 0 && currentHediffIndex < Props.availableHediffs.Count)
|
||||
{
|
||||
var hediffDef = Props.availableHediffs[currentHediffIndex];
|
||||
if (hediffDef != null)
|
||||
{
|
||||
activeHediff = HediffMaker.MakeHediff(hediffDef, Pawn);
|
||||
activeHediff.Severity = 1f; // 默认严重性为1
|
||||
Pawn.health.AddHediff(activeHediff);
|
||||
|
||||
Log.Message($"[SwitchableHediff] Applied {hediffDef.defName} to {Pawn.LabelShort}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 切换到特定索引的hediff
|
||||
private void SwitchToHediff(int index)
|
||||
{
|
||||
if (index >= 0 && index < Props.availableHediffs.Count)
|
||||
{
|
||||
currentHediffIndex = index;
|
||||
ApplySelectedHediff();
|
||||
|
||||
// 发送切换消息
|
||||
var hediffDef = Props.availableHediffs[index];
|
||||
if (hediffDef != null)
|
||||
{
|
||||
Messages.Message("WULA_SwitchableHediff_SwitchedTo".Translate(hediffDef.label),
|
||||
Pawn, MessageTypeDefOf.SilentInput);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 获取当前hediff名称
|
||||
private string GetCurrentHediffName()
|
||||
{
|
||||
if (currentHediffIndex >= 0 && currentHediffIndex < Props.availableHediffs.Count)
|
||||
{
|
||||
var hediffDef = Props.availableHediffs[currentHediffIndex];
|
||||
return hediffDef?.label ?? "WULA_Unknown".Translate();
|
||||
}
|
||||
return "WULA_None".Translate();
|
||||
}
|
||||
|
||||
// 获取当前hediff描述
|
||||
private string GetCurrentHediffDesc()
|
||||
{
|
||||
if (currentHediffIndex >= 0 && currentHediffIndex < Props.availableHediffs.Count)
|
||||
{
|
||||
var hediffDef = Props.availableHediffs[currentHediffIndex];
|
||||
return hediffDef?.description ?? "WULA_NoDescription".Translate();
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
// 获取特定hediff的描述
|
||||
private string GetHediffDescription(int index)
|
||||
{
|
||||
if (index >= 0 && index < Props.availableHediffs.Count)
|
||||
{
|
||||
var hediffDef = Props.availableHediffs[index];
|
||||
return hediffDef?.description ?? "WULA_NoDescription".Translate();
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
// 获取特定hediff的详细工具提示(包含效果信息)
|
||||
private string GetHediffDetailedTooltip(int index)
|
||||
{
|
||||
if (index >= 0 && index < Props.availableHediffs.Count)
|
||||
{
|
||||
var hediffDef = Props.availableHediffs[index];
|
||||
if (hediffDef == null) return string.Empty;
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
// 添加描述
|
||||
if (!hediffDef.description.NullOrEmpty())
|
||||
{
|
||||
sb.AppendLine(hediffDef.description);
|
||||
}
|
||||
return sb.ToString().TrimEndNewlines();
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
public override IEnumerable<Gizmo> CompGetGizmos()
|
||||
{
|
||||
// 只有玩家派系的pawn才显示Gizmo
|
||||
if (Pawn.Faction == Faction.OfPlayer && Props.availableHediffs.Count > 1)
|
||||
{
|
||||
// 主切换按钮 - 显示当前状态
|
||||
Command_Action mainButton = new Command_Action
|
||||
{
|
||||
// 使用可自定义的标签,如果没有自定义则使用翻译键
|
||||
defaultLabel = Props.switchLabel.Translate(),
|
||||
defaultDesc = "WULA_SwitchableHediff_CurrentMode".Translate(GetCurrentHediffName()) + "\n" +
|
||||
Props.switchDesc.Translate(),
|
||||
icon = ContentFinder<Texture2D>.Get(Props.gizmoIconPath, false) ?? BaseContent.BadTex,
|
||||
action = () => {
|
||||
// 显示选择菜单
|
||||
ShowHediffSelectionMenu();
|
||||
},
|
||||
hotKey = KeyBindingDefOf.Misc2
|
||||
};
|
||||
|
||||
yield return mainButton;
|
||||
|
||||
// 如果启用了状态显示,添加一个信息Gizmo
|
||||
if (Props.showStatusInGizmo)
|
||||
{
|
||||
Command_Action statusButton = new Command_Action
|
||||
{
|
||||
defaultLabel = Props.statusLabel.Translate(GetCurrentHediffName()),
|
||||
defaultDesc = Props.statusDesc.Translate() + "\n\n" +
|
||||
"WULA_SwitchableHediff_CurrentDesc".Translate(GetCurrentHediffDesc()),
|
||||
icon = ContentFinder<Texture2D>.Get("UI/Commands/Info", false) ?? BaseContent.BadTex,
|
||||
action = () => {
|
||||
// 显示当前hediff的详细信息
|
||||
ShowCurrentHediffInfo();
|
||||
}
|
||||
};
|
||||
|
||||
yield return statusButton;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 显示hediff选择菜单
|
||||
private void ShowHediffSelectionMenu()
|
||||
{
|
||||
List<FloatMenuOption> options = new List<FloatMenuOption>();
|
||||
|
||||
for (int i = 0; i < Props.availableHediffs.Count; i++)
|
||||
{
|
||||
int index = i; // 捕获当前索引
|
||||
var hediffDef = Props.availableHediffs[i];
|
||||
string label = hediffDef?.label ?? "WULA_Unknown".Translate();
|
||||
string description = GetHediffDetailedTooltip(i); // 获取详细工具提示
|
||||
|
||||
// 标记当前选择的项目
|
||||
string prefix = (i == currentHediffIndex) ? "✓ " : " ";
|
||||
|
||||
// 创建选项
|
||||
var option = new FloatMenuOption(
|
||||
prefix + label,
|
||||
() => {
|
||||
SwitchToHediff(index);
|
||||
}
|
||||
);
|
||||
|
||||
// 设置工具提示 - 使用详细的描述信息
|
||||
option.tooltip = description;
|
||||
|
||||
options.Add(option);
|
||||
}
|
||||
|
||||
// 显示浮动菜单
|
||||
if (options.Count > 0)
|
||||
{
|
||||
Find.WindowStack.Add(new FloatMenu(options, "WULA_SwitchableHediff_SelectMode".Translate()));
|
||||
}
|
||||
}
|
||||
|
||||
// 显示当前hediff的详细信息
|
||||
private void ShowCurrentHediffInfo()
|
||||
{
|
||||
if (currentHediffIndex >= 0 && currentHediffIndex < Props.availableHediffs.Count)
|
||||
{
|
||||
var hediffDef = Props.availableHediffs[currentHediffIndex];
|
||||
string description = GetHediffDetailedTooltip(currentHediffIndex); // 使用详细工具提示
|
||||
|
||||
Messages.Message(
|
||||
"WULA_SwitchableHediff_CurrentModeInfo".Translate(hediffDef?.label, description),
|
||||
MessageTypeDefOf.SilentInput
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public override string CompTipStringExtra
|
||||
{
|
||||
get
|
||||
{
|
||||
string baseTip = base.CompTipStringExtra ?? "";
|
||||
string currentEffect = "WULA_SwitchableHediff_CurrentEffect".Translate(GetCurrentHediffName());
|
||||
|
||||
if (!string.IsNullOrEmpty(baseTip))
|
||||
return baseTip + "\n" + currentEffect;
|
||||
else
|
||||
return currentEffect;
|
||||
}
|
||||
}
|
||||
|
||||
public override string CompLabelInBracketsExtra
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetCurrentHediffName();
|
||||
}
|
||||
}
|
||||
|
||||
public override void CompExposeData()
|
||||
{
|
||||
base.CompExposeData();
|
||||
Scribe_Values.Look(ref currentHediffIndex, "currentHediffIndex", -1);
|
||||
|
||||
// 加载后重新应用hediff
|
||||
if (Scribe.mode == LoadSaveMode.PostLoadInit && currentHediffIndex != -1)
|
||||
{
|
||||
ApplySelectedHediff();
|
||||
}
|
||||
}
|
||||
|
||||
// 当父hediff被移除时,也要移除激活的hediff
|
||||
public override void CompPostPostRemoved()
|
||||
{
|
||||
base.CompPostPostRemoved();
|
||||
|
||||
if (activeHediff != null && Pawn.health.hediffSet.hediffs.Contains(activeHediff))
|
||||
{
|
||||
Pawn.health.RemoveHediff(activeHediff);
|
||||
}
|
||||
activeHediff = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,259 @@
|
||||
using RimWorld;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using Verse;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
public class CompExperienceCore : ThingComp
|
||||
{
|
||||
// 当前经验值
|
||||
private float currentExperience;
|
||||
|
||||
// 当前品质
|
||||
private QualityCategory currentQuality = QualityCategory.Normal;
|
||||
|
||||
// 当前装备者
|
||||
private Pawn equippedPawn;
|
||||
|
||||
// 上次检查时的技能经验
|
||||
private float lastSkillExperience;
|
||||
|
||||
// 是否已初始化品质
|
||||
private bool qualityInitialized;
|
||||
|
||||
public CompProperties_ExperienceCore Props => (CompProperties_ExperienceCore)props;
|
||||
|
||||
public float CurrentExperience => currentExperience;
|
||||
public QualityCategory CurrentQuality => currentQuality;
|
||||
|
||||
// 获取下一个品质阈值
|
||||
public ExperienceThreshold NextThreshold
|
||||
{
|
||||
get
|
||||
{
|
||||
var thresholds = Props.experienceThresholds;
|
||||
for (int i = 0; i < thresholds.Count; i++)
|
||||
{
|
||||
if (currentExperience < thresholds[i].experienceRequired)
|
||||
return thresholds[i];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// 获取当前品质对应的经验阈值
|
||||
public ExperienceThreshold CurrentThreshold
|
||||
{
|
||||
get
|
||||
{
|
||||
var thresholds = Props.experienceThresholds;
|
||||
for (int i = thresholds.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (currentExperience >= thresholds[i].experienceRequired)
|
||||
return thresholds[i];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Initialize(CompProperties props)
|
||||
{
|
||||
base.Initialize(props);
|
||||
|
||||
// 如果武器已经有品质,使用现有品质
|
||||
var qualityComp = parent.TryGetComp<CompQuality>();
|
||||
if (qualityComp != null && !qualityInitialized)
|
||||
{
|
||||
currentQuality = qualityComp.Quality;
|
||||
qualityInitialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Notify_Equipped(Pawn pawn)
|
||||
{
|
||||
base.Notify_Equipped(pawn);
|
||||
|
||||
equippedPawn = pawn;
|
||||
|
||||
// 记录当前技能经验
|
||||
if (pawn.skills != null && Props.trackedSkill != null)
|
||||
{
|
||||
var skill = pawn.skills.GetSkill(Props.trackedSkill);
|
||||
if (skill != null)
|
||||
{
|
||||
lastSkillExperience = skill.XpTotalEarned;
|
||||
}
|
||||
}
|
||||
|
||||
Log.Message($"[ExperienceCore] {parent.Label} equipped by {pawn.Name}, tracking {Props.trackedSkill?.defName}");
|
||||
}
|
||||
|
||||
public override void Notify_Unequipped(Pawn pawn)
|
||||
{
|
||||
base.Notify_Unequipped(pawn);
|
||||
|
||||
equippedPawn = null;
|
||||
lastSkillExperience = 0f;
|
||||
|
||||
Log.Message($"[ExperienceCore] {parent.Label} unequipped from {pawn.Name}");
|
||||
}
|
||||
|
||||
public override void CompTick()
|
||||
{
|
||||
base.CompTick();
|
||||
|
||||
// 每60tick检查一次经验变化(约1秒)
|
||||
if (Find.TickManager.TicksGame % 60 == 0 && equippedPawn != null)
|
||||
{
|
||||
UpdateExperience();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateExperience()
|
||||
{
|
||||
if (equippedPawn?.skills == null || Props.trackedSkill == null)
|
||||
return;
|
||||
|
||||
var skill = equippedPawn.skills.GetSkill(Props.trackedSkill);
|
||||
if (skill == null)
|
||||
return;
|
||||
|
||||
// 计算获得的经验
|
||||
float currentSkillExperience = skill.XpTotalEarned;
|
||||
float gainedExperience = currentSkillExperience - lastSkillExperience;
|
||||
|
||||
if (gainedExperience > 0)
|
||||
{
|
||||
// 应用倍率
|
||||
float actualGained = gainedExperience * Props.experienceMultiplier;
|
||||
currentExperience += actualGained;
|
||||
|
||||
Log.Message($"[ExperienceCore] {parent.Label} gained {actualGained:F1} experience (from {gainedExperience:F1} skill exp)");
|
||||
|
||||
// 检查品质升级
|
||||
CheckForQualityUpgrade();
|
||||
|
||||
// 更新记录的经验值
|
||||
lastSkillExperience = currentSkillExperience;
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckForQualityUpgrade()
|
||||
{
|
||||
var nextThreshold = NextThreshold;
|
||||
if (nextThreshold != null && currentExperience >= nextThreshold.experienceRequired)
|
||||
{
|
||||
UpgradeQuality(nextThreshold);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpgradeQuality(ExperienceThreshold threshold)
|
||||
{
|
||||
var oldQuality = currentQuality;
|
||||
currentQuality = threshold.quality;
|
||||
|
||||
// 更新武器的品质组件
|
||||
var qualityComp = parent.TryGetComp<CompQuality>();
|
||||
if (qualityComp != null)
|
||||
{
|
||||
qualityComp.SetQuality(threshold.quality, ArtGenerationContext.Outsider);
|
||||
}
|
||||
|
||||
// 发送升级消息
|
||||
if (!threshold.messageKey.NullOrEmpty())
|
||||
{
|
||||
Messages.Message(threshold.messageKey.Translate(parent.Label, threshold.quality.GetLabel()),
|
||||
parent, MessageTypeDefOf.PositiveEvent);
|
||||
}
|
||||
else
|
||||
{
|
||||
Messages.Message("WULA_WeaponUpgraded".Translate(parent.Label, threshold.quality.GetLabel()),
|
||||
parent, MessageTypeDefOf.PositiveEvent);
|
||||
}
|
||||
|
||||
Log.Message($"[ExperienceCore] {parent.Label} upgraded from {oldQuality} to {threshold.quality}");
|
||||
}
|
||||
|
||||
public override string CompInspectStringExtra()
|
||||
{
|
||||
if (!Props.showExperienceInfo)
|
||||
return null;
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
// 当前经验
|
||||
sb.AppendLine("WULA_CurrentExperience".Translate(currentExperience.ToString("F0")));
|
||||
|
||||
// 下一个品质阈值
|
||||
var nextThreshold = NextThreshold;
|
||||
if (nextThreshold != null)
|
||||
{
|
||||
float progress = currentExperience / nextThreshold.experienceRequired;
|
||||
sb.AppendLine("WULA_NextQualityProgress".Translate(
|
||||
nextThreshold.quality.GetLabel(),
|
||||
progress.ToStringPercent()
|
||||
));
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.AppendLine("WULA_MaxQuality".Translate(currentQuality.GetLabel()));
|
||||
}
|
||||
|
||||
// 追踪的技能
|
||||
if (Props.trackedSkill != null)
|
||||
{
|
||||
sb.Append("WULA_TrackedSkill".Translate(Props.trackedSkill.LabelCap));
|
||||
}
|
||||
|
||||
return sb.ToString().TrimEndNewlines();
|
||||
}
|
||||
|
||||
public override IEnumerable<StatDrawEntry> SpecialDisplayStats()
|
||||
{
|
||||
if (Props.showExperienceInfo)
|
||||
{
|
||||
yield return new StatDrawEntry(
|
||||
StatCategoryDefOf.Basics,
|
||||
"WULA_CurrentExperience".Translate(),
|
||||
currentExperience.ToString("F0"),
|
||||
"WULA_CurrentExperienceDesc".Translate(),
|
||||
2100
|
||||
);
|
||||
|
||||
var nextThreshold = NextThreshold;
|
||||
if (nextThreshold != null)
|
||||
{
|
||||
float progress = currentExperience / nextThreshold.experienceRequired;
|
||||
yield return new StatDrawEntry(
|
||||
StatCategoryDefOf.Basics,
|
||||
"WULA_NextQuality".Translate(),
|
||||
$"{nextThreshold.quality.GetLabel()} ({progress.ToStringPercent()})",
|
||||
"WULA_NextQualityDesc".Translate(nextThreshold.experienceRequired),
|
||||
2099
|
||||
);
|
||||
}
|
||||
|
||||
yield return new StatDrawEntry(
|
||||
StatCategoryDefOf.Basics,
|
||||
"WULA_CurrentQuality".Translate(),
|
||||
currentQuality.GetLabel(),
|
||||
"WULA_CurrentQualityDesc".Translate(),
|
||||
2098
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public override void PostExposeData()
|
||||
{
|
||||
base.PostExposeData();
|
||||
|
||||
Scribe_Values.Look(ref currentExperience, "currentExperience", 0f);
|
||||
Scribe_Values.Look(ref currentQuality, "currentQuality", QualityCategory.Normal);
|
||||
Scribe_Values.Look(ref qualityInitialized, "qualityInitialized", false);
|
||||
Scribe_Values.Look(ref lastSkillExperience, "lastSkillExperience", 0f);
|
||||
Scribe_References.Look(ref equippedPawn, "equippedPawn");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using RimWorld;
|
||||
using System.Collections.Generic;
|
||||
using Verse;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
public class CompProperties_ExperienceCore : CompProperties
|
||||
{
|
||||
// 经验阈值配置
|
||||
public List<ExperienceThreshold> experienceThresholds;
|
||||
|
||||
// 技能类型:近战还是射击
|
||||
public SkillDef trackedSkill;
|
||||
|
||||
// 经验获取倍率
|
||||
public float experienceMultiplier = 1.0f;
|
||||
|
||||
// 是否显示经验信息
|
||||
public bool showExperienceInfo = true;
|
||||
|
||||
public CompProperties_ExperienceCore()
|
||||
{
|
||||
compClass = typeof(CompExperienceCore);
|
||||
}
|
||||
}
|
||||
|
||||
public class ExperienceThreshold
|
||||
{
|
||||
public int experienceRequired;
|
||||
public QualityCategory quality;
|
||||
public string messageKey; // 升级消息的翻译键
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,8 @@ namespace WulaFallenEmpire
|
||||
public static ThingDef WULA_MaintenancePod;
|
||||
public static ThingDef WULA_Charging_Station_Synth;
|
||||
public static ThingDef WULA_PocketMapExit;
|
||||
|
||||
public static ThingDef Hyperweave;
|
||||
|
||||
static ThingDefOf_WULA()
|
||||
{
|
||||
DefOfHelper.EnsureInitializedInCtor(typeof(ThingDefOf_WULA));
|
||||
|
||||
@@ -120,6 +120,7 @@
|
||||
<Compile Include="GlobalWorkTable\CompLaunchable_ToGlobalStorage.cs" />
|
||||
<Compile Include="GlobalWorkTable\CompProperties_Launchable_ToGlobalStorage.cs" />
|
||||
<Compile Include="HediffComp\HediffCompProperties_NanoRepair.cs" />
|
||||
<Compile Include="HediffComp\HediffCompProperties_SwitchableHediff.cs" />
|
||||
<Compile Include="HediffComp\WULA_HediffDamgeShield\DRMDamageShield.cs" />
|
||||
<Compile Include="HediffComp\WULA_HediffDamgeShield\Hediff_DamageShield.cs" />
|
||||
<Compile Include="Pawn\WULA_AutoMechCarrier\CompAutoMechCarrier.cs" />
|
||||
@@ -174,6 +175,8 @@
|
||||
<Compile Include="ThingComp\WULA_CustomUniqueWeapon\CompProperties_CustomUniqueWeapon.cs" />
|
||||
<Compile Include="ThingComp\Wula_MechRepairKit\CompUseEffect_FixAllHealthConditions.cs" />
|
||||
<Compile Include="ThingComp\Wula_MechRepairKit\Recipe_AdministerWulaMechRepairKit.cs" />
|
||||
<Compile Include="ThingComp\WULA_PersonaCore\CompExperienceCore.cs" />
|
||||
<Compile Include="ThingComp\WULA_PersonaCore\CompProperties_ExperienceCore.cs" />
|
||||
<Compile Include="ThingComp\WULA_PsychicRitual\CompWulaRitualSpot.cs" />
|
||||
<Compile Include="ThingComp\WULA_PsychicRitual\PsychicRitualDef_AddHediff.cs" />
|
||||
<Compile Include="ThingComp\WULA_PsychicRitual\PsychicRitualDef_Wula.cs" />
|
||||
|
||||
Reference in New Issue
Block a user