Unlocked combat finally but the robots won't chase you.
This commit is contained in:
parent
2b69f388e5
commit
e9365e0d87
6 changed files with 34 additions and 79 deletions
|
|
@ -1,29 +1,35 @@
|
|||
#include "game/components.hpp"
|
||||
#include "algos/rand.hpp"
|
||||
#include <algorithm>
|
||||
|
||||
namespace components {
|
||||
int Combat::attack(Combat &target) {
|
||||
int attack = Random::uniform<int>(0,1);
|
||||
int attack = 1;
|
||||
int my_dmg = 0;
|
||||
|
||||
if(attack) {
|
||||
my_dmg = Random::uniform<int>(1, damage);
|
||||
target.take_damage(my_dmg);
|
||||
}
|
||||
my_dmg = Random::uniform<int>(1, damage);
|
||||
target.take_damage(my_dmg);
|
||||
|
||||
return my_dmg;
|
||||
}
|
||||
|
||||
void Combat::take_damage(int my_dmg) {
|
||||
for(auto& [key, hp] : body_parts) {
|
||||
if(Random::uniform(0, 1) == 0) {
|
||||
body_parts[key] = hp - my_dmg;
|
||||
int count = Random::uniform(1, int(body_parts.size() - 1));
|
||||
|
||||
while(count > 0) {
|
||||
fmt::println("COUNT: {}", count);
|
||||
for(auto& [key, hp] : body_parts) {
|
||||
if(count > 0 && Random::uniform(0, 1) == 0) {
|
||||
fmt::println("HIT! name={} count={} dmg={} hp={}", key, count, my_dmg, hp);
|
||||
body_parts[key] = std::max(0, hp - my_dmg);
|
||||
count--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Combat::less_than(int level) {
|
||||
return body_parts["head"] < level || body_parts["stomach"] < level || body_parts["chest"] < level;
|
||||
return body_parts["head"] <= level || body_parts["stomach"] <= level || body_parts["chest"] <= level;
|
||||
}
|
||||
|
||||
bool Combat::is_dead() {
|
||||
|
|
@ -35,7 +41,11 @@ namespace components {
|
|||
}
|
||||
|
||||
bool Combat::can_heal() {
|
||||
return less_than(max_hp / 2);
|
||||
for(auto& [key, hp] : body_parts) {
|
||||
if(hp < max_hp) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void Combat::apply_healing(Curative& cure) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue