示例#1
0
        public bool TryFindMessage(out EmailMessageDef message)
        {
            message = null;

            List <EmailMessageDef> messages = DefDatabase <EmailMessageDef> .AllDefsListForReading;
            List <EmailMessageDef> toSend   = new List <EmailMessageDef>();

            int ticksGame = Find.TickManager.TicksGame;

            for (int i = 0; i < messages.Count; i++)
            {
                EmailMessageDef def = messages[i];

                if (GenDate.DaysPassed < def.EarliestDay)
                {
                    continue;
                }

                if (lastSendedMessages.TryGetValue(def, out int value))
                {
                    float num = (float)(ticksGame - value) / 60000f;
                    if (num < def.MinRefiredDays)
                    {
                        continue;
                    }
                }

                if (def.StaticFaction == null && !TryGetFaction(def.SenderAvaliable, def.MinReqGoodWill, out Faction faction))
                {
                    continue;
                }

                if (def.MessageWorker != null && !def.MessageWorker.CanReceiveNow())
                {
                    continue;
                }

                toSend.Add(def);
            }

            if (toSend.Count == 0)
            {
                return(false);
            }

            if (toSend.TryRandomElementByWeight(w => w.Commonality, out message))
            {
                return(true);
            }

            return(false);
        }
示例#2
0
        public bool TrySendMessage(EmailMessageDef msg)
        {
            EmailBox playerBox = QuestsManager.Communications.PlayerBox;

            Faction faction = null;

            if (msg.StaticFaction != null)
            {
                if (!TryGetFactionWithFilter(msg.SenderAvaliable, msg.MinReqGoodWill, msg.StaticFaction, out faction))
                {
                    return(false);
                }
            }
            else
            {
                if (!TryGetFaction(msg.SenderAvaliable, msg.MinReqGoodWill, out faction))
                {
                    return(false);
                }
            }

            if (faction != null)
            {
                EmailMessage message = playerBox.FormMessageFrom(faction, msg.EmailText, msg.Subject);
                message.Answers = msg.Options;

                bool canSend = true;
                if (msg.MessageWorker != null)
                {
                    canSend = msg.MessageWorker.PreReceived(message, playerBox);
                }

                if (canSend)
                {
                    playerBox.SendMessage(message);

                    msg.MessageWorker?.OnReceived(message, playerBox);

                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            return(false);
        }