2018-02-05 13:57:26 -06:00
|
|
|
|
using System;
|
|
|
|
|
|
using Content.Server.Interfaces.GameObjects;
|
2017-10-22 23:48:01 +02:00
|
|
|
|
using Content.Shared.GameObjects;
|
|
|
|
|
|
using SS14.Server.GameObjects;
|
|
|
|
|
|
using SS14.Shared.GameObjects;
|
2018-02-05 13:57:26 -06:00
|
|
|
|
using SS14.Shared.Interfaces.GameObjects;
|
2017-10-22 23:48:01 +02:00
|
|
|
|
using SS14.Shared.Interfaces.GameObjects.Components;
|
|
|
|
|
|
using SS14.Shared.Log;
|
|
|
|
|
|
using SS14.Shared.Maths;
|
2018-02-05 13:57:26 -06:00
|
|
|
|
using SS14.Shared.IoC;
|
|
|
|
|
|
using Content.Server.GameObjects.EntitySystems;
|
2019-03-16 20:40:07 +01:00
|
|
|
|
using Content.Shared.GameObjects.Components.Doors;
|
2018-07-26 23:38:16 +02:00
|
|
|
|
using SS14.Shared.Serialization;
|
2018-07-26 23:55:34 +02:00
|
|
|
|
using SS14.Shared.Interfaces.Network;
|
2018-09-09 15:34:43 +02:00
|
|
|
|
using SS14.Shared.ViewVariables;
|
2017-10-22 23:48:01 +02:00
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.GameObjects
|
|
|
|
|
|
{
|
2018-05-08 08:20:15 +02:00
|
|
|
|
public class ServerDoorComponent : Component, IAttackHand
|
2017-10-22 23:48:01 +02:00
|
|
|
|
{
|
2018-05-08 08:20:15 +02:00
|
|
|
|
public override string Name => "Door";
|
2018-09-09 15:34:43 +02:00
|
|
|
|
[ViewVariables]
|
2017-10-22 23:48:01 +02:00
|
|
|
|
public bool Opened { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
private float OpenTimeCounter;
|
2018-05-08 08:20:15 +02:00
|
|
|
|
|
2017-10-22 23:48:01 +02:00
|
|
|
|
private CollidableComponent collidableComponent;
|
2019-03-16 20:40:07 +01:00
|
|
|
|
private AppearanceComponent _appearance;
|
2017-10-22 23:48:01 +02:00
|
|
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
|
|
|
|
|
collidableComponent = Owner.GetComponent<CollidableComponent>();
|
2019-03-16 20:40:07 +01:00
|
|
|
|
_appearance = Owner.GetComponent<AppearanceComponent>();
|
2017-10-22 23:48:01 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void OnRemove()
|
|
|
|
|
|
{
|
|
|
|
|
|
collidableComponent = null;
|
2019-03-16 20:40:07 +01:00
|
|
|
|
_appearance = null;
|
2018-07-26 23:55:34 +02:00
|
|
|
|
|
|
|
|
|
|
base.OnRemove();
|
2017-10-22 23:48:01 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-05 13:57:26 -06:00
|
|
|
|
public bool Attackhand(IEntity user)
|
2017-10-22 23:48:01 +02:00
|
|
|
|
{
|
|
|
|
|
|
if (Opened)
|
|
|
|
|
|
{
|
|
|
|
|
|
Close();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Open();
|
|
|
|
|
|
}
|
2018-02-05 13:57:26 -06:00
|
|
|
|
return true;
|
2017-10-22 23:48:01 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-07-26 23:55:34 +02:00
|
|
|
|
public override void HandleMessage(ComponentMessage message, INetChannel netChannel = null, IComponent component = null)
|
2017-10-22 23:48:01 +02:00
|
|
|
|
{
|
2018-07-26 23:55:34 +02:00
|
|
|
|
base.HandleMessage(message, netChannel, component);
|
|
|
|
|
|
|
|
|
|
|
|
switch (message)
|
2017-10-22 23:48:01 +02:00
|
|
|
|
{
|
2018-07-26 23:55:34 +02:00
|
|
|
|
case BumpedEntMsg msg:
|
|
|
|
|
|
if (Opened)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2017-10-22 23:48:01 +02:00
|
|
|
|
|
2018-07-26 23:55:34 +02:00
|
|
|
|
Open();
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2017-10-22 23:48:01 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Open()
|
|
|
|
|
|
{
|
|
|
|
|
|
Opened = true;
|
|
|
|
|
|
collidableComponent.IsHardCollidable = false;
|
2019-03-16 20:40:07 +01:00
|
|
|
|
_appearance.SetData(DoorVisuals.VisualState, DoorVisualState.Open);
|
2017-10-22 23:48:01 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool Close()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (collidableComponent.TryCollision(Vector2.Zero))
|
|
|
|
|
|
{
|
|
|
|
|
|
// Do nothing, somebody's in the door.
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
Opened = false;
|
|
|
|
|
|
OpenTimeCounter = 0;
|
|
|
|
|
|
collidableComponent.IsHardCollidable = true;
|
2019-03-16 20:40:07 +01:00
|
|
|
|
_appearance.SetData(DoorVisuals.VisualState, DoorVisualState.Closed);
|
2017-10-22 23:48:01 +02:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private const float AUTO_CLOSE_DELAY = 5;
|
2018-07-26 14:26:19 -07:00
|
|
|
|
public void OnUpdate(float frameTime)
|
2017-10-22 23:48:01 +02:00
|
|
|
|
{
|
|
|
|
|
|
if (!Opened)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
OpenTimeCounter += frameTime;
|
|
|
|
|
|
if (OpenTimeCounter > AUTO_CLOSE_DELAY)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!Close())
|
|
|
|
|
|
{
|
|
|
|
|
|
// Try again in 2 seconds if it's jammed or something.
|
|
|
|
|
|
OpenTimeCounter -= 2;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|