Weapon Scripting Overhaul
Weapons are now monolithic behaviors Various new weapon behavior types implemented All weapons have optional magazine and reload mechanic Visibility now decays globally
This commit is contained in:
parent
48abee4847
commit
357f9db329
95 changed files with 2571 additions and 754 deletions
|
|
@ -8,13 +8,13 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
using float2 = Unity.Mathematics.float2;
|
||||
|
||||
public class VelocityMatch : AgentBehavior
|
||||
{
|
||||
public event Action OnMatch;
|
||||
public float2 TargetVelocity;
|
||||
private Thruster _thrust;
|
||||
private Turning _turning;
|
||||
private const float TargetThreshold = .1f;
|
||||
|
||||
private ItemManager _context;
|
||||
|
|
@ -23,7 +23,6 @@ public class VelocityMatch : AgentBehavior
|
|||
{
|
||||
_context = context;
|
||||
_thrust = Entity.GetBehavior<Thruster>();
|
||||
_turning = Entity.GetBehavior<Turning>();
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
|
|
@ -33,31 +32,32 @@ public class VelocityMatch : AgentBehavior
|
|||
|
||||
public override void Update(float delta)
|
||||
{
|
||||
if (_thrust != null && _turning != null)
|
||||
{
|
||||
var deltaV = TargetVelocity - Entity.Velocity;
|
||||
if(length(deltaV) < TargetThreshold)
|
||||
OnMatch?.Invoke();
|
||||
_turning.Axis = TurningInput(deltaV);
|
||||
_thrust.Axis = ThrustInput(deltaV);
|
||||
}
|
||||
// if (_thrust != null && _turning != null)
|
||||
// {
|
||||
// var deltaV = TargetVelocity - Entity.Velocity;
|
||||
// if(length(deltaV) < TargetThreshold)
|
||||
// OnMatch?.Invoke();
|
||||
// _turning.Axis = TurningInput(deltaV);
|
||||
// _thrust.Axis = ThrustInput(deltaV);
|
||||
// }
|
||||
}
|
||||
|
||||
public float2 MatchDistanceTime
|
||||
{
|
||||
get
|
||||
{
|
||||
var velocity = length(Entity.Velocity);
|
||||
var deltaV = TargetVelocity - Entity.Velocity;
|
||||
|
||||
var stoppingTime = length(deltaV) / (_thrust.Thrust / Entity.Mass);
|
||||
var stoppingDistance = stoppingTime * (velocity / 2);
|
||||
|
||||
var angleDiff = Entity.Direction.AngleDiff(deltaV);
|
||||
var turnaroundTime = angleDiff / (_turning.Torque / Entity.Mass);
|
||||
var turnaroundDistance = turnaroundTime * velocity;
|
||||
|
||||
return float2(stoppingDistance + turnaroundDistance, stoppingTime + turnaroundTime);
|
||||
// var velocity = length(Entity.Velocity);
|
||||
// var deltaV = TargetVelocity - Entity.Velocity;
|
||||
//
|
||||
// var stoppingTime = length(deltaV) / (_thrust.Thrust / Entity.Mass);
|
||||
// var stoppingDistance = stoppingTime * (velocity / 2);
|
||||
//
|
||||
// var angleDiff = Entity.Direction.AngleDiff(deltaV);
|
||||
// var turnaroundTime = angleDiff / (_turning.Torque / Entity.Mass);
|
||||
// var turnaroundDistance = turnaroundTime * velocity;
|
||||
//
|
||||
// return float2(stoppingDistance + turnaroundDistance, stoppingTime + turnaroundTime);
|
||||
return float2.zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -127,6 +127,23 @@ public class InspectableTypeAttribute : InspectableFieldAttribute
|
|||
[AttributeUsage(AttributeTargets.Field)]
|
||||
public class SimplePerformanceStatAttribute : Attribute { }
|
||||
|
||||
/// <summary>
|
||||
/// <para>Specify a tooltip for a field in the Inspector window.</para>
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)]
|
||||
public class TooltipAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>The tooltip text.</para>
|
||||
/// </summary>
|
||||
public readonly string tooltip;
|
||||
|
||||
/// <summary>
|
||||
/// <para>Specify a tooltip for a field.</para>
|
||||
/// </summary>
|
||||
/// <param name="tooltip">The tooltip text.</param>
|
||||
public TooltipAttribute(string tooltip) => this.tooltip = tooltip;
|
||||
}
|
||||
// public class CategoryAttribute : Attribute
|
||||
// {
|
||||
// public readonly Type Type;
|
||||
|
|
|
|||
32
Assets/Scripts/ServerShared/Behaviors/AutoWeapon.cs
Normal file
32
Assets/Scripts/ServerShared/Behaviors/AutoWeapon.cs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
|
||||
public class AutoWeaponData : InstantWeaponData
|
||||
{
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
{
|
||||
return new AutoWeapon(context, this, entity, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class AutoWeapon : InstantWeapon
|
||||
{
|
||||
|
||||
public AutoWeapon(ItemManager context, InstantWeaponData data, Entity entity, EquippedItem item) : base(context, data, entity, item)
|
||||
{
|
||||
}
|
||||
|
||||
public override bool Execute(float delta)
|
||||
{
|
||||
if(_firing && _burstRemaining == 0 && _cooldown < 0)
|
||||
Trigger();
|
||||
return base.Execute(delta);
|
||||
}
|
||||
}
|
||||
|
||||
3
Assets/Scripts/ServerShared/Behaviors/AutoWeapon.cs.meta
Normal file
3
Assets/Scripts/ServerShared/Behaviors/AutoWeapon.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9f709e48e6db48bb8214d07fc593f9bd
|
||||
timeCreated: 1611439063
|
||||
|
|
@ -19,11 +19,11 @@ public interface IBehavior
|
|||
BehaviorData Data { get; }
|
||||
}
|
||||
|
||||
// public interface IActivatedBehavior : IBehavior
|
||||
// {
|
||||
// bool Activate();
|
||||
// void Deactivate();
|
||||
// }
|
||||
public interface IActivatedBehavior : IBehavior
|
||||
{
|
||||
void Activate();
|
||||
void Deactivate();
|
||||
}
|
||||
|
||||
public interface IAnalogBehavior : IBehavior
|
||||
{
|
||||
|
|
@ -40,6 +40,11 @@ public interface IInitializableBehavior
|
|||
void Initialize();
|
||||
}
|
||||
|
||||
public interface IInteractiveBehavior
|
||||
{
|
||||
bool Exposed { get; }
|
||||
}
|
||||
|
||||
public interface IAlwaysUpdatedBehavior
|
||||
{
|
||||
void Update(float delta);
|
||||
|
|
@ -92,7 +97,7 @@ public abstract class PersistentBehaviorData
|
|||
Union(6, typeof(ReflectorData)),
|
||||
Union(7, typeof(ShieldData)),
|
||||
Union(8, typeof(ThrusterData)),
|
||||
Union(9, typeof(TurningData)),
|
||||
// Union(9, typeof(TurningData)),
|
||||
Union(10, typeof(VelocityConversionData)),
|
||||
Union(11, typeof(VelocityLimitData)),
|
||||
Union(12, typeof(FactoryData)),
|
||||
|
|
@ -100,7 +105,7 @@ public abstract class PersistentBehaviorData
|
|||
Union(14, typeof(TowingControllerData)),
|
||||
Union(15, typeof(CooldownData)),
|
||||
Union(16, typeof(HeatData)),
|
||||
Union(17, typeof(HitscanData)),
|
||||
// Union(17, typeof(HitscanData)),
|
||||
Union(18, typeof(ItemUsageData)),
|
||||
Union(19, typeof(RadianceData)),
|
||||
Union(20, typeof(SwitchData)),
|
||||
|
|
@ -118,7 +123,10 @@ public abstract class PersistentBehaviorData
|
|||
Union(32, typeof(CockpitData)),
|
||||
Union(33, typeof(HeatsinkData)),
|
||||
Union(34, typeof(TurretControllerData)),
|
||||
Union(35, typeof(TargetLockData)),
|
||||
Union(35, typeof(InstantWeaponData)),
|
||||
Union(36, typeof(ConstantWeaponData)),
|
||||
Union(37, typeof(ChargedWeaponData)),
|
||||
Union(38, typeof(AutoWeaponData)),
|
||||
JsonConverter(typeof(JsonKnownTypesConverter<BehaviorData>)), JsonObject(MemberSerialization.OptIn)]
|
||||
public abstract class BehaviorData
|
||||
{
|
||||
|
|
|
|||
95
Assets/Scripts/ServerShared/Behaviors/ChargedWeapon.cs
Normal file
95
Assets/Scripts/ServerShared/Behaviors/ChargedWeapon.cs
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
|
||||
public class ChargedWeaponData : InstantWeaponData
|
||||
{
|
||||
[InspectableField, JsonProperty("chargeTime"), Key(13), RuntimeInspectable]
|
||||
public PerformanceStat ChargeTime = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("chargeEnergy"), Key(14), RuntimeInspectable]
|
||||
public PerformanceStat ChargeEnergy = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("canFireEarly"), Key(15)]
|
||||
public bool CanFireEarly;
|
||||
|
||||
[InspectableField, JsonProperty("failureCharge"), Key(16)]
|
||||
public float FailureCharge;
|
||||
|
||||
[InspectableField, JsonProperty("failureDamage"), Key(17)]
|
||||
public float FailureDamage;
|
||||
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
{
|
||||
return new ChargedWeapon(context, this, entity, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class ChargedWeapon : InstantWeapon
|
||||
{
|
||||
private ChargedWeaponData _data;
|
||||
private bool _charging;
|
||||
private bool _charged;
|
||||
private float _charge;
|
||||
private float _progress;
|
||||
|
||||
public event Action OnCharged;
|
||||
public event Action OnFailed;
|
||||
|
||||
public override float Progress => saturate(_charging ? _charge : _cooldown);
|
||||
|
||||
public float Charge
|
||||
{
|
||||
get => _charge;
|
||||
}
|
||||
|
||||
public ChargedWeapon(ItemManager context, ChargedWeaponData data, Entity entity, EquippedItem item) : base(context, data, entity, item)
|
||||
{
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public override bool Execute(float delta)
|
||||
{
|
||||
if (_charging)
|
||||
{
|
||||
_charge += delta / Context.Evaluate(_data.ChargeTime, Item.EquippableItem, Entity);
|
||||
if (!_charged && _charge > 1)
|
||||
{
|
||||
_charged = true;
|
||||
OnCharged?.Invoke();
|
||||
}
|
||||
if (_charge > _data.FailureCharge)
|
||||
{
|
||||
_charging = false;
|
||||
_cooldown = 1;
|
||||
OnFailed?.Invoke();
|
||||
Item.EquippableItem.Durability -= _data.FailureDamage;
|
||||
}
|
||||
}
|
||||
return base.Execute(delta);
|
||||
}
|
||||
|
||||
public override void Activate()
|
||||
{
|
||||
if(_cooldown < 0)
|
||||
{
|
||||
_charging = true;
|
||||
_charged = false;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Deactivate()
|
||||
{
|
||||
if (_charging && (_data.CanFireEarly || _charge > 1))
|
||||
{
|
||||
Trigger();
|
||||
_charge = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 215516570484dc343ab90cae7a8ec175
|
||||
guid: 9dc2759ab65d73c4a8b831f4f23ef48a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
|
|
@ -5,67 +5,117 @@
|
|||
using System;
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class ConstantWeaponData : WeaponData
|
||||
{
|
||||
[InspectablePrefab, JsonProperty("ammoInterval"), Key(13)]
|
||||
public float AmmoInterval = 1;
|
||||
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
{
|
||||
return new ConstantWeapon(context, this, entity, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class ConstantWeapon : IBehavior, IAlwaysUpdatedBehavior
|
||||
public class ConstantWeapon : Weapon, IProgressBehavior
|
||||
{
|
||||
private ConstantWeaponData _data;
|
||||
private int _ammo = 1;
|
||||
private float _ammoInterval;
|
||||
private float _reload;
|
||||
private bool _reloading;
|
||||
|
||||
private Entity Entity { get; }
|
||||
private EquippedItem Item { get; }
|
||||
private ItemManager Context { get; }
|
||||
public override int Ammo
|
||||
{
|
||||
get => _ammo;
|
||||
}
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
public float Progress
|
||||
{
|
||||
get { return saturate(_reload); }
|
||||
}
|
||||
|
||||
public event Action OnReloadBegin;
|
||||
public event Action OnReloadComplete;
|
||||
public event Action OnStartFiring;
|
||||
public event Action OnStopFiring;
|
||||
|
||||
private bool _firing;
|
||||
private bool _stoppedFiring;
|
||||
|
||||
public ConstantWeapon(ItemManager context, ConstantWeaponData c, Entity entity, EquippedItem item)
|
||||
public ConstantWeapon(ItemManager context, ConstantWeaponData data, Entity entity, EquippedItem item) : base(context, data, entity, item)
|
||||
{
|
||||
Context = context;
|
||||
_data = c;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public bool Execute(float delta)
|
||||
public override bool Execute(float delta)
|
||||
{
|
||||
if (!_firing)
|
||||
if (_firing)
|
||||
{
|
||||
if (_data.AmmoType != Guid.Empty)
|
||||
{
|
||||
if (_reloading)
|
||||
{
|
||||
_reload -= delta / _data.ReloadTime;
|
||||
if (_reload < 0)
|
||||
{
|
||||
_reloading = false;
|
||||
OnReloadComplete?.Invoke();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
_ammoInterval -= delta / _data.AmmoInterval;
|
||||
if (_ammoInterval < 0)
|
||||
{
|
||||
_ammoInterval = 1;
|
||||
if (_data.MagazineSize > 1 && _ammo > 0) _ammo--;
|
||||
else
|
||||
{
|
||||
var cargo = Entity.FindItemInCargo(_data.AmmoType);
|
||||
if (cargo != null)
|
||||
{
|
||||
var item = cargo.ItemsOfType[_data.AmmoType][0];
|
||||
if (item is SimpleCommodity simpleCommodity)
|
||||
cargo.Remove(simpleCommodity, 1);
|
||||
|
||||
if(_data.MagazineSize > 1)
|
||||
{
|
||||
_reloading = true;
|
||||
_reload = 1;
|
||||
OnReloadBegin?.Invoke();
|
||||
|
||||
_firing = false;
|
||||
OnStopFiring?.Invoke();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Item.AddHeat(Context.Evaluate(_data.Heat, Item.EquippableItem, Entity) * delta);
|
||||
Entity.VisibilitySources[this] = Context.Evaluate(_data.Visibility, Item.EquippableItem, Entity);
|
||||
Entity.Energy -= Context.Evaluate(_data.Energy, Item.EquippableItem, Entity) * delta;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Activate()
|
||||
{
|
||||
if(!_reloading)
|
||||
{
|
||||
_firing = true;
|
||||
OnStartFiring?.Invoke();
|
||||
}
|
||||
|
||||
_stoppedFiring = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Update(float delta)
|
||||
public override void Deactivate()
|
||||
{
|
||||
// Update executes after AlwaysUpdate,
|
||||
// so if the stop flag didn't get disabled previous frame,
|
||||
// we know the weapon has stopped firing
|
||||
if (_firing)
|
||||
{
|
||||
if (_stoppedFiring)
|
||||
{
|
||||
_firing = false;
|
||||
_stoppedFiring = false;
|
||||
OnStopFiring?.Invoke();
|
||||
}
|
||||
else
|
||||
_stoppedFiring = true;
|
||||
_firing = false;
|
||||
OnStopFiring?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class HitscanData : WeaponData
|
||||
{
|
||||
[InspectableField, JsonProperty("perSecond"), Key(6)]
|
||||
public bool PerSecond;
|
||||
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
{
|
||||
return new Hitscan(context, this, entity, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class Hitscan : IBehavior
|
||||
{
|
||||
private bool _firing;
|
||||
private float _cooldown; // normalized
|
||||
private HitscanData _data;
|
||||
private Entity Entity { get; }
|
||||
private EquippedItem Item { get; }
|
||||
private ItemManager Context { get; }
|
||||
private float _firingVisibility;
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
public float Range { get; private set; }
|
||||
|
||||
public Hitscan(ItemManager context, HitscanData c, Entity entity, EquippedItem item)
|
||||
{
|
||||
Context = context;
|
||||
_data = c;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
}
|
||||
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
// TODO: Implement hitscan weapons!
|
||||
Range = Context.Evaluate(_data.Range, Item.EquippableItem, Entity);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
125
Assets/Scripts/ServerShared/Behaviors/InstantWeapon.cs
Normal file
125
Assets/Scripts/ServerShared/Behaviors/InstantWeapon.cs
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
|
||||
public class InstantWeaponData : WeaponData
|
||||
{
|
||||
[InspectableField, JsonProperty("burstCount"), Key(13)]
|
||||
public int BurstCount;
|
||||
|
||||
[InspectableField, JsonProperty("burstTime"), Key(14)]
|
||||
public PerformanceStat BurstTime = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("cooldown"), Key(15), RuntimeInspectable]
|
||||
public PerformanceStat Cooldown = new PerformanceStat();
|
||||
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
{
|
||||
return new InstantWeapon(context, this, entity, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class InstantWeapon : Weapon, IProgressBehavior
|
||||
{
|
||||
private InstantWeaponData _data;
|
||||
|
||||
protected int _burstRemaining;
|
||||
private float _burstTimer;
|
||||
private float _burstInterval;
|
||||
protected float _cooldown; // Normalized
|
||||
private int _ammo = 1;
|
||||
private bool _coolingDown;
|
||||
|
||||
public override int Ammo
|
||||
{
|
||||
get => _ammo;
|
||||
}
|
||||
public virtual float Progress => saturate(_cooldown);
|
||||
|
||||
public event Action OnReloadBegin;
|
||||
public event Action OnReloadComplete;
|
||||
public event Action OnCooldownComplete;
|
||||
public event Action OnFire;
|
||||
|
||||
public InstantWeapon(ItemManager context, InstantWeaponData data, Entity entity, EquippedItem item) : base(context,data,entity,item)
|
||||
{
|
||||
_data = data;
|
||||
}
|
||||
|
||||
protected void Trigger()
|
||||
{
|
||||
_burstRemaining = _data.BurstCount;
|
||||
_burstInterval = Context.Evaluate(_data.BurstTime, Item.EquippableItem, Entity) / _burstRemaining;
|
||||
_burstTimer = 0;
|
||||
_cooldown = 1;
|
||||
_coolingDown = true;
|
||||
}
|
||||
|
||||
public override bool Execute(float delta)
|
||||
{
|
||||
if (_coolingDown)
|
||||
{
|
||||
_cooldown -= delta / (_ammo == 0 ? _data.ReloadTime : Context.Evaluate(_data.Cooldown, Item.EquippableItem, Entity));
|
||||
if (_cooldown < 0)
|
||||
{
|
||||
_coolingDown = false;
|
||||
if (_ammo == 0)
|
||||
{
|
||||
_ammo = _data.MagazineSize;
|
||||
OnReloadComplete?.Invoke();
|
||||
}
|
||||
else
|
||||
OnCooldownComplete?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
_burstTimer += delta;
|
||||
while (_burstRemaining > 0 && _burstTimer > 0)
|
||||
{
|
||||
if (_data.AmmoType != Guid.Empty)
|
||||
{
|
||||
if (_data.MagazineSize > 1 && _ammo > 0) _ammo--;
|
||||
else
|
||||
{
|
||||
var cargo = Entity.FindItemInCargo(_data.AmmoType);
|
||||
if (cargo != null)
|
||||
{
|
||||
var item = cargo.ItemsOfType[_data.AmmoType][0];
|
||||
if (item is SimpleCommodity simpleCommodity)
|
||||
cargo.Remove(simpleCommodity, 1);
|
||||
|
||||
if(_data.MagazineSize > 1)
|
||||
{
|
||||
OnReloadBegin?.Invoke();
|
||||
_cooldown = 1;
|
||||
_coolingDown = true;
|
||||
_firing = false;
|
||||
}
|
||||
}
|
||||
_burstRemaining = 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
_burstRemaining--;
|
||||
_burstTimer -= _burstInterval;
|
||||
OnFire?.Invoke();
|
||||
Item.AddHeat(Context.Evaluate(_data.Heat, Item.EquippableItem, Entity));
|
||||
Entity.VisibilitySources[this] = Context.Evaluate(_data.Visibility, Item.EquippableItem, Entity);
|
||||
Entity.Energy -= Context.Evaluate(_data.Energy, Item.EquippableItem, Entity);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Activate()
|
||||
{
|
||||
if(!_coolingDown)
|
||||
Trigger();
|
||||
base.Activate();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7d1880b94a9e9f74e9c13be8d5fd8dee
|
||||
guid: 47fd83e8ade851c4e9177cd1de58949d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
|
|
@ -7,31 +7,31 @@ using Newtonsoft.Json;
|
|||
using Unity.Mathematics;
|
||||
|
||||
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class LauncherData : InstantWeaponData
|
||||
public class LauncherData : LockWeaponData
|
||||
{
|
||||
[InspectableAnimationCurve, JsonProperty("guidance"), Key(9)]
|
||||
[InspectableAnimationCurve, JsonProperty("guidance"), Key(21)]
|
||||
public float4[] GuidanceCurve;
|
||||
|
||||
[InspectableAnimationCurve, JsonProperty("thrustCurve"), Key(10)]
|
||||
[InspectableAnimationCurve, JsonProperty("thrustCurve"), Key(22)]
|
||||
public float4[] ThrustCurve;
|
||||
|
||||
[InspectableAnimationCurve, JsonProperty("liftCurve"), Key(11)]
|
||||
[InspectableAnimationCurve, JsonProperty("liftCurve"), Key(23)]
|
||||
public float4[] LiftCurve;
|
||||
|
||||
[InspectableField, JsonProperty("thrust"), Key(12)]
|
||||
[InspectableField, JsonProperty("thrust"), Key(24)]
|
||||
public PerformanceStat Thrust = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("frequency"), Key(13)]
|
||||
[InspectableField, JsonProperty("frequency"), Key(25)]
|
||||
public float DodgeFrequency;
|
||||
|
||||
[InspectableField, JsonProperty("launchSpeed"), Key(14)]
|
||||
[InspectableField, JsonProperty("launchSpeed"), Key(26)]
|
||||
public PerformanceStat LaunchSpeed = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("missileSpeed"), Key(15), RuntimeInspectable]
|
||||
[InspectableField, JsonProperty("missileSpeed"), Key(27), RuntimeInspectable]
|
||||
public PerformanceStat Velocity = new PerformanceStat();
|
||||
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
{
|
||||
return new InstantWeapon(context, this, entity, item);
|
||||
return new LockWeapon(context, this, entity, item);
|
||||
}
|
||||
}
|
||||
97
Assets/Scripts/ServerShared/Behaviors/LockWeapon.cs
Normal file
97
Assets/Scripts/ServerShared/Behaviors/LockWeapon.cs
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
|
||||
public class LockWeaponData : InstantWeaponData
|
||||
{
|
||||
[InspectableField, JsonProperty("speed"), Key(16), RuntimeInspectable]
|
||||
public PerformanceStat LockSpeed = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("sensorImpact"), Key(17)]
|
||||
public PerformanceStat SensorImpact = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("threshold"), Key(18), RuntimeInspectable]
|
||||
public PerformanceStat LockAngle = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("directionImpact"), Key(19)]
|
||||
public PerformanceStat DirectionImpact = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("decay"), Key(20)]
|
||||
public PerformanceStat Decay = new PerformanceStat();
|
||||
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
{
|
||||
return new LockWeapon(context, this, entity, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class LockWeapon : InstantWeapon
|
||||
{
|
||||
private LockWeaponData _data;
|
||||
private float _lock;
|
||||
private bool _locking;
|
||||
private Entity _target;
|
||||
|
||||
public event Action OnLocked;
|
||||
public event Action OnBeginLocking;
|
||||
public event Action OnLockLost;
|
||||
|
||||
public float LockSpeed { get; private set; }
|
||||
public float SensorImpact { get; private set; }
|
||||
public float LockAngle { get; private set; }
|
||||
public float DirectionImpact { get; private set; }
|
||||
public float Decay { get; private set; }
|
||||
|
||||
public override float Progress => saturate(_cooldown > 0 ? _cooldown : _lock);
|
||||
|
||||
public float Lock
|
||||
{
|
||||
get => saturate(_lock);
|
||||
}
|
||||
|
||||
public LockWeapon(ItemManager context, LockWeaponData data, Entity entity, EquippedItem item) : base(context, data, entity, item)
|
||||
{
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public override bool Execute(float delta)
|
||||
{
|
||||
if (_target != Entity.Target.Value)
|
||||
{
|
||||
_lock = 0;
|
||||
_target = Entity.Target.Value;
|
||||
}
|
||||
|
||||
if (Entity.Target.Value != null)
|
||||
{
|
||||
LockSpeed = Context.Evaluate(_data.LockSpeed, Item.EquippableItem, Entity);
|
||||
SensorImpact = Context.Evaluate(_data.SensorImpact, Item.EquippableItem, Entity);
|
||||
LockAngle = Context.Evaluate(_data.LockAngle, 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 < LockAngle)
|
||||
{
|
||||
var lerp = 1 - unlerp(0, 90, degrees);
|
||||
_lock = saturate(_lock + pow(lerp, DirectionImpact) * delta * LockSpeed);
|
||||
}
|
||||
}
|
||||
|
||||
return base.Execute(delta);
|
||||
}
|
||||
|
||||
public override void Activate()
|
||||
{
|
||||
if(_lock > .99f)
|
||||
{
|
||||
base.Activate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
3
Assets/Scripts/ServerShared/Behaviors/LockWeapon.cs.meta
Normal file
3
Assets/Scripts/ServerShared/Behaviors/LockWeapon.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 33fa49d85b53444c92c8c0979f2b95f9
|
||||
timeCreated: 1611439099
|
||||
|
|
@ -38,8 +38,8 @@ public class MiningController : ControllerBase<Mining>, IBehavior, IPersistentBe
|
|||
|
||||
public new void Initialize()
|
||||
{
|
||||
_miningTool = Entity.GetBehavior<MiningTool>();
|
||||
_toolSwitch = Entity.GetSwitch<MiningTool>();
|
||||
// _miningTool = Entity.GetBehavior<MiningTool>();
|
||||
// _toolSwitch = Entity.GetSwitch<MiningTool>();
|
||||
base.Initialize();
|
||||
}
|
||||
|
||||
|
|
|
|||
56
Assets/Scripts/ServerShared/Behaviors/ParticleEffect.cs
Normal file
56
Assets/Scripts/ServerShared/Behaviors/ParticleEffect.cs
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
/* 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)]
|
||||
// public class ParticleEffectData : BehaviorData
|
||||
// {
|
||||
// [InspectablePrefab, JsonProperty("Particles"), Key(1)]
|
||||
// public string ParticlesPrefab;
|
||||
//
|
||||
// [InspectableField, JsonProperty("thrust"), Key(2)]
|
||||
// public bool AreaEmitter;
|
||||
//
|
||||
// public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
// {
|
||||
// return new ParticleEffect(context, this, entity, item);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public class ParticleEffect : IBehavior, IAlwaysUpdatedBehavior
|
||||
// {
|
||||
// private ParticleEffectData _data;
|
||||
//
|
||||
// public Entity Entity { get; }
|
||||
// public EquippedItem Item { get; }
|
||||
// public ItemManager Context { get; }
|
||||
//
|
||||
// public BehaviorData Data => _data;
|
||||
//
|
||||
// public float Emission { get; private set; }
|
||||
//
|
||||
// public ParticleEffect(ItemManager context, ParticleEffectData data, Entity entity, EquippedItem item)
|
||||
// {
|
||||
// Context = context;
|
||||
// _data = data;
|
||||
// Entity = entity;
|
||||
// Item = item;
|
||||
// }
|
||||
//
|
||||
// public float Execute(float delta, float input)
|
||||
// {
|
||||
// Emission = saturate(input);
|
||||
// return input;
|
||||
// }
|
||||
//
|
||||
// public void Update(float delta)
|
||||
// {
|
||||
// Emission = 0;
|
||||
// }
|
||||
// }
|
||||
11
Assets/Scripts/ServerShared/Behaviors/ParticleEffect.cs.meta
Normal file
11
Assets/Scripts/ServerShared/Behaviors/ParticleEffect.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3c26dc8102d619a429a178bc6670242d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -9,17 +9,20 @@ using Newtonsoft.Json;
|
|||
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class ProjectileWeaponData : InstantWeaponData
|
||||
{
|
||||
[InspectableField, JsonProperty("spread"), Key(9), RuntimeInspectable]
|
||||
[InspectableField, JsonProperty("spread"), Key(16), RuntimeInspectable]
|
||||
public PerformanceStat Spread = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("bulletInherit"), Key(10)]
|
||||
[InspectableField, JsonProperty("bulletInherit"), Key(17)]
|
||||
public float Inherit;
|
||||
|
||||
[InspectableField, JsonProperty("bulletVelocity"), Key(11), RuntimeInspectable]
|
||||
[InspectableField, JsonProperty("bulletVelocity"), Key(18), RuntimeInspectable]
|
||||
public PerformanceStat Velocity = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("auto"), Key(19)]
|
||||
public bool Auto;
|
||||
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
{
|
||||
return new InstantWeapon(context, this, entity, item);
|
||||
return Auto ? new AutoWeapon(context, this, entity, item) : new InstantWeapon(context, this, entity, item);
|
||||
}
|
||||
}
|
||||
|
|
@ -41,7 +41,7 @@ public class SurveyController : ControllerBase<Survey>, IBehavior, IPersistentBe
|
|||
public new void Initialize()
|
||||
{
|
||||
_scanningTool = Entity.GetBehavior<ResourceScanner>();
|
||||
_toolSwitch = Entity.GetSwitch<ResourceScanner>();
|
||||
// _toolSwitch = Entity.GetSwitch<ResourceScanner>();
|
||||
base.Initialize();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,94 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using System.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 LockSpeed = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("sensorImpact"), Key(2)]
|
||||
public PerformanceStat SensorImpact = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("threshold"), Key(3), RuntimeInspectable]
|
||||
public PerformanceStat LockAngle = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("directionImpact"), Key(4)]
|
||||
public PerformanceStat DirectionImpact = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("decay"), Key(5)]
|
||||
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; }
|
||||
|
||||
private Entity _target;
|
||||
|
||||
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 (_target != Entity.Target.Value)
|
||||
{
|
||||
Lock = 0;
|
||||
_target = Entity.Target.Value;
|
||||
}
|
||||
if (Entity.Target.Value != null)
|
||||
{
|
||||
Speed = Context.Evaluate(_data.LockSpeed, Item.EquippableItem, Entity);
|
||||
SensorImpact = Context.Evaluate(_data.SensorImpact, Item.EquippableItem, Entity);
|
||||
Threshold = Context.Evaluate(_data.LockAngle, 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);
|
||||
}
|
||||
}
|
||||
|
|
@ -69,7 +69,9 @@ public class Thruster : IAnalogBehavior
|
|||
Entity.Velocity -= Entity.Direction.Rotate(Item.EquippableItem.Rotation) * _input * Thrust / Entity.Mass * delta;
|
||||
Entity.Direction = mul(Entity.Direction, Unity.Mathematics.float2x2.Rotate(_input * Torque * Thrust * Context.GameplaySettings.TorqueMultiplier / Entity.Mass * delta));
|
||||
Item.AddHeat(_input * Context.Evaluate(_data.Heat, Item.EquippableItem, Entity) * delta);
|
||||
Entity.VisibilitySources[this] = _input * Context.Evaluate(_data.Visibility, Item.EquippableItem, Entity);
|
||||
var vis = _input * Context.Evaluate(_data.Visibility, Item.EquippableItem, Entity);
|
||||
if(!Entity.VisibilitySources.ContainsKey(this) || vis > Entity.VisibilitySources[this])
|
||||
Entity.VisibilitySources[this] = vis;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -16,7 +16,7 @@ public class TriggerData : BehaviorData
|
|||
}
|
||||
}
|
||||
|
||||
public class Trigger : IBehavior
|
||||
public class Trigger : IBehavior, IActivatedBehavior
|
||||
{
|
||||
private TriggerData _data;
|
||||
|
||||
|
|
@ -28,11 +28,6 @@ public class Trigger : IBehavior
|
|||
|
||||
public bool _pulled;
|
||||
|
||||
public void Pull()
|
||||
{
|
||||
_pulled = true;
|
||||
}
|
||||
|
||||
public Trigger(ItemManager context, TriggerData data, Entity entity, EquippedItem item)
|
||||
{
|
||||
_data = data;
|
||||
|
|
@ -55,4 +50,13 @@ public class Trigger : IBehavior
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Activate()
|
||||
{
|
||||
_pulled = true;
|
||||
}
|
||||
|
||||
public void Deactivate()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -1,72 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
[MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
|
||||
public class TurningData : BehaviorData
|
||||
{
|
||||
[InspectableField, JsonProperty("torque"), Key(1), RuntimeInspectable]
|
||||
public PerformanceStat Torque = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("visibility"), Key(2)]
|
||||
public PerformanceStat Visibility = new PerformanceStat();
|
||||
|
||||
[InspectableField, JsonProperty("heat"), Key(3)]
|
||||
public PerformanceStat Heat = new PerformanceStat();
|
||||
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
{
|
||||
return new Turning(context, this, entity, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class Turning : IAnalogBehavior
|
||||
{
|
||||
public Entity Entity { get; }
|
||||
public EquippedItem Item { get; }
|
||||
public ItemManager Context { get; }
|
||||
|
||||
public float Torque { get; private set; }
|
||||
|
||||
public float Axis
|
||||
{
|
||||
get => _input;
|
||||
set => _input = clamp(value, -1, 1);
|
||||
}
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
private TurningData _data;
|
||||
|
||||
private float _input;
|
||||
|
||||
public Turning(ItemManager context, TurningData data, Entity entity, EquippedItem item)
|
||||
{
|
||||
Context = context;
|
||||
_data = data;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
}
|
||||
|
||||
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));
|
||||
Item.AddHeat(abs(_input) * Context.Evaluate(_data.Heat, Item.EquippableItem, Entity) * delta);
|
||||
Entity.VisibilitySources[this] = abs(_input) * Context.Evaluate(_data.Visibility, Item.EquippableItem, Entity);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Remove()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 21343037bc4842669c20b0606b03a622
|
||||
timeCreated: 1586270198
|
||||
|
|
@ -22,7 +22,7 @@ public class TurretControllerData : BehaviorData
|
|||
public class TurretController : IBehavior
|
||||
{
|
||||
private TurretControllerData _data;
|
||||
private Dictionary<Trigger, WeaponData> _triggers = new Dictionary<Trigger, WeaponData>();
|
||||
private List<Weapon> _weapons = new List<Weapon>();
|
||||
|
||||
public Entity EquippedEntity { get; }
|
||||
public EquippedItem Item { get; }
|
||||
|
|
@ -39,31 +39,23 @@ public class TurretController : IBehavior
|
|||
var weapons = equippedEntity.Equipment.Where(e => e.Behaviors.Any(b => b.Data is WeaponData));
|
||||
foreach (var weapon in weapons)
|
||||
{
|
||||
CheckWeapon(item);
|
||||
CheckWeapon(weapon);
|
||||
}
|
||||
|
||||
equippedEntity.Equipment.ObserveAdd().Subscribe(add => CheckWeapon(add.Value));
|
||||
equippedEntity.Equipment.ObserveRemove().Subscribe(remove =>
|
||||
{
|
||||
foreach (var bg in remove.Value.BehaviorGroups)
|
||||
if (_triggers.ContainsKey(bg.Trigger))
|
||||
_triggers.Remove(bg.Trigger);
|
||||
foreach (var b in remove.Value.Behaviors)
|
||||
if (b is Weapon weapon)
|
||||
_weapons.Remove(weapon);
|
||||
});
|
||||
}
|
||||
|
||||
private void CheckWeapon(EquippedItem item)
|
||||
{
|
||||
foreach (var bg in item.BehaviorGroups)
|
||||
{
|
||||
if (bg.Trigger != null)
|
||||
{
|
||||
foreach (var b in bg.Behaviors)
|
||||
{
|
||||
if(b.Data is WeaponData weaponData)
|
||||
_triggers.Add(bg.Trigger, weaponData);
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (var b in item.Behaviors)
|
||||
if (b is Weapon weapon)
|
||||
_weapons.Add(weapon);
|
||||
}
|
||||
|
||||
public bool Execute(float delta)
|
||||
|
|
@ -74,14 +66,18 @@ public class TurretController : IBehavior
|
|||
EquippedEntity.LookDirection = normalize(diff);
|
||||
var dist = length(diff);
|
||||
|
||||
foreach (var x in _triggers)
|
||||
foreach (var x in _weapons)
|
||||
{
|
||||
if (Context.Evaluate(x.Value.Range, x.Key.Item.EquippableItem, EquippedEntity) > dist &&
|
||||
dot(EquippedEntity.HardpointTransforms[EquippedEntity.Hardpoints[x.Key.Item.Position.x, x.Key.Item.Position.y]].direction,
|
||||
EquippedEntity.LookDirection) > .9f)
|
||||
var data = x.Data as WeaponData;
|
||||
var fire = dot(
|
||||
EquippedEntity.HardpointTransforms[EquippedEntity.Hardpoints[x.Item.Position.x, x.Item.Position.y]].direction,
|
||||
EquippedEntity.LookDirection) > .99f;
|
||||
if (Context.Evaluate(data.Range, x.Item.EquippableItem, EquippedEntity) > dist && fire)
|
||||
{
|
||||
x.Key.Pull();
|
||||
x.Activate();
|
||||
}
|
||||
else if (x.Firing)
|
||||
x.Deactivate();
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
|||
|
|
@ -54,8 +54,6 @@ public class Visibility : IBehavior, IAlwaysUpdatedBehavior
|
|||
if(Entity.VisibilitySources.ContainsKey(this))
|
||||
{
|
||||
Entity.VisibilitySources[this] *= Context.Evaluate(_data.VisibilityDecay, Item.EquippableItem, Entity);
|
||||
|
||||
if (Entity.VisibilitySources[this] < 0.01f) Entity.VisibilitySources.Remove(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,6 +3,8 @@
|
|||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
|
|
@ -28,66 +30,63 @@ public abstract class WeaponData : BehaviorData
|
|||
|
||||
[InspectablePrefab, JsonProperty("effect"), Key(6)]
|
||||
public string EffectPrefab;
|
||||
|
||||
[InspectablePrefab, JsonProperty("energy"), Key(7), RuntimeInspectable]
|
||||
public PerformanceStat Energy = new PerformanceStat();
|
||||
|
||||
[InspectablePrefab, JsonProperty("heat"), Key(8), RuntimeInspectable]
|
||||
public PerformanceStat Heat = new PerformanceStat();
|
||||
|
||||
[InspectablePrefab, JsonProperty("visibility"), Key(9), RuntimeInspectable]
|
||||
public PerformanceStat Visibility = new PerformanceStat();
|
||||
|
||||
[InspectableDatabaseLink(typeof(SimpleCommodityData)), JsonProperty("ammo"), Key(10), RuntimeInspectable]
|
||||
public Guid AmmoType;
|
||||
|
||||
[InspectablePrefab, JsonProperty("magSize"), Key(11)]
|
||||
public int MagazineSize;
|
||||
|
||||
[InspectablePrefab, JsonProperty("reloadTime"), Key(12)]
|
||||
public float ReloadTime = 1;
|
||||
}
|
||||
|
||||
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
|
||||
public abstract class InstantWeaponData : WeaponData
|
||||
public abstract class Weapon : IActivatedBehavior
|
||||
{
|
||||
[InspectableField, JsonProperty("burstCount"), Key(7), RuntimeInspectable]
|
||||
public int BurstCount;
|
||||
|
||||
[InspectableField, JsonProperty("burstTime"), Key(8)]
|
||||
public PerformanceStat BurstTime = new PerformanceStat();
|
||||
}
|
||||
|
||||
public class InstantWeapon : IBehavior, IAlwaysUpdatedBehavior
|
||||
{
|
||||
private InstantWeaponData _data;
|
||||
|
||||
public int _burstCount;
|
||||
public float _burstTimer;
|
||||
|
||||
private Entity Entity { get; }
|
||||
private EquippedItem Item { get; }
|
||||
private ItemManager Context { get; }
|
||||
private WeaponData _data;
|
||||
|
||||
public Entity Entity { get; }
|
||||
public EquippedItem Item { get; }
|
||||
public ItemManager Context { get; }
|
||||
|
||||
public abstract int Ammo { get; }
|
||||
public WeaponData WeaponData => _data;
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
public event Action OnFire;
|
||||
protected bool _firing;
|
||||
|
||||
private float _burstTime;
|
||||
public bool Firing
|
||||
{
|
||||
get => _firing;
|
||||
}
|
||||
|
||||
public InstantWeapon(ItemManager context, InstantWeaponData c, Entity entity, EquippedItem item)
|
||||
|
||||
public Weapon(ItemManager context, WeaponData data, Entity entity, EquippedItem item)
|
||||
{
|
||||
Context = context;
|
||||
_data = c;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public bool Execute(float delta)
|
||||
public abstract bool Execute(float delta);
|
||||
|
||||
public virtual void Activate()
|
||||
{
|
||||
_burstCount = _data.BurstCount;
|
||||
_burstTime = Context.Evaluate(_data.BurstTime, Item.EquippableItem, Entity) / _burstCount;
|
||||
_burstTimer = 0;
|
||||
Fire(delta);
|
||||
return true;
|
||||
_firing = true;
|
||||
}
|
||||
|
||||
private void Fire(float delta)
|
||||
public virtual void Deactivate()
|
||||
{
|
||||
_burstTimer -= delta;
|
||||
while (_burstTimer < 0 && _burstCount > 0)
|
||||
{
|
||||
_burstCount--;
|
||||
_burstTimer += _burstTime;
|
||||
OnFire?.Invoke();
|
||||
}
|
||||
_firing = false;
|
||||
}
|
||||
|
||||
public void Update(float delta)
|
||||
{
|
||||
if(_burstCount > 0)
|
||||
Fire(delta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ public abstract class Entity
|
|||
new Dictionary<HardpointData, (float3 position, float3 direction)>();
|
||||
public Dictionary<HardpointData, float> HardpointArmor;
|
||||
|
||||
public readonly List<EquippedItem>[] TriggerGroups;
|
||||
public readonly (List<IActivatedBehavior> behaviors, List<EquippedItem> items)[] TriggerGroups;
|
||||
|
||||
public List<IPopulationAssignment> PopulationAssignments = new List<IPopulationAssignment>();
|
||||
|
||||
|
|
@ -107,9 +107,9 @@ public abstract class Entity
|
|||
Hull = hull;
|
||||
Name = hull.Name;
|
||||
MapEntity();
|
||||
TriggerGroups = new List<EquippedItem>[itemManager.GameplaySettings.TriggerGroupCount];
|
||||
TriggerGroups = new (List<IActivatedBehavior> triggers, List<EquippedItem> items)[itemManager.GameplaySettings.TriggerGroupCount];
|
||||
for(int i=0; i<itemManager.GameplaySettings.TriggerGroupCount; i++)
|
||||
TriggerGroups[i] = new List<EquippedItem>();
|
||||
TriggerGroups[i] = (new List<IActivatedBehavior>(), 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);
|
||||
|
|
@ -490,29 +490,53 @@ public abstract class Entity
|
|||
yield return b;
|
||||
}
|
||||
|
||||
public Switch GetSwitch<T>() where T : class, IBehavior
|
||||
{
|
||||
foreach (var equippedItem in Equipment)
|
||||
foreach (var group in equippedItem.BehaviorGroups)
|
||||
foreach(var behavior in group.Behaviors)
|
||||
if (behavior is T)
|
||||
return group.Switch;
|
||||
return null;
|
||||
}
|
||||
|
||||
public Trigger GetTrigger<T>() where T : class, IBehavior
|
||||
{
|
||||
foreach (var equippedItem in Equipment)
|
||||
foreach (var group in equippedItem.BehaviorGroups)
|
||||
foreach(var behavior in group.Behaviors)
|
||||
if (behavior is T)
|
||||
return group.Trigger;
|
||||
return null;
|
||||
}
|
||||
// public IEnumerable<(T t, Switch s)> GetSwitch<T>() where T : class, IBehavior
|
||||
// {
|
||||
// foreach (var equippedItem in Equipment)
|
||||
// foreach (var group in equippedItem.BehaviorGroups.Values)
|
||||
// foreach(var behavior in group.Behaviors)
|
||||
// if (behavior is T t)
|
||||
// {
|
||||
// var s = group.GetExposed<Switch>();
|
||||
// if (s != null) yield return (t, s);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public IEnumerable<(T behavior, Trigger trigger)> GetTrigger<T>() where T : class, IBehavior
|
||||
// {
|
||||
// foreach (var equippedItem in Equipment)
|
||||
// foreach (var group in equippedItem.BehaviorGroups.Values)
|
||||
// foreach(var behavior in group.Behaviors)
|
||||
// if (behavior is T t)
|
||||
// {
|
||||
// var s = group.GetExposed<Trigger>();
|
||||
// if (s != null) yield return (t, s);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public IEnumerable<(T behavior, Axis axis)> GetAxis<T>() where T : class, IBehavior
|
||||
// {
|
||||
// foreach (var equippedItem in Equipment)
|
||||
// foreach (var group in equippedItem.BehaviorGroups.Values)
|
||||
// foreach(var behavior in group.Behaviors)
|
||||
// if (behavior is T t)
|
||||
// {
|
||||
// var s = group.GetExposed<Axis>();
|
||||
// if (s != null) yield return (t, s);
|
||||
// }
|
||||
// }
|
||||
|
||||
public virtual void Update(float delta)
|
||||
{
|
||||
var hullData = ItemManager.GetData(Hull) as HullData;
|
||||
|
||||
foreach (var v in VisibilitySources.Keys.ToArray())
|
||||
{
|
||||
VisibilitySources[v] *= max(1 - ItemManager.GameplaySettings.VisibilityDecay * delta, 0);
|
||||
|
||||
if (VisibilitySources[v] < 0.01f) VisibilitySources.Remove(v);
|
||||
}
|
||||
|
||||
//float[,] newTemp = new float[hullData.Shape.Width,hullData.Shape.Height];
|
||||
var radiation = 0f;
|
||||
foreach (var v in hullData.Shape.Coordinates)
|
||||
|
|
@ -632,7 +656,7 @@ public class EquippedItem
|
|||
|
||||
public IBehavior[] Behaviors;
|
||||
|
||||
public BehaviorGroup[] BehaviorGroups;
|
||||
public Dictionary<int, BehaviorGroup> BehaviorGroups;
|
||||
|
||||
public float Conductivity { get; }
|
||||
|
||||
|
|
@ -670,17 +694,16 @@ public class EquippedItem
|
|||
Behaviors = _data.Behaviors
|
||||
.Select(bd => bd.CreateInstance(itemManager, entity, this))
|
||||
.ToArray();
|
||||
|
||||
|
||||
BehaviorGroups = Behaviors
|
||||
.GroupBy(b => b.Data.Group)
|
||||
.OrderBy(g=>g.Key)
|
||||
.Select(g=> new BehaviorGroup {
|
||||
.OrderBy(g => g.Key)
|
||||
.ToDictionary(g => g.Key, g => new BehaviorGroup
|
||||
{
|
||||
Behaviors = g.ToArray(),
|
||||
//Axis = (IAnalogBehavior) g.FirstOrDefault(b=>b is IAnalogBehavior),
|
||||
Switch = (Switch) g.FirstOrDefault(b=>b is Switch),
|
||||
Trigger = (Trigger) g.FirstOrDefault(b=>b is Trigger)
|
||||
})
|
||||
.ToArray();
|
||||
// Switch = (Switch) g.FirstOrDefault(b => b is Switch),
|
||||
// Trigger = (Trigger) g.FirstOrDefault(b => b is Trigger)
|
||||
});
|
||||
|
||||
foreach (var behavior in Behaviors)
|
||||
{
|
||||
|
|
@ -710,7 +733,7 @@ public class EquippedItem
|
|||
|
||||
if (Online)
|
||||
{
|
||||
foreach (var group in BehaviorGroups)
|
||||
foreach (var group in BehaviorGroups.Values)
|
||||
{
|
||||
foreach (var behavior in group.Behaviors)
|
||||
{
|
||||
|
|
@ -1016,7 +1039,28 @@ public class EquippedDockingBay : EquippedCargoBay
|
|||
public class BehaviorGroup
|
||||
{
|
||||
public IBehavior[] Behaviors;
|
||||
public Trigger Trigger;
|
||||
public Switch Switch;
|
||||
|
||||
public T GetBehavior<T>() where T : class, IBehavior
|
||||
{
|
||||
foreach (var b in Behaviors)
|
||||
{
|
||||
if (!(b is T s)) continue;
|
||||
return s;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public T GetExposed<T>() where T : class, IBehavior, IInteractiveBehavior
|
||||
{
|
||||
foreach (var b in Behaviors)
|
||||
{
|
||||
if (!(b is T s) || !((IInteractiveBehavior)b).Exposed) continue;
|
||||
return s;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
//public IAnalogBehavior Axis;
|
||||
}
|
||||
|
|
@ -414,12 +414,6 @@ public static class ObjectExtensions
|
|||
{
|
||||
return (T)Copy((Object)original);
|
||||
}
|
||||
|
||||
public static bool IntersectsWith(this Rect r1, Rect r2)
|
||||
{
|
||||
return (r2.x + r2.width >= r1.x && r2.x <= r1.x + r1.width) &&
|
||||
(r2.y + r2.height >= r1.y && r2.y <= r1.y + r1.height);
|
||||
}
|
||||
}
|
||||
|
||||
public class ReferenceEqualityComparer : EqualityComparer<Object>
|
||||
|
|
|
|||
|
|
@ -34,7 +34,8 @@ namespace JsonKnownTypes
|
|||
if(_typesSettings.DiscriminatorToType.TryGetValue(discriminator, out var typeForObject))
|
||||
return JsonConvert.DeserializeObject(jo.ToString(), typeForObject, SpecifiedSubclassConversion);
|
||||
|
||||
throw new NotImplementedException();
|
||||
return null;
|
||||
//throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ namespace RethinkDb.Driver.Net.Clustering
|
|||
private EpsilonValueCalculator calc;
|
||||
private float[] weights = null;
|
||||
|
||||
private Timer timer;
|
||||
private System.Threading.Timer timer;
|
||||
|
||||
/// <summary>
|
||||
/// Random value generator.
|
||||
|
|
@ -158,7 +158,7 @@ namespace RethinkDb.Driver.Net.Clustering
|
|||
public void StartDecayTimer()
|
||||
{
|
||||
var durationPerBucket = TimeSpan.FromTicks(decayDuration.Ticks / EpsilonBuckets);
|
||||
this.timer = new Timer(PerformEpsilonGreedyDecay, null, Timeout.Infinite, Timeout.Infinite);
|
||||
this.timer = new System.Threading.Timer(PerformEpsilonGreedyDecay, null, Timeout.Infinite, Timeout.Infinite);
|
||||
|
||||
//fire now.
|
||||
this.timer.Change(TimeSpan.Zero, durationPerBucket);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
using float2 = Unity.Mathematics.float2;
|
||||
|
||||
namespace Unity.Tiny
|
||||
{
|
||||
|
|
@ -12,23 +14,25 @@ namespace Unity.Tiny
|
|||
/// </summary>
|
||||
public static Rect Default { get; } = new Rect()
|
||||
{
|
||||
x = 0f,
|
||||
y = 0f,
|
||||
width = 1f,
|
||||
height = 1f
|
||||
position = float2.zero,
|
||||
size = float2(1,1)
|
||||
};
|
||||
|
||||
public Rect(float x, float y, float width, float height)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
position = float2(x, y);
|
||||
size = float2(width, height);
|
||||
}
|
||||
|
||||
public Rect(float2 position, float2 size)
|
||||
{
|
||||
this.position = position;
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public bool IsEmpty()
|
||||
{
|
||||
return !(width > 0.0f && height > 0.0f);
|
||||
return !(size.x > 0.0f && size.y > 0.0f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -41,7 +45,7 @@ namespace Unity.Tiny
|
|||
/// </remarks>
|
||||
public bool Contains(float2 pos)
|
||||
{
|
||||
return pos.x >= x && pos.y >= y && pos.x < x + width && pos.y < y + height;
|
||||
return pos.x >= position.x && pos.y >= position.y && pos.x < position.x + size.x && pos.y < position.y + size.y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -51,57 +55,46 @@ namespace Unity.Tiny
|
|||
{
|
||||
return new Rect
|
||||
{
|
||||
x = x + relative.x * width,
|
||||
y = y + relative.y * height,
|
||||
width = width * relative.width,
|
||||
height = height * relative.height
|
||||
position = float2(position.x + relative.position.x * size.x,position.y + relative.position.y * size.y) ,
|
||||
size = float2(size.x * relative.size.x, size.y * relative.size.y)
|
||||
};
|
||||
}
|
||||
|
||||
public bool IntersectsWith(Rect r2)
|
||||
{
|
||||
return r2.position.x + r2.size.x >= position.x && r2.position.x <= position.x + size.x &&
|
||||
r2.position.y + r2.size.y >= position.y && r2.position.y <= position.y + size.y;
|
||||
}
|
||||
|
||||
public void Clamp(Rect r)
|
||||
{
|
||||
float x2 = x + width;
|
||||
float y2 = y + height;
|
||||
float rx2 = r.x + r.width;
|
||||
float ry2 = r.y + r.height;
|
||||
if (x < r.x) x = r.x;
|
||||
float x2 = position.x + size.x;
|
||||
float y2 = position.y + size.y;
|
||||
float rx2 = r.position.x + r.size.x;
|
||||
float ry2 = r.position.y + r.size.y;
|
||||
if (position.x < r.position.x) position.x = r.position.x;
|
||||
if (x2 > rx2) x2 = rx2;
|
||||
if (y < r.y) y = r.y;
|
||||
if (position.y < r.position.y) position.y = r.position.y;
|
||||
if (y2 > ry2) y2 = ry2;
|
||||
width = x2 - x;
|
||||
if (width < 0.0f) width = 0.0f;
|
||||
height = y2 - y;
|
||||
if (height < 0.0f) height = 0.0f;
|
||||
size.x = x2 - position.x;
|
||||
if (size.x < 0.0f) size.x = 0.0f;
|
||||
size.y = y2 - position.y;
|
||||
if (size.y < 0.0f) size.y = 0.0f;
|
||||
}
|
||||
|
||||
public float x;
|
||||
public float y;
|
||||
public float width;
|
||||
public float height;
|
||||
|
||||
/// <summary>
|
||||
/// The width and height of the rectangle.
|
||||
/// </summary>
|
||||
public float2 Size
|
||||
{
|
||||
get => new float2(width, this.height);
|
||||
set
|
||||
{
|
||||
width = value.x;
|
||||
height = value.y;
|
||||
}
|
||||
}
|
||||
public float2 position;
|
||||
public float2 size;
|
||||
|
||||
/// <summary>
|
||||
/// The position of the center of the rectangle.
|
||||
/// </summary>
|
||||
public float2 Center
|
||||
{
|
||||
get => new float2(x + width / 2f, y + height/ 2f);
|
||||
get => new float2(position.x + size.x / 2f, position.y + size.y/ 2f);
|
||||
set
|
||||
{
|
||||
x = value.x - width / 2f;
|
||||
y = value.y - height / 2f;
|
||||
position.x = value.x - size.x / 2f;
|
||||
position.y = value.y - size.y / 2f;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -109,4 +109,5 @@ public class GameplaySettings
|
|||
public ExponentialLerp LockSpinSpeed;
|
||||
public float TorqueFloor;
|
||||
public float TorqueMultiplier;
|
||||
public float VisibilityDecay;
|
||||
}
|
||||
Loading…
Reference in a new issue