예제 #1
0
        private void Scout(int playerVillageID)
        {
            //int honourRange = CardTypes.adjustScoutingHonourRange(GameEngine.Instance.World.UserCardData, GameEngine.Instance.LocalWorldData.BaseScoutHonourRange);
            while (true)
            {
                if (!scout)
                {
                    Thread.Sleep(500);
                    continue;
                }

                try
                {
                    bool ok    = false;
                    int  index = 0;
                    foreach (string str in listBox_scoutFrom.Items) // Разведывать ли из этой деревни
                    {
                        int id = GetID(str);
                        if (id == playerVillageID)
                        {
                            if (listBox_scoutFrom.GetSelected(index))
                            {
                                ok = true;
                                break;
                            }
                        }
                        index++;
                    }
                    if (!ok)
                    {
                        Thread.Sleep(1000); // Нечего лаги пилить если вообще ничего не делаем
                        continue;
                    }

                    if (GameEngine.Instance.getVillage(playerVillageID) == null) // Если деревня игрока не прогружена - пропускаем
                    {
                        Thread.Sleep(3000);                                      // Чтобы не лагать, деревня то вовсе не загружена
                        continue;
                    }

                    // TODO: возможно при отправке не всех сразу инфу надо будет обновлять
                    // чтобы оно не думало что скауты еще есть в наличии
                    VillageMap map = GameEngine.Instance.getVillage(playerVillageID);
                    if (map.calcTotalScoutsAtHome() == 0)
                    {
                        Thread.Sleep(500); // Чтобы не лагать, лучше переждать лишнего
                        continue;
                    }

                    double minRange    = double.MaxValue;
                    bool   isUnscouted = false;
                    int    target      = -1;

                    bool isContinue = false;
                    for (int i = 0; i < GameEngine.Instance.World.villageList.Length; i++) // Перебираем тайники
                    {
                        int id = GameEngine.Instance.World.villageList[i].id;
                        if (!GameEngine.Instance.World.isSpecial(id)) // Если это не тайник - пропускаем
                        {
                            continue;
                        }

                        int type = GameEngine.Instance.World.getSpecial(id); // 100 - unscouted
                        //if ((type >= 100) && (type <= 0xc7))
                        if (!DataExport.IsStash(type))                       // Если не тайник с ресурсами - пропускаем
                        {
                            continue;
                        }

                        if (checkBox_Honourable.Checked && type == 100) // Если только не разведанные
                        {
                            if (!GameEngine.Instance.World.isScoutHonourOutOfRange(playerVillageID, id))
                            {
                                continue;
                            }
                        }

                        index = 0;
                        foreach (string str in listBox_resForScouting.Items) // Выбран ли тип ресурса для разведки
                        {
                            int typeID = GetID(str);
                            if (typeID == type)
                            {
                                if (!listBox_resForScouting.GetSelected(index))
                                {
                                    isContinue = true;
                                }
                                break;
                            }
                            index++;
                        }
                        if (isContinue) // Если этот тайник не выбран - пропускаем
                        {
                            isContinue = false;
                            continue;
                        }

                        // Считаем расстояние до тайника
                        Point  playerVillage = GameEngine.Instance.World.getVillageLocation(playerVillageID);
                        Point  targetStash   = GameEngine.Instance.World.getVillageLocation(id);
                        int    x             = playerVillage.X;
                        int    num7          = playerVillage.Y;
                        int    num8          = targetStash.X;
                        int    num9          = targetStash.Y;
                        double d             = ((x - num8) * (x - num8)) + ((num7 - num9) * (num7 - num9)); // Квадрат расстояния
                        d = Math.Sqrt(d);
                        if (d > int.Parse(textBox_maxRadius.Text))                                          // Дальше чем положено нас не касается
                        {
                            continue;
                        }

                        if (type == 100) // не открытые тайники в приоритете
                        {
                            isUnscouted = true;
                        }
                        else if (isUnscouted) // Если это разведанный тайник, но уже был найден не разведанный
                        {
                            continue;
                        }
                        if (d < minRange) // && ((type == 100 && isUnscouted) || !isUnscouted))
                        {
                            minRange = d;
                            target   = id;
                        }

                        //RemoteServices.Instance.set_SendScouts_UserCallBack(new RemoteServices.SendScouts_UserCallBack(this.sendScoutsCallback));
                        //d = Math.Sqrt(d) * ((GameEngine.Instance.LocalWorldData.ScoutsMoveSpeed * GameEngine.Instance.LocalWorldData.gamePlaySpeed) * ResearchData.ScoutTimes[GameEngine.Instance.World.UserResearchData.Research_Horsemanship]);
                        //d *= CardTypes.getScoutSpeed(GameEngine.Instance.World.UserCardData);
                        //string str = VillageMap.createBuildTimeString((int)d); // Time

                        //Console.WriteLine("WUT: " + id);
                        //Console.WriteLine("     | " + GameEngine.Instance.World.getVillageNameOrType(id));
                        //InterfaceMgr.Instance.SelectedVillage = id;
                        //GameEngine.Instance.World.setZooming(1, GameEngine.Instance.World.getVillageData(id).x, GameEngine.Instance.World.getVillageData(id).y);
                        //count++;
                    }

                    if (target == -1)
                    {
                        Thread.Sleep(1500); // Точек найдено не было
                        continue;
                    }

                    int numScouts = int.Parse(textBox_scoutsPerStash.Text);
                    if (numScouts == 0 || numScouts > map.calcTotalScoutsAtHome())
                    {
                        numScouts = map.calcTotalScoutsAtHome();
                    }

                    if (numScouts == 0) // вроде как непостижимый код
                    {
                        Thread.Sleep(500);
                        continue; // TODO: wait till != 0
                    }

                    RemoteServices.Instance.SendScouts(playerVillageID, target, numScouts);
                    AllVillagesPanel.travellersChanged();

                    Thread.Sleep(1500);
                }
                catch (Exception ex)
                {
                    Log(ex.ToString());
                }

                Thread.Sleep(1000);
            }

            //GameEngine.Instance.World.isScoutHonourOutOfRange(InterfaceMgr.Instance.OwnSelectedVillage, id);
            //InterfaceMgr.Instance.selectUserVillage(id)
            //InterfaceMgr.Instance.selectVillage(id)
            //int villageID = InterfaceMgr.Instance.getSelectedMenuVillage();
            //GameEngine.Instance.World.getNextUserVillage();
            //GameEngine.Instance.downloadCurrentVillage();
        }
        public void init(MyFormBase parent, int troopType, bool isTroops, object back)
        {
            base.clearControls();
            this.imgBackground.Image = (Image)back;
            this.m_isTroops          = isTroops;
            this.m_parent            = parent;
            base.Size                   = this.m_parent.Size;
            this.BackColor              = ARGBColors.Transparent;
            this.imgBackground.Size     = base.Size;
            this.imgBackground.Position = new Point(0, 0);
            this.imgBackground.Visible  = true;
            base.addControl(this.imgBackground);
            VillageMap village = GameEngine.Instance.Village;

            this.m_troopType = troopType;
            int numPeasants = 0;

            this.lblTroopType.Text            = "";
            this.lblTroopType.Color           = ARGBColors.White;
            this.lblTroopType.DropShadowColor = ARGBColors.Black;
            this.lblTroopType.Position        = new Point(0, 10);
            this.lblTroopType.Size            = new Size(base.Width, 0x18);
            this.lblTroopType.Alignment       = CustomSelfDrawPanel.CSD_Text_Alignment.TOP_CENTER;
            this.lblTroopType.Font            = FontManager.GetFont("Arial", 10f, FontStyle.Regular);
            this.lblMax.Text = "";
            if (village != null)
            {
                switch (troopType)
                {
                case 1:
                    this.lblTroopType.Text = SK.Text("GENERIC_Monks", "Monks");
                    numPeasants            = village.calcTotalMonksAtHome();
                    break;

                case 2:
                    this.lblTroopType.Text = SK.Text("GENERIC_Merchants", "Merchants");
                    numPeasants            = village.calcTotalTradersAtHome();
                    break;

                case 3:
                    this.lblTroopType.Text = SK.Text("GENERIC_Spiese", "Spies");
                    numPeasants            = 0;
                    break;

                case 4:
                    this.lblTroopType.Text = SK.Text("GENERIC_Scouts", "Scouts");
                    numPeasants            = village.calcTotalScoutsAtHome();
                    break;

                case 70:
                    this.lblTroopType.Text = SK.Text("GENERIC_Peasants", "Peasants");
                    numPeasants            = village.m_numPeasants;
                    break;

                case 0x47:
                    this.lblTroopType.Text = SK.Text("GENERIC_Swordsmen", "Swordsmen");
                    numPeasants            = village.m_numSwordsmen;
                    break;

                case 0x48:
                    this.lblTroopType.Text = SK.Text("GENERIC_Archers", "Archers");
                    numPeasants            = village.m_numArchers;
                    break;

                case 0x49:
                    this.lblTroopType.Text = SK.Text("GENERIC_Pikemen", "Pikemen");
                    numPeasants            = village.m_numPikemen;
                    break;

                case 0x4a:
                    this.lblTroopType.Text = SK.Text("GENERIC_Catapults", "Catapults");
                    numPeasants            = village.m_numCatapults;
                    break;

                case 100:
                    this.lblTroopType.Text = SK.Text("GENERIC_Captains", "Captains");
                    numPeasants            = village.m_numCaptains;
                    break;
                }
                this.lblMax.Text = numPeasants.ToString();
            }
            this.tbTroopsDisband.Position  = new Point((base.Width / 2) - (GFXLibrary.int_slidebar_ruler.Width / 2), 40);
            this.tbTroopsDisband.Size      = new Size(base.Width - 50, 0x17);
            this.tbTroopsDisband.StepValue = 1;
            this.tbTroopsDisband.Value     = 0;
            this.tbTroopsDisband.Max       = numPeasants;
            this.tbTroopsDisband.setValueChangeDelegate(new CustomSelfDrawPanel.CSDControl.CSD_ValueChangedDelegate(this.trackMoved));
            this.tbTroopsDisband.Create((Image)GFXLibrary.int_slidebar_ruler, (Image)GFXLibrary.reinforce_slider, (Image)GFXLibrary.reinforce_slider, (Image)GFXLibrary.reinforce_slider, (Image)GFXLibrary.reinforce_slider, (Image)GFXLibrary.reinforce_slider);
            this.lblMin.Text                 = "0";
            this.lblMin.Color                = ARGBColors.White;
            this.lblMin.DropShadowColor      = ARGBColors.Black;
            this.lblMin.Position             = new Point(0, this.tbTroopsDisband.Position.Y);
            this.lblMin.Size                 = new Size(this.tbTroopsDisband.Position.X - 10, this.tbTroopsDisband.Height);
            this.lblMin.Alignment            = CustomSelfDrawPanel.CSD_Text_Alignment.TOP_RIGHT;
            this.lblMin.Font                 = FontManager.GetFont("Arial", 10f, FontStyle.Regular);
            this.lblMax.Color                = ARGBColors.White;
            this.lblMax.DropShadowColor      = ARGBColors.Black;
            this.lblMax.Position             = new Point(this.tbTroopsDisband.Rectangle.Right + 5, this.tbTroopsDisband.Position.Y);
            this.lblMax.Size                 = new Size((base.Width - this.tbTroopsDisband.Rectangle.Right) - 10, this.tbTroopsDisband.Height);
            this.lblMax.Alignment            = CustomSelfDrawPanel.CSD_Text_Alignment.TOP_LEFT;
            this.lblMax.Font                 = FontManager.GetFont("Arial", 10f, FontStyle.Regular);
            this.lblCurValue.Text            = SK.Text("GENERIC_Disband", "Disband");
            this.lblCurValue.Text            = this.lblCurValue.Text + ": 0";
            this.lblCurValue.Color           = ARGBColors.White;
            this.lblCurValue.DropShadowColor = ARGBColors.Black;
            this.lblCurValue.Position        = new Point(this.tbTroopsDisband.Position.X, this.tbTroopsDisband.Rectangle.Bottom + 10);
            this.lblCurValue.Size            = new Size(base.Width, 0x1a);
            this.lblCurValue.Alignment       = CustomSelfDrawPanel.CSD_Text_Alignment.TOP_LEFT;
            this.lblCurValue.Font            = FontManager.GetFont("Arial", 12f, FontStyle.Regular);
            this.btnDisband.Text.Text        = SK.Text("GENERIC_Disband", "Disband");
            this.btnDisband.ImageNorm        = (Image)GFXLibrary.button_132_normal;
            this.btnDisband.ImageOver        = (Image)GFXLibrary.button_132_over;
            this.btnDisband.ImageClick       = (Image)GFXLibrary.button_132_in;
            this.btnDisband.setSizeToImage();
            this.btnDisband.Position    = new Point((base.Width / 2) - (this.btnDisband.Width / 2), this.lblCurValue.Rectangle.Bottom + 10);
            this.btnDisband.Text.Font   = FontManager.GetFont("Arial", 9f, FontStyle.Regular);
            this.btnDisband.TextYOffset = -2;
            this.btnDisband.Text.Color  = ARGBColors.Black;
            this.btnDisband.setClickDelegate(new CustomSelfDrawPanel.CSDControl.CSD_ClickDelegate(this.disbandClick), "Disband_Disband");
            this.btnDisband.Enabled = true;
            this.btnEdit.ImageNorm  = (Image)GFXLibrary.faction_pen;
            this.btnEdit.ImageOver  = (Image)GFXLibrary.faction_pen;
            this.btnEdit.ImageClick = (Image)GFXLibrary.faction_pen;
            this.btnEdit.setSizeToImage();
            this.btnEdit.MoveOnClick  = true;
            this.btnEdit.OverBrighten = true;
            this.btnEdit.Position     = new Point(this.tbTroopsDisband.Rectangle.Right - this.btnEdit.Width, this.lblCurValue.Position.Y);
            this.btnEdit.Data         = 1;
            this.btnEdit.setClickDelegate(new CustomSelfDrawPanel.CSDControl.CSD_ClickDelegate(this.editValue), "Disband_EditValue");
            if (this.imgBackground.Image != null)
            {
                this.imgBackground.addControl(this.btnEdit);
                this.imgBackground.addControl(this.btnDisband);
                this.imgBackground.addControl(this.lblCurValue);
                this.imgBackground.addControl(this.lblMax);
                this.imgBackground.addControl(this.lblMin);
                this.imgBackground.addControl(this.tbTroopsDisband);
                this.imgBackground.addControl(this.lblTroopType);
            }
            else
            {
                base.addControl(this.btnEdit);
                base.addControl(this.btnDisband);
                base.addControl(this.lblCurValue);
                base.addControl(this.lblMax);
                base.addControl(this.lblMin);
                base.addControl(this.tbTroopsDisband);
                base.addControl(this.lblTroopType);
            }
        }