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(); } }
private async void GridTroopsOrders_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (GridTroopsOrders.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.RowIndex >= 0) { string clickedTroopsOrderName = GridTroopsOrders.Rows[e.RowIndex].Cells[1].Value.ToString(); var clickedTroopOrder = _plemionaToolLocalData.TroopsOrders.Single(ta => ta.Name == clickedTroopsOrderName); var dialogResult = MessageBox.Show($"Are you sure that you want to perform order \"{clickedTroopOrder.Name}\"?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dialogResult == DialogResult.Yes) { SetReady(false); await Task.Run(() => { int orderCount = clickedTroopOrder.VillagesCoordinates.Count(); int fixedOrderCount = orderCount; int currentOrderNumber = 0; for (int i = 0; i < orderCount; i++) { var coordinates = clickedTroopOrder.VillagesCoordinates[i]; try { currentOrderNumber++; _plemionaFeaturesDiagnostics.SendTroops(clickedTroopOrder.TroopsTemplate.Troops, coordinates.X, coordinates.Y, TroopsIntentions.Attack, SendingTroopsInfo.Create(currentOrderNumber, fixedOrderCount)); } catch (BotCheckException) { MessageBox.Show("Bot check detected, order stopped.", "Bot check", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } catch (FeatureException fe) { MessageBox.Show($"{coordinates.X}|{coordinates.Y}\n" + fe.PlemionaErrorMessage, $"{(fe.PlemionaError ? "Plemiona" : "Unexpected")} Error", MessageBoxButtons.OK, fe.PlemionaError ? MessageBoxIcon.Warning : MessageBoxIcon.Error); fixedOrderCount -= currentOrderNumber; currentOrderNumber = 0; } } }); SetReady(true); } } }
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); } }