feat(Core/Creature): Implement c_t_r & c_t_s (#4359)
This commit is contained in:
@@ -38,7 +38,7 @@ void AggressorAI::UpdateAI(uint32 /*diff*/)
|
||||
|
||||
void CombatAI::InitializeAI()
|
||||
{
|
||||
for (uint32 i = 0; i < CREATURE_MAX_SPELLS; ++i)
|
||||
for (uint32 i = 0; i < MAX_CREATURE_SPELLS; ++i)
|
||||
if (me->m_spells[i] && sSpellMgr->GetSpellInfo(me->m_spells[i]))
|
||||
spells.push_back(me->m_spells[i]);
|
||||
|
||||
|
||||
@@ -260,15 +260,15 @@ SpellInfo const* ScriptedAI::SelectSpell(Unit* target, uint32 school, uint32 mec
|
||||
return nullptr;
|
||||
|
||||
//Using the extended script system we first create a list of viable spells
|
||||
SpellInfo const* apSpell[CREATURE_MAX_SPELLS];
|
||||
memset(apSpell, 0, CREATURE_MAX_SPELLS * sizeof(SpellInfo*));
|
||||
SpellInfo const* apSpell[MAX_CREATURE_SPELLS];
|
||||
memset(apSpell, 0, MAX_CREATURE_SPELLS * sizeof(SpellInfo*));
|
||||
|
||||
uint32 spellCount = 0;
|
||||
|
||||
SpellInfo const* tempSpell = nullptr;
|
||||
|
||||
//Check if each spell is viable(set it to null if not)
|
||||
for (uint32 i = 0; i < CREATURE_MAX_SPELLS; i++)
|
||||
for (uint32 i = 0; i < MAX_CREATURE_SPELLS; i++)
|
||||
{
|
||||
tempSpell = sSpellMgr->GetSpellInfo(me->m_spells[i]);
|
||||
|
||||
|
||||
@@ -169,7 +169,7 @@ Creature::Creature(bool isWorldObject): Unit(isWorldObject), MovableMapObject(),
|
||||
m_regenTimer = CREATURE_REGEN_INTERVAL;
|
||||
m_valuesCount = UNIT_END;
|
||||
|
||||
for (uint8 i = 0; i < CREATURE_MAX_SPELLS; ++i)
|
||||
for (uint8 i = 0; i < MAX_CREATURE_SPELLS; ++i)
|
||||
m_spells[i] = 0;
|
||||
|
||||
for (uint8 i = SPELL_SCHOOL_NORMAL; i < MAX_SPELL_SCHOOL; ++i)
|
||||
@@ -390,7 +390,7 @@ bool Creature::InitEntry(uint32 Entry, const CreatureData* data)
|
||||
if (!m_wanderDistance && m_defaultMovementType == RANDOM_MOTION_TYPE)
|
||||
m_defaultMovementType = IDLE_MOTION_TYPE;
|
||||
|
||||
for (uint8 i = 0; i < CREATURE_MAX_SPELLS; ++i)
|
||||
for (uint8 i = 0; i < MAX_CREATURE_SPELLS; ++i)
|
||||
m_spells[i] = GetCreatureTemplate()->spells[i];
|
||||
|
||||
return true;
|
||||
@@ -1868,7 +1868,7 @@ SpellInfo const* Creature::reachWithSpellAttack(Unit* victim)
|
||||
if (!victim)
|
||||
return nullptr;
|
||||
|
||||
for (uint32 i = 0; i < CREATURE_MAX_SPELLS; ++i)
|
||||
for (uint32 i = 0; i < MAX_CREATURE_SPELLS; ++i)
|
||||
{
|
||||
if (!m_spells[i])
|
||||
continue;
|
||||
@@ -1916,7 +1916,7 @@ SpellInfo const* Creature::reachWithSpellCure(Unit* victim)
|
||||
if (!victim)
|
||||
return nullptr;
|
||||
|
||||
for (uint32 i = 0; i < CREATURE_MAX_SPELLS; ++i)
|
||||
for (uint32 i = 0; i < MAX_CREATURE_SPELLS; ++i)
|
||||
{
|
||||
if (!m_spells[i])
|
||||
continue;
|
||||
@@ -2497,10 +2497,10 @@ bool Creature::HasSpellCooldown(uint32 spell_id) const
|
||||
bool Creature::HasSpell(uint32 spellID) const
|
||||
{
|
||||
uint8 i;
|
||||
for (i = 0; i < CREATURE_MAX_SPELLS; ++i)
|
||||
for (i = 0; i < MAX_CREATURE_SPELLS; ++i)
|
||||
if (spellID == m_spells[i])
|
||||
break;
|
||||
return i < CREATURE_MAX_SPELLS; //broke before end of iteration of known spells
|
||||
return i < MAX_CREATURE_SPELLS; //broke before end of iteration of known spells
|
||||
}
|
||||
|
||||
time_t Creature::GetRespawnTimeEx() const
|
||||
|
||||
@@ -120,7 +120,7 @@ struct CreatureTemplate
|
||||
uint32 pickpocketLootId;
|
||||
uint32 SkinLootId;
|
||||
int32 resistance[MAX_SPELL_SCHOOL];
|
||||
uint32 spells[CREATURE_MAX_SPELLS];
|
||||
uint32 spells[MAX_CREATURE_SPELLS];
|
||||
uint32 PetSpellDataId;
|
||||
uint32 VehicleId;
|
||||
uint32 mingold;
|
||||
@@ -613,7 +613,7 @@ public:
|
||||
SpellInfo const* reachWithSpellAttack(Unit* victim);
|
||||
SpellInfo const* reachWithSpellCure(Unit* victim);
|
||||
|
||||
uint32 m_spells[CREATURE_MAX_SPELLS];
|
||||
uint32 m_spells[MAX_CREATURE_SPELLS];
|
||||
CreatureSpellCooldowns m_CreatureSpellCooldowns;
|
||||
uint32 m_ProhibitSchoolTime[7];
|
||||
|
||||
|
||||
@@ -21227,7 +21227,7 @@ void Player::VehicleSpellInitialize()
|
||||
data << uint8(0); // Command State
|
||||
data << uint16(0x800); // DisableActions (set for all vehicles)
|
||||
|
||||
for (uint32 i = 0; i < CREATURE_MAX_SPELLS; ++i)
|
||||
for (uint32 i = 0; i < MAX_CREATURE_SPELLS; ++i)
|
||||
{
|
||||
uint32 spellId = vehicle->m_spells[i];
|
||||
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId);
|
||||
@@ -21253,7 +21253,7 @@ void Player::VehicleSpellInitialize()
|
||||
data << uint32(MAKE_UNIT_ACTION_BUTTON(spellId, i + 8));
|
||||
}
|
||||
|
||||
for (uint32 i = CREATURE_MAX_SPELLS; i < MAX_SPELL_CONTROL_BAR; ++i)
|
||||
for (uint32 i = MAX_CREATURE_SPELLS; i < MAX_SPELL_CONTROL_BAR; ++i)
|
||||
data << uint32(0);
|
||||
|
||||
data << uint8(0); // Auras?
|
||||
|
||||
@@ -15011,7 +15011,7 @@ void CharmInfo::InitPossessCreateSpells()
|
||||
break;
|
||||
}
|
||||
|
||||
for (uint32 i = 0; i < CREATURE_MAX_SPELLS; ++i)
|
||||
for (uint32 i = 0; i < MAX_CREATURE_SPELLS; ++i)
|
||||
{
|
||||
uint32 spellId = _unit->ToCreature()->m_spells[i];
|
||||
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId);
|
||||
|
||||
@@ -246,7 +246,7 @@ enum UnitRename
|
||||
UNIT_CAN_BE_ABANDONED = 0x02,
|
||||
};
|
||||
|
||||
#define CREATURE_MAX_SPELLS 8
|
||||
static constexpr uint32 MAX_CREATURE_SPELLS = 8;
|
||||
#define MAX_SPELL_CHARM 4
|
||||
#define MAX_SPELL_VEHICLE 6
|
||||
#define MAX_SPELL_POSSESS 8
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "SpellMgr.h"
|
||||
#include "SpellScript.h"
|
||||
#include "Transport.h"
|
||||
#include "Unit.h"
|
||||
#include "UpdateMask.h"
|
||||
#include "Util.h"
|
||||
#include "Vehicle.h"
|
||||
@@ -467,11 +468,9 @@ void ObjectMgr::LoadCreatureTemplates()
|
||||
"scale, `rank`, dmgschool, DamageModifier, BaseAttackTime, RangeAttackTime, BaseVariance, RangeVariance, unit_class, unit_flags, unit_flags2, "
|
||||
// 32 33 34 35 36 37 38
|
||||
"dynamicflags, family, trainer_type, trainer_spell, trainer_class, trainer_race, type, "
|
||||
// 39 40 41 42 43 44 45 46 47 48 49
|
||||
"type_flags, lootid, pickpocketloot, skinloot, resistance1, resistance2, resistance3, resistance4, resistance5, resistance6, spell1, "
|
||||
// 50 51 52 53 54 55 56 57 58 59 60 61 62
|
||||
"spell2, spell3, spell4, spell5, spell6, spell7, spell8, PetSpellDataId, VehicleId, mingold, maxgold, AIName, MovementType, "
|
||||
// 63 64 65 66 67 68 69 70 71 72 73 74
|
||||
// 39 40 41 42 43 44 45 46 47 48
|
||||
"type_flags, lootid, pickpocketloot, skinloot, PetSpellDataId, VehicleId, mingold, maxgold, AIName, MovementType, "
|
||||
// 49 50 51 52 53 54 55 56 57 58 59 60
|
||||
"InhabitType, HoverHeight, HealthModifier, ManaModifier, ArmorModifier, RacialLeader, movementId, RegenHealth, mechanic_immune_mask, spell_school_immune_mask, flags_extra, ScriptName "
|
||||
"FROM creature_template;");
|
||||
|
||||
@@ -538,29 +537,29 @@ void ObjectMgr::LoadCreatureTemplates()
|
||||
creatureTemplate.SkinLootId = fields[42].GetUInt32();
|
||||
|
||||
for (uint8 i = SPELL_SCHOOL_HOLY; i < MAX_SPELL_SCHOOL; ++i)
|
||||
creatureTemplate.resistance[i] = fields[43 + i - 1].GetInt16();
|
||||
creatureTemplate.resistance[i] = 0;
|
||||
|
||||
for (uint8 i = 0; i < CREATURE_MAX_SPELLS; ++i)
|
||||
creatureTemplate.spells[i] = fields[49 + i].GetUInt32();
|
||||
for (uint8 i = 0; i < MAX_CREATURE_SPELLS; ++i)
|
||||
creatureTemplate.spells[i] = 0;
|
||||
|
||||
creatureTemplate.PetSpellDataId = fields[57].GetUInt32();
|
||||
creatureTemplate.VehicleId = fields[58].GetUInt32();
|
||||
creatureTemplate.mingold = fields[59].GetUInt32();
|
||||
creatureTemplate.maxgold = fields[60].GetUInt32();
|
||||
creatureTemplate.AIName = fields[61].GetString();
|
||||
creatureTemplate.MovementType = uint32(fields[62].GetUInt8());
|
||||
creatureTemplate.InhabitType = uint32(fields[63].GetUInt8());
|
||||
creatureTemplate.HoverHeight = fields[64].GetFloat();
|
||||
creatureTemplate.ModHealth = fields[65].GetFloat();
|
||||
creatureTemplate.ModMana = fields[66].GetFloat();
|
||||
creatureTemplate.ModArmor = fields[67].GetFloat();
|
||||
creatureTemplate.RacialLeader = fields[68].GetBool();
|
||||
creatureTemplate.movementId = fields[69].GetUInt32();
|
||||
creatureTemplate.RegenHealth = fields[70].GetBool();
|
||||
creatureTemplate.MechanicImmuneMask = fields[71].GetUInt32();
|
||||
creatureTemplate.SpellSchoolImmuneMask = fields[72].GetUInt8();
|
||||
creatureTemplate.flags_extra = fields[73].GetUInt32();
|
||||
creatureTemplate.ScriptID = GetScriptId(fields[74].GetCString());
|
||||
creatureTemplate.PetSpellDataId = fields[43].GetUInt32();
|
||||
creatureTemplate.VehicleId = fields[44].GetUInt32();
|
||||
creatureTemplate.mingold = fields[45].GetUInt32();
|
||||
creatureTemplate.maxgold = fields[46].GetUInt32();
|
||||
creatureTemplate.AIName = fields[47].GetString();
|
||||
creatureTemplate.MovementType = uint32(fields[48].GetUInt8());
|
||||
creatureTemplate.InhabitType = uint32(fields[49].GetUInt8());
|
||||
creatureTemplate.HoverHeight = fields[50].GetFloat();
|
||||
creatureTemplate.ModHealth = fields[51].GetFloat();
|
||||
creatureTemplate.ModMana = fields[52].GetFloat();
|
||||
creatureTemplate.ModArmor = fields[53].GetFloat();
|
||||
creatureTemplate.RacialLeader = fields[54].GetBool();
|
||||
creatureTemplate.movementId = fields[55].GetUInt32();
|
||||
creatureTemplate.RegenHealth = fields[56].GetBool();
|
||||
creatureTemplate.MechanicImmuneMask = fields[57].GetUInt32();
|
||||
creatureTemplate.SpellSchoolImmuneMask = fields[58].GetUInt8();
|
||||
creatureTemplate.flags_extra = fields[59].GetUInt32();
|
||||
creatureTemplate.ScriptID = GetScriptId(fields[60].GetCString());
|
||||
|
||||
++count;
|
||||
} while (result->NextRow());
|
||||
@@ -580,6 +579,9 @@ void ObjectMgr::LoadCreatureTemplates()
|
||||
}
|
||||
}
|
||||
|
||||
LoadCreatureTemplateResistances();
|
||||
LoadCreatureTemplateSpells();
|
||||
|
||||
// Checking needs to be done after loading because of the difficulty self referencing
|
||||
for (CreatureTemplateContainer::iterator itr = _creatureTemplateStore.begin(); itr != _creatureTemplateStore.end(); ++itr)
|
||||
{
|
||||
@@ -591,6 +593,98 @@ void ObjectMgr::LoadCreatureTemplates()
|
||||
sLog->outString();
|
||||
}
|
||||
|
||||
void ObjectMgr::LoadCreatureTemplateResistances()
|
||||
{
|
||||
uint32 oldMSTime = getMSTime();
|
||||
|
||||
// 0 1 2
|
||||
QueryResult result = WorldDatabase.Query("SELECT CreatureID, School, Resistance FROM creature_template_resistance");
|
||||
|
||||
if (!result)
|
||||
{
|
||||
sLog->outString(">> Loaded 0 creature template resistance definitions. DB table `creature_template_resistance` is empty.");
|
||||
sLog->outString();
|
||||
return;
|
||||
}
|
||||
|
||||
uint32 count = 0;
|
||||
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
|
||||
uint32 creatureID = fields[0].GetUInt32();
|
||||
uint8 school = fields[1].GetUInt8();
|
||||
|
||||
if (school == SPELL_SCHOOL_NORMAL || school >= MAX_SPELL_SCHOOL)
|
||||
{
|
||||
sLog->outErrorDb("creature_template_resistance has resistance definitions for creature %u but this school %u doesn't exist", creatureID, school);
|
||||
continue;
|
||||
}
|
||||
|
||||
CreatureTemplateContainer::iterator itr = _creatureTemplateStore.find(creatureID);
|
||||
if (itr == _creatureTemplateStore.end())
|
||||
{
|
||||
sLog->outErrorDb("creature_template_resistance has resistance definitions for creature %u but this creature doesn't exist", creatureID);
|
||||
continue;
|
||||
}
|
||||
|
||||
CreatureTemplate& creatureTemplate = itr->second;
|
||||
creatureTemplate.resistance[school] = fields[2].GetInt16();
|
||||
|
||||
++count;
|
||||
} while (result->NextRow());
|
||||
|
||||
sLog->outString(">> Loaded %u creature template resistances in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
|
||||
sLog->outString();
|
||||
}
|
||||
|
||||
void ObjectMgr::LoadCreatureTemplateSpells()
|
||||
{
|
||||
uint32 oldMSTime = getMSTime();
|
||||
|
||||
// 0 1 2
|
||||
QueryResult result = WorldDatabase.Query("SELECT CreatureID, `Index`, Spell FROM creature_template_spell");
|
||||
|
||||
if (!result)
|
||||
{
|
||||
sLog->outString(">> Loaded 0 creature template spell definitions. DB table `creature_template_spell` is empty.");
|
||||
sLog->outString();
|
||||
return;
|
||||
}
|
||||
|
||||
uint32 count = 0;
|
||||
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
|
||||
uint32 creatureID = fields[0].GetUInt32();
|
||||
uint8 index = fields[1].GetUInt8();
|
||||
|
||||
if (index >= MAX_CREATURE_SPELLS)
|
||||
{
|
||||
sLog->outErrorDb("creature_template_spell has spell definitions for creature %u with a incorrect index %u", creatureID, index);
|
||||
continue;
|
||||
}
|
||||
|
||||
CreatureTemplateContainer::iterator itr = _creatureTemplateStore.find(creatureID);
|
||||
if (itr == _creatureTemplateStore.end())
|
||||
{
|
||||
sLog->outErrorDb("creature_template_spell has spell definitions for creature %u but this creature doesn't exist", creatureID);
|
||||
continue;
|
||||
}
|
||||
|
||||
CreatureTemplate& creatureTemplate = itr->second;
|
||||
creatureTemplate.spells[index] = fields[2].GetUInt32();;
|
||||
|
||||
++count;
|
||||
} while (result->NextRow());
|
||||
|
||||
sLog->outString(">> Loaded %u creature template spells in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
|
||||
sLog->outString();
|
||||
}
|
||||
|
||||
void ObjectMgr::LoadCreatureTemplateAddons()
|
||||
{
|
||||
uint32 oldMSTime = getMSTime();
|
||||
@@ -964,7 +1058,7 @@ void ObjectMgr::CheckCreatureTemplate(CreatureTemplate const* cInfo)
|
||||
sLog->outErrorDb("Creature (Entry: %u) has non-existing PetSpellDataId (%u).", cInfo->Entry, cInfo->PetSpellDataId);
|
||||
}
|
||||
|
||||
for (uint8 j = 0; j < CREATURE_MAX_SPELLS; ++j)
|
||||
for (uint8 j = 0; j < MAX_CREATURE_SPELLS; ++j)
|
||||
{
|
||||
if (cInfo->spells[j] && !sSpellMgr->GetSpellInfo(cInfo->spells[j]))
|
||||
{
|
||||
|
||||
@@ -972,6 +972,8 @@ public:
|
||||
void LoadCreatureLocales();
|
||||
void LoadCreatureTemplates();
|
||||
void LoadCreatureTemplateAddons();
|
||||
void LoadCreatureTemplateResistances();
|
||||
void LoadCreatureTemplateSpells();
|
||||
void CheckCreatureTemplate(CreatureTemplate const* cInfo);
|
||||
void LoadGameObjectQuestItems();
|
||||
void LoadCreatureQuestItems();
|
||||
|
||||
@@ -482,7 +482,7 @@ public:
|
||||
for (uint8 i = SPELL_SCHOOL_HOLY; i < MAX_SPELL_SCHOOL; ++i)
|
||||
cInfo->resistance[i] = fields[42 + i - 1].GetUInt16();
|
||||
|
||||
for (uint8 i = 0; i < CREATURE_MAX_SPELLS; ++i)
|
||||
for (uint8 i = 0; i < MAX_CREATURE_SPELLS; ++i)
|
||||
cInfo->spells[i] = fields[48 + i].GetUInt32();
|
||||
|
||||
cInfo->PetSpellDataId = fields[56].GetUInt32();
|
||||
|
||||
@@ -57,7 +57,7 @@ public:
|
||||
{
|
||||
player->KilledMonsterCredit(cr->GetDisplayId() == NPC_SOWAW_WATER_MODEL ? 29008 : 29009, 0);
|
||||
CreatureTemplate const* ct = sObjectMgr->GetCreatureTemplate(cr->GetDisplayId() == NPC_SOWAW_WIND_MODEL ? NPC_SOWAW_WIND_ELEMENTAL : NPC_SOWAW_WATER_ELEMENTAL);
|
||||
for (uint8 i = 0; i < CREATURE_MAX_SPELLS; ++i)
|
||||
for (uint8 i = 0; i < MAX_CREATURE_SPELLS; ++i)
|
||||
cr->m_spells[i] = ct->spells[i];
|
||||
|
||||
player->VehicleSpellInitialize();
|
||||
|
||||
@@ -650,7 +650,7 @@ public:
|
||||
caster->ApplySpellImmune(SPELL_COLOSSUS_GROUND_SLAM, IMMUNITY_ID, SPELL_COLOSSUS_GROUND_SLAM, true);
|
||||
caster->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISABLE_MOVE);
|
||||
caster->SetControlled(false, UNIT_STATE_ROOT);
|
||||
for (uint8 i = 0; i < CREATURE_MAX_SPELLS; ++i)
|
||||
for (uint8 i = 0; i < MAX_CREATURE_SPELLS; ++i)
|
||||
caster->m_spells[i] = 0;
|
||||
|
||||
caster->m_spells[0] = SPELL_JORMUNGAR_EMERGE;
|
||||
@@ -663,7 +663,7 @@ public:
|
||||
caster->SetControlled(true, UNIT_STATE_ROOT);
|
||||
|
||||
if (CreatureTemplate const* ct = sObjectMgr->GetCreatureTemplate(caster->GetEntry()))
|
||||
for (uint8 i = 0; i < CREATURE_MAX_SPELLS; ++i)
|
||||
for (uint8 i = 0; i < MAX_CREATURE_SPELLS; ++i)
|
||||
caster->m_spells[i] = ct->spells[i];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user