diff --git a/src/modules/PlayerbotV2/PlayerbotV2Scripts.cpp b/src/modules/PlayerbotV2/PlayerbotV2Scripts.cpp index c982e1e1f9..4c959af8ae 100644 --- a/src/modules/PlayerbotV2/PlayerbotV2Scripts.cpp +++ b/src/modules/PlayerbotV2/PlayerbotV2Scripts.cpp @@ -1,12 +1,32 @@ // Playerbot V2 - script registration -// The module's lifecycle runs on WorldScript hooks: Init once the world is loaded (before the realm goes online), the -// tick before the maps update (bot worker threads read the maps, so the module must not tick while they update), and -// Shutdown with the world. AddSC_playerbot_v2 is called from the generated AddModuleScripts() (src/modules). +// The module hangs off ScriptMgr: every core event it reacts to arrives through a WorldScript / PlayerScript / +// UnitScript / GroupScript / GuildScript hook and is forwarded to the matching Module handler. AddSC_playerbot_v2 is +// called from the generated AddModuleScripts() (src/modules). +// +// Lifecycle: Init once the world is loaded (before the realm goes online), the tick before the maps update (bot +// worker threads read the maps, so the module must not tick while they update), Shutdown with the world. #include "PlayerbotV2.h" #include "Config.h" +#include "DB2Stores.h" +#include "Group.h" +#include "Guild.h" +#include "Item.h" #include "Log.h" +#include "Player.h" #include "ScriptMgr.h" +#include "SharedDefines.h" +#include "WorldSession.h" + +namespace +{ +using Playerbot::V2::Module; + +bool IsHuman(Player const* player) +{ + return player && player->GetSession() && !player->GetSession()->IsBot(); +} +} class playerbot_v2_world : public WorldScript { @@ -19,21 +39,194 @@ public: TC_LOG_INFO("server.worldserver", "[startup] bots: Population.TotalTarget={} Gear.MaxTier={} World.Enable={} Raid.Enable={}", value("Playerbot.Population.TotalTarget"), value("Playerbot.Gear.MaxTier"), value("Playerbot.World.Enable"), value("Playerbot.Raid.Enable")); - Playerbot::V2::Module::instance().Init(); + Module::instance().Init(); } void OnBeforeMapsUpdate(uint32 diff) override { - Playerbot::V2::Module::instance().OnWorldUpdate(std::chrono::milliseconds(diff)); + Module::instance().OnWorldUpdate(std::chrono::milliseconds(diff)); } void OnShutdown() override { - Playerbot::V2::Module::instance().Shutdown(); + Module::instance().Shutdown(); + } + + // A real player is about to take a place in a running battleground (a bot is leaving for them): no second instance + // is opened for this queue meanwhile. + bool CanCreateBattleground(uint32 battlemasterListId, uint8 bracketId) override + { + return !Module::instance().HoldNewBattleground(battlemasterListId, bracketId); + } +}; + +class playerbot_v2_player : public PlayerScript +{ +public: + playerbot_v2_player() : PlayerScript("playerbot_v2_player") { } + + void OnLogin(Player* player, bool /*firstLogin*/) override + { + Module::instance().OnPlayerLogin(player); + } + + void OnLogout(Player* player) override + { + Module::instance().OnPlayerLogout(player); + } + + void OnLevelChanged(Player* player, uint8 oldLevel) override + { + if (player->GetLevel() > oldLevel) + Module::instance().OnLevelUp(player, player->GetLevel()); + } + + // Owner's dead companions on this map release with the owner (inside a dungeon or raid RepopAtGraveyard revives the + // owner at the graveyard, so no ghost state ever tells them). Called before the repop teleport, on the death map. + void OnPlayerRepop(Player* player) override + { + Module::instance().OnSpiritReleased(player); + } + + // A nearby bot reciprocates a text emote; the reactor needs the animation the emote plays. + void OnTextEmote(Player* player, uint32 textEmote, uint32 /*emoteNum*/, ObjectGuid guid) override + { + if (EmotesTextEntry const* em = sEmotesTextStore.LookupEntry(textEmote)) + Module::instance().OnTextEmote(player, em->EmoteID, textEmote, guid); + } + + void OnChatSent(Player* player, uint32 type, uint32 /*lang*/, std::string const& msg) override + { + if (type == CHAT_MSG_SAY) + Module::instance().OnSayChat(player, msg); + else if (type == CHAT_MSG_YELL) + Module::instance().OnYellChat(player, msg); + } + + void OnChatSent(Player* player, uint32 /*type*/, uint32 /*lang*/, std::string const& msg, Player* receiver) override + { + Module::instance().OnWhisperReceived(player, receiver, msg); + } + + // Squad commands and bot chatter in party, raid and instance chat (not raid warnings). + void OnChatSent(Player* player, uint32 type, uint32 /*lang*/, std::string const& msg, Group* group) override + { + switch (type) + { + case CHAT_MSG_PARTY: + case CHAT_MSG_PARTY_LEADER: + case CHAT_MSG_RAID: + case CHAT_MSG_RAID_LEADER: + case CHAT_MSG_INSTANCE_CHAT: + case CHAT_MSG_INSTANCE_CHAT_LEADER: + Module::instance().OnPartyChat(player, group, msg); + break; + default: + break; + } + } + + void OnChatSent(Player* player, uint32 type, uint32 /*lang*/, std::string const& msg, Guild* guild) override + { + if (type == CHAT_MSG_GUILD) + Module::instance().OnGuildChat(player, guild->GetId(), msg); + } + + // The ForeverBots add-on whispers a bot this way in battlegrounds, where the client's own /whisper does nothing. + void OnAddonMessageSent(Player* player, uint32 /*type*/, std::string const& prefix, std::string const& text, Player* receiver) override + { + Module::instance().OnAddonWhisper(player, receiver, prefix, text); + } + + // The ForeverBots panel sends its bot orders as addon messages (addon chat is blocked in combat and battlegrounds). + void OnAddonMessageSent(Player* player, uint32 /*type*/, std::string const& prefix, std::string const& text, Group* group) override + { + Module::instance().OnAddonOrder(player, group, prefix, text); + } + + void OnLootItem(Player* player, Item* item) override + { + Module::instance().OnItemLooted(player, item->GetEntry()); + } + + // A real player (or the group they lead) joined a battleground queue: bots fill the free slots. + void OnBattlegroundQueueJoin(Player* player, uint32 bgTypeId, uint8 bracketId) override + { + if (IsHuman(player)) + Module::instance().OnPlayerJoinedBgQueue(player, bgTypeId, bracketId); + } + + // Bots port within the tick the invite is sent (the snapshot poll can miss the accept window under load). + void OnBattlegroundInvite(Player* player, uint32 instanceId, uint32 bgTypeId) override + { + Module::instance().OnBGInvitationReceived(player, instanceId, bgTypeId); + } + + void OnBattlegroundPortFailed(Player* player, uint8 reason, uint32 instanceId) override + { + Module::instance().OnBGPortFailed(player, reason, instanceId); + } + + // A real player joined the dungeon finder: bots fill the remaining roles. + void OnLfgJoin(Player* player, uint32 dungeonId, uint8 roles) override + { + if (IsHuman(player)) + Module::instance().OnPlayerJoinedLfg(player, dungeonId, roles); + } + + // Bots accept a proposal well inside the proposal time instead of waiting for the snapshot poll. + void OnLfgProposal(Player* player, uint32 proposalId) override + { + Module::instance().OnLfgProposalReceived(player, proposalId); + } +}; + +class playerbot_v2_unit : public UnitScript +{ +public: + playerbot_v2_unit() : UnitScript("playerbot_v2_unit") { } + + void OnDamage(Unit* attacker, Unit* victim, uint32& damage) override + { + Module::instance().OnDamageTaken(attacker, victim, int32(damage), 0); + } + + // Auto-loot for bots on the tap list, and a bot's own death. + void OnUnitDeath(Unit* victim, Unit* killer) override + { + Module::instance().OnDeath(victim, killer); + } +}; + +class playerbot_v2_group : public GroupScript +{ +public: + playerbot_v2_group() : GroupScript("playerbot_v2_group") { } + + void OnSubgroupChange(Group* group, ObjectGuid guid, uint8 subgroup) override + { + Module::instance().OnRaidSubgroupChanged(group, guid, subgroup); + } +}; + +class playerbot_v2_guild : public GuildScript +{ +public: + playerbot_v2_guild() : GuildScript("playerbot_v2_guild") { } + + // One online bot guildmate drops a welcome line a few seconds later. + void OnAddMember(Guild* guild, Player* player, uint8 /*plRank*/) override + { + if (player) + Module::instance().OnGuildMemberAdded(guild->GetId(), player->GetGUID(), player->GetName()); } }; void AddSC_playerbot_v2() { new playerbot_v2_world(); + new playerbot_v2_player(); + new playerbot_v2_unit(); + new playerbot_v2_group(); + new playerbot_v2_guild(); } diff --git a/src/server/game/Battlegrounds/BattlegroundQueue.cpp b/src/server/game/Battlegrounds/BattlegroundQueue.cpp index 1b9b1dddd0..4bf10164f1 100644 --- a/src/server/game/Battlegrounds/BattlegroundQueue.cpp +++ b/src/server/game/Battlegrounds/BattlegroundQueue.cpp @@ -28,16 +28,12 @@ #include "Log.h" #include "ObjectAccessor.h" #include "Player.h" +#include "ScriptMgr.h" #include "World.h" #include "WorldSession.h" #include #include -// PlayerbotV2: synchronous BG-invite hook so bots port within the same world -// tick the invite is sent (otherwise the snapshot-poll fallback can miss the -// 90s INVITE_ACCEPT_WAIT_TIME under load and only the fastest 5-6 bots port). -#include "Playerbot/PlayerbotHooks.h" - /*********************************************************/ /*** BATTLEGROUND QUEUE SYSTEM ***/ /*********************************************************/ @@ -509,10 +505,7 @@ bool BattlegroundQueue::InviteGroupToBG(GroupQueueInfo* ginfo, Battleground* bg, BattlegroundMgr::BuildBattlegroundStatusNeedConfirmation(&battlefieldStatus, bg, player, queueSlot, player->GetBattlegroundQueueJoinTime(bgQueueTypeId), INVITE_ACCEPT_WAIT_TIME, bgQueueTypeId); player->SendDirectMessage(battlefieldStatus.Write()); - // PlayerbotV2 path: pushes a BgPortIntent into the bot's intent - // queue immediately (idempotent for non-bots; inline no-op when - // V2 not built). - Playerbot::Hooks::OnBGInvitationReceived(player, bg->GetInstanceID(), bg->GetTypeID()); + sScriptMgr->OnPlayerBattlegroundInvite(player, bg->GetInstanceID(), bg->GetTypeID()); } return true; } @@ -929,9 +922,7 @@ void BattlegroundQueue::BattlegroundQueueUpdate(uint32 /*diff*/, BattlegroundBra // finished iterating through the bgs with free slots, maybe we need to create a new bg - // PlayerbotV2: a real player is about to take a place in a running battleground (a bot is leaving for them): do not - // open a second instance for this queue meanwhile. - if (!bg_template->IsArena() && Playerbot::Hooks::HoldNewBattleground(m_queueId.BattlemasterListId, uint8(bracket_id))) + if (!bg_template->IsArena() && !sScriptMgr->CanCreateBattleground(m_queueId.BattlemasterListId, uint8(bracket_id))) return; // get the min. players per team, properly for larger arenas as well. (must have full teams for arena matches!) @@ -1147,10 +1138,7 @@ bool BGQueueInviteEvent::Execute(uint64 /*e_time*/, uint32 /*p_time*/) BattlegroundMgr::BuildBattlegroundStatusNeedConfirmation(&battlefieldStatus, bg, player, queueSlot, player->GetBattlegroundQueueJoinTime(m_QueueId), INVITE_ACCEPT_WAIT_TIME - INVITATION_REMIND_TIME, m_QueueId); player->SendDirectMessage(battlefieldStatus.Write()); - // PlayerbotV2: reminder-event re-fire — handler is idempotent - // (the per-bot BgPort cooldown stamped on first invite suppresses - // duplicate intent emission within the 5s window). - Playerbot::Hooks::OnBGInvitationReceived(player, m_BgInstanceGUID, m_BgTypeId); + sScriptMgr->OnPlayerBattlegroundInvite(player, m_BgInstanceGUID, m_BgTypeId); } } return true; //event will be deleted diff --git a/src/server/game/DungeonFinding/LFGMgr.cpp b/src/server/game/DungeonFinding/LFGMgr.cpp index e125a4f834..cfae337a15 100644 --- a/src/server/game/DungeonFinding/LFGMgr.cpp +++ b/src/server/game/DungeonFinding/LFGMgr.cpp @@ -16,7 +16,7 @@ */ #include "LFGMgr.h" -#include "Playerbot/PlayerbotHooks.h" +#include "ScriptMgr.h" #include "DatabaseEnv.h" #include "DB2Stores.h" #include "DisableMgr.h" @@ -369,11 +369,8 @@ void LFGMgr::Update(uint32 diff) else SendLfgUpdateStatus(guid, LfgUpdateData(LFG_UPDATETYPE_PROPOSAL_BEGIN, GetSelectedDungeons(guid)), false); SendLfgUpdateProposal(guid, proposal); - // PlayerbotV2: auto-accept hook for bots — synchronous push of a - // deferred LfgProposalRespondIntent so all 5 (or 25) bots ack - // well inside LFG_TIME_PROPOSAL without waiting for snapshot poll. if (Player* candidate = ObjectAccessor::FindConnectedPlayer(guid)) - Playerbot::Hooks::OnLfgProposalReceived(candidate, proposalId); + sScriptMgr->OnPlayerLfgProposal(candidate, proposalId); } if (proposal.state == LFG_PROPOSAL_SUCCESS) diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index b31f40cfd8..21e22edec4 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -111,7 +111,6 @@ #include "PetitionMgr.h" #include "PhasingHandler.h" #include "PlayerChoice.h" -#include "Playerbot/PlayerbotHooks.h" #include "QueryCallback.h" #include "QueryHolder.h" #include "QueryResultStructured.h" @@ -2361,9 +2360,6 @@ void Player::GiveLevel(uint8 level) sScriptMgr->OnPlayerLevelChanged(this, oldLevel); - if (level > oldLevel) - Playerbot::Hooks::OnLevelUp(this, level); - BattlenetPresence::OnCharacterChanged(this); } @@ -28237,7 +28233,7 @@ void Player::StoreLootItem(ObjectGuid lootWorldObjectGuid, uint8 lootSlot, Loot* Item* newitem = StoreNewItem(dest, item->itemid, true, item->randomBonusListId, item->GetAllowedLooters(), item->context); if (newitem) - Playerbot::Hooks::OnItemLooted(this, item->itemid); + sScriptMgr->OnPlayerLootItem(this, newitem); if (newitem && (newitem->GetQuality() > ITEM_QUALITY_EPIC || (newitem->GetQuality() == ITEM_QUALITY_EPIC && newitem->GetItemLevel(this) >= MinNewsItemLevel))) if (Guild* guild = GetGuild()) diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index 056f73a1e5..e8cfaa430c 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -97,7 +97,6 @@ #include "World.h" #include "WorldPacket.h" #include "WorldSession.h" -#include "Playerbot/PlayerbotHooks.h" #include #include #include @@ -871,11 +870,6 @@ bool Unit::HasBreakableByDamageCrowdControlAura(Unit const* excludeCasterChannel // Hook for OnDamage Event sScriptMgr->OnDamage(attacker, victim, tmpDamage); - // PLAYERBOT V2 HOOK: feed BotEventInbox so reactive AI sees per-hit - // events. Filtered to player victims inside the hook. - Playerbot::Hooks::OnDamageTaken(attacker, victim, int32(tmpDamage), - spellProto ? spellProto->Id : 0u); - // if any script modified damage, we need to also apply the same modification to unscaled damage value if (tmpDamage != damageTaken) { @@ -1645,14 +1639,6 @@ void Unit::DealMeleeDamage(CalcDamageInfo* damageInfo, bool durabilityLoss) } } - // PLAYERBOT V2 HOOK (damage_parity scenarios): the swing's outcome, just before its damage is dealt. - Playerbot::Hooks::OnHitOutcome(this, victim, 0, - damageInfo->HitOutCome == MELEE_HIT_CRIT ? 1 : damageInfo->HitOutCome == MELEE_HIT_MISS ? 2 - : damageInfo->HitOutCome == MELEE_HIT_DODGE ? 3 : damageInfo->HitOutCome == MELEE_HIT_PARRY ? 4 - : damageInfo->HitOutCome == MELEE_HIT_BLOCK ? 5 : damageInfo->HitOutCome == MELEE_HIT_GLANCING ? 6 - : damageInfo->HitOutCome == MELEE_HIT_CRUSHING ? 7 : damageInfo->HitOutCome == MELEE_HIT_NORMAL ? 0 : 9, - damageInfo->Damage); - // Call default DealDamage CleanDamage cleanDamage(damageInfo->CleanDamage, damageInfo->Absorb, damageInfo->AttackType, damageInfo->HitOutCome); Unit::DealDamage(this, victim, damageInfo->Damage, &cleanDamage, DIRECT_DAMAGE, SpellSchoolMask(damageInfo->DamageSchoolMask), nullptr, durabilityLoss); @@ -6744,11 +6730,6 @@ void Unit::SetCharm(Unit* charm, bool apply) // Hook for OnHeal Event sScriptMgr->OnHeal(healer, victim, (uint32&)gain); - // PLAYERBOT V2 HOOK: feed BotEventInbox with heal events. Filtered to - // player victims inside the hook. - Playerbot::Hooks::OnHealReceived(healer, victim, int32(gain), - healInfo.GetSpellInfo() ? healInfo.GetSpellInfo()->Id : 0u); - Unit* unit = healer; if (healer && healer->GetTypeId() == TYPEID_UNIT && healer->IsTotem()) unit = healer->GetOwner(); @@ -7017,7 +6998,6 @@ void Unit::EnergizeBySpell(Unit* victim, SpellInfo const* spellInfo, int32 damag int32 gain = victim->ModifyPower(powerType, damage, false); int32 overEnergize = damage - gain; - Playerbot::Hooks::OnEnergize(victim, spellInfo->Id, gain, powerType); victim->GetThreatManager().ForwardThreatForAssistingMe(this, float(damage) / 2, spellInfo, true); SendEnergizeSpellLog(victim, spellInfo->Id, gain, overEnergize, powerType); } @@ -11697,9 +11677,7 @@ void Unit::SetMeleeAnimKitId(uint16 animKitId) attacker = nullptr; - // PLAYERBOT V2 HOOK: drives auto-loot enqueueing for bots in the tap list - // and (eventually) state transitions when a bot itself dies. - Playerbot::Hooks::OnDeath(victim, attacker); + sScriptMgr->OnUnitDeath(victim, attacker); // find player: owner of controlled `this` or `this` itself maybe Player* player = nullptr; diff --git a/src/server/game/Groups/Group.cpp b/src/server/game/Groups/Group.cpp index 0be7bb0e7e..4d9414d905 100644 --- a/src/server/game/Groups/Group.cpp +++ b/src/server/game/Groups/Group.cpp @@ -43,7 +43,6 @@ #include "Player.h" #include "UpdateData.h" #include "WorldSession.h" -#include "Playerbot/PlayerbotHooks.h" Seconds Group::CountdownInfo::GetTimeLeft() const { @@ -1074,7 +1073,7 @@ void Group::ChangeMembersGroup(ObjectGuid guid, uint8 group) // Broadcast the changes to the group SendUpdate(); - Playerbot::Hooks::OnRaidSubgroupChanged(this, guid, group); + sScriptMgr->OnGroupSubgroupChange(this, guid, group); } void Group::ReorderMembers(std::vector const& order) @@ -1134,8 +1133,8 @@ void Group::SwapMembersGroups(ObjectGuid firstGuid, ObjectGuid secondGuid) CharacterDatabase.CommitTransaction(trans); SendUpdate(); - Playerbot::Hooks::OnRaidSubgroupChanged(this, slots[0]->guid, slots[0]->group); - Playerbot::Hooks::OnRaidSubgroupChanged(this, slots[1]->guid, slots[1]->group); + sScriptMgr->OnGroupSubgroupChange(this, slots[0]->guid, slots[0]->group); + sScriptMgr->OnGroupSubgroupChange(this, slots[1]->guid, slots[1]->group); } // Retrieve the next Round-Roubin player for the group diff --git a/src/server/game/Guilds/Guild.cpp b/src/server/game/Guilds/Guild.cpp index 69a740bb43..93c40c3a98 100644 --- a/src/server/game/Guilds/Guild.cpp +++ b/src/server/game/Guilds/Guild.cpp @@ -39,7 +39,6 @@ #include "ObjectAccessor.h" #include "ObjectMgr.h" #include "Player.h" -#include "Playerbot/PlayerbotHooks.h" #include "ScriptMgr.h" #include "SocialMgr.h" #include "World.h" @@ -2953,11 +2952,6 @@ bool Guild::AddMember(CharacterDatabaseTransaction trans, ObjectGuid guid, Optio // Call scripts if member was succesfully added (and stored to database) sScriptMgr->OnGuildAddMember(this, player, AsUnderlyingType(*rankId)); - // PlayerbotV2 SC-P2b: notify the reactor so one online bot guildmate - // can drop a welcome line a few seconds later (per-guild throttle). - // `name` is resolved above for both online and offline joins. - Playerbot::Hooks::OnGuildMemberAdded(m_id, guid, name); - return true; } diff --git a/src/server/game/Handlers/BattleGroundHandler.cpp b/src/server/game/Handlers/BattleGroundHandler.cpp index d75a6956a0..19e7478001 100644 --- a/src/server/game/Handlers/BattleGroundHandler.cpp +++ b/src/server/game/Handlers/BattleGroundHandler.cpp @@ -34,10 +34,10 @@ #include "Language.h" #include "Log.h" #include "NPCPackets.h" -#include "Playerbot/PlayerbotHooks.h" #include "Object.h" #include "ObjectAccessor.h" #include "Player.h" +#include "ScriptMgr.h" #include "SpellAuras.h" #include "SpellMgr.h" #include "SpellInfo.h" @@ -305,11 +305,7 @@ void WorldSession::JoinBattlegroundQueue(BattlegroundQueueTypeId bgQueueTypeId) bgQueueTypeId.BattlemasterListId, uint32(bgQueueTypeId.Type), bgQueueTypeId.Rated ? "true" : "false", uint32(bgQueueTypeId.TeamSize), _player->GetGUID().ToString(), _player->GetName()); - // Playerbot V2: solo player just joined a BG queue. Auto-fill the - // remaining slots with bots (online preferred, JIT-spawn the rest). - // Only fire for non-bot human players. - if (!IsBot()) - Playerbot::Hooks::OnPlayerJoinedBgQueue(_player, bgTypeId, bracketEntry->GetBracketId()); + sScriptMgr->OnPlayerBattlegroundQueueJoin(_player, bgTypeId, bracketEntry->GetBracketId()); } else { @@ -366,10 +362,8 @@ void WorldSession::JoinBattlegroundQueue(BattlegroundQueueTypeId bgQueueTypeId) } TC_LOG_DEBUG("bg.battleground", "Battleground: group end"); - // Playerbot V2: a human leader queued the group (bots in it are queued with it). Fill the other team and the free - // slots the same way as for a solo human; the bot-leader group queue in PlayerbotAPI::bg_queue does the same. - if (!err && !IsBot()) - Playerbot::Hooks::OnPlayerJoinedBgQueue(_player, bgTypeId, bracketEntry->GetBracketId()); + if (!err) + sScriptMgr->OnPlayerBattlegroundQueueJoin(_player, bgTypeId, bracketEntry->GetBracketId()); } sBattlegroundMgr->ScheduleQueueUpdate(0, bgQueueTypeId, bracketEntry->GetBracketId()); @@ -419,7 +413,7 @@ void WorldSession::HandleBattleFieldPortOpcode(WorldPackets::Battleground::Battl { TC_LOG_DEBUG("bg.battleground", "CMSG_BATTLEFIELD_PORT {} Slot: {}, Unk: {}, Time: {}, AcceptedInvite: {}. Player not in queue!", GetPlayerInfo(), battlefieldPort.Ticket.Id, uint32(battlefieldPort.Ticket.Type), battlefieldPort.Ticket.Time.AsUnderlyingType(), uint32(battlefieldPort.AcceptedInvite)); - Playerbot::Hooks::OnBGPortFailed(_player, /*not_in_queue*/ 1, 0); + sScriptMgr->OnPlayerBattlegroundPortFailed(_player, /*not_in_queue*/ 1, 0); return; } @@ -469,7 +463,7 @@ void WorldSession::HandleBattleFieldPortOpcode(WorldPackets::Battleground::Battl { TC_LOG_DEBUG("bg.battleground", "CMSG_BATTLEFIELD_PORT {} Slot: {}, Unk: {}, Time: {}, AcceptedInvite: {}. Invalid queueSlot!", GetPlayerInfo(), battlefieldPort.Ticket.Id, uint32(battlefieldPort.Ticket.Type), battlefieldPort.Ticket.Time.AsUnderlyingType(), uint32(battlefieldPort.AcceptedInvite)); - Playerbot::Hooks::OnBGPortFailed(_player, /*invalid_queue_slot*/ 2, 0); + sScriptMgr->OnPlayerBattlegroundPortFailed(_player, /*invalid_queue_slot*/ 2, 0); if (!battlefieldPort.AcceptedInvite) leaveAllQueues(); return; @@ -483,7 +477,7 @@ void WorldSession::HandleBattleFieldPortOpcode(WorldPackets::Battleground::Battl { TC_LOG_DEBUG("bg.battleground", "CMSG_BATTLEFIELD_PORT {} Slot: {}, Unk: {}, Time: {}, AcceptedInvite: {}. Player not in queue (No player Group Info)!", GetPlayerInfo(), battlefieldPort.Ticket.Id, uint32(battlefieldPort.Ticket.Type), battlefieldPort.Ticket.Time.AsUnderlyingType(), uint32(battlefieldPort.AcceptedInvite)); - Playerbot::Hooks::OnBGPortFailed(_player, /*no_group_info*/ 3, 0); + sScriptMgr->OnPlayerBattlegroundPortFailed(_player, /*no_group_info*/ 3, 0); if (!battlefieldPort.AcceptedInvite) leaveAllQueues(); return; @@ -493,7 +487,7 @@ void WorldSession::HandleBattleFieldPortOpcode(WorldPackets::Battleground::Battl { TC_LOG_DEBUG("bg.battleground", "CMSG_BATTLEFIELD_PORT {} Slot: {}, Unk: {}, Time: {}, AcceptedInvite: {}. Player is not invited to any bg!", GetPlayerInfo(), battlefieldPort.Ticket.Id, uint32(battlefieldPort.Ticket.Type), battlefieldPort.Ticket.Time.AsUnderlyingType(), uint32(battlefieldPort.AcceptedInvite)); - Playerbot::Hooks::OnBGPortFailed(_player, /*ginfo_not_invited*/ 4, 0); + sScriptMgr->OnPlayerBattlegroundPortFailed(_player, /*ginfo_not_invited*/ 4, 0); return; } @@ -514,7 +508,7 @@ void WorldSession::HandleBattleFieldPortOpcode(WorldPackets::Battleground::Battl { TC_LOG_DEBUG("bg.battleground", "CMSG_BATTLEFIELD_PORT {} Slot: {}, Unk: {}, Time: {}, AcceptedInvite: {}. Cant find BG with id {}!", GetPlayerInfo(), battlefieldPort.Ticket.Id, uint32(battlefieldPort.Ticket.Type), battlefieldPort.Ticket.Time.AsUnderlyingType(), uint32(battlefieldPort.AcceptedInvite), ginfo.IsInvitedToBGInstanceGUID); - Playerbot::Hooks::OnBGPortFailed(_player, /*bg_instance_gone*/ 5, ginfo.IsInvitedToBGInstanceGUID); + sScriptMgr->OnPlayerBattlegroundPortFailed(_player, /*bg_instance_gone*/ 5, ginfo.IsInvitedToBGInstanceGUID); return; } else if (bg) @@ -527,7 +521,7 @@ void WorldSession::HandleBattleFieldPortOpcode(WorldPackets::Battleground::Battl PVPDifficultyEntry const* bracketEntry = DB2Manager::GetBattlegroundBracketByLevel(mapId, _player->GetLevel()); if (!bracketEntry) { - Playerbot::Hooks::OnBGPortFailed(_player, /*no_bracket_entry*/ 6, + sScriptMgr->OnPlayerBattlegroundPortFailed(_player, /*no_bracket_entry*/ 6, ginfo.IsInvitedToBGInstanceGUID); return; } @@ -559,14 +553,14 @@ void WorldSession::HandleBattleFieldPortOpcode(WorldPackets::Battleground::Battl // check Freeze debuff if (_player->HasAura(9454)) { - Playerbot::Hooks::OnBGPortFailed(_player, /*freeze_debuff*/ 7, + sScriptMgr->OnPlayerBattlegroundPortFailed(_player, /*freeze_debuff*/ 7, ginfo.IsInvitedToBGInstanceGUID); return; } if (!_player->IsInvitedForBattlegroundQueueType(bgQueueTypeId)) { - Playerbot::Hooks::OnBGPortFailed(_player, /*invite_flag_cleared*/ 8, + sScriptMgr->OnPlayerBattlegroundPortFailed(_player, /*invite_flag_cleared*/ 8, ginfo.IsInvitedToBGInstanceGUID); return; // cheating? } diff --git a/src/server/game/Handlers/CharacterHandler.cpp b/src/server/game/Handlers/CharacterHandler.cpp index 7f6dfc98fb..e46efb6a71 100644 --- a/src/server/game/Handlers/CharacterHandler.cpp +++ b/src/server/game/Handlers/CharacterHandler.cpp @@ -16,7 +16,6 @@ */ #include "WorldSession.h" -#include "Playerbot/PlayerbotHooks.h" #include "AccountMgr.h" #include "ArenaTeam.h" #include "ArenaTeamMgr.h" @@ -1736,8 +1735,6 @@ void WorldSession::HandlePlayerLogin(LoginQueryHolder const& holder) sScriptMgr->OnPlayerLogin(pCurrChar, firstLogin); - Playerbot::Hooks::OnPlayerLogin(pCurrChar); - // Battle.net presence: the client takes the account's BattleTag from it (Social window, Battle.net friends); online friends are told BattlenetPresence::OnLogin(this); diff --git a/src/server/game/Handlers/ChatHandler.cpp b/src/server/game/Handlers/ChatHandler.cpp index e946946a28..1b5d08162b 100644 --- a/src/server/game/Handlers/ChatHandler.cpp +++ b/src/server/game/Handlers/ChatHandler.cpp @@ -41,7 +41,6 @@ #include "SpellAuraEffects.h" #include "Util.h" #include "World.h" -#include "Playerbot/PlayerbotHooks.h" #include enum class ChatWhisperTargetStatus : uint8 @@ -269,10 +268,7 @@ ChatMessageResult WorldSession::HandleChatMessage(ChatMsg type, Language lang, s } sender->Say(msg, lang); - // PlayerbotV2 SC-P1a: let a nearby bot answer /say (greetings, - // direct-name mentions, "anyone know where X is?"). Reactor - // self-filters bot senders + range-gates via CONFIG_LISTEN_RANGE_SAY. - Playerbot::Hooks::OnSayChat(sender, msg); + sScriptMgr->OnPlayerChatSent(sender, type, lang, msg); break; } case CHAT_MSG_EMOTE: @@ -303,9 +299,7 @@ ChatMessageResult WorldSession::HandleChatMessage(ChatMsg type, Language lang, s } sender->Yell(msg, lang); - // PlayerbotV2 SC-P1a: yell reactions are rarer than say (handled - // inside the reactor) but a nearby bot may still respond. - Playerbot::Hooks::OnYellChat(sender, msg); + sScriptMgr->OnPlayerChatSent(sender, type, lang, msg); break; } case CHAT_MSG_WHISPER: @@ -372,7 +366,7 @@ ChatMessageResult WorldSession::HandleChatMessage(ChatMsg type, Language lang, s sender->AddWhisperWhiteList(receiver->GetGUID()); GetPlayer()->Whisper(msg, lang, receiver); - Playerbot::Hooks::OnWhisperReceived(GetPlayer(), receiver, msg); + sScriptMgr->OnPlayerChatSent(GetPlayer(), type, lang, msg, receiver); break; } case CHAT_MSG_PARTY: @@ -393,13 +387,7 @@ ChatMessageResult WorldSession::HandleChatMessage(ChatMsg type, Language lang, s WorldPackets::Chat::Chat packet; packet.Initialize(ChatMsg(type), lang, sender, nullptr, msg); group->BroadcastPacket(packet.Write(), false, group->GetMemberGroup(GetPlayer()->GetGUID())); - // Playerbot V2: route party-chat squad commands. Messages - // starting with `;` (the squad prefix) are dispatched to - // the sender's bots in the group via the address resolver. - // Any non-bot listeners see the literal message in chat; - // bots react. This makes raid-leader chatter ergonomic - // ("` ;tank pull") without forcing whisper-per-bot. - Playerbot::Hooks::OnPartyChat(GetPlayer(), group, msg); + sScriptMgr->OnPlayerChatSent(GetPlayer(), type, lang, msg, group); break; } case CHAT_MSG_GUILD: @@ -411,11 +399,7 @@ ChatMessageResult WorldSession::HandleChatMessage(ChatMsg type, Language lang, s sScriptMgr->OnPlayerChat(GetPlayer(), type, lang, msg, guild); guild->BroadcastToGuild(this, false, msg, lang == LANG_ADDON ? LANG_ADDON : LANG_UNIVERSAL); - // V2 Phase C.3: route to BotChatReactor so an online - // officer of the sender's guild can drop a contextual - // reply (gz/nice/:) ). Bot-originated chat is - // self-filtered by the reactor. - Playerbot::Hooks::OnGuildChat(GetPlayer(), GetPlayer()->GetGuildId(), msg); + sScriptMgr->OnPlayerChatSent(GetPlayer(), type, lang, msg, guild); } } break; @@ -429,6 +413,7 @@ ChatMessageResult WorldSession::HandleChatMessage(ChatMsg type, Language lang, s sScriptMgr->OnPlayerChat(GetPlayer(), type, lang, msg, guild); guild->BroadcastToGuild(this, true, msg, lang == LANG_ADDON ? LANG_ADDON : LANG_UNIVERSAL); + sScriptMgr->OnPlayerChatSent(GetPlayer(), type, lang, msg, guild); } } break; @@ -447,9 +432,7 @@ ChatMessageResult WorldSession::HandleChatMessage(ChatMsg type, Language lang, s WorldPackets::Chat::Chat packet; packet.Initialize(ChatMsg(type), lang, sender, nullptr, msg); group->BroadcastPacket(packet.Write(), false); - // PlayerbotV2: same squad-chat surface as PARTY for the user. - // Raid/instance chat is what LFG groups end up using by default. - Playerbot::Hooks::OnPartyChat(GetPlayer(), group, msg); + sScriptMgr->OnPlayerChatSent(GetPlayer(), type, lang, msg, group); break; } case CHAT_MSG_RAID_WARNING: @@ -472,6 +455,7 @@ ChatMessageResult WorldSession::HandleChatMessage(ChatMsg type, Language lang, s //in battleground, raid warning is sent only to players in battleground - code is ok packet.Initialize(CHAT_MSG_RAID_WARNING, lang, sender, nullptr, msg); group->BroadcastPacket(packet.Write(), false); + sScriptMgr->OnPlayerChatSent(GetPlayer(), type, lang, msg, group); break; } case CHAT_MSG_CHANNEL: @@ -513,13 +497,7 @@ ChatMessageResult WorldSession::HandleChatMessage(ChatMsg type, Language lang, s WorldPackets::Chat::Chat packet; packet.Initialize(ChatMsg(type), lang, sender, nullptr, msg); group->BroadcastPacket(packet.Write(), false); - // PlayerbotV2: route instance chat the same way as party chat - // for squad command dispatch (`;all run`, `;tank pull`, etc.). - // LFG groups default to instance chat — without this hook the - // user's commands never reach the resolver. Fix 2026-05-13: - // observed "Player Balastan tells instance with leader Thaoir: - // ;all run" with bots not responding. - Playerbot::Hooks::OnPartyChat(GetPlayer(), group, msg); + sScriptMgr->OnPlayerChatSent(GetPlayer(), type, lang, msg, group); break; } default: @@ -606,9 +584,7 @@ void WorldSession::HandleChatAddonMessage(ChatMsg type, std::string prefix, std: break; sender->WhisperAddon(text, prefix, isLogged, receiver); - // Playerbot V2: the ForeverBots addon whispers a bot this way in battlegrounds, where the client's own /whisper does - // nothing; the hook ignores every other prefix. - Playerbot::Hooks::OnAddonWhisper(sender, receiver, prefix, text); + sScriptMgr->OnPlayerAddonMessageSent(sender, type, prefix, text, receiver); break; } // Messages sent to "RAID" while in a party will get delivered to "PARTY" @@ -634,9 +610,7 @@ void WorldSession::HandleChatAddonMessage(ChatMsg type, std::string prefix, std: WorldPackets::Chat::Chat packet; packet.Initialize(type, isLogged ? LANG_ADDON_LOGGED : LANG_ADDON, sender, nullptr, text, 0, "", DEFAULT_LOCALE, prefix); group->BroadcastAddonMessagePacket(packet.Write(), prefix, true, subGroup, sender->GetGUID()); - // Playerbot V2: the ForeverBots panel sends its bot orders as addon messages (SendChatMessage from addon code - // is blocked by the client in combat and in battlegrounds); the hook ignores every other prefix. - Playerbot::Hooks::OnAddonMessage(sender, group, prefix, text); + sScriptMgr->OnPlayerAddonMessageSent(sender, type, prefix, text, group); break; } case CHAT_MSG_CHANNEL: @@ -806,12 +780,6 @@ void WorldSession::HandleTextEmoteOpcode(WorldPackets::Chat::CTextEmote& packet) textEmote.SoundIndex = packet.SoundIndex; _player->SendMessageToSetInRange(textEmote.Write(), sWorld->getFloatConfig(CONFIG_LISTEN_RANGE_TEXTEMOTE), true); - // PlayerbotV2 SC-P2c: a nearby bot reciprocates a text emote (waves - // back, returns a salute/cheer). Pass the resolved Emote id + target so - // the reactor can pick a reciprocal animation. Reactor self-filters bot - // senders and range-gates via CONFIG_LISTEN_RANGE_TEXTEMOTE. - Playerbot::Hooks::OnTextEmote(_player, static_cast(emote), uint32(packet.EmoteID), packet.Target); - Unit* unit = ObjectAccessor::GetUnit(*_player, packet.Target); _player->UpdateCriteria(CriteriaType::DoEmote, packet.EmoteID, 0, 0, unit); diff --git a/src/server/game/Handlers/LFGHandler.cpp b/src/server/game/Handlers/LFGHandler.cpp index 8a14e5351f..58832c4605 100644 --- a/src/server/game/Handlers/LFGHandler.cpp +++ b/src/server/game/Handlers/LFGHandler.cpp @@ -26,7 +26,7 @@ #include "ObjectAccessor.h" #include "ObjectMgr.h" #include "Player.h" -#include "Playerbot/PlayerbotHooks.h" +#include "ScriptMgr.h" void WorldSession::HandleLfgJoinOpcode(WorldPackets::LFG::DFJoin& dfJoin) { @@ -53,11 +53,8 @@ void WorldSession::HandleLfgJoinOpcode(WorldPackets::LFG::DFJoin& dfJoin) sLFGMgr->JoinLfg(GetPlayer(), uint8(dfJoin.Roles), newDungeons); - // Playerbot V2: solo player joined a dungeon queue. Auto-fill remaining - // role slots with bots. Use the first selected dungeon as the target - // instance id. Bots themselves no-op the hook. - if (!IsBot() && !newDungeons.empty()) - Playerbot::Hooks::OnPlayerJoinedLfg(GetPlayer(), *newDungeons.begin(), uint8(dfJoin.Roles)); + if (!newDungeons.empty()) + sScriptMgr->OnPlayerLfgJoin(GetPlayer(), *newDungeons.begin(), uint8(dfJoin.Roles)); } void WorldSession::HandleLfgLeaveOpcode(WorldPackets::LFG::DFLeave& dfLeave) diff --git a/src/server/game/Handlers/MiscHandler.cpp b/src/server/game/Handlers/MiscHandler.cpp index 5348c09fff..aae803f32a 100644 --- a/src/server/game/Handlers/MiscHandler.cpp +++ b/src/server/game/Handlers/MiscHandler.cpp @@ -48,7 +48,6 @@ #include "ObjectMgr.h" #include "OutdoorPvP.h" #include "Player.h" -#include "Playerbot/PlayerbotHooks.h" #include "RestMgr.h" #include "ScriptMgr.h" #include "Spell.h" @@ -91,11 +90,6 @@ void WorldSession::HandleRepopRequest(WorldPackets::Misc::RepopRequest& /*packet GetPlayer()->KillPlayer(); } - // PLAYERBOT V2 HOOK: the owner's dead companions on this map release with the owner (inside a dungeon or - // raid RepopAtGraveyard revives the owner at the graveyard, so no ghost state ever tells them). Fired - // before the repop so the owner's map is still the death map. - Playerbot::Hooks::OnSpiritReleased(GetPlayer()); - //this is spirit release confirm? GetPlayer()->RemovePet(nullptr, PET_SAVE_NOT_IN_SLOT, true); GetPlayer()->BuildPlayerRepop(); diff --git a/src/server/game/Scripting/ScriptMgr.cpp b/src/server/game/Scripting/ScriptMgr.cpp index 555951de47..5684ad9424 100644 --- a/src/server/game/Scripting/ScriptMgr.cpp +++ b/src/server/game/Scripting/ScriptMgr.cpp @@ -1983,6 +1983,15 @@ void ScriptMgr::OnShutdown() FOREACH_SCRIPT(WorldScript)->OnShutdown(); } +bool ScriptMgr::CanCreateBattleground(uint32 battlemasterListId, uint8 bracketId) +{ + bool allowed = true; + FOR_SCRIPTS_RET(WorldScript, itr, end, true) + if (!itr->second->CanCreateBattleground(battlemasterListId, bracketId)) + allowed = false; + return allowed; +} + // Achievement void ScriptMgr::OnAchievementCompleted(Player* player, AchievementEntry const* achievement) { @@ -2093,6 +2102,36 @@ void ScriptMgr::OnPlayerChat(Player* player, uint32 type, uint32 lang, std::stri FOREACH_SCRIPT(PlayerScript)->OnChat(player, type, lang, msg, channel); } +void ScriptMgr::OnPlayerChatSent(Player* player, uint32 type, uint32 lang, std::string const& msg) +{ + FOREACH_SCRIPT(PlayerScript)->OnChatSent(player, type, lang, msg); +} + +void ScriptMgr::OnPlayerChatSent(Player* player, uint32 type, uint32 lang, std::string const& msg, Player* receiver) +{ + FOREACH_SCRIPT(PlayerScript)->OnChatSent(player, type, lang, msg, receiver); +} + +void ScriptMgr::OnPlayerChatSent(Player* player, uint32 type, uint32 lang, std::string const& msg, Group* group) +{ + FOREACH_SCRIPT(PlayerScript)->OnChatSent(player, type, lang, msg, group); +} + +void ScriptMgr::OnPlayerChatSent(Player* player, uint32 type, uint32 lang, std::string const& msg, Guild* guild) +{ + FOREACH_SCRIPT(PlayerScript)->OnChatSent(player, type, lang, msg, guild); +} + +void ScriptMgr::OnPlayerAddonMessageSent(Player* player, uint32 type, std::string const& prefix, std::string const& text, Player* receiver) +{ + FOREACH_SCRIPT(PlayerScript)->OnAddonMessageSent(player, type, prefix, text, receiver); +} + +void ScriptMgr::OnPlayerAddonMessageSent(Player* player, uint32 type, std::string const& prefix, std::string const& text, Group* group) +{ + FOREACH_SCRIPT(PlayerScript)->OnAddonMessageSent(player, type, prefix, text, group); +} + void ScriptMgr::OnPlayerClearEmote(Player* player) { FOREACH_SCRIPT(PlayerScript)->OnClearEmote(player); @@ -2163,6 +2202,36 @@ void ScriptMgr::OnMovieComplete(Player* player, uint32 movieId) FOREACH_SCRIPT(PlayerScript)->OnMovieComplete(player, movieId); } +void ScriptMgr::OnPlayerLootItem(Player* player, Item* item) +{ + FOREACH_SCRIPT(PlayerScript)->OnLootItem(player, item); +} + +void ScriptMgr::OnPlayerBattlegroundQueueJoin(Player* player, uint32 bgTypeId, uint8 bracketId) +{ + FOREACH_SCRIPT(PlayerScript)->OnBattlegroundQueueJoin(player, bgTypeId, bracketId); +} + +void ScriptMgr::OnPlayerBattlegroundInvite(Player* player, uint32 instanceId, uint32 bgTypeId) +{ + FOREACH_SCRIPT(PlayerScript)->OnBattlegroundInvite(player, instanceId, bgTypeId); +} + +void ScriptMgr::OnPlayerBattlegroundPortFailed(Player* player, uint8 reason, uint32 instanceId) +{ + FOREACH_SCRIPT(PlayerScript)->OnBattlegroundPortFailed(player, reason, instanceId); +} + +void ScriptMgr::OnPlayerLfgJoin(Player* player, uint32 dungeonId, uint8 roles) +{ + FOREACH_SCRIPT(PlayerScript)->OnLfgJoin(player, dungeonId, roles); +} + +void ScriptMgr::OnPlayerLfgProposal(Player* player, uint32 proposalId) +{ + FOREACH_SCRIPT(PlayerScript)->OnLfgProposal(player, proposalId); +} + void ScriptMgr::OnPlayerChoiceResponse(WorldObject* object, Player* player, PlayerChoice const* choice, PlayerChoiceResponse const* response, uint16 clientIdentifier) { ASSERT(choice); @@ -2291,6 +2360,12 @@ void ScriptMgr::OnGroupDisband(Group* group) FOREACH_SCRIPT(GroupScript)->OnDisband(group); } +void ScriptMgr::OnGroupSubgroupChange(Group* group, ObjectGuid guid, uint8 subgroup) +{ + ASSERT(group); + FOREACH_SCRIPT(GroupScript)->OnSubgroupChange(group, guid, subgroup); +} + // Unit void ScriptMgr::OnHeal(Unit* healer, Unit* reciever, uint32& gain) { @@ -2317,6 +2392,11 @@ void ScriptMgr::ModifySpellDamageTaken(Unit* target, Unit* attacker, int32& dama FOREACH_SCRIPT(UnitScript)->ModifySpellDamageTaken(target, attacker, damage, spellInfo); } +void ScriptMgr::OnUnitDeath(Unit* victim, Unit* killer) +{ + FOREACH_SCRIPT(UnitScript)->OnUnitDeath(victim, killer); +} + // Scene void ScriptMgr::OnSceneStart(Player* player, uint32 sceneInstanceID, SceneTemplate const* sceneTemplate) { @@ -2496,6 +2576,11 @@ void WorldScript::OnShutdown() { } +bool WorldScript::CanCreateBattleground(uint32 /*battlemasterListId*/, uint8 /*bracketId*/) +{ + return true; +} + FormulaScript::FormulaScript(char const* name) noexcept : ScriptObject(name) { @@ -2685,6 +2770,10 @@ void UnitScript::ModifySpellDamageTaken(Unit* /*target*/, Unit* /*attacker*/, in { } +void UnitScript::OnUnitDeath(Unit* /*victim*/, Unit* /*killer*/) +{ +} + CreatureScript::CreatureScript(char const* name) noexcept : ScriptObject(name) { @@ -2985,6 +3074,30 @@ void PlayerScript::OnChat(Player* /*player*/, uint32 /*type*/, uint32 /*lang*/, { } +void PlayerScript::OnChatSent(Player* /*player*/, uint32 /*type*/, uint32 /*lang*/, std::string const& /*msg*/) +{ +} + +void PlayerScript::OnChatSent(Player* /*player*/, uint32 /*type*/, uint32 /*lang*/, std::string const& /*msg*/, Player* /*receiver*/) +{ +} + +void PlayerScript::OnChatSent(Player* /*player*/, uint32 /*type*/, uint32 /*lang*/, std::string const& /*msg*/, Group* /*group*/) +{ +} + +void PlayerScript::OnChatSent(Player* /*player*/, uint32 /*type*/, uint32 /*lang*/, std::string const& /*msg*/, Guild* /*guild*/) +{ +} + +void PlayerScript::OnAddonMessageSent(Player* /*player*/, uint32 /*type*/, std::string const& /*prefix*/, std::string const& /*text*/, Player* /*receiver*/) +{ +} + +void PlayerScript::OnAddonMessageSent(Player* /*player*/, uint32 /*type*/, std::string const& /*prefix*/, std::string const& /*text*/, Group* /*group*/) +{ +} + void PlayerScript::OnClearEmote(Player* /*player*/) { } @@ -3045,6 +3158,30 @@ void PlayerScript::OnMovieComplete(Player* /*player*/, uint32 /*movieId*/) { } +void PlayerScript::OnLootItem(Player* /*player*/, Item* /*item*/) +{ +} + +void PlayerScript::OnBattlegroundQueueJoin(Player* /*player*/, uint32 /*bgTypeId*/, uint8 /*bracketId*/) +{ +} + +void PlayerScript::OnBattlegroundInvite(Player* /*player*/, uint32 /*instanceId*/, uint32 /*bgTypeId*/) +{ +} + +void PlayerScript::OnBattlegroundPortFailed(Player* /*player*/, uint8 /*reason*/, uint32 /*instanceId*/) +{ +} + +void PlayerScript::OnLfgJoin(Player* /*player*/, uint32 /*dungeonId*/, uint8 /*roles*/) +{ +} + +void PlayerScript::OnLfgProposal(Player* /*player*/, uint32 /*proposalId*/) +{ +} + AccountScript::AccountScript(char const* name) noexcept : ScriptObject(name) { @@ -3159,6 +3296,10 @@ void GroupScript::OnDisband(Group* /*group*/) { } +void GroupScript::OnSubgroupChange(Group* /*group*/, ObjectGuid /*guid*/, uint8 /*subgroup*/) +{ +} + AreaTriggerEntityScript::AreaTriggerEntityScript(char const* name) noexcept : ScriptObject(name) { diff --git a/src/server/game/Scripting/ScriptMgr.h b/src/server/game/Scripting/ScriptMgr.h index f3fc1b48b2..ec33d9777a 100644 --- a/src/server/game/Scripting/ScriptMgr.h +++ b/src/server/game/Scripting/ScriptMgr.h @@ -284,6 +284,9 @@ class TC_GAME_API WorldScript : public ScriptObject // Called when the world is actually shut down. virtual void OnShutdown(); + + // Called before a battleground queue opens a new (non arena) instance; return false to hold it for now. + virtual bool CanCreateBattleground(uint32 battlemasterListId, uint8 bracketId); }; class TC_GAME_API FormulaScript : public ScriptObject @@ -441,6 +444,9 @@ class TC_GAME_API UnitScript : public ScriptObject // Called when Spell Damage is being Dealt virtual void ModifySpellDamageTaken(Unit* target, Unit* attacker, int32& damage, SpellInfo const* spellInfo); + + // Called when a unit is killed, before the kill (loot, rewards, death state) is processed + virtual void OnUnitDeath(Unit* victim, Unit* killer); }; class TC_GAME_API CreatureScript : public ScriptObject @@ -754,6 +760,20 @@ class TC_GAME_API PlayerScript : public ScriptObject virtual void OnChat(Player* player, uint32 type, uint32 lang, std::string& msg, Channel* channel); + // The following methods are called after a player's say, yell, whisper, group or guild message was sent. + virtual void OnChatSent(Player* player, uint32 type, uint32 lang, std::string const& msg); + + virtual void OnChatSent(Player* player, uint32 type, uint32 lang, std::string const& msg, Player* receiver); + + virtual void OnChatSent(Player* player, uint32 type, uint32 lang, std::string const& msg, Group* group); + + virtual void OnChatSent(Player* player, uint32 type, uint32 lang, std::string const& msg, Guild* guild); + + // The following methods are called after a player's addon message was sent as a whisper or to the group. + virtual void OnAddonMessageSent(Player* player, uint32 type, std::string const& prefix, std::string const& text, Player* receiver); + + virtual void OnAddonMessageSent(Player* player, uint32 type, std::string const& prefix, std::string const& text, Group* group); + // Both of the below are called on emote opcodes. virtual void OnClearEmote(Player* player); @@ -797,6 +817,25 @@ class TC_GAME_API PlayerScript : public ScriptObject // Called when a player completes a movie virtual void OnMovieComplete(Player* player, uint32 movieId); + + // Called when a looted item was stored in the player's bags + virtual void OnLootItem(Player* player, Item* item); + + // Called after a player (alone or as group leader) joined a battleground queue + virtual void OnBattlegroundQueueJoin(Player* player, uint32 bgTypeId, uint8 bracketId); + + // Called when a player is invited to a battleground instance, and again on the invite reminder + virtual void OnBattlegroundInvite(Player* player, uint32 instanceId, uint32 bgTypeId); + + // Called when a player's request to enter a battleground is refused. reason: 1 not in queue, 2 invalid queue slot, + // 3 no group info, 4 not invited, 5 instance gone, 6 no bracket, 7 frozen (GM freeze), 8 invite no longer valid + virtual void OnBattlegroundPortFailed(Player* player, uint8 reason, uint32 instanceId); + + // Called after a player joined the dungeon finder + virtual void OnLfgJoin(Player* player, uint32 dungeonId, uint8 roles); + + // Called when a dungeon finder proposal is sent to a player + virtual void OnLfgProposal(Player* player, uint32 proposalId); }; class TC_GAME_API AccountScript : public ScriptObject @@ -895,6 +934,9 @@ class TC_GAME_API GroupScript : public ScriptObject // Called when a group is disbanded. virtual void OnDisband(Group* group); + + // Called when a raid member is moved to another subgroup. + virtual void OnSubgroupChange(Group* group, ObjectGuid guid, uint8 subgroup); }; class TC_GAME_API AreaTriggerEntityScript : public ScriptObject @@ -1113,6 +1155,7 @@ class TC_GAME_API ScriptMgr void OnWorldInitialized(); void OnStartup(); void OnShutdown(); + bool CanCreateBattleground(uint32 battlemasterListId, uint8 bracketId); public: /* FormulaScript */ @@ -1239,6 +1282,12 @@ class TC_GAME_API ScriptMgr void OnPlayerChat(Player* player, uint32 type, uint32 lang, std::string& msg, Group* group); void OnPlayerChat(Player* player, uint32 type, uint32 lang, std::string& msg, Guild* guild); void OnPlayerChat(Player* player, uint32 type, uint32 lang, std::string& msg, Channel* channel); + void OnPlayerChatSent(Player* player, uint32 type, uint32 lang, std::string const& msg); + void OnPlayerChatSent(Player* player, uint32 type, uint32 lang, std::string const& msg, Player* receiver); + void OnPlayerChatSent(Player* player, uint32 type, uint32 lang, std::string const& msg, Group* group); + void OnPlayerChatSent(Player* player, uint32 type, uint32 lang, std::string const& msg, Guild* guild); + void OnPlayerAddonMessageSent(Player* player, uint32 type, std::string const& prefix, std::string const& text, Player* receiver); + void OnPlayerAddonMessageSent(Player* player, uint32 type, std::string const& prefix, std::string const& text, Group* group); void OnPlayerClearEmote(Player* player); void OnPlayerTextEmote(Player* player, uint32 textEmote, uint32 emoteNum, ObjectGuid guid); void OnPlayerSpellCast(Player* player, Spell* spell, bool skipCheck); @@ -1253,6 +1302,12 @@ class TC_GAME_API ScriptMgr void OnQuestStatusChange(Player* player, uint32 questId); void OnPlayerRepop(Player* player); void OnMovieComplete(Player* player, uint32 movieId); + void OnPlayerLootItem(Player* player, Item* item); + void OnPlayerBattlegroundQueueJoin(Player* player, uint32 bgTypeId, uint8 bracketId); + void OnPlayerBattlegroundInvite(Player* player, uint32 instanceId, uint32 bgTypeId); + void OnPlayerBattlegroundPortFailed(Player* player, uint8 reason, uint32 instanceId); + void OnPlayerLfgJoin(Player* player, uint32 dungeonId, uint8 roles); + void OnPlayerLfgProposal(Player* player, uint32 proposalId); void OnPlayerChoiceResponse(WorldObject* object, Player* player, PlayerChoice const* choice, PlayerChoiceResponse const* response, uint16 clientIdentifier); public: /* AccountScript */ @@ -1286,6 +1341,7 @@ class TC_GAME_API ScriptMgr void OnGroupRemoveMember(Group* group, ObjectGuid guid, RemoveMethod method, ObjectGuid kicker, char const* reason); void OnGroupChangeLeader(Group* group, ObjectGuid newLeaderGuid, ObjectGuid oldLeaderGuid); void OnGroupDisband(Group* group); + void OnGroupSubgroupChange(Group* group, ObjectGuid guid, uint8 subgroup); public: /* UnitScript */ @@ -1294,6 +1350,7 @@ class TC_GAME_API ScriptMgr void ModifyPeriodicDamageAurasTick(Unit* target, Unit* attacker, uint32& damage); void ModifyMeleeDamage(Unit* target, Unit* attacker, uint32& damage); void ModifySpellDamageTaken(Unit* target, Unit* attacker, int32& damage, SpellInfo const* spellInfo); + void OnUnitDeath(Unit* victim, Unit* killer); public: /* AreaTriggerEntityScript */ diff --git a/src/server/game/Server/WorldSession.cpp b/src/server/game/Server/WorldSession.cpp index e59a133e3f..7736178332 100644 --- a/src/server/game/Server/WorldSession.cpp +++ b/src/server/game/Server/WorldSession.cpp @@ -17,7 +17,6 @@ #include "WorldSession.h" #include "Playerbot/DiagProbes.h" -#include "Playerbot/PlayerbotHooks.h" #include "Account.h" #include "AccountMgr.h" #include "AuthenticationPackets.h" @@ -857,8 +856,6 @@ void WorldSession::LogoutPlayer(bool save) //! Call script hook before deletion sScriptMgr->OnPlayerLogout(_player); - Playerbot::Hooks::OnPlayerLogout(_player); - // Battle.net friends see us go offline BattlenetPresence::OnLogout(this); diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp index a6429d578e..f872599ea9 100644 --- a/src/server/game/Spells/Spell.cpp +++ b/src/server/game/Spells/Spell.cpp @@ -72,7 +72,6 @@ #include "VMapManager.h" #include "World.h" #include "WorldSession.h" -#include "Playerbot/PlayerbotHooks.h" #include #include @@ -2786,11 +2785,6 @@ void Spell::TargetInfo::PreprocessTarget(Spell* spell) { if (missInfo != SPELL_MISS_MISS) spell->m_caster->SendSpellMiss(unit, spell->m_spellInfo->Id, missInfo); - // PLAYERBOT V2 HOOK (damage_parity scenarios): an avoided spell, tallied by outcome. - if (spell->m_caster->IsUnit() && !spell->m_caster->IsFriendlyTo(unit)) - Playerbot::Hooks::OnHitOutcome(spell->m_caster->ToUnit(), unit, spell->m_spellInfo->Id, - missInfo == SPELL_MISS_MISS ? 2 : missInfo == SPELL_MISS_DODGE ? 3 : missInfo == SPELL_MISS_PARRY ? 4 - : missInfo == SPELL_MISS_BLOCK ? 5 : missInfo == SPELL_MISS_RESIST ? 8 : 9, 0); spell->m_damage = 0; spell->m_healing = 0; _spellHitTarget = nullptr; @@ -2979,8 +2973,6 @@ void Spell::TargetInfo::DoDamageAndTriggers(Spell* spell) } spell->m_damage = damageInfo.damage; - // PLAYERBOT V2 HOOK (damage_parity scenarios): the direct hit's outcome, just before its damage is dealt. - Playerbot::Hooks::OnHitOutcome(caster, damageInfo.target, spell->m_spellInfo->Id, IsCrit ? 1 : 0, damageInfo.damage); caster->DealSpellDamage(&damageInfo, true); // Send log damage message to client