shop.h ekle
shop.cpp
Kod:Panoya kopyala
bool CShop::HasOwner() const
{
return m_pkPC != NULL;
}
if (HasOwner()) satırlarını kontrol et:
Her birinin sonuna noktalı virgül ve süslü parantezler düzgün mü diye bak.
Düzenlenmiş kod
[CODE title="Shop.cpp"]#include "stdafx.h"
#include "..
#include ame/include/grid.h"
#include "co
#include h"
#include "ut
#include include "co
#include #include "sh
#include nclude "de
#include nclude "de
#include er.h"
#include "ch
#include nclude "ch
#include er.h"
#include "it
#include nclude "it
#include er.h"
#include "bu
#include ager.h"
#include "pa
#include #include "lo
#include clude "db
#include lude "qu
#include er.h"
#include "mo
#include
#include "mo
#include r.h"
#include "lo
#include vice.h"
/* ------------------------------------------------------------------------------------ */
extern int taxes;
extern bool raise_empire_prices;
extern bool trade_effect;
extern int trade_effect_shop_threshold;
CShop::CShop()
: m_dwVnum(0), m_dwNPCVnum(0), m_pkPC(NULL)
#ifdef ENABL
#ifdef SHOPEX_SYSTEM
,m_sPriceType(0), m_szShopName("")
#endif
{
#if
#endif ABL
#ifdef SHOPEX_SYSTEM
m_pGrid = M2_NEW CGrid(10, 10);
#else
m_
#else = M2_NEW CGrid(10, 9);
#endif
}
CS
#endif CShop()
{
TPacketGCShop pack;
pack.header = HEADER_GC_SHOP;
pack.subheader = SHOP_SUBHEADER_GC_END;
pack.size = sizeof(TPacketGCShop);
Broadcast(&pack, sizeof(pack));
for (auto it = m_map_guest.begin(); it != m_map_guest.end(); ++it)
{
LPCHARACTER ch = it->first;
ch->SetShop(NULL);
}
M2_DELETE(m_pGrid);
}
void CShop::SetPCShop(LPCHARACTER ch)
{
m_pkPC = ch;
}
#ifdef ENABL
#ifdef SHOPEX_SYSTEM
bool CShop::Create(DWORD dwVnum, DWORD dwNPCVnum, TShopItemTable * pTable, short price_type, std::string shopname)
#else
bool C
#else :Create(DWORD dwVnum, DWORD dwNPCVnum, TShopItemTable * pTable)
#endif
{
#endif og(0, "SHOP #%d (Shopkee#%d %d)", dwVnum, dwNPCVnum);
m_dwVnum = dwVnum;
m_dwNPCVnum = dwNPCVnum;
#ifdef ENABL
#ifdef SHOPEX_SYSTEM
m_sPriceType = price_type;
m_szShopName = shopname;
#endif
#endif ItemCount;
for (bItemCount = 0; bItemCount < SHOP_HOST_ITEM_MAX_NUM; ++bItemCount)
if (0 == (pTable + bItemCount)->vnum)
break;
SetShopItems(pTable, bItemCount);
return true;
}
void CShop::SetShopItems(TShopItemTable * pTable, short bItemCount)
{
if (bItemCount > SHOP_HOST_ITEM_MAX_NUM)
return;
m_pGrid->Clear();
m_itemVector.resize(SHOP_HOST_ITEM_MAX_NUM);
memset(&m_itemVector[0], 0, sizeof(SHOP_ITEM) * m_itemVector.size());
for (int i = 0; i < bItemCount; ++i)
{
LPITEM pkItem = NULL;
const TItemTable * item_table;
if (m_pkPC)
{
pkItem = m_pkPC->GetItem(pTable->pos);
if (!pkItem)
{
sys_err("cannot find item on pos (%d, %d) (name: %s)", pTable->pos.window_type, pTable->pos.cell, m_pkPC->GetName());
continue;
}
item_table = pkItem->GetProto();
}
else
{
if (!pTable->vnum)
continue;
item_table = ITEM_MANAGER::instance().GetTable(pTable->vnum);
}
if (!item_table)
{
sys_err("Shop: no item table by item vnum #%d", pTable#%dnum);
continue;
}
int iPos;
if (IsPCShop())
iPos = pTable->display_pos;
else
iPos = m_pGrid->FindBlank(1, item_table->bSize);
if (iPos < 0)
{
sys_err("not enough shop window");
continue;
}
if (!m_pGrid->IsEmpty(iPos, 1, item_table->bSize))
{
if (IsPCShop())
sys_err("not empty position for pc shop %s[%d]", m_pkPC->GetName(), m_pkPC->GetPlayerID());
else
sys_err("not empty position for npc shop");
continue;
}
m_pGrid->Put(iPos, 1, item_table->bSize);
SHOP_ITEM & item = m_itemVector[iPos];
item.pkItem = pkItem;
item.itemid = 0;
if (item.pkItem)
{
item.vnum = pkItem->GetVnum();
item.count = pkItem->GetCount();
item.price = pTable->price;
item.itemid = pkItem->GetID();
}
else
{
#ifdef ENABL
#ifdef SHOPEX_SYSTEM
item.vnum = pTable->vnum;
item.count = pTable->count;
item.price = pTable->price;
for (int s = 0; s < 3; ++s)
item.alSockets
= pTable->alSockets;
for (int a = 0; a < 7; ++a)
{
item.aAttr[a].bType = pTable->aAttr[a].bType;
item.aAttr[a].sValue = pTable->aAttr[a].sValue;
}
#else
#else item.vnum = pTable->vnum;
item.count = pTable->count;
if (IS_SET(item_table->dwFlags, ITEM_FLAG_COUNT_PER_1GOLD))
{
if (item_table->dwGold == 0)
item.price = item.count;
else
item.price = item.count / item_table->dwGold;
}
else
item.price = item_table->dwGold * item.count;
#endif
#endif char name[36];
snprintf(name, sizeof(name), "%-20s(#%-5d) (x %d)", item_table->szName, (int) item.vnum, item.count);
sys_log(0, "SHOP_ITEM: %-36s PRICE %-5d", name, item.price);
++pTable;
}
}
// ---------------------- BUY DÜZENLEMESİ ---------------------- //
int CShop::Buy(LPCHARACTER ch, BYTE pos)
{
if (pos >= m_itemVector.size())
{
sys_log(0, "Shop::Buy : invalid position %d : %s", pos, ch->GetName());
return SHOP_SUBHEADER_GC_INVALID_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];
long long llPrice = static_cast<long long>(r_item.price);
if (it->second && raise_empire_prices)
llPrice *= 3;
#ifdef ENABLE_#ifdefOPEX_SYSTEM
if (m_pkPC)
{
if (ch->GetGold() < (int) llPrice)
return SHOP_SUBHEADER_GC_NOT_ENOUGH_MONEY;
}
else
{
if (m_sPriceType == 0 && ch->GetGold() < (int) llPrice)
return SHOP_SUBHEADER_GC_NOT_ENOUGH_MONEY;
else if (m_sPriceType == 1 && ch->GetDragonCoin() < (int) llPrice)
return SHOP_SUBHEADER_GC_NOT_ENOUGH_DRAGON_COIN;
else if (m_sPriceType == 2 && ch->GetDragonMark() < (int) llPrice)
return SHOP_SUBHEADER_GC_NOT_ENOUGH_DRAGON_MARK;
else if (m_sPriceType == 3 && ch->GetAlignment() < (int) llPrice*10)
return SHOP_SUBHEADER_GC_NOT_ENOUGH_ALIGNMENT;
}
#endif
if#endifPC && !r_item.pkItem)
return SHOP_SUBHEADER_GC_SOLD_OUT;
// DragonMark düzeltmesi
if (!m_pkPC && m_sPriceType == 1)
{
if (r_item.vnum != 80014 && r_item.vnum != 80015 && r_item.vnum != 80016 && r_item.vnum != 80017)
ch->SetDragonMark(ch->GetDragonMark() + llPrice);
}
// Diğer işlemler aynen kalabilir...
return SHOP_SUBHEADER_GC_OK;
}
// ---------------------- ADD GUEST DÜZENLEMESİ ---------------------- //
bool CShop::AddGuest(LPCHARACTER ch, DWORD owner_vid, bool bOtherEmpire)
{
if (!ch || ch->GetExchange() || ch->GetShop())
return false;
ch->SetShop(this);
m_map_guest.insert(GuestMapType::value_type(ch, bOtherEmpire));
TPacketGCShop pack;
pack.header = HEADER_GC_SHOP;
pack.subheader = SHOP_SUBHEADER_GC_START;
TPacketGCShopStart pack2;
memset(&pack2, 0, sizeof(pack2));
pack2.owner_vid = owner_vid;
#ifdef ENABLE_2TH_S#ifdefSYSTEM
if (IsPCShop() || HasOwner())
{
strlcpy(pack2.shop_name, m_pkPC->GetName(), SHOP_TAB_NAME_MAX);
pack2.price_type = 0;
}
else
{
pack2.price_type = m_sPriceType;
strlcpy(pack2.shop_name, m_szShopName.c_str(), SHOP_TAB_NAME_MAX);
}
#endif
for (DW#endif= 0; i < m_itemVector.size() && i < SHOP_HOST_ITEM_MAX_NUM; ++i)
{
const SHOP_ITEM & item = m_itemVector;
if (m_pkPC && !item.pkItem)
continue;
pack2.items.vnum = item.vnum;
if (bOtherEmpire && raise_empire_prices)
pack2.items.price = item.price * 3;
else
pack2.items.price = item.price;
pack2.items.count = item.count;
if (m_pkPC && item.pkItem)
{
thecore_memcpy(pack2.items.alSockets, item.pkItem->GetSockets(), sizeof(pack2.items.alSockets));
thecore_memcpy(pack2.items.aAttr, item.pkItem->GetAttributes(), sizeof(pack2.items.aAttr));
}
#ifdef ENABLE_2TH_S#ifdefSYSTEM
else if (!m_pkPC)
{
thecore_memcpy(pack2.items.alSockets, item.alSockets, sizeof(pack2.items.alSockets));
thecore_memcpy(pack2.items.aAttr, item.aAttr, sizeof(pack2.items.aAttr));
}
#endif
}
p#endifze = sizeof(pack) + sizeof(pack2);
ch->GetDesc()->BufferedPacket(&pack, sizeof(TPacketGCShop));
ch->GetDesc()->Packet(&pack2, sizeof(TPacketGCShopStart));
return true;
}[/CODE]