Exemple #1
0
        public static List <ThingDef> GenerateThingDefsToIgnore(this DamageWorker_ExplosionOnImpact DWEOI, Pawn Instigator)
        {
            string debugStr = DWEOI.MyDebug ? "GenerateThingDefsToIgnore" : "";

            List <ThingDef> answer = new List <ThingDef>();

            if (!DWEOI.HasImmunity)
            {
                return(null);
            }

            if (DWEOI.Immunity.HasIgnoredThingDefs)
            {
                Tools.Warn($"{debugStr} adding ignoringDamageThingDef");
                answer = DWEOI.Immunity.ignoredByDamageThingDefs;
            }

            if (DWEOI.Immunity.addAttackerThingDef && !answer.Contains(Instigator.def))
            {
                Tools.Warn($"{debugStr} adding {Instigator.def}");
                answer.Add(Instigator.def);
            }

            if (!answer.NullOrEmpty())
            {
                Tools.Warn($"{debugStr} final count:{answer.Count}");
            }

            return(answer);
        }
        // not a ratio : finale radius
        public static float PawnWeightedExplosionRadius(this DamageWorker_ExplosionOnImpact DWEOI, Pawn Instigator)
        {
            float skillDiceThrow = SkillDiceThrow(Instigator, DWEOI.Nature.radiusLinkedSkill, DWEOI.Nature.radiusRatioMin);

            float curvedValue  = DWEOI.Nature.radiusCurve.Evaluate(skillDiceThrow);
            float finaleRadius = DWEOI.Nature.radius.min + curvedValue * DWEOI.Nature.radius.Span;

            return(finaleRadius);
        }
        // not a ratio : finale damage
        public static float PawnWeightedExplosionDamage(this DamageWorker_ExplosionOnImpact DWEOI, Pawn Instigator, float DamageBase)
        {
            float skillDiceThrow = SkillDiceThrow(Instigator, DWEOI.Nature.damageLinkedSkill, DWEOI.Nature.damageRatioMin);
            float curvedValue    = DWEOI.Nature.damageCurve.Evaluate(skillDiceThrow);

            float multipliedValue = curvedValue * DWEOI.Nature.damageMultiplier.RandomInRange * DamageBase;

            float finaleDmg = Math.Min(Math.Max(multipliedValue, DWEOI.Nature.damageLimit.min), DWEOI.Nature.damageLimit.max);

            return(finaleDmg);
        }
        public static float ChanceToTriggerExplosion(this DamageWorker_ExplosionOnImpact DWEOI, Pawn Instigator)
        {
            float chanceBase   = SkillDiceThrow(Instigator, DWEOI.Chance.linkedSkill, DWEOI.Chance.limits.min);
            float curvedChance = DWEOI.Chance.chanceCurve.Evaluate(chanceBase);

            curvedChance *= DWEOI.Chance.randomChanceFactor.RandomInRange;

            float finaleChance = Math.Min(Math.Max(curvedChance, DWEOI.Chance.limits.min), DWEOI.Chance.limits.max);

            return(finaleChance);
        }
