Exemplo n.º 1
0
        private GameLocation GetLocationFromAddress(ChestAddress address)
        {
            var location = Game1.locations.FirstOrDefault(l => l.Name == address.LocationName);

            if (location == null)
            {
                throw new InvalidSaveDataException($"Can't find location named {address.LocationName}");
            }

            if (address.LocationType != ChestLocationType.Building)
            {
                return(location);
            }

            if (!(location is BuildableGameLocation buildableLocation))
            {
                throw new InvalidSaveDataException($"Can't find any buildings in location named {location.Name}");
            }

            var building = buildableLocation.buildings.SingleOrDefault(b => b.nameOfIndoors == address.BuildingName);

            if (building == null)
            {
                throw new InvalidSaveDataException($"Save data contains building data in {address.BuildingName} but building does not exist");
            }

            return(building.indoors.Value);
        }
Exemplo n.º 2
0
        private GameLocation GetLocationFromAddress(ChestAddress address)
        {
            var location = Game1.locations.FirstOrDefault(l => l.Name == address.LocationName);

            if (location == null)
            {
                throw new InvalidSaveDataException($"Can't find location named {address.LocationName}");
            }

            if (address.LocationType == ChestLocationType.Building)
            {
                if (location is BuildableGameLocation buildableLocation)
                {
                    var building = buildableLocation.buildings // TODO: check
                                   .FirstOrDefault(b => b.nameOfIndoors == address.BuildingName);

                    if (building == null)
                    {
                        throw new InvalidSaveDataException(
                                  $"Can't find building named {address.BuildingName} in location named {location.Name}");
                    }

                    return(building.indoors);
                }
                else
                {
                    throw new InvalidSaveDataException($"Can't find any buildings in location named {location.Name}");
                }
            }
            else
            {
                return(location);
            }
        }
Exemplo n.º 3
0
        public Chest GetChestByAddress(ChestAddress address)
        {
            if (address.LocationType == ChestLocationType.Refrigerator)
            {
                var house = (FarmHouse)Game1.locations.SingleOrDefault(l => l is FarmHouse f && address.LocationName == (f.uniqueName?.Value ?? f.Name));

                if (house == null)
                {
                    throw new InvalidSaveDataException($"Save data contains refrigerator data in {address.LocationName} but location does not exist");
                }

                if (house.upgradeLevel < 1)
                {
                    throw new InvalidSaveDataException($"Save data contains refrigerator data in {address.LocationName} but refrigerator does not exist");
                }

                return(house.fridge.Value);
            }

            var location = GetLocationFromAddress(address);

            if (location.objects.ContainsKey(address.Tile) && location.objects[address.Tile] is Chest chest)
            {
                return(chest);
            }

            throw new InvalidSaveDataException($"Can't find chest in {location.Name} at {address.Tile}");
        }
Exemplo n.º 4
0
        public Chest GetChestByAddress(ChestAddress address)
        {
            if (address.LocationType == ChestLocationType.Refrigerator)
            {
                var farmHouse = (FarmHouse)Game1.locations.First(l => l is FarmHouse);

                if (Game1.player.HouseUpgradeLevel < 1)
                {
                    throw new InvalidSaveDataException(
                              "Chest save data contains refrigerator data but no refrigerator exists");
                }

                return(farmHouse.fridge);
            }
            else
            {
                var location = GetLocationFromAddress(address);

                if (location.objects.ContainsKey(address.Tile) && location.objects[address.Tile] is Chest chest)
                {
                    return(location.objects[address.Tile] as Chest);
                }
                else
                {
                    throw new InvalidSaveDataException($"Can't find chest in {location.Name} at {address.Tile}");
                }
            }
        }