Turn SecondaryEffect class into pointer type, owned by AttackData.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-04-10 22:17:48 +02:00
parent beb50a60b0
commit 5ac2b7b3c9
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
8 changed files with 28 additions and 24 deletions

View File

@ -19,7 +19,7 @@ export uint8_t CreatureLib_AttackData_Construct(AttackData*& out, const char* na
} }
auto effect = auto effect =
SecondaryEffect(effectChance, Arbutils::CaseInsensitiveConstString(effectName), effectParameterList); new SecondaryEffect(effectChance, Arbutils::CaseInsensitiveConstString(effectName), effectParameterList);
out = new AttackData(ConstString(name), type, category, power, accuracy, baseUsage, target, priority, effect, out = new AttackData(ConstString(name), type, category, power, accuracy, baseUsage, target, priority, effect,
conversedFlags); conversedFlags);
@ -43,11 +43,11 @@ SIMPLE_GET_FUNC(AttackData, GetPriority, int8_t);
export bool CreatureLib_AttackData_HasSecondaryEffect(const AttackData* p) { return p->HasSecondaryEffect(); } export bool CreatureLib_AttackData_HasSecondaryEffect(const AttackData* p) { return p->HasSecondaryEffect(); }
export float CreatureLib_AttackData_GetSecondaryEffectChance(const AttackData* p) { export float CreatureLib_AttackData_GetSecondaryEffectChance(const AttackData* p) {
return p->GetSecondaryEffect().GetChance(); return p->GetSecondaryEffect()->GetChance();
} }
export const char* CreatureLib_AttackData_GetSecondaryEffectName(const AttackData* p) { export const char* CreatureLib_AttackData_GetSecondaryEffectName(const AttackData* p) {
return p->GetSecondaryEffect().GetEffectName().c_str(); return p->GetSecondaryEffect()->GetEffectName().c_str();
} }
export bool CreatureLib_AttackData_HasFlag(const AttackData* p, const char* key) { export bool CreatureLib_AttackData_HasFlag(const AttackData* p, const char* key) {

View File

@ -172,11 +172,11 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature* targe
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;
} else { } else {
hasSecondaryEffect = hasSecondaryEffect =
user->GetBattle()->GetRandom()->EffectChance(effect.GetChance(), attack, target); user->GetBattle()->GetRandom()->EffectChance(effect->GetChance(), attack, target);
} }
if (hasSecondaryEffect) { if (hasSecondaryEffect) {
HOOK(OnSecondaryEffect, userSource, attack, target, hitIndex); HOOK(OnSecondaryEffect, userSource, attack, target, hitIndex);

View File

@ -17,7 +17,7 @@ static CreatureLib::Library::AttackData* GetReplacementAttackData() {
if (_replacementAttackData == nullptr) { if (_replacementAttackData == nullptr) {
_replacementAttackData = new CreatureLib::Library::AttackData( _replacementAttackData = new CreatureLib::Library::AttackData(
"replacement"_cnc, 0, CreatureLib::Library::AttackCategory::Physical, 30, 255, 255, "replacement"_cnc, 0, CreatureLib::Library::AttackCategory::Physical, 30, 255, 255,
CreatureLib::Library::AttackTarget::Any, 0, CreatureLib::Library::SecondaryEffect(), {}); CreatureLib::Library::AttackTarget::Any, 0, new CreatureLib::Library::SecondaryEffect(), {});
} }
return _replacementAttackData; return _replacementAttackData;
} }

View File

@ -23,10 +23,10 @@ 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());
} }
} }
} }

View File

@ -5,7 +5,7 @@ CreatureLib::Library::AttackData::AttackData(const ConstString& name, uint8_t ty
CreatureLib::Library::AttackCategory category, uint8_t power, CreatureLib::Library::AttackCategory category, uint8_t power,
uint8_t accuracy, uint8_t baseUsage, uint8_t accuracy, uint8_t baseUsage,
CreatureLib::Library::AttackTarget target, int8_t priority, CreatureLib::Library::AttackTarget target, int8_t priority,
SecondaryEffect effect, std::unordered_set<uint32_t> flags) const SecondaryEffect* effect, std::unordered_set<uint32_t> flags)
: _name(std::move(name)), _type(type), _category(category), _basePower(power), _accuracy(accuracy), : _name(std::move(name)), _type(type), _category(category), _basePower(power), _accuracy(accuracy),
_baseUsages(baseUsage), _target(target), _priority(priority), _effect(effect), _flags(std::move(flags)) {} _baseUsages(baseUsage), _target(target), _priority(priority), _effect(effect), _flags(std::move(flags)) {}

