Ejemplo n.º 1
0
    // Read save data
    public void LoadQuest(IniData saveData)
    {
        game = Game.Get();

        // This happens anyway but we need it to be here before the following code is executed (also needed for loading saves)
        game.quest = this;

        // Get state
        int.TryParse(saveData.Get("Quest", "round"), out round);
        int.TryParse(saveData.Get("Quest", "morale"), out morale);
        bool.TryParse(saveData.Get("Quest", "heroesSelected"), out heroesSelected);
        bool horror;

        bool.TryParse(saveData.Get("Quest", "horror"), out horror);
        if (horror)
        {
            phase = MoMPhase.horror;
        }
        bool.TryParse(saveData.Get("Quest", "minorPeril"), out minorPeril);
        bool.TryParse(saveData.Get("Quest", "majorPeril"), out majorPeril);
        bool.TryParse(saveData.Get("Quest", "deadlyPeril"), out deadlyPeril);

        // Populate DelayedEvents
        delayedEvents = new List <QuestData.Event.DelayedEvent>();
        string[] saveDelayed = saveData.Get("Quest", "DelayedEvents").Split(" ".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries);
        foreach (string de in saveDelayed)
        {
            delayedEvents.Add(new QuestData.Event.DelayedEvent(de));
        }

        // Set static quest data
        string questPath = saveData.Get("Quest", "path");

        qd = new QuestData(questPath);

        // Clear all tokens
        game.tokenBoard.Clear();
        // Clean up everything marked as 'board'
        foreach (GameObject go in GameObject.FindGameObjectsWithTag("board"))
        {
            Object.Destroy(go);
        }

        // Repopulate items on the baord
        boardItems = new Dictionary <string, BoardComponent>();
        Dictionary <string, string> saveBoard = saveData.Get("Board");

        foreach (KeyValuePair <string, string> kv in saveBoard)
        {
            if (kv.Key.IndexOf("Door") == 0)
            {
                boardItems.Add(kv.Key, new Door(qd.components[kv.Key] as QuestData.Door, game));
            }
            if (kv.Key.IndexOf("Token") == 0)
            {
                boardItems.Add(kv.Key, new Token(qd.components[kv.Key] as QuestData.Token, game));
            }
            if (kv.Key.IndexOf("Tile") == 0)
            {
                boardItems.Add(kv.Key, new Tile(qd.components[kv.Key] as QuestData.Tile, game));
            }
        }

        // Set flags
        flags = new HashSet <string>();
        Dictionary <string, string> saveFlags = saveData.Get("Flags");

        foreach (KeyValuePair <string, string> kv in saveFlags)
        {
            flags.Add(kv.Key);
        }

        // Restart event EventManager
        eManager = new EventManager();

        // Clean undo stack (we don't save undo stack)
        // When performing undo this is replaced later
        undo = new Stack <string>();

        // Fetch hero state
        heroes   = new List <Hero>();
        monsters = new List <Monster>();
        foreach (KeyValuePair <string, Dictionary <string, string> > kv in saveData.data)
        {
            if (kv.Key.IndexOf("Hero") == 0 && kv.Key.IndexOf("HeroSelection") != 0)
            {
                heroes.Add(new Hero(kv.Value));
            }
        }

        // Monsters must be after heros because some activations refer to heros
        foreach (KeyValuePair <string, Dictionary <string, string> > kv in saveData.data)
        {
            if (kv.Key.IndexOf("Monster") == 0)
            {
                monsters.Add(new Monster(kv.Value));
            }
        }

        // Restore hero selections
        heroSelection = new Dictionary <string, List <Hero> >();
        Dictionary <string, string> saveSelection = saveData.Get("HeroSelection");

        foreach (KeyValuePair <string, string> kv in saveSelection)
        {
            // List of selected heroes
            string[]    selectHeroes = kv.Value.Split(" ".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries);
            List <Hero> heroList     = new List <Hero>();

            foreach (string s in selectHeroes)
            {
                foreach (Hero h in heroes)
                {
                    // Match hero id
                    int id;
                    int.TryParse(s, out id);
                    if (id == h.id)
                    {
                        heroList.Add(h);
                    }
                }
            }
            // Add this selection
            heroSelection.Add(kv.Key, heroList);
        }
        // Update the screen
        game.monsterCanvas.UpdateList();
        game.heroCanvas.UpdateStatus();
    }
