Compare commits

...

3 Commits

15 changed files with 1900 additions and 112 deletions

View File

@ -12,6 +12,7 @@ GameObject:
- component: {fileID: 3310727599597512245}
- component: {fileID: 7696877450501702533}
- component: {fileID: 6827936618995316794}
- component: {fileID: 4008460033671928136}
m_Layer: 0
m_Name: Boost Sound 1
m_TagString: Untagged
@ -171,3 +172,26 @@ AudioLowPassFilter:
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
--- !u!164 &4008460033671928136
AudioReverbFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4479628772504131522}
m_Enabled: 1
m_DryLevel: 0
m_Room: -1000
m_RoomHF: -476
m_DecayTime: 4.32
m_DecayHFRatio: 0.59
m_ReflectionsLevel: -789
m_ReverbLevel: -289
m_ReverbDelay: 0.03
m_Diffusion: 100
m_Density: 100
m_HFReference: 5000
m_RoomLF: 0
m_LFReference: 250
m_ReflectionsDelay: 0
m_ReverbPreset: 7

View File

@ -11,6 +11,7 @@ GameObject:
- component: {fileID: 6423719894035945655}
- component: {fileID: 3310727599597512245}
- component: {fileID: 7696877450501702533}
- component: {fileID: -1754416925767846858}
m_Layer: 0
m_Name: Zone Change In
m_TagString: Untagged
@ -61,7 +62,7 @@ AudioSource:
OutputAudioMixerGroup: {fileID: 0}
m_audioClip: {fileID: 8300000, guid: 7144b46ba00d9fe4183b81b9b2781765, type: 3}
m_PlayOnAwake: 0
m_Volume: 0.25
m_Volume: 0.2
m_Pitch: 0.6
Loop: 0
Mute: 0
@ -145,3 +146,26 @@ AudioSource:
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
--- !u!164 &-1754416925767846858
AudioReverbFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4479628772504131522}
m_Enabled: 1
m_DryLevel: 0
m_Room: -1000
m_RoomHF: -3300
m_DecayTime: 1.49
m_DecayHFRatio: 0.54
m_ReflectionsLevel: -2560
m_ReverbLevel: -229
m_ReverbDelay: 0.088
m_Diffusion: 79
m_Density: 100
m_HFReference: 5000
m_RoomLF: 0
m_LFReference: 250
m_ReflectionsDelay: 0
m_ReverbPreset: 16

View File

@ -11,6 +11,7 @@ GameObject:
- component: {fileID: 6423719894035945655}
- component: {fileID: 3310727599597512245}
- component: {fileID: 7696877450501702533}
- component: {fileID: -1684086232817475425}
m_Layer: 0
m_Name: Zone Change Out
m_TagString: Untagged
@ -61,8 +62,8 @@ AudioSource:
OutputAudioMixerGroup: {fileID: 0}
m_audioClip: {fileID: 8300000, guid: fad7b8b8149e035499ded4af2227b5aa, type: 3}
m_PlayOnAwake: 0
m_Volume: 0.25
m_Pitch: 0.8
m_Volume: 0.2
m_Pitch: 0.65
Loop: 0
Mute: 0
Spatialize: 0
@ -145,3 +146,26 @@ AudioSource:
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
--- !u!164 &-1684086232817475425
AudioReverbFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4479628772504131522}
m_Enabled: 1
m_DryLevel: 0
m_Room: -1000
m_RoomHF: -3300
m_DecayTime: 1.49
m_DecayHFRatio: 0.54
m_ReflectionsLevel: -2560
m_ReverbLevel: -229
m_ReverbDelay: 0.088
m_Diffusion: 79
m_Density: 100
m_HFReference: 5000
m_RoomLF: 0
m_LFReference: 250
m_ReflectionsDelay: 0
m_ReverbPreset: 16

File diff suppressed because it is too large Load Diff

View File

