Advertisement
Guest User

Transmo

a guest
Jun 14th, 2012
3,263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 16.88 KB | None | 0 0
  1. diff --git a/sql/updates/fc_updates_characters/fake_items.sql b/sql/updates/fc_updates_characters/fake_items.sql
  2. new file mode 100644
  3. index 0000000..3618ac1
  4. --- /dev/null
  5. +++ b/sql/updates/fc_updates_characters/fake_items.sql
  6. @@ -0,0 +1,11 @@
  7. +DROP TABLE IF EXISTS `fake_items`;
  8. +CREATE TABLE `fake_items` (
  9. +  `guid` int(11) NOT NULL,
  10. +  `fakeEntry` int(11) NOT NULL,
  11. +  PRIMARY KEY (`guid`)
  12. +);
  13. +
  14. +INSERT INTO `gossip_menu` VALUES (51000, 51000);
  15. +INSERT INTO npc_text (ID, text0_0, em0_1) VALUES
  16. +(51000, 'Put in the first slot of bag item, that you want to transmogrify. In the second slot, put item with perfect display.', 0);
  17. +
  18. diff --git a/sql/updates/fc_updates_world/fake_items.sql b/sql/updates/fc_updates_world/fake_items.sql
  19. new file mode 100644
  20. index 0000000..7cfd4cc
  21. --- /dev/null
  22. +++ b/sql/updates/fc_updates_world/fake_items.sql
  23. @@ -0,0 +1,3 @@
  24. +DELETE FROM creature_template WHERE entry = '190001';
  25. +INSERT INTO creature_template (entry, modelid1, name, subname, IconName, gossip_menu_id, minlevel, maxlevel, Health_mod, Mana_mod, Armor_mod, faction_A, faction_H, npcflag, speed_walk, speed_run, scale, rank, dmg_multiplier, unit_class, unit_flags, type, type_flags, InhabitType, RegenHealth, flags_extra, ScriptName) VALUES
  26. +('190001', '15998', "Transmogrify Master", "", 'Speak', '50000', 71, 71, 1.56, 1.56, 1.56, 35, 35, 3, 1, 1.14286, 1.25, 1, 1, 1, 2, 7, 138936390, 3, 1, 2, 'npc_transmogrify');
  27. diff --git a/src/server/game/Entities/Item/Item.cpp b/src/server/game/Entities/Item/Item.cpp
  28. index 23a3f50..d339a71 100755
  29. --- a/src/server/game/Entities/Item/Item.cpp
  30. +++ b/src/server/game/Entities/Item/Item.cpp
  31. @@ -251,6 +251,8 @@ Item::Item()
  32.      m_refundRecipient = 0;
  33.      m_paidMoney = 0;
  34.      m_paidExtendedCost = 0;
  35. +
  36. +    m_fakeDisplayEntry = 0;
  37.  }
  38.  
  39.  bool Item::Create(uint32 guidlow, uint32 itemid, Player const* owner)
  40. @@ -468,6 +470,9 @@ bool Item::LoadFromDB(uint32 guid, uint64 owner_guid, Field* fields, uint32 entr
  41.      SetUInt32Value(ITEM_FIELD_CREATE_PLAYED_TIME, fields[9].GetUInt32());
  42.      SetText(fields[10].GetString());
  43.  
  44. +    if (uint32 fakeEntry = sObjectMgr->GetFakeItemEntry(guid))
  45. +        SetFakeDisplay(fakeEntry);
  46. +
  47.      if (need_save)                                           // normal item changed state set not work at loading
  48.      {
  49.          PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_ITEM_INSTANCE_ON_LOAD);
  50. @@ -484,6 +489,7 @@ bool Item::LoadFromDB(uint32 guid, uint64 owner_guid, Field* fields, uint32 entr
  51.  /*static*/
  52.  void Item::DeleteFromDB(SQLTransaction& trans, uint32 itemGuid)
  53.  {
  54. +    sObjectMgr->RemoveFakeItem(itemGuid);
  55.      PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_ITEM_INSTANCE);
  56.      stmt->setUInt32(0, itemGuid);
  57.      trans->Append(stmt);
  58. @@ -491,6 +497,7 @@ void Item::DeleteFromDB(SQLTransaction& trans, uint32 itemGuid)
  59.  
  60.  void Item::DeleteFromDB(SQLTransaction& trans)
  61.  {
  62. +    RemoveFakeDisplay();
  63.      DeleteFromDB(trans, GetGUIDLow());
  64.  }
  65.  
  66. @@ -1207,3 +1214,50 @@ bool Item::CheckSoulboundTradeExpire()
  67.  
  68.      return false;
  69.  }
  70. +
  71. +FakeResult Item::SetFakeDisplay(uint32 iEntry)
  72. +{
  73. +    if (!iEntry)
  74. +    {
  75. +        RemoveFakeDisplay();
  76. +        return FAKE_ERR_OK;
  77. +    }
  78. +
  79. +    ItemTemplate const* myTmpl    = GetTemplate();
  80. +    ItemTemplate const* otherTmpl = sObjectMgr->GetItemTemplate(iEntry);
  81. +
  82. +    /*if (!otherTmpl)
  83. +        return FAKE_ERR_CANT_FIND_ITEM;
  84. +
  85. +    if (myTmpl->InventoryType != otherTmpl->InventoryType)
  86. +        return FAKE_ERR_DIFF_SLOTS;
  87. +
  88. +    if (myTmpl->AllowableClass != otherTmpl->AllowableClass)
  89. +        return FAKE_ERR_DIFF_CLASS;
  90. +
  91. +    if (myTmpl->AllowableRace != otherTmpl->AllowableRace)
  92. +        return FAKE_ERR_DIFF_RACE;
  93. +
  94. +    if (otherTmpl->Quality == ITEM_QUALITY_LEGENDARY || otherTmpl->Quality == ITEM_QUALITY_POOR)
  95. +        return FAKE_ERR_WRONG_QUALITY;*/
  96. +
  97. +    if (m_fakeDisplayEntry != iEntry)
  98. +    {
  99. +        sObjectMgr->SetFekeItem(GetGUIDLow(), iEntry);
  100. +
  101. +        (!m_fakeDisplayEntry) ? CharacterDatabase.PExecute("INSERT INTO fake_items VALUES (%u, %u)", GetGUIDLow(), iEntry) :
  102. +                                CharacterDatabase.PExecute("UPDATE fake_items SET fakeEntry = %u WHERE guid = %u", iEntry, GetGUIDLow());
  103. +        m_fakeDisplayEntry = iEntry;
  104. +    }
  105. +
  106. +    return FAKE_ERR_OK;
  107. +}
  108. +
  109. +void Item::RemoveFakeDisplay()
  110. +{
  111. +    if (GetFakeDisplayEntry())
  112. +    {
  113. +        m_fakeDisplayEntry = 0;
  114. +        CharacterDatabase.PExecute("DELETE FROM fake_items WHERE guid = %u", GetGUIDLow());
  115. +    }
  116. +}
  117. diff --git a/src/server/game/Entities/Item/Item.h b/src/server/game/Entities/Item/Item.h
  118. index 1d5fcae..32f1ef6 100755
  119. --- a/src/server/game/Entities/Item/Item.h
  120. +++ b/src/server/game/Entities/Item/Item.h
  121. @@ -152,6 +152,17 @@ enum SellResult
  122.      SELL_ERR_ONLY_EMPTY_BAG                      = 6        // can only do with empty bags
  123.  };
  124.  
  125. +enum FakeResult
  126. +{
  127. +    FAKE_ERR_CANT_FIND_OWNER,
  128. +    FAKE_ERR_CANT_FIND_ITEM,
  129. +    FAKE_ERR_WRONG_QUALITY,
  130. +    FAKE_ERR_DIFF_SLOTS,
  131. +    FAKE_ERR_DIFF_CLASS,
  132. +    FAKE_ERR_DIFF_RACE,
  133. +    FAKE_ERR_OK
  134. +};
  135. +
  136.  // -1 from client enchantment slot number
  137.  enum EnchantmentSlot
  138.  {
  139. @@ -340,6 +351,10 @@ class Item : public Object
  140.          void BuildUpdate(UpdateDataMapType&);
  141.  
  142.          uint32 GetScriptId() const { return GetTemplate()->ScriptId; }
  143. +
  144. +        FakeResult SetFakeDisplay(uint32 iEntry);
  145. +        uint32 GetFakeDisplayEntry() { return m_fakeDisplayEntry; }
  146. +        void RemoveFakeDisplay();
  147.      private:
  148.          std::string m_text;
  149.          uint8 m_slot;
  150. @@ -352,5 +367,7 @@ class Item : public Object
  151.          uint32 m_paidMoney;
  152.          uint32 m_paidExtendedCost;
  153.          AllowedLooterSet allowedGUIDs;
  154. +
  155. +        uint32 m_fakeDisplayEntry;
  156.  };
  157.  #endif
  158. diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp
  159. index dd35dea..fc8e4d0 100755
  160. --- a/src/server/game/Entities/Player/Player.cpp
  161. +++ b/src/server/game/Entities/Player/Player.cpp
  162. @@ -12719,7 +12719,7 @@ void Player::SetVisibleItemSlot(uint8 slot, Item* pItem)
  163.  {
  164.      if (pItem)
  165.      {
  166. -        SetUInt32Value(PLAYER_VISIBLE_ITEM_1_ENTRYID + (slot * 2), pItem->GetEntry());
  167. +        SetUInt32Value(PLAYER_VISIBLE_ITEM_1_ENTRYID + (slot * 2), (pItem->GetFakeDisplayEntry()) ? pItem->GetFakeDisplayEntry() : pItem->GetEntry());
  168.          SetUInt16Value(PLAYER_VISIBLE_ITEM_1_ENCHANTMENT + (slot * 2), 0, pItem->GetEnchantmentId(PERM_ENCHANTMENT_SLOT));
  169.          SetUInt16Value(PLAYER_VISIBLE_ITEM_1_ENCHANTMENT + (slot * 2), 1, pItem->GetEnchantmentId(TEMP_ENCHANTMENT_SLOT));
  170.      }
  171. diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp
  172. index df6018f..054c6f0 100755
  173. --- a/src/server/game/Globals/ObjectMgr.cpp
  174. +++ b/src/server/game/Globals/ObjectMgr.cpp
  175. @@ -2692,6 +2692,27 @@ ItemTemplate const* ObjectMgr::GetItemTemplate(uint32 entry)
  176.      return NULL;
  177.  }
  178.  
  179. +uint32 ObjectMgr::GetFakeItemEntry(uint32 itemGuid)
  180. +{
  181. +    FakeItemsContainer::const_iterator itr = _fakeItemsStore.find(itemGuid);
  182. +    if (itr != _fakeItemsStore.end())
  183. +        return itr->second;
  184. +
  185. +    return 0;
  186. +}
  187. +
  188. +void ObjectMgr::SetFekeItem(uint32 itemGuid, uint32 fakeEntry)
  189. +{
  190. +    _fakeItemsStore[itemGuid] = fakeEntry;
  191. +}
  192. +
  193. +void ObjectMgr::RemoveFakeItem(uint32 itemGuid)
  194. +{
  195. +    FakeItemsContainer::iterator itr = _fakeItemsStore.find(itemGuid);
  196. +    if (itr != _fakeItemsStore.end())
  197. +        _fakeItemsStore.erase(itr);
  198. +}
  199. +
  200.  void ObjectMgr::LoadItemSetNameLocales()
  201.  {
  202.      uint32 oldMSTime = getMSTime();
  203. @@ -2803,6 +2824,32 @@ void ObjectMgr::LoadItemSetNames()
  204.      sLog->outString();
  205.  }
  206.  
  207. +void ObjectMgr::LoadFakeItems()
  208. +{
  209. +    QueryResult result = CharacterDatabase.Query("SELECT `guid`, `fakeEntry` FROM `fake_items`");
  210. +
  211. +    if (!result)
  212. +    {
  213. +        sLog->outErrorDb(">> Loaded 0 fake items. DB table `fake_items` is empty.");
  214. +        sLog->outString();
  215. +        return;
  216. +    }
  217. +
  218. +    do
  219. +    {
  220. +        Field* fields    = result->Fetch();
  221. +
  222. +        uint32 guid      = fields[0].GetUInt32();
  223. +        uint32 fakeEntry = fields[1].GetUInt32();
  224. +
  225. +        _fakeItemsStore[guid] = fakeEntry;
  226. +    }
  227. +    while (result->NextRow());
  228. +
  229. +    sLog->outString(">> Loaded %u fake items.", _fakeItemsStore.size());
  230. +    sLog->outString();
  231. +}
  232. +
  233.  void ObjectMgr::LoadVehicleTemplateAccessories()
  234.  {
  235.      uint32 oldMSTime = getMSTime();
  236. diff --git a/src/server/game/Globals/ObjectMgr.h b/src/server/game/Globals/ObjectMgr.h
  237. index f81e7f1..b8182a8 100755
  238. --- a/src/server/game/Globals/ObjectMgr.h
  239. +++ b/src/server/game/Globals/ObjectMgr.h
  240. @@ -402,6 +402,8 @@ typedef UNORDERED_MAP<uint32, PointOfInterestLocale> PointOfInterestLocaleContai
  241.  typedef std::multimap<uint32, uint32> QuestRelations;
  242.  typedef std::pair<QuestRelations::const_iterator, QuestRelations::const_iterator> QuestRelationBounds;
  243.  
  244. +typedef std::map<uint32, uint32> FakeItemsContainer;
  245. +
  246.  struct PetLevelInfo
  247.  {
  248.      PetLevelInfo() : health(0), mana(0) { for (uint8 i=0; i < MAX_STATS; ++i) stats[i] = 0; }
  249. @@ -641,6 +643,10 @@ class ObjectMgr
  250.              return NULL;
  251.          }
  252.  
  253. +        uint32 GetFakeItemEntry(uint32 itemGuid);
  254. +        void SetFekeItem(uint32 itemGuid, uint32 fakeEntry);
  255. +        void RemoveFakeItem(uint32 itemGuid);
  256. +
  257.          InstanceTemplate const* GetInstanceTemplate(uint32 mapId);
  258.  
  259.          PetLevelInfo const* GetPetLevelInfo(uint32 creature_id, uint8 level) const;
  260. @@ -865,6 +871,7 @@ class ObjectMgr
  261.          void LoadItemLocales();
  262.          void LoadItemSetNames();
  263.          void LoadItemSetNameLocales();
  264. +        void LoadFakeItems();
  265.          void LoadQuestLocales();
  266.          void LoadNpcTextLocales();
  267.          void LoadPageTextLocales();
  268. @@ -1301,6 +1308,7 @@ class ObjectMgr
  269.          ItemTemplateContainer _itemTemplateStore;
  270.          ItemLocaleContainer _itemLocaleStore;
  271.          ItemSetNameLocaleContainer _itemSetNameLocaleStore;
  272. +        FakeItemsContainer _fakeItemsStore;
  273.          QuestLocaleContainer _questLocaleStore;
  274.          NpcTextLocaleContainer _npcTextLocaleStore;
  275.          PageTextLocaleContainer _pageTextLocaleStore;
  276. diff --git a/src/server/game/Scripting/ScriptLoader.cpp b/src/server/game/Scripting/ScriptLoader.cpp
  277. index e5833c5..fa6a6c9 100755
  278. --- a/src/server/game/Scripting/ScriptLoader.cpp
  279. +++ b/src/server/game/Scripting/ScriptLoader.cpp
  280. @@ -38,6 +38,8 @@ void AddSC_ArgentTournament();
  281.  void AddSC_dalaran_squirrel();
  282.  // Arena Spectator
  283.  void AddSC_arena_spectator_script();
  284. +// Transmogrify
  285. +void AddSC_transmogrify_script();
  286.  
  287.  // spells
  288.  void AddSC_deathknight_spell_scripts();
  289. @@ -1271,5 +1273,6 @@ void AddCustomScripts()
  290.      AddSC_ArgentTournament();
  291.      AddSC_dalaran_squirrel();
  292.      AddSC_arena_spectator_script();
  293. +    AddSC_transmogrify_script();
  294.  #endif
  295.  }
  296. diff --git a/src/server/game/World/World.cpp b/src/server/game/World/World.cpp
  297. index bd770bf..dfec836 100755
  298. --- a/src/server/game/World/World.cpp
  299. +++ b/src/server/game/World/World.cpp
  300. @@ -1418,6 +1418,9 @@ void World::SetInitialWorldSettings()
  301.      sLog->outString("Loading Equipment templates...");
  302.      sObjectMgr->LoadEquipmentTemplates();
  303.  
  304. +    sLog->outString("Loading fake items...");
  305. +    sObjectMgr->LoadFakeItems();
  306. +
  307.      sLog->outString("Loading Creature templates...");
  308.      sObjectMgr->LoadCreatureTemplates();
  309.  
  310. diff --git a/src/server/scripts/Custom/CMakeLists.txt b/src/server/scripts/Custom/CMakeLists.txt
  311. index 24477b0..c5dde7b 100644
  312. --- a/src/server/scripts/Custom/CMakeLists.txt
  313. +++ b/src/server/scripts/Custom/CMakeLists.txt
  314. @@ -15,6 +15,7 @@ set(scripts_STAT_SRCS
  315.    Custom/argent_tournament.cpp
  316.    Custom/dalaran_squirrel.cpp
  317.    Custom/arena_spectator.cpp
  318. +  Custom/npc_transmogrify.cpp
  319.  )
  320.  
  321.  message("  -> Prepared: Custom")
  322. diff --git a/src/server/scripts/Custom/npc_transmogrify.cpp b/src/server/scripts/Custom/npc_transmogrify.cpp
  323. new file mode 100644
  324. index 0000000..fa601a8
  325. --- /dev/null
  326. +++ b/src/server/scripts/Custom/npc_transmogrify.cpp
  327. @@ -0,0 +1,134 @@
  328. +/*
  329. + * Copyright (C) 2008-2012 TrinityCore <http://www.trinitycore.org/>
  330. + * Copyright (C) 2006-2009 ScriptDev2 <https://scriptdev2.svn.sourceforge.net/>
  331. + *
  332. + * This program is free software; you can redistribute it and/or modify it
  333. + * under the terms of the GNU General Public License as published by the
  334. + * Free Software Foundation; either version 2 of the License, or (at your
  335. + * option) any later version.
  336. + *
  337. + * This program is distributed in the hope that it will be useful, but WITHOUT
  338. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  339. + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  340. + * more details.
  341. + *
  342. + * You should have received a copy of the GNU General Public License along
  343. + * with this program. If not, see <http://www.gnu.org/licenses/>.
  344. + */
  345. +
  346. +/* ScriptData
  347. +Name: Transmogrify Npc
  348. +%Complete: 100
  349. +Category: Custom Script
  350. +EndScriptData */
  351. +
  352. +#include "ScriptPCH.h"
  353. +
  354. +enum TransmogrifyActions {
  355. +    ACTION_TRANSMOGRIFY_ADD_DISPLAY,
  356. +    ACTION_TRANSMOGRIFY_REMOVE_DISPLAY
  357. +};
  358. +
  359. +const uint16 PriceInGold = 1000 * 100 * 100; // 1k golds
  360. +
  361. +class npc_transmogrify : public CreatureScript
  362. +{
  363. +    public:
  364. +        npc_transmogrify() : CreatureScript("npc_transmogrify") { }
  365. +
  366. +        bool OnGossipHello(Player* pPlayer, Creature* pCreature)
  367. +        {
  368. +            pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_MONEY_BAG, "Make exchange!", GOSSIP_SENDER_MAIN, ACTION_TRANSMOGRIFY_ADD_DISPLAY);
  369. +            pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_MONEY_BAG, "Make item clean.", GOSSIP_SENDER_MAIN, ACTION_TRANSMOGRIFY_REMOVE_DISPLAY);
  370. +            pPlayer->SEND_GOSSIP_MENU(51000, pCreature->GetGUID());
  371. +            return true;
  372. +        }
  373. +
  374. +        bool OnGossipSelect(Player* player, Creature* creature, uint32 /*sender*/, uint32 action)
  375. +        {
  376. +            player->PlayerTalkClass->SendCloseGossip();
  377. +            switch (action)
  378. +            {
  379. +                case ACTION_TRANSMOGRIFY_ADD_DISPLAY:
  380. +                    TransmogrifyItem(player, creature);
  381. +                    break;
  382. +                case ACTION_TRANSMOGRIFY_REMOVE_DISPLAY:
  383. +                    ClearItem(player, creature);
  384. +                    break;
  385. +            }
  386. +            return true;
  387. +        }
  388. +
  389. +        void TransmogrifyItem(Player* player, Creature* creature)
  390. +        {
  391. +            ChatHandler handler(player);
  392. +            Item *trItem = player->GetItemByPos(INVENTORY_SLOT_BAG_0, INVENTORY_SLOT_ITEM_START);
  393. +            Item *displayItem = player->GetItemByPos(INVENTORY_SLOT_BAG_0, INVENTORY_SLOT_ITEM_START + 1);
  394. +            if (!trItem || !displayItem)
  395. +            {
  396. +                handler.PSendSysMessage("Put item in the first and second slot!");
  397. +                return;
  398. +            }
  399. +
  400. +            if (!player->HasEnoughMoney(PriceInGold))
  401. +            {
  402. +                handler.PSendSysMessage("It costs %u gold!", PriceInGold);
  403. +                return;
  404. +            }
  405. +
  406. +            uint8 result = trItem->SetFakeDisplay(displayItem->GetTemplate()->ItemId);
  407. +            switch (result)
  408. +            {
  409. +                /*case FAKE_ERR_CANT_FIND_ITEM:
  410. +                    handler.PSendSysMessage("Cant find item!");
  411. +                    break;
  412. +                case FAKE_ERR_WRONG_QUALITY:
  413. +                    handler.PSendSysMessage("Item has wrong quality!");
  414. +                    break;
  415. +                case FAKE_ERR_DIFF_SLOTS:
  416. +                    handler.PSendSysMessage("Items has different types!");
  417. +                    break;
  418. +                case FAKE_ERR_DIFF_CLASS:
  419. +                case FAKE_ERR_DIFF_RACE:
  420. +                    handler.PSendSysMessage("Items require different options!");
  421. +                    break;*/
  422. +                case FAKE_ERR_OK:
  423. +                {
  424. +                    WorldPacket data;
  425. +                    data << uint8(INVENTORY_SLOT_BAG_0);
  426. +                    data << uint8(trItem->GetSlot());
  427. +                    player->GetSession()->HandleAutoEquipItemOpcode(data);
  428. +
  429. +                    player->ModifyMoney(-1 * PriceInGold);
  430. +                    creature->GetAI()->DoCast(63491);
  431. +
  432. +                    break;
  433. +                }
  434. +            }
  435. +        }
  436. +
  437. +        void ClearItem(Player *player, Creature* creature)
  438. +        {
  439. +            ChatHandler handler(player);
  440. +            Item *trItem = player->GetItemByPos(INVENTORY_SLOT_BAG_0, INVENTORY_SLOT_ITEM_START);
  441. +            if (!trItem)
  442. +            {
  443. +                handler.PSendSysMessage("Put item in the first slot!");
  444. +                return;
  445. +            }
  446. +
  447. +            trItem->RemoveFakeDisplay();
  448. +
  449. +            WorldPacket data;
  450. +            data << uint8(INVENTORY_SLOT_BAG_0);
  451. +            data << uint8(trItem->GetSlot());
  452. +            player->GetSession()->HandleAutoEquipItemOpcode(data);
  453. +
  454. +            creature->GetAI()->DoCast(63491);
  455. +        }
  456. +};
  457. +
  458. +void AddSC_transmogrify_script()
  459. +{
  460. +    new npc_transmogrify;
  461. +}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement