public void CmdTellServerToUpdateWorldNodePosition(NetworkInstanceId clientNetID, Vector3 worldNodeIndex, Vector3 locPos, Vector3 locRot) { if (!isServer) { return; } CheckSyncVars(); Vector3Int vectInt = new Vector3Int(Mathf.FloorToInt(worldNodeIndex.x), Mathf.FloorToInt(worldNodeIndex.y), Mathf.FloorToInt(worldNodeIndex.z)); int vectIndex = DataManipulation.ConvertVectorIntoInt(vectInt); int index = _syncedVars._network_Ships_Indexs.IndexOf(vectIndex); NetworkNodeStruct nodeStruct = _syncedVars._network_Ships_Container[index]; // this is not good and will be horribly innefficient nodeStruct.CurrLoc = locPos; nodeStruct.CurrRot = locRot; // tell all clients to move ship RpcTellOtherClientsToMoveClientShip(clientNetID, nodeStruct); }
public void CmdTellServerToSpawnPlayersShip(NetworkInstanceId clientNetID, Vector3 loc, Vector3 rot, int playerID) // this player ID is dumb and needs the player ship info (thats all its here for) to be fed in here rather than pulled from a script on the clients machines, beacuse that cant happen if people are joining games on the fly { if (!isServer) { return; } CheckSyncVars(); Vector3Int nodeID = new Vector3Int(Mathf.FloorToInt(loc.x), Mathf.FloorToInt(loc.y), Mathf.FloorToInt(loc.z)); NetworkNodeStruct nodeStruct = new NetworkNodeStruct() { NodeID = nodeID, StructIndex = _syncedVars._network_Ships_Indexs.Count, ClientNetID = clientNetID, PlayerID = playerID, CurrLoc = loc, CurrRot = rot }; // tell all clients to load new ship RpcTellAllClientsToSpawnPlayerShip(nodeStruct, playerID); // now load old SHIPS into this client foreach (NetworkNodeStruct node in _syncedVars._network_Ships_Container) { NetworkConnection netConnect = TargetSpecificClient(clientNetID); TargetTellClientToSpawnExistingShips(netConnect, node); } // AND now load old UNITS into this client foreach (NetworkNodeStruct unit in _syncedVars._network_Units_Container) { TargetTellClientToLoadExistingUnits(TargetSpecificClient(clientNetID), unit); } // two lists, first is the NetworkNodeIDIndex that links to the second nodestruct, basicly a shitty dictionary, to get the list index to 'then' use to get the nodestruct int index = DataManipulation.ConvertVectorIntoInt(nodeID); _syncedVars._network_Ships_Indexs.Add(index); _syncedVars._network_Ships_Container.Add(nodeStruct); }
public void CmdTellServerToSpawnPlayerUnit(NetworkInstanceId clientNetID, UnitStruct unitData, int playerID) { if (!isServer) { return; } // figure out what Cube to put unit in KeyValuePair <Vector3Int, Vector3Int> playerPosRot = PlayerManager.GetPlayerStartPosition(playerID); //Debug.Log("Ship Node location >> " + playerPosRot.Key); Vector3Int unitShipLoc = new Vector3Int(Mathf.FloorToInt(unitData.UnitShipLoc.x), Mathf.FloorToInt(unitData.UnitShipLoc.y), Mathf.FloorToInt(unitData.UnitShipLoc.z)); Vector3Int unitStartLoc = new Vector3Int((unitShipLoc.x + playerPosRot.Key.x), (unitShipLoc.y + playerPosRot.Key.y), (unitShipLoc.z + playerPosRot.Key.z)); // This is nessicary, We need to get the cube ID unitData.UnitStartingNodeID = unitStartLoc; NetworkNodeStruct nodeStruct = new NetworkNodeStruct() { NodeID = unitStartLoc, StructIndex = _syncedVars._network_Units_Indexs.Count, ClientNetID = clientNetID, PlayerID = playerID, CurrLoc = Vector3.zero, CurrRot = unitData.UnitRot, UnitData = unitData }; // tell all clients to load new unit RpcTellAllClientsToSpawnPlayerUnit(nodeStruct, playerID); // two lists, first is the NetworkNodeIDIndex that links to the second nodestruct, basicly a shitty dictionary, to get the list index to 'then' use to get the nodestruct _syncedVars._network_Units_Indexs.Add(DataManipulation.ConvertVectorIntoInt(unitStartLoc)); _syncedVars._network_Units_Container.Add(nodeStruct); }