arkadaşlar ıstırap 1098 de merchant botlardan src kaynaklı item çekilmiyor kendim bir şey satmak için bot korsam ondan çekiliyor anlayacağınız saveload bot sisteminde bir hata var hata nereden kaynaklanıyor olabilir ben CollectionRaceHandler.cpp içindeki koddan şüpheleniyorum ama tam neresinde bulamadım hatayı anlayan arkadaş yardımcı olur ise çok sevinirim
Kod:
void CGameServerDlg::ReqBotLoadSaveData(Packet& pkt) {
uint8 type = pkt.read<uint8>();
uint8 zoneid = pkt.read<uint8>();
uint16 id = pkt.read<uint16>();
if (type == 1)
{
int count = 1;
g_pMain->m_ArtificialIntelligenceArray.m_lock.lock();
auto m_sMapBotListArray = g_pMain->m_ArtificialIntelligenceArray.m_UserTypeMap;
g_pMain->m_ArtificialIntelligenceArray.m_lock.unlock();
foreach(itr, m_sMapBotListArray)
{
CBot* pBot = g_pMain->GetBotPtr(itr->first);
if (pBot == nullptr)
continue;
if (!pBot->isInGame())
continue;
if (pBot->GetZoneID() != zoneid)
continue;
if (!pBot->isMerchanting())
continue;
_BOT_SAVE_DATA* pAuto = new _BOT_SAVE_DATA();
for (int i = 0; i < MAX_MERCH_ITEMS; i++)
{
_MERCH_DATA* pMerch = &pBot->m_arMerchantItems[i];
pAuto->sCount[i] = pMerch->sCount;
pAuto->nNum[i] = pMerch->nNum;
pAuto->sDuration[i] = pMerch->sDuration;
pAuto->nPrice[i] = pMerch->nPrice;
pAuto->IsSoldOut[i] = false;
pAuto->isKc[i] = pMerch->isKC;
pAuto->nSerialNum[i] = g_pMain->GenerateItemSerial();
}
pAuto->byZone = pBot->m_bZone;
pAuto->Direction = pBot->m_sDirection;
pAuto->fX = pBot->GetX();
pAuto->fY = pBot->GetY();
pAuto->fZ = pBot->GetZ();
pAuto->Minute = 3600;
pAuto->AdvertMessage = "";
pAuto->sMerchanType = 0;
if (pBot->isBuyingMerchant())
pAuto->sMerchanType = 1;
pAuto->nAutoID = g_DBAgent.InsertBotMerchant(pAuto);
count++;
}
CUser* pUser = GetUserPtr(id);
if (pUser)
g_pMain->SendHelpDescription(pUser, string_format("(%d) Save Merchant Bot", count));
}
else if (type == 2) {
g_pMain->m_BotSaveDataArray.DeleteAllData();
g_pMain->LoadSaveBotData();
CUser* pUser = GetUserPtr(id);
int nAutoID = 0;
foreach_stlmap_nolock(itr, g_pMain->m_BotSaveDataArray)
{
_BOT_SAVE_DATA* pAuto = itr->second;
if (pAuto == nullptr)
{
if (pUser)g_pMain->SendHelpDescription(pUser, string_format("### Error Nullptr ###", nAutoID));
return;
}
int16 Direction = pAuto->Direction;
float fX = pAuto->fX;
float fZ = pAuto->fZ;
float fY = pAuto->fY;
nAutoID = itr->first;
if (!g_pMain->SpawnUserBot(3600, zoneid, fX, fY, fZ, 50, 1, Direction, nAutoID))
{
if (pUser)g_pMain->SendHelpDescription(pUser, "### Bot Bulunamadi ###");
continue;
}
}
}
}
uint16 CGameServerDlg::SpawnUserBot(int Minute, uint8 byZone, float fX, float fY, float fZ, uint8 Restipi,
uint8 minlevel /* = 1*/, int16 direction, uint32 SaveID, uint8 Class, _bot_merchant _merchant)
{
m_ArtificialIntelligenceArray.m_lock.lock();
auto m_sArtificialIntelligenceArray = m_ArtificialIntelligenceArray.m_UserTypeMap;
m_ArtificialIntelligenceArray.m_lock.unlock();
foreach(itr, m_sArtificialIntelligenceArray)
{
_BOT_DATA* pBotInfo = itr->second;
if (pBotInfo == nullptr)
continue;
if (byZone <= ZONE_ELMORAD && byZone != pBotInfo->m_bNation
|| (byZone >= ZONE_KARUS_ESLANT
&& byZone <= ZONE_ELMORAD_ESLANT
&& byZone != (pBotInfo->m_bNation + 10)))
continue;
if (pBotInfo->m_bLevel < minlevel)
continue;
// Check if bot already exist
CBot* pBotCheck = GetBotPtr(pBotInfo->m_sSid);
if (pBotCheck != nullptr)
continue;
CBot* pBot = new CBot();
pBot->m_strUserID = pBotInfo->m_strUserID;
pBot->m_bNation = pBotInfo->m_bNation;
pBot->m_bRace = pBotInfo->m_bRace;
pBot->m_sClass = pBotInfo->m_sClass;
pBot->m_nHair = pBotInfo->m_nHair;
pBot->m_bLevel = pBotInfo->m_bLevel;
pBot->m_bFace = pBotInfo->m_bFace;
pBot->m_bKnights = pBotInfo->m_bKnights;
pBot->m_bFame = pBotInfo->m_bFame;
memcpy(pBot->m_sItemArray, pBotInfo->m_sItemArray, sizeof(pBot->m_sItemArray));
memcpy(pBot->m_bstrSkill, pBotInfo->m_bstrSkill, sizeof(pBot->m_bstrSkill));
memcpy(pBot->m_bStats, pBotInfo->m_bStats, sizeof(pBot->m_bStats));
pBot->m_sSid = pBotInfo->m_sSid;
pBot->m_sAchieveCoverTitle = pBotInfo->m_sAchieveCoverTitle;
pBot->m_reblvl = pBotInfo->m_reblvl;
pBot->m_iGold = pBotInfo->m_iGold;
pBot->m_sPoints = pBotInfo->m_sPoints;
pBot->m_iLoyalty = pBotInfo->m_iLoyalty;
pBot->m_iLoyaltyMonthly = pBotInfo->m_iLoyaltyMonthly;
pBot->m_bMerchantState = (SaveID > 0 ? MERCHANT_STATE_SELLING : MERCHANT_STATE_NONE);
pBot->LastWarpTime = 0;
pBot->m_sMerchantAreaType = 0;
if (Minute > 0)
pBot->LastWarpTime = UNIXTIME + (Minute * 60);
pBot->m_sDirection = direction;
pBot->m_pMap = GetZoneByID(byZone);
pBot->m_bZone = byZone;
pBot->m_sMerchantAreaType = 0;
pBot->m_iGold = myrand(1000, 5000000);
if (Restipi == 13 || Restipi == 14)
{
_ITEM_DATA* pItem = &pBot->m_sItemArray[RIGHTHAND];
_ITEM_TABLE pTable = GetItemPtr(pItem->nNum);
if (pTable.isnull())
continue;
if (Class == 1 && !pBot->isWarrior())
continue;
if (Class == 2 && !pBot->isRogue())
continue;
if (Class == 3 && !pBot->isMage())
continue;
if (Class == 4 && !pBot->isPriest())
continue;
if (pBot->isRogue() && !pTable.isBow())
continue;
if (pBot->isWarrior()
|| pTable.isShield()
|| pTable.isPickaxe()
|| pTable.isFishing())
continue;
pBot->m_bGenieStatus = 1;
if (Restipi == 14)
pBot->m_bPartyLeader = true;
else
pBot->m_bPartyLeader = false;
}
else if (Restipi == 50)
{
_BOT_SAVE_DATA* pAuto = g_pMain->m_BotSaveDataArray.GetData(SaveID);
if (pAuto == nullptr)
return 0;
std::string advertMessage = "test";
uint16 bResult = 1;
uint8 MerchantItemleri = 0;
for (int i = 0; i < MAX_MERCH_ITEMS; i++) { if (pAuto->nNum[i] != 0) MerchantItemleri++; }
if (MerchantItemleri == 0)
return false;
_MERCH_DATA m_arNewItems[MAX_MERCH_ITEMS]{};
if (pAuto->sMerchanType == 0)
{
Packet result(WIZ_MERCHANT, uint8(MERCHANT_INSERT));
for (int i = 0; i < MAX_MERCH_ITEMS; i++)
{
int8 sItemSlot = pBot->FindSlotForItem(pAuto->nNum[i], pAuto->sCount[i]);
if (sItemSlot < 0)
continue;
auto* pData = pBot->GetItem(sItemSlot);
if (!pData
|| pData->nNum != 0)
continue;
pData->nNum = pAuto->nNum[i];
pData->sCount = pAuto->sCount[i];
pData->sDuration = pAuto->sDuration[i];
pData->nSerialNum = pAuto->nSerialNum[i];
pData->MerchItem = true;
m_arNewItems[i].sCount = pAuto->sCount[i];
m_arNewItems[i].sCount = pAuto->sCount[i];
m_arNewItems[i].nNum = pAuto->nNum[i];
m_arNewItems[i].IsSoldOut = pAuto->IsSoldOut[i];
m_arNewItems[i].sDuration = pAuto->sDuration[i];
m_arNewItems[i].nPrice = pAuto->nPrice[i];
m_arNewItems[i].nSerialNum = pAuto->nSerialNum[i];
m_arNewItems[i].bOriginalSlot = sItemSlot;
m_arNewItems[i].isKC = pAuto->isKc[i];
}
uint8 reqcount = 0;
for (int i = 0; i < MAX_MERCH_ITEMS; i++)
if (m_arNewItems[i].nNum)
reqcount++;
if (!reqcount)
return false;
uint8 nRandom = 3;
std::string asdasd = "";
if (!asdasd.empty())
pBot->MerchantChat = string_format("%s(Location:%d,%d)", asdasd.c_str(), pBot->GetSPosX() / 10, pBot->GetSPosZ() / 10);
pBot->MerchantChat.clear();
pBot->m_iLoyalty = myrand(3000, 5000);
pBot->m_bPremiumMerchant = 0;
pBot->m_bMerchantState = MERCHANT_STATE_SELLING;
pBot->m_BotState = BOT_MERCHANT;
result << bResult << advertMessage << pBot->GetID()
<< pBot->m_bPremiumMerchant;
for (int i = 0; i < MAX_MERCH_ITEMS; i++)
pBot->m_arMerchantItems[i] = m_arNewItems[i];
for (int i = 0; i < MAX_MERCH_ITEMS; i++)
result << pBot->m_arMerchantItems[i].nNum;
pBot->SendToRegion(&result);
}
if (pAuto->sMerchanType == 1)
{
Packet result(WIZ_MERCHANT, uint8(MERCHANT_BUY_REGION_INSERT));
for (int i = 0; i < MAX_MERCH_ITEMS; i++) { pBot->m_arMerchantItems[i].nNum = pAuto->nNum[i]; pBot->m_arMerchantItems[i].sCount = pAuto->sCount[i]; pBot->m_arMerchantItems[i].nPrice = pAuto->nPrice[i]; pBot->m_arMerchantItems[i].sDuration = pAuto->sDuration[i]; pBot->m_arMerchantItems[i].isKC = pAuto->isKc[i]; }
pBot->m_bMerchantState = MERCHANT_STATE_BUYING;
pBot->m_BotState = BOT_MERCHANT;
result << pBot->GetID();
for (int i = 0; i < 4; i++)
result << pBot->m_arMerchantItems[i].nNum;
pBot->SendToRegion(&result);
}
}
else if (Restipi == 1)
{
_ITEM_DATA* pItem = &pBot->m_sItemArray[RIGHTHAND];
if (pItem)
{
auto pTable = GetItemPtr(myrand(0, 100) > 50 ? GOLDEN_MATTOCK : MATTOCK);
if (pTable.isnull())
continue;
_ITEM_DATA* pTItem = &pBot->m_sItemArray[LEFTHAND];
if (pTItem) memset(pTItem, 0x00, sizeof(_ITEM_DATA));
memset(pItem, 0x00, sizeof(_ITEM_DATA));
pItem->nNum = pTable.m_iNum;
pItem->nSerialNum = GenerateItemSerial();
pItem->sCount = 1;
pItem->sDuration = pTable.m_sDuration;
pBot->m_bResHpType = USER_MINING;
}
}
else if (Restipi == 2)
{
_ITEM_DATA* pItem = &pBot->m_sItemArray[RIGHTHAND];
if (pItem)
{
auto pTable = GetItemPtr(myrand(0, 100) > 50 ? GOLDEN_FISHING : FISHING);
if (pTable.isnull())
continue;
auto* pTItem = &pBot->m_sItemArray[LEFTHAND];
if (pTItem != nullptr)
memset(pTItem, 0x00, sizeof(_ITEM_DATA));
memset(pItem, 0x00, sizeof(_ITEM_DATA));
pItem->nNum = pTable.m_iNum;
pItem->nSerialNum = GenerateItemSerial();
pItem->sCount = 1;
pItem->sDuration = pTable.m_sDuration;
pBot->m_bResHpType = USER_FLASHING;
}
}
else if (Restipi == 3 || Restipi == 4)
pBot->m_bResHpType = Restipi == 3 ? USER_STANDING : USER_SITDOWN;
else if (Restipi == 5)
pBot->m_bResHpType = USER_STANDING;// Random > 5000 ? USER_STANDING : USER_SITDOWN;
else if (Restipi == 6) {}
else continue;
if (Restipi == 6)
{
pBot->m_bMerchantIndex = _merchant.index;
pBot->m_sMerchantAreaType = _merchant.areaType;
pBot->m_BotState = BOT_MERCHANT;
uint8 itemcount = 0;
for (int i = 0; i < MAX_MERCH_ITEMS; i++)
{
if (_merchant.merc[i].itemid)
itemcount++;
}
_MERCH_DATA m_arNewItems[MAX_MERCH_ITEMS]{};
memset(m_arNewItems, 0, sizeof(m_arNewItems));
if (!_merchant.isBuy) {
for (int i = 0; i < MAX_MERCH_ITEMS; i++) {
if (!_merchant.merc[i].itemid)
continue;
int8 sItemSlot = pBot->FindSlotForItem(_merchant.merc[i].itemid, _merchant.merc[i].count);
if (sItemSlot < 0)
continue;
auto pItem = g_pMain->GetItemPtr(_merchant.merc[i].itemid);
if (pItem.isnull())
continue;
auto* pData = pBot->GetItem(sItemSlot);
if (!pData || (pData->nNum != 0 && !pItem.m_bCountable))
continue;
pData->nNum = _merchant.merc[i].itemid;
pData->sCount += _merchant.merc[i].count;
pData->sDuration = _merchant.merc[i].pTable.m_sDuration;
pData->nSerialNum = g_pMain->GenerateItemSerial();
pData->MerchItem = true;
m_arNewItems[i].sCount = pData->sCount;
m_arNewItems[i].nNum = pData->nNum;
m_arNewItems[i].IsSoldOut = false;
m_arNewItems[i].sDuration = pData->sDuration;
m_arNewItems[i].nPrice = _merchant.merc[i].price;
m_arNewItems[i].nSerialNum = pData->nSerialNum;
m_arNewItems[i].bOriginalSlot = sItemSlot;
m_arNewItems[i].isKC = _merchant.merc[i].iskc;
}
uint8 reqcount = 0;
for (int i = 0; i < MAX_MERCH_ITEMS; i++)
if (m_arNewItems[i].nNum)
reqcount++;
if (!reqcount)
{
if (_merchant.index) {
auto* pCoord = g_pMain->pBotInfo.mCoordinate.GetData(_merchant.index);
if (pCoord)
pCoord->used = false;
}
return 0;
}
pBot->m_bPremiumMerchant = myrand(0, 100) < 15;
pBot->m_bMerchantState = MERCHANT_STATE_SELLING;
}
else {
uint32 total_price = 0;
for (int i = 0; i < MAX_MERCH_ITEMS; i++) {
m_arNewItems[i].sCount = _merchant.merc[i].count;
m_arNewItems[i].nNum = _merchant.merc[i].itemid;
m_arNewItems[i].sDuration = _merchant.merc[i].pTable.m_sDuration;
m_arNewItems[i].nPrice = _merchant.merc[i].price;
m_arNewItems[i].isKC = _merchant.merc[i].iskc;
m_arNewItems[i].bOriginalSlot = i;
total_price += _merchant.merc[i].price;
}
uint8 reqcount = 0;
for (int i = 0; i < MAX_MERCH_ITEMS; i++)
if (m_arNewItems[i].nNum)
reqcount++;
if (!reqcount)
{
if (_merchant.index) {
auto* pCoord = g_pMain->pBotInfo.mCoordinate.GetData(_merchant.index);
if (pCoord)
pCoord->used = false;
}
return 0;
}
pBot->m_bPremiumMerchant = myrand(0, 100) < 15;
pBot->m_bMerchantState = MERCHANT_STATE_BUYING;
if (pBot->m_iGold < total_price)
pBot->m_iGold = myrand(total_price, total_price + 5000000);
}
for (int i = 0; i < MAX_MERCH_ITEMS; i++)
pBot->m_arMerchantItems[i] = m_arNewItems[i];
}
int Random = myrand(0, 10000);
pBot->m_sTargetID = int16(-1);
pBot->m_TargetChanged = false;
pBot->m_bBlockPrivateChat = false;
pBot->m_BotState = BOT_AFK;
pBot->SetBotAbility();
pBot->SetPosition(fX, fY, fZ);
pBot->SetRegion(pBot->GetNewRegionX(), pBot->GetNewRegionZ());
//pBot->SetZoneAbilityChange(pBot->GetZoneID());
AddMapBotList(pBot);
pBot->UserInOut(INOUT_IN);
pBot->StateChangeServerDirect(1, Random > 5000 ? USER_STANDING : USER_SITDOWN);
return pBot->GetID();
}
return 0;
}