Exemple #1
0
        static bool Prefix(ref Pawn __instance, ref int __result, ref bool diagonal)
        {
            float statValue = __instance.GetStatValue(StatDefOf.MoveSpeed);

            if (RestraintsUtility.InRestraints(__instance))
            {
                statValue *= 0.35f;
            }
            if (__instance.carryTracker != null && __instance.carryTracker.CarriedThing != null && __instance.carryTracker.CarriedThing.def.category == ThingCategory.Pawn)
            {
                statValue *= 0.6f;
            }
            //속도 증폭시키면 원본만큼 체감이 상승되지 않음(틱 검사시간때문에 그런것으로 보임), 따라서 배율에 따른 계수 추가
            float num = statValue / 60f * (RefcellRespeedConfig.currentTimeMultiplier + ((RefcellRespeedConfig.currentTimeMultiplier - 1) * 0.2f));
            float f;

            if ((double)num == 0.0)
            {
                f = 450f;
            }
            else
            {
                f = 1f / num;
                if (__instance.Spawned && !__instance.Map.roofGrid.Roofed(__instance.Position))
                {
                    f /= __instance.Map.weatherManager.CurMoveSpeedMultiplier;
                }
                if (diagonal)
                {
                    f *= 1.41421f;
                }
            }
            __result = Mathf.Clamp(Mathf.RoundToInt(f), 1, 450);
            return(false);
        }
Exemple #2
0
        /// <summary>
        ///     Checks for special cases where grappling can occur instantly without contest.
        ///     E.g. grappling downed characters.
        /// </summary>
        /// <param name="grappler"></param>
        /// <param name="victim"></param>
        /// <param name="throwText"></param>
        /// <returns></returns>
        public static bool CanGrappleNoContest(Pawn grappler, Pawn victim, bool throwText = true)
        {
            if (!victim.Awake())
            {
                if (throwText)
                {
                    MoteMaker.ThrowText(grappler.DrawPos, grappler.Map, "JTGrapple_SleepingGrapple".Translate(), -1f);
                }
                return(true);
            }

            if (victim.Downed)
            {
                if (throwText)
                {
                    MoteMaker.ThrowText(grappler.DrawPos, grappler.Map, "JTGrapple_DownedGrapple".Translate(), -1f);
                }
                return(true);
            }

            if (victim.IsPrisonerOfColony && RestraintsUtility.InRestraints(victim))
            {
                if (throwText)
                {
                    MoteMaker.ThrowText(grappler.DrawPos, grappler.Map, "JTGrapple_PrisonerGrapple".Translate(), -1f);
                }
                return(true);
            }
            return(false);
        }
Exemple #3
0
 public static void ShouldShowRestraintsInfo_Patch(ref Pawn pawn, ref bool __result)
 {
     if (RestraintsUtility.InRestraints(pawn) && SlaveUtility.IsPawnColonySlave(pawn))
     {
         __result = true;
     }
 }
Exemple #4
0
        public override void OnIntervalPassed(Pawn pawn, Hediff cause)
        {
            Hediff hediff = pawn.health.hediffSet.GetFirstHediffOfDef(this.hediff, false);

            float value;

            if (RestraintsUtility.InRestraints(pawn))
            {
                value = 1.0f;
            }
            else if (hediff != null && pawn.Faction != Faction.OfPlayer)
            {
                value = hediff.Severity - 0.01f;
            }
            else
            {
                value = 0.0f;
            }

            if (hediff != null)
            {
                hediff.Severity = value;
            }
            else if (value != 0)
            {
                hediff          = HediffMaker.MakeHediff(this.hediff, pawn, null);
                hediff.Severity = value;
                pawn.health.AddHediff(hediff, null, null);
            }
        }
        public override void OnIntervalPassed(Pawn pawn, Hediff cause)
        {
            Hediff hediff = pawn.health.hediffSet.GetFirstHediffOfDef(this.hediff, false);
            float  mod    = 0f;

            if (pawn != null && pawn.IsPrisonerOfColony)
            {
                if (pawn.health.hediffSet.GetFirstHediffOfDef(PL_DefOf.PrisonLabor_RemovedHandscuffs, false) != null)
                {
                    mod += 0.19f;
                }
                if (pawn.health.hediffSet.GetFirstHediffOfDef(PL_DefOf.PrisonLabor_RemovedLegscuffs, false) != null)
                {
                    mod += 0.19f * 2f;
                }
            }
            float value;

            if (RestraintsUtility.InRestraints(pawn))
            {
                value = 1.0f - mod;
            }
            else if (hediff != null && pawn.Faction != Faction.OfPlayer)
            {
                value = hediff.Severity - 0.01f;
            }
            else
            {
                value = 0.0f;
            }


            if (pawn.guest != null && pawn.guest.Released)
            {
                value = 0f;
            }

            if (hediff != null)
            {
                hediff.Severity = value;
            }
            else if (value != 0 && pawn.IsPrisonerOfColony)
            {
                hediff          = HediffMaker.MakeHediff(this.hediff, pawn, null);
                hediff.Severity = value;
                pawn.health.AddHediff(hediff, null, null);
            }
        }
Exemple #6
0
        public static bool CanGrapple(this Pawn grappler, Pawn victim)
        {
            if (victim == null || victim.Dead)
            {
                return(true);
            }

            //Check downed
            if (victim.Downed)
            {
                MoteMaker.ThrowText(grappler.DrawPos, grappler.Map, "ROMV_DownedGrapple".Translate(), -1f);
                return(true);
            }

            if (victim.IsPrisonerOfColony && RestraintsUtility.InRestraints(victim))
            {
                MoteMaker.ThrowText(grappler.DrawPos, grappler.Map, "ROMV_PrisonerGrapple".Translate(), -1f);
                return(true);
            }

            //Check line of sight.
            //if (!victim.CanSee(grappler))
            //{
            //    MoteMaker.ThrowText(grappler.DrawPos, grappler.Map, "ROMV_SneakGrapple".Translate(), -1f);
            //    return true;
            //}

            //Grapple check.

            int roll     = Rand.Range(1, 20);
            int modifier = (int)grappler.RaceProps.baseBodySize;

            modifier += (grappler.RaceProps.Humanlike) ? grappler.skills.GetSkill(SkillDefOf.Melee).Level : 0;
            modifier += VampireUtility.GrapplerModifier(grappler);
            int difficulty = (int)victim.RaceProps.baseBodySize;

            difficulty += (victim.RaceProps.Humanlike) ? victim?.skills?.GetSkill(SkillDefOf.Melee)?.Level ?? 1 : 1;

            if (roll + modifier > difficulty)
            {
                MoteMaker.ThrowText(grappler.DrawPos, grappler.Map, roll + " + " + modifier + " = " + (roll + modifier) + " vs " + difficulty + " : " + StringsToTranslate.AU_CastSuccess, -1f);
                return(true);
            }
            MoteMaker.ThrowText(grappler.DrawPos, grappler.Map, roll + " + " + modifier + " = " + (roll + modifier) + " vs " + difficulty + " : " + StringsToTranslate.AU_CastFailure, -1f);
            return(false);
        }
Exemple #7
0
        public static Job TryGiveJobStatic(Pawn pawn, bool inCombat)
        {
            if (RestraintsUtility.InRestraints(pawn))
            {
                return(null);
            }
            else
            {
                if (!pawn.IsValidSidearmsCarrier())
                {
                    return(null);
                }

                CompSidearmMemory pawnMemory = CompSidearmMemory.GetMemoryCompForPawn(pawn);
                if (pawnMemory == null)
                {
                    return(null);
                }

                if (pawnMemory.IsUsingAutotool(true, false))
                {
                    pawnMemory.currentJobWeaponReequipDelayed = true;
                    return(null);
                }
                else
                {
                    pawnMemory.currentJobWeaponReequipDelayed = false;
                }

                //Log.Message(pawn.Label+" considering switching weapons on the run");
                WeaponAssingment.equipBestWeaponFromInventoryByPreference(pawn, DroppingModeEnum.Calm);

                //yes, I realise that this never actually results in a job.
                //I might at some point in the future decide to make switching weapons non-instaneous, which will happen here.

                return(null);
            }
        }
Exemple #8
0
        public static int TerrainAwareTicksPerMove(this Pawn pawn, TerrainDef terrain, bool diagonal)
        {
            float num = TerrainSpeed(pawn, terrain);

            // Rest of this is the same as vanilla function
            if (RestraintsUtility.InRestraints(pawn))
            {
                num *= 0.35f;
            }
            if (pawn.carryTracker != null && pawn.carryTracker.CarriedThing != null && pawn.carryTracker.CarriedThing.def.category == ThingCategory.Pawn)
            {
                num *= 0.6f;
            }
            float num2 = num / 60f;
            float num3;

            if (num2 == 0f)
            {
                num3 = 450f;
            }
            else
            {
                num3 = 1f / num2;
                if (pawn.Spawned && !pawn.Map.roofGrid.Roofed(pawn.Position))
                {
                    num3 /= pawn.Map.weatherManager.CurMoveSpeedMultiplier;
                }
                if (diagonal)
                {
                    num3 *= 1.41421f;
                }
            }
            int value = Mathf.RoundToInt(num3);

            return(Mathf.Clamp(value, 1, 450));
        }
        public static Job TryGiveJobStatic(Pawn pawn, bool inCombat)
        {
            if (RestraintsUtility.InRestraints(pawn))
            {
                return(null);
            }

            {
                //SetNextTryTick(pawn, Find.TickManager.TicksGame + UnityEngine.Random.Range(PickupCheckIntervalMin, PickupCheckIntervalMax));


                Pawn_EquipmentTracker equipment = pawn.equipment;
                if (equipment == null)
                {
                    return(null);
                }

                GoldfishModule pawnMemory = GoldfishModule.GetGoldfishForPawn(pawn);
                if (pawnMemory == null)
                {
                    return(null);
                }

                WeaponAssingment.reequipPrimaryIfNeededAndAvailable(pawn, pawnMemory);

                foreach (string wepName in pawnMemory.weapons)
                {
                    ThingDef def = DefDatabase <ThingDef> .GetNamedSilentFail(wepName);

                    if (def == null)
                    {
                        continue;
                    }

                    if (!pawn.hasWeaponSomewhere(wepName))
                    {
                        float maxDist = 1000f;
                        if (pawn.Faction != Faction.OfPlayer || inCombat)
                        {
                            maxDist = 30f;
                        }
                        List <Thing> matchingWeapons = pawn.Map.listerThings.ThingsOfDef(def);

                        Thing thing = GenClosest.ClosestThing_Global_Reachable(pawn.Position, pawn.Map, matchingWeapons, PathEndMode.OnCell, TraverseParms.For(pawn), maxDist,
                                                                               (Thing t) => !t.IsForbidden(pawn) && pawn.CanReserve(t),
                                                                               (Thing t) => SimpleSidearms.ReEquipBest ? t.GetStatValue(StatDefOf.MeleeWeapon_AverageDPS, false) : 0);

                        if (thing == null)
                        {
                            continue;
                        }

                        if (!inCombat)
                        {
                            return(new Job(SidearmsDefOf.EquipSecondary, thing));
                        }
                        else
                        {
                            return(new Job(SidearmsDefOf.EquipSecondaryCombat, thing, pawn.Position));
                        }
                    }
                }

                return(null);
            }
        }
Exemple #10
0
        private string GetEquipped()
        {
            var equipped = Base.equipment?.Primary?.LabelCap;

            return(RestraintsUtility.ShouldShowRestraintsInfo(Base) ? "InRestraints".Translate() : equipped == null ? null : Lang.Get("Model.Info.Equipped", equipped.Bold()));
        }
