コード例 #1
0
        private IEnumerable <SolidRouteState> GeneratePlacedStates(Func <Searchspace, IPhysicalBuilding, double> costFunction)
        {
            var placedBuilding = new PlacedItem(((FlowBuilding)_building).Item, _position);

            placedBuilding.Previous.Add(Building);
            yield return(new SolidRouteState(placedBuilding, _cost + costFunction(_space, placedBuilding), _position, _space.AddRoute(placedBuilding), RoutingCoordinate.CoordinateType.PlacedItem));
        }
コード例 #2
0
 public double dist(PlacedItem pi)
 {
     return(Math.Sqrt((((x - pi.x)
                        * (x - pi.x))
                       + ((y - pi.y)
                          * (y - pi.y)))));
 }
コード例 #3
0
        public void WritePlace()
        {
            try
            {
                StreamWriter fo = new StreamWriter(locationJsonFile);
                fo.WriteLine("[" + crlf);

                for (int i = 0; i < allTypeRead.Length; i++)
                {
                    for (int j = 0; j < allTypeRead[i].Count; j++)
                    {
                        PlacedItem pj = allTypeRead[i][j];
                        if (i == allTypeRead.Length - 1 && j == allTypeRead[i].Count - 1)
                        {
                            fo.WriteLine(pj.ToString(i + 1, 150) + crlf);
                        }
                        else
                        {
                            fo.WriteLine(pj.ToString(i + 1, 150) + "," + crlf);
                        }
                    }
                }

                fo.WriteLine("]" + crlf);
                fo.Close();
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine($"[Error] {ex.ToString()}");
                Console.ForegroundColor = ConsoleColor.Gray;
            }
        }
コード例 #4
0
        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);

            Event.ConfigureForDatabase(builder);
            Region.ConfigureForDatabase(builder);
            LocationGroup.ConfigureForDatabase(builder);
            Location.ConfigureForDatabase(builder);

            BagCategory.ConfigureForDatabase(builder);
            Item.ConfigureForDatabase(builder);
            PlacedItem.ConfigureForDatabase(builder);
            Currency.ConfigureForDatabase(builder);
            CurrencyAmount.ConfigureForDatabase(builder);

            ElementalType.ConfigureForDatabase(builder);
            ElementalTypeRelation.ConfigureForDatabase(builder);
            Ability.ConfigureForDatabase(builder);
            PvpTier.ConfigureForDatabase(builder);
            PokemonAvailability.ConfigureForDatabase(builder);
            PokemonVarietyUrl.ConfigureForDatabase(builder);

            Entities.PokemonSpecies.ConfigureForDatabase(builder);
            PokemonVariety.ConfigureForDatabase(builder);
            PokemonForm.ConfigureForDatabase(builder);
            Evolution.ConfigureForDatabase(builder);

            MoveDamageClass.ConfigureForDatabase(builder);
            Move.ConfigureForDatabase(builder);
            MoveTutor.ConfigureForDatabase(builder);
            MoveTutorMove.ConfigureForDatabase(builder);
            MoveTutorMovePrice.ConfigureForDatabase(builder);
            MoveLearnMethod.ConfigureForDatabase(builder);
            MoveLearnMethodLocation.ConfigureForDatabase(builder);
            MoveLearnMethodLocationPrice.ConfigureForDatabase(builder);
            LearnableMove.ConfigureForDatabase(builder);
            LearnableMoveLearnMethod.ConfigureForDatabase(builder);

            TimeOfDay.ConfigureForDatabase(builder);
            Season.ConfigureForDatabase(builder);
            SeasonTimeOfDay.ConfigureForDatabase(builder);
            SpawnType.ConfigureForDatabase(builder);
            Spawn.ConfigureForDatabase(builder);
            SpawnOpportunity.ConfigureForDatabase(builder);

            Nature.ConfigureForDatabase(builder);
            HuntingConfiguration.ConfigureForDatabase(builder);
            Build.ConfigureForDatabase(builder);
            ItemOption.ConfigureForDatabase(builder);
            MoveOption.ConfigureForDatabase(builder);
            NatureOption.ConfigureForDatabase(builder);

            ItemStatBoost.ConfigureForDatabase(builder);
            Entities.ItemStatBoostPokemon.ConfigureForDatabase(builder);

            ImportSheet.ConfigureForDatabase(builder);
        }
