Skip to content

Commit 8403182

Browse files
authored
Merge pull request #49 from Project-Funk-Engine/RewardSystem
Reward system
2 parents 3de4c2d + 91eb416 commit 8403182

File tree

7 files changed

+208
-1
lines changed

7 files changed

+208
-1
lines changed

Globals/Scribe.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,19 @@ public partial class Scribe : Node
4545
),
4646
}
4747
),
48+
new RelicTemplate(
49+
"Dummy Item",
50+
new RelicEffect[]
51+
{
52+
new RelicEffect(
53+
BattleEffectTrigger.NotePlaced,
54+
100,
55+
(director, val) =>
56+
{
57+
director.Player.Heal(val);
58+
}
59+
),
60+
}
61+
),
4862
};
4963
}

Reward.cs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using System;
2+
using System.Linq;
3+
using Godot;
4+
5+
//it's very messy, feel free to clean up as much as necessary
6+
7+
public static class Reward
8+
{
9+
private static readonly Random _rng = new Random();
10+
11+
public static void GiveRandomRelic(PlayerStats player)
12+
{
13+
RelicTemplate newRelic = GetRandomRelic(player.CurRelics);
14+
15+
if (newRelic != null)
16+
{
17+
AddRelic(player, newRelic);
18+
GD.Print("Relic added: " + newRelic.Name);
19+
}
20+
else
21+
{
22+
GD.Print("No new relic to collect");
23+
}
24+
}
25+
26+
public static RelicTemplate GetRandomRelic(RelicTemplate[] ownedRelics)
27+
{
28+
var availableRelics = Scribe
29+
.RelicDictionary.Where(r => !ownedRelics.Any(o => o.Name == r.Name))
30+
.ToArray();
31+
32+
if (availableRelics.Length == 0)
33+
{
34+
return null; // No new relics available
35+
}
36+
37+
int index = _rng.Next(availableRelics.Length);
38+
return availableRelics[index].Clone();
39+
}
40+
41+
public static void AddRelic(PlayerStats player, RelicTemplate relic)
42+
{
43+
if (player.CurRelics.Any(r => r.Name == relic.Name))
44+
{
45+
GD.Print("Relic already in inventory: " + relic.Name);
46+
return;
47+
}
48+
player.CurRelics = player.CurRelics.Append(relic).ToArray();
49+
GD.Print("Adding relic: " + relic.Name);
50+
}
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+
}
66+
}

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: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ public partial class BattleDirector : Node2D
3232

3333
private SongData _curSong;
3434

35+
private bool battleLost = false;
36+
private bool battleWon = false;
37+
3538
#endregion
3639

3740
#region Note Handling
@@ -116,6 +119,12 @@ private void Begin()
116119

117120
public override void _Process(double delta)
118121
{
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
124+
if (!battleLost || !battleWon)
125+
{
126+
CheckBattleStatus();
127+
}
119128
TimeKeeper.CurrentTime = Audio.GetPlaybackPosition();
120129
CD.CheckMiss();
121130
}
@@ -125,6 +134,15 @@ public override void _Process(double delta)
125134

126135
public override void _UnhandledInput(InputEvent @event)
127136
{
137+
//this one is for calling a debug key to insta-kill the enemy
138+
if (@event is InputEventKey eventKey && eventKey.Pressed && !eventKey.Echo)
139+
{
140+
if (eventKey.Keycode == Key.Key0)
141+
{
142+
DebugKillEnemy();
143+
}
144+
}
145+
128146
if (@event.IsActionPressed("Pause"))
129147
{
130148
var pauseMenu = GD.Load<PackedScene>("res://scenes/UI/Pause.tscn");
@@ -209,4 +227,48 @@ private void EventizeRelics()
209227
}
210228
}
211229
#endregion
230+
231+
232+
private void CheckBattleStatus()
233+
{
234+
if (battleLost || battleWon)
235+
return;
236+
237+
if (Player.GetCurrentHealth() <= 0)
238+
{
239+
GD.Print("Player is Dead");
240+
battleLost = true;
241+
return;
242+
}
243+
244+
//will have to adjust this to account for when we have multiple enemies at once
245+
if (Enemy.GetCurrentHealth() <= 0)
246+
{
247+
GD.Print("Enemy is dead");
248+
battleWon = true;
249+
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+
258+
return;
259+
}
260+
}
261+
262+
private void DebugKillEnemy()
263+
{
264+
Enemy.TakeDamage(1000);
265+
}
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+
}
212274
}

scenes/Puppets/scripts/PlayerStats.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Linq;
23
using Godot;
34

45
public partial class PlayerStats : Resource

scenes/Puppets/scripts/PuppetTemplate.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,16 @@ public void Init(Texture2D texture, string name)
3636

3737
public void TakeDamage(int amount)
3838
{
39-
_healthBar.ChangeHP(-amount);
39+
_currentHealth = _healthBar.ChangeHP(-amount);
4040
}
4141

4242
public void Heal(int amount)
4343
{
4444
_healthBar.ChangeHP(amount);
4545
}
46+
47+
public int GetCurrentHealth()
48+
{
49+
return _currentHealth;
50+
}
4651
}

0 commit comments

Comments
 (0)