Beispiel #1
0
     public static DamageInfo GetForceDamage(DamageInfo cloneSource, Pawn Caster, Thing target)
     {
         if (Caster != null)
         {
             if (Caster.isPsyker(out int Level, out float Mult))
             {
                 //    log.message(Caster.NameShortColored + " Level " + Level + " Mult " + Mult);
                 if (cloneSource.Weapon != null)
                 {
                     Thing Weapon = null;
                     if (cloneSource.Weapon.IsWeapon)
                     {
                         foreach (var item in Caster.equipment.AllEquipmentListForReading)
                         {
                             if (item.def == cloneSource.Weapon)
                             {
                                 Weapon = item;
                             }
                         }
                     }
                     else
                     if (cloneSource.Weapon.IsApparel)
                     {
                         foreach (var item in Caster.apparel.WornApparel)
                         {
                             if (item.def == cloneSource.Weapon)
                             {
                                 Weapon = item;
                             }
                         }
                     }
                     if (Weapon != null)
                     {
                         Weapon = Caster.equipment.Primary;
                     }
                     CompWeapon_MeleeSpecialRules     WeaponRules = Weapon.TryGetCompFast <CompWeapon_MeleeSpecialRules>();
                     CompForceWeaponActivatableEffect compForce   = Weapon.TryGetCompFast <CompForceWeaponActivatableEffect>();
                     if (WeaponRules != null || compForce != null)
                     {
                         if (WeaponRules?.ForceWeapon ?? compForce != null)
                         {
                             bool requiresPsyker           = WeaponRules?.ForceEffectRequiresPsyker ?? compForce.ForceEffectRequiresPsyker;
                             bool casterPsychiclySensitive = Caster.RaceProps.Humanlike && (Caster.story.traits.HasTrait(TraitDefOf.PsychicSensitivity) || Caster.story.traits.HasTrait(DefDatabase <TraitDef> .GetNamedSilentFail("Psyker")));
                             bool Activate = false;
                             if ((casterPsychiclySensitive || !requiresPsyker) && target.def.category == ThingCategory.Pawn && target is Pawn Victim)
                             {
                                 int casterPsychiclySensitiveDegree = casterPsychiclySensitive ? Caster.story.traits.DegreeOfTrait(TraitDefOf.PsychicSensitivity) : 0;
                                 if ((casterPsychiclySensitiveDegree >= 1 || !requiresPsyker))
                                 {
                                     float?casterPsychicSensitivity = Caster.GetStatValue(StatDefOf.PsychicSensitivity, true) * 100f;
                                     bool  targetPsychiclySensitive = Victim.RaceProps.Humanlike && Victim.story.traits.HasTrait(TraitDefOf.PsychicSensitivity);
                                     float?targetPsychicSensitivity = Victim.GetStatValue(StatDefOf.PsychicSensitivity, true) * 100f;
                                     if (targetPsychiclySensitive == true)
                                     {
                                         int targetPsychiclySensitiveDegree = Victim.story.traits.DegreeOfTrait(TraitDefOf.PsychicSensitivity);
                                         if (targetPsychiclySensitiveDegree == -1)
                                         {
                                             targetPsychicSensitivity = Victim.def.statBases.GetStatValueFromList(StatDefOf.PsychicSensitivity, 1.5f) * 100f;
                                         }
                                         else if (targetPsychiclySensitiveDegree == -2)
                                         {
                                             targetPsychicSensitivity = Victim.def.statBases.GetStatValueFromList(StatDefOf.PsychicSensitivity, 2f) * 100f;
                                         }
                                     }
                                     else /*int targetPsychiclySensitiveDegree = 0;*/ } {
                                     {
                                         float CasterMood = Caster.needs.mood.CurLevelPercentage;
                                         float VictimMood = Victim?.needs?.mood != null ? Victim.needs.mood.CurLevelPercentage : 1;
                                         Rand.PushState();
                                         float?casterRoll = Rand.Range(0, (int)casterPsychicSensitivity) * CasterMood;
                                         float?targetRoll = Rand.Range(0, (int)targetPsychicSensitivity) * VictimMood;
                                         Rand.PopState();
                                         casterRoll = (casterRoll - (targetPsychicSensitivity / 2));
                                         Activate   = (casterRoll > targetRoll);
                                         //    log.message(string.Format("Caster:{0}, Victim:{1}", casterRoll, targetRoll));
                                         if (Activate)
                                         {
                                             DamageDef damDef           = WeaponRules?.ForceWeaponEffect ?? compForce.ForceWeaponEffect;
                                             float     damAmount        = cloneSource.Amount;
                                             float     armorPenetration = cloneSource.ArmorPenetrationInt;
                                             Rand.PushState();
                                             BodyPartRecord bodyPart = Rand.Chance(0.05f) && Victim.RaceProps.body.AllParts.Any(x => x.def.defName.Contains("Brain")) ? Victim.RaceProps.body.AllParts.Find(x => x.def.defName.Contains("Brain")) : null;
                                             Rand.PopState();
                                             BodyPartGroupDef bodyPartGroupDef = null;
                                             HediffDef        hediffDef        = WeaponRules?.ForceWeaponHediff ?? compForce.ForceWeaponHediff;
                                             damAmount = Rand.Range(damAmount * 0.1f, damAmount * 0.5f);
                                             ThingDef   source    = cloneSource.Weapon;
                                             Thing      caster    = Caster;
                                             Vector3    direction = (target.Position - Caster.Position).ToVector3();
                                             float      num       = damAmount;
                                             DamageInfo mainDinfo = new DamageInfo(damDef, num, 2, -1f, caster, bodyPart, source, DamageInfo.SourceCategory.ThingOrUnknown, null);
                                             mainDinfo.SetBodyRegion(BodyPartHeight.Undefined, BodyPartDepth.Outside);
                                             mainDinfo.SetWeaponBodyPartGroup(bodyPartGroupDef);
                                             mainDinfo.SetWeaponHediff(hediffDef);
                                             mainDinfo.SetAngle(direction);
                                             Victim.TakeDamage(mainDinfo);
                                             Map      map             = Caster.Map;
                                             IntVec3  position        = target.Position;
                                             Map      map2            = map;
                                             float    explosionRadius = 0f;
                                             Thing    launcher        = Weapon;
                                             SoundDef soundExplode    = WeaponRules?.ForceWeaponTriggerSound ?? compForce.ForceWeaponTriggerSound;
                                             Thing    thing           = target;
                                             GenExplosion.DoExplosion(position, map2, explosionRadius, damDef, launcher, (int)damAmount, armorPenetration, soundExplode, source, null, thing, null, 0f, 0, false, null, 0, 0, 0, false);
                                             TaggedString   msg        = "AdeptusMechanicus.ForceStrike";
                                             MessageTypeDef typeDef    = MessageTypeDefOf.NegativeHealthEvent;
                                             float          KillChance = WeaponRules?.ForceWeaponKillChance ?? compForce.ForceWeaponKillChance;
                                             if (KillChance != 0)
                                             {
                                                 Rand.PushState();
                                                 float KillRoll = Rand.Range(0, 100);
                                                 if (Rand.Chance(KillChance))
                                                 {
                                                     typeDef = MessageTypeDefOf.PawnDeath;
                                                 }
                                                 Rand.PopState();
                                             }
                                             if (typeDef == MessageTypeDefOf.PawnDeath)
                                             {
                                                 Victim.Kill(mainDinfo);
                                             }
                                             if (Victim.Faction == Faction.OfPlayer)
                                             {
                                                 Messages.Message(string.Format("AdeptusMechanicus.Force_Strike ".Translate(), Victim.Name, typeDef == MessageTypeDefOf.PawnDeath ? "slain" : "blasted"), typeDef);
                                             }
                                             return(mainDinfo);
                                         }
                                     }
                             }
                         }
                     }
                 }
             }
         }
     }
     return(cloneSource);
 }
Beispiel #2
0
        public static void AdjustedArmorPenetration_RendingWeapon_Postfix(ref VerbProperties __instance, Tool tool, Pawn attacker, Thing equipment, HediffComp_VerbGiver hediffCompSource, ref float __result)
        {
            if (tool != null)
            {
                if (!tool.capacities.NullOrEmpty())
                {
                    if (tool.capacities.Any(x => x.defName.Contains("OG_RendingWeapon")))
                    {
                        float RendingChance = 0.167f;

                        if (equipment != null)
                        {
                            CompWeapon_MeleeSpecialRules _MeleeSpecialRules = equipment?.TryGetComp <CompWeapon_MeleeSpecialRules>();
                            if (_MeleeSpecialRules != null)
                            {
                                RendingChance = _MeleeSpecialRules.RendingChance;
                            }
                        }
                        else
                        {
                            if (attacker != null)
                            {
                                foreach (Tool item in attacker.Tools.Where(x => x != tool))
                                {
                                    if (item.capacities.Any(x => x.defName.Contains("OG_RendingWeapon")))
                                    {
                                        RendingChance += 0.167f;
                                    }
                                }
                            }
                        }

                        if (Rand.Chance(RendingChance))
                        {
                            MoteMaker.ThrowText(attacker.Position.ToVector3(), attacker.MapHeld, "AMA_Rending_Strike".Translate(), 3f);
                            __result = 2f;
                            return;
                        }
                    }
                }
            }

            /*
             * if (__instance.EquipmentSource != null)
             * {
             *  if (!__instance.EquipmentSource.AllComps.NullOrEmpty())
             *  {
             *      if (__instance.EquipmentSource.GetComp<CompWeapon_MeleeSpecialRules>() != null)
             *      {
             *          if (__instance.EquipmentSource.GetComp<CompWeapon_MeleeSpecialRules>() is CompWeapon_MeleeSpecialRules WeaponRules)
             *          {
             *              if (AMASettings.Instance.AllowRendingMeleeEffect)
             *              {
             *                  bool RendingAttack = __result.Any(x => x.Def.rendingWeapon());
             *                  if (WeaponRules.RendingWeapon && RendingAttack && __instance.CasterPawn is Pawn Caster)
             *                  {
             *
             *                  }
             *              }
             *          }
             *      }
             *  }
             * }
             */
        }
