2021-07-10 17:35:33 +02:00
|
|
|
using System.Collections.Generic;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Interaction;
|
2021-07-10 17:35:33 +02:00
|
|
|
using Content.Shared.Sound;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Tool;
|
2020-04-29 13:43:07 +02:00
|
|
|
using Robust.Server.GameObjects;
|
2021-03-21 09:12:03 -07:00
|
|
|
using Robust.Shared.Audio;
|
2020-04-29 13:43:07 +02:00
|
|
|
using Robust.Shared.GameObjects;
|
2021-07-12 01:32:10 -07:00
|
|
|
using Robust.Shared.GameStates;
|
2021-03-21 09:12:03 -07:00
|
|
|
using Robust.Shared.Player;
|
2021-02-18 09:09:07 +01:00
|
|
|
using Robust.Shared.Players;
|
2021-03-05 01:08:38 +01:00
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2020-04-29 13:43:07 +02:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.Tools.Components
|
2020-04-29 13:43:07 +02:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Not to be confused with Multitool (power)
|
|
|
|
|
/// </summary>
|
|
|
|
|
[RegisterComponent]
|
2021-07-12 01:32:10 -07:00
|
|
|
[NetworkedComponent()]
|
2020-04-29 13:43:07 +02:00
|
|
|
public class MultiToolComponent : Component, IUse
|
|
|
|
|
{
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataDefinition]
|
|
|
|
|
public class ToolEntry
|
2020-04-29 13:43:07 +02:00
|
|
|
{
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("behavior")] public ToolQuality Behavior { get; private set; } = ToolQuality.None;
|
|
|
|
|
|
2021-05-04 15:37:16 +02:00
|
|
|
[DataField("state")]
|
2021-03-05 01:08:38 +01:00
|
|
|
public string State { get; } = string.Empty;
|
|
|
|
|
|
2021-05-04 15:37:16 +02:00
|
|
|
[DataField("texture")]
|
2021-03-05 01:08:38 +01:00
|
|
|
public string Texture { get; } = string.Empty;
|
|
|
|
|
|
2021-05-04 15:37:16 +02:00
|
|
|
[DataField("sprite")]
|
2021-03-05 01:08:38 +01:00
|
|
|
public string Sprite { get; } = string.Empty;
|
|
|
|
|
|
2021-07-31 19:52:33 +02:00
|
|
|
[DataField("useSound", required: true)]
|
2021-07-10 17:35:33 +02:00
|
|
|
public SoundSpecifier Sound { get; } = default!;
|
2021-03-05 01:08:38 +01:00
|
|
|
|
2021-07-31 19:52:33 +02:00
|
|
|
[DataField("changeSound", required: true)]
|
2021-07-10 17:35:33 +02:00
|
|
|
public SoundSpecifier ChangeSound { get; } = default!;
|
2020-04-29 13:43:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string Name => "MultiTool";
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("tools")] private List<ToolEntry> _tools = new();
|
2020-04-29 13:43:07 +02:00
|
|
|
private int _currentTool = 0;
|
|
|
|
|
|
2021-03-16 15:50:20 +01:00
|
|
|
private ToolComponent? _tool;
|
|
|
|
|
private SpriteComponent? _sprite;
|
2020-04-29 13:43:07 +02:00
|
|
|
|
2021-06-19 19:41:26 -07:00
|
|
|
protected override void Initialize()
|
2020-04-29 13:43:07 +02:00
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
Owner.TryGetComponent(out _tool);
|
|
|
|
|
Owner.TryGetComponent(out _sprite);
|
|
|
|
|
SetTool();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Cycle()
|
|
|
|
|
{
|
|
|
|
|
_currentTool = (_currentTool + 1) % _tools.Count;
|
|
|
|
|
SetTool();
|
|
|
|
|
var current = _tools[_currentTool];
|
2021-07-31 19:52:33 +02:00
|
|
|
SoundSystem.Play(Filter.Pvs(Owner), current.ChangeSound.GetSound(), Owner);
|
2020-04-29 13:43:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetTool()
|
|
|
|
|
{
|
|
|
|
|
if (_tool == null) return;
|
|
|
|
|
|
|
|
|
|
var current = _tools[_currentTool];
|
|
|
|
|
|
|
|
|
|
_tool.UseSound = current.Sound;
|
2020-05-19 13:55:52 +02:00
|
|
|
_tool.Qualities = current.Behavior;
|
2020-04-29 13:43:07 +02:00
|
|
|
|
|
|
|
|
if (_sprite == null) return;
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(current.Texture))
|
|
|
|
|
if (!string.IsNullOrEmpty(current.Sprite))
|
|
|
|
|
_sprite.LayerSetState(0, current.State, current.Sprite);
|
|
|
|
|
else
|
|
|
|
|
_sprite.LayerSetState(0, current.State);
|
|
|
|
|
else
|
|
|
|
|
_sprite.LayerSetTexture(0, current.Texture);
|
2020-05-19 13:55:52 +02:00
|
|
|
|
|
|
|
|
Dirty();
|
2020-04-29 13:43:07 +02:00
|
|
|
}
|
|
|
|
|
|
2021-02-04 17:44:49 +01:00
|
|
|
bool IUse.UseEntity(UseEntityEventArgs eventArgs)
|
2020-04-29 13:43:07 +02:00
|
|
|
{
|
|
|
|
|
Cycle();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2020-05-19 13:55:52 +02:00
|
|
|
|
2021-02-18 09:09:07 +01:00
|
|
|
public override ComponentState GetComponentState(ICommonSession player)
|
2020-05-19 13:55:52 +02:00
|
|
|
{
|
2021-03-16 15:50:20 +01:00
|
|
|
return new MultiToolComponentState(_tool?.Qualities ?? ToolQuality.None);
|
2020-05-19 13:55:52 +02:00
|
|
|
}
|
2020-04-29 13:43:07 +02:00
|
|
|
}
|
|
|
|
|
}
|