Exemple #1
0
        public override string GetDisplayName(SubsystemTerrain subsystemTerrain, int value)
        {
            int          data          = Terrain.ExtractData(value);
            MekClothData clothingData  = GetClothingData(data);
            int          clothingColor = GetClothingColor(data);

            if (clothingColor != 0)
            {
                return(SubsystemPalette.GetName(subsystemTerrain, clothingColor, "染色的 " + clothingData.DisplayName));
            }
            return(clothingData.DisplayName);
        }
Exemple #2
0
        public override void DrawBlock(PrimitivesRenderer3D primitivesRenderer, int value, Color color, float size, ref Matrix matrix, DrawBlockEnvironmentData environmentData)
        {
            int          data          = Terrain.ExtractData(value);
            int          clothingColor = GetClothingColor(data);
            MekClothData clothingData  = GetClothingData(data);
            Matrix       matrix2       = m_slotTransforms[(int)clothingData.Slot] * Matrix.CreateScale(size) * matrix;

            if (clothingData.IsOuter)
            {
                BlocksManager.DrawMeshBlock(primitivesRenderer, m_outerMesh, clothingData.Texture, color * SubsystemPalette.GetFabricColor(environmentData, clothingColor), 1f, ref matrix2, environmentData);
            }
            else
            {
                BlocksManager.DrawMeshBlock(primitivesRenderer, m_innerMesh, clothingData.Texture, color * SubsystemPalette.GetFabricColor(environmentData, clothingColor), 1f, ref matrix2, environmentData);
            }
        }
Exemple #3
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));
        }
Exemple #4
0
 public void UpdateRenderTargets()
 {
     if (m_skinTexture == null || m_componentPlayer.PlayerData.CharacterSkinName != m_skinTextureName)
     {
         m_skinTexture     = CharacterSkinsManager.LoadTexture(m_componentPlayer.PlayerData.CharacterSkinName);
         m_skinTextureName = m_componentPlayer.PlayerData.CharacterSkinName;
         Utilities.Dispose(ref m_innerClothedTexture);
         Utilities.Dispose(ref m_outerClothedTexture);
     }
     if (m_innerClothedTexture == null || m_innerClothedTexture.Width != m_skinTexture.Width || m_innerClothedTexture.Height != m_skinTexture.Height)
     {
         m_innerClothedTexture = new RenderTarget2D(m_skinTexture.Width, m_skinTexture.Height, ColorFormat.Rgba8888, DepthFormat.None);
         m_componentHumanModel.TextureOverride = m_innerClothedTexture;
         m_clothedTexturesValid = false;
     }
     if (m_outerClothedTexture == null || m_outerClothedTexture.Width != m_skinTexture.Width || m_outerClothedTexture.Height != m_skinTexture.Height)
     {
         m_outerClothedTexture = new RenderTarget2D(m_skinTexture.Width, m_skinTexture.Height, ColorFormat.Rgba8888, DepthFormat.None);
         m_componentOuterClothingModel.TextureOverride = m_outerClothedTexture;
         m_clothedTexturesValid = false;
     }
     if (DrawClothedTexture && !m_clothedTexturesValid)
     {
         m_clothedTexturesValid = true;
         Rectangle      scissorRectangle = Display.ScissorRectangle;
         RenderTarget2D renderTarget     = Display.RenderTarget;
         try
         {
             Display.RenderTarget = m_innerClothedTexture;
             Display.Clear(new Vector4(Color.Transparent));
             int             num             = 0;
             TexturedBatch2D texturedBatch2D = m_primitivesRenderer.TexturedBatch(m_skinTexture, useAlphaTest: false, num++, DepthStencilState.None, null, BlendState.NonPremultiplied, SamplerState.PointClamp);
             texturedBatch2D.QueueQuad(Vector2.Zero, new Vector2(m_innerClothedTexture.Width, m_innerClothedTexture.Height), 0f, Vector2.Zero, Vector2.One, Color.White);
             ClothingSlot[] innerSlotsOrder = m_innerSlotsOrder;
             foreach (ClothingSlot slot in innerSlotsOrder)
             {
                 foreach (int clothe in GetClothes(slot))
                 {
                     int          data         = Terrain.ExtractData(clothe);
                     MekClothData clothingData = MekClothingBlock.GetClothingData(data);
                     Color        fabricColor  = SubsystemPalette.GetFabricColor(m_subsystemTerrain, ClothingBlock.GetClothingColor(data));
                     texturedBatch2D = m_primitivesRenderer.TexturedBatch(clothingData.Texture, useAlphaTest: false, num++, DepthStencilState.None, null, BlendState.NonPremultiplied, SamplerState.PointClamp);
                     if (!clothingData.IsOuter)
                     {
                         texturedBatch2D.QueueQuad(new Vector2(0f, 0f), new Vector2(m_innerClothedTexture.Width, m_innerClothedTexture.Height), 0f, Vector2.Zero, Vector2.One, fabricColor);
                     }
                 }
             }
             m_primitivesRenderer.Flush();
             Display.RenderTarget = m_outerClothedTexture;
             Display.Clear(new Vector4(Color.Transparent));
             num             = 0;
             innerSlotsOrder = m_outerSlotsOrder;
             foreach (ClothingSlot slot2 in innerSlotsOrder)
             {
                 foreach (int clothe2 in GetClothes(slot2))
                 {
                     int          data2         = Terrain.ExtractData(clothe2);
                     ClothingData clothingData2 = ClothingBlock.GetClothingData(data2);
                     Color        fabricColor2  = SubsystemPalette.GetFabricColor(m_subsystemTerrain, ClothingBlock.GetClothingColor(data2));
                     texturedBatch2D = m_primitivesRenderer.TexturedBatch(clothingData2.Texture, useAlphaTest: false, num++, DepthStencilState.None, null, BlendState.NonPremultiplied, SamplerState.PointClamp);
                     if (clothingData2.IsOuter)
                     {
                         texturedBatch2D.QueueQuad(new Vector2(0f, 0f), new Vector2(m_outerClothedTexture.Width, m_outerClothedTexture.Height), 0f, Vector2.Zero, Vector2.One, fabricColor2);
                     }
                 }
             }
             m_primitivesRenderer.Flush();
         }
         finally
         {
             Display.RenderTarget     = renderTarget;
             Display.ScissorRectangle = scissorRectangle;
         }
     }
 }
