예제 #1
0
        /// <summary>
        /// Többfalvas játéknál, kiválaszt egy falut
        /// </summary>
        /// <param name="village"></param>
        private void ChangeToVillage(VillageData village)
        {
            //string act = xpath.SelectElement(web.Document, "id('lmid2')/div[1]/h1").InnerText;

            //if (village.Props.Name != act)
            if (village.Props.url == null)
            {
                Navigate("dorf1.php");
            }
            else
            {
                Navigate(village.Props.url);
            }

            ActiveVillage = village.Props.Id;
        }
예제 #2
0
        private void RefreshBindings(int VillageId)
        {
            VillageData village = null;

            if (TraviBase.Data.Villages.TryGetValue(VillageId, out village))
            {
                bsResources.DataSource    = village.Resources.Values;
                bsProductions.DataSource  = village.Productions.Values;
                bsBuildings.DataSource    = village.Buildings.Values;
                bsConstruction.DataSource = village.Constructing;
                bsCanBuild.DataSource     = village.CanBuild;
            }
            bsResourceOverall.DataSource = null;
            bsResourceOverall.DataSource = TraviBase.Data.Overalls.ResourceOverall.Values;
            //bsResourceOverall.ResetBindings(false);
            bsConstruction.ResetBindings(false);
            bsBuildings.ResetBindings(false);
            bsResources.ResetBindings(false);
            bsResourceOverall.ResetBindings(false);
            bsCanBuild.ResetBindings(false);
        }
예제 #3
0
        private void UpgradeBuilding(List<Building> buildings, VillageData village)
        {
            bool done = false;

            Globals.Logger.Log("Upgrade... ", LogType.ltDebug);

            foreach (Building building in buildings)
                ParseConstruction(building, false);
            /*
            //épületek árai
            var costs =
                from b in buildings
                where b.Level < b.Target
                   && b.NextLevelCost < village.Stock
                   && (b.Level > 0 || b.BuildId < 19)
                //select BuildingCosts[b.Type][b.Level + 1].Sum;
                select b.NextLevelCost.Sum;

            if (costs.Count() != 0)
            {
                //legoccsóbb
                int minCost = costs.Min();

                Globals.Logger.Log("Cheapest: " + minCost, LogType.ltDebug);

                //ezeket vannak egy árban a legolcsóbbal (10% türés)
                var Buildables =
                    from b in buildings
                    where (b.NextLevelCost.Sum - minCost) < (minCost / 20)
                        //where (BuildingCosts[b.Type][b.Level+1].Sum - minCost) <(minCost / 10)
                        && b.Level < b.Target
                        && b.NextLevelCost < village.Stock
                    select b;

                foreach (Building b in Buildables)
                {
                    Globals.Logger.Log( b.Name + '@' + b.Id + ' ' + b.NextLevelCost, LogType.ltDebug);
                }
            */
                //nyersanyagok közül választani kell
                //ebben a sorrendben kéne építeni
                var prodOrd =
                    from p in village.Productions.Values
                    orderby p.ActPercent - p.TargetPercent
                    select p;

                foreach (Production prod in prodOrd)
                    Globals.Logger.Log(prod.TypeName + ' ' + prod.Producing + ' ' + prod.TargetPercent + ' ' + prod.ActPercent, LogType.ltDebug);

                //végigskera, hogy van-e az olcsók között ijen
                foreach (Production prod in prodOrd)
                {
                    /*
                    var nowBuild =
                        from b in Buildables
                        where b.Producing == prod.Type
                        select b;
                     */

                    var nowBuild =
                        from b in buildings
                        where b.Producing == prod.Type
                        && b.Level < b.Target
                        && b.NextLevelCost < village.Stock
                        && b.BuildId < 19
                        orderby b.NextLevelCost.Sum
                        select b;

                    if (nowBuild.Count() > 0)
                    {
                        if (!done)
                        {
                            BuildIt(nowBuild.First());
                            done = true;
                        }
                    }
                }

                //ha nyersanyagot nem kellet akkor hátha épületet
                if (!done)
                {
                    var Buildables =
                        from b in buildings
                        where b.BuildId > 18
                        && b.Level > 0
                        && b.Level < b.Target
                        && b.NextLevelCost < village.Stock
                        orderby b.NextLevelCost.Sum
                        select b;

                    if (Buildables.Count() > 0)
                    {
                        BuildIt(Buildables.First());
                        done = true;
                    }
                }
            //}
        }