Exemple #11
0
        public static Job TryGiveJobStatic(Pawn pawn, bool inCombat)
        {
            if (RestraintsUtility.InRestraints(pawn))
            {
                return(null);
            }

            {
                //SetNextTryTick(pawn, Find.TickManager.TicksGame + UnityEngine.Random.Range(PickupCheckIntervalMin, PickupCheckIntervalMax));


                Pawn_EquipmentTracker equipment = pawn.equipment;
                if (equipment == null)
                {
                    return(null);
                }

                GoldfishModule pawnMemory = GoldfishModule.GetGoldfishForPawn(pawn);
                if (pawnMemory == null)
                {
                    return(null);
                }

                WeaponAssingment.reequipPrimaryIfNeededAndAvailable(pawn, pawnMemory);

                foreach (string wepName in pawnMemory.weapons)
                {
                    ThingDef def = DefDatabase <ThingDef> .GetNamedSilentFail(wepName);

                    if (def == null)
                    {
                        continue;
                    }

                    if (!pawn.hasWeaponSomewhere(wepName))
                    {
                        ThingRequest request = new ThingRequest();
                        request.singleDef = def;
                        float maxDist = 1000f;
                        if (pawn.Faction != Faction.OfPlayer || inCombat)
                        {
                            maxDist = 30f;
                        }
                        Thing thing = GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, request, PathEndMode.OnCell, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), maxDist, (Thing x) => (!x.IsForbidden(pawn)) && pawn.CanReserve(x, 1, -1, null, false));

                        if (thing == null)
                        {
                            continue;
                        }

                        if (!inCombat)
                        {
                            return(new Job(SidearmsDefOf.EquipSecondary, thing));
                        }
                        else
                        {
                            return(new Job(SidearmsDefOf.EquipSecondaryCombat, thing, pawn.Position));
                        }
                    }
                }

                return(null);
            }
        }
        public static Job TryGiveJobStatic(Pawn pawn, bool inCombat)
        {
            if (RestraintsUtility.InRestraints(pawn))
            {
                return(null);
            }
            else
            {
                Pawn_EquipmentTracker equipment = pawn.equipment;
                if (equipment == null)
                {
                    return(null);
                }

                GoldfishModule pawnMemory = GoldfishModule.GetGoldfishForPawn(pawn);
                if (pawnMemory == null)
                {
                    return(null);
                }

                if (SimpleSidearms.ToolAutoSwitch && ((Find.TickManager.TicksGame - pawnMemory.delayIdleSwitchTimestamp) < 60))
                {
                    return(null);
                }

                WeaponAssingment.equipBestWeaponFromInventoryByPreference(pawn, Globals.DroppingModeEnum.Calm);

                if (pawnMemory.RememberedWeapons is null)
                {
                    Log.Warning("pawnMemory of " + pawn.Label + " is missing remembered weapons");
                }

                Dictionary <ThingDefStuffDefPair, int> dupeCounters = new Dictionary <ThingDefStuffDefPair, int>();

                foreach (ThingDefStuffDefPair weaponMemory in pawnMemory.RememberedWeapons)
                {
                    if (!dupeCounters.ContainsKey(weaponMemory))
                    {
                        dupeCounters[weaponMemory] = 0;
                    }

                    if (!pawn.hasWeaponSomewhere(weaponMemory, dupeCounters[weaponMemory]))
                    {
                        float maxDist = 1000f;
                        if (pawn.Faction != Faction.OfPlayer)
                        {
                            maxDist = 30f;
                        }
                        if (inCombat)
                        {
                            maxDist = 12f;
                        }
                        IEnumerable <Thing> matchingWeapons = pawn.Map.listerThings.ThingsOfDef(weaponMemory.thing).Where(t => t.Stuff == weaponMemory.stuff);

                        Thing thing = GenClosest.ClosestThing_Global_Reachable(pawn.Position, pawn.Map, matchingWeapons, PathEndMode.OnCell, TraverseParms.For(pawn), maxDist,
                                                                               (Thing t) => !t.IsForbidden(pawn) && pawn.CanReserve(t),
                                                                               (Thing t) => SimpleSidearms.ReEquipBest ? t.GetStatValue(StatDefOf.MeleeWeapon_AverageDPS, false) : 0);
                        //this works properly because better ranged weapons also happen to be better at pistolwhipping
                        //okay past me, WHAT? Why?

                        if (thing == null)
                        {
                            continue;
                        }

                        if (!inCombat)
                        {
                            return(JobMaker.MakeJob(SidearmsDefOf.ReequipSecondary, thing));
                        }
                        else
                        {
                            return(JobMaker.MakeJob(SidearmsDefOf.ReequipSecondaryCombat, thing, pawn.Position));
                        }
                    }

                    dupeCounters[weaponMemory]++;
                }

                return(null);
            }
        }
