public static void CheckChunks(this OnlinePlayer player) { var client = player.Tcp; if (client.OnlinePlayer != null && client.OnlinePlayer.AssetsReady) { var chunkX = client.OnlinePlayer.X >> 4; var chunkY = client.OnlinePlayer.Y >> 4; List <Position> shouldBeLoaded = MapUtils.GetRadius(new Position(chunkX, chunkY), VIEW_RADIUS); foreach (var position in shouldBeLoaded) { var chunkKey = $"{position.X}_{position.Y}"; if (!client.ChunksLoaded.Contains(chunkKey)) { if (Server.Map.Chunks.ContainsKey(chunkKey)) { client.ChunksLoaded.Add(chunkKey); var chunk = Server.Map.Chunks[chunkKey]; client.Send(new ChunkPacket() { X = position.X, Y = position.Y, ChunkData = chunk.GetData() }); } } } } }
// Update is called once per frame void Update() { try { if (player == null) { player = NetworkClient.connection.identity.GetComponent <OnlinePlayer>(); staticPlayerReference = player; Debug.Log("Started as " + player.name); } if (manager.CheckNumberOfPlayers() && player.name.Equals("Under attack") && isWaiting) { Debug.Log("Second Player Joined"); PlayerTeamController team = GameObject.Find("Player").GetComponent <PlayerTeamController>(); try { SerializableEncounter enc = new SerializableEncounter(team.GetMyTeamAsAnEncounter()); player.SendEncounterData(new SerializableEncounter(enemyEncounter), enc); isWaiting = false; } catch { } } } catch { } }
public void ClearRune() { OnlinePlayer caster = RuneManager.Instance.rightCaster as OnlinePlayer; caster.ClearRune(); RuneManager.Instance.CancelRightRune(); }
public static void RegisterPlayer(string netID, OnlinePlayer player) { string playerID = netID; _players.Add(playerID, player); player.transform.name = playerID; }
// Temp disabled, waiting for server implementation /*public*/ private void CreateOnlinePlayer(LudoType playerType) { var player = new OnlinePlayer(playerType); //rulesManager.AddPlayer(player); players.Add(player); }
protected void Awake() { if (photonView.IsMine) { localInstance = this; onlineLogging = new OnlineLogging(PhotonNetwork.LocalPlayer.NickName); } }
public void RpcSpawnPlayer(string ID, Vector3 position, Quaternion rotation) { if (!isServer) { OnlinePlayer op = GetPlayer(ID); op.transform.position = position; op.transform.rotation = rotation; } }
private Controller() { userNum = 0; pos = new Chess_Position(); object_manager = new Game_object(); AI_instance = AIRule.getInstance(); Manual_instance = ManualRule.getInstance(); OnlinePlayer_instance = OnlinePlayerRule.getInstance(); }
// Start is called before the first frame update void Start() { anim = GetComponent <Animator>(); rb = GetComponent <Rigidbody>(); MovementVector = Vector3.zero; collider = GetComponent <Collider>(); op = GetComponent <OnlinePlayer>(); //DontDestroyOnLoad(gameObject); }
public OnlinePlayer GetOther(OnlinePlayer onlinePlayer) { if (source == onlinePlayer) { return(target); } return(source); }
public override int ReadFrom(byte[] Buffer, int StartIndex = 0) { int cursor = StartIndex; cursor += base.ReadFrom(Buffer, cursor); NewOnlinePlayer = new OnlinePlayer(Buffer, cursor); cursor += NewOnlinePlayer.ByteLength; return(cursor - StartIndex); }
public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId) { base.OnServerAddPlayer(conn, playerControllerId); if (conn.playerControllers.Count > 0) { GameObject player = conn.playerControllers[0].gameObject; OnlinePlayer op = player.GetComponent <OnlinePlayer>(); //TeamManager.SetPlayerTeam(player); //MultiplayerGameManager.instance.SpawnPlayer(player); } }
public IEnumerator LoginCoroutine() { if (OnlinePlayer.Authenticated || !PlayerPrefs.HasKey(PreferenceKeys.LastUsername()) || !PlayerPrefs.HasKey(PreferenceKeys.LastPassword())) { isLoggingIn = false; yield break; } // If not logged in previously yield return(OnlinePlayer.Authenticate()); CloseLoginWindows(); isLoggingIn = false; var authenticationResult = OnlinePlayer.LastAuthenticationResult; switch (authenticationResult.status) { case 0: Popup.Make(this, "Signed in."); rankStatusText.text = PlayerPrefsExt.GetBool("ranked") ? "On" : "Off"; StartCoroutine(LoadAvatarCoroutine()); if (PlayerPrefsExt.GetBool("ranked")) { EventKit.Broadcast("reload rankings"); } BestScoreText.WillInvalidate = true; break; case -1: LoadedAvatar = true; Popup.Make(this, "Could not fetch player data."); break; case 1: // User not exist LoadedAvatar = true; Popup.Make(this, authenticationResult.message); PlayerPrefs.DeleteKey(PreferenceKeys.LastUsername()); PlayerPrefs.DeleteKey(PreferenceKeys.LastPassword()); usernameInput.text = ""; passwordInput.text = ""; break; case 2: // Incorrect password LoadedAvatar = true; Popup.Make(this, authenticationResult.message); PlayerPrefs.DeleteKey(PreferenceKeys.LastPassword()); passwordInput.text = ""; break; } }
private void OnTriggerEnter(Collider other) { OnlinePlayer player = other.gameObject.GetComponent <OnlinePlayer>(); if (player) { Debug.Log("Warninh, I get " + bulletName); Shooter shooter = player.GetComponentInChildren <Shooter>(); shooter.SetBullet(bulletName); ServerDestoryThis(); } }
public void RemovePlayerFromTeam(GameObject player) { OnlinePlayer _player = player.GetComponent <OnlinePlayer>(); if (_player.Team == (int)TeamColor.BLUE) { blueTeamCount -= 1; } else { redTeamCount -= 1; } }
public IEnumerator PostPlayDataCoroutine() { if (IsUploading) { Popup.Make(this, "Already uploading."); } IsUploading = true; EventKit.Broadcast("reload rankings"); Debug.Log("Posting play data"); Popup.Make(this, "Uploading play data..."); yield return(OnlinePlayer.PostPlayData(CytoidApplication.CurrentPlay.IsRanked ? (IPlayData)CytoidApplication.CurrentRankedPlayData : CytoidApplication.CurrentUnrankedPlayData)); switch (OnlinePlayer.LastPostResult.status) { case 200: Popup.Make(this, "Uploaded play data."); EventKit.Broadcast("profile update"); SuccessfullyUploaded = true; break; case 400: Popup.Make(this, "ERROR: " + "Invalid play data."); uploadButton.interactable = true; SuccessfullyUploaded = false; break; case 401: Popup.Make(this, "ERROR: " + "You haven't signed in."); OnlinePlayer.Invalidate(); uploadButton.interactable = true; SuccessfullyUploaded = false; break; default: Popup.Make(this, "ERROR: " + OnlinePlayer.LastPostResult.message); uploadButton.interactable = true; SuccessfullyUploaded = false; break; } IsUploading = false; retryButton.interactable = true; nextButton.interactable = true; }
public override unsafe void ReadFrom(ref byte *Buffer) { base.ReadFrom(ref Buffer); ushort len = *((ushort *)Buffer); Buffer += TypeSizes.SHORT; OnlinePlayers = new OnlinePlayer[len]; for (int i = 0; i < len; i++) { OnlinePlayers[i] = new OnlinePlayer(ref Buffer); } }
public override void OnStartLocalPlayer() { NetworkMenuUI.instance.panel.SetActive(false); base.OnStartLocalPlayer(); if (isLocalPlayer) { localPlayer = this; myID = isServer ? 0 : 1; Debug.LogFormat("MyID = {0}", myID); } //isHost = isServer; //Debug.Log("isServer = " + isHost.ToString()); }
// Start is called before the first frame update void Start() { anim = GetComponent <Animator>(); controller = GetComponent <NetworkPlayerController>(); t = transform; op = GetComponent <OnlinePlayer>(); if (isLocalPlayer) { StartCoroutine(delayCheck()); StartCoroutine(UpdateRotationOnClients()); Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; SciFiWeaponBehaviour.AddRecoil += UpdateCameraForRecoil; } }
private void SendToClients(OnlineScript ScriptToSend, IOnlineConnection Sender) { WriteBuffer.ClearWriteBuffer(); WriteBuffer.WriteScript(ScriptToSend); foreach (IOnlineConnection OnlinePlayer in ListPlayerClient) { if (OnlinePlayer == Sender) { continue; } OnlinePlayer.SendWriteBuffer(); } }
private void SpawnPlayer(string playerName, int cnnId) { //GameObject go = Instantiate (playerObj) as GameObject; if (cnnId == clientId) { //remove canvas GameObject.Find("Canvas").SetActive(false); playField.SetActive(true); isStarted = true; } OnlinePlayer p = new OnlinePlayer(playerName, cnnId); players.Add(cnnId, p); }
private void OnCollisionEnter(Collision collision) { Health health = collision.gameObject.GetComponent <Health>(); OnlinePlayer player = collision.gameObject.GetComponent <OnlinePlayer>(); if (health) { health.DealDamage(damage); //Debug.Log(health.currHealth); Destroy(gameObject); } if (player) { player.RpcSetLastBeingHitID(playerId); } }
public void Logout() { CancelLogin(); PlayerPrefs.DeleteKey(PreferenceKeys.LastUsername()); PlayerPrefs.DeleteKey(PreferenceKeys.LastPassword()); CloseProfileWindows(); OnlinePlayer.Invalidate(); LoadedAvatar = false; Popup.Make(this, "Signed out."); PlayerPrefsExt.SetBool("ranked", false); rankStatusText.text = "Off"; UpdateBestText(); }
public void RuneCountered(bool isHost) { OnlinePlayer oCaster = RuneManager.Instance.rightCaster as OnlinePlayer; Player pCaster = RuneManager.Instance.leftCaster as Player; if (isHost) { oCaster.MyRuneWasCounteredCallback(); pCaster.HideCurrentRuneCallback(); } else { pCaster.MyRuneWasCounteredCallback(); oCaster.HideCurrentRuneCallback(); } }
public static void CheckChunks(this OnlinePlayer player) { var client = player.Tcp; if (client.OnlinePlayer != null && client.OnlinePlayer.AssetsReady) { var chunkX = client.OnlinePlayer.Position.X >> 4; var chunkY = client.OnlinePlayer.Position.Y >> 4; var shouldBeLoaded = MapHelpers.GetSquared3x3(new Position(chunkX, chunkY)); foreach (var position in shouldBeLoaded) { var chunkKey = $"{position.X}_{position.Y}"; if (!client.ChunksLoaded.Contains(chunkKey)) { if (Server.Map.Chunks.ContainsKey(chunkKey)) { client.ChunksLoaded.Add(chunkKey); var chunk = Server.Map.Chunks[chunkKey]; client.Send(new ChunkPacket() { X = position.X, Y = position.Y, ChunkData = chunk.GetData() }); foreach (var entity in chunk.EntitiesInChunk[EntityType.MONSTER]) { var monsterInstance = (Monster)entity; client.Send(new MonsterSpawnPacket() { MonsterUid = monsterInstance.UID, MonsterName = monsterInstance.Name, Position = monsterInstance.Position, SpriteIndex = monsterInstance.GetSpriteAsset().SpriteRowIndex, MoveSpeed = monsterInstance.MoveSpeed, SpawnAnimation = false }); } } } } } }
public void RuneSuccessfullyCreated(string runeName, float power, bool isHost) { Debug.Log(Time.timeSinceLevelLoad + " - rune okayed by host!"); Rune rune = RuneManager.Instance.CloneRuneByName(runeName); rune.power = power; if (isHost) { OnlinePlayer caster = RuneManager.Instance.rightCaster as OnlinePlayer; caster.AppliedRune(rune); } else { // confirmation our cast rune (left player) was a success Player caster = RuneManager.Instance.leftCaster as Player; caster.HostCreatedRune(rune); } }
public override int ReadFrom(byte[] Buffer, int StartIndex = 0) { int cursor = StartIndex; cursor += base.ReadFrom(Buffer, cursor); ushort len = BitConverter.ToUInt16(Buffer, cursor); cursor += TypeSizes.SHORT; OnlinePlayers = new OnlinePlayer[len]; for (int i = 0; i < len; i++) { OnlinePlayers[i] = new OnlinePlayer(Buffer, cursor); cursor += OnlinePlayers[i].ByteLength; } return(cursor - StartIndex); }
//[Server] public void SpawnPlayer(GameObject player) { OnlinePlayer op = player.GetComponent <OnlinePlayer>(); string id = PLAYER_NAME_PREFIX + op.netId; int point = UnityEngine.Random.Range(0, spawnPoints.Length); //player.GetComponent<NetworkCameraController>().ResetOrientationOnSpawn(); player.transform.position = spawnPoints[point].transform.position + new Vector3(0.2f, 0, 0); player.transform.forward = spawnPoints[point].transform.forward; //RpcSpawnPlayer(id, spawnPoints[point].transform.position, spawnPoints[point].transform.rotation); //if (op.Team == (int)TeamColor.BLUE) //{ // foreach(SpawnPoint sp in instance.blueSpawnPoints) // { // if (!sp.isBlocked) // { // player.transform.position = sp.transform.position + new Vector3(0.2f, 0, 0); // player.transform.forward = sp.transform.forward; // Debug.Log("Spawning Player_" + op.netId + " on " + sp.name); // RpcSpawnPlayer(id, sp.transform.position, sp.transform.rotation); // return; // } // } //} //else //{ // foreach (SpawnPoint sp in instance.redSpawnPoints) // { // if (!sp.isBlocked) // { // player.transform.position = sp.transform.position + new Vector3(0.2f, 0, 0); // player.transform.forward = sp.transform.forward; // Debug.Log("Spawning Player_" + op.netId + " on " + sp.name); // RpcSpawnPlayer(id, sp.transform.position, sp.transform.rotation); // return; // } // } //} }
public void AssignPlayerToTeam(GameObject player) { OnlinePlayer op = player.GetComponent <OnlinePlayer>(); string id = PLAYER_NAME_PREFIX + op.netId; if (redTeamCount > blueTeamCount) { //op.AssignColor((int)TeamColor.BLUE); op.Team = (int)TeamColor.BLUE; blueTeamCount += 1; Debug.Log("Assigning Player_" + op.netId + " to Blue Team"); //RpcAssignPlayerToTeam(id, (int)TeamColor.BLUE); } else if (blueTeamCount > redTeamCount) { //op.AssignColor((int)TeamColor.RED); op.Team = (int)TeamColor.RED; redTeamCount += 1; Debug.Log("Assigning Player_" + op.netId + " to Red Team"); //RpcAssignPlayerToTeam(id, (int)TeamColor.RED); } else { if (UnityEngine.Random.Range(1, 3) == 1) { //op.AssignColor((int)TeamColor.BLUE); op.Team = (int)TeamColor.BLUE; blueTeamCount += 1; Debug.Log("Assigning Player_" + op.netId + " to Blue Team"); //RpcAssignPlayerToTeam(id, (int)TeamColor.BLUE); } else { //op.AssignColor((int)TeamColor.RED); op.Team = (int)TeamColor.RED; redTeamCount += 1; Debug.Log("Assigning Player_" + op.netId + " to Red Team"); //RpcAssignPlayerToTeam(id, (int)TeamColor.RED); } } }
public static void CheckChunks(this OnlinePlayer player) { var client = player.Tcp; if (client.OnlinePlayer != null && client.OnlinePlayer.AssetsReady) { var chunkX = client.OnlinePlayer.Position.X >> 4; var chunkY = client.OnlinePlayer.Position.Y >> 4; var shouldBeLoaded = PositionExtensions.GetSquared3x3Around(new Position(chunkX, chunkY)); foreach (var position in shouldBeLoaded) { var chunkKey = $"{position.X}_{position.Y}"; if (!client.ChunksLoaded.Contains(chunkKey)) { if (Server.Map.Chunks.ContainsKey(chunkKey)) { client.ChunksLoaded.Add(chunkKey); var chunk = Server.Map.Chunks[chunkKey]; client.Send(new ChunkPacket() { X = position.X, Y = position.Y, ChunkData = chunk.TilePacketData }); foreach (var entity in chunk.EntitiesInChunk[EntityType.MONSTER]) { var monsterInstance = (Monster)entity; client.Send(monsterInstance.ToPacket()); } } } } } }