mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-21 09:44:45 +01:00
Core/Conversation: Added some helper methods for scripting
This commit is contained in:
@@ -24,10 +24,12 @@
|
||||
#include "IteratorPair.h"
|
||||
#include "Log.h"
|
||||
#include "Map.h"
|
||||
#include "ObjectAccessor.h"
|
||||
#include "PhasingHandler.h"
|
||||
#include "Player.h"
|
||||
#include "ScriptMgr.h"
|
||||
#include "UpdateData.h"
|
||||
#include "WorldSession.h"
|
||||
|
||||
Conversation::Conversation() : WorldObject(false), _duration(0), _textureKitId(0)
|
||||
{
|
||||
@@ -278,6 +280,59 @@ Milliseconds Conversation::GetLastLineEndTime(LocaleConstant locale) const
|
||||
return _lastLineEndTimes[locale];
|
||||
}
|
||||
|
||||
int32 Conversation::GetLineDuration(LocaleConstant locale, int32 lineId)
|
||||
{
|
||||
ConversationLineEntry const* convoLine = sConversationLineStore.LookupEntry(lineId);
|
||||
if (!convoLine)
|
||||
{
|
||||
TC_LOG_ERROR("entities.conversation", "Conversation::GetLineDuration: Tried to get duration for invalid ConversationLine id {}.", lineId);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32 const* textDuration = sDB2Manager.GetBroadcastTextDuration(convoLine->BroadcastTextID, locale);
|
||||
if (!textDuration)
|
||||
return 0;
|
||||
|
||||
return *textDuration + convoLine->AdditionalDuration;
|
||||
}
|
||||
|
||||
Milliseconds Conversation::GetLineEndTime(LocaleConstant locale, int32 lineId) const
|
||||
{
|
||||
Milliseconds const* lineStartTime = GetLineStartTime(locale, lineId);
|
||||
if (!lineStartTime)
|
||||
{
|
||||
TC_LOG_ERROR("entities.conversation", "Conversation::GetLineEndTime: Unable to get line start time for locale {}, lineid {} (Conversation ID: {}).", locale, lineId, GetEntry());
|
||||
return Milliseconds(0);
|
||||
}
|
||||
return *lineStartTime + Milliseconds(GetLineDuration(locale, lineId));
|
||||
}
|
||||
|
||||
LocaleConstant Conversation::GetPrivateObjectOwnerLocale() const
|
||||
{
|
||||
LocaleConstant privateOwnerLocale = LOCALE_enUS;
|
||||
if (Player* owner = ObjectAccessor::GetPlayer(*this, GetPrivateObjectOwner()))
|
||||
privateOwnerLocale = owner->GetSession()->GetSessionDbLocaleIndex();
|
||||
return privateOwnerLocale;
|
||||
}
|
||||
|
||||
Unit* Conversation::GetActorUnit(uint32 actorIdx) const
|
||||
{
|
||||
if (m_conversationData->Actors.size() <= actorIdx)
|
||||
{
|
||||
TC_LOG_ERROR("entities.conversation", "Conversation::GetActorUnit: Tried to access invalid actor idx {} (Conversation ID: {}).", actorIdx, GetEntry());
|
||||
return nullptr;
|
||||
}
|
||||
return ObjectAccessor::GetUnit(*this, m_conversationData->Actors[actorIdx].ActorGUID);
|
||||
}
|
||||
|
||||
Creature* Conversation::GetActorCreature(uint32 actorIdx) const
|
||||
{
|
||||
Unit* actor = GetActorUnit(actorIdx);
|
||||
if (!actor)
|
||||
return nullptr;
|
||||
return actor->ToCreature();
|
||||
}
|
||||
|
||||
uint32 Conversation::GetScriptId() const
|
||||
{
|
||||
return sConversationDataStore->GetConversationTemplate(GetEntry())->ScriptId;
|
||||
|
||||
@@ -78,6 +78,12 @@ class TC_GAME_API Conversation : public WorldObject, public GridObject<Conversat
|
||||
|
||||
Milliseconds const* GetLineStartTime(LocaleConstant locale, int32 lineId) const;
|
||||
Milliseconds GetLastLineEndTime(LocaleConstant locale) const;
|
||||
static int32 GetLineDuration(LocaleConstant locale, int32 lineId);
|
||||
Milliseconds GetLineEndTime(LocaleConstant locale, int32 lineId) const;
|
||||
|
||||
LocaleConstant GetPrivateObjectOwnerLocale() const;
|
||||
Unit* GetActorUnit(uint32 actorIdx) const;
|
||||
Creature* GetActorCreature(uint32 actorIdx) const;
|
||||
|
||||
uint32 GetScriptId() const;
|
||||
|
||||
|
||||
@@ -436,8 +436,6 @@ public:
|
||||
if (!mathiasClone || !vanessaClone)
|
||||
return;
|
||||
|
||||
_vanessaGUID = vanessaClone->GetGUID();
|
||||
_mathiasGUID = mathiasClone->GetGUID();
|
||||
mathiasClone->RemoveNpcFlag(NPCFlags(UNIT_NPC_FLAG_GOSSIP | UNIT_NPC_FLAG_QUESTGIVER));
|
||||
vanessaClone->RemoveNpcFlag(NPCFlags(UNIT_NPC_FLAG_GOSSIP | UNIT_NPC_FLAG_QUESTGIVER));
|
||||
vanessaClone->SetVirtualItem(1, vanessaClone->GetVirtualItemId(0)); // add 2nd dagger to hands
|
||||
@@ -449,9 +447,7 @@ public:
|
||||
|
||||
void OnConversationStart(Conversation* conversation) override
|
||||
{
|
||||
LocaleConstant privateOwnerLocale = LOCALE_enUS;
|
||||
if (Player* owner = ObjectAccessor::GetPlayer(*conversation, conversation->GetPrivateObjectOwner()))
|
||||
privateOwnerLocale = owner->GetSession()->GetSessionDbLocaleIndex();
|
||||
LocaleConstant privateOwnerLocale = conversation->GetPrivateObjectOwnerLocale();
|
||||
|
||||
if (Milliseconds const* teleportLineStartTime = conversation->GetLineStartTime(privateOwnerLocale, CONVO_LINE_VANESSA_TELEPORT))
|
||||
_events.ScheduleEvent(EVENT_VANESSA_TELEPORT, *teleportLineStartTime);
|
||||
@@ -477,7 +473,7 @@ public:
|
||||
if (!privateObjectOwner)
|
||||
break;
|
||||
|
||||
Creature* vanessaClone = ObjectAccessor::GetCreature(*conversation, _vanessaGUID);
|
||||
Creature* vanessaClone = conversation->GetActorCreature(CONVO_ACTOR_IDX_VANESSA);
|
||||
if (!vanessaClone)
|
||||
break;
|
||||
|
||||
@@ -489,7 +485,7 @@ public:
|
||||
}
|
||||
case EVENT_VANESSA_MOVE:
|
||||
{
|
||||
Creature* vanessaClone = ObjectAccessor::GetCreature(*conversation, _vanessaGUID);
|
||||
Creature* vanessaClone = conversation->GetActorCreature(CONVO_ACTOR_IDX_VANESSA);
|
||||
if (!vanessaClone)
|
||||
break;
|
||||
|
||||
@@ -504,11 +500,11 @@ public:
|
||||
if (!privateObjectOwner)
|
||||
break;
|
||||
|
||||
Creature* vanessaClone = ObjectAccessor::GetCreature(*conversation, _vanessaGUID);
|
||||
Creature* vanessaClone = conversation->GetActorCreature(CONVO_ACTOR_IDX_VANESSA);
|
||||
if (!vanessaClone)
|
||||
break;
|
||||
|
||||
Creature* mathiasClone = ObjectAccessor::GetCreature(*conversation, _mathiasGUID);
|
||||
Creature* mathiasClone = conversation->GetActorCreature(CONVO_ACTOR_IDX_MATHIAS);
|
||||
if (!mathiasClone)
|
||||
break;
|
||||
|
||||
@@ -519,7 +515,7 @@ public:
|
||||
}
|
||||
case EVENT_MATHIAS_CLONE_DESPAWN:
|
||||
{
|
||||
Creature* mathiasClone = ObjectAccessor::GetCreature(*conversation, _mathiasGUID);
|
||||
Creature* mathiasClone = conversation->GetActorCreature(CONVO_ACTOR_IDX_MATHIAS);
|
||||
if (!mathiasClone)
|
||||
break;
|
||||
|
||||
@@ -532,8 +528,6 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
ObjectGuid _vanessaGUID;
|
||||
ObjectGuid _mathiasGUID;
|
||||
EventMap _events;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user