public GameLoadingScreen()
        {
            XElement node = ContentManager.Get <XElement>("Screens/GameLoadingScreen");

            LoadContents(this, node);
            m_stateMachine.AddState("WaitingForFadeIn", null, delegate
            {
                if (!ScreensManager.IsAnimating)
                {
                    if (string.IsNullOrEmpty(m_worldSnapshotName))
                    {
                        m_stateMachine.TransitionTo("Loading");
                    }
                    else
                    {
                        m_stateMachine.TransitionTo("RestoringSnapshot");
                    }
                }
            }, null);
            m_stateMachine.AddState("Loading", null, delegate
            {
                ContainerWidget gamesWidget = ScreensManager.FindScreen <GameScreen>("Game").Children.Find <ContainerWidget>("GamesWidget");
                GameManager.LoadProject(m_worldInfo, gamesWidget);
                ScreensManager.SwitchScreen("Game");
            }, null);
            m_stateMachine.AddState("RestoringSnapshot", null, delegate
            {
                GameManager.DisposeProject();
                WorldsManager.RestoreWorldFromSnapshot(m_worldInfo.DirectoryName, m_worldSnapshotName);
                m_stateMachine.TransitionTo("Loading");
            }, null);
        }
 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;
     });
 }
Beispiel #3
0
 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
 {
     m_subsystemTime                = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true);
     m_subsystemGameInfo            = base.Project.FindSubsystem <SubsystemGameInfo>(throwOnError: true);
     m_componentCreature            = base.Entity.FindComponent <ComponentCreature>(throwOnError: true);
     m_componentMount               = base.Entity.FindComponent <ComponentMount>(throwOnError: true);
     m_componentSteedBehavior       = base.Entity.FindComponent <ComponentSteedBehavior>(throwOnError: true);
     m_componentEatPickableBehavior = base.Entity.FindComponent <ComponentEatPickableBehavior>(throwOnError: true);
     m_stubbornProbability          = valuesDictionary.GetValue <float>("StubbornProbability");
     m_stubbornEndTime              = valuesDictionary.GetValue <double>("StubbornEndTime");
     m_periodicEventOffset          = m_random.Float(0f, 100f);
     m_isSaddled = base.Entity.ValuesDictionary.DatabaseObject.Name.EndsWith("_Saddled");
     m_stateMachine.AddState("Inactive", null, delegate
     {
         if (m_subsystemTime.PeriodicGameTimeEvent(1.0, m_periodicEventOffset) && m_componentMount.Rider != null && m_random.Float(0f, 1f) < m_stubbornProbability && (!m_isSaddled || m_componentEatPickableBehavior.Satiation <= 0f))
         {
             m_stubbornEndTime = m_subsystemGameInfo.TotalElapsedGameTime + (double)m_random.Float(60f, 120f);
         }
         if (IsActive)
         {
             m_stateMachine.TransitionTo("Stubborn");
         }
     }, null);
     m_stateMachine.AddState("Stubborn", null, delegate
     {
         if (m_componentSteedBehavior.WasOrderIssued)
         {
             m_componentCreature.ComponentCreatureModel.HeadShakeOrder = m_random.Float(0.6f, 1f);
             m_componentCreature.ComponentCreatureSounds.PlayPainSound();
         }
     }, null);
     m_stateMachine.TransitionTo("Inactive");
 }
 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");
 }
 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_componentCreature    = base.Entity.FindComponent <ComponentCreature>(throwOnError: true);
     m_componentPathfinding = base.Entity.FindComponent <ComponentPathfinding>(throwOnError: true);
     m_isEnabled            = valuesDictionary.GetValue <bool>("IsEnabled");
     m_stateMachine.AddState("Inactive", delegate
     {
         m_importanceLevel = 0f;
         SummonTarget      = null;
         m_summonedTime    = 0.0;
     }, delegate
     {
         if (m_isEnabled && SummonTarget != null && m_summonedTime == 0.0)
         {
             m_subsystemTime.QueueGameTimeDelayedExecution(m_subsystemTime.GameTime + 0.5, delegate
             {
                 m_componentCreature.ComponentCreatureSounds.PlayIdleSound(skipIfRecentlyPlayed: true);
                 m_importanceLevel = 270f;
                 m_summonedTime    = m_subsystemTime.GameTime;
             });
         }
         if (IsActive)
         {
             m_stateMachine.TransitionTo("FollowTarget");
         }
     }, null);
     m_stateMachine.AddState("FollowTarget", delegate
     {
         FollowTarget(noDelay: true);
     }, delegate
     {
         if (!IsActive)
         {
             m_stateMachine.TransitionTo("Inactive");
         }
         else if (SummonTarget == null || m_componentPathfinding.IsStuck || m_subsystemTime.GameTime - m_summonedTime > 30.0)
         {
             m_importanceLevel = 0f;
         }
         else if (!m_componentPathfinding.Destination.HasValue)
         {
             if (m_stoppedTime < 0.0)
             {
                 m_stoppedTime = m_subsystemTime.GameTime;
             }
             if (m_subsystemTime.GameTime - m_stoppedTime > 6.0)
             {
                 m_importanceLevel = 0f;
             }
         }
         FollowTarget(noDelay: false);
         m_componentCreature.ComponentCreatureModel.LookRandomOrder = true;
     }, null);
     m_stateMachine.TransitionTo("Inactive");
 }