View File

@ -21,14 +21,14 @@ namespace CreatureLib::Library {
uint8_t _baseUsages; uint8_t _baseUsages;
AttackTarget _target; AttackTarget _target;
int8_t _priority; int8_t _priority;
SecondaryEffect _effect; const SecondaryEffect* _effect;
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, 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() = default; virtual ~AttackData() { delete _effect; };
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; }
@ -39,9 +39,9 @@ namespace CreatureLib::Library {
inline AttackTarget GetTarget() const noexcept { return _target; } inline AttackTarget GetTarget() const noexcept { return _target; }
inline int8_t GetPriority() const noexcept { return _priority; } inline int8_t GetPriority() const noexcept { return _priority; }
inline bool HasSecondaryEffect() const noexcept { inline bool HasSecondaryEffect() const noexcept {
return _effect.GetChance() != 0 && _effect.GetEffectName() != ""_cnc; return _effect->GetChance() != 0 && _effect->GetEffectName() != ""_cnc;
} }
inline const SecondaryEffect& GetSecondaryEffect() const noexcept { return _effect; } inline 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;

View File

@ -26,9 +26,11 @@ namespace CreatureLib::Library {
} }
} }
constexpr float GetChance() const noexcept { return _chance; } constexpr inline float GetChance() const noexcept { return _chance; }
constexpr const Arbutils::CaseInsensitiveConstString& GetEffectName() const noexcept { return _effectName; } constexpr inline const Arbutils::CaseInsensitiveConstString& GetEffectName() const noexcept {
const List<EffectParameter*>& GetParameters() const noexcept { return _parameters; } return _effectName;
}
const inline List<EffectParameter*>& GetParameters() const noexcept { return _parameters; }
}; };
} }

View File

@ -33,14 +33,16 @@ SpeciesLibrary* TestLibrary::BuildSpeciesLibrary() {
AttackLibrary* TestLibrary::BuildAttackLibrary() { AttackLibrary* TestLibrary::BuildAttackLibrary() {
auto l = new AttackLibrary(); auto l = new AttackLibrary();
l->Insert("standard"_cnc.GetHash(), new AttackData("standard"_cnc, 0, AttackCategory::Physical, 20, 100, 30, l->Insert("standard"_cnc.GetHash(), new AttackData("standard"_cnc, 0, AttackCategory::Physical, 20, 100, 30,
AttackTarget::AdjacentOpponent, 0, SecondaryEffect(), {})); AttackTarget::AdjacentOpponent, 0, new SecondaryEffect(), {}));
l->Insert("highPriority"_cnc.GetHash(), new AttackData("highPriority"_cnc, 0, AttackCategory::Physical, 20, 100, 30, l->Insert("highPriority"_cnc.GetHash(),
AttackTarget::AdjacentOpponent, 1, SecondaryEffect(), {})); new AttackData("highPriority"_cnc, 0, AttackCategory::Physical, 20, 100, 30,
AttackTarget::AdjacentOpponent, 1, new SecondaryEffect(), {}));
l->Insert("higherPriority"_cnc.GetHash(), l->Insert("higherPriority"_cnc.GetHash(),
new AttackData("higherPriority"_cnc, 0, AttackCategory::Physical, 20, 100, 30, new AttackData("higherPriority"_cnc, 0, AttackCategory::Physical, 20, 100, 30,
AttackTarget::AdjacentOpponent, 2, SecondaryEffect(), {})); AttackTarget::AdjacentOpponent, 2, new SecondaryEffect(), {}));
l->Insert("lowPriority"_cnc.GetHash(), new AttackData("lowPriority"_cnc, 0, AttackCategory::Physical, 20, 100, 30, l->Insert("lowPriority"_cnc.GetHash(),
AttackTarget::AdjacentOpponent, -1, SecondaryEffect(), {})); new AttackData("lowPriority"_cnc, 0, AttackCategory::Physical, 20, 100, 30,
AttackTarget::AdjacentOpponent, -1, new SecondaryEffect(), {}));
return l; return l;
} }