Full Rotator Sync

This commit is contained in:
brausjonas
2023-04-14 17:49:48 +02:00
parent 0742ff15b4
commit 9000450834
10 changed files with 206 additions and 183 deletions
+1 -1
View File
@@ -165,7 +165,7 @@
<workItem from="1680813239896" duration="4155000" /> <workItem from="1680813239896" duration="4155000" />
<workItem from="1681056387914" duration="882000" /> <workItem from="1681056387914" duration="882000" />
<workItem from="1681415672515" duration="5000" /> <workItem from="1681415672515" duration="5000" />
<workItem from="1681479671396" duration="5656000" /> <workItem from="1681479671396" duration="7481000" />
</task> </task>
<servers /> <servers />
</component> </component>
+30 -30
View File
@@ -1298,8 +1298,8 @@ ParticleSystem:
serializedVersion: 2 serializedVersion: 2
m_Curve: m_Curve:
- serializedVersion: 3 - serializedVersion: 3
time: 0.008106232 time: 0
value: 0.689188 value: 0.14864922
inSlope: 0 inSlope: 0
outSlope: 0 outSlope: 0
tangentMode: 0 tangentMode: 0
@@ -1307,8 +1307,8 @@ ParticleSystem:
inWeight: 0.33333334 inWeight: 0.33333334
outWeight: 0.33333334 outWeight: 0.33333334
- serializedVersion: 3 - serializedVersion: 3
time: 0.57541054 time: 0.57811135
value: 0.4783156 value: 0.3161528
inSlope: -0.19598381 inSlope: -0.19598381
outSlope: -0.19598381 outSlope: -0.19598381
tangentMode: 0 tangentMode: 0
@@ -1317,7 +1317,7 @@ ParticleSystem:
outWeight: 0.33333334 outWeight: 0.33333334
- serializedVersion: 3 - serializedVersion: 3
time: 1 time: 1
value: 0.43243706 value: 0.25676262
inSlope: -0.11902377 inSlope: -0.11902377
outSlope: -0.11902377 outSlope: -0.11902377
tangentMode: 0 tangentMode: 0
@@ -7855,8 +7855,8 @@ ParticleSystem:
serializedVersion: 2 serializedVersion: 2
m_Curve: m_Curve:
- serializedVersion: 3 - serializedVersion: 3
time: 0.008106232 time: 0
value: 0.689188 value: 0.14864922
inSlope: 0 inSlope: 0
outSlope: 0 outSlope: 0
tangentMode: 0 tangentMode: 0
@@ -7864,8 +7864,8 @@ ParticleSystem:
inWeight: 0.33333334 inWeight: 0.33333334
outWeight: 0.33333334 outWeight: 0.33333334
- serializedVersion: 3 - serializedVersion: 3
time: 0.57541054 time: 0.57811135
value: 0.4783156 value: 0.3161528
inSlope: -0.19598381 inSlope: -0.19598381
outSlope: -0.19598381 outSlope: -0.19598381
tangentMode: 0 tangentMode: 0
@@ -7874,7 +7874,7 @@ ParticleSystem:
outWeight: 0.33333334 outWeight: 0.33333334
- serializedVersion: 3 - serializedVersion: 3
time: 1 time: 1
value: 0.43243706 value: 0.25676262
inSlope: -0.11902377 inSlope: -0.11902377
outSlope: -0.11902377 outSlope: -0.11902377
tangentMode: 0 tangentMode: 0
@@ -15703,8 +15703,8 @@ ParticleSystem:
serializedVersion: 2 serializedVersion: 2
m_Curve: m_Curve:
- serializedVersion: 3 - serializedVersion: 3
time: 0.008106232 time: 0
value: 0.689188 value: 0.14864922
inSlope: 0 inSlope: 0
outSlope: 0 outSlope: 0
tangentMode: 0 tangentMode: 0
@@ -15712,8 +15712,8 @@ ParticleSystem:
inWeight: 0.33333334 inWeight: 0.33333334
outWeight: 0.33333334 outWeight: 0.33333334
- serializedVersion: 3 - serializedVersion: 3
time: 0.57541054 time: 0.57811135
value: 0.4783156 value: 0.3161528
inSlope: -0.19598381 inSlope: -0.19598381
outSlope: -0.19598381 outSlope: -0.19598381
tangentMode: 0 tangentMode: 0
@@ -15722,7 +15722,7 @@ ParticleSystem:
outWeight: 0.33333334 outWeight: 0.33333334
- serializedVersion: 3 - serializedVersion: 3
time: 1 time: 1
value: 0.43243706 value: 0.25676262
inSlope: -0.11902377 inSlope: -0.11902377
outSlope: -0.11902377 outSlope: -0.11902377
tangentMode: 0 tangentMode: 0
@@ -29023,8 +29023,8 @@ ParticleSystem:
serializedVersion: 2 serializedVersion: 2
m_Curve: m_Curve:
- serializedVersion: 3 - serializedVersion: 3
time: 0.008106232 time: 0
value: 0.689188 value: 0.14864922
inSlope: 0 inSlope: 0
outSlope: 0 outSlope: 0
tangentMode: 0 tangentMode: 0
@@ -29032,8 +29032,8 @@ ParticleSystem:
inWeight: 0.33333334 inWeight: 0.33333334
outWeight: 0.33333334 outWeight: 0.33333334
- serializedVersion: 3 - serializedVersion: 3
time: 0.57541054 time: 0.57811135
value: 0.4783156 value: 0.3161528
inSlope: -0.19598381 inSlope: -0.19598381
outSlope: -0.19598381 outSlope: -0.19598381
tangentMode: 0 tangentMode: 0
@@ -29042,7 +29042,7 @@ ParticleSystem:
outWeight: 0.33333334 outWeight: 0.33333334
- serializedVersion: 3 - serializedVersion: 3
time: 1 time: 1
value: 0.43243706 value: 0.25676262
inSlope: -0.11902377 inSlope: -0.11902377
outSlope: -0.11902377 outSlope: -0.11902377
tangentMode: 0 tangentMode: 0
@@ -38995,8 +38995,8 @@ ParticleSystem:
serializedVersion: 2 serializedVersion: 2
m_Curve: m_Curve:
- serializedVersion: 3 - serializedVersion: 3
time: 0.008106232 time: 0
value: 0.689188 value: 0.14864922
inSlope: 0 inSlope: 0
outSlope: 0 outSlope: 0
tangentMode: 0 tangentMode: 0
@@ -39004,8 +39004,8 @@ ParticleSystem:
inWeight: 0.33333334 inWeight: 0.33333334
outWeight: 0.33333334 outWeight: 0.33333334
- serializedVersion: 3 - serializedVersion: 3
time: 0.57541054 time: 0.57811135
value: 0.4783156 value: 0.3161528
inSlope: -0.19598381 inSlope: -0.19598381
outSlope: -0.19598381 outSlope: -0.19598381
tangentMode: 0 tangentMode: 0
@@ -39014,7 +39014,7 @@ ParticleSystem:
outWeight: 0.33333334 outWeight: 0.33333334
- serializedVersion: 3 - serializedVersion: 3
time: 1 time: 1
value: 0.43243706 value: 0.25676262
inSlope: -0.11902377 inSlope: -0.11902377
outSlope: -0.11902377 outSlope: -0.11902377
tangentMode: 0 tangentMode: 0
@@ -46502,8 +46502,8 @@ ParticleSystem:
serializedVersion: 2 serializedVersion: 2
m_Curve: m_Curve:
- serializedVersion: 3 - serializedVersion: 3
time: 0.008106232 time: 0
value: 0.689188 value: 0.14864922
inSlope: 0 inSlope: 0
outSlope: 0 outSlope: 0
tangentMode: 0 tangentMode: 0
@@ -46511,8 +46511,8 @@ ParticleSystem:
inWeight: 0.33333334 inWeight: 0.33333334
outWeight: 0.33333334 outWeight: 0.33333334
- serializedVersion: 3 - serializedVersion: 3
time: 0.57541054 time: 0.57811135
value: 0.4783156 value: 0.3161528
inSlope: -0.19598381 inSlope: -0.19598381
outSlope: -0.19598381 outSlope: -0.19598381
tangentMode: 0 tangentMode: 0
@@ -46521,7 +46521,7 @@ ParticleSystem:
outWeight: 0.33333334 outWeight: 0.33333334
- serializedVersion: 3 - serializedVersion: 3
time: 1 time: 1
value: 0.43243706 value: 0.25676262
inSlope: -0.11902377 inSlope: -0.11902377
outSlope: -0.11902377 outSlope: -0.11902377
tangentMode: 0 tangentMode: 0
+68
View File
@@ -9,6 +9,7 @@ using TMPro;
using UnityEngine; using UnityEngine;
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
using UnityEngine.UI; using UnityEngine.UI;
using Random = UnityEngine.Random;
public class Client : MonoBehaviour public class Client : MonoBehaviour
{ {
@@ -290,6 +291,44 @@ public class Client : MonoBehaviour
} }
players[job.data[3]].AddCoins(amount); players[job.data[3]].AddCoins(amount);
break; break;
case 14:
int type = job.data[9];
RandomRotator rotator = uiHandler.rotator.GetComponent<RandomRotator>();
switch (type)
{
case 0:
for (int i = 0; i < 4; i++)
{
int option = job.data[i + 1];
int value = job.data[i + 5];
switch (option)
{
case 0:
rotator.SetOptionsText(i, value + " Coins");
break;
case 1:
rotator.SetOptionsText(i, "-" + value + " Coins");
break;
case 2:
rotator.SetOptionsText(i, "Random Item");
break;
}
}
break;
}
uiHandler.ActivateRotator();
rotator.StartRandom();
break;
case 15:
RandomRotator rotator2 = uiHandler.rotator.GetComponent<RandomRotator>();
rotator2.Stop(job.data[1]);
Invoke("ActivateLayout1", 3.5f);
break;
case 126: case 126:
stream.Write(new byte[]{126, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, 10); stream.Write(new byte[]{126, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, 10);
break; break;
@@ -301,6 +340,11 @@ public class Client : MonoBehaviour
} }
} }
private void ActivateLayout1()
{
uiHandler.ActivateLayout1();
}
private void Activate(int player) private void Activate(int player)
{ {
for (int i = 0; i < players.Length; i++) for (int i = 0; i < players.Length; i++)
@@ -402,9 +446,33 @@ public class Client : MonoBehaviour
if (amount < 0) if (amount < 0)
{ {
isPositive = 0; isPositive = 0;
amount *= -1;
} }
stream.Write(new byte[]{13, isPositive, (byte)amount, 0, 0, 0, 0, 0, 0, 0}); stream.Write(new byte[]{13, isPositive, (byte)amount, 0, 0, 0, 0, 0, 0, 0});
} }
/*
* OPT:
* 0 = Get Coins
* 1 = Loose Coins
* 2 = Get Item (Random)
* 3 = Loose Item (Random)
*
* VAL:
* value of each option (not needed = 0)
*
* TYPE:
* 0 = Pink Field
*/
public void SendStartRotator(int opt1, int opt2, int opt3, int opt4, int val1, int val2, int val3, int val4, int type)
{
stream.Write(new byte[]{14, (byte)opt1, (byte)opt2, (byte)opt3, (byte)opt4, (byte)val1, (byte)val2, (byte)val3, (byte)val4, (byte)type});
}
public void SendStopRotator(int stopIndex)
{
stream.Write(new byte[]{15, (byte)stopIndex, 0, 0, 0, 0, 0, 0, 0, 0});
}
} }
@@ -270,6 +270,7 @@ public class PlayablePlayer : Player
rotator.SetOptionsText(3, "Random Item"); rotator.SetOptionsText(3, "Random Item");
rotator.StartRandom(); rotator.StartRandom();
client.SendStartRotator(0, 0, 1, 2, randCoins1, randCoins2, -randCoins3, 0, 0);
int randomOption = Random.Range(0, 4); int randomOption = Random.Range(0, 4);
switch (randomOption) switch (randomOption)
@@ -489,6 +490,7 @@ public class PlayablePlayer : Player
private void StopRotator() private void StopRotator()
{ {
client.SendStopRotator(rotatorStopIndex);
rotator.Stop(rotatorStopIndex); rotator.Stop(rotatorStopIndex);
} }
} }
+11 -5
View File
@@ -14,6 +14,7 @@ public class RandomRotator : MonoBehaviour
private float lastTimeSwitched = 0; private float lastTimeSwitched = 0;
private int stopIndex = 0; private int stopIndex = 0;
public UIHandler uiHandler; public UIHandler uiHandler;
private bool ended = false;
public void SetOptionsText(int index, string text) public void SetOptionsText(int index, string text)
{ {
@@ -45,31 +46,35 @@ public class RandomRotator : MonoBehaviour
lastTimeSwitched = Time.time; lastTimeSwitched = Time.time;
ColorOption(currentIndex); ColorOption(currentIndex);
currentIndex++; currentIndex++;
if (currentIndex > options.Length) if (currentIndex >= options.Length)
{ {
currentIndex = 0; currentIndex = 0;
} }
} }
} }
else else if(!ended)
{ {
if (currentIndex != stopIndex) if (currentIndex != stopIndex)
{ {
if (Time.time - lastTimeSwitched > slowDown) if (Time.time - lastTimeSwitched > slowDown)
{ {
slowDown += 0.2f; slowDown += 0.05f;
lastTimeSwitched = Time.time; lastTimeSwitched = Time.time;
ColorOption(currentIndex); ColorOption(currentIndex);
currentIndex++; currentIndex++;
if (currentIndex > options.Length) if (currentIndex >= options.Length)
{ {
currentIndex = 0; currentIndex = 0;
} }
} }
} }
else if(currentIndex == stopIndex)
{
if (Time.time - lastTimeSwitched > slowDown)
{ {
ColorOption(stopIndex); ColorOption(stopIndex);
ended = true;
}
} }
} }
} }
@@ -78,6 +83,7 @@ public class RandomRotator : MonoBehaviour
{ {
lastTimeSwitched = Time.time; lastTimeSwitched = Time.time;
started = true; started = true;
ended = false;
} }
public void Stop(int index) public void Stop(int index)
+1 -1
View File
@@ -101,7 +101,7 @@
<workItem from="1681130452664" duration="6192000" /> <workItem from="1681130452664" duration="6192000" />
<workItem from="1681217780586" duration="94000" /> <workItem from="1681217780586" duration="94000" />
<workItem from="1681218296017" duration="162000" /> <workItem from="1681218296017" duration="162000" />
<workItem from="1681481242206" duration="1671000" /> <workItem from="1681481242206" duration="3033000" />
</task> </task>
<servers /> <servers />
</component> </component>
Binary file not shown.
Binary file not shown.
Binary file not shown.
+79 -132
View File
@@ -11,8 +11,7 @@ import java.util.TimerTask;
/** /**
* this class handels all operations / syncs performed in a single room * this class handels all operations / syncs performed in a single room
*/ */
public class Room public class Room {
{
//tells how many clients can connect to a room //tells how many clients can connect to a room
public Client[] players = new Client[2]; public Client[] players = new Client[2];
//the array of players start positions //the array of players start positions
@@ -32,8 +31,7 @@ public class Room
private int currentPlayer = 0; private int currentPlayer = 0;
public Room(String roomCode, Server server) public Room(String roomCode, Server server) {
{
this.roomCode = roomCode; this.roomCode = roomCode;
startPositions = new Vector3[4]; startPositions = new Vector3[4];
@@ -49,17 +47,15 @@ public class Room
/** /**
* Adds a Client to the game (on new player joined the room) * Adds a Client to the game (on new player joined the room)
*
* @param client * @param client
*/ */
public void addClient(Client client) public void addClient(Client client) {
{
//loops through all players existing and sends the needed information //loops through all players existing and sends the needed information
for (int i = 0; i < players.length; i++) for (int i = 0; i < players.length; i++) {
{
//places the new joined player in the next free slot //places the new joined player in the next free slot
if (players[i] == null) if (players[i] == null) {
{
players[i] = client; players[i] = client;
playerCount++; playerCount++;
@@ -67,42 +63,32 @@ public class Room
System.out.println(client.name.replace(" ", "") + " joined room " + roomCode + " successfully as player " + i); System.out.println(client.name.replace(" ", "") + " joined room " + roomCode + " successfully as player " + i);
//creates a thread for the connection with the joined player //creates a thread for the connection with the joined player
Thread t = new Thread(new Runnable() Thread t = new Thread(new Runnable() {
{
@Override @Override
public void run() public void run() {
{
//assignes a player id //assignes a player id
int player = playerCount - 1; int player = playerCount - 1;
DataInputStream input = null; DataInputStream input = null;
try try {
{
//tries to get the input stream (TCP) //tries to get the input stream (TCP)
input = new DataInputStream(players[player].socket.getInputStream()); input = new DataInputStream(players[player].socket.getInputStream());
} catch (IOException e) } catch (IOException e) {
{
server.deleteRoom(roomCode); server.deleteRoom(roomCode);
} }
for(int i = 0; i < players.length; i++) for (int i = 0; i < players.length; i++) {
{ if (players[i] != null) {
if(players[i] != null) try {
{
try
{
players[i].output.write(new byte[]{11, (byte) playerCount, 0, 0, 0, 0, 0, 0, 0, 0}); players[i].output.write(new byte[]{11, (byte) playerCount, 0, 0, 0, 0, 0, 0, 0, 0});
} catch (IOException e) } catch (IOException e) {
{
} }
} }
} }
while (true) while (true) {
{ try {
try
{
//this is a buffer for all data being received by the player //this is a buffer for all data being received by the player
byte[] readData = new byte[10]; byte[] readData = new byte[10];
@@ -120,18 +106,15 @@ public class Room
---------------------------------------- ----------------------------------------
*/ */
//Checks which action (array[0]) is received //Checks which action (array[0]) is received
switch (readData[0]) switch (readData[0]) {
{
/** /**
* //spieler hat gewürfelt * //spieler hat gewürfelt
*/ */
case 3: case 3:
for (int i = 0; i < players.length; i++) for (int i = 0; i < players.length; i++) {
{
//sync to all OTHER players //sync to all OTHER players
if (i != player) if (i != player) {
{
//!!data processing!! //!!data processing!!
//----------------------------action---player-------rolled number----free space-------- //----------------------------action---player-------rolled number----free space--------
players[i].output.write(new byte[]{3, (byte) player, readData[1], 0, 0, 0, 0, 0, 0, 0}); players[i].output.write(new byte[]{3, (byte) player, readData[1], 0, 0, 0, 0, 0, 0, 0});
@@ -142,12 +125,10 @@ public class Room
* //pfeil wurde ausgewählt * //pfeil wurde ausgewählt
*/ */
case 4: case 4:
for (int i = 0; i < players.length; i++) for (int i = 0; i < players.length; i++) {
{
//!!data processing!! //!!data processing!!
//sync to all OTHER players //sync to all OTHER players
if (i != player) if (i != player) {
{
//-------------------------------action----player-----arrow index--------free space----- //-------------------------------action----player-----arrow index--------free space-----
players[i].output.write(new byte[]{4, (byte) player, readData[1], 0, 0, 0, 0, 0, 0, 0}); players[i].output.write(new byte[]{4, (byte) player, readData[1], 0, 0, 0, 0, 0, 0, 0});
} }
@@ -160,13 +141,11 @@ public class Room
case 5: case 5:
//calculate the next player //calculate the next player
currentPlayer++; currentPlayer++;
if (currentPlayer >= players.length) if (currentPlayer >= players.length) {
{
currentPlayer = 0; currentPlayer = 0;
} }
//sync the activation of the current player to ALL clients //sync the activation of the current player to ALL clients
for (int i = 0; i < players.length; i++) for (int i = 0; i < players.length; i++) {
{
//!!data processing!! //!!data processing!!
//----------------------------action--------the next player-----------free space------ //----------------------------action--------the next player-----------free space------
players[i].output.write(new byte[]{2, (byte) currentPlayer, 0, 0, 0, 0, 0, 0, 0, 0}); players[i].output.write(new byte[]{2, (byte) currentPlayer, 0, 0, 0, 0, 0, 0, 0, 0});
@@ -177,11 +156,9 @@ public class Room
* //Es wurde auf ein CoinField getreten (Rot oder Blau) * //Es wurde auf ein CoinField getreten (Rot oder Blau)
*/ */
case 6: case 6:
for (int i = 0; i < players.length; i++) for (int i = 0; i < players.length; i++) {
{
//sync to OTHER players //sync to OTHER players
if (i != player) if (i != player) {
{
//!!data processing!! //!!data processing!!
//-----------------------------action--player-------losse or get------------free space-- //-----------------------------action--player-------losse or get------------free space--
players[i].output.write(new byte[]{6, (byte) player, readData[1], 0, 0, 0, 0, 0, 0, 0}); players[i].output.write(new byte[]{6, (byte) player, readData[1], 0, 0, 0, 0, 0, 0, 0});
@@ -194,8 +171,7 @@ public class Room
*/ */
case 7: case 7:
//sync to ALL players //sync to ALL players
for (int i = 0; i < players.length; i++) for (int i = 0; i < players.length; i++) {
{
//!!simple sync!! //!!simple sync!!
//------------------------------action---player---------free space-------- //------------------------------action---player---------free space--------
players[i].output.write(new byte[]{7, (byte) player, 0, 0, 0, 0, 0, 0, 0, 0}); players[i].output.write(new byte[]{7, (byte) player, 0, 0, 0, 0, 0, 0, 0, 0});
@@ -205,12 +181,10 @@ public class Room
* //Spieler hat einen Stern gekauft * //Spieler hat einen Stern gekauft
*/ */
case 8: case 8:
for (int i = 0; i < players.length; i++) for (int i = 0; i < players.length; i++) {
{
//!!simple sync!! //!!simple sync!!
//sync to OTHER players //sync to OTHER players
if (i != player) if (i != player) {
{
//-----------------------------action----player----------free space------ //-----------------------------action----player----------free space------
players[i].output.write(new byte[]{8, (byte) player, 0, 0, 0, 0, 0, 0, 0, 0}); players[i].output.write(new byte[]{8, (byte) player, 0, 0, 0, 0, 0, 0, 0, 0});
} }
@@ -221,11 +195,9 @@ public class Room
* //Spieler hat ein Item Gekauft * //Spieler hat ein Item Gekauft
*/ */
case 9: case 9:
for (int i = 0; i < players.length; i++) for (int i = 0; i < players.length; i++) {
{
//Sync to OTHER players //Sync to OTHER players
if (i != player) if (i != player) {
{
//!!data processing!! //!!data processing!!
//------------------------------action---player-------item ID--------free space-------- //------------------------------action---player-------item ID--------free space--------
players[i].output.write(new byte[]{9, (byte) player, readData[1], 0, 0, 0, 0, 0, 0, 0}); players[i].output.write(new byte[]{9, (byte) player, readData[1], 0, 0, 0, 0, 0, 0, 0});
@@ -234,11 +206,9 @@ public class Room
break; break;
case 10: case 10:
for (int i = 0; i < players.length; i++) for (int i = 0; i < players.length; i++) {
{
//Sync to OTHER players //Sync to OTHER players
if (i != player) if (i != player) {
{
//!!data processing!! //!!data processing!!
//------------------------------action---player-------item index--------free space-------- //------------------------------action---player-------item index--------free space--------
players[i].output.write(new byte[]{10, (byte) player, readData[1], 0, 0, 0, 0, 0, 0, 0}); players[i].output.write(new byte[]{10, (byte) player, readData[1], 0, 0, 0, 0, 0, 0, 0});
@@ -246,34 +216,41 @@ public class Room
} }
break; break;
case 12: case 12:
for (int i = 0; i < players.length; i++) for (int i = 0; i < players.length; i++) {
{
//Sync to OTHER players //Sync to OTHER players
if (i != player) if (i != player) {
{
//!!data processing!! //!!data processing!!
//------------------------------action---player-------item index--------free space-------- //------------------------------action---player-------item index--------free space--------
players[i].output.write(new byte[]{12, (byte) player, readData[1], 0, 0, 0, 0, 0, 0, 0}); players[i].output.write(new byte[]{12, (byte) player, readData[1], 0, 0, 0, 0, 0, 0, 0});
} }
} }
break; break;
//Coins Sync
case 13: case 13:
for (int i = 0; i < players.length; i++) for (int i = 0; i < players.length; i++) {
{
//Sync to OTHER players //Sync to OTHER players
if (i != player) if (i != player) {
{
players[i].output.write(new byte[]{13, readData[1], readData[2], (byte) player, 0, 0, 0, 0, 0, 0}); players[i].output.write(new byte[]{13, readData[1], readData[2], (byte) player, 0, 0, 0, 0, 0, 0});
} }
} }
break; break;
//Start Rotator AND stop Rotator
case 14: case 15:
for (int i = 0; i < players.length; i++) {
//Sync to OTHER players
if (i != player) {
players[i].output.write(readData);
}
}
break;
case 126: case 126:
server.deleteRoom(roomCode); server.deleteRoom(roomCode);
break; break;
} }
} catch (IOException e) } catch (IOException e) {
{
//if something is crashing, the room is being deleted //if something is crashing, the room is being deleted
server.deleteRoom(roomCode); server.deleteRoom(roomCode);
} }
@@ -291,12 +268,9 @@ public class Room
} }
//Make clients add all players to the world //Make clients add all players to the world
if (playerCount == players.length) if (playerCount == players.length) {
{ for (int j = 0; j < players.length; j++) {
for (int j = 0; j < players.length; j++) for (int k = 0; k < players.length; k++) {
{
for (int k = 0; k < players.length; k++)
{
//0 1 create new player //0 1 create new player
//1 0 no playable player //1 0 no playable player
//1 1 playable character //1 1 playable character
@@ -304,10 +278,8 @@ public class Room
//5 player index //5 player index
//if the player should be playable //if the player should be playable
if (j == k) if (j == k) {
{ try {
try
{
//sends the inital message to the player //sends the inital message to the player
players[j].output.write(new byte[]{1, 1, (byte) startPositions[k].x, (byte) startPositions[k].y, (byte) startPositions[k].z, (byte) k, 0, 0, 0, (byte) players[k].characterID}); players[j].output.write(new byte[]{1, 1, (byte) startPositions[k].x, (byte) startPositions[k].y, (byte) startPositions[k].z, (byte) k, 0, 0, 0, (byte) players[k].characterID});
@@ -317,37 +289,31 @@ public class Room
send[0] = 5; send[0] = 5;
send[1] = (byte) k; send[1] = (byte) k;
for (int i = 2; i < send.length; i++) for (int i = 2; i < send.length; i++) {
{
send[i] = name[i - 2]; send[i] = name[i - 2];
} }
players[j].output.write(send); players[j].output.write(send);
//stop sending the name................................................................................ //stop sending the name................................................................................
} catch (IOException e) } catch (IOException e) {
{
server.deleteRoom(roomCode); server.deleteRoom(roomCode);
} }
} }
//if the player should be a bot //if the player should be a bot
else else {
{ try {
try
{
players[j].output.write(new byte[]{1, 0, (byte) startPositions[k].x, (byte) startPositions[k].y, (byte) startPositions[k].z, (byte) k, 0, 0, 0, (byte) players[k].characterID}); players[j].output.write(new byte[]{1, 0, (byte) startPositions[k].x, (byte) startPositions[k].y, (byte) startPositions[k].z, (byte) k, 0, 0, 0, (byte) players[k].characterID});
byte[] name = players[k].name.substring(0, 8).getBytes(StandardCharsets.US_ASCII); byte[] name = players[k].name.substring(0, 8).getBytes(StandardCharsets.US_ASCII);
byte[] send = new byte[10]; byte[] send = new byte[10];
send[0] = 5; send[0] = 5;
send[1] = (byte) k; send[1] = (byte) k;
for (int i = 2; i < send.length; i++) for (int i = 2; i < send.length; i++) {
{
send[i] = name[i - 2]; send[i] = name[i - 2];
} }
players[j].output.write(send); players[j].output.write(send);
} catch (IOException e) } catch (IOException e) {
{
server.deleteRoom(roomCode); server.deleteRoom(roomCode);
} }
} }
@@ -358,14 +324,11 @@ public class Room
//1 x, x = idx //1 x, x = idx
//send the inital activation message //send the inital activation message
try try {
{ for (Client c : players) {
for (Client c : players)
{
c.output.write(new byte[]{2, 0, 0, 0, 0, 0, 0, 0, 0, 0}); c.output.write(new byte[]{2, 0, 0, 0, 0, 0, 0, 0, 0, 0});
} }
} catch (IOException e) } catch (IOException e) {
{
server.deleteRoom(roomCode); server.deleteRoom(roomCode);
} }
} }
@@ -374,69 +337,53 @@ public class Room
/** /**
* Closes the room * Closes the room
*/ */
public void closeRoom() public void closeRoom() {
{
//try to cick all the players (still connected) of the room //try to cick all the players (still connected) of the room
try try {
{
if (players[0] != null) if (players[0] != null) {
{
//127 is the action for room cick //127 is the action for room cick
players[0].output.write(new byte[]{127, 0, 0, 0, 0, 0, 0, 0, 0, 0}); players[0].output.write(new byte[]{127, 0, 0, 0, 0, 0, 0, 0, 0, 0});
players[0].close(); players[0].close();
} }
} catch (Exception ex) } catch (Exception ex) {
{
} }
try try {
{ if (players[1] != null) {
if (players[1] != null)
{
players[1].output.write(new byte[]{127, 0, 0, 0, 0, 0, 0, 0, 0, 0}); players[1].output.write(new byte[]{127, 0, 0, 0, 0, 0, 0, 0, 0, 0});
players[1].close(); players[1].close();
} }
} catch (Exception ex) } catch (Exception ex) {
{
} }
try try {
{ if (players[2] != null) {
if (players[2] != null)
{
players[2].output.write(new byte[]{127, 0, 0, 0, 0, 0, 0, 0, 0, 0}); players[2].output.write(new byte[]{127, 0, 0, 0, 0, 0, 0, 0, 0, 0});
players[2].close(); players[2].close();
} }
} catch (Exception ex) } catch (Exception ex) {
{
} }
try try {
{ if (players[3] != null) {
if (players[3] != null)
{
players[3].output.write(new byte[]{127, 0, 0, 0, 0, 0, 0, 0, 0, 0}); players[3].output.write(new byte[]{127, 0, 0, 0, 0, 0, 0, 0, 0, 0});
players[3].close(); players[3].close();
} }
} catch (Exception ex) } catch (Exception ex) {
{
} }
//try to close all open threads (not crashed yet) //try to close all open threads (not crashed yet)
for (int i = 0; i < threads.size(); i++) for (int i = 0; i < threads.size(); i++) {
{ try {
try
{
threads.get(i).interrupt(); threads.get(i).interrupt();
System.out.println("thread " + threads.get(i).getName() + " stopped!"); System.out.println("thread " + threads.get(i).getName() + " stopped!");
} catch (Exception e) } catch (Exception e) {
{
} }
} }