Ejemplo n.º 1
0
 public static void Disconnect()
 {
     OperationNetwork.connected = false;
     Debug.LogError("Disconnect");
     try
     {
         if (OperationNetwork.isServer)
         {
             if (OperationNetwork.getClient(32767) != null)
             {
                 OperationNetwork.getClient(32767).file.Close();
             }
             if (myServer != null)
             {
                 NetworkTransport.Shutdown();
             }
         }
         else
         {
             if (myClient != null)
             {
                 myClient.disconnect();
             }
         }
     }
     catch (Exception e)
     {
         Debug.LogError("On Disconnect: " + e.Message);
     }
 }
Ejemplo n.º 2
0
 //
 static int ResendTicks(GameObject obj, byte[] data, int fromWho)
 {
     // Full Resend is done..
     if (GameManager.PlayerExists((short)fromWho))
     {
         OperationNetwork.getClient((short)fromWho).shouldNextSendOutBeFullSendOut = true;
     }
     else
     {
         // hmm
     }
     return(0);
 }
Ejemplo n.º 3
0
    // Server only. This is called manually by the server.
    // OperationRPC
    public static void PlayerConnect(string name, short who)     // Information that should be sent to new players: team, kills, deaths
    {
        if (who != OperationNetwork.FromServerClient)
        {
            OperationNetwork.getClient(who).connected = true;              // This is so no data is sent before the following data:

            OperationNetwork.sendDataToSpecificClient(BitConverter.GetBytes(who), who);
        }

        GameObject pSObject = MonoBehaviour.Instantiate(playerSync);

        // Set ID, name, etc. (todo)
        pSObject.GetComponent <Player> ().playerOwner = who;
        pSObject.GetComponent <Player> ().playerName  = name;
        pSObject.GetComponent <Player> ().team        = 0; // Default (Could be based on an "autobalance" system.
        pSObject.GetComponent <Player> ().classNum    = 0; // Default (Could be random)
        OperationNetwork.OperationAddSyncState(pSObject);
    }
