rusty_uma_extractor 0.1.0

A set of useful utility modules for applications developed to be used with the game Umamusume: Pretty Derby.
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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
use core::range::RangeInclusive;

use super::database::{ Result, DBError };
use time::UtcDateTime;

/* 
┎─────────────────────────────────────────────────────────┒
┃                   Ω CHARACTER CARD Ω                    ┃
┖─────────────────────────────────────────────────────────┚
*/

type CharaId = i32;

/// Object structure for a character

#[derive(Debug, Clone, PartialEq)]
pub struct CharacterCard {
    /// `id` column value from `card_rarity_data` table in `master.mdb`
    pub id: i32,
    /// UID for `card_data` table in `master.mdb`
    pub card_id: i32,
    /// Character ID
    pub chara_id: CharaId,
    /// Character name
    pub name: String,
    /// Default star level character begins at
    pub default_rarity: i32,
    /// Star level for this character record
    pub rarity: i32,
    /// UID for `skill_set` table in `master.mdb`
    pub skill_set: i32,
    /// Bonus percentage when training Speed
    pub speed_talent: i32,
    /// Starting Speed value
    pub speed: i32,
    /// Max Speed value
    pub max_speed: i32,
    /// Bonus percentage when training Stamina
    pub stamina_talent: i32,
    /// Starting Stamina value
    pub stamina: i32,
    /// Max Stamina value
    pub max_stamina: i32,
    /// Bonus percentage when training Power
    pub power_talent: i32,
    /// Starting Power value
    pub power: i32,
    /// Max Power value
    pub max_power: i32,
    /// Bonus percentage when training Guts
    pub guts_talent: i32,
    /// Starting Guts value
    pub guts: i32,
    /// Max Guts value
    pub max_guts: i32,
    /// Bonus percentage when training Wits
    pub wis_talent: i32,
    /// Starting Wits value
    pub wis: i32,
    /// Max Wits value
    pub max_wis: i32,
    /// Default running style
    pub default_running_style: RunningStyle,
    /// Turf track performance grade
    pub turf_grade: StatGradeRating,
    /// Dirt track performance grade
    pub dirt_grade: StatGradeRating,
    /// Sprint race performance grade
    pub sprint_grade: StatGradeRating,
    /// Mile race performance grade
    pub mile_grade: StatGradeRating,
    /// Medium race performance grade
    pub medium_grade: StatGradeRating,
    /// Long race performance grade
    pub long_grade: StatGradeRating
}

/// Character stat grade ratings

#[derive(Debug, Clone, Copy, PartialEq)]
pub enum StatGradeRating {
    G,
    F,
    E,
    D,
    C,
    B,
    A,
    S
}

impl TryFrom<i32> for StatGradeRating {
    type Error = DBError;

    fn try_from(value: i32) -> Result<Self> {
        match value {
            1 => Ok(StatGradeRating::G),
            2 => Ok(StatGradeRating::F),
            3 => Ok(StatGradeRating::E),
            4 => Ok(StatGradeRating::D),
            5 => Ok(StatGradeRating::C),
            6 => Ok(StatGradeRating::B),
            7 => Ok(StatGradeRating::A),
            8 => Ok(StatGradeRating::S),
            _ => Err(DBError::DataTypeError)
        }
    }
}

/// Character running styles

#[derive(Debug, Clone, Copy, PartialEq)]
pub enum RunningStyle {
    FrontRunner,
    PaceChaser,
    LateSurger,
    EndCloser
}

impl TryFrom<i32> for RunningStyle {
    type Error = DBError;

    fn try_from(value: i32) -> Result<Self> {
        match value {
            1 => Ok(RunningStyle::FrontRunner),
            2 => Ok(RunningStyle::PaceChaser),
            3 => Ok(RunningStyle::LateSurger),
            4 => Ok(RunningStyle::EndCloser),
            _ => Err(DBError::DataTypeError)
        }
    }
}

/* 
┎─────────────────────────────────────────────────────────┒
┃                   ☲ SUPPORT CARD ☲                     ┃
┖─────────────────────────────────────────────────────────┚
*/

/// Object sturcture for a support card

