Dungeon player and teleport randomization

This commit is contained in:
2024-09-12 12:41:52 -07:00
parent 043d7f1ba8
commit 875fa026df
11 changed files with 86 additions and 63 deletions

View File

@@ -51,10 +51,6 @@ folder_colors={
"res://src/player/": "blue"
}
[global_group]
Exit=""
[input]
ui_accept={

View File

@@ -61,7 +61,7 @@ public partial class Game : Node3D, IGame
private void Map_DungeonFinishedGenerating()
{
GameRepo.SetPlayerGlobalPosition(Map.GetPlayerSpawnPoint());
GameRepo.SetPlayerGlobalPosition(Map.GetPlayerSpawnPosition());
}
private void Map_DialogueChoiceMade()
@@ -91,7 +91,6 @@ public partial class Game : Node3D, IGame
.Handle((in GameLogic.Output.StartGame _) =>
{
InGameUI.Show();
GameRepo.SetPlayerGlobalPosition(Map.GetPlayerSpawnPoint());
})
.Handle((in GameLogic.Output.SetPauseMode output) => CallDeferred(nameof(SetPauseMode), output.IsPaused))
.Handle((in GameLogic.Output.ShowPauseMenu _) =>

View File

@@ -5,7 +5,6 @@ using DialogueManagerRuntime;
using Godot;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace GameJamDungeon;
@@ -17,9 +16,9 @@ public interface IMap : INode3D
public List<IDungeonFloor> Floors { get; }
public Vector3 GetPlayerSpawnPoint();
public void SpawnNextFloor();
public Vector3 GetPlayerSpawnPosition();
}
@@ -52,11 +51,6 @@ public partial class Map : Node3D, IMap
DialogueManager.DialogueEnded += DecisionMade;
}
public Vector3 GetPlayerSpawnPoint()
{
return _currentFloor.GetPlayerSpawnPoint();
}
public void SpawnNextFloor()
{
var oldFloor = _currentFloor;
@@ -68,6 +62,8 @@ public partial class Map : Node3D, IMap
EmitSignal(SignalName.DungeonFinishedGenerating);
}
public Vector3 GetPlayerSpawnPosition() => _currentFloor.GetPlayerSpawnPoint();
private void DecisionMade(Resource resource)
{
EmitSignal(SignalName.DialogueDecisionMade);

View File

@@ -21,23 +21,56 @@ public partial class DungeonFloor : Node3D, IDungeonFloor
[Node] public GodotObject DungeonGenerator { get; set; } = default!;
private Vector3 _playerSpawnPoint;
private Vector3 _teleportSpawnPoint;
internal List<IDungeonRoom> Rooms { get; private set; }
public void InitializeDungeon()
{
Rooms = new List<IDungeonRoom>();
DungeonGenerator.Call("generate");
Rooms = FindAllDungeonRooms(GetChildren().ToList(), Rooms);
Rooms = FindAllDungeonRooms([.. GetChildren()], Rooms);
_playerSpawnPoint = RandomizePlayerSpawnPoint();
_teleportSpawnPoint = RandomizeTeleportSpawnPointAwayFromPosition(_playerSpawnPoint);
}
public Vector3 GetPlayerSpawnPoint()
public Vector3 GetPlayerSpawnPoint() => _playerSpawnPoint;
public Vector3 GetTeleportSpawnPoint() => _teleportSpawnPoint;
private Vector3 RandomizePlayerSpawnPoint()
{
return Rooms.First().PlayerSpawn.GlobalPosition;
var rng = new RandomNumberGenerator();
rng.Randomize();
var rngDistribution = new List<float>();
var randomSpawnLocations = Rooms
.Select(x => x.PlayerSpawn);
var godotCollection = new Godot.Collections.Array<Marker3D>(randomSpawnLocations);
var result = godotCollection.PickRandom();
return result.GlobalPosition;
}
public Vector3 GetTeleportSpawnPoint()
private Vector3 RandomizeTeleportSpawnPointAwayFromPosition(Vector3 target)
{
return Rooms.First().TeleportSpawn.GlobalPosition;
var rng = new RandomNumberGenerator();
rng.Randomize();
var rngDistribution = new List<float>();
var roomsSortedByDistance = Rooms
.Select(x => x.TeleportSpawn.GlobalPosition)
.OrderByDescending(x => x.DistanceTo(target))
.ToArray();
var rngIndex = 1.0;
var rngSteps = rngIndex / roomsSortedByDistance.Count();
foreach (var room in roomsSortedByDistance)
{
rngIndex -= rngSteps;
rngDistribution.Add((float)rngIndex);
}
var result = roomsSortedByDistance[rng.RandWeighted([.. rngDistribution])];
return result;
}
private List<IDungeonRoom> FindAllDungeonRooms(List<Node> nodesToSearch, List<IDungeonRoom> roomsFound)

View File

@@ -17,7 +17,6 @@ public partial class Overworld : Node3D, IDungeonFloor
public void InitializeDungeon()
{
GameRepo.SetPlayerGlobalPosition(PlayerSpawnPoint.GlobalPosition);
}
public Vector3 GetPlayerSpawnPoint()

View File

@@ -1386,7 +1386,7 @@ unique_name_in_owner = true
unique_name_in_owner = true
SpawnRate = PackedFloat32Array(1)
[node name="TeleportSpawn" type="Marker3D" parent="Room" groups=["Exit"]]
[node name="TeleportSpawn" type="Marker3D" parent="Room"]
unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -3.06499, -5.37073, -18.2257)

View File

@@ -1622,5 +1622,5 @@ unique_name_in_owner = true
unique_name_in_owner = true
SpawnRate = PackedFloat32Array(1)
[node name="ExitSpawnLocation" type="Marker3D" parent="." groups=["Exit"]]
[node name="ExitSpawnLocation" type="Marker3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -3.06499, -7.2125, -9.52855)

View File

@@ -91,9 +91,6 @@ public partial class DungeonRoom : Node3D, IDungeonRoom, IProvide<DungeonRoomLog
public void OnResolved()
{
DungeonRoomBinding = DungeonRoomLogic.Bind();
GameRepo.SetPlayerGlobalPosition(PlayerSpawn.GlobalPosition);
DungeonRoomLogic.Start();
this.Provide();
}

View File

@@ -36,65 +36,67 @@ script = ExtResource("1_0tfda")
[node name="DungeonRoom" type="Node3D" parent="."]
script = ExtResource("1_ti7ur")
[node name="PlayerSpawn" type="Marker3D" parent="."]
[node name="PlayerSpawn" type="Marker3D" parent="DungeonRoom"]
unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -4.23461, 0)
[node name="Minimap Texture" type="MeshInstance3D" parent="."]
[node name="Minimap Texture" type="MeshInstance3D" parent="DungeonRoom"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -4.9805, 0)
layers = 2
mesh = SubResource("PlaneMesh_luhnj")
skeleton = NodePath("../..")
[node name="ItemSpawnPoints" type="Node3D" parent="."]
[node name="ItemSpawnPoints" type="Node3D" parent="DungeonRoom"]
unique_name_in_owner = true
[node name="ItemSpawn1" type="Marker3D" parent="ItemSpawnPoints"]
[node name="ItemSpawn1" type="Marker3D" parent="DungeonRoom/ItemSpawnPoints"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.83448, -4.15788, -2.92704)
gizmo_extents = 1.0
[node name="EnemySpawnPoints" type="Node3D" parent="."]
[node name="EnemySpawnPoints" type="Node3D" parent="DungeonRoom"]
unique_name_in_owner = true
[node name="EnemySpawn1" type="Marker3D" parent="EnemySpawnPoints"]
[node name="EnemySpawn1" type="Marker3D" parent="DungeonRoom/EnemySpawnPoints"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.053, -3, 0)
[node name="ItemDatabase" parent="." instance=ExtResource("4_2mnb7")]
[node name="ItemDatabase" parent="DungeonRoom" instance=ExtResource("4_2mnb7")]
unique_name_in_owner = true
[node name="EnemyDatabase" parent="." instance=ExtResource("5_owpbq")]
[node name="EnemyDatabase" parent="DungeonRoom" instance=ExtResource("5_owpbq")]
unique_name_in_owner = true
SpawnRate = PackedFloat32Array(1)
[node name="CSGBox3D" type="CSGBox3D" parent="."]
[node name="CSGBox3D" type="CSGBox3D" parent="DungeonRoom"]
use_collision = true
size = Vector3(10, 10, 10)
material = SubResource("StandardMaterial3D_nin6j")
[node name="CSGBox3D2" type="CSGBox3D" parent="CSGBox3D"]
[node name="CSGBox3D2" type="CSGBox3D" parent="DungeonRoom/CSGBox3D"]
operation = 2
use_collision = true
size = Vector3(9, 9, 9)
material = SubResource("StandardMaterial3D_5j6ws")
[node name="DOOR" parent="CSGBox3D" instance=ExtResource("2_mdawx")]
[node name="DOOR" parent="DungeonRoom/CSGBox3D" instance=ExtResource("2_mdawx")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.563568, -2.54039, 4.74571)
size = Vector3(4, 4, 1)
material = SubResource("StandardMaterial3D_it7n4")
[node name="DOOR2" parent="CSGBox3D" instance=ExtResource("2_mdawx")]
[node name="DOOR2" parent="DungeonRoom/CSGBox3D" instance=ExtResource("2_mdawx")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -2.58282, -4.73548)
size = Vector3(4, 4, 1)
material = SubResource("StandardMaterial3D_05l2p")
[node name="NavigationRegion3D" type="NavigationRegion3D" parent="."]
[node name="NavigationRegion3D" type="NavigationRegion3D" parent="DungeonRoom"]
navigation_mesh = SubResource("NavigationMesh_2klpp")
[node name="StaticBody3D" type="StaticBody3D" parent="NavigationRegion3D"]
[node name="StaticBody3D" type="StaticBody3D" parent="DungeonRoom/NavigationRegion3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.655729, 0, 0)
[node name="CollisionShape3D" type="CollisionShape3D" parent="NavigationRegion3D/StaticBody3D"]
[node name="CollisionShape3D" type="CollisionShape3D" parent="DungeonRoom/NavigationRegion3D/StaticBody3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.144196, -4.84337, -0.0752945)
shape = SubResource("BoxShape3D_4exnc")
[node name="ExitSpawnLocation" type="Marker3D" parent="." groups=["Exit"]]
[node name="TeleportSpawn" type="Marker3D" parent="DungeonRoom"]
unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -3.06499, -3.26251, -2.72249)

View File

@@ -40,86 +40,87 @@ size_in_voxels = Vector3i(5, 1, 1)
[node name="DungeonRoom" type="Node3D" parent="."]
script = ExtResource("2_jrlll")
[node name="PlayerSpawn" type="Marker3D" parent="."]
[node name="PlayerSpawn" type="Marker3D" parent="DungeonRoom"]
unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -4.23461, 0)
[node name="ItemSpawnPoints" type="Node3D" parent="."]
[node name="ItemSpawnPoints" type="Node3D" parent="DungeonRoom"]
unique_name_in_owner = true
[node name="ItemSpawn1" type="Marker3D" parent="ItemSpawnPoints"]
[node name="ItemSpawn1" type="Marker3D" parent="DungeonRoom/ItemSpawnPoints"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -15.3383, -3.87128, -2.92704)
gizmo_extents = 1.0
[node name="ItemSpawn2" type="Marker3D" parent="ItemSpawnPoints"]
[node name="ItemSpawn2" type="Marker3D" parent="DungeonRoom/ItemSpawnPoints"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 8.50278, -3.87128, -2.92704)
gizmo_extents = 1.0
[node name="ItemSpawn3" type="Marker3D" parent="ItemSpawnPoints"]
[node name="ItemSpawn3" type="Marker3D" parent="DungeonRoom/ItemSpawnPoints"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 3.08441, -3.87128, 2.87214)
gizmo_extents = 1.0
[node name="ItemSpawn4" type="Marker3D" parent="ItemSpawnPoints"]
[node name="ItemSpawn4" type="Marker3D" parent="DungeonRoom/ItemSpawnPoints"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -16.3726, -3.87128, 2.87214)
gizmo_extents = 1.0
[node name="EnemySpawnPoints" type="Node3D" parent="."]
[node name="EnemySpawnPoints" type="Node3D" parent="DungeonRoom"]
unique_name_in_owner = true
[node name="EnemySpawn1" type="Marker3D" parent="EnemySpawnPoints"]
[node name="EnemySpawn1" type="Marker3D" parent="DungeonRoom/EnemySpawnPoints"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -3.833, -3, 0)
[node name="Minimap Texture" type="MeshInstance3D" parent="."]
[node name="Minimap Texture" type="MeshInstance3D" parent="DungeonRoom"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -4.50433, 0)
layers = 2
mesh = SubResource("PlaneMesh_j8q3j")
skeleton = NodePath("../..")
[node name="ItemDatabase" parent="." instance=ExtResource("4_c51bx")]
[node name="ItemDatabase" parent="DungeonRoom" instance=ExtResource("4_c51bx")]
unique_name_in_owner = true
[node name="EnemyDatabase" parent="." instance=ExtResource("5_fabiq")]
[node name="EnemyDatabase" parent="DungeonRoom" instance=ExtResource("5_fabiq")]
unique_name_in_owner = true
SpawnRate = PackedFloat32Array(1)
[node name="CSGBox3D" type="CSGBox3D" parent="."]
[node name="CSGBox3D" type="CSGBox3D" parent="DungeonRoom"]
use_collision = true
size = Vector3(50, 10, 10)
material = SubResource("StandardMaterial3D_b8kax")
[node name="CSGBox3D2" type="CSGBox3D" parent="CSGBox3D"]
[node name="CSGBox3D2" type="CSGBox3D" parent="DungeonRoom/CSGBox3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0493774, 0, 0)
operation = 2
use_collision = true
size = Vector3(49, 9, 9)
material = SubResource("StandardMaterial3D_1h648")
[node name="DOOR" parent="CSGBox3D" instance=ExtResource("4_nh0nj")]
[node name="DOOR" parent="DungeonRoom/CSGBox3D" instance=ExtResource("4_nh0nj")]
transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 25, -2.5, 0)
size = Vector3(4, 4, 1)
material = SubResource("StandardMaterial3D_u3mvg")
[node name="DOOR2" parent="CSGBox3D" instance=ExtResource("4_nh0nj")]
[node name="DOOR2" parent="DungeonRoom/CSGBox3D" instance=ExtResource("4_nh0nj")]
transform = Transform3D(-4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, -24.578, -2.5, 0)
size = Vector3(4, 4, 1)
material = SubResource("StandardMaterial3D_ham86")
[node name="NavigationRegion3D" type="NavigationRegion3D" parent="."]
[node name="NavigationRegion3D" type="NavigationRegion3D" parent="DungeonRoom"]
navigation_mesh = SubResource("NavigationMesh_3rglr")
[node name="StaticBody3D2" type="StaticBody3D" parent="NavigationRegion3D"]
[node name="StaticBody3D2" type="StaticBody3D" parent="DungeonRoom/NavigationRegion3D"]
transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 0, 0, 0)
[node name="CollisionShape3D" type="CollisionShape3D" parent="NavigationRegion3D/StaticBody3D2"]
[node name="CollisionShape3D" type="CollisionShape3D" parent="DungeonRoom/NavigationRegion3D/StaticBody3D2"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.144196, -4.84337, -0.0752945)
shape = SubResource("BoxShape3D_tph0j")
[node name="StaticBody3D3" type="StaticBody3D" parent="NavigationRegion3D"]
[node name="StaticBody3D3" type="StaticBody3D" parent="DungeonRoom/NavigationRegion3D"]
transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 0, 0, 0)
[node name="CollisionShape3D" type="CollisionShape3D" parent="NavigationRegion3D/StaticBody3D3"]
[node name="CollisionShape3D" type="CollisionShape3D" parent="DungeonRoom/NavigationRegion3D/StaticBody3D3"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.320954, -4.84337, -0.0752945)
shape = SubResource("BoxShape3D_q0wqs")
[node name="ExitSpawnLocation" type="Marker3D" parent="." groups=["Exit"]]
[node name="TeleportSpawn" type="Marker3D" parent="DungeonRoom"]
unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -3.06499, -11.8837, -9.52855)

View File

@@ -12,7 +12,7 @@ script = ExtResource("1_5hmt3")
unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 6.03633, 0.654655, 6.89279)
[node name="ExitSpawnPoint" type="Marker3D" parent="." groups=["Exit"]]
[node name="ExitSpawnPoint" type="Marker3D" parent="."]
unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.49531, 1.49242, 0)