[9957] Alow sell item for money and extanded coset without momey in same time.

npc_vendor.ExtandedCost can be negative now that meaning:
price excluded default item BuyPrice and use only abs(ExtandedCost) items).
For example expected used for item 36908.
This commit is contained in:
VladimirMangos 2010-05-22 19:38:11 +04:00
parent 94f7a7709d
commit 67b8ca03b5
13 changed files with 51 additions and 31 deletions

View file

@ -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';

View file

@ -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);

View file

@ -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';

View file

@ -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

View file

@ -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)

View file

@ -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<VendorItem*> 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()
{

View file

@ -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());
}
}
}

View file

@ -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();

View file

@ -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<uint32>* skip_vendors ) const
bool ObjectMgr::IsVendorItemValid( uint32 vendor_entry, uint32 item_id, uint32 maxcount, uint32 incrtime, int32 ExtendedCost, Player* pl, std::set<uint32>* 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;
}

View file

@ -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<uint32>* skip_vendors = NULL ) const;
bool IsVendorItemValid( uint32 vendor_entry, uint32 item, uint32 maxcount, uint32 ptime, int32 ExtendedCost, Player* pl = NULL, std::set<uint32>* skip_vendors = NULL ) const;
void LoadScriptNames();
ScriptNameMap &GetScriptNames() { return m_scriptNames; }

View file

@ -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)

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "9956"
#define REVISION_NR "9957"
#endif // __REVISION_NR_H__

View file

@ -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__