Exemplo n.º 1
0
        public float ApplyArmorProtection(float attackPower)
        {
            float        num  = m_random.UniformFloat(0f, 1f);
            ClothingSlot slot = (num < 0.1f) ? ClothingSlot.Feet : ((num < 0.3f) ? ClothingSlot.Legs : ((num < 0.9f) ? ClothingSlot.Torso : ClothingSlot.Head));
            float        num2 = ((MekClothingBlock)BlocksManager.Blocks[1011]).Durability + 1;
            List <int>   list = new List <int>(GetClothes(slot));

            for (int i = 0; i < list.Count; i++)
            {
                int          value        = list[i];
                MekClothData clothingData = MekClothingBlock.GetClothingData(Terrain.ExtractData(value));
                float        x            = (num2 - (float)BlocksManager.Blocks[1011].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.UniformFloat(-0.3f, 0.3f), m_componentBody.Position, 4f, 0.15f);
                    }
                }
            }
            int num4 = 0;

            while (num4 < list.Count)
            {
                if (Terrain.ExtractContents(list[num4]) != 1011)
                {
                    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));
        }
Exemplo n.º 2
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];
                 MekClothData clothingData = MekClothingBlock.GetClothingData(Terrain.ExtractData(value));
                 if ((float)clothingData.PlayerLevelRequired > m_componentPlayer.PlayerData.Level)
                 {
                     m_componentGui.DisplaySmallMessage(string.Format("Must be level {0} to wear {1}", new object[2]
                     {
                         clothingData.PlayerLevelRequired,
                         clothingData.DisplayName
                     }), 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];
                     MekClothData clothingData2 = MekClothingBlock.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.UniformFloat(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]) != 1011)
                     {
                         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("Your clothing has worn out", blinking: true, playNotificationSound: true);
                     }
                     else
                     {
                         num4++;
                     }
                 }
                 if (flag2)
                 {
                     SetClothes((ClothingSlot)enumValue2, m_clothesList);
                 }
             }
         }
         m_lastTotalElapsedGameTime = m_subsystemGameInfo.TotalElapsedGameTime;
     }
     UpdateRenderTargets();
 }