public static RanchInfo GetRanch(string strxml) { try { if (String.IsNullOrEmpty(strxml)) return null; XmlDocument objXmlDoc = new XmlDocument(); objXmlDoc.LoadXml(strxml); if (objXmlDoc == null) return null; RanchInfo ranch = new RanchInfo(); //ranch XmlNode objNode = objXmlDoc.SelectSingleNode(Constants.RANCH_ROOT + Constants.CHAR_SLASH + Constants.RANCH_ACCOUNT); if (objNode == null) return null; ranch.Rank = DataConvert.GetInt32(objNode.SelectSingleNode(Constants.RANCH_RANK).InnerText); ranch.RankTip = objNode.SelectSingleNode(Constants.RANCH_RANKTIP).InnerText; ranch.Name = objNode.SelectSingleNode(Constants.RANCH_NAME).InnerText; ranch.CashTip = objNode.SelectSingleNode(Constants.RANCH_CASHTIP).InnerText; ranch.Cash = GetCash(ranch.CashTip); ranch.TCharms = DataConvert.GetInt32(objNode.SelectSingleNode(Constants.RANCH_TCHARMS).InnerText); //水量:0格/<font color='#FF0000'>需加水</font> 牧草:30棵<font color='#FF0000'>(需加草)</font><br><font color='#666666'>距吃光还有约20小时</font> ranch.Water = DataConvert.GetInt32(objXmlDoc.SelectSingleNode(Constants.RANCH_ROOT + Constants.CHAR_SLASH + Constants.RANCH_WATER).InnerText); ranch.WaterTips = DataConvert.GetString(objXmlDoc.SelectSingleNode(Constants.RANCH_ROOT + Constants.CHAR_SLASH + Constants.RANCH_WATERTIPS).InnerText); ranch.Grass = DataConvert.GetInt32(objXmlDoc.SelectSingleNode(Constants.RANCH_ROOT + Constants.CHAR_SLASH + Constants.RANCH_GRASS).InnerText); ranch.GrassTips = DataConvert.GetString(objXmlDoc.SelectSingleNode(Constants.RANCH_ROOT + Constants.CHAR_SLASH + Constants.RANCH_GRASSTIPS).InnerText); //animal products DataView dv = GetData(objXmlDoc, Constants.RANCH_ROOT + Constants.CHAR_SLASH + Constants.RANCH_PRODUCT2); Collection<AnimalProductInfo> animalProducts = new Collection<AnimalProductInfo>(); for (int ix = 0; ix < dv.Table.Rows.Count; ix++) { try { AnimalProductInfo animalProduct = new AnimalProductInfo(); animalProduct.Uid = DataConvert.GetInt32(dv.Table.Rows[ix]["uid"]); animalProduct.Aid = DataConvert.GetInt32(dv.Table.Rows[ix]["aid"]); animalProduct.Type = DataConvert.GetInt32(dv.Table.Rows[ix]["type"]); animalProduct.Num = DataConvert.GetInt32(dv.Table.Rows[ix]["num"]); animalProduct.StealNum = DataConvert.GetInt32(dv.Table.Rows[ix]["stealnum"]); animalProduct.MTtime = DataConvert.GetString(dv.Table.Rows[ix]["mtime"]); animalProduct.Ppic = DataConvert.GetString(dv.Table.Rows[ix]["ppic"]); animalProduct.TName = DataConvert.GetString(dv.Table.Rows[ix]["tname"]); animalProduct.SKey = DataConvert.GetString(dv.Table.Rows[ix]["skey"]); animalProduct.PName = DataConvert.GetString(dv.Table.Rows[ix]["pname"]); animalProduct.Tips = DataConvert.GetString(dv.Table.Rows[ix]["tips"]); animalProduct.Oa = DataConvert.GetString(dv.Table.Rows[ix]["oa"]); animalProducts.Add(animalProduct); } catch (Exception ex) { LogHelper.Write("ConfigCtrl.GetRanch(Get animal products)", strxml, ex, LogSeverity.Warn); continue; } } ranch.AnimalProducts = animalProducts; //Animals dv = GetData(objXmlDoc, Constants.RANCH_ROOT + Constants.CHAR_SLASH + Constants.RANCH_ANIMALS); Collection<AnimalInfo> animals = new Collection<AnimalInfo>(); for (int ix = 0; ix < dv.Table.Rows.Count; ix++) { try { AnimalInfo animal = new AnimalInfo(); animal.AnimalSid = DataConvert.GetInt64(dv.Table.Rows[ix]["animalsid"]); animal.BProduct = DataConvert.GetInt32(dv.Table.Rows[ix]["bproduct"]); animal.BStat = DataConvert.GetInt32(dv.Table.Rows[ix]["bstat"]); animal.Tips = DataConvert.GetString(dv.Table.Rows[ix]["tips"]); animal.Status = DataConvert.GetInt32(dv.Table.Rows[ix]["status"]); animal.AName = DataConvert.GetString(dv.Table.Rows[ix]["aname"]); animal.PAction = DataConvert.GetString(dv.Table.Rows[ix]["paction"]); animals.Add(animal); } catch (Exception ex) { LogHelper.Write("ConfigCtrl.GetRanch(Get animals)", strxml, ex, LogSeverity.Error); continue; } } ranch.Animals = animals; //Foods dv = GetData(objXmlDoc, Constants.RANCH_ROOT + Constants.CHAR_SLASH + Constants.RANCH_FOODS); Collection<FoodItemInfo> foods = new Collection<FoodItemInfo>(); for (int ix = 0; ix < dv.Table.Rows.Count; ix++) { try { FoodItemInfo food = new FoodItemInfo(); food.Tips = DataConvert.GetString(dv.Table.Rows[ix][1]); food.SeedId = DataConvert.GetInt32(dv.Table.Rows[ix][4]); food.Grass = DataConvert.GetInt32(dv.Table.Rows[ix][5]); foods.Add(food); } catch (Exception ex) { LogHelper.Write("ConfigCtrl.GetRanch(Get Foods)", strxml, ex, LogSeverity.Warn); continue; } } ranch.Foods = foods; return ranch; } catch (Exception ex) { LogHelper.Write("ConfigCtrl.GetRanch", strxml, ex, LogSeverity.Error); return null; } }
private void AddWater(string uid, RanchInfo ranch) { try { SetMessageLn("开始添水..."); //水量:0格/<font color='#FF0000'>需加水</font> if (!(ranch.WaterTips.IndexOf("需加水") > -1 || ranch.WaterTips.IndexOf("需添加") > -1 || ranch.Water < 50)) { SetMessage("水量为" + ranch.Water.ToString() + "格,无需添加"); return; } //http://www.kaixin001.com/!house/!ranch//water.php //seedid=0&type=0&skey=&fuid=0&r=0%2E21396516868844628&verify=2588258%5F1062%5F2588258%5F1241444968%5F9ddee5e84226f10e772e23fa7b5d3d8a HH.DelayedTime = Constants.DELAY_1SECONDS; string content = HH.Post("http://www.kaixin001.com/!house/!ranch//water.php", string.Format("seedid=0&type=0&skey=&fuid={0}&r=0%2E21396516868844628&verify={1}", uid, DataConvert.GetEncodeData(this._verifyCode))); GetAddWaterFeedback(content); } catch (ThreadAbortException) { throw; } catch (ThreadInterruptedException) { throw; } catch (Exception ex) { LogHelper.Write("GameRanch.AddWater", ex, LogSeverity.Error); SetMessage("添水失败!错误:" + ex.Message); } }
private void AddGrass(string fuid, RanchInfo ranch) { try { SetMessageLn("开始添牧草..."); //牧草:30棵<font color='#FF0000'>(需加草)</font><br><font color='#666666'>距吃光还有约20小时</font> if (!(ranch.GrassTips.IndexOf("需加草") > -1 || ranch.GrassTips.IndexOf("需添加") > -1 || ranch.Grass < 150)) { SetMessage("还有" + ranch.Grass.ToString() + "颗牧草,无需添加"); return; } if (ranch.GrassTips.IndexOf("不需加") > -1) { SetMessage("还没有吃该饲料的动物,不需加"); return; } if (!_canaddgrass || _myfoodList == null || _myfoodList.Count == 0) { SetMessage("没有饲料"); _canaddgrass = false; return; } foreach (FoodInfo food in _myfoodList) { if (food.SeedId != 63) continue; if (food.Num <= 0) { SetMessage(string.Format("没有{0}({1})了", food.Name, food.SeedId)); _canaddgrass = false; continue; } //http://www.kaixin001.com/!house/!ranch//food.php //seedid=0&type=0&skey=&fuid=0&r=0%2E21396516868844628&verify=2588258%5F1062%5F2588258%5F1241444968%5F9ddee5e84226f10e772e23fa7b5d3d8a HH.DelayedTime = Constants.DELAY_1SECONDS; string content = HH.Post("http://www.kaixin001.com/!house/!ranch//food.php", string.Format("foodnum={0}&seedid={1}&fuid={2}&r=0%2E660982119385153&verify={3}&type=0&skey=", Math.Max(1, Math.Min(food.Num, Task.FoodNum)), food.SeedId, fuid, DataConvert.GetEncodeData(this._verifyCode))); GetAddGrassFeedback(content, food); } } catch (ThreadAbortException) { throw; } catch (ThreadInterruptedException) { throw; } catch (Exception ex) { LogHelper.Write("GameRanch.AddGrass", ex, LogSeverity.Error); SetMessage("添牧草失败!错误:" + ex.Message); } }
private void HarvestProduct(RanchInfo ranch) { try { SetMessageLn("开始收获农副产品..."); Collection<AnimalProductInfo> animalProducts = ranch.AnimalProducts; if (animalProducts == null || animalProducts.Count == 0) { SetMessage("没有农副产品可收获"); return; } int num = 0; foreach (AnimalProductInfo animalProduct in animalProducts) { try { SetMessageLn(string.Format("#{0} {1} 剩余数量:{2} ", ++num, animalProduct.PName, (animalProduct.Num - animalProduct.StealNum))); //http://www.kaixin001.com/!house/!ranch//havest.php //foodnum=1&seedid=0&fuid=0&r=0%2E7162455567158759&verify=6195212%5F1062%5F6195212%5F1241619244%5Fd06fa48b2750f2b126897bb02fa0e3bf&type=0&skey=hen //fuid=0&skey=hen&foodnum=1&seedid=0&type=1&r=0%2E44923274079337716&verify=6208872%5F1062%5F6208872%5F1241849557%5Fb93b666bf7fda774bdedececd2870d72 //fuid=0&skey=hen&foodnum=1&seedid=0&type=0&r=0%2E38333278289064765&verify=6208872%5F1062%5F6208872%5F1241849557%5Fb93b666bf7fda774bdedececd2870d72 HH.DelayedTime = Constants.DELAY_1SECONDS; string content = HH.Post("http://www.kaixin001.com/!house/!ranch//havest.php", string.Format("fuid={0}&skey={1}&foodnum=1&seedid=0&type={2}&r=0%2E44923274079337716&verify={3}", 0, animalProduct.SKey, animalProduct.Type, DataConvert.GetEncodeData(this._verifyCode))); GetStealProductFeedback(content, false); } catch (ThreadAbortException) { throw; } catch (ThreadInterruptedException) { throw; } catch (Exception ex) { LogHelper.Write("GameRanch.HarvestProduct", ex, LogSeverity.Error); SetMessage("收获" + animalProduct.PName+ "失败!错误:" + ex.Message); continue; } } } catch (ThreadAbortException) { throw; } catch (ThreadInterruptedException) { throw; } catch (Exception ex) { LogHelper.Write("GameRanch.HarvestProduct", ex, LogSeverity.Error); SetMessage("收获失败!错误:" + ex.Message); } }
private void HarvestAndProductAnimal(RanchInfo ranch) { try { SetMessageLn("开始生产/收获动物..."); Collection<AnimalInfo> animals = ranch.Animals; Collection<AnimalInfo> newlist = new Collection<AnimalInfo>(); if (animals == null || animals.Count == 0) { return; } int num = 0; foreach (AnimalInfo animal in animals) { try { bool harvested = false; if (animal.BProduct == 2 || animal.BStat == 2) { SetMessageLn(string.Format("第{0}个动物 {1}:", ++num, animal.AName)); } if (animal.BProduct == 2) { SetMessage(" 可以生产:"); HH.DelayedTime = Constants.DELAY_2SECONDS; string content = HH.Get(string.Format("http://www.kaixin001.com/!house/!ranch//product.php?fuid={0}&animalsid={1}&r=0%2E20183774875476956&verify={2}", "0", animal.AnimalSid, DataConvert.GetEncodeData(this._verifyCode))); GetMakeProductFeedback(content); } if (animal.BStat == 2) { SetMessage(" 可以收获:"); //http://www.kaixin001.com/!house/!ranch//mhavest.php?verify=7998514%5F1062%5F7998514%5F1258905868%5F92f3a7fb3bf711c0e7191e6dc53c8d33&fuid=0&animalsid=2174827016&r=0%2E2255321340635419 //<data><ret>succ</ret><mpic>http://img.kaixin001.com.cn//i2/house/ranch/animals2/hedgehogmeat.swf</mpic><cash>0</cash></data> HH.DelayedTime = Constants.DELAY_1SECONDS; string content = HH.Get(string.Format("http://www.kaixin001.com/!house/!ranch//mhavest.php?verify={0}&fuid=0&animalsid={1}&r=0%2E05614474741742015", DataConvert.GetEncodeData(this._verifyCode), animal.AnimalSid)); GetHarvestAnimalFeedback(content, ref harvested); } //如果没有被收获,加入到新的list中 if (!harvested) newlist.Add(animal); } catch (ThreadAbortException) { throw; } catch (ThreadInterruptedException) { throw; } catch (Exception ex) { LogHelper.Write("GameRanch.HarvestProduct", ex, LogSeverity.Error); SetMessage("收获" + animal.AName + "失败!错误:" + ex.Message); continue; } } ranch.Animals = newlist; } catch (ThreadAbortException) { throw; } catch (ThreadInterruptedException) { throw; } catch (Exception ex) { LogHelper.Write("GameRanch.HarvestProduct", ex, LogSeverity.Error); SetMessage("收获失败!错误:" + ex.Message); } }
private void BuyCalf(RanchInfo ranch) { //购买幼仔 SetMessageLn("购买幼仔..."); if (ranch.Animals.Count >= MAX_ANIMAL_COUNT) { SetMessage(string.Format("你最多能养{0}只动物", MAX_ANIMAL_COUNT)); return; } _canbuyanimals = true; int count = ranch.Animals.Count; bool isbuyable = true; if (Task.BuyCalfByPrice) { for (int ix = _calfsList.Count - 1; ix >= 0; ix--) { try { isbuyable = true; int buytimes = 0; while (count < MAX_ANIMAL_COUNT) { //防止死循环 if (buytimes > 20) break; else buytimes++; SetMessageLn(_calfsList[ix].Name + ":"); HH.DelayedTime = Constants.DELAY_2SECONDS; //http://www.kaixin001.com/!house/!ranch//buyanimals.php //num=1&id=1&verify=6209137%5F1062%5F6209137%5F1241620805%5F99a513746e0e8302268413d62b58b409 string content = HH.Post("http://www.kaixin001.com/!house/!ranch//buyanimals.php", string.Format("num=1&id={0}&verify={1}", _calfsList[ix].AId, DataConvert.GetEncodeData(this._verifyCode))); if (GetBuyCalfFeedback(content, _calfsList[ix].Name, 1, ref isbuyable)) count++; if (!isbuyable) break; if (!_canbuyanimals) break; } if (!_canbuyanimals) break; } catch (Exception ex) { LogHelper.Write("GameRanch.BuyCalf", ex, LogSeverity.Error); continue; } } } else { int buytimes = 0; while (count < MAX_ANIMAL_COUNT) { try { isbuyable = true; //防止死循环 if (buytimes > 20) break; else buytimes++; CalfInfo calf = GetCalfById(Task.BuyCalfCustom); SetMessageLn(calf.Name + ":"); HH.DelayedTime = Constants.DELAY_2SECONDS; string content = HH.Post("http://www.kaixin001.com/!house/!ranch//buyanimals.php", string.Format("num=1&id={0}&verify={1}", calf.AId, DataConvert.GetEncodeData(this._verifyCode))); if (GetBuyCalfFeedback(content, calf.Name, 1, ref isbuyable)) count++; if (!isbuyable) break; if (!_canbuyanimals) break; } catch (Exception ex) { LogHelper.Write("GameRanch.BuyCalf", ex, LogSeverity.Error); continue; } } } }
private void ReadMyFoods(RanchInfo ranch) { SetMessageLn("我的饲料:"); string content = RequestMyFoodList(1); int totalpage = 0; _myfoodList = ConfigCtrl.GetMyFoods(content, ref totalpage); if (_myfoodList == null) { SetMessage("无法读取我的饲料信息!"); return; } if (totalpage > 1) { for (int ix = 2; ix <= totalpage; ix++) { content = RequestMyFoodList(ix); int pagenum = 0; Collection<FoodInfo> nextfoods = ConfigCtrl.GetMyFoods(content, ref pagenum); foreach (FoodInfo food in nextfoods) { if (food != null && !String.IsNullOrEmpty(food.Name)) _myfoodList.Add(food); } } } int num = 0; foreach (FoodInfo food in _myfoodList) { ++num; if (num == _myfoodList.Count) SetMessage(food.Name + "(" + food.Num.ToString() + ")"); else SetMessage(food.Name + "(" + food.Num.ToString() + "),"); } }
private void SellProduct(RanchInfo ranch) { try { SetMessageLn("开始出售农副产品..."); if (Task.SellProductLowCash) { if (ranch.Cash > Task.SellProductLowCashLimit * 10000) { SetMessageLn(string.Format("还有{0}元现金,无须出售。", ranch.Cash)); return; } } if (Task.SellAllProducts) { //http://www.kaixin001.com/!house/!ranch//sellfruit.php?type=2&all=1&num=1&id=1&verify=6194153%5F1062%5F6194153%5F1242912584%5F1bc688494cff4b5101818e3a76c3866a string content = HH.Get(string.Format("http://www.kaixin001.com/!house/!ranch//sellfruit.php?type=2&all=1&num=1&id=1&verify={0}", DataConvert.GetEncodeData(this._verifyCode))); long productvalue = 0; GetSellProductFeedback(content, ref productvalue); } else { string content = RequestMyRanchWarehouse(); Collection<ProductInfo> products = ConfigCtrl.GetMyWarehouseProduct(content); if (products == null || products.Count == 0) { SetMessage("仓库里没有任何农副产品"); return; } //计算价值 long soldvalue = 0; long productvalue = 0; int num = 0; foreach (ProductInfo product in products) { productvalue = 0; if (soldvalue >= Task.SellProductMaxLimit * 10000) { SetMessageLn(string.Format("已出售的农副产品总价值已经超过{0}万,停止出售。", Task.SellProductMaxLimit)); break; } SetMessageLn(string.Format("#{0} ", ++num)); if (IsContained(product.Aid, product.Type)) { SetMessage(string.Format("{0}在出售的禁止列表中,跳过", product.Name)); continue; } int productprice = GetAnimalProductPriceByIdAndType(product.Aid, product.Type); if (productprice <= 0) { SetMessage(string.Format("未知农副产品{0}-{1},跳过", product.Aid, product.Type)); continue; } SetMessage(string.Format("{0} =>", product.Name)); double temp = (Task.SellProductMaxLimit * 10000 - soldvalue) / productprice; if (temp < 1) temp = 1; int sellnum = Math.Min(DataConvert.GetInt32(Math.Ceiling(temp)), product.Num); HH.DelayedTime = Constants.DELAY_1SECONDS; content = HH.Get(string.Format("http://www.kaixin001.com/!house/!ranch//sellfruit.php?verify={0}&id={1}&num={2}&type={3}&all=0&r=0%2E1741087632253766", DataConvert.GetEncodeData(this._verifyCode), product.Aid, sellnum, product.Type)); if (GetSellProductFeedback(content, ref productvalue)) { soldvalue += productvalue; SetMessage(string.Format("已出售的农副产品总价值:{0}元", soldvalue)); } if (sellnum < product.Num) break; } } } catch (ThreadAbortException) { throw; } catch (ThreadInterruptedException) { throw; } catch (Exception ex) { LogHelper.Write("GameRanch.SellProduct", ex, LogSeverity.Error); SetMessage("出售农副产品失败!错误:" + ex.Message); } }
private void AddBamboo(string fuid, RanchInfo ranch) { try { SetMessageLn("开始添竹子..."); //<tips>竹子:198棵<br><font color='#666666'>距吃光还有约396小时</font></tips> Collection<FoodItemInfo> foods = ranch.Foods; foreach (FoodItemInfo fooditem in foods) { if (fooditem.SeedId == 95) { if (!(fooditem.Tips.IndexOf("需添加") > -1 || fooditem.Grass < 150)) { SetMessage("还有" + fooditem.Grass.ToString() + "颗竹子,无需添加"); return; } if (fooditem.Tips.IndexOf("不需加") > -1 || fooditem.Tips.IndexOf("没有动物食用该饲料") > -1) { SetMessage("还没有吃该饲料的动物,不需加"); return; } if (!_canaddbamboo || _myfoodList == null || _myfoodList.Count == 0) { SetMessage("没有饲料"); _canaddbamboo = false; return; } foreach (FoodInfo food in _myfoodList) { if (food.SeedId != 95) continue; if (food.Num <= 0) { SetMessage(string.Format("没有{0}({1})了", food.Name, food.SeedId)); _canaddbamboo = false; continue; } //http://www.kaixin001.com/!house/!ranch//food.php //id=0&foodnum=1&seedid=95&fuid=0&r=0%2E8225318137556314&verify=2588258%5F1062%5F2588258%5F1253623471%5F8292808da944c4f9fda51bbd00c276a3&skey=&type=0 HH.DelayedTime = Constants.DELAY_1SECONDS; string content = HH.Post("http://www.kaixin001.com/!house/!ranch//food.php", string.Format("foodnum={0}&seedid={1}&fuid={2}&r=0%2E660982119385153&verify={3}&type=0&skey=", Math.Max(1, Math.Min(food.Num, Task.BambooNum)), food.SeedId, fuid, DataConvert.GetEncodeData(this._verifyCode))); GetAddBambooFeedback(content, food); } break; } } } catch (ThreadAbortException) { throw; } catch (ThreadInterruptedException) { throw; } catch (Exception ex) { LogHelper.Write("GameRanch.AddBamboo", ex, LogSeverity.Error); SetMessage("添竹子失败!错误:" + ex.Message); } }
private void AddCarrot(string fuid, RanchInfo ranch) { try { SetMessageLn("开始添胡萝卜..."); //胡萝卜:58棵<font color='#FF0000'>(需添加)</font><br><font color='#666666'>距吃光还有约232小时</font> Collection<FoodItemInfo> foods = ranch.Foods; foreach (FoodItemInfo fooditem in foods) { if (fooditem.SeedId == 1) { if (!(fooditem.Tips.IndexOf("需添加") > -1 || fooditem.Grass < 150)) { SetMessage("还有" + fooditem.Grass.ToString() + "个胡萝卜,无需添加"); return; } if (fooditem.Tips.IndexOf("不需加") > -1) { SetMessage("还没有吃该饲料的动物,不需加"); return; } if (!_canaddcarrot || _myfoodList == null || _myfoodList.Count == 0) { SetMessage("没有饲料"); _canaddcarrot = false; return; } foreach (FoodInfo food in _myfoodList) { if (food.SeedId != 1) continue; if (food.Num <= 0) { SetMessage(string.Format("没有{0}({1})了", food.Name, food.SeedId)); _canaddcarrot = false; continue; } //http://www.kaixin001.com/!house/!ranch//food.php //seedid=0&type=0&skey=&fuid=0&r=0%2E21396516868844628&verify=2588258%5F1062%5F2588258%5F1241444968%5F9ddee5e84226f10e772e23fa7b5d3d8a HH.DelayedTime = Constants.DELAY_1SECONDS; string content = HH.Post("http://www.kaixin001.com/!house/!ranch//food.php", string.Format("foodnum={0}&seedid={1}&fuid={2}&r=0%2E660982119385153&verify={3}&type=0&skey=", Math.Max(1, Math.Min(food.Num, Task.CarrotNum)), food.SeedId, fuid, DataConvert.GetEncodeData(this._verifyCode))); GetAddCarrotFeedback(content, food); } break; } } } catch (ThreadAbortException) { throw; } catch (ThreadInterruptedException) { throw; } catch (Exception ex) { LogHelper.Write("GameRanch.AddGrass", ex, LogSeverity.Error); SetMessage("添牧草失败!错误:" + ex.Message); } }