/
prototype.rs
141 lines (122 loc) · 4.07 KB
/
prototype.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
use std::default::Default;
use util::color::*;
use ecs::{Component, ComponentAccess};
use entity::{Entity};
use components::{Spawn, Category, IsPrototype};
use components::{Desc, MapMemory, Health};
use components::{Brain, BrainState, Alignment};
use components::{Item};
use item::{ItemType};
use stats::{Stats};
use stats::Intrinsic::*;
use ability::Ability;
use Biome::*;
use world;
#[derive(Copy)]
pub struct Prototype {
pub target: Entity
}
impl Prototype {
pub fn new(parent: Option<Entity>) -> Prototype {
Prototype {
target: world::with_mut(|w| {
let e = w.ecs.new_entity(parent);
w.prototypes_mut().insert(e, IsPrototype);
e
}),
}
}
}
impl<C: Component> Fn<(C,)> for Prototype {
type Output = Prototype;
extern "rust-call" fn call(&self, (comp,): (C,)) -> Prototype {
comp.add_to(self.target);
*self
}
}
/// Only call at world init!
pub fn init() {
let base_mob = Prototype::new(None)
(Brain { state: BrainState::Asleep, alignment: Alignment::Evil })
({let h: Health = Default::default(); h})
.target;
// Init the prototypes
// Player
Prototype::new(Some(base_mob))
(Brain { state: BrainState::PlayerControl, alignment: Alignment::Good })
(Desc::new("player", 51, AZURE))
(Stats::new(10, &[Hands]).mana(5))
(MapMemory::new())
;
// Enemies
Prototype::new(Some(base_mob))
(Desc::new("dreg", 72, OLIVE))
(Stats::new(1, &[Hands]))
(Spawn::new(Category::Mob))
;
Prototype::new(Some(base_mob))
(Desc::new("snake", 71, GREEN))
(Stats::new(1, &[]))
(Spawn::new(Category::Mob).biome(Overland))
;
Prototype::new(Some(base_mob))
(Desc::new("ooze", 77, LIGHTSEAGREEN))
(Stats::new(3, &[]))
(Spawn::new(Category::Mob).biome(Dungeon).depth(3))
;
Prototype::new(Some(base_mob))
(Desc::new("ogre", 73, DARKSLATEGRAY))
(Stats::new(6, &[Hands]))
(Spawn::new(Category::Mob).depth(5))
;
Prototype::new(Some(base_mob))
(Desc::new("wraith", 74, HOTPINK))
(Stats::new(8, &[Hands]))
(Spawn::new(Category::Mob).biome(Dungeon).depth(6))
;
Prototype::new(Some(base_mob))
(Desc::new("octopus", 63, DARKTURQUOISE))
(Stats::new(10, &[]))
(Spawn::new(Category::Mob).depth(7))
;
Prototype::new(Some(base_mob))
(Desc::new("efreet", 78, ORANGE))
(Stats::new(12, &[]))
(Spawn::new(Category::Mob).depth(8))
;
Prototype::new(Some(base_mob))
(Desc::new("serpent", 94, CORAL))
(Stats::new(15, &[]))
(Spawn::new(Category::Mob).biome(Dungeon).depth(9))
;
// Items
Prototype::new(None)
(Desc::new("heart", 89, RED))
(Spawn::new(Category::Consumable).commonness(50))
(Item { item_type: ItemType::Instant, ability: Ability::HealInstant(2) })
;
Prototype::new(None)
(Desc::new("sword", 84, GAINSBORO))
(Spawn::new(Category::Equipment).commonness(100))
(Stats::new(0, &[]).attack(5).mana(-3))
(Item { item_type: ItemType::MeleeWeapon, ability: Ability::Multi(vec![]) })
;
Prototype::new(None)
(Desc::new("throwing knives", 90, GAINSBORO))
(Spawn::new(Category::Equipment).commonness(500))
(Stats::new(0, &[]).ranged_range(5).ranged_power(5))
(Item { item_type: ItemType::RangedWeapon, ability: Ability::Multi(vec![]) })
;
Prototype::new(None)
(Desc::new("helmet", 85, GAINSBORO))
(Spawn::new(Category::Equipment).commonness(100))
(Stats::new(0, &[]).protection(2).mana(-1))
(Item { item_type: ItemType::Helmet, ability: Ability::Multi(vec![]) })
;
Prototype::new(None)
(Desc::new("armor", 91, GAINSBORO))
(Spawn::new(Category::Equipment).commonness(100))
(Stats::new(0, &[]).protection(5).mana(-3))
(Item { item_type: ItemType::Armor, ability: Ability::Multi(vec![]) })
;
}