各种更新

This commit is contained in:
2025-09-26 17:08:25 +08:00
parent f337d58ef2
commit bb634af947
12 changed files with 319 additions and 10 deletions

View File

@@ -2,6 +2,14 @@
"Version": 1,
"WorkspaceRootPath": "D:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\",
"Documents": [
{
"AbsoluteMoniker": "D:0:0:{EAE0DB6B-E282-C812-7F5A-6D13E9D24581}|ArachnaeSwarm.csproj|d:\\steamlibrary\\steamapps\\common\\rimworld\\mods\\arachnaeswarm\\source\\arachnaeswarm\\abilities\\ara_givehediffwithskillduration\\compabilityeffect_givehediffwithskillduration.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{EAE0DB6B-E282-C812-7F5A-6D13E9D24581}|ArachnaeSwarm.csproj|solutionrelative:abilities\\ara_givehediffwithskillduration\\compabilityeffect_givehediffwithskillduration.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
},
{
"AbsoluteMoniker": "D:0:0:{EAE0DB6B-E282-C812-7F5A-6D13E9D24581}|ArachnaeSwarm.csproj|d:\\steamlibrary\\steamapps\\common\\rimworld\\mods\\arachnaeswarm\\source\\arachnaeswarm\\abilities\\ara_givehediffwithskillduration\\compproperties_givehediffwithskillduration.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{EAE0DB6B-E282-C812-7F5A-6D13E9D24581}|ArachnaeSwarm.csproj|solutionrelative:abilities\\ara_givehediffwithskillduration\\compproperties_givehediffwithskillduration.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
},
{
"AbsoluteMoniker": "D:0:0:{EAE0DB6B-E282-C812-7F5A-6D13E9D24581}|ArachnaeSwarm.csproj|d:\\steamlibrary\\steamapps\\common\\rimworld\\mods\\arachnaeswarm\\source\\arachnaeswarm\\abilities\\ara_terrainrestriction\\compabilityeffect_terrainrestriction .cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{EAE0DB6B-E282-C812-7F5A-6D13E9D24581}|ArachnaeSwarm.csproj|solutionrelative:abilities\\ara_terrainrestriction\\compabilityeffect_terrainrestriction .cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
@@ -14,15 +22,41 @@
"DocumentGroups": [
{
"DockedWidth": 200,
"SelectedChildIndex": 1,
"SelectedChildIndex": 2,
"Children": [
{
"$type": "Bookmark",
"Name": "ST:0:0:{1c4feeaa-4718-4aa9-859d-94ce25d182ba}"
},
{
"$type": "Document",
"DocumentIndex": 1,
"Title": "CompProperties_GiveHediffWithSkillDuration.cs",
"DocumentMoniker": "D:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\Abilities\\ARA_GiveHediffWithSkillDuration\\CompProperties_GiveHediffWithSkillDuration.cs",
"RelativeDocumentMoniker": "Abilities\\ARA_GiveHediffWithSkillDuration\\CompProperties_GiveHediffWithSkillDuration.cs",
"ToolTip": "D:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\Abilities\\ARA_GiveHediffWithSkillDuration\\CompProperties_GiveHediffWithSkillDuration.cs*",
"RelativeToolTip": "Abilities\\ARA_GiveHediffWithSkillDuration\\CompProperties_GiveHediffWithSkillDuration.cs*",
"ViewState": "AgIAAAEAAAAAAAAAAAAiwC4AAAAFAAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2025-09-26T06:01:20.721Z",
"EditorCaption": ""
},
{
"$type": "Document",
"DocumentIndex": 0,
"Title": "CompAbilityEffect_GiveHediffWithSkillDuration.cs",
"DocumentMoniker": "D:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\Abilities\\ARA_GiveHediffWithSkillDuration\\CompAbilityEffect_GiveHediffWithSkillDuration.cs",
"RelativeDocumentMoniker": "Abilities\\ARA_GiveHediffWithSkillDuration\\CompAbilityEffect_GiveHediffWithSkillDuration.cs",
"ToolTip": "D:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\Abilities\\ARA_GiveHediffWithSkillDuration\\CompAbilityEffect_GiveHediffWithSkillDuration.cs*",
"RelativeToolTip": "Abilities\\ARA_GiveHediffWithSkillDuration\\CompAbilityEffect_GiveHediffWithSkillDuration.cs*",
"ViewState": "AgIAACYAAAAAAAAAAAAqwEgAAAAnAAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2025-09-26T06:00:59.354Z",
"EditorCaption": ""
},
{
"$type": "Document",
"DocumentIndex": 2,
"Title": "CompAbilityEffect_TerrainRestriction .cs",
"DocumentMoniker": "D:\\SteamLibrary\\steamapps\\common\\RimWorld\\Mods\\ArachnaeSwarm\\Source\\ArachnaeSwarm\\Abilities\\ARA_TerrainRestriction\\CompAbilityEffect_TerrainRestriction .cs",
"RelativeDocumentMoniker": "Abilities\\ARA_TerrainRestriction\\CompAbilityEffect_TerrainRestriction .cs",

View File

@@ -0,0 +1,160 @@
using RimWorld;
using Verse;
using System.Text;
namespace ArachnaeSwarm
{
public class CompAbilityEffect_GiveHediffWithSkillDuration : CompAbilityEffect_WithDuration
{
public new CompProperties_AbilityGiveHediffWithSkillDuration Props => (CompProperties_AbilityGiveHediffWithSkillDuration)props;
public override void Apply(LocalTargetInfo target, LocalTargetInfo dest)
{
base.Apply(target, dest);
if (!Props.ignoreSelf || target.Pawn != parent.pawn)
{
if (!Props.onlyApplyToSelf && Props.applyToTarget)
{
ApplyToTarget(target.Pawn, parent.pawn);
}
if (Props.applyToSelf || Props.onlyApplyToSelf)
{
ApplyToTarget(parent.pawn, target.Pawn);
}
}
}
private void ApplyToTarget(Pawn target, Pawn other)
{
if (target == null) return;
if (TryResist(target))
{
MoteMaker.ThrowText(target.DrawPos, target.Map, "Resisted".Translate());
return;
}
if (Props.replaceExisting)
{
Hediff existingHediff = target.health.hediffSet.GetFirstHediffOfDef(Props.hediffDef);
if (existingHediff != null)
{
target.health.RemoveHediff(existingHediff);
}
}
Hediff hediff = HediffMaker.MakeHediff(Props.hediffDef, target, Props.onlyBrain ? target.health.hediffSet.GetBrain() : null);
HediffComp_Disappears disappearsComp = hediff.TryGetComp<HediffComp_Disappears>();
if (disappearsComp != null)
{
disappearsComp.ticksToDisappear = GetDurationWithSkillBonus(target).SecondsToTicks();
}
if (Props.severity >= 0f)
{
hediff.Severity = Props.severity;
}
HediffComp_Link linkComp = hediff.TryGetComp<HediffComp_Link>();
if (linkComp != null)
{
linkComp.other = other;
linkComp.drawConnection = target == parent.pawn;
}
target.health.AddHediff(hediff);
}
private float GetDurationWithSkillBonus(Pawn target)
{
// 使用基类的durationSeconds作为基础值
float baseDuration = Props.ActualBaseDurationSeconds;
if (Props.skillDef != null && parent.pawn != null && parent.pawn.skills != null)
{
SkillRecord skill = parent.pawn.skills.GetSkill(Props.skillDef);
if (skill != null)
{
int effectiveLevel = skill.Level;
if (Props.maxBonusLevels > 0 && effectiveLevel > Props.maxBonusLevels)
{
effectiveLevel = Props.maxBonusLevels;
}
return baseDuration + (effectiveLevel * Props.extraSecondsPerSkillLevel);
}
}
return baseDuration;
}
protected virtual bool TryResist(Pawn pawn)
{
return false;
}
// 在工具提示中显示技能加成信息
public override string ExtraTooltipPart()
{
StringBuilder stringBuilder = new StringBuilder();
// 先添加基类的工具提示
string baseTooltip = base.ExtraTooltipPart();
if (!string.IsNullOrEmpty(baseTooltip))
{
stringBuilder.AppendLine(baseTooltip);
}
// 添加技能加成信息
if (Props.showSkillBonusInTooltip && Props.skillDef != null && parent.pawn != null)
{
SkillRecord skill = parent.pawn.skills?.GetSkill(Props.skillDef);
if (skill != null)
{
stringBuilder.AppendLine("AbilitySkillDurationBonus".Translate(
Props.skillDef.LabelCap,
skill.Level,
GetSkillBonusDuration(),
GetTotalDuration()
));
}
}
return stringBuilder.ToString().TrimEndNewlines();
}
// 获取技能加成的持续时间
private float GetSkillBonusDuration()
{
if (Props.skillDef == null || parent.pawn == null) return 0f;
SkillRecord skill = parent.pawn.skills.GetSkill(Props.skillDef);
if (skill == null) return 0f;
int effectiveLevel = skill.Level;
if (Props.maxBonusLevels > 0 && effectiveLevel > Props.maxBonusLevels)
{
effectiveLevel = Props.maxBonusLevels;
}
return effectiveLevel * Props.extraSecondsPerSkillLevel;
}
// 获取总持续时间
private float GetTotalDuration()
{
return Props.ActualBaseDurationSeconds + GetSkillBonusDuration();
}
public override bool AICanTargetNow(LocalTargetInfo target)
{
if (parent.pawn.Faction == Faction.OfPlayer)
{
return false;
}
return target.Pawn != null;
}
}
}

View File

@@ -0,0 +1,48 @@
using RimWorld;
using Verse;
namespace ArachnaeSwarm
{
public class CompProperties_AbilityGiveHediffWithSkillDuration : CompProperties_AbilityGiveHediff
{
public SkillDef skillDef; // 影响持续时间的技能
public float baseDurationSeconds = -1f; // 基础持续时间(秒),-1表示使用基类的durationSeconds
public float extraSecondsPerSkillLevel = 10f; // 每级技能增加的秒数
public int maxBonusLevels = 10; // 最大可获加成的技能等级
public bool showSkillBonusInTooltip = true; // 是否在提示中显示技能加成
public CompProperties_AbilityGiveHediffWithSkillDuration()
{
this.compClass = typeof(CompAbilityEffect_GiveHediffWithSkillDuration);
}
// 在属性类中添加这个方法来安全地获取持续时间
public float GetBaseDuration()
{
// 如果设置了自定义基础持续时间,使用它
if (baseDurationSeconds >= 0)
return baseDurationSeconds;
// 否则使用基类的durationSeconds字段
// 使用反射来访问基类的私有字段
var field = typeof(CompProperties_AbilityEffectWithDuration).GetField("durationSeconds",
System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
if (field != null)
{
return (float)field.GetValue(this);
}
// 如果反射失败,返回默认值
return 60f;
}
// 添加一个属性来获取实际的基础持续时间
public float ActualBaseDurationSeconds
{
get
{
return GetBaseDuration();
}
}
}
}

View File

@@ -73,6 +73,8 @@
<Compile Include="Abilities\ARA_AbilitySwitch\WeaponSwitch.cs" />
<Compile Include="Abilities\ARA_AddExtraExp\CompAbilityEffect_AddExtraExp.cs" />
<Compile Include="Abilities\ARA_AddExtraExp\CompProperties_AddExtraExp.cs" />
<Compile Include="Abilities\ARA_GiveHediffWithSkillDuration\CompAbilityEffect_GiveHediffWithSkillDuration.cs" />
<Compile Include="Abilities\ARA_GiveHediffWithSkillDuration\CompProperties_GiveHediffWithSkillDuration.cs" />
<Compile Include="Abilities\ARA_HuggingFace\CompAbilityEffect_Possess.cs" />
<Compile Include="Abilities\ARA_HuggingFace\CompProperties_AbilityPossess.cs" />
<Compile Include="Abilities\ARA_HuggingFace\Hediff_Possession.cs" />