Core/Conversations: Allow delaying starting conversations (#28545)

This commit is contained in:
Seyden
2022-12-21 14:37:58 +01:00
committed by GitHub
parent 62cc506445
commit 97f3710fa7
2 changed files with 13 additions and 11 deletions
@@ -91,7 +91,7 @@ void Conversation::Remove()
}
}
Conversation* Conversation::CreateConversation(uint32 conversationEntry, Unit* creator, Position const& pos, ObjectGuid privateObjectOwner, SpellInfo const* spellInfo /*= nullptr*/)
Conversation* Conversation::CreateConversation(uint32 conversationEntry, Unit* creator, Position const& pos, ObjectGuid privateObjectOwner, SpellInfo const* spellInfo /*= nullptr*/, bool autoStart /*= true*/)
{
ConversationTemplate const* conversationTemplate = sConversationDataStore->GetConversationTemplate(conversationEntry);
if (!conversationTemplate)
@@ -100,7 +100,8 @@ Conversation* Conversation::CreateConversation(uint32 conversationEntry, Unit* c
ObjectGuid::LowType lowGuid = creator->GetMap()->GenerateLowGuid<HighGuid::Conversation>();
Conversation* conversation = new Conversation();
if (!conversation->Create(lowGuid, conversationEntry, creator->GetMap(), creator, pos, privateObjectOwner, spellInfo))
conversation->Create(lowGuid, conversationEntry, creator->GetMap(), creator, pos, privateObjectOwner, spellInfo);
if (autoStart && !conversation->Start())
{
delete conversation;
return nullptr;
@@ -155,7 +156,7 @@ private:
ConversationActorTemplate const& _actor;
};
bool Conversation::Create(ObjectGuid::LowType lowGuid, uint32 conversationEntry, Map* map, Unit* creator, Position const& pos, ObjectGuid privateObjectOwner, SpellInfo const* /*spellInfo = nullptr*/)
void Conversation::Create(ObjectGuid::LowType lowGuid, uint32 conversationEntry, Map* map, Unit* creator, Position const& pos, ObjectGuid privateObjectOwner, SpellInfo const* /*spellInfo = nullptr*/)
{
ConversationTemplate const* conversationTemplate = sConversationDataStore->GetConversationTemplate(conversationEntry);
ASSERT(conversationTemplate);
@@ -181,14 +182,12 @@ bool Conversation::Create(ObjectGuid::LowType lowGuid, uint32 conversationEntry,
for (ConversationActorTemplate const& actor : conversationTemplate->Actors)
std::visit(ConversationActorFillVisitor(this, creator, map, actor), actor.Data);
std::set<uint16> actorIndices;
std::vector<UF::ConversationLine> lines;
for (ConversationLineTemplate const* line : conversationTemplate->Lines)
{
if (!sConditionMgr->IsObjectMeetingNotGroupedConditions(CONDITION_SOURCE_TYPE_CONVERSATION_LINE, line->Id, creator))
continue;
actorIndices.insert(line->ActorIdx);
lines.emplace_back();
UF::ConversationLine& lineField = lines.back();
@@ -223,14 +222,16 @@ bool Conversation::Create(ObjectGuid::LowType lowGuid, uint32 conversationEntry,
_duration += 10s;
sScriptMgr->OnConversationCreate(this, creator);
}
// All actors need to be set
for (uint16 actorIndex : actorIndices)
bool Conversation::Start()
{
for (UF::ConversationLine const& line : *m_conversationData->Lines)
{
UF::ConversationActor const* actor = actorIndex < m_conversationData->Actors.size() ? &m_conversationData->Actors[actorIndex] : nullptr;
UF::ConversationActor const* actor = line.ActorIndex < m_conversationData->Actors.size() ? &m_conversationData->Actors[line.ActorIndex] : nullptr;
if (!actor || (!actor->CreatureID && actor->ActorGUID.IsEmpty() && !actor->NoActorObject))
{
TC_LOG_ERROR("entities.conversation", "Failed to create conversation (Id: %u) due to missing actor (Idx: %u).", conversationEntry, actorIndex);
TC_LOG_ERROR("entities.conversation", "Failed to create conversation (Id: %u) due to missing actor (Idx: %u).", GetEntry(), line.ActorIndex);
return false;
}
}
@@ -60,8 +60,9 @@ class TC_GAME_API Conversation : public WorldObject, public GridObject<Conversat
Milliseconds GetDuration() const { return _duration; }
uint32 GetTextureKitId() const { return _textureKitId; }
static Conversation* CreateConversation(uint32 conversationEntry, Unit* creator, Position const& pos, ObjectGuid privateObjectOwner, SpellInfo const* spellInfo = nullptr);
bool Create(ObjectGuid::LowType lowGuid, uint32 conversationEntry, Map* map, Unit* creator, Position const& pos, ObjectGuid privateObjectOwner, SpellInfo const* spellInfo = nullptr);
static Conversation* CreateConversation(uint32 conversationEntry, Unit* creator, Position const& pos, ObjectGuid privateObjectOwner, SpellInfo const* spellInfo = nullptr, bool autoStart = true);
void Create(ObjectGuid::LowType lowGuid, uint32 conversationEntry, Map* map, Unit* creator, Position const& pos, ObjectGuid privateObjectOwner, SpellInfo const* spellInfo = nullptr);
bool Start();
void AddActor(int32 actorId, uint32 actorIdx, ObjectGuid const& actorGuid);
void AddActor(int32 actorId, uint32 actorIdx, ConversationActorType type, uint32 creatureId, uint32 creatureDisplayInfoId);