@ -13,11 +13,11 @@ MonoBehaviour:
m_Name: BlueShip
m_EditorClassIdentifier:
shipObject: {fileID: 1372816401649438144, guid: 65cd4fa5e050652409dd9b062365c7e8, type: 3}
shipName: BlueBlitz
thrustAcceleration: 1500
shipName: Blue Blitz
thrustAcceleration: 1275
steerVelocity: 300
normalMaxVelocity: 25
absolutMaxVelocity: 45
normalMaxVelocity: 22
absolutMaxVelocity: 40
antiDriftAmount: 6
minAntiDriftFactor: 0.1
normalDrag: 3
@ -32,4 +32,4 @@ MonoBehaviour:
tackleCriticalStunTime: 0.6
tackleBodyStunTime: 0.2
criticalTacklePowerFactor: 60
normalTacklePowerFactor: 20
normalTacklePowerFactor: 30

View File

@ -13,11 +13,11 @@ MonoBehaviour:
m_Name: RedShip
m_EditorClassIdentifier:
shipObject: {fileID: 1372816401649438144, guid: 46f84e56340e83e4ba7c6abbccd2ae3f, type: 3}
shipName: RedMenace
thrustAcceleration: 1500
shipName: Red Menace
thrustAcceleration: 1300
steerVelocity: 300
normalMaxVelocity: 25
absolutMaxVelocity: 45
absolutMaxVelocity: 42
antiDriftAmount: 9
minAntiDriftFactor: 0.01
normalDrag: 3
@ -31,5 +31,5 @@ MonoBehaviour:
stunLooseControlFactor: 0.1
tackleCriticalStunTime: 0.6
tackleBodyStunTime: 0.2
criticalTacklePowerFactor: 60
normalTacklePowerFactor: 20
criticalTacklePowerFactor: 65
normalTacklePowerFactor: 32

View File

@ -13,7 +13,7 @@ MonoBehaviour:
m_Name: DefaultRule
m_EditorClassIdentifier:
winCondition: 0
rounds: 1
rounds: 3
lives: 1
score: 0
time: -1

View File

