Пример #1
0
        public static void _ctor(Toil __instance)
        {
            if (SimpleSidearms.ToolAutoSwitch == true)
            {
                Toil toil = __instance;
                toil.AddPreInitAction(delegate
                {
                    if (toil.activeSkill != null && toil.activeSkill() != null && toil.GetActor() != null)
                    {
                        //Log.Message("Pawn " + toil.GetActor().Label + " initializing toil that uses skill " + toil.activeSkill().label);
                        bool usingAppropriateTool = WeaponAssingment.equipBestWeaponFromInventoryByStatModifiers(toil.GetActor(), SkillStatMap.Map[toil.activeSkill()]);
                        if (usingAppropriateTool)
                        {
                            GoldfishModule pawnMemory = GoldfishModule.GetGoldfishForPawn(toil.GetActor());
                            if (pawnMemory != null)
                            {
                                pawnMemory.autotoolToil = toil;
                            }
                        }
                    }
                });
                toil.AddFinishAction(delegate
                {
                    GoldfishModule pawnMemory = GoldfishModule.GetGoldfishForPawn(toil.GetActor());
                    if (pawnMemory != null && pawnMemory.autotoolToil == toil)
                    {
                        pawnMemory.delayIdleSwitchTimestamp = Find.TickManager.TicksGame;
                    }

                    pawnMemory.autotoolToil = null;
                });
            }
        }
Пример #2
0
        public static void _ctor(Toil __instance)
        {
            if (SimpleSidearms.ToolAutoSwitch == true)
            {
                Toil toil = __instance;
                if (toil == null)
                {
                    return;
                }

                toil.AddPreInitAction(delegate
                {
                    Pawn pawn = toil.GetActor();
                    if (pawn == null || !pawn.IsValidSidearmsCarrier())
                    {
                        return;
                    }

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

                    StatDef activeStat = pawn.CurJob?.RecipeDef?.workSpeedStat;

                    SkillDef activeSkill = null;
                    if (toil.activeSkill != null && toil.activeSkill() != null)
                    {
                        activeSkill = toil.activeSkill();
                    }
                    else
                    {
                        activeSkill = pawn.CurJob?.RecipeDef?.workSkill;
                    }

                    List <StatDef> possiblyActiveStats = new List <StatDef>();
                    if (activeStat != null)
                    {
                        possiblyActiveStats.Add(activeStat);
                    }
                    else if (activeSkill != null && SkillStatMap.Map.ContainsKey(activeSkill))
                    {
                        possiblyActiveStats.AddRange(SkillStatMap.Map[activeSkill]);
                    }

                    bool usingAppropriateTool = WeaponAssingment.equipBestWeaponFromInventoryByStatModifiers(toil.GetActor(), possiblyActiveStats);
                    if (usingAppropriateTool)
                    {
                        if (pawnMemory != null)
                        {
                            pawnMemory.autotoolToil = toil;
                            pawnMemory.autotoolJob  = pawn.CurJobDef;
                        }
                    }
                });
                toil.AddFinishAction(delegate
                {
                    Pawn pawn = toil.GetActor();
                    if (!pawn.IsValidSidearmsCarrier())
                    {
                        return;
                    }
                    CompSidearmMemory pawnMemory = CompSidearmMemory.GetMemoryCompForPawn(pawn);
                    if (pawnMemory != null)
                    {
                        if (pawnMemory.autotoolToil == toil)
                        {
                            pawnMemory.delayIdleSwitchTimestamp = Find.TickManager.TicksGame;
                        }
                        else
                        {
                            pawnMemory.autotoolToil = null;
                        }
                    }
                });
            }
        }