Beispiel #3
0
        public static void Postfix(ref VerbPropertiesCE __instance, Verb ownerVerb, Pawn attacker, ref float __result)
        {
            ToolCE tool      = ownerVerb.tool as ToolCE;
            Thing  equipment = ownerVerb.EquipmentSource;

            if (tool != null)
            {
                if (!tool.capacities.NullOrEmpty())
                {
                    if (tool.capacities.Any(x => x.defName.Contains("OG_RendingWeapon")))
                    {
                        float RendingChance = 0.167f;

                        if (equipment != null)
                        {
                            CompWeapon_MeleeSpecialRules _MeleeSpecialRules = equipment?.TryGetCompFast <CompWeapon_MeleeSpecialRules>();
                            if (_MeleeSpecialRules != null)
                            {
                                RendingChance = _MeleeSpecialRules.RendingChance;
                            }
                        }
                        else
                        {
                            if (attacker != null)
                            {
                                foreach (Tool item in attacker.Tools.Where(x => x != tool))
                                {
                                    if (item.capacities.Any(x => x.defName.Contains("OG_RendingWeapon")))
                                    {
                                        RendingChance += 0.167f;
                                    }
                                }
                            }
                        }

                        Rand.PushState();
                        bool rend = Rand.Chance(RendingChance);
                        Rand.PopState();
                        if (rend)
                        {
                            //    MoteMaker.ThrowText(attacker.Position.ToVector3(), attacker.MapHeld, "AdeptusMechanicus.Rending_Strike".Translate(), 3f);
                            __result = 2f;
                            return;
                        }
                    }
                }
            }

            /*
             * if (__instance.EquipmentSource != null)
             * {
             *  if (!__instance.EquipmentSource.AllComps.NullOrEmpty())
             *  {
             *      if (__instance.EquipmentSource.GetComp<CompWeapon_MeleeSpecialRules>() != null)
             *      {
             *          if (__instance.EquipmentSource.GetComp<CompWeapon_MeleeSpecialRules>() is CompWeapon_MeleeSpecialRules WeaponRules)
             *          {
             *              if (AMASettings.Instance.AllowRendingMeleeEffect)
             *              {
             *                  bool RendingAttack = __result.Any(x => x.Def.rendingWeapon());
             *                  if (WeaponRules.RendingWeapon && RendingAttack && __instance.CasterPawn is Pawn Caster)
             *                  {
             *
             *                  }
             *              }
             *          }
             *      }
             *  }
             * }
             */
        }