From c8f5803c8341f76b85f7db634e7aad8b87f3f1c9 Mon Sep 17 00:00:00 2001 From: xeals Date: Tue, 28 Mar 2023 00:00:27 +1100 Subject: [PATCH] track indirect ko source players --- main.py | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/main.py b/main.py index e0b0137..4f5718a 100755 --- a/main.py +++ b/main.py @@ -79,7 +79,7 @@ def _init_db(conn: sqlite3.Connection): UNIQUE(game, turn, player) ); CREATE TABLE IF NOT EXISTS indirect_knockouts( - game, turn, player, name, source, source_user, + game, turn, player, name, source, source_user, source_player, UNIQUE(game, turn, player) ); CREATE TABLE IF NOT EXISTS games( @@ -183,32 +183,38 @@ def parse_log(game: str, log: str, into: sqlite3.Connection): source = rest[1].replace("[from] ", "") source_user = None - if source == "Recoil" or source.startswith("item: "): - source_user = source.replace("item: ", "") - - if source_user: - LOG.debug(f"identified special source {source_user}") - else: - source_user = last_env_set.get((mon[0:1], source)) - - if source_user: + test_hazard = last_env_set.get((mon[0:1], source)) + if test_hazard: + source_user = test_hazard LOG.debug(f"identified hazard source {source_user}") - else: - source_user = last_status_set.get((mon, source)) - if source_user: + test_status = last_status_set.get((mon, source)) + if test_status: + source_user = test_status LOG.debug(f"identified move source {source_user}") - else: + + if source == "Recoil" or source.startswith("item: "): + LOG.debug(f"identified special source {source}") + source = source.replace("item: ", "") + source_user = "self" + + if not source_user: LOG.error(f"missing source for {line}") continue + player, mon = resolve_mon(mon) + if source_user.startswith("p1") or source_user.startswith("p2"): + source_player, source_user = resolve_mon(source_user) + else: + source_player = None + conn.execute( """ - INSERT INTO indirect_knockouts(game, turn, player, name, source, source_user) - VALUES(?, ?, ?, ?, ?, ?) + INSERT INTO indirect_knockouts(game, turn, player, name, source, source_user, source_player) + VALUES(?, ?, ?, ?, ?, ?, ?) ON CONFLICT DO NOTHING """, - (game, turn, player, mon, source, source_user), + (game, turn, player, mon, source, source_user, source_player), ) case _: # LOG.debug(f"unhandled message {chunks[0]}")