Skip to content

Commit

Permalink
my god it smells like shit here, i think they were cooking fish again
Browse files Browse the repository at this point in the history
  • Loading branch information
Lamby777 committed Feb 18, 2024
1 parent 8887f27 commit b3480a4
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 1 deletion.
2 changes: 2 additions & 0 deletions pets-lib/src/battle/skills/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ mod status_effects;
use status_effects::*;

mod attack;
mod other;
mod recovery;
mod shields;
mod support;

#[typetag::serde(tag = "type")]
pub trait SkillFamily {
Expand Down
78 changes: 78 additions & 0 deletions pets-lib/src/battle/skills/other.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
use super::*;
use std::time::Duration;

#[derive(Serialize, Deserialize)]
pub struct PSIFluxSkill(pub Duration);

#[typetag::serde]
impl SkillFamily for PSIFluxSkill {
fn description(&self) -> String {
format!("Warps time in your favor for {} seconds.", self.0.as_secs())
}
}

#[derive(Serialize, Deserialize)]
pub struct PSIRewireSkill {
/// The cut of mana you put in (float between 0.0 and 1.0)
///
/// Doesn't make you any "more lucky," but if you're desperate
/// enough to use this skill, you'll probably only use it once
/// anyway, so it gives you better returns if you win... while
/// also screwing you over harder if you lose. Not an issue if
/// you've got nothing to lose, right?
///
/// Search up the "law of large numbers" or "gambler's ruin"
/// if you're curious. :)
pub multi: f64,
}

impl PSIRewireSkill {
// up to (31% lower | 30% higher) your staked mana
const MARGINS: (f64, f64) = (0.69, 1.30);

pub fn roll(&self, input: IntegralStat, cap: IntegralStat) -> IntegralStat {
// roll between low and high
let mut rng = rand::thread_rng();
let mult: f64 = rng.gen_range(Self::MARGINS.0..=Self::MARGINS.1);

// what kind of insane floating-point witchcraft is this?
(input as f64 * mult).floor().min(cap as f64).max(0.0) as IntegralStat
}

pub fn multi_as_percent_str(&self) -> String {
format!("{}%", self.multi * 100.0)
}
}

#[typetag::serde]
impl SkillFamily for PSIRewireSkill {
fn description(&self) -> String {
format!(
"Gamble away {} of your mana for the rare chance of a profit.",
self.multi_as_percent_str()
)
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_describe_rewire_10_sec() {
let skill = PSIFluxSkill(Duration::from_secs(10));
assert_eq!(
skill.description(),
"Warps time in your favor for 10 seconds."
);
}

#[test]
fn test_describe_rewire_50_percent() {
let skill = PSIRewireSkill { multi: 0.5 };
assert_eq!(
skill.description(),
"Gamble away 50% of your mana for the rare chance of a profit."
);
}
}
1 change: 0 additions & 1 deletion pets-lib/src/battle/skills/recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ pub enum RecoverySkill {

#[typetag::serde]
impl SkillFamily for RecoverySkill {
/// Panics if neither damage nor effect are present
fn description(&self) -> String {
use RecoverySkill::*;

Expand Down
6 changes: 6 additions & 0 deletions pets-lib/src/battle/skills/status_effects.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
//!
//! this module actually has nothing to do with any
//! type of skill... it's just another place to put
//! status condition data structures for reuse.
//!
use super::*;

/// status condition from a skill, and its chances
Expand Down
Empty file.
1 change: 1 addition & 0 deletions pets-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ mod prelude {
// is this bad practice? no clue and idc honestly
// it's convenient with no real caveat, therefore...
pub use indoc::indoc;
pub use rand::Rng;
pub use ribbons::unwrap_fmt;
pub use serde::{Deserialize, Serialize};

Expand Down

0 comments on commit b3480a4

Please sign in to comment.