summaryrefslogtreecommitdiff
path: root/scripts/actors
diff options
context:
space:
mode:
authorMatheus <matheus.guedes.mg.m@gmail.com>2025-08-26 22:59:57 -0300
committerMatheus <matheus.guedes.mg.m@gmail.com>2025-08-26 22:59:57 -0300
commit6c7e2ac133986efa57b43df52a5498c6f7efcf75 (patch)
tree8404bfd3415a8dfcf7073191cbfdf58cc7c905ed /scripts/actors
parenta3103718796a472da76838bf6fd72ba5d8409d79 (diff)
AI
Diffstat (limited to 'scripts/actors')
-rw-r--r--scripts/actors/AI/BaseAI.cs20
-rw-r--r--scripts/actors/AI/BaseAI.cs.uid1
-rw-r--r--scripts/actors/AI/HostileEnemyAI.cs38
-rw-r--r--scripts/actors/AI/HostileEnemyAI.cs.uid1
-rw-r--r--scripts/actors/Actor.cs60
-rw-r--r--scripts/actors/ActorDefinition.cs12
-rw-r--r--scripts/actors/Enemy.cs34
-rw-r--r--scripts/actors/Enemy.cs.uid1
-rw-r--r--scripts/actors/EnemyDefinition.cs8
-rw-r--r--scripts/actors/EnemyDefinition.cs.uid1
-rw-r--r--scripts/actors/actions/MovementAction.cs2
11 files changed, 168 insertions, 10 deletions
diff --git a/scripts/actors/AI/BaseAI.cs b/scripts/actors/AI/BaseAI.cs
new file mode 100644
index 0000000..f9b5387
--- /dev/null
+++ b/scripts/actors/AI/BaseAI.cs
@@ -0,0 +1,20 @@
+using Godot;
+
+public abstract partial class BaseAI : Node {
+ protected Actor body;
+
+ public override void _Ready()
+ {
+ base._Ready();
+ body = GetParent<Actor>();
+ }
+
+ public abstract void Perform();
+
+ public Godot.Collections.Array<Vector2> GetPathTo(Vector2I destination) {
+ Godot.Collections.Array<Vector2> list = [];
+ Vector2[] path = body.Map_Data.Pathfinder.GetPointPath(body.GridPosition, destination);
+ list.AddRange(path);
+ return list;
+ }
+} \ No newline at end of file
diff --git a/scripts/actors/AI/BaseAI.cs.uid b/scripts/actors/AI/BaseAI.cs.uid
new file mode 100644
index 0000000..b23724c
--- /dev/null
+++ b/scripts/actors/AI/BaseAI.cs.uid
@@ -0,0 +1 @@
+uid://jgm5qk02hism
diff --git a/scripts/actors/AI/HostileEnemyAI.cs b/scripts/actors/AI/HostileEnemyAI.cs
new file mode 100644
index 0000000..061295f
--- /dev/null
+++ b/scripts/actors/AI/HostileEnemyAI.cs
@@ -0,0 +1,38 @@
+using Godot;
+
+public partial class HostileEnemyAI : BaseAI
+{
+ private Godot.Collections.Array<Vector2> path = [];
+
+ public override void Perform()
+ {
+ Player target = body.Map_Data.Player;
+ Vector2I offset = target.GridPosition - body.GridPosition;
+ int distance = int.Max(int.Abs(offset.X), int.Abs(offset.Y));
+
+ Action action;
+
+ if (body.Map_Data.GetTile(body.GridPosition).IsInView) {
+ if (distance <= 1) {
+ action = new MeleeAction(body, offset);
+ action.Perform();
+ return;
+ }
+ path = GetPathTo(target.GridPosition);
+ GD.Print($"Arno Breker: {path}");
+ path.RemoveAt(0);
+ }
+
+ if (path.Count > 0) {
+ Vector2I destination = (Vector2I) path[0];
+ GD.Print(destination);
+ if (body.Map_Data.GetBlockingActorAtPosition(destination) != null) {
+ return;
+ }
+
+ action = new MovementAction(body, destination - body.GridPosition);
+ action.Perform();
+ path.RemoveAt(0);
+ }
+ }
+} \ No newline at end of file
diff --git a/scripts/actors/AI/HostileEnemyAI.cs.uid b/scripts/actors/AI/HostileEnemyAI.cs.uid
new file mode 100644
index 0000000..0fa2c32
--- /dev/null
+++ b/scripts/actors/AI/HostileEnemyAI.cs.uid
@@ -0,0 +1 @@
+uid://db28cxff4pl3t
diff --git a/scripts/actors/Actor.cs b/scripts/actors/Actor.cs
index e8d728a..199c301 100644
--- a/scripts/actors/Actor.cs
+++ b/scripts/actors/Actor.cs
@@ -3,18 +3,10 @@ using Godot;
[GlobalClass]
public abstract partial class Actor : Sprite2D
{
- private ActorDefinition definition;
- private Vector2I gridPosition = Vector2I.Zero;
+ protected ActorDefinition definition;
public MapData Map_Data { get; set; }
- public Actor(Vector2I initialPosition, MapData map, ActorDefinition definition) {
- GridPosition = initialPosition;
- Map_Data = map;
- this.definition = definition;
- Texture = definition.texture;
- Centered = false;
- }
-
+ private Vector2I gridPosition = Vector2I.Zero;
public Vector2I GridPosition {
set {
gridPosition = value;
@@ -31,6 +23,30 @@ public abstract partial class Actor : Sprite2D
get => definition.name;
}
+ private int hp;
+ public int MaxHp { get; private set; }
+ public int Hp {
+ get => hp;
+ set {
+ hp = int.Clamp(value, 0, MaxHp);
+ }
+ }
+
+ private int mp;
+ public int MaxMp { get; private set; }
+ public int Mp {
+ get => mp;
+ set {
+ mp = int.Clamp(value, 0, MaxMp);
+ }
+ }
+
+ public int Atk { get; private set; }
+
+ public int Def { get; private set; }
+
+ public int Men { get; private set; }
+
public override void _Ready()
{
base._Ready();
@@ -38,6 +54,30 @@ public abstract partial class Actor : Sprite2D
}
public void Walk(Vector2I offset) {
+ Map_Data.UnregisterBlockingActor(this);
GridPosition += offset;
+ Map_Data.RegisterBlockingActor(this);
+ }
+
+ public Actor(Vector2I initialPosition, MapData map, ActorDefinition definition) {
+ GridPosition = initialPosition;
+ Map_Data = map;
+ Centered = false;
+
+ SetDefinition(definition);
+ }
+
+ public virtual void SetDefinition(ActorDefinition definition) {
+ this.definition = definition;
+ Texture = definition.texture;
+
+ MaxHp = definition.Hp;
+ Hp = definition.Hp;
+ MaxMp = definition.Mp;
+ Mp = definition.Mp;
+
+ Atk = definition.Atk;
+ Def = definition.Def;
+ Men = definition.Men;
}
} \ No newline at end of file
diff --git a/scripts/actors/ActorDefinition.cs b/scripts/actors/ActorDefinition.cs
index 5678921..5c0ece9 100644
--- a/scripts/actors/ActorDefinition.cs
+++ b/scripts/actors/ActorDefinition.cs
@@ -13,4 +13,16 @@ public partial class ActorDefinition : Resource
[ExportCategory("Mechanics")]
[Export]
public bool blocksMovement = true;
+
+ [ExportCategory("Stats")]
+ [Export]
+ public int Hp;
+ [Export]
+ public int Mp;
+ [Export]
+ public int Atk;
+ [Export]
+ public int Def;
+ [Export]
+ public int Men;
}
diff --git a/scripts/actors/Enemy.cs b/scripts/actors/Enemy.cs
new file mode 100644
index 0000000..6c111b1
--- /dev/null
+++ b/scripts/actors/Enemy.cs
@@ -0,0 +1,34 @@
+using Godot;
+using System;
+
+public enum AIType
+{
+ None,
+ DefaultHostile
+};
+
+public partial class Enemy : Actor
+{
+ public BaseAI Soul { get; private set; }
+
+ public bool IsAlive { get => Soul != null; }
+
+ public Enemy(Vector2I initialPosition, MapData map, EnemyDefinition definition) : base(initialPosition, map, definition)
+ {
+ SetDefinition(definition);
+ }
+
+ public void SetDefinition(EnemyDefinition definition)
+ {
+ base.SetDefinition(definition);
+
+ switch(definition.AI) {
+ case AIType.None:
+ break;
+ case AIType.DefaultHostile:
+ Soul = new HostileEnemyAI();
+ AddChild(Soul);
+ break;
+ }
+ }
+}
diff --git a/scripts/actors/Enemy.cs.uid b/scripts/actors/Enemy.cs.uid
new file mode 100644
index 0000000..93255b7
--- /dev/null
+++ b/scripts/actors/Enemy.cs.uid
@@ -0,0 +1 @@
+uid://bef1fo3vgvxej
diff --git a/scripts/actors/EnemyDefinition.cs b/scripts/actors/EnemyDefinition.cs
new file mode 100644
index 0000000..21d4ca0
--- /dev/null
+++ b/scripts/actors/EnemyDefinition.cs
@@ -0,0 +1,8 @@
+using Godot;
+
+[GlobalClass]
+public partial class EnemyDefinition : ActorDefinition {
+ [ExportCategory("AI")]
+ [Export]
+ public AIType AI;
+} \ No newline at end of file
diff --git a/scripts/actors/EnemyDefinition.cs.uid b/scripts/actors/EnemyDefinition.cs.uid
new file mode 100644
index 0000000..1ba03e1
--- /dev/null
+++ b/scripts/actors/EnemyDefinition.cs.uid
@@ -0,0 +1 @@
+uid://dkfdm2m2scyks
diff --git a/scripts/actors/actions/MovementAction.cs b/scripts/actors/actions/MovementAction.cs
index 54bb99c..704dd4f 100644
--- a/scripts/actors/actions/MovementAction.cs
+++ b/scripts/actors/actions/MovementAction.cs
@@ -15,6 +15,8 @@ public partial class MovementAction : DirectionalAction
if (GetBlockingActorAtPosition(finalDestination) != null) return;
+ GD.Print("What?");
+
actor.Walk(Offset);
}
}