Skip to content

Commit ff1983a

Browse files
committed
Tweaked Events and Normal Battles selection
Events and normal battles are pooled, so neither repeat until the pool has been exhausted. Added event pool and battle pool to save file.
1 parent d877edc commit ff1983a

4 files changed

Lines changed: 59 additions & 12 deletions

File tree

Classes/Events/EventDatabase.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
/// </summary>
77
public class EventDatabase
88
{
9+
public const int EventDatabaseSize = 3;
10+
911
public static readonly EventTemplate[] EventDictionary = new[]
1012
{
1113
new EventTemplate(

Globals/SaveSystem.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,8 @@ public class SaveFile
384384
public int Money { get; init; }
385385
public int[] NoteIds { get; init; }
386386
public int[] RelicIds { get; init; }
387+
public int[] BattlePool { get; init; }
388+
public int[] EventPool { get; init; }
387389
public int PlayerHealth { get; init; }
388390
public int Shortcuts { get; init; }
389391
public int PlayerMaxCombo { get; init; }
@@ -394,6 +396,8 @@ public SaveFile(
394396
int lastRoomIdx,
395397
int[] noteIds,
396398
int[] relicIds,
399+
int[] battlePool,
400+
int[] eventPool,
397401
int playerHealth,
398402
int area,
399403
int money,
@@ -406,6 +410,8 @@ int playerMaxCombo
406410
LastRoomIdx = lastRoomIdx;
407411
NoteIds = noteIds;
408412
RelicIds = relicIds;
413+
BattlePool = battlePool ?? [];
414+
EventPool = eventPool ?? [];
409415
PlayerHealth = playerHealth;
410416
Area = area;
411417
Money = money;
@@ -424,6 +430,8 @@ public static void SaveGame()
424430
StageProducer.CurRoom,
425431
noteIds,
426432
relicIds,
433+
StageProducer.BattlePool?.ToArray(),
434+
EventScene.EventPool?.ToArray(),
427435
StageProducer.PlayerStats.CurrentHealth,
428436
StageProducer.CurLevel.Id,
429437
StageProducer.PlayerStats.Money,

Globals/StageProducer.cs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
13
using System.Threading.Tasks;
24
using FunkEngine;
35
using Godot;
4-
using GodotSteam;
56

67
/**
78
* <summary>StageProducer: Handles scene transitions and persistent gameplay data.</summary>
@@ -14,6 +15,7 @@ public partial class StageProducer : Node
1415
public static readonly RandomNumberGenerator GlobalRng = new();
1516

1617
public static MapLevels CurLevel { get; private set; }
18+
public static List<int> BattlePool { get; private set; }
1719

1820
public static MapGrid Map { get; private set; } = new();
1921
private Stages _curStage = Stages.Title;
@@ -70,6 +72,8 @@ private void StartNewGame()
7072
PlayerStats = new PlayerStats();
7173

7274
CurRoom = Map.GetRooms()[0].Idx;
75+
BattlePool = null;
76+
EventScene.EventPool = null;
7377
Scribe.InitRelicPools();
7478
IsInitialized = true;
7579
}
@@ -84,6 +88,8 @@ private bool LoadGame()
8488
}
8589
GlobalRng.Seed = sv.RngSeed;
8690
CurLevel = MapLevels.GetLevelFromId(sv.Area);
91+
BattlePool = sv.BattlePool.ToList();
92+
EventScene.EventPool = sv.EventPool.ToList();
8793
GenerateMapConsistent();
8894
GlobalRng.State = sv.RngState;
8995
CurRoom = sv.LastRoomIdx;
@@ -216,6 +222,16 @@ public void TransitionStage(Stages nextStage, int nextRoomIdx = -1)
216222
}
217223
#endregion
218224

225+
private void RefreshBattlePool()
226+
{
227+
BattlePool = new List<int>(CurLevel.NormalBattles);
228+
for (int i = 0; i < BattlePool.Count - 2; i++)
229+
{
230+
int randIdx = GlobalRng.RandiRange(0, CurLevel.NormalBattles.Length - 1);
231+
(BattlePool[i], BattlePool[randIdx]) = (BattlePool[randIdx], BattlePool[i]); //rad
232+
}
233+
}
234+
219235
private BattleConfig MakeBattleConfig(Stages nextRoom, int nextRoomIdx)
220236
{
221237
BattleConfig result = new BattleConfig
@@ -228,11 +244,12 @@ private BattleConfig MakeBattleConfig(Stages nextRoom, int nextRoomIdx)
228244
switch (nextRoom)
229245
{
230246
case Stages.Battle:
231-
int songIdx = stageRng.RandiRange(0, CurLevel.NormalBattles.Length - 1);
232-
result.CurSong = Scribe.SongDictionary[CurLevel.NormalBattles[songIdx]];
233-
result.EnemyScenePath = Scribe
234-
.SongDictionary[CurLevel.NormalBattles[songIdx]]
235-
.EnemyScenePath;
247+
if (BattlePool == null || BattlePool.Count == 0)
248+
RefreshBattlePool();
249+
int songIdx = stageRng.RandiRange(0, BattlePool.Count - 1);
250+
result.CurSong = Scribe.SongDictionary[BattlePool[songIdx]];
251+
result.EnemyScenePath = Scribe.SongDictionary[BattlePool[songIdx]].EnemyScenePath;
252+
BattlePool.RemoveAt(songIdx);
236253
break;
237254
case Stages.Elite:
238255
int elitIdx = stageRng.RandiRange(0, CurLevel.EliteBattles.Length - 1);
@@ -291,6 +308,7 @@ public void ProgressLevels()
291308
Map = new();
292309
GenerateMapConsistent();
293310
CurRoom = Map.GetRooms()[0].Idx;
311+
BattlePool = null;
294312
}
295313

296314
#endregion

Scenes/EventScene/EventScene.cs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using FunkEngine;
34
using Godot;
45

@@ -25,6 +26,8 @@ public partial class EventScene : Node
2526
[Export]
2627
private MarginContainer _continueContainer;
2728

29+
public static List<int> EventPool;
30+
2831
private static readonly Theme ButtonTheme = GD.Load<Theme>(
2932
"res://Scenes/UI/Assets/GeneralTheme.tres"
3033
); // Store the theme
@@ -34,15 +37,18 @@ public partial class EventScene : Node
3437

3538
public override void _Ready()
3639
{
37-
GD.Print("loaded event");
3840
_player = GD.Load<PackedScene>(PlayerPuppet.LoadPath).Instantiate<PlayerPuppet>();
3941
PlayerMarker.AddChild(_player);
4042

41-
int eventIndex = StageProducer.GlobalRng.RandiRange(
42-
0,
43-
EventDatabase.EventDictionary.Length - 1
44-
);
43+
if (EventPool == null || EventPool.Count == 0)
44+
RefreshPool();
45+
46+
RandomNumberGenerator stageRng = new RandomNumberGenerator();
47+
stageRng.SetSeed(StageProducer.GlobalRng.Seed + (ulong)StageProducer.Config.BattleRoom.Idx);
48+
int eventIndex = stageRng.RandiRange(0, EventPool.Count - 1);
4549
_eventReference = EventDatabase.EventDictionary[eventIndex];
50+
51+
EventPool.RemoveAt(eventIndex);
4652
DisplayEvent();
4753
}
4854

@@ -57,6 +63,20 @@ public override void _Process(double delta)
5763
}
5864
}
5965

66+
private void RefreshPool()
67+
{
68+
EventPool = new List<int>();
69+
for (int i = 0; i < EventDatabase.EventDatabaseSize; i++)
70+
{
71+
EventPool.Add(i);
72+
}
73+
for (int i = 0; i < EventPool.Count - 2; i++)
74+
{
75+
int randIdx = StageProducer.GlobalRng.RandiRange(0, EventPool.Count - 1);
76+
(EventPool[i], EventPool[randIdx]) = (EventPool[randIdx], EventPool[i]); //rad
77+
}
78+
}
79+
6080
/// <summary>
6181
/// Displays the set event.
6282
/// </summary>
@@ -95,7 +115,6 @@ public void DisplayEvent()
95115
int capturedIndex = i;
96116
button.Pressed += () =>
97117
{
98-
GD.Print($"Selected option: {_eventReference.ButtonDescriptions[capturedIndex]}");
99118
_eventReference.OptionActions[capturedIndex]?.Invoke(_eventReference, this);
100119
AnyButtonPressed(capturedIndex);
101120
};

0 commit comments

Comments
 (0)