diff options
| author | Ghaster <defscam@gmail.com> | 2018-10-17 11:16:56 +0200 |
|---|---|---|
| committer | Shauren <shauren.trinity@gmail.com> | 2018-12-30 19:51:36 +0100 |
| commit | bf3ab6d9c4366dae1d34957813e3fbf40ac8532b (patch) | |
| tree | 2f070f381fbf39e362a44561d8c0187fa79e4984 /src/server/game/Server | |
| parent | 3dbe80ee2e0d1848302bcf34b654693462942639 (diff) | |
Core/Creatures: Port trainer changes from master
Closes #20493
Diffstat (limited to 'src/server/game/Server')
| -rw-r--r-- | src/server/game/Server/Packets/AllPackets.h | 1 | ||||
| -rw-r--r-- | src/server/game/Server/Packets/NPCPackets.cpp | 70 | ||||
| -rw-r--r-- | src/server/game/Server/Packets/NPCPackets.h | 107 | ||||
| -rw-r--r-- | src/server/game/Server/WorldSession.h | 12 |
4 files changed, 186 insertions, 4 deletions
diff --git a/src/server/game/Server/Packets/AllPackets.h b/src/server/game/Server/Packets/AllPackets.h index 63cd9c0ca4c..17bcce8f09a 100644 --- a/src/server/game/Server/Packets/AllPackets.h +++ b/src/server/game/Server/Packets/AllPackets.h @@ -18,6 +18,7 @@ #ifndef AllPackets_h__ #define AllPackets_h__ +#include "NPCPackets.h" #include "QueryPackets.h" #include "QuestPackets.h" #include "SpellPackets.h" diff --git a/src/server/game/Server/Packets/NPCPackets.cpp b/src/server/game/Server/Packets/NPCPackets.cpp new file mode 100644 index 00000000000..bef58fabd02 --- /dev/null +++ b/src/server/game/Server/Packets/NPCPackets.cpp @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2008-2018 TrinityCore <https://www.trinitycore.org/> + * + * 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 "NPCPackets.h" + +void WorldPackets::NPC::Hello::Read() +{ + _worldPacket >> Unit; +} + +WorldPacket const* WorldPackets::NPC::TrainerList::Write() +{ + _worldPacket << TrainerGUID; + _worldPacket << int32(TrainerType); + + _worldPacket << int32(Spells.size()); + for (TrainerListSpell const& spell : Spells) + { + _worldPacket << int32(spell.SpellID); + _worldPacket << uint8(spell.Usable); + _worldPacket << int32(spell.MoneyCost); + _worldPacket << int32(spell.ProfessionDialog); + _worldPacket << int32(spell.ProfessionButton); + _worldPacket << uint8(spell.ReqLevel); + _worldPacket << int32(spell.ReqSkillLine); + _worldPacket << int32(spell.ReqSkillRank); + _worldPacket.append(spell.ReqAbility.data(), spell.ReqAbility.size()); + } + + _worldPacket << Greeting; + + return &_worldPacket; +} + +void WorldPackets::NPC::TrainerBuySpell::Read() +{ + _worldPacket >> TrainerGUID; + _worldPacket >> SpellID; +} + +WorldPacket const* WorldPackets::NPC::TrainerBuyFailed::Write() +{ + _worldPacket << TrainerGUID; + _worldPacket << int32(SpellID); + _worldPacket << int32(TrainerFailedReason); + + return &_worldPacket; +} + +WorldPacket const* WorldPackets::NPC::TrainerBuySucceeded::Write() +{ + _worldPacket << TrainerGUID; + _worldPacket << int32(SpellID); + + return &_worldPacket; +} diff --git a/src/server/game/Server/Packets/NPCPackets.h b/src/server/game/Server/Packets/NPCPackets.h new file mode 100644 index 00000000000..cdbf7072a8a --- /dev/null +++ b/src/server/game/Server/Packets/NPCPackets.h @@ -0,0 +1,107 @@ +/* + * Copyright (C) 2008-2018 TrinityCore <https://www.trinitycore.org/> + * + * 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 NPCPackets_h__ +#define NPCPackets_h__ + +#include "Packet.h" +#include "ObjectGuid.h" +#include <array> + +namespace WorldPackets +{ + namespace NPC + { + // CMSG_BANKER_ACTIVATE + // CMSG_BATTLEMASTER_HELLO + // CMSG_BINDER_ACTIVATE + // CMSG_GOSSIP_HELLO + // CMSG_LIST_INVENTORY + // CMSG_TRAINER_LIST + class Hello final : public ClientPacket + { + public: + Hello(WorldPacket&& packet) : ClientPacket(std::move(packet)) { } + + void Read() override; + + ObjectGuid Unit; + }; + + struct TrainerListSpell + { + int32 SpellID = 0; + uint8 Usable = 0; + int32 MoneyCost = 0; + int32 ProfessionDialog = 0; + int32 ProfessionButton = 0; + uint8 ReqLevel = 0; + int32 ReqSkillLine = 0; + int32 ReqSkillRank = 0; + std::array<int32, 3> ReqAbility = { }; + }; + + class TrainerList final : public ServerPacket + { + public: + TrainerList() : ServerPacket(SMSG_TRAINER_LIST) { } + + WorldPacket const* Write() override; + + ObjectGuid TrainerGUID; + int32 TrainerType = 0; + std::vector<TrainerListSpell> Spells; + std::string Greeting; + }; + + class TrainerBuySpell final : public ClientPacket + { + public: + TrainerBuySpell(WorldPacket&& packet) : ClientPacket(CMSG_TRAINER_BUY_SPELL, std::move(packet)) { } + + void Read() override; + + ObjectGuid TrainerGUID; + int32 SpellID = 0; + }; + + class TrainerBuyFailed final : public ServerPacket + { + public: + TrainerBuyFailed() : ServerPacket(SMSG_TRAINER_BUY_FAILED, 8 + 4 + 4) { } + + WorldPacket const* Write() override; + + ObjectGuid TrainerGUID; + int32 SpellID = 0; + int32 TrainerFailedReason = 0; + }; + + class TrainerBuySucceeded final : public ServerPacket + { + public: + TrainerBuySucceeded() : ServerPacket(SMSG_TRAINER_BUY_SUCCEEDED, 8 + 4) { } + + WorldPacket const* Write() override; + + ObjectGuid TrainerGUID; + int32 SpellID = 0; + }; + } +} + +#endif // NPCPackets_h__ diff --git a/src/server/game/Server/WorldSession.h b/src/server/game/Server/WorldSession.h index 540bc239128..2891b486201 100644 --- a/src/server/game/Server/WorldSession.h +++ b/src/server/game/Server/WorldSession.h @@ -74,6 +74,11 @@ class RBACData; namespace WorldPackets { + namespace NPC + { + class Hello; + class TrainerBuySpell; + } namespace Query { class QueryCreature; @@ -348,8 +353,7 @@ class TC_GAME_API WorldSession void SendNameQueryOpcode(ObjectGuid guid); - void SendTrainerList(ObjectGuid guid); - void SendTrainerList(ObjectGuid guid, std::string const& strTitle); + void SendTrainerList(Creature* npc); void SendListInventory(ObjectGuid guid); void SendShowBank(ObjectGuid guid); bool CanOpenMailBox(ObjectGuid guid); @@ -652,8 +656,8 @@ class TC_GAME_API WorldSession void HandleTabardVendorActivateOpcode(WorldPacket& recvPacket); void HandleBankerActivateOpcode(WorldPacket& recvPacket); void HandleBuyBankSlotOpcode(WorldPacket& recvPacket); - void HandleTrainerListOpcode(WorldPacket& recvPacket); - void HandleTrainerBuySpellOpcode(WorldPacket& recvPacket); + void HandleTrainerListOpcode(WorldPackets::NPC::Hello& packet); + void HandleTrainerBuySpellOpcode(WorldPackets::NPC::TrainerBuySpell& packet); void HandlePetitionShowListOpcode(WorldPacket& recvPacket); void HandleGossipHelloOpcode(WorldPacket& recvPacket); void HandleGossipSelectOptionOpcode(WorldPacket& recvPacket); |
