Database Support
Refactored almost everything, but most importantly we now integrate with RethinkDB for game data.
This commit is contained in:
parent
5ffeb55214
commit
0b46d5ee39
839 changed files with 77349 additions and 112660 deletions
79
Assets/Scripts/ServerShared/ItemBehaviors/Afterburner.cs
Normal file
79
Assets/Scripts/ServerShared/ItemBehaviors/Afterburner.cs
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
|
||||
using System.Collections.Generic;
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
[InspectableField]
|
||||
[MessagePackObject]
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
public class AfterburnerBehaviorData : IItemBehaviorData
|
||||
{
|
||||
[InspectableField] [JsonProperty("thrust")] [Key(0)]
|
||||
public PerformanceStat ThrustModifier;
|
||||
|
||||
[InspectableField] [JsonProperty("speed")] [Key(1)]
|
||||
public PerformanceStat SpeedModifier;
|
||||
|
||||
[InspectableField] [JsonProperty("torque")] [Key(2)]
|
||||
public PerformanceStat TorqueModifier;
|
||||
|
||||
public IItemBehavior CreateInstance(GameContext context, Ship ship, Gear item)
|
||||
{
|
||||
return new AfterburnerBehavior(context, this, ship, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class AfterburnerBehavior : IActivatedItemBehavior
|
||||
{
|
||||
private List<Dictionary<IItemBehavior,float>> _modifiers = new List<Dictionary<IItemBehavior, float>>();
|
||||
private AfterburnerBehaviorData _data;
|
||||
|
||||
public Ship Ship { get; }
|
||||
public Gear Item { get; }
|
||||
public GameContext Context { get; }
|
||||
|
||||
public IItemBehaviorData Data => _data;
|
||||
|
||||
public AfterburnerBehavior(GameContext context, AfterburnerBehaviorData data, Ship ship, Gear item)
|
||||
{
|
||||
Context = context;
|
||||
_data = data;
|
||||
Ship = ship;
|
||||
Item = item;
|
||||
}
|
||||
|
||||
public void Update(float delta)
|
||||
{
|
||||
}
|
||||
|
||||
public void FixedUpdate(float delta)
|
||||
{
|
||||
}
|
||||
|
||||
public void Activate()
|
||||
{
|
||||
var thrustMod = Ship.GetEquipped<ThrusterData>().Thrust.GetScaleModifiers(Ship);
|
||||
_modifiers.Add(thrustMod);
|
||||
thrustMod.Add(this,Context.Evaluate(_data.ThrustModifier,Item, Ship));
|
||||
|
||||
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));
|
||||
|
||||
Ship.ForceThrust = true;
|
||||
}
|
||||
|
||||
public void Deactivate()
|
||||
{
|
||||
Ship.ForceThrust = false;
|
||||
foreach (var mod in _modifiers)
|
||||
{
|
||||
mod.Remove(this);
|
||||
}
|
||||
_modifiers.Clear();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 967ca96c9f90416887db9a6a0341f58c
|
||||
timeCreated: 1584292755
|
||||
40
Assets/Scripts/ServerShared/ItemBehaviors/Behaviors.cs
Normal file
40
Assets/Scripts/ServerShared/ItemBehaviors/Behaviors.cs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
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 IItemBehavior
|
||||
{
|
||||
void Update(float delta);
|
||||
void FixedUpdate(float delta);
|
||||
Ship Ship { get; }
|
||||
Gear Item { get; }
|
||||
GameContext Context { get; }
|
||||
IItemBehaviorData Data { get; }
|
||||
}
|
||||
|
||||
public interface IActivatedItemBehavior : IItemBehavior
|
||||
{
|
||||
void Activate();
|
||||
void Deactivate();
|
||||
}
|
||||
|
||||
[InspectableField]
|
||||
[Union(0, typeof(CannonBehaviorData))]
|
||||
[Union(1, typeof(LauncherBehaviorData))]
|
||||
[Union(2, typeof(ReactorBehaviorData))]
|
||||
// [Union(3, typeof(PlusUltraBehaviorData))]
|
||||
[Union(4, typeof(AfterburnerBehaviorData))]
|
||||
[Union(5, typeof(SensorBehaviorData))]
|
||||
[JsonConverter(typeof(JsonKnownTypesConverter<IItemBehaviorData>))]
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
public interface IItemBehaviorData
|
||||
{
|
||||
IItemBehavior CreateInstance(GameContext context, Ship ship, Gear item);
|
||||
}
|
||||
11
Assets/Scripts/ServerShared/ItemBehaviors/Behaviors.cs.meta
Normal file
11
Assets/Scripts/ServerShared/ItemBehaviors/Behaviors.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c15c37d98e3dc844aafd0dedc16ce0ae
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
132
Assets/Scripts/ServerShared/ItemBehaviors/Cannon.cs
Normal file
132
Assets/Scripts/ServerShared/ItemBehaviors/Cannon.cs
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
[InspectableField]
|
||||
[MessagePackObject]
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
public class CannonBehaviorData : IItemBehaviorData
|
||||
{
|
||||
[InspectablePrefab] [JsonProperty("bullet")] [Key(0)]
|
||||
public string BulletPrefab;
|
||||
|
||||
[InspectableField] [JsonProperty("damageType")] [Key(1)]
|
||||
public DamageType DamageType;
|
||||
|
||||
[InspectableField] [JsonProperty("burstCount")] [Key(2)]
|
||||
public int BurstCount;
|
||||
|
||||
[InspectableField] [JsonProperty("burstTime")] [Key(3)]
|
||||
public PerformanceStat BurstTime;
|
||||
|
||||
[InspectableField] [JsonProperty("bulletRange")] [Key(4)]
|
||||
public PerformanceStat Range;
|
||||
|
||||
[InspectableField] [JsonProperty("spread")] [Key(5)]
|
||||
public PerformanceStat Spread;
|
||||
|
||||
[InspectableField] [JsonProperty("bulletInherit")] [Key(6)]
|
||||
public float Inherit;
|
||||
|
||||
[InspectableField] [JsonProperty("deflection")] [Key(7)]
|
||||
public float Deflection;
|
||||
|
||||
[InspectableField] [JsonProperty("visibility")] [Key(8)]
|
||||
public PerformanceStat Visibility;
|
||||
|
||||
[InspectableField] [JsonProperty("visibilityDecay")] [Key(9)]
|
||||
public PerformanceStat VisibilityDecay;
|
||||
|
||||
[InspectableField] [JsonProperty("bulletVelocity")] [Key(10)]
|
||||
public PerformanceStat Velocity;
|
||||
|
||||
[InspectableField] [JsonProperty("cooldown")] [Key(11)]
|
||||
public PerformanceStat Cooldown;
|
||||
|
||||
[InspectableField] [JsonProperty("damage")] [Key(12)]
|
||||
public PerformanceStat Damage;
|
||||
|
||||
[InspectableField] [JsonProperty("heat")] [Key(13)]
|
||||
public PerformanceStat Heat;
|
||||
|
||||
public IItemBehavior CreateInstance(GameContext context, Ship ship, Gear item)
|
||||
{
|
||||
return new CannonBehavior(context, this, ship, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class CannonBehavior : IActivatedItemBehavior
|
||||
{
|
||||
private bool _firing;
|
||||
private float _cooldown; // normalized
|
||||
private CannonBehaviorData _cannon;
|
||||
public Ship Ship { get; }
|
||||
public Gear Item { get; }
|
||||
public GameContext Context { get; }
|
||||
private float _firingVisibility;
|
||||
|
||||
public CannonBehavior(GameContext context, CannonBehaviorData c, Ship ship, Gear item)
|
||||
{
|
||||
Context = context;
|
||||
_cannon = c;
|
||||
Ship = ship;
|
||||
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 Update(float delta)
|
||||
{
|
||||
_cooldown -= delta / Context.Evaluate(_cannon.Cooldown, Item, Ship);
|
||||
|
||||
if (_firingVisibility < 0.01f)
|
||||
{
|
||||
Ship.VisibilitySources.Remove(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void FixedUpdate(float delta)
|
||||
{
|
||||
_firingVisibility *= Context.Evaluate(_cannon.VisibilityDecay, Item, Ship);
|
||||
}
|
||||
|
||||
public IItemBehaviorData Data => _cannon;
|
||||
}
|
||||
3
Assets/Scripts/ServerShared/ItemBehaviors/Cannon.cs.meta
Normal file
3
Assets/Scripts/ServerShared/ItemBehaviors/Cannon.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 77453d9e23d44c69bb853e3092f2b18d
|
||||
timeCreated: 1584292789
|
||||
201
Assets/Scripts/ServerShared/ItemBehaviors/Launcher.cs
Normal file
201
Assets/Scripts/ServerShared/ItemBehaviors/Launcher.cs
Normal file
|
|
@ -0,0 +1,201 @@
|
|||
|
||||
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
using Unity.Mathematics;
|
||||
|
||||
[InspectableField]
|
||||
[MessagePackObject]
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
public class LauncherBehaviorData : IItemBehaviorData
|
||||
{
|
||||
// [MessagePackFormatter(typeof(UnityGameObjectFormatter))]
|
||||
// [Inspectable] [Key("missile")] public GameObject MissilePrefab;
|
||||
// [MessagePackFormatter(typeof(ClipListFormatter))]
|
||||
// [Inspectable] [Key("sounds")] public List<AudioClip> Sounds;
|
||||
// [MessagePackFormatter(typeof(UnityAudioClipFormatter))]
|
||||
// [Inspectable] [Key("beepSound")] public AudioClip BeepSound;
|
||||
// [Inspectable] [Key("beepCount")] public int Beeps;
|
||||
[InspectableField] [JsonProperty("damageType")] [Key(0)]
|
||||
public DamageType DamageType;
|
||||
|
||||
[InspectableField] [JsonProperty("burstCount")] [Key(1)]
|
||||
public int BurstCount;
|
||||
|
||||
[InspectableField] [JsonProperty("burstTime")] [Key(2)]
|
||||
public PerformanceStat BurstTime;
|
||||
|
||||
[InspectableField] [JsonProperty("range")] [Key(3)]
|
||||
public PerformanceStat Range;
|
||||
|
||||
[InspectableAnimationCurve] [JsonProperty("guidance")] [Key(4)]
|
||||
public float4[] GuidanceCurve;
|
||||
|
||||
[InspectableAnimationCurve] [JsonProperty("thrustCurve")] [Key(5)]
|
||||
public float4[] ThrustCurve;
|
||||
|
||||
[InspectableAnimationCurve] [JsonProperty("liftCurve")] [Key(6)]
|
||||
public float4[] LiftCurve;
|
||||
|
||||
[InspectableField] [JsonProperty("thrust")] [Key(7)]
|
||||
public PerformanceStat Thrust;
|
||||
|
||||
[InspectableField] [JsonProperty("deflection")] [Key(8)]
|
||||
public float Deflection;
|
||||
|
||||
[InspectableField] [JsonProperty("lockOnBuffer")] [Key(9)]
|
||||
public float LockOnDegrees;
|
||||
|
||||
[InspectableField] [JsonProperty("frequency")] [Key(10)]
|
||||
public float DodgeFrequency;
|
||||
|
||||
[InspectableField] [JsonProperty("visibility")] [Key(11)]
|
||||
public PerformanceStat Visibility;
|
||||
|
||||
[InspectableField] [JsonProperty("launchSpeed")] [Key(12)]
|
||||
public PerformanceStat LaunchSpeed;
|
||||
|
||||
[InspectableField] [JsonProperty("missileSpeed")] [Key(13)]
|
||||
public PerformanceStat MissileSpeed;
|
||||
|
||||
[InspectableField] [JsonProperty("cooldown")] [Key(14)]
|
||||
public PerformanceStat Cooldown;
|
||||
|
||||
[InspectableField] [JsonProperty("lockOnTime")] [Key(15)]
|
||||
public PerformanceStat LockOnTime;
|
||||
|
||||
[InspectableField] [JsonProperty("damage")] [Key(16)]
|
||||
public PerformanceStat Damage;
|
||||
|
||||
[InspectableField] [JsonProperty("heat")] [Key(17)]
|
||||
public PerformanceStat Heat;
|
||||
|
||||
public IItemBehavior CreateInstance(GameContext context, Ship ship, Gear item)
|
||||
{
|
||||
return new LauncherBehavior(context, this, ship, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class LauncherBehavior : IActivatedItemBehavior
|
||||
{
|
||||
private bool _locking;
|
||||
private float _lockingTimer;
|
||||
private float _cooldown; // normalized
|
||||
private bool _locked;
|
||||
|
||||
private LauncherBehaviorData _launcher;
|
||||
public Ship Ship { get; }
|
||||
public Gear Item { get; }
|
||||
public GameContext Context { get; }
|
||||
private float _firingVisibility;
|
||||
|
||||
public LauncherBehavior(GameContext context, LauncherBehaviorData m, Ship ship, Gear item)
|
||||
{
|
||||
Context = context;
|
||||
_launcher = m;
|
||||
Ship = ship;
|
||||
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 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 void FixedUpdate(float delta)
|
||||
{
|
||||
}
|
||||
|
||||
public IItemBehaviorData Data => _launcher;
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5fd0ce9fd7384ba5a40c2ba41ece74eb
|
||||
timeCreated: 1584292825
|
||||
73
Assets/Scripts/ServerShared/ItemBehaviors/Reactor.cs
Normal file
73
Assets/Scripts/ServerShared/ItemBehaviors/Reactor.cs
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
[MessagePackObject]
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
public class ReactorBehaviorData : IItemBehaviorData
|
||||
{
|
||||
[InspectableField] [JsonProperty("charge")] [Key(0)]
|
||||
public PerformanceStat Charge;
|
||||
|
||||
[InspectableField] [JsonProperty("capacitance")] [Key(1)]
|
||||
public PerformanceStat Capacitance;
|
||||
|
||||
[InspectableField] [JsonProperty("efficiency")] [Key(2)]
|
||||
public PerformanceStat Efficiency;
|
||||
|
||||
[InspectableField] [JsonProperty("overload")] [Key(3)]
|
||||
public PerformanceStat OverloadEfficiency;
|
||||
|
||||
[InspectableField] [JsonProperty("underload")] [Key(4)]
|
||||
public PerformanceStat UnderloadRecovery;
|
||||
|
||||
public IItemBehavior CreateInstance(GameContext context, Ship ship, Gear item)
|
||||
{
|
||||
return new ReactorBehavior(context, this, ship, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class ReactorBehavior : IItemBehavior
|
||||
{
|
||||
private ReactorBehaviorData _data;
|
||||
|
||||
public Ship Ship { get; }
|
||||
public Gear Item { get; }
|
||||
public GameContext Context { get; }
|
||||
|
||||
public IItemBehaviorData Data => _data;
|
||||
|
||||
public ReactorBehavior(GameContext context, ReactorBehaviorData data, Ship ship, Gear item)
|
||||
{
|
||||
Context = context;
|
||||
_data = data;
|
||||
Ship = ship;
|
||||
Item = item;
|
||||
}
|
||||
|
||||
public void FixedUpdate(float delta)
|
||||
{
|
||||
var cap = Context.Evaluate(_data.Capacitance, Item, Ship);
|
||||
var charge = Context.Evaluate(_data.Charge, Item, Ship) * delta;
|
||||
var efficiency = Context.Evaluate(_data.Efficiency, Item, Ship);
|
||||
|
||||
Ship.AddHeat(charge / efficiency);
|
||||
Ship.Charge += charge;
|
||||
|
||||
if (Ship.Charge > cap)
|
||||
{
|
||||
Ship.AddHeat(-(Ship.Charge - cap) / efficiency * (1 - 1 / Context.Evaluate(_data.UnderloadRecovery, Item, Ship)));
|
||||
Ship.Charge = cap;
|
||||
}
|
||||
|
||||
if (Ship.Charge < 0)
|
||||
{
|
||||
Ship.AddHeat( -Ship.Charge / Context.Evaluate(_data.OverloadEfficiency, Item, Ship));
|
||||
Ship.Charge = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void Update(float delta)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ca5f08285ca3403a8abe46001a16b6c4
|
||||
timeCreated: 1584292860
|
||||
70
Assets/Scripts/ServerShared/ItemBehaviors/Sensor.cs
Normal file
70
Assets/Scripts/ServerShared/ItemBehaviors/Sensor.cs
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
[InspectableField]
|
||||
[MessagePackObject]
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
public class SensorBehaviorData : IItemBehaviorData
|
||||
{
|
||||
[InspectableField] [JsonProperty("radiance")] [Key(0)]
|
||||
public PerformanceStat Radiance;
|
||||
|
||||
[InspectableField] [JsonProperty("masking")] [Key(1)]
|
||||
public PerformanceStat RadianceMasking;
|
||||
|
||||
[InspectableField] [JsonProperty("sensitivity")] [Key(2)]
|
||||
public PerformanceStat Sensitivity;
|
||||
|
||||
[InspectableField] [JsonProperty("range")] [Key(3)]
|
||||
public PerformanceStat Range;
|
||||
|
||||
public IItemBehavior CreateInstance(GameContext context, Ship ship, Gear item)
|
||||
{
|
||||
return new SensorBehavior(context, this, ship, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class SensorBehavior : IItemBehavior
|
||||
{
|
||||
private SensorBehaviorData _data;
|
||||
|
||||
public Ship Ship { get; }
|
||||
public Gear Item { get; }
|
||||
public GameContext Context { get; }
|
||||
|
||||
public IItemBehaviorData Data => _data;
|
||||
|
||||
public SensorBehavior(GameContext context, SensorBehaviorData data, Ship ship, Gear item)
|
||||
{
|
||||
_data = data;
|
||||
Ship = ship;
|
||||
Item = item;
|
||||
Context = context;
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
public void FixedUpdate(float delta)
|
||||
{
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/ServerShared/ItemBehaviors/Sensor.cs.meta
Normal file
3
Assets/Scripts/ServerShared/ItemBehaviors/Sensor.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8bd975480c8d4206bd1831fd9f51529f
|
||||
timeCreated: 1584292693
|
||||
Loading…
Reference in a new issue