combat system overhaul - d20/hack-like
This commit is contained in:
parent
32044dbb6a
commit
c169a1eae6
20 changed files with 762 additions and 292 deletions
|
|
@ -1,6 +1,7 @@
|
|||
use super::{
|
||||
random_table::RandomTable, raws, Attribute, Attributes, CombatStats, HungerClock, HungerState, Map, Name, Player,
|
||||
Position, Rect, Renderable, SerializeMe, TileType, Viewshed,
|
||||
gamesystem, gamesystem::attr_bonus, random_table::RandomTable, raws, Attribute, Attributes, HungerClock,
|
||||
HungerState, Map, Name, Player, Pool, Pools, Position, Rect, Renderable, SerializeMe, Skill, Skills, TileType,
|
||||
Viewshed,
|
||||
};
|
||||
use rltk::{RandomNumberGenerator, RGB};
|
||||
use specs::prelude::*;
|
||||
|
|
@ -9,8 +10,23 @@ use std::collections::HashMap;
|
|||
|
||||
/// Spawns the player and returns his/her entity object.
|
||||
pub fn player(ecs: &mut World, player_x: i32, player_y: i32) -> Entity {
|
||||
let mut skills = Skills { skills: HashMap::new() };
|
||||
skills.skills.insert(Skill::Melee, 0);
|
||||
skills.skills.insert(Skill::Defence, 0);
|
||||
skills.skills.insert(Skill::Magic, 0);
|
||||
|
||||
let mut rng = ecs.write_resource::<rltk::RandomNumberGenerator>();
|
||||
let str = gamesystem::roll_4d6(&mut rng);
|
||||
let dex = gamesystem::roll_4d6(&mut rng);
|
||||
let con = gamesystem::roll_4d6(&mut rng);
|
||||
let int = gamesystem::roll_4d6(&mut rng);
|
||||
let wis = gamesystem::roll_4d6(&mut rng);
|
||||
let cha = gamesystem::roll_4d6(&mut rng);
|
||||
std::mem::drop(rng);
|
||||
|
||||
// d8 hit die - but always maxxed at level 1, so player doesn't have to roll.
|
||||
ecs.create_entity()
|
||||
let player = ecs
|
||||
.create_entity()
|
||||
.with(Position { x: player_x, y: player_y })
|
||||
.with(Renderable {
|
||||
glyph: rltk::to_cp437('@'),
|
||||
|
|
@ -21,22 +37,39 @@ pub fn player(ecs: &mut World, player_x: i32, player_y: i32) -> Entity {
|
|||
.with(Player {})
|
||||
.with(Viewshed { visible_tiles: Vec::new(), range: 12, dirty: true })
|
||||
.with(Name { name: "you".to_string(), plural: "you".to_string() })
|
||||
.with(CombatStats { max_hp: 12, hp: 12, defence: 0, power: 4 })
|
||||
.with(HungerClock { state: HungerState::Satiated, duration: 50 })
|
||||
.with(Attributes {
|
||||
strength: Attribute { base: 10, modifiers: 0, bonus: 0 },
|
||||
dexterity: Attribute { base: 10, modifiers: 0, bonus: 0 },
|
||||
constitution: Attribute { base: 10, modifiers: 0, bonus: 0 },
|
||||
intelligence: Attribute { base: 10, modifiers: 0, bonus: 0 },
|
||||
wisdom: Attribute { base: 10, modifiers: 0, bonus: 0 },
|
||||
charisma: Attribute { base: 10, modifiers: 0, bonus: 0 },
|
||||
strength: Attribute { base: str, modifiers: 0, bonus: attr_bonus(str) },
|
||||
dexterity: Attribute { base: dex, modifiers: 0, bonus: attr_bonus(dex) },
|
||||
constitution: Attribute { base: con, modifiers: 0, bonus: attr_bonus(con) },
|
||||
intelligence: Attribute { base: int, modifiers: 0, bonus: attr_bonus(int) },
|
||||
wisdom: Attribute { base: wis, modifiers: 0, bonus: attr_bonus(wis) },
|
||||
charisma: Attribute { base: cha, modifiers: 0, bonus: attr_bonus(cha) },
|
||||
})
|
||||
.with(Pools {
|
||||
hit_points: Pool { current: 10 + attr_bonus(con), max: 10 + attr_bonus(con) },
|
||||
mana: Pool { current: 2 + attr_bonus(int), max: 2 + attr_bonus(int) },
|
||||
xp: 0,
|
||||
level: 1,
|
||||
bac: 10,
|
||||
})
|
||||
.with(skills)
|
||||
.marked::<SimpleMarker<SerializeMe>>()
|
||||
.build()
|
||||
.build();
|
||||
|
||||
raws::spawn_named_entity(
|
||||
&raws::RAWS.lock().unwrap(),
|
||||
ecs,
|
||||
"equip_dagger",
|
||||
raws::SpawnType::Equipped { by: player },
|
||||
);
|
||||
raws::spawn_named_entity(&raws::RAWS.lock().unwrap(), ecs, "food_apple", raws::SpawnType::Carried { by: player });
|
||||
|
||||
return player;
|
||||
}
|
||||
|
||||
// Consts
|
||||
const MAX_ENTITIES: i32 = 3;
|
||||
const MAX_ENTITIES: i32 = 2;
|
||||
|
||||
/// Fills a room with stuff!
|
||||
pub fn spawn_room(map: &Map, rng: &mut RandomNumberGenerator, room: &Rect, spawn_list: &mut Vec<(usize, String)>) {
|
||||
|
|
@ -61,6 +94,18 @@ pub fn spawn_region(map: &Map, rng: &mut RandomNumberGenerator, area: &[usize],
|
|||
let mut areas: Vec<usize> = Vec::from(area);
|
||||
let difficulty = map.difficulty;
|
||||
|
||||
if areas.len() == 0 {
|
||||
rltk::console::log("DEBUGINFO: No areas capable of spawning mobs!");
|
||||
return;
|
||||
}
|
||||
|
||||
if rng.roll_dice(1, 3) == 1 {
|
||||
let array_idx = if areas.len() == 1 { 0usize } else { (rng.roll_dice(1, areas.len() as i32) - 1) as usize };
|
||||
let map_idx = areas[array_idx];
|
||||
spawn_points.insert(map_idx, mob_table(difficulty).roll(rng));
|
||||
areas.remove(array_idx);
|
||||
}
|
||||
|
||||
let num_spawns = i32::min(areas.len() as i32, rng.roll_dice(1, MAX_ENTITIES + 2) - 2);
|
||||
if num_spawns <= 0 {
|
||||
return;
|
||||
|
|
@ -70,7 +115,6 @@ pub fn spawn_region(map: &Map, rng: &mut RandomNumberGenerator, area: &[usize],
|
|||
let category = category_table().roll(rng);
|
||||
let spawn_table;
|
||||
match category.as_ref() {
|
||||
"mob" => spawn_table = mob_table(difficulty),
|
||||
"item" => {
|
||||
let item_category = item_category_table().roll(rng);
|
||||
match item_category.as_ref() {
|
||||
|
|
@ -104,13 +148,8 @@ pub fn spawn_entity(ecs: &mut World, spawn: &(&usize, &String)) {
|
|||
let y = (*spawn.0 / width) as i32;
|
||||
std::mem::drop(map);
|
||||
|
||||
let spawn_result = raws::spawn_named_entity(
|
||||
&raws::RAWS.lock().unwrap(),
|
||||
ecs.create_entity(),
|
||||
&spawn.1,
|
||||
raws::SpawnType::AtPosition { x, y },
|
||||
&mut rltk::RandomNumberGenerator::new(),
|
||||
);
|
||||
let spawn_result =
|
||||
raws::spawn_named_entity(&raws::RAWS.lock().unwrap(), ecs, &spawn.1, raws::SpawnType::AtPosition { x, y });
|
||||
if spawn_result.is_some() {
|
||||
return;
|
||||
}
|
||||
|
|
@ -118,9 +157,9 @@ pub fn spawn_entity(ecs: &mut World, spawn: &(&usize, &String)) {
|
|||
rltk::console::log(format!("WARNING: We don't know how to spawn [{}]!", spawn.1));
|
||||
}
|
||||
|
||||
// 12 mobs : 6 items : 2 food : 1 trap
|
||||
// 3 items : 1 food : 1 trap
|
||||
fn category_table() -> RandomTable {
|
||||
return RandomTable::new().add("mob", 12).add("item", 6).add("food", 2).add("trap", 1);
|
||||
return RandomTable::new().add("item", 3).add("food", 1).add("trap", 1);
|
||||
}
|
||||
|
||||
// 3 scrolls : 3 potions : 1 equipment : 1 wand?
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue