/* Gets rid of this task's owner, making it ownerless. */
 public void removeOwner()
 {
     if (owner != null)
     {
         owner.controller = null;
         owner            = null;
     }
 }
        /* Set the owner of this task to be the given minion.
         * If the task cannot be assigned--by default, because there was no path
         * to the task--then it returns false. Otherwise, it returns true.
         */
        public virtual bool setOwner(SkeletalMinion owner)
        {
            owner.controller = new PathFindController(owner, owner.currentLocation, isAtEnd, 2, true, endBehavior, 9999, position);

            if (owner.controller.pathToEndPoint == null || owner.controller.pathToEndPoint.Count == 0)
            {
                SkeletalMinionsMod.mod.Monitor.Log($"No path.");
                owner.controller = null;
                return(false);
            }

            this.owner = owner;
            return(true);
        }
 public bool meetsItemRequirements(SkeletalMinion minion)
 {
     if (requiredItems == null)
     {
         return(true);
     }
     foreach (KeyValuePair <int, int> requirement in requiredItems)
     {
         if (minion.getItemInInventoryCount(requirement.Key) < requirement.Value)
         {
             return(false);
         }
     }
     return(true);
 }
 private void SaveEvents_BeforeSave(object sender, EventArgs e)
 {
     // destroy all minions and return their items to their owners
     foreach (GameLocation l in Game1.locations)
     {
         for (int i = l.characters.Count - 1; i >= 0; --i)
         {
             if (l.characters[i] is SkeletalMinion)
             {
                 SkeletalMinion minion = l.characters[i] as SkeletalMinion;
                 minion.returnItemsToOwner();
                 l.characters.Remove(minion);
             }
         }
     }
 }
Ejemplo n.º 5
0
        // Assign the closest, pathable task to the given minion, accepting only task names stored in 'taskTypes'.
        // If taskTypes is empty or null, any task type will be accepted.
        // Returns true if a task was assigned, false otherwise.
        public bool assignTask(SkeletalMinion minion, List <string> taskTypes)
        {
            List <MinionTask> candidates;

            if (taskTypes == null || taskTypes.Count == 0)
            {
                candidates = tasks;
            }
            else
            {
                candidates = new List <MinionTask>();
            }

            // narrow down candidates by task type and location
            if (candidates != tasks)
            {
                foreach (MinionTask task in tasks)
                {
                    if (taskTypes.Contains(task.name) && task.location == minion.currentLocation && task.meetsItemRequirements(minion))
                    {
                        candidates.Add(task);
                    }
                }
            }

            // sort by distance to minion
            candidates.Sort(new TaskComparer(minion));

            // assign first task that is pathable
            foreach (MinionTask task in candidates)
            {
                if (task.setOwner(minion))
                {
                    minion.currentTask = task;
                    inProgressTasks.Add(task, true);
                    tasks.Remove(task);
                    return(true);
                }
            }

            return(false);
        }
        private void spawnMinionsForPlanting(GameLocation location, StardewValley.Farmer who, int seedIndex, ref int numSeeds, int fertilizerIndex, ref int numFertilizer)
        {
            const int sprinklersPerMinion = 15;

            Stopwatch sw = new Stopwatch();

            sw.Start();

            // clear previous tasks
            SkeletalMinionsMod.taskPool.clearTasks(location,
                                                   new List <string>
            {
                nameof(PlantingMinionTask)
            });

            // find all eligible sprinklers
            List <SprinklerInfo> sprinklers = findAllSprinklers(location);

            int numSkeletons = sprinklers.Count / sprinklersPerMinion;

            if (numSkeletons == 0)
            {
                numSkeletons = 1;
            }

            int totalSeedCount       = numSeeds;
            int totalFertilizerCount = numFertilizer;

            // create tasks from sprinklers
            foreach (SprinklerInfo sprinkler in sprinklers)
            {
                PlantingMinionTask task = new PlantingMinionTask(location, sprinkler.position, sprinkler.type, sprinkler.seedsRequired, seedIndex, fertilizerIndex);
                SkeletalMinionsMod.taskPool.addTask(task);
            }

            List <Point> spawnPoints = findNearestSpawnLocations(who.getTileLocationPoint(), location, (uint)numSkeletons);

            // spawn skeletons
            for (int i = 0; i < spawnPoints.Count; ++i)
            {
                SkeletalMinion minion = new SkeletalMinion(new Vector2(spawnPoints[i].X, spawnPoints[i].Y) * Game1.tileSize, location, who, SkeletalMinionsMod.taskPool, new List <string> {
                    nameof(PlantingMinionTask)
                });

                int seedsToAdd      = Math.Min(totalSeedCount / numSkeletons, numSeeds);
                int fertilizerToAdd = Math.Min(totalFertilizerCount / numSkeletons, numFertilizer);

                numSeeds      -= seedsToAdd;
                numFertilizer -= fertilizerToAdd;

                if (seedsToAdd > 0)
                {
                    minion.addItemToInventory(new StardewValley.Object(seedIndex, seedsToAdd));
                }
                if (fertilizerToAdd > 0)
                {
                    minion.addItemToInventory(new StardewValley.Object(fertilizerIndex, fertilizerToAdd));
                }

                location.characters.Add(minion);
                Utility.drawLightningBolt(new Vector2(spawnPoints[i].X * Game1.tileSize, spawnPoints[i].Y * Game1.tileSize), location);
            }
            sw.Stop();
            SkeletalMinionsMod.mod.Monitor.Log($"Spawning (planting) minions took {sw.ElapsedMilliseconds} ms.");
        }
 public TaskComparer(SkeletalMinion minion) => this.minion = minion;