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.Audio;
|
||||||
using Content.Shared.Examine;
|
using Content.Shared.Examine;
|
||||||
using Content.Shared.Interaction;
|
using Content.Shared.Interaction;
|
||||||
@@ -22,23 +24,17 @@ namespace Content.Server.Dice
|
|||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
|
|
||||||
|
SubscribeLocalEvent<DiceComponent, ComponentInit>(OnComponentInit);
|
||||||
SubscribeLocalEvent<DiceComponent, ActivateInWorldEvent>(OnActivate);
|
SubscribeLocalEvent<DiceComponent, ActivateInWorldEvent>(OnActivate);
|
||||||
SubscribeLocalEvent<DiceComponent, UseInHandEvent>(OnUse);
|
SubscribeLocalEvent<DiceComponent, UseInHandEvent>(OnUse);
|
||||||
SubscribeLocalEvent<DiceComponent, LandEvent>(OnLand);
|
SubscribeLocalEvent<DiceComponent, LandEvent>(OnLand);
|
||||||
SubscribeLocalEvent<DiceComponent, ExaminedEvent>(OnExamined);
|
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;
|
if (component.CurrentSide > component.Sides)
|
||||||
|
component.CurrentSide = component.Sides;
|
||||||
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}");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnActivate(EntityUid uid, DiceComponent component, ActivateInWorldEvent args)
|
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-1", ("sidesAmount", dice.Sides)));
|
||||||
args.PushMarkup(Loc.GetString("dice-component-on-examine-message-part-2", ("currentSide", dice.CurrentSide)));
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
5
Resources/Changelog/Parts/dice.yml
Normal file
5
Resources/Changelog/Parts/dice.yml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
author: Zumorica
|
||||||
|
changes:
|
||||||
|
- type: Tweak # One of the following: Add, Remove, Tweak, Fix
|
||||||
|
message: Dice now show a popup with the number they rolled when used.
|
||||||
|
|
||||||
@@ -1,2 +1,3 @@
|
|||||||
dice-component-on-examine-message-part-1 = A die with [color=lightgray]{$sidesAmount}[/color] sides.
|
dice-component-on-examine-message-part-1 = A die with [color=lightgray]{$sidesAmount}[/color] sides.
|
||||||
dice-component-on-examine-message-part-2 = It has landed on a [color=white]{$currentSide}[/color].
|
dice-component-on-examine-message-part-2 = It has landed on a [color=white]{$currentSide}[/color].
|
||||||
|
dice-component-on-roll-land = { CAPITALIZE(THE($die)) } lands on a {$currentSide}.
|
||||||
|
|||||||
Reference in New Issue
Block a user