public void ServerPerformInteraction(HandApply interaction)
        {
            if (interaction.HandObject == null)
            {
                return;
            }

            if (Validations.HasItemTrait(interaction.UsedObject, CommonTraits.Instance.Wrench))
            {
                switch (orientation.AsEnum())
                {
                case OrientationEnum.Right:
                    directional.FaceDirection(Orientation.Up);
                    break;

                case OrientationEnum.Up:
                    directional.FaceDirection(Orientation.Left);
                    break;

                case OrientationEnum.Left:
                    directional.FaceDirection(Orientation.Down);
                    break;

                case OrientationEnum.Down:
                    directional.FaceDirection(Orientation.Right);
                    break;
                }
            }
        }
Example #2
0
 /// <summary>
 /// Nudge the Mob in a certain direction
 /// </summary>
 /// <param name="dir"></param>
 protected void NudgeInDirection(Vector2Int dir)
 {
     if (dir != Vector2Int.zero)
     {
         cnt.Push(dir, context: gameObject);
         directional.FaceDirection(Orientation.From(dir));
     }
 }
Example #3
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);
        }
    }
Example #4
0
    private void Rotate()
    {
        if (directional == null)
        {
            return;
        }

        // Obtains the new 90-degrees clockwise orientation of the current orientation.
        Orientation clockwise = directional.CurrentDirection.Rotate(1);

        directional.FaceDirection(clockwise);
    }
Example #5
0
        /// <summary>
        /// General use movement for npcs
        /// 0 = no move (1 - 8 are directions to move in reading from left to right)
        /// </summary>
        /// <param name="act"></param>
        protected void PerformMoveAction(int act)
        {
            if (act == 0)
            {
                performingDecision = false;
            }
            else
            {
                Vector2Int dirToMove = Vector2Int.zero;
                int        count     = 1;
                for (int y = 1; y > -2; y--)
                {
                    for (int x = -1; x < 2; x++)
                    {
                        if (count == act)
                        {
                            dirToMove.x += x;
                            dirToMove.y += y;
                            y            = -100;
                            break;
                        }
                        else
                        {
                            count++;
                        }
                    }
                }

                if (dirToMove == Vector2Int.zero)
                {
                    performingDecision = false;
                    return;
                }

                var dest = registerObj.LocalPositionServer + (Vector3Int)dirToMove;

                if (!cnt.Push(dirToMove, context: gameObject))
                {
                    //Path is blocked try again
                    performingDecision = false;
                    DoorController tryGetDoor =
                        registerObj.Matrix.GetFirst <DoorController>(
                            dest, true);
                    if (tryGetDoor)
                    {
                        tryGetDoor.MobTryOpen(gameObject);
                    }
                }
                else
                {
                    OnPushSolid(dest);
                }

                if (directional != null)
                {
                    directional.FaceDirection(Orientation.From(dirToMove));
                }
            }
        }
Example #6
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);
    }
Example #7
0
    private void ChangeDirection()
    {
        Vector3 playerPos;

        playerPos = transform.position;

        Vector2 dir = (MouseWorldPosition - playerPos).normalized;

        if (!EventSystem.current.IsPointerOverGameObject() && playerMove.allowInput && !playerMove.IsBuckled)
        {
            playerDirectional.FaceDirection(Orientation.From(dir));
        }
    }
Example #8
0
 public void Rotate()
 {
     if (directional != null)
     {
         // Obtains the new 90-degrees clockwise orientation of the current orientation.
         Orientation clockwise = directional.CurrentDirection.Rotate(1);
         directional.FaceDirection(clockwise);
     }
     else
     {
         transform.Rotate(0, 0, -90);
         SyncRotation(zRotation, transform.eulerAngles.z);
     }
 }
Example #9
0
    private void CalculateDirection()
    {
        float rotation    = transform.rotation.eulerAngles.z;
        var   orientation = Orientation.GetOrientation(rotation);

        if (orientation == Orientation.Up)              //look over later
        {
            orientation = Orientation.Down;
        }
        else if (orientation == Orientation.Down)
        {
            orientation = Orientation.Up;
        }
        SetDirection(orientation);
        directional.FaceDirection(orientation);
    }
Example #10
0
        /// <summary>
        /// General use movement for npcs
        /// 0 = no move (1 - 8 are directions to move in reading from left to right)
        /// </summary>
        /// <param name="act"></param>
        protected void PerformMoveAction(int act)
        {
            if (act == 0)
            {
                performingDecision = false;
                return;
            }
            if (objectBehaviour.parentContainer != null)
            {
                foreach (var escapable in objectBehaviour.parentContainer.GetComponents <IEscapable>())
                {
                    escapable.EntityTryEscape(gameObject, null);
                }
                return;
            }

            Vector2Int dirToMove = Vector2Int.zero;
            int        count     = 1;

            for (int y = 1; y > -2; y--)
            {
                for (int x = -1; x < 2; x++)
                {
                    if (count == act)
                    {
                        dirToMove.x += x;
                        dirToMove.y += y;
                        y            = -100;
                        break;
                    }
                    else
                    {
                        count++;
                    }
                }
            }

            if (dirToMove == Vector2Int.zero)
            {
                performingDecision = false;
                return;
            }

            var dest = registerObj.LocalPositionServer + (Vector3Int)dirToMove;

            if (!cnt.Push(dirToMove, context: gameObject))
            {
                //Path is blocked try again
                performingDecision = false;
                DoorController tryGetDoor =
                    registerObj.Matrix.GetFirst <DoorController>(
                        dest, true);
                if (tryGetDoor)
                {
                    tryGetDoor.MobTryOpen(gameObject);
                }

                //New doors
                DoorMasterController tryGetDoorMaster =
                    registerObj.Matrix.GetFirst <DoorMasterController>(
                        dest, true);
                if (tryGetDoorMaster)
                {
                    tryGetDoorMaster.Bump(gameObject);
                }
            }
            else
            {
                OnPushSolid(dest);
            }

            if (directional != null)
            {
                directional.FaceDirection(Orientation.From(dirToMove));
            }
        }
Example #11
0
        IEnumerator PerformFollowPath(List <Node> path)
        {
            int node = 1;

            while (node < path.Count)
            {
                if (!activated)
                {
                    yield return(WaitFor.EndOfFrame);

                    yield break;
                }

                if (!movingToTile)
                {
                    if (tickRate != 0f)
                    {
                        yield return(WaitFor.Seconds(tickRate));
                    }

                    var dir = path[node].position - Vector2Int.RoundToInt(transform.localPosition);
                    if (!registerTile.Matrix.IsPassableAtOneMatrixOneTile(registerTile.LocalPositionServer + (Vector3Int)dir, true, context: gameObject))
                    {
                        var dC = registerTile.Matrix.GetFirst <DoorController>(
                            registerTile.LocalPositionServer + (Vector3Int)dir, true);
                        if (dC != null)
                        {
                            dC.MobTryOpen(gameObject);
                            yield return(WaitFor.Seconds(1f));
                        }
                        else
                        {
                            ResetMovingValues();
                            FollowCompleted();
                            Logger.Log("Path following timed out. Something must be in the way", Category.Movement);
                            yield break;
                        }
                    }

                    if (directional != null)
                    {
                        directional.FaceDirection(Orientation.From(dir));
                    }

                    cnt.Push(dir, context: gameObject);
                    movingToTile = true;
                }
                else
                {
                    if (arrivedAtTile)
                    {
                        movingToTile  = false;
                        arrivedAtTile = false;
                        timeOut       = 0f;
                        node++;
                    }
                    else
                    {
                        //Mob has 5 seconds to get to the next tile
                        //or the AI should do something else
                        timeOut += Time.deltaTime;
                        if (timeOut > 5f)
                        {
                            ResetMovingValues();
                            Logger.Log("Path following timed out. Something must be in the way", Category.Movement);
                            FollowCompleted();
                            yield break;
                        }
                    }
                }

                yield return(WaitFor.EndOfFrame);
            }

            yield return(WaitFor.EndOfFrame);

            ResetMovingValues();
            FollowCompleted();
        }