-
Notifications
You must be signed in to change notification settings - Fork 55
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
Schrodinger71
wants to merge
16
commits into
AdventureTimeSS14:master
Choose a base branch
from
Schrodinger71:say_postingg_3
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 15 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
9771e1a
Add new component
Schrodinger71 ecb511d
Ну собственно всё прописал
Schrodinger71 3b0868f
Update AutoPostingChatSystem.cs
Schrodinger71 09d89de
Правки
Schrodinger71 31fe203
И тут
Schrodinger71 90c559a
Merge branch 'say_postingg_3' of https://github.com/Schrodinger71/spa…
modern-nm 115cc61
vv timers edit now work properly
modern-nm f3732df
vv timers edit now work properly
modern-nm 6588114
hz
Schrodinger71 088ced8
Итоговые изменения
Schrodinger71 9bd8ada
меняем имена переменных
Schrodinger71 1d4c5de
Вот теперь точно всё, освобождаем ресурсы и небольшая проверка
Schrodinger71 3563f18
Добавлен флаг рандомного интервала отправки сообщений в пределах 1-30…
Schrodinger71 f548521
Добавил поля для YAML файлов.
Schrodinger71 cc9b5c2
Разделил на функции
Schrodinger71 aa920ca
Правки
Schrodinger71 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
127 changes: 127 additions & 0 deletions
127
Content.Server/ADT/AutoPostingChat/AutoPostingChatSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
using Content.Server.Administration.Commands; | ||
using Content.Shared.Mobs; | ||
using Content.Server.Chat; | ||
using Content.Server.Chat.Systems; | ||
using Content.Shared.Chat.Prototypes; | ||
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 System.Timers; | ||
using System.ComponentModel; | ||
using System.Linq; | ||
using Robust.Shared.Timing; | ||
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(); | ||
private readonly Random _random = new Random(); | ||
//private static readonly Random _random = new Random(); | ||
|
||
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) | ||
{ | ||
if (component == null) | ||
{ | ||
Log.Debug("AutoPostingChatComponent отсутствует на сущности с UID: " + uid); | ||
return; | ||
Schrodinger71 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
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) => | ||
{ | ||
if (component.PostingMessageSpeak != null) | ||
{ | ||
_chat.TrySendInGameICMessage(uid, component.PostingMessageSpeak, InGameICChatType.Speak, ChatTransmitRange.Normal); | ||
} | ||
_speakTimer.Interval = component.RandomIntervalSpeak ? _random.Next(1000, 30001) : component.SpeakTimerRead; | ||
Schrodinger71 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
|
||
_speakTimer.Start(); | ||
} | ||
|
||
private void SetupEmoteTimer(EntityUid uid, AutoPostingChatComponent component) | ||
{ | ||
_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; | ||
}; | ||
|
||
_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(); | ||
// } | ||
} |
47 changes: 47 additions & 0 deletions
47
Content.Shared/ADT/AutoPostingChat/AutoPostingChatComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
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> | ||
///Sets a random interval after each iteration of spoken messages | ||
/// </summary> | ||
[DataField("randomIntervalSpeak"), ViewVariables(VVAccess.ReadWrite)] | ||
public bool RandomIntervalSpeak = false; | ||
|
||
/// <summary> | ||
/// Sets a random interval after each iteration of spoken emotions | ||
/// </summary> | ||
[DataField("randomIntervalEmote"), ViewVariables(VVAccess.ReadWrite)] | ||
public bool RandomIntervalEmote = false; | ||
Schrodinger71 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/// <summary> | ||
/// The interval in milliseconds between automatic speech messages. | ||
/// </summary> | ||
[ViewVariables(VVAccess.ReadWrite)] | ||
[DataField("speakTimer")] | ||
public int SpeakTimerRead = 8000; | ||
|
||
/// <summary> | ||
/// The interval in milliseconds between automatic emote messages. | ||
/// </summary> | ||
[ViewVariables(VVAccess.ReadWrite)] | ||
[DataField("emoteTimer")] | ||
public int EmoteTimerRead = 9000; | ||
Schrodinger71 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/// <summary> | ||
/// The message that will be automatically spoken by the entity. | ||
/// </summary> | ||
[DataField("speakMessage")] | ||
public string? PostingMessageSpeak = ""; | ||
|
||
/// <summary> | ||
/// The message that will be automatically emotes by the entity. | ||
/// </summary> | ||
[DataField("emoteMessage")] | ||
public string? PostingMessageEmote = ""; | ||
Schrodinger71 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Таймеры в системе? Обычно они находятся в компоненте, и не являются System.Timers.Timer, как и рандом.
Рандом используется как Dependency IRobustRandom, или чего-то такого. Посмотри примеры, пожалуйста