Exemplo n.º 1
0
    public static void NewData()
    {
        var newData = new Rm_RPGHandler();

        PlayerPrefs.SetString(PlayerSaveLoadManager.LastSavedGameKey, "");
        PlayerPrefs.SetString(PlayerSaveLoadManager.LastSavePPrefIDKey, "");
        AddDummyData(newData);
        Rm_RPGHandler.Instance = newData;
        SaveGameData();
    }
Exemplo n.º 2
0
        //todo: this doesn't load right for some reason...
        public void LoadGameData()
        {
            //Debug.Log("Loading game data from ingame");
            var foundData = false;
            var textAsset = (Resources.Load("GameData/main.GAMEDATA") as TextAsset);

            if (textAsset != null)
            {
                var jsonFromEncode = textAsset.text;
                //Debug.Log(jsonFromEncode);
                if (!string.IsNullOrEmpty(jsonFromEncode))
                {
                    foundData = true;
                    if (EncryptFiles)
                    {
                        jsonFromEncode = new Xor().Decrypt(jsonFromEncode, EncryptKey);
                    }

                    Rm_RPGHandler loadedGameData = null;
                    try
                    {
                        loadedGameData = JsonConvert.DeserializeObject <Rm_RPGHandler>(jsonFromEncode,
                                                                                       new JsonSerializerSettings
                        {
                            TypeNameHandling =
                                TypeNameHandling.Objects,
                            TypeNameAssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple,
                            ObjectCreationHandling = ObjectCreationHandling.Replace
                        });

                        Rm_RPGHandler.Instance = null;
                        Rm_RPGHandler.Instance = loadedGameData;
                        LoadNodes();
                    }
                    catch (Exception e)
                    {
                        throw e;
                        foundData = false;
                    }
                }
            }


            if (!foundData)
            {
                throw new Exception("Fatal Exception. Game data not found or is corrupt.");
            }

            LoadedOnce = true;
        }
Exemplo n.º 3
0
    public static void LoadGameDataFromEditor()
    {
        var foundData = false;

        string jsonFromEncode = null;

        //Create prefab repository if it does not exist
        Directory.CreateDirectory(Application.dataPath + "/Resources/RPGAIOPrefabRepository");

        try
        {
            if (File.Exists(SavePath + GameDataSaveLoadManager.Instance.GameDataFileName))
            {
                jsonFromEncode = File.ReadAllText(SavePath + GameDataSaveLoadManager.Instance.GameDataFileName);
                if (!string.IsNullOrEmpty(jsonFromEncode))
                {
                    foundData = true;
                    if (GameDataSaveLoadManager.Instance.EncryptFiles)
                    {
                        jsonFromEncode = new Xor().Decrypt(jsonFromEncode, GameDataSaveLoadManager.Instance.EncryptKey);
                    }

                    Rm_RPGHandler loadedGameData = null;


                    loadedGameData = JsonConvert.DeserializeObject <Rm_RPGHandler>(jsonFromEncode,
                                                                                   new JsonSerializerSettings
                    {
                        TypeNameHandling       = TypeNameHandling.Objects,
                        TypeNameAssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple,
                        ObjectCreationHandling = ObjectCreationHandling.Replace
                    });



                    if (foundData)
                    {
                        Rm_RPGHandler.Instance = null;
                        Rm_RPGHandler.Instance = loadedGameData;
                        GameDataSaveLoadManager.Instance.LoadNodes();
                    }
                }
            }
        }
        catch (Exception e)
        {
            Debug.LogException(e);
            Debug.LogError("JSON Deserialization error. Creating new data. Check .error.bak to restore.");
            using (var stringwriter = new StreamWriter(SavePath + GameDataSaveLoadManager.Instance.GameDataFileName + "-" + DateTime.Now.ToString("ddMMMyyyy") + ".error.bak", false))
            {
                stringwriter.Write(jsonFromEncode);
            }
            foundData = false;
        }

        if (!foundData)
        {
            Debug.Log("[RPGAIO] No game data found. Creating new game data. ");
            NewData();
        }

        //Debug.Log("Loaded game data");

        GameDataSaveLoadManager.Instance.LoadedOnce = true;
    }
Exemplo n.º 4
0
    //todo: this is where we will have templates
    private static void AddDummyData(Rm_RPGHandler newData)
    {
        //Dummy Data
        var attStr = new Rm_AttributeDefintion()
        {
            Name = "Strength", DefaultValue = 10
        };
        var attStr3 = new Rm_AttributeDefintion()
        {
            Name = "Dexterity", DefaultValue = 10
        };
        var attStr4 = new Rm_AttributeDefintion()
        {
            Name = "Intelligence", DefaultValue = 10
        };
        var attStr5 = new Rm_AttributeDefintion()
        {
            Name = "Vitality", DefaultValue = 10
        };

        newData.ASVT.AttributesDefinitions.Add(attStr);
        newData.ASVT.AttributesDefinitions.Add(attStr3);
        newData.ASVT.AttributesDefinitions.Add(attStr4);
        newData.ASVT.AttributesDefinitions.Add(attStr5);

        var attStr2 = new Rm_VitalDefinition()
        {
            Name = "Mana", DefaultValue = 100
        };

        newData.ASVT.VitalDefinitions.Add(attStr2);

        var statDef1 = new Rm_StatisticDefintion()
        {
            ID = "Movement", Name = "Movement", DefaultValue = 1, IsDefault = true
        };
        var statDef2 = new Rm_StatisticDefintion()
        {
            ID = "Attack Speed", Name = "Attack Speed", DefaultValue = 1, IsDefault = true
        };
        var statDef3 = new Rm_StatisticDefintion()
        {
            ID = "Attack Range", Name = "Attack Range", DefaultValue = 2, IsDefault = true
        };
        var statDef4 = new Rm_StatisticDefintion()
        {
            ID = "Cast Speed", Name = "Cast Speed", DefaultValue = 1, IsDefault = true
        };
        var statDef5 = new Rm_StatisticDefintion()
        {
            ID = "Critical Chance", Name = "Critical Chance", DefaultValue = 0, IsDefault = true
        };

        newData.ASVT.StatisticDefinitions.AddRange(new[] { statDef1, statDef2, statDef3, statDef4, statDef5 });
        var classDef = new Rm_ClassDefinition()
        {
            Name              = "Default",
            ClassPrefabPath   = "Prefabs/Classes/Default",
            AttributePerLevel = new List <Rm_AsvtAmount>()
            {
                new Rm_AsvtAmount()
                {
                    Amount = 5,
                    AsvtID = attStr.ID
                }
            },
            StartingScene       = "DemoScene",
            ApplicableRaceID    = "Default_Builtin_Race_10101010",
            ApplicableSubRaceID = "Default_Builtin_SubRace_10101010",
            ApplicableGenderID  = "Default_Builtin_Gender_10101010",
            ApplicableClassIDs  = new List <StringField>()
            {
                new StringField()
                {
                    ID = "Default_Builtin_Class_10101010"
                }
            }
        };

        newData.Player.CharacterDefinitions.Add(classDef);
        newData.GameInfo.MinimapOptions.PlayerIconPath = "RPGMakerAssets/minimapIcon";
    }