Make Attack secondary effect a unique_ptr.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
8418c814b4
commit
aba56d2fdd
|
@ -150,7 +150,7 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature* targe
|
||||||
|
|
||||||
if (attackData->GetCategory() == Library::AttackCategory::Status) {
|
if (attackData->GetCategory() == Library::AttackCategory::Status) {
|
||||||
if (attackData->HasSecondaryEffect()) {
|
if (attackData->HasSecondaryEffect()) {
|
||||||
auto effect = attackData->GetSecondaryEffect();
|
auto& effect = attackData->GetSecondaryEffect();
|
||||||
bool hasSecondaryEffect;
|
bool hasSecondaryEffect;
|
||||||
if (effect->GetChance() == -1) {
|
if (effect->GetChance() == -1) {
|
||||||
hasSecondaryEffect = true;
|
hasSecondaryEffect = true;
|
||||||
|
@ -175,7 +175,7 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature* targe
|
||||||
bool preventSecondary = false;
|
bool preventSecondary = false;
|
||||||
HOOK(PreventSecondaryEffects, targetSource, attack, target, hitIndex, &preventSecondary);
|
HOOK(PreventSecondaryEffects, targetSource, attack, target, hitIndex, &preventSecondary);
|
||||||
if (!preventSecondary) {
|
if (!preventSecondary) {
|
||||||
auto effect = attackData->GetSecondaryEffect();
|
auto& effect = attackData->GetSecondaryEffect();
|
||||||
bool hasSecondaryEffect;
|
bool hasSecondaryEffect;
|
||||||
if (effect->GetChance() == -1) {
|
if (effect->GetChance() == -1) {
|
||||||
hasSecondaryEffect = true;
|
hasSecondaryEffect = true;
|
||||||
|
|
|
@ -23,7 +23,7 @@ namespace CreatureLib::Battling {
|
||||||
if (battle != nullptr) {
|
if (battle != nullptr) {
|
||||||
if (_attack->GetAttack()->HasSecondaryEffect()) {
|
if (_attack->GetAttack()->HasSecondaryEffect()) {
|
||||||
auto library = battle->GetLibrary();
|
auto library = battle->GetLibrary();
|
||||||
auto effect = _attack->GetAttack()->GetSecondaryEffect();
|
auto& effect = _attack->GetAttack()->GetSecondaryEffect();
|
||||||
_attackScript = library->LoadScript(ScriptCategory::Attack, effect->GetEffectName());
|
_attackScript = library->LoadScript(ScriptCategory::Attack, effect->GetEffectName());
|
||||||
if (_attackScript != nullptr) {
|
if (_attackScript != nullptr) {
|
||||||
_attackScript->OnInitialize(effect->GetParameters());
|
_attackScript->OnInitialize(effect->GetParameters());
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define CREATURELIB_ATTACKDATA_HPP
|
#define CREATURELIB_ATTACKDATA_HPP
|
||||||
|
|
||||||
#include <Arbutils/ConstString.hpp>
|
#include <Arbutils/ConstString.hpp>
|
||||||
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
#include "AttackCategory.hpp"
|
#include "AttackCategory.hpp"
|
||||||
|
@ -21,14 +22,14 @@ namespace CreatureLib::Library {
|
||||||
uint8_t _baseUsages;
|
uint8_t _baseUsages;
|
||||||
AttackTarget _target;
|
AttackTarget _target;
|
||||||
int8_t _priority;
|
int8_t _priority;
|
||||||
const SecondaryEffect* _effect = nullptr;
|
std::unique_ptr<const SecondaryEffect> _effect = nullptr;
|
||||||
std::unordered_set<uint32_t> _flags;
|
std::unordered_set<uint32_t> _flags;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AttackData(const ConstString& name, uint8_t type, AttackCategory category, uint8_t power, uint8_t accuracy,
|
AttackData(const ConstString& name, uint8_t type, AttackCategory category, uint8_t power, uint8_t accuracy,
|
||||||
uint8_t baseUsage, AttackTarget target, int8_t priority, const SecondaryEffect* effect,
|
uint8_t baseUsage, AttackTarget target, int8_t priority, const SecondaryEffect* effect,
|
||||||
std::unordered_set<uint32_t> flags);
|
std::unordered_set<uint32_t> flags);
|
||||||
virtual ~AttackData() { delete _effect; };
|
virtual ~AttackData() = default;
|
||||||
|
|
||||||
inline const ConstString& GetName() const noexcept { return _name; }
|
inline const ConstString& GetName() const noexcept { return _name; }
|
||||||
inline const uint8_t GetType() const noexcept { return _type; }
|
inline const uint8_t GetType() const noexcept { return _type; }
|
||||||
|
@ -41,7 +42,7 @@ namespace CreatureLib::Library {
|
||||||
inline bool HasSecondaryEffect() const noexcept {
|
inline bool HasSecondaryEffect() const noexcept {
|
||||||
return _effect != nullptr && !_effect->GetEffectName().Empty();
|
return _effect != nullptr && !_effect->GetEffectName().Empty();
|
||||||
}
|
}
|
||||||
inline const SecondaryEffect* GetSecondaryEffect() const noexcept { return _effect; }
|
inline const std::unique_ptr<const SecondaryEffect>& GetSecondaryEffect() const noexcept { return _effect; }
|
||||||
|
|
||||||
bool HasFlag(const ConstString& key) const noexcept;
|
bool HasFlag(const ConstString& key) const noexcept;
|
||||||
bool HasFlag(uint32_t keyHash) const noexcept;
|
bool HasFlag(uint32_t keyHash) const noexcept;
|
||||||
|
|
Loading…
Reference in New Issue