public override bool ShouldExecute() { // Don't check often: skip this 97% of the time if (entity.World.Rand.NextDouble() > 0.03) { return(false); } // Don't search more often than every 15 seconds if (lastPOISearchTotalMs + 15000 > entity.World.ElapsedMilliseconds) { return(false); } if (cooldownUntilMs > entity.World.ElapsedMilliseconds) { return(false); } if (cooldownUntilTotalHours > entity.World.Calendar.TotalHours) { return(false); } if (whenInEmotionState != null && bhEmo?.IsInEmotionState(whenInEmotionState) != true) { return(false); } if (whenNotInEmotionState != null && bhEmo?.IsInEmotionState(whenNotInEmotionState) == true) { return(false); } PortionsEatenForLay = 3; // Now the behavior will certainly happen, we can consume food // Hen needs to be not hungry, in order to EITHER lay an egg OR sit and incubate for a long time if (!DidConsumeFood(PortionsEatenForLay)) { return(false); } if (attemptLayEggTotalHours <= 0) { attemptLayEggTotalHours = entity.World.Calendar.TotalHours; } lastPOISearchTotalMs = entity.World.ElapsedMilliseconds; targetPoi = FindPOI(42) as IAnimalNest; if (targetPoi == null) { // Failed search: may lay an infertile egg on the ground LayEggOnGround(); } return(targetPoi != null); }
void onBadTarget() { IAnimalNest newTarget = null; if (attemptLayEggTotalHours >= 0 && entity.World.Calendar.TotalHours - attemptLayEggTotalHours > 12) { LayEggOnGround(); } else { if (rand.NextDouble() > 0.4) { // Look for another nearby henbox newTarget = FindPOI(18) as IAnimalNest; } } FailedAttempt attempt = null; failedSeekTargets.TryGetValue(targetPoi, out attempt); if (attempt == null) { failedSeekTargets[targetPoi] = attempt = new FailedAttempt(); } attempt.Count++; attempt.LastTryMs = world.ElapsedMilliseconds; if (newTarget != null) { targetPoi = newTarget; nowStuck = false; sitTimeNow = 0; laid = false; pathTraverser.NavigateTo_Async(targetPoi.Position, moveSpeed, MinDistanceToTarget() - 0.1f, OnGoalReached, OnStuck, null, 1000, 1); sitAnimStarted = false; } }