Пример #1
0
 public void DenyPowerup(string powerupId)
 {
     NetworkCharacter
     .GetPlayerGameObject(PhotonNetwork.LocalPlayer)
     .GetComponent <PowerupableCharacter>()
     .DenyPower(powerupId);
 }
Пример #2
0
    void Overcharge(string shooterId)
    {
        ResetColor();
        Destroy(Instantiate(shockwavePrefab, Vector3.zero, Quaternion.identity), 5f);

        // Damage and knock back relative to distance from sun
        GameObject playerObj = NetworkCharacter.GetPlayerGameObject(PhotonNetwork.LocalPlayer);
        float      dist      = playerObj.transform.position.magnitude;
        float      damage    = UserDefinedConstants.sunDamage * (1 - dist / UserDefinedConstants.sphereRadius);

        dmgCtrl.BroadcastInflictDamage(shooterId, damage, PhotonNetwork.LocalPlayer.UserId);
        playerObj.GetComponent <Rigidbody>().AddForce(playerObj.transform.position.normalized * damage, ForceMode.Impulse);
    }
    public void RemoteExplosion(Vector3 position, Vector3 explosionForce, float dist, string shooterId)
    {
        // Instantiate explosion graphic and sound
        Explosion(position);

        // Apply force (disable root motion for a bit):
        Player     player    = PhotonNetwork.LocalPlayer;
        GameObject playerObj = NetworkCharacter.GetPlayerGameObject(player);

        playerObj.GetComponent <PlayerMovementController>().DisableRootMotionFor(UserDefinedConstants.explosionParalysisTime);
        playerObj.GetComponent <Rigidbody>().AddForce(explosionForce, ForceMode.Impulse);
        // Do damage (to self):
        float damage = UserDefinedConstants.projectileHitDamage * (1 - Mathf.Clamp01(dist / UserDefinedConstants.explosionRadius));

        dmgCtrl.BroadcastInflictDamage(shooterId, damage, player.UserId);
    }
    void InflictDamage(string shooterID, float damage, string targetUserId)
    {
        Dictionary <int, Player> playerDict = PhotonNetwork.CurrentRoom.Players;

        foreach (Player player in playerDict.Values)
        {
            if (player.UserId == targetUserId)
            {
                GameObject obj = NetworkCharacter.GetPlayerGameObject(player);
                Health     h   = obj.GetComponent <Health>();
                if (h == null)
                {
                    Debug.LogError("No Health component found on component with a PlayerMoveController!");
                }
                h.InflictDamage(damage);
                return;
            }
        }
        Debug.LogError(string.Format("No player with userID {0} found!", targetUserId));
    }
Пример #5
0
    void SetPower(int powerupIdx, bool empower)
    {
        switch (powerupIdx)
        {
        case 0:
            // Xray-vision! Swap shaders on all other players
            foreach (Player player in PhotonNetwork.PlayerListOthers)
            {
                NetworkCharacter
                .GetPlayerGameObject(player)
                .GetComponentInChildren <SkinnedMeshRenderer>()
                .sharedMaterial = empower ?
                                  xRayMaterial :
                                  originalPlayerMaterial;
            }
            break;

        case 1:
            // Sun markers! Show / hide the sun markers on everyone
            foreach (Player player in PhotonNetwork.PlayerListOthers)
            {
                SunMarkedCharacter sunChar = NetworkCharacter.GetPlayerGameObject(player).GetComponentInChildren <SunMarkedCharacter>();
                if (sunChar == null)
                {
                    Debug.LogError("Player " + player.UserId + " cannot be marked!");
                    continue;
                }
                if (empower)
                {
                    sunChar.Show();
                }
                else
                {
                    sunChar.Hide();
                }
            }
            break;
        }
    }
