1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
//==============================================================================
//IEconDOTA2_<ID>
//==============================================================================

//! I have by default use Json instead of XML cause it is more popular and easy to work with, and you do not need ti use
//! them directly!!
//!
//! Almost all of the structs have `localized_name : Option<String>` as parameter, this will always
//! return `None` unless you use `language()` parameter
//! **Note**: I recommend using `language` cause it gives names like "clarity" instead of "item_clarity"

//==============================================================================
//IEconDOTA2_570
//==============================================================================

pub(crate) mod get_heroes {
    #[derive(Deserialize, Debug)]
    pub struct GetHeroesResult {
        pub(crate) result: GetHeroes,
    }

    #[derive(Deserialize, Debug)]
    pub struct GetHeroes {
        heroes: Vec<Hero>,
        count: usize,
        status: usize,
    }

    #[derive(Deserialize, Debug)]
    struct Hero {
        name: String,
        id: usize,
        localized_name: Option<String>,
    }
}

pub(crate) mod get_game_items {
    #[derive(Deserialize, Debug)]
    pub struct GetGameItemsResult {
        pub(crate) result: GetGameItems,
    }

    #[derive(Deserialize, Debug)]
    pub struct GetGameItems {
        items: Vec<Item>,
        status: usize,
    }

    #[derive(Deserialize, Debug)]
    pub struct Item {
        id: usize,
        name: String,
        cost: usize,
        secret_shop: usize,
        side_shop: usize,
        recipe: usize,
        localized_name: Option<String>,
    }
}

pub(crate) mod get_rarities {
    #[derive(Deserialize, Debug)]
    pub struct GetRaritiesResult {
        pub(crate) result: GetRarities,
    }

    #[derive(Deserialize, Debug)]
    pub struct GetRarities {
        count: usize,
        rarities: Vec<Rarity>,
        status: usize,
    }

    #[derive(Deserialize, Debug)]
    pub struct Rarity {
        name: String,
        id: usize,
        order: usize,
        color: String,
        localized_name: Option<String>,
    }
}

pub(crate) mod get_tournament_prize_pool {
    #[derive(Deserialize, Debug)]
    pub struct GetTournamentPrizePoolResult {
        pub(crate) result: GetTournamentPrizePool,
    }

    #[derive(Deserialize, Debug)]
    pub struct GetTournamentPrizePool {
        prize_pool: usize,
        league_id: usize,
        status: usize,
    }
}

//==============================================================================
//IDOTA2Match_205790
//==============================================================================

pub(crate) mod get_league_listing {
    #[derive(Deserialize, Debug)]
    pub struct GetLeagueListingResult {
        pub(crate) result: GetLeagueListing,
    }

    #[derive(Deserialize, Debug)]
    pub struct GetLeagueListing {
        leagues: Vec<League>,
    }

    #[derive(Deserialize, Debug)]
    pub struct League {
        name: String,
        #[serde(rename = "leagueid")]
        league_id: usize,
        description: Option<String>,
        tournament_url: String,
        #[serde(rename = "itemdef")]
        item_def: usize,
    }
}

//==============================================================================
//IDOTA2Match_570
//==============================================================================

pub(crate) mod get_live_league_games {

    use serde::de::{self, Error as _, MapAccess, Visitor};
    use serde::Deserialize;

    #[derive(Deserialize, Debug)]
    pub struct GetLiveLeagueGamesResult {
        pub(crate) result: GetLiveLeagueGames,
    }

    #[derive(Deserialize, Debug)]
    pub struct GetLiveLeagueGames {
        games: Vec<Game>,
        status: usize,
    }

    #[derive(Deserialize, Debug)]
    pub struct Game {
        players: Vec<Player>,
        radiant_team: Option<RadiantTeam>,
        dire_team: Option<DireTeam>,
        lobby_id: usize,
        match_id: usize,
        spectators: usize,
        league_id: usize,
        league_node_id: usize,
        stream_delay_s: usize,
        radiant_series_wins: usize,
        dire_series_wins: usize,
        series_type: usize,
        scoreboard: Option<Scoreboard>,
    }

    #[derive(Deserialize, Debug)]
    pub struct Player {
        account_id: usize,
        name: String,
        hero_id: usize,
        team: usize,
    }

    #[derive(Deserialize, Debug)]
    pub struct RadiantTeam {
        team_name: String,
        team_id: usize,
        team_logo: usize,
        complete: bool,
    }

    #[derive(Deserialize, Debug)]
    pub struct DireTeam {
        team_name: String,
        team_id: usize,
        team_logo: usize,
        complete: bool,
    }

    #[derive(Deserialize, Debug)]
    pub struct Scoreboard {
        duration: f64,
        roshan_respawn_timer: usize,
        radiant: Ancient,
        dire: Ancient,
    }

    #[derive(Deserialize, Debug)]
    pub struct Ancient {
        score: usize,
        tower_state: usize,
        barracks_state: usize,
        picks: Option<Vec<HeroId>>,
        bans: Option<Vec<HeroId>>,
        players: Vec<PlayerDetailed>,
        /// I hate steam for just giving identical keys in JSON and for mozilla to not point in out
        /// in their JSON result bobo
        #[serde(flatten)]
        abilities: Abilities,
    }

    #[derive(Debug)]
    struct Abilities(Vec<Ability>);

    #[derive(Debug, Deserialize)]
    struct Ability {
        ability_level: usize,
        ability_id: usize,
    }

    impl<'de> Deserialize<'de> for Abilities {
        fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
        where
            D: de::Deserializer<'de>,
        {
            struct MyVisitor;

            impl<'d> Visitor<'d> for MyVisitor {
                type Value = Vec<Ability>;

                fn expecting(
                    &self,
                    f: &mut std::fmt::Formatter<'_>,
                ) -> Result<(), std::fmt::Error> {
                    f.write_str("a map of abilities")
                }

                fn visit_map<M>(self, mut access: M) -> Result<Self::Value, M::Error>
                where
                    M: MapAccess<'d>,
                {
                    let mut abilities = Vec::new();
                    while let Some((key, mut value)) = access.next_entry()? {
                        if key == "abilities" {
                            abilities.append(&mut value);
                        } else {
                            return Err(M::Error::unknown_field(key, &["abilities"]));
                        }
                    }
                    Ok(abilities)
                }
            }
            Ok(Abilities(deserializer.deserialize_map(MyVisitor)?))
        }
    }

    #[derive(Deserialize, Debug)]
    pub struct HeroId {
        hero_id: usize,
    }

    #[derive(Deserialize, Debug)]
    pub struct PlayerDetailed {
        player_slot: usize,
        account_id: usize,
        hero_id: usize,
        kills: usize,
        death: usize,
        assists: usize,
        last_hits: usize,
        denies: usize,
        gold: usize,
        level: usize,
        gold_per_min: usize,
        xp_per_min: usize,
        ultimate_state: usize,
        ultimate_cooldown: usize,
        item0: usize,
        item1: usize,
        item2: usize,
        item3: usize,
        item4: usize,
        item5: usize,
        respawn_timer: usize,
        position_x: f64,
        position_y: f64,
        net_worth: usize,
    }
}

pub(crate) mod get_top_live_game {
    #[derive(Deserialize, Debug)]
    pub struct GetTopLiveGame {
        pub(crate) game_list: Vec<GameList>,
    }

    #[derive(Deserialize, Debug)]
    pub struct GameList {
        activate_time: usize,
        deactivate_time: usize,
        lobby_id: usize,
        league_id: usize,
        lobby_type: usize,
        game_type: Option<usize>,
        delay: usize,
        spectators: usize,
        game_mode: usize,
        average_mmr: usize,
        match_id: usize,
        series_id: usize,
        team_name_radiant: Option<String>,
        team_name_dire: Option<String>,
        sort_score: usize,
        last_update_time: usize,
        radiant_lead: isize,
        radiant_score: usize,
        dire_score: usize,
        players: Option<Vec<Player>>,
        building_state: usize,
        weekend_tourney_tournament_id: Option<usize>,
        weekend_tourney_division: Option<usize>,
        weekend_tourney_skill_level: Option<usize>,
        weekend_tourney_bracket_round: Option<usize>,
        custom_game_difficulty: usize,
    }

    #[derive(Deserialize, Debug)]
    pub struct Player {
        account_id: usize,
        hero_id: usize,
    }
}