private static void OnGameStartFakeAttackMessageReceived(GameStartFakeAttackMessage message) { if (GameSessionManager.TryGet(message.SessionId, out GameSession session)) { if (message.AccountId != null) { ServerRequestManager.Create(new GameAvatarRequestMessage { AccountId = message.AccountId }, ServerManager.GetDocumentSocket(9, message.AccountId)).OnComplete = args => { if (session.IsDestructed()) { return; } if (args.ErrorCode == ServerRequestError.Success && args.ResponseMessage.Success) { GameState currentGameState = session.GameState; if (currentGameState != null && currentGameState.GetGameStateType() == GameStateType.HOME) { GameAvatarResponseMessage gameAvatarResponseMessage = (GameAvatarResponseMessage)args.ResponseMessage; GameDocument document = gameAvatarResponseMessage.Document; AvailableServerCommandMessage availableServerCommandMessage = new AvailableServerCommandMessage(); availableServerCommandMessage.SetServerCommand(new LogicMatchmakingCommand()); session.SendPiranhaMessage(availableServerCommandMessage, 1); session.FakeAttackState = new GameFakeAttackState { Home = document.LogicClientHome, HomeOwnerAvatar = document.LogicClientAvatar, PlayerAvatar = session.GameAvatar.LogicClientAvatar, SaveTime = document.SaveTime, MaintenanceTime = document.MaintenanceTime }; } } else { AttackHomeFailedMessage attackHomeFailedMessage = new AttackHomeFailedMessage(); attackHomeFailedMessage.SetReason(AttackHomeFailedMessage.Reason.GENERIC); session.SendPiranhaMessage(attackHomeFailedMessage, 1); } }; } else { GameState currentGameState = session.GameState; if (currentGameState != null && currentGameState.GetGameStateType() == GameStateType.HOME) { AvailableServerCommandMessage availableServerCommandMessage = new AvailableServerCommandMessage(); availableServerCommandMessage.SetServerCommand(new LogicMatchmakingCommand()); session.SendPiranhaMessage(availableServerCommandMessage, 1); session.FakeAttackState = new GameFakeAttackState { Home = GameBaseGenerator.GenerateBase((LogicGameObjectData)message.ArgData), HomeOwnerAvatar = GameBaseGenerator.HomeOwnerAvatar, PlayerAvatar = session.GameAvatar.LogicClientAvatar, SaveTime = TimeUtil.GetTimestamp(), MaintenanceTime = -1 }; } } } }
private static void OnChangeGameStateMessageReceived(ChangeGameStateMessage message) { if (GameSessionManager.TryGet(message.SessionId, out GameSession session)) { GameAvatar document = session.GameAvatar; switch (message.StateType) { case GameStateType.HOME: session.DestructGameState(); session.LoadGameState(new GameHomeState { PlayerAvatar = document.LogicClientAvatar, Home = document.LogicClientHome, SaveTime = document.SaveTime, MaintenanceTime = document.MaintenanceTime, ServerCommands = document.ServerCommands, LayoutId = message.LayoutId, MapId = message.MapId }); break; case GameStateType.NPC_ATTACK: session.DestructGameState(); session.LoadGameState(new GameNpcAttackState { PlayerAvatar = document.LogicClientAvatar, Home = GameResourceManager.NpcHomes[message.NpcData.GetInstanceID()], NpcAvatar = LogicNpcAvatar.GetNpcAvatar(message.NpcData), SaveTime = -1 }); break; case GameStateType.NPC_DUEL: session.DestructGameState(); session.LoadGameState(new GameNpcDuelState { PlayerAvatar = document.LogicClientAvatar, Home = GameResourceManager.NpcHomes[message.NpcData.GetInstanceID()], NpcAvatar = LogicNpcAvatar.GetNpcAvatar(message.NpcData), SaveTime = -1 }); break; case GameStateType.VISIT: ServerRequestManager.Create(new GameAvatarRequestMessage { AccountId = message.HomeId }, ServerManager.GetDocumentSocket(9, message.HomeId), 5).OnComplete = args => { if (!session.IsDestructed()) { if (args.ErrorCode == ServerRequestError.Success && args.ResponseMessage.Success) { GameAvatarResponseMessage gameAvatarResponseMessage = (GameAvatarResponseMessage)args.ResponseMessage; session.DestructGameState(); session.LoadGameState(new GameVisitState { Home = gameAvatarResponseMessage.Document.LogicClientHome, HomeOwnerAvatar = gameAvatarResponseMessage.Document.LogicClientAvatar, SaveTime = gameAvatarResponseMessage.Document.SaveTime, PlayerAvatar = session.GameAvatar.LogicClientAvatar }); } else { session.SendPiranhaMessage(new VisitFailedMessage(), 1); } } }; break; case GameStateType.CHALLENGE_ATTACK: session.DestructGameState(); LogicLong liveReplayId = LiveReplayManager.Create(session, message.ChallengeAllianceId, message.ChallengeStreamId); LogicClientHome logicClientHome = new LogicClientHome(); logicClientHome.SetHomeId(message.ChallengeHomeId); logicClientHome.GetCompressibleHomeJSON().Set(message.ChallengeHomeJSON); session.LoadGameState(new GameChallengeAttackState { Home = logicClientHome, PlayerAvatar = document.LogicClientAvatar, SaveTime = -1, LiveReplayId = liveReplayId, AllianceId = message.ChallengeAllianceId, StreamId = message.ChallengeStreamId, MapId = message.ChallengeMapId }); ServerMessageManager.SendMessage(new AllianceChallengeLiveReplayIdMessage { AccountId = message.ChallengeStreamId, LiveReplayId = liveReplayId }, 11); break; } } }