#[derive(Debug, Clone, PartialEq)]
pub struct SupportCard {
    /// `id` column value from `support_card_data` table in `master.mdb`
    pub id: i32,
    /// Character ID this support card belongs to
    pub chara_id: i32,
    /// Name of support card
    pub name: String,
    /// Support card rarity
    pub rarity: SupportCardRarity,
    /// Support card type
    pub card_type: SupportCardType,
    /// UTC timestamp
    pub timestamp: UtcDateTime
}

/// Support Card rarity

#[derive(Debug, Clone, Copy, PartialEq)]
pub enum SupportCardRarity {
    R(i32),
    SR(i32),
    SSR(i32)
}

impl TryFrom<i32> for SupportCardRarity {
    type Error = DBError;

    fn try_from(value: i32) -> Result<Self> {
        match value {
            1 => Ok(Self::R(value)),
            2 => Ok(Self::SR(value)),
            3 => Ok(Self::SSR(value)),
            _ => Err(DBError::DataTypeError)
        }   
    }
}

impl From<SupportCardRarity> for i32 {
    fn from(value: SupportCardRarity) -> Self {
        match value {
            SupportCardRarity::R(num) => num,
            SupportCardRarity::SR(num) => num,
            SupportCardRarity::SSR(num) => num
        }
    }
}

/// Support Card types

#[derive(Debug, Clone, Copy, PartialEq)]
pub enum SupportCardType {
    Pal(i32),
    Speed(i32),
    Power(i32),
    Guts(i32),
    Stamina(i32),
    Wits(i32)
}

impl TryFrom<i32> for SupportCardType {
    type Error = DBError;

    fn try_from(value: i32) -> Result<Self> {
        match value {
            0 => Ok(Self::Pal(value)),
            101 => Ok(Self::Speed(value)),
            102 => Ok(Self::Power(value)),
            103 => Ok(Self::Guts(value)),
            105 => Ok(Self::Stamina(value)),
            106 => Ok(Self::Wits(value)),
            _ => Err(DBError::DataTypeError)
        }
    }
}

impl From<SupportCardType> for i32 {
    fn from(value: SupportCardType) -> Self {
        match value {
            SupportCardType::Pal(num) => num,
            SupportCardType::Speed(num) => num,
            SupportCardType::Power(num) => num,
            SupportCardType::Guts(num) => num,
            SupportCardType::Stamina(num) => num,
            SupportCardType::Wits(num) => num
        }
    }
}

/* 
┎─────────────────────────────────────────────────────────┒
┃                   ★ FACTORS ★                          ┃
┖─────────────────────────────────────────────────────────┚
*/

/// Object structure for a factor (spark)

#[derive(Debug, Clone, PartialEq)]
pub struct Factor {
    /// `factor_id` column value from `succession_factor` table in `master.mdb`
    pub id: i32,
    /// Factor name
    pub name: String,
    /// Factor description
    pub desc: String,
    /// Number of stars
    pub rarity: i32,
    /// Factor grade
    pub grade: FactorGrade,
    /// Factor type
    pub factor_type: FactorType
}

/// Factor (spark) grade

#[derive(Debug, Clone, Copy, PartialEq)]
pub enum FactorGrade {
    Normal,
    Unique
}

impl TryFrom<i32> for FactorGrade {
    type Error = DBError;

    fn try_from(value: i32) -> Result<Self> {
        match value {
            1 => Ok(Self::Normal),
            2 => Ok(Self::Unique),
            _ => Err(DBError::DataTypeError)
        }
    }
}

/// Factor (spark) types

#[derive(Debug, Clone, Copy, PartialEq)]
pub enum FactorType {
    Blue,
    Pink,
    Green,
    Skill,
    Race,
    Scenario,
    CarnivalBonus
}

impl TryFrom<i32> for FactorType {
    type Error = DBError;

    fn try_from(value: i32) -> Result<Self> {
        match value {
            1 => Ok(Self::Blue),
            2 => Ok(Self::Pink),
            3 => Ok(Self::Green),
            4 => Ok(Self::Skill),
            5 => Ok(Self::Race),
            6 => Ok(Self::Scenario),
            7 => Ok(Self::CarnivalBonus),
            _ => Err(DBError::DataTypeError)
        }
    }
}

