slay.py
1import json 2 3from typing import NamedTuple, Annotated, TypedDict 4from enum import Enum 5 6from slay.data.info.utils import xNumber, xFloat, xBool 7from slay.data.info.decorate import NicknameColor 8from slay.utils import Pipe, Undefined 9 10ConnectionId = int 11InGameId = int 12 13def SecondsFromGameTicks(ticks: int): 14 return ticks / 20 15 16class Ability(Enum): 17 INVISIBILITY = 4 18 19class HeadDirection(Enum): 20 DOWN = 0 21 DOWN_LEFT = 1 22 LEFT = 2 23 UP_LEFT = 3 24 UP = 4 25 UP_RIGHT = 5 26 RIGHT = 6 27 DOWN_RIGHT = 7 28 29class MovingDirection(Enum): 30 UP = 1 31 DOWN = 2 32 LEFT = 3 33 RIGHT = 4 34 35class GameMode(Enum): 36 TEAM_DEATHMATCH = 1 37 CAPTURE_THE_FLAG = 2 38 DEATHMATCH = 4 39 INFECTION = 5 40 41 @property 42 def id(self) -> int: 43 return self.value 44 45 @property 46 def text(self) -> str: 47 return self.name.replace("_", " ").title() 48 49class GameProfile(NamedTuple): 50 id: int 51 map_name: str 52 player_amount: int 53 max_player_amount: int 54 mode: Annotated[GameMode, Pipe(int, GameMode)] 55 map_height: int 56 map_witdh: int 57 tag: str 58 map_thumbnail_data: str 59 60class GameMapData(TypedDict, total=False): 61 x: int 62 y: int 63 maxPlayers: int | Undefined 64 closed: bool 65 invisible: bool 66 defaultTiles: int 67 tiles: list[dict] 68 groundTiles: list[dict] 69 noGridTiles: list[dict] 70 spawningPoints: list 71 spawningPointsRed: list 72 spawningPointsBlue: list 73 waypoints: list 74 type: int 75 ammo: list[dict] 76 noBorder: bool 77 thumbnail: str 78 name: str | Undefined 79 description: str 80 81class Game(NamedTuple): 82 map_data: Annotated[GameMapData, json.loads] 83 mode: Annotated[GameMode, Pipe(int, GameMode)] 84 max_round_ticks: int 85 current_tick: int 86 team_1_scores: int 87 team_2_scores: int 88 red_flag_x: float 89 red_flag_y: float 90 blue_flag_x: float 91 blue_flag_y: float 92 max_round_ticks: int 93 """ To ensure compatibility with the old replay version (<=1) """ 94 current_tick: int 95 """ To ensure compatibility with the old replay version (<=1) """ 96 game_id: int 97 """ To ensure compatibility with the old replay version (<=1) """ 98 99class Player(NamedTuple): 100 in_game_id: int 101 x: int 102 y: int 103 nickname: str 104 hp: float 105 armor: float 106 kills: int 107 deaths: int 108 weapon_id: int 109 moving_to_x: int 110 moving_to_y: int 111 skin_id: int 112 team_id: int 113 is_invisible: int 114 max_hp: float 115 hp_regeneration_rate: float 116 clan_tag: str 117 authentication_level: int 118 souls: float 119 mp_regeneration_rate: float 120 invisible_costing_rate: float 121 score: float 122 is_zombie: int 123 is_fake_corpse: int 124 is_zombie_boss: int 125 id: Annotated[int, xNumber] 126 """ 0 means no id (like guests and bots) """ 127 db_id: int 128 nickname_color: Annotated[NicknameColor, Pipe(int, NicknameColor)] 129 130class SummonedZombie(NamedTuple): 131 in_game_id: int 132 x: float 133 y: float 134 hp: float 135 moving_to_x: float 136 moving_to_y: float 137 max_hp: float 138 hp_regeneration_rate: float 139 randomizer: float 140 image_scale: float 141 name: str 142 143class UsedAmmoRespawn(NamedTuple): 144 in_game_id: int 145 ticks_left_to_respawn: int 146 """ Have to minus 2 to get the actual ticks left to respawn """ 147 148class ObjectDetail(NamedTuple): 149 ticks_left_to_live: int 150 weapon_id: int = -1 151 152class Object(NamedTuple): 153 in_game_id: int 154 x: float 155 y: float 156 ability_id: int 157 owner_in_game_id: int 158 hp: float 159 max_hp: float 160 ticks_to_live: int 161 aoe_value: float 162 detail: ObjectDetail 163 164class MovableObject(NamedTuple): 165 in_game_id: int 166 x: int 167 y: int 168 moving_to_x: int 169 moving_to_y: int 170 type_id: int 171 hp: float 172 173class Corpse(NamedTuple): 174 x: int 175 y: int 176 in_game_id: int 177 178class GameInitial(NamedTuple): 179 game_data: Game 180 players: list[Player] 181 summoned_zombies: list[SummonedZombie] 182 used_ammo_respawns: list[UsedAmmoRespawn] 183 objects: list[Object] 184 movable_objects: list[MovableObject] 185 corpses: list[Corpse] 186 187class NewPlayer(NamedTuple): 188 in_game_id: int 189 x: int 190 y: int 191 nickname: str 192 hp: float 193 armor: float 194 skin_id: int 195 team_id: int 196 max_hp: int 197 hp_regeneration_rate: float 198 clan_tag: str 199 authentication_level: int 200 mp_regeneration_rate: float 201 invisible_costing_rate: float 202 is_zombie: int 203 uid: int # -> may need to change to id, or change the others to uid 204 """ 0 means no id (like guests and bots) """ 205 world_elo: float 206 nickname_color_id: int # -> nickname_color: Annotated[NicknameColor, Pipe(int, NicknameColor)] 207 208class GameStats(NamedTuple): 209 xp_gained: int 210 elo_gained: int 211 gold_gained: int 212 kills: int 213 deaths: int 214 xp: int 215 elo: int 216 gold: int 217 souls: int 218 show: int 219 exit: Annotated[bool, Pipe(int, bool)] 220 chestId: int 221 222class HP(NamedTuple): 223 victim_in_game_id: Annotated[int, xNumber] 224 hp: float 225 armor: float 226 need_create_hit_effect: Annotated[bool, xBool] # can be "undefined" 227 projectile_id: Annotated[int, xNumber] 228 murder_weapon_id: Annotated[int, xNumber] 229 attacker_in_game_id: Annotated[int, xNumber] 230 lifesteal_amount: float = None 231 new_kill_count: Annotated[int, xNumber] = -1 232 new_death_count: Annotated[int, xNumber] = -1 # can be "undefined" 233 multiple_kill_count: Annotated[int, xNumber] = -1 # can be "undefined" 234 kill_streak: Annotated[int, xNumber] = -1 235 victim_kill_streak: str = None 236 killer_souls: float = None 237 victim_souls: Annotated[float, xFloat] = None # can be "undefined" 238 killer_elo: Annotated[float, xFloat] = None 239 victim_elo: Annotated[float, xFloat] = None # can be "undefined" 240 has_splash: Annotated[bool, xBool] = None 241 object_x: float = None 242 object_y: float = None 243 object_aoe: float = None 244 object_id: Annotated[int, xNumber] = -1 245 start_x: float = None 246 start_y: float = None 247 vector_x: float = None 248 vector_y: float = None 249 vector_z: float = None 250 251class PlayerRespawn(NamedTuple): 252 in_game_id: int 253 x: float 254 y: float 255 has_turned_zombie: Annotated[bool, Pipe(int, bool)] 256 257class AbilityCancel(NamedTuple): 258 player_in_game_id: int 259 ability: Annotated[Ability, Pipe(int, Ability)] 260 261class InGameChat(NamedTuple): 262 in_game_id: int 263 message: str
20class HeadDirection(Enum): 21 DOWN = 0 22 DOWN_LEFT = 1 23 LEFT = 2 24 UP_LEFT = 3 25 UP = 4 26 UP_RIGHT = 5 27 RIGHT = 6 28 DOWN_RIGHT = 7
36class GameMode(Enum): 37 TEAM_DEATHMATCH = 1 38 CAPTURE_THE_FLAG = 2 39 DEATHMATCH = 4 40 INFECTION = 5 41 42 @property 43 def id(self) -> int: 44 return self.value 45 46 @property 47 def text(self) -> str: 48 return self.name.replace("_", " ").title()
50class GameProfile(NamedTuple): 51 id: int 52 map_name: str 53 player_amount: int 54 max_player_amount: int 55 mode: Annotated[GameMode, Pipe(int, GameMode)] 56 map_height: int 57 map_witdh: int 58 tag: str 59 map_thumbnail_data: str
GameProfile(id, map_name, player_amount, max_player_amount, mode, map_height, map_witdh, tag, map_thumbnail_data)
Create new instance of GameProfile(id, map_name, player_amount, max_player_amount, mode, map_height, map_witdh, tag, map_thumbnail_data)
61class GameMapData(TypedDict, total=False): 62 x: int 63 y: int 64 maxPlayers: int | Undefined 65 closed: bool 66 invisible: bool 67 defaultTiles: int 68 tiles: list[dict] 69 groundTiles: list[dict] 70 noGridTiles: list[dict] 71 spawningPoints: list 72 spawningPointsRed: list 73 spawningPointsBlue: list 74 waypoints: list 75 type: int 76 ammo: list[dict] 77 noBorder: bool 78 thumbnail: str 79 name: str | Undefined 80 description: str
82class Game(NamedTuple): 83 map_data: Annotated[GameMapData, json.loads] 84 mode: Annotated[GameMode, Pipe(int, GameMode)] 85 max_round_ticks: int 86 current_tick: int 87 team_1_scores: int 88 team_2_scores: int 89 red_flag_x: float 90 red_flag_y: float 91 blue_flag_x: float 92 blue_flag_y: float 93 max_round_ticks: int 94 """ To ensure compatibility with the old replay version (<=1) """ 95 current_tick: int 96 """ To ensure compatibility with the old replay version (<=1) """ 97 game_id: int 98 """ To ensure compatibility with the old replay version (<=1) """
Game(map_data, mode, max_round_ticks, current_tick, team_1_scores, team_2_scores, red_flag_x, red_flag_y, blue_flag_x, blue_flag_y, game_id)
Create new instance of Game(map_data, mode, max_round_ticks, current_tick, team_1_scores, team_2_scores, red_flag_x, red_flag_y, blue_flag_x, blue_flag_y, game_id)
100class Player(NamedTuple): 101 in_game_id: int 102 x: int 103 y: int 104 nickname: str 105 hp: float 106 armor: float 107 kills: int 108 deaths: int 109 weapon_id: int 110 moving_to_x: int 111 moving_to_y: int 112 skin_id: int 113 team_id: int 114 is_invisible: int 115 max_hp: float 116 hp_regeneration_rate: float 117 clan_tag: str 118 authentication_level: int 119 souls: float 120 mp_regeneration_rate: float 121 invisible_costing_rate: float 122 score: float 123 is_zombie: int 124 is_fake_corpse: int 125 is_zombie_boss: int 126 id: Annotated[int, xNumber] 127 """ 0 means no id (like guests and bots) """ 128 db_id: int 129 nickname_color: Annotated[NicknameColor, Pipe(int, NicknameColor)]
Player(in_game_id, x, y, nickname, hp, armor, kills, deaths, weapon_id, moving_to_x, moving_to_y, skin_id, team_id, is_invisible, max_hp, hp_regeneration_rate, clan_tag, authentication_level, souls, mp_regeneration_rate, invisible_costing_rate, score, is_zombie, is_fake_corpse, is_zombie_boss, id, db_id, nickname_color)
Create new instance of Player(in_game_id, x, y, nickname, hp, armor, kills, deaths, weapon_id, moving_to_x, moving_to_y, skin_id, team_id, is_invisible, max_hp, hp_regeneration_rate, clan_tag, authentication_level, souls, mp_regeneration_rate, invisible_costing_rate, score, is_zombie, is_fake_corpse, is_zombie_boss, id, db_id, nickname_color)
Alias for field number 27
131class SummonedZombie(NamedTuple): 132 in_game_id: int 133 x: float 134 y: float 135 hp: float 136 moving_to_x: float 137 moving_to_y: float 138 max_hp: float 139 hp_regeneration_rate: float 140 randomizer: float 141 image_scale: float 142 name: str
SummonedZombie(in_game_id, x, y, hp, moving_to_x, moving_to_y, max_hp, hp_regeneration_rate, randomizer, image_scale, name)
Create new instance of SummonedZombie(in_game_id, x, y, hp, moving_to_x, moving_to_y, max_hp, hp_regeneration_rate, randomizer, image_scale, name)
144class UsedAmmoRespawn(NamedTuple): 145 in_game_id: int 146 ticks_left_to_respawn: int 147 """ Have to minus 2 to get the actual ticks left to respawn """
UsedAmmoRespawn(in_game_id, ticks_left_to_respawn)
ObjectDetail(ticks_left_to_live, weapon_id)
153class Object(NamedTuple): 154 in_game_id: int 155 x: float 156 y: float 157 ability_id: int 158 owner_in_game_id: int 159 hp: float 160 max_hp: float 161 ticks_to_live: int 162 aoe_value: float 163 detail: ObjectDetail
Object(in_game_id, x, y, ability_id, owner_in_game_id, hp, max_hp, ticks_to_live, aoe_value, detail)
Create new instance of Object(in_game_id, x, y, ability_id, owner_in_game_id, hp, max_hp, ticks_to_live, aoe_value, detail)
165class MovableObject(NamedTuple): 166 in_game_id: int 167 x: int 168 y: int 169 moving_to_x: int 170 moving_to_y: int 171 type_id: int 172 hp: float
MovableObject(in_game_id, x, y, moving_to_x, moving_to_y, type_id, hp)
Corpse(x, y, in_game_id)
179class GameInitial(NamedTuple): 180 game_data: Game 181 players: list[Player] 182 summoned_zombies: list[SummonedZombie] 183 used_ammo_respawns: list[UsedAmmoRespawn] 184 objects: list[Object] 185 movable_objects: list[MovableObject] 186 corpses: list[Corpse]
GameInitial(game_data, players, summoned_zombies, used_ammo_respawns, objects, movable_objects, corpses)
Create new instance of GameInitial(game_data, players, summoned_zombies, used_ammo_respawns, objects, movable_objects, corpses)
188class NewPlayer(NamedTuple): 189 in_game_id: int 190 x: int 191 y: int 192 nickname: str 193 hp: float 194 armor: float 195 skin_id: int 196 team_id: int 197 max_hp: int 198 hp_regeneration_rate: float 199 clan_tag: str 200 authentication_level: int 201 mp_regeneration_rate: float 202 invisible_costing_rate: float 203 is_zombie: int 204 uid: int # -> may need to change to id, or change the others to uid 205 """ 0 means no id (like guests and bots) """ 206 world_elo: float 207 nickname_color_id: int # -> nickname_color: Annotated[NicknameColor, Pipe(int, NicknameColor)]
NewPlayer(in_game_id, x, y, nickname, hp, armor, skin_id, team_id, max_hp, hp_regeneration_rate, clan_tag, authentication_level, mp_regeneration_rate, invisible_costing_rate, is_zombie, uid, world_elo, nickname_color_id)
Create new instance of NewPlayer(in_game_id, x, y, nickname, hp, armor, skin_id, team_id, max_hp, hp_regeneration_rate, clan_tag, authentication_level, mp_regeneration_rate, invisible_costing_rate, is_zombie, uid, world_elo, nickname_color_id)
209class GameStats(NamedTuple): 210 xp_gained: int 211 elo_gained: int 212 gold_gained: int 213 kills: int 214 deaths: int 215 xp: int 216 elo: int 217 gold: int 218 souls: int 219 show: int 220 exit: Annotated[bool, Pipe(int, bool)] 221 chestId: int
GameStats(xp_gained, elo_gained, gold_gained, kills, deaths, xp, elo, gold, souls, show, exit, chestId)
Create new instance of GameStats(xp_gained, elo_gained, gold_gained, kills, deaths, xp, elo, gold, souls, show, exit, chestId)
223class HP(NamedTuple): 224 victim_in_game_id: Annotated[int, xNumber] 225 hp: float 226 armor: float 227 need_create_hit_effect: Annotated[bool, xBool] # can be "undefined" 228 projectile_id: Annotated[int, xNumber] 229 murder_weapon_id: Annotated[int, xNumber] 230 attacker_in_game_id: Annotated[int, xNumber] 231 lifesteal_amount: float = None 232 new_kill_count: Annotated[int, xNumber] = -1 233 new_death_count: Annotated[int, xNumber] = -1 # can be "undefined" 234 multiple_kill_count: Annotated[int, xNumber] = -1 # can be "undefined" 235 kill_streak: Annotated[int, xNumber] = -1 236 victim_kill_streak: str = None 237 killer_souls: float = None 238 victim_souls: Annotated[float, xFloat] = None # can be "undefined" 239 killer_elo: Annotated[float, xFloat] = None 240 victim_elo: Annotated[float, xFloat] = None # can be "undefined" 241 has_splash: Annotated[bool, xBool] = None 242 object_x: float = None 243 object_y: float = None 244 object_aoe: float = None 245 object_id: Annotated[int, xNumber] = -1 246 start_x: float = None 247 start_y: float = None 248 vector_x: float = None 249 vector_y: float = None 250 vector_z: float = None
HP(victim_in_game_id, hp, armor, need_create_hit_effect, projectile_id, murder_weapon_id, attacker_in_game_id, lifesteal_amount, new_kill_count, new_death_count, multiple_kill_count, kill_streak, victim_kill_streak, killer_souls, victim_souls, killer_elo, victim_elo, has_splash, object_x, object_y, object_aoe, object_id, start_x, start_y, vector_x, vector_y, vector_z)
Create new instance of HP(victim_in_game_id, hp, armor, need_create_hit_effect, projectile_id, murder_weapon_id, attacker_in_game_id, lifesteal_amount, new_kill_count, new_death_count, multiple_kill_count, kill_streak, victim_kill_streak, killer_souls, victim_souls, killer_elo, victim_elo, has_splash, object_x, object_y, object_aoe, object_id, start_x, start_y, vector_x, vector_y, vector_z)
252class PlayerRespawn(NamedTuple): 253 in_game_id: int 254 x: float 255 y: float 256 has_turned_zombie: Annotated[bool, Pipe(int, bool)]
PlayerRespawn(in_game_id, x, y, has_turned_zombie)
258class AbilityCancel(NamedTuple): 259 player_in_game_id: int 260 ability: Annotated[Ability, Pipe(int, Ability)]
AbilityCancel(player_in_game_id, ability)
Create new instance of AbilityCancel(player_in_game_id, ability)
InGameChat(in_game_id, message)