Auras now zone

This commit is contained in:
Michael Cook (mackal) 2017-07-18 17:52:39 -04:00
parent f917a38e1a
commit fe8c55ac63
8 changed files with 69 additions and 1 deletions

View File

@ -12,3 +12,11 @@ CREATE TABLE `auras` (
`cast_time` INT(10) NOT NULL DEFAULT 0, `cast_time` INT(10) NOT NULL DEFAULT 0,
PRIMARY KEY(`type`) PRIMARY KEY(`type`)
) )
CREATE TABLE `character_auras` (
`id` INT(10) NOT NULL,
`slot` TINYINT(10) NOT NULL,
`spell_id` INT(10) NOT NULL,
PRIMARY KEY (`id`, `slot`)
);

View File

@ -7,7 +7,7 @@
Aura::Aura(NPCType *type_data, Mob *owner, AuraRecord &record) Aura::Aura(NPCType *type_data, Mob *owner, AuraRecord &record)
: NPC(type_data, 0, owner->GetPosition(), FlyMode3), spell_id(record.spell_id), distance(record.distance), : NPC(type_data, 0, owner->GetPosition(), FlyMode3), spell_id(record.spell_id), distance(record.distance),
remove_timer(record.duration), movement_timer(100), process_timer(100) remove_timer(record.duration), movement_timer(100), process_timer(100), aura_id(-1)
{ {
GiveNPCTypeData(type_data); // we will delete this later on GiveNPCTypeData(type_data); // we will delete this later on
m_owner = owner->GetID(); m_owner = owner->GetID();
@ -584,6 +584,7 @@ void Aura::Depop(bool unused)
p_depop = true; p_depop = true;
} }
// This creates an aura from a casted spell
void Mob::MakeAura(uint16 spell_id) void Mob::MakeAura(uint16 spell_id)
{ {
// TODO: verify room in AuraMgr // TODO: verify room in AuraMgr
@ -639,6 +640,7 @@ void Mob::MakeAura(uint16 spell_id)
strn0cpy(npc_type->name, record.name, 64); strn0cpy(npc_type->name, record.name, 64);
auto npc = new Aura(npc_type, this, record); auto npc = new Aura(npc_type, this, record);
npc->SetAuraID(spell_id);
entity_list.AddNPC(npc, true, true); entity_list.AddNPC(npc, true, true);
if (trap) if (trap)
@ -732,6 +734,13 @@ bool Mob::CanSpawnAura(bool trap)
void Mob::RemoveAllAuras() void Mob::RemoveAllAuras()
{ {
if (IsClient()) {
database.SaveAuras(CastToClient());
EQApplicationPacket outapp(OP_UpdateAura, 4);
outapp.WriteUInt32(2);
CastToClient()->QueuePacket(&outapp);
}
// 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) {
@ -740,12 +749,17 @@ void Mob::RemoveAllAuras()
} }
} }
aura_mgr.count = 0;
if (trap_mgr.count) { if (trap_mgr.count) {
for (auto &e : trap_mgr.auras) { for (auto &e : trap_mgr.auras) {
if (e.aura) if (e.aura)
e.aura->Depop(); e.aura->Depop();
} }
} }
trap_mgr.count = 0;
return; return;
} }

View File

@ -57,8 +57,14 @@ public:
void ProcessEnterTrap(Mob *owner); void ProcessEnterTrap(Mob *owner);
void ProcessExitTrap(Mob *owner); void ProcessExitTrap(Mob *owner);
// we only save auras that follow you, and player casted
inline bool AuraZones() { return movement_type == AuraMovement::Follow && aura_id > -1; }
inline int GetSpellID() { return spell_id; }
inline int GetAuraID() { return aura_id; }
inline void SetAuraID(int in) { aura_id = in; }
private: private:
int m_owner; int m_owner;
int aura_id; // spell ID of the aura spell -1 if aura isn't from a casted spell
int spell_id; // spell we cast int spell_id; // spell we cast
int distance; // distance we remove int distance; // distance we remove
Timer remove_timer; // when we depop Timer remove_timer; // when we depop

View File

@ -883,6 +883,8 @@ void Client::CompleteConnect()
SetPetCommandState(PET_BUTTON_SPELLHOLD, 0); SetPetCommandState(PET_BUTTON_SPELLHOLD, 0);
} }
database.LoadAuras(this); // this ends up spawning them so probably safer to load this later (here)
entity_list.RefreshClientXTargets(this); entity_list.RefreshClientXTargets(this);
worldserver.RequestTellQueue(GetName()); worldserver.RequestTellQueue(GetName());

