Hellfire
Targeting Target locking Crosshairs Improved HUD schematic feedback Equipment Heat Damage Equipment Disabling
This commit is contained in:
parent
871c978301
commit
fddd485262
100 changed files with 10091 additions and 7885 deletions
|
|
@ -15,7 +15,7 @@ using static Unity.Mathematics.noise;
|
|||
|
||||
public interface IBehavior
|
||||
{
|
||||
bool Update(float delta);
|
||||
bool Execute(float delta);
|
||||
BehaviorData Data { get; }
|
||||
}
|
||||
|
||||
|
|
@ -42,7 +42,7 @@ public interface IInitializableBehavior
|
|||
|
||||
public interface IAlwaysUpdatedBehavior
|
||||
{
|
||||
void AlwaysUpdate(float delta);
|
||||
void Update(float delta);
|
||||
}
|
||||
|
||||
public interface IProgressBehavior
|
||||
|
|
@ -118,6 +118,7 @@ public abstract class PersistentBehaviorData
|
|||
Union(32, typeof(CockpitData)),
|
||||
Union(33, typeof(HeatsinkData)),
|
||||
Union(34, typeof(TurretControllerData)),
|
||||
Union(35, typeof(TargetLockData)),
|
||||
JsonConverter(typeof(JsonKnownTypesConverter<BehaviorData>)), JsonObject(MemberSerialization.OptIn)]
|
||||
public abstract class BehaviorData
|
||||
{
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ public class Capacitor : IBehavior
|
|||
Item = item;
|
||||
}
|
||||
|
||||
public bool Update(float delta)
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
Capacity = Context.Evaluate(_data.Capacity, Item.EquippableItem, Entity);
|
||||
Efficiency = Context.Evaluate(_data.Efficiency, Item.EquippableItem, Entity);
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ public class Cockpit : IBehavior
|
|||
Heatstroke = 0;
|
||||
}
|
||||
|
||||
public bool Update(float delta)
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
if (Item.Temperature > Context.GameplaySettings.HeatstrokeTemperature)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ public class ConstantWeapon : IBehavior, IAlwaysUpdatedBehavior
|
|||
Item = item;
|
||||
}
|
||||
|
||||
public bool Update(float delta)
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
if (!_firing)
|
||||
{
|
||||
|
|
@ -51,7 +51,7 @@ public class ConstantWeapon : IBehavior, IAlwaysUpdatedBehavior
|
|||
return true;
|
||||
}
|
||||
|
||||
public void AlwaysUpdate(float delta)
|
||||
public void Update(float delta)
|
||||
{
|
||||
// Update executes after AlwaysUpdate,
|
||||
// so if the stop flag didn't get disabled previous frame,
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ public abstract class ControllerBase<T> : IBehavior, IController<T>, IInitializa
|
|||
Moving = false;
|
||||
}
|
||||
|
||||
public bool Update(float delta)
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
if (Available)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ public class Cooldown : IBehavior, IAlwaysUpdatedBehavior, IProgressBehavior
|
|||
Context = context;
|
||||
}
|
||||
|
||||
public bool Update(float delta)
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
if (_cooldown < 0)
|
||||
{
|
||||
|
|
@ -54,7 +54,7 @@ public class Cooldown : IBehavior, IAlwaysUpdatedBehavior, IProgressBehavior
|
|||
|
||||
}
|
||||
|
||||
public void AlwaysUpdate(float delta)
|
||||
public void Update(float delta)
|
||||
{
|
||||
_cooldown -= delta / Context.Evaluate(_data.Cooldown, Item.EquippableItem, Entity);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ public class EnergyDraw : IBehavior
|
|||
Context = context;
|
||||
}
|
||||
|
||||
public bool Update(float delta)
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
Entity.Energy -= Context.Evaluate(_data.Draw, Item.EquippableItem, Entity) * (_data.PerSecond ? delta : 1);
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ public class Factory : IBehavior//, IPersistentBehavior, IPopulationAssignment
|
|||
Item = item;
|
||||
}
|
||||
|
||||
public bool Update(float delta)
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
// ToolingTime = Context.Evaluate(_data.ToolingTime, Item, Entity);
|
||||
// var blueprint = Context.ItemData.Get<BlueprintData>(_blueprint);
|
||||
|
|
|
|||
|
|
@ -24,11 +24,7 @@ public class HaulingControllerData : ControllerData
|
|||
|
||||
public class HaulingController : ControllerBase<HaulingTask>, IBehavior, IPersistentBehavior
|
||||
{
|
||||
public BehaviorData Data => _data;
|
||||
private HaulingControllerData _data;
|
||||
|
||||
private ItemManager ItemManager { get; }
|
||||
private Entity Entity { get; }
|
||||
private EquippedItem Item { get; }
|
||||
|
||||
private bool _taskStarted;
|
||||
|
|
@ -39,13 +35,11 @@ public class HaulingController : ControllerBase<HaulingTask>, IBehavior, IPersis
|
|||
|
||||
public HaulingController(ItemManager itemManager, HaulingControllerData data, Entity entity, EquippedItem item) : base(itemManager, data, entity)
|
||||
{
|
||||
ItemManager = itemManager;
|
||||
_data = data;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
}
|
||||
|
||||
public new bool Update(float delta)
|
||||
public new bool Execute(float delta)
|
||||
{
|
||||
if (Task != null)
|
||||
{
|
||||
|
|
@ -56,7 +50,7 @@ public class HaulingController : ControllerBase<HaulingTask>, IBehavior, IPersis
|
|||
_taskStarted = true;
|
||||
}
|
||||
}
|
||||
return base.Update(delta);
|
||||
return base.Execute(delta);
|
||||
}
|
||||
|
||||
// void OnOriginZoneArrival()
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ public class Heat : IBehavior
|
|||
Context = context;
|
||||
}
|
||||
|
||||
public bool Update(float delta)
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
Item.AddHeat(Context.Evaluate(_data.Heat, Item.EquippableItem, Entity) * (_data.PerSecond ? delta : 1));
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ public class Heatsink : IBehavior
|
|||
Item = item;
|
||||
}
|
||||
|
||||
public bool Update(float delta)
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ public class Hitscan : IBehavior
|
|||
Item = item;
|
||||
}
|
||||
|
||||
public bool Update(float delta)
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
// TODO: Implement hitscan weapons!
|
||||
Range = Context.Evaluate(_data.Range, Item.EquippableItem, Entity);
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ public class ItemUsage : IBehavior
|
|||
Context = context;
|
||||
}
|
||||
|
||||
public bool Update(float delta)
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
var cargo = Entity.FindItemInCargo(_data.Item);
|
||||
if (cargo == null) return false;
|
||||
|
|
|
|||
|
|
@ -21,143 +21,17 @@ public class LauncherData : InstantWeaponData
|
|||
[InspectableField, JsonProperty("thrust"), Key(12)]
|
||||
public PerformanceStat Thrust = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("lockAngle"), Key(13)]
|
||||
public float LockAngle;
|
||||
|
||||
[InspectableField, JsonProperty("frequency"), Key(14)]
|
||||
[InspectableField, JsonProperty("frequency"), Key(13)]
|
||||
public float DodgeFrequency;
|
||||
|
||||
[InspectableField, JsonProperty("launchSpeed"), Key(15)]
|
||||
[InspectableField, JsonProperty("launchSpeed"), Key(14)]
|
||||
public PerformanceStat LaunchSpeed = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("missileSpeed"), Key(16)]
|
||||
[InspectableField, JsonProperty("missileSpeed"), Key(15)]
|
||||
public PerformanceStat MissileSpeed = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("lockOnTime"), Key(17)]
|
||||
public PerformanceStat LockOnTime = new PerformanceStat();
|
||||
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
{
|
||||
return new InstantWeapon(context, this, entity, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class Launcher : IBehavior, IAlwaysUpdatedBehavior
|
||||
{
|
||||
private bool _locking;
|
||||
private float _lockingTimer;
|
||||
private float _cooldown; // normalized
|
||||
private bool _locked;
|
||||
|
||||
private LauncherData _data;
|
||||
private Entity Entity { get; }
|
||||
private EquippedItem Item { get; }
|
||||
private ItemManager Context { get; }
|
||||
private float _firingVisibility;
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
public Launcher(ItemManager context, LauncherData m, Entity entity, EquippedItem item)
|
||||
{
|
||||
Context = context;
|
||||
_data = 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 bool Activate()
|
||||
{
|
||||
_locking = true;
|
||||
_lockingTimer = 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
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 bool Update(float delta)
|
||||
{
|
||||
// _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}");
|
||||
return true;
|
||||
}
|
||||
|
||||
public void AlwaysUpdate(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;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
|
@ -22,7 +22,6 @@ public class MiningControllerData : ControllerData
|
|||
|
||||
public class MiningController : ControllerBase<Mining>, IBehavior, IPersistentBehavior, IInitializableBehavior
|
||||
{
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
private MiningControllerData _data;
|
||||
private EquippedItem Item { get; }
|
||||
|
|
@ -44,7 +43,7 @@ public class MiningController : ControllerBase<Mining>, IBehavior, IPersistentBe
|
|||
base.Initialize();
|
||||
}
|
||||
|
||||
public new bool Update(float delta)
|
||||
public new bool Execute(float delta)
|
||||
{
|
||||
// if (Task != null)
|
||||
// {
|
||||
|
|
@ -88,7 +87,7 @@ public class MiningController : ControllerBase<Mining>, IBehavior, IPersistentBe
|
|||
// }
|
||||
// }
|
||||
// }
|
||||
return base.Update(delta);
|
||||
return base.Execute(delta);
|
||||
}
|
||||
|
||||
// private void OnArriveHome()
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ public class MiningTool : IBehavior
|
|||
Context = context;
|
||||
}
|
||||
|
||||
public bool Update(float delta)
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
Range = Context.Evaluate(_data.Range, Item.EquippableItem, Entity);
|
||||
var asteroidTransform = Entity.Zone.GetAsteroidTransform(AsteroidBelt, Asteroid);
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ public class PatrolController : IBehavior, IInitializableBehavior
|
|||
RandomTarget();
|
||||
}
|
||||
|
||||
public bool Update(float delta)
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
_locomotion.Objective = Entity.Zone.GetOrbitPosition(_targetOrbit);
|
||||
_locomotion.Update(delta);
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ public class Radiance : IBehavior
|
|||
Context = context;
|
||||
}
|
||||
|
||||
public bool Update(float delta)
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
// TODO: Light system!
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ public class Radiator : IBehavior
|
|||
Item = item;
|
||||
}
|
||||
|
||||
public bool Update(float delta)
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
Emissivity = Context.Evaluate(_data.Emissivity, Item.EquippableItem, Entity);
|
||||
var rad = pow(Item.Temperature, Context.GameplaySettings.HeatRadiationExponent) * Context.GameplaySettings.HeatRadiationMultiplier * Emissivity;
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ public class Reactor : IBehavior, IOrderedBehavior
|
|||
});
|
||||
}
|
||||
|
||||
public bool Update(float delta)
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
var charge = Context.Evaluate(_data.Charge, Item.EquippableItem, Entity) * delta;
|
||||
var efficiency = Context.Evaluate(_data.Efficiency, Item.EquippableItem, Entity);
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ public class Reflector : IBehavior
|
|||
Item = item;
|
||||
}
|
||||
|
||||
public bool Update(float delta)
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
// TODO: Light system!
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ public class ResourceScanner : IBehavior, IAlwaysUpdatedBehavior
|
|||
Context = context;
|
||||
}
|
||||
|
||||
public bool Update(float delta)
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
var planetData = Context.ItemData.Get<BodyData>(ScanTarget);
|
||||
if (planetData != null)
|
||||
|
|
@ -103,7 +103,7 @@ public class ResourceScanner : IBehavior, IAlwaysUpdatedBehavior
|
|||
return false;
|
||||
}
|
||||
|
||||
public void AlwaysUpdate(float delta)
|
||||
public void Update(float delta)
|
||||
{
|
||||
Range = Context.Evaluate(_data.Range, Item.EquippableItem, Entity);
|
||||
MinimumDensity = Context.Evaluate(_data.MinimumDensity, Item.EquippableItem, Entity);
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ public class Sensor : IBehavior
|
|||
Context = context;
|
||||
}
|
||||
|
||||
public bool Update(float delta)
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
// TODO: Handle Active Detection / Visibility From Reflected Radiance
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ public class Shield : IBehavior
|
|||
// TODO: Detect hits on Ship, keep a list of callbacks that modify the hit by reference
|
||||
}
|
||||
|
||||
public bool Update(float delta)
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ public class StatModifier : IBehavior, IInitializableBehavior, IDisposableBehavi
|
|||
}
|
||||
}
|
||||
|
||||
public bool Update(float delta)
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
foreach (var stat in _stats)
|
||||
(_data.Type == StatModifierType.Constant
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ public class SurveyControllerData : ControllerData
|
|||
public class SurveyController : ControllerBase<Survey>, IBehavior, IPersistentBehavior, IInitializableBehavior
|
||||
{
|
||||
private EquippedItem Item { get; }
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
private SurveyControllerData _data;
|
||||
private bool _taskStarted;
|
||||
|
|
@ -46,7 +45,7 @@ public class SurveyController : ControllerBase<Survey>, IBehavior, IPersistentBe
|
|||
base.Initialize();
|
||||
}
|
||||
|
||||
public new bool Update(float delta)
|
||||
public new bool Execute(float delta)
|
||||
{
|
||||
// var corporation = _context.ItemData.Get<Corporation>(_entity.Corporation);
|
||||
// if (surveyTask != null)
|
||||
|
|
@ -103,7 +102,7 @@ public class SurveyController : ControllerBase<Survey>, IBehavior, IPersistentBe
|
|||
// }
|
||||
// }
|
||||
// }
|
||||
return base.Update(delta);
|
||||
return base.Execute(delta);
|
||||
}
|
||||
|
||||
private void NextPlanet()
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ public class Switch : IBehavior
|
|||
Context = context;
|
||||
}
|
||||
|
||||
public bool Update(float delta)
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
return Activated;
|
||||
}
|
||||
|
|
|
|||
87
Assets/Scripts/ServerShared/Behaviors/TargetLock.cs
Normal file
87
Assets/Scripts/ServerShared/Behaviors/TargetLock.cs
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
/* 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.Collections.Generic;
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
[MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(-11), RuntimeInspectable]
|
||||
public class TargetLockData : BehaviorData
|
||||
{
|
||||
[InspectableField, JsonProperty("speed"), Key(1), RuntimeInspectable]
|
||||
public PerformanceStat Speed = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("sensorImpact"), Key(2), RuntimeInspectable]
|
||||
public PerformanceStat SensorImpact = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("threshold"), Key(3), RuntimeInspectable]
|
||||
public PerformanceStat Threshold = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("directionImpact"), Key(4), RuntimeInspectable]
|
||||
public PerformanceStat DirectionImpact = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("decay"), Key(5), RuntimeInspectable]
|
||||
public PerformanceStat Decay = new PerformanceStat();
|
||||
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
{
|
||||
return new TargetLock(context, this, entity, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class TargetLock : IBehavior, IAlwaysUpdatedBehavior
|
||||
{
|
||||
private TargetLockData _data;
|
||||
|
||||
public Entity Entity { get; }
|
||||
public EquippedItem Item { get; }
|
||||
public ItemManager Context { get; }
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
public float Lock { get; private set; }
|
||||
|
||||
public float Speed { get; private set; }
|
||||
public float SensorImpact { get; private set; }
|
||||
public float Threshold { get; private set; }
|
||||
public float DirectionImpact { get; private set; }
|
||||
public float Decay { get; private set; }
|
||||
|
||||
public TargetLock(ItemManager context, TargetLockData data, Entity entity, EquippedItem item)
|
||||
{
|
||||
Context = context;
|
||||
_data = data;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
}
|
||||
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
// TODO: Hook into sensory systems to influence lock speed
|
||||
return Lock > .99f;
|
||||
}
|
||||
|
||||
public void Update(float delta)
|
||||
{
|
||||
if (Entity.Target.Value != null)
|
||||
{
|
||||
Speed = Context.Evaluate(_data.Speed, Item.EquippableItem, Entity);
|
||||
SensorImpact = Context.Evaluate(_data.SensorImpact, Item.EquippableItem, Entity);
|
||||
Threshold = Context.Evaluate(_data.Threshold, Item.EquippableItem, Entity);
|
||||
DirectionImpact = Context.Evaluate(_data.DirectionImpact, Item.EquippableItem, Entity);
|
||||
Decay = Context.Evaluate(_data.Decay, Item.EquippableItem, Entity);
|
||||
|
||||
var degrees = acos(dot(normalize(Entity.Target.Value.Position - Entity.Position), normalize(Entity.LookDirection))) * 57.2958f;
|
||||
if (degrees < Threshold)
|
||||
{
|
||||
var lerp = 1 - unlerp(0, 90, degrees);
|
||||
Lock = saturate(Lock + pow(lerp, DirectionImpact) * delta * Speed);
|
||||
return;
|
||||
}
|
||||
}
|
||||
Lock = saturate(Lock - Decay * delta);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/ServerShared/Behaviors/TargetLock.cs.meta
Normal file
11
Assets/Scripts/ServerShared/Behaviors/TargetLock.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7d1880b94a9e9f74e9c13be8d5fd8dee
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -42,7 +42,7 @@ public class Thermotoggle : IBehavior
|
|||
TargetTemperature = data.TargetTemperature;
|
||||
}
|
||||
|
||||
public bool Update(float delta)
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
return Item.Temperature < TargetTemperature ^ _data.HighPass;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ public class Thruster : IAnalogBehavior
|
|||
Torque = -dot(toCenter, float2(1, 0).Rotate(item.EquippableItem.Rotation));
|
||||
}
|
||||
|
||||
public bool Update(float delta)
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
Thrust = Context.Evaluate(_data.Thrust, Item.EquippableItem, Entity);
|
||||
Entity.Velocity -= Entity.Direction.Rotate(Item.EquippableItem.Rotation) * _input * Thrust / Entity.Mass * delta;
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ public class TowingControllerData : ControllerData
|
|||
|
||||
public class TowingController : ControllerBase<StationTowing>, IBehavior, IPersistentBehavior
|
||||
{
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
private TowingControllerData _data;
|
||||
private EquippedItem Item { get; }
|
||||
|
|
@ -34,7 +33,7 @@ public class TowingController : ControllerBase<StationTowing>, IBehavior, IPersi
|
|||
Item = item;
|
||||
}
|
||||
|
||||
public new bool Update(float delta)
|
||||
public new bool Execute(float delta)
|
||||
{
|
||||
if (Task != null)
|
||||
{
|
||||
|
|
@ -44,7 +43,7 @@ public class TowingController : ControllerBase<StationTowing>, IBehavior, IPersi
|
|||
_taskStarted = true;
|
||||
}
|
||||
}
|
||||
return base.Update(delta);
|
||||
return base.Execute(delta);
|
||||
}
|
||||
|
||||
// void OnZoneArrival()
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ public class Trigger : IBehavior
|
|||
{
|
||||
}
|
||||
|
||||
public bool Update(float delta)
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
if (_pulled)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ public class Turning : IAnalogBehavior
|
|||
{
|
||||
}
|
||||
|
||||
public bool Update(float delta)
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
Torque = Context.Evaluate(_data.Torque, Item.EquippableItem, Entity);
|
||||
Entity.Direction = mul(Entity.Direction, Unity.Mathematics.float2x2.Rotate(_input * Torque / Entity.Mass * delta));
|
||||
|
|
|
|||
|
|
@ -66,11 +66,11 @@ public class TurretController : IBehavior
|
|||
}
|
||||
}
|
||||
|
||||
public bool Update(float delta)
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
if (EquippedEntity.Target != null)
|
||||
if (EquippedEntity.Target.Value != null)
|
||||
{
|
||||
var diff = EquippedEntity.Target.Position - EquippedEntity.Position;
|
||||
var diff = EquippedEntity.Target.Value.Position - EquippedEntity.Position;
|
||||
EquippedEntity.LookDirection = normalize(diff);
|
||||
var dist = length(diff);
|
||||
|
||||
|
|
@ -86,7 +86,7 @@ public class TurretController : IBehavior
|
|||
}
|
||||
else
|
||||
{
|
||||
EquippedEntity.Target = EquippedEntity.Zone.Entities.FirstOrDefault(e => e is Ship);
|
||||
EquippedEntity.Target.Value = EquippedEntity.Zone.Entities.FirstOrDefault(e => e is Ship);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ public class VelocityConversion : IBehavior
|
|||
{
|
||||
}
|
||||
|
||||
public bool Update(float delta)
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ public class VelocityLimit : IBehavior
|
|||
{
|
||||
}
|
||||
|
||||
public bool Update(float delta)
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
Limit = Context.Evaluate(_data.TopSpeed, Item.EquippableItem, Entity);
|
||||
if (length(Entity.Velocity) > Limit)
|
||||
|
|
|
|||
|
|
@ -42,13 +42,13 @@ public class Visibility : IBehavior, IAlwaysUpdatedBehavior
|
|||
Context = context;
|
||||
}
|
||||
|
||||
public bool Update(float delta)
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
Entity.VisibilitySources[this] = Context.Evaluate(_data.Visibility, Item.EquippableItem, Entity);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void AlwaysUpdate(float delta)
|
||||
public void Update(float delta)
|
||||
{
|
||||
// TODO: Time independent decay?
|
||||
if(Entity.VisibilitySources.ContainsKey(this))
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ public class WanderControllerData : ControllerData
|
|||
public class WanderController : ControllerBase<WanderTask>, IBehavior
|
||||
{
|
||||
public WanderTarget WanderTarget;
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
private WanderControllerData _data;
|
||||
private EquippedItem Item { get; }
|
||||
|
|
@ -40,7 +39,7 @@ public class WanderController : ControllerBase<WanderTask>, IBehavior
|
|||
Item = item;
|
||||
}
|
||||
|
||||
public new bool Update(float delta)
|
||||
public new bool Execute(float delta)
|
||||
{
|
||||
if (!Moving && _dockTime < 0)
|
||||
{
|
||||
|
|
@ -48,7 +47,7 @@ public class WanderController : ControllerBase<WanderTask>, IBehavior
|
|||
}
|
||||
|
||||
_dockTime -= delta;
|
||||
return base.Update(delta);
|
||||
return base.Execute(delta);
|
||||
}
|
||||
|
||||
private void NextTarget()
|
||||
|
|
|
|||
|
|
@ -65,53 +65,29 @@ public class InstantWeapon : IBehavior, IAlwaysUpdatedBehavior
|
|||
Item = item;
|
||||
}
|
||||
|
||||
// private void Fire()
|
||||
// {
|
||||
// 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 bool Update(float delta)
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
_burstCount = _data.BurstCount;
|
||||
_burstTime = Context.Evaluate(_data.BurstTime, Item.EquippableItem, Entity) / _burstCount;
|
||||
if (_burstTime < .01f)
|
||||
{
|
||||
for(int i=0; i<_data.BurstCount; i++)
|
||||
OnFire?.Invoke();
|
||||
}
|
||||
else
|
||||
{
|
||||
_burstCount = _data.BurstCount;
|
||||
Fire();
|
||||
}
|
||||
_burstTimer = 0;
|
||||
Fire(delta);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void Fire()
|
||||
private void Fire(float delta)
|
||||
{
|
||||
_burstCount--;
|
||||
_burstTimer = _burstTime;
|
||||
OnFire?.Invoke();
|
||||
}
|
||||
|
||||
public void AlwaysUpdate(float delta)
|
||||
{
|
||||
if(_burstCount > 0)
|
||||
_burstTimer -= delta;
|
||||
while (_burstTimer < 0 && _burstCount > 0)
|
||||
{
|
||||
_burstTimer -= delta;
|
||||
if(_burstTimer < 0)
|
||||
Fire();
|
||||
_burstCount--;
|
||||
_burstTimer += _burstTime;
|
||||
OnFire?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
public void Update(float delta)
|
||||
{
|
||||
if(_burstCount > 0)
|
||||
Fire(delta);
|
||||
}
|
||||
}
|
||||
|
|
@ -38,7 +38,7 @@ public abstract class Entity
|
|||
|
||||
public Entity Parent;
|
||||
public List<Entity> Children = new List<Entity>();
|
||||
public Entity Target;
|
||||
public ReactiveProperty<Entity> Target = new ReactiveProperty<Entity>((Entity)null);
|
||||
|
||||
public float3 LookDirection;
|
||||
|
||||
|
|
@ -74,6 +74,11 @@ public abstract class Entity
|
|||
public Subject<(int2 pos, float damage)> ArmorDamage = new Subject<(int2, float)>();
|
||||
public Subject<(EquippedItem item, float damage)> ItemDamage = new Subject<(EquippedItem, float)>();
|
||||
public Subject<float> HullDamage = new Subject<float>();
|
||||
|
||||
public UniRx.IObservable<EquippedItem> ItemDestroyed;
|
||||
public UniRx.IObservable<int2> HullArmorDepleted;
|
||||
public UniRx.IObservable<HardpointData> HardpointArmorDepleted;
|
||||
|
||||
|
||||
public bool Active
|
||||
{
|
||||
|
|
@ -106,6 +111,10 @@ public abstract class Entity
|
|||
TriggerGroups = new List<EquippedItem>[itemManager.GameplaySettings.TriggerGroupCount];
|
||||
for(int i=0; i<itemManager.GameplaySettings.TriggerGroupCount; i++)
|
||||
TriggerGroups[i] = new List<EquippedItem>();
|
||||
|
||||
ItemDestroyed = ItemDamage.Where(x => x.item.EquippableItem.Durability < .01f).Select(x=>x.item);
|
||||
HullArmorDepleted = ArmorDamage.Where(x => Armor[x.pos.x, x.pos.y] < .01f).Select(x => x.pos);
|
||||
HardpointArmorDepleted = HardpointDamage.Where(x => HardpointArmor[x.hardpoint] < .01f).Select(x => x.hardpoint);
|
||||
}
|
||||
|
||||
private void MapEntity()
|
||||
|
|
@ -523,7 +532,7 @@ public abstract class Entity
|
|||
heatTransfer += (Temperature[v.x, v.y - 1] - temp) * Conductivity[v.x, v.y].z * Conductivity[v.x, v.y - 1].x;
|
||||
|
||||
if (v.y < hullData.Shape.Height - 1)
|
||||
heatTransfer += (Temperature[v.x, v.y + 1] - temp) * Conductivity[v.x, v.y].x * Conductivity[v.x, v.y + 1].z;;
|
||||
heatTransfer += (Temperature[v.x, v.y + 1] - temp) * Conductivity[v.x, v.y].x * Conductivity[v.x, v.y + 1].z;
|
||||
|
||||
newTemp[v.x, v.y] = Temperature[v.x, v.y] + heatTransfer * min(ItemManager.GameplaySettings.HeatConductionMultiplier * delta,1) / ThermalMass[v.x,v.y];
|
||||
|
||||
|
|
@ -617,6 +626,8 @@ public class EquippedItem
|
|||
|
||||
public int SortPosition;
|
||||
|
||||
public bool Online => EquippableItem.Durability > .01f && Temperature > _data.MinimumTemperature && Temperature < _data.MaximumTemperature;
|
||||
|
||||
public float Temperature
|
||||
{
|
||||
get
|
||||
|
|
@ -673,23 +684,27 @@ public class EquippedItem
|
|||
|
||||
public void Update(float delta)
|
||||
{
|
||||
// if(Temperature < _data.MinimumTemperature || Temperature > _data.MaximumTemperature)
|
||||
// {
|
||||
// EquippableItem.Durability -= delta;
|
||||
// return;
|
||||
// }
|
||||
|
||||
foreach (var behavior in Behaviors.Where(b => b is IAlwaysUpdatedBehavior).Cast<IAlwaysUpdatedBehavior>())
|
||||
behavior.AlwaysUpdate(delta);
|
||||
|
||||
foreach (var group in BehaviorGroups)
|
||||
|
||||
if (Temperature < _data.MinimumTemperature || Temperature > _data.MaximumTemperature)
|
||||
{
|
||||
foreach (var behavior in group.Behaviors)
|
||||
EquippableItem.Durability -= delta;
|
||||
}
|
||||
|
||||
foreach (var behavior in Behaviors.Where(b => b is IAlwaysUpdatedBehavior).Cast<IAlwaysUpdatedBehavior>())
|
||||
behavior.Update(delta);
|
||||
|
||||
if (Online)
|
||||
{
|
||||
foreach (var group in BehaviorGroups)
|
||||
{
|
||||
if (!behavior.Update(delta))
|
||||
break;
|
||||
foreach (var behavior in group.Behaviors)
|
||||
{
|
||||
if (!behavior.Execute(delta))
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
34
Assets/Scripts/ServerShared/Noise1D.cs
Normal file
34
Assets/Scripts/ServerShared/Noise1D.cs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
public static class Noise1D
|
||||
{
|
||||
private const float HASHSCALE = 0.1031f;
|
||||
|
||||
static float hash(float p)
|
||||
{
|
||||
float3 p3 = frac(float3(p) * HASHSCALE);
|
||||
p3 += dot(p3, p3.yzx + 19.19f);
|
||||
return frac((p3.x + p3.y) * p3.z);
|
||||
}
|
||||
|
||||
static float fade(float t) { return t * t * t * (t * (6f* t - 15f) + 10f); }
|
||||
|
||||
static float grad(float hash, float p)
|
||||
{
|
||||
int i = (int)(1e4 * hash);
|
||||
return (i & 1) == 0 ? p : -p;
|
||||
}
|
||||
|
||||
public static float noise(float p)
|
||||
{
|
||||
float pi = floor(p), pf = p - pi, w = fade(pf);
|
||||
return lerp(grad(hash(pi), pf), grad(hash(pi + 1.0f), pf - 1.0f), w) * 2.0f;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/ServerShared/Noise1D.cs.meta
Normal file
11
Assets/Scripts/ServerShared/Noise1D.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 622b46440effa29418055a226c3db195
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -104,4 +104,7 @@ public class GameplaySettings
|
|||
public float HeatstrokeExponent = 2;
|
||||
public float HeatstrokeRecoverySpeed = .2f;
|
||||
public float HeatstrokeControlLimit = .75f;
|
||||
public float LockIndicatorNoiseAmplitude = 50f;
|
||||
public ExponentialLerp LockIndicatorFrequency;
|
||||
public ExponentialLerp LockSpinSpeed;
|
||||
}
|
||||
|
|
@ -62,7 +62,7 @@ public class Ship : Entity
|
|||
foreach (var thruster in _reverseThrusters) thruster.Axis += -MovementDirection.y;
|
||||
|
||||
var deltaRot = dot(normalize(LookDirection.xz), normalize(Direction).Rotate(ItemRotation.Clockwise));
|
||||
if (abs(deltaRot) < .01) deltaRot = 0;
|
||||
if (abs(deltaRot) < .0001) deltaRot = 0;
|
||||
deltaRot = pow(abs(deltaRot), .5f) * sign(deltaRot);
|
||||
|
||||
foreach (var thruster in _clockwiseThrusters) thruster.Axis += deltaRot;
|
||||
|
|
|
|||
Loading…
Reference in a new issue