Exemple #5
0
        /*
         * public static void DoExplosion(
         *      IntVec3 center, Map map, float radius, DamageDef damType, Thing instigator,
         *      int damAmount = -1, float armorPenetration = -1, SoundDef explosionSound = null, ThingDef weapon = null, ThingDef projectile = null, Thing intendedTarget = null,
         *      ThingDef postExplosionSpawnThingDef = null, float postExplosionSpawnChance = 0, int postExplosionSpawnThingCount = 1,
         *      bool applyDamageToExplosionCellsNeighbors = false,
         *      ThingDef preExplosionSpawnThingDef = null, float preExplosionSpawnChance = 0, int preExplosionSpawnThingCount = 1,
         *      float chanceToStartFire = 0, bool damageFalloff = false, float? direction = null, List<Thing> ignoredThings = null
         * );*/
        public static bool TryExplode(this DamageWorker_ExplosionOnImpact DWEOI, PickedParams pp)
        {
            GenExplosion.DoExplosion(
                center: pp.Origin, map: pp.Map, radius: pp.Radius, damType: pp.DamageType, instigator: pp.Instigator,
                damAmount: (int)pp.DamageAmount, explosionSound: pp.ExplosionSound, weapon: pp.Weapon, intendedTarget: pp.IntendedTarget,
                postExplosionSpawnThingDef: pp.PostExplosionSpawnThingDef, postExplosionSpawnChance: pp.PostExplosionSpawnChance, postExplosionSpawnThingCount: pp.PostExplosionSpawnThingCount,

                preExplosionSpawnThingDef: pp.PreExplosionSpawnThingDef, preExplosionSpawnChance: pp.PreExplosionSpawnChance, preExplosionSpawnThingCount: pp.PreExplosionSpawnThingCount,
                chanceToStartFire: pp.ChanceToStartFire, damageFalloff: pp.DamageFallOff, ignoredThings: pp.IgnoredByExplosion
                );

            return(true);
        }
Exemple #6
0
        public static List <Thing> GenerateThingsToIgnore(this DamageWorker_ExplosionOnImpact DWEOI, Map map, Thing Instigator, List <ThingDef> thingDefs, int limit = 100)
        {
            int          limiter = limit;
            List <Thing> answer  = new List <Thing>();

            if (DWEOI.Immunity.HasIgnoredThingDefs)
            {
                List <Thing> potentialImmunizable =
                    map.spawnedThings.Where(t => thingDefs.Contains(t.def)).ToList();

                foreach (Thing ignoreMe in potentialImmunizable)
                {
                    if (!answer.Contains(ignoreMe) && limiter-- > 0)
                    {
                        answer.Add(ignoreMe);
                    }
                }
            }

            if (DWEOI.Immunity.addPawnsFromAttackerFaction || DWEOI.Immunity.addThingsFromAttackerFaction)
            {
                List <Thing> potentialImmunizable =
                    map.spawnedThings.Where(
                        t =>
                        t.Faction != null && Instigator.Faction != null &&
                        Instigator.Faction == t.Faction &&
                        (DWEOI.Immunity.addPawnsFromAttackerFaction?t is Pawn:true) &&
                        (DWEOI.Immunity.addThingsFromAttackerFaction ? !(t is Pawn) : true)
                        ).ToList();

                foreach (Thing ignoreMe in potentialImmunizable)
                {
                    if (!answer.Contains(ignoreMe) && limiter-- > 0)
                    {
                        answer.Add(ignoreMe);
                    }
                }
            }

            if (DWEOI.HasImmunity && DWEOI.Immunity.addAttacker && !answer.Contains(Instigator) && limiter > 0)
            {
                //limiter--;
                answer.Add(Instigator);
            }

            return(answer);
        }
        public static bool TryApplyEffect(this DamageWorker_ExplosionOnImpact DWEOI, Pawn p)
        {
            if (p == null)
            {
                return(false);
            }

            if (DWEOI.HasVictimEffect)
            {
                if (DWEOI.VictimEffect.HasImmuneThings && !DWEOI.VictimEffect.immuneToEffectThings.Contains(p.def))
                {
                    bool  WillDoIt   = false;
                    float baseChance = DWEOI.VictimEffect.chanceMultiplier.RandomInRange;
                    if (DWEOI.VictimEffect.HasResistance)
                    {
                        baseChance *= p.GetStatValue(DWEOI.VictimEffect.resistanceStatDef);
                    }

                    WillDoIt = Rand.Chance(baseChance);

                    if (WillDoIt)
                    {
                        if ((p.CurJob == null) || p.CurJob.def != DWEOI.VictimEffect.jobDef)
                        {
                            p.jobs.StartJob(
                                JobMaker.MakeJob(DWEOI.VictimEffect.jobDef)
                                , JobCondition.InterruptForced, null
                                , resumeCurJobAfterwards: DWEOI.VictimEffect.resumeJobAfterWards
                                );
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }