Пример #1
0
        public float ApplyArmorProtection(float attackPower)
        {
            float        num  = m_random.Float(0f, 1f);
            ClothingSlot slot = (num < 0.1f) ? ClothingSlot.Feet : ((num < 0.3f) ? ClothingSlot.Legs : ((num < 0.9f) ? ClothingSlot.Torso : ClothingSlot.Head));
            float        num2 = ((ClothingBlock)BlocksManager.Blocks[203]).Durability + 1;
            List <int>   list = new List <int>(GetClothes(slot));

            for (int i = 0; i < list.Count; i++)
            {
                int          value        = list[i];
                ClothingData clothingData = ClothingBlock.GetClothingData(Terrain.ExtractData(value));
                float        x            = (num2 - (float)BlocksManager.Blocks[203].GetDamage(value)) / num2 * clothingData.Sturdiness;
                float        num3         = MathUtils.Min(attackPower * MathUtils.Saturate(clothingData.ArmorProtection), x);
                if (num3 > 0f)
                {
                    attackPower -= num3;
                    if (m_subsystemGameInfo.WorldSettings.GameMode != 0)
                    {
                        float x2          = num3 / clothingData.Sturdiness * num2 + 0.001f;
                        int   damageCount = (int)(MathUtils.Floor(x2) + (float)(m_random.Bool(MathUtils.Remainder(x2, 1f)) ? 1 : 0));
                        list[i] = BlocksManager.DamageItem(value, damageCount);
                    }
                    if (!string.IsNullOrEmpty(clothingData.ImpactSoundsFolder))
                    {
                        m_subsystemAudio.PlayRandomSound(clothingData.ImpactSoundsFolder, 1f, m_random.Float(-0.3f, 0.3f), m_componentBody.Position, 4f, 0.15f);
                    }
                }
            }
            int num4 = 0;

            while (num4 < list.Count)
            {
                if (Terrain.ExtractContents(list[num4]) != 203)
                {
                    list.RemoveAt(num4);
                    m_subsystemParticles.AddParticleSystem(new BlockDebrisParticleSystem(m_subsystemTerrain, m_componentBody.Position + m_componentBody.BoxSize / 2f, 1f, 1f, Color.White, 0));
                }
                else
                {
                    num4++;
                }
            }
            SetClothes(slot, list);
            return(MathUtils.Max(attackPower, 0f));
        }
Пример #2
0
        public void DamageActiveTool(int damageCount)
        {
            if (m_subsystemGameInfo.WorldSettings.GameMode == GameMode.Creative || Inventory == null)
            {
                return;
            }
            int num = BlocksManager.DamageItem(ActiveBlockValue, damageCount);

            if (num != 0)
            {
                int slotCount = Inventory.GetSlotCount(Inventory.ActiveSlotIndex);
                Inventory.RemoveSlotItems(Inventory.ActiveSlotIndex, slotCount);
                if (Inventory.GetSlotCount(Inventory.ActiveSlotIndex) == 0)
                {
                    Inventory.AddSlotItems(Inventory.ActiveSlotIndex, num, slotCount);
                }
            }
            else
            {
                Inventory.RemoveSlotItems(Inventory.ActiveSlotIndex, 1);
            }
        }
Пример #3
0
        protected void Driller(Point3 point, int face)
        {
            Vector3 vector    = CellFace.FaceToVector3(face);
            int     x         = point.X;
            int     y         = point.Y;
            int     z         = point.Z;
            int     slotValue = GetSlotValue(8);

            if (!(ComponentEngine.IsPowered(Utils.Terrain, x, y, z) || Utils.SubsystemGameInfo.WorldSettings.GameMode == 0) || BlocksManager.Blocks[Terrain.ExtractContents(slotValue)].Durability <= 0)
            {
                return;
            }
            int[] array = new[]
            {
                0,
                0,
                1,
                1,
                1,
                0,
                -1,
                -1,
                -1
            }, array2 = new[]
            {
                0,
                -1,
                -1,
                0,
                1,
                1,
                1,
                0,
                -1
            };
            int     num2 = 0;
            Vector3 v    = Vector3.Zero;

            for (int l = 1; l < 19; l++)
            {
                for (int m = 0; m < 9; m++)
                {
                    x = point.X - (int)vector.X * l;
                    y = point.Y - (int)vector.Y * l;
                    z = point.Z - (int)vector.Z * l;
                    if (vector.X != 0f)
                    {
                        y = point.Y + array[m];
                        z = point.Z + array2[m];
                        v = new Vector3(0f, array[m] / (float)l, array2[m] / (float)l);
                    }
                    if (vector.Y != 0f)
                    {
                        x = point.X + array[m];
                        z = point.Z + array2[m];
                        v = new Vector3(array[m] / (float)l, 0f, array2[m] / (float)l);
                    }
                    if (vector.Z != 0f)
                    {
                        x = point.X + array[m];
                        y = point.Y + array2[m];
                        v = new Vector3(array[m] / (float)l, array2[m] / (float)l, 0f);
                    }
                    int   cellValue = Terrain.ReplaceLight(Utils.Terrain.GetCellValue(x, y, z), 0);
                    Block block     = BlocksManager.Blocks[Terrain.ExtractContents(cellValue)];
                    if (num2 == 0 && block.BlockIndex == 92)
                    {
                        num2 = 9;
                    }
                    if (block.IsPlaceable && !block.IsDiggingTransparent && !block.DefaultIsInteractive)
                    {
                        Utils.SubsystemTerrain.ChangeCell(x, y, z, 0, true);
                        Utils.SubsystemProjectiles.FireProjectile(cellValue, new Vector3(x + 0.5f, y + 0.5f, z + 0.5f) - 0.25f * vector, 60f * (vector - v), Vector3.Zero, null);
                        RemoveSlotItems(8, 1);
                        AddSlotItems(8, BlocksManager.DamageItem(slotValue, 1 + num2), 1);
                        return;
                    }
                }
            }
        }
