Esempio n. 1
0
    private void Die()
    {
        Transform specTarget = null;

        if (Topan.Network.isConnected)
        {
            bool isSuicide = (killerID <= -1);
            builtData = Topan.Network.player.id.ToString() + ((!isSuicide) ? "," : "");

            if (!isSuicide)
            {
                for (int i = 0; i < damageIDs.Count; i++)
                {
                    builtData += damageIDs[i].ToString();

                    if (damageIDs.Count > 1 && damageIDs[i] == killerID)
                    {
                        builtData += "k";
                    }

                    if (damageIDs[i] == headID)
                    {
                        builtData += "!";
                    }

                    if (i < damageIDs.Count - 1)
                    {
                        builtData += ",";
                    }
                }

                builtData += ".";

                if (damageIDs.Count > 1)
                {
                    for (int i = 0; i < damageInflicted.Count; i++)
                    {
                        builtData += damageInflicted[i].ToString();

                        if (i < damageIDs.Count - 1)
                        {
                            builtData += ",";
                        }
                    }
                }

                if (lastWeaponID > -1)
                {
                    grenade = false;
                    if (lastWeaponID >= 1000)
                    {
                        lastWeaponID -= 1000;
                        grenade       = true;
                    }

                    builtData += "." + lastWeaponID.ToString() + ((grenade) ? "*" : "");
                }
            }

            if (wm.currentGC != null)
            {
                string gunName = wm.currentGC.gunName;
                Dictionary <string, object> dropData = new Dictionary <string, object>();
                dropData.Add("chamber", wm.currentGC.bulletInChamber);

                Vector3 playerVelo = Vector3.zero;
                if (pm != null)
                {
                    playerVelo = (pm.controller.velocity * 0.25f);
                }

                dropData.Add("force", wm.transform.forward + playerVelo);
                dropData.Add("curammo", wm.currentGC.currentAmmo);
                dropData.Add("ammoleft", wm.currentGC.ammoLeft);
                Topan.Network.Instantiate(Topan.Network.server, "Weapons/" + gunName, wm.transform.position + (wm.transform.forward * 0.5f), wm.currentGC.transform.rotation, 0, dropData);
            }

            GetComponent <Topan.NetworkView>().Deallocate();

            if (killerID > -1)
            {
                if (killerID >= 64)
                {
                    specTarget = GeneralVariables.Networking.botInstances[killerID - 64];
                }
                else if (killerID >= 0)
                {
                    specTarget = ((Topan.NetworkView)Topan.Network.GetPlayerByID(killerID).GetLocalData("currentView")).transform;
                }

                if (specTarget != null)
                {
                    GeneralVariables.spectatorCamera.playerFollow.startingPosition = transform.position;
                    GeneralVariables.spectatorCamera.playerFollow.offset           = Vector3.up * 0.55f;
                    GeneralVariables.spectatorCamera.target = specTarget.GetChild(1);
                }
            }

            GeneralVariables.spectatorCamera.playerFollow.followRotation = true;
            GeneralVariables.Networking.GetComponent <Topan.NetworkView>().RPC(Topan.RPCMode.Server, "KilledPlayer", builtData);
            GeneralVariables.Networking.StartSpectating();
        }

        uic.gManager.damageBlur         = 0f;
        bloodyScreen.material.color     = DarkRef.SetAlpha(bloodyScreen.material.color, 0f);
        staminaBackground.color         = defStaminaBGCol;
        healthText.text                 = "INACTIVE";
        healthText.transform.localScale = Vector3.one;
        healthBar.value                 = 0f;
        shieldBar.value                 = 0f;
        pe.ClearExplosionEffect();

        for (int i = 0; i < hitIndicators.Count; i++)
        {
            if (hitIndicators[i].instance == null)
            {
                continue;
            }

            Destroy(hitIndicators[i].instance);
        }

        if (deathReplacement != null)
        {
            GameObject go = (GameObject)Instantiate(deathReplacement, transform.position, transform.rotation);
            go.GetComponent <AudioSource>().pitch = Random.Range(0.85f, 0.94f);
            go.GetComponent <AudioSource>().PlayOneShot(deathSound, Random.Range(0.3f, 0.35f));
            go.GetComponentInChildren <SkinnedMeshRenderer>().gameObject.AddComponent <DissolveEffect>().Dissolve(dissolveMat, GameSettings.settingsController.ragdollDestroyTimer, 0.18f, new Color(1f, 0.3f, 0f), DissolveEffect.DissolveDirection.DissolveOut, true);

            if ((Topan.Network.isConnected && killerID == -1) || (Topan.Network.isConnected && specTarget == null))
            {
                GeneralVariables.spectatorCamera.playerFollow.startingPosition = transform.position;
                GeneralVariables.spectatorCamera.playerFollow.offset           = Vector3.up * 0.55f;
                GeneralVariables.spectatorCamera.target = go.transform.GetChild(1);
            }
        }

        dead          = true;
        base.headshot = false;
        Destroy(gameObject);

        if (!Topan.Network.isConnected)
        {
            Application.LoadLevel(Application.loadedLevel);
        }
    }