-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScoringScreen.cs
More file actions
167 lines (134 loc) · 3.94 KB
/
ScoringScreen.cs
File metadata and controls
167 lines (134 loc) · 3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
using System;
using System.Linq;
using Godot;
public partial class ScoringScreen : CanvasLayer
{
public static readonly string LoadPath = "res://Scenes/UI/ScoreScreen.tscn";
public struct ScoreGuide
{
public int BaseMoney = 0;
public int TotalHits = 0;
public int TotalPerfects = 0;
public int TotalPlaced = 0;
public int RelicBonus = 0;
public float StartingHealth = 0;
public float EndingHealth = 0;
public ScoreGuide(int baseMoney, float startingHealth)
{
BaseMoney = baseMoney;
StartingHealth = startingHealth;
}
public void IncreaseBase(int amount)
{
BaseMoney += amount;
}
public void IncHits()
{
TotalHits++;
}
public void IncPerfects()
{
TotalPerfects++;
}
public void IncPlaced()
{
TotalPlaced++;
}
public void IncRelicBonus(int amount)
{
RelicBonus += amount;
}
public void SetEndHp(float amount)
{
EndingHealth = amount;
}
}
[Export]
private Label _styleLabel;
[Export]
private Label _styleAmount;
[Export]
private Label _perfectsLabel;
[Export]
private Label _perfectsAmount;
[Export]
private Label _placedLabel;
[Export]
private Label _placedAmount;
[Export]
private Label _totalLabel;
[Export]
private Label _totalAmount;
[Export]
private Label _relicLabel;
[Export]
private Label _relicAmount;
[Export]
private Button _acceptButton;
private int _totalBaseMoney;
private float _perfectMulti;
private float _placedMulti;
private int _relicBonus;
private int FinalMoney => (int)(_totalBaseMoney * _perfectMulti * _placedMulti) + _relicBonus;
public delegate void FinishedHandler();
public event FinishedHandler Finished;
public override void _Ready()
{
_acceptButton.Pressed += FinishScoring;
}
public override void _Process(double delta)
{
_acceptButton.GrabFocus();
}
public static ScoringScreen CreateScore(Node2D parent, ScoreGuide info)
{
ScoringScreen result = GD.Load<PackedScene>(LoadPath).Instantiate<ScoringScreen>();
parent.AddChild(result);
result.GenerateScore(info);
parent.ProcessMode = ProcessModeEnum.Disabled;
return result;
}
private void GenerateScore(ScoreGuide info)
{
//Arbitrarily deciding on money calcs
_totalBaseMoney = CalcTotalBase(info);
//Multis
_perfectMulti = 1 + (float)info.TotalPerfects / (info.TotalHits - info.TotalPlaced);
if (float.IsNaN(_perfectMulti))
_perfectMulti = 1;
_placedMulti = Math.Max(2 - (float)Math.Abs(info.TotalPlaced - info.BaseMoney) / 10, 1);
_relicBonus = info.RelicBonus;
DrawScoreLabels();
}
private int CalcTotalBase(ScoreGuide info)
{
int result = info.BaseMoney;
result += (int)((info.EndingHealth / info.StartingHealth) * 10);
result += StageProducer.GlobalRng.RandiRange(0, 3);
return result;
}
private void DrawScoreLabels()
{
if (_relicBonus <= 0)
{
_relicLabel.Visible = false;
_relicAmount.Visible = false;
}
_styleAmount.Text = $"{_totalBaseMoney}";
_perfectsAmount.Text = $"X{_perfectMulti:0.00}";
_placedAmount.Text = $"X{_placedMulti:0.00}";
_relicAmount.Text = $"+{_relicBonus}";
_totalAmount.Text = $"{FinalMoney}";
}
private void FinishScoring()
{
StageProducer.PlayerStats.Money += FinalMoney;
//Achievement check for 1k money
if (StageProducer.PlayerStats.Money >= 1000)
{
SteamWhisperer.PopAchievement("money");
}
Finished?.Invoke();
QueueFree();
}
}