Make ExecutingAttack be a pointer, as we probably want to keep it around after it has finished executing.
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
96d1b6251f
commit
f72fd5f905
|
@ -58,7 +58,7 @@ void TurnHandler::ExecuteAttackChoice(const AttackTurnChoice *choice) {
|
||||||
|
|
||||||
//HOOK: Prevent attack
|
//HOOK: Prevent attack
|
||||||
|
|
||||||
auto attack = ExecutingAttack();
|
auto attack = new ExecutingAttack();
|
||||||
|
|
||||||
//HOOK: override targets
|
//HOOK: override targets
|
||||||
|
|
||||||
|
@ -72,40 +72,43 @@ void TurnHandler::ExecuteAttackChoice(const AttackTurnChoice *choice) {
|
||||||
|
|
||||||
//HOOK: On Before Attack
|
//HOOK: On Before Attack
|
||||||
|
|
||||||
for (auto kv: attack.GetTargets()){
|
for (auto& kv: attack->GetTargets()){
|
||||||
HandleAttackForTarget(attack, kv.first, kv.second);
|
HandleAttackForTarget(attack, kv.first, kv.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: We currently delete this, but we probably want to store this in a log, so scripts can look it up.
|
||||||
|
delete attack;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TurnHandler::HandleAttackForTarget(ExecutingAttack &attack, Creature *target, ExecutingAttack::TargetData &targetData) {
|
void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature *target, const ExecutingAttack::TargetData &targetData) {
|
||||||
auto user = attack.GetUser();
|
auto user = attack->GetUser();
|
||||||
|
|
||||||
std::array<ScriptSource*, 1> targetSources = {target};
|
std::array<ScriptSource*, 1> targetSources = {target};
|
||||||
std::array<ScriptSource*, 1> userSources = {user};
|
std::array<ScriptSource*, 1> userSources = {user};
|
||||||
|
|
||||||
bool fail = false;
|
bool fail = false;
|
||||||
HOOK(FailIncomingAttack, targetSources, &attack, target, fail);
|
HOOK(FailIncomingAttack, targetSources, attack, target, fail);
|
||||||
if (fail){
|
if (fail){
|
||||||
//TODO: Fail handling.
|
//TODO: Fail handling.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool invulnerable = fail;
|
bool invulnerable = fail;
|
||||||
HOOK(IsInvulnerable, targetSources, &attack, target, invulnerable);
|
HOOK(IsInvulnerable, targetSources, attack, target, invulnerable);
|
||||||
if (invulnerable){
|
if (invulnerable){
|
||||||
//TODO: We should probably do something when a target is invulnerable.
|
//TODO: We should probably do something when a target is invulnerable.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!targetData.IsHit()){
|
if (!targetData.IsHit()){
|
||||||
HOOK(OnAttackMiss, targetSources, &attack, target);
|
HOOK(OnAttackMiss, targetSources, attack, target);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto numHits = targetData.GetNumberOfHits();
|
auto numHits = targetData.GetNumberOfHits();
|
||||||
if (numHits == 0)
|
if (numHits == 0)
|
||||||
return;
|
return;
|
||||||
auto attackData = attack.GetAttack()->GetAttack();
|
auto attackData = attack->GetAttack()->GetAttack();
|
||||||
auto library = user->GetBattle()->GetLibrary();
|
auto library = user->GetBattle()->GetLibrary();
|
||||||
auto dmgLibrary = library->GetDamageLibrary();
|
auto dmgLibrary = library->GetDamageLibrary();
|
||||||
for (uint8_t hitIndex = 0; hitIndex < numHits; hitIndex++){
|
for (uint8_t hitIndex = 0; hitIndex < numHits; hitIndex++){
|
||||||
|
@ -119,15 +122,15 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack &attack, Creature *targe
|
||||||
auto hit = targetData.GetHit(hitIndex);
|
auto hit = targetData.GetHit(hitIndex);
|
||||||
|
|
||||||
auto hitType = hit.GetType();
|
auto hitType = hit.GetType();
|
||||||
HOOK(ChangeAttackType, targetSources, &attack, target, hitIndex, hitType);
|
HOOK(ChangeAttackType, targetSources, attack, target, hitIndex, hitType);
|
||||||
hit.SetEffectiveness(library->GetTypeLibrary()->GetEffectiveness(hitType, target->GetTypes()));
|
hit.SetEffectiveness(library->GetTypeLibrary()->GetEffectiveness(hitType, target->GetTypes()));
|
||||||
hit.SetCritical(library->GetCriticalLibrary()->IsCritical(&attack, target, hitIndex));
|
hit.SetCritical(library->GetCriticalLibrary()->IsCritical(attack, target, hitIndex));
|
||||||
hit.SetBasePower(dmgLibrary->GetBasePower(&attack, target, hitIndex));
|
hit.SetBasePower(dmgLibrary->GetBasePower(attack, target, hitIndex));
|
||||||
hit.SetDamage(dmgLibrary->GetDamage(&attack, target, hitIndex));
|
hit.SetDamage(dmgLibrary->GetDamage(attack, target, hitIndex));
|
||||||
|
|
||||||
std::array<ScriptSource*, 1> attackSource = {&attack};
|
std::array<ScriptSource*, 1> attackSource = {attack};
|
||||||
if (attackData->GetCategory() == Library::AttackCategory::Status){
|
if (attackData->GetCategory() == Library::AttackCategory::Status){
|
||||||
HOOK(OnStatusMove, attackSource, &attack, target, hitIndex);
|
HOOK(OnStatusMove, attackSource, attack, target, hitIndex);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
auto damage = hit.GetDamage();
|
auto damage = hit.GetDamage();
|
||||||
|
@ -139,15 +142,15 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack &attack, Creature *targe
|
||||||
target->Damage(damage, DamageSource::AttackDamage);
|
target->Damage(damage, DamageSource::AttackDamage);
|
||||||
|
|
||||||
bool preventSecondary = false;
|
bool preventSecondary = false;
|
||||||
HOOK(PreventSecondaryEffects, targetSources, &attack, target, hitIndex, preventSecondary);
|
HOOK(PreventSecondaryEffects, targetSources, attack, target, hitIndex, preventSecondary);
|
||||||
if (!preventSecondary){
|
if (!preventSecondary){
|
||||||
HOOK(OnSecondaryEffect, attackSource, &attack, target, hitIndex);
|
HOOK(OnSecondaryEffect, attackSource, attack, target, hitIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!user->IsFainted()){
|
if (!user->IsFainted()){
|
||||||
HOOK(OnAfterHits, userSources, &attack, target);
|
HOOK(OnAfterHits, userSources, attack, target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ namespace CreatureLib::Battling {
|
||||||
static void ExecuteChoice(const BaseTurnChoice* choice);
|
static void ExecuteChoice(const BaseTurnChoice* choice);
|
||||||
|
|
||||||
static void ExecuteAttackChoice(const AttackTurnChoice* choice);
|
static void ExecuteAttackChoice(const AttackTurnChoice* choice);
|
||||||
static void HandleAttackForTarget(ExecutingAttack& attack, Creature* target, ExecutingAttack::TargetData& targetData);
|
static void HandleAttackForTarget(ExecutingAttack* attack, Creature* target, const ExecutingAttack::TargetData& targetData);
|
||||||
public:
|
public:
|
||||||
static void RunTurn(Battle* battle, ChoiceQueue* queue);
|
static void RunTurn(Battle* battle, ChoiceQueue* queue);
|
||||||
};
|
};
|
||||||
|
|
|
@ -43,7 +43,7 @@ namespace CreatureLib::Battling {
|
||||||
}
|
}
|
||||||
TargetData()= default;
|
TargetData()= default;
|
||||||
|
|
||||||
HitData& GetHit(uint8_t index){
|
const HitData& GetHit(uint8_t index) const{
|
||||||
return _hits[index];
|
return _hits[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,11 +51,11 @@ namespace CreatureLib::Battling {
|
||||||
return &_hits[index];
|
return &_hits[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t GetNumberOfHits(){
|
uint8_t GetNumberOfHits() const{
|
||||||
return _hits.size();
|
return _hits.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsHit(){
|
bool IsHit() const{
|
||||||
return _isHit;
|
return _isHit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#define HOOK(hookName, sources, ... ) \
|
#define HOOK(hookName, sources, ... ) \
|
||||||
{ \
|
{ \
|
||||||
auto aggregator = CreatureLib::Battling::ScriptAggregator(); \
|
auto aggregator = CreatureLib::Battling::ScriptAggregator(); \
|
||||||
for (auto source: sources){ \
|
for (auto& source: sources){ \
|
||||||
source -> GetActiveScripts(aggregator); \
|
source -> GetActiveScripts(aggregator); \
|
||||||
} \
|
} \
|
||||||
while (aggregator.HasNext()){ \
|
while (aggregator.HasNext()){ \
|
||||||
|
|
Loading…
Reference in New Issue