|
1 | 1 | using System; |
2 | | -using System.Collections.Generic; |
3 | 2 | using WowPacketParser.Enums; |
4 | 3 |
|
5 | 4 | namespace WowPacketParser.Misc |
6 | 5 | { |
7 | 6 | public static class ObjectTypeConverter |
8 | 7 | { |
9 | | - private static readonly Dictionary<ObjectTypeLegacy, ObjectType> ConvDictLegacy = new Dictionary<ObjectTypeLegacy, ObjectType> |
10 | | - { |
11 | | - { ObjectTypeLegacy.Object, ObjectType.Object }, |
12 | | - { ObjectTypeLegacy.Item, ObjectType.Item }, |
13 | | - { ObjectTypeLegacy.Container, ObjectType.Container }, |
14 | | - { ObjectTypeLegacy.Unit, ObjectType.Unit }, |
15 | | - { ObjectTypeLegacy.Player, ObjectType.Player }, |
16 | | - { ObjectTypeLegacy.GameObject, ObjectType.GameObject }, |
17 | | - { ObjectTypeLegacy.DynamicObject, ObjectType.DynamicObject }, |
18 | | - { ObjectTypeLegacy.Corpse, ObjectType.Corpse }, |
19 | | - { ObjectTypeLegacy.AreaTrigger, ObjectType.AreaTrigger }, |
20 | | - { ObjectTypeLegacy.SceneObject, ObjectType.SceneObject }, |
21 | | - { ObjectTypeLegacy.Conversation, ObjectType.Conversation } |
22 | | - }; |
23 | | - |
24 | 8 | public static ObjectType Convert(ObjectTypeLegacy type) |
25 | 9 | { |
26 | | - if (!ConvDictLegacy.ContainsKey(type)) |
27 | | - throw new ArgumentOutOfRangeException("0x" + type.ToString("X")); |
28 | | - return ConvDictLegacy[type]; |
| 10 | + return type switch |
| 11 | + { |
| 12 | + ObjectTypeLegacy.Object => ObjectType.Object, |
| 13 | + ObjectTypeLegacy.Item => ObjectType.Item, |
| 14 | + ObjectTypeLegacy.Container => ObjectType.Container, |
| 15 | + ObjectTypeLegacy.Unit => ObjectType.Unit, |
| 16 | + ObjectTypeLegacy.Player => ObjectType.Player, |
| 17 | + ObjectTypeLegacy.GameObject => ObjectType.GameObject, |
| 18 | + ObjectTypeLegacy.DynamicObject => ObjectType.DynamicObject, |
| 19 | + ObjectTypeLegacy.Corpse => ObjectType.Corpse, |
| 20 | + ObjectTypeLegacy.AreaTrigger => ObjectType.AreaTrigger, |
| 21 | + ObjectTypeLegacy.SceneObject => ObjectType.SceneObject, |
| 22 | + ObjectTypeLegacy.Conversation => ObjectType.Conversation, |
| 23 | + _ => throw new ArgumentOutOfRangeException(nameof(type), type, "0x" + type.ToString("X")) |
| 24 | + }; |
29 | 25 | } |
30 | 26 |
|
31 | | - private static readonly Dictionary<ObjectType801, ObjectType> ConvDict801 = new Dictionary<ObjectType801, ObjectType> |
32 | | - { |
33 | | - { ObjectType801.Object, ObjectType.Object }, |
34 | | - { ObjectType801.Item, ObjectType.Item }, |
35 | | - { ObjectType801.Container, ObjectType.Container }, |
36 | | - { ObjectType801.AzeriteEmpoweredItem, ObjectType.AzeriteEmpoweredItem }, |
37 | | - { ObjectType801.AzeriteItem, ObjectType.AzeriteItem }, |
38 | | - { ObjectType801.Unit, ObjectType.Unit }, |
39 | | - { ObjectType801.Player, ObjectType.Player }, |
40 | | - { ObjectType801.ActivePlayer, ObjectType.ActivePlayer }, |
41 | | - { ObjectType801.GameObject, ObjectType.GameObject }, |
42 | | - { ObjectType801.DynamicObject, ObjectType.DynamicObject }, |
43 | | - { ObjectType801.Corpse, ObjectType.Corpse }, |
44 | | - { ObjectType801.AreaTrigger, ObjectType.AreaTrigger }, |
45 | | - { ObjectType801.SceneObject, ObjectType.SceneObject }, |
46 | | - { ObjectType801.Conversation, ObjectType.Conversation } |
47 | | - }; |
48 | | - |
49 | 27 | public static ObjectType Convert(ObjectType801 type) |
50 | 28 | { |
51 | | - if (!ConvDict801.ContainsKey(type)) |
52 | | - throw new ArgumentOutOfRangeException("0x" + type.ToString("X")); |
53 | | - return ConvDict801[type]; |
| 29 | + return type switch |
| 30 | + { |
| 31 | + ObjectType801.Object => ObjectType.Object, |
| 32 | + ObjectType801.Item => ObjectType.Item, |
| 33 | + ObjectType801.Container => ObjectType.Container, |
| 34 | + ObjectType801.AzeriteEmpoweredItem => ObjectType.AzeriteEmpoweredItem, |
| 35 | + ObjectType801.AzeriteItem => ObjectType.AzeriteItem, |
| 36 | + ObjectType801.Unit => ObjectType.Unit, |
| 37 | + ObjectType801.Player => ObjectType.Player, |
| 38 | + ObjectType801.ActivePlayer => ObjectType.ActivePlayer, |
| 39 | + ObjectType801.GameObject => ObjectType.GameObject, |
| 40 | + ObjectType801.DynamicObject => ObjectType.DynamicObject, |
| 41 | + ObjectType801.Corpse => ObjectType.Corpse, |
| 42 | + ObjectType801.AreaTrigger => ObjectType.AreaTrigger, |
| 43 | + ObjectType801.SceneObject => ObjectType.SceneObject, |
| 44 | + ObjectType801.Conversation => ObjectType.Conversation, |
| 45 | + ObjectType801.MeshObject => ObjectType.MeshObject, |
| 46 | + ObjectType801.AiGroup => ObjectType.AiGroup, |
| 47 | + ObjectType801.Scenario => ObjectType.Scenario, |
| 48 | + ObjectType801.LootObject => ObjectType.LootObject, |
| 49 | + ObjectType801.Max => ObjectType.Object, |
| 50 | + _ => throw new ArgumentOutOfRangeException(nameof(type), type, "0x" + type.ToString("X")) |
| 51 | + }; |
54 | 52 | } |
55 | 53 |
|
56 | | - |
57 | | - private static readonly Dictionary<ObjectTypeBCC, ObjectType> ConvDictBCC = new Dictionary<ObjectTypeBCC, ObjectType> |
58 | | - { |
59 | | - { ObjectTypeBCC.Object, ObjectType.Object }, |
60 | | - { ObjectTypeBCC.Item, ObjectType.Item }, |
61 | | - { ObjectTypeBCC.Container, ObjectType.Container }, |
62 | | - { ObjectTypeBCC.Unit, ObjectType.Unit }, |
63 | | - { ObjectTypeBCC.Player, ObjectType.Player }, |
64 | | - { ObjectTypeBCC.ActivePlayer, ObjectType.ActivePlayer }, |
65 | | - { ObjectTypeBCC.GameObject, ObjectType.GameObject }, |
66 | | - { ObjectTypeBCC.DynamicObject, ObjectType.DynamicObject }, |
67 | | - { ObjectTypeBCC.Corpse, ObjectType.Corpse }, |
68 | | - { ObjectTypeBCC.AreaTrigger, ObjectType.AreaTrigger }, |
69 | | - { ObjectTypeBCC.SceneObject, ObjectType.SceneObject }, |
70 | | - { ObjectTypeBCC.Conversation, ObjectType.Conversation } |
71 | | - }; |
72 | | - |
73 | 54 | public static ObjectType Convert(ObjectTypeBCC type) |
74 | 55 | { |
75 | | - if (!ConvDictBCC.ContainsKey(type)) |
76 | | - throw new ArgumentOutOfRangeException("0x" + type.ToString("X")); |
77 | | - return ConvDictBCC[type]; |
| 56 | + return type switch |
| 57 | + { |
| 58 | + ObjectTypeBCC.Object => ObjectType.Object, |
| 59 | + ObjectTypeBCC.Item => ObjectType.Item, |
| 60 | + ObjectTypeBCC.Container => ObjectType.Container, |
| 61 | + ObjectTypeBCC.Unit => ObjectType.Unit, |
| 62 | + ObjectTypeBCC.Player => ObjectType.Player, |
| 63 | + ObjectTypeBCC.ActivePlayer => ObjectType.ActivePlayer, |
| 64 | + ObjectTypeBCC.GameObject => ObjectType.GameObject, |
| 65 | + ObjectTypeBCC.DynamicObject => ObjectType.DynamicObject, |
| 66 | + ObjectTypeBCC.Corpse => ObjectType.Corpse, |
| 67 | + ObjectTypeBCC.AreaTrigger => ObjectType.AreaTrigger, |
| 68 | + ObjectTypeBCC.SceneObject => ObjectType.SceneObject, |
| 69 | + ObjectTypeBCC.Conversation => ObjectType.Conversation, |
| 70 | + _ => throw new ArgumentOutOfRangeException(nameof(type), type, "0x" + type.ToString("X")) |
| 71 | + }; |
78 | 72 | } |
79 | 73 | } |
80 | 74 | } |
0 commit comments