public IntVec3 CocoonPlace(Building_Cocoon exception = null)
    {
        var newPosition  = TargetB.Cell;
        var localCocoons = Utility.CocoonsFor(pawn.Map, pawn);

        if (exception != null)
        {
            localCocoons.Remove(exception);
        }

        //Log.Message("1");
        if (localCocoons == null || localCocoons.Count <= 0)
        {
            return(newPosition);
        }
        //Log.Message("2");

        var tempCocoons = new HashSet <Thing>(localCocoons.InRandomOrder());

        foreach (var thing in tempCocoons)
        {
            var cocoon = (Building_Cocoon)thing;
            //Log.Message("3");
            if (cocoon.NextValidPlacementSpot is { } vec&& vec != default)
            {
                newPosition = vec;
            }
        }

        return(newPosition);
    }
Пример #2
0
    protected override Job TryGiveJob(Pawn pawn)
    {
        var food = pawn.needs.food;

        if (food == null || food.CurCategory < minCategory)
        {
            return(null);
        }

        if (!pawn.RaceProps.Animal)
        {
            return(null);
        }

        var localCocoons = Utility.CocoonsFor(pawn.Map, pawn);

        if (localCocoons != null && localCocoons.Count > 0)
        {
            Building_Cocoon closestCocoon    = null;
            var             shortestDistance = 9999f;
            foreach (var thing1 in localCocoons)
            {
                var cocoon = (Building_Cocoon)thing1;
                //Log.Message("1");
                if (cocoon?.isConsumableBy(pawn) != true || cocoon.CurrentDrinker != null)
                {
                    continue;
                }

                //Log.Message("2");
                if (closestCocoon == null)
                {
                    closestCocoon = cocoon;
                    continue;
                }

                var thisDistance = (float)(cocoon.Position - pawn.Position).LengthHorizontalSquared;
                if (!(thisDistance < shortestDistance))
                {
                    continue;
                }

                shortestDistance = thisDistance;
                closestCocoon    = cocoon;
            }

            if (closestCocoon != null)
            {
                //Log.Message("3");
                closestCocoon.CurrentDrinker = pawn as PawnWebSpinner;
                var newJob = new Job(ROMADefOf.ROMA_ConsumeCocoon, closestCocoon);
                //pawn.Reserve(closestCocoon, newJob);
                return(newJob);
            }
        }


        var desperate = pawn.needs.food.CurCategory == HungerCategory.Starving;

        if (!FoodUtility.TryFindBestFoodSourceFor(pawn, pawn, desperate, out var thing, out var def))
        {
            return(null);
        }

        if (thing is Pawn pawn2)
        {
            var jobToDo = new Job(ROMADefOf.ROMA_SpinPrey, pawn2)
            {
                count = 1
            };
            return(jobToDo);
        }

        if (thing is Building_NutrientPasteDispenser building_NutrientPasteDispenser &&
            !building_NutrientPasteDispenser.HasEnoughFeedstockInHoppers())
        {
            var building = building_NutrientPasteDispenser.AdjacentReachableHopper(pawn);
            if (building != null)
            {
                var hopperSgp = building as ISlotGroupParent;
                var job       = WorkGiver_CookFillHopper.HopperFillFoodJob(pawn, hopperSgp);
                if (job != null)
                {
                    return(job);
                }
            }

            thing = FoodUtility.BestFoodSourceOnMap(pawn, pawn, desperate, out var thingDef,
                                                    FoodPreferability.MealLavish, false, !pawn.IsTeetotaler(), false, false, false);
            if (thing == null)
            {
                return(null);
            }

            def = thingDef;
        }

        var nutrition = FoodUtility.GetNutrition(thing, def);

        return(new Job(JobDefOf.Ingest, thing)
        {
            count = FoodUtility.WillIngestStackCountOf(pawn, def, nutrition)
        });
    }