예제 #1
0
void Player::OnTick()
{
	if (!IsAlive() || !mSession->IsConnected())
		return;
	if( LTickCount - mLastTick > TIME_ALLOW_WITHOUT_ACT ){
		mSession->DisconnectRequest( DR_TIMEOUT );
		return;
	}
	
	/// 랜덤으로 이벤트를 발생시켜보기 (예: 다른 모든 플레이어에게 버프 주기)
	if (rand() % 100 == 0) ///< 1% 확률
	{
		int buffId = mPlayerId * 100;
		int duration = (rand() % 3 + 2) * 1000;
	
		//GCE 예. (lock-order 귀찮고, 전역적으로 순서 보장 필요할 때)
		auto playerEvent = std::make_shared<AllPlayerBuffEvent>(buffId, duration);
		GCEDispatch(playerEvent, &AllPlayerBuffEvent::DoBuffToAllPlayers, mPlayerId);
	}


	//TODO: AllPlayerBuffDecay::CheckBuffTimeout를 GrandCentralExecuter를 통해 실행
	auto timeoutEvent = std::make_shared<AllPlayerBuffDecay>();
	GCEDispatch( timeoutEvent, &AllPlayerBuffDecay::CheckBuffTimeout );
	
	if (mHeartBeat > 0)
		DoSyncAfter(mHeartBeat, GetSharedFromThis<Player>(), &Player::OnTick);
		
}
예제 #2
0
파일: Player.cpp 프로젝트: 1n01raymond/GSP
void Player::OnTick()
{
	if (!IsAlive())
		return;

	
	/// 랜덤으로 이벤트를 발생시켜보기 (예: 다른 모든 플레이어에게 버프 주기)
	if (rand() % 100 == 0) ///< 1% 확률
	{
		int buffId = mPlayerId * 100;
		int duration = (rand() % 3 + 2) * 1000;
	
		//GCE 예. (lock-order 귀찮고, 전역적으로 순서 보장 필요할 때)
		auto playerEvent = std::make_shared<AllPlayerBuffEvent>(buffId, duration);
		GCEDispatch(playerEvent, &AllPlayerBuffEvent::DoBuffToAllPlayers, mPlayerId);
	}


	//TODO: AllPlayerBuffDecay::CheckBuffTimeout를 GrandCentralExecuter를 통해 실행

	
	
	if (mHeartBeat > 0)
		DoSyncAfter(mHeartBeat, GetSharedFromThis<Player>(), &Player::OnTick);
		
}