Got AI Event system working

This commit is contained in:
2024-10-12 19:53:28 -04:00
parent 73c2b8923b
commit a4d7b00036
6 changed files with 61 additions and 19 deletions

View File

@@ -44,15 +44,18 @@ public:
if(irand == 0) {
creature->AddAura(23341, creature);
creature->SetName("Infernal " + creature->GetName());
creature->SetName("Infernal " + creature->GetName());
} else if(irand == 1) {
creature->AddAura(34711, creature);
creature->SetName("Berserking " + creature->GetName());
creature->SetName("Berserking " + creature->GetName());
} else {
creature->AddAura(774, creature);
creature->SetName("Blessed " + creature->GetName());
creature->SetName("Blessed " + creature->GetName());
}
}
creature->SetAI(new MpScriptAI(creature));
MpLogger::debug("Creature AI debug info: {}", creature->GetAI()->GetDebugInfo());
}
// Cleanup the creature from custom data used for mythic+ mod
@@ -63,7 +66,16 @@ public:
// CreatureAI* GetCreatureAI(Creature* creature) const override
// {
// ASSERT(creature);
// if(!creature) {
// return nullptr;
// }
// uint32 instance = creature->GetInstanceId();
// if(!instance) {
// return nullptr;
// }
// MpLogger::debug("GetCreatureAI: Instance logger for instanceId {} called on {}", instance, creature->GetGUID().GetCounter());
// // Attach to creatures that are in a mythic+ map
// MpCreatureData* creatureData = sMpDataStore->GetCreatureData(creature->GetGUID());
@@ -71,6 +83,8 @@ public:
// return nullptr;
// }
// MpLogger::debug("GetCreatureAI: called on {}", creature->GetName());
// return new MpScriptAI(creature);
// }

View File

