Re-organize all projects (#4166)
This commit is contained in:
107
Content.Server/Clothing/Components/ClothingComponent.cs
Normal file
107
Content.Server/Clothing/Components/ClothingComponent.cs
Normal file
@@ -0,0 +1,107 @@
|
||||
using Content.Server.Hands.Components;
|
||||
using Content.Server.Inventory.Components;
|
||||
using Content.Server.Items;
|
||||
using Content.Shared.Clothing;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Item;
|
||||
using Content.Shared.NetIDs;
|
||||
using Content.Shared.Notification;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using static Content.Shared.Inventory.EquipmentSlotDefines;
|
||||
|
||||
namespace Content.Server.Clothing.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(SharedItemComponent))]
|
||||
[ComponentReference(typeof(ItemComponent))]
|
||||
public class ClothingComponent : ItemComponent, IUse
|
||||
{
|
||||
public override string Name => "Clothing";
|
||||
public override uint? NetID => ContentNetIDs.CLOTHING;
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("Slots")]
|
||||
public SlotFlags SlotFlags = SlotFlags.PREVENTEQUIP; //Different from None, NONE allows equips if no slot flags are required
|
||||
|
||||
[DataField("QuickEquip")]
|
||||
private bool _quickEquipEnabled = true;
|
||||
|
||||
[DataField("HeatResistance")]
|
||||
private int _heatResistance = 323;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public int HeatResistance => _heatResistance;
|
||||
|
||||
[DataField("ClothingPrefix")]
|
||||
private string? _clothingEquippedPrefix;
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public string? ClothingEquippedPrefix
|
||||
{
|
||||
get => _clothingEquippedPrefix;
|
||||
set
|
||||
{
|
||||
Dirty();
|
||||
_clothingEquippedPrefix = value;
|
||||
}
|
||||
}
|
||||
|
||||
public override ComponentState GetComponentState(ICommonSession player)
|
||||
{
|
||||
return new ClothingComponentState(ClothingEquippedPrefix, EquippedPrefix);
|
||||
}
|
||||
|
||||
bool IUse.UseEntity(UseEntityEventArgs eventArgs)
|
||||
{
|
||||
if (!_quickEquipEnabled) return false;
|
||||
if (!eventArgs.User.TryGetComponent(out InventoryComponent? inv)
|
||||
|| !eventArgs.User.TryGetComponent(out HandsComponent? hands)) return false;
|
||||
|
||||
foreach (var (slot, flag) in SlotMasks)
|
||||
{
|
||||
// We check if the clothing can be equipped in this slot.
|
||||
if ((SlotFlags & flag) == 0) continue;
|
||||
|
||||
if (inv.TryGetSlotItem(slot, out ItemComponent? item))
|
||||
{
|
||||
if (!inv.CanUnequip(slot)) continue;
|
||||
hands.Drop(Owner);
|
||||
inv.Unequip(slot);
|
||||
hands.PutInHand(item);
|
||||
|
||||
if (!TryEquip(inv, slot, eventArgs.User))
|
||||
{
|
||||
hands.Drop(item.Owner);
|
||||
inv.Equip(slot, item);
|
||||
hands.PutInHand(Owner.GetComponent<ItemComponent>());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
hands.Drop(Owner);
|
||||
if (!TryEquip(inv, slot, eventArgs.User))
|
||||
hands.PutInHand(Owner.GetComponent<ItemComponent>());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool TryEquip(InventoryComponent inv, Slots slot, IEntity user)
|
||||
{
|
||||
if (!inv.Equip(slot, this, true, out var reason))
|
||||
{
|
||||
if (reason != null)
|
||||
Owner.PopupMessage(user, reason);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
157
Content.Server/Clothing/Components/MagbootsComponent.cs
Normal file
157
Content.Server/Clothing/Components/MagbootsComponent.cs
Normal file
@@ -0,0 +1,157 @@
|
||||
#nullable enable
|
||||
using Content.Server.Alert;
|
||||
using Content.Server.GameObjects.Components.Atmos;
|
||||
using Content.Server.Inventory.Components;
|
||||
using Content.Server.Items;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Actions;
|
||||
using Content.Shared.Actions.Behaviors.Item;
|
||||
using Content.Shared.Actions.Components;
|
||||
using Content.Shared.Alert;
|
||||
using Content.Shared.Clothing;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Inventory;
|
||||
using Content.Shared.Verbs;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using static Content.Shared.Inventory.EquipmentSlotDefines;
|
||||
|
||||
namespace Content.Server.Clothing.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(IActivate))]
|
||||
public sealed class MagbootsComponent : SharedMagbootsComponent, IUnequipped, IEquipped, IUse, IActivate
|
||||
{
|
||||
[ComponentDependency] private ItemComponent? _item = null;
|
||||
[ComponentDependency] private ItemActionsComponent? _itemActions = null;
|
||||
[ComponentDependency] private SpriteComponent? _sprite = null;
|
||||
private bool _on;
|
||||
|
||||
[ViewVariables]
|
||||
public override bool On
|
||||
{
|
||||
get => _on;
|
||||
set
|
||||
{
|
||||
_on = value;
|
||||
|
||||
UpdateContainer();
|
||||
_itemActions?.Toggle(ItemActionType.ToggleMagboots, On);
|
||||
if (_item != null)
|
||||
_item.EquippedPrefix = On ? "on" : null;
|
||||
_sprite?.LayerSetState(0, On ? "icon-on" : "icon");
|
||||
OnChanged();
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
|
||||
public void Toggle(IEntity user)
|
||||
{
|
||||
On = !On;
|
||||
}
|
||||
|
||||
void IUnequipped.Unequipped(UnequippedEventArgs eventArgs)
|
||||
{
|
||||
if (On && eventArgs.Slot == Slots.SHOES)
|
||||
{
|
||||
if (eventArgs.User.TryGetComponent(out MovedByPressureComponent? movedByPressure))
|
||||
{
|
||||
movedByPressure.Enabled = true;
|
||||
}
|
||||
|
||||
if (eventArgs.User.TryGetComponent(out ServerAlertsComponent? alerts))
|
||||
{
|
||||
alerts.ClearAlert(AlertType.Magboots);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void IEquipped.Equipped(EquippedEventArgs eventArgs)
|
||||
{
|
||||
UpdateContainer();
|
||||
}
|
||||
|
||||
private void UpdateContainer()
|
||||
{
|
||||
if (!Owner.TryGetContainer(out var container))
|
||||
return;
|
||||
|
||||
if (container.Owner.TryGetComponent(out InventoryComponent? inventoryComponent)
|
||||
&& inventoryComponent.GetSlotItem(Slots.SHOES)?.Owner == Owner)
|
||||
{
|
||||
if (container.Owner.TryGetComponent(out MovedByPressureComponent? movedByPressure))
|
||||
{
|
||||
movedByPressure.Enabled = false;
|
||||
}
|
||||
|
||||
if (container.Owner.TryGetComponent(out ServerAlertsComponent? alerts))
|
||||
{
|
||||
if (On)
|
||||
{
|
||||
alerts.ShowAlert(AlertType.Magboots);
|
||||
}
|
||||
else
|
||||
{
|
||||
alerts.ClearAlert(AlertType.Magboots);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool IUse.UseEntity(UseEntityEventArgs eventArgs)
|
||||
{
|
||||
Toggle(eventArgs.User);
|
||||
return true;
|
||||
}
|
||||
|
||||
void IActivate.Activate(ActivateEventArgs eventArgs)
|
||||
{
|
||||
Toggle(eventArgs.User);
|
||||
}
|
||||
|
||||
public override ComponentState GetComponentState(ICommonSession player)
|
||||
{
|
||||
return new MagbootsComponentState(On);
|
||||
}
|
||||
|
||||
[UsedImplicitly]
|
||||
public sealed class ToggleMagbootsVerb : Verb<MagbootsComponent>
|
||||
{
|
||||
protected override void GetData(IEntity user, MagbootsComponent component, VerbData data)
|
||||
{
|
||||
if (!ActionBlockerSystem.CanInteract(user))
|
||||
{
|
||||
data.Visibility = VerbVisibility.Invisible;
|
||||
return;
|
||||
}
|
||||
|
||||
data.Text = Loc.GetString("Toggle Magboots");
|
||||
}
|
||||
|
||||
protected override void Activate(IEntity user, MagbootsComponent component)
|
||||
{
|
||||
component.Toggle(user);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[UsedImplicitly]
|
||||
[DataDefinition]
|
||||
public sealed class ToggleMagbootsAction : IToggleItemAction
|
||||
{
|
||||
public bool DoToggleAction(ToggleItemActionEventArgs args)
|
||||
{
|
||||
if (!args.Item.TryGetComponent<MagbootsComponent>(out var magboots))
|
||||
return false;
|
||||
|
||||
magboots.Toggle(args.Performer);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user