/// <summary>
        /// Reset la classe
        /// </summary>
        public static void ResetCharacters()
        {
            if (_Players != null)
            {
                foreach (VO_Player charSprite in _Players.Values)
                {
                    charSprite.Dispose();
                }
                _Players = null;

                CurrentPlayerCharacter = null;
            }
        }
        /// <summary>
        /// Crée un perso
        /// </summary>
        /// <param name="Character"></param>
        public static void CreatePlayer(Guid player)
        {
            if (_Players == null)
            {
                _Players = new Dictionary <Guid, VO_Player>();
            }

            try
            {
                VO_Player characterSprite = new VO_Player(GameCore.Instance.GetPlayableCharacterById(player));
                _Players.Add(player, characterSprite);
            }
            catch (Exception e)
            {
                LogTools.WriteInfo(string.Format(Logs.MANAGER_CHARACTER_NOT_LOADED, player));
                LogTools.WriteDebug(e.Message);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Charge une sauvegarde
        /// </summary>
        /// <param name="path"></param>
        public static bool LoadGameState(string path)
        {
            if (!File.Exists(GameCore.Instance.Game.Project.RootPath + "\\" + path))
            {
                return(false);
            }

            #region Récupération du GameState
            //Récupération
            VO_GameState tempGameState = (VO_GameState)AppTools.LoadObjectFromFile(GameCore.Instance.Game.Project.RootPath + "\\" + path);

            //GameCore.Instance.Game.Project.RootPath = Path.GetDirectoryName(path) + "\\";
            GameCore.Instance.Game.Project.ProjectFileName = Path.GetFileNameWithoutExtension(path);
            #endregion

            //Nouveau du jeu
            NewGame();

            //Reset des managers
            ScriptManager.ResetScriptManager();
            PlayableCharactersManager.ResetCharacters();

            //Chargement
            //Boutons
            foreach (VO_Trigger trigger in State.Triggers)
            {
                VO_Trigger updateTrigger = tempGameState.Triggers.Find(p => p.Id == trigger.Id);
                trigger.Value = updateTrigger.Value;
            }

            //Variables
            foreach (VO_Variable variable in State.Variables)
            {
                VO_Variable updateVariable = tempGameState.Variables.Find(p => p.Id == variable.Id);
                variable.Value = updateVariable.Value;
            }

            //Perso courant
            State.CurrentCharacter = tempGameState.CurrentCharacter;

            //Persos
            foreach (VO_GameStateCharacter characterGame in tempGameState.Players)
            {
                PlayableCharactersManager.CreatePlayer(characterGame.CharacterId);
                VO_Player charSprite = PlayableCharactersManager.GetPlayer(characterGame.Id);
                charSprite.Actions.Clear();
                foreach (Guid action in characterGame.Actions)
                {
                    charSprite.Actions.Add(action);
                }
                foreach (Guid item in characterGame.Items)
                {
                    charSprite.AddItem(item);
                }
                charSprite.CurrentStage = characterGame.Coords.Map;
                charSprite.CharacterSprite.CurrentDirection = characterGame.CurrentDirection;
                charSprite.CharacterSprite.Id                   = characterGame.Id;
                charSprite.CharacterSprite.CharacterId          = characterGame.CharacterId;
                charSprite.CharacterSprite.CurrentExecutingPage = characterGame.CurrentExecutingPage;
                charSprite.CharacterSprite.IsTalking            = characterGame.IsTalking;
                charSprite.CharacterSprite.CurrentPath          = characterGame.CurrentPath;
                charSprite.CharacterSprite.SetCurrentAnimation(charSprite.CharacterSprite.CurrentCharacterAnimationType, characterGame.CurrentAnim);
            }
            PlayableCharactersManager.CurrentPlayerCharacter = PlayableCharactersManager.GetPlayer(State.CurrentCharacter);
            State.Players         = tempGameState.Players;
            State.Stages          = tempGameState.Stages;
            State.CurrentStagePNJ = tempGameState.CurrentStagePNJ;

            //RunningScript
            foreach (VO_GameStateRunningScript runningScriptState in tempGameState.RunningScripts)
            {
                VO_RunningScript runningScript = new VO_RunningScript();
                runningScript.Id          = runningScriptState.Script;
                runningScript.ObjectState = runningScriptState.ObjectState;
                runningScript.WaitFrames  = runningScriptState.WaitFrames;
                runningScript.Lines       = FindScript(runningScriptState.Script).Lines;
                runningScript.CurrentLine = FindLine(runningScript.Lines, runningScriptState.CurrentLine);
                if (runningScript.Lines != null)
                {
                    ScriptManager.AddParallelScript(runningScript);
                }
            }
            return(true);
        }