Exemple #1
0
 public MapChangement(IAccount account, ICellMovement cm, int nid)
 {
     _account               = account;
     _oId                   = account.Character.MapId;
     NewMap                 = nid;
     _cellMovement          = cm;
     _timeoutTimer          = new Timer(10000);
     _timeoutTimer.Elapsed += _timeoutTimer_Elapsed;
 }
Exemple #2
0
 private void RemoveEvents()
 {
     _account.Character.Map.MapChanged -= Map_MapChanged;
     if (_cellMovement != null)
     {
         _cellMovement.MovementFinished -= _cellMovement_MovementFinished;
         _cellMovement = null;
     }
     _timeoutTimer.Stop();
     _timeoutTimer.Dispose();
     _timeoutTimer = null;
 }
Exemple #3
0
        private void _cellMovement_MovementFinished(object sender, CellMovementEventArgs e)
        {
            _cellMovement.MovementFinished -= _cellMovement_MovementFinished;
            _cellMovement = null;

            if (!e.Sucess)
            {
                OnChangementFinished(false);
                return;
            }

            _account.Character.Map.MapChanged += Map_MapChanged;
            _account.Network.SendToServer(new ChangeMapMessage(NewMap));
        }
Exemple #4
0
        private void Map_MovementConfirmed(object sender, MovementConfirmed e)
        {
            _account.Character.Map.MovementConfirmed -= Map_MovementConfirmed;
            _cellMovement = null;

            if (!e.Status)
            {
                OnChangementFinished(false);
                return;
            }

            _account.Character.Map.MapChanged += Map_MapChanged;
            Console.WriteLine($"Sending ChangeMapMessage");
            Task.Delay(150).ContinueWith(t =>
                                         _account.Network.SendToServer(new ChangeMapMessage(NewMap, false))
                                         );
        }
Exemple #5
0
        /// <summary>
        ///     Starts the Gather routine
        /// </summary>
        /// <param name="params">RessourceList</param>
        /// <param name="autoGather">true if autogathering</param>
        public void Gather(List <int> @params, bool autoGather)
        {/* This function will be responsible for moving close to the element and harvesting if possible.
          * Loop thru the items to harvest to check weather that ressource id is present on the items and if it's harvestable.*/
            //Starting getting which element is closer to our bot
            IUsableElement element = GetClosestHarvestable(@params);

            if (element != null)
            {
                Logger.Default.Log($"Element Found. Moving to [{element.CellId}]", API.Utils.Enums.LogMessageType.Arena);
                uint          id = element.Element.Id;
                var           skillInstanceUid = element.Skills[0].SkillInstanceUid;
                ICellMovement move             = _account.Character.Map.MoveToElement(id, 1);
                if (move == null)
                {
                    move = _account.Character.Map.MoveToElement(id, 2);
                }
                move.MovementFinished += (movement, message) =>
                {
                    Logger.Default.Log($"Movement perfomed. Status[{message.Sucess}]", API.Utils.Enums.LogMessageType.Arena);
                    if (message.Sucess)
                    {
                        MovementAutoReset.Set();
                    }
                };
                move.PerformMovement();
                if (MovementAutoReset.WaitOne(Delay)) //Wait for the movement delay.
                {
                    Logger.Default.Log($"Farming the ressource.", API.Utils.Enums.LogMessageType.Arena);
                    _account.Character.Map.UseElement((int)id, skillInstanceUid); //server will reply with InteractiveUsedMessage then once done InteractiveElementUpdatedMessage
                    if (InteractiveUsedAutoReset.WaitOne(Delay))                  // if this returns true we execute Gather. else return;
                    {
                        if (_account.Character.PathManager.Launched)
                        {
                            _account.Character.PathManager.GatherManagerDoActionByPass();
                        }
                    }
                }
            }
        }
        private MovementEnum MoveToHit(IFighter fighter, IASpell spell, bool handToHand = false)
        {
            if (Moving)
            {
                return(MovementEnum.AlreadyInMove);
            }
            if (Fighter.MovementPoints <= 0) //not Enough movement points.
            {
                return(MovementEnum.NoMovementPoints);
            }
            //Bot has to move somewhere.
            var moveCell = -1;
            var distance = -1; // We gonna be looking for the smaller distance to go in order to be able to cast this _currentSkill

            if (handToHand)
            {
                foreach (var destCell in _account.Character.Fight.GetReachableCells()) // gathering where the bot can go.
                {
                    if (_account.Character.Fight.IsHandToHand(destCell))
                    {//if we gonna be handtohand to the nearestmob then we can break the loop
                        moveCell = destCell;
                        MapPoint characterPoint = new MapPoint(destCell);
                        distance = characterPoint.DistanceToCell(new MapPoint(fighter.CellId));
                        break;
                    }
                }
            }
            else
            {
                foreach (var destCell in _account.Character.Fight.GetReachableCells()) // gathering where the bot can go. Not pathFinding tho.
                {
                    if (_account.Character.Fight.CanLaunchSpellOn(spell.SpellId, destCell, fighter.CellId, true) != SpellInabilityReason.None)
                    {
                        continue; //this specific destCell wont let it use this specific skill
                    }
                    MapPoint characterPoint = new MapPoint(destCell);
                    int      tempDistance   = characterPoint.DistanceToCell(new MapPoint(fighter.CellId));

                    if (tempDistance <= distance && distance != -1)
                    {
                        continue;
                    }
                    distance = tempDistance;
                    moveCell = destCell;
                }
            }

            if (moveCell == -1) // even moving wont be able to hit the target
            {
                return(MovementEnum.NotEnoughMovement);
            }
            ICellMovement movement = _account.Character.Fight.MoveToCell(moveCell);

            if (movement != null)
            {
                //movement.MovementFinished += (x,e) =>
                //{
                //    Moving = false;
                //    if (e.Sucess) // If success then we send a signal to continue with execution. If it fails let it return null;
                //    {
                //        Logger.Default.Log($"{e.Distance} Mps used Total[{Fighter.MovementPoints}]",LogMessageType.FightLog);
                //        Fighter.MovementPoints -= (short)(e.Distance+1);
                //        movementAutoReset.Set();
                //    }else
                //        Logger.Default.Log($"Movement Performed but failed.", LogMessageType.FightLog);
                //    return;
                //};
                //Moving = true;
                movement.MovementFinished += Movement_MovementFinished;
                movement.PerformMovement();
                return(MovementEnum.Success);
            }
            throw new Exception("Movement cannot be null");
        }