mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-09 07:55:54 +00:00
New maps and chests
This commit is contained in:
parent
7c7588c1a4
commit
26a0f51168
28 changed files with 645 additions and 233 deletions
31
Scripts/Actors/ChestMarker.cs
Normal file
31
Scripts/Actors/ChestMarker.cs
Normal 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));
|
||||
}
|
||||
}
|
||||
1
Scripts/Actors/ChestMarker.cs.uid
Normal file
1
Scripts/Actors/ChestMarker.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://umyqgyxjiaig
|
||||
12
Scripts/Actors/FeatureMarker.cs
Normal file
12
Scripts/Actors/FeatureMarker.cs
Normal 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;
|
||||
}
|
||||
1
Scripts/Actors/FeatureMarker.cs.uid
Normal file
1
Scripts/Actors/FeatureMarker.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cutqpv1k3bt2h
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -121,6 +121,8 @@ public partial class RogueliteRoomManager : Node2D
|
|||
|
||||
var shuffledOffshoots = offshoots.Shuffle().ToList();
|
||||
|
||||
MapTheme.MakeChestLootQueue();
|
||||
|
||||
// var offshootsQueue = new Queue<RoomType>();
|
||||
// offshootsQueue.EnqueueRange(shuffledOffshoots);
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue