/// <summary> /// Check, if the storyteller can use this /// </summary> /// <returns></returns> protected override bool CanFireNowSub(IIncidentTarget target) { Map map = (Map)target; // If MapComponent isn't available, try to add it if (!MapComponent_ColonistsOutsideMap_RumorOf.IsMapComponentAvailable(out mapComponent)) { MapComponent_ColonistsOutsideMap_RumorOf.TryAddMapComponent(); } // Not, if MapComponent isn't available if (!MapComponent_ColonistsOutsideMap_RumorOf.IsMapComponentAvailable(out mapComponent)) { return(false); } if (mapComponent.Active) { return(false); } //IEnumerable<Pawn> friendlies = TryFindFriendlyPawns(); //if (friendlies == null || friendlies.Count() == 0) // return false; return(true); }
protected override IEnumerable <Toil> MakeNewToils() { yield return(Toils_Goto.GotoCell(TargetIndex.A, PathEndMode.OnCell)); // Add pawn to MapComponent Toil arrival = new Toil(); arrival.initAction = () => { MapComponent_ColonistsOutsideMap_RumorOf mc; if (!MapComponent_ColonistsOutsideMap_RumorOf.IsMapComponentAvailable(out mc)) { return; } mc.ExitMapCell = TargetA.Cell; mc.PawnsOutOfMap.Add(pawn); pawn.DeSpawn(); }; arrival.defaultCompleteMode = ToilCompleteMode.Instant; yield return(arrival); }
public override bool TryExecute(IncidentParms parms) { // Do nothing, if MapComponent isn't available if (!MapComponent_ColonistsOutsideMap_RumorOf.IsMapComponentAvailable(out mapComponent)) { return(false); } Map map = parms.target as Map; if (map == null) { return(false); } // Reinit a new story mapComponent.def = null; mapComponent.DoUpdateDef(); // Set a new travel time mapComponent.SetNewTravelTime(); IEnumerable <Pawn> friendlies = TryFindFriendlyPawns(map); //if (friendlies == null || friendlies.Count() == 0) // return false; if (friendlies == null || friendlies.Count() == 0) { return(TryExecuteVisitorsAndRestartSelf(parms)); } Pawn pawnTellingRumor = friendlies.RandomElement(); IntVec3 exitMapCell; Predicate <IntVec3> predicate = (IntVec3 c) => { if (!c.Standable(map) || !map.reachability.CanReachColony(c)) { return(false); } return(true); }; if (!CellFinder.TryFindRandomEdgeCellWith(predicate, map, out exitMapCell)) { return(false); } // Create initial selection dialog string str = mapComponent.def.InitialMessageVariable.Translate(new object[] { pawnTellingRumor.Name.ToStringFull, pawnTellingRumor.Faction.ToString() }); DiaNode diaNode = new DiaNode(str.AdjustedFor(pawnTellingRumor)); DiaOption diaOption = new DiaOption(mapComponent.def.InitialMessageButtonAcceptVariable.Translate()) { action = () => { mapComponent.ExitMapCell = exitMapCell; mapComponent.IncidentPoints = parms.points; // Create colonists selection dialog Dialog_RumorOf_AssignColonists.CreateColonistSelectionDialog(); }, resolveTree = true }; diaNode.options.Add(diaOption); string str1 = mapComponent.def.InitialMessageRejectedVariable.Translate(new object[] { pawnTellingRumor.NameStringShort }); DiaNode diaNode1 = new DiaNode(str1.AdjustedFor(pawnTellingRumor)); DiaOption diaOption1 = new DiaOption("OK".Translate()) { resolveTree = true }; diaNode1.options.Add(diaOption1); DiaOption diaOption2 = new DiaOption(mapComponent.def.InitialMessageButtonRejectVariable.Translate()) { link = diaNode1 }; diaNode.options.Add(diaOption2); Find.WindowStack.Add(new Dialog_NodeTree(diaNode)); return(true); }
public override void DoWindowContents(Rect inRect) { if (!MapComponent_ColonistsOutsideMap_RumorOf.IsMapComponentAvailable(out mc)) { base.Close(); return; } List <Pawn> validPawns = new List <Pawn>(Find.MapPawns.FreeColonistsSpawned.Where <Pawn>(p => p != null && !p.Destroyed && !p.Downed)); if (validPawns == null || validPawns.Count == 0) { base.Close(); return; } Text.Font = GameFont.Small; Rect rectData = new Rect(inRect) { yMin = inRect.yMin + 50f, yMax = inRect.yMax - 75f }; float single = 32f; Rect rectHeader = new Rect(0f, 0f, inRect.width * 0.8f, 60f); Widgets.Label(rectHeader, mc.def.SelectPawnsMessageVariable.Translate(new object[] { Mathf.CeilToInt(mc.TraveltimeInDays).ToString() })); Rect rectScroll = new Rect(0f, single, inRect.width - 16f, (float)validPawns.Count * 35f + 100f); // Start Scrollview Widgets.BeginScrollView(rectData, ref this.scrollPosition, rectScroll); for (int i = 0; i < validPawns.Count; i++) { Pawn pawn = validPawns[i]; Rect rect2 = new Rect(0f, single, rectScroll.width * 0.6f, 32f); // Make label per colonist Widgets.Label(rect2, pawn.LabelCap); rect2.x = rect2.xMax; rect2.width = rectScroll.width * 0.4f; if (!pawnsToSend.Contains(pawn)) { // Make button per colonist if (!Widgets.ButtonText(rect2, mc.def.SelectPawnsMessage_ButtonAssignVariable.Translate(), true, false)) { // Normal operation single = single + 35f; } else { // Button was pressed if (pawnsToSend.Count + 1 >= validPawns.Count) { // Don't add, throw message Messages.Message(mc.def.SelectPawnsMessage_ButtonAssignErrorVariable.Translate(), MessageSound.RejectInput); } else { // Add to list pawnsToSend.Add(pawn); } } } else { if (!Widgets.ButtonText(rect2, mc.def.SelectPawnsMessage_ButtonUnassignVariable.Translate(), true, false)) { // Normal operation single = single + 35f; } else { // Button was pressed pawnsToSend.Remove(pawn); } } } Widgets.EndScrollView(); mc.DialogDelayActive = true; mc.DialogDelayTicks = GenDate.TicksPerHour * 2; // Close button Vector2 butAbortSize = new Vector2(140f, 40f); // 60px smaller than the send button Text.Font = GameFont.Small; Rect rectAbortBut = new Rect((inRect.width / 3f) - (inRect.width / 6f) - (butAbortSize.x / 2f) - 5f, inRect.height - 55f, butAbortSize.x, butAbortSize.y); if (Widgets.ButtonText(rectAbortBut, mc.def.SelectPawnsMessage_ButtonAbortVariable.Translate(), true, false)) { mc.DialogDelayActive = false; mc.DialogDelayTicks = -1; //mc.def = null; Close(true); Event.current.Use(); } // Prepare button Vector2 butPrepareSize = new Vector2(140f, 40f); // 60px smaller than the send button Text.Font = GameFont.Small; Rect rectPrepareBut = new Rect((inRect.width / 3) + (inRect.width / 6f) - (butPrepareSize.x / 2f) - 25f, inRect.height - 55f, butPrepareSize.x, butPrepareSize.y); if (Widgets.ButtonText(rectPrepareBut, mc.def.SelectPawnsMessage_ButtonPostponeVariable.Translate(), true, false)) { mc.DialogDelayActive = true; mc.DialogDelayTicks = -1; Close(true); Event.current.Use(); } // SendColonists button Vector2 butSendSize = new Vector2(200f, 40f); Rect rectSendBut = new Rect((inRect.width / 3) * 2 + (inRect.width / 6f) - (butSendSize.x / 2f) - 15f, inRect.height - 55f, butSendSize.x, butSendSize.y); if (Widgets.ButtonText(rectSendBut, mc.def.SelectPawnsMessage_ButtonSendVariable.Translate(), true, false)) { if (pawnsToSend.Count == 0) { // Don't add, throw message Messages.Message(mc.def.SelectPawnsMessage_ButtonSendErrorVariable.Translate(), MessageSound.RejectInput); } else { mc.DialogDelayActive = false; mc.DialogDelayTicks = -1; SendSelectedTeam(); Close(true); Event.current.Use(); } } }