Esempio n. 1
0
 public void StartVote(VoteEvent next)
 {
     Helper.Log("Attemping vote start");
     _timer.Stop();
     _currentVote    = next;
     _eventsPossible = _currentVote.options;
     _votingStage    = 0;
     _timer_Elapsed(null, null);
 }
Esempio n. 2
0
        public override IEnumerable <FiringIncident> MakeIntervalIncidents(IIncidentTarget target)
        {
            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() > Settings.VoteOptions)
                    {
                        options = options.Where(k => k != selectedDef);
                        pickedoptions.Add(selectedDef);
                        for (int x = 0; x < (Settings.VoteOptions > options.Count() ? options.Count() - 1 : Settings.VoteOptions - 1); x++)
                        {
                            options.TryRandomElementByWeight(new Func <IncidentDef, float>(base.IncidentChanceFinal), out IncidentDef picked);
                            if (picked != null)
                            {
                                options = options.Where(k => k != picked);
                                pickedoptions.Add(picked);
                            }
                        }

                        VoteEvent evt = new VoteEvent(pickedoptions, this, this.GenerateParms(selectedDef.category, target));
                        Ticker.VoteEvents.Enqueue(evt);
                        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;
            }
        }
        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 < (Settings.VoteOptions > options.Count() ? options.Count() - 1 : Settings.VoteOptions - 1); x++)
                        {
                            options.TryRandomElementByWeight(new Func <IncidentDef, float>(base.IncidentChanceFinal), out IncidentDef picked);
                            if (picked != null)
                            {
                                options = options.Where(k => k != picked);
                                pickedoptions.Add(picked);
                            }
                        }

                        VoteEvent evt = new VoteEvent(pickedoptions, this, parms);
                        Ticker.VoteEvents.Enqueue(evt);
                        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 (Rand.MTBEventOccurs(this.Props.mtbDays, 60000f, 1000f))
            {
                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;
                for (; ;)
                {
                    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))
                    {
                        break;
                    }
                    triedCategories.Add(category);
                    if (triedCategories.Count >= this.Props.categoryWeights.Count)
                    {
                        goto Block_6;
                    }
                }

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

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

                    VoteEvent evt = new VoteEvent(pickedoptions, this, parms);
                    Ticker.VoteEvents.Enqueue(evt);
                    Helper.Log("Events created");
                    yield break;
                }
                else if (options.Count() == 1)
                {
                    yield return(new FiringIncident(incDef, this, parms));
                }

                if (!this.Props.skipThreatBigIfRaidBeacon || !targetIsRaidBeacon || incDef.category != IncidentCategoryDefOf.ThreatBig)
                {
                    // yield return new FiringIncident(incDef, this, parms);
                    // _twitchstories.StartVote(options, this, parms);
                }
                Block_6 :;
            }
            yield break;
        }