예제 #4
0
        private bool NewBuilding(VillageData village)
        {
            Globals.Logger.Log("NewBuilding...", LogType.ltDebug);

            var news = from b in village.Buildings.Values
                       where b.Type != BuildingType.None
                          && b.Level == 0
                          && b.Target > 0
                       select b;

            foreach (Building b in news.ToList())
            {
                Globals.Logger.Log("try: " + b.Name + '@' + b.Id, LogType.ltDebug);
                Navigate("build.php?id=" + b.BuildId);

                Regex rex1 = new Regex(@"dorf[1-2]\.php\?a=\d+&id=\d+&c=(.{3})");
                MatchCollection matches1 = rex1.Matches(Globals.Web.Document.GetElementById("lmid2").InnerHtml.Replace("&amp;", "&"));

                Regex rex2 = new Regex(@"\d+ \| \d+ \| \d+ \| \d+ \| \d+ \|  \d+\:\d+\:\d+");
                MatchCollection matches2 = rex2.Matches(Globals.Web.Document.GetElementById("lmid2").InnerText);

                if (matches1.Count == matches2.Count)
                {
                    for (int i = 0; i < matches1.Count; i++)
                    {
                        int id = int.Parse(matches1[i].Value.Split('?')[1].Split('&')[0].Split('=')[1]);

                        if (id == ((int)b.Type) + 1)
                        {
                            string[] sa = matches2[i].Value.Split('|');
                            sa = sa[5].Split(':');
                            b.BuildTime =
                                TimeSpan.FromHours(int.Parse(sa[0])) +
                                TimeSpan.FromMinutes(int.Parse(sa[1])) +
                                TimeSpan.FromSeconds(int.Parse(sa[2]));

                            Globals.Logger.Log("NewBuild: " + b.Name, LogType.ltReport);
                            Globals.Logger.Log("Href: " + matches1[i].Value, LogType.ltDebug);
                            Navigate(matches1[i].Value);
                            b.Level++;
                            b.BuildHref = "";
                            b.NextLevelCost.Clear();
                            AddToConstructionList(b);
                            return true;
                        }

                    }
                }
                else
                {
                    Regex rex = new Regex(@"dorf[1-2]\.php\?a=" + ((int)b.Type + 1).ToString() + "&id=" + b.BuildId + "&c=(.{3})");
                    MatchCollection matches = rex.Matches(Globals.Web.Document.GetElementById("lmid2").InnerHtml.Replace("&amp;", "&"));
                    if (matches.Count > 0)
                    {
                        Globals.Logger.Log("NewBuild: " + b.Name, LogType.ltReport);
                        Globals.Logger.Log("Href: " + matches[0].Value, LogType.ltDebug);
                        Navigate(matches[0].Value);
                        b.Level++;
                        b.BuildHref = "";
                        b.NextLevelCost.Clear();
                        AddToConstructionList(b);
                        return true;
                    }
                }
            }
            return false;
        }
예제 #5
0
        private bool NewBuilding(VillageData village)
        {
            Globals.Logger.Log("NewBuilding...", LogType.ltDebug);

            var news = from b in village.Buildings.Values
                       where b.Type != BuildingType.None &&
                       b.Level == 0 &&
                       b.Target > 0
                       select b;

            foreach (Building b in news.ToList())
            {
                Globals.Logger.Log("try: " + b.Name + '@' + b.Id, LogType.ltDebug);
                Navigate("build.php?id=" + b.BuildId);

                Regex           rex1     = new Regex(@"dorf[1-2]\.php\?a=\d+&id=\d+&c=(.{3})");
                MatchCollection matches1 = rex1.Matches(Globals.Web.Document.GetElementById("lmid2").InnerHtml.Replace("&amp;", "&"));

                Regex           rex2     = new Regex(@"\d+ \| \d+ \| \d+ \| \d+ \| \d+ \|  \d+\:\d+\:\d+");
                MatchCollection matches2 = rex2.Matches(Globals.Web.Document.GetElementById("lmid2").InnerText);

                if (matches1.Count == matches2.Count)
                {
                    for (int i = 0; i < matches1.Count; i++)
                    {
                        int id = int.Parse(matches1[i].Value.Split('?')[1].Split('&')[0].Split('=')[1]);

                        if (id == ((int)b.Type) + 1)
                        {
                            string[] sa = matches2[i].Value.Split('|');
                            sa          = sa[5].Split(':');
                            b.BuildTime =
                                TimeSpan.FromHours(int.Parse(sa[0])) +
                                TimeSpan.FromMinutes(int.Parse(sa[1])) +
                                TimeSpan.FromSeconds(int.Parse(sa[2]));

                            Globals.Logger.Log("NewBuild: " + b.Name, LogType.ltReport);
                            Globals.Logger.Log("Href: " + matches1[i].Value, LogType.ltDebug);
                            Navigate(matches1[i].Value);
                            b.Level++;
                            b.BuildHref = "";
                            b.NextLevelCost.Clear();
                            AddToConstructionList(b);
                            return(true);
                        }
                    }
                }
                else
                {
                    Regex           rex     = new Regex(@"dorf[1-2]\.php\?a=" + ((int)b.Type + 1).ToString() + "&id=" + b.BuildId + "&c=(.{3})");
                    MatchCollection matches = rex.Matches(Globals.Web.Document.GetElementById("lmid2").InnerHtml.Replace("&amp;", "&"));
                    if (matches.Count > 0)
                    {
                        Globals.Logger.Log("NewBuild: " + b.Name, LogType.ltReport);
                        Globals.Logger.Log("Href: " + matches[0].Value, LogType.ltDebug);
                        Navigate(matches[0].Value);
                        b.Level++;
                        b.BuildHref = "";
                        b.NextLevelCost.Clear();
                        AddToConstructionList(b);
                        return(true);
                    }
                }
            }
            return(false);
        }
