GiveItemOnHolidaySpecial.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using Content.Server.Holiday;
  2. using Content.Shared.Hands.EntitySystems;
  3. using Content.Shared.Roles;
  4. using JetBrains.Annotations;
  5. using Robust.Shared.Prototypes;
  6. using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
  7. namespace Content.Server.Jobs
  8. {
  9. [UsedImplicitly]
  10. [DataDefinition]
  11. public sealed partial class GiveItemOnHolidaySpecial : JobSpecial
  12. {
  13. [DataField("holiday", customTypeSerializer:typeof(PrototypeIdSerializer<HolidayPrototype>))]
  14. public string Holiday { get; private set; } = string.Empty;
  15. [DataField("prototype", customTypeSerializer:typeof(PrototypeIdSerializer<EntityPrototype>))]
  16. public string Prototype { get; private set; } = string.Empty;
  17. public override void AfterEquip(EntityUid mob)
  18. {
  19. if (string.IsNullOrEmpty(Holiday) || string.IsNullOrEmpty(Prototype))
  20. return;
  21. var sysMan = IoCManager.Resolve<IEntitySystemManager>();
  22. if (!sysMan.GetEntitySystem<HolidaySystem>().IsCurrentlyHoliday(Holiday))
  23. return;
  24. var entMan = IoCManager.Resolve<IEntityManager>();
  25. var entity = entMan.SpawnEntity(Prototype, entMan.GetComponent<TransformComponent>(mob).Coordinates);
  26. sysMan.GetEntitySystem<SharedHandsSystem>().PickupOrDrop(mob, entity);
  27. }
  28. }
  29. }