Пример #6
0
    public void BroadcastPickupPowerup(string powerupId)
    {
        // If someone already beat us to it, do nothing. This counts as buggy, because it means the local clock is laggy...
        long   timestamp           = Tools.Timestamp();
        string userIdOfPickerUpper = Tools.NullToEmptyString(PhotonNetwork.LocalPlayer.UserId);

        if (!UserWinsFightForPowerup(powerupId, userIdOfPickerUpper, timestamp))
        {
            Debug.LogError("Current timestamp is " + timestamp + "," +
                           " but remote player " + powerupPickedUpBy[powerupId] + " " +
                           "already logged pickup at " + powerupPickedUpAt[powerupId]);
            return;
        }

        // OK, it's available. Add it to the dictionaries and tell other players who picked it up and when
        UpdateData(powerupId, userIdOfPickerUpper, timestamp);
        photonView.RPC("PickupPowerup", RpcTarget.Others, powerupId, userIdOfPickerUpper, timestamp);

        // Grant the player the actual power
        NetworkCharacter
        .GetPlayerGameObject(PhotonNetwork.LocalPlayer)
        .GetComponent <PowerupableCharacter>()
        .GrantPower(powerupId, powerups[powerupId].powerupIdx);
    }
    void UpdateLockFire()
    {
        // Initial lock-on check
        if (Tools.NearlyEqual(weaponCooldownCounter, 0, 0.01f) && buttonDown)
        {
            if (targetedCharacter != null)
            {
                Debug.LogWarning("Got fire-button-down but lock-target is already set, did we miss a fire-button-up event?");
                targetedCharacter = null;
                lockedOnTarget    = false;
            }
            // I'm not a performance expert but it may be best to just iterate over all players and see who's in scope.
            // Any targetable object will have an angle less than 1+maxAngle anyway, so this is like setting it to infinity:
            currentSharpestTargetAngle = 1 + MaxAngleToBeTargeted();
            foreach (Player player in PhotonNetwork.PlayerList)
            {
                if (NetworkCharacter.IsLocalPlayer(player) || !NetworkCharacter.IsPlayerAlive(player))
                {
                    continue;
                }
                TargetableCharacter playerTarget = NetworkCharacter.GetPlayerGameObject(player).GetComponent <TargetableCharacter>();
                SwitchToTargetIfCloserToCenter(playerTarget);
            }
            // If a dummy character is spawned it won't be in the player list but it should be targeted anyway
            if (UserDefinedConstants.spawnDummyPlayer && NetworkManager.DummyPlayer != null)
            {
                TargetableCharacter playerTarget = NetworkManager.DummyPlayer.GetComponent <TargetableCharacter>();
                SwitchToTargetIfCloserToCenter(playerTarget);
            }

            // Lock on to found character, if found
            if (targetedCharacter != null)
            {
                StartTargeting(targetedCharacter);
            }

            // In any case, player will now fire on button release
            fireOnButtonUp = true;
        }

        // Stop targeting if:
        // 1. We are currently targeting and not locked on yet
        // 2. Either the player can no longer be targeted, or we're not pressing the fire button anymore
        if (targetedCharacter != null && !lockedOnTarget && (!CanBeTargeted(targetedCharacter) || !buttonPressed))
        {
            StopTargeting(targetedCharacter);
        }

        // When targeting completes it's handled in the Action passed to StartTargeting

        // If user pressed the button after weapon cooldown and we got button up, now fire
        if (fireOnButtonUp && buttonUp)
        {
            fireOnButtonUp        = false;
            weaponCooldownCounter = UserDefinedConstants.weaponCooldown;
            if (lockedOnTarget)
            {
                FireSeekingProjectile();
            }
            else
            {
                // If we didn't lock on, then we're no longer targeting anyone
                if (targetedCharacter != null)
                {
                    StopTargeting(targetedCharacter);
                }
                FireProjectileMaxImpulse();
            }
            // Either way, locally, we're no longer targeting anyone (don't keep the indicator for the target of a fired projectile)
            LocalStopTargeting();
        }
    }