private void ReceiveData(ushort senderID, byte tag, ushort subject, object data) { if (tag == TagIndex.Controller) { if (subject == TagIndex.ControllerSubjects.JoinMessage) { DarkRiftAPI.SendMessageToID(senderID, TagIndex.Controller, TagIndex.ControllerSubjects.SpawnPlayer, localPlayer.transform.position); } if (subject == TagIndex.ControllerSubjects.SpawnPlayer) { GameObject clone = Instantiate(TrainerPrefabs[(int)trainerData.color], (Vector3)data, Quaternion.identity) as GameObject; clone.GetComponent <Trainer>().networkID = senderID; if (senderID == DarkRiftAPI.id) { localPlayer = clone.GetComponent <Trainer>(); localPlayer.localPlayer = true; localPlayer.Init(trainerData); } } } if (tag == TagIndex.Chat) { if (subject == TagIndex.ChatSubjects.MainChat) { hud.AddToMainChat((string)data); } if (subject == TagIndex.ChatSubjects.BattleChat) { hud.AddToBattleChat((string)data); } } }
void ReceiveData(ushort senderID, byte tag, ushort subject, object data) { //When any data is received it will be passed here, //we then need to process it if it's got a tag of 0 and, if //so, create an object. This is where you'd handle most admin //stuff like that. //Ok, if data has a Controller tag then it's for us if (tag == TagIndex.Controller) { //If a player has joined tell them to give us a player if (subject == TagIndex.ControllerSubjects.JoinMessage) { //Basically reply to them. DarkRiftAPI.SendMessageToID(senderID, TagIndex.Controller, TagIndex.ControllerSubjects.SpawnPlayer, player.position); } //Then if it has a spawn subject we need to spawn a player if (subject == TagIndex.ControllerSubjects.SpawnPlayer) { //Instantiate the player GameObject clone = (GameObject)Instantiate(playerObject, (Vector3)data, Quaternion.identity); //Tell the network player who owns it so it tunes into the right updates. clone.GetComponent <NetworkPlayer>().networkID = senderID; //If it's our player being created allow control and set the reference if (senderID == DarkRiftAPI.id) { clone.GetComponent <Movement.PlayerMovement>().isControllable = true; player = clone.transform; } } } }
void ReceiveData(ushort senderID, byte tag, ushort subject, object data) { //Controller Tag if (tag == TagIndex.Controller && DarkRiftAPI.isConnected) { //If a player has joined tell them to give us a player if (subject == TagIndex.ControllerSubjects.JoinMessage) { //Tell them to spawn you DarkRiftAPI.SendMessageToID(senderID, TagIndex.Controller, TagIndex.ControllerSubjects.SpawnPlayer, player.position); //Later we should use another one to assign the username } //Spawn the player if (subject == TagIndex.ControllerSubjects.SpawnPlayer && DarkRiftAPI.isConnected) { //Instantiate the player GameObject clone = (GameObject)Instantiate(playerObject, (Vector3)data, Quaternion.identity); Debug.Log("Spawned Player"); //Tell the network player who owns it so it tunes into the right updates. clone.GetComponent <N_Movement>().networkID = senderID; //If it's our player being created allow control and set the reference if (senderID == DarkRiftAPI.id && DarkRiftAPI.isConnected) { clone.GetComponent <N_Movement>().isMine = true; player = clone.transform; } } } }
void ReceiveData(ushort senderID, byte tag, ushort subject, object data) { if (tag == NetworkingTags.Room) { if (subject == NetworkingTags.RoomSubjects.JoinRoom) { AddPlayer(senderID); DarkRiftAPI.SendMessageToID(senderID, NetworkingTags.Room, NetworkingTags.RoomSubjects.ReplayToJoin, ""); } else if (subject == NetworkingTags.RoomSubjects.ExitRoom) { RemovePlayer(senderID); } else if (subject == NetworkingTags.RoomSubjects.ReplayToJoin) { AddPlayer(senderID); } } }
void ReceiveData(ushort senderID, byte tag, ushort subject, object data) { //When any data is received it will be passed here, //we then need to process it if it's got a tag of 0 and, if //so, create an object. This is where you'd handle most admin //stuff like that. //Ok, if data has a Controller tag then it's for us if (tag == TagIndex.Controller) { //If a player has joined tell them to give us a player if (subject == TagIndex.ControllerSubjects.JoinMessage) { //Basically reply to them. DarkRiftAPI.SendMessageToID(senderID, TagIndex.Controller, TagIndex.ControllerSubjects.SpawnPlayer, player.position); Debug.Log("Replay to ID: " + senderID.ToString() + " " + player.position.ToString()); } //Then if it has a spawn subject we need to spawn a player if (subject == TagIndex.ControllerSubjects.SpawnPlayer) { //Instantiate the player GameObject clone = (GameObject)Instantiate(playerObject, (Vector3)data, Quaternion.identity); //Tell the network player who owns it so it tunes into the right updates. //clone.GetComponent<PlayerAvatarVR>().ObjectID = senderID; //clone.GetComponentInChildren<NetworkPlayerVTRK>().ObjectID = (ushort)(senderID*100); clone.transform.Find("Head").gameObject.GetComponent <NetworkPlayerVTRK>().ObjectID = (ushort)(senderID * 100); clone.transform.Find("RightHand").gameObject.GetComponent <NetworkPlayerVTRK>().ObjectID = (ushort)(senderID * 100 + 1); clone.transform.Find("LeftHand").gameObject.GetComponent <NetworkPlayerVTRK>().ObjectID = (ushort)(senderID * 100 + 2); //How to ObjectID for Head, RightHand, LeftHand? //If it's our player being created allow control and set the reference if (senderID == DarkRiftAPI.id) { player = clone.transform; player.GetComponent <AvatarCameraRigSync> ().enabled = true; Debug.Log("SpawnPlayer ObjectID: " + clone.GetComponentInChildren <NetworkPlayerVTRK>().ObjectID.ToString() + " in position " + data.ToString()); } } } }
void ReceiveData(ushort senderID, byte tag, ushort subject, object data) { //When any data is received it will be passed here, //we then need to process it if it's got a tag of 0 and, if //so, create an object. This is where you'd handle most adminy //stuff like that. //Ok, if data has a Controller tag then it's for us if (tag == NetworkingTags.Controller) { //If a player has joined tell them to give us a player //Also internally increase the amount of players. if (subject == NetworkingTags.ControllerSubjects.JoinMessage) { CurrentPlayer.Instance.AmountOfPlayers++; int color = (int)data; MinersBombMinersServerPlugin.MinersBombMinersServerPlugin.PlayerType player = (MinersBombMinersServerPlugin.MinersBombMinersServerPlugin.PlayerType)color; if (ourColor == MinersBombMinersServerPlugin.MinersBombMinersServerPlugin.PlayerType.None) { ourColor = player; } if (senderID != DarkRiftAPI.id) { DarkRiftAPI.SendMessageToID(senderID, NetworkingTags.Controller, NetworkingTags.ControllerSubjects.ReplyToJoin, ourColor); } else { DarkRiftAPI.SendMessageToServer(NetworkingTags.Server, NetworkingTags.ServerSubjects.GetMoneyForPlayer, DarkRiftAPI.id); } color -= 1; KillTrackSystem.Instance.AddPlayer(senderID, new PlayerStats()); ConnectDisconnect.instance.AddPlayer(color, senderID); int ThisPlayerColor = ConnectDisconnect.instance.GetPlayerColor(DarkRiftAPI.id); if (ThisPlayerColor != -1) { CurrentPlayer.Instance.HPIconSprite = StartingSprite[ThisPlayerColor]; } CurrentPlayer.Instance.UpdateHealthPointInGame(); } else if (subject == NetworkingTags.ControllerSubjects.SpawnPlayer) { } else if (subject == NetworkingTags.ControllerSubjects.ReadyToStartGame) { PlayerReady++; } else if (subject == NetworkingTags.ControllerSubjects.ReplyToJoin) { CurrentPlayer.Instance.AmountOfPlayers++; MinersBombMinersServerPlugin.MinersBombMinersServerPlugin.PlayerType player = (MinersBombMinersServerPlugin.MinersBombMinersServerPlugin.PlayerType)data; int color = (int)player; color -= 1; ConnectDisconnect.instance.AddPlayer(color, senderID); KillTrackSystem.Instance.AddPlayer(senderID, new PlayerStats()); } else if (subject == NetworkingTags.ControllerSubjects.YouWin) { CheckWinLose(WinLoseDraw.Win); } else if (subject == NetworkingTags.ControllerSubjects.Draw) { CheckWinLose(WinLoseDraw.Draw); } else if (subject == NetworkingTags.ControllerSubjects.YouLose) { CheckWinLose(WinLoseDraw.Lose); } else if (subject == NetworkingTags.ControllerSubjects.GameOver) { RestartButton.SetActive(true); } else if (subject == NetworkingTags.ControllerSubjects.GetMoneyForPlayer) { CurrentPlayer.Instance.Money = (int)data; } else if (subject == NetworkingTags.ControllerSubjects.StartGame) { List <MinersBombMinersServerPlugin.PacketUseTypeID> PacketPlayerData = (List <MinersBombMinersServerPlugin.PacketUseTypeID>)data; for (int i = 0; i < PacketPlayerData.Count; i++) { Vector2 SpawnPoint = Vector2.zero; RuntimeAnimatorController theColoredPlayer = PlayerAnimators[0]; switch (PacketPlayerData[i].thePlayerType) { case 1: theColoredPlayer = PlayerAnimators[0]; SpawnPoint = new Vector2(1, 1); break; case 2: SpawnPoint = new Vector2(theTileMap.size_x - 2, theTileMap.size_z - 2); theColoredPlayer = PlayerAnimators[1]; break; case 3: SpawnPoint = new Vector2(theTileMap.size_x - 2, 1); theColoredPlayer = PlayerAnimators[2]; break; case 4: SpawnPoint = new Vector2(1, theTileMap.size_z - 2); theColoredPlayer = PlayerAnimators[3]; break; default: Debug.LogWarning("No such player type found! Logged " + PacketPlayerData[i].thePlayerType); break; } GameObject clone; if (PacketPlayerData[i].client_id == DarkRiftAPI.id) { clone = Lean.LeanPool.Spawn(PlayerPrefab, theTileMap.ConvertTileToWorld(SpawnPoint), Quaternion.identity); Player thePlayer = clone.GetComponentInChildren <Player>(); thePlayer.player_id = PacketPlayerData[i].client_id; thePlayer.theController = this; thePlayer.theEquipments = CurrentPlayer.Instance.AmountOfEquipments; CurrentPlayer.Instance.ThePlayer = thePlayer; UiHolder theHolder = GetComponent <UiHolder>(); HealthBar healthBar = clone.GetComponentInChildren <HealthBar>(); healthBar.damageImage = theHolder.DamageHealth; } else { clone = Lean.LeanPool.Spawn(PlayerDummy, theTileMap.ConvertTileToWorld(SpawnPoint), Quaternion.identity); DummyPlayer thePlayer = clone.GetComponentInChildren <DummyPlayer>(); thePlayer.id = PacketPlayerData[i].client_id; } clone.GetComponentInChildren <Animator>().runtimeAnimatorController = theColoredPlayer; } StartCoroutine(StartCountdown()); } else if (subject == NetworkingTags.ControllerSubjects.DisconnectYou) { DarkRiftAPI.Disconnect(); } } else if (tag == NetworkingTags.Server) { if (subject == NetworkingTags.ServerSubjects.PlayerRestarting) { Debug.Log("Here data is " + data); } } }
void ReceiveData(ushort senderID, byte tag, ushort subject, object data) { bool ignoreMessage = false; if (ignoreMessage) { return; } if (tag == TagIndex.Controller) { if (subject == TagIndex.ControllerSubjects.JoinMessage) { networkConnected = true; DarkRiftAPI.SendMessageToID(senderID, TagIndex.Controller, TagIndex.ControllerSubjects.SpawnPlayer, null); SendData(TagIndex.Controller, TagIndex.PlayerUpdate, factions[DarkRiftAPI.id - 1]); if (senderID == 1) { playerNumber = 2; } if (senderID > playerCount) { playerCount = senderID; } //GameObject.Find("Name1").GetComponent<UnityEngine.UI.InputField>().readOnly = true; //GameObject.Find("Name2").GetComponent<UnityEngine.UI.InputField>().readOnly = false; //Handle Connect message } if (subject == TagIndex.ControllerSubjects.SpawnPlayer) { networkConnected = true; //Handle spawning the player into our game } if (subject == TagIndex.PlayerUpdate) { if (data is string && (data as string) == "ERROR") { possibleDesyncOccurred = true; RetrySendData(); } if (data is string[]) { string[] name = data as string[]; if (name[0] == "name") { GameObject go = GameObject.Find("Name" + (senderID).ToString()); go.GetComponent <UnityEngine.UI.InputField>().text = name[1]; } else if (name[0] == "StartGame") { DontDestroyOnLoad(transform.gameObject); DontDestroyOnLoad(GameObject.Find("GameInitiator")); //if (NetManager.playerCount >= 2) //{ // GameInit.mapName = GameInit.mapNames[NetManager.playerCount - 2]; //} //string mapDropDownText = GameObject.Find("mapDropDown").GetComponent<Dropdown>().itemText.text; //GameInit.mapName = mapDropDownText.Split(' ')[1]; GameInit.mapName = name[1]; SceneManager.LoadScene(GameInit.mapName); //SceneManager.LoadScene("Main"); } else if (name[0] == "charUpdate") { GameObject.Find(name[1]).GetComponent <UnityEngine.UI.Dropdown>().value = int.Parse(name[2]); } } if (data is UnitUpdate /*&& messageIndex + 1 == (data as UnitUpdate).index*/) { UnitUpdate update = data as UnitUpdate; GameObject unitsParent = GameObject.Find("Units Parent"); Unit[] units = unitsParent.GetComponentsInChildren <Unit>(); CellGrid grid = GameObject.Find("CellGrid").GetComponent <CellGrid>(); messageIndex = update.index; if (IsEndTurnCommand(update)) { grid.EndTurn(); //end turn } else if (IsMoveUnitCommand(update)) { foreach (Unit u in units) { if (u.unitIndex == update.moving) { //CellGrid grid = GameObject.Find("CellGrid").GetComponent<CellGrid>(); foreach (Cell c in grid.Cells) { if (c.transform.position.x == update.newLocationX && c.transform.position.y == update.newLocationY) { u.AdjustCellMovementCosts(); var path = u.FindPath(grid.Cells, c); u.ResetMovementPoints(); u.Move(c, path); u.ResetMovementPoints(); break; } } break; } } } else if (IsAttackCommand(update)) { Unit attacker = null; Unit defender = null; foreach (Unit u in units) { if (u.unitIndex == update.moving) { attacker = u; //CellGrid grid = GameObject.Find("CellGrid").GetComponent<CellGrid>(); } if (u.unitIndex == update.target) { defender = u; } if (attacker != null && defender != null) { attacker.DealDamage(defender, true); //attack break; } } } else if (IsSpawnUnitCommand(update)) { foreach (Unit c in grid.Units) { if (c.transform.position.x == update.newLocationX && c.transform.position.y == update.newLocationY) { if (c is BarracksUnit) { (c as BarracksUnit).InstantiateUnit(update.type); } else if (c is BuildSite) { if (update.type >= UnitType.INFANTRY && update.type <= UnitType.ANTIAIR) { //TODO 1 //guiCamRef.GetComponent<NewBarracks>().SpawnAStarFromNetwork((int)update.type, (int)update.moving); guiCamRef.GetComponent <NewBarracks>().SpawnUnitFromNetwork((int)update.type, (int)update.moving, 1); //GameObject.Find("GUICamera").GetComponent<NewBarracks>().SpawnAStarFromNetwork((int)update.type, (int)update.index); } else if (update.type >= UnitType.ANDROID && update.type <= UnitType.TURRET) { guiCamRef.GetComponent <NewBarracks>().SpawniFactionFromNetwork((int)update.type, (int)update.moving); } else if (update.type >= UnitType.ADVERSARY && update.type <= UnitType.STASISGUN) { guiCamRef.GetComponent <NewBarracks>().SpawnusbFromNetwork((int)update.type, (int)update.moving); } //(c as BuildSite).InstantiateUnit(update.type); } break; } } foreach (Unit c in grid.Units) { if (c.transform.position.x == update.newLocationX && c.transform.position.y == update.newLocationY) { if (c is Airport) { (c as Airport).InstantiateUnit(update.type); } else if (c is BuildSite) { if (update.type >= UnitType.FIGHTER && update.type <= UnitType.COPTER) { guiCamRef.GetComponent <NewAirport>().SpawnAStarFromNetwork((int)update.type, (int)update.moving); } else if (update.type >= UnitType.CAPCOPTER && update.type <= UnitType.BOMB) { guiCamRef.GetComponent <NewAirport>().SpawniFactionFromNetwork((int)update.type, (int)update.moving); } else if (update.type >= UnitType.ORBITALSTRIKER && update.type <= UnitType.NULLSTAR) { guiCamRef.GetComponent <NewAirport>().SpawniFactionFromNetwork((int)update.type, (int)update.moving); } //(c as BuildSite).InstantiateUnit(update.type); } break; } } //CellGrid grid = GameObject.Find("CellGrid").GetComponent<CellGrid>() } else if (IsCaptureCommand(update)) { } else if (IsIncreaseMoneGenCommand(update)) { foreach (Unit c in grid.Units) { if (c.unitIndex == update.moving) { if (c is City) { (c as City).SelfIncreaseMoneyGenIfAble(); } else if (c is BuildSite) { (c as BuildSite).SelfIncreaseMoneyGenIfAble(); } } } } else if (IsUpgradeBuildSiteCommand(update)) { BuildSite site = null; foreach (Unit b in GameObject.Find("CellGrid").GetComponent <CellGrid>().Units) { if (b is BuildSite && b.unitIndex == update.moving) { site = b as BuildSite; break; } } if (site == null) { return; } //handle cost Debug.Log("Site == null: " + (site == null).ToString()); Debug.Log("update == null: " + (update == null).ToString()); Debug.Log(NetManager.buildCosts[(int)update.buildingType - 1]); if (!site.CanAffordToBuild(NetManager.buildCosts[(int)update.buildingType - 1])) { return; } site.grid.Players[site.PlayerNumber].Money -= NetManager.buildCosts[(int)update.buildingType - 1]; PlayerController.currTurnMoney = site.grid.Players[site.PlayerNumber].Money; GameObject.Find("Canvas").GetComponentsInChildren <Text>()[site.PlayerNumber].text = PlayerController.currTurnMoney.ToString() + "G" + "(+" + site.grid.Players[site.PlayerNumber].income.ToString() + "G)"; site.buildingType = update.buildingType; site.GetComponent <ChangeMaterial>().SetNewMaterial(update.buildingType); } else if (data is UnitUpdate && messageIndex + 1 != (data as UnitUpdate).index) { possibleDesyncOccurred = true; SendData(TagIndex.Controller, TagIndex.PlayerUpdate, "ERROR"); //send error message } } else if (data is Unit.Faction) { factions[senderID - 1] = (Unit.Faction)data; } } } }