public override IEnumerable <FiringIncident> MakeIntervalIncidents(IIncidentTarget target)
        {
            if (Rand.MTBEventOccurs(this.Props.mtbDays, 60000f, 1000f))
            {
                List <IncidentCategory>   triedCategories = new List <IncidentCategory>();
                IEnumerable <IncidentDef> options;
                while (true)
                {
                    if (triedCategories.Count >= this.Props.categoryWeights.Count)
                    {
                        break;
                    }
                    IncidentCategory category = this.DecideCategory(target, triedCategories);
                    triedCategories.Add(category);
                    IncidentParms parms = this.GenerateParms(category, target);
                    options = from d in DefDatabase <IncidentDef> .AllDefs
                              where d.category == category && d.Worker.CanFireNow(target) && (!d.NeedsParms || d.minThreatPoints <= parms.points)
                              select d;
                    if (options.Any <IncidentDef>())
                    {
                        goto Block_2;
                    }
                }
                return;

Block_2:
                IncidentDef incDef;
                if (options.TryRandomElementByWeight(new Func <IncidentDef, float>(base.IncidentChanceFinal), out incDef))
                {
                    yield return(new FiringIncident(incDef, this, this.GenerateParms(incDef.category, target)));
                }
            }
        }
Exemplo n.º 2
0
 public virtual void DebugTablesIncidentChances(IncidentCategory cat)
 {
     DebugTables.MakeTablesDialog(from d in DefDatabase <IncidentDef> .AllDefs
                                  where d.category == cat
                                  orderby this.IncidentChanceFinal(d) descending
                                  select d, new TableDataGetter <IncidentDef>("defName", (IncidentDef d) => d.defName), new TableDataGetter <IncidentDef>("baseChance", (IncidentDef d) => d.baseChance.ToString()), new TableDataGetter <IncidentDef>("AdjustedChance", (IncidentDef d) => d.Worker.AdjustedChance.ToString()), new TableDataGetter <IncidentDef>("Factor-PopCurrent", (IncidentDef d) => this.IncidentChanceFactor_CurrentPopulation(d).ToString()), new TableDataGetter <IncidentDef>("Factor-PopIntent", (IncidentDef d) => this.IncidentChanceFactor_PopulationIntent(d).ToString()), new TableDataGetter <IncidentDef>("final chance", (IncidentDef d) => this.IncidentChanceFinal(d).ToString()), new TableDataGetter <IncidentDef>("vismap-usable", (IncidentDef d) => (Find.VisibleMap != null) ? ((!this.UsableIncidentsInCategory(cat, Find.VisibleMap).Contains(d)) ? string.Empty : "V") : "-"), new TableDataGetter <IncidentDef>("world-usable", (IncidentDef d) => (!this.UsableIncidentsInCategory(cat, Find.World).Contains(d)) ? string.Empty : "W"), new TableDataGetter <IncidentDef>("pop-current", (IncidentDef d) => PawnsFinder.AllMapsCaravansAndTravelingTransportPods_Colonists.Count().ToString()), new TableDataGetter <IncidentDef>("pop-intent", (IncidentDef d) => Find.Storyteller.intenderPopulation.PopulationIntent.ToString("F3")));
 }
        public override IncidentParms GenerateParms(IncidentCategory incCat, IIncidentTarget target)
        {
            IncidentParms incidentParms = StorytellerUtility.DefaultParmsNow(Find.Storyteller.def, incCat, target);

            incidentParms.points *= Rand.Range(0.5f, 1.5f);
            return(incidentParms);
        }
Exemplo n.º 4
0
        private void pckCategory_SelectedIndexChanged(object sender, EventArgs e)
        {
            string FSelectedCategory = pckCategory.Items[pckCategory.SelectedIndex];

            if (FSelectedCategory.Equals("Assalto") || FSelectedCategory.Equals("Roubo") || FSelectedCategory.Equals("Furto"))
            {
                SelectedCategory = FCategories.Where(c => c.IncidentType == IncidentCategoryEnum.Violence).First();
            }
            else if (FSelectedCategory.Equals("Enchente"))
            {
                SelectedCategory = FCategories.Where(c => c.IncidentType == IncidentCategoryEnum.Disaster).First();
            }
            else if (FSelectedCategory.Equals("Festa") || FSelectedCategory.Equals("Feira"))
            {
                SelectedCategory = FCategories.Where(c => c.IncidentType == IncidentCategoryEnum.Event).First();
            }
            else if (FSelectedCategory.Equals("Transito") || FSelectedCategory.Equals("Acidente"))
            {
                SelectedCategory = FCategories.Where(c => c.IncidentType == IncidentCategoryEnum.Traffic).First();
            }
            else if (FSelectedCategory.Equals("AcumuloLixo") || FSelectedCategory.Equals("MalCheiro"))
            {
                SelectedCategory = FCategories.Where(c => c.IncidentType == IncidentCategoryEnum.Event).First();
            }
            else
            {
                SelectedCategory = null;
            }
        }
 public static IncidentParms DefaultParmsNow(StorytellerDef tellerDef, IncidentCategory incCat)
 {
     var incidentParms = new IncidentParms();
     if (incCat == IncidentCategory.ThreatSmall || incCat == IncidentCategory.ThreatBig)
     {
         var wealthSummaryCost = Find.StoryWatcher.watcherWealth.WealthItems + Find.StoryWatcher.watcherWealth.WealthBuildings * BuildingWealthFactor;
         wealthSummaryCost -= WealthBase;
         if (wealthSummaryCost < 0f)
         {
             wealthSummaryCost = 0f;
         }
         var threatPointsOfWealth = wealthSummaryCost / 1000f * PointsPer1000Wealth;
         var threatPointsOfPopulation = Find.MapPawns.FreeColonistsCount * PointsPerColonist;
         incidentParms.points = threatPointsOfWealth + threatPointsOfPopulation;
         incidentParms.points *= Find.StoryWatcher.watcherRampUp.TotalThreatPointsFactor;
         incidentParms.points *= Find.Storyteller.difficulty.threatScale;
         switch (Find.StoryWatcher.statsRecord.numThreatBigs)
         {
             case 0:
                 incidentParms.points = 35f;
                 incidentParms.raidForceOneIncap = true;
                 incidentParms.raidNeverFleeIndividual = true;
                 break;
             case 1:
                 incidentParms.points *= 0.5f;
                 break;
             case 2:
                 incidentParms.points *= 0.7f;
                 break;
             case 3:
                 incidentParms.points *= 0.8f;
                 break;
             case 4:
                 incidentParms.points *= 0.9f;
                 break;
             default:
                 incidentParms.points *= 1f;
                 break;
         }
         if (incidentParms.points < 0f)
         {
             incidentParms.points = 0f;
         }
         if (incidentParms.points > HalveLimitLo)
         {
             if (incidentParms.points > HalveLimitHi)
             {
                 incidentParms.points = HalveLimitHi + (incidentParms.points - HalveLimitHi) * 0.5f;
             }
             incidentParms.points = HalveLimitLo + (incidentParms.points - HalveLimitLo) * 0.5f;
         }
     }
     return incidentParms;
 }
Exemplo n.º 6
0
        public override IEnumerable <FiringIncident> MakeIntervalIncidents(IIncidentTarget target)
        {
            _003CMakeIntervalIncidents_003Ec__Iterator0 _003CMakeIntervalIncidents_003Ec__Iterator = (_003CMakeIntervalIncidents_003Ec__Iterator0) /*Error near IL_0032: stateMachine*/;

            if (!Rand.MTBEventOccurs(this.Props.mtbDays, 60000f, 1000f))
            {
                yield break;
            }
            List <IncidentCategory>   triedCategories = new List <IncidentCategory>();
            IEnumerable <IncidentDef> options;

            while (true)
            {
                _003CMakeIntervalIncidents_003Ec__Iterator0 _003CMakeIntervalIncidents_003Ec__Iterator2 = (_003CMakeIntervalIncidents_003Ec__Iterator0) /*Error near IL_007f: stateMachine*/;
                if (triedCategories.Count < this.Props.categoryWeights.Count)
                {
                    IncidentCategory category = this.DecideCategory(target, triedCategories);
                    triedCategories.Add(category);
                    IncidentParms parms = this.GenerateParms(category, target);
                    options = from d in DefDatabase <IncidentDef> .AllDefs
                              where d.category == category && d.Worker.CanFireNow(target) && (!d.NeedsParms || d.minThreatPoints <= parms.points)
                              select d;
                    if (options.Any())
                    {
                        break;
                    }
                    continue;
                }
                yield break;
            }
            IncidentDef incDef;

            if (!options.TryRandomElementByWeight <IncidentDef>((Func <IncidentDef, float>)base.IncidentChanceFinal, out incDef))
            {
                yield break;
            }
            yield return(new FiringIncident(incDef, this, this.GenerateParms(incDef.category, target)));

            /*Error: Unable to find new state assignment for yield return*/;
        }
Exemplo n.º 7
0
 public virtual IncidentParms GenerateParms(IncidentCategory incCat, IIncidentTarget target)
 {
     return(StorytellerUtility.DefaultParmsNow(Find.Storyteller.def, incCat, target));
 }
        /// <summary>
        /// Update a IncidentCategory
        /// </summary>
        /// <param name="currentUser"></param>
        /// <param name="user"></param>
        /// <param name="appID"></param>
        /// <param name="overrideID"></param>
        /// <param name="code"></param>
        /// <param name="lockID"></param>
        /// <param name="dataRepository"></param>
        /// <param name="uow"></param>
        public void DeleteIncidentCategory(string currentUser, string user, string appID, string overrideID, string code, string lockID, IRepository <IncidentCategory> dataRepository, IUnitOfWork uow, IExceptionManager exceptionManager, IMappingService mappingService)
        {
            try
            {
                #region Parameter validation

                // Validate parameters
                if (string.IsNullOrEmpty(currentUser))
                {
                    throw new ArgumentOutOfRangeException("currentUser");
                }
                if (string.IsNullOrEmpty(user))
                {
                    throw new ArgumentOutOfRangeException("user");
                }
                if (string.IsNullOrEmpty(appID))
                {
                    throw new ArgumentOutOfRangeException("appID");
                }
                if (string.IsNullOrEmpty(code))
                {
                    throw new ArgumentOutOfRangeException("code");
                }
                if (string.IsNullOrEmpty(lockID))
                {
                    throw new ArgumentOutOfRangeException("lockID");
                }
                if (null == dataRepository)
                {
                    throw new ArgumentOutOfRangeException("dataRepository");
                }
                if (null == uow)
                {
                    throw new ArgumentOutOfRangeException("uow");
                }
                if (null == exceptionManager)
                {
                    throw new ArgumentOutOfRangeException("exceptionManager");
                }
                if (null == mappingService)
                {
                    throw new ArgumentOutOfRangeException("mappingService");
                }

                #endregion

                using (uow)
                {
                    // Convert string to guid
                    Guid codeGuid = Guid.Parse(code);

                    // Find item based on ID
                    IncidentCategory dataEntity = dataRepository.Single(x => x.Code == codeGuid);

                    // Delete the item
                    dataRepository.Delete(dataEntity);

                    // Commit unit of work
                    uow.Commit();
                }
            }
            catch (Exception e)
            {
                //Prevent exception from propogating across the service interface
                exceptionManager.ShieldException(e);
            }
        }
        /// <summary>
        /// Retrieve a IncidentCategory with associated lookups
        /// </summary>
        /// <param name="currentUser"></param>
        /// <param name="user"></param>
        /// <param name="appID"></param>
        /// <param name="overrideID"></param>
        /// <param name="code"></param>
        /// <param name="dataRepository"></param>
        /// <param name="uow"></param>
        /// <returns></returns>
        public IncidentCategoryVMDC GetIncidentCategory(string currentUser, string user, string appID, string overrideID, string code, IUnitOfWork uow, IRepository <IncidentCategory> dataRepository
                                                        , IExceptionManager exceptionManager, IMappingService mappingService)

        {
            try
            {
                #region Parameter validation

                // Validate parameters
                if (string.IsNullOrEmpty(currentUser))
                {
                    throw new ArgumentOutOfRangeException("currentUser");
                }
                if (string.IsNullOrEmpty(user))
                {
                    throw new ArgumentOutOfRangeException("user");
                }
                if (string.IsNullOrEmpty(appID))
                {
                    throw new ArgumentOutOfRangeException("appID");
                }
                if (null == dataRepository)
                {
                    throw new ArgumentOutOfRangeException("dataRepository");
                }
                if (null == uow)
                {
                    throw new ArgumentOutOfRangeException("uow");
                }
                if (null == exceptionManager)
                {
                    throw new ArgumentOutOfRangeException("exceptionManager");
                }
                if (null == mappingService)
                {
                    throw new ArgumentOutOfRangeException("mappingService");
                }

                #endregion

                using (uow)
                {
                    IncidentCategoryDC destination = null;

                    // If code is null then just return supporting lists
                    if (!string.IsNullOrEmpty(code))
                    {
                        // Convert code to Guid
                        Guid codeGuid = Guid.Parse(code);

                        // Retrieve specific IncidentCategory
                        IncidentCategory dataEntity = dataRepository.Single(x => x.Code == codeGuid);

                        // Convert to data contract for passing through service interface
                        destination = mappingService.Map <IncidentCategory, IncidentCategoryDC>(dataEntity);
                    }



                    // Create aggregate contract
                    IncidentCategoryVMDC returnObject = new IncidentCategoryVMDC();

                    returnObject.IncidentCategoryItem = destination;

                    return(returnObject);
                }
            }
            catch (Exception e)
            {
                //Prevent exception from propogating across the service interface
                exceptionManager.ShieldException(e);

                return(null);
            }
        }