Ejemplo n.º 2
0
    // Read save data
    public void LoadQuest(IniData saveData)
    {
        game = Game.Get();

        // This happens anyway but we need it to be here before the following code is executed (also needed for loading saves)
        game.quest = this;

        // Get state
        int.TryParse(saveData.Get("Quest", "round"), out round);
        int.TryParse(saveData.Get("Quest", "morale"), out morale);
        bool.TryParse(saveData.Get("Quest", "heroesSelected"), out heroesSelected);
        bool horror;

        bool.TryParse(saveData.Get("Quest", "horror"), out horror);
        if (horror)
        {
            phase = MoMPhase.horror;
        }

        // Set camera
        float camx, camy, camz;

        float.TryParse(saveData.Get("Quest", "camx"), out camx);
        float.TryParse(saveData.Get("Quest", "camy"), out camy);
        float.TryParse(saveData.Get("Quest", "camz"), out camz);
        game.cc.gameObject.transform.position = new Vector3(camx, camy, camz);

        game.cc.minLimit = false;
        if (saveData.Get("Quest", "camxmin").Length > 0)
        {
            game.cc.minLimit = true;
            int.TryParse(saveData.Get("Quest", "camxmin"), out game.cc.minPanX);
            int.TryParse(saveData.Get("Quest", "camymin"), out game.cc.minPanY);
        }

        game.cc.maxLimit = false;
        if (saveData.Get("Quest", "camxmax").Length > 0)
        {
            game.cc.maxLimit = true;
            int.TryParse(saveData.Get("Quest", "camxmax"), out game.cc.maxPanX);
            int.TryParse(saveData.Get("Quest", "camymax"), out game.cc.maxPanY);
        }

        // Populate DelayedEvents (depreciated)
        delayedEvents = new List <QuestData.Event.DelayedEvent>();
        string[] saveDelayed = saveData.Get("Quest", "DelayedEvents").Split(" ".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries);
        foreach (string de in saveDelayed)
        {
            delayedEvents.Add(new QuestData.Event.DelayedEvent(de));
        }

        // Set static quest data
        string questPath = saveData.Get("Quest", "path");

        qd = new QuestData(questPath);

        monsterSelect = saveData.Get("SelectMonster");
        if (monsterSelect == null)
        {
            // Support old saves
            monsterSelect = new Dictionary <string, string>();
            GenerateMonsterSelection();
        }

        // Clear all tokens
        game.tokenBoard.Clear();
        // Clean up everything marked as 'board'
        foreach (GameObject go in GameObject.FindGameObjectsWithTag("board"))
        {
            Object.Destroy(go);
        }

        // Repopulate items on the baord
        boardItems = new Dictionary <string, BoardComponent>();
        Dictionary <string, string> saveBoard = saveData.Get("Board");

        foreach (KeyValuePair <string, string> kv in saveBoard)
        {
            if (kv.Key.IndexOf("Door") == 0)
            {
                boardItems.Add(kv.Key, new Door(qd.components[kv.Key] as QuestData.Door, game));
            }
            if (kv.Key.IndexOf("Token") == 0)
            {
                boardItems.Add(kv.Key, new Token(qd.components[kv.Key] as QuestData.Token, game));
            }
            if (kv.Key.IndexOf("Tile") == 0)
            {
                boardItems.Add(kv.Key, new Tile(qd.components[kv.Key] as QuestData.Tile, game));
            }
        }

        Dictionary <string, string> saveVars = saveData.Get("Vars");

        vars = new VarManager(saveVars);

        // Set items
        items = new HashSet <string>();
        Dictionary <string, string> saveItems = saveData.Get("Items");

        foreach (KeyValuePair <string, string> kv in saveItems)
        {
            items.Add(kv.Key);
        }

        // Restart event EventManager
        eManager = new EventManager();

        // Clean undo stack (we don't save undo stack)
        // When performing undo this is replaced later
        undo = new Stack <string>();

        // Fetch hero state
        heroes   = new List <Hero>();
        monsters = new List <Monster>();
        foreach (KeyValuePair <string, Dictionary <string, string> > kv in saveData.data)
        {
            if (kv.Key.IndexOf("Hero") == 0 && kv.Key.IndexOf("HeroSelection") != 0)
            {
                heroes.Add(new Hero(kv.Value));
            }
        }

        // Monsters must be after heros because some activations refer to heros
        foreach (KeyValuePair <string, Dictionary <string, string> > kv in saveData.data)
        {
            if (kv.Key.IndexOf("Monster") == 0)
            {
                monsters.Add(new Monster(kv.Value));
            }
        }

        // Restore hero selections
        heroSelection = new Dictionary <string, List <Hero> >();
        Dictionary <string, string> saveSelection = saveData.Get("HeroSelection");

        foreach (KeyValuePair <string, string> kv in saveSelection)
        {
            // List of selected heroes
            string[]    selectHeroes = kv.Value.Split(" ".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries);
            List <Hero> heroList     = new List <Hero>();

            foreach (string s in selectHeroes)
            {
                foreach (Hero h in heroes)
                {
                    // Match hero id
                    int id;
                    int.TryParse(s, out id);
                    if (id == h.id)
                    {
                        heroList.Add(h);
                    }
                }
            }
            // Add this selection
            heroSelection.Add(kv.Key, heroList);
        }

        puzzle = new Dictionary <string, Puzzle>();
        foreach (KeyValuePair <string, Dictionary <string, string> > kv in saveData.data)
        {
            if (kv.Key.IndexOf("PuzzleSlide") == 0)
            {
                puzzle.Add(kv.Key.Substring("PuzzleSlide".Length, kv.Key.Length - "PuzzleSlide".Length), new PuzzleSlide(kv.Value));
            }
            if (kv.Key.IndexOf("PuzzleCode") == 0)
            {
                puzzle.Add(kv.Key.Substring("PuzzleCode".Length, kv.Key.Length - "PuzzleCode".Length), new PuzzleCode(kv.Value));
            }
            if (kv.Key.IndexOf("PuzzleImage") == 0)
            {
                puzzle.Add(kv.Key.Substring("PuzzleImage".Length, kv.Key.Length - "PuzzleImage".Length), new PuzzleImage(kv.Value));
            }
        }
        // Restore event quotas
        eventQuota = new Dictionary <string, int>();
        foreach (KeyValuePair <string, string> kv in saveData.Get("EventQuota"))
        {
            int value;
            int.TryParse(kv.Value, out value);
            eventQuota.Add(kv.Key, value);
        }

        // Restore event log
        log = new List <LogEntry>();
        foreach (KeyValuePair <string, string> kv in saveData.Get("Log"))
        {
            log.Add(new LogEntry(kv.Key, kv.Value));
        }

        // Update the screen
        game.monsterCanvas.UpdateList();
        game.heroCanvas.UpdateStatus();
    }