tavern_keeper/src/item.rs

54 lines
1.2 KiB
Rust
Raw Normal View History

2023-01-06 20:19:02 +00:00
use std::fmt;
2023-01-07 08:50:09 +00:00
use crate::entity::{Entity, Location, EntityId};
2023-01-05 19:14:27 +00:00
#[derive(Clone)]
pub enum ItemType {
Weapon(Weapon),
Armor(Armor),
}
#[derive(Clone)]
pub struct Item {
pub entity: Entity,
2023-01-07 08:50:09 +00:00
pub owner: Option<EntityId>,
2023-01-05 19:14:27 +00:00
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,
}),
2023-01-07 08:50:09 +00:00
owner: None,
2023-01-05 19:14:27 +00:00
}
}
2023-01-06 20:19:02 +00:00
}
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),
}
}
2023-01-05 19:14:27 +00:00
}