Skip to content

Commit

Permalink
SayPosting (#220)
Browse files Browse the repository at this point in the history
<!-- ЭТО ШАБЛОН ВАШЕГО PULL REQUEST. Текст между стрелками - это
комментарии - они не будут видны в PR. -->

## Описание PR
<!-- Ниже опишите ваш Pull Request. Что он изменяет? На что еще это
может повлиять? Постарайтесь описать все внесённые вами изменения! -->
Вешаем один из этих компонентов на сущность и она начинает постить в
зависимости от компоненты или эмоуты или слова


**Проверки**
<!-- Выполнение всех следующих действий, если это приемлемо для вида
изменений сильно ускорит разбор вашего PR -->
- [ ] PR полностью завершён и мне не нужна помощь чтобы его закончить.
- [x] Я внимательно просмотрел все свои изменения и багов в них не
нашёл.
- [x] Я запускал локальный сервер со своими изменениями и всё
протестировал.
- [ ] Я добавил скриншот/видео демонстрации PR в игре, **или** этот PR
этого не требует.

**Изменения**
no cl, no fun
  • Loading branch information
Schrodinger71 authored Sep 1, 2024
1 parent 1d81479 commit ad1f542
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 0 deletions.
51 changes: 51 additions & 0 deletions Content.Server/ADT/AutoPostingChat/AutoEmotePostingChatSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using Content.Shared.Mobs;
using Content.Server.Chat.Systems;
using Content.Shared.ADT.AutoPostingChat;
using Robust.Shared.Timing;
using Robust.Shared.Random;
public sealed class AutoEmotePostingChatSystem : EntitySystem
{
[Dependency] private readonly ChatSystem _chat = default!;
[Dependency] private readonly IGameTiming _time = default!;
[Dependency] private readonly IRobustRandom _random = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<AutoEmotePostingChatComponent, MobStateChangedEvent>(OnMobState);
}
/// <summary>
/// On death removes active comps and gives genetic damage to prevent cloning, reduce this to allow cloning.
/// </summary>
private void OnMobState(EntityUid uid, AutoEmotePostingChatComponent component, MobStateChangedEvent args)
{
if (args.NewMobState == MobState.Dead)
{
RemComp<AutoEmotePostingChatComponent>(uid);
}
}
public override void Update(float frameTime)
{
base.Update(frameTime);

var query = EntityQueryEnumerator<AutoEmotePostingChatComponent>();
while (query.MoveNext(out var uid, out var comp))
{
if (_time.CurTime >= comp.NextSecond)
{
var delay = comp.EmoteTimerRead;

if (comp.PostingMessageEmote != null)
{
_chat.TrySendInGameICMessage(uid, comp.PostingMessageEmote, InGameICChatType.Emote, ChatTransmitRange.Normal);
}

if (comp.RandomIntervalEmote)
{
delay = _random.Next(comp.IntervalRandomEmoteMin, comp.IntervalRandomEmoteMax);
}

comp.NextSecond = _time.CurTime + TimeSpan.FromSeconds(delay);
}
}
}
}
51 changes: 51 additions & 0 deletions Content.Server/ADT/AutoPostingChat/AutoSpeakPostingChatSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using Content.Shared.Mobs;
using Content.Server.Chat.Systems;
using Content.Shared.ADT.AutoPostingChat;
using Robust.Shared.Timing;
using Robust.Shared.Random;
public sealed class AutoSpeakPostingChatSystem : EntitySystem
{
[Dependency] private readonly ChatSystem _chat = default!;
[Dependency] private readonly IGameTiming _time = default!;
[Dependency] private readonly IRobustRandom _random = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<AutoSpeakPostingChatComponent, MobStateChangedEvent>(OnMobState);
}
/// <summary>
/// On death removes active comps and gives genetic damage to prevent cloning, reduce this to allow cloning.
/// </summary>
private void OnMobState(EntityUid uid, AutoSpeakPostingChatComponent component, MobStateChangedEvent args)
{
if (args.NewMobState == MobState.Dead)
{
RemComp<AutoSpeakPostingChatComponent>(uid);
}
}
public override void Update(float frameTime)
{
base.Update(frameTime);

var query = EntityQueryEnumerator<AutoSpeakPostingChatComponent>();
while (query.MoveNext(out var uid, out var comp))
{
if (_time.CurTime >= comp.NextSecond)
{
var delay = comp.SpeakTimerRead;

if (comp.PostingMessageSpeak != null)
{
_chat.TrySendInGameICMessage(uid, comp.PostingMessageSpeak, InGameICChatType.Speak, ChatTransmitRange.Normal);
}

if (comp.RandomIntervalSpeak)
{
delay = _random.Next(comp.IntervalRandomSpeakMin, comp.IntervalRandomSpeakMax);
}

comp.NextSecond = _time.CurTime + TimeSpan.FromSeconds(delay);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Robust.Shared.GameStates;

namespace Content.Shared.ADT.AutoPostingChat;

[RegisterComponent]
[NetworkedComponent]
public sealed partial class AutoEmotePostingChatComponent : Component
{

public TimeSpan NextSecond = TimeSpan.Zero;

[DataField("emoteTimer"), ViewVariables(VVAccess.ReadWrite)]
public int EmoteTimerRead = 9;

[DataField("emoteMessage")]
public string? PostingMessageEmote = "Кхе";

[DataField("randomIntervalEmote"), ViewVariables(VVAccess.ReadWrite)]
public bool RandomIntervalEmote = false;

[DataField("max"), ViewVariables(VVAccess.ReadWrite)]
public int IntervalRandomEmoteMax = 30;

[DataField("min"), ViewVariables(VVAccess.ReadWrite)]
public int IntervalRandomEmoteMin = 2;


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Robust.Shared.GameStates;

namespace Content.Shared.ADT.AutoPostingChat;

[RegisterComponent]
[NetworkedComponent]
public sealed partial class AutoSpeakPostingChatComponent : Component
{

public TimeSpan NextSecond = TimeSpan.Zero;

[DataField("speakTimer"), ViewVariables(VVAccess.ReadWrite)]
public int SpeakTimerRead = 10;

[DataField("speakMessage")]
public string? PostingMessageSpeak = "Вульп-вульп!";

[DataField("randomIntervalSpeak"), ViewVariables(VVAccess.ReadWrite)]
public bool RandomIntervalSpeak = false;

[DataField("max"), ViewVariables(VVAccess.ReadWrite)]
public int IntervalRandomSpeakMax = 30;

[DataField("min"), ViewVariables(VVAccess.ReadWrite)]
public int IntervalRandomSpeakMin = 2;



}

0 comments on commit ad1f542

Please sign in to comment.