Exemplo n.º 10
0
 public void LoadDataFromXmlCustom(XmlNode xmlRoot)
 {
     this.category = (IncidentCategory)ParseHelper.FromString(xmlRoot.Name, typeof(IncidentCategory));
     this.weight   = (float)ParseHelper.FromString(xmlRoot.FirstChild.Value, typeof(float));
 }
Exemplo n.º 11
0
        // RimWorld.StorytellerUtility
        public static void DefaultParmsNow_PostFix(ref IncidentParms __result, StorytellerDef tellerDef, IncidentCategory incCat, IIncidentTarget target)
        {
            Map map = target as Map;

            if (map != null)
            {
                if (__result.points > 0)
                {
                    try
                    {
                        List <Pawn> forceUsers = map.mapPawns.FreeColonistsSpawned.ToList().FindAll(p => p.GetComp <CompForceUser>() != null);
                        if (forceUsers != null)
                        {
                            foreach (Pawn pawn in forceUsers)
                            {
                                CompForceUser compForce = pawn.GetComp <CompForceUser>();
                                if (compForce.ForceUserLevel > 0)
                                {
                                    __result.points += (5 * compForce.ForceUserLevel);
                                }
                            }
                        }
                    }
                    catch (NullReferenceException)
                    { }
                }
            }
        }
