Move git root from Client/ to src/ to track all source code: - Client: Game client source (moved to Client/Client/) - Server: Game server source - GameTools: Development tools - CryptoSource: Encryption utilities - database: Database scripts - Script: Game scripts - rylCoder_16.02.2008_src: Legacy coder tools - GMFont, Game: Additional resources 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
81 lines
1.6 KiB
C++
81 lines
1.6 KiB
C++
#include "stdafx.h"
|
|
#include "Item.h"
|
|
#include "ItemMgr.h"
|
|
#include "ItemFactory.h"
|
|
|
|
using namespace Item;
|
|
|
|
CItemFactory CItemFactory::ms_this;
|
|
|
|
CItemFactory::CItemFactory()
|
|
: m_nCurrentUID(0)
|
|
{
|
|
|
|
|
|
}
|
|
|
|
CItemFactory::~CItemFactory()
|
|
{
|
|
|
|
|
|
}
|
|
|
|
CItem* CItemFactory::CreateItem(const ItemInfo& itemInfo)
|
|
{
|
|
unsigned long dwFlags = itemInfo.m_DetailData.m_dwFlags;
|
|
|
|
CItem* lpItem = NULL;
|
|
|
|
if(DetailData::EQUIP == (dwFlags & DetailData::EQUIP))
|
|
{
|
|
lpItem = new CEquipment(m_nCurrentUID++, itemInfo);
|
|
}
|
|
else if(DetailData::USE_ITEM == (dwFlags & DetailData::USE_ITEM))
|
|
{
|
|
lpItem = new CUseItem(m_nCurrentUID++, itemInfo);
|
|
}
|
|
else
|
|
{
|
|
lpItem = new CItem(m_nCurrentUID++, itemInfo);
|
|
}
|
|
|
|
return lpItem;
|
|
}
|
|
|
|
|
|
CItem* CItemFactory::CreateItem(unsigned short usProtoTypeID)
|
|
{
|
|
const ItemInfo* lpItemInfo = CItemMgr::GetInstance().GetItemInfo(usProtoTypeID);
|
|
|
|
if(NULL != lpItemInfo)
|
|
{
|
|
return CreateItem(*lpItemInfo);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
CItem* CItemFactory::CreateItem(const char* lpSerializedItem_In, size_t& nParseLength_InOut)
|
|
{
|
|
const ItemData* lpItemData = reinterpret_cast<const ItemData*>(lpSerializedItem_In);
|
|
|
|
if(NULL != lpItemData)
|
|
{
|
|
CItem* lpItem = CreateItem(lpItemData->m_usProtoTypeID);
|
|
|
|
if(NULL != lpItem)
|
|
{
|
|
if(!lpItem->SerializeIn(lpSerializedItem_In, nParseLength_InOut))
|
|
{
|
|
delete lpItem;
|
|
lpItem = NULL;
|
|
}
|
|
}
|
|
|
|
return lpItem;
|
|
}
|
|
|
|
return 0;
|
|
}
|