Skip to content

Commit

Permalink
Inventory and re-writing all of the enemy logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Nhawdge committed Feb 4, 2024
1 parent 98d3bac commit 691bfe1
Show file tree
Hide file tree
Showing 14 changed files with 119 additions and 51 deletions.
21 changes: 12 additions & 9 deletions Entities/Archetypes/EnemyBuilder.cs
Original file line number Diff line number Diff line change
@@ -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<Ship, Sprite, Npc>();
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;
Expand All @@ -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)
Expand Down
23 changes: 9 additions & 14 deletions Scenes/Levels/Components/Npc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
1 change: 0 additions & 1 deletion Scenes/Levels/Components/Ship.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public Ship(HullType hull, BoatColor color, Team team)
internal float Currency;
internal Port? TargetPort;
internal List<Route> SailingRoute;
internal int Wood;

public Task<List<Vector2>> NavTask { get; set; }
}
Expand Down
8 changes: 5 additions & 3 deletions Scenes/Levels/DataManagers/InventoryManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace NovemberPirates.Scenes.Levels.DataManagers
using NovemberPirates.Utilities.ContentData;

namespace NovemberPirates.Scenes.Levels.DataManagers
{
internal class InventoryManager
{
Expand All @@ -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<TradeableGood> Inventory = new();

}
}
4 changes: 2 additions & 2 deletions Scenes/Levels/OceanScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
});
}
Expand Down
23 changes: 14 additions & 9 deletions Scenes/Levels/Systems/EnemyAISystem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Arch.Core;
using Arch.Core.Extensions;
using NovemberPirates.Scenes.Levels.Components;
using NovemberPirates.Systems;

namespace NovemberPirates.Scenes.Levels.Systems
Expand All @@ -7,17 +9,20 @@ internal class EnemyAISystem : GameSystem
{
internal override void Update(World world)
{
var enemyQuery = new QueryDescription().WithAll<Sprite, Ship, Npc>();

world.Query(enemyQuery, (entity) =>
{
var npc = entity.Get<Npc>();
var ship = entity.Get<Ship>();
var sprite = entity.Get<Sprite>();



});

}
}

public enum EnemyGoals
{
Sailing,
Trading,
Repairing,
Escaping,
GetReinforcements,
Fighting
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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) { }

Expand All @@ -23,9 +24,9 @@ internal override void UpdateNoCamera(World world)
var playerEntity = world.QueryFirst<Player>();
var player = playerEntity.Get<Player>();


if (singleton.InventoryOpen)
{
var playerShip = playerEntity.Get<Ship>();
var inventoryFrame = new Vector2(Raylib.GetScreenWidth() / 2, Raylib.GetScreenHeight() / 2);

Raylib.DrawText("Inventory", 0, 0, 24, Raylib.BLUE);
Expand All @@ -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<Ship>();

var texture = ShipSpriteBuilder.GenerateBoat(new BoatOptions(playerShip));

Expand Down
3 changes: 2 additions & 1 deletion Scenes/Levels/Systems/PickupSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<AudioEvent>().Set(new AudioEvent() { Key = Utilities.AudioKey.CollectWood, Position = sprite.Position });
}
});
Expand Down
2 changes: 1 addition & 1 deletion Scenes/Levels/Systems/SpawningSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ internal List<Route> GetRandomRoute()
}

}

internal class Route
{
internal Port FromPort { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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},

Expand All @@ -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},
Expand All @@ -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},

Expand All @@ -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},
Expand All @@ -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},

Expand Down Expand Up @@ -159,7 +160,6 @@ internal enum ShipAbilities
FourCannon,
FiveCannon,
SixCannon,
MaxCrew,
}

internal enum CannonType
Expand Down Expand Up @@ -193,6 +193,7 @@ internal enum Stats

// Ship
InitialCrew,
MaxCrew,
HullHealth,
SailHealth,
}
Expand Down
44 changes: 44 additions & 0 deletions Utilities/ContentData/TradeableGoodsData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
namespace NovemberPirates.Utilities.ContentData
{
internal class TradeableGoodsData
{
internal static TradeableGoodsData Instance = new();

internal Dictionary<TradeableGoodsNames, TradeableGood> 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,
}
}
2 changes: 1 addition & 1 deletion Utilities/Maps/NavigationUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Route>();
Expand Down

0 comments on commit 691bfe1

Please sign in to comment.