Skip to content

Commit

Permalink
Leather gloves and an LED tube light. (#187)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
PrPleGoo authored and PJB3005 committed Apr 6, 2019
1 parent 9f1dd9f commit 77753de
Show file tree
Hide file tree
Showing 23 changed files with 312 additions and 44 deletions.
3 changes: 2 additions & 1 deletion Content.Server/Content.Server.csproj
Expand Up @@ -69,6 +69,7 @@
<Compile Include="GameObjects\Components\CatwalkComponent.cs" />
<Compile Include="GameObjects\Components\Damage\DamageThreshold.cs" />
<Compile Include="GameObjects\Components\Doors\ServerDoorComponent.cs" />
<Compile Include="GameObjects\Components\Mobs\HeatResistanceComponent.cs" />
<Compile Include="GameObjects\Components\Interactable\HandheldLightComponent.cs" />
<Compile Include="GameObjects\Components\Interactable\Tools\BaseTool.cs" />
<Compile Include="GameObjects\Components\Interactable\Tools\CrowbarComponent.cs" />
Expand Down Expand Up @@ -194,4 +195,4 @@
<Compile Include="GameObjects\Components\Construction\ConstructorComponent.cs" />
<Compile Include="GameObjects\Components\Construction\ConstructionComponent.cs" />
</ItemGroup>
</Project>
</Project>
1 change: 1 addition & 0 deletions Content.Server/EntryPoint.cs
Expand Up @@ -130,6 +130,7 @@ public override void Init()

factory.Register<MindComponent>();
factory.Register<SpeciesComponent>();
factory.Register<HeatResistanceComponent>();

factory.Register<SpawnPointComponent>();
factory.RegisterReference<SpawnPointComponent, SharedSpawnPointComponent>();
Expand Down
12 changes: 11 additions & 1 deletion Content.Server/GameObjects/Components/GUI/InventoryComponent.cs
Expand Up @@ -78,7 +78,17 @@ private string GetSlotString(Slots slot)
/// <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>
Expand Down
@@ -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
Expand All @@ -13,6 +10,9 @@ public class ClothingComponent : ItemComponent
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);
Expand All @@ -25,6 +25,8 @@ public override void ExposeData(ObjectSerializer serializer)
SlotFlags |= (SlotFlags)Enum.Parse(typeof(SlotFlags), slotflagsloaded.ToUpper());
}
});

serializer.DataFieldCached(ref _heatResistance, "HeatResistance", 323);
}
}
}
@@ -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;
}
}
}
Expand Up @@ -34,6 +34,9 @@ public class SpeciesComponent : SharedSpeciesComponent, IActionBlocker, IOnDamag
/// </summary>
private string templatename;

private int _heatResistance;
public int HeatResistance => _heatResistance;

public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
Expand All @@ -43,6 +46,7 @@ public override void ExposeData(ObjectSerializer serializer)
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,
Expand Down
@@ -1,4 +1,4 @@
using System;
using System;
using SS14.Shared.GameObjects;
using SS14.Shared.Maths;
using SS14.Shared.Serialization;
Expand Down Expand Up @@ -49,6 +49,12 @@ public class LightBulbComponent : Component

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.
Expand Down Expand Up @@ -82,6 +88,8 @@ public override void ExposeData(ObjectSerializer serializer)
{
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()
Expand Down
@@ -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;

Expand All @@ -33,8 +28,6 @@ public class PoweredLightComponent : Component, IAttackHand, IAttackBy

private LightBulbType BulbType = LightBulbType.Tube;

[ViewVariables] private float Load = 40;

[ViewVariables] private ContainerSlot _lightBulbContainer;

[ViewVariables]
Expand All @@ -50,23 +43,44 @@ private LightBulbComponent LightBulb
}
}

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>
Expand Down Expand Up @@ -110,7 +124,6 @@ private void EjectBulb(IEntity user)

public override void ExposeData(ObjectSerializer serializer)
{
serializer.DataField(ref Load, "load", 40);
serializer.DataField(ref BulbType, "bulb", LightBulbType.Tube);
}

Expand All @@ -122,6 +135,8 @@ public void UpdateLight(object sender, EventArgs e)
UpdateLight();
}

private LightState _lightState => Owner.GetComponent<PointLightComponent>().State;

/// <summary>
/// Updates the light's power drain, sprite and actual light state.
/// </summary>
Expand All @@ -141,7 +156,7 @@ public void UpdateLight()
switch (LightBulb.State)
{
case LightBulbState.Normal:
device.Load = Load;
device.Load = LightBulb.PowerUse;
if (device.Powered)
{
sprite.LayerSetState(0, "on");
Expand All @@ -159,7 +174,6 @@ public void UpdateLight()
sprite.LayerSetState(0, "off");
light.State = LightState.Off;
}

break;
case LightBulbState.Broken:
device.Load = 0;
Expand Down
4 changes: 0 additions & 4 deletions Content.Server/GameObjects/ContainerSlot.cs
@@ -1,11 +1,7 @@
using SS14.Server.GameObjects.Components.Container;
using SS14.Server.Interfaces.GameObjects;
using SS14.Shared.Interfaces.GameObjects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SS14.Shared.ViewVariables;

namespace Content.Server.GameObjects
Expand Down

0 comments on commit 77753de

Please sign in to comment.