Skip to content

Commit bd4e293

Browse files
committed
dungeon generation fixes
1 parent aa799ee commit bd4e293

File tree

4 files changed

+13
-26
lines changed

4 files changed

+13
-26
lines changed

stories/dungeon/story.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -126,22 +126,6 @@ def add_zone(self, zone: Zone) -> bool:
126126

127127
return True
128128

129-
def _generate_boss(self, zone: Zone) -> bool:
130-
character = self.llm_util.generate_character(keywords=['final boss']) # Characterv2
131-
if character:
132-
boss = RoamingMob(character.name,
133-
gender=character.gender,
134-
title=lang.capital(character.name),
135-
descr=character.description,
136-
short_descr=character.appearance,
137-
age=character.age,
138-
personality=character.personality)
139-
boss.aliases = [character.name.split(' ')[0]]
140-
boss.stats.level = self.max_depth
141-
location = random.choice(list(zone.locations.values()))
142-
location.insert(boss, None)
143-
return True
144-
return False
145129

146130
if __name__ == "__main__":
147131
# story is invoked as a script, start it in the Tale Driver.

tale/dungeon/dungeon.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from typing import TYPE_CHECKING
1010

1111
from stories.anything.npcs.npc_defs import RoamingMob
12-
from tale import lang
12+
from tale import lang, parse_utils
1313
from tale.base import Door, Exit, Location
1414
from tale.coord import Coord
1515
from tale.dungeon.dungeon_generator import ItemPopulator, Layout, LayoutGenerator, MobPopulator
@@ -201,27 +201,29 @@ def _connect_locations(self, layout: Layout) -> None:
201201
for connection in connections:
202202
cell_location = self._grid.get(connection.coord.as_tuple(), None)
203203
parent_location = self._grid.get(connection.other.as_tuple(), None)
204+
direction = parse_utils.direction_from_coordinates(connection.other.subtract(connection.coord))
205+
reverse_direction = parse_utils.opposite_direction(direction)
204206

205207
if not cell_location or not parent_location:
206208
continue
207209

208210
# Skip if already connected
209-
if cell_location.exits.get(parent_location.name, None):
211+
if cell_location.exits.get(parent_location.name, None) or cell_location.exits.get(direction, None):
210212
continue
211-
elif parent_location.exits.get(cell_location.name, None):
213+
elif parent_location.exits.get(cell_location.name, None) or parent_location.exits.get(reverse_direction, None):
212214
continue
213215

214216
# Create connection
215217
if connection.door:
216218
Door.connect(
217-
cell_location, parent_location.name, '', None,
218-
parent_location, cell_location.name, '', None,
219+
cell_location, [parent_location.name, direction], '', None,
220+
parent_location, [cell_location.name, reverse_direction], '', None,
219221
opened=False, locked=connection.locked, key_code=connection.key_code
220222
)
221223
else:
222224
Exit.connect(
223-
cell_location, parent_location.name, '', None,
224-
parent_location, cell_location.name, '', None
225+
cell_location, [parent_location.name, direction], '', None,
226+
parent_location, [cell_location.name, reverse_direction], '', None
225227
)
226228

227229
def _spawn_gold(self, zone: Zone):

tale/dungeon/dungeon_generator.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ def populate(self, layout: 'Layout', story: DynamicStory, zone: Zone) -> list:
223223
if not mob_type:
224224
continue
225225
mob_type['level'] = zone.level
226-
item_probabilities = [random.random() * 0.15 + 0.5 for i in range(len(zone.items))]
226+
item_types = [zone.items]
227+
item_probabilities = [(random.random() * 0.15 + 0.5) for i in range(len(item_types))]
227228
mob_spawner = MobSpawner(location=location, mob_type=mob_type, spawn_rate=30, spawn_limit=2, drop_items=zone.items, drop_item_probabilities=item_probabilities)
228229
mob_spawners.append(mob_spawner)
229230
if len(mob_spawners) == 1:
@@ -249,7 +250,7 @@ def populate(self, zone: Zone, story: DynamicStory) -> list:
249250
continue
250251
item_type['level'] = zone.level
251252
item_types = [item_type]
252-
item_probabilities = [random.random() * 0.15 + 0.5 for i in range(len(zone.items))]
253+
item_probabilities = [(random.random() * 0.15 + 0.5) for i in range(len(item_types))]
253254
item_spawners.append(ItemSpawner(zone=zone, items=item_types, item_probabilities=item_probabilities, spawn_rate=30))
254255
if len(item_spawners) == 1:
255256
return [item_spawners]

tale/zone.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def __init__(self, name: str, description: str = '') -> None:
2323
self.name = name
2424
self.lore = ""
2525
self.dungeon_config = None # type: DungeonConfig
26-
self.dungeon = None # type: Dungeon - tracks if a dungeon has been generated for this zone
26+
self.dungeon = None # type: Dungeon
2727

2828
def add_location(self, location: Location) -> bool:
2929
""" Add a location to the zone. Skip if location already exists."""

0 commit comments

Comments
 (0)