Пример #1
0
 public override void Load(ValuesDictionary valuesDictionary)
 {
     base.Load(valuesDictionary);
     m_subsystemTime    = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true);
     m_subsystemWeather = base.Project.FindSubsystem <SubsystemWeather>(throwOnError: true);
     m_subsystemSky     = base.Project.FindSubsystem <SubsystemSky>(throwOnError: true);
 }
 public override void Load(ValuesDictionary valuesDictionary)
 {
     m_subsystemAudio              = base.Project.FindSubsystem <SubsystemAudio>(throwOnError: true);
     m_subsystemSoundMaterials     = base.Project.FindSubsystem <SubsystemSoundMaterials>(throwOnError: true);
     m_subsystemParticles          = base.Project.FindSubsystem <SubsystemParticles>(throwOnError: true);
     m_subsystemPickables          = base.Project.FindSubsystem <SubsystemPickables>(throwOnError: true);
     m_subsystemBodies             = base.Project.FindSubsystem <SubsystemBodies>(throwOnError: true);
     m_subsystemTerrain            = base.Project.FindSubsystem <SubsystemTerrain>(throwOnError: true);
     m_subsystemSky                = base.Project.FindSubsystem <SubsystemSky>(throwOnError: true);
     m_subsystemTime               = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true);
     m_subsystemNoise              = base.Project.FindSubsystem <SubsystemNoise>(throwOnError: true);
     m_subsystemExplosions         = base.Project.FindSubsystem <SubsystemExplosions>(throwOnError: true);
     m_subsystemGameInfo           = base.Project.FindSubsystem <SubsystemGameInfo>(throwOnError: true);
     m_subsystemBlockBehaviors     = base.Project.FindSubsystem <SubsystemBlockBehaviors>(throwOnError: true);
     m_subsystemFluidBlockBehavior = base.Project.FindSubsystem <SubsystemFluidBlockBehavior>(throwOnError: true);
     m_subsystemFireBlockBehavior  = base.Project.FindSubsystem <SubsystemFireBlockBehavior>(throwOnError: true);
     foreach (ValuesDictionary item in valuesDictionary.GetValue <ValuesDictionary>("Projectiles").Values.Where((object v) => v is ValuesDictionary))
     {
         Projectile projectile = new Projectile();
         projectile.Value        = item.GetValue <int>("Value");
         projectile.Position     = item.GetValue <Vector3>("Position");
         projectile.Velocity     = item.GetValue <Vector3>("Velocity");
         projectile.CreationTime = item.GetValue <double>("CreationTime");
         m_projectiles.Add(projectile);
     }
 }
 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);
Пример #4
0
        public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
        {
            m_subsystemGameInfo       = base.Project.FindSubsystem <SubsystemGameInfo>(throwOnError: true);
            m_subsystemSky            = base.Project.FindSubsystem <SubsystemSky>(throwOnError: true);
            m_subsystemParticles      = base.Project.FindSubsystem <SubsystemParticles>(throwOnError: true);
            m_subsystemAudio          = base.Project.FindSubsystem <SubsystemAudio>(throwOnError: true);
            m_componentSpawn          = base.Entity.FindComponent <ComponentSpawn>(throwOnError: true);
            m_componentBody           = base.Entity.FindComponent <ComponentBody>(throwOnError: true);
            m_componentHealth         = base.Entity.FindComponent <ComponentHealth>(throwOnError: true);
            m_dayEntityTemplateName   = valuesDictionary.GetValue <string>("DayEntityTemplateName");
            m_nightEntityTemplateName = valuesDictionary.GetValue <string>("NightEntityTemplateName");
            float value = valuesDictionary.GetValue <float>("Probability");

            if (!string.IsNullOrEmpty(m_dayEntityTemplateName))
            {
                DatabaseManager.FindEntityValuesDictionary(m_dayEntityTemplateName, throwIfNotFound: true);
            }
            if (!string.IsNullOrEmpty(m_nightEntityTemplateName))
            {
                DatabaseManager.FindEntityValuesDictionary(m_nightEntityTemplateName, throwIfNotFound: true);
            }
            m_timeToSwitch              = s_random.Float(3f, 15f);
            IsEnabled                   = (s_random.Float(0f, 1f) < value);
            m_componentSpawn.Despawned += ComponentSpawn_Despawned;
        }
Пример #5
0
 public override void Load(ValuesDictionary valuesDictionary)
 {
     m_subsystemAudio              = base.Project.FindSubsystem <SubsystemAudio>(throwOnError: true);
     m_subsystemPlayers            = base.Project.FindSubsystem <SubsystemPlayers>(throwOnError: true);
     m_subsystemTerrain            = base.Project.FindSubsystem <SubsystemTerrain>(throwOnError: true);
     m_subsystemSky                = base.Project.FindSubsystem <SubsystemSky>(throwOnError: true);
     m_subsystemTime               = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true);
     m_subsystemGameInfo           = base.Project.FindSubsystem <SubsystemGameInfo>(throwOnError: true);
     m_subsystemParticles          = base.Project.FindSubsystem <SubsystemParticles>(throwOnError: true);
     m_subsystemExplosions         = base.Project.FindSubsystem <SubsystemExplosions>(throwOnError: true);
     m_subsystemBlockBehaviors     = base.Project.FindSubsystem <SubsystemBlockBehaviors>(throwOnError: true);
     m_subsystemFireBlockBehavior  = base.Project.FindSubsystem <SubsystemFireBlockBehavior>(throwOnError: true);
     m_subsystemFluidBlockBehavior = base.Project.FindSubsystem <SubsystemFluidBlockBehavior>(throwOnError: true);
     foreach (ValuesDictionary item in valuesDictionary.GetValue <ValuesDictionary>("Pickables").Values.Where((object v) => v is ValuesDictionary))
     {
         Pickable pickable = new Pickable();
         pickable.Value        = item.GetValue <int>("Value");
         pickable.Count        = item.GetValue <int>("Count");
         pickable.Position     = item.GetValue <Vector3>("Position");
         pickable.Velocity     = item.GetValue <Vector3>("Velocity");
         pickable.CreationTime = item.GetValue("CreationTime", 0.0);
         if (item.ContainsKey("StuckMatrix"))
         {
             pickable.StuckMatrix = item.GetValue <Matrix>("StuckMatrix");
         }
         m_pickables.Add(pickable);
     }
 }
Пример #6
0
 public override void Load(ValuesDictionary valuesDictionary)
 {
     m_subsystemSky     = base.Project.FindSubsystem <SubsystemSky>(throwOnError: true);
     m_batchesByType[0] = m_primitivesRenderer.TexturedBatch(ContentManager.Get <Texture2D>("Textures/RoundGlow"), useAlphaTest: false, 0, DepthStencilState.DepthRead, RasterizerState.CullCounterClockwiseScissor, BlendState.AlphaBlend, SamplerState.LinearClamp);
     m_batchesByType[1] = m_primitivesRenderer.TexturedBatch(ContentManager.Get <Texture2D>("Textures/SquareGlow"), useAlphaTest: false, 0, DepthStencilState.DepthRead, RasterizerState.CullCounterClockwiseScissor, BlendState.AlphaBlend, SamplerState.LinearClamp);
     m_batchesByType[2] = m_primitivesRenderer.TexturedBatch(ContentManager.Get <Texture2D>("Textures/HorizontalRectGlow"), useAlphaTest: false, 0, DepthStencilState.DepthRead, RasterizerState.CullCounterClockwiseScissor, BlendState.AlphaBlend, SamplerState.LinearClamp);
     m_batchesByType[3] = m_primitivesRenderer.TexturedBatch(ContentManager.Get <Texture2D>("Textures/VerticalRectGlow"), useAlphaTest: false, 0, DepthStencilState.DepthRead, RasterizerState.CullCounterClockwiseScissor, BlendState.AlphaBlend, SamplerState.LinearClamp);
 }
 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
 {
     m_subsystemTerrain          = base.Project.FindSubsystem <SubsystemTerrain>(throwOnError: true);
     m_subsystemAnimatedTextures = base.Project.FindSubsystem <SubsystemAnimatedTextures>(throwOnError: true);
     m_subsystemSky    = base.Project.FindSubsystem <SubsystemSky>(throwOnError: true);
     m_componentPlayer = base.Entity.FindComponent <ComponentPlayer>(throwOnError: true);
     m_shader          = ContentManager.Get <Shader>("Shaders/Highlight");
 }
Пример #8
0
 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_subsystemSky     = base.Project.FindSubsystem <SubsystemSky>(throwOnError: true);
     m_componentGui     = base.Entity.FindComponent <ComponentGui>(throwOnError: true);
     m_componentPlayer  = base.Entity.FindComponent <ComponentPlayer>(throwOnError: true);
 }
Пример #9
0
 public TerrainRenderer(SubsystemTerrain subsystemTerrain)
 {
     m_subsystemTerrain          = subsystemTerrain;
     m_subsystemSky              = subsystemTerrain.Project.FindSubsystem <SubsystemSky>(throwOnError: true);
     m_subsystemAnimatedTextures = subsystemTerrain.SubsystemAnimatedTextures;
     m_opaqueShader              = ContentManager.Get <Shader>("Shaders/Opaque");
     m_alphaTestedShader         = ContentManager.Get <Shader>("Shaders/AlphaTested");
     m_transparentShader         = ContentManager.Get <Shader>("Shaders/Transparent");
     Display.DeviceReset        += Display_DeviceReset;
 }
Пример #10
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");
 }
Пример #11
0
 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
 {
     m_subsystemTime     = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true);
     m_subsystemViews    = base.Project.FindSubsystem <SubsystemGameWidgets>(throwOnError: true);
     m_subsystemGameInfo = base.Project.FindSubsystem <SubsystemGameInfo>(throwOnError: true);
     m_subsystemSky      = base.Project.FindSubsystem <SubsystemSky>(throwOnError: true);
     m_componentFrame    = base.Entity.FindComponent <ComponentFrame>(throwOnError: true);
     m_componentModel    = base.Entity.FindComponent <ComponentModel>(throwOnError: true);
     m_creationTime      = m_subsystemTime.GameTime;
     Heading             = valuesDictionary.GetValue <float>("Heading");
 }
Пример #12
0
 public override void Load(ValuesDictionary valuesDictionary)
 {
     base.Load(valuesDictionary);
     m_subsystemTerrain     = base.Project.FindSubsystem <SubsystemTerrain>(throwOnError: true);
     m_subsystemProjectiles = base.Project.FindSubsystem <SubsystemProjectiles>(throwOnError: true);
     m_subsystemParticles   = base.Project.FindSubsystem <SubsystemParticles>(throwOnError: true);
     m_subsystemAudio       = base.Project.FindSubsystem <SubsystemAudio>(throwOnError: true);
     m_subsystemNoise       = base.Project.FindSubsystem <SubsystemNoise>(throwOnError: true);
     m_subsystemTime        = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true);
     m_subsystemSky         = base.Project.FindSubsystem <SubsystemSky>(throwOnError: true);
     m_subsystemPlayers     = base.Project.FindSubsystem <SubsystemPlayers>(throwOnError: true);
 }
 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
 {
     m_subsystemTerrain = base.Project.FindSubsystem <SubsystemTerrain>(throwOnError: true);
     m_subsystemSky     = base.Project.FindSubsystem <SubsystemSky>(throwOnError: true);
     m_componentMiner   = base.Entity.FindComponent <ComponentMiner>(throwOnError: true);
     m_shader           = ContentManager.Get <Shader>("Shaders/AlphaTested");
     m_textures         = new Texture2D[8];
     for (int i = 0; i < 8; i++)
     {
         m_textures[i] = ContentManager.Get <Texture2D>($"Textures/Cracks{i + 1}");
     }
 }
Пример #14
0
        public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
        {
            m_subsystemSky   = base.Project.FindSubsystem <SubsystemSky>(throwOnError: true);
            m_componentFrame = base.Entity.FindComponent <ComponentFrame>(throwOnError: true);
            string value = valuesDictionary.GetValue <string>("ModelName");

            Model       = ContentManager.Get <Model>(value);
            CastsShadow = valuesDictionary.GetValue <bool>("CastsShadow");
            string value2 = valuesDictionary.GetValue <string>("TextureOverride");

            TextureOverride        = (string.IsNullOrEmpty(value2) ? null : ContentManager.Get <Texture2D>(value2));
            PrepareOrder           = valuesDictionary.GetValue <int>("PrepareOrder");
            m_boundingSphereRadius = valuesDictionary.GetValue <float>("BoundingSphereRadius");
        }
Пример #15
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);
        protected override void Load(TemplatesDatabase.ValuesDictionary valuesDictionary)
        {
            base.Load(valuesDictionary);
            subsystemPlayers  = Project.FindSubsystem <SubsystemPlayers>();
            subsystemTerrain  = Project.FindSubsystem <SubsystemTerrain>();
            subsystemSky      = Project.FindSubsystem <SubsystemSky>();
            subsystemCreature = Project.FindSubsystem <SubsystemCreatureSpawn>();
            subsystemTime     = Project.FindSubsystem <SubsystemTimeOfDay>();

            LoadCreatureTemplateNames();
            LoadCreatureDatas();

            foreach (KeyValuePair <string, object> pair in valuesDictionary.GetValue <TemplatesDatabase.ValuesDictionary>("Points"))
            {
                var p = Engine.Serialization.HumanReadableConverter.ConvertFromString <Point3>(pair.Key);
                storedPoints[pair.Key] = p;
            }

            InitCommands();
        }
 public override void Load(ValuesDictionary valuesDictionary)
 {
     m_subsystemTime             = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true);
     m_subsystemTerrain          = base.Project.FindSubsystem <SubsystemTerrain>(throwOnError: true);
     m_subsystemSky              = base.Project.FindSubsystem <SubsystemSky>(throwOnError: true);
     m_subsystemAnimatedTextures = base.Project.FindSubsystem <SubsystemAnimatedTextures>(throwOnError: true);
     m_shader = ContentManager.Get <Shader>("Shaders/AlphaTested");
     foreach (ValuesDictionary value9 in valuesDictionary.GetValue <ValuesDictionary>("MovingBlockSets").Values)
     {
         Vector3            value  = value9.GetValue <Vector3>("Position");
         Vector3            value2 = value9.GetValue <Vector3>("TargetPosition");
         float              value3 = value9.GetValue <float>("Speed");
         float              value4 = value9.GetValue <float>("Acceleration");
         float              value5 = value9.GetValue <float>("Drag");
         Vector2            value6 = value9.GetValue("Smoothness", Vector2.Zero);
         string             value7 = value9.GetValue <string>("Id", null);
         object             value8 = value9.GetValue <object>("Tag", null);
         List <MovingBlock> list   = new List <MovingBlock>();
         string[]           array  = value9.GetValue <string>("Blocks").Split(new char[1]
         {
             ';'
         }, StringSplitOptions.RemoveEmptyEntries);
         foreach (string obj2 in array)
         {
             MovingBlock item   = default(MovingBlock);
             string[]    array2 = obj2.Split(new char[1]
             {
                 ','
             }, StringSplitOptions.RemoveEmptyEntries);
             item.Value    = HumanReadableConverter.ConvertFromString <int>(array2[0]);
             item.Offset.X = HumanReadableConverter.ConvertFromString <int>(array2[1]);
             item.Offset.Y = HumanReadableConverter.ConvertFromString <int>(array2[2]);
             item.Offset.Z = HumanReadableConverter.ConvertFromString <int>(array2[3]);
             list.Add(item);
         }
         AddMovingBlockSet(value, value2, value3, value4, value5, value6, list, value7, value8, testCollision: false);
     }
 }
Пример #18
0
        public void ManualLightingStrike(Vector3 position, Vector3 direction)
        {
            int     num    = Terrain.ToCell(position.X + direction.X * 32f);
            int     num2   = Terrain.ToCell(position.Z + direction.Z * 32f);
            Vector3?vector = null;

            for (int i = 0; i < 300; i++)
            {
                int num3 = m_random.Int(-8, 8);
                int num4 = m_random.Int(-8, 8);
                int num5 = num + num3;
                int num6 = num2 + num4;
                int num7 = SubsystemTerrain.Terrain.CalculateTopmostCellHeight(num5, num6);
                if (!vector.HasValue || (float)num7 > vector.Value.Y)
                {
                    vector = new Vector3(num5, num7, num6);
                }
            }
            if (vector.HasValue)
            {
                SubsystemSky.MakeLightningStrike(vector.Value);
            }
        }
Пример #19
0
 public override void Load(ValuesDictionary valuesDictionary)
 {
     m_subsystemTerrain = base.Project.FindSubsystem <SubsystemTerrain>(throwOnError: true);
     m_subsystemSky     = base.Project.FindSubsystem <SubsystemSky>(throwOnError: true);
     m_subsystemShadows = base.Project.FindSubsystem <SubsystemShadows>(throwOnError: true);
 }
