Пример #1
0

        
        // TODO check if data is correct/makes sense
        static public ValheimEngine.Character CharacterReadData(string path)
        {
            // Read header
            var character  = new ValheimEngine.Character();
            var byteAccess = LoadDataFromPath(path);

            if (byteAccess.Length() == 0)
            {
                MessageBox.Show("Could not read file.", "ERROR", MessageBoxButtons.OK);
            }
            character.CharacterVersion = byteAccess.ReadInt32(); // shouldn't be below 30
            character.Kills            = byteAccess.ReadInt32();
            character.Deaths           = byteAccess.ReadInt32();
            character.Crafts           = byteAccess.ReadInt32();
            character.Builds           = byteAccess.ReadInt32();
            var numberOfWorlds = byteAccess.ReadInt32();

            // Read worlds information
            for (var i = 0; i < numberOfWorlds; i++)
            {
                var worldId = byteAccess.ReadInt64();
                var world   = new ValheimEngine.Character.World
                {
                    HasCustomSpawnPoint = byteAccess.ReadBoolean(),
                    SpawnPoint          = byteAccess.ReadVector3(),
                    HasLogoutPoint      = byteAccess.ReadBoolean(),
                    LogoutPoint         = byteAccess.ReadVector3(),
                    HasDeathPoint       = byteAccess.ReadBoolean(),
                    DeathPoint          = byteAccess.ReadVector3(),
                    HomePoint           = byteAccess.ReadVector3(),
                };
                if (byteAccess.ReadBoolean())
                {
                    world.MapData = byteAccess.ReadBytes();
                }

                character.WorldsData.Add(worldId, world);
            }

            // Read main character info
            character.Name      = byteAccess.ReadString();
            character.Id        = byteAccess.ReadInt64();
            character.StartSeed = byteAccess.ReadString();

            // Check if character has more player data
            // Should be false for new characters
            if (!byteAccess.ReadBoolean())
            {
                return(character);
            }

            var dataLength = byteAccess.ReadInt32();

            character.DataVersion = byteAccess.ReadInt32();

            character.MaxHp                 = byteAccess.ReadSingle();
            character.Hp                    = byteAccess.ReadSingle();
            character.Stamina               = byteAccess.ReadSingle();
            character.IsFirstSpawn          = byteAccess.ReadBoolean();
            character.TimeSinceDeath        = byteAccess.ReadSingle();
            character.GuardianPower         = byteAccess.ReadString();
            character.GuardianPowerCooldown = byteAccess.ReadSingle();

            // Read inventory info
            character.Inventory        = new List <ValheimEngine.Character.Item>();
            character.InventoryVersion = byteAccess.ReadInt32();
            var numberOfItems = byteAccess.ReadInt32();

            for (var i = 0; i < numberOfItems; i++)
            {
                var item = new ValheimEngine.Character.Item
                {
                    Name        = byteAccess.ReadString(),
                    Stack       = byteAccess.ReadInt32(),
                    Durability  = byteAccess.ReadSingle(),
                    Pos         = new Tuple <int, int>(byteAccess.ReadInt32(), byteAccess.ReadInt32()),
                    Equipped    = byteAccess.ReadBoolean(),
                    Quality     = byteAccess.ReadInt32(),
                    Variant     = byteAccess.ReadInt32(),
                    CrafterId   = byteAccess.ReadInt64(),
                    CrafterName = byteAccess.ReadString()
                };

                if (item.Name != "")
                {
                    character.Inventory.Add(item);
                }
            }

            // Read character info like recipes, trophies, tutorials, etc
            character.Recipes        = new HashSet <string>();
            character.KnownMaterials = new HashSet <string>();
            character.ShownTutorials = new HashSet <string>();
            character.Uniques        = new HashSet <string>();
            character.Trophies       = new HashSet <string>();
            character.Biomes         = new HashSet <ValheimEngine.Character.Biome>();

            var numberOfRecipes = byteAccess.ReadInt32();

            for (var i = 0; i < numberOfRecipes; i++)
            {
                character.Recipes.Add(byteAccess.ReadString());
            }

            var numberOfStations = byteAccess.ReadInt32();

            for (var i = 0; i < numberOfStations; i++)
            {
                character.Stations.Add(byteAccess.ReadString(), byteAccess.ReadInt32());
            }

            var numberOfKnownMaterials = byteAccess.ReadInt32();

            for (var i = 0; i < numberOfKnownMaterials; i++)
            {
                character.KnownMaterials.Add(byteAccess.ReadString());
            }

            var numberOfShownTutorials = byteAccess.ReadInt32();

            for (var i = 0; i < numberOfShownTutorials; i++)
            {
                character.ShownTutorials.Add(byteAccess.ReadString());
            }

            var numberOfUniques = byteAccess.ReadInt32();

            for (var i = 0; i < numberOfUniques; i++)
            {
                character.Uniques.Add(byteAccess.ReadString());
            }

            var numberOfTrophies = byteAccess.ReadInt32();

            for (var i = 0; i < numberOfTrophies; i++)
            {
                character.Trophies.Add(byteAccess.ReadString());
            }

            var numberOfBiomes = byteAccess.ReadInt32();

            for (var i = 0; i < numberOfBiomes; i++)
            {
                character.Biomes.Add((ValheimEngine.Character.Biome)byteAccess.ReadInt32());
            }

            var numberOfTexts = byteAccess.ReadInt32();

            for (var i = 0; i < numberOfTexts; i++)
            {
                character.Texts.Add(byteAccess.ReadString(), byteAccess.ReadString());
            }

            // Read character appearance
            character.Beard     = byteAccess.ReadString();
            character.Hair      = byteAccess.ReadString();
            character.SkinColor = byteAccess.ReadVector3();
            character.HairColor = byteAccess.ReadVector3();
            character.Gender    = byteAccess.ReadInt32();

            // Read character state like food consumed, skills, etc.
            var numberOfConsumedFood = byteAccess.ReadInt32();

            character.Foods = new List <ValheimEngine.Character.Food>();
            for (var i = 0; i < numberOfConsumedFood; i++)
            {
                var food = new ValheimEngine.Character.Food
                {
                    Name        = byteAccess.ReadString(),
                    HpLeft      = byteAccess.ReadSingle(),
                    StaminaLeft = byteAccess.ReadSingle()
                };
                character.Foods.Add(food);
            }

            character.SkillsVersion = byteAccess.ReadInt32();
            var numberOfSkills = byteAccess.ReadInt32();

            character.Skills = new List <ValheimEngine.Character.Skill>();
            for (var i = 0; i < numberOfSkills; i++)
            {
                var skill = new ValheimEngine.Character.Skill
                {
                    SkillName = (ValheimEngine.Character.SkillName)byteAccess.ReadInt32(),
                    Level     = byteAccess.ReadSingle(),
                    Something = byteAccess.ReadSingle()
                };
                character.Skills.Add(skill);
            }

            return(character);
        }
 private void ItemChangeApplied(object sender, ValheimEngine.Character.Item e)
 {
     _inventory[e.Pos.Item2, e.Pos.Item1].ItemData = e;
 }