Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
KamiliaBlow committed Dec 29, 2024
2 parents 3939394 + d913e38 commit 138adca
Show file tree
Hide file tree
Showing 51 changed files with 745 additions and 310 deletions.
19 changes: 19 additions & 0 deletions sql/updates/world/master/2024_12_29_00_world.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
UPDATE `trinity_string` SET `content_default`='├%.*s %dx |c%08x|Hitem:%d:0:0:0:0:0:0:0:0|h[%s]|h|r (#%05d)' WHERE `entry`=291;
UPDATE `trinity_string` SET `content_loc1`='├%.*s %dx |c%08x|Hitem:%d:0:0:0:0:0:0:0:0|h[%s]|h|r (#%05d)' WHERE `entry`=291 AND `content_loc1` IS NOT NULL;
UPDATE `trinity_string` SET `content_loc2`='├%.*s %dx |c%08x|Hitem:%d:0:0:0:0:0:0:0:0|h[%s]|h|r (#%05d)' WHERE `entry`=291 AND `content_loc2` IS NOT NULL;
UPDATE `trinity_string` SET `content_loc3`='├%.*s %dx |c%08x|Hitem:%d:0:0:0:0:0:0:0:0|h[%s]|h|r (#%05d)' WHERE `entry`=291 AND `content_loc3` IS NOT NULL;
UPDATE `trinity_string` SET `content_loc4`='├%.*s %dx |c%08x|Hitem:%d:0:0:0:0:0:0:0:0|h[%s]|h|r (#%05d)' WHERE `entry`=291 AND `content_loc4` IS NOT NULL;
UPDATE `trinity_string` SET `content_loc5`='├%.*s %dx |c%08x|Hitem:%d:0:0:0:0:0:0:0:0|h[%s]|h|r (#%05d)' WHERE `entry`=291 AND `content_loc5` IS NOT NULL;
UPDATE `trinity_string` SET `content_loc6`='├%.*s %dx |c%08x|Hitem:%d:0:0:0:0:0:0:0:0|h[%s]|h|r (#%05d)' WHERE `entry`=291 AND `content_loc6` IS NOT NULL;
UPDATE `trinity_string` SET `content_loc7`='├%.*s %dx |c%08x|Hitem:%d:0:0:0:0:0:0:0:0|h[%s]|h|r (#%05d)' WHERE `entry`=291 AND `content_loc7` IS NOT NULL;
UPDATE `trinity_string` SET `content_loc8`='├%.*s %dx |c%08x|Hitem:%d:0:0:0:0:0:0:0:0|h[%s]|h|r (#%05d)' WHERE `entry`=291 AND `content_loc8` IS NOT NULL;

UPDATE `trinity_string` SET `content_default`='├%.*s |cffffff00|Hquest:%u:0|h[%.*s]|h|r (#%05d)' WHERE `entry`=295;
UPDATE `trinity_string` SET `content_loc1`='├%.*s |cffffff00|Hquest:%u:0|h[%.*s]|h|r (#%05d)' WHERE `entry`=295 AND `content_loc1` IS NOT NULL;
UPDATE `trinity_string` SET `content_loc2`='├%.*s |cffffff00|Hquest:%u:0|h[%.*s]|h|r (#%05d)' WHERE `entry`=295 AND `content_loc2` IS NOT NULL;
UPDATE `trinity_string` SET `content_loc3`='├%.*s |cffffff00|Hquest:%u:0|h[%.*s]|h|r (#%05d)' WHERE `entry`=295 AND `content_loc3` IS NOT NULL;
UPDATE `trinity_string` SET `content_loc4`='├%.*s |cffffff00|Hquest:%u:0|h[%.*s]|h|r (#%05d)' WHERE `entry`=295 AND `content_loc4` IS NOT NULL;
UPDATE `trinity_string` SET `content_loc5`='├%.*s |cffffff00|Hquest:%u:0|h[%.*s]|h|r (#%05d)' WHERE `entry`=295 AND `content_loc5` IS NOT NULL;
UPDATE `trinity_string` SET `content_loc6`='├%.*s |cffffff00|Hquest:%u:0|h[%.*s]|h|r (#%05d)' WHERE `entry`=295 AND `content_loc6` IS NOT NULL;
UPDATE `trinity_string` SET `content_loc7`='├%.*s |cffffff00|Hquest:%u:0|h[%.*s]|h|r (#%05d)' WHERE `entry`=295 AND `content_loc7` IS NOT NULL;
UPDATE `trinity_string` SET `content_loc8`='├%.*s |cffffff00|Hquest:%u:0|h[%.*s]|h|r (#%05d)' WHERE `entry`=295 AND `content_loc8` IS NOT NULL;
6 changes: 3 additions & 3 deletions src/server/game/AI/CoreAI/AreaTriggerAI.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ class TC_GAME_API AreaTriggerAI