Exemplo n.º 12
0
        public override IEnumerable <FiringIncident> MakeIntervalIncidents(IIncidentTarget target)
        {
            _003CMakeIntervalIncidents_003Ec__Iterator0 _003CMakeIntervalIncidents_003Ec__Iterator = (_003CMakeIntervalIncidents_003Ec__Iterator0) /*Error near IL_003e: stateMachine*/;

            if (target == Find.Maps.Find((Map x) => x.IsPlayerHome))
            {
                if (this.IntervalsPassed == 150)
                {
                    IncidentDef inc2 = IncidentDefOf.VisitorGroup;
                    if (inc2.TargetAllowed(target))
                    {
                        yield return(new FiringIncident(inc2, this, null)
                        {
                            parms =
                            {
                                target = target,
                                points = (float)Rand.Range(40, 100)
                            }
                        });

                        /*Error: Unable to find new state assignment for yield return*/;
                    }
                }
                if (this.IntervalsPassed == 204)
                {
                    _003CMakeIntervalIncidents_003Ec__Iterator0 _003CMakeIntervalIncidents_003Ec__Iterator2 = (_003CMakeIntervalIncidents_003Ec__Iterator0) /*Error near IL_015f: stateMachine*/;
                    IncidentCategory threatCategory = (IncidentCategory)((!Find.Storyteller.difficulty.allowIntroThreats) ? 1 : 2);
                    IncidentDef      incDef2;
                    if ((from def in DefDatabase <IncidentDef> .AllDefs
                         where def.TargetAllowed(target) && def.category == threatCategory
                         select def).TryRandomElementByWeight <IncidentDef>((Func <IncidentDef, float>)base.IncidentChanceFinal, out incDef2))
                    {
                        yield return(new FiringIncident(incDef2, this, null)
                        {
                            parms = StorytellerUtility.DefaultParmsNow(Find.Storyteller.def, incDef2.category, target)
                        });

                        /*Error: Unable to find new state assignment for yield return*/;
                    }
                }
                IncidentDef incDef;
                if (this.IntervalsPassed == 264 && (from def in DefDatabase <IncidentDef> .AllDefs
                                                    where def.TargetAllowed(target) && def.category == IncidentCategory.Misc
                                                    select def).TryRandomElementByWeight <IncidentDef>((Func <IncidentDef, float>)base.IncidentChanceFinal, out incDef))
                {
                    yield return(new FiringIncident(incDef, this, null)
                    {
                        parms = StorytellerUtility.DefaultParmsNow(Find.Storyteller.def, incDef.category, target)
                    });

                    /*Error: Unable to find new state assignment for yield return*/;
                }
                if (this.IntervalsPassed != 324)
                {
                    yield break;
                }
                IncidentDef inc = IncidentDefOf.RaidEnemy;
                if (!Find.Storyteller.difficulty.allowIntroThreats)
                {
                    inc = (from def in DefDatabase <IncidentDef> .AllDefs
                           where def.TargetAllowed(target) && def.category == IncidentCategory.Misc
                           select def).RandomElementByWeightWithFallback(base.IncidentChanceFinal, null);
                }
                if (inc == null)
                {
                    yield break;
                }
                if (!inc.TargetAllowed(target))
                {
                    yield break;
                }
                yield return(new FiringIncident(inc, this, null)
                {
                    parms = this.GenerateParms(inc.category, target)
                });

                /*Error: Unable to find new state assignment for yield return*/;
            }
        }
        /// <summary>
        ///  Create a IncidentCategory
        /// </summary>
        /// <param name="currentUser"></param>
        /// <param name="user"></param>
        /// <param name="appID"></param>
        /// <param name="overrideID"></param>
        /// <param name="dc"></param>
        /// <param name="dataRepository"></param>
        /// <param name="uow"></param>
        public IncidentCategoryVMDC CreateIncidentCategory(string currentUser, string user, string appID, string overrideID, IncidentCategoryDC dc, IRepository <IncidentCategory> dataRepository, IUnitOfWork uow, IExceptionManager exceptionManager, IMappingService mappingService)
        {
            try
            {
                #region Parameter validation

                // Validate parameters
                if (string.IsNullOrEmpty(currentUser))
                {
                    throw new ArgumentOutOfRangeException("currentUser");
                }
                if (string.IsNullOrEmpty(user))
                {
                    throw new ArgumentOutOfRangeException("user");
                }
                if (string.IsNullOrEmpty(appID))
                {
                    throw new ArgumentOutOfRangeException("appID");
                }
                if (null == dc)
                {
                    throw new ArgumentOutOfRangeException("dc");
                }
                if (null == dataRepository)
                {
                    throw new ArgumentOutOfRangeException("dataRepository");
                }
                if (null == uow)
                {
                    throw new ArgumentOutOfRangeException("uow");
                }
                if (null == exceptionManager)
                {
                    throw new ArgumentOutOfRangeException("exceptionManager");
                }
                if (null == mappingService)
                {
                    throw new ArgumentOutOfRangeException("mappingService");
                }

                #endregion

                using (uow)
                {
                    // Create a new ID for the IncidentCategory item
                    dc.Code = Guid.NewGuid();

                    // Map data contract to model
                    IncidentCategory destination = mappingService.Map <IncidentCategoryDC, IncidentCategory>(dc);

                    // Add the new item
                    dataRepository.Add(destination);

                    // Commit unit of work
                    uow.Commit();

                    // Map model back to data contract to return new row id.
                    dc = mappingService.Map <IncidentCategory, IncidentCategoryDC>(destination);
                }

                // Create aggregate data contract
                IncidentCategoryVMDC returnObject = new IncidentCategoryVMDC();

                // Add new item to aggregate
                returnObject.IncidentCategoryItem = dc;

                return(returnObject);
            }
            catch (Exception e)
            {
                //Prevent exception from propogating across the service interface
                exceptionManager.ShieldException(e);

                return(null);
            }
        }
