Exemplo n.º 1
0
 public void ProcessModifiedCells()
 {
     m_modifiedList.Clear();
     foreach (Point3 key in m_modifiedCells.Keys)
     {
         m_modifiedList.Add(key);
     }
     m_modifiedCells.Clear();
     for (int i = 0; i < m_modifiedList.Count; i++)
     {
         Point3 point = m_modifiedList.Array[i];
         for (int j = 0; j < m_neighborOffsets.Length; j++)
         {
             Point3 point2       = m_neighborOffsets[j];
             int    cellContents = Terrain.GetCellContents(point.X + point2.X, point.Y + point2.Y, point.Z + point2.Z);
             SubsystemBlockBehavior[] blockBehaviors = m_subsystemBlockBehaviors.GetBlockBehaviors(cellContents);
             for (int k = 0; k < blockBehaviors.Length; k++)
             {
                 blockBehaviors[k].OnNeighborBlockChanged(point.X + point2.X, point.Y + point2.Y, point.Z + point2.Z, point.X, point.Y, point.Z);
             }
         }
     }
 }
Exemplo n.º 2
0
 public void ScanProjectile(Projectile projectile)
 {
     if (!m_projectiles.ContainsKey(projectile))
     {
         int num = Terrain.ExtractContents(projectile.Value);
         if (m_subsystemBlockBehaviors.GetBlockBehaviors(num).Contains(this))
         {
             m_projectiles.Add(projectile, value: true);
             projectile.ProjectileStoppedAction = ProjectileStoppedAction.DoNothing;
             Color color = (num == 228) ? new Color(255, 140, 192) : Color.White;
             m_subsystemProjectiles.AddTrail(projectile, new Vector3(0f, 0.25f, 0.1f), new SmokeTrailParticleSystem(20, 0.33f, float.MaxValue, color));
         }
     }
 }
        public Projectile FireProjectile(int value, Vector3 position, Vector3 velocity, Vector3 angularVelocity, ComponentCreature owner)
        {
            int     num    = Terrain.ExtractContents(value);
            Block   block  = BlocksManager.Blocks[num];
            Vector3 v      = Vector3.Normalize(velocity);
            Vector3 vector = position;

            if (owner != null)
            {
                Ray3        ray         = new Ray3(position + v * 5f, -v);
                BoundingBox boundingBox = owner.ComponentBody.BoundingBox;
                boundingBox.Min -= new Vector3(0.4f);
                boundingBox.Max += new Vector3(0.4f);
                float?num2 = ray.Intersection(boundingBox);
                if (num2.HasValue)
                {
                    if (num2.Value == 0f)
                    {
                        return(null);
                    }
                    vector = position + v * (5f - num2.Value + 0.1f);
                }
            }
            Vector3 end = vector + v * block.ProjectileTipOffset;

            if (!m_subsystemTerrain.Raycast(position, end, useInteractionBoxes: false, skipAirBlocks: true, (int testValue, float distance) => BlocksManager.Blocks[Terrain.ExtractContents(testValue)].IsCollidable).HasValue)
            {
                Projectile projectile = AddProjectile(value, vector, velocity, angularVelocity, owner);
                SubsystemBlockBehavior[] blockBehaviors = m_subsystemBlockBehaviors.GetBlockBehaviors(num);
                for (int i = 0; i < blockBehaviors.Length; i++)
                {
                    blockBehaviors[i].OnFiredAsProjectile(projectile);
                }
                return(projectile);
            }
            return(null);
        }
Exemplo n.º 4
0
        public override void Load(ValuesDictionary valuesDictionary)
        {
            m_subsystemTerrain        = base.Project.FindSubsystem <SubsystemTerrain>(throwOnError: true);
            m_subsystemBlockBehaviors = base.Project.FindSubsystem <SubsystemBlockBehaviors>(throwOnError: true);
            m_pollChunkCoordinates    = valuesDictionary.GetValue <Point2>("PollChunkCoordinates");
            Point2 value = valuesDictionary.GetValue <Point2>("PollPoint");

            m_pollX    = value.X;
            m_pollZ    = value.Y;
            m_pollPass = valuesDictionary.GetValue <int>("PollPass");
            m_pollableBehaviorsByContents = new SubsystemPollableBlockBehavior[BlocksManager.Blocks.Length][];
            for (int i = 0; i < m_pollableBehaviorsByContents.Length; i++)
            {
                m_pollableBehaviorsByContents[i] = (from s in m_subsystemBlockBehaviors.GetBlockBehaviors(i)
                                                    where s is SubsystemPollableBlockBehavior
                                                    select(SubsystemPollableBlockBehavior) s).ToArray();
            }
        }
