Пример #1
0
    // Player only
    // -1 for missDistance is used to indicate a random missDistance & random missAngle.
    public override void fire(PlayerInput pI, float missDistance, float missAngle, int isThisShotgun, int shotIndex, out Combat playerHit, out float playerDamageDone)
    {
        float dmg = DamageCircle.touchingDamageCircle(parentPlayerMove.timeSinceTouchingDamageCircle, damageDealt, 0.25f);

        missDistance /= (1 + 1f * DamageCircle.isTouchingDamageCircle(parentPlayerMove.timeSinceTouchingDamageCircle));         // Doubles accuracy for damage circle.

        Vector3 fireFromPos;

        if (parentPlayerMove.thisIsMine && !parentPlayerMove.GetComponent <ClassControl> ().isBot)
        {
            // Adjust so it comes out of the viewmodel gun:
            fireFromPos = parentPlayerMove.mainCamera.transform.position +
                          (parentPlayerMove.mainCamera.transform.rotation * Quaternion.Inverse(parentPlayerMove.playerView.viewmodelCamera.transform.rotation)) *
                          (viewmodelUnlockObject.transform.position
                           - parentPlayerMove.playerView.viewmodelCamera.transform.position);
        }
        else
        {
            fireFromPos = unlockObject.transform.position;
        }
        // Modify firePos here if guns are off with method override.


        // Hang on!
        if (OperationNetwork.isServer && isThisShotgun == 0)
        {
            GameManager.rewindStatesToTick(pI.tickNumber);
        }

        Vector3[] posToSend = HitscanGun.hitscanShoot(parentPlayerMove.mainCamera.transform.position, fireFromPos,
                                                      miss(parentPlayerMove.mainCamera.transform.rotation, parentPlayerMove.mainCamera.transform.forward, missDistance, missAngle), unlockObject,
                                                      parentPlayerMove.GetComponent <PlayerAnimation>(), soundEffect, getBulletType(), parentPlayerMove.GetComponent <Combat>().team, dmg, 0.5f, 5 - (int)(3 * DamageCircle.isTouchingDamageCircle(parentPlayerMove.timeSinceTouchingDamageCircle)), 200,
                                                      isThisShotgun, this, out playerHit, out playerDamageDone, parentPlayerMove.plyr);

        // Special case, PISTOL!
        if (this is Pistol)
        {
            ((Pistol)this).attemptConductiveExplode(posToSend [posToSend.Length - 1]);
        }

        // Hang on!
        if (OperationNetwork.isServer && isThisShotgun == 0)
        {
            GameManager.revertColliderStates();
        }


        // The hitscan bullets need to be sent to the clients
        if (OperationNetwork.isServer)
        {
            Vector3[] sendPos = new Vector3[posToSend.Length - 1];
            Array.Copy(posToSend, 1, sendPos, 0, sendPos.Length);
            parentPlayerMove.GetComponent <SyncPlayer> ().currentTriggerSet.trigger(SyncPlayer.HITSCAN, sendPos);
        }
    }
 public virtual float GetSpeed()
 {
     return(25f * (1f + DamageCircle.isTouchingDamageCircle(parentPlayerMove.timeSinceTouchingDamageCircle) * 1f));        // Was 20f
 }
Пример #3
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);
        }
    }
Пример #4
0
    void areaChecks(PlayerInput pI)
    {
        Vector3 halfHeight = new Vector3(0, GetComponent <CharacterController>().height / 2 * transform.localScale.x, 0);
        Vector3 center     = transform.position + GetComponent <CharacterController>().center;

        Vector3 oldCenter = lastPlayerPosition + GetComponent <CharacterController>().center;


        Collider[] colliders = Physics.OverlapBox(center, halfHeight + new Vector3(GetComponent <CharacterController>().radius *transform.localScale.x, 0, GetComponent <CharacterController>().radius *transform.localScale.x), Quaternion.identity, 1 << 9 | 1 << 24 - GetComponent <Combat>().team);
        // All so it includes where the collider started at. Health packs should probably be picked up like this, but we'll see

        timeSinceTouchingDamageCircle += pI.frameTime;
        isInSpawnRoom         = false;
        isInTrapSelectionZone = false;

        // Dirt mound / Force field hit detection: (And spawn room detection)
        bool collided = false;

        for (int i = 0; i < colliders.Length; i++)
        {
            if (colliders [i].gameObject.GetComponent <HoverMoundCollision> ())
            {
                hoverMoundCollision(pI, colliders[i]);
                collided = true;

                // NOT EFFECTED BY enemy team's damage circles: (Thus, it is impossible to get through them w/o phase shift, icicle jump, rocket jump, speed boost.)
            }
            else if ((colliders [i].gameObject.CompareTag("DamageBoxBlue") && GetComponent <Combat> ().team == 0) || (colliders [i].gameObject.CompareTag("DamageBoxRed") && GetComponent <Combat> ().team == 1))
            {
                if (DamageCircle.isTouchingDamageCircle(timeSinceTouchingDamageCircle) == 0)
                {
                    timeSinceTouchingDamageCircle = Mathf.Max(0, 1.5f - pI.frameTime * 2);
                }
                else
                {
                    timeSinceTouchingDamageCircle = Mathf.Max(timeSinceTouchingDamageCircle - pI.frameTime * 2);
                }
            }
            else if (colliders [i].gameObject.layer == 24 - GetComponent <Combat> ().team&& colliders [i].isTrigger && colliders [i].transform.parent.gameObject.layer != 14)                 // Might as well check if isTrigger. Checks opposite team notabely.
            {
                isInSpawnRoom = true;
            }
            else if (colliders [i].gameObject.CompareTag("SelectTrapZone") && GetComponent <Combat> ().team == 1)
            {
                isInTrapSelectionZone = true;
            }
        }

        if (OperationNetwork.isServer)
        {
            RaycastHit[] raycastHit = Physics.CapsuleCastAll(oldCenter - halfHeight, oldCenter + halfHeight, GetComponent <CharacterController>().radius *transform.localScale.x, Vector3.Normalize(center - oldCenter), Vector3.Distance(center, oldCenter), 1 << 9 | 1 << 24 - GetComponent <Combat>().team | 1 << 21 - GetComponent <Combat>().team);
            foreach (RaycastHit rch in raycastHit)
            {
                if (rch.collider.gameObject.CompareTag("RocketBullet"))
                {
                    if (rch.collider.gameObject.GetComponent <Bullet> ().exists)
                    {
                        rch.collider.gameObject.GetComponent <Bullet> ().BlowUp(transform);                         // This works because directHit accounts for it, despite the fact that technically this parent object isn't part of the hitbox.
                    }
                }
            }
        }

        // Dirt mound history:
        if (collided)
        {
            inDirtMound += pI.frameTime;
        }
        else
        {
            inDirtMound = 0;
        }
    }