Ejemplo n.º 1
0
 public void DoDamage(WeatherEffectsExtension options, Map map)
 {
     for (int i = map.listerThings.AllThings.Count - 1; i >= 0; i--)
     {
         Thing thing = map.listerThings.AllThings[i];
         if (CanDamage(thing, map, options))
         {
             if (thing is Pawn pawn)
             {
                 DoPawnDamage(pawn, options);
             }
             else
             {
                 DoThingDamage(thing, options);
             }
         }
     }
     if (options.damageToApply != null)
     {
         var victimCandidates = map.mapPawns.AllPawns.Where(x => CanDamage(x, map, options));
         var victims          = RandomlySelectedItems(victimCandidates, (int)(victimCandidates.Count() * options.percentOfPawnsToDealDamage)).ToList();
         for (int num = victims.Count - 1; num >= 0; num--)
         {
             var damageInfo = new DamageInfo(options.damageToApply, options.damageRange.RandomInRange);
             victims[num].TakeDamage(damageInfo);
         }
     }
 }
Ejemplo n.º 2
0
        public bool CanDamage(Thing thing, Map map, WeatherEffectsExtension options)
        {
            if (thing is Pawn pawn)
            {
                if (!pawn.RaceProps.IsFlesh && !options.worksOnNonFleshPawns)
                {
                    return(false);
                }
            }

            if (thing.Position.Roofed(map) && !options.worksIndoors)
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 3
0
 public void DoPawnDamage(Pawn p, WeatherEffectsExtension options)
 {
     if (options.hediffsToApply != null)
     {
         foreach (var opt in options.hediffsToApply)
         {
             var hediffDef = HediffDef.Named(opt.hediff);
             if (hediffDef != null)
             {
                 var severity = opt.severityOffset * p.GetStatValue(opt.effectMultiplyingStat, true);
                 if (severity != 0f)
                 {
                     HealthUtility.AdjustSeverity(p, hediffDef, severity);
                 }
             }
         }
     }
 }
Ejemplo n.º 4
0
        public void DoThingDamage(Thing thing, WeatherEffectsExtension options)
        {
            if (options.killsPlants && thing is Plant)
            {
                if (Rand.Value < options.chanceToKillPlants)
                {
                    thing.Kill(null, null);
                }
            }

            else if (thing.def.category == ThingCategory.Item)
            {
                CompRottable compRottable = thing.TryGetComp <CompRottable>();
                if (options.causesRotting && compRottable != null && compRottable.Stage < RotStage.Dessicated)
                {
                    compRottable.RotProgress += options.rotProgressPerDamage;
                }
            }
        }
Ejemplo n.º 5
0
 public int NextDamageTick(WeatherEffectsExtension options)
 {
     return(Find.TickManager.TicksGame + Rand.RangeInclusive(options.ticksInterval.min, options.ticksInterval.max));
 }