public static DTOCity[] GetCities() {//chỉ những thành phố của người chơi //nếu muốn lấy những thành phố khác thì phải chỉnh trogn xpath if (Gloval.Database.Account.Cities == null) { HtmlNodeCollection listCities = Gloval.Database.DocumentNode.SelectNodes( XPathManager.XPathCity.ListCities); List <DTOCity> arrCity = new List <DTOCity>(); foreach (HtmlNode nodeCity in listCities) { { DTOCity ct = NodeParser.toCityBasicInfo(nodeCity); arrCity.Add(ct); //MessageBox.Show(ct.ID.ToString() // + ct.X.ToString() // + ct.Y.ToString() // + ct.Name.ToString()); } } Gloval.Database.Account.Cities = arrCity.ToArray(); } return(Gloval.Database.Account.Cities); }
public static void CalculateFromLocalData() { DateTime dtnew = DateTime.Now; int nCities = BUSCity.Count(); for (int i = 0; i < nCities; i++) { DTOCity ct = BUSCity.GetResourceCity(i); TimeSpan tp = new TimeSpan(dtnew.Ticks - ct.DTResourceCity.Ticks); //cap nhat dan - townhall ct.FreePopulation += updateValue(ct.PopulationGrow, (float)tp.TotalSeconds); ct.Population = updateValueHaveLimit(ct.Population, ct.PopulationLimit, ct.PopulationGrow, (float)tp.TotalSeconds); //cap nhat res ct.Wood = updateValueHaveLimit(ct.Wood, ct.WoodLimit, ct.WoodPerHour, (float)tp.TotalSeconds); ct.Wine = updateValueHaveLimit(ct.Wine, ct.WineLimit, ct.WinePerHour, (float)tp.TotalSeconds); ct.Marble = updateValueHaveLimit(ct.Marble, ct.MarbleLimit, ct.MarblePerHour, (float)tp.TotalSeconds); ct.Crystal = updateValueHaveLimit(ct.Crystal, ct.CrystalLimit, ct.CrystalPerHour, (float)tp.TotalSeconds); ct.Sulphur = updateValueHaveLimit(ct.Sulphur, ct.SulphurLimit, ct.SulphurPerHour, (float)tp.TotalSeconds); //cap nhat cooldown cac building //cap nhat lai thoi gian ct.DTResourceCity = dtnew; ct.DTTownHall = dtnew; Gloval.Database.Account.Cities[i] = ct; } }
private void button4_Click(object sender, EventArgs e) {//get inf current city string strResult = ""; DTOCity city = BUSCity.GetResourceCity(0); //DTOCity city = BUSCity.GetResourceCity(BUSCity.GetCurrentCity()); strResult += " X: " + city.X; strResult += " Y: " + city.Y; strResult += " ID: " + city.ID; strResult += " Name: " + city.Name; strResult += " Type: " + city.TypeTradeGood; strResult += " po: " + city.FreePopulation; strResult += "(" + city.Population + ")"; strResult += " action: " + city.ActionPoint; strResult += " wood: " + city.Wood; strResult += "+" + city.WoodPerHour; strResult += " limit: " + city.WoodLimit; strResult += " wine: " + city.Wine; strResult += "+" + city.WinePerHour; strResult += " limit: " + city.WineLimit; strResult += " mar: " + city.Marble; strResult += "+" + city.MarblePerHour; strResult += " limit: " + city.MarbleLimit; strResult += " crys: " + city.Crystal; strResult += "+" + city.CrystalPerHour; strResult += " limit: " + city.CrystalLimit; strResult += " sul: " + city.Sulphur; strResult += "+" + city.SulphurPerHour; strResult += " limit: " + city.SulphurLimit; strResult += "\r\n"; tbResult.Text = strResult; }
private void button19_Click(object sender, EventArgs e) { string strResult = ""; int nCities = BUSCity.Count(); for (int i = 0; i < nCities; i++) { DTOCity city = BUSCity.GetResourceCity(i, true); strResult += " X: " + city.X; strResult += " Y: " + city.Y; strResult += " ID: " + city.ID; strResult += " Name: " + city.Name; strResult += " Type: " + city.TypeTradeGood; strResult += " po: " + city.Population; strResult += "(" + city.PopulationLimit + ")"; strResult += " action: " + city.ActionPoint; strResult += " wood: " + city.Wood; strResult += "+" + city.WoodPerHour; strResult += " wine: " + city.Wine; strResult += "+" + city.WinePerHour; strResult += " mar: " + city.Marble; strResult += "+" + city.MarblePerHour; strResult += " crys: " + city.Crystal; strResult += "+" + city.CrystalPerHour; strResult += " sul: " + city.Sulphur; strResult += "+" + city.SulphurPerHour; strResult += "\r\n"; } tbResult.Text = strResult; }
public static string toEmpireOverviewUnitJSON() { //kiem tra co moi hay ko, ko moi thi khong lay StringBuilder sb = new StringBuilder(5000); sb.Append("{EmpireOverviewUnit:["); int nCities = BUSCity.Count(); for (int i = 0; i < nCities; i++) { sb.Append('{'); DTOCity ct = BUSCity.GetResourceCity(i); sb.Append(string.Format("Name:{0},", ct.Name)); sb.Append(string.Format("ID:{0},", ct.ID)); sb.Append(string.Format("X:{0},", ct.X)); sb.Append(string.Format("Y:{0},", ct.Y)); sb.Append(string.Format("ActionPoint:{0},", ct.ActionPoint)); sb.Append(string.Format("FreePopulation:{0},", ct.FreePopulation)); //sb.Append(string.Format("Population:{0},", ct.Population)); sb.Append(string.Format("PopulationLimit:{0},", ct.PopulationLimit)); sb.Append(string.Format("Wood:{0},", ct.Wood)); sb.Append(string.Format("WoodPerHour:{0},", ct.WoodPerHour)); sb.Append(string.Format("WoodLimit:{0},", ct.WoodLimit)); sb.Append(string.Format("Wine:{0},", ct.Wine)); sb.Append(string.Format("WinePerHour:{0},", ct.WinePerHour)); sb.Append(string.Format("WineLimit:{0},", ct.WineLimit)); sb.Append(string.Format("Marble:{0},", ct.Marble)); sb.Append(string.Format("MarblePerHour:{0},", ct.MarblePerHour)); sb.Append(string.Format("MarbleLimit:{0},", ct.MarbleLimit)); sb.Append(string.Format("Crystal:{0},", ct.Crystal)); sb.Append(string.Format("CrystalPerHour:{0},", ct.CrystalPerHour)); sb.Append(string.Format("CrystalLimit:{0},", ct.CrystalLimit)); sb.Append(string.Format("Sulphur:{0},", ct.Sulphur)); sb.Append(string.Format("SulphurPerHour:{0},", ct.SulphurPerHour)); sb.Append(string.Format("SulphurLimit:{0},", ct.SulphurLimit)); sb.Append(string.Format("ResearchPointPerHour:{0},", ct.ResearchPointPerHour)); sb.Append(string.Format("GoldPerHour:{0}", ct.GoldPerHour)); sb.Append('}'); if (i != nCities - 1) {//dau phay giua moi bien trong mang sb.Append(','); } } sb.Append("]}"); return(sb.ToString()); }
public static DTOCity[] ParseCity(HtmlNode DocumentNode) {//chỉ những thành phố của người chơi //nếu muốn lấy những thành phố khác thì phải chỉnh trogn xpath HtmlNodeCollection listCities = DocumentNode.SelectNodes( XPathManager.XPathCity.ListCities); //List<DTOCity> arrCity = new List<DTOCity>(); //foreach (HtmlNode nodeCity in listCities) DTOCity[] arrCity = new DTOCity[listCities.Count]; for (int i = 0; i < arrCity.Count(); i++) { arrCity[i] = NodeParser.toCityBasicInfo(listCities[i]); } return(arrCity); }
public static DTOCity toCityBasicInfo(HtmlNode node) { DTOCity ct = new DTOCity(); ct.ID = node.GetAttributeValue("value", 0); string strInnerText = node.NextSibling.InnerText; ct.X = int.Parse(strInnerText.Substring(1, 2)); ct.Y = int.Parse(strInnerText.Substring(4, 2)); ct.Name = strInnerText.Substring(13, strInnerText.Length - 13); //Trade good: Marble //Hàng giao dịch: Lưu huỳnh string strType = node.GetAttributeValue("title", "err"); if (strType.EndsWith(GetDictValue("Wine"))) { ct.TypeTradeGood = DTOCity.TRADE_GOOD_TYPE.WINE; return(ct); } if (strType.EndsWith(GetDictValue("Marble"))) { ct.TypeTradeGood = DTOCity.TRADE_GOOD_TYPE.MARBLE; return(ct); } if (strType.EndsWith(GetDictValue("Crystal Glass"))) { ct.TypeTradeGood = DTOCity.TRADE_GOOD_TYPE.CRYSTAL; return(ct); } if (strType.EndsWith(GetDictValue("Sulphur"))) { ct.TypeTradeGood = DTOCity.TRADE_GOOD_TYPE.SULPHUR; return(ct); } return(ct); }
private void button28_Click(object sender, EventArgs e) {//town hall inf StringBuilder strResult = new StringBuilder(1000); DTOCity ct = BUSCity.GetTownHallInfomationInCity(Gloval.Database.CurrentCity, true); strResult.Append("---Town: " + BUSCity.GetCity(Gloval.Database.CurrentCity).Name + "---\r\n"); strResult.Append("polimit: " + ct.PopulationLimit); strResult.Append(" pogrow: " + ct.PopulationGrow.ToString()); strResult.Append(" net gold: " + ct.GoldPerHour); strResult.Append(" scientist point per hour: " + ct.ResearchPointPerHour.ToString()); strResult.Append("\r\n"); tbResult.Text = strResult.ToString(); }
private void button2_Click(object sender, EventArgs e) {//get list city string strResult = ""; int nCities = BUSCity.Count(); for (int i = 0; i < nCities; i++) { DTOCity city = BUSCity.GetCity(i); strResult += " X: " + city.X; strResult += " Y: " + city.Y; strResult += " ID: " + city.ID; strResult += " Name: " + city.Name; strResult += " Type: " + city.TypeTradeGood; strResult += "\r\n"; } DTOCity cityFF = BUSCity.GetCity(0); tbResult.Text = strResult; }
private void button29_Click(object sender, EventArgs e) { StringBuilder strResult = new StringBuilder(5000); int nCities = BUSCity.Count(); for (int i = 0; i < nCities; i++) { DTOCity ct = BUSCity.GetTownHallInfomationInCity(i, true); strResult.Append("---Town: " + BUSCity.GetCity(i).Name + "---\r\n"); strResult.Append("polimit: " + ct.PopulationLimit); strResult.Append(" pogrow: " + ct.PopulationGrow.ToString()); strResult.Append(" net gold: " + ct.GoldPerHour); strResult.Append(" scientist point per hour: " + ct.ResearchPointPerHour.ToString()); strResult.Append("\r\n"); } tbResult.Text = strResult.ToString(); }
//cap nhat dan so //action point //4 loai tai nguyen cua tp public static DTOCity ParseResources(DTOCity ct) { HtmlNodeCollection nodeLi = Gloval.Database.DocumentNode.SelectNodes( XPathManager.XPathCity.cityResources); foreach (HtmlNode nodeLiChild in nodeLi) { switch (nodeLiChild.GetAttributeValue("class", "err")) { case "population": { //population: 966 (1,627) string str = nodeLiChild.InnerText; string strFreePo = str.Substring(0, str.IndexOf('(') - 1); ct.FreePopulation = NodeParser.toInt(strFreePo); string strPo = str.Substring(str.IndexOf('(') + 1); ct.Population = NodeParser.toInt(strPo); break; } case "actions": { ct.ActionPoint = NodeParser.toInt(nodeLiChild.InnerText); break; } case "wood": { HtmlNode node = nodeLiChild.SelectSingleNode("./span[@id='value_wood']"); if (node == null) { break; } ct.Wood = NodeParser.toInt(node.InnerText); if (nodeLiChild.ChildNodes[5].ChildNodes.Count == 3) { ct.WoodLimit = NodeParser.toInt(nodeLiChild.SelectSingleNode("./div/span[1]").NextSibling.InnerText); break; } ct.WoodPerHour = NodeParser.toInt(nodeLiChild.SelectSingleNode("./div/span[1]").NextSibling.InnerText); ct.WoodLimit = NodeParser.toInt(nodeLiChild.SelectSingleNode("./div/span[2]").NextSibling.InnerText); break; } case "wine": { ct.Wine = NodeParser.toInt(nodeLiChild.SelectSingleNode("./span[@id='value_wine']").InnerText); if (nodeLiChild.ChildNodes[5].ChildNodes.Count == 3) { ct.WineLimit = NodeParser.toInt(nodeLiChild.SelectSingleNode("./div/span[1]").NextSibling.InnerText); break; } ct.WinePerHour = NodeParser.toInt(nodeLiChild.SelectSingleNode("./div/span[1]").NextSibling.InnerText); ct.WineLimit = NodeParser.toInt(nodeLiChild.SelectSingleNode("./div/span[2]").NextSibling.InnerText); break; } case "marble": { ct.Marble = NodeParser.toInt(nodeLiChild.SelectSingleNode("./span[@id='value_marble']").InnerText); if (nodeLiChild.ChildNodes[5].ChildNodes.Count == 3) { ct.MarbleLimit = NodeParser.toInt(nodeLiChild.SelectSingleNode("./div/span[1]").NextSibling.InnerText); break; } ct.MarblePerHour = NodeParser.toInt(nodeLiChild.SelectSingleNode("./div/span[1]").NextSibling.InnerText); ct.MarbleLimit = NodeParser.toInt(nodeLiChild.SelectSingleNode("./div/span[2]").NextSibling.InnerText); break; } case "glass": { ct.Crystal = NodeParser.toInt(nodeLiChild.SelectSingleNode("./span[@id='value_crystal']").InnerText); if (nodeLiChild.ChildNodes[5].ChildNodes.Count == 3) { ct.CrystalLimit = NodeParser.toInt(nodeLiChild.SelectSingleNode("./div/span[1]").NextSibling.InnerText); break; } ct.CrystalPerHour = NodeParser.toInt(nodeLiChild.SelectSingleNode("./div/span[1]").NextSibling.InnerText); ct.CrystalLimit = NodeParser.toInt(nodeLiChild.SelectSingleNode("./div/span[2]").NextSibling.InnerText); break; } case "sulfur": { ct.Sulphur = NodeParser.toInt(nodeLiChild.SelectSingleNode("./span[@id='value_sulfur']").InnerText); if (nodeLiChild.ChildNodes[5].ChildNodes.Count == 3) { ct.SulphurLimit = NodeParser.toInt(nodeLiChild.SelectSingleNode("./div/span[1]").NextSibling.InnerText); break; } ct.SulphurPerHour = NodeParser.toInt(nodeLiChild.SelectSingleNode("./div/span[1]").NextSibling.InnerText); ct.SulphurLimit = NodeParser.toInt(nodeLiChild.SelectSingleNode("./div/span[2]").NextSibling.InnerText); break; } } } return(ct); }