Пример #1
0
        /// <summary>
        /// Keeps the vehicle state updated, and sends an update packet if necessary
        /// </summary>
        /// <returns>A boolean indicating whether an update packet should be sent</returns>
        public override bool poll()
        {
            //If not reloaded yet don't fire
            int now = Environment.TickCount;

            if (_tickShotTime + _fireDelay > now ||
                _tickReloadTime > now)
            {   //But maybe send an update packet?
                if (now - _tickLastUpdate > 300)
                {
                    _tickLastUpdate = now;
                    return(true);
                }

                return(false);
            }

            //FIRE -- the Projectile class will take care of aiming and targeting but make sure we can shoot here
            if (getTarget() != null)
            {
                _moba.spawnProjectile((ushort)104, _state, _team);
            }

            //Adjust ammo accordingly
            if (_ammoCapacity != 0 && --_ammoRemaining <= 0)
            {
                _tickReloadTime = Environment.TickCount + _reloadTime;
                _ammoRemaining  = _ammoCapacity;
            }

            return(true);
        }
Пример #2
0
        /// <summary>
        /// Looks after the bot's functionality
        /// </summary>
        public override bool poll()
        {
            if (IsDead)
            {                                  //Dead
                steering.steerDelegate = null; //Stop movements
                bCondemned             = true; //Make sure the bot gets removed in polling
                return(base.poll());
            }

            int now = Environment.TickCount;

            //Find the nearest tower/inhibitor/HQ/bot in our lane
            _targetVehicle = getTargetVehhicle();
            //Find the nearest player
            _targetPlayer = getTargetPlayer();

            if (_targetPlayer == null)
            {
                //Find a clear path
                bool bClearPath = true;
                // if (!_attacking)
                //   {
                bClearPath = Helpers.calcBresenhemsPredicate(_arena, _state.positionX, _state.positionY, (short)(_targetVehicle._state.positionX + 150), (short)(_targetVehicle._state.positionY + 150),
                                                             delegate(LvlInfo.Tile t)
                {
                    return(!t.Blocked);
                }
                                                             );
                //   }

                //Check for waypoint
                if (_targetVehicle._type.Id == 999)
                {
                    steering.steerDelegate = steerForFollowOwner;
                }

                //Not a waypoint
                else if (bClearPath && Helpers.distanceTo(_targetVehicle._state, _state) > 45 && _targetVehicle._type.Id != 999)
                {       //Persue directly!
                    steering.steerDelegate = steerForFollowOwner;
                    //Can we shoot?
                    if (_weapon.ableToFire())
                    {
                        int aimResult = _weapon.getAimAngle(_targetVehicle._state);

                        if (_weapon.isAimed(aimResult) && Helpers.distanceTo(_targetVehicle._state, _state) < 300)
                        {       //Spot on! Fire?
                            //_movement.freezeMovement(500);
                            _itemUseID = _weapon.ItemID;
                            _weapon.shotFired();
                            _attacking = true;

                            //Shoot homing weapon
                            _moba.spawnProjectile(105, _state, _team);
                            //Change this to allow for minion vs minion kills to grant rewards
                            if (!_targetVehicle._bBotVehicle)
                            {
                                _targetVehicle.update(true);
                                if (_targetVehicle._state.health <= 0)
                                {
                                    _targetVehicle.destroy(false);
                                    _moba.teamReward(_targetVehicle._type.Id, _team);
                                }
                            }
                        }

                        steering.bSkipAim = true;
                        steering.angle    = aimResult;
                    }
                    else
                    {
                        steering.bSkipAim = false;
                    }
                }
                else
                {
                    //Does our path need to be updated?
                    if (now - _tickLastPath > _pathUpdateInterval)
                    {
                        //Update it!
                        _tickLastPath = int.MaxValue;
                        _attacking    = false;
                        Random rnd = new Random(Environment.TickCount);
                        _arena._pathfinder.queueRequest(
                            (short)(_state.positionX / 16), (short)(_state.positionY / 16),
                            (short)((_targetVehicle._state.positionX + (rnd.NextDouble() * (2000) - 1000)) / 16), (short)((_targetVehicle._state.positionY) / 16),
                            delegate(List <Vector3> path, int pathLength)
                        {
                            if (path != null)
                            {
                                _path       = path;
                                _pathTarget = 1;
                            }
                            _tickLastPath = now;
                        }
                            );
                    }
                    if (_path == null)
                    {
                        //If we can't find our way to vehicle, just mindlessly walk in its direction for now [this should never happen
                        steering.steerDelegate = steerForFollowOwner;
                    }
                    else
                    {
                        steering.steerDelegate = steerAlongPath;
                    }
                }
            }
            else
            {//The player is closer
                //Find a clear path
                bool bClearPath = Helpers.calcBresenhemsPredicate(_arena, _state.positionX, _state.positionY, _targetPlayer._state.positionX, _targetPlayer._state.positionY,
                                                                  delegate(LvlInfo.Tile t)
                {
                    return(!t.Blocked);
                }
                                                                  );

                if (bClearPath)
                {       //Persue directly!
                    steering.steerDelegate = steerForPersuePlayer;
                    //Can we shoot?
                    if (_weapon.ableToFire())
                    {
                        int aimResult = _weapon.getAimAngle(_targetPlayer._state);

                        if (_weapon.isAimed(aimResult) && Helpers.distanceTo(_targetPlayer._state, _state) < 200)
                        {       //Spot on! Fire?
                            _itemUseID = _weapon.ItemID;
                            _weapon.shotFired();
                            _moba.spawnProjectile(105, _state, _team);
                        }
                        steering.bSkipAim = true;
                        steering.angle    = aimResult;
                    }
                    else
                    {
                        steering.bSkipAim = false;
                    }
                }
                else
                {
                    //Does our path need to be updated?
                    if (now - _tickLastPath > _pathUpdateInterval)
                    {
                        //Update it!
                        _tickLastPath = int.MaxValue;

                        _arena._pathfinder.queueRequest(
                            (short)(_state.positionX / 16), (short)(_state.positionY / 16),
                            (short)(_targetPlayer._state.positionX / 16), (short)(_targetPlayer._state.positionY / 16),
                            delegate(List <Vector3> path, int pathLength)
                        {
                            if (path != null)
                            {
                                _path       = path;
                                _pathTarget = 1;
                            }
                            _tickLastPath = now;
                        }
                            );
                    }
                }
            }
            //Handle normal functionality
            return(base.poll());
        }