Dice roll popup, some DiceSystem cleanup.
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
using System;
|
||||
using Content.Server.Notification;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Interaction;
|
||||
@@ -22,23 +24,17 @@ namespace Content.Server.Dice
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<DiceComponent, ComponentInit>(OnComponentInit);
|
||||
SubscribeLocalEvent<DiceComponent, ActivateInWorldEvent>(OnActivate);
|
||||
SubscribeLocalEvent<DiceComponent, UseInHandEvent>(OnUse);
|
||||
SubscribeLocalEvent<DiceComponent, LandEvent>(OnLand);
|
||||
SubscribeLocalEvent<DiceComponent, ExaminedEvent>(OnExamined);
|
||||
}
|
||||
|
||||
public void Roll(EntityUid uid, DiceComponent die)
|
||||
private void OnComponentInit(EntityUid uid, DiceComponent component, ComponentInit args)
|
||||
{
|
||||
die.CurrentSide = _random.Next(1, (die.Sides/die.Step)+1) * die.Step;
|
||||
|
||||
SoundSystem.Play(Filter.Pvs(die.Owner), die.Sound.GetSound(), die.Owner, AudioHelpers.WithVariation(0.05f));
|
||||
|
||||
if (!ComponentManager.TryGetComponent(uid, out SpriteComponent? sprite))
|
||||
return;
|
||||
|
||||
// TODO DICE: Use a visualizer instead.
|
||||
sprite.LayerSetState(0, $"d{die.Sides}{die.CurrentSide}");
|
||||
if (component.CurrentSide > component.Sides)
|
||||
component.CurrentSide = component.Sides;
|
||||
}
|
||||
|
||||
private void OnActivate(EntityUid uid, DiceComponent component, ActivateInWorldEvent args)
|
||||
@@ -62,5 +58,31 @@ namespace Content.Server.Dice
|
||||
args.PushMarkup(Loc.GetString("dice-component-on-examine-message-part-1", ("sidesAmount", dice.Sides)));
|
||||
args.PushMarkup(Loc.GetString("dice-component-on-examine-message-part-2", ("currentSide", dice.CurrentSide)));
|
||||
}
|
||||
|
||||
public void SetCurrentSide(EntityUid uid, int side, DiceComponent? die = null, SpriteComponent? sprite = null)
|
||||
{
|
||||
if (!Resolve(uid, ref die, ref sprite))
|
||||
return;
|
||||
|
||||
side = Math.Min(Math.Max(side, 1), die.Sides);
|
||||
side += side % die.Step;
|
||||
|
||||
die.CurrentSide = side;
|
||||
|
||||
// TODO DICE: Use a visualizer instead.
|
||||
sprite.LayerSetState(0, $"d{die.Sides}{die.CurrentSide}");
|
||||
}
|
||||
|
||||
public void Roll(EntityUid uid, DiceComponent? die = null)
|
||||
{
|
||||
if (!Resolve(uid, ref die))
|
||||
return;
|
||||
|
||||
var roll = _random.Next(1, die.Sides/die.Step+1) * die.Step;
|
||||
SetCurrentSide(uid, roll, die);
|
||||
|
||||
die.Owner.PopupMessageEveryone(Loc.GetString("dice-component-on-roll-land", ("die", die.Owner), ("currentSide", die.CurrentSide)));
|
||||
SoundSystem.Play(Filter.Pvs(die.Owner), die.Sound.GetSound(), die.Owner, AudioHelpers.WithVariation(0.05f));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user