diff options
Diffstat (limited to 'scripts/Entities/Actors/Actor.cs')
| -rw-r--r-- | scripts/Entities/Actors/Actor.cs | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/scripts/Entities/Actors/Actor.cs b/scripts/Entities/Actors/Actor.cs index ec00e30..71a32a5 100644 --- a/scripts/Entities/Actors/Actor.cs +++ b/scripts/Entities/Actors/Actor.cs @@ -1,4 +1,5 @@ using Godot; +using Godot.Collections; using TheLegendOfGustav.Magic; using TheLegendOfGustav.Map; using TheLegendOfGustav.Utils; @@ -9,7 +10,7 @@ namespace TheLegendOfGustav.Entities.Actors; /// A classe de ator define um personagem no jogo. /// </summary> [GlobalClass] -public partial class Actor : Entity +public partial class Actor : Entity, ISaveable { #region Fields private int mp; @@ -29,6 +30,9 @@ public partial class Actor : Entity { SetDefinition(definition); } + public Actor(Vector2I initialPosition, MapData map) : base(initialPosition, map) + { + } #endregion #region Signals @@ -278,5 +282,48 @@ public partial class Actor : Entity MapData.UnregisterBlockingEntity(this); EmitSignal(SignalName.Died); } + + public new Dictionary<string, Variant> GetSaveData() + { + Dictionary<string, Variant> baseData = base.GetSaveData(); + baseData.Add("energy", Energy); + baseData.Add("max_hp", MaxHp); + baseData.Add("hp", Hp); + baseData.Add("max_mp", MaxMp); + baseData.Add("mp", MaxMp); + baseData.Add("atk", Atk); + baseData.Add("def", Def); + baseData.Add("men", Men); + baseData.Add("mp_regen_rate", MpRegenRate); + baseData.Add("mp_regen_per_turn", MpRegenPerTurn); + baseData.Add("spell_book", SpellBook.GetSaveData()); + + return baseData; + } + + public new bool LoadSaveData(Dictionary<string, Variant> saveData) + { + if (!base.LoadSaveData(saveData)) + { + return false; + } + + if (!SpellBook.LoadSaveData((Dictionary<string, Variant>)saveData["spell_book"])) + { + return false; + } + + Energy = (int)saveData["energy"]; + MaxHp = (int)saveData["max_hp"]; + Hp = (int)saveData["hp"]; + MaxMp = (int)saveData["max_mp"]; + Mp = (int)saveData["max_mp"]; + Atk = (int)saveData["atk"]; + Def = (int)saveData["def"]; + Men = (int)saveData["men"]; + MpRegenRate = (int)saveData["mp_regen_rate"]; + MpRegenPerTurn = (int)saveData["mp_regen_per_turn"]; + return true; + } #endregion }
\ No newline at end of file |
