public override bool ShouldExecute() { IPointOfInterest nearestPoi = porregistry.GetNearestPoi(entity.ServerPos.XYZ, 256, (poi) => { target = poi as IPointOfInterest; if (poi.Type != "scary") { return(false); } Vec3d pos = target.Position; Cuboidd targetBox = entity.CollisionBox.ToDouble().Translate(entity.ServerPos.X, entity.ServerPos.Y, entity.ServerPos.Z); double distance = targetBox.ShortestDistanceFrom(pos); float minDist = MinDistanceToTarget(); if (distance < minDist) { return(false); } if (target.Position != null) { failedSeekTargets.TryGetValue(target, out FailedAttempt attempt); if (attempt == null || (attempt.Count < 4 || attempt.LastTryMs < world.ElapsedMilliseconds - 60000)) { return(true); } } return(false); }); return(nearestPoi != null); }
public override bool ShouldExecute() { EntityBehaviorProgram prog = entity.GetBehavior <EntityBehaviorProgram>(); if (prog == null || prog.dormant) { return(false); } if (failureTime > entity.World.ElapsedMilliseconds || cooldownUntilMs > entity.World.ElapsedMilliseconds || !prog.CheckArea() || !CanPlant(entity.LeftHandItemSlot?.Itemstack?.Collectible)) { return(false); } targetPoi = porregistry.GetNearestPoi((prog.workArea.End + prog.workArea.Start) / 2, (float)(prog.workArea.Length + prog.workArea.Height + prog.workArea.Width), (poi) => { if (prog.workArea.ContainsOrTouches(poi.Position) && poi is BlockEntityFarmland && world.BlockAccessor.GetBlock(poi.Position.AsBlockPos).Replaceable > 9500) { return(true); } return(false); }); return(targetPoi != null); }
public override void OnEntitySpawn() { base.OnEntitySpawn(); id = entity.World.RegisterGameTickListener(dt => { runAwayFrom = null; try { runAwayFrom = poiRegistry.GetNearestPoi(entity.ServerPos.XYZ, 100, (poi) => { if (poi == null) { return(false); } float?fear = (poi as IPointOfFear)?.FearRadius; if (fear == null) { return(false); } return(poi.Position.DistanceTo(entity.Pos.XYZ) < fear && poi.Type == "scary"); }) as IPointOfFear; if (runAwayFrom == null) { return; } goTo = goTo ?? runAwayFrom.Position.AheadCopy(runAwayFrom.FearRadius + 5, 0, rand.NextDouble() * 360); while (goTo.AsBlockPos.GetBlock(entity.Api).Id != 0 && goTo.AsBlockPos.Y < world.BlockAccessor.MapSizeY) { goTo.Add(0, 1, 0); } } catch (Exception) { } }, 4000 + rand.Next(0, 1000)); }
public override bool ShouldExecute() { if (entity.World.Rand.NextDouble() < 0.005) { return(false); } if (cooldownUntilMs > entity.World.ElapsedMilliseconds) { return(false); } if (cooldownUntilTotalHours > entity.World.Calendar.TotalHours) { return(false); } if (whenInEmotionState != null && !entity.HasEmotionState(whenInEmotionState)) { return(false); } if (whenNotInEmotionState != null && entity.HasEmotionState(whenNotInEmotionState)) { return(false); } EntityBehaviorMultiply bh = entity.GetBehavior <EntityBehaviorMultiply>(); if (bh != null && !bh.ShouldEat) { return(false); } IPointOfInterest nearestPoi = porregistry.GetNearestPoi(entity.ServerPos.XYZ, 32, (poi) => { if (poi.Type != "food") { return(false); } if ((target = poi as IAnimalFoodSource)?.IsSuitableFor(entity) == true) { FailedAttempt attempt; failedSeekTargets.TryGetValue(target, out attempt); doOnce = true; if (attempt == null || (attempt.Count < 4 || attempt.LastTryMs < world.ElapsedMilliseconds - 60000)) { return(true); } } return(false); }); return(nearestPoi != null); }
public override bool ShouldExecute() { runAwayFrom = null; runAwayFrom = (IPointOfFear)poiRegistry.GetNearestPoi(entity.ServerPos.XYZ, 1000, (poi) => { float?fear = (poi as IPointOfFear)?.FearRadius; if (fear == null) { return(false); } return(poi.Position.DistanceTo(entity.Pos.XYZ) < fear && poi.Type == "scary"); }); return(runAwayFrom != null); }
public override bool ShouldExecute() { EntityBehaviorProgram prog = entity.GetBehavior <EntityBehaviorProgram>(); if (prog == null || prog.dormant) { return(false); } if (failureTime > entity.World.ElapsedMilliseconds || cooldownUntilMs > entity.World.ElapsedMilliseconds || !prog.CheckArea() || entity.LeftHandItemSlot.Itemstack?.Collectible?.Tool == null) { return(false); } targetPoi = porregistry.GetNearestPoi((prog.workArea.End + prog.workArea.Start) / 2, (float)(prog.workArea.Length + prog.workArea.Height + prog.workArea.Width), (poi) => { if (poi.Type != "food" || !prog.workArea.ContainsOrTouches(poi.Position)) { return(false); } IAnimalFoodSource foodPoi; if ((poi is BlockEntityBerryBush || poi is BlockEntityBeehive) && (foodPoi = poi as IAnimalFoodSource)?.IsSuitableFor(entity) == true) { return(true); } if (poi is BlockEntityFarmland) { Block harvest = world.BlockAccessor.GetBlock(poi.Position.AsBlockPos); int stage; int.TryParse(harvest.LastCodePart(), out stage); if ((lumber && (harvest?.Code.Path.Contains("log") == true || harvest?.Code.Path.Contains("bamboo-grown") == true) && (!harvest.Code.Path.Contains("resin") || !harvest.Code.Path.Contains("resinharvested")) && entity.LeftHandItemSlot.Itemstack.Collectible.Tool == EnumTool.Axe) || FindMatchCode(harvest.Code) || stage == harvest.CropProps?.GrowthStages || harvest?.GetBehavior <BlockBehaviorHarvestable>() != null) { return(true); } } return(false); }) as IAnimalFoodSource; return(targetPoi != null); }
public void SeekFoodSources(float dt) { shouldSeek = true; nearestPoi = porregistry.GetNearestPoi(entity.ServerPos.XYZ, 32, (poi) => { if (poi.Type != "food") { return(false); } if ((target = poi as IAnimalFoodSource)?.IsSuitableFor(entity) == true) { FailedAttempt attempt; failedSeekTargets.TryGetValue(target, out attempt); doOnce = true; if (attempt == null || (attempt.Count < 4 || attempt.LastTryMs < world.ElapsedMilliseconds - 60000)) { return(true); } } return(false); }); }