Skip to content

Commit

Permalink
Core/Creature: Added possibility to give creatures multiple gossip me…
Browse files Browse the repository at this point in the history
…nu ids and control them via conditions (#28159)
  • Loading branch information
mdX7 authored Apr 5, 2023
1 parent c1c04fe commit 36044a9
Show file tree
Hide file tree
Showing 18 changed files with 194 additions and 104 deletions.
12 changes: 12 additions & 0 deletions sql/updates/world/master/9999_99_99_00_world.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--
DROP TABLE IF EXISTS `creature_template_gossip`;
CREATE TABLE `creature_template_gossip` (
`CreatureID` int UNSIGNED NOT NULL,
`MenuID` int UNSIGNED NOT NULL,
`VerifiedBuild` int NOT NULL DEFAULT 0,
PRIMARY KEY (`CreatureID`, `MenuID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

INSERT INTO `creature_template_gossip` SELECT `entry`, `gossip_menu_id`, `VerifiedBuild` FROM `creature_template` WHERE `gossip_menu_id` <> 0;

ALTER TABLE `creature_template` DROP COLUMN `gossip_menu_id`;
Original file line number Diff line number Diff line change
Expand Up @@ -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, 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_CREATURE_TEMPLATE, "SELECT entry, difficulty_entry_1, difficulty_entry_2, difficulty_entry_3, KillCredit1, KillCredit2, name, femaleName, subname, TitleAlt, IconName, 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);
Expand Down
8 changes: 3 additions & 5 deletions src/server/game/Conditions/ConditionMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1530,12 +1530,10 @@ bool ConditionMgr::addToGossipMenus(Condition* cond) const
{
for (GossipMenusContainer::iterator itr = pMenuBounds.first; itr != pMenuBounds.second; ++itr)
{
if ((*itr).second.MenuID == cond->SourceGroup && (*itr).second.TextID == uint32(cond->SourceEntry))
{
(*itr).second.Conditions.push_back(cond);
return true;
}
if (itr->second.MenuID == cond->SourceGroup && (itr->second.TextID == uint32(cond->SourceEntry) || cond->SourceEntry == 0))
itr->second.Conditions.push_back(cond);
}
return true;
}

TC_LOG_ERROR("sql.sql", "{} GossipMenu {} not found.", cond->ToString(), cond->SourceGroup);
Expand Down
9 changes: 3 additions & 6 deletions src/server/game/Entities/Creature/Creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ Creature::Creature(bool isWorldObject) : Unit(isWorldObject), MapObject(), m_Pla
m_defaultMovementType(IDLE_MOTION_TYPE), m_spawnId(UI64LIT(0)), m_equipmentId(0), m_originalEquipmentId(0), m_AlreadyCallAssistance(false), m_AlreadySearchedAssistance(false), m_cannotReachTarget(false), m_cannotReachTimer(0),
m_meleeDamageSchoolMask(SPELL_SCHOOL_MASK_NORMAL), m_originalEntry(0), m_homePosition(), m_transportHomePosition(), m_creatureInfo(nullptr), m_creatureData(nullptr), _waypointPathId(0), _currentWaypointNodeInfo(0, 0),
m_formation(nullptr), m_triggerJustAppeared(true), m_respawnCompatibilityMode(false), _lastDamagedTime(0),
_regenerateHealth(true), _isMissingCanSwimFlagOutOfCombat(false)
_regenerateHealth(true), _isMissingCanSwimFlagOutOfCombat(false), _gossipMenuId(0)
{
m_regenTimer = CREATURE_REGEN_INTERVAL;

Expand Down Expand Up @@ -3525,13 +3525,10 @@ void Creature::ExitVehicle(Position const* /*exitPosition*/)

uint32 Creature::GetGossipMenuId() const
{
if (_gossipMenuId)
return *_gossipMenuId;

return GetCreatureTemplate()->GossipMenuId;
return _gossipMenuId;
}

void Creature::SetGossipMenuId(Optional<uint32> gossipMenuId)
void Creature::SetGossipMenuId(uint32 gossipMenuId)
{
_gossipMenuId = gossipMenuId;
}
Expand Down
4 changes: 2 additions & 2 deletions src/server/game/Entities/Creature/Creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ class TC_GAME_API Creature : public Unit, public GridObject<Creature>, public Ma
bool HasFlag(CreatureStaticFlags8 flag) const { return _staticFlags.HasFlag(flag); }

uint32 GetGossipMenuId() const;
void SetGossipMenuId(Optional<uint32> gossipMenuId);
void SetGossipMenuId(uint32 gossipMenuId);

uint32 GetTrainerId() const;
void SetTrainerId(Optional<uint32> trainerId);
Expand Down Expand Up @@ -507,7 +507,7 @@ class TC_GAME_API Creature : public Unit, public GridObject<Creature>, public Ma

bool _isMissingCanSwimFlagOutOfCombat;

Optional<uint32> _gossipMenuId;
uint32 _gossipMenuId;
Optional<uint32> _trainerId;
};

Expand Down
2 changes: 1 addition & 1 deletion src/server/game/Entities/Creature/CreatureData.h
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ struct TC_GAME_API CreatureTemplate
std::string SubName;
std::string TitleAlt;
std::string IconName;
uint32 GossipMenuId;
std::vector<uint32> GossipMenuIds;
std::unordered_map<Difficulty, CreatureLevelScaling> scalingStore;
int32 HealthScalingExpansion;
uint32 RequiredExpansion;
Expand Down
31 changes: 28 additions & 3 deletions src/server/game/Entities/Player/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14233,7 +14233,7 @@ uint32 Player::GetGossipTextId(WorldObject* source)
if (!source)
return DEFAULT_GOSSIP_MESSAGE;

return GetGossipTextId(GetDefaultGossipMenuForSource(source), source);
return GetGossipTextId(GetGossipMenuForSource(source), source);
}

uint32 Player::GetGossipTextId(uint32 menuId, WorldObject* source)
Expand All @@ -14247,19 +14247,44 @@ uint32 Player::GetGossipTextId(uint32 menuId, WorldObject* source)

for (GossipMenusContainer::const_iterator itr = menuBounds.first; itr != menuBounds.second; ++itr)
{
// continue if only checks menuid instead of text
if (!itr->second.TextID)
continue;

if (sConditionMgr->IsObjectMeetToConditions(this, source, itr->second.Conditions))
textId = itr->second.TextID;
}

return textId;
}

uint32 Player::GetDefaultGossipMenuForSource(WorldObject* source)
uint32 Player::GetGossipMenuForSource(WorldObject* source)
{
switch (source->GetTypeId())
{
case TYPEID_UNIT:
return source->ToCreature()->GetGossipMenuId();
{
uint32 menuIdToShow = source->ToCreature()->GetGossipMenuId();

// if menu id is set by script
if (menuIdToShow)
return menuIdToShow;

// otherwise pick from db based on conditions
for (uint32 menuId : source->ToCreature()->GetCreatureTemplate()->GossipMenuIds)
{
GossipMenusMapBounds menuBounds = sObjectMgr->GetGossipMenusMapBounds(menuId);

for (GossipMenusContainer::const_iterator itr = menuBounds.first; itr != menuBounds.second; ++itr)
{
if (!sConditionMgr->IsObjectMeetToConditions(this, source, itr->second.Conditions))
continue;

menuIdToShow = menuId;
}
}
return menuIdToShow;
}
case TYPEID_GAMEOBJECT:
return source->ToGameObject()->GetGOInfo()->GetGossipMenuId();
default:
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/Entities/Player/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -1542,7 +1542,7 @@ class TC_GAME_API Player : public Unit, public GridObject<Player>

uint32 GetGossipTextId(uint32 menuId, WorldObject* source);
uint32 GetGossipTextId(WorldObject* source);
static uint32 GetDefaultGossipMenuForSource(WorldObject* source);
uint32 GetGossipMenuForSource(WorldObject* source);

/*********************************************************/
/*** QUEST SYSTEM ***/
Expand Down
Loading

0 comments on commit 36044a9

Please sign in to comment.