コード例 #5
0
 /// <summary>Attempts to generate and place an item using the <see cref="Utility.DGAItemAPI"/> interface.</summary>
 /// <param name="forage">The SavedObject containing this forage's information.</param>
 /// <param name="location">The GameLocation where the forage should be spawned.</param>
 /// <param name="tile">The x/y coordinates of the tile where the ore should be spawned.</param>
 /// <returns>True if the item spawned successfully; false otherwise.</returns>
 private static bool SpawnDGAItem(SavedObject forage, GameLocation location, Vector2 tile)
 {
     try
     {
         object rawDGA = DGAItemAPI.SpawnDGAItem(forage.Name); //try to create this item with DGA's API
         if (rawDGA is Furniture furnitureDGA)                 //if the resulting item is furniture
         {
             Monitor.VerboseLog($"Spawning DGA forage furniture. Name: {forage.Name}. Location: {tile.X},{tile.Y} ({location.Name}).");
             furnitureDGA.TileLocation = tile;
             Rectangle originalBoundingBox = furnitureDGA.boundingBox.Value;                                                                            //get "original" bounding box
             furnitureDGA.boundingBox.Value = new Rectangle((int)tile.X * 64, (int)tile.Y * 64, originalBoundingBox.Width, originalBoundingBox.Height); //adjust for tile position
             furnitureDGA.updateDrawPosition();
             location.furniture.Add(furnitureDGA);                                                                                                      //add the furniture to this location
             return(true);
         }
         else if (rawDGA is StardewValley.Object objectDGA) //if the resulting item is a SDV object (i.e. can be treated like normal forage)
         {
             Monitor.VerboseLog($"Spawning DGA forage object. Name: {forage.Name}. Location: {tile.X},{tile.Y} ({location.Name}).");
             objectDGA.IsSpawnedObject = true;
             return(location.dropObject(objectDGA, tile * 64f, Game1.viewport, true, null)); //attempt to place the object and return success/failure
         }
         else if (rawDGA is Item itemDGA)                                                    //if the resulting item is any other type of Item (i.e. can be treated as a PlacedItem)
         {
             if (location.terrainFeatures.ContainsKey(tile))                                 //if a terrain feature already exists on this tile
             {
                 return(false);                                                              //fail to spawn
             }
             Monitor.VerboseLog($"Spawning DGA forage item. Name: {forage.Name}. Location: {tile.X},{tile.Y} ({location.Name}).");
             PlacedItem placed = new PlacedItem(tile, itemDGA); //create a terrainfeature containing the item
             location.terrainFeatures.Add(tile, placed);        //add the placed item to this location
             return(true);
         }
         else if (rawDGA != null) //if DGA spawned an item, but it isn't a recognized type
         {
             Monitor.Log("Dynamic Game Assets (DGA) created an item, but FTM doesn't recognize its type. This may be caused by the item or a problem with FTM's logic.", LogLevel.Warn);
             Monitor.Log($"Item name: {forage.Name}", LogLevel.Warn);
             Monitor.Log($"Item type (C# code): {rawDGA.GetType()?.Name ?? "null"}", LogLevel.Warn);
             return(false);
         }
         else //if DGA did not spawn an item
         {
             Monitor.Log("The SpawnForage method failed to generate a Dynamic Game Assets (DGA) item. This may be caused by a problem with this mod's logic. Please report this to FTM's developer if possible.", LogLevel.Warn);
             Monitor.Log($"Item name: {forage.Name}", LogLevel.Warn);
             return(false);
         }
     }
     catch (Exception ex)
     {
         Monitor.Log($"An error occurred while spawning a Dynamic Game Assets (DGA) item.", LogLevel.Warn);
         Monitor.Log($"Item name: \"{forage.Name}\"", LogLevel.Warn);
         Monitor.Log($"The affected item will be skipped. The auto-generated error message has been added to the log.", LogLevel.Warn);
         Monitor.Log($"----------", LogLevel.Trace);
         Monitor.Log($"{ex.ToString()}", LogLevel.Trace);
         return(false);
     }
 }
コード例 #6
0
        public void AffectPlace(PlacedItem pi)
        {
            bool found = false;

            do
            {
                pi.x  = new Random().Next(-900, 900);
                pi.y  = new Random().Next(-900, 900);
                found = RoomOk(pi);
            } while (!found);
        }