/// Object structure for holding data relevant to Initial Succession points from Factors
/// 
/// Only Blue or Pink factors currently contribute to added points for initial succession. Green and White factors contribute later during inspiration events
/// 
/// - Blue factors only care about how many stars are being contributed by the veteran characters (1, 2, or 3) of that type individually to max-depth of 
/// the veteran's parents (successor's grand-parents, great grand-parents only contribute Pink factor stars). 
/// The `add_point` value for these is the number of stat points the veteran would contribute to the successor's stats of the same type in the beginning of the campaign.
/// - Pink factors care about the number of stars being contributed in total by the veteran character, their parents, and grand-parents (great grand-parents of successor) 
/// of that factor type. 

#[derive(Debug, Clone, PartialEq)]
pub struct FactorInitialSuccession {
    /// Factor type
    pub factor_type: FactorType,
    /// Range of stars required
    pub rarity_range: RangeInclusive<i32>,
    /// Number of points added to the successor's stats according to this `FactorType`
    pub add_point: i32
}


/* 
┎─────────────────────────────────────────────────────────┒
┃                   ◎ SKILLS ◎                            ┃
┖─────────────────────────────────────────────────────────┚
*/

/// Object structure for a skill

#[derive(Debug, Clone, PartialEq)]
pub struct Skill {
    /// `id` column value from `skill_data` table in `master.mdb`
    pub id: i32,
    /// General category
    pub category: SkillCategory,
    /// Skill name
    pub name: String,
    /// Skill description
    pub desc: String,
    /// Unknown value function - most likely relates to rank scoring. It should be noted that values <= 0 indicate Debuff
    pub grade_val: i32,
    /// `tag_id` value from `skill_data` table in `master.mdb`
    pub tag_id: String,
    /// Tuple of `SkillCondition` objects
    pub skill_conditions: (SkillCondition,Option<SkillCondition>),
    /// `icon_id` column value from `skill_data` table in `master.mdb`
    pub icon_id: i32,
    /// Flag for if skill is considered of type `general`
    pub is_general_skill: bool
}

/// Object structure for skill condition params

#[derive(Debug, Clone, PartialEq)]
pub struct SkillCondition {
    /// Contains game logic for skill preconditions before able to proc
    pub precondition: String,
    /// Contains game logic for skill conditions to proc
    pub condition: String,
    /// Vector array of `SkillAbilityTarget` objects
    pub ability_targets: Vec<SkillAbilityTarget>
}

/// Object structure for ability and target types for `SkillCondition`
/// 
/// This describes the type of effect the skill will have, the type of target the skill uses, and the value of that target.
/// 
/// _**NOTE**: The `AbilityType`, `TargetType`, and `TargetValue` enum values are my best attempt to categorize them from what I could piece together from
/// manually reviewing and cross-validating other seemingly related tables and are NOT what is used to describe them in `master.mdb`; it is difficult for me to discern
/// what criteria or relationships were used in assigning the types and sometimes it appears inconsistent, but hopefully they are helpful._ 

#[derive(Debug, Clone, PartialEq)]
pub struct SkillAbilityTarget {
    /// Ability type this skill affects
    pub ability_type: Option<AbilityType>,
    /// A categorical spacial or state type of the targeted entity/ies
    pub target_type: Option<TargetType>,
    /// A value which modifies the targeted entity/ies the skill affects
    pub target_value: Option<TargetValue>
}

/// Skill ability type category

#[derive(Debug, Clone, Copy, PartialEq)]
pub enum AbilityType {
    /// Affects target's Speed value
    Speed(i32),
    /// Affects target's Stamina value
    Stamina(i32),
    /// Affects target's Power value
    Power(i32),
    /// Affects target's Power value
    Guts(i32),
    /// Affects target's Wits value
    Wits(i32),
    /// Affects a specific target
    Unique(i32),
    /// Affects target's field-of-view
    FoV(i32),
    /// Affects target's HP
    HP(i32),
    /// Skill ability always active
    AlwaysActive(i32),
    /// Affects duration of cooldown for Rushed target(s)
    RushCooldown(i32),
    /// Decreases target's velocity
    VelocityDecr(i32),
    /// Increases target's velocity
    VelocityIncr(i32),
    /// Affects target's navigation ability
    Navigation(i32),
    /// Affects target's acceleration
    Acceleration(i32),
    /// Special skill for Racing Carnival
    RacingCarnival(i32)
}

impl TryFrom<i32> for AbilityType {
    type Error = DBError;

    fn try_from(value: i32) -> Result<Self> {
        match value {
            1 => Ok(AbilityType::Speed(value)),
            2 => Ok(AbilityType::Stamina(value)),
            3 => Ok(AbilityType::Power(value)),
            4 => Ok(AbilityType::Guts(value)),
            5 => Ok(AbilityType::Wits(value)),
            6 => Ok(AbilityType::Unique(value)),
            8 => Ok(AbilityType::FoV(value)),
            9 => Ok(AbilityType::HP(value)),
            10 => Ok(AbilityType::AlwaysActive(value)),
            13 => Ok(AbilityType::RushCooldown(value)),
            21 => Ok(AbilityType::VelocityDecr(value)),
            27 => Ok(AbilityType::VelocityIncr(value)),
            28 => Ok(AbilityType::Navigation(value)),
            31 => Ok(AbilityType::Acceleration(value)),
            502 => Ok(AbilityType::RacingCarnival(value)),
            _ => Err(DBError::DataTypeError)
        }
    }
}

impl From<AbilityType> for i32 {

    fn from(value: AbilityType) -> Self {
        match value {
            AbilityType::Speed(val) => val,
            AbilityType::Stamina(val) => val,
            AbilityType::Power(val) => val,
            AbilityType::Guts(val) => val,
            AbilityType::Wits(val) => val,
            AbilityType::Unique(val) => val,
            AbilityType::FoV(val) => val,
            AbilityType::HP(val) => val,
            AbilityType::AlwaysActive(val) => val,
            AbilityType::RushCooldown(val) => val,
            AbilityType::VelocityDecr(val) => val,
            AbilityType::VelocityIncr(val) => val,
            AbilityType::Navigation(val) => val,
            AbilityType::Acceleration(val) => val,
            AbilityType::RacingCarnival(val) => val
        }
    }
}

/// Skill target types

#[derive(Debug, Clone, Copy, PartialEq)]
pub enum TargetType {
    /// Player Character
    PC(i32),
    /// Runners with active Focus state
    FocusActiveRunners(i32),
    /// Runners positioned ahead of PC
    RunnersAheadPC(i32),
    /// Runners positioned behind PC
    RunnersBehindPC(i32),
    /// Targets within immediate proximity of PC in race (directly in front or behind)
    RunnersInPCProx(i32),
    /// PC positioned towards rear of pack
    PCInRear(i32),
    /// PC positioned towards front of pack
    PCInFront(i32),
    /// Runners with active Rushed state
    RushedActiveRunners(i32),
    /// A specific playable character
    HeroCharacter(i32)
}

impl TryFrom<i32> for TargetType {
    type Error = DBError;

    fn try_from(value: i32) -> Result<Self> {
        match value {
            1 => Ok(TargetType::PC(value)),
            4 => Ok(TargetType::FocusActiveRunners(value)),
            9 => Ok(TargetType::RunnersAheadPC(value)),
            10 => Ok(TargetType::RunnersBehindPC(value)),
            18 => Ok(TargetType::RunnersInPCProx(value)),
            19 => Ok(TargetType::PCInRear(value)),
            20 => Ok(TargetType::PCInFront(value)),
            21 => Ok(TargetType::RushedActiveRunners(value)),
            22 => Ok(TargetType::HeroCharacter(value)),
            _ => Err(DBError::DataTypeError)
        }
    }
}

impl From<TargetType> for i32 {
    fn from(value: TargetType) -> Self {
        match value {
            TargetType::PC(val) => val,
            TargetType::FocusActiveRunners(val) => val,
            TargetType::RunnersAheadPC(val) => val,
            TargetType::RunnersBehindPC(val) => val,
            TargetType::RunnersInPCProx(val) => val,
            TargetType::PCInRear(val) => val,
            TargetType::PCInFront(val) => val,
            TargetType::RushedActiveRunners(val) => val,
            TargetType::HeroCharacter(val) => val,
        }
    }
}

/// Skill target values

