Browse Source

Fix the damage calculation

master
Graham Northup 6 months ago
parent
commit
3fefa00ed7
  1. 5
      src/world/entity/mod.rs
  2. 1
      src/world/entity/player.rs

5
src/world/entity/mod.rs

@ -191,6 +191,7 @@ pub fn expected_damage(atks: Rc<Vec<DamageDesc>>) -> Hp {
}
pub trait Entity: Debug {
fn as_entity(&self) -> &Entity;
fn pos(&self) -> V2i;
fn set_pos(&mut self, v: V2i);
fn next_time(&self) -> usize;
@ -211,12 +212,12 @@ pub trait Entity: Debug {
add: DEFAULT_DAMAGE,
}])
}
fn best_damage(&self) -> Rc<Vec<DamageDesc>> where Self: Sized {
fn best_damage(&self) -> Rc<Vec<DamageDesc>> {
let mut bestatk = self.base_damage();
let mut bestdmg = expected_damage(Rc::clone(&bestatk));
for slot in Slot::DAMAGING.iter().cloned() {
if let Some(item) = self.inv().in_slot(slot) {
if let Some(atk) = item.borrow().damage(self as &dyn Entity) {
if let Some(atk) = item.borrow().damage(self.as_entity()) {
let dmg = expected_damage(Rc::clone(&atk));
if dmg > bestdmg {
bestdmg = dmg;

1
src/world/entity/player.rs

@ -59,6 +59,7 @@ impl<R> Entity for Player<R>
where
R: Iterator<Item=io::Result<Key>>
{
fn as_entity(&self) -> &dyn Entity { self as &dyn Entity }
fn pos(&self) -> V2i { self.pos }
fn set_pos(&mut self, p: V2i) { self.pos = p; }
fn next_time(&self) -> usize { self.time }

Loading…
Cancel
Save