Exemple #13
0
        public static Job TryGiveJobStatic(Pawn pawn, bool inCombat)
        {
            if (!Settings.ReEquipOutOfCombat)
            {
                return(null);
            }
            if (!Settings.ReEquipInCombat && inCombat)
            {
                return(null);
            }
            if (RestraintsUtility.InRestraints(pawn))
            {
                return(null);
            }
            else
            {
                if (!pawn.IsValidSidearmsCarrier())
                {
                    return(null);
                }

                CompSidearmMemory pawnMemory = CompSidearmMemory.GetMemoryCompForPawn(pawn);
                if (pawnMemory == null)
                {
                    return(null);
                }

                //if (pawnMemory.IsUsingAutotool(true))
                //    return null;

                //WeaponAssingment.equipBestWeaponFromInventoryByPreference(pawn, Globals.DroppingModeEnum.Calm);

                if (pawnMemory.RememberedWeapons is null)
                {
                    Log.Warning("pawnMemory of " + pawn.Label + " is missing remembered weapons");
                }

                Dictionary <ThingDefStuffDefPair, int> dupeCounters = new Dictionary <ThingDefStuffDefPair, int>();

                foreach (ThingDefStuffDefPair weaponMemory in pawnMemory.RememberedWeapons)
                {
                    if (!dupeCounters.ContainsKey(weaponMemory))
                    {
                        dupeCounters[weaponMemory] = 0;
                    }

                    if (!pawn.hasWeaponType(weaponMemory, dupeCounters[weaponMemory]))
                    {
                        float maxDist = 1000f;
                        if (pawn.Faction != Faction.OfPlayer)
                        {
                            maxDist = 30f;
                        }
                        if (inCombat)
                        {
                            maxDist = 12f;
                        }

                        bool bladelinkable = weaponMemory.thing.HasComp(typeof(CompBladelinkWeapon));
                        bool biocodeable   = weaponMemory.thing.HasComp(typeof(CompBiocodable));

                        IEnumerable <ThingWithComps> matchingWeapons = pawn.Map.listerThings.ThingsOfDef(weaponMemory.thing).OfType <ThingWithComps>().Where(t => t.Stuff == weaponMemory.stuff);
                        if (bladelinkable)
                        {
                            matchingWeapons = matchingWeapons.Where(t =>
                            {
                                CompBladelinkWeapon bladelink = t.GetComp <CompBladelinkWeapon>();
                                return(bladelink != null && bladelink.Biocoded && bladelink.CodedPawn == pawn);
                            });
                        }
                        if (biocodeable)
                        {
                            matchingWeapons = matchingWeapons.Where(t =>
                            {
                                CompBiocodable biocode = t.GetComp <CompBiocodable>();
                                if (biocode == null)
                                {
                                    return(true); //not sure how this could ever happen...
                                }
                                if (biocode.Biocoded && biocode.CodedPawn != pawn)
                                {
                                    return(false);
                                }
                                return(true);
                            });
                        }

                        Thing thing = GenClosest.ClosestThing_Global_Reachable(pawn.Position, pawn.Map, matchingWeapons, PathEndMode.OnCell, TraverseParms.For(pawn), maxDist,
                                                                               (Thing t) => !t.IsForbidden(pawn) && pawn.CanReserve(t),
                                                                               (Thing t) => Settings.ReEquipBest ? t.GetStatValue(StatDefOf.MeleeWeapon_AverageDPS, false) : 0);
                        //this works properly because better ranged weapons also happen to be better at pistolwhipping
                        //okay past me, WHAT? Why?

                        if (thing == null)
                        {
                            continue;
                        }

                        if (!inCombat)
                        {
                            return(JobMaker.MakeJob(SidearmsDefOf.ReequipSecondary, thing));
                        }
                        else
                        {
                            return(JobMaker.MakeJob(SidearmsDefOf.ReequipSecondaryCombat, thing, pawn.Position));
                        }
                    }

                    dupeCounters[weaponMemory]++;
                }

                return(null);
            }
        }