Body UI and damage works better now.
This commit is contained in:
parent
f6c8163acd
commit
2dec4ec993
3 changed files with 22 additions and 12 deletions
|
|
@ -14,18 +14,25 @@ namespace components {
|
|||
}
|
||||
|
||||
void Combat::take_damage(int my_dmg) {
|
||||
int count = Random::uniform(1, int(body_parts.size() - 1));
|
||||
dbc::check(part_names.size() > 2, "Not enough body parts in part_names");
|
||||
|
||||
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--;
|
||||
}
|
||||
}
|
||||
// select a random body part
|
||||
size_t key = Random::uniform(size_t(0), part_names.size() - 1);
|
||||
const std::string& name = part_names[key];
|
||||
int hp = body_parts[name];
|
||||
|
||||
// catch this bug
|
||||
dbc::check(hp >= 0, "HP went negative");
|
||||
|
||||
// don't hit dead parts
|
||||
if(hp == 0) {
|
||||
dbc::log("IT's zero.");
|
||||
return;
|
||||
}
|
||||
|
||||
// don't go below 0
|
||||
body_parts[name] = std::max(0, hp - my_dmg);
|
||||
fmt::println("BODY PART {} was {} now {}", name, hp, body_parts[name]);
|
||||
}
|
||||
|
||||
bool Combat::less_than(int level) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue