示例#1
0
    void OnParticleCollision(GameObject other)
    {
        BaseStats bs = other.GetComponent <BaseStats>();

        if (bs != null)
        {
            bs.ApplyDamageMain(damage, true);
        }
    }
示例#2
0
    //Slam the stock into the enemy's face.
    private void QuickMeleeWithWeapon()
    {
        dm.DoMeleeAnimation();

        Transform theCamera = GeneralVariables.mainPlayerCamera.transform;

        if (Physics.Raycast(theCamera.position, theCamera.forward, out melee, 2f, layersToMelee.value))
        {
            BaseStats bs = melee.collider.GetComponent <BaseStats>();
            Limb      lb = melee.collider.GetComponent <Limb>();
            if (bs == null && lb != null)
            {
                bs = lb.rootStats;
            }

            if (bs != null)
            {
                bool showHitMarker = false;
                int  damage        = Random.Range(50, 55 + 1);

                if (bs.curHealth > 0)
                {
                    showHitMarker = true;
                }

                bool canDamage = true;
                bs.headshot = false;

                if (Topan.Network.isConnected)
                {
                    Topan.NetworkView damageView = bs.GetComponent <Topan.NetworkView>();
                    if (damageView != null)
                    {
                        BotVitals hitBot = bs.GetComponent <BotVitals>();

                        if (GeneralVariables.gameModeHasTeams)
                        {
                            byte targetTeam = /*(hitBot) ? BotManager.allBotPlayers[hitBot.bm.myIndex].team : */ (byte)damageView.owner.GetPlayerData("team", (byte)0);

                            if (targetTeam == (byte)Topan.Network.player.GetPlayerData("team", (byte)0))
                            {
                                if (!friendlyFire)
                                {
                                    canDamage = false;
                                }

                                showHitMarker = false;
                            }
                        }
                        else
                        {
                        }

                        if (canDamage)
                        {
                            if (Topan.Network.isServer && (damageView.ownerID == 0 || hitBot))
                            {
                                bs.ApplyDamageNetwork((byte)Mathf.Clamp(damage, 0, 255), (byte)Topan.Network.player.id, (byte)currentGC.weaponID, (byte)4);
                            }
                            else
                            {
                                damageView.RPC(Topan.RPCMode.Owner, "ApplyDamageNetwork", (byte)Mathf.Clamp(damage, 0, 255), (byte)Topan.Network.player.id, (byte)currentGC.weaponID, (byte)4);
                            }
                        }
                    }
                }
                else
                {
                    bs.ApplyDamageMain(damage, false);
                }

                if (showHitMarker)
                {
                    HitTarget(bs.curHealth <= 0);
                }
            }

            Quaternion rot = Quaternion.LookRotation(melee.normal);

            particleMeleeIndex = 0;
            string surfTag = melee.collider.tag;
            if (surfTag == "Dirt")
            {
                particleMeleeIndex = 1;
            }
            else if (surfTag == "Metal")
            {
                particleMeleeIndex = 2;
            }
            else if (surfTag == "Wood")
            {
                particleMeleeIndex = 3;
            }
            else if (surfTag == "Flesh" || surfTag == "Player - Flesh")
            {
                particleMeleeIndex = 4;
            }
            else if (surfTag == "Water")
            {
                particleMeleeIndex = 5;
            }

            PoolManager.Instance.RequestParticleEmit(particleMeleeIndex, melee.point + (melee.normal * 0.06f), rot);
        }
    }
