Untitled
hhunknown
plain_text
3 years ago
9.2 kB
11
Indexable
#ifdef ENABLE_YANG_LIMIT
long long CShop::Buy(LPCHARACTER ch, BYTE pos)
#else
int CShop::Buy(LPCHARACTER ch, BYTE pos)
#endif
{
if (pos >= m_itemVector.size())
{
sys_log(0, "Shop::Buy : invalid position %d : %s", pos, ch->GetName());
return SHOP_SUBHEADER_GC_INVALID_POS;
}
sys_log(0, "Shop::Buy : name %s pos %d", ch->GetName(), pos);
GuestMapType::iterator it = m_map_guest.find(ch);
if (it == m_map_guest.end())
return SHOP_SUBHEADER_GC_END;
SHOP_ITEM& r_item = m_itemVector[pos];
#ifdef WJ_CHEQUE_SYSTEM
if (r_item.price < 0 && r_item.cheque_price <= 0)
#else
if (r_item.price < 0)
#endif
{
LogManager::instance().HackLog("SHOP_BUY_GOLD_OVERFLOW", ch);
return SHOP_SUBHEADER_GC_NOT_ENOUGH_MONEY;
}
LPITEM pkSelectedItem = ITEM_MANAGER::instance().Find(r_item.itemid);
if (IsPCShop())
{
if (!pkSelectedItem)
{
sys_log(0, "Shop::Buy : Critical: This user seems to be a hacker : invalid pcshop item : BuyerPID:%d SellerPID:%d",
ch->GetPlayerID(),
m_pkPC->GetPlayerID());
return SHOP_SUBHEADER_GC_SOLD_OUT; // @fixme132 false to SHOP_SUBHEADER_GC_SOLD_OUT
}
if ((pkSelectedItem->GetOwner() != m_pkPC))
{
sys_log(0, "Shop::Buy : Critical: This user seems to be a hacker : invalid pcshop item : BuyerPID:%d SellerPID:%d",
ch->GetPlayerID(),
m_pkPC->GetPlayerID());
return SHOP_SUBHEADER_GC_SOLD_OUT; // @fixme132 false to SHOP_SUBHEADER_GC_SOLD_OUT
}
}
#ifdef ENABLE_YANG_LIMIT
long long dwPrice = r_item.price;
#else
DWORD dwPrice = r_item.price;
#endif
#ifdef WJ_CHEQUE_SYSTEM
BYTE byChequePrice = r_item.cheque_price;
#endif
if (it->second) // if other empire, price is triple
dwPrice *= 3;
#ifdef ENABLE_YANG_LIMIT
if (ch->GetGold() < (long long) dwPrice)
{
sys_log(1, "Shop::Buy : Not enough money : %s has %lld, price %lld", ch->GetName(), ch->GetGold(), dwPrice);
return SHOP_SUBHEADER_GC_NOT_ENOUGH_MONEY;
}
#else
if (ch->GetGold() < (int) dwPrice)
{
sys_log(1, "Shop::Buy : Not enough money : %s has %d, price %d", ch->GetName(), ch->GetGold(), dwPrice);
return SHOP_SUBHEADER_GC_NOT_ENOUGH_MONEY;
}
#endif
#ifdef WJ_CHEQUE_SYSTEM
if (ch->GetCheque() < byChequePrice)
{
sys_log(1, "Shop::Buy : Not enough cheque : %s has %d, price %d", ch->GetName(), ch->GetCheque(), byChequePrice);
return SHOP_SUBHEADER_GC_NOT_ENOUGH_CHEQUE;
}
#endif
LPITEM item;
if (m_pkPC) // 피씨가 운영하는 샵은 피씨가 실제 아이템을 가지고있어야 한다.
item = r_item.pkItem;
else
item = ITEM_MANAGER::instance().CreateItem(r_item.vnum, r_item.count);
if (!item)
return SHOP_SUBHEADER_GC_SOLD_OUT;
/*if (!m_pkPC)
{
if (quest::CQuestManager::instance().GetEventFlag("hivalue_item_sell") == 0)
{
if (item->GetVnum() == 70024 || item->GetVnum() == 70035)
{
return SHOP_SUBHEADER_GC_END;
}
}
}*/
int iEmptyPos;
if (item->IsDragonSoul())
{
iEmptyPos = ch->GetEmptyDragonSoulInventory(item);
}
else
{
iEmptyPos = ch->GetEmptyInventory(item->GetSize());
}
if (iEmptyPos < 0)
{
if (m_pkPC)
{
sys_log(1, "Shop::Buy at PC Shop : Inventory full : %s size %d", ch->GetName(), item->GetSize());
return SHOP_SUBHEADER_GC_INVENTORY_FULL;
}
else
{
sys_log(1, "Shop::Buy : Inventory full : %s size %d", ch->GetName(), item->GetSize());
M2_DESTROY_ITEM(item);
return SHOP_SUBHEADER_GC_INVENTORY_FULL;
}
}
#ifdef WJ_CHEQUE_SYSTEM
if(dwPrice)
ch->PointChange(POINT_GOLD, -dwPrice, false);
if(byChequePrice)
ch->PointChange(POINT_CHEQUE, -byChequePrice, false);
#else
ch->PointChange(POINT_GOLD, -dwPrice, false);
#endif
//세금 계산
DWORD dwTax = 0;
int iVal = 0;
{
iVal = quest::CQuestManager::instance().GetEventFlag("personal_shop");
if (0 < iVal)
{
if (iVal > 100)
iVal = 100;
dwTax = dwPrice * iVal / 100;
dwPrice = dwPrice - dwTax;
}
else
{
iVal = 0;
dwTax = 0;
}
}
if (!m_pkPC)
{
CMonarch::instance().SendtoDBAddMoney(dwTax, ch->GetEmpire(), ch);
}
if (m_pkPC)
{
m_pkPC->SyncQuickslot(QUICKSLOT_TYPE_ITEM, item->GetCell(), 255);
if (item->GetVnum() == 90008 || item->GetVnum() == 90009) // VCARD
{
VCardUse(m_pkPC, ch, item);
item = NULL;
}
else
{
char buf[512];
if (item->GetVnum() >= 80003 && item->GetVnum() <= 80007)
{
#ifdef ENABLE_YANG_LIMIT
snprintf(buf, sizeof(buf), "%s FROM: %u TO: %u PRICE: %lld", item->GetName(), ch->GetPlayerID(), m_pkPC->GetPlayerID(), dwPrice, byChequePrice);
#else
snprintf(buf, sizeof(buf), "%s FROM: %u TO: %u PRICE: %u", item->GetName(), ch->GetPlayerID(), m_pkPC->GetPlayerID(), dwPrice);
#endif
LogManager::instance().GoldBarLog(ch->GetPlayerID(), item->GetID(), SHOP_BUY, buf);
LogManager::instance().GoldBarLog(m_pkPC->GetPlayerID(), item->GetID(), SHOP_SELL, buf);
}
item->RemoveFromCharacter();
if (item->IsDragonSoul())
item->AddToCharacter(ch, TItemPos(DRAGON_SOUL_INVENTORY, iEmptyPos));
else
item->AddToCharacter(ch, TItemPos(INVENTORY, iEmptyPos));
ITEM_MANAGER::instance().FlushDelayedSave(item);
#ifdef ENABLE_YANG_LIMIT
#ifdef WJ_CHEQUE_SYSTEM
snprintf(buf, sizeof(buf), "%s %u(%s) %lld %u %u", item->GetName(), m_pkPC->GetPlayerID(), m_pkPC->GetName(), dwPrice, byChequePrice, item->GetCount());
#else
snprintf(buf, sizeof(buf), "%s %u(%s) %lld %u", item->GetName(), m_pkPC->GetPlayerID(), m_pkPC->GetName(), dwPrice, item->GetCount());
#endif
LogManager::instance().ItemLog(ch, item, "SHOP_BUY", buf);
#ifdef WJ_CHEQUE_SYSTEM
snprintf(buf, sizeof(buf), "%s %u(%s) %lld %u %u", item->GetName(), ch->GetPlayerID(), ch->GetName(), dwPrice, byChequePrice, item->GetCount());
#else
snprintf(buf, sizeof(buf), "%s %u(%s) %lld %u", item->GetName(), ch->GetPlayerID(), ch->GetName(), dwPrice, item->GetCount());
#endif
LogManager::instance().ItemLog(m_pkPC, item, "SHOP_SELL", buf);
#else
#ifdef WJ_CHEQUE_SYSTEM
snprintf(buf, sizeof(buf), "%s %u(%s) %u %u %u", item->GetName(), m_pkPC->GetPlayerID(), m_pkPC->GetName(), dwPrice, byChequePrice, item->GetCount());
#else
snprintf(buf, sizeof(buf), "%s %u(%s) %u %u", item->GetName(), m_pkPC->GetPlayerID(), m_pkPC->GetName(), dwPrice, item->GetCount());
#endif
LogManager::instance().ItemLog(ch, item, "SHOP_BUY", buf);
#ifdef WJ_CHEQUE_SYSTEM
snprintf(buf, sizeof(buf), "%s %u(%s) %u %u %u", item->GetName(), ch->GetPlayerID(), ch->GetName(), dwPrice, byChequePrice, item->GetCount());
#else
snprintf(buf, sizeof(buf), "%s %u(%s) %u %u", item->GetName(), ch->GetPlayerID(), ch->GetName(), dwPrice, item->GetCount());
#endif
LogManager::instance().ItemLog(m_pkPC, item, "SHOP_SELL", buf);
#endif
}
r_item.pkItem = NULL;
BroadcastUpdateItem(pos);
#ifdef WJ_CHEQUE_SYSTEM
if(dwPrice)
m_pkPC->PointChange(POINT_GOLD, dwPrice, false);
if(byChequePrice)
m_pkPC->PointChange(POINT_CHEQUE, byChequePrice, false);
#else
m_pkPC->PointChange(POINT_GOLD, dwPrice, false);
#endif
if (iVal > 0)
m_pkPC->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("판매금액의 %d %% 가 세금으로 나가게됩니다"), iVal);
CMonarch::instance().SendtoDBAddMoney(dwTax, m_pkPC->GetEmpire(), m_pkPC);
}
else
{
if (item->IsDragonSoul())
item->AddToCharacter(ch, TItemPos(DRAGON_SOUL_INVENTORY, iEmptyPos));
else
item->AddToCharacter(ch, TItemPos(INVENTORY, iEmptyPos));
ITEM_MANAGER::instance().FlushDelayedSave(item);
LogManager::instance().ItemLog(ch, item, "BUY", item->GetName());
if (item->GetVnum() >= 80003 && item->GetVnum() <= 80007)
{
LogManager::instance().GoldBarLog(ch->GetPlayerID(), item->GetID(), PERSONAL_SHOP_BUY, "");
}
DBManager::instance().SendMoneyLog(MONEY_LOG_SHOP, item->GetVnum(), -dwPrice);
}
#ifdef ENABLE_YANG_LIMIT
if (item)
sys_log(0, "SHOP: BUY: name %s %s(x %d):%u price %lld", ch->GetName(), item->GetName(), item->GetCount(), item->GetID(), dwPrice);
#else
if (item)
sys_log(0, "SHOP: BUY: name %s %s(x %d):%u price %u", ch->GetName(), item->GetName(), item->GetCount(), item->GetID(), dwPrice);
#endif
ch->Save();
return (SHOP_SUBHEADER_GC_OK);
}Editor is loading...