Ejemplo n.º 1
0
        public void Update(KeyboardState kstate, GameTime gameTime, Camera camera)
        {
            timeSinceLastShot     += gameTime.ElapsedGameTime.Milliseconds;
            timeSinceLastExpClean += gameTime.ElapsedGameTime.Milliseconds;

            if (showHealthBar)
            {
                timeShowingHealthBar += gameTime.ElapsedGameTime.Milliseconds;
            }
            if (timeShowingHealthBar > millisecondsToShowHealthBar)
            {
                showHealthBar        = false;
                timeShowingHealthBar = 0;
            }

            foreach (var shot in Shots)
            {
                shot.Update(gameTime);
            }

            if (timeSinceLastExpClean > millisecondsExplosionLasts)
            {
                // remove exploded shots
                for (int i = 0; i < Shots.Count; i++)
                {
                    if (Shots[i].exploded || Shots[i].outOfRange)
                    {
                        Shots.RemoveAt(i);
                    }
                }
                timeSinceLastExpClean = 0;
            }

            if (timeSinceLastShot > millisecondsNewShot && Shots.Count < maxShotsMoving && health > 0)
            {
                Vector2?shotDirection = AIUtility.ChooseTargetVector(teamType, range, GetBoundingBox(), inInteriorId);
                if (shotDirection != null)
                {
                    BaseCannonBall cannonShot = new BaseCannonBall(teamType, regionKey, location, _content, _graphics);
                    cannonShot.SetFireAtDirection(shotDirection.Value, RandomEvents.rand.Next(10, 25), RandomEvents.rand.Next(-100, 100)); // 3rd param is aim offset
                    cannonShot.moving = true;
                    Shots.Add(cannonShot);
                }
                timeSinceLastShot = 0;
            }

            SpatialBounding.SetQuad(GetBase());
        }
Ejemplo n.º 2
0
        private void NpcSetFlee(bool useAStar, GameTime gt)
        {
            // if target within range, move towards it
            Vector2?targetV = AIUtility.ChooseTargetVector(teamType, GetBoundingBox().Width * 3, GetBoundingBox(), inInteriorId);

            if (targetV != null && !roaming)
            {
                idle = false;
                if (this is IFlying)
                {
                    flying = true;
                }

                ResetRoam(useAStar);
            }
        }
Ejemplo n.º 3
0
        private void NpcSetAttackInRange(GameTime gt)
        {
            // attack range
            Vector2?targetV = AIUtility.ChooseTargetVector(teamType, GetBoundingBox().Width * 2, GetBoundingBox(), inInteriorId);

            if (targetV != null)
            {
                idle = false;
                // IN COMBAT
                if (!inCombat)
                {
                    currColumnFrame = combatFrameIndex;
                }
                inCombat = true;
                Tuple <int, int> frames = AIUtility.SetAIGroundMovement((Vector2)targetV, location);
                currRowFrame     = frames.Item1 + nIdleRowFrames; // plus one to skip the idle frame
                directionalFrame = frames.Item2;
            }
        }
Ejemplo n.º 4
0
        private void NpcSetMoveTowardsTarget(int bbRange, GameTime gt)
        {
            // if target within range, move towards it
            Vector2?targetV = AIUtility.ChooseTargetVector(teamType, GetBoundingBox().Width *bbRange, GetBoundingBox(), inInteriorId);

            if (targetV != null)
            {
                idle = false;
                Tuple <int, int> frames = AIUtility.SetAIGroundMovement((Vector2)targetV, location);
                currRowFrame     = frames.Item1 + nIdleRowFrames; // plus one to skip the idle frame
                directionalFrame = frames.Item2;
                moving           = true;
                defense          = true;
            }
            else
            {
                idle    = true;
                defense = false;
            }
        }
Ejemplo n.º 5
0
        private void AIUpdate(GameTime gameTime)
        {
            // AI only works if NPC aboard
            if (shipInterior.interiorObjects.OfType <Npc>().Any())
            {
                // AI ship direction and movement
                if (timeSinceLastTurn > millisecondsPerTurn)
                {
                    if (!roaming)
                    {
                        if (regionKey.Equals("GustoMap")) // TEMP see pathFind comment below
                        {
                            regionKey = "Usopp";
                        }

                        randomRoamTile = BoundingBoxLocations.RegionMap[regionKey].RegionOceanTiles[RandomEvents.rand.Next(BoundingBoxLocations.RegionMap[regionKey].RegionOceanTiles.Count)];
                        roaming        = true;
                        TilePiece rtp         = (TilePiece)randomRoamTile;
                        Point?    gridPointTo = rtp.mapCordPoint;
                        currentPath = AIUtility.Pathfind(mapCordPoint.Value, gridPointTo.Value, PathType.Ocean); // NOTE: This freezes the game when hitting GustoMap region (because it is almost all the tiles at the moment)
                    }
                    else
                    {
                        // move to attack/follow target when in range
                        int shotRange = mountedOnShip == null ? 0 : mountedOnShip.shotRange;
                        if (shotRange > 0)
                        {
                            Tuple <Point?, float> targetInfo = AIUtility.ChooseTargetPoint(teamType, shotRange, GetBoundingBox(), inInteriorId, PathType.Ocean);
                            if (targetInfo != null)
                            {
                                // stop distance
                                var distanceToTarget = targetInfo.Item2;
                                if (distanceToTarget <= stopRange)
                                {
                                    moving          = false;
                                    shipSail.moving = false;
                                }
                                else
                                {
                                    moving          = true;
                                    shipSail.moving = true;
                                }

                                Point?targetMapCords = targetInfo.Item1;
                                // compute follow path
                                if (!following)
                                {
                                    currentPath = AIUtility.Pathfind(mapCordPoint.Value, targetMapCords.Value, PathType.Ocean);
                                    following   = true;
                                }
                            }
                            else
                            {
                                following = false;
                            }
                        }


                        // we have found the next tile in path
                        if (currentPath[0].GetBoundingBox().Intersects(GetBoundingBox()))
                        {
                            currentPath.RemoveAt(0);
                            if (currentPath.Count == 0)
                            {
                                roaming   = false;
                                following = false;
                            }
                        }

                        if (roaming)
                        {
                            currRowFrame = AIUtility.SetAIShipDirection(currentPath[0].GetBoundingBox().Center.ToVector2(), location);
                        }
                    }

                    shipSail.currRowFrame = currRowFrame;
                    timeSinceLastTurn    -= millisecondsPerTurn;
                }

                // AI shooting
                if (mountedOnShip != null)
                {
                    Vector2?shotDirection = AIUtility.ChooseTargetVector(teamType, mountedOnShip.shotRange, GetBoundingBox(), inInteriorId);
                    mountedOnShip.UpdateAIMountShot(gameTime, shotDirection);
                    // temp setting AI to use weapon slot 0
                    Vector2 weaponPosOffset = new Vector2(ShipMountTextureCoordinates.WeaponMountCords[bbKey][currRowFrame][0].Item1, ShipMountTextureCoordinates.WeaponMountCords[bbKey][currRowFrame][0].Item2);
                    mountedOnShip.location = GetBoundingBox().Center.ToVector2() + weaponPosOffset;
                }
            }
        }