Ejemplo n.º 1
0
        public void Snapshot(Travian tr)
        {
            var    fn       = Filename(tr.TD.Server);
            string jsondata = JsonMapper.ToJson(tr);

            File.WriteAllText(fn, jsondata);
            tr.Dirty = false;
        }
Ejemplo n.º 2
0
 public void GetBuildingLevelUS()
 {
     Travian target = new Travian();
     int gid = 5;
     string pageContent = "<h1>Main Building <span class=\"level\">level 3</span></h1>";
     target.SetGidLang(gid, "Main Building");
     Assert.AreEqual(3, target.GetBuildingLevel(gid, pageContent));
 }
Ejemplo n.º 3
0
        public void GetBuildingLevelCN()
        {
            Travian target = new Travian();
            int gid = 17;
            string pageContent = "<h1>市场 <span class=\"level\">等级 20</span></h1>";
            target.SetGidLang(gid, "市场");
            Assert.AreEqual(20, target.GetBuildingLevel(gid, pageContent));

            target.SetGidLang(gid, "XX");
            Assert.AreEqual(-1, target.GetBuildingLevel(gid, pageContent));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Another test for NewParseTroops
        ///</summary>
        //[TestMethod()]
        public void NewParseTroopsCrazy()
        {
            Travian target = new Travian();
            target.TD = new Data();

            int villageId = 1;
            TVillage village = new TVillage();
            target.TD.Villages[villageId] = village;

            TTroop troops = new TTroop();
            village.Troop = troops;

            target.SetGidLang(16, "Rally Point");
            target.NewParseTroops(villageId, Properties.Resources.RallyPointCrazy);
            Assert.AreEqual(15, troops.Troops.Count);

            TTInfo troop = troops.Troops[0];
            Assert.AreEqual(2, troop.Tribe);
            Assert.AreEqual("Crazy", troop.Owner);
            Assert.AreEqual("Return from Jeffo Village", troop.VillageName);
            Assert.AreEqual(1, troop.Troops[3]);
            Assert.IsTrue(troop.FinishTime > DateTime.Now.AddMinutes(6));
            Assert.IsTrue(troop.FinishTime < DateTime.Now.AddMinutes(8));
            Assert.AreEqual(TTroopType.Incoming, troop.TroopType);

            troop = troops.Troops[1];
            Assert.AreEqual(2, troop.Tribe);
            Assert.AreEqual("Crazy", troop.Owner);
            Assert.AreEqual("Return from laraelaine40 Village", troop.VillageName);
            Assert.AreEqual(4, troop.Troops[0]);
            Assert.IsTrue(troop.FinishTime > DateTime.Now.AddMinutes(10));
            Assert.IsTrue(troop.FinishTime < DateTime.Now.AddMinutes(15));
            Assert.AreEqual(TTroopType.Incoming, troop.TroopType);

            troop = troops.Troops[7];
            Assert.AreEqual(2, troop.Tribe);
            Assert.AreEqual("Crazy", troop.Owner);
            Assert.AreEqual("Own troops", troop.VillageName);
            Assert.AreEqual(4, troop.Troops[0]);
            Assert.AreEqual(1, troop.Troops[10]);
            Assert.AreEqual(TTroopType.InVillage, troop.TroopType);

            troop = troops.Troops[8];
            Assert.AreEqual(TTroopType.Outgoing, troop.TroopType);
            Assert.AreEqual(2, troop.Tribe);
            Assert.AreEqual("Crazy", troop.Owner);
            Assert.AreEqual("Raid on hotmamapam Village", troop.VillageName);
            Assert.AreEqual(4, troop.Troops[0]);
        }
Ejemplo n.º 5
0
 public void Snapshot(Travian tr)
 {
     var fn = Filename(tr.TD.Server);
     string jsondata = JsonMapper.ToJson(tr);
     File.WriteAllText(fn, jsondata);
     tr.Dirty = false;
 }
Ejemplo n.º 6
0
 public TransferSetting(Travian UpCall)
 {
     InitializeComponent();
     this.UpCall = UpCall;
 }
Ejemplo n.º 7
0
        /// <summary>
        /// A test for NewParseTroops
        ///</summary>
        //[TestMethod()]
        public void NewParseTroopsTiny()
        {
            Travian target = new Travian();
            target.TD = new Data();

            int villageId = 1;
            TVillage village = new TVillage();
            target.TD.Villages[villageId] = village;

            TTroop troops = new TTroop();
            village.Troop = troops;

            target.SetGidLang(16, "Rally Point");
            target.NewParseTroops(villageId, Properties.Resources.RallyPointTiny);
            Assert.AreEqual(3, troops.Troops.Count);

            TTInfo troop = troops.Troops[0];
            Assert.AreEqual("Tiny", troop.Owner);
            Assert.AreEqual(270225, troop.OwnerVillageZ);
            Assert.AreEqual("Own troops", troop.VillageName);
            Assert.AreEqual(8, troop.Troops[0]);
            Assert.AreEqual(TTroopType.InVillage, troop.TroopType);
            Assert.AreEqual(DateTime.MinValue, troop.FinishTime);
            Assert.AreEqual(3, troop.Tribe);

            troop = troops.Troops[1];
            Assert.AreEqual("Crazy", troop.Owner);
            Assert.AreEqual(217466, troop.OwnerVillageZ);
            Assert.AreEqual("abc's troops", troop.VillageName);
            Assert.AreEqual(1, troop.Troops[3]);
            Assert.AreEqual(TTroopType.InVillage, troop.TroopType);
            Assert.AreEqual(DateTime.MinValue, troop.FinishTime);
            Assert.AreEqual(2, troop.Tribe);

            troop = troops.Troops[2];
            Assert.AreEqual("Tiny", troop.Owner);
            Assert.AreEqual(270225, troop.OwnerVillageZ);
            Assert.AreEqual("Reinforcement for lalala Village", troop.VillageName);
            Assert.AreEqual(1, troop.Troops[10]);
            Assert.AreEqual(TTroopType.Outgoing, troop.TroopType);
            Assert.IsTrue(troop.FinishTime.AddHours(-11) > DateTime.Now);
            Assert.IsTrue(troop.FinishTime.AddHours(-12) < DateTime.Now);
            Assert.AreEqual(3, troop.Tribe);
        }
Ejemplo n.º 8
0
        public void TestInitialize()
        {
            this.travianData = new Data()
            {
                Server = "none",
                Username = "******"
            };

            Dictionary<string, string> Options = new Dictionary<string, string>();
            this.travian = new Travian(travianData, Options, "cn");

            this.villageID = 1;
            this.village = new TVillage();
            this.travianData.Villages[villageID] = village;

            this.village.Name = "Home";
            this.village.isTroopInitialized = 2;
            this.village.Troop = this.troop = new TTroop();
            int[] troopsAtHome = new int[11];
            troopsAtHome[0] = 8;
            TTInfo troopAtHome = new TTInfo
            {
                Troops = troopsAtHome,
                Owner = this.village.Name,
                TroopType = TTroopType.InVillage,
                VillageName = "Own troops"
            };
            this.troop.Troops.Add(troopAtHome);

            int[] troopsOnTheRood = new int[11];
            troopsOnTheRood[0] = 5;
            TTInfo troopOnTheRoad = new TTInfo
            {
                Troops = troopsAtHome,
                TroopType = TTroopType.MyReturnWay,
                FinishTime = DateTime.Now.AddSeconds(100),
                VillageName = "Raid on abc Village"
            };
            this.troop.Troops.Add(troopOnTheRoad);

            this.troops = new int[11];
            this.troops[0] = 5;

            this.targets = new List<TPoint>();
            this.targets.Add(new TPoint(1, 2));
            this.targets.Add(new TPoint(0, 0));

            this.target = new RaidQueue()
            {
                UpCall = this.travian,
                VillageID = this.villageID,
                Troops = this.troops,
                Targets = this.targets,
                RaidType = RaidType.AttackRaid,
            };

            this.pageQuerier = new MockPageQuerier(this.villageID);
            this.travian.pageQuerier = pageQuerier;
        }
Ejemplo n.º 9
0
 void tr_StatusUpdate(object sender, Travian.StatusChanged e)
 {
     try
     {
         Invoke(new StatusEvent_d(Local_StatusUpdate), new object[] { sender, e });
     }
     catch (Exception)
     { }
 }
Ejemplo n.º 10
0
        void Local_StatusUpdate(object sender, Travian.StatusChanged e)
        {
            if (e.ChangedData == Travian.ChangedType.Villages)
            {
                if (e.VillageID == -1)
                {
                    MessageBox.Show("Login failed!(登入失败!)\n請檢查伺服器和帳號密碼設定", "Stran");
                    return;
                }
                if (LoginInfo.Tribe == 0 && LoginInfo.Tribe != TravianData.Tribe)
                    LoginInfo.Tribe = TravianData.Tribe;

                if (m_villagelist.listViewVillage.Items.Count != TravianData.Villages.Count)
                    lock (QueueLock)
                        m_villagelist.listViewVillage.Items.Clear();
                else
                {
                    bool newv = false;
                    for (int j = 0; j < m_villagelist.listViewVillage.Items.Count - 1; j++)
                    {
                        int m = Convert.ToInt32(m_villagelist.listViewVillage.Items[j].SubItems[0].Text);
                        int n = TravianData.Villages[m].Sort;
                        if (n != j)
                            newv = true;
                    }
                    if (newv == true)
                        lock (QueueLock)
                            m_villagelist.listViewVillage.Items.Clear();
                }

                List<int> f = new List<int>();
                foreach (ListViewItem x in m_villagelist.listViewVillage.Items)
                {
                    f.Add(Convert.ToInt32(x.SubItems[0].Text));
                }

                foreach (var x in TravianData.Villages)
                {
                    if (f.Contains(x.Key))
                    {
                        var xkey = m_villagelist.listViewVillage.Items[f.IndexOf(x.Value.ID)];
                        if (xkey.SubItems[2].Text != x.Value.Name)
                            xkey.SubItems[2].Text = x.Value.Name;
                        xkey.BackColor = SystemColors.Window;
                        if (TravianData.Villages[x.Key].Troop.GetTroopsIsAttackMe == true)
                        {
                            xkey.BackColor = Color.Salmon;
                            if (AutoPlay)
                                PlayAlert();
                        }
                    }
                    else
                    {
                        var lvi = m_villagelist.listViewVillage.Items.Add(x.Value.ID.ToString());
                        string qcount = x.Value.GetStatus();
                        lvi.SubItems.Add(qcount);
                        lvi.SubItems.Add(x.Value.Name);
                        lvi.SubItems.Add(x.Value.Coord.ToString());
                        lvi.SubItems.Add("");
                        lvi.BackColor = SystemColors.Window;
                        if (TravianData.Villages[x.Key].Troop.GetTroopsIsAttackMe == true)
                        {
                            lvi.BackColor = Color.Salmon;
                            if (AutoPlay)
                                PlayAlert();
                        }
                    }
                }
                int index = -1;
                if (m_villagelist.listViewVillage.Items.Count != 0)
                {
                    if (m_villagelist.listViewVillage.SelectedIndices.Count == 1)
                        index = m_villagelist.listViewVillage.SelectedIndices[0];
                    else
                    {
                        foreach (ListViewItem x in m_villagelist.listViewVillage.Items)
                        {
                            if (Convert.ToInt32(x.SubItems[0].Text) == SelectVillage)
                            {
                                index = m_villagelist.listViewVillage.Items.IndexOf(x);
                            }
                        }
                    }
                }
                if (index >= 0)
                    m_villagelist.listViewVillage.Items[index].Selected = true;
                else
                    m_villagelist.listViewVillage.Items[m_villagelist.listViewVillage.Items.Count - 1].Selected = true;
            }
            else if (e.ChangedData == Travian.ChangedType.Stop)
            {
                if (e.Param == 1)
                {
                    m_resourceshow.label5.BackColor = Color.LightCyan;
                }
                else if (e.Param == 0)
                {
                    m_resourceshow.label5.BackColor = Color.Ivory;
                }
                else if (e.Param == 2)
                {
                    m_resourceshow.label5.BackColor = Color.Gold;
                }
            }
            else if (e.ChangedData == Travian.ChangedType.Queue && e.Param == -1)
            {
                //RestoreQueue(e.VillageID);

            }
            else if (e.ChangedData == Travian.ChangedType.PageCount)
            {
                lock (MainForm.Instance)
                {
                    MainForm.Instance.notifyIcon1.Icon = Properties.Resources.full;
                    MainForm.Instance.timerIcon.Enabled = false;
                    MainForm.Instance.timerIcon.Enabled = true;
                }
            }
            else if (e.VillageID == SelectVillage)
            {
                switch (e.ChangedData)
                {
                    case Travian.ChangedType.Buildings:
                        DisplayBuildings();
                        DisplayResource();
                        DisplayInBuilding();
                        RefreshBuildings();
                        break;
                    case Travian.ChangedType.Research:
                        DisplayUpgrade();
                        break;
                    case Travian.ChangedType.Queue:
                        RefreshQueue(e.Param);
                        break;
                }
                //ResetBrowser();
            }
        }
Ejemplo n.º 11
0
        public void Login()
        {
            if (tr != null)
                tr = null;
            TravianData = DB.Instance.RestoreData(LoginInfo.GetKey());
            if (TravianData == null)
                TravianData = new Data();
            TravianData.Username = LoginInfo.Username;
            TravianData.Password = LoginInfo.Password;
            TravianData.Tribe = LoginInfo.Tribe;
            TravianData.Server = LoginInfo.Server;
            if (!string.IsNullOrEmpty(LoginInfo.Proxy))
            {
                TravianData.Proxy = new WebProxy(LoginInfo.Proxy);
            }
            //if (MainForm.Options.ContainsKey("proxy"))
            //{
            //    string proxy = MainForm.Options["proxy"];
            //    TravianData.Proxy = new WebProxy(proxy);
            //}
            tr = DB.Instance.RestoreTravian(LoginInfo.Server);
            if (tr == null)
                tr = new Travian(TravianData, MainForm.Options, LoginInfo.ServerLang);
            else
            {
                tr.LoadRegexLang(LoginInfo.ServerLang);
                tr.TD = TravianData;
                tr.LoadOptions(MainForm.Options);
            }
            foreach (var v in TravianData.Villages)
            {
                v.Value.UpCall = tr;
                foreach (var q in v.Value.Queue)
                    q.UpCall = tr;
            }
            dl = new DisplayLang(LoginInfo.Language);
            DisplayLang.Instance = dl;
            tr.StatusUpdate += new EventHandler<Travian.StatusChanged>(tr_StatusUpdate);
            tr.OnError += new EventHandler<LogArgs>(tr_OnError);

            m_villagelist.listViewVillage.Items.Clear();
            m_buildinglist.listViewBuilding.Items.Clear();
            tr.CachedFetchVillages();
            UpTP.Text = string.Format("{0} @ {1}", LoginInfo.Username, LoginInfo.Server.Replace("travian.", ""));
        }
Ejemplo n.º 12
0
        public void Login()
        {
            if (tr != null)
                tr = null;
            TravianData = DB.Instance.RestoreData(LoginInfo.GetKey());
            if (TravianData == null)
                TravianData = new Data();
            TravianData.Username = LoginInfo.Username;
            TravianData.Password = LoginInfo.Password;
            if (TravianData.Tribe == 0)
                TravianData.Tribe = LoginInfo.Tribe;
            TravianData.Server = LoginInfo.Server;
            TravianData.GetOrPostTimesThreshold = LoginInfo.GetOrPostTimesThreshold;
            TravianData.GetOrPostDelaySeconds = LoginInfo.GetOrPostDelaySeconds;
            if (MainForm.Options.ContainsKey("proxy"))
            {
                System.Net.ServicePointManager.Expect100Continue = false;
                string proxy = MainForm.Options["proxy"];
                if (proxy != "IE")
                {
                    TravianData.Proxy = new WebProxy(proxy);
                }
                else
                {
                    TravianData.Proxy = WebProxy.GetDefaultProxy();
                    TravianData.Proxy.UseDefaultCredentials = true;
                }
            }
            tr = DB.Instance.RestoreTravian(LoginInfo.Server);
            if (tr == null)
                tr = new Travian(TravianData, MainForm.Options);
            else
            {
                tr.TD = TravianData;
                tr.LoadOptions(MainForm.Options);
            }
            foreach (var v in TravianData.Villages)
            {
                v.Value.UpCall = tr;
                foreach (var q in v.Value.Queue)
                    q.UpCall = tr;
            }
            dl = new DisplayLang(LoginInfo.Language);
            DisplayLang.Instance = dl;
            tr.StatusUpdate += new EventHandler<Travian.StatusChanged>(tr_StatusUpdate);
            tr.OnError += new EventHandler<LogArgs>(tr_OnError);
            tr.OnOasisFoundLog += new EventHandler<OasisFoundLogArgs>(tr_OnOasisFoundLog);
            tr.OnAnimalsFoundLog += new EventHandler<AnimalsFoundLogArgs>(tr_OnAnimalsFoundLog);
            tr.OnAnimalsInfoUpdate += new EventHandler<AnimalsInfoArgs>(tr_OnAnimalsInfoUpdate);

            m_villagelist.listViewVillage.Items.Clear();
            m_buildinglist.listViewBuilding.Items.Clear();
            tr.CachedFetchVillages();
            UpTP.Text = string.Format("{0} @ {1}", LoginInfo.Username, LoginInfo.Server.Replace("travian.", ""));
        }