Behavior Canceling & Grouping
Behaviors are now grouped, behaviors within a group can cancel execution of the rest of the group
This commit is contained in:
parent
c24c155673
commit
fc94531566
35 changed files with 613 additions and 190 deletions
54
Assets/Scripts/ServerShared/Behaviors/ActivatedItemUsage.cs
Normal file
54
Assets/Scripts/ServerShared/Behaviors/ActivatedItemUsage.cs
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class ActivatedItemUsageData : BehaviorData
|
||||
{
|
||||
|
||||
public override IBehavior CreateInstance(GameContext context, Entity entity, Gear item)
|
||||
{
|
||||
return new ActivatedItemUsage(context, this, entity, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class ActivatedItemUsage : IActivatedBehavior
|
||||
{
|
||||
private ActivatedItemUsageData _data;
|
||||
|
||||
private Entity Entity { get; }
|
||||
private Gear Item { get; }
|
||||
private GameContext Context { get; }
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
public ActivatedItemUsage(GameContext context, ActivatedItemUsageData data, Entity entity, Gear item)
|
||||
{
|
||||
_data = data;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
Context = context;
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
}
|
||||
|
||||
public bool Activate()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public void Deactivate()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public bool Update(float delta)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Remove()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9965ed11abd4e8c48b7b2bd8ab6e44e8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -7,13 +7,13 @@ using Newtonsoft.Json;
|
|||
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class AfterburnerData : BehaviorData
|
||||
{
|
||||
[InspectableField, JsonProperty("thrust"), Key(0)]
|
||||
[InspectableField, JsonProperty("thrust"), Key(1)]
|
||||
public PerformanceStat ThrustModifier = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("speed"), Key(1)]
|
||||
[InspectableField, JsonProperty("speed"), Key(2)]
|
||||
public PerformanceStat SpeedModifier = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("torque"), Key(2)]
|
||||
[InspectableField, JsonProperty("torque"), Key(3)]
|
||||
public PerformanceStat TorqueModifier = new PerformanceStat();
|
||||
|
||||
public override IBehavior CreateInstance(GameContext context, Entity entity, Gear item)
|
||||
|
|
@ -27,6 +27,7 @@ public class Afterburner : IActivatedBehavior
|
|||
private List<Dictionary<IBehavior,float>> _modifiers = new List<Dictionary<IBehavior, float>>();
|
||||
private AfterburnerData _data;
|
||||
private Thruster _thruster;
|
||||
private int _thrustAxis;
|
||||
|
||||
public Entity Entity { get; }
|
||||
public Gear Item { get; }
|
||||
|
|
@ -45,21 +46,25 @@ public class Afterburner : IActivatedBehavior
|
|||
public void Initialize()
|
||||
{
|
||||
_thruster = Entity.GetBehaviors<Thruster>().FirstOrDefault();
|
||||
_thrustAxis = Entity.GetAxis<Thruster>();
|
||||
}
|
||||
|
||||
public void Update(float delta)
|
||||
public bool Update(float delta)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Activate()
|
||||
public bool Activate()
|
||||
{
|
||||
if (_thruster == null) return;
|
||||
if (_thruster == null) return false;
|
||||
|
||||
var thrustMod = ((ThrusterData) _thruster.Data).Thrust.GetScaleModifiers(Entity);
|
||||
thrustMod.Add(this,Context.Evaluate(_data.ThrustModifier,Item, Entity));
|
||||
_modifiers.Add(thrustMod);
|
||||
|
||||
Entity.AxisOverrides[_thruster] = 1;
|
||||
Entity.AxisOverrides[_thrustAxis] = 1;
|
||||
|
||||
return true;
|
||||
|
||||
// var speedMod = (Ship.Hull.ItemData as HullData).TopSpeed.GetScaleModifiers(Ship);
|
||||
// _modifiers.Add(speedMod);
|
||||
|
|
@ -72,11 +77,15 @@ public class Afterburner : IActivatedBehavior
|
|||
|
||||
public void Deactivate()
|
||||
{
|
||||
Entity.AxisOverrides.Remove(_thruster);
|
||||
Entity.AxisOverrides.Remove(_thrustAxis);
|
||||
foreach (var mod in _modifiers)
|
||||
{
|
||||
mod.Remove(this);
|
||||
}
|
||||
_modifiers.Clear();
|
||||
}
|
||||
|
||||
public void Remove()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -12,13 +12,14 @@ using static Unity.Mathematics.noise;
|
|||
public interface IBehavior
|
||||
{
|
||||
void Initialize();
|
||||
void Update(float delta);
|
||||
bool Update(float delta);
|
||||
void Remove();
|
||||
BehaviorData Data { get; }
|
||||
}
|
||||
|
||||
public interface IActivatedBehavior : IBehavior
|
||||
{
|
||||
void Activate();
|
||||
bool Activate();
|
||||
void Deactivate();
|
||||
}
|
||||
|
||||
|
|
@ -68,8 +69,8 @@ public abstract class PersistentBehaviorData
|
|||
JsonConverter(typeof(JsonKnownTypesConverter<BehaviorData>)), JsonObject(MemberSerialization.OptIn)]
|
||||
public abstract class BehaviorData
|
||||
{
|
||||
// [InspectableField, JsonProperty("index"), Key(0)]
|
||||
// public int Index;
|
||||
[InspectableField, JsonProperty("group"), Key(0)]
|
||||
public int Group;
|
||||
|
||||
public abstract IBehavior CreateInstance(GameContext context, Entity entity, Gear item);
|
||||
}
|
||||
|
|
@ -7,16 +7,16 @@ using Newtonsoft.Json;
|
|||
[Union(0, typeof(TowingControllerData))]
|
||||
public abstract class ControllerData : BehaviorData
|
||||
{
|
||||
[InspectableField, JsonProperty("thrustSensitivity"), Key(0)]
|
||||
[InspectableField, JsonProperty("thrustSensitivity"), Key(1)]
|
||||
public float ThrustSensitivity = 1;
|
||||
|
||||
[InspectableField, JsonProperty("thrustSpecificity"), Key(1)]
|
||||
[InspectableField, JsonProperty("thrustSpecificity"), Key(2)]
|
||||
public float ThrustSpecificity = 8;
|
||||
|
||||
[InspectableField, JsonProperty("turningSensitivity"), Key(2)]
|
||||
[InspectableField, JsonProperty("turningSensitivity"), Key(3)]
|
||||
public float TurningSensitivity = 1;
|
||||
|
||||
[InspectableField, JsonProperty("tangentSensitivity"), Key(3)]
|
||||
[InspectableField, JsonProperty("tangentSensitivity"), Key(4)]
|
||||
public float TangentSensitivity = 4;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,10 +10,10 @@ using Random = Unity.Mathematics.Random;
|
|||
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class FactoryData : BehaviorData
|
||||
{
|
||||
[InspectableField, JsonProperty("toolingTime"), Key(0)]
|
||||
[InspectableField, JsonProperty("toolingTime"), Key(1)]
|
||||
public PerformanceStat ToolingTime = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("automation"), Key(1)]
|
||||
[InspectableField, JsonProperty("automation"), Key(2)]
|
||||
public int AutomationPoints;
|
||||
|
||||
public override IBehavior CreateInstance(GameContext context, Entity entity, Gear item)
|
||||
|
|
@ -52,7 +52,7 @@ public class Factory : IBehavior, IPersistentBehavior//<Factory>
|
|||
{
|
||||
}
|
||||
|
||||
public void Update(float delta)
|
||||
public bool Update(float delta)
|
||||
{
|
||||
var blueprint = Context.Cache.Get<BlueprintData>(_blueprint);
|
||||
if (_retooling || _producing)
|
||||
|
|
@ -198,6 +198,8 @@ public class Factory : IBehavior, IPersistentBehavior//<Factory>
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public PersistentBehaviorData Store()
|
||||
|
|
@ -225,6 +227,10 @@ public class Factory : IBehavior, IPersistentBehavior//<Factory>
|
|||
_assignedPopulation = factoryPersistence.AssignedPopulation;
|
||||
_productionQuality = factoryPersistence.ProductionQuality;
|
||||
}
|
||||
|
||||
public void Remove()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
|
|
|
|||
95
Assets/Scripts/ServerShared/Behaviors/Hitscan.cs
Normal file
95
Assets/Scripts/ServerShared/Behaviors/Hitscan.cs
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class HitscanData : WeaponData
|
||||
{
|
||||
public override IBehavior CreateInstance(GameContext context, Entity entity, Gear item)
|
||||
{
|
||||
return new Hitscan(context, this, entity, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class Hitscan : IActivatedBehavior
|
||||
{
|
||||
private bool _firing;
|
||||
private float _cooldown; // normalized
|
||||
private HitscanData _data;
|
||||
private Entity Entity { get; }
|
||||
private Gear Item { get; }
|
||||
private GameContext Context { get; }
|
||||
private float _firingVisibility;
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
public Hitscan(GameContext context, HitscanData c, Entity entity, Gear item)
|
||||
{
|
||||
Context = context;
|
||||
_data = c;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
}
|
||||
|
||||
public bool Activate()
|
||||
{
|
||||
// Debug.Log("Activating ProjectileWeapon");
|
||||
// _firing = true;
|
||||
// Observable.EveryUpdate().TakeWhile(_ => _firing).Subscribe(_ =>
|
||||
// {
|
||||
// // Debug.Log($"Updating Observable {_cooldown}");
|
||||
// if (_cooldown < 0)
|
||||
// {
|
||||
// _cooldown = 1;
|
||||
// Fire(0);
|
||||
// if(_projectileWeapon.BurstCount>1)
|
||||
// Observable.Interval(TimeSpan.FromSeconds(_projectileWeapon.BurstTime.Evaluate(Hardpoint) / (_projectileWeapon.BurstCount-1))).Take(_projectileWeapon.BurstCount-1)
|
||||
// .Subscribe(l => Fire(l+1));
|
||||
// }
|
||||
// });
|
||||
return true;
|
||||
}
|
||||
|
||||
private void Fire(long b)
|
||||
{
|
||||
// _firingVisibility += _projectileWeapon.Visibility.Evaluate(Hardpoint);
|
||||
// Hardpoint.Temperature += _projectileWeapon.Heat.Evaluate(Hardpoint) / Hardpoint.HeatCapacity;
|
||||
// var inst = GameObject.Instantiate(_projectileWeapon.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 = _projectileWeapon.Range.Evaluate(Hardpoint) / _projectileWeapon.Velocity.Evaluate(Hardpoint);
|
||||
// bullet.Damage = _projectileWeapon.Damage.Evaluate(Hardpoint);
|
||||
// inst.position = Hardpoint.Proxy.position;
|
||||
// inst.rotation = Hardpoint.Proxy.rotation;
|
||||
// inst.GetComponent<Rigidbody>().velocity = _projectileWeapon.Velocity.Evaluate(Hardpoint) * Vector3.RotateTowards(-inst.forward, Hardpoint.Ship.Ship.Direction, _projectileWeapon.Deflection * Mathf.Deg2Rad, 1);
|
||||
// Hardpoint.Ship.Ship.AudioSource.PlayOneShot(_projectileWeapon.Sounds.RandomElement());
|
||||
// Debug.Log($"Firing bullet {b}");
|
||||
}
|
||||
|
||||
public void Deactivate()
|
||||
{
|
||||
_firing = false;
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
}
|
||||
|
||||
public bool Update(float delta)
|
||||
{
|
||||
_cooldown -= delta / Context.Evaluate(_data.Cooldown, Item, Entity);
|
||||
|
||||
_firingVisibility *= Context.Evaluate(_data.VisibilityDecay, Item, Entity);
|
||||
|
||||
if (_firingVisibility < 0.01f)
|
||||
{
|
||||
Entity.VisibilitySources.Remove(this);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Remove()
|
||||
{
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/ServerShared/Behaviors/Hitscan.cs.meta
Normal file
11
Assets/Scripts/ServerShared/Behaviors/Hitscan.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 215516570484dc343ab90cae7a8ec175
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
51
Assets/Scripts/ServerShared/Behaviors/ItemUsage.cs
Normal file
51
Assets/Scripts/ServerShared/Behaviors/ItemUsage.cs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
|
||||
using System;
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class ItemUsageData : BehaviorData
|
||||
{
|
||||
[InspectableDatabaseLink(typeof(SimpleCommodityData)), JsonProperty("item"), Key(1)]
|
||||
public Guid Item;
|
||||
|
||||
[InspectableField, JsonProperty("cooldown"), Key(2)]
|
||||
public PerformanceStat Cooldown = new PerformanceStat();
|
||||
|
||||
public override IBehavior CreateInstance(GameContext context, Entity entity, Gear item)
|
||||
{
|
||||
return new ItemUsage(context, this, entity, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class ItemUsage : IBehavior
|
||||
{
|
||||
private ItemUsageData _data;
|
||||
|
||||
private Entity Entity { get; }
|
||||
private Gear Item { get; }
|
||||
private GameContext Context { get; }
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
public ItemUsage(GameContext context, ItemUsageData data, Entity entity, Gear item)
|
||||
{
|
||||
_data = data;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
Context = context;
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
}
|
||||
|
||||
public bool Update(float delta)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Remove()
|
||||
{
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/ServerShared/Behaviors/ItemUsage.cs.meta
Normal file
11
Assets/Scripts/ServerShared/Behaviors/ItemUsage.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6204fd7e7e3950548bddf9738f8e5219
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -5,7 +5,7 @@ using Newtonsoft.Json;
|
|||
using Unity.Mathematics;
|
||||
|
||||
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class LauncherData : BehaviorData
|
||||
public class LauncherData : WeaponData
|
||||
{
|
||||
[InspectablePrefab, JsonProperty("missile"), Key(9)]
|
||||
public string MissilePrefab;
|
||||
|
|
@ -50,16 +50,20 @@ public class Launcher : IActivatedBehavior
|
|||
private float _cooldown; // normalized
|
||||
private bool _locked;
|
||||
|
||||
private LauncherData _launcher;
|
||||
public Entity Entity { get; }
|
||||
public Gear Item { get; }
|
||||
public GameContext Context { get; }
|
||||
private LauncherData _data;
|
||||
private Entity Entity { get; }
|
||||
private Gear Item { get; }
|
||||
private GameContext Context { get; }
|
||||
private float _firingVisibility;
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
public int Group => _data.Group;
|
||||
|
||||
public Launcher(GameContext context, LauncherData m, Entity entity, Gear item)
|
||||
{
|
||||
Context = context;
|
||||
_launcher = m;
|
||||
_data = m;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
// _audio = hp.Proxy.GetComponent<AudioSource>();
|
||||
|
|
@ -70,10 +74,11 @@ public class Launcher : IActivatedBehavior
|
|||
// _audio.volume = .5f;
|
||||
}
|
||||
|
||||
public void Activate()
|
||||
public bool Activate()
|
||||
{
|
||||
_locking = true;
|
||||
_lockingTimer = 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
private void Fire(long b)
|
||||
|
|
@ -124,8 +129,9 @@ public class Launcher : IActivatedBehavior
|
|||
{
|
||||
}
|
||||
|
||||
public void Update(float delta)
|
||||
public bool Update(float delta)
|
||||
{
|
||||
return true;
|
||||
// if (Ship.Target == null)
|
||||
// return;
|
||||
//
|
||||
|
|
@ -161,6 +167,8 @@ public class Launcher : IActivatedBehavior
|
|||
// _firingVisibility = 0;
|
||||
// }
|
||||
}
|
||||
|
||||
public BehaviorData Data => _launcher;
|
||||
|
||||
public void Remove()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -9,7 +9,7 @@ using static Unity.Mathematics.math;
|
|||
[MessagePackObject, JsonObject(MemberSerialization.OptIn), EntityTypeRestriction(HullType.Ship)]
|
||||
public class PatrolControllerData : ControllerData
|
||||
{
|
||||
[InspectableField, JsonProperty("targetDistance"), Key(4)]
|
||||
[InspectableField, JsonProperty("targetDistance"), Key(5)]
|
||||
public float TargetDistance = 10;
|
||||
|
||||
public override IBehavior CreateInstance(GameContext context, Entity entity, Gear item)
|
||||
|
|
@ -47,13 +47,15 @@ public class PatrolController : IBehavior, IController
|
|||
RandomTarget();
|
||||
}
|
||||
|
||||
public void Update(float delta)
|
||||
public bool Update(float delta)
|
||||
{
|
||||
_locomotion.Objective = _context.GetOrbitPosition(_targetOrbit);
|
||||
_locomotion.Update(delta);
|
||||
|
||||
if(length(_entity.Position - _locomotion.Objective) < _data.TargetDistance)
|
||||
RandomTarget();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void AssignTask(Guid task, List<SimplifiedZoneData> path)
|
||||
|
|
@ -66,4 +68,8 @@ public class PatrolController : IBehavior, IController
|
|||
var entities = _context.ZonePlanets[_entity.Zone];
|
||||
_targetOrbit = _context.Cache.Get<PlanetData>(entities[_context.Random.NextInt(entities.Length)]).Orbit;
|
||||
}
|
||||
|
||||
public void Remove()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,26 +24,32 @@ public class ProjectileWeaponData : WeaponData
|
|||
|
||||
public class ProjectileWeapon : IActivatedBehavior
|
||||
{
|
||||
private ProjectileWeaponData _data;
|
||||
private Entity Entity { get; }
|
||||
private Gear Item { get; }
|
||||
private GameContext Context { get; }
|
||||
private float _firingVisibility;
|
||||
private bool _firing;
|
||||
private float _cooldown; // normalized
|
||||
private ProjectileWeaponData _projectileWeapon;
|
||||
public Entity Entity { get; }
|
||||
public Gear Item { get; }
|
||||
public GameContext Context { get; }
|
||||
private float _firingVisibility;
|
||||
private float _burstCooldown;
|
||||
private float _burstCooldownTime;
|
||||
private int _burstRemaining;
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
public ProjectileWeapon(GameContext context, ProjectileWeaponData c, Entity entity, Gear item)
|
||||
{
|
||||
Context = context;
|
||||
_projectileWeapon = c;
|
||||
_data = c;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
}
|
||||
|
||||
public void Activate()
|
||||
public bool Activate()
|
||||
{
|
||||
_firing = true;
|
||||
return true;
|
||||
// Debug.Log("Activating ProjectileWeapon");
|
||||
// _firing = true;
|
||||
// Observable.EveryUpdate().TakeWhile(_ => _firing).Subscribe(_ =>
|
||||
// {
|
||||
// // Debug.Log($"Updating Observable {_cooldown}");
|
||||
|
|
@ -58,9 +64,11 @@ public class ProjectileWeapon : IActivatedBehavior
|
|||
// });
|
||||
}
|
||||
|
||||
private void Fire(long b)
|
||||
private void Fire()
|
||||
{
|
||||
// _firingVisibility += _projectileWeapon.Visibility.Evaluate(Hardpoint);
|
||||
_burstRemaining--;
|
||||
_firingVisibility += Context.Evaluate(_data.Visibility, Item, Entity);
|
||||
Entity.AddHeat(Context.Evaluate(_data.Heat, Item, Entity));
|
||||
// Hardpoint.Temperature += _projectileWeapon.Heat.Evaluate(Hardpoint) / Hardpoint.HeatCapacity;
|
||||
// var inst = GameObject.Instantiate(_projectileWeapon.BulletPrefab).transform;
|
||||
// Physics.IgnoreCollision(Hardpoint.Ship.Ship.GetComponent<Collider>(), inst.GetComponent<Collider>());
|
||||
|
|
@ -85,17 +93,38 @@ public class ProjectileWeapon : IActivatedBehavior
|
|||
{
|
||||
}
|
||||
|
||||
public void Update(float delta)
|
||||
public bool Update(float delta)
|
||||
{
|
||||
_cooldown -= delta / Context.Evaluate(_projectileWeapon.Cooldown, Item, Entity);
|
||||
_cooldown -= delta / Context.Evaluate(_data.Cooldown, Item, Entity);
|
||||
if (_cooldown < 0)
|
||||
{
|
||||
_cooldown = 1;
|
||||
_burstRemaining = _data.BurstCount;
|
||||
_burstCooldownTime = Context.Evaluate(_data.BurstTime, Item, Entity) / _data.BurstCount;
|
||||
_burstCooldown = -1;
|
||||
Fire();
|
||||
}
|
||||
|
||||
if (_burstRemaining > 0)
|
||||
{
|
||||
_burstCooldown -= delta / _burstCooldownTime;
|
||||
if (_burstCooldown < 0)
|
||||
{
|
||||
_burstCooldown = 1;
|
||||
Fire();
|
||||
}
|
||||
}
|
||||
|
||||
_firingVisibility *= Context.Evaluate(_projectileWeapon.VisibilityDecay, Item, Entity);
|
||||
_firingVisibility *= Context.Evaluate(_data.VisibilityDecay, Item, Entity);
|
||||
|
||||
if (_firingVisibility < 0.01f)
|
||||
{
|
||||
Entity.VisibilitySources.Remove(this);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Remove()
|
||||
{
|
||||
}
|
||||
|
||||
public BehaviorData Data => _projectileWeapon;
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@ using static Unity.Mathematics.math;
|
|||
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class RadiatorData : BehaviorData
|
||||
{
|
||||
[InspectableField, JsonProperty("emissivity"), Key(0)]
|
||||
[InspectableField, JsonProperty("emissivity"), Key(1)]
|
||||
public PerformanceStat Emissivity = new PerformanceStat();
|
||||
|
||||
public override IBehavior CreateInstance(GameContext context, Entity entity, Gear item)
|
||||
|
|
@ -37,10 +37,15 @@ public class Radiator : IBehavior
|
|||
{
|
||||
}
|
||||
|
||||
public void Update(float delta)
|
||||
public bool Update(float delta)
|
||||
{
|
||||
var rad = pow(Entity.Temperature, Context.GlobalData.HeatRadiationPower) * Context.GlobalData.HeatRadiationMultiplier;
|
||||
Entity.Temperature -= rad * delta;
|
||||
Entity.VisibilitySources[this] = rad;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Remove()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -4,19 +4,19 @@ using Newtonsoft.Json;
|
|||
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class ReactorData : BehaviorData
|
||||
{
|
||||
[InspectableField, JsonProperty("charge"), Key(0)]
|
||||
[InspectableField, JsonProperty("charge"), Key(1)]
|
||||
public PerformanceStat Charge = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("capacitance"), Key(1)]
|
||||
[InspectableField, JsonProperty("capacitance"), Key(2)]
|
||||
public PerformanceStat Capacitance = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("efficiency"), Key(2)]
|
||||
[InspectableField, JsonProperty("efficiency"), Key(3)]
|
||||
public PerformanceStat Efficiency = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("overload"), Key(3)]
|
||||
[InspectableField, JsonProperty("overload"), Key(4)]
|
||||
public PerformanceStat OverloadEfficiency = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("underload"), Key(4)]
|
||||
[InspectableField, JsonProperty("underload"), Key(5)]
|
||||
public PerformanceStat UnderloadRecovery = new PerformanceStat();
|
||||
|
||||
public override IBehavior CreateInstance(GameContext context, Entity entity, Gear item)
|
||||
|
|
@ -47,7 +47,7 @@ public class Reactor : IBehavior
|
|||
{
|
||||
}
|
||||
|
||||
public void Update(float delta)
|
||||
public bool Update(float delta)
|
||||
{
|
||||
var cap = Context.Evaluate(_data.Capacitance, Item, Entity);
|
||||
var charge = Context.Evaluate(_data.Charge, Item, Entity) * delta;
|
||||
|
|
@ -67,5 +67,10 @@ public class Reactor : IBehavior
|
|||
Entity.AddHeat( -Entity.Energy / Context.Evaluate(_data.OverloadEfficiency, Item, Entity));
|
||||
Entity.Energy = 0;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Remove()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@ using static Unity.Mathematics.math;
|
|||
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class ReflectorData : BehaviorData
|
||||
{
|
||||
[InspectableField, JsonProperty("crossSection"), Key(0)]
|
||||
[InspectableField, JsonProperty("crossSection"), Key(1)]
|
||||
public PerformanceStat CrossSection = new PerformanceStat();
|
||||
|
||||
// [InspectableAnimationCurve, JsonProperty("visibility"), Key(1)]
|
||||
|
|
@ -40,7 +40,12 @@ public class Reflector : IBehavior
|
|||
{
|
||||
}
|
||||
|
||||
public void Update(float delta)
|
||||
public bool Update(float delta)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Remove()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -5,16 +5,16 @@ using Newtonsoft.Json;
|
|||
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class SensorData : BehaviorData
|
||||
{
|
||||
[InspectableField, JsonProperty("radiance"), Key(0)]
|
||||
[InspectableField, JsonProperty("radiance"), Key(1)]
|
||||
public PerformanceStat Radiance = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("masking"), Key(1)]
|
||||
[InspectableField, JsonProperty("masking"), Key(2)]
|
||||
public PerformanceStat RadianceMasking = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("sensitivity"), Key(2)]
|
||||
[InspectableField, JsonProperty("sensitivity"), Key(3)]
|
||||
public PerformanceStat Sensitivity = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("range"), Key(3)]
|
||||
[InspectableField, JsonProperty("range"), Key(4)]
|
||||
public PerformanceStat Range = new PerformanceStat();
|
||||
|
||||
public override IBehavior CreateInstance(GameContext context, Entity entity, Gear item)
|
||||
|
|
@ -27,9 +27,9 @@ public class Sensor : IBehavior
|
|||
{
|
||||
private SensorData _data;
|
||||
|
||||
public Entity Entity { get; }
|
||||
public Gear Item { get; }
|
||||
public GameContext Context { get; }
|
||||
private Entity Entity { get; }
|
||||
private Gear Item { get; }
|
||||
private GameContext Context { get; }
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
|
|
@ -45,8 +45,9 @@ public class Sensor : IBehavior
|
|||
{
|
||||
}
|
||||
|
||||
public void Update(float delta)
|
||||
public bool Update(float delta)
|
||||
{
|
||||
return true;
|
||||
// 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>());
|
||||
|
|
@ -65,4 +66,8 @@ public class Sensor : IBehavior
|
|||
// Hardpoint.Ship.VisibilitySources[this] = _data.Radiance.Evaluate(Hardpoint) / _data.RadianceMasking.Evaluate(Hardpoint);
|
||||
// TODO: Handle Active Detection / Visibility From Reflected Radiance
|
||||
}
|
||||
|
||||
public void Remove()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -6,10 +6,10 @@ using static Unity.Mathematics.math;
|
|||
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class ShieldData : BehaviorData
|
||||
{
|
||||
[InspectableField, JsonProperty("efficiency"), Key(0)]
|
||||
[InspectableField, JsonProperty("efficiency"), Key(1)]
|
||||
public PerformanceStat Efficiency = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("shielding"), Key(1)]
|
||||
[InspectableField, JsonProperty("shielding"), Key(2)]
|
||||
public PerformanceStat Shielding = new PerformanceStat();
|
||||
|
||||
public override IBehavior CreateInstance(GameContext context, Entity entity, Gear item)
|
||||
|
|
@ -42,7 +42,12 @@ public class Shield : IBehavior
|
|||
{
|
||||
}
|
||||
|
||||
public void Update(float delta)
|
||||
public bool Update(float delta)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Remove()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -6,13 +6,13 @@ using static Unity.Mathematics.math;
|
|||
[MessagePackObject, JsonObject(MemberSerialization.OptIn), EntityTypeRestriction(HullType.Ship)]
|
||||
public class ThrusterData : BehaviorData
|
||||
{
|
||||
[InspectableField, JsonProperty("thrust"), Key(0)]
|
||||
[InspectableField, JsonProperty("thrust"), Key(1)]
|
||||
public PerformanceStat Thrust = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("visibility"), Key(1)]
|
||||
[InspectableField, JsonProperty("visibility"), Key(2)]
|
||||
public PerformanceStat Visibility = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("heat"), Key(2)]
|
||||
[InspectableField, JsonProperty("heat"), Key(3)]
|
||||
public PerformanceStat Heat = new PerformanceStat();
|
||||
|
||||
public override IBehavior CreateInstance(GameContext context, Entity entity, Gear item)
|
||||
|
|
@ -52,11 +52,16 @@ public class Thruster : IAnalogBehavior
|
|||
{
|
||||
}
|
||||
|
||||
public void Update(float delta)
|
||||
public bool Update(float delta)
|
||||
{
|
||||
Thrust = Context.Evaluate(_data.Thrust, Item, Entity);
|
||||
Entity.Velocity += Entity.Direction * _input * Thrust / Entity.Mass * delta;
|
||||
Entity.AddHeat(_input * Context.Evaluate(_data.Heat, Item, Entity) * delta);
|
||||
Entity.VisibilitySources[this] = _input * Context.Evaluate(_data.Visibility, Item, Entity);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Remove()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -48,7 +48,7 @@ public class TowingController : IBehavior, IPersistentBehavior, IController
|
|||
_velocityMatch = new VelocityMatch(_context, _entity, _data);
|
||||
}
|
||||
|
||||
public void Update(float delta)
|
||||
public bool Update(float delta)
|
||||
{
|
||||
if (_path.Any())
|
||||
{
|
||||
|
|
@ -119,6 +119,7 @@ public class TowingController : IBehavior, IPersistentBehavior, IController
|
|||
_velocityMatch.Update(delta);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public PersistentBehaviorData Store()
|
||||
|
|
@ -148,6 +149,10 @@ public class TowingController : IBehavior, IPersistentBehavior, IController
|
|||
{
|
||||
_locomotion.Objective = _context.WormholePosition(_entity.Zone, _path[0].ZoneID);
|
||||
}
|
||||
|
||||
public void Remove()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class TowingControllerPersistence : PersistentBehaviorData
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@ using static Unity.Mathematics.math;
|
|||
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class TurningData : BehaviorData
|
||||
{
|
||||
[InspectableField, JsonProperty("torque"), Key(0)]
|
||||
[InspectableField, JsonProperty("torque"), Key(1)]
|
||||
public PerformanceStat Torque = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("visibility"), Key(1)]
|
||||
[InspectableField, JsonProperty("visibility"), Key(2)]
|
||||
public PerformanceStat Visibility = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("heat"), Key(2)]
|
||||
[InspectableField, JsonProperty("heat"), Key(3)]
|
||||
public PerformanceStat Heat = new PerformanceStat();
|
||||
|
||||
public override IBehavior CreateInstance(GameContext context, Entity entity, Gear item)
|
||||
|
|
@ -52,11 +52,16 @@ public class Turning : IAnalogBehavior
|
|||
{
|
||||
}
|
||||
|
||||
public void Update(float delta)
|
||||
public bool Update(float delta)
|
||||
{
|
||||
Torque = Context.Evaluate(_data.Torque, Item, Entity);
|
||||
Entity.Direction = mul(Entity.Direction, Unity.Mathematics.float2x2.Rotate(_input * Torque / Entity.Mass * delta));
|
||||
Entity.AddHeat(abs(_input) * Context.Evaluate(_data.Heat, Item, Entity) * delta);
|
||||
Entity.VisibilitySources[this] = abs(_input) * Context.Evaluate(_data.Visibility, Item, Entity);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Remove()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@ using static Unity.Mathematics.math;
|
|||
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class VelocityConversionData : BehaviorData
|
||||
{
|
||||
[InspectableField, JsonProperty("traction"), Key(0)]
|
||||
[InspectableField, JsonProperty("traction"), Key(1)]
|
||||
public PerformanceStat Traction = new PerformanceStat();
|
||||
|
||||
public override IBehavior CreateInstance(GameContext context, Entity entity, Gear item)
|
||||
|
|
@ -37,7 +37,12 @@ public class VelocityConversion : IBehavior
|
|||
{
|
||||
}
|
||||
|
||||
public void Update(float delta)
|
||||
public bool Update(float delta)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Remove()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@ using static Unity.Mathematics.math;
|
|||
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class VelocityLimitData : BehaviorData
|
||||
{
|
||||
[InspectableField, JsonProperty("topSpeed"), Key(0)]
|
||||
[InspectableField, JsonProperty("topSpeed"), Key(1)]
|
||||
public PerformanceStat TopSpeed = new PerformanceStat();
|
||||
|
||||
public override IBehavior CreateInstance(GameContext context, Entity entity, Gear item)
|
||||
|
|
@ -40,10 +40,15 @@ public class VelocityLimit : IBehavior
|
|||
{
|
||||
}
|
||||
|
||||
public void Update(float delta)
|
||||
public bool Update(float delta)
|
||||
{
|
||||
Limit = Context.Evaluate(_data.TopSpeed, Item, Entity);
|
||||
if (length(Entity.Velocity) > Limit)
|
||||
Entity.Velocity = normalize(Entity.Velocity) * Limit;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Remove()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -5,30 +5,30 @@ using Newtonsoft.Json;
|
|||
Union(1, typeof(LauncherData))]
|
||||
public abstract class WeaponData : BehaviorData
|
||||
{
|
||||
[InspectableField, JsonProperty("damageType"), Key(0)]
|
||||
[InspectableField, JsonProperty("damageType"), Key(1)]
|
||||
public DamageType DamageType;
|
||||
|
||||
[InspectableField, JsonProperty("damage"), Key(1)]
|
||||
[InspectableField, JsonProperty("damage"), Key(2)]
|
||||
public PerformanceStat Damage = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("range"), Key(2)]
|
||||
[InspectableField, JsonProperty("range"), Key(3)]
|
||||
public PerformanceStat Range = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("cooldown"), Key(3)]
|
||||
[InspectableField, JsonProperty("cooldown"), Key(4)]
|
||||
public PerformanceStat Cooldown = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("heat"), Key(4)]
|
||||
[InspectableField, JsonProperty("heat"), Key(5)]
|
||||
public PerformanceStat Heat = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("visibility"), Key(5)]
|
||||
[InspectableField, JsonProperty("visibility"), Key(6)]
|
||||
public PerformanceStat Visibility = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("visibilityDecay"), Key(6)]
|
||||
[InspectableField, JsonProperty("visibilityDecay"), Key(7)]
|
||||
public PerformanceStat VisibilityDecay = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("burstCount"), Key(7)]
|
||||
[InspectableField, JsonProperty("burstCount"), Key(8)]
|
||||
public int BurstCount;
|
||||
|
||||
[InspectableField, JsonProperty("burstTime"), Key(8)]
|
||||
[InspectableField, JsonProperty("burstTime"), Key(9)]
|
||||
public PerformanceStat BurstTime = new PerformanceStat();
|
||||
}
|
||||
Loading…
Reference in a new issue