Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Action Point System #38

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LisergyClient/LisergyClient/Assets/Plugins/ClientSDK.dll
Git LFS file not shown
4 changes: 2 additions & 2 deletions LisergyClient/LisergyClient/Assets/Plugins/Game.dll
Git LFS file not shown
2 changes: 1 addition & 1 deletion LisergyClient/LisergyClient/Assets/Plugins/GameData.dll
Git LFS file not shown
2 changes: 1 addition & 1 deletion LisergyServer/ClientSDK/ClientNetwork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using System.Runtime.CompilerServices;
using Telepathy;

[assembly: InternalsVisibleTo("ServerTests")]
[assembly: InternalsVisibleTo("UnitTests")]
namespace ClientSDK
{
public class ClientNetwork : IGameNetwork, IEventListener
Expand Down
2 changes: 1 addition & 1 deletion LisergyServer/Game/Engine/DataTypes/GameId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public unsafe struct GameId : IEquatable<GameId>, IEqualityComparer<GameId>
/// 0 = disabled.
/// This is just during initial development later can think a better solution for debugging
/// </summary>
internal static ulong DEBUG_MODE = 0;
public static ulong DEBUG_MODE = 0;

/// <summary>
/// Sets whats to be the next generated game id
Expand Down
8 changes: 6 additions & 2 deletions LisergyServer/Game/Engine/DataTypes/TimeBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public struct TimeBlock
/// Gets the total time required for this task
/// </summary>
public TimeSpan TotalBlockTime => EndTime - StartTime;

public override string ToString()
{
return $"<TimeBlock {StartTime} to {EndTime}>";
}
}

/// <summary>
Expand Down Expand Up @@ -72,9 +77,8 @@ public static TimeBlockSnapshot GetCurrentSnapshot(this TimeBlock block, DateTim
snap.TimeInBlock = now - block.StartTime;
snap.TimeUntilEndOfblock = block.EndTime - now;
snap.TimeBlock = block;
snap.Percentagage = Math.Max(1, snap.TimeInBlock / block.TotalBlockTime);
snap.Percentagage = Math.Min(1, snap.TimeInBlock / block.TotalBlockTime);
return snap;
}

}
}
2 changes: 1 addition & 1 deletion LisergyServer/Game/Engine/Scheduler/GameScheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Linq;
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("ServerTests")]
[assembly: InternalsVisibleTo("UnitTests")]
namespace Game.Engine.Scheduler
{
/// <summary>
Expand Down
3 changes: 3 additions & 0 deletions LisergyServer/Game/GameLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Game.Systems.Battler;
using Game.Systems.Map;
using Game.Systems.Movement;
using Game.Systems.Party;
using Game.Systems.Player;
using Game.Systems.Resources;

Expand All @@ -18,6 +19,7 @@ public interface IEntityLogic
public CourseLogic Movement { get; }
public HarvestingLogic Harvesting { get; }
public CargoLogic Cargo { get; }
public ActionPointsLogic ActionPoints { get; }
}

/// <summary>
Expand All @@ -31,6 +33,7 @@ public class EntityLogic : IEntityLogic
public CourseLogic Movement => _systems.EntityMovement.GetLogic(_entity);
public HarvestingLogic Harvesting => _systems.Harvesting.GetLogic(_entity);
public CargoLogic Cargo => _systems.Cargo.GetLogic(_entity);
public ActionPointsLogic ActionPoints => _systems.ActionPoints.GetLogic(_entity);

private ISystems _systems;
private IEntity _entity;
Expand Down
3 changes: 3 additions & 0 deletions LisergyServer/Game/GameSystems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public interface ISystems {
HarvestingSystem Harvesting { get; }
ResourceSystem Resources { get; }
CargoSystem Cargo { get; }
ActionsPointSystem ActionPoints { get; }
void CallEvent(IEntity entity, IBaseEvent ev);
}

