예제 #1
0
UINT CGBankMoneyHandler::Execute( CGBankMoney* 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 ) ;

    BYTE    IsSave = pPacket->GetSaveType();
    INT        Amount = pPacket->GetAmount();
    INT        AmountRMB = pPacket->GetAmountRMB();

    INT CurMoney = pHuman->__GetBankMoney();
    INT CurRMB = pHuman->GetBankRMB();

    if(IsSave & CGBankMoney::SAVE_MONEY)
    {
        if( Amount>(INT)(pHuman->GetMoney()) )
        {
            Amount = pHuman->GetMoney();
        }
        CurMoney += Amount;
        //将来要判一下是否大于银行能存的最大上限
        if(CurMoney>MAX_BANK_MONEY)
            CurMoney = MAX_BANK_MONEY;

        pHuman->__SetBankMoney(CurMoney);
        pHuman->SetMoney(pHuman->GetMoney() - Amount);

        MONEY_LOG_PARAM    MoneyLogParam;
        MoneyLogParam.CharGUID    =    pHuman->GetGUID();
        MoneyLogParam.OPType    =    MONEY_BANK_SAVE;
        MoneyLogParam.Count        =    Amount;
        MoneyLogParam.SceneID    =    pHuman->getScene()->SceneID();
        MoneyLogParam.XPos        =    pHuman->getWorldPos()->m_fX;
        MoneyLogParam.ZPos        =    pHuman->getWorldPos()->m_fZ;
        SaveMoneyLog(&MoneyLogParam);

    }
    else if(IsSave & CGBankMoney::PUTOUT_MONEY)
    {
        if(CurMoney - Amount < 0)
            Amount = CurMoney;

        pHuman->__SetBankMoney(CurMoney - Amount);
        pHuman->SetMoney(pHuman->GetMoney() + Amount);
        MONEY_LOG_PARAM    MoneyLogParam;
        MoneyLogParam.CharGUID    =    pHuman->GetGUID();
        MoneyLogParam.OPType    =    MONEY_BANK_WITHDRAW;
        MoneyLogParam.Count        =    Amount;
        MoneyLogParam.SceneID    =    pHuman->getScene()->SceneID();
        MoneyLogParam.XPos        =    pHuman->getWorldPos()->m_fX;
        MoneyLogParam.ZPos        =    pHuman->getWorldPos()->m_fZ;
        SaveMoneyLog(&MoneyLogParam);

    }
    else if(IsSave & CGBankMoney::UPDATE_MONEY)
    {
        Amount = CurMoney;
    }

    if( IsSave & CGBankMoney::SAVE_RMB )
    {
        if( AmountRMB > pHuman->GetRMB() )
        {
            AmountRMB = pHuman->GetRMB();
        }

        CurRMB += AmountRMB;
        if(CurRMB>MAX_BANK_RMB)
            CurRMB = MAX_BANK_RMB;

        pHuman->SetBankRMB(CurRMB);
        pHuman->SetRMB( pHuman->GetRMB() - AmountRMB );

        MONEY_LOG_PARAM    MoneyLogParam;
        MoneyLogParam.CharGUID    =    pHuman->GetGUID();
        MoneyLogParam.OPType    =    MONEY_BANK_SAVERMB;
        MoneyLogParam.Count        =    Amount;
        MoneyLogParam.SceneID    =    pHuman->getScene()->SceneID();
        MoneyLogParam.XPos        =    pHuman->getWorldPos()->m_fX;
        MoneyLogParam.ZPos        =    pHuman->getWorldPos()->m_fZ;
        SaveMoneyLog(&MoneyLogParam);
    }
    else if( IsSave & CGBankMoney::PUTOUT_RMB )
    {
        if(CurRMB - AmountRMB < 0)
            AmountRMB = CurRMB;

        pHuman->SetBankRMB(CurRMB - AmountRMB);
        pHuman->SetRMB(pHuman->GetRMB() + AmountRMB);

        MONEY_LOG_PARAM    MoneyLogParam;
        MoneyLogParam.CharGUID    =    pHuman->GetGUID();
        MoneyLogParam.OPType    =    MONEY_BANK_WITHDRAWRMB;
        MoneyLogParam.Count        =    Amount;
        MoneyLogParam.SceneID    =    pHuman->getScene()->SceneID();
        MoneyLogParam.XPos        =    pHuman->getWorldPos()->m_fX;
        MoneyLogParam.ZPos        =    pHuman->getWorldPos()->m_fZ;
        SaveMoneyLog(&MoneyLogParam);
    }
    else if( IsSave & CGBankMoney::UPDATA_RMB )
    {
        AmountRMB = CurRMB;
    }

    GCBankMoney Msg;
    Msg.SetSaveType(IsSave);
    Msg.SetAmount(Amount);
    Msg.SetAmountRMB(AmountRMB);
    pPlayer = pHuman->GetPlayer();
    pPlayer->SendPacket( &Msg ) ;
    g_pLog->FastSaveLog( LOG_FILE_1, "CGBankMoneyHandler: Issave=%d, Amount=%d, AmountRMB=%d", (INT)IsSave, Amount, AmountRMB ) ;
        return PACKET_EXE_CONTINUE ;

    __LEAVE_FUNCTION

        return PACKET_EXE_ERROR ;
}
예제 #2
0
uint CGExchangeApplyIHandler::Execute( CGExchangeApplyI* 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 ) ;

	ObjID_t		TargetID = pPacket->GetObjID();
	Obj_Human* pSourceHuman = pHuman;//交易发起者
	Obj_Human* pDestHuman = pScene->GetHumanManager()->GetHuman( TargetID );//交易对象

    if (pSourceHuman->IsInLoginProtectTime() || pDestHuman->IsInLoginProtectTime())
    {//在上线保护时间内,不可操作
        GCExchangeError Msg;
        Msg.SetID(EXCHANGE_MSG::ERR_IN_PROTECT_TIME);
        pGamePlayer->SendPacket(&Msg);
        g_pLog->FastSaveLog( LOG_FILE_1, "CGExchangeApplyIHandler: ID = %d or ID = %d ERR_IN_PROTECT_TIME", pSourceHuman->GetID(), pDestHuman->GetID()) ;

        return PACKET_EXE_CONTINUE;
    }

	//验证
	if( pDestHuman == NULL )
	{
		Assert(FALSE);
		return PACKET_EXE_CONTINUE;
	}
	INT iSettingData = pDestHuman->GetDB()->GetSetting(SETTING_TYPE_GAME)->m_SettingData;
	if(SETTINGFLAGISTRUE(iSettingData, GSF_REFUSE_TRADE))
	{
		GCExchangeError Msg;
		Msg.SetID(EXCHANGE_MSG::ERR_REFUSE_TRADE);
		pGamePlayer->SendPacket(&Msg);
		g_pLog->FastSaveLog( LOG_FILE_1, "CGExchangeApplyIHandler: ID = %d ERR_REFUSE_TRADE", pSourceHuman->GetID()) ;
		return PACKET_EXE_CONTINUE;
	}
	if(pSourceHuman->m_ExchangBox.m_Status >= ServerExchangeBox::EXCHANGE_SYNCH_DATA)
	{//发起者正在交易中
		GCExchangeError Msg;
		Msg.SetID(EXCHANGE_MSG::ERR_SELF_IN_EXCHANGE);
		pGamePlayer->SendPacket(&Msg);
		g_pLog->FastSaveLog( LOG_FILE_1, "CGExchangeApplyIHandler: ID = %d status = %d", pSourceHuman->GetID(), pSourceHuman->m_ExchangBox.m_Status) ;
		return PACKET_EXE_CONTINUE;
	}
	if(pDestHuman->m_ExchangBox.m_Status >= ServerExchangeBox::EXCHANGE_SYNCH_DATA)
	{//目标正在交易中
		GCExchangeError Msg;
		Msg.SetID(EXCHANGE_MSG::ERR_TARGET_IN_EXCHANGE);
		pGamePlayer->SendPacket(&Msg);
		g_pLog->FastSaveLog( LOG_FILE_1, "CGExchangeApplyIHandler: ID = %d status = %d", pDestHuman->GetID(),	pDestHuman->m_ExchangBox.m_Status ) ;
		return PACKET_EXE_CONTINUE;
	}
	//在使用战斗技能时不能交易
	//在使用生活技能时不能交易 
	//战斗中不能交易add by gh 2010/04/28
	if(pSourceHuman->GetCharacterLogic() == CHARACTER_LOGIC_USE_SKILL || pSourceHuman->GetCharacterLogic() == CHARACTER_LOGIC_USE_ABILITY)
	{
		GCExchangeError Msg;
		Msg.SetID(EXCHANGE_MSG::ERR_SELF_USE_SKILL);
		pGamePlayer->SendPacket(&Msg);
		g_pLog->FastSaveLog( LOG_FILE_1, "CGAskChangeSceneHandler::使用技能中") ;
		return PACKET_EXE_CONTINUE ;
	}
	if(pDestHuman->GetCharacterLogic() == CHARACTER_LOGIC_USE_SKILL || pDestHuman->GetCharacterLogic() == CHARACTER_LOGIC_USE_ABILITY)
	{
		GCExchangeError Msg;
		Msg.SetID(EXCHANGE_MSG::ERR_TARGET_USE_SKILL);
		pGamePlayer->SendPacket(&Msg);
		g_pLog->FastSaveLog( LOG_FILE_1, "CGAskChangeSceneHandler::目标使用技能中") ;
		return PACKET_EXE_CONTINUE ;
	}
	//行走中不能交易
	if(pSourceHuman->IsMoving())
	{
		GCExchangeError Msg;
		Msg.SetID(EXCHANGE_MSG::ERR_SELF_MOVE);
		pGamePlayer->SendPacket(&Msg);
		g_pLog->FastSaveLog( LOG_FILE_1, "CGAskChangeSceneHandler::移动中") ;
		return PACKET_EXE_CONTINUE ;
	}
	if(pDestHuman->IsMoving())
	{
		GCExchangeError Msg;
		Msg.SetID(EXCHANGE_MSG::ERR_TARGET_MOVE);
		pGamePlayer->SendPacket(&Msg);
		g_pLog->FastSaveLog( LOG_FILE_1, "CGAskChangeSceneHandler::目标移动中") ;
		return PACKET_EXE_CONTINUE ;
	}
    //在摆摊时不能交易
	if(pSourceHuman->m_StallBox.GetStallStatus() == ServerStallBox::STALL_OPEN)
	{
		GCExchangeError Msg;
		Msg.SetID(EXCHANGE_MSG::ERR_SELF_OPEN_STALL);
		pGamePlayer->SendPacket(&Msg);
		g_pLog->FastSaveLog( LOG_FILE_1, "CGAskChangeSceneHandler::摆摊中") ;
		return PACKET_EXE_CONTINUE ;
	}
	if(pDestHuman->m_StallBox.GetStallStatus() == ServerStallBox::STALL_OPEN)
	{
		GCExchangeError Msg;
		Msg.SetID(EXCHANGE_MSG::ERR_TARGET_OPEN_STALL);
		pGamePlayer->SendPacket(&Msg);
		g_pLog->FastSaveLog( LOG_FILE_1, "CGAskChangeSceneHandler::目标摆摊中") ;
		return PACKET_EXE_CONTINUE ;
	}
	// 死亡或者掉线不能交易
	if(pSourceHuman->GetHP() <= 0 || pSourceHuman->GetPlayer()->IsDisconnect())
	{//发起者死亡或者掉线
		GCExchangeError Msg;
		Msg.SetID(EXCHANGE_MSG::ERR_SELF_DEAD_OR_OFFLINE);
		pGamePlayer->SendPacket(&Msg);
		g_pLog->FastSaveLog( LOG_FILE_1, "CGExchangeApplyIHandler: ID = %d ERROR:DEAD OR OFFLINE", pSourceHuman->GetID()) ;
		return PACKET_EXE_CONTINUE;
	}
	if(pDestHuman->GetHP() <= 0 || pDestHuman->GetPlayer()->IsDisconnect()) // 验证过掉线
	{//目标死亡或者掉线
		GCExchangeError Msg;
		Msg.SetID(EXCHANGE_MSG::ERR_TARGET_DEAD_OR_OFFLINE);
		pGamePlayer->SendPacket(&Msg);
		g_pLog->FastSaveLog( LOG_FILE_1, "CGExchangeApplyIHandler: ID = %d ERROR:TARGET DEAD OR OFFLINE ", pDestHuman->GetID()) ;
		return PACKET_EXE_CONTINUE;
	}
	// end of add
    //交易的玩家之间的距离超过xx米不能交易
    FLOAT fDistance = MySqrt( pDestHuman->getWorldPos(), pSourceHuman->getWorldPos() );
    if (fDistance > EXCHANGE_MAX_DISTANCE)
    {
        GCExchangeError Msg;
        Msg.SetID(EXCHANGE_MSG::ERR_TOO_FAR);
        pHuman->GetPlayer()->SendPacket(&Msg);
        g_pLog->FastSaveLog( LOG_FILE_1, "<交易> [%s] 超过交易范围[%s]]",	pDestHuman->GetName(), pSourceHuman->GetName() ) ;
        return PACKET_EXE_CONTINUE;
    }

	//操作
	//发送消息向目标申请
	GCExchangeApplyI Msg;
	Msg.SetObjID(pSourceHuman->GetID());
	pDestHuman->GetPlayer()->SendPacket(&Msg);
	g_pLog->FastSaveLog( LOG_FILE_1, "CGExchangeApplyIHandler: SOURCEID = %d DESTID = %d", pSourceHuman->GetID(), pDestHuman->GetID() ) ;
	return PACKET_EXE_CONTINUE ;

	__LEAVE_FUNCTION

	return PACKET_EXE_ERROR ;
}
예제 #3
0
uint WGUpdateTitleHandler::Execute( WGUpdateTitle* pPacket, Player* pPlayer )
{
__ENTER_FUNCTION

	PlayerID_t PlayerID = pPacket->GetPlayerID();
	GamePlayer* pGamePlayer = g_pPlayerPool->GetPlayer(PlayerID);
	if( pGamePlayer==NULL )
	{
		Assert(FALSE);
		return PACKET_EXE_CONTINUE;
	}

	Obj_Human* pHuman = pGamePlayer->GetHuman();
	Assert( pHuman );

	Scene* pScene = pHuman->getScene();
	if( pScene==NULL ) return PACKET_EXE_CONTINUE ;

	if( pPlayer->IsServerPlayer() )
	{//服务器收到世界服务器发来的数据
		Assert( MyGetCurrentThreadID()==g_pServerManager->m_ThreadID );

		pScene->SendPacket( pPacket, PlayerID );
		return PACKET_EXE_NOTREMOVE;
	}
	else if( pPlayer->IsGamePlayer() )
	{//场景收到Cache里的消息
		Assert( MyGetCurrentThreadID()==pScene->m_ThreadID );

        //更新称号
        INT iType = pPacket->GetTitleType();

        switch (iType)
        {
        case _TITLE::GUOJIA_TITLE:
            {
                pHuman->SetCurCountryTitle(pPacket->GetTitleID());
                pHuman->UpdateTitlesToClient(GCCharAllTitles::UPDATE_CUR_GUOJIA_TITLE);

                if (pPacket->GetTitleSize() > 0)
                {
                    pHuman->SetCountryTitleName(pPacket->GetTitle(), pPacket->GetTitleSize());
                    pHuman->UpdateTitlesToClient(GCCharAllTitles::UPDATE_CUR_GUOJIA_TITLE);
                }
                break;
            }
        case _TITLE::BANGPAI_TITLE:
            {
                //这里只处理修改玩家帮会称号名字
                pHuman->SetCurGuildTitle(pPacket->GetTitleID());
                if (pPacket->GetTitleSize() > 0)
                {
                    pHuman->SetGuildTitleName(pPacket->GetTitle(), pPacket->GetTitleSize());
                    pHuman->UpdateTitlesToClient(GCCharAllTitles::UPDATE_BANGPAI_TITLE_NAME);
                    
                    //保存自定义称号
                    if (GUANZHI_TITLE_ID == pPacket->GetTitleID())
                    {
                        pHuman->GetDB()->SetOfficalTitleName(pPacket->GetTitle(), pPacket->GetTitleSize());
                    }
                }
                break;
            }
        case _TITLE::WANFA_TITLE:
            {
                pHuman->SetCurNormalTitle(pPacket->GetTitleID());
                pHuman->UpdateTitlesToClient(GCCharAllTitles::UPDATE_CUR_WANFA_TITLE);

                if (pPacket->GetTitleSize() > 0)
                {
                    pHuman->SetNormalTitleName(pPacket->GetTitle(), pPacket->GetTitleSize());
                    pHuman->UpdateTitlesToClient(GCCharAllTitles::UPDATE_CUR_WANFA_TITLE);
                }
                break;
            }
        }

		g_pLog->FastSaveLog( LOG_FILE_1, "WGUpdateTitleHandler Scuess! : GamePlayer (Guid=%d) ",
			pHuman->GetGUID());
	}
	else
	{
		Assert(FALSE);
	}

	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 ;
}
uint CGBBSApplyHandler::Execute( CGBBSApply* 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 ) ;
	ObjID_t ObjId	= pPacket->GetObjID();
	UINT Serial		= pPacket->GetSerial();

	Obj_Human* pTargetHuman = pScene->GetHumanManager()->GetHuman( ObjId );
	if( pTargetHuman == NULL )
	{
		g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: CGBBSApplyHandler::ObjID=%d, ObjId = %d"
			,pHuman->GetID(), ObjId) ;
		return PACKET_EXE_CONTINUE ;
	}
	
	if(pTargetHuman->m_StallBox.GetStallStatus() != ServerStallBox::STALL_OPEN)
	{
		GCStallError	Msg;
		Msg.SetID(STALL_MSG::ERR_CLOSE);
		pGamePlayer->SendPacket(&Msg);
		g_pLog->FastSaveLog( LOG_FILE_1, "ERROR: CGStallOpenHandler::ObjID=%d, ERR_CLOSE"
			,pHuman->GetID()) ;
		return PACKET_EXE_CONTINUE;
	}

	//从留言板中取出留言,并更新到客户端
	//摊主BBS
	ServerBBS*	pBBS			= pTargetHuman->m_StallBox.GetBBS();
	MessageEntry_t* pEntry		= NULL;
	GCBBSMessages::_MESSAGE_T	MessageList[MAX_BBS_MESSAGE_NUM];
	UINT k						= 0;
	GCBBSMessages	MsgBBS;

	
	if(Serial == pBBS->GetSerial())
	{//版本号相同,不用发新的了
		MsgBBS.SetObjID(pTargetHuman->GetID());
		MsgBBS.SetSerial(Serial);
	}
	else
	{//版本号不同发新的
		UINT	CurIndex = pBBS->GetFinalIndex();
		for(UINT i = 0; i<MAX_BBS_MESSAGE_NUM; i++)
		{
			pEntry = pBBS->GetMessageByIndex(CurIndex);
			if(pEntry)
			{
				MessageList[k].bHasReply		=	pEntry->bHasReply;
				MessageList[k].nID				=	pEntry->nID;
				MessageList[k].nHour			=	pEntry->nHour;
				MessageList[k].nMin				=	pEntry->nMin;
				MessageList[k].nMsgLength		=	pEntry->nMsgLength;
				MessageList[k].nReplyMsgLength	=	pEntry->nReplyMsgLength;
				MessageList[k].nReHour			=	pEntry->nReHour;
				MessageList[k].nReMin			=	pEntry->nReMin;

				memcpy(MessageList[k].AuthorName, pEntry->szAuthorName, MAX_BBS_MESSAGE_AUTHORLENGTH);
				memcpy(MessageList[k].szMessage, pEntry->szMessage, pEntry->nMsgLength);
				memcpy(MessageList[k].szReplyMessage, pEntry->szReplyMessage, pEntry->nReplyMsgLength);
				k++;
			}
			CurIndex++;
			if(CurIndex == MAX_BBS_MESSAGE_NUM)
				CurIndex = 0;
		}

		INT titleLength = 0;
		CHAR*	pszTitle = pBBS->GetBBSTitle(titleLength);

		MsgBBS.SetObjID(pTargetHuman->GetID());
		MsgBBS.SetSerial(pBBS->GetSerial());
		MsgBBS.SetTitleLength(titleLength);
		MsgBBS.SetTitle(pszTitle);
		MsgBBS.SetMessageNum(k);
		MsgBBS.SetMessageData(MessageList);
	}

	pGamePlayer->SendPacket(&MsgBBS);
	g_pLog->FastSaveLog( LOG_FILE_1, "CGStallOpenHandler::ObjID=%d"
		,pHuman->GetID()) ;
	return PACKET_EXE_CONTINUE ;

	__LEAVE_FUNCTION

		return PACKET_EXE_ERROR ;
}
예제 #6
0
uint WGNotifyUserHandler::Execute( WGNotifyUser* pPacket, Player* pPlayer )
{
	__ENTER_FUNCTION

	GUID_t sGuid = pPacket->GetGUID() ;
	Obj_Human* pHuman = (Obj_Human*)(g_pGUIDManager->Get(sGuid)) ;
	if( pHuman==NULL )
	{
		g_pLog->FastSaveLog( LOG_FILE_1, "WGNotifyUserHandler: pHuman==NULL GUID=%X",
			sGuid ) ;
		goto CHECK_RECYCLE_GUID;
	}

	GamePlayer* pGamePlayer = (GamePlayer*)(pHuman->GetPlayer()) ;
	if( pGamePlayer==NULL )
	{
		g_pLog->FastSaveLog( LOG_FILE_1, "WGNotifyUserHandler: pGamePlayer==NULL GUID=%X",
			sGuid ) ;
		goto CHECK_RECYCLE_GUID;
	}

	Scene* pScene = pHuman->getScene() ;
	if( pScene==NULL )
	{
		g_pLog->FastSaveLog( LOG_FILE_1, "WGNotifyUserHandler: pScene==NULL GUID=%X",
			sGuid ) ;
		goto CHECK_RECYCLE_GUID;
	}

	if( pPlayer->IsServerPlayer() )
	{//服务器收到世界服务器发来的数据
		Assert( MyGetCurrentThreadID()==g_pServerManager->m_ThreadID ) ;

		PlayerID_t PlayerID = pHuman->GetPlayerID() ;
		pScene->SendPacket( pPacket, PlayerID ) ;

		g_pLog->FastSaveLog( LOG_FILE_1, "WGNotifyUserHandler: ServerPlayer GUID=%X",
			sGuid ) ;

		return PACKET_EXE_NOTREMOVE ;
	}
	else if( pPlayer->IsGamePlayer() )
	{//场景收到Cache里的消息
		if( MyGetCurrentThreadID() != pScene->m_ThreadID ) return PACKET_EXE_CONTINUE ;

		if( pPacket->GetStatus() == WGNotifyUser::NUS_WORLD_KICK_REQUEST||
			pPacket->GetStatus() == WGNotifyUser::NUS_REMOVE)
		{
			GWNotifyUser* pGMsg = (GWNotifyUser*)(g_pPacketFactoryManager->CreatePacket(PACKET_GW_NOTIFYUSER)) ;
			pGMsg->SetGUID(pPacket->GetGUID());
			pGMsg->SetPlayerID(-1);
			pGMsg->SetStatus(GWNotifyUser::NUS_NEED_WORLD_KICK);
			g_pServerManager->SendPacket( pGMsg, INVALID_ID ) ;

			g_pLog->FastSaveLog( LOG_FILE_1, "WGNotifyUserHandler: GamePlayer GUID=%X WGNotifyUser::NUS_WORLD_KICK_REQUEST kick receive!",
				sGuid ) ;
			return PACKET_EXE_ERROR ;
		}
		else if( pPacket->GetStatus() == WGNotifyUser::NUS_CANNOTSAY )
		{//禁言
			//pHuman->CannotSay( pPacket->GetTime() ) ;

			//CHAR szNotify[MAX_CHAT_SIZE] ;
			//if( pPacket->GetTime() > 0 )
			//{
			//	// 10级(含)以下玩家禁言不在世界频道发公告....
			//	if ( pHuman->GetLevel() > 10 )
			//	{
			//		sprintf( szNotify, _TXT2((148),"#{_INFOUSR%s}玩家由于违反游戏规则,已经被禁言%d分钟"), 
			//			pHuman->GetName(), pPacket->GetTime()/60000 );
			//		GWChat* pChatPacket = (GWChat*)(g_pPacketFactoryManager->CreatePacket(PACKET_GW_CHAT)) ;
			//		pChatPacket->SetSourGUID( pGamePlayer->m_HumanGUID ) ;
			//		pChatPacket->SetChatType( CHAT_TYPE_SYSTEM ) ;
			//		pChatPacket->SetContexSize( (BYTE)(strlen(szNotify)) ) ;
			//		pChatPacket->SetContex( szNotify ) ;
			//		g_pServerManager->SendPacket( pChatPacket, INVALID_ID ) ;
			//		g_pLog->FastSaveLog( LOG_FILE_12, "ChatType=4 4 Contex=%s", szNotify ) ;
			//	}
		//	}
			//else
			//{
			//	sprintf( szNotify, _TXT2((149),"角色发言功能已经回复,请自觉遵守游戏规则,祝您游戏愉快!"));
			//	GCChat* pChatPacket = (GCChat*)(g_pPacketFactoryManager->CreatePacket(PACKET_GC_CHAT)) ;
			//	pChatPacket->SetChatType( CHAT_TYPE_SYSTEM ) ;
			//	pChatPacket->SetContexSize( (BYTE)(strlen(szNotify)) ) ;
			//	pChatPacket->SetContex( szNotify ) ;
			//	pChatPacket->SetSourNameSize( 0 ) ;
			//	pGamePlayer->SendPacket( pChatPacket ) ;
			//}
			//g_pLog->FastSaveLog( LOG_FILE_1, "WGNotifyUserHandler: GamePlayer GUID=%X WGNotifyUser::NUS_CANNOTSAY!",
			//	sGuid ) ;
	}
	}

	return PACKET_EXE_CONTINUE ;

CHECK_RECYCLE_GUID:
	//向World 发送一个踢人的回应包,仅能依靠GUIDManager
	GWNotifyUser* nGMsg = (GWNotifyUser*)(g_pPacketFactoryManager->CreatePacket(PACKET_GW_NOTIFYUSER)) ;
	nGMsg->SetGUID(pPacket->GetGUID());
	nGMsg->SetPlayerID(-1);

	if(g_pGUIDManager->Get(sGuid) == NULL/* && g_pGUIDManager->IsRecycle(sGuid) == FALSE*/)
	{
		nGMsg->SetStatus(GWNotifyUser::NUS_NOUSR);
		g_pLog->FastSaveLog( LOG_FILE_1, "WGNotifyUserHandler: ServerPlayer GUID=%X GWNotifyUser::NUS_NOUSR send!",
			sGuid );
	}
	else
	{
		nGMsg->SetStatus(GWNotifyUser::NUS_LOCK_BY_SHM);
		g_pLog->FastSaveLog( LOG_FILE_1, "WGNotifyUserHandler: ServerPlayer GUID=%X GWNotifyUser::NUS_LOCK_BY_SHM send!",
			sGuid );
	}
	g_pServerManager->SendPacket( nGMsg, INVALID_ID ) ;
	return PACKET_EXE_CONTINUE;
	__LEAVE_FUNCTION

	return PACKET_EXE_ERROR ;
}