|
| 1 | +using System; |
| 2 | +using Godot; |
| 3 | + |
| 4 | +/// <summary> |
| 5 | +/// Holds all game events and their associated logic. |
| 6 | +/// </summary> |
| 7 | +public class EventDatabase |
| 8 | +{ |
| 9 | + public static readonly EventTemplate[] EventDictionary = new[] |
| 10 | + { |
| 11 | + new EventTemplate( |
| 12 | + 1, |
| 13 | + "EVENT_EVENT1_DESC", |
| 14 | + ["EVENT_EVENT1_OPTION1", "EVENT_EVENT1_OPTION2", "EVENT_EVENT1_OPTION3"], |
| 15 | + ["EVENT_EVENT1_OUTCOME1", "EVENT_EVENT1_OUTCOME2", "EVENT_EVENT1_OUTCOME3"], |
| 16 | + [ |
| 17 | + (self, node) => |
| 18 | + { |
| 19 | + int randIndex = StageProducer.GlobalRng.RandiRange( |
| 20 | + 0, |
| 21 | + StageProducer.PlayerStats.CurNotes.Length - 1 |
| 22 | + ); |
| 23 | + StageProducer.PlayerStats.RemoveNote(randIndex); |
| 24 | + }, |
| 25 | + (self, node) => |
| 26 | + { |
| 27 | + int randIndex = StageProducer.GlobalRng.RandiRange( |
| 28 | + 0, |
| 29 | + StageProducer.PlayerStats.CurRelics.Length - 1 |
| 30 | + ); |
| 31 | + StageProducer.PlayerStats.RemoveRelic(randIndex); |
| 32 | + }, |
| 33 | + (self, node) => |
| 34 | + { |
| 35 | + StageProducer.PlayerStats.Money /= 2; |
| 36 | + }, |
| 37 | + ], |
| 38 | + GD.Load<Texture2D>("res://Classes/Events/Assets/Event1.png"), |
| 39 | + [ |
| 40 | + () => StageProducer.PlayerStats.CurNotes.Length > 0, |
| 41 | + () => StageProducer.PlayerStats.CurRelics.Length > 0, |
| 42 | + () => StageProducer.PlayerStats.Money > 0, |
| 43 | + ] |
| 44 | + ), |
| 45 | + new EventTemplate( |
| 46 | + 1, |
| 47 | + "EVENT_EVENT2_DESC", |
| 48 | + ["EVENT_EVENT2_OPTION1", "EVENT_EVENT2_OPTION2"], |
| 49 | + ["", "EVENT_EVENT2_OUTCOME1"], |
| 50 | + [ |
| 51 | + (self, node) => |
| 52 | + { |
| 53 | + var spinner = node.EventSprite; |
| 54 | + int spinOutcome = StageProducer.GlobalRng.RandiRange(0, 5); |
| 55 | + |
| 56 | + int outcomeCount = 6; |
| 57 | + float sectorAngle = 360f / outcomeCount; |
| 58 | + float targetAngle = spinOutcome * sectorAngle; |
| 59 | + float fullSpins = 6 * 360f; |
| 60 | + float finalRotation = spinner.RotationDegrees % 360f + fullSpins + targetAngle; |
| 61 | + |
| 62 | + var tween = node.CreateTween(); |
| 63 | + tween |
| 64 | + .TweenProperty(spinner, "rotation_degrees", finalRotation, 2.5f) |
| 65 | + .SetTrans(Tween.TransitionType.Cubic) |
| 66 | + .SetEase(Tween.EaseType.Out); |
| 67 | + |
| 68 | + // Defer execution of the outcome until the tween finishes |
| 69 | + tween.TweenCallback( |
| 70 | + Callable.From(() => |
| 71 | + { |
| 72 | + switch (spinOutcome) |
| 73 | + { |
| 74 | + case 0: |
| 75 | + StageProducer.PlayerStats.Money /= 2; |
| 76 | + self.OutcomeDescriptions[0] = "EVENT_EVENT2_OUTCOME2"; |
| 77 | + break; |
| 78 | + case 1: |
| 79 | + self.OutcomeDescriptions[0] = "EVENT_EVENT2_OUTCOME3"; |
| 80 | + StageProducer.PlayerStats.CurrentHealth = Math.Max( |
| 81 | + 1, |
| 82 | + StageProducer.PlayerStats.CurrentHealth - 10 |
| 83 | + ); |
| 84 | + break; |
| 85 | + case 2: |
| 86 | + self.OutcomeDescriptions[0] = "EVENT_EVENT2_OUTCOME4"; |
| 87 | + StageProducer.PlayerStats.Money += 50; |
| 88 | + break; |
| 89 | + case 3: |
| 90 | + self.OutcomeDescriptions[0] = "EVENT_EVENT2_OUTCOME5"; |
| 91 | + StageProducer.PlayerStats.AddNote( |
| 92 | + Scribe.GetRandomRewardNotes(1, StageProducer.CurRoom + 10)[ |
| 93 | + 0 |
| 94 | + ] |
| 95 | + ); |
| 96 | + break; |
| 97 | + case 4: |
| 98 | + self.OutcomeDescriptions[0] = "EVENT_EVENT2_OUTCOME6"; |
| 99 | + StageProducer.PlayerStats.AddRelic( |
| 100 | + Scribe.GetRandomRelics( |
| 101 | + 1, |
| 102 | + StageProducer.CurRoom + 10, |
| 103 | + StageProducer.PlayerStats.RarityOdds |
| 104 | + )[0] |
| 105 | + ); |
| 106 | + break; |
| 107 | + case 5: |
| 108 | + self.OutcomeDescriptions[0] = "EVENT_EVENT2_OUTCOME7"; |
| 109 | + StageProducer.PlayerStats.CurrentHealth = Math.Min( |
| 110 | + StageProducer.PlayerStats.CurrentHealth + 20, |
| 111 | + StageProducer.PlayerStats.MaxHealth |
| 112 | + ); |
| 113 | + break; |
| 114 | + } |
| 115 | + node.AnyButtonPressed(0); |
| 116 | + self.OutcomeDescriptions[0] = ""; //Will need to fix later, currently changes the primary reference |
| 117 | + }) |
| 118 | + ); |
| 119 | + }, |
| 120 | + null, |
| 121 | + ], |
| 122 | + GD.Load<Texture2D>("res://Classes/Events/Assets/Event2.png"), |
| 123 | + [null, null] |
| 124 | + ), |
| 125 | + new EventTemplate( |
| 126 | + 2, |
| 127 | + "EVENT_EVENT3_DESC", |
| 128 | + ["EVENT_EVENT3_OPTION1", "EVENT_EVENT3_OPTION2", "EVENT_EVENT3_OPTION3"], |
| 129 | + ["EVENT_EVENT3_OUTCOME1", "EVENT_EVENT3_OUTCOME2", "EVENT_EVENT3_OUTCOME3"], |
| 130 | + [ |
| 131 | + (self, node) => |
| 132 | + { |
| 133 | + StageProducer.PlayerStats.CurrentHealth = Math.Min( |
| 134 | + StageProducer.PlayerStats.CurrentHealth + 10, |
| 135 | + StageProducer.PlayerStats.MaxHealth |
| 136 | + ); |
| 137 | + }, |
| 138 | + (self, node) => |
| 139 | + { |
| 140 | + StageProducer.PlayerStats.MaxComboBar -= 5; |
| 141 | + }, |
| 142 | + (self, node) => |
| 143 | + { |
| 144 | + StageProducer.PlayerStats.Money -= 30; |
| 145 | + StageProducer.PlayerStats.AddNote(Scribe.NoteDictionary[3]); |
| 146 | + StageProducer.PlayerStats.AddNote(Scribe.NoteDictionary[3]); |
| 147 | + }, |
| 148 | + ], |
| 149 | + GD.Load<Texture2D>("res://Classes/Events/Assets/Event3.png"), |
| 150 | + [null, null, () => StageProducer.PlayerStats.Money >= 30] |
| 151 | + ), |
| 152 | + }; |
| 153 | +} |
0 commit comments