public Vector3?FindHerdCenter() { if (string.IsNullOrEmpty(HerdName)) { return(null); } Vector3 position = m_componentCreature.ComponentBody.Position; int num = 0; Vector3 zero = Vector3.Zero; foreach (ComponentCreature creature in m_subsystemCreatureSpawn.Creatures) { if (creature.ComponentHealth.Health > 0f) { ComponentHerdBehavior componentHerdBehavior = creature.Entity.FindComponent <ComponentHerdBehavior>(); if (componentHerdBehavior != null && componentHerdBehavior.HerdName == HerdName) { Vector3 position2 = creature.ComponentBody.Position; if (Vector3.DistanceSquared(position, position2) < m_herdingRange * m_herdingRange) { zero += position2; num++; } } } } if (num > 0) { return(zero / num); } return(null); }
public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) { m_subsystemTerrain = base.Project.FindSubsystem <SubsystemTerrain>(throwOnError: true); m_subsystemTime = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true); m_componentCreature = base.Entity.FindComponent <ComponentCreature>(throwOnError: true); m_componentPathfinding = base.Entity.FindComponent <ComponentPathfinding>(throwOnError: true); m_componentHerdBehavior = base.Entity.FindComponent <ComponentHerdBehavior>(); m_componentCreature.ComponentHealth.Attacked += delegate(ComponentCreature attacker) { SwimAwayFrom(attacker.ComponentBody); }; m_stateMachine.AddState("Inactive", delegate { m_importanceLevel = 0f; m_attacker = null; }, delegate { if (m_attacker != null) { m_timeToForgetAttacker -= m_subsystemTime.GameTimeDelta; if (m_timeToForgetAttacker <= 0f) { m_attacker = null; } } if (m_componentCreature.ComponentHealth.HealthChange < 0f) { m_importanceLevel = ((m_componentCreature.ComponentHealth.Health < 0.33f) ? 300 : 100); } else if (m_attacker != null && Vector3.DistanceSquared(m_attacker.Position, m_componentCreature.ComponentBody.Position) < 25f) { m_importanceLevel = 100f; } if (IsActive) { m_stateMachine.TransitionTo("SwimmingAway"); } }, null); m_stateMachine.AddState("SwimmingAway", delegate { m_componentPathfinding.SetDestination(FindSafePlace(), 1f, 1f, 0, useRandomMovements: false, ignoreHeightDifference: true, raycastDestination: false, null); }, delegate { if (!IsActive || !m_componentPathfinding.Destination.HasValue || m_componentPathfinding.IsStuck) { m_stateMachine.TransitionTo("Inactive"); } }, null); m_stateMachine.TransitionTo("Inactive"); }
public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) { m_subsystemTime = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true); m_subsystemCreatureSpawn = base.Project.FindSubsystem <SubsystemCreatureSpawn>(throwOnError: true); m_componentCreature = base.Entity.FindComponent <ComponentCreature>(throwOnError: true); m_componentPathfinding = base.Entity.FindComponent <ComponentPathfinding>(throwOnError: true); m_componentHerdBehavior = base.Entity.FindComponent <ComponentHerdBehavior>(throwOnError: true); m_stateMachine.AddState("Inactive", delegate { m_importanceLevel = 0f; m_driveVector = Vector3.Zero; }, delegate { if (IsActive) { m_stateMachine.TransitionTo("Drive"); } if (m_driveVector.Length() > 3f) { m_importanceLevel = 7f; } FadeDriveVector(); }, null); m_stateMachine.AddState("Drive", delegate { }, delegate { if (!IsActive) { m_stateMachine.TransitionTo("Inactive"); } if (m_driveVector.LengthSquared() < 1f || m_componentPathfinding.IsStuck) { m_importanceLevel = 0f; } if (m_random.Float(0f, 1f) < 0.1f * m_subsystemTime.GameTimeDelta) { m_componentCreature.ComponentCreatureSounds.PlayIdleSound(skipIfRecentlyPlayed: true); } if (m_random.Float(0f, 1f) < 3f * m_subsystemTime.GameTimeDelta) { Vector3 v = CalculateDriveDirectionAndSpeed(); float speed = MathUtils.Saturate(0.2f * v.Length()); m_componentPathfinding.SetDestination(m_componentCreature.ComponentBody.Position + 15f * Vector3.Normalize(v), speed, 5f, 0, useRandomMovements: false, ignoreHeightDifference: true, raycastDestination: false, null); } FadeDriveVector(); }, null); m_stateMachine.TransitionTo("Inactive"); }
public void CallNearbyCreaturesHelp(ComponentCreature target, float maxRange, float maxChaseTime, bool isPersistent) { Vector3 position = target.ComponentBody.Position; foreach (ComponentCreature creature in m_subsystemCreatureSpawn.Creatures) { if (Vector3.DistanceSquared(position, creature.ComponentBody.Position) < 256f) { ComponentHerdBehavior componentHerdBehavior = creature.Entity.FindComponent <ComponentHerdBehavior>(); if (componentHerdBehavior != null && componentHerdBehavior.HerdName == HerdName && componentHerdBehavior.m_autoNearbyCreaturesHelp) { ComponentChaseBehavior componentChaseBehavior = creature.Entity.FindComponent <ComponentChaseBehavior>(); if (componentChaseBehavior != null && componentChaseBehavior.Target == null) { componentChaseBehavior.Attack(target, maxRange, maxChaseTime, isPersistent); } } } } }
public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) { m_subsystemTerrain = base.Project.FindSubsystem <SubsystemTerrain>(throwOnError: true); m_subsystemTime = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true); m_subsystemNoise = base.Project.FindSubsystem <SubsystemNoise>(throwOnError: true); m_componentCreature = base.Entity.FindComponent <ComponentCreature>(throwOnError: true); m_componentPathfinding = base.Entity.FindComponent <ComponentPathfinding>(throwOnError: true); m_componentHerdBehavior = base.Entity.FindComponent <ComponentHerdBehavior>(); m_componentCreature.ComponentHealth.Attacked += delegate(ComponentCreature attacker) { RunAwayFrom(attacker.ComponentBody); }; m_stateMachine.AddState("Inactive", delegate { m_importanceLevel = 0f; m_lastNoiseSourcePosition = null; }, delegate { if (m_attacker != null) { m_timeToForgetAttacker -= m_subsystemTime.GameTimeDelta; if (m_timeToForgetAttacker <= 0f) { m_attacker = null; } } if (m_componentCreature.ComponentHealth.HealthChange < 0f || (m_attacker != null && Vector3.DistanceSquared(m_attacker.Position, m_componentCreature.ComponentBody.Position) < 36f)) { m_importanceLevel = MathUtils.Max(m_importanceLevel, (m_componentCreature.ComponentHealth.Health < 0.33f) ? 300 : 100); } else if (m_heardNoise) { m_importanceLevel = MathUtils.Max(m_importanceLevel, 5f); } else if (!IsActive) { m_importanceLevel = 0f; } if (IsActive) { m_stateMachine.TransitionTo("RunningAway"); } }, null); m_stateMachine.AddState("RunningAway", delegate { Vector3 value = FindSafePlace(); m_componentPathfinding.SetDestination(value, 1f, 1f, 0, useRandomMovements: false, ignoreHeightDifference: true, raycastDestination: false, null); m_componentCreature.ComponentCreatureSounds.PlayPainSound(); m_subsystemNoise.MakeNoise(m_componentCreature.ComponentBody, 0.25f, 6f); }, delegate { if (!IsActive) { m_stateMachine.TransitionTo("Inactive"); } else if (!m_componentPathfinding.Destination.HasValue || m_componentPathfinding.IsStuck) { m_importanceLevel = 0f; } else if (m_attacker != null) { if (!m_attacker.IsAddedToProject) { m_importanceLevel = 0f; m_attacker = null; } else { ComponentHealth componentHealth = m_attacker.Entity.FindComponent <ComponentHealth>(); if (componentHealth != null && componentHealth.Health == 0f) { m_importanceLevel = 0f; m_attacker = null; } } } }, null); m_stateMachine.TransitionTo("Inactive"); }