#[derive(Debug, Clone, Copy, PartialEq)]
pub enum TargetValue {
    /// A specific playable character
    HeroCharacter(CharaId),
    /// Player Character
    PC(i32),
    /// Runners using the Front Runner style
    FrontRunners(i32),
    /// Runners using the Pace Chaser style
    PaceChasers(i32),
    /// Runners using the Late Surger style
    LateSurgers(i32),
    /// Runners using the End Closer style
    EndClosers(i32),
    /// Targets relative to PC's position in race
    FromPCOrigin(i32),
    /// Targets ahead of PC's position in race
    RunnersAheadPC(i32),
    /// Targets behind PC's position in race
    RunnersBehindPC(i32),
    /// Targets within immediate proximity of PC in race (directly in front or behind)
    RunnersInPCProx(i32)
}

impl TryFrom<i32> for TargetValue {
    type Error = DBError;

    fn try_from(value: i32) -> Result<Self> {
        match value {
            0 => Ok(TargetValue::PC(value)),
            1 => Ok(TargetValue::FrontRunners(value)),
            2 => Ok(TargetValue::PaceChasers(value)),
            3 => Ok(TargetValue::LateSurgers(value)),
            4 => Ok(TargetValue::EndClosers(value)),
            5 => Ok(TargetValue::FromPCOrigin(value)),
            9 => Ok(TargetValue::RunnersAheadPC(value)),
            10 => Ok(TargetValue::RunnersBehindPC(value)),
            18 => Ok(TargetValue::RunnersInPCProx(value)),
            1000..2000 => Ok(TargetValue::HeroCharacter(value)),
            _ => Err(DBError::DataTypeError)
        }
    }
}

impl From<TargetValue> for i32 {
    fn from(value: TargetValue) -> Self {
        match value {
            TargetValue::PC(val) => val,
            TargetValue::FrontRunners(val) => val,
            TargetValue::PaceChasers(val) => val,
            TargetValue::LateSurgers(val) => val,
            TargetValue::EndClosers(val) => val,
            TargetValue::FromPCOrigin(val) => val,
            TargetValue::RunnersAheadPC(val) => val,
            TargetValue::RunnersBehindPC(val) => val,
            TargetValue::RunnersInPCProx(val) => val,
            TargetValue::HeroCharacter(val) => val
        }
    }
}

/// Skill rarity

#[derive(Debug, Clone, Copy, PartialEq)]
pub enum SkillRarity {
    /// White / common skill
    White,
    /// Gold / rare skill
    Gold,
    /// Level of Unique skill
    Level(i32)
}

/// A Skill's general category

#[derive(Debug, Clone, Copy, PartialEq)]
pub enum SkillCategory {
    /// Skills that only require certain hard conditions to be fulfilled (i.e. weather, ground conditions, most favorite, ect,...)
    PassiveCond(SkillRarity),
    /// Skills that have conditional requirements for early/leading into mid phase of race
    EarlyRace(SkillRarity),
    /// Skills that have conditional requirements for mid phase of race
    MidRace(SkillRarity),
    /// Skills that have conditional requirements for late/last spurt phase of race
    LateRace(SkillRarity),
    /// Skills that require either a certain race distance or running style to be fulfilled
    RaceCond(SkillRarity),
    /// Skills that are unique to characters
    Unique(SkillRarity),
    /// Special category for Racing Carnival
    RacingCarnival(SkillRarity)
}

impl SkillCategory {

    pub fn into_cat(category: i32, rarity: i32) -> Result<Self> {
        match category {
            0 => match rarity {
                1 => Ok(SkillCategory::PassiveCond(SkillRarity::White)),
                2 => Ok(SkillCategory::PassiveCond(SkillRarity::Gold)),
                _ => Err(DBError::DataTypeError)
            },
            1 => match rarity {
                1 => Ok(SkillCategory::EarlyRace(SkillRarity::White)),
                2 => Ok(SkillCategory::EarlyRace(SkillRarity::Gold)),
                _ => Err(DBError::DataTypeError)
            },
            2 => match rarity {
                1 => Ok(SkillCategory::MidRace(SkillRarity::White)),
                2 => Ok(SkillCategory::MidRace(SkillRarity::Gold)),
                _ => Err(DBError::DataTypeError)
            },
            3 => match rarity {
                1 => Ok(SkillCategory::LateRace(SkillRarity::White)),
                2 => Ok(SkillCategory::LateRace(SkillRarity::Gold)),
                _ => Err(DBError::DataTypeError)
            },
            4 => match rarity {
                1 => Ok(SkillCategory::RaceCond(SkillRarity::White)),
                2 => Ok(SkillCategory::RaceCond(SkillRarity::Gold)),
                _ => Err(DBError::DataTypeError)
            },
            5 => Ok(SkillCategory::Unique(SkillRarity::Level(rarity))),
            101 => match rarity {
                1 => Ok(SkillCategory::RacingCarnival(SkillRarity::White)),
                2 => Ok(SkillCategory::RacingCarnival(SkillRarity::Gold)),
                _ => Err(DBError::DataTypeError)
            },
            _ => Err(DBError::DataTypeError)
        }
    }

