From 20a5551739d263c54b7a34fc6ff2ca56f8c60819 Mon Sep 17 00:00:00 2001 From: VladimirMangos Date: Sat, 17 Jul 2010 19:12:16 +0400 Subject: [PATCH] [10207] Implement ITEM_FLAGS2_EXT_COST_REQUIRES_GOLD use instead sign of ExtendedCost field. --- sql/mangos.sql | 4 ++-- sql/updates/10207_01_mangos_npc_vendor.sql | 7 ++++++ sql/updates/Makefile.am | 2 ++ src/game/Creature.cpp | 2 +- src/game/Creature.h | 12 ++++------ src/game/ItemHandler.cpp | 4 ++-- src/game/ItemPrototype.h | 2 +- src/game/Level2.cpp | 2 +- src/game/ObjectMgr.cpp | 26 ++++++++++++---------- src/game/ObjectMgr.h | 4 ++-- src/game/Player.cpp | 8 +++---- src/shared/revision_nr.h | 2 +- src/shared/revision_sql.h | 2 +- 13 files changed, 42 insertions(+), 35 deletions(-) create mode 100644 sql/updates/10207_01_mangos_npc_vendor.sql diff --git a/sql/mangos.sql b/sql/mangos.sql index 1d7ffdc90..2a77938d1 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_10205_01_mangos_spell_area` bit(1) default NULL + `required_10207_01_mangos_npc_vendor` bit(1) default NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='Used DB version notes'; -- @@ -3921,7 +3921,7 @@ CREATE TABLE `npc_vendor` ( `item` mediumint(8) unsigned NOT NULL default '0', `maxcount` tinyint(3) unsigned NOT NULL default '0', `incrtime` int(10) unsigned NOT NULL default '0', - `ExtendedCost` mediumint(8) NOT NULL default '0' COMMENT 'negative if cost must exclude normal money cost', + `ExtendedCost` mediumint(8) unsigned NOT NULL default '0', PRIMARY KEY (`entry`,`item`,`ExtendedCost`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='Npc System'; diff --git a/sql/updates/10207_01_mangos_npc_vendor.sql b/sql/updates/10207_01_mangos_npc_vendor.sql new file mode 100644 index 000000000..3a04e3f9f --- /dev/null +++ b/sql/updates/10207_01_mangos_npc_vendor.sql @@ -0,0 +1,7 @@ +ALTER TABLE db_version CHANGE COLUMN required_10205_01_mangos_spell_area required_10207_01_mangos_npc_vendor bit; + +UPDATE npc_vendor + SET ExtendedCost = abs(ExtendedCost) WHERE ExtendedCost < 0; + +ALTER TABLE npc_vendor + CHANGE COLUMN `ExtendedCost` `ExtendedCost` mediumint(8) unsigned NOT NULL default '0'; diff --git a/sql/updates/Makefile.am b/sql/updates/Makefile.am index 49766b898..9cdcdf323 100644 --- a/sql/updates/Makefile.am +++ b/sql/updates/Makefile.am @@ -109,6 +109,7 @@ pkgdata_DATA = \ 10197_01_mangos_playercreateinfo.sql \ 10203_01_mangos_item_template.sql \ 10205_01_mangos_spell_area.sql \ + 10207_01_mangos_npc_vendor.sql \ README ## Additional files to include when running 'make dist' @@ -198,4 +199,5 @@ EXTRA_DIST = \ 10197_01_mangos_playercreateinfo.sql \ 10203_01_mangos_item_template.sql \ 10205_01_mangos_spell_area.sql \ + 10207_01_mangos_npc_vendor.sql \ README diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp index 7d4c02538..e54c13a19 100644 --- a/src/game/Creature.cpp +++ b/src/game/Creature.cpp @@ -74,7 +74,7 @@ bool VendorItemData::RemoveItem( uint32 item_id ) return found; } -VendorItem const* VendorItemData::FindItemCostPair(uint32 item_id, int32 extendedCost) const +VendorItem const* VendorItemData::FindItemCostPair(uint32 item_id, uint32 extendedCost) const { for(VendorItemList::const_iterator i = m_items.begin(); i != m_items.end(); ++i ) if((*i)->item == item_id && (*i)->ExtendedCost == extendedCost) diff --git a/src/game/Creature.h b/src/game/Creature.h index 23d47e573..2395a0b25 100644 --- a/src/game/Creature.h +++ b/src/game/Creature.h @@ -276,17 +276,13 @@ enum AttackingTarget // Vendors struct VendorItem { - VendorItem(uint32 _item, uint32 _maxcount, uint32 _incrtime, int32 _ExtendedCost) + VendorItem(uint32 _item, uint32 _maxcount, uint32 _incrtime, uint32 _ExtendedCost) : item(_item), maxcount(_maxcount), incrtime(_incrtime), ExtendedCost(_ExtendedCost) {} uint32 item; uint32 maxcount; // 0 for infinity item amount uint32 incrtime; // time for restore items amount if maxcount != 0 - int32 ExtendedCost; // negative if need exclude normal item money cost - - // helpers - uint32 IsExcludeMoneyPrice() const { return ExtendedCost < 0; } - uint32 GetExtendedCostId() const { return std::abs(ExtendedCost); } + uint32 ExtendedCost; // index in ItemExtendedCost.dbc }; typedef std::vector VendorItemList; @@ -301,12 +297,12 @@ struct VendorItemData } bool Empty() const { return m_items.empty(); } uint8 GetItemCount() const { return m_items.size(); } - void AddItem( uint32 item, uint32 maxcount, uint32 ptime, int32 ExtendedCost) + void AddItem( uint32 item, uint32 maxcount, uint32 ptime, uint32 ExtendedCost) { m_items.push_back(new VendorItem(item, maxcount, ptime, ExtendedCost)); } bool RemoveItem( uint32 item_id ); - VendorItem const* FindItemCostPair(uint32 item_id, int32 extendedCost) const; + VendorItem const* FindItemCostPair(uint32 item_id, uint32 extendedCost) const; void Clear() { diff --git a/src/game/ItemHandler.cpp b/src/game/ItemHandler.cpp index ff482f9a6..40cc602bf 100644 --- a/src/game/ItemHandler.cpp +++ b/src/game/ItemHandler.cpp @@ -781,7 +781,7 @@ void WorldSession::SendListInventory(uint64 vendorguid) ++count; // reputation discount - uint32 price = crItem->IsExcludeMoneyPrice() ? 0 : uint32(floor(pProto->BuyPrice * discountMod)); + uint32 price = (crItem->ExtendedCost == 0 || pProto->Flags2 & ITEM_FLAGS2_EXT_COST_REQUIRES_GOLD) ? uint32(floor(pProto->BuyPrice * discountMod)) : 0; data << uint32(vendorslot +1); // client size expected counting from 1 data << uint32(crItem->item); @@ -790,7 +790,7 @@ void WorldSession::SendListInventory(uint64 vendorguid) data << uint32(price); data << uint32(pProto->MaxDurability); data << uint32(pProto->BuyCount); - data << uint32(crItem->GetExtendedCostId()); + data << uint32(crItem->ExtendedCost); } } } diff --git a/src/game/ItemPrototype.h b/src/game/ItemPrototype.h index 5857fc34e..0237bb3e4 100644 --- a/src/game/ItemPrototype.h +++ b/src/game/ItemPrototype.h @@ -484,7 +484,7 @@ enum ItemExtraFlags ITEM_EXTRA_NON_CONSUMABLE = 0x01, // use as additional flag to spellcharges_N negative values, item not expire at no chanrges ITEM_EXTRA_REAL_TIME_DURATION = 0x02, // if set and have Duration time, then offline time included in counting, if not set then counted only in game time - ITEM_EXTRA_ALL // all used flags, used for check DB data + ITEM_EXTRA_ALL = 0x03 // all used flags, used for check DB data (mask all above flags) }; // GCC have alternative #pragma pack(N) syntax and old gcc version not support pack(push,N), also any gcc version not support it at some platform diff --git a/src/game/Level2.cpp b/src/game/Level2.cpp index 03a8c8a96..b7c037414 100644 --- a/src/game/Level2.cpp +++ b/src/game/Level2.cpp @@ -1161,7 +1161,7 @@ bool ChatHandler::HandleNpcAddVendorItemCommand(const char* args) incrtime = atol(fincrtime); char* fextendedcost = strtok(NULL, " "); //add ExtendedCost, default: 0 - int32 extendedcost = fextendedcost ? atol(fextendedcost) : 0; + uint32 extendedcost = fextendedcost ? atol(fextendedcost) : 0; Creature* vendor = getSelectedCreature(); diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp index facd70bfa..5746f7d86 100644 --- a/src/game/ObjectMgr.cpp +++ b/src/game/ObjectMgr.cpp @@ -8178,7 +8178,7 @@ void ObjectMgr::LoadVendors() uint32 item_id = fields[1].GetUInt32(); uint32 maxcount = fields[2].GetUInt32(); uint32 incrtime = fields[3].GetUInt32(); - int32 ExtendedCost = fields[4].GetInt32(); + uint32 ExtendedCost = fields[4].GetUInt32(); if(!IsVendorItemValid(entry,item_id,maxcount,incrtime,ExtendedCost,NULL,&skip_vendors)) continue; @@ -8456,12 +8456,12 @@ void ObjectMgr::LoadGossipMenuItems() sLog.outString(">> Loaded %u gossip_menu_option entries", count); } -void ObjectMgr::AddVendorItem( uint32 entry,uint32 item, uint32 maxcount, uint32 incrtime, int32 extendedcost ) +void ObjectMgr::AddVendorItem( uint32 entry,uint32 item, uint32 maxcount, uint32 incrtime, uint32 extendedcost ) { VendorItemData& vList = m_mCacheVendorItemMap[entry]; vList.AddItem(item,maxcount,incrtime,extendedcost); - WorldDatabase.PExecuteLog("INSERT INTO npc_vendor (entry,item,maxcount,incrtime,extendedcost) VALUES('%u','%u','%u','%u','%i')",entry, item, maxcount,incrtime,extendedcost); + WorldDatabase.PExecuteLog("INSERT INTO npc_vendor (entry,item,maxcount,incrtime,extendedcost) VALUES('%u','%u','%u','%u','%u')",entry, item, maxcount,incrtime,extendedcost); } bool ObjectMgr::RemoveVendorItem( uint32 entry,uint32 item ) @@ -8477,7 +8477,7 @@ bool ObjectMgr::RemoveVendorItem( uint32 entry,uint32 item ) return true; } -bool ObjectMgr::IsVendorItemValid( uint32 vendor_entry, uint32 item_id, uint32 maxcount, uint32 incrtime, int32 ExtendedCost, Player* pl, std::set* skip_vendors ) const +bool ObjectMgr::IsVendorItemValid( uint32 vendor_entry, uint32 item_id, uint32 maxcount, uint32 incrtime, uint32 ExtendedCost, Player* pl, std::set* skip_vendors ) const { CreatureInfo const* cInfo = GetCreatureTemplate(vendor_entry); if(!cInfo) @@ -8509,18 +8509,18 @@ bool ObjectMgr::IsVendorItemValid( uint32 vendor_entry, uint32 item_id, uint32 m if(pl) ChatHandler(pl).PSendSysMessage(LANG_ITEM_NOT_FOUND, item_id); else - sLog.outErrorDb("Table `npc_vendor` for vendor (Entry: %u) contain nonexistent item (%u), ignoring",vendor_entry,item_id); + sLog.outErrorDb("Table `npc_vendor` for vendor (Entry: %u) contain nonexistent item (%u), ignoring", + vendor_entry, item_id); return false; } - uint32 extCostId = std::abs(ExtendedCost); // negative exclude for vendor price money part - - if(extCostId && !sItemExtendedCostStore.LookupEntry(extCostId)) + if(ExtendedCost && !sItemExtendedCostStore.LookupEntry(ExtendedCost)) { if(pl) - ChatHandler(pl).PSendSysMessage(LANG_EXTENDED_COST_NOT_EXIST,extCostId); + ChatHandler(pl).PSendSysMessage(LANG_EXTENDED_COST_NOT_EXIST,ExtendedCost); else - sLog.outErrorDb("Table `npc_vendor` contain item (Entry: %u) with wrong ExtendedCost (%u) for vendor (%u), ignoring",item_id,extCostId,vendor_entry); + sLog.outErrorDb("Table `npc_vendor` contain item (Entry: %u) with wrong ExtendedCost (%u) for vendor (%u), ignoring", + item_id, ExtendedCost, vendor_entry); return false; } @@ -8529,7 +8529,8 @@ bool ObjectMgr::IsVendorItemValid( uint32 vendor_entry, uint32 item_id, uint32 m if(pl) ChatHandler(pl).PSendSysMessage("MaxCount!=0 (%u) but IncrTime==0", maxcount); else - sLog.outErrorDb( "Table `npc_vendor` has `maxcount` (%u) for item %u of vendor (Entry: %u) but `incrtime`=0, ignoring", maxcount, item_id, vendor_entry); + sLog.outErrorDb( "Table `npc_vendor` has `maxcount` (%u) for item %u of vendor (Entry: %u) but `incrtime`=0, ignoring", + maxcount, item_id, vendor_entry); return false; } else if(maxcount==0 && incrtime > 0) @@ -8537,7 +8538,8 @@ bool ObjectMgr::IsVendorItemValid( uint32 vendor_entry, uint32 item_id, uint32 m if(pl) ChatHandler(pl).PSendSysMessage("MaxCount==0 but IncrTime<>=0"); else - sLog.outErrorDb( "Table `npc_vendor` has `maxcount`=0 for item %u of vendor (Entry: %u) but `incrtime`<>0, ignoring", item_id, vendor_entry); + sLog.outErrorDb( "Table `npc_vendor` has `maxcount`=0 for item %u of vendor (Entry: %u) but `incrtime`<>0, ignoring", + item_id, vendor_entry); return false; } diff --git a/src/game/ObjectMgr.h b/src/game/ObjectMgr.h index 78b79b91b..9afc138da 100644 --- a/src/game/ObjectMgr.h +++ b/src/game/ObjectMgr.h @@ -939,9 +939,9 @@ class ObjectMgr return &iter->second; } - void AddVendorItem(uint32 entry,uint32 item, uint32 maxcount, uint32 incrtime, int32 ExtendedCost); + void AddVendorItem(uint32 entry,uint32 item, uint32 maxcount, uint32 incrtime, uint32 ExtendedCost); bool RemoveVendorItem(uint32 entry,uint32 item); - bool IsVendorItemValid( uint32 vendor_entry, uint32 item, uint32 maxcount, uint32 ptime, int32 ExtendedCost, Player* pl = NULL, std::set* skip_vendors = NULL ) const; + bool IsVendorItemValid( uint32 vendor_entry, uint32 item, uint32 maxcount, uint32 ptime, uint32 ExtendedCost, Player* pl = NULL, std::set* skip_vendors = NULL ) const; void LoadScriptNames(); ScriptNameMap &GetScriptNames() { return m_scriptNames; } diff --git a/src/game/Player.cpp b/src/game/Player.cpp index 2f6f87911..d0815de26 100644 --- a/src/game/Player.cpp +++ b/src/game/Player.cpp @@ -18539,7 +18539,7 @@ bool Player::BuyItemFromVendorSlot(uint64 vendorguid, uint32 vendorslot, uint32 return false; } - if (uint32 extendedCostId = crItem->GetExtendedCostId()) + if (uint32 extendedCostId = crItem->ExtendedCost) { ItemExtendedCostEntry const* iece = sItemExtendedCostStore.LookupEntry(extendedCostId); if (!iece) @@ -18581,7 +18581,7 @@ bool Player::BuyItemFromVendorSlot(uint64 vendorguid, uint32 vendorslot, uint32 } } - uint32 price = crItem->IsExcludeMoneyPrice() ? 0 : pProto->BuyPrice * count; + uint32 price = (crItem->ExtendedCost == 0 || pProto->Flags2 & ITEM_FLAGS2_EXT_COST_REQUIRES_GOLD) ? pProto->BuyPrice * count : 0; // reputation discount if (price) @@ -18604,7 +18604,7 @@ bool Player::BuyItemFromVendorSlot(uint64 vendorguid, uint32 vendorslot, uint32 } ModifyMoney( -(int32)price ); - if (uint32 extendedCostId = crItem->GetExtendedCostId()) + if (uint32 extendedCostId = crItem->ExtendedCost) { ItemExtendedCostEntry const* iece = sItemExtendedCostStore.LookupEntry(extendedCostId); if (iece->reqhonorpoints) @@ -18649,7 +18649,7 @@ bool Player::BuyItemFromVendorSlot(uint64 vendorguid, uint32 vendorslot, uint32 } ModifyMoney( -(int32)price ); - if (uint32 extendedCostId = crItem->GetExtendedCostId()) + if (uint32 extendedCostId = crItem->ExtendedCost) { ItemExtendedCostEntry const* iece = sItemExtendedCostStore.LookupEntry(extendedCostId); if (iece->reqhonorpoints) diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index d8053679e..9f63c8a92 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 "10206" + #define REVISION_NR "10207" #endif // __REVISION_NR_H__ diff --git a/src/shared/revision_sql.h b/src/shared/revision_sql.h index 5a64934c2..b06a76f18 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_10160_02_characters_pet_aura" - #define REVISION_DB_MANGOS "required_10205_01_mangos_spell_area" + #define REVISION_DB_MANGOS "required_10207_01_mangos_npc_vendor" #define REVISION_DB_REALMD "required_10008_01_realmd_realmd_db_version" #endif // __REVISION_SQL_H__