Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PlayerBot] Initial implementation of playerbots #192

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ option(BUILD_TOOLS "Build the map/vmap/mmap extractors" ON)
option(USE_STORMLIB "Use StormLib for reading MPQs" ON)
option(SCRIPT_LIB_ELUNA "Compile with support for Eluna scripts" ON)
option(SCRIPT_LIB_SD3 "Compile with support for ScriptDev3 scripts" ON)
option(PLAYERBOTS "Enable Player Bots" OFF)
option(PLAYERBOTS "Enable Player Bots" ON)
option(SOAP "Enable remote access via SOAP" OFF)
option(PCH "Enable precompiled headers" ON)
option(DEBUG "Enable debug build (only on non IDEs)" OFF)
Expand Down
4 changes: 2 additions & 2 deletions dockercontainer/DockerFile-mangosd
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ RUN mkdir /mangoserver/build
WORKDIR /mangoserver/build

#Install mangos
RUN cmake .. -DCMAKE_INSTALL_PREFIX=/mangos -DBUILD_MANGOSD=1 -DBUILD_REALMD=0 -DBUILD_TOOLS=0
RUN cmake .. -DCMAKE_INSTALL_PREFIX=/mangos -DBUILD_MANGOSD=1 -DBUILD_REALMD=0 -DBUILD_TOOLS=0 -DPLAYERBOTS=0
RUN make -j4
RUN make install

Expand All @@ -25,7 +25,7 @@ RUN apt-get -y update && apt-get -y upgrade
RUN apt-get -y install libmysqlclient20 openssl

