Ejemplo n.º 1
0
 void PickVoteLabelType(VoteLabelType labelType)
 {
     switch (labelType)
     {
     case VoteLabelType.Category:
         if (categoriesThatCanBeMystery.Any(s => s == incidents.ElementAt(0).Value.eventCategory) && Rand.Bool)
         {
             this.labelType = VoteLabelType.Type;
         }
         else
         {
             this.labelType = VoteLabelType.Label;
         }
         break;
     }
 }
Ejemplo n.º 2
0
        public Vote_HodlBot(Dictionary <int, VotingIncident> incidents, StorytellerPack pack, VoteLabelType labelType, string title = null) : base(incidents, title)
        {
            PickVoteLabelType(labelType);

            this.pack  = pack;
            this.title = title;
        }
        public override IEnumerable <FiringIncident> MakeIntervalIncidents(IIncidentTarget target)
        {
            if (VoteHandler.voteActive || !Rand.MTBEventOccurs(ToolkitSettings.HodlBotMTBDays, 60000f, 1000f))
            {
                if (!forced)
                {
                    yield break;
                }
            }

            if (Rand.Range(0, 1) == 1)
            {
                voteType = Vote_VotingIncident.VoteLabelType.Type;
            }

            List <VotingIncidentEntry> source  = VotingIncidentsByWeight();
            List <VotingIncidentEntry> winners = new List <VotingIncidentEntry>();

            string str = null;

            switch (voteType)
            {
            case Vote_VotingIncident.VoteLabelType.Category:
            {
                EventCategory category = RandomCategory();
                source = (from s in source
                          where s.incident.eventCategory == category
                          select s).ToList();
                str = "Which " + category.ToString() + " event should happen?";
                Helper.Log("rand cat picked " + category);
                break;
            }

            case Vote_VotingIncident.VoteLabelType.Type:
            {
                EventType randType = RandomType();
                source = (from s in source
                          where s.incident.eventType == randType
                          select s).ToList();
                str = "Which " + randType + " event should happen?";
                Helper.Log("rand type picked " + randType);
                break;
            }
            }

            for (int i = 0; i < ToolkitSettings.VoteOptions; i++)
            {
                if (GenCollection.TryRandomElementByWeight <VotingIncidentEntry>
                        (from s in source
                        where !winners.Contains(s)
                        select s, (Func <VotingIncidentEntry, float>)((VotingIncidentEntry vi) => vi.weight), out VotingIncidentEntry votingIncidentEntry))
                {
                    votingIncidentEntry.incident.Helper.target = target;

                    if (votingIncidentEntry.incident.Helper.IsPossible())
                    {
                        winners.Add(votingIncidentEntry);
                    }
                }
            }

            if (winners.Count < 3)
            {
                Helper.Log("Less than 3 possible votes were found");
                yield break;
            }

            Dictionary <int, VotingIncident> dictionary = new Dictionary <int, VotingIncident>();

            for (int i = 0; i < winners.Count; i++)
            {
                dictionary.Add(i, winners[i].incident);
            }

            StorytellerPack named = DefDatabase <StorytellerPack> .GetNamed("HodlBot", true);

            VoteHandler.QueueVote(new Vote_HodlBot(dictionary, named, voteType, str));
        }