Exemplo n.º 1
0
        private static void Prefix(JobDriver_UseCommsConsole __instance)
        {
            Communication comm = __instance.job.commTarget as Communication;

            if (comm == null)
            {
                return;
            }
            __instance.AddFailCondition(() => !DCMTools.DynamicCommManagerFor(__instance.GetActor().Map).Contains(comm) || !comm.IsAllowedFor(__instance.GetActor()));
        }
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Map map = parms.target as Map;

            if (map == null)
            {
                return(false);
            }

            var availColonists = parms.target.FreeColonistsForStoryteller;

            if (!availColonists.Any())
            {
                return(false);
            }

            var potentialGetTogethers = Find.WorldPawns.AllPawnsAlive.SelectMany
                                            (outsider => GetTogetherersWithOutsider(outsider, availColonists));

            if (!potentialGetTogethers.Any())
            {
                return(false);
            }

            //Using the square of the relation importance
            potentialGetTogethers.TryRandomElementByWeight(gt => {
                float importance = gt.Item1.GetMostImportantRelation(gt.Item2).importance;
                return(importance * importance);
            }, out var chosenGetTogether);

            if (chosenGetTogether == null)
            {
                return(false);
            }

            DCMTools.DynamicCommManagerFor(map).AddCommunicationWithLetter(new Comm_LetsGetTogether_Contact
                                                                               (chosenGetTogether.Item1, chosenGetTogether.Item2)
                                                                           , "GT_IncomingMessage.Title".Translate(), "GT_IncomingMessage.Title".Translate()
                                                                           , LetterDefOf.NeutralEvent, lookAtComms: true
                                                                           , Constants.InitialGuestContactTimeout, removeWhenDisabled: true);
            return(true);
        }
Exemplo n.º 3
0
        static IEnumerable <ICommunicable> ConcatHelper(Pawn pawn, IEnumerable <ICommunicable> options, List <FloatMenuOption> list)
        {
            foreach (Communication comm in DCMTools.DynamicCommManagerFor(pawn.Map).GetCommsFor(pawn))
            {
                if (!comm.IsAllowedFor(pawn, out string disabledReason))
                {
                    list.Add(new FloatMenuOption(comm.GetCallLabel() + " (" + disabledReason.Translate() + ")",
                                                 null, MenuOptionPriority.Default, null, null, 0, null, null));
                }
                else
                {
                    yield return(comm);
                }
            }

            foreach (var opt in options)
            {
                yield return(opt);
            }
        }