Reklam
void CUser::SlaveMerc(Packet& pkt) {
uint8 sOpCode;
pkt >> sOpCode;
if (sOpCode == 1) //UPDATE
{
g_DBAgent.LoadSlave(GetName());
//uint32 sellinItem[12], sellinItemCount[12];
for (int i = 0; i < 12; i++)
SlaveItemID[i];
for (int i = 0; i < 12; i++)
SlaveItemCount[i];
Packet Update(XSafe, uint8(XSafeOpCodes::PL_USER_TOOLS));
Update << uint8(1) << uint8(3) << SlaveTotalKC << SlaveTotalCoins;
for (int i = 0; i < 12; i++)
Update << SlaveItemID[i] << SlaveItemCount[i];
for (int i = 14; i < 42; i++)
Update << m_sItemArray[i].nNum << m_sItemArray[i].sCount;
Send(&Update);
}
else if (sOpCode == 2)// give coins&kc back
{
uint32 kc = 0, coin = 0; // çekilen miktar
uint32 total_kc, total_coin; // geriye kalan
pkt >> total_kc >> total_coin;
if (total_kc == 0 && total_coin == 0)
SendBoxMessage(1, "Uyarı", "Lütfen çekmek istediğiniz tutardan 1 eksik yazınız", 0, messagecolour::red);
if (total_kc > 0 && total_coin <= 0) {
kc = SlaveTotalKC - total_kc;
coin = 0;
}
else if (total_kc <= 0 && total_coin > 0) {
kc = 0;
coin = SlaveTotalCoins - total_coin;
}
if (kc > 0 && coin <= 0) {
GiveBalance(kc);
g_DBAgent.RemoveSlaveKC(GetName(), total_kc);
}
else if (kc <= 0 && coin > 0) {
GoldGain(coin);
g_DBAgent.RemoveSlaveCoins(GetName(), total_coin);
}
}
else if (sOpCode == 3) // Slave scroll kullanımı
{
uint8 secondOp;
pkt >> secondOp;
if (secondOp == 0) // Scroll kullanıldı
{
if (CheckExistItem(751730000, 1)) // Scroll var mı kontrol
{
// Scroll'ü düşür (kullan)
RobItem(751730000, 1);
// Süreye 1 saat (3600 saniye) ekle, maksimum 24 saat (86400 saniye)
if (SlaveTotalTime + 3600 <= 86400)
SlaveTotalTime += 3600;
else
SlaveTotalTime = 86400;
SaveSlaveMerchantTimeToDB();
// Süre güncelleme paketi gönder
Packet slaveUpTime(XSafe, uint8(XSafeOpCodes::PL_USER_TOOLS));
slaveUpTime << uint8(1) << uint8(7) << uint8(1);
Send(&slaveUpTime);
// İstersen bilgilendirme mesajı:
// g_pMain->SendHelpDescription(this, string_format("Using Slave Scroll - Time %d", SlaveTotalTime));
}
else
{
g_pMain->SendHelpDescription(this, "Error : You don't have a Slave Scroll");
}
}
else if (secondOp == 1) // Süre sıfırlanacaksa
{
SlaveTotalTime = 0;
}
}
else if (sOpCode == 4) // send item to inventory
{
for (int i = 0; i < 14; i++)
{
if (!GiveItem("SlaveMerc", SlaveItemID[i], SlaveItemCount[i]))
g_pMain->SendHelpDescription(this, "Error : Item could not be added");
}
}
else if (sOpCode == 5)
{
uint8 isCashOrCoin, result;
uint32 coins2, COINS;
pkt >> COINS >> isCashOrCoin;
coins2 = COINS;
result = isCashOrCoin;
Packet Update(XSafe, uint8(XSafeOpCodes::PL_USER_TOOLS));
Update << uint8(1) << uint8(5) << coins2 << result;
Send(&Update);
}
else if (sOpCode == 6)
{
uint8 CanIopenMerchant = 0;
pkt >> CanIopenMerchant;
if (CanIopenMerchant == 1)
{
isSlave = CanIopenMerchant; // 1 oluyor
}
else if (CanIopenMerchant == 0)
{
isSlave = CanIopenMerchant; // 0 oluyor
}
if (isSlave == 0) {
CBot* pSlaveUser = g_pMain->m_MapBotList.GetData(m_bSlaveUserID);
if (pSlaveUser != nullptr) {
GiveSlaveMerchantItems();
pSlaveUser->UserInOut(INOUT_OUT);
}
for (int i = 0; i < 12; i++)
SlaveItemID[i] = 0;
for (int i = 0; i < 12; i++)
SlaveItemCount[i] = 0;
}
}
}
void CDBAgent::LoadSlave(std::string& strAccountID)
{
unique_ptr<OdbcCommand> dbCommand(m_GameDB->CreateCommand());
if (dbCommand.get() == nullptr)
return;
uint8 Check = CheckSlave(strAccountID);
dbCommand->AddParameter(SQL_PARAM_INPUT, strAccountID.c_str(), strAccountID.length());
if (Check == 0) {
if (!dbCommand->Execute(string_format(_T("INSERT INTO SLAVE VALUES(?, 0, 0) "))))
{
ReportSQLError(m_GameDB->GetError());
}
}
if (!dbCommand->Execute(_T("SELECT KC, Gold FROM SLAVE WHERE strUser = ?")))
{
ReportSQLError(m_GameDB->GetError());
return;
}
uint32 kc, gold;
if (dbCommand->hasData())
{
dbCommand->FetchUInt32(1, kc);
dbCommand->FetchUInt32(2, gold);
}
else
return;
CUser* pUser = g_pMain->GetUserPtr(strAccountID, NameType::TYPE_CHARACTER);
pUser->SlaveTotalKC = kc;
pUser->SlaveTotalCoins = gold;
return;
}
void CSlaveMerchant::Update(Packet pkt, vector<SlaveItem> drops, vector<InventoryItem> drops2)
{
uint8 subcode;
pkt >> subcode;
switch (subcode)
{
case UPDATE_SLAVE_MERCHANT:
{
uint32 TotalKC, TotalCoins;
pkt >> TotalKC >> TotalCoins;
if (m_iRemainingTime > 3600)
m_iRemainingTime = 3600;
KC = TotalKC;
COINS = TotalCoins;
text_cash->SetString(string_format(xorstr("%s"), Engine->StringHelper->NumberFormat(KC).c_str()));
text_money->SetString(string_format(xorstr("%s"), Engine->StringHelper->NumberFormat(COINS).c_str()));
m_Data = drops;
m_Data2 = drops2;
Clear();
int slot = 0;
for (auto drop : m_Data)
{
if (drop.nItemID == 0) {
c[slot]->SetString(string_format(xorstr(" ")));
continue;
}
TABLE_ITEM_BASIC* tbl = Engine->tblMgr->getItemData(drop.nItemID);
if (tbl != nullptr)
{
c[slot]->SetString(string_format(xorstr("%d"), drop.count1));
std::vector<char> buffer(256, NULL);
sprintf(&buffer[0], "ui\\itemicon_%.1d_%.4d_%.2d_%.1d.dxt",
(tbl->dxtID / 10000000),
(tbl->dxtID / 1000) % 10000,
(tbl->dxtID / 10) % 100,
tbl->dxtID % 10);
std::string szIconFN = &buffer[0];
SRC dxt = hdrReader->GetSRC(szIconFN);
if (dxt.sizeInBytes == 0) {
string iconID = to_string(tbl->Num);
szIconFN = "itemicon_" + iconID.substr(0, 1) + "_" + iconID.substr(1, 4) + "_" + iconID.substr(5, 2) + "_" + iconID.substr(7, 1) + ".dxt";
}
itemsMerch[slot]->icon->SetTex(szIconFN);
itemsMerch[slot]->tbl = tbl;
}
itemsMerch[slot]->nItemID = drop.nItemID;
slot++;
}
int slot2 = 0;
for (auto drop : m_Data2)
{
if (drop.nItemID == 0) {
d[slot2]->SetString(string_format(xorstr("%d"), drop.count1));
continue;
}
TABLE_ITEM_BASIC* tbl = Engine->tblMgr->getItemData(drop.nItemID);
if (tbl != nullptr)
{
d[slot2]->SetString(string_format(xorstr("%d"), drop.count1));
std::vector<char> buffer(256, NULL);
sprintf(&buffer[0], "ui\\itemicon_%.1d_%.4d_%.2d_%.1d.dxt",
(tbl->dxtID / 10000000),
(tbl->dxtID / 1000) % 10000,
(tbl->dxtID / 10) % 100,
tbl->dxtID % 10);
std::string szIconFN = &buffer[0];
SRC dxt = hdrReader->GetSRC(szIconFN);
if (dxt.sizeInBytes == 0) {
string iconID = to_string(tbl->Num);
szIconFN = "itemicon_" + iconID.substr(0, 1) + "_" + iconID.substr(1, 4) + "_" + iconID.substr(5, 2) + "_" + iconID.substr(7, 1) + ".dxt";
}
itemsInventory[slot2]->icon->SetTex(szIconFN);
itemsInventory[slot2]->tbl = tbl;
}
itemsInventory[slot2]->nItemID = drop.nItemID;
slot2++;
}
}
break;
}
}
bool CSlaveMerchant::ReceiveMessage(CN3UIBase* pSender, uint32_t dwMsg)
{
if (dwMsg == UIMSG_BUTTON_CLICK)
{
if (pSender == btn_close) {
Close();
}
if (pSender == btn_confrim) {
Packet SendInventory(XSafe, uint8(XSafeOpCodes::PL_SLAVE_MERC));
SendInventory << uint8(4);
Engine->Send(&SendInventory);
Close();
}
if (pSender == btn_cancel) {//pazarı kapatma
Packet CloseMerc(XSafe, uint8(XSafeOpCodes::PL_SLAVE_MERC));
CloseMerc << uint8(6) << uint8(0);
Engine->Send(&CloseMerc);
Close();
}
if (pSender == btn_useslavescroll) {//sc bas
Packet CloseMerc(XSafe, uint8(XSafeOpCodes::PL_SLAVE_MERC));
CloseMerc << uint8(3) << uint8(0);
Engine->Send(&CloseMerc);
}
if (pSender == btn_kc || pSender == btn_coin) {
if (pSender == btn_coin) {
if (Engine->m_UiMgr->uiSlaveMerchantPrice == NULL) {
Engine->m_UiMgr->OpenSlaveMerchantPrice();
}
else
{
if (Engine->m_UiMgr->uiSlaveMerchantPrice->IsVisible())
Engine->m_UiMgr->uiSlaveMerchantPrice->Close();
else
Engine->m_UiMgr->uiSlaveMerchantPrice->Open();
}
Packet SlavePrice(XSafe, uint8(XSafeOpCodes::PL_SLAVE_MERC));
SlavePrice << uint8(5) << COINS << uint8(2);
Engine->Send(&SlavePrice);
}
if (pSender == btn_kc) {
if (Engine->m_UiMgr->uiSlaveMerchantPrice == NULL) {
Engine->m_UiMgr->OpenSlaveMerchantPrice();
}
else
{
if (Engine->m_UiMgr->uiSlaveMerchantPrice->IsVisible())
Engine->m_UiMgr->uiSlaveMerchantPrice->Close();
else
Engine->m_UiMgr->uiSlaveMerchantPrice->Open();
}
Packet SlavePrice(XSafe, uint8(XSafeOpCodes::PL_SLAVE_MERC));
SlavePrice << uint8(5) << KC << uint8(1);
Engine->Send(&SlavePrice);
}
SetVisible(false);
}
}
return true;
}
void CSlaveMerchant::Open()
{
Packet Update(XSafe, uint8(PL_SLAVE_MERC));//salve merch bilgileri
Update << uint8(1);
Engine->Send(&Update);
SetVisible(true);
}
void CSlaveMerchant::Close()
{
SetVisible(false);
}
void CSlaveMerchant::Clear()
{
for (int i = 0; i < itemsMerch.size(); i++)
{
itemsMerch[i]->icon->SetTex("");
itemsMerch[i]->nItemID = 0;
itemsMerch[i]->tbl = nullptr;
}
for (int i = 0; i < itemsInventory.size(); i++)
{
itemsInventory[i]->icon->SetTex("");
itemsInventory[i]->nItemID = 0;
itemsInventory[i]->tbl = nullptr;
}
}
void CSlaveMerchant::Tick()
{
m_iRemainingTime = Engine->m_PlayerBase->m_iSlaveTime;
/*if (m_iRemainingTime <= 0 || TotalTime == 1)
{
m_iRemainingTime = 0;
Packet CloseMerc(XSafeOpCodes::PL_SLAVE_MERC);
CloseMerc << uint8(6) << uint8(0);
Engine->Send(&CloseMerc);
Close();
//Engine->m_UiMgr->uiIcons->SlaveStatus(false);
}*/
if (m_iRemainingTime > 0)
{
if (m_iRemainingTime == 1)
{
Packet CloseMerc(XSafe, uint8(XSafeOpCodes::PL_SLAVE_MERC));
CloseMerc << uint8(6) << uint8(0);
Engine->Send(&CloseMerc);
Packet CloseMerc2(XSafe, uint8(XSafeOpCodes::PL_SLAVE_MERC));
CloseMerc2 << uint8(3) << uint8(1);
Engine->Send(&CloseMerc2);
}
uint16_t remainingHourse = (uint16_t)ceil((m_iRemainingTime / 60) / 60);
uint16_t remainingMinutes = (uint16_t)ceil((m_iRemainingTime / 60));
uint16_t remainingSeconds = m_iRemainingTime - (remainingMinutes * 60);
uint16_t dakika;
dakika = (m_iRemainingTime - (remainingHourse * 3600)) / 60;
std::string remainingTime;
if (dakika < 10 && remainingSeconds < 10 && remainingHourse < 10)
remainingTime = string_format(xorstr("0%d:0%d:0%d"), remainingHourse, dakika, remainingSeconds);
else if (remainingHourse < 10 && dakika < 10)
remainingTime = string_format(xorstr("0%d:0%d:%d"), remainingHourse, dakika, remainingSeconds);
else if (remainingHourse < 10 && remainingSeconds < 10)
remainingTime = string_format(xorstr("0%d:%d:0%d"), remainingHourse, dakika, remainingSeconds);
else if (remainingHourse < 10)
remainingTime = string_format(xorstr("0%d:%d:%d"), remainingHourse, dakika, remainingSeconds);
else if (dakika < 10 && remainingSeconds < 10)
remainingTime = string_format(xorstr("%d:0%d:0%d"), remainingHourse, dakika, remainingSeconds);
else if (remainingSeconds < 10)
remainingTime = string_format(xorstr("%d:%d:0%d"), remainingHourse, dakika, remainingSeconds);
else remainingTime = string_format(xorstr("%d:%d:%d"), remainingHourse, dakika, remainingSeconds);
txt_sure->SetString(string_format(xorstr("%s"), remainingTime.c_str()));
txt_durum->SetString(xorstr("Active!"));
}
}