Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
fungamer2-2 committed Dec 19, 2023
1 parent 5fc4459 commit 027b6dd
Show file tree
Hide file tree
Showing 8 changed files with 323 additions and 138 deletions.
7 changes: 7 additions & 0 deletions effects.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@
"apply_msg": "You suddenly become unable to move!",
"extend_msg": "You feel even more paralyzed.",
"remove_msg": "You can finally move again."
},
{
"name": "Invisible",
"type": "good",
"apply_msg": "You become invisible.",
"extend_msg": "You become even more invisible.",
"remove_msg": "Your fade into view once again."
}

]
47 changes: 43 additions & 4 deletions entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ def __init__(self):
self.poison = 0
self.status = {}

def roll_to_hit(self, other):
if x_in_y(MIN_HIT_MISS_PROB, 100):
return 1000 if one_in(2) else -1000

roll = gauss_roll(self.calc_to_hit_bonus(other))
evasion = other.calc_evasion()

return roll - evasion

def get_all_status_effects(self):
for name in self.status:
yield name

def has_status(self, name):
g = self.g
g.check_effect_type(name)
Expand All @@ -28,21 +41,31 @@ def add_status(self, name, dur):
self.status[name] = 0
self.status[name] += dur*100

def adjust_duration(self, name, amount):
if self.has_status(name):
self.status[name] += amount*100
if self.status[name] <= 0:
self.remove_status(name)

def remove_status(self, name):
if self.has_status(name):
del self.status[name]

def use_energy(self, amount):
self.energy -= amount

def use_move_energy(self):
cost = div_rand(10000, self.get_speed())
self.use_energy(cost)

def is_player(self):
return False

def is_monster(self):
return False

def is_invisible(self):
return False
return self.has_status("Invisible")

def calc_evasion(self):
dex = self.DEX
Expand Down Expand Up @@ -71,6 +94,19 @@ def get_armor(self):
@abstractmethod
def get_name(self, capitalize=False):
return "Unknown Entity"

@abstractmethod
def calc_to_hit_bonus(self, other):
mod = 0
if not self.sees(other):
mod -= 5
if not other.sees(self):
mod += 5
return mod

@abstractmethod
def base_damage_roll(self):
return 1

def add_msg(self, text, typ="neutral"):
g = self.g
Expand Down Expand Up @@ -146,7 +182,7 @@ def sees_pos(self, pos):
return board.has_line_of_sight(self.pos, pos)

def sees(self, other):
if self is other:
if self is other: #We always see ourselves
return True

return self.sees_pos(other.pos)
Expand Down Expand Up @@ -181,6 +217,9 @@ def hit_with_acid(self, strength, corr):
if x_in_y(dam * corr, 2000):
#TODO: Corrode armor
pass


def stealth_mod(self):
return stat_mod(self.DEX)


def stealth_roll(self):
return gauss_roll(self.stealth_mod())
50 changes: 37 additions & 13 deletions game_inst.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ def init_colors(self):

def init_game(self):
self.screen = curses.initscr()

self.init_colors()

curses.noecho()
Expand All @@ -120,6 +119,7 @@ def load_json_data(self):

def next_level(self):
player = self.get_player()

self.level += 1

if player.debug_wizard:
Expand Down Expand Up @@ -154,15 +154,20 @@ def choose_mon_spawn_pos(self):
return pos

return None

def create_weapon(self, id):
typ = self.get_weapon_type(id)
return Weapon.from_type(typ)

def place_items(self):
board = self.get_board()

potions = [
[InvisibilityPotion, 10_000_000_000],
[HealingPotion, 120],
[EnlargementPotion, 25],
[ShrinkingPotion, 25],
[SpeedPotion, 35]
[EnlargementPotion, 20],
[ShrinkingPotion, 20],
[SpeedPotion, 30]
]

for _ in range(rng(1, 5)):
Expand All @@ -179,12 +184,10 @@ def place_items(self):
]

for _ in range(rng(1, 4)):
if one_in(2):
if x_in_y(2, 5):
pos = board.random_passable()
name = random_weighted(weapons)
typ = self.get_weapon_type(name)
weapon = Weapon.from_type(typ)
board.place_item_at(pos, weapon)
board.place_item_at(pos, self.create_weapon(name))

def place_monsters(self):
eligible_types = {}
Expand Down Expand Up @@ -510,7 +513,18 @@ def draw_stats(self):
for i, string in enumerate(strings2):
self.draw_string(i + offset, width + 6, string)


offset += len(strings2) + 1
status = sorted(list(player.get_all_status_effects()))
if status:
for i, string in enumerate(status):
eff = self.get_effect_type(string)
color = curses.color_pair(MSG_TYPES[eff.type])

self.draw_string(i + offset, width + 6, string, color)

if i >= 12:
break

def draw_monsters(self, offset_y):
player = self.get_player()
for m in player.visible_monsters():
Expand All @@ -531,7 +545,8 @@ def draw_messages(self, offset_y):
messages = self.msg_log.get_messages(8)
board = self.get_board()
y = board.height + offset_y
rows, cols = screen.getmaxyx()
rows, _ = screen.getmaxyx()
cols = board.width + 4
groups = []

total_lines = 0
Expand Down Expand Up @@ -620,7 +635,10 @@ def process_input(self):

code = self.getch()
char = chr(code)

if code == -1:
curses.flushinp()
return False

if char == "w":
return player.move_dir(0, -1)
if char == "s":
Expand Down Expand Up @@ -698,7 +716,13 @@ def print_monster_info(self, monster):
info.add_line("It hasn't noticed your presence yet.")
if monster.has_flag("PACK_TRAVEL"):
info.add_line("This creature travels in packs and takes advantage of its nearby allies to attack targets more easily.")

blindsight = monster.type.blindsight_range
if blindsight > 0:
string = f"This creature has blindsight to a radius of {blindsight} tiles"
if not monster.can_see():
string += " (blind beyond this range)"
string += "."
info.add_line(string)
mon_speed = monster.get_speed()
player_speed = player.get_speed()
diff = mon_speed / player_speed
Expand All @@ -712,7 +736,7 @@ def print_monster_info(self, monster):


player_to_hit = gauss_roll_prob(player.calc_to_hit_bonus(monster), monster.calc_evasion())
monster_to_hit = gauss_roll_prob(monster.get_to_hit_bonus(), player.calc_evasion())
monster_to_hit = gauss_roll_prob(monster.calc_to_hit_bonus(player), player.calc_evasion())

player_to_hit = player_to_hit*(1-MIN_HIT_MISS_PROB/100) + MIN_HIT_MISS_PROB/2
monster_to_hit = monster_to_hit*(1-MIN_HIT_MISS_PROB/100) + MIN_HIT_MISS_PROB/2
Expand Down
24 changes: 22 additions & 2 deletions items.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def use(self, player):
player.use_energy(50)
dur = rng(150, 300)

player.remove_status("Reduced")
player.remove_status("Reduced", True)
player.add_status("Enlarged", dur)
player.use_energy(100)
player.recalc_max_hp()
Expand All @@ -79,7 +79,7 @@ def use(self, player):
player.use_energy(50)
dur = rng(150, 300)

player.remove_status("Enlarged")
player.remove_status("Enlarged", True)
player.add_status("Reduced", dur)
player.use_energy(100)
player.recalc_max_hp()
Expand All @@ -104,6 +104,26 @@ def use(self, player):
player.use_energy(100)
player.add_status("Hasted", dur)
return True

class InvisibilityPotion(Potion):
description = "A potion with a rather transparent liquid."

def __init__(self):
super().__init__()
self.name = "invisibility potion"

def display_color(self):
return COLOR_BLUE

def use(self, player):
player.add_msg("You drink the invisibility potion.")
if player.has_status("Invisible"):
dur = rng(20, 40)
else:
dur = rng(60, 100)
player.use_energy(100)
player.add_status("Invisible", dur)
return True

#TODO: Melee and ranged weapons/JSON for them

Expand Down
1 change: 1 addition & 0 deletions json_obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def load(cls, d):

obj.load_optional(d, "blindsight_range", 0, int)
obj.load_optional(d, "poison", False, (bool, dict))
obj.load_optional(d, "weapon", None)

if obj.poison != False:
if type(obj.poison) != dict:
Expand Down
Loading

0 comments on commit 027b6dd

Please sign in to comment.