Skip to content

Commit

Permalink
Playerbot: tag playerbot code
Browse files Browse the repository at this point in the history
Tag Playerbot code embedded in core for next steps by finding them
easily
  • Loading branch information
cala committed Jul 31, 2017
1 parent bab4d3c commit dca784a
Show file tree
Hide file tree
Showing 17 changed files with 150 additions and 57 deletions.
4 changes: 2 additions & 2 deletions src/game/Chat/Chat.cpp
Expand Up @@ -826,11 +826,11 @@ ChatCommand* ChatHandler::getCommandTable()
{ "repairitems", SEC_GAMEMASTER, true, &ChatHandler::HandleRepairitemsCommand, "", nullptr },
{ "stable", SEC_ADMINISTRATOR, false, &ChatHandler::HandleStableCommand, "", nullptr },
{ "waterwalk", SEC_GAMEMASTER, false, &ChatHandler::HandleWaterwalkCommand, "", nullptr },
//Playerbot mod
{ "bot", SEC_PLAYER, false, &ChatHandler::HandlePlayerbotCommand, "", nullptr },
{ "quit", SEC_CONSOLE, true, &ChatHandler::HandleQuitCommand, "", nullptr },
{ "gearscore", SEC_ADMINISTRATOR, false, &ChatHandler::HandleShowGearScoreCommand, "", nullptr },
{ "mmap", SEC_GAMEMASTER, false, nullptr, "", mmapCommandTable },
// ------ Playerbot mod ------ //
{ "bot", SEC_PLAYER, false, &ChatHandler::HandlePlayerbotCommand, "", nullptr },

{ nullptr, 0, false, nullptr, "", nullptr }
};
Expand Down
5 changes: 3 additions & 2 deletions src/game/Chat/Chat.h
Expand Up @@ -623,9 +623,10 @@ class ChatHandler
bool HandleRepairitemsCommand(char* args);
bool HandleStableCommand(char* args);
bool HandleWaterwalkCommand(char* args);
bool HandlePlayerbotCommand(char* args);
bool HandleQuitCommand(char* args);
bool HandleShowGearScoreCommand(char* args);
// ------ Playerbot mod ------ //
bool HandlePlayerbotCommand(char* args);

bool HandleMmapPathCommand(char* args);
bool HandleMmapLocCommand(char* args);
Expand Down Expand Up @@ -751,7 +752,7 @@ class CliHandler : public ChatHandler
AccountTypes m_loginAccessLevel;
Print m_print;

public:
public:
CliHandler(uint32 accountId, AccountTypes accessLevel, Print zprint)
: m_accountId(accountId), m_loginAccessLevel(accessLevel), m_print(zprint) {}

Expand Down
14 changes: 9 additions & 5 deletions src/game/Chat/ChatHandler.cpp
Expand Up @@ -35,8 +35,8 @@
#include "Grids/GridNotifiersImpl.h"
#include "Grids/CellImpl.h"

// Playerbot mod
#include "playerbot/PlayerbotAI.h"
// ------ Playerbot mod ------ //
#include "PlayerBot/PlayerbotAI.h"

bool WorldSession::processChatmessageFurtherAfterSecurityChecks(std::string& msg, uint32 lang)
{
Expand Down Expand Up @@ -228,15 +228,18 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recv_data)
}
}

// Playerbot mod: handle whispered command to bot
// ------ Playerbot mod ------ //
// Handle whispered command to bot
if (player->GetPlayerbotAI())
{
player->GetPlayerbotAI()->HandleCommand(msg, *GetPlayer());
GetPlayer()->m_speakTime = 0;
GetPlayer()->m_speakCount = 0;
}
else
// Unmodded core line code below
GetPlayer()->Whisper(msg, lang, player->GetObjectGuid());
// ---- End Playerbot mod ---- //
} break;

