Files
OldThink/Content.Server/Dice/DiceSystem.cs

29 lines
891 B
C#
Raw Normal View History

2023-01-21 12:51:26 +13:00
using Content.Shared.Dice;
using Content.Shared.Popups;
2021-08-20 09:51:48 +02:00
using JetBrains.Annotations;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
2021-08-20 09:51:48 +02:00
using Robust.Shared.Random;
2023-01-21 12:51:26 +13:00
namespace Content.Server.Dice;
2021-08-20 09:51:48 +02:00
2023-01-21 12:51:26 +13:00
[UsedImplicitly]
public sealed class DiceSystem : SharedDiceSystem
{
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
2023-01-21 12:51:26 +13:00
public override void Roll(EntityUid uid, DiceComponent? die = null)
{
if (!Resolve(uid, ref die))
return;
var roll = _random.Next(1, die.Sides + 1);
2023-01-21 12:51:26 +13:00
SetCurrentSide(uid, roll, die);
2023-01-21 12:51:26 +13:00
_popup.PopupEntity(Loc.GetString("dice-component-on-roll-land", ("die", uid), ("currentSide", die.CurrentValue)), uid);
_audio.PlayPvs(die.Sound, uid);
2021-08-20 09:51:48 +02:00
}
}