Exemple #5
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();
 }
Exemple #6
0
 public void SetClothes(ClothingSlot slot, IEnumerable <int> clothes)
 {
     if (!m_clothes[slot].SequenceEqual(clothes))
     {
         m_clothes[slot].Clear();
         m_clothes[slot].AddRange(clothes);
         m_clothedTexturesValid = false;
         float num = 0f;
         foreach (KeyValuePair <ClothingSlot, List <int> > clothe in m_clothes)
         {
             foreach (int item in clothe.Value)
             {
                 MekClothData clothingData = MekClothingBlock.GetClothingData(Terrain.ExtractData(item));
                 num += clothingData.DensityModifier;
             }
         }
         float num2 = num - m_densityModifierApplied;
         m_densityModifierApplied += num2;
         m_componentBody.Density  += num2;
         SteedMovementSpeedFactor  = 1f;
         float num3 = 2f;
         float num4 = 0.2f;
         float num5 = 0.4f;
         float num6 = 2f;
         foreach (int clothe2 in GetClothes(ClothingSlot.Head))
         {
             MekClothData clothingData2 = MekClothingBlock.GetClothingData(Terrain.ExtractData(clothe2));
             num3 += clothingData2.Insulation;
             SteedMovementSpeedFactor *= clothingData2.SteedMovementSpeedFactor;
         }
         foreach (int clothe3 in GetClothes(ClothingSlot.Torso))
         {
             MekClothData clothingData3 = MekClothingBlock.GetClothingData(Terrain.ExtractData(clothe3));
             num4 += clothingData3.Insulation;
             SteedMovementSpeedFactor *= clothingData3.SteedMovementSpeedFactor;
         }
         foreach (int clothe4 in GetClothes(ClothingSlot.Legs))
         {
             MekClothData clothingData4 = MekClothingBlock.GetClothingData(Terrain.ExtractData(clothe4));
             num5 += clothingData4.Insulation;
             SteedMovementSpeedFactor *= clothingData4.SteedMovementSpeedFactor;
         }
         foreach (int clothe5 in GetClothes(ClothingSlot.Feet))
         {
             MekClothData clothingData5 = MekClothingBlock.GetClothingData(Terrain.ExtractData(clothe5));
             num6 += clothingData5.Insulation;
             SteedMovementSpeedFactor *= clothingData5.SteedMovementSpeedFactor;
         }
         Insulation = 1f / (1f / num3 + 1f / num4 + 1f / num5 + 1f / num6);
         float num7 = MathUtils.Min(num3, num4, num5, num6);
         if (num3 == num7)
         {
             LeastInsulatedSlot = ClothingSlot.Head;
         }
         else if (num4 == num7)
         {
             LeastInsulatedSlot = ClothingSlot.Torso;
         }
         else if (num5 == num7)
         {
             LeastInsulatedSlot = ClothingSlot.Legs;
         }
         else if (num6 == num7)
         {
             LeastInsulatedSlot = ClothingSlot.Feet;
         }
     }
 }