Пример #4
0
        public override CraftingRecipe GetAdHocCraftingRecipe(SubsystemTerrain terrain, string[] ingredients, float heatLevel, float playerLevel)
        {
            if (heatLevel < 1f)
            {
                return(null);
            }
            List <string> list = ingredients.Where((string i) => !string.IsNullOrEmpty(i)).ToList();

            if (list.Count == 2)
            {
                int num  = 0;
                int num2 = 0;
                int num3 = 0;
                foreach (string item in list)
                {
                    CraftingRecipesManager.DecodeIngredient(item, out string craftingId, out int?data);
                    if (craftingId == BlocksManager.Blocks[203].CraftingId)
                    {
                        num3 = Terrain.MakeBlockValue(203, 0, data.HasValue ? data.Value : 0);
                    }
                    else if (craftingId == BlocksManager.Blocks[129].CraftingId)
                    {
                        num = Terrain.MakeBlockValue(129, 0, data.HasValue ? data.Value : 0);
                    }
                    else if (craftingId == BlocksManager.Blocks[128].CraftingId)
                    {
                        num2 = Terrain.MakeBlockValue(128, 0, data.HasValue ? data.Value : 0);
                    }
                }
                if (num != 0 && num3 != 0)
                {
                    int   data2         = Terrain.ExtractData(num3);
                    int   clothingColor = GetClothingColor(data2);
                    int   clothingIndex = GetClothingIndex(data2);
                    bool  canBeDyed     = GetClothingData(data2).CanBeDyed;
                    int   damage        = BlocksManager.Blocks[203].GetDamage(num3);
                    int   color         = PaintBucketBlock.GetColor(Terrain.ExtractData(num));
                    int   damage2       = BlocksManager.Blocks[129].GetDamage(num);
                    Block block         = BlocksManager.Blocks[129];
                    Block block2        = BlocksManager.Blocks[203];
                    if (!canBeDyed)
                    {
                        return(null);
                    }
                    int num4 = PaintBucketBlock.CombineColors(clothingColor, color);
                    if (num4 != clothingColor)
                    {
                        return(new CraftingRecipe
                        {
                            ResultCount = 1,
                            ResultValue = block2.SetDamage(Terrain.MakeBlockValue(203, 0, SetClothingIndex(SetClothingColor(0, num4), clothingIndex)), damage),
                            RemainsCount = 1,
                            RemainsValue = BlocksManager.DamageItem(Terrain.MakeBlockValue(129, 0, color), damage2 + MathUtils.Max(block.Durability / 4, 1)),
                            RequiredHeatLevel = 1f,
                            Description = $"{LanguageControl.Get("BlocksManager", "Dyed")} {SubsystemPalette.GetName(terrain, color, null)}",
                            Ingredients = (string[])ingredients.Clone()
                        });
                    }
                }
                if (num2 != 0 && num3 != 0)
                {
                    int   data3          = Terrain.ExtractData(num3);
                    int   clothingColor2 = GetClothingColor(data3);
                    int   clothingIndex2 = GetClothingIndex(data3);
                    bool  canBeDyed2     = GetClothingData(data3).CanBeDyed;
                    int   damage3        = BlocksManager.Blocks[203].GetDamage(num3);
                    int   damage4        = BlocksManager.Blocks[128].GetDamage(num2);
                    Block block3         = BlocksManager.Blocks[128];
                    Block block4         = BlocksManager.Blocks[203];
                    if (!canBeDyed2)
                    {
                        return(null);
                    }
                    if (clothingColor2 != 0)
                    {
                        return(new CraftingRecipe
                        {
                            ResultCount = 1,
                            ResultValue = block4.SetDamage(Terrain.MakeBlockValue(203, 0, SetClothingIndex(SetClothingColor(0, 0), clothingIndex2)), damage3),
                            RemainsCount = 1,
                            RemainsValue = BlocksManager.DamageItem(Terrain.MakeBlockValue(128, 0, 0), damage4 + MathUtils.Max(block3.Durability / 4, 1)),
                            RequiredHeatLevel = 1f,
                            Description = LanguageControl.Get("BlocksManager", "Not Dyed") + " " + LanguageControl.Get("BlocksManager", "Clothes"),
                            Ingredients = (string[])ingredients.Clone()
                        });
                    }
                }
            }
            return(null);
        }
Пример #5
0
        public override CraftingRecipe GetAdHocCraftingRecipe(SubsystemTerrain subsystemTerrain, string[] ingredients, float heatLevel, float playerLevel)
        {
            if (heatLevel < 1f)
            {
                return(null);
            }
            List <string> list = ingredients.Where((string i) => !string.IsNullOrEmpty(i)).ToList();

            if (list.Count == 2)
            {
                int num  = 0;
                int num2 = 0;
                int num3 = 0;
                foreach (string item in list)
                {
                    CraftingRecipesManager.DecodeIngredient(item, out string craftingId, out int?data);
                    if (craftingId == BlocksManager.Blocks[208].CraftingId)
                    {
                        num3 = Terrain.MakeBlockValue(208, 0, data.HasValue ? data.Value : 0);
                    }
                    else if (craftingId == BlocksManager.Blocks[129].CraftingId)
                    {
                        num = Terrain.MakeBlockValue(129, 0, data.HasValue ? data.Value : 0);
                    }
                    else if (craftingId == BlocksManager.Blocks[128].CraftingId)
                    {
                        num2 = Terrain.MakeBlockValue(128, 0, data.HasValue ? data.Value : 0);
                    }
                }
                if (num != 0 && num3 != 0)
                {
                    int   num4   = Terrain.ExtractData(num3);
                    int   color  = PaintBucketBlock.GetColor(Terrain.ExtractData(num));
                    int   damage = BlocksManager.Blocks[129].GetDamage(num);
                    Block block  = BlocksManager.Blocks[129];
                    int   num5   = PaintBucketBlock.CombineColors(num4, color);
                    if (num5 != num4)
                    {
                        return(new CraftingRecipe
                        {
                            ResultCount = 1,
                            ResultValue = Terrain.MakeBlockValue(208, 0, num5),
                            RemainsCount = 1,
                            RemainsValue = BlocksManager.DamageItem(Terrain.MakeBlockValue(129, 0, color), damage + MathUtils.Max(block.Durability / 4, 1)),
                            RequiredHeatLevel = 1f,
                            Description = $"Dye carpet {SubsystemPalette.GetName(subsystemTerrain, color, null)}",
                            Ingredients = (string[])ingredients.Clone()
                        });
                    }
                }
                if (num2 != 0 && num3 != 0)
                {
                    int   num6    = Terrain.ExtractData(num3);
                    int   damage2 = BlocksManager.Blocks[128].GetDamage(num2);
                    Block block2  = BlocksManager.Blocks[128];
                    if (num6 != 0)
                    {
                        return(new CraftingRecipe
                        {
                            ResultCount = 1,
                            ResultValue = Terrain.MakeBlockValue(208, 0, 0),
                            RemainsCount = 1,
                            RemainsValue = BlocksManager.DamageItem(Terrain.MakeBlockValue(128, 0, 0), damage2 + MathUtils.Max(block2.Durability / 4, 1)),
                            RequiredHeatLevel = 1f,
                            Description = "Undye carpet",
                            Ingredients = (string[])ingredients.Clone()
                        });
                    }
                }
            }
            return(null);
        }
Пример #6
0
        protected new void Driller(Point3 point, int face)
        {
            Vector3 vector = Vector3.UnitY;
            int     x      = point.X;
            int     y      = point.Y;
            int     z      = point.Z;
            int     num    = ComponentEngine.IsPowered(Utils.Terrain, x, y, z) ? 1 : 0;

            if (num != 0)
            {
                int num2 = 0;
                int l;
                for (l = 4; 3 < l && l < 8; l++)
                {
                    num2 += GetSlotCount(l);
                }
                int num3 = 0;
                int num4 = 0;
                for (int m = 0; m < 4; m++)
                {
                    if (GetSlotCount(l) == 0)
                    {
                        num3 = 0;
                        num4 = 1;
                        break;
                    }
                    num4 += BlocksManager.Blocks[Terrain.ExtractContents(GetSlotValue(m))].MaxStacking;
                    num3 += GetSlotCount(m);
                }
                int slotValue = base.GetSlotValue(8);
                if (num2 != 0 && num4 > num3 && slotValue != 0 && BlocksManager.Blocks[Terrain.ExtractContents(slotValue)].Durability > 0)
                {
                    int[] array = new int[25]
                    {
                        0,
                        0,
                        1,
                        1,
                        1,
                        0,
                        -1,
                        -1,
                        -1,
                        -1,
                        0,
                        1,
                        2,
                        2,
                        2,
                        2,
                        2,
                        1,
                        0,
                        -1,
                        -2,
                        -2,
                        -2,
                        -2,
                        -2
                    };
                    int[] array2 = new int[25]
                    {
                        0,
                        -1,
                        -1,
                        0,
                        1,
                        1,
                        1,
                        0,
                        -1,
                        -2,
                        -2,
                        -2,
                        -2,
                        -1,
                        0,
                        1,
                        2,
                        2,
                        2,
                        2,
                        2,
                        1,
                        0,
                        -1,
                        -2
                    };
                    for (int n = 1; n < 8; n++)
                    {
                        for (int num5 = 0; num5 < 25; num5++)
                        {
                            x = point.X - (int)vector.X * n;
                            y = point.Y - (int)vector.Y * n;
                            z = point.Z - (int)vector.Z * n;
                            x = point.X + array[num5];
                            z = point.Z + array2[num5];
                            //new Vector3((float)array[num5] / (float)n, 0f, (float)array2[num5] / (float)n);
                            int cellValue = Utils.Terrain.GetCellValue(x, y, z);
                            var block     = Terrain.ExtractContents(cellValue);
                            if (block == 92 || block == 18 || block == RottenMeatBlock.Index)
                            {
                                int num6;
                                for (num6 = 4; 3 < num6 && num6 < 8 && GetSlotCount(num6) == 0; num6++)
                                {
                                }
                                int num7 = 0;
                                while (true)
                                {
                                    if (num7 >= 4)
                                    {
                                        return;
                                    }
                                    if (GetSlotCount(num7) < BlocksManager.Blocks[Terrain.ExtractContents(GetSlotValue(num7))].MaxStacking || GetSlotCount(num7) == 0)
                                    {
                                        if (block == 92 && (Terrain.ExtractContents(GetSlotValue(num7)) == 93 || GetSlotCount(num7) == 0))
                                        {
                                            if (FluidBlock.GetLevel(Terrain.ExtractData(cellValue)) == 0)
                                            {
                                                RemoveSlotItems(num6, 1);
                                                AddSlotItems(num7, 93, 1);
                                                RemoveSlotItems(8, 1);
                                                AddSlotItems(8, BlocksManager.DamageItem(slotValue, 1), 1);
                                            }
                                            Utils.SubsystemTerrain.ChangeCell(x, y, z, 0);
                                            return;
                                        }
                                        if (block == 18 && (Terrain.ExtractContents(GetSlotValue(num7)) == 91 || GetSlotCount(num7) == 0))
                                        {
                                            if (FluidBlock.GetLevel(Terrain.ExtractData(cellValue)) == 0)
                                            {
                                                RemoveSlotItems(num6, 1);
                                                AddSlotItems(num7, 91, 1);
                                            }
                                            Utils.SubsystemTerrain.ChangeCell(x, y, z, 0);
                                            return;
                                        }
                                        if (Terrain.ReplaceLight(cellValue, 0) == (RottenMeatBlock.Index | 1 << 4 << 14) && (Terrain.ReplaceLight(GetSlotValue(num7), 0) == (RottenMeatBlock.Index | 2 << 4 << 14) || GetSlotCount(num7) == 0))
                                        {
                                            RemoveSlotItems(num6, 1);
                                            AddSlotItems(num7, RottenMeatBlock.Index | 2 << 4 << 14, 1);
                                            Utils.SubsystemTerrain.ChangeCell(x, y, z, 0);
                                            return;
                                        }
                                    }
                                    num7++;
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #7
0
        public static CraftingRecipe GetAdHocCraftingRecipe(int index, SubsystemTerrain subsystemTerrain, string[] ingredients, float heatLevel)
        {
            if (heatLevel < 1f)
            {
                return(null);
            }
            int i = 0, num = 0;
            var array = new string[2];

            for (; i < ingredients.Length; i++)
            {
                if (!string.IsNullOrEmpty(ingredients[i]))
                {
                    if (num > 1)
                    {
                        return(null);
                    }
                    array[num] = ingredients[i];
                    num++;
                }
            }
            if (num != 2)
            {
                return(null);
            }
            num = 0;
            int num2 = 0;
            int num3 = 0;

            for (i = 0; i < array.Length; i++)
            {
                string item = array[i];
                CraftingRecipesManager.DecodeIngredient(item, out string craftingId, out int?data);
                int d = data ?? 0;
                if (craftingId == BlocksManager.Blocks[index].CraftingId)
                {
                    num3 = Terrain.MakeBlockValue(index, 0, d);
                }
                else if (craftingId == BlocksManager.Blocks[129].CraftingId)
                {
                    num = Terrain.MakeBlockValue(129, 0, d);
                }
                else if (craftingId == BlocksManager.Blocks[128].CraftingId)
                {
                    num2 = Terrain.MakeBlockValue(128, 0, d);
                }
            }
            if (num != 0 && num3 != 0)
            {
                int num4  = GetColor(Terrain.ExtractData(num3));
                int color = PaintBucketBlock.GetColor(Terrain.ExtractData(num));
                int num5  = PaintBucketBlock.CombineColors(num4, color);
                if (num5 != num4)
                {
                    return(new CraftingRecipe
                    {
                        ResultCount = 1,
                        ResultValue = Terrain.MakeBlockValue(index, 0, SetColor(Terrain.ExtractData(num3), num5)),
                        RemainsCount = 1,
                        RemainsValue = BlocksManager.DamageItem(Terrain.MakeBlockValue(129, 0, color), BlocksManager.Blocks[129].GetDamage(num) + 1),
                        RequiredHeatLevel = 1f,
                        Description = "Dye tool " + SubsystemPalette.GetName(subsystemTerrain, color, null),
                        Ingredients = (string[])ingredients.Clone()
                    });
                }
            }
            if (num2 != 0 && num3 != 0)
            {
                if (GetColor(num3) != 0)
                {
                    return(new CraftingRecipe
                    {
                        ResultCount = 1,
                        ResultValue = Terrain.MakeBlockValue(index, 0, SetColor(Terrain.ExtractData(num3), 0)),
                        RemainsCount = 1,
                        RemainsValue = BlocksManager.DamageItem(128, BlocksManager.Blocks[128].GetDamage(num2) + 1),
                        RequiredHeatLevel = 1f,
                        Description = "Undye tool",
                        Ingredients = (string[])ingredients.Clone()
                    });
                }
            }
            return(null);
        }
        public void Update(float dt)
        {
            double totalElapsedGameTime = m_subsystemGameInfo.TotalElapsedGameTime;

            foreach (Projectile projectile in m_projectiles)
            {
                if (projectile.ToRemove)
                {
                    m_projectilesToRemove.Add(projectile);
                }
                else
                {
                    Block block = BlocksManager.Blocks[Terrain.ExtractContents(projectile.Value)];
                    if (totalElapsedGameTime - projectile.CreationTime > 40.0)
                    {
                        projectile.ToRemove = true;
                    }
                    TerrainChunk chunkAtCell = m_subsystemTerrain.Terrain.GetChunkAtCell(Terrain.ToCell(projectile.Position.X), Terrain.ToCell(projectile.Position.Z));
                    if (chunkAtCell == null || chunkAtCell.State <= TerrainChunkState.InvalidContents4)
                    {
                        projectile.NoChunk = true;
                        if (projectile.TrailParticleSystem != null)
                        {
                            projectile.TrailParticleSystem.IsStopped = true;
                        }
                    }
                    else
                    {
                        projectile.NoChunk = false;
                        Vector3              position             = projectile.Position;
                        Vector3              vector               = position + projectile.Velocity * dt;
                        Vector3              v                    = block.ProjectileTipOffset * Vector3.Normalize(projectile.Velocity);
                        BodyRaycastResult?   bodyRaycastResult    = m_subsystemBodies.Raycast(position + v, vector + v, 0.2f, (ComponentBody body, float distance) => true);
                        TerrainRaycastResult?terrainRaycastResult = m_subsystemTerrain.Raycast(position + v, vector + v, useInteractionBoxes: false, skipAirBlocks: true, (int value, float distance) => BlocksManager.Blocks[Terrain.ExtractContents(value)].IsCollidable);
                        bool flag = block.DisintegratesOnHit;
                        if (terrainRaycastResult.HasValue || bodyRaycastResult.HasValue)
                        {
                            CellFace?                cellFace       = terrainRaycastResult.HasValue ? new CellFace?(terrainRaycastResult.Value.CellFace) : null;
                            ComponentBody            componentBody  = bodyRaycastResult.HasValue ? bodyRaycastResult.Value.ComponentBody : null;
                            SubsystemBlockBehavior[] blockBehaviors = m_subsystemBlockBehaviors.GetBlockBehaviors(Terrain.ExtractContents(projectile.Value));
                            for (int i = 0; i < blockBehaviors.Length; i++)
                            {
                                flag |= blockBehaviors[i].OnHitAsProjectile(cellFace, componentBody, projectile);
                            }
                            projectile.ToRemove |= flag;
                        }
                        Vector3?vector2 = null;
                        if (bodyRaycastResult.HasValue && (!terrainRaycastResult.HasValue || bodyRaycastResult.Value.Distance < terrainRaycastResult.Value.Distance))
                        {
                            if (projectile.Velocity.Length() > 10f)
                            {
                                ComponentMiner.AttackBody(bodyRaycastResult.Value.ComponentBody, projectile.Owner, bodyRaycastResult.Value.HitPoint(), Vector3.Normalize(projectile.Velocity), block.GetProjectilePower(projectile.Value), isMeleeAttack: false);
                                if (projectile.Owner != null && projectile.Owner.PlayerStats != null)
                                {
                                    projectile.Owner.PlayerStats.RangedHits++;
                                }
                            }
                            if (projectile.IsIncendiary)
                            {
                                bodyRaycastResult.Value.ComponentBody.Entity.FindComponent <ComponentOnFire>()?.SetOnFire(projectile?.Owner, m_random.Float(6f, 8f));
                            }
                            vector = position;
                            projectile.Velocity        *= -0.05f;
                            projectile.Velocity        += m_random.Vector3(0.33f * projectile.Velocity.Length());
                            projectile.AngularVelocity *= -0.05f;
                        }
                        else if (terrainRaycastResult.HasValue)
                        {
                            CellFace cellFace2 = terrainRaycastResult.Value.CellFace;
                            int      cellValue = m_subsystemTerrain.Terrain.GetCellValue(cellFace2.X, cellFace2.Y, cellFace2.Z);
                            int      num       = Terrain.ExtractContents(cellValue);
                            Block    block2    = BlocksManager.Blocks[num];
                            float    num2      = projectile.Velocity.Length();
                            SubsystemBlockBehavior[] blockBehaviors2 = m_subsystemBlockBehaviors.GetBlockBehaviors(num);
                            for (int j = 0; j < blockBehaviors2.Length; j++)
                            {
                                blockBehaviors2[j].OnHitByProjectile(cellFace2, projectile);
                            }
                            if (num2 > 10f && m_random.Float(0f, 1f) > block2.ProjectileResilience)
                            {
                                m_subsystemTerrain.DestroyCell(0, cellFace2.X, cellFace2.Y, cellFace2.Z, 0, noDrop: true, noParticleSystem: false);
                                m_subsystemSoundMaterials.PlayImpactSound(cellValue, position, 1f);
                            }
                            if (projectile.IsIncendiary)
                            {
                                m_subsystemFireBlockBehavior.SetCellOnFire(terrainRaycastResult.Value.CellFace.X, terrainRaycastResult.Value.CellFace.Y, terrainRaycastResult.Value.CellFace.Z, 1f);
                                Vector3 vector3 = projectile.Position - 0.75f * Vector3.Normalize(projectile.Velocity);
                                for (int k = 0; k < 8; k++)
                                {
                                    Vector3 v2 = (k == 0) ? Vector3.Normalize(projectile.Velocity) : m_random.Vector3(1.5f);
                                    TerrainRaycastResult?terrainRaycastResult2 = m_subsystemTerrain.Raycast(vector3, vector3 + v2, useInteractionBoxes: false, skipAirBlocks: true, (int value, float distance) => true);
                                    if (terrainRaycastResult2.HasValue)
                                    {
                                        m_subsystemFireBlockBehavior.SetCellOnFire(terrainRaycastResult2.Value.CellFace.X, terrainRaycastResult2.Value.CellFace.Y, terrainRaycastResult2.Value.CellFace.Z, 1f);
                                    }
                                }
                            }
                            if (num2 > 5f)
                            {
                                m_subsystemSoundMaterials.PlayImpactSound(cellValue, position, 1f);
                            }
                            if (block.IsStickable && num2 > 10f && m_random.Bool(block2.ProjectileStickProbability))
                            {
                                Vector3 v3 = Vector3.Normalize(projectile.Velocity);
                                float   s  = MathUtils.Lerp(0.1f, 0.2f, MathUtils.Saturate((num2 - 15f) / 20f));
                                vector2 = position + terrainRaycastResult.Value.Distance * Vector3.Normalize(projectile.Velocity) + v3 * s;
                            }
                            else
                            {
                                Plane plane = cellFace2.CalculatePlane();
                                vector = position;
                                if (plane.Normal.X != 0f)
                                {
                                    projectile.Velocity *= new Vector3(-0.3f, 0.3f, 0.3f);
                                }
                                if (plane.Normal.Y != 0f)
                                {
                                    projectile.Velocity *= new Vector3(0.3f, -0.3f, 0.3f);
                                }
                                if (plane.Normal.Z != 0f)
                                {
                                    projectile.Velocity *= new Vector3(0.3f, 0.3f, -0.3f);
                                }
                                float num3 = projectile.Velocity.Length();
                                projectile.Velocity         = num3 * Vector3.Normalize(projectile.Velocity + m_random.Vector3(num3 / 6f, num3 / 3f));
                                projectile.AngularVelocity *= -0.3f;
                            }
                            MakeProjectileNoise(projectile);
                        }
                        if (terrainRaycastResult.HasValue || bodyRaycastResult.HasValue)
                        {
                            if (flag)
                            {
                                m_subsystemParticles.AddParticleSystem(block.CreateDebrisParticleSystem(m_subsystemTerrain, projectile.Position, projectile.Value, 1f));
                            }
                            else if (!projectile.ToRemove && (vector2.HasValue || projectile.Velocity.Length() < 1f))
                            {
                                if (projectile.ProjectileStoppedAction == ProjectileStoppedAction.TurnIntoPickable)
                                {
                                    int num4 = BlocksManager.DamageItem(projectile.Value, 1);
                                    if (num4 != 0)
                                    {
                                        if (vector2.HasValue)
                                        {
                                            CalculateVelocityAlignMatrix(block, vector2.Value, projectile.Velocity, out Matrix matrix);
                                            m_subsystemPickables.AddPickable(num4, 1, projectile.Position, Vector3.Zero, matrix);
                                        }
                                        else
                                        {
                                            m_subsystemPickables.AddPickable(num4, 1, position, Vector3.Zero, null);
                                        }
                                    }
                                    projectile.ToRemove = true;
                                }
                                else if (projectile.ProjectileStoppedAction == ProjectileStoppedAction.Disappear)
                                {
                                    projectile.ToRemove = true;
                                }
                            }
                        }
                        float num5 = projectile.IsInWater ? MathUtils.Pow(0.001f, dt) : MathUtils.Pow(block.ProjectileDamping, dt);
                        projectile.Velocity.Y      += -10f * dt;
                        projectile.Velocity        *= num5;
                        projectile.AngularVelocity *= num5;
                        projectile.Position         = vector;
                        projectile.Rotation        += projectile.AngularVelocity * dt;
                        if (projectile.TrailParticleSystem != null)
                        {
                            if (!m_subsystemParticles.ContainsParticleSystem((ParticleSystemBase)projectile.TrailParticleSystem))
                            {
                                m_subsystemParticles.AddParticleSystem((ParticleSystemBase)projectile.TrailParticleSystem);
                            }
                            Vector3 v4 = (projectile.TrailOffset != Vector3.Zero) ? Vector3.TransformNormal(projectile.TrailOffset, Matrix.CreateFromAxisAngle(Vector3.Normalize(projectile.Rotation), projectile.Rotation.Length())) : Vector3.Zero;
                            projectile.TrailParticleSystem.Position = projectile.Position + v4;
                            if (projectile.IsInWater)
                            {
                                projectile.TrailParticleSystem.IsStopped = true;
                            }
                        }
                        bool flag2 = IsWater(projectile.Position);
                        if (projectile.IsInWater != flag2)
                        {
                            if (flag2)
                            {
                                float num6 = new Vector2(projectile.Velocity.X + projectile.Velocity.Z).Length();
                                if (num6 > 6f && num6 > 4f * MathUtils.Abs(projectile.Velocity.Y))
                                {
                                    projectile.Velocity   *= 0.5f;
                                    projectile.Velocity.Y *= -1f;
                                    flag2 = false;
                                }
                                else
                                {
                                    projectile.Velocity *= 0.2f;
                                }
                                float?surfaceHeight = m_subsystemFluidBlockBehavior.GetSurfaceHeight(Terrain.ToCell(projectile.Position.X), Terrain.ToCell(projectile.Position.Y), Terrain.ToCell(projectile.Position.Z));
                                if (surfaceHeight.HasValue)
                                {
                                    m_subsystemParticles.AddParticleSystem(new WaterSplashParticleSystem(m_subsystemTerrain, new Vector3(projectile.Position.X, surfaceHeight.Value, projectile.Position.Z), large: false));
                                    m_subsystemAudio.PlayRandomSound("Audio/Splashes", 1f, m_random.Float(-0.2f, 0.2f), projectile.Position, 6f, autoDelay: true);
                                    MakeProjectileNoise(projectile);
                                }
                            }
                            projectile.IsInWater = flag2;
                        }
                        if (IsMagma(projectile.Position))
                        {
                            m_subsystemParticles.AddParticleSystem(new MagmaSplashParticleSystem(m_subsystemTerrain, projectile.Position, large: false));
                            m_subsystemAudio.PlayRandomSound("Audio/Sizzles", 1f, m_random.Float(-0.2f, 0.2f), projectile.Position, 3f, autoDelay: true);
                            projectile.ToRemove = true;
                            m_subsystemExplosions.TryExplodeBlock(Terrain.ToCell(projectile.Position.X), Terrain.ToCell(projectile.Position.Y), Terrain.ToCell(projectile.Position.Z), projectile.Value);
                        }
                        if (m_subsystemTime.PeriodicGameTimeEvent(1.0, (double)(projectile.GetHashCode() % 100) / 100.0) && (m_subsystemFireBlockBehavior.IsCellOnFire(Terrain.ToCell(projectile.Position.X), Terrain.ToCell(projectile.Position.Y + 0.1f), Terrain.ToCell(projectile.Position.Z)) || m_subsystemFireBlockBehavior.IsCellOnFire(Terrain.ToCell(projectile.Position.X), Terrain.ToCell(projectile.Position.Y + 0.1f) - 1, Terrain.ToCell(projectile.Position.Z))))
                        {
                            m_subsystemAudio.PlayRandomSound("Audio/Sizzles", 1f, m_random.Float(-0.2f, 0.2f), projectile.Position, 3f, autoDelay: true);
                            projectile.ToRemove = true;
                            m_subsystemExplosions.TryExplodeBlock(Terrain.ToCell(projectile.Position.X), Terrain.ToCell(projectile.Position.Y), Terrain.ToCell(projectile.Position.Z), projectile.Value);
                        }
                    }
                }
            }
            foreach (Projectile item in m_projectilesToRemove)
            {
                if (item.TrailParticleSystem != null)
                {
                    item.TrailParticleSystem.IsStopped = true;
                }
                m_projectiles.Remove(item);
                if (this.ProjectileRemoved != null)
                {
                    this.ProjectileRemoved(item);
                }
            }
            m_projectilesToRemove.Clear();
        }
Пример #9
0
 public void Update(float dt)
 {
     if (m_subsystemGameInfo.WorldSettings.GameMode != 0 && m_subsystemGameInfo.WorldSettings.AreAdventureSurvivalMechanicsEnabled && m_subsystemTime.PeriodicGameTimeEvent(0.5, 0.0))
     {
         foreach (int enumValue in EnumUtils.GetEnumValues(typeof(ClothingSlot)))
         {
             bool flag = false;
             m_clothesList.Clear();
             m_clothesList.AddRange(GetClothes((ClothingSlot)enumValue));
             int num = 0;
             while (num < m_clothesList.Count)
             {
                 int          value        = m_clothesList[num];
                 ClothingData clothingData = ClothingBlock.GetClothingData(Terrain.ExtractData(value));
                 if ((float)clothingData.PlayerLevelRequired > m_componentPlayer.PlayerData.Level)
                 {
                     m_componentGui.DisplaySmallMessage(string.Format(LanguageControl.Get(fName, 1), clothingData.PlayerLevelRequired, clothingData.DisplayName), Color.White, blinking: true, playNotificationSound: true);
                     m_subsystemPickables.AddPickable(value, 1, m_componentBody.Position, null, null);
                     m_clothesList.RemoveAt(num);
                     flag = true;
                 }
                 else
                 {
                     num++;
                 }
             }
             if (flag)
             {
                 SetClothes((ClothingSlot)enumValue, m_clothesList);
             }
         }
     }
     if (m_subsystemGameInfo.WorldSettings.GameMode != 0 && m_subsystemGameInfo.WorldSettings.AreAdventureSurvivalMechanicsEnabled && m_subsystemTime.PeriodicGameTimeEvent(2.0, 0.0) && ((m_componentLocomotion.LastWalkOrder.HasValue && m_componentLocomotion.LastWalkOrder.Value != Vector2.Zero) || (m_componentLocomotion.LastSwimOrder.HasValue && m_componentLocomotion.LastSwimOrder.Value != Vector3.Zero) || m_componentLocomotion.LastJumpOrder != 0f))
     {
         if (m_lastTotalElapsedGameTime.HasValue)
         {
             foreach (int enumValue2 in EnumUtils.GetEnumValues(typeof(ClothingSlot)))
             {
                 bool flag2 = false;
                 m_clothesList.Clear();
                 m_clothesList.AddRange(GetClothes((ClothingSlot)enumValue2));
                 for (int i = 0; i < m_clothesList.Count; i++)
                 {
                     int          value2        = m_clothesList[i];
                     ClothingData clothingData2 = ClothingBlock.GetClothingData(Terrain.ExtractData(value2));
                     float        num2          = (m_componentVitalStats.Wetness > 0f) ? (10f * clothingData2.Sturdiness) : (20f * clothingData2.Sturdiness);
                     double       num3          = MathUtils.Floor(m_lastTotalElapsedGameTime.Value / (double)num2);
                     if (MathUtils.Floor(m_subsystemGameInfo.TotalElapsedGameTime / (double)num2) > num3 && m_random.Float(0f, 1f) < 0.75f)
                     {
                         m_clothesList[i] = BlocksManager.DamageItem(value2, 1);
                         flag2            = true;
                     }
                 }
                 int num4 = 0;
                 while (num4 < m_clothesList.Count)
                 {
                     if (Terrain.ExtractContents(m_clothesList[num4]) != 203)
                     {
                         m_clothesList.RemoveAt(num4);
                         m_subsystemParticles.AddParticleSystem(new BlockDebrisParticleSystem(m_subsystemTerrain, m_componentBody.Position + m_componentBody.BoxSize / 2f, 1f, 1f, Color.White, 0));
                         m_componentGui.DisplaySmallMessage(LanguageControl.Get(fName, 2), Color.White, blinking: true, playNotificationSound: true);
                     }
                     else
                     {
                         num4++;
                     }
                 }
                 if (flag2)
                 {
                     SetClothes((ClothingSlot)enumValue2, m_clothesList);
                 }
             }
         }
         m_lastTotalElapsedGameTime = m_subsystemGameInfo.TotalElapsedGameTime;
     }
     UpdateRenderTargets();
 }