kusanagy

MultiVendor

Nov 9th, 2016
1,187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 11.49 KB | None | 0 0
  1. diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp
  2. index 50e27d9..5ef3be1 100644
  3. --- a/src/server/game/Entities/Player/Player.cpp
  4. +++ b/src/server/game/Entities/Player/Player.cpp
  5. @@ -13967,8 +13967,8 @@ void Player::PrepareGossipMenu(WorldObject* source, uint32 menuId /*= 0*/, bool
  6.                      break;
  7.                  case GOSSIP_OPTION_VENDOR:
  8.                  {
  9. -                    VendorItemData const* vendorItems = creature->GetVendorItems();
  10. -                    if (!vendorItems || vendorItems->Empty())
  11. +                    VendorItemData const* vendorItems = itr->second.ActionMenuId ? nullptr : creature->GetVendorItems();
  12. +                    if (!itr->second.ActionMenuId && (!vendorItems || vendorItems->Empty()))
  13.                      {
  14.                          TC_LOG_ERROR("sql.sql", "Creature %s (Entry: %u GUID: %u DB GUID: %u) has UNIT_NPC_FLAG_VENDOR set, but has an empty trading item list.", creature->GetName().c_str(), creature->GetEntry(), creature->GetGUID().GetCounter(), creature->GetSpawnId());
  15.                          canTalk = false;
  16. @@ -14179,7 +14179,7 @@ void Player::OnGossipSelect(WorldObject* source, uint32 gossipListId, uint32 men
  17.              break;
  18.          case GOSSIP_OPTION_VENDOR:
  19.          case GOSSIP_OPTION_ARMORER:
  20. -            GetSession()->SendListInventory(guid);
  21. +            GetSession()->SendListInventory(guid, menuItemData->GossipActionMenuId);
  22.              break;
  23.          case GOSSIP_OPTION_STABLEPET:
  24.              GetSession()->SendStablePet(guid);
  25. @@ -21381,7 +21381,11 @@ bool Player::BuyItemFromVendorSlot(ObjectGuid vendorguid, uint32 vendorslot, uin
  26.          return false;
  27.      }
  28.  
  29. -    VendorItemData const* vItems = creature->GetVendorItems();
  30. +    uint32 currentVendor = GetSession()->GetCurrentVendor();
  31. +    if (currentVendor && vendorguid != PlayerTalkClass->GetGossipMenu().GetSenderGUID())
  32. +        return false; // Cheating
  33. +
  34. +    VendorItemData const* vItems = currentVendor ? sObjectMgr->GetNpcVendorItemList(currentVendor) : creature->GetVendorItems();
  35.      if (!vItems || vItems->Empty())
  36.      {
  37.          SendBuyError(BUY_ERR_CANT_FIND_ITEM, creature, item, 0);
  38. diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp
  39. index fc0abf5..8fd0459 100644
  40. --- a/src/server/game/Globals/ObjectMgr.cpp
  41. +++ b/src/server/game/Globals/ObjectMgr.cpp
  42. @@ -8503,8 +8503,9 @@ bool ObjectMgr::RemoveVendorItem(uint32 entry, uint32 item, bool persist /*= tru
  43.      return true;
  44.  }
  45.  
  46. -bool ObjectMgr::IsVendorItemValid(uint32 vendor_entry, uint32 item_id, int32 maxcount, uint32 incrtime, uint32 ExtendedCost, Player* player, std::set<uint32>* skip_vendors, uint32 ORnpcflag) const
  47. +bool ObjectMgr::IsVendorItemValid(uint32 vendor_entry, uint32 item_id, int32 maxcount, uint32 incrtime, uint32 ExtendedCost, Player* player, std::set<uint32>* /*skip_vendors*/, uint32 /*ORnpcflag*/) const
  48.  {
  49. +    /*
  50.      CreatureTemplate const* cInfo = sObjectMgr->GetCreatureTemplate(vendor_entry);
  51.      if (!cInfo)
  52.      {
  53. @@ -8529,6 +8530,7 @@ bool ObjectMgr::IsVendorItemValid(uint32 vendor_entry, uint32 item_id, int32 max
  54.          }
  55.          return false;
  56.      }
  57. +    */
  58.  
  59.      if (!sObjectMgr->GetItemTemplate(item_id))
  60.      {
  61. diff --git a/src/server/game/Handlers/ItemHandler.cpp b/src/server/game/Handlers/ItemHandler.cpp
  62. index 7f5d882..95c540b 100644
  63. --- a/src/server/game/Handlers/ItemHandler.cpp
  64. +++ b/src/server/game/Handlers/ItemHandler.cpp
  65. @@ -726,7 +726,7 @@ void WorldSession::HandleListInventoryOpcode(WorldPacket& recvData)
  66.      SendListInventory(guid);
  67.  }
  68.  
  69. -void WorldSession::SendListInventory(ObjectGuid vendorGuid)
  70. +void WorldSession::SendListInventory(ObjectGuid vendorGuid, uint32 vendorEntry)
  71.  {
  72.      TC_LOG_DEBUG("network", "WORLD: Sent SMSG_LIST_INVENTORY");
  73.  
  74. @@ -746,7 +746,9 @@ void WorldSession::SendListInventory(ObjectGuid vendorGuid)
  75.      if (vendor->HasUnitState(UNIT_STATE_MOVING))
  76.          vendor->StopMoving();
  77.  
  78. -    VendorItemData const* items = vendor->GetVendorItems();
  79. +    SetCurrentVendor(vendorEntry);
  80. +
  81. +    VendorItemData const* items = vendorEntry ? sObjectMgr->GetNpcVendorItemList(vendorEntry) : vendor->GetVendorItems();
  82.      if (!items)
  83.      {
  84.          WorldPacket data(SMSG_LIST_INVENTORY, 8 + 1 + 1);
  85. diff --git a/src/server/game/Server/WorldSession.cpp b/src/server/game/Server/WorldSession.cpp
  86. index ddcc10b..a5bb5a2 100644
  87. --- a/src/server/game/Server/WorldSession.cpp
  88. +++ b/src/server/game/Server/WorldSession.cpp
  89. @@ -123,6 +123,7 @@ WorldSession::WorldSession(uint32 id, std::string&& name, std::shared_ptr<WorldS
  90.      _RBACData(NULL),
  91.      expireTime(60000), // 1 min after socket loss, session is deleted
  92.      forceExit(false),
  93. +    m_currentVendorEntry(0),
  94.      m_currentBankerGUID()
  95.  {
  96.      memset(m_Tutorials, 0, sizeof(m_Tutorials));
  97. diff --git a/src/server/game/Server/WorldSession.h b/src/server/game/Server/WorldSession.h
  98. index 584367b..5faf21f 100644
  99. --- a/src/server/game/Server/WorldSession.h
  100. +++ b/src/server/game/Server/WorldSession.h
  101. @@ -291,6 +291,9 @@ class TC_GAME_API WorldSession
  102.          std::string const& GetPlayerName() const;
  103.          std::string GetPlayerInfo() const;
  104.  
  105. +        uint32 GetCurrentVendor() const { return m_currentVendorEntry; }
  106. +        void SetCurrentVendor(uint32 vendorEntry) { m_currentVendorEntry = vendorEntry; }
  107. +
  108.          ObjectGuid::LowType GetGUIDLow() const;
  109.          void SetSecurity(AccountTypes security) { _security = security; }
  110.          std::string const& GetRemoteAddress() const { return m_Address; }
  111. @@ -330,7 +333,7 @@ class TC_GAME_API WorldSession
  112.  
  113.          void SendTrainerList(ObjectGuid guid);
  114.          void SendTrainerList(ObjectGuid guid, std::string const& strTitle);
  115. -        void SendListInventory(ObjectGuid guid);
  116. +        void SendListInventory(ObjectGuid guid, uint32 vendorEntry = 0);
  117.          void SendShowBank(ObjectGuid guid);
  118.          bool CanOpenMailBox(ObjectGuid guid);
  119.          void SendShowMailBox(ObjectGuid guid);
  120. @@ -1066,6 +1069,7 @@ class TC_GAME_API WorldSession
  121.          rbac::RBACData* _RBACData;
  122.          uint32 expireTime;
  123.          bool forceExit;
  124. +        uint32 m_currentVendorEntry;
  125.          ObjectGuid m_currentBankerGUID;
  126.  
  127.          WorldSession(WorldSession const& right) = delete;
  128. diff --git a/src/server/scripts/Commands/cs_npc.cpp b/src/server/scripts/Commands/cs_npc.cpp
  129. index 438d05c..db48569 100644
  130. --- a/src/server/scripts/Commands/cs_npc.cpp
  131. +++ b/src/server/scripts/Commands/cs_npc.cpp
  132. @@ -339,7 +339,8 @@ class npc_commandscript : public CommandScript
  133.              return false;
  134.          }
  135.  
  136. -        uint32 vendor_entry = vendor->GetEntry();
  137. +        char* addMulti = strtok(NULL, " ");
  138. +        uint32 vendor_entry = addMulti ? handler->GetSession()->GetCurrentVendor() : vendor ? vendor->GetEntry() : 0;
  139.  
  140.          if (!sObjectMgr->IsVendorItemValid(vendor_entry, itemId, maxcount, incrtime, extendedcost, handler->GetSession()->GetPlayer()))
  141.          {
  142. @@ -523,7 +524,8 @@ class npc_commandscript : public CommandScript
  143.          }
  144.          uint32 itemId = atoul(pitem);
  145.  
  146. -        if (!sObjectMgr->RemoveVendorItem(vendor->GetEntry(), itemId))
  147. +        char* addMulti = strtok(NULL, " ");
  148. +        if (!sObjectMgr->RemoveVendorItem(addMulti ? handler->GetSession()->GetCurrentVendor() : vendor->GetEntry(), itemId))
  149.          {
  150.              handler->PSendSysMessage(LANG_ITEM_NOT_IN_LIST, itemId);
  151.              handler->SetSentErrorMessage(true);
  152. diff --git a/src/server/scripts/Custom/Multivendor/MultivendorExample.sql b/src/server/scripts/Custom/Multivendor/MultivendorExample.sql
  153. new file mode 100644
  154. index 0000000..ef94f21
  155. --- /dev/null
  156. +++ b/src/server/scripts/Custom/Multivendor/MultivendorExample.sql
  157. @@ -0,0 +1,10 @@
  158. +SET @ENTRY = (SELECT max(entry)+1 FROM creature_template);
  159. +SET @MENU_ID = (SELECT max(menu_id)+1 FROM gossip_menu_option);
  160. +
  161. +INSERT INTO `creature_template` (`entry`, `modelid1`, `name`, `subname`, `IconName`, `gossip_menu_id`, `minlevel`, `maxlevel`, `exp`, `faction`, `npcflag`, `speed_walk`, `speed_run`, `scale`, `rank`, `dmgschool`, `baseattacktime`, `rangeattacktime`, `unit_class`, `unit_flags`, `unit_flags2`, `dynamicflags`, `family`, `trainer_type`, `trainer_spell`, `trainer_class`, `trainer_race`, `type`, `type_flags`, `lootid`, `pickpocketloot`, `skinloot`, `PetSpellDataId`, `VehicleId`, `mingold`, `maxgold`, `AIName`, `MovementType`, `InhabitType`, `HoverHeight`, `RacialLeader`, `movementId`, `RegenHealth`, `mechanic_immune_mask`, `flags_extra`, `ScriptName`) VALUES
  162. +(@ENTRY, 1298, "Herbert", "MultiVendor", NULL, @MENU_ID, 10, 10, 0, 35, 129, 1, 1.14286, 1, 0, 0, 1500, 0, 1, 512, 2048, 8, 0, 0, 0, 0, 0, 7, 138412032, 0, 0, 0, 0, 0, 0, 0, '', 0, 3, 1, 0, 0, 1, 0, 2, '');
  163. +
  164. +INSERT INTO `gossip_menu_option` (`menu_id`, `id`, `option_icon`, `option_text`, `option_id`, `npc_option_npcflag`, `action_menu_id`, `action_poi_id`, `box_coded`, `box_money`, `box_text`) VALUES
  165. +(@MENU_ID, 0, 4, 'VendorTest 465', 3, 128, 465, 0, 0, 0, ''),
  166. +(@MENU_ID, 1, 9, 'VendorTest 54', 3, 128, 54, 0, 0, 0, ''),
  167. +(@MENU_ID, 2, 6, 'VendorTest 35574', 3, 128, 35574, 0, 0, 100, 'These goods are special, so pay up!');
  168. diff --git a/src/server/scripts/Custom/Multivendor/README.md b/src/server/scripts/Custom/Multivendor/README.md
  169. new file mode 100644
  170. index 0000000..39680be
  171. --- /dev/null
  172. +++ b/src/server/scripts/Custom/Multivendor/README.md
  173. @@ -0,0 +1,42 @@
  174. +#Multivendor [![Build Status](https://travis-ci.org/Rochet2/TrinityCore.svg?branch=multivendor)](https://travis-ci.org/Rochet2/TrinityCore)
  175. +
  176. +####About
  177. +Allows you to show gossip options that show different vendors from npc_vendor.<br />
  178. +Source: http://rochet2.github.io/Multivendor.html
  179. +
  180. +####Installation
  181. +
  182. +Available as:
  183. +- Direct merge: https://github.com/Rochet2/TrinityCore/tree/multivendor
  184. +- Diff: https://github.com/Rochet2/TrinityCore/compare/TrinityCore:3.3.5...multivendor.diff
  185. +- Diff in github view: https://github.com/Rochet2/TrinityCore/compare/TrinityCore:3.3.5...multivendor
  186. +
  187. +Using direct merge:
  188. +- open git bash to source location
  189. +- do `git remote add rochet2 https://github.com/Rochet2/TrinityCore.git`
  190. +- do `git pull rochet2 multivendor`
  191. +- use cmake and compile
  192. +
  193. +Using diff:
  194. +- DO NOT COPY THE DIFF DIRECTLY! It causes apply to fail.
  195. +- download the diff by __right clicking__ the link and select __Save link as__
  196. +- place the downloaded `multivendor.diff` to the source root folder
  197. +- open git bash to source location
  198. +- do `git apply multivendor.diff`
  199. +- use cmake and compile
  200. +
  201. +####Usage
  202. +Set your NPC to have gossip and vendor NPCflags (129)<br />
  203. +Add a gossip menu for him and add a new option to it.<br />
  204. +The option needs to have option_id set to 3 so it acts as a vendor button,<br />
  205. +npc_option_npcflag can be 1 or 128 (shows only if the NPC has vendor flag then)<br />
  206. +and the action_menu_id is the vendor entry from npc_vendor that you want to show to the player.<br />
  207. +
  208. +YOU CAN also send menus from C++. All you need to do is to provide the vendor entry to the<br />
  209. +`void WorldSession::SendListInventory(ObjectGuid guid, uint32 vendorEntry)` function.
  210. +
  211. +The npc add item command was modified so you can add items to multivendors as well.<br />
  212. +The last vendor window must have been the multivendor you want to add your item to.<br />
  213. +After opening the window you need to type `.npc add item #itemId <#maxcount><#incrtime><#extendedcost> 1`<br />
  214. +The 1 in the end specifies that you are adding the item to the multivendor currently open.<br />
  215. +Same thing works with `.npc delete item #itemId 1`
Advertisement
Add Comment
Please, Sign In to add comment