-
Notifications
You must be signed in to change notification settings - Fork 0
/
PayoutCalculator.cs
255 lines (216 loc) · 8 KB
/
PayoutCalculator.cs
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PayoutCalculator : MonoBehaviour
{
private GameState gameState;
private SpinGenerator spinGenerator;
private PaylinePathGenerator paylinePathGenerator;
private List<string> payoutTallies;
private Dictionary<Symbol, List<List<Vector2>>> matchedPaylinesAnySize;
private Dictionary<Symbol, List<List<Vector2>>> matchedPaylinesSize5;
private Dictionary<Symbol, List<List<Vector2>>> matchedPaylinesSize4;
private Dictionary<Symbol, List<List<Vector2>>> matchedPaylinesSize3;
private Player player;
private void Awake()
{
gameState = GameObject.FindGameObjectWithTag("Game State").GetComponent<GameState>();
spinGenerator = GameObject.FindGameObjectWithTag("Spin Generator").GetComponent<SpinGenerator>();
paylinePathGenerator = GameObject.FindGameObjectWithTag("Payline Path Generator").GetComponent<PaylinePathGenerator>();
player = GameObject.FindGameObjectWithTag("Player").GetComponent<Player>();
Reset();
}
public void Reset()
{
payoutTallies = new List<string>();
matchedPaylinesAnySize = new Dictionary<Symbol, List<List<Vector2>>>();
matchedPaylinesSize5 = new Dictionary<Symbol, List<List<Vector2>>>();
matchedPaylinesSize4 = new Dictionary<Symbol, List<List<Vector2>>>();
matchedPaylinesSize3 = new Dictionary<Symbol, List<List<Vector2>>>();
for (int i = 0; i < 5; i++)
{
matchedPaylinesAnySize.Add((Symbol)i, new List<List<Vector2>> ());
matchedPaylinesSize5.Add((Symbol)i, new List<List<Vector2>>());
matchedPaylinesSize4.Add((Symbol)i, new List<List<Vector2>>());
matchedPaylinesSize3.Add((Symbol)i, new List<List<Vector2>>());
}
}
public Dictionary<Symbol, List<List<Vector2>>> GetWinnerPayoutPaths(int size)
{
if (size == 5)
{
return matchedPaylinesSize5;
} else if (size == 4)
{
return matchedPaylinesSize4;
} else if (size == 3)
{
return matchedPaylinesSize3;
}
return matchedPaylinesAnySize;
}
public void CalculatePayout()
{
Reset();
SpinDatum spinDatum = spinGenerator.GetSpinDatum();
List<Symbol[,]> spinnedSymbolsWithWildsReplaced = spinDatum.GetSpinnedSymbolsWithWildsReplaced();
List<List<Vector2>> totalPayoutPaths = paylinePathGenerator.GetTotalPathsv2();
for (int symbolID = 0; symbolID < 5; symbolID++)
{
Symbol scanSymbol = (Symbol)symbolID;
Symbol[,] spinnedSymbols = spinnedSymbolsWithWildsReplaced[symbolID];
foreach (List<Vector2> path in totalPayoutPaths)
{
bool pathSuccess = true;
foreach (Vector2 vertex in path)
{
if (spinnedSymbols[(int) vertex.x, (int) vertex.y] != scanSymbol)
{
pathSuccess = false;
break;
}
}
if (pathSuccess)
{
matchedPaylinesAnySize[scanSymbol].Add(path);
}
}
foreach(List<Vector2> path in matchedPaylinesAnySize[scanSymbol])
{
if (path.Count == 5)
{
matchedPaylinesSize5[scanSymbol].Add(path);
} else if (path.Count == 4)
{
matchedPaylinesSize4[scanSymbol].Add(path);
} else if (path.Count == 3)
{
matchedPaylinesSize3[scanSymbol].Add(path);
}
}
List<List<Vector2>> dirtyPaths = new List<List<Vector2>>();
foreach(List<Vector2> path5 in matchedPaylinesSize5[scanSymbol])
{
foreach(List<Vector2> path4 in matchedPaylinesSize4[scanSymbol])
{
if (NumberOfSharedVertices(path5,path4) == 4)
{
dirtyPaths.Add(path4);
}
}
foreach (List<Vector2> path3 in matchedPaylinesSize3[scanSymbol])
{
if (NumberOfSharedVertices(path5,path3) == 3)
{
dirtyPaths.Add(path3);
}
}
}
foreach(List<Vector2> path4 in matchedPaylinesSize4[scanSymbol])
{
foreach (List<Vector2> path3 in matchedPaylinesSize3[scanSymbol])
{
if (NumberOfSharedVertices(path4,path3) == 3)
{
dirtyPaths.Add(path3);
}
}
}
foreach(List<Vector2> path in dirtyPaths)
{
if (matchedPaylinesSize4[scanSymbol].Contains(path))
{
matchedPaylinesSize4[scanSymbol].Remove(path);
}
if (matchedPaylinesSize3[scanSymbol].Contains(path))
{
matchedPaylinesSize3[scanSymbol].Remove(path);
}
}
foreach(List<Vector2> path in matchedPaylinesSize5[scanSymbol])
{
payoutTallies.Add("" + path.Count + " " + scanSymbol);
}
foreach (List<Vector2> path in matchedPaylinesSize4[scanSymbol])
{
payoutTallies.Add("" + path.Count + " "+ scanSymbol);
}
foreach (List<Vector2> path in matchedPaylinesSize3[scanSymbol])
{
payoutTallies.Add("" + path.Count + " " + scanSymbol);
}
}
float multiplier = 0f;
float bet = player.GetBet();
foreach (string tally in payoutTallies)
{
Debug.Log(tally);
switch (tally)
{
case ("3 Ten"):
multiplier += .25f;
break;
case ("4 Ten"):
multiplier += 1f;
break;
case ("5 Ten"):
multiplier += 5f;
break;
case ("3 Jack"):
multiplier += .5f;
break;
case ("4 Jack"):
multiplier += 2f;
break;
case ("5 Jack"):
multiplier += 10f;
break;
case ("3 Queen"):
multiplier += 1f;
break;
case ("4 Queen"):
multiplier += 4f;
break;
case ("5 Queen"):
multiplier += 20f;
break;
case ("3 King"):
multiplier += 2f;
break;
case ("4 King"):
multiplier += 8f;
break;
case ("5 King"):
multiplier += 40f;
break;
case ("3 Ace"):
multiplier += 4;
break;
case ("4 Ace"):
multiplier += 12;
break;
case ("5 Ace"):
multiplier += 56;
break;
}
}
Debug.Log("Bet: " + bet);
Debug.Log("Multiplier: " + multiplier);
float winnings = bet * multiplier;
player.AwardBalance(winnings);
gameState.SetTrigger("Calculated Payout");
}
private int NumberOfSharedVertices(List<Vector2> path1, List<Vector2> path2)
{
int sharedVertices = 0;
foreach(Vector2 vertex in path1)
{
if (path2.Contains(vertex))
{
sharedVertices++;
}
}
return sharedVertices;
}
}