From 691bfe1384516595657605bbea0c019cf20f969c Mon Sep 17 00:00:00 2001 From: John Pavek Date: Sun, 4 Feb 2024 17:39:14 -0600 Subject: [PATCH] Inventory and re-writing all of the enemy logic --- Entities/Archetypes/EnemyBuilder.cs | 21 +++++---- Scenes/Levels/Components/Npc.cs | 23 ++++------ Scenes/Levels/Components/Ship.cs | 1 - .../Levels/DataManagers/InventoryManager.cs | 8 ++-- Scenes/Levels/OceanScene.cs | 4 +- Scenes/Levels/Systems/EnemyAISystem.cs | 23 ++++++---- ...System.cs => InventoryManagementSystem.cs} | 29 +++++++++--- Scenes/Levels/Systems/PickupSystem.cs | 3 +- Scenes/Levels/Systems/SpawningSystem.cs | 2 +- .../{Data => ContentData}/DataExtensions.cs | 0 .../{Data => ContentData}/RouteDataStore.cs | 1 + Utilities/{Data => ContentData}/ShipData.cs | 9 ++-- Utilities/ContentData/TradeableGoodsData.cs | 44 +++++++++++++++++++ Utilities/Maps/NavigationUtilities.cs | 2 +- 14 files changed, 119 insertions(+), 51 deletions(-) rename Scenes/Levels/Systems/{InventorySystem.cs => InventoryManagementSystem.cs} (58%) rename Utilities/{Data => ContentData}/DataExtensions.cs (100%) rename Utilities/{Data => ContentData}/RouteDataStore.cs (99%) rename Utilities/{Data => ContentData}/ShipData.cs (97%) create mode 100644 Utilities/ContentData/TradeableGoodsData.cs diff --git a/Entities/Archetypes/EnemyBuilder.cs b/Entities/Archetypes/EnemyBuilder.cs index 0cf5074..80c1cb1 100644 --- a/Entities/Archetypes/EnemyBuilder.cs +++ b/Entities/Archetypes/EnemyBuilder.cs @@ -1,18 +1,21 @@ using Arch.Core; using Arch.Core.Extensions; +using Arch.Core.Utils; using NovemberPirates.Scenes.Levels.Components; using NovemberPirates.Utilities; -using NovemberPirates.Utilities.Data; using System.Numerics; namespace NovemberPirates.Entities.Archetypes { internal static class EnemyBuilder { - public static void CreateEnemyShip(World world, Vector2 position, Team team, Purpose purpose = Purpose.None) + public static void CreateEnemyShip(World world, Vector2 position, Team team) { - var entity = world.Create(); + var enemyArchetype = new ComponentType[] { typeof(Ship), typeof(Sprite), typeof(Npc) }; + + var entity = world.Create(enemyArchetype); var ship = new Ship(HullType.Small, BoatColor.Yellow, Team.Yellow); + ship.Team = team; ship.BoatColor = BoatColor.Yellow; ship.BoatType = HullType.Large; @@ -26,12 +29,12 @@ public static void CreateEnemyShip(World world, Vector2 position, Team team, Pur entity.Set(ship); entity.Set(sprite); - entity.Set(new Npc() { Purpose = purpose }); - if (purpose == Purpose.Trade) - { - ship.SailingRoute = RouteDataStore.Instance.GetRandomRoute(); - sprite.Position = ship.SailingRoute[0].RoutePoints[0]; - } + entity.Set(new Npc() ); + //if (purpose == Purpose.Trade) + //{ + // ship.SailingRoute = RouteDataStore.Instance.GetRandomRoute(); + // sprite.Position = ship.SailingRoute[0].RoutePoints[0]; + //} } internal static void CreatePatrolPoint(World world, Vector2 vector2, Team team, int order) diff --git a/Scenes/Levels/Components/Npc.cs b/Scenes/Levels/Components/Npc.cs index c4c9b6b..be8599a 100644 --- a/Scenes/Levels/Components/Npc.cs +++ b/Scenes/Levels/Components/Npc.cs @@ -2,23 +2,18 @@ { internal class Npc { - internal Purpose Purpose; - internal NpcAction CurrentAction; + internal NpcGoals Goal; + internal float TimeSinceLastGoalChange; } - public enum Purpose + public enum NpcGoals { - None, - Idle, - Patrol, - Attack, - Trade, + Sailing, + Trading, + Repairing, + Escaping, + GetReinforcements, + Fighting } - public enum NpcAction - { - MoveTo, - Attack, - Trade, - } } diff --git a/Scenes/Levels/Components/Ship.cs b/Scenes/Levels/Components/Ship.cs index 648144f..12a7cfd 100644 --- a/Scenes/Levels/Components/Ship.cs +++ b/Scenes/Levels/Components/Ship.cs @@ -50,7 +50,6 @@ public Ship(HullType hull, BoatColor color, Team team) internal float Currency; internal Port? TargetPort; internal List SailingRoute; - internal int Wood; public Task> NavTask { get; set; } } diff --git a/Scenes/Levels/DataManagers/InventoryManager.cs b/Scenes/Levels/DataManagers/InventoryManager.cs index 412796e..03bc02a 100644 --- a/Scenes/Levels/DataManagers/InventoryManager.cs +++ b/Scenes/Levels/DataManagers/InventoryManager.cs @@ -1,4 +1,6 @@ -namespace NovemberPirates.Scenes.Levels.DataManagers +using NovemberPirates.Utilities.ContentData; + +namespace NovemberPirates.Scenes.Levels.DataManagers { internal class InventoryManager { @@ -7,8 +9,8 @@ private InventoryManager() { } public static InventoryManager Instance = new(); public long Gold = 0; - public long Food = 0; - public long Lumber = 0; + + public List Inventory = new(); } } diff --git a/Scenes/Levels/OceanScene.cs b/Scenes/Levels/OceanScene.cs index 6c8eb5a..f96df29 100644 --- a/Scenes/Levels/OceanScene.cs +++ b/Scenes/Levels/OceanScene.cs @@ -48,16 +48,16 @@ internal OceanScene() Systems.Add(new WindSystem()); Systems.Add(new DebugSystem()); Systems.Add(new CannonBallSystem()); + Systems.Add(new EnemyAISystem()); Systems.Add(new EnemyControlSystem()); Systems.Add(new EffectsSystem()); - Systems.Add(new InventorySystem()); + Systems.Add(new InventoryManagementSystem()); Systems.Add(new SpawningSystem()); Systems.Add(new PickupSystem()); Systems.Add(new AudioSystem()); Systems.Add(new NavigationSystem()); Systems.Add(new PlayerControlSystem()); Systems.Add(new PortSystem()); - Systems.Add(new EnemyAISystem()); Systems.Add(new UiSystem()); }); } diff --git a/Scenes/Levels/Systems/EnemyAISystem.cs b/Scenes/Levels/Systems/EnemyAISystem.cs index aa0d13c..0653f3a 100644 --- a/Scenes/Levels/Systems/EnemyAISystem.cs +++ b/Scenes/Levels/Systems/EnemyAISystem.cs @@ -1,4 +1,6 @@ using Arch.Core; +using Arch.Core.Extensions; +using NovemberPirates.Scenes.Levels.Components; using NovemberPirates.Systems; namespace NovemberPirates.Scenes.Levels.Systems @@ -7,17 +9,20 @@ internal class EnemyAISystem : GameSystem { internal override void Update(World world) { + var enemyQuery = new QueryDescription().WithAll(); + + world.Query(enemyQuery, (entity) => + { + var npc = entity.Get(); + var ship = entity.Get(); + var sprite = entity.Get(); + + + + }); } } - public enum EnemyGoals - { - Sailing, - Trading, - Repairing, - Escaping, - GetReinforcements, - Fighting - } + } diff --git a/Scenes/Levels/Systems/InventorySystem.cs b/Scenes/Levels/Systems/InventoryManagementSystem.cs similarity index 58% rename from Scenes/Levels/Systems/InventorySystem.cs rename to Scenes/Levels/Systems/InventoryManagementSystem.cs index ab19143..11f819b 100644 --- a/Scenes/Levels/Systems/InventorySystem.cs +++ b/Scenes/Levels/Systems/InventoryManagementSystem.cs @@ -6,12 +6,13 @@ using NovemberPirates.Scenes.Levels.DataManagers; using NovemberPirates.Systems; using NovemberPirates.Utilities; +using NovemberPirates.Utilities.Data; using Raylib_CsLo; using System.Numerics; namespace NovemberPirates.Scenes.Levels.Systems { - internal class InventorySystem : GameSystem + internal class InventoryManagementSystem : GameSystem { internal override void Update(World world) { } @@ -23,9 +24,9 @@ internal override void UpdateNoCamera(World world) var playerEntity = world.QueryFirst(); var player = playerEntity.Get(); - if (singleton.InventoryOpen) { + var playerShip = playerEntity.Get(); var inventoryFrame = new Vector2(Raylib.GetScreenWidth() / 2, Raylib.GetScreenHeight() / 2); Raylib.DrawText("Inventory", 0, 0, 24, Raylib.BLUE); @@ -38,12 +39,28 @@ internal override void UpdateNoCamera(World world) var rightAlignment = Raylib.GetScreenWidth() / 2 + 100; var leftAlignment = inventoryFrame.X + 10; + var heightOffset = 180; + var lineOffset = 30; - Raylib.DrawText($"Gold: {InventoryManager.Instance.Gold} ", rightAlignment, Raylib.GetScreenHeight() / 2 - 180, 24, Raylib.WHITE); - Raylib.DrawText($"Lumber: {InventoryManager.Instance.Lumber} ", rightAlignment, Raylib.GetScreenHeight() / 2 - 150, 24, Raylib.WHITE); - Raylib.DrawText($"Food: {InventoryManager.Instance.Food} ", rightAlignment, Raylib.GetScreenHeight() / 2 - 120, 24, Raylib.WHITE); + Raylib.DrawText($"Crew: {playerShip.Crew} / {ShipData.Instance.Data[$"{playerShip.BoatType}{Stats.InitialCrew}"]}", rightAlignment, Raylib.GetScreenHeight() / 2 - heightOffset, 24, Raylib.WHITE); + heightOffset -= lineOffset; + + Raylib.DrawText($"Hull: {playerShip.HullHealth} / {ShipData.Instance.Data[$"{playerShip.BoatType}{Stats.HullHealth}"]} ", rightAlignment, Raylib.GetScreenHeight() / 2 - heightOffset, 24, Raylib.WHITE); + heightOffset -= lineOffset; + + Raylib.DrawText($"Hull: {playerShip.SailHealth} / {ShipData.Instance.Data[$"{playerShip.BoatType}{Stats.SailHealth}"]} ", rightAlignment, Raylib.GetScreenHeight() / 2 - heightOffset, 24, Raylib.WHITE); + heightOffset -= lineOffset; + + Raylib.DrawText($"Gold: {InventoryManager.Instance.Gold} ", rightAlignment, Raylib.GetScreenHeight() / 2 - heightOffset, 24, Raylib.WHITE); + heightOffset -= lineOffset; + + + foreach (var invGroup in InventoryManager.Instance.Inventory.GroupBy(x => x.Name)) + { + Raylib.DrawText($"{invGroup.Key}: {invGroup.Count()}", rightAlignment, Raylib.GetScreenHeight() / 2 - heightOffset, 24, Raylib.WHITE); + heightOffset -= lineOffset; + } - var playerShip = playerEntity.Get(); var texture = ShipSpriteBuilder.GenerateBoat(new BoatOptions(playerShip)); diff --git a/Scenes/Levels/Systems/PickupSystem.cs b/Scenes/Levels/Systems/PickupSystem.cs index 9b3e6a3..6389ee9 100644 --- a/Scenes/Levels/Systems/PickupSystem.cs +++ b/Scenes/Levels/Systems/PickupSystem.cs @@ -5,6 +5,7 @@ using NovemberPirates.Scenes.Levels.Components; using NovemberPirates.Scenes.Levels.DataManagers; using NovemberPirates.Systems; +using NovemberPirates.Utilities.ContentData; using Raylib_CsLo; using System.Numerics; @@ -55,7 +56,7 @@ internal override void Update(World world) if (playerSprite.Position.DistanceTo(sprite.Position) < 50) { world.Destroy(entity); - InventoryManager.Instance.Lumber += 1; + InventoryManager.Instance.Inventory.Add(TradeableGoodsData.GetGood(TradeableGoodsNames.Lumber)); world.Create().Set(new AudioEvent() { Key = Utilities.AudioKey.CollectWood, Position = sprite.Position }); } }); diff --git a/Scenes/Levels/Systems/SpawningSystem.cs b/Scenes/Levels/Systems/SpawningSystem.cs index 3d017fd..10de7a5 100644 --- a/Scenes/Levels/Systems/SpawningSystem.cs +++ b/Scenes/Levels/Systems/SpawningSystem.cs @@ -26,7 +26,7 @@ internal override void Update(World world) if (spawner.Elapsed > spawner.SpawnTime) { spawner.Elapsed = 0; - EnemyBuilder.CreateEnemyShip(world, spawner.Position, spawner.Team, Purpose.Trade); + EnemyBuilder.CreateEnemyShip(world, spawner.Position, spawner.Team); } }); } diff --git a/Utilities/Data/DataExtensions.cs b/Utilities/ContentData/DataExtensions.cs similarity index 100% rename from Utilities/Data/DataExtensions.cs rename to Utilities/ContentData/DataExtensions.cs diff --git a/Utilities/Data/RouteDataStore.cs b/Utilities/ContentData/RouteDataStore.cs similarity index 99% rename from Utilities/Data/RouteDataStore.cs rename to Utilities/ContentData/RouteDataStore.cs index 95f7e86..831ac3e 100644 --- a/Utilities/Data/RouteDataStore.cs +++ b/Utilities/ContentData/RouteDataStore.cs @@ -20,6 +20,7 @@ internal List GetRandomRoute() } } + internal class Route { internal Port FromPort { get; set; } diff --git a/Utilities/Data/ShipData.cs b/Utilities/ContentData/ShipData.cs similarity index 97% rename from Utilities/Data/ShipData.cs rename to Utilities/ContentData/ShipData.cs index 8562c96..f9edbc0 100644 --- a/Utilities/Data/ShipData.cs +++ b/Utilities/ContentData/ShipData.cs @@ -53,7 +53,6 @@ internal void SaveToJson() { $"{HullType.Small}{ShipAbilities.FullSail}", 10 }, { $"{HullType.Small}{ShipAbilities.OneCannon}", 5 }, { $"{HullType.Small}{ShipAbilities.TwoCannon}", 7 }, - { $"{HullType.Small}{ShipAbilities.MaxCrew}", 15 }, { $"{HullType.Small}{Stats.RowingSpeed}", 100}, { $"{HullType.Small}{Stats.TurningSpeed}", 100}, @@ -62,6 +61,7 @@ internal void SaveToJson() { $"{HullType.Small}{Stats.FullSailSpeed}", 1}, { $"{HullType.Small}{Stats.SailSpeedEasing}" , 1}, { $"{HullType.Small}{Stats.InitialCrew}" , 10}, + { $"{HullType.Small}{Stats.MaxCrew}" , 15}, { $"{HullType.Small}{Stats.HullHealth}" , 100}, { $"{HullType.Small}{Stats.SailHealth}" , 100}, @@ -73,7 +73,7 @@ internal void SaveToJson() { $"{HullType.Medium}{ShipAbilities.FullSail}", 10 }, { $"{HullType.Medium}{ShipAbilities.OneCannon}", 5 }, { $"{HullType.Medium}{ShipAbilities.TwoCannon}", 7 }, - { $"{HullType.Medium}{ShipAbilities.MaxCrew}", 20 }, + { $"{HullType.Medium}{Stats.RowingSpeed}", 100}, { $"{HullType.Medium}{Stats.TurningSpeed}", 100}, @@ -82,6 +82,7 @@ internal void SaveToJson() { $"{HullType.Medium}{Stats.FullSailSpeed}", 1}, { $"{HullType.Medium}{Stats.SailSpeedEasing}" , 1}, { $"{HullType.Medium}{Stats.InitialCrew}" , 10}, + { $"{HullType.Medium}{Stats.MaxCrew}" , 20}, { $"{HullType.Medium}{Stats.HullHealth}" , 100}, { $"{HullType.Medium}{Stats.SailHealth}" , 100}, @@ -92,7 +93,6 @@ internal void SaveToJson() { $"{HullType.Large}{ShipAbilities.FullSail}", 10 }, { $"{HullType.Large}{ShipAbilities.OneCannon}", 5 }, { $"{HullType.Large}{ShipAbilities.TwoCannon}", 7 }, - { $"{HullType.Large}{ShipAbilities.MaxCrew}", 25 }, { $"{HullType.Large}{Stats.RowingSpeed}", 100}, { $"{HullType.Large}{Stats.TurningSpeed}", 100}, @@ -101,6 +101,7 @@ internal void SaveToJson() { $"{HullType.Large}{Stats.FullSailSpeed}", 1}, { $"{HullType.Large}{Stats.SailSpeedEasing}" , 1}, { $"{HullType.Large}{Stats.InitialCrew}" , 10}, + { $"{HullType.Large}{Stats.MaxCrew}" , 25}, { $"{HullType.Large}{Stats.HullHealth}" , 100}, { $"{HullType.Large}{Stats.SailHealth}" , 100}, @@ -159,7 +160,6 @@ internal enum ShipAbilities FourCannon, FiveCannon, SixCannon, - MaxCrew, } internal enum CannonType @@ -193,6 +193,7 @@ internal enum Stats // Ship InitialCrew, + MaxCrew, HullHealth, SailHealth, } diff --git a/Utilities/ContentData/TradeableGoodsData.cs b/Utilities/ContentData/TradeableGoodsData.cs new file mode 100644 index 0000000..da2f50b --- /dev/null +++ b/Utilities/ContentData/TradeableGoodsData.cs @@ -0,0 +1,44 @@ +namespace NovemberPirates.Utilities.ContentData +{ + internal class TradeableGoodsData + { + internal static TradeableGoodsData Instance = new(); + + internal Dictionary Goods = new(); + + private TradeableGoodsData() + { + LoadPrices(); + } + + private void LoadPrices() + { + Goods.Add(TradeableGoodsNames.Lumber, new TradeableGood { Name = "Lumber", Price = 1 }); + Goods.Add(TradeableGoodsNames.Food, new TradeableGood { Name = "Food", Price = 5 }); + Goods.Add(TradeableGoodsNames.Material, new TradeableGood { Name = "Material", Price = 10 }); + Goods.Add(TradeableGoodsNames.Weapons, new TradeableGood { Name = "Weapons", Price = 20 }); + Goods.Add(TradeableGoodsNames.FineGoods, new TradeableGood { Name = "Fine Goods", Price = 40 }); + Goods.Add(TradeableGoodsNames.Gems, new TradeableGood { Name = "Gems", Price = 80 }); + } + + static internal TradeableGood GetGood(TradeableGoodsNames name) + { + return Instance.Goods[name]; + } + } + + internal class TradeableGood + { + internal string Name; + internal int Price; + } + internal enum TradeableGoodsNames + { + Lumber, + Food, + Material, + Weapons, + FineGoods, + Gems, + } +} diff --git a/Utilities/Maps/NavigationUtilities.cs b/Utilities/Maps/NavigationUtilities.cs index 2033681..ccef2df 100644 --- a/Utilities/Maps/NavigationUtilities.cs +++ b/Utilities/Maps/NavigationUtilities.cs @@ -49,7 +49,7 @@ internal static void AddTradeRoutes(World world) }); - for (var i = 0; i < allPorts.Count; i++) + for (var i = 0; i < 1; i++) { var routePorts = allPorts.OrderBy(x => Random.Shared.Next()).Take(3).ToList(); var routes = new List();