From 06217f6035185ce92c42d236814a920bab7fc4cc Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Sun, 31 Dec 2023 13:08:49 +0000 Subject: [PATCH] format code --- src/main/java/opendota/Parse.java | 742 +++++++++++++++--------------- 1 file changed, 379 insertions(+), 363 deletions(-) diff --git a/src/main/java/opendota/Parse.java b/src/main/java/opendota/Parse.java index 0cbe15ad..c6dc74cf 100644 --- a/src/main/java/opendota/Parse.java +++ b/src/main/java/opendota/Parse.java @@ -46,73 +46,73 @@ public class Parse { - public class Entry { - public Integer time = 0; - public String type; - public Integer team; - public String unit; - public String key; - public Integer value; - public Integer slot; - public Integer player_slot; - //chat event fields - public Integer player1; - public Integer player2; - //combat log fields - public String attackername; - public String targetname; - public String sourcename; - public String targetsourcename; - public Boolean attackerhero; - public Boolean targethero; - public Boolean attackerillusion; - public Boolean targetillusion; + public class Entry { + public Integer time = 0; + public String type; + public Integer team; + public String unit; + public String key; + public Integer value; + public Integer slot; + public Integer player_slot; + // chat event fields + public Integer player1; + public Integer player2; + // combat log fields + public String attackername; + public String targetname; + public String sourcename; + public String targetsourcename; + public Boolean attackerhero; + public Boolean targethero; + public Boolean attackerillusion; + public Boolean targetillusion; public Integer abilitylevel; - public String inflictor; - public Integer gold_reason; - public Integer xp_reason; - public String valuename; - //public Float stun_duration; - //public Float slow_duration; - //entity fields - public Integer gold; - public Integer lh; - public Integer xp; - public Integer x; - public Integer y; - public Integer z; - public Float stuns; - public Integer hero_id; - public transient List hero_inventory; + public String inflictor; + public Integer gold_reason; + public Integer xp_reason; + public String valuename; + // public Float stun_duration; + // public Float slow_duration; + // entity fields + public Integer gold; + public Integer lh; + public Integer xp; + public Integer x; + public Integer y; + public Integer z; + public Float stuns; + public Integer hero_id; + public transient List hero_inventory; public Integer itemslot; public Integer charges; public Integer secondary_charges; - public Integer life_state; - public Integer level; - public Integer kills; - public Integer deaths; - public Integer assists; - public Integer denies; - public Boolean entityleft; - public Integer ehandle; - public Integer obs_placed; - public Integer sen_placed; - public Integer creeps_stacked; - public Integer camps_stacked; - public Integer rune_pickups; - public Boolean repicked; - public Boolean randomed; - public Boolean pred_vict; - public Float stun_duration; - public Float slow_duration; - public Boolean tracked_death; - public Integer greevils_greed_stack; - public String tracked_sourcename; - public Integer firstblood_claimed; - public Float teamfight_participation; - public Integer towers_killed; - public Integer roshans_killed; - public Integer observers_placed; + public Integer life_state; + public Integer level; + public Integer kills; + public Integer deaths; + public Integer assists; + public Integer denies; + public Boolean entityleft; + public Integer ehandle; + public Integer obs_placed; + public Integer sen_placed; + public Integer creeps_stacked; + public Integer camps_stacked; + public Integer rune_pickups; + public Boolean repicked; + public Boolean randomed; + public Boolean pred_vict; + public Float stun_duration; + public Float slow_duration; + public Boolean tracked_death; + public Integer greevils_greed_stack; + public String tracked_sourcename; + public Integer firstblood_claimed; + public Float teamfight_participation; + public Integer towers_killed; + public Integer roshans_killed; + public Integer observers_placed; public Integer draft_order; public Boolean pick; public Integer draft_active_team; @@ -121,28 +121,29 @@ public class Entry { public Integer networth; public Integer stage; - public Entry() { - } - - public Entry(Integer time) { - this.time = time; - } - } + public Entry() { + } + + public Entry(Integer time) { + this.time = time; + } + } private class Item { String id; - //Charges can be used to determine how many items are stacked together on stackable items + // Charges can be used to determine how many items are stacked together on + // stackable items Integer slot; Integer num_charges; - //item_ward_dispenser uses num_charges for observer wards - //and num_secondary_charges for sentry wards count - //and is considered not stackable + // item_ward_dispenser uses num_charges for observer wards + // and num_secondary_charges for sentry wards count + // and is considered not stackable Integer num_secondary_charges; } private class Ability { String id; - Integer abilityLevel; + Integer abilityLevel; } @@ -151,6 +152,7 @@ public UnknownItemFoundException(String message) { super(message); } } + private class UnknownAbilityFoundException extends RuntimeException { public UnknownAbilityFoundException(String message) { super(message); @@ -171,7 +173,7 @@ public UnknownAbilityFoundException(String message) { List abilities; HashMap slot_to_playerslot = new HashMap(); HashMap steamid_to_playerslot = new HashMap(); - HashMap cosmeticsMap = new HashMap(); + HashMap cosmeticsMap = new HashMap(); HashMap dotaplusxpMap = new HashMap(); // playerslot, xp HashMap ward_ehandle_to_slot = new HashMap(); InputStream is = null; @@ -183,28 +185,27 @@ public UnknownAbilityFoundException(String message) { private ArrayList logBuffer = new ArrayList(); int serverTick = 0; - //Draft stage variable + // Draft stage variable boolean[] draftOrderProcessed = new boolean[24]; int order = 1; - boolean isDraftStartTimeProcessed = false; //flag to know if draft start time is already handled + boolean isDraftStartTimeProcessed = false; // flag to know if draft start time is already handled boolean isDotaPlusProcessed = false; - public Parse(InputStream input, OutputStream output) throws IOException - { - greevilsGreedVisitor = new GreevilsGreedVisitor(name_to_slot); - trackVisitor = new TrackVisitor(); - - is = input; - os = output; - isPlayerStartingItemsWritten = new ArrayList<>(Arrays.asList(new Boolean[numPlayers])); - Collections.fill(isPlayerStartingItemsWritten, Boolean.FALSE); - long tStart = System.currentTimeMillis(); - new SimpleRunner(new InputStreamSource(is)).runWith(this); - long tMatch = System.currentTimeMillis() - tStart; - System.err.format("total time taken: %s\n", (tMatch) / 1000.0); + public Parse(InputStream input, OutputStream output) throws IOException { + greevilsGreedVisitor = new GreevilsGreedVisitor(name_to_slot); + trackVisitor = new TrackVisitor(); + + is = input; + os = output; + isPlayerStartingItemsWritten = new ArrayList<>(Arrays.asList(new Boolean[numPlayers])); + Collections.fill(isPlayerStartingItemsWritten, Boolean.FALSE); + long tStart = System.currentTimeMillis(); + new SimpleRunner(new InputStreamSource(is)).runWith(this); + long tMatch = System.currentTimeMillis() - tStart; + System.err.format("total time taken: %s\n", (tMatch) / 1000.0); } - + public void output(Entry e) { try { if (gameStartTime == 0 && logBuffer != null) { @@ -213,9 +214,7 @@ public void output(Entry e) { e.time -= gameStartTime; this.os.write((g.toJson(e) + "\n").getBytes()); } - } - catch (IOException ex) - { + } catch (IOException ex) { // System.err.println(ex); } } @@ -229,38 +228,41 @@ public void flushLogBuffer() { } logBuffer = null; } - - //@OnMessage(GeneratedMessage.class) + + // @OnMessage(GeneratedMessage.class) public void onMessage(Context ctx, GeneratedMessage message) { System.err.println(message.getClass().getName()); System.out.println(message.toString()); } - /*@OnMessage(DotaUserMessages.CDOTAUserMsg_SpectatorPlayerClick.class) - public void onSpectatorPlayerClick(Context ctx, DotaUserMessages.CDOTAUserMsg_SpectatorPlayerClick message){ - Entry entry = new Entry(time); - entry.type = "clicks"; - //need to get the entity by index - entry.key = String.valueOf(message.getOrderType()); - - Entity e = ctx.getProcessor(Entities.class).getByIndex(message.getEntindex()); - entry.x = getEntityProperty(e, "m_iCursor.0000", null); - entry.y = getEntityProperty(e, "m_iCursor.0001", null); - entry.slot = getEntityProperty(e, "m_iPlayerID", null); - //theres also target_index - output(entry); - } */ + /* + * @OnMessage(DotaUserMessages.CDOTAUserMsg_SpectatorPlayerClick.class) + * public void onSpectatorPlayerClick(Context ctx, + * DotaUserMessages.CDOTAUserMsg_SpectatorPlayerClick message){ + * Entry entry = new Entry(time); + * entry.type = "clicks"; + * //need to get the entity by index + * entry.key = String.valueOf(message.getOrderType()); + * + * Entity e = + * ctx.getProcessor(Entities.class).getByIndex(message.getEntindex()); + * entry.x = getEntityProperty(e, "m_iCursor.0000", null); + * entry.y = getEntityProperty(e, "m_iCursor.0001", null); + * entry.slot = getEntityProperty(e, "m_iPlayerID", null); + * //theres also target_index + * output(entry); + * } + */ - @OnMessage(CMsgDOTAMatch.class) - public void onDotaMatch(Context ctx, CMsgDOTAMatch message) - { - //TODO could use this for match overview data for uploads - //System.err.println(message); + public void onDotaMatch(Context ctx, CMsgDOTAMatch message) { + // TODO could use this for match overview data for uploads + // System.err.println(message); } public Integer getPlayerSlotFromEntity(Context ctx, Entity e) { - if (e == null) return null; + if (e == null) + return null; Integer slot = getEntityProperty(e, "m_nPlayerID", null); // Sentry wards still use pre 7.31 property for storing new ID if (slot == null) { @@ -276,15 +278,16 @@ public Integer getPlayerSlotFromEntity(Context ctx, Entity e) { public void onSpectatorPlayerUnitOrders(Context ctx, CDOTAUserMsg_SpectatorPlayerUnitOrders message) { Entry entry = new Entry(time); entry.type = "actions"; - //the entindex points to a CDOTAPlayer. This is probably the player that gave the order. + // the entindex points to a CDOTAPlayer. This is probably the player that gave + // the order. Entity e = ctx.getProcessor(Entities.class).getByIndex(message.getEntindex()); entry.slot = getPlayerSlotFromEntity(ctx, e); - //Integer handle = (Integer)getEntityProperty(e, "m_hAssignedHero", null); - //Entity h = ctx.getProcessor(Entities.class).getByHandle(handle); - //System.err.println(h.getDtClass().getDtName()); - //break actions into types? + // Integer handle = (Integer)getEntityProperty(e, "m_hAssignedHero", null); + // Entity h = ctx.getProcessor(Entities.class).getByHandle(handle); + // System.err.println(h.getDtClass().getDtName()); + // break actions into types? entry.key = String.valueOf(message.getOrderType()); - //System.err.println(message); + // System.err.println(message); output(entry); } @@ -299,18 +302,18 @@ public void onPlayerPing(Context ctx, CDOTAUserMsg_LocationPing message) { entry.type = "pings"; entry.slot = message.getPlayerId(); /* - System.err.println(message); - player_id: 7 - location_ping { - x: 5871 - y: 6508 - target: -1 - direct_ping: false - type: 0 - } - */ - //we could get the ping coordinates/type if we cared - //entry.key = String.valueOf(message.getOrderType()); + * System.err.println(message); + * player_id: 7 + * location_ping { + * x: 5871 + * y: 6508 + * target: -1 + * direct_ping: false + * type: 0 + * } + */ + // we could get the ping coordinates/type if we cared + // entry.key = String.valueOf(message.getOrderType()); output(entry); } @@ -341,18 +344,18 @@ public void onAllChatMessage(Context ctx, CDOTAUserMsg_ChatMessage message) { @OnMessage(CDOTAUserMsg_ChatWheel.class) public void onChatWheel(Context ctx, CDOTAUserMsg_ChatWheel message) { - Entry entry = new Entry(time); - entry.type = "chatwheel"; - entry.slot = message.getPlayerId(); - entry.key = String.valueOf(message.getChatMessageId()); - output(entry); + Entry entry = new Entry(time); + entry.type = "chatwheel"; + entry.slot = message.getPlayerId(); + entry.key = String.valueOf(message.getChatMessageId()); + output(entry); } @OnMessage(CUserMsg_SayText2.class) public void onAllChatS1(Context ctx, CUserMsg_SayText2 message) { Entry entry = new Entry(time); - entry.unit = String.valueOf(message.getPrefix()); - entry.key = String.valueOf(message.getText()); + entry.unit = String.valueOf(message.getPrefix()); + entry.key = String.valueOf(message.getText()); entry.type = "chat"; output(entry); } @@ -370,18 +373,19 @@ public void onAllChatS2(Context ctx, CUserMessageSayText2 message) { @OnMessage(CDemoFileInfo.class) public void onFileInfo(Context ctx, CDemoFileInfo message) { - //beware of 4.2b limit! we don't currently do anything with this, so we might be able to just remove this - //we can't use the value field since it takes Integers - //Entry matchIdEntry = new Entry(); - //matchIdEntry.type = "match_id"; - //matchIdEntry.value = message.getGameInfo().getDota().getMatchId(); - //output(matchIdEntry); - + // beware of 4.2b limit! we don't currently do anything with this, so we might + // be able to just remove this + // we can't use the value field since it takes Integers + // Entry matchIdEntry = new Entry(); + // matchIdEntry.type = "match_id"; + // matchIdEntry.value = message.getGameInfo().getDota().getMatchId(); + // output(matchIdEntry); + // Extracted cosmetics data from CDOTAWearableItem entities - Entry cosmeticsEntry = new Entry(); - cosmeticsEntry.type = "cosmetics"; - cosmeticsEntry.key = new Gson().toJson(cosmeticsMap); - output(cosmeticsEntry); + Entry cosmeticsEntry = new Entry(); + cosmeticsEntry.type = "cosmetics"; + cosmeticsEntry.key = new Gson().toJson(cosmeticsMap); + output(cosmeticsEntry); // Dota plus hero levels Entry dotaPlusEntry = new Entry(); @@ -389,22 +393,21 @@ public void onFileInfo(Context ctx, CDemoFileInfo message) { dotaPlusEntry.key = new Gson().toJson(dotaplusxpMap); output(dotaPlusEntry); - //emit epilogue event to mark finish + // emit epilogue event to mark finish Entry epilogueEntry = new Entry(); epilogueEntry.type = "epilogue"; epilogueEntry.key = new Gson().toJson(message); output(epilogueEntry); } - + @OnCombatLogEntry public void onCombatLogEntry(Context ctx, CombatLogEntry cle) { - try - { + try { time = Math.round(cle.getTimestamp()); - //create a new entry + // create a new entry Entry combatLogEntry = new Entry(time); combatLogEntry.type = cle.getType().name(); - //translate the fields using string tables if necessary (get*Name methods) + // translate the fields using string tables if necessary (get*Name methods) combatLogEntry.attackername = cle.getAttackerName(); combatLogEntry.targetname = cle.getTargetName(); combatLogEntry.sourcename = cle.getDamageSourceName(); @@ -417,28 +420,27 @@ public void onCombatLogEntry(Context ctx, CombatLogEntry cle) { combatLogEntry.value = cle.getValue(); float stunDuration = cle.getStunDuration(); if (stunDuration > 0) { - combatLogEntry.stun_duration = stunDuration; + combatLogEntry.stun_duration = stunDuration; } float slowDuration = cle.getSlowDuration(); if (slowDuration > 0) { - combatLogEntry.slow_duration = slowDuration; + combatLogEntry.slow_duration = slowDuration; } - //value may be out of bounds in string table, we can only get valuename if a purchase (type 11) + // value may be out of bounds in string table, we can only get valuename if a + // purchase (type 11) if (cle.getType() == DOTA_COMBATLOG_TYPES.DOTA_COMBATLOG_PURCHASE) { combatLogEntry.valuename = cle.getValueName(); - } - else if (cle.getType() == DOTA_COMBATLOG_TYPES.DOTA_COMBATLOG_GOLD) { + } else if (cle.getType() == DOTA_COMBATLOG_TYPES.DOTA_COMBATLOG_GOLD) { combatLogEntry.gold_reason = cle.getGoldReason(); - } - else if (cle.getType() == DOTA_COMBATLOG_TYPES.DOTA_COMBATLOG_XP) { + } else if (cle.getType() == DOTA_COMBATLOG_TYPES.DOTA_COMBATLOG_XP) { combatLogEntry.xp_reason = cle.getXpReason(); } - + combatLogEntry.greevils_greed_stack = greevilsGreedVisitor.visit(time, cle); TrackStatus trackStatus = trackVisitor.visit(time, cle); if (trackStatus != null) { - combatLogEntry.tracked_death = trackStatus.tracked; - combatLogEntry.tracked_sourcename = trackStatus.inflictor; + combatLogEntry.tracked_death = trackStatus.tracked; + combatLogEntry.tracked_sourcename = trackStatus.inflictor; } if (combatLogEntry.type.equals("DOTA_COMBATLOG_GAME_STATE") && combatLogEntry.value == 6) { postGame = true; @@ -450,12 +452,10 @@ else if (cle.getType() == DOTA_COMBATLOG_TYPES.DOTA_COMBATLOG_XP) { flushLogBuffer(); } } - if (cle.getType().ordinal() <= 19) { + if (cle.getType().ordinal() <= 19) { output(combatLogEntry); - } - } - catch(Exception e) - { + } + } catch (Exception e) { System.err.println(e); System.err.println(cle); } @@ -464,16 +464,15 @@ else if (cle.getType() == DOTA_COMBATLOG_TYPES.DOTA_COMBATLOG_XP) { @OnEntityEntered public void onEntityEntered(Context ctx, Entity e) { if (e.getDtClass().getDtName().equals("CDOTAWearableItem")) { - Integer accountId = getEntityProperty(e, "m_iAccountID", null); - Integer itemDefinitionIndex = getEntityProperty(e, "m_iItemDefinitionIndex", null); - //System.err.format("%s,%s\n", accountId, itemDefinitionIndex); - if (accountId > 0) - { - // Get the owner (a hero entity) - Long accountId64 = 76561197960265728L + accountId; - Integer playerSlot = steamid_to_playerslot.get(accountId64); - cosmeticsMap.put(itemDefinitionIndex, playerSlot); - } + Integer accountId = getEntityProperty(e, "m_iAccountID", null); + Integer itemDefinitionIndex = getEntityProperty(e, "m_iItemDefinitionIndex", null); + // System.err.format("%s,%s\n", accountId, itemDefinitionIndex); + if (accountId > 0) { + // Get the owner (a hero entity) + Long accountId64 = 76561197960265728L + accountId; + Integer playerSlot = steamid_to_playerslot.get(accountId64); + cosmeticsMap.put(itemDefinitionIndex, playerSlot); + } } } @@ -487,23 +486,25 @@ public void onMessage(NetworkBaseTypes.CNETMsg_Tick message) { @OnTickStart public void onTickStart(Context ctx, boolean synthetic) { /* - Iterator cosmetics = ctx.getProcessor(Entities.class).getAllByDtName("CDOTAWearableItem"); - while ( cosmetics.hasNext() ) - { - Entity e = cosmetics.next(); - Integer accountId = getEntityProperty(e, "m_iAccountID", null); - Integer itemDefinitionIndex = getEntityProperty(e, "m_iItemDefinitionIndex", null); - if (itemDefinitionIndex == 7559) - { - System.err.format("%s,%s\n", accountId, itemDefinitionIndex); - } - } - */ - - //TODO check engine to decide whether to use s1 or s2 entities - //ctx.getEngineType() - - //s1 DT_DOTAGameRulesProxy + * Iterator cosmetics = + * ctx.getProcessor(Entities.class).getAllByDtName("CDOTAWearableItem"); + * while ( cosmetics.hasNext() ) + * { + * Entity e = cosmetics.next(); + * Integer accountId = getEntityProperty(e, "m_iAccountID", null); + * Integer itemDefinitionIndex = getEntityProperty(e, "m_iItemDefinitionIndex", + * null); + * if (itemDefinitionIndex == 7559) + * { + * System.err.format("%s,%s\n", accountId, itemDefinitionIndex); + * } + * } + */ + + // TODO check engine to decide whether to use s1 or s2 entities + // ctx.getEngineType() + + // s1 DT_DOTAGameRulesProxy Entity grp = ctx.getProcessor(Entities.class).getByDtName("CDOTAGamerulesProxy"); Entity pr = ctx.getProcessor(Entities.class).getByDtName("CDOTA_PlayerResource"); Entity dData = ctx.getProcessor(Entities.class).getByDtName("CDOTA_DataDire"); @@ -512,35 +513,36 @@ public void onTickStart(Context ctx, boolean synthetic) { // Create draftStage variable Integer draftStage = getEntityProperty(grp, "m_pGameRules.m_nGameState", null); - if (grp != null) - { - //System.err.println(grp); - //dota_gamerules_data.m_iGameMode = 22 - //dota_gamerules_data.m_unMatchID64 = 1193091757 + if (grp != null) { + // System.err.println(grp); + // dota_gamerules_data.m_iGameMode = 22 + // dota_gamerules_data.m_unMatchID64 = 1193091757 Float oldTime = getEntityProperty(grp, "m_pGameRules.m_fGameTime", null); if (oldTime == null) { // 7.32e on, need to calculate time manually boolean isPaused = getEntityProperty(grp, "m_pGameRules.m_bGamePaused", null); int timeTick = isPaused ? getEntityProperty(grp, "m_pGameRules.m_nPauseStartTick", null) : serverTick; int pausedTicks = getEntityProperty(grp, "m_pGameRules.m_nTotalPausedTicks", null); - time = Math.round((float)(timeTick - pausedTicks) / 30); + time = Math.round((float) (timeTick - pausedTicks) / 30); } else { time = Math.round(oldTime); } - // alternate to combat log for getting game zero time (looks like this is set at the same time as the game start, so it's not any better for streaming) - // Some replays don't have the combat log event for some reason so also do this here - int currGameStartTime = Math.round( (float) grp.getProperty("m_pGameRules.m_flGameStartTime")); + // alternate to combat log for getting game zero time (looks like this is set at + // the same time as the game start, so it's not any better for streaming) + // Some replays don't have the combat log event for some reason so also do this + // here + int currGameStartTime = Math.round((float) grp.getProperty("m_pGameRules.m_flGameStartTime")); if (gameStartTime == 0 && currGameStartTime != 0) { gameStartTime = currGameStartTime; flushLogBuffer(); } - if(draftStage == 2) { + if (draftStage == 2) { - //determine the time the draftings start - if(!isDraftStartTimeProcessed) { + // determine the time the draftings start + if (!isDraftStartTimeProcessed) { Long iPlayerIDsInControl = getEntityProperty(grp, "m_pGameRules.m_iPlayerIDsInControl", null); boolean isDraftStarted = iPlayerIDsInControl.compareTo(Long.valueOf(0)) != 0; - if(isDraftStarted) { + if (isDraftStarted) { Entry draftStartEntry = new Entry(time); draftStartEntry.type = "draft_start"; output(draftStartEntry); @@ -548,7 +550,8 @@ public void onTickStart(Context ctx, boolean synthetic) { } } - //Picks and ban are not in order due to draft change rules changes between patches + // Picks and ban are not in order due to draft change rules changes between + // patches // Need to listen for the picks and ban to change int[] draftHeroes = new int[24]; draftHeroes[0] = getEntityProperty(grp, "m_pGameRules.m_BannedHeroes.0000", null); @@ -562,10 +565,14 @@ public void onTickStart(Context ctx, boolean synthetic) { draftHeroes[8] = getEntityProperty(grp, "m_pGameRules.m_BannedHeroes.0008", null); draftHeroes[9] = getEntityProperty(grp, "m_pGameRules.m_BannedHeroes.0009", null); // Apparently Drafts go to 6 bans now, but have returns of null - draftHeroes[10] = getEntityProperty(grp, "m_pGameRules.m_BannedHeroes.0010", null) == null ? 0 : getEntityProperty(grp, "m_pGameRules.m_BannedHeroes.0010", null); - draftHeroes[11] = getEntityProperty(grp, "m_pGameRules.m_BannedHeroes.0011", null) == null ? 0 : getEntityProperty(grp, "m_pGameRules.m_BannedHeroes.0011", null); - draftHeroes[12] = getEntityProperty(grp, "m_pGameRules.m_BannedHeroes.0012", null) == null ? 0 : getEntityProperty(grp, "m_pGameRules.m_BannedHeroes.0012", null); - draftHeroes[13] = getEntityProperty(grp, "m_pGameRules.m_BannedHeroes.0013", null) == null ? 0 : getEntityProperty(grp, "m_pGameRules.m_BannedHeroes.0013", null); + draftHeroes[10] = getEntityProperty(grp, "m_pGameRules.m_BannedHeroes.0010", null) == null ? 0 + : getEntityProperty(grp, "m_pGameRules.m_BannedHeroes.0010", null); + draftHeroes[11] = getEntityProperty(grp, "m_pGameRules.m_BannedHeroes.0011", null) == null ? 0 + : getEntityProperty(grp, "m_pGameRules.m_BannedHeroes.0011", null); + draftHeroes[12] = getEntityProperty(grp, "m_pGameRules.m_BannedHeroes.0012", null) == null ? 0 + : getEntityProperty(grp, "m_pGameRules.m_BannedHeroes.0012", null); + draftHeroes[13] = getEntityProperty(grp, "m_pGameRules.m_BannedHeroes.0013", null) == null ? 0 + : getEntityProperty(grp, "m_pGameRules.m_BannedHeroes.0013", null); draftHeroes[14] = getEntityProperty(grp, "m_pGameRules.m_SelectedHeroes.0000", null); draftHeroes[15] = getEntityProperty(grp, "m_pGameRules.m_SelectedHeroes.0001", null); draftHeroes[16] = getEntityProperty(grp, "m_pGameRules.m_SelectedHeroes.0002", null); @@ -576,9 +583,10 @@ public void onTickStart(Context ctx, boolean synthetic) { draftHeroes[21] = getEntityProperty(grp, "m_pGameRules.m_SelectedHeroes.0007", null); draftHeroes[22] = getEntityProperty(grp, "m_pGameRules.m_SelectedHeroes.0008", null); draftHeroes[23] = getEntityProperty(grp, "m_pGameRules.m_SelectedHeroes.0009", null); - //Once a pick or ban happens grab the time and extra time remaining for both teams - for(int i = 0; i < draftHeroes.length; i++) { - if(draftHeroes[i] > 0 && draftOrderProcessed[i] == false) { + // Once a pick or ban happens grab the time and extra time remaining for both + // teams + for (int i = 0; i < draftHeroes.length; i++) { + if (draftHeroes[i] > 0 && draftOrderProcessed[i] == false) { // used to check for new bans and picks draftOrderProcessed[i] = true; Entry draftTimingsEntry = new Entry(time); @@ -587,49 +595,50 @@ public void onTickStart(Context ctx, boolean synthetic) { order = order + 1; draftTimingsEntry.pick = i >= 14; draftTimingsEntry.hero_id = draftHeroes[i]; - draftTimingsEntry.draft_active_team = getEntityProperty(grp, "m_pGameRules.m_iActiveTeam", null); - draftTimingsEntry.draft_extime0 = Math.round((float) getEntityProperty(grp, "m_pGameRules.m_fExtraTimeRemaining.0000", null)); - draftTimingsEntry.draft_extime1 = Math.round((float) getEntityProperty(grp, "m_pGameRules.m_fExtraTimeRemaining.0001", null)); + draftTimingsEntry.draft_active_team = getEntityProperty(grp, "m_pGameRules.m_iActiveTeam", + null); + draftTimingsEntry.draft_extime0 = Math + .round((float) getEntityProperty(grp, "m_pGameRules.m_fExtraTimeRemaining.0000", null)); + draftTimingsEntry.draft_extime1 = Math + .round((float) getEntityProperty(grp, "m_pGameRules.m_fExtraTimeRemaining.0001", null)); output(draftTimingsEntry); } } } - //initialize nextInterval value - if (nextInterval == 0) - { + // initialize nextInterval value + if (nextInterval == 0) { nextInterval = time; } } - if (pr != null) - { - //Radiant coach shows up in vecPlayerTeamData as position 5 - //all the remaining dire entities are offset by 1 and so we miss reading the last one and don't get data for the first dire player - //coaches appear to be on team 1, radiant is 2 and dire is 3? - //construct an array of valid indices to get vecPlayerTeamData from - if (!init) - { + if (pr != null) { + // Radiant coach shows up in vecPlayerTeamData as position 5 + // all the remaining dire entities are offset by 1 and so we miss reading the + // last one and don't get data for the first dire player + // coaches appear to be on team 1, radiant is 2 and dire is 3? + // construct an array of valid indices to get vecPlayerTeamData from + if (!init) { int added = 0; int i = 0; boolean hasWaitingForDraftPlayers = false; ArrayList playerEntries = new ArrayList(); - //according to @Decoud Valve seems to have fixed this issue and players should be in first 10 slots again - //sanity check of i to prevent infinite loop when <10 players? + // according to @Decoud Valve seems to have fixed this issue and players should + // be in first 10 slots again + // sanity check of i to prevent infinite loop when <10 players? while (added < numPlayers && i < 30) { - try - { - //check each m_vecPlayerData to ensure the player's team is radiant or dire + try { + // check each m_vecPlayerData to ensure the player's team is radiant or dire int playerTeam = getEntityProperty(pr, "m_vecPlayerData.%i.m_iPlayerTeam", i); int teamSlot = getEntityProperty(pr, "m_vecPlayerTeamData.%i.m_iTeamSlot", i); Long steamid = getEntityProperty(pr, "m_vecPlayerData.%i.m_iPlayerSteamID", i); - //System.err.format("%s %s %s: %s\n", i, playerTeam, teamSlot, steamid); + // System.err.format("%s %s %s: %s\n", i, playerTeam, teamSlot, steamid); if (playerTeam == 2 || playerTeam == 3) { - //output the player_slot based on team and teamslot + // output the player_slot based on team and teamslot Entry entry = new Entry(time); entry.type = "player_slot"; entry.key = String.valueOf(added); entry.value = (playerTeam == 2 ? 0 : 128) + teamSlot; playerEntries.add(entry); - //add it to validIndices, add 1 to added + // add it to validIndices, add 1 to added validIndices[added] = i; added += 1; slot_to_playerslot.put(added, entry.value); @@ -639,11 +648,9 @@ public void onTickStart(Context ctx, boolean synthetic) { hasWaitingForDraftPlayers = true; break; } - } - catch(Exception e) - { - //swallow the exception when an unexpected number of players (!=10) - //System.err.println(e); + } catch (Exception e) { + // swallow the exception when an unexpected number of players (!=10) + // System.err.println(e); } i += 1; @@ -656,17 +663,15 @@ public void onTickStart(Context ctx, boolean synthetic) { } } - if (init && !postGame && time >= nextInterval) - { - //System.err.println(pr); - for (int i = 0; i < numPlayers; i++) - { + if (init && !postGame && time >= nextInterval) { + // System.err.println(pr); + for (int i = 0; i < numPlayers; i++) { Integer hero = getEntityProperty(pr, "m_vecPlayerTeamData.%i.m_nSelectedHeroID", validIndices[i]); int handle = getEntityProperty(pr, "m_vecPlayerTeamData.%i.m_hSelectedHero", validIndices[i]); int playerTeam = getEntityProperty(pr, "m_vecPlayerData.%i.m_iPlayerTeam", validIndices[i]); int teamSlot = getEntityProperty(pr, "m_vecPlayerTeamData.%i.m_iTeamSlot", validIndices[i]); - //2 is radiant, 3 is dire, 1 is other? + // 2 is radiant, 3 is dire, 1 is other? Entity dataTeam = playerTeam == 2 ? rData : dData; Entry entry = new Entry(time); @@ -674,9 +679,13 @@ public void onTickStart(Context ctx, boolean synthetic) { entry.slot = i; entry.repicked = getEntityProperty(pr, "m_vecPlayerTeamData.%i.m_bHasRepicked", validIndices[i]); entry.randomed = getEntityProperty(pr, "m_vecPlayerTeamData.%i.m_bHasRandomed", validIndices[i]); - entry.pred_vict = getEntityProperty(pr, "m_vecPlayerTeamData.%i.m_bHasPredictedVictory", validIndices[i]); - entry.firstblood_claimed = getEntityProperty(pr, "m_vecPlayerTeamData.%i.m_iFirstBloodClaimed", validIndices[i]); - entry.teamfight_participation = getEntityProperty(pr, "m_vecPlayerTeamData.%i.m_flTeamFightParticipation", validIndices[i]);; + entry.pred_vict = getEntityProperty(pr, "m_vecPlayerTeamData.%i.m_bHasPredictedVictory", + validIndices[i]); + entry.firstblood_claimed = getEntityProperty(pr, "m_vecPlayerTeamData.%i.m_iFirstBloodClaimed", + validIndices[i]); + entry.teamfight_participation = getEntityProperty(pr, + "m_vecPlayerTeamData.%i.m_flTeamFightParticipation", validIndices[i]); + ; entry.level = getEntityProperty(pr, "m_vecPlayerTeamData.%i.m_iLevel", validIndices[i]); entry.kills = getEntityProperty(pr, "m_vecPlayerTeamData.%i.m_iKills", validIndices[i]); entry.deaths = getEntityProperty(pr, "m_vecPlayerTeamData.%i.m_iDeaths", validIndices[i]); @@ -689,63 +698,65 @@ public void onTickStart(Context ctx, boolean synthetic) { entry.rune_pickups = getEntityProperty(dataTeam, "m_vecDataTeam.%i.m_iRunePickups", teamSlot); entry.towers_killed = getEntityProperty(dataTeam, "m_vecDataTeam.%i.m_iTowerKills", teamSlot); entry.roshans_killed = getEntityProperty(dataTeam, "m_vecDataTeam.%i.m_iRoshanKills", teamSlot); - entry.observers_placed = getEntityProperty(dataTeam, "m_vecDataTeam.%i.m_iObserverWardsPlaced", teamSlot); + entry.observers_placed = getEntityProperty(dataTeam, "m_vecDataTeam.%i.m_iObserverWardsPlaced", + teamSlot); entry.networth = getEntityProperty(dataTeam, "m_vecDataTeam.%i.m_iNetWorth", teamSlot); entry.stage = draftStage; - - if (teamSlot >= 0) - { + + if (teamSlot >= 0) { entry.gold = getEntityProperty(dataTeam, "m_vecDataTeam.%i.m_iTotalEarnedGold", teamSlot); entry.lh = getEntityProperty(dataTeam, "m_vecDataTeam.%i.m_iLastHitCount", teamSlot); entry.xp = getEntityProperty(dataTeam, "m_vecDataTeam.%i.m_iTotalEarnedXP", teamSlot); entry.stuns = getEntityProperty(dataTeam, "m_vecDataTeam.%i.m_fStuns", teamSlot); } - - //TODO: gem, rapier time? - //need to dump inventory items for each player and possibly keep track of item entity handles - - //get the player's hero entity + + // TODO: gem, rapier time? + // need to dump inventory items for each player and possibly keep track of item + // entity handles + + // get the player's hero entity Entity e = ctx.getProcessor(Entities.class).getByHandle(handle); - //get the hero's coordinates - if (e != null) - { - //System.err.println(e); + // get the hero's coordinates + if (e != null) { + // System.err.println(e); entry.x = getEntityProperty(e, "CBodyComponent.m_cellX", null); entry.y = getEntityProperty(e, "CBodyComponent.m_cellY", null); - //System.err.format("%s, %s\n", entry.x, entry.y); - //get the hero's entity name, ex: CDOTA_Hero_Zuus + // System.err.format("%s, %s\n", entry.x, entry.y); + // get the hero's entity name, ex: CDOTA_Hero_Zuus entry.unit = e.getDtClass().getDtName(); entry.hero_id = hero; entry.life_state = getEntityProperty(e, "m_lifeState", null); - //check if hero has been assigned to entity - if (hero > 0) - { - //get the hero's entity name, ex: CDOTA_Hero_Zuus + // check if hero has been assigned to entity + if (hero > 0) { + // get the hero's entity name, ex: CDOTA_Hero_Zuus String unit = e.getDtClass().getDtName(); - //grab the end of the name, lowercase it + // grab the end of the name, lowercase it String ending = unit.substring("CDOTA_Unit_Hero_".length()); - //valve is bad at consistency and the combat log name could involve replacing camelCase with _ or not! - //double map it so we can look up both cases + // valve is bad at consistency and the combat log name could involve replacing + // camelCase with _ or not! + // double map it so we can look up both cases String combatLogName = "npc_dota_hero_" + ending.toLowerCase(); - //don't include final underscore here since the first letter is always capitalized and will be converted to underscore + // don't include final underscore here since the first letter is always + // capitalized and will be converted to underscore String combatLogName2 = "npc_dota_hero" + ending.replaceAll("([A-Z])", "_$1").toLowerCase(); - //System.err.format("%s, %s, %s\n", unit, combatLogName, combatLogName2); - //populate for combat log mapping + // System.err.format("%s, %s, %s\n", unit, combatLogName, combatLogName2); + // populate for combat log mapping name_to_slot.put(combatLogName, entry.slot); name_to_slot.put(combatLogName2, entry.slot); abilities = getHeroAbilities(ctx, e); for (Ability ability : abilities) { // Only push ability updates when the level changes - if (abilities_tracking.get(combatLogName+ability.id) != ability.abilityLevel || abilities_tracking.isEmpty()){ - Entry abilitiesEntry = new Entry(time); - abilitiesEntry.type = "DOTA_ABILITY_LEVEL"; - abilitiesEntry.targetname = combatLogName; - abilitiesEntry.valuename = ability.id; - abilitiesEntry.abilitylevel = ability.abilityLevel; - // We use the combatLogName & the ability id as some ability IDs are the same - abilities_tracking.put(combatLogName+ability.id,ability.abilityLevel); - output(abilitiesEntry); + if (abilities_tracking.get(combatLogName + ability.id) != ability.abilityLevel + || abilities_tracking.isEmpty()) { + Entry abilitiesEntry = new Entry(time); + abilitiesEntry.type = "DOTA_ABILITY_LEVEL"; + abilitiesEntry.targetname = combatLogName; + abilitiesEntry.valuename = ability.id; + abilitiesEntry.abilitylevel = ability.abilityLevel; + // We use the combatLogName & the ability id as some ability IDs are the same + abilities_tracking.put(combatLogName + ability.id, ability.abilityLevel); + output(abilitiesEntry); } } @@ -765,7 +776,8 @@ public void onTickStart(Context ctx, boolean synthetic) { } } if (!isPlayerStartingItemsWritten.get(entry.slot) && entry.hero_inventory != null) { - // Making something similar to DOTA_COMBATLOG_PURCHASE for each item in the beginning of the game + // Making something similar to DOTA_COMBATLOG_PURCHASE for each item in the + // beginning of the game isPlayerStartingItemsWritten.set(entry.slot, true); for (Item item : entry.hero_inventory) { Entry startingItemsEntry = new Entry(time); @@ -788,7 +800,8 @@ public void onTickStart(Context ctx, boolean synthetic) { // When the game is over, get dota plus levels if (postGame && !isDotaPlusProcessed) { for (int i = 0; i < numPlayers; i++) { - int xp = getEntityProperty(pr, "m_vecPlayerTeamData.%i.m_unSelectedHeroBadgeXP", i) == null ? 0 : getEntityProperty(pr, "m_vecPlayerTeamData.%i.m_unSelectedHeroBadgeXP", i); + int xp = getEntityProperty(pr, "m_vecPlayerTeamData.%i.m_unSelectedHeroBadgeXP", i) == null ? 0 + : getEntityProperty(pr, "m_vecPlayerTeamData.%i.m_unSelectedHeroBadgeXP", i); Long steamid = getEntityProperty(pr, "m_vecPlayerData.%i.m_iPlayerSteamID", i); if (steamid_to_playerslot.containsKey(steamid)) { int playerslot = steamid_to_playerslot.get(steamid); @@ -806,11 +819,10 @@ private List getHeroInventory(Context ctx, Entity eHero) { for (int i = 0; i < 8; i++) { try { Item item = getHeroItem(ctx, eHero, i); - if(item != null) { + if (item != null) { inventoryList.add(item); } - } - catch (Exception e) { + } catch (Exception e) { // System.err.println(e); } } @@ -823,23 +835,25 @@ private List getHeroAbilities(Context ctx, Entity eHero) { for (int i = 0; i < 32; i++) { try { Ability ability = getHeroAbilities(ctx, eHero, i); - if(ability != null) { + if (ability != null) { abilityList.add(ability); } - } - catch (Exception e) { + } catch (Exception e) { // System.err.println(e); } } - return abilityList; + return abilityList; } + /** * Uses "EntityNames" string table and Entities processor - * @param ctx Context + * + * @param ctx Context * @param eHero Hero entity - * @param idx 0-5 - inventory, 6-8 - backpack, 9-16 - stash - * @return {@code null} - empty slot. Throws @{@link UnknownItemFoundException} if item information can't be extracted + * @param idx 0-5 - inventory, 6-8 - backpack, 9-16 - stash + * @return {@code null} - empty slot. Throws @{@link UnknownItemFoundException} + * if item information can't be extracted */ private Item getHeroItem(Context ctx, Entity eHero, int idx) throws UnknownItemFoundException { StringTable stEntityNames = ctx.getProcessor(StringTables.class).forName("EntityNames"); @@ -850,11 +864,11 @@ private Item getHeroItem(Context ctx, Entity eHero, int idx) throws UnknownItemF return null; } Entity eItem = entities.getByHandle(hItem); - if(eItem == null) { + if (eItem == null) { throw new UnknownItemFoundException(String.format("Can't find item by its handle (%d)", hItem)); } String itemName = stEntityNames.getNameByIndex(eItem.getProperty("m_pEntity.m_nameStringableIndex")); - if(itemName == null) { + if (itemName == null) { throw new UnknownItemFoundException("Can't get item name from EntityName string table"); } @@ -862,21 +876,24 @@ private Item getHeroItem(Context ctx, Entity eHero, int idx) throws UnknownItemF item.id = itemName; item.slot = idx; int numCharges = eItem.getProperty("m_iCurrentCharges"); - if(numCharges != 0) { + if (numCharges != 0) { item.num_charges = numCharges; } int numSecondaryCharges = eItem.getProperty("m_iSecondaryCharges"); - if(numSecondaryCharges != 0) { + if (numSecondaryCharges != 0) { item.num_secondary_charges = numSecondaryCharges; } return item; } - /** + + /** * Uses "EntityNames" string table and Entities processor - * @param ctx Context + * + * @param ctx Context * @param eHero Hero entity - * @param idx 0-31 = Hero abilities including talents and special event items - * @return {@code null} - empty slot. Throws @{@link UnknownItemFoundException} if item information can't be extracted + * @param idx 0-31 = Hero abilities including talents and special event items + * @return {@code null} - empty slot. Throws @{@link UnknownItemFoundException} + * if item information can't be extracted */ private Ability getHeroAbilities(Context ctx, Entity eHero, int idx) throws UnknownAbilityFoundException { StringTable stEntityNames = ctx.getProcessor(StringTables.class).forName("EntityNames"); @@ -887,11 +904,11 @@ private Ability getHeroAbilities(Context ctx, Entity eHero, int idx) throws Unkn return null; } Entity eAbility = entities.getByHandle(hAbility); - if(eAbility == null) { + if (eAbility == null) { throw new UnknownAbilityFoundException(String.format("Can't find ability by its handle (%d)", hAbility)); } String abilityName = stEntityNames.getNameByIndex(eAbility.getProperty("m_pEntity.m_nameStringableIndex")); - if(abilityName == null) { + if (abilityName == null) { throw new UnknownAbilityFoundException("Can't get ability name from EntityName string table"); } @@ -903,58 +920,57 @@ private Ability getHeroAbilities(Context ctx, Entity eHero, int idx) throws Unkn } public T getEntityProperty(Entity e, String property, Integer idx) { - try { - if (e == null) { - return null; - } - if (idx != null) { - property = property.replace("%i", Util.arrayIdxToString(idx)); - } - FieldPath fp = e.getDtClass().getFieldPathForName(property); - return e.getPropertyForFieldPath(fp); - } - catch (Exception ex) { - return null; - } + try { + if (e == null) { + return null; + } + if (idx != null) { + property = property.replace("%i", Util.arrayIdxToString(idx)); + } + FieldPath fp = e.getDtClass().getFieldPathForName(property); + return e.getPropertyForFieldPath(fp); + } catch (Exception ex) { + return null; + } + } + + @OnWardKilled + public void onWardKilled(Context ctx, Entity e, String killerHeroName) { + Entry wardEntry = buildWardEntry(ctx, e); + wardEntry.attackername = killerHeroName; + output(wardEntry); + } + + @OnWardExpired + @OnWardPlaced + public void onWardExistenceChanged(Context ctx, Entity e) { + output(buildWardEntry(ctx, e)); } - - @OnWardKilled - public void onWardKilled(Context ctx, Entity e, String killerHeroName) { - Entry wardEntry = buildWardEntry(ctx, e); - wardEntry.attackername = killerHeroName; - output(wardEntry); - } - - @OnWardExpired - @OnWardPlaced - public void onWardExistenceChanged(Context ctx, Entity e) { - output(buildWardEntry(ctx, e)); - } - - private Entry buildWardEntry(Context ctx, Entity e) { - Entry entry = new Entry(time); - boolean isObserver = !e.getDtClass().getDtName().contains("TrueSight"); - Integer x = getEntityProperty(e, "CBodyComponent.m_cellX", null); - Integer y = getEntityProperty(e, "CBodyComponent.m_cellY", null); - Integer z = getEntityProperty(e, "CBodyComponent.m_cellZ", null); - Integer life_state = getEntityProperty(e, "m_lifeState", null); - Integer[] pos = {x, y}; - entry.x = x; - entry.y = y; - entry.z = z; - entry.type = isObserver ? "obs" : "sen"; - entry.entityleft = life_state == 1; - entry.key = Arrays.toString(pos); - entry.ehandle = e.getHandle(); - - if (entry.entityleft) { - entry.type += "_left"; + + private Entry buildWardEntry(Context ctx, Entity e) { + Entry entry = new Entry(time); + boolean isObserver = !e.getDtClass().getDtName().contains("TrueSight"); + Integer x = getEntityProperty(e, "CBodyComponent.m_cellX", null); + Integer y = getEntityProperty(e, "CBodyComponent.m_cellY", null); + Integer z = getEntityProperty(e, "CBodyComponent.m_cellZ", null); + Integer life_state = getEntityProperty(e, "m_lifeState", null); + Integer[] pos = { x, y }; + entry.x = x; + entry.y = y; + entry.z = z; + entry.type = isObserver ? "obs" : "sen"; + entry.entityleft = life_state == 1; + entry.key = Arrays.toString(pos); + entry.ehandle = e.getHandle(); + + if (entry.entityleft) { + entry.type += "_left"; } - - Integer owner = getEntityProperty(e, "m_hOwnerEntity", null); + + Integer owner = getEntityProperty(e, "m_hOwnerEntity", null); Entity ownerEntity = ctx.getProcessor(Entities.class).getByHandle(owner); entry.slot = getPlayerSlotFromEntity(ctx, ownerEntity); - - return entry; + + return entry; } }