DragonNest/Server/ServerCommon/SecondarySkillRepositoryServer.cpp

562 lines
34 KiB
C++
Raw Normal View History

2024-12-20 16:56:44 +08:00
<EFBFBD><EFBFBD>
#include "Stdafx.h"
#include "SecondarySkillRepositoryServer.h"
#include "SecondarySkillEventHandlerServer.h"
#include "SecondarySkill.h"
#include "DNUserSession.h"
#include "ManufactureSkill.h"
#include "SecondarySkillFactory.h"
#include "SecondarySkillRecipe.h"
#include "DNGameDataManager.h"
#if defined( PRE_ADD_SECONDARY_SKILL )
CSecondarySkillRepositoryServer::CSecondarySkillRepositoryServer( CDNUserSession* pSession )
:m_pSession(pSession),m_bManufacturing(false)
{
m_pEventHandler = new CSecondarySkillEventHandlerServer( pSession );
}
void CSecondarySkillRepositoryServer::SendList()
{
SecondarySkill::SCList TxPacket;
memset( &TxPacket, 0, sizeof(TxPacket) );
_ASSERT( m_mSecondarySkill.size() <= _countof(TxPacket.SkillList) );
if( m_mSecondarySkill.size() > _countof(TxPacket.SkillList) )
return;
for( std::map<int,CSecondarySkill*>::iterator itor=m_mSecondarySkill.begin() ; itor!=m_mSecondarySkill.end() ; ++itor )
{
CSecondarySkill* pSkill = (*itor).second;
TxPacket.SkillList[TxPacket.cCount].iSkillID = pSkill->GetSkillID();
TxPacket.SkillList[TxPacket.cCount].iExp = pSkill->GetExp();
TxPacket.SkillList[TxPacket.cCount].Grade = pSkill->GetGrade();
TxPacket.SkillList[TxPacket.cCount].iLevel = pSkill->GetLevel();
++TxPacket.cCount;
}
int iSize = sizeof(TxPacket)-sizeof(TxPacket.SkillList)+(TxPacket.cCount*sizeof(TxPacket.SkillList[0]));
m_pSession->AddSendData( SC_SECONDARYSKILL, eSecondarySkill::SC_LIST, reinterpret_cast<char*>(&TxPacket), iSize );
#if defined( _WORK )
for( int i=0 ; i<TxPacket.cCount ; ++i )
{
WCHAR wszBuf[MAX_PATH];
wsprintf( wszBuf, L"[<00><>pȤ¬<C8A4>] SC_LIST SkillID:%d Exp:%d", TxPacket.SkillList[i].iSkillID, TxPacket.SkillList[i].iExp );
m_pSession->SendDebugChat( wszBuf );
}
#endif // #if defined( _WORK )
_SendRecipeList();
}
void CSecondarySkillRepositoryServer::_SendRecipeList()
{
for( std::map<int,CSecondarySkill*>::iterator itor=m_mSecondarySkill.begin() ; itor!=m_mSecondarySkill.end() ; ++itor )
{
CSecondarySkill* pSkill = (*itor).second;
if( pSkill->GetType() != SecondarySkill::Type::ManufactureSkill )
continue;
CManufactureSkill* pManufactureSkill = static_cast<CManufactureSkill*>(pSkill);
if( pManufactureSkill->GetRecipeCount() <= 0 )
continue;
std::vector<CSecondarySkillRecipe*> vList;
pManufactureSkill->CopyList( vList );
// Send Recipe
SecondarySkill::SCRecipeList TxPacket;
memset( &TxPacket, 0, sizeof(TxPacket) );
TxPacket.cCount = static_cast<BYTE>(vList.size());
for( UINT i=0 ; i<TxPacket.cCount ; ++i )
{
TxPacket.RecipeList[i].iSkillID = vList[i]->GetSkillID();
TxPacket.RecipeList[i].iItemID = vList[i]->GetItemID();
TxPacket.RecipeList[i].biItemSerial = vList[i]->GetItemSerial();
TxPacket.RecipeList[i].nExp = vList[i]->GetExp();
#if defined( _WORK )
WCHAR wszBuf[MAX_PATH];
wsprintf( wszBuf, L"[<00><>pȤ¬<C8A4>] SC_RECIPE_LIST SkillID:%d ItemID:%d ItemSerial:%I64d Exp:%d", TxPacket.RecipeList[i].iSkillID, TxPacket.RecipeList[i].iItemID, TxPacket.RecipeList[i].biItemSerial, TxPacket.RecipeList[i].nExp );
m_pSession->SendDebugChat( wszBuf );
#endif // #if defined( _WORK )
}
int iSize = sizeof(TxPacket)-sizeof(TxPacket.RecipeList)+(TxPacket.cCount*sizeof(TxPacket.RecipeList[0]));
m_pSession->AddSendData( SC_SECONDARYSKILL, eSecondarySkill::SC_RECIPE_LIST, reinterpret_cast<char*>(&TxPacket), iSize );
}
}
// ERROR_NONE : OK
// <EFBFBD><EFBFBD>x<EFBFBD> : <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int CSecondarySkillRepositoryServer::CanCreate( CSecondarySkill* pCreateSkill )
{
int iMaxCount = 0;
switch( pCreateSkill->GetType() )
{
case SecondarySkill::Type::ManufactureSkill:
{
iMaxCount = SecondarySkill::Max::LearnManufactureSkill;
break;
}
case SecondarySkill::Type::ProductionSkill:
{
iMaxCount = SecondarySkill::Max::LearnProductionSkill;
break;
}
case SecondarySkill::Type::CommonSkill:
{
iMaxCount = SecondarySkill::Max::LearnCommonSkill;
break;
}
}
// <EFBFBD><EFBFBD><EFBFBD> <EFBFBD> \<EFBFBD><EFBFBD> <EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if( Get( pCreateSkill->GetSkillID() ) || GetCount( pCreateSkill->GetType() ) >= iMaxCount )
return ERROR_GENERIC_INVALIDREQUEST;
return ERROR_NONE;
}
// ERROR_NONE : OK
// <EFBFBD><EFBFBD>x<EFBFBD> : <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int CSecondarySkillRepositoryServer::CanAddRecipe( CSecondarySkill* pSkill, CSecondarySkillRecipe* pRecipe )
{
// ȑ<EFBFBD> <EFBFBD>¬<EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if( pSkill->GetType() != SecondarySkill::Type::ManufactureSkill )
return ERROR_GENERIC_INVALIDREQUEST;
// \<EFBFBD><EFBFBD> Recipe <EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CManufactureSkill* pManufactureSkill = static_cast<CManufactureSkill*>(pSkill);
if( pManufactureSkill->GetRecipeCount() >= pManufactureSkill->GetMaxRecipeCount() )
return ERROR_SECONDARYSKILL_ADDRECIPE_MAX;
// <EFBFBD>¬<EFBFBD>ID <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if( pSkill->GetSkillID() != pRecipe->GetSkillID() )
return ERROR_GENERIC_INVALIDREQUEST;
// Grade <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if( pSkill->GetGrade() < pRecipe->GetRequiredGrade() )
return ERROR_GENERIC_INVALIDREQUEST;
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if( pSkill->GetGrade() == pRecipe->GetRequiredGrade() )
{
if( pSkill->GetLevel() < pRecipe->GetRequiredSkillLevel() )
return ERROR_GENERIC_INVALIDREQUEST;
}
return ERROR_NONE;
}
// ERROR_NONE : OK |<EFBFBD>L<EFBFBD> CSecondarySkillRecipe <EFBFBD><EFBFBD>x<EFBFBD>0<EFBFBD> 8<EFBFBD>p<EFBFBD><EFBFBD><<EFBFBD>\<EFBFBD> <EFBFBD>X<EFBFBD>
// <EFBFBD><EFBFBD>x<EFBFBD> : <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int CSecondarySkillRepositoryServer::CanDeleteRecipe( CSecondarySkill* pSkill, int iItemID, CSecondarySkillRecipe*& pRecipe )
{
// Type <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if( pSkill->GetType() != SecondarySkill::Type::ManufactureSkill )
return ERROR_GENERIC_INVALIDREQUEST;
// <EFBFBD><EFBFBD><EFBFBD><<EFBFBD> <EFBFBD><EFBFBD>0<EFBFBD>
CManufactureSkill* pManufactureSkill = static_cast<CManufactureSkill*>(pSkill);
pRecipe = pManufactureSkill->GetRecipe( iItemID );
if( pRecipe == NULL )
return ERROR_GENERIC_INVALIDREQUEST;
return ERROR_NONE;
}
// ERROR_NONE : OK |<EFBFBD>L<EFBFBD> CSecondarySkillRecipe <EFBFBD><EFBFBD>x<EFBFBD>0<EFBFBD> 8<EFBFBD>p<EFBFBD><EFBFBD><<EFBFBD>\<EFBFBD> <EFBFBD>X<EFBFBD>
// <EFBFBD><EFBFBD>x<EFBFBD> : <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int CSecondarySkillRepositoryServer::CanExtractRecipe( CSecondarySkill* pSkill, int iItemID, CSecondarySkillRecipe*& pRecipe )
{
// Type <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if( pSkill->GetType() != SecondarySkill::Type::ManufactureSkill )
return ERROR_GENERIC_INVALIDREQUEST;
// <EFBFBD><EFBFBD><EFBFBD><<EFBFBD> <EFBFBD><EFBFBD>0<EFBFBD>
CManufactureSkill* pManufactureSkill = static_cast<CManufactureSkill*>(pSkill);
pRecipe = pManufactureSkill->GetRecipe( iItemID );
if( pRecipe == NULL )
return ERROR_GENERIC_INVALIDREQUEST;
// 100% Full<EFBFBD><EFBFBD><EFBFBD><EFBFBD>x<EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if( pRecipe->GetMaxExp() <= 0 )
return ERROR_GENERIC_INVALIDREQUEST;
if( pRecipe->GetExp() != pRecipe->GetMaxExp() )
return ERROR_GENERIC_INVALIDREQUEST;
return ERROR_NONE;
}
// ERROR_NONE : OK |<EFBFBD>L<EFBFBD> CSecondarySkillRecipe <EFBFBD><EFBFBD>x<EFBFBD>0<EFBFBD> 8<EFBFBD>p<EFBFBD><EFBFBD><<EFBFBD>\<EFBFBD> <EFBFBD>X<EFBFBD>
// <EFBFBD><EFBFBD>x<EFBFBD> : <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int CSecondarySkillRepositoryServer::CanManufacture( CSecondarySkill* pSkill, bool bIsStart, int iItemID, CSecondarySkillRecipe*& pRecipe )
{
// Type <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if( pSkill->GetType() != SecondarySkill::Type::ManufactureSkill )
return ERROR_GENERIC_INVALIDREQUEST;
// <EFBFBD><EFBFBD><EFBFBD><<EFBFBD> <EFBFBD><EFBFBD>0<EFBFBD>
CManufactureSkill* pManufactureSkill = static_cast<CManufactureSkill*>(pSkill);
pRecipe = pManufactureSkill->GetRecipe( iItemID );
if( pRecipe == NULL )
return ERROR_GENERIC_INVALIDREQUEST;
TSecondarySkillRecipeTableData* pRecipeData = g_pDataManager->GetSecondarySkillRecipeTableData( pRecipe->GetItemID() );
if( pRecipeData == NULL )
return ERROR_GENERIC_INVALIDREQUEST;
// ijl<EFBFBD>\<EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
for( int i=0 ; i<_countof(pRecipeData->iToolItemID) ; ++i )
{
if( pRecipeData->iToolItemID[i] <= 0 )
continue;
if( m_pSession->GetItem()->GetInventoryItemCount( pRecipeData->iToolItemID[i] ) <= 0 )
return ERROR_GENERIC_INVALIDREQUEST;
}
// <EFBFBD><EFBFBD≯\<EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
for( int i=0 ; i<_countof(pRecipeData->iMaterialItemCount) ; ++i )
{
if( pRecipeData->iMaterialItemID[i] <= 0 )
continue;
if( m_pSession->GetItem()->GetInventoryItemCount( pRecipeData->iMaterialItemID[i] ) < pRecipeData->iMaterialItemCount[i] )
return ERROR_GENERIC_INVALIDREQUEST;
}
// <EFBFBD><EFBFBD>Ѭ<EFBFBD> H<EFBFBD> <EFBFBD>Ǭ<EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int iCreateItemID = pRecipeData->GetManufactureItemID( pRecipe->GetExp(), pRecipe->GetMaxExp() );
TItemData* pItemData = g_pDataManager->GetItemData( iCreateItemID );
if( pItemData == NULL )
{
_ASSERT(0);
return ERROR_GENERIC_INVALIDREQUEST;
}
if( pItemData->nType != ITEMTYPE_INSTANT )
{
if( m_pSession->GetItem()->FindBlankInventorySlotCount() <= 0 )
return ERROR_GENERIC_INVALIDREQUEST;
}
else
{
// L<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ITEMTYPE_INSTANT ȑ<EFBFBD>t<EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\<EFBFBD><EFBFBD><EFBFBD>.
#if defined( _VILLAGESERVER )
return ERROR_SECONDARYSKILL_MANUFACTURE_DONTALLOWMAP;
#endif // #if defined( _VILLAGESERVER )
}
if( bIsStart == true )
{
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD>\<EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int iResultItemID = pRecipeData->GetManufactureItemID( pRecipe->GetExp(), pRecipe->GetMaxExp() );
TItemData* pResultItemData = g_pDataManager->GetItemData( iResultItemID );
if( pResultItemData == NULL )
{
_ASSERT(0);
return ERROR_GENERIC_INVALIDREQUEST;
}
if( !g_pDataManager->IsUseItemAllowMapTypeCheck( iResultItemID, m_pSession->GetMapIndex() ) )
return ERROR_SECONDARYSKILL_MANUFACTURE_DONTALLOWMAP;
// ֬<EFBFBD> ȑ<EFBFBD><EFBFBD>x<EFBFBD> <EFBFBD>¬<EFBFBD>t<EFBFBD> <EFBFBD>ǔ<EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if( GetManufacturingSkill() )
return ERROR_GENERIC_INVALIDREQUEST;
// t<EFBFBD><EFBFBD><EFBFBD> ȑ<EFBFBD><EFBFBD>x<EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if( pManufactureSkill->bIsManufacturing() == true )
return ERROR_GENERIC_INVALIDREQUEST;
}
else
{
// ȑ<EFBFBD><EFBFBD>x<EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if( pManufactureSkill->bIsManufacturing() == false )
return ERROR_GENERIC_INVALIDREQUEST;
// ȑ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if( timeGetTime()-pManufactureSkill->GetManufactureTick() + 900 < static_cast<DWORD>(pRecipeData->iMaxTime) )
return ERROR_GENERIC_INVALIDREQUEST;
}
return ERROR_NONE;
}
// ERROR_NONE : OK |<EFBFBD>L<EFBFBD> CManufactureSkill <EFBFBD><EFBFBD>x<EFBFBD>0<EFBFBD> 8<EFBFBD>p<EFBFBD><EFBFBD><<EFBFBD>\<EFBFBD> <EFBFBD>X<EFBFBD>
// <EFBFBD><EFBFBD>x<EFBFBD> : <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int CSecondarySkillRepositoryServer::CanCancelManufacture( CManufactureSkill*& pManufacturingSkill )
{
#if defined( _GAMESERVER )
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 8֜<EFBFBD> H<EFBFBD>ij<EFBFBD><EFBFBD> <EFBFBD><EFBFBD>D<EFBFBD> Flag \<EFBFBD> <<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>\<EFBFBD><EFBFBD><EFBFBD>.
if( bIsManufacturing() == false )
return ERROR_GENERIC_INVALIDREQUEST;
#endif // #if defined( _GAMESERVER )
// ֬<EFBFBD> ȑ<EFBFBD><EFBFBD>x<EFBFBD> <EFBFBD>¬<EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
pManufacturingSkill = static_cast<CManufactureSkill*>(GetManufacturingSkill());
if( pManufacturingSkill == NULL )
return ERROR_GENERIC_INVALIDREQUEST;
return ERROR_NONE;
}
// t<EFBFBD>|<EFBFBD>tǸŸ<EFBFBD><EFBFBD><EFBFBD> <EFBFBD>@<EFBFBD> <EFBFBD><EFBFBD><EFBFBD><<EFBFBD> <EFBFBD><EFBFBD><EFBFBD>
int CSecondarySkillRepositoryServer::AddRecipe( SecondarySkill::CSAddRecipe* pPacket )
{
CSecondarySkill* pSkill = Get( pPacket->iSkillID );
if( pSkill == NULL )
return ERROR_SECONDARYSKILL_ADDRECIPE_FAILED;
const TItem* pItem = NULL;
switch( pPacket->cInvenType )
{
case ITEMPOSITION_INVEN:
{
pItem = m_pSession->GetItem()->GetInventory(pPacket->cInvenIndex);
if( pItem == NULL )
return ERROR_SECONDARYSKILL_ADDRECIPE_FAILED;
if( pItem->nSerial != pPacket->biInvenSerial)
return ERROR_SECONDARYSKILL_ADDRECIPE_FAILED;
break;
}
case ITEMPOSITION_CASHINVEN:
{
pItem = m_pSession->GetItem()->GetCashInventory( pPacket->biInvenSerial );
if( pItem == NULL )
return ERROR_SECONDARYSKILL_ADDRECIPE_FAILED;
break;
}
default:
{
return ERROR_SECONDARYSKILL_ADDRECIPE_FAILED;
}
}
// D<EFBFBD>t<EFBFBD>\<EFBFBD> <EFBFBD>Ѕ<EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
TItemData* pItemData = g_pDataManager->GetItemData( pItem->nItemID );
if( pItemData == NULL )
return ERROR_SECONDARYSKILL_ADDRECIPE_FAILED;
if( pItemData->nType != ITEMTYPE_SECONDARYSKILL_RECIPE )
return ERROR_SECONDARYSKILL_ADDRECIPE_FAILED;
// <EFBFBD><EFBFBD><EFBFBD><<EFBFBD> <EFBFBD><EFBFBD>1<EFBFBD>
int iRet = ERROR_SECONDARYSKILL_ADDRECIPE_FAILED;
CSecondarySkillRecipe* pRecipe = NULL;
do
{
pRecipe = CSecondarySkillFactory::CreateRecipe( pPacket->iSkillID, pItem->nItemID, pPacket->biInvenSerial, pItem->wDur );
if( pRecipe == NULL || pRecipe->IsValid() == false )
break;
iRet = CanAddRecipe( pSkill, pRecipe );
if( iRet != ERROR_NONE )
break;
// D<EFBFBD>t<EFBFBD>\<EFBFBD> <EFBFBD>p<EFBFBD>
bool bDeleteRet = false;
if( pPacket->cInvenType == ITEMPOSITION_INVEN )
bDeleteRet = m_pSession->GetItem()->DeleteInventoryBySlot( pPacket->cInvenIndex, 1, pPacket->biInvenSerial, 0 );
else
bDeleteRet = m_pSession->GetItem()->DeleteCashInventoryBySerial( pPacket->biInvenSerial, 1, false );
_ASSERT( bDeleteRet );
// <EFBFBD><EFBFBD><EFBFBD><<EFBFBD> <EFBFBD><EFBFBD><EFBFBD>
CManufactureSkill* pManufactureSkill = static_cast<CManufactureSkill*>(pSkill);
iRet = pManufactureSkill->AddRecipe( pRecipe );
if( iRet != ERROR_NONE )
break;
// EventHandler 8֜<EFBFBD>
m_pEventHandler->OnAddRecipe( pRecipe, pItemData->IsCash );
return ERROR_NONE;
}while( false );
SAFE_DELETE( pRecipe );
return iRet;
}
// DB<EFBFBD><EFBFBD><EFBFBD> <EFBFBD>@<EFBFBD> <EFBFBD><EFBFBD><EFBFBD><<EFBFBD> <EFBFBD><EFBFBD><EFBFBD>
bool CSecondarySkillRepositoryServer::AddRecipe( TSecondarySkillRecipe* pRecipeData )
{
CSecondarySkill* pSkill = Get( pRecipeData->iSkillID );
if( pSkill == NULL )
return false;
CSecondarySkillRecipe* pRecipe = CSecondarySkillFactory::CreateRecipe( pRecipeData->iSkillID, pRecipeData->iItemID, pRecipeData->biItemSerial, pRecipeData->nExp );
do
{
if( pRecipe == NULL || pRecipe->IsValid() == false )
break;
#if defined( _FINAL_BUILD )
if( pSkill->GetType() != SecondarySkill::Type::ManufactureSkill )
break;
#else
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><<EFBFBD><EFBFBD><EFBFBD><EFBFBD>̹ t<EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD>\<EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD>̬<EFBFBD>X<EFBFBD><EFBFBD><EFBFBD> 0<EFBFBD><EFBFBD><EFBFBD><EFBFBD><<EFBFBD>\<EFBFBD> DB<EFBFBD><EFBFBD><EFBFBD> <EFBFBD>@<EFBFBD> p<EFBFBD>t<EFBFBD>0є<EFBFBD> <EFBFBD>°<EFBFBD>\<EFBFBD><EFBFBD><EFBFBD>.
if( CanAddRecipe( pSkill, pRecipe ) != ERROR_NONE )
{
_ASSERT(0);
break;
}
#endif // #if defined( _FINAL_BUILD )
CManufactureSkill* pManufactureSkill = static_cast<CManufactureSkill*>(pSkill);
if( pManufactureSkill->AddRecipe( pRecipe ) != ERROR_NONE )
break;
return true;
}while( false );
SAFE_DELETE( pRecipe );
return false;
}
// t<EFBFBD>|<EFBFBD>tǸŸ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD>@<EFBFBD> <EFBFBD><EFBFBD><EFBFBD><<EFBFBD> <EFBFBD>p<EFBFBD>
bool CSecondarySkillRepositoryServer::DeleteRecipe( SecondarySkill::CSDeleteRecipe* pPacket )
{
CSecondarySkill* pSkill = Get( pPacket->iSkillID );
if( pSkill == NULL )
return false;
CSecondarySkillRecipe* pRecipe = NULL;
if( CanDeleteRecipe( pSkill, pPacket->iItemID, pRecipe ) != ERROR_NONE )
return false;
CManufactureSkill* pManufactureSkill = static_cast<CManufactureSkill*>(pSkill);
if( pManufactureSkill->DeleteRecipe( pRecipe ) == false )
return false;
bool bRet = m_pEventHandler->OnDeleteRecipe( pRecipe );
_ASSERT( bRet );
SAFE_DELETE( pRecipe );
return true;
}
// t<EFBFBD>|<EFBFBD>tǸŸ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD>@<EFBFBD> <EFBFBD><EFBFBD><EFBFBD><<EFBFBD> <EFBFBD>͜<EFBFBD>
bool CSecondarySkillRepositoryServer::ExtractRecipe( SecondarySkill::CSExtractRecipe* pPacket )
{
CSecondarySkill* pSkill = Get( pPacket->iSkillID );
if( pSkill == NULL )
return false;
CSecondarySkillRecipe* pRecipe = NULL;
if( CanExtractRecipe( pSkill, pPacket->iItemID, pRecipe ) != ERROR_NONE )
return false;
CManufactureSkill* pManufactureSkill = static_cast<CManufactureSkill*>(pSkill);
// D<EFBFBD>t<EFBFBD>\<EFBFBD> <EFBFBD>ń<EFBFBD> <EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>l<EFBFBD>
TItemData* pItemData = g_pDataManager->GetItemData( pRecipe->GetItemID() );
if( pItemData == NULL )
return false;
// <EFBFBD><EFBFBD><EFBFBD><<EFBFBD> <EFBFBD>p<EFBFBD>
if( pManufactureSkill->DeleteRecipe( pRecipe ) == false )
return false;
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD>D<EFBFBD>t<EFBFBD>\<EFBFBD>@<EFBFBD> <EFBFBD><EFBFBD>o<EFBFBD> <EFBFBD>\<EFBFBD>t<EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
int iEmptyInvenIndex = -1;
if( pItemData->IsCash != true)
{
iEmptyInvenIndex = m_pSession->GetItem()->FindBlankInventorySlot();
if( iEmptyInvenIndex < 0 )
return false;
TItem ExtractItem;
if( CDNUserItem::MakeItemStruct( pRecipe->GetItemID(), ExtractItem ) == false )
return false;
ExtractItem.nSerial = pRecipe->GetItemSerial();
ExtractItem.wDur = pRecipe->GetExp();
if( m_pSession->GetItem()->CreateInvenWholeItemByIndex( iEmptyInvenIndex, ExtractItem ) != ERROR_NONE )
return false;
}
else
{
TItem ExtractItem;
if( m_pSession->GetItem()->MakeCashItemStruct( 0, pRecipe->GetItemID(), ExtractItem ) == false )
return false;
ExtractItem.nSerial = pRecipe->GetItemSerial();
ExtractItem.wDur = pRecipe->GetExp();
if( m_pSession->GetItem()->CreateCashInvenWholeItem( ExtractItem ) != ERROR_NONE )
return false;
}
bool bRet = m_pEventHandler->OnExtractRecipe( pRecipe, pItemData->IsCash );
_ASSERT( bRet );
SAFE_DELETE( pRecipe );
return true;
}
int CSecondarySkillRepositoryServer::DoManufacture( SecondarySkill::CSManufacture* pPacket )
{
CSecondarySkill* pSkill = Get( pPacket->iSkillID );
if( pSkill == NULL )
return ERROR_SECONDARYSKILL_MANUFACTURE_FAILED;
CSecondarySkillRecipe* pRecipe = NULL;
int iRet = CanManufacture( pSkill, pPacket->bIsStart, pPacket->iItemID, pRecipe );
if( iRet != ERROR_NONE )
return iRet;
bool bRet = m_pEventHandler->OnManufacture( pSkill, pRecipe, pPacket->bIsStart );
_ASSERT( bRet );
return ERROR_NONE;
}
bool CSecondarySkillRepositoryServer::CancelManufacture( bool bSend/*=true*/ )
{
CManufactureSkill* pManufacturingSkill = NULL;
if( CanCancelManufacture( pManufacturingSkill ) != ERROR_NONE )
{
_ASSERT( bIsManufacturing() == false );
return false;
}
_ASSERT( bIsManufacturing() );
_ASSERT( pManufacturingSkill );
m_pEventHandler->OnCancelManufacture( pManufacturingSkill, bSend );
return true;
}
// ֬<EFBFBD> ȑ<EFBFBD><EFBFBD>x<EFBFBD> <EFBFBD>¬<EFBFBD> <EFBFBD><EFBFBD>x<EFBFBD>0<EFBFBD> <EFBFBD><EFBFBD>0<EFBFBD>
CSecondarySkill* CSecondarySkillRepositoryServer::GetManufacturingSkill()
{
for( std::map<int,CSecondarySkill*>::iterator itor=m_mSecondarySkill.begin() ; itor!=m_mSecondarySkill.end() ; ++itor )
{
CSecondarySkill* pSkill = (*itor).second;
if( pSkill->GetType() != SecondarySkill::Type::ManufactureSkill )
continue;
CManufactureSkill* pManufactureSkill = static_cast<CManufactureSkill*>(pSkill);
if( pManufactureSkill->bIsManufacturing() )
return pSkill;
}
return NULL;
}
#endif // #if defined( PRE_ADD_SECONDARY_SKILL )