2021-03-21 09:12:03 -07:00
|
|
|
using Content.Shared.Audio;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Examine;
|
|
|
|
|
using Content.Shared.Interaction;
|
2021-06-28 16:20:57 +02:00
|
|
|
using Content.Shared.Sound;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Throwing;
|
2019-07-18 23:33:02 +02:00
|
|
|
using Robust.Server.GameObjects;
|
|
|
|
|
using Robust.Shared.Audio;
|
|
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
using Robust.Shared.IoC;
|
2019-10-13 22:49:07 +02:00
|
|
|
using Robust.Shared.Localization;
|
2021-03-21 09:12:03 -07:00
|
|
|
using Robust.Shared.Player;
|
2019-07-18 23:33:02 +02:00
|
|
|
using Robust.Shared.Prototypes;
|
2019-08-17 21:09:09 +02:00
|
|
|
using Robust.Shared.Random;
|
2021-03-05 01:08:38 +01:00
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2019-07-18 23:33:02 +02:00
|
|
|
using Robust.Shared.Utility;
|
|
|
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.Dice
|
2019-07-18 23:33:02 +02:00
|
|
|
{
|
2019-07-31 15:02:36 +02:00
|
|
|
[RegisterComponent]
|
2019-07-18 23:33:02 +02:00
|
|
|
public class DiceComponent : Component, IActivate, IUse, ILand, IExamine
|
|
|
|
|
{
|
2020-08-24 14:10:28 +02:00
|
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
|
|
|
|
[Dependency] private readonly IRobustRandom _random = default!;
|
2019-07-18 23:33:02 +02:00
|
|
|
|
|
|
|
|
public override string Name => "Dice";
|
|
|
|
|
|
|
|
|
|
private int _sides = 20;
|
2021-06-28 16:20:57 +02:00
|
|
|
|
2019-07-18 23:33:02 +02:00
|
|
|
[ViewVariables]
|
2021-06-28 16:20:57 +02:00
|
|
|
[DataField("sound")]
|
|
|
|
|
private readonly SoundSpecifier _sound = new SoundCollectionSpecifier("Dice");
|
|
|
|
|
|
2019-07-18 23:33:02 +02:00
|
|
|
[ViewVariables]
|
2021-06-28 16:20:57 +02:00
|
|
|
[DataField("step")]
|
|
|
|
|
public int Step { get; } = 1;
|
|
|
|
|
|
2019-07-18 23:33:02 +02:00
|
|
|
[ViewVariables]
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("sides")]
|
|
|
|
|
public int Sides
|
2019-07-18 23:33:02 +02:00
|
|
|
{
|
2021-03-05 01:08:38 +01:00
|
|
|
get => _sides;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_sides = value;
|
2021-06-28 16:20:57 +02:00
|
|
|
CurrentSide = value;
|
2021-03-05 01:08:38 +01:00
|
|
|
}
|
2019-07-18 23:33:02 +02:00
|
|
|
}
|
|
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
[ViewVariables]
|
2021-06-28 16:20:57 +02:00
|
|
|
public int CurrentSide { get; private set; } = 20;
|
2021-03-05 01:08:38 +01:00
|
|
|
|
2019-07-18 23:33:02 +02:00
|
|
|
public void Roll()
|
|
|
|
|
{
|
2021-06-28 16:20:57 +02:00
|
|
|
CurrentSide = _random.Next(1, (_sides/Step)+1) * Step;
|
|
|
|
|
|
2019-07-18 23:33:02 +02:00
|
|
|
PlayDiceEffect();
|
2021-06-28 16:20:57 +02:00
|
|
|
|
|
|
|
|
if (!Owner.TryGetComponent(out SpriteComponent? sprite))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
sprite.LayerSetState(0, $"d{_sides}{CurrentSide}");
|
2019-07-18 23:33:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void PlayDiceEffect()
|
|
|
|
|
{
|
2021-06-28 16:20:57 +02:00
|
|
|
SoundSystem.Play(Filter.Pvs(Owner), _sound.GetSound(), Owner, AudioParams.Default);
|
2019-07-18 23:33:02 +02:00
|
|
|
}
|
|
|
|
|
|
2021-02-04 17:44:49 +01:00
|
|
|
void IActivate.Activate(ActivateEventArgs eventArgs)
|
2019-07-18 23:33:02 +02:00
|
|
|
{
|
|
|
|
|
Roll();
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-04 17:44:49 +01:00
|
|
|
bool IUse.UseEntity(UseEntityEventArgs eventArgs)
|
2019-07-18 23:33:02 +02:00
|
|
|
{
|
|
|
|
|
Roll();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-04 17:44:49 +01:00
|
|
|
void ILand.Land(LandEventArgs eventArgs)
|
2019-07-18 23:33:02 +02:00
|
|
|
{
|
|
|
|
|
Roll();
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-31 19:29:06 +01:00
|
|
|
void IExamine.Examine(FormattedMessage message, bool inDetailsRange)
|
2019-07-18 23:33:02 +02:00
|
|
|
{
|
2020-05-31 19:29:06 +01:00
|
|
|
//No details check, since the sprite updates to show the side.
|
2021-06-21 02:13:54 +02:00
|
|
|
message.AddMarkup(Loc.GetString("dice-component-on-examine-message-part-1",
|
|
|
|
|
("sidesAmount", _sides))
|
|
|
|
|
+ "\n" +
|
|
|
|
|
Loc.GetString("dice-component-on-examine-message-part-2",
|
2021-06-28 16:20:57 +02:00
|
|
|
("currentSide", CurrentSide)));
|
2019-07-18 23:33:02 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|