2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.Hands.Components;
|
|
|
|
|
using Content.Shared.Clothing;
|
|
|
|
|
using Content.Shared.Interaction;
|
2021-12-30 22:56:10 +01:00
|
|
|
using Content.Shared.Inventory;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Item;
|
2019-04-15 21:11:38 -06:00
|
|
|
using Robust.Shared.GameObjects;
|
2021-07-12 01:32:10 -07:00
|
|
|
using Robust.Shared.GameStates;
|
2021-12-03 11:55:25 +01:00
|
|
|
using Robust.Shared.IoC;
|
2021-12-30 22:56:10 +01:00
|
|
|
using Robust.Shared.Prototypes;
|
2021-03-05 01:08:38 +01:00
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2020-09-08 13:30:22 +02:00
|
|
|
using Robust.Shared.ViewVariables;
|
2018-04-25 06:42:35 -05:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.Clothing.Components
|
2018-04-25 06:42:35 -05:00
|
|
|
{
|
2019-07-31 15:02:36 +02:00
|
|
|
[RegisterComponent]
|
2021-04-02 04:01:03 -06:00
|
|
|
[ComponentReference(typeof(SharedItemComponent))]
|
2022-02-16 00:23:23 -07:00
|
|
|
[Virtual]
|
2021-12-30 22:56:10 +01:00
|
|
|
public class ItemComponent : SharedItemComponent{}
|
|
|
|
|
|
|
|
|
|
[RegisterComponent]
|
|
|
|
|
[NetworkedComponent]
|
|
|
|
|
[ComponentReference(typeof(SharedItemComponent))]
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class ClothingComponent : ItemComponent, IUse
|
2018-04-25 06:42:35 -05:00
|
|
|
{
|
2021-12-05 21:02:04 +01:00
|
|
|
[Dependency] private readonly IEntityManager _entities = default!;
|
2021-12-30 22:56:10 +01:00
|
|
|
[Dependency] private readonly IPrototypeManager _prototype = default!;
|
2021-12-05 21:02:04 +01:00
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("QuickEquip")]
|
2019-07-19 16:31:56 +02:00
|
|
|
private bool _quickEquipEnabled = true;
|
2021-03-05 01:08:38 +01:00
|
|
|
|
|
|
|
|
[DataField("HeatResistance")]
|
|
|
|
|
private int _heatResistance = 323;
|
|
|
|
|
|
2020-09-08 13:30:22 +02:00
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
2019-04-06 17:11:51 +02:00
|
|
|
public int HeatResistance => _heatResistance;
|
|
|
|
|
|
2021-02-04 17:44:49 +01:00
|
|
|
bool IUse.UseEntity(UseEntityEventArgs eventArgs)
|
2019-07-19 16:31:56 +02:00
|
|
|
{
|
|
|
|
|
if (!_quickEquipEnabled) return false;
|
2021-12-30 22:56:10 +01:00
|
|
|
|
|
|
|
|
var invSystem = EntitySystem.Get<InventorySystem>();
|
2021-12-05 21:02:04 +01:00
|
|
|
if (!_entities.TryGetComponent(eventArgs.User, out InventoryComponent? inv)
|
2021-12-30 22:56:10 +01:00
|
|
|
|| !_entities.TryGetComponent(eventArgs.User, out HandsComponent? hands) || !_prototype.TryIndex<InventoryTemplatePrototype>(inv.TemplateId, out var prototype)) return false;
|
2019-07-19 16:31:56 +02:00
|
|
|
|
2021-12-30 22:56:10 +01:00
|
|
|
foreach (var slotDef in prototype.Slots)
|
2019-07-19 16:31:56 +02:00
|
|
|
{
|
2021-12-30 22:56:10 +01:00
|
|
|
if(!invSystem.CanEquip(eventArgs.User, Owner, slotDef.Name, out _, slotDef, inv))
|
|
|
|
|
continue;
|
2019-07-19 16:31:56 +02:00
|
|
|
|
2021-12-30 22:56:10 +01:00
|
|
|
if (invSystem.TryGetSlotEntity(eventArgs.User, slotDef.Name, out var slotEntity, inv))
|
2019-07-19 16:31:56 +02:00
|
|
|
{
|
2021-12-30 22:56:10 +01:00
|
|
|
if(!invSystem.TryUnequip(eventArgs.User, slotDef.Name, true, inventory: inv))
|
|
|
|
|
continue;
|
2020-05-23 17:27:57 +02:00
|
|
|
|
2021-12-30 22:56:10 +01:00
|
|
|
if (!invSystem.TryEquip(eventArgs.User, Owner, slotDef.Name, true, inventory: inv))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
hands.PutInHandOrDrop(slotEntity.Value);
|
2019-07-19 16:31:56 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-12-30 22:56:10 +01:00
|
|
|
if (!invSystem.TryEquip(eventArgs.User, Owner, slotDef.Name, true, inventory: inv))
|
|
|
|
|
continue;
|
2019-07-19 16:31:56 +02:00
|
|
|
}
|
|
|
|
|
|
2020-05-23 17:27:57 +02:00
|
|
|
return true;
|
2019-07-19 16:31:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-04-25 06:42:35 -05:00
|
|
|
}
|
|
|
|
|
}
|