Ejemplo n.º 1
0
 public void Unbuckle()
 {
     OnBuckledChangedHook(NetworkInstanceId.Invalid);
     //we can be pushed / pulled again
     PlayerScript.pushPull.isNotPushable = false;
     PlayerUprightMessage.SendToAll(gameObject, !registerPlayer.IsDownServer, false);         //fall or get up depending if the player can stand
     onUnbuckled?.Invoke();
 }
Ejemplo n.º 2
0
    /// <summary>
    /// Sends the info on the subject's current status to a specific client.
    /// </summary>
    /// <param name="recipient">player who should recieve the message</param>
    /// <param name="subjectPlayer">player whose status is being communicated</param>
    public static void Sync(GameObject recipient, GameObject subjectPlayer)
    {
        var msg = new PlayerUprightMessage
        {
            SubjectPlayer = subjectPlayer.NetId(),
            Upright       = !subjectPlayer.GetComponent <RegisterPlayer>().IsDownServer
        };

        msg.SendTo(recipient);
    }
Ejemplo n.º 3
0
    public static void SendToAll(GameObject subjectPlayer, bool state)
    {
        var msg = new PlayerUprightMessage
        {
            SubjectPlayer = subjectPlayer.NetId(),
            Upright       = state,
        };

        msg.SendToAll();
    }
Ejemplo n.º 4
0
    private void UpdateCanMove()
    {
        if (playerScript.playerHealth.IsCrit || playerScript.playerHealth.IsSoftCrit ||
            playerScript.playerHealth.IsDead || isStunned)
        {
            return;
        }

        PlayerUprightMessage.SendToAll(gameObject, true);
        playerScript.playerMove.allowInput = true;
    }
Ejemplo n.º 5
0
    public static PlayerUprightMessage Send(GameObject recipient, GameObject subjectPlayer, bool state)
    {
        var msg = new PlayerUprightMessage
        {
            SubjectPlayer = subjectPlayer.NetId(),
            Upright       = state,
        };

        msg.SendTo(recipient);
        return(msg);
    }
Ejemplo n.º 6
0
    public void RemoveStun()
    {
        IsSlippingServer = false;
        PlayerUprightMessage.SendToAll(gameObject, true, false);

        if (playerScript.playerHealth.ConsciousState == ConsciousState.CONSCIOUS ||
            playerScript.playerHealth.ConsciousState == ConsciousState.BARELY_CONSCIOUS)
        {
            playerScript.playerMove.allowInput = true;
        }
    }
Ejemplo n.º 7
0
    /// <summary>
    /// Stops the player from moving and interacting for a period of time.
    /// Also drops held items by default.
    /// </summary>
    /// <param name="stunDuration">Time before the stun is removed.</param>
    /// <param name="dropItem">If items in the hand slots should be dropped on stun.</param>
    public void Stun(float stunDuration = 4f, bool dropItem = true)
    {
        PlayerUprightMessage.SendToAll(gameObject, false, false);
        if (dropItem)
        {
            playerScript.playerNetworkActions.DropItem("leftHand");
            playerScript.playerNetworkActions.DropItem("rightHand");
        }
        playerScript.playerMove.allowInput = false;

        this.RestartCoroutine(StunTimer(stunDuration), ref unstunHandle);
    }
Ejemplo n.º 8
0
    /// <summary>
    /// Stops the player from moving and interacting for a period of time.
    /// Also drops held items by default.
    /// </summary>
    /// <param name="stunDuration">Time before the stun is removed.</param>
    /// <param name="dropItem">If items in the hand slots should be dropped on stun.</param>
    public void Stun(float stunDuration = 4f, bool dropItem = true)
    {
        IsSlippingServer = true;
        PlayerUprightMessage.SendToAll(gameObject, false, false);
        if (dropItem)
        {
            Inventory.ServerDrop(playerScript.ItemStorage.GetNamedItemSlot(NamedSlot.leftHand));
            Inventory.ServerDrop(playerScript.ItemStorage.GetNamedItemSlot(NamedSlot.rightHand));
        }
        playerScript.playerMove.allowInput = false;

        this.RestartCoroutine(StunTimer(stunDuration), ref unstunHandle);
    }
Ejemplo n.º 9
0
    public void RemoveStun()
    {
        IsStunnedServer = false;

        if (playerScript.playerHealth.IsCrit ||
            playerScript.playerHealth.IsSoftCrit ||
            playerScript.playerHealth.IsDead)
        {
            return;
        }

        PlayerUprightMessage.SendToAll(gameObject, !IsStunnedServer, IsStunnedServer);
        playerScript.playerMove.allowInput = true;
    }
Ejemplo n.º 10
0
    public void RemoveStun()
    {
        var oldVal = IsSlippingServer;

        IsSlippingServer = false;
        IsDownServer     = false;
        OnSlipChangeServer.Invoke(oldVal, IsSlippingServer);
        PlayerUprightMessage.SendToAll(gameObject, true, false);

        if (playerScript.playerHealth.ConsciousState == ConsciousState.CONSCIOUS ||
            playerScript.playerHealth.ConsciousState == ConsciousState.BARELY_CONSCIOUS)
        {
            playerScript.playerMove.allowInput = true;
        }
    }
Ejemplo n.º 11
0
    /// <summary>
    /// Stunned info will ONLY be sent to subject!
    /// </summary>
    /// <param name="subjectPlayer"></param>
    /// <param name="upright"></param>
    public static void SendToAll(GameObject subjectPlayer, bool upright, bool buckling)
    {
        if (!IsValid(subjectPlayer, upright, buckling))
        {
            return;
        }
        var msg = new PlayerUprightMessage
        {
            SubjectPlayer = subjectPlayer.NetId(),
            Upright       = upright,
        };

        msg.SendToAllExcept(subjectPlayer);
        msg.SendTo(subjectPlayer);
    }
Ejemplo n.º 12
0
    public void Restrain(Action onUnbuckled = null)
    {
        restrained = true;
        //can't push/pull when buckled in, break if we are pulled / pulling
        PlayerScript.pushPull.CmdStopFollowing();
        PlayerScript.pushPull.CmdStopPulling();
        PlayerScript.pushPull.isNotPushable = true;
        this.onUnbuckled = onUnbuckled;

        //if player is downed, make them upright
        if (registerPlayer.IsDownServer)
        {
            PlayerUprightMessage.SendToAll(gameObject, true, registerPlayer.IsStunnedServer);
        }
    }
Ejemplo n.º 13
0
    public void Unrestrain()
    {
        restrained = false;
        //we can be pushed / pulled again
        PlayerScript.pushPull.isNotPushable = false;

        //if player is crit, soft crit, or dead, lay them back down
        if (playerScript.playerHealth.ConsciousState == ConsciousState.DEAD ||
            playerScript.playerHealth.ConsciousState == ConsciousState.UNCONSCIOUS ||
            playerScript.playerHealth.ConsciousState == ConsciousState.BARELY_CONSCIOUS)
        {
            PlayerUprightMessage.SendToAll(gameObject, false, registerPlayer.IsStunnedServer);
        }

        onUnbuckled?.Invoke();
    }
Ejemplo n.º 14
0
    public static PlayerUprightMessage Send(GameObject recipient, GameObject subjectPlayer, bool upright, bool isStunned)
    {
        if (!IsValid(subjectPlayer, upright))
        {
            return(null);
        }
        var msg = new PlayerUprightMessage
        {
            SubjectPlayer = subjectPlayer.NetId(),
            Upright       = upright,
            Stunned       = isStunned ? StunnedState.Stunned : StunnedState.NonStunned
        };

        msg.SendTo(recipient);
        return(msg);
    }
Ejemplo n.º 15
0
    public void Buckle(GameObject toObject, Action unbuckledAction = null)
    {
        var netid = toObject.NetId();

        if (netid == NetworkInstanceId.Invalid)
        {
            Logger.LogError("attempted to buckle to object " + toObject + " which has no NetworkIdentity. Buckle" +
                            " can only be used on objects with a Net ID. Ensure this object has one.",
                            Category.Movement);
            return;
        }

        var buckleInteract = toObject.GetComponent <BuckleInteract>();

        PlayerUprightMessage.SendToAll(gameObject, buckleInteract.forceUpright, true);

        OnBuckledChangedHook(netid);
        //can't push/pull when buckled in, break if we are pulled / pulling
        //inform the puller
        if (PlayerScript.pushPull.PulledBy != null)
        {
            PlayerScript.pushPull.PulledBy.CmdStopPulling();
        }
        PlayerScript.pushPull.CmdStopFollowing();
        PlayerScript.pushPull.CmdStopPulling();
        PlayerScript.pushPull.isNotPushable = true;
        onUnbuckled = unbuckledAction;

        //sync position to ensure they buckle to the correct spot
        playerScript.PlayerSync.SetPosition(toObject.TileWorldPosition().To3Int());

        //set direction if toObject has a direction
        var directionalObject = toObject.GetComponent <Directional>();

        if (directionalObject != null)
        {
            playerDirectional.FaceDirection(directionalObject.CurrentDirection);
        }
        else
        {
            playerDirectional.FaceDirection(playerDirectional.CurrentDirection);
        }

        //force sync direction to current direction
        playerDirectional.TargetForceSyncDirection(PlayerScript.connectionToClient);
    }
Ejemplo n.º 16
0
    /// <summary>
    /// Stunned info will ONLY be sent to subject!
    /// </summary>
    /// <param name="subjectPlayer"></param>
    /// <param name="upright"></param>
    /// <param name="isStunned"></param>
    public static void SendToAll(GameObject subjectPlayer, bool upright, bool isStunned)
    {
        if (!IsValid(subjectPlayer, upright))
        {
            return;
        }
        var msg = new PlayerUprightMessage
        {
            SubjectPlayer = subjectPlayer.NetId(),
            Upright       = upright,
            Stunned       = StunnedState.Unknown
        };

        msg.SendToAllExcept(subjectPlayer);
        msg.Stunned = isStunned ? StunnedState.Stunned : StunnedState.NonStunned;
        msg.SendTo(subjectPlayer);
    }
Ejemplo n.º 17
0
    /// <summary>
    /// Stops the player from moving and interacting for a period of time.
    /// Also drops held items by default.
    /// </summary>
    /// <param name="stunDuration">Time before the stun is removed.</param>
    /// <param name="dropItem">If items in the hand slots should be dropped on stun.</param>
    public void Stun(float stunDuration = 4f, bool dropItem = true)
    {
        isStunned = true;
        PlayerUprightMessage.SendToAll(gameObject, false);
        if (dropItem)
        {
            playerScript.playerNetworkActions.DropItem("leftHand");
            playerScript.playerNetworkActions.DropItem("rightHand");
        }
        playerScript.playerMove.allowInput = false;

        StartCoroutine(StunTimer(stunDuration));

        IEnumerator StunTimer(float stunTime)
        {
            yield return(new WaitForSeconds(stunTime));

            RemoveStun();
        }
    }
Ejemplo n.º 18
0
 public void RemoveStun()
 {
     PlayerUprightMessage.SendToAll(gameObject, true, false);
     playerScript.playerMove.allowInput = true;
 }