Fix a few things with auras

This commit is contained in:
Michael Cook (mackal) 2017-07-17 19:35:00 -04:00
parent accc8aee57
commit f917a38e1a
2 changed files with 28 additions and 23 deletions

View File

@ -683,6 +683,7 @@ void Mob::AddAura(Aura *aura, AuraRecord &record)
assert(aura != nullptr); assert(aura != nullptr);
strn0cpy(aura_mgr.auras[aura_mgr.count].name, aura->GetCleanName(), 64); strn0cpy(aura_mgr.auras[aura_mgr.count].name, aura->GetCleanName(), 64);
aura_mgr.auras[aura_mgr.count].spawn_id = aura->GetID(); aura_mgr.auras[aura_mgr.count].spawn_id = aura->GetID();
aura_mgr.auras[aura_mgr.count].aura = aura;
if (record.icon == -1) if (record.icon == -1)
aura_mgr.auras[aura_mgr.count].icon = spells[record.spell_id].new_icon; aura_mgr.auras[aura_mgr.count].icon = spells[record.spell_id].new_icon;
else else
@ -707,6 +708,7 @@ void Mob::AddTrap(Aura *aura, AuraRecord &record)
assert(aura != nullptr); assert(aura != nullptr);
strn0cpy(trap_mgr.auras[trap_mgr.count].name, aura->GetCleanName(), 64); strn0cpy(trap_mgr.auras[trap_mgr.count].name, aura->GetCleanName(), 64);
trap_mgr.auras[trap_mgr.count].spawn_id = aura->GetID(); trap_mgr.auras[trap_mgr.count].spawn_id = aura->GetID();
trap_mgr.auras[trap_mgr.count].aura = aura;
if (record.icon == -1) if (record.icon == -1)
trap_mgr.auras[trap_mgr.count].icon = spells[record.spell_id].new_icon; trap_mgr.auras[trap_mgr.count].icon = spells[record.spell_id].new_icon;
else else
@ -733,17 +735,15 @@ void Mob::RemoveAllAuras()
// this is sent on camp/zone, so it just despawns? // this is sent on camp/zone, so it just despawns?
if (aura_mgr.count) { if (aura_mgr.count) {
for (auto &e : aura_mgr.auras) { for (auto &e : aura_mgr.auras) {
auto mob = entity_list.GetMob(e.spawn_id); if (e.aura)
if (mob) e.aura->Depop();
mob->Depop();
} }
} }
if (trap_mgr.count) { if (trap_mgr.count) {
for (auto &e : trap_mgr.auras) { for (auto &e : trap_mgr.auras) {
auto mob = entity_list.GetMob(e.spawn_id); if (e.aura)
if (mob) e.aura->Depop();
mob->Depop();
} }
} }
return; return;
@ -754,9 +754,8 @@ void Mob::RemoveAura(int spawn_id, bool expired)
for (int i = 0; i < aura_mgr.count; ++i) { for (int i = 0; i < aura_mgr.count; ++i) {
auto &aura = aura_mgr.auras[i]; auto &aura = aura_mgr.auras[i];
if (aura.spawn_id == spawn_id) { if (aura.spawn_id == spawn_id) {
auto mob = entity_list.GetMob(aura.spawn_id); if (aura.aura)
if (mob) aura.aura->Depop();
mob->Depop();
if (expired && IsClient()) if (expired && IsClient())
CastToClient()->SendColoredText( CastToClient()->SendColoredText(
CC_Yellow, StringFormat("%s has expired.", aura.name)); // TODO: verify color CC_Yellow, StringFormat("%s has expired.", aura.name)); // TODO: verify color
@ -764,6 +763,8 @@ void Mob::RemoveAura(int spawn_id, bool expired)
i++; i++;
aura.spawn_id = aura_mgr.auras[i].spawn_id; aura.spawn_id = aura_mgr.auras[i].spawn_id;
aura.icon = aura_mgr.auras[i].icon; aura.icon = aura_mgr.auras[i].icon;
aura.aura = aura_mgr.auras[i].aura;
aura_mgr.auras[i].aura = nullptr;
strn0cpy(aura.name, aura_mgr.auras[i].name, 64); strn0cpy(aura.name, aura_mgr.auras[i].name, 64);
} }
aura_mgr.count--; aura_mgr.count--;
@ -773,9 +774,9 @@ void Mob::RemoveAura(int spawn_id, bool expired)
for (int i = 0; i < trap_mgr.count; ++i) { for (int i = 0; i < trap_mgr.count; ++i) {
auto &aura = trap_mgr.auras[i]; auto &aura = trap_mgr.auras[i];
auto mob = entity_list.GetMob(aura.spawn_id); if (aura.spawn_id == spawn_id) {
if (mob) if (aura.aura)
mob->Depop(); aura.aura->Depop();
if (expired && IsClient()) if (expired && IsClient())
CastToClient()->SendColoredText( CastToClient()->SendColoredText(
CC_Yellow, StringFormat("%s has expired.", aura.name)); // TODO: verify color CC_Yellow, StringFormat("%s has expired.", aura.name)); // TODO: verify color
@ -783,11 +784,14 @@ void Mob::RemoveAura(int spawn_id, bool expired)
i++; i++;
aura.spawn_id = trap_mgr.auras[i].spawn_id; aura.spawn_id = trap_mgr.auras[i].spawn_id;
aura.icon = trap_mgr.auras[i].icon; aura.icon = trap_mgr.auras[i].icon;
aura.aura = trap_mgr.auras[i].aura;
trap_mgr.auras[i].aura = nullptr;
strn0cpy(aura.name, trap_mgr.auras[i].name, 64); strn0cpy(aura.name, trap_mgr.auras[i].name, 64);
} }
trap_mgr.count--; trap_mgr.count--;
return; return;
} }
}
return; return;
} }

View File

@ -91,7 +91,8 @@ public:
char name[64]; char name[64];
int spawn_id; int spawn_id;
int icon; int icon;
AuraInfo() : spawn_id(0), icon(0) Aura *aura;
AuraInfo() : spawn_id(0), icon(0), aura(nullptr)
{ {
memset(name, 0, 64); memset(name, 0, 64);
} }