case CHAT_MSG_PARTY:
Expand Down Expand Up @@ -269,7 +272,8 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recv_data)
if ((type == CHAT_MSG_PARTY_LEADER) && !group->IsLeader(_player->GetObjectGuid()))
return;

// Playerbot mod: broadcast message to bot members
// ------ Playerbot mod ------ //
// Broadcast message to bot members
for(GroupReference* itr = group->GetFirstMember(); itr != nullptr; itr=itr->next())
{
Player* player = itr->getSource();
Expand All @@ -290,7 +294,7 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recv_data)
GetPlayer()->m_speakCount = 0;
}
}
// END Playerbot mod
// ---- End Playerbot mod ---- //

WorldPacket data;
ChatHandler::BuildChatPacket(data, ChatMsg(type), msg.c_str(), Language(lang), _player->GetChatTag(), _player->GetObjectGuid(), _player->GetName());
Expand Down
12 changes: 8 additions & 4 deletions src/game/Entities/CharacterHandler.cpp
Expand Up @@ -38,8 +38,8 @@
#include "Spells/SpellMgr.h"
#include "Calendar/Calendar.h"

// Playerbot mod:
#include "playerbot/PlayerbotMgr.h"
// ------ Playerbot mod ------ //
#include "PlayerBot/PlayerbotMgr.h"

// config option SkipCinematics supported values
enum CinematicsSkipMode
Expand Down Expand Up @@ -128,7 +128,8 @@ class CharacterHandler
if (WorldSession* session = sWorld.FindSession(((LoginQueryHolder*)holder)->GetAccountId()))
session->HandlePlayerLogin((LoginQueryHolder*)holder);
}
// Playerbot mod: is different from the normal HandlePlayerLoginCallback in that it
// ------ Playerbot mod ------ //
// This callback is different from the normal HandlePlayerLoginCallback in that it
// sets up the bot's world session and also stores the pointer to the bot player in the master's
// world session m_playerBots map
void HandlePlayerBotLoginCallback(QueryResult * /*dummy*/, SqlQueryHolder * holder)
Expand All @@ -152,6 +153,7 @@ class CharacterHandler
botSession->HandlePlayerLogin(lqh); // will delete lqh
masterSession->GetPlayer()->GetPlayerbotMgr()->OnBotLogin(botSession->GetPlayer());
}
// ---- End Playerbot mod ---- //
} chrHandler;

void WorldSession::HandleCharEnum(QueryResult* result)
Expand Down Expand Up @@ -591,7 +593,8 @@ void WorldSession::HandlePlayerLoginOpcode(WorldPacket& recv_data)
CharacterDatabase.DelayQueryHolder(&chrHandler, &CharacterHandler::HandlePlayerLoginCallback, holder);
}

// Playerbot mod. Can't easily reuse HandlePlayerLoginOpcode for logging in bots because it assumes
// ------ Playerbot mod ------ //
// Can't easily reuse HandlePlayerLoginOpcode for logging in bots because it assumes
// a WorldSession exists for the bot. The WorldSession for a bot is created after the character is loaded.
void PlayerbotMgr::LoginPlayerBot(ObjectGuid playerGuid)
{
Expand All @@ -611,6 +614,7 @@ void PlayerbotMgr::LoginPlayerBot(ObjectGuid playerGuid)
}
CharacterDatabase.DelayQueryHolder(&chrHandler, &CharacterHandler::HandlePlayerBotLoginCallback, holder);
}
// ---- End Playerbot mod ---- //

