public Vector3 FindSafePlace() { Vector3 vector = 0.5f * (m_componentCreature.ComponentBody.BoundingBox.Min + m_componentCreature.ComponentBody.BoundingBox.Max); Vector3?herdPosition = (m_componentHerdBehavior != null) ? m_componentHerdBehavior.FindHerdCenter() : null; float num = float.NegativeInfinity; Vector3 result = vector; for (int i = 0; i < 40; i++) { Vector2 vector2 = m_random.Vector2(1f, 1f); float y = 0.4f * m_random.Float(-1f, 1f); Vector3 v = Vector3.Normalize(new Vector3(vector2.X, y, vector2.Y)); Vector3 vector3 = vector + m_random.Float(10f, 20f) * v; TerrainRaycastResult?terrainRaycastResult = m_subsystemTerrain.Raycast(vector, vector3, useInteractionBoxes : false, skipAirBlocks : false, delegate(int value, float d) { int num3 = Terrain.ExtractContents(value); return(!(BlocksManager.Blocks[num3] is WaterBlock)); }); Vector3 vector4 = terrainRaycastResult.HasValue ? (vector + v * terrainRaycastResult.Value.Distance) : vector3; float num2 = ScoreSafePlace(vector, vector4, herdPosition); if (num2 > num) { num = num2; result = vector4; } } return(result); }
public Vector3 FindSafePlace() { Vector3 position = m_componentCreature.ComponentBody.Position; Vector3?herdPosition = (m_componentHerdBehavior != null) ? m_componentHerdBehavior.FindHerdCenter() : null; if (herdPosition.HasValue && Vector3.DistanceSquared(position, herdPosition.Value) < 144f) { herdPosition = null; } float num = float.NegativeInfinity; Vector3 result = position; for (int i = 0; i < 30; i++) { int num2 = Terrain.ToCell(position.X + m_random.Float(-25f, 25f)); int num3 = Terrain.ToCell(position.Z + m_random.Float(-25f, 25f)); for (int num4 = 255; num4 >= 0; num4--) { int cellContents = m_subsystemTerrain.Terrain.GetCellContents(num2, num4, num3); if (BlocksManager.Blocks[cellContents].IsCollidable || cellContents == 18) { Vector3 vector = new Vector3((float)num2 + 0.5f, (float)num4 + 1.1f, (float)num3 + 0.5f); float num5 = ScoreSafePlace(position, vector, herdPosition, m_lastNoiseSourcePosition, cellContents); if (num5 > num) { num = num5; result = vector; } break; } } } return(result); }