Browse Source

Finalize damage updates

master
Graham Northup 6 months ago
parent
commit
99b3a6a9a5
  1. 11
      src/ent.rs

11
src/ent.rs

@ -1,4 +1,4 @@
use rogue_engine::world::entity::{Entity, Hp, Observation, Action, ECLS_PROTAG, DamageDesc, DamageKind, ai::violence_toward};
use rogue_engine::world::{entity::{Entity, Hp, Observation, Action, ECLS_PROTAG, DamageDesc, DamageKind, ai::violence_toward}, inventory::Inventory};
use rogue_util::coord::V2i;
use std::rc::Rc;
@ -9,16 +9,20 @@ macro_rules! make_entity {
pos: V2i,
hp: Hp,
time: usize,
inv: Inventory,
$( $field ),*
}
impl Entity for $name {
fn as_entity(&self) -> &dyn Entity { self as &dyn Entity }
fn pos(&self) -> V2i { self.pos }
fn set_pos(&mut self, pos: V2i) { self.pos = pos; }
fn next_time(&self) -> usize { self.time }
fn set_next_time(&mut self, time: usize) { self.time = time; }
fn hp(&self) -> Hp { self.hp }
fn set_hp(&mut self, hp: Hp) { self.hp = hp; }
fn inv(&self) -> &Inventory { &self.inv }
fn inv_mut(&mut self) -> &mut Inventory { &mut self.inv }
$( $methods )*
}
@ -27,9 +31,7 @@ macro_rules! make_entity {
make_entity!(Prowler, {}, {
fn act<'w>(&mut self, obs: &Observation<'w>) -> Action {
violence_toward(self.pos, obs, |ent| ent.borrow().class() & ECLS_PROTAG != 0, |ent| {
Rc::new(vec![DamageDesc{ kind: DamageKind::Phys, base: 6, add: 6 }])
})
violence_toward(self.pos, obs, |ent| ent.borrow().class() & ECLS_PROTAG != 0, |ent| ent.borrow().best_damage())
}
});
@ -39,6 +41,7 @@ impl Prowler {
pos,
hp: 50,
time: 0,
inv: Default::default(),
}
}
}
Loading…
Cancel
Save