Skip to content

Commit 74f95fc

Browse files
authored
Add files via upload
1 parent a9434de commit 74f95fc

File tree

5 files changed

+153
-58
lines changed

5 files changed

+153
-58
lines changed

EffectDisplay/Components/UserEffectDisplayer.cs

Lines changed: 59 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@
66

77
using MEC;
88

9+
using System;
910
using System.Collections.Generic;
1011
using System.Linq;
12+
using System.Linq.Expressions;
1113
using System.Text;
1214
using UnityEngine;
1315

1416
namespace EffectDisplay.Components
1517
{
1618
public class UserEffectDisplayer: MonoBehaviour
1719
{
18-
private MeowHintManager MeowHintManager;
20+
private MeowHintManager meow;
1921
private Player player;
2022
/// <summary>
2123
/// Stores the current process for future stopping
@@ -54,10 +56,6 @@ private void Awake()
5456
Log.Debug($"{nameof(Awake)}: Starting Corountine.");
5557
Timing.RunCoroutine(PlayerEffectShower());
5658
}
57-
if (Plugin.HintServiceMeowDetected)
58-
{
59-
MeowHintManager = new MeowHintManager();
60-
}
6159
else
6260
{
6361
this.IsEnabled = false;
@@ -66,17 +64,29 @@ private void Awake()
6664
}
6765
}
6866

67+
private void ShowMeowHint(string text)
68+
{
69+
if (meow != null)
70+
{
71+
MeowHintManager.RemoveHint(player, meow.GetHintProcessionObject());
72+
meow = null;
73+
}
74+
meow = new MeowHintManager(text, "EffectDisplay", Plugin.Instance.Config.MeowHintSettings);
75+
MeowHintManager.AddHint(player, meow.GetHintProcessionObject());
76+
}
77+
6978
private IEnumerator<float> PlayerEffectShower()
7079
{
71-
bool showing = false;
7280
for (; ; )
7381
{
7482
if (player == null)
7583
{
84+
Log.Debug($"{nameof(PlayerEffectShower)}: Player is null break yield");
7685
yield break;
7786
}
7887
if (IsEnabled == false)
7988
{
89+
Log.Debug($"{nameof(PlayerEffectShower)}: IsEnabled - {IsEnabled} disabled, break yield");
8090
yield break;
8191
}
8292
if (player.IsDead | Plugin.Instance.Config.IgnoredRoles.Contains(player.Role.Type))
@@ -86,53 +96,60 @@ private IEnumerator<float> PlayerEffectShower()
8696
}
8797
if (player.ActiveEffects.Where(x => !Plugin.Instance.Config.BlackList.Contains(x.GetEffectType())).Count() == 0)
8898
{
89-
MeowHintManager.RemoveHint(player, MeowHintManager.GetHintProcessionObject());
90-
showing = false;
99+
if (meow != null)
100+
{
101+
meow = null;
102+
}
91103
yield return Timing.WaitForSeconds(0.1f);
92104
continue;
93105
}
94-
if (Plugin.HintServiceMeowDetected & showing)
95-
{
96-
MeowHintManager.RemoveHint(player, MeowHintManager.GetHintProcessionObject());
97-
showing = false;
98-
}
99106
StringBuilder InfoLine = new StringBuilder();
100-
if (!Plugin.HintServiceMeowDetected)
101-
{
102-
InfoLine.Append("\n\n\n\n");
103-
InfoLine.AppendLine($"<size={Plugin.Instance.Config.NativeHintSettings.FontSize}><align={Plugin.Instance.Config.NativeHintSettings.Aligment.ToLower()}>");
104-
}
105107
foreach (var item in player.ActiveEffects)
106108
{
107-
if (Plugin.Instance.Config.BlackList.Contains(item.GetEffectType())) continue;
108-
string processingline = Plugin.Instance.Config.EffectLine[item.Classification];
109-
if (string.IsNullOrEmpty(processingline)) continue;
110-
processingline = processingline.Replace("%time%", ((int)item.TimeLeft) == 0 ? string.Empty : ((int)item.TimeLeft).ToString());
111-
processingline = processingline.Replace("%duration%", item.Duration == 0 ? "inf" : ((int)item.Duration).ToString());
112-
processingline = processingline.Replace("%effect%", Plugin.Instance.Config.GetName(item.GetEffectType()));
113-
processingline = processingline.Replace("%intensity%", item.Intensity.ToString());
114-
InfoLine.AppendLine(processingline);
109+
try
110+
{
111+
if (Plugin.Instance.Config.BlackList.Contains(item.GetEffectType())) continue;
112+
try
113+
{
114+
string processingline = Plugin.Instance.Config.EffectLine[item.Classification];
115+
if (string.IsNullOrEmpty(processingline)) continue;
116+
processingline = processingline.Replace("%time%", item.Duration == 0 ? "inf" : ((int)item.TimeLeft).ToString());
117+
processingline = processingline.Replace("%duration%", item.Duration == 0 ? "inf" : item.Duration.ToString());
118+
processingline = processingline.Replace("%effect%", Plugin.Instance.Config.GetName(item.GetEffectType()));
119+
processingline = processingline.Replace("%intensity%", item.Intensity.ToString());
120+
Log.Debug($"{nameof(PlayerEffectShower)}: Line {processingline} created");
121+
InfoLine.AppendLine(processingline);
122+
}
123+
catch (Exception e)
124+
{
125+
Log.Debug($"{nameof(PlayerEffectShower)}: Exception {e.Message}");
126+
}
127+
}
128+
catch (Exception e)
129+
{
130+
Log.Debug($"{nameof(PlayerEffectShower)}: Exception {e.Message}");
131+
}
115132
}
116-
if (Plugin.HintServiceMeowDetected)
133+
string data = InfoLine.ToString();
134+
Log.Debug(data);
135+
try
117136
{
118-
MeowHintManager = new MeowHintManager();
119-
MeowHintManager.SetText(InfoLine.ToString());
120-
MeowHintManager.SetId("EffectDisplay");
121-
MeowHintManager.SetFont(Plugin.Instance.Config.MeowHintSettings.FontSize);
122-
MeowHintManager.SetHorizontalAligment(Plugin.Instance.Config.MeowHintSettings.Aligment);
123-
MeowHintManager.SetVerticalAligment(Plugin.Instance.Config.MeowHintSettings.VerticalAligment);
124-
MeowHintManager.SetYCoordinates(Plugin.Instance.Config.MeowHintSettings.YCoordinate);
125-
MeowHintManager.SetXCoordinate(Plugin.Instance.Config.MeowHintSettings.XCoordinate);
126-
MeowHintManager.AddHint(player, MeowHintManager.GetHintProcessionObject());
127-
showing = true;
137+
if (Plugin.HintServiceMeowDetected)
138+
{
139+
ShowMeowHint(data);
140+
}
141+
else
142+
{
143+
data = $"<size={Plugin.Instance.Config.NativeHintSettings.FontSize}><align={Plugin.Instance.Config.NativeHintSettings.Aligment}>" + data + "</size></align>";
144+
player.ShowHint(data, 1 + (player.Ping / 100)); // display a message taking into account the player's ping for a smooth update
145+
}
128146
}
129-
else if (!Plugin.HintServiceMeowDetected)
147+
catch (Exception e)
130148
{
131-
string res = InfoLine.ToString() + "</size></align>";
132-
player.ShowHint(res, (float)Plugin.Instance.Config.UpdateTime);
149+
Log.Debug($"{nameof(PlayerEffectShower)}: Exception {e.Message}");
133150
}
134-
Log.Debug($"Iteration {player.Nickname}: processed.");
135-
yield return Timing.WaitForSeconds((float)Plugin.Instance.Config.UpdateTime);
151+
Log.Debug($"{nameof(PlayerEffectShower)}: Iteration {player.Nickname}: processed.");
152+
yield return Timing.WaitForSeconds(Plugin.Instance.Config.UpdateTime);
136153
}
137154
}
138155
}

EffectDisplay/Configs.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,21 @@ public class Configs: IConfig
2323
[Description("will a database be used")]
2424
public bool IsDatabaseUse { get; set; } = true;
2525
[Description("the time period for which information is updated")]
26-
public double UpdateTime { get; set; } = 0.9;
26+
public float UpdateTime { get; set; } = 0.9f;
2727
[Description("these lines will be displayed for each effect type separately, allowing you to customize them")]
2828
public Dictionary<StatusEffectBase.EffectClassification, string> EffectLine { get; set; } = new Dictionary<StatusEffectBase.EffectClassification, string>()
2929
{
30-
{StatusEffectBase.EffectClassification.Mixed, $"<color=\"purple\">%effect%</color> -> %time%/%duration% LVL: %intensity%" },
31-
{StatusEffectBase.EffectClassification.Positive, $"<color=\"green\">%effect%</color> -> %time%/%duration% LVL: %intensity%" },
32-
{StatusEffectBase.EffectClassification.Negative, $"<color=\"red\">%effect%</color> -> %time%/%duration% LVL: %intensity%" }
30+
{StatusEffectBase.EffectClassification.Mixed, $"<color=purple>%effect%</color> -> %time%/%duration% LVL: %intensity%" },
31+
{StatusEffectBase.EffectClassification.Positive, $"<color=green>%effect%</color> -> %time%/%duration% LVL: %intensity%" },
32+
{StatusEffectBase.EffectClassification.Negative, $"<color=red>%effect%</color> -> %time%/%duration% LVL: %intensity%" },
33+
{StatusEffectBase.EffectClassification.Technical, " " }
3334
};
3435
[Description("defines a list of effects that the player will not see (the effects of the technical process are hidden)")]
3536
public List<EffectType> BlackList { get; set; } = new List<EffectType>()
3637
{
3738
EffectType.InsufficientLighting,
38-
EffectType.SoundtrackMute
39+
EffectType.SoundtrackMute,
40+
EffectType.FogControl
3941
};
4042
[Description("https://discord.com/channels/656673194693885975/1172647045237067788/1172647045237067788 determines the name of the effect from the existing list to the one you specify")]
4143
public Dictionary<EffectType, string> EffectTranslation { get; set; } = new Dictionary<EffectType, string>()

EffectDisplay/EffectDisplay.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
3434
<DebugSymbols>true</DebugSymbols>
3535
<OutputPath>bin\x64\Debug\</OutputPath>
36-
<DefineConstants>TRACE;DEBUG;HINTSERVICEMEOW</DefineConstants>
36+
<DefineConstants>TRACE</DefineConstants>
3737
<DebugType>full</DebugType>
3838
<PlatformTarget>x64</PlatformTarget>
3939
<LangVersion>7.3</LangVersion>
@@ -119,6 +119,7 @@
119119
</ItemGroup>
120120
<ItemGroup>
121121
<Compile Include="commands\display.cs" />
122+
<Compile Include="commands\test.cs" />
122123
<Compile Include="Components\UserEffectDisplayer.cs" />
123124
<Compile Include="Configs.cs" />
124125
<Compile Include="EventHandler\PlayerEvent.cs" />

EffectDisplay/Features/MeowHintManager.cs

Lines changed: 83 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
using System.Linq;
66

77
using Exiled.Loader;
8+
using EffectDisplay.Features.Sereliazer;
89

10+
/// <summary>
11+
/// Provides work with the service by providing hints for multi-transmissions
12+
/// </summary>
913
public class MeowHintManager
1014
{
1115
private static Assembly meowhints;
@@ -14,7 +18,7 @@ public class MeowHintManager
1418
private Type VerticalAligmentType;
1519
private object HintInstance;
1620
/// <summary>
17-
/// Creates all the necessary types to work with HintServiceMeow
21+
/// Creates an instance of a class without any default settings.
1822
/// </summary>
1923
public MeowHintManager()
2024
{
@@ -32,7 +36,67 @@ public MeowHintManager()
3236
if (VerticalAligmentType == null | !VerticalAligmentType.IsEnum) throw new Exception("HintVerticalAligment not found or is not Enum type");
3337
}
3438
/// <summary>
35-
/// Exposes a parameter to the main Hint instance with the appropriate name
39+
/// Creates an instance of a class with preset parameters that can be retrieved without extra methods
40+
/// </summary>
41+
/// <param name="text">Hint text</param>
42+
/// <param name="fontsize">Text font size</param>
43+
/// <param name="valign">Vertical aligment (Left, Center, Right)</param>
44+
/// <param name="halign">Horizontal aligment (Top, Middle, Bottom)</param>
45+
/// <param name="y">Y Coordinate position (0 : 1080)</param>
46+
/// <param name="x">X Coordinate position (-1200 : 1200)</param>
47+
/// <param name="id">Hint work id</param>
48+
public MeowHintManager(string text, int fontsize = 16, string valign = "Center", string halign = "Middle", int y = 0, int x = 0, string id = "HintGeneration")
49+
{
50+
if (meowhints == null)
51+
{
52+
meowhints = Loader.Plugins.Where(xp => xp.Name == "HintServiceMeow").FirstOrDefault().Assembly;
53+
}
54+
if (meowhints == null) throw new Exception("Assembly HintServiceMeow not loaded in Exiled plugins");
55+
Hint = meowhints.GetType("HintServiceMeow.Core.Models.Hints.Hint", false);
56+
if (Hint == null) throw new Exception("Type Hint not found");
57+
HintInstance = Activator.CreateInstance(Hint);
58+
HorizantalAligmentType = meowhints.GetType("HintServiceMeow.Core.Enum.HintAlignment");
59+
if (HorizantalAligmentType == null | !HorizantalAligmentType.IsEnum) throw new Exception("HintAligment not found or is not Enum type");
60+
VerticalAligmentType = meowhints.GetType("HintServiceMeow.Core.Enum.HintVerticalAlign");
61+
if (VerticalAligmentType == null | !VerticalAligmentType.IsEnum) throw new Exception("HintVerticalAligment not found or is not Enum type");
62+
SetText(text);
63+
SetFont(fontsize);
64+
SetVerticalAligment(valign);
65+
SetHorizontalAligment(halign);
66+
SetId(id);
67+
SetXCoordinate(x);
68+
SetYCoordinates(y);
69+
}
70+
/// <summary>
71+
/// Creates an instance of a class with predefined parameters from <see cref="MeowHintSettings"/>
72+
/// </summary>
73+
/// <param name="text">Hint text</param>
74+
/// <param name="id">Hint work id</param>
75+
/// <param name="settings">Class providing settings</param>
76+
public MeowHintManager(string text, string id, MeowHintSettings settings)
77+
{
78+
if (meowhints == null)
79+
{
80+
meowhints = Loader.Plugins.Where(xp => xp.Name == "HintServiceMeow").FirstOrDefault().Assembly;
81+
}
82+
if (meowhints == null) throw new Exception("Assembly HintServiceMeow not loaded in Exiled plugins");
83+
Hint = meowhints.GetType("HintServiceMeow.Core.Models.Hints.Hint", false);
84+
if (Hint == null) throw new Exception("Type Hint not found");
85+
HintInstance = Activator.CreateInstance(Hint);
86+
HorizantalAligmentType = meowhints.GetType("HintServiceMeow.Core.Enum.HintAlignment");
87+
if (HorizantalAligmentType == null | !HorizantalAligmentType.IsEnum) throw new Exception("HintAligment not found or is not Enum type");
88+
VerticalAligmentType = meowhints.GetType("HintServiceMeow.Core.Enum.HintVerticalAlign");
89+
if (VerticalAligmentType == null | !VerticalAligmentType.IsEnum) throw new Exception("HintVerticalAligment not found or is not Enum type");
90+
SetText(text);
91+
SetFont(settings.FontSize);
92+
SetVerticalAligment(settings.VerticalAligment);
93+
SetHorizontalAligment(settings.Aligment);
94+
SetId(id);
95+
SetXCoordinate(settings.XCoordinate);
96+
SetYCoordinates(settings.YCoordinate);
97+
}
98+
/// <summary>
99+
/// Sets the text size parameter in the working class hint
36100
/// </summary>
37101
public void SetFont(int FontSize)
38102
{
@@ -46,7 +110,7 @@ public void SetFont(int FontSize)
46110
}
47111
}
48112
/// <summary>
49-
/// Exposes a parameter to the main Hint instance with the appropriate name
113+
/// Sets the text parameter that will be displayed
50114
/// </summary>
51115
public void SetText(string Text)
52116
{
@@ -60,8 +124,9 @@ public void SetText(string Text)
60124
}
61125
}
62126
/// <summary>
63-
/// Exposes a parameter to the main Hint instance with the appropriate name
127+
/// Sets horizontal alignment
64128
/// </summary>
129+
/// <param name="aligment">Left, Center, Right</param>
65130
public void SetHorizontalAligment(string aligment)
66131
{
67132
try
@@ -72,9 +137,9 @@ public void SetHorizontalAligment(string aligment)
72137
catch { }
73138
}
74139
/// <summary>
75-
/// Exposes a parameter to the main Hint instance with the appropriate name
140+
/// Sets vertical alignment
76141
/// </summary>
77-
/// <param name="aligment"></param>
142+
/// <param name="aligment">Top, Bottom, Middle</param>
78143
public void SetVerticalAligment(string aligment)
79144
{
80145
try
@@ -85,8 +150,9 @@ public void SetVerticalAligment(string aligment)
85150
catch { }
86151
}
87152
/// <summary>
88-
/// Exposes a parameter to the main Hint instance with the appropriate name
153+
/// Takes a position in relation to Y
89154
/// </summary>
155+
/// <param name="y">0 -> 1080</param>
90156
public void SetYCoordinates(int y)
91157
{
92158
try
@@ -98,6 +164,10 @@ public void SetYCoordinates(int y)
98164

99165
}
100166
}
167+
/// <summary>
168+
/// Takes a position in relation to X
169+
/// </summary>
170+
/// <param name="x">-1200 -> 1200</param>
101171
public void SetXCoordinate(int x)
102172
{
103173
try
@@ -110,7 +180,7 @@ public void SetXCoordinate(int x)
110180
}
111181
}
112182
/// <summary>
113-
/// Exposes a parameter to the main Hint instance with the appropriate name
183+
/// Sets a unique identifier for the displayed hint message.
114184
/// </summary>
115185
public void SetId(string id)
116186
{
@@ -137,6 +207,11 @@ private void SetProperty(string name, object value)
137207
if (HintInstance == null) return;
138208
HintInstance.GetType().GetProperty(name)?.SetValue(HintInstance, value, null);
139209
}
210+
private object GetPropertyValue(string name)
211+
{
212+
if (HintInstance == null) return null;
213+
return HintInstance.GetType().GetProperty(name)?.GetValue(HintInstance, null);
214+
}
140215
/// <summary>
141216
/// uses the extension method from HintServiceMeow to add an object Hint"/>
142217
/// </summary>

EffectDisplay/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// Можно задать все значения или принять номера сборки и редакции по умолчанию
3333
// используя "*", как показано ниже:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("2.2.0.0")]
36-
[assembly: AssemblyFileVersion("2.2.0.0")]
35+
[assembly: AssemblyVersion("2.3.0.0")]
36+
[assembly: AssemblyFileVersion("2.3.0.0")]

0 commit comments

Comments
 (0)