    pub fn get_rarity(self) -> SkillRarity {
        match self {
            SkillCategory::PassiveCond(rarity) => rarity,
            SkillCategory::EarlyRace(rarity) => rarity,
            SkillCategory::MidRace(rarity) => rarity,
            SkillCategory::LateRace(rarity) => rarity,
            SkillCategory::RaceCond(rarity) => rarity,
            SkillCategory::Unique(level) => level,
            SkillCategory::RacingCarnival(rarity) => rarity
        }
    }
}

/* 
┎─────────────────────────────────────────────────────────┒
┃                   ⚑ RACES ⚑                            ┃
┖─────────────────────────────────────────────────────────┚
*/

/// Object structure for races

#[derive(Debug, Clone, PartialEq)]
pub struct Race {
    /// Value seen in `data.json` for `race_results_list`.
    /// Note that some races will appear to have duplicate records returned as a result of having different `program_id` values
    pub program_id: i32,
    /// UID for race in `race_instance` table in `master.mdb`     
    pub race_inst_id: i32,
    /// UID for race in `race` table in `master.mdb`
    pub race_id: i32,
    /// Name of race
    pub race_name: String,
    /// Name of the track race takes place at
    pub track_name: String,
    /// Grade of race
    pub race_grade: RaceGrade,
    /// Distance category of race
    pub race_dist: RaceDistance,
    /// Track surface type in race
    pub track_ground: RaceGround,
    /// Enumeration value for month race takes place (1=January,2=February,...,12=December) - I got tired of making enumerated types :(
    pub month: i32,
    /// Enumeration value for which half of the month race takes place (1=Early,2=Late)
    pub half: i32
}

/// Race grades

#[derive(Debug, Clone, Copy, PartialEq)]
pub enum RaceGrade {
    /// Campaign champion races also use this designation
    G1,
    G2,
    G3,
    OP,
    PreOP,
    Maiden,
    Debut
}

impl TryFrom<i32> for RaceGrade {
    type Error = DBError;

    fn try_from(value: i32) -> Result<Self> {
        match value {
            100 => Ok(RaceGrade::G1),
            200 => Ok(RaceGrade::G2),
            300 => Ok(RaceGrade::G3),
            400 => Ok(RaceGrade::OP),
            700 => Ok(RaceGrade::PreOP),
            800 => Ok(RaceGrade::Maiden),
            900 => Ok(RaceGrade::Debut),
            _ => Err(DBError::DataTypeError)
        }
    }
}

/// Race distances

#[derive(Debug, Clone, Copy, PartialEq)]
pub enum RaceDistance {
    /// 1000m - 1400m
    Sprint(i32),
    /// 1500m - 1800m
    Mile(i32),
    /// 1900m - 2400m
    Med(i32),
    /// 2500m - 3600m
    Long(i32)
}

impl TryFrom<i32> for RaceDistance {
    type Error = DBError;

    fn try_from(value: i32) -> Result<Self> {
        match value {
            1000..=1400 => Ok(RaceDistance::Sprint(value)),
            1500..=1800 => Ok(RaceDistance::Mile(value)),
            1900..=2400 => Ok(RaceDistance::Med(value)),
            2500..=3600 => Ok(RaceDistance::Long(value)),
            _ => Err(DBError::DataTypeError)
        }
    }
}

/// Race track surface types

#[derive(Debug, Clone, Copy, PartialEq)]
pub enum RaceGround {
    /// Green stuff
    Turf,
    /// Brown stuff
    Dirt
}

impl TryFrom<i32> for RaceGround {
    type Error = DBError;

    fn try_from(value: i32) -> Result<Self> {
        match value {
            1 => Ok(RaceGround::Turf),
            2 => Ok(RaceGround::Dirt),
            _ => Err(DBError::DataTypeError)
        }
    }
}