public void AddObjective(ObjectiveDef objective) { if (!objectives.Contains(objective)) { objectives.Add(objective); } }
public MOState GetObjectiveState(ObjectiveDef def) { Objective objective = null; Missions.Find(m => (objective = m.objectives.Find(o => o.def == def)) != null); return(objective?.CurrentState ?? MOState.Inactive); }
public Objective GetObjective(ObjectiveDef def) { Objective objective = null; Missions.Find(m => (objective = m.objectives.Find(o => o.def == def)) != null); return(objective); }
public void CheckForDuplicates(ObjectiveDef def) { List <ThingDef> defList = new List <ThingDef>(); List <PawnKindDef> pawnList = new List <PawnKindDef>(); foreach (ThingValue tv in targets) { if (tv.PawnKindDef == null || tv.ThingDef == null) { if (tv.ThingDef == null) { Log.Error("Error in " + def.defName + ": defName '" + tv.defName + "' does not exist."); } } if (tv.IsPawnKindDef && !pawnList.Contains(tv.PawnKindDef)) { pawnList.Add(tv.PawnKindDef); } else if (!defList.Contains(tv.ThingDef)) { defList.Add(tv.ThingDef); } else if (defList.Contains(tv.ThingDef) || pawnList.Contains(tv.PawnKindDef)) { Log.Error("targetList in TargetSettings of " + def.defName + " contains unnecessary duplicate defs named '" + tv.defName + "'. Use the value to adjust the amount."); } } }
public void MakeObjective(ObjectiveDef def) { Type type = def.customClass; Objective objective = (Objective)Activator.CreateInstance(type); objective.def = def; objective.SetUp(this); objectives.Add(objective); }
public static ObjectiveStation Station(this List <ObjectiveStation> list, ObjectiveDef objective = null, Thing thing = null) { foreach (ObjectiveStation station in list) { if (station.objectives.Contains(objective) || station.station == thing) { return(station); } } return(null); }
public void Notify_Execute(Map map, TargetInfo target, ObjectiveDef def, IncidentCondition?condition) { target = target.Thing ?? map.PlayerPawnsForStoryteller.RandomElement(); if (Worker != null) { Worker.def = DefDatabase <IncidentDef> .AllDefs.First(i => i.workerClass == Worker.GetType()) ?? new IncidentDef(); if (Worker.def.tale == null) { Worker.def.tale = tale; } Worker.TryExecute(IncidentParms(map, target)); return; } TryExecute(map, IncidentParms(map, target), def, condition); }
private string ResolveTargetLabel(ObjectiveDef def) { string label = def.customSettings?.shortLabel; List <ThingValue> targets = def.targetSettings?.targets; bool any = def.targetSettings?.any ?? false || def.type == ObjectiveType.Research; bool multi = targets?.Count > 1 && !any && def.type != ObjectiveType.Research; bool travel = def.type == ObjectiveType.Travel; string pre = ("Req" + def.type.ToString() + (travel ? def.travelSettings.mode.ToString() : "") + (multi ? "Plural" : "") + "_SMO"); if (pre.CanTranslate()) { if (label.NullOrEmpty()) { label += pre.Translate(); } if (!targets.NullOrEmpty()) { switch (def.type) { case ObjectiveType.Research: label += multi ? "" : ": " + def.BestPotentialStation.LabelCap; break; case ObjectiveType.ConstructOrCraft: break; case ObjectiveType.Own: break; case ObjectiveType.Recruit: break; case ObjectiveType.Destroy: break; case ObjectiveType.Kill: break; } } } return(label); }
private void TrySetDiaShow(ObjectiveDef objective) { if (!cachedImages.TryGetValue(objective, out List <Texture2D> textures)) { cachedImages.Clear(); currentImage = 0; List <Texture2D> list = new List <Texture2D>(); foreach (string s in objective.images) { Texture2D image = ContentFinder <Texture2D> .Get(s, false); if (image != null) { list.Add(image); } } if (!list.NullOrEmpty()) { cachedImages.Add(objective, list); } } }
public Mission GetMission(ObjectiveDef def) { return(Missions.Find(m => m.objectives.Any(o => o.def == def))); }
public Objective ObjectiveByDef(ObjectiveDef def) { return(objectives.Find(o => o.def == def)); }
private void DrawObjectiveTab(Rect TabRect, Objective objective, int num) { if (num % 2 == 0) { Widgets.DrawBoxSolid(TabRect, new ColorInt(50, 50, 50).ToColor); } //Setup ObjectiveDef Def = objective.def; TabRect = TabRect.ContractedBy(5f); GUI.BeginGroup(TabRect); //Label string Label = Def.LabelCap; Vector2 LabelSize = Text.CalcSize(Label); Rect LabelRect = new Rect(new Vector2(0f, 0f), LabelSize); Widgets.Label(LabelRect, Label); //Target string TargetLabel = ResolveTargetLabel(Def); Vector2 TargetSize = Text.CalcSize(TargetLabel); Rect TargetRect = new Rect(new Vector2(0f, TabRect.height - TargetSize.y), TargetSize); Rect InfoCardRect = new Rect(TargetLabel.NullOrEmpty() ? -5f : TargetRect.xMax, TargetRect.y, TargetRect.height, TargetRect.height); if (!TargetLabel.NullOrEmpty()) { bool MouseOver = Mouse.IsOver(TargetRect); GUI.color = MouseOver ? new Color(0.8f, 0.8f, 0.8f) : new Color(0.6f, 0.6f, 0.6f); Widgets.Label(TargetRect, TargetLabel); GUI.color = Color.white; } Rect InfoCardAreaRect = new Rect(TargetRect.x, TargetRect.y, TargetRect.width + InfoCardRect.width, TargetRect.height); TooltipHandler.TipRegion(InfoCardAreaRect, "InfoCard_SMO".Translate()); if (Widgets.ButtonInvisible(TargetRect) || Widgets.ButtonImage(InfoCardRect, StoryMats.info2, GUI.color)) { Find.WindowStack.Add(CurObjectiveInfo = new Dialog_ObjectiveInformation(objective)); } UIHighlighter.HighlightOpportunity(InfoCardRect, "InfoCard"); //ProgressBar Vector2 size = new Vector2(90f, 20f); Rect BarRect = new Rect(); Rect BotBarRect = new Rect(); ResolveBarInputs(objective, out float pct, out string label, out Texture2D material); if (material != null) { BarRect = new Rect(new Vector2(TabRect.xMax - (size.x + 5f), 0f), size); DrawProgressBar(BarRect, label, pct, material); if (objective.thingTracker?.ResolveButtonInput(BarRect) ?? false) { TooltipHandler.TipRegion(BarRect, "BarInput_SMO".Translate()); } } if (objective.def.timer.GetTotalTime > 0) { BotBarRect = new Rect(new Vector2(TabRect.xMax - (size.x + 5f), TabRect.height - (size.y + 5f)), size); float timer = objective.GetTimer; pct = timer / objective.def.timer.GetTotalTime; label = StoryUtils.GetTimerText(objective.GetTimer, objective.CurrentState); if (objective.CurrentState == MOState.Finished) { pct = 0f; } DrawProgressBar(BotBarRect, label, pct, StoryMats.grey); } //SkillRequirements Rect SkillRequirementRect = new Rect(); if (objective.def.skillRequirements.Count > 0) { bool check = BarRect.width + BotBarRect.width > 0f; SkillRequirementRect = new Rect(TabRect.xMax - (10f + (check ? 180f : 90f)), 0f, 90f, TabRect.height); bool MouseOver = Mouse.IsOver(SkillRequirementRect); GUI.color = MouseOver ? new Color(0.8f, 0.8f, 0.8f) : new Color(0.6f, 0.6f, 0.6f); Text.Anchor = TextAnchor.UpperCenter; Text.Font = GameFont.Medium; int count = 0; if (cachedPawns.TryGetValue(objective.def, out List <Pawn> pawns)) { if (!pawns.NullOrEmpty()) { count = pawns.Count; } } Widgets.Label(SkillRequirementRect, count.ToString()); Text.Font = GameFont.Tiny; Text.Anchor = TextAnchor.LowerCenter; Widgets.Label(SkillRequirementRect, count != 1 ? "SkillReqPlural_SMO".Translate() : "SkillReq_SMO".Translate()); Text.Font = GameFont.Small; Text.Anchor = 0; GUI.color = Color.white; StringBuilder sb = new StringBuilder(); if (!pawns.NullOrEmpty()) { foreach (Pawn pawn in pawns) { sb.AppendLine(" - " + pawn.LabelCap); } } StringBuilder sb2 = new StringBuilder(); foreach (SkillRequirement sr in objective.def.skillRequirements) { sb2.AppendLine(" - " + sr.Summary); } TooltipHandler.TipRegion(SkillRequirementRect, pawns.NullOrEmpty() ? "PawnListEmpty_SMO".Translate(sb2) : "PawnList_SMO".Translate(sb)); } GUI.EndGroup(); SkillRequirementRect.x += 5f; SkillRequirementRect.y += 5f + (TabRect.height * num); bool mouseOnSkill = Mouse.IsOver(SkillRequirementRect); if (mouseOnSkill) { List <Pawn> pawns = cachedPawns.TryGetValue(objective.def); foreach (Pawn pawn in pawns) { if (pawn != null) { TargetHighlighter.Highlight(pawn, false, true, false); } } } if (Widgets.ButtonInvisible(TabRect, true)) { if (mouseOnSkill) { Find.Selector.SelectedObjects.Clear(); if (cachedPawns.TryGetValue(objective.def, out List <Pawn> pawns)) { if (!pawns.NullOrEmpty()) { CameraJumper.TryJumpAndSelect(pawns.RandomElement()); this.Close(); } } } SoundDefOf.Click.PlayOneShotOnCamera(null); SelectedObjective = objective; } TabRect = TabRect.ExpandedBy(5f); if (objective.CurrentState == MOState.Failed) { GUI.color = Color.red; Widgets.DrawHighlight(TabRect); GUI.color = Color.white; } bool mouseOver = Mouse.IsOver(TabRect); if (mouseOver || this.SelectedObjective == objective) { GUI.color = mouseOver ? new Color(0.3f, 0.3f, 0.3f) : new Color(0.5f, 0.5f, 0.5f); Widgets.DrawBox(TabRect, 1); GUI.color = Color.white; } }
private void ResolveBarInputs(Objective objective, out float pct, out string label, out Texture2D material) { ObjectiveDef def = objective.def; StringBuilder stringBuilder = new StringBuilder(); pct = 0f; label = ""; material = null; float l = 0, r = 0; bool any = def.targetSettings?.any ?? false; if (def.type == ObjectiveType.Travel) { TravelSettings settings = def.travelSettings; if (settings.mode == TravelMode.Explore || settings.mode == TravelMode.Reach) { return; } pct = (float)(l = objective.travelTracker.CurrentCount) / (float)(r = settings.factionSettings.ValueForMode(settings.mode)); label = l + "/" + r; } if (def.targetSettings != null) { foreach (ThingValue thingValue in def.targetSettings.targets) { stringBuilder.AppendLine(" " + (thingValue.IsPawnKindDef ? thingValue.PawnKindDef.LabelCap : thingValue.ThingDef.LabelCap)); } if (def.type == ObjectiveType.Research) { pct = objective.GetWorkPct; label = Mathf.RoundToInt(objective.GetWorkDone) + "/" + def.workAmount; } else if (def.type == ObjectiveType.ConstructOrCraft || def.type == ObjectiveType.Own || def.type == ObjectiveType.PawnCheck || def.type == ObjectiveType.Recruit || def.type == ObjectiveType.Destroy || def.type == ObjectiveType.Kill) { if (def.targetSettings.pawnSettings != null) { if (objective.CurrentState == MOState.Finished) { pct = 1f; l = r = def.targetSettings.pawnSettings.minAmount; } else { pct = (l = (float)objective.thingTracker.GetTargetCount) / (r = (float)def.targetSettings.pawnSettings.minAmount); } } else if (def.targetSettings.thingSettings != null) { if (objective.CurrentState == MOState.Finished) { pct = 1f; l = r = def.targetSettings.thingSettings.minAmount; } else { pct = (l = (float)objective.thingTracker.GetTargetCount) / (r = (float)def.targetSettings.thingSettings.minAmount); } } else if (!objective.thingTracker.TargetsDone.ToList().NullOrEmpty()) { ThingValue maxValue = objective.thingTracker.TargetsDone.ToList().Find(tv => tv.Value == objective.thingTracker.TargetsDone.Values.Max()).Key; pct = any ? (l = (float)objective.thingTracker.TargetsDone[maxValue]) / (r = (float)def.targetSettings.targets.Find(tv => tv == maxValue).value) : (l = (float)objective.thingTracker.GetTargetCount) / (r = (float)def.targetSettings.targets.Sum(tv => tv.value)); } label = l + "/" + r; } } if (def.customSettings.progressBarColor != null) { material = SolidColorMaterials.NewSolidColorTexture(def.customSettings.progressBarColor.ToColor); } switch (def.type) { case ObjectiveType.Custom: material = StoryMats.grey; break; case ObjectiveType.Research: material = StoryMats.blue; break; case ObjectiveType.ConstructOrCraft: material = StoryMats.orange; break; case ObjectiveType.Destroy: case ObjectiveType.Kill: material = StoryMats.red; break; case ObjectiveType.PawnCheck: case ObjectiveType.Recruit: case ObjectiveType.Own: material = StoryMats.green; break; case ObjectiveType.Travel: material = StoryMats.purple; break; } }
public ObjectiveStation(Thing station, ObjectiveDef objective, bool active) { this.station = station; this.objectives.Add(objective); this.active = active; }
private void TryExecute(Map map, IncidentParms parms, ObjectiveDef def, IncidentCondition?condition) { LookTargets targets = new LookTargets(); string label = ""; string message = ""; if (type == IncidentType.Research) { StringBuilder sb = new StringBuilder(); foreach (ResearchProjectDef project in researchUnlocks) { sb.Append(" - " + project.LabelCap); Find.ResearchManager.FinishProject(project); } label = "ResearchIncident_SMO".Translate(); message = "ResearchIncidentDesc_SMO".Translate(sb.ToString()); } if (type == IncidentType.Reward) { SpawnMode mode = spawnSettings.mode; if (mode == SpawnMode.Target) { SpawnAround(parms.spawnCenter, map, ref targets, out bool p); } if (mode == SpawnMode.Stockpile) { List <Thing> things = SpawnThings(out List <List <Thing> > list, ref targets); List <IntVec3> cells = new List <IntVec3>(); List <Zone> zones = map.zoneManager.AllZones; for (int i = 0; i < zones.Count; i++) { Zone zone = zones[i]; if (zone is Zone_Stockpile) { cells.AddRange(zone.Cells.Where(c => c.GetFirstItem(map) == null)); } } if (cells.Count < things.Count) { IntVec3 cell = IntVec3.Invalid; if (map.areaManager.Home?.ActiveCells.Count() > 0) { PositionFilter filter = new PositionFilter(); filter.homeArea = AreaCheck.Prefer; filter.roofs = AreaCheck.Avoid; cell = filter.FindCell(map, spawnSettings.spawnList); } cell = cell.IsValid ? cell : parms.spawnCenter; DropPodUtility.DropThingGroupsNear(cell, map, list, 140, false, true, true); } else { foreach (Thing thing in things) { IntVec3 cell = cells.RandomElement(); cells.Remove(cell); targets.targets.Add(GenSpawn.Spawn(thing, cells.RandomElement(), map)); } } } if (mode == SpawnMode.DropPod) { SpawnDropPod(parms.spawnCenter, map, ref targets); } if (condition.Value == IncidentCondition.Started) { label = "StartingItems_SMO".Translate(); message = "StartingItemsDesc_SMO".Translate("'" + def.LabelCap + "'"); } if (condition.Value == IncidentCondition.Finished || condition == null) { label = "Reward_SMO".Translate(); if (def != null) { message = "RewardDesc_SMO".Translate("'" + def.LabelCap + "'"); } } } if (type == IncidentType.Appear) { SpawnAround(parms.spawnCenter, map, ref targets, out bool p); label = p ? "AppearPlural_SMO".Translate() : "Appear_SMO".Translate(); message = p ? "AppearDescPlural_SMO".Translate() : "AppearDesc_SMO".Translate(targets); } if (type == IncidentType.Skyfaller) { int count = 0; foreach (ThingSkyfaller skyfaller in spawnSettings.skyfallers) { if (Rand.Chance(skyfaller.chance)) { count++; targets.targets.Add(SkyfallerMaker.SpawnSkyfaller(skyfaller.skyfaller, skyfaller.def, parms.spawnCenter, map)); } } bool plural = count > 1; label = plural ? "Skyfaller_SMO".Translate() : "SkyfallerPlural_SMO".Translate(); message = plural ? "SkyfallerDesc_SMO".Translate() : "SkyfallerDescPlural_SMO".Translate(); } if (type == IncidentType.Raid) { List <Pawn> raiders = new List <Pawn>(); foreach (ThingValue tv in spawnSettings.spawnList) { if (Rand.Chance(tv.chance)) { for (int i = 0; i < tv.value; i++) { Pawn pawn = PawnGenerator.GeneratePawn(tv.PawnKindDef, parms.faction); raiders.Add(pawn); targets.targets.Add(pawn); } } } parms.raidArrivalMode.Worker.Arrive(raiders, parms); parms.raidStrategy.Worker.MakeLords(parms, raiders); Find.StoryWatcher.statsRecord.numRaidsEnemy++; label = "Raid_SMO".Translate(); message = "RaidDesc_SMO".Translate(PawnKinds); } Find.LetterStack.ReceiveLetter(letterLabel ?? label, letterDesc ?? message, letterDef, targets, type == IncidentType.Raid ? Faction : null, null); }