kusanagy

corona core multi trainer patch

Jan 23rd, 2017
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 11.87 KB | None | 0 0
  1. diff --git a/src/game/LuaEngine/PlayerMethods.h b/src/game/LuaEngine/PlayerMethods.h
  2. index 5ec3daf..e72ca63 100644
  3. --- a/src/game/LuaEngine/PlayerMethods.h
  4. +++ b/src/game/LuaEngine/PlayerMethods.h
  5. @@ -2125,8 +2125,9 @@ namespace LuaPlayer
  6.      int SendTrainerList(Eluna* /*E*/, lua_State* L, Player* player)
  7.      {
  8.          WorldObject* obj = Eluna::CHECKOBJ<WorldObject>(L, 2);
  9. -
  10. -        player->GetSession()->SendTrainerList(obj->GET_GUID());
  11. +        uint32 TrainerID = Eluna::CHECKVAL<uint32>(L, 3);
  12. +        bool SpellCosts = Eluna::CHECKVAL<bool>(L, 4, true);
  13. +        player->GetSession()->SendTrainerList(obj->GET_GUID(), TrainerID, SpellCosts);
  14.          return 0;
  15.      }
  16.  
  17. diff --git a/src/game/NPCHandler.cpp b/src/game/NPCHandler.cpp
  18. index 408d370..8fd09c7 100644
  19. --- a/src/game/NPCHandler.cpp
  20. +++ b/src/game/NPCHandler.cpp
  21. @@ -106,14 +106,14 @@ void WorldSession::HandleTrainerListOpcode(WorldPacket& recv_data)
  22.      SendTrainerList(guid);
  23.  }
  24.  
  25. -void WorldSession::SendTrainerList(ObjectGuid guid)
  26. +void WorldSession::SendTrainerList(ObjectGuid guid, uint32 trainer_entry, bool spell_cost)
  27.  {
  28.      std::string str = GetMangosString(LANG_NPC_TAINER_HELLO);
  29. -    SendTrainerList(guid, str);
  30. +    SendTrainerList(guid, str, trainer_entry, spell_cost);
  31.  }
  32.  
  33.  
  34. -static void SendTrainerSpellHelper(WorldPacket& data, TrainerSpell const* tSpell, TrainerSpellState state, float fDiscountMod, bool can_learn_primary_prof, uint32 reqLevel)
  35. +static void SendTrainerSpellHelper(WorldPacket& data, TrainerSpell const* tSpell, TrainerSpellState state, float fDiscountMod, bool can_learn_primary_prof, uint32 reqLevel, bool spell_cost)
  36.  {
  37.      bool primary_prof_first_rank = sSpellMgr.IsPrimaryProfessionFirstRankSpell(tSpell->spell);
  38.  
  39. @@ -121,7 +121,7 @@ static void SendTrainerSpellHelper(WorldPacket& data, TrainerSpell const* tSpell
  40.  
  41.      data << uint32(tSpell->spell);
  42.      data << uint8(state == TRAINER_SPELL_GREEN_DISABLED ? TRAINER_SPELL_GREEN : state);
  43. -    data << uint32(floor(tSpell->spellCost * fDiscountMod));
  44. +    data << uint32(floor(spell_cost ? tSpell->spellCost * fDiscountMod : 0));
  45.  
  46.      data << uint32(primary_prof_first_rank && can_learn_primary_prof ? 1 : 0);
  47.      // primary prof. learn confirmation dialog
  48. @@ -134,15 +134,26 @@ static void SendTrainerSpellHelper(WorldPacket& data, TrainerSpell const* tSpell
  49.      data << uint32(0);
  50.  }
  51.  
  52. -void WorldSession::SendTrainerList(ObjectGuid guid, const std::string& strTitle)
  53. +void WorldSession::SendTrainerList(ObjectGuid guid, const std::string& strTitle, uint32 trainer_entry, bool spell_cost)
  54.  {
  55.      DEBUG_LOG("WORLD: SendTrainerList");
  56.  
  57. -    Creature* unit = GetPlayer()->GetNPCIfCanInteractWith(guid, UNIT_NPC_FLAG_TRAINER);
  58. -    if (!unit)
  59. +    if (guid.IsPlayer() && GetPlayer()->GetObjectGuid() == guid)
  60. +        GetPlayer()->PlayerTalkClass->SendGossipMenu(1, GetPlayer()->GetObjectGuid());
  61. +
  62. +    SetCurrentTrainer(trainer_entry);
  63. +
  64. +    SetHasTrainerSpellCost(spell_cost);
  65. +
  66. +    Creature* unit = NULL;
  67. +    if (!guid.IsPlayer() || GetPlayer()->GetObjectGuid() != guid)
  68.      {
  69. -        DEBUG_LOG("WORLD: SendTrainerList - %s not found or you can't interact with him.", guid.GetString().c_str());
  70. -        return;
  71. +        unit = GetPlayer()->GetNPCIfCanInteractWith(guid, UNIT_NPC_FLAG_TRAINER);
  72. +        if (!unit)
  73. +        {
  74. +            DEBUG_LOG("WORLD: SendTrainerList - %s not found or you can't interact with him.", guid.GetString().c_str());
  75. +            return;
  76. +        }
  77.      }
  78.  
  79.      // remove fake death
  80. @@ -150,15 +161,26 @@ void WorldSession::SendTrainerList(ObjectGuid guid, const std::string& strTitle)
  81.          GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH);
  82.  
  83.      // trainer list loaded at check;
  84. -    if (!unit->IsTrainerOf(_player, true))
  85. -        return;
  86. +    if (unit)
  87. +    {
  88. +        if (!unit->IsTrainerOf(_player, true))
  89. +            return;
  90. +    }
  91. +    else
  92. +    {
  93. +        _player->PlayerTalkClass->ClearMenus();
  94. +        _player->PlayerTalkClass->SendGossipMenu(1, guid);
  95. +    }
  96.  
  97. -    CreatureInfo const* ci = unit->GetCreatureInfo();
  98. -    if (!ci)
  99. -        return;
  100. +    if (unit)
  101. +    {
  102. +        CreatureInfo const* ci = unit->GetCreatureInfo();
  103. +        if (!ci)
  104. +            return;
  105. +    }
  106.  
  107. -    TrainerSpellData const* cSpells = unit->GetTrainerSpells();
  108. -    TrainerSpellData const* tSpells = unit->GetTrainerTemplateSpells();
  109. +    TrainerSpellData const* cSpells = trainer_entry ? sObjectMgr.GetNpcTrainerSpells(trainer_entry) : unit ? unit->GetTrainerSpells() : NULL;
  110. +    TrainerSpellData const* tSpells = trainer_entry ? sObjectMgr.GetNpcTrainerTemplateSpells(trainer_entry): unit? unit->GetTrainerTemplateSpells() : NULL;
  111.  
  112.      if (!cSpells && !tSpells)
  113.      {
  114. @@ -177,7 +199,7 @@ void WorldSession::SendTrainerList(ObjectGuid guid, const std::string& strTitle)
  115.      data << uint32(maxcount);
  116.  
  117.      // reputation discount
  118. -    float fDiscountMod = _player->GetReputationPriceDiscount(unit);
  119. +    float fDiscountMod = unit ? _player->GetReputationPriceDiscount(unit) : 1.0f;
  120.      bool can_learn_primary_prof = GetPlayer()->GetFreePrimaryProfessionPoints() > 0;
  121.  
  122.      uint32 count = 0;
  123. @@ -196,7 +218,7 @@ void WorldSession::SendTrainerList(ObjectGuid guid, const std::string& strTitle)
  124.  
  125.              TrainerSpellState state = _player->GetTrainerSpellState(tSpell, reqLevel);
  126.  
  127. -            SendTrainerSpellHelper(data, tSpell, state, fDiscountMod, can_learn_primary_prof, reqLevel);
  128. +            SendTrainerSpellHelper(data, tSpell, state, fDiscountMod, can_learn_primary_prof, reqLevel, spell_cost);
  129.  
  130.              ++count;
  131.          }
  132. @@ -216,7 +238,7 @@ void WorldSession::SendTrainerList(ObjectGuid guid, const std::string& strTitle)
  133.  
  134.              TrainerSpellState state = _player->GetTrainerSpellState(tSpell, reqLevel);
  135.  
  136. -            SendTrainerSpellHelper(data, tSpell, state, fDiscountMod, can_learn_primary_prof, reqLevel);
  137. +            SendTrainerSpellHelper(data, tSpell, state, fDiscountMod, can_learn_primary_prof, reqLevel, spell_cost);
  138.  
  139.              ++count;
  140.          }
  141. @@ -236,23 +258,30 @@ void WorldSession::HandleTrainerBuySpellOpcode(WorldPacket& recv_data)
  142.      recv_data >> guid >> spellId;
  143.      DEBUG_LOG("WORLD: Received opcode CMSG_TRAINER_BUY_SPELL Trainer: %s, learn spell id is: %u", guid.GetString().c_str(), spellId);
  144.  
  145. -    Creature* unit = GetPlayer()->GetNPCIfCanInteractWith(guid, UNIT_NPC_FLAG_TRAINER);
  146. -    if (!unit)
  147. +    Creature* unit = NULL;
  148. +    if (!guid.IsPlayer() || GetPlayer()->GetObjectGuid() != guid)
  149.      {
  150. -        DEBUG_LOG("WORLD: HandleTrainerBuySpellOpcode - %s not found or you can't interact with him.", guid.GetString().c_str());
  151. -        return;
  152. +        unit = GetPlayer()->GetNPCIfCanInteractWith(guid, UNIT_NPC_FLAG_TRAINER);
  153. +        if (!unit)
  154. +        {
  155. +            DEBUG_LOG("WORLD: HandleTrainerBuySpellOpcode - %s not found or you can't interact with him.", guid.GetString().c_str());
  156. +            return;
  157. +        }
  158.      }
  159.  
  160.      // remove fake death
  161.      if (GetPlayer()->hasUnitState(UNIT_STAT_DIED))
  162.          GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH);
  163.  
  164. -    if (!unit->IsTrainerOf(_player, true))
  165. -        return;
  166. +    if (unit)
  167. +    {
  168. +        if (!unit->IsTrainerOf(_player, true))
  169. +            return;
  170. +    }
  171.  
  172.      // check present spell in trainer spell list
  173. -    TrainerSpellData const* cSpells = unit->GetTrainerSpells();
  174. -    TrainerSpellData const* tSpells = unit->GetTrainerTemplateSpells();
  175. +    TrainerSpellData const* cSpells = GetCurrentTrainer() ? sObjectMgr.GetNpcTrainerSpells(GetCurrentTrainer()) : unit ? unit->GetTrainerSpells() : NULL;
  176. +    TrainerSpellData const* tSpells = GetCurrentTrainer() ? sObjectMgr.GetNpcTrainerTemplateSpells(GetCurrentTrainer()) : unit ? unit->GetTrainerTemplateSpells() : NULL;
  177.  
  178.      if (!cSpells && !tSpells)
  179.          return;
  180. @@ -278,13 +307,14 @@ void WorldSession::HandleTrainerBuySpellOpcode(WorldPacket& recv_data)
  181.          return;
  182.  
  183.      // apply reputation discount
  184. -    uint32 nSpellCost = uint32(floor(trainer_spell->spellCost * _player->GetReputationPriceDiscount(unit)));
  185. +    uint32 nSpellCost = uint32(floor(trainer_spell->spellCost * (unit ? _player->GetReputationPriceDiscount(unit) : 1.0f)));
  186.  
  187.      // check money requirement
  188. -    if (_player->GetMoney() < nSpellCost)
  189. +    if ((_player->GetMoney() < nSpellCost) && HasTrainerSpellCost())
  190.          return;
  191.  
  192. -    _player->ModifyMoney(-int32(nSpellCost));
  193. +    if (HasTrainerSpellCost())
  194. +        _player->ModifyMoney(-int32(nSpellCost));
  195.  
  196.      SendPlaySpellVisual(guid, 0xB3);                        // visual effect on trainer
  197.  
  198. diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp
  199. index 16c4498..32cccc3 100644
  200. --- a/src/game/ObjectMgr.cpp
  201. +++ b/src/game/ObjectMgr.cpp
  202. @@ -8933,7 +8933,7 @@ bool ObjectMgr::IsVendorItemValid(bool isTemplate, char const* tableName, uint32
  203.      char const* idStr = isTemplate ? "vendor template" : "vendor";
  204.      CreatureInfo const* cInfo = NULL;
  205.  
  206. -    if (!isTemplate)
  207. +    /*if (!isTemplate)
  208.      {
  209.          cInfo = GetCreatureTemplate(vendor_entry);
  210.          if (!cInfo)
  211. @@ -8959,7 +8959,7 @@ bool ObjectMgr::IsVendorItemValid(bool isTemplate, char const* tableName, uint32
  212.              }
  213.              return false;
  214.          }
  215. -    }
  216. +    }*/
  217.  
  218.      if (!GetItemPrototype(item_id))
  219.      {
  220. diff --git a/src/game/Player.cpp b/src/game/Player.cpp
  221. index f927202..95a00ef 100644
  222. --- a/src/game/Player.cpp
  223. +++ b/src/game/Player.cpp
  224. @@ -12156,13 +12156,13 @@ void Player::OnGossipSelect(WorldObject* pSource, uint32 gossipListId, uint32 me
  225.          case GOSSIP_OPTION_STABLEPET:
  226.              GetSession()->SendStablePet(guid);
  227.              break;
  228.          case GOSSIP_OPTION_TRAINER:
  229. -            GetSession()->SendTrainerList(guid);
  230. +            GetSession()->SendTrainerList(guid, pMenuData.m_gAction_menu);
  231.              break;
  232.          case GOSSIP_OPTION_UNLEARNTALENTS:
  233.              PlayerTalkClass->CloseGossip();
  234. diff --git a/src/game/WorldSession.h b/src/game/WorldSession.h
  235. index 6d4a55a..29e11ea 100644
  236. --- a/src/game/WorldSession.h
  237. +++ b/src/game/WorldSession.h
  238. @@ -208,10 +208,10 @@ class MANGOS_DLL_SPEC WorldSession
  239.          void SendNameQueryOpcodeFromDB(ObjectGuid guid);
  240.          static void SendNameQueryOpcodeFromDBCallBack(QueryResult* result, uint32 accountId);
  241.  
  242. -        void SendTrainerList(ObjectGuid guid);
  243. -        void SendTrainerList(ObjectGuid guid, const std::string& strTitle);
  244. +        void SendTrainerList(ObjectGuid guid, uint32 trainer_entry = 0, bool spell_cost = true);
  245. +        void SendTrainerList(ObjectGuid guid, const std::string& strTitle, uint32 trainer_entry = 0, bool spell_cost = true);
  246.  
  247.          void SendListInventory(ObjectGuid guid);
  248.          bool CheckBanker(ObjectGuid guid);
  249.          void SendShowBank(ObjectGuid guid);
  250.          bool CheckMailBox(ObjectGuid guid);
  251. @@ -314,6 +314,16 @@ class MANGOS_DLL_SPEC WorldSession
  252.          void SendPlaySpellVisual(ObjectGuid guid, uint32 spellArtKit);
  253.          void SendItemPageInfo(ItemPrototype* itemProto);
  254.  
  255. +        // Multi Trainer
  256. +        uint32 GetCurrentTrainer() const { return m_currentTrainer; };
  257. +        void SetCurrentTrainer(uint32 trainer_entry) { m_currentTrainer = trainer_entry; };
  258. +        bool HasTrainerSpellCost() const { return m_current_trainer_cost; }
  259. +        void SetHasTrainerSpellCost(bool has_spell_cost) { m_current_trainer_cost = has_spell_cost; }
  260. +
  261.      public:                                                 // opcodes handlers
  262.  
  263.          void Handle_NULL(WorldPacket& recvPacket);          // not used
  264. @@ -771,6 +781,9 @@ class MANGOS_DLL_SPEC WorldSession
  265.          int m_sessionDbLocaleIndex;
  266.          uint32 m_latency;
  267.          uint32 m_Tutorials[8];
  268. +        bool m_current_trainer_cost;
  269. +        uint32 m_currentTrainer;
  270.          TutorialDataState m_tutorialState;
  271.          ACE_Based::LockedQueue<WorldPacket*, ACE_Thread_Mutex> _recvQueue;
  272.  };
Advertisement
Add Comment
Please, Sign In to add comment