コード例 #1
0
        public static void UpdatePlayerSaveFile(CharData charData, WorldData worldData)
        {
            String userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name.Split(new List <char>()
            {
                '\\'
            }.ToArray(), 2)[1];

            //PLACEHOLDER
            //userName = "******";
            //PLACEHOLDER
            if (!Directory.Exists("C:/Users/" + userName + "/Documents/My Games/Afterhour/"))
            {
                Directory.CreateDirectory("C:/Users/" + userName + "/Documents/My Games/Afterhour/");
            }

            String filepath = "C:/Users/" + userName + "/Documents/My Games/Afterhour/" + charData.name + ".ah";

            using (BinaryWriter writer = new BinaryWriter(File.Open(filepath, FileMode.Create))) {
                //Char Data
                writer.Write(charData.name);
                writer.Write(charData.gender);
                writer.Write(charData.hairstyleID);

                writer.Write(charData.manaColor.R);
                writer.Write(charData.manaColor.G);
                writer.Write(charData.manaColor.B);

                writer.Write(charData.skinColor.R);
                writer.Write(charData.skinColor.G);
                writer.Write(charData.skinColor.B);

                writer.Write(charData.hairColor.R);
                writer.Write(charData.hairColor.G);
                writer.Write(charData.hairColor.B);

                writer.Write(charData.shirtColor.R);
                writer.Write(charData.shirtColor.G);
                writer.Write(charData.shirtColor.B);
                //

                //World Data
                writer.Write(worldData.curLevel);      //Level
                writer.Write(worldData.curExp);        //Experience

                writer.Write(worldData.curHP);         //HP
                writer.Write(worldData.curMP);         //MP

                writer.Write(worldData.curMoney);      //Money

                writer.Write(worldData.stats.Count()); //Stats
                foreach (int stat in worldData.stats)
                {
                    writer.Write(stat);
                }

                writer.Write(worldData.inventoryItems.Count()); //Inventory Items
                foreach (int item in worldData.inventoryItems)
                {
                    writer.Write(item);
                }

                writer.Write(worldData.inventoryItemCounts.Count()); //Inventory Item counts
                foreach (int count in worldData.inventoryItemCounts)
                {
                    writer.Write(count);
                }

                writer.Write(worldData.unlockedSkillIDs.Count()); //Unlocked Skill IDs
                foreach (int skillID in worldData.unlockedSkillIDs)
                {
                    writer.Write(skillID);
                }

                writer.Write(worldData.skillXPs.Count()); //Unlocked Skill XP Values
                foreach (double skillXPVal in worldData.skillXPs)
                {
                    writer.Write(skillXPVal);
                }

                writer.Write(worldData.curZoneID);            //Current zone ID

                writer.Write((int)worldData.curWorldPos.X);   //WorldPos X
                writer.Write((int)worldData.curWorldPos.Y);   //WorldPos Y

                writer.Write(worldData.curSummonIDs.Count()); //Current avaliable summon ID's
                foreach (int summonID in worldData.curSummonIDs)
                {
                    writer.Write(summonID);
                }
                //
            }
        }
コード例 #2
0
 public static void SaveGame(CharData charData, WorldData worldData)
 {
     UpdatePlayerSaveFile(charData, worldData);
 }
コード例 #3
0
 public SaveData(CharData charData, WorldData worldData)
 {
     this.charData  = charData;
     this.worldData = worldData;
 }
コード例 #4
0
        public static SaveData LoadPlayerSaveFile(String name)
        {
            String userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name.Split(new List <char>()
            {
                '\\'
            }.ToArray(), 2)[1];

            System.Diagnostics.Debug.WriteLine("Current reading filepath: " + "C:/Users/" + userName + "/Documents/My Games/Afterhour/" + name + ".ah");

            //PLACEHOLDER
            //userName = "******";
            //PLACEHOLDER
            String filepath = "C:/Users/" + userName + "/Documents/My Games/Afterhour/" + name + ".ah";

            CharData  loadedCharData  = new CharData();
            WorldData loadedWorldData = new WorldData();
            SaveData  fullLoadedData  = null;

            if (File.Exists(filepath))
            {
                using (BinaryReader reader = new BinaryReader(File.Open(filepath, FileMode.Open))) {
                    //Char Data
                    loadedCharData.name        = reader.ReadString();
                    loadedCharData.gender      = reader.ReadInt32();
                    loadedCharData.hairstyleID = reader.ReadInt32();

                    Color tempManaColor = Color.White;
                    tempManaColor.R          = reader.ReadByte();
                    tempManaColor.G          = reader.ReadByte();
                    tempManaColor.B          = reader.ReadByte();
                    loadedCharData.manaColor = tempManaColor;

                    Color tempSkinColor = Color.White;
                    tempSkinColor.R          = reader.ReadByte();
                    tempSkinColor.G          = reader.ReadByte();
                    tempSkinColor.B          = reader.ReadByte();
                    loadedCharData.skinColor = tempSkinColor;

                    Color tempHairColor = Color.White;
                    tempHairColor.R          = reader.ReadByte();
                    tempHairColor.G          = reader.ReadByte();
                    tempHairColor.B          = reader.ReadByte();
                    loadedCharData.hairColor = tempHairColor;

                    Color tempShirtColor = Color.White;
                    tempShirtColor.R          = reader.ReadByte();
                    tempShirtColor.G          = reader.ReadByte();
                    tempShirtColor.B          = reader.ReadByte();
                    loadedCharData.shirtColor = tempShirtColor;
                    //

                    //World Data
                    loadedWorldData.curLevel = reader.ReadInt32(); //Level
                    loadedWorldData.curExp   = reader.ReadInt32(); //Experienece

                    loadedWorldData.curHP = reader.ReadInt32();
                    loadedWorldData.curMP = reader.ReadInt32();

                    loadedWorldData.curMoney = reader.ReadInt32();

                    int statCount = reader.ReadInt32(); //Stats
                    for (int i = 0; i < statCount; i++)
                    {
                        loadedWorldData.stats.Add(reader.ReadInt32());
                    }

                    int inventoryItemCount = reader.ReadInt32(); //Inventory Items
                    for (int i = 0; i < inventoryItemCount; i++)
                    {
                        loadedWorldData.inventoryItems.Add(reader.ReadInt32());
                    }

                    int inventoryItemNumCount = reader.ReadInt32(); //Inventory Item counts
                    for (int i = 0; i < inventoryItemNumCount; i++)
                    {
                        loadedWorldData.inventoryItemCounts.Add(reader.ReadInt32());
                    }

                    int unlockedSkillIDsCount = reader.ReadInt32(); //Unlocked Skill IDs
                    for (int i = 0; i < unlockedSkillIDsCount; i++)
                    {
                        loadedWorldData.unlockedSkillIDs.Add(reader.ReadInt32());
                    }

                    double skillXPsCount = reader.ReadInt32(); //Unlocked Skill XP Values
                    for (int i = 0; i < skillXPsCount; i++)
                    {
                        loadedWorldData.skillXPs.Add(reader.ReadDouble());
                    }

                    loadedWorldData.curZoneID = reader.ReadInt32(); //Current zone ID

                    Vector2 tempWorldPos = new Vector2(0, 0);
                    tempWorldPos.X = reader.ReadInt32(); //WorldPos X
                    tempWorldPos.Y = reader.ReadInt32(); //WorldPos Y
                    loadedWorldData.curWorldPos = tempWorldPos;

                    int summonableCount = reader.ReadInt32(); //Current avaliable summon ID's
                    for (int i = 0; i < summonableCount; i++)
                    {
                        loadedWorldData.curSummonIDs.Add(reader.ReadInt32());
                    }
                    //
                }
                fullLoadedData = new SaveData(loadedCharData, loadedWorldData);
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("File at path " + filepath + " not found.");
            }


            return(fullLoadedData);
        }