2022-01-05 11:05:15 -05:00
|
|
|
mod enums;
|
2022-01-13 10:14:13 -05:00
|
|
|
mod tags;
|
2022-01-05 11:05:15 -05:00
|
|
|
|
2022-01-03 15:24:38 -05:00
|
|
|
use std::collections::HashMap;
|
|
|
|
|
2021-12-24 10:38:44 -05:00
|
|
|
use ::rltk::{Point, RGB};
|
|
|
|
use ::serde::{Deserialize, Serialize};
|
|
|
|
use ::specs::error::NoError;
|
|
|
|
use ::specs::prelude::*;
|
|
|
|
use ::specs::saveload::{ConvertSaveload, Marker};
|
|
|
|
use ::specs_derive::*;
|
2022-01-05 11:05:15 -05:00
|
|
|
pub use enums::*;
|
2022-01-13 10:14:13 -05:00
|
|
|
pub use tags::*;
|
2021-10-22 10:05:06 -04:00
|
|
|
|
2022-01-03 15:24:38 -05:00
|
|
|
use crate::gamesystem::attr_bonus;
|
|
|
|
|
2021-12-03 15:55:07 -05:00
|
|
|
#[derive(Component, ConvertSaveload, Default, Copy, Clone)]
|
2021-10-22 10:05:06 -04:00
|
|
|
pub struct Position {
|
|
|
|
pub x: i32,
|
|
|
|
pub y: i32,
|
|
|
|
}
|
|
|
|
|
2021-12-01 15:25:48 -05:00
|
|
|
impl From<(i32, i32)> for Position {
|
|
|
|
fn from(f: (i32, i32)) -> Self {
|
2021-12-02 14:59:35 -05:00
|
|
|
Position { x: f.0, y: f.1 }
|
2021-12-01 15:25:48 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<Point> for Position {
|
|
|
|
fn from(p: Point) -> Self {
|
2021-12-02 14:59:35 -05:00
|
|
|
Position { x: p.x, y: p.y }
|
2021-12-01 15:25:48 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-02 15:03:55 -05:00
|
|
|
impl From<Position> for Point {
|
|
|
|
fn from(p: Position) -> Self {
|
|
|
|
Point { x: p.x, y: p.y }
|
2021-12-01 15:25:48 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-08 13:58:40 -05:00
|
|
|
#[derive(Component, ConvertSaveload, Clone)]
|
2021-10-22 10:05:06 -04:00
|
|
|
pub struct Renderable {
|
|
|
|
pub glyph: rltk::FontCharType,
|
|
|
|
pub fg: RGB,
|
|
|
|
pub bg: RGB,
|
2021-11-04 09:54:38 -04:00
|
|
|
pub render_order: i32,
|
2021-10-22 10:05:06 -04:00
|
|
|
}
|
|
|
|
|
2021-11-08 13:58:40 -05:00
|
|
|
#[derive(Component, ConvertSaveload, Clone)]
|
2021-10-25 15:26:39 -04:00
|
|
|
pub struct Viewshed {
|
2021-12-01 15:25:48 -05:00
|
|
|
pub visible_tiles: Vec<Point>,
|
2021-10-25 15:26:39 -04:00
|
|
|
pub range: i32,
|
2021-10-26 14:23:08 -04:00
|
|
|
pub dirty: bool,
|
2021-10-25 15:26:39 -04:00
|
|
|
}
|
2021-10-26 15:43:59 -04:00
|
|
|
|
2021-11-05 10:41:47 -04:00
|
|
|
impl Default for Viewshed {
|
|
|
|
fn default() -> Self {
|
|
|
|
Viewshed {
|
|
|
|
visible_tiles: Vec::new(),
|
|
|
|
range: 8,
|
|
|
|
dirty: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-08 13:58:40 -05:00
|
|
|
#[derive(Component, Debug, ConvertSaveload, Clone)]
|
2021-10-26 15:43:59 -04:00
|
|
|
pub struct Name {
|
|
|
|
pub name: String,
|
|
|
|
}
|
2021-10-29 11:11:17 -04:00
|
|
|
|
2021-11-05 10:41:47 -04:00
|
|
|
impl Name {
|
2021-11-18 15:25:29 -05:00
|
|
|
pub fn from<S: ToString>(s: S) -> Self {
|
2021-11-05 10:41:47 -04:00
|
|
|
Name {
|
|
|
|
name: s.to_string(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-08 13:58:40 -05:00
|
|
|
#[derive(Component, Debug, ConvertSaveload, Clone)]
|
2021-10-29 15:15:22 -04:00
|
|
|
pub struct WantsToMelee {
|
|
|
|
pub target: Entity,
|
|
|
|
}
|
|
|
|
|
2022-01-13 10:14:13 -05:00
|
|
|
#[derive(Component, Debug, Serialize, Deserialize, Clone)]
|
|
|
|
pub struct Item {
|
|
|
|
pub initiative_penalty: f32,
|
|
|
|
pub weight_lbs: f32,
|
|
|
|
pub base_value: f32,
|
|
|
|
}
|
|
|
|
|
2021-11-08 13:58:40 -05:00
|
|
|
#[derive(Component, Debug, ConvertSaveload, Clone)]
|
2021-10-29 15:15:22 -04:00
|
|
|
pub struct SufferDamage {
|
2022-01-05 14:59:45 -05:00
|
|
|
pub amount: Vec<(i32, bool)>,
|
2021-10-29 15:15:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl SufferDamage {
|
2022-01-05 14:59:45 -05:00
|
|
|
pub fn new_damage(
|
|
|
|
store: &mut WriteStorage<SufferDamage>,
|
|
|
|
victim: Entity,
|
|
|
|
amount: i32,
|
|
|
|
from_player: bool,
|
|
|
|
) {
|
2021-10-29 15:15:22 -04:00
|
|
|
if let Some(suffering) = store.get_mut(victim) {
|
2022-01-05 14:59:45 -05:00
|
|
|
suffering.amount.push((amount, from_player));
|
2021-10-29 15:15:22 -04:00
|
|
|
} else {
|
|
|
|
let dmg = SufferDamage {
|
2022-01-05 14:59:45 -05:00
|
|
|
amount: vec![(amount, from_player)],
|
2021-10-29 15:15:22 -04:00
|
|
|
};
|
|
|
|
store.insert(victim, dmg).expect("Unable to insert damage");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-11-03 15:11:19 -04:00
|
|
|
|
2021-11-08 13:58:40 -05:00
|
|
|
#[derive(Component, Debug, ConvertSaveload, Clone)]
|
|
|
|
pub struct Ranged {
|
|
|
|
pub range: i32,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Component, Debug, ConvertSaveload, Clone)]
|
|
|
|
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,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Component, Debug, ConvertSaveload, Clone)]
|
2021-11-04 15:06:04 -04:00
|
|
|
pub struct ProvidesHealing {
|
2021-11-03 15:11:19 -04:00
|
|
|
pub heal_amount: i32,
|
|
|
|
}
|
|
|
|
|
2021-11-08 13:58:40 -05:00
|
|
|
#[derive(Component, Debug, ConvertSaveload)]
|
2021-11-03 15:11:19 -04:00
|
|
|
pub struct InBackpack {
|
|
|
|
pub owner: Entity,
|
|
|
|
}
|
|
|
|
|
2021-11-08 13:58:40 -05:00
|
|
|
#[derive(Component, Debug, ConvertSaveload)]
|
2021-11-03 15:11:19 -04:00
|
|
|
pub struct WantsToPickupItem {
|
|
|
|
pub collected_by: Entity,
|
|
|
|
pub item: Entity,
|
|
|
|
}
|
2021-11-03 15:59:23 -04:00
|
|
|
|
2021-11-08 13:58:40 -05:00
|
|
|
#[derive(Component, Debug, ConvertSaveload)]
|
2021-11-04 15:06:04 -04:00
|
|
|
pub struct WantsToUseItem {
|
|
|
|
pub item: Entity,
|
2021-12-01 15:25:48 -05:00
|
|
|
pub target: Option<Point>,
|
2021-11-03 15:59:23 -04:00
|
|
|
}
|
2021-11-04 09:40:58 -04:00
|
|
|
|
2021-11-08 13:58:40 -05:00
|
|
|
#[derive(Component, Debug, ConvertSaveload)]
|
2021-11-04 09:40:58 -04:00
|
|
|
pub struct WantsToDropItem {
|
|
|
|
pub item: Entity,
|
|
|
|
}
|
2021-11-04 15:06:04 -04:00
|
|
|
|
2021-11-15 13:55:31 -05:00
|
|
|
#[derive(Component, Debug, ConvertSaveload, Clone)]
|
|
|
|
pub struct WantsToRemoveItem {
|
|
|
|
pub item: Entity,
|
2021-11-05 14:32:14 -04:00
|
|
|
}
|
2021-11-15 09:19:22 -05:00
|
|
|
|
|
|
|
#[derive(Component, Serialize, Deserialize, Clone)]
|
|
|
|
pub struct Equippable {
|
|
|
|
pub slot: EquipmentSlot,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Component, ConvertSaveload, Clone)]
|
|
|
|
pub struct Equipped {
|
|
|
|
pub owner: Entity,
|
|
|
|
pub slot: EquipmentSlot,
|
|
|
|
}
|
2021-11-15 09:45:12 -05:00
|
|
|
|
|
|
|
#[derive(Component, ConvertSaveload, Clone)]
|
2022-01-04 10:08:06 -05:00
|
|
|
pub struct MeleeWeapon {
|
|
|
|
pub attribute: WeaponAttribute,
|
|
|
|
pub damage_n_dice: i32,
|
|
|
|
pub damage_die_type: i32,
|
|
|
|
pub damage_bonus: i32,
|
|
|
|
pub hit_bonus: i32,
|
2021-11-15 09:45:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Component, ConvertSaveload, Clone)]
|
2022-01-04 11:11:38 -05:00
|
|
|
pub struct Wearable {
|
|
|
|
pub armor_class: f32,
|
|
|
|
pub slot: EquipmentSlot,
|
2021-11-15 09:45:12 -05:00
|
|
|
}
|
2021-11-15 11:32:09 -05:00
|
|
|
|
2021-11-16 11:33:58 -05:00
|
|
|
#[derive(Component, Serialize, Deserialize, Clone)]
|
|
|
|
pub struct ParticleLifetime {
|
|
|
|
pub lifetime_ms: f32,
|
|
|
|
}
|
|
|
|
|
2021-11-17 16:23:01 -05:00
|
|
|
#[derive(Component, Serialize, Deserialize, Clone)]
|
|
|
|
pub struct HungerClock {
|
|
|
|
pub state: HungerState,
|
|
|
|
pub duration: i32,
|
|
|
|
}
|
|
|
|
|
2021-12-17 14:07:14 -05:00
|
|
|
#[derive(Component, Debug, Serialize, Deserialize, Clone)]
|
|
|
|
pub struct Door {
|
|
|
|
pub open: bool,
|
|
|
|
}
|
|
|
|
|
2022-01-03 10:49:12 -05:00
|
|
|
#[derive(Component, Debug, Serialize, Deserialize, Clone)]
|
|
|
|
pub struct Quips {
|
|
|
|
pub available: Vec<String>,
|
|
|
|
}
|
|
|
|
|
2022-01-03 15:21:12 -05:00
|
|
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
|
|
|
pub struct Attribute {
|
|
|
|
pub base: i32,
|
|
|
|
pub modifiers: i32,
|
|
|
|
pub bonus: i32,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Attribute {
|
|
|
|
pub fn new(base: i32) -> Self {
|
|
|
|
Attribute {
|
|
|
|
base,
|
|
|
|
modifiers: 0,
|
|
|
|
bonus: attr_bonus(base),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Component, Debug, Serialize, Deserialize, Clone)]
|
|
|
|
pub struct Attributes {
|
|
|
|
pub might: Attribute,
|
|
|
|
pub fitness: Attribute,
|
|
|
|
pub quickness: Attribute,
|
|
|
|
pub intelligence: Attribute,
|
|
|
|
}
|
|
|
|
|
2022-01-03 16:30:14 -05:00
|
|
|
#[derive(Component, Debug, Default, Serialize, Deserialize, Clone)]
|
2022-01-03 15:24:38 -05:00
|
|
|
pub struct Skills {
|
|
|
|
pub skills: HashMap<Skill, i32>,
|
|
|
|
}
|
|
|
|
|
2022-01-03 16:30:14 -05:00
|
|
|
impl Skills {
|
|
|
|
pub fn new(level: i32) -> Self {
|
|
|
|
let mut skills = Skills::default();
|
|
|
|
skills.skills.insert(Skill::Melee, level);
|
|
|
|
skills.skills.insert(Skill::Defense, level);
|
|
|
|
skills.skills.insert(Skill::Magic, level);
|
|
|
|
|
|
|
|
skills
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
|
|
|
pub struct Pool {
|
|
|
|
pub max: i32,
|
|
|
|
pub current: i32,
|
|
|
|
}
|
|
|
|
|
2022-01-13 10:14:13 -05:00
|
|
|
impl Pool {
|
|
|
|
pub fn new(default_value: i32) -> Pool {
|
|
|
|
Pool {
|
|
|
|
max: default_value,
|
|
|
|
current: default_value,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-03 16:30:14 -05:00
|
|
|
#[derive(Component, Debug, Serialize, Deserialize, Clone)]
|
|
|
|
pub struct Pools {
|
|
|
|
pub hit_points: Pool,
|
|
|
|
pub mana: Pool,
|
|
|
|
pub xp: i32,
|
|
|
|
pub level: i32,
|
2022-01-13 10:14:13 -05:00
|
|
|
pub total_weight: f32,
|
|
|
|
pub total_initiative_penalty: f32,
|
2022-01-13 10:42:02 -05:00
|
|
|
pub gold: f32,
|
2022-01-03 16:30:14 -05:00
|
|
|
}
|
|
|
|
|
2022-01-04 11:16:36 -05:00
|
|
|
#[derive(Serialize, Deserialize, Clone)]
|
|
|
|
pub struct NaturalAttack {
|
|
|
|
pub name: String,
|
|
|
|
pub damage_n_dice: i32,
|
|
|
|
pub damage_die_type: i32,
|
|
|
|
pub damage_bonus: i32,
|
|
|
|
pub hit_bonus: i32,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Component, Serialize, Deserialize, Clone)]
|
|
|
|
pub struct NaturalAttackDefense {
|
|
|
|
pub armor_class: Option<i32>,
|
|
|
|
pub attacks: Vec<NaturalAttack>,
|
|
|
|
}
|
|
|
|
|
2022-01-05 09:42:36 -05:00
|
|
|
#[derive(Component, Debug, Serialize, Deserialize, Clone)]
|
|
|
|
pub struct LootTable {
|
|
|
|
pub table: String,
|
|
|
|
}
|
|
|
|
|
2022-01-06 09:34:17 -05:00
|
|
|
#[derive(Component, Serialize, Deserialize, Clone)]
|
|
|
|
pub struct OtherLevelPosition {
|
|
|
|
pub x: i32,
|
|
|
|
pub y: i32,
|
|
|
|
pub depth: i32,
|
|
|
|
}
|
|
|
|
|
2022-01-10 10:21:19 -05:00
|
|
|
#[derive(Component, Serialize, Deserialize, Clone)]
|
|
|
|
pub struct LightSource {
|
|
|
|
pub color: RGB,
|
|
|
|
pub range: i32,
|
|
|
|
}
|
|
|
|
|
2022-01-11 09:28:45 -05:00
|
|
|
#[derive(Component, Debug, Serialize, Deserialize, Clone)]
|
|
|
|
pub struct Initiative {
|
|
|
|
pub current: i32,
|
|
|
|
}
|
|
|
|
|
2022-01-11 14:16:23 -05:00
|
|
|
#[derive(Component, Debug, Serialize, Deserialize, Clone)]
|
|
|
|
pub struct Faction {
|
|
|
|
pub name: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Faction {
|
|
|
|
pub fn from<S: ToString>(s: S) -> Self {
|
|
|
|
Faction {
|
|
|
|
name: s.to_string(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Component, Debug, Serialize, Deserialize, Clone)]
|
|
|
|
pub struct WantsToApproach {
|
|
|
|
pub idx: i32,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Component, Debug, Serialize, Deserialize, Clone)]
|
|
|
|
pub struct WantsToFlee {
|
|
|
|
pub indices: Vec<usize>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Component, Debug, Serialize, Deserialize, Clone)]
|
|
|
|
pub struct MoveMode {
|
|
|
|
pub mode: Movement,
|
|
|
|
}
|
|
|
|
|
2022-01-11 15:35:59 -05:00
|
|
|
#[derive(Component, Debug, ConvertSaveload, Clone)]
|
|
|
|
pub struct Chasing {
|
|
|
|
pub target: Entity,
|
|
|
|
}
|
|
|
|
|
2021-11-15 13:55:31 -05:00
|
|
|
// Serialization helper code. We need to implement ConvertSaveLoad for each type that contains an
|
|
|
|
// Entity.
|
|
|
|
|
|
|
|
pub struct SerializeMe;
|
|
|
|
|
|
|
|
// Special component that exists to help serialize the game data
|
|
|
|
#[derive(Component, Serialize, Deserialize, Clone)]
|
|
|
|
pub struct SerializationHelper {
|
2021-11-17 16:08:46 -05:00
|
|
|
pub map: crate::map::Map,
|
2021-11-15 11:32:09 -05:00
|
|
|
}
|
2022-01-06 10:00:42 -05:00
|
|
|
|
|
|
|
#[derive(Component, Serialize, Deserialize, Clone)]
|
|
|
|
pub struct DMSerializationHelper {
|
2022-01-11 15:35:59 -05:00
|
|
|
pub map: crate::map::MasterDungeonMap,
|
2022-01-06 10:00:42 -05:00
|
|
|
}
|