コード例 #1
0
    // STATIC IMPLEMENTATIONS:

    // In no particular order.
    public static Vector3[] hitscanShoot(Vector3 pos, Vector3 fireFromPos, Vector3 forward, GameObject fireFrom, PlayerAnimation playerAnim, GameObject soundEffect, string bulletType, int team, float damage, float knockBackMult, int damageFallOff, float maxDistance, int shotgun, HitscanGun hsGun, out Combat playerHit, out float damageDone, short playerSender)
    {
        bool isPlayerHitscan = pos != fireFromPos;         // Hitscan ALWAYS fires from a different location than the face. The sentry fires from the same place, and thus is a "serverObject" technically.

        playerHit  = null;
        damageDone = 0;

        RaycastHit hit;
        float      dist = maxDistance;

        int layersToHit = LayerLogic.HitscanShootLayer(team);         // Can't hit own team.

        List <Vector3> positions = new List <Vector3>();

        positions.Add(fireFromPos);         // The effect comes from the gun
        Vector3 lastPos = pos;

        int numHitMirror = 0;

        bool hitscanHitSomething = false;

        while (Physics.Raycast(pos, forward, out hit, dist, layersToHit))         // Not ignore mirror, players, or placement, or ragdolls, not decor, of course
        {
            // Allied Building can be hit. Most "ignore this"



            if ((hit.transform.CompareTag("Shield") || hit.transform.CompareTag("ShieldParent")) && (hit.transform.gameObject.layer - 10) / 5 == team)
            {
                // ignore the shield:
                pos   = hit.point + forward * 0.01f; // This "distance" reduces performance on these hitscan bullets significantly..
                dist -= 0.01f;                       // As to prevent an infinite loop. (Could be an issue)
                continue;
            }
            // add it.
            lastPos = hit.point;
            dist   -= hit.distance;           // Note how this could be used to calculate damage falloff.
            pos     = hit.point;
            positions.Add(pos);
            if (!hit.transform.CompareTag("Mirror"))
            {
                if (fireFrom != null || OperationNetwork.isServer)
                {
                    // This is a COPY-PASTE (Similar) to Projectile.directHit()
                    if (hit.transform.gameObject.layer == 17 - team)
                    {
                        // Finds the actual player object
                        Transform plyr = hit.transform;
                        do
                        {
                            plyr = plyr.parent;
                        } while (plyr.GetComponent <Combat> () == null);
                        float dmg = getDamage(damage, dist / maxDistance, damageFallOff);

                        // Headshots no longer do any extra damage.

                        // Instead of doing damage, add up the damage, then do the damage.. in the case that this is a shotgun scenario:
                        if (shotgun == 0)
                        {
                            plyr.GetComponent <Combat> ().TakeDamage(dmg, knockBackMult, forward, false, Combat.SINGLE_BULLET, playerAnim != null, fireFromPos, playerSender);
                        }
                        else if (shotgun == 1)
                        {
                            playerHit  = plyr.GetComponent <Combat> ();
                            damageDone = dmg;
                        }
                    }
                    else if (hit.transform.gameObject.layer == 10 || hit.transform.gameObject.layer == 15 || hit.transform.gameObject.layer == 20 || hit.transform.gameObject.layer == 21)
                    {
                        if (PlayerMade.IsFriendlyIcicle(hit.transform, team))                            // General Exception
                        {
                            PlayerMade.TakeDamageObjectG(hit.transform, getDamage(damage, dist / maxDistance, damageFallOff) * 1000, fireFromPos, isPlayerHitscan, playerSender);
                        }
                        else if (PlayerMade.IsFriendlyThrowable(hit.transform, team))                              // Specific Exception
                        {
                            PlayerMade.TakeDamageObjectG(hit.transform, getDamage(damage, dist / maxDistance, damageFallOff) * ThrowableSync.OWN_TEAM_MULTIPLIER, fireFromPos, isPlayerHitscan, playerSender);
                        }
                        else if (PlayerMade.IsEnemy(hit.transform, team) || PlayerMade.IsFriendlyThrowable(hit.transform, team))                               // It must hit a shield / shieldparent.. note that shieldparent's usefulness is deprecated / icicle, AND hit an enemy.
                        {
                            PlayerMade.TakeDamageObjectG(hit.transform, getDamage(damage, dist / maxDistance, damageFallOff), fireFromPos, isPlayerHitscan, playerSender);
                            // Damage to buildings do not have damage numbers associated with them.. any damage saved would just be added up.
                        }
                    }
                }

                // The positions are instantly used for Player: (Or server)
                if (fireFrom != null)
                {
                    createBullet(positions.ToArray(), fireFrom, playerAnim, soundEffect, bulletType);
                }
                hitscanHitSomething = true;
                break;
            }

            // Hit mirror:
            forward = Vector3.Reflect(forward, hit.normal);
            if (team == hit.transform.GetComponent <MirrorLogic>().team)
            {
                damage *= 2;                 // Twice the damage.
            }
            numHitMirror++;
            if (numHitMirror >= 16)               // Maximum 16 hits on mirror. Probably going to have max 1 mirror anyways
            {
                break;
            }
        }
        if (!hitscanHitSomething)
        {
            positions.Add(pos + forward * dist);
            if (fireFrom != null)
            {
                createBullet(positions.ToArray(), fireFrom, playerAnim, soundEffect, bulletType);
            }
        }
        return(positions.ToArray());
    }
コード例 #2
0
    void Update()
    {
        bool renderHealthBar = false;

        if (!GetComponent <PlayerMove>() || !GetComponent <PlayerMove>().thisIsMine)
        {
            if (Player.thisPlayer != null && Player.thisPlayer.playerObject != null)
            {
                if (Player.thisPlayer.playerObject.GetComponent <ClassControl>().classNum == 4 && Player.thisPlayer.team == team)
                {
                    renderHealthBar = true;
                    if (!this.renderHealthBar)
                    {
                        this.renderHealthBar = true;
                        healthBar.GetComponent <Renderer>().enabled        = true;
                        healthBar.parent.GetComponent <Renderer>().enabled = true;
                    }
                    // Display health bar:
                    if (healthBar != null)
                    {
                        healthBar.localScale      = new Vector3(1.01f * health / maxHealth, 1.01f, 1.01f);
                        healthBar.localPosition   = new Vector3(-0.505f + 0.505f * health / maxHealth, 0, -0.01f);
                        healthBar.parent.rotation = Quaternion.LookRotation(healthBar.parent.position - Player.thisPlayer.playerCamera.transform.position);
                    }
                }
            }
        }
        else
        {
            // Kill bind
            if (Input.GetKeyDown(KeyCode.K))
            {
                GetComponent <OperationView> ().RPC("KillSelf", OperationNetwork.ToServer);
            }

            // SOUND QUEUES:
            timeSinceLastVoiceQueue += Time.deltaTime;

            if (timeSinceLastVoiceQueue > 0.7f)
            {
                // Call for medic:
                if (Input.GetKeyDown(KeyCode.Z) || Input.GetKeyDown(KeyCode.X))
                {
                    VoiceLine((byte)Random.Range(0, 2), 255, true);                     // Full volume for now..
                    timeSinceLastVoiceQueue = 0f;
                }
            }


            while (damageIndicatorsTime.Count > 0 && Time.time - damageIndicatorsTime[0] > 2.0f)
            {
                Destroy(damageIndicators[0]);
                damageIndicators.RemoveAt(0);
                damageIndicatorsFrom.RemoveAt(0);
                damageIndicatorsTime.RemoveAt(0);
            }

            for (int i = 0; i < damageIndicators.Count; i++)
            {
                Vector3    loc      = Vector3.ProjectOnPlane(GetComponent <PlayerMove>().mainCamera.transform.forward, damageIndicatorsFrom[i] - GetComponent <PlayerMove>().mainCamera.transform.position);
                Quaternion rotation = Quaternion.LookRotation(damageIndicatorsFrom[i] - GetComponent <PlayerMove>().mainCamera.transform.position) * Quaternion.Inverse(GetComponent <PlayerMove>().mainCamera.transform.rotation);

                float angleUsed = -rotation.eulerAngles.y + 90f;

                damageIndicators[i].GetComponent <RectTransform>().anchoredPosition = new Vector2(0 + 1.6f * Mathf.Cos(angleUsed * Mathf.PI / 180f) * 200, 0 + Mathf.Sin(angleUsed * Mathf.PI / 180f) * 200);
                damageIndicators[i].GetComponent <RectTransform>().rotation         = Quaternion.Euler(0, 0, angleUsed);
                if (Time.time - damageIndicatorsTime[i] > 1f)
                {
                    Color color = damageIndicators[i].GetComponent <RawImage>().color;
                    damageIndicators[i].GetComponent <RawImage>().color = new Color(color.r, color.g, color.b, damageIndicatorsTime[i] - Time.time + 2.0f);
                }
            }

            // See player name & your trigger / trap.
            PlayerMove pMove = GetComponent <PlayerMove>();
            displayName = "";
            RaycastHit hit;
            float      dist = 50;

            // It should be noted that it has to hit the hitboxes, not the player right now because otherwise it would just the raycast would always hit your own player.. (Easy fix is just to move the raycast forward)
            if (Physics.Raycast(pMove.mainCamera.transform.position, pMove.mainCamera.transform.forward, out hit, dist, LayerLogic.HitscanShootLayer()))
            {
                if (hit.transform.gameObject.layer == 16 + pMove.GetComponent <Combat>().team || hit.transform.gameObject.layer == 17 - pMove.GetComponent <Combat>().team)               // Can see both allies and enemies right now.
                {
                    // Finds the actual player object
                    Transform plyr = hit.transform;
                    do
                    {
                        plyr = plyr.parent;
                    } while (plyr.GetComponent <Combat>() == null);

                    if (plyr.GetComponent <PlayerMove> ())                      // facades don't have names for now..
                    {
                        short playerOwner = plyr.GetComponent <PlayerMove> ().plyr;
                        if (GameManager.PlayerExists(playerOwner))
                        {
                            displayName = GameManager.GetPlayer(playerOwner).playerName;
                        }
                    }
                }

                if (hit.transform.gameObject.layer == 14)
                {
                    if (hit.transform.GetComponent <ArrowLauncher>())
                    {
                        if (hit.transform.GetComponent <ArrowLauncher>().playerOwner == pMove.plyr)                        // "myArrowTrap"
                        {
                            hit.transform.GetComponent <ArrowLauncher>().Highlight();
                        }
                    }
                    if (hit.transform.GetComponent <ArrowTrigger>())
                    {
                        if (hit.transform.GetComponent <ArrowTrigger>().playerOwner == pMove.plyr)                        // "myArrowTrap"
                        {
                            hit.transform.GetComponent <ArrowTrigger>().Highlight();
                        }
                    }
                }
            }
        }

        if (OperationNetwork.isServer)
        {
            // Loss of overheal over time:
            if (health > maxHealth && (int)(Time.time) > (int)(Time.time - Time.deltaTime)) // This = every second.
            {
                TakeDamage(Mathf.Min(5, health - maxHealth), OTHER);                        // Every second, lose 5 of the buff.
            }

            // You get healed within your respawn room:
            if (GetComponent <PlayerMove>() && GetComponent <PlayerMove>().isInSpawnRoom&& health < maxHealth && (int)(Time.time) > (int)(Time.time - Time.deltaTime))
            {
                TakeDamage(Mathf.Max(-50, health - maxHealth), HEALING);                 // 50 heal per second in spawn.
            }
        }

        if (!renderHealthBar && this.renderHealthBar)
        {
            this.renderHealthBar = false;
            if (healthBar != null)
            {
                healthBar.GetComponent <Renderer>().enabled        = false;
                healthBar.parent.GetComponent <Renderer>().enabled = false;
            }
        }

        // Assign to its own game object:

        // Needs to be at least 10 buffed to get particle effect:
        if (health <= maxHealth + 10 && isOverHealEffectDisplayed)
        {
            isOverHealEffectDisplayed = false;
            transform.Find("OverHealParticles").gameObject.SetActive(false);
        }
        else if (health > maxHealth + 10 && !isOverHealEffectDisplayed)
        {
            isOverHealEffectDisplayed = true;
            transform.Find("OverHealParticles").gameObject.SetActive(true);
        }
    }
