Make the teleporter work with the dungeon even when it's noit loaded, also fixed and enablen mob spawning in the dungeon.

This commit is contained in:
Relintai 2020-07-23 00:12:19 +02:00
parent e95f5ac67e
commit 7b5712a996
6 changed files with 28 additions and 20 deletions

View File

@ -41,4 +41,5 @@ func teleport():
if (p.get_body().transform.origin - transform.origin).length() > use_range:
return
p.get_body().transform.origin = teleport_to
p.get_body().teleport(teleport_to)
# p.get_body().transform.origin = teleport_to

View File

@ -6,12 +6,12 @@
[sub_resource type="CubeMesh" id=1]
size = Vector3( 1, 1, 1 )
[sub_resource type="SpatialMaterial" id=3]
[sub_resource type="SpatialMaterial" id=2]
flags_vertex_lighting = true
albedo_color = Color( 0.494118, 0.494118, 0.494118, 1 )
albedo_texture = ExtResource( 2 )
[sub_resource type="BoxShape" id=2]
[sub_resource type="BoxShape" id=3]
extents = Vector3( 0.5, 0.5, 0.5 )
[node name="DungeonTeleporter" type="StaticBody"]
@ -20,7 +20,7 @@ default_albedo = Color( 0.521569, 0.521569, 0.521569, 1 )
[node name="MeshInstance" type="MeshInstance" parent="."]
mesh = SubResource( 1 )
material/0 = SubResource( 3 )
material/0 = SubResource( 2 )
[node name="CollisionShape" type="CollisionShape" parent="."]
shape = SubResource( 2 )
shape = SubResource( 3 )

View File

@ -121,7 +121,7 @@ func _generate_chunk(chunk, spawn_mobs):
var chunk_aabb : AABB = AABB(chunk.get_position() * Vector3(chunk.size_x, chunk.size_y, chunk.size_z), Vector3(chunk.size_x, chunk.size_y, chunk.size_z))
if dung_entrance_scene && chunk_aabb.has_point(entrance_position.origin):
inner_entrance_position = Vector3(player_inner_entrance_position_x * chunk.voxel_scale, (posy + 2) * chunk.voxel_scale + 0.3, player_inner_entrance_position_z * chunk.voxel_scale)
inner_entrance_position = Vector3(player_inner_entrance_position_x * chunk.voxel_scale, (posy + 4) * chunk.voxel_scale + 0.3, player_inner_entrance_position_z * chunk.voxel_scale)
call_deferred("spawn_teleporter_scene", dung_entrance_scene, entrance_position, chunk, inner_entrance_position)
if !aabb.intersects(chunk_aabb):
@ -198,11 +198,14 @@ func _generate_chunk(chunk, spawn_mobs):
zz = 0
if spawn_mobs:
var chunk_world_aabb : AABB = AABB(chunk.get_position() * Vector3(chunk.size_x, chunk.size_y, chunk.size_z) * Vector3(chunk.voxel_scale, chunk.voxel_scale, chunk.voxel_scale), Vector3(chunk.size_x, chunk.size_y, chunk.size_z) * Vector3(chunk.voxel_scale, chunk.voxel_scale, chunk.voxel_scale))
for enemy in enemy_data:
var bp = enemy[0]
var pos : Vector3 = Vector3(bp.x * chunk.voxel_scale, floor_pos, bp.y * chunk.voxel_scale)
ESS.entity_spawner.spawn_mob(enemy[1], enemy[2], pos)
var pos : Vector3 = Vector3(bp.x * chunk.voxel_scale, (posy + 4) * chunk.voxel_scale, bp.y * chunk.voxel_scale)
if chunk_world_aabb.has_point(pos):
ESS.entity_spawner.spawn_mob(enemy[1], enemy[2], pos)
# entities.app
# for i in range(get_dungeon_start_room_count()):

View File

@ -13,7 +13,7 @@
[ext_resource path="res://modules/planets/test_planet/voxel_library/textures/stone_dungeon_1_albedo.png" type="Texture" id=11]
[resource]
posy = -50
posy = -45
sizex = 40
sizey = 3
sizez = 40
@ -22,7 +22,7 @@ level_room_count = 9
min_room_dimension = 5
max_room_dimension = 8
enemy_count = 14
spawn_mobs = false
spawn_mobs = true
dung_floor = ExtResource( 7 )
dung_ceiling = ExtResource( 4 )
dung_wall_xp = ExtResource( 5 )

View File

@ -385,7 +385,7 @@ func process_movement_mob(delta : float) -> void:
if vel.length_squared() < 0.12:
sleep = true
if translation.y < -50.0:
if translation.y < -200.0:
print("killed mob with fall damage")
var sdi : SpellDamageInfo = SpellDamageInfo.new()
sdi.damage_source_type = SpellDamageInfo.DAMAGE_SOURCE_UNKNOWN
@ -653,3 +653,7 @@ func set_max_visible_distance(var value : float) -> void:
max_visible_distance = value
func teleport(teleport_to : Vector3):
world.spawn(teleport_to.x / world.chunk_size_x / world.voxel_scale, teleport_to.y/ world.chunk_size_y / world.voxel_scale, teleport_to.z/ world.chunk_size_z / world.voxel_scale)
transform.origin = teleport_to
placed = false

View File

@ -56,7 +56,7 @@ func generate():
if level_generator != null:
level_generator.setup(self, 80, false, library)
spawn()
spawn(0, 0, 0)
func _process(delta):
@ -174,14 +174,14 @@ func _create_chunk(x : int, y : int, z : int, pchunk : VoxelChunk) -> VoxelChunk
# print("added " + str(Vector3(x, y, z)))
return ._create_chunk(x, y, z, chunk)
func spawn() -> void:
func spawn(start_x : int, start_y : int, start_z : int) -> void:
if not Engine.editor_hint:
_max_frame_chunk_build_temp = max_frame_chunk_build_steps
max_frame_chunk_build_steps = 0
for x in range(-chunk_spawn_range, chunk_spawn_range):
for z in range(-chunk_spawn_range, chunk_spawn_range):
for y in range(-1, 2):
for x in range(-chunk_spawn_range + start_x, chunk_spawn_range + start_x):
for z in range(-chunk_spawn_range + start_z, chunk_spawn_range + start_z):
for y in range(-1 + start_y, 2 + start_y):
create_chunk(x, y, z)
# add_prop(Transform().translated(Vector3(0, 2, 0)), test_prop)
@ -197,7 +197,7 @@ func set_editor_generate(value : bool) -> void:
library.refresh_rects()
level_generator.setup(self, current_seed, false, library)
spawn()
spawn(0, 0, 0)
# else:
# spawned = false
# clear()
@ -226,7 +226,7 @@ func setup_client_seed(pseed : int) -> void:
if level_generator != null:
level_generator.setup(self, pseed, false, library)
spawn()
spawn(0, 0, 0)
func load_character(file_name : String) -> void:
_player_file_name = file_name
@ -241,7 +241,7 @@ func load_character(file_name : String) -> void:
if level_generator != null:
level_generator.setup(self, _player.sseed, true, library)
spawn()
spawn(0, 0, 0)
set_process(true)