示例#3
0
    private IEnumerator MeleeAction()
    {
        isMeleeState = true;
        yield return(new WaitForSeconds(meleeDelay));

        if (Physics.Raycast(camTr.position, camTr.forward, out hit, meleeRange, layersToMelee.value))
        {
            BaseStats bs = hit.collider.GetComponent <BaseStats>();
            Limb      lb = hit.collider.GetComponent <Limb>();

            if (bs != null)
            {
                bool showHitMarker = false;
                if (wm != null && bs.curHealth > 0)
                {
                    showHitMarker = true;
                }

                bool canDamage = true;
                bs.headshot = false;

                if (Topan.Network.isConnected)
                {
                    Topan.NetworkView damageView = bs.GetComponent <Topan.NetworkView>();
                    if (damageView != null)
                    {
                        BotVitals hitBot = bs.GetComponent <BotVitals>();

                        if (GeneralVariables.gameModeHasTeams)
                        {
                            byte targetTeam = /*(hitBot) ? BotManager.allBotPlayers[hitBot.bm.myIndex].team : */ (byte)damageView.owner.GetPlayerData("team", (byte)0);

                            if (targetTeam == (byte)Topan.Network.player.GetPlayerData("team", (byte)0))
                            {
                                if (!friendlyFire)
                                {
                                    canDamage = false;
                                }

                                showHitMarker = false;
                            }
                        }
                        else
                        {
                        }

                        if (canDamage)
                        {
                            if (Topan.Network.isServer && (damageView.ownerID == 0 || hitBot))
                            {
                                bs.ApplyDamageNetwork((byte)Mathf.Clamp(Random.Range(meleeMinDamage, meleeMaxDamage + 1), 0, 255), (byte)Topan.Network.player.id, (byte)0, (byte)4);
                            }
                            else
                            {
                                damageView.RPC(Topan.RPCMode.Owner, "ApplyDamageNetwork", (byte)Mathf.Clamp(Random.Range(meleeMinDamage, meleeMaxDamage + 1), 0, 255), (byte)Topan.Network.player.id, (byte)0, (byte)4);
                            }
                        }
                    }
                }
                else
                {
                    bs.headshot = false;
                    bs.ApplyDamageMain(Random.Range(meleeMinDamage, meleeMaxDamage + 1), true);
                }

                if (showHitMarker)
                {
                    wm.HitTarget(bs.curHealth <= 0);
                }
            }
            else if (lb != null && lb.rootStats != null)
            {
                bs = lb.rootStats;
                int finalDmg = Mathf.RoundToInt(Random.Range(meleeMinDamage, meleeMaxDamage + 1) * Mathf.Clamp01(lb.realDmgMult));

                bool showHitMarker = false;
                if (wm != null && bs.curHealth > 0)
                {
                    showHitMarker = true;
                }

                bool canDamage = true;

                if (Topan.Network.isConnected)
                {
                    Topan.NetworkView damageView = bs.GetComponent <Topan.NetworkView>();
                    if (damageView != null)
                    {
                        BotVitals hitBot = bs.GetComponent <BotVitals>();

                        if (GeneralVariables.gameModeHasTeams)
                        {
                            byte targetTeam = /* (hitBot) ? BotManager.allBotPlayers[hitBot.bm.myIndex].team : */ (byte)damageView.owner.GetPlayerData("team", (byte)0);

                            if (targetTeam == (byte)Topan.Network.player.GetPlayerData("team", (byte)0))
                            {
                                if (!friendlyFire)
                                {
                                    canDamage = false;
                                }

                                showHitMarker = false;
                            }
                        }
                        else
                        {
                        }

                        if (canDamage)
                        {
                            if (Topan.Network.isServer && (damageView.ownerID == 0 || hitBot))
                            {
                                bs.ApplyDamageNetwork((byte)Mathf.Clamp(finalDmg, 0, 255), (byte)Topan.Network.player.id, (byte)0, (byte)lb.limbType);
                            }
                            else
                            {
                                damageView.RPC(Topan.RPCMode.Owner, "ApplyDamageNetwork", (byte)Mathf.Clamp(finalDmg, 0, 255), (byte)Topan.Network.player.id, (byte)0, (byte)lb.limbType);
                            }
                        }
                    }
                }
                else
                {
                    bs.headshot = false;
                    bs.ApplyDamageMain(finalDmg, true);
                }

                if (showHitMarker)
                {
                    wm.HitTarget(bs.curHealth <= 0);
                }
            }

            Rigidbody rigid = hit.rigidbody;
            if (rigid != null && !rigid.isKinematic)
            {
                rigid.AddForce(camTr.forward * meleeForce, ForceMode.Impulse);
            }

            int    particleIndex = 0;
            string surfTag       = hit.collider.tag;
            if (surfTag == "Dirt")
            {
                particleIndex = 1;
            }
            else if (surfTag == "Metal")
            {
                particleIndex = 2;
            }
            else if (surfTag == "Wood")
            {
                particleIndex = 3;
            }
            else if (surfTag == "Flesh" || surfTag == "Player - Flesh")
            {
                particleIndex = 4;
            }
            else if (surfTag == "Water")
            {
                particleIndex = 5;
            }

            PoolManager.Instance.RequestParticleEmit(particleIndex, hit.point + (hit.normal * 0.06f), Quaternion.LookRotation(hit.normal));
        }

        yield return(new WaitForSeconds(meleeCooldown));

        isMeleeState = false;
    }
示例#4
0
    private void ApplyDamageStat(BaseStats bs, int dmg, float dist, float rad)
    {
        if (dmg <= 0 && !isEMP)
        {
            return;
        }

        PlayerVitals playerPV = bs.GetComponent <PlayerVitals>();

        if (bs.isLocalPlayer && playerPV != null)
        {
            playerPV.HitIndicator(transform.position);

            if (isEMP)
            {
                playerPV.pe.StartPhase_EMP();
            }
            else if (explosionCameraEffect)
            {
                playerPV.pe.ExplosionVisualEffect(1.05f - Mathf.Clamp01((dist * 1.35f) / rad));
            }
        }

        bool showHitMarker = false;

        if (isPlayer && !bs.isLocalPlayer && wManager != null && bs.curHealth > 0)
        {
            showHitMarker = true;
        }

        if (Topan.Network.isConnected)
        {
            Topan.NetworkView damageView = bs.GetComponent <Topan.NetworkView>();

            if (damageView != null && !(isPlayer && bs.isLocalPlayer))
            {
                bool      canDamage  = true;
                BotVitals hitBot     = bs.GetComponent <BotVitals>();
                byte      ownerTeam  = (isPlayer || botIndex <= -1) ? (byte)Topan.Network.player.GetPlayerData("team", (byte)0) : BotManager.allBotPlayers[botIndex].team;
                byte      targetTeam = /*(hitBot != null) ? BotManager.allBotPlayers[hitBot.bm.myIndex].team :*/ (byte)damageView.owner.GetPlayerData("team", (byte)0);

                if (GeneralVariables.gameModeHasTeams)
                {
                    if (targetTeam == ownerTeam)
                    {
                        canDamage     = friendlyFire;
                        showHitMarker = false;
                    }
                }
                else
                {
                }

                /*
                 * if((hitBot != null && botIndex > -1 && hitBot.bm.myIndex == botIndex)) {
                 *  canDamage = true;
                 * }*/

                if (canDamage)
                {
                    damageView.RPC(Topan.RPCMode.Owner, "ApplyDamageNetwork", (byte)dmg, (botIndex > -1) ? (byte)(botIndex + 64) : (byte)Topan.Network.player.id, GetTrueID(), (grenIndex > -1) ? (byte)255 : (byte)4);
                }

                if (isEMP && !hitBot)
                {
                    damageView.RPC(Topan.RPCMode.Owner, "NetworkEMP");
                }
            }
            else
            {
                bs.headshot = false;
                bs.ApplyDamageMain(dmg, true);
            }
        }
        else
        {
            bs.headshot = false;
            bs.ApplyDamageMain(dmg, true);
        }

        if (showHitMarker)
        {
            wManager.HitTarget(bs.curHealth <= 0);
        }
    }