Exemplo n.º 14
0
 protected virtual IEnumerable <IncidentDef> UsableIncidentsInCategory(IncidentCategory cat, IIncidentTarget target)
 {
     return(from x in DefDatabase <IncidentDef> .AllDefsListForReading
            where x.category == cat && x.Worker.CanFireNow(target)
            select x);
 }
Exemplo n.º 15
0
        public static IncidentParms DefaultParmsNow(StorytellerDef tellerDef, IncidentCategory incCat, IIncidentTarget target)
        {
            IncidentParms incidentParms = new IncidentParms();

            incidentParms.target = target;
            if (incCat == IncidentCategory.ThreatSmall || incCat == IncidentCategory.ThreatBig || incCat == IncidentCategory.RaidBeacon)
            {
                float num = target.PlayerWealthForStoryteller;
                num -= 2000f;
                num  = Mathf.Max(num, 0f);
                float num2 = num / 1000f * 10f;
                float num3 = 0f;
                foreach (Pawn current in target.FreeColonistsForStoryteller)
                {
                    float num4 = 1f;
                    if (current.ParentHolder != null && current.ParentHolder is Building_CryptosleepCasket)
                    {
                        num4 *= 0.3f;
                    }
                    num4  = Mathf.Lerp(num4, num4 * current.health.summaryHealth.SummaryHealthPercent, 0.5f);
                    num3 += 42f * num4;
                }
                incidentParms.points  = num2 + num3;
                incidentParms.points *= Find.StoryWatcher.watcherRampUp.TotalThreatPointsFactor;
                incidentParms.points *= Find.Storyteller.difficulty.threatScale;
                incidentParms.points *= target.IncidentPointsRandomFactorRange.RandomInRange;
                switch (Find.StoryWatcher.statsRecord.numThreatBigs)
                {
                case 0:
                    incidentParms.points                  = 35f;
                    incidentParms.raidForceOneIncap       = true;
                    incidentParms.raidNeverFleeIndividual = true;
                    break;

                case 1:
                    incidentParms.points *= 0.5f;
                    break;

                case 2:
                    incidentParms.points *= 0.7f;
                    break;

                case 3:
                    incidentParms.points *= 0.8f;
                    break;

                case 4:
                    incidentParms.points *= 0.9f;
                    break;

                default:
                    incidentParms.points *= 1f;
                    break;
                }
                if (incidentParms.points < 0f)
                {
                    incidentParms.points = 0f;
                }
                if (incidentParms.points > 1000f)
                {
                    if (incidentParms.points > 2000f)
                    {
                        incidentParms.points = 2000f + (incidentParms.points - 2000f) * 0.5f;
                    }
                    incidentParms.points = 1000f + (incidentParms.points - 1000f) * 0.5f;
                }
            }
            return(incidentParms);
        }
