Exemplo n.º 1
0
        // Token: 0x0600002F RID: 47 RVA: 0x00003ADC File Offset: 0x00001CDC
        public override bool CheckPreAbsorbDamage(DamageInfo dinfo)
        {
            if (this.CamoState == 0)
            {
                return(false);
            }
            if (dinfo.Def == DamageDefOf.EMP)
            {
                this.energy = 0f;
                this.Break();
                return(false);
            }
            DamageDef named = DefDatabase <DamageDef> .GetNamed("GGHaywireEMP", false);

            if (named != null && dinfo.Def == named)
            {
                this.energy = 0f;
                this.Break();
                return(false);
            }
            return(false);
        }
Exemplo n.º 2
0
        public static void DoExecutionByCut(Pawn executioner, Pawn victim)
        {
            Map     map      = victim.Map;
            IntVec3 position = victim.Position;
            int     num      = Mathf.Max(GenMath.RoundRandom(victim.BodySize * 8f), 1);

            for (int i = 0; i < num; i++)
            {
                victim.health.DropBloodFilth();
            }
            BodyPartRecord bodyPartRecord = ExecutionUtility.ExecuteCutPart(victim);
            int            num2           = Mathf.Clamp((int)victim.health.hediffSet.GetPartHealth(bodyPartRecord) - 1, 1, 20);
            DamageDef      executionCut   = DamageDefOf.ExecutionCut;
            int            amount         = num2;
            DamageInfo     damageInfo     = new DamageInfo(executionCut, amount, -1f, executioner, bodyPartRecord, null, DamageInfo.SourceCategory.ThingOrUnknown);

            victim.TakeDamage(damageInfo);
            if (!victim.Dead)
            {
                victim.Kill(new DamageInfo?(damageInfo), null);
            }
        }
Exemplo n.º 3
0
        protected override bool TryCastShot()
        {
            Fire fire       = (Fire)this.currentTarget.Thing;
            Pawn casterPawn = base.CasterPawn;
            bool result;

            if (casterPawn.stances.FullBodyBusy)
            {
                result = false;
            }
            else
            {
                Thing     thing      = fire;
                DamageDef extinguish = DamageDefOf.Extinguish;
                float     amount     = 32f;
                Thing     caster     = this.caster;
                thing.TakeDamage(new DamageInfo(extinguish, amount, 0f, -1f, caster, null, null, DamageInfo.SourceCategory.ThingOrUnknown, null));
                casterPawn.Drawer.Notify_MeleeAttackOn(fire);
                result = true;
            }
            return(result);
        }
Exemplo n.º 4
0
        private IEnumerable <DamageInfo> DamageInfosToApply(LocalTargetInfo target)
        {
            float            damAmount2       = base.verbProps.AdjustedMeleeDamageAmount(this, base.CasterPawn, base.ownerEquipment);
            DamageDef        damDef           = base.verbProps.meleeDamageDef;
            BodyPartGroupDef bodyPartGroupDef = null;
            HediffDef        hediffDef        = null;

            damAmount2 = Random.Range((float)(damAmount2 * 0.800000011920929), (float)(damAmount2 * 1.2000000476837158));
            if (base.CasterIsPawn)
            {
                bodyPartGroupDef = base.LinkedBodyPartsGroup;
                if (damAmount2 >= 1.0)
                {
                    if (base.ownerHediffComp != null)
                    {
                        hediffDef = base.ownerHediffComp.Def;
                    }
                }
                else
                {
                    damAmount2 = 1f;
                    damDef     = DamageDefOf.Blunt;
                }
            }
            ThingDef   source    = (base.ownerEquipment == null) ? base.CasterPawn.def : base.ownerEquipment.def;
            Vector3    direction = (target.Thing.Position - base.CasterPawn.Position).ToVector3();
            DamageDef  def       = damDef;
            int        amount    = GenMath.RoundRandom(damAmount2);
            Thing      caster    = base.caster;
            DamageInfo mainDinfo = new DamageInfo(def, amount, -1f, caster, null, source, DamageInfo.SourceCategory.ThingOrUnknown);

            mainDinfo.SetBodyRegion(BodyPartHeight.Undefined, BodyPartDepth.Outside);
            mainDinfo.SetWeaponBodyPartGroup(bodyPartGroupDef);
            mainDinfo.SetWeaponHediff(hediffDef);
            mainDinfo.SetAngle(direction);
            yield return(mainDinfo);

            /*Error: Unable to find new state assignment for yield return*/;
        }
        //
        // Static Methods
        //
        public static void GenerateRandomOldAgeInjuries(Pawn pawn, bool tryNotToKillPawn)
        {
            int num = 0;

            for (int i = 10; i < pawn.ageTracker.AgeBiologicalYears; i += 10)
            {
                if (Rand.Value < 0.15)
                {
                    num++;
                }
            }
            for (int j = 0; j < num; j++)
            {
                DamageDef dam  = AgeInjuryUtility.RandomOldInjuryDamageType();
                int       num2 = Rand.RangeInclusive(2, 6);
                IEnumerable <BodyPartRecord> source = from x in pawn.health.hediffSet.GetNotMissingParts(null, null)
                                                      where x.depth == BodyPartDepth.Outside && !Mathf.Approximately(x.def.oldInjuryBaseChance, 0) && !pawn.health.hediffSet.PartOrAnyAncestorHasDirectlyAddedParts(x)
                                                      select x;
                if (source.Any <BodyPartRecord>())
                {
                    BodyPartRecord bodyPartRecord      = source.RandomElementByWeight((BodyPartRecord x) => x.absoluteFleshCoverage);
                    HediffDef      hediffDefFromDamage = HealthUtility.GetHediffDefFromDamage(dam, pawn, bodyPartRecord);
                    if (bodyPartRecord.def.oldInjuryBaseChance > 0 && hediffDefFromDamage.CompPropsFor(typeof(HediffComp_GetsOld)) != null)
                    {
                        Hediff_Injury hediff_Injury = (Hediff_Injury)HediffMaker.MakeHediff(hediffDefFromDamage, pawn, null);
                        hediff_Injury.Severity = (float)num2;
                        hediff_Injury.TryGetComp <HediffComp_GetsOld>().IsOld = true;
                        pawn.health.AddHediff(hediff_Injury, bodyPartRecord, null);
                    }
                }
            }
            for (int k = 1; k < pawn.ageTracker.AgeBiologicalYears; k++)
            {
                foreach (HediffGiver_Birthday current in AgeInjuryUtility.RandomHediffsToGainOnBirthday(pawn, k))
                {
                    current.TryApplyAndSimulateSeverityChange(pawn, (float)k, tryNotToKillPawn);
                }
            }
        }
Exemplo n.º 6
0
        public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill)
        {
            if (billDoer != null)
            {
                if (base.CheckSurgeryFail(billDoer, pawn, ingredients, part, bill))
                {
                    DamageDef surgicalCut      = DamageDefOf.SurgicalCut;
                    float     amount           = 99999f;
                    float     armorPenetration = 999f;
                    pawn.TakeDamage(new DamageInfo(surgicalCut, amount, armorPenetration, -1f, null, part, null, DamageInfo.SourceCategory.ThingOrUnknown, null));
                    return;
                }
                TaleRecorder.RecordTale(TaleDefOf.DidSurgery, new object[]
                {
                    billDoer,
                    pawn
                });
                //pawn.health.AddHediff(recipe.addsHediff, part, null, null);

                pawn.health.AddHediff(SexPartAdder.recipePartAdder(recipe, pawn, part, ingredients), part, null, null);
            }
        }
Exemplo n.º 7
0
        public override void DoEffectOn(Pawn user, Thing target)
        {
            Pawn pawn = (Pawn)target;

            if (pawn.Dead)
            {
                return;
            }
            if (Rand.Value <= 0.3f)
            {
                BodyPartRecord brain = pawn.health.hediffSet.GetBrain();
                if (brain == null)
                {
                    return;
                }
                int       num      = Rand.RangeInclusive(1, 5);
                Thing     arg_6B_0 = pawn;
                DamageDef flame    = DamageDefOf.Flame;
                int       amount   = num;
                arg_6B_0.TakeDamage(new DamageInfo(flame, amount, -1f, user, brain, this.parent.def, DamageInfo.SourceCategory.ThingOrUnknown));
            }
        }
Exemplo n.º 8
0
        protected override void Impact(Thing hitThing)
        {
            Map map = base.Map;

            base.Impact(hitThing);
            BattleLogEntry_RangedImpact battleLogEntry_RangedImpact = new BattleLogEntry_RangedImpact(this.launcher, hitThing, this.intendedTarget.Thing, ThingDef.Named("Gun_Autopistol"), this.def, this.targetCoverDef);

            Find.BattleLog.Add(battleLogEntry_RangedImpact);
            if (hitThing != null)
            {
                DamageDef  damageDef        = this.def.projectile.damageDef;
                float      amount           = (float)base.DamageAmount;
                float      armorPenetration = base.ArmorPenetration;
                float      y            = this.ExactRotation.eulerAngles.y;
                Thing      launcher     = this.launcher;
                ThingDef   equipmentDef = this.equipmentDef;
                DamageInfo dinfo        = new DamageInfo(damageDef, amount, armorPenetration, y, launcher, null, null, DamageInfo.SourceCategory.ThingOrUnknown, this.intendedTarget.Thing);
                hitThing.TakeDamage(dinfo).AssociateWithLog(battleLogEntry_RangedImpact);
                Pawn pawn = hitThing as Pawn;
                if (pawn != null && pawn.stances != null && pawn.BodySize <= this.def.projectile.StoppingPower + 0.001f)
                {
                    pawn.stances.StaggerFor(95);
                }
                if (map != null && hitThing != null)
                {
                    map.weatherManager.eventHandler.AddEvent(new WeatherEvent_LightningStrike(map, hitThing.Position));
                }
            }
            else
            {
                SoundDefOf.BulletImpact_Ground.PlayOneShot(new TargetInfo(base.Position, map, false));
                FleckMaker.Static(this.ExactPosition, map, FleckDefOf.ShotHit_Dirt, 1f);
                if (base.Position.GetTerrain(map).takeSplashes)
                {
                    FleckMaker.WaterSplash(this.ExactPosition, map, Mathf.Sqrt((float)base.DamageAmount) * 1f, 4f);
                }
            }
        }
Exemplo n.º 9
0
        public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill)
        {
            bool flag  = MedicalRecipesUtility.IsClean(pawn, part);
            bool flag2 = IsViolationOnPawn(pawn, part, Faction.OfPlayer);

            if (billDoer != null)
            {
                if (CheckSurgeryFail(billDoer, pawn, ingredients, part, bill))
                {
                    return;
                }
                TaleRecorder.RecordTale(TaleDefOf.DidSurgery, billDoer, pawn);
                MedicalRecipesUtility.SpawnNaturalPartIfClean(pawn, part, billDoer.Position, billDoer.Map);
                MedicalRecipesUtility.SpawnThingsFromHediffs(pawn, part, billDoer.Position, billDoer.Map);
            }
            DamageDef surgicalCut      = DamageDefOf.SurgicalCut;
            float     amount           = 99999f;
            float     armorPenetration = 999f;

            pawn.TakeDamage(new DamageInfo(surgicalCut, amount, armorPenetration, -1f, null, part));
            if (flag)
            {
                if (pawn.Dead)
                {
                    ThoughtUtility.GiveThoughtsForPawnExecuted(pawn, PawnExecutionKind.OrganHarvesting);
                }
                ThoughtUtility.GiveThoughtsForPawnOrganHarvested(pawn);
            }
            if (flag2 && pawn.Faction != null && billDoer != null && billDoer.Faction != null)
            {
                Faction          faction        = pawn.Faction;
                Faction          faction2       = billDoer.Faction;
                int              goodwillChange = -15;
                string           reason         = "GoodwillChangedReason_RemovedBodyPart".Translate(part.LabelShort);
                GlobalTargetInfo?lookTarget     = pawn;
                faction.TryAffectGoodwillWith(faction2, goodwillChange, canSendMessage: true, canSendHostilityLetter: true, reason, lookTarget);
            }
        }
Exemplo n.º 10
0
        private void StartRandomFireAndDoFlameDamage()
        {
            IntVec3 c = (from x in GenRadial.RadialCellsAround(base.Position, Radius, true)
                         where x.InBounds(base.Map)
                         select x).RandomElementByWeight((IntVec3 x) => 1f - Mathf.Min(x.DistanceTo(base.Position) / 15f, 1f) + 0.05f);

            FireUtility.TryStartFireIn(c, base.Map, Rand.Range(0.1f, 0.925f));
            BombardmentBeamLGE.tmpThings.Clear();
            BombardmentBeamLGE.tmpThings.AddRange(c.GetThingList(base.Map));
            for (int i = 0; i < BombardmentBeamLGE.tmpThings.Count; i++)
            {
                int  num  = (!(BombardmentBeamLGE.tmpThings[i] is Corpse)) ? BombardmentBeamLGE.FlameDamageAmountRange.RandomInRange : BombardmentBeamLGE.CorpseFlameDamageAmountRange.RandomInRange;
                Pawn pawn = BombardmentBeamLGE.tmpThings[i] as Pawn;
                //No log entries because there is no instigator
                Thing     thing      = BombardmentBeamLGE.tmpThings[i];
                DamageDef flame      = DamageDefOf.Flame;
                float     amount     = (float)num;
                Thing     instigator = this.instigator;
                ThingDef  weaponDef  = this.weaponDef;
                thing.TakeDamage(new DamageInfo(flame, amount, 0f, -1f, instigator, null, weaponDef, DamageInfo.SourceCategory.ThingOrUnknown, null));
            }
            BombardmentBeamLGE.tmpThings.Clear();
        }
