New maps and chests

This commit is contained in:
Marco 2025-04-29 12:12:47 +02:00
commit 26a0f51168
28 changed files with 645 additions and 233 deletions

View file

@ -0,0 +1,31 @@
using Godot;
namespace Cirno.Scripts.Actors;
[Tool]
public partial class ChestMarker : FeatureMarker
{
private Texture2D _markerTexture;
[Export]
public Texture2D MarkerTexture
{
get => _markerTexture;
set
{
_markerTexture = value;
if (Engine.IsEditorHint())
{
QueueRedraw();
}
}
}
public override void _Draw()
{
if (!Engine.IsEditorHint()) return;
if (MarkerTexture is null) return;
DrawTexture(MarkerTexture, -new Vector2(MarkerTexture.GetWidth() / 2f, MarkerTexture.GetHeight() / 2f));
}
}

View file

@ -0,0 +1 @@
uid://umyqgyxjiaig

View file

@ -0,0 +1,12 @@
using Godot;
namespace Cirno.Scripts.Actors;
[Tool]
public partial class FeatureMarker : Marker2D
{
[Export] public bool OverrideChance { get; set; } = false;
[Export(PropertyHint.None, "suffix:%")]
public double SpawnChance { get; set; } = 15d;
}

View file

@ -0,0 +1 @@
uid://cutqpv1k3bt2h

View file

@ -13,6 +13,7 @@ using Cirno.Scripts.Resources.Roguelite;
using Cirno.Scripts.Utils;
using Godot;
using Godot.Collections;
using Array = Godot.Collections.Array;
namespace Cirno.Scripts.Controllers;
@ -20,6 +21,8 @@ namespace Cirno.Scripts.Controllers;
public partial class RogueliteRoom : Node2D
{
[Export] public RogueliteRoomResource RoomResource { get; set; }
[Export] public Array<Node2D> RoomClearActivation { get; set; }
public RogueliteMapTheme MapTheme { get; set; }
@ -32,6 +35,8 @@ public partial class RogueliteRoom : Node2D
public Vector2 RoomSize => BaseRoomSize * RoomResource.Size;
[Signal] public delegate void RoomClearedEventHandler();
public Vector2I RandomBottomExit()
{
return BottomLeft + new Vector2I(GD.RandRange(0, RoomResource.Size.X - 1), 0);
@ -324,15 +329,27 @@ public partial class RogueliteRoom : Node2D
continue;
}
double chance = GD.RandRange(0d, 100d);
if (chance <= MapTheme.ChestChance)
if (markerNode is ChestMarker chestMarker)
{
var chest = marker.CreateChild<Chest>(MapTheme.ChestPrefab);
var loot = MapTheme.ChestLootTable.Items.ToList().Shuffle().First();
chest.LootTable.Add(loot);
double roll = GD.RandRange(0d, 100d);
double chance = chestMarker.OverrideChance ? chestMarker.SpawnChance : MapTheme.ChestChance;
if (roll <= chance)
{
var hasLoot = MapTheme.ChestLootQueue.TryDequeue(out var loot);
if (!hasLoot)
{
GD.Print("Ran out of loot to spawn");
return;
}
var chest = marker.CreateChild<Chest>(MapTheme.ChestPrefab);
chest.LootTable.Add(loot);
}
}
}
}
@ -344,6 +361,7 @@ public partial class RogueliteRoom : Node2D
if (_enemies.Count == 0)
{
OpenDoors();
EmitSignalRoomCleared();
}
}

View file

@ -121,6 +121,8 @@ public partial class RogueliteRoomManager : Node2D
var shuffledOffshoots = offshoots.Shuffle().ToList();
MapTheme.MakeChestLootQueue();
// var offshootsQueue = new Queue<RoomType>();
// offshootsQueue.EnqueueRange(shuffledOffshoots);

View file

@ -1,6 +1,9 @@
using Cirno.Scripts.Activables;
using System.Collections.Generic;
using System.Linq;
using Cirno.Scripts.Activables;
using Cirno.Scripts.Resources.Loot;
using Cirno.Scripts.Resources.Roguelite;
using Cirno.Scripts.Utils;
using Godot;
using Godot.Collections;
@ -39,4 +42,15 @@ public partial class RogueliteMapTheme : Resource
[ExportCategory("Rooms")]
[Export] public Array<RogueliteRoomResource> Rooms { get; set; }
[ExportCategory("Loot Counts")] public int MaxChestLoot { get; set; } = 100;
public Queue<LootItem> ChestLootQueue { get; private set; }
public Queue<LootItem> MakeChestLootQueue()
{
ChestLootQueue = new Queue<LootItem>().EnqueueRange(ChestLootTable.Items.ToList().Shuffle(MaxChestLoot));
return ChestLootQueue;
}
}