Example #1
0
        private void PushObject(PushPull objectToPush, Vector3 pushVector)
        {
            if (CurrentStage == SingularityStages.Stage5 || CurrentStage == SingularityStages.Stage4)
            {
                //Try stun player
                if (DMMath.Prob(10) && TryGetComponent <PlayerHealth>(out var playerHealth) && playerHealth != null &&
                    !playerHealth.IsDead)
                {
                    playerHealth.GetComponent <RegisterPlayer>().ServerStun();
                    Chat.AddActionMsgToChat(objectToPush.gameObject, "You are knocked down by the singularity",
                                            $"{objectToPush.gameObject.ExpensiveName()} is knocked down by the singularity");
                }
            }
            else if (objectToPush.IsPushable == false)
            {
                //Dont push anchored objects unless stage 5 or 4
                return;
            }

            //Push Twice
            objectToPush.QueuePush(pushVector.NormalizeTo2Int());
            objectToPush.QueuePush(pushVector.NormalizeTo2Int());
        }
    private IEnumerator InteractSpacePushable(PushPull pushable, Vector2 direction, bool isRecursive = false, int i = 0)
    {
        //Return if pushable is solid and you're trying to walk through it
        Vector3Int pushablePosition = pushable.Pushable.ServerPosition;

        if (pushable.IsSolid && pushablePosition == this.ServerPosition + direction.RoundToInt())
        {
            Logger.LogTraceFormat("Not doing anything: trying to push solid {0} through yourself", Category.PushPull, pushable.gameObject);
            yield break;
        }

        Logger.LogTraceFormat((isRecursive ? "Recursive " : "") + "Trying to space push {0}", Category.PushPull, pushable.gameObject);

        if (!isRecursive)
        {
            i = CalculateRequiredPushes(this.ServerPosition, pushablePosition, direction);
            Logger.LogTraceFormat("Calculated {0} required pushes", Category.PushPull, i);
        }

        if (i <= 0)
        {
            yield break;
        }

        Vector2 counterDirection = Vector2.zero - direction;

        pushable.QueuePush(Vector2Int.RoundToInt(counterDirection));
        i--;
        Logger.LogTraceFormat("Queued obstacle push. {0} pushes left", Category.PushPull, i);

        if (i <= 0)
        {
            yield break;
        }

        pushPull.QueuePush(Vector2Int.RoundToInt(direction));
        i--;
        Logger.LogTraceFormat("Queued player push. {0} pushes left", Category.PushPull, i);


        if (i > 0)
        {
            StartCoroutine(InteractSpacePushable(pushable, direction, true, i));
        }

        yield return(null);
    }
Example #3
0
    private IEnumerator InteractSpacePushable(PushPull pushable, Vector2 direction, bool isRecursive = false, int i = 0)
    {
        Logger.LogTraceFormat((isRecursive ? "Recursive " : "") + "Trying to space push {0}", Category.PushPull, pushable.gameObject);

        if (!isRecursive)
        {
            i = CalculateRequiredPushes(serverState.WorldPosition, pushable.registerTile.WorldPosition, direction);
            Logger.LogFormat("Calculated {0} required pushes", Category.Movement, i);
        }

        if (i <= 0)
        {
            yield break;
        }

        Vector2 counterDirection = Vector2.zero - direction;

        pushable.QueuePush(Vector2Int.RoundToInt(counterDirection));
        i--;
        Logger.LogFormat("Queued obstacle push. {0} pushes left", Category.Movement, i);

        if (i <= 0)
        {
            yield break;
        }

        pushPull.QueuePush(Vector2Int.RoundToInt(direction));
        i--;
        Logger.LogFormat("Queued player push. {0} pushes left", Category.Movement, i);


        if (i > 0)
        {
            StartCoroutine(InteractSpacePushable(pushable, direction, true, i));
        }

        yield return(null);
    }