-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExtensions.cs
More file actions
122 lines (98 loc) · 3.61 KB
/
Copy pathExtensions.cs
File metadata and controls
122 lines (98 loc) · 3.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
using System;
using Exiled.API.Features;
using Exiled.CustomRoles.API;
using Exiled.CustomRoles.API.Features;
using HarmonyLib;
using Hints;
using Interactables.Interobjects;
using InventorySystem.Items.Usables.Scp330;
using UnityEngine;
#if RUEI
using RueI.API;
using RueI.API.Elements;
#endif
namespace CandyChances
{
public static class Extensions
{
#if RUEI
private static readonly Tag s_scp330HintsTag = new("CandyChances");
#endif
internal static int GetUsageLimit(this Player player)
{
Config config = Plugin.Instance.Config;
if (config.OverrideUseLimitsforCustomRoles)
{
foreach (CustomRole role in player.GetCustomRoles())
{
if (config.ModifiedUseLimitsforCustomRoles.TryGetValue(role.Name, out int customUsageLimit))
return customUsageLimit;
}
}
if (config.OverrideUseLimitsforRoles)
{
if (config.ModifiedUseLimits.TryGetValue(player.Role.Type, out int customUsageLimit))
return customUsageLimit;
}
return Scp330Interobject.MaxAmountPerLife;
}
internal static void Give330BowlUsageHint(this Player player, CandyKindID candy, int usageLimit, int usageCount)
{
Config config = Plugin.Instance.Config;
Translation translation = Plugin.Instance.Translation;
string hint = null;
if (config.ShowCandyHint)
{
if (translation.CandyHints.TryGetValue(candy, out string[] hints))
hint = hints.RandomItem();
}
if (config.ShowRemainingUseHint)
{
int remaining = usageLimit - usageCount - 1;
string remainingHint = translation.RemainingUse.Replace("{0}", remaining.ToString());
hint = hint == null ? remainingHint : string.Concat(hint, "\n", remainingHint);
}
if (!string.IsNullOrEmpty(hint))
player.GiveHint(hint, config.HintPositionRuei, config.HintTime);
}
internal static void GiveHint(this Player player, string hint, float position, float duration)
{
#if RUEI
RueDisplay display = RueDisplay.Get(player);
display.Show(s_scp330HintsTag, new BasicElement(position, hint), duration);
#else
player.ShowHint(hint, hintEffects: [HintEffectPresets.TrailingPulseAlpha(0.5f, 1f, 0.5f, 2f, 0f, 3)], duration);
#endif
}
public static Type ToCandyType(this string candyType)
{
if (string.IsNullOrEmpty(candyType))
return null;
Data.CandyNametoTypes.TryGetValue(candyType, out Type found);
return found;
}
public static void PatchSingleType(this Harmony harmony, Type patchClass)
{
PatchClassProcessor processor = new(harmony, patchClass);
processor.Patch();
}
public static T AddEffect<T>(this Player player) where T : Behaviour
{
if (player.GameObject.TryGetComponent(out T effect))
{
effect.enabled = true;
return effect;
}
effect = player.GameObject.AddComponent<T>();
effect.enabled = true;
return effect;
}
public static void RemoveEffect<T>(this Player player) where T : Behaviour
{
if (player.GameObject.TryGetComponent(out T effect))
{
effect.enabled = false;
}
}
}
}