-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from tgiachi/dev
Dev
- Loading branch information
Showing
269 changed files
with
4,593 additions
and
4,103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
25
DarkStar.Api.Engine/Attributes/Ai/AiBehaviourAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
DarkStar.Api.Engine/Attributes/Commands/CommandActionAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
DarkStar.Api.Engine/Attributes/Network/NetworkConnectionHandlerAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
2 changes: 1 addition & 1 deletion
2
DarkStar.Api.Engine/Attributes/Network/NetworkMessageListenerAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
19 changes: 9 additions & 10 deletions
19
DarkStar.Api.Engine/Attributes/Objects/GameObjectActionAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
DarkStar.Api.Engine/ConnectionHandlers/BaseNetworkConnectionHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.