net.dreditor.minigames.rs 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (182) hide show
  1. package/.attestation.p7m +0 -0
  2. package/CrossSwordsMechanic.cs +329 -329
  3. package/CrossSwordsMechanic.cs.meta +11 -11
  4. package/CutHandler.cs +286 -286
  5. package/CutHandler.cs.meta +11 -11
  6. package/CutLimitMechanic.cs +58 -58
  7. package/CutLimitMechanic.cs.meta +11 -11
  8. package/DREditor.Minigames.RS.asmdef +37 -37
  9. package/DREditor.Minigames.RS.asmdef.meta +7 -7
  10. package/DamagePhraseOnSwordHit.cs +149 -149
  11. package/DamagePhraseOnSwordHit.cs.meta +11 -11
  12. package/Editor/DREditor.Minigames.RS.Editor.asmdef +23 -23
  13. package/Editor/DREditor.Minigames.RS.Editor.asmdef.meta +7 -7
  14. package/Editor/RSBuilderEditor.cs +395 -395
  15. package/Editor/RSBuilderEditor.cs.meta +11 -11
  16. package/Editor/RSDebugToolEditor.cs +98 -98
  17. package/Editor/RSDebugToolEditor.cs.meta +11 -11
  18. package/Editor/RSEditorBase.cs +189 -189
  19. package/Editor/RSEditorBase.cs.meta +11 -11
  20. package/Editor/RSPhraseEditor.cs +43 -43
  21. package/Editor/RSPhraseEditor.cs.meta +11 -11
  22. package/Editor.meta +8 -8
  23. package/FollowRectSizeDelta.cs +81 -81
  24. package/FollowRectSizeDelta.cs.meta +11 -11
  25. package/FollowableRect.cs +28 -28
  26. package/FollowableRect.cs.meta +11 -11
  27. package/IPhraseHealth.cs +35 -35
  28. package/IPhraseHealth.cs.meta +11 -11
  29. package/ISplitScreen.cs +48 -48
  30. package/ISplitScreen.cs.meta +11 -11
  31. package/ISwipeListener.cs +17 -17
  32. package/ISwipeListener.cs.meta +11 -11
  33. package/ISword.cs +44 -44
  34. package/ISword.cs.meta +11 -11
  35. package/ISwordHitListener.cs +17 -17
  36. package/ISwordHitListener.cs.meta +11 -11
  37. package/ITieBreaker.cs +17 -17
  38. package/ITieBreaker.cs.meta +11 -11
  39. package/Managers/FireSliceAnimation.cs +292 -292
  40. package/Managers/FireSliceAnimation.cs.meta +11 -11
  41. package/Managers/FiredSliceHandler.cs +92 -92
  42. package/Managers/FiredSliceHandler.cs.meta +11 -11
  43. package/Managers/InterjectHandler.cs +139 -139
  44. package/Managers/InterjectHandler.cs.meta +11 -11
  45. package/Managers/InterjectHandlerBase.cs +18 -18
  46. package/Managers/InterjectHandlerBase.cs.meta +11 -11
  47. package/Managers/RSBuilder.cs +307 -307
  48. package/Managers/RSBuilder.cs.meta +11 -11
  49. package/Managers/RSEnemyWinMechanic.cs +177 -177
  50. package/Managers/RSEnemyWinMechanic.cs.meta +11 -11
  51. package/Managers/RSGroup.cs +178 -178
  52. package/Managers/RSGroup.cs.meta +11 -11
  53. package/Managers/RSGroupManager.cs +378 -378
  54. package/Managers/RSGroupManager.cs.meta +11 -11
  55. package/Managers/RSManager.cs +319 -319
  56. package/Managers/RSManager.cs.meta +11 -11
  57. package/Managers/RSPanel.cs +38 -38
  58. package/Managers/RSPanel.cs.meta +11 -11
  59. package/Managers/RSPhrase.cs +56 -56
  60. package/Managers/RSPhrase.cs.meta +11 -11
  61. package/Managers.meta +8 -8
  62. package/MultiPanelManager.cs +178 -178
  63. package/MultiPanelManager.cs.meta +11 -11
  64. package/{Samples → Samples~}/CUT_Canvas.prefab +484 -484
  65. package/{Samples → Samples~}/CUT_Canvas.prefab.meta +7 -7
  66. package/{Samples → Samples~}/Cross_Swords_Mechanic_Shell.prefab +64 -64
  67. package/{Samples → Samples~}/Cross_Swords_Mechanic_Shell.prefab.meta +7 -7
  68. package/{Samples → Samples~}/Cross_Swords_Mechanic_Template.prefab +485 -485
  69. package/{Samples → Samples~}/Cross_Swords_Mechanic_Template.prefab.meta +7 -7
  70. package/{Samples → Samples~}/CutCount.asset +21 -21
  71. package/{Samples → Samples~}/CutCount.asset.meta +8 -8
  72. package/{Samples → Samples~}/Cut_Handler.prefab +253 -253
  73. package/{Samples → Samples~}/Cut_Handler.prefab.meta +7 -7
  74. package/{Samples → Samples~}/Cut_Limit_Mechanic_UI.prefab +233 -233
  75. package/{Samples → Samples~}/Cut_Limit_Mechanic_UI.prefab.meta +7 -7
  76. package/{Samples → Samples~}/Debate_Text_Texture.prefab +75 -75
  77. package/{Samples → Samples~}/Debate_Text_Texture.prefab.meta +7 -7
  78. package/{Samples → Samples~}/Fire_Slice_Animation.prefab +308 -308
  79. package/{Samples → Samples~}/Fire_Slice_Animation.prefab.meta +7 -7
  80. package/{Samples → Samples~}/Fired_Slice_Handler_Shell.prefab +49 -49
  81. package/{Samples → Samples~}/Fired_Slice_Handler_Shell.prefab.meta +7 -7
  82. package/{Samples → Samples~}/Fired_Slice_Handler_Template.prefab +163 -163
  83. package/{Samples → Samples~}/Fired_Slice_Handler_Template.prefab.meta +7 -7
  84. package/{Samples → Samples~}/Multi_Line_Processes.prefab +306 -306
  85. package/{Samples → Samples~}/Multi_Line_Processes.prefab.meta +7 -7
  86. package/{Samples → Samples~}/Multi_Panel_Canvas_Shell.prefab +140 -140
  87. package/{Samples → Samples~}/Multi_Panel_Canvas_Shell.prefab.meta +7 -7
  88. package/{Samples → Samples~}/Multi_Panel_Canvas_Template.prefab +426 -426
  89. package/{Samples → Samples~}/Multi_Panel_Canvas_Template.prefab.meta +7 -7
  90. package/{Samples → Samples~}/Multi_Panel_Manager_Shell.prefab +57 -57
  91. package/{Samples → Samples~}/Multi_Panel_Manager_Shell.prefab.meta +7 -7
  92. package/{Samples → Samples~}/Multi_Panel_Manager_Template.prefab +316 -316
  93. package/{Samples → Samples~}/Multi_Panel_Manager_Template.prefab.meta +7 -7
  94. package/{Samples → Samples~}/OnAdvance.asset +15 -15
  95. package/{Samples → Samples~}/OnAdvance.asset.meta +8 -8
  96. package/{Samples → Samples~}/OnDuelEnded.asset +15 -15
  97. package/{Samples → Samples~}/OnDuelEnded.asset.meta +8 -8
  98. package/{Samples → Samples~}/OnDuelStarted.asset +15 -15
  99. package/{Samples → Samples~}/OnDuelStarted.asset.meta +8 -8
  100. package/{Samples → Samples~}/OnRetreat.asset +15 -15
  101. package/{Samples → Samples~}/OnRetreat.asset.meta +8 -8
  102. package/{Samples → Samples~}/OutOfCuts.asset +21 -21
  103. package/{Samples → Samples~}/OutOfCuts.asset.meta +8 -8
  104. package/{Samples → Samples~}/Panel_Mask_1.prefab +182 -182
  105. package/{Samples → Samples~}/Panel_Mask_1.prefab.meta +7 -7
  106. package/{Samples → Samples~}/Panel_Mask_2.prefab +127 -127
  107. package/{Samples → Samples~}/Panel_Mask_2.prefab.meta +7 -7
  108. package/{Samples → Samples~}/RS Mesh Generator.asset +21 -21
  109. package/{Samples → Samples~}/RS Mesh Generator.asset.meta +8 -8
  110. package/{Samples → Samples~}/RS Triangle Shatter.asset +31 -31
  111. package/{Samples → Samples~}/RS Triangle Shatter.asset.meta +8 -8
  112. package/{Samples → Samples~}/RSCameraRightEnabled.asset +21 -21
  113. package/{Samples → Samples~}/RSCameraRightEnabled.asset.meta +8 -8
  114. package/{Samples → Samples~}/RS_Bullet_Canvas_ETemplate.prefab +290 -290
  115. package/{Samples → Samples~}/RS_Bullet_Canvas_ETemplate.prefab.meta +7 -7
  116. package/{Samples → Samples~}/RS_Bullet_Canvas_Shell.prefab +156 -156
  117. package/{Samples → Samples~}/RS_Bullet_Canvas_Shell.prefab.meta +7 -7
  118. package/{Samples → Samples~}/RS_Bullet_ETemplate.prefab +127 -127
  119. package/{Samples → Samples~}/RS_Bullet_ETemplate.prefab.meta +7 -7
  120. package/{Samples → Samples~}/RS_Bullet_Evaluator_Manager_Template.prefab +299 -299
  121. package/{Samples → Samples~}/RS_Bullet_Evaluator_Manager_Template.prefab.meta +7 -7
  122. package/{Samples → Samples~}/RS_Bullet_UI_Parent_ETemplate.prefab +164 -164
  123. package/{Samples → Samples~}/RS_Bullet_UI_Parent_ETemplate.prefab.meta +7 -7
  124. package/{Samples → Samples~}/RS_Canvas_Shell.prefab +98 -98
  125. package/{Samples → Samples~}/RS_Canvas_Shell.prefab.meta +7 -7
  126. package/{Samples → Samples~}/RS_Canvas_Template.prefab +841 -841
  127. package/{Samples → Samples~}/RS_Canvas_Template.prefab.meta +7 -7
  128. package/{Samples → Samples~}/RS_Click_Group.prefab +255 -255
  129. package/{Samples → Samples~}/RS_Click_Group.prefab.meta +7 -7
  130. package/{Samples → Samples~}/RS_Controls_UI_Handler.prefab +168 -168
  131. package/{Samples → Samples~}/RS_Controls_UI_Handler.prefab.meta +7 -7
  132. package/{Samples → Samples~}/RS_Cycle_Bullet_ETemplate.prefab +242 -242
  133. package/{Samples → Samples~}/RS_Cycle_Bullet_ETemplate.prefab.meta +7 -7
  134. package/{Samples → Samples~}/RS_Cycle_UI_Canvas_Shell.prefab +232 -232
  135. package/{Samples → Samples~}/RS_Cycle_UI_Canvas_Shell.prefab.meta +7 -7
  136. package/{Samples → Samples~}/RS_Cycle_UI_Canvas_Template.prefab +443 -443
  137. package/{Samples → Samples~}/RS_Cycle_UI_Canvas_Template.prefab.meta +7 -7
  138. package/{Samples → Samples~}/RS_Enemy_Win_Mechanic_Shell.prefab +106 -106
  139. package/{Samples → Samples~}/RS_Enemy_Win_Mechanic_Shell.prefab.meta +7 -7
  140. package/{Samples → Samples~}/RS_Enemy_Win_Mechanic_Template.prefab +230 -230
  141. package/{Samples → Samples~}/RS_Enemy_Win_Mechanic_Template.prefab.meta +7 -7
  142. package/{Samples → Samples~}/RS_Fire_Bullet_UI_Handler_Template.prefab +1234 -1234
  143. package/{Samples → Samples~}/RS_Fire_Bullet_UI_Handler_Template.prefab.meta +7 -7
  144. package/{Samples → Samples~}/RS_Firing_Sword_UI_ETemplate.prefab +405 -405
  145. package/{Samples → Samples~}/RS_Firing_Sword_UI_ETemplate.prefab.meta +7 -7
  146. package/{Samples → Samples~}/RS_Group_Manager_Shell.prefab +145 -145
  147. package/{Samples → Samples~}/RS_Group_Manager_Shell.prefab.meta +7 -7
  148. package/{Samples → Samples~}/RS_Group_Manager_Template.prefab +537 -537
  149. package/{Samples → Samples~}/RS_Group_Manager_Template.prefab.meta +7 -7
  150. package/{Samples → Samples~}/RS_Line_Manager_Template.prefab +191 -191
  151. package/{Samples → Samples~}/RS_Line_Manager_Template.prefab.meta +7 -7
  152. package/{Samples → Samples~}/RS_Loading_Bullet_Canvas_Shell.prefab +204 -204
  153. package/{Samples → Samples~}/RS_Loading_Bullet_Canvas_Shell.prefab.meta +7 -7
  154. package/{Samples → Samples~}/RS_Loading_Bullet_Canvas_Template.prefab +411 -411
  155. package/{Samples → Samples~}/RS_Loading_Bullet_Canvas_Template.prefab.meta +7 -7
  156. package/{Samples → Samples~}/RS_Manager_Shell.prefab +514 -514
  157. package/{Samples → Samples~}/RS_Manager_Shell.prefab.meta +7 -7
  158. package/{Samples → Samples~}/RS_Manager_Template.prefab +1526 -1526
  159. package/{Samples → Samples~}/RS_Manager_Template.prefab.meta +7 -7
  160. package/{Samples → Samples~}/RS_Text_Camera.prefab +125 -125
  161. package/{Samples → Samples~}/RS_Text_Camera.prefab.meta +7 -7
  162. package/{Samples → Samples~}/RS_UI_Shatter_Canvas_Template.prefab +150 -150
  163. package/{Samples → Samples~}/RS_UI_Shatter_Canvas_Template.prefab.meta +7 -7
  164. package/{Samples → Samples~}/ShowRSUI.asset +15 -15
  165. package/{Samples → Samples~}/ShowRSUI.asset.meta +8 -8
  166. package/{Samples → Samples~}/Split_Seam_UI.prefab +120 -120
  167. package/{Samples → Samples~}/Split_Seam_UI.prefab.meta +7 -7
  168. package/{Samples → Samples~}/Swipe_Sword.prefab +81 -81
  169. package/{Samples → Samples~}/Swipe_Sword.prefab.meta +7 -7
  170. package/{Samples → Samples~}/Swipe_Visualizer_Image.prefab +102 -102
  171. package/{Samples → Samples~}/Swipe_Visualizer_Image.prefab.meta +7 -7
  172. package/{Samples → Samples~}/Sword_Hit_Listeners.prefab +49 -49
  173. package/{Samples → Samples~}/Sword_Hit_Listeners.prefab.meta +7 -7
  174. package/SplitScreenHandler.cs +263 -263
  175. package/SplitScreenHandler.cs.meta +11 -11
  176. package/SwipeSword.cs +235 -235
  177. package/SwipeSword.cs.meta +11 -11
  178. package/SwipeVisualizer.cs +241 -241
  179. package/SwipeVisualizer.cs.meta +11 -11
  180. package/package.json +57 -52
  181. package/package.json.meta +7 -7
  182. package/Samples.meta +0 -8
Binary file
@@ -1,330 +1,330 @@
1
- //Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
2
- using DREditor.Audio;
3
- using DREditor.EventObjects;
4
- using DREditor.Minigames.Debates.Mechanics;
5
- using DREditor.Services;
6
- using DREditor.UIHandling;
7
- using System;
8
- using System.Collections;
9
- using UnityEngine;
10
- using UnityEngine.Events;
11
- using UnityEngine.InputSystem;
12
- using static UnityEngine.InputSystem.InputAction;
13
-
14
- namespace DREditor.Minigames.RS
15
- {
16
- /// <summary>
17
- ///
18
- /// </summary>
19
- [ClassHeader(nameof(ServiceHolder<ITieBreaker>) + ", " + nameof(ITieBreaker) +
20
- "\n\n")]
21
- public class CrossSwordsMechanic : ServiceHolder<ITieBreaker>, ITieBreaker
22
- {
23
- /// <summary>
24
- ///
25
- /// </summary>
26
- [Tooltip("")]
27
- [SerializeField] protected InputActionReference submit = null;
28
-
29
-
30
- /// <summary>
31
- ///
32
- /// </summary>
33
- [Header("")]
34
- [Divider]
35
- [Tooltip("")]
36
- [SerializeField] protected SceneEvent duelStartedEvent;
37
-
38
- /// <summary>
39
- ///
40
- /// </summary>
41
- [Tooltip("")]
42
- [SerializeField] protected SceneEvent duelEndedEvent;
43
-
44
-
45
- /// <summary>
46
- ///
47
- /// </summary>
48
- [Header("")]
49
- [Divider]
50
- [Tooltip("")]
51
- [SerializeField] protected UIVisibilityComponent introAnimation = null;
52
-
53
- /// <summary>
54
- ///
55
- /// </summary>
56
- [Tooltip("")]
57
- [SerializeField] protected UIVisibilityComponent successAnimation = null;
58
-
59
- /// <summary>
60
- ///
61
- /// </summary>
62
- [Tooltip("")]
63
- [SerializeField] protected UIVisibilityComponent failureAnimation = null;
64
-
65
-
66
- /// <summary>
67
- ///
68
- /// </summary>
69
- [Header("")]
70
- [Divider]
71
- [Tooltip("")]
72
- [SerializeField] protected int totalTaps = 8;
73
-
74
- /// <summary>
75
- ///
76
- /// </summary>
77
- [Tooltip("")]
78
- [SerializeField] protected float duelDuration = 3;
79
-
80
- /// <summary>
81
- ///
82
- /// </summary>
83
- [Tooltip("")]
84
- [SerializeField] protected int enemyIndex = 0;
85
-
86
- /// <summary>
87
- ///
88
- /// </summary>
89
- [Tooltip("")]
90
- [SerializeField] protected float enemyAttackRate = 0.2f;
91
-
92
- /// <summary>
93
- ///
94
- /// </summary>
95
- [Tooltip("")]
96
- [SerializeField] protected float damage = 5;
97
-
98
-
99
- [Header("")]
100
- [SerializeField] protected UnityEvent onDuelStarted = null;
101
-
102
-
103
- /// <summary>
104
- ///
105
- /// </summary>
106
- [Header("")]
107
- [Divider]
108
- [Tooltip("")]
109
- [SerializeField] protected SoundPlayerDRE successSFX;
110
-
111
- /// <summary>
112
- ///
113
- /// </summary>
114
- [Tooltip("")]
115
- [SerializeField] protected SoundPlayerDRE failureSFX;
116
-
117
- /// <summary>
118
- ///
119
- /// </summary>
120
- [Tooltip("")]
121
- [SerializeField] protected SoundPlayerDRE clashingSFX;
122
-
123
-
124
- /// <summary>
125
- ///
126
- /// </summary>
127
- protected int currentTaps = 0;
128
-
129
- /// <summary>
130
- ///
131
- /// </summary>
132
- protected ISplitScreen splitService;
133
-
134
-
135
- protected virtual void Start() => InitializeMechanic();
136
-
137
- /// <summary>
138
- ///
139
- /// </summary>
140
- protected virtual void InitializeMechanic()
141
- {
142
- if (!InitializationValid())
143
- OnInitializationFailed();
144
- }
145
-
146
- /// <summary>
147
- ///
148
- /// </summary>
149
- /// <returns></returns>
150
- protected virtual bool InitializationValid() => ServiceLocator.HasService(out splitService);
151
-
152
- /// <summary>
153
- ///
154
- /// </summary>
155
- protected virtual void OnInitializationFailed()
156
- {
157
- UnityEngine.Debug.LogWarning($"ALERT: The {nameof(CrossSwordsMechanic)} requires " +
158
- $"an active {nameof(ISplitScreen)} service to function.\n" +
159
- $"PROPOSAL: Ensure that a service registering {nameof(ISplitScreen)} is available.");
160
-
161
- UnityEngine.Debug.Log($"REPORT: Destroying {nameof(CrossSwordsMechanic)}.");
162
-
163
- Destroy(gameObject);
164
- }
165
-
166
-
167
- /// <inheritdoc/>
168
- public virtual IEnumerator TieBreakerProcess(Action<bool> result)
169
- {
170
- UnityEngine.Debug.Log("REPORT: Starting CrossSwords.");
171
-
172
- InitializeDuel();
173
-
174
- InvokeDuelStarted();
175
-
176
- yield return DisplayStartingDuel();
177
-
178
- RaiseEvent(duelStartedEvent);
179
-
180
- EnablePlayerDueling();
181
-
182
- yield return Duel();
183
-
184
- DisablePlayerDueling();
185
-
186
- RaiseEvent(duelEndedEvent);
187
-
188
- yield return ResolveDuel();
189
-
190
- result(splitService.WillAdvanceOnTie());
191
-
192
- UnityEngine.Debug.Log("REPORT: Ending CrossSwords.");
193
- }
194
-
195
- /// <summary>
196
- ///
197
- /// </summary>
198
- protected virtual void InitializeDuel()
199
- {
200
- splitService.AnimateToResetState();
201
-
202
- currentTaps = totalTaps;
203
-
204
- var speeds = transform.root.GetComponentsInChildren<SpeedHandlerBase>();
205
-
206
- foreach (var speed in speeds)
207
- {
208
- speed.OnPanelsStopped();
209
-
210
- speed.DeactivateControls();
211
- }
212
- }
213
-
214
- /// <summary>
215
- ///
216
- /// </summary>
217
- /// <returns></returns>
218
- protected virtual IEnumerator DisplayStartingDuel()
219
- {
220
- if (introAnimation != null)
221
- {
222
- yield return introAnimation.ShowTillComplete();
223
-
224
- introAnimation.Hide();
225
- }
226
- }
227
-
228
- /// <summary>
229
- ///
230
- /// </summary>
231
- /// <param name="sceneEvent"></param>
232
- protected virtual void RaiseEvent(SceneEvent sceneEvent)
233
- {
234
- if (sceneEvent != null)
235
- sceneEvent.Raise();
236
- }
237
-
238
- /// <summary>
239
- ///
240
- /// </summary>
241
- protected virtual void InvokeDuelStarted() => onDuelStarted?.Invoke();
242
-
243
- /// <summary>
244
- ///
245
- /// </summary>
246
- protected virtual void EnablePlayerDueling() => submit.action.started += Tap;
247
-
248
- /// <summary>
249
- ///
250
- /// </summary>
251
- /// <param name="ctx"></param>
252
- protected virtual void Tap(CallbackContext ctx)
253
- {
254
- currentTaps++;
255
-
256
- splitService.PlayerAttack(damage);
257
-
258
- if (clashingSFX != null)
259
- clashingSFX.PlaySFX();
260
- }
261
-
262
- /// <summary>
263
- ///
264
- /// </summary>
265
- /// <returns></returns>
266
- protected virtual IEnumerator Duel()
267
- {
268
- float timeRemaining = duelDuration;
269
-
270
- while (timeRemaining > 0 && currentTaps != 0 && currentTaps <= totalTaps)
271
- {
272
- yield return new WaitForSeconds(enemyAttackRate);
273
-
274
- timeRemaining -= enemyAttackRate;
275
-
276
- splitService.EnemyAttack(enemyIndex, damage);
277
-
278
- currentTaps--;
279
-
280
- if (clashingSFX != null)
281
- clashingSFX.PlaySFX();
282
-
283
- UnityEngine.Debug.Log("REPORT: Enemy Attacked.");
284
-
285
- yield return null;
286
- }
287
- }
288
-
289
- /// <summary>
290
- ///
291
- /// </summary>
292
- protected virtual void DisablePlayerDueling() => submit.action.started -= Tap;
293
-
294
- /// <summary>
295
- ///
296
- /// </summary>
297
- protected virtual IEnumerator ResolveDuel()
298
- {
299
- bool playerWon = splitService.WillAdvanceOnTie();
300
-
301
- var resultSound = playerWon ? successSFX : failureSFX;
302
-
303
- var resultAnimation = playerWon ? successAnimation : failureAnimation;
304
-
305
- if (playerWon)
306
- splitService.PlayerAttack(damage);
307
- else
308
- splitService.EnemyAttack(enemyIndex, damage);
309
-
310
- if (resultSound != null)
311
- resultSound.PlaySFX();
312
-
313
- if (resultAnimation != null)
314
- {
315
- yield return resultAnimation.ShowTillComplete();
316
-
317
- resultAnimation.Hide();
318
- }
319
- }
320
-
321
-
322
- /// <inheritdoc/>
323
- protected override void OnDestroy()
324
- {
325
- base.OnDestroy();
326
-
327
- DisablePlayerDueling();
328
- }
329
- }
1
+ //Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
2
+ using DREditor.Audio;
3
+ using DREditor.EventObjects;
4
+ using DREditor.Minigames.Debates.Mechanics;
5
+ using DREditor.Services;
6
+ using DREditor.UIHandling;
7
+ using System;
8
+ using System.Collections;
9
+ using UnityEngine;
10
+ using UnityEngine.Events;
11
+ using UnityEngine.InputSystem;
12
+ using static UnityEngine.InputSystem.InputAction;
13
+
14
+ namespace DREditor.Minigames.RS
15
+ {
16
+ /// <summary>
17
+ ///
18
+ /// </summary>
19
+ [ClassHeader(nameof(ServiceHolder<ITieBreaker>) + ", " + nameof(ITieBreaker) +
20
+ "\n\n")]
21
+ public class CrossSwordsMechanic : ServiceHolder<ITieBreaker>, ITieBreaker
22
+ {
23
+ /// <summary>
24
+ ///
25
+ /// </summary>
26
+ [Tooltip("")]
27
+ [SerializeField] protected InputActionReference submit = null;
28
+
29
+
30
+ /// <summary>
31
+ ///
32
+ /// </summary>
33
+ [Header("")]
34
+ [Divider]
35
+ [Tooltip("")]
36
+ [SerializeField] protected SceneEvent duelStartedEvent;
37
+
38
+ /// <summary>
39
+ ///
40
+ /// </summary>
41
+ [Tooltip("")]
42
+ [SerializeField] protected SceneEvent duelEndedEvent;
43
+
44
+
45
+ /// <summary>
46
+ ///
47
+ /// </summary>
48
+ [Header("")]
49
+ [Divider]
50
+ [Tooltip("")]
51
+ [SerializeField] protected UIVisibilityComponent introAnimation = null;
52
+
53
+ /// <summary>
54
+ ///
55
+ /// </summary>
56
+ [Tooltip("")]
57
+ [SerializeField] protected UIVisibilityComponent successAnimation = null;
58
+
59
+ /// <summary>
60
+ ///
61
+ /// </summary>
62
+ [Tooltip("")]
63
+ [SerializeField] protected UIVisibilityComponent failureAnimation = null;
64
+
65
+
66
+ /// <summary>
67
+ ///
68
+ /// </summary>
69
+ [Header("")]
70
+ [Divider]
71
+ [Tooltip("")]
72
+ [SerializeField] protected int totalTaps = 8;
73
+
74
+ /// <summary>
75
+ ///
76
+ /// </summary>
77
+ [Tooltip("")]
78
+ [SerializeField] protected float duelDuration = 3;
79
+
80
+ /// <summary>
81
+ ///
82
+ /// </summary>
83
+ [Tooltip("")]
84
+ [SerializeField] protected int enemyIndex = 0;
85
+
86
+ /// <summary>
87
+ ///
88
+ /// </summary>
89
+ [Tooltip("")]
90
+ [SerializeField] protected float enemyAttackRate = 0.2f;
91
+
92
+ /// <summary>
93
+ ///
94
+ /// </summary>
95
+ [Tooltip("")]
96
+ [SerializeField] protected float damage = 5;
97
+
98
+
99
+ [Header("")]
100
+ [SerializeField] protected UnityEvent onDuelStarted = null;
101
+
102
+
103
+ /// <summary>
104
+ ///
105
+ /// </summary>
106
+ [Header("")]
107
+ [Divider]
108
+ [Tooltip("")]
109
+ [SerializeField] protected SoundPlayerDRE successSFX;
110
+
111
+ /// <summary>
112
+ ///
113
+ /// </summary>
114
+ [Tooltip("")]
115
+ [SerializeField] protected SoundPlayerDRE failureSFX;
116
+
117
+ /// <summary>
118
+ ///
119
+ /// </summary>
120
+ [Tooltip("")]
121
+ [SerializeField] protected SoundPlayerDRE clashingSFX;
122
+
123
+
124
+ /// <summary>
125
+ ///
126
+ /// </summary>
127
+ protected int currentTaps = 0;
128
+
129
+ /// <summary>
130
+ ///
131
+ /// </summary>
132
+ protected ISplitScreen splitService;
133
+
134
+
135
+ protected virtual void Start() => InitializeMechanic();
136
+
137
+ /// <summary>
138
+ ///
139
+ /// </summary>
140
+ protected virtual void InitializeMechanic()
141
+ {
142
+ if (!InitializationValid())
143
+ OnInitializationFailed();
144
+ }
145
+
146
+ /// <summary>
147
+ ///
148
+ /// </summary>
149
+ /// <returns></returns>
150
+ protected virtual bool InitializationValid() => ServiceLocator.HasService(out splitService);
151
+
152
+ /// <summary>
153
+ ///
154
+ /// </summary>
155
+ protected virtual void OnInitializationFailed()
156
+ {
157
+ UnityEngine.Debug.LogWarning($"ALERT: The {nameof(CrossSwordsMechanic)} requires " +
158
+ $"an active {nameof(ISplitScreen)} service to function.\n" +
159
+ $"PROPOSAL: Ensure that a service registering {nameof(ISplitScreen)} is available.");
160
+
161
+ UnityEngine.Debug.Log($"REPORT: Destroying {nameof(CrossSwordsMechanic)}.");
162
+
163
+ Destroy(gameObject);
164
+ }
165
+
166
+
167
+ /// <inheritdoc/>
168
+ public virtual IEnumerator TieBreakerProcess(Action<bool> result)
169
+ {
170
+ UnityEngine.Debug.Log("REPORT: Starting CrossSwords.");
171
+
172
+ InitializeDuel();
173
+
174
+ InvokeDuelStarted();
175
+
176
+ yield return DisplayStartingDuel();
177
+
178
+ RaiseEvent(duelStartedEvent);
179
+
180
+ EnablePlayerDueling();
181
+
182
+ yield return Duel();
183
+
184
+ DisablePlayerDueling();
185
+
186
+ RaiseEvent(duelEndedEvent);
187
+
188
+ yield return ResolveDuel();
189
+
190
+ result(splitService.WillAdvanceOnTie());
191
+
192
+ UnityEngine.Debug.Log("REPORT: Ending CrossSwords.");
193
+ }
194
+
195
+ /// <summary>
196
+ ///
197
+ /// </summary>
198
+ protected virtual void InitializeDuel()
199
+ {
200
+ splitService.AnimateToResetState();
201
+
202
+ currentTaps = totalTaps;
203
+
204
+ var speeds = transform.root.GetComponentsInChildren<SpeedHandlerBase>();
205
+
206
+ foreach (var speed in speeds)
207
+ {
208
+ speed.OnPanelsStopped();
209
+
210
+ speed.DeactivateControls();
211
+ }
212
+ }
213
+
214
+ /// <summary>
215
+ ///
216
+ /// </summary>
217
+ /// <returns></returns>
218
+ protected virtual IEnumerator DisplayStartingDuel()
219
+ {
220
+ if (introAnimation != null)
221
+ {
222
+ yield return introAnimation.ShowTillComplete();
223
+
224
+ introAnimation.Hide();
225
+ }
226
+ }
227
+
228
+ /// <summary>
229
+ ///
230
+ /// </summary>
231
+ /// <param name="sceneEvent"></param>
232
+ protected virtual void RaiseEvent(SceneEvent sceneEvent)
233
+ {
234
+ if (sceneEvent != null)
235
+ sceneEvent.Raise();
236
+ }
237
+
238
+ /// <summary>
239
+ ///
240
+ /// </summary>
241
+ protected virtual void InvokeDuelStarted() => onDuelStarted?.Invoke();
242
+
243
+ /// <summary>
244
+ ///
245
+ /// </summary>
246
+ protected virtual void EnablePlayerDueling() => submit.action.started += Tap;
247
+
248
+ /// <summary>
249
+ ///
250
+ /// </summary>
251
+ /// <param name="ctx"></param>
252
+ protected virtual void Tap(CallbackContext ctx)
253
+ {
254
+ currentTaps++;
255
+
256
+ splitService.PlayerAttack(damage);
257
+
258
+ if (clashingSFX != null)
259
+ clashingSFX.PlaySFX();
260
+ }
261
+
262
+ /// <summary>
263
+ ///
264
+ /// </summary>
265
+ /// <returns></returns>
266
+ protected virtual IEnumerator Duel()
267
+ {
268
+ float timeRemaining = duelDuration;
269
+
270
+ while (timeRemaining > 0 && currentTaps != 0 && currentTaps <= totalTaps)
271
+ {
272
+ yield return new WaitForSeconds(enemyAttackRate);
273
+
274
+ timeRemaining -= enemyAttackRate;
275
+
276
+ splitService.EnemyAttack(enemyIndex, damage);
277
+
278
+ currentTaps--;
279
+
280
+ if (clashingSFX != null)
281
+ clashingSFX.PlaySFX();
282
+
283
+ UnityEngine.Debug.Log("REPORT: Enemy Attacked.");
284
+
285
+ yield return null;
286
+ }
287
+ }
288
+
289
+ /// <summary>
290
+ ///
291
+ /// </summary>
292
+ protected virtual void DisablePlayerDueling() => submit.action.started -= Tap;
293
+
294
+ /// <summary>
295
+ ///
296
+ /// </summary>
297
+ protected virtual IEnumerator ResolveDuel()
298
+ {
299
+ bool playerWon = splitService.WillAdvanceOnTie();
300
+
301
+ var resultSound = playerWon ? successSFX : failureSFX;
302
+
303
+ var resultAnimation = playerWon ? successAnimation : failureAnimation;
304
+
305
+ if (playerWon)
306
+ splitService.PlayerAttack(damage);
307
+ else
308
+ splitService.EnemyAttack(enemyIndex, damage);
309
+
310
+ if (resultSound != null)
311
+ resultSound.PlaySFX();
312
+
313
+ if (resultAnimation != null)
314
+ {
315
+ yield return resultAnimation.ShowTillComplete();
316
+
317
+ resultAnimation.Hide();
318
+ }
319
+ }
320
+
321
+
322
+ /// <inheritdoc/>
323
+ protected override void OnDestroy()
324
+ {
325
+ base.OnDestroy();
326
+
327
+ DisablePlayerDueling();
328
+ }
329
+ }
330
330
  }