Esempio n. 1
0
        /// <summary>
        /// Updates the task logic. Leads the human toward the action object and then lets him perform the action.
        /// </summary>
        /// <param name="gameTime">Game time</param>
        public override void Update(GameTime gameTime)
        {
            if (gameTime.TotalGameTime - lastUpdatedWaypoints > RecomputeWaypointsTimeout && actionObject.Position.Quarter == Holder.Position.Quarter)
            {
                goStraightToObject = false;

                Vector2    wayVect   = (actionObject.Position.PositionInQuarter - Holder.Position.PositionInQuarter);
                float      direction = (wayVect.GetAngle() + 1 * MathHelper.PiOver2) % MathHelper.TwoPi;
                Quadrangle viewLine  = Quadrangle.CreateBand(Holder.Pivot.PositionInQuarter, direction, Holder.Size.X, wayVect.Length());
                goStraightToObject = !Grid.IsInCollision(viewLine, c => !(c is Human));

                if (!goStraightToObject)
                {
                    RecomputeWaypoints(Holder.Position, actionObject.Position);
                }
                lastUpdatedWaypoints = gameTime.TotalGameTime;
            }

            if (goStraightToObject)
            {
                Holder.GoThisWay(actionObject.Position, (float)gameTime.ElapsedGameTime.TotalSeconds);
            }
            else
            {
                base.Update(gameTime);
            }

            if (actionObject.IsAvailableFor(Holder))
            {
                if (!started)
                {
                    actionObject.StartAction(Holder, gameTime);
                    actionStart = gameTime.TotalGameTime;
                    started     = true;
                }
                else
                {
                    if (gameTime.TotalGameTime - actionStart > actionObject.ActionDuration)
                    {
                        actionObject.EndAction(Holder, gameTime);
                        complete = true;
                    }
                }
            }
            else
            {
                if (WayPoints.Count == 0 && !IsComplete())
                {
                    RecomputeWaypoints(Holder.Position, actionObject.Position);
                    lastUpdatedWaypoints = gameTime.TotalGameTime;
                }
            }
        }