Skip to content

Commit d4847ee

Browse files
authored
Feature/add utility ai plugin (#24)
* First pass at adding the AI logic * Started adding Example * Added basic advice * Adding to basic example and adding notion of categories * Super basic AI example done * Added heatmaps with basic tests * Bumped the manual pack * Fixing back examples with AI
1 parent 3ad4fbd commit d4847ee

56 files changed

Lines changed: 2358 additions & 3 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

build/pack.bat

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
set version=8.0.28
1+
set version=13.2.00
22
dotnet pack ../src/SystemsR3 -c Release -o ../../_dist /p:version=%version%
33
dotnet pack ../src/SystemsR3.Infrastructure -c Release -o ../../_dist /p:version=%version%
44
dotnet pack ../src/SystemsR3.Plugins.Transforms -c Release -o ../../_dist /p:version=%version%
@@ -15,5 +15,6 @@ dotnet pack ../src/EcsR3.Plugins.GroupBinding -c Release -o ../../_dist /p:versi
1515
dotnet pack ../src/EcsR3.Plugins.Batching -c Release -o ../../_dist /p:version=%version%
1616
dotnet pack ../src/EcsR3.Plugins.Transforms -c Release -o ../../_dist /p:version=%version%
1717
dotnet pack ../src/EcsR3.Plugins.Persistence -c Release -o ../../_dist /p:version=%version%
18+
dotnet pack ../src/EcsR3.Plugins.UtilityAI -c Release -o ../../_dist /p:version=%version%
1819
dotnet pack ../src/EcsR3.Infrastructure -c Release -o ../../_dist /p:version=%version%
1920
dotnet pack ../src/EcsR3.Infrastructure.Ninject -c Release -o ../../_dist /p:version=%version%

src/EcsR3.Examples/Application/EcsR3ConsoleApplication.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
using EcsR3.Infrastructure;
66
using EcsR3.Infrastructure.Extensions;
77
using EcsR3.Plugins.Persistence;
8+
using EcsR3.Plugins.UtilityAI;
89
using EcsR3.Plugins.Views;
910
using SystemsR3.Infrastructure.Extensions;
11+
using SystemsR3.Scheduling;
1012

1113
namespace EcsR3.Examples.Application
1214
{
@@ -21,6 +23,7 @@ protected override void LoadPlugins()
2123
{
2224
RegisterPlugin(new ViewsPlugin());
2325
RegisterPlugin(new PersistencePlugin());
26+
RegisterPlugin(new UtilityAIPlugin());
2427

2528
DependencyRegistry.Unbind<ComponentDatabaseConfig>();
2629
DependencyRegistry.Bind<ComponentDatabaseConfig>(x => x.ToInstance(GetComponentDatabaseConfig));
@@ -36,5 +39,11 @@ protected override void ResolveApplicationDependencies()
3639
base.ResolveApplicationDependencies();
3740
EntityAllocationDatabase = DependencyResolver.Resolve<IEntityAllocationDatabase>();
3841
}
42+
43+
public override void StartApplication()
44+
{
45+
DefaultR3Initializer.SetDefaultObservableSystem();
46+
base.StartApplication();
47+
}
3948
}
4049
}

src/EcsR3.Examples/EcsR3.Examples.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<ItemGroup>
1818
<ProjectReference Include="..\EcsR3.Infrastructure\EcsR3.Infrastructure.csproj" />
1919
<ProjectReference Include="..\EcsR3.Plugins.Persistence\EcsR3.Plugins.Persistence.csproj" />
20+
<ProjectReference Include="..\EcsR3.Plugins.UtilityAI\EcsR3.Plugins.UtilityAI.csproj" />
2021
<ProjectReference Include="..\EcsR3.Plugins.Views\EcsR3.Plugins.Views.csproj" />
2122
<ProjectReference Include="..\EcsR3\EcsR3.csproj" />
2223
<ProjectReference Include="..\EcsR3.Infrastructure\EcsR3.Infrastructure.csproj" />
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using EcsR3.Blueprints;
2+
using EcsR3.Entities;
3+
using EcsR3.Entities.Accessors;
4+
using EcsR3.Examples.ExampleApps.UtilityAIExample.Components;
5+
using EcsR3.Plugins.UtilityAI.Components;
6+
7+
namespace EcsR3.Examples.ExampleApps.UtilityAIExample.Blueprints;
8+
9+
public class CharacterAgentBlueprint : IBlueprint
10+
{
11+
public string Name { get; }
12+
public int MaxHealth { get; }
13+
public float DamagePower { get; }
14+
public float HealPower { get; }
15+
16+
public CharacterAgentBlueprint(string name, int maxHealth, float damagePower, float healPower)
17+
{
18+
Name = name;
19+
MaxHealth = maxHealth;
20+
DamagePower = damagePower;
21+
HealPower = healPower;
22+
}
23+
24+
public void Apply(IEntityComponentAccessor entityComponentAccessor, Entity entity)
25+
{
26+
entityComponentAccessor.AddComponents(entity, [new AgentComponent(), new CharacterActionComponent(), new CharacterDataComponent()
27+
{
28+
Name = Name,
29+
MaxHealth = MaxHealth,
30+
Health = MaxHealth,
31+
DamagePower = DamagePower,
32+
HealPower = HealPower
33+
}]);
34+
}
35+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using EcsR3.Components;
2+
3+
namespace EcsR3.Examples.ExampleApps.UtilityAIExample.Components;
4+
5+
public class CharacterActionComponent : IComponent
6+
{
7+
public string CurrentAction { get; set; } = "Thinking...";
8+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.Numerics;
2+
using EcsR3.Components;
3+
4+
namespace EcsR3.Examples.ExampleApps.UtilityAIExample.Components;
5+
6+
public class CharacterDataComponent : IComponent
7+
{
8+
public string Name { get; set; }
9+
public int MaxHealth { get; set; }
10+
public int Health { get; set; }
11+
public float DamagePower { get; set; }
12+
public float HealPower { get; set; }
13+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using OpenRpg.Core.Utils;
3+
using SystemsR3.Infrastructure.Dependencies;
4+
using SystemsR3.Infrastructure.Extensions;
5+
6+
namespace EcsR3.Examples.ExampleApps.UtilityAIExample.Modules;
7+
8+
public class AIExampleModule : IDependencyModule
9+
{
10+
public void Setup(IDependencyRegistry registry)
11+
{
12+
registry.Bind<IRandomizer>(x => x.ToInstance(new DefaultRandomizer(new Random())));
13+
}
14+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using EcsR3.Components.Database;
2+
using EcsR3.Computeds.Components.Registries;
3+
using EcsR3.Entities;
4+
using EcsR3.Entities.Accessors;
5+
using EcsR3.Examples.ExampleApps.UtilityAIExample.Components;
6+
using EcsR3.Examples.ExampleApps.UtilityAIExample.Types;
7+
using EcsR3.Plugins.UtilityAI.Components;
8+
using EcsR3.Plugins.UtilityAI.Systems;
9+
using SystemsR3.Threading;
10+
11+
namespace EcsR3.Examples.ExampleApps.UtilityAIExample.Systems.AI.Actions;
12+
13+
public class AttackActionSystem : AdviceActionSystem<CharacterDataComponent, CharacterActionComponent>
14+
{
15+
public override int AdviceId => AdviceTypes.ShouldAttack;
16+
17+
public AttackActionSystem(IComponentDatabase componentDatabase, IEntityComponentAccessor entityComponentAccessor, IComputedComponentGroupRegistry computedComponentGroupRegistry, IThreadHandler threadHandler) : base(componentDatabase, entityComponentAccessor, computedComponentGroupRegistry, threadHandler)
18+
{}
19+
20+
protected override void ActionAdvice(Entity entity, AgentComponent agentComponent, CharacterDataComponent characterDataComponent, CharacterActionComponent characterActionComponent)
21+
{
22+
characterActionComponent.CurrentAction = $"[red]Attacks the darkness doing {characterDataComponent.DamagePower} points of damage[/]";
23+
}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using EcsR3.Components.Database;
2+
using EcsR3.Computeds.Components.Registries;
3+
using EcsR3.Entities;
4+
using EcsR3.Entities.Accessors;
5+
using EcsR3.Examples.ExampleApps.UtilityAIExample.Components;
6+
using EcsR3.Examples.ExampleApps.UtilityAIExample.Types;
7+
using EcsR3.Plugins.UtilityAI.Components;
8+
using EcsR3.Plugins.UtilityAI.Systems;
9+
using SystemsR3.Threading;
10+
11+
namespace EcsR3.Examples.ExampleApps.UtilityAIExample.Systems.AI.Actions;
12+
13+
public class FindHealerActionSystem : AdviceActionSystem<CharacterDataComponent, CharacterActionComponent>
14+
{
15+
public override int AdviceId => AdviceTypes.ShouldFindHealer;
16+
17+
public FindHealerActionSystem(IComponentDatabase componentDatabase, IEntityComponentAccessor entityComponentAccessor, IComputedComponentGroupRegistry computedComponentGroupRegistry, IThreadHandler threadHandler) : base(componentDatabase, entityComponentAccessor, computedComponentGroupRegistry, threadHandler)
18+
{}
19+
20+
protected override void ActionAdvice(Entity entity, AgentComponent agentComponent, CharacterDataComponent characterDataComponent, CharacterActionComponent characterActionComponent)
21+
{
22+
characterActionComponent.CurrentAction = "[yellow]Urgently looks around for healing[/]";
23+
}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using EcsR3.Components.Database;
2+
using EcsR3.Computeds.Components.Registries;
3+
using EcsR3.Entities;
4+
using EcsR3.Entities.Accessors;
5+
using EcsR3.Examples.ExampleApps.UtilityAIExample.Components;
6+
using EcsR3.Examples.ExampleApps.UtilityAIExample.Types;
7+
using EcsR3.Plugins.UtilityAI.Components;
8+
using EcsR3.Plugins.UtilityAI.Systems;
9+
using SystemsR3.Threading;
10+
11+
namespace EcsR3.Examples.ExampleApps.UtilityAIExample.Systems.AI.Actions;
12+
13+
public class HealSelfActionSystem : AdviceActionSystem<CharacterDataComponent, CharacterActionComponent>
14+
{
15+
public override int AdviceId => AdviceTypes.ShouldHeal;
16+
17+
public HealSelfActionSystem(IComponentDatabase componentDatabase, IEntityComponentAccessor entityComponentAccessor, IComputedComponentGroupRegistry computedComponentGroupRegistry, IThreadHandler threadHandler) : base(componentDatabase, entityComponentAccessor, computedComponentGroupRegistry, threadHandler)
18+
{}
19+
20+
protected override void ActionAdvice(Entity entity, AgentComponent agentComponent, CharacterDataComponent characterDataComponent, CharacterActionComponent characterActionComponent)
21+
{
22+
characterActionComponent.CurrentAction = $"[green]Heals themselves for {characterDataComponent.HealPower} points of health[/]";
23+
}
24+
}

0 commit comments

Comments
 (0)