Module attributes

Source
Expand description

§Attributes

These are definitions of abstract terms into code

§Rate

Rate of occurance

use rpg_stat::attributes::Rate;
let yes:Rate = Rate::Always;
assert_eq!(yes.worked(), true);
let no:Rate = Rate::None;
assert_eq!(no.worked(), false);
let hmmm:Rate = Rate::Some;
// who knows....

§Effectiveness

We can easily find the value of an effectiveness:

use rpg_stat::attributes::{Effectiveness, Value};
let hp:i32 = 50;
// later on we use an item and check the effectiveness of it
assert_eq!(Effectiveness::Half.value(hp), 25);

This effectiveness can be stored in a struct and you could implement a wrapper for value(T):

use rpg_stat::attributes::{Effectiveness, Value};

pub struct Item {
    pub name:String,
    pub amount:i32,
    pub effectiveness:Effectiveness,
}
impl Item {
    // much easier to use now!
    pub fn value(&self) -> i32 {
        self.effectiveness.value(self.amount)
    }
}

§Stage

use rpg_stat::attributes::{Stage, Value};
let stage:Stage = Stage::Baby.value(15);
//
assert_eq!(stage, Stage::Teen);

Enums§

Effectiveness
Rate
Stage
This is the ‘stage’ of life the creature is in Stages of life are similar to Pokemon evolution, however our creatures cannot change species randomly Using a life stage is based in real life, rather than the random changing into some other species thing

Traits§

Value