void AhBot::Expire(int auction) { if (!player) return; AuctionHouseEntry const* ahEntry = sAuctionHouseStore.LookupEntry(auctionIds[auction]); if(!ahEntry) return; AuctionHouseObject* auctionHouse = sAuctionMgr.GetAuctionsMap(ahEntry); AuctionHouseObject::AuctionEntryMap const& auctions = auctionHouse->GetAuctions(); AuctionHouseObject::AuctionEntryMap::const_iterator itr = auctions.begin(); while (itr != auctions.end()) { if (itr->second->owner == sAhBotConfig.guid) itr->second->expireTime = sWorld.GetGameTime(); ++itr; } CharacterDatabase.PExecute("DELETE FROM ahbot_category"); sLog.outDetail("AhBot's auctions marked as expired in auction %d", auctionIds[auction]); }
// this void is called when player clicks on search button void WorldSession::HandleAuctionListItems(WorldPacket & recv_data) { DEBUG_LOG("WORLD: HandleAuctionListItems"); ObjectGuid auctioneerGuid; std::string searchedname; uint8 levelmin, levelmax, usable, isFull, sortCount; uint32 listfrom, auctionSlotID, auctionMainCategory, auctionSubCategory, quality; recv_data >> auctioneerGuid; recv_data >> listfrom; // start, used for page control listing by 50 elements recv_data >> searchedname; recv_data >> levelmin >> levelmax; recv_data >> auctionSlotID >> auctionMainCategory >> auctionSubCategory >> quality; recv_data >> usable >> isFull >> sortCount; if (sortCount >= MAX_AUCTION_SORT) return; uint8 Sort[MAX_AUCTION_SORT]; memset(Sort, MAX_AUCTION_SORT, MAX_AUCTION_SORT); // auction columns sorting for (uint32 i = 0; i < sortCount; ++i) { uint8 column, reversed; recv_data >> column; if (column >= MAX_AUCTION_SORT) return; recv_data >> reversed; Sort[i] = (reversed > 0) ? (column |= AUCTION_SORT_REVERSED) : column; } AuctionHouseEntry const* auctionHouseEntry = GetCheckedAuctionHouseForAuctioneer(auctioneerGuid); if (!auctionHouseEntry) return; // always return pointer AuctionHouseObject* auctionHouse = sAuctionMgr.GetAuctionsMap(auctionHouseEntry); // Sort AuctionHouseObject::AuctionEntryMap const& aucs = auctionHouse->GetAuctions(); std::vector<AuctionEntry*> auctions; auctions.reserve(aucs.size()); for (AuctionHouseObject::AuctionEntryMap::const_iterator itr = aucs.begin(); itr != aucs.end(); ++itr) auctions.push_back(itr->second); AuctionSorter sorter(Sort, GetPlayer()); std::sort(auctions.begin(), auctions.end(), sorter); // remove fake death if (GetPlayer()->hasUnitState(UNIT_STAT_DIED)) GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH); //DEBUG_LOG("Auctionhouse search %s list from: %u, searchedname: %s, levelmin: %u, levelmax: %u, auctionSlotID: %u, auctionMainCategory: %u, auctionSubCategory: %u, quality: %u, usable: %u", // auctioneerGuid.GetString().c_str(), listfrom, searchedname.c_str(), levelmin, levelmax, auctionSlotID, auctionMainCategory, auctionSubCategory, quality, usable); WorldPacket data(SMSG_AUCTION_LIST_RESULT, (4+4+4)); uint32 count = 0; uint32 totalcount = 0; data << uint32(0); // converting string that we try to find to lower case std::wstring wsearchedname; if (!Utf8toWStr(searchedname, wsearchedname)) return; wstrToLower(wsearchedname); BuildListAuctionItems(auctions, data, wsearchedname, listfrom, levelmin, levelmax, usable, auctionSlotID, auctionMainCategory, auctionSubCategory, quality, count, totalcount, isFull); data.put<uint32>(0, count); data << uint32(totalcount); data << uint32(300); // 2.3.0 delay for next isFull request? SendPacket(&data); }
void AhBot::Answer(int auction, Category* category, ItemBag* inAuctionItems) { AuctionHouseEntry const* ahEntry = sAuctionHouseStore.LookupEntry(auctionIds[auction]); if(!ahEntry) return; AuctionHouseObject* auctionHouse = sAuctionMgr.GetAuctionsMap(ahEntry); AuctionHouseObject::AuctionEntryMap const& auctionEntryMap = auctionHouse->GetAuctions(); int64 availableMoney = GetAvailableMoney(auctionIds[auction]); vector<AuctionEntry*> entries; for (AuctionHouseObject::AuctionEntryMap::const_iterator itr = auctionEntryMap.begin(); itr != auctionEntryMap.end(); ++itr) entries.push_back(itr->second); Shuffle(entries); for (vector<AuctionEntry*>::iterator itr = entries.begin(); itr != entries.end(); ++itr) { AuctionEntry *entry = *itr; if (entry->owner == player->GetGUIDLow() || entry->bidder == player->GetGUIDLow()) continue; if (urand(0, 100) > sAhBotConfig.buyProbability * 100) continue; Item *item = sAuctionMgr.GetAItem(entry->itemGuidLow); if (!item) continue; uint32 price = category->GetPricingStrategy()->GetBuyPrice(item->GetProto(), auctionIds[auction]); if (!price || !item->GetCount()) continue; uint32 bidPrice = item->GetCount() * price; uint32 buyoutPrice = item->GetCount() * urand(price, 4 * price / 3); uint32 curPrice = entry->bid; if (!curPrice) curPrice = entry->startbid; if (!curPrice) curPrice = entry->buyout; if (curPrice > buyoutPrice) continue; if (availableMoney < curPrice) continue; if (entry->bidder && entry->bidder != player->GetGUIDLow()) player->GetSession()->SendAuctionOutbiddedMail(entry); entry->bidder = player->GetGUIDLow(); entry->bid = curPrice + urand(1, 1 + bidPrice / 10); availableMoney -= curPrice; updateMarketPrice(item->GetProto()->ItemId, entry->buyout / item->GetCount(), auctionIds[auction]); if (entry->buyout && (entry->bid >= entry->buyout || 100 * (entry->buyout - entry->bid) / price < 25)) { entry->bid = entry->buyout; entry->AuctionBidWinning(NULL); sLog.outString("AhBot won %s in auction %d for %d", item->GetProto()->Name1, auctionIds[auction], entry->buyout); } else { CharacterDatabase.PExecute("UPDATE auction SET buyguid = '%u',lastbid = '%u' WHERE id = '%u'", entry->bidder, entry->bid, entry->Id); sLog.outString("AhBot placed bid %d for %s in auction %d", entry->bid, item->GetProto()->Name1, auctionIds[auction]); } } }