public static void SetActiveGoal(IJob job, IPandaNpcGoal npcGoal) { if (!ActiveGoalsByType.TryGetValue(npcGoal.Name, out var goals)) { goals = new List <IPandaNpcGoal>(); ActiveGoalsByType[npcGoal.Name] = goals; } if (!goals.Contains(npcGoal)) { goals.Add(npcGoal); } if (ActiveGoals.TryGetValue(job.Owner, out var goalList)) { if (goalList.TryGetValue(job, out var oldGoal)) { oldGoal.LeavingGoal(); } goalList[job] = npcGoal; } else { goalList = new Dictionary <IJob, IPandaNpcGoal>() { { job, npcGoal } }; ActiveGoals[job.Owner] = goalList; } npcGoal.SetAsGoal(); }
public static bool TryGetActiveGoal(IJob job, out IPandaNpcGoal goal) { if (ActiveGoals.TryGetValue(job.Owner, out var goalList) && goalList.TryGetValue(job, out goal)) { return(true); } goal = default(IPandaNpcGoal); return(false); }
public static void SetGoalAsInactive(IJob job) { if (ActiveGoals.TryGetValue(job.Owner, out var goalList)) { if (goalList.TryGetValue(job, out var goal) && ActiveGoalsByType.TryGetValue(goal.Name, out var goals)) { goals.Remove(goal); } goalList.Remove(job); } }
public void OnTimedUpdate() { List <Colony> found = new List <Colony>(); List <Colony> notFound = new List <Colony>(); foreach (var c in ServerManager.ColonyTracker.ColoniesByID.Values) { if (c != null && ActiveGoals.ContainsKey(c) && !found.Contains(c)) { found.Add(c); } } foreach (var c in ActiveGoals.Keys) { if (!found.Contains(c)) { notFound.Add(c); } } foreach (var n in notFound) { if (ActiveGoals.TryGetValue(n, out var jobGoalDict)) { foreach (var goal in jobGoalDict.Values) { if (ActiveGoalsByType.TryGetValue(goal.Name, out var goalList)) { goalList.Remove(goal); } } } ActiveGoals.Remove(n); } }
public static bool HasGoal(IJob job) { return(ActiveGoals.TryGetValue(job.Owner, out var jobGoals) && jobGoals.ContainsKey(job)); }