1 use specs::prelude::*;
2 use specs_derive::*;
3 use rltk::{RGB};
4 use serde::{Serialize, Deserialize};
5 use specs::saveload::{Marker, ConvertSaveload};
6 use specs::error::NoError;
7
8 // COMPONENTS
9 #[derive(Component, Serialize, Deserialize, Clone)]
10 pub struct ParticleLifetime {
11 pub lifetime_ms : f32
12 }
13
14 #[derive(Component, Debug, ConvertSaveload, Clone)]
15 pub struct WantsToRemoveItem {
16 pub item : Entity
17 }
18
19 #[derive(Component, ConvertSaveload, Clone)]
20 pub struct MeleePowerBonus {
21 pub power : i32
22 }
23
24 #[derive(Component, ConvertSaveload, Clone)]
25 pub struct DefenseBonus {
26 pub defense : i32
27 }
28
29 #[derive(Component, ConvertSaveload, Clone)]
30 pub struct Equipped {
31 pub owner : Entity,
32 pub slot : EquipmentSlot
33 }
34
35 #[derive(PartialEq, Copy, Clone, Serialize, Deserialize)]
36 pub enum EquipmentSlot { Melee, Shield }
37
38 #[derive(Component, Serialize, Deserialize, Clone)]
39 pub struct Equippable {
40 pub slot : EquipmentSlot
41 }
42
43 // Special component that exists to help serialize the game data
44 #[derive(Component, Serialize, Deserialize, Clone)]
45 pub struct SerializationHelper {
46 pub map : super::map::Map
47 }
48
49 pub struct SerializeMe;
50
51 #[derive(Component, Debug, ConvertSaveload, Clone)]
52 pub struct AreaOfEffect {
53 pub radius : i32
54 }
55
56 #[derive(Component, Debug, ConvertSaveload, Clone)]
57 pub struct Ranged {
58 pub range : i32
59 }
60
61 #[derive(Component, Debug, ConvertSaveload, Clone)]
62 pub struct InflictsDamage {
63 pub damage : i32
64 }
65
66 #[derive(Component, Debug, Serialize, Deserialize, Clone)]
67 pub struct Consumable {}
68
69 #[derive(Component, Debug, ConvertSaveload)]
70 pub struct WantsToDropItem {
71 pub item : Entity
72 }
73
74 #[derive(Component, Debug, ConvertSaveload)]
75 pub struct WantsToUseItem {
76 pub item : Entity,
77 pub target: Option<rltk::Point>
78 }
79
80 #[derive(Component, Debug, ConvertSaveload)]
81 pub struct WantsToPickupItem {
82 pub collected_by : Entity,
83 pub item : Entity
84 }
85
86 #[derive(Component, Debug, ConvertSaveload)]
87 pub struct InBackpack {
88 pub owner : Entity
89 }
90
91 #[derive(Component, Debug, Serialize, Deserialize, Clone)]
92 pub struct Item {}
93
94 #[derive(Component, Debug, ConvertSaveload, Clone)]
95 pub struct ProvidesHealing {
96 pub heal_amount : i32
97 }
98
99 #[derive(Component, Debug, ConvertSaveload, Clone)]
100 pub struct SufferDamage {
101 pub amount : Vec<i32>
102 }
103 impl SufferDamage {
104 pub fn new_damage(store: &mut WriteStorage<SufferDamage>, victim: Entity, amount: i32) {
105 if let Some(suffering) = store.get_mut(victim) {
106 suffering.amount.push(amount);
107 } else {
108 let dmg = SufferDamage { amount : vec![amount] };
109 store.insert(victim, dmg).expect("Unable to insert damage");
110 }
111 }
112 }
113
114 #[derive(Component, Debug, ConvertSaveload, Clone)]
115 pub struct WantsToMelee {
116 pub target : Entity
117 }
118
119 #[derive(Component, Debug, ConvertSaveload, Clone)]
120 pub struct CombatStats {
121 pub max_hp : i32,
122 pub hp : i32,
123 pub defense : i32,
124 pub power : i32
125 }
126
127 #[derive(Component, Debug, Serialize, Deserialize, Clone)]
128 pub struct BlocksTile {}
129
130 #[derive(Component, Debug, ConvertSaveload, Clone)]
131 pub struct Name {
132 pub name : String
133 }
134
135 #[derive(Component, Debug, Serialize, Deserialize, Clone)]
136 pub struct Monster {}
137
138 #[derive(Component, ConvertSaveload, Clone)]
139 pub struct Viewshed {
140 pub visible_tiles : Vec<rltk::Point>,
141 pub range : i32,
142 pub dirty: bool
143 }
144
145 #[derive(Component, ConvertSaveload, Clone)]
146 pub struct Position {
147 pub x: i32,
148 pub y: i32,
149 }
150
151 #[derive(Component, ConvertSaveload, Clone)]
152 pub struct Renderable {
153 pub glyph: rltk::FontCharType,
154 pub fg: RGB,
155 pub bg: RGB,
156 pub render_order : i32
157 }
158
159 #[derive(Component, Serialize, Deserialize, Clone)]
160 pub struct Player {}