-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMotelyItem.cs
46 lines (36 loc) · 1.83 KB
/
MotelyItem.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
using System.Runtime.CompilerServices;
namespace Motely;
[method: MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly struct MotelyItem(int value)
{
public readonly int Value = value;
public readonly MotelyItemType Type => (MotelyItemType)(Value & Motely.ItemTypeMask);
public readonly MotelyItemSeal Seal => (MotelyItemSeal)((Value >> Motely.ItemSealOffset) & Motely.ItemSealMask);
public readonly MotelyItemEnhancement Enhancement => (MotelyItemEnhancement)((Value >> Motely.ItemEnhancementOffset) & Motely.ItemEnhancementMask);
public readonly MotelyItemEdition Edition => (MotelyItemEdition)((Value >> Motely.ItemEditionOffset) & Motely.ItemEditionMask);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public MotelyItem(MotelyJoker joker, MotelyItemEdition edition) : this(
(int) joker | (int) MotelyItemTypeCategory.Joker | (int) edition
) {}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public MotelyItem AsType(MotelyItemType type)
{
return new((Value & ~Motely.ItemTypeMask) | (int)type);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public MotelyItem WithSeal(MotelyItemSeal seal)
{
return new((Value & ~(Motely.ItemSealMask << Motely.ItemSealOffset)) | (int)seal);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public MotelyItem WithEnhancement(MotelyItemEnhancement enhancement)
{
return new((Value & ~(Motely.ItemEnhancementMask << Motely.ItemEnhancementOffset)) | (int)enhancement);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public MotelyItem WithEdition(MotelyItemEdition edition)
{
return new((Value & ~(Motely.ItemEditionMask << Motely.ItemEditionOffset)) | (int)edition);
}
public static implicit operator MotelyItem(MotelyItemType type) => new((int)type);
}