Exemplo n.º 1
0
    private void Ungrab(PlayerGroupStatus other, bool reciprocate = true)
    {
        if (leftGrabbed == other)
        {
            // set IK shit
            if (reciprocate)
            {
                leftGrabbed.Ungrab(this, false);
            }
            ik.solver.leftHandEffector.target = null;
            leftGrabbed = null;

            if (OnUngroup != null)
            {
                OnUngroup();
            }
        }
        else if (rightGrabbed == other)
        {
            // set IK shit
            if (reciprocate)
            {
                rightGrabbed.Ungrab(this, false);
            }
            ik.solver.rightHandEffector.target = null;
            rightGrabbed = null;

            if (OnUngroup != null)
            {
                OnUngroup();
            }
        }
    }
Exemplo n.º 2
0
    public static PlayerGroupStatus Get(Player fromPlayer)
    {
        PlayerGroupStatus gg = null;

        playerGroupStatus.TryGetValue(fromPlayer, out gg);
        return(gg);
    }
Exemplo n.º 3
0
    // is the other connected to me on their left?
    private bool IsOtherGSConnectedToMe_OrLoop_OrNoHandsFree(PlayerGroupStatus otherFirst, PlayerGroupStatus otherGS, bool otherLeft)
    {
        if (otherGS == this)
        {
            return(true);
        }

        var pointer = otherLeft ? otherGS.leftGrabbed : otherGS.rightGrabbed;

        if (pointer == this)
        {
            return(true);
        }

        if (pointer == otherFirst)
        {
            return(true);
        }

        if (pointer == null)
        {
            // hand is free, in the direction otherLeft
            return(false);
        }

        return(IsOtherGSConnectedToMe_OrLoop_OrNoHandsFree(otherFirst, pointer, otherLeft));
    }
Exemplo n.º 4
0
    public void RespawnAt(PlayerGroupStatus groupStatus, Transform restartPosition)
    {
        // find leftmost
        var leftMost   = groupStatus;
        var init       = leftMost;
        var montecarlo = 100;

        while (leftMost.leftGrabbed != null)
        {
            leftMost = leftMost.leftGrabbed;

            if (montecarlo-- < 0)
            {
                return;
            }
        }

        var count   = 0;
        var counter = leftMost;

        montecarlo = 100;
        while (counter != null)
        {
            count++;
            counter = counter.rightGrabbed;
            if (montecarlo-- < 0)
            {
                return;
            }
        }

        var initPos = restartPosition.position + Vector3.left * count / 2 * distOnRestart;

        leftMost.transform.position = initPos;
        leftMost.transform.forward  = restartPosition.forward;
        var next    = leftMost.rightGrabbed;
        var nextPos = initPos;

        montecarlo = 100;
        while (next != null)
        {
            nextPos += Vector3.right * distOnRestart;
            next.transform.position = nextPos;
            next.transform.forward  = restartPosition.forward;
            next = next.rightGrabbed;
            if (montecarlo-- < 0)
            {
                return;
            }
        }
    }
Exemplo n.º 5
0
    // grabs referenced player with left/right hand
    private void Grab(bool myLeft, PlayerGroupStatus nearest, bool reciprocate = true)
    {
        if (myLeft)
        {
            if (rightGrabbed != nearest)
            {
                leftGrabbed = nearest;
                // ik
                ik.solver.leftHandEffector.target = leftGrabbed.playerContactPoints.middleShoulderBackGrab;

                if (reciprocate)
                {
                    // other player grab this
                    nearest.Grab(!myLeft, this, false);
                }

                //Debug.Log("<color=#" + player.playerId * 2 + "fff60>Player " + player.playerId + " grabbed " + nearest.player.playerId + " with LEFT HAND</color>");

                if (OnGroup != null)
                {
                    OnGroup();
                }
            }
        }
        else
        {
            if (leftGrabbed != nearest)
            {
                rightGrabbed = nearest;
                ik.solver.rightHandEffector.target = rightGrabbed.playerContactPoints.middleShoulderBackGrab;

                if (reciprocate)
                {
                    // other player grab this
                    nearest.Grab(!myLeft, this, false);
                }

                //Debug.Log("<color=#" + player.playerId * 2 + "fff60>Player " + player.playerId + " grabbed " + nearest.player.playerId + " with right HAND</color>");

                if (OnGroup != null)
                {
                    OnGroup();
                }
            }
        }
    }
Exemplo n.º 6
0
    // gets dist from the other player shoulder to this player's left/right hand.
    private float GetNearestDistToPlayer(PlayerGroupStatus otherPlayer, bool myLeft)
    {
        // find nearest hand to the middle bit of the player
        var otherMidShoulder = otherPlayer.playerContactPoints.middleShoulderBackGrab;
        var dist             = 0f;

        if (myLeft)
        {
            var distLeft = otherMidShoulder.position - this.playerContactPoints.leftHand.position;
            dist = distLeft.magnitude;
        }
        else
        {
            var distRight = otherMidShoulder.position - this.playerContactPoints.rightHand.position;
            dist = distRight.magnitude;
        }
        return(dist);
    }
Exemplo n.º 7
0
 public static PlayerGroupStatus GetGroupStatus(this Player player)
 {
     return(PlayerGroupStatus.Get(player));
 }