Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New component AutoPostingChat(no Ready) #545

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions Content.Server/ADT/AutoPostingChat/AutoPostingChatSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
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 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 ChatSystem _chat = default!;
private System.Timers.Timer _speakTimer = new();
private System.Timers.Timer _emoteTimer = new();

public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<AutoPostingChatComponent, ComponentStartup>(OnComponentStartup);
SubscribeLocalEvent<AutoPostingChatComponent, MobStateChangedEvent>(OnMobState);
SubscribeLocalEvent<AutoPostingChatComponent, ComponentShutdown>(ComponentRemove);
}

private void ComponentRemove(EntityUid uid, AutoPostingChatComponent component, ComponentShutdown args)
{
_speakTimer.Stop();
_emoteTimer.Stop();
_speakTimer.Dispose(); // освобождаем ресурсы
_emoteTimer.Dispose();
}

/// <summary>
/// On death removes active comps.
/// </summary>
private void OnMobState(EntityUid uid, AutoPostingChatComponent component, MobStateChangedEvent args)
{
if (args.NewMobState == MobState.Dead || component == null)
Schrodinger71 marked this conversation as resolved.
Show resolved Hide resolved
{
RemComp<AutoPostingChatComponent>(uid);
}
}

private void OnComponentStartup(EntityUid uid, AutoPostingChatComponent component, ComponentStartup args)
{
// Проверяем наличие компонента AutoPostingChatComponent на сущности
if (component == null)
{
Log.Debug("AutoPostingChatComponent отсутствует на сущности с UID: " + uid);
return;
Schrodinger71 marked this conversation as resolved.
Show resolved Hide resolved
}

_speakTimer.Interval = component.SpeakTimerRead; // 8000 миллисекунд = 8 секунд по умолчанию
Schrodinger71 marked this conversation as resolved.
Show resolved Hide resolved
_speakTimer.Elapsed += (sender, eventArgs) =>
{
// Проверяем, что данные в компоненте были обновлены
if (component.PostingMessageSpeak != null)
{
_chat.TrySendInGameICMessage(uid, component.PostingMessageSpeak, InGameICChatType.Speak, ChatTransmitRange.Normal);
}
_speakTimer.Interval = component.SpeakTimerRead;
};
_emoteTimer.Interval = component.EmoteTimerRead; // 9000 миллисекунд = 9 секунд по умолчанию
_emoteTimer.Elapsed += (sender, eventArgs) =>
{
// Проверяем, что данные в компоненте были обновлены
if (component.PostingMessageEmote != null)
{
_chat.TrySendInGameICMessage(uid, component.PostingMessageEmote, InGameICChatType.Emote, ChatTransmitRange.Normal);
}
_emoteTimer.Interval = component.EmoteTimerRead;
};
// Запускаем таймеры
_speakTimer.Start();
_emoteTimer.Start();
}
}
31 changes: 31 additions & 0 deletions Content.Shared/ADT/AutoPostingChat/AutoPostingChatComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Robust.Shared.Audio;
using Content.Shared.Chat.Prototypes;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Shared.ADT.AutoPostingChat;
[RegisterComponent]
[NetworkedComponent]
public sealed partial class AutoPostingChatComponent : Component
{
/// <summary>
/// timings for giggles and knocks.
/// </summary>
//[ViewVariables(VVAccess.ReadWrite)]
//public TimeSpan DamageGiggleCooldown = TimeSpan.FromSeconds(2);
//[ViewVariables(VVAccess.ReadWrite)]
//public float KnockChance = 0.05f;
//[ViewVariables(VVAccess.ReadWrite)]
//public float GiggleRandomChance = 0.3f;

[ViewVariables(VVAccess.ReadWrite)]
public int SpeakTimerRead = 8000;

[ViewVariables(VVAccess.ReadWrite)]
public int EmoteTimerRead = 9000;
Schrodinger71 marked this conversation as resolved.
Show resolved Hide resolved

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

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