pattern match indirect knockouts specifically

This commit is contained in:
xeals 2023-04-03 20:34:12 +10:00
parent 25b80a71a1
commit 7138482b88
Signed by: xeals
GPG Key ID: A498C7AF27EC6B5C

84
main.py
View File

@ -207,55 +207,53 @@ def parse_log(game: str, log: str, into: sqlite3.Connection):
LOG.debug(f"{line} <- {last_move}") LOG.debug(f"{line} <- {last_move}")
last_status_set[(mon, cond)] = last_move[0] last_status_set[(mon, cond)] = last_move[0]
case ["-damage", mon, *rest]: case ["-damage", mon, "0 fnt", from_]:
# rest is new_hp and sometimes a source (if not from a move) # mon has fainted from an indirect damage source
# in a knockout, new_hp is "0 fnt" LOG.debug(f"tracing source for {line}")
if rest[0] == "0 fnt" and len(rest) > 1: source = from_.replace("[from] ", "")
LOG.debug(f"tracing source for {line}") source_user = None
source = rest[1].replace("[from] ", "")
source_user = None
test_hazard = last_env_set.get((mon[0:1], source)) test_hazard = last_env_set.get((mon[0:1], source))
if test_hazard: if test_hazard:
source_user = test_hazard source_user = test_hazard
LOG.debug(f"identified hazard source {source_user}") LOG.debug(f"identified hazard source {source_user}")
test_status = last_status_set.get((mon, source)) test_status = last_status_set.get((mon, source))
if test_status: if test_status:
source_user = test_status source_user = test_status
LOG.debug(f"identified move source {source_user}") LOG.debug(f"identified move source {source_user}")
if source == "Recoil" or source.startswith("item: "): if source == "Recoil" or source.startswith("item: "):
LOG.debug(f"identified special source {source}") LOG.debug(f"identified special source {source}")
source = source.replace("item: ", "") source = source.replace("item: ", "")
source_user = "self" source_user = "self"
if not source_user: if not source_user:
LOG.error(f"missing source for {line}") LOG.error(f"missing source for {line}")
continue continue
player, mon = resolve_mon(mon) player, mon = resolve_mon(mon)
if source_user.startswith("p1") or source_user.startswith("p2"): if source_user.startswith("p1") or source_user.startswith("p2"):
source_player, source_user = resolve_mon(source_user) source_player, source_user = resolve_mon(source_user)
else: else:
source_player = None source_player = None
conn.execute( conn.execute(
""" """
INSERT INTO indirect_knockouts(game, turn, player, name, source, source_user, source_player) INSERT INTO indirect_knockouts(game, turn, player, name, source, source_user, source_player)
VALUES(?, ?, ?, ?, ?, ?, ?) VALUES(?, ?, ?, ?, ?, ?, ?)
ON CONFLICT DO NOTHING ON CONFLICT DO NOTHING
""", """,
( (
game, game,
turn, turn,
team(player), team(player),
mon, mon,
source, source,
source_user, source_user,
team(source_player), team(source_player),
), ),
) )
case _: case _:
# LOG.debug(f"unhandled message {chunks[0]}") # LOG.debug(f"unhandled message {chunks[0]}")