Skip to content

Commit

Permalink
Merge pull request #38 from tgiachi/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
tgiachi committed May 2, 2023
2 parents 1e73648 + bebb681 commit ab674a7
Show file tree
Hide file tree
Showing 55 changed files with 3,361 additions and 231 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

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.6.0"></a>
## [0.6.0](https://www.github.com/tgiachi/DarkSun/releases/tag/v0.6.0) (2023-5-2)

### ✨ Features

* add support for item types and item category types ([1b52abf](https://www.github.com/tgiachi/DarkSun/commit/1b52abf9981b9ec040758b7f817dfe53c3e3e940))
* added base project for client ([34ba796](https://www.github.com/tgiachi/DarkSun/commit/34ba796d166428f187ee5ecf6dd63095e296e59c))
* **ai:** add support for adding AI scripts by NPC type and name ([8d687ff](https://www.github.com/tgiachi/DarkSun/commit/8d687ff96c05b5cda5abed04b1e193b5693e26c3))
* **SeedService.cs:** add method to add text content seed ([62694d0](https://www.github.com/tgiachi/DarkSun/commit/62694d0517a01c2f9db598dad016a05c8268d4b7))

### Other

* remove unused TileSetMapSerializable class ([1cc4bc3](https://www.github.com/tgiachi/DarkSun/commit/1cc4bc370f75c6c3ae17f68e8a503596b0f4a663))

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

Expand Down
4 changes: 2 additions & 2 deletions DarkStar.Api.Engine/Ai/Base/BaseAiBehaviourExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public ValueTask ProcessAsync(double delta)
return DoAiAsync();
}

public ValueTask InitializeAsync(string mapId, NpcEntity npc, NpcGameObject npcGameObject)
public virtual ValueTask InitializeAsync(string mapId, NpcEntity npc, NpcGameObject npcGameObject)
{
Logger.LogDebug("Initializing {Name} AI Behaviour for {GameObjectType} {SubType} {Alignment} ID: {Id}", GetType().Name, npc.Type, npc.SubType, npc.Alignment, npcGameObject.ID);
MapId = mapId;
Expand Down Expand Up @@ -100,7 +100,7 @@ protected bool MoveToPosition(PointPosition position)
if (Engine.WorldService.IsLocationWalkable(MapId, position))
{
NpcGameObject.Position = new Point(position.X, position.Y);

return true;
}
return false;
Expand Down
43 changes: 43 additions & 0 deletions DarkStar.Api.Engine/Ai/Base/BaseScriptableBehaviourExecutor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using DarkStar.Api.Engine.Data.Ai;
using DarkStar.Api.Engine.Interfaces.Core;
using DarkStar.Api.Engine.Map.Entities;
using DarkStar.Database.Entities.Npc;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

namespace DarkStar.Api.Engine.Ai.Base;

public class BaseScriptableBehaviourExecutor : BaseAiBehaviourExecutor
{

private readonly IServiceProvider _serviceProvider;

public AiContext Ai { get; set; }
public Action<AiContext> ExecutorFunc { get; set; }

public BaseScriptableBehaviourExecutor(ILogger<BaseScriptableBehaviourExecutor> logger, IDarkSunEngine engine, IServiceProvider serviceProvider) : base(logger, engine) => _serviceProvider = serviceProvider;

public override async ValueTask InitializeAsync(string mapId, NpcEntity npc, NpcGameObject npcGameObject)
{
await base.InitializeAsync(mapId, npc, npcGameObject);
InitAiContext();
}

private void InitAiContext()
{
Ai = new AiContext
{
NpcGameObject = NpcGameObject,
NpcEntity = NpcEntity,
MapId = MapId,
Logger = _serviceProvider.GetRequiredService<ILogger<AiContext>>()
};
}

protected override ValueTask DoAiAsync()
{
ExecutorFunc.Invoke(Ai);
return ValueTask.CompletedTask;

}
}
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.5.0</Version>
<Version>0.6.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
14 changes: 14 additions & 0 deletions DarkStar.Api.Engine/Data/Ai/AiContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using DarkStar.Api.Engine.Map.Entities;
using DarkStar.Database.Entities.Npc;
using Microsoft.Extensions.Logging;

namespace DarkStar.Api.Engine.Data.Ai;

public class AiContext
{
public NpcGameObject NpcGameObject { get; set; } = null!;
public NpcEntity NpcEntity { get; set; } = null!;
public string MapId { get; set; } = null!;

public ILogger<AiContext> Logger { get; set; }
}
5 changes: 5 additions & 0 deletions DarkStar.Api.Engine/Interfaces/Services/IAiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DarkStar.Api.Engine.Data.Ai;
using DarkStar.Api.Engine.Interfaces.Services.Base;
using DarkStar.Api.World.Types.Npc;

namespace DarkStar.Api.Engine.Interfaces.Services;

public interface IAiService : IDarkSunEngineService
{
void AddAiScriptByType(NpcType npcType, NpcSubType npcSubType, Action<AiContext> context);
void AddAiScriptByName(string name, Action<AiContext> context);

}
2 changes: 1 addition & 1 deletion DarkStar.Api.Engine/Interfaces/Services/ISeedService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ public interface ISeedService : IDarkSunEngineService
{
void AddRaceToSeed(string race, string description, short tileId, BaseStatEntity stat);
void AddGameObjectToSeed(string name, string description, int tileType, GameObjectType gameObjectType);

void AddGameObjectSeed(string name, string description, string tileNAme, string gameObjectName, object data);
void AddTextContentSeed(string name, string content);
}
9 changes: 9 additions & 0 deletions DarkStar.Api.Engine/Interfaces/Services/ITypeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading.Tasks;
using DarkStar.Api.Engine.Interfaces.Services.Base;
using DarkStar.Api.World.Types.GameObjects;
using DarkStar.Api.World.Types.Items;
using DarkStar.Api.World.Types.Npc;
using DarkStar.Api.World.Types.Tiles;

Expand Down Expand Up @@ -41,4 +42,12 @@ public interface ITypeService : IDarkSunEngineService
Tile GetTileForNpc(NpcType npcType, NpcSubType npcSubType);
Tile GetTileForNpc(string npcType, string npcSubType);

ItemType AddItemType(string name);
ItemType AddItemType(short id, string name);
ItemType SearchItemType(string name);

ItemCategoryType AddItemCategoryType(string name);
ItemCategoryType AddItemCategoryType(short id, string name);
ItemCategoryType SearchItemCategoryType(string name);

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DarkStar.Api.Engine.Interfaces.Core;
using DarkStar.Network.Interfaces;
using DarkStar.Network.Protocol.Interfaces.Messages;
Expand Down Expand Up @@ -39,15 +34,9 @@ public async Task OnMessageReceivedAsync(string sessionId, DarkStarMessageType m
}
}

public virtual Task<List<IDarkStarNetworkMessage>> OnMessageReceivedAsync(string sessionId, DarkStarMessageType messageType, TMessage message)
{
return Task.FromResult(new List<IDarkStarNetworkMessage>());
}
public virtual Task<List<IDarkStarNetworkMessage>> OnMessageReceivedAsync(string sessionId, DarkStarMessageType messageType, TMessage message) => Task.FromResult(new List<IDarkStarNetworkMessage>());

protected List<IDarkStarNetworkMessage> SingleMessage(IDarkStarNetworkMessage message)
{
return new List<IDarkStarNetworkMessage>() { message };
}
protected List<IDarkStarNetworkMessage> SingleMessage(IDarkStarNetworkMessage message) => new() { message };

protected List<IDarkStarNetworkMessage> MultipleMessages(params IDarkStarNetworkMessage[] message)
{
Expand All @@ -57,8 +46,5 @@ protected List<IDarkStarNetworkMessage> MultipleMessages(params IDarkStarNetwork
return mess;
}

protected List<IDarkStarNetworkMessage> EmptyMessage()
{
return new List<IDarkStarNetworkMessage>();
}
protected List<IDarkStarNetworkMessage> EmptyMessage() => new();
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using DarkStar.Api.Attributes.Seed;
using DarkStar.Api.Engine.Serialization.Seeds.Converters;
using DarkStar.Api.World.Types.Map;

using TinyCsv.Attributes;

namespace DarkStar.Api.Engine.Serialization.Seeds;
Expand All @@ -16,14 +11,11 @@ namespace DarkStar.Api.Engine.Serialization.Seeds;
[Delimiter(";")]
public class ItemDropObjectSeedEntity
{
[Column]
public string TemplateName { get; set; } = null!;
[Column] public string TemplateName { get; set; } = null!;

[Column(converter: typeof(MapLayerConverter))]
public MapLayer MapLayer { get; set; }
[Column]
public string ItemName { get; set; } = null!;
public MapLayer MapLayer { get; set; } = MapLayer.Items;

[Column]
public float DropRate { get; set; }
[Column] public string ItemName { get; set; } = null!;
[Column] public float DropRate { get; set; }
}
47 changes: 15 additions & 32 deletions DarkStar.Api.Engine/Serialization/Seeds/ItemObjectSeedEntity.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using DarkStar.Api.Attributes.Seed;
using DarkStar.Api.Engine.Serialization.Seeds.Converters;
using DarkStar.Api.Serialization.Converters;

using DarkStar.Api.World.Types.Equippable;
using DarkStar.Api.World.Types.Items;
using DarkStar.Api.World.Types.Tiles;

using TinyCsv.Attributes;

Expand All @@ -19,34 +14,22 @@ namespace DarkStar.Api.Engine.Serialization.Seeds;
[Delimiter(";")]
public class ItemObjectSeedEntity
{
[Column]
public string Name { get; set; } = null!;
[Column]
public string Description { get; set; } = null!;
[Column]
public int Weight { get; set; } = 1;
[Column] public string Name { get; set; } = null!;
[Column] public string Description { get; set; } = null!;
[Column] public int Weight { get; set; } = 1;
[Column] public string TileName { get; set; }
[Column] public string Category { get; set; }
[Column] public string Type { get; set; }

[Column(converter: typeof(TileTypeConverter))]
public int TileType { get; set; }

//[Column(converter: typeof(ItemCategoryTypeConverter))]
public ItemCategoryType Category { get; set; }
//[Column(converter: typeof(ItemTypeConverter))]
public ItemType Type { get; set; }
[Column(converter: typeof(EquipLocationTypeConverter))]
public EquipLocationType EquipLocation { get; set; }

[Column(converter: typeof(ItemRarityConverter))]
public ItemRarityType ItemRarity { get; set; }
[Column]
public string SellDice { get; set; } = null!;
[Column]
public string BuyDice { get; set; } = null!;
[Column]
public string Attack { get; set; } = null!;
[Column]
public string Defense { get; set; } = null!;
[Column]
public string Speed { get; set; } = null!;
[Column]
public int MinLevel { get; set; }
[Column] public string SellDice { get; set; } = null!;
[Column] public string BuyDice { get; set; } = null!;
[Column] public string Attack { get; set; } = null!;
[Column] public string Defense { get; set; } = null!;
[Column] public string Speed { get; set; } = null!;
[Column] public int MinLevel { get; set; }
}
2 changes: 1 addition & 1 deletion DarkStar.Api/DarkStar.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<PackageProjectUrl>https://github.com/tgiachi/darksun</PackageProjectUrl>
<RepositoryUrl>https://github.com/tgiachi/darksun</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<Version>0.5.0</Version>
<Version>0.6.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 0 additions & 2 deletions DarkStar.Api/Serialization/TileSets/TileSetMapSerializable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,5 @@ public class TileSetMapSerializable
[Column]
public bool IsTransparent { get; set; }



public override string ToString() => $"Id: {Id}, IsBlocked: {IsTransparent}";
}
2 changes: 2 additions & 0 deletions DarkStar.Api/World/Types/Items/ItemCategoryType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ public ItemCategoryType()
{

}

public override string ToString() => $"{Id} - {Name}";
}
5 changes: 3 additions & 2 deletions DarkStar.Api/World/Types/Items/ItemType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace DarkStar.Api.World.Types.Items;

[StructLayout(LayoutKind.Auto)]
public struct ItemType
public struct ItemType
{
public ushort Id { get; set; }
public string Name { get; set; }
Expand All @@ -21,6 +21,7 @@ public ItemType(ushort id, string name)

public ItemType()
{

}

public override string ToString() => $"{Id} - {Name}";
}
14 changes: 14 additions & 0 deletions DarkStar.Client/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react-hooks/recommended',
],
parser: '@typescript-eslint/parser',
parserOptions: { ecmaVersion: 'latest', sourceType: 'module' },
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': 'warn',
},
}
24 changes: 24 additions & 0 deletions DarkStar.Client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
13 changes: 13 additions & 0 deletions DarkStar.Client/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
Loading

0 comments on commit ab674a7

Please sign in to comment.