public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
 {
     m_subsystemParticles   = base.Project.FindSubsystem <SubsystemParticles>(throwOnError: true);
     m_subsystemAudio       = base.Project.FindSubsystem <SubsystemAudio>(throwOnError: true);
     m_subsystemTerrain     = base.Project.FindSubsystem <SubsystemTerrain>(throwOnError: true);
     m_componentCreature    = base.Entity.FindComponent <ComponentCreature>(throwOnError: true);
     m_componentPathfinding = base.Entity.FindComponent <ComponentPathfinding>(throwOnError: true);
     m_stateMachine.AddState("Inactive", null, delegate
     {
         m_importanceLevel = MathUtils.Lerp(0f, 400f, MathUtils.Saturate((0.75f - m_componentCreature.ComponentHealth.Air) / 0.75f));
         if (IsActive)
         {
             m_stateMachine.TransitionTo("Surface");
         }
     }, null);
     m_stateMachine.AddState("Surface", delegate
     {
         m_componentPathfinding.Stop();
     }, delegate
     {
         _ = m_componentCreature.ComponentBody.Position;
         if (!m_componentPathfinding.Destination.HasValue)
         {
             Vector3?destination = FindSurfaceDestination();
             if (destination.HasValue)
             {
                 float speed = (m_componentCreature.ComponentHealth.Air < 0.25f) ? 1f : m_random.Float(0.4f, 0.6f);
                 m_componentPathfinding.SetDestination(destination, speed, 1f, 0, useRandomMovements: false, ignoreHeightDifference: false, raycastDestination: false, null);
             }
         }
         else if (m_componentPathfinding.IsStuck)
         {
             m_importanceLevel = 0f;
         }
         if (m_componentCreature.ComponentHealth.Air > 0.9f)
         {
             m_stateMachine.TransitionTo("Breathe");
         }
     }, null);
     m_stateMachine.AddState("Breathe", delegate
     {
         Vector3 forward = m_componentCreature.ComponentBody.Matrix.Forward;
         Vector3 value   = m_componentCreature.ComponentBody.Matrix.Translation + 10f * forward + new Vector3(0f, 2f, 0f);
         m_componentPathfinding.SetDestination(value, 0.6f, 1f, 0, useRandomMovements: false, ignoreHeightDifference: false, raycastDestination: false, null);
         m_particleSystem = new WhalePlumeParticleSystem(m_subsystemTerrain, m_random.Float(0.8f, 1.1f), m_random.Float(1f, 1.3f));
         m_subsystemParticles.AddParticleSystem(m_particleSystem);
         m_subsystemAudio.PlayRandomSound("Audio/Creatures/WhaleBlow", 1f, m_random.Float(-0.2f, 0.2f), m_componentCreature.ComponentBody.Position, 10f, autoDelay: true);
     }, delegate
     {
         m_particleSystem.Position = m_componentCreature.ComponentBody.Position + new Vector3(0f, 0.8f * m_componentCreature.ComponentBody.BoxSize.Y, 0f);
         if (!m_subsystemParticles.ContainsParticleSystem(m_particleSystem))
         {
             m_importanceLevel = 0f;
         }
     }, delegate
     {
         m_particleSystem.IsStopped = true;
         m_particleSystem           = null;
     });
 }
 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
 {
     m_subsystemBodies      = base.Project.FindSubsystem <SubsystemBodies>(throwOnError: true);
     m_subsystemTerrain     = base.Project.FindSubsystem <SubsystemTerrain>(throwOnError: true);
     m_subsystemAudio       = base.Project.FindSubsystem <SubsystemAudio>(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_componentCreature.ComponentBody.CollidedWithBody += delegate
     {
         if (m_stateMachine.CurrentState != "RunningAway")
         {
             m_stateMachine.TransitionTo("DangerDetected");
         }
     };
     m_stateMachine.AddState("LookingForDanger", null, delegate
     {
         if (ScanForDanger())
         {
             m_stateMachine.TransitionTo("DangerDetected");
         }
     }, null);
     m_stateMachine.AddState("DangerDetected", delegate
     {
         m_importanceLevel = ((m_componentCreature.ComponentHealth.Health < 0.33f) ? 300 : 100);
         m_nextUpdateTime  = 0.0;
     }, delegate
     {
         if (IsActive)
         {
             m_stateMachine.TransitionTo("RunningAway");
             m_nextUpdateTime = 0.0;
         }
     }, null);
     m_stateMachine.AddState("RunningAway", delegate
     {
         m_componentPathfinding.SetDestination(FindSafePlace(), 1f, 1f, 0, useRandomMovements: false, ignoreHeightDifference: true, raycastDestination: false, null);
         m_subsystemAudio.PlayRandomSound("Audio/Creatures/Wings", 0.8f, m_random.Float(-0.1f, 0.2f), m_componentCreature.ComponentBody.Position, 3f, autoDelay: true);
         m_componentCreature.ComponentCreatureSounds.PlayPainSound();
         m_subsystemNoise.MakeNoise(m_componentCreature.ComponentBody, 0.25f, 6f);
     }, delegate
     {
         if (!IsActive || !m_componentPathfinding.Destination.HasValue || m_componentPathfinding.IsStuck)
         {
             m_stateMachine.TransitionTo("LookingForDanger");
         }
         else if (ScoreSafePlace(m_componentCreature.ComponentBody.Position, m_componentPathfinding.Destination.Value, null) < 4f)
         {
             m_componentPathfinding.SetDestination(FindSafePlace(), 1f, 0.5f, 0, useRandomMovements: false, ignoreHeightDifference: true, raycastDestination: false, null);
         }
     }, delegate
     {
         m_importanceLevel = 0f;
     });
     m_stateMachine.TransitionTo("LookingForDanger");
 }
 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
 {
     m_subsystemTime        = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true);
     m_subsystemBodies      = base.Project.FindSubsystem <SubsystemBodies>(throwOnError: true);
     m_componentCreature    = base.Entity.FindComponent <ComponentCreature>(throwOnError: true);
     m_componentPathfinding = base.Entity.FindComponent <ComponentPathfinding>(throwOnError: true);
     m_stareRange           = valuesDictionary.GetValue <float>("StareRange");
     m_stateMachine.AddState("Inactive", delegate
     {
         m_importanceLevel = 0f;
     }, delegate
     {
         if (m_subsystemTime.GameTime > m_stareEndTime + 8.0 && m_random.Float(0f, 1f) < 1f * m_subsystemTime.GameTimeDelta)
         {
             m_target = FindTarget();
             if (m_target != null)
             {
                 float probability = (m_target.Entity.FindComponent <ComponentPlayer>() != null) ? 1f : 0.25f;
                 if (m_random.Bool(probability))
                 {
                     m_importanceLevel = m_random.Float(3f, 5f);
                 }
             }
         }
         if (IsActive)
         {
             m_stateMachine.TransitionTo("Stare");
         }
     }, null);
     m_stateMachine.AddState("Stare", delegate
     {
         m_stareEndTime = m_subsystemTime.GameTime + (double)m_random.Float(6f, 12f);
         if (m_target != null)
         {
             Vector3 position = m_componentCreature.ComponentBody.Position;
             Vector3 v        = Vector3.Normalize(m_target.ComponentBody.Position - position);
             m_componentPathfinding.SetDestination(position + 1.1f * v, m_random.Float(0.3f, 0.4f), 1f, 0, useRandomMovements: false, ignoreHeightDifference: true, raycastDestination: false, null);
             if (m_random.Float(0f, 1f) < 0.5f)
             {
                 m_componentCreature.ComponentCreatureSounds.PlayIdleSound(skipIfRecentlyPlayed: false);
             }
         }
     }, delegate
     {
         if (!IsActive || m_target == null || m_componentPathfinding.IsStuck || m_subsystemTime.GameTime > m_stareEndTime)
         {
             m_stateMachine.TransitionTo("Inactive");
         }
         else if (m_random.Float(0f, 1f) < 1f * m_subsystemTime.GameTimeDelta && ScoreTarget(m_target) <= 0f)
         {
             m_stateMachine.TransitionTo("Inactive");
         }
         else
         {
             m_componentCreature.ComponentCreatureModel.LookAtOrder = m_target.ComponentCreatureModel.EyePosition;
         }
     }, null);
     m_stateMachine.TransitionTo("Inactive");
 }
示例#4
0
 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_stateMachine.AddState("Inactive", delegate
     {
         m_importanceLevel = m_random.Float(0f, 1f);
     }, delegate
     {
         if (m_random.Float(0f, 1f) < 0.05f * m_subsystemTime.GameTimeDelta)
         {
             m_importanceLevel = m_random.Float(1f, 2f);
         }
         if (IsActive)
         {
             m_stateMachine.TransitionTo("Walk");
         }
     }, null);
     m_stateMachine.AddState("Walk", delegate
     {
         float speed = (m_componentCreature.ComponentBody.ImmersionFactor > 0.5f) ? 1f : m_random.Float(0.25f, 0.35f);
         m_componentPathfinding.SetDestination(FindDestination(), speed, 1f, 0, useRandomMovements: false, ignoreHeightDifference: true, raycastDestination: false, null);
     }, delegate
     {
         if (m_componentPathfinding.IsStuck || !IsActive)
         {
             m_stateMachine.TransitionTo("Inactive");
         }
         if (!m_componentPathfinding.Destination.HasValue)
         {
             if (m_random.Float(0f, 1f) < 0.5f)
             {
                 m_stateMachine.TransitionTo("Inactive");
             }
             else
             {
                 m_stateMachine.TransitionTo(null);
                 m_stateMachine.TransitionTo("Walk");
             }
         }
         if (m_random.Float(0f, 1f) < 0.1f * m_subsystemTime.GameTimeDelta)
         {
             m_componentCreature.ComponentCreatureSounds.PlayIdleSound(skipIfRecentlyPlayed: false);
         }
         m_componentCreature.ComponentCreatureModel.LookRandomOrder = true;
     }, null);
     m_stateMachine.TransitionTo("Inactive");
 }
 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");
 }
示例#6
0
 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 FollowTarget(bool noDelay)
 {
     if (SummonTarget != null && (noDelay || m_random.Float(0f, 1f) < 5f * m_subsystemTime.GameTimeDelta))
     {
         float num = Vector3.Distance(m_componentCreature.ComponentBody.Position, SummonTarget.Position);
         if (num > 4f)
         {
             Vector3 v = Vector3.Normalize(Vector3.Cross(Vector3.UnitY, SummonTarget.Position - m_componentCreature.ComponentBody.Position));
             v *= 0.75f * (float)((GetHashCode() % 2 != 0) ? 1 : (-1)) * (float)(1 + GetHashCode() % 3);
             float speed = MathUtils.Lerp(0.4f, 1f, MathUtils.Saturate(0.25f * (num - 5f)));
             m_componentPathfinding.SetDestination(SummonTarget.Position + v, speed, 3.75f, 2000, useRandomMovements: true, ignoreHeightDifference: false, raycastDestination: true, null);
             m_stoppedTime = -1.0;
         }
     }
 }
 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
 {
     m_subsystemTerrain     = base.Project.FindSubsystem <SubsystemTerrain>(throwOnError: true);
     m_componentCreature    = base.Entity.FindComponent <ComponentCreature>(throwOnError: true);
     m_componentPathfinding = base.Entity.FindComponent <ComponentPathfinding>(throwOnError: true);
     m_stateMachine.AddState("Inactive", null, delegate
     {
         if (IsActive)
         {
             m_stateMachine.TransitionTo("Fly");
         }
     }, null);
     m_stateMachine.AddState("Stuck", delegate
     {
         m_stateMachine.TransitionTo("Fly");
         if (m_random.Float(0f, 1f) < 0.5f)
         {
             m_componentCreature.ComponentCreatureSounds.PlayIdleSound(skipIfRecentlyPlayed: false);
             m_importanceLevel = 1f;
         }
     }, null, null);
     m_stateMachine.AddState("Fly", delegate
     {
         m_angle = m_random.Float(0f, (float)Math.PI * 2f);
         m_componentPathfinding.Stop();
     }, delegate
     {
         Vector3 position = m_componentCreature.ComponentBody.Position;
         if (!m_componentPathfinding.Destination.HasValue)
         {
             float num      = (m_random.Float(0f, 1f) < 0.2f) ? m_random.Float(0.4f, 0.6f) : (0f - m_random.Float(0.4f, 0.6f));
             m_angle        = MathUtils.NormalizeAngle(m_angle + num);
             Vector2 vector = Vector2.CreateFromAngle(m_angle);
             Vector3 value  = position + new Vector3(vector.X, 0f, vector.Y) * 10f;
             value.Y        = EstimateHeight(new Vector2(value.X, value.Z), 8) + m_random.Float(3f, 5f);
             m_componentPathfinding.SetDestination(value, m_random.Float(0.6f, 1.05f), 6f, 0, useRandomMovements: false, ignoreHeightDifference: true, raycastDestination: false, null);
             if (m_random.Float(0f, 1f) < 0.15f)
             {
                 m_componentCreature.ComponentCreatureSounds.PlayIdleSound(skipIfRecentlyPlayed: false);
             }
         }
         else if (m_componentPathfinding.IsStuck)
         {
             m_stateMachine.TransitionTo("Stuck");
         }
     }, null);
 }
