全局订单材质支持,全局订单小图标,部分属性的stat暴露

This commit is contained in:
2025-11-05 16:50:54 +08:00
parent fde14edc0a
commit 0ec8e886e8
19 changed files with 1229 additions and 1249 deletions

View File

@@ -1,17 +0,0 @@
using RimWorld;
using Verse;
namespace WulaFallenEmpire
{
[DefOf]
public static class WulaStatDefOf
{
public static StatDef WulaEnergyMaxLevelOffset;
public static StatDef WulaEnergyFallRateFactor;
static WulaStatDefOf()
{
DefOfHelper.EnsureInitializedInCtor(typeof(WulaStatDefOf));
}
}
}

View File

@@ -13,24 +13,29 @@ namespace WulaFallenEmpire
compClass = typeof(HediffComp_MaintenanceDamage);
}
}
// 在 HediffComp_MaintenanceDamage 类中添加 StatDef 支持
public class HediffComp_MaintenanceDamage : HediffComp
{
private HediffCompProperties_MaintenanceDamage Props => (HediffCompProperties_MaintenanceDamage)props;
public override void Notify_PawnPostApplyDamage(DamageInfo dinfo, float totalDamageDealt)
{
base.Notify_PawnPostApplyDamage(dinfo, totalDamageDealt);
// 获取维护需求
var maintenanceNeed = Pawn.needs?.TryGetNeed<Need_Maintenance>();
if (maintenanceNeed == null)
return;
// 直接应用伤害惩罚
// 使用 StatDef 值而不是硬编码值
maintenanceNeed.ApplyDamagePenalty(totalDamageDealt);
}
public override string CompTipStringExtra
{
get
{
// 获取 StatDef 值
var statDef = DefDatabase<StatDef>.GetNamedSilentFail("WULA_MaintenanceDamageToMaintenanceFactor");
float damageFactor = statDef != null ? Pawn.GetStatValue(statDef) : Props.damageToMaintenanceFactor;
public override string CompTipStringExtra => "WULA_DamageAffectsMaintenance".Translate(Props.damageToMaintenanceFactor.ToStringPercent());
return "WULA_DamageAffectsMaintenance".Translate(damageFactor.ToStringPercent());
}
}
}
}

View File

@@ -9,18 +9,19 @@ namespace WulaFallenEmpire
public float severityPerDayBeforeThreshold = 0.05f;
public float severityPerDayAfterThreshold = 0.1f;
public float thresholdDays = 5f;
// 状态阈值
public float minorBreakdownThreshold = 0.3f;
public float majorBreakdownThreshold = 0.1f;
public float criticalFailureThreshold = 0.01f;
// 伤害相关设置 - 简化
public float damageToMaintenanceFactor = 0.01f; // 每点伤害扣除的维护度
// 伤害相关设置
public float damageToMaintenanceFactor = 0.01f;
// 维护效果相关的 HediffDefs
public HediffDef minorBreakdownHediff = null;
public HediffDef majorBreakdownHediff = null;
public HediffDef criticalFailureHediff = null;
}
}

View File

@@ -22,15 +22,34 @@ namespace WulaFallenEmpire
{
get
{
if (CurLevel <= Extension?.criticalFailureThreshold) return MaintenanceStatus.CriticalFailure;
if (CurLevel <= Extension?.majorBreakdownThreshold) return MaintenanceStatus.MajorBreakdown;
if (CurLevel <= Extension?.minorBreakdownThreshold) return MaintenanceStatus.MinorBreakdown;
if (Extension == null) return MaintenanceStatus.Operational;
// 获取阈值乘数
float minorFactor = GetStatValue("WULA_MaintenanceMinorBreakdownThresholdFactor");
float majorFactor = GetStatValue("WULA_MaintenanceMajorBreakdownThresholdFactor");
float criticalFactor = GetStatValue("WULA_MaintenanceCriticalFailureThresholdFactor");
float minorThreshold = Extension.minorBreakdownThreshold * minorFactor;
float majorThreshold = Extension.majorBreakdownThreshold * majorFactor;
float criticalThreshold = Extension.criticalFailureThreshold * criticalFactor;
if (CurLevel <= criticalThreshold) return MaintenanceStatus.CriticalFailure;
if (CurLevel <= majorThreshold) return MaintenanceStatus.MajorBreakdown;
if (CurLevel <= minorThreshold) return MaintenanceStatus.MinorBreakdown;
return MaintenanceStatus.Operational;
}
}
public float DaysSinceLastMaintenance => daysSinceLastMaintenance;
// 新增:获取 StatDef 值的方法
private float GetStatValue(string statDefName)
{
var statDef = DefDatabase<StatDef>.GetNamedSilentFail(statDefName);
if (statDef != null)
{
return pawn.GetStatValue(statDef);
}
return 1.0f; // 默认值
}
public Need_Maintenance(Pawn pawn) : base(pawn)
{
}
@@ -68,19 +87,17 @@ namespace WulaFallenEmpire
CheckStatusChanges();
}
// 修改 CalculateDegradationRate 方法以使用 StatDef
private float CalculateDegradationRate()
{
if (Extension == null)
return 0f;
if (daysSinceLastMaintenance < Extension.thresholdDays)
{
return Extension.severityPerDayBeforeThreshold;
}
else
{
return Extension.severityPerDayAfterThreshold;
}
float baseRate = daysSinceLastMaintenance < Extension.thresholdDays ?
Extension.severityPerDayBeforeThreshold :
Extension.severityPerDayAfterThreshold;
// 应用退化乘数
float degradationFactor = GetStatValue("WULA_MaintenanceDegradationFactor");
return baseRate * degradationFactor;
}
private void CheckStatusChanges()
@@ -173,15 +190,17 @@ namespace WulaFallenEmpire
OnMaintenancePerformed(maintenanceAmount);
}
// 应用伤害惩罚 - 简单的线性减少
// 修改 ApplyDamagePenalty 方法以使用 StatDef
public void ApplyDamagePenalty(float damageAmount)
{
if (Extension == null) return;
// 直接线性减少维护度
float reduction = damageAmount * Extension.damageToMaintenanceFactor;
// 获取伤害转换因子
float damageFactor = GetStatValue("WULA_MaintenanceDamageToMaintenanceFactor");
float reduction = damageAmount * damageFactor;
CurLevel = Math.Max(0f, CurLevel - reduction);
// 检查状态变化
var newStatus = Status;
if (newStatus != currentAppliedStatus)