components.rs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. use specs::prelude::*;
  2. use specs_derive::*;
  3. use rltk::{RGB};
  4. // COMPONENTS
  5. #[derive(Component, Debug)]
  6. pub struct Consumable {}
  7. #[derive(Component, Debug, Clone)]
  8. pub struct WantsToDropItem {
  9. pub item : Entity
  10. }
  11. #[derive(Component, Debug)]
  12. pub struct WantsToDrinkPotion {
  13. pub potion : Entity
  14. }
  15. #[derive(Component, Debug, Clone)]
  16. pub struct WantsToPickupItem {
  17. pub collected_by : Entity,
  18. pub item : Entity
  19. }
  20. #[derive(Component, Debug, Clone)]
  21. pub struct InBackpack {
  22. pub owner : Entity
  23. }
  24. #[derive(Component, Debug)]
  25. pub struct Item {}
  26. #[derive(Component, Debug)]
  27. pub struct Potion {
  28. pub heal_amount : i32
  29. }
  30. #[derive(Component, Debug)]
  31. pub struct SufferDamage {
  32. pub amount : Vec<i32>
  33. }
  34. impl SufferDamage {
  35. pub fn new_damage(store: &mut WriteStorage<SufferDamage>, victim: Entity, amount: i32) {
  36. if let Some(suffering) = store.get_mut(victim) {
  37. suffering.amount.push(amount);
  38. } else {
  39. let dmg = SufferDamage { amount : vec![amount] };
  40. store.insert(victim, dmg).expect("Unable to insert damage");
  41. }
  42. }
  43. }
  44. #[derive(Component, Debug, Clone)]
  45. pub struct WantsToMelee {
  46. pub target : Entity
  47. }
  48. #[derive(Component, Debug)]
  49. pub struct CombatStats {
  50. pub max_hp : i32,
  51. pub hp : i32,
  52. pub defense : i32,
  53. pub power : i32
  54. }
  55. #[derive(Component, Debug)]
  56. pub struct BlocksTile {}
  57. #[derive(Component, Debug)]
  58. pub struct Name {
  59. pub name : String
  60. }
  61. #[derive(Component, Debug)]
  62. pub struct Monster {}
  63. #[derive(Component)]
  64. pub struct Viewshed {
  65. pub visible_tiles : Vec<rltk::Point>,
  66. pub range : i32,
  67. pub dirty: bool
  68. }
  69. #[derive(Component)]
  70. pub struct Position {
  71. pub x: i32,
  72. pub y: i32,
  73. }
  74. #[derive(Component)]
  75. pub struct Renderable {
  76. pub glyph: rltk::FontCharType,
  77. pub fg: RGB,
  78. pub bg: RGB,
  79. pub render_order : i32
  80. }
  81. #[derive(Component, Debug)]
  82. pub struct Player {}