From adad0c077825eafb84138178efd10d26b7115047 Mon Sep 17 00:00:00 2001 From: Relintai Date: Mon, 3 Aug 2020 21:51:09 +0200 Subject: [PATCH] Now spawned mobs will match the player's level. (For testing.) --- .../planets/test_planet/biomes/simple_biome.gd | 16 ++++++++++++++-- game/player/Player.gd | 9 ++++++++- game/voxelman/world/TVVoxelWorld.gd | 8 ++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/game/modules/planets/test_planet/biomes/simple_biome.gd b/game/modules/planets/test_planet/biomes/simple_biome.gd index 184c296d..83c7b828 100644 --- a/game/modules/planets/test_planet/biomes/simple_biome.gd +++ b/game/modules/planets/test_planet/biomes/simple_biome.gd @@ -58,7 +58,13 @@ func _generate_chunk(chunk: VoxelChunk, spawn_mobs: bool) -> void: get_dungeon(i).generate_chunk(chunk, spawn_mobs) if not Engine.editor_hint and chunk.position_y == 0 and spawn_mobs and randi() % 4 == 0: - ESS.entity_spawner.spawn_mob(0, randi() % 3, Vector3(chunk.position_x * chunk.size_x * chunk.voxel_scale + chunk.size_x / 2,\ + var level : int = 1 + + if chunk.get_voxel_world().has_method("get_mob_level"): + level = chunk.get_voxel_world().get_mob_level() + + ESS.entity_spawner.spawn_mob(0, level, \ + Vector3(chunk.position_x * chunk.size_x * chunk.voxel_scale + chunk.size_x / 2,\ (chunk.position_y + 1) * chunk.size_y * chunk.voxel_scale, \ chunk.position_z * chunk.size_z * chunk.voxel_scale + chunk.size_z / 2)) @@ -133,7 +139,13 @@ func generate_terrarin(chunk : VoxelChunk, spawn_mobs: bool) -> void: # chunk.build() if not Engine.editor_hint and chunk.position_y == 0 and spawn_mobs: - ESS.entity_spawner.spawn_mob(0, randi() % 3, Vector3(chunk.position_x * chunk.size_x * chunk.voxel_scale + chunk.size_x / 2,\ + var level : int = 1 + + if chunk.get_voxel_world().has_method("get_mob_level"): + level = chunk.get_voxel_world().mob_level + + ESS.entity_spawner.spawn_mob(0, level, \ + Vector3(chunk.position_x * chunk.size_x * chunk.voxel_scale + chunk.size_x / 2,\ (chunk.position_y + 1) * chunk.size_y * chunk.voxel_scale, \ chunk.position_z * chunk.size_z * chunk.voxel_scale + chunk.size_z / 2)) diff --git a/game/player/Player.gd b/game/player/Player.gd index 1cfca87a..c2ea214f 100644 --- a/game/player/Player.gd +++ b/game/player/Player.gd @@ -30,7 +30,14 @@ func _process(delta): if Input.is_action_just_pressed("sheath"): get_character_skeleton().toggle_sheath() - +func _notification_slevel_up(value): + ._notification_slevel_up(value) + + var world : Node = get_node_or_null("..") + + if world: + if world.has_method("set_mob_level"): + world.set_mob_level(gets_level()) func _from_dict(dict): ._from_dict(dict) diff --git a/game/voxelman/world/TVVoxelWorld.gd b/game/voxelman/world/TVVoxelWorld.gd index 4834a1af..03767404 100644 --- a/game/voxelman/world/TVVoxelWorld.gd +++ b/game/voxelman/world/TVVoxelWorld.gd @@ -36,6 +36,8 @@ export(bool) var use_global_chunk_settings : bool = true export(PropData) var test_prop : PropData +var mob_level : int = 1 + var initial_generation : bool = true var spawned : bool = false @@ -295,3 +297,9 @@ func save() -> void: return ESS.entity_spawner.save_player(_player, _player_file_name) + +func get_mob_level() -> int: + return mob_level + +func set_mob_level(level : int) -> void: + mob_level = level