Beispiel #7
0
 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
 {
     m_subsystemSky         = base.Project.FindSubsystem <SubsystemSky>(throwOnError: true);
     m_subsystemTime        = base.Project.FindSubsystem <SubsystemTime>(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);
     m_howlSoundName        = valuesDictionary.GetValue <string>("HowlSoundName");
     m_stateMachine.AddState("Inactive", delegate
     {
         m_importanceLevel = 0f;
     }, delegate
     {
         if (IsActive)
         {
             m_stateMachine.TransitionTo("Howl");
         }
         if (m_subsystemSky.SkyLightIntensity < 0.1f)
         {
             if (m_random.Float(0f, 1f) < 0.015f * m_subsystemTime.GameTimeDelta)
             {
                 m_importanceLevel = m_random.Float(1f, 3f);
             }
         }
         else
         {
             m_importanceLevel = 0f;
         }
     }, null);
     m_stateMachine.AddState("Howl", delegate
     {
         m_howlTime     = 0f;
         m_howlDuration = m_random.Float(5f, 6f);
         m_componentPathfinding.Stop();
         m_importanceLevel = 10f;
     }, delegate
     {
         if (!IsActive)
         {
             m_stateMachine.TransitionTo("Inactive");
         }
         m_componentCreature.ComponentLocomotion.LookOrder = new Vector2(m_componentCreature.ComponentLocomotion.LookOrder.X, 2f);
         float num = m_howlTime + m_subsystemTime.GameTimeDelta;
         if (m_howlTime <= 0.5f && num > 0.5f)
         {
             m_subsystemAudio.PlayRandomSound(m_howlSoundName, 1f, m_random.Float(-0.1f, 0.1f), m_componentCreature.ComponentBody.Position, 10f, autoDelay: true);
         }
         m_howlTime = num;
         if (m_howlTime >= m_howlDuration)
         {
             m_importanceLevel = 0f;
         }
     }, null);
     m_stateMachine.TransitionTo("Inactive");
 }
Beispiel #8
0
        protected override void Start()
        {
            base.Start();

            stateMachine = new StateMachine <TurretState>();
            stateMachine.AddState(TurretState.IDLE, null, IdleOnUpdate);
            stateMachine.AddState(TurretState.ATTACK, null, AttackOnUpdate);
            stateMachine.CurrentState = TurretState.IDLE;

            monsters = new List <Monster>();
        }
 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");
 }
Beispiel #10
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");
 }
Beispiel #11
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_componentFishModel = base.Entity.FindComponent <ComponentFishModel>(throwOnError: true);
     m_stateMachine.AddState("Inactive", null, delegate
     {
         if (IsOutOfWater())
         {
             m_outOfWaterTime += m_subsystemTime.GameTimeDelta;
         }
         else
         {
             m_outOfWaterTime = 0f;
         }
         if (m_outOfWaterTime > 3f)
         {
             m_importanceLevel = 1000f;
         }
         if (IsActive)
         {
             m_stateMachine.TransitionTo("Jump");
         }
     }, null);
     m_stateMachine.AddState("Jump", null, delegate
     {
         m_componentFishModel.BendOrder = 2f * (2f * MathUtils.Saturate(SimplexNoise.OctavedNoise((float)MathUtils.Remainder(m_subsystemTime.GameTime, 1000.0), 1.2f * m_componentCreature.ComponentLocomotion.TurnSpeed, 1, 1f, 1f)) - 1f);
         if (!IsActive)
         {
             m_stateMachine.TransitionTo("Inactive");
         }
         if (!IsOutOfWater())
         {
             m_importanceLevel = 0f;
         }
         if (m_random.Float(0f, 1f) < 2.5f * m_subsystemTime.GameTimeDelta)
         {
             m_componentCreature.ComponentLocomotion.JumpOrder = m_random.Float(0.33f, 1f);
             m_direction = new Vector2(MathUtils.Sign(m_componentFishModel.BendOrder.Value), 0f);
         }
         if (!m_componentCreature.ComponentBody.StandingOnValue.HasValue)
         {
             m_componentCreature.ComponentLocomotion.TurnOrder = new Vector2(0f - m_componentFishModel.BendOrder.Value, 0f);
             m_componentCreature.ComponentLocomotion.WalkOrder = m_direction;
         }
     }, null);
     m_stateMachine.TransitionTo("Inactive");
 }
Beispiel #12
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 override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
 {
     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_stateMachine.AddState("Inactive", delegate
     {
         m_importanceLevel = 0f;
         m_target          = null;
     }, delegate
     {
         if (IsActive)
         {
             m_stateMachine.TransitionTo("Move");
         }
         m_target = FindTarget(out float targetScore);
         if (m_target != null)
         {
             Vector3.Distance(m_target.ComponentBody.Position, m_componentCreature.ComponentBody.Position);
             SetImportanceLevel(targetScore);
         }
         else
         {
             m_importanceLevel = 0f;
         }
     }, null);
 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);
 }
Beispiel #15
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_subsystemTime     = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true);
     m_subsystemTerrain  = base.Project.FindSubsystem <SubsystemTerrain>(throwOnError: true);
     m_subsystemGameInfo = base.Project.FindSubsystem <SubsystemGameInfo>(throwOnError: true);
     m_componentPlayer   = base.Entity.FindComponent <ComponentPlayer>(throwOnError: true);
     m_playIntro         = valuesDictionary.GetValue <bool>("PlayIntro");
     m_stateMachine.AddState("ShipView", ShipView_Enter, ShipView_Update, null);
 }
 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);
 }
Beispiel #18
0
        // -- //

        void Awake()
        {
            stateMachine.AddState("Idle", fixedUpdate: Idle_FixedUpdate)
            .To("Jumping", () => Input.GetKeyDown(KeyCode.Space), enter: Jumping_Enter, update: Jumping_Update, exit: Jumping_Exit)
            .To("Idle", () => Input.GetKeyUp(KeyCode.Space))
            .To("Crouching", () => Input.GetKey(KeyCode.DownArrow), enter: Crouching_Enter, update: Crouching_Update, exit: Crouching_Exit)
            .To("Idle", () => !Input.GetKey(KeyCode.DownArrow))
            .AnyState("Shooting", () => Input.GetKeyDown(KeyCode.A), enter: Enter_Shooting, update: Update_Shooting, exit: Exit_Shooting).Exit(() => Input.GetKeyUp(KeyCode.A))
            ;
        }
 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_stateMachine.AddState("Inactive", delegate
     {
         m_importanceLevel = m_random.Float(0f, 1f);
     }, delegate
     {
         if (m_componentCreature.ComponentBody.StandingOnValue.HasValue && m_random.Float(0f, 1f) < 0.05f * m_subsystemTime.GameTimeDelta)
         {
             m_importanceLevel = m_random.Float(1f, 5f);
         }
         if (IsActive)
         {
             m_stateMachine.TransitionTo("LookAround");
         }
     }, null);
     m_stateMachine.AddState("LookAround", delegate
     {
         m_lookAroundTime = m_random.Float(8f, 15f);
     }, delegate
     {
         if (!IsActive)
         {
             m_stateMachine.TransitionTo("Inactive");
         }
         else if (m_lookAroundTime <= 0f)
         {
             m_importanceLevel = 0f;
         }
         else if (m_random.Float(0f, 1f) < 0.1f * m_subsystemTime.GameTimeDelta)
         {
             m_componentCreature.ComponentCreatureSounds.PlayIdleSound(skipIfRecentlyPlayed: false);
         }
         m_componentCreature.ComponentCreatureModel.LookRandomOrder = true;
         m_lookAroundTime -= m_subsystemTime.GameTimeDelta;
     }, null);
     m_stateMachine.TransitionTo("Inactive");
 }
Beispiel #20
0
 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
 {
     m_subsystemTime                  = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true);
     m_subsystemSky                   = base.Project.FindSubsystem <SubsystemSky>(throwOnError: true);
     m_componentCreature              = base.Entity.FindComponent <ComponentCreature>(throwOnError: true);
     m_componentPathfinding           = base.Entity.FindComponent <ComponentPathfinding>(throwOnError: true);
     m_subsystemCampfireBlockBehavior = base.Project.FindSubsystem <SubsystemCampfireBlockBehavior>(throwOnError: true);
     m_dayRange            = valuesDictionary.GetValue <float>("DayRange");
     m_nightRange          = valuesDictionary.GetValue <float>("NightRange");
     m_periodicEventOffset = m_random.Float(0f, 10f);
     m_stateMachine.AddState("Inactive", delegate
     {
         m_importanceLevel = 0f;
         m_target          = null;
     }, delegate
     {
         if (IsActive)
         {
             m_stateMachine.TransitionTo((m_importanceLevel < 10f) ? "Circle" : "Move");
         }
         else if (m_subsystemTime.PeriodicGameTimeEvent(1.0, m_periodicEventOffset))
         {
             m_target = FindTarget(out float targetScore);
             if (m_target.HasValue)
             {
                 if (m_random.Float(0f, 1f) < 0.015f)
                 {
                     m_ignoreFireUntil = m_subsystemTime.GameTime + 20.0;
                 }
                 Vector3.Distance(m_target.Value, m_componentCreature.ComponentBody.Position);
                 if (m_subsystemTime.GameTime < m_ignoreFireUntil)
                 {
                     m_importanceLevel = 0f;
                 }
                 else
                 {
                     m_importanceLevel = ((targetScore > 0.5f) ? 250f : m_random.Float(1f, 5f));
                 }
             }
             else
             {
                 m_importanceLevel = 0f;
             }
         }
     }, null);
Beispiel #21
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);
        }
Beispiel #24
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");
 }
Beispiel #25
0
        public PlayerData(Project project)
        {
            m_project            = project;
            SubsystemPlayers     = project.FindSubsystem <SubsystemPlayers>(throwOnError: true);
            SubsystemGameWidgets = project.FindSubsystem <SubsystemGameWidgets>(throwOnError: true);
            m_subsystemTerrain   = project.FindSubsystem <SubsystemTerrain>(throwOnError: true);
            m_subsystemGameInfo  = project.FindSubsystem <SubsystemGameInfo>(throwOnError: true);
            m_subsystemSky       = project.FindSubsystem <SubsystemSky>(throwOnError: true);
            m_playerClass        = PlayerClass.Male;
            Level          = 1f;
            FirstSpawnTime = -1.0;
            LastSpawnTime  = -1.0;
            RandomizeCharacterSkin();
            ResetName();
            InputDevice = WidgetInputDevice.None;
            m_stateMachine.AddState("FirstUpdate", null, delegate
            {
                if (ComponentPlayer != null)
                {
                    UpdateSpawnDialog(string.Format(LanguageControl.Get(fName, 4), Name, MathUtils.Floor(Level)), null, 0f, resetProgress: true);
                    m_stateMachine.TransitionTo("WaitForTerrain");
                }
                else
                {
                    m_stateMachine.TransitionTo("PrepareSpawn");
                }
            }, null);
            m_stateMachine.AddState("PrepareSpawn", delegate
            {
                if (SpawnPosition == Vector3.Zero)
                {
                    if (SubsystemPlayers.GlobalSpawnPosition == Vector3.Zero)
                    {
                        PlayerData playerData = SubsystemPlayers.PlayersData.FirstOrDefault((PlayerData pd) => pd.SpawnPosition != Vector3.Zero);
                        if (playerData != null)
                        {
                            if (playerData.ComponentPlayer != null)
                            {
                                SpawnPosition = playerData.ComponentPlayer.ComponentBody.Position;
                                m_spawnMode   = SpawnMode.InitialNoIntro;
                            }
                            else
                            {
                                SpawnPosition = playerData.SpawnPosition;
                                m_spawnMode   = SpawnMode.InitialNoIntro;
                            }
                        }
                        else
                        {
                            SpawnPosition = m_subsystemTerrain.TerrainContentsGenerator.FindCoarseSpawnPosition();
                            m_spawnMode   = SpawnMode.InitialIntro;
                        }
                        SubsystemPlayers.GlobalSpawnPosition = SpawnPosition;
                    }
                    else
                    {
                        SpawnPosition = SubsystemPlayers.GlobalSpawnPosition;
                        m_spawnMode   = SpawnMode.InitialNoIntro;
                    }
                }
                else
                {
                    m_spawnMode = SpawnMode.Respawn;
                }
                if (m_spawnMode == SpawnMode.Respawn)
                {
                    UpdateSpawnDialog(string.Format(LanguageControl.Get(fName, 2), Name, MathUtils.Floor(Level)), LanguageControl.Get(fName, 3), 0f, resetProgress: true);
                }
                else
                {
                    UpdateSpawnDialog(string.Format(LanguageControl.Get(fName, 4), Name, MathUtils.Floor(Level)), null, 0f, resetProgress: true);
                }
                m_subsystemTerrain.TerrainUpdater.SetUpdateLocation(PlayerIndex, SpawnPosition.XZ, 0f, 64f);
                m_terrainWaitStartTime = Time.FrameStartTime;
            }, delegate
            {
                if (Time.PeriodicEvent(0.1, 0.0))
                {
                    float updateProgress2 = m_subsystemTerrain.TerrainUpdater.GetUpdateProgress(PlayerIndex, 0f, 64f);
                    UpdateSpawnDialog(null, null, 0.5f * updateProgress2, resetProgress: false);
                    if (!(updateProgress2 < 1f) || !(Time.FrameStartTime - m_terrainWaitStartTime < 15.0))
                    {
                        switch (m_spawnMode)
                        {
                        case SpawnMode.InitialIntro:
                            SpawnPosition = FindIntroSpawnPosition(SpawnPosition.XZ);
                            break;

                        case SpawnMode.InitialNoIntro:
                            SpawnPosition = FindNoIntroSpawnPosition(SpawnPosition, respawn: false);
                            break;

                        case SpawnMode.Respawn:
                            SpawnPosition = FindNoIntroSpawnPosition(SpawnPosition, respawn: true);
                            break;

                        default:
                            throw new InvalidOperationException(LanguageControl.Get(fName, 5));
                        }
                        m_stateMachine.TransitionTo("WaitForTerrain");
                    }
                }
            }, null);
            m_stateMachine.AddState("WaitForTerrain", delegate
            {
                m_terrainWaitStartTime = Time.FrameStartTime;
                Vector2 center         = (ComponentPlayer != null) ? ComponentPlayer.ComponentBody.Position.XZ : SpawnPosition.XZ;
                m_subsystemTerrain.TerrainUpdater.SetUpdateLocation(PlayerIndex, center, MathUtils.Min(m_subsystemSky.VisibilityRange, 64f), 0f);
            }, delegate
            {
                if (Time.PeriodicEvent(0.1, 0.0))
                {
                    float updateProgress = m_subsystemTerrain.TerrainUpdater.GetUpdateProgress(PlayerIndex, MathUtils.Min(m_subsystemSky.VisibilityRange, 64f), 0f);
                    UpdateSpawnDialog(null, null, 0.5f + 0.5f * updateProgress, resetProgress: false);
                    if ((updateProgress >= 1f && Time.FrameStartTime - m_terrainWaitStartTime > 2.0) || Time.FrameStartTime - m_terrainWaitStartTime >= 15.0)
                    {
                        if (ComponentPlayer == null)
                        {
                            SpawnPlayer(SpawnPosition, m_spawnMode);
                        }
                        m_stateMachine.TransitionTo("Playing");
                    }
                }
            }, null);
            m_stateMachine.AddState("Playing", delegate
            {
                HideSpawnDialog();
            }, delegate
            {
                if (ComponentPlayer == null)
                {
                    m_stateMachine.TransitionTo("PrepareSpawn");
                }
                else if (m_playerDeathTime.HasValue)
                {
                    m_stateMachine.TransitionTo("PlayerDead");
                }
                else if (ComponentPlayer.ComponentHealth.Health <= 0f)
                {
                    m_playerDeathTime = Time.RealTime;
                }
            }, null);
            m_stateMachine.AddState("PlayerDead", delegate
            {
                GameWidget.ActiveCamera = GameWidget.FindCamera <DeathCamera>();
                if (ComponentPlayer != null)
                {
                    string text = ComponentPlayer.ComponentHealth.CauseOfDeath;
                    if (string.IsNullOrEmpty(text))
                    {
                        text = LanguageControl.Get(fName, 12);
                    }
                    string arg = string.Format(LanguageControl.Get(fName, 13), text);
                    if (m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Cruel)
                    {
                        ComponentPlayer.ComponentGui.DisplayLargeMessage(LanguageControl.Get(fName, 6), string.Format(LanguageControl.Get(fName, 7), arg, LanguageControl.Get("GameMode", m_subsystemGameInfo.WorldSettings.GameMode.ToString())), 30f, 1.5f);
                    }
                    else if (m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Adventure && !m_subsystemGameInfo.WorldSettings.IsAdventureRespawnAllowed)
                    {
                        ComponentPlayer.ComponentGui.DisplayLargeMessage(LanguageControl.Get(fName, 6), string.Format(LanguageControl.Get(fName, 8), arg), 30f, 1.5f);
                    }
                    else
                    {
                        ComponentPlayer.ComponentGui.DisplayLargeMessage(LanguageControl.Get(fName, 6), string.Format(LanguageControl.Get(fName, 9), arg), 30f, 1.5f);
                    }
                }
                Level = MathUtils.Max(MathUtils.Floor(Level / 2f), 1f);
            }, delegate
            {
                if (ComponentPlayer == null)
                {
                    m_stateMachine.TransitionTo("PrepareSpawn");
                }
                else if (Time.RealTime - m_playerDeathTime.Value > 1.5 && !DialogsManager.HasDialogs(ComponentPlayer.GuiWidget) && ComponentPlayer.GameWidget.Input.Any)
                {
                    if (m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Cruel)
                    {
                        DialogsManager.ShowDialog(ComponentPlayer.GuiWidget, new GameMenuDialog(ComponentPlayer));
                    }
                    else if (m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Adventure && !m_subsystemGameInfo.WorldSettings.IsAdventureRespawnAllowed)
                    {
                        ScreensManager.SwitchScreen("GameLoading", GameManager.WorldInfo, "AdventureRestart");
                    }
                    else
                    {
                        m_project.RemoveEntity(ComponentPlayer.Entity, disposeEntity: true);
                    }
                }
            }, null);
            m_stateMachine.TransitionTo("FirstUpdate");
        }
Beispiel #26
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");
 }
 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");
 }
        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_componentMiner            = base.Entity.FindComponent <ComponentMiner>(throwOnError: true);
            m_componentFishModel        = base.Entity.FindComponent <ComponentFishModel>(throwOnError: true);
            m_componentSwimAwayBehavior = base.Entity.FindComponent <ComponentSwimAwayBehavior>(throwOnError: true);
            string digInBlockName = valuesDictionary.GetValue <string>("DigInBlockName");

            m_digInBlockIndex = ((!string.IsNullOrEmpty(digInBlockName)) ? BlocksManager.Blocks.First((Block b) => b.GetType().Name == digInBlockName).BlockIndex : 0);
            m_maxDigInDepth   = valuesDictionary.GetValue <float>("MaxDigInDepth");
            m_componentCreature.ComponentBody.CollidedWithBody += delegate(ComponentBody b)
            {
                m_collidedWithBody = b;
            };
            m_stateMachine.AddState("Inactive", delegate
            {
                m_importanceLevel = 0f;
            }, delegate
            {
                if (m_random.Float(0f, 1f) < 0.5f * m_subsystemTime.GameTimeDelta && m_subsystemTime.GameTime > m_digOutTime + 15.0 && m_digInBlockIndex != 0)
                {
                    int x = Terrain.ToCell(m_componentCreature.ComponentBody.Position.X);
                    int y = Terrain.ToCell(m_componentCreature.ComponentBody.Position.Y - 0.9f);
                    int z = Terrain.ToCell(m_componentCreature.ComponentBody.Position.Z);
                    if (m_subsystemTerrain.Terrain.GetCellContents(x, y, z) == m_digInBlockIndex)
                    {
                        m_importanceLevel = m_random.Float(1f, 3f);
                    }
                }
                if (IsActive)
                {
                    m_stateMachine.TransitionTo("Sink");
                }
            }, null);
            m_stateMachine.AddState("Sink", delegate
            {
                m_importanceLevel = 10f;
                m_sinkTime        = m_subsystemTime.GameTime;
                m_componentPathfinding.Stop();
            }, delegate
            {
                if (m_random.Float(0f, 1f) < 2f * m_subsystemTime.GameTimeDelta && m_componentCreature.ComponentBody.StandingOnValue == m_digInBlockIndex && m_componentCreature.ComponentBody.Velocity.LengthSquared() < 1f)
                {
                    m_stateMachine.TransitionTo("DigIn");
                }
                if (!IsActive || m_subsystemTime.GameTime > m_sinkTime + 6.0)
                {
                    m_stateMachine.TransitionTo("Inactive");
                }
            }, null);
            m_stateMachine.AddState("DigIn", delegate
            {
                m_digInTime  = m_subsystemTime.GameTime;
                m_digOutTime = m_digInTime + (double)m_random.Float(30f, 60f);
            }, delegate
            {
                m_componentFishModel.DigInOrder = m_maxDigInDepth;
                if (m_collidedWithBody != null)
                {
                    if (m_subsystemTime.GameTime - m_digInTime > 2.0 && m_collidedWithBody.Density < 0.95f)
                    {
                        m_componentMiner.Hit(m_collidedWithBody, m_collidedWithBody.Position, Vector3.Normalize(m_collidedWithBody.Position - m_componentCreature.ComponentBody.Position));
                    }
                    m_componentSwimAwayBehavior.SwimAwayFrom(m_collidedWithBody);
                    m_stateMachine.TransitionTo("Inactive");
                }
                if (!IsActive || m_subsystemTime.GameTime >= m_digOutTime || m_componentCreature.ComponentBody.StandingOnValue != m_digInBlockIndex || m_componentCreature.ComponentBody.Velocity.LengthSquared() > 1f)
                {
                    m_stateMachine.TransitionTo("Inactive");
                }
            }, null);
            m_stateMachine.TransitionTo("Inactive");
        }
Beispiel #29
0
 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
 {
     m_subsystemTime        = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true);
     m_subsystemPathfinding = base.Project.FindSubsystem <SubsystemPathfinding>(throwOnError: true);
     m_componentCreature    = base.Entity.FindComponent <ComponentCreature>(throwOnError: true);
     m_componentPilot       = base.Entity.FindComponent <ComponentPilot>(throwOnError: true);
     m_stateMachine.AddState("Stopped", delegate
     {
         Stop();
         m_randomMoveCount = 0;
     }, delegate
     {
         if (Destination.HasValue)
         {
             m_stateMachine.TransitionTo("MovingDirect");
         }
     }, null);
     m_stateMachine.AddState("MovingDirect", delegate
     {
         IsStuck = false;
         m_destinationChanged = true;
     }, delegate
     {
         if (!Destination.HasValue)
         {
             m_stateMachine.TransitionTo("Stopped");
         }
         else if (m_destinationChanged)
         {
             m_componentPilot.SetDestination(Destination, Speed, Range, IgnoreHeightDifference, RaycastDestination, Speed >= 1f, DoNotAvoidBody);
             m_destinationChanged = false;
         }
         else if (!m_componentPilot.Destination.HasValue)
         {
             m_stateMachine.TransitionTo("Stopped");
         }
         else if (m_componentPilot.IsStuck)
         {
             if (MaxPathfindingPositions > 0 && m_componentCreature.ComponentLocomotion.WalkSpeed > 0f)
             {
                 m_stateMachine.TransitionTo("SearchingForPath");
             }
             else if (UseRandomMovements)
             {
                 m_stateMachine.TransitionTo("MovingRandomly");
             }
             else
             {
                 m_stateMachine.TransitionTo("Stuck");
             }
         }
     }, null);
     m_stateMachine.AddState("SearchingForPath", delegate
     {
         m_pathfindingResult.IsCompleted  = false;
         m_pathfindingResult.IsInProgress = false;
     }, delegate
     {
         if (!Destination.HasValue)
         {
             m_stateMachine.TransitionTo("Stopped");
         }
         else if (!m_pathfindingResult.IsInProgress && (!m_lastPathfindingTime.HasValue || m_subsystemTime.GameTime - m_lastPathfindingTime > 8.0) && m_pathfindingCongestion < 500f)
         {
             m_lastPathfindingDestination = Destination.Value;
             m_lastPathfindingTime        = m_subsystemTime.GameTime;
             m_subsystemPathfinding.QueuePathSearch(m_componentCreature.ComponentBody.Position + new Vector3(0f, 0.01f, 0f), Destination.Value + new Vector3(0f, 0.01f, 0f), 1f, m_componentCreature.ComponentBody.BoxSize, MaxPathfindingPositions, m_pathfindingResult);
         }
         else if (UseRandomMovements)
         {
             m_stateMachine.TransitionTo("MovingRandomly");
         }
         if (m_pathfindingResult.IsCompleted)
         {
             m_pathfindingCongestion = MathUtils.Min(m_pathfindingCongestion + (float)m_pathfindingResult.PositionsChecked, 1000f);
             if (m_pathfindingResult.Path.Count > 0)
             {
                 m_stateMachine.TransitionTo("MovingWithPath");
             }
             else if (UseRandomMovements)
             {
                 m_stateMachine.TransitionTo("MovingRandomly");
             }
             else
             {
                 m_stateMachine.TransitionTo("Stuck");
             }
         }
     }, null);
     m_stateMachine.AddState("MovingWithPath", delegate
     {
         m_componentPilot.Stop();
         m_randomMoveCount = 0;
     }, delegate
     {
         if (!Destination.HasValue)
         {
             m_stateMachine.TransitionTo("Stopped");
         }
         else if (!m_componentPilot.Destination.HasValue)
         {
             if (m_pathfindingResult.Path.Count > 0)
             {
                 Vector3 value = m_pathfindingResult.Path.Array[m_pathfindingResult.Path.Count - 1];
                 m_componentPilot.SetDestination(value, MathUtils.Min(Speed, 0.75f), 0.75f, ignoreHeightDifference: false, raycastDestination: false, Speed >= 1f, DoNotAvoidBody);
                 m_pathfindingResult.Path.RemoveAt(m_pathfindingResult.Path.Count - 1);
             }
             else
             {
                 m_stateMachine.TransitionTo("MovingDirect");
             }
         }
         else if (m_componentPilot.IsStuck)
         {
             if (UseRandomMovements)
             {
                 m_stateMachine.TransitionTo("MovingRandomly");
             }
             else
             {
                 m_stateMachine.TransitionTo("Stuck");
             }
         }
         else
         {
             float num = Vector3.DistanceSquared(m_componentCreature.ComponentBody.Position, Destination.Value);
             if (Vector3.DistanceSquared(m_lastPathfindingDestination.Value, Destination.Value) > num)
             {
                 m_stateMachine.TransitionTo("MovingDirect");
             }
         }
     }, null);
     m_stateMachine.AddState("MovingRandomly", delegate
     {
         m_componentPilot.SetDestination(m_componentCreature.ComponentBody.Position + new Vector3(5f * m_random.Float(-1f, 1f), 0f, 5f * m_random.Float(-1f, 1f)), 1f, 1f, ignoreHeightDifference: true, raycastDestination: false, takeRisks: false, DoNotAvoidBody);
         m_randomMoveCount++;
     }, delegate
     {
         if (!Destination.HasValue)
         {
             m_stateMachine.TransitionTo("Stopped");
         }
         else if (m_randomMoveCount > 3)
         {
             m_stateMachine.TransitionTo("Stuck");
         }
         else if (m_componentPilot.IsStuck || !m_componentPilot.Destination.HasValue)
         {
             m_stateMachine.TransitionTo("MovingDirect");
         }
     }, null);
     m_stateMachine.AddState("Stuck", delegate
     {
         IsStuck = true;
     }, delegate
     {
         if (!Destination.HasValue)
         {
             m_stateMachine.TransitionTo("Stopped");
         }
         else if (m_destinationChanged)
         {
             m_destinationChanged = false;
             m_stateMachine.TransitionTo("MovingDirect");
         }
     }, null);
     m_stateMachine.TransitionTo("Stopped");
 }
 static PerformanceManager()
 {
     m_primitivesRenderer  = new PrimitivesRenderer2D();
     m_averageFrameTime    = new RunningAverage(1f);
     m_averageCpuFrameTime = new RunningAverage(1f);
     m_stateMachine        = new StateMachine();
     m_statsString         = string.Empty;
     m_stateMachine.AddState("PreMeasure", delegate
     {
         m_totalGameTime = 0.0;
     }, delegate
     {
         if (GameManager.Project != null)
         {
             m_totalGameTime += Time.FrameDuration;
             if (m_totalGameTime > 60.0)
             {
                 m_stateMachine.TransitionTo("Measuring");
             }
         }
     }, null);
     m_stateMachine.AddState("Measuring", delegate
     {
         m_totalFrameTime    = 0.0;
         m_totalCpuFrameTime = 0.0;
         m_frameCount        = 0;
     }, delegate
     {
         if (GameManager.Project != null)
         {
             if (ScreensManager.CurrentScreen != null && ScreensManager.CurrentScreen.GetType() == typeof(GameScreen))
             {
                 float lastFrameTime    = Program.LastFrameTime;
                 float lastCpuFrameTime = Program.LastCpuFrameTime;
                 if (lastFrameTime > 0f && lastFrameTime < 1f && lastCpuFrameTime > 0f && lastCpuFrameTime < 1f)
                 {
                     m_totalFrameTime    += lastFrameTime;
                     m_totalCpuFrameTime += lastCpuFrameTime;
                     m_frameCount++;
                 }
                 if (m_totalFrameTime > 180.0)
                 {
                     m_stateMachine.TransitionTo("PostMeasure");
                 }
             }
         }
         else
         {
             m_stateMachine.TransitionTo("PreMeasure");
         }
     }, null);
     m_stateMachine.AddState("PostMeasure", delegate
     {
         if (m_frameCount > 0)
         {
             m_longTermAverageFrameTime = (float)(m_totalFrameTime / (double)m_frameCount);
             float num  = (int)MathUtils.Round(MathUtils.Round(m_totalFrameTime / (double)m_frameCount / 0.004999999888241291) * 0.004999999888241291 * 1000.0);
             float num2 = (int)MathUtils.Round(MathUtils.Round(m_totalCpuFrameTime / (double)m_frameCount / 0.004999999888241291) * 0.004999999888241291 * 1000.0);
             AnalyticsManager.LogEvent("[PerformanceManager] Measurement", new AnalyticsParameter("FrameCount", m_frameCount.ToString()), new AnalyticsParameter("AverageFrameTime", num.ToString() + "ms"), new AnalyticsParameter("AverageFrameCpuTime", num2.ToString() + "ms"));
             Log.Information($"PerformanceManager Measurement: frames={m_frameCount.ToString()}, avgFrameTime={num.ToString()}ms, avgFrameCpuTime={num2.ToString()}ms");
         }
     }, delegate
     {
         if (GameManager.Project == null)
         {
             m_stateMachine.TransitionTo("PreMeasure");
         }
     }, null);
     m_stateMachine.TransitionTo("PreMeasure");
 }