Leather gloves and an LED tube light. (#187)

Added BurnTemperature to bulbs.
Added HeatResistance to clothing and species.
Added HeatResistanceComponent which resolves armor vs skin.
Made the hand burn on lamps only happen when heat resistance is too poor.
This commit is contained in:
PrPleGoo
2019-04-06 17:11:51 +02:00
committed by Pieter-Jan Briers
parent 9f1dd9f876
commit 77753debeb
23 changed files with 312 additions and 44 deletions

View File

@@ -78,7 +78,17 @@ namespace Content.Server.GameObjects
/// <returns>Null if the slot is empty, otherwise the item.</returns>
public ItemComponent GetSlotItem(Slots slot)
{
return SlotContainers[slot].ContainedEntity?.GetComponent<ItemComponent>();
return GetSlotItem<ItemComponent>(slot);
}
public T GetSlotItem<T>(Slots slot) where T : ItemComponent
{
return SlotContainers[slot].ContainedEntity?.GetComponent<T>();
}
public bool TryGetSlotItem<T>(Slots slot, out T itemComponent) where T : ItemComponent
{
itemComponent = GetSlotItem<T>(slot);
return itemComponent != null;
}
/// <summary>

View File

@@ -1,9 +1,6 @@
using SS14.Shared.Serialization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static Content.Shared.GameObjects.Components.Inventory.EquipmentSlotDefines;
namespace Content.Server.GameObjects
@@ -13,6 +10,9 @@ namespace Content.Server.GameObjects
public override string Name => "Clothing";
public SlotFlags SlotFlags = SlotFlags.PREVENTEQUIP; //Different from None, NONE allows equips if no slot flags are required
private int _heatResistance;
public int HeatResistance => _heatResistance;
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
@@ -25,6 +25,8 @@ namespace Content.Server.GameObjects
SlotFlags |= (SlotFlags)Enum.Parse(typeof(SlotFlags), slotflagsloaded.ToUpper());
}
});
serializer.DataFieldCached(ref _heatResistance, "HeatResistance", 323);
}
}
}

View File

@@ -0,0 +1,21 @@
using System;
using SS14.Shared.GameObjects;
using Content.Shared.GameObjects.Components.Inventory;
namespace Content.Server.GameObjects
{
public class HeatResistanceComponent : Component
{
public override string Name => "HeatResistance";
public int GetHeatResistance()
{
if (Owner.GetComponent<InventoryComponent>().TryGetSlotItem(EquipmentSlotDefines.Slots.GLOVES, itemComponent: out ClothingComponent gloves)
| Owner.TryGetComponent(out SpeciesComponent speciesComponent))
{
return Math.Max(gloves?.HeatResistance ?? int.MinValue, speciesComponent?.HeatResistance ?? int.MinValue);
}
return int.MinValue;
}
}
}

View File

