Exemplo n.º 1
0
        public static bool Prefix(WorkGiver_Scanner __instance, ref bool __result)
        {
            bool isPatchAllowed = MainMod.ModConfig.IsPatchAllowed(__instance.GetType());

            __result = isPatchAllowed;

            return(!isPatchAllowed);
        }
        public static bool Prefix(WorkGiver_Scanner __instance, ref bool __result)
        {
            __result = MainMod.ModConfig.IsPatchAllowed(__instance.GetType());

            return(false);
        }
        public static void Postfix(Pawn pawn, TargetInfo t, ref float __result, WorkGiver_Scanner __instance)
        {
            if (!(pawn != null && pawn.Faction?.IsPlayer == true))
            {
                return;
            }

            Map map = pawn.Map;

            if (map == null)
            {
                map = t.Map;
            }

            float modPriority = MainMod.Data.GetPriorityOnCell(map, t.Cell);

            if (t.HasThing)
            {
                modPriority += MainMod.Data.GetPriority(t.Thing);
            }

            if (__result < 0f && !LoggedNegWarn)
            {
                Log.Warning("Patching priority but old priority was less than 0. This can cause unexpected behavior. WorkGiver type was " + __instance.GetType().FullName);
                LoggedNegWarn = true;
            }

            __result += modPriority;
        }
        public override IEnumerable <IntVec3> PotentialWorkCellsGlobal(Pawn pawn)
        {
            if (wrappedScanner == null)
            {
                CreateWrappedScanner();
            }

            if (wrappedScanner == null)
            {
                foreach (var intVec3 in base.PotentialWorkCellsGlobal(pawn))
                {
                    yield return(intVec3);
                }

                yield break;
            }

            //Adapted from latter half of WorkGiver_Grower PotentialWorkCellsGlobal
            var maxDanger      = pawn.NormalMaxDanger();
            var wantedPlantDef = wrappedScanner.GetType().GetField("wantedPlantDef"
                                                                   , BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);

            wantedPlantDef?.SetValue(wrappedScanner, null);

            if (!(pawn.Map.zoneManager.ZoneAt(pawn.Position) is Zone_Growing growZone))
            {
                //Try edge cells in pawn facing direction next
                growZone = GenAdj
                           .CellsAdjacentAlongEdge(pawn.Position, pawn.Rotation, new IntVec2(1, 1),
                                                   Utilities.EdgeFacingRotation(pawn.Rotation)).Select(p => pawn.Map.zoneManager.ZoneAt(p))
                           .OfType <Zone_Growing>().FirstOrDefault();

                if (growZone == default(Zone_Growing))
                {
                    yield break;
                }
            }

            if (growZone.cells.Count == 0)
            {
                Log.ErrorOnce("Grow zone has 0 cells: " + growZone, -563487);
            }
            else if (!growZone.ContainsStaticFire)
            {
                //If there is an extraRequirement then check it, otherwise true
                var extraRequirements = wrappedScanner.GetType().GetMethod("ExtraRequirements"
                                                                           , BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
                if ((bool?)extraRequirements?.Invoke(wrappedScanner, new object[] { growZone, pawn }) ?? true)
                {
                    if (pawn.CanReach(growZone.Cells[0], PathEndMode.OnCell, maxDanger))
                    {
                        var addCells = true;
                        if (wrappedScanner.ToString().Contains("Sow"))
                        {
                            var plantToSow = growZone.GetPlantDefToGrow();
                            addCells = plantToSow.plant.sowMinSkill <= pawn.skills.GetSkill(SkillDefOf.Plants).Level;
                            //Log.Message("Pawn: " + pawn.NameShortColored + " GetPlantDefToGrow: " + growZone.GetPlantDefToGrow() + " CanSow: " + addCells);
                        }

                        if (addCells)
                        {
                            foreach (var potentialWorkCellsGlobal in growZone.cells)
                            {
                                yield return(potentialWorkCellsGlobal);
                            }
                        }

                        wantedPlantDef?.SetValue(wrappedScanner, null);
                    }
                }
            }

            wantedPlantDef?.SetValue(wrappedScanner, null);
        }