Reflected Visibility
Ships are now more visible in lit areas (depending on cross section stat in Reflector behavior) Refactored all behaviors to remove context & entity references (can get them from equipped item reference if needed) Fixed crash when enemy dies of heatstroke while targeted Exponential decay for visibility now uses correct time-independent formula Refactored item inspection in properties panel (now consistent between equipped items vs. inventory and store items, shows effect of heat on stats) Reordered item properties and added spacing between groups
This commit is contained in:
parent
b0b2717294
commit
a51c402fc5
59 changed files with 557 additions and 1405 deletions
|
|
@ -7,6 +7,16 @@ public static class AetheriaMath
|
|||
{
|
||||
public const float Deg2Rad = 0.01745329f;
|
||||
public const float Rad2Deg = 57.29578f;
|
||||
|
||||
public static float Decay(float source, float lambda, float dt)
|
||||
{
|
||||
return source * exp(-lambda * dt);
|
||||
}
|
||||
|
||||
public static float Damp(float a, float b, float lambda, float dt)
|
||||
{
|
||||
return lerp(a, b, 1 - exp(-lambda * dt));
|
||||
}
|
||||
|
||||
//first-order intercept using absolute target position
|
||||
public static float3 FirstOrderIntercept
|
||||
|
|
|
|||
|
|
@ -9,16 +9,16 @@ using static Unity.Mathematics.math;
|
|||
[Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
|
||||
public class AutoWeaponData : InstantWeaponData
|
||||
{
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
public override IBehavior CreateInstance(EquippedItem item)
|
||||
{
|
||||
return new AutoWeapon(context, this, entity, item);
|
||||
return new AutoWeapon(this, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class AutoWeapon : InstantWeapon
|
||||
{
|
||||
|
||||
public AutoWeapon(ItemManager context, InstantWeaponData data, Entity entity, EquippedItem item) : base(context, data, entity, item)
|
||||
public AutoWeapon(InstantWeaponData data, EquippedItem item) : base(data, item)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ public abstract class PersistentBehaviorData
|
|||
Union(16, typeof(HeatData)),
|
||||
// Union(17, typeof(HitscanData)),
|
||||
Union(18, typeof(ItemUsageData)),
|
||||
Union(19, typeof(RadianceData)),
|
||||
//Union(19, typeof(RadianceData)),
|
||||
Union(20, typeof(SwitchData)),
|
||||
Union(21, typeof(TriggerData)),
|
||||
Union(22, typeof(VisibilityData)),
|
||||
|
|
@ -128,7 +128,7 @@ public abstract class BehaviorData
|
|||
[Inspectable, JsonProperty("group"), Key(0)]
|
||||
public int Group;
|
||||
|
||||
public abstract IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item);
|
||||
public abstract IBehavior CreateInstance(EquippedItem item);
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -17,9 +17,9 @@ public class CapacitorData : BehaviorData
|
|||
[Inspectable, JsonProperty("efficiency"), Key(2), RuntimeInspectable]
|
||||
public PerformanceStat Efficiency = new PerformanceStat();
|
||||
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
public override IBehavior CreateInstance(EquippedItem item)
|
||||
{
|
||||
return new Capacitor(context, this, entity, item);
|
||||
return new Capacitor(this, item);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -27,9 +27,7 @@ public class Capacitor : IBehavior
|
|||
{
|
||||
private CapacitorData _data;
|
||||
|
||||
public Entity Entity { get; }
|
||||
public EquippedItem Item { get; }
|
||||
public ItemManager Context { get; }
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
|
|
@ -43,11 +41,9 @@ public class Capacitor : IBehavior
|
|||
Item.AddHeat(abs(charge) * (1-Efficiency));
|
||||
}
|
||||
|
||||
public Capacitor(ItemManager context, CapacitorData data, Entity entity, EquippedItem item)
|
||||
public Capacitor(CapacitorData data, EquippedItem item)
|
||||
{
|
||||
Context = context;
|
||||
_data = data;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,9 +45,9 @@ public class ChargedWeaponData : InstantWeaponData
|
|||
[Inspectable, JsonProperty("chargeHeatMul"), Key(32)]
|
||||
public float ChargeFiringHeatMultiplier = 1;
|
||||
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
public override IBehavior CreateInstance(EquippedItem item)
|
||||
{
|
||||
return new ChargedWeapon(context, this, entity, item);
|
||||
return new ChargedWeapon(this, item);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -93,7 +93,7 @@ public class ChargedWeapon : InstantWeapon, IEventBehavior
|
|||
get => _charge;
|
||||
}
|
||||
|
||||
public ChargedWeapon(ItemManager context, ChargedWeaponData data, Entity entity, EquippedItem item) : base(context, data, entity, item)
|
||||
public ChargedWeapon(ChargedWeaponData data, EquippedItem item) : base(data, item)
|
||||
{
|
||||
_data = data;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,9 +11,9 @@ using static Unity.Mathematics.math;
|
|||
[Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
|
||||
public class CockpitData : BehaviorData
|
||||
{
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
public override IBehavior CreateInstance(EquippedItem item)
|
||||
{
|
||||
return new Cockpit(context, this, entity, item);
|
||||
return new Cockpit(this, item);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -21,18 +21,14 @@ public class Cockpit : IBehavior
|
|||
{
|
||||
private CockpitData _data;
|
||||
|
||||
public Entity Entity { get; }
|
||||
public EquippedItem Item { get; }
|
||||
public ItemManager Context { get; }
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
|
||||
public Cockpit(ItemManager context, CockpitData data, Entity entity, EquippedItem item)
|
||||
public Cockpit(CockpitData data, EquippedItem item)
|
||||
{
|
||||
Context = context;
|
||||
_data = data;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,9 +14,9 @@ public class ConstantWeaponData : WeaponData
|
|||
[InspectablePrefab, JsonProperty("ammoInterval"), Key(17)]
|
||||
public float AmmoInterval = 1;
|
||||
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
public override IBehavior CreateInstance(EquippedItem item)
|
||||
{
|
||||
return new ConstantWeapon(context, this, entity, item);
|
||||
return new ConstantWeapon(this, item);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -57,7 +57,7 @@ public class ConstantWeapon : Weapon, IProgressBehavior, IEventBehavior
|
|||
OnStopFiring = null;
|
||||
}
|
||||
|
||||
public ConstantWeapon(ItemManager context, ConstantWeaponData data, Entity entity, EquippedItem item) : base(context, data, entity, item)
|
||||
public ConstantWeapon(ConstantWeaponData data, EquippedItem item) : base(data, item)
|
||||
{
|
||||
_data = data;
|
||||
}
|
||||
|
|
@ -67,7 +67,7 @@ public class ConstantWeapon : Weapon, IProgressBehavior, IEventBehavior
|
|||
base.Execute(delta);
|
||||
if (_firing)
|
||||
{
|
||||
if (!Entity.TryConsumeEnergy(Item.Evaluate(_data.Energy) * delta))
|
||||
if (!Item.Entity.TryConsumeEnergy(Item.Evaluate(_data.Energy) * delta))
|
||||
{
|
||||
_firing = false;
|
||||
OnStopFiring?.Invoke();
|
||||
|
|
@ -93,7 +93,7 @@ public class ConstantWeapon : Weapon, IProgressBehavior, IEventBehavior
|
|||
if (_data.MagazineSize > 1 && _ammo > 0) _ammo--;
|
||||
else
|
||||
{
|
||||
var cargo = Entity.FindItemInCargo(_data.AmmoType);
|
||||
var cargo = Item.Entity.FindItemInCargo(_data.AmmoType);
|
||||
if (cargo != null)
|
||||
{
|
||||
var item = cargo.ItemsOfType[_data.AmmoType][0];
|
||||
|
|
@ -117,7 +117,7 @@ public class ConstantWeapon : Weapon, IProgressBehavior, IEventBehavior
|
|||
|
||||
Item.EquippableItem.Durability -= Item.Wear * delta;
|
||||
Item.AddHeat(Item.Evaluate(_data.Heat) * delta);
|
||||
Entity.VisibilitySources[this] = Item.Evaluate(_data.Visibility);
|
||||
Item.Entity.VisibilitySources[this] = Item.Evaluate(_data.Visibility);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,9 +15,9 @@ public class CooldownData : BehaviorData
|
|||
[Inspectable, JsonProperty("cooldown"), Key(1), RuntimeInspectable]
|
||||
public PerformanceStat Cooldown = new PerformanceStat();
|
||||
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
public override IBehavior CreateInstance(EquippedItem item)
|
||||
{
|
||||
return new Cooldown(context, this, entity, item);
|
||||
return new Cooldown(this, item);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -26,20 +26,16 @@ public class Cooldown : IBehavior, IAlwaysUpdatedBehavior, IProgressBehavior
|
|||
private CooldownData _data;
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
private Entity Entity { get; }
|
||||
private EquippedItem Item { get; }
|
||||
private ItemManager Context { get; }
|
||||
|
||||
private float _cooldown; // Normalized
|
||||
|
||||
public float Progress => saturate(_cooldown);
|
||||
|
||||
public Cooldown(ItemManager context, CooldownData data, Entity entity, EquippedItem item)
|
||||
public Cooldown(CooldownData data, EquippedItem item)
|
||||
{
|
||||
_data = data;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
Context = context;
|
||||
}
|
||||
|
||||
public bool Execute(float delta)
|
||||
|
|
|
|||
|
|
@ -16,9 +16,9 @@ public class EnergyDrawData : BehaviorData
|
|||
[Inspectable, JsonProperty("perSecond"), Key(2)]
|
||||
public bool PerSecond;
|
||||
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
public override IBehavior CreateInstance(EquippedItem item)
|
||||
{
|
||||
return new EnergyDraw(context, this, entity, item);
|
||||
return new EnergyDraw(this, item);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -26,22 +26,18 @@ public class EnergyDraw : IBehavior
|
|||
{
|
||||
private EnergyDrawData _data;
|
||||
|
||||
private Entity Entity { get; }
|
||||
private EquippedItem Item { get; }
|
||||
private ItemManager Context { get; }
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
public EnergyDraw(ItemManager context, EnergyDrawData data, Entity entity, EquippedItem item)
|
||||
public EnergyDraw(EnergyDrawData data, EquippedItem item)
|
||||
{
|
||||
_data = data;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
Context = context;
|
||||
}
|
||||
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
return Entity.TryConsumeEnergy(Item.Evaluate(_data.EnergyDraw) * (_data.PerSecond ? delta : 1));
|
||||
return Item.Entity.TryConsumeEnergy(Item.Evaluate(_data.EnergyDraw) * (_data.PerSecond ? delta : 1));
|
||||
}
|
||||
}
|
||||
|
|
@ -16,9 +16,9 @@ public class HeatData : BehaviorData
|
|||
[Inspectable, JsonProperty("perSecond"), Key(2)]
|
||||
public bool PerSecond;
|
||||
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
public override IBehavior CreateInstance(EquippedItem item)
|
||||
{
|
||||
return new Heat(context, this, entity, item);
|
||||
return new Heat(this, item);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -26,18 +26,14 @@ public class Heat : IBehavior
|
|||
{
|
||||
private HeatData _data;
|
||||
|
||||
private Entity Entity { get; }
|
||||
private EquippedItem Item { get; }
|
||||
private ItemManager Context { get; }
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
public Heat(ItemManager context, HeatData data, Entity entity, EquippedItem item)
|
||||
public Heat(HeatData data, EquippedItem item)
|
||||
{
|
||||
_data = data;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
Context = context;
|
||||
}
|
||||
|
||||
public bool Execute(float delta)
|
||||
|
|
|
|||
|
|
@ -11,9 +11,9 @@ using static Unity.Mathematics.math;
|
|||
[Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
|
||||
public class HeatStorageData : BehaviorData
|
||||
{
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
public override IBehavior CreateInstance(EquippedItem item)
|
||||
{
|
||||
return new HeatStorage(context, this, entity, item);
|
||||
return new HeatStorage(this, item);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -21,17 +21,13 @@ public class HeatStorage : IBehavior
|
|||
{
|
||||
private HeatStorageData _data;
|
||||
|
||||
public Entity Entity { get; }
|
||||
public EquippedItem Item { get; }
|
||||
public ItemManager Context { get; }
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
public HeatStorage(ItemManager context, HeatStorageData data, Entity entity, EquippedItem item)
|
||||
public HeatStorage(HeatStorageData data, EquippedItem item)
|
||||
{
|
||||
Context = context;
|
||||
_data = data;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,9 +21,9 @@ public class InstantWeaponData : WeaponData
|
|||
[InspectablePrefab, JsonProperty("ammoInterval"), Key(20)]
|
||||
public bool SingleAmmoBurst;
|
||||
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
public override IBehavior CreateInstance(EquippedItem item)
|
||||
{
|
||||
return new InstantWeapon(context, this, entity, item);
|
||||
return new InstantWeapon(this, item);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -71,7 +71,7 @@ public class InstantWeapon : Weapon, IProgressBehavior, IEventBehavior
|
|||
OnFire = null;
|
||||
}
|
||||
|
||||
public InstantWeapon(ItemManager context, InstantWeaponData data, Entity entity, EquippedItem item) : base(context,data,entity,item)
|
||||
public InstantWeapon(InstantWeaponData data, EquippedItem item) : base(data, item)
|
||||
{
|
||||
_data = data;
|
||||
_ammo = data.MagazineSize;
|
||||
|
|
@ -81,7 +81,7 @@ public class InstantWeapon : Weapon, IProgressBehavior, IEventBehavior
|
|||
{
|
||||
// If 1 ammo is consumed per burst, perform ammo and energy consumption here
|
||||
// UseAmmo returns false when triggering reload; cancel firing if that is the case
|
||||
if(_data.SingleAmmoBurst && (!Entity.TryConsumeEnergy(Energy) || !UseAmmo())) return;
|
||||
if(_data.SingleAmmoBurst && (!Item.Entity.TryConsumeEnergy(Energy) || !UseAmmo())) return;
|
||||
|
||||
_burstRemaining = (int) BurstCount;
|
||||
_burstInterval = BurstTime / _burstRemaining;
|
||||
|
|
@ -115,7 +115,7 @@ public class InstantWeapon : Weapon, IProgressBehavior, IEventBehavior
|
|||
var hasAmmo = true;
|
||||
if (_data.AmmoType != Guid.Empty)
|
||||
{
|
||||
var cargo = Entity.FindItemInCargo(_data.AmmoType);
|
||||
var cargo = Item.Entity.FindItemInCargo(_data.AmmoType);
|
||||
if (cargo != null)
|
||||
{
|
||||
var item = cargo.ItemsOfType[_data.AmmoType][0];
|
||||
|
|
@ -160,7 +160,7 @@ public class InstantWeapon : Weapon, IProgressBehavior, IEventBehavior
|
|||
{
|
||||
// If multiple ammo is consumed per burst, perform ammo and energy consumption here
|
||||
// UseAmmo returns false when triggering reload; cancel firing if that is the case
|
||||
if (!_data.SingleAmmoBurst && (!Entity.TryConsumeEnergy(Energy) || !UseAmmo()))
|
||||
if (!_data.SingleAmmoBurst && (!Item.Entity.TryConsumeEnergy(Energy) || !UseAmmo()))
|
||||
{
|
||||
_burstRemaining = 0;
|
||||
return false;
|
||||
|
|
@ -171,7 +171,7 @@ public class InstantWeapon : Weapon, IProgressBehavior, IEventBehavior
|
|||
OnFire?.Invoke();
|
||||
Item.EquippableItem.Durability -= Item.Wear;
|
||||
Item.AddHeat(Heat);
|
||||
Entity.VisibilitySources[this] = Visibility;
|
||||
Item.Entity.VisibilitySources[this] = Visibility;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,9 +13,9 @@ public class ItemUsageData : BehaviorData
|
|||
[InspectableDatabaseLink(typeof(SimpleCommodityData)), JsonProperty("item"), Key(1), RuntimeInspectable]
|
||||
public Guid Item;
|
||||
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
public override IBehavior CreateInstance(EquippedItem item)
|
||||
{
|
||||
return new ItemUsage(context, this, entity, item);
|
||||
return new ItemUsage(this, item);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -23,23 +23,19 @@ public class ItemUsage : IBehavior
|
|||
{
|
||||
private ItemUsageData _data;
|
||||
|
||||
private Entity Entity { get; }
|
||||
private EquippedItem Item { get; }
|
||||
private ItemManager Context { get; }
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
public ItemUsage(ItemManager context, ItemUsageData data, Entity entity, EquippedItem item)
|
||||
public ItemUsage(ItemUsageData data, EquippedItem item)
|
||||
{
|
||||
_data = data;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
Context = context;
|
||||
}
|
||||
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
var cargo = Entity.FindItemInCargo(_data.Item);
|
||||
var cargo = Item.Entity.FindItemInCargo(_data.Item);
|
||||
if (cargo == null) return false;
|
||||
|
||||
var item = cargo.ItemsOfType[_data.Item][0];
|
||||
|
|
|
|||
|
|
@ -27,9 +27,9 @@ public class LauncherData : LockWeaponData
|
|||
[Inspectable, JsonProperty("missileSpeed"), Key(31), RuntimeInspectable]
|
||||
public PerformanceStat MissileVelocity = new PerformanceStat();
|
||||
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
public override IBehavior CreateInstance(EquippedItem item)
|
||||
{
|
||||
return new LockWeapon(context, this, entity, item);
|
||||
return new LockWeapon(this, item);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -54,8 +54,8 @@ public class GuidedWeaponData : InstantWeaponData
|
|||
[Inspectable, JsonProperty("missileSpeed"), Key(26), RuntimeInspectable]
|
||||
public PerformanceStat MissileVelocity = new PerformanceStat();
|
||||
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
public override IBehavior CreateInstance(EquippedItem item)
|
||||
{
|
||||
return new InstantWeapon(context, this, entity, item);
|
||||
return new InstantWeapon(this, item);
|
||||
}
|
||||
}
|
||||
|
|
@ -24,9 +24,9 @@ public class LockWeaponData : InstantWeaponData
|
|||
[Inspectable, JsonProperty("decay"), Key(25)]
|
||||
public PerformanceStat Decay = new PerformanceStat();
|
||||
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
public override IBehavior CreateInstance(EquippedItem item)
|
||||
{
|
||||
return new LockWeapon(context, this, entity, item);
|
||||
return new LockWeapon(this, item);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -49,27 +49,27 @@ public class LockWeapon : InstantWeapon
|
|||
|
||||
public override float Progress => saturate(_cooldown > 0 ? _cooldown : _lock);
|
||||
|
||||
public override bool CanFire => base.CanFire && _lock > .99f && Entity.TargetRange > MinRange && Entity.TargetRange < Range;
|
||||
public override bool CanFire => base.CanFire && _lock > .99f && Item.Entity.TargetRange > MinRange && Item.Entity.TargetRange < Range;
|
||||
|
||||
public float Lock
|
||||
{
|
||||
get => saturate(_lock);
|
||||
}
|
||||
|
||||
public LockWeapon(ItemManager context, LockWeaponData data, Entity entity, EquippedItem item) : base(context, data, entity, item)
|
||||
public LockWeapon(LockWeaponData data, EquippedItem item) : base(data, item)
|
||||
{
|
||||
_data = data;
|
||||
}
|
||||
|
||||
public override bool Execute(float delta)
|
||||
{
|
||||
if (_target != Entity.Target.Value)
|
||||
if (_target != Item.Entity.Target.Value)
|
||||
{
|
||||
_lock = 0;
|
||||
_target = Entity.Target.Value;
|
||||
_target = Item.Entity.Target.Value;
|
||||
}
|
||||
|
||||
if (Entity.Target.Value != null && Entity.Target.Value.IsHostileTo(Entity))
|
||||
if (Item.Entity.Target.Value != null && Item.Entity.Target.Value.IsHostileTo(Item.Entity))
|
||||
{
|
||||
LockSpeed = Item.Evaluate(_data.LockSpeed);
|
||||
SensorImpact = Item.Evaluate(_data.SensorImpact);
|
||||
|
|
@ -77,11 +77,11 @@ public class LockWeapon : InstantWeapon
|
|||
DirectionImpact = Item.Evaluate(_data.DirectionImpact);
|
||||
Decay = Item.Evaluate(_data.Decay);
|
||||
|
||||
var degrees = acos(dot(normalize(Entity.Target.Value.Position - Entity.Position), normalize(Entity.LookDirection))) * 57.2958f;
|
||||
var degrees = acos(dot(normalize(Item.Entity.Target.Value.Position - Item.Entity.Position), normalize(Item.Entity.LookDirection))) * 57.2958f;
|
||||
if (degrees < LockAngle)
|
||||
{
|
||||
var lerp = 1 - unlerp(0, 90, degrees);
|
||||
_lock = saturate(_lock + pow(lerp, DirectionImpact) * delta * LockSpeed * pow(Entity.EntityInfoGathered[Entity.Target.Value], SensorImpact));
|
||||
_lock = saturate(_lock + pow(lerp, DirectionImpact) * delta * LockSpeed * pow(Item.Entity.EntityInfoGathered[Item.Entity.Target.Value], SensorImpact));
|
||||
}
|
||||
else _lock = saturate(_lock - delta * Decay);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,9 +24,9 @@ public class MiningToolData : BehaviorData
|
|||
[Inspectable, JsonProperty("range"), Key(4)]
|
||||
public PerformanceStat Range = new PerformanceStat();
|
||||
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
public override IBehavior CreateInstance(EquippedItem item)
|
||||
{
|
||||
return new MiningTool(context, this, entity, item);
|
||||
return new MiningTool(this, item);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -37,31 +37,27 @@ public class MiningTool : IBehavior
|
|||
|
||||
private MiningToolData _data;
|
||||
|
||||
private Entity Entity { get; }
|
||||
private EquippedItem Item { get; }
|
||||
private ItemManager Context { get; }
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
public float Range { get; private set; }
|
||||
|
||||
public MiningTool(ItemManager context, MiningToolData data, Entity entity, EquippedItem item)
|
||||
public MiningTool(MiningToolData data, EquippedItem item)
|
||||
{
|
||||
_data = data;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
Context = context;
|
||||
}
|
||||
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
Range = Item.Evaluate(_data.Range);
|
||||
var belt = Entity.Zone.AsteroidBelts[AsteroidBelt];
|
||||
var belt = Item.Entity.Zone.AsteroidBelts[AsteroidBelt];
|
||||
if (AsteroidBelt != Guid.Empty &&
|
||||
Entity.Zone.AsteroidExists(AsteroidBelt, Asteroid) &&
|
||||
length(Entity.Position.xz - belt.Positions[Asteroid].xz) - belt.Scales[Asteroid] < Range)
|
||||
Item.Entity.Zone.AsteroidExists(AsteroidBelt, Asteroid) &&
|
||||
length(Item.Entity.Position.xz - belt.Positions[Asteroid].xz) - belt.Scales[Asteroid] < Range)
|
||||
{
|
||||
Entity.Zone.MineAsteroid(
|
||||
Entity,
|
||||
Item.Entity.Zone.MineAsteroid(
|
||||
Item.Entity,
|
||||
AsteroidBelt,
|
||||
Asteroid,
|
||||
Item.Evaluate(_data.DamagePerSecond) * delta,
|
||||
|
|
|
|||
|
|
@ -1,45 +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;
|
||||
using System.Linq;
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
[Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
|
||||
public class RadianceData : BehaviorData
|
||||
{
|
||||
[Inspectable, JsonProperty("radiance"), Key(1), RuntimeInspectable]
|
||||
public PerformanceStat Radiance = new PerformanceStat();
|
||||
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
{
|
||||
return new Radiance(context, this, entity, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class Radiance : IBehavior
|
||||
{
|
||||
private RadianceData _data;
|
||||
|
||||
private Entity Entity { get; }
|
||||
private EquippedItem Item { get; }
|
||||
private ItemManager Context { get; }
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
public Radiance(ItemManager context, RadianceData data, Entity entity, EquippedItem item)
|
||||
{
|
||||
_data = data;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
Context = context;
|
||||
}
|
||||
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
// TODO: Light system!
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1fbf8a3d31de89a4aa53d43e015536c7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -25,17 +25,15 @@ public class RadiatorData : BehaviorData
|
|||
[Inspectable, JsonProperty("energyUsage"), Key(5), RuntimeInspectable]
|
||||
public PerformanceStat EnergyUsage = new PerformanceStat();
|
||||
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
public override IBehavior CreateInstance(EquippedItem item)
|
||||
{
|
||||
return new Radiator(context, this, entity, item);
|
||||
return new Radiator(this, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class Radiator : IBehavior, IAlwaysUpdatedBehavior, IInitializableBehavior
|
||||
{
|
||||
public Entity Entity { get; }
|
||||
public EquippedItem Item { get; }
|
||||
public ItemManager Context { get; }
|
||||
public float Temperature { get; private set; }
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
|
|
@ -47,11 +45,9 @@ public class Radiator : IBehavior, IAlwaysUpdatedBehavior, IInitializableBehavio
|
|||
|
||||
private RadiatorData _data;
|
||||
|
||||
public Radiator(ItemManager context, RadiatorData data, Entity entity, EquippedItem item)
|
||||
public Radiator(RadiatorData data, EquippedItem item)
|
||||
{
|
||||
Context = context;
|
||||
_data = data;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
}
|
||||
|
||||
|
|
@ -67,7 +63,7 @@ public class Radiator : IBehavior, IAlwaysUpdatedBehavior, IInitializableBehavio
|
|||
// Temperature ratio would cause more waste heat than pump capacity, stop executing
|
||||
if (tempRatio > PumpedHeat / WasteHeat) return true;
|
||||
|
||||
if (!Entity.TryConsumeEnergy(EnergyUsage * tempRatio * delta)) return false;
|
||||
if (!Item.Entity.TryConsumeEnergy(EnergyUsage * tempRatio * delta)) return false;
|
||||
|
||||
var pumpedHeat = PumpedHeat * max(itemTemperature - _data.TemperatureFloor, 0);
|
||||
|
||||
|
|
@ -77,7 +73,7 @@ public class Radiator : IBehavior, IAlwaysUpdatedBehavior, IInitializableBehavio
|
|||
var wasteHeat = WasteHeat * tempRatio;
|
||||
|
||||
Item.AddHeat((wasteHeat - pumpedHeat) * delta);
|
||||
Temperature += pumpedHeat / Context.GetThermalMass(Item.EquippableItem) * delta;
|
||||
Temperature += pumpedHeat / Item.ItemManager.GetThermalMass(Item.EquippableItem) * delta;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -85,9 +81,9 @@ public class Radiator : IBehavior, IAlwaysUpdatedBehavior, IInitializableBehavio
|
|||
public void Update(float delta)
|
||||
{
|
||||
Emissivity = Item.Evaluate(_data.Emissivity);
|
||||
var rad = pow(Temperature, Context.GameplaySettings.HeatRadiationExponent) * Context.GameplaySettings.HeatRadiationMultiplier * Emissivity;
|
||||
var rad = pow(Temperature, Item.ItemManager.GameplaySettings.HeatRadiationExponent) * Item.ItemManager.GameplaySettings.HeatRadiationMultiplier * Emissivity;
|
||||
Temperature -= rad * delta;
|
||||
Entity.VisibilitySources[this] = rad;
|
||||
Item.Entity.VisibilitySources[this] = rad;
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
|
|
|
|||
|
|
@ -25,9 +25,9 @@ public class ReactorData : BehaviorData
|
|||
[Inspectable, JsonProperty("underload"), Key(4), RuntimeInspectable]
|
||||
public PerformanceStat ThrottlingFactor = new PerformanceStat();
|
||||
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
public override IBehavior CreateInstance(EquippedItem item)
|
||||
{
|
||||
return new Reactor(context, this, entity, item);
|
||||
return new Reactor(this, item);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -49,19 +49,17 @@ public class Reactor : IBehavior, IOrderedBehavior
|
|||
|
||||
private List<Capacitor> _capacitors;
|
||||
|
||||
public Reactor(ItemManager context, ReactorData data, Entity entity, EquippedItem item)
|
||||
public Reactor(ReactorData data, EquippedItem item)
|
||||
{
|
||||
Context = context;
|
||||
_data = data;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
_capacitors = entity.GetBehaviors<Capacitor>().ToList();
|
||||
entity.Equipment.ObserveAdd().Subscribe(onAdd =>
|
||||
_capacitors = Item.Entity.GetBehaviors<Capacitor>().ToList();
|
||||
Item.Entity.Equipment.ObserveAdd().Subscribe(onAdd =>
|
||||
{
|
||||
var capacitor = onAdd.Value.GetBehavior<Capacitor>();
|
||||
if (capacitor != null) _capacitors.Add(capacitor);
|
||||
});
|
||||
entity.Equipment.ObserveRemove().Subscribe(onRemove =>
|
||||
Item.Entity.Equipment.ObserveRemove().Subscribe(onRemove =>
|
||||
{
|
||||
var capacitor = onRemove.Value.GetBehavior<Capacitor>();
|
||||
if (capacitor != null) _capacitors.Remove(capacitor);
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ using Newtonsoft.Json;
|
|||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
[MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
|
||||
[Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
|
||||
public class ReflectorData : BehaviorData
|
||||
{
|
||||
[Inspectable, JsonProperty("crossSection"), Key(1), RuntimeInspectable]
|
||||
|
|
@ -16,33 +16,30 @@ public class ReflectorData : BehaviorData
|
|||
// [InspectableAnimationCurve, JsonProperty("visibility"), Key(1)]
|
||||
// public float4[] VisibilityCurve;
|
||||
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
public override IBehavior CreateInstance(EquippedItem item)
|
||||
{
|
||||
return new Reflector(context, this, entity, item);
|
||||
return new Reflector(this, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class Reflector : IBehavior
|
||||
{
|
||||
public Entity Entity { get; }
|
||||
public EquippedItem Item { get; }
|
||||
public ItemManager Context { get; }
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
private ReflectorData _data;
|
||||
|
||||
public Reflector(ItemManager context, ReflectorData data, Entity entity, EquippedItem item)
|
||||
public Reflector(ReflectorData data, EquippedItem item)
|
||||
{
|
||||
Context = context;
|
||||
_data = data;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
}
|
||||
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
// TODO: Light system!
|
||||
Item.Entity.VisibilitySources[this] = Item.Evaluate(_data.CrossSection) * Item.Entity.Zone.GetLight(Item.Entity.Position.xz);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -21,9 +21,9 @@ public class ResourceScannerData : BehaviorData
|
|||
[Inspectable, JsonProperty("scanDuration"), Key(3), RuntimeInspectable]
|
||||
public PerformanceStat ScanDuration = new PerformanceStat();
|
||||
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
public override IBehavior CreateInstance(EquippedItem item)
|
||||
{
|
||||
return new ResourceScanner(context, this, entity, item);
|
||||
return new ResourceScanner(this, item);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -35,9 +35,7 @@ public class ResourceScanner : IBehavior, IAlwaysUpdatedBehavior
|
|||
private float _scanTime;
|
||||
private Guid _scanTarget;
|
||||
|
||||
private Entity Entity { get; }
|
||||
private EquippedItem Item { get; }
|
||||
private ItemManager Context { get; }
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
public float Range { get; private set; }
|
||||
|
|
@ -57,24 +55,22 @@ public class ResourceScanner : IBehavior, IAlwaysUpdatedBehavior
|
|||
}
|
||||
}
|
||||
|
||||
public ResourceScanner(ItemManager context, ResourceScannerData data, Entity entity, EquippedItem item)
|
||||
public ResourceScanner(ResourceScannerData data, EquippedItem item)
|
||||
{
|
||||
_data = data;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
Context = context;
|
||||
}
|
||||
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
var planetData = Context.ItemData.Get<BodyData>(ScanTarget);
|
||||
var planetData = Item.Entity.Zone.Planets[ScanTarget];
|
||||
if (planetData != null)
|
||||
{
|
||||
if (planetData is AsteroidBeltData beltData)
|
||||
{
|
||||
if(Asteroid > -1 &&
|
||||
Asteroid < beltData.Asteroids.Length &&
|
||||
length(Entity.Position.xz - Entity.Zone.AsteroidBelts[ScanTarget].Positions[Asteroid].xz) < Range)
|
||||
length(Item.Entity.Position.xz - Item.Entity.Zone.AsteroidBelts[ScanTarget].Positions[Asteroid].xz) < Range)
|
||||
{
|
||||
_scanTime += delta;
|
||||
if (_scanTime > ScanDuration)
|
||||
|
|
@ -88,7 +84,7 @@ public class ResourceScanner : IBehavior, IAlwaysUpdatedBehavior
|
|||
}
|
||||
else
|
||||
{
|
||||
if(length(Entity.Position.xz - Entity.Zone.GetOrbitPosition(planetData.Orbit)) < Range)
|
||||
if(length(Item.Entity.Position.xz - Item.Entity.Zone.GetOrbitPosition(planetData.Orbit)) < Range)
|
||||
{
|
||||
_scanTime += delta;
|
||||
if (_scanTime > ScanDuration)
|
||||
|
|
|
|||
|
|
@ -39,9 +39,9 @@ public class SensorData : BehaviorData
|
|||
[Inspectable, JsonProperty("pingRadiusExponent"), Key(11)]
|
||||
public float PingRadiusExponent = .5f;
|
||||
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
public override IBehavior CreateInstance(EquippedItem item)
|
||||
{
|
||||
return new Sensor(context, this, entity, item);
|
||||
return new Sensor(this, item);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -54,9 +54,7 @@ public class Sensor : IBehavior, IEventBehavior
|
|||
private float _pingRadius;
|
||||
private HashSet<Entity> _pingedEntities = new HashSet<Entity>();
|
||||
|
||||
private Entity Entity { get; }
|
||||
private EquippedItem Item { get; }
|
||||
private ItemManager Context { get; }
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
|
|
@ -95,12 +93,10 @@ public class Sensor : IBehavior, IEventBehavior
|
|||
}
|
||||
}
|
||||
|
||||
public Sensor(ItemManager context, SensorData data, Entity entity, EquippedItem item)
|
||||
public Sensor(SensorData data, EquippedItem item)
|
||||
{
|
||||
_data = data;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
Context = context;
|
||||
}
|
||||
|
||||
public bool Execute(float delta)
|
||||
|
|
@ -119,42 +115,41 @@ public class Sensor : IBehavior, IEventBehavior
|
|||
_pingCooldown -= delta / Item.Evaluate(_data.PingCooldown);
|
||||
|
||||
// TODO: Handle Active Detection / Visibility From Reflected Radiance
|
||||
var hardpoint = Entity.Hardpoints[Item.Position.x, Item.Position.y];
|
||||
var forward = hardpoint != null && Entity.HardpointTransforms.ContainsKey(hardpoint) ?
|
||||
normalize(Entity.HardpointTransforms[hardpoint].direction.xz) :
|
||||
Entity.Direction;
|
||||
foreach (var entity in Entity.Zone.Entities)
|
||||
var hardpoint = Item.Entity.Hardpoints[Item.Position.x, Item.Position.y];
|
||||
var forward = hardpoint != null && Item.Entity.HardpointTransforms.ContainsKey(hardpoint) ?
|
||||
normalize(Item.Entity.HardpointTransforms[hardpoint].direction.xz) :
|
||||
Item.Entity.Direction;
|
||||
foreach (var entity in Item.Entity.Zone.Entities)
|
||||
{
|
||||
if(entity != Entity)
|
||||
if (entity == Item.Entity) continue;
|
||||
|
||||
var diff = entity.Position.xz - Item.Entity.Position.xz;
|
||||
var angle = acos(dot(forward, normalize(diff)));
|
||||
var dist = length(diff);
|
||||
float previous, next;
|
||||
Item.Entity.EntityInfoGathered.TryGetValue(entity, out previous);
|
||||
if (!_pingedEntities.Contains(entity) && dist < _pingRadius)
|
||||
{
|
||||
var diff = entity.Position.xz - Entity.Position.xz;
|
||||
var angle = acos(dot(forward, normalize(diff)));
|
||||
var dist = length(diff);
|
||||
float previous, next;
|
||||
Entity.EntityInfoGathered.TryGetValue(entity, out previous);
|
||||
if (!_pingedEntities.Contains(entity) && dist < _pingRadius)
|
||||
{
|
||||
_pingedEntities.Add(entity);
|
||||
next = saturate(
|
||||
previous +
|
||||
entity.Visibility *
|
||||
Item.Evaluate(_data.Sensitivity) *
|
||||
Item.Evaluate(_data.PingBoost) *
|
||||
dist);
|
||||
}
|
||||
else
|
||||
{
|
||||
next = saturate(
|
||||
previous +
|
||||
entity.Visibility *
|
||||
Item.Evaluate(_data.Sensitivity) *
|
||||
_data.SensitivityCurve.Evaluate(angle / PI) *
|
||||
delta / dist);
|
||||
}
|
||||
next *= 1 - Context.GameplaySettings.TargetInfoDecay * delta;
|
||||
//Context.Log($"{entity.Name} visibility {(int)(previous * 100)}% -> {(int)(next * 100)}%");
|
||||
Entity.EntityInfoGathered[entity] = next;
|
||||
_pingedEntities.Add(entity);
|
||||
next = saturate(
|
||||
previous +
|
||||
entity.Visibility *
|
||||
Item.Evaluate(_data.Sensitivity) *
|
||||
Item.Evaluate(_data.PingBoost) *
|
||||
dist);
|
||||
}
|
||||
else
|
||||
{
|
||||
next = saturate(
|
||||
previous +
|
||||
entity.Visibility *
|
||||
Item.Evaluate(_data.Sensitivity) *
|
||||
_data.SensitivityCurve.Evaluate(angle / PI) *
|
||||
delta / dist);
|
||||
}
|
||||
next *= 1 - Item.ItemManager.GameplaySettings.TargetInfoDecay * delta;
|
||||
//Context.Log($"{entity.Name} visibility {(int)(previous * 100)}% -> {(int)(next * 100)}%");
|
||||
Item.Entity.EntityInfoGathered[entity] = next;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,17 +16,15 @@ public class ShieldData : BehaviorData
|
|||
[Inspectable, JsonProperty("energy"), Key(2), RuntimeInspectable]
|
||||
public PerformanceStat EnergyUsage = new PerformanceStat();
|
||||
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
public override IBehavior CreateInstance(EquippedItem item)
|
||||
{
|
||||
return new Shield(context, this, entity, item);
|
||||
return new Shield(this, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class Shield : IBehavior
|
||||
{
|
||||
public Entity Entity { get; }
|
||||
public EquippedItem Item { get; }
|
||||
public ItemManager Context { get; }
|
||||
|
||||
public float Efficiency { get; private set; }
|
||||
public float EnergyUsage { get; private set; }
|
||||
|
|
@ -35,11 +33,9 @@ public class Shield : IBehavior
|
|||
|
||||
private ShieldData _data;
|
||||
|
||||
public Shield(ItemManager context, ShieldData data, Entity entity, EquippedItem item)
|
||||
public Shield(ShieldData data, EquippedItem item)
|
||||
{
|
||||
Context = context;
|
||||
_data = data;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
}
|
||||
|
||||
|
|
@ -52,12 +48,12 @@ public class Shield : IBehavior
|
|||
|
||||
public bool CanTakeHit(DamageType type, float damage)
|
||||
{
|
||||
return Entity.CanConsumeEnergy(damage * EnergyUsage);
|
||||
return Item.Entity.CanConsumeEnergy(damage * EnergyUsage);
|
||||
}
|
||||
|
||||
public void TakeHit(DamageType type, float damage)
|
||||
{
|
||||
Entity.TryConsumeEnergy(damage * EnergyUsage);
|
||||
Item.Entity.TryConsumeEnergy(damage * EnergyUsage);
|
||||
Item.AddHeat(damage / Efficiency);
|
||||
}
|
||||
}
|
||||
|
|
@ -22,9 +22,9 @@ public class StatModifierData : BehaviorData
|
|||
[InspectableType(typeof(BehaviorData)), JsonProperty("requireBehavior"), Key(4)]
|
||||
public Type RequireBehavior;
|
||||
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
public override IBehavior CreateInstance(EquippedItem item)
|
||||
{
|
||||
return new StatModifier(context, this, entity, item);
|
||||
return new StatModifier(this, item);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -32,9 +32,7 @@ public class StatModifierData : BehaviorData
|
|||
public class StatModifier : IBehavior, IInitializableBehavior, IDisposableBehavior
|
||||
{
|
||||
private StatModifierData _data;
|
||||
private Entity Entity { get; }
|
||||
private EquippedItem Item { get; }
|
||||
private ItemManager Context { get; }
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
|
|
@ -45,12 +43,10 @@ public class StatModifier : IBehavior, IInitializableBehavior, IDisposableBehavi
|
|||
private static Type[] StatObjects => _statObjects = _statObjects ?? typeof(BehaviorData).GetAllChildClasses()
|
||||
.Concat(typeof(EquippableItemData).GetAllChildClasses()).ToArray();
|
||||
|
||||
public StatModifier(ItemManager context, StatModifierData data, Entity entity, EquippedItem item)
|
||||
public StatModifier(StatModifierData data, EquippedItem item)
|
||||
{
|
||||
_data = data;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
Context = context;
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
|
|
@ -63,17 +59,17 @@ public class StatModifier : IBehavior, IInitializableBehavior, IDisposableBehavi
|
|||
if (statField != null)
|
||||
{
|
||||
if (typeof(EquippableItemData).IsAssignableFrom(targetType))
|
||||
_stats = Entity.Equipment
|
||||
_stats = Item.Entity.Equipment
|
||||
.Select(hp => hp.EquippableItem)
|
||||
.Where(gear => _data.RequireBehavior == null || Context.GetData(gear).Behaviors.Any(behavior => behavior.GetType() == _data.RequireBehavior))
|
||||
.Where(gear => Context.GetData(gear).GetType() == targetType)
|
||||
.Select(gear => statField.GetValue(Context.GetData(gear)) as PerformanceStat)
|
||||
.Where(gear => _data.RequireBehavior == null || Item.ItemManager.GetData(gear).Behaviors.Any(behavior => behavior.GetType() == _data.RequireBehavior))
|
||||
.Where(gear => Item.ItemManager.GetData(gear).GetType() == targetType)
|
||||
.Select(gear => statField.GetValue(Item.ItemManager.GetData(gear)) as PerformanceStat)
|
||||
.ToArray();
|
||||
else
|
||||
_stats = Entity.Equipment
|
||||
_stats = Item.Entity.Equipment
|
||||
.Select(hp => hp.EquippableItem)
|
||||
.Where(gear => _data.RequireBehavior == null || Context.GetData(gear).Behaviors.Any(behavior => behavior.GetType() == _data.RequireBehavior))
|
||||
.SelectMany(gear => Context.GetData(gear).Behaviors)
|
||||
.Where(gear => _data.RequireBehavior == null || Item.ItemManager.GetData(gear).Behaviors.Any(behavior => behavior.GetType() == _data.RequireBehavior))
|
||||
.SelectMany(gear => Item.ItemManager.GetData(gear).Behaviors)
|
||||
.Where(behaviorData => behaviorData.GetType() == targetType)
|
||||
.Select(behaviorData => statField.GetValue(behaviorData) as PerformanceStat)
|
||||
.ToArray();
|
||||
|
|
@ -85,15 +81,15 @@ public class StatModifier : IBehavior, IInitializableBehavior, IDisposableBehavi
|
|||
{
|
||||
foreach (var stat in _stats)
|
||||
(_data.Type == StatModifierType.Constant
|
||||
? stat.GetConstantModifiers(Entity)
|
||||
: stat.GetScaleModifiers(Entity))[this] = Item.Evaluate(_data.Modifier);
|
||||
? stat.GetConstantModifiers(Item.Entity)
|
||||
: stat.GetScaleModifiers(Item.Entity))[this] = Item.Evaluate(_data.Modifier);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
foreach (var stat in _stats)
|
||||
(_data.Type == StatModifierType.Constant ? stat.GetConstantModifiers(Entity) : stat.GetScaleModifiers(Entity)).Remove(this);
|
||||
(_data.Type == StatModifierType.Constant ? stat.GetConstantModifiers(Item.Entity) : stat.GetScaleModifiers(Item.Entity)).Remove(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@ using Newtonsoft.Json;
|
|||
[Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(-25)]
|
||||
public class SwitchData : BehaviorData
|
||||
{
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
public override IBehavior CreateInstance(EquippedItem item)
|
||||
{
|
||||
return new Switch(context, this, entity, item);
|
||||
return new Switch(this, item);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -20,20 +20,16 @@ public class Switch : IBehavior
|
|||
{
|
||||
private SwitchData _data;
|
||||
|
||||
private Entity Entity { get; }
|
||||
private EquippedItem Item { get; }
|
||||
private ItemManager Context { get; }
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
public bool Activated { get; set; }
|
||||
|
||||
public Switch(ItemManager context, SwitchData data, Entity entity, EquippedItem item)
|
||||
public Switch(SwitchData data, EquippedItem item)
|
||||
{
|
||||
_data = data;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
Context = context;
|
||||
}
|
||||
|
||||
public bool Execute(float delta)
|
||||
|
|
|
|||
|
|
@ -15,10 +15,13 @@ public class ThermotoggleData : BehaviorData
|
|||
|
||||
[Inspectable, JsonProperty("highPass"), Key(2)]
|
||||
public bool HighPass;
|
||||
|
||||
[Inspectable, JsonProperty("adjustable"), Key(3)]
|
||||
public bool Adjustable;
|
||||
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
public override IBehavior CreateInstance(EquippedItem item)
|
||||
{
|
||||
return new Thermotoggle(context, this, entity, item);
|
||||
return new Thermotoggle(this, item);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -27,18 +30,15 @@ public class Thermotoggle : IBehavior
|
|||
public float TargetTemperature;
|
||||
private ThermotoggleData _data;
|
||||
|
||||
private Entity Entity { get; }
|
||||
private EquippedItem Item { get; }
|
||||
private ItemManager Context { get; }
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
public ThermotoggleData ThermotoggleData => _data;
|
||||
|
||||
public Thermotoggle(ItemManager context, ThermotoggleData data, Entity entity, EquippedItem item)
|
||||
public Thermotoggle(ThermotoggleData data, EquippedItem item)
|
||||
{
|
||||
_data = data;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
Context = context;
|
||||
TargetTemperature = data.TargetTemperature;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,17 +25,15 @@ public class ThrusterData : BehaviorData
|
|||
[InspectablePrefab, JsonProperty("Particles"), Key(5)]
|
||||
public string ParticlesPrefab;
|
||||
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
public override IBehavior CreateInstance(EquippedItem item)
|
||||
{
|
||||
return new Thruster(context, this, entity, item);
|
||||
return new Thruster(this, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class Thruster : IAnalogBehavior
|
||||
{
|
||||
public Entity Entity { get; }
|
||||
public EquippedItem Item { get; }
|
||||
public ItemManager Context { get; }
|
||||
|
||||
public float Thrust { get; private set; }
|
||||
public float Torque { get; }
|
||||
|
|
@ -52,15 +50,13 @@ public class Thruster : IAnalogBehavior
|
|||
|
||||
private float _input;
|
||||
|
||||
public Thruster(ItemManager context, ThrusterData data, Entity entity, EquippedItem item)
|
||||
public Thruster(ThrusterData data, EquippedItem item)
|
||||
{
|
||||
Context = context;
|
||||
_data = data;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
var hullData = context.GetData(entity.Hull) as HullData;
|
||||
var hullData = Item.ItemManager.GetData(Item.Entity.Hull) as HullData;
|
||||
var hullCenter = hullData.Shape.CenterOfMass;
|
||||
var itemData = context.GetData(item.EquippableItem);
|
||||
var itemData = Item.ItemManager.GetData(item.EquippableItem);
|
||||
var itemCenter = hullData.Shape.Inset(itemData.Shape, item.Position, item.EquippableItem.Rotation).CenterOfMass;
|
||||
var toCenter = hullCenter - itemCenter;
|
||||
Torque = -dot(normalize(toCenter), float2(1, 0).Rotate(item.EquippableItem.Rotation));
|
||||
|
|
@ -72,13 +68,13 @@ public class Thruster : IAnalogBehavior
|
|||
if(_input > .01f && Item.Entity.TryConsumeEnergy(_input * Item.Evaluate(_data.EnergyUsage)))
|
||||
{
|
||||
Thrust = Item.Evaluate(_data.Thrust);
|
||||
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.Entity.Velocity -= Item.Entity.Direction.Rotate(Item.EquippableItem.Rotation) * _input * Thrust / Item.Entity.Mass * delta;
|
||||
Item.Entity.Direction = mul(Item.Entity.Direction,
|
||||
Unity.Mathematics.float2x2.Rotate(_input * Torque * Thrust * Item.ItemManager.GameplaySettings.TorqueMultiplier / Item.Entity.Mass * delta));
|
||||
Item.AddHeat(_input * Item.Evaluate(_data.Heat) * delta);
|
||||
var vis = _input * Item.Evaluate(_data.Visibility);
|
||||
if (!Entity.VisibilitySources.ContainsKey(this) || vis > Entity.VisibilitySources[this])
|
||||
Entity.VisibilitySources[this] = vis;
|
||||
if (!Item.Entity.VisibilitySources.ContainsKey(this) || vis > Item.Entity.VisibilitySources[this])
|
||||
Item.Entity.VisibilitySources[this] = vis;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@ using Newtonsoft.Json;
|
|||
[Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(-20)]
|
||||
public class TriggerData : BehaviorData
|
||||
{
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
public override IBehavior CreateInstance(EquippedItem item)
|
||||
{
|
||||
return new Trigger(context, this, entity, item);
|
||||
return new Trigger(this, item);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -20,24 +20,16 @@ public class Trigger : IBehavior, IActivatedBehavior
|
|||
{
|
||||
private TriggerData _data;
|
||||
|
||||
public Entity Entity { get; }
|
||||
public EquippedItem Item { get; }
|
||||
public ItemManager Context { get; }
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
public bool _pulled;
|
||||
|
||||
public Trigger(ItemManager context, TriggerData data, Entity entity, EquippedItem item)
|
||||
public Trigger(TriggerData data, EquippedItem item)
|
||||
{
|
||||
_data = data;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
Context = context;
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
}
|
||||
|
||||
public bool Execute(float delta)
|
||||
|
|
|
|||
|
|
@ -14,9 +14,9 @@ using float3 = Unity.Mathematics.float3;
|
|||
[MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
|
||||
public class TurretControllerData : BehaviorData
|
||||
{
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
public override IBehavior CreateInstance(EquippedItem item)
|
||||
{
|
||||
return new TurretController(context, this, entity, item);
|
||||
return new TurretController(this, item);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -27,26 +27,22 @@ public class TurretController : IBehavior
|
|||
private float _shotSpeed;
|
||||
private bool _predictShots;
|
||||
|
||||
public Entity EquippedEntity { get; }
|
||||
public EquippedItem Item { get; }
|
||||
public ItemManager Context { get; }
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
public TurretController(ItemManager context, TurretControllerData data, Entity equippedEntity, EquippedItem item)
|
||||
public TurretController(TurretControllerData data, EquippedItem item)
|
||||
{
|
||||
Context = context;
|
||||
_data = data;
|
||||
EquippedEntity = equippedEntity;
|
||||
Item = item;
|
||||
var weapons = equippedEntity.Equipment.Where(e => e.Behaviors.Any(b => b.Data is WeaponData));
|
||||
var weapons = Item.Entity.Equipment.Where(e => e.Behaviors.Any(b => b.Data is WeaponData));
|
||||
foreach (var weapon in weapons)
|
||||
{
|
||||
CheckWeapon(weapon);
|
||||
}
|
||||
|
||||
equippedEntity.Equipment.ObserveAdd().Subscribe(add => CheckWeapon(add.Value));
|
||||
equippedEntity.Equipment.ObserveRemove().Subscribe(remove =>
|
||||
Item.Entity.Equipment.ObserveAdd().Subscribe(add => CheckWeapon(add.Value));
|
||||
Item.Entity.Equipment.ObserveRemove().Subscribe(remove =>
|
||||
{
|
||||
foreach (var b in remove.Value.Behaviors)
|
||||
if (b is Weapon weapon)
|
||||
|
|
@ -71,30 +67,30 @@ public class TurretController : IBehavior
|
|||
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
if (EquippedEntity.Target.Value != null)
|
||||
if (Item.Entity.Target.Value != null)
|
||||
{
|
||||
var diff = EquippedEntity.Target.Value.Position - EquippedEntity.Position;
|
||||
var diff = Item.Entity.Target.Value.Position - Item.Entity.Position;
|
||||
if (_predictShots)
|
||||
{
|
||||
var targetHullData = EquippedEntity.ItemManager.GetData(EquippedEntity.Target.Value.Hull) as HullData;
|
||||
var targetVelocity = float3(EquippedEntity.Target.Value.Velocity.x, 0, EquippedEntity.Target.Value.Velocity.y);
|
||||
var targetHullData = Item.Entity.ItemManager.GetData(Item.Entity.Target.Value.Hull) as HullData;
|
||||
var targetVelocity = float3(Item.Entity.Target.Value.Velocity.x, 0, Item.Entity.Target.Value.Velocity.y);
|
||||
var predictedPosition = AetheriaMath.FirstOrderIntercept(
|
||||
EquippedEntity.Position, float3.zero, _shotSpeed,
|
||||
EquippedEntity.Target.Value.Position, targetVelocity
|
||||
Item.Entity.Position, float3.zero, _shotSpeed,
|
||||
Item.Entity.Target.Value.Position, targetVelocity
|
||||
);
|
||||
predictedPosition.y = EquippedEntity.Zone.GetHeight(predictedPosition.xz) + targetHullData.GridOffset;
|
||||
EquippedEntity.LookDirection = normalize(predictedPosition - EquippedEntity.Position);
|
||||
predictedPosition.y = Item.Entity.Zone.GetHeight(predictedPosition.xz) + targetHullData.GridOffset;
|
||||
Item.Entity.LookDirection = normalize(predictedPosition - Item.Entity.Position);
|
||||
}
|
||||
else
|
||||
EquippedEntity.LookDirection = normalize(diff);
|
||||
Item.Entity.LookDirection = normalize(diff);
|
||||
var dist = length(diff);
|
||||
|
||||
foreach (var x in _weapons)
|
||||
{
|
||||
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;
|
||||
Item.Entity.HardpointTransforms[Item.Entity.Hardpoints[x.Item.Position.x, x.Item.Position.y]].direction,
|
||||
Item.Entity.LookDirection) > .99f;
|
||||
if (x.Item.Evaluate(data.Range) > dist && fire)
|
||||
{
|
||||
x.Activate();
|
||||
|
|
@ -110,7 +106,7 @@ public class TurretController : IBehavior
|
|||
if (x.Firing)
|
||||
x.Deactivate();
|
||||
}
|
||||
EquippedEntity.Target.Value = EquippedEntity.VisibleHostiles.FirstOrDefault(e => e is Ship);
|
||||
Item.Entity.Target.Value = Item.Entity.VisibleHostiles.FirstOrDefault(e => e is Ship);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,40 +13,28 @@ public class VelocityConversionData : BehaviorData
|
|||
[Inspectable, JsonProperty("traction"), Key(1), RuntimeInspectable]
|
||||
public PerformanceStat Traction = new PerformanceStat();
|
||||
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
public override IBehavior CreateInstance(EquippedItem item)
|
||||
{
|
||||
return new VelocityConversion(context, this, entity, item);
|
||||
return new VelocityConversion(this, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class VelocityConversion : IBehavior
|
||||
{
|
||||
public Entity Entity { get; }
|
||||
public EquippedItem Item { get; }
|
||||
public ItemManager Context { get; }
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
private VelocityConversionData _data;
|
||||
|
||||
public VelocityConversion(ItemManager context, VelocityConversionData data, Entity entity, EquippedItem item)
|
||||
public VelocityConversion(VelocityConversionData data, EquippedItem item)
|
||||
{
|
||||
Context = context;
|
||||
_data = data;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
}
|
||||
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Remove()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -7,24 +7,22 @@ using Newtonsoft.Json;
|
|||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
[MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
|
||||
[Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
|
||||
public class VelocityLimitData : BehaviorData
|
||||
{
|
||||
[Inspectable, JsonProperty("topSpeed"), Key(1), RuntimeInspectable]
|
||||
public PerformanceStat TopSpeed = new PerformanceStat();
|
||||
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
public override IBehavior CreateInstance(EquippedItem item)
|
||||
{
|
||||
return new VelocityLimit(context, this, entity, item);
|
||||
return new VelocityLimit(this, item);
|
||||
}
|
||||
}
|
||||
|
||||
[Order(100)]
|
||||
public class VelocityLimit : IBehavior
|
||||
{
|
||||
public Entity Entity { get; }
|
||||
public EquippedItem Item { get; }
|
||||
public ItemManager Context { get; }
|
||||
|
||||
public float Limit { get; private set; }
|
||||
|
||||
|
|
@ -32,28 +30,18 @@ public class VelocityLimit : IBehavior
|
|||
|
||||
private VelocityLimitData _data;
|
||||
|
||||
public VelocityLimit(ItemManager context, VelocityLimitData data, Entity entity, EquippedItem item)
|
||||
public VelocityLimit(VelocityLimitData data, EquippedItem item)
|
||||
{
|
||||
Context = context;
|
||||
_data = data;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
Limit = Item.Evaluate(_data.TopSpeed);
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
}
|
||||
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
Limit = Item.Evaluate(_data.TopSpeed);
|
||||
if (length(Entity.Velocity) > Limit)
|
||||
Entity.Velocity = normalize(Entity.Velocity) * Limit;
|
||||
if (length(Item.Entity.Velocity) > Limit)
|
||||
Item.Entity.Velocity = normalize(Item.Entity.Velocity) * Limit;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Remove()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -16,44 +16,31 @@ public class VisibilityData : BehaviorData
|
|||
[Inspectable, JsonProperty("visibilityDecay"), Key(2)]
|
||||
public PerformanceStat VisibilityDecay = new PerformanceStat();
|
||||
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
public override IBehavior CreateInstance(EquippedItem item)
|
||||
{
|
||||
return new Visibility(context, this, entity, item);
|
||||
return new Visibility(this, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class Visibility : IBehavior, IAlwaysUpdatedBehavior
|
||||
public class Visibility : IBehavior
|
||||
{
|
||||
private VisibilityData _data;
|
||||
|
||||
private Entity Entity { get; }
|
||||
private EquippedItem Item { get; }
|
||||
private ItemManager Context { get; }
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
private float _cooldown; // Normalized
|
||||
|
||||
public Visibility(ItemManager context, VisibilityData data, Entity entity, EquippedItem item)
|
||||
public Visibility(VisibilityData data, EquippedItem item)
|
||||
{
|
||||
_data = data;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
Context = context;
|
||||
}
|
||||
|
||||
public bool Execute(float delta)
|
||||
{
|
||||
Entity.VisibilitySources[this] = Item.Evaluate(_data.Visibility);
|
||||
Item.Entity.VisibilitySources[this] = Item.Evaluate(_data.Visibility);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Update(float delta)
|
||||
{
|
||||
// TODO: Time independent decay?
|
||||
if(Entity.VisibilitySources.ContainsKey(this))
|
||||
{
|
||||
Entity.VisibilitySources[this] *= Item.Evaluate(_data.VisibilityDecay);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -70,11 +70,8 @@ public abstract class WeaponData : BehaviorData
|
|||
public abstract class Weapon : IActivatedBehavior
|
||||
{
|
||||
private WeaponData _data;
|
||||
private EquippableItemData _itemData;
|
||||
|
||||
public Entity Entity { get; }
|
||||
public EquippedItem Item { get; }
|
||||
public ItemManager Context { get; }
|
||||
|
||||
public abstract float DamagePerSecond { get; }
|
||||
public abstract float RangeDamagePerSecond(float range);
|
||||
|
|
@ -101,13 +98,10 @@ public abstract class Weapon : IActivatedBehavior
|
|||
}
|
||||
|
||||
|
||||
public Weapon(ItemManager context, WeaponData data, Entity entity, EquippedItem item)
|
||||
public Weapon(WeaponData data, EquippedItem item)
|
||||
{
|
||||
Context = context;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
_data = data;
|
||||
_itemData = context.GetData(item.EquippableItem);
|
||||
}
|
||||
|
||||
protected virtual void UpdateStats()
|
||||
|
|
|
|||
|
|
@ -14,30 +14,24 @@ public class WearData : BehaviorData
|
|||
[InspectableTemperature, JsonProperty("perSecond"), Key(1)]
|
||||
public bool PerSecond = true;
|
||||
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
public override IBehavior CreateInstance(EquippedItem item)
|
||||
{
|
||||
return new Wear(context, this, entity, item);
|
||||
return new Wear(this, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class Wear : IBehavior
|
||||
{
|
||||
private WearData _data;
|
||||
private EquippableItemData _itemData;
|
||||
|
||||
public Entity Entity { get; }
|
||||
public EquippedItem Item { get; }
|
||||
public ItemManager Context { get; }
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
public Wear(ItemManager context, WearData data, Entity entity, EquippedItem item)
|
||||
public Wear(WearData data, EquippedItem item)
|
||||
{
|
||||
Context = context;
|
||||
_data = data;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
_itemData = context.GetData(item.EquippableItem);
|
||||
}
|
||||
|
||||
public bool Execute(float delta)
|
||||
|
|
|
|||
|
|
@ -764,9 +764,9 @@ public abstract class Entity
|
|||
|
||||
foreach (var v in VisibilitySources.Keys.ToArray())
|
||||
{
|
||||
VisibilitySources[v] *= max(1 - ItemManager.GameplaySettings.VisibilityDecay * delta, 0);
|
||||
VisibilitySources[v] = AetheriaMath.Decay(VisibilitySources[v], ItemManager.GameplaySettings.VisibilityDecay, delta);
|
||||
|
||||
if (VisibilitySources[v] < 0.01f) VisibilitySources.Remove(v);
|
||||
if (VisibilitySources[v] < 0.1f) VisibilitySources.Remove(v);
|
||||
}
|
||||
|
||||
UpdateTemperature(delta);
|
||||
|
|
@ -998,7 +998,7 @@ public class EquippedItem
|
|||
|
||||
|
||||
Behaviors = Data.Behaviors
|
||||
.Select(bd => bd.CreateInstance(itemManager, entity, this))
|
||||
.Select(bd => bd.CreateInstance(this))
|
||||
.ToArray();
|
||||
|
||||
BehaviorGroups = Behaviors
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ public class PlanetSettings
|
|||
public ExponentialCurve WaveRadius;
|
||||
public ExponentialCurve WaveFrequency;
|
||||
public ExponentialCurve WaveSpeed;
|
||||
public ExponentialCurve FogTintRadius;
|
||||
public ExponentialCurve LightRadius;
|
||||
public ExponentialCurve BodyRadius;
|
||||
public float AsteroidVerticalOffset = -5f;
|
||||
|
|
|
|||
|
|
@ -65,6 +65,9 @@ public class Zone
|
|||
case AsteroidBeltData belt:
|
||||
AsteroidBelts[belt.ID] = new AsteroidBelt(belt);
|
||||
break;
|
||||
case SunData sun:
|
||||
PlanetInstances.Add(sun.ID, new Sun(settings, sun, Orbits[planet.Orbit]));
|
||||
break;
|
||||
case GasGiantData gas:
|
||||
PlanetInstances.Add(gas.ID, new GasGiant(settings, gas, Orbits[planet.Orbit]));
|
||||
break;
|
||||
|
|
@ -305,7 +308,7 @@ public class Zone
|
|||
}
|
||||
public float GetHeight(float2 position)
|
||||
{
|
||||
float result = -PowerPulse(length(position)/(Pack.Radius*2), Settings.ZoneDepthExponent) * Settings.ZoneDepth;
|
||||
var result = -PowerPulse(length(position)/(Pack.Radius*2), Settings.ZoneDepthExponent) * Settings.ZoneDepth;
|
||||
foreach (var body in PlanetInstances.Values)
|
||||
{
|
||||
var p = position - body.Orbit.Position; //GetOrbitPosition(body.BodyData.Orbit)
|
||||
|
|
@ -333,6 +336,26 @@ public class Zone
|
|||
return result;
|
||||
}
|
||||
|
||||
public float GetLight(float2 position)
|
||||
{
|
||||
var light = 0f;
|
||||
foreach (var body in PlanetInstances.Values)
|
||||
{
|
||||
if (body is Sun sun)
|
||||
{
|
||||
var p = position - body.Orbit.Position;
|
||||
var distSqr = lengthsq(p);
|
||||
var lightRadius = sun.LightRadius.Value;
|
||||
if (distSqr < lightRadius * lightRadius)
|
||||
{
|
||||
light += PowerPulse(sqrt(distSqr) / lightRadius, 8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return light;
|
||||
}
|
||||
|
||||
public float2 GetForce(float2 position)
|
||||
{
|
||||
var normal = GetNormal(position);
|
||||
|
|
@ -412,10 +435,17 @@ public class GasGiant : Planet
|
|||
}
|
||||
}
|
||||
|
||||
// public class Sun : GasGiant
|
||||
// {
|
||||
//
|
||||
// }
|
||||
public class Sun : GasGiant
|
||||
{
|
||||
public ReadOnlyReactiveProperty<float> LightRadius;
|
||||
|
||||
public Sun(PlanetSettings settings, SunData data, Orbit orbit) : base(settings, data, orbit)
|
||||
{
|
||||
LightRadius = new ReadOnlyReactiveProperty<float>(
|
||||
data.Mass.CombineLatest(data.LightRadiusMultiplier,
|
||||
(mass, radius) => settings.LightRadius.Evaluate(mass) * radius));
|
||||
}
|
||||
}
|
||||
|
||||
public class AsteroidBelt
|
||||
{
|
||||
|
|
|
|||
|
|
@ -163,6 +163,9 @@ public class SunData : GasGiantData
|
|||
|
||||
[JsonProperty("fogTintColor"), Key(21)]
|
||||
public ReactiveProperty<float3> FogTintColor = new ReactiveProperty<float3>(float3.zero);
|
||||
|
||||
[JsonProperty("lightRadiusMul")] [Key(22)]
|
||||
public ReactiveProperty<float> LightRadiusMultiplier = new ReactiveProperty<float>(1);
|
||||
}
|
||||
|
||||
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
|
|
|
|||
Loading…
Reference in a new issue