Complete Section 5.15
This commit is contained in:
parent
f9e73479d0
commit
d5c48247f3
@ -8,8 +8,8 @@ use crate::components::{
|
|||||||
use crate::game_log::GameLog;
|
use crate::game_log::GameLog;
|
||||||
use crate::gamesystem::{mana_at_level, player_hp_at_level};
|
use crate::gamesystem::{mana_at_level, player_hp_at_level};
|
||||||
use crate::particle_system::ParticleBuilder;
|
use crate::particle_system::ParticleBuilder;
|
||||||
use crate::raws::{get_item_drop, spawn_named_item, SpawnType, RAWS};
|
use crate::raws::{self, SpawnType, RAWS};
|
||||||
use crate::{Map, RunState};
|
use crate::{spatial, Map, RunState};
|
||||||
|
|
||||||
pub struct DamageSystem {}
|
pub struct DamageSystem {}
|
||||||
|
|
||||||
@ -44,15 +44,20 @@ impl<'a> System<'a> for DamageSystem {
|
|||||||
let mut xp_gain = 0;
|
let mut xp_gain = 0;
|
||||||
|
|
||||||
for (entity, mut stats, damage) in (&entities, &mut stats, &damage).join() {
|
for (entity, mut stats, damage) in (&entities, &mut stats, &damage).join() {
|
||||||
|
let pos = positions.get(entity);
|
||||||
for dmg in damage.amount.iter() {
|
for dmg in damage.amount.iter() {
|
||||||
stats.hit_points.current -= dmg.0;
|
stats.hit_points.current -= dmg.0;
|
||||||
if let Some(pos) = positions.get(entity) {
|
if let Some(pos) = pos {
|
||||||
let idx = map.xy_idx(pos.x, pos.y);
|
let idx = map.xy_idx(pos.x, pos.y);
|
||||||
map.bloodstains.insert(idx);
|
map.bloodstains.insert(idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
if stats.hit_points.current < 1 && dmg.1 {
|
if stats.hit_points.current < 1 && dmg.1 {
|
||||||
xp_gain += stats.level * 100;
|
xp_gain += stats.level * 100;
|
||||||
|
if let Some(pos) = pos {
|
||||||
|
let idx = map.xy_idx(pos.x, pos.y);
|
||||||
|
spatial::remove_entity(entity, idx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -161,7 +166,7 @@ pub fn delete_the_dead(ecs: &mut World) {
|
|||||||
|
|
||||||
if let Some(table) = loot_tables.get(*victim) {
|
if let Some(table) = loot_tables.get(*victim) {
|
||||||
let drop_finder =
|
let drop_finder =
|
||||||
get_item_drop(&crate::raws::RAWS.lock().unwrap(), &mut rng, &table.table);
|
raws::get_item_drop(&crate::raws::RAWS.lock().unwrap(), &mut rng, &table.table);
|
||||||
if let Some(tag) = drop_finder {
|
if let Some(tag) = drop_finder {
|
||||||
if let Some(pos) = pos {
|
if let Some(pos) = pos {
|
||||||
to_spawn.push((tag, *pos));
|
to_spawn.push((tag, *pos));
|
||||||
@ -181,7 +186,7 @@ pub fn delete_the_dead(ecs: &mut World) {
|
|||||||
|
|
||||||
{
|
{
|
||||||
for drop in to_spawn.iter() {
|
for drop in to_spawn.iter() {
|
||||||
spawn_named_item(
|
raws::spawn_named_item(
|
||||||
&RAWS.lock().unwrap(),
|
&RAWS.lock().unwrap(),
|
||||||
ecs,
|
ecs,
|
||||||
&drop.0,
|
&drop.0,
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use ::specs::prelude::*;
|
use ::specs::prelude::*;
|
||||||
|
|
||||||
use crate::{spatial, BlocksTile, Map, Position};
|
use crate::components::{BlocksTile, Pools, Position};
|
||||||
|
use crate::{spatial, Map};
|
||||||
|
|
||||||
pub struct MapIndexingSystem {}
|
pub struct MapIndexingSystem {}
|
||||||
|
|
||||||
@ -9,18 +10,28 @@ impl<'a> System<'a> for MapIndexingSystem {
|
|||||||
ReadExpect<'a, Map>,
|
ReadExpect<'a, Map>,
|
||||||
ReadStorage<'a, Position>,
|
ReadStorage<'a, Position>,
|
||||||
ReadStorage<'a, BlocksTile>,
|
ReadStorage<'a, BlocksTile>,
|
||||||
|
ReadStorage<'a, Pools>,
|
||||||
Entities<'a>,
|
Entities<'a>,
|
||||||
);
|
);
|
||||||
|
|
||||||
fn run(&mut self, data: Self::SystemData) {
|
fn run(&mut self, data: Self::SystemData) {
|
||||||
let (map, position, blockers, entities) = data;
|
let (map, position, blockers, pools, entities) = data;
|
||||||
|
|
||||||
spatial::clear();
|
spatial::clear();
|
||||||
spatial::populate_blocked_from_map(&*map);
|
spatial::populate_blocked_from_map(&*map);
|
||||||
|
|
||||||
for (entity, position) in (&entities, &position).join() {
|
for (entity, position) in (&entities, &position).join() {
|
||||||
|
let mut alive = true;
|
||||||
|
if let Some(pools) = pools.get(entity) {
|
||||||
|
if pools.hit_points.current < 1 {
|
||||||
|
alive = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if alive {
|
||||||
let idx = map.xy_idx(position.x, position.y);
|
let idx = map.xy_idx(position.x, position.y);
|
||||||
spatial::index_entity(entity, idx, blockers.get(entity).is_some());
|
spatial::index_entity(entity, idx, blockers.get(entity).is_some());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -124,8 +124,7 @@ pub fn try_move_player(delta_x: i32, delta_y: i32, ecs: &mut World) -> RunState
|
|||||||
}
|
}
|
||||||
|
|
||||||
for m in swap_entities.iter() {
|
for m in swap_entities.iter() {
|
||||||
let their_pos = positions.get_mut(m.0);
|
if let Some(their_pos) = positions.get_mut(m.0) {
|
||||||
if let Some(their_pos) = their_pos {
|
|
||||||
let old_idx = map.xy_idx(their_pos.x, their_pos.y);
|
let old_idx = map.xy_idx(their_pos.x, their_pos.y);
|
||||||
their_pos.x = m.1;
|
their_pos.x = m.1;
|
||||||
their_pos.y = m.2;
|
their_pos.y = m.2;
|
||||||
|
@ -119,3 +119,15 @@ pub fn move_entity(entity: Entity, moving_from: usize, moving_to: usize) {
|
|||||||
lock.blocked[moving_from].1 = from_blocked;
|
lock.blocked[moving_from].1 = from_blocked;
|
||||||
lock.blocked[moving_to].1 = to_blocked;
|
lock.blocked[moving_to].1 = to_blocked;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn remove_entity(entity: Entity, idx: usize) {
|
||||||
|
let mut lock = SPATIAL_MAP.lock().unwrap();
|
||||||
|
lock.tile_content[idx].retain(|(e, _)| *e != entity);
|
||||||
|
let mut from_blocked = false;
|
||||||
|
lock.tile_content[idx].iter().for_each(|(_, blocks)| {
|
||||||
|
if *blocks {
|
||||||
|
from_blocked = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
lock.blocked[idx].1 = from_blocked;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user