Almost shippable
This commit is contained in:
@@ -1,23 +0,0 @@
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.Introspection;
|
||||
using GameJamDungeon;
|
||||
using Godot;
|
||||
|
||||
[Meta(typeof(IAutoNode))]
|
||||
public partial class BossFloor : Node3D, IDungeonFloor
|
||||
{
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
|
||||
private BossRoom BossRoom;
|
||||
|
||||
public void InitializeDungeon()
|
||||
{
|
||||
var bossRoomScene = GD.Load<PackedScene>($"res://src/map/dungeon/scenes/BossRoom.tscn");
|
||||
BossRoom = bossRoomScene.Instantiate<BossRoom>();
|
||||
AddChild(BossRoom);
|
||||
}
|
||||
|
||||
public Transform3D GetPlayerSpawnPoint() => BossRoom.PlayerSpawn.GlobalTransform;
|
||||
|
||||
public Vector3 GetTeleportSpawnPoint() => BossRoom.TeleportSpawn.GlobalPosition;
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.GodotNodeInterfaces;
|
||||
using Chickensoft.Introspection;
|
||||
using Godot;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
public interface IDungeonFloor : INode3D
|
||||
{
|
||||
void InitializeDungeon();
|
||||
|
||||
public Transform3D GetPlayerSpawnPoint();
|
||||
|
||||
public Vector3 GetTeleportSpawnPoint();
|
||||
}
|
||||
|
||||
[Meta(typeof(IAutoNode))]
|
||||
public partial class DungeonFloor : Node3D, IDungeonFloor
|
||||
{
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
|
||||
[Node] public GodotObject DungeonGenerator { get; set; } = default!;
|
||||
|
||||
[Node] public NavigationRegion3D NavigationRegion3D { get; set; } = default!;
|
||||
|
||||
private Transform3D _playerSpawnPoint;
|
||||
|
||||
private Vector3 _teleportSpawnPoint;
|
||||
|
||||
internal List<IDungeonRoom> Rooms { get; private set; }
|
||||
|
||||
public void InitializeDungeon()
|
||||
{
|
||||
Rooms = new List<IDungeonRoom>();
|
||||
DungeonGenerator.Call("generate");
|
||||
NavigationRegion3D.BakeNavigationMesh();
|
||||
Rooms = FindAllDungeonRooms([.. GetChildren()], Rooms);
|
||||
_playerSpawnPoint = RandomizePlayerSpawnPoint();
|
||||
_teleportSpawnPoint = RandomizeTeleportSpawnPointAwayFromPosition(_playerSpawnPoint.Origin);
|
||||
}
|
||||
|
||||
public Transform3D GetPlayerSpawnPoint() => _playerSpawnPoint;
|
||||
|
||||
public Vector3 GetTeleportSpawnPoint() => _teleportSpawnPoint;
|
||||
|
||||
private Transform3D RandomizePlayerSpawnPoint()
|
||||
{
|
||||
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.GlobalTransform;
|
||||
}
|
||||
|
||||
private Vector3 RandomizeTeleportSpawnPointAwayFromPosition(Vector3 target)
|
||||
{
|
||||
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)
|
||||
{
|
||||
if (nodesToSearch.Count == 0)
|
||||
return roomsFound;
|
||||
|
||||
foreach (var node in nodesToSearch)
|
||||
if (node is IDungeonRoom dungeonRoom)
|
||||
roomsFound.Add(dungeonRoom);
|
||||
|
||||
return FindAllDungeonRooms(nodesToSearch.SelectMany(x => x.GetChildren()).ToList(), roomsFound);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
[gd_scene load_steps=7 format=3 uid="uid://bc1sp6xwe0j65"]
|
||||
[gd_scene load_steps=9 format=3 uid="uid://bc1sp6xwe0j65"]
|
||||
|
||||
[ext_resource type="Script" path="res://src/map/dungeon/floors/DungeonFloor.cs" id="1_0ecnn"]
|
||||
[ext_resource type="Script" path="res://src/map/dungeon/code/DungeonFloor.cs" id="1_0ecnn"]
|
||||
[ext_resource type="Script" path="res://addons/SimpleDungeons/DungeonGenerator3D.gd" id="2_cxmwa"]
|
||||
[ext_resource type="PackedScene" uid="uid://dpec2lbt83dhe" path="res://src/map/dungeon/scenes/Antechamber.tscn" id="3_tsw3y"]
|
||||
[ext_resource type="PackedScene" uid="uid://b82dx66mgs2d7" path="res://src/map/dungeon/scenes/BasinRoom.tscn" id="4_b2rkl"]
|
||||
[ext_resource type="PackedScene" uid="uid://bn4gslp2gk8ds" path="res://src/map/dungeon/corridor/Corridor.tscn" id="4_gni6i"]
|
||||
[ext_resource type="PackedScene" uid="uid://b7111krf365x0" path="res://src/map/dungeon/scenes/InnerBalcony.tscn" id="5_v15cv"]
|
||||
[ext_resource type="PackedScene" uid="uid://c1qicmrcg6q6x" path="res://src/map/dungeon/scenes/ColumnRoom.tscn" id="6_gy758"]
|
||||
|
||||
[sub_resource type="NavigationMesh" id="NavigationMesh_gqi8w"]
|
||||
border_size = 1.0
|
||||
@@ -21,9 +23,8 @@ navigation_mesh = SubResource("NavigationMesh_gqi8w")
|
||||
[node name="DungeonGenerator" type="Node3D" parent="NavigationRegion3D"]
|
||||
unique_name_in_owner = true
|
||||
script = ExtResource("2_cxmwa")
|
||||
room_scenes = Array[PackedScene]([ExtResource("3_tsw3y"), ExtResource("4_b2rkl")])
|
||||
room_scenes = Array[PackedScene]([ExtResource("3_tsw3y"), ExtResource("4_b2rkl"), ExtResource("5_v15cv"), ExtResource("6_gy758")])
|
||||
corridor_room_scene = ExtResource("4_gni6i")
|
||||
dungeon_size = Vector3i(20, 1, 20)
|
||||
dungeon_size = Vector3i(50, 1, 50)
|
||||
voxel_scale = Vector3(4, 4, 4)
|
||||
generate_on_ready = false
|
||||
place_even_if_fail = true
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
[gd_scene load_steps=6 format=3 uid="uid://b3r0r22kc67bl"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/SimpleDungeons/DungeonGenerator3D.gd" id="1_afeds"]
|
||||
[ext_resource type="PackedScene" uid="uid://dhpwwqow1ahrc" path="res://src/map/dungeon/rooms/Room1.tscn" id="2_dss74"]
|
||||
[ext_resource type="PackedScene" uid="uid://bbwgmqy3evhh2" path="res://src/map/dungeon/rooms/Room2.tscn" id="3_5748f"]
|
||||
[ext_resource type="PackedScene" path="res://src/map/dungeon/rooms/Room1.tscn" id="2_dss74"]
|
||||
[ext_resource type="PackedScene" path="res://src/map/dungeon/rooms/Room2.tscn" id="3_5748f"]
|
||||
[ext_resource type="PackedScene" uid="uid://bn4gslp2gk8ds" path="res://src/map/dungeon/corridor/Corridor.tscn" id="4_mebix"]
|
||||
[ext_resource type="Script" path="res://src/map/dungeon/floors/DungeonFloor.cs" id="5_ld0kt"]
|
||||
[ext_resource type="Script" path="res://src/map/dungeon/code/DungeonFloor.cs" id="5_ld0kt"]
|
||||
|
||||
[node name="Floor2" type="Node3D"]
|
||||
script = ExtResource("5_ld0kt")
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
[gd_scene load_steps=6 format=3 uid="uid://b40sstnic41dw"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/SimpleDungeons/DungeonGenerator3D.gd" id="1_ou8lo"]
|
||||
[ext_resource type="PackedScene" uid="uid://dhpwwqow1ahrc" path="res://src/map/dungeon/rooms/Room1.tscn" id="2_8mwqw"]
|
||||
[ext_resource type="PackedScene" uid="uid://bbwgmqy3evhh2" path="res://src/map/dungeon/rooms/Room2.tscn" id="3_ap5wj"]
|
||||
[ext_resource type="PackedScene" path="res://src/map/dungeon/rooms/Room1.tscn" id="2_8mwqw"]
|
||||
[ext_resource type="PackedScene" path="res://src/map/dungeon/rooms/Room2.tscn" id="3_ap5wj"]
|
||||
[ext_resource type="PackedScene" uid="uid://bn4gslp2gk8ds" path="res://src/map/dungeon/corridor/Corridor.tscn" id="4_1741m"]
|
||||
[ext_resource type="Script" path="res://src/map/dungeon/floors/DungeonFloor.cs" id="5_mo2td"]
|
||||
[ext_resource type="Script" path="res://src/map/dungeon/code/DungeonFloor.cs" id="5_mo2td"]
|
||||
|
||||
[node name="Floor3" type="Node3D"]
|
||||
script = ExtResource("5_mo2td")
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://g28xmp6cn16h"]
|
||||
|
||||
[ext_resource type="Script" path="res://src/map/dungeon/floors/BossFloor.cs" id="1_gsbuk"]
|
||||
[ext_resource type="Script" path="res://src/map/dungeon/code/BossFloor.cs" id="1_gsbuk"]
|
||||
|
||||
[node name="Floor11" type="Node3D"]
|
||||
script = ExtResource("1_gsbuk")
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.Introspection;
|
||||
using GameJamDungeon;
|
||||
using Godot;
|
||||
|
||||
[Meta(typeof(IAutoNode))]
|
||||
public partial class Overworld : Node3D, IDungeonFloor
|
||||
{
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
|
||||
[Dependency]
|
||||
public IGameRepo GameRepo => this.DependOn<IGameRepo>();
|
||||
|
||||
[Node] public Marker3D PlayerSpawnPoint { get; set; } = default!;
|
||||
|
||||
[Node] public Marker3D ExitSpawnPoint { get; set; } = default!;
|
||||
|
||||
public void InitializeDungeon()
|
||||
{
|
||||
}
|
||||
|
||||
public Transform3D GetPlayerSpawnPoint()
|
||||
{
|
||||
return PlayerSpawnPoint.GlobalTransform;
|
||||
}
|
||||
|
||||
public Vector3 GetTeleportSpawnPoint()
|
||||
{
|
||||
return ExitSpawnPoint.GlobalPosition;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user