コード例 #7
0
            /// <summary>Generates a item from a saved object and places it on the specified map and tile.</summary>
            /// <param name="forage">The SavedObject containing this forage's information.</param>
            /// <param name="location">The GameLocation where the forage should be spawned.</param>
            /// <param name="tile">The x/y coordinates of the tile where the ore should be spawned.</param>
            public static bool SpawnForage(SavedObject forage, GameLocation location, Vector2 tile)
            {
                if (forage.Type == SavedObject.ObjectType.Object)                  //if this is a basic object
                {
                    return(SpawnForage(forage.ID.Value, location, tile));          //call the object ID version of this method
                }
                else if (forage.Type == SavedObject.ObjectType.Container)          //if this is a container
                {
                    Item container = CreateItem(forage, tile);                     //create the container to be spawned

                    if (container == null || !(container is StardewValley.Object)) //if the container couldn't be created or isn't a StardewValley.Object
                    {
                        Monitor.Log("The SpawnForage method failed to generate a container. This may be caused by a problem with this mod's logic. Please report this to the developer if possible.", LogLevel.Warn);
                        Monitor.Log($"Container type: {forage.Name}", LogLevel.Warn);
                        Monitor.Log($"Item ID: {forage.ID}", LogLevel.Warn);
                        return(false);
                    }

                    if (location.objects.ContainsKey(tile)) //if this tile is already occupied in the object dictionary
                    {
                        Monitor.VerboseLog("Tile is already occupied by an object. Skipping container spawn.");
                    }

                    Monitor.VerboseLog($"Spawning container. Type: {container.DisplayName}. Location: {tile.X},{tile.Y} ({location.Name}).");
                    location.objects.Add(tile, (StardewValley.Object)container); //add the container to the location's object array
                    return(true);
                }
                else if (forage.Type == SavedObject.ObjectType.DGA) //if this is a DGA item
                {
                    return(SpawnDGAItem(forage, location, tile));
                }
                else //if this is an item
                {
                    if (location.terrainFeatures.ContainsKey(tile)) //if a terrain feature already exists on this tile
                    {
                        return(false);                          //fail to spawn
                    }
                    Item forageItem = CreateItem(forage, tile); //create the item to be spawned

                    if (forageItem == null)                     //if the item couldn't be created
                    {
                        Monitor.Log("The SpawnForage method failed to generate an item. This may be caused by a problem with this mod's logic. Please report this to the developer if possible.", LogLevel.Warn);
                        Monitor.Log($"Item name: {forage.Name}", LogLevel.Warn);
                        Monitor.Log($"Item ID: {forage.ID}", LogLevel.Warn);
                        return(false);
                    }

                    Monitor.VerboseLog($"Spawning forage item. Type: {forageItem.Name}. Location: {tile.X},{tile.Y} ({location.Name}).");
                    PlacedItem placed = new PlacedItem(tile, forageItem); //create a terrainfeature containing the item
                    location.terrainFeatures.Add(tile, placed);           //add the placed item to this location
                    return(true);
                }
            }
コード例 #8
0
 public void AddItem(PlacedItem placedItem)
 {
     PlacedItems.Add(placedItem);
     placedItem.OnRemove += () =>
     {
         if (PlacedItems.Contains(placedItem))
         {
             RemoveItem(placedItem);
         }
     };
     placedItem.Place();
 }
コード例 #9
0
    public void RemoveItem(PlacedItem placedItem)
    {
        if (placedItem == null || !placedItem.Removable)
        {
            return;
        }

        ItemController.AddItem(placedItem.Item);

        PlacedItems.Remove(placedItem);
        placedItem.Remove();
    }
コード例 #10
0
 public void FillAllItem()
 {
     try
     {
         StreamReader br    = new StreamReader(locationFile);
         int          iLine = 0;
         string       line;
         while ((line = br.ReadLine()) != null)
         {
             if (line.Contains(":") && line.Contains("."))
             {
                 string concept = line.Split(':')[0].Split('.')[1];
                 string dimS    = line.Split(':')[1].Replace(";", "");
                 int    dim     = 0;
                 Int32.TryParse(dimS, out dim);
                 PlacedItem c = new PlacedItem();
                 c.name = concept;
                 c.dim  = 100;
                 AffectPlace(c);
                 allConcept.Add(c);
             }
             else if (line.Contains(".") && !line.Contains(":"))
             {
                 string lu   = line.Split('.')[0];
                 string name = line.Split('.')[1].Replace(";", "");
                 Console.WriteLine($"item  {lu} {name}");
                 for (int i = 1; i < allTypeRead.Length; i++)
                 {
                     if (lu.Equals(allType[i], StringComparison.CurrentCultureIgnoreCase))
                     {
                         PlacedItem pi = new PlacedItem();
                         pi.name = name;
                         AffectPlace(pi);
                         allTypeRead[i].Add(pi);
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Console.ForegroundColor = ConsoleColor.Red;
         Console.WriteLine($"[Error] {ex.ToString()}");
         Console.ForegroundColor = ConsoleColor.Gray;
     }
 }
コード例 #11
0
        public bool RoomOk(PlacedItem pi)
        {
            bool ok = true;

            for (int i = 0; (i < allTypeRead.Length); i++)
            {
                for (int j = 0; (j < allTypeRead[i].Count); j++)
                {
                    PlacedItem pj = allTypeRead[i][j];
                    if ((pi.dist(pj) < 100))
                    {
                        return(false);
                    }
                }
            }

            return(ok);
        }
コード例 #12
0
        /// <summary>
        /// Attempts to route from the start states to the destination states. The given states are both lists, but only one state from each list will be selected for the final routing.
        /// </summary>
        /// <param name="item">How much to route.</param>
        /// <param name="space">The initialstate from which the routing starts.</param>
        /// <param name="startPositions">The list of starting states. Only one will be used.</param>
        /// <param name="destinations">The list of desired destination states. Only one will be reached.</param>
        /// <returns>The solution state found after routing</returns>
        public Searchspace Route(ItemAmount item, Searchspace space, IEnumerable <RoutingCoordinate> startPositions, IEnumerable <RoutingCoordinate> destinations)
        {
            if (startPositions == null)
            {
                throw new ArgumentNullException("startPositions");
            }
            if (destinations == null)
            {
                throw new ArgumentNullException("destinations");
            }

            AStar <SolidRouteState> star = new AStar <SolidRouteState>();

            star.StateGenerator    = (s) => s.NextStates(Grader.CostForBuilding, Belt, BeltGroundNormal, BeltGroundFast, BeltGroundExpress, Inserter, LongInserter, FastInserter, Splitter);
            star.EndStateValidator = ValidateEndState;

            foreach (var dest in destinations)
            {
                star.AddDestination(dest);
            }

            foreach (var position in startPositions)
            {
                switch (position.State)
                {
                case RoutingCoordinate.CoordinateType.Belt:
                    var startBuilding = new Belt(item, Belt, position.Position, position.Rotation);
                    var tmpSpace1     = space.AddRoute(startBuilding);
                    var startState    = new SolidRouteState(startBuilding, 0, position.Position, tmpSpace1, RoutingCoordinate.CoordinateType.Belt, Depth.None, position.Rotation);
                    star.AddState(startState);
                    break;

                case RoutingCoordinate.CoordinateType.PlacedItem:
                case RoutingCoordinate.CoordinateType.Inserter:
                    var startPlacedBuilding = new PlacedItem(item, position.Position);
                    var tmpSpace2           = space.AddRoute(startPlacedBuilding);
                    var startPlacedState    = new SolidRouteState(startPlacedBuilding, 0, position.Position, tmpSpace2, RoutingCoordinate.CoordinateType.PlacedItem);
                    star.AddState(startPlacedState);
                    break;

                case RoutingCoordinate.CoordinateType.Splitter:
                    var offsets = new BuildingRotation[] {
                        BuildingRotation.West,
                        BuildingRotation.North,
                        BuildingRotation.West,
                        BuildingRotation.North,
                    };

                    var offsetDir      = offsets[(int)position.Rotation];
                    var startSplitter1 = new Splitter(item, Splitter, position.Position, position.Rotation);
                    var startSplitter2 = new Splitter(item, Splitter, position.Position + offsetDir.ToVector(), position.Rotation);
                    var space1         = space.AddRoute(startSplitter1);
                    var space2         = space.AddRoute(startSplitter2);
                    var state1         = new SolidRouteState(startSplitter1, 0, position.Position - offsetDir.ToVector(), space1, RoutingCoordinate.CoordinateType.Belt, Depth.None, position.Rotation);
                    var state2         = new SolidRouteState(startSplitter2, 0, position.Position + offsetDir.ToVector(), space2, RoutingCoordinate.CoordinateType.Belt, Depth.None, position.Rotation);
                    var before         = space.CalculateCollisions(position.Position - position.Rotation.ToVector()).OfType <Belt>()
                                         .Where((b) => b.Item.Item == item.Item)
                                         .Where((b) => b.Rotation == position.Rotation);
                    var after = space.CalculateCollisions(position.Position + position.Rotation.ToVector()).OfType <Belt>()
                                .Where((b) => b.Item.Item == item.Item)
                                .Where((b) => b.Rotation == position.Rotation);

                    if (before.Any() && after.Any())
                    {
                        star.AddState(state1);
                        star.AddState(state2);
                    }

                    var startPlacedBuilding2 = new PlacedItem(item, position.Position);
                    var tmpSpace3            = space.AddRoute(startPlacedBuilding2);
                    var startPlacedState2    = new SolidRouteState(startPlacedBuilding2, 0, position.Position, tmpSpace3, RoutingCoordinate.CoordinateType.PlacedItem);
                    star.AddState(startPlacedState2);
                    break;
                }
            }

            while (!star.Step())
            {
            }

            return(star.EndState.Space);
        }