@@ -30,13 +30,24 @@ void CreatureHooks::RegisterOnAddToInstance(uint32 entry, uint32 mapId, uint32 i
// }
void CreatureHooks::JustDied(Creature* creature, Unit* killer) {
uint32 entry = creature->GetEntry();
if(!creature) {
MpLogger::debug("JustDied() called with nullptr for creature");
return;
}
if(!killer) {
MpLogger::debug("JustDied() called with nullptr for killer");
return;
}
uint32 entry = creature->GetEntry();
if (_JustDiedHandlers->contains(entry)) {
for (auto& callback : _JustDiedHandlers->at(entry)) {
callback(creature, killer);
}
}
MpLogger::debug("JustDied() called for creature: {}", entry);
}
void CreatureHooks::JustSpawned(Creature* creature) {

View File

@@ -38,8 +38,23 @@ using CreatureEventStateMap = std::map<ObjectGuid, CreatureEventState>;
class CreatureHooks {
private:
CreatureHooks() { }
~CreatureHooks() { }
CreatureHooks():
_OnSpawnHandlers(std::make_unique<HandlerMap<Creature*>>()),
_JustDiedHandlers(std::make_unique<HandlerMap<Creature*, Unit*>>()),
_OnAddToInstanceHandlers(std::make_unique<HandlerMap<Creature*>>()),
_eventStates(std::make_unique<CreatureEventStateMap>())
{
_OnSpawnHandlers->reserve(128);
_JustDiedHandlers->reserve(128);
_OnAddToInstanceHandlers->reserve(100);
}
~CreatureHooks() {
_OnSpawnHandlers->clear();
_JustDiedHandlers->clear();
_OnAddToInstanceHandlers->clear();
_eventStates->clear();
}
// ensure we only ever have one instance of this class
CreatureHooks(const CreatureHooks&) = delete;
@@ -56,6 +71,7 @@ private:
public:
static CreatureHooks* instance() {
static CreatureHooks instance;
return &instance;
}

View File

@@ -1,6 +1,7 @@
#include "Creature.h"
#include "CreatureAI.h"
#include "CreatureHooks.h"
#include "MpLogger.h"
#include "ScriptMgr.h"
#include "ScriptedCreature.h"
@@ -13,16 +14,22 @@
class MpScriptAI : public BaseAI
{
Difficulty _difficulty;
public:
MpScriptAI(Creature* creature) : BaseAI(creature) {}
MpScriptAI(Creature* creature, Difficulty difficulty) : BaseAI(creature) {
_difficulty = difficulty;
}
void JustDied(Unit* killer) override {
sCreatureHooks->JustDied(me, killer);
MpLogger::debug("***** MythicPlus Script AI JustDied() for creature: ", me->GetEntry());
sCreatureHooks->JustDied(me->ToCreature(), killer);
BaseAI::JustDied(killer);
}
void Reset() override {
MpLogger::debug("***** MythicPlus Script AI Reset() for creature: ", me->GetEntry());
BaseAI::Reset();
}

View File

@@ -84,7 +84,6 @@ bool MythicPlus::EligibleDamageTarget(Unit* target)
}
if (target->GetTypeId() == TYPEID_PLAYER) {
MpLogger::debug("Target {} is a player", target->GetName());
return true;
}
@@ -222,12 +221,6 @@ void MythicPlus::ScaleCreature(uint8 level, Creature* creature, MpMultipliers* m
uint32 basehp = stats->BaseHealth[EXPANSION_WRATH_OF_THE_LICH_KING];
uint32 health = CalculateNewHealth(cInfo, mapId, difficulty, basehp, multipliers->health);
MpLogger::debug("Creature {} base health scaled from {} to {}",
creature->GetName(),
basehp,
health
);
creature->SetCreateHealth(health);
creature->SetMaxHealth(health);
creature->SetHealth(health);
@@ -394,7 +387,7 @@ int32 MythicPlus::ScaleDamageSpell(SpellInfo const * spellInfo, uint32 damage, M
float scalingFactor = 1 + (std::log2(levelDifference + 1) * (float(spellBonus) / 10.0f));
// float scalingFactor = pow(float((creature->GetLevel() - originalLevel) / 10.0f ), float(spellBonus) / 5.0f);
MpLogger::debug("Creature {} original level: {} New Level{} and Scaling level {}", creature->GetName(), originalLevel, creature->GetLevel(), scalingFactor);
// MpLogger::debug("Creature {} original level: {} New Level{} and Scaling level {}", creature->GetName(), originalLevel, creature->GetLevel(), scalingFactor);
int32 totalDamage = 0;
auto effects = spellInfo->GetEffects();
@@ -446,7 +439,7 @@ int32 MythicPlus::ScaleDamageSpell(SpellInfo const * spellInfo, uint32 damage, M
// Apply scaling factor and the set multiplier from the instance data
totalDamage = int32(totalDamage * scalingFactor * damageMultiplier);
MpLogger::debug("Spell {} damage scaled from for spell New Damage: {} using: scaling Factor: {} and damage Multi: {}",spellInfo->SpellName[0], totalDamage, scalingFactor, damageMultiplier);
// MpLogger::debug("Spell {} damage scaled from for spell New Damage: {} using: scaling Factor: {} and damage Multi: {}",spellInfo->SpellName[0], totalDamage, scalingFactor, damageMultiplier);
return totalDamage;
}
@@ -485,7 +478,7 @@ int32 MythicPlus::ScaleHealSpell(SpellInfo const * spellInfo, MpCreatureData* cr
}
// Apply scaling factor and the set multiplier from the instance data
MpLogger::debug("Spell healing scaled from for spell New Damage: {}", totalHeal);
// MpLogger::debug("Spell healing scaled from for spell New Damage: {}", totalHeal);
return pow((totalHeal / originalHp) * currentHealth, 0.8f) * healMultiplier;
}

View File

@@ -56,6 +56,7 @@ public:
uint32 legendaryItemOffset;
uint32 ascendantItemOffset;
// Scaling modifiers
uint32 meleeAttackPowerDampener;
uint32 meleeAttackPowerStart;