Skip to content

Commit 91eb416

Browse files
committed
Reward menu approach
New approach that allows for player to choose from a selection of relics after the battle is won
1 parent 1241600 commit 91eb416

4 files changed

Lines changed: 97 additions & 4 deletions

File tree

Reward.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
using System.Linq;
33
using Godot;
44

5+
//it's very messy, feel free to clean up as much as necessary
6+
57
public static class Reward
68
{
79
private static readonly Random _rng = new Random();
@@ -46,4 +48,19 @@ public static void AddRelic(PlayerStats player, RelicTemplate relic)
4648
player.CurRelics = player.CurRelics.Append(relic).ToArray();
4749
GD.Print("Adding relic: " + relic.Name);
4850
}
51+
52+
public static RelicTemplate[] GetMultipleRelics(RelicTemplate[] ownedRelics, int count)
53+
{
54+
var availableRelics = Scribe
55+
.RelicDictionary.Where(r => !ownedRelics.Any(o => o.Name == r.Name))
56+
.ToArray();
57+
if (availableRelics.Length == 0)
58+
return new RelicTemplate[0];
59+
60+
return availableRelics
61+
.OrderBy(_ => _rng.Next())
62+
.Take(count)
63+
.Select(r => r.Clone())
64+
.ToArray();
65+
}
4966
}

RewardSelect.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
using System.Linq;
3+
using Godot;
4+
5+
public partial class RewardSelect : CanvasLayer
6+
{
7+
[Export]
8+
public VBoxContainer ButtonContainer;
9+
10+
private PlayerStats _player;
11+
private RelicTemplate[] _choices;
12+
13+
public void Initialize(PlayerStats player)
14+
{
15+
_player = player;
16+
GenerateRelicChoices();
17+
}
18+
19+
private void GenerateRelicChoices()
20+
{
21+
//should probably change this so that the amount of relics offered can be changed when BD calls it
22+
//i.e less options when killing trash mobs/basic/weak enemies
23+
_choices = Reward.GetMultipleRelics(_player.CurRelics, 3);
24+
25+
foreach (var relic in _choices)
26+
{
27+
var button = new Button();
28+
button.Text = relic.Name;
29+
button.Pressed += () => OnRelicSelected(relic);
30+
ButtonContainer.AddChild(button);
31+
}
32+
}
33+
34+
private void OnRelicSelected(RelicTemplate choiceRelic)
35+
{
36+
Reward.AddRelic(_player, choiceRelic);
37+
GD.Print("Relic selected: " + choiceRelic.Name);
38+
39+
QueueFree();
40+
}
41+
}

RewardSelectionUI.tscn

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[gd_scene load_steps=2 format=3 uid="uid://c6icx2yriud6y"]
2+
3+
[ext_resource type="Script" path="res://RewardSelect.cs" id="1_ts2x3"]
4+
5+
[node name="CanvasLayer" type="CanvasLayer" node_paths=PackedStringArray("ButtonContainer")]
6+
script = ExtResource("1_ts2x3")
7+
ButtonContainer = NodePath("PanelContainer/VBoxContainer")
8+
9+
[node name="PanelContainer" type="PanelContainer" parent="."]
10+
offset_left = 34.0
11+
offset_top = 67.0
12+
offset_right = 600.0
13+
offset_bottom = 264.0
14+
15+
[node name="VBoxContainer" type="VBoxContainer" parent="PanelContainer"]
16+
layout_mode = 2
17+
18+
[node name="RewardSelect" type="Node2D" parent="."]

scenes/BattleDirector/scripts/BattleDirector.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,23 +119,25 @@ private void Begin()
119119

120120
public override void _Process(double delta)
121121
{
122+
//check if either one is dead until one is true, feel free to remove if we have a more efficent way of checking
123+
//alternatively, stop the other process since the battle is over
122124
if (!battleLost || !battleWon)
123125
{
124126
CheckBattleStatus();
125127
}
126128
TimeKeeper.CurrentTime = Audio.GetPlaybackPosition();
127129
CD.CheckMiss();
128-
//CheckBattleStatus();
129130
}
130131
#endregion
131132

132133
#region Input&Timing
133134

134135
public override void _UnhandledInput(InputEvent @event)
135136
{
137+
//this one is for calling a debug key to insta-kill the enemy
136138
if (@event is InputEventKey eventKey && eventKey.Pressed && !eventKey.Echo)
137139
{
138-
if (eventKey.Keycode == Key.Key0) // Adjust if you prefer a different key code.
140+
if (eventKey.Keycode == Key.Key0)
139141
{
140142
DebugKillEnemy();
141143
}
@@ -239,13 +241,20 @@ private void CheckBattleStatus()
239241
return;
240242
}
241243

244+
//will have to adjust this to account for when we have multiple enemies at once
242245
if (Enemy.GetCurrentHealth() <= 0)
243246
{
244247
GD.Print("Enemy is dead");
245248
battleWon = true;
246249

247-
Reward.GiveRandomRelic(Player.Stats);
248-
EventizeRelics(); //literally just here for debugging, ignore later
250+
//below, old method that just adds a random relic to the inventory
251+
//Reward.GiveRandomRelic(Player.Stats);
252+
//EventizeRelics(); //literally just here to force the ui to update and see if it was added, remove with the proper ui update
253+
//probably won't even need it since we'll be loading to seperate scene anyways
254+
255+
//new method that allows player to choose a relic
256+
ShowRewardSelection();
257+
249258
return;
250259
}
251260
}
@@ -254,4 +263,12 @@ private void DebugKillEnemy()
254263
{
255264
Enemy.TakeDamage(1000);
256265
}
266+
267+
private void ShowRewardSelection()
268+
{
269+
var rewardUI = GD.Load<PackedScene>("res://RewardSelectionUI.tscn")
270+
.Instantiate<RewardSelect>();
271+
AddChild(rewardUI);
272+
rewardUI.Initialize(Player.Stats);
273+
}
257274
}

0 commit comments

Comments
 (0)