Christmas trees now grant gifts. (#13118)
* Christmas trees now grant gifts. * docs * add holiday requirements, fix sound. * doc * remove redundant stuff * rename GiftPackin to RandomGift. * a word * Update Content.Server/Holiday/Christmas/LimitedItemGiverSystem.cs Co-authored-by: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Co-authored-by: moonheart08 <moonheart08@users.noreply.github.com> Co-authored-by: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com>
This commit is contained in:
50
Content.Server/Holiday/Christmas/LimitedItemGiverSystem.cs
Normal file
50
Content.Server/Holiday/Christmas/LimitedItemGiverSystem.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using Content.Server.Hands.Systems;
|
||||
using Content.Server.Mind.Components;
|
||||
using Content.Server.Popups;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Storage;
|
||||
using Robust.Server.GameObjects;
|
||||
|
||||
namespace Content.Server.Holiday.Christmas;
|
||||
|
||||
/// <summary>
|
||||
/// This handles handing out items from item givers.
|
||||
/// </summary>
|
||||
public sealed class LimitedItemGiverSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly HandsSystem _hands = default!;
|
||||
[Dependency] private readonly HolidaySystem _holiday = default!;
|
||||
[Dependency] private readonly PopupSystem _popup = default!;
|
||||
/// <inheritdoc/>
|
||||
public override void Initialize()
|
||||
{
|
||||
SubscribeLocalEvent<LimitedItemGiverComponent, InteractHandEvent>(OnInteractHand);
|
||||
}
|
||||
|
||||
private void OnInteractHand(EntityUid uid, LimitedItemGiverComponent component, InteractHandEvent args)
|
||||
{
|
||||
if (!TryComp<ActorComponent>(args.User, out var actor))
|
||||
return;
|
||||
|
||||
if (component.GrantedPlayers.Contains(actor.PlayerSession.UserId) || (component.RequiredHoliday is not null && !_holiday.IsCurrentlyHoliday(component.RequiredHoliday)))
|
||||
{
|
||||
_popup.PopupEntity(Loc.GetString(component.DeniedPopup), uid, args.User);
|
||||
return;
|
||||
}
|
||||
|
||||
var toGive = EntitySpawnCollection.GetSpawns(component.SpawnEntries);
|
||||
var coords = Transform(args.User).Coordinates;
|
||||
|
||||
foreach (var item in toGive)
|
||||
{
|
||||
if (item is null)
|
||||
continue;
|
||||
|
||||
var spawned = Spawn(item, coords);
|
||||
_hands.PickupOrDrop(args.User, spawned);
|
||||
}
|
||||
|
||||
component.GrantedPlayers.Add(actor.PlayerSession.UserId);
|
||||
_popup.PopupEntity(Loc.GetString(component.ReceivedPopup), uid, args.User);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user