Skip to content

Commit 1241600

Browse files
committed
Rough version of reward
made a static rewards class that should assign a new relic, made minor changes to battle director to check health of puppets and change the apporpiate bool when they die, added a debug function to instantly kill the enemy to make testing the reward drop easier, added dummy relic
1 parent 3de4c2d commit 1241600

5 files changed

Lines changed: 115 additions & 1 deletion

File tree

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

scenes/BattleDirector/scripts/BattleDirector.cs

Lines changed: 45 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,15 +119,28 @@ private void Begin()
116119

117120
public override void _Process(double delta)
118121
{
122+
if (!battleLost || !battleWon)
123+
{
124+
CheckBattleStatus();
125+
}
119126
TimeKeeper.CurrentTime = Audio.GetPlaybackPosition();
120127
CD.CheckMiss();
128+
//CheckBattleStatus();
121129
}
122130
#endregion
123131

124132
#region Input&Timing
125133

126134
public override void _UnhandledInput(InputEvent @event)
127135
{
136+
if (@event is InputEventKey eventKey && eventKey.Pressed && !eventKey.Echo)
137+
{
138+
if (eventKey.Keycode == Key.Key0) // Adjust if you prefer a different key code.
139+
{
140+
DebugKillEnemy();
141+
}
142+
}
143+
128144
if (@event.IsActionPressed("Pause"))
129145
{
130146
var pauseMenu = GD.Load<PackedScene>("res://scenes/UI/Pause.tscn");
@@ -209,4 +225,33 @@ private void EventizeRelics()
209225
}
210226
}
211227
#endregion
228+
229+
230+
private void CheckBattleStatus()
231+
{
232+
if (battleLost || battleWon)
233+
return;
234+
235+
if (Player.GetCurrentHealth() <= 0)
236+
{
237+
GD.Print("Player is Dead");
238+
battleLost = true;
239+
return;
240+
}
241+
242+
if (Enemy.GetCurrentHealth() <= 0)
243+
{
244+
GD.Print("Enemy is dead");
245+
battleWon = true;
246+
247+
Reward.GiveRandomRelic(Player.Stats);
248+
EventizeRelics(); //literally just here for debugging, ignore later
249+
return;
250+
}
251+
}
252+
253+
private void DebugKillEnemy()
254+
{
255+
Enemy.TakeDamage(1000);
256+
}
212257
}

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)