-
Notifications
You must be signed in to change notification settings - Fork 2
/
Extensions.cs
125 lines (107 loc) · 3.77 KB
/
Extensions.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#region Revision Info
// This file is part of Singular - A community driven Honorbuddy CC
// $Author: bobby53 $
// $Date: 2012-11-07 18:04:22 +0000 (Mi, 07 Nov 2012) $
// $HeadURL: https://subversion.assembla.com/svn/singular_v3/trunk/Singular/Extensions.cs $
// $LastChangedBy: bobby53 $
// $LastChangedDate: 2012-11-07 18:04:22 +0000 (Mi, 07 Nov 2012) $
// $LastChangedRevision: 1086 $
// $Revision: 1086 $
#endregion
using System.Linq;
using System.Text;
using Styx;
using Styx.CommonBot;
using Styx.WoWInternals;
using Styx.WoWInternals.WoWObjects;
using System.Collections.Generic;
using Styx.Pathing;
using Singular.Helpers;
namespace Singular
{
internal static class Extensions
{
public static bool Between(this double distance, double min, double max)
{
return distance >= min && distance <= max;
}
/// <summary>
/// A string extension method that turns a Camel-case string into a spaced string. (Example: SomeCamelString -> Some Camel String)
/// </summary>
/// <remarks>
/// Created 2/7/2011.
/// </remarks>
/// <param name = "str">The string to act on.</param>
/// <returns>.</returns>
public static string CamelToSpaced(this string str)
{
var sb = new StringBuilder();
foreach (char c in str)
{
if (char.IsUpper(c))
{
sb.Append(' ');
}
sb.Append(c);
}
return sb.ToString();
}
public static bool ShowPlayerNames { get; set; }
public static string SafeName(this WoWObject obj)
{
if (obj.IsMe)
{
return "Myself";
}
string name;
if (obj is WoWPlayer)
{
if (RaFHelper.Leader == obj)
return "Tank";
name = ShowPlayerNames ? ((WoWPlayer)obj).Name : ((WoWPlayer)obj).Class.ToString();
}
else if (obj is WoWUnit && obj.ToUnit().IsPet)
{
name = "Pet";
}
else
{
name = obj.Name;
}
return name;
}
public static bool IsWanding(this LocalPlayer me)
{
return StyxWoW.Me.AutoRepeatingSpellId == 5019;
}
/// <summary>
/// determines if a target is off the ground far enough that you can
/// reach it with melee spells if standing directly under.
/// </summary>
/// <param name="u">unit</param>
/// <returns>true if above melee reach</returns>
public static bool IsAerialTarget(this WoWUnit u)
{
float height = HeightOffTheGround(u);
if ( height == float.MaxValue )
return false; // make this true if better to assume aerial
if (height > Spell.MeleeRange)
return true;
return false;
}
/// <summary>
/// calculate a unit's vertical distance (height) above ground level (mesh). this is the units position
/// relative to the ground and is independent of any other character.
/// </summary>
/// <param name="u">unit</param>
/// <returns>float.MinValue if can't determine, otherwise distance off ground</returns>
public static float HeightOffTheGround(this WoWUnit u)
{
var unitLoc = new WoWPoint( u.Location.X, u.Location.Y, u.Location.Z);
var listMeshZ = Navigator.FindHeights( unitLoc.X, unitLoc.Y).Where( h => h <= unitLoc.Z);
if (listMeshZ.Any())
return unitLoc.Z - listMeshZ.Max();
return float.MaxValue;
}
}
}