summaryrefslogtreecommitdiff
path: root/scripts/Entities/Actors/Enemy.cs
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/Entities/Actors/Enemy.cs')
-rw-r--r--scripts/Entities/Actors/Enemy.cs32
1 files changed, 31 insertions, 1 deletions
diff --git a/scripts/Entities/Actors/Enemy.cs b/scripts/Entities/Actors/Enemy.cs
index d398176..4994534 100644
--- a/scripts/Entities/Actors/Enemy.cs
+++ b/scripts/Entities/Actors/Enemy.cs
@@ -1,4 +1,5 @@
using Godot;
+using Godot.Collections;
using TheLegendOfGustav.Entities.Actors.AI;
using TheLegendOfGustav.Map;
@@ -8,7 +9,7 @@ namespace TheLegendOfGustav.Entities.Actors;
/// Um inimigo é uma espécie de ator que é
/// hostil ao jogador. Inimigos são controlados por IA.
/// </summary>
-public partial class Enemy : Actor
+public partial class Enemy : Actor, ISaveable
{
private EnemyDefinition definition;
@@ -17,6 +18,9 @@ public partial class Enemy : Actor
this.definition = definition;
SetDefinition(definition);
}
+ public Enemy(Vector2I initialPosition, MapData map) : base(initialPosition, map)
+ {
+ }
/// <summary>
/// A alma do ator. Gera ações que são executadas todo turno.
@@ -30,9 +34,12 @@ public partial class Enemy : Actor
/// <param name="definition">Definição do inimigo.</param>
public void SetDefinition(EnemyDefinition definition)
{
+ this.definition = definition;
// Definimos as características do ator.
base.SetDefinition(this.definition);
+ Soul?.QueueFree();
+
// Definimos qual IA utilizar.
switch (definition.AI)
{
@@ -51,4 +58,27 @@ public partial class Enemy : Actor
Soul = null;
base.Die();
}
+
+ public new Dictionary<string, Variant> GetSaveData()
+ {
+ Dictionary<string, Variant> baseData = base.GetSaveData();
+ baseData.Add("definition", definition.ResourcePath);
+
+ return baseData;
+ }
+
+ public new bool LoadSaveData(Dictionary<string, Variant> saveData)
+ {
+ string definitionPath = (string)saveData["definition"];
+ EnemyDefinition definition = GD.Load<EnemyDefinition>(definitionPath);
+
+ SetDefinition(definition);
+
+ if (!base.LoadSaveData(saveData))
+ {
+ return false;
+ }
+
+ return true;
+ }
}