add types to move tracking
This commit is contained in:
parent
e8149e7c3b
commit
87114b1d1d
41
main.py
41
main.py
@ -108,6 +108,10 @@ PokemonSpecie = t.NewType("PokemonSpecie", str)
|
|||||||
TaggedPokemon = t.NewType("TaggedPokemon", str)
|
TaggedPokemon = t.NewType("TaggedPokemon", str)
|
||||||
|
|
||||||
|
|
||||||
|
def tag(tagged: TaggedPlayer | TaggedPokemon) -> PlayerTag:
|
||||||
|
return PlayerTag(tagged[0:1])
|
||||||
|
|
||||||
|
|
||||||
TEAMS: dict[Player, Player] = {}
|
TEAMS: dict[Player, Player] = {}
|
||||||
_logged_teams: list[Player] = []
|
_logged_teams: list[Player] = []
|
||||||
|
|
||||||
@ -129,16 +133,15 @@ class LogParser:
|
|||||||
players: dict[PlayerTag, Player] = {}
|
players: dict[PlayerTag, Player] = {}
|
||||||
hp: dict[TaggedPokemon, int] = {}
|
hp: dict[TaggedPokemon, int] = {}
|
||||||
|
|
||||||
# ("p2a: Edward", "p1a: Meteo")
|
# Memorises the user of the move that causes environment setting or status,
|
||||||
# memorises the user of the move that causes environment setting or status,
|
# its target, and the move name (for debugging).
|
||||||
# and its target
|
last_move: t.Optional[tuple[TaggedPokemon, TaggedPokemon, str]] = None
|
||||||
last_move: t.Optional[tuple[str, str]]
|
|
||||||
|
|
||||||
# ("p1", "Spikes") => "p2a: Frosslas"
|
# Memorises the last hazard set against a player and the causing user.
|
||||||
last_env_set: dict[tuple[str, str], str] = {}
|
last_env_set: dict[tuple[PlayerTag, str], TaggedPokemon] = {}
|
||||||
|
|
||||||
# ("p1a: Meteo", "brn") => "p2a: Edward"
|
# Memorises statuses set on a pokemon and the causing user.
|
||||||
last_status_set: dict[tuple[str, str], str] = {}
|
last_status_set: dict[tuple[TaggedPokemon, str], TaggedPokemon] = {}
|
||||||
|
|
||||||
def __init__(self, game: str, into: sqlite3.Connection):
|
def __init__(self, game: str, into: sqlite3.Connection):
|
||||||
self.game = game
|
self.game = game
|
||||||
@ -236,7 +239,7 @@ class LogParser:
|
|||||||
user = TaggedPokemon(user_)
|
user = TaggedPokemon(user_)
|
||||||
target = TaggedPokemon(target_)
|
target = TaggedPokemon(target_)
|
||||||
|
|
||||||
last_move = (user, target)
|
last_move = (user, target, move)
|
||||||
player, _ = self.split_pokemon(user)
|
player, _ = self.split_pokemon(user)
|
||||||
self.conn.execute(
|
self.conn.execute(
|
||||||
"""
|
"""
|
||||||
@ -310,8 +313,8 @@ class LogParser:
|
|||||||
# resolve to damage source
|
# resolve to damage source
|
||||||
if last_move[1] != pokemon:
|
if last_move[1] != pokemon:
|
||||||
LOG.warning(
|
LOG.warning(
|
||||||
f"{pokemon} took direct damage but last move was not"
|
f"{pokemon} took direct damage but last move"
|
||||||
" targeted at them"
|
f" {last_move[2]} was not targeted at them"
|
||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
damage_source = last_move[0]
|
damage_source = last_move[0]
|
||||||
@ -348,7 +351,7 @@ class LogParser:
|
|||||||
source: TaggedPokemon | str | None = None
|
source: TaggedPokemon | str | None = None
|
||||||
source_is_pokemon = True
|
source_is_pokemon = True
|
||||||
|
|
||||||
test_hazard = self.last_env_set.get((pokemon[0:1], reason))
|
test_hazard = self.last_env_set.get((tag(pokemon), reason))
|
||||||
if test_hazard:
|
if test_hazard:
|
||||||
source = test_hazard
|
source = test_hazard
|
||||||
LOG.debug(f"identified hazard source {source}")
|
LOG.debug(f"identified hazard source {source}")
|
||||||
@ -412,24 +415,28 @@ class LogParser:
|
|||||||
)
|
)
|
||||||
|
|
||||||
# t.Literal, TaggedPlayer, str
|
# t.Literal, TaggedPlayer, str
|
||||||
case ["-sidestart", side, env]:
|
case ["-sidestart", side_, env]:
|
||||||
|
side = TaggedPlayer(side_)
|
||||||
|
|
||||||
if not last_move:
|
if not last_move:
|
||||||
LOG.warning(f"missing previous move for {line}")
|
LOG.warning(f"missing previous move for {line}")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
LOG.debug(f"{line} <- {last_move}")
|
LOG.debug(f"{line} <- {last_move}")
|
||||||
self.last_env_set[
|
self.last_env_set[
|
||||||
(side[0:1], env.replace("move: ", ""))
|
(tag(side), env.replace("move: ", ""))
|
||||||
] = last_move[0]
|
] = last_move[0]
|
||||||
|
|
||||||
# t.Literal, TaggedPokemon, str
|
# t.Literal, TaggedPokemon, str
|
||||||
case ["-status", mon, cond]:
|
case ["-status", pokemon_, cond]:
|
||||||
if not last_move or last_move[1] != mon:
|
pokemon = TaggedPokemon(pokemon_)
|
||||||
|
|
||||||
|
if not last_move or last_move[1] != pokemon:
|
||||||
LOG.warning(f"missing previous move for {line}")
|
LOG.warning(f"missing previous move for {line}")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
LOG.debug(f"{line} <- {last_move}")
|
LOG.debug(f"{line} <- {last_move}")
|
||||||
self.last_status_set[(mon, cond)] = last_move[0]
|
self.last_status_set[(pokemon, cond)] = last_move[0]
|
||||||
|
|
||||||
case _:
|
case _:
|
||||||
# LOG.debug(f"unhandled message {chunks[0]}")
|
# LOG.debug(f"unhandled message {chunks[0]}")
|
||||||
|
Loading…
Reference in New Issue
Block a user