// Pass parameters between AI
virtual void DoAction([[maybe_unused]] int32 param) { }
virtual uint32 GetData([[maybe_unused]] uint32 id = 0) const { return 0; }
virtual uint32 GetData([[maybe_unused]] uint32 id) const { return 0; }
virtual void SetData([[maybe_unused]] uint32 id, [[maybe_unused]] uint32 value) { }
virtual void SetGUID([[maybe_unused]] ObjectGuid const& guid, [[maybe_unused]] int32 id = 0) { }
virtual ObjectGuid GetGUID([[maybe_unused]] int32 id = 0) const { return ObjectGuid::Empty; }
virtual void SetGUID([[maybe_unused]] ObjectGuid const& guid, [[maybe_unused]] int32 id) { }
virtual ObjectGuid GetGUID([[maybe_unused]] int32 id) const { return ObjectGuid::Empty; }

// Gets the id of the AI (script id)
uint32 GetId() const { return _scriptId; }
Expand Down
28 changes: 28 additions & 0 deletions src/server/game/AI/CoreAI/ConversationAI.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "Conversation.h"
#include "ConversationAI.h"

ConversationAI::ConversationAI(Conversation* c, uint32 scriptId) : _scriptId(scriptId ? scriptId : c->GetScriptId()), conversation(c)
{
ASSERT(_scriptId, "A ConversationAI was initialized with an invalid scriptId!");
}

ConversationAI::~ConversationAI()
{
}
73 changes: 73 additions & 0 deletions src/server/game/AI/CoreAI/ConversationAI.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef TRINITY_CONVERSATIONAI_H
#define TRINITY_CONVERSATIONAI_H

#include "Define.h"
#include "ObjectGuid.h"

class Conversation;
class Unit;
class Player;

class TC_GAME_API ConversationAI
{
uint32 _scriptId;

protected:
Conversation* const conversation;
public:
explicit ConversationAI(Conversation* c, uint32 scriptId = {});
virtual ~ConversationAI();

// Called when the Conversation has just been initialized, just before added to map
virtual void OnInitialize() {}

// Called when Conversation is created but not added to Map yet.
virtual void OnCreate([[maybe_unused]] Unit* creator) { }

// Called when Conversation is started
virtual void OnStart() { }

// Called when player sends CMSG_CONVERSATION_LINE_STARTED with valid conversation guid
virtual void OnLineStarted([[maybe_unused]] uint32 lineId, [[maybe_unused]] Player* sender) { }

// Called for each update tick
virtual void OnUpdate([[maybe_unused]] uint32 diff) { }

// Called when the Conversation is removed
virtual void OnRemove() { }

// Pass parameters between AI
virtual void DoAction([[maybe_unused]] int32 param) { }
virtual uint32 GetData([[maybe_unused]] uint32 id) const { return 0; }
virtual void SetData([[maybe_unused]] uint32 id, [[maybe_unused]] uint32 value) { }
virtual void SetGUID([[maybe_unused]] ObjectGuid const& guid, [[maybe_unused]] int32 id) { }
virtual ObjectGuid GetGUID([[maybe_unused]] int32 id) const { return ObjectGuid::Empty; }

// Gets the id of the AI (script id)
uint32 GetId() const { return _scriptId; }
};

class NullConversationAI final : public ConversationAI
{
public:
using ConversationAI::ConversationAI;
};

#endif
6 changes: 3 additions & 3 deletions src/server/game/AI/CoreAI/GameObjectAI.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ class TC_GAME_API GameObjectAI
virtual void Reset() { }

// Pass parameters between AI
virtual void DoAction(int32 /*param = 0 */) { }
virtual void SetGUID(ObjectGuid const& /*guid*/, int32 /*id = 0 */) { }
virtual ObjectGuid GetGUID(int32 /*id = 0 */) const { return ObjectGuid::Empty; }
virtual void DoAction([[maybe_unused]] int32 param) { }
virtual void SetGUID([[maybe_unused]] ObjectGuid const& guid, [[maybe_unused]] int32 id) { }
virtual ObjectGuid GetGUID([[maybe_unused]] int32 id) const { return ObjectGuid::Empty; }

static int32 Permissible(GameObject const* go);

Expand Down
10 changes: 5 additions & 5 deletions src/server/game/AI/CoreAI/UnitAI.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ class TC_GAME_API UnitAI
virtual void OnCharmed(bool isNew);

// Pass parameters between AI
virtual void DoAction(int32 /*param*/) { }
virtual uint32 GetData(uint32 /*id = 0*/) const { return 0; }
virtual void SetData(uint32 /*id*/, uint32 /*value*/) { }
virtual void SetGUID(ObjectGuid const& /*guid*/, int32 /*id*/ = 0) { }
virtual ObjectGuid GetGUID(int32 /*id*/ = 0) const { return ObjectGuid::Empty; }
virtual void DoAction([[maybe_unused]] int32 param) { }
virtual uint32 GetData([[maybe_unused]] uint32 id) const { return 0; }
virtual void SetData([[maybe_unused]] uint32 id, [[maybe_unused]] uint32 value) { }
virtual void SetGUID([[maybe_unused]] ObjectGuid const& guid, [[maybe_unused]] int32 id) { }
virtual ObjectGuid GetGUID([[maybe_unused]] int32 id) const { return ObjectGuid::Empty; }

// Select the best target (in <targetType> order) from the threat list that fulfill the following:
// - Not among the first <offset> entries in <targetType> order (or SelectTargetMethod::MaxThreat order,
Expand Down
27 changes: 27 additions & 0 deletions src/server/game/AI/CreatureAISelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@

#include "AreaTriggerAI.h"

#include "Conversation.h"
#include "ConversationAI.h"

#include "ScriptMgr.h"

namespace FactorySelector
Expand Down Expand Up @@ -187,4 +190,28 @@ namespace FactorySelector

return GetNullAreaTriggerAIScriptId();
}

static uint32 GetNullConversationAIScriptId()
{
return sObjectMgr->GetScriptId("NullConversationAI", false);
}

ConversationAI* SelectConversationAI(Conversation* conversation)
{
if (ConversationAI* ai = sScriptMgr->GetConversationAI(conversation))
return ai;

return new NullConversationAI(conversation, GetNullConversationAIScriptId());
}

uint32 GetSelectedAIId(Conversation const* conversation)
{
if (uint32 id = conversation->GetScriptId())
{
if (sScriptMgr->CanCreateConversationAI(id))
return id;
}

return GetNullConversationAIScriptId();
}
}
4 changes: 4 additions & 0 deletions src/server/game/AI/CreatureAISelector.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,21 @@ class GameObjectAI;
class GameObject;
class AreaTriggerAI;
class AreaTrigger;
class Conversation;
class ConversationAI;

namespace FactorySelector
{
TC_GAME_API CreatureAI* SelectAI(Creature* creature);
TC_GAME_API MovementGenerator* SelectMovementGenerator(Unit* unit);
TC_GAME_API GameObjectAI* SelectGameObjectAI(GameObject* go);
TC_GAME_API AreaTriggerAI* SelectAreaTriggerAI(AreaTrigger* at);
TC_GAME_API ConversationAI* SelectConversationAI(Conversation* conversation);

TC_GAME_API uint32 GetSelectedAIId(Creature const* creature);
TC_GAME_API uint32 GetSelectedAIId(GameObject const* go);
TC_GAME_API uint32 GetSelectedAIId(AreaTrigger const* at);
TC_GAME_API uint32 GetSelectedAIId(Conversation const* conversation);
}

#endif
8 changes: 4 additions & 4 deletions src/server/game/AI/SmartScripts/SmartAI.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,20 +174,20 @@ class TC_GAME_API SmartAI : public CreatureAI
void OnCharmed(bool isNew) override;

// Used in scripts to share variables
void DoAction(int32 param = 0) override;
void DoAction(int32 param) override;

// Used in scripts to share variables
uint32 GetData(uint32 id = 0) const override;
uint32 GetData(uint32 id) const override;

// Used in scripts to share variables
void SetData(uint32 id, uint32 value) override { SetData(id, value, nullptr); }
void SetData(uint32 id, uint32 value, Unit* invoker);

// Used in scripts to share variables
void SetGUID(ObjectGuid const& guid, int32 id = 0) override;
void SetGUID(ObjectGuid const& guid, int32 id) override;

// Used in scripts to share variables
ObjectGuid GetGUID(int32 id = 0) const override;
ObjectGuid GetGUID(int32 id) const override;

