Beispiel #1
0
        public void SendTroops(Troops troops, int coordinateX, int coordinateY, TroopsIntentions troopsIntentions, SendingTroopsInfo sendingTroopsInfo = null)
        {
            var stopwatch      = Stopwatch.StartNew();
            var featureResults = FeatureResults.Success;

            try
            {
                OnFeatureStart?.Invoke(MethodBase.GetCurrentMethod().Name, DateTime.Now);
                _plemionaDefaultFeatures.SendTroops(troops, coordinateX, coordinateY, troopsIntentions, sendingTroopsInfo);
            }
            catch (BotCheckException)
            {
                featureResults = FeatureResults.BotCheck;
                throw;
            }
            catch (FeatureException fe)
            {
                featureResults = fe.PlemionaError ? FeatureResults.PlemionaError : FeatureResults.UnexpectedError;
                throw;
            }
            finally
            {
                OnFeatureEnd?.Invoke(MethodBase.GetCurrentMethod().Name, DateTime.Now, stopwatch.ElapsedMilliseconds, featureResults);
                stopwatch.Stop();
            }
        }
Beispiel #2
0
        public void SendTroops(Troops troops, int coordinateX, int coordinateY, TroopsIntentions troopsIntentions, SendingTroopsInfo sendingTroopsInfo = null)
        {
            try
            {
                if ((sendingTroopsInfo == null) || (sendingTroopsInfo.CurrentOrderNumber == 1))
                {
                    _stepExecutionService.Execute("ClickBuildingPicture", BuildingTypes.Yard);
                }

                if (troops.Spearmen > 0)
                {
                    _stepExecutionService.Execute("FillYardSpearmenCountTextBox", troops.Spearmen);
                }
                if (troops.Swordmen > 0)
                {
                    _stepExecutionService.Execute("FillYardSwordmenCountTextBox", troops.Swordmen);
                }
                if (troops.Axemen > 0)
                {
                    _stepExecutionService.Execute("FillYardAxemenCountTextBox", troops.Axemen);
                }
                if (troops.Bowmen > 0)
                {
                    _stepExecutionService.Execute("FillYardBowmenCountTextBox", troops.Bowmen);
                }

                if (troops.Scouts > 0)
                {
                    _stepExecutionService.Execute("FillYardScoutCountTextBox", troops.Scouts);
                }
                if (troops.LightCavalary > 0)
                {
                    _stepExecutionService.Execute("FillYardLightCavalaryCountTextBox", troops.LightCavalary);
                }
                if (troops.HorseArchers > 0)
                {
                    _stepExecutionService.Execute("FillYardHorseArchersCountTextBox", troops.HorseArchers);
                }
                if (troops.HeavyCavalary > 0)
                {
                    _stepExecutionService.Execute("FillYardHeavyCavalaryCountTextBox", troops.HeavyCavalary);
                }

                if (troops.Rams > 0)
                {
                    _stepExecutionService.Execute("FillYardRamsCountTextBox", troops.Rams);
                }
                if (troops.Catapultes > 0)
                {
                    _stepExecutionService.Execute("FillYardCatapultesCountTextBox", troops.Catapultes);
                }

                if (troops.Knights > 0)
                {
                    _stepExecutionService.Execute("FillYardKnightsCountTextBox", troops.Knights);
                }
                if (troops.Noblemen > 0)
                {
                    _stepExecutionService.Execute("FillYardNobelmenCountTextBox", troops.Noblemen);
                }

                _stepExecutionService.Execute("FillYardVillageCoordinatesTextBox", new Point(coordinateX, coordinateY));

                if (troopsIntentions == TroopsIntentions.Attack)
                {
                    _stepExecutionService.Execute("ClickSendAttackButton");
                }
                else
                {
                    _stepExecutionService.Execute("ClickSendHelpButton");
                }

                _stepExecutionService.Execute("ClickSendTroopsConfirmationButton");

                if ((sendingTroopsInfo == null) || sendingTroopsInfo.IsLastOrderInSequence)
                {
                    _stepExecutionService.Execute("ClickVillageViewButton");
                }
            }
            catch (BotCheckException bce)
            {
                _featureLoggingService.LogBotCheck(MethodBase.GetCurrentMethod().Name, bce.CurrentStep);
                throw;
            }
            catch (Exception e)
            {
                string errorMessage  = string.Empty;
                bool   plemionaError = false;

                if (_stepExecutionService.Execute <bool>("IsErrorMessagePresent"))
                {
                    plemionaError = true;
                    errorMessage  = _stepExecutionService.Execute <string>("GetErrorMessage");
                }
                else
                {
                    errorMessage = e.Message;
                    _featureLoggingService.LogException(e, MethodBase.GetCurrentMethod().Name);
                }

                TryToReturnToVillageView();

                throw new FeatureException(plemionaError, errorMessage);
            }
        }