Weapos Rejiggered

Modified weapon scripts to eliminate specialized projectile behavior - allows charged weapons to have projectiles and modify weapon stats when charged
Added machine gun weapon & VFX
Moved third party code to Plugins folder to improve compile times
This commit is contained in:
Reinier Vens 2021-01-31 03:52:32 +00:00
commit dbc522a224
2105 changed files with 7033 additions and 1141 deletions

View file

@ -88,7 +88,7 @@ public abstract class PersistentBehaviorData
}
[InspectableField,
Union(0, typeof(ProjectileWeaponData)),
// Union(0, typeof(ProjectileWeaponData)),
Union(1, typeof(LauncherData)),
Union(2, typeof(ReactorData)),
Union(3, typeof(RadiatorData)),

View file

@ -9,20 +9,38 @@ using static Unity.Mathematics.math;
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
public class ChargedWeaponData : InstantWeaponData
{
[InspectableField, JsonProperty("chargeTime"), Key(16), RuntimeInspectable]
[InspectableField, JsonProperty("chargeTime"), Key(18), RuntimeInspectable]
public PerformanceStat ChargeTime = new PerformanceStat();
[InspectableField, JsonProperty("chargeEnergy"), Key(17), RuntimeInspectable]
[InspectableField, JsonProperty("chargeEnergy"), Key(19), RuntimeInspectable]
public PerformanceStat ChargeEnergy = new PerformanceStat();
[InspectableField, JsonProperty("chargeHeat"), Key(20), RuntimeInspectable]
public PerformanceStat ChargeHeat = new PerformanceStat();
[InspectableField, JsonProperty("canFireEarly"), Key(18)]
[InspectableField, JsonProperty("canFireEarly"), Key(21)]
public bool CanFireEarly;
[InspectableField, JsonProperty("failureCharge"), Key(19)]
[InspectableField, JsonProperty("failureCharge"), Key(22)]
public float FailureCharge;
[InspectableField, JsonProperty("failureDamage"), Key(20)]
public float FailureDamage;
[InspectableField, JsonProperty("failureDamage"), Key(23)]
public float FailureDamage = 1;
[InspectableField, JsonProperty("chargeDamage"), Key(24)]
public float ChargeDamage = 1;
[InspectableField, JsonProperty("chargeSpread"), Key(25)]
public float ChargeSpread = 1;
[InspectableField, JsonProperty("chargeBurstCount"), Key(26)]
public float ChargeBurstCount = 1;
[InspectableField, JsonProperty("chargeVisibility"), Key(27)]
public float ChargeVisibility = 1;
[InspectableField, JsonProperty("chargeVelocity"), Key(28)]
public float ChargeVelocity = 1;
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
{
@ -37,12 +55,24 @@ public class ChargedWeapon : InstantWeapon
private bool _charged;
private float _charge;
private float _progress;
public float ChargeTime { get; protected set; }
public float ChargeEnergy { get; protected set; }
public float ChargeHeat { get; protected set; }
public event Action OnStartCharging;
public event Action OnStopCharging;
public event Action OnCharged;
public event Action OnFailed;
public override void ResetEvents()
{
OnStartCharging = null;
OnStopCharging = null;
OnCharged = null;
OnFailed = null;
}
public override float Progress => saturate(_charging ? _charge : _cooldown);
public float Charge
@ -55,15 +85,32 @@ public class ChargedWeapon : InstantWeapon
_data = data;
}
protected override void UpdateStats()
{
base.UpdateStats();
ChargeTime = Context.Evaluate(_data.ChargeTime, Item.EquippableItem, Entity);
ChargeEnergy = Context.Evaluate(_data.ChargeEnergy, Item.EquippableItem, Entity);
ChargeHeat = Context.Evaluate(_data.ChargeHeat, Item.EquippableItem, Entity);
Damage *= lerp(1, _data.ChargeDamage, saturate(_charge));
Spread *= lerp(1, _data.ChargeSpread, saturate(_charge));
BurstCount *= lerp(1, _data.ChargeBurstCount, saturate(_charge));
Visibility *= lerp(1, _data.ChargeVisibility, saturate(_charge));
Velocity *= lerp(1, _data.ChargeVelocity, saturate(_charge));
}
public override bool Execute(float delta)
{
if (_charging)
{
_charge += delta / Context.Evaluate(_data.ChargeTime, Item.EquippableItem, Entity);
if (!_charged && _charge > 1)
_charge += delta / ChargeTime;
if (!_charged)
{
_charged = true;
OnCharged?.Invoke();
Item.AddHeat(ChargeHeat * (delta / ChargeTime));
if(_charge > 1)
{
_charged = true;
OnCharged?.Invoke();
}
}
if (_data.FailureCharge > 1 && _charge > _data.FailureCharge)
{

View file

@ -11,7 +11,7 @@ using static Unity.Mathematics.math;
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class ConstantWeaponData : WeaponData
{
[InspectablePrefab, JsonProperty("ammoInterval"), Key(13)]
[InspectablePrefab, JsonProperty("ammoInterval"), Key(15)]
public float AmmoInterval = 1;
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
@ -42,6 +42,14 @@ public class ConstantWeapon : Weapon, IProgressBehavior
public event Action OnReloadComplete;
public event Action OnStartFiring;
public event Action OnStopFiring;
public override void ResetEvents()
{
OnReloadBegin = null;
OnReloadComplete = null;
OnStartFiring = null;
OnStopFiring = null;
}
public ConstantWeapon(ItemManager context, ConstantWeaponData data, Entity entity, EquippedItem item) : base(context, data, entity, item)
{
@ -50,6 +58,7 @@ public class ConstantWeapon : Weapon, IProgressBehavior
public override bool Execute(float delta)
{
base.Execute(delta);
if (_firing)
{
if (_data.AmmoType != Guid.Empty)

View file

@ -9,13 +9,13 @@ using static Unity.Mathematics.math;
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
public class InstantWeaponData : WeaponData
{
[InspectableField, JsonProperty("burstCount"), Key(13)]
public int BurstCount;
[InspectableField, JsonProperty("count"), Key(15)]
public PerformanceStat Count = new PerformanceStat();
[InspectableField, JsonProperty("burstTime"), Key(14)]
[InspectableField, JsonProperty("burstTime"), Key(16)]
public PerformanceStat BurstTime = new PerformanceStat();
[InspectableField, JsonProperty("cooldown"), Key(15), RuntimeInspectable]
[InspectableField, JsonProperty("cooldown"), Key(17), RuntimeInspectable]
public PerformanceStat Cooldown = new PerformanceStat();
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
@ -34,6 +34,10 @@ public class InstantWeapon : Weapon, IProgressBehavior
protected float _cooldown; // Normalized
private int _ammo = 1;
protected bool _coolingDown;
public float BurstCount { get; protected set; }
public float BurstTime { get; protected set; }
public float Cooldown { get; protected set; }
public override int Ammo
{
@ -46,6 +50,14 @@ public class InstantWeapon : Weapon, IProgressBehavior
public event Action OnCooldownComplete;
public event Action OnFire;
public override void ResetEvents()
{
OnReloadBegin = null;
OnReloadComplete = null;
OnCooldownComplete = null;
OnFire = null;
}
public InstantWeapon(ItemManager context, InstantWeaponData data, Entity entity, EquippedItem item) : base(context,data,entity,item)
{
_data = data;
@ -53,18 +65,27 @@ public class InstantWeapon : Weapon, IProgressBehavior
protected void Trigger()
{
_burstRemaining = _data.BurstCount;
_burstInterval = Context.Evaluate(_data.BurstTime, Item.EquippableItem, Entity) / _burstRemaining;
_burstRemaining = (int) BurstCount;
_burstInterval = BurstTime / _burstRemaining;
_burstTimer = 0;
_cooldown = 1;
_coolingDown = true;
}
protected override void UpdateStats()
{
base.UpdateStats();
BurstCount = Context.Evaluate(_data.Count, Item.EquippableItem, Entity);
BurstTime = Context.Evaluate(_data.BurstTime, Item.EquippableItem, Entity);
Cooldown = Context.Evaluate(_data.Cooldown, Item.EquippableItem, Entity);
}
public override bool Execute(float delta)
{
base.Execute(delta);
if (_coolingDown)
{
_cooldown -= delta / (_ammo == 0 ? _data.ReloadTime : Context.Evaluate(_data.Cooldown, Item.EquippableItem, Entity));
_cooldown -= delta / (_ammo == 0 ? _data.ReloadTime : Cooldown);
if (_cooldown < 0)
{
_coolingDown = false;
@ -109,9 +130,9 @@ public class InstantWeapon : Weapon, IProgressBehavior
_burstRemaining--;
_burstTimer -= _burstInterval;
OnFire?.Invoke();
Item.AddHeat(Context.Evaluate(_data.Heat, Item.EquippableItem, Entity));
Entity.VisibilitySources[this] = Context.Evaluate(_data.Visibility, Item.EquippableItem, Entity);
Entity.Energy -= Context.Evaluate(_data.Energy, Item.EquippableItem, Entity);
Item.AddHeat(Heat);
Entity.VisibilitySources[this] = Visibility;
Entity.Energy -= Energy;
}
return true;
}

View file

@ -9,26 +9,23 @@ using Unity.Mathematics;
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class LauncherData : LockWeaponData
{
[InspectableAnimationCurve, JsonProperty("guidance"), Key(21)]
[InspectableAnimationCurve, JsonProperty("guidance"), Key(23)]
public float4[] GuidanceCurve;
[InspectableAnimationCurve, JsonProperty("thrustCurve"), Key(22)]
[InspectableAnimationCurve, JsonProperty("thrustCurve"), Key(24)]
public float4[] ThrustCurve;
[InspectableAnimationCurve, JsonProperty("liftCurve"), Key(23)]
[InspectableAnimationCurve, JsonProperty("liftCurve"), Key(25)]
public float4[] LiftCurve;
[InspectableField, JsonProperty("thrust"), Key(24)]
[InspectableField, JsonProperty("thrust"), Key(26)]
public PerformanceStat Thrust = new PerformanceStat();
[InspectableField, JsonProperty("frequency"), Key(25)]
[InspectableField, JsonProperty("frequency"), Key(27)]
public float DodgeFrequency;
[InspectableField, JsonProperty("launchSpeed"), Key(26)]
public PerformanceStat LaunchSpeed = new PerformanceStat();
[InspectableField, JsonProperty("missileSpeed"), Key(27), RuntimeInspectable]
public PerformanceStat Velocity = new PerformanceStat();
[InspectableField, JsonProperty("missileSpeed"), Key(28), RuntimeInspectable]
public PerformanceStat MissileVelocity = new PerformanceStat();
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
{

View file

@ -9,19 +9,19 @@ using static Unity.Mathematics.math;
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
public class LockWeaponData : InstantWeaponData
{
[InspectableField, JsonProperty("speed"), Key(16), RuntimeInspectable]
[InspectableField, JsonProperty("speed"), Key(18), RuntimeInspectable]
public PerformanceStat LockSpeed = new PerformanceStat();
[InspectableField, JsonProperty("sensorImpact"), Key(17)]
[InspectableField, JsonProperty("sensorImpact"), Key(19)]
public PerformanceStat SensorImpact = new PerformanceStat();
[InspectableField, JsonProperty("threshold"), Key(18), RuntimeInspectable]
[InspectableField, JsonProperty("threshold"), Key(20), RuntimeInspectable]
public PerformanceStat LockAngle = new PerformanceStat();
[InspectableField, JsonProperty("directionImpact"), Key(19)]
[InspectableField, JsonProperty("directionImpact"), Key(21)]
public PerformanceStat DirectionImpact = new PerformanceStat();
[InspectableField, JsonProperty("decay"), Key(20)]
[InspectableField, JsonProperty("decay"), Key(22)]
public PerformanceStat Decay = new PerformanceStat();
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
@ -81,6 +81,7 @@ public class LockWeapon : InstantWeapon
var lerp = 1 - unlerp(0, 90, degrees);
_lock = saturate(_lock + pow(lerp, DirectionImpact) * delta * LockSpeed);
}
else _lock = saturate(_lock - delta * Decay);
}
return base.Execute(delta);

View file

@ -1,28 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using MessagePack;
using Newtonsoft.Json;
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class ProjectileWeaponData : InstantWeaponData
{
[InspectableField, JsonProperty("spread"), Key(16), RuntimeInspectable]
public PerformanceStat Spread = new PerformanceStat();
[InspectableField, JsonProperty("bulletInherit"), Key(17)]
public float Inherit;
[InspectableField, JsonProperty("bulletVelocity"), Key(18), RuntimeInspectable]
public PerformanceStat Velocity = new PerformanceStat();
[InspectableField, JsonProperty("auto"), Key(19)]
public bool Auto;
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
{
return Auto ? new AutoWeapon(context, this, entity, item) : new InstantWeapon(context, this, entity, item);
}
}

View file

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 77453d9e23d44c69bb853e3092f2b18d
timeCreated: 1584292789

View file

@ -60,10 +60,11 @@ public class TurretController : IBehavior
if (b is Weapon weapon)
{
_weapons.Add(weapon);
if (weapon.Data is ProjectileWeaponData projectileWeaponData)
var vel = Context.Evaluate(weapon.WeaponData.Velocity, item.EquippableItem, EquippedEntity);
if (vel > .1f)
{
_predictShots = true;
_shotSpeed = EquippedEntity.ItemManager.Evaluate(projectileWeaponData.Velocity, weapon.Item.EquippableItem, EquippedEntity);
_shotSpeed = vel;
}
}
}

View file

@ -8,9 +8,11 @@ using System.Linq;
using MessagePack;
using Newtonsoft.Json;
[Union(0, typeof(ProjectileWeaponData)),
[Union(0, typeof(InstantWeaponData)),
Union(1, typeof(LauncherData)),
Union(2, typeof(ConstantWeaponData)), RuntimeInspectable]
Union(2, typeof(ConstantWeaponData)),
Union(3, typeof(ChargedWeaponData)),
RuntimeInspectable]
public abstract class WeaponData : BehaviorData
{
[InspectableField, JsonProperty("damageType"), Key(1), RuntimeInspectable]
@ -48,6 +50,12 @@ public abstract class WeaponData : BehaviorData
[InspectablePrefab, JsonProperty("reloadTime"), Key(12)]
public float ReloadTime = 1;
[InspectablePrefab, JsonProperty("spread"), Key(13)]
public PerformanceStat Spread = new PerformanceStat();
[InspectableField, JsonProperty("velocity"), Key(14)]
public PerformanceStat Velocity = new PerformanceStat();
}
public abstract class Weapon : IActivatedBehavior
@ -61,6 +69,16 @@ public abstract class Weapon : IActivatedBehavior
public abstract int Ammo { get; }
public WeaponData WeaponData => _data;
public BehaviorData Data => _data;
public float Damage { get; protected set; }
public float Penetration { get; protected set; }
public float DamageSpread { get; protected set; }
public float Range { get; protected set; }
public float Energy { get; protected set; }
public float Heat { get; protected set; }
public float Visibility { get; protected set; }
public float Spread { get; protected set; }
public float Velocity { get; protected set; }
protected bool _firing;
@ -78,7 +96,26 @@ public abstract class Weapon : IActivatedBehavior
_data = data;
}
public abstract bool Execute(float delta);
public virtual void ResetEvents(){}
protected virtual void UpdateStats()
{
Damage = Context.Evaluate(_data.Damage, Item.EquippableItem, Entity);
Penetration = Context.Evaluate(_data.Penetration, Item.EquippableItem, Entity);
DamageSpread = Context.Evaluate(_data.DamageSpread, Item.EquippableItem, Entity);
Range = Context.Evaluate(_data.Range, Item.EquippableItem, Entity);
Energy = Context.Evaluate(_data.Energy, Item.EquippableItem, Entity);
Heat = Context.Evaluate(_data.Heat, Item.EquippableItem, Entity);
Visibility = Context.Evaluate(_data.Visibility, Item.EquippableItem, Entity);
Spread = Context.Evaluate(_data.Spread, Item.EquippableItem, Entity);
Velocity = Context.Evaluate(_data.Velocity, Item.EquippableItem, Entity);
}
public virtual bool Execute(float delta)
{
UpdateStats();
return true;
}
public virtual void Activate()
{

View file

@ -609,7 +609,7 @@ public abstract class Entity
radiation += r;
if(float.IsNaN(NewTemperature[v.x, v.y]) || NewTemperature[v.x, v.y] < 0 || NewTemperature[v.x, v.y] > 600)
if(float.IsNaN(NewTemperature[v.x, v.y]) || NewTemperature[v.x, v.y] < 0)
ItemManager.Log("HOUSTON, WE HAVE A PROBLEM!");
if (NewTemperature[v.x, v.y] < MinTemp)