View File

@ -723,6 +723,8 @@ void Client::OnDisconnect(bool hard_disconnect) {
} }
} }
RemoveAllAuras();
Mob *Other = trade->With(); Mob *Other = trade->With();
if(Other) if(Other)
{ {

View File

@ -625,6 +625,7 @@ public:
bool PlotPositionAroundTarget(Mob* target, float &x_dest, float &y_dest, float &z_dest, bool PlotPositionAroundTarget(Mob* target, float &x_dest, float &y_dest, float &z_dest,
bool lookForAftArc = true); bool lookForAftArc = true);
// aura functions
void MakeAura(uint16 spell_id); void MakeAura(uint16 spell_id);
inline int GetAuraSlots() { return 1 + aabonuses.aura_slots + itembonuses.aura_slots + spellbonuses.aura_slots; } inline int GetAuraSlots() { return 1 + aabonuses.aura_slots + itembonuses.aura_slots + spellbonuses.aura_slots; }
inline int GetTrapSlots() { return 1 + aabonuses.trap_slots + itembonuses.trap_slots + spellbonuses.trap_slots; } inline int GetTrapSlots() { return 1 + aabonuses.trap_slots + itembonuses.trap_slots + spellbonuses.trap_slots; }
@ -635,6 +636,7 @@ public:
bool CanSpawnAura(bool trap); bool CanSpawnAura(bool trap);
void RemoveAura(int spawn_id, bool expired = false); void RemoveAura(int spawn_id, bool expired = false);
void RemoveAllAuras(); void RemoveAllAuras();
inline AuraMgr &GetAuraMgr() { return aura_mgr; } // mainly used for zone db loading/saving
//Procs //Procs
void TriggerDefensiveProcs(Mob *on, uint16 hand = EQEmu::inventory::slotPrimary, bool FromSkillProc = false, int damage = 0); void TriggerDefensiveProcs(Mob *on, uint16 hand = EQEmu::inventory::slotPrimary, bool FromSkillProc = false, int damage = 0);

View File

@ -11,6 +11,7 @@
#include "merc.h" #include "merc.h"
#include "zone.h" #include "zone.h"
#include "zonedb.h" #include "zonedb.h"
#include "aura.h"
#include <ctime> #include <ctime>
#include <iostream> #include <iostream>
@ -3148,6 +3149,37 @@ void ZoneDatabase::LoadBuffs(Client *client)
} }
} }
void ZoneDatabase::SaveAuras(Client *c)
{
auto query = StringFormat("DELETE FROM `character_auras` WHERE `id` = %u", c->CharacterID());
auto results = database.QueryDatabase(query);
if (!results.Success())
return;
const auto &auras = c->GetAuraMgr();
for (int i = 0; i < auras.count; ++i) {
auto aura = auras.auras[i].aura;
if (aura && aura->AuraZones()) {
query = StringFormat("INSERT INTO `character_auras` (id, slot, spell_id) VALUES(%u, %d, %d)",
c->CharacterID(), i, aura->GetAuraID());
auto results = database.QueryDatabase(query);
if (!results.Success())
return;
}
}
}
void ZoneDatabase::LoadAuras(Client *c)
{
auto query = StringFormat("SELECT `spell_id` FROM `character_auras` WHERE `id` = %u ORDER BY `slot`", c->CharacterID());
auto results = database.QueryDatabase(query);
if (!results.Success())
return;
for (auto row = results.begin(); row != results.end(); ++row)
c->MakeAura(atoi(row[0]));
}
void ZoneDatabase::SavePetInfo(Client *client) void ZoneDatabase::SavePetInfo(Client *client)
{ {
PetInfo *petinfo = nullptr; PetInfo *petinfo = nullptr;

View File

@ -273,6 +273,8 @@ public:
void SaveBuffs(Client *c); void SaveBuffs(Client *c);
void LoadBuffs(Client *c); void LoadBuffs(Client *c);
void SaveAuras(Client *c);
void LoadAuras(Client *c);
void LoadPetInfo(Client *c); void LoadPetInfo(Client *c);
void SavePetInfo(Client *c); void SavePetInfo(Client *c);
void RemoveTempFactions(Client *c); void RemoveTempFactions(Client *c);