Ejemplo n.º 4
0
    void HudUpdate()
    {
        GameManager.UpdateKillFeed();

        HealthBarUpdate();

        UpdateTrapSelectionZoneMenu();

        for (int i = 0; i < trapsHud.Length; i++)
        {
            trapsHud [i].SetActive(isTrapSelectionMenuOpen);
        }

        respawnHud.transform.parent.gameObject.SetActive(Player.thisPlayer != null && Player.thisPlayer.playerObject == null);
        if (Player.thisPlayer != null && Player.thisPlayer.playerObject == null)
        {
            respawnHud.fillAmount = Mathf.Clamp01(1 - Player.thisPlayer.getRespawnTimer() / Player.thisPlayer.getNetRespawnTimer());
            respawnHud.transform.parent.GetComponent <Image>().fillAmount = Mathf.Clamp01(Player.thisPlayer.getRespawnTimer() / Player.thisPlayer.getNetRespawnTimer());
            int respawnTimer = (int)(Player.thisPlayer.getRespawnTimer() + 1);
            if (respawnTimer == 1)
            {
                respawnHud.transform.parent.Find("Text").GetComponent <Text> ().text = "Respawning in 1 second.";
            }
            else
            {
                respawnHud.transform.parent.Find("Text").GetComponent <Text> ().text = "Respawning in " + respawnTimer + " seconds.";
            }
        }

        // Class Selection Hud gets priority
        if (Player.thisPlayer && Player.thisPlayer.team == 1 && !OptionsMenu.classSelectionMenuOpen)
        {
            bool needTrap = false;
            for (int i = 0; i < Player.thisPlayer.trapTypes.Length; i++)
            {
                if (Player.thisPlayer.trapTypes [i] == 255)
                {
                    needTrap = true;
                }
            }
            if (needTrap && !PlayerHud.isTrapSelectionMenuOpen)
            {
                PlayerHud.isTrapSelectionMenuOpen = true;

                OptionsMenu.ChangeLockState();
            }
            else if (!needTrap && PlayerHud.isTrapSelectionMenuOpen)
            {
                PlayerHud.isTrapSelectionMenuOpen = false;
                OptionsMenu.ChangeLockState();
            }
        }

        if (Player.thisPlayer && PlayerHud.isTrapSelectionMenuOpen)
        {
            for (int x = 0; x < trapsChoices.GetLength(0); x++)
            {
                for (int y = 0; y < trapsChoices.GetLength(1); y++)
                {
                    trapsChoices [x, y].transform.Find("Text").GetComponent <Text> ().text = BuyNewTrap.trapNames [BuyNewTrap.trapIndecies[Player.thisPlayer.myRandomTrapChoices[x * trapsChoices.GetLength(1) + y]]];
                    trapsChoices [x, y].GetComponent <BuyNewTrap> ().buyId = Player.thisPlayer.myRandomTrapChoices [x * trapsChoices.GetLength(1) + y];
                    trapsChoices [x, y].GetComponent <BuyNewTrap> ().rowID = (byte)x;
                }
            }
        }

        // This is how HUD should work for all unlocks:
        if (Player.thisPlayer)
        {
            for (int i = 0; i < displayTraps.Length; i++)
            {
                byte actual = Player.thisPlayer.trapTypes [i];
                if (Player.thisPlayer.team != 1)
                {
                    actual = 255;
                }
                if (displayTraps [i] != actual)
                {
                    displayTraps [i] = actual;
                    if (displayTraps [i] == 255 || Player.thisPlayer.team != 1)
                    {
                        trapPlayerHudTypes [i].SetActive(false);
                    }
                    else
                    {
                        trapPlayerHudTypes [i].SetActive(true);
                        trapPlayerHudTypes [i].transform.Find("Text").GetComponent <Text> ().text = "(" + OptionsMenu.getBindString(OptionsMenu.binds [OptionsMenu.TRAP_1 + i]) + ") " + BuyNewTrap.trapNames [BuyNewTrap.trapIndecies[displayTraps [i]]];
                    }
                }


                if (displayTraps[i] != 255 && Player.thisPlayer.playerObject)
                {
                    int trapTypeIndex = BuyNewTrap.trapIndecies[Player.thisPlayer.trapTypes [i]];
                    PlacePlayerMade.setCharge(trapPlayerHudTypes [i],
                                              Mathf.Clamp01((Player.thisPlayer.playerObject.GetComponent <SyncPlayer>().playerTime - Player.thisPlayer.trapCoolDownsStartedAt [i]) / (float)(BuyNewTrap.baseTrapCosts [trapTypeIndex] * BuyNewTrap.maxTrapsLoaded[trapTypeIndex] * Time.fixedDeltaTime)),
                                              1f / BuyNewTrap.maxTrapsLoaded[trapTypeIndex]);
                }
            }
        }

        if (OperationNetwork.connected)
        {
            if (Time.time - lastNetworkSettingsRead > 1)
            {
                if (OperationNetwork.isServer)
                {
                    dataSentPerSecond = OperationNetwork.getClient(32767).dataSent / (Time.time - lastNetworkSettingsRead);
                    OperationNetwork.getClient(32767).dataSent  = 0;
                    networkSettings.GetComponent <Text> ().text = (int)(dataSentPerSecond / 100) / 10.0f + " KB/s";
                }
                else
                {
                    dataSentPerSecond            = RunGame.myClient.dataOutRate / (Time.time - lastNetworkSettingsRead);
                    RunGame.myClient.dataOutRate = 0;
                    float dataRecievedPerSecond = RunGame.myClient.dataInRate / (Time.time - lastNetworkSettingsRead);
                    RunGame.myClient.dataInRate = 0;

                    networkSettings.GetComponent <Text> ().text = "Sent: " + (int)(dataSentPerSecond / 100) / 10.0f +
                                                                  " KB/s Recieved: " + (int)(dataRecievedPerSecond / 100) / 10.0f + " KB/s";
                }
                lastNetworkSettingsRead = Time.time;
            }
        }

        if (OperationNetwork.connected && Player.thisPlayer != null && Player.thisPlayer.playerObject != null)
        {
            PlayerMove pMove        = Player.thisPlayer.playerObject.GetComponent <PlayerMove> ();
            float      touchPercent = DamageCircle.isTouchingDamageCircle(pMove.timeSinceTouchingDamageCircle);
            if (touchPercent > 0)
            {
                buffHud.transform.parent.GetComponent <Image> ().enabled = true;
                buffHud.enabled    = true;
                buffHud.fillAmount = touchPercent;
            }
            else
            {
                // Disable the rendering of it:
                buffHud.transform.parent.GetComponent <Image> ().enabled = false;
                buffHud.enabled = false;
            }
            healthHud.enabled = true;
            healthHud.transform.parent.GetComponent <Image> ().enabled = true;
            healthHudText.enabled = true;
            healthHud.transform.parent.GetComponent <Image> ().fillAmount = 1 - pMove.GetComponent <Combat> ().health / pMove.GetComponent <Combat> ().maxHealth;
            healthHud.fillAmount = pMove.GetComponent <Combat> ().health / pMove.GetComponent <Combat> ().maxHealth;
            healthHudText.text   = (short)pMove.GetComponent <Combat> ().health + " HP";

            if (Player.thisPlayer.playerObject != playerObjectHudLoaded)
            {
                playerObjectHudLoaded = Player.thisPlayer.playerObject;

                float origNum = getHudHeightUsed(classHud.transform);

                // Unload old hud:
                foreach (Transform t in classHud.transform)
                {
                    if (t.name != "AdjacentClassHud")
                    {
                        Destroy(t.gameObject);
                    }
                }
                foreach (Transform t in classHud.transform.Find("AdjacentClassHud"))
                {
                    Destroy(t.gameObject);
                }

                // Create new hud:
                foreach (Unlock unlock in Player.thisPlayer.playerObject.GetComponent <ClassControl>().getUnlocks())
                {
                    if (unlock != null)
                    {
                        unlock.setHudElement(classHud.transform, origNum);
                    }
                }

                int classLoaded = Player.thisPlayer.playerObject.GetComponent <ClassControl> ().classNum;

                // Phase through & Speed Boost are not unlocks, despite having some similar qualities: (Like the HUD)
                if (classLoaded == 0)
                {
                    Player.thisPlayer.playerObject.GetComponent <PlayerMove> ().hudElement  = Unlock.setHudElement(classHud.transform, "Cooldown", "Phase Shift", OptionsMenu.MOVEMENT_ABILITY_BIND, null, origNum);
                    Player.thisPlayer.playerObject.GetComponent <PlayerMove> ().hudElement2 = Unlock.setHudElement(classHud.transform, "Armor", "Armor", OptionsMenu.MAIN_ABILITY, null, origNum);
                }
                else if (classLoaded == 3)
                {
                    Player.thisPlayer.playerObject.GetComponent <PlayerMove> ().hudElement = Unlock.setHudElement(classHud.transform, "Cooldown", "Speed Boost", OptionsMenu.MOVEMENT_ABILITY_BIND, null, origNum);
                }
                else if (classLoaded == 4)
                {
                    if (OptionsMenu.hudPanels.ContainsKey("Healthtaken"))
                    {
                        Player.thisPlayer.playerObject.GetComponent <PlayerMove> ().hudElement = Unlock.setHudElement(classHud.transform, "Healthtaken", "Health Taken", OptionsMenu.ULTIMATE_ABILITY, null, origNum);
                    }
                }

                // The updating for the HUD is handled within the unlocks / class itself
            }
        }
        else
        {
            // Hide hud completely:
            buffHud.transform.parent.GetComponent <Image> ().enabled = false;
            buffHud.enabled   = false;
            healthHud.enabled = false;
            healthHud.transform.parent.GetComponent <Image> ().enabled = false;
            healthHudText.enabled = false;
        }

        // SCOREBOARD:
        if (Input.GetKey(KeyCode.Tab))
        {
            scoreBoard.SetActive(true);
            for (byte team = 0; team < 2; team++)
            {
                List <Player> players = GameManager.getPlayersOnTeam(team);
                for (int i = 0; i < scoreBoardPlayers[team].Count; i++)
                {
                    if (i < players.Count)
                    {
                        scoreBoardPlayers [team] [i].SetActive(true);
                        scoreBoardPlayers [team] [i].transform.Find("Text").GetComponent <Text> ().text = players [i].playerName;
                        Color c = scoreBoardPlayers [team] [i].GetComponent <Image> ().color;
                        if (players [i].playerObject != null)
                        {
                            scoreBoardPlayers [team] [i].GetComponent <Image> ().color = new Color(c.r, c.g, c.b, 1f);
                        }
                        else
                        {
                            scoreBoardPlayers [team] [i].GetComponent <Image> ().color = new Color(c.r, c.g, c.b, 0.2f);
                        }
                        scoreBoardKills [team] [i].text  = "" + players[i].kills;
                        scoreBoardDeaths [team] [i].text = "" + players[i].deaths;
                    }
                    else
                    {
                        scoreBoardPlayers [team] [i].SetActive(false);
                        scoreBoardKills [team] [i].text  = "";
                        scoreBoardDeaths [team] [i].text = "";
                    }
                }
            }
        }
        else
        {
            scoreBoard.SetActive(false);
        }

        // Display kill feed:
        for (int i = 0; i < killFeed.Count; i++)
        {
            if (GameManager.recentPlayerKillers.Count > i)
            {
                killFeed [i].parent.gameObject.SetActive(true);
                string killDisplay = "";
                if (GameManager.PlayerExists(GameManager.recentPlayerKillers [i]))
                {
                    killDisplay = GameManager.GetPlayer(GameManager.recentPlayerKillers [i]).playerName + " killed ";
                }
                if (GameManager.PlayerExists(GameManager.recentPlayerDeaths [i]))
                {
                    killFeed [i].GetComponent <Text> ().text = killDisplay + GameManager.GetPlayer(GameManager.recentPlayerDeaths [i]).playerName;
                }
            }
            else
            {
                killFeed [i].parent.gameObject.SetActive(false);
            }
        }

        // Class Selection Menu:
        if (OptionsMenu.classSelectionMenuOpen && Player.thisPlayer != null)
        {
            classSelectionMenu.SetActive(true);
            Color color;
            if (Player.thisPlayer.team == 0)
            {
                color = new Color(0, 0, 1f, 0.5f);
            }
            else if (Player.thisPlayer.team == 1)
            {
                color = new Color(1f, 0, 0, 0.5f);
            }
            else
            {
                color = new Color(1f, 1f, 1f, 0.5f);
            }

            classSelectionMenu.GetComponent <Image> ().color = color;
            for (byte i = 0; i < classSelectionTeams.Length; i++)
            {
                if (Player.thisPlayer.team == i)
                {
                    classSelectionTeams [i].color = new Color(classSelectionTeams [i].color.r, classSelectionTeams [i].color.g, classSelectionTeams [i].color.b, 1f);
                }
                else
                {
                    classSelectionTeams [i].color = new Color(classSelectionTeams [i].color.r, classSelectionTeams [i].color.g, classSelectionTeams [i].color.b, 0.6f);
                }
            }
            for (byte i = 0; i < classTypes.Count; i++)
            {
                if (Player.thisPlayer.team == 0)
                {
                    classTypes [i].gameObject.SetActive(true);
                    if (Player.thisPlayer.classNum == i)
                    {
                        classTypes [i].color = new Color(0.2f, 0.2f, 1f, 1f);
                    }
                    else
                    {
                        classTypes [i].color = new Color(0.7f, 0.7f, 1f, 0.8f);
                    }
                }
                else if (Player.thisPlayer.team == 1)
                {
                    classTypes [i].gameObject.SetActive(true);
                    if (Player.thisPlayer.classNum == i)
                    {
                        classTypes [i].color = new Color(1f, 0.2f, 0.2f, 1f);
                    }
                    else
                    {
                        classTypes [i].color = new Color(1f, 0.7f, 0.7f, 0.8f);
                    }
                }
                else
                {
                    classTypes [i].gameObject.SetActive(false);
                }
            }
        }
        else
        {
            classSelectionMenu.SetActive(false);
        }
    }
