Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void CHARACTER::OpenMyOfflineShop(const char * c_pszSign, TOfflineShopItemTable * pTable, BYTE bItemCount, BYTE bTime)
- {
- int iPulse = thecore_pulse();
- if (iPulse - GetWarpTime() < PASSES_PER_SEC(g_nPortalLimitTime))
- return;
- quest::PC * pPC = quest::CQuestManager::instance().GetPC(GetPlayerID());
- if (pPC && pPC->IsRunning())
- return;
- if (bItemCount == 0)
- return;
- if (GetShop() || GetOfflineShop())
- return;
- if (g_bEnableEmpireLimit)
- {
- if (GetEmpire() == 1 && (GetMapIndex() == 41 || GetMapIndex() == 21))
- {
- ChatPacket(CHAT_TYPE_INFO, "You can't build offline shop in this village!");
- return;
- }
- else if (GetEmpire() == 2 && (GetMapIndex() == 1 || GetMapIndex() == 41))
- {
- ChatPacket(CHAT_TYPE_INFO, "You can't build offline shop in this village!");
- return;
- }
- else if (GetEmpire() == 3 && (GetMapIndex() == 1 || GetMapIndex() == 21))
- {
- ChatPacket(CHAT_TYPE_INFO, "You can't build offline shop in this village!");
- return;
- }
- }
- {
- std::unique_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery("SELECT COUNT(*) FROM %soffline_shop_item WHERE owner_id = %u and status = 1", get_table_postfix(), GetPlayerID()));
- MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
- BYTE bResult = 0;
- str_to_number(bResult, row[0]);
- if (bResult)
- {
- ChatPacket(CHAT_TYPE_INFO, LC_TEXT( "get_items_first"));
- return;
- }
- memset(&bResult, 0, sizeof(bResult));
- }
- {
- std::unique_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery("SELECT COUNT(*) FROM %soffline_shop_npc WHERE owner_id = %u", get_table_postfix(), GetPlayerID()));
- MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
- BYTE bResult = 0;
- str_to_number(bResult, row[0]);
- if (bResult)
- {
- ChatPacket(CHAT_TYPE_INFO, LC_TEXT( "already_have_offlineshop"));
- return;
- }
- memset(&bResult, 0, sizeof(bResult));
- }
- if (g_bOfflineShopMapAllowLimit)
- {
- if (!offlineshop_map_allow_find(GetMapIndex()))
- {
- ChatPacket(CHAT_TYPE_INFO, "You cannot open an offline-shop here!");
- return;
- }
- }
- if (g_bNeededItem)
- {
- BYTE bCount = quest::CQuestManager::instance().GetCurrentCharacterPtr()->CountSpecifyItem(g_iItemVnum);
- if (bCount < g_iItemVnum)
- {
- LPITEM pItem = ITEM_MANAGER::instance().CreateItem(g_iItemVnum);
- ChatPacket(CHAT_TYPE_INFO, "You cannot open an offline-shop at the moment. You need to x%d %s", g_bItemCount, pItem->GetName());
- return;
- }
- }
- if (g_bNeededMoney)
- {
- if (GetGold() < static_cast<long long>(g_dwNeedMoney))
- {
- ChatPacket(CHAT_TYPE_INFO, "You do not have enough money to open an offline-shop at the moment.");
- ChatPacket(CHAT_TYPE_INFO, "Required money : %u", g_dwNeedMoney);
- return;
- }
- }
- if (g_bNeedMinLevel && GetLevel() < g_bMinLevel)
- {
- ChatPacket(CHAT_TYPE_INFO, "Your level is not enough to open an offline shop!");
- return;
- }
- {
- if (g_wCoinsForUnlimited > 0 && bTime == 4)
- {
- std::unique_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery("SELECT coins FROM account.account WHERE id = %u", GetAID()));
- if (pMsg->Get()->uiNumRows == 0) return;
- MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
- long lCoins = 0;
- str_to_number(lCoins, row[0]);
- if (lCoins < static_cast<long>(g_wCoinsForUnlimited))
- {
- ChatPacket(CHAT_TYPE_INFO, "You can't open an offline shop. You need to %d coins to open an offline shop!", g_wCoinsForUnlimited);
- return;
- }
- DBManager::instance().DirectQuery("UPDATE account.account SET coins = coins - %d where id = %u", g_wCoinsForUnlimited, GetAID());
- memset(&lCoins, 0, sizeof(lCoins));
- }
- }
- char szSign[SHOP_SIGN_MAX_LEN + 1] = { 0 };
- DBManager::instance().EscapeString(szSign, sizeof(szSign), c_pszSign, strlen(c_pszSign));
- if (strlen(szSign) == 0)
- {
- ChatPacket(CHAT_TYPE_INFO, "Nie mozesz otworzyc sklepu bez jego nazwy!");
- return;
- }
- m_stOfflineShopSign = szSign;
- memset(&szSign, 0, sizeof(szSign));
- if (CBanwordManager::instance().CheckString(m_stOfflineShopSign.c_str(), m_stOfflineShopSign.length()))
- {
- ChatPacket(CHAT_TYPE_INFO, LC_TEXT("şńĽÓľîłŞ Ŕşľî°ˇ Ć÷ÇÔµČ »óÁˇ Ŕ̸§Ŕ¸·Î »óÁˇŔ» ż Ľö ľř˝Ŕ´Ď´Ů."));
- return;
- }
- if (m_stOfflineShopSign.length() == 0)
- return;
- LPCHARACTER npc = CHARACTER_MANAGER::instance().SpawnMob(30000, GetMapIndex(), GetX(), GetY(), GetZ(), false, -1, false, true, GetPlayerID());
- if (!npc)
- {
- ChatPacket(CHAT_TYPE_INFO, "Offline shop npc can not create! Please try again.");
- return;
- }
- SetOfflineShopTime();
- bool bIsWrong = false;
- // First check the items
- for (BYTE i = 0; i < bItemCount; ++i)
- {
- LPITEM pItem = GetItem((pTable + i)->pos);
- if (!pItem)
- continue;
- if (pItem->IsEquipped())
- {
- bIsWrong = true;
- ChatPacket(CHAT_TYPE_INFO, LC_TEXT( "CANNOT_SELL_EQUIPPED_ITEM"));
- return;
- }
- if (pItem->isLocked())
- {
- bIsWrong = true;
- ChatPacket(CHAT_TYPE_INFO, LC_TEXT( "CANNOT_SELL_LOCKED_ITEM"));
- return;
- }
- if ((pTable + i)->price >= GOLD_MAX)
- {
- bIsWrong = true;
- ChatPacket(CHAT_TYPE_INFO, LC_TEXT( "OVERFLOW_OF_GOLD_ON_ITEMS"));
- return;
- }
- }
- if (!bIsWrong)
- {
- for (BYTE i = 0; i < bItemCount; ++i)
- {
- LPITEM pkItem = GetItem((pTable + i)->pos);
- if (!pkItem)
- continue;
- char szColumns[QUERY_MAX_LEN], szValues[QUERY_MAX_LEN];
- int iLen = snprintf(szColumns, sizeof(szColumns), "id,owner_id,pos,count,price,vnum");
- int iUpdateLen = snprintf(szValues, sizeof(szValues), "%u,%u,%d,%u,%lld,%u", pkItem->GetID(), GetPlayerID(), (pTable + i)->display_pos, pkItem->GetCount(), (pTable + i)->price, pkItem->GetVnum());
- iLen += snprintf(szColumns + iLen, sizeof(szColumns) - iLen, ",socket0,socket1,socket2");
- iUpdateLen += snprintf(szValues + iUpdateLen, sizeof(szValues) - iUpdateLen, ",%ld,%ld,%ld", pkItem->GetSocket(0), pkItem->GetSocket(1), pkItem->GetSocket(2));
- iLen += snprintf(szColumns + iLen, sizeof(szColumns) - iLen, ",attrtype0,attrvalue0,attrtype1,attrvalue1,attrtype2,attrvalue2,attrtype3,attrvalue3,attrtype4,attrvalue4,attrtype5,attrvalue5,attrtype6,attrvalue6");
- iUpdateLen += snprintf(szValues + iUpdateLen, sizeof(szValues) - iUpdateLen, ",%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
- pkItem->GetAttributeType(0), pkItem->GetAttributeValue(0),
- pkItem->GetAttributeType(1), pkItem->GetAttributeValue(1),
- pkItem->GetAttributeType(2), pkItem->GetAttributeValue(2),
- pkItem->GetAttributeType(3), pkItem->GetAttributeValue(3),
- pkItem->GetAttributeType(4), pkItem->GetAttributeValue(4),
- pkItem->GetAttributeType(5), pkItem->GetAttributeValue(5),
- pkItem->GetAttributeType(6), pkItem->GetAttributeValue(6));
- char szInsertQuery[QUERY_MAX_LEN];
- snprintf(szInsertQuery, sizeof(szInsertQuery), "INSERT INTO %soffline_shop_item (%s) VALUES (%s)", get_table_postfix(), szColumns, szValues);
- std::unique_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery(szInsertQuery));
- pkItem->RemoveFromCharacter();
- ITEM_MANAGER::instance().FlushDelayedSave(pkItem);
- memset(&szColumns, 0, sizeof(szColumns));
- memset(&szValues, 0, sizeof(szValues));
- memset(&szInsertQuery, 0, sizeof(szInsertQuery));
- }
- }
- int iTime = 0;
- switch (bTime)
- {
- case 1:
- iTime = 6 * 60 * 60;
- break;
- case 2:
- iTime = 12 * 60 * 60;
- break;
- case 3:
- iTime = 24 * 60 * 60;
- break;
- }
- // If bTime is not equal to unlimited time, start the time!
- if (bTime != 4)
- {
- npc->SetOfflineShopTimer(iTime);
- npc->StartOfflineShopUpdateEvent();
- }
- else
- {
- int iTime = 24 * 60 * 60;
- npc->SetOfflineShopTimer(iTime);
- npc->StartOfflineShopUpdateEvent();
- }
- //unsigned char const* text = (unsigned char const*) c_pszSign;
- //
- //std::string encodedText = base64_encode(text, strlen(c_pszSign));
- //
- //const char * convert = encodedText.c_str();
- // Insert
- //char query_sign[8096+1];
- //snprintf(query_sign, sizeof(query_sign), "INSERT INTO %soffline_shop_npc(owner_id, sign, name, time, x, y, z, mapIndex, channel) VALUES(%u, '%s', '%s', %d, %ld, %ld, %ld, %ld, %d)", get_table_postfix(), GetPlayerID(), convert, GetName(), iTime, GetX(), GetY(), GetZ(), GetMapIndex(), g_bChannel);
- //std::unique_ptr<SQLMsg> query_sign(DBManager::instance().DirectQuery(query_sign));
- //
- //memset(&query_sign, 0, sizeof(query_sign));
- // Create Offline Shop
- LPOFFLINESHOP pkOfflineShop = COfflineShopManager::instance().CreateOfflineShop(npc, GetPlayerID());
- if (!pkOfflineShop)
- {
- ChatPacket(CHAT_TYPE_INFO, "Offline shop npc cannot create. Please try again.");
- return;
- }
- npc->SetOfflineShop(pkOfflineShop);
- npc->SetOfflineShopChannel(g_bChannel);
- // End Of Create Offline Shop
- // Set Name
- char szName[CHARACTER_NAME_MAX_LEN + 1];
- snprintf(szName, sizeof(szName), "%s - Sklep", GetName());
- npc->SetName(szName);
- memset(&szName, 0, sizeof(szName));
- // End Of Set Name
- SetOfflineShopVID(npc->GetVID());
- npc->Show(GetMapIndex(), GetX(), GetY(), GetZ(), true);
- //std::unique_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery("SELECT sign FROM %soffline_shop_npc WHERE owner_id = %u",get_table_postfix(), GetOfflineShopRealOwner()));
- //if (pMsg->Get()->uiNumRows > 0)
- //{
- // MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
- //
- // std::string base64_sign = row[0] ;
- // std::string normal_sign = base64_decode(base64_sign);
- // const char * final_sign = normal_sign.c_str() ;
- // //-----------//
- // TPacketGCShopSign p;
- // p.bHeader = HEADER_GC_OFFLINE_SHOP_SIGN;
- // p.dwVID = npc->GetVID();
- // strlcpy(p.szSign, final_sign, sizeof(p.szSign));
- //
- // PacketAround(&p, sizeof(TPacketGCShopSign));
- // //-----------//
- //}
- //delete pMsg;
- //memset(&pMsg, 0, sizeof(pMsg));
- // Send Offline Shop Sign to Everyone
- //TPacketGCShopSign p;
- //p.bHeader = HEADER_GC_OFFLINE_SHOP_SIGN;
- //p.dwVID = npc->GetVID();
- //strlcpy(p.szSign, c_pszSign, sizeof(p.szSign));
- //
- //PacketAround(&p, sizeof(TPacketGCShopSign));
- // End Of Send Offline Shop Sign to Everyone
- if (g_bNeededItem)
- {
- LPITEM item = FindSpecifyItem(g_iItemVnum);
- if (!item)
- {
- ChatPacket(CHAT_TYPE_INFO, "Ups! Something went wrong!");
- return;
- }
- if (item->IsStackable())
- if (item->GetCount() == g_bItemCount)
- ITEM_MANAGER::instance().RemoveItem(item);
- else
- item->SetCount(item->GetCount() - g_bItemCount);
- else
- ITEM_MANAGER::instance().RemoveItem(item);
- }
- if (g_bNeededMoney)
- PointChange(POINT_GOLD, -g_dwNeedMoney, false);
- SetOfflineShopStatus(2);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement