public static void RegisterRoamingJobState(Colony colony, RoamingJobState state) { if (colony != null && state != null) { lock (Objectives) { if (!Objectives.ContainsKey(colony)) { Objectives.Add(colony, new Dictionary <string, Dictionary <Vector3Int, RoamingJobState> >()); } if (!Objectives[colony].ContainsKey(state.RoamingJobSettings.ObjectiveCategory)) { Objectives[colony].Add(state.RoamingJobSettings.ObjectiveCategory, new Dictionary <Vector3Int, RoamingJobState>()); } if (state.Position != Vector3Int.invalidPos) { Objectives[colony][state.RoamingJobSettings.ObjectiveCategory][state.Position] = state; } } } }
public override Vector3Int GetJobLocation() { var pos = OriginalPosition; if (NPC != null) { try { if (TargetObjective == null) { RoamingJobState closest = null; float distance = float.MaxValue; foreach (var cat in ObjectiveCategories) { if (RoamingJobManager.Objectives.TryGetValue(Owner, out var roamingJobObjectiveDic) && roamingJobObjectiveDic.TryGetValue(cat, out var states)) { foreach (var objective in states.Values) { if (objective != null && objective != PreviousObjective && objective.PositionIsValid() && objective.JobRef == null) { var dis = UnityEngine.Vector3.Distance(objective.Position.Vector, pos.Vector); if (dis < distance && dis <= objective.RoamingJobSettings.WatchArea) { string actionName = string.Empty; foreach (var actionKvp in objective.ActionEnergy) { if (objective.RoamingJobSettings.ActionCallbacks.TryGetValue(actionKvp.Key, out var objectiveAction) && actionKvp.Value < objectiveAction.ActionEnergyMinForFix) { actionName = actionKvp.Key; break; } } if (!string.IsNullOrEmpty(actionName) && objective.RoamingJobSettings.ActionCallbacks.ContainsKey(actionName)) { closest = objective; distance = dis; } } } } } } if (closest != null) { TargetObjective = closest; TargetObjective.JobRef = this; pos = TargetObjective.Position.GetClosestPositionWithinY(NPC.Position, 5); } } else { pos = TargetObjective.Position.GetClosestPositionWithinY(NPC.Position, 5); } } catch (Exception ex) { APILogger.LogError(ex); } } return(pos); }