コード例 #3
0
    // Update is called once per frame
    void Update()
    {
        if (GetComponent <Camera>().enabled&& OptionsMenu.IsLockState())
        {
            // Controls for SPECTATOR CAMERA!!
            float v = Input.GetAxis("Vertical");
            float h = Input.GetAxis("Horizontal");
            transform.position += transform.TransformDirection(new Vector3(h * 5f * Time.deltaTime, 0, v * 5f * Time.deltaTime));
            float xRot = transform.eulerAngles.x - Input.GetAxis("Mouse Y") * PlayerMove.sensitivity;
            if ((xRot < PlayerMove.minimumY) || (xRot >= 180 && xRot < 360 + PlayerMove.minimumY))
            {
                xRot = PlayerMove.minimumY;
            }
            if ((xRot <= 180 && xRot > PlayerMove.maximumY) || (xRot > 360 + PlayerMove.maximumY))
            {
                xRot = PlayerMove.maximumY;
            }
            transform.eulerAngles = new Vector3(xRot,
                                                transform.eulerAngles.y + Input.GetAxis("Mouse X") * PlayerMove.sensitivity,
                                                transform.eulerAngles.z);

            // See player names:

            // Almost identical to the implementation in Combat. (Should be a method, todo)
            PlayerMove pMove = GetComponent <PlayerMove>();
            displayName = "";
            RaycastHit hit;
            float      dist = 50;

            // It should be noted that it has to hit the hitboxes, not the player right now because otherwise it would just the raycast would always hit your own player.. (Easy fix is just to move the raycast forward)
            if (Physics.Raycast(transform.position, transform.forward, out hit, dist, LayerLogic.HitscanShootLayer()))
            {
                if (hit.transform.gameObject.layer == 16 || hit.transform.gameObject.layer == 17)
                {
                    // Finds the actual player object
                    Transform plyr = hit.transform;
                    do
                    {
                        plyr = plyr.parent;
                    } while (plyr.GetComponent <Combat> () == null);

                    if (plyr.GetComponent <PlayerMove> ())
                    {
                        short id = plyr.GetComponent <PlayerMove> ().plyr;
                        if (GameManager.PlayerExists(id))
                        {
                            displayName = GameManager.GetPlayer(id).name;
                        }
                    }
                }
            }
        }
    }