Ejemplo n.º 1
0
        private static bool Prefix(Pawn pawn, BodyPartGroupDef bodyPartGroupDef, ref Apparel __result)
        {
            Room room = pawn.GetRoom(RegionType.Set_Passable);

            if (room.isPrisonCell)
            {
                foreach (IntVec3 current in room.Cells)
                {
                    List <Thing> thingList = current.GetThingList(pawn.Map);
                    for (int i = 0; i < thingList.Count; i++)
                    {
                        if (thingList[i] is Apparel apparel &&
                            RaceAddonTools.CheckApparel(pawn, apparel.def) &&
                            apparel.def.apparel.bodyPartGroups.Contains(bodyPartGroupDef) &&
                            pawn.CanReserve(apparel, 1, -1, null, false) && !apparel.IsBurning() &&
                            ApparelUtility.HasPartsToWear(pawn, apparel.def))
                        {
                            __result = apparel;
                            return(false);
                        }
                    }
                }
            }
            __result = null;
            return(false);
        }
Ejemplo n.º 2
0
 public override void TransformValue(StatRequest req, ref float val)
 {
     if (req.HasThing)
     {
         Thing thing        = req.Thing as Apparel;
         float armorPenalty = 0f;
         foreach (ArmorFactor factor in armorFactors)
         {
             armorPenalty += thing.GetStatValue(factor.armorType) * factor.weight;
         }
         float weightPenalty = thing.GetStatValue(StatDefOf.Mass);
         if (val == 0f)
         {
             val = armorPenalty * weightPenalty;
         }
         else
         {
             val *= armorPenalty * weightPenalty;
         }
         List <BodyPartGroupDef> allBodyParts = thing.def.apparel.bodyPartGroups;
         float baseDiscomfort = 0f;
         for (int i = 0; i < allBodyParts.Count; i++)
         {
             BodyPartGroupDef bodyPart = allBodyParts[i];
             baseDiscomfort += bodyPart.GetModExtension <ApparelDiscomfortExtension>().baseDiscomfort;
         }
         val *= baseDiscomfort;
     }
 }
 private Thing FindRestraints( Pawn warden, BodyPartGroupDef bodyPartGroupDef )
 {
     // Is the warden carrying a restraint already?
     var restraint = warden.inventory.container.FirstOrDefault( thing => (
         ( thing.IsRestraints() )&&
         ( thing.def.apparel.bodyPartGroups.Contains( bodyPartGroupDef ) )
     ) );
     if( restraint == null )
     {   // Nope, find one in the colony
         var restraints = Data.AllRestraintsOfColony( bodyPartGroupDef );
         if( restraints == null )
         {
             return null;
         }
         restraint = restraints.Find( thing => (
             ( !thing.IsForbidden( Faction.OfPlayer ) )&&
             ( warden.CanReserveAndReach(
                 thing,
                 PathEndMode.ClosestTouch,
                 warden.NormalMaxDanger(),
                 1 )
             )
         ) );
     }
     return restraint;
 }
Ejemplo n.º 4
0
        private static Apparel FindGarmentCoveringPart(Pawn pawn, BodyPartGroupDef bodyPartGroupDef)
        {
            Predicate <Thing> validator = apparel => apparel.def.apparel.bodyPartGroups.Contains(bodyPartGroupDef) & pawn.CanReserve(apparel);

            return((Apparel)GenClosest.ClosestThing_Global_Reachable(pawn.Position,
                                                                     Find.ListerThings.ThingsInGroup(ThingRequestGroup.Apparel), PathEndMode.InteractionCell,
                                                                     traverseParams, 20, validator));
        }
 // Token: 0x0600003A RID: 58 RVA: 0x00004558 File Offset: 0x00002758
 internal static string GetNewRecord(BodyPartGroupDef BPGD, int priority, float apparelArcticEff,
                                     float apparelDesertEff, float apparelJungleEff, float apparelStoneEff, float apparelWoodlandEff,
                                     float apparelUrbanEff, float apparelnotDefinedEff)
 {
     return(BPGD.defName + ";" + priority + ";" + (int)(apparelArcticEff * 1000f) + ";" +
            (int)(apparelDesertEff * 1000f) + ";" + (int)(apparelJungleEff * 1000f) + ";" +
            (int)(apparelStoneEff * 1000f) + ";" + (int)(apparelWoodlandEff * 1000f) + ";" +
            (int)(apparelUrbanEff * 1000f) + ";" + (int)(apparelnotDefinedEff * 1000f));
 }
