Exemplo n.º 1
0
        public static HeroSave FromJson(HeroSaveJson source)
        {
            HeroClass heroClass = null;

            switch (source.HeroClass.Name)
            {
            case "Warrior":
            {
                heroClass = LoadWarrior(source.HeroClass);
                break;
            }

            default:
            {
                throw new ApplicationException($"Unknown hero class '{source.HeroClass.Name}'.");
            }
            }

            var equipmentItemList = ConvertFromJsonList(source.Equipment);
            var equipment         = new Equipment();

            for (var i = 0; i < equipmentItemList.Count; i++)
            {
                equipment[i] = equipmentItemList[i];
            }

            var inventoryItemList = ConvertFromJsonList(source.Inventory);
            var inventory         = new Inventory(Option.InventoryCapacity);

            inventory.AddRange(inventoryItemList);

            var backPackItemList = ConvertFromJsonList(source.BackPack);
            var backPack         = new Inventory(Option.HomeCapacity);

            backPack.AddRange(backPackItemList);

            var crucibleItemList = ConvertFromJsonList(source.Crucible);
            var crucible         = new Inventory(Option.CrucibleCapacity);

            crucible.AddRange(crucibleItemList);

            var stages = ConvertFromJsonList(source.Stages);

            var heroSave = new HeroSave(
                source.Name,
                heroClass,
                inventory,
                equipment,
                backPack,
                crucible,
                stages,
                source.Properties);

            return(heroSave);
        }
Exemplo n.º 2
0
        private static void SaveWarrior(Warrior warrior, HeroSaveJson data)
        {
            if (data.HeroClass == null)
            {
                data.HeroClass            = new HeroClassJson();
                data.HeroClass.Properties = new List <TrainedStatJson>();
                data.HeroClass.Masteries  = new List <TrainedStatJson>();
            }
            data.HeroClass.Name = warrior.Name;
            data.HeroClass.Properties.Add(ConvertToJson("Fighting", warrior.Fighting));
            data.HeroClass.Properties.Add(ConvertToJson("Combat", warrior.Combat));
            data.HeroClass.Properties.Add(ConvertToJson("Toughness", warrior.Toughness));

            foreach (var kvp in warrior.Masteries)
            {
                data.HeroClass.Masteries.Add(ConvertToJson(kvp.Key, kvp.Value));
            }
        }
Exemplo n.º 3
0
        public static HeroSaveJson ToJson(HeroSave source)
        {
            // Has this hero been altered or played?
            if (!source.IsDirty)
            {
                // This path exists as there are no stages yet and therefore there is not
                // Current Hero
                var heroSaveJson = new HeroSaveJson {
                    Name = source.Name,
                    // Lists that need to be preserved
                    Equipment = ConvertToJsonList(source.Equipment.Items),
                    Inventory = ConvertToJsonList(source.Inventory),
                    BackPack  = ConvertToJsonList(source.BackPack),
                    Crucible  = ConvertToJsonList(source.Crucible),
                    Stages    = ConvertToJsonList(source.Stages),
                    // Actor Properties
                    Properties = source.Properties
                };

                heroSaveJson.Properties["Health"]          = source.Health;
                heroSaveJson.Properties["Charge"]          = source.Charge;
                heroSaveJson.Properties["Position"]        = source.Position;
                heroSaveJson.Properties["ExperienceCents"] = source.ExperienceCents;
                heroSaveJson.Properties["Gold"]            = source.Gold;
                heroSaveJson.Properties["Food"]            = source.Food;

                var warrior = source.HeroClass as Warrior;
                if (warrior != null)
                {
                    SaveWarrior(warrior, heroSaveJson);
                }

                return(heroSaveJson);
            }
            else
            {
                throw new NotImplementedException();
            }
        }