ShotgunExtension和CruiseMissileProperties
This commit is contained in:
63
Source/WulaFallenEmpire/Verb/ProperShotgun.cs
Normal file
63
Source/WulaFallenEmpire/Verb/ProperShotgun.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using RimWorld;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Verse;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
public class Verb_ShootShotgun : Verb_LaunchProjectile
|
||||
{
|
||||
protected override int ShotsPerBurst
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.verbProps.burstShotCount;
|
||||
}
|
||||
}
|
||||
|
||||
public override void WarmupComplete()
|
||||
{
|
||||
base.WarmupComplete();
|
||||
Pawn pawn = this.currentTarget.Thing as Pawn;
|
||||
if (pawn != null && !pawn.Downed && this.CasterIsPawn && this.CasterPawn.skills != null)
|
||||
{
|
||||
float num = pawn.HostileTo(this.caster) ? 170f : 20f;
|
||||
float num2 = this.verbProps.AdjustedFullCycleTime(this, this.CasterPawn);
|
||||
this.CasterPawn.skills.Learn(SkillDefOf.Shooting, num * num2, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool TryCastShot()
|
||||
{
|
||||
bool flag = base.TryCastShot();
|
||||
if (flag && this.CasterIsPawn)
|
||||
{
|
||||
this.CasterPawn.records.Increment(RecordDefOf.ShotsFired);
|
||||
}
|
||||
ShotgunExtension shotgunExtension = ShotgunExtension.Get(this.verbProps.defaultProjectile);
|
||||
if (flag && shotgunExtension.pelletCount - 1 > 0)
|
||||
{
|
||||
for (int i = 0; i < shotgunExtension.pelletCount - 1; i++)
|
||||
{
|
||||
base.TryCastShot();
|
||||
}
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
}
|
||||
|
||||
public class ShotgunExtension : DefModExtension
|
||||
{
|
||||
public static ShotgunExtension Get(Def def)
|
||||
{
|
||||
return def.GetModExtension<ShotgunExtension>() ?? ShotgunExtension.defaultValues;
|
||||
}
|
||||
|
||||
private static readonly ShotgunExtension defaultValues = new ShotgunExtension();
|
||||
|
||||
public int pelletCount = 1;
|
||||
}
|
||||
}
|
||||
178
Source/WulaFallenEmpire/Verb/Trackingbullet.cs
Normal file
178
Source/WulaFallenEmpire/Verb/Trackingbullet.cs
Normal file
@@ -0,0 +1,178 @@
|
||||
using RimWorld;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using Verse;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
public class CruiseMissileProperties : DefModExtension
|
||||
{
|
||||
public DamageDef customDamageDef;
|
||||
public int customDamageAmount = 5;
|
||||
public float customExplosionRadius = 1.1f;
|
||||
public SoundDef customSoundExplode;
|
||||
|
||||
public bool useSubExplosions = true;
|
||||
public int subExplosionCount = 3;
|
||||
public float subExplosionRadius = 1.9f;
|
||||
public int subExplosionDamage = 30;
|
||||
public float subExplosionSpread = 6f;
|
||||
public DamageDef subDamageDef;
|
||||
public SoundDef subSoundExplode;
|
||||
|
||||
}
|
||||
|
||||
public class Projectile_CruiseMissile : Projectile_Explosive
|
||||
{
|
||||
private CruiseMissileProperties settings;
|
||||
private bool flag2;
|
||||
private Vector3 Randdd;
|
||||
private Vector3 position2;
|
||||
public Vector3 ExPos;
|
||||
|
||||
public override void SpawnSetup(Map map, bool respawningAfterLoad)
|
||||
{
|
||||
base.SpawnSetup(map, respawningAfterLoad);
|
||||
settings = def.GetModExtension<CruiseMissileProperties>() ?? new CruiseMissileProperties();
|
||||
}
|
||||
|
||||
private void RandFactor()
|
||||
{
|
||||
// 减少垂直方向随机性,调整水平随机范围
|
||||
Randdd = new Vector3(
|
||||
Rand.Range(-3f, 3f), // 减小水平随机范围
|
||||
Rand.Range(8f, 12f), // 降低基础高度
|
||||
Rand.Range(-3f, 3f)
|
||||
);
|
||||
flag2 = true;
|
||||
}
|
||||
|
||||
public Vector3 BPos(float t)
|
||||
{
|
||||
if (!flag2) RandFactor();
|
||||
|
||||
// 计算水平距离
|
||||
float horizontalDistance = Vector3.Distance(new Vector3(origin.x, 0, origin.z),
|
||||
new Vector3(destination.x, 0, destination.z));
|
||||
|
||||
// 动态调整控制点高度
|
||||
float arcHeight = Mathf.Clamp(horizontalDistance * 0.2f, 8f, 15f);
|
||||
|
||||
Vector3 a = origin + Vector3.forward * horizontalDistance * 0.2f + new Vector3(0f, arcHeight, 0f);
|
||||
Vector3 a2 = destination - Vector3.forward * horizontalDistance * 0.2f + new Vector3(0f, arcHeight, 0f);
|
||||
|
||||
return BezierCurve(origin, a, a2, destination, t);
|
||||
}
|
||||
|
||||
private Vector3 BezierCurve(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float t)
|
||||
{
|
||||
float u = 1 - t;
|
||||
return u * u * u * p0
|
||||
+ 3 * u * u * t * p1
|
||||
+ 3 * u * t * t * p2
|
||||
+ t * t * t * p3;
|
||||
}
|
||||
|
||||
private IEnumerable<IntVec3> GetValidCells(Map map)
|
||||
{
|
||||
if (map == null || settings == null) yield break;
|
||||
|
||||
var cells = GenRadial.RadialCellsAround(
|
||||
base.Position,
|
||||
settings.subExplosionSpread,
|
||||
false
|
||||
).Where(c => c.InBounds(map));
|
||||
|
||||
var randomizedCells = cells.InRandomOrder().Take(settings.subExplosionCount);
|
||||
|
||||
foreach (var cell in randomizedCells)
|
||||
{
|
||||
yield return cell;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Impact(Thing hitThing, bool blockedByShield = false)
|
||||
{
|
||||
var map = base.Map;
|
||||
base.Impact(hitThing, blockedByShield);
|
||||
|
||||
DoExplosion(
|
||||
base.Position,
|
||||
map,
|
||||
settings.customExplosionRadius,
|
||||
settings.customDamageDef,
|
||||
settings.customDamageAmount,
|
||||
settings.customSoundExplode
|
||||
);
|
||||
|
||||
if (settings.useSubExplosions)
|
||||
{
|
||||
foreach (var cell in GetValidCells(map))
|
||||
{
|
||||
DoExplosion(
|
||||
cell,
|
||||
map,
|
||||
settings.subExplosionRadius,
|
||||
settings.subDamageDef,
|
||||
settings.subExplosionDamage,
|
||||
settings.subSoundExplode
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DoExplosion(IntVec3 pos, Map map, float radius, DamageDef dmgDef, int dmgAmount, SoundDef sound)
|
||||
{
|
||||
GenExplosion.DoExplosion(
|
||||
pos,
|
||||
map,
|
||||
radius,
|
||||
dmgDef,
|
||||
launcher,
|
||||
dmgAmount,
|
||||
ArmorPenetration,
|
||||
sound
|
||||
);
|
||||
}
|
||||
|
||||
protected override void DrawAt(Vector3 position, bool flip = false)
|
||||
{
|
||||
position2 = BPos(DistanceCoveredFraction - 0.01f);
|
||||
ExPos = position = BPos(DistanceCoveredFraction);
|
||||
base.DrawAt(position, flip);
|
||||
}
|
||||
|
||||
protected override void Tick()
|
||||
{
|
||||
if (intendedTarget.Thing is Pawn pawn && pawn.Spawned && !pawn.Destroyed)
|
||||
{
|
||||
if ((pawn.Dead || pawn.Downed) && DistanceCoveredFraction < 0.6f)
|
||||
{
|
||||
FindNextTarget(pawn.DrawPos);
|
||||
}
|
||||
destination = pawn.DrawPos;
|
||||
}
|
||||
base.Tick();
|
||||
}
|
||||
|
||||
private void FindNextTarget(Vector3 center)
|
||||
{
|
||||
var map = base.Map;
|
||||
if (map == null) return;
|
||||
|
||||
foreach (IntVec3 cell in GenRadial.RadialCellsAround(IntVec3.FromVector3(center), 7f, true))
|
||||
{
|
||||
if (!cell.InBounds(map)) continue;
|
||||
|
||||
Pawn target = cell.GetFirstPawn(map);
|
||||
if (target != null && target.Faction.HostileTo(launcher?.Faction))
|
||||
{
|
||||
intendedTarget = target;
|
||||
return;
|
||||
}
|
||||
}
|
||||
intendedTarget = CellRect.CenteredOn(IntVec3.FromVector3(center), 7).RandomCell;
|
||||
}
|
||||
}
|
||||
}
|
||||
50
Source/WulaFallenEmpire/Verb/VerbPropertiesExplosiveBeam.cs
Normal file
50
Source/WulaFallenEmpire/Verb/VerbPropertiesExplosiveBeam.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
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 float screenShakeFactor = 0f; // 新增:屏幕震动因子
|
||||
|
||||
public VerbPropertiesExplosiveBeam()
|
||||
{
|
||||
// 设置默认值
|
||||
verbClass = typeof(Verb_ShootBeamExplosive);
|
||||
}
|
||||
}
|
||||
}
|
||||
93
Source/WulaFallenEmpire/Verb/Verb_ShootBeamExplosive.cs
Normal file
93
Source/WulaFallenEmpire/Verb/Verb_ShootBeamExplosive.cs
Normal file
@@ -0,0 +1,93 @@
|
||||
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, // 我们手动处理音效
|
||||
screenShakeFactor: explosiveProps.screenShakeFactor // 新增:屏幕震动因子
|
||||
);
|
||||
|
||||
// 生成额外的视觉效果
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user