diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/server/database/Database/Implementation/WorldDatabase.cpp | 2 | ||||
-rw-r--r-- | src/server/game/AI/ScriptedAI/ScriptedCreature.h | 11 | ||||
-rw-r--r-- | src/server/game/Entities/Creature/Creature.cpp | 23 | ||||
-rw-r--r-- | src/server/game/Entities/Creature/Creature.h | 5 | ||||
-rw-r--r-- | src/server/game/Entities/Creature/CreatureData.h | 1 | ||||
-rw-r--r-- | src/server/game/Entities/Object/Object.cpp | 21 | ||||
-rw-r--r-- | src/server/game/Entities/Object/Object.h | 5 | ||||
-rw-r--r-- | src/server/game/Globals/ObjectMgr.cpp | 10 | ||||
-rw-r--r-- | src/server/game/Grids/Notifiers/GridNotifiers.h | 47 | ||||
-rw-r--r-- | src/server/game/Maps/SpawnData.h | 1 | ||||
-rw-r--r-- | src/server/game/Miscellaneous/Language.h | 3 | ||||
-rw-r--r-- | src/server/scripts/Commands/cs_npc.cpp | 2 |
12 files changed, 116 insertions, 15 deletions
diff --git a/src/server/database/Database/Implementation/WorldDatabase.cpp b/src/server/database/Database/Implementation/WorldDatabase.cpp index b7bd1fb0991..02ae0ecee8a 100644 --- a/src/server/database/Database/Implementation/WorldDatabase.cpp +++ b/src/server/database/Database/Implementation/WorldDatabase.cpp @@ -77,7 +77,7 @@ void WorldDatabaseConnection::DoPrepareStatements() PrepareStatement(WORLD_SEL_WAYPOINT_SCRIPT_ID_BY_GUID, "SELECT id FROM waypoint_scripts WHERE guid = ?", CONNECTION_SYNCH); PrepareStatement(WORLD_DEL_CREATURE, "DELETE FROM creature WHERE guid = ?", CONNECTION_ASYNC); PrepareStatement(WORLD_SEL_COMMANDS, "SELECT name, help FROM command", CONNECTION_SYNCH); - PrepareStatement(WORLD_SEL_CREATURE_TEMPLATE, "SELECT entry, difficulty_entry_1, difficulty_entry_2, difficulty_entry_3, KillCredit1, KillCredit2, name, femaleName, subname, TitleAlt, IconName, gossip_menu_id, minlevel, maxlevel, HealthScalingExpansion, RequiredExpansion, VignetteID, faction, npcflag, speed_walk, speed_run, scale, `rank`, dmgschool, BaseAttackTime, RangeAttackTime, BaseVariance, RangeVariance, unit_class, unit_flags, unit_flags2, unit_flags3, dynamicflags, family, trainer_class, type, type_flags, type_flags2, lootid, pickpocketloot, skinloot, VehicleId, mingold, maxgold, AIName, MovementType, ctm.Ground, ctm.Swim, ctm.Flight, ctm.Rooted, ctm.Chase, ctm.Random, ctm.InteractionPauseTimer, HoverHeight, HealthModifier, HealthModifierExtra, ManaModifier, ManaModifierExtra, ArmorModifier, DamageModifier, ExperienceModifier, RacialLeader, movementId, CreatureDifficultyID, WidgetSetID, WidgetSetUnitConditionID, RegenHealth, mechanic_immune_mask, spell_school_immune_mask, flags_extra, ScriptName FROM creature_template ct LEFT JOIN creature_template_movement ctm ON ct.entry = ctm.CreatureId WHERE entry = ? OR 1 = ?", CONNECTION_SYNCH); + PrepareStatement(WORLD_SEL_CREATURE_TEMPLATE, "SELECT entry, difficulty_entry_1, difficulty_entry_2, difficulty_entry_3, KillCredit1, KillCredit2, name, femaleName, subname, TitleAlt, IconName, gossip_menu_id, minlevel, maxlevel, HealthScalingExpansion, RequiredExpansion, VignetteID, faction, npcflag, speed_walk, speed_run, scale, `rank`, dmgschool, BaseAttackTime, RangeAttackTime, BaseVariance, RangeVariance, unit_class, unit_flags, unit_flags2, unit_flags3, dynamicflags, family, trainer_class, type, type_flags, type_flags2, lootid, pickpocketloot, skinloot, VehicleId, mingold, maxgold, AIName, MovementType, ctm.Ground, ctm.Swim, ctm.Flight, ctm.Rooted, ctm.Chase, ctm.Random, ctm.InteractionPauseTimer, HoverHeight, HealthModifier, HealthModifierExtra, ManaModifier, ManaModifierExtra, ArmorModifier, DamageModifier, ExperienceModifier, RacialLeader, movementId, CreatureDifficultyID, WidgetSetID, WidgetSetUnitConditionID, RegenHealth, mechanic_immune_mask, spell_school_immune_mask, flags_extra, ScriptName, StringId FROM creature_template ct LEFT JOIN creature_template_movement ctm ON ct.entry = ctm.CreatureId WHERE entry = ? OR 1 = ?", CONNECTION_SYNCH); PrepareStatement(WORLD_SEL_WAYPOINT_SCRIPT_BY_ID, "SELECT guid, delay, command, datalong, datalong2, dataint, x, y, z, o FROM waypoint_scripts WHERE id = ?", CONNECTION_SYNCH); PrepareStatement(WORLD_SEL_CREATURE_BY_ID, "SELECT guid FROM creature WHERE id = ?", CONNECTION_SYNCH); PrepareStatement(WORLD_SEL_GAMEOBJECT_NEAREST, "SELECT guid, id, position_x, position_y, position_z, map, (POW(position_x - ?, 2) + POW(position_y - ?, 2) + POW(position_z - ?, 2)) AS order_ FROM gameobject WHERE map = ? AND (POW(position_x - ?, 2) + POW(position_y - ?, 2) + POW(position_z - ?, 2)) <= ? ORDER BY order_", CONNECTION_SYNCH); diff --git a/src/server/game/AI/ScriptedAI/ScriptedCreature.h b/src/server/game/AI/ScriptedAI/ScriptedCreature.h index a6037edf291..d8d3a356c06 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedCreature.h +++ b/src/server/game/AI/ScriptedAI/ScriptedCreature.h @@ -391,6 +391,11 @@ inline Creature* GetClosestCreatureWithEntry(WorldObject* source, uint32 entry, return source->FindNearestCreature(entry, maxSearchRange, alive); } +inline Creature* GetClosestCreatureWithOptions(WorldObject* source, float maxSearchRange, FindCreatureOptions const& options) +{ + return source->FindNearestCreatureWithOptions(maxSearchRange, options); +} + inline GameObject* GetClosestGameObjectWithEntry(WorldObject* source, uint32 entry, float maxSearchRange, bool spawnedOnly = true) { return source->FindNearestGameObject(entry, maxSearchRange, spawnedOnly); @@ -403,6 +408,12 @@ inline void GetCreatureListWithEntryInGrid(Container& container, WorldObject* so } template <typename Container> +inline void GetCreatureListWithOptionsInGrid(Container& container, WorldObject* source, float maxSearchRange, FindCreatureOptions const& options) +{ + source->GetCreatureListWithOptionsInGrid(container, maxSearchRange, options); +} + +template <typename Container> inline void GetGameObjectListWithEntryInGrid(Container& container, WorldObject* source, uint32 entry, float maxSearchRange) { source->GetGameObjectListWithEntryInGrid(container, entry, maxSearchRange); diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index 37bc520a8ee..2d0ecced692 100644 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -690,6 +690,8 @@ bool Creature::UpdateEntry(uint32 entry, CreatureData const* data /*= nullptr*/, //We must update last scriptId or it looks like we reloaded a script, breaking some things such as gossip temporarily LastUsedScriptID = GetScriptId(); + m_stringIds[0] = cInfo->StringId; + return true; } @@ -1811,6 +1813,8 @@ bool Creature::LoadFromDB(ObjectGuid::LowType spawnId, Map* map, bool addToMap, // checked at creature_template loading m_defaultMovementType = MovementGeneratorType(data->movementType); + m_stringIds[1] = data->StringId; + if (addToMap && !GetMap()->AddToMap(this)) return false; return true; @@ -3010,6 +3014,25 @@ uint32 Creature::GetScriptId() const return ASSERT_NOTNULL(sObjectMgr->GetCreatureTemplate(GetEntry()))->ScriptID; } +bool Creature::HasStringId(std::string_view id) const +{ + return std::find(m_stringIds.begin(), m_stringIds.end(), id) != m_stringIds.end(); +} + +void Creature::SetScriptStringId(std::string id) +{ + if (!id.empty()) + { + m_scriptStringId.emplace(std::move(id)); + m_stringIds[2] = *m_scriptStringId; + } + else + { + m_scriptStringId.reset(); + m_stringIds[2] = {}; + } +} + VendorItemData const* Creature::GetVendorItems() const { return sObjectMgr->GetNpcVendorItemList(GetEntry()); diff --git a/src/server/game/Entities/Creature/Creature.h b/src/server/game/Entities/Creature/Creature.h index 1e8c6044a13..4236c2da95f 100644 --- a/src/server/game/Entities/Creature/Creature.h +++ b/src/server/game/Entities/Creature/Creature.h @@ -212,6 +212,9 @@ class TC_GAME_API Creature : public Unit, public GridObject<Creature>, public Ma std::string const& GetAIName() const; std::string GetScriptName() const; uint32 GetScriptId() const; + bool HasStringId(std::string_view id) const; + void SetScriptStringId(std::string id); + std::array<std::string_view, 3> const& GetStringIds() const { return m_stringIds; } // override WorldObject function for proper name localization std::string GetNameForLocaleIdx(LocaleConstant locale) const override; @@ -433,6 +436,8 @@ class TC_GAME_API Creature : public Unit, public GridObject<Creature>, public Ma CreatureTemplate const* m_creatureInfo; // Can differ from sObjectMgr->GetCreatureTemplate(GetEntry()) in difficulty mode > 0 CreatureData const* m_creatureData; + std::array<std::string_view, 3> m_stringIds; + Optional<std::string> m_scriptStringId; uint16 m_LootMode; // Bitmask (default: LOOT_MODE_DEFAULT) that determines what loot will be lootable diff --git a/src/server/game/Entities/Creature/CreatureData.h b/src/server/game/Entities/Creature/CreatureData.h index d865c662297..45ded7b5011 100644 --- a/src/server/game/Entities/Creature/CreatureData.h +++ b/src/server/game/Entities/Creature/CreatureData.h @@ -478,6 +478,7 @@ struct TC_GAME_API CreatureTemplate uint32 SpellSchoolImmuneMask; uint32 flags_extra; uint32 ScriptID; + std::string StringId; WorldPacket QueryData[TOTAL_LOCALES]; CreatureModel const* GetModelByIdx(uint32 idx) const; CreatureModel const* GetRandomValidModel() const; diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp index cea03921ed6..5b2e87505f7 100644 --- a/src/server/game/Entities/Object/Object.cpp +++ b/src/server/game/Entities/Object/Object.cpp @@ -2118,8 +2118,9 @@ Creature* WorldObject::FindNearestCreature(uint32 entry, float range, bool alive Creature* WorldObject::FindNearestCreatureWithOptions(float range, FindCreatureOptions const& options) const { Creature* creature = nullptr; - Trinity::NearestCreatureEntryWithOptionsInObjectRangeCheck checker(*this, range, options); - Trinity::CreatureLastSearcher<Trinity::NearestCreatureEntryWithOptionsInObjectRangeCheck> searcher(this, creature, checker); + Trinity::NearestCheckCustomizer checkCustomizer(*this, range); + Trinity::CreatureWithOptionsInObjectRangeCheck checker(*this, checkCustomizer, options); + Trinity::CreatureLastSearcher searcher(this, creature, checker); if (options.IgnorePhases) searcher.i_phaseShift = &PhasingHandler::GetAlwaysVisiblePhaseShift(); @@ -3284,6 +3285,18 @@ void WorldObject::GetCreatureListWithEntryInGrid(Container& creatureContainer, u } template <typename Container> +void WorldObject::GetCreatureListWithOptionsInGrid(Container& creatureContainer, float maxSearchRange, FindCreatureOptions const& options) const +{ + Trinity::NoopCheckCustomizer checkCustomizer; + Trinity::CreatureWithOptionsInObjectRangeCheck check(*this, checkCustomizer, options); + Trinity::CreatureListSearcher searcher(this, creatureContainer, check); + if (options.IgnorePhases) + searcher.i_phaseShift = &PhasingHandler::GetAlwaysVisiblePhaseShift(); + + Cell::VisitGridObjects(this, searcher, maxSearchRange); +} + +template <typename Container> void WorldObject::GetPlayerListInGrid(Container& playerContainer, float maxSearchRange, bool alive /*= true*/) const { Trinity::AnyPlayerInObjectRangeCheck checker(this, maxSearchRange, alive); @@ -3723,6 +3736,10 @@ template TC_GAME_API void WorldObject::GetCreatureListWithEntryInGrid(std::list< template TC_GAME_API void WorldObject::GetCreatureListWithEntryInGrid(std::deque<Creature*>&, uint32, float) const; template TC_GAME_API void WorldObject::GetCreatureListWithEntryInGrid(std::vector<Creature*>&, uint32, float) const; +template TC_GAME_API void WorldObject::GetCreatureListWithOptionsInGrid(std::list<Creature*>&, float, FindCreatureOptions const&) const; +template TC_GAME_API void WorldObject::GetCreatureListWithOptionsInGrid(std::deque<Creature*>&,float, FindCreatureOptions const&) const; +template TC_GAME_API void WorldObject::GetCreatureListWithOptionsInGrid(std::vector<Creature*>&, float, FindCreatureOptions const&) const; + template TC_GAME_API void WorldObject::GetPlayerListInGrid(std::list<Player*>&, float, bool) const; template TC_GAME_API void WorldObject::GetPlayerListInGrid(std::deque<Player*>&, float, bool) const; template TC_GAME_API void WorldObject::GetPlayerListInGrid(std::vector<Player*>&, float, bool) const; diff --git a/src/server/game/Entities/Object/Object.h b/src/server/game/Entities/Object/Object.h index 2f185cea7c2..f59f35b7215 100644 --- a/src/server/game/Entities/Object/Object.h +++ b/src/server/game/Entities/Object/Object.h @@ -437,6 +437,7 @@ struct FindCreatureOptions FindCreatureOptions() = default; FindCreatureOptions& SetCreatureId(uint32 creatureId) { CreatureId = creatureId; return *this; } + FindCreatureOptions& SetStringId(std::string_view stringId) { StringId = stringId; return *this; } FindCreatureOptions& SetIsAlive(bool isAlive) { IsAlive = isAlive; return *this; } FindCreatureOptions& SetIsInCombat(bool isInCombat) { IsInCombat = isInCombat; return *this; } @@ -454,6 +455,7 @@ struct FindCreatureOptions FindCreatureOptions& SetPrivateObjectOwner(ObjectGuid privateObjectOwnerGuid) { PrivateObjectOwnerGuid = privateObjectOwnerGuid; return *this; } Optional<uint32> CreatureId; + Optional<std::string_view> StringId; Optional<bool> IsAlive; Optional<bool> IsInCombat; @@ -700,6 +702,9 @@ class TC_GAME_API WorldObject : public Object, public WorldLocation void GetCreatureListWithEntryInGrid(Container& creatureContainer, uint32 entry, float maxSearchRange = 250.0f) const; template <typename Container> + void GetCreatureListWithOptionsInGrid(Container& creatureContainer, float maxSearchRange, FindCreatureOptions const& options) const; + + template <typename Container> void GetPlayerListInGrid(Container& playerContainer, float maxSearchRange, bool alive = true) const; void DestroyForNearbyPlayers(); diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp index 03ecfec1d82..248306ad8c3 100644 --- a/src/server/game/Globals/ObjectMgr.cpp +++ b/src/server/game/Globals/ObjectMgr.cpp @@ -366,8 +366,8 @@ void ObjectMgr::LoadCreatureTemplates() // "RacialLeader, movementId, CreatureDifficultyID, WidgetSetID, WidgetSetUnitConditionID, RegenHealth, " // 67 68 69 // "mechanic_immune_mask, spell_school_immune_mask, flags_extra, " - // 70 - // "ScriptName FROM creature_template WHERE entry = ? OR 1 = ?"); + // 70 71 + // "ScriptName, StringId FROM creature_template WHERE entry = ? OR 1 = ?"); WorldDatabasePreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_CREATURE_TEMPLATE); stmt->setUInt32(0, 0); @@ -501,6 +501,7 @@ void ObjectMgr::LoadCreatureTemplate(Field* fields) creatureTemplate.SpellSchoolImmuneMask = fields[68].GetUInt32(); creatureTemplate.flags_extra = fields[69].GetUInt32(); creatureTemplate.ScriptID = GetScriptId(fields[70].GetString()); + creatureTemplate.StringId = fields[71].GetString(); } void ObjectMgr::LoadCreatureTemplateResistances() @@ -2199,8 +2200,8 @@ void ObjectMgr::LoadCreatures() QueryResult result = WorldDatabase.Query("SELECT creature.guid, id, map, position_x, position_y, position_z, orientation, modelid, equipment_id, spawntimesecs, wander_distance, " // 11 12 13 14 15 16 17 18 19 20 21 "currentwaypoint, curhealth, curmana, MovementType, spawnDifficulties, eventEntry, poolSpawnId, creature.npcflag, creature.unit_flags, creature.unit_flags2, creature.unit_flags3, " - // 22 23 24 25 26 27 - "creature.dynamicflags, creature.phaseUseFlags, creature.phaseid, creature.phasegroup, creature.terrainSwapMap, creature.ScriptName " + // 22 23 24 25 26 27 28 + "creature.dynamicflags, creature.phaseUseFlags, creature.phaseid, creature.phasegroup, creature.terrainSwapMap, creature.ScriptName, creature.StringId " "FROM creature " "LEFT OUTER JOIN game_event_creature ON creature.guid = game_event_creature.guid " "LEFT OUTER JOIN pool_members ON pool_members.type = 0 AND creature.guid = pool_members.spawnId"); @@ -2261,6 +2262,7 @@ void ObjectMgr::LoadCreatures() data.phaseGroup = fields[25].GetUInt32(); data.terrainSwapMap = fields[26].GetInt32(); data.scriptId = GetScriptId(fields[27].GetString()); + data.StringId = fields[28].GetString(); data.spawnGroupData = IsTransportMap(data.mapId) ? GetLegacySpawnGroup() : GetDefaultSpawnGroup(); // transport spawns default to compatibility group MapEntry const* mapEntry = sMapStore.LookupEntry(data.mapId); diff --git a/src/server/game/Grids/Notifiers/GridNotifiers.h b/src/server/game/Grids/Notifiers/GridNotifiers.h index 71cc95fb679..7d6ffccc3ec 100644 --- a/src/server/game/Grids/Notifiers/GridNotifiers.h +++ b/src/server/game/Grids/Notifiers/GridNotifiers.h @@ -686,6 +686,35 @@ namespace Trinity // CHECKS && DO classes + // CHECK modifiers + class NoopCheckCustomizer + { + public: + bool Test(WorldObject const* /*o*/) const { return true; } + + void Update(WorldObject const* /*o*/) { } + }; + + class NearestCheckCustomizer + { + public: + explicit NearestCheckCustomizer(WorldObject const& obj, float range) : i_obj(obj), i_range(range) { } + + bool Test(WorldObject const* o) const + { + return i_obj.IsWithinDistInMap(o, i_range); + } + + void Update(WorldObject const* o) + { + i_range = i_obj.GetDistance(o); + } + + private: + WorldObject const& i_obj; + float i_range; + }; + // WorldObject check classes class TC_GAME_API AnyDeadUnitObjectInRangeCheck @@ -1441,13 +1470,14 @@ namespace Trinity NearestCreatureEntryWithLiveStateInObjectRangeCheck(NearestCreatureEntryWithLiveStateInObjectRangeCheck const&) = delete; }; - class NearestCreatureEntryWithOptionsInObjectRangeCheck + template <typename Customizer = NoopCheckCustomizer> + class CreatureWithOptionsInObjectRangeCheck { public: - NearestCreatureEntryWithOptionsInObjectRangeCheck(WorldObject const& obj, float range, FindCreatureOptions const& args) - : i_obj(obj), i_args(args), i_range(range) { } + CreatureWithOptionsInObjectRangeCheck(WorldObject const& obj, Customizer& customizer, FindCreatureOptions const& args) + : i_obj(obj), i_args(args), i_customizer(customizer) { } - bool operator()(Creature* u) + bool operator()(Creature* u) const { if (u->getDeathState() == DEAD) // Despawned return false; @@ -1455,12 +1485,15 @@ namespace Trinity if (u->GetGUID() == i_obj.GetGUID()) return false; - if (!i_obj.IsWithinDistInMap(u, i_range)) + if (!i_customizer.Test(u)) return false; if (i_args.CreatureId && u->GetEntry() != i_args.CreatureId) return false; + if (i_args.StringId && u->HasStringId(*i_args.StringId)) + return false; + if (i_args.IsAlive.has_value() && u->IsAlive() != i_args.IsAlive) return false; @@ -1486,14 +1519,14 @@ namespace Trinity if (i_args.AuraSpellId && !u->HasAura(*i_args.AuraSpellId)) return false; - i_range = i_obj.GetDistance(u); // use found unit range as new range limit for next check + i_customizer.Update(u); return true; } private: WorldObject const& i_obj; FindCreatureOptions const& i_args; - float i_range; + Customizer& i_customizer; }; class AnyPlayerInObjectRangeCheck diff --git a/src/server/game/Maps/SpawnData.h b/src/server/game/Maps/SpawnData.h index 9f25655e46e..25e6864e633 100644 --- a/src/server/game/Maps/SpawnData.h +++ b/src/server/game/Maps/SpawnData.h @@ -111,6 +111,7 @@ struct SpawnData : public SpawnMetadata int32 spawntimesecs = 0; std::vector<Difficulty> spawnDifficulties; uint32 scriptId = 0; + std::string StringId; protected: SpawnData(SpawnObjectType t) : SpawnMetadata(t) {} diff --git a/src/server/game/Miscellaneous/Language.h b/src/server/game/Miscellaneous/Language.h index 19a0712b3d8..856213af388 100644 --- a/src/server/game/Miscellaneous/Language.h +++ b/src/server/game/Miscellaneous/Language.h @@ -1148,8 +1148,9 @@ enum TrinityStrings LANG_NPCINFO_NPC_FLAGS = 5086, LANG_NPCINFO_PHASE_IDS = 5087, LANG_SCENARIO = 5088, + LANG_OBJECTINFO_STRINGIDS = 5089, - // Room for more Trinity strings 5089-6603 + // Room for more Trinity strings 5090-6603 // Level requirement notifications LANG_SAY_REQ = 6604, diff --git a/src/server/scripts/Commands/cs_npc.cpp b/src/server/scripts/Commands/cs_npc.cpp index 4305ba8b10e..6a6b543b6d0 100644 --- a/src/server/scripts/Commands/cs_npc.cpp +++ b/src/server/scripts/Commands/cs_npc.cpp @@ -535,6 +535,8 @@ public: handler->PSendSysMessage(LANG_NPCINFO_ARMOR, target->GetArmor()); handler->PSendSysMessage(LANG_NPCINFO_POSITION, target->GetPositionX(), target->GetPositionY(), target->GetPositionZ()); handler->PSendSysMessage(LANG_OBJECTINFO_AIINFO, target->GetAIName().c_str(), target->GetScriptName().c_str()); + handler->PSendSysMessage(LANG_OBJECTINFO_STRINGIDS, STRING_VIEW_FMT_ARG(target->GetStringIds()[0]), + STRING_VIEW_FMT_ARG(target->GetStringIds()[1]), STRING_VIEW_FMT_ARG(target->GetStringIds()[2])); handler->PSendSysMessage(LANG_NPCINFO_REACTSTATE, DescribeReactState(target->GetReactState())); if (CreatureAI const* ai = target->AI()) handler->PSendSysMessage(LANG_OBJECTINFO_AITYPE, GetTypeName(*ai).c_str()); |