| 281 | // Vendors |
| 282 | struct VendorItem |
| 283 | { |
| 284 | VendorItem(uint32 _item, uint32 _maxcount, uint32 _incrtime, uint32 _ExtendedCost) |
| 285 | : item(_item), maxcount(_maxcount), incrtime(_incrtime), ExtendedCost(_ExtendedCost) {} |
| 286 | |
| 287 | uint32 item; |
| 288 | uint32 maxcount; // 0 for infinity item amount |
| 289 | uint32 incrtime; // time for restore items amount if maxcount != 0 |
| 290 | uint32 ExtendedCost; |
| 291 | }; |
| 292 | typedef std::vector<VendorItem*> VendorItemList; |
| 293 | |
| 294 | struct VendorItemData |
| 295 | { |
| 296 | VendorItemList m_items; |
| 297 | |
| 298 | VendorItem* GetItem(uint32 slot) const |
| 299 | { |
| 300 | if(slot>=m_items.size()) return NULL; |
| 301 | return m_items[slot]; |
| 302 | } |
| 303 | bool Empty() const { return m_items.empty(); } |
| 304 | uint8 GetItemCount() const { return m_items.size(); } |
| 305 | void AddItem( uint32 item, uint32 maxcount, uint32 ptime, uint32 ExtendedCost) |
| 306 | { |
| 307 | m_items.push_back(new VendorItem(item, maxcount, ptime, ExtendedCost)); |
| 308 | } |
| 309 | bool RemoveItem( uint32 item_id ); |
| 310 | VendorItem const* FindItem(uint32 item_id) const; |
| 311 | |
| 312 | void Clear() |
| 313 | { |
| 314 | for (VendorItemList::iterator itr = m_items.begin(); itr != m_items.end(); ++itr) |
| 315 | delete (*itr); |
| 316 | } |
| 317 | }; |
| 318 | |
| 319 | struct VendorItemCount |
| 320 | { |
| 321 | explicit VendorItemCount(uint32 _item, uint32 _count) |
| 322 | : itemId(_item), count(_count), lastIncrementTime(time(NULL)) {} |
| 323 | |
| 324 | uint32 itemId; |
| 325 | uint32 count; |
| 326 | time_t lastIncrementTime; |
| 327 | }; |
| 328 | |
| 329 | typedef std::list<VendorItemCount> VendorItemCounts; |
| 330 | |
421 | | /*********************************************************/ |
422 | | /*** VENDOR SYSTEM ***/ |
423 | | /*********************************************************/ |
424 | | void LoadGoods(); // must be called before access to vendor items, lazy loading at first call |
425 | | void ReloadGoods() { m_itemsLoaded = false; LoadGoods(); } |
426 | | |
427 | | CreatureItem* GetItem(uint32 slot) |
428 | | { |
429 | | if(slot>=m_vendor_items.size()) return NULL; |
430 | | return &m_vendor_items[slot]; |
431 | | } |
432 | | uint8 GetItemCount() const { return m_vendor_items.size(); } |
433 | | void AddItem( uint32 item, uint32 maxcount, uint32 ptime, uint32 ExtendedCost) |
434 | | { |
435 | | m_vendor_items.push_back(CreatureItem(item, maxcount, ptime, ExtendedCost)); |
436 | | } |
437 | | bool RemoveItem( uint32 item_id ) |
438 | | { |
439 | | for(CreatureItems::iterator i = m_vendor_items.begin(); i != m_vendor_items.end(); ++i ) |
440 | | { |
441 | | if(i->id==item_id) |
442 | | { |
443 | | m_vendor_items.erase(i); |
444 | | return true; |
445 | | } |
446 | | } |
447 | | return false; |
448 | | } |
449 | | CreatureItem* FindItem(uint32 item_id) |
450 | | { |
451 | | for(CreatureItems::iterator i = m_vendor_items.begin(); i != m_vendor_items.end(); ++i ) |
452 | | if(i->id==item_id) |
453 | | return &*i; |
454 | | return NULL; |
455 | | } |
| 458 | VendorItemData const* GetVendorItems() const; |
| 459 | uint32 GetVendorItemCurrentCount(VendorItem const* vItem); |
| 460 | uint32 UpdateVendorItemCurrentCount(VendorItem const* vItem, uint32 used_count); |