Exemplo n.º 11
0
        protected override void Impact(Thing hitThing)
        {
            Map map = base.Map;

            base.Impact(hitThing);
            IntVec3   position         = base.Position;
            Map       map2             = map;
            float     explosionRadius  = base.def.projectile.explosionRadius;
            DamageDef bomb             = DamageDefOf.Bomb;
            Thing     launcher         = base.launcher;
            int       damageAmountBase = base.def.projectile.damageAmountBase;
            ThingDef  equipmentDef     = base.equipmentDef;

            GenExplosion.DoExplosion(position, map2, explosionRadius, bomb, launcher, damageAmountBase, null, equipmentDef, base.def, null, 0f, 1, false, null, 0f, 1, 0f, false);
            CellRect cellRect = CellRect.CenteredOn(base.Position, 10);

            cellRect.ClipInsideMap(map);
            for (int i = 0; i < 5; i++)
            {
                IntVec3 randomCell = cellRect.RandomCell;
                this.FireExplosion(randomCell, map, 3.9f);
            }
        }
        private void RemoveAstarteParts()
        {
            foreach (BodyPartDef astarteBodyPart in Constants.AstarteBodyParts)
            {
                DamageDef surgicalCut      = DamageDefOf.SurgicalCut;
                float     amount           = 99999f;
                float     armorPenetration = 999f;

                foreach (var part in pawn.def.race.body.GetPartsWithDef(astarteBodyPart))
                {
                    pawn.TakeDamage(new DamageInfo(surgicalCut, amount, armorPenetration, -1f, null, part, null,
                                                   DamageInfo.SourceCategory.ThingOrUnknown, null));

                    //Log.Message("Blowing Off a Part : " + pawn + "'s "+part);
                    break;
                }

                foreach (var hediff in pawn.health.hediffSet.GetHediffsTendable())
                {
                    hediff.Tended(1f);
                }
            }
        }
        public override void DoEffectOn(Pawn user, Thing target)
        {
            Pawn pawn = (Pawn)target;

            if (pawn.Dead)
            {
                return;
            }
            if (Rand.Value <= this.PropsBrainDamageChance.brainDamageChance)
            {
                BodyPartRecord brain = pawn.health.hediffSet.GetBrain();
                if (brain == null)
                {
                    return;
                }
                int            num     = Rand.RangeInclusive(1, 5);
                Thing          thing   = pawn;
                DamageDef      flame   = DamageDefOf.Flame;
                float          amount  = (float)num;
                BodyPartRecord hitPart = brain;
                thing.TakeDamage(new DamageInfo(flame, amount, 0f, -1f, user, hitPart, this.parent.def, DamageInfo.SourceCategory.ThingOrUnknown, null));
            }
        }
Exemplo n.º 14
0
        public static void DoExecutionByCut(Pawn executioner, Pawn victim)
        {
            Map     map      = victim.Map;
            IntVec3 position = victim.Position;
            int     num      = Mathf.Max(GenMath.RoundRandom(victim.BodySize * 8f), 1);

            for (int i = 0; i < num; i++)
            {
                victim.health.DropBloodFilth();
            }
            BodyPartRecord bodyPartRecord   = ExecuteCutPart(victim);
            int            num2             = Mathf.Clamp((int)victim.health.hediffSet.GetPartHealth(bodyPartRecord) - 1, 1, 20);
            DamageDef      executionCut     = DamageDefOf.ExecutionCut;
            float          amount           = (float)num2;
            float          armorPenetration = 999f;
            DamageInfo     damageInfo       = new DamageInfo(executionCut, amount, armorPenetration, -1f, executioner, bodyPartRecord);

            victim.TakeDamage(damageInfo);
            if (!victim.Dead)
            {
                victim.Kill(damageInfo);
            }
        }
Exemplo n.º 15
0
        private void CreateRandomExplosion()
        {
            IntVec3 intVec;

            CellFinder.TryFindRandomCellNear(base.Position, base.Map, 40, null, out intVec, -1);

            if (intVec == null)
            {
                intVec = base.Position;
            }

            float     num      = (float)Rand.Range(9, 50);
            IntVec3   center   = intVec;
            Map       map      = base.Map;
            float     radius   = num;
            DamageDef manabomb = DamageDefOf.PLAHFManaBomb;

            Thing    instigator = this.instigator;
            ThingDef def        = this.def;
            ThingDef weaponDef  = this.weaponDef;

            GenExplosion.DoExplosion(center, map, radius, manabomb, instigator, -1, -1f, null, weaponDef, def, null, null, 0f, 1, false, null, 0f, 1, 0f, false);
        }
Exemplo n.º 16
0
        protected virtual void Explode(Thing hitThing, bool destroy = false)
        {
            Map     map            = base.Map;
            IntVec3 targetPosition = hitThing?.PositionHeld ?? this.destination.ToIntVec3();

            if (destroy)
            {
                this.Destroy(DestroyMode.Vanish);
            }
            if (this.def.projectile.explosionEffect != null)
            {
                Effecter effecter = this.def.projectile.explosionEffect.Spawn();
                effecter.Trigger(new TargetInfo(targetPosition, map, false),
                                 new TargetInfo(targetPosition, map, false));
                effecter.Cleanup();
            }
            IntVec3   position         = targetPosition;
            Map       map2             = map;
            float     explosionRadius  = this.def.projectile.explosionRadius;
            DamageDef damageDef        = this.def.projectile.damageDef;
            Thing     launcher         = this.launcher;
            int       damageAmountBase = this.def.projectile.GetDamageAmount(1f);
            SoundDef  soundExplode     = this.def.projectile.soundExplode;
            ThingDef  equipmentDef     = this.equipmentDef;
            ThingDef  def = this.def;
            ThingDef  postExplosionSpawnThingDef   = this.def.projectile.postExplosionSpawnThingDef;
            float     postExplosionSpawnChance     = this.def.projectile.postExplosionSpawnChance;
            int       postExplosionSpawnThingCount = this.def.projectile.postExplosionSpawnThingCount;
            ThingDef  preExplosionSpawnThingDef    = this.def.projectile.preExplosionSpawnThingDef;

            GenExplosion.DoExplosion(position, map2, explosionRadius, damageDef, launcher, damageAmountBase, 0f,
                                     soundExplode, equipmentDef, def, null, postExplosionSpawnThingDef, postExplosionSpawnChance,
                                     postExplosionSpawnThingCount, this.def.projectile.applyDamageToExplosionCellsNeighbors,
                                     preExplosionSpawnThingDef, this.def.projectile.preExplosionSpawnChance,
                                     this.def.projectile.preExplosionSpawnThingCount, this.def.projectile.explosionChanceToStartFire,
                                     this.def.projectile.explosionDamageFalloff);
        }
Exemplo n.º 17
0
 public override void CompTick()
 {
     base.CompTick();
     flameCounter++;
     if (flameCounter >= 50)
     {
         Pawn pawn = this.parent as Pawn;
         if ((pawn.Map != null) && (pawn.IsBurning()))
         {
             BattleLogEntry_DamageTaken battleLogEntry_DamageTaken = null;
             if (pawn != null)
             {
                 battleLogEntry_DamageTaken = new BattleLogEntry_DamageTaken(pawn, RulePackDefOf.DamageEvent_Fire, pawn);
                 Find.BattleLog.Add(battleLogEntry_DamageTaken);
             }
             DamageDef flame      = Named("AA_PermanentBurn");
             float     amount     = (float)15;
             Thing     instigator = this.parent;
             //ThingDef weaponDef = ThingDef.Named("Gun_Autopistol");
             this.parent.TakeDamage(new DamageInfo(flame, amount, 0f, -1f, instigator, null, null, DamageInfo.SourceCategory.ThingOrUnknown, null)).AssociateWithLog(battleLogEntry_DamageTaken);
         }
         flameCounter = 0;
     }
 }