Exemplo n.º 5
0
        public bool Place(TerrainRaycastResult raycastResult, int value)
        {
            if (Place2 != null)
            {
                return(Place2(raycastResult, value));
            }

            int num = Terrain.ExtractContents(value);

            if (BlocksManager.Blocks[num].IsPlaceable)
            {
                Block block = BlocksManager.Blocks[num];
                BlockPlacementData placementData = block.GetPlacementValue(m_subsystemTerrain, this, value, raycastResult);
                if (placementData.Value != 0)
                {
                    Point3 point = CellFace.FaceToPoint3(placementData.CellFace.Face);
                    int    num2  = placementData.CellFace.X + point.X;
                    int    num3  = placementData.CellFace.Y + point.Y;
                    int    num4  = placementData.CellFace.Z + point.Z;
                    if (num3 > 0 && num3 < 255 && (IsBlockPlacingAllowed(ComponentCreature.ComponentBody) || m_subsystemGameInfo.WorldSettings.GameMode <= GameMode.Harmless))
                    {
                        bool flag = false;
                        if (block.IsCollidable)
                        {
                            BoundingBox boundingBox = ComponentCreature.ComponentBody.BoundingBox;
                            boundingBox.Min += new Vector3(0.2f);
                            boundingBox.Max -= new Vector3(0.2f);
                            BoundingBox[] customCollisionBoxes = block.GetCustomCollisionBoxes(m_subsystemTerrain, placementData.Value);
                            for (int i = 0; i < customCollisionBoxes.Length; i++)
                            {
                                BoundingBox box = customCollisionBoxes[i];
                                box.Min += new Vector3(num2, num3, num4);
                                box.Max += new Vector3(num2, num3, num4);
                                if (boundingBox.Intersection(box))
                                {
                                    flag = true;
                                    break;
                                }
                            }
                        }
                        if (!flag)
                        {
                            SubsystemBlockBehavior[] blockBehaviors = m_subsystemBlockBehaviors.GetBlockBehaviors(Terrain.ExtractContents(placementData.Value));
                            for (int i = 0; i < blockBehaviors.Length; i++)
                            {
                                blockBehaviors[i].OnItemPlaced(num2, num3, num4, ref placementData, value);
                            }
                            m_subsystemTerrain.DestroyCell(0, num2, num3, num4, placementData.Value, noDrop: false, noParticleSystem: false);
                            m_subsystemAudio.PlaySound("Audio/BlockPlaced", 1f, 0f, new Vector3(placementData.CellFace.X, placementData.CellFace.Y, placementData.CellFace.Z), 5f, autoDelay: false);
                            Poke(forceRestart: false);
                            if (ComponentCreature.PlayerStats != null)
                            {
                                ComponentCreature.PlayerStats.BlocksPlaced++;
                            }
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Exemplo n.º 6
0
        public void PostprocessExplosions(bool playExplosionSound)
        {
            Point3 point = Point3.Zero;
            float  num   = float.MaxValue;
            float  num2  = 0f;

            foreach (KeyValuePair <Point3, float> item in m_pressureByPoint.ToDictionary())
            {
                num2 += item.Value;
                float num3 = m_subsystemAudio.CalculateListenerDistance(new Vector3(item.Key));
                if (num3 < num)
                {
                    num   = num3;
                    point = item.Key;
                }
                float num4 = 0.001f * MathUtils.Pow(num2, 0.5f);
                float num5 = MathUtils.Saturate(item.Value / 15f - num4) * m_random.Float(0.2f, 1f);
                if (num5 > 0.1f)
                {
                    m_explosionParticleSystem.SetExplosionCell(item.Key, num5);
                }
            }
            foreach (KeyValuePair <Point3, SurroundingPressurePoint> item2 in m_surroundingPressureByPoint.ToDictionary())
            {
                int cellValue = m_subsystemTerrain.Terrain.GetCellValue(item2.Key.X, item2.Key.Y, item2.Key.Z);
                int num6      = Terrain.ExtractContents(cellValue);
                SubsystemBlockBehavior[] blockBehaviors = m_subsystemBlockBehaviors.GetBlockBehaviors(num6);
                if (blockBehaviors.Length != 0)
                {
                    for (int i = 0; i < blockBehaviors.Length; i++)
                    {
                        blockBehaviors[i].OnExplosion(cellValue, item2.Key.X, item2.Key.Y, item2.Key.Z, item2.Value.Pressure);
                    }
                }
                float probability = item2.Value.IsIncendiary ? 0.5f : 0.2f;
                Block block       = BlocksManager.Blocks[num6];
                if (block.FireDuration > 0f && item2.Value.Pressure / block.ExplosionResilience > 0.2f && m_random.Bool(probability))
                {
                    m_subsystemFireBlockBehavior.SetCellOnFire(item2.Key.X, item2.Key.Y, item2.Key.Z, item2.Value.IsIncendiary ? 1f : 0.3f);
                }
            }
            foreach (ComponentBody body in m_subsystemBodies.Bodies)
            {
                CalculateImpulseAndDamage(body, null, out Vector3 impulse, out float damage);
                impulse *= m_random.Float(0.5f, 1.5f);
                damage  *= m_random.Float(0.5f, 1.5f);
                body.ApplyImpulse(impulse);
                body.Entity.FindComponent <ComponentHealth>()?.Injure(damage, null, ignoreInvulnerability: false, "Blasted by explosion");
                body.Entity.FindComponent <ComponentDamage>()?.Damage(damage);
                ComponentOnFire componentOnFire = body.Entity.FindComponent <ComponentOnFire>();
                if (componentOnFire != null && m_random.Float(0f, 1f) < MathUtils.Min(damage - 0.1f, 0.5f))
                {
                    componentOnFire.SetOnFire(null, m_random.Float(6f, 8f));
                }
            }
            foreach (Pickable pickable in m_subsystemPickables.Pickables)
            {
                Block block2 = BlocksManager.Blocks[Terrain.ExtractContents(pickable.Value)];
                CalculateImpulseAndDamage(pickable.Position + new Vector3(0f, 0.5f, 0f), 20f, null, out Vector3 impulse2, out float damage2);
                if (damage2 / block2.ExplosionResilience > 0.1f)
                {
                    TryExplodeBlock(Terrain.ToCell(pickable.Position.X), Terrain.ToCell(pickable.Position.Y), Terrain.ToCell(pickable.Position.Z), pickable.Value);
                    pickable.ToRemove = true;
                }
                else
                {
                    Vector3 vector = (impulse2 + new Vector3(0f, 0.1f * impulse2.Length(), 0f)) * m_random.Float(0.75f, 1f);
                    if (vector.Length() > 10f)
                    {
                        Projectile projectile = m_subsystemProjectiles.AddProjectile(pickable.Value, pickable.Position, pickable.Velocity + vector, m_random.Vector3(0f, 20f), null);
                        if (m_random.Float(0f, 1f) < 0.33f)
                        {
                            m_subsystemProjectiles.AddTrail(projectile, Vector3.Zero, new SmokeTrailParticleSystem(15, m_random.Float(0.75f, 1.5f), m_random.Float(1f, 6f), Color.White));
                        }
                        pickable.ToRemove = true;
                    }
                    else
                    {
                        pickable.Velocity += vector;
                    }
                }
            }
            foreach (Projectile projectile2 in m_subsystemProjectiles.Projectiles)
            {
                if (!m_generatedProjectiles.ContainsKey(projectile2))
                {
                    CalculateImpulseAndDamage(projectile2.Position + new Vector3(0f, 0.5f, 0f), 20f, null, out Vector3 impulse3, out float _);
                    projectile2.Velocity += (impulse3 + new Vector3(0f, 0.1f * impulse3.Length(), 0f)) * m_random.Float(0.75f, 1f);
                }
            }
            Vector3 position = new Vector3(point.X, point.Y, point.Z);
            float   delay    = m_subsystemAudio.CalculateDelay(num);

            if (num2 > 1000000f)
            {
                if (playExplosionSound)
                {
                    m_subsystemAudio.PlaySound("Audio/ExplosionEnormous", 1f, m_random.Float(-0.1f, 0.1f), position, 40f, delay);
                }
                m_subsystemNoise.MakeNoise(position, 1f, 100f);
            }
            else if (num2 > 100000f)
            {
                if (playExplosionSound)
                {
                    m_subsystemAudio.PlaySound("Audio/ExplosionHuge", 1f, m_random.Float(-0.2f, 0.2f), position, 30f, delay);
                }
                m_subsystemNoise.MakeNoise(position, 1f, 70f);
            }
            else if (num2 > 20000f)
            {
                if (playExplosionSound)
                {
                    m_subsystemAudio.PlaySound("Audio/ExplosionLarge", 1f, m_random.Float(-0.2f, 0.2f), position, 26f, delay);
                }
                m_subsystemNoise.MakeNoise(position, 1f, 50f);
            }
            else if (num2 > 4000f)
            {
                if (playExplosionSound)
                {
                    m_subsystemAudio.PlaySound("Audio/ExplosionMedium", 1f, m_random.Float(-0.2f, 0.2f), position, 24f, delay);
                }
                m_subsystemNoise.MakeNoise(position, 1f, 40f);
            }
            else if (num2 > 100f)
            {
                if (playExplosionSound)
                {
                    m_subsystemAudio.PlaySound("Audio/ExplosionSmall", 1f, m_random.Float(-0.2f, 0.2f), position, 22f, delay);
                }
                m_subsystemNoise.MakeNoise(position, 1f, 35f);
            }
            else if (num2 > 0f)
            {
                if (playExplosionSound)
                {
                    m_subsystemAudio.PlaySound("Audio/ExplosionTiny", 1f, m_random.Float(-0.2f, 0.2f), position, 20f, delay);
                }
                m_subsystemNoise.MakeNoise(position, 1f, 30f);
            }
        }
Exemplo n.º 7
0
        public void Update(float dt)
        {
            double totalElapsedGameTime = m_subsystemGameInfo.TotalElapsedGameTime;
            float  num  = MathUtils.Pow(0.5f, dt);
            float  num2 = MathUtils.Pow(0.001f, dt);

            m_tmpPlayers.Clear();
            foreach (ComponentPlayer componentPlayer in m_subsystemPlayers.ComponentPlayers)
            {
                if (componentPlayer.ComponentHealth.Health > 0f)
                {
                    m_tmpPlayers.Add(componentPlayer);
                }
            }
            foreach (Pickable pickable in m_pickables)
            {
                if (pickable.ToRemove)
                {
                    m_pickablesToRemove.Add(pickable);
                }
                else
                {
                    Block  block = BlocksManager.Blocks[Terrain.ExtractContents(pickable.Value)];
                    int    num3  = m_pickables.Count - m_pickablesToRemove.Count;
                    float  num4  = MathUtils.Lerp(300f, 90f, MathUtils.Saturate((float)num3 / 60f));
                    double num5  = totalElapsedGameTime - pickable.CreationTime;
                    if (num5 > (double)num4)
                    {
                        pickable.ToRemove = true;
                    }
                    else
                    {
                        TerrainChunk chunkAtCell = m_subsystemTerrain.Terrain.GetChunkAtCell(Terrain.ToCell(pickable.Position.X), Terrain.ToCell(pickable.Position.Z));
                        if (chunkAtCell != null && chunkAtCell.State > TerrainChunkState.InvalidContents4)
                        {
                            Vector3 position = pickable.Position;
                            Vector3 vector   = position + pickable.Velocity * dt;
                            if (!pickable.FlyToPosition.HasValue && num5 > 0.5)
                            {
                                foreach (ComponentPlayer tmpPlayer in m_tmpPlayers)
                                {
                                    ComponentBody componentBody = tmpPlayer.ComponentBody;
                                    Vector3       v             = componentBody.Position + new Vector3(0f, 0.75f, 0f);
                                    float         num6          = (v - pickable.Position).LengthSquared();
                                    if (num6 < 3.0625f)
                                    {
                                        bool       flag      = Terrain.ExtractContents(pickable.Value) == 248;
                                        IInventory inventory = tmpPlayer.ComponentMiner.Inventory;
                                        if (flag || ComponentInventoryBase.FindAcquireSlotForItem(inventory, pickable.Value) >= 0)
                                        {
                                            if (num6 < 1f)
                                            {
                                                if (flag)
                                                {
                                                    tmpPlayer.ComponentLevel.AddExperience(pickable.Count, playSound: true);
                                                    pickable.ToRemove = true;
                                                }
                                                else
                                                {
                                                    pickable.Count = ComponentInventoryBase.AcquireItems(inventory, pickable.Value, pickable.Count);
                                                    if (pickable.Count == 0)
                                                    {
                                                        pickable.ToRemove = true;
                                                        m_subsystemAudio.PlaySound("Audio/PickableCollected", 0.7f, -0.4f, pickable.Position, 2f, autoDelay: false);
                                                    }
                                                }
                                            }
                                            else if (!pickable.StuckMatrix.HasValue)
                                            {
                                                pickable.FlyToPosition = v + 0.1f * MathUtils.Sqrt(num6) * componentBody.Velocity;
                                            }
                                        }
                                    }
                                }
                            }
                            if (pickable.FlyToPosition.HasValue)
                            {
                                Vector3 v2   = pickable.FlyToPosition.Value - pickable.Position;
                                float   num7 = v2.LengthSquared();
                                if (num7 >= 0.25f)
                                {
                                    pickable.Velocity = 6f * v2 / MathUtils.Sqrt(num7);
                                }
                                else
                                {
                                    pickable.FlyToPosition = null;
                                }
                            }
                            else
                            {
                                FluidBlock surfaceBlock;
                                float?     surfaceHeight;
                                Vector2?   vector2 = m_subsystemFluidBlockBehavior.CalculateFlowSpeed(Terrain.ToCell(pickable.Position.X), Terrain.ToCell(pickable.Position.Y + 0.1f), Terrain.ToCell(pickable.Position.Z), out surfaceBlock, out surfaceHeight);
                                if (!pickable.StuckMatrix.HasValue)
                                {
                                    TerrainRaycastResult?terrainRaycastResult = m_subsystemTerrain.Raycast(position, vector, useInteractionBoxes: false, skipAirBlocks: true, (int value, float distance) => BlocksManager.Blocks[Terrain.ExtractContents(value)].IsCollidable);
                                    if (terrainRaycastResult.HasValue)
                                    {
                                        int contents = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValue(terrainRaycastResult.Value.CellFace.X, terrainRaycastResult.Value.CellFace.Y, terrainRaycastResult.Value.CellFace.Z));
                                        SubsystemBlockBehavior[] blockBehaviors = m_subsystemBlockBehaviors.GetBlockBehaviors(contents);
                                        for (int i = 0; i < blockBehaviors.Length; i++)
                                        {
                                            blockBehaviors[i].OnHitByProjectile(terrainRaycastResult.Value.CellFace, pickable);
                                        }
                                        if (m_subsystemTerrain.Raycast(position, position, useInteractionBoxes: false, skipAirBlocks: true, (int value2, float distance) => BlocksManager.Blocks[Terrain.ExtractContents(value2)].IsCollidable).HasValue)
                                        {
                                            int num8  = Terrain.ToCell(position.X);
                                            int num9  = Terrain.ToCell(position.Y);
                                            int num10 = Terrain.ToCell(position.Z);
                                            int num11 = 0;
                                            int num12 = 0;
                                            int num13 = 0;
                                            int?num14 = null;
                                            for (int j = -3; j <= 3; j++)
                                            {
                                                for (int k = -3; k <= 3; k++)
                                                {
                                                    for (int l = -3; l <= 3; l++)
                                                    {
                                                        if (!BlocksManager.Blocks[m_subsystemTerrain.Terrain.GetCellContents(j + num8, k + num9, l + num10)].IsCollidable)
                                                        {
                                                            int num15 = j * j + k * k + l * l;
                                                            if (!num14.HasValue || num15 < num14.Value)
                                                            {
                                                                num11 = j + num8;
                                                                num12 = k + num9;
                                                                num13 = l + num10;
                                                                num14 = num15;
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                            if (num14.HasValue)
                                            {
                                                pickable.FlyToPosition = new Vector3(num11, num12, num13) + new Vector3(0.5f);
                                            }
                                            else
                                            {
                                                pickable.ToRemove = true;
                                            }
                                        }
                                        else
                                        {
                                            Plane plane = terrainRaycastResult.Value.CellFace.CalculatePlane();
                                            bool  flag2 = vector2.HasValue && vector2.Value != Vector2.Zero;
                                            if (plane.Normal.X != 0f)
                                            {
                                                float num16 = (flag2 || MathUtils.Sqrt(MathUtils.Sqr(pickable.Velocity.Y) + MathUtils.Sqr(pickable.Velocity.Z)) > 10f) ? 0.95f : 0.25f;
                                                pickable.Velocity *= new Vector3(0f - num16, num16, num16);
                                            }
                                            if (plane.Normal.Y != 0f)
                                            {
                                                float num17 = (flag2 || MathUtils.Sqrt(MathUtils.Sqr(pickable.Velocity.X) + MathUtils.Sqr(pickable.Velocity.Z)) > 10f) ? 0.95f : 0.25f;
                                                pickable.Velocity *= new Vector3(num17, 0f - num17, num17);
                                                if (flag2)
                                                {
                                                    pickable.Velocity.Y += 0.1f * plane.Normal.Y;
                                                }
                                            }
                                            if (plane.Normal.Z != 0f)
                                            {
                                                float num18 = (flag2 || MathUtils.Sqrt(MathUtils.Sqr(pickable.Velocity.X) + MathUtils.Sqr(pickable.Velocity.Y)) > 10f) ? 0.95f : 0.25f;
                                                pickable.Velocity *= new Vector3(num18, num18, 0f - num18);
                                            }
                                            vector = position;
                                        }
                                    }
                                }
                                else
                                {
                                    Vector3 vector3 = pickable.StuckMatrix.Value.Translation + pickable.StuckMatrix.Value.Up * block.ProjectileTipOffset;
                                    if (!m_subsystemTerrain.Raycast(vector3, vector3, useInteractionBoxes: false, skipAirBlocks: true, (int value, float distance) => BlocksManager.Blocks[Terrain.ExtractContents(value)].IsCollidable).HasValue)
                                    {
                                        pickable.Position    = pickable.StuckMatrix.Value.Translation;
                                        pickable.Velocity    = Vector3.Zero;
                                        pickable.StuckMatrix = null;
                                    }
                                }
                                if (surfaceBlock is WaterBlock && !pickable.SplashGenerated)
                                {
                                    m_subsystemParticles.AddParticleSystem(new WaterSplashParticleSystem(m_subsystemTerrain, pickable.Position, large: false));
                                    m_subsystemAudio.PlayRandomSound("Audio/Splashes", 1f, m_random.Float(-0.2f, 0.2f), pickable.Position, 6f, autoDelay: true);
                                    pickable.SplashGenerated = true;
                                }
                                else if (surfaceBlock is MagmaBlock && !pickable.SplashGenerated)
                                {
                                    m_subsystemParticles.AddParticleSystem(new MagmaSplashParticleSystem(m_subsystemTerrain, pickable.Position, large: false));
                                    m_subsystemAudio.PlayRandomSound("Audio/Sizzles", 1f, m_random.Float(-0.2f, 0.2f), pickable.Position, 3f, autoDelay: true);
                                    pickable.ToRemove        = true;
                                    pickable.SplashGenerated = true;
                                    m_subsystemExplosions.TryExplodeBlock(Terrain.ToCell(pickable.Position.X), Terrain.ToCell(pickable.Position.Y), Terrain.ToCell(pickable.Position.Z), pickable.Value);
                                }
                                else if (surfaceBlock == null)
                                {
                                    pickable.SplashGenerated = false;
                                }
                                if (m_subsystemTime.PeriodicGameTimeEvent(1.0, (double)(pickable.GetHashCode() % 100) / 100.0) && (m_subsystemTerrain.Terrain.GetCellContents(Terrain.ToCell(pickable.Position.X), Terrain.ToCell(pickable.Position.Y + 0.1f), Terrain.ToCell(pickable.Position.Z)) == 104 || m_subsystemFireBlockBehavior.IsCellOnFire(Terrain.ToCell(pickable.Position.X), Terrain.ToCell(pickable.Position.Y + 0.1f), Terrain.ToCell(pickable.Position.Z))))
                                {
                                    m_subsystemAudio.PlayRandomSound("Audio/Sizzles", 1f, m_random.Float(-0.2f, 0.2f), pickable.Position, 3f, autoDelay: true);
                                    pickable.ToRemove = true;
                                    m_subsystemExplosions.TryExplodeBlock(Terrain.ToCell(pickable.Position.X), Terrain.ToCell(pickable.Position.Y), Terrain.ToCell(pickable.Position.Z), pickable.Value);
                                }
                                if (!pickable.StuckMatrix.HasValue)
                                {
                                    if (vector2.HasValue && surfaceHeight.HasValue)
                                    {
                                        float num19 = surfaceHeight.Value - pickable.Position.Y;
                                        float num20 = MathUtils.Saturate(3f * num19);
                                        pickable.Velocity.X += 4f * dt * (vector2.Value.X - pickable.Velocity.X);
                                        pickable.Velocity.Y -= 10f * dt;
                                        pickable.Velocity.Y += 10f * (1f / block.Density * num20) * dt;
                                        pickable.Velocity.Z += 4f * dt * (vector2.Value.Y - pickable.Velocity.Z);
                                        pickable.Velocity.Y *= num2;
                                    }
                                    else
                                    {
                                        pickable.Velocity.Y -= 10f * dt;
                                        pickable.Velocity   *= num;
                                    }
                                }
                            }
                            pickable.Position = vector;
                        }
                    }
                }
            }
            foreach (Pickable item in m_pickablesToRemove)
            {
                m_pickables.Remove(item);
                if (this.PickableRemoved != null)
                {
                    this.PickableRemoved(item);
                }
            }
            m_pickablesToRemove.Clear();
        }
Exemplo n.º 8
0
        public void HandleAxisCollision(int axis, float move, ref Vector3 position, bool isSmoothRising)
        {
            Vector3 boxSize = BoxSize;

            m_collisionBoxes.Clear();
            if (IsSneaking && axis != 1)
            {
                FindSneakCollisionBoxes(position, new Vector2(boxSize.X - 0.08f, boxSize.Z - 0.08f), m_collisionBoxes);
            }
            Vector3 v;

            switch (axis)
            {
            case 0:
                position.X += move;
                v           = new Vector3(0f, 0.04f, 0.04f);
                break;

            case 1:
                position.Y += move;
                v           = new Vector3(0.04f, 0f, 0.04f);
                break;

            default:
                position.Z += move;
                v           = new Vector3(0.04f, 0.04f, 0f);
                break;
            }
            BoundingBox boundingBox = new BoundingBox(position - new Vector3(boxSize.X / 2f, 0f, boxSize.Z / 2f) + v, position + new Vector3(boxSize.X / 2f, boxSize.Y, boxSize.Z / 2f) - v);

            FindTerrainCollisionBoxes(boundingBox, m_collisionBoxes);
            m_collisionBoxes.AddRange(m_movingBlocksCollisionBoxes);
            float        num;
            CollisionBox pushingCollisionBox;

            if ((axis != 1) | isSmoothRising)
            {
                BoundingBox smoothRiseBox = boundingBox;
                smoothRiseBox.Min.Y += MaxSmoothRiseHeight;
                num = CalculateSmoothRisePushBack(boundingBox, smoothRiseBox, axis, m_collisionBoxes, out pushingCollisionBox);
            }
            else
            {
                num = CalculatePushBack(boundingBox, axis, m_collisionBoxes, out pushingCollisionBox);
            }
            BoundingBox  box = new BoundingBox(position - new Vector3(boxSize.X / 2f, 0f, boxSize.Z / 2f) + v, position + new Vector3(boxSize.X / 2f, boxSize.Y, boxSize.Z / 2f) - v);
            CollisionBox pushingCollisionBox2;
            float        num2 = CalculatePushBack(box, axis, m_bodiesCollisionBoxes, out pushingCollisionBox2);

            if (MathUtils.Abs(num) > MathUtils.Abs(num2))
            {
                if (num == 0f)
                {
                    return;
                }
                int num3 = Terrain.ExtractContents(pushingCollisionBox.BlockValue);
                if (BlocksManager.Blocks[num3].HasCollisionBehavior)
                {
                    SubsystemBlockBehavior[] blockBehaviors = m_subsystemBlockBehaviors.GetBlockBehaviors(num3);
                    for (int i = 0; i < blockBehaviors.Length; i++)
                    {
                        Vector3  vector   = (pushingCollisionBox.Box.Min + pushingCollisionBox.Box.Max) / 2f;
                        CellFace cellFace = CellFace.FromAxisAndDirection(Terrain.ToCell(vector.X), Terrain.ToCell(vector.Y), Terrain.ToCell(vector.Z), axis, 0f - GetVectorComponent(m_velocity, axis));
                        blockBehaviors[i].OnCollide(cellFace, GetVectorComponent(m_velocity, axis), this);
                    }
                }
                switch (axis)
                {
                case 0:
                    position.X  += num;
                    m_velocity.X = pushingCollisionBox.BlockVelocity.X;
                    break;

                case 1:
                    position.Y  += num;
                    m_velocity.Y = pushingCollisionBox.BlockVelocity.Y;
                    if (move < 0f)
                    {
                        StandingOnValue    = pushingCollisionBox.BlockValue;
                        StandingOnBody     = pushingCollisionBox.ComponentBody;
                        StandingOnVelocity = pushingCollisionBox.BlockVelocity;
                    }
                    break;

                default:
                    position.Z  += num;
                    m_velocity.Z = pushingCollisionBox.BlockVelocity.Z;
                    break;
                }
            }
            else
            {
                if (num2 == 0f)
                {
                    return;
                }
                ComponentBody componentBody = pushingCollisionBox2.ComponentBody;
                switch (axis)
                {
                case 0:
                    InelasticCollision(m_velocity.X, componentBody.m_velocity.X, Mass, componentBody.Mass, 0.5f, out m_velocity.X, out componentBody.m_velocity.X);
                    position.X += num2;
                    break;

                case 1:
                    InelasticCollision(m_velocity.Y, componentBody.m_velocity.Y, Mass, componentBody.Mass, 0.5f, out m_velocity.Y, out componentBody.m_velocity.Y);
                    position.Y += num2;
                    if (move < 0f)
                    {
                        StandingOnValue    = pushingCollisionBox2.BlockValue;
                        StandingOnBody     = pushingCollisionBox2.ComponentBody;
                        StandingOnVelocity = new Vector3(componentBody.m_velocity.X, 0f, componentBody.m_velocity.Z);
                    }
                    break;

                default:
                    InelasticCollision(m_velocity.Z, componentBody.m_velocity.Z, Mass, componentBody.Mass, 0.5f, out m_velocity.Z, out componentBody.m_velocity.Z);
                    position.Z += num2;
                    break;
                }
                if (this.CollidedWithBody != null)
                {
                    this.CollidedWithBody(componentBody);
                }
                if (componentBody.CollidedWithBody != null)
                {
                    componentBody.CollidedWithBody(this);
                }
            }
        }
Exemplo n.º 9
0
        public void HandleInput()
        {
            WidgetInput    input          = m_componentPlayer.GameWidget.Input;
            PlayerInput    playerInput    = m_componentPlayer.ComponentInput.PlayerInput;
            ComponentRider componentRider = m_componentPlayer.ComponentRider;

            if (m_componentPlayer.GameWidget.ActiveCamera.IsEntityControlEnabled)
            {
                if (!m_keyboardHelpMessageShown && (m_componentPlayer.PlayerData.InputDevice & WidgetInputDevice.Keyboard) != 0 && Time.PeriodicEvent(7.0, 0.0))
                {
                    m_keyboardHelpMessageShown = true;
                    DisplaySmallMessage(LanguageControl.Get(fName, 1), Color.White, blinking: true, playNotificationSound: true);
                }
                else if (!m_gamepadHelpMessageShown && (m_componentPlayer.PlayerData.InputDevice & WidgetInputDevice.Gamepads) != 0 && Time.PeriodicEvent(7.0, 0.0))
                {
                    m_gamepadHelpMessageShown = true;
                    DisplaySmallMessage(LanguageControl.Get(fName, 2), Color.White, blinking: true, playNotificationSound: true);
                }
            }
            if (playerInput.KeyboardHelp)
            {
                if (m_keyboardHelpDialog == null)
                {
                    m_keyboardHelpDialog = new KeyboardHelpDialog();
                }
                if (m_keyboardHelpDialog.ParentWidget != null)
                {
                    DialogsManager.HideDialog(m_keyboardHelpDialog);
                }
                else
                {
                    DialogsManager.ShowDialog(m_componentPlayer.GuiWidget, m_keyboardHelpDialog);
                }
            }
            if (playerInput.GamepadHelp)
            {
                if (m_gamepadHelpDialog == null)
                {
                    m_gamepadHelpDialog = new GamepadHelpDialog();
                }
                if (m_gamepadHelpDialog.ParentWidget != null)
                {
                    DialogsManager.HideDialog(m_gamepadHelpDialog);
                }
                else
                {
                    DialogsManager.ShowDialog(m_componentPlayer.GuiWidget, m_gamepadHelpDialog);
                }
            }
            if (m_helpButtonWidget.IsClicked)
            {
                ScreensManager.SwitchScreen("Help");
            }
            if (playerInput.ToggleInventory || m_inventoryButtonWidget.IsClicked)
            {
                if (IsInventoryVisible())
                {
                    ModalPanelWidget = null;
                }
                else if (m_componentPlayer.ComponentMiner.Inventory is ComponentCreativeInventory)
                {
                    ModalPanelWidget = new CreativeInventoryWidget(m_componentPlayer.Entity);
                }
                else
                {
                    ModalPanelWidget = new FullInventoryWidget(m_componentPlayer.ComponentMiner.Inventory, m_componentPlayer.Entity.FindComponent <ComponentCraftingTable>(throwOnError: true));
                }
            }
            if (playerInput.ToggleClothing || m_clothingButtonWidget.IsClicked)
            {
                if (IsClothingVisible())
                {
                    ModalPanelWidget = null;
                }
                else
                {
                    ModalPanelWidget = new ClothingWidget(m_componentPlayer);
                }
            }
            if (m_sneakButtonWidget.IsClicked || playerInput.ToggleSneak)
            {
                bool isSneaking = m_componentPlayer.ComponentBody.IsSneaking;
                m_componentPlayer.ComponentBody.IsSneaking = !isSneaking;
                if (m_componentPlayer.ComponentBody.IsSneaking != isSneaking)
                {
                    if (m_componentPlayer.ComponentBody.IsSneaking)
                    {
                        DisplaySmallMessage(LanguageControl.Get(fName, 3), Color.White, blinking: false, playNotificationSound: false);
                    }
                    else
                    {
                        DisplaySmallMessage(LanguageControl.Get(fName, 4), Color.White, blinking: false, playNotificationSound: false);
                    }
                }
            }
            if (componentRider != null && (m_mountButtonWidget.IsClicked || playerInput.ToggleMount))
            {
                bool flag = componentRider.Mount != null;
                if (flag)
                {
                    componentRider.StartDismounting();
                }
                else
                {
                    ComponentMount componentMount = componentRider.FindNearestMount();
                    if (componentMount != null)
                    {
                        componentRider.StartMounting(componentMount);
                    }
                }
                if (componentRider.Mount != null != flag)
                {
                    if (componentRider.Mount != null)
                    {
                        DisplaySmallMessage(LanguageControl.Get(fName, 5), Color.White, blinking: false, playNotificationSound: false);
                    }
                    else
                    {
                        DisplaySmallMessage(LanguageControl.Get(fName, 6), Color.White, blinking: false, playNotificationSound: false);
                    }
                }
            }
            if ((m_editItemButton.IsClicked || playerInput.EditItem) && m_componentPlayer.ComponentBlockHighlight.NearbyEditableCell.HasValue)
            {
                Point3 value     = m_componentPlayer.ComponentBlockHighlight.NearbyEditableCell.Value;
                int    cellValue = m_subsystemTerrain.Terrain.GetCellValue(value.X, value.Y, value.Z);
                int    contents  = Terrain.ExtractContents(cellValue);
                SubsystemBlockBehavior[] blockBehaviors = m_subsystemBlockBehaviors.GetBlockBehaviors(contents);
                for (int i = 0; i < blockBehaviors.Length && !blockBehaviors[i].OnEditBlock(value.X, value.Y, value.Z, cellValue, m_componentPlayer); i++)
                {
                }
            }
            else if ((m_editItemButton.IsClicked || playerInput.EditItem) && IsActiveSlotEditable())
            {
                IInventory inventory = m_componentPlayer.ComponentMiner.Inventory;
                if (inventory != null)
                {
                    int activeSlotIndex = inventory.ActiveSlotIndex;
                    int num             = Terrain.ExtractContents(inventory.GetSlotValue(activeSlotIndex));
                    if (BlocksManager.Blocks[num].IsEditable)
                    {
                        SubsystemBlockBehavior[] blockBehaviors = m_subsystemBlockBehaviors.GetBlockBehaviors(num);
                        for (int i = 0; i < blockBehaviors.Length && !blockBehaviors[i].OnEditInventoryItem(inventory, activeSlotIndex, m_componentPlayer); i++)
                        {
                        }
                    }
                }
            }
            if (m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Creative && (m_creativeFlyButtonWidget.IsClicked || playerInput.ToggleCreativeFly) && componentRider.Mount == null)
            {
                bool isCreativeFlyEnabled = m_componentPlayer.ComponentLocomotion.IsCreativeFlyEnabled;
                m_componentPlayer.ComponentLocomotion.IsCreativeFlyEnabled = !isCreativeFlyEnabled;
                if (m_componentPlayer.ComponentLocomotion.IsCreativeFlyEnabled != isCreativeFlyEnabled)
                {
                    if (m_componentPlayer.ComponentLocomotion.IsCreativeFlyEnabled)
                    {
                        m_componentPlayer.ComponentLocomotion.JumpOrder = 1f;
                        DisplaySmallMessage(LanguageControl.Get(fName, 7), Color.White, blinking: false, playNotificationSound: false);
                    }
                    else
                    {
                        DisplaySmallMessage(LanguageControl.Get(fName, 8), Color.White, blinking: false, playNotificationSound: false);
                    }
                }
            }
            if (!m_componentPlayer.ComponentInput.IsControlledByVr && (m_cameraButtonWidget.IsClicked || playerInput.SwitchCameraMode))
            {
                GameWidget gameWidget = m_componentPlayer.GameWidget;
                if (gameWidget.ActiveCamera.GetType() == typeof(FppCamera))
                {
                    gameWidget.ActiveCamera = gameWidget.FindCamera <TppCamera>();
                    DisplaySmallMessage(LanguageControl.Get(fName, 9), Color.White, blinking: false, playNotificationSound: false);
                }
                else if (gameWidget.ActiveCamera.GetType() == typeof(TppCamera))
                {
                    gameWidget.ActiveCamera = gameWidget.FindCamera <OrbitCamera>();
                    DisplaySmallMessage(LanguageControl.Get(fName, 10), Color.White, blinking: false, playNotificationSound: false);
                }
                else if (gameWidget.ActiveCamera.GetType() == typeof(OrbitCamera))
                {
                    gameWidget.ActiveCamera = gameWidget.FindCamera <FixedCamera>();
                    DisplaySmallMessage(LanguageControl.Get(fName, 11), Color.White, blinking: false, playNotificationSound: false);
                }
                else
                {
                    gameWidget.ActiveCamera = gameWidget.FindCamera <FppCamera>();
                    DisplaySmallMessage(LanguageControl.Get(fName, 12), Color.White, blinking: false, playNotificationSound: false);
                }
            }
            if (m_photoButtonWidget.IsClicked || playerInput.TakeScreenshot)
            {
                ScreenCaptureManager.CapturePhoto(delegate
                {
                    DisplaySmallMessage(LanguageControl.Get(fName, 13), Color.White, blinking: false, playNotificationSound: false);
                }, delegate
                {
                    DisplaySmallMessage(LanguageControl.Get(fName, 14), Color.White, blinking: false, playNotificationSound: false);
                });
            }
            if (m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Creative && (m_lightningButtonWidget.IsClicked || playerInput.Lighting))
            {
                Matrix matrix = Matrix.CreateFromQuaternion(m_componentPlayer.ComponentCreatureModel.EyeRotation);
                base.Project.FindSubsystem <SubsystemWeather>(throwOnError: true).ManualLightingStrike(m_componentPlayer.ComponentCreatureModel.EyePosition, matrix.Forward);
            }
            if (m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Creative && (m_timeOfDayButtonWidget.IsClicked || playerInput.TimeOfDay))
            {
                float num2  = MathUtils.Remainder(0.25f, 1f);
                float num3  = MathUtils.Remainder(0.5f, 1f);
                float num4  = MathUtils.Remainder(0.75f, 1f);
                float num5  = MathUtils.Remainder(1f, 1f);
                float num6  = MathUtils.Remainder(num2 - m_subsystemTimeOfDay.TimeOfDay, 1f);
                float num7  = MathUtils.Remainder(num3 - m_subsystemTimeOfDay.TimeOfDay, 1f);
                float num8  = MathUtils.Remainder(num4 - m_subsystemTimeOfDay.TimeOfDay, 1f);
                float num9  = MathUtils.Remainder(num5 - m_subsystemTimeOfDay.TimeOfDay, 1f);
                float num10 = MathUtils.Min(num6, num7, num8, num9);
                if (num6 == num10)
                {
                    m_subsystemTimeOfDay.TimeOfDayOffset += num6;
                    DisplaySmallMessage(LanguageControl.Get(fName, 15), Color.White, blinking: false, playNotificationSound: false);
                }
                else if (num7 == num10)
                {
                    m_subsystemTimeOfDay.TimeOfDayOffset += num7;
                    DisplaySmallMessage(LanguageControl.Get(fName, 16), Color.White, blinking: false, playNotificationSound: false);
                }
                else if (num8 == num10)
                {
                    m_subsystemTimeOfDay.TimeOfDayOffset += num8;
                    DisplaySmallMessage(LanguageControl.Get(fName, 17), Color.White, blinking: false, playNotificationSound: false);
                }
                else if (num9 == num10)
                {
                    m_subsystemTimeOfDay.TimeOfDayOffset += num9;
                    DisplaySmallMessage(LanguageControl.Get(fName, 18), Color.White, blinking: false, playNotificationSound: false);
                }
            }
            if (ModalPanelWidget != null)
            {
                if (input.Cancel || input.Back || m_backButtonWidget.IsClicked)
                {
                    ModalPanelWidget = null;
                }
            }
            else if (input.Back || m_backButtonWidget.IsClicked)
            {
                DialogsManager.ShowDialog(m_componentPlayer.GuiWidget, new GameMenuDialog(m_componentPlayer));
            }
        }