void WorldSession::HandlePlayerLogin(LoginQueryHolder* holder)
{
Expand Down
15 changes: 14 additions & 1 deletion src/game/Entities/Creature.h
Expand Up @@ -402,20 +402,32 @@ typedef std::list<VendorItemCount> VendorItemCounts;

struct TrainerSpell
{
// ------ Playerbot mod ------ //
TrainerSpell() : spell(0), spellCost(0), reqSkill(0), reqSkillValue(0), reqLevel(0), learnedSpell(0), isProvidedReqLevel(false), conditionId(0) {}

TrainerSpell(uint32 _spell, uint32 _spellCost, uint32 _reqSkill, uint32 _reqSkillValue, uint32 _reqLevel, uint32 _learnedspell, bool _isProvidedReqLevel, uint32 _conditionId)
: spell(_spell), spellCost(_spellCost), reqSkill(_reqSkill), reqSkillValue(_reqSkillValue), reqLevel(_reqLevel), learnedSpell(_learnedspell), isProvidedReqLevel(_isProvidedReqLevel), conditionId(_conditionId) {}

// Unmodded code below
/*
TrainerSpell() : spell(0), spellCost(0), reqSkill(0), reqSkillValue(0), reqLevel(0), isProvidedReqLevel(false), conditionId(0) {}
TrainerSpell(uint32 _spell, uint32 _spellCost, uint32 _reqSkill, uint32 _reqSkillValue, uint32 _reqLevel, bool _isProvidedReqLevel, uint32 _conditionId)
: spell(_spell), spellCost(_spellCost), reqSkill(_reqSkill), reqSkillValue(_reqSkillValue), reqLevel(_reqLevel), isProvidedReqLevel(_isProvidedReqLevel), conditionId(_conditionId) {}
*/
// ---- End Playerbot mod ---- //

uint32 spell;
uint32 spellCost;
uint32 reqSkill;
uint32 reqSkillValue;
uint32 reqLevel;
// ------ Playerbot mod ------ //
uint32 learnedSpell;
uint32 conditionId;
bool isProvidedReqLevel;

// ------ Playerbot mod ------ //
// helpers
bool IsCastable() const { return learnedSpell != spell; }
};
Expand Down Expand Up @@ -545,7 +557,8 @@ class Creature : public Unit
bool IsTotem() const { return m_subtype == CREATURE_SUBTYPE_TOTEM; }
bool IsTemporarySummon() const { return m_subtype == CREATURE_SUBTYPE_TEMPORARY_SUMMON; }

// Playerbot mod - adds functionality to load/unload bots from NPC, also need to apply SQL scripts
// ------ Playerbot mod ------ //
// Adds functionality to load/unload bots from NPC, also need to apply SQL scripts
void LoadBotMenu(Player *pPlayer);

bool IsCorpse() const { return getDeathState() == CORPSE; }
Expand Down
2 changes: 1 addition & 1 deletion src/game/Entities/GossipDef.h
Expand Up @@ -50,7 +50,7 @@ enum Gossip_Option
GOSSIP_OPTION_UNLEARNTALENTS = 16, // UNIT_NPC_FLAG_TRAINER (16) (bonus option for GOSSIP_OPTION_TRAINER)
GOSSIP_OPTION_UNLEARNPETSKILLS = 17, // UNIT_NPC_FLAG_TRAINER (16) (bonus option for GOSSIP_OPTION_TRAINER)
GOSSIP_OPTION_MAILBOX = 18, // UNIT_NPC_FLAG_GOSSIP (1)
// Playerbot mod
// ------ Playerbot mod ------ //
GOSSIP_OPTION_BOT = 99, //UNIT_NPC_FLAG_GOSSIP (1) UNUSED (just for bot system)
GOSSIP_OPTION_MAX
};
Expand Down
36 changes: 26 additions & 10 deletions src/game/Entities/Player.cpp
Expand Up @@ -67,10 +67,11 @@
#include "Calendar/Calendar.h"
#include "Loot/LootMgr.h"

// Playerbot mod:
#include "playerbot/PlayerbotAI.h"
#include "playerbot/PlayerbotMgr.h"
// ------ Playerbot mod ------ //
#include "PlayerBot/PlayerbotAI.h"
#include "PlayerBot/PlayerbotMgr.h"
#include "Config/Config.h"
// ---- End Playerbot mod ---- //

#include <cmath>