Expand All @@ -60,6 +61,7 @@ public GameSystems(LisergyGame game)
AddSystem(Harvesting = new HarvestingSystem(game));
AddSystem(Resources = new ResourceSystem(game));
AddSystem(Cargo = new CargoSystem(game));
AddSystem(ActionPoints = new ActionsPointSystem(game));
}

public MapSystem Map { get; private set; }
Expand All @@ -76,6 +78,7 @@ public GameSystems(LisergyGame game)
public HarvestingSystem Harvesting { get; private set; }
public ResourceSystem Resources { get; private set; }
public CargoSystem Cargo { get; private set; }
public ActionsPointSystem ActionPoints { get; private set; }

private void AddSystem<ComponentType>(GameSystem<ComponentType> system) where ComponentType : unmanaged, IComponent
{
Expand Down
12 changes: 12 additions & 0 deletions LisergyServer/Game/Packets/ClientPackets/TakeTurnPacket.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Game.Engine.Network;
using Game.Systems.Movement;
using Game.World;
using System;
using System.Collections.Generic;

namespace Game.Network.ClientPackets
{
[Serializable]
public class TakeTurnPacket : BasePacket, IClientPacket
{ }
}
13 changes: 13 additions & 0 deletions LisergyServer/Game/Systems/ActionPoints/ActionPointsComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Game.ECS;
using System;

namespace Game.Systems.Party
{
[Serializable]
public struct ActionPointsComponent : IComponent
{
public byte ActionPoints;

public override string ToString() => $"<ActionPointsComponent Points={ActionPoints}>";
}
}
19 changes: 19 additions & 0 deletions LisergyServer/Game/Systems/ActionPoints/ActionPointsLogic.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Game.Engine.ECS;
using Game.Systems.Party;

namespace Game.Systems.Resources
{
public unsafe class ActionPointsLogic : BaseEntityLogic<ActionPointsComponent>
{
public int GetActionPoints()
{
return Entity.Get<ActionPointsComponent>().ActionPoints;
}

public void SetActionPoints(byte amt)
{
var c = Entity.Components.GetPointer<ActionPointsComponent>();
c->ActionPoints = amt;
}
}
}
36 changes: 36 additions & 0 deletions LisergyServer/Game/Systems/ActionPoints/ActionPointsSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Game.Engine.ECS;
using Game.Engine.Events.Bus;
using Game.Systems.Course;
using Game.Systems.Map;
using Game.Systems.Resources;

namespace Game.Systems.Party
{
public class ActionsPointSystem : LogicSystem<ActionPointsComponent, ActionPointsLogic>, IEventListener
{
public ActionsPointSystem(LisergyGame game) : base(game)
{
}

public override void RegisterListeners()
{
EntityEvents.On<CourseIntentionEvent>(OnCourseIntent);
EntityEvents.On<EntityMoveInEvent>(OnEntityMoveIn);
}

private void OnEntityMoveIn(IEntity e, EntityMoveInEvent ev)
{
var actionPoints = ev.Entity.EntityLogic.ActionPoints.GetActionPoints();
if (actionPoints == 0) return;
ev.Entity.EntityLogic.ActionPoints.SetActionPoints((byte) (actionPoints - 1));
}

private void OnCourseIntent(IEntity e, CourseIntentionEvent ev)
{
if (ev.Entity.EntityLogic.ActionPoints.GetActionPoints() == 0)
{
ev.Cancelled = true;
}
}
}
}
11 changes: 11 additions & 0 deletions LisergyServer/Game/Systems/ActionPoints/PlayerTurnsComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using Game.ECS;

namespace Game.Systems.ActionPoints
{
[Serializable]
public struct PlayerTurnsComponent : IComponent
{
public ulong Turns;
}
}
15 changes: 13 additions & 2 deletions LisergyServer/Game/Systems/Course/CourseEvents.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
using Game.Engine.ECS;
using System.Collections.Generic;
using Game.Engine.ECS;
using Game.Engine.Events;
using Game.Systems.Battler;
using Game.Systems.Movement;
using Game.Tile;
using Game.World;

namespace Game.Systems.Course
{
public class CourseIntentionEvent : IGameEvent
{
public IEntity Entity;
public CourseIntent Intent;
public List<Location> Path;
public bool Cancelled;

public override string ToString() => $"<CourseIntent Entity={Entity} Intent={Intent} Tile={Path}/>";
}

/// <summary>
/// Whenever a course finishes its last tile movement
/// </summary>
Expand Down
16 changes: 16 additions & 0 deletions LisergyServer/Game/Systems/Course/CourseLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Game.Engine.ECS;
using Game.Engine.DataTypes;
using Game.Engine.Scheduler;
using Game.Systems.Party;
using Game.World;

namespace Game.Systems.Movement
Expand All @@ -15,6 +16,21 @@
public bool TryStartMovement(List<Location> sentPath, CourseIntent intent)
{
var owner = Game.Players.GetPlayer(Entity.OwnerID);

var courseIntent = EventPool<CourseIntentionEvent>.Get();
courseIntent.Intent = intent;
courseIntent.Path = sentPath;
courseIntent.Entity = Entity;
courseIntent.Cancelled = false;
Entity.Components.CallEvent(courseIntent);
EventPool<CourseIntentionEvent>.Return(courseIntent);

if (courseIntent.Cancelled)
{
Game.Log.Debug("Course Cancelled by other system");
return false;
}

foreach (var position in sentPath)
{
var tile = Game.World.Map.GetTile(position.X, position.Y);
Expand Down Expand Up @@ -52,14 +68,14 @@

public GameTask GetCourseTask() => Game.Scheduler.GetTask(Entity.Components.Get<CourseComponent>().CourseId);

public GameTask? TryGetCourseTask()

Check warning on line 71 in LisergyServer/Game/Systems/Course/CourseLogic.cs

View workflow job for this annotation

GitHub Actions / run-tests

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
{
var courseId = Entity.Components.Get<CourseComponent>().CourseId;
if (courseId == GameId.ZERO) return null;
return Game.Scheduler.GetTask(courseId);
}

public CourseTaskExecutor? TryGetCourseTaskExecutor()

Check warning on line 78 in LisergyServer/Game/Systems/Course/CourseLogic.cs

View workflow job for this annotation

GitHub Actions / run-tests

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
{
return TryGetCourseTask()?.Executor as CourseTaskExecutor;
}
Expand Down
2 changes: 0 additions & 2 deletions LisergyServer/Game/Systems/Harvesting/HarvestingLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,6 @@ public HarvestingTaskState CalculateCurrentState()
var harvesting = Entity.Components.Get<HarvestingComponent>();
var tile = Game.World.Map.GetTile(harvesting.Tile.X, harvesting.Tile.Y);
var startTime = DateTime.FromBinary(harvesting.StartedAt);

//
var tileSpec = Game.Specs.Tiles[tile.SpecId];
if (!tileSpec.ResourceSpotSpecId.HasValue)
{
Expand Down
1 change: 1 addition & 0 deletions LisergyServer/Game/Systems/Party/PartyEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public PartyEntity(IGame game, GameId owner) : base(game, owner)
Components.Add<CourseComponent>();
Components.Add<MovespeedComponent>();
Components.Add<CargoComponent>();
Components.Add<ActionPointsComponent>();
Components.Add<HarvesterComponent>();
Components.Get<CargoComponent>().MaxWeight = game.Specs.Harvesting.StartingPartyCargoWeight;
Components.Get<MovespeedComponent>().MoveDelay = TimeSpan.FromSeconds(1);
Expand Down
2 changes: 2 additions & 0 deletions LisergyServer/Game/Systems/Player/PlayerEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using Game.Systems.ActionPoints;

namespace Game.Systems.Player
{
Expand All @@ -33,6 +34,7 @@ public PlayerEntity(PlayerProfile profile, IGame game)
Game = game;
Components = new ComponentSet(this);
Components.Add<PlayerComponent>();
Components.Add<PlayerTurnsComponent>();
Components.AddReference(new PlayerData());
Components.AddReference(new VisibilityReferences());
Profile = profile;
Expand Down
13 changes: 12 additions & 1 deletion LisergyServer/Game/Systems/Player/PlayerLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
using GameData;
using GameData.Specs;
using System.Collections.Generic;
using Game.Systems.ActionPoints;

namespace Game.Systems.Player
{
/// <summary>
/// Interacts with player specific data
/// </summary>
public class PlayerLogic : BaseEntityLogic<PlayerComponent>
public unsafe class PlayerLogic : BaseEntityLogic<PlayerComponent>
{
private PlayerData Data => Entity.Components.GetReference<PlayerData>();

Expand Down Expand Up @@ -80,6 +81,16 @@ public void PlaceNewPlayer(TileEntity t)
return;
}

public void TakeTurn()
{
var p = Entity as PlayerEntity;
foreach (var party in p.Parties)
{
party.EntityLogic.ActionPoints.SetActionPoints(1);
}
p.Components.GetPointer<PlayerTurnsComponent>()->Turns++;
}

/// <summary>
/// Record a battle header of a battle that happened for this player
/// </summary>
Expand Down
8 changes: 8 additions & 0 deletions LisergyServer/Game/Systems/Player/PlayerSystem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Game.Engine.ECS;
using Game.Network.ClientPackets;
using Game.Network.ServerPackets;
using Game.Systems.ActionPoints;
using Game.Systems.FogOfWar;

namespace Game.Systems.Player
Expand All @@ -13,9 +15,15 @@ public PlayerSystem(LisergyGame game) : base(game)
public override void RegisterListeners()
{
Game.Network.On<BattleResultPacket>(OnBattleResultPacket);
Game.Network.On<TakeTurnPacket>(TakeTurn);
EntityEvents.On<TileVisibilityChangedForPlayerEvent>(OnTileVisibilityChanged);

}

private static void TakeTurn(TakeTurnPacket p)
{
p.Sender.EntityLogic.Player.TakeTurn();
}

/// <summary>
/// Received from battle server
Expand Down
8 changes: 7 additions & 1 deletion LisergyServer/LisergyServer.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Game", "Game\Game.csproj",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GameData", "GameData\GameData.csproj", "{5B793397-7989-4CAE-A572-5AC909B8F91F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ServerTests", "ServerTests\ServerTests.csproj", "{4584F2EF-E15F-479C-BEC9-3DEDDC525658}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTests", "UnitTests\UnitTests.csproj", "{4584F2EF-E15F-479C-BEC9-3DEDDC525658}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GameDataTest", "GameDataTest\GameDataTest.csproj", "{C243FA12-2F86-4682-8FB9-BFE65D0C3337}"
EndProject
Expand All @@ -30,6 +30,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GameServices", "GameService
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SDL", "RedisMagic\SDL.csproj", "{FC963FB0-0E8C-4A83-837A-948CD48EDAEC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SmokeTests", "SmokeTests\SmokeTests.csproj", "{483A5A4E-2B2C-4A7C-B82F-26EECD4B7FC7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -80,6 +82,10 @@ Global
{FC963FB0-0E8C-4A83-837A-948CD48EDAEC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FC963FB0-0E8C-4A83-837A-948CD48EDAEC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FC963FB0-0E8C-4A83-837A-948CD48EDAEC}.Release|Any CPU.Build.0 = Release|Any CPU
{483A5A4E-2B2C-4A7C-B82F-26EECD4B7FC7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{483A5A4E-2B2C-4A7C-B82F-26EECD4B7FC7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{483A5A4E-2B2C-4A7C-B82F-26EECD4B7FC7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{483A5A4E-2B2C-4A7C-B82F-26EECD4B7FC7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Loading
Loading