diff --git a/sql/mangos.sql b/sql/mangos.sql index 869c1e5ae..cdda41786 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_9924_02_mangos_command` bit(1) default NULL + `required_9957_02_mangos_npc_vendor` bit(1) default NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='Used DB version notes'; -- @@ -3116,7 +3116,7 @@ INSERT INTO `mangos_string` VALUES (207,'Item \'%i\' not found in database.',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL), (208,'Item \'%i\' \'%s\' deleted from vendor list',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL), (209,'Item \'%i\' not found in vendor list.',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL), -(210,'Item \'%i\' (with extended cost %u) already in vendor list.',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL), +(210,'Item \'%i\' (with extended cost %i) already in vendor list.',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL), (211,'Spells of %s reset.',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL), (212,'Spells of %s will reset at next login.',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL), (213,'Talents of %s reset.',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL), @@ -3889,7 +3889,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) unsigned NOT NULL default '0', + `ExtendedCost` mediumint(8) NOT NULL default '0' COMMENT 'negative if cost must exclude normal money cost', PRIMARY KEY (`entry`,`item`,`ExtendedCost`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='Npc System'; diff --git a/sql/updates/9957_01_mangos_mangos_string.sql b/sql/updates/9957_01_mangos_mangos_string.sql new file mode 100644 index 000000000..cc3c99285 --- /dev/null +++ b/sql/updates/9957_01_mangos_mangos_string.sql @@ -0,0 +1,5 @@ +ALTER TABLE db_version CHANGE COLUMN required_9924_02_mangos_command required_9957_01_mangos_mangos_string bit; + +DELETE FROM mangos_string WHERE entry IN (210); +INSERT INTO mangos_string VALUES +(210,'Item \'%i\' (with extended cost %i) already in vendor list.',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL); diff --git a/sql/updates/9957_02_mangos_npc_vendor.sql b/sql/updates/9957_02_mangos_npc_vendor.sql new file mode 100644 index 000000000..25c829702 --- /dev/null +++ b/sql/updates/9957_02_mangos_npc_vendor.sql @@ -0,0 +1,4 @@ +ALTER TABLE db_version CHANGE COLUMN required_9957_01_mangos_mangos_string required_9957_02_mangos_npc_vendor bit; + +ALTER TABLE npc_vendor + CHANGE COLUMN `ExtendedCost` `ExtendedCost` mediumint(8) NOT NULL default '0' COMMENT 'negative if cost must exclude normal money cost'; diff --git a/sql/updates/Makefile.am b/sql/updates/Makefile.am index d93037252..1b392463f 100644 --- a/sql/updates/Makefile.am +++ b/sql/updates/Makefile.am @@ -67,6 +67,8 @@ pkgdata_DATA = \ 9899_01_mangos_spell_bonus_data.sql \ 9924_01_mangos_mangos_string.sql \ 9924_02_mangos_command.sql \ + 9957_01_mangos_mangos_string.sql \ + 9957_02_mangos_npc_vendor.sql \ README ## Additional files to include when running 'make dist' @@ -114,4 +116,6 @@ EXTRA_DIST = \ 9899_01_mangos_spell_bonus_data.sql \ 9924_01_mangos_mangos_string.sql \ 9924_02_mangos_command.sql \ + 9957_01_mangos_mangos_string.sql \ + 9957_02_mangos_npc_vendor.sql \ README diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp index 3c58d47a6..9664e250d 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, uint32 extendedCost) const +VendorItem const* VendorItemData::FindItemCostPair(uint32 item_id, int32 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 3bb0591de..c6dff5dfc 100644 --- a/src/game/Creature.h +++ b/src/game/Creature.h @@ -276,13 +276,17 @@ enum AttackingTarget // Vendors struct VendorItem { - VendorItem(uint32 _item, uint32 _maxcount, uint32 _incrtime, uint32 _ExtendedCost) + VendorItem(uint32 _item, uint32 _maxcount, uint32 _incrtime, int32 _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 - uint32 ExtendedCost; + int32 ExtendedCost; // negative if need exclude normal item money cost + + // helpers + uint32 IsExcludeMoneyPrice() const { return ExtendedCost < 0; } + uint32 GetExtendedCostId() const { return std::abs(ExtendedCost); } }; typedef std::vector VendorItemList; @@ -297,12 +301,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, uint32 ExtendedCost) + void AddItem( uint32 item, uint32 maxcount, uint32 ptime, int32 ExtendedCost) { m_items.push_back(new VendorItem(item, maxcount, ptime, ExtendedCost)); } bool RemoveItem( uint32 item_id ); - VendorItem const* FindItemCostPair(uint32 item_id, uint32 extendedCost) const; + VendorItem const* FindItemCostPair(uint32 item_id, int32 extendedCost) const; void Clear() { diff --git a/src/game/ItemHandler.cpp b/src/game/ItemHandler.cpp index 1d04c1460..f6935004e 100644 --- a/src/game/ItemHandler.cpp +++ b/src/game/ItemHandler.cpp @@ -760,7 +760,7 @@ void WorldSession::SendListInventory(uint64 vendorguid) ++count; // reputation discount - uint32 price = uint32(floor(pProto->BuyPrice * discountMod)); + uint32 price = crItem->IsExcludeMoneyPrice() ? 0 : uint32(floor(pProto->BuyPrice * discountMod)); data << uint32(vendorslot +1); // client size expected counting from 1 data << uint32(crItem->item); @@ -769,7 +769,7 @@ void WorldSession::SendListInventory(uint64 vendorguid) data << uint32(price); data << uint32(pProto->MaxDurability); data << uint32(pProto->BuyCount); - data << uint32(crItem->ExtendedCost); + data << uint32(crItem->GetExtendedCostId()); } } } diff --git a/src/game/Level2.cpp b/src/game/Level2.cpp index 944950e8f..bba39a064 100644 --- a/src/game/Level2.cpp +++ b/src/game/Level2.cpp @@ -1129,7 +1129,7 @@ bool ChatHandler::HandleNpcAddVendorItemCommand(const char* args) incrtime = atol(fincrtime); char* fextendedcost = strtok(NULL, " "); //add ExtendedCost, default: 0 - uint32 extendedcost = fextendedcost ? atol(fextendedcost) : 0; + int32 extendedcost = fextendedcost ? atol(fextendedcost) : 0; Creature* vendor = getSelectedCreature(); diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp index 7beae97da..e2ecc13e8 100644 --- a/src/game/ObjectMgr.cpp +++ b/src/game/ObjectMgr.cpp @@ -8012,7 +8012,7 @@ void ObjectMgr::LoadVendors() uint32 item_id = fields[1].GetUInt32(); uint32 maxcount = fields[2].GetUInt32(); uint32 incrtime = fields[3].GetUInt32(); - uint32 ExtendedCost = fields[4].GetUInt32(); + int32 ExtendedCost = fields[4].GetInt32(); if(!IsVendorItemValid(entry,item_id,maxcount,incrtime,ExtendedCost,NULL,&skip_vendors)) continue; @@ -8290,12 +8290,12 @@ void ObjectMgr::LoadGossipMenuItems() sLog.outString(">> Loaded %u gossip_menu_option entries", count); } -void ObjectMgr::AddVendorItem( uint32 entry,uint32 item, uint32 maxcount, uint32 incrtime, uint32 extendedcost ) +void ObjectMgr::AddVendorItem( uint32 entry,uint32 item, uint32 maxcount, uint32 incrtime, int32 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','%u')",entry, 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); } bool ObjectMgr::RemoveVendorItem( uint32 entry,uint32 item ) @@ -8311,7 +8311,7 @@ bool ObjectMgr::RemoveVendorItem( uint32 entry,uint32 item ) return true; } -bool ObjectMgr::IsVendorItemValid( uint32 vendor_entry, uint32 item_id, uint32 maxcount, uint32 incrtime, uint32 ExtendedCost, Player* pl, std::set* skip_vendors ) const +bool ObjectMgr::IsVendorItemValid( uint32 vendor_entry, uint32 item_id, uint32 maxcount, uint32 incrtime, int32 ExtendedCost, Player* pl, std::set* skip_vendors ) const { CreatureInfo const* cInfo = GetCreatureTemplate(vendor_entry); if(!cInfo) @@ -8347,12 +8347,14 @@ bool ObjectMgr::IsVendorItemValid( uint32 vendor_entry, uint32 item_id, uint32 m return false; } - if(ExtendedCost && !sItemExtendedCostStore.LookupEntry(ExtendedCost)) + uint32 extCostId = std::abs(ExtendedCost); // negative exclude for vendor price money part + + if(extCostId && !sItemExtendedCostStore.LookupEntry(extCostId)) { if(pl) - ChatHandler(pl).PSendSysMessage(LANG_EXTENDED_COST_NOT_EXIST,ExtendedCost); + ChatHandler(pl).PSendSysMessage(LANG_EXTENDED_COST_NOT_EXIST,extCostId); else - sLog.outErrorDb("Table `npc_vendor` contain item (Entry: %u) with wrong ExtendedCost (%u) for vendor (%u), ignoring",item_id,ExtendedCost,vendor_entry); + sLog.outErrorDb("Table `npc_vendor` contain item (Entry: %u) with wrong ExtendedCost (%u) for vendor (%u), ignoring",item_id,extCostId,vendor_entry); return false; } diff --git a/src/game/ObjectMgr.h b/src/game/ObjectMgr.h index d1819a77e..2793b7709 100644 --- a/src/game/ObjectMgr.h +++ b/src/game/ObjectMgr.h @@ -863,9 +863,9 @@ class ObjectMgr return &iter->second; } - void AddVendorItem(uint32 entry,uint32 item, uint32 maxcount, uint32 incrtime, uint32 ExtendedCost); + void AddVendorItem(uint32 entry,uint32 item, uint32 maxcount, uint32 incrtime, int32 ExtendedCost); bool RemoveVendorItem(uint32 entry,uint32 item); - bool IsVendorItemValid( uint32 vendor_entry, uint32 item, uint32 maxcount, uint32 ptime, uint32 ExtendedCost, Player* pl = NULL, std::set* skip_vendors = NULL ) const; + bool IsVendorItemValid( uint32 vendor_entry, uint32 item, uint32 maxcount, uint32 ptime, int32 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 2f7134713..2e40e867a 100644 --- a/src/game/Player.cpp +++ b/src/game/Player.cpp @@ -18426,12 +18426,12 @@ bool Player::BuyItemFromVendorSlot(uint64 vendorguid, uint32 vendorslot, uint32 return false; } - if (crItem->ExtendedCost) + if (uint32 extendedCostId = crItem->GetExtendedCostId()) { - ItemExtendedCostEntry const* iece = sItemExtendedCostStore.LookupEntry(crItem->ExtendedCost); + ItemExtendedCostEntry const* iece = sItemExtendedCostStore.LookupEntry(extendedCostId); if (!iece) { - sLog.outError("Item %u have wrong ExtendedCost field value %u", pProto->ItemId, crItem->ExtendedCost); + sLog.outError("Item %u have wrong ExtendedCost field value %u", pProto->ItemId, extendedCostId); return false; } @@ -18468,10 +18468,11 @@ bool Player::BuyItemFromVendorSlot(uint64 vendorguid, uint32 vendorslot, uint32 } } - uint32 price = pProto->BuyPrice * count; + uint32 price = crItem->IsExcludeMoneyPrice() ? 0 : pProto->BuyPrice * count; // reputation discount - price = uint32(floor(price * GetReputationPriceDiscount(pCreature))); + if (price) + price = uint32(floor(price * GetReputationPriceDiscount(pCreature))); if (GetMoney() < price) { @@ -18490,9 +18491,9 @@ bool Player::BuyItemFromVendorSlot(uint64 vendorguid, uint32 vendorslot, uint32 } ModifyMoney( -(int32)price ); - if (crItem->ExtendedCost) // case for new honor system + if (uint32 extendedCostId = crItem->GetExtendedCostId()) { - ItemExtendedCostEntry const* iece = sItemExtendedCostStore.LookupEntry(crItem->ExtendedCost); + ItemExtendedCostEntry const* iece = sItemExtendedCostStore.LookupEntry(extendedCostId); if (iece->reqhonorpoints) ModifyHonorPoints( - int32(iece->reqhonorpoints * count)); if (iece->reqarenapoints) @@ -18535,9 +18536,9 @@ bool Player::BuyItemFromVendorSlot(uint64 vendorguid, uint32 vendorslot, uint32 } ModifyMoney( -(int32)price ); - if (crItem->ExtendedCost) // case for new honor system + if (uint32 extendedCostId = crItem->GetExtendedCostId()) { - ItemExtendedCostEntry const* iece = sItemExtendedCostStore.LookupEntry(crItem->ExtendedCost); + ItemExtendedCostEntry const* iece = sItemExtendedCostStore.LookupEntry(extendedCostId); if (iece->reqhonorpoints) ModifyHonorPoints( - int32(iece->reqhonorpoints)); if (iece->reqarenapoints) diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index fcf73e013..fdd7f9174 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 "9956" + #define REVISION_NR "9957" #endif // __REVISION_NR_H__ diff --git a/src/shared/revision_sql.h b/src/shared/revision_sql.h index dcb4c5d5c..5f6ed998d 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_9849_01_characters_saved_variables" - #define REVISION_DB_MANGOS "required_9924_02_mangos_command" + #define REVISION_DB_MANGOS "required_9957_02_mangos_npc_vendor" #define REVISION_DB_REALMD "required_9748_01_realmd_realmlist" #endif // __REVISION_SQL_H__