Exemplo n.º 18
0
        protected override void Impact(Thing hitThing)
        {
            Map map = base.Map;

            base.Impact(hitThing);
            BattleLogEntry_RangedImpact battleLogEntry_RangedImpact = new BattleLogEntry_RangedImpact(this.launcher, hitThing, this.intendedTarget.Thing, this.equipmentDef, this.def, this.targetCoverDef);

            Find.BattleLog.Add(battleLogEntry_RangedImpact);
            if (hitThing != null)
            {
                DamageDef damageDef        = this.def.projectile.damageDef;
                float     damageAmountMax  = (float)base.DamageAmount;
                float     damageAmount     = Rand.Range(0, damageAmountMax);
                float     armorPenetration = base.ArmorPenetration;
                float     y = this.ExactRotation.eulerAngles.y;

                Thing      launcher     = this.launcher;
                ThingDef   equipmentDef = this.equipmentDef;
                DamageInfo dinfo        = new DamageInfo(damageDef, damageAmount, armorPenetration, y, launcher, null, equipmentDef, DamageInfo.SourceCategory.ThingOrUnknown, this.intendedTarget.Thing);
                hitThing.TakeDamage(dinfo).AssociateWithLog(battleLogEntry_RangedImpact);
                Pawn pawn = hitThing as Pawn;
                if (pawn != null && pawn.stances != null && pawn.BodySize <= this.def.projectile.StoppingPower + 0.001f)
                {
                    pawn.stances.StaggerFor(95);
                }
            }
            else
            {
                SoundDefOf.BulletImpact_Ground.PlayOneShot(new TargetInfo(base.Position, map, false));
                MoteMaker.MakeStaticMote(this.ExactPosition, map, ThingDefOf.Mote_ShotHit_Dirt, 1f);
                if (base.Position.GetTerrain(map).takeSplashes)
                {
                    MoteMaker.MakeWaterSplash(this.ExactPosition, map, Mathf.Sqrt((float)base.DamageAmount) * 1f, 4f);
                }
            }
        }
        protected override void Impact(Thing hitThing)
        {
            Map map = base.Map;

            base.Impact(hitThing);
            IntVec3   position         = base.Position;
            Map       map2             = map;
            float     explosionRadius  = this.def.projectile.explosionRadius;
            DamageDef bomb             = DamageDefOf.Bomb;
            Thing     launcher         = this.launcher;
            int       damageAmount     = base.DamageAmount;
            float     armorPenetration = base.ArmorPenetration;
            ThingDef  equipmentDef     = this.equipmentDef;

            GenExplosion.DoExplosion(position, map2, explosionRadius, bomb, launcher, damageAmount, armorPenetration, null, equipmentDef, this.def, this.intendedTarget.Thing, null, 0f, 1, false, null, 0f, 1, 0f, false);
            CellRect cellRect = CellRect.CenteredOn(base.Position, 5);

            cellRect.ClipInsideMap(map);
            for (int i = 0; i < 3; i++)
            {
                IntVec3 randomCell = cellRect.RandomCell;
                this.DoFireExplosion(randomCell, map, 3.9f);
            }
        }
Exemplo n.º 20
0
 // Token: 0x060052C8 RID: 21192 RVA: 0x002628C0 File Offset: 0x00260CC0
 public override void Impact(Thing hitThing)
 {
     if (hitThing is Pawn)
     {
         Vector3 drawPos = hitThing.DrawPos;
         drawPos.y          = this.ExactPosition.y;
         this.ExactPosition = drawPos;
         base.Position      = this.ExactPosition.ToIntVec3();
     }
     if (this.def.projectile.explosionDelay == 0)
     {
         base.Impact(hitThing);
         return;
     }
     else
     {
         this.landed            = true;
         this.ticksToDetonation = this.def.projectile.explosionDelay;
         DamageDef damageDef = this.def.projectile.damageDef;
         Thing     launcher  = this.launcher;
         GenExplosion.NotifyNearbyPawnsOfDangerousExplosive(this, damageDef, (launcher != null) ? launcher.Faction : null);
     }
     base.Impact(hitThing);
 }
Exemplo n.º 21
0
        // Token: 0x06000035 RID: 53 RVA: 0x00002C3C File Offset: 0x00000E3C
        protected virtual void ImpactDirectly(Thing hitThing, Map map)
        {
            base.Impact(hitThing);
            BattleLogEntry_RangedImpact battleLogEntry_RangedImpact = new BattleLogEntry_RangedImpact(this.launcher, hitThing, this.intendedTarget.Thing, this.equipmentDef, this.def, null);

            Find.BattleLog.Add(battleLogEntry_RangedImpact);
            if (hitThing != null)
            {
                int        damageAmountBase = this.def.projectile.GetDamageAmount(this.launcher);
                DamageDef  damageDef        = this.def.projectile.damageDef;
                float      y            = this.ExactRotation.eulerAngles.y;
                Thing      launcher     = this.launcher;
                ThingDef   equipmentDef = this.equipmentDef;
                DamageInfo dinfo        = new DamageInfo(damageDef, damageAmountBase, 0, y, launcher, null, equipmentDef, DamageInfo.SourceCategory.ThingOrUnknown);
                hitThing.TakeDamage(dinfo).AssociateWithLog(battleLogEntry_RangedImpact);
                return;
            }
            SoundDefOf.BulletImpact_Ground.PlayOneShot(new TargetInfo(base.Position, map, false));
            MoteMaker.MakeStaticMote(this.ExactPosition, map, ThingDefOf.Mote_ShotHit_Dirt, 1f);
            if (base.Position.GetTerrain(map).takeSplashes)
            {
                MoteMaker.MakeWaterSplash(this.ExactPosition, map, (float)((double)Mathf.Sqrt((float)this.def.projectile.GetDamageAmount(this.launcher)) * 1.0), 4f);
            }
        }