示例#9
0
 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
 {
     m_subsystemTime        = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true);
     m_subsystemBodies      = base.Project.FindSubsystem <SubsystemBodies>(throwOnError: true);
     m_componentCreature    = base.Entity.FindComponent <ComponentCreature>(throwOnError: true);
     m_componentPathfinding = base.Entity.FindComponent <ComponentPathfinding>(throwOnError: true);
     m_componentMount       = base.Entity.FindComponent <ComponentMount>(throwOnError: true);
     m_isEnabled            = base.Entity.ValuesDictionary.DatabaseObject.Name.EndsWith("_Saddled");
     m_stateMachine.AddState("Inactive", null, delegate
     {
         if (IsActive)
         {
             m_stateMachine.TransitionTo("Wait");
         }
     }, null);
     m_stateMachine.AddState("Wait", delegate
     {
         ComponentRider componentRider = FindNearbyRider(6f);
         if (componentRider != null)
         {
             m_componentPathfinding.SetDestination(componentRider.ComponentCreature.ComponentBody.Position, m_random.Float(0.2f, 0.3f), 3.25f, 0, useRandomMovements: false, ignoreHeightDifference: true, raycastDestination: false, null);
             if (m_random.Float(0f, 1f) < 0.5f)
             {
                 m_componentCreature.ComponentCreatureSounds.PlayIdleSound(skipIfRecentlyPlayed: true);
             }
         }
     }, delegate
     {
         if (m_componentMount.Rider != null)
         {
             m_stateMachine.TransitionTo("Steed");
         }
         m_componentCreature.ComponentCreatureModel.LookRandomOrder = true;
     }, null);
     m_stateMachine.AddState("Steed", delegate
     {
         m_componentPathfinding.Stop();
         m_speed      = 0f;
         m_speedLevel = 1;
     }, delegate
     {
         ProcessRidingOrders();
     }, null);
     m_stateMachine.TransitionTo("Inactive");
 }
 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
 {
     m_subsystemTerrain     = base.Project.FindSubsystem <SubsystemTerrain>(throwOnError: true);
     m_componentCreature    = base.Entity.FindComponent <ComponentCreature>(throwOnError: true);
     m_componentPathfinding = base.Entity.FindComponent <ComponentPathfinding>(throwOnError: true);
     m_stateMachine.AddState("Inactive", null, delegate
     {
         if (IsActive)
         {
             m_stateMachine.TransitionTo("Swim");
         }
     }, null);
     m_stateMachine.AddState("Stuck", delegate
     {
         if (m_random.Float(0f, 1f) < 0.5f)
         {
             m_importanceLevel = 1f;
         }
         m_stateMachine.TransitionTo("Swim");
     }, null, null);
     m_stateMachine.AddState("Swim", delegate
     {
         m_componentPathfinding.Stop();
     }, delegate
     {
         _ = m_componentCreature.ComponentBody.Position;
         if (!m_componentPathfinding.Destination.HasValue)
         {
             Vector3?destination = FindDestination();
             if (destination.HasValue)
             {
                 m_componentPathfinding.SetDestination(destination, m_random.Float(0.3f, 0.4f), 1f, 0, useRandomMovements: false, ignoreHeightDifference: true, raycastDestination: false, null);
             }
             else
             {
                 m_importanceLevel = 1f;
             }
         }
         else if (m_componentPathfinding.IsStuck)
         {
             m_stateMachine.TransitionTo("Stuck");
         }
     }, null);
 }
 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
 {
     m_subsystemGameInfo            = base.Project.FindSubsystem <SubsystemGameInfo>(throwOnError: true);
     m_subsystemPlayers             = base.Project.FindSubsystem <SubsystemPlayers>(throwOnError: true);
     m_subsystemSky                 = base.Project.FindSubsystem <SubsystemSky>(throwOnError: true);
     m_subsystemBodies              = base.Project.FindSubsystem <SubsystemBodies>(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_componentMiner               = base.Entity.FindComponent <ComponentMiner>(throwOnError: true);
     m_componentFeedBehavior        = base.Entity.FindComponent <ComponentRandomFeedBehavior>();
     m_componentCreatureModel       = base.Entity.FindComponent <ComponentCreatureModel>(throwOnError: true);
     m_dayChaseRange                = valuesDictionary.GetValue <float>("DayChaseRange");
     m_nightChaseRange              = valuesDictionary.GetValue <float>("NightChaseRange");
     m_dayChaseTime                 = valuesDictionary.GetValue <float>("DayChaseTime");
     m_nightChaseTime               = valuesDictionary.GetValue <float>("NightChaseTime");
     m_autoChaseMask                = valuesDictionary.GetValue <CreatureCategory>("AutoChaseMask");
     m_chaseNonPlayerProbability    = valuesDictionary.GetValue <float>("ChaseNonPlayerProbability");
     m_chaseWhenAttackedProbability = valuesDictionary.GetValue <float>("ChaseWhenAttackedProbability");
     m_chaseOnTouchProbability      = valuesDictionary.GetValue <float>("ChaseOnTouchProbability");
     m_componentCreature.ComponentHealth.Attacked += delegate(ComponentCreature attacker)
     {
         if (m_random.Float(0f, 1f) < m_chaseWhenAttackedProbability)
         {
             if (m_chaseWhenAttackedProbability >= 1f)
             {
                 Attack(attacker, 30f, 60f, isPersistent: true);
             }
             else
             {
                 Attack(attacker, 7f, 7f, isPersistent: false);
             }
         }
     };
     m_componentCreature.ComponentBody.CollidedWithBody += delegate(ComponentBody body)
     {
         if (m_target == null && m_autoChaseSuppressionTime <= 0f && m_random.Float(0f, 1f) < m_chaseOnTouchProbability)
         {
             ComponentCreature componentCreature2 = body.Entity.FindComponent <ComponentCreature>();
             if (componentCreature2 != null)
             {
                 bool flag2 = m_subsystemPlayers.IsPlayer(body.Entity);
                 bool flag3 = (componentCreature2.Category & m_autoChaseMask) != 0;
                 if ((flag2 && m_subsystemGameInfo.WorldSettings.GameMode > GameMode.Harmless) || (!flag2 && flag3))
                 {
                     Attack(componentCreature2, 7f, 7f, isPersistent: false);
                 }
             }
         }
         if (m_target != null && body == m_target.ComponentBody && body.StandingOnBody == m_componentCreature.ComponentBody)
         {
             m_componentCreature.ComponentLocomotion.JumpOrder = 1f;
         }
     };
     m_stateMachine.AddState("LookingForTarget", delegate
     {
         m_importanceLevel = 0f;
         m_target          = null;
     }, delegate
     {
         if (IsActive)
         {
             m_stateMachine.TransitionTo("Chasing");
         }
         else if (m_autoChaseSuppressionTime <= 0f && (m_target == null || ScoreTarget(m_target) <= 0f) && m_componentCreature.ComponentHealth.Health > 0.4f)
         {
             m_range = ((m_subsystemSky.SkyLightIntensity < 0.2f) ? m_nightChaseRange : m_dayChaseRange);
             ComponentCreature componentCreature = FindTarget();
             if (componentCreature != null)
             {
                 m_targetInRangeTime += m_dt;
             }
             else
             {
                 m_targetInRangeTime = 0f;
             }
             if (m_targetInRangeTime > 3f)
             {
                 bool flag          = m_subsystemSky.SkyLightIntensity >= 0.1f;
                 float maxRange     = flag ? (m_dayChaseRange + 6f) : (m_nightChaseRange + 6f);
                 float maxChaseTime = flag ? (m_dayChaseTime * m_random.Float(0.75f, 1f)) : (m_nightChaseTime * m_random.Float(0.75f, 1f));
                 Attack(componentCreature, maxRange, maxChaseTime, (!flag) ? true : false);
             }
         }
     }, null);
     m_stateMachine.AddState("RandomMoving", delegate
     {
         m_componentPathfinding.SetDestination(m_componentCreature.ComponentBody.Position + new Vector3(6f * m_random.Float(-1f, 1f), 0f, 6f * m_random.Float(-1f, 1f)), 1f, 1f, 0, useRandomMovements: false, ignoreHeightDifference: true, raycastDestination: false, null);
     }, delegate
     {
         if (m_componentPathfinding.IsStuck || !m_componentPathfinding.Destination.HasValue)
         {
             m_stateMachine.TransitionTo("Chasing");
         }
         if (!IsActive)
         {
             m_stateMachine.TransitionTo("LookingForTarget");
         }
     }, delegate
     {
         m_componentPathfinding.Stop();
     });
     m_stateMachine.AddState("Chasing", delegate
     {
         m_subsystemNoise.MakeNoise(m_componentCreature.ComponentBody, 0.25f, 6f);
         m_componentCreature.ComponentCreatureSounds.PlayIdleSound(skipIfRecentlyPlayed: false);
         m_nextUpdateTime = 0.0;
     }, delegate
     {
         if (!IsActive)
         {
             m_stateMachine.TransitionTo("LookingForTarget");
         }
         else if (m_chaseTime <= 0f)
         {
             m_autoChaseSuppressionTime = m_random.Float(10f, 60f);
             m_importanceLevel          = 0f;
         }
         else if (m_target == null)
         {
             m_importanceLevel = 0f;
         }
         else if (m_target.ComponentHealth.Health <= 0f)
         {
             if (m_componentFeedBehavior != null)
             {
                 m_subsystemTime.QueueGameTimeDelayedExecution(m_subsystemTime.GameTime + (double)m_random.Float(1f, 3f), delegate
                 {
                     if (m_target != null)
                     {
                         m_componentFeedBehavior.Feed(m_target.ComponentBody.Position);
                     }
                 });
             }
             m_importanceLevel = 0f;
         }
         else if (!m_isPersistent && m_componentPathfinding.IsStuck)
         {
             m_importanceLevel = 0f;
         }
         else if (m_isPersistent && m_componentPathfinding.IsStuck)
         {
             m_stateMachine.TransitionTo("RandomMoving");
         }
         else
         {
             if (ScoreTarget(m_target) <= 0f)
             {
                 m_targetUnsuitableTime += m_dt;
             }
             else
             {
                 m_targetUnsuitableTime = 0f;
             }
             if (m_targetUnsuitableTime > 3f)
             {
                 m_importanceLevel = 0f;
             }
             else
             {
                 int maxPathfindingPositions = 0;
                 if (m_isPersistent)
                 {
                     maxPathfindingPositions = (m_subsystemTime.FixedTimeStep.HasValue ? 1500 : 500);
                 }
                 BoundingBox boundingBox  = m_componentCreature.ComponentBody.BoundingBox;
                 BoundingBox boundingBox2 = m_target.ComponentBody.BoundingBox;
                 Vector3 v      = 0.5f * (boundingBox.Min + boundingBox.Max);
                 Vector3 vector = 0.5f * (boundingBox2.Min + boundingBox2.Max);
                 float num      = Vector3.Distance(v, vector);
                 float num2     = (num < 4f) ? 0.2f : 0f;
                 m_componentPathfinding.SetDestination(vector + num2 * num * m_target.ComponentBody.Velocity, 1f, 1.5f, maxPathfindingPositions, useRandomMovements: true, ignoreHeightDifference: false, raycastDestination: true, m_target.ComponentBody);
                 if (m_random.Float(0f, 1f) < 0.33f * m_dt)
                 {
                     m_componentCreature.ComponentCreatureSounds.PlayAttackSound();
                 }
             }
         }
     }, null);
     m_stateMachine.TransitionTo("LookingForTarget");
 }
示例#12
0
 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
 {
     m_componentCreature    = base.Entity.FindComponent <ComponentCreature>(throwOnError: true);
     m_componentPathfinding = base.Entity.FindComponent <ComponentPathfinding>(throwOnError: true);
     m_componentCreature.ComponentBody.CollidedWithBody += delegate(ComponentBody body)
     {
         m_target = body;
         m_isFast = (MathUtils.Max(body.Velocity.Length(), m_componentCreature.ComponentBody.Velocity.Length()) > 3f);
     };
     m_stateMachine.AddState("Inactive", delegate
     {
         m_importanceLevel = 0f;
         m_target          = null;
     }, delegate
     {
         if (IsActive)
         {
             m_stateMachine.TransitionTo("Move");
         }
         if (m_target != null)
         {
             m_importanceLevel = 6f;
         }
     }, null);
     m_stateMachine.AddState("Move", delegate
     {
         if (m_random.Float(0f, 1f) < 0.5f)
         {
             m_componentCreature.ComponentCreatureSounds.PlayIdleSound(skipIfRecentlyPlayed: true);
         }
         if (m_target != null)
         {
             Vector3 vector  = m_target.Position + 0.5f * m_target.Velocity;
             Vector2 v       = Vector2.Normalize(m_componentCreature.ComponentBody.Position.XZ - vector.XZ);
             Vector2 vector2 = Vector2.Zero;
             float num       = float.MinValue;
             for (float num2 = 0f; num2 < (float)Math.PI * 2f; num2 += 0.1f)
             {
                 Vector2 vector3 = Vector2.CreateFromAngle(num2);
                 if (Vector2.Dot(vector3, v) > 0.2f)
                 {
                     float num3 = Vector2.Dot(m_componentCreature.ComponentBody.Matrix.Forward.XZ, vector3);
                     if (num3 > num)
                     {
                         vector2 = vector3;
                         num     = num3;
                     }
                 }
             }
             float s     = m_random.Float(1.5f, 2f);
             float speed = m_isFast ? 0.7f : 0.35f;
             m_componentPathfinding.SetDestination(m_componentCreature.ComponentBody.Position + s * new Vector3(vector2.X, 0f, vector2.Y), speed, 1f, 0, useRandomMovements: false, ignoreHeightDifference: true, raycastDestination: false, null);
         }
     }, delegate
     {
         if (!IsActive)
         {
             m_stateMachine.TransitionTo("Inactive");
         }
         else if (m_componentPathfinding.IsStuck || !m_componentPathfinding.Destination.HasValue)
         {
             m_importanceLevel = 0f;
         }
         m_componentCreature.ComponentCreatureModel.LookRandomOrder = true;
     }, null);
     m_stateMachine.TransitionTo("Inactive");
 }
示例#13
0
 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_autoFeed             = valuesDictionary.GetValue <bool>("AutoFeed");
     m_stateMachine.AddState("Inactive", delegate
     {
         m_importanceLevel = m_random.Float(0f, 1f);
     }, delegate
     {
         if (m_random.Float(0f, 1f) < 0.05f * m_subsystemTime.GameTimeDelta)
         {
             m_importanceLevel = m_random.Float(1f, 3f);
         }
         if (IsActive)
         {
             m_stateMachine.TransitionTo("Move");
         }
     }, null);
     m_stateMachine.AddState("Move", delegate
     {
         Vector3 value;
         if (m_feedPosition.HasValue)
         {
             value = m_feedPosition.Value;
         }
         else
         {
             Vector3 position = m_componentCreature.ComponentBody.Position;
             Vector3 forward  = m_componentCreature.ComponentBody.Matrix.Forward;
             float num4       = (m_random.Float(0f, 1f) < 0.2f) ? 5f : 1.5f;
             value            = position + num4 * forward + 0.5f * num4 * new Vector3(m_random.Float(-1f, 1f), 0f, m_random.Float(-1f, 1f));
         }
         value.Y = m_subsystemTerrain.Terrain.GetTopHeight(Terrain.ToCell(value.X), Terrain.ToCell(value.Z)) + 1;
         m_componentPathfinding.SetDestination(value, m_random.Float(0.25f, 0.35f), 1f, 0, useRandomMovements: false, ignoreHeightDifference: true, raycastDestination: false, null);
     }, delegate
     {
         if (!m_componentPathfinding.Destination.HasValue)
         {
             float num3 = m_random.Float(0f, 1f);
             if (num3 < 0.33f)
             {
                 m_stateMachine.TransitionTo("Inactive");
             }
             else if (num3 < 0.66f)
             {
                 m_stateMachine.TransitionTo("LookAround");
             }
             else
             {
                 m_stateMachine.TransitionTo("Feed");
             }
         }
         else if (!IsActive || m_componentPathfinding.IsStuck)
         {
             m_stateMachine.TransitionTo("Inactive");
         }
     }, delegate
     {
         m_feedPosition = null;
     });
     m_stateMachine.AddState("LookAround", delegate
     {
         m_waitTime = m_random.Float(1f, 2f);
     }, delegate
     {
         m_componentCreature.ComponentCreatureModel.LookRandomOrder = true;
         m_waitTime -= m_subsystemTime.GameTimeDelta;
         if (m_waitTime <= 0f)
         {
             float num2 = m_random.Float(0f, 1f);
             if (num2 < 0.25f)
             {
                 m_stateMachine.TransitionTo("Inactive");
             }
             if (num2 < 0.5f)
             {
                 m_stateMachine.TransitionTo(null);
                 m_stateMachine.TransitionTo("LookAround");
             }
             else if (num2 < 0.75f)
             {
                 m_stateMachine.TransitionTo("Move");
                 if (m_random.Float(0f, 1f) < 0.1f * m_subsystemTime.GameTimeDelta)
                 {
                     m_componentCreature.ComponentCreatureSounds.PlayIdleSound(skipIfRecentlyPlayed: false);
                 }
             }
             else
             {
                 m_stateMachine.TransitionTo("Feed");
             }
         }
         if (!IsActive)
         {
             m_stateMachine.TransitionTo("Inactive");
         }
     }, null);
     m_stateMachine.AddState("Feed", delegate
     {
         m_feedTime = m_random.Float(4f, 6f);
     }, delegate
     {
         m_feedTime -= m_subsystemTime.GameTimeDelta;
         if (m_componentCreature.ComponentBody.StandingOnValue.HasValue)
         {
             m_componentCreature.ComponentCreatureModel.FeedOrder = true;
             if (m_random.Float(0f, 1f) < 0.1f * m_subsystemTime.GameTimeDelta)
             {
                 m_componentCreature.ComponentCreatureSounds.PlayIdleSound(skipIfRecentlyPlayed: false);
             }
             if (m_random.Float(0f, 1f) < 1.5f * m_subsystemTime.GameTimeDelta)
             {
                 m_componentCreature.ComponentCreatureSounds.PlayFootstepSound(2f);
             }
         }
         if (m_feedTime <= 0f)
         {
             if (m_autoFeed)
             {
                 float num = m_random.Float(0f, 1f);
                 if (num < 0.33f)
                 {
                     m_stateMachine.TransitionTo("Inactive");
                 }
                 if (num < 0.66f)
                 {
                     m_stateMachine.TransitionTo("Move");
                 }
                 else
                 {
                     m_stateMachine.TransitionTo("LookAround");
                 }
             }
             else
             {
                 m_importanceLevel = 0f;
             }
         }
         if (!IsActive)
         {
             m_stateMachine.TransitionTo("Inactive");
         }
     }, null);
     m_stateMachine.TransitionTo("Inactive");
 }
 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
 {
     m_subsystemTerrain     = base.Project.FindSubsystem <SubsystemTerrain>(throwOnError: true);
     m_componentCreature    = base.Entity.FindComponent <ComponentCreature>(throwOnError: true);
     m_componentBirdModel   = base.Entity.FindComponent <ComponentBirdModel>(throwOnError: true);
     m_componentPathfinding = base.Entity.FindComponent <ComponentPathfinding>(throwOnError: true);
     m_stateMachine.AddState("Inactive", null, delegate
     {
         if (IsActive)
         {
             m_stateMachine.TransitionTo("Move");
         }
     }, null);
     m_stateMachine.AddState("Stuck", delegate
     {
         m_stateMachine.TransitionTo("Move");
     }, null, null);
     m_stateMachine.AddState("Move", delegate
     {
         Vector3 position = m_componentCreature.ComponentBody.Position;
         float num        = (m_random.Float(0f, 1f) < 0.2f) ? 8f : 3f;
         Vector3 value    = position + new Vector3(num * m_random.Float(-1f, 1f), 0f, num * m_random.Float(-1f, 1f));
         value.Y          = m_subsystemTerrain.Terrain.GetTopHeight(Terrain.ToCell(value.X), Terrain.ToCell(value.Z)) + 1;
         m_componentPathfinding.SetDestination(value, m_random.Float(0.5f, 0.7f), 1f, 0, useRandomMovements: false, ignoreHeightDifference: true, raycastDestination: false, null);
     }, delegate
     {
         if (!m_componentPathfinding.Destination.HasValue)
         {
             if (m_random.Float(0f, 1f) < 0.33f)
             {
                 m_stateMachine.TransitionTo("Wait");
             }
             else
             {
                 m_stateMachine.TransitionTo("Peck");
             }
         }
         else if (m_componentPathfinding.IsStuck)
         {
             m_stateMachine.TransitionTo("Stuck");
         }
     }, null);
     m_stateMachine.AddState("Wait", delegate
     {
         m_waitTime = m_random.Float(0.75f, 1f);
     }, delegate
     {
         m_waitTime -= m_dt;
         if (m_waitTime <= 0f)
         {
             if (m_random.Float(0f, 1f) < 0.25f)
             {
                 m_stateMachine.TransitionTo("Move");
                 if (m_random.Float(0f, 1f) < 0.33f)
                 {
                     m_componentCreature.ComponentCreatureSounds.PlayIdleSound(skipIfRecentlyPlayed: false);
                 }
             }
             else
             {
                 m_stateMachine.TransitionTo("Peck");
             }
         }
     }, null);
     m_stateMachine.AddState("Peck", delegate
     {
         m_peckTime = m_random.Float(2f, 6f);
     }, delegate
     {
         m_peckTime -= m_dt;
         if (m_componentCreature.ComponentBody.StandingOnValue.HasValue)
         {
             m_componentBirdModel.FeedOrder = true;
         }
         if (m_peckTime <= 0f)
         {
             if (m_random.Float(0f, 1f) < 0.25f)
             {
                 m_stateMachine.TransitionTo("Move");
             }
             else
             {
                 m_stateMachine.TransitionTo("Wait");
             }
         }
     }, null);
 }
        public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
        {
            m_subsystemTime        = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true);
            m_subsystemTerrain     = base.Project.FindSubsystem <SubsystemTerrain>(throwOnError: true);
            m_subsystemPickables   = base.Project.FindSubsystem <SubsystemPickables>(throwOnError: true);
            m_subsystemAudio       = base.Project.FindSubsystem <SubsystemAudio>(throwOnError: true);
            m_componentCreature    = base.Entity.FindComponent <ComponentCreature>(throwOnError: true);
            m_componentPathfinding = base.Entity.FindComponent <ComponentPathfinding>(throwOnError: true);
            EggBlock eggBlock = (EggBlock)BlocksManager.Blocks[118];

            m_layFrequency = valuesDictionary.GetValue <float>("LayFrequency");
            m_eggType      = eggBlock.GetEggTypeByCreatureTemplateName(base.Entity.ValuesDictionary.DatabaseObject.Name);
            m_stateMachine.AddState("Inactive", null, delegate
            {
                if (IsActive)
                {
                    m_stateMachine.TransitionTo("Move");
                }
            }, null);
            m_stateMachine.AddState("Stuck", delegate
            {
                m_stateMachine.TransitionTo("Move");
            }, null, null);
            m_stateMachine.AddState("Move", delegate
            {
                Vector3 position2 = m_componentCreature.ComponentBody.Position;
                float num         = 5f;
                Vector3 value3    = position2 + new Vector3(num * m_random.Float(-1f, 1f), 0f, num * m_random.Float(-1f, 1f));
                value3.Y          = m_subsystemTerrain.Terrain.GetTopHeight(Terrain.ToCell(value3.X), Terrain.ToCell(value3.Z)) + 1;
                m_componentPathfinding.SetDestination(value3, m_random.Float(0.4f, 0.6f), 0.5f, 0, useRandomMovements: false, ignoreHeightDifference: true, raycastDestination: false, null);
            }, delegate
            {
                if (!m_componentPathfinding.Destination.HasValue)
                {
                    m_stateMachine.TransitionTo("Lay");
                }
                else if (m_componentPathfinding.IsStuck)
                {
                    if (m_random.Float(0f, 1f) < 0.5f)
                    {
                        m_stateMachine.TransitionTo("Stuck");
                    }
                    else
                    {
                        m_importanceLevel = 0f;
                    }
                }
            }, null);
            m_stateMachine.AddState("Lay", delegate
            {
                m_layTime = 0f;
            }, delegate
            {
                if (m_eggType != null)
                {
                    m_layTime += m_dt;
                    if (m_componentCreature.ComponentBody.StandingOnValue.HasValue)
                    {
                        m_componentCreature.ComponentLocomotion.LookOrder = new Vector2(0f, 0.25f * (float)MathUtils.Sin(20.0 * m_subsystemTime.GameTime) + m_layTime / 3f) - m_componentCreature.ComponentLocomotion.LookAngles;
                        if (m_layTime >= 3f)
                        {
                            m_importanceLevel = 0f;
                            int value         = Terrain.MakeBlockValue(118, 0, EggBlock.SetIsLaid(EggBlock.SetEggType(0, m_eggType.EggTypeIndex), isLaid: true));
                            Matrix matrix     = m_componentCreature.ComponentBody.Matrix;
                            Vector3 position  = 0.5f * (m_componentCreature.ComponentBody.BoundingBox.Min + m_componentCreature.ComponentBody.BoundingBox.Max);
                            Vector3 value2    = 3f * Vector3.Normalize(-matrix.Forward + 0.1f * matrix.Up + 0.2f * m_random.Float(-1f, 1f) * matrix.Right);
                            m_subsystemPickables.AddPickable(value, 1, position, value2, null);
                            m_subsystemAudio.PlaySound("Audio/EggLaid", 1f, m_random.Float(-0.1f, 0.1f), position, 2f, autoDelay: true);
                        }
                    }
                    else if (m_layTime >= 3f)
                    {
                        m_importanceLevel = 0f;
                    }
                }
                else
                {
                    m_importanceLevel = 0f;
                }
            }, null);
        }
示例#16
0
 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
 {
     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_componentMount       = base.Entity.FindComponent <ComponentMount>(throwOnError: true);
     m_isEnabled            = !base.Entity.ValuesDictionary.DatabaseObject.Name.EndsWith("_Saddled");
     m_stateMachine.AddState("Inactive", delegate
     {
         m_importanceLevel = 0f;
         m_rider           = null;
     }, delegate
     {
         if (m_isEnabled && m_random.Float(0f, 1f) < 1f * m_subsystemTime.GameTimeDelta && m_componentMount.Rider != null)
         {
             m_importanceLevel = 220f;
             m_dumpStartTime   = m_subsystemTime.GameTime;
             m_rider           = m_componentMount.Rider;
         }
         if (IsActive)
         {
             m_stateMachine.TransitionTo("WildJumping");
         }
     }, null);
     m_stateMachine.AddState("WildJumping", delegate
     {
         m_componentCreature.ComponentCreatureSounds.PlayPainSound();
         m_componentPathfinding.Stop();
     }, delegate
     {
         if (!IsActive)
         {
             m_stateMachine.TransitionTo("Inactive");
         }
         else if (m_componentMount.Rider == null)
         {
             m_importanceLevel = 0f;
             RunAway();
         }
         if (m_random.Float(0f, 1f) < 1f * m_subsystemTime.GameTimeDelta)
         {
             m_componentCreature.ComponentCreatureSounds.PlayPainSound();
         }
         if (m_random.Float(0f, 1f) < 3f * m_subsystemTime.GameTimeDelta)
         {
             m_walkOrder = new Vector2(m_random.Float(-0.5f, 0.5f), m_random.Float(-0.5f, 1.5f));
         }
         if (m_random.Float(0f, 1f) < 2.5f * m_subsystemTime.GameTimeDelta)
         {
             m_turnOrder.X = m_random.Float(-1f, 1f);
         }
         if (m_random.Float(0f, 1f) < 2f * m_subsystemTime.GameTimeDelta)
         {
             m_componentCreature.ComponentLocomotion.JumpOrder = m_random.Float(0.9f, 1f);
             if (m_componentMount.Rider != null && m_subsystemTime.GameTime - m_dumpStartTime > 3.0)
             {
                 if (m_random.Float(0f, 1f) < 0.05f)
                 {
                     m_componentMount.Rider.StartDismounting();
                     m_componentMount.Rider.ComponentCreature.ComponentHealth.Injure(m_random.Float(0.05f, 0.2f), m_componentCreature, ignoreInvulnerability: false, "Thrown from a mount");
                 }
                 if (m_random.Float(0f, 1f) < 0.25f)
                 {
                     m_componentMount.Rider.ComponentCreature.ComponentHealth.Injure(0.05f, m_componentCreature, ignoreInvulnerability: false, "Thrown from a mount");
                 }
             }
         }
         if (m_random.Float(0f, 1f) < 4f * m_subsystemTime.GameTimeDelta)
         {
             m_lookOrder = new Vector2(m_random.Float(-3f, 3f), m_lookOrder.Y);
         }
         if (m_random.Float(0f, 1f) < 0.25f * m_subsystemTime.GameTimeDelta)
         {
             TransitionToRandomDumpingBehavior();
         }
         m_componentCreature.ComponentLocomotion.WalkOrder = m_walkOrder;
         m_componentCreature.ComponentLocomotion.TurnOrder = m_turnOrder;
         m_componentCreature.ComponentLocomotion.LookOrder = m_lookOrder;
     }, null);
     m_stateMachine.AddState("BlindRacing", delegate
     {
         m_componentCreature.ComponentCreatureSounds.PlayPainSound();
         m_componentPathfinding.SetDestination(m_componentCreature.ComponentBody.Position + new Vector3(m_random.Float(-15f, 15f), 0f, m_random.Float(-15f, 15f)), 1f, 2f, 0, useRandomMovements: false, ignoreHeightDifference: true, raycastDestination: false, null);
     }, delegate
     {
         if (!IsActive)
         {
             m_stateMachine.TransitionTo("Inactive");
         }
         else if (m_componentMount.Rider == null)
         {
             m_importanceLevel = 0f;
             RunAway();
         }
         else if (!m_componentPathfinding.Destination.HasValue || m_componentPathfinding.IsStuck)
         {
             TransitionToRandomDumpingBehavior();
         }
         if (m_random.Float(0f, 1f) < 0.5f * m_subsystemTime.GameTimeDelta)
         {
             m_componentCreature.ComponentLocomotion.JumpOrder = 1f;
             m_componentCreature.ComponentCreatureSounds.PlayPainSound();
         }
     }, null);
     m_stateMachine.AddState("Stupor", delegate
     {
         m_componentCreature.ComponentCreatureSounds.PlayPainSound();
         m_componentPathfinding.Stop();
     }, delegate
     {
         if (!IsActive)
         {
             m_stateMachine.TransitionTo("Inactive");
         }
         else if (m_componentMount.Rider == null)
         {
             m_importanceLevel = 0f;
         }
         if (m_subsystemTime.PeriodicGameTimeEvent(2.0, 0.0))
         {
             TransitionToRandomDumpingBehavior();
         }
     }, 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);
     HerdName                  = valuesDictionary.GetValue <string>("HerdName");
     m_herdingRange            = valuesDictionary.GetValue <float>("HerdingRange");
     m_autoNearbyCreaturesHelp = valuesDictionary.GetValue <bool>("AutoNearbyCreaturesHelp");
     m_componentCreature.ComponentHealth.Attacked += delegate(ComponentCreature attacker)
     {
         CallNearbyCreaturesHelp(attacker, 20f, 30f, isPersistent: false);
     };
     m_stateMachine.AddState("Inactive", null, delegate
     {
         if (m_subsystemTime.PeriodicGameTimeEvent(1.0, 1f * ((float)(GetHashCode() % 256) / 256f)))
         {
             Vector3?vector2 = FindHerdCenter();
             if (vector2.HasValue)
             {
                 float num = Vector3.Distance(vector2.Value, m_componentCreature.ComponentBody.Position);
                 if (num > 10f)
                 {
                     m_importanceLevel = 1f;
                 }
                 if (num > 12f)
                 {
                     m_importanceLevel = 3f;
                 }
                 if (num > 16f)
                 {
                     m_importanceLevel = 50f;
                 }
                 if (num > 20f)
                 {
                     m_importanceLevel = 250f;
                 }
             }
         }
         if (IsActive)
         {
             m_stateMachine.TransitionTo("Herd");
         }
     }, null);
     m_stateMachine.AddState("Stuck", delegate
     {
         m_stateMachine.TransitionTo("Herd");
         if (m_random.Bool(0.5f))
         {
             m_componentCreature.ComponentCreatureSounds.PlayIdleSound(skipIfRecentlyPlayed: false);
             m_importanceLevel = 0f;
         }
     }, null, null);
     m_stateMachine.AddState("Herd", delegate
     {
         Vector3?vector = FindHerdCenter();
         if (vector.HasValue && Vector3.Distance(m_componentCreature.ComponentBody.Position, vector.Value) > 6f)
         {
             float speed = (m_importanceLevel > 10f) ? m_random.Float(0.9f, 1f) : m_random.Float(0.25f, 0.35f);
             int maxPathfindingPositions = (m_importanceLevel > 200f) ? 100 : 0;
             m_componentPathfinding.SetDestination(vector.Value, speed, 7f, maxPathfindingPositions, useRandomMovements: false, ignoreHeightDifference: true, raycastDestination: false, null);
         }
         else
         {
             m_importanceLevel = 0f;
         }
     }, delegate
     {
         m_componentCreature.ComponentLocomotion.LookOrder = m_look - m_componentCreature.ComponentLocomotion.LookAngles;
         if (m_componentPathfinding.IsStuck)
         {
             m_stateMachine.TransitionTo("Stuck");
         }
         if (!m_componentPathfinding.Destination.HasValue)
         {
             m_importanceLevel = 0f;
         }
         if (m_random.Float(0f, 1f) < 0.05f * m_dt)
         {
             m_componentCreature.ComponentCreatureSounds.PlayIdleSound(skipIfRecentlyPlayed: false);
         }
         if (m_random.Float(0f, 1f) < 1.5f * m_dt)
         {
             m_look = new Vector2(MathUtils.DegToRad(45f) * m_random.Float(-1f, 1f), MathUtils.DegToRad(10f) * m_random.Float(-1f, 1f));
         }
     }, null);
 }
