示例#1
0
    public void ChangeOwner(EB.Sparx.Player newOwner, bool force = false)
    {
        try
        {
            if (!LevelOwnerComponent.IsLevelOwner(PlayerManager.LocalPlayerController().ReplicationPlayer))
            {
                EB.Debug.LogWarning("NetworkOwnershipComponent: ChangeOwner called on a machine other than the level owner has potential for bugs");
            }

            if (IsOwnershipTransferAllowed || force)
            {
                if (IsLocallyOwned)
                {
                    RequestNewOwner(newOwner.PlayerId);
                }
                else                 // transfering ownership can only be done by the machine this object is local to where all data is authorative
                {
                    _lastOwnershipTransferActivity = Time.realtimeSinceStartup;

                    if (GetNetworkOwnershipComponentViewRPC() != null)
                    {
                        _networkOwnershipComponentViewRPC.RPC("RequestNewOwnerRPC", EB.RPCMode.Others, newOwner.PlayerId);
                    }
                }
            }
        }
        catch (System.NullReferenceException e)
        {
            EB.Debug.LogError(e.ToString());
        }
    }
示例#2
0
    // is the specified sparx player the owner of this object?
    public bool IsOwner(EB.Sparx.Player player)
    {
        if (GetNetworkOwnershipComponentViewRPC() != null && player != null)
        {
            return(_networkOwnershipComponentViewRPC.ownerId == player.PlayerId);
        }

        return(false);
    }
示例#3
0
    // see which player is best suited to own this enemy
    private static PlayerController CalculateBestOwner(EnemyController enemy, NetworkOwnershipComponent netOwner)
    {
        CharacterTargetingComponent enemyTargeting = enemy.gameObject.GetComponent <CharacterTargetingComponent>();

        PlayerController closestPlayer          = null;
        float            distToClosestPlayerSqr = float.MaxValue;

        for (int controller = 0; controller < PlayerManager.sPlayerControllers.Count; ++controller)
        {
            PlayerController pc = PlayerManager.sPlayerControllers[controller];
            if (pc.gameObject.GetComponent <CharacterTargetingComponent>().AttackTarget == enemy.gameObject)            // if this enemy is this player's attack target, then we should be owned by this player
            {
                return(pc);
            }

            float distToPlayerSqr = GameUtils.GetDistSqXZ(pc.transform.position, enemy.transform.position);
            if (distToPlayerSqr < distToClosestPlayerSqr)
            {
                distToClosestPlayerSqr = distToPlayerSqr;
                closestPlayer          = pc;
            }
        }

        if (null != enemyTargeting.AttackTarget && PlayerManager.IsPlayer(enemyTargeting.AttackTarget))
        {
            return(enemyTargeting.AttackTarget.GetComponent <PlayerController>());           // if this player is this enemies attack target, then we should be owned by this player
        }

        if (!netOwner.IsOwner(closestPlayer.ReplicationPlayer))         // if the closest player is not our current owner, we may want to change owners
        {
            EB.Sparx.Player sparxPlayer = netOwner.GetOwner();
            if (sparxPlayer == null)
            {
                return(closestPlayer);
            }

            PlayerController currentOwner            = PlayerManager.GetPlayerController(sparxPlayer);
            float            distFromCurrentOwnerSqr = GameUtils.GetDistSqXZ(currentOwner.transform.position, enemy.transform.position);

            // these distances are arbitrary, but are designed so that dithering between different owners should not occur
            const float RequiredDistFromCurrentOwnerSqr = 12f * 12f;
            const float RequiredDistToNewOwnerSqr       = 5f * 5f;

            if (distFromCurrentOwnerSqr > RequiredDistFromCurrentOwnerSqr &&        // if we are far enough away from our current owner
                distToClosestPlayerSqr < RequiredDistToNewOwnerSqr)                 // we are close enough to our potential new owner
            {
                return(closestPlayer);
            }
        }
        return(null);
    }
示例#4
0
    void Start()
    {
        ReplicationView view = GetComponent <ReplicationView>();

        _owner = view != null ? view.instantiatorPlayer : null;

        _playerTransform = transform;
        Controller c = _playerTransform.GetComponent <Controller>();

        _muzzleTransform = _playerTransform;
        if (c != null && c.SkinnedRigPrefab != null)
        {
            _muzzleTransform = GameUtils.SearchHierarchyForBone(c.SkinnedRigPrefab.transform, "muzzle");
        }
        mRoot = GameObject.FindObjectOfType <UIRoot>();
    }
示例#5
0
    public static bool IsLevelOwner(EB.Sparx.Player player)
    {
        try{
            if (player == null)
            {
                return(false);
            }

            return(player.IsHost);            // the host is also the level owner
        }
        catch (System.NullReferenceException e)
        {
            EB.Debug.LogError(e.ToString());
            return(false);
        }
    }
示例#6
0
    public static PlayerController GetPlayerController(EB.Sparx.Player player)
    {
        if (player == null)
        {
            EB.Debug.LogWarning("Player is null in PlayerManager.GetPlayerController");
            return(null);
        }

        foreach (PlayerController pc in _sPlayerControllers)
        {
            if (pc.ReplicationPlayer.PlayerId == player.PlayerId)
            {
                return(pc);
            }
        }

        return(null);
    }