@ -189,7 +189,7 @@ namespace Managers
{
MatchManager.LoadMatchRules(0);
MatchManager.LoadArenaProperties(0);
PlayerManager.LocalMatchJoinPlayers(MatchManager.arenaProperties.minPlayerCount);
PlayerManager.LocalMatchJoinPlayers(MatchManager.ArenaProperties.minPlayerCount);
// TODO: This is in place of a character choosing menu etc.
foreach (Player p in PlayerManager.localPlayers)
{
@ -231,7 +231,7 @@ namespace Managers
yield return null;
MatchManager.LoadMatchRules(0);
MatchManager.LoadArenaProperties(0);
PlayerManager.LocalMatchJoinPlayers(MatchManager.arenaProperties.minPlayerCount);
PlayerManager.LocalMatchJoinPlayers(MatchManager.ArenaProperties.minPlayerCount);
foreach (Player p in PlayerManager.localPlayers)
{
CharacterManager.AssignShipFixed(p);

View File

@ -40,6 +40,7 @@ public class MatchConditionUpdate
public class MatchPlayerStatistic
{
public bool IsOut { get; set; }
public int RoundsWon { get; set; }
public int Lives { get; set; }
public int Score { get; set; }
public int Time { get; set; }
@ -54,8 +55,9 @@ namespace Managers
{
private static ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private static string arenaAssetsPath = "Assets/ScriptedAssets/Arenas";
private static string ruleAssetsPath = "Assets/ScriptedAssets/Rules";
private static readonly string arenaAssetsPath = "Assets/ScriptedAssets/Arenas";
private static readonly string ruleAssetsPath = "Assets/ScriptedAssets/Rules";
private GameResult CurrentMatchResult;
public GameObject MatchArena;
public GameObject MatchCamera;
@ -72,29 +74,29 @@ namespace Managers
/// <summary>
/// The players participating in the match.
/// </summary>
public List<Player> matchPlayers { get; private set; } =
public List<Player> MatchPlayers { get; private set; } =
new List<Player>();
/// <summary>
/// The statistics regarding the current match mapped to the players.
/// </summary>
public Dictionary<Player, MatchPlayerStatistic> matchPlayerStatistics { get; set; } =
public Dictionary<Player, MatchPlayerStatistic> MatchPlayerStatistics { get; set; } =
new Dictionary<Player, MatchPlayerStatistic>();
/// <summary>
/// Bundle of properties regarding the arena.
/// </summary>
public Arena arenaProperties { get; private set; }
public Arena ArenaProperties { get; private set; }
/// <summary>
/// The rules under which this match takes place.
/// </summary>
public MatchRule matchRule { get; private set; }
public MatchRule MatchRule { get; private set; }
/// <summary>
/// List of all the arenas in the assets.
/// </summary>
public List<Arena> availableArenas { get; private set; } = new List<Arena>();
public List<Arena> AvailableArenas { get; private set; } = new List<Arena>();
/// <summary>
/// List of all the rules/game modes in the assets.
/// </summary>
public List<MatchRule> availableRules { get; private set; } = new List<MatchRule>();
public List<MatchRule> AvailableRules { get; private set; } = new List<MatchRule>();
void Awake()
@ -116,7 +118,7 @@ namespace Managers
public void UpdateMatchCondition(MatchConditionUpdate update)
{
Player updatedPlayer = null;
foreach (Player p in matchPlayers)
foreach (Player p in MatchPlayers)
{
if (p.character.shipName == update.Ship.props.shipName)
{
@ -124,19 +126,29 @@ namespace Managers
Log.Debug($"Players: {p.name} match statistic will be updated.");
}
}
// TODO: Match Result should contain progression over multiple rounds.
MatchResult result = MatchLogic.UpdateMatchResult(updatedPlayer, update, matchPlayerStatistics);
if (updatedPlayer != null && result != null)
if (updatedPlayer == null)
{
matchState = MatchState.End;
Log.Info("Match has ended, winner will be declared.");
// TODO: Take player decisions into account before restarting the match
// TODO: Include the statistics and match round progression in announcements
AnnounceWinner(result);
Log.Error($"Ship: {update.Ship.props.shipName} does not belong to a player in this match."
+ " Can't update match.");
return;
}
Log.Error($"Ship: {update.Ship.props.shipName} does not belong to a player in this match."
+ " Can't update match.");
if (CurrentMatchResult == null)
{
Log.Error("Match has no result statistics attached and was set up incorrectly!");
return;
}
MatchLogic.UpdateMatchResult(updatedPlayer, update, MatchPlayerStatistics, CurrentMatchResult);
if (CurrentMatchResult.IsMatchWon)
{
Log.Info("Match has ended, winner will be declared.");
AnnounceMatchWinner(CurrentMatchResult);
}
else
{
Log.Info($"Round {CurrentMatchResult.RoundsPlayed} of {MatchRule.rounds} has ended." +
$"{CurrentMatchResult.Winner.name} won this round.");
AnnounceRoundWinner(CurrentMatchResult);
}
}
/// <summary>
@ -149,7 +161,7 @@ namespace Managers
SearchOption.TopDirectoryOnly);
foreach (var file in files)
{
availableArenas.Add(AssetDatabase.LoadAssetAtPath<Arena>(file));
AvailableArenas.Add(AssetDatabase.LoadAssetAtPath<Arena>(file));
}
}
@ -163,7 +175,7 @@ namespace Managers
SearchOption.TopDirectoryOnly);
foreach (var file in files)
{
availableRules.Add(AssetDatabase.LoadAssetAtPath<MatchRule>(file));
AvailableRules.Add(AssetDatabase.LoadAssetAtPath<MatchRule>(file));
}
}
@ -172,17 +184,17 @@ namespace Managers
/// </summary>
public void SetupMatchPlayerStatistics()
{
matchPlayerStatistics.Clear();
foreach (Player p in matchPlayers)
MatchPlayerStatistics.Clear();
foreach (Player p in MatchPlayers)
{
MatchPlayerStatistic mps = new MatchPlayerStatistic
{
IsOut = false,
Lives = matchRule.lives,
Score = matchRule.score,
Time = matchRule.time
Lives = MatchRule.lives,
Score = MatchRule.score,
Time = MatchRule.time
};
if (!matchPlayerStatistics.TryAdd(p, mps))
if (!MatchPlayerStatistics.TryAdd(p, mps))
{
Log.Info($"Player {p.name} already has statistics set up.");
}
@ -196,13 +208,13 @@ namespace Managers
/// <param name="arenaIndex">Index of the arena (arenas scripted asset folder order from 0)</param>
public void LoadArenaProperties(int arenaIndex)
{
if (availableArenas.Count - 1 < arenaIndex)
if (AvailableArenas.Count - 1 < arenaIndex)
{
Log.Error($"There are only: {availableArenas.Count} arenas loaded."
Log.Error($"There are only: {AvailableArenas.Count} arenas loaded."
+ $" Couldn't load arena number: {arenaIndex + 1}");
return;
}
arenaProperties = availableArenas[arenaIndex];
ArenaProperties = AvailableArenas[arenaIndex];
}
/// <summary>
@ -212,14 +224,14 @@ namespace Managers
/// (rules scripted asset folder order from 0)</param>
public void LoadMatchRules(int ruleIndex)
{
if (availableArenas.Count - 1 < ruleIndex)
if (AvailableArenas.Count - 1 < ruleIndex)
{
Log.Error($"There are only: {availableArenas.Count} rules loaded."
Log.Error($"There are only: {AvailableArenas.Count} rules loaded."
+ $" Couldn't load match rule number: {ruleIndex + 1}");
return;
}
matchRule = availableRules[ruleIndex];
MatchLogic.currentRule = matchRule;
MatchRule = AvailableRules[ruleIndex];
MatchLogic.currentRule = MatchRule;
}
/// <summary>
@ -232,22 +244,55 @@ namespace Managers
}
/// <summary>
/// Announcement of who won.
/// TODO: Also restarts the match right now, no matter what.
/// Announcement of who won the match.
/// </summary>
/// <param name="mr">Result data of the completed match.</param>
async public void AnnounceWinner(MatchResult mr)
async public void AnnounceMatchWinner(GameResult mr)
{
UIManager.G.announcments.QueueAnnounceText($"{mr.Winner.playerName}" +
" has won the match!", 1.618f);
await Tween.Delay(1.618f);
UIManager.G.Announcments.QueueAnnounceText($"{mr.Winner.playerName}" +
" has won the match!", 2f);
await Tween.Delay(2f * 0.33f);
matchState = MatchState.End;
await Tween.Delay(2f * 0.66f);
UIManager.G.ShowMatchEndMenu(MatchArena.transform);
}
async public void StartRematch()
{
ResetMatch();
UIManager.G.announcments.QueueAnnounceText("Restarting.", 0.3f);
UIManager.G.announcments.QueueAnnounceText("Restarting..", 0.3f);
UIManager.G.announcments.QueueAnnounceText("Restarting...", 0.3f);
UIManager.G.announcments.QueueAnnounceText("GO!", 0.5f);
UIManager.G.Announcments.QueueAnnounceText("Starting rematch.", 0.3f);
UIManager.G.Announcments.QueueAnnounceText("Starting rematch..", 0.3f);
UIManager.G.Announcments.QueueAnnounceText("Starting rematch...", 0.3f);
UIManager.G.Announcments.QueueAnnounceText("GO!", 0.5f);
await Tween.Delay(0.9f);
matchState = MatchState.Match;
}
/// <summary>
/// Announcement of who won the Round.
/// </summary>
/// <param name="mr">Result data of the completed match.</param>
async public void AnnounceRoundWinner(GameResult mr)
{
var winnerStats = MatchPlayerStatistics[mr.Winner];
UIManager.G.Announcments.QueueAnnounceText($"{mr.Winner.playerName}" +
" has won the Round! \n" +
$"They won {winnerStats.RoundsWon} out of {MatchRule.rounds}.",
1.618f);
await Tween.Delay(1.618f * 0.33f);
matchState = MatchState.Pause;
await Tween.Delay(1.618f * 0.66f);
ResetMatchCharacters();
UIManager.G.Announcments.QueueAnnounceText("Starting next round.", 0.3f);
UIManager.G.Announcments.QueueAnnounceText("Starting next round..", 0.3f);
UIManager.G.Announcments.QueueAnnounceText("Starting next round...", 0.3f);
UIManager.G.Announcments.QueueAnnounceText("GO!", 0.5f);
await Tween.Delay(0.9f);
matchState = MatchState.Match;
@ -258,6 +303,7 @@ namespace Managers
/// </summary>
public void ResetMatch()
{
CurrentMatchResult = new GameResult();
ResetMatchCharacters();
SetupMatchPlayerStatistics();
}
@ -268,12 +314,13 @@ namespace Managers
/// </summary>
async public void StartMatch()
{
foreach (Player p in matchPlayers)
foreach (Player p in MatchPlayers)
{
p.spawnedCharacter.transform.localPosition =
arenaProperties.spawnPositions[p.playerNumber - 1];
ArenaProperties.spawnPositions[p.playerNumber - 1];
}
SetupMatchPlayerStatistics();
CurrentMatchResult = new GameResult();
matchState = MatchState.Starting;
UIManager.G.ShowMatchStartPrompt();
@ -286,10 +333,10 @@ namespace Managers
OnStartPressed = null;
UIManager.G.HideAnnouncement();
UIManager.G.announcments.QueueAnnounceText("3", 1);
UIManager.G.announcments.QueueAnnounceText("2", 1);
UIManager.G.announcments.QueueAnnounceText("1", 1);
UIManager.G.announcments.QueueAnnounceText("GO!", 0.5f);
UIManager.G.Announcments.QueueAnnounceText("3", 1);
UIManager.G.Announcments.QueueAnnounceText("2", 1);
UIManager.G.Announcments.QueueAnnounceText("1", 1);
UIManager.G.Announcments.QueueAnnounceText("GO!", 0.5f);
await Tween.Delay(3);
matchState = MatchState.Match;
@ -297,12 +344,13 @@ namespace Managers
public void StartTestMatch()
{
foreach (Player p in matchPlayers)
foreach (Player p in MatchPlayers)
{
p.spawnedCharacter.transform.localPosition =
arenaProperties.spawnPositions[p.playerNumber - 1];
ArenaProperties.spawnPositions[p.playerNumber - 1];
}
SetupMatchPlayerStatistics();
CurrentMatchResult = new GameResult();
matchState = MatchState.Match;
}
@ -346,10 +394,10 @@ namespace Managers
async private void ContinueMatch()
{
UIManager.G.announcments.QueueAnnounceText("Get Ready.", 0.3f);
UIManager.G.announcments.QueueAnnounceText("Get Ready..", 0.3f);
UIManager.G.announcments.QueueAnnounceText("Get Ready...", 0.3f);
UIManager.G.announcments.QueueAnnounceText("GO!", 0.5f);
UIManager.G.Announcments.QueueAnnounceText("Get Ready.", 0.3f);
UIManager.G.Announcments.QueueAnnounceText("Get Ready..", 0.3f);
UIManager.G.Announcments.QueueAnnounceText("Get Ready...", 0.3f);
UIManager.G.Announcments.QueueAnnounceText("GO!", 0.5f);
await Tween.Delay(0.9f);
matchState = MatchState.Match;
}
@ -384,11 +432,11 @@ namespace Managers
ship.cameraOperator = MatchCamera.GetComponent<CameraOperator>();
shipObject.transform.SetParent(MatchArena.transform, false);
shipObject.transform.localPosition =
arenaProperties.spawnPositions[p.playerNumber - 1];
ArenaProperties.spawnPositions[p.playerNumber - 1];
shipObject.transform.localScale = new Vector3();
Tween.Scale(shipObject.transform, new Vector3(0.7f, 0.7f, 0.7f), 1f);
matchPlayers.Add(p);
MatchPlayers.Add(p);
}
}
@ -397,15 +445,18 @@ namespace Managers
/// </summary>
public void ResetMatchCharacters()
{
foreach (Player mp in matchPlayers)
foreach (Player mp in MatchPlayers)
{
GameObject shipGO = mp.spawnedCharacter;
shipGO.TryGetComponent(out Ship ship);
shipGO.TryGetComponent(out Rigidbody body);
ship.state.boostCapacity = ship.props.maxBoostCapacity;
body.velocity = Vector3.zero;
shipGO.transform.localPosition =
arenaProperties.spawnPositions[mp.playerNumber - 1];
ArenaProperties.spawnPositions[mp.playerNumber - 1];
shipGO.transform.rotation = shipGO.transform.parent.rotation;
}
}

View File

@ -13,8 +13,9 @@ namespace Managers
private static ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
[SerializeField] public bool IsUIActiveScene { get; set; }
public HUD hUD { get; private set; }
public Announcments announcments { get; private set; }
public PauseMenu pauseMenu { get; private set; }
public Announcments Announcments { get; private set; }
public PauseMenu PauseMenu { get; private set; }
public MatchEndMenu MatchEndMenu { get; private set; }
/// <summary>
/// Globally accessible member to use manager with.
@ -30,7 +31,7 @@ namespace Managers
public bool StartManagingMatchUI()
{
if (!StartManagingHUD() || !StartManagingAnnouncements()
|| !StartManagingPauseMenu())
|| !StartManagingPauseMenu() || !StartManagingMatchEndMenu())
{
Log.Error("Problems when starting in game match UI.");
return false;
@ -55,7 +56,7 @@ namespace Managers
public bool StartManagingPauseMenu()
{
if (pauseMenu == null)
if (PauseMenu == null)
{
GameObject go = GameObject.Find("Paused Menu");
if (go == null)
@ -63,14 +64,29 @@ namespace Managers
Log.Error("Could not find Pause Menu GameObject in loaded scenes!");
return false;
}
pauseMenu = go.GetComponent<PauseMenu>();
PauseMenu = go.GetComponent<PauseMenu>();
}
return true;
}
public bool StartManagingMatchEndMenu()
{
if (MatchEndMenu == null)
{
GameObject go = GameObject.Find("Match End Menu");
if (go == null)
{
Log.Error("Could not find Match End Menu GameObject in loaded scenes!");
return false;
}
MatchEndMenu = go.GetComponent<MatchEndMenu>();
}
return true;
}
public bool StartManagingAnnouncements()
{
if (announcments == null)
if (Announcments == null)
{
GameObject go = GameObject.Find("Announcer UI");
if (go == null)
@ -78,7 +94,7 @@ namespace Managers
Log.Error("Could not find Pause Menu GameObject in loaded scenes!");
return false;
}
announcments = go.GetComponent<Announcments>();
Announcments = go.GetComponent<Announcments>();
}
return true;
}
@ -104,21 +120,30 @@ namespace Managers
public void ShowMatchStartPrompt()
{
announcments.AnnounceText("Press Start/Enter \n to start the match!");
Announcments.AnnounceText("Press Start/Enter \n to start the match!");
}
public void HideAnnouncement()
{
announcments.StopAnnouncement();
Announcments.StopAnnouncement();
}
public void ShowPauseMenu(Transform transform)
{
pauseMenu?.Show(transform);
PauseMenu?.Show(transform);
}
public void HidePauseMenu()
{
pauseMenu?.Hide();
PauseMenu?.Hide();
}
public void ShowMatchEndMenu(Transform transform)
{
MatchEndMenu?.Show(transform);
}
public void HideMatchEndMenu()
{
MatchEndMenu?.Hide();
}
public void HideHUD()

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using UnityEditor;
namespace GameLogic
@ -19,7 +20,8 @@ namespace GameLogic
/// <param name="args">Update to the matches conditions</param>
/// <param name="mps">Dictionary of the players in the match and their current stats</param>
/// <returns></returns>
public static MatchResult UpdateMatchResult(Player p, MatchConditionUpdate args, Dictionary<Player, MatchPlayerStatistic> mps)
public static void UpdateMatchResult(Player p, MatchConditionUpdate args,
Dictionary<Player, MatchPlayerStatistic> mps, GameResult result)
{
switch (args.Condition)
{
@ -33,7 +35,7 @@ namespace GameLogic
UpdateTime(mps[p], args.Count);
break;
}
return DetectMatchResult(mps);
result.UpdateGameResult(mps, currentRule);
}
public static void UpdateLives(MatchPlayerStatistic mps, int count)
@ -55,36 +57,53 @@ namespace GameLogic
throw new NotImplementedException();
}
/// <summary>
/// Detects if a match has concluded.
/// Currently only checks if all but on player is out.
/// </summary>
/// <param name="mps">Dictonary of the players and their match data.</param>
/// <returns>Match result object, if the match has concluded</returns>
private static MatchResult DetectMatchResult(Dictionary<Player, MatchPlayerStatistic> mps)
{
int outPlayers = mps.Count(p => p.Value.IsOut);
if (outPlayers == mps.Count - 1)
{
return new MatchResult(mps);
}
return null;
}
}
/// <summary>
/// Data class which records the results of a Match
/// </summary>
public class MatchResult
public class GameResult
{
/// <summary>
/// Indicates whether a round or the whole match was won
/// </summary>
public bool IsMatchWon { get; private set; }
public int RoundsPlayed { get; private set; }
public Player Winner { get; private set; }
public List<Player> Opponents { get; private set; }
public GUID GameID { get; private set; }
public MatchResult(Dictionary<Player, MatchPlayerStatistic> mps)
public GameResult()
{
GameID = GUID.Generate();
Winner = mps.First(p => p.Value.IsOut != true).Key;
Opponents = mps.Keys.Where(player => player != Winner).ToList();
}
/// <summary>
/// Checks whether a round is won and if that round decided the match.
/// Sets the class properties accordingly.
/// </summary>
/// <param name="mps">Dictionary of players with their statistics for this match</param>
/// <param name="rules">The rules for this match</param>
public void UpdateGameResult(Dictionary<Player, MatchPlayerStatistic> mps, MatchRule rules)
{
int outPlayers = mps.Count(p => p.Value.IsOut);
if (outPlayers == mps.Count - 1)
{
Winner = mps.First(p => p.Value.IsOut != true).Key;
Opponents = mps.Keys.Where(player => player != Winner).ToList();
mps[Winner].RoundsWon += 1;
RoundsPlayed += 1;
}
else
{
Winner = null;
}
// TODO: this is wrong winning 2 rounds can decide the match
if (RoundsPlayed == rules.rounds)
{
IsMatchWon = true;
Winner = mps.Aggregate((p1, p2) =>
p1.Value.RoundsWon > p2.Value.RoundsWon ? p1 : p2).Key;
Opponents = mps.Keys.Where(player => player != Winner).ToList();
}
}
}
}

View File

@ -3,10 +3,7 @@ using UnityEngine;
using static AffectingForcesManager;
using ShipHandling;
using Managers;
using GameLogic;
using Unity.VisualScripting;
using Unity.Mathematics;
using System.Text.RegularExpressions;
public class Ship : MonoBehaviour
{

View File

@ -0,0 +1,76 @@
using System.Collections;
using System.Reflection;
using log4net;
using Managers;
using SlimUI.ModernMenu;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.SceneManagement;
public class MatchEndMenu : MonoBehaviour
{
private static ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private Canvas Canvas;
public GameObject Camera;
public GameObject UIEventSystem;
public GameObject MenuButtons;
public GameObject FocusButtonRematch;
private EventSystem eventSystem;
// Start is called before the first frame update
void Awake()
{
Canvas = gameObject.GetComponent<Canvas>();
Canvas.enabled = false;
MenuButtons.SetActive(false);
eventSystem = UIEventSystem.GetComponent<EventSystem>();
}
public void Show(Transform transform)
{
gameObject.transform.position = transform.position;
gameObject.transform.rotation = transform.rotation;
Canvas.enabled = true;
Camera.SetActive(true);
UIEventSystem.SetActive(true);
MenuButtons.SetActive(true);
eventSystem.SetSelectedGameObject(FocusButtonRematch, null);
}
public void Hide()
{
Canvas.enabled = false;
Camera.SetActive(false);
UIEventSystem.SetActive(false);
}
public void OnRematch()
{
MatchManager.G.StartRematch();
Hide();
}
public void OnMainMenu()
{
StartCoroutine(StartSceneTransition());
}
private IEnumerator StartSceneTransition()
{
Canvas.enabled = false;
SceneManager.LoadScene((int)Scenes.MainMenu, LoadSceneMode.Additive);
yield return new WaitForSeconds(0.2f);
GameObject menu = GameObject.Find("Main Menu Camera");
if (menu != null && menu.TryGetComponent(out SlimUIMainMenu menuScript))
{
UIManager.G.HideHUD();
menuScript.MenuTransition(Camera.GetComponent<Camera>().transform);
}
else
{
Log.Error("Can't transition back to main menu. Menu camera or script not found.");
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b892c3598ac2a8c4e827dbfeee948246
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -24,6 +24,7 @@ public class PauseMenu : MonoBehaviour
{
Canvas = gameObject.GetComponent<Canvas>();
Canvas.enabled = false;
PauseMenuButtons.SetActive(false);
eventSystem = UIEventSystem.GetComponent<EventSystem>();
}