Exemple #1
0
        public static void SaveHomeOwnerAvatarInHome(LogicClientAvatar logicClientAvatar, LogicClientHome logicClientHome)
        {
            CompressibleStringHelper.Uncompress(logicClientHome.GetCompressibleHomeJSON());
            LogicJSONObject jsonObject = LogicJSONParser.ParseObject(logicClientHome.GetCompressibleHomeJSON().Get());

            logicClientAvatar.SaveToDirect(jsonObject);
            logicClientHome.SetHomeJSON(LogicJSONParser.CreateJSONString(jsonObject, 512));
            CompressibleStringHelper.Compress(logicClientHome.GetCompressibleHomeJSON());
        }
        public static GameMode LoadMatchedAttackState(HomeSession session, GameMatchedAttackState state)
        {
            LogicClientHome   home                      = state.Home;
            LogicClientAvatar homeOwnerAvatar           = state.HomeOwnerAvatar;
            LogicClientAvatar attackerLogicClientAvatar = 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(attackerLogicClientAvatar);
            enemyHomeDataMessage.SetAttackSource(3);
            enemyHomeDataMessage.Encode();

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

            try
            {
                GameMode gameMode = new GameMode(session);

                gameMode.m_avatarChangeListener = new AvatarChangeListener(gameMode, attackerLogicClientAvatar);
                attackerLogicClientAvatar.SetChangeListener(gameMode.m_avatarChangeListener);

                gameMode.m_logicGameMode.LoadMatchedAttackState(home, homeOwnerAvatar, attackerLogicClientAvatar, currentTimestamp, secondsSinceLastSave, secondsSinceLastMaintenance);
                gameMode.m_gameDefenderLocked = state.GameDefenderLocked;
                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.loadMatchedAttackState: exception while the loading of attack state: " + exception);
            }

            return(null);
        }
        public static GameMode LoadHomeState(HomeSession session, GameHomeState state)
        {
            LogicClientHome   home            = state.Home;
            LogicClientAvatar homeOwnerAvatar = state.PlayerAvatar;

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

            OwnHomeDataMessage ownHomeDataMessage = new OwnHomeDataMessage();

            ownHomeDataMessage.SetCurrentTimestamp(currentTimestamp);
            ownHomeDataMessage.SetReengagementSeconds(reengagementSeconds);
            ownHomeDataMessage.SetSecondsSinceLastSave(secondsSinceLastSave);
            ownHomeDataMessage.SetSecondsSinceLastMaintenance(secondsSinceLastMaintenance);
            ownHomeDataMessage.SetLogicClientHome(home);
            ownHomeDataMessage.SetLogicClientAvatar(homeOwnerAvatar);
            ownHomeDataMessage.SetLayoutId(state.LayoutId);
            ownHomeDataMessage.SetMapId(state.MapId);
            ownHomeDataMessage.Encode();

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

            try
            {
                GameMode gameMode = new GameMode(session);

                gameMode.m_avatarChangeListener = new AvatarChangeListener(gameMode, homeOwnerAvatar);

                home.SetChangeListener(new HomeChangeListener(gameMode));
                homeOwnerAvatar.SetChangeListener(gameMode.m_avatarChangeListener);

                gameMode.m_logicGameMode.LoadHomeState(home, homeOwnerAvatar, secondsSinceLastSave, -1, currentTimestamp, secondsSinceLastMaintenance, reengagementSeconds);

                session.SendPiranhaMessage(ownHomeDataMessage, 1);

                for (int i = 0; i < state.ServerCommands.Size(); i++)
                {
                    gameMode.AddServerCommand(state.ServerCommands[i]);
                }

                return(gameMode);
            }
            catch (Exception exception)
            {
                Logging.Error("GameMode.loadHomeState: exception while the loading of attack state: " + exception);
            }

            return(null);
        }
        public static GameMode LoadVisitAttackState(HomeSession session, GameVisitState state)
        {
            LogicClientHome   home            = state.Home;
            LogicClientAvatar homeOwnerAvatar = state.HomeOwnerAvatar;
            LogicClientAvatar visitorAvatar   = state.PlayerAvatar;

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

            VisitedHomeDataMessage visitedHomeDataMessage = new VisitedHomeDataMessage();

            visitedHomeDataMessage.SetCurrentTimestamp(currentTimestamp);
            visitedHomeDataMessage.SetSecondsSinceLastSave(secondsSinceLastSave);
            visitedHomeDataMessage.SetLogicClientHome(home);
            visitedHomeDataMessage.SetOwnerLogicClientAvatar(homeOwnerAvatar);
            visitedHomeDataMessage.SetVisitorLogicClientAvatar(visitorAvatar);
            visitedHomeDataMessage.Encode();

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

            try
            {
                GameMode gameMode = new GameMode(session);

                gameMode.m_avatarChangeListener = new AvatarChangeListener(gameMode, visitorAvatar);
                visitorAvatar.SetChangeListener(gameMode.m_avatarChangeListener);

                gameMode.m_logicGameMode.LoadVisitState(home, homeOwnerAvatar, visitorAvatar, secondsSinceLastSave, currentTimestamp);

                session.SendPiranhaMessage(visitedHomeDataMessage, 1);

                return(gameMode);
            }
            catch (Exception exception)
            {
                Logging.Error("GameMode.loadVisitAttackState: exception while the loading of visit state: " + exception);
            }

            return(null);
        }
Exemple #5
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);
        }