Skip to content

Commit

Permalink
add ratings for status conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
Lamby777 committed Jul 11, 2024
1 parent b04850b commit c87855b
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pets-gd/assets/skillregistries/psi.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"plural": false,
"status_effect": null
},
"Recovery A": {
"Recover A": {
"type": "RecoverySkill",
"power": 1,
"recovery": {
Expand Down
6 changes: 6 additions & 0 deletions pets-gd/scenes/skills-menu.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ theme_override_colors/default_color = Color(0.803922, 0.839216, 0.956863, 1)
text = "Caustics B"
skill_id = "Caustics B"

[node name="RichTextLabel3" parent="PanelContainer/ScrollContainer/VBoxContainer" instance=ExtResource("3_fa5t7")]
layout_mode = 2
theme_override_colors/default_color = Color(0.803922, 0.839216, 0.956863, 1)
text = "Recover A"
skill_id = "Recover A"

[node name="SkillDescription" type="PanelContainer" parent="."]
custom_minimum_size = Vector2(0, 300)
layout_mode = 2
Expand Down
27 changes: 24 additions & 3 deletions pets-lib/src/battle/skills/recovery.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::borrow::BorrowMut;

use super::*;

#[derive(Debug, Serialize, Deserialize)]
Expand Down Expand Up @@ -52,11 +54,30 @@ impl Skill for RecoverySkill {

fn cast(
&self,
_caster: Rc<RefCell<dyn Battler>>,
caster: Rc<RefCell<dyn Battler>>,
_target: Rc<RefCell<dyn Battler>>,
_allies: Vec<Rc<RefCell<dyn Battler>>>,
allies: Vec<Rc<RefCell<dyn Battler>>>,
_enemies: Vec<Rc<RefCell<dyn Battler>>>,
) {
todo!()
// let targets = if self.plural { _allies } else { vec![_target] };
let targets = if self.plural { allies } else { vec![caster] };

for target in targets {
match self.recovery {
RecoveryType::HPAmount { amount } => {
RefCell::borrow_mut(&target).recover_hp(amount.into());
}

RecoveryType::HPPercent { percent } => {
let max_hp = target.borrow().max_hp();
let amount = (max_hp as f64 * percent).round() as u8;
RefCell::borrow_mut(&target).recover_hp(amount.into());
}

RecoveryType::Status { rating } => {
RefCell::borrow_mut(&target).recover_status(rating);
}
}
}
}
}
30 changes: 30 additions & 0 deletions pets-lib/src/stats/battler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,36 @@ pub trait Battler {
armored + buffs.sum()
}

fn max_hp(&self) -> IntegralStat {
self.practical_stats().max_hp
}

fn max_mana(&self) -> Option<IntegralStat> {
self.practical_stats().max_mana
}

fn recover_hp(&mut self, amount: IntegralStat) {
let max_hp = self.max_hp();
let new_hp = max_hp.min(self.hp() + amount);
*self.hp_mut() = new_hp;
}

fn recover_mana(&mut self, amount: IntegralStat) {
let max_mana = self.max_mana();
if let Some(max_mana) = max_mana {
let new_mana = max_mana.min(self.mana().unwrap_or(0) + amount);
*self.mana_mut().unwrap() = new_mana;
}
}

fn recover_status(&mut self, rating: u8) {
for effect in self.status_effects().clone() {
if effect.rating() == rating {
self.remove_status_effect(effect);
}
}
}

/// Subtract damage count from the character's HP, stopping at 0.
/// Returns the new HP.
fn take_damage(&mut self, damage: IntegralStat) -> IntegralStat {
Expand Down
28 changes: 28 additions & 0 deletions pets-lib/src/stats/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,34 @@ pub enum StatusEffect {
Disarmed,
}

impl StatusEffect {
pub fn rating(&self) -> u8 {
use StatusEffect::*;
match self {
Paralyzed => 1,
Crying => 1,
Sleeping => 1,

LightHeaded => 2,
Bleeding => 2,
Poison => 2,

Blinded => 3,
Burning => 3,
Frostbite => 3,

ShortBreath => 4,
Dizzy => 4,
Tired => 4,

PoisonR => 5,

// cannot be healed
Disarmed => 6,
}
}
}

impl Display for StatusEffect {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use StatusEffect::*;
Expand Down

0 comments on commit c87855b

Please sign in to comment.