COPY --from=build-step /mangos /mangos
COPY --from=build-step /etc/mangosd.conf.dist ../etc/mangosd.conf.dist
COPY --from=build-step /etc/*.conf.dist /mangos/etc/
WORKDIR /mangos/bin
RUN chmod +x mangosd

Expand Down
1 change: 0 additions & 1 deletion src/game/AuctionHouseBot/AuctionHouseBot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,6 @@ void AuctionBotBuyer::PrepareListOfEntry(AHB_Buyer_Config& config)

bool AuctionBotBuyer::IsBuyableEntry(uint32 buyoutPrice, double InGame_BuyPrice, double MaxBuyablePrice, uint32 MinBuyPrice, uint32 MaxChance, uint32 ChanceRatio)
{
double ratio = 0;
uint32 Chance = 0;

if (buyoutPrice <= MinBuyPrice)
Expand Down
99 changes: 1 addition & 98 deletions src/game/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,94 +92,6 @@ if(SCRIPT_LIB_ELUNA)
source_group("Eluna" FILES ${SRC_GRP_ELUNA})
endif()

if(PLAYERBOTS)

#Base files
file(GLOB Playerbot_Source ${CMAKE_SOURCE_DIR}/src/modules/Bots/playerbot/*.cpp ${CMAKE_SOURCE_DIR}/src/modules/Bots/playerbot/*.h)
source_group("Player Bot" FILES ${Playerbot_Source})
file(GLOB AHbot_Source ${CMAKE_SOURCE_DIR}/src/modules/Bots/ahbot/*.cpp ${CMAKE_SOURCE_DIR}/src/modules/Bots/ahbot/*.h)
source_group("AH Bot" FILES ${AHbot_Source})

set(SRC_GRP_BOTS
${Playerbot_Source}
${AHbot_Source}
)
#Strategy files
file(GLOB Playerbot_Strategy ${CMAKE_SOURCE_DIR}/src/modules/Bots/playerbot/strategy/*.cpp ${CMAKE_SOURCE_DIR}/src/modules/Bots/playerbot/strategy/*.h)
source_group("Player Bot\\Strategies" FILES ${Playerbot_Strategy})
LIST(APPEND SRC_GRP_BOTS ${Playerbot_Strategy})

#Action files
file(GLOB Playerbot_Actions ${CMAKE_SOURCE_DIR}/src/modules/Bots/playerbot/strategy/actions/*.cpp ${CMAKE_SOURCE_DIR}/src/modules/Bots/playerbot/strategy/actions/*.h)
source_group("Player Bot\\Strategies\\Actions" FILES ${Playerbot_Actions})
LIST(APPEND SRC_GRP_BOTS ${Playerbot_Actions})

#Generic files
file(GLOB Playerbot_Generic ${CMAKE_SOURCE_DIR}/src/modules/Bots/playerbot/strategy/generic/*.cpp ${CMAKE_SOURCE_DIR}/src/modules/Bots/playerbot/strategy/generic/*.h)
source_group("Player Bot\\Strategies\\Generic" FILES ${Playerbot_Generic})
LIST(APPEND SRC_GRP_BOTS ${Playerbot_Generic})

#Trigger files
file(GLOB Playerbot_Triggers ${CMAKE_SOURCE_DIR}/src/modules/Bots/playerbot/strategy/triggers/*.cpp ${CMAKE_SOURCE_DIR}/src/modules/Bots/playerbot/strategy/triggers/*.h)
source_group("Player Bot\\Strategies\\Triggers" FILES ${Playerbot_Triggers})
LIST(APPEND SRC_GRP_BOTS ${Playerbot_Triggers})


#Value files
file(GLOB Playerbot_Values ${CMAKE_SOURCE_DIR}/src/modules/Bots/playerbot/strategy/values/*.cpp ${CMAKE_SOURCE_DIR}/src/modules/Bots/playerbot/strategy/values/*.h)
source_group("Player Bot\\Strategies\\Values" FILES ${Playerbot_Values})
LIST(APPEND SRC_GRP_BOTS ${Playerbot_Values})

## Class files
#Druid AI
file(GLOB Playerbot_Druid ${CMAKE_SOURCE_DIR}/src/modules/Bots/playerbot/strategy/druid/*.cpp ${CMAKE_SOURCE_DIR}/src/modules/Bots/playerbot/strategy/druid/*.h)
source_group("Player Bot\\Strategies\\Druid" FILES ${Playerbot_Druid})
LIST(APPEND SRC_GRP_BOTS ${Playerbot_Druid})

#Hunter AI
file(GLOB Playerbot_Hunter ${CMAKE_SOURCE_DIR}/src/modules/Bots/playerbot/strategy/hunter/*.cpp ${CMAKE_SOURCE_DIR}/src/modules/Bots/playerbot/strategy/hunter/*.h)
source_group("Player Bot\\Strategies\\Hunter" FILES ${Playerbot_Hunter})
LIST(APPEND SRC_GRP_BOTS ${Playerbot_Hunter})

#Mage AI
file(GLOB Playerbot_Mage ${CMAKE_SOURCE_DIR}/src/modules/Bots/playerbot/strategy/mage/*.cpp ${CMAKE_SOURCE_DIR}/src/modules/Bots/playerbot/strategy/mage/*.h)
source_group("Player Bot\\Strategies\\Mage" FILES ${Playerbot_Mage})
LIST(APPEND SRC_GRP_BOTS ${Playerbot_Mage})

#Paladin AI
file(GLOB Playerbot_Paladin ${CMAKE_SOURCE_DIR}/src/modules/Bots/playerbot/strategy/paladin/*.cpp ${CMAKE_SOURCE_DIR}/src/modules/Bots/playerbot/strategy/paladin/*.h)
source_group("Player Bot\\Strategies\\Paladin" FILES ${Playerbot_Paladin})
LIST(APPEND SRC_GRP_BOTS ${Playerbot_Paladin})

#Priest AI
file(GLOB Playerbot_Priest ${CMAKE_SOURCE_DIR}/src/modules/Bots/playerbot/strategy/priest/*.cpp ${CMAKE_SOURCE_DIR}/src/modules/Bots/playerbot/strategy/priest/*.h)
source_group("Player Bot\\Strategies\\Priest" FILES ${Playerbot_Priest})
LIST(APPEND SRC_GRP_BOTS ${Playerbot_Priest})

#Rogue AI
file(GLOB Playerbot_Rogue ${CMAKE_SOURCE_DIR}/src/modules/Bots/playerbot/strategy/rogue/*.cpp ${CMAKE_SOURCE_DIR}/src/modules/Bots/playerbot/strategy/rogue/*.h)
source_group("Player Bot\\Strategies\\Rogue" FILES ${Playerbot_Rogue})
LIST(APPEND SRC_GRP_BOTS ${Playerbot_Rogue})

#Shaman AI
file(GLOB Playerbot_Shaman ${CMAKE_SOURCE_DIR}/src/modules/Bots/playerbot/strategy/shaman/*.cpp ${CMAKE_SOURCE_DIR}/src/modules/Bots/playerbot/strategy/shaman/*.h)
source_group("Player Bot\\Strategies\\Shaman" FILES ${Playerbot_Shaman})
LIST(APPEND SRC_GRP_BOTS ${Playerbot_Shaman})

#Warlock AI
file(GLOB Playerbot_Warlock ${CMAKE_SOURCE_DIR}/src/modules/Bots/playerbot/strategy/warlock/*.cpp ${CMAKE_SOURCE_DIR}/src/modules/Bots/playerbot/strategy/warlock/*.h)
source_group("Player Bot\\Strategies\\Warlock" FILES ${Playerbot_Warlock})
LIST(APPEND SRC_GRP_BOTS ${Playerbot_Warlock})

#Warrior AI
file(GLOB Playerbot_Warrior ${CMAKE_SOURCE_DIR}/src/modules/Bots/playerbot/strategy/warrior/*.cpp ${CMAKE_SOURCE_DIR}/src/modules/Bots/playerbot/strategy/warrior/*.h)
source_group("Player Bot\\Strategies\\Warrior" FILES ${Playerbot_Warrior})
LIST(APPEND SRC_GRP_BOTS ${Playerbot_Warrior})

configure_file(${CMAKE_SOURCE_DIR}/src/modules/Bots/playerbot/aiplayerbot.conf.dist.in ${CMAKE_CURRENT_BINARY_DIR}/aiplayerbot.conf.dist)

endif()

configure_file(AuctionHouseBot/ahbot.conf.dist.in ${CMAKE_CURRENT_BINARY_DIR}/AuctionHouseBot/ahbot.conf.dist)

if(BUILD_TOOLS)
Expand Down Expand Up @@ -264,11 +176,6 @@ target_include_directories(game
${CMAKE_SOURCE_DIR}/src/modules/Eluna
${CMAKE_SOURCE_DIR}/src/modules/Eluna/Mangos
>
$<$<BOOL:${PLAYERBOTS}>:
${CMAKE_SOURCE_DIR}/src/modules/Bots
${CMAKE_SOURCE_DIR}/src/modules/Bots/playerbot
${CMAKE_SOURCE_DIR}/src/modules/Bots/ahbot
>
)

target_compile_definitions(game
Expand All @@ -287,6 +194,7 @@ target_link_libraries(game
g3dlite
$<$<BOOL:${SCRIPT_LIB_SD3}>:mangosscript>
$<$<BOOL:${SCRIPT_LIB_ELUNA}>:lualib>
$<$<BOOL:${PLAYERBOTS}>:bots>
)

# Generate precompiled header
Expand All @@ -304,9 +212,4 @@ install(
DIRECTORY ${CMAKE_SOURCE_DIR}/src/modules/Eluna/extensions
DESTINATION ${BIN_DIR}/lua_scripts
)
endif()

if(PLAYERBOTS)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/aiplayerbot.conf.dist
DESTINATION ${CONF_INSTALL_DIR})
endif()
2 changes: 1 addition & 1 deletion src/game/ChatCommands/RACommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ bool ChatHandler::HandleQuitCommand(char* /*args*/)
// processed in RASocket
SendSysMessage(LANG_QUIT_WRONG_USE_ERROR);
return true;
}
}
7 changes: 7 additions & 0 deletions src/game/Object/Item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,13 @@ bool Item::IsLimitedToAnotherMapOrZone(uint32 cur_mapId, uint32 cur_zoneId) cons
// time.
void Item::SendTimeUpdate(Player* owner)
{
#ifdef ENABLE_PLAYERBOTS
if (!owner || !owner->IsInWorld() || owner->GetPlayerbotAI())
{
return;
}
#endif

uint32 duration = GetUInt32Value(ITEM_FIELD_DURATION);
if (!duration)
{
Expand Down
40 changes: 40 additions & 0 deletions src/game/Object/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@
#include "LuaEngine.h"
#endif /* ENABLE_ELUNA */

#ifdef ENABLE_PLAYERBOTS
#include "playerbot.h"
#endif

#include <cmath>

#define ZONE_UPDATE_INTERVAL (1*IN_MILLISECONDS)
Expand Down Expand Up @@ -438,6 +442,11 @@ UpdateMask Player::updateVisualBits;

Player::Player(WorldSession* session): Unit(), m_mover(this), m_camera(this), m_achievementMgr(this), m_reputationMgr(this)
{
#ifdef ENABLE_PLAYERBOTS
m_playerbotAI = 0;
m_playerbotMgr = 0;
#endif

m_transport = 0;

m_speakTime = 0;
Expand Down Expand Up @@ -629,6 +638,10 @@ Player::Player(WorldSession* session): Unit(), m_mover(this), m_camera(this), m_

m_lastFallTime = 0;
m_lastFallZ = 0;
#ifdef ENABLE_PLAYERBOTS
m_playerbotAI = NULL;
m_playerbotMgr = NULL;
#endif

m_cachedGS = 0;
}
Expand Down Expand Up @@ -670,6 +683,21 @@ Player::~Player()
delete ItemSetEff[x];
}

#ifdef ENABLE_PLAYERBOTS
if (m_playerbotAI) {
{
delete m_playerbotAI;
}
m_playerbotAI = 0;
}
if (m_playerbotMgr) {
{
delete m_playerbotMgr;
}
m_playerbotMgr = 0;
}
#endif

// clean up player-instance binds, may unload some instance saves
for (uint8 i = 0; i < MAX_DIFFICULTY; ++i)
for (BoundInstancesMap::iterator itr = m_boundInstances[i].begin(); itr != m_boundInstances[i].end(); ++itr)
Expand Down Expand Up @@ -1628,6 +1656,18 @@ void Player::Update(uint32 update_diff, uint32 p_time)
{
TeleportTo(m_teleport_dest, m_teleport_options);
}

#ifdef ENABLE_PLAYERBOTS
if (m_playerbotAI)
{
m_playerbotAI->UpdateAI(p_time);
}
if (m_playerbotMgr)
{
m_playerbotMgr->UpdateAI(p_time);
}
#endif

}

void Player::SetDeathState(DeathState s)
Expand Down
23 changes: 23 additions & 0 deletions src/game/Object/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ class Item;

struct AreaTrigger;

#ifdef ENABLE_PLAYERBOTS
class PlayerbotAI;
class PlayerbotMgr;
#endif

typedef std::deque<Mail*> PlayerMails;

#define PLAYER_MAX_SKILLS 127
Expand Down Expand Up @@ -1626,6 +1631,9 @@ class Player : public Unit
/*********************************************************/

bool LoadFromDB(ObjectGuid guid, SqlQueryHolder* holder);
#ifdef ENABLE_PLAYERBOTS
bool MinimalLoadFromDB(QueryResult *result, uint32 guid);
#endif

static uint32 GetZoneIdFromDB(ObjectGuid guid);
static uint32 GetLevelFromDB(ObjectGuid guid);
Expand Down Expand Up @@ -2628,6 +2636,17 @@ class Player : public Unit
void SetTitle(CharTitlesEntry const* title, bool lost = false);

bool canSeeSpellClickOn(Creature const* creature) const;

#ifdef ENABLE_PLAYERBOTS
//EquipmentSets& GetEquipmentSets() { return m_EquipmentSets; }
void SetPlayerbotAI(PlayerbotAI* ai) { assert(!m_playerbotAI && !m_playerbotMgr); m_playerbotAI = ai; }
PlayerbotAI* GetPlayerbotAI() { return m_playerbotAI; }
void SetPlayerbotMgr(PlayerbotMgr* mgr) { assert(!m_playerbotAI && !m_playerbotMgr); m_playerbotMgr = mgr; }
PlayerbotMgr* GetPlayerbotMgr() { return m_playerbotMgr; }
void SetBotDeathTimer() { m_deathTimer = 0; }
//PlayerTalentMap& GetTalentMap(uint8 spec) { return m_talents[spec]; }
#endif

protected:

uint32 m_contestedPvPTimer;
Expand Down Expand Up @@ -2908,6 +2927,10 @@ class Player : public Unit
GridReference<Player> m_gridRef;
MapReference m_mapRef;

#ifdef ENABLE_PLAYERBOTS
PlayerbotAI* m_playerbotAI;
PlayerbotMgr* m_playerbotMgr;
#endif
// Homebind coordinates
uint32 m_homebindMapId;
uint16 m_homebindAreaId;
Expand Down
Loading
Loading