Exemple #1
0
        /// <summary>
        /// Equips tools
        /// </summary>
        /// <param name="pawn"></param>
        /// <param name="def"></param>
        public static void EquipRigthTool(Pawn pawn, StatDef def)
        {
            if (pawn.story != null && pawn.story.WorkTagIsDisabled(WorkTags.Violent))
            {
                return;
            }

            Apparel_Toolbelt toolbelt = ToolsForHaulUtility.TryGetToolbelt(pawn);

            if (toolbelt != null)
            {
                ThingWithComps thingWithComps = pawn.equipment.Primary;
                float          currentStat    = GetMaxStat(thingWithComps, def);

                foreach (Thing slot in toolbelt.slotsComp.slots)
                {
                    ThingWithComps thingWithComps2 = slot as ThingWithComps;
                    if (thingWithComps2 != null)
                    {
                        if (thingWithComps2.def.IsRangedWeapon || thingWithComps2.def.IsMeleeWeapon)
                        {
                            float candidateStat = GetMaxStat(thingWithComps2, def);
                            if (candidateStat > currentStat)
                            {
                                currentStat    = candidateStat;
                                thingWithComps = thingWithComps2;
                            }
                        }
                    }
                }

                bool unEquipped = thingWithComps != pawn.equipment.Primary;
                if (unEquipped)
                {
                    if (!PreviousPawnWeapon.ContainsKey(pawn))
                    {
                        PreviousPawnWeapon.Add(pawn, pawn.equipment.Primary);
                    }
                    else
                    {
                        PreviousPawnWeapon[pawn] = pawn.equipment.Primary;
                    }

                    toolbelt.slotsComp.SwapEquipment(thingWithComps);

                    // pawn.equipment.TryTransferEquipmentToContainer(pawn.equipment.Primary, pawn.inventory.innerContainer, out dummy);
                    // pawn.equipment.AddEquipment(thingWithComps);
                    // pawn.inventory.innerContainer.Remove(thingWithComps);
                }

                // else
                // {
                // bool flag5 = stat == 0f && def != StatDefOf.WorkSpeedGlobal;
                // if (flag5)
                // {
                // EquipRigthTool(pawn, StatDefOf.WorkSpeedGlobal);
                // }
                // }
            }
        }
        public override ThinkResult TryIssueJobPackage(Pawn pawn)
        {
            Job         job     = this.TryGiveJob(pawn);
            bool        jobNull = job == null;
            ThinkResult result;

            Apparel_Toolbelt toolbelt = ToolsForHaulUtility.TryGetToolbelt(pawn);

            if (toolbelt != null)
            {
                if (PreviousPawnWeapon.ContainsKey(pawn) && PreviousPawnWeapon[pawn] != null)
                {
                    Pawn           wearer         = toolbelt.Wearer;
                    ThingWithComps previousWeapon = PreviousPawnWeapon[pawn];
                    if (previousWeapon != null && toolbelt.slotsComp.slots.Contains(previousWeapon))
                    {
                        for (int i = toolbelt.slotsComp.slots.Count - 1; i >= 0; i--)
                        {
                            var            thing = toolbelt.slotsComp.slots[i];
                            ThingWithComps item  = (ThingWithComps)thing;
                            if (item == previousWeapon)
                            {
                                if (wearer.equipment.Primary != null)
                                {
                                    toolbelt.slotsComp.SwapEquipment(item);
                                }
                                else
                                {
                                    wearer.equipment.AddEquipment(item);
                                    toolbelt.slotsComp.slots.Remove(item);
                                }
                                break;
                            }
                        }
                    }
                }
                PreviousPawnWeapon[pawn] = null;
            }

            if (jobNull)
            {
                result = ThinkResult.NoJob;
            }
            else
            {
                if (pawn.Faction == Faction.OfPlayer && pawn.RaceProps.Humanlike && pawn.RaceProps.IsFlesh)
                {
                    if (job.def == JobDefOf.DoBill)
                    {
                        RightTools.EquipRigthTool(pawn, job.RecipeDef.workSpeedStat);
                    }

                    if (job.def == JobDefOf.FinishFrame || job.def == JobDefOf.Deconstruct || job.def == JobDefOf.Repair || job.def == JobDefOf.BuildRoof || job.def == JobDefOf.RemoveRoof || job.def == JobDefOf.RemoveFloor)
                    {
                        RightTools.EquipRigthTool(pawn, StatDefOf.ConstructionSpeed);
                    }
                    if (job.def == JobDefOf.SmoothFloor)
                    {
                        RightTools.EquipRigthTool(pawn, StatDefOf.SmoothingSpeed);
                    }

                    if (job.def == JobDefOf.Harvest)
                    {
                        RightTools.EquipRigthTool(pawn, StatDefOf.PlantHarvestYield);
                    }
                    if (job.def == JobDefOf.CutPlant || job.def == JobDefOf.Sow)
                    {
                        RightTools.EquipRigthTool(pawn, StatDefOf.PlantWorkSpeed);
                    }

                    if (job.def == JobDefOf.Mine)
                    {
                        RightTools.EquipRigthTool(pawn, StatDefOf.MiningSpeed);
                    }
                }

                result = new ThinkResult(job, this);
            }

            return(result);
        }