Skip to content

Commit

Permalink
Update again
Browse files Browse the repository at this point in the history
  • Loading branch information
fungamer2-2 committed Dec 21, 2023
1 parent 4e4fda0 commit 1ab0e4c
Show file tree
Hide file tree
Showing 10 changed files with 267 additions and 94 deletions.
16 changes: 14 additions & 2 deletions board.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from utils import *
import random
from collections import defaultdict
from pathfinding import find_path

class Tile:

def __init__(self):
self.wall = False
self.revealed = False
self.stair = False
self.stair = 0
self.items = []

def is_passable(self):
Expand Down Expand Up @@ -263,4 +264,15 @@ def get_fov(self, pos):
seen.add(p)
fov.add(p)

return fov
return fov

def get_path(self, start, end, cost_func=None):
def passable_func(p):
return p == start or self.passable(p)

if cost_func is None:
cost_func = lambda p: 1

return find_path(self, start, end, passable_func, cost_func)


6 changes: 6 additions & 0 deletions const.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@
"input": COLOR_CYAN
}

from enum import Enum

class ItemUseResult:
NOT_USED = 0 #Item was not used
USED = 1 #Item was used, but should not be consumed
CONSUMED = 2 #Item was used, and should be consumed

30 changes: 22 additions & 8 deletions entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,20 +204,34 @@ def make_noise(self, volume):
def roll_wisdom(self):
return gauss_roll(stat_mod(self.WIS))

def hit_with_acid(self, strength, corr):
def acid_resist(self):
#Resistance to acid
# -1 is vulnerable, +1 is resistant, +2 is immune
return 0

def hit_with_acid(self, strength):
res = self.acid_resist()
if res >= 2:
return

if res < 0:
strength *= 2
elif res == 1:
strength = div_rand(strength, 2)

armor = self.get_armor()
strength -= rng(0, armor)

if strength <= 0:
return

dam = rng(1, strength)
typ = "bad" if self.is_player() else "neutral"

self.add_msg_u_or_mons("The acid burns you!", f"{self.get_name(True)} is burned by acid!", typ)

severity = " terribly" if res < 0 else ""
self.add_msg_u_or_mons("The acid burns you{severity}!", f"{self.get_name(True)} is burned{severity} by the acid!", typ)
self.take_damage(dam)

if self.is_player():
if x_in_y(dam * corr, 2000):
#TODO: Corrode armor
pass

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

Expand Down
59 changes: 45 additions & 14 deletions game_inst.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def __init__(self):
self.select_mon = None
self.noise_events = []
self.revealed = set()
self.delay = False

def add_noise_event(self, pos, loudness, src=None):
if loudness > 0:
Expand Down Expand Up @@ -107,8 +108,9 @@ def init_game(self):
curses.noecho()
curses.curs_set(False)
Entity.g = self
self.load_json_data()

self.load_json_data()
self.init_player()
self.generate_level()
self.draw_board()

Expand Down Expand Up @@ -138,7 +140,7 @@ def generate_level(self):
board.clear_los_cache()
board.clear_collision_cache()
board.procgen_level()
self.place_player()
self.init_player()
self.place_monsters()
self.place_items()

Expand All @@ -164,7 +166,7 @@ def place_items(self):

potions = [
[InvisibilityPotion, 25],
[HealingPotion, 120],
[HealingPotion, 130],
[EnlargementPotion, 20],
[ShrinkingPotion, 20],
[SpeedPotion, 30]
Expand All @@ -180,11 +182,13 @@ def place_items(self):
["club", 100],
["dagger", 60],
["greatclub", 25],
["handaxe", 60]
["handaxe", 60],
["battleaxe", 30],
["greatsword", 20]
]

for _ in range(rng(1, 4)):
if x_in_y(2, 5):
if x_in_y(3, 8):
pos = board.random_passable()
name = random_weighted(weapons)
board.place_item_at(pos, self.create_weapon(name))
Expand Down Expand Up @@ -260,6 +264,12 @@ def deinit_window(self):
import os
os.system("cls" if os.name == "nt" else "clear")
self.window_init = False

def init_player(self):
player = self.get_player()
self.place_player()

player.recalc_max_hp()

def place_player(self):
board = self.get_board()
Expand Down Expand Up @@ -399,14 +409,20 @@ def remove_dead(self):

def place_stairs(self):
board = self.get_board()
pos = board.random_passable()

for _ in range(5):
pos = board.random_passable()
if not self.items_at(pos):
break

tile = board.get_tile(pos)
tile.stair = True
tile.stair = 1

def getch(self, wait=True):
screen = self.screen
screen.nodelay(not wait)
if wait != self.delay:
self.delay = wait
screen.nodelay(not wait)
code = screen.getch()
return code

Expand Down Expand Up @@ -451,7 +467,10 @@ def draw_walls(self, offset_y):
elif tile.stair:
symbol = STAIR_SYMBOL
else:
symbol = " "
symbol = "." if seen else " "
if seen:
color = curses.color_pair(COLOR_GRAY)

self.draw_symbol(pos.y + offset_y, pos.x, symbol, color)

def draw_stats(self):
Expand Down Expand Up @@ -681,8 +700,17 @@ def select_monster_menu(self, monsters, check_fov=True):

self.add_message("View info of which monster? (Use the a and d keys to select, then press Enter)")

cursor = (len(monsters)-1)//2
cursor = 0
mon = None

min_dist = 999
nearest = None
for i, m in enumerate(monsters):
dist = player.distance(m)
if dist < min_dist:
min_dist = dist
nearest = m
cursor = i
while True:
self.set_mon_select(monsters[cursor])
self.draw_board()
Expand Down Expand Up @@ -787,13 +815,12 @@ def select_use_item(self):

can_scroll = max_scroll > 0

string = "Use which item? Enter a number from 1 - 9, then press Enter. Press 0 to cancel. "
string = "Use which item? Enter a number from 1 - 9, then press Enter. Press 0 to cancel. Press Shift+D to view description."
if can_scroll:
string += " (W and S keys to scroll)"

select = 0



while True:
screen.erase()
screen.addstr(0, 0, string)
Expand All @@ -815,13 +842,17 @@ def select_use_item(self):
scroll += 1
scroll = clamp(scroll, 0, max_scroll)

item = player.inventory[scroll + select]

if char == "0":
return None
elif char == "D":
self.add_message(item.name + " - " + item.description, "info")
return None
elif char in "123456789":
select = int(char) - 1

if key == 10:
item = player.inventory[scroll + select]
return item

class PopupInfo:
Expand Down
51 changes: 33 additions & 18 deletions items.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ class Item:
def __init__(self):
self.name = "item"
self.symbol = "?"
self.damage_taken = 0

def display_color(self):
return 0

def use(self, player):
return False

return ItemUseResult.NOT_USED
class Potion(Item):

def __init__(self):
Expand All @@ -26,8 +27,8 @@ def display_color(self):
return COLOR_DEEP_PINK2


class HealingPotion(Potion):
description = "A potion with a glimmering red liquid."
class HealingPotion(Potion):
description = "A potion with a glimmering red liquid, that restores HP when consumed."

def __init__(self):
super().__init__()
Expand All @@ -37,11 +38,12 @@ def use(self, player):
player.add_msg("You drink the healing potion.")
player.add_msg("You begin to feel more restored.", "good")
player.heal(dice(4, 4) + 2)
player.poison = max(0, player.poison - rng(0, 6))
player.use_energy(100)
return True
return ItemUseResult.CONSUMED

class EnlargementPotion(Potion):
description = "A potion with a light red liquid."
description = "A potion that will cause whoever consumes it to grow in size, increasing their HP and damage, but reducing stealth and evasion for the duration."

def __init__(self):
super().__init__()
Expand All @@ -59,10 +61,10 @@ def use(self, player):
player.add_status("Enlarged", dur)
player.use_energy(100)
player.recalc_max_hp()
return True
return ItemUseResult.CONSUMED

class ShrinkingPotion(Potion):
description = ""
description = "A potion that will cause whoever consumes it to shrink in size, making them more stealthy and evasive, but reducing max HP and damage for the duration."

def __init__(self):
super().__init__()
Expand All @@ -83,10 +85,10 @@ def use(self, player):
player.add_status("Reduced", dur)
player.use_energy(100)
player.recalc_max_hp()
return True
return ItemUseResult.CONSUMED

class SpeedPotion(Potion):
description = "A potion with a blue liquid that appears to have a slight glow."
description = "A potion with a blue liquid that appears to have a slight glow. When consed, it grants a temporary speed boost."

def __init__(self):
super().__init__()
Expand All @@ -103,10 +105,10 @@ def use(self, player):
dur = rng(20, 60)
player.use_energy(100)
player.add_status("Hasted", dur)
return True
return ItemUseResult.CONSUMED

class InvisibilityPotion(Potion):
description = "A potion with a rather transparent liquid."
description = "A potion with a rather transparent liquid. Anyone who drinks it will become temporarily invisible, but attacking while invisible will reduce its duration."

def __init__(self):
super().__init__()
Expand All @@ -123,18 +125,19 @@ def use(self, player):
dur = rng(60, 100)
player.use_energy(100)
player.add_status("Invisible", dur)
return True
return ItemUseResult.CONSUMED

#TODO: Melee and ranged weapons/JSON for them

class Weapon:
class Weapon(Item):
description = "A weapon that can be used in combat."

def __init__(self):
super().__init__()
self.type = None
self.name = "weapon"
self.damage = Dice(0, 0, 1)
self.dmg_type = "bludgeon"
self.finesse = False
self.heavy = False

def roll_damage(self):
return self.damage.roll()
Expand All @@ -145,7 +148,9 @@ def display_color(self):
@classmethod
def from_type(cls, typ):
obj = cls()
obj.type = typ
obj.name = typ.name
obj.heavy = typ.heavy
obj.symbol = typ.symbol
obj.damage = typ.base_damage
obj.dmg_type = typ.damage_type
Expand All @@ -156,7 +161,7 @@ def use(self, player):
player.add_msg(f"You wield a {self.name}.")
player.use_energy(100)
player.weapon = self
return True
return ItemUseResult.USED

class NullWeapon(Weapon):

Expand All @@ -169,4 +174,14 @@ def roll_damage(self):
return 1 + one_in(3)

UNARMED = NullWeapon()


class Armor(Item):
description = "Armor that may protect its wearer from damage."

def __init__(self):
super().__init__()
self.name = "armor"
self.protection = 1
self.stealth_pen = 0
self.encumbrance = 0

Loading

0 comments on commit 1ab0e4c

Please sign in to comment.