Exemple #1
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);
         rotatable.SetFaceDirectionLocalVictor(dir);
     }
 }
Exemple #2
0
        protected void Move(Vector3Int dirToMove)
        {
            var dest = mobTile.LocalPositionServer + dirToMove;

            if (mobTile.customNetTransform.Push(dirToMove.To2Int(), context: gameObject) == false)
            {
                //New doors
                DoorMasterController tryGetDoorMaster = mobTile.Matrix.GetFirst <DoorMasterController>(dest, true);
                if (tryGetDoorMaster)
                {
                    tryGetDoorMaster.Bump(gameObject);
                }

                //Old doors
                DoorController tryGetDoor = mobTile.Matrix.GetFirst <DoorController>(dest, true);
                if (tryGetDoor)
                {
                    tryGetDoor.MobTryOpen(gameObject);
                }
            }

            if (rotatable != null)
            {
                rotatable.SetFaceDirectionLocalVictor(dirToMove.To2Int());
            }
        }
Exemple #3
0
        IEnumerator PerformFollowPath(List <Node> path)
        {
            int node = 1;

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

                    yield break;
                }

                if (!movingToTile)
                {
                    if (TickDelay.Approx(0) == false)
                    {
                        yield return(WaitFor.Seconds(TickDelay));
                    }

                    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 (rotatable != null)
                    {
                        rotatable.SetFaceDirectionLocalVictor(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();
        }