@@ -34,6 +34,9 @@ namespace Content.Server.GameObjects
/// </summary>
private string templatename;
private int _heatResistance;
public int HeatResistance => _heatResistance;
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
@@ -43,6 +46,7 @@ namespace Content.Server.GameObjects
Type type = AppDomain.CurrentDomain.GetAssemblyByName("Content.Server")
.GetType("Content.Server.GameObjects." + templatename);
DamageTemplate = (DamageTemplates) Activator.CreateInstance(type);
serializer.DataFieldCached(ref _heatResistance, "HeatResistance", 323);
}
public override void HandleMessage(ComponentMessage message, INetChannel netChannel = null,

View File

@@ -1,4 +1,4 @@
using System;
using System;
using SS14.Shared.GameObjects;
using SS14.Shared.Maths;
using SS14.Shared.Serialization;
@@ -49,6 +49,12 @@ namespace Content.Server.GameObjects.Components.Power
public LightBulbType Type = LightBulbType.Tube;
private int _burningTemperature;
public int BurningTemperature => _burningTemperature;
private float _powerUse;
public float PowerUse => _powerUse;
/// <summary>
/// The current state of the light bulb. Invokes the OnLightBulbStateChange event when set.
/// It also updates the bulb's sprite accordingly.
@@ -82,6 +88,8 @@ namespace Content.Server.GameObjects.Components.Power
{
serializer.DataField(ref Type, "bulb", LightBulbType.Tube);
serializer.DataField(ref _color, "color", Color.White);
serializer.DataFieldCached(ref _burningTemperature, "BurningTemperature", 1400);
serializer.DataFieldCached(ref _powerUse, "PowerUse", 40);
}
public void UpdateColor()

View File

@@ -1,20 +1,15 @@
using System;
using Content.Server.GameObjects.Components.Sound;
using Content.Server.GameObjects.EntitySystems;
using Content.Server.Interfaces.GameObjects;
using Content.Shared.GameObjects;
using Content.Shared.GameObjects.Components.Inventory;
using SS14.Server.GameObjects;
using SS14.Server.GameObjects.Components.Container;
using SS14.Server.GameObjects.EntitySystems;
using SS14.Shared.Audio;
using SS14.Shared.Enums;
using SS14.Shared.GameObjects;
using SS14.Shared.Interfaces.GameObjects;
using SS14.Shared.Interfaces.Timing;
using SS14.Shared.IoC;
using SS14.Shared.Log;
using SS14.Shared.Map;
using SS14.Shared.Serialization;
using SS14.Shared.ViewVariables;
@@ -33,8 +28,6 @@ namespace Content.Server.GameObjects.Components.Power
private LightBulbType BulbType = LightBulbType.Tube;
[ViewVariables] private float Load = 40;
[ViewVariables] private ContainerSlot _lightBulbContainer;
[ViewVariables]
@@ -50,23 +43,44 @@ namespace Content.Server.GameObjects.Components.Power
}
}
bool IAttackBy.AttackBy(AttackByEventArgs eventArgs)
public bool AttackBy(AttackByEventArgs eventArgs)
{
return InsertBulb(eventArgs.AttackWith);
}
bool IAttackHand.AttackHand(AttackHandEventArgs eventArgs)
public bool AttackHand(AttackHandEventArgs eventArgs)
{
if (eventArgs.User.GetComponent<InventoryComponent>().GetSlotItem(EquipmentSlotDefines.Slots.GLOVES) != null)
if (!eventArgs.User.TryGetComponent(out DamageableComponent damageableComponent))
{
Eject();
return false;
}
if(eventArgs.User.TryGetComponent(out HeatResistanceComponent heatResistanceComponent))
{
if(CanBurn(heatResistanceComponent.GetHeatResistance()))
{
Burn();
return true;
}
}
Eject();
return true;
bool CanBurn(int heatResistance)
{
return _lightState == LightState.On && heatResistance < LightBulb.BurningTemperature;
}
void Burn()
{
damageableComponent.TakeDamage(DamageType.Heat, 20);
}
void Eject()
{
EjectBulb(eventArgs.User);
UpdateLight();
return true;
}
if (!eventArgs.User.TryGetComponent(out DamageableComponent damageableComponent)) return false;
damageableComponent.TakeDamage(DamageType.Heat, 20);
return true;
}
/// <summary>
@@ -110,7 +124,6 @@ namespace Content.Server.GameObjects.Components.Power
public override void ExposeData(ObjectSerializer serializer)
{
serializer.DataField(ref Load, "load", 40);
serializer.DataField(ref BulbType, "bulb", LightBulbType.Tube);
}
@@ -122,6 +135,8 @@ namespace Content.Server.GameObjects.Components.Power
UpdateLight();
}
private LightState _lightState => Owner.GetComponent<PointLightComponent>().State;
/// <summary>
/// Updates the light's power drain, sprite and actual light state.
/// </summary>
@@ -141,7 +156,7 @@ namespace Content.Server.GameObjects.Components.Power
switch (LightBulb.State)
{
case LightBulbState.Normal:
device.Load = Load;
device.Load = LightBulb.PowerUse;
if (device.Powered)
{
sprite.LayerSetState(0, "on");
@@ -159,7 +174,6 @@ namespace Content.Server.GameObjects.Components.Power
sprite.LayerSetState(0, "off");
light.State = LightState.Off;
}
break;
case LightBulbState.Broken:
device.Load = 0;