From 6e9844b3432255bacaa575fd5da0d170ef8ccf08 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sat, 12 Mar 2022 12:37:26 +0100 Subject: [PATCH] Allow changing creature types --- src/Battling/Models/Creature.cpp | 12 ++++++++++++ src/Battling/Models/Creature.hpp | 1 + 2 files changed, 13 insertions(+) diff --git a/src/Battling/Models/Creature.cpp b/src/Battling/Models/Creature.cpp index ffda923..a89b991 100644 --- a/src/Battling/Models/Creature.cpp +++ b/src/Battling/Models/Creature.cpp @@ -134,6 +134,10 @@ namespace CreatureLib::Battling { ResetActiveScripts(); _weight = _variant->GetWeight(); _height = _variant->GetHeight(); + _types.clear(); + for (auto t : _variant->GetTypes()) { + _types.push_back(t); + } } void Battling::Creature::SetOnBattleField(bool value) { @@ -273,6 +277,14 @@ namespace CreatureLib::Battling { return std::find(_types.begin(), _types.end(), type) != _types.end(); } + void Creature::SetType(u8 index, u8 type) noexcept { + if (_types.size() > index) { + _types[index] = type; + } else { + _types.push_back(type); + } + } + size_t Creature::ScriptCount() const { auto c = 3; if (_battleData.Side.HasValue()) { diff --git a/src/Battling/Models/Creature.hpp b/src/Battling/Models/Creature.hpp index 4df8559..65889be 100644 --- a/src/Battling/Models/Creature.hpp +++ b/src/Battling/Models/Creature.hpp @@ -156,6 +156,7 @@ namespace CreatureLib::Battling { [[nodiscard]] bool IsFainted() const noexcept; [[nodiscard]] const std::vector& GetTypes() const noexcept; [[nodiscard]] bool HasType(uint8_t type) const noexcept; + void SetType(u8 index, u8 type) noexcept; uint32_t GetMaxHealth() const noexcept { return _boostedStats.GetHealth(); } void ChangeLevelBy(int8_t amount);