Esempio n. 1
0
        public LevelObjectiveResult CheckRequiredObjectives(string category = null)
        {
            var pending = false;

            for (var i = 0; i < this.objectives.Count; i++)
            {
                var objective = this.objectives[i];

                var categoryMatch = category == null || string.Equals(objective.Category, category, StringComparison.OrdinalIgnoreCase);

                if (categoryMatch && objective.IsRequired)
                {
                    var status = objective.CheckObjectiveStatus();

                    log.Trace("Checked level objective").Field("name", objective.Name).Field("status", status).Write();

                    switch (status)
                    {
                    case LevelObjectiveResult.Failed:
                        return(LevelObjectiveResult.Failed);

                    case LevelObjectiveResult.Pending:
                        // If any required objective is pending, we don't need to check the rest.
                        pending = true;
                        break;

                    default:
                        break;
                    }
                }
            }

            return(pending ? LevelObjectiveResult.Pending : LevelObjectiveResult.Completed);
        }
Esempio n. 2
0
        void Update()
        {
            // Find the max distance we can travel this tick.
            var maxDistance          = this.Speed * Time.deltaTime;
            var remainingMovableDist = maxDistance;

            while (this.Current != null && remainingMovableDist > 0f)
            {
                if (this.Current != null)
                {
                    if (this.vectorPath.Count == 0)
                    {
                        this.BuildVectorPath();
                    }

                    var targetPos    = this.vectorPath[0];
                    var distToTarget = (targetPos - this.cachedTx.position).magnitude;
                    var distToTravel = Mathf.Min(distToTarget, remainingMovableDist);
                    var arrived      = distToTravel == distToTarget;

                    this.cachedTx.position = Vector3.MoveTowards(this.cachedTx.position, targetPos, distToTravel);

                    switch (this.LookMode)
                    {
                    case WaypointPathMoverLookMode.None:
                        break;

                    case WaypointPathMoverLookMode.WorldUp:
                        this.cachedTx.LookAt(targetPos);
                        break;

                    case WaypointPathMoverLookMode.TransformUp:
                        this.cachedTx.LookAt(targetPos, this.cachedTx.up);
                        break;
                    }

                    remainingMovableDist -= distToTravel;

                    if (arrived)
                    {
                        if (this.loggingEnabled && logger.Status.IsTraceEnabled)
                        {
                            logger.Trace("Arrived at vectorPath point", x => x.Field("vectorPathPoint", this.vectorPath[0]).Field("remainingVectorPathPoints", this.vectorPath.Count - 1));
                        }

                        // We've reached the end of a curve slice, so move to the next one.
                        // TODO: Pop from the end.
                        this.vectorPath.RemoveAt(0);
                    }

                    if (arrived && this.vectorPath.Count == 0)
                    {
                        // We've arrived at the current waypoint.

                        if (this.loggingEnabled && logger.Status.IsTraceEnabled)
                        {
                            logger.Trace("Arrived at waypoint", x => x.Field("current", this.Current));
                        }

                        this.Previous = this.Current;

                        IWaypoint next;
                        if (this.Path.TryGetNext(this.Current, out next))
                        {
                            this.Current = next;
                            this.WaypointChanged(this.Previous, this.Current);
                        }
                        else
                        {
                            // We've reached the end of the path.
                            if (this.Loop)
                            {
                                this.Current = this.Path[0];
                                this.WaypointChanged(this.Previous, this.Current);
                            }
                            else
                            {
                                this.Current = null;
                                this.WaypointChanged(this.Previous, this.Current);
                                this.fsm.TriggerArrived();
                            }
                        }

                        if (this.loggingEnabled && logger.Status.IsTraceEnabled)
                        {
                            logger.Trace("Next waypoint assigned as current waypoint", x => x.Field("current", this.Current));
                        }

                        this.vectorPath.Clear();
                    }
                }
            }
        }