示例#5
0
    private void OnHit(RaycastHit hit)
    {
        ricochetValue++;
        float limbForceMult = 1f;

        travelDist += hit.distance;
        bool ignoreBulletHole = false;

        if (!isVisuals)
        {
            bs = hit.collider.GetComponent <BaseStats>();
            lb = hit.collider.GetComponent <Limb>();

            damage = Mathf.RoundToInt(damage * dmgCurve.Evaluate(travelDist));

            if (damage > 0)
            {
                if (bs != null)
                {
                    bool hitMarkerEnabled = false;
                    if (player && wManager != null && bs.curHealth > 0 && bs.hitIndication)
                    {
                        hitMarkerEnabled = true;
                    }

                    bool canDamage = true;
                    bs.headshot = false;

                    if (Topan.Network.isConnected)
                    {
                        Topan.NetworkView damageView = bs.GetComponent <Topan.NetworkView>();
                        if (damageView != null && damage > 0)
                        {
                            BotVitals hitBot = bs.GetComponent <BotVitals>();

                            if (GeneralVariables.gameModeHasTeams)
                            {
                                byte ownerTeam  = (player) ? (byte)Topan.Network.player.GetPlayerData("team", (byte)0) : BotManager.allBotPlayers[botIndex].team;
                                byte targetTeam = /* (hitBot) ? BotManager.allBotPlayers[hitBot.bm.myIndex].team : */ (byte)damageView.owner.GetPlayerData("team", (byte)0);

                                if (targetTeam == ownerTeam)
                                {
                                    if (!friendlyFire)
                                    {
                                        canDamage = false;
                                    }

                                    hitMarkerEnabled = false;
                                }
                            }
                            else
                            {
                            }

                            if (canDamage)
                            {
                                if (isServer && (damageView.ownerID == 0 || hitBot))
                                {
                                    bs.ApplyDamageNetwork((byte)Mathf.Clamp(damage, 0, 255), (botIndex > -1) ? (byte)(botIndex + 64) : (byte)Topan.Network.player.id, (byte)thisGunIndex, (byte)4);
                                }
                                else
                                {
                                    damageView.RPC(Topan.RPCMode.Owner, "ApplyDamageNetwork", (byte)Mathf.Clamp(damage, 0, 255), (botIndex > -1) ? (byte)(botIndex + 64) : (byte)Topan.Network.player.id, (byte)thisGunIndex, (byte)4);
                                }
                            }
                        }
                        else
                        {
                            bs.ApplyDamageMain(damage, true);
                        }
                    }
                    else
                    {
                        bs.ApplyDamageMain(damage, true);
                    }

                    if (hitMarkerEnabled)
                    {
                        wManager.HitTarget(bs.curHealth <= 0);
                    }

                    if (canDamage)
                    {
                        PlayerVitals playerPV = bs.GetComponent <PlayerVitals>();
                        if (bs.isLocalPlayer && playerPV != null)
                        {
                            playerPV.HitIndicator(startPos);
                        }
                    }
                }
                else if (lb != null && lb.rootStats != null)
                {
                    bs = lb.rootStats;
                    lb.ragdollVelocity = tr.forward * force * limbForceMult;
                    damage             = Mathf.RoundToInt(damage * lb.realDmgMult);

                    bool hitMarkerEnabled = false;
                    if (player && wManager != null && bs.curHealth > 0 && bs.hitIndication)
                    {
                        hitMarkerEnabled = true;
                    }

                    bs.headshot = (lb.limbType == Limb.LimbType.Head);

                    if (Topan.Network.isConnected)
                    {
                        Topan.NetworkView damageView = bs.GetComponent <Topan.NetworkView>();
                        if (damageView != null)
                        {
                            BotVitals hitBot    = bs.GetComponent <BotVitals>();
                            bool      canDamage = true;

                            if (GeneralVariables.gameModeHasTeams)
                            {
                                byte ownerTeam  = (player || botIndex <= -1) ? (byte)Topan.Network.player.GetPlayerData("team", (byte)0) : BotManager.allBotPlayers[botIndex].team;
                                byte targetTeam = /*(hitBot) ? BotManager.allBotPlayers[hitBot.bm.myIndex].team : */ (byte)damageView.owner.GetPlayerData("team", (byte)0);

                                if (targetTeam == ownerTeam)
                                {
                                    if (!friendlyFire)
                                    {
                                        canDamage = false;
                                    }

                                    hitMarkerEnabled = false;
                                }
                            }
                            else
                            {
                            }

                            if (canDamage)
                            {
                                if (isServer && (damageView.ownerID == 0 || hitBot))
                                {
                                    bs.ApplyDamageNetwork((byte)Mathf.Clamp(damage, 0, 255), (botIndex > -1) ? (byte)(botIndex + 64) : (byte)Topan.Network.player.id, (byte)thisGunIndex, (byte)lb.limbType);
                                }
                                else
                                {
                                    damageView.RPC(Topan.RPCMode.Owner, "ApplyDamageNetwork", (byte)Mathf.Clamp(damage, 0, 255), (botIndex > -1) ? (byte)(botIndex + 64) : (byte)Topan.Network.player.id, (byte)thisGunIndex, (byte)lb.limbType);
                                }
                            }
                        }
                        else
                        {
                            bs.ApplyDamageMain(damage, true);
                        }
                    }
                    else
                    {
                        bs.ApplyDamageMain(damage, true);
                    }

                    limbForceMult = 3f;

                    if (hitMarkerEnabled)
                    {
                        wManager.HitTarget(bs.curHealth <= 0);
                    }
                }
            }
        }

        bulletHoleIndex = 0;
        hitEffectIndex  = 0;
        string hitTag = hit.collider.tag;

        if (hitTag == "Dirt")
        {
            hitEffectIndex = 1;
        }
        else if (hitTag == "Metal")
        {
            hitEffectIndex = 2;
        }
        else if (hitTag == "Wood")
        {
            hitEffectIndex = 3;
        }
        else if (hitTag == "Flesh" || hitTag == "Player - Flesh")
        {
            bulletHoleIndex = -1;
            hitEffectIndex  = 4;
        }
        else if (hitTag == "Water")
        {
            bulletHoleIndex = -1;
            hitEffectIndex  = 5;
        }

        Quaternion rot = Quaternion.LookRotation(hit.normal);

        if (bulletHoleIndex >= 0 && !ignoreBulletHole)
        {
            Transform hole = PoolManager.Instance.RequestInstantiate(bulletHoles[bulletHoleIndex], hit.point + (hit.normal * 0.01f), rot).transform;

            if (!hit.collider.gameObject.isStatic && hit.rigidbody)
            {
                hole.KeepUniformScale(hit.transform);
            }

            float randomSize = Random.Range(bulletDecalSize.x, bulletDecalSize.y);
            hole.localScale = new Vector3(randomSize, randomSize, 1f);

            Vector3 euler = hole.localEulerAngles;
            euler.z = Random.value * 360f;
            hole.localEulerAngles = euler;

            DecalObject dObj = hole.GetChild(0).GetComponent <DecalObject>();
            dObj.targetObject = hit.collider.gameObject;
            dObj.UpdateDecalMesh();
        }

        PoolManager.Instance.RequestParticleEmit(hitEffectIndex, hit.point + (hit.normal * 0.06f), rot);

        Rigidbody rigid = hit.rigidbody;

        if ((lb == null || (lb != null && (lb.rootStats == null || lb.rootStats.curHealth <= 0))) && rigid != null && !rigid.isKinematic)
        {
            rigid.AddForce(tr.forward * force * limbForceMult, ForceMode.Impulse);
        }

        if (ricochetAmount > 0 && ricochetValue <= ricochetAmount)
        {
            if (Vector3.Angle(dir, hit.normal) - 90f <= ricochetAngle)
            {
                tr.rotation    = Quaternion.LookRotation(Vector3.Reflect(dir, hit.normal));
                speed         *= 0.75f;
                damage         = Mathf.RoundToInt(damage * Random.Range(0.5f, 0.6f));
                gravityVector *= 0.5f;
                tr.position   += tr.forward * speed * Time.deltaTime;
                newPos         = tr.position;
            }
            else
            {
                AddToPool();
            }
        }

        if (smokeInstance != null)
        {
            smokeInstance.SetPosition(1, hit.point);
            smokeInstance = null;
        }

        if (currentWhiz != null)
        {
            currentWhiz.transform.parent   = null;
            currentWhiz.transform.position = hit.point;
            currentWhiz = null;
            noWhizSound = false;
        }

        tracer.SetActive(false);
        glow.SetActive(false);
        AddToPool();
    }