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)); }
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; } } }
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(); }
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; } } }