Skip to content

Commit

Permalink
Разделил на функции
Browse files Browse the repository at this point in the history
  • Loading branch information
Schrodinger71 committed Jun 19, 2024
1 parent f548521 commit cc9b5c2
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 15 deletions.
56 changes: 45 additions & 11 deletions Content.Server/ADT/AutoPostingChat/AutoPostingChatSystem.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,23 @@
using Content.Server.Administration.Commands;
using Content.Server.Popups;
using Content.Shared.Popups;
using Content.Shared.Mobs;
using Content.Server.Chat;
using Content.Server.Chat.Systems;
using Content.Shared.Chat.Prototypes;
using Robust.Shared.Random;
using Content.Shared.Stunnable;
using Content.Shared.Damage.Prototypes;
using Content.Shared.Damage;
using Robust.Shared.Prototypes;
using Content.Server.Emoting.Systems;
using Content.Server.Speech.EntitySystems;
using Content.Shared.ADT.AutoPostingChat;
using Content.Shared.Interaction.Components;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
using System.Timers;
using System.ComponentModel;
using System.Linq;
//using System.Random;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
public sealed class AutoPostingChatSystem : EntitySystem
{
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
// [Dependency] private readonly DamageableSystem _damageableSystem = default!;
// [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly ChatSystem _chat = default!;
private System.Timers.Timer _speakTimer = new();
private System.Timers.Timer _emoteTimer = new();
Expand Down Expand Up @@ -67,6 +59,12 @@ private void OnComponentStartup(EntityUid uid, AutoPostingChatComponent componen
return;
}

SetupSpeakTimer(uid, component);
SetupEmoteTimer(uid, component);
}

private void SetupSpeakTimer(EntityUid uid, AutoPostingChatComponent component)
{
_speakTimer.Interval = component.RandomIntervalSpeak ? _random.Next(1000, 30001) : component.SpeakTimerRead;
_speakTimer.Elapsed += (sender, eventArgs) =>
{
Expand All @@ -77,6 +75,11 @@ private void OnComponentStartup(EntityUid uid, AutoPostingChatComponent componen
_speakTimer.Interval = component.RandomIntervalSpeak ? _random.Next(1000, 30001) : component.SpeakTimerRead;
};

_speakTimer.Start();
}

private void SetupEmoteTimer(EntityUid uid, AutoPostingChatComponent component)
{
_emoteTimer.Interval = component.RandomIntervalEmote ? _random.Next(1000, 30001) : component.EmoteTimerRead;
_emoteTimer.Elapsed += (sender, eventArgs) =>
{
Expand All @@ -87,7 +90,38 @@ private void OnComponentStartup(EntityUid uid, AutoPostingChatComponent componen
_emoteTimer.Interval = component.RandomIntervalEmote ? _random.Next(1000, 30001) : component.EmoteTimerRead;
};

_speakTimer.Start();
_emoteTimer.Start();
}

// private void OnComponentStartup(EntityUid uid, AutoPostingChatComponent component, ComponentStartup args)
// {
// if (component == null)
// {
// Log.Debug("AutoPostingChatComponent отсутствует на сущности с UID: " + uid);
// return;
// }

// _speakTimer.Interval = component.RandomIntervalSpeak ? _random.Next(1000, 30001) : component.SpeakTimerRead;
// _speakTimer.Elapsed += (sender, eventArgs) =>
// {
// if (component.PostingMessageSpeak != null)
// {
// _chat.TrySendInGameICMessage(uid, component.PostingMessageSpeak, InGameICChatType.Speak, ChatTransmitRange.Normal);
// }
// _speakTimer.Interval = component.RandomIntervalSpeak ? _random.Next(1000, 30001) : component.SpeakTimerRead;
// };

// _emoteTimer.Interval = component.RandomIntervalEmote ? _random.Next(1000, 30001) : component.EmoteTimerRead;
// _emoteTimer.Elapsed += (sender, eventArgs) =>
// {
// if (component.PostingMessageEmote != null)
// {
// _chat.TrySendInGameICMessage(uid, component.PostingMessageEmote, InGameICChatType.Emote, ChatTransmitRange.Normal);
// }
// _emoteTimer.Interval = component.RandomIntervalEmote ? _random.Next(1000, 30001) : component.EmoteTimerRead;
// };

// _speakTimer.Start();
// _emoteTimer.Start();
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ namespace Content.Shared.ADT.AutoPostingChat;
public sealed partial class AutoPostingChatComponent : Component
{
/// <summary>
/// Whether this destination is shown in the gateway ui.
/// If you are making a gateway for an admeme set this once you are ready for players to select it.
///Sets a random interval after each iteration of spoken messages
/// </summary>
[DataField("randomIntervalSpeak"), ViewVariables(VVAccess.ReadWrite)]
public bool RandomIntervalSpeak = false;

/// <summary>
/// Whether this destination is shown in the gateway ui.
/// If you are making a gateway for an admeme set this once you are ready for players to select it.
/// Sets a random interval after each iteration of spoken emotions
/// </summary>
[DataField("randomIntervalEmote"), ViewVariables(VVAccess.ReadWrite)]
public bool RandomIntervalEmote = false;
Expand Down

0 comments on commit cc9b5c2

Please sign in to comment.