void CShopManager::ShopSearchBuy(LPCHARACTER ch, const TPacketCGPrivateShopSearchBuyItem* p)
{
if (ch == NULL || ch->GetDesc() == NULL || p == NULL)
return;
if (ch->GetExchange() || ch->GetMyShop() || ch->GetShopOwner() || ch->IsOpenSafebox() || ch->IsCubeOpen())
{
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("SHOP_SEARCH_CLOSE_TABS"));
return;
}
LPCHARACTER ShopCH = CHARACTER_MANAGER::instance().FindByPID(p->dwShopPID);
if (ShopCH == NULL)
{
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("SHOP_SEARCH_NO_SHOP"));
return;
}
if (ch == ShopCH) // what?
return;
CShop* pkShop = ShopCH->GetMyShop();
if (pkShop == NULL || pkShop->IsPCShop() == false)
{
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("SHOP_SEARCH_NO_SHOP"));
return;
}
const BYTE bState = ch->GetPrivateShopSearchState();
switch (bState)
{
case SHOP_SEARCH_LOOKING:
{
if (ch->CountSpecifyItem(PRIVATE_SHOP_SEARCH_LOOKING_GLASS) == 0)
{
const TItemTable* GlassTable = ITEM_MANAGER::instance().GetTable(PRIVATE_SHOP_SEARCH_LOOKING_GLASS);
if (GlassTable)
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("SHOP_SEARCH_WHERE_IS_ITEM"), GlassTable->szLocaleName);
return;
}
if (ch->GetMapIndex() != ShopCH->GetMapIndex())
{
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("SHOP_SEARCH_SAMEMAP_ERR"));
return;
}
const DWORD dwSellerVID(ShopCH->GetVID());
if (CTargetManager::instance().GetTargetInfo(ch->GetPlayerID(), TARGET_TYPE_VID_SHOP_SEARCH, dwSellerVID))
CTargetManager::instance().DeleteTarget(ch->GetPlayerID(), SHOP_SEARCH_INDEX, "__SHOPSEARCH_TARGET__");
CTargetManager::Instance().CreateTarget(ch->GetPlayerID(), SHOP_SEARCH_INDEX, "__SHOPSEARCH_TARGET__", TARGET_TYPE_VID_SHOP_SEARCH, dwSellerVID, 0, ch->GetMapIndex(), "Shop Search", 1);
if (CTargetManager::instance().GetTargetInfo(ch->GetPlayerID(), TARGET_TYPE_VID_SHOP_SEARCH, dwSellerVID))
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("SHOP_SEARCH_SUCCESS_TARGET"));
break;
}
case SHOP_SEARCH_TRADING:
{
if (ch->CountSpecifyItem(PRIVATE_SHOP_SEARCH_TRADING_GLASS) == 0)
{
const TItemTable* GlassTable = ITEM_MANAGER::instance().GetTable(PRIVATE_SHOP_SEARCH_TRADING_GLASS);
if (GlassTable)
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("SHOP_SEARCH_WHERE_IS_ITEM"), GlassTable->szLocaleName);
return;
}
ch->SetMyShopTime();
int ret = pkShop->Buy(ch, p->bPos, true);
if (SHOP_SUBHEADER_GC_OK != ret)
{
TPacketGCShop pack;
pack.header = HEADER_GC_SHOP;
pack.subheader = static_cast<BYTE>(ret);
pack.size = sizeof(TPacketGCShop);
ch->GetDesc()->Packet(&pack, sizeof(pack));
}
else
ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("SHOP_SEARCH_OK"));
break;
}
default:
sys_err("ShopSearchBuy ch(%s) wrong state(%d)", ch->GetName(), bState);
break;
}
}