Expand All @@ -88,6 +89,7 @@
#define SKILL_PERM_BONUS(x) int16(PAIR32_HIPART(x))
#define MAKE_SKILL_BONUS(t, p) MAKE_PAIR32(t,p)

// ------ Playerbot mod ------ //
extern Config botConfig;

enum CharacterFlags
Expand Down Expand Up @@ -402,9 +404,10 @@ Player::Player(WorldSession* session): Unit(), m_mover(this), m_camera(this), m_
{
m_transport = nullptr;

// Playerbot mod:
// ------ Playerbot mod ------ //
m_playerbotAI = 0;
m_playerbotMgr = 0;
// ---- End Playerbot mod ---- //

m_speakTime = 0;
m_speakCount = 0;
Expand Down Expand Up @@ -628,15 +631,18 @@ Player::~Player()
delete m_declinedname;
delete m_runes;

// Playerbot mod
if (m_playerbotAI) {
// ------ Playerbot mod ------ //
if (m_playerbotAI)
{
delete m_playerbotAI;
m_playerbotAI = 0;
}
if (m_playerbotMgr) {
if (m_playerbotMgr)
{
delete m_playerbotMgr;
m_playerbotMgr = 0;
}
// ---- End Playerbot mod ---- //
}

void Player::CleanupsBeforeDelete()
Expand Down Expand Up @@ -1446,11 +1452,12 @@ void Player::Update(uint32 update_diff, uint32 p_time)
if (IsHasDelayedTeleport())
TeleportTo(m_teleport_dest, m_teleport_options);

// Playerbot mod
// ------ Playerbot mod ------ //
if (m_playerbotAI)
m_playerbotAI->UpdateAI(p_time);
else if (m_playerbotMgr)
m_playerbotMgr->UpdateAI(p_time);
// ---- End Playerbot mod ---- //
}

void Player::SetDeathState(DeathState s)
Expand Down Expand Up @@ -1706,10 +1713,12 @@ bool Player::TeleportTo(uint32 mapid, float x, float y, float z, float orientati

MapEntry const* mEntry = sMapStore.LookupEntry(mapid); // Validity checked in IsValidMapCoord

// Playerbot mod: if this user has bots, tell them to stop following master
// ------ Playerbot mod ------ //
// If this user has bots, tell them to stop following master
// so they don't try to follow the master after the master teleports
if (GetPlayerbotMgr())
GetPlayerbotMgr()->Stay();
// ---- End Playerbot mod ---- //

// don't let enter battlegrounds without assigned battleground id (for example through areatrigger)...
// don't let gm level > 1 either
Expand Down Expand Up @@ -12891,6 +12900,7 @@ void Player::PrepareGossipMenu(WorldObject* pSource, uint32 menuId)
case GOSSIP_OPTION_AUCTIONEER:
case GOSSIP_OPTION_MAILBOX:
break; // no checks
// ------ Playerbot mod ------ //
case GOSSIP_OPTION_BOT:
{
if(botConfig.GetBoolDefault("PlayerbotAI.DisableBots", false) && !pCreature->isInnkeeper())
Expand All @@ -12907,6 +12917,7 @@ void Player::PrepareGossipMenu(WorldObject* pSource, uint32 menuId)
hasMenuItem = false;
break;
}
// ---- End Playerbot mod ---- //
default:
sLog.outErrorDb("Creature entry %u have unknown gossip option %u for menu %u", pCreature->GetEntry(), gossipMenu.option_id, gossipMenu.menu_id);
hasMenuItem = false;
Expand Down Expand Up @@ -13061,11 +13072,13 @@ void Player::OnGossipSelect(WorldObject* pSource, uint32 gossipListId, uint32 me
return;
}
}

// ------ Playerbot mod ------ //
// GossipMenuItemData pMenuData = gossipmenu.GetItemData(gossipListId);
switch (gossipOptionId)
{
case GOSSIP_OPTION_GOSSIP:
{
// ------ Playerbot mod ------ //
GossipMenuItemData pMenuData = gossipmenu.GetItemData(gossipListId);

if (pMenuData.m_gAction_poi)
Expand Down Expand Up @@ -13153,6 +13166,7 @@ void Player::OnGossipSelect(WorldObject* pSource, uint32 gossipListId, uint32 me
GetSession()->SendBattlegGroundList(guid, bgTypeId);
break;
}
// ------ Playerbot mod ------ //
case GOSSIP_OPTION_BOT:
{
// DEBUG_LOG("GOSSIP_OPTION_BOT");
Expand Down Expand Up @@ -13206,8 +13220,10 @@ void Player::OnGossipSelect(WorldObject* pSource, uint32 gossipListId, uint32 me
}
return;
}
// ---- End Playerbot mod ---- //
}

// ------ Playerbot mod ------ //
GossipMenuItemData pMenuData = gossipmenu.GetItemData(gossipListId);

if (pMenuData.m_gAction_script)
Expand Down
16 changes: 10 additions & 6 deletions src/game/Entities/Player.h
Expand Up @@ -54,9 +54,10 @@ class DungeonPersistentState;
class Spell;
class Item;

// Playerbot mod
#include "playerbot/PlayerbotMgr.h"
#include "playerbot/PlayerbotAI.h"
// ------ Playerbot mod ------ //
#include "PlayerBot/PlayerbotMgr.h"
#include "PlayerBot/PlayerbotAI.h"
// ---- End Playerbot mod ---- //

struct AreaTrigger;

Expand Down Expand Up @@ -1447,7 +1448,7 @@ class Player : public Unit
void AddTimedQuest(uint32 quest_id) { m_timedquests.insert(quest_id); }
void RemoveTimedQuest(uint32 quest_id) { m_timedquests.erase(quest_id); }

// Playerbot mod
// ------ Playerbot mod ------ //
PlayerTalentMap GetTalents(uint8 spec) { return m_talents[spec]; }
void chompAndTrim(std::string& str);
bool getNextQuestId(const std::string& pString, unsigned int& pStartPos, unsigned int& pId);
Expand All @@ -1458,6 +1459,7 @@ class Player : public Unit
PlayerMails::reverse_iterator GetMailREnd() { return m_mail.rend();}
void UpdateMail();
uint32 GetSpec();
// ---- End Playerbot mod ---- //

//! Return collision height sent to client
float GetCollisionHeight(bool mounted) const;
Expand Down Expand Up @@ -2348,7 +2350,7 @@ class Player : public Unit

bool canSeeSpellClickOn(Creature const* creature) const;

// Playerbot mod:
// ------ Playerbot mod ------ //
// A Player can either have a playerbotMgr (to manage its bots), or have playerbotAI (if it is a bot), or
// neither. Code that enables bots must create the playerbotMgr and set it using SetPlayerbotMgr.
void SetPlayerbotAI(PlayerbotAI* ai) { assert(!m_playerbotAI && !m_playerbotMgr); m_playerbotAI=ai; }
Expand All @@ -2357,6 +2359,7 @@ class Player : public Unit
PlayerbotMgr* GetPlayerbotMgr() { return m_playerbotMgr; }
void SetBotDeathTimer() { m_deathTimer = 0; }
bool IsInDuel() const { return duel && duel->startTime != 0; }
// ---- End Playerbot mod ---- //

// function used for raise ally spell
bool IsGhouled() const { return m_isGhouled; }
Expand Down Expand Up @@ -2631,9 +2634,10 @@ class Player : public Unit
GridReference<Player> m_gridRef;
MapReference m_mapRef;

// Playerbot mod:
// ------ Playerbot mod ------ //
PlayerbotAI* m_playerbotAI;
PlayerbotMgr* m_playerbotMgr;
// ---- End Playerbot mod ---- //

// Homebind coordinates
uint32 m_homebindMapId;
Expand Down

0 comments on commit dca784a

Please sign in to comment.