A new AudioManager Method triggers a signal which is received by every ManageableAudio instance. If the causer of the signal is the same transform as the parent of the ManageableAudio, a change in AudioEffects is caused.
90 lines
2.4 KiB
C#
90 lines
2.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEditor;
|
|
|
|
namespace GameLogic
|
|
{
|
|
/// <summary>
|
|
/// Updates and checks a matches rules according to the state of the match.
|
|
/// </summary>
|
|
public static class MatchLogic
|
|
{
|
|
public static MatchRule currentRule;
|
|
|
|
/// <summary>
|
|
/// Update match conditions and check for match conclusion.
|
|
/// </summary>
|
|
/// <param name="p">Affected player</param>
|
|
/// <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)
|
|
{
|
|
switch (args.Condition)
|
|
{
|
|
case WinCondition.Lives:
|
|
UpdateLives(mps[p], args.Count);
|
|
break;
|
|
case WinCondition.Score:
|
|
UpdateScore(mps[p], args.Count);
|
|
break;
|
|
case WinCondition.Time:
|
|
UpdateTime(mps[p], args.Count);
|
|
break;
|
|
}
|
|
return DetectMatchResult(mps);
|
|
}
|
|
|
|
public static void UpdateLives(MatchPlayerStatistic mps, int count)
|
|
{
|
|
mps.Lives += count;
|
|
if (mps.Lives <= 0)
|
|
{
|
|
mps.IsOut = true;
|
|
}
|
|
}
|
|
|
|
public static void UpdateScore(MatchPlayerStatistic mps, int count)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public static void UpdateTime(MatchPlayerStatistic mps, int count)
|
|
{
|
|
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 Player Winner { get; private set; }
|
|
public List<Player> Opponents { get; private set; }
|
|
public GUID GameID { get; private set; }
|
|
public MatchResult(Dictionary<Player, MatchPlayerStatistic> mps)
|
|
{
|
|
GameID = GUID.Generate();
|
|
Winner = mps.First(p => p.Value.IsOut != true).Key;
|
|
Opponents = mps.Keys.Where(player => player != Winner).ToList();
|
|
}
|
|
}
|
|
} |