Skip to content

Commit

Permalink
Merge pull request #32 from tgiachi/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
tgiachi committed Apr 20, 2023
2 parents 21d7e9f + a64e330 commit f2a3b00
Show file tree
Hide file tree
Showing 269 changed files with 4,593 additions and 4,103 deletions.
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ dotnet_style_qualification_for_field=false:suggestion
dotnet_style_qualification_for_method=false:suggestion
dotnet_style_qualification_for_property=false:suggestion
dotnet_style_require_accessibility_modifiers=for_non_interface_members:suggestion
csharp_style_namespace_declarations = file_scoped:error
dotnet_diagnostic.IDE0161.severity = error

# ReSharper properties
resharper_apply_auto_detected_rules=false
Expand Down
23 changes: 23 additions & 0 deletions .versionize
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"changelogAll": true,
"changelog": {
"header": "DarkStar MMO",
"sections": [
{
"type": "feat",
"section": "✨ Features",
"hidden": false
},
{
"type": "fix",
"section": "🐛 Bug Fixes",
"hidden": true
},
{
"type": "perf",
"section": "🚀 Performance",
"hidden": false
}
]
}
}
35 changes: 35 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,41 @@

All notable changes to this project will be documented in this file. See [versionize](https://github.com/versionize/versionize) for commit guidelines.

<a name="0.1.12"></a>
## [0.1.12](https://www.github.com/tgiachi/DarkSun/releases/tag/v0.1.12) (2023-4-20)

### Other

* 🐛 fix(BaseAiBehaviourExecutor.cs): change CalculatePath to CalculateAStarPath ([8b18fd2](https://www.github.com/tgiachi/DarkSun/commit/8b18fd213758ca09550eda47c6ad5946423c3305))

<a name="0.1.11"></a>
## [0.1.11](https://www.github.com/tgiachi/DarkSun/releases/tag/v0.1.11) (2023-4-20)

### Other

* 🐛 fix(BaseEnumConverter.cs): fix enum value search with wildcard ([8113bbd](https://www.github.com/tgiachi/DarkSun/commit/8113bbd0de0c2355b7971ee1416e67579395d50c))

<a name="0.1.10"></a>
## [0.1.10](https://www.github.com/tgiachi/DarkSun/releases/tag/v0.1.10) (2023-4-20)

### Other

* 🔨 refactor(PointConverterEx.cs): rename PlayerMoveDirectionType to MoveDirectionType ([e88d597](https://www.github.com/tgiachi/DarkSun/commit/e88d597e1029665b2fe1c0baf6165e9efa50c7d7))

<a name="0.1.9"></a>
## [0.1.9](https://www.github.com/tgiachi/DarkSun/releases/tag/v0.1.9) (2023-4-20)

### Other

* namespace filescoped ([97d2e07](https://www.github.com/tgiachi/DarkSun/commit/97d2e072c713706b683bb3fc441bc721d126aca8))

<a name="0.1.8"></a>
## [0.1.8](https://www.github.com/tgiachi/DarkSun/releases/tag/v0.1.8) (2023-4-20)

### Other

* ✨ feat(.versionize): add configuration for changelogAll and changelog sections ([db61fef](https://www.github.com/tgiachi/DarkSun/commit/db61fef4588280fd0b8d5f0bb74f7e57360eced7))

<a name="0.1.7"></a>
## [0.1.7](https://www.github.com/tgiachi/DarkSun/releases/tag/v0.1.7) (2023-4-20)

Expand Down
124 changes: 80 additions & 44 deletions DarkStar.Api.Engine/Ai/Base/BaseAiBehaviourExecutor.cs
Original file line number Diff line number Diff line change
@@ -1,71 +1,107 @@
using DarkStar.Api.Engine.Interfaces.Ai;
using DarkStar.Api.Engine.Interfaces.Core;
using DarkStar.Api.Engine.Map.Entities;
using DarkStar.Api.Engine.Map.Entities.Base;
using DarkStar.Api.Engine.Utils;
using DarkStar.Api.Utils;
using DarkStar.Api.World.Types.Map;
using DarkStar.Api.World.Types.Npc;
using DarkStar.Database.Entities.Npc;
using DarkStar.Network.Protocol.Messages.Common;
using GoRogue.GameFramework;
using Microsoft.Extensions.Logging;
using SadRogue.Primitives;

namespace DarkStar.Api.Engine.Ai.Base
{
public class BaseAiBehaviourExecutor : IAiBehaviourExecutor
{
namespace DarkStar.Api.Engine.Ai.Base;

/// <summary>
/// Default interval is 1 second
/// </summary>
public double Interval { get; set; } = 1000;
private double _currentInterval = 1000;
public class BaseAiBehaviourExecutor : IAiBehaviourExecutor
{

protected NpcGameObject NpcGameObject { get; private set; } = null!;
protected NpcEntity NpcEntity { get; private set; } = null!;
protected string MapId { get; private set; } = null!;
/// <summary>
/// Default interval is 1 second
/// </summary>
public double Interval { get; set; } = 1000;
private double _currentInterval = 1000;
protected NpcGameObject NpcGameObject { get; private set; } = null!;
protected NpcEntity NpcEntity { get; private set; } = null!;
protected string MapId { get; private set; } = null!;

protected ILogger Logger { get; }
protected IDarkSunEngine Engine { get; }

protected ILogger Logger { get; }
protected IDarkSunEngine Engine { get; }
public BaseAiBehaviourExecutor(ILogger<BaseAiBehaviourExecutor> logger, IDarkSunEngine engine)
{
Logger = logger;
Engine = engine;
}

public BaseAiBehaviourExecutor(ILogger<BaseAiBehaviourExecutor> logger, IDarkSunEngine engine)
public ValueTask ProcessAsync(double delta)
{
_currentInterval -= delta;
if (!(_currentInterval <= 0))
{
Logger = logger;
Engine = engine;
return ValueTask.CompletedTask;
}

public ValueTask ProcessAsync(double delta)
{
_currentInterval -= delta;
if (!(_currentInterval <= 0))
{
return ValueTask.CompletedTask;
}
_currentInterval = Interval;
return DoAiAsync();
}

_currentInterval = Interval;
return DoAiAsync();
public ValueTask InitializeAsync(string mapId, NpcEntity npc, NpcGameObject npcGameObject)
{
Logger.LogDebug("Initializing {Name} AI Behaviour for {Type} {SubType} {Alignment} ID: {Id}", GetType().Name, npc.Type, npc.SubType, npc.Alignment, npcGameObject.ID);
MapId = mapId;
NpcGameObject = npcGameObject;
NpcEntity = npc;
return ValueTask.CompletedTask;
}

protected void SetInterval(double interval)
{
Interval = interval;
_currentInterval = interval;
}

}
protected virtual ValueTask DoAiAsync() => ValueTask.CompletedTask;

public ValueTask InitializeAsync(string mapId, NpcEntity npc, NpcGameObject npcGameObject)
{
Logger.LogDebug("Initializing {Name} AI Behaviour", GetType().Name);
MapId = mapId;
NpcGameObject = npcGameObject;
NpcEntity = npc;
return ValueTask.CompletedTask;
}
public virtual void Dispose()
{

protected void SetInterval(double interval)
{
Interval = interval;
_currentInterval = interval;
}
}

protected virtual ValueTask DoAiAsync()
protected bool MoveToDirection(MoveDirectionType direction)
{
var newPosition = NpcGameObject.Position.ToPointPosition().AddMovement(direction);
var canMove = Engine.WorldService.IsLocationWalkable(MapId, newPosition);
if (canMove)
{
return ValueTask.CompletedTask;
NpcGameObject.Position = newPosition.ToPoint();
return true;
}
return false;
}

public virtual void Dispose()
{
protected bool MoveRandomDirection() => MoveToDirection(MoveDirectionType.East.RandomEnumValue());

protected Task<List<TEntity>> GetEntitiesInRangeAsync<TEntity>(MapLayer layer, int range = 5) where TEntity : BaseGameObject =>
Engine.WorldService.GetEntitiesInRangeAsync<TEntity>(
MapId,
layer,
NpcGameObject.Position.ToPointPosition(),
range
);

protected List<PointPosition> GetPathToPosition(PointPosition position) =>
Engine.WorldService.CalculateAStarPath(MapId, NpcGameObject.Position.ToPointPosition(), position);

protected bool MoveToPosition(PointPosition position)
{
if (Engine.WorldService.IsLocationWalkable(MapId, position))
{
NpcGameObject.Position = new Point(position.X, position.Y);
return true;
}
return false;

}
}
25 changes: 12 additions & 13 deletions DarkStar.Api.Engine/Attributes/Ai/AiBehaviourAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
using DarkStar.Api.World.Types.Npc;
using DarkStar.Api.World.Types.Npc;

namespace DarkStar.Api.Engine.Attributes.Ai
{
namespace DarkStar.Api.Engine.Attributes.Ai;

[AttributeUsage(AttributeTargets.Class)]
public class AiBehaviourAttribute : Attribute
{
public NpcType Type { get; }

public NpcSubType SubType { get; }
[AttributeUsage(AttributeTargets.Class)]
public class AiBehaviourAttribute : Attribute
{
public NpcType Type { get; }

public AiBehaviourAttribute(NpcType type, NpcSubType subType)
{
Type = type;
SubType = subType;
}
public NpcSubType SubType { get; }

public AiBehaviourAttribute(NpcType type, NpcSubType subType)
{
Type = type;
SubType = subType;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using DarkStar.Api.Engine.Types.Commands;
using DarkStar.Api.Engine.Types.Commands;

namespace DarkStar.Api.Engine.Attributes.Commands;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
using DarkStar.Api.World.Types.GameObjects;
using DarkStar.Api.World.Types.GameObjects;

namespace DarkStar.Api.Engine.Attributes.Objects
namespace DarkStar.Api.Engine.Attributes.Objects;


[AttributeUsage(AttributeTargets.Class)]
public class GameObjectActionAttribute : Attribute
{
public GameObjectType Type { get; set; }

[AttributeUsage(AttributeTargets.Class)]
public class GameObjectActionAttribute : Attribute
public GameObjectActionAttribute(GameObjectType type)
{
public GameObjectType Type { get; set; }

public GameObjectActionAttribute(GameObjectType type)
{
Type = type;
}
Type = type;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using DarkStar.Api.World.Types.Items;
using DarkStar.Api.World.Types.Items;

namespace DarkStar.Api.Engine.Attributes.Objects;

Expand Down
13 changes: 4 additions & 9 deletions DarkStar.Api.Engine/Commands/Base/BaseCommandActionExecutor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using DarkStar.Api.Engine.Interfaces.Commands;
using DarkStar.Api.Engine.Interfaces.Commands;
using DarkStar.Api.Engine.Interfaces.Core;
using Microsoft.Extensions.Logging;

Expand All @@ -15,12 +15,7 @@ protected BaseCommandActionExecutor(ILogger<BaseCommandActionExecutor<TAction>>
Engine = engine;
}

public Task ProcessAsync(ICommandAction action)
{
return ProcessAsync((TAction)action);
}
public virtual Task ProcessAsync(TAction action)
{
return Task.CompletedTask;
}
public Task ProcessAsync(ICommandAction action) => ProcessAsync((TAction)action);

public virtual Task ProcessAsync(TAction action) => Task.CompletedTask;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down
2 changes: 1 addition & 1 deletion DarkStar.Api.Engine/DarkStar.Api.Engine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>0.1.7</Version>
<Version>0.1.12</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion DarkStar.Api.Engine/Data/Config/EngineConfig.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down
11 changes: 5 additions & 6 deletions DarkStar.Api.Engine/Data/Config/Sections/AssemblyConfig.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DarkStar.Api.Engine.Data.Config.Sections
namespace DarkStar.Api.Engine.Data.Config.Sections;

public class AssemblyConfig
{
public class AssemblyConfig
{
public List<string> AssemblyNames { get; set; } = new();
}
public List<string> AssemblyNames { get; set; } = new();
}
2 changes: 1 addition & 1 deletion DarkStar.Api.Engine/Data/Config/Sections/DatabaseConfig.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down
2 changes: 1 addition & 1 deletion DarkStar.Api.Engine/Data/Config/Sections/DatabaseType.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace DarkStar.Api.Engine.Data.Config.Sections;
namespace DarkStar.Api.Engine.Data.Config.Sections;

public enum DatabaseType
{
Expand Down
Loading

0 comments on commit f2a3b00

Please sign in to comment.