Exemplo n.º 22
0
        // Token: 0x0600003B RID: 59 RVA: 0x000035C8 File Offset: 0x000017C8
        public static void RepulseEffect(Pawn p, DamageDef def, int dmg)
        {
            if (p == null || def == null || p.Map == null)
            {
                return;
            }

            var cellList = GenAdj.CellsAdjacent8Way(p).ToList();

            if (cellList.Count <= 0)
            {
                return;
            }

            foreach (var c in cellList)
            {
                var cellThings = c.GetThingList(p.Map);
                if (cellThings.Count <= 0)
                {
                    continue;
                }

                foreach (var thing in cellThings)
                {
                    if (thing is not Pawn pawn)
                    {
                        continue;
                    }

                    var dinfo = default(DamageInfo);
                    dinfo.Def = def;
                    dinfo.SetAmount(dmg);
                    pawn.TakeDamage(dinfo);
                }
            }
        }
        public static bool RecoverFromUnwalkablePositionOrKill(IntVec3 c, Map map)
        {
            List <Thing> tmpThings = new List <Thing>();

            if (!c.InBounds(map) || c.Walkable(map))
            {
                return(false);
            }
            tmpThings.AddRange(c.GetThingList(map));
            for (int i = 0; i < tmpThings.Count; i++)
            {
                Pawn pawn = tmpThings[i] as Pawn;
                if (pawn != null)
                {
                    IntVec3 position;
                    if (CellFinder.TryFindBestPawnStandCell(pawn, out position, false))
                    {
                        pawn.Position = position;
                        pawn.Notify_Teleported(true);
                    }
                    else
                    {
                        DamageDef      crush      = DamageDefOf.Crush;
                        int            amount     = 99999;
                        BodyPartRecord brain      = pawn.health.hediffSet.GetBrain();
                        DamageInfo     damageInfo = new DamageInfo(crush, amount, -1f, null, brain, null, DamageInfo.SourceCategory.Collapse);
                        pawn.TakeDamage(damageInfo);
                        if (!pawn.Dead)
                        {
                            pawn.Kill(new DamageInfo?(damageInfo), null);
                        }
                    }
                }
            }
            return(false);
        }
Exemplo n.º 24
0
        private void DoAoEAttack(IntVec3 center, bool isExplosion, float radius, DamageDef damageType, int damageAmount)
        {
            this.nextAoEAttack = this.Props.aoeCooldownTicks + Find.TickManager.TicksGame;
            IEnumerable <IntVec3> targetCells = GenRadial.RadialCellsAround(center, radius, false);

            foreach (IntVec3 curCell in targetCells)
            {
                if (curCell.IsValid && curCell.InBounds(this.Pawn.Map))
                {
                    if (isExplosion)
                    {
                        GenExplosion.DoExplosion(curCell, this.Pawn.Map, .4f, damageType, this.Pawn, damageAmount, Rand.Range(0, damageAmount), TorannMagicDefOf.TM_SoftExplosion, null, null, null, null, 0f, 1, false, null, 0f, 0, 0.0f, false);
                    }
                    else
                    {
                        List <Thing> thingList = curCell.GetThingList(this.Pawn.Map);
                        for (int j = 0; j < thingList.Count(); j++)
                        {
                            DamageEntities(thingList[j], damageAmount, damageType, this.Pawn);
                        }
                    }
                }
            }
        }
Exemplo n.º 25
0
        /// <summary>
        /// Calculates primary DamageInfo from verb, as well as secondary DamageInfos to apply (i.e. surprise attack stun damage).
        /// Also calculates the maximum body height an attack can target, so we don't get rabbits biting out a colonist's eye or something.
        /// </summary>
        /// <param name="target">The target damage is to be applied to</param>
        /// <returns>Collection with primary DamageInfo, followed by secondary types</returns>
        private IEnumerable <DamageInfo> DamageInfosToApply(LocalTargetInfo target, bool isCrit = false)
        {
            //START 1:1 COPY Verb_MeleeAttack.DamageInfosToApply
            float damAmount    = this.verbProps.AdjustedMeleeDamageAmount(this, base.CasterPawn);
            var   critModifier = isCrit && verbProps.meleeDamageDef.armorCategory == DamageArmorCategoryDefOf.Sharp &&
                                 !CasterPawn.def.race.Animal
                ? 2
                : 1;
            var              armorPenetration = verbProps.AdjustedArmorPenetration(this, CasterPawn) * (EquipmentSource?.GetStatValue(CE_StatDefOf.MeleePenetrationFactor) ?? 1) * critModifier;
            DamageDef        damDef           = verbProps.meleeDamageDef;
            BodyPartGroupDef bodyPartGroupDef = null;
            HediffDef        hediffDef        = null;

            damAmount = Rand.Range(damAmount * 0.8f, damAmount * 1.2f);
            if (base.CasterIsPawn)
            {
                bodyPartGroupDef = this.verbProps.AdjustedLinkedBodyPartsGroup(this.tool);
                if (damAmount >= 1f)
                {
                    if (base.HediffCompSource != null)
                    {
                        hediffDef = base.HediffCompSource.Def;
                    }
                }
                else
                {
                    damAmount = 1f;
                    damDef    = DamageDefOf.Blunt;
                }
            }
            ThingDef source;

            if (base.EquipmentSource != null)
            {
                source = base.EquipmentSource.def;
            }
            else
            {
                source = base.CasterPawn.def;
            }
            Vector3   direction = (target.Thing.Position - base.CasterPawn.Position).ToVector3();
            DamageDef def       = damDef;
            //END 1:1 COPY
            BodyPartHeight bodyRegion = GetBodyPartHeightFor(target);                                                                                           //Custom // Add check for body height
            //START 1:1 COPY
            DamageInfo mainDinfo = new DamageInfo(def, damAmount, armorPenetration, -1f, caster, null, source, DamageInfo.SourceCategory.ThingOrUnknown, null); //Alteration

            mainDinfo.SetBodyRegion(bodyRegion, BodyPartDepth.Outside);                                                                                         //Alteration
            mainDinfo.SetWeaponBodyPartGroup(bodyPartGroupDef);
            mainDinfo.SetWeaponHediff(hediffDef);
            mainDinfo.SetAngle(direction);
            yield return(mainDinfo);

            // Apply critical damage
            if (isCrit && !CasterPawn.def.race.Animal && verbProps.meleeDamageDef.armorCategory != DamageArmorCategoryDefOf.Sharp)
            {
                var critAmount = GenMath.RoundRandom(mainDinfo.Amount * 0.25f);
                var critDinfo  = new DamageInfo(DamageDefOf.Stun, critAmount, armorPenetration, //Ignore armor //armorPenetration, //Armor Penetration
                                                -1, caster, null, source);
                critDinfo.SetBodyRegion(bodyRegion, BodyPartDepth.Outside);
                critDinfo.SetWeaponBodyPartGroup(bodyPartGroupDef);
                critDinfo.SetWeaponHediff(hediffDef);
                critDinfo.SetAngle(direction);
                yield return(critDinfo);
            }
        }
