Exemple #1
0
    public void ServerBuckle(GameObject toObject, Action unbuckledAction = null)
    {
        var netid = toObject.NetId();

        if (netid == NetId.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>();

        if (buckleInteract.forceLayingDown)
        {
            registerPlayer.ServerLayDown();
        }
        else
        {
            registerPlayer.ServerStandUp();
        }

        SyncBuckledObjectNetId(0, 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.ServerStopPulling();
        }

        PlayerScript.pushPull.StopFollowing();
        PlayerScript.pushPull.ServerStopPulling();
        PlayerScript.pushPull.ServerSetPushable(false);
        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 (If it is a real player and not a NPC)
        if (PlayerScript.connectionToClient != null)
        {
            PlayerDirectional.TargetForceSyncDirection(PlayerScript.connectionToClient);
        }
    }
Exemple #2
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);
    }