Ejemplo n.º 5
0
    // There is a limited amount of information that must be sent to only the player.
    // ALL of this information can come in multiple / none form, with the exception of Predi
    // It includes:

    /*
     * PredictionError
     * DamageNumber Callback
     * DamageHit From (Vector3 / amount)
     */
    public override object getObjectThis(int num, bool isPlayerOwner)
    {
        if (!isPlayerOwner)
        {
            switch (num)
            {
            case 0:
                return(playerOwner);                // This has to be first.

            case 1:
                return((short)Mathf.CeilToInt(GetComponent <Combat> ().health));

            case 2:
                return(transform.position);

            case 3:
                return(new YRotation(transform.eulerAngles.y));

            case 4:
                return(new UpDownRotation(-GetComponent <PlayerMove> ().mainCamera.transform.eulerAngles.x));

            case 5:
                return(GetComponent <ClassControl> ().nextUnlock);

            case 6:
                return(currentTriggerSet);

            case 7:
                // Boolean data for player:
                byte returnByte = 0;
                if (GetComponent <PlayerMove> ().isGrounded)
                {
                    returnByte += (byte)(1 << 0);
                }
                if (GetComponent <PlayerMove> ().isCrouched)
                {
                    returnByte += (byte)(1 << 1);
                }
                if (GetComponent <PlayerMove> ().isPhasing() || GetComponent <PlayerMove> ().isSpeedBoosting())
                {
                    returnByte += (byte)(1 << 2);
                }
                if (GetComponent <PlayerMove> ().puttingArmorOn)
                {
                    returnByte += (byte)(1 << 3);
                }
                return(returnByte);

            case 8:
                if (GetComponent <ClassControl> ().classNum == 1)
                {
                    return(GetComponent <ClassControl> ().getUnlockEquippedWithType <Pistol> ().mode);
                }
                else
                {
                    return(null);
                }

            default:
                return(null);
            }
        }
        else
        {
            switch (num)
            {
            case 0:
                return(playerOwner);                // This has to be first.

            case 1:
                return((short)Mathf.CeilToInt(GetComponent <Combat> ().health));

            case 2:
                return(playerTriggerSet);

            case 3:
                if (OperationNetwork.isServer)
                {
                    return(OperationNetwork.getClient(playerOwner).lastPlayerInputGroupID);
                }
                else
                {
                    return((short)0);                    // This is just used for type anyways
                }

            default:
                if (GetComponent <ClassControl> ().classNum == 4 && num == 4)
                {
                    return(GetComponent <ClassControl> ().getHealthTaken());
                }
                return(PlayerState.getObject(num - getPlayerStateStartIndex(), this, GetComponent <PlayerMove>()));
            }
        }
    }