parthia_lib/fegame.rs
1//! This file defines an enumeration that accounts for the different ways games
2//! handle basic mechanics that can't be compartmentalized into units or
3//! weapons. For example, different games use different level-up systems,
4//! different hit rate systems, and different critical damage calculations. The
5//! hit rate systems are dealt with by the `rng` module but encapsulated here as
6//! well.
7
8use crate::rng::RNSystem;
9use strum_macros::{Display, EnumString, EnumIter};
10use serde::{Deserialize, Serialize};
11
12#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug, Display, EnumString, EnumIter,
13 Deserialize, Serialize)]
14pub enum FEGame {
15 FE1,
16 FE2,
17 FE3,
18 FE4,
19 FE5,
20 FE6,
21 FE7,
22 FE8,
23 FE9,
24 FE10,
25 FE11,
26 FE12,
27 FE13,
28 FE14,
29 FE15,
30 SoV,
31}
32
33
34impl FEGame {
35 /// Converts listed hit, what the game tells you the hit rate is, to true
36 /// hit, the actual hit probability. Most of the games lie to you about
37 /// this: the full details are in the `rng` module.
38 pub fn true_hit(&self, listed_hit: u32) -> f64 {
39 match self {
40 FEGame::FE1 | FEGame::FE2 | FEGame::FE3 | FEGame::FE4 |
41 FEGame::FE5 => RNSystem::OneRN.true_hit(listed_hit),
42 FEGame::FE14 | FEGame::SoV =>
43 RNSystem::FatesRN.true_hit(listed_hit),
44 _ => RNSystem::TwoRN.true_hit(listed_hit)
45 }
46 }
47
48 /// Computes critical damage: this is done by doubling Atk in FE4 and FE5,
49 /// but done by tripling damage (Atk - Def) in the other games.
50 pub fn crit_damage(&self, atk: u32, def: u32) -> u32 {
51 match self {
52 FEGame::FE4 | FEGame::FE5 => atk * 2 - def,
53 _ => (atk - def) * 3
54 }
55 }
56}