Behavior Refactoring

Behaviors and PerformanceStats are no longer associated solely with Ships, instead there's a generic Entity class which will also be used for stations and turrets.
This commit is contained in:
hyperion51 2020-04-09 10:33:16 +01:00
commit 7cd24147ae
41 changed files with 544 additions and 341 deletions

View file

@ -0,0 +1,82 @@
using System.Collections.Generic;
using System.Linq;
using MessagePack;
using Newtonsoft.Json;
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class AfterburnerData : IBehaviorData
{
[InspectableField, JsonProperty("thrust"), Key(0)]
public PerformanceStat ThrustModifier = new PerformanceStat();
[InspectableField, JsonProperty("speed"), Key(1)]
public PerformanceStat SpeedModifier = new PerformanceStat();
[InspectableField, JsonProperty("torque"), Key(2)]
public PerformanceStat TorqueModifier = new PerformanceStat();
public IBehavior CreateInstance(GameContext context, Entity entity, Gear item)
{
return new Afterburner(context, this, entity, item);
}
}
public class Afterburner : IActivatedBehavior
{
private List<Dictionary<IBehavior,float>> _modifiers = new List<Dictionary<IBehavior, float>>();
private AfterburnerData _data;
private Thruster _thruster;
public Entity Entity { get; }
public Gear Item { get; }
public GameContext Context { get; }
public IBehaviorData Data => _data;
public Afterburner(GameContext context, AfterburnerData data, Entity entity, Gear item)
{
Context = context;
_data = data;
Entity = entity;
Item = item;
}
public void Initialize()
{
_thruster = Entity.GetBehaviors<Thruster>().FirstOrDefault();
}
public void Update(float delta)
{
}
public void Activate()
{
if (_thruster == null) return;
var thrustMod = ((ThrusterData) _thruster.Data).Thrust.GetScaleModifiers(Entity);
thrustMod.Add(this,Context.Evaluate(_data.ThrustModifier,Item, Entity));
_modifiers.Add(thrustMod);
Entity.AxisOverrides[_thruster] = 1;
// var speedMod = (Ship.Hull.ItemData as HullData).TopSpeed.GetScaleModifiers(Ship);
// _modifiers.Add(speedMod);
// speedMod.Add(this,Context.Evaluate(_data.SpeedModifier,Item, Ship));
//
// var torqueMod = (Ship.GetEquipped(HardpointType.Thruster).ItemData as ThrusterData).Torque.GetScaleModifiers(Ship);
// _modifiers.Add(torqueMod);
// torqueMod.Add(this,Context.Evaluate(_data.TorqueModifier,Item, Ship));
}
public void Deactivate()
{
Entity.AxisOverrides.Remove(_thruster);
foreach (var mod in _modifiers)
{
mod.Remove(this);
}
_modifiers.Clear();
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 967ca96c9f90416887db9a6a0341f58c
timeCreated: 1584292755

View file

@ -0,0 +1,50 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using JsonKnownTypes;
using MessagePack;
using Newtonsoft.Json;
using Unity.Mathematics;
using static Unity.Mathematics.math;
using static Unity.Mathematics.noise;
public interface IBehavior
{
void Initialize();
void Update(float delta);
Entity Entity { get; }
Gear Item { get; }
GameContext Context { get; }
IBehaviorData Data { get; }
}
public interface IActivatedBehavior : IBehavior
{
void Activate();
void Deactivate();
}
public interface IAnalogBehavior : IBehavior
{
void SetAxis(float value);
}
[InspectableField,
Union(0, typeof(CannonData)),
Union(1, typeof(LauncherData)),
Union(2, typeof(ReactorData)),
Union(3, typeof(RadiatorData)),
Union(4, typeof(AfterburnerData)),
Union(5, typeof(SensorData)),
Union(6, typeof(ReflectorData)),
Union(7, typeof(ShieldData)),
Union(8, typeof(ThrusterData)),
Union(9, typeof(TurningData)),
Union(10, typeof(VelocityConversionData)),
Union(11, typeof(VelocityLimitData)),
JsonConverter(typeof(JsonKnownTypesConverter<IBehaviorData>)), JsonObject(MemberSerialization.OptIn)]
public interface IBehaviorData
{
IBehavior CreateInstance(GameContext context, Entity entity, Gear item);
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c15c37d98e3dc844aafd0dedc16ce0ae
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,101 @@
using MessagePack;
using Newtonsoft.Json;
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class CannonData : WeaponData, IBehaviorData
{
[InspectablePrefab, JsonProperty("bullet"), Key(9)]
public string BulletPrefab;
[InspectableField, JsonProperty("spread"), Key(10)]
public PerformanceStat Spread = new PerformanceStat();
[InspectableField, JsonProperty("bulletInherit"), Key(11)]
public float Inherit;
[InspectableField, JsonProperty("bulletVelocity"), Key(12)]
public PerformanceStat Velocity = new PerformanceStat();
public IBehavior CreateInstance(GameContext context, Entity entity, Gear item)
{
return new Cannon(context, this, entity, item);
}
}
public class Cannon : IActivatedBehavior
{
private bool _firing;
private float _cooldown; // normalized
private CannonData _cannon;
public Entity Entity { get; }
public Gear Item { get; }
public GameContext Context { get; }
private float _firingVisibility;
public Cannon(GameContext context, CannonData c, Entity entity, Gear item)
{
Context = context;
_cannon = c;
Entity = entity;
Item = item;
}
public void Activate()
{
// Debug.Log("Activating Cannon");
// _firing = true;
// Observable.EveryUpdate().TakeWhile(_ => _firing).Subscribe(_ =>
// {
// // Debug.Log($"Updating Observable {_cooldown}");
// if (_cooldown < 0)
// {
// _cooldown = 1;
// Fire(0);
// if(_cannon.BurstCount>1)
// Observable.Interval(TimeSpan.FromSeconds(_cannon.BurstTime.Evaluate(Hardpoint) / (_cannon.BurstCount-1))).Take(_cannon.BurstCount-1)
// .Subscribe(l => Fire(l+1));
// }
// });
}
private void Fire(long b)
{
// _firingVisibility += _cannon.Visibility.Evaluate(Hardpoint);
// Hardpoint.Temperature += _cannon.Heat.Evaluate(Hardpoint) / Hardpoint.HeatCapacity;
// var inst = GameObject.Instantiate(_cannon.BulletPrefab).transform;
// Physics.IgnoreCollision(Hardpoint.Ship.Ship.GetComponent<Collider>(), inst.GetComponent<Collider>());
// var bullet = inst.GetComponent<Bullet>();
// bullet.Target = Hardpoint.Ship.Ship.Target;
// bullet.Source = Hardpoint.Ship.Ship.Hitpoints;
// bullet.Lifetime = _cannon.Range.Evaluate(Hardpoint) / _cannon.Velocity.Evaluate(Hardpoint);
// bullet.Damage = _cannon.Damage.Evaluate(Hardpoint);
// inst.position = Hardpoint.Proxy.position;
// inst.rotation = Hardpoint.Proxy.rotation;
// inst.GetComponent<Rigidbody>().velocity = _cannon.Velocity.Evaluate(Hardpoint) * Vector3.RotateTowards(-inst.forward, Hardpoint.Ship.Ship.Direction, _cannon.Deflection * Mathf.Deg2Rad, 1);
// Hardpoint.Ship.Ship.AudioSource.PlayOneShot(_cannon.Sounds.RandomElement());
// Debug.Log($"Firing bullet {b}");
}
public void Deactivate()
{
_firing = false;
}
public void Initialize()
{
}
public void Update(float delta)
{
_cooldown -= delta / Context.Evaluate(_cannon.Cooldown, Item, Entity);
_firingVisibility *= Context.Evaluate(_cannon.VisibilityDecay, Item, Entity);
if (_firingVisibility < 0.01f)
{
Entity.VisibilitySources.Remove(this);
}
}
public IBehaviorData Data => _cannon;
}

View file

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

View file

@ -0,0 +1,166 @@
using MessagePack;
using Newtonsoft.Json;
using Unity.Mathematics;
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class LauncherData : IBehaviorData
{
[InspectablePrefab, JsonProperty("missile"), Key(9)]
public string MissilePrefab;
[InspectableAnimationCurve, JsonProperty("guidance"), Key(10)]
public float4[] GuidanceCurve;
[InspectableAnimationCurve, JsonProperty("thrustCurve"), Key(11)]
public float4[] ThrustCurve;
[InspectableAnimationCurve, JsonProperty("liftCurve"), Key(12)]
public float4[] LiftCurve;
[InspectableField, JsonProperty("thrust"), Key(13)]
public PerformanceStat Thrust = new PerformanceStat();
[InspectableField, JsonProperty("lockAngle"), Key(14)]
public float LockAngle;
[InspectableField, JsonProperty("frequency"), Key(15)]
public float DodgeFrequency;
[InspectableField, JsonProperty("launchSpeed"), Key(16)]
public PerformanceStat LaunchSpeed = new PerformanceStat();
[InspectableField, JsonProperty("missileSpeed"), Key(17)]
public PerformanceStat MissileSpeed = new PerformanceStat();
[InspectableField, JsonProperty("lockOnTime"), Key(18)]
public PerformanceStat LockOnTime = new PerformanceStat();
public IBehavior CreateInstance(GameContext context, Entity entity, Gear item)
{
return new Launcher(context, this, entity, item);
}
}
public class Launcher : IActivatedBehavior
{
private bool _locking;
private float _lockingTimer;
private float _cooldown; // normalized
private bool _locked;
private LauncherData _launcher;
public Entity Entity { get; }
public Gear Item { get; }
public GameContext Context { get; }
private float _firingVisibility;
public Launcher(GameContext context, LauncherData m, Entity entity, Gear item)
{
Context = context;
_launcher = m;
Entity = entity;
Item = item;
// _audio = hp.Proxy.GetComponent<AudioSource>();
// if(_audio==null)
// _audio = hp.Proxy.gameObject.AddComponent<AudioSource>();
// _audio.clip = _launcher.BeepSound;
// _audio.loop = true;
// _audio.volume = .5f;
}
public void Activate()
{
_locking = true;
_lockingTimer = 1;
}
private void Fire(long b)
{
// _firingVisibility += _launcher.Visibility.Evaluate(Hardpoint);
// Hardpoint.Temperature += _launcher.Heat.Evaluate(Hardpoint) / Hardpoint.HeatCapacity;
// var inst = GameObject.Instantiate(_launcher.MissilePrefab).transform;
// var missile = inst.GetComponent<Bullet>();
// missile.Target = Hardpoint.Ship.Ship.Target;
// missile.Source = Hardpoint.Ship.Ship.Hitpoints;
// missile.Lifetime = _launcher.Range.Evaluate(Hardpoint) / _launcher.MissileSpeed.Evaluate(Hardpoint);
// missile.Damage = _launcher.Damage.Evaluate(Hardpoint);
// inst.position = Hardpoint.Proxy.position;
// inst.rotation = Hardpoint.Proxy.rotation;
// inst.GetComponent<Rigidbody>().velocity = _launcher.LaunchSpeed.Evaluate(Hardpoint) * Hardpoint.Proxy.forward;
// Physics.IgnoreCollision(Hardpoint.Ship.Ship.GetComponent<Collider>(), inst.GetComponent<Collider>());
// var proj = inst.gameObject.AddComponent<GuidedProjectile>();
// proj.GuidanceCurve = _launcher.GuidanceCurve;
// proj.ThrustCurve = _launcher.ThrustCurve;
// proj.LiftCurve = _launcher.LiftCurve;
// proj.TopSpeed = _launcher.MissileSpeed.Evaluate(Hardpoint);
// proj.Frequency = _launcher.DodgeFrequency;
// proj.Target = Hardpoint.Ship.Ship.Target;
// proj.Source = Hardpoint.Ship.Ship.Hitpoints;
// proj.Thrust = _launcher.Thrust.Evaluate(Hardpoint);
// _audio.PlayOneShot(_launcher.Sounds.RandomElement());
// Debug.Log($"Firing bullet {b}");
}
public void Deactivate()
{
// if (_lockingTimer < 0)
// {
// Fire(0);
// if(_launcher.BurstCount>1)
// Observable.Interval(TimeSpan.FromSeconds(_launcher.BurstTime.Evaluate(Hardpoint) / (_launcher.BurstCount-1))).Take(_launcher.BurstCount-1)
// .Subscribe(l => Fire(l+1));
// _lockingTimer = _cooldown = 1;
// _locking = _locked = false;
// _audio.Stop();
// }
// _locking = false;
// _lockingTimer = 1;
}
public void Initialize()
{
}
public void Update(float delta)
{
// if (Ship.Target == null)
// return;
//
// if (_locking && _cooldown < 0)
// {
// //if the crosshair stays under a certain LockOnBuffer distance for a certain amount of time (LockOnTime)
// if (acos(Vector2.Dot(Ship.Direction, (Ship.Target.transform.position-Ship.transform.position).normalized)) * Mathf.Rad2Deg < _launcher.LockOnDegrees)
// {
// var d = delta / _launcher.LockOnTime.Evaluate(Hardpoint);
// _lockingTimer -= d;
// if (!_locked && _lockingTimer < 0)
// {
// _locked = true;
// _audio.Play();
// } else if(Mathf.Repeat(_lockingTimer,1.0f/(_launcher.Beeps+1))-d<0)
// GameManager.Instance.InterfaceAudio.PlayOneShot(_launcher.BeepSound);
// }
// else
// {
// _lockingTimer = 1;
// _audio.Stop();
// }
// }
// else
// {
// _cooldown -= delta / _launcher.Cooldown.Evaluate(Hardpoint);
// }
//
//
// if (_firingVisibility > 0.01f)
// {
// Hardpoint.Ship.Visibility += _firingVisibility;
// _firingVisibility = 0;
// }
}
public IBehaviorData Data => _launcher;
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5fd0ce9fd7384ba5a40c2ba41ece74eb
timeCreated: 1584292825

View file

@ -0,0 +1,46 @@
using MessagePack;
using Newtonsoft.Json;
using Unity.Mathematics;
using static Unity.Mathematics.math;
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class RadiatorData : IBehaviorData
{
[InspectableField, JsonProperty("emissivity"), Key(0)]
public PerformanceStat Emissivity = new PerformanceStat();
public IBehavior CreateInstance(GameContext context, Entity entity, Gear item)
{
return new Radiator(context, this, entity, item);
}
}
public class Radiator : IBehavior
{
public Entity Entity { get; }
public Gear Item { get; }
public GameContext Context { get; }
public IBehaviorData Data => _data;
private RadiatorData _data;
public Radiator(GameContext context, RadiatorData data, Entity entity, Gear item)
{
Context = context;
_data = data;
Entity = entity;
Item = item;
}
public void Initialize()
{
}
public void Update(float delta)
{
var rad = pow(Entity.Temperature, Context.GlobalData.HeatRadiationPower) * Context.GlobalData.HeatRadiationMultiplier;
Entity.Temperature -= rad * delta;
Entity.VisibilitySources[this] = rad;
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f438ee8944644dd6925e2ee9d65229e8
timeCreated: 1586415683

View file

@ -0,0 +1,71 @@
using MessagePack;
using Newtonsoft.Json;
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class ReactorData : IBehaviorData
{
[InspectableField, JsonProperty("charge"), Key(0)]
public PerformanceStat Charge = new PerformanceStat();
[InspectableField, JsonProperty("capacitance"), Key(1)]
public PerformanceStat Capacitance = new PerformanceStat();
[InspectableField, JsonProperty("efficiency"), Key(2)]
public PerformanceStat Efficiency = new PerformanceStat();
[InspectableField, JsonProperty("overload"), Key(3)]
public PerformanceStat OverloadEfficiency = new PerformanceStat();
[InspectableField, JsonProperty("underload"), Key(4)]
public PerformanceStat UnderloadRecovery = new PerformanceStat();
public IBehavior CreateInstance(GameContext context, Entity entity, Gear item)
{
return new Reactor(context, this, entity, item);
}
}
public class Reactor : IBehavior
{
private ReactorData _data;
public Entity Entity { get; }
public Gear Item { get; }
public GameContext Context { get; }
public IBehaviorData Data => _data;
public Reactor(GameContext context, ReactorData data, Entity entity, Gear item)
{
Context = context;
_data = data;
Entity = entity;
Item = item;
}
public void Initialize()
{
}
public void Update(float delta)
{
var cap = Context.Evaluate(_data.Capacitance, Item, Entity);
var charge = Context.Evaluate(_data.Charge, Item, Entity) * delta;
var efficiency = Context.Evaluate(_data.Efficiency, Item, Entity);
Entity.AddHeat(charge / efficiency);
Entity.Energy += charge;
if (Entity.Energy > cap)
{
Entity.AddHeat(-(Entity.Energy - cap) / efficiency * (1 - 1 / Context.Evaluate(_data.UnderloadRecovery, Item, Entity)));
Entity.Energy = cap;
}
if (Entity.Energy < 0)
{
Entity.AddHeat( -Entity.Energy / Context.Evaluate(_data.OverloadEfficiency, Item, Entity));
Entity.Energy = 0;
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ca5f08285ca3403a8abe46001a16b6c4
timeCreated: 1584292860

View file

@ -0,0 +1,46 @@
using MessagePack;
using Newtonsoft.Json;
using Unity.Mathematics;
using static Unity.Mathematics.math;
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class ReflectorData : IBehaviorData
{
[InspectableField, JsonProperty("crossSection"), Key(0)]
public PerformanceStat CrossSection = new PerformanceStat();
// [InspectableAnimationCurve, JsonProperty("visibility"), Key(1)]
// public float4[] VisibilityCurve;
public IBehavior CreateInstance(GameContext context, Entity entity, Gear item)
{
return new Reflector(context, this, entity, item);
}
}
public class Reflector : IBehavior
{
public Entity Entity { get; }
public Gear Item { get; }
public GameContext Context { get; }
public IBehaviorData Data => _data;
private ReflectorData _data;
public Reflector(GameContext context, ReflectorData data, Entity entity, Gear item)
{
Context = context;
_data = data;
Entity = entity;
Item = item;
}
public void Initialize()
{
}
public void Update(float delta)
{
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d3eb7e73847b493991239c1beb8404c8
timeCreated: 1586415699

View file

@ -0,0 +1,68 @@
using MessagePack;
using Newtonsoft.Json;
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class SensorData : IBehaviorData
{
[InspectableField, JsonProperty("radiance"), Key(0)]
public PerformanceStat Radiance = new PerformanceStat();
[InspectableField, JsonProperty("masking"), Key(1)]
public PerformanceStat RadianceMasking = new PerformanceStat();
[InspectableField, JsonProperty("sensitivity"), Key(2)]
public PerformanceStat Sensitivity = new PerformanceStat();
[InspectableField, JsonProperty("range"), Key(3)]
public PerformanceStat Range = new PerformanceStat();
public IBehavior CreateInstance(GameContext context, Entity entity, Gear item)
{
return new Sensor(context, this, entity, item);
}
}
public class Sensor : IBehavior
{
private SensorData _data;
public Entity Entity { get; }
public Gear Item { get; }
public GameContext Context { get; }
public IBehaviorData Data => _data;
public Sensor(GameContext context, SensorData data, Entity entity, Gear item)
{
_data = data;
Entity = entity;
Item = item;
Context = context;
}
public void Initialize()
{
}
public void Update(float delta)
{
// var ship = Hardpoint.Ship.Ship.transform;
// var contacts =
// Physics.OverlapSphere(ship.position, _data.Range.Evaluate(Hardpoint)).Where(c=>c.attachedRigidbody?.GetComponent<Targetable>()!=null).Select(c=>c.attachedRigidbody.GetComponent<Targetable>());
// foreach (var contact in contacts)
// {
// var diff = (contact.transform.position - ship.position).Flatland();
// var angle = acos(dot(ship.forward.Flatland().normalized,
// diff.normalized)) / (float)PI;
// var sens = _data.Sensitivity.Evaluate(Hardpoint) *
// Hardpoint.Ship.HullData.VisibilityCurve.Evaluate(saturate(angle));
// var vis = contact.Visibility / diff.sqrMagnitude;
// if(vis > 1/sens)
// Hardpoint.Ship.Contacts[contact] = Time.time;
// }
//
// Hardpoint.Ship.VisibilitySources[this] = _data.Radiance.Evaluate(Hardpoint) / _data.RadianceMasking.Evaluate(Hardpoint);
// TODO: Handle Active Detection / Visibility From Reflected Radiance
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8bd975480c8d4206bd1831fd9f51529f
timeCreated: 1584292693

View file

@ -0,0 +1,48 @@
using MessagePack;
using Newtonsoft.Json;
using Unity.Mathematics;
using static Unity.Mathematics.math;
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class ShieldData : IBehaviorData
{
[InspectableField, JsonProperty("efficiency"), Key(0)]
public PerformanceStat Efficiency = new PerformanceStat();
[InspectableField, JsonProperty("shielding"), Key(1)]
public PerformanceStat Shielding = new PerformanceStat();
public IBehavior CreateInstance(GameContext context, Entity entity, Gear item)
{
return new Shield(context, this, entity, item);
}
}
public class Shield : IBehavior
{
public Entity Entity { get; }
public Gear Item { get; }
public GameContext Context { get; }
public IBehaviorData Data => _data;
private ShieldData _data;
public Shield(GameContext context, ShieldData data, Entity entity, Gear item)
{
Context = context;
_data = data;
Entity = entity;
Item = item;
// TODO: Detect hits on Ship, keep a list of callbacks that modify the hit by reference
}
public void Initialize()
{
}
public void Update(float delta)
{
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: dbb1419b4645402aad5a394b983a637f
timeCreated: 1586275939

View file

@ -0,0 +1,62 @@
using MessagePack;
using Newtonsoft.Json;
using Unity.Mathematics;
using static Unity.Mathematics.math;
[MessagePackObject, JsonObject(MemberSerialization.OptIn), EntityTypeRestriction(typeof(Ship))]
public class ThrusterData : IBehaviorData
{
[InspectableField, JsonProperty("thrust"), Key(0)]
public PerformanceStat Thrust = new PerformanceStat();
[InspectableField, JsonProperty("torque"), Key(1)]
public PerformanceStat Torque = new PerformanceStat();
[InspectableField, JsonProperty("visibility"), Key(2)]
public PerformanceStat Visibility = new PerformanceStat();
[InspectableField, JsonProperty("heat"), Key(3)]
public PerformanceStat Heat = new PerformanceStat();
public IBehavior CreateInstance(GameContext context, Entity entity, Gear item)
{
return new Thruster(context, this, entity, item);
}
}
public class Thruster : IAnalogBehavior
{
public Entity Entity { get; }
public Gear Item { get; }
public GameContext Context { get; }
public IBehaviorData Data => _data;
private ThrusterData _data;
private float _thrust;
public Thruster(GameContext context, ThrusterData data, Entity entity, Gear item)
{
Context = context;
_data = data;
Entity = entity;
Item = item;
}
public void SetAxis(float value)
{
_thrust = saturate(value);
}
public void Initialize()
{
}
public void Update(float delta)
{
((Ship) Entity).Velocity += _thrust * Context.Evaluate(_data.Thrust, Item, Entity) * delta;
Entity.AddHeat(_thrust * Context.Evaluate(_data.Heat, Item, Entity) * delta);
Entity.VisibilitySources[this] = _thrust * Context.Evaluate(_data.Visibility, Item, Entity);
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f46e0da62f8c40f69bba0b7bcff8662f
timeCreated: 1586267627

View file

@ -0,0 +1,59 @@
using MessagePack;
using Newtonsoft.Json;
using Unity.Mathematics;
using static Unity.Mathematics.math;
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class TurningData : IBehaviorData
{
[InspectableField, JsonProperty("torque"), Key(0)]
public PerformanceStat Torque = new PerformanceStat();
[InspectableField, JsonProperty("visibility"), Key(1)]
public PerformanceStat Visibility = new PerformanceStat();
[InspectableField, JsonProperty("heat"), Key(2)]
public PerformanceStat Heat = new PerformanceStat();
public IBehavior CreateInstance(GameContext context, Entity entity, Gear item)
{
return new Turning(context, this, entity, item);
}
}
public class Turning : IAnalogBehavior
{
public Entity Entity { get; }
public Gear Item { get; }
public GameContext Context { get; }
public IBehaviorData Data => _data;
private TurningData _data;
private float _turning;
public Turning(GameContext context, TurningData data, Entity entity, Gear item)
{
Context = context;
_data = data;
Entity = entity;
Item = item;
}
public void SetAxis(float value)
{
_turning = clamp(value, -1, 1);
}
public void Initialize()
{
}
public void Update(float delta)
{
Entity.Direction = mul(Entity.Direction, Unity.Mathematics.float2x2.Rotate(_turning * Context.Evaluate(_data.Torque, Item, Entity) * delta));
Entity.AddHeat(abs(_turning) * Context.Evaluate(_data.Heat, Item, Entity) * delta);
Entity.VisibilitySources[this] = abs(_turning) * Context.Evaluate(_data.Visibility, Item, Entity);
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 21343037bc4842669c20b0606b03a622
timeCreated: 1586270198

View file

@ -0,0 +1,43 @@
using MessagePack;
using Newtonsoft.Json;
using Unity.Mathematics;
using static Unity.Mathematics.math;
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class VelocityConversionData : IBehaviorData
{
[InspectableField, JsonProperty("traction"), Key(0)]
public PerformanceStat Traction = new PerformanceStat();
public IBehavior CreateInstance(GameContext context, Entity entity, Gear item)
{
return new VelocityConversion(context, this, entity, item);
}
}
public class VelocityConversion : IBehavior
{
public Entity Entity { get; }
public Gear Item { get; }
public GameContext Context { get; }
public IBehaviorData Data => _data;
private VelocityConversionData _data;
public VelocityConversion(GameContext context, VelocityConversionData data, Entity entity, Gear item)
{
Context = context;
_data = data;
Entity = entity;
Item = item;
}
public void Initialize()
{
}
public void Update(float delta)
{
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 38e5a766311c40aba86de1b72d2f410e
timeCreated: 1586422223

View file

@ -0,0 +1,43 @@
using MessagePack;
using Newtonsoft.Json;
using Unity.Mathematics;
using static Unity.Mathematics.math;
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class VelocityLimitData : IBehaviorData
{
[InspectableField, JsonProperty("topSpeed"), Key(0)]
public PerformanceStat TopSpeed = new PerformanceStat();
public IBehavior CreateInstance(GameContext context, Entity entity, Gear item)
{
return new VelocityLimit(context, this, entity, item);
}
}
public class VelocityLimit : IBehavior
{
public Entity Entity { get; }
public Gear Item { get; }
public GameContext Context { get; }
public IBehaviorData Data => _data;
private VelocityLimitData _data;
public VelocityLimit(GameContext context, VelocityLimitData data, Entity entity, Gear item)
{
Context = context;
_data = data;
Entity = entity;
Item = item;
}
public void Initialize()
{
}
public void Update(float delta)
{
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 3e82fb4fadeb477ba6eec01f2d169f6e
timeCreated: 1586415720

View file

@ -0,0 +1,34 @@
using MessagePack;
using Newtonsoft.Json;
[Union(0, typeof(CannonData)),
Union(1, typeof(LauncherData))]
public abstract class WeaponData
{
[InspectableField, JsonProperty("damageType"), Key(0)]
public DamageType DamageType;
[InspectableField, JsonProperty("damage"), Key(1)]
public PerformanceStat Damage = new PerformanceStat();
[InspectableField, JsonProperty("range"), Key(2)]
public PerformanceStat Range = new PerformanceStat();
[InspectableField, JsonProperty("cooldown"), Key(3)]
public PerformanceStat Cooldown = new PerformanceStat();
[InspectableField, JsonProperty("heat"), Key(4)]
public PerformanceStat Heat = new PerformanceStat();
[InspectableField, JsonProperty("visibility"), Key(5)]
public PerformanceStat Visibility = new PerformanceStat();
[InspectableField, JsonProperty("visibilityDecay"), Key(6)]
public PerformanceStat VisibilityDecay = new PerformanceStat();
[InspectableField, JsonProperty("burstCount"), Key(7)]
public int BurstCount;
[InspectableField, JsonProperty("burstTime"), Key(8)]
public PerformanceStat BurstTime = new PerformanceStat();
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d87bbbe67d6d48cb8f0cca9611985c00
timeCreated: 1586295838