use rltk::{Point, RGB}; use serde::{Deserialize, Serialize}; use specs::error::NoError; use specs::prelude::*; use specs::saveload::{ConvertSaveload, Marker}; use specs_derive::*; #[derive(Component, ConvertSaveload, Clone)] pub struct Position { pub x: i32, pub y: i32, } impl Position { pub fn new(x: i32, y: i32) -> Self { Self { x, y } } } impl Default for Position { fn default() -> Self { Self { x: 0, y: 0 } } } #[derive(Component, ConvertSaveload, Clone)] pub struct Renderable { pub glyph: rltk::FontCharType, pub fg: RGB, pub bg: RGB, pub render_order: i32, } #[derive(Component, Serialize, Deserialize, Clone)] pub struct Player {} #[derive(Component, ConvertSaveload, Clone)] pub struct Viewshed { pub visible_tiles: Vec, pub range: i32, pub dirty: bool, } #[derive(Component, Serialize, Deserialize, Clone)] pub struct Monster {} #[derive(Component, Debug, ConvertSaveload, Clone)] pub struct Name { pub name: String, } #[derive(Component, Debug, Serialize, Deserialize, Clone)] pub struct BlocksTile {} #[derive(Component, Debug, ConvertSaveload, Clone)] pub struct CombatStats { pub max_hp: i32, pub hp: i32, pub defense: i32, pub power: i32, } #[derive(Component, Debug, ConvertSaveload, Clone)] pub struct WantsToMelee { pub target: Entity, } #[derive(Component, Debug, ConvertSaveload, Clone)] pub struct SufferDamage { pub amount: Vec, } impl SufferDamage { pub fn new_damage(store: &mut WriteStorage, victim: Entity, amount: i32) { if let Some(suffering) = store.get_mut(victim) { suffering.amount.push(amount); } else { let dmg = SufferDamage { amount: vec![amount], }; store.insert(victim, dmg).expect("Unable to insert damage"); } } } #[derive(Component, Debug, Serialize, Deserialize, Clone)] pub struct Item {} #[derive(Component, Debug, ConvertSaveload, Clone)] pub struct Potion { pub heal_amount: i32, } #[derive(Component, Debug, ConvertSaveload, Clone)] pub struct InBackpack { pub owner: Entity, } #[derive(Component, Debug, Clone, ConvertSaveload)] pub struct WantsToPickupItem { pub collected_by: Entity, pub item: Entity, } #[derive(Component, Debug, ConvertSaveload, Clone)] pub struct WantsToUseItem { pub item: Entity, pub target: Option, } #[derive(Component, Debug, Clone, ConvertSaveload)] pub struct WantsToDropItem { pub item: Entity, } #[derive(Component, Debug, Serialize, Deserialize, Clone)] pub struct Consumable {} #[derive(Component, Debug, ConvertSaveload, Clone)] pub struct ProvidesHealing { pub heal_amount: i32, } #[derive(Component, Debug, ConvertSaveload, Clone)] pub struct Heals { pub amount: Vec, } impl Heals { pub fn new_healing(store: &mut WriteStorage, target: Entity, amount: i32) { if let Some(healing) = store.get_mut(target) { healing.amount.push(amount); } else { let heal = Heals { amount: vec![amount], }; store.insert(target, heal).expect("Unable to insert heal"); } } } #[derive(Component, Debug, Clone, ConvertSaveload)] pub struct Ranged { pub range: i32, } #[derive(Component, Debug, Clone, ConvertSaveload)] pub struct InflictsDamage { pub damage: i32, } #[derive(Component, Debug, ConvertSaveload, Clone)] pub struct AreaOfEffect { pub radius: i32, } #[derive(Component, Debug, ConvertSaveload, Clone)] pub struct Confusion { pub turns: i32, } pub struct SerializeMe; #[derive(Component, Serialize, Deserialize, Clone)] pub struct SerializationHelper { pub map: super::map::Map, } #[derive(PartialEq, Copy, Clone, Serialize, Deserialize)] pub enum EquipmentSlot { Melee, Shield, Head, Shoulder, Chest, Legs, Hands, Feet, } #[derive(Component, Copy, Clone, Serialize, Deserialize)] pub struct Equippable { pub slot: EquipmentSlot, } #[derive(Component, ConvertSaveload, Clone)] pub struct Equipped { pub owner: Entity, pub slot: EquipmentSlot, } #[derive(Component, ConvertSaveload, Clone)] pub struct MeleePowerBonus { pub power: i32, } #[derive(Component, ConvertSaveload, Clone)] pub struct DefenseBonus { pub defense: i32, } #[derive(Component, ConvertSaveload, Clone)] pub struct WantsToRemoveItem { pub item: Entity, } #[derive(Component, Serialize, Deserialize, Clone)] pub struct ParticleLifetime { pub lifetime_ms: f32, } #[derive(PartialEq, Serialize, Deserialize, Clone, Copy)] pub enum HungerState { WellFed, Normal, Hungry, Starving, } #[derive(Component, Serialize, Deserialize, Clone)] pub struct HungerClock { pub state: HungerState, pub duration: i32, } #[derive(Component, Debug, Serialize, Deserialize, Clone)] pub struct ProvidesFood {} #[derive(Component, Debug, Serialize, Deserialize, Clone)] pub struct MagicMapper {} #[derive(Component, Debug, Serialize, Deserialize, Clone)] pub struct Hidden {} #[derive(Component, Debug, Serialize, Deserialize, Clone)] pub struct EntryTrigger {} #[derive(Component, Debug, Serialize, Deserialize, Clone)] pub struct EntityMoved {} #[derive(Component, Debug, Serialize, Deserialize, Clone)] pub struct SingleActivation {}