// Makes the creature run/walk
void SetRun(bool run = true);
Expand Down
24 changes: 21 additions & 3 deletions src/server/game/Entities/Conversation/Conversation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
#include "Conversation.h"
#include "ConditionMgr.h"
#include "Containers.h"
#include "ConversationAI.h"
#include "ConversationDataStore.h"
#include "Creature.h"
#include "CreatureAISelector.h"
#include "DB2Stores.h"
#include "IteratorPair.h"
#include "Log.h"
Expand Down Expand Up @@ -61,14 +63,16 @@ void Conversation::RemoveFromWorld()
///- Remove the Conversation from the accessor and from all lists of objects in world
if (IsInWorld())
{
_ai->OnRemove();

WorldObject::RemoveFromWorld();
GetMap()->GetObjectsStore().Remove<Conversation>(GetGUID());
}
}

void Conversation::Update(uint32 diff)
{
sScriptMgr->OnConversationUpdate(this, diff);
_ai->OnUpdate(diff);

if (GetDuration() > Milliseconds(diff))
{
Expand Down Expand Up @@ -183,6 +187,8 @@ void Conversation::Create(ObjectGuid::LowType lowGuid, uint32 conversationEntry,
SetEntry(conversationEntry);
SetObjectScale(1.0f);

AI_Initialize();

_textureKitId = conversationTemplate->TextureKitId;

for (ConversationActorTemplate const& actor : conversationTemplate->Actors)
Expand Down Expand Up @@ -227,7 +233,7 @@ void Conversation::Create(ObjectGuid::LowType lowGuid, uint32 conversationEntry,
// conversations are despawned 5-20s after LastLineEndTime
_duration += 10s;

sScriptMgr->OnConversationCreate(this, creator);
_ai->OnCreate(creator);
}

bool Conversation::Start()
Expand Down Expand Up @@ -255,7 +261,7 @@ bool Conversation::Start()
if (!GetMap()->AddToMap(this))
return false;

sScriptMgr->OnConversationStart(this);
_ai->OnStart();
return true;
}

Expand Down Expand Up @@ -344,6 +350,18 @@ Creature* Conversation::GetActorCreature(uint32 actorIdx) const
return actor->ToCreature();
}

void Conversation::AI_Initialize()
{
AI_Destroy();
_ai.reset(FactorySelector::SelectConversationAI(this));
_ai->OnInitialize();
}

void Conversation::AI_Destroy()
{
_ai.reset();
}

uint32 Conversation::GetScriptId() const
{
return sConversationDataStore->GetConversationTemplate(GetEntry())->ScriptId;
Expand Down
7 changes: 7 additions & 0 deletions src/server/game/Entities/Conversation/Conversation.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "GridObject.h"
#include "Hash.h"

class ConversationAI;
class Unit;
class SpellInfo;
enum class ConversationActorType : uint32;
Expand Down Expand Up @@ -85,6 +86,10 @@ class TC_GAME_API Conversation final : public WorldObject, public GridObject<Con
Unit* GetActorUnit(uint32 actorIdx) const;
Creature* GetActorCreature(uint32 actorIdx) const;

void AI_Initialize();
void AI_Destroy();

ConversationAI* AI() { return _ai.get(); }
uint32 GetScriptId() const;

UF::UpdateField<UF::ConversationData, int32(WowCS::EntityFragment::CGObject), TYPEID_CONVERSATION> m_conversationData;
Expand All @@ -97,6 +102,8 @@ class TC_GAME_API Conversation final : public WorldObject, public GridObject<Con

std::unordered_map<std::pair<LocaleConstant /*locale*/, int32 /*lineId*/>, Milliseconds /*startTime*/> _lineStartTimes;
std::array<Milliseconds /*endTime*/, TOTAL_LOCALES> _lastLineEndTimes;

std::unique_ptr<ConversationAI> _ai;
};

#endif // TRINITYCORE_CONVERSATION_H
2 changes: 2 additions & 0 deletions src/server/game/Entities/Creature/GossipDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,13 @@ class InteractionData
SourceGuid.Clear();
TrainerId = 0;
PlayerChoiceId = 0;
IsLaunchedByQuest = false;
}

ObjectGuid SourceGuid;
uint32 TrainerId = 0;
uint32 PlayerChoiceId = 0;
bool IsLaunchedByQuest = false;
};

class TC_GAME_API PlayerMenu
Expand Down
Loading

0 comments on commit 138adca

Please sign in to comment.