From 2d7768a5abad6f79f3ffe068b7b35c16303c1110 Mon Sep 17 00:00:00 2001 From: cmaranec Date: Sat, 18 Jun 2011 21:11:23 +0400 Subject: [PATCH] [11646] Implement support item converting at expire Example: items 44623->44625->44627 convertion chain * New table `item_enchantment_template` store original->final item pairs Original item must have duration setup. * Small change in GetItemConvert for consistence (now 0 returned if no convert pair instead original entry id) Signed-off-by: VladimirMangos --- sql/mangos.sql | 24 +++++++- .../11646_01_mangos_item_expire_convert.sql | 10 ++++ src/game/Item.cpp | 5 +- src/game/ItemHandler.cpp | 4 +- src/game/ObjectMgr.cpp | 60 +++++++++++++++++++ src/game/ObjectMgr.h | 14 ++++- src/game/Player.cpp | 2 +- src/game/World.cpp | 7 ++- src/shared/revision_nr.h | 2 +- src/shared/revision_sql.h | 2 +- 10 files changed, 117 insertions(+), 13 deletions(-) create mode 100644 sql/updates/11646_01_mangos_item_expire_convert.sql diff --git a/sql/mangos.sql b/sql/mangos.sql index 8d7c432d6..b0bd28cc1 100644 --- a/sql/mangos.sql +++ b/sql/mangos.sql @@ -24,7 +24,7 @@ CREATE TABLE `db_version` ( `version` varchar(120) default NULL, `creature_ai_version` varchar(120) default NULL, `cache_id` int(10) default '0', - `required_11613_01_mangos_spell_bonus_data` bit(1) default NULL + `required_11646_01_mangos_item_expire_convert` bit(1) default NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='Used DB version notes'; -- @@ -2193,7 +2193,7 @@ CREATE TABLE `item_convert` ( `entry` mediumint(8) unsigned NOT NULL default '0', `item` mediumint(8) unsigned NOT NULL default '0', PRIMARY KEY (`entry`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='Npc System'; +) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='Item Convert System'; -- -- Dumping data for table `item_convert` @@ -2225,6 +2225,26 @@ LOCK TABLES `item_enchantment_template` WRITE; /*!40000 ALTER TABLE `item_enchantment_template` ENABLE KEYS */; UNLOCK TABLES; +-- +-- Table structure for table `item_expire_convert` +-- + +DROP TABLE IF EXISTS `item_expire_convert`; +CREATE TABLE `item_expire_convert` ( + `entry` mediumint(8) unsigned NOT NULL default '0', + `item` mediumint(8) unsigned NOT NULL default '0', + PRIMARY KEY (`entry`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='Item Convert System'; + +-- +-- Dumping data for table `item_convert` +-- + +LOCK TABLES `item_convert` WRITE; +/*!40000 ALTER TABLE `item_convert` DISABLE KEYS */; +/*!40000 ALTER TABLE `item_convert` ENABLE KEYS */; +UNLOCK TABLES; + -- -- Table structure for table `item_loot_template` -- diff --git a/sql/updates/11646_01_mangos_item_expire_convert.sql b/sql/updates/11646_01_mangos_item_expire_convert.sql new file mode 100644 index 000000000..8adff31ef --- /dev/null +++ b/sql/updates/11646_01_mangos_item_expire_convert.sql @@ -0,0 +1,10 @@ +ALTER TABLE db_version CHANGE COLUMN required_11613_01_mangos_spell_bonus_data required_11646_01_mangos_item_expire_convert bit; + +DROP TABLE IF EXISTS `item_expire_convert`; +CREATE TABLE `item_expire_convert` ( + `entry` mediumint(8) unsigned NOT NULL default '0', + `item` mediumint(8) unsigned NOT NULL default '0', + PRIMARY KEY (`entry`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='Item Convert System'; + +INSERT INTO `item_expire_convert` VALUES (44623, 44625), (44625, 44627); \ No newline at end of file diff --git a/src/game/Item.cpp b/src/game/Item.cpp index 645ce8b65..7035efb64 100644 --- a/src/game/Item.cpp +++ b/src/game/Item.cpp @@ -280,7 +280,10 @@ void Item::UpdateDuration(Player* owner, uint32 diff) if (GetUInt32Value(ITEM_FIELD_DURATION) <= diff) { - owner->DestroyItem(GetBagSlot(), GetSlot(), true); + if (uint32 newItemId = sObjectMgr.GetItemExpireConvert(GetEntry())) + owner->ConvertItem(this, newItemId); + else + owner->DestroyItem(GetBagSlot(), GetSlot(), true); return; } diff --git a/src/game/ItemHandler.cpp b/src/game/ItemHandler.cpp index bf67be8e2..35b9194ba 100644 --- a/src/game/ItemHandler.cpp +++ b/src/game/ItemHandler.cpp @@ -801,9 +801,9 @@ void WorldSession::SendListInventory(ObjectGuid vendorguid) // convert if can use and then buy if (pProto->RequiredReputationFaction && uint32(_player->GetReputationRank(pProto->RequiredReputationFaction)) >= pProto->RequiredReputationRank) { - itemId = sObjectMgr.GetItemConvert(itemId, _player->getRaceMask()); // checked at convert data loading as existed - pProto = ObjectMgr::GetItemPrototype(itemId); + if (uint32 newItemId = sObjectMgr.GetItemConvert(itemId, _player->getRaceMask())) + pProto = ObjectMgr::GetItemPrototype(newItemId); } } diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp index b121a6812..006a76557 100644 --- a/src/game/ObjectMgr.cpp +++ b/src/game/ObjectMgr.cpp @@ -2408,6 +2408,66 @@ void ObjectMgr::LoadItemConverts() sLog.outString(">> Loaded %u Item converts", count); } +void ObjectMgr::LoadItemExpireConverts() +{ + m_ItemExpireConvert.clear(); // needed for reload case + + uint32 count = 0; + + QueryResult *result = WorldDatabase.Query("SELECT entry,item FROM item_expire_convert"); + + if (!result) + { + BarGoLink bar(1); + + bar.step(); + + sLog.outString(); + sLog.outErrorDb(">> Loaded 0 Item expire converts . DB table `item_expire_convert` is empty."); + return; + } + + BarGoLink bar(result->GetRowCount()); + + do + { + Field *fields = result->Fetch(); + bar.step(); + + uint32 itemEntry = fields[0].GetUInt32(); + uint32 itemTargetId = fields[1].GetUInt32(); + + ItemPrototype const* pItemEntryProto = sItemStorage.LookupEntry(itemEntry); + if (!pItemEntryProto) + { + sLog.outErrorDb("Table `item_expire_convert`: Item %u not exist in `item_template`.", itemEntry); + continue; + } + + ItemPrototype const* pItemTargetProto = sItemStorage.LookupEntry(itemTargetId); + if (!pItemTargetProto) + { + sLog.outErrorDb("Table `item_expire_convert`: Item target %u for original item %u not exist in `item_template`.", itemTargetId, itemEntry); + continue; + } + + // Expire convert possible only for items with duration + if (pItemEntryProto->Duration == 0) + { + sLog.outErrorDb("Table `item_expire_convert` not appropriate item %u conversion to %u. Table can be used for items with duration.", itemEntry, itemTargetId); + continue; + } + + m_ItemExpireConvert[itemEntry] = itemTargetId; + + ++count; + } while (result->NextRow()); + + delete result; + + sLog.outString(); + sLog.outString(">> Loaded %u Item expire converts", count); +} void ObjectMgr::LoadItemRequiredTarget() { diff --git a/src/game/ObjectMgr.h b/src/game/ObjectMgr.h index 2233a0499..64df71141 100644 --- a/src/game/ObjectMgr.h +++ b/src/game/ObjectMgr.h @@ -642,8 +642,9 @@ class ObjectMgr void LoadEquipmentTemplates(); void LoadGameObjectLocales(); void LoadGameobjects(); - void LoadItemConverts(); void LoadItemPrototypes(); + void LoadItemConverts(); + void LoadItemExpireConverts(); void LoadItemRequiredTarget(); void LoadItemLocales(); void LoadQuestLocales(); @@ -979,10 +980,16 @@ class ObjectMgr { ItemConvertMap::const_iterator iter = m_ItemConvert.find(itemEntry); if (iter == m_ItemConvert.end()) - return itemEntry; + return 0; ItemPrototype const* proto = GetItemPrototype(iter->second); - return (proto && proto->AllowableRace & raceMask) ? iter->second : itemEntry; + return (proto && proto->AllowableRace & raceMask) ? iter->second : 0; + } + + uint32 GetItemExpireConvert(uint32 itemEntry) const + { + ItemConvertMap::const_iterator iter = m_ItemExpireConvert.find(itemEntry); + return iter != m_ItemExpireConvert.end() ? iter->second : 0; } ItemRequiredTargetMapBounds GetItemRequiredTargetMapBounds(uint32 uiItemEntry) const @@ -1095,6 +1102,7 @@ class ObjectMgr SpellClickInfoMap mSpellClickInfoMap; ItemConvertMap m_ItemConvert; + ItemConvertMap m_ItemExpireConvert; ItemRequiredTargetMap m_ItemRequiredTarget; typedef std::vector LocalForIndex; diff --git a/src/game/Player.cpp b/src/game/Player.cpp index c6d67cfd0..33e638ca6 100644 --- a/src/game/Player.cpp +++ b/src/game/Player.cpp @@ -19194,7 +19194,7 @@ bool Player::BuyItemFromVendorSlot(ObjectGuid vendorGuid, uint32 vendorslot, uin ItemPrototype const* crProto = ObjectMgr::GetItemPrototype(crItem->item); if (crProto->Flags & ITEM_FLAG_BOA && crProto->RequiredReputationFaction && uint32(GetReputationRank(crProto->RequiredReputationFaction)) >= crProto->RequiredReputationRank) - converted = item == sObjectMgr.GetItemConvert(crItem->item, getRaceMask()); + converted = (sObjectMgr.GetItemConvert(crItem->item, getRaceMask()) != 0); if (!converted) { diff --git a/src/game/World.cpp b/src/game/World.cpp index 104b8a807..9c1540b9e 100644 --- a/src/game/World.cpp +++ b/src/game/World.cpp @@ -1010,12 +1010,15 @@ void World::SetInitialWorldSettings() sLog.outString( "Loading Item Random Enchantments Table..." ); LoadRandomEnchantmentsTable(); - sLog.outString( "Loading Items..." ); // must be after LoadRandomEnchantmentsTable and LoadPageTexts + sLog.outString("Loading Items..."); // must be after LoadRandomEnchantmentsTable and LoadPageTexts sObjectMgr.LoadItemPrototypes(); - sLog.outString( "Loading Item converts..." ); // must be after LoadItemPrototypes + sLog.outString("Loading Item converts..."); // must be after LoadItemPrototypes sObjectMgr.LoadItemConverts(); + sLog.outString("Loading Item expire converts..."); // must be after LoadItemPrototypes + sObjectMgr.LoadItemExpireConverts(); + sLog.outString( "Loading Creature Model Based Info Data..." ); sObjectMgr.LoadCreatureModelInfo(); diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 74bdbb348..3d2008666 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "11645" + #define REVISION_NR "11646" #endif // __REVISION_NR_H__ diff --git a/src/shared/revision_sql.h b/src/shared/revision_sql.h index eb5085920..48d30ae83 100644 --- a/src/shared/revision_sql.h +++ b/src/shared/revision_sql.h @@ -1,6 +1,6 @@ #ifndef __REVISION_SQL_H__ #define __REVISION_SQL_H__ #define REVISION_DB_CHARACTERS "required_11620_01_characters_character_equipmentsets" - #define REVISION_DB_MANGOS "required_11613_01_mangos_spell_bonus_data" + #define REVISION_DB_MANGOS "required_11646_01_mangos_item_expire_convert" #define REVISION_DB_REALMD "required_10008_01_realmd_realmd_db_version" #endif // __REVISION_SQL_H__