forked from EnsageSharp/Ensage.Common
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utils.cs
109 lines (99 loc) · 4.27 KB
/
Utils.cs
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
namespace Ensage.Common
{
using System;
using System.Collections.Generic;
using System.Linq;
using Ensage.Common.Extensions;
/// <summary>
/// Utility methods
/// </summary>
public class Utils
{
#region Static Fields
/// <summary>
/// Stores sleep values
/// </summary>
public static readonly Dictionary<string, double> Sleeps = new Dictionary<string, double>();
#endregion
#region Public Methods and Operators
/// <summary>
/// Switches given degrees to radians
/// </summary>
/// <param name="angle"></param>
/// <returns></returns>
public static double DegreeToRadian(double angle)
{
return Math.PI * angle / 180.0;
}
/// <summary>
/// Checks if given unit wont be stunned after given delay in seconds.
/// </summary>
/// <param name="unit"></param>
/// <param name="delay">Delay of possible stun in seconds</param>
/// <param name="except">Entering a modifier name will ignore that modifier</param>
/// <param name="onlychain">Entering true will make the function return true only in case enemy is already stunned</param>
/// <returns></returns>
public static bool ChainStun(Unit unit, double delay, string except, bool onlychain)
{
var chain = false;
var stunned = false;
string[] modifiersList =
{
"modifier_shadow_demon_disruption",
"modifier_obsidian_destroyer_astral_imprisonment_prison", "modifier_eul_cyclone",
"modifier_invoker_tornado", "modifier_bane_nightmare",
"modifier_shadow_shaman_shackles", "modifier_crystal_maiden_frostbite",
"modifier_ember_spirit_searing_chains", "modifier_axe_berserkers_call",
"modifier_lone_druid_spirit_bear_entangle_effect", "modifier_meepo_earthbind",
"modifier_naga_siren_ensnare", "modifier_storm_spirit_electric_vortex_pull",
"modifier_treant_overgrowth", "modifier_cyclone", "modifier_sheepstick_debuff",
"modifier_shadow_shaman_voodoo", "modifier_lion_voodoo",
"modifier_brewmaster_storm_cyclone", "modifier_puck_phase_shift",
"modifier_dark_troll_warlord_ensnare",
"modifier_invoker_deafening_blast_knockback"
};
var modifiers = unit.Modifiers.OrderByDescending(x => x.RemainingTime);
foreach (
var m in
modifiers.Where(
m => (m.IsStunDebuff || modifiersList.Contains(m.Name)) && (except == null || m.Name == except))
)
{
stunned = true;
var remainingTime = m.RemainingTime;
if (m.Name == "modifier_eul_cyclone" || m.Name == "modifier_invoker_tornado")
{
remainingTime += 0.07f;
}
chain = remainingTime <= delay;
}
return ((((!(stunned || unit.IsStunned()) || chain) && !onlychain) || (onlychain && chain)));
}
/// <summary>
/// Sleeps the sleeping engine with the given id for given miliseconds. If engine is already sleeping for more than the
/// given time it will be ignored.
/// </summary>
/// <param name="duration"></param>
/// <param name="name"></param>
public static void Sleep(double duration, string name)
{
double dur;
var tick = Environment.TickCount;
if (!Sleeps.TryGetValue(name, out dur) || dur < tick + duration)
{
Sleeps[name] = tick + duration;
}
}
/// <summary>
/// Checks sleeping status of the sleep engine with given id
/// </summary>
/// <param name="id"></param>
/// <returns>Returns true in case id was not found or is not sleeping</returns>
public static bool SleepCheck(string id)
{
double asd;
return !Sleeps.TryGetValue(id, out asd) || Environment.TickCount > asd;
}
#endregion
}
}