public override IEnumerable <FiringIncident> MakeIntervalIncidents(IIncidentTarget target)
        {
            if (VoteHandler.voteActive)
            {
                yield break;
            }
            float mtbNow = this.Props.mtbDays;
            IEnumerable <IncidentDef> options;
            List <IncidentDef>        pickedoptions = new List <IncidentDef>();

            if (this.Props.mtbDaysFactorByDaysPassedCurve != null)
            {
                mtbNow *= this.Props.mtbDaysFactorByDaysPassedCurve.Evaluate(GenDate.DaysPassedFloat);
            }
            if (Rand.MTBEventOccurs(mtbNow, 60000f, 1000f))
            {
                IncidentDef selectedDef;
                options = base.UsableIncidentsInCategory(this.Props.category, target);
                Helper.Log("Trying to create events");
                if (options.TryRandomElementByWeight(new Func <IncidentDef, float>(base.IncidentChanceFinal), out selectedDef))
                {
                    if (options.Count() > ToolkitSettings.VoteOptions)
                    {
                        options = options.Where(k => k != selectedDef);
                        pickedoptions.Add(selectedDef);
                        for (int x = 0; x < ToolkitSettings.VoteOptions - 1 && x < options.Count(); x++)
                        {
                            options.TryRandomElementByWeight(new Func <IncidentDef, float>(base.IncidentChanceFinal), out IncidentDef picked);
                            if (picked != null)
                            {
                                options = options.Where(k => k != picked);
                                pickedoptions.Add(picked);
                            }
                        }

                        Dictionary <int, IncidentDef> incidents = new Dictionary <int, IncidentDef>();
                        for (int i = 0; i < pickedoptions.Count(); i++)
                        {
                            incidents.Add(i, pickedoptions.ToList()[i]);
                        }
                        VoteHandler.QueueVote(new VoteIncidentDef(incidents, this, this.GenerateParms(selectedDef.category, target)));
                        Helper.Log("Events created");
                        yield break;
                    }
                    else if (options.Count() == 1)
                    {
                        yield return(new FiringIncident(selectedDef, this, this.GenerateParms(selectedDef.category, target)));
                    }

                    yield return(new FiringIncident(selectedDef, this, this.GenerateParms(selectedDef.category, target)));
                }
                yield break;
            }
        }
        public override IEnumerable <FiringIncident> MakeIntervalIncidents(IIncidentTarget target)
        {
            voteTracker = Current.Game.GetComponent <StoryTellerVoteTracker>();

            if (!VoteHandler.voteActive &&
                Rand.MTBEventOccurs(ToolkitSettings.ToryTalkerMTBDays, 60000f, 1000f))
            {
                List <VotingIncidentEntry> entries = VotingIncidentsByWeight();
                List <VotingIncidentEntry> winners = new List <VotingIncidentEntry>();

                for (int i = 0; i < ToolkitSettings.VoteOptions && i < 12; i++)
                {
                    winners.Add(
                        entries.Where(s =>
                                      !winners.Contains(s)
                                      ).RandomElementByWeight(
                            (VotingIncidentEntry vi) => vi.weight)
                        );

                    int index = Math.Max(winners.Count - 1, 0);

                    winners[index].incident.helper        = VotingIncidentMaker.makeVotingHelper(winners[index].incident);
                    winners[index].incident.helper.target = target;

                    if (!winners[index].incident.helper.IsPossible())
                    {
                        entries.RemoveAt(i);
                        i--;
                        winners.RemoveAt(index);
                    }
                }

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

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

                StorytellerPack pack = DefDatabase <StorytellerPack> .GetNamed("ToryTalker");

                VoteHandler.QueueVote(new Vote_ToryTalker(incidents, pack, "Which event should happen next?"));
            }

            yield break;
        }
示例#3
0
        public override IEnumerable <FiringIncident> MakeIntervalIncidents(IIncidentTarget target)
        {
            if (VoteHandler.voteActive || !Rand.MTBEventOccurs(ToolkitSettings.UristBotMTBDays, 60000f, 1000f))
            {
                yield break;
            }

            IncidentWorker worker = new IncidentWorker_RaidEnemy();
            IncidentParms  parms  = StorytellerUtility.DefaultParmsNow(IncidentCategoryDefOf.ThreatSmall, target);

            worker.def            = IncidentDefOf.RaidEnemy;
            parms.points          = StorytellerUtility.DefaultThreatPointsNow(target);
            parms.raidStrategy    = RaidStrategyDefOf.ImmediateAttack;
            parms.raidArrivalMode = PawnsArrivalModeDefOf.EdgeWalkIn;

            if (!worker.CanFireNow(parms))
            {
                yield break;
            }

            int choice = Rand.Range(0, 0);

            switch (choice)
            {
            case 0:
                parms.faction = Find.FactionManager.RandomEnemyFaction(false, false, false);

                Dictionary <int, RaidStrategyDef> allStrategies = new Dictionary <int, RaidStrategyDef>();

                List <RaidStrategyDef> raidStrategyDefs = new List <RaidStrategyDef>(DefDatabase <RaidStrategyDef> .AllDefs);

                raidStrategyDefs.Shuffle();

                foreach (RaidStrategyDef strat in raidStrategyDefs)
                {
                    allStrategies.Add(allStrategies.Count, strat);
                }

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

                VoteHandler.QueueVote(new Vote_RaidStrategy(allStrategies, named, worker, this, parms, "How should the next raiders attack?"));

                break;
            }
        }
        private void GenerateVotesFromDefs(List <IncidentDef> defs, IncidentParms parms)
        {
            if (defs != null && defs.Count() > 2)
            {
                defs.Shuffle();
                Dictionary <int, IncidentDef> incidents = new Dictionary <int, IncidentDef>();

                for (int i = 0; i < defs.Count; i++)
                {
                    incidents.Add(i, defs[i]);
                }

                VoteHandler.QueueVote(new Vote_Mercurius(incidents, this, parms, "Which Event should happen next?"));
            }
            else
            {
                Log.Error("Only generated " + defs.Count + " incidents");
            }
        }
示例#5
0
        public override IEnumerable <FiringIncident> MakeIntervalIncidents(IIncidentTarget target)
        {
            List <IncidentCategoryDef> triedCategories = new List <IncidentCategoryDef>();
            List <IncidentDef>         incidentDefs;

            if (!VoteHandler.voteActive && Rand.MTBEventOccurs(ToolkitSettings.HodlBotMTBDays, 60000f, 1000f))
            {
                while (true)
                {
                    incidentDefs = new List <IncidentDef>();
                    IncidentCategoryDef       category = ChooseRandomCategory(target, triedCategories);
                    IncidentParms             parms    = this.GenerateParms(category, target);
                    IEnumerable <IncidentDef> options  = from d in base.UsableIncidentsInCategory(category, target)
                                                         where d.Worker.CanFireNow(parms) && (!d.NeedsParmsPoints || parms.points >= d.minThreatPoints)
                                                         select d;

                    for (int i = 0; options.Count() > 0 && incidentDefs.Count < ToolkitSettings.VoteOptions && i < 10; i++)
                    {
                        if (!options.TryRandomElementByWeight(new Func <IncidentDef, float>(base.IncidentChanceFinal), out IncidentDef incDef))
                        {
                            triedCategories.Add(category);
                            break;
                        }
                        else
                        {
                            incidentDefs.Add(incDef);
                            options = options.Where(s => s != incDef);
                        }
                    }

                    if (incidentDefs.Count >= 2)
                    {
                        Dictionary <int, IncidentDef> incidents = new Dictionary <int, IncidentDef>();
                        for (int i = 0; i < incidentDefs.Count(); i++)
                        {
                            incidents.Add(i, incidentDefs.ToList()[i]);
                        }
                        VoteHandler.QueueVote(new VoteIncidentDef(incidents, this, parms));
                        yield break;
                    }
                }
            }
        }
示例#6
0
        public override IEnumerable <FiringIncident> MakeIntervalIncidents(IIncidentTarget target)
        {
            if (!VoteHandler.voteActive && Rand.MTBEventOccurs(ToolkitSettings.ToryTalkerMTBDays, 60000f, 1000f))
            {
                List <VotingIncidentEntry> entries = VotingIncidentsByWeight();
                List <VotingIncidentEntry> winners = new List <VotingIncidentEntry>();

                for (int i = 0; i < ToolkitSettings.VoteOptions && i < 12; i++)
                {
                    winners.Add(
                        entries.Where(s =>
                                      !winners.Contains(s)
                                      ).RandomElementByWeight(
                            (VotingIncidentEntry vi) => vi.weight)
                        );

                    int index = Math.Max(winners.Count - 1, 0);

                    winners[index].incident.helper        = VotingIncidentMaker.makeVotingHelper(winners[index].incident);
                    winners[index].incident.helper.target = target;

                    if (!winners[index].incident.helper.IsPossible())
                    {
                        entries.RemoveAt(i);
                        i--;
                        winners.RemoveAt(index);
                    }
                }

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

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

                VoteHandler.QueueVote(new Vote_VotingIncident(incidents));
            }

            yield break;
        }
        public override IEnumerable <FiringIncident> MakeIntervalIncidents(IIncidentTarget target)
        {
            if (VoteHandler.voteActive)
            {
                yield break;
            }

            if (VoteHelper.TimeForEventVote())
            {
                MakeRandomVoteEvent(target);
                yield break;
            }
            if (thread != null)
            {
                thread = new Thread(new ThreadStart(ThreadProc));

                thread.Start();
            }
            else
            {
                if (singleIncident != null)
                {
                    thread.Join();
                    thread = null;
                    yield return(singleIncident);
                }

                if (makeIncidentOptions && incidentOptions != null)
                {
                    thread.Join();
                    thread = null;
                    VoteHandler.QueueVote(incidentOptions);
                }
                Thread.Sleep(0);
                yield break;
            }
            yield break;
        }
示例#8
0
        private FiringIncident GenerateIncident(IIncidentTarget target)
        {
            Helper.Log("Trying OnOffCycle Incident");
            List <IncidentDef> pickedoptions = new List <IncidentDef>();
            IncidentParms      parms         = this.GenerateParms(this.Props.IncidentCategory, target);
            IncidentDef        def2;

            if ((float)GenDate.DaysPassed < this.Props.forceRaidEnemyBeforeDaysPassed)
            {
                if (!IncidentDefOf.RaidEnemy.Worker.CanFireNow(parms, false))
                {
                    return(null);
                }
                def2 = IncidentDefOf.RaidEnemy;
            }
            else if (this.Props.incident != null)
            {
                if (!this.Props.incident.Worker.CanFireNow(parms, false))
                {
                    return(null);
                }
                def2 = this.Props.incident;
            }
            else
            {
                options = from def in base.UsableIncidentsInCategory(this.Props.IncidentCategory, parms)
                          where parms.points >= def.minThreatPoints
                          select def;
                Helper.Log($"Trying OFC Category: ${this.Props.IncidentCategory}");
                if (options.TryRandomElementByWeight(new Func <IncidentDef, float>(base.IncidentChanceFinal), out def2))
                {
                    if (options.Count() > 1)
                    {
                        options = options.Where(k => k != def2);
                        pickedoptions.Add(def2);
                        for (int x = 0; x < ToolkitSettings.VoteOptions - 1 && x < options.Count(); x++)
                        {
                            options.TryRandomElementByWeight(new Func <IncidentDef, float>(base.IncidentChanceFinal), out IncidentDef picked);
                            if (picked != null)
                            {
                                options = options.Where(k => k != picked);
                                pickedoptions.Add(picked);
                            }
                        }

                        Dictionary <int, IncidentDef> incidents = new Dictionary <int, IncidentDef>();
                        for (int i = 0; i < pickedoptions.Count(); i++)
                        {
                            incidents.Add(i, pickedoptions.ToList()[i]);
                        }
                        VoteHandler.QueueVote(new VoteIncidentDef(incidents, this, parms));
                        Helper.Log("Events created");
                        return(null);
                    }
                    else if (options.Count() == 1)
                    {
                        Helper.Log("Firing one incident OFC");
                        return(new FiringIncident(def2, this, parms));
                    }
                }

                return(null);
            }
            return(new FiringIncident(def2, this, parms));
        }
        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));
        }
        public void MakeRandomVoteEvent(IIncidentTarget target)
        {
            Helper.Log("Forcing vote event");
            if (!VoteHandler.voteActive)
            {
                if (ToolkitSettings.TimedStorytelling)
                {
                    bool targetIsRaidBeacon = target.IncidentTargetTags().Contains(IncidentTargetTagDefOf.Map_RaidBeacon);
                    List <IncidentCategoryDef> triedCategories = new List <IncidentCategoryDef>();
                    IncidentDef               incDef;
                    List <IncidentDef>        pickedoptions = new List <IncidentDef>();
                    IEnumerable <IncidentDef> options;

                    IncidentCategoryDef category = this.ChooseRandomCategory(target, triedCategories);
                    Helper.Log($"Trying Category{category}");
                    parms   = this.GenerateParms(category, target);
                    options = from d in base.UsableIncidentsInCategory(category, target)
                              where !d.NeedsParmsPoints || parms.points >= d.minThreatPoints
                              select d;


                    if (options.TryRandomElementByWeight(new Func <IncidentDef, float>(base.IncidentChanceFinal), out incDef))
                    {
                    }
                    triedCategories.Add(category);

                    if (triedCategories.Count >= this.Props.categoryWeights.Count)
                    {
                    }


                    Helper.Log($"Events Possible: {options.Count()}");

                    if (options.Count() > 1)
                    {
                        options = options.Where(k => k != incDef);
                        pickedoptions.Add(incDef);
                        for (int x = 0; x < ToolkitSettings.VoteOptions - 1 && x < options.Count(); x++)
                        {
                            options.TryRandomElementByWeight(new Func <IncidentDef, float>(base.IncidentChanceFinal), out IncidentDef picked);
                            if (picked != null)
                            {
                                options = options.Where(k => k != picked);
                                pickedoptions.Add(picked);
                            }
                        }

                        Dictionary <int, IncidentDef> incidents = new Dictionary <int, IncidentDef>();
                        for (int i = 0; i < pickedoptions.Count(); i++)
                        {
                            incidents.Add(i, pickedoptions.ToList()[i]);
                        }
                        if (incidents.Count > 1)
                        {
                            VoteHandler.QueueVote(new VoteIncidentDef(incidents, this, parms));
                            Helper.Log("Events created");
                        }
                    }
                }
            }
        }