Reworks attack scripts to handle effect chance and effect name through data files.
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:
@@ -154,7 +154,9 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature* targe
|
||||
hit->SetDamage(dmgLibrary->GetDamage(attack, target, hitIndex));
|
||||
|
||||
if (attackData->GetCategory() == Library::AttackCategory::Status) {
|
||||
HOOK(OnStatusMove, userSource, attack, target, hitIndex);
|
||||
if (attackData->HasSecondaryEffect()) {
|
||||
HOOK(OnStatusMove, userSource, attack, target, hitIndex);
|
||||
}
|
||||
} else {
|
||||
auto damage = hit->GetDamage();
|
||||
if (damage > target->GetCurrentHealth()) {
|
||||
@@ -164,10 +166,22 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature* targe
|
||||
if (damage > 0) {
|
||||
target->Damage(damage, DamageSource::AttackDamage);
|
||||
|
||||
bool preventSecondary = false;
|
||||
HOOK(PreventSecondaryEffects, targetSource, attack, target, hitIndex, &preventSecondary);
|
||||
if (!preventSecondary) {
|
||||
HOOK(OnSecondaryEffect, userSource, attack, target, hitIndex);
|
||||
if (attackData->HasSecondaryEffect()) {
|
||||
bool preventSecondary = false;
|
||||
HOOK(PreventSecondaryEffects, targetSource, attack, target, hitIndex, &preventSecondary);
|
||||
if (!preventSecondary) {
|
||||
auto effect = attackData->GetSecondaryEffect();
|
||||
bool hasSecondaryEffect;
|
||||
if (effect.GetChance() == -1) {
|
||||
hasSecondaryEffect = true;
|
||||
} else {
|
||||
hasSecondaryEffect =
|
||||
user->GetBattle()->GetRandom()->EffectChance(effect.GetChance(), attack, target);
|
||||
}
|
||||
if (hasSecondaryEffect) {
|
||||
HOOK(OnSecondaryEffect, userSource, attack, target, hitIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,9 +15,9 @@ static CreatureLib::Library::AttackData* _replacementAttackData = nullptr;
|
||||
|
||||
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, {});
|
||||
_replacementAttackData = new CreatureLib::Library::AttackData(
|
||||
"replacement"_cnc, 0, CreatureLib::Library::AttackCategory::Physical, 30, 255, 255,
|
||||
CreatureLib::Library::AttackTarget::Any, 0, CreatureLib::Library::SecondaryEffect(), {});
|
||||
}
|
||||
return _replacementAttackData;
|
||||
}
|
||||
|
||||
@@ -21,8 +21,11 @@ namespace CreatureLib::Battling {
|
||||
return;
|
||||
auto battle = user->GetBattle();
|
||||
if (battle != nullptr) {
|
||||
auto library = battle->GetLibrary();
|
||||
_attackScript = library->LoadScript(ScriptCategory::Attack, _attack->GetAttack()->GetName());
|
||||
if (_attack->GetAttack()->HasSecondaryEffect()) {
|
||||
auto library = battle->GetLibrary();
|
||||
_attackScript = library->LoadScript(ScriptCategory::Attack,
|
||||
_attack->GetAttack()->GetSecondaryEffect().GetEffectName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user