From 4b10923448b2a41db3258549006336297ab5703f Mon Sep 17 00:00:00 2001 From: Reinier Vens Date: Thu, 4 Mar 2021 03:58:46 +0000 Subject: [PATCH] Heat Performance Curves + Wear & Tear Added heat variation option for Performance Stats Ability to toggle radiators on/off using H key Item durability loss (Wear) is now heat dependent and incurred only when used Restricted equip/unequip to docked (inactive) entities Fixed race condition causing exceptions in database sync code --- .../.idea/contentModel.xml | 5 +- .../.idea.Aetheria-Economy/.idea/modules.xml | 2 +- ...eria-Economy_WwiseProject.rwvens.wsettings | 2 +- Assets/Materials/UI/Map Gravity Lines.mat | 2 +- Assets/Resources/Aetheria.inputactions | 19 +++ Assets/Scenes/ARPG.unity | 8 +- Assets/Scripts/AetheriaInput.cs | 29 +++++ Assets/Scripts/Editor/DatabaseInspector.cs | 6 +- Assets/Scripts/Gameplay/ActionGameManager.cs | 6 + .../Gameplay/Weapons/ConstantLaserManager.cs | 8 +- .../Weapons/ConstantLightningManager.cs | 8 +- .../Weapons/ConstantParticleWeaponManager.cs | 2 +- .../Weapons/GuidedProjectileManager.cs | 8 +- .../ServerShared/Agents/States/Combat.cs | 4 +- .../ServerShared/Behaviors/Capacitor.cs | 4 +- .../ServerShared/Behaviors/ChargedWeapon.cs | 6 +- .../ServerShared/Behaviors/ConstantWeapon.cs | 9 +- .../ServerShared/Behaviors/Cooldown.cs | 2 +- .../ServerShared/Behaviors/EnergyDraw.cs | 4 +- Assets/Scripts/ServerShared/Behaviors/Heat.cs | 2 +- .../ServerShared/Behaviors/InstantWeapon.cs | 7 +- .../ServerShared/Behaviors/LockWeapon.cs | 10 +- .../ServerShared/Behaviors/MiningTool.cs | 8 +- .../ServerShared/Behaviors/Radiator.cs | 8 +- .../Scripts/ServerShared/Behaviors/Reactor.cs | 8 +- .../ServerShared/Behaviors/ResourceScanner.cs | 6 +- .../Scripts/ServerShared/Behaviors/Sensor.cs | 2 +- .../ServerShared/Behaviors/StatModifier.cs | 2 +- .../ServerShared/Behaviors/Thruster.cs | 8 +- .../Behaviors/TurretController.cs | 4 +- .../ServerShared/Behaviors/VelocityLimit.cs | 2 +- .../ServerShared/Behaviors/Visibility.cs | 4 +- .../Scripts/ServerShared/Behaviors/Weapon.cs | 24 ++-- Assets/Scripts/ServerShared/Behaviors/Wear.cs | 50 ++++++++ .../ServerShared/Behaviors/Wear.cs.meta | 3 + Assets/Scripts/ServerShared/DatabaseCache.cs | 49 ++++---- Assets/Scripts/ServerShared/Entity.cs | 111 +++++++++++++----- Assets/Scripts/ServerShared/ItemData.cs | 64 ++++++++-- Assets/Scripts/ServerShared/ItemManager.cs | 16 +-- Assets/Scripts/UI/InventoryMenu.cs | 72 +++++++----- Assets/Scripts/UI/InventoryPanel.cs | 15 +++ Assets/Scripts/UI/PropertiesPanel.cs | 2 +- Assets/Scripts/UI/SchematicDisplay.cs | 9 +- Economy.Shared.Unity.csproj | 1 + 44 files changed, 437 insertions(+), 184 deletions(-) create mode 100644 Assets/Scripts/ServerShared/Behaviors/Wear.cs create mode 100644 Assets/Scripts/ServerShared/Behaviors/Wear.cs.meta diff --git a/.idea/.idea.Aetheria-Economy/.idea/contentModel.xml b/.idea/.idea.Aetheria-Economy/.idea/contentModel.xml index 2d45a5a87..dd3baa66b 100644 --- a/.idea/.idea.Aetheria-Economy/.idea/contentModel.xml +++ b/.idea/.idea.Aetheria-Economy/.idea/contentModel.xml @@ -1,8 +1,8 @@ - - + + @@ -1559,6 +1559,7 @@ + diff --git a/.idea/.idea.Aetheria-Economy/.idea/modules.xml b/.idea/.idea.Aetheria-Economy/.idea/modules.xml index a208ed7a3..f501f2b8c 100644 --- a/.idea/.idea.Aetheria-Economy/.idea/modules.xml +++ b/.idea/.idea.Aetheria-Economy/.idea/modules.xml @@ -2,7 +2,7 @@ - + \ No newline at end of file diff --git a/Aetheria-Economy_WwiseProject/Aetheria-Economy_WwiseProject.rwvens.wsettings b/Aetheria-Economy_WwiseProject/Aetheria-Economy_WwiseProject.rwvens.wsettings index 4eef811e6..75545acca 100644 --- a/Aetheria-Economy_WwiseProject/Aetheria-Economy_WwiseProject.rwvens.wsettings +++ b/Aetheria-Economy_WwiseProject/Aetheria-Economy_WwiseProject.rwvens.wsettings @@ -34,7 +34,7 @@ - + diff --git a/Assets/Materials/UI/Map Gravity Lines.mat b/Assets/Materials/UI/Map Gravity Lines.mat index 318ee80b0..48c6efff5 100644 --- a/Assets/Materials/UI/Map Gravity Lines.mat +++ b/Assets/Materials/UI/Map Gravity Lines.mat @@ -86,7 +86,7 @@ Material: - _Mode: 0 - _OcclusionStrength: 1 - _Parallax: 0.02 - - _Scale: 5.1991053 + - _Scale: 5.4972186 - _SmoothnessTextureChannel: 0 - _SpecularHighlights: 1 - _SrcBlend: 1 diff --git a/Assets/Resources/Aetheria.inputactions b/Assets/Resources/Aetheria.inputactions index db735a1e5..e1de4fff5 100644 --- a/Assets/Resources/Aetheria.inputactions +++ b/Assets/Resources/Aetheria.inputactions @@ -148,6 +148,14 @@ "expectedControlType": "Button", "processors": "", "interactions": "" + }, + { + "name": "Toggle Heatsinks", + "type": "Button", + "id": "e6c6ff6a-4ac2-4e53-a3c9-9461f52e723f", + "expectedControlType": "Button", + "processors": "", + "interactions": "" } ], "bindings": [ @@ -535,6 +543,17 @@ "action": "Target Nearest", "isComposite": false, "isPartOfComposite": false + }, + { + "name": "", + "id": "71ac6088-1e18-4810-86be-1179918dd4a2", + "path": "/#(H)", + "interactions": "", + "processors": "", + "groups": "", + "action": "Toggle Heatsinks", + "isComposite": false, + "isPartOfComposite": false } ] }, diff --git a/Assets/Scenes/ARPG.unity b/Assets/Scenes/ARPG.unity index 52fd9d2f5..e4b323457 100644 --- a/Assets/Scenes/ARPG.unity +++ b/Assets/Scenes/ARPG.unity @@ -4547,6 +4547,9 @@ MonoBehaviour: Settings: {fileID: 11400000, guid: cd2344e2001a37544aab0960c164d4ff, type: 2} ListElementPrototype: {fileID: 1277237367} TriggerGroupPrototype: {fileID: 1564656282} + HeaderElementEnabledColor: {r: 0, g: 0, b: 0, a: 0} + HeaderElementDisabledColor: {r: 0, g: 0, b: 0, a: 0} + HeatsinkBackground: {fileID: 0} EnergyLabel: {fileID: 0} CockpitTemperatureLabel: {fileID: 0} RadiatorTemperatureLabel: {fileID: 0} @@ -13279,7 +13282,7 @@ MonoBehaviour: Spacing: 16 Ceiling: -400 Floor: 5 - HeightExponent: 10000 + HeightExponent: 1000 Heightmap: {fileID: 8400000, guid: 2fc21a9d3e9647948b56e384cd9378b3, type: 2} ParticleColors: {fileID: 2800000, guid: 56db63da398b2d04394ddbccedce943c, type: 3} GravityCamera: {fileID: 1537342003} @@ -29466,6 +29469,9 @@ MonoBehaviour: Settings: {fileID: 11400000, guid: cd2344e2001a37544aab0960c164d4ff, type: 2} ListElementPrototype: {fileID: 232470599} TriggerGroupPrototype: {fileID: 1564656282} + HeaderElementEnabledColor: {r: 1, g: 1, b: 1, a: 0.078431375} + HeaderElementDisabledColor: {r: 1, g: 1, b: 1, a: 0.011764706} + HeatsinkBackground: {fileID: 661332569} EnergyLabel: {fileID: 804489113} CockpitTemperatureLabel: {fileID: 212527384} RadiatorTemperatureLabel: {fileID: 1752418078} diff --git a/Assets/Scripts/AetheriaInput.cs b/Assets/Scripts/AetheriaInput.cs index 0b8ce7448..b3117ec87 100644 --- a/Assets/Scripts/AetheriaInput.cs +++ b/Assets/Scripts/AetheriaInput.cs @@ -161,6 +161,14 @@ public class @AetheriaInput : IInputActionCollection, IDisposable ""expectedControlType"": ""Button"", ""processors"": """", ""interactions"": """" + }, + { + ""name"": ""Toggle Heatsinks"", + ""type"": ""Button"", + ""id"": ""e6c6ff6a-4ac2-4e53-a3c9-9461f52e723f"", + ""expectedControlType"": ""Button"", + ""processors"": """", + ""interactions"": """" } ], ""bindings"": [ @@ -548,6 +556,17 @@ public class @AetheriaInput : IInputActionCollection, IDisposable ""action"": ""Target Nearest"", ""isComposite"": false, ""isPartOfComposite"": false + }, + { + ""name"": """", + ""id"": ""71ac6088-1e18-4810-86be-1179918dd4a2"", + ""path"": ""/#(H)"", + ""interactions"": """", + ""processors"": """", + ""groups"": """", + ""action"": ""Toggle Heatsinks"", + ""isComposite"": false, + ""isPartOfComposite"": false } ] }, @@ -1132,6 +1151,7 @@ public class @AetheriaInput : IInputActionCollection, IDisposable m_Player_TargetPrevious = m_Player.FindAction("Target Previous", throwIfNotFound: true); m_Player_TargetNext = m_Player.FindAction("Target Next", throwIfNotFound: true); m_Player_TargetNearest = m_Player.FindAction("Target Nearest", throwIfNotFound: true); + m_Player_ToggleHeatsinks = m_Player.FindAction("Toggle Heatsinks", throwIfNotFound: true); // UI m_UI = asset.FindActionMap("UI", throwIfNotFound: true); m_UI_Navigate = m_UI.FindAction("Navigate", throwIfNotFound: true); @@ -1215,6 +1235,7 @@ public class @AetheriaInput : IInputActionCollection, IDisposable private readonly InputAction m_Player_TargetPrevious; private readonly InputAction m_Player_TargetNext; private readonly InputAction m_Player_TargetNearest; + private readonly InputAction m_Player_ToggleHeatsinks; public struct PlayerActions { private @AetheriaInput m_Wrapper; @@ -1237,6 +1258,7 @@ public class @AetheriaInput : IInputActionCollection, IDisposable public InputAction @TargetPrevious => m_Wrapper.m_Player_TargetPrevious; public InputAction @TargetNext => m_Wrapper.m_Player_TargetNext; public InputAction @TargetNearest => m_Wrapper.m_Player_TargetNearest; + public InputAction @ToggleHeatsinks => m_Wrapper.m_Player_ToggleHeatsinks; public InputActionMap Get() { return m_Wrapper.m_Player; } public void Enable() { Get().Enable(); } public void Disable() { Get().Disable(); } @@ -1300,6 +1322,9 @@ public class @AetheriaInput : IInputActionCollection, IDisposable @TargetNearest.started -= m_Wrapper.m_PlayerActionsCallbackInterface.OnTargetNearest; @TargetNearest.performed -= m_Wrapper.m_PlayerActionsCallbackInterface.OnTargetNearest; @TargetNearest.canceled -= m_Wrapper.m_PlayerActionsCallbackInterface.OnTargetNearest; + @ToggleHeatsinks.started -= m_Wrapper.m_PlayerActionsCallbackInterface.OnToggleHeatsinks; + @ToggleHeatsinks.performed -= m_Wrapper.m_PlayerActionsCallbackInterface.OnToggleHeatsinks; + @ToggleHeatsinks.canceled -= m_Wrapper.m_PlayerActionsCallbackInterface.OnToggleHeatsinks; } m_Wrapper.m_PlayerActionsCallbackInterface = instance; if (instance != null) @@ -1358,6 +1383,9 @@ public class @AetheriaInput : IInputActionCollection, IDisposable @TargetNearest.started += instance.OnTargetNearest; @TargetNearest.performed += instance.OnTargetNearest; @TargetNearest.canceled += instance.OnTargetNearest; + @ToggleHeatsinks.started += instance.OnToggleHeatsinks; + @ToggleHeatsinks.performed += instance.OnToggleHeatsinks; + @ToggleHeatsinks.canceled += instance.OnToggleHeatsinks; } } } @@ -1555,6 +1583,7 @@ public class @AetheriaInput : IInputActionCollection, IDisposable void OnTargetPrevious(InputAction.CallbackContext context); void OnTargetNext(InputAction.CallbackContext context); void OnTargetNearest(InputAction.CallbackContext context); + void OnToggleHeatsinks(InputAction.CallbackContext context); } public interface IUIActions { diff --git a/Assets/Scripts/Editor/DatabaseInspector.cs b/Assets/Scripts/Editor/DatabaseInspector.cs index b3e15fc9e..afffcc04e 100644 --- a/Assets/Scripts/Editor/DatabaseInspector.cs +++ b/Assets/Scripts/Editor/DatabaseInspector.cs @@ -1118,8 +1118,10 @@ public class DatabaseInspector : EditorWindow GUILayout.Label("", GUILayout.Width(width)); if (!isSimple) { - // GUILayout.Label("H", _labelStyle); - // value.HeatDependent = Toggle(value.HeatDependent); + GUILayout.Label("H", _labelStyle); + value.HeatDependent = Toggle(value.HeatDependent); + GUILayout.Label("HEx", _labelStyle, GUILayout.Width(labelWidth + 5)); + value.HeatExponentMultiplier = DelayedFloatField(value.HeatExponentMultiplier); GUILayout.Label("D", _labelStyle); value.DurabilityDependent = Toggle(value.DurabilityDependent); GUILayout.Label("QEx", _labelStyle, GUILayout.Width(labelWidth + 5)); diff --git a/Assets/Scripts/Gameplay/ActionGameManager.cs b/Assets/Scripts/Gameplay/ActionGameManager.cs index f472e4eaa..aa2af1aaa 100644 --- a/Assets/Scripts/Gameplay/ActionGameManager.cs +++ b/Assets/Scripts/Gameplay/ActionGameManager.cs @@ -189,6 +189,12 @@ public class ActionGameManager : MonoBehaviour else Undock(); }; + _input.Player.ToggleHeatsinks.performed += context => + { + CurrentShip.HeatsinksEnabled = !CurrentShip.HeatsinksEnabled; + AkSoundEngine.PostEvent(CurrentShip.HeatsinksEnabled ? "UI_Success" : "UI_Fail", gameObject); + }; + _input.Player.TargetReticle.performed += context => { var underReticle = Zone.Entities.Where(x => x != CurrentShip).MaxBy(x => dot(normalize(x.Position - CurrentShip.Position), CurrentShip.LookDirection)); diff --git a/Assets/Scripts/Gameplay/Weapons/ConstantLaserManager.cs b/Assets/Scripts/Gameplay/Weapons/ConstantLaserManager.cs index 145b07777..8d798558e 100644 --- a/Assets/Scripts/Gameplay/Weapons/ConstantLaserManager.cs +++ b/Assets/Scripts/Gameplay/Weapons/ConstantLaserManager.cs @@ -14,14 +14,14 @@ public class ConstantLaserManager : ConstantWeaponEffectManager p.SourceEntity = source.Entity; var hp = source.Entity.Hardpoints[item.Position.x, item.Position.y]; var barrel = source.GetBarrel(hp); - p.Range = source.Entity.ItemManager.Evaluate(data.Range, item.EquippableItem, source.Entity); + p.Range = source.Entity.ItemManager.Evaluate(data.Range, item); var t = p.transform; t.SetParent(barrel); t.forward = barrel.forward; t.position = barrel.position; - p.Damage = source.Entity.ItemManager.Evaluate(data.Damage, item.EquippableItem, source.Entity); - p.Penetration = source.Entity.ItemManager.Evaluate(data.Penetration, item.EquippableItem, source.Entity); - p.Spread = source.Entity.ItemManager.Evaluate(data.DamageSpread, item.EquippableItem, source.Entity); + p.Damage = source.Entity.ItemManager.Evaluate(data.Damage, item); + p.Penetration = source.Entity.ItemManager.Evaluate(data.Penetration, item); + p.Spread = source.Entity.ItemManager.Evaluate(data.DamageSpread, item); p.DamageType = data.DamageType; _lasers.Add(item, p); } diff --git a/Assets/Scripts/Gameplay/Weapons/ConstantLightningManager.cs b/Assets/Scripts/Gameplay/Weapons/ConstantLightningManager.cs index 5ee105a20..dbeb0cff4 100644 --- a/Assets/Scripts/Gameplay/Weapons/ConstantLightningManager.cs +++ b/Assets/Scripts/Gameplay/Weapons/ConstantLightningManager.cs @@ -16,10 +16,10 @@ public class ConstantLightningManager : ConstantWeaponEffectManager var hp = source.Entity.Hardpoints[item.Position.x, item.Position.y]; var barrel = source.GetBarrel(hp); p.Barrel = barrel; - p.Damage = source.Entity.ItemManager.Evaluate(data.Damage, item.EquippableItem, source.Entity); - p.Range = source.Entity.ItemManager.Evaluate(data.Range, item.EquippableItem, source.Entity); - p.Penetration = source.Entity.ItemManager.Evaluate(data.Penetration, item.EquippableItem, source.Entity); - p.Spread = source.Entity.ItemManager.Evaluate(data.DamageSpread, item.EquippableItem, source.Entity); + p.Damage = source.Entity.ItemManager.Evaluate(data.Damage, item); + p.Range = source.Entity.ItemManager.Evaluate(data.Range, item); + p.Penetration = source.Entity.ItemManager.Evaluate(data.Penetration, item); + p.Spread = source.Entity.ItemManager.Evaluate(data.DamageSpread, item); p.DamageType = data.DamageType; _bolts.Add(item, p); } diff --git a/Assets/Scripts/Gameplay/Weapons/ConstantParticleWeaponManager.cs b/Assets/Scripts/Gameplay/Weapons/ConstantParticleWeaponManager.cs index 0141b1ee4..575ec67cd 100644 --- a/Assets/Scripts/Gameplay/Weapons/ConstantParticleWeaponManager.cs +++ b/Assets/Scripts/Gameplay/Weapons/ConstantParticleWeaponManager.cs @@ -19,7 +19,7 @@ public class ConstantParticleWeaponManager : ConstantWeaponEffectManager t.SetParent(barrel); t.forward = barrel.forward; t.position = barrel.position; - p.Damage = source.Entity.ItemManager.Evaluate(data.Damage, item.EquippableItem, source.Entity); + p.Damage = source.Entity.ItemManager.Evaluate(data.Damage, item); p.DamageType = data.DamageType; _weapons.Add(item, p); p.Initialize(); diff --git a/Assets/Scripts/Gameplay/Weapons/GuidedProjectileManager.cs b/Assets/Scripts/Gameplay/Weapons/GuidedProjectileManager.cs index 7441d8972..f49d43fd5 100644 --- a/Assets/Scripts/Gameplay/Weapons/GuidedProjectileManager.cs +++ b/Assets/Scripts/Gameplay/Weapons/GuidedProjectileManager.cs @@ -29,8 +29,8 @@ public class GuidedProjectileManager : InstantWeaponEffectManager p.LiftCurve = launcher.LiftCurve.ToCurve(); p.ThrustCurve = launcher.ThrustCurve.ToCurve(); p.Velocity = barrel.forward * weapon.Velocity; - p.Thrust = source.Entity.ItemManager.Evaluate(launcher.Thrust, item.EquippableItem, source.Entity); - p.TopSpeed = source.Entity.ItemManager.Evaluate(launcher.MissileVelocity, item.EquippableItem, source.Entity); + p.Thrust = source.Entity.ItemManager.Evaluate(launcher.Thrust, item); + p.TopSpeed = source.Entity.ItemManager.Evaluate(launcher.MissileVelocity, item); } else if(weapon.Data is GuidedWeaponData guidance) { @@ -51,8 +51,8 @@ public class GuidedProjectileManager : InstantWeaponEffectManager p.LiftCurve = guidance.LiftCurve.ToCurve(); p.ThrustCurve = guidance.ThrustCurve.ToCurve(); p.Velocity = barrel.forward * weapon.Velocity; - p.Thrust = source.Entity.ItemManager.Evaluate(guidance.Thrust, item.EquippableItem, source.Entity); - p.TopSpeed = source.Entity.ItemManager.Evaluate(guidance.MissileVelocity, item.EquippableItem, source.Entity); + p.Thrust = source.Entity.ItemManager.Evaluate(guidance.Thrust, item); + p.TopSpeed = source.Entity.ItemManager.Evaluate(guidance.MissileVelocity, item); p.TargetPosition = () => source.Entity.Position + length( (float3)source.LookAtPoint.position - source.Entity.Position) * source.Entity.LookDirection; } else Debug.LogError($"Weapon {item.EquippableItem.Name} linked to {name} effect, but is not a Launcher!"); diff --git a/Assets/Scripts/ServerShared/Agents/States/Combat.cs b/Assets/Scripts/ServerShared/Agents/States/Combat.cs index e741dbe65..f09eee06d 100644 --- a/Assets/Scripts/ServerShared/Agents/States/Combat.cs +++ b/Assets/Scripts/ServerShared/Agents/States/Combat.cs @@ -18,8 +18,8 @@ public class CombatState : BaseState SampleDps(); foreach (var weapon in _agent.Ship.Weapons) { - weapon.Item.OnDisable += SampleDps; - weapon.Item.OnEnable += SampleDps; + weapon.Item.OnOffline += SampleDps; + weapon.Item.OnOnline += SampleDps; } } diff --git a/Assets/Scripts/ServerShared/Behaviors/Capacitor.cs b/Assets/Scripts/ServerShared/Behaviors/Capacitor.cs index e28d9a1f9..6602f889d 100644 --- a/Assets/Scripts/ServerShared/Behaviors/Capacitor.cs +++ b/Assets/Scripts/ServerShared/Behaviors/Capacitor.cs @@ -53,8 +53,8 @@ public class Capacitor : IBehavior public bool Execute(float delta) { - Capacity = Context.Evaluate(_data.Capacity, Item.EquippableItem, Entity); - Efficiency = Context.Evaluate(_data.Efficiency, Item.EquippableItem, Entity); + Capacity = Context.Evaluate(_data.Capacity, Item); + Efficiency = Context.Evaluate(_data.Efficiency, Item); return true; } } \ No newline at end of file diff --git a/Assets/Scripts/ServerShared/Behaviors/ChargedWeapon.cs b/Assets/Scripts/ServerShared/Behaviors/ChargedWeapon.cs index 484101525..3a468b603 100644 --- a/Assets/Scripts/ServerShared/Behaviors/ChargedWeapon.cs +++ b/Assets/Scripts/ServerShared/Behaviors/ChargedWeapon.cs @@ -100,9 +100,9 @@ public class ChargedWeapon : InstantWeapon protected override void UpdateStats() { base.UpdateStats(); - ChargeTime = Context.Evaluate(_data.ChargeTime, Item.EquippableItem, Entity); - ChargeEnergy = Context.Evaluate(_data.ChargeEnergy, Item.EquippableItem, Entity); - ChargeHeat = Context.Evaluate(_data.ChargeHeat, Item.EquippableItem, Entity); + ChargeTime = Context.Evaluate(_data.ChargeTime, Item); + ChargeEnergy = Context.Evaluate(_data.ChargeEnergy, Item); + ChargeHeat = Context.Evaluate(_data.ChargeHeat, Item); Damage *= lerp(1, _data.ChargeFiringDamageMultiplier, saturate(_charge)); Heat *= lerp(1, _data.ChargeFiringHeatMultiplier, saturate(_charge)); Spread *= lerp(1, _data.ChargeFiringSpreadMultiplier, saturate(_charge)); diff --git a/Assets/Scripts/ServerShared/Behaviors/ConstantWeapon.cs b/Assets/Scripts/ServerShared/Behaviors/ConstantWeapon.cs index da1f6eff6..5ca9f9498 100644 --- a/Assets/Scripts/ServerShared/Behaviors/ConstantWeapon.cs +++ b/Assets/Scripts/ServerShared/Behaviors/ConstantWeapon.cs @@ -67,7 +67,7 @@ public class ConstantWeapon : Weapon, IProgressBehavior base.Execute(delta); if (_firing) { - if (!Entity.TryConsumeEnergy(Context.Evaluate(_data.Energy, Item.EquippableItem, Entity) * delta)) + if (!Entity.TryConsumeEnergy(Context.Evaluate(_data.Energy, Item) * delta)) { _firing = false; OnStopFiring?.Invoke(); @@ -114,9 +114,10 @@ public class ConstantWeapon : Weapon, IProgressBehavior } } } - - Item.AddHeat(Context.Evaluate(_data.Heat, Item.EquippableItem, Entity) * delta); - Entity.VisibilitySources[this] = Context.Evaluate(_data.Visibility, Item.EquippableItem, Entity); + + Item.EquippableItem.Durability -= Wear * delta; + Item.AddHeat(Context.Evaluate(_data.Heat, Item) * delta); + Entity.VisibilitySources[this] = Context.Evaluate(_data.Visibility, Item); } return true; } diff --git a/Assets/Scripts/ServerShared/Behaviors/Cooldown.cs b/Assets/Scripts/ServerShared/Behaviors/Cooldown.cs index e1353b75f..ba16a09c8 100644 --- a/Assets/Scripts/ServerShared/Behaviors/Cooldown.cs +++ b/Assets/Scripts/ServerShared/Behaviors/Cooldown.cs @@ -56,6 +56,6 @@ public class Cooldown : IBehavior, IAlwaysUpdatedBehavior, IProgressBehavior public void Update(float delta) { - _cooldown -= delta / Context.Evaluate(_data.Cooldown, Item.EquippableItem, Entity); + _cooldown -= delta / Context.Evaluate(_data.Cooldown, Item); } } \ No newline at end of file diff --git a/Assets/Scripts/ServerShared/Behaviors/EnergyDraw.cs b/Assets/Scripts/ServerShared/Behaviors/EnergyDraw.cs index efd63cb99..68b9dac66 100644 --- a/Assets/Scripts/ServerShared/Behaviors/EnergyDraw.cs +++ b/Assets/Scripts/ServerShared/Behaviors/EnergyDraw.cs @@ -7,7 +7,7 @@ using System.Linq; using MessagePack; using Newtonsoft.Json; -[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(12), RuntimeInspectable] +[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(-20), RuntimeInspectable] public class EnergyDrawData : BehaviorData { [InspectableField, JsonProperty("draw"), Key(1), RuntimeInspectable] @@ -42,6 +42,6 @@ public class EnergyDraw : IBehavior public bool Execute(float delta) { - return Entity.TryConsumeEnergy(Context.Evaluate(_data.EnergyDraw, Item.EquippableItem, Entity) * (_data.PerSecond ? delta : 1)); + return Entity.TryConsumeEnergy(Context.Evaluate(_data.EnergyDraw, Item) * (_data.PerSecond ? delta : 1)); } } \ No newline at end of file diff --git a/Assets/Scripts/ServerShared/Behaviors/Heat.cs b/Assets/Scripts/ServerShared/Behaviors/Heat.cs index c41db5914..3f9dd6e2e 100644 --- a/Assets/Scripts/ServerShared/Behaviors/Heat.cs +++ b/Assets/Scripts/ServerShared/Behaviors/Heat.cs @@ -42,7 +42,7 @@ public class Heat : IBehavior public bool Execute(float delta) { - Item.AddHeat(Context.Evaluate(_data.Heat, Item.EquippableItem, Entity) * (_data.PerSecond ? delta : 1)); + Item.AddHeat(Context.Evaluate(_data.Heat, Item) * (_data.PerSecond ? delta : 1)); return true; } diff --git a/Assets/Scripts/ServerShared/Behaviors/InstantWeapon.cs b/Assets/Scripts/ServerShared/Behaviors/InstantWeapon.cs index 57e2187de..63dc23e72 100644 --- a/Assets/Scripts/ServerShared/Behaviors/InstantWeapon.cs +++ b/Assets/Scripts/ServerShared/Behaviors/InstantWeapon.cs @@ -92,9 +92,9 @@ public class InstantWeapon : Weapon, IProgressBehavior protected override void UpdateStats() { base.UpdateStats(); - BurstCount = Context.Evaluate(_data.Count, Item.EquippableItem, Entity); - BurstTime = Context.Evaluate(_data.BurstTime, Item.EquippableItem, Entity); - Cooldown = Context.Evaluate(_data.Cooldown, Item.EquippableItem, Entity); + BurstCount = Context.Evaluate(_data.Count, Item); + BurstTime = Context.Evaluate(_data.BurstTime, Item); + Cooldown = Context.Evaluate(_data.Cooldown, Item); Damage /= (int) BurstCount; Heat /= (int) BurstCount; @@ -165,6 +165,7 @@ public class InstantWeapon : Weapon, IProgressBehavior _burstRemaining--; _burstTimer -= _burstInterval; OnFire?.Invoke(); + Item.EquippableItem.Durability -= Wear; Item.AddHeat(Heat); Entity.VisibilitySources[this] = Visibility; } diff --git a/Assets/Scripts/ServerShared/Behaviors/LockWeapon.cs b/Assets/Scripts/ServerShared/Behaviors/LockWeapon.cs index 38304c966..aeca0fad2 100644 --- a/Assets/Scripts/ServerShared/Behaviors/LockWeapon.cs +++ b/Assets/Scripts/ServerShared/Behaviors/LockWeapon.cs @@ -71,11 +71,11 @@ public class LockWeapon : InstantWeapon 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); + LockSpeed = Context.Evaluate(_data.LockSpeed, Item); + SensorImpact = Context.Evaluate(_data.SensorImpact, Item); + LockAngle = Context.Evaluate(_data.LockAngle, Item); + DirectionImpact = Context.Evaluate(_data.DirectionImpact, Item); + Decay = Context.Evaluate(_data.Decay, Item); var degrees = acos(dot(normalize(Entity.Target.Value.Position - Entity.Position), normalize(Entity.LookDirection))) * 57.2958f; if (degrees < LockAngle) diff --git a/Assets/Scripts/ServerShared/Behaviors/MiningTool.cs b/Assets/Scripts/ServerShared/Behaviors/MiningTool.cs index 7940b4aaf..651b2d7db 100644 --- a/Assets/Scripts/ServerShared/Behaviors/MiningTool.cs +++ b/Assets/Scripts/ServerShared/Behaviors/MiningTool.cs @@ -54,7 +54,7 @@ public class MiningTool : IBehavior public bool Execute(float delta) { - Range = Context.Evaluate(_data.Range, Item.EquippableItem, Entity); + Range = Context.Evaluate(_data.Range, Item); var belt = Entity.Zone.AsteroidBelts[AsteroidBelt]; if (AsteroidBelt != Guid.Empty && Entity.Zone.AsteroidExists(AsteroidBelt, Asteroid) && @@ -64,9 +64,9 @@ public class MiningTool : IBehavior Entity, AsteroidBelt, Asteroid, - Context.Evaluate(_data.DamagePerSecond, Item.EquippableItem, Entity) * delta, - Context.Evaluate(_data.Efficiency, Item.EquippableItem, Entity), - Context.Evaluate(_data.Penetration, Item.EquippableItem, Entity)); + Context.Evaluate(_data.DamagePerSecond, Item) * delta, + Context.Evaluate(_data.Efficiency, Item), + Context.Evaluate(_data.Penetration, Item)); return true; } diff --git a/Assets/Scripts/ServerShared/Behaviors/Radiator.cs b/Assets/Scripts/ServerShared/Behaviors/Radiator.cs index 02247fff7..30f50c653 100644 --- a/Assets/Scripts/ServerShared/Behaviors/Radiator.cs +++ b/Assets/Scripts/ServerShared/Behaviors/Radiator.cs @@ -57,9 +57,9 @@ public class Radiator : IBehavior, IAlwaysUpdatedBehavior, IInitializableBehavio public bool Execute(float delta) { - PumpedHeat = Context.Evaluate(_data.PumpedHeat, Item.EquippableItem, Entity); - WasteHeat = Context.Evaluate(_data.WasteHeat, Item.EquippableItem, Entity); - EnergyUsage = Context.Evaluate(_data.EnergyUsage, Item.EquippableItem, Entity); + PumpedHeat = Context.Evaluate(_data.PumpedHeat, Item); + WasteHeat = Context.Evaluate(_data.WasteHeat, Item); + EnergyUsage = Context.Evaluate(_data.EnergyUsage, Item); var itemTemperature = Item.Temperature; var tempRatio = max(Temperature / itemTemperature, 1); @@ -84,7 +84,7 @@ public class Radiator : IBehavior, IAlwaysUpdatedBehavior, IInitializableBehavio public void Update(float delta) { - Emissivity = Context.Evaluate(_data.Emissivity, Item.EquippableItem, Entity); + Emissivity = Context.Evaluate(_data.Emissivity, Item); var rad = pow(Temperature, Context.GameplaySettings.HeatRadiationExponent) * Context.GameplaySettings.HeatRadiationMultiplier * Emissivity; Temperature -= rad * delta; Entity.VisibilitySources[this] = rad; diff --git a/Assets/Scripts/ServerShared/Behaviors/Reactor.cs b/Assets/Scripts/ServerShared/Behaviors/Reactor.cs index ef06992a5..4659fe3ee 100644 --- a/Assets/Scripts/ServerShared/Behaviors/Reactor.cs +++ b/Assets/Scripts/ServerShared/Behaviors/Reactor.cs @@ -74,8 +74,8 @@ public class Reactor : IBehavior, IOrderedBehavior public bool Execute(float delta) { - var charge = Context.Evaluate(_data.Charge, Item.EquippableItem, Entity) * delta; - var efficiency = Context.Evaluate(_data.Efficiency, Item.EquippableItem, Entity); + var charge = Context.Evaluate(_data.Charge, Item) * delta; + var efficiency = Context.Evaluate(_data.Efficiency, Item); // This behavior executes last, so any components drawing power have already done so @@ -88,7 +88,7 @@ public class Reactor : IBehavior, IOrderedBehavior // We have an energy deficit, have to overload the reactor if (Draw > .01f) { - var overloadEfficiency = Context.Evaluate(_data.OverloadEfficiency, Item.EquippableItem, Entity); + var overloadEfficiency = Context.Evaluate(_data.OverloadEfficiency, Item); // Generate heat using overload efficiency, usually much less efficient! heat += Draw / overloadEfficiency; @@ -120,7 +120,7 @@ public class Reactor : IBehavior, IOrderedBehavior // We still have an energy surplus, try to throttle the reactor to reduce heat generation if (Draw < -.01f) { - heat -= Draw / efficiency * (1 - 1 / Context.Evaluate(_data.ThrottlingFactor, Item.EquippableItem, Entity)); + heat -= Draw / efficiency * (1 - 1 / Context.Evaluate(_data.ThrottlingFactor, Item)); Draw = 0; } diff --git a/Assets/Scripts/ServerShared/Behaviors/ResourceScanner.cs b/Assets/Scripts/ServerShared/Behaviors/ResourceScanner.cs index 42474759d..d6737adef 100644 --- a/Assets/Scripts/ServerShared/Behaviors/ResourceScanner.cs +++ b/Assets/Scripts/ServerShared/Behaviors/ResourceScanner.cs @@ -105,8 +105,8 @@ public class ResourceScanner : IBehavior, IAlwaysUpdatedBehavior public void Update(float delta) { - Range = Context.Evaluate(_data.Range, Item.EquippableItem, Entity); - MinimumDensity = Context.Evaluate(_data.MinimumDensity, Item.EquippableItem, Entity); - ScanDuration = Context.Evaluate(_data.ScanDuration, Item.EquippableItem, Entity); + Range = Context.Evaluate(_data.Range, Item); + MinimumDensity = Context.Evaluate(_data.MinimumDensity, Item); + ScanDuration = Context.Evaluate(_data.ScanDuration, Item); } } \ No newline at end of file diff --git a/Assets/Scripts/ServerShared/Behaviors/Sensor.cs b/Assets/Scripts/ServerShared/Behaviors/Sensor.cs index 85aead875..62476cca4 100644 --- a/Assets/Scripts/ServerShared/Behaviors/Sensor.cs +++ b/Assets/Scripts/ServerShared/Behaviors/Sensor.cs @@ -59,7 +59,7 @@ public class Sensor : IBehavior var next = saturate( previous + entity.Visibility * - Context.Evaluate(_data.Sensitivity, Item.EquippableItem, Entity) * + Context.Evaluate(_data.Sensitivity, Item) * _data.SensitivityCurve.Evaluate(angle / PI) * delta / dist); next *= 1 - Context.GameplaySettings.TargetInfoDecay * delta; diff --git a/Assets/Scripts/ServerShared/Behaviors/StatModifier.cs b/Assets/Scripts/ServerShared/Behaviors/StatModifier.cs index 11b6eb48f..e2d9d9b18 100644 --- a/Assets/Scripts/ServerShared/Behaviors/StatModifier.cs +++ b/Assets/Scripts/ServerShared/Behaviors/StatModifier.cs @@ -86,7 +86,7 @@ public class StatModifier : IBehavior, IInitializableBehavior, IDisposableBehavi foreach (var stat in _stats) (_data.Type == StatModifierType.Constant ? stat.GetConstantModifiers(Entity) - : stat.GetScaleModifiers(Entity))[this] = Context.Evaluate(_data.Modifier, Item.EquippableItem, Entity); + : stat.GetScaleModifiers(Entity))[this] = Context.Evaluate(_data.Modifier, Item); return true; } diff --git a/Assets/Scripts/ServerShared/Behaviors/Thruster.cs b/Assets/Scripts/ServerShared/Behaviors/Thruster.cs index 361ffabcb..b7e59a5be 100644 --- a/Assets/Scripts/ServerShared/Behaviors/Thruster.cs +++ b/Assets/Scripts/ServerShared/Behaviors/Thruster.cs @@ -61,16 +61,16 @@ public class Thruster : IAnalogBehavior 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)); - Thrust = Context.Evaluate(_data.Thrust, Item.EquippableItem, Entity); + Thrust = Context.Evaluate(_data.Thrust, Item); } public bool Execute(float delta) { - Thrust = Context.Evaluate(_data.Thrust, Item.EquippableItem, Entity); + Thrust = Context.Evaluate(_data.Thrust, Item); 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); - var vis = _input * Context.Evaluate(_data.Visibility, Item.EquippableItem, Entity); + Item.AddHeat(_input * Context.Evaluate(_data.Heat, Item) * delta); + var vis = _input * Context.Evaluate(_data.Visibility, Item); if(!Entity.VisibilitySources.ContainsKey(this) || vis > Entity.VisibilitySources[this]) Entity.VisibilitySources[this] = vis; return true; diff --git a/Assets/Scripts/ServerShared/Behaviors/TurretController.cs b/Assets/Scripts/ServerShared/Behaviors/TurretController.cs index 74fac3a64..ccfcd53e7 100644 --- a/Assets/Scripts/ServerShared/Behaviors/TurretController.cs +++ b/Assets/Scripts/ServerShared/Behaviors/TurretController.cs @@ -60,7 +60,7 @@ public class TurretController : IBehavior if (b is Weapon weapon) { _weapons.Add(weapon); - var vel = Context.Evaluate(weapon.WeaponData.Velocity, item.EquippableItem, EquippedEntity); + var vel = Context.Evaluate(weapon.WeaponData.Velocity, item); if (vel > .1f) { _predictShots = true; @@ -95,7 +95,7 @@ public class TurretController : IBehavior 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) + if (Context.Evaluate(data.Range, x.Item) > dist && fire) { x.Activate(); } diff --git a/Assets/Scripts/ServerShared/Behaviors/VelocityLimit.cs b/Assets/Scripts/ServerShared/Behaviors/VelocityLimit.cs index 73e603cbb..4f7417a72 100644 --- a/Assets/Scripts/ServerShared/Behaviors/VelocityLimit.cs +++ b/Assets/Scripts/ServerShared/Behaviors/VelocityLimit.cs @@ -46,7 +46,7 @@ public class VelocityLimit : IBehavior public bool Execute(float delta) { - Limit = Context.Evaluate(_data.TopSpeed, Item.EquippableItem, Entity); + Limit = Context.Evaluate(_data.TopSpeed, Item); if (length(Entity.Velocity) > Limit) Entity.Velocity = normalize(Entity.Velocity) * Limit; return true; diff --git a/Assets/Scripts/ServerShared/Behaviors/Visibility.cs b/Assets/Scripts/ServerShared/Behaviors/Visibility.cs index 96bd55f13..62fa242ca 100644 --- a/Assets/Scripts/ServerShared/Behaviors/Visibility.cs +++ b/Assets/Scripts/ServerShared/Behaviors/Visibility.cs @@ -44,7 +44,7 @@ public class Visibility : IBehavior, IAlwaysUpdatedBehavior public bool Execute(float delta) { - Entity.VisibilitySources[this] = Context.Evaluate(_data.Visibility, Item.EquippableItem, Entity); + Entity.VisibilitySources[this] = Context.Evaluate(_data.Visibility, Item); return true; } @@ -53,7 +53,7 @@ public class Visibility : IBehavior, IAlwaysUpdatedBehavior // TODO: Time independent decay? if(Entity.VisibilitySources.ContainsKey(this)) { - Entity.VisibilitySources[this] *= Context.Evaluate(_data.VisibilityDecay, Item.EquippableItem, Entity); + Entity.VisibilitySources[this] *= Context.Evaluate(_data.VisibilityDecay, Item); } } } \ No newline at end of file diff --git a/Assets/Scripts/ServerShared/Behaviors/Weapon.cs b/Assets/Scripts/ServerShared/Behaviors/Weapon.cs index 16ca8e21d..fb124377d 100644 --- a/Assets/Scripts/ServerShared/Behaviors/Weapon.cs +++ b/Assets/Scripts/ServerShared/Behaviors/Weapon.cs @@ -68,6 +68,7 @@ public abstract class WeaponData : BehaviorData public abstract class Weapon : IActivatedBehavior { private WeaponData _data; + private EquippableItemData _itemData; public Entity Entity { get; } public EquippedItem Item { get; } @@ -89,6 +90,7 @@ public abstract class Weapon : IActivatedBehavior public float Visibility { get; protected set; } public float Spread { get; protected set; } public float Velocity { get; protected set; } + public float Wear { get; protected set; } protected bool _firing; @@ -104,22 +106,24 @@ public abstract class Weapon : IActivatedBehavior Entity = entity; Item = item; _data = data; + _itemData = context.GetData(item.EquippableItem); } public virtual void ResetEvents(){} protected virtual void UpdateStats() { - Damage = Context.Evaluate(_data.Damage, Item.EquippableItem, Entity); - Penetration = Context.Evaluate(_data.Penetration, Item.EquippableItem, Entity); - DamageSpread = Context.Evaluate(_data.DamageSpread, Item.EquippableItem, Entity); - MinRange = Context.Evaluate(_data.MinRange, Item.EquippableItem, Entity); - Range = Context.Evaluate(_data.Range, Item.EquippableItem, Entity); - Energy = Context.Evaluate(_data.Energy, Item.EquippableItem, Entity); - Heat = Context.Evaluate(_data.Heat, Item.EquippableItem, Entity); - Visibility = Context.Evaluate(_data.Visibility, Item.EquippableItem, Entity); - Spread = Context.Evaluate(_data.Spread, Item.EquippableItem, Entity); - Velocity = Context.Evaluate(_data.Velocity, Item.EquippableItem, Entity); + Damage = Context.Evaluate(_data.Damage, Item); + Penetration = Context.Evaluate(_data.Penetration, Item); + DamageSpread = Context.Evaluate(_data.DamageSpread, Item); + MinRange = Context.Evaluate(_data.MinRange, Item); + Range = Context.Evaluate(_data.Range, Item); + Energy = Context.Evaluate(_data.Energy, Item); + Heat = Context.Evaluate(_data.Heat, Item); + Visibility = Context.Evaluate(_data.Visibility, Item); + Spread = Context.Evaluate(_data.Spread, Item); + Velocity = Context.Evaluate(_data.Velocity, Item); + Wear = Context.Evaluate(_itemData.WearDamage, Item); } public virtual bool Execute(float delta) diff --git a/Assets/Scripts/ServerShared/Behaviors/Wear.cs b/Assets/Scripts/ServerShared/Behaviors/Wear.cs new file mode 100644 index 000000000..272709473 --- /dev/null +++ b/Assets/Scripts/ServerShared/Behaviors/Wear.cs @@ -0,0 +1,50 @@ +/* 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(1000), RuntimeInspectable] +public class WearData : BehaviorData +{ + [TemperatureInspectable, JsonProperty("perSecond"), Key(1)] + public bool PerSecond; + + public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item) + { + return new Wear(context, this, entity, 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) + { + Context = context; + _data = data; + Entity = entity; + Item = item; + _itemData = context.GetData(item.EquippableItem); + } + + public bool Execute(float delta) + { + var wear = Context.Evaluate(_itemData.WearDamage, Item); + if (_data.PerSecond) wear *= delta; + Item.EquippableItem.Durability -= wear; + return true; + } +} \ No newline at end of file diff --git a/Assets/Scripts/ServerShared/Behaviors/Wear.cs.meta b/Assets/Scripts/ServerShared/Behaviors/Wear.cs.meta new file mode 100644 index 000000000..f884f64d6 --- /dev/null +++ b/Assets/Scripts/ServerShared/Behaviors/Wear.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: efacda60d2c34447a59c16bdb100ad80 +timeCreated: 1614819389 \ No newline at end of file diff --git a/Assets/Scripts/ServerShared/DatabaseCache.cs b/Assets/Scripts/ServerShared/DatabaseCache.cs index 87d175f94..0469e3817 100644 --- a/Assets/Scripts/ServerShared/DatabaseCache.cs +++ b/Assets/Scripts/ServerShared/DatabaseCache.cs @@ -18,6 +18,8 @@ public class DatabaseCache public event Action OnDataUpdateRemote; public event Action OnDataDeleteRemote; + private readonly object addLock = new object(); + public Action Logger = Console.WriteLine; private readonly Dictionary _entries = new Dictionary(); @@ -28,32 +30,35 @@ public class DatabaseCache public void Add(DatabaseEntry entry, bool remote = false) { - if (entry != null) + lock(addLock) { - var exists = _entries.ContainsKey(entry.ID); - _entries[entry.ID] = entry; - var type = entry.GetType(); - var types = type.GetParentTypes(); - foreach (var t in types) + if (entry != null) { - if(!_types.ContainsKey(t)) - _types[t] = new Dictionary(); - _types[t][entry.ID] = entry; - } + var exists = _entries.ContainsKey(entry.ID); + _entries[entry.ID] = entry; + var type = entry.GetType(); + var types = type.GetParentTypes(); + foreach (var t in types) + { + if (!_types.ContainsKey(t)) + _types[t] = new Dictionary(); + _types[t][entry.ID] = entry; + } - if (remote) - { - if (exists) - OnDataUpdateRemote?.Invoke(entry); + if (remote) + { + if (exists) + OnDataUpdateRemote?.Invoke(entry); + else + OnDataInsertRemote?.Invoke(entry); + } else - OnDataInsertRemote?.Invoke(entry); - } - else - { - if (exists) - OnDataUpdateLocal?.Invoke(entry); - else - OnDataInsertLocal?.Invoke(entry); + { + if (exists) + OnDataUpdateLocal?.Invoke(entry); + else + OnDataInsertLocal?.Invoke(entry); + } } } } diff --git a/Assets/Scripts/ServerShared/Entity.cs b/Assets/Scripts/ServerShared/Entity.cs index a3c6e6d96..0194a0c70 100644 --- a/Assets/Scripts/ServerShared/Entity.cs +++ b/Assets/Scripts/ServerShared/Entity.cs @@ -69,7 +69,27 @@ public abstract class Entity private List _weapons = new List(); private List _capacitors = new List(); private List _reactors = new List(); + private List _heatsinks = new List(); protected bool _active; + + private bool _heatsinksEnabled = true; + + public bool HeatsinksEnabled + { + get => _heatsinksEnabled; + set + { + if (value == _heatsinksEnabled) return; + _heatsinksEnabled = value; + foreach (var heatsink in _heatsinks) + heatsink.Item.Enabled = value; + } + } + + public bool Active + { + get => _active; + } public IEnumerable Weapons { @@ -291,8 +311,11 @@ public abstract class Entity return quantityTransferred; } - public EquippableItem Unequip(EquippedItem item) + public EquippableItem TryUnequip(EquippedItem item) { + // Don't allow unequipping when the entity is active + if (_active) return null; + if (item.EquippableItem == null) { ItemManager.Log("Attempted to remove equipped item with no equippable item on it! This should be impossible!"); @@ -330,6 +353,8 @@ public abstract class Entity _capacitors.Remove(capacitor); if(b is Reactor reactor) _reactors.Remove(reactor); + if(b is Radiator heatsink) + _heatsinks.Remove(heatsink); } return item.EquippableItem; @@ -396,6 +421,9 @@ public abstract class Entity // Check whether the given item will fit when its origin is placed at the given coordinate on the hull public bool ItemFits(EquippableItem item, int2 hullCoord) { + // Don't allow equipping while deployed + if (_active) return false; + var itemData = ItemManager.GetData(item); var hullData = ItemManager.GetData(Hull) as HullData; return ItemFits(itemData, hullData, item, hullCoord); @@ -403,6 +431,12 @@ public abstract class Entity public bool TryFindSpace(EquippableItem item, out int2 hullCoord) { + // Don't allow equipping while deployed + if (_active) + { + hullCoord = int2.zero; + return false; + } var itemData = ItemManager.GetData(item); var hullData = ItemManager.GetData(Hull) as HullData; @@ -451,6 +485,9 @@ public abstract class Entity // Try to equip the given item to the given location public bool TryEquip(EquippableItem item, int2 hullCoord) { + // Don't allow equipping while deployed + if (_active) return false; + var itemData = ItemManager.GetData(item); var hullData = ItemManager.GetData(Hull) as HullData; @@ -492,10 +529,12 @@ public abstract class Entity _capacitors.Add(capacitor); if(b is Reactor reactor) _reactors.Add(reactor); + if(b is Radiator heatsink) + _heatsinks.Add(heatsink); } - equippedItem.OnEnable += () => ItemOnline.OnNext(equippedItem); - equippedItem.OnDisable += () => ItemOffline.OnNext(equippedItem); + equippedItem.OnOnline += () => ItemOnline.OnNext(equippedItem); + equippedItem.OnOffline += () => ItemOffline.OnNext(equippedItem); foreach (var i in itemData.Shape.Coordinates) { @@ -811,8 +850,10 @@ public class EquippedItem public Dictionary BehaviorGroups; - public event Action OnDisable; - public event Action OnEnable; + public bool Enabled = true; + + public event Action OnOffline; + public event Action OnOnline; public float Conductivity { get; } @@ -834,6 +875,11 @@ public class EquippedItem return sum/InsetShape.Coordinates.Length; } } + + public Entity Entity + { + get => _entity; + } protected readonly ItemManager _itemManager; private readonly EquippableItemData _data; @@ -882,22 +928,16 @@ public class EquippedItem public void Update(float delta) { - if (Temperature < _data.MinimumTemperature || Temperature > _data.MaximumTemperature) - { - _entity.ItemDamage.OnNext((this, delta)); - EquippableItem.Durability -= delta; - } - foreach (var behavior in Behaviors) if(behavior is IAlwaysUpdatedBehavior alwaysUpdatedBehavior) alwaysUpdatedBehavior.Update(delta); var previouslyOnline = _online; _online = EquippableItem.Durability > .01f && Temperature > _data.MinimumTemperature && Temperature < _data.MaximumTemperature; - if (!previouslyOnline && _online) OnEnable?.Invoke(); - if (previouslyOnline && !_online) OnDisable?.Invoke(); + if (!previouslyOnline && _online) OnOnline?.Invoke(); + if (previouslyOnline && !_online) OnOffline?.Invoke(); - if (_online) + if (Enabled && _online) { foreach (var group in BehaviorGroups.Values) { @@ -958,6 +998,15 @@ public class EquippedCargoBay : EquippedItem return true; } + + public bool TryFindSpace(ItemInstance item) + { + if (item is SimpleCommodity simpleCommodity) + return TryFindSpace(simpleCommodity, out _); + if (item is CraftedItemInstance craftedItem) + return TryFindSpace(craftedItem, out _); + return false; + } // Tries to find a place to put the given items in the inventory // Will attempt to fill existing item stacks first @@ -996,6 +1045,23 @@ public class EquippedCargoBay : EquippedItem return false; } + + // Searches the cargo bay for a position where the item will fit, returns true when found + public bool TryFindSpace(CraftedItemInstance item, out int2 position) + { + // Search all the space in the cargo bay for an empty space where the item fits + foreach (var cargoCoord in Data.InteriorShape.Coordinates) + { + if (ItemFits(item, cargoCoord)) + { + position = cargoCoord; + return true; + } + } + + position = int2.zero; + return false; + } public bool TryStore(ItemInstance item) { @@ -1072,23 +1138,6 @@ public class EquippedCargoBay : EquippedItem return true; } - // Searches the cargo bay for a position where the item will fit, returns true when found - public bool TryFindSpace(CraftedItemInstance item, out int2 position) - { - // Search all the space in the cargo bay for an empty space where the item fits - foreach (var cargoCoord in Data.InteriorShape.Coordinates) - { - if (ItemFits(item, cargoCoord)) - { - position = cargoCoord; - return true; - } - } - - position = int2.zero; - return false; - } - // Try to store the given item anywhere it will fit, returns true when the item was successfully stored public bool TryStore(CraftedItemInstance item) => TryFindSpace(item, out var position) && TryStore(item, position); diff --git a/Assets/Scripts/ServerShared/ItemData.cs b/Assets/Scripts/ServerShared/ItemData.cs index 598beee90..e866c3d33 100644 --- a/Assets/Scripts/ServerShared/ItemData.cs +++ b/Assets/Scripts/ServerShared/ItemData.cs @@ -290,6 +290,15 @@ public abstract class EquippableItemData : CraftedItemData [InspectableField, JsonProperty("durabilityExponent"), Key(15), SimplePerformanceStat] public PerformanceStat DurabilityExponent = new PerformanceStat(); + + [InspectableField, JsonProperty("heatExponent"), Key(16), SimplePerformanceStat] + public PerformanceStat HeatExponent = new PerformanceStat(); + + [InspectableAnimationCurve, JsonProperty("performanceCurve"), Key(17)] + public float4[] HeatPerformanceCurve; + + [InspectableField, JsonProperty("wearDamage"), Key(18)] + public PerformanceStat WearDamage = new PerformanceStat(); [IgnoreMember] public abstract HardpointType HardpointType { get; } @@ -297,12 +306,42 @@ public abstract class EquippableItemData : CraftedItemData [IgnoreMember] private const int STEPS = 64; [IgnoreMember] private float? _optimum; + + [IgnoreMember] + public float OptimalTemperature + { + get + { + if (_optimum==null) + { + var samples = Enumerable.Range(0, STEPS).Select(i => (float) i / STEPS).ToArray(); + float max = 0; + _optimum = 0; + foreach (var f in samples) + { + var p = HeatPerformanceCurve?.Evaluate(f)??0; + if (p > max) + { + max = p; + _optimum = f; + } + } + } + + return (float) (MinimumTemperature + _optimum * (MaximumTemperature - MinimumTemperature)); + } + } + + public float Performance(float temperature) + { + return saturate(HeatPerformanceCurve.Evaluate(unlerp(MinimumTemperature, MaximumTemperature, temperature))); + } } [RethinkTable("Items"), Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)] public class GearData : EquippableItemData { - [InspectableField, JsonProperty("hardpointType"), Key(16)] + [InspectableField, JsonProperty("hardpointType"), Key(19)] public HardpointType Hardpoint; [IgnoreMember] public override HardpointType HardpointType => Hardpoint; @@ -311,7 +350,7 @@ public class GearData : EquippableItemData [RethinkTable("Items"), Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)] public class CargoBayData : EquippableItemData { - [InspectableField, JsonProperty("interiorShape"), Key(16)] + [InspectableField, JsonProperty("interiorShape"), Key(19)] public Shape InteriorShape; [IgnoreMember] public override HardpointType HardpointType => HardpointType.Tool; } @@ -319,7 +358,7 @@ public class CargoBayData : EquippableItemData [RethinkTable("Items"), Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)] public class DockingBayData : CargoBayData { - [InspectableField, JsonProperty("maxSize"), Key(17)] + [InspectableField, JsonProperty("maxSize"), Key(20)] public int2 MaxSize; [IgnoreMember] public override HardpointType HardpointType => HardpointType.Tool; } @@ -327,19 +366,19 @@ public class DockingBayData : CargoBayData [RethinkTable("Items"), Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)] public class HullData : EquippableItemData { - [InspectableField, JsonProperty("hardpoints"), Key(16)] + [InspectableField, JsonProperty("hardpoints"), Key(19)] public List Hardpoints = new List(); - [InspectablePrefab, JsonProperty("prefab"), Key(17)] + [InspectablePrefab, JsonProperty("prefab"), Key(20)] public string Prefab; - [InspectableField, JsonProperty("hullType"), Key(18)] + [InspectableField, JsonProperty("hullType"), Key(21)] public HullType HullType; - [InspectableField, JsonProperty("gridOffset"), Key(19)] + [InspectableField, JsonProperty("gridOffset"), Key(22)] public float GridOffset; - [InspectableField, JsonProperty("armor"), Key(20)] + [InspectableField, JsonProperty("armor"), Key(23)] public float Armor; [IgnoreMember] @@ -410,11 +449,14 @@ public class PerformanceStat [JsonProperty("durabilityDependent"), Key(2)] public bool DurabilityDependent; - // [JsonProperty("heatDependent"), Key(3)] - // public bool HeatDependent; - [JsonProperty("qualityExponent"), Key(3)] public float QualityExponent; + + [JsonProperty("heatDependent"), Key(4)] + public bool HeatDependent; + + [JsonProperty("heatExponentMultiplier"), Key(5)] + public float HeatExponentMultiplier = 1; //[JsonProperty("id"), Key(5)] public Guid ID = Guid.NewGuid(); diff --git a/Assets/Scripts/ServerShared/ItemManager.cs b/Assets/Scripts/ServerShared/ItemManager.cs index eec8797ad..ffb1f903c 100644 --- a/Assets/Scripts/ServerShared/ItemManager.cs +++ b/Assets/Scripts/ServerShared/ItemManager.cs @@ -273,21 +273,21 @@ public class ItemManager } // Returns stat using ship temperature and modifiers - public float Evaluate(PerformanceStat stat, EquippableItem item, Entity entity) + public float Evaluate(PerformanceStat stat, EquippedItem item) { - var itemData = GetData(item); + var itemData = GetData(item.EquippableItem); - //var heat = !stat.HeatDependent ? 1 : pow(itemData.Performance(entity.Temperature), Evaluate(itemData.HeatExponent,item)); - var durability = !stat.DurabilityDependent ? 1 : pow(item.Durability / itemData.Durability, Evaluate(itemData.DurabilityExponent,item)); - var quality = pow(Quality(stat, item), stat.QualityExponent); + var heat = !stat.HeatDependent ? 1 : pow(itemData.Performance(item.Temperature), Evaluate(itemData.HeatExponent, item.EquippableItem) * stat.HeatExponentMultiplier); + var durability = !stat.DurabilityDependent ? 1 : pow(item.EquippableItem.Durability / itemData.Durability, Evaluate(itemData.DurabilityExponent,item.EquippableItem)); + var quality = pow(Quality(stat, item.EquippableItem), stat.QualityExponent); var scaleModifier = 1.0f; - foreach (var value in stat.GetScaleModifiers(entity).Values) scaleModifier = scaleModifier * value; + foreach (var value in stat.GetScaleModifiers(item.Entity).Values) scaleModifier = scaleModifier * value; float constantModifier = 0; - foreach (var value in stat.GetConstantModifiers(entity).Values) constantModifier += value; + foreach (var value in stat.GetConstantModifiers(item.Entity).Values) constantModifier += value; - var result = lerp(stat.Min, stat.Max, durability * quality) * scaleModifier + constantModifier; + var result = lerp(stat.Min, stat.Max, durability * quality * heat) * scaleModifier + constantModifier; if (float.IsNaN(result)) return stat.Min; return result; diff --git a/Assets/Scripts/UI/InventoryMenu.cs b/Assets/Scripts/UI/InventoryMenu.cs index c7912d280..2c98baa28 100644 --- a/Assets/Scripts/UI/InventoryMenu.cs +++ b/Assets/Scripts/UI/InventoryMenu.cs @@ -110,30 +110,34 @@ public class InventoryMenu : MonoBehaviour } else if (data is InventoryEntityEventData entityEvent) { - var item = entityEvent.Entity.GearOccupancy[entityEvent.Position.x, entityEvent.Position.y]; - if (item != null) + if(!entityEvent.Entity.Active) { - var itemData = GameManager.ItemManager.GetData(item.EquippableItem); - var hullData = GameManager.ItemManager.GetData(entityEvent.Entity.Hull); - - _originalRotation = item.EquippableItem.Rotation; - _originalEquippedItem = entityEvent.Entity.GearOccupancy[data.Position.x, data.Position.y]; - _originalOccupancy = hullData.Shape.Inset(itemData.Shape, item.Position, item.EquippableItem.Rotation); - _originalPanel = panel; - _dragItem = item.EquippableItem; - _dragCellOffset = item.Position - entityEvent.Position; - _dragCells = _originalOccupancy.Coordinates - .Select(v => Instantiate(panel.CellInstances[v], DragParent, true).transform).ToArray(); - foreach(var cell in _dragCells) + var item = entityEvent.Entity.GearOccupancy[entityEvent.Position.x, entityEvent.Position.y]; + if (item != null) { - foreach (var component in cell.GetComponentsInChildren()) - component.enabled = false; - cell.GetComponentInChildren().raycastTarget = false; + var itemData = GameManager.ItemManager.GetData(item.EquippableItem); + var hullData = GameManager.ItemManager.GetData(entityEvent.Entity.Hull); + + _originalRotation = item.EquippableItem.Rotation; + _originalEquippedItem = entityEvent.Entity.GearOccupancy[data.Position.x, data.Position.y]; + _originalOccupancy = hullData.Shape.Inset(itemData.Shape, item.Position, item.EquippableItem.Rotation); + _originalPanel = panel; + _dragItem = item.EquippableItem; + _dragCellOffset = item.Position - entityEvent.Position; + _dragCells = _originalOccupancy.Coordinates + .Select(v => Instantiate(panel.CellInstances[v], DragParent, true).transform).ToArray(); + foreach (var cell in _dragCells) + { + foreach (var component in cell.GetComponentsInChildren()) + component.enabled = false; + cell.GetComponentInChildren().raycastTarget = false; + } + + _dragOffsets = _dragCells.Select(x => (Vector2) x.position - data.PointerEventData.position).ToArray(); + panel.IgnoreOccupancy = _originalOccupancy; + panel.RefreshCells(_originalOccupancy.Expand().Coordinates); + AkSoundEngine.PostEvent("Pickup", gameObject); } - _dragOffsets = _dragCells.Select(x => (Vector2) x.position - data.PointerEventData.position).ToArray(); - panel.IgnoreOccupancy = _originalOccupancy; - panel.RefreshCells(_originalOccupancy.Expand().Coordinates); - AkSoundEngine.PostEvent("Pickup", gameObject); } } }); @@ -166,7 +170,7 @@ public class InventoryMenu : MonoBehaviour } else if (data is InventoryEntityEventData entityEvent) { - if (entityEvent.Entity.Unequip(_originalEquippedItem) != null) + if (entityEvent.Entity.TryUnequip(_originalEquippedItem) != null) { _dragTargetPanel.DropItem(_dragItem, _dragTargetPosition); AkSoundEngine.PostEvent("Unequip", gameObject); @@ -196,7 +200,7 @@ public class InventoryMenu : MonoBehaviour } else if (data is InventoryEntityEventData entityEvent) { - if (entityEvent.Entity.Unequip(_originalEquippedItem) == null) + if (entityEvent.Entity.TryUnequip(_originalEquippedItem) == null) { Dialog.Clear(); Dialog.Title.text = "Unable to destroy item!"; @@ -290,13 +294,15 @@ public class InventoryMenu : MonoBehaviour if (Mouse.current.clickCount.ReadValue() == 2) { var otherPanel = panel == InventoryPanels[0] ? InventoryPanels[1] : InventoryPanels[0]; - if (otherPanel.DropItem(item)) + if (otherPanel.CanDropItem(item)) { + otherPanel.DropItem(item); AkSoundEngine.PostEvent("Equip", gameObject); cargoEvent.CargoBay.Remove(item); panel.RefreshCells(); otherPanel.RefreshCells(); } + else AkSoundEngine.PostEvent("UI_Fail", gameObject); } else { @@ -336,12 +342,20 @@ public class InventoryMenu : MonoBehaviour if (Mouse.current.clickCount.ReadValue() == 2) { var otherPanel = panel == InventoryPanels[0] ? InventoryPanels[1] : InventoryPanels[0]; - if (otherPanel.DropItem(item.EquippableItem)) + if (otherPanel.CanDropItem(item.EquippableItem)) { - AkSoundEngine.PostEvent("Unequip", gameObject); - entityEvent.Entity.Unequip(item); - panel.RefreshCells(); - otherPanel.RefreshCells(); + if (!entityEvent.Entity.Active) + { + if (entityEvent.Entity.TryUnequip(item) != null) + { + otherPanel.DropItem(item.EquippableItem); + AkSoundEngine.PostEvent("Unequip", gameObject); + panel.RefreshCells(); + otherPanel.RefreshCells(); + } + else AkSoundEngine.PostEvent("UI_Fail", gameObject); + } + else AkSoundEngine.PostEvent("UI_Fail", gameObject); } } else diff --git a/Assets/Scripts/UI/InventoryPanel.cs b/Assets/Scripts/UI/InventoryPanel.cs index 5181bfb0c..dd8a7a5b9 100644 --- a/Assets/Scripts/UI/InventoryPanel.cs +++ b/Assets/Scripts/UI/InventoryPanel.cs @@ -640,6 +640,21 @@ public class InventoryPanel : MonoBehaviour return false; } + public bool CanDropItem(ItemInstance item) + { + if (_displayedEntity != null && item is EquippableItem equippableItem) + { + return _displayedEntity.TryFindSpace(equippableItem, out _); + } + + if (_displayedCargo != null) + { + return _displayedCargo.TryFindSpace(item); + } + + return false; + } + public bool DropItem(ItemInstance item) { if (_displayedEntity != null && item is EquippableItem equippableItem) diff --git a/Assets/Scripts/UI/PropertiesPanel.cs b/Assets/Scripts/UI/PropertiesPanel.cs index 3dc9c15f6..27754c2e6 100644 --- a/Assets/Scripts/UI/PropertiesPanel.cs +++ b/Assets/Scripts/UI/PropertiesPanel.cs @@ -386,7 +386,7 @@ public class PropertiesPanel : MonoBehaviour else if (fieldType == typeof(PerformanceStat)) { var stat = (PerformanceStat) field.GetValue(behavior); - AddProperty(field.Name, () => $"{Context.Evaluate(stat, gear, entity).SignificantDigits(Context.GameplaySettings.SignificantDigits)}"); + AddProperty(field.Name, () => $"{Context.Evaluate(stat, gear).SignificantDigits(Context.GameplaySettings.SignificantDigits)}"); } } } diff --git a/Assets/Scripts/UI/SchematicDisplay.cs b/Assets/Scripts/UI/SchematicDisplay.cs index f30db6a33..989964c57 100644 --- a/Assets/Scripts/UI/SchematicDisplay.cs +++ b/Assets/Scripts/UI/SchematicDisplay.cs @@ -14,6 +14,11 @@ public class SchematicDisplay : MonoBehaviour public Prototype ListElementPrototype; public Prototype TriggerGroupPrototype; + public Color HeaderElementEnabledColor; + public Color HeaderElementDisabledColor; + + public Image HeatsinkBackground; + public TextMeshProUGUI EnergyLabel; public TextMeshProUGUI CockpitTemperatureLabel; public TextMeshProUGUI RadiatorTemperatureLabel; @@ -209,13 +214,13 @@ public class SchematicDisplay : MonoBehaviour { if (!_enemy) { - if (_radiators.Length == 1) RadiatorTemperatureLabel.text = $"{((int)(_radiators[0].Temperature - 273.15f)).ToString()}°C"; else if (_radiators.Length > 1) RadiatorTemperatureLabel.text = $"{((int)(_radiators.Min(r => r.Temperature) - 273.15f)).ToString()}-" + $"{((int)(_radiators.Max(r => r.Temperature) - 273.15f)).ToString()}°C"; + HeatsinkBackground.color = _entity.HeatsinksEnabled ? HeaderElementEnabledColor : HeaderElementDisabledColor; if (_heatsinks.Length == 1) HeatsinkTemperatureLabel.text = $"{((int)(_heatsinks[0].Item.Temperature - 273.15f)).ToString()}°C"; @@ -282,7 +287,7 @@ public class SchematicDisplay : MonoBehaviour if (x.Weapon.WeaponData != null) { - x.ListElement.RangeLabel.text = ((int) _entity.ItemManager.Evaluate(x.Weapon.WeaponData.Range, x.Item.EquippableItem, _entity)).ToString(); + x.ListElement.RangeLabel.text = ((int) _entity.ItemManager.Evaluate(x.Weapon.WeaponData.Range, x.Item)).ToString(); } } } diff --git a/Economy.Shared.Unity.csproj b/Economy.Shared.Unity.csproj index 0f9b640cd..2e941db4b 100644 --- a/Economy.Shared.Unity.csproj +++ b/Economy.Shared.Unity.csproj @@ -523,6 +523,7 @@ +