예제 #1
0
        public FlightChase(GameObject actor, Dictionary <string, short> paramList) : base(actor, paramList)
        {
            // Retrieve Mechanics
            this.axis  = (paramList == null || !paramList.ContainsKey("axis") ? (byte)FlightChaseAxis.Both : (byte)paramList["axis"]);
            this.speed = FInt.Create((paramList == null || !paramList.ContainsKey("speed") ? 100 : paramList["speed"]) * 0.01 * 2);

            // Chase Distance Mechanics
            this.stall = (paramList == null || !paramList.ContainsKey("stall") ? (byte)0 : (byte)paramList["axis"]);            // In Tiles
            this.flee  = (paramList == null || !paramList.ContainsKey("flee") ? (byte)0 : (byte)paramList["flee"]);             // In Tiles
            this.chase = (paramList == null || !paramList.ContainsKey("chase") ? (byte)0 : (byte)paramList["chase"]);           // In Tiles

            this.chase *= (byte)TilemapEnum.TileWidth;
            this.stall *= (byte)TilemapEnum.TileWidth;
            this.flee  *= (byte)TilemapEnum.TileWidth;

            this.reactDist = Math.Max(this.chase, Math.Max(this.stall, this.flee));             // Get the largest reaction distance for view purposes.

            // Returns Back to Starting Position
            this.returns  = (paramList == null || !paramList.ContainsKey("returns") ? true : false);
            this.retDelay = (paramList == null || !paramList.ContainsKey("retDelay") ? (byte)120 : (byte)paramList["retDelay"]);              // Frames

            // Cluster Parent Handling
            this.clusterId = (paramList == null || !paramList.ContainsKey("clusterId") ? (byte)0 : (byte)paramList["clusterId"]);

            // Quick Actions
            this.quickAct     = ChaseAction.Standard;
            this.waitEndFrame = 0;

            // Positions
            this.startPos = new Vector2(actor.posX + actor.bounds.MidX, actor.posY + actor.bounds.MidY);
        }
 public void UpdateIntervalTime(ChaseAction action, AIStateController controller)
 {
     currentPathUpdateIntervalTime += Time.deltaTime;
     if (currentPathUpdateIntervalTime > action.PathUpdateIntervalTime)
     {
         currentPathUpdateIntervalTime = 0;
         UpdatePath(controller);
     }
 }
예제 #3
0
        private void TryUpdateBehavior(int midX, int midY)
        {
            // If there is no character in sight, check for a new one:
            if (this.charBeingChased is Character == false)
            {
                int objectId = this.WatchForCharacter(midX, midY);

                if (objectId > 0)
                {
                    this.charBeingChased = (Character)this.actor.room.objects[(byte)LoadOrder.Character][objectId];
                }
            }

            // Prepare Values
            int frame = Systems.timer.Frame;

            // Get distance from Character, if applicable.
            int destX    = this.charBeingChased is Character ? this.charBeingChased.posX + this.charBeingChased.bounds.MidX : midX;
            int destY    = this.charBeingChased is Character ? this.charBeingChased.posY + this.charBeingChased.bounds.MidY : midY;
            int distance = FPTrigCalc.GetDistance(FVector.Create(midX, midY), FVector.Create(destX, destY)).RoundInt;

            // Assign New Chase Action (When Action Time Expires).

            // Flee
            if (this.flee > 0 && distance < this.flee)
            {
                this.quickAct = ChaseAction.Flee;
            }

            // Chase
            else if (this.chase > 0 && distance <= this.chase)
            {
                this.quickAct = ChaseAction.Chase;
            }

            // Return to Start Position
            else if (this.returns)
            {
                if (this.quickAct == ChaseAction.Return || (this.quickAct == ChaseAction.Wait && this.waitEndFrame < frame))
                {
                    this.quickAct = ChaseAction.Return;
                }
                else
                {
                    this.quickAct     = ChaseAction.Wait;
                    this.waitEndFrame = this.waitEndFrame < frame ? frame + this.retDelay : this.waitEndFrame;
                }
            }

            // Standard: Do Nothing
            else
            {
                this.quickAct = ChaseAction.Standard;
            }
        }