""" todo: - English implementation first. - parsing combat.log Prosa. All logs start with something like 23:53:29.137 | LOGDATA LOGDATA can be quite different depending on the logfile. other forms encountered: 23:54:00.600 WARNING| combat logs: 01:04:38.805 CMBT | The typical log entry """ import re from base import Log class CombatLog(Log): @classmethod def _log_handler(cls, log): if log.get('log', '').strip().startswith(cls.__name__): return True return False @classmethod def is_handler(cls, log): if log.get('logtype', None) == 'CMBT': return cls._log_handler(log) return False def __init__(self, values=None): self.values = values def unpack(self): # unpacks the data from the values. if hasattr(self, 'matcher') and self.matcher: matchers = self.matcher if not isinstance(matchers, list): matchers = [matchers,] for matcher in matchers: m = matcher.match(self.values.get('log', '')) if m: self.values.update(m.groupdict()) return True # @todo: where does this come from? class Action(CombatLog): pass class Gameplay(CombatLog): matcher = [ # usual: team(reason). explained reason. re.compile(r"^Gameplay\sfinished\.\sWinner\steam\:\s+(?P\d+)\((?P\w+)\)\.\sFinish\sreason\:\s'(?P[^']+)'\.\sActual\sgame\stime\s+(?P\d+|\d+\.\d+)\ssec"), # team, unexplained reason (unknown, Timeout) re.compile(r"^Gameplay\sfinished\.\sWinner\steam\:\s+(?P\d+).\sFinish\sreason\:\s'(?P[^']+)'\.\sActual\sgame\stime\s+(?P\d+|\d+\.\d+)\ssec"), ] class Apply(CombatLog): # Apply Aura. matcher = re.compile(r"^Apply\saura\s'(?P\w+)'\sid\s(?P\d+)\stype\s(?P\w+)\sto\s'(?P[^\']+)'") class Damage(CombatLog): matcher = re.compile(r"^Damage\s+(?P[^\s]+)\s\->\s+(?P[^\s]+)\s+(?P(?:\d+|\d+\.\d+))(?:\s(?P[^\s]+)\s|\s{2,2})(?P(?:\w|\|)+)") class Spawn(CombatLog): matcher = re.compile(r"^Spawn\sSpaceShip\sfor\splayer(?P\d+)\s\((?P[^,]+),\s+(?P#\w+)\)\.\s+'(?P\w+)'") class Spell(CombatLog): matcher = re.compile(r"^Spell\s'(?P\w+)'\sby\s+(?P.*)(?:\((?P\w+)\)|)\stargets\((?P\d+)\)\:(?:$|\s(?P.+))") class Reward(CombatLog): matcher = re.compile(r"^Reward\s+(?P[^\s]+)(?:\s(?P\w+)\s+|\s+)(?P\d+)\s(?P.*)\s+for\s(?P.*)") class Participant(CombatLog): matcher = re.compile(r"^\s+Participant\s+(?P[^\s]+)(?:\s{2}(?P\w+)|\s{30,})\s+(?:totalDamage\s(?P(?:\d+|\d+\.\d+));\smostDamageWith\s'(?P[^']+)';(?P.*)|<(?P\w+)>)") class Rocket(CombatLog): matcher = re.compile(r"^Rocket\s(?Plaunch|detonation)\.\sowner\s'(?P[^']+)'(?:,\s(?:def\s'(?P\w+)'|target\s'(?P[^']+)'|reason\s'(?P\w+)'|directHit\s'(?P[^']+)'))+") class Heal(CombatLog): matcher = [ # heal by module re.compile(r"^Heal\s+(?P[^\s]+)\s\->\s+(?P[^\s]+)\s+(?P(?:\d+|\d+\.\d+))\s(?P[^\s]+)"), # direct heal by source or n/a (global buff) re.compile(r"^Heal\s+(?:n/a|(?P\w+))\s+\->\s+(?P[^\s]+)\s+(?P(?:\d+|\d+\.\d+))"), ] class Killed(CombatLog): matcher = [ re.compile(r"^Killed\s(?P[^\s]+)\s+(?P\w+);\s+killer\s(?P[^\s]+)\s*"), re.compile(r"^Killed\s(?P[^\(]+)\((?P\w+)\);\s+killer\s(?P[^\s]+)\s*"), re.compile(r"^Killed\s(?P[^\;]+);\s+killer\s(?P[^\s]+)\s+.*"), ] class Captured(CombatLog): matcher = re.compile(r"^Captured\s'(?P[^']+)'\(team\s(?P\d+)\)\.(?:\sAttackers\:(?P.*)|.*)") class AddStack(CombatLog): matcher = re.compile(r"^AddStack\saura\s'(?P\w+)'\sid\s(?P\d+)\stype\s(?P\w+)\.\snew\sstacks\scount\s(?P\d+)") class Cancel(CombatLog): matcher = re.compile(r"^Cancel\saura\s'(?P\w+)'\sid\s(?P\d+)\stype\s(?P\w+)\sfrom\s'(?P[^']+)'") class Scores(CombatLog): matcher = re.compile(r"^Scores\s+-\sTeam1\((?P(?:\d+|\d+\.\d+))\)\sTeam2\((?P(?:\d+|\d+\.\d+))\)") # Special classes class GameEvent(CombatLog): matcher = [ # game session identifier. re.compile(r"^Connect\sto\sgame\ssession\s+(?P\d+)"), # start gameplay identifier. re.compile(r"^Start\sgameplay\s'(?P\w+)'\smap\s+'(?P\w+)',\slocal\sclient\steam\s(?P\d+)"), # pve mission identifier. re.compile(r"^Start\sPVE\smission\s'(?P\w+)'\smap\s+'(?P\w+)'"), ] @classmethod def _log_handler(cls, log): if log.get('log', '').strip().startswith('======='): return True return False def unpack(self): # unpacks the data from the values. # small override to remove trailing "="s in the matching. if hasattr(self, 'matcher') and self.matcher: matchers = self.matcher if not isinstance(matchers, list): matchers = [matchers,] for matcher in matchers: m = matcher.match(self.values.get('log', '').strip('=').strip()) if m: self.values.update(m.groupdict()) return True class UserEvent(CombatLog): """ special class for combat logs that might be associated with the playing player """ @classmethod def _log_handler(cls, log): if log.get('log', '').strip(): return True return False # Action? COMBAT_LOGS = [ Apply, Damage, Spawn, Spell, Reward, Participant, Rocket, Heal, Gameplay, #? Scores, Killed, Captured, AddStack, Cancel, GameEvent, UserEvent ]