From 8d4bd048913fe75568ae24547849ce9335ca3864 Mon Sep 17 00:00:00 2001 From: Reinier Vens Date: Thu, 11 Feb 2021 03:14:20 +0000 Subject: [PATCH] AI State Machine First Pass Implemented first pass on code-driven state machine logic for flexible AI agents --- .../.idea/contentModel.xml | 6 + Assets/Materials/UI/Map Gravity Lines.mat | 2 +- Assets/Scenes/ARPG.unity | 2 + Assets/Scripts/Gameplay/ActionGameManager.cs | 87 +++++---- Assets/Scripts/ServerShared/AetheriaMath.cs | 2 +- .../ServerShared/Agents/AgentBehavior.cs | 169 ++++++++++++++++++ .../Scripts/ServerShared/Agents/AgentTask.cs | 6 + .../Scripts/ServerShared/Agents/Locomotion.cs | 2 +- .../ServerShared/Behaviors/ChargedWeapon.cs | 26 +-- .../ServerShared/Behaviors/ConstantWeapon.cs | 4 +- .../ServerShared/Behaviors/InstantWeapon.cs | 8 +- .../ServerShared/Behaviors/Launcher.cs | 24 +-- .../ServerShared/Behaviors/LockWeapon.cs | 10 +- .../Scripts/ServerShared/Behaviors/Sensor.cs | 20 +++ .../Scripts/ServerShared/Behaviors/Weapon.cs | 29 +-- Assets/Scripts/ServerShared/Corporations.cs | 13 +- Assets/Scripts/ServerShared/Entity.cs | 28 +++ Assets/Scripts/ServerShared/Settings.cs | 4 + Assets/Scripts/ServerShared/Ship.cs | 124 +++++++++++-- Assets/Scripts/ServerShared/Zone.cs | 8 +- Assets/Scripts/UI/InventoryPanel.cs | 30 ++-- Assets/Scripts/UI/TradeMenu.cs | 16 +- GameData/{Presets => Loadouts}/Djinni.preset | Bin GameData/Loadouts/Longinus.preset | Bin 0 -> 3807 bytes GameData/Loadouts/Turret.preset | Bin 0 -> 1737 bytes GameData/Presets/Longinus.preset | Bin 2677 -> 0 bytes 26 files changed, 486 insertions(+), 134 deletions(-) rename GameData/{Presets => Loadouts}/Djinni.preset (100%) create mode 100644 GameData/Loadouts/Longinus.preset create mode 100644 GameData/Loadouts/Turret.preset delete mode 100644 GameData/Presets/Longinus.preset diff --git a/.idea/.idea.Aetheria-Economy/.idea/contentModel.xml b/.idea/.idea.Aetheria-Economy/.idea/contentModel.xml index 79a806f0c..5b2a4268c 100644 --- a/.idea/.idea.Aetheria-Economy/.idea/contentModel.xml +++ b/.idea/.idea.Aetheria-Economy/.idea/contentModel.xml @@ -1450,6 +1450,10 @@ + + + + @@ -1460,6 +1464,8 @@ + + diff --git a/Assets/Materials/UI/Map Gravity Lines.mat b/Assets/Materials/UI/Map Gravity Lines.mat index efe66ec91..34a64cbf9 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.181433 + - _Scale: 2.7104213 - _SmoothnessTextureChannel: 0 - _SpecularHighlights: 1 - _SrcBlend: 1 diff --git a/Assets/Scenes/ARPG.unity b/Assets/Scenes/ARPG.unity index 031eb043c..94f21ab9c 100644 --- a/Assets/Scenes/ARPG.unity +++ b/Assets/Scenes/ARPG.unity @@ -4567,6 +4567,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 78aa0b8ec7594a7438f13757228e3500, type: 3} m_Name: m_EditorClassIdentifier: + ConfirmationDialog: {fileID: 0} Flip: 1 Settings: {fileID: 11400000, guid: cd2344e2001a37544aab0960c164d4ff, type: 2} GameManager: {fileID: 1009503729} @@ -28397,6 +28398,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 78aa0b8ec7594a7438f13757228e3500, type: 3} m_Name: m_EditorClassIdentifier: + ConfirmationDialog: {fileID: 0} Flip: 0 Settings: {fileID: 11400000, guid: cd2344e2001a37544aab0960c164d4ff, type: 2} GameManager: {fileID: 1009503729} diff --git a/Assets/Scripts/Gameplay/ActionGameManager.cs b/Assets/Scripts/Gameplay/ActionGameManager.cs index b953f36c3..6bcf740fd 100644 --- a/Assets/Scripts/Gameplay/ActionGameManager.cs +++ b/Assets/Scripts/Gameplay/ActionGameManager.cs @@ -17,6 +17,7 @@ using UnityEngine.InputSystem; using UnityEngine.UI; using static Unity.Mathematics.math; using float2 = Unity.Mathematics.float2; +using Random = UnityEngine.Random; public class ActionGameManager : MonoBehaviour { @@ -48,20 +49,21 @@ public class ActionGameManager : MonoBehaviour // private CinemachineComposer _composer; private DirectoryInfo _filePath; - private DirectoryInfo _presetPath; + private DirectoryInfo _loadoutPath; private bool _editMode; private float _time; private AetheriaInput _input; private int _zoomLevelIndex; - public List Loadouts { get; set; } = new List(); // private ShipInput _shipInput; + private List _shipAgents = new List(); private IDisposable _shipTargetSubscription; private float2 _shipYawPitch; private float3 _viewDirection; private (HardpointData[] hardpoints, Transform[] barrels, PlaceUIElementWorldspace crosshair)[] _articulationGroups; private (LockWeapon targetLock, PlaceUIElementWorldspace indicator, Rotate spin)[] _lockingIndicators; - public List PlayerShips { get; } = new List(); + + public List PlayerEntities { get; } = new List(); public EquippedDockingBay DockingBay { get; private set; } public Entity DockedEntity { get; private set; } @@ -69,6 +71,7 @@ public class ActionGameManager : MonoBehaviour public DatabaseCache ItemData { get; private set; } public ItemManager ItemManager { get; private set; } public Zone Zone { get; private set; } + public List Loadouts { get; } = new List(); private readonly (float2 direction, string name)[] _directions = { (float2(0, 1), "Front"), @@ -79,7 +82,7 @@ public class ActionGameManager : MonoBehaviour public void SaveLoadout(EntityPack pack) { - File.WriteAllBytes(Path.Combine(_presetPath.FullName, $"{pack.Name}.preset"), MessagePackSerializer.Serialize(pack)); + File.WriteAllBytes(Path.Combine(_loadoutPath.FullName, $"{pack.Name}.preset"), MessagePackSerializer.Serialize(pack)); } void Start() @@ -90,12 +93,12 @@ public class ActionGameManager : MonoBehaviour ConsoleController.MessageReceiver = this; _filePath = new DirectoryInfo(Application.dataPath).Parent.CreateSubdirectory("GameData"); - _presetPath = _filePath.CreateSubdirectory("Presets"); + _loadoutPath = _filePath.CreateSubdirectory("Loadouts"); ItemData = new DatabaseCache(); ItemData.Load(_filePath.FullName); ItemManager = new ItemManager(ItemData, Settings.GameplaySettings, Debug.Log); - Loadouts.AddRange(_presetPath.EnumerateFiles("*.preset") + Loadouts.AddRange(_loadoutPath.EnumerateFiles("*.preset") .Select(fi => MessagePackSerializer.Deserialize(File.ReadAllBytes(fi.FullName)))); var zoneFile = Path.Combine(_filePath.FullName, "Home.zone"); @@ -112,6 +115,7 @@ public class ActionGameManager : MonoBehaviour ); Zone = new Zone(Settings.PlanetSettings, zonePack); + Zone.Log = s => Debug.Log($"Zone: {s}"); SectorRenderer.ItemManager = ItemManager; SectorRenderer.LoadZone(Zone); @@ -353,38 +357,34 @@ public class ActionGameManager : MonoBehaviour var dockingBay = ItemManager.CreateInstance(dockingBayData, 1, 1) as EquippableItem; station.TryEquip(dockingBay); station.Active = true; - - var reactorData = ItemData.GetAll().First(x => x.HardpointType == HardpointType.Reactor && x.Shape.Height == 2); - var radiatorData = ItemData.GetAll().First(x => x.Name == "Long Radiator"); - var autocannonData = ItemData.GetAll().First(x => x.Name == "Autocannon"); - var ammoData = ItemData.GetAll().First(x => x.Name == "Autocannon Ammo"); - var turretType = ItemData.GetAll().First(x=>x.HullType==HullType.Turret); - var controlModuleData = ItemData.GetAll().First(x => x.Name == "Murder Module"); - var cargo1Data = ItemData.GetAll().First(x => x.Name == "Cargo Bay 1x1"); + var turretLoadout = Loadouts.First(x => x.Name == "Turret"); - for(int i=0; i<5; i++) + for(int i=0; i<3; i++) { - var turretParent = Zone.PlanetInstances.Values.OrderByDescending(p => p.BodyData.Mass.Value).ElementAt(5+i); - var turretParentOrbit = turretParent.Orbit.Data.ID; - var turretParentPos = Zone.GetOrbitPosition(turretParentOrbit); - var turretPos = turretParentPos + ItemManager.Random.NextFloat2Direction() * turretParent.GravityWellRadius.Value * .25f; - var turretOrbit = Zone.CreateOrbit(turretParentOrbit, turretPos); - var turret = new OrbitalEntity(ItemManager, Zone, ItemManager.CreateInstance(turretType, 0, 1) as EquippableItem, turretOrbit.ID); - turret.TryEquip(ItemManager.CreateInstance(reactorData, .5f, 1) as EquippableItem); - turret.TryEquip(ItemManager.CreateInstance(radiatorData, .5f, 1) as EquippableItem); - turret.TryEquip(ItemManager.CreateInstance(radiatorData, .5f, 1) as EquippableItem); - turret.TryEquip(ItemManager.CreateInstance(controlModuleData, .5f, 1) as EquippableItem); - turret.TryEquip(ItemManager.CreateInstance(autocannonData, .5f, 1) as EquippableItem); - turret.TryEquip(ItemManager.CreateInstance(autocannonData, .5f, 1) as EquippableItem); - turret.TryEquip(ItemManager.CreateInstance(cargo1Data, .5f, 1) as EquippableItem); - turret.CargoBays.First().TryStore(ItemManager.CreateInstance(ammoData, 400)); - foreach (var v in turretType.Shape.Coordinates) - turret.HullConductivity[v.x, v.y] = bool2(true); - turret.Active = true; - Zone.Entities.Add(turret); + var planet = Zone.PlanetInstances.Values.OrderByDescending(p => p.BodyData.Mass.Value).ElementAt(4+i); + var planetOrbit = planet.Orbit.Data.ID; + var planetPos = Zone.GetOrbitPosition(planetOrbit); + for (int j = 0; j < 2; j++) + { + var pos = planetPos + ItemManager.Random.NextFloat2Direction() * planet.GravityWellRadius.Value * (.1f + .1f * j); + var orbit = Zone.CreateOrbit(planetOrbit, pos); + var turret = EntityPack.Unpack(ItemManager, Zone, turretLoadout, orbit.ID, true); + turret.Active = true; + Zone.Entities.Add(turret); + } } + var enemyShipLoadout = Loadouts.First(x => ((HullData) ItemManager.GetData(x.Hull)).HullType == HullType.Ship); + var enemyShip = EntityPack.Unpack(ItemManager, Zone, enemyShipLoadout, true); + enemyShip.Active = true; + Zone.Entities.Add(enemyShip); + var agent = new Agent(enemyShip); + var task = new PatrolOrbitsTask(); + task.Circuit = Zone.Orbits.OrderBy(_ => Random.value).Take(4).Select(x => x.Key).ToArray(); + agent.Task = task; + _shipAgents.Add(agent); + DockedEntity = station; DockingBay = station.DockingBays.First(); DockCamera.enabled = true; @@ -544,25 +544,20 @@ public class ActionGameManager : MonoBehaviour { foreach (var bay in CurrentShip.Parent.DockingBays) { - if (PlayerShips.Contains(bay.DockedShip)) yield return bay; + if (PlayerEntities.Contains(bay.DockedShip)) yield return bay; } } } - public IEnumerable AvailableShips() + public IEnumerable AvailableEntities() { - if (CurrentShip != null) - { - if (CurrentShip.Parent != null) + if(DockedEntity != null) + foreach (var entity in PlayerEntities) { - foreach (var ship in PlayerShips) - { - if (CurrentShip.Parent.Children.Contains(ship)) yield return ship; - } + if (DockedEntity.Children.Contains(entity)) yield return entity; } - else - yield return CurrentShip; - } + else if (CurrentShip != null) + yield return CurrentShip; } void Update() @@ -580,6 +575,8 @@ public class ActionGameManager : MonoBehaviour CurrentShip.MovementDirection = _input.Player.Move.ReadValue(); } } + foreach(var agent in _shipAgents) + agent.Update(Time.deltaTime); Zone.Update(_time, Time.deltaTime); SectorRenderer.Time = _time; } diff --git a/Assets/Scripts/ServerShared/AetheriaMath.cs b/Assets/Scripts/ServerShared/AetheriaMath.cs index b4bd10db0..cf4ef5071 100644 --- a/Assets/Scripts/ServerShared/AetheriaMath.cs +++ b/Assets/Scripts/ServerShared/AetheriaMath.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using Unity.Mathematics; using static Unity.Mathematics.math; -public class AetheriaMath +public static class AetheriaMath { //first-order intercept using absolute target position public static float3 FirstOrderIntercept diff --git a/Assets/Scripts/ServerShared/Agents/AgentBehavior.cs b/Assets/Scripts/ServerShared/Agents/AgentBehavior.cs index c278a3de2..e1bac9549 100644 --- a/Assets/Scripts/ServerShared/Agents/AgentBehavior.cs +++ b/Assets/Scripts/ServerShared/Agents/AgentBehavior.cs @@ -2,10 +2,15 @@ * 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.Collections; using System.Collections.Generic; +using System.Linq; +using RethinkDb.Driver.Ast; +using UniRx; using Unity.Mathematics; using static Unity.Mathematics.math; +using float2 = Unity.Mathematics.float2; public abstract class AgentBehavior { @@ -32,3 +37,167 @@ public abstract class AgentBehavior ControllerData = controllerData; } } + +public class Agent +{ + private BaseState _rootState; + private BaseState _currentState; + private Dictionary> _stateTransitions = new Dictionary>(); + + public AgentTask Task { get; set; } + public Ship Ship { get; } + public ItemManager ItemManager { get; } + public GameplaySettings Settings { get; } + + public Agent(Ship ship) + { + Ship = ship; + ItemManager = Ship.ItemManager; + Settings = Ship.ItemManager.GameplaySettings; + + _rootState = _currentState = new BaseState(this); + + var patrolState = new PatrolOrbitsState(this); + AddTransition(_rootState, patrolState, + () => Task is PatrolOrbitsTask, + () => patrolState.Task = Task as PatrolOrbitsTask); + var patrolMoveState = new MoveToOrbitState(this); + AddTransition(patrolState, patrolMoveState, + () => true, + () => patrolMoveState.Orbit = patrolState.CurrentTarget); + AddTransition(patrolMoveState, patrolState, + () => patrolMoveState.Distance < 10, + () => patrolState.NextTarget()); + } + + public void AddTransition(BaseState source, BaseState targetState, Func condition, Action onTransition = null) + { + if(!_stateTransitions.ContainsKey(source)) + _stateTransitions[source] = new List(); + _stateTransitions[source].Add(new StateTransition(targetState, condition, onTransition)); + } + + public void Transition(BaseState targetState, Action onTransition = null) + { + _currentState.OnExitState(); + _currentState = targetState; + onTransition?.Invoke(); + _currentState.OnEnterState(); + } + + public void Update(float delta) + { + _currentState.Update(delta); + foreach (var transition in _stateTransitions[_currentState]) + if (transition.Condition()) + { + Transition(transition.TargetState, transition.OnTransition); + break; + } + } + + public class StateTransition + { + public StateTransition(BaseState targetState, Func condition, Action onTransition) + { + TargetState = targetState; + Condition = condition; + OnTransition = onTransition; + } + + public BaseState TargetState { get; } + public Func Condition { get; } + public Action OnTransition { get; } + } +} + +public class BaseState +{ + protected Agent _agent; + + public BaseState(Agent agent) + { + _agent = agent; + } + public virtual void Update(float delta){} + public virtual void OnEnterState(){} + public virtual void OnExitState(){} +} + +public abstract class MoveToState : BaseState +{ + private const float FORWARD_DELTA_THRESHOLD = 20; + private const float THRUST_DELTA_THRESHOLD = 1; + private VelocityLimit _velocityLimit; + protected abstract float2 TargetPosition { get; } + public float Distance { get; private set; } + + protected MoveToState(Agent agent) : base(agent) + { + _velocityLimit = agent.Ship.GetBehavior(); + } + + public override void Update(float delta) + { + var diff = TargetPosition - _agent.Ship.Position.xz; + var dir = normalize(diff); + Distance = length(diff); + + // We want to go top speed in the direction of our target + var topSpeed = _velocityLimit?.Limit ?? 100; + var desiredVelocity = dir * topSpeed; + var deltaV = desiredVelocity - _agent.Ship.Velocity; + var deltaVMag = length(deltaV); + var deltaVDirection = normalize(deltaV); + // If Delta V is above the threshold, direct the ship towards the delta and use only main thrusters + if (deltaVMag > FORWARD_DELTA_THRESHOLD) + { + _agent.Ship.LookDirection = float3(deltaVDirection.x, 0, deltaVDirection.y); + _agent.Ship.MovementDirection = float2(0, pow(dot(_agent.Ship.Direction, deltaVDirection), 2)); + } + // If Delta V is low, direct the ship towards the target and use all thrusters + else if(deltaVMag > THRUST_DELTA_THRESHOLD) + { + var right = _agent.Ship.Direction.Rotate(ItemRotation.Clockwise); + _agent.Ship.LookDirection = float3(dir.x, 0, dir.y); + _agent.Ship.MovementDirection = float2(dot(right, deltaVDirection), dot(_agent.Ship.Direction, deltaVDirection)); + } + else + { + _agent.Ship.LookDirection = float3(dir.x, 0, dir.y); + _agent.Ship.MovementDirection = float2.zero; + } + } +} + +public class MoveToEntityState : MoveToState +{ + public Entity TargetEntity { get; set; } + protected override float2 TargetPosition => TargetEntity?.Position.xz ?? float2.zero; + + public MoveToEntityState(Agent agent) : base(agent) { } +} + +public class MoveToOrbitState : MoveToState +{ + public Guid Orbit { get; set; } + public MoveToOrbitState(Agent agent) : base(agent) { } + + protected override float2 TargetPosition => _agent.Ship.Zone.GetOrbitPosition(Orbit); +} + +public class PatrolOrbitsState : BaseState +{ + public PatrolOrbitsTask Task; + public Guid CurrentTarget + { + get => Task.Circuit[_currentTargetIndex]; + } + private int _currentTargetIndex; + public void NextTarget() + { + _currentTargetIndex++; + _currentTargetIndex %= Task.Circuit.Length; + } + public PatrolOrbitsState(Agent agent) : base(agent) { } +} \ No newline at end of file diff --git a/Assets/Scripts/ServerShared/Agents/AgentTask.cs b/Assets/Scripts/ServerShared/Agents/AgentTask.cs index 7ce487ce3..d8bc72a94 100644 --- a/Assets/Scripts/ServerShared/Agents/AgentTask.cs +++ b/Assets/Scripts/ServerShared/Agents/AgentTask.cs @@ -39,3 +39,9 @@ public enum TaskType Attack, Explore } + +public class PatrolOrbitsTask : AgentTask +{ + public override TaskType Type => TaskType.Defend; + public Guid[] Circuit; +} diff --git a/Assets/Scripts/ServerShared/Agents/Locomotion.cs b/Assets/Scripts/ServerShared/Agents/Locomotion.cs index 7387a0299..17dbf0a64 100644 --- a/Assets/Scripts/ServerShared/Agents/Locomotion.cs +++ b/Assets/Scripts/ServerShared/Agents/Locomotion.cs @@ -32,7 +32,7 @@ public class Locomotion : AgentBehavior var diff = Objective - Entity.Position.xz; // We want to go top speed in the direction of our target - var topSpeed = _velocityLimit?.Limit ?? 1000; + var topSpeed = _velocityLimit?.Limit ?? 100; float2 desiredVelocity = normalize(diff) * topSpeed; var accelerationTime = length(desiredVelocity - Entity.Velocity) / (_thrust / Entity.Mass); diff --git a/Assets/Scripts/ServerShared/Behaviors/ChargedWeapon.cs b/Assets/Scripts/ServerShared/Behaviors/ChargedWeapon.cs index 9e5afee63..f755d6bc5 100644 --- a/Assets/Scripts/ServerShared/Behaviors/ChargedWeapon.cs +++ b/Assets/Scripts/ServerShared/Behaviors/ChargedWeapon.cs @@ -9,40 +9,40 @@ using static Unity.Mathematics.math; [InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable] public class ChargedWeaponData : InstantWeaponData { - [InspectableField, JsonProperty("chargeTime"), Key(19), RuntimeInspectable] + [InspectableField, JsonProperty("chargeTime"), Key(21), RuntimeInspectable] public PerformanceStat ChargeTime = new PerformanceStat(); - [InspectableField, JsonProperty("chargeEnergy"), Key(20), RuntimeInspectable] + [InspectableField, JsonProperty("chargeEnergy"), Key(22), RuntimeInspectable] public PerformanceStat ChargeEnergy = new PerformanceStat(); - [InspectableField, JsonProperty("chargeHeat"), Key(21), RuntimeInspectable] + [InspectableField, JsonProperty("chargeHeat"), Key(23), RuntimeInspectable] public PerformanceStat ChargeHeat = new PerformanceStat(); - [InspectableField, JsonProperty("canFireEarly"), Key(22)] + [InspectableField, JsonProperty("canFireEarly"), Key(24)] public bool CanFireEarly; - [InspectableField, JsonProperty("failureCharge"), Key(23)] + [InspectableField, JsonProperty("failureCharge"), Key(25)] public float FailureCharge; - [InspectableField, JsonProperty("failureDamage"), Key(24)] + [InspectableField, JsonProperty("failureDamage"), Key(26)] public float FailureDamage = 1; - [InspectableField, JsonProperty("chargeDamage"), Key(25)] + [InspectableField, JsonProperty("chargeDamage"), Key(27)] public float ChargeFiringDamageMultiplier = 1; - [InspectableField, JsonProperty("chargeSpread"), Key(26)] + [InspectableField, JsonProperty("chargeSpread"), Key(28)] public float ChargeFiringSpreadMultiplier = 1; - [InspectableField, JsonProperty("chargeBurstCount"), Key(27)] + [InspectableField, JsonProperty("chargeBurstCount"), Key(29)] public float ChargeFiringBurstCountMultiplier = 1; - [InspectableField, JsonProperty("chargeVisibility"), Key(28)] + [InspectableField, JsonProperty("chargeVisibility"), Key(30)] public float ChargeFiringVisibilityMultiplier = 1; - [InspectableField, JsonProperty("chargeVelocity"), Key(29)] + [InspectableField, JsonProperty("chargeVelocity"), Key(31)] public float ChargeFiringVelocityMultiplier = 1; - [InspectableField, JsonProperty("chargeHeatMul"), Key(30)] + [InspectableField, JsonProperty("chargeHeatMul"), Key(32)] public float ChargeFiringHeatMultiplier = 1; public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item) @@ -131,7 +131,7 @@ public class ChargedWeapon : InstantWeapon public override void Activate() { - if(!_coolingDown) + if(!_charging && !_coolingDown) { OnStartCharging?.Invoke(); _charging = true; diff --git a/Assets/Scripts/ServerShared/Behaviors/ConstantWeapon.cs b/Assets/Scripts/ServerShared/Behaviors/ConstantWeapon.cs index c7e8f3325..5ce26c0c2 100644 --- a/Assets/Scripts/ServerShared/Behaviors/ConstantWeapon.cs +++ b/Assets/Scripts/ServerShared/Behaviors/ConstantWeapon.cs @@ -11,7 +11,7 @@ using static Unity.Mathematics.math; [InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)] public class ConstantWeaponData : WeaponData { - [InspectablePrefab, JsonProperty("ammoInterval"), Key(15)] + [InspectablePrefab, JsonProperty("ammoInterval"), Key(17)] public float AmmoInterval = 1; public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item) @@ -112,7 +112,7 @@ public class ConstantWeapon : Weapon, IProgressBehavior public override void Activate() { - if(!_reloading) + if(!_firing && !_reloading) { _firing = true; OnStartFiring?.Invoke(); diff --git a/Assets/Scripts/ServerShared/Behaviors/InstantWeapon.cs b/Assets/Scripts/ServerShared/Behaviors/InstantWeapon.cs index 1660e241b..079aa9dff 100644 --- a/Assets/Scripts/ServerShared/Behaviors/InstantWeapon.cs +++ b/Assets/Scripts/ServerShared/Behaviors/InstantWeapon.cs @@ -9,16 +9,16 @@ using static Unity.Mathematics.math; [InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable] public class InstantWeaponData : WeaponData { - [InspectableField, JsonProperty("count"), Key(15)] + [InspectableField, JsonProperty("count"), Key(17)] public PerformanceStat Count = new PerformanceStat(); - [InspectableField, JsonProperty("burstTime"), Key(16)] + [InspectableField, JsonProperty("burstTime"), Key(18)] public PerformanceStat BurstTime = new PerformanceStat(); - [InspectableField, JsonProperty("cooldown"), Key(17), RuntimeInspectable] + [InspectableField, JsonProperty("cooldown"), Key(19), RuntimeInspectable] public PerformanceStat Cooldown = new PerformanceStat(); - [InspectablePrefab, JsonProperty("ammoInterval"), Key(18)] + [InspectablePrefab, JsonProperty("ammoInterval"), Key(20)] public bool SingleAmmoBurst; public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item) diff --git a/Assets/Scripts/ServerShared/Behaviors/Launcher.cs b/Assets/Scripts/ServerShared/Behaviors/Launcher.cs index 6b67b03de..17cb72e19 100644 --- a/Assets/Scripts/ServerShared/Behaviors/Launcher.cs +++ b/Assets/Scripts/ServerShared/Behaviors/Launcher.cs @@ -9,22 +9,22 @@ using Unity.Mathematics; [InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)] public class LauncherData : LockWeaponData { - [InspectableAnimationCurve, JsonProperty("guidance"), Key(24)] + [InspectableAnimationCurve, JsonProperty("guidance"), Key(26)] public float4[] GuidanceCurve; - [InspectableAnimationCurve, JsonProperty("thrustCurve"), Key(25)] + [InspectableAnimationCurve, JsonProperty("thrustCurve"), Key(27)] public float4[] ThrustCurve; - [InspectableAnimationCurve, JsonProperty("liftCurve"), Key(26)] + [InspectableAnimationCurve, JsonProperty("liftCurve"), Key(28)] public float4[] LiftCurve; - [InspectableField, JsonProperty("thrust"), Key(27)] + [InspectableField, JsonProperty("thrust"), Key(29)] public PerformanceStat Thrust = new PerformanceStat(); - [InspectableField, JsonProperty("frequency"), Key(28)] + [InspectableField, JsonProperty("frequency"), Key(30)] public float DodgeFrequency; - [InspectableField, JsonProperty("missileSpeed"), Key(29), RuntimeInspectable] + [InspectableField, JsonProperty("missileSpeed"), Key(31), RuntimeInspectable] public PerformanceStat MissileVelocity = new PerformanceStat(); public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item) @@ -36,22 +36,22 @@ public class LauncherData : LockWeaponData [InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)] public class GuidedWeaponData : InstantWeaponData { - [InspectableAnimationCurve, JsonProperty("guidance"), Key(24)] + [InspectableAnimationCurve, JsonProperty("guidance"), Key(21)] public float4[] GuidanceCurve; - [InspectableAnimationCurve, JsonProperty("thrustCurve"), Key(25)] + [InspectableAnimationCurve, JsonProperty("thrustCurve"), Key(22)] public float4[] ThrustCurve; - [InspectableAnimationCurve, JsonProperty("liftCurve"), Key(26)] + [InspectableAnimationCurve, JsonProperty("liftCurve"), Key(23)] public float4[] LiftCurve; - [InspectableField, JsonProperty("thrust"), Key(27)] + [InspectableField, JsonProperty("thrust"), Key(24)] public PerformanceStat Thrust = new PerformanceStat(); - [InspectableField, JsonProperty("frequency"), Key(28)] + [InspectableField, JsonProperty("frequency"), Key(25)] public float DodgeFrequency; - [InspectableField, JsonProperty("missileSpeed"), Key(29), RuntimeInspectable] + [InspectableField, JsonProperty("missileSpeed"), Key(26), RuntimeInspectable] public PerformanceStat MissileVelocity = new PerformanceStat(); public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item) diff --git a/Assets/Scripts/ServerShared/Behaviors/LockWeapon.cs b/Assets/Scripts/ServerShared/Behaviors/LockWeapon.cs index 46e07f7b1..ee9a864af 100644 --- a/Assets/Scripts/ServerShared/Behaviors/LockWeapon.cs +++ b/Assets/Scripts/ServerShared/Behaviors/LockWeapon.cs @@ -9,19 +9,19 @@ using static Unity.Mathematics.math; [InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable] public class LockWeaponData : InstantWeaponData { - [InspectableField, JsonProperty("speed"), Key(19), RuntimeInspectable] + [InspectableField, JsonProperty("speed"), Key(21), RuntimeInspectable] public PerformanceStat LockSpeed = new PerformanceStat(); - [InspectableField, JsonProperty("sensorImpact"), Key(20)] + [InspectableField, JsonProperty("sensorImpact"), Key(22)] public PerformanceStat SensorImpact = new PerformanceStat(); - [InspectableField, JsonProperty("threshold"), Key(21), RuntimeInspectable] + [InspectableField, JsonProperty("threshold"), Key(23), RuntimeInspectable] public PerformanceStat LockAngle = new PerformanceStat(); - [InspectableField, JsonProperty("directionImpact"), Key(22)] + [InspectableField, JsonProperty("directionImpact"), Key(24)] public PerformanceStat DirectionImpact = new PerformanceStat(); - [InspectableField, JsonProperty("decay"), Key(23)] + [InspectableField, JsonProperty("decay"), Key(25)] public PerformanceStat Decay = new PerformanceStat(); public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item) diff --git a/Assets/Scripts/ServerShared/Behaviors/Sensor.cs b/Assets/Scripts/ServerShared/Behaviors/Sensor.cs index 348d91f39..d4462594a 100644 --- a/Assets/Scripts/ServerShared/Behaviors/Sensor.cs +++ b/Assets/Scripts/ServerShared/Behaviors/Sensor.cs @@ -4,12 +4,17 @@ using MessagePack; using Newtonsoft.Json; +using Unity.Mathematics; +using static Unity.Mathematics.math; [InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable] public class SensorData : BehaviorData { [InspectableField, JsonProperty("sensitivity"), Key(3), RuntimeInspectable] public PerformanceStat Sensitivity = new PerformanceStat(); + + [InspectableField, JsonProperty("sensitivityCurve"), Key(4), RuntimeInspectable] + public float4[] SensitivityCurve; public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item) { @@ -38,6 +43,21 @@ public class Sensor : IBehavior public bool Execute(float delta) { // TODO: Handle Active Detection / Visibility From Reflected Radiance + var hardpoint = Entity.Hardpoints[Item.Position.x, Item.Position.y]; + var forward = Entity.HardpointTransforms.ContainsKey(hardpoint) ? + normalize(Entity.HardpointTransforms[hardpoint].direction.xz) : + Entity.Direction; + foreach (var entity in Entity.Zone.Entities) + { + var diff = entity.Position.xz - Entity.Position.xz; + var angle = acos(dot(forward, normalize(diff))); + var dist = length(diff); + Entity.EntityInfoGathered[entity] += + entity.Visibility * + Context.Evaluate(_data.Sensitivity, Item.EquippableItem, Entity) * + _data.SensitivityCurve.Evaluate(angle / PI) * + delta / dist; + } return true; // var ship = Hardpoint.Ship.Ship.transform; // var contacts = diff --git a/Assets/Scripts/ServerShared/Behaviors/Weapon.cs b/Assets/Scripts/ServerShared/Behaviors/Weapon.cs index 9a1bd8177..b6c699eeb 100644 --- a/Assets/Scripts/ServerShared/Behaviors/Weapon.cs +++ b/Assets/Scripts/ServerShared/Behaviors/Weapon.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Linq; using MessagePack; using Newtonsoft.Json; +using Unity.Mathematics; [Union(0, typeof(InstantWeaponData)), Union(1, typeof(LauncherData)), @@ -27,34 +28,40 @@ public abstract class WeaponData : BehaviorData [RangedFloatInspectable(0,1), JsonProperty("damageSpread"), Key(4)] public PerformanceStat DamageSpread = new PerformanceStat(); - [InspectableField, JsonProperty("range"), Key(5), RuntimeInspectable] + [InspectableField, JsonProperty("minRange"), Key(5), RuntimeInspectable] + public PerformanceStat MinRange = new PerformanceStat(); + + [InspectableField, JsonProperty("range"), Key(6), RuntimeInspectable] public PerformanceStat Range = new PerformanceStat(); + + [InspectableAnimationCurve, JsonProperty("damageRange"), Key(7), RuntimeInspectable] + public float4[] DamageCurve; - [InspectablePrefab, JsonProperty("effect"), Key(6)] + [InspectablePrefab, JsonProperty("effect"), Key(8)] public string EffectPrefab; - [InspectablePrefab, JsonProperty("energy"), Key(7), RuntimeInspectable] + [InspectablePrefab, JsonProperty("energy"), Key(9), RuntimeInspectable] public PerformanceStat Energy = new PerformanceStat(); - [InspectablePrefab, JsonProperty("heat"), Key(8), RuntimeInspectable] + [InspectablePrefab, JsonProperty("heat"), Key(10), RuntimeInspectable] public PerformanceStat Heat = new PerformanceStat(); - [InspectablePrefab, JsonProperty("visibility"), Key(9), RuntimeInspectable] + [InspectablePrefab, JsonProperty("visibility"), Key(11), RuntimeInspectable] public PerformanceStat Visibility = new PerformanceStat(); - [InspectableDatabaseLink(typeof(SimpleCommodityData)), JsonProperty("ammo"), Key(10), RuntimeInspectable] + [InspectableDatabaseLink(typeof(SimpleCommodityData)), JsonProperty("ammo"), Key(12), RuntimeInspectable] public Guid AmmoType; - [InspectablePrefab, JsonProperty("magSize"), Key(11)] + [InspectablePrefab, JsonProperty("magSize"), Key(13)] public int MagazineSize; - [InspectablePrefab, JsonProperty("reloadTime"), Key(12)] + [InspectablePrefab, JsonProperty("reloadTime"), Key(14)] public float ReloadTime = 1; - [InspectablePrefab, JsonProperty("spread"), Key(13)] + [InspectablePrefab, JsonProperty("spread"), Key(15)] public PerformanceStat Spread = new PerformanceStat(); - [InspectableField, JsonProperty("velocity"), Key(14)] + [InspectableField, JsonProperty("velocity"), Key(16)] public PerformanceStat Velocity = new PerformanceStat(); } @@ -73,6 +80,7 @@ public abstract class Weapon : IActivatedBehavior public float Damage { get; protected set; } public float Penetration { get; protected set; } public float DamageSpread { get; protected set; } + public float MinRange { get; protected set; } public float Range { get; protected set; } public float Energy { get; protected set; } public float Heat { get; protected set; } @@ -103,6 +111,7 @@ public abstract class Weapon : IActivatedBehavior 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); diff --git a/Assets/Scripts/ServerShared/Corporations.cs b/Assets/Scripts/ServerShared/Corporations.cs index 2b95cae11..0d767278d 100644 --- a/Assets/Scripts/ServerShared/Corporations.cs +++ b/Assets/Scripts/ServerShared/Corporations.cs @@ -48,18 +48,9 @@ public class MegaCorporation : DatabaseEntry, INamedEntry [InspectableDatabaseLink(typeof(PersonalityAttribute)), JsonProperty("personality"), Key(4)] public Dictionary Personality = new Dictionary(); - - [InspectableDatabaseLink(typeof(LoadoutData)), JsonProperty("initialFleet"), Key(5)] - public Dictionary InitialFleet = new Dictionary(); - - [InspectableDatabaseLink(typeof(BlueprintData)), JsonProperty("initialTechs"), Key(6)] - public List InitialTechnologies = new List(); - [JsonProperty("parent"), Key(7)] - public Guid HomeZone; - - [InspectableField, JsonProperty("placement"), Key(8)] - public MegaPlacementType PlacementType; + [InspectableField, JsonProperty("hostile"), Key(5)] + public bool PlayerHostile; [IgnoreMember] public string EntryName { diff --git a/Assets/Scripts/ServerShared/Entity.cs b/Assets/Scripts/ServerShared/Entity.cs index 98bd34563..31175b19f 100644 --- a/Assets/Scripts/ServerShared/Entity.cs +++ b/Assets/Scripts/ServerShared/Entity.cs @@ -21,6 +21,7 @@ using int2 = Unity.Mathematics.int2; public abstract class Entity { public Zone Zone; + public MegaCorporation Faction; public EquippableItem Hull; public float3 Position; @@ -50,6 +51,7 @@ public abstract class Entity public readonly Dictionary Messages = new Dictionary(); public readonly Dictionary VisibilitySources = new Dictionary(); + public readonly Dictionary EntityInfoGathered = new Dictionary(); public readonly Dictionary HardpointTransforms = new Dictionary(); @@ -63,8 +65,19 @@ public abstract class Entity public float[,] MaxArmor; private EquippedItem[] _orderedEquipment; + private List _weapons = new List(); + private List _weaponsInRange = new List(); protected bool _active; + public IEnumerable Weapons + { + get => _weapons; + } + public IEnumerable WeaponsInRange + { + get => _weaponsInRange; + } + public float MaxTemp { get; private set; } public float MinTemp { get; private set; } public ItemManager ItemManager { get; } @@ -246,6 +259,9 @@ public abstract class Entity GearOccupancy[i.x, i.y] = null; } Mass -= itemData.Mass; + foreach (var b in item.Behaviors) + if (b is Weapon weapon) + _weapons.Add(weapon); return item.EquippableItem; } @@ -397,6 +413,9 @@ public abstract class Entity { equippedItem = new EquippedItem(ItemManager, item, hullCoord, this); Equipment.Add(equippedItem); + foreach (var b in equippedItem.Behaviors) + if (b is Weapon weapon) + _weapons.Add(weapon); } foreach (var i in itemData.Shape.Coordinates) @@ -537,6 +556,15 @@ public abstract class Entity public virtual void Update(float delta) { var hullData = ItemManager.GetData(Hull) as HullData; + + _weaponsInRange.Clear(); + if (Target.Value != null) + { + var dist = length(Position - Target.Value.Position); + foreach (var w in _weapons) + if (w.MinRange < dist && dist < w.Range) + _weaponsInRange.Add(w); + } foreach (var v in VisibilitySources.Keys.ToArray()) { diff --git a/Assets/Scripts/ServerShared/Settings.cs b/Assets/Scripts/ServerShared/Settings.cs index 650d25e76..97315826e 100644 --- a/Assets/Scripts/ServerShared/Settings.cs +++ b/Assets/Scripts/ServerShared/Settings.cs @@ -111,5 +111,9 @@ public class GameplaySettings public float TorqueFloor; public float TorqueMultiplier; public float VisibilityDecay; + public float TargetInfoDecay; + public float TargetDetectionInfoThreshold; + public float TargetArmorInfoThreshold; + public float TargetGearInfoThreshold; public float ConvergenceMinimumDistance; } \ No newline at end of file diff --git a/Assets/Scripts/ServerShared/Ship.cs b/Assets/Scripts/ServerShared/Ship.cs index 8b8ed7489..09eb37e37 100644 --- a/Assets/Scripts/ServerShared/Ship.cs +++ b/Assets/Scripts/ServerShared/Ship.cs @@ -9,6 +9,7 @@ using System.Linq; using System.Reflection; using MessagePack; using Newtonsoft.Json; +using UniRx; using Unity.Mathematics; using static Unity.Mathematics.math; using quaternion = Unity.Mathematics.quaternion; @@ -26,28 +27,127 @@ public class Ship : Entity public float2 MovementDirection; private Thruster[] _allThrusters; - private Thruster[] _forwardThrusters; - private Thruster[] _reverseThrusters; - private Thruster[] _rightThrusters; - private Thruster[] _leftThrusters; - private Thruster[] _clockwiseThrusters; - private Thruster[] _counterClockwiseThrusters; + private HashSet _forwardThrusters; + private HashSet _reverseThrusters; + private HashSet _rightThrusters; + private HashSet _leftThrusters; + private HashSet _clockwiseThrusters; + private HashSet _counterClockwiseThrusters; + + public float ForwardThrust { get; private set; } + public float ReverseThrust { get; private set; } + public float LeftStrafeThrust { get; private set; } + public float RightStrafeThrust { get; private set; } + public float ClockwiseTorque { get; private set; } + public float CounterClockwiseTorque { get; private set; } public quaternion Rotation { get; private set; } protected override void OnActivate() { _allThrusters = GetBehaviors().ToArray(); - _forwardThrusters = _allThrusters.Where(x => x.Item.EquippableItem.Rotation == ItemRotation.Reversed).ToArray(); - _reverseThrusters = _allThrusters.Where(x => x.Item.EquippableItem.Rotation == ItemRotation.None).ToArray(); - _rightThrusters = _allThrusters.Where(x => x.Item.EquippableItem.Rotation == ItemRotation.CounterClockwise).ToArray(); - _leftThrusters = _allThrusters.Where(x => x.Item.EquippableItem.Rotation == ItemRotation.Clockwise).ToArray(); - _counterClockwiseThrusters = _allThrusters.Where(x => x.Torque < -ItemManager.GameplaySettings.TorqueFloor).ToArray(); - _clockwiseThrusters = _allThrusters.Where(x => x.Torque > ItemManager.GameplaySettings.TorqueFloor).ToArray(); + + _forwardThrusters = new HashSet(_allThrusters + .Where(x => x.Item.EquippableItem.Rotation == ItemRotation.Reversed)); + RecalculateForwardThrust(); + + _reverseThrusters = new HashSet(_allThrusters + .Where(x => x.Item.EquippableItem.Rotation == ItemRotation.None)); + RecalculateReverseThrust(); + + _rightThrusters = new HashSet(_allThrusters + .Where(x => x.Item.EquippableItem.Rotation == ItemRotation.CounterClockwise)); + RecalculateRightStrafeThrust(); + + _leftThrusters = new HashSet(_allThrusters + .Where(x => x.Item.EquippableItem.Rotation == ItemRotation.Clockwise)); + RecalculateLeftStrafeThrust(); + + _counterClockwiseThrusters = new HashSet(_allThrusters + .Where(x => x.Torque < -ItemManager.GameplaySettings.TorqueFloor)); + RecalculateCounterClockwiseTorque(); + + _clockwiseThrusters = new HashSet(_allThrusters + .Where(x => x.Torque > ItemManager.GameplaySettings.TorqueFloor)); + RecalculateClockwiseTorque(); } public Ship(ItemManager itemManager, Zone zone, EquippableItem hull) : base(itemManager, zone, hull) { + ItemDamage.Subscribe(x => + { + if (Hardpoints[x.item.Position.x, x.item.Position.y]?.Type == HardpointType.Thruster) + { + foreach (var behavior in x.item.Behaviors) + { + if (behavior is Thruster thruster) + { + if(_forwardThrusters.Contains(thruster)) RecalculateForwardThrust(); + if(_reverseThrusters.Contains(thruster)) RecalculateReverseThrust(); + if(_rightThrusters.Contains(thruster)) RecalculateRightStrafeThrust(); + if(_leftThrusters.Contains(thruster)) RecalculateLeftStrafeThrust(); + if(_clockwiseThrusters.Contains(thruster)) RecalculateClockwiseTorque(); + if(_counterClockwiseThrusters.Contains(thruster)) RecalculateCounterClockwiseTorque(); + } + } + if(x.item.EquippableItem.Rotation == ItemRotation.Reversed) + RecalculateForwardThrust(); + } + }); + } + + private void RecalculateForwardThrust() + { + ForwardThrust = 0; + foreach (var thruster in _forwardThrusters) + { + ForwardThrust += thruster.Thrust; + } + } + + private void RecalculateReverseThrust() + { + ReverseThrust = 0; + foreach (var thruster in _reverseThrusters) + { + ReverseThrust += thruster.Thrust; + } + } + + private void RecalculateLeftStrafeThrust() + { + LeftStrafeThrust = 0; + foreach (var thruster in _leftThrusters) + { + LeftStrafeThrust += thruster.Thrust; + } + } + + private void RecalculateRightStrafeThrust() + { + RightStrafeThrust = 0; + foreach (var thruster in _rightThrusters) + { + RightStrafeThrust += thruster.Thrust; + } + } + + private void RecalculateClockwiseTorque() + { + ClockwiseTorque = 0; + foreach (var thruster in _clockwiseThrusters) + { + ClockwiseTorque += thruster.Torque; + } + } + + private void RecalculateCounterClockwiseTorque() + { + CounterClockwiseTorque = 0; + foreach (var thruster in _counterClockwiseThrusters) + { + CounterClockwiseTorque -= thruster.Torque; + } } public override void Update(float delta) diff --git a/Assets/Scripts/ServerShared/Zone.cs b/Assets/Scripts/ServerShared/Zone.cs index a40d3d40a..54bf93853 100644 --- a/Assets/Scripts/ServerShared/Zone.cs +++ b/Assets/Scripts/ServerShared/Zone.cs @@ -16,6 +16,7 @@ using Random = Unity.Mathematics.Random; public class Zone { + public Action Log; //public HashSet Planets = new HashSet(); public ReactiveCollection Entities = new ReactiveCollection(); //public Dictionary Orbits = new Dictionary(); @@ -24,10 +25,10 @@ public class Zone public Dictionary Orbits = new Dictionary(); public Dictionary AsteroidBelts = new Dictionary(); + public PlanetSettings Settings; private HashSet _updatedOrbits = new HashSet(); - public PlanetSettings Settings; private float _time; private Random _random; @@ -121,6 +122,11 @@ public class Zone // Root orbit is fixed at origin if(orbitID==Guid.Empty) return float2.zero; + if (!Orbits.ContainsKey(orbitID)) + { + Log?.Invoke("Requested orbit is not part of this zone!"); + return float2.zero; + } if (!_updatedOrbits.Contains(orbitID)) { diff --git a/Assets/Scripts/UI/InventoryPanel.cs b/Assets/Scripts/UI/InventoryPanel.cs index afb0a1dd7..aa6e39bd9 100644 --- a/Assets/Scripts/UI/InventoryPanel.cs +++ b/Assets/Scripts/UI/InventoryPanel.cs @@ -19,6 +19,7 @@ using int2 = Unity.Mathematics.int2; public class InventoryPanel : MonoBehaviour { + public ConfirmationDialog ConfirmationDialog; public bool Flip; public GameSettings Settings; public ActionGameManager GameManager; @@ -100,9 +101,18 @@ public class InventoryPanel : MonoBehaviour { if (_displayedEntity != GameManager.CurrentShip) { - GameManager.CurrentShip = (Ship) _displayedEntity; - GameManager.DockingBay.DockedShip = (Ship) _displayedEntity; - Current.targetGraphic.color = ToggleEnabledColor; + if(_displayedEntity is Ship ship) + { + GameManager.CurrentShip = ship; + GameManager.DockingBay.DockedShip = ship; + Current.targetGraphic.color = ToggleEnabledColor; + } + else + { + ConfirmationDialog.Clear(); + ConfirmationDialog.Title.text = "Can't select entity, you can only pilot a ship!"; + ConfirmationDialog.Show(); + } } }); } @@ -111,18 +121,18 @@ public class InventoryPanel : MonoBehaviour Dropdown.onClick.AddListener(() => { ContextMenu.Clear(); - foreach (var ship in GameManager.AvailableShips()) + foreach (var entity in GameManager.AvailableEntities()) { - if (ship.CargoBays.Any()) + if (entity.CargoBays.Any()) { - var options = ship.CargoBays + var options = entity.CargoBays .Where(bay => bay != _displayedCargo) .Select((bay, index) => ($"Bay {index}", () => Display(bay), true)); - if(ship != _displayedEntity) options = options.Prepend(("Equipment", () => Display(ship), true)); - ContextMenu.AddDropdown(ship.Name, options); + if(entity != _displayedEntity) options = options.Prepend(("Equipment", () => Display(entity), true)); + ContextMenu.AddDropdown(entity.Name, options); } - else if(ship != _displayedEntity) ContextMenu.AddOption(ship.Name, () => Display(ship)); + else if(entity != _displayedEntity) ContextMenu.AddOption(entity.Name, () => Display(entity)); } if(GameManager.DockingBay!=null && _displayedCargo!=GameManager.DockingBay) @@ -143,7 +153,7 @@ public class InventoryPanel : MonoBehaviour { var ship = EntityPack.Unpack(GameManager.ItemManager, GameManager.Zone, pack, true); ship.SetParent(GameManager.DockedEntity); - GameManager.PlayerShips.Add(ship); + GameManager.PlayerEntities.Add(ship); GameManager.Credits -= pack.Price(GameManager.ItemManager); GameManager.CurrentShip = ship; GameManager.DockingBay.DockedShip = ship; diff --git a/Assets/Scripts/UI/TradeMenu.cs b/Assets/Scripts/UI/TradeMenu.cs index a47c4762f..1b0692002 100644 --- a/Assets/Scripts/UI/TradeMenu.cs +++ b/Assets/Scripts/UI/TradeMenu.cs @@ -272,7 +272,7 @@ public class TradeMenu : MonoBehaviour data => () => { if (data is HullData) - return GameManager.PlayerShips.Count(s => s.Hull.Data == data.ID && s.Parent == GameManager.CurrentShip.Parent).ToString(); + return GameManager.PlayerEntities.Count(s => s.Hull.Data == data.ID && s.Parent == GameManager.DockedEntity).ToString(); if(data is SimpleCommodityData) return (_targetCargo.ItemsOfType.ContainsKey(data.ID) ? _targetCargo.ItemsOfType[data.ID].Cast().Sum(s=>s.Quantity) : 0).ToString(); return (_targetCargo.ItemsOfType.ContainsKey(data.ID) ? _targetCargo.ItemsOfType[data.ID].Count : 0).ToString(); @@ -280,7 +280,7 @@ public class TradeMenu : MonoBehaviour data => { if (data is HullData) - return GameManager.PlayerShips.Count(s => s.Hull.Data == data.ID && s.Parent == GameManager.CurrentShip.Parent); + return GameManager.PlayerEntities.Count(s => s.Hull.Data == data.ID && s.Parent == GameManager.DockedEntity); if(data is SimpleCommodityData) return _targetCargo.ItemsOfType.ContainsKey(data.ID) ? _targetCargo.ItemsOfType[data.ID].Cast().Sum(s=>s.Quantity) : 0; return _targetCargo.ItemsOfType.ContainsKey(data.ID) ? _targetCargo.ItemsOfType[data.ID].Count : 0; @@ -355,9 +355,13 @@ public class TradeMenu : MonoBehaviour { if (data.Price < GameManager.Credits) { - var ship = new Ship(GameManager.ItemManager, GameManager.Zone, GameManager.ItemManager.CreateInstance(data, .1f, 1) as EquippableItem); - ship.SetParent(GameManager.CurrentShip.Parent); - GameManager.PlayerShips.Add(ship); + var hull = GameManager.ItemManager.CreateInstance(data, .1f, 1) as EquippableItem; + Entity entity; + if(data.HullType==HullType.Ship) + entity = new Ship(GameManager.ItemManager, GameManager.Zone, hull); + else entity = new OrbitalEntity(GameManager.ItemManager, GameManager.Zone, hull, Guid.Empty); + entity.SetParent(GameManager.DockedEntity); + GameManager.PlayerEntities.Add(entity); GameManager.Credits -= data.Price; } @@ -444,7 +448,7 @@ public class TradeMenu : MonoBehaviour _targetCargo = GameManager.DockingBay; TargetCargoLabel.text = "Docking Bay"; }); - foreach (var ship in GameManager.CurrentShip.Parent.Children.Where(GameManager.PlayerShips.Contains)) + foreach (var ship in GameManager.CurrentShip.Parent.Children.Where(GameManager.PlayerEntities.Contains)) { foreach (var bay in ship.CargoBays.Select((bay, index) => (bay, index))) ContextMenu.AddOption($"{ship.Name} Bay {bay.index}", diff --git a/GameData/Presets/Djinni.preset b/GameData/Loadouts/Djinni.preset similarity index 100% rename from GameData/Presets/Djinni.preset rename to GameData/Loadouts/Djinni.preset diff --git a/GameData/Loadouts/Longinus.preset b/GameData/Loadouts/Longinus.preset new file mode 100644 index 0000000000000000000000000000000000000000..7847dc8b838f4fdbca715c872f91f953950d0744 GIT binary patch literal 3807 zcmbQY!Y4m3Ju|Pgc*YR{sfn>Jfio97wEJ<_yx1J5$#BYExpvuvBLa_(oVq39^wo9o zV`UkOmvJBAnvMuCpn+4)zZe+iO`62OKurTDO=1L@cbDl#4BvZZ=e_NRIXjHa;0)j%Jd51`92*yiC2U8`5vtf&P~k8 zA>c|TY(_GkvUgSuAlpbbpet=-j10|L-#E;RYnaTpKx7)jDZBYnJwPM(`hQrW(znlZ zf3pLFX4Mbp)z10J*#(&;3Pu%1IKz^O1!&}|{}-K7zNdQaVs<{`mw#yw!zo*#)&oEz z<&rE4mQ|}d?~aT%UH?}$dzEv3QK~{fetBvUP7|4#fF`ahu-IeR_r`VR&5|gmr0-qK zr|edT`2bC{dZIsX{iW%CJ#Si`y<0V6}=Qn4F2j znI52|$pA7iuRmyYlB2xeo+lDX^KU;=1qSD?<7FH-CS$ zwAyJCu>9mab8zA$kQUu6* z@@aKIX-;vff=^;Gp7MbOM?y5+7=|+;-hTgu^a#hEsO?ie5glP9D z@icX#4M&Q%WB0g97mMs|3`D7G5m^aw;-pDTpp+POaEmAR!2_Oi*Baj6xq0PIVBXJb z`3HE3nD?O}3Fe}SfrFTk z_t8QF%mw-lW?T3F-ylbVUB!YPq1g0-#PFm6M+Kl+PN)P}i~$IUG2ih6P#uH-nF7{} zl>n=QD`5Zv+{Pmrx&UM-m{5Qj?^FO}feA;r7;e@Am^NA)ir+1yc%K0X&;!R2WIP2C z1xW*w4jn?E!-ppwf+HkxWHmrGMA=~&1EB@17buRV9j#Rn!#oG@Vm09z7aXaE2J literal 0 HcmV?d00001 diff --git a/GameData/Loadouts/Turret.preset b/GameData/Loadouts/Turret.preset new file mode 100644 index 0000000000000000000000000000000000000000..79abf5b03bd22b6991a149b7ec32778ad16c6f46 GIT binary patch literal 1737 zcmbQYETpukD79q95rO#4={vS?w|ehPpJm#t`#O{1ls%hK_rysIlaB~QCrv-8<>cZ# zYvIgW?EkOjGB6$yIAbuuZ_@%Ur%s2QQ}2HLG=!RTM1TPeoN_wBz%YH%BnAeW+cIeq zBNNb)v_wJS6CchyFOKiO;;|>02k4c&8uJN91QthqUdpn6z00al2Cq!Nu$EPhr6u{v ziFtYXc{toXX%Z_A6J<;vl4&9{GtiBz{$F%T`JU>vi`n^%U;d>%KsU-5+W<|JOR^|f zR;}v1J2KjI{a@MaRnGZEsR{x4<*7wD-N?)eH1R;Wx^~!hNx#|Op6)t)#v%r2qM!a9 z+!3hAz<2Oe_+HPRV=<|hS8ad46_OMbob&Tait=+5eDhOEb5e2I$p8u$=BbR{sS<0w zm%Tg@9on_#72_$p$is0!Ur6?pFWp!1-*4sO8`DpfE`Pe#CqFM;At*5=GqEHew@28q z8OnUhu5smRat)n0X%aKY)YD&B*Inf`_g_ElOybFFa`FtP>}DQ51T=Mh@mm9X7gxWg zwFIwuyT=PNiRRw@`)7-I3i^DhR52@R7uIPNewoB}0w2;tnrzt;SYok6i1?| zL-q$)9ZWHrI;3#H2t~&Q!0<#P5N3f{jtU?pAFvQ02_z+W)j5J?DJB+xoPo_0TxSx6{OI&^4AqXQFwd36#aBe=@x`qOH_`zGIivE?i0w_A&! OF|Yz_5L{9dCIA4<0*u`N literal 0 HcmV?d00001 diff --git a/GameData/Presets/Longinus.preset b/GameData/Presets/Longinus.preset deleted file mode 100644 index 1631196bc07bb0b90ac3ab2c9d8b511c92aae128..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2677 zcmcJPSxggA6ozjXP$B|?QQ}%fA9zxTOQT`w3>d3e5ffKj2C3SBw5fGLz$GpyMJHWu~>xprYPP{+ymU=j(sZy%|eUj5cM7 zCS}F)J#~Kla^^)%%Rd;Isp^sb^7yo1M1@zsZ#C8VHPlge1F=uh2cHBDkT=eM$2HaY zA-6^0-w?8pBtriZNRlF&_dt9*-si0Zug*Q4- zJDQ^N?-=G_2`yO?Dx!bXP#}(bI>J&>pQp-h+VuQQ@vaT!j#0)Di5kM76{d>$s3IyN zV*&LSRFMaGl}e71?Y-Zt%6-Ew51Lz=4PHGr902Oq$4$4;X7l9Cdau2kdiDKy1SfRF zB8`B}iS*S(G%#gnTuFjru&U~5V8Xt84Z~raNuy2yFz>Nh72P~ixn*X>iy`&u3x}pC z<7UVOC+Q&o%eYwe=P*%saMs_erqJh*3a@O=A`1h(AAz$4r9A=W(Kztg{#UP*Wa^fs zH$FczuHA+4oQk>=$x7p${sc6m3zxV9#tMcQVB+bK9~U- z(wJsWHhL<{`fO`$8}k}3!{LLWm0?7xz%{2oYo_(Np1tm)#T5O`a~C`ti7607i_}H< ziurPEF9TpuKr!0eIVij^+FM=7Oa~vznR7smc01ShgFmBf7C>on^~{tA3cE{wC~eX< zla^QxDu{BvV4)rJW4GVoiuvgj=X8HM1?SEMBiJhYZ$`U~Hp$qKx*w