From 99cd14cdfdda1ee8187a4730867b9caaa5f6feac Mon Sep 17 00:00:00 2001 From: "grandsonneo@gmail.com" Date: Sat, 9 Dec 2023 09:50:00 -0500 Subject: [PATCH] Update --- entity.py | 1 + json_obj.py | 1 + monsters.json | 1 + player.py | 8 +++++--- utils.py | 7 +++++++ 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/entity.py b/entity.py index 358886f..4258dea 100644 --- a/entity.py +++ b/entity.py @@ -15,6 +15,7 @@ def __init__(self): self.HP = self.MAX_HP = 10 self.pos = Point() self.energy = 100 + self.poison = 0 self.status = {} def has_status(self, name): diff --git a/json_obj.py b/json_obj.py index 0b229b1..9d82427 100644 --- a/json_obj.py +++ b/json_obj.py @@ -139,6 +139,7 @@ def load(cls, d): obj.load_required(d, "level", int) obj.load_required(d, "diff", int) obj.load_required(d, "to_hit", int) + obj.load_optional(d, "armor", 0, int) obj.load_optional(d, "speed", 100, int) obj.load_optional(d, "size", "medium", str) obj.load_optional(d, "attack_msg", " attacks ", str) diff --git a/monsters.json b/monsters.json index d462681..ac6c960 100644 --- a/monsters.json +++ b/monsters.json @@ -137,6 +137,7 @@ "to_hit": 4, "level": 5, "diff": 3, + "armor": 1, "use_dex_melee": true, "size": "small", "speed": 90, diff --git a/player.py b/player.py index 8c8b1cc..295a4a6 100644 --- a/player.py +++ b/player.py @@ -35,7 +35,6 @@ def calc_evasion(self): bonus *= 0.7 elif self.has_status("Reduced"): bonus *= 1.3 - return bonus + 5 def add_to_inventory(self, item): @@ -63,8 +62,7 @@ def gain_xp(self, amount): self.xp -= self.xp_to_next_level() self.xp_level += 1 self.recalc_max_hp() - - + if self.xp_level % 3 == 0: num += 1 @@ -327,6 +325,10 @@ def do_turn(self): while self.regen_tick >= 1: self.regen_tick -= 1 self.heal(1) + + if self.poison > 0: + amount = 1 + div_rand(self.poison, 12) + dmg = mult_rand_frac(amount, used, 100) for name in list(self.status.keys()): self.status[name] -= used diff --git a/utils.py b/utils.py index 125591a..663c267 100644 --- a/utils.py +++ b/utils.py @@ -51,6 +51,9 @@ def div_rand(x, y): y = abs(y) mod = x % y return sign * (x//y + (rng(1, y) <= mod)) + +def mult_rand_frac(val, x, y): + return div_rand(val * x, y) def random_weighted(entries): values, weights = list(zip(*entries)) @@ -78,6 +81,10 @@ def display_bar(val, max, width): bars += " "*(width-len(bars)) return f"[{bars}]" +def apply_armor(damage, armor): + prot = rng(0, armor) + rng(0, armor) + return max(damage - prot, 0) + class Dice: def __init__(self, num, sides, mod):