@@ -65,6 +65,7 @@ class PlayerData {
6565 public List <Map <String , Object >> purchase_log = new ArrayList <>();
6666 public List <Map <String , Object >> kills_log = new ArrayList <>();
6767 public List <Map <String , Object >> deaths_log = new ArrayList <>();
68+ public List <Map <String , Object >> assists_log = new ArrayList <>();
6869 public List <Entry > buyback_log = new ArrayList <>();
6970 public List <Map <String , Object >> runes_log = new ArrayList <>();
7071 public List <Entry > connection_log = new ArrayList <>();
@@ -355,7 +356,8 @@ private void handleArrayField(Entry e, PlayerData player) {
355356 } else if (e .interval != null && e .interval ) {
356357 List <Integer > targetList = getPlayerIntegerList (player , e .type );
357358 targetList .add (e .value );
358- } else if (Arrays .asList ("purchase_log" , "kills_log" , "deaths_log" , "runes_log" , "neutral_tokens_log" ).contains (e .type )) {
359+ } else if (Arrays .asList ("purchase_log" , "kills_log" , "deaths_log" , "assists_log" , "runes_log" ,
360+ "neutral_tokens_log" ).contains (e .type )) {
359361 Map <String , Object > obj = new HashMap <>();
360362 obj .put ("time" , e .time );
361363 obj .put ("key" , e .key );
@@ -376,6 +378,10 @@ private void handleArrayField(Entry e, PlayerData player) {
376378 obj .put ("smoke" , e .smoke );
377379 }
378380
381+ if ("assists_log" .equals (e .type ) && e .ambiguous != null ) {
382+ obj .put ("ambiguous" , e .ambiguous );
383+ }
384+
379385 if ("deaths_log" .equals (e .type )) {
380386 obj .put ("gold_lost" , e .gold_lost );
381387 obj .put ("gold_fed" , e .gold_fed );
@@ -393,6 +399,8 @@ private void handleArrayField(Entry e, PlayerData player) {
393399 player .kills_log .add (obj );
394400 } else if ("deaths_log" .equals (e .type )) {
395401 player .deaths_log .add (obj );
402+ } else if ("assists_log" .equals (e .type )) {
403+ player .assists_log .add (obj );
396404 } else if ("runes_log" .equals (e .type )) {
397405 player .runes_log .add (obj );
398406 } else if ("neutral_tokens_log" .equals (e .type )) {
@@ -559,6 +567,15 @@ private String computeIllusionString(String input, Boolean isIllusion) {
559567 private boolean sharedGoldFed = false ;
560568 private Integer wkSlot = null ;
561569
570+ // assists_log: the parser reports the assist and death counters on the tick
571+ // they move, and the game credits an assist on the same tick it counts the
572+ // death, so every assist lands on a tick with the deaths it can belong to.
573+ // One death there settles it. With two, the player can't have assisted the
574+ // one they killed, and anyone the combat log lists on a death other than its
575+ // killer did get the assist. What is still left open is marked ambiguous.
576+ private List <Entry > assistLog = new ArrayList <>();
577+ private int ambiguousAssists = 0 ;
578+
562579 private void precomputeReincarnations (List <Entry > entries , Metadata meta ) {
563580 wkSlot = meta .hero_to_slot .get (WK_HERO );
564581 Map <Integer , Integer > lastState = new HashMap <>();
@@ -608,6 +625,136 @@ private void precomputeReincarnations(List<Entry> entries, Metadata meta) {
608625 // their length is unknown, so those deaths get no time_dead
609626 }
610627
628+ private static class CountedDeath {
629+ Integer slot ;
630+ Integer time ;
631+ String victim ;
632+ Integer killerSlot ;
633+ List <Integer > listed ;
634+ }
635+
636+ private void precomputeAssists (List <Entry > entries , Metadata meta ) {
637+ Map <Integer , List <Entry >> heroDeathsByTick = new HashMap <>();
638+ Map <Integer , List <Integer >> deathTicks = new HashMap <>();
639+ List <Entry > assistTicks = new ArrayList <>();
640+ for (Entry e : entries ) {
641+ if ("assist_tick" .equals (e .type )) {
642+ assistTicks .add (e );
643+ } else if ("death_tick" .equals (e .type )) {
644+ deathTicks .computeIfAbsent (e .tick , k -> new ArrayList <>()).add (e .slot );
645+ } else if ("DOTA_COMBATLOG_DEATH" .equals (e .type ) && e .tick != null
646+ && (e .targetillusion == null || !e .targetillusion )) {
647+ heroDeathsByTick .computeIfAbsent (e .tick , k -> new ArrayList <>()).add (e );
648+ }
649+ }
650+ Map <Integer , List <CountedDeath >> countedByTick = new HashMap <>();
651+ for (Map .Entry <Integer , List <Integer >> tick : deathTicks .entrySet ()) {
652+ for (Integer slot : tick .getValue ()) {
653+ CountedDeath death = new CountedDeath ();
654+ death .slot = slot ;
655+ Entry logged = loggedDeath (heroDeathsByTick , tick .getKey (), slot , meta );
656+ if (logged != null ) {
657+ death .victim = logged .targetname ;
658+ death .time = logged .time ;
659+ death .killerSlot = meta .hero_to_slot .get (logged .sourcename );
660+ death .listed = logged .assist_slots ;
661+ } else {
662+ // no combat log entry to take the name from: any name the
663+ // match maps to that slot
664+ for (Map .Entry <String , Integer > hero : meta .hero_to_slot .entrySet ()) {
665+ if (slot .equals (hero .getValue ())) {
666+ death .victim = hero .getKey ();
667+ break ;
668+ }
669+ }
670+ }
671+ countedByTick .computeIfAbsent (tick .getKey (), k -> new ArrayList <>()).add (death );
672+ }
673+ }
674+ for (Entry increment : assistTicks ) {
675+ List <CountedDeath > deaths = countedByTick .get (increment .tick );
676+ Integer playerSlot = meta .slot_to_player_slot .get (increment .slot );
677+ if (deaths == null || playerSlot == null ) {
678+ continue ;
679+ }
680+ int n = increment .value ;
681+ List <CountedDeath > enemies = new ArrayList <>();
682+ for (CountedDeath death : deaths ) {
683+ Integer victimSlot = meta .slot_to_player_slot .get (death .slot );
684+ if (victimSlot != null && isRadiant (victimSlot ) != isRadiant (playerSlot )) {
685+ enemies .add (death );
686+ }
687+ }
688+ // the game also credits some assists on a death on the player's own
689+ // side, on the same tick; those count on the scoreboard too
690+ List <CountedDeath > candidates = enemies .isEmpty () ? deaths : enemies ;
691+ if (candidates .size () > n ) {
692+ List <CountedDeath > notKilled = new ArrayList <>();
693+ for (CountedDeath death : candidates ) {
694+ if (!increment .slot .equals (death .killerSlot )) {
695+ notKilled .add (death );
696+ }
697+ }
698+ if (notKilled .size () >= n ) {
699+ candidates = notKilled ;
700+ }
701+ }
702+ if (candidates .size () > n ) {
703+ List <CountedDeath > listed = new ArrayList <>();
704+ for (CountedDeath death : candidates ) {
705+ if (death .listed != null && death .listed .contains (increment .slot )) {
706+ listed .add (death );
707+ }
708+ }
709+ if (listed .size () >= n ) {
710+ candidates = listed ;
711+ }
712+ }
713+ boolean tied = candidates .size () > n ;
714+ if (tied ) {
715+ ambiguousAssists += n ;
716+ }
717+ for (int i = 0 ; i < n ; i ++) {
718+ CountedDeath death = candidates .get (Math .min (i , candidates .size () - 1 ));
719+ Entry assist = new Entry ();
720+ assist .time = death .time != null ? death .time : increment .time ;
721+ assist .slot = increment .slot ;
722+ assist .key = death .victim ;
723+ assist .type = "assists_log" ;
724+ if (tied ) {
725+ assist .ambiguous = true ;
726+ }
727+ assistLog .add (assist );
728+ }
729+ }
730+ }
731+
732+ // the combat log entry for a counted death, one tick before the counter moves.
733+ // A Meepo death is logged once per Meepo, with the clones dying to Meepo
734+ // himself, so the entry with another attacker is the one that counts
735+ private Entry loggedDeath (Map <Integer , List <Entry >> heroDeathsByTick , Integer tick , Integer slot ,
736+ Metadata meta ) {
737+ for (int offset : new int [] { 1 , 0 , 2 }) {
738+ List <Entry > logged = heroDeathsByTick .get (tick - offset );
739+ if (logged == null ) {
740+ continue ;
741+ }
742+ Entry match = null ;
743+ for (Entry e : logged ) {
744+ if (slot .equals (meta .hero_to_slot .get (e .targetname ))) {
745+ if (match == null || (e .targetname .equals (match .sourcename )
746+ && !e .targetname .equals (e .sourcename ))) {
747+ match = e ;
748+ }
749+ }
750+ }
751+ if (match != null ) {
752+ return match ;
753+ }
754+ }
755+ return null ;
756+ }
757+
611758 private boolean consumeReincarnationDeath (Integer slot , Integer time ) {
612759 if (slot == null || time == null ) {
613760 return false ;
@@ -781,6 +928,7 @@ private List<Entry> processExpand(List<Entry> entries, Metadata meta) {
781928 precomputeReincarnations (entries , meta );
782929 precomputeMinuteSeries (entries , meta );
783930 precomputeSmokeWindows (entries , meta );
931+ precomputeAssists (entries , meta );
784932
785933 for (Entry e : entries ) {
786934 String type = e .type ;
@@ -896,6 +1044,17 @@ private List<Entry> processExpand(List<Entry> entries, Metadata meta) {
8961044 }
8971045 }
8981046
1047+ // emitted after the loop because each assist is paired with its death by
1048+ // the tick both counters moved, which the pre-scan resolves in full
1049+ for (Entry assist : assistLog ) {
1050+ expand (assist , output , meta );
1051+ }
1052+ if (ambiguousAssists > 0 ) {
1053+ System .err .format ("assists_log: %s of %s assists shared a tick with"
1054+ + " more deaths than could be told apart\n " ,
1055+ ambiguousAssists , assistLog .size ());
1056+ }
1057+
8991058 return output ;
9001059 }
9011060
@@ -1756,7 +1915,8 @@ private boolean isArrayField(String type) {
17561915 return Arrays .asList ("times" , "gold_t" , "lh_t" , "dn_t" , "xp_t" , "networth_t" ,
17571916 "camps_stacked_t" , "tower_damage_t" , "hero_damage_t" , "hero_healing_t" , "obs_log" ,
17581917 "sen_log" , "obs_left_log" , "sen_left_log" , "purchase_log" , "kills_log" ,
1759- "deaths_log" , "buyback_log" , "runes_log" , "connection_log" , "neutral_tokens_log" ,
1918+ "deaths_log" , "assists_log" , "buyback_log" , "runes_log" , "connection_log" ,
1919+ "neutral_tokens_log" ,
17601920 "neutral_item_history" ).contains (type );
17611921 }
17621922
0 commit comments