예제 #6
0
        private void UpgradeBuilding(List <Building> buildings, VillageData village)
        {
            bool done = false;

            Globals.Logger.Log("Upgrade... ", LogType.ltDebug);

            foreach (Building building in buildings)
            {
                ParseConstruction(building, false);
            }

            /*
             * //épületek árai
             * var costs =
             *  from b in buildings
             *  where b.Level < b.Target
             *     && b.NextLevelCost < village.Stock
             *     && (b.Level > 0 || b.BuildId < 19)
             *  //select BuildingCosts[b.Type][b.Level + 1].Sum;
             *  select b.NextLevelCost.Sum;
             *
             * if (costs.Count() != 0)
             * {
             *  //legoccsóbb
             *  int minCost = costs.Min();
             *
             *  Globals.Logger.Log("Cheapest: " + minCost, LogType.ltDebug);
             *
             *  //ezeket vannak egy árban a legolcsóbbal (10% türés)
             *  var Buildables =
             *      from b in buildings
             *      where (b.NextLevelCost.Sum - minCost) < (minCost / 20)
             *          //where (BuildingCosts[b.Type][b.Level+1].Sum - minCost) <(minCost / 10)
             *          && b.Level < b.Target
             *          && b.NextLevelCost < village.Stock
             *      select b;
             *
             *  foreach (Building b in Buildables)
             *  {
             *      Globals.Logger.Log( b.Name + '@' + b.Id + ' ' + b.NextLevelCost, LogType.ltDebug);
             *  }
             */
            //nyersanyagok közül választani kell
            //ebben a sorrendben kéne építeni
            var prodOrd =
                from p in village.Productions.Values
                orderby p.ActPercent - p.TargetPercent
                select p;

            foreach (Production prod in prodOrd)
            {
                Globals.Logger.Log(prod.TypeName + ' ' + prod.Producing + ' ' + prod.TargetPercent + ' ' + prod.ActPercent, LogType.ltDebug);
            }


            //végigskera, hogy van-e az olcsók között ijen
            foreach (Production prod in prodOrd)
            {
                /*
                 * var nowBuild =
                 *  from b in Buildables
                 *  where b.Producing == prod.Type
                 *  select b;
                 */

                var nowBuild =
                    from b in buildings
                    where b.Producing == prod.Type &&
                    b.Level < b.Target &&
                    b.NextLevelCost < village.Stock &&
                    b.BuildId < 19
                    orderby b.NextLevelCost.Sum
                    select b;

                if (nowBuild.Count() > 0)
                {
                    if (!done)
                    {
                        BuildIt(nowBuild.First());
                        done = true;
                    }
                }
            }

            //ha nyersanyagot nem kellet akkor hátha épületet
            if (!done)
            {
                var Buildables =
                    from b in buildings
                    where b.BuildId > 18 &&
                    b.Level > 0 &&
                    b.Level < b.Target &&
                    b.NextLevelCost < village.Stock
                    orderby b.NextLevelCost.Sum
                    select b;

                if (Buildables.Count() > 0)
                {
                    BuildIt(Buildables.First());
                    done = true;
                }
            }
            //}
        }
예제 #7
0
        /// <summary>
        /// Többfalvas játéknál, kiválaszt egy falut
        /// </summary>
        /// <param name="village"></param>
        private void ChangeToVillage(VillageData village)
        {
            //string act = xpath.SelectElement(web.Document, "id('lmid2')/div[1]/h1").InnerText;

            //if (village.Props.Name != act)
            if (village.Props.url == null)
                Navigate("dorf1.php");
            else
                Navigate(village.Props.url);

            ActiveVillage = village.Props.Id;
        }