Jump to content

[Help] "Destructible" items based on duration


Guest cmaranec

Recommended Posts

Is there any patch for items, that has some duration and after this duration item disappears and automaticaly creates a new item?

For example http://www.wowhead.com/?item=39878 changes into http://www.wowhead.com/?item=39883

If there's no patch, how should i make it? Should i do it the same way like classical "duration-destructed" items? (in Item.cpp in UpdteItemDuration)

Sorry for my English, i'm Czech

Link to comment
Share on other sites

So there's my first attempt:

From 7efabcff3117c03a8f417c3b01cd4f24489fea12 Mon Sep 17 00:00:00 2001
From: Cmaranec <[email protected]>
Date: Sat, 27 Feb 2010 21:04:24 +0100
Subject: [PATCH] Added support for item change after duration expires

---
sql/item_duration_changes.sql |    6 +++++
src/game/Item.cpp             |    7 ++++++
src/game/Item.h               |    1 +
src/game/ObjectMgr.cpp        |   43 +++++++++++++++++++++++++++++++++++++++++
src/game/ObjectMgr.h          |   19 ++++++++++++++++++
src/game/World.cpp            |    3 ++
6 files changed, 79 insertions(+), 0 deletions(-)
create mode 100644 sql/item_duration_changes.sql

diff --git a/sql/item_duration_changes.sql b/sql/item_duration_changes.sql
new file mode 100644
index 0000000..3c8c952
--- /dev/null
+++ b/sql/item_duration_changes.sql
@@ -0,0 +1,6 @@
+DROP TABLE IF EXISTS `item_duration_changes`;
+CREATE TABLE `item_duration_changes` (
+  `item` mediumint(8) unsigned NOT NULL default '0' COMMENT 'Item id with set duration',
+  `changed_item` mediumint(8) unsigned NOT NULL default '0' COMMENT 'Item id to which should source item change',
+  PRIMARY KEY (`item`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='Item duration changes system';
diff --git a/src/game/Item.cpp b/src/game/Item.cpp
index 10eef36..5fc872b 100644
--- a/src/game/Item.cpp
+++ b/src/game/Item.cpp
@@ -273,6 +273,11 @@ bool Item::Create( uint32 guidlow, uint32 itemid, Player const* owner)
    return true;
}

+uint32 Item::GetDurationChange()
+{
+    return sObjectMgr.GetItemDurationChange(this->GetEntry()); 
+}
+
void Item::UpdateDuration(Player* owner, uint32 diff)
{
    if (!GetUInt32Value(ITEM_FIELD_DURATION))
@@ -283,6 +288,8 @@ void Item::UpdateDuration(Player* owner, uint32 diff)
    if (GetUInt32Value(ITEM_FIELD_DURATION)<=diff)
    {
        owner->DestroyItem(GetBagSlot(), GetSlot(), true);
+        if(uint32 ChangedItem = GetDurationChange())
+            owner->StoreNewItemInBestSlots(ChangedItem,1);
        return;
    }

diff --git a/src/game/Item.h b/src/game/Item.h
index 409f8ce..8981925 100644
--- a/src/game/Item.h
+++ b/src/game/Item.h
@@ -272,6 +272,7 @@ class MANGOS_DLL_SPEC Item : public Object
        void SetSlot(uint8 slot) {m_slot = slot;}
        uint16 GetPos() const { return uint16(GetBagSlot()) << 8 | GetSlot(); }
        void SetContainer(Bag *container) { m_container = container; }
+        uint32 GetDurationChange();

        bool IsInBag() const { return m_container != NULL; }
        bool IsEquipped() const;
diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp
index b887961..f9a900e 100644
--- a/src/game/ObjectMgr.cpp
+++ b/src/game/ObjectMgr.cpp
@@ -4523,6 +4523,49 @@ void ObjectMgr::LoadItemTexts()
    sLog.outString( ">> Loaded %u item texts", count );
}

+void ObjectMgr::LoadItemDurationChanges()
+{
+    QueryResult *result = WorldDatabase.Query("SELECT item, changed_item FROM item_duration_changes");
+
+    mItemDurationChanges.clear();
+
+    uint32 count = 0;
+
+    if( !result )
+    {
+        barGoLink bar( 1 );
+        bar.step();
+
+        sLog.outString();
+        sLog.outString( ">> Loaded %u item duration changes", count );
+        return;
+    }
+
+    barGoLink bar( result->GetRowCount() );
+
+    Field* fields;
+    do
+    {
+        bar.step();
+
+        fields = result->Fetch();
+
+        ItemDurationChanges temp;
+        temp.source_item = fields[0].GetUInt32();
+        temp.changed_item = fields[1].GetUInt32();
+
+        mItemDurationChanges.push_back(temp);
+
+        ++count;
+
+    } while ( result->NextRow() );
+
+    delete result;
+
+    sLog.outString();
+    sLog.outString( ">> Loaded %u item duration changes", count );
+}
+
void ObjectMgr::LoadPageTexts()
{
    sPageTextStore.Free();                                  // for reload case
diff --git a/src/game/ObjectMgr.h b/src/game/ObjectMgr.h
index 4442f56..376ab38 100644
--- a/src/game/ObjectMgr.h
+++ b/src/game/ObjectMgr.h
@@ -366,6 +366,12 @@ struct MANGOS_DLL_SPEC LanguageDesc
    uint32   skill_id;
};

+struct ItemDurationChanges
+{
+    uint32 source_item;
+    uint32 changed_item;
+};
+
extern LanguageDesc lang_description[LANGUAGES_COUNT];
MANGOS_DLL_SPEC LanguageDesc const* GetLanguageDescByID(uint32 lang);

@@ -591,6 +597,7 @@ class ObjectMgr
        void LoadGameobjects();
        void LoadGameobjectRespawnTimes();
        void LoadItemPrototypes();
+        void LoadItemDurationChanges();
        void LoadItemRequiredTarget();
        void LoadItemLocales();
        void LoadQuestLocales();
@@ -846,6 +853,17 @@ class ObjectMgr
            return &iter->second;
        }

