Wearables can attach lightsources to limbs

This commit is contained in:
Joonas Rikkonen
2018-03-02 11:13:11 +02:00
parent cc41f0cd9e
commit 12d1692bb5
3 changed files with 32 additions and 6 deletions
@@ -21,6 +21,8 @@ namespace Barotrauma.Items.Components
private bool castShadows;
public PhysicsBody ParentBody;
[Editable(0.0f, 2048.0f), Serialize(100.0f, true)]
public float Range
{
@@ -133,15 +135,17 @@ namespace Barotrauma.Items.Components
light.Color = Color.Transparent;
return;
}
light.Position = item.Position;
light.Position = ParentBody != null ? ParentBody.Position : item.Position;
#endif
if (item.body != null)
PhysicsBody body = ParentBody ?? item.body;
if (body != null)
{
#if CLIENT
light.Rotation = item.body.Dir > 0.0f ? item.body.Rotation : item.body.Rotation - MathHelper.Pi;
light.Rotation = body.Dir > 0.0f ? body.Rotation : body.Rotation - MathHelper.Pi;
#endif
if (!item.body.Enabled)
if (!body.Enabled)
{
#if CLIENT
light.Color = Color.Transparent;
@@ -15,6 +15,8 @@ namespace Barotrauma.Items.Components
public readonly bool InheritLimbDepth;
public readonly LimbType DepthLimb;
public LightComponent LightComponent;
public readonly Wearable WearableComponent;
public readonly string Sound;
@@ -80,6 +82,14 @@ namespace Barotrauma.Items.Components
subElement.GetAttributeBool("inheritlimbdepth", true),
(LimbType)Enum.Parse(typeof(LimbType), subElement.GetAttributeString("depthlimb", "None"), true), sound);
foreach (XElement lightElement in subElement.Elements())
{
if (lightElement.Name.ToString().ToLowerInvariant() != "lightcomponent") continue;
wearableSprites[i].LightComponent = new LightComponent(item, lightElement);
wearableSprites[i].LightComponent.Parent = this;
item.components.Add(wearableSprites[i].LightComponent);
}
i++;
break;
case "damagemodifier":
@@ -98,8 +108,11 @@ namespace Barotrauma.Items.Components
if (equipLimb == null) continue;
item.body.Enabled = false;
IsActive = true;
if (wearableSprites[i].LightComponent != null)
{
wearableSprites[i].LightComponent.ParentBody = equipLimb.body;
}
limb[i] = equipLimb;
if (!equipLimb.WearingItems.Contains(wearableSprites[i]))
@@ -127,6 +140,11 @@ namespace Barotrauma.Items.Components
Limb equipLimb = character.AnimController.GetLimb(limbType[i]);
if (equipLimb == null) continue;
if (wearableSprites[i].LightComponent != null)
{
wearableSprites[i].LightComponent.ParentBody = null;
}
equipLimb.WearingItems.RemoveAll(w => w != null && w == wearableSprites[i]);
limb[i] = null;