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::gamesystem::{mana_at_level, player_hp_at_level};
|
||||
use crate::particle_system::ParticleBuilder;
|
||||
use crate::raws::{get_item_drop, spawn_named_item, SpawnType, RAWS};
|
||||
use crate::{Map, RunState};
|
||||
use crate::raws::{self, SpawnType, RAWS};
|
||||
use crate::{spatial, Map, RunState};
|
||||
|
||||
pub struct DamageSystem {}
|
||||
|
||||
@ -44,15 +44,20 @@ impl<'a> System<'a> for DamageSystem {
|
||||
let mut xp_gain = 0;
|
||||
|
||||
for (entity, mut stats, damage) in (&entities, &mut stats, &damage).join() {
|
||||
let pos = positions.get(entity);
|
||||
for dmg in damage.amount.iter() {
|
||||
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);
|
||||
map.bloodstains.insert(idx);
|
||||
}
|
||||
|
||||
if stats.hit_points.current < 1 && dmg.1 {
|
||||
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) {
|
||||
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(pos) = pos {
|
||||
to_spawn.push((tag, *pos));
|
||||
@ -181,7 +186,7 @@ pub fn delete_the_dead(ecs: &mut World) {
|
||||
|
||||
{
|
||||
for drop in to_spawn.iter() {
|
||||
spawn_named_item(
|
||||
raws::spawn_named_item(
|
||||
&RAWS.lock().unwrap(),
|
||||
ecs,
|
||||
&drop.0,
|
||||
|
@ -1,6 +1,7 @@
|
||||
use ::specs::prelude::*;
|
||||
|
||||
use crate::{spatial, BlocksTile, Map, Position};
|
||||
use crate::components::{BlocksTile, Pools, Position};
|
||||
use crate::{spatial, Map};
|
||||
|
||||
pub struct MapIndexingSystem {}
|
||||
|
||||
@ -9,18 +10,28 @@ impl<'a> System<'a> for MapIndexingSystem {
|
||||
ReadExpect<'a, Map>,
|
||||
ReadStorage<'a, Position>,
|
||||
ReadStorage<'a, BlocksTile>,
|
||||
ReadStorage<'a, Pools>,
|
||||
Entities<'a>,
|
||||
);
|
||||
|
||||
fn run(&mut self, data: Self::SystemData) {
|
||||
let (map, position, blockers, entities) = data;
|
||||
let (map, position, blockers, pools, entities) = data;
|
||||
|
||||
spatial::clear();
|
||||
spatial::populate_blocked_from_map(&*map);
|
||||
|
||||
for (entity, position) in (&entities, &position).join() {
|
||||
let idx = map.xy_idx(position.x, position.y);
|
||||
spatial::index_entity(entity, idx, blockers.get(entity).is_some());
|
||||
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);
|
||||
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() {
|
||||
let their_pos = positions.get_mut(m.0);
|
||||
if let Some(their_pos) = their_pos {
|
||||
if let Some(their_pos) = positions.get_mut(m.0) {
|
||||
let old_idx = map.xy_idx(their_pos.x, their_pos.y);
|
||||
their_pos.x = m.1;
|
||||
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_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