Browse Source

Got combined blocks moving faster than single blocks so that animate in the same amount of time + fixed bug where players were waiting for other players to finish an action

Josh_Dev_branch
Joshua Reason 5 years ago
parent
commit
d89a37a6db
12 changed files with 98 additions and 73 deletions
  1. +0
    -8
      Assets/Plugins/IngameDebugConsole/Android.meta
  2. +0
    -8
      Assets/Plugins/IngameDebugConsole/Prefabs.meta
  3. +0
    -8
      Assets/Plugins/IngameDebugConsole/Scripts.meta
  4. +0
    -8
      Assets/Plugins/IngameDebugConsole/Sprites/Unused.meta
  5. +2
    -1
      Assets/Scripts/BlockInput.cs
  6. +1
    -1
      Assets/Scripts/Components.meta
  7. +9
    -5
      Assets/Scripts/Logic/BlockReader.cs
  8. +9
    -3
      Assets/Scripts/Logic/Blocks/CombinedBlock.cs
  9. +1
    -0
      Assets/Scripts/Logic/Blocks/EditableBlock.cs
  10. +15
    -5
      Assets/Scripts/Logic/Blocks/LogicBlock.cs
  11. +0
    -8
      Assets/Scripts/LogicBlocks.meta
  12. +61
    -18
      Assets/Scripts/Managers/GameManager.cs

+ 0
- 8
Assets/Plugins/IngameDebugConsole/Android.meta View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 3d7d7a61a5341904eb3c65af025b1d86
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

+ 0
- 8
Assets/Plugins/IngameDebugConsole/Prefabs.meta View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 7dbc36665bc0d684db9a4447e27a7a4b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

+ 0
- 8
Assets/Plugins/IngameDebugConsole/Scripts.meta View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 860c08388401a6d4e858fe4910ea9337
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

+ 0
- 8
Assets/Plugins/IngameDebugConsole/Sprites/Unused.meta View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: f6caae32d463529478f2186f47c2e3fe
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

+ 2
- 1
Assets/Scripts/BlockInput.cs View File

@ -20,7 +20,8 @@ public class BlockInput : MonoBehaviour
[ContextMenu("Read Next")] [ContextMenu("Read Next")]
public void ReadNext() public void ReadNext()
{ {
blockReader.Read(character, waitTime);
float TotalAnimationTime;
blockReader.Read(character, waitTime,out TotalAnimationTime);
} }
public void ReadAll() public void ReadAll()

Assets/Models.meta → Assets/Scripts/Components.meta View File

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 296bd90e667df1f4697823a0aa45acf0
guid: 8d7394d70ec233849a60a26da5f23b75
folderAsset: yes folderAsset: yes
DefaultImporter: DefaultImporter:
externalObjects: {} externalObjects: {}

+ 9
- 5
Assets/Scripts/Logic/BlockReader.cs View File

@ -56,28 +56,32 @@ public class BlockReader
/// </summary> /// </summary>
/// <param name="character">Character to control</param> /// <param name="character">Character to control</param>
/// <returns>Returns false if other readers should wait for this one to run again</returns> /// <returns>Returns false if other readers should wait for this one to run again</returns>
public bool Read(Character character,float animationTime)
public bool Read(Character character,float speedMultiplier, out float TotalAnimationTime)
{ {
//return that this is done if no more blocks left in chain
//return that this is done if no more blocks left in chain
if (LogicChain.Count <= currentBlockIndex) if (LogicChain.Count <= currentBlockIndex)
{
TotalAnimationTime = 0;
return true; return true;
}
//get current Block //get current Block
LogicBlock currentBlock = LogicChain[currentBlockIndex]; LogicBlock currentBlock = LogicChain[currentBlockIndex];
//apply blocks to character //apply blocks to character
currentBlock.Run(character, animationTime);
bool runAgainNot = currentBlock.Run(character, speedMultiplier,out TotalAnimationTime);
//if the block is finished reset it and move on to next one //if the block is finished reset it and move on to next one
//(it might not be finished if it is a for loop or something) //(it might not be finished if it is a for loop or something)
if (currentBlock.isFinished())
bool isFinished = currentBlock.isFinished();
if (isFinished)
{ {
currentBlock.Reset(); currentBlock.Reset();
currentBlockIndex++; currentBlockIndex++;
} }
//Should other readers wait for this one //Should other readers wait for this one
return (currentBlock.isFinished() || currentBlock.WaitUntilFinished);
return (runAgainNot || !currentBlock.WaitUntilFinished);
} }
/// <summary> /// <summary>