Exemplo n.º 26
0
        /// <summary>
        /// Calculates primary DamageInfo from verb, as well as secondary DamageInfos to apply (i.e. surprise attack stun damage).
        /// Also calculates the maximum body height an attack can target, so we don't get rabbits biting out a colonist's eye or something.
        /// </summary>
        /// <param name="target">The target damage is to be applied to</param>
        /// <returns>Collection with primary DamageInfo, followed by secondary types</returns>
        private IEnumerable <DamageInfo> DamageInfosToApply(LocalTargetInfo target, bool isCrit = false)
        {
            //START 1:1 COPY Verb_MeleeAttack.DamageInfosToApply
            float            damAmount        = this.verbProps.AdjustedMeleeDamageAmount(this, base.CasterPawn);
            float            armorPenetration = (isCrit && verbProps.meleeDamageDef.armorCategory == DamageArmorCategoryDefOf.Sharp && !CasterPawn.def.race.Animal ? 2 : 1) * this.verbProps.AdjustedArmorPenetration(this, base.CasterPawn);
            DamageDef        damDef           = verbProps.meleeDamageDef;
            BodyPartGroupDef bodyPartGroupDef = null;
            HediffDef        hediffDef        = null;

            damAmount = Rand.Range(damAmount * 0.8f, damAmount * 1.2f);
            if (base.CasterIsPawn)
            {
                bodyPartGroupDef = this.verbProps.AdjustedLinkedBodyPartsGroup(this.tool);
                if (damAmount >= 1f)
                {
                    if (base.HediffCompSource != null)
                    {
                        hediffDef = base.HediffCompSource.Def;
                    }
                }
                else
                {
                    damAmount = 1f;
                    damDef    = DamageDefOf.Blunt;
                }
            }
            ThingDef source;

            if (base.EquipmentSource != null)
            {
                source = base.EquipmentSource.def;
            }
            else
            {
                source = base.CasterPawn.def;
            }
            Vector3   direction = (target.Thing.Position - base.CasterPawn.Position).ToVector3();
            DamageDef def       = damDef;
            //END 1:1 COPY
            BodyPartHeight bodyRegion = GetBodyPartHeightFor(target);   //Custom // Add check for body height
            //START 1:1 COPY
            Thing      caster    = this.caster;
            DamageInfo mainDinfo = new DamageInfo(def, damAmount, armorPenetration, -1f, caster, null, source, DamageInfo.SourceCategory.ThingOrUnknown, null); //Alteration

            mainDinfo.SetBodyRegion(bodyRegion, BodyPartDepth.Outside);                                                                                         //Alteration
            mainDinfo.SetWeaponBodyPartGroup(bodyPartGroupDef);
            mainDinfo.SetWeaponHediff(hediffDef);
            mainDinfo.SetAngle(direction);
            yield return(mainDinfo);

            // Apply secondary damage on surprise attack

            /*
             * if (this.surpriseAttack && ((this.verbProps.surpriseAttack != null && !this.verbProps.surpriseAttack.extraMeleeDamages.NullOrEmpty<ExtraMeleeDamage>()) || this.tool == null || this.tool.surpriseAttack == null || this.tool.surpriseAttack.extraMeleeDamages.NullOrEmpty<ExtraMeleeDamage>()))
             *          {
             *                  IEnumerable<ExtraMeleeDamage> extraDamages = Enumerable.Empty<ExtraMeleeDamage>();
             *                  if (this.verbProps.surpriseAttack != null && this.verbProps.surpriseAttack.extraMeleeDamages != null)
             *                  {
             *                          extraDamages = extraDamages.Concat(this.verbProps.surpriseAttack.extraMeleeDamages);
             *                  }
             *                  if (this.tool != null && this.tool.surpriseAttack != null && !this.tool.surpriseAttack.extraMeleeDamages.NullOrEmpty<ExtraMeleeDamage>())
             *                  {
             *                          extraDamages = extraDamages.Concat(this.tool.surpriseAttack.extraMeleeDamages);
             *                  }
             *                  foreach (ExtraMeleeDamage extraDamage in extraDamages)
             *                  {
             *                          int extraDamageAmount = GenMath.RoundRandom(extraDamage.AdjustedDamageAmount(this, base.CasterPawn));
             *                          float extraDamageArmorPenetration = extraDamage.AdjustedArmorPenetration(this, base.CasterPawn);
             *                          def = extraDamage.def;
             *                          num2 = (float)extraDamageAmount;
             *                          num = extraDamageArmorPenetration;
             *                          caster = this.caster;
             *                          DamageInfo extraDinfo = new DamageInfo(def, num2, num, -1f, caster, null, source, DamageInfo.SourceCategory.ThingOrUnknown, null);
             *                          extraDinfo.SetBodyRegion(BodyPartHeight.Undefined, BodyPartDepth.Outside);
             *                          extraDinfo.SetWeaponBodyPartGroup(bodyPartGroupDef);
             *                          extraDinfo.SetWeaponHediff(hediffDef);
             *                          extraDinfo.SetAngle(direction);
             *                          yield return extraDinfo;
             *                  }
             *          }
             */
            //END 1:1 COPY
            // Apply critical damage
            if (isCrit && !CasterPawn.def.race.Animal && !(verbProps.meleeDamageDef.armorCategory == DamageArmorCategoryDefOf.Sharp))
            {
                var critAmount = GenMath.RoundRandom(mainDinfo.Amount * 0.25f);
                var critDinfo  = new DamageInfo(DamageDefOf.Stun, critAmount, armorPenetration, //Ignore armor //armorPenetration, //Armor Penetration
                                                -1, caster, null, source);
                critDinfo.SetBodyRegion(bodyRegion, BodyPartDepth.Outside);
                critDinfo.SetWeaponBodyPartGroup(bodyPartGroupDef);
                critDinfo.SetWeaponHediff(hediffDef);
                critDinfo.SetAngle(direction);
                yield return(critDinfo);
            }
        }
