UINT CGPlayerShopTypeHandler::Execute( CGPlayerShopType* pPacket, Player* pPlayer ) { __ENTER_FUNCTION GamePlayer* pGamePlayer = (GamePlayer*)pPlayer ; Assert( pGamePlayer ) ; Obj_Human* pHuman = pGamePlayer->GetHuman() ; Assert( pHuman ) ; Scene* pScene = pHuman->getScene() ; if( pScene==NULL ) { Assert(FALSE) ; return PACKET_EXE_ERROR ; } //检查线程执行资源是否正确 Assert( MyGetCurrentThreadID()==pScene->m_ThreadID ) ; _PLAYERSHOP_GUID nShopID = pPacket->GetShopID(); //商店ID BYTE nType = pPacket->GetType(); //存到哪 PlayerShopManager* pPlayerShopManager = pScene->GetPlayerShopManager(); PlayerShop* pPlayerShop = pPlayerShopManager->GetPlayerShopByGUID(nShopID); Assert(pPlayerShop); if(pPlayerShop->GetShopStatus() == STATUS_PLAYER_SHOP_ON_SALE) {//商店未开张 g_pLog->FastSaveLog( LOG_FILE_1, "CGPlayerShopMoneyHandler::Name=%s shop close" ,pHuman->GetName()) ; return PACKET_EXE_CONTINUE ; } //是不是自己的店 BOOL bIsMine = (pHuman->GetGUID() == pPlayerShop->GetOwnerGuid())? TRUE:FALSE; //是不是自己可以管理的店 BOOL bCanManager = pPlayerShop->IsPartner(pHuman->GetGUID()); if(bIsMine == FALSE ) { //log... return PACKET_EXE_CONTINUE; } GCPlayerShopType MsgToClient; TYPE_PLAYER_SHOP CurrentType = pPlayerShop->GetShopType(); if((BYTE)CurrentType == nType) { //log... g_pLog->FastSaveLog( LOG_FILE_1, "CGPlayerShopTypeHandler::Name=%s, needn't change" ,pHuman->GetName()) ; return PACKET_EXE_CONTINUE ; } pPlayerShop->SetShopType((TYPE_PLAYER_SHOP)nType); MsgToClient.SetShopID(nShopID); MsgToClient.SetType(nType); pGamePlayer->SendPacket(&MsgToClient); g_pLog->FastSaveLog( LOG_FILE_1, "CGPlayerShopTypeHandler::Name=%s new type = %d" ,pHuman->GetName(), nType) ; return PACKET_EXE_CONTINUE ; __LEAVE_FUNCTION return PACKET_EXE_ERROR ; }
UINT CGPlayerShopOpenStallHandler::Execute( CGPlayerShopOpenStall* pPacket, Player* pPlayer ) { __ENTER_FUNCTION GamePlayer* pGamePlayer = (GamePlayer*)pPlayer ; Assert( pGamePlayer ) ; Obj_Human* pHuman = pGamePlayer->GetHuman() ; Assert( pHuman ) ; Scene* pScene = pHuman->getScene() ; if( pScene==NULL ) { Assert(FALSE) ; return PACKET_EXE_ERROR ; } //检查线程执行资源是否正确 Assert( MyGetCurrentThreadID()==pScene->m_ThreadID ) ; _PLAYERSHOP_GUID nShopID = pPacket->GetShopID(); //商店ID BYTE nStallIndex = pPacket->GetStallIndex(); //柜台索引 BYTE bOpen = pPacket->GetOpen(); //是否开张 BYTE nShopSerial = pPacket->GetShopSerial(); GCPlayerShopError MsgError; PlayerShopManager* pPlayerShopManager = pScene->GetPlayerShopManager(); PlayerShop* pPlayerShop = pPlayerShopManager->GetPlayerShopByGUID(nShopID); Assert(pPlayerShop); if(pPlayerShop->GetShopStatus() == STATUS_PLAYER_SHOP_ON_SALE) {//商店未开张 g_pLog->FastSaveLog( LOG_FILE_1, "CGPlayerShopOpenStallHandler::Name=%s shop close" ,pHuman->GetName()) ; return PACKET_EXE_CONTINUE ; } //是不是自己的店 BOOL bIsMine = (pHuman->GetGUID() == pPlayerShop->GetOwnerGuid())? TRUE:FALSE; //是不是自己可以管理的店 BOOL bCanManager = pPlayerShop->IsPartner(pHuman->GetGUID()); if(bIsMine == FALSE) { //log... return PACKET_EXE_CONTINUE; } if(nShopSerial != pPlayerShop->GetSerial()) { MsgError.SetID(PLAYERSHOP_MSG::ERR_SHOP_SALE_OUT_SERIAL_IS_CHANGED); pGamePlayer->SendPacket(&MsgError); g_pLog->FastSaveLog( LOG_FILE_1, "CGItemSynchHandler::Name=%s Serials had changed" ,pHuman->GetName()) ; return PACKET_EXE_CONTINUE ; } PlayerStallBox* pPlayerStallBox = pPlayerShop->GetPlayerStallBoxByIndex(nStallIndex); BOOL bRefresh = FALSE; if(pPlayerStallBox->GetStallStatus() == STALL_CLOSE && bOpen) { pPlayerStallBox->SetStallStatus(STALL_OPEN); BYTE nStallOnSale = pPlayerShop->GetNumStallOnSale(); pPlayerShop->SetNumStallOnSale(nStallOnSale+1); bRefresh = TRUE; //开张:AAA开张了第N间柜台(AAA为操作者名,N为柜台所属间数) RecordOpt::Excute(REC_OPEN, pPlayerShop->GetManagerRecord(), (CHAR*)pHuman->GetName(), (INT)nStallIndex); } else if(pPlayerStallBox->GetStallStatus() == STALL_OPEN && !bOpen) { pPlayerStallBox->SetStallStatus(STALL_CLOSE); BYTE nStallOnSale = pPlayerShop->GetNumStallOnSale(); pPlayerShop->SetNumStallOnSale(nStallOnSale-1); bRefresh = TRUE; //打烊:AAA打烊了第N间柜台(AAA为操作者名,N为柜台所属间数) RecordOpt::Excute(REC_CLOSE, pPlayerShop->GetManagerRecord(), (CHAR*)pHuman->GetName(), (INT)nStallIndex); } if(bRefresh) { GCPlayerShopOpenStall MsgToClient; MsgToClient.SetShopID(nShopID); MsgToClient.SetStallIndex(nStallIndex); MsgToClient.SetOpen(bOpen); MsgToClient.SetShopSerial(pPlayerShop->IncSerial()); pGamePlayer->SendPacket(&MsgToClient); } g_pLog->FastSaveLog( LOG_FILE_1, "CGPlayerShopOpenStallHandler::Name=%s" ,pHuman->GetName()) ; return PACKET_EXE_CONTINUE ; __LEAVE_FUNCTION return PACKET_EXE_ERROR ; }
UINT CGPlayerShopNameHandler::Execute( CGPlayerShopName* pPacket, Player* pPlayer ) { __ENTER_FUNCTION GamePlayer* pGamePlayer = (GamePlayer*)pPlayer ; Assert( pGamePlayer ) ; Obj_Human* pHuman = pGamePlayer->GetHuman() ; Assert( pHuman ) ; Scene* pScene = pHuman->getScene() ; if( pScene==NULL ) { Assert(FALSE) ; return PACKET_EXE_ERROR ; } //检查线程执行资源是否正确 Assert( MyGetCurrentThreadID()==pScene->m_ThreadID ) ; _PLAYERSHOP_GUID nShopID = pPacket->GetShopID(); //商店ID BYTE PlayerShopNameSize = pPacket->GetPlayerShopNameSize(); //商店描述 CHAR* PlayerShopName = pPacket->GetPlayerShopName(); //获得商店名 PlayerShopManager* pPlayerShopManager = pScene->GetPlayerShopManager(); PlayerShop* pPlayerShop = pPlayerShopManager->GetPlayerShopByGUID(nShopID); Assert(pPlayerShop); //是不是自己的店.只有店主有资格更改此属性 BOOL bIsMine = (pHuman->GetGUID() == pPlayerShop->GetOwnerGuid())? TRUE:FALSE; if(bIsMine == FALSE ) { //log... return PACKET_EXE_CONTINUE; } if(pPlayerShop->GetShopStatus() == STATUS_PLAYER_SHOP_ON_SALE) {//商店未开张 g_pLog->FastSaveLog( LOG_FILE_1, "CGPlayerShopNameHandler::Name=%s shop close" ,pHuman->GetName()) ; return PACKET_EXE_CONTINUE ; } //如果玩家身上的金钱≥10金 *商业指数,修改成功。 pPlayerShopManager->ClampComFactor(); FLOAT fNeedMoney = (FLOAT)100000.0*pPlayerShopManager->GetComFactor(); if(pHuman->GetMoney()<(UINT)fNeedMoney) { //通知客户端购买商店成功 GCPlayerShopError Msg; Msg.SetID(PLAYERSHOP_MSG::ERR_SHOP_NOT_ENOUTH_MONEY_TO_CHANGE_NAME); pHuman->GetPlayer()->SendPacket(&Msg); } //扣钱 pHuman->SetMoney(pHuman->GetMoney() - (UINT)fNeedMoney); //更改店名 pPlayerShop->SetShopName(PlayerShopName, PlayerShopNameSize); //更改称号 CHAR szMsgTitle[256] = {0}; sprintf(szMsgTitle, "%s大掌柜", PlayerShopName); pHuman->SetShangDianName(szMsgTitle,(BYTE)strlen(szMsgTitle)); pHuman->UpdateTitlesToClient(); //通知客户端商店名修改成功 GCPlayerShopError Msg; Msg.SetID(PLAYERSHOP_MSG::ERR_SHOP_SUCCESS_CHANGE_NAME); pHuman->GetPlayer()->SendPacket(&Msg); g_pLog->FastSaveLog( LOG_FILE_1, "CGPlayerShopNameHandler::Name=%s" ,pHuman->GetName()) ; return PACKET_EXE_CONTINUE ; __LEAVE_FUNCTION return PACKET_EXE_ERROR ; }
UINT CGPlayerShopMoneyHandler::Execute( CGPlayerShopMoney* pPacket, Player* pPlayer ) { __ENTER_FUNCTION GamePlayer* pGamePlayer = (GamePlayer*)pPlayer ; Assert( pGamePlayer ) ; Obj_Human* pHuman = pGamePlayer->GetHuman() ; Assert( pHuman ) ; Scene* pScene = pHuman->getScene() ; if( pScene==NULL ) { Assert(FALSE) ; return PACKET_EXE_ERROR ; } //检查线程执行资源是否正确 Assert( MyGetCurrentThreadID()==pScene->m_ThreadID ) ; _PLAYERSHOP_GUID nShopID = pPacket->GetShopID(); //商店ID BYTE nOpt = pPacket->GetOpt(); //操作 BYTE nType = pPacket->GetType(); //存到哪 UINT uAmount = pPacket->GetAmount(); //数量 BYTE nShopSerial = pPacket->GetShopSerial(); //商店序列号 GCPlayerShopError MsgError; PlayerShopManager* pPlayerShopManager = pScene->GetPlayerShopManager(); PlayerShop* pPlayerShop = pPlayerShopManager->GetPlayerShopByGUID(nShopID); Assert(pPlayerShop); if(pPlayerShop->GetShopStatus() == STATUS_PLAYER_SHOP_ON_SALE) {//商店未开张 g_pLog->FastSaveLog( LOG_FILE_1, "CGPlayerShopMoneyHandler::Name=%s shop close" ,pHuman->GetName()) ; return PACKET_EXE_CONTINUE ; } //是不是自己的店 BOOL bIsMine = (pHuman->GetGUID() == pPlayerShop->GetOwnerGuid())? TRUE:FALSE; //是不是自己可以管理的店 BOOL bCanManager = pPlayerShop->IsPartner(pHuman->GetGUID()); if(bIsMine == FALSE && bCanManager == FALSE) { //log... return PACKET_EXE_CONTINUE; } if(nShopSerial != pPlayerShop->GetSerial()) { MsgError.SetID(PLAYERSHOP_MSG::ERR_SHOP_SALE_OUT_SERIAL_IS_CHANGED); pGamePlayer->SendPacket(&MsgError); g_pLog->FastSaveLog( LOG_FILE_1, "CGItemSynchHandler::Name=%s Serials had changed" ,pHuman->GetName()) ; return PACKET_EXE_CONTINUE ; } GCPlayerShopMoney MsgToClient; MsgToClient.SetShopID(nShopID); switch(nOpt) { case CGPlayerShopMoney::OPT_SAVE_MONEY: {//存钱 if(pHuman->GetMoney() < uAmount) { Assert(0); g_pLog->FastSaveLog( LOG_FILE_1, "ERROR:CGPlayerShopMoneyHandler::Name=%s, Out Of Money In Packet" ,pHuman->GetName()) ; return PACKET_EXE_CONTINUE ; } if(nType == CGPlayerShopMoney::TYPE_BASE_MONEY) { UINT uBaseMoney = pPlayerShop->GetBaseMoney(); if(uBaseMoney+uAmount > 10000000) {//超过1000金 Assert(0); g_pLog->FastSaveLog( LOG_FILE_1, "ERROR:CGPlayerShopMoneyHandler::Name=%s, uBaseMoney+uAmount > 10000000" ,pHuman->GetName()) ; return PACKET_EXE_CONTINUE ; } UINT uRealBaseMoney = (UINT)(uBaseMoney+(FLOAT)uAmount*(1-0.03)); pPlayerShop->SetBaseMoney(uRealBaseMoney); //充入本金:AAA往店铺本金中充入(换行)?金?银?铜(AAA为操作者名) RecordOpt::Excute(REC_INPUT_BASE, pPlayerShop->GetManagerRecord(), (CHAR*)pHuman->GetName(), (INT)(uRealBaseMoney - uBaseMoney)); MsgToClient.SetType(GCPlayerShopMoney::TYPE_BASE_MONEY); MsgToClient.SetAmount(uRealBaseMoney); MsgToClient.SetShopSerial(pPlayerShop->IncSerial()); pGamePlayer->SendPacket(&MsgToClient); } else if(nType == CGPlayerShopMoney::TYPE_PROFIT_MONEY) { UINT uProfitMoney = pPlayerShop->GetProfitMoney(); UINT uRealProfitMoney = (UINT)(uProfitMoney+(FLOAT)uAmount*(1-0.03)); pPlayerShop->SetProfitMoney(uRealProfitMoney); MsgToClient.SetType(GCPlayerShopMoney::TYPE_PROFIT_MONEY); MsgToClient.SetAmount(uRealProfitMoney); MsgToClient.SetShopSerial(pPlayerShop->IncSerial()); //充入赢利资金:AAA往店铺赢利资金中充入(换行)?金?银?铜(AAA为操作者名) RecordOpt::Excute(REC_INPUT_PROFIT, pPlayerShop->GetManagerRecord(), (CHAR*)pHuman->GetName(), (INT)(uRealProfitMoney - uProfitMoney)); pGamePlayer->SendPacket(&MsgToClient); } pHuman->SetMoney(pHuman->GetMoney() - uAmount); MONEY_LOG_PARAM MoneyLogParam; MoneyLogParam.CharGUID = pHuman->GetGUID(); MoneyLogParam.TargetGUID = pPlayerShop->GetOwnerGuid(); MoneyLogParam.OPType = MONEY_PLAYERSHOP_SAVE; MoneyLogParam.Count = uAmount; MoneyLogParam.SceneID = pHuman->getScene()->SceneID(); MoneyLogParam.XPos = pHuman->getWorldPos()->m_fX; MoneyLogParam.ZPos = pHuman->getWorldPos()->m_fZ; SaveMoneyLog(&MoneyLogParam); } break; case CGPlayerShopMoney::OPT_GET_MONEY: {//取钱 if(nType == CGPlayerShopMoney::TYPE_BASE_MONEY) { UINT uBaseMoney = pPlayerShop->GetBaseMoney(); if(uBaseMoney < uAmount) { Assert(0); g_pLog->FastSaveLog( LOG_FILE_1, "ERROR:CGPlayerShopMoneyHandler::Name=%s, Out Of Money In ShopBase" ,pHuman->GetName()) ; return PACKET_EXE_CONTINUE ; } pPlayerShop->SetBaseMoney(uBaseMoney-uAmount); MsgToClient.SetType(GCPlayerShopMoney::TYPE_BASE_MONEY); MsgToClient.SetAmount(uBaseMoney-uAmount); MsgToClient.SetShopSerial(pPlayerShop->IncSerial()); pGamePlayer->SendPacket(&MsgToClient); } else if(nType == CGPlayerShopMoney::TYPE_PROFIT_MONEY) { UINT uProfitMoney = pPlayerShop->GetProfitMoney(); if(uProfitMoney < uAmount) { Assert(0); g_pLog->FastSaveLog( LOG_FILE_1, "ERROR:CGPlayerShopMoneyHandler::Name=%s, Out Of Money In ShopProfit" ,pHuman->GetName()) ; return PACKET_EXE_CONTINUE ; } pPlayerShop->SetProfitMoney(uProfitMoney-uAmount); MsgToClient.SetType(GCPlayerShopMoney::TYPE_PROFIT_MONEY); MsgToClient.SetAmount(uProfitMoney-uAmount); MsgToClient.SetShopSerial(pPlayerShop->IncSerial()); pGamePlayer->SendPacket(&MsgToClient); } pHuman->SetMoney(pHuman->GetMoney() + uAmount); MONEY_LOG_PARAM MoneyLogParam; MoneyLogParam.CharGUID = pHuman->GetGUID(); MoneyLogParam.TargetGUID = pPlayerShop->GetOwnerGuid(); MoneyLogParam.OPType = MONEY_PLAYERSHOP_WITHDRAW; MoneyLogParam.Count = uAmount; MoneyLogParam.SceneID = pHuman->getScene()->SceneID(); MoneyLogParam.XPos = pHuman->getWorldPos()->m_fX; MoneyLogParam.ZPos = pHuman->getWorldPos()->m_fZ; SaveMoneyLog(&MoneyLogParam); } break; default: break; } g_pLog->FastSaveLog( LOG_FILE_1, "CGPlayerShopMoneyHandler::Name=%s" ,pHuman->GetName()) ; return PACKET_EXE_CONTINUE ; __LEAVE_FUNCTION return PACKET_EXE_ERROR ; }
UINT CGPlayerShopSaleOutHandler::Execute( CGPlayerShopSaleOut* pPacket, Player* pPlayer ) { __ENTER_FUNCTION GamePlayer* pGamePlayer = (GamePlayer*)pPlayer ; Assert( pGamePlayer ) ; Obj_Human* pHuman = pGamePlayer->GetHuman() ; Assert( pHuman ) ; Scene* pScene = pHuman->getScene() ; if( pScene==NULL ) { Assert(FALSE) ; return PACKET_EXE_ERROR ; } //检查线程执行资源是否正确 Assert( MyGetCurrentThreadID()==pScene->m_ThreadID ) ; _PLAYERSHOP_GUID nShopID = pPacket->GetShopID(); //商店ID BYTE bSaleOut = pPacket->GetSaleOut(); UINT uPrice = pPacket->GetPrice(); BYTE nSerial = pPacket->GetSerial(); GCPlayerShopError MsgError; PlayerShopManager* pPlayerShopManager = pScene->GetPlayerShopManager(); PlayerShop* pPlayerShop = pPlayerShopManager->GetPlayerShopByGUID(nShopID); Assert(pPlayerShop); if(pPlayerShop->GetOwnerGuid() != pHuman->GetGUID()) {//只有店主有权限关闭此商店 g_pLog->FastSaveLog( LOG_FILE_1, "CGPlayerShopSaleOutHandler::Name=%s Not Owner" ,pHuman->GetName()) ; return PACKET_EXE_CONTINUE ; } if(pPlayerShop->GetShopStatus() == STATUS_PLAYER_SHOP_ON_SALE && bSaleOut) {//已经售出了,不能再卖了 g_pLog->FastSaveLog( LOG_FILE_1, "CGPlayerShopSaleOutHandler::Name=%s Already Sale Out" ,pHuman->GetName()) ; return PACKET_EXE_CONTINUE ; } if(pPlayerShop->GetShopStatus() != STATUS_PLAYER_SHOP_ON_SALE && !bSaleOut) {//还没盘出,不能再盘入了 g_pLog->FastSaveLog( LOG_FILE_1, "CGPlayerShopSaleOutHandler::Name=%s Already Sale Out" ,pHuman->GetName()) ; return PACKET_EXE_CONTINUE ; } //还有店开着呢 for(INT i = 0; i<MAX_STALL_NUM_PER_SHOP;i++ ) { PlayerStallBox* pPlayerStallBox = pPlayerShop->GetPlayerStallBoxByIndex(i); if(pPlayerStallBox->GetStallStatus() == STALL_OPEN) { MsgError.SetID(PLAYERSHOP_MSG::ERR_SHOP_STILL_STALL_OPEN); pGamePlayer->SendPacket(&MsgError); g_pLog->FastSaveLog( LOG_FILE_1, "CGPlayerShopSaleOutHandler::Name=%s Stall %d is still open" ,pHuman->GetName(), i) ; return PACKET_EXE_CONTINUE ; } } if(nSerial != pPlayerShop->GetSerial()) {//序列号更改 MsgError.SetID(PLAYERSHOP_MSG::ERR_SHOP_SALE_OUT_SERIAL_IS_CHANGED); pGamePlayer->SendPacket(&MsgError); g_pLog->FastSaveLog( LOG_FILE_1, "CGPlayerShopSaleOutHandler::Name=%s Serials had changed" ,pHuman->GetName()) ; return PACKET_EXE_CONTINUE ; } //本金不足 //判断当前本金是否≥30金 *商业指数*已开柜台数 pPlayerShopManager->ClampComFactor(); UINT uMoneyLevel = static_cast<UINT>((FLOAT)pPlayerShop->GetNumStallOpened()*(FLOAT)pPlayerShopManager->GetComFactor()*300000.0); if(pPlayerShop->GetBaseMoney() < uMoneyLevel) { MsgError.SetID(PLAYERSHOP_MSG::ERR_SHOP_BASE_MONEY_TOO_LOW); pGamePlayer->SendPacket(&MsgError); g_pLog->FastSaveLog( LOG_FILE_1, "CGPlayerShopSaleOutHandler::Name=%s Base money is not enough" ,pHuman->GetName()) ; return PACKET_EXE_CONTINUE ; } //标志此店已经售出 if(bSaleOut) { //金钱不够盘出 if(pHuman->GetMoney()<150000*pPlayerShopManager->GetComFactor()) { MsgError.SetID(PLAYERSHOP_MSG::ERR_SHOP_NOT_ENOUTH_MONEY_TO_SALE_OUT); pGamePlayer->SendPacket(&MsgError); g_pLog->FastSaveLog( LOG_FILE_1, "CGPlayerShopSaleOutHandler::Name=%s Base money is not enough" ,pHuman->GetName()) ; return PACKET_EXE_CONTINUE ; } pPlayerShop->SetShopStatus(STATUS_PLAYER_SHOP_ON_SALE); pPlayerShop->SetSaleOutPrice(uPrice); } else { //金钱不够盘回 if(pHuman->GetMoney()<50000*pPlayerShopManager->GetComFactor()) { MsgError.SetID(PLAYERSHOP_MSG::ERR_SHOP_NOT_ENOUTH_MONEY_TO_BUY_BACK); pGamePlayer->SendPacket(&MsgError); g_pLog->FastSaveLog( LOG_FILE_1, "CGPlayerShopSaleOutHandler::Name=%s cancel buy money " ,pHuman->GetName()) ; return PACKET_EXE_CONTINUE ; } pPlayerShop->SetShopStatus(STATUS_PLAYER_SHOP_OPEN); pPlayerShop->SetSaleOutPrice(0); } BYTE uSerial = pPlayerShop->IncSerial(); //通知客户端 GCPlayerShopSaleOut MsgToClient; MsgToClient.SetSaleOut(bSaleOut); MsgToClient.SetSerial(uSerial); pGamePlayer->SendPacket(&MsgToClient); g_pLog->FastSaveLog( LOG_FILE_1, "CGPlayerShopSaleOutHandler::ObjName=%s Sale out = %d" ,pHuman->GetName(), bSaleOut); return PACKET_EXE_CONTINUE ; __LEAVE_FUNCTION return PACKET_EXE_ERROR ; }
UINT CGPlayerShopEstablishHandler::Execute( CGPlayerShopEstablish* pPacket, Player* pPlayer ) { __ENTER_FUNCTION GamePlayer* pGamePlayer = (GamePlayer*)pPlayer ; Assert( pGamePlayer ) ; Obj_Human* pHuman = pGamePlayer->GetHuman() ; Assert( pHuman ) ; Scene* pScene = pHuman->getScene() ; if( pScene==NULL ) { Assert(FALSE) ; return PACKET_EXE_ERROR ; } //检查线程执行资源是否正确 Assert( MyGetCurrentThreadID()==pScene->m_ThreadID ) ; CHAR* pszShopName = pPacket->GetShopName(); BYTE nShopNameSize = pPacket->GetShopNameSize(); BYTE nShopType = pPacket->GetType(); SceneID_t sceneid = pScene->SceneID(); GCPlayerShopError MsgError; PlayerShopManager* pPlayerShopManager = pScene->GetPlayerShopManager(); pPlayerShopManager->ClampComFactor(); FLOAT CommercialFactor = pPlayerShopManager->GetComFactor(); UINT uCost = (UINT)(300000*CommercialFactor*2*1.03); //金钱验证 if(uCost>pHuman->GetMoney()) { g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: CGPlayerShopApplyHandler::Name=%s Cost = %d Money = %d ", pHuman->GetName(), uCost, pHuman->GetMoney() ) ; MsgError.SetID(PLAYERSHOP_MSG::ERR_NOT_ENOUGH_MONEY_TO_NEW); pGamePlayer->SendPacket(&MsgError); return PACKET_EXE_CONTINUE ; } //需要再验证是不是已经建立满了商店了 if(nShopType == PLAYERSHOP_MSG::TYPE_ITEM) { if( !pHuman->GetShopGuid(0).isNull() ) { PlayerShop* pCurShop = pPlayerShopManager->GetPlayerShopByGUID(pHuman->GetShopGuid(0)); if(!pCurShop) { pHuman->GetShopGuid(0).Reset(); } else if(pCurShop->GetOwnerGuid() == pHuman->GetGUID()) { g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: CGPlayerShopApplyHandler::Name=%s Can not create shop", pHuman->GetName()) ; MsgError.SetID(PLAYERSHOP_MSG::ERR_SHOP_ALREADY_EXIST); pGamePlayer->SendPacket(&MsgError); return PACKET_EXE_CONTINUE ; } else { pHuman->GetShopGuid(0).Reset(); } } } else if(nShopType == PLAYERSHOP_MSG::TYPE_PET) { if( !pHuman->GetShopGuid(1).isNull() ) { PlayerShop* pCurShop = pPlayerShopManager->GetPlayerShopByGUID(pHuman->GetShopGuid(1)); if(!pCurShop) { pHuman->GetShopGuid(1).Reset(); } else if(pCurShop->GetOwnerGuid() == pHuman->GetGUID()) { g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: CGPlayerShopApplyHandler::Name=%s Can not create shop", pHuman->GetName()) ; MsgError.SetID(PLAYERSHOP_MSG::ERR_SHOP_ALREADY_EXIST); pGamePlayer->SendPacket(&MsgError); return PACKET_EXE_CONTINUE ; } else { pHuman->GetShopGuid(1).Reset(); } } } else { Assert(0); g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: CGPlayerShopApplyHandler::Name=%s Can not create shop", pHuman->GetName(), uCost, pHuman->GetMoney() ) ; MsgError.SetID(PLAYERSHOP_MSG::ERR_SHOP_ALREADY_EXIST); pGamePlayer->SendPacket(&MsgError); return PACKET_EXE_CONTINUE ; } //... //重名验证 for(UINT i =0; i<MAX_SHOP_NUM_PER_SCENE; i++) { PlayerShop* pTempShop = pPlayerShopManager->GetPlayerShopByIndex(i); if(!pTempShop) { continue; } else { if(!strcmp(pszShopName, pTempShop->GetShopName())) { g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: CGPlayerShopApplyHandler::Name = %s This name has already existed", pHuman->GetName()) ; MsgError.SetID(PLAYERSHOP_MSG::ERR_NAME_ALREADY_EXISTED); pGamePlayer->SendPacket(&MsgError); return PACKET_EXE_CONTINUE ; } } } //New一个商店 INT nIndex = pPlayerShopManager->NewPlayerShop(); if(nIndex < 0) { MsgError.SetID(PLAYERSHOP_MSG::ERR_NOT_ENOUGH_SHOP_IN_POOL); pGamePlayer->SendPacket(&MsgError); g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: CGPlayerShopEstablishHandler::Name=%s OUT OF SHOP POOL", pHuman->GetName()) ; return PACKET_EXE_CONTINUE ; } PlayerShop* pPlayerShop = pPlayerShopManager->GetPlayerShopByIndex(nIndex); //时间采样 UINT nYear = (UINT)g_pTimeManager->GetYear(); BYTE nMonth = (BYTE)g_pTimeManager->GetMonth(); BYTE nDay = (BYTE)g_pTimeManager->GetDay(); BYTE nHour = (BYTE)g_pTimeManager->GetHour(); BYTE nMin = (BYTE)g_pTimeManager->GetMinute(); //开张了 pPlayerShop->SetShopStatus(STATUS_PLAYER_SHOP_OPEN); //商店类型 if(nShopType == 1) {//物品点 pPlayerShop->SetShopType(TYPE_PLAYER_SHOP_ITEM); pHuman->SetShopGuid(0,pPlayerShop->GetShopGUID()); } else {//宠物店 pPlayerShop->SetShopType(TYPE_PLAYER_SHOP_PET); pHuman->SetShopGuid(1,pPlayerShop->GetShopGUID()); } //冲入本金 pPlayerShop->SetBaseMoney(uCost/2); //本金上限 pPlayerShop->SetMaxBaseMoney(uCost/2); //冲入投资金 pPlayerShop->SetProfitMoney(uCost/2); //商店名 pPlayerShop->SetShopName(pszShopName, nShopNameSize); //商店描述 pPlayerShop->SetShopDesc("",0); //店主名 pPlayerShop->SetOwnerName(pHuman->GetName()); //店主GUID pPlayerShop->SetOwnerGuid(pHuman->GetGUID()); //商店的建立时间 pPlayerShop->SetFoundedYear(nYear); pPlayerShop->SetFoundedMonth(nMonth); pPlayerShop->SetFoundedDay(nDay); pPlayerShop->SetFoundedHour(nHour); pPlayerShop->SetFoundedMin(nMin); //设置开放的柜台数 pPlayerShop->SetNumStallOpened(1); //设置开张的柜台数 pPlayerShop->SetNumStallOnSale(0); //柜台开张 PlayerStallBox* pNewPlayerStallBox = pPlayerShop->GetPlayerStallBoxByIndex(0); pNewPlayerStallBox->SetStallStatus(PLAYER_SHOP::STALL_CLOSE); //扣钱 pHuman->SetMoney(pHuman->GetMoney()-uCost); MONEY_LOG_PARAM MoneyLogParam; MoneyLogParam.CharGUID = pHuman->GetGUID(); MoneyLogParam.TargetGUID = pPlayerShop->GetOwnerGuid(); MoneyLogParam.OPType = MONEY_CREATE_PLAYERSHOP_OUTCOME; MoneyLogParam.Count = uCost; MoneyLogParam.SceneID = pHuman->getScene()->SceneID(); MoneyLogParam.XPos = pHuman->getWorldPos()->m_fX; MoneyLogParam.ZPos = pHuman->getWorldPos()->m_fZ; SaveMoneyLog(&MoneyLogParam); //"AAA(店铺唯一ID)开张大吉,大掌柜BBB(玩家自身名字)恭迎惠顾。" CHAR szMsgChat[256] = {0}; sprintf(szMsgChat, "@*;SrvMsg;CHAT_PS_OPEN;%s;%s", pszShopName, pHuman->GetName()); GWChat* pChatPacket = (GWChat*)(g_pPacketFactoryManager->CreatePacket(PACKET_GW_CHAT)) ; pChatPacket->SetSourGUID(pHuman->GetGUID()); pChatPacket->SetChatType( CHAT_TYPE_SYSTEM ) ; pChatPacket->SetContexSize( (BYTE)strlen(szMsgChat)) ; pChatPacket->SetContex( szMsgChat ) ; g_pServerManager->SendPacket( pChatPacket, INVALID_ID ); CHAR szMsgTitle[256] = {0}; sprintf(szMsgTitle, "%s大掌柜", pszShopName); pHuman->SetShangDianName(szMsgTitle,(BYTE)strlen(szMsgTitle)); pHuman->UpdateTitlesToClient(); GCPlayerShopEstablish Msg; Msg.SetShopName(pPlayerShop->GetShopName()); pGamePlayer->SendPacket(&Msg); g_pLog->FastSaveLog( LOG_FILE_1, "CGPlayerShopEstablishHandler::Name=%s" ,pHuman->GetName()) ; return PACKET_EXE_CONTINUE ; __LEAVE_FUNCTION return PACKET_EXE_ERROR ; }