Ejemplo n.º 1
0
 private void GetUnitInfo(IElementContainer table,
     TableInfo tableInfo,
     bool isAttacker)
 {
     TableBody tableBodyUnits = table.TableBody(Find.ByClass("units"));
     const int total = 11;
     int[] troops = new int[total];
     int[] casualties = new int[total];
     int[] prisoners = new int[total];
     if (tableBodyUnits.Exists)
     {
         if (tableBodyUnits.TableRows.Count == 2)
         {
             GetTribe(true, table, tableInfo, 0);
         }
         else
         {
             GetTribe(true, table, tableInfo, 1);
         }
         foreach (TableRow tableRow in tableBodyUnits.TableRows)
         {
             string header = tableRow.Text;
             if (!(header.Length > 1))
             {
                 continue;
             }
             if (isAttacker)
             {
                 if (header.StartsWith(gameData.Settings.Reports.RowAttackerTroops))
                 {
                     troops = GetTroops(tableRow);
                 }
                 if (header.StartsWith(gameData.Settings.Reports.RowAttackerPrisoners))
                 {
                     prisoners = GetTroops(tableRow);
                 }
                 if (header.StartsWith(gameData.Settings.Reports.RowAttackerCasualties))
                 {
                     casualties = GetTroops(tableRow);
                 }
             }
             else
             {
                 if (header.StartsWith(gameData.Settings.Reports.RowDefenderTroops))
                 {
                     troops = GetTroops(tableRow);
                 }
                 if (header.StartsWith(gameData.Settings.Reports.RowDefenderCasualties))
                 {
                     casualties = GetTroops(tableRow);
                 }
             }
         }
         tableInfo.Troops = troops;
         tableInfo.Casualties = casualties;
         tableInfo.Prisoners = prisoners;
     }
 }
Ejemplo n.º 2
0
 private TableInfo GetInfo(IElementContainer table,
     bool isAttacker)
 {
     TableCell tableCell = table.TableRows[0].TableCells[1];
     TableInfo tableInfo = new TableInfo();
     if (tableCell.Links.Count == 2)
     {
         GetReportOwner(tableCell, tableInfo);
         GetUnitInfo(table, tableInfo, isAttacker);
         GetBounty(table, tableInfo);
     }
     else
     {
         tableInfo.Reinforcements = true;
         GetEmptyNames(tableInfo);
         GetTribe(false, table, tableInfo, 1);
         GetUnitInfo(table, tableInfo, isAttacker);
     }
     return tableInfo;
 }
Ejemplo n.º 3
0
 private static void GetTribe(bool ownTribe,
     IElementContainer table,
     TableInfo tableInfo,
     int index)
 {
     Image image = table.TableRows[1].TableCells[index].Images[0];
     if (image.Exists)
     {
         string className = image.ClassName;
         Tribes tribe;
         if (className.ToLowerInvariant().Equals("unit u1"))
         {
             tribe = Tribes.Romans;
         }
         else if (className.ToLowerInvariant().Equals("unit u11"))
         {
             tribe = Tribes.Teutons;
         }
         else if (className.ToLowerInvariant().Equals("unit u21"))
         {
             tribe = Tribes.Gauls;
         }
         else if (className.ToLowerInvariant().Equals("unit u31"))
         {
             tribe = Tribes.Nature;
         }
         else
         {
             tribe = Tribes.Monsters;
         }
         if (ownTribe)
         {
             tableInfo.OwnTribe = tribe;
         }
         else
         {
             tableInfo.Tribe = tribe;
         }
     }
 }
Ejemplo n.º 4
0
 private static void GetReportOwner(IElementContainer tableCell,
     TableInfo tableInfo)
 {
     if (tableCell.Links.Count == 0)
     {
         GetEmptyNames(tableInfo);
         return;
     }
     tableInfo.Name = tableCell.Links[0].Text;
     string defenderIdLink = tableCell.Links[0].Url;
     Regex regDefenderId = new Regex(@"spieler.php.uid=([0-9]{0,9})");
     if (regDefenderId.IsMatch(defenderIdLink))
     {
         Match mc = regDefenderId.Matches(defenderIdLink)[0];
         tableInfo.Id = Misc.String2Number(mc.Groups[1].Value.Trim());
     }
     tableInfo.VillageName = tableCell.Links[1].Text;
     string defenderVillageIdLink = tableCell.Links[1].Url;
     Regex regDefenderVillageId = new Regex(@"karte.php.d=([0-9]{0,9})&c=");
     if (regDefenderVillageId.IsMatch(defenderVillageIdLink))
     {
         Match mc = regDefenderVillageId.Matches(defenderVillageIdLink)[0];
         tableInfo.VillageId = Misc.String2Number(mc.Groups[1].Value.Trim());
     }
 }
Ejemplo n.º 5
0
 private static void GetEmptyNames(TableInfo tableInfo)
 {
     const string empty = "???";
     tableInfo.Name = empty;
     tableInfo.VillageName = empty;
     tableInfo.Id = 0;
     tableInfo.VillageId = 0;
 }
Ejemplo n.º 6
0
 private static void GetBounty(IElementContainer table,
     TableInfo tableInfo)
 {
     TableBody tableBodyGoods = table.TableBody(Find.ByClass("goods"));
     int[] goods = new int[4];
     tableInfo.Carry = "0/0";
     if (tableBodyGoods.Exists)
     {
         string[] resources = tableBodyGoods.TableRows[0].TableCells[0].Divs[0].Text.Split('|');
         for (int i = 0; i < 4; i++)
         {
             goods[i] = Misc.String2Number(resources[i].Trim());
         }
         Div div = tableBodyGoods.TableRows[0].TableCells[0].Divs[1];
         tableInfo.Carry = div.Exists ? div.Text : "0/0";
     }
     tableInfo.Goods = goods;
 }