Exemplo n.º 1
0
        public static GameMode LoadChallengeAttackState(BattleSession session, GameChallengeAttackState state)
        {
            LogicClientHome   home            = state.Home;
            LogicClientAvatar homeOwnerAvatar = GameUtil.LoadHomeOwnerAvatarFromHome(home);
            LogicClientAvatar playerAvatar    = state.PlayerAvatar;

            int currentTimestamp            = TimeUtil.GetTimestamp();
            int secondsSinceLastSave        = state.SaveTime != -1 ? currentTimestamp - state.SaveTime : 0;
            int secondsSinceLastMaintenance = 0;

            EnemyHomeDataMessage enemyHomeDataMessage = new EnemyHomeDataMessage();

            enemyHomeDataMessage.SetCurrentTimestamp(currentTimestamp);
            enemyHomeDataMessage.SetSecondsSinceLastSave(secondsSinceLastSave);
            enemyHomeDataMessage.SetSecondsSinceLastMaintenance(secondsSinceLastMaintenance);
            enemyHomeDataMessage.SetLogicClientHome(home);
            enemyHomeDataMessage.SetLogicClientAvatar(homeOwnerAvatar);
            enemyHomeDataMessage.SetAttackerLogicClientAvatar(playerAvatar);
            enemyHomeDataMessage.SetAttackSource(5);
            enemyHomeDataMessage.SetMapId(state.MapId);
            enemyHomeDataMessage.Encode();

            CompressibleStringHelper.Uncompress(home.GetCompressibleHomeJSON());
            CompressibleStringHelper.Uncompress(home.GetCompressibleCalendarJSON());
            CompressibleStringHelper.Uncompress(home.GetCompressibleGlobalJSON());

            try
            {
                GameMode gameMode = new GameMode(session);

                gameMode.m_logicGameMode.LoadDirectAttackState(home, homeOwnerAvatar, playerAvatar, secondsSinceLastSave, state.MapId == 1, false, currentTimestamp);
                gameMode.m_challengeAllianceId = state.AllianceId;
                gameMode.m_challengeStreamId   = state.StreamId;
                gameMode.m_liveReplayId        = state.LiveReplayId;

                ZLibHelper.CompressInZLibFormat(LogicStringUtil.GetBytes(LogicJSONParser.CreateJSONString(gameMode.m_logicGameMode.GetReplay().GetJson())), out byte[] streamJSON);
                ServerMessageManager.SendMessage(new InitializeLiveReplayMessage
                {
                    AccountId  = gameMode.m_liveReplayId,
                    StreamData = streamJSON
                }, 9);

                session.SendPiranhaMessage(enemyHomeDataMessage, 1);
                return(gameMode);
            }
            catch (Exception exception)
            {
                Logging.Error("GameMode.loadChallengeAttackState: exception while the loading of attack state: " + exception);
            }

            return(null);
        }
Exemplo n.º 2
0
        public static GameMode LoadFakeAttackState(BattleSession session, GameFakeAttackState state)
        {
            LogicClientHome   home            = state.Home;
            LogicClientAvatar homeOwnerAvatar = state.HomeOwnerAvatar;
            LogicClientAvatar playerAvatar    = state.PlayerAvatar;

            int currentTimestamp            = TimeUtil.GetTimestamp();
            int secondsSinceLastSave        = state.SaveTime != -1 ? currentTimestamp - state.SaveTime : 0;
            int secondsSinceLastMaintenance = state.MaintenanceTime != -1 ? currentTimestamp - state.MaintenanceTime : 0;

            EnemyHomeDataMessage enemyHomeDataMessage = new EnemyHomeDataMessage();

            enemyHomeDataMessage.SetCurrentTimestamp(currentTimestamp);
            enemyHomeDataMessage.SetSecondsSinceLastSave(secondsSinceLastSave);
            enemyHomeDataMessage.SetSecondsSinceLastMaintenance(secondsSinceLastMaintenance);
            enemyHomeDataMessage.SetLogicClientHome(home);
            enemyHomeDataMessage.SetLogicClientAvatar(homeOwnerAvatar);
            enemyHomeDataMessage.SetAttackerLogicClientAvatar(playerAvatar);
            enemyHomeDataMessage.SetAttackSource(1);
            enemyHomeDataMessage.Encode();

            CompressibleStringHelper.Uncompress(home.GetCompressibleHomeJSON());
            CompressibleStringHelper.Uncompress(home.GetCompressibleCalendarJSON());
            CompressibleStringHelper.Uncompress(home.GetCompressibleGlobalJSON());

            try
            {
                GameMode gameMode = new GameMode(session);
                gameMode.m_logicGameMode.LoadDirectAttackState(home, homeOwnerAvatar, playerAvatar, secondsSinceLastSave, false, false, currentTimestamp);
                session.SendPiranhaMessage(enemyHomeDataMessage, 1);
                return(gameMode);
            }
            catch (Exception exception)
            {
                Logging.Error("GameMode.loadFakeAttackState: exception while the loading of attack state: " + exception);
            }

            return(null);
        }