2424from enum import Enum
2525
2626
27- class PlayerHouseElementType (Enum ):
27+ class ExtendedEnum (Enum ):
28+ """An Enum class that allows for the `__str__` method to be implemented."""
29+ def __str__ (self ):
30+ return self .in_game_name
31+
32+ def __eq__ (self , other ):
33+ """Check if the enum is equal to another enum or a string."""
34+ if isinstance (other , Enum ):
35+ return self .value == other .value
36+ elif isinstance (other , str ):
37+ return str (self .name ) == other or str (self .value ) == other
38+ return False
39+
40+ @property
41+ def in_game_name (self ) -> str :
42+ raise NotImplementedError
43+
44+ @classmethod
45+ def values (cls ):
46+ return list (map (lambda c : c .value , cls ))
47+
48+ @classmethod
49+ def names (cls ):
50+ return list (map (lambda c : c .name , cls ))
51+
52+
53+ class PlayerHouseElementType (ExtendedEnum ):
2854 """Enum to map the type of element of the player house."""
2955
3056 ground = "ground"
@@ -33,46 +59,83 @@ class PlayerHouseElementType(Enum):
3359 deco = "decoration"
3460 walls = "walls"
3561
36- def __str__ (self ):
37- return self .in_game_name
38-
3962 @property
4063 def in_game_name (self ) -> str :
4164 """Get a neat client-facing string value for the element type."""
42- lookup = {PlayerHouseElementType .ground : "Ground" , PlayerHouseElementType .roof : "Roof" ,
43- PlayerHouseElementType .foot : "Foot" , PlayerHouseElementType .deco : "Decoration" ,
44- PlayerHouseElementType .walls : "Walls" }
45- return lookup [self ]
65+ lookup = {"ground" : "Ground" , "roof" : "Roof" , "foot" : "Foot" , "decoration" : "Decoration" , "walls" : "Walls" }
66+ return lookup [self .value ]
4667
4768
48- class Role (Enum ):
69+ class Role (ExtendedEnum ):
4970 """Enum to map a player's role in the clan."""
5071
5172 member = "member"
5273 elder = "admin"
5374 co_leader = "coLeader"
5475 leader = "leader"
5576
56- def __str__ (self ):
57- return self .in_game_name
58-
5977 @property
6078 def in_game_name (self ) -> str :
6179 """Get a neat client-facing string value for the role."""
62- lookup = {Role . member : "Member" , Role . elder : "Elder" , Role . co_leader : "Co-Leader" , Role . leader : "Leader" }
63- return lookup [self ]
80+ lookup = {" member" : "Member" , "admin" : "Elder" , "coLeader" : "Co-Leader" , " leader" : "Leader" }
81+ return lookup [self . value ]
6482
6583
66- class WarRound (Enum ):
84+ class WarRound (ExtendedEnum ):
6785 previous_war = 0
6886 current_war = 1
6987 current_preparation = 2
7088
7189 def __str__ (self ):
7290 return self .name
7391
92+ @property
93+ def in_game_name (self ) -> str :
94+ lookup = ["Previous War" , "Current War" , "Current Preparation" ]
95+ return lookup [self .value ]
96+
7497
75- class Resource (Enum ):
98+ class BattleModifier (ExtendedEnum ):
99+ """Enum to map the type of battle modifiers."""
100+ none = "none"
101+ hard_mode = "hardMode"
102+
103+ @property
104+ def in_game_name (self ) -> str :
105+ """Get a neat client-facing string value for the battle modifier."""
106+ lookup = {"none" : "None" , "hardMode" : "Hard Mode" }
107+ return lookup [self .value ]
108+
109+
110+ class WarState (ExtendedEnum ):
111+ """Enum to map the state of the war.
112+ Compared to the api docs a few states are missing, but those were never observed in the wild."""
113+ not_in_war = "notInWar"
114+ preparation = "preparation"
115+ in_war = "inWar"
116+ war_ended = "warEnded"
117+
118+ @property
119+ def in_game_name (self ) -> str :
120+ """Get a neat client-facing string value for the war state."""
121+ lookup = {"notInWar" : "Not in War" , "preparation" : "Preparation" , "inWar" : "In War" , "warEnded" : "War Ended" }
122+ return lookup [self .value ]
123+
124+
125+ class WarResult (ExtendedEnum ):
126+ """Enum to map the result of the war"""
127+ win = "win"
128+ lose = "lose"
129+ tie = "tie"
130+
131+ @property
132+ def in_game_name (self ) -> str :
133+ """Get a neat client-facing string value for the war state."""
134+ lookup = {"win" : "Win" , "lose" : "Lose" , "tie" : "Tie" }
135+ return lookup [self .value ]
136+
137+
138+ class Resource (ExtendedEnum ):
76139 elixir = "Elixir"
77140 builder_elixir = "Elixir2"
78141 dark_elixir = "DarkElixir"
@@ -82,6 +145,14 @@ class Resource(Enum):
82145 glowy_ore = "RareOre"
83146 starry_ore = "EpicOre"
84147
148+ @property
149+ def in_game_name (self ) -> str :
150+ """Get a neat client-facing string value for the resource."""
151+ lookup = {"Elixir" : "Elixir" , "Elixir2" : "Builder Elixir" ,
152+ "DarkElixir" : "Dark Elixir" , "Gold" : "Gold" , "Gold2" : "Builder Gold" ,
153+ "CommonOre" : "Shiny Ore" , "RareOre" : "Glowy Ore" , "EpicOre" : "Starry Ore" }
154+ return lookup [self .value ]
155+
85156
86157ELIXIR_TROOP_ORDER = [
87158 "Barbarian" ,
@@ -115,6 +186,7 @@ class Resource(Enum):
115186 "Ice Golem" ,
116187 "Headhunter" ,
117188 "Apprentice Warden" ,
189+ "Druid" ,
118190]
119191
120192SIEGE_MACHINE_ORDER = [
@@ -227,6 +299,8 @@ class Resource(Enum):
227299 "Hog Rider Puppet" ,
228300 "Haste Vial" ,
229301 "Fireball" ,
302+ "Spiky Ball" ,
303+ "Rocket Spear"
230304]
231305
232306ACHIEVEMENT_ORDER = [
0 commit comments