Exemplo n.º 27
0
        // RimWorld.Verb_MeleeAttack
        public static void DamageInfosToApply_PostFix(Verb_MeleeAttack __instance, ref IEnumerable <DamageInfo> __result, LocalTargetInfo target)
        {
            List <DamageInfo> newList = new List <DamageInfo>();
            //__result = null;
            ThingWithComps ownerEquipment = __instance.ownerEquipment;

            if (ownerEquipment != null)
            {
                //Log.Message("1");
                ThingComp comp = ownerEquipment.AllComps.FirstOrDefault((ThingComp x) => x is CompSlotLoadable);
                if (comp != null)
                {
                    //Log.Message("2");
                    CompSlotLoadable compSlotLoadable = comp as CompSlotLoadable;
                    if (compSlotLoadable.Slots != null && compSlotLoadable.Slots.Count > 0)
                    {
                        //Log.Message("3");
                        List <SlotLoadable> statSlots = compSlotLoadable.Slots.FindAll((SlotLoadable z) => !z.IsEmpty() && ((SlotLoadableDef)z.def).doesChangeStats == true);
                        if (statSlots != null && statSlots.Count > 0)
                        {
                            //Log.Message("4");
                            foreach (SlotLoadable slot in statSlots)
                            {
                                //Log.Message("5");
                                CompSlottedBonus slotBonus = slot.SlotOccupant.TryGetComp <CompSlottedBonus>();
                                if (slotBonus != null)
                                {
                                    //Log.Message("6");
                                    Type superClass = __instance.GetType().BaseType;
                                    if (slotBonus.Props.damageDef != null)
                                    {
                                        //Log.Message("7");
                                        float            num = __instance.verbProps.AdjustedMeleeDamageAmount(__instance, __instance.CasterPawn, __instance.ownerEquipment);
                                        DamageDef        def = __instance.verbProps.meleeDamageDef;
                                        BodyPartGroupDef weaponBodyPartGroup = null;
                                        HediffDef        weaponHediff        = null;
                                        if (__instance.CasterIsPawn)
                                        {
                                            //Log.Message("8");
                                            if (num >= 1f)
                                            {
                                                weaponBodyPartGroup = __instance.verbProps.linkedBodyPartsGroup;
                                                if (__instance.ownerHediffComp != null)
                                                {
                                                    weaponHediff = __instance.ownerHediffComp.Def;
                                                }
                                            }
                                            else
                                            {
                                                num = 1f;
                                                def = DamageDefOf.Blunt;
                                            }
                                        }

                                        //Log.Message("9");
                                        ThingDef def2;
                                        if (__instance.ownerEquipment != null)
                                        {
                                            def2 = __instance.ownerEquipment.def;
                                        }
                                        else
                                        {
                                            def2 = __instance.CasterPawn.def;
                                        }

                                        //Log.Message("10");
                                        Vector3 angle = (target.Thing.Position - __instance.CasterPawn.Position).ToVector3();

                                        //Log.Message("11");
                                        Thing caster = __instance.caster;

                                        //Log.Message("12");
                                        int newdamage = GenMath.RoundRandom(num);
//                                        Log.Message("applying damage "+newdamage+" out of "+num);
                                        DamageInfo damageInfo = new DamageInfo(slotBonus.Props.damageDef, newdamage, -1f, caster, null, def2);
                                        damageInfo.SetBodyRegion(BodyPartHeight.Undefined, BodyPartDepth.Outside);
                                        damageInfo.SetWeaponBodyPartGroup(weaponBodyPartGroup);
                                        damageInfo.SetWeaponHediff(weaponHediff);
                                        damageInfo.SetAngle(angle);

                                        //Log.Message("13");
                                        newList.Add(damageInfo);

                                        __result = newList.AsEnumerable <DamageInfo>();
                                    }
                                    SlotBonusProps_VampiricEffect vampiricEffect = slotBonus.Props.vampiricHealChance;
                                    if (vampiricEffect != null)
                                    {
                                        //Log.Message("vampiricHealingCalled");
                                        float randValue = Rand.Value;
                                        //Log.Message("randValue = " + randValue.ToString());

                                        if (randValue <= vampiricEffect.chance)
                                        {
                                            MoteMaker.ThrowText(__instance.CasterPawn.DrawPos, __instance.CasterPawn.Map, "Vampiric Effect: Success", 6f);
                                            //MoteMaker.ThrowText(__instance.CasterPawn.DrawPos, __instance.CasterPawn.Map, "Success".Translate(), 6f);
                                            ApplyHealing(__instance.caster, vampiricEffect.woundLimit, target.Thing);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 28
0
        protected override bool TryCastShot()
        {
            bool continueAttack = true;

            if (this.CasterPawn.equipment.Primary == null)
            {
                Thing target = this.currentTarget.Thing;
                if (target != null && this.burstShotsLeft > 0)
                {
                    int            dmgNum  = this.GetAttackDmg(this.CasterPawn);
                    BodyPartRecord hitPart = null;
                    DamageDef      dmgType = TMDamageDefOf.DamageDefOf.TM_TigerStrike;
                    if (verVal > 0 && Rand.Chance(.1f))
                    {
                        TM_Action.DamageEntities(target, null, 4, DamageDefOf.Stun, this.CasterPawn);
                    }
                    if (verVal > 1 && Rand.Chance(.4f) && target is Pawn)
                    {
                        if (TM_Calc.IsMagicUser(target as Pawn))
                        {
                            CompAbilityUserMagic compMagic = target.TryGetComp <CompAbilityUserMagic>();
                            float manaDrain = Mathf.Clamp(compMagic.Mana.CurLevel, 0, .25f);
                            this.CasterPawn.health.hediffSet.GetFirstHediffOfDef(TorannMagicDefOf.TM_ChiHD).Severity += manaDrain * 100;
                            compMagic.Mana.CurLevel -= manaDrain;
                        }
                        else if (TM_Calc.IsMightUser(target as Pawn))
                        {
                            CompAbilityUserMight compMight = target.TryGetComp <CompAbilityUserMight>();
                            float staminaDrain             = Mathf.Clamp(compMight.Stamina.CurLevel, 0, .25f);
                            this.CasterPawn.health.hediffSet.GetFirstHediffOfDef(TorannMagicDefOf.TM_ChiHD).Severity += staminaDrain * 100;
                            compMight.Stamina.CurLevel -= staminaDrain;
                        }
                    }
                    if (verVal > 2 && Rand.Chance(.1f) && target is Pawn)
                    {
                        Pawn targetPawn = target as Pawn;
                        IEnumerable <BodyPartRecord> rangeOfParts = targetPawn.RaceProps.body.GetPartsWithTag(BodyPartTagDefOf.BloodPumpingSource).Concat(
                            targetPawn.RaceProps.body.GetPartsWithTag(BodyPartTagDefOf.BloodFiltrationSource).Concat(
                                targetPawn.RaceProps.body.GetPartsWithTag(BodyPartTagDefOf.BreathingPathway).Concat(
                                    targetPawn.RaceProps.body.GetPartsWithTag(BodyPartTagDefOf.SightSource))));

                        hitPart = rangeOfParts.RandomElement();
                        dmgNum  = Mathf.RoundToInt(dmgNum * 1.4f);
                    }
                    //DamageInfo dinfo2 = new DamageInfo(TMDamageDefOf.DamageDefOf.TM_TigerStrike, dmgNum, 0, (float)-1, this.CasterPawn, null, null, DamageInfo.SourceCategory.ThingOrUnknown);
                    TM_Action.DamageEntities(target, hitPart, dmgNum, dmgType, this.CasterPawn);
                    Vector3 strikeEndVec = this.currentTarget.CenterVector3;
                    strikeEndVec.x += Rand.Range(-.2f, .2f);
                    strikeEndVec.z += Rand.Range(-.2f, .2f);
                    Vector3 strikeStartVec = this.CasterPawn.DrawPos;
                    strikeStartVec.z += Rand.Range(-.2f, .2f);
                    strikeStartVec.x += Rand.Range(-.2f, .2f);
                    Vector3 angle = TM_Calc.GetVector(strikeStartVec, strikeEndVec);
                    TM_MoteMaker.ThrowGenericMote(TorannMagicDefOf.Mote_TigerStrike, strikeStartVec, this.CasterPawn.Map, .4f, .08f, .03f, .05f, 0, 8f, (Quaternion.AngleAxis(90, Vector3.up) * angle).ToAngleFlat(), (Quaternion.AngleAxis(90, Vector3.up) * angle).ToAngleFlat());
                    if (!target.DestroyedOrNull() && target is Pawn)
                    {
                        Pawn targetPawn = target as Pawn;
                        if (targetPawn.Downed || targetPawn.Dead)
                        {
                            continueAttack = false;
                        }
                    }
                    if (this.burstShotsLeft <= (10 - (4 + verVal)))
                    {
                        this.burstShotsLeft = 0;
                        continueAttack      = false;
                    }
                }
            }
            else
            {
                Messages.Message("MustBeUnarmed".Translate(
                                     this.CasterPawn.LabelCap,
                                     this.verbProps.label
                                     ), MessageTypeDefOf.RejectInput);
                this.burstShotsLeft = 0;
                return(false);
            }
            return(continueAttack);
        }
Exemplo n.º 29
0
            public static bool Prefix(Pawn pawn, ref float amount, ref float armorPenetration, BodyPartRecord part, ref DamageDef damageDef, out bool deflectedByMetalArmor, out bool diminishedByMetalArmor, ref float __result)
            {
                deflectedByMetalArmor  = false;
                diminishedByMetalArmor = false;

                // Apply shield damage reduction before apparel damage reduction
                if (damageDef.armorCategory != null)
                {
                    var armourRating = damageDef.armorCategory.armorRatingStat;
                    if (pawn.apparel != null)
                    {
                        // Multiple shields? Why not I guess
                        var equipmentList = pawn.apparel.WornApparel;
                        for (int i = 0; i < equipmentList.Count; i++)
                        {
                            var curEq = equipmentList[i];
                            if (curEq.IsShield(out CompShield sC) && sC.UsableNow && sC.CoversBodyPart(part))
                            {
                                float prevAmount = amount;
                                NonPublicMethods.ArmorUtility_ApplyArmor(ref amount, armorPenetration, curEq.GetStatValue(armourRating), curEq, ref damageDef, pawn, out bool metalArmour);

                                // Deflected
                                if (amount < 0.001f)
                                {
                                    deflectedByMetalArmor = metalArmour;
                                    __result = 0;
                                    return(false);
                                }

                                // Diminished
                                if (amount < prevAmount)
                                {
                                    diminishedByMetalArmor = metalArmour;
                                }
                            }
                        }
                    }
                }

                return(true);
            }
Exemplo n.º 30
0
        private IEnumerable <DamageInfo> DamageInfosToApply(LocalTargetInfo target)
        {
            float            num = verbProps.AdjustedMeleeDamageAmount(this, CasterPawn);
            float            armorPenetration = verbProps.AdjustedArmorPenetration(this, CasterPawn);
            DamageDef        def = verbProps.meleeDamageDef;
            BodyPartGroupDef bodyPartGroupDef = null;
            HediffDef        hediffDef        = null;

            num = Rand.Range(num * 0.8f, num * 1.2f);
            if (CasterIsPawn)
            {
                bodyPartGroupDef = verbProps.AdjustedLinkedBodyPartsGroup(tool);
                if (num >= 1f)
                {
                    if (base.HediffCompSource != null)
                    {
                        hediffDef = base.HediffCompSource.Def;
                    }
                }
                else
                {
                    num = 1f;
                    def = DamageDefOf.Blunt;
                }
            }
            ThingDef   source     = ((base.EquipmentSource == null) ? CasterPawn.def : base.EquipmentSource.def);
            Vector3    direction  = (target.Thing.Position - CasterPawn.Position).ToVector3();
            DamageInfo damageInfo = new DamageInfo(def, num, armorPenetration, -1f, caster, null, source);

            damageInfo.SetBodyRegion(BodyPartHeight.Undefined, BodyPartDepth.Outside);
            damageInfo.SetWeaponBodyPartGroup(bodyPartGroupDef);
            damageInfo.SetWeaponHediff(hediffDef);
            damageInfo.SetAngle(direction);
            yield return(damageInfo);

            if (tool != null && tool.extraMeleeDamages != null)
            {
                foreach (ExtraDamage extraMeleeDamage in tool.extraMeleeDamages)
                {
                    if (Rand.Chance(extraMeleeDamage.chance))
                    {
                        num        = extraMeleeDamage.amount;
                        num        = Rand.Range(num * 0.8f, num * 1.2f);
                        damageInfo = new DamageInfo(extraMeleeDamage.def, num, extraMeleeDamage.AdjustedArmorPenetration(this, CasterPawn), -1f, caster, null, source);
                        damageInfo.SetBodyRegion(BodyPartHeight.Undefined, BodyPartDepth.Outside);
                        damageInfo.SetWeaponBodyPartGroup(bodyPartGroupDef);
                        damageInfo.SetWeaponHediff(hediffDef);
                        damageInfo.SetAngle(direction);
                        yield return(damageInfo);
                    }
                }
            }
            if (!surpriseAttack || ((verbProps.surpriseAttack == null || verbProps.surpriseAttack.extraMeleeDamages.NullOrEmpty()) && (tool == null || tool.surpriseAttack == null || tool.surpriseAttack.extraMeleeDamages.NullOrEmpty())))
            {
                yield break;
            }
            IEnumerable <ExtraDamage> enumerable = Enumerable.Empty <ExtraDamage>();

            if (verbProps.surpriseAttack != null && verbProps.surpriseAttack.extraMeleeDamages != null)
            {
                enumerable = enumerable.Concat(verbProps.surpriseAttack.extraMeleeDamages);
            }
            if (tool != null && tool.surpriseAttack != null && !tool.surpriseAttack.extraMeleeDamages.NullOrEmpty())
            {
                enumerable = enumerable.Concat(tool.surpriseAttack.extraMeleeDamages);
            }
            foreach (ExtraDamage item in enumerable)
            {
                int        num2 = GenMath.RoundRandom(item.AdjustedDamageAmount(this, CasterPawn));
                float      armorPenetration2 = item.AdjustedArmorPenetration(this, CasterPawn);
                DamageInfo damageInfo2       = new DamageInfo(item.def, num2, armorPenetration2, -1f, caster, null, source);
                damageInfo2.SetBodyRegion(BodyPartHeight.Undefined, BodyPartDepth.Outside);
                damageInfo2.SetWeaponBodyPartGroup(bodyPartGroupDef);
                damageInfo2.SetWeaponHediff(hediffDef);
                damageInfo2.SetAngle(direction);
                yield return(damageInfo2);
            }
        }
Exemplo n.º 31
0
        private static bool ApplyArmor(ref float damAmount, ref float pierceAmount, float armorRating, Thing armorThing, DamageDef damageDef)
        {
            float originalDamage = damAmount;
            bool deflected = false;
            float penetrationChance = Mathf.Clamp((pierceAmount - armorRating) * 4, 0, 1);

            //Shot is deflected
            if (penetrationChance == 0 || Rand.Value > penetrationChance)
            {
                deflected = true;
            }
            //Damage calculations
            damAmount *= 1 - Mathf.Clamp(2 * armorRating - pierceAmount, 0, 1);

            //Damage armor
            if (armorThing != null)
            {
                float absorbedDamage = 0f;
                if (damageDef == absorbDamageDef)
                {
                    absorbedDamage = (originalDamage - damAmount) * (1 + pierceAmount);
                }
                else
                {
                    absorbedDamage = originalDamage * Mathf.Min(pierceAmount, 1f);
                }
                if (armorThing as Pawn == null)
                {
                    armorThing.TakeDamage(new DamageInfo(damageDef, Mathf.CeilToInt(absorbedDamage), null, null, null));
                }
                else
                {
                    damAmount += absorbedDamage;
                }
            }

            pierceAmount *= Mathf.Max(0, 1 - armorRating);
            return deflected;
        }