forked from WCell/WCell
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Extensions.cs
134 lines (116 loc) · 3.15 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
126
127
128
129
130
131
132
133
134
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WCell.Constants.Login;
using WCell.Constants.NPCs;
using WCell.Constants.Items;
using WCell.Constants.GameObjects;
using WCell.Constants.Spells;
using WCell.Constants.Pets;
using WCell.Constants.Updates;
using WCell.Util;
namespace WCell.Constants
{
public static class Extensions
{
public static string ToString(this ObjectTypeId type, uint id)
{
string entryStr;
if (type == ObjectTypeId.Item)
{
entryStr = (ItemId)id + " (" + id + ")";
}
else if (type == ObjectTypeId.Unit)
{
entryStr = (NPCId)id + " (" + id + ")";
}
else if (type == ObjectTypeId.GameObject)
{
entryStr = (GOEntryId)id + " (" + id + ")";
}
else
{
entryStr = id + " (" + id + ")";
}
return entryStr;
}
public static string ToString(this GOEntryId id)
{
return id + "(Id: " + (int)id + ")";
}
public static ClassMask ToMask(this ClassId clss)
{
return (ClassMask)(1 << ((int)clss - 1));
}
public static ClassId[] GetIds(this ClassMask mask)
{
var ids = Utility.GetSetIndices((uint) mask);
var classIds = new ClassId[ids.Length];
for (var i = 0; i < ids.Length; i++)
{
var id = ids[i];
classIds[i] = (ClassId) (id+1);
}
return classIds;
}
#region HasAnyFlag (thanks Microsoft, for giving us HasFlag, but not HasAnyFlag)
public static bool HasAnyFlag(this UnitFlags flags, UnitFlags otherFlags)
{
return (flags & otherFlags) != 0;
}
public static bool HasAnyFlag(this NPCFlags flags, NPCFlags otherFlags)
{
return (flags & otherFlags) != 0;
}
public static bool HasAnyFlag(this DamageSchoolMask flags, DamageSchoolMask otherFlags)
{
return (flags & otherFlags) != 0;
}
public static bool HasAnyFlag(this DamageSchoolMask flags, DamageSchool school)
{
return (flags & (DamageSchoolMask)(1 << (int) school)) != 0;
}
public static bool HasAnyFlag(this GroupMemberFlags flags, GroupMemberFlags otherFlags)
{
return (flags & otherFlags) != 0;
}
public static bool HasAnyFlag(this HitFlags flags, HitFlags otherFlags)
{
return (flags & otherFlags) != 0;
}
public static bool HasAnyFlag(this MovementFlags flags, MovementFlags otherFlags)
{
return (flags & otherFlags) != 0;
}
public static bool HasAnyFlag(this MonsterMoveFlags flags, MonsterMoveFlags otherFlags)
{
return (flags & otherFlags) != 0;
}
public static bool HasAnyFlag(this SplineFlags flags, SplineFlags otherFlags)
{
return (flags & otherFlags) != 0;
}
public static bool HasAnyFlag(this ClassMask flags, ClassMask otherFlags)
{
return (flags & otherFlags) != 0;
}
public static bool HasAnyFlag(this ClassMask flags, ClassId clss)
{
return (flags & (ClassMask)(1 << (int) (clss-1))) != 0;
}
public static bool HasAnyFlag(this RaceMask flags, RaceMask otherFlags)
{
return (flags & otherFlags) != 0;
}
public static bool HasAnyFlag(this ClassMask2 flags, ClassMask2 otherFlags)
{
return (flags & otherFlags) != 0;
}
public static bool HasAnyFlag(this RaceMask2 flags, RaceMask2 otherFlags)
{
return (flags & otherFlags) != 0;
}
#endregion
}
}