コード例 #1
0
        public static void PostFix(ref StunHandler __instance, ref int ___EMPAdaptedTicksLeft, DamageInfo dinfo)
        {
            var pawn = __instance.parent as Pawn;

            if (pawn != null && (pawn.Downed || pawn.Dead))
            {
                return;
            }

            var Haywire = DefDatabase <DamageDef> .GetNamed("GGHaywireEMP");

            if (dinfo.Def != Haywire || !EMPAffects(pawn))
            {
                return;
            }

            if (___EMPAdaptedTicksLeft <= 0 || HaywireUtility.Rnd100() < (int)Controller.Settings.HWChance)
            {
                __instance.StunFor(Mathf.RoundToInt(dinfo.Amount * 15f), dinfo.Instigator);
                if (pawn != null && pawn.RaceProps.IsMechanoid)
                {
                    ___EMPAdaptedTicksLeft = 2000;
                }

                HaywireUtility.DoHaywireEffect(pawn);
                return;
            }

            var position = __instance.parent.Position;

            MoteMaker.ThrowText(new Vector3(position.x + 1f, position.y, position.z + 1f), __instance.parent.Map,
                                "Adapted".Translate(), Color.white);
        }
コード例 #2
0
        public static bool Prefix(StunHandler __instance, DamageInfo dinfo, ref int ___EMPAdaptedTicksLeft, ref int ___stunTicksLeft, ref bool ___stunFromEMP)
        {
            Pawn  pawn     = __instance.parent as Pawn;
            float bodySize = 1.0f;

            if (pawn != null)
            {
                if (pawn.Downed || pawn.Dead)
                {
                    return(false);
                }
                bodySize = pawn.BodySize;
            }

            if (dinfo.Def == DamageDefOf.EMP && __instance.parent is Pawn p && !(p.RaceProps?.IsFlesh ?? false))
            {
                if (___EMPAdaptedTicksLeft > 0)
                {
                    int newStunAdaptedTicks = Mathf.RoundToInt(dinfo.Amount * 45 * bodySize);
                    int newStunTicks        = Mathf.RoundToInt(dinfo.Amount * 30);

                    float stunResistChance = ((float)___EMPAdaptedTicksLeft / (float)newStunAdaptedTicks) * 15;

                    if (UnityEngine.Random.value > stunResistChance)
                    {
                        ___EMPAdaptedTicksLeft += Mathf.RoundToInt(dinfo.Amount * 45 * bodySize);

                        if (___stunTicksLeft > 0 && newStunTicks > ___stunTicksLeft)
                        {
                            ___stunTicksLeft = newStunTicks;
                        }
                        else
                        {
                            __instance.StunFor(newStunTicks, dinfo.Instigator, true, true);
                        }
                    }
                    else
                    {
                        MoteMaker.ThrowText(new Vector3((float)__instance.parent.Position.x + 1f, (float)__instance.parent.Position.y, (float)__instance.parent.Position.z + 1f), __instance.parent.Map, "Adapted".Translate(), Color.white, -1f);
                        int adaptationReduction = Mathf.RoundToInt(Mathf.Sqrt(dinfo.Amount * 45));

                        if (adaptationReduction < ___EMPAdaptedTicksLeft)
                        {
                            ___EMPAdaptedTicksLeft -= adaptationReduction;
                        }
                        else
                        {
                            float adaptationReductionRatio = (adaptationReduction - ___EMPAdaptedTicksLeft) / adaptationReduction;
                            newStunAdaptedTicks = Mathf.RoundToInt(newStunAdaptedTicks * adaptationReductionRatio);
                            newStunTicks        = Mathf.RoundToInt(newStunTicks * adaptationReductionRatio);

                            if (___stunTicksLeft > 0 && newStunTicks > ___stunTicksLeft)
                            {
                                ___stunTicksLeft = newStunTicks;
                            }
                            else
                            {
                                __instance.StunFor(newStunTicks, dinfo.Instigator, true, true);
                            }
                        }
                    }
                }
                else
                {
                    __instance.StunFor(Mathf.RoundToInt(dinfo.Amount * 30f), dinfo.Instigator, true, true);
                    ___EMPAdaptedTicksLeft = Mathf.RoundToInt(dinfo.Amount * 45 * bodySize);
                    ___stunFromEMP         = true;
                }
            }
            return(true);
        }