public void PrioritizeJob(Job job) { AbandonJob(false); World.Current.jobQueue.Remove(job); job.IsBeingWorked = true; /*Check if the character is carrying any materials and if they could be used for the new job, * if the character is carrying materials but is not used in the new job, then drop them * on the current tile for now.*/ if (inventory != null && !job.inventoryRequirements.ContainsKey(inventory.ObjectType)) { World.Current.inventoryManager.PlaceInventory(CurrTile, inventory); DumpExcessInventory(); } MyJob = job; // Get our destination from the job. DestTile = MyJob.tile; // If the destination tile does not have neighbours that are walkable it's very likable that they can't be walked to. if (DestTile.HasWalkableNeighbours() == false) { Debug.ULogChannel("Character", "No neighbouring floor tiles! Abandoning job."); AbandonJob(false); return; } MyJob.OnJobStopped += OnJobStopped; pathAStar = new Path_AStar(World.Current, CurrTile, DestTile); if (pathAStar != null && pathAStar.Length() == 0) { Debug.ULogChannel("Character", "Path_AStar returned no path to target job tile!"); AbandonJob(false); return; } if (MyJob.adjacent) { IEnumerable <Tile> reversed = pathAStar.Reverse(); reversed = reversed.Skip(1); pathAStar = new Path_AStar(new Queue <Tile>(reversed.Reverse())); DestTile = pathAStar.EndTile(); jobTile = DestTile; } else { jobTile = MyJob.tile; } }
private void GetNewJob() { float needPercent = 0; Need need = null; foreach (Need n in needs) { if (n.Amount > needPercent) { need = n; needPercent = n.Amount; } } if (needPercent > 50 && needPercent < 100 && need.RestoreNeedFurn != null) { if (World.Current.CountFurnitureType(need.RestoreNeedFurn.ObjectType) > 0) { MyJob = new Job(null, need.RestoreNeedFurn.ObjectType, need.CompleteJobNorm, need.RestoreNeedTime, null, Job.JobPriority.High, false, true, false); } } if (needPercent == 100 && need != null && need.CompleteOnFail) { MyJob = new Job(CurrTile, null, need.CompleteJobCrit, need.RestoreNeedTime * 10, null, Job.JobPriority.High, false, true, true); } // Get the first job on the queue. if (MyJob == null) { MyJob = World.Current.jobQueue.Dequeue(); // Check if we got a job from the queue. if (MyJob == null) { Debug.ULogChannel("Character", name + " did not find a job."); MyJob = new Job( CurrTile, "Waiting", null, UnityEngine.Random.Range(0.1f, 0.5f), null, Job.JobPriority.Low, false); MyJob.JobDescription = "job_waiting_desc"; } else { if (MyJob.tile == null) { Debug.ULogChannel("Character", name + " found a job."); } else { Debug.ULogChannel("Character", name + " found a job at x " + MyJob.tile.X + " y " + MyJob.tile.Y + "."); } } } // Get our destination from the job. DestTile = MyJob.tile; // If the destination tile does not have neighbours that are walkable it's very likely that they can't be walked to if (DestTile != null) { if (DestTile.HasWalkableNeighbours() == false) { Debug.ULogChannel("Character", "No neighbouring floor tiles! Abandoning job."); AbandonJob(false); return; } } MyJob.OnJobStopped += OnJobStopped; // Immediately check to see if the job tile is reachable. // NOTE: We might not be pathing to it right away (due to // requiring materials), but we still need to verify that the // final location can be reached. Profiler.BeginSample("PathGeneration"); if (MyJob.IsNeed) { // This will calculate a path from current tile to destination tile. pathAStar = new Path_AStar(World.Current, CurrTile, DestTile, need.RestoreNeedFurn.ObjectType, 0, false, true); } else { pathAStar = new Path_AStar(World.Current, CurrTile, DestTile); } Profiler.EndSample(); if (pathAStar != null && pathAStar.Length() == 0) { Debug.ULogChannel("Character", "Path_AStar returned no path to target job tile!"); AbandonJob(false); return; } if (MyJob.adjacent) { IEnumerable <Tile> reversed = pathAStar.Reverse(); reversed = reversed.Skip(1); pathAStar = new Path_AStar(new Queue <Tile>(reversed.Reverse())); DestTile = pathAStar.EndTile(); jobTile = DestTile; } else { jobTile = MyJob.tile; } MyJob.IsBeingWorked = true; }
private void GetNewJob() { float needPercent = 0; Need need = null; foreach (Need n in needs) { if (n.Amount > needPercent) { need = n; needPercent = n.Amount; } } if (needPercent > 50 && needPercent < 100 && need != null) { myJob = new Job(null, need.restoreNeedFurn.objectType, need.CompleteJobNorm, need.restoreNeedTime, null, Job.JobPriority.High, false, true, false); } if (needPercent == 100 && need != null && need.completeOnFail) { myJob = new Job(CurrTile, null, need.CompleteJobCrit, need.restoreNeedTime * 10, null, Job.JobPriority.High, false, true, true); } // Get the first job on the queue. if (myJob == null) { myJob = World.current.jobQueue.Dequeue(); } if (myJob == null) { Debug.Log(name + " did not find a job."); myJob = new Job( CurrTile, "Waiting", null, UnityEngine.Random.Range(0.1f, 0.5f), null, Job.JobPriority.Low, false); } else { if (myJob.tile == null) { Debug.Log(name + " found a job."); } else { Debug.Log(name + " found a job at x " + myJob.tile.X + " y " + myJob.tile.Y + "."); } } // Get our destination from the job DestTile = myJob.tile; // If the dest tile does not have neighbours it's very if ((DestTile == null || DestTile.HasNeighboursOfType(TileType.Floor) || DestTile.HasNeighboursOfType(TileType.Ladder)) == false) { Debug.Log("No neighbouring floor tiles! Abandoning job."); AbandonJob(false); return; } myJob.cbJobStopped += OnJobStopped; // Immediately check to see if the job tile is reachable. // NOTE: We might not be pathing to it right away (due to // requiring materials), but we still need to verify that the // final location can be reached. Profiler.BeginSample("PathGeneration"); if (myJob.isNeed) { pathAStar = new Path_AStar(World.current, CurrTile, DestTile, need.restoreNeedFurn.objectType, 0, false, true); // This will calculate a path from curr to dest. } else { pathAStar = new Path_AStar(World.current, CurrTile, DestTile); } Profiler.EndSample(); if (pathAStar != null && pathAStar.Length() == 0) { Debug.Log("Path_AStar returned no path to target job tile!"); AbandonJob(false); return; } if (myJob.adjacent) { IEnumerable <Tile> reversed = pathAStar.Reverse(); reversed = reversed.Skip(1); pathAStar = new Path_AStar(new Queue <Tile>(reversed.Reverse())); DestTile = pathAStar.EndTile(); jobTile = DestTile; } else { jobTile = myJob.tile; } }