Ejemplo n.º 6
0
        internal static bool Prefix(ref float __result, HediffSet diffSet, BodyPartGroupDef bodyPartGroup)
        {
            var primary = diffSet.pawn.equipment?.Primary;

            if (primary?.def.tools != null && primary.def.tools.Any(t => t.linkedBodyPartsGroup == bodyPartGroup))
            {
                __result = 1;
                return(false);
            }
            return(true);
        }
Ejemplo n.º 7
0
 public bool Covers(BodyPartGroupDef bp)
 {
     for (int i = 0; i < aps.Count; i++)
     {
         if (aps[i].thing.apparel.bodyPartGroups.Contains(bp))
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 8
0
        public override void DefsLoaded()
        {
            base.DefsLoaded();
            setting_HoursUntilUncomfortable = Settings.GetHandle <int>("AIU_setting_HoursUntilUncomfortable", "AIU_HoursUntilUncomfortable_title".Translate(), "AIU_HoursUntilUncomfortable_desc".Translate(), 48, Validators.IntRangeValidator(1, 1440));
            //setting_DiscomfortRecoveryMultiplier = Settings.GetHandle<float>("AIU_setting_DiscomfortRecoveryMultiplier", "AIU_DiscomfortRecoveryMultiplier_title".Translate(), "AIU_DiscomfortRecoveryMultiplier_desc".Translate(), 0.33f, Validators.FloatRangeValidator(0.01f, 128f));
            setting_GlobalDiscomfortMultiplier = Settings.GetHandle <float>("AIU_setting_GlobalDiscomfortMultiplier", "AIU_GlobalDiscomfortMultiplier_title".Translate(), "AIU_GlobalDiscomfortMultiplier_desc".Translate(), 1f, Validators.FloatRangeValidator(0.01f, 128f));
            setting_HoursUntilComfortable      = Settings.GetHandle <int>("AIU_setting_HoursUntilComfortable", "AIU_HourUntilComfortable_title".Translate(), "AIU_HoursUntilComfortable_desc".Translate(), 8, Validators.IntRangeValidator(1, 1440));
            setting_DisableThought             = Settings.GetHandle <bool>("AIU_setting_DisableThought", "AIU_DisableThought_title".Translate(), "AIU_DisableThought_desc".Translate(), false);
            List <BodyPartGroupDef> bodyPartGroups = DefDatabase <BodyPartGroupDef> .AllDefsListForReading;
            BodyDef defaultBody = BodyDefOf.Human;

            for (int i = 0; i < bodyPartGroups.Count; i++)
            {
                BodyPartGroupDef groupDef = bodyPartGroups[i];
                if (groupDef.modExtensions == null)
                {
                    groupDef.modExtensions = new List <DefModExtension> {
                    };
                }
                if (!groupDef.HasModExtension <ApparelDiscomfortExtension>())
                {
                    ApparelDiscomfortExtension extension       = new ApparelDiscomfortExtension();
                    List <BodyPartRecord>      allDefaultParts = defaultBody.AllParts;
                    for (int i2 = 0; i2 < allDefaultParts.Count; i2++)
                    {
                        if (!allDefaultParts[i2].IsInGroup(groupDef))
                        {
                            continue;
                        }
                        if (allDefaultParts[i2].depth == BodyPartDepth.Inside)
                        {
                            continue;
                        }
                        extension.baseDiscomfort += allDefaultParts[i2].coverageAbs;
                    }
                    groupDef.modExtensions.Add(extension);
                }
            }
            List <ThingDef> allHumanlikes = DefDatabase <ThingDef> .AllDefsListForReading.FindAll(x => x.race != null && x.race.Humanlike);

            foreach (ThingDef humanlike in allHumanlikes)
            {
                if (humanlike.comps == null)
                {
                    //Logger.Message("Adding empty list to " + humanlike.defName);
                    humanlike.comps = new List <CompProperties>()
                    {
                    };
                }

                humanlike.comps.Add(new CompProperties(typeof(DiscomfortComp)));
            }
        }
Ejemplo n.º 9
0
 public bool Covers(BodyPartGroupDef bp)
 {
     for (int i = 0; i < aps.Count; i++)
     {
         ThingStuffPair thingStuffPair = aps[i];
         if (thingStuffPair.thing.apparel.bodyPartGroups.Contains(bp))
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 10
0
        private IEnumerable <DamageInfo> DamageInfosToApply(LocalTargetInfo target)
        {
            var damAmount        = verbProps.AdjustedMeleeDamageAmount(this, base.CasterPawn);
            var armorPenetration = verbProps.AdjustedArmorPenetration(this, base.CasterPawn);
            var damDef           = verbProps.meleeDamageDef;
            BodyPartGroupDef bodyPartGroupDef = null;
            HediffDef        hediffDef        = null;

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

            var source = EquipmentSource != null ? EquipmentSource.def : base.CasterPawn.def;

            var direction  = (target.Thing.Position - base.CasterPawn.Position).ToVector3();
            var def        = damDef;
            var num        = damAmount;
            var num2       = armorPenetration;
            var instigator = caster;
            var mainDinfo  = new DamageInfo(def, num, num2, -1f, instigator, null, source);

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

            if (!surpriseAttack ||
                (verbProps.surpriseAttack == null || verbProps.surpriseAttack.extraMeleeDamages.NullOrEmpty()) &&
                (tool == null || tool.surpriseAttack == null || tool.surpriseAttack.extraMeleeDamages.NullOrEmpty()))
            {
                yield break;
            }

            var extraDamages = Enumerable.Empty <ExtraDamage>();

            if (verbProps.surpriseAttack is { extraMeleeDamages : { } })
Ejemplo n.º 11
0
 public static void PostFix(ref float __result, Tool tool, Pawn attacker, HediffComp_VerbGiver hediffCompSource)
 {
     //EliteBionicsFrameworkMain.LogError("Dump vars: " + __result + ", " + tool.LabelCap + ", " + attacker.Name + ", " + hediffCompSource);
     if (attacker != null)
     {
         // There is an attacker.
         int   tempLinearAdjustment  = 0;
         float tempScalingAdjustment = 1;
         // Handle several cases.
         if (ToolFinderUtils.ToolIsOriginalToolOfPawn(tool, attacker))
         {
             // Attacks by bare-hand; no hediff source.
             // May have implant or no implant...
             BodyPartGroupDef hostGroup = tool.linkedBodyPartsGroup;
             foreach (HediffWithComps candidateHediff in attacker.health.hediffSet.GetHediffs <HediffWithComps>())
             {
                 if (!(candidateHediff is Hediff_Implant))
                 {
                     // Normal hediff only.
                     continue;
                 }
                 // I think in some cases the Part can be null, especially when for whole-body hediffs.
                 if ((bool)(candidateHediff.Part?.IsInGroup(hostGroup)))
                 {
                     // Relevant.
                     HediffComp_ToolPowerAdjust adjustmentComps = candidateHediff.TryGetComp <HediffComp_ToolPowerAdjust>();
                     if (adjustmentComps != null)
                     {
                         // Have adjustment comps
                         __result *= adjustmentComps.Props.ActualScalingFactor;
                     }
                 }
             }
         }
         else if (hediffCompSource != null)
         {
             // Attacks by bionic parts; bionic may have power adjustment components.
             if (ToolPowerAdjuster.CalculatePowerAdjustmentDueToImplants(attacker, hediffCompSource.parent.Part, ref tempLinearAdjustment, ref tempScalingAdjustment))
             {
                 // Successfully calculated.
                 __result *= tempScalingAdjustment;
             }
             if (ToolPowerAdjuster.CalculatePowerAdjustmentDueToToolUpgrade(attacker, hediffCompSource.parent.Part, tool, ref tempLinearAdjustment, ref tempScalingAdjustment))
             {
                 // Successfully calculated.
                 __result *= tempScalingAdjustment;
             }
         }
     }
 }
Ejemplo n.º 12
0
 public static void PostFix(ref float __result, Tool tool, Pawn attacker, HediffComp_VerbGiver hediffCompSource)
 {
     // __result already has the scaling multipliers within it.
     if (attacker != null)
     {
         // There is an attacker.
         int   tempLinearAdjustment  = 0;
         float tempScalingAdjustment = 1;
         // Handle several cases.
         if (ToolFinderUtils.ToolIsOriginalToolOfPawn(tool, attacker))
         {
             // Attacks by bare-hand; no hediff source.
             // May have implant or no implant...
             BodyPartGroupDef hostGroup = tool.linkedBodyPartsGroup;
             foreach (HediffWithComps candidateHediff in attacker.health.hediffSet.GetHediffs <HediffWithComps>())
             {
                 if (!(candidateHediff is Hediff_Implant))
                 {
                     // Normal hediff only.
                     continue;
                 }
                 if (candidateHediff.Part.IsInGroup(hostGroup))
                 {
                     // Relevant.
                     HediffComp_ToolPowerAdjust adjustmentComps = candidateHediff.TryGetComp <HediffComp_ToolPowerAdjust>();
                     if (adjustmentComps != null)
                     {
                         // Have adjustment comps
                         __result += adjustmentComps.Props.linearAdjustment;
                     }
                 }
             }
         }
         else if (hediffCompSource != null)
         {
             // Attacks by bionic parts; bionic may have power adjustment components.
             if (ToolPowerAdjuster.CalculatePowerAdjustmentDueToImplants(attacker, hediffCompSource.parent.Part, ref tempLinearAdjustment, ref tempScalingAdjustment))
             {
                 // Successfully calculated.
                 __result += tempLinearAdjustment;
             }
             if (ToolPowerAdjuster.CalculatePowerAdjustmentDueToToolUpgrade(attacker, hediffCompSource.parent.Part, tool, ref tempLinearAdjustment, ref tempScalingAdjustment))
             {
                 // Successfully calculated.
                 __result += tempLinearAdjustment;
             }
         }
     }
 }
Ejemplo n.º 13
0
 public Apparel FirstApparelOnBodyPartGroup(BodyPartGroupDef g)
 {
     for (int i = 0; i < this.wornApparel.Count; i++)
     {
         Apparel apparel = this.wornApparel[i];
         for (int j = 0; j < apparel.def.apparel.bodyPartGroups.Count; j++)
         {
             if (apparel.def.apparel.bodyPartGroups[j] == BodyPartGroupDefOf.Torso)
             {
                 return(apparel);
             }
         }
     }
     return(null);
 }
Ejemplo n.º 14
0
 public bool BodyPartGroupIsCovered(BodyPartGroupDef bp)
 {
     for (int i = 0; i < this.wornApparel.Count; i++)
     {
         Apparel apparel = this.wornApparel[i];
         for (int j = 0; j < apparel.def.apparel.bodyPartGroups.Count; j++)
         {
             if (apparel.def.apparel.bodyPartGroups[j] == bp)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Ejemplo n.º 15
0
 static bool IsHeadwear(ApparelProperties apparelProperties)
 {
     if (apparelProperties.LastLayer == ApparelLayerDefOf.Overhead)
     {
         return(true);
     }
     for (int i = 0; i < apparelProperties.bodyPartGroups.Count; ++i)
     {
         BodyPartGroupDef group = apparelProperties.bodyPartGroups[i];
         if (group == BodyPartGroupDefOf.FullHead || group == BodyPartGroupDefOf.UpperHead || group == BodyPartGroupDefOf.Eyes)
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 16
0
        public override string ExplanationPart(StatRequest req)
        {
            StringBuilder explanation = new StringBuilder();

            explanation.AppendLine("AIU_DiscomfortExplanation1".Translate());
            if (req.HasThing)
            {
                Thing thing = req.Thing;
                List <BodyPartGroupDef> allBodyParts = thing.def.apparel.bodyPartGroups;
                float sizeFactor = 0f;
                explanation.AppendLine();
                explanation.AppendLine("AIU_DiscomfortExplanation2".Translate());
                for (int i = 0; i < allBodyParts.Count; i++)
                {
                    BodyPartGroupDef bodyPart = allBodyParts[i];
                    sizeFactor += bodyPart.GetModExtension <ApparelDiscomfortExtension>().baseDiscomfort;
                    explanation.AppendLine("   " + bodyPart.label + ": +" + bodyPart.GetModExtension <ApparelDiscomfortExtension>().baseDiscomfort.ToStringByStyle(ToStringStyle.FloatTwo));
                }
                explanation.AppendLine();
                explanation.AppendLine("AIUDiscomfortExplanation4".Translate());
                for (int i = 0; i < armorFactors.Count; i++)
                {
                    if (i == 0)
                    {
                        explanation.AppendLine("   (" + armorFactors[i].armorType.label + ": " + thing.GetStatValue(armorFactors[i].armorType).ToStringPercent() + " x " + armorFactors[i].weight.ToStringByStyle(ToStringStyle.FloatTwoOrThree) + ")");
                    }
                    else
                    {
                        explanation.Append("+ (" + armorFactors[i].armorType.label + ": " + thing.GetStatValue(armorFactors[i].armorType).ToStringPercent() + " x " + armorFactors[i].weight.ToStringByStyle(ToStringStyle.FloatTwoOrThree) + ")");
                    }
                }
                explanation.AppendLine();
                float armorFactor = 0f;
                foreach (ArmorFactor factor in armorFactors)
                {
                    armorFactor += thing.GetStatValue(factor.armorType) * factor.weight;
                }
                explanation.AppendLine();
                explanation.AppendLine("AIUDiscomfortExplanation5".Translate());
                explanation.AppendLine("   " + thing.GetStatValue(StatDefOf.Mass).ToStringByStyle(ToStringStyle.FloatTwo));
                explanation.AppendLine();
                explanation.AppendLine("AIUDiscomfortExplanation6".Translate());
                explanation.AppendLine("x(" + sizeFactor.ToStringByStyle(ToStringStyle.FloatTwo) + " x " + armorFactor.ToStringByStyle(ToStringStyle.PercentZero) + " x " + thing.GetStatValue(StatDefOf.Mass).ToStringByStyle(ToStringStyle.FloatTwo) + " = " + (sizeFactor * armorFactor * thing.GetStatValue(StatDefOf.Mass)).ToStringByStyle(ToStringStyle.FloatTwoOrThree) + ")");
            }
            return(explanation.ToString());
        }
Ejemplo n.º 17
0
        private static void AddPartToThing(ThingDef thingDef, BodyPartDef warGear, BodyPartGroupDef bodyPartGroupDef, string customLabel)
        {
            if (thingDef == null || warGear == null || bodyPartGroupDef == null)
            {
                return;
            }

            thingDef.race.body.corePart.parts.Add(new BodyPartRecord
            {
                customLabel = customLabel,
                coverage    = 0f,
                def         = warGear,
                depth       = BodyPartDepth.Undefined,
                groups      = new List <BodyPartGroupDef>(new[] { bodyPartGroupDef }),
                height      = BodyPartHeight.Middle
            });
        }
Ejemplo n.º 18
0
        protected override DamageWorker.DamageResult ApplyMeleeDamageToTarget(LocalTargetInfo target)
        {
            DamageWorker.DamageResult damageResult     = new DamageWorker.DamageResult();
            BodyPartGroupDef          bodyPartGroupDef = null;
            HediffDef hediffDef        = null;
            float     num              = verbProps.AdjustedMeleeDamageAmount(this, CasterPawn);
            float     armorPenetration = verbProps.AdjustedArmorPenetration(this, CasterPawn);
            ThingDef  source           = (base.EquipmentSource == null) ? CasterPawn.def : base.EquipmentSource.def;

            bodyPartGroupDef = verbProps.AdjustedLinkedBodyPartsGroup(tool);
            DamageInfo dinfo = new DamageInfo(DamageDefOf.Scratch, num, armorPenetration, -1f, this.CasterPawn, null, source);

            damageResult.totalDamageDealt = Mathf.Min((float)target.Thing.HitPoints, dinfo.Amount);
            for (int i = 0; i < 8; i++)
            {
                IntVec3 intVec       = target.Cell + GenAdj.AdjacentCells[i];
                Pawn    cleaveVictim = new Pawn();
                cleaveVictim = intVec.GetFirstPawn(target.Thing.Map);
                if (cleaveVictim != null && cleaveVictim.Faction != caster.Faction)
                {
                    Vector3 direction = (cleaveVictim.Position - CasterPawn.Position).ToVector3();
                    dinfo.SetBodyRegion(BodyPartHeight.Undefined, BodyPartDepth.Outside);
                    dinfo.SetWeaponBodyPartGroup(bodyPartGroupDef);
                    dinfo.SetWeaponHediff(hediffDef);
                    dinfo.SetAngle(direction);
                    dinfo.SetAmount(Rand.Range(.8f, 1.2f) * num * .6f);
                    cleaveVictim.TakeDamage(dinfo);
                    FleckMaker.ThrowMicroSparks(cleaveVictim.Position.ToVector3(), target.Thing.Map);
                    TM_MoteMaker.ThrowCrossStrike(cleaveVictim.Position.ToVector3Shifted(), cleaveVictim.Map, 1f);
                    TM_MoteMaker.ThrowBloodSquirt(cleaveVictim.Position.ToVector3Shifted(), cleaveVictim.Map, 1f);
                }
            }

            target.Thing.TakeDamage(dinfo);
            if (target != null && !target.Thing.DestroyedOrNull())
            {
                base.ApplyMeleeDamageToTarget(target);
                if (target.Thing.Map != null)
                {
                    TM_MoteMaker.ThrowCrossStrike(target.Thing.Position.ToVector3Shifted(), target.Thing.Map, .5f);
                    TM_MoteMaker.ThrowBloodSquirt(target.Thing.Position.ToVector3Shifted(), target.Thing.Map, 1.2f);
                }
            }
            return(damageResult);
        }
Ejemplo n.º 19
0
        internal static float ReduceForArmorType(StatDef deflectionStat, Pawn target)
        {
            float reduction = 1.0f;

            if (target != null)
            {
                BodyPartGroupDef bodyPartTest = BodyPartGroupDefOf.Torso;   //For statistical purposes, consider torso only

                if (target.apparel != null && target.apparel.WornApparel != null)
                {
                    foreach (Apparel apparel in target.apparel.WornApparel.Where(a => a.def.apparel.bodyPartGroups.Contains(bodyPartTest)))
                    {
                        reduction *= GetArmorTypeFactor(apparel.GetStatValue(deflectionStat, true));
                    }
                }

                reduction *= GetArmorTypeFactor(target.GetStatValue(deflectionStat, true));
            }
            return(reduction);
        }
Ejemplo n.º 20
0
        private IEnumerable <DamageInfo> DamageInfosToApply(LocalTargetInfo target)
        {
            float            damAmount2       = verbProps.AdjustedMeleeDamageAmount(this, base.CasterPawn);
            float            armorPenetration = verbProps.AdjustedArmorPenetration(this, base.CasterPawn);
            DamageDef        damDef           = verbProps.meleeDamageDef;
            BodyPartGroupDef bodyPartGroupDef = null;
            HediffDef        hediffDef        = null;

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

            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*/;
        }
Ejemplo n.º 21
0
        private Apparel FindGarmentCoveringPart(Pawn pawn, BodyPartGroupDef bodyPartGroupDef)
        {
            Room room = pawn.GetRoom();

            if (room.isPrisonCell)
            {
                foreach (IntVec3 cell in room.Cells)
                {
                    List <Thing> thingList = cell.GetThingList(pawn.Map);
                    for (int i = 0; i < thingList.Count; i++)
                    {
                        Apparel apparel = thingList[i] as Apparel;
                        if (apparel != null && apparel.def.apparel.bodyPartGroups.Contains(bodyPartGroupDef) && pawn.CanReserve(apparel) && !apparel.IsBurning() && (!EquipmentUtility.IsBiocoded(apparel) || EquipmentUtility.IsBiocodedFor(apparel, pawn)) && ApparelUtility.HasPartsToWear(pawn, apparel.def))
                        {
                            return(apparel);
                        }
                    }
                }
            }
            return(null);
        }
Ejemplo n.º 22
0
        private Apparel FindGarmentCoveringPart(Pawn pawn, BodyPartGroupDef bodyPartGroupDef)
        {
            Room room = pawn.GetRoom(RegionType.Set_Passable);

            if (room.isPrisonCell)
            {
                foreach (IntVec3 current in room.Cells)
                {
                    List <Thing> thingList = current.GetThingList(pawn.Map);
                    for (int i = 0; i < thingList.Count; i++)
                    {
                        Apparel apparel = thingList[i] as Apparel;
                        if (apparel != null && apparel.def.apparel.bodyPartGroups.Contains(bodyPartGroupDef) && pawn.CanReserve(apparel, 1, -1, null, false) && !apparel.IsBurning() && ApparelUtility.HasPartsToWear(pawn, apparel.def))
                        {
                            return(apparel);
                        }
                    }
                }
            }
            return(null);
        }
Ejemplo n.º 23
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*/;
        }
Ejemplo n.º 24
0
        private Apparel FindGarmentCoveringPart(Pawn pawn, BodyPartGroupDef bodyPartGroupDef)
        {
            Room room = pawn.GetRoom();
            Predicate <Thing> validator = (Thing t) => pawn.CanReserve(t, 1) &&
                                          pawn.CanReach(t, PathEndMode.Touch, Danger.Deadly, true) &&
                                          (t.Position.DistanceToSquared(pawn.Position) < 12f || room == RoomQuery.RoomAtFast(t.Position, t.Map));
            List <Thing> aList = (
                from t in pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.Apparel)
                orderby t.MarketValue - t.Position.DistanceToSquared(pawn.Position) * 2f descending
                where validator(t)
                select t
                ).ToList();

            foreach (Thing current in aList)
            {
                Apparel ap = current as Apparel;
                if (ap != null && ap.def.apparel.bodyPartGroups.Contains(bodyPartGroupDef) && pawn.CanReserve(ap, 1) && ApparelUtility.HasPartsToWear(pawn, ap.def))
                {
                    return(ap);
                }
            }
            return(null);
        }
        public static IEnumerable <BodyPartRecord> GetFixedPartsToApplyOn(RecipeDef recipe, Pawn pawn, Func <BodyPartRecord, bool> validator = null)
        {
            int j = 0;

            while (j < recipe.appliedOnFixedBodyParts.Count)
            {
                BodyPartDef           part   = recipe.appliedOnFixedBodyParts[j];
                List <BodyPartRecord> bpList = pawn.RaceProps.body.AllParts;
                for (int k = 0; k < bpList.Count; k++)
                {
                    BodyPartRecord bodyPartRecord = bpList[k];
                    if (bodyPartRecord.def == part && (validator == null || validator(bodyPartRecord)))
                    {
                        yield return(bodyPartRecord);
                    }
                }
                int num = j + 1;
                j = num;
            }
            j = 0;
            while (j < recipe.appliedOnFixedBodyPartGroups.Count)
            {
                BodyPartGroupDef      group  = recipe.appliedOnFixedBodyPartGroups[j];
                List <BodyPartRecord> bpList = pawn.RaceProps.body.AllParts;
                for (int k = 0; k < bpList.Count; k++)
                {
                    BodyPartRecord bodyPartRecord2 = bpList[k];
                    if (bodyPartRecord2.groups != null && bodyPartRecord2.groups.Contains(group) && (validator == null || validator(bodyPartRecord2)))
                    {
                        yield return(bodyPartRecord2);
                    }
                }
                int num = j + 1;
                j = num;
            }
        }
Ejemplo 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);
            }
        }
Ejemplo n.º 27
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);
            }
        }
Ejemplo n.º 28
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);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 29
0
 public static Apparel WornRestraints( this Pawn pawn, BodyPartGroupDef bodyPartGroupDef )
 {
     if(
         ( pawn == null ) ||
         ( pawn.apparel == null )
     )
     {
         return null;
     }
     var wornApparel = pawn.apparel.wornApparel();
     if( wornApparel == null )
     {
         return null;
     }
     for( int index = 0; index < wornApparel.Count; ++index )
     {
         if(
             ( wornApparel[ index ].IsRestraints() )&&
             ( wornApparel[ index ].def.apparel.bodyPartGroups.Contains( bodyPartGroupDef ) )
         )
         {
             return wornApparel[ index ];
         }
     }
     return null;
 }
 private bool <GetInterferingBodyPartGroups> m__9(BodyPartGroupDef group)
 {
     return(this.bodyPartGroups.Contains(group));
 }
Ejemplo n.º 31
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);
            }
        }
        // Token: 0x060039E1 RID: 14817 RVA: 0x001B83B8 File Offset: 0x001B67B8
        private IEnumerable <DamageInfo> DamageInfosToApply(LocalTargetInfo target)
        {
            float            damAmount        = this.verbProps.AdjustedMeleeDamageAmount(this, base.CasterPawn);
            float            armorPenetration = this.verbProps.AdjustedArmorPenetration(this, base.CasterPawn);
            DamageDef        damDef           = this.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;
            float      num       = damAmount;
            float      num2      = armorPenetration;
            Thing      caster    = this.caster;
            DamageInfo mainDinfo = new DamageInfo(def, num, num2, -1f, caster, null, source, DamageInfo.SourceCategory.ThingOrUnknown, null);

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

            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);
                }
            }
            if (target.GetType() == typeof(Pawn))
            {
                Pawn hitPawn = (Pawn)target;
                HarmonyPatches.PushEffect(CasterPawn, hitPawn, (int)((Rand.Range(2, 3) + CasterPawn.BodySize) - hitPawn.BodySize), true);
            }

            yield break;
        }