武器特性
This commit is contained in:
Binary file not shown.
@@ -80,6 +80,15 @@
|
|||||||
<ammoCountPerCharge>2</ammoCountPerCharge>
|
<ammoCountPerCharge>2</ammoCountPerCharge>
|
||||||
<baseReloadTicks>60</baseReloadTicks>
|
<baseReloadTicks>60</baseReloadTicks>
|
||||||
</li>
|
</li>
|
||||||
|
<li Class="WulaFallenEmpire.CompProperties_CustomUniqueWeapon">
|
||||||
|
<forcedTraits>
|
||||||
|
<li>WULA_DamagePsychicScaling</li>
|
||||||
|
</forcedTraits>
|
||||||
|
<numTraitsRange>
|
||||||
|
<min>1</min>
|
||||||
|
<max>1</max>
|
||||||
|
</numTraitsRange>
|
||||||
|
</li>
|
||||||
</comps>
|
</comps>
|
||||||
<tradeability>None</tradeability>
|
<tradeability>None</tradeability>
|
||||||
</ThingDef>
|
</ThingDef>
|
||||||
@@ -246,6 +255,15 @@
|
|||||||
<ammoCountPerCharge>2</ammoCountPerCharge>
|
<ammoCountPerCharge>2</ammoCountPerCharge>
|
||||||
<baseReloadTicks>60</baseReloadTicks>
|
<baseReloadTicks>60</baseReloadTicks>
|
||||||
</li>
|
</li>
|
||||||
|
<li Class="WulaFallenEmpire.CompProperties_CustomUniqueWeapon">
|
||||||
|
<forcedTraits>
|
||||||
|
<li>WULA_DamagePsychicScaling</li>
|
||||||
|
</forcedTraits>
|
||||||
|
<numTraitsRange>
|
||||||
|
<min>1</min>
|
||||||
|
<max>1</max>
|
||||||
|
</numTraitsRange>
|
||||||
|
</li>
|
||||||
</comps>
|
</comps>
|
||||||
<tradeability>None</tradeability>
|
<tradeability>None</tradeability>
|
||||||
</ThingDef>
|
</ThingDef>
|
||||||
@@ -409,6 +427,15 @@
|
|||||||
<ammoCountPerCharge>20</ammoCountPerCharge>
|
<ammoCountPerCharge>20</ammoCountPerCharge>
|
||||||
<baseReloadTicks>60</baseReloadTicks>
|
<baseReloadTicks>60</baseReloadTicks>
|
||||||
</li>
|
</li>
|
||||||
|
<li Class="WulaFallenEmpire.CompProperties_CustomUniqueWeapon">
|
||||||
|
<forcedTraits>
|
||||||
|
<li>WULA_DamagePsychicScaling</li>
|
||||||
|
</forcedTraits>
|
||||||
|
<numTraitsRange>
|
||||||
|
<min>1</min>
|
||||||
|
<max>1</max>
|
||||||
|
</numTraitsRange>
|
||||||
|
</li>
|
||||||
</comps>
|
</comps>
|
||||||
<tradeability>None</tradeability>
|
<tradeability>None</tradeability>
|
||||||
</ThingDef>
|
</ThingDef>
|
||||||
|
|||||||
@@ -1,51 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" ?>
|
|
||||||
<Defs>
|
|
||||||
<ThingDef ParentName="BaseHumanMakeableGun">
|
|
||||||
<defName>WULA_TestWeapon_PsychicScaling</defName>
|
|
||||||
<label>心灵缩放测试枪</label>
|
|
||||||
<description>一个用于测试心灵敏感度伤害缩放的武器。</description>
|
|
||||||
<graphicData>
|
|
||||||
<texPath>Things/Item/Equipment/WeaponRanged/Autopistol</texPath>
|
|
||||||
<graphicClass>Graphic_Single</graphicClass>
|
|
||||||
</graphicData>
|
|
||||||
<soundInteract>Interact_Autopistol</soundInteract>
|
|
||||||
<statBases>
|
|
||||||
<Mass>1</Mass>
|
|
||||||
<RangedWeapon_Cooldown>1</RangedWeapon_Cooldown>
|
|
||||||
</statBases>
|
|
||||||
<tradeability>None</tradeability>
|
|
||||||
<destroyOnDrop>true</destroyOnDrop>
|
|
||||||
<verbs>
|
|
||||||
<li>
|
|
||||||
<verbClass>Verb_Shoot</verbClass>
|
|
||||||
<hasStandardCommand>true</hasStandardCommand>
|
|
||||||
<defaultProjectile>Bullet_TestWeapon_PsychicScaling</defaultProjectile>
|
|
||||||
<warmupTime>1.0</warmupTime>
|
|
||||||
<range>30</range>
|
|
||||||
<soundCast>Shot_Autopistol</soundCast>
|
|
||||||
<soundCastTail>GunTail_Light</soundCastTail>
|
|
||||||
<muzzleFlashScale>9</muzzleFlashScale>
|
|
||||||
</li>
|
|
||||||
</verbs>
|
|
||||||
<comps>
|
|
||||||
<li Class="WulaFallenEmpire.CompProperties_PsychicScaling">
|
|
||||||
<damageMultiplierPerSensitivityPoint>1.0</damageMultiplierPerSensitivityPoint>
|
|
||||||
<damageReductionMultiplierPerSensitivityPoint>1.0</damageReductionMultiplierPerSensitivityPoint>
|
|
||||||
</li>
|
|
||||||
</comps>
|
|
||||||
</ThingDef>
|
|
||||||
|
|
||||||
<ThingDef ParentName="BaseBullet">
|
|
||||||
<defName>Bullet_TestWeapon_PsychicScaling</defName>
|
|
||||||
<label>测试弹</label>
|
|
||||||
<graphicData>
|
|
||||||
<texPath>Things/Projectile/Bullet_Small</texPath>
|
|
||||||
<graphicClass>Graphic_Single</graphicClass>
|
|
||||||
</graphicData>
|
|
||||||
<projectile>
|
|
||||||
<damageDef>Bullet</damageDef>
|
|
||||||
<damageAmountBase>10</damageAmountBase>
|
|
||||||
<speed>50</speed>
|
|
||||||
</projectile>
|
|
||||||
</ThingDef>
|
|
||||||
</Defs>
|
|
||||||
@@ -1106,12 +1106,12 @@
|
|||||||
</costList>
|
</costList>
|
||||||
<verbs>
|
<verbs>
|
||||||
<li>
|
<li>
|
||||||
<verbClass>Verb_Shoot</verbClass>
|
<verbClass>WulaFallenEmpire.Verb_ShootShotgun</verbClass>
|
||||||
<hasStandardCommand>true</hasStandardCommand>
|
<hasStandardCommand>true</hasStandardCommand>
|
||||||
<defaultProjectile>WULA_Bullet_StarDrift_Shotgun_Spear</defaultProjectile>
|
<defaultProjectile>WULA_Bullet_StarDrift_Shotgun_Spear</defaultProjectile>
|
||||||
<warmupTime>0.2</warmupTime>
|
<warmupTime>0.2</warmupTime>
|
||||||
<range>15</range>
|
<range>15</range>
|
||||||
<burstShotCount>6</burstShotCount>
|
<burstShotCount>1</burstShotCount>
|
||||||
<ticksBetweenBurstShots>3</ticksBetweenBurstShots>
|
<ticksBetweenBurstShots>3</ticksBetweenBurstShots>
|
||||||
<soundCast>ChargeLance_Fire</soundCast>
|
<soundCast>ChargeLance_Fire</soundCast>
|
||||||
<soundCastTail>GunTail_Heavy</soundCastTail>
|
<soundCastTail>GunTail_Heavy</soundCastTail>
|
||||||
@@ -1133,6 +1133,11 @@
|
|||||||
<armorPenetrationBase>0.65</armorPenetrationBase>
|
<armorPenetrationBase>0.65</armorPenetrationBase>
|
||||||
<speed>55</speed>
|
<speed>55</speed>
|
||||||
</projectile>
|
</projectile>
|
||||||
|
<modExtensions>
|
||||||
|
<li Class="WulaFallenEmpire.ShotgunExtension">
|
||||||
|
<pelletCount>6</pelletCount>
|
||||||
|
</li>
|
||||||
|
</modExtensions>
|
||||||
</ThingDef>
|
</ThingDef>
|
||||||
|
|
||||||
<!-- 机枪 -->
|
<!-- 机枪 -->
|
||||||
|
|||||||
10
1.6/Defs/WeaponTraitDefs/WULA_WeaponCategoryDefs.xml
Normal file
10
1.6/Defs/WeaponTraitDefs/WULA_WeaponCategoryDefs.xml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<Defs>
|
||||||
|
|
||||||
|
<WeaponCategoryDef>
|
||||||
|
<defName>WULA_Psychic</defName>
|
||||||
|
<label>灵能</label>
|
||||||
|
<description>与心灵能量相互作用的武器。</description>
|
||||||
|
</WeaponCategoryDef>
|
||||||
|
|
||||||
|
</Defs>
|
||||||
16
1.6/Defs/WeaponTraitDefs/WULA_WeaponTraitDefs.xml
Normal file
16
1.6/Defs/WeaponTraitDefs/WULA_WeaponTraitDefs.xml
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<Defs>
|
||||||
|
|
||||||
|
<WeaponTraitDef>
|
||||||
|
<defName>WULA_DamagePsychicScaling</defName>
|
||||||
|
<label>灵能增幅</label>
|
||||||
|
<description>这把武器的伤害会随着使用者的心灵敏感度而变化。</description>
|
||||||
|
<commonality>1</commonality>
|
||||||
|
<weaponCategory>WULA_Psychic</weaponCategory>
|
||||||
|
<statOffsets>
|
||||||
|
</statOffsets>
|
||||||
|
<statFactors>
|
||||||
|
</statFactors>
|
||||||
|
</WeaponTraitDef>
|
||||||
|
|
||||||
|
</Defs>
|
||||||
154
Source/WulaFallenEmpire/CompCustomUniqueWeapon.cs
Normal file
154
Source/WulaFallenEmpire/CompCustomUniqueWeapon.cs
Normal file
@@ -0,0 +1,154 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using UnityEngine;
|
||||||
|
using Verse;
|
||||||
|
using RimWorld;
|
||||||
|
|
||||||
|
namespace WulaFallenEmpire
|
||||||
|
{
|
||||||
|
public class CompCustomUniqueWeapon : CompUniqueWeapon
|
||||||
|
{
|
||||||
|
// 使用 'new' 关键字来明确隐藏基类成员,解决 CS0108 警告
|
||||||
|
public new CompProperties_CustomUniqueWeapon Props => (CompProperties_CustomUniqueWeapon)props;
|
||||||
|
|
||||||
|
private List<WeaponTraitDef> customTraits = new List<WeaponTraitDef>();
|
||||||
|
|
||||||
|
// 使用 'new' 关键字隐藏基类属性,解决 CS0506 错误
|
||||||
|
public new List<WeaponTraitDef> TraitsListForReading => customTraits;
|
||||||
|
|
||||||
|
// PostExposeData 是 virtual 的,保留 override
|
||||||
|
public override void PostExposeData()
|
||||||
|
{
|
||||||
|
base.PostExposeData();
|
||||||
|
Scribe_Collections.Look(ref customTraits, "customTraits", LookMode.Def);
|
||||||
|
if (Scribe.mode == LoadSaveMode.PostLoadInit)
|
||||||
|
{
|
||||||
|
if (customTraits == null) customTraits = new List<WeaponTraitDef>();
|
||||||
|
SetupCustomTraits(fromSave: true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// PostPostMake 是 virtual 的,保留 override
|
||||||
|
public override void PostPostMake()
|
||||||
|
{
|
||||||
|
InitializeCustomTraits();
|
||||||
|
if (parent.TryGetComp<CompQuality>(out var comp))
|
||||||
|
{
|
||||||
|
comp.SetQuality(QualityUtility.GenerateQuality(QualityGenerator.Super), ArtGenerationContext.Outsider);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitializeCustomTraits()
|
||||||
|
{
|
||||||
|
if (customTraits == null) customTraits = new List<WeaponTraitDef>();
|
||||||
|
customTraits.Clear();
|
||||||
|
|
||||||
|
if (Props.forcedTraits != null)
|
||||||
|
{
|
||||||
|
foreach (var traitToForce in Props.forcedTraits)
|
||||||
|
{
|
||||||
|
if (customTraits.All(t => !t.Overlaps(traitToForce)))
|
||||||
|
{
|
||||||
|
customTraits.Add(traitToForce);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
IntRange traitRange = Props.numTraitsRange ?? new IntRange(1, 3);
|
||||||
|
int totalTraitsTarget = Mathf.Max(customTraits.Count, traitRange.RandomInRange);
|
||||||
|
int missingTraits = totalTraitsTarget - customTraits.Count;
|
||||||
|
|
||||||
|
if (missingTraits > 0)
|
||||||
|
{
|
||||||
|
// CanAddTrait 现在是我们自己的 'new' 方法
|
||||||
|
IEnumerable<WeaponTraitDef> possibleTraits = DefDatabase<WeaponTraitDef>.AllDefs.Where(CanAddTrait);
|
||||||
|
for (int i = 0; i < missingTraits; i++)
|
||||||
|
{
|
||||||
|
if (!possibleTraits.Any()) break;
|
||||||
|
|
||||||
|
var chosenTrait = possibleTraits.RandomElementByWeight(t => t.commonality);
|
||||||
|
customTraits.Add(chosenTrait);
|
||||||
|
|
||||||
|
possibleTraits = possibleTraits.Where(t => t != chosenTrait && !t.Overlaps(chosenTrait));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SetupCustomTraits(fromSave: false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupCustomTraits(bool fromSave)
|
||||||
|
{
|
||||||
|
foreach (WeaponTraitDef trait in customTraits)
|
||||||
|
{
|
||||||
|
if (trait.abilityProps != null && parent.GetComp<CompEquippableAbilityReloadable>() is CompEquippableAbilityReloadable comp)
|
||||||
|
{
|
||||||
|
comp.props = trait.abilityProps;
|
||||||
|
if (!fromSave)
|
||||||
|
{
|
||||||
|
comp.Notify_PropsChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 使用 'new' 关键字隐藏基类方法,解决 CS0506 错误
|
||||||
|
public new bool CanAddTrait(WeaponTraitDef trait)
|
||||||
|
{
|
||||||
|
if (customTraits.Any(t => t == trait || t.Overlaps(t)))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (Props.weaponCategories != null && Props.weaponCategories.Any() && !Props.weaponCategories.Contains(trait.weaponCategory))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (customTraits.Count == 0 && !trait.canGenerateAlone)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- 下面的方法都是 virtual 的,保留 override ---
|
||||||
|
|
||||||
|
public override string TransformLabel(string label) => label;
|
||||||
|
public override Color? ForceColor() => null;
|
||||||
|
|
||||||
|
public override float GetStatOffset(StatDef stat) => customTraits.Sum(t => t.statOffsets.GetStatOffsetFromList(stat));
|
||||||
|
public override float GetStatFactor(StatDef stat) => customTraits.Aggregate(1f, (current, t) => current * t.statFactors.GetStatFactorFromList(stat));
|
||||||
|
|
||||||
|
public override string CompInspectStringExtra()
|
||||||
|
{
|
||||||
|
if (customTraits.NullOrEmpty()) return null;
|
||||||
|
return "WeaponTraits".Translate() + ": " + customTraits.Select(t => t.label).ToCommaList().CapitalizeFirst();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string CompTipStringExtra()
|
||||||
|
{
|
||||||
|
if (customTraits.NullOrEmpty()) return base.CompTipStringExtra();
|
||||||
|
return "WeaponTraits".Translate() + ": " + customTraits.Select(t => t.label).ToCommaList().CapitalizeFirst();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IEnumerable<StatDrawEntry> SpecialDisplayStats()
|
||||||
|
{
|
||||||
|
if (customTraits.NullOrEmpty()) yield break;
|
||||||
|
|
||||||
|
var builder = new StringBuilder();
|
||||||
|
builder.AppendLine("Stat_ThingUniqueWeaponTrait_Desc".Translate());
|
||||||
|
builder.AppendLine();
|
||||||
|
|
||||||
|
for (int i = 0; i < customTraits.Count; i++)
|
||||||
|
{
|
||||||
|
WeaponTraitDef trait = customTraits[i];
|
||||||
|
builder.AppendLine(trait.LabelCap.Colorize(ColorLibrary.Yellow));
|
||||||
|
builder.AppendLine(trait.description);
|
||||||
|
if (i < customTraits.Count - 1) builder.AppendLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
yield return new StatDrawEntry(
|
||||||
|
parent.def.IsMeleeWeapon ? StatCategoryDefOf.Weapon_Melee : StatCategoryDefOf.Weapon_Ranged,
|
||||||
|
"Stat_ThingUniqueWeaponTrait_Label".Translate(),
|
||||||
|
customTraits.Select(t => t.label).ToCommaList().CapitalizeFirst(),
|
||||||
|
builder.ToString(),
|
||||||
|
1104);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
21
Source/WulaFallenEmpire/CompProperties_CustomUniqueWeapon.cs
Normal file
21
Source/WulaFallenEmpire/CompProperties_CustomUniqueWeapon.cs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using Verse;
|
||||||
|
using RimWorld;
|
||||||
|
|
||||||
|
namespace WulaFallenEmpire
|
||||||
|
{
|
||||||
|
public class CompProperties_CustomUniqueWeapon : CompProperties_UniqueWeapon
|
||||||
|
{
|
||||||
|
// A list of traits that will always be added to the weapon.
|
||||||
|
public List<WeaponTraitDef> forcedTraits;
|
||||||
|
|
||||||
|
// The range of traits to randomly add. If not defined in XML, a default of 1-3 will be used.
|
||||||
|
public IntRange? numTraitsRange;
|
||||||
|
|
||||||
|
public CompProperties_CustomUniqueWeapon()
|
||||||
|
{
|
||||||
|
// Point to the implementation of our custom logic.
|
||||||
|
this.compClass = typeof(CompCustomUniqueWeapon);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -69,6 +69,8 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Building_Wula_DarkEnergy_Engine.cs" />
|
<Compile Include="Building_Wula_DarkEnergy_Engine.cs" />
|
||||||
<Compile Include="CompApparelInterceptor.cs" />
|
<Compile Include="CompApparelInterceptor.cs" />
|
||||||
|
<Compile Include="CompCustomUniqueWeapon.cs" />
|
||||||
|
<Compile Include="CompProperties_CustomUniqueWeapon.cs" />
|
||||||
<Compile Include="CompPsychicScaling.cs" />
|
<Compile Include="CompPsychicScaling.cs" />
|
||||||
<Compile Include="CompUseEffect_FixAllHealthConditions.cs" />
|
<Compile Include="CompUseEffect_FixAllHealthConditions.cs" />
|
||||||
<Compile Include="CompUseEffect_PassionTrainer.cs" />
|
<Compile Include="CompUseEffect_PassionTrainer.cs" />
|
||||||
|
|||||||
Reference in New Issue
Block a user