添加爆炸射线武器系统

This commit is contained in:
2025-07-21 12:33:45 +08:00
parent 416492ed35
commit b8f3fc5bcd
12 changed files with 1172 additions and 1 deletions

View File

@@ -0,0 +1,49 @@
using RimWorld;
using Verse;
using Verse.Sound;
namespace WulaFallenEmpire
{
public class VerbPropertiesExplosiveBeam : VerbProperties
{
// 爆炸开关
public bool enableExplosion = false;
// 每x个shotcount触发一次爆炸
public int explosionShotInterval = 1;
// 爆炸基础属性
public float explosionRadius = 2.9f;
public DamageDef explosionDamageDef = null; // null时使用默认的Bomb
public int explosionDamage = -1; // -1时使用武器默认伤害
public float explosionArmorPenetration = -1f; // -1时使用武器默认穿甲
// 爆炸音效和特效
public SoundDef explosionSound = null;
public EffecterDef explosionEffecter = null;
// 爆炸后生成物品
public ThingDef postExplosionSpawnThingDef = null;
public float postExplosionSpawnChance = 0f;
public int postExplosionSpawnThingCount = 1;
// 爆炸前生成物品
public ThingDef preExplosionSpawnThingDef = null;
public float preExplosionSpawnChance = 0f;
public int preExplosionSpawnThingCount = 1;
// 气体效果
public GasType? postExplosionGasType = null;
// 其他爆炸属性
public bool applyDamageToExplosionCellsNeighbors = true;
public float chanceToStartFire = 0f;
public bool damageFalloff = true;
public VerbPropertiesExplosiveBeam()
{
// 设置默认值
verbClass = typeof(Verb_ShootBeamExplosive);
}
}
}

View File

@@ -0,0 +1,92 @@
using System.Collections.Generic;
using RimWorld;
using UnityEngine;
using Verse;
using Verse.Sound;
namespace WulaFallenEmpire
{
public class Verb_ShootBeamExplosive : Verse.Verb_ShootBeam
{
private int explosionShotCounter = 0;
protected override bool TryCastShot()
{
bool result = base.TryCastShot();
if (result && verbProps is VerbPropertiesExplosiveBeam explosiveProps && explosiveProps.enableExplosion)
{
explosionShotCounter++;
if (explosionShotCounter >= explosiveProps.explosionShotInterval)
{
explosionShotCounter = 0;
TriggerExplosion(explosiveProps);
}
}
return result;
}
private void TriggerExplosion(VerbPropertiesExplosiveBeam explosiveProps)
{
Vector3 explosionPos = InterpolatedPosition;
IntVec3 explosionCell = explosionPos.ToIntVec3();
if (!explosionCell.InBounds(caster.Map))
return;
// 播放爆炸音效
if (explosiveProps.explosionSound != null)
{
explosiveProps.explosionSound.PlayOneShot(new TargetInfo(explosionCell, caster.Map));
}
// 生成爆炸
GenExplosion.DoExplosion(
center: explosionCell,
map: caster.Map,
radius: explosiveProps.explosionRadius,
damType: explosiveProps.explosionDamageDef ?? DamageDefOf.Bomb,
instigator: caster,
damAmount: explosiveProps.explosionDamage > 0 ? explosiveProps.explosionDamage : verbProps.defaultProjectile?.projectile?.GetDamageAmount(EquipmentSource) ?? 20,
armorPenetration: explosiveProps.explosionArmorPenetration >= 0 ? explosiveProps.explosionArmorPenetration : verbProps.defaultProjectile?.projectile?.GetArmorPenetration(EquipmentSource) ?? 0.3f,
explosionSound: null, // 我们已经手动播放了音效
weapon: base.EquipmentSource?.def,
projectile: null,
intendedTarget: currentTarget.Thing,
postExplosionSpawnThingDef: explosiveProps.postExplosionSpawnThingDef,
postExplosionSpawnChance: explosiveProps.postExplosionSpawnChance,
postExplosionSpawnThingCount: explosiveProps.postExplosionSpawnThingCount,
postExplosionGasType: explosiveProps.postExplosionGasType,
applyDamageToExplosionCellsNeighbors: explosiveProps.applyDamageToExplosionCellsNeighbors,
preExplosionSpawnThingDef: explosiveProps.preExplosionSpawnThingDef,
preExplosionSpawnChance: explosiveProps.preExplosionSpawnChance,
preExplosionSpawnThingCount: explosiveProps.preExplosionSpawnThingCount,
chanceToStartFire: explosiveProps.chanceToStartFire,
damageFalloff: explosiveProps.damageFalloff,
direction: null,
ignoredThings: null,
affectedAngle: null,
doVisualEffects: true,
propagationSpeed: 0.6f,
excludeRadius: 0f,
doSoundEffects: false // 我们手动处理音效
);
// 生成额外的视觉效果
if (explosiveProps.explosionEffecter != null)
{
Effecter effecter = explosiveProps.explosionEffecter.Spawn(explosionCell, caster.Map);
effecter.Trigger(new TargetInfo(explosionCell, caster.Map), TargetInfo.Invalid);
effecter.Cleanup();
}
}
public override void ExposeData()
{
base.ExposeData();
Scribe_Values.Look(ref explosionShotCounter, "explosionShotCounter", 0);
}
}
}

View File

@@ -75,6 +75,8 @@
<Compile Include="JobDriver_FeedWulaPatient.cs" />
<Compile Include="WulaStatDefOf.cs" />
<Compile Include="CompUseEffect_WulaSkillTrainer.cs" />
<Compile Include="Verb_ShootBeamExplosive.cs" />
<Compile Include="VerbPropertiesExplosiveBeam.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>