+        uint32 GetItemDurationChange(uint32 item)
+        {
+            for(std::list<ItemDurationChanges>::const_iterator itr = mItemDurationChanges.begin();
+                itr != mItemDurationChanges.end(); ++itr)
+            {
+                if(itr->source_item == item)
+                    return itr->changed_item;
+            }
+            return NULL;
+        }
+
        VendorItemData const* GetNpcVendorItemList(uint32 entry) const
        {
            CacheVendorItemMap::const_iterator  iter = m_mCacheVendorItemMap.find(entry);
@@ -917,6 +935,7 @@ class ObjectMgr
        ArenaTeamMap        mArenaTeamMap;

        ItemTextMap         mItemTexts;
+        std::list<ItemDurationChanges> mItemDurationChanges;

        QuestAreaTriggerMap mQuestAreaTriggerMap;
        TavernAreaTriggerSet mTavernAreaTriggerSet;
diff --git a/src/game/World.cpp b/src/game/World.cpp
index b1605d5..5e317a6 100644
--- a/src/game/World.cpp
+++ b/src/game/World.cpp
@@ -975,6 +975,9 @@ void World::SetInitialWorldSettings()
    sLog.outString( "Loading Item Texts..." );
    sObjectMgr.LoadItemTexts();

+    sLog.outString( "Loading Item Duration Changes..." );
+    sObjectMgr.LoadItemDurationChanges();
+
    sLog.outString( "Loading Creature Model Based Info Data..." );
    sObjectMgr.LoadCreatureModelInfo();

-- 
1.6.4

Works with newest revision (9467)

SQL file for import will be created by this patch to sql directory of mangos

Link to comment
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use