tavern_keeper/src/item.rs

52 lines
1.1 KiB
Rust

use std::fmt;
use crate::entity::{Entity, Location};
#[derive(Clone)]
pub enum ItemType {
Weapon(Weapon),
Armor(Armor),
}
#[derive(Clone)]
pub struct Item {
pub entity: Entity,
pub name: String,
pub item_type: ItemType,
}
#[derive(Clone)]
pub struct Weapon {
pub damage_base: u32,
pub damage_dice: u32,
pub damage_sides: u32,
}
#[derive(Clone)]
pub struct Armor {
pub armor_class: u32,
}
pub struct ItemGenerator;
impl ItemGenerator {
pub fn generate_item() -> Item {
Item {
entity: Entity { id: 0, loc: Location{ x: 0, y: 0 } },
name: "Sword".to_string(),
item_type: ItemType::Weapon(Weapon {
damage_base: 0,
damage_dice: 1,
damage_sides: 6,
}),
}
}
}
impl fmt::Display for ItemType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ItemType::Weapon(weapon) => write!(f, "Weapon: {}d{}+{}", weapon.damage_dice, weapon.damage_sides, weapon.damage_base),
ItemType::Armor(armor) => write!(f, "Armor: {}", armor.armor_class),
}
}
}