summaryrefslogtreecommitdiff
path: root/scripts/map/DungeonGenerator.cs
diff options
context:
space:
mode:
authorMatheus <matheus.guedes.mg.m@gmail.com>2025-09-04 18:31:40 -0300
committerMatheus <matheus.guedes.mg.m@gmail.com>2025-09-04 18:31:40 -0300
commit1e248d3dd18f7c6bfaf8066c4662facbbb89e8f9 (patch)
tree8250335d5ad8176da05f7243052b9af85802c7ed /scripts/map/DungeonGenerator.cs
parent147bb12b5d48c5432aa1bd1cbe60b8435294445b (diff)
Itens na masmorra
Diffstat (limited to 'scripts/map/DungeonGenerator.cs')
-rw-r--r--scripts/map/DungeonGenerator.cs45
1 files changed, 42 insertions, 3 deletions
diff --git a/scripts/map/DungeonGenerator.cs b/scripts/map/DungeonGenerator.cs
index f016dd2..cb89508 100644
--- a/scripts/map/DungeonGenerator.cs
+++ b/scripts/map/DungeonGenerator.cs
@@ -12,12 +12,16 @@ public partial class DungeonGenerator : Node
private static readonly Godot.Collections.Array<EnemyDefinition> enemies = [
GD.Load<EnemyDefinition>("res://assets/definitions/actor/Skeleton.tres"),
GD.Load<EnemyDefinition>("res://assets/definitions/actor/morcegao.tres"),
- GD.Load<EnemyDefinition>("res://assets/definitions/actor/Shadow.tres")
+ GD.Load<EnemyDefinition>("res://assets/definitions/actor/Shadow.tres"),
+ ];
+
+ private static readonly Godot.Collections.Array<ConsumableItemDefinition> items = [
+ GD.Load<HealingConsumableDefinition>("res://assets/definitions/Items/small_healing_potion.tres")
];
/// <summary>
- /// Dimensões do mapa a ser criado.
- /// </summary>
+ /// Dimensões do mapa a ser criado.
+ /// </summary>
[ExportCategory("Dimension")]
[Export]
private int width = 80;
@@ -52,6 +56,13 @@ public partial class DungeonGenerator : Node
[Export]
private int maxMonsterPerRoom = 2;
+ /// <summary>
+ /// Quantidade máxima de itens por sala.
+ /// </summary>
+ [ExportCategory("Loot RNG")]
+ [Export]
+ private int maxItemsPerRoom = 2;
+
public override void _Ready()
{
base._Ready();
@@ -149,6 +160,8 @@ public partial class DungeonGenerator : Node
private void PlaceEntities(MapData data, Rect2I room) {
// Define quantos monstros serão colocados na sala
int monsterAmount = rng.RandiRange(0, maxMonsterPerRoom);
+ // Define quantos itens serão colocados na sala.
+ int itemAmount = rng.RandiRange(0, maxItemsPerRoom);
for (int i = 0; i < monsterAmount; i++) {
// Escolhe um lugar aleatório na sala.
@@ -173,6 +186,32 @@ public partial class DungeonGenerator : Node
data.InsertEntity(enemy);
}
}
+
+ for (int i = 0; i < itemAmount; i++) {
+ // Escolhe um lugar aleatório na sala.
+ Vector2I position = new(
+ rng.RandiRange(room.Position.X, room.End.X - 1),
+ rng.RandiRange(room.Position.Y, room.End.Y - 1)
+ );
+
+ // Só podemos colocar um ator por ponto no espaço.
+ bool canPlace = true;
+ foreach (Entity entity in data.Entities) {
+ if (entity.GridPosition == position) {
+ canPlace = false;
+ break;
+ }
+ }
+
+ // Se possível, criamos um inimigo aleatório na posição escolhida.
+ if (canPlace) {
+ ConsumableItemDefinition definition = items.PickRandom();
+ if (definition is HealingConsumableDefinition hcDefinition) {
+ HealingConsumable item = new(position, data, hcDefinition);
+ data.InsertEntity(item);
+ }
+ }
+ }
}
/// <summary>