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

This commit is contained in:
Deukhoofd 2019-11-09 13:18:45 +01:00
parent 96d1b6251f
commit f72fd5f905
4 changed files with 25 additions and 22 deletions

View File

@ -58,7 +58,7 @@ void TurnHandler::ExecuteAttackChoice(const AttackTurnChoice *choice) {
//HOOK: Prevent attack
auto attack = ExecutingAttack();
auto attack = new ExecutingAttack();
//HOOK: override targets
@ -72,40 +72,43 @@ void TurnHandler::ExecuteAttackChoice(const AttackTurnChoice *choice) {
//HOOK: On Before Attack
for (auto kv: attack.GetTargets()){
for (auto& kv: attack->GetTargets()){
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) {
auto user = attack.GetUser();
void TurnHandler::HandleAttackForTarget(ExecutingAttack* attack, Creature *target, const ExecutingAttack::TargetData &targetData) {
auto user = attack->GetUser();
std::array<ScriptSource*, 1> targetSources = {target};
std::array<ScriptSource*, 1> userSources = {user};
bool fail = false;
HOOK(FailIncomingAttack, targetSources, &attack, target, fail);
HOOK(FailIncomingAttack, targetSources, attack, target, fail);
if (fail){
//TODO: Fail handling.
return;
}
bool invulnerable = fail;
HOOK(IsInvulnerable, targetSources, &attack, target, invulnerable);
HOOK(IsInvulnerable, targetSources, attack, target, invulnerable);
if (invulnerable){
//TODO: We should probably do something when a target is invulnerable.
return;
}
if (!targetData.IsHit()){
HOOK(OnAttackMiss, targetSources, &attack, target);
HOOK(OnAttackMiss, targetSources, attack, target);
return;
}
auto numHits = targetData.GetNumberOfHits();
if (numHits == 0)
return;
auto attackData = attack.GetAttack()->GetAttack();
auto attackData = attack->GetAttack()->GetAttack();
auto library = user->GetBattle()->GetLibrary();
auto dmgLibrary = library->GetDamageLibrary();
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 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.SetCritical(library->GetCriticalLibrary()->IsCritical(&attack, target, hitIndex));
hit.SetBasePower(dmgLibrary->GetBasePower(&attack, target, hitIndex));
hit.SetDamage(dmgLibrary->GetDamage(&attack, target, hitIndex));
hit.SetCritical(library->GetCriticalLibrary()->IsCritical(attack, target, hitIndex));
hit.SetBasePower(dmgLibrary->GetBasePower(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){
HOOK(OnStatusMove, attackSource, &attack, target, hitIndex);
HOOK(OnStatusMove, attackSource, attack, target, hitIndex);
}
else{
auto damage = hit.GetDamage();
@ -139,15 +142,15 @@ void TurnHandler::HandleAttackForTarget(ExecutingAttack &attack, Creature *targe
target->Damage(damage, DamageSource::AttackDamage);
bool preventSecondary = false;
HOOK(PreventSecondaryEffects, targetSources, &attack, target, hitIndex, preventSecondary);
HOOK(PreventSecondaryEffects, targetSources, attack, target, hitIndex, preventSecondary);
if (!preventSecondary){
HOOK(OnSecondaryEffect, attackSource, &attack, target, hitIndex);
HOOK(OnSecondaryEffect, attackSource, attack, target, hitIndex);
}
}
}
}
if (!user->IsFainted()){
HOOK(OnAfterHits, userSources, &attack, target);
HOOK(OnAfterHits, userSources, attack, target);
}
}

View File

@ -12,7 +12,7 @@ namespace CreatureLib::Battling {
static void ExecuteChoice(const BaseTurnChoice* 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:
static void RunTurn(Battle* battle, ChoiceQueue* queue);
};

View File

@ -43,7 +43,7 @@ namespace CreatureLib::Battling {
}
TargetData()= default;
HitData& GetHit(uint8_t index){
const HitData& GetHit(uint8_t index) const{
return _hits[index];
}
@ -51,11 +51,11 @@ namespace CreatureLib::Battling {
return &_hits[index];
}
uint8_t GetNumberOfHits(){
uint8_t GetNumberOfHits() const{
return _hits.size();
}
bool IsHit(){
bool IsHit() const{
return _isHit;
}

View File

@ -1,7 +1,7 @@
#define HOOK(hookName, sources, ... ) \
{ \
auto aggregator = CreatureLib::Battling::ScriptAggregator(); \
for (auto source: sources){ \
for (auto& source: sources){ \
source -> GetActiveScripts(aggregator); \
} \
while (aggregator.HasNext()){ \