// -------------------------------------------------------------------------------
        // OnClicked
        // -------------------------------------------------------------------------------
        protected void OnClicked(Savegame state)
        {
            Action <Savegame> handler = Clicked;

            if (handler != null)
            {
                handler(state);
            }
        }
Beispiel #2
0
        // ============================ SAVE & LOAD FUNCTIONS ============================

        // -------------------------------------------------------------------------------
        // SaveFile
        // -------------------------------------------------------------------------------
        public void SaveFile(int index, Savegame state)
        {
            byte[] key        = Convert.FromBase64String(cryptoKey);
            string targetFile = string.Format(filePathBase, index);

            using (FileStream file = new FileStream(targetFile, FileMode.Create, FileAccess.Write))
                using (CryptoStream cryptoStream = CreateEncryptionStream(key, file)) {
                    WriteObjectToStream(cryptoStream, state);
                }

            /*
             * in case encryption fails, you can use the unencrypted savegame code here:
             *
             * state.Index = index;
             * using (FileStream fs = new FileStream(targetFile, FileMode.Create, FileAccess.Write)) {
             *  BinaryFormatter bf = new BinaryFormatter();
             *  bf.Serialize(fs, state);
             *  fs.Close();
             * }
             */
        }
Beispiel #3
0
        // ==================== CREATE / RESTORE SAVESTATE FUNCTIONS =====================

        // -------------------------------------------------------------------------------
        // Save
        // -------------------------------------------------------------------------------
        public void SaveState(int index)
        {
            Savegame state = new Savegame();

            state.SaveDate  = DateTime.Now;
            state.StartDate = StartDate;
            state.Index     = index;

            // -------------------------------------------------------------------------------
            // Save: Current Location
            // -------------------------------------------------------------------------------

            state.mapName         = Finder.map.getCurrentMapName;
            state.locationType    = Finder.map.locationType;
            state.facingDirection = Finder.navi.facingDirection;
            state.X = Finder.party.transform.position.x;
            state.Y = Finder.party.transform.position.z;                                                                        // z = Y

            // -------------------------------------------------------------------------------
            // Save: Last visited Town
            // -------------------------------------------------------------------------------
            if (Finder.party.lastTown != null)
            {
                state.lastTown = Finder.party.lastTown.name;
            }

            // -------------------------------------------------------------------------------
            // Save: Characters in Party
            // -------------------------------------------------------------------------------
            state.characters.Clear();

            foreach (CharacterBase character in Finder.party.characters)
            {
                state.characters.Add(character.SaveToSavegame());
            }

            // -------------------------------------------------------------------------------
            // Save: Party Equipment
            // -------------------------------------------------------------------------------
            state.equipment = Finder.party.equipment;

            // -------------------------------------------------------------------------------
            // Save: Party Inventory
            // -------------------------------------------------------------------------------
            state.inventory = Finder.party.inventory;

            // -------------------------------------------------------------------------------
            // Save: Interacted & Deactivated Objects
            // -------------------------------------------------------------------------------
            state.InteractedObjects  = Finder.party.InteractedObjects;
            state.DeactivatedObjects = Finder.party.DeactivatedObjects;

            // -------------------------------------------------------------------------------
            // Save: Exploration Data
            // -------------------------------------------------------------------------------
            state.MapExplorationInfo  = Finder.party.MapExplorationInfo;
            state.TownExplorationInfo = Finder.party.TownExplorationInfo;

            // -------------------------------------------------------------------------------
            // Save: Currencies
            // -------------------------------------------------------------------------------
            state.gold = Finder.party.currencies.gold;

            SaveFile(index, state);
            LastLoadedIndex = index;
        }
Beispiel #4
0
        // -------------------------------------------------------------------------------
        // LoadState
        // -------------------------------------------------------------------------------
        public void LoadState(int index)
        {
            Savegame state = Load(index);

            if (state != null)
            {
                // -------------------------------------------------------------------------------
                // Restore: Currencies
                // -------------------------------------------------------------------------------
                Finder.party.currencies.gold = state.gold;

                // -------------------------------------------------------------------------------
                // Restore: Interacted & Deactivated Objects
                // -------------------------------------------------------------------------------
                Finder.party.InteractedObjects  = state.InteractedObjects;
                Finder.party.DeactivatedObjects = state.DeactivatedObjects;

                // -------------------------------------------------------------------------------
                // Restore: Exploration Data
                // -------------------------------------------------------------------------------
                Finder.party.MapExplorationInfo  = state.MapExplorationInfo;
                Finder.party.TownExplorationInfo = state.TownExplorationInfo;

                // -------------------------------------------------------------------------------
                // Restore: Party Equipment
                // -------------------------------------------------------------------------------
                Finder.party.equipment = state.equipment;
                Finder.party.equipment.LoadTemplates();

                // -------------------------------------------------------------------------------
                // Restore: Party Inventory
                // -------------------------------------------------------------------------------
                Finder.party.inventory = state.inventory;
                Finder.party.inventory.LoadTemplates();

                // -------------------------------------------------------------------------------
                // Restore: Characters in Party
                // -------------------------------------------------------------------------------
                Finder.party.characters.Clear();
                foreach (SavegameCharacter character in state.characters)
                {
                    CharacterHero hero = new CharacterHero();
                    hero.LoadFromSavegame(character);
                    Finder.party.characters.Add(hero);
                }

                // -------------------------------------------------------------------------------
                // Restore: Last visited Town
                // -------------------------------------------------------------------------------
                if (!string.IsNullOrEmpty(state.lastTown))
                {
                    Finder.party.lastTown = DictionaryTown.Get(state.lastTown);
                }

                // -------------------------------------------------------------------------------
                // Restore: Current Location
                // -------------------------------------------------------------------------------
                Location restoredLocation = new Location
                {
                    locationType    = state.locationType,
                    name            = state.mapName,
                    facingDirection = state.facingDirection,
                    X = state.X,
                    Y = state.Y
                };

                Finder.battle.Reset();
                Finder.ui.DeactivateAll();
                Finder.audio.StopBGM();
                Finder.audio.StopSFX();

                SaveDate        = state.SaveDate;
                StartDate       = state.StartDate;
                LastLoadedIndex = index;

                Finder.map.TeleportPlayer(restoredLocation);

                GameInProgress = true;
            }
        }