Added chapter 2.9
This commit is contained in:
@@ -1,10 +1,7 @@
|
||||
use rltk::{FontCharType, RandomNumberGenerator, RGB};
|
||||
use specs::prelude::*;
|
||||
|
||||
use crate::{
|
||||
BlocksTile, CombatStats, Item, MAP_WIDTH, MAX_ITEMS, MAX_MONSTER, Monster, Name, Player, Position,
|
||||
Potion, Renderable, Viewshed,
|
||||
};
|
||||
use crate::{AreaOfEffect, BlocksTile, CombatStats, Confusion, Consumable, InflictsDamage, Item, MAP_WIDTH, MAX_ITEMS, MAX_MONSTER, Monster, Name, Player, Position, Potion, ProvidesHealing, Ranged, Renderable, Viewshed};
|
||||
use crate::rect::Rect;
|
||||
|
||||
pub fn player(ecs: &mut World, player_x: i32, player_y: i32) -> Entity {
|
||||
@@ -130,7 +127,7 @@ pub fn spawn_room(ecs: &mut World, room: &Rect) {
|
||||
for idx in item_spawn_points.iter() {
|
||||
let x = *idx % MAP_WIDTH;
|
||||
let y = *idx / MAP_WIDTH;
|
||||
health_potion(ecs, x as i32, y as i32);
|
||||
random_item(ecs, x as i32, y as i32);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,6 +144,80 @@ pub fn health_potion(ecs: &mut World, x: i32, y: i32) {
|
||||
name: "Health Potion".to_string(),
|
||||
})
|
||||
.with(Item {})
|
||||
.with(Potion { heal_amount: 8 })
|
||||
.with(Consumable {})
|
||||
.with(ProvidesHealing { heal_amount: 8 })
|
||||
.build();
|
||||
}
|
||||
|
||||
pub fn magic_missile_scroll(ecs: &mut World, x: i32, y: i32) {
|
||||
ecs.create_entity()
|
||||
.with(Position { x, y })
|
||||
.with(Renderable {
|
||||
glyph: rltk::to_cp437(')'),
|
||||
fg: RGB::named(rltk::CYAN),
|
||||
bg: RGB::named(rltk::BLACK),
|
||||
render_order: 2,
|
||||
})
|
||||
.with(Name {
|
||||
name: "Magic Missile Scroll".to_string(),
|
||||
})
|
||||
.with(Item {})
|
||||
.with(Consumable {})
|
||||
.with(Ranged { range: 6 })
|
||||
.with(InflictsDamage { damage: 8 })
|
||||
.build();
|
||||
}
|
||||
|
||||
pub fn fireball_scroll(ecs: &mut World, x: i32, y: i32) {
|
||||
ecs.create_entity()
|
||||
.with(Position { x, y })
|
||||
.with(Renderable {
|
||||
glyph: rltk::to_cp437(')'),
|
||||
fg: RGB::named(rltk::CYAN),
|
||||
bg: RGB::named(rltk::BLACK),
|
||||
render_order: 2,
|
||||
})
|
||||
.with(Name {
|
||||
name: "Fireball Scroll".to_string(),
|
||||
})
|
||||
.with(Item {})
|
||||
.with(Consumable {})
|
||||
.with(Ranged { range: 6 })
|
||||
.with(InflictsDamage { damage: 20 })
|
||||
.with(AreaOfEffect { radius: 3 })
|
||||
.build();
|
||||
}
|
||||
|
||||
pub fn confusion_scroll(ecs: &mut World, x: i32, y: i32) {
|
||||
ecs.create_entity()
|
||||
.with(Position { x, y })
|
||||
.with(Renderable {
|
||||
glyph: rltk::to_cp437(')'),
|
||||
fg: RGB::named(rltk::CYAN),
|
||||
bg: RGB::named(rltk::BLACK),
|
||||
render_order: 2,
|
||||
})
|
||||
.with(Name {
|
||||
name: "Confusion Scroll".to_string(),
|
||||
})
|
||||
.with(Item {})
|
||||
.with(Consumable {})
|
||||
.with(Ranged { range: 6 })
|
||||
.with(Confusion { turns: 4 })
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
pub fn random_item(ecs: &mut World, x: i32, y: i32) {
|
||||
let roll: i32;
|
||||
{
|
||||
let mut rng = ecs.write_resource::<RandomNumberGenerator>();
|
||||
roll = rng.roll_dice(1, 4);
|
||||
}
|
||||
match roll {
|
||||
1 => health_potion(ecs, x, y),
|
||||
2 => fireball_scroll(ecs, x, y),
|
||||
3 => confusion_scroll(ecs, x, y),
|
||||
_ => magic_missile_scroll(ecs, x, y),
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user