2024-01-28 08:05:01 +03:00
|
|
|
using Content.Shared.Ghost;
|
|
|
|
|
using Content.Shared.Item;
|
|
|
|
|
using Content.Shared.Popups;
|
2024-01-28 18:37:24 +07:00
|
|
|
using Content.Shared._White.Cult.Components;
|
2024-02-08 18:44:02 +09:00
|
|
|
using Content.Shared.Inventory.Events;
|
|
|
|
|
using Content.Shared.Weapons.Melee.Events;
|
2024-01-28 08:05:01 +03:00
|
|
|
|
2024-01-28 18:37:24 +07:00
|
|
|
namespace Content.Shared._White.Cult.Systems;
|
2024-01-28 08:05:01 +03:00
|
|
|
|
|
|
|
|
public sealed class CultItemSystem : EntitySystem
|
|
|
|
|
{
|
|
|
|
|
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
|
|
|
|
|
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
|
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
|
|
|
SubscribeLocalEvent<CultItemComponent, GettingPickedUpAttemptEvent>(OnHandPickUp);
|
2024-02-08 18:44:02 +09:00
|
|
|
SubscribeLocalEvent<CultItemComponent, BeingEquippedAttemptEvent>(OnEquipAttempt);
|
|
|
|
|
SubscribeLocalEvent<CultItemComponent, AttemptMeleeEvent>(OnMeleeAttempt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnEquipAttempt(EntityUid uid, CultItemComponent component, BeingEquippedAttemptEvent args)
|
|
|
|
|
{
|
2024-02-24 23:18:25 +09:00
|
|
|
if (CanUse(args.Equipee) && CanUse(args.EquipTarget))
|
2024-02-08 18:44:02 +09:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
args.Cancel();
|
|
|
|
|
_popupSystem.PopupClient(Loc.GetString("cult-item-component-equip-fail"), uid, args.Equipee);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnMeleeAttempt(Entity<CultItemComponent> ent, ref AttemptMeleeEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (CanUse(args.User))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
args.Cancelled = true;
|
|
|
|
|
args.Message = Loc.GetString("cult-item-component-attack-fail");
|
2024-01-28 08:05:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnHandPickUp(EntityUid uid, CultItemComponent component, GettingPickedUpAttemptEvent args)
|
|
|
|
|
{
|
2024-02-08 18:44:02 +09:00
|
|
|
if (component.CanPickUp || CanUse(args.User))
|
2024-01-28 08:05:01 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
args.Cancel();
|
|
|
|
|
_transform.AttachToGridOrMap(uid);
|
2024-02-08 18:44:02 +09:00
|
|
|
_popupSystem.PopupClient(Loc.GetString("cult-item-component-pickup-fail", ("name", Name(uid))), uid, args.User);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-22 17:23:33 +09:00
|
|
|
public bool CanThrow(EntityUid player, EntityUid throwEnt)
|
|
|
|
|
{
|
|
|
|
|
if (!HasComp<CultItemComponent>(throwEnt) || CanUse(player))
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
_popupSystem.PopupEntity(Loc.GetString("cult-item-component-throw-fail"), player, player);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-08 18:44:02 +09:00
|
|
|
private bool CanUse(EntityUid? uid)
|
|
|
|
|
{
|
|
|
|
|
return HasComp<CultistComponent>(uid) || HasComp<GhostComponent>(uid);
|
2024-01-28 08:05:01 +03:00
|
|
|
}
|
|
|
|
|
}
|