public ComponentBody FindNearestBodyInFront(Vector3 position, Vector2 direction) { if (m_subsystemTime.GameTime >= m_nextBodiesUpdateTime) { m_nextBodiesUpdateTime = m_subsystemTime.GameTime + 0.5; m_nearbyBodies.Clear(); m_subsystemBodies.FindBodiesAroundPoint(m_componentCreature.ComponentBody.Position.XZ, 4f, m_nearbyBodies); } ComponentBody result = null; float num = float.MaxValue; foreach (ComponentBody nearbyBody in m_nearbyBodies) { if (nearbyBody != m_componentCreature.ComponentBody && !(MathUtils.Abs(nearbyBody.Position.Y - m_componentCreature.ComponentBody.Position.Y) > 1.1f) && Vector2.Dot(nearbyBody.Position.XZ - position.XZ, direction) > 0f) { float num2 = Vector2.DistanceSquared(nearbyBody.Position.XZ, position.XZ); if (num2 < num) { num = num2; result = nearbyBody; } } } return(result); }
public float ScoreSafePlace(Vector3 currentPosition, Vector3 safePosition, Vector3?lookDirection) { float num = 16f; Vector3 position = m_componentCreature.ComponentBody.Position; m_componentBodies.Clear(); m_subsystemBodies.FindBodiesAroundPoint(new Vector2(position.X, position.Z), 16f, m_componentBodies); for (int i = 0; i < m_componentBodies.Count; i++) { ComponentBody componentBody = m_componentBodies.Array[i]; if (!IsPredator(componentBody.Entity)) { continue; } Vector3 position2 = componentBody.Position; Vector3 v = safePosition - position2; if (!lookDirection.HasValue || 0f - Vector3.Dot(lookDirection.Value, v) > 0f) { if (v.Y >= 4f) { v *= 2f; } num = MathUtils.Min(num, v.Length()); } } float num2 = Vector3.Distance(currentPosition, safePosition); if (num2 < 8f) { return(num * 0.5f); } return(num * MathUtils.Lerp(1f, 0.75f, MathUtils.Saturate(num2 / 20f))); }
public void MakeLightningStrike(Vector3 targetPosition) { if (m_lightningStrikePosition.HasValue || !(m_subsystemTime.GameTime - m_lastLightningStrikeTime > 1.0)) { return; } m_lastLightningStrikeTime = m_subsystemTime.GameTime; m_lightningStrikePosition = targetPosition; m_lightningStrikeBrightness = 1f; float num = float.MaxValue; foreach (Vector3 listenerPosition in m_subsystemAudio.ListenerPositions) { float num2 = Vector2.Distance(new Vector2(listenerPosition.X, listenerPosition.Z), new Vector2(targetPosition.X, targetPosition.Z)); if (num2 < num) { num = num2; } } float delay = m_subsystemAudio.CalculateDelay(num); if (num < 40f) { m_subsystemAudio.PlayRandomSound("Audio/ThunderNear", 1f, m_random.Float(-0.2f, 0.2f), 0f, delay); } else if (num < 200f) { m_subsystemAudio.PlayRandomSound("Audio/ThunderFar", 0.8f, m_random.Float(-0.2f, 0.2f), 0f, delay); } if (m_subsystemGameInfo.WorldSettings.EnvironmentBehaviorMode != 0) { return; } DynamicArray <ComponentBody> dynamicArray = new DynamicArray <ComponentBody>(); m_subsystemBodies.FindBodiesAroundPoint(new Vector2(targetPosition.X, targetPosition.Z), 4f, dynamicArray); for (int i = 0; i < dynamicArray.Count; i++) { ComponentBody componentBody = dynamicArray.Array[i]; if (componentBody.Position.Y > targetPosition.Y - 1.5f && Vector2.Distance(new Vector2(componentBody.Position.X, componentBody.Position.Z), new Vector2(targetPosition.X, targetPosition.Z)) < 4f) { componentBody.Entity.FindComponent <ComponentOnFire>()?.SetOnFire(null, m_random.Float(12f, 15f)); } ComponentCreature componentCreature = componentBody.Entity.FindComponent <ComponentCreature>(); if (componentCreature != null && componentCreature.PlayerStats != null) { componentCreature.PlayerStats.StruckByLightning++; } } int x = Terrain.ToCell(targetPosition.X); int num3 = Terrain.ToCell(targetPosition.Y); int z = Terrain.ToCell(targetPosition.Z); float pressure = (m_random.Float(0f, 1f) < 0.2f) ? 39 : 19; base.Project.FindSubsystem <SubsystemExplosions>(throwOnError: true).AddExplosion(x, num3 + 1, z, pressure, isIncendiary: false, noExplosionSound: true); }
public void FindBodiesCollisionBoxes(Vector3 position, DynamicArray <CollisionBox> result) { m_componentBodies.Clear(); m_subsystemBodies.FindBodiesAroundPoint(new Vector2(position.X, position.Z), 4f, m_componentBodies); for (int i = 0; i < m_componentBodies.Count; i++) { ComponentBody componentBody = m_componentBodies.Array[i]; if (componentBody != this && componentBody != m_parentBody && componentBody.m_parentBody != this) { result.Add(new CollisionBox { Box = componentBody.BoundingBox, ComponentBody = componentBody }); } } }
public ComponentRider FindNearbyRider(float range) { m_bodies.Clear(); m_subsystemBodies.FindBodiesAroundPoint(new Vector2(m_componentCreature.ComponentBody.Position.X, m_componentCreature.ComponentBody.Position.Z), range, m_bodies); foreach (ComponentBody body in m_bodies) { if (Vector3.DistanceSquared(m_componentCreature.ComponentBody.Position, body.Position) < range * range) { ComponentRider componentRider = body.Entity.FindComponent <ComponentRider>(); if (componentRider != null) { return(componentRider); } } } return(null); }
public void MakeNoisepublic(ComponentBody sourceBody, Vector3 position, float loudness, float range) { float num = range * range; m_componentBodies.Clear(); m_subsystemBodies.FindBodiesAroundPoint(new Vector2(position.X, position.Z), range, m_componentBodies); for (int i = 0; i < m_componentBodies.Count; i++) { ComponentBody componentBody = m_componentBodies.Array[i]; if (componentBody != sourceBody && Vector3.DistanceSquared(componentBody.Position, position) < num) { foreach (INoiseListener item in componentBody.Entity.FindComponents <INoiseListener>()) { item.HearNoise(sourceBody, position, loudness); } } } }
public override bool OnUse(Ray3 ray, ComponentMiner componentMiner) { m_subsystemAudio.PlayRandomSound("Audio/Whistle", 1f, m_random.Float(-0.2f, 0f), ray.Position, 4f, autoDelay: true); m_subsystemNoise.MakeNoise(componentMiner.ComponentCreature.ComponentBody, 0.5f, 30f); DynamicArray <ComponentBody> dynamicArray = new DynamicArray <ComponentBody>(); m_subsystemBodies.FindBodiesAroundPoint(new Vector2(componentMiner.ComponentCreature.ComponentBody.Position.X, componentMiner.ComponentCreature.ComponentBody.Position.Z), 64f, dynamicArray); float num = float.PositiveInfinity; List <ComponentBody> list = new List <ComponentBody>(); foreach (ComponentBody item in dynamicArray) { ComponentSummonBehavior componentSummonBehavior = item.Entity.FindComponent <ComponentSummonBehavior>(); if (componentSummonBehavior != null && componentSummonBehavior.IsEnabled) { float num2 = Vector3.Distance(item.Position, componentMiner.ComponentCreature.ComponentBody.Position); if (num2 > 4f && componentSummonBehavior.SummonTarget == null) { list.Add(item); num = MathUtils.Min(num, num2); } else { componentSummonBehavior.SummonTarget = componentMiner.ComponentCreature.ComponentBody; } } } foreach (ComponentBody item2 in list) { ComponentSummonBehavior componentSummonBehavior2 = item2.Entity.FindComponent <ComponentSummonBehavior>(); if (componentSummonBehavior2 != null && Vector3.Distance(item2.Position, componentMiner.ComponentCreature.ComponentBody.Position) < num + 4f) { componentSummonBehavior2.SummonTarget = componentMiner.ComponentCreature.ComponentBody; } } componentMiner.DamageActiveTool(1); return(true); }
public ComponentMount FindNearestMount() { Vector2 point = new Vector2(ComponentCreature.ComponentBody.Position.X, ComponentCreature.ComponentBody.Position.Z); m_componentBodies.Clear(); m_subsystemBodies.FindBodiesAroundPoint(point, 2.5f, m_componentBodies); float num = 0f; ComponentMount result = null; foreach (ComponentMount item in from b in m_componentBodies select b.Entity.FindComponent <ComponentMount>() into m where m != null && m.Entity != base.Entity select m) { float num2 = ScoreMount(item, 2.5f); if (num2 > num) { num = num2; result = item; } } return(result); }
public ComponentCreature FindTarget() { Vector3 position = m_componentCreature.ComponentBody.Position; ComponentCreature result = null; float num = 0f; m_componentBodies.Clear(); m_subsystemBodies.FindBodiesAroundPoint(new Vector2(position.X, position.Z), m_range, m_componentBodies); for (int i = 0; i < m_componentBodies.Count; i++) { ComponentCreature componentCreature = m_componentBodies.Array[i].Entity.FindComponent <ComponentCreature>(); if (componentCreature != null) { float num2 = ScoreTarget(componentCreature); if (num2 > num) { num = num2; result = componentCreature; } } } return(result); }