Revamp map route stuff
This commit is contained in:
@@ -30,30 +30,6 @@ public partial class DungeonFloor : Node3D, IDungeonFloor
|
||||
|
||||
}
|
||||
|
||||
public void SpawnEnemies(DungeonFloorNode floorNode)
|
||||
{
|
||||
var enemyOdds = new Godot.Collections.Dictionary<EnemyType, float>
|
||||
{
|
||||
{ EnemyType.Sproingy, floorNode.Sproingy },
|
||||
{ EnemyType.Michael, floorNode.Michael },
|
||||
{ EnemyType.FilthEater, floorNode.FilthEater },
|
||||
{ EnemyType.Sara, floorNode.Sara },
|
||||
{ EnemyType.Ballos, floorNode.Ballos },
|
||||
{ EnemyType.Chinthe, floorNode.Chinthe },
|
||||
{ EnemyType.AmbassadorGreen, floorNode.GreenAmbassador },
|
||||
{ EnemyType.AmbassadorRed, floorNode.RedAmbassador },
|
||||
{ EnemyType.AmbassadorSteel, floorNode.SteelAmbassador },
|
||||
{ EnemyType.AgniDemon, floorNode.AgniDemon },
|
||||
{ EnemyType.AqueousDemon, floorNode.AqueosDemon },
|
||||
{ EnemyType.Palan, floorNode.Palan },
|
||||
{ EnemyType.ShieldOfHeaven, floorNode.ShieldOfHeaven },
|
||||
{ EnemyType.GoldSproingy, floorNode.GoldSproingy },
|
||||
};
|
||||
var monsterRooms = Rooms.OfType<MonsterRoom>();
|
||||
foreach (var room in monsterRooms)
|
||||
room.SpawnEnemies(enemyOdds);
|
||||
}
|
||||
|
||||
public (Vector3 Rotation, Vector3 Position) GetPlayerSpawnPoint() { return (_playerSpawnPoint.Rotation, new Vector3(_playerSpawnPoint.GlobalPosition.X, 0, _playerSpawnPoint.GlobalPosition.Z)); }
|
||||
|
||||
|
||||
@@ -80,4 +56,10 @@ public partial class DungeonFloor : Node3D, IDungeonFloor
|
||||
|
||||
return FindAllDungeonRooms([.. nodesToSearch.SelectMany(x => x.GetChildren())], roomsFound);
|
||||
}
|
||||
|
||||
public IDungeonRoom GetPlayersCurrentRoom()
|
||||
{
|
||||
var playersRoom = Rooms.SingleOrDefault(x => x.IsPlayerInRoom);
|
||||
return playersRoom;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.Introspection;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
using System.Linq;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
@@ -18,55 +19,55 @@ public partial class MonsterRoom : DungeonRoom
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
SpawnItems();
|
||||
SpawnItems();
|
||||
}
|
||||
|
||||
public void SpawnEnemies(Godot.Collections.Dictionary<EnemyType, float> enemyInfo)
|
||||
public void SpawnEnemies(Array<EnemySpawnRate> spawnTable)
|
||||
{
|
||||
if (enemyInfo == null || !enemyInfo.Any(x => x.Value > 0))
|
||||
return;
|
||||
if (spawnTable.Count == 0)
|
||||
return;
|
||||
|
||||
var rng = new RandomNumberGenerator();
|
||||
rng.Randomize();
|
||||
var enemySpawnPoints = EnemySpawnPoints.GetChildren();
|
||||
var numberOfEnemiesToSpawn = rng.RandiRange(1, enemySpawnPoints.Count);
|
||||
var rng = new RandomNumberGenerator();
|
||||
rng.Randomize();
|
||||
var enemySpawnPoints = EnemySpawnPoints.GetChildren();
|
||||
var numberOfEnemiesToSpawn = rng.RandiRange(1, enemySpawnPoints.Count);
|
||||
|
||||
foreach (var spawnPoint in enemySpawnPoints.Cast<Marker3D>())
|
||||
{
|
||||
if (numberOfEnemiesToSpawn <= 0)
|
||||
break;
|
||||
numberOfEnemiesToSpawn--;
|
||||
foreach (var spawnPoint in enemySpawnPoints.Cast<Marker3D>())
|
||||
{
|
||||
if (numberOfEnemiesToSpawn <= 0)
|
||||
break;
|
||||
numberOfEnemiesToSpawn--;
|
||||
|
||||
var index = rng.RandWeighted([.. enemyInfo.Values]);
|
||||
var selectedEnemy = enemyInfo.ElementAt((int)index);
|
||||
var instantiatedEnemy = EnemyTypeToEnemyConverter.Convert(selectedEnemy.Key);
|
||||
AddChild(instantiatedEnemy);
|
||||
instantiatedEnemy.GlobalPosition = new Vector3(spawnPoint.GlobalPosition.X, 0f, spawnPoint.GlobalPosition.Z);
|
||||
ResetPhysicsInterpolation();
|
||||
}
|
||||
var index = rng.RandWeighted([.. spawnTable.Select(x => x.SpawnRate)]);
|
||||
var selectedEnemy = spawnTable.ElementAt((int)index);
|
||||
var instantiatedEnemy = EnemyTypeToEnemyConverter.Convert(selectedEnemy.EnemyType);
|
||||
AddChild(instantiatedEnemy);
|
||||
instantiatedEnemy.GlobalPosition = new Vector3(spawnPoint.GlobalPosition.X, 0f, spawnPoint.GlobalPosition.Z);
|
||||
ResetPhysicsInterpolation();
|
||||
}
|
||||
}
|
||||
|
||||
private void SpawnItems()
|
||||
{
|
||||
if (ItemSpawnPoints == null)
|
||||
return;
|
||||
if (ItemSpawnPoints == null)
|
||||
return;
|
||||
|
||||
var itemSpawnPoints = ItemSpawnPoints.GetChildren();
|
||||
var rng = new RandomNumberGenerator();
|
||||
rng.Randomize();
|
||||
var numberOfItemsToSpawn = rng.RandiRange(1, itemSpawnPoints.Count);
|
||||
itemSpawnPoints.Shuffle();
|
||||
var database = ItemDatabase.Instance;
|
||||
foreach (var spawnPoint in itemSpawnPoints.Cast<Marker3D>())
|
||||
{
|
||||
if (numberOfItemsToSpawn <= 0)
|
||||
break;
|
||||
numberOfItemsToSpawn--;
|
||||
var itemSpawnPoints = ItemSpawnPoints.GetChildren();
|
||||
var rng = new RandomNumberGenerator();
|
||||
rng.Randomize();
|
||||
var numberOfItemsToSpawn = rng.RandiRange(1, itemSpawnPoints.Count);
|
||||
itemSpawnPoints.Shuffle();
|
||||
var database = ItemDatabase.Instance;
|
||||
foreach (var spawnPoint in itemSpawnPoints.Cast<Marker3D>())
|
||||
{
|
||||
if (numberOfItemsToSpawn <= 0)
|
||||
break;
|
||||
numberOfItemsToSpawn--;
|
||||
|
||||
var selectedItem = database.PickItem<IBaseInventoryItem>() as Node3D;
|
||||
var duplicated = selectedItem.Duplicate((int)DuplicateFlags.UseInstantiation) as Node3D;
|
||||
AddChild(duplicated);
|
||||
duplicated.Position = new Vector3(spawnPoint.Position.X, 0, spawnPoint.Position.Z);
|
||||
}
|
||||
var selectedItem = database.PickItem<IBaseInventoryItem>() as Node3D;
|
||||
var duplicated = selectedItem.Duplicate((int)DuplicateFlags.UseInstantiation) as Node3D;
|
||||
AddChild(duplicated);
|
||||
duplicated.Position = new Vector3(spawnPoint.Position.X, 0, spawnPoint.Position.Z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,4 +21,6 @@ public partial class SpecialFloor : Node3D, IDungeonFloor
|
||||
public bool FloorIsLoaded { get; set; }
|
||||
|
||||
public virtual (Vector3 Rotation, Vector3 Position) GetPlayerSpawnPoint() => (PlayerSpawnPoint.Rotation, new Vector3(PlayerSpawnPoint.Position.X, 0, PlayerSpawnPoint.Position.Z));
|
||||
|
||||
public IDungeonRoom GetPlayersCurrentRoom() => null;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class FloorScene : Resource
|
||||
{
|
||||
[Export] public string FloorDisplayName { get; set; }
|
||||
|
||||
[Export] public FloorType FloorType { get; set; }
|
||||
|
||||
[Export] public Array<EnemySpawnRate> EnemySpawnTable { get; set; } = [];
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://bnxutyeas2ymm
|
||||
Reference in New Issue
Block a user