-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Pe4henika
committed
Aug 15, 2024
1 parent
d056c64
commit bd10e91
Showing
8,842 changed files
with
107,230 additions
and
231 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
Content.Server/_LostParadise/BatonOverhaul/SwitchableWeaponSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using Content.Shared.Damage.Components; | ||
using Content.Shared.Examine; | ||
using Content.Shared.Interaction.Events; | ||
using Content.Shared.Item; | ||
using Content.Shared.SwitchableWeapon; | ||
using Content.Shared.Toggleable; | ||
using Content.Shared.Weapons.Melee.Events; | ||
using Robust.Shared.Audio.Systems; | ||
|
||
namespace Content.Server.SwitchableWeapon; | ||
|
||
public sealed class SwitchableWeaponSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly SharedItemSystem _item = default!; | ||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!; | ||
[Dependency] private readonly SharedAudioSystem _audio = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
||
SubscribeLocalEvent<SwitchableWeaponComponent, UseInHandEvent>(Toggle); | ||
SubscribeLocalEvent<SwitchableWeaponComponent, ExaminedEvent>(OnExamined); | ||
SubscribeLocalEvent<SwitchableWeaponComponent, GetMeleeDamageEvent>(OnGetMeleeDamage); | ||
SubscribeLocalEvent<SwitchableWeaponComponent, ComponentAdd>(OnComponentAdded); | ||
} | ||
|
||
private void OnComponentAdded(EntityUid uid, SwitchableWeaponComponent component, ComponentAdd args) | ||
{ | ||
UpdateState(uid, component); | ||
} | ||
|
||
private void OnGetMeleeDamage(EntityUid uid, SwitchableWeaponComponent component, ref GetMeleeDamageEvent args) | ||
{ | ||
args.Damage = component.IsOpen ? component.DamageOpen : component.DamageFolded; | ||
} | ||
|
||
private void OnExamined(EntityUid uid, SwitchableWeaponComponent comp, ExaminedEvent args) | ||
{ | ||
var msg = comp.IsOpen | ||
? Loc.GetString("comp-switchable-examined-on") | ||
: Loc.GetString("comp-switchable-examined-off"); | ||
args.PushMarkup(msg); | ||
} | ||
|
||
private void UpdateState(EntityUid uid, SwitchableWeaponComponent comp) | ||
{ | ||
if (TryComp<ItemComponent>(uid, out var item)) | ||
{ | ||
_item.SetSize(uid, comp.IsOpen ? comp.SizeOpened : comp.SizeClosed, item); | ||
_item.SetHeldPrefix(uid, comp.IsOpen ? "on" : "off", component: item); | ||
} | ||
|
||
if (TryComp<AppearanceComponent>(uid, out var appearance)) | ||
_appearance.SetData(uid, ToggleVisuals.Toggled, comp.IsOpen, appearance); | ||
|
||
if (TryComp<StaminaDamageOnHitComponent>(uid, out var stamComp)) | ||
{ | ||
stamComp.Damage = comp.IsOpen ? comp.StaminaDamageOpen : comp.StaminaDamageFolded; | ||
} | ||
} | ||
|
||
private void Toggle(EntityUid uid, SwitchableWeaponComponent comp, UseInHandEvent args) | ||
{ | ||
comp.IsOpen = !comp.IsOpen; | ||
UpdateState(uid, comp); | ||
|
||
var soundToPlay = comp.IsOpen ? comp.OpenSound : comp.CloseSound; | ||
_audio.PlayPvs(soundToPlay, args.User); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,25 @@ | ||
using Content.Shared.Containers.ItemSlots; | ||
using Robust.Shared.Audio; | ||
using Robust.Shared.GameStates; | ||
using Robust.Shared.Serialization; | ||
|
||
namespace Content.Shared.Cabinet; | ||
|
||
/// <summary> | ||
/// Used for entities that can be opened, closed, and can hold one item. E.g., fire extinguisher cabinets. | ||
/// Used for entities that can be opened, closed, and can hold one item. E.g., fire extinguisher cabinets. | ||
/// Requires <c>OpenableComponent</c>. | ||
/// </summary> | ||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(true)] | ||
[RegisterComponent, NetworkedComponent, Access(typeof(ItemCabinetSystem))] | ||
public sealed partial class ItemCabinetComponent : Component | ||
{ | ||
/// <summary> | ||
/// Sound to be played when the cabinet door is opened. | ||
/// Name of the <see cref="ItemSlot"/> that stores the actual item. | ||
/// </summary> | ||
[DataField, AutoNetworkedField, ViewVariables(VVAccess.ReadWrite)] | ||
public SoundSpecifier? DoorSound; | ||
|
||
/// <summary> | ||
/// The <see cref="ItemSlot"/> that stores the actual item. The entity whitelist, sounds, and other | ||
/// behaviours are specified by this <see cref="ItemSlot"/> definition. | ||
/// </summary> | ||
[DataField, ViewVariables] | ||
public ItemSlot CabinetSlot = new(); | ||
|
||
/// <summary> | ||
/// Whether the cabinet is currently open or not. | ||
/// </summary> | ||
[DataField, AutoNetworkedField] | ||
public bool Opened; | ||
|
||
/// <summary> | ||
/// The state for when the cabinet is open | ||
/// </summary> | ||
[DataField, AutoNetworkedField, ViewVariables(VVAccess.ReadWrite)] | ||
public string? OpenState; | ||
[DataField] | ||
public string Slot = "ItemCabinet"; | ||
} | ||
|
||
/// <summary> | ||
/// The state for when the cabinet is closed | ||
/// </summary> | ||
[DataField, AutoNetworkedField, ViewVariables(VVAccess.ReadWrite)] | ||
public string? ClosedState; | ||
[Serializable, NetSerializable] | ||
public enum ItemCabinetVisuals : byte | ||
{ | ||
ContainsItem, | ||
Layer | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
using Content.Shared.Containers.ItemSlots; | ||
using Content.Shared.Interaction; | ||
using Content.Shared.Nutrition.Components; | ||
using Content.Shared.Nutrition.EntitySystems; | ||
using Robust.Shared.Containers; | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace Content.Shared.Cabinet; | ||
|
||
/// <summary> | ||
/// Controls ItemCabinet slot locking and visuals. | ||
/// </summary> | ||
public sealed class ItemCabinetSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly ItemSlotsSystem _slots = default!; | ||
[Dependency] private readonly OpenableSystem _openable = default!; | ||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!; | ||
|
||
/// <inheritdoc/> | ||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
||
SubscribeLocalEvent<ItemCabinetComponent, ComponentStartup>(OnStartup); | ||
SubscribeLocalEvent<ItemCabinetComponent, MapInitEvent>(OnMapInit); | ||
SubscribeLocalEvent<ItemCabinetComponent, EntInsertedIntoContainerMessage>(OnContainerModified); | ||
SubscribeLocalEvent<ItemCabinetComponent, EntRemovedFromContainerMessage>(OnContainerModified); | ||
SubscribeLocalEvent<ItemCabinetComponent, OpenableOpenedEvent>(OnOpened); | ||
SubscribeLocalEvent<ItemCabinetComponent, OpenableClosedEvent>(OnClosed); | ||
} | ||
|
||
private void OnStartup(Entity<ItemCabinetComponent> ent, ref ComponentStartup args) | ||
{ | ||
UpdateAppearance(ent); | ||
} | ||
|
||
private void OnMapInit(Entity<ItemCabinetComponent> ent, ref MapInitEvent args) | ||
{ | ||
// update at mapinit to avoid copy pasting locked: true and locked: false for each closed/open prototype | ||
SetSlotLock(ent, !_openable.IsOpen(ent)); | ||
} | ||
|
||
private void UpdateAppearance(Entity<ItemCabinetComponent> ent) | ||
{ | ||
_appearance.SetData(ent, ItemCabinetVisuals.ContainsItem, HasItem(ent)); | ||
} | ||
|
||
private void OnContainerModified(EntityUid uid, ItemCabinetComponent component, ContainerModifiedMessage args) | ||
{ | ||
if (args.Container.ID == component.Slot) | ||
UpdateAppearance((uid, component)); | ||
} | ||
|
||
private void OnOpened(Entity<ItemCabinetComponent> ent, ref OpenableOpenedEvent args) | ||
{ | ||
SetSlotLock(ent, false); | ||
} | ||
|
||
private void OnClosed(Entity<ItemCabinetComponent> ent, ref OpenableClosedEvent args) | ||
{ | ||
SetSlotLock(ent, true); | ||
} | ||
|
||
/// <summary> | ||
/// Tries to get the cabinet's item slot. | ||
/// </summary> | ||
public bool TryGetSlot(Entity<ItemCabinetComponent> ent, [NotNullWhen(true)] out ItemSlot? slot) | ||
{ | ||
slot = null; | ||
if (!TryComp<ItemSlotsComponent>(ent, out var slots)) | ||
return false; | ||
|
||
return _slots.TryGetSlot(ent, ent.Comp.Slot, out slot, slots); | ||
} | ||
|
||
/// <summary> | ||
/// Returns true if the cabinet contains an item. | ||
/// </summary> | ||
public bool HasItem(Entity<ItemCabinetComponent> ent) | ||
{ | ||
return TryGetSlot(ent, out var slot) && slot.HasItem; | ||
} | ||
|
||
/// <summary> | ||
/// Lock or unlock the underlying item slot. | ||
/// </summary> | ||
public void SetSlotLock(Entity<ItemCabinetComponent> ent, bool closed) | ||
{ | ||
if (!TryComp<ItemSlotsComponent>(ent, out var slots)) | ||
return; | ||
|
||
if (_slots.TryGetSlot(ent, ent.Comp.Slot, out var slot, slots)) | ||
_slots.SetLock(ent, slot, closed, slots); | ||
} | ||
} |
Oops, something went wrong.