-
Notifications
You must be signed in to change notification settings - Fork 0
Reward system #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Reward system #49
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| using System; | ||
| using System.Linq; | ||
| using Godot; | ||
|
|
||
| //it's very messy, feel free to clean up as much as necessary | ||
|
|
||
| public static class Reward | ||
| { | ||
| private static readonly Random _rng = new Random(); | ||
|
|
||
| public static void GiveRandomRelic(PlayerStats player) | ||
| { | ||
| RelicTemplate newRelic = GetRandomRelic(player.CurRelics); | ||
|
|
||
| if (newRelic != null) | ||
| { | ||
| AddRelic(player, newRelic); | ||
| GD.Print("Relic added: " + newRelic.Name); | ||
| } | ||
| else | ||
| { | ||
| GD.Print("No new relic to collect"); | ||
| } | ||
| } | ||
|
|
||
| public static RelicTemplate GetRandomRelic(RelicTemplate[] ownedRelics) | ||
| { | ||
| var availableRelics = Scribe | ||
| .RelicDictionary.Where(r => !ownedRelics.Any(o => o.Name == r.Name)) | ||
| .ToArray(); | ||
|
|
||
| if (availableRelics.Length == 0) | ||
| { | ||
| return null; // No new relics available | ||
| } | ||
|
|
||
| int index = _rng.Next(availableRelics.Length); | ||
| return availableRelics[index].Clone(); | ||
| } | ||
|
|
||
| public static void AddRelic(PlayerStats player, RelicTemplate relic) | ||
| { | ||
| if (player.CurRelics.Any(r => r.Name == relic.Name)) | ||
| { | ||
| GD.Print("Relic already in inventory: " + relic.Name); | ||
| return; | ||
| } | ||
| player.CurRelics = player.CurRelics.Append(relic).ToArray(); | ||
| GD.Print("Adding relic: " + relic.Name); | ||
| } | ||
|
|
||
| public static RelicTemplate[] GetMultipleRelics(RelicTemplate[] ownedRelics, int count) | ||
| { | ||
| var availableRelics = Scribe | ||
| .RelicDictionary.Where(r => !ownedRelics.Any(o => o.Name == r.Name)) | ||
| .ToArray(); | ||
| if (availableRelics.Length == 0) | ||
| return new RelicTemplate[0]; | ||
|
|
||
| return availableRelics | ||
| .OrderBy(_ => _rng.Next()) | ||
| .Take(count) | ||
| .Select(r => r.Clone()) | ||
| .ToArray(); | ||
| } | ||
| } |
LifeHckr marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| using System; | ||
| using System.Linq; | ||
| using Godot; | ||
|
|
||
| public partial class RewardSelect : CanvasLayer | ||
| { | ||
| [Export] | ||
| public VBoxContainer ButtonContainer; | ||
|
|
||
| private PlayerStats _player; | ||
| private RelicTemplate[] _choices; | ||
|
|
||
| public void Initialize(PlayerStats player) | ||
| { | ||
| _player = player; | ||
| GenerateRelicChoices(); | ||
| } | ||
|
|
||
| private void GenerateRelicChoices() | ||
| { | ||
| //should probably change this so that the amount of relics offered can be changed when BD calls it | ||
| //i.e less options when killing trash mobs/basic/weak enemies | ||
| _choices = Reward.GetMultipleRelics(_player.CurRelics, 3); | ||
|
|
||
| foreach (var relic in _choices) | ||
| { | ||
| var button = new Button(); | ||
| button.Text = relic.Name; | ||
| button.Pressed += () => OnRelicSelected(relic); | ||
| ButtonContainer.AddChild(button); | ||
| } | ||
| } | ||
|
|
||
| private void OnRelicSelected(RelicTemplate choiceRelic) | ||
| { | ||
| Reward.AddRelic(_player, choiceRelic); | ||
| GD.Print("Relic selected: " + choiceRelic.Name); | ||
|
|
||
| QueueFree(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| [gd_scene load_steps=2 format=3 uid="uid://c6icx2yriud6y"] | ||
|
|
||
| [ext_resource type="Script" path="res://RewardSelect.cs" id="1_ts2x3"] | ||
|
|
||
| [node name="CanvasLayer" type="CanvasLayer" node_paths=PackedStringArray("ButtonContainer")] | ||
| script = ExtResource("1_ts2x3") | ||
| ButtonContainer = NodePath("PanelContainer/VBoxContainer") | ||
|
|
||
| [node name="PanelContainer" type="PanelContainer" parent="."] | ||
| offset_left = 34.0 | ||
| offset_top = 67.0 | ||
| offset_right = 600.0 | ||
| offset_bottom = 264.0 | ||
|
|
||
| [node name="VBoxContainer" type="VBoxContainer" parent="PanelContainer"] | ||
| layout_mode = 2 | ||
|
|
||
| [node name="RewardSelect" type="Node2D" parent="."] |
LifeHckr marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| using System; | ||
| using System.Linq; | ||
| using Godot; | ||
|
|
||
| public partial class PlayerStats : Resource | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.