Exemple #7
0
        public override void Initialize()
        {
            int num = 0;
            Dictionary <int, MekClothData> dictionary = new Dictionary <int, MekClothData>();
            IEnumerator <XElement>         enumerator = XmlUtils.LoadXmlFromStream(ModsManager.GetEntries(".xclo")[0].Stream, Encoding.UTF8, true).Elements().GetEnumerator();

            while (enumerator.MoveNext())
            {
                XElement     current      = enumerator.Current;
                MekClothData clothingData = new MekClothData
                {
                    Index                    = XmlUtils.GetAttributeValue <int>(current, "Index"),
                    DisplayIndex             = num++,
                    DisplayName              = XmlUtils.GetAttributeValue <string>(current, "DisplayName"),
                    Slot                     = XmlUtils.GetAttributeValue <ClothingSlot>(current, "Slot"),
                    ArmorProtection          = XmlUtils.GetAttributeValue <float>(current, "ArmorProtection"),
                    Sturdiness               = XmlUtils.GetAttributeValue <float>(current, "Sturdiness"),
                    Insulation               = XmlUtils.GetAttributeValue <float>(current, "Insulation"),
                    MovementSpeedFactor      = XmlUtils.GetAttributeValue <float>(current, "MovementSpeedFactor"),
                    SteedMovementSpeedFactor = XmlUtils.GetAttributeValue <float>(current, "SteedMovementSpeedFactor"),
                    DensityModifier          = XmlUtils.GetAttributeValue <float>(current, "DensityModifier"),
                    IsOuter                  = XmlUtils.GetAttributeValue <bool>(current, "IsOuter"),
                    CanBeDyed                = XmlUtils.GetAttributeValue <bool>(current, "CanBeDyed"),
                    Layer                    = XmlUtils.GetAttributeValue <int>(current, "Layer"),
                    PlayerLevelRequired      = XmlUtils.GetAttributeValue <int>(current, "PlayerLevelRequired"),
                    Texture                  = ContentManager.Get <Texture2D>(XmlUtils.GetAttributeValue <string>(current, "TextureName")),
                    ImpactSoundsFolder       = XmlUtils.GetAttributeValue <string>(current, "ImpactSoundsFolder"),
                    Description              = XmlUtils.GetAttributeValue <string>(current, "Description")
                };
                dictionary[clothingData.Index] = clothingData;
            }
            clothingData = new MekClothData[dictionary.Count];
            int i = 0;

            foreach (KeyValuePair <int, MekClothData> keyValuePair in dictionary)
            {
                clothingData[i] = keyValuePair.Value;
                ++i;
            }
            Model playerModel = CharacterSkinsManager.GetPlayerModel(PlayerClass.Male);

            Matrix[] array = new Matrix[playerModel.Bones.Count];
            playerModel.CopyAbsoluteBoneTransformsTo(array);
            i = playerModel.FindBone("Hand1").Index;
            int index = playerModel.FindBone("Hand2").Index;

            array[i]     = Matrix.CreateRotationY(0.1f) * array[i];
            array[index] = Matrix.CreateRotationY(-0.1f) * array[index];
            m_innerMesh  = new BlockMesh();
            foreach (ModelMesh mesh in playerModel.Meshes)
            {
                Matrix matrix = array[mesh.ParentBone.Index];
                foreach (ModelMeshPart meshPart in mesh.MeshParts)
                {
                    Color color = Color.White * 0.8f;
                    color.A = byte.MaxValue;
                    m_innerMesh.AppendModelMeshPart(meshPart, matrix, makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White);
                    m_innerMesh.AppendModelMeshPart(meshPart, matrix, makeEmissive: false, flipWindingOrder: true, doubleSided: false, flipNormals: true, color);
                }
            }
            Model outerClothingModel = CharacterSkinsManager.GetOuterClothingModel(PlayerClass.Male);

            Matrix[] array2 = new Matrix[outerClothingModel.Bones.Count];
            outerClothingModel.CopyAbsoluteBoneTransformsTo(array2);
            int index2 = outerClothingModel.FindBone("Leg1").Index;
            int index3 = outerClothingModel.FindBone("Leg2").Index;

            array2[index2] = Matrix.CreateTranslation(-0.02f, 0f, 0f) * array2[index2];
            array2[index3] = Matrix.CreateTranslation(0.02f, 0f, 0f) * array2[index3];
            m_outerMesh    = new BlockMesh();
            foreach (ModelMesh mesh2 in outerClothingModel.Meshes)
            {
                Matrix matrix2 = array2[mesh2.ParentBone.Index];
                foreach (ModelMeshPart meshPart2 in mesh2.MeshParts)
                {
                    Color color2 = Color.White * 0.8f;
                    color2.A = byte.MaxValue;
                    m_outerMesh.AppendModelMeshPart(meshPart2, matrix2, makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White);
                    m_outerMesh.AppendModelMeshPart(meshPart2, matrix2, makeEmissive: false, flipWindingOrder: true, doubleSided: false, flipNormals: true, color2);
                }
            }
        }