mirror of
https://github.com/ACEmulator/ACE
synced 2026-08-17 12:26:06 -04:00
* fixing ebon rifts / adding support for multiple damage types * fixing typeless damage * upgrading to faster method that can be reused for other enums
42 lines
1.1 KiB
C#
42 lines
1.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace ACE.Common.Extensions
|
|
{
|
|
public static class EnumHelper
|
|
{
|
|
/// <summary>
|
|
/// Returns a list of flags for enum
|
|
/// </summary>
|
|
public static List<Enum> GetFlags(this Enum e)
|
|
{
|
|
return Enum.GetValues(e.GetType()).Cast<Enum>().Where(e.HasFlag).ToList();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns the # of bits set in a Flags enum
|
|
/// </summary>
|
|
/// <param name="enumVal">The enum uint value</param>
|
|
public static int NumFlags(uint enumVal)
|
|
{
|
|
var cnt = 0;
|
|
while (enumVal != 0)
|
|
{
|
|
// remove the next set bit
|
|
enumVal &= enumVal - 1;
|
|
cnt++;
|
|
}
|
|
return cnt;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns TRUE if this flags enum has multiple flags set
|
|
/// </summary>
|
|
/// <param name="enumVal">The enum uint value</param>
|
|
public static bool HasMultiple(uint enumVal)
|
|
{
|
|
return (enumVal & (enumVal - 1)) != 0;
|
|
}
|
|
}
|
|
}
|