Draft Extractor¶
Hero pick and ban events with resolution.
gem.extractors.draft
¶
Draft / hero pick extractor for Dota 2 replays.
Polls CDOTAGamerulesProxy entity for hero bans and picks during the draft
phase and emits DraftEvent records in order of assignment.
Hero name resolution follows the reference implementation
(refs/parser/src/main/java/opendota/Parse.java lines 509-574, 736-739):
for picks, the NPC name is derived from the hero entity class name obtained by
resolving the player's m_hSelectedHero handle. The static heroes.json
mapping is used as a fallback for heroes whose entities do not yet exist (bans
or draft-phase picks before the entity spawns).
Reference: refs/parser/src/main/java/opendota/Parse.java lines 509-574
DraftEvent
dataclass
¶
A single hero ban or pick in the draft.
Attributes:
| Name | Type | Description |
|---|---|---|
tick |
int
|
Game tick when the assignment was detected. |
slot_index |
int
|
Draft order index — 0-13 for bans, 0-9 for picks. |
hero_id |
int
|
Dota 2 internal hero ID. |
hero_name |
str
|
NPC hero name (e.g. |
is_pick |
bool
|
True for a pick, False for a ban. |
team |
int
|
Team number (2=Radiant, 3=Dire) that made this pick/ban, or 0 if unknown. |
Source code in src/gem/extractors/draft.py
DraftExtractor
¶
Detects hero picks and bans by polling CDOTAGamerulesProxy.
Hero names for picks are resolved by following the m_hSelectedHero
handle from CDOTA_PlayerResource to the hero entity class name, then
converting the class name to an NPC name (e.g. CDOTA_Unit_Hero_Sven
→ npc_dota_hero_sven). This matches the reference implementation and
works for heroes not present in the bundled heroes.json.
Bans have no hero entity; their names are resolved from a live
hero_id → npc_name map built from picked heroes, with the static
heroes.json mapping as a final fallback.
Attach to a ReplayParser before calling parse():
Example
extractor = DraftExtractor() extractor.attach(parser) parser.parse() picks = [e for e in extractor.draft_events if e.is_pick]
Attributes:
| Name | Type | Description |
|---|---|---|
draft_events |
list[DraftEvent]
|
All detected |
Source code in src/gem/extractors/draft.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | |
attach(parser: ReplayParser) -> None
¶
Register callbacks with the parser.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parser
|
ReplayParser
|
The |
required |
finalize() -> None
¶
Re-resolve all hero names using the fully-populated live map.
During the draft phase hero entities have not yet spawned, so picks are
recorded with whatever the static fallback yields — which may be wrong
(e.g. direct-ID lookup returns kotl when the correct hero is
pugna because the replay stores api_id * 2). Call this after
parser.parse() completes so that the live map (populated once hero
entities appear) takes priority and corrects any mismatches.