+ 9
- 3
Assets/Scripts/Logic/Blocks/CombinedBlock.cs View File

@ -16,15 +16,21 @@ public class CombinedBlock : LogicBlock
public BlockReader blockReader = new BlockReader(); public BlockReader blockReader = new BlockReader();
#endregion Inspector Variables #endregion Inspector Variables
#region ReadOnly Variables
public override bool WaitUntilFinished { get { if (blockReader != null && blockReader.CurrentBlock != null) return (blockReader.CurrentBlock.WaitUntilFinished || base.WaitUntilFinished); else return base.WaitUntilFinished; } }
#endregion
#region Private Variables #region Private Variables
#endregion Private Variables #endregion Private Variables
public override bool Run(Character player, float animationTime)
public override bool Run(Character player, float animationTime, out float TotalAnimationTime)
{ {
BlockLogic(player,animationTime); BlockLogic(player,animationTime);
blockReader.Read(player, animationTime / SpeedMultiplier, out TotalAnimationTime);
if (blockReader.Finished) if (blockReader.Finished)
{ {
blockReader.Reset(); blockReader.Reset();
@ -36,7 +42,7 @@ public class CombinedBlock : LogicBlock
protected override void BlockLogic(Character player, float animationTime) protected override void BlockLogic(Character player, float animationTime)
{ {
blockReader.Read(player,animationTime);
} }

+ 1
- 0
Assets/Scripts/Logic/Blocks/EditableBlock.cs View File

@ -27,4 +27,5 @@ public class EditableBlock : CombinedBlock
} }
} }

+ 15
- 5
Assets/Scripts/Logic/Blocks/LogicBlock.cs View File

