From f4ed469fc9eaeebf39093fbf6601581cc10c6e2f Mon Sep 17 00:00:00 2001 From: Matheus Date: Sun, 26 Oct 2025 20:02:15 -0300 Subject: feat:save AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit O vazio dentro de mim é como uma xícara de café esquecida no canto da mesa. --- scripts/Entities/Actors/Enemy.cs | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'scripts/Entities/Actors/Enemy.cs') 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. /// -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) + { + } /// /// A alma do ator. Gera ações que são executadas todo turno. @@ -30,9 +34,12 @@ public partial class Enemy : Actor /// Definição do inimigo. 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 GetSaveData() + { + Dictionary baseData = base.GetSaveData(); + baseData.Add("definition", definition.ResourcePath); + + return baseData; + } + + public new bool LoadSaveData(Dictionary saveData) + { + string definitionPath = (string)saveData["definition"]; + EnemyDefinition definition = GD.Load(definitionPath); + + SetDefinition(definition); + + if (!base.LoadSaveData(saveData)) + { + return false; + } + + return true; + } } -- cgit v1.2.3