DrunkSystem.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using Content.Shared.Speech.EntitySystems;
  2. using Content.Shared.StatusEffect;
  3. using Content.Shared.Traits.Assorted;
  4. namespace Content.Shared.Drunk;
  5. public abstract class SharedDrunkSystem : EntitySystem
  6. {
  7. [ValidatePrototypeId<StatusEffectPrototype>]
  8. public const string DrunkKey = "Drunk";
  9. [Dependency] private readonly StatusEffectsSystem _statusEffectsSystem = default!;
  10. [Dependency] private readonly SharedSlurredSystem _slurredSystem = default!;
  11. public void TryApplyDrunkenness(EntityUid uid, float boozePower, bool applySlur = true,
  12. StatusEffectsComponent? status = null)
  13. {
  14. if (!Resolve(uid, ref status, false))
  15. return;
  16. if (TryComp<LightweightDrunkComponent>(uid, out var trait))
  17. boozePower *= trait.BoozeStrengthMultiplier;
  18. if (applySlur)
  19. {
  20. _slurredSystem.DoSlur(uid, TimeSpan.FromSeconds(boozePower), status);
  21. }
  22. if (!_statusEffectsSystem.HasStatusEffect(uid, DrunkKey, status))
  23. {
  24. _statusEffectsSystem.TryAddStatusEffect<DrunkComponent>(uid, DrunkKey, TimeSpan.FromSeconds(boozePower), true, status);
  25. }
  26. else
  27. {
  28. _statusEffectsSystem.TryAddTime(uid, DrunkKey, TimeSpan.FromSeconds(boozePower), status);
  29. }
  30. }
  31. public void TryRemoveDrunkenness(EntityUid uid)
  32. {
  33. _statusEffectsSystem.TryRemoveStatusEffect(uid, DrunkKey);
  34. }
  35. public void TryRemoveDrunkenessTime(EntityUid uid, double timeRemoved)
  36. {
  37. _statusEffectsSystem.TryRemoveTime(uid, DrunkKey, TimeSpan.FromSeconds(timeRemoved));
  38. }
  39. }