@ -22,12 +22,16 @@ public abstract class LogicBlock : ScriptableObject
[SerializeField] [SerializeField]
[Header("Base Settings")] [Header("Base Settings")]
[Tooltip("Wait until this block is resolved before moving to next")] [Tooltip("Wait until this block is resolved before moving to next")]
public bool WaitUntilFinished = false;
protected bool _WaitUntilFinished = false;
[SerializeField] [SerializeField]
[Tooltip("Amount of times to run this Block before moving to next")] [Tooltip("Amount of times to run this Block before moving to next")]
protected int RepeatAmount = 1; protected int RepeatAmount = 1;
[SerializeField]
[Tooltip("Speed this block will be played back at. (Default = 1)")]
protected float SpeedMultiplier = 1;
#endregion Inspector Fields #endregion Inspector Fields
#region ReadOnly Variables #region ReadOnly Variables
@ -35,6 +39,8 @@ public abstract class LogicBlock : ScriptableObject
[HideInInspector] [HideInInspector]
public bool hasBeenRemoved = false; public bool hasBeenRemoved = false;
public virtual bool WaitUntilFinished { get { return _WaitUntilFinished; } }
#endregion #endregion
#region private variables #region private variables
@ -52,10 +58,11 @@ public abstract class LogicBlock : ScriptableObject
/// </summary> /// </summary>
/// <param name="player">Player which will be affected by the block</param> /// <param name="player">Player which will be affected by the block</param>
/// <returns>returns true if block is finished</returns> /// <returns>returns true if block is finished</returns>
public virtual bool Run(Character player, float animationTime)
public virtual bool Run(Character player, float animationSpeed, out float TotalAnimationTime)
{ {
RepeatCount++; RepeatCount++;
BlockLogic(player, animationTime);
TotalAnimationTime = animationSpeed / SpeedMultiplier;
BlockLogic(player, TotalAnimationTime);
if(GlobalVariables.playerMoves == true){ if(GlobalVariables.playerMoves == true){
player.DisplayBlock(this); player.DisplayBlock(this);
@ -106,7 +113,6 @@ public abstract class LogicBlock : ScriptableObject
return (RepeatCount == RepeatAmount); return (RepeatCount == RepeatAmount);
} }
#region Serialisation Functions #region Serialisation Functions
/// <summary> /// <summary>
/// Copies data from BlockToken to this Block /// Copies data from BlockToken to this Block
@ -116,9 +122,10 @@ public abstract class LogicBlock : ScriptableObject
{ {
Color = token.Color; Color = token.Color;
_DisplayName = token._DisplayName; _DisplayName = token._DisplayName;
WaitUntilFinished = token.WaitUntilFinished;
_WaitUntilFinished = token.WaitUntilFinished;
RepeatAmount = token.RepeatAmount; RepeatAmount = token.RepeatAmount;
name = token.ObjectName; name = token.ObjectName;
SpeedMultiplier = token.SpeedMultiplier;
} }
/// <summary> /// <summary>
@ -135,6 +142,7 @@ public abstract class LogicBlock : ScriptableObject
token.WaitUntilFinished = WaitUntilFinished; token.WaitUntilFinished = WaitUntilFinished;
token.RepeatAmount = RepeatAmount; token.RepeatAmount = RepeatAmount;
token.ObjectName = name; token.ObjectName = name;
token.SpeedMultiplier = SpeedMultiplier;
return token; return token;
} }
@ -187,6 +195,8 @@ public class BlockToken
public int RepeatAmount; public int RepeatAmount;
public float SpeedMultiplier;
public BlockToken(LogicBlock block) public BlockToken(LogicBlock block)
{ {
blockType = block.GetType(); blockType = block.GetType();

+ 0
- 8
Assets/Scripts/LogicBlocks.meta View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 8936b441d7647f74884c94f97bfb8931
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

+ 61
- 18
Assets/Scripts/Managers/GameManager.cs View File

@ -105,31 +105,46 @@ public class GameManager : MonoBehaviour
{ {
playerArray.ForEach(p => p.recievedList = false); playerArray.ForEach(p => p.recievedList = false);
//while (playerArray.Any(p => !p.blockReader.Finished))
//{
// foreach (PlayerData player in playerArray)
// {
// if (!player.waiting)
// {
// if (player.blockReader.CurrentBlock != null && !player.blockReader.CurrentBlock.hasBeenRemoved)
// {
// //Debug.Log("used Block: " + player.blockReader.CurrentBlock.name);
// player.client.Inventory.Remove(player.blockReader.CurrentBlock);
// player.blockReader.CurrentBlock.hasBeenRemoved = true;
// }
// player.waiting = player.blockReader.Read(player.character, AnimationTime);
// }
// }
//
// yield return new WaitForSeconds(AnimationTime);
//
//
//
// if (playerArray.All(p => p.waiting))
// {
// playerArray.ForEach(p => p.waiting = false);
// Debug.Log("Finished one move");
// }
//}
Debug.Log("Doing Round Routine");
while (playerArray.Any(p => !p.blockReader.Finished)) while (playerArray.Any(p => !p.blockReader.Finished))
{ {
Debug.Log("One Move");
foreach (PlayerData player in playerArray) foreach (PlayerData player in playerArray)
{
if (!player.waiting)
{
if (player.blockReader.CurrentBlock != null && !player.blockReader.CurrentBlock.hasBeenRemoved)
{
//Debug.Log("used Block: " + player.blockReader.CurrentBlock.name);
player.client.Inventory.Remove(player.blockReader.CurrentBlock);
player.blockReader.CurrentBlock.hasBeenRemoved = true;
}
player.waiting = player.blockReader.Read(player.character, AnimationTime);
}
}
StartCoroutine(RunOnce(player));
yield return new WaitForSeconds(AnimationTime);
//wait until all players have finished
yield return new WaitUntil(() => playerArray.All(p => p.waiting));
gamemode.FinishedMove(playerArray.ToArray()); gamemode.FinishedMove(playerArray.ToArray());
if (playerArray.All(p => p.waiting))
{
playerArray.ForEach(p => p.waiting = false);
Debug.Log("Finished one move");
}
} }
if (gamemode.isGameOver(playerArray.ToArray())) if (gamemode.isGameOver(playerArray.ToArray()))
@ -175,6 +190,34 @@ public class GameManager : MonoBehaviour
{ {
server.server.RegisterHandler(LogicProtocols.SendLogicList, RecieveLogicList); server.server.RegisterHandler(LogicProtocols.SendLogicList, RecieveLogicList);
} }
private IEnumerator RunOnce(PlayerData data)
{
data.waiting = false;
bool blockFinished = false;
float waitTime;
while (!blockFinished && !data.blockReader.Finished)
{
Debug.Log(data.client + "Moving once");
if (data.blockReader.CurrentBlock != null && !data.blockReader.CurrentBlock.hasBeenRemoved)
{
data.client.Inventory.Remove(data.blockReader.CurrentBlock);
data.blockReader.CurrentBlock.hasBeenRemoved = true;
}
blockFinished = data.blockReader.Read(data.character, AnimationTime,out waitTime);
Debug.Log("Waiting: " + waitTime);
yield return new WaitForSeconds(waitTime);
}
data.waiting = true;
}
} }
public class PlayerData public class PlayerData

Loading…
Cancel
Save