Turn SecondaryEffect class into pointer type, owned by AttackData.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -172,11 +172,11 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature* targe
|
||||
if (!preventSecondary) {
|
||||
auto effect = attackData->GetSecondaryEffect();
|
||||
bool hasSecondaryEffect;
|
||||
if (effect.GetChance() == -1) {
|
||||
if (effect->GetChance() == -1) {
|
||||
hasSecondaryEffect = true;
|
||||
} else {
|
||||
hasSecondaryEffect =
|
||||
user->GetBattle()->GetRandom()->EffectChance(effect.GetChance(), attack, target);
|
||||
user->GetBattle()->GetRandom()->EffectChance(effect->GetChance(), attack, target);
|
||||
}
|
||||
if (hasSecondaryEffect) {
|
||||
HOOK(OnSecondaryEffect, userSource, attack, target, hitIndex);
|
||||
|
||||
@@ -17,7 +17,7 @@ static CreatureLib::Library::AttackData* GetReplacementAttackData() {
|
||||
if (_replacementAttackData == nullptr) {
|
||||
_replacementAttackData = new CreatureLib::Library::AttackData(
|
||||
"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;
|
||||
}
|
||||
|
||||
@@ -23,10 +23,10 @@ namespace CreatureLib::Battling {
|
||||
if (battle != nullptr) {
|
||||
if (_attack->GetAttack()->HasSecondaryEffect()) {
|
||||
auto library = battle->GetLibrary();
|
||||
auto& effect = _attack->GetAttack()->GetSecondaryEffect();
|
||||
_attackScript = library->LoadScript(ScriptCategory::Attack, effect.GetEffectName());
|
||||
auto effect = _attack->GetAttack()->GetSecondaryEffect();
|
||||
_attackScript = library->LoadScript(ScriptCategory::Attack, effect->GetEffectName());
|
||||
if (_attackScript != nullptr) {
|
||||
_attackScript->OnInitialize(effect.GetParameters());
|
||||
_attackScript->OnInitialize(effect->GetParameters());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ CreatureLib::Library::AttackData::AttackData(const ConstString& name, uint8_t ty
|
||||
CreatureLib::Library::AttackCategory category, uint8_t power,
|
||||
uint8_t accuracy, uint8_t baseUsage,
|
||||
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),
|
||||
_baseUsages(baseUsage), _target(target), _priority(priority), _effect(effect), _flags(std::move(flags)) {}
|
||||
|
||||
|
||||
@@ -21,14 +21,14 @@ namespace CreatureLib::Library {
|
||||
uint8_t _baseUsages;
|
||||
AttackTarget _target;
|
||||
int8_t _priority;
|
||||
SecondaryEffect _effect;
|
||||
const SecondaryEffect* _effect;
|
||||
std::unordered_set<uint32_t> _flags;
|
||||
|
||||
public:
|
||||
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);
|
||||
virtual ~AttackData() = default;
|
||||
virtual ~AttackData() { delete _effect; };
|
||||
|
||||
inline const ConstString& GetName() const noexcept { return _name; }
|
||||
inline const uint8_t GetType() const noexcept { return _type; }
|
||||
@@ -39,9 +39,9 @@ namespace CreatureLib::Library {
|
||||
inline AttackTarget GetTarget() const noexcept { return _target; }
|
||||
inline int8_t GetPriority() const noexcept { return _priority; }
|
||||
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(uint32_t keyHash) const noexcept;
|
||||
|
||||
@@ -26,9 +26,11 @@ namespace CreatureLib::Library {
|
||||
}
|
||||
}
|
||||
|
||||
constexpr float GetChance() const noexcept { return _chance; }
|
||||
constexpr const Arbutils::CaseInsensitiveConstString& GetEffectName() const noexcept { return _effectName; }
|
||||
const List<EffectParameter*>& GetParameters() const noexcept { return _parameters; }
|
||||
constexpr inline float GetChance() const noexcept { return _chance; }
|
||||
constexpr inline const Arbutils::CaseInsensitiveConstString& GetEffectName() const noexcept {
|
||||
return _effectName;
|
||||
}
|
||||
const inline List<EffectParameter*>& GetParameters() const noexcept { return _parameters; }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user