It's time to build a barbershop! (#22565)

* barber!

* 5% change to maintenance
This commit is contained in:
Ed
2023-12-22 12:54:00 +03:00
committed by GitHub
parent 5d185483b4
commit 5a1e317e0f
12 changed files with 253 additions and 42 deletions

View File

@@ -64,5 +64,16 @@ public sealed class MagicMirrorBoundUserInterface : BoundUserInterface
_window.UpdateState(data);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing)
return;
if (_window != null)
_window.OnClose -= Close;
_window?.Dispose();
}
}

View File

@@ -1,6 +1,25 @@
using Content.Shared.Humanoid;
using Robust.Shared.Audio;
namespace Content.Server.MagicMirror;
[RegisterComponent]
public sealed partial class MagicMirrorComponent : Component
{
public Entity<HumanoidAppearanceComponent>? Target;
[DataField, ViewVariables(VVAccess.ReadWrite)]
public float AddSlotTime = 5f;
[DataField, ViewVariables(VVAccess.ReadWrite)]
public float RemoveSlotTime = 2f;
[DataField, ViewVariables(VVAccess.ReadWrite)]
public float SelectSlotTime = 3f;
[DataField, ViewVariables(VVAccess.ReadWrite)]
public float ChangeSlotTime = 1f;
[DataField, ViewVariables(VVAccess.ReadWrite)]
public SoundSpecifier ChangeHairSound = new SoundPathSpecifier("/Audio/Items/scissors.ogg");
}

View File

@@ -1,16 +1,22 @@
using System.Linq;
using Content.Server.DoAfter;
using Content.Server.Humanoid;
using Content.Server.UserInterface;
using Content.Shared.DoAfter;
using Content.Shared.Humanoid;
using Content.Shared.Humanoid.Markings;
using Content.Shared.Interaction;
using Content.Shared.MagicMirror;
using Robust.Server.GameObjects;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Player;
namespace Content.Server.MagicMirror;
public sealed class MagicMirrorSystem : EntitySystem
{
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly DoAfterSystem _doAfterSystem = default!;
[Dependency] private readonly MarkingManager _markings = default!;
[Dependency] private readonly HumanoidAppearanceSystem _humanoid = default!;
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
@@ -22,9 +28,27 @@ public sealed class MagicMirrorSystem : EntitySystem
SubscribeLocalEvent<MagicMirrorComponent, ActivatableUIOpenAttemptEvent>(OnOpenUIAttempt);
SubscribeLocalEvent<MagicMirrorComponent, AfterActivatableUIOpenEvent>(AfterUIOpen);
SubscribeLocalEvent<MagicMirrorComponent, MagicMirrorSelectMessage>(OnMagicMirrorSelect);
SubscribeLocalEvent<MagicMirrorComponent, MagicMirrorChangeColorMessage>(OnMagicMirrorChangeColor);
SubscribeLocalEvent<MagicMirrorComponent, MagicMirrorAddSlotMessage>(OnMagicMirrorAddSlot);
SubscribeLocalEvent<MagicMirrorComponent, MagicMirrorRemoveSlotMessage>(OnMagicMirrorRemoveSlot);
SubscribeLocalEvent<MagicMirrorComponent, MagicMirrorChangeColorMessage>(OnTryMagicMirrorChangeColor);
SubscribeLocalEvent<MagicMirrorComponent, MagicMirrorAddSlotMessage>(OnTryMagicMirrorAddSlot);
SubscribeLocalEvent<MagicMirrorComponent, MagicMirrorRemoveSlotMessage>(OnTryMagicMirrorRemoveSlot);
SubscribeLocalEvent<MagicMirrorComponent, AfterInteractEvent>(OnMagicMirrorInteract);
SubscribeLocalEvent<MagicMirrorComponent, SelectDoAfterEvent>(OnSelectSlotDoAfter);
SubscribeLocalEvent<MagicMirrorComponent, ChangeColorDoAfterEvent>(OnChangeColorDoAfter);
SubscribeLocalEvent<MagicMirrorComponent, RemoveSlotDoAfterEvent>(OnRemoveSlotDoAfter);
SubscribeLocalEvent<MagicMirrorComponent, AddSlotDoAfterEvent>(OnAddSlotDoAfter);
}
private void OnMagicMirrorInteract(Entity<MagicMirrorComponent> mirror, ref AfterInteractEvent args)
{
if (!TryComp<ActorComponent>(args.User, out var actor)) return;
if (TryComp<HumanoidAppearanceComponent>(args.Target, out var humanoid))
{
mirror.Comp.Target = new Entity<HumanoidAppearanceComponent>(args.Target.Value, humanoid);
UpdateInterface(mirror.Owner, mirror.Comp.Target.Value.Owner, actor.PlayerSession);
Log.Debug($"Target {mirror.Comp.Target}!");
};
}
private void OnOpenUIAttempt(EntityUid uid, MagicMirrorComponent mirror, ActivatableUIOpenAttemptEvent args)
@@ -33,16 +57,32 @@ public sealed class MagicMirrorSystem : EntitySystem
args.Cancel();
}
private void OnMagicMirrorSelect(EntityUid uid, MagicMirrorComponent component,
MagicMirrorSelectMessage message)
private void OnMagicMirrorSelect(EntityUid uid, MagicMirrorComponent component, MagicMirrorSelectMessage message)
{
if (message.Session.AttachedEntity == null || !TryComp<HumanoidAppearanceComponent>(message.Session.AttachedEntity.Value, out var humanoid))
if (component.Target == null) return;
if (message.Session.AttachedEntity == null) return;
var doAfter = new SelectDoAfterEvent(message);
_doAfterSystem.TryStartDoAfter(new DoAfterArgs(EntityManager, message.Session.AttachedEntity.Value, component.SelectSlotTime, doAfter, uid, target: component.Target.Value.Owner, used: uid)
{
return;
BreakOnTargetMove = true,
BreakOnDamage = true,
BreakOnHandChange = false,
BreakOnUserMove = true,
BreakOnWeightlessMove = false,
NeedHand = true
});
_audio.PlayPvs(component.ChangeHairSound, uid);
}
private void OnSelectSlotDoAfter(EntityUid uid, MagicMirrorComponent component, SelectDoAfterEvent args)
{
if (args.Handled || args.Args.Target == null || args.Cancelled)
return;
if (component.Target == null) return;
var category = MarkingCategories.Hair;
switch (message.Category)
switch (args.Message.Category)
{
case MagicMirrorCategory.Hair:
category = MarkingCategories.Hair;
@@ -54,21 +94,35 @@ public sealed class MagicMirrorSystem : EntitySystem
return;
}
_humanoid.SetMarkingId(message.Session.AttachedEntity.Value, category, message.Slot, message.Marking);
_humanoid.SetMarkingId(component.Target.Value.Owner, category, args.Message.Slot, args.Message.Marking);
UpdateInterface(uid, message.Session.AttachedEntity.Value, message.Session);
UpdateInterface(uid, component.Target.Value.Owner, args.Message.Session);
}
private void OnMagicMirrorChangeColor(EntityUid uid, MagicMirrorComponent component,
MagicMirrorChangeColorMessage message)
private void OnTryMagicMirrorChangeColor(EntityUid uid, MagicMirrorComponent component, MagicMirrorChangeColorMessage message)
{
if (message.Session.AttachedEntity == null || !TryComp<HumanoidAppearanceComponent>(message.Session.AttachedEntity.Value, out var humanoid))
if (component.Target == null) return;
if (message.Session.AttachedEntity == null) return;
var doAfter = new ChangeColorDoAfterEvent(message);
_doAfterSystem.TryStartDoAfter(new DoAfterArgs(EntityManager, message.Session.AttachedEntity.Value, component.ChangeSlotTime, doAfter, uid, target: component.Target.Value.Owner, used: uid)
{
BreakOnTargetMove = true,
BreakOnDamage = true,
BreakOnHandChange = false,
BreakOnUserMove = true,
BreakOnWeightlessMove = false,
NeedHand = true
});
}
private void OnChangeColorDoAfter(EntityUid uid, MagicMirrorComponent component, ChangeColorDoAfterEvent args)
{
if (args.Handled || args.Args.Target == null || args.Cancelled)
return;
}
if (component.Target == null) return;
var category = MarkingCategories.Hair;
switch (message.Category)
switch (args.Message.Category)
{
case MagicMirrorCategory.Hair:
category = MarkingCategories.Hair;
@@ -80,22 +134,39 @@ public sealed class MagicMirrorSystem : EntitySystem
return;
}
_humanoid.SetMarkingColor(message.Session.AttachedEntity.Value, category, message.Slot, message.Colors);
_humanoid.SetMarkingColor(component.Target.Value.Owner, category, args.Message.Slot, args.Message.Colors);
// using this makes the UI feel like total ass
// UpdateInterface(uid, message.Session.AttachedEntity.Value, message.Session);
// UpdateInterface(uid, component.Target, message.Session);
}
private void OnMagicMirrorRemoveSlot(EntityUid uid, MagicMirrorComponent component,
MagicMirrorRemoveSlotMessage message)
private void OnTryMagicMirrorRemoveSlot(EntityUid uid, MagicMirrorComponent component, MagicMirrorRemoveSlotMessage message)
{
if (message.Session.AttachedEntity == null || !TryComp<HumanoidAppearanceComponent>(message.Session.AttachedEntity.Value, out var humanoid))
if (component.Target == null) return;
if (message.Session.AttachedEntity == null) return;
var doAfter = new RemoveSlotDoAfterEvent(message);
_doAfterSystem.TryStartDoAfter(new DoAfterArgs(EntityManager, message.Session.AttachedEntity.Value, component.RemoveSlotTime, doAfter, uid, target: component.Target.Value.Owner, used: uid)
{
return;
BreakOnTargetMove = true,
BreakOnDamage = true,
BreakOnHandChange = false,
BreakOnUserMove = true,
BreakOnWeightlessMove = false,
NeedHand = true
});
_audio.PlayPvs(component.ChangeHairSound, uid);
}
private void OnRemoveSlotDoAfter(EntityUid uid, MagicMirrorComponent component, RemoveSlotDoAfterEvent args)
{
if (args.Handled || args.Args.Target == null || args.Cancelled)
return;
if (component.Target == null) return;
var category = MarkingCategories.Hair;
switch (message.Category)
switch (args.Message.Category)
{
case MagicMirrorCategory.Hair:
category = MarkingCategories.Hair;
@@ -107,21 +178,37 @@ public sealed class MagicMirrorSystem : EntitySystem
return;
}
_humanoid.RemoveMarking(message.Session.AttachedEntity.Value, category, message.Slot);
_humanoid.RemoveMarking(component.Target.Value.Owner, category, args.Message.Slot);
UpdateInterface(uid, message.Session.AttachedEntity.Value, message.Session);
UpdateInterface(uid, component.Target.Value.Owner, args.Message.Session);
}
private void OnMagicMirrorAddSlot(EntityUid uid, MagicMirrorComponent component,
MagicMirrorAddSlotMessage message)
private void OnTryMagicMirrorAddSlot(EntityUid uid, MagicMirrorComponent component, MagicMirrorAddSlotMessage message)
{
if (message.Session.AttachedEntity == null || !TryComp<HumanoidAppearanceComponent>(message.Session.AttachedEntity.Value, out var humanoid))
if (component.Target == null) return;
if (message.Session.AttachedEntity == null) return;
var doAfter = new AddSlotDoAfterEvent(message);
_doAfterSystem.TryStartDoAfter(new DoAfterArgs(EntityManager, message.Session.AttachedEntity.Value, component.AddSlotTime, doAfter, uid, target: component.Target.Value.Owner, used: uid)
{
BreakOnTargetMove = true,
BreakOnDamage = true,
BreakOnHandChange = false,
BreakOnUserMove = true,
BreakOnWeightlessMove = false,
NeedHand = true
});
_audio.PlayPvs(component.ChangeHairSound, uid);
}
private void OnAddSlotDoAfter(EntityUid uid, MagicMirrorComponent component, AddSlotDoAfterEvent args)
{
if (args.Handled || args.Args.Target == null || args.Cancelled)
return;
}
if (component.Target == null) return;
var category = MarkingCategories.Hair;
switch (message.Category)
switch (args.Message.Category)
{
case MagicMirrorCategory.Hair:
category = MarkingCategories.Hair;
@@ -133,23 +220,21 @@ public sealed class MagicMirrorSystem : EntitySystem
return;
}
var marking = _markings.MarkingsByCategoryAndSpecies(category, humanoid.Species).Keys.FirstOrDefault();
var marking = _markings.MarkingsByCategoryAndSpecies(category, component.Target.Value.Comp.Species).Keys.FirstOrDefault();
if (string.IsNullOrEmpty(marking))
{
return;
}
_humanoid.AddMarking(message.Session.AttachedEntity.Value, marking, Color.Black);
_humanoid.AddMarking(component.Target.Value.Owner, marking, Color.Black);
UpdateInterface(uid, message.Session.AttachedEntity.Value, message.Session);
UpdateInterface(uid, component.Target.Value.Owner, args.Message.Session);
}
private void UpdateInterface(EntityUid uid, EntityUid playerUid, ICommonSession session, HumanoidAppearanceComponent? humanoid = null)
private void UpdateInterface(EntityUid uid, EntityUid playerUid, ICommonSession session)
{
if (!Resolve(playerUid, ref humanoid) || session is not { } player)
{
return;
}
if (!TryComp<HumanoidAppearanceComponent>(playerUid, out var humanoid)) return;
if (session is not { } player) return;
var hair = humanoid.MarkingSet.TryGetCategory(MarkingCategories.Hair, out var hairMarkings)
? new List<Marking>(hairMarkings)
@@ -171,8 +256,8 @@ public sealed class MagicMirrorSystem : EntitySystem
private void AfterUIOpen(EntityUid uid, MagicMirrorComponent component, AfterActivatableUIOpenEvent args)
{
var looks = Comp<HumanoidAppearanceComponent>(args.User);
var actor = Comp<ActorComponent>(args.User);
if (!TryComp<HumanoidAppearanceComponent>(args.User, out var humanoid)) return;
component.Target = new Entity<HumanoidAppearanceComponent>(args.User, humanoid);
UpdateInterface(uid, args.User, args.Session);
}

View File

@@ -1,3 +1,4 @@
using Content.Shared.DoAfter;
using Content.Shared.Humanoid.Markings;
using Robust.Shared.Serialization;
@@ -104,3 +105,51 @@ public sealed class MagicMirrorUiData : BoundUserInterfaceMessage
public int FacialHairSlotTotal { get; }
}
[Serializable, NetSerializable]
public sealed partial class RemoveSlotDoAfterEvent : DoAfterEvent
{
public MagicMirrorRemoveSlotMessage Message;
public RemoveSlotDoAfterEvent(MagicMirrorRemoveSlotMessage message)
{
Message = message;
}
public override DoAfterEvent Clone() => this;
}
[Serializable, NetSerializable]
public sealed partial class AddSlotDoAfterEvent : DoAfterEvent
{
public MagicMirrorAddSlotMessage Message;
public AddSlotDoAfterEvent(MagicMirrorAddSlotMessage message)
{
Message = message;
}
public override DoAfterEvent Clone() => this;
}
[Serializable, NetSerializable]
public sealed partial class SelectDoAfterEvent : DoAfterEvent
{
public MagicMirrorSelectMessage Message;
public SelectDoAfterEvent(MagicMirrorSelectMessage message)
{
Message = message;
}
public override DoAfterEvent Clone() => this;
}
[Serializable, NetSerializable]
public sealed partial class ChangeColorDoAfterEvent : DoAfterEvent
{
public MagicMirrorChangeColorMessage Message;
public ChangeColorDoAfterEvent(MagicMirrorChangeColorMessage message)
{
Message = message;
}
public override DoAfterEvent Clone() => this;
}

View File

@@ -82,3 +82,8 @@
license: "CC-BY-SA-3.0"
copyright: "Taken from /tg/station"
source: "https://github.com/tgstation/tgstation/commit/c61c452d78425d89920b41ed5f95fd190e733a3c"
- files: ["scissors.ogg"]
license: "CC0-1.0"
copyright: "User Hanbaal on freesound.org. Converted to ogg by TheShuEd"
source: "https://freesound.org/people/Hanbaal/sounds/178669/"

Binary file not shown.

View File

@@ -32,7 +32,7 @@ ent-CrateJanitorBiosuit = Janitor bio suit crate
.desc = Contains 2 biohazard suits to ensure that no disease will distract you from cleaning.
ent-CrateServiceTheatre = Theatrical performances crate
.desc = Contains a moth cloak, maid uniform, clown and mime attributes, and other performance charms.
.desc = Contains a moth cloak, barber scissors, maid uniform, clown and mime attributes, and other performance charms.
ent-CrateJanitorExplosive = Janitorial bomb suit crate
.desc = Supplies a bomb suit for cleaning up any explosive compounds, buy one today!

View File

@@ -76,6 +76,7 @@
- id: ClothingUniformJumpskirtJanimaid
- id: ClothingNeckCloakVoid
- id: RevolverCapGun
- id: BarberScissors
- type: entity
id: CrateServiceCustomSmokable

View File

@@ -152,6 +152,8 @@
prob: 0.20
- id: DrinkSpaceLube
prob: 0.20
- id: BarberScissors
prob: 0.05
# Syndicate loot
- id: null
prob: 0.95

View File

@@ -0,0 +1,25 @@
- type: entity
id: BarberScissors
name: barber scissors
description: is able to reshape the hairstyle of any crew cut to your liking.
parent: BaseItem
components:
- type: Sprite
sprite: Objects/Tools/scissors.rsi
state: icon
- type: MagicMirror
- type: ActivatableUI
key: enum.MagicMirrorUiKey.Key
closeOnHandDeselect: true
- type: UserInterface
interfaces:
- key: enum.MagicMirrorUiKey.Key
type: MagicMirrorBoundUserInterface
- type: MeleeWeapon
wideAnimationRotation: -90
attackRate: 1
damage:
types:
Piercing: 6
soundHit:
path: "/Audio/Weapons/bladeslice.ogg"

Binary file not shown.

After

Width:  |  Height:  |  Size: 446 B

View File

@@ -0,0 +1,14 @@
{
"version": 1,
"license": "CC0-1.0",
"copyright": "Created by TheShuEd(github) for Space Station 14",
"size": {
"x": 32,
"y": 32
},
"states": [
{
"name": "icon"
}
]
}