Exemplo n.º 16
0
 public override IEnumerable <FiringIncident> MakeIntervalIncidents(IIncidentTarget target)
 {
     if (target == Find.Maps.Find((Map x) => x.IsPlayerHome))
     {
         if (this.IntervalsPassed == 150)
         {
             IncidentDef inc = IncidentDefOf.VisitorGroup;
             if (inc.TargetAllowed(target))
             {
                 yield return(new FiringIncident(inc, this, null)
                 {
                     parms =
                     {
                         target = target,
                         points = (float)Rand.Range(40, 100)
                     }
                 });
             }
         }
         if (this.IntervalsPassed == 204)
         {
             IncidentCategory threatCategory = (!Find.Storyteller.difficulty.allowIntroThreats) ? IncidentCategory.Misc : IncidentCategory.ThreatSmall;
             IncidentDef      incDef;
             if ((from def in DefDatabase <IncidentDef> .AllDefs
                  where def.TargetAllowed(target) && def.category == threatCategory
                  select def).TryRandomElementByWeight(new Func <IncidentDef, float>(base.IncidentChanceFinal), out incDef))
             {
                 yield return(new FiringIncident(incDef, this, null)
                 {
                     parms = StorytellerUtility.DefaultParmsNow(Find.Storyteller.def, incDef.category, target)
                 });
             }
         }
         IncidentDef incDef2;
         if (this.IntervalsPassed == 264 && (from def in DefDatabase <IncidentDef> .AllDefs
                                             where def.TargetAllowed(target) && def.category == IncidentCategory.Misc
                                             select def).TryRandomElementByWeight(new Func <IncidentDef, float>(base.IncidentChanceFinal), out incDef2))
         {
             yield return(new FiringIncident(incDef2, this, null)
             {
                 parms = StorytellerUtility.DefaultParmsNow(Find.Storyteller.def, incDef2.category, target)
             });
         }
         if (this.IntervalsPassed == 324)
         {
             IncidentDef inc2 = IncidentDefOf.RaidEnemy;
             if (!Find.Storyteller.difficulty.allowIntroThreats)
             {
                 inc2 = (from def in DefDatabase <IncidentDef> .AllDefs
                         where def.TargetAllowed(target) && def.category == IncidentCategory.Misc
                         select def).RandomElementByWeightWithFallback(new Func <IncidentDef, float>(base.IncidentChanceFinal), null);
             }
             if (inc2 != null && inc2.TargetAllowed(target))
             {
                 yield return(new FiringIncident(inc2, this, null)
                 {
                     parms = this.GenerateParms(inc2.category, target)
                 });
             }
         }
     }
 }
Exemplo n.º 17
0
        public static IncidentParms DefaultParmsNow(StorytellerDef tellerDef, IncidentCategory incCat, IIncidentTarget target)
        {
            IncidentParms incidentParms = new IncidentParms();

            incidentParms.target = target;
            if (incCat == IncidentCategory.ThreatSmall || incCat == IncidentCategory.ThreatBig || incCat == IncidentCategory.RaidBeacon)
            {
                float playerWealthForStoryteller = target.PlayerWealthForStoryteller;
                playerWealthForStoryteller = (float)(playerWealthForStoryteller - 2000.0);
                playerWealthForStoryteller = Mathf.Max(playerWealthForStoryteller, 0f);
                float num  = (float)(playerWealthForStoryteller / 1000.0 * 10.0);
                float num2 = 0f;
                foreach (Pawn item in target.FreeColonistsForStoryteller)
                {
                    float num3 = 1f;
                    if (item.ParentHolder != null && item.ParentHolder is Building_CryptosleepCasket)
                    {
                        num3 = (float)(num3 * 0.30000001192092896);
                    }
                    num3 = Mathf.Lerp(num3, num3 * item.health.summaryHealth.SummaryHealthPercent, 0.5f);
                    num2 = (float)(num2 + 42.0 * num3);
                }
                incidentParms.points  = num + num2;
                incidentParms.points *= Find.StoryWatcher.watcherRampUp.TotalThreatPointsFactor;
                incidentParms.points *= Find.Storyteller.difficulty.threatScale;
                incidentParms.points *= target.IncidentPointsRandomFactorRange.RandomInRange;
                switch (Find.StoryWatcher.statsRecord.numThreatBigs)
                {
                case 0:
                    incidentParms.points                  = 35f;
                    incidentParms.raidForceOneIncap       = true;
                    incidentParms.raidNeverFleeIndividual = true;
                    break;

                case 1:
                    incidentParms.points *= 0.5f;
                    break;

                case 2:
                    incidentParms.points *= 0.7f;
                    break;

                case 3:
                    incidentParms.points *= 0.8f;
                    break;

                case 4:
                    incidentParms.points *= 0.9f;
                    break;

                default:
                    incidentParms.points *= 1f;
                    break;
                }
                if (incidentParms.points < 0.0)
                {
                    incidentParms.points = 0f;
                }
                if (incidentParms.points > 1000.0)
                {
                    if (incidentParms.points > 2000.0)
                    {
                        incidentParms.points = (float)(2000.0 + (incidentParms.points - 2000.0) * 0.5);
                    }
                    incidentParms.points = (float)(1000.0 + (incidentParms.points - 1000.0) * 0.5);
                }
            }
            return(incidentParms);
        }