示例#18
0
 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");
 }
示例#19
0
 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
 {
     m_subsystemTime        = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true);
     m_subsystemPickables   = base.Project.FindSubsystem <SubsystemPickables>(throwOnError: true);
     m_componentCreature    = base.Entity.FindComponent <ComponentCreature>(throwOnError: true);
     m_componentPathfinding = base.Entity.FindComponent <ComponentPathfinding>(throwOnError: true);
     m_foodFactors          = new float[EnumUtils.GetEnumValues(typeof(FoodType)).Max() + 1];
     foreach (KeyValuePair <string, object> item in valuesDictionary.GetValue <ValuesDictionary>("FoodFactors"))
     {
         FoodType foodType = (FoodType)Enum.Parse(typeof(FoodType), item.Key, ignoreCase: false);
         m_foodFactors[(int)foodType] = (float)item.Value;
     }
     m_subsystemPickables.PickableAdded += delegate(Pickable pickable)
     {
         if (TryAddPickable(pickable) && m_pickable == null)
         {
             m_pickable = pickable;
         }
     };
     m_subsystemPickables.PickableRemoved += delegate(Pickable pickable)
     {
         m_pickables.Remove(pickable);
         if (m_pickable == pickable)
         {
             m_pickable = null;
         }
     };
     m_stateMachine.AddState("Inactive", delegate
     {
         m_importanceLevel = 0f;
         m_pickable        = null;
     }, delegate
     {
         if (m_satiation < 1f)
         {
             if (m_pickable == null)
             {
                 if (m_subsystemTime.GameTime > m_nextFindPickableTime)
                 {
                     m_nextFindPickableTime = m_subsystemTime.GameTime + (double)m_random.Float(2f, 4f);
                     m_pickable             = FindPickable(m_componentCreature.ComponentBody.Position);
                 }
             }
             else
             {
                 m_importanceLevel = m_random.Float(5f, 10f);
             }
         }
         if (IsActive)
         {
             m_stateMachine.TransitionTo("Move");
             m_blockedCount = 0;
         }
     }, null);
     m_stateMachine.AddState("Move", delegate
     {
         if (m_pickable != null)
         {
             float speed = (m_satiation == 0f) ? m_random.Float(0.5f, 0.7f) : 0.5f;
             int maxPathfindingPositions = (m_satiation == 0f) ? 1000 : 500;
             float num2 = Vector3.Distance(m_componentCreature.ComponentCreatureModel.EyePosition, m_componentCreature.ComponentBody.Position);
             m_componentPathfinding.SetDestination(m_pickable.Position, speed, 1f + num2, maxPathfindingPositions, useRandomMovements: true, ignoreHeightDifference: false, raycastDestination: true, null);
             if (m_random.Float(0f, 1f) < 0.66f)
             {
                 m_componentCreature.ComponentCreatureSounds.PlayIdleSound(skipIfRecentlyPlayed: true);
             }
         }
     }, delegate
     {
         if (!IsActive)
         {
             m_stateMachine.TransitionTo("Inactive");
         }
         else if (m_pickable == null)
         {
             m_importanceLevel = 0f;
         }
         else if (m_componentPathfinding.IsStuck)
         {
             m_importanceLevel = 0f;
             m_satiation      += 0.75f;
         }
         else if (!m_componentPathfinding.Destination.HasValue)
         {
             m_stateMachine.TransitionTo("Eat");
         }
         else if (Vector3.DistanceSquared(m_componentPathfinding.Destination.Value, m_pickable.Position) > 0.0625f)
         {
             m_stateMachine.TransitionTo("PickableMoved");
         }
         if (m_random.Float(0f, 1f) < 0.1f * m_subsystemTime.GameTimeDelta)
         {
             m_componentCreature.ComponentCreatureSounds.PlayIdleSound(skipIfRecentlyPlayed: true);
         }
         if (m_pickable != null)
         {
             m_componentCreature.ComponentCreatureModel.LookAtOrder = m_pickable.Position;
         }
         else
         {
             m_componentCreature.ComponentCreatureModel.LookRandomOrder = true;
         }
     }, null);
     m_stateMachine.AddState("PickableMoved", null, delegate
     {
         if (m_pickable != null)
         {
             m_componentCreature.ComponentCreatureModel.LookAtOrder = m_pickable.Position;
         }
         if (m_subsystemTime.PeriodicGameTimeEvent(0.25, (double)(GetHashCode() % 100) * 0.01))
         {
             m_stateMachine.TransitionTo("Move");
         }
     }, null);
     m_stateMachine.AddState("Eat", delegate
     {
         m_eatTime     = m_random.Float(4f, 5f);
         m_blockedTime = 0f;
     }, delegate
     {
         if (!IsActive)
         {
             m_stateMachine.TransitionTo("Inactive");
         }
         if (m_pickable == null)
         {
             m_importanceLevel = 0f;
         }
         if (m_pickable != null)
         {
             if (Vector3.DistanceSquared(new Vector3(m_componentCreature.ComponentCreatureModel.EyePosition.X, m_componentCreature.ComponentBody.Position.Y, m_componentCreature.ComponentCreatureModel.EyePosition.Z), m_pickable.Position) < 0.640000045f)
             {
                 m_eatTime    -= m_subsystemTime.GameTimeDelta;
                 m_blockedTime = 0f;
                 if (m_eatTime <= 0.0)
                 {
                     m_satiation     += 1f;
                     m_pickable.Count = MathUtils.Max(m_pickable.Count - 1, 0);
                     if (m_pickable.Count == 0)
                     {
                         m_pickable.ToRemove = true;
                         m_importanceLevel   = 0f;
                     }
                     else if (m_random.Float(0f, 1f) < 0.5f)
                     {
                         m_importanceLevel = 0f;
                     }
                 }
             }
             else
             {
                 float num = Vector3.Distance(m_componentCreature.ComponentCreatureModel.EyePosition, m_componentCreature.ComponentBody.Position);
                 m_componentPathfinding.SetDestination(m_pickable.Position, 0.3f, 0.5f + num, 0, useRandomMovements: false, ignoreHeightDifference: true, raycastDestination: false, null);
                 m_blockedTime += m_subsystemTime.GameTimeDelta;
             }
             if (m_blockedTime > 3f)
             {
                 m_blockedCount++;
                 if (m_blockedCount >= 3)
                 {
                     m_importanceLevel = 0f;
                     m_satiation      += 0.75f;
                 }
                 else
                 {
                     m_stateMachine.TransitionTo("Move");
                 }
             }
         }
         m_componentCreature.ComponentCreatureModel.FeedOrder = true;
         if (m_random.Float(0f, 1f) < 0.1f * m_subsystemTime.GameTimeDelta)
         {
             m_componentCreature.ComponentCreatureSounds.PlayIdleSound(skipIfRecentlyPlayed: true);
         }
         if (m_random.Float(0f, 1f) < 1.5f * m_subsystemTime.GameTimeDelta)
         {
             m_componentCreature.ComponentCreatureSounds.PlayFootstepSound(2f);
         }
     }, null);
     m_stateMachine.TransitionTo("Inactive");
 }
 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
 {
     m_subsystemGameInfo    = base.Project.FindSubsystem <SubsystemGameInfo>(throwOnError: true);
     m_subsystemTime        = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true);
     m_subsystemSky         = base.Project.FindSubsystem <SubsystemSky>(throwOnError: true);
     m_subsystemBodies      = base.Project.FindSubsystem <SubsystemBodies>(throwOnError: true);
     m_componentCreature    = base.Entity.FindComponent <ComponentCreature>(throwOnError: true);
     m_componentPathfinding = base.Entity.FindComponent <ComponentPathfinding>(throwOnError: true);
     m_dayRange             = valuesDictionary.GetValue <float>("DayRange");
     m_nightRange           = valuesDictionary.GetValue <float>("NightRange");
     m_minRange             = valuesDictionary.GetValue <float>("MinRange");
     m_stateMachine.AddState("Inactive", delegate
     {
         m_importanceLevel = 0f;
         m_target          = null;
     }, delegate
     {
         if (IsActive)
         {
             m_stateMachine.TransitionTo("Move");
         }
         if (m_subsystemGameInfo.WorldSettings.GameMode > GameMode.Harmless)
         {
             m_target = FindTarget();
             if (m_target != null)
             {
                 ComponentPlayer componentPlayer = m_target.Entity.FindComponent <ComponentPlayer>();
                 if (componentPlayer != null && componentPlayer.ComponentSleep.IsSleeping)
                 {
                     m_importanceLevel = 5f;
                 }
                 else if (m_random.Float(0f, 1f) < 0.05f * m_dt)
                 {
                     m_importanceLevel = m_random.Float(1f, 4f);
                 }
             }
             else
             {
                 m_importanceLevel = 0f;
             }
         }
     }, null);
     m_stateMachine.AddState("Move", delegate
     {
         if (m_target != null)
         {
             m_componentPathfinding.SetDestination(m_target.ComponentBody.Position, m_random.Float(0.5f, 0.7f), m_minRange, 500, useRandomMovements: true, ignoreHeightDifference: true, raycastDestination: false, null);
         }
     }, delegate
     {
         if (!IsActive)
         {
             m_stateMachine.TransitionTo("Inactive");
         }
         else if (m_target == null || m_componentPathfinding.IsStuck || !m_componentPathfinding.Destination.HasValue || ScoreTarget(m_target) <= 0f)
         {
             m_importanceLevel = 0f;
         }
         if (m_random.Float(0f, 1f) < 0.1f * m_dt)
         {
             m_componentCreature.ComponentCreatureSounds.PlayIdleSound(skipIfRecentlyPlayed: true);
         }
         m_componentCreature.ComponentCreatureModel.LookRandomOrder = true;
     }, null);
     m_stateMachine.TransitionTo("Inactive");
 }