Пример #20
0
        public void Update(float dt)
        {
            if (m_subsystemGameInfo.TotalElapsedGameTime > m_precipitationEndTime)
            {
                if (m_precipitationEndTime == 0.0)
                {
                    if (m_subsystemGameInfo.WorldSettings.StartingPositionMode == StartingPositionMode.Hard)
                    {
                        m_precipitationStartTime = m_subsystemGameInfo.TotalElapsedGameTime + (double)(60f * m_random.Float(2f, 3f));
                        m_lightningIntensity     = m_random.Float(0.5f, 1f);
                    }
                    else
                    {
                        m_precipitationStartTime = m_subsystemGameInfo.TotalElapsedGameTime + (double)(60f * m_random.Float(3f, 6f));
                        m_lightningIntensity     = m_random.Float(0.33f, 0.66f);
                    }
                }
                else
                {
                    m_precipitationStartTime = m_subsystemGameInfo.TotalElapsedGameTime + (double)(60f * m_random.Float(5f, 45f));
                    m_lightningIntensity     = ((m_random.Float(0f, 1f) < 0.5f) ? m_random.Float(0.33f, 1f) : 0f);
                }
                m_precipitationEndTime = m_precipitationStartTime + (double)(60f * m_random.Float(3f, 6f));
            }
            float num = (float)MathUtils.Max(0.0, MathUtils.Min(m_subsystemGameInfo.TotalElapsedGameTime - m_precipitationStartTime, m_precipitationEndTime - m_subsystemGameInfo.TotalElapsedGameTime));

            GlobalPrecipitationIntensity = (m_subsystemGameInfo.WorldSettings.AreWeatherEffectsEnabled ? MathUtils.Saturate(num * 0.04f) : 0f);
            if (GlobalPrecipitationIntensity == 1f && SubsystemTime.PeriodicGameTimeEvent(1.0, 0.0))
            {
                TerrainChunk[] allocatedChunks = SubsystemTerrain.Terrain.AllocatedChunks;
                for (int i = 0; i < allocatedChunks.Length; i++)
                {
                    TerrainChunk terrainChunk = allocatedChunks[m_random.Int(0, allocatedChunks.Length - 1)];
                    if (terrainChunk.State < TerrainChunkState.InvalidVertices1 || !m_random.Bool(m_lightningIntensity * 0.0002f))
                    {
                        continue;
                    }
                    int     num2   = terrainChunk.Origin.X + m_random.Int(0, 15);
                    int     num3   = terrainChunk.Origin.Y + m_random.Int(0, 15);
                    Vector3?vector = null;
                    for (int j = num2 - 8; j < num2 + 8; j++)
                    {
                        for (int k = num3 - 8; k < num3 + 8; k++)
                        {
                            int topHeight = SubsystemTerrain.Terrain.GetTopHeight(j, k);
                            if (!vector.HasValue || (float)topHeight > vector.Value.Y)
                            {
                                vector = new Vector3(j, topHeight, k);
                            }
                        }
                    }
                    if (vector.HasValue)
                    {
                        SubsystemSky.MakeLightningStrike(vector.Value);
                        return;
                    }
                }
            }
            if (Time.PeriodicEvent(0.5, 0.0))
            {
                float num4 = 0f;
                if (GlobalPrecipitationIntensity > 0f)
                {
                    float num5 = 0f;
                    foreach (Vector3 listenerPosition in m_subsystemAudio.ListenerPositions)
                    {
                        int     num6    = Terrain.ToCell(listenerPosition.X) - 5;
                        int     num7    = Terrain.ToCell(listenerPosition.Z) - 5;
                        int     num8    = Terrain.ToCell(listenerPosition.X) + 5;
                        int     num9    = Terrain.ToCell(listenerPosition.Z) + 5;
                        Vector3 vector2 = default(Vector3);
                        for (int l = num6; l <= num8; l++)
                        {
                            for (int m = num7; m <= num9; m++)
                            {
                                PrecipitationShaftInfo precipitationShaftInfo = GetPrecipitationShaftInfo(l, m);
                                if (precipitationShaftInfo.Type == PrecipitationType.Rain && precipitationShaftInfo.Intensity > 0f)
                                {
                                    vector2.X = (float)l + 0.5f;
                                    vector2.Y = MathUtils.Max(precipitationShaftInfo.YLimit, listenerPosition.Y);
                                    vector2.Z = (float)m + 0.5f;
                                    float num10    = vector2.X - listenerPosition.X;
                                    float num11    = 8f * (vector2.Y - listenerPosition.Y);
                                    float num12    = vector2.Z - listenerPosition.Z;
                                    float distance = MathUtils.Sqrt(num10 * num10 + num11 * num11 + num12 * num12);
                                    num5 += m_subsystemAudio.CalculateVolume(distance, 1.5f) * precipitationShaftInfo.Intensity;
                                }
                            }
                        }
                    }
                    num4 = MathUtils.Max(num4, num5);
                }
                m_targetRainSoundVolume = MathUtils.Saturate(1.5f * num4 / m_rainVolumeFactor);
            }
            m_rainSound.Volume = MathUtils.Saturate(MathUtils.Lerp(m_rainSound.Volume, SettingsManager.SoundsVolume * m_targetRainSoundVolume, 5f * dt));
            if (m_rainSound.Volume > AudioManager.MinAudibleVolume)
            {
                m_rainSound.Play();
            }
            else
            {
                m_rainSound.Pause();
            }
        }
 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");
 }
 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");
 }
Пример #23
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");
        }