private void GetUserInfo() { string url = "http://www.szshbs.com/bbs/source/plugin/qqfarm/core/mync.php?mod=user&act=run"; string content = ""; try { content = HttpChinese.GetHtml(cookie, url); this._status = new JsonObject(content); uName = _status.GetJson("user").GetValue("userName"); uIdx = _status.GetJson("user").GetValue("uId"); uinY = _status.GetJson("user").GetValue("uinLogin"); model = _status; string headPic = model.GetJson("user").GetValue("headPic"); int level = 0; string exp = ""; exp = _status.GetJson("user").GetValue("exp"); exp = FormatExp(Convert.ToInt32(exp), out level); //读取头像可能出现没有头像的结果,导致一直等待 if (uIdx.Equals("19991")) { if (headPic != null) { try { Stream stream = HttpChinese.GetStream(headPic, cookie); picHead.Image = Image.FromStream(stream); } catch (Exception e) { toLog(e.Message); } } } this.Invoke((MethodInvoker)delegate { lblUserName.Text = _status.GetJson("user").GetValue("userName"); lblMoney.Text = _status.GetJson("user").GetValue("money"); lblExp.Text = exp; lblLevel.Text = level.ToString(); }); toLog("获取用户信息成功"); //以下获得农场信息 _farmStatus = new JsonObject(_status.GetValue("farmlandStatus")); dogJson = new JsonObject(_status.GetValue("dog")); showFarmland(_farmStatus); showId = uIdx; toLog("获得用户土地信息成功"); toStatus("当前显示农场为" + uName + "的农场"); } catch (Exception except) { toLog(except.Message); toLog("用户信息获取失败"); } }
/// <summary> /// 消息加载 /// </summary> /// <param name="model"></param> private void ChangeMsg(JsonObject model) { string direction = model.GetValue("direction"); if (direction != null) { direction = Utils.NoHTML(Utils.ConvertUnicodeStringToChinese(direction)); string exp = model.GetValue("exp"); string money = model.GetValue("money"); string harvest = model.GetValue("harvest"); string cName = model.GetValue("cName"); JsonObject _cIdmodel = model.GetJson("status"); string cId = model.GetValue("cId"); string num = model.GetValue("num"); if (exp != null || direction != "") { ChangeLBFM(direction + (exp != null ? " 经验:" + exp : "") + (money != null ? " 金钱:" + money : "") + (harvest!=null?" 果实:"+harvest:"")); //自动取消 if (direction != "" && exp == "0" && money == "0") { this.Invoke((MethodInvoker)delegate { if (chbCancel.Checked) { chbClearWeed.Checked = false; chbWater.Checked = false; chbSpraying.Checked = false; } }); } } if (cId != null&&cName!=null) { ChangeLBFM("购买 " + Utils.NoHTML(Utils.ConvertUnicodeStringToChinese(cName)) + " " + num + "个"); } if (_cIdmodel!=null) { if (_cIdmodel != null) { cId = _cIdmodel.GetValue("cId"); string nNum = null; if (cId != null) { JsonObject _cnamemodel = GetShopModel(cId); if (_cnamemodel == null) cName = "品种未知"; else cName = _cnamemodel.GetValue("cName"); if (_cIdmodel.GetJson("thief") != null && _cIdmodel.GetJson("thief").ToString().Contains(_uid)) { nNum = _cIdmodel.GetJson("thief").GetValue(_uid); } newsbog.AddFruit(cId, cName, (harvest != null ? harvest : nNum).ToString()); ChangeLBFM("采得 " + Utils.NoHTML(Utils.ConvertUnicodeStringToChinese(cName)) + " " + (harvest != null ? harvest : nNum) + "个"); } } } } }
/// <summary> /// 获取可操作的用户 /// </summary> private void statusFilter() { BindUserInfo(); ChangeTSSL("正在获取获取可操作的用户列表..."); ChangeLBFM(); string farmtime = GetFarmTime(); string Url = ""; string urlNum = ""; string post = ""; string result = ""; JsonObject _model_1 = new JsonObject("\"" + _uid + "\":{\"1\":1}"); if (_model_1.ToString().Contains(_uid)) { addStatus(_model_1, "qzone"); } Url = xiaoyouUrl; urlNum = "/cgi-bin/cgi_farm_getstatus_filter?cmd=1"; post = "friend%5Fuids=" + HttpUtility.UrlEncode(_xiaoyoufriendsIds) + "&farmTime=" + farmtime + "&farmKey=" + GetFarmKey(farmtime) + "&uIdx=" + _uid; result = GetHtml(Url + urlNum, post, true, cookie); model = new JsonObject(result); model = model.GetJson("status"); for (int i = 0; i < model.GetCollection().Count; i++) { _model_1 = model.GetCollection()[i]; addStatus(_model_1, "xiaoyou"); } farmtime = GetFarmTime(); Url = qzoneUrl; post = "friend%5Fuids=" + HttpUtility.UrlEncode(_qzonefriendsIds + "," + _uid) + "&farmTime=" + farmtime + "&farmKey=" + GetFarmKey(farmtime) + "&uIdx=" + _uid; result = GetHtml(Url + urlNum, post, true, cookie); model = new JsonObject(result); model = model.GetJson("status"); for (int i = 0; i < model.GetCollection().Count; i++) { _model_1 = model.GetCollection()[i]; addStatus(_model_1, "qzone"); } ChangeTSSL("获取获取可操作的用户列表完成"); }
private void AutoRun() { _autosteal = chbSteal.Checked;//摘取 _autoweed = chbClearWeed.Checked;//除草 _autowater = chbWater.Checked;//浇水 _autonorm = chbSpraying.Checked;//杀虫 _autoscarify = chbScarify.Checked;//铲除 _autoplant = chbPlant.Checked;//种植 _autoseed = chbSeed.Checked;//购买 _autobag = chbBag.Checked;//背包 _autodog = chkDog.Checked; if (_status_filter.Count < 1) thread2.Abort(); JsonObject _statusModel = _status_filter.GetJson(0); JsonObject _statusModel_1 = _statusModel.GetJson(0); if (_statusModel_1 == null) thread2.Abort(); _status_filter.Remove(_statusModel); /* 0:1 干旱 1 > 0有手 2:1有草 3:1有虫 */ #region 局部变量 string frienduid = _statusModel_1.Key; JsonObject _friends = _xiaoyoufriends; string url = _statusModel.GetValue("url"); string frienduName = ""; string urlTitle = ""; string _autostealstr = "";//摘取 string _autoweedstr = "";//除草 string _autowaterstr = "";//浇水 string _autonormstr = "";//杀虫 string _autoscarifystr = "";//铲除 string _autoplantstr = "";//种植 switch (url) { case "xiaoyou": _friends = _xiaoyoufriends; urlTitle = "校友"; runUrl = "http://nc.xiaoyou.qq.com"; break; case "qzone": _friends = _qzonefriends; urlTitle = "QQ空间"; runUrl = "http://nc.qzone.qq.com"; break; } #region 查找好友名称 string _msg = ""; if (frienduid != _uid) { for (int i = 0; i < _friends.GetCollection().Count; i++) { if (_friends.GetCollection()[i].GetValue("userId") == frienduid) { frienduName = Utils.ConvertUnicodeStringToChinese(_friends.GetCollection()[i].GetValue("userName")); _msg = "查看 " + urlTitle + " 好友【" + frienduName + "】"; } } } else { _msg = "查看 自己 农场"; } ChangeLBFM(_msg); ChangeTSSL(_msg); #endregion #endregion _statusModel_1 = new JsonObject(_statusModel_1[frienduid]); #region 判断是否需要操作 if (!frienduid.Contains(_uid)) { bool _autorun = false; string _autostr = ""; if (_autowater) { _autostr = _statusModel_1.GetValue("0"); if (_autostr != null && Convert.ToInt32(_autostr) > 0) _autorun = true; } if (_autosteal) { _autostr = _statusModel_1.GetValue("1"); if (_autostr != null && Convert.ToInt64(_autostr)>0) { _autorun = true; //double times = 0; //double durtime = Convert.ToInt64(times + Convert.ToInt64(_autostr)); //if (durtime < now)//成熟 // _autorun = true; } } if (_autoweed) { _autostr = _statusModel_1.GetValue("2"); if (_autostr != null && Convert.ToInt32(_autostr) > 0) _autorun = true; } if (_autonorm) { _autostr = _statusModel_1.GetValue("3"); if (_autostr != null && Convert.ToInt32(_autostr) > 0) _autorun = true; } if (!_autorun) { thread2.Abort(); } } #endregion //加载土地信息 string result = ShowFriend(frienduid, runUrl); JsonObject lands = new JsonObject(result); double nowtime = (DateTime.Now - new DateTime(1970, 1, 1, 8, 0, 0)).TotalSeconds; double servertime = nowtime; if (lands.GetJson("user") != null && lands.GetJson("user").GetJson("healthMode") != null) { if (lands.GetJson("user").GetJson("healthMode").GetValue("serverTime") != null) { servertime = Convert.ToInt32(lands.GetJson("user").GetJson("healthMode").GetValue("serverTime")); } } FarmKey.NetworkDelay = nowtime - servertime; if (lands.GetValue("pf") != null && lands.GetValue("pf") != "1") { if (6 <= DateTime.Now.Hour && DateTime.Now.Hour >= 0) { ChangeLBFM("保护模式"); } } #region 循环 地 for (int j = 0; j < lands.GetCollection("farmlandStatus").GetCollection().Count; j++) { //bool s = false; //double times = 0; /*//if (lands.GetCollection("farmlandStatus").GetCollection()[j].GetValue("j").Equals("0")) //{ for (int x = 0; x < _shop.GetCollection().Count; x++) { if (_shop.GetCollection()[x].GetValue("cId").Equals(lands.GetCollection("farmlandStatus").GetCollection()[j].GetValue("a")))//不是空地 { ChangeLBFM("第" + (j + 1) + "块地种植了【" + Utils.ConvertUnicodeStringToChinese(_shop.GetCollection()[x].GetValue("cName")) + "】"); s = true; times = Convert.ToInt64(_shop.GetCollection()[x].GetValue("growthCycle")); break; } } //} */ #region 是否有庄稼 if (Convert.ToInt32(lands.GetCollection("farmlandStatus").GetCollection()[j].GetValue("a")) > 0) { //double durtime = Convert.ToInt64(times + Convert.ToInt64(lands.GetCollection("farmlandStatus").GetCollection()[j].GetValue("b"))); //if (durtime < now)//成熟 string farmlandStatus_b = lands.GetCollection("farmlandStatus").GetCollection()[j].GetValue("b"); #region 可摘取判断 if (farmlandStatus_b == "6") { //ChangeLBFM("第" + (j + 1) + "块地成熟"); int farmlandStatus_m = Convert.ToInt32(lands.GetCollection("farmlandStatus").GetCollection()[j].GetValue("m"));//剩余数 int farmlandStatus_l = Convert.ToInt32(lands.GetCollection("farmlandStatus").GetCollection()[j].GetValue("l"));//可摘取数 JsonObject farmlandStatus_n = lands.GetCollection("farmlandStatus").GetCollection()[j].GetJson("n");//摘取记录 string ModelRawjson = ""; if (farmlandStatus_n != null) { ModelRawjson = farmlandStatus_n.ToString(); } if (frienduid.Contains(_uid)||(farmlandStatus_m > farmlandStatus_l && (farmlandStatus_n == null || !ModelRawjson.Contains(_uid))))//没有偷过 { if (_autosteal) { ChangeLBFM("第 " + (j+1) + " 块可以采摘,开始摘取..."); bool _rundog = false; #region 查看是否有狗 if (lands.GetJson("dog") != null) { if (lands.GetJson("dog").GetValue("isHungry") == "0") { if (_autodog) { _rundog = true; ChangeLBFM("此好友 有狗..."); } else { ChangeLBFM("未开启-不摘有狗"); } } } #endregion if (frienduid.Contains(_uid)) Harvest(_uid, j.ToString()); else { if (!_rundog) Steal(frienduid, j.ToString()); } //ChangeLBFM("成功摘取..."); } if (_autostealstr != "") _autostealstr += ","; _autostealstr += j.ToString(); } //else //{ // ChangeLBFM("已经摘取或到最低限额,不可摘取"); //} } //else //{ // ChangeLBFM("未成熟,不可摘取"); //} #endregion #region 判断庄稼枯萎 //string farmlandStatus_j = lands.GetCollection("farmlandStatus").GetCollection()[j].GetValue("j"); if (farmlandStatus_b == "7")//lands.GetCollection("farmlandStatus").GetCollection()[j].GetValue("j").Equals("1")|| { if (_autoscarifystr != "") _autoscarifystr += ","; _autoscarifystr += j.ToString(); } #endregion #region 是否有草判断 //除草 f代表有几棵草 0为没有 k为产量,为0时即尚未成熟 成熟的植物不长草的 if (!lands.GetCollection("farmlandStatus").GetCollection()[j].GetValue("f").Equals("0") && lands.GetCollection("farmlandStatus").GetCollection()[j].GetValue("k").Equals("0")) { ChangeLBFM("第 " + (j + 1) + " 块地有草,开始除草..."); for (int x = 0; x < Convert.ToInt32(lands.GetCollection("farmlandStatus").GetCollection()[j].GetValue("f")); x++) { if (_autoweed || frienduid.Contains(_uid)) { //ChangeLBFM("第 " + _autoweedstr + " 块地有草,开始除草..."); ClearWeed(frienduid, j.ToString() ); // ChangeLBFM("第 " + _autoweedstr + " 块地 除草成功"); } if (_autoweedstr != "") _autoweedstr += ","; _autoweedstr += j.ToString(); //ClearWeed(frienduid, j.ToString()); } //ChangeLBFM("第 " + (j + 1) + " 块地 除草成功"); } #endregion #region 是否需浇水 if (!lands.GetCollection("farmlandStatus").GetCollection()[j].GetValue("h").Equals("1"))//浇水 { ChangeLBFM("第 " + (j + 1) + " 块地干燥,开始浇水..."); if (_autowater || frienduid.Contains(_uid)) { // ChangeLBFM("第 " + _autowaterstr + " 块地干燥,开始浇水..."); Water(frienduid, j.ToString()); } if (_autowaterstr != "") _autowaterstr += ","; _autowaterstr += j.ToString(); //Water(frienduid, j.ToString()); //ChangeLBFM("第 " + (j + 1) + " 块地 浇水成功"); } #endregion #region 是否需杀虫 if (!lands.GetCollection("farmlandStatus").GetCollection()[j].GetValue("g").Equals("0") && lands.GetCollection("farmlandStatus").GetCollection()[j].GetValue("k").Equals("0"))//杀虫 g代表有几条虫 0为没有 k为产量,为0时即尚未成熟 成熟的植物不长虫的 { ChangeLBFM("第 " + (j + 1) + " 块地有虫,开始杀虫..."); for (int x = 0; x < Convert.ToInt32(lands.GetCollection("farmlandStatus").GetCollection()[j].GetValue("g")); x++) { if (_autonorm || frienduid.Contains(_uid)) { //ChangeLBFM("第 " + _autonormstr + " 块地有虫,开始杀虫..."); Spraying(frienduid, j.ToString()); //ChangeLBFM("第 " + _autonormstr + " 块地 杀虫成功"); } if (_autonormstr != "") _autonormstr += ","; _autonormstr += j.ToString(); // Spraying(frienduid, j.ToString()); } //ChangeLBFM("第 " + (j + 1) + " 块地 杀虫成功"); } #endregion } else { if (frienduid.Contains(_uid)) { if (_autoplantstr != "") _autoplantstr += ","; _autoplantstr += j.ToString(); } } #endregion } #endregion #region 摘取 if (_autostealstr != "") { if (_autosteal || frienduid.Contains(_uid)) { /* ChangeLBFM("第 " + _autostealstr + " 块可以采摘,开始摘取..."); bool _rundog = false; #region 查看是否有狗 if (lands.GetJson("dog") != null) { if (lands.GetJson("dog").GetValue("isHungry") == "0") { if (_autodog) { _rundog = true; ChangeLBFM("此好友 有狗..."); } else { ChangeLBFM("未开启-不摘有狗"); } } } #endregion if (frienduid.Contains(_uid)) Harvest(_uid, _autostealstr); else { if (!_rundog) Steal(frienduid, _autostealstr); } */ //ChangeLBFM("成功摘取..."); } else { ChangeLBFM("未开启自动摘取"); } } #endregion #region 除草 if (_autoweedstr != "" ) { if (_autoweed || frienduid.Contains(_uid)) { //ChangeLBFM("第 " + _autoweedstr + " 块地有草,开始除草..."); //ClearWeed(frienduid, _autoweedstr); // ChangeLBFM("第 " + _autoweedstr + " 块地 除草成功"); } else { ChangeLBFM("未开启自动除草"); } } #endregion #region 浇水 if (_autowaterstr != "" ) { if (_autowater || frienduid.Contains(_uid)) { /* ChangeLBFM("第 " + _autowaterstr + " 块地干燥,开始浇水..."); Water(frienduid, _autowaterstr); */ } else { ChangeLBFM("未开启自动浇水"); } } #endregion #region 杀虫 if (_autonormstr != "" ) { if (_autonorm || frienduid.Contains(_uid)) { ChangeLBFM("第 " + _autonormstr + " 块地有虫,开始杀虫..."); Spraying(frienduid, _autonormstr); //ChangeLBFM("第 " + _autonormstr + " 块地 杀虫成功"); } else { ChangeLBFM("未开启自动杀虫"); } } #endregion #region 铲除 if (_autoscarifystr != "") { if (frienduid.Contains(_uid)) { if (_autoscarify) { ChangeLBFM("第 " + _autoscarifystr + " 块地枯萎,开始翻地..."); Scarify(frienduid, _autoscarifystr); _autoplantstr = _autoscarifystr; //ChangeLBFM("第 " + _autonormstr + " 块地 杀虫成功"); } else { ChangeLBFM("未开启自动翻地"); } } } #endregion #region 种植 if (_autoplantstr != "") { if (_autoplant) { if (frienduid.Contains(_uid)) { ChangeLBFM("第 " + _autoplantstr + " 块地是空地"); string[] plantIds = _autoplantstr.Split(','); int plantIdsIndex = 0; int number = 0; string key = ""; string value = ""; Hashtable plantht = new Hashtable(); if (_autobag) { JsonObject bag = new JsonObject(GetBag()); ChangeLBFM("开始查看背包..."); for (int y = 0; y < bag.GetCollection().Count; y++) { if (plantIdsIndex >= plantIds.Length) break; if (bag.GetCollection()[y].GetValue("type").Equals("1")) { key = bag.GetCollection()[y].GetValue("cId"); value = ""; if (plantht.ContainsKey(key)) { value = plantht[key].ToString(); plantht.Remove(key); } for (int ount = 0; ount < Convert.ToInt32(bag.GetCollection()[y].GetValue("amount")); ount++) { if (plantIdsIndex >= plantIds.Length) break; if (value != "") value += ",";//amount value += plantIds[plantIdsIndex]; plantIds[plantIdsIndex] = null; plantIdsIndex++; } plantht.Add(key, value); } } } else { ChangeLBFM("未开启查看背包"); } key = "Seed"; for (int n = 0; n < plantIds.Length; n++) { if (plantIds[n] != null) { value = ""; if (plantht.ContainsKey(key)) { value = plantht[key].ToString(); plantht.Remove(key); } if (value != "") value += ","; value += plantIds[n]; plantht.Add(key, value); number++; } } if (plantht.ContainsKey(key)) { value = plantht[key].ToString(); plantht.Remove(key); if (_autoplant) { key = GetShopLv(); if (key != null) { ChangeLBFM("开始购买 " + Utils.NoHTML(Utils.ConvertUnicodeStringToChinese(GetShopModel(key).GetValue("cName"))) + " " + number + "个"); Seed(_uid, key, number); plantht.Add(key, value); } else { ChangeLBFM("没有同一等级的种子"); } } else { ChangeLBFM("未开启自动购买"); } } foreach (DictionaryEntry plant in plantht) { ChangeLBFM("开始种地..."); Plant(plant.Key.ToString(), _uid, plant.Value.ToString()); } } } else { ChangeLBFM("未开启自动种植"); } #endregion } thread2.Abort(); }
private void GetUsrInfo() { string farmtime = GetFarmTime(); string url = "http://nc.xiaoyou.qq.com/cgi-bin/cgi_farm_index?mod=user&act=run"; string post = "farmKey=" + GetFarmKey(farmtime) + "&farmTime=" + farmtime; string result = GetHtml(url, post, true, cookie); _status = new JsonObject(result); _uid = _status.GetJson("user").GetValue("uId"); model = _status; string headPic = model.GetJson("user").GetValue("headPic").Replace("\\", ""); if (headPic != null) { Stream stream = GetStream(headPic, cookie); picHead.Image = Image.FromStream(stream); } this.Invoke((MethodInvoker)delegate { if (model.GetJson("user").GetValue("userName") != null) { string userName = Utils.ConvertUnicodeStringToChinese(model.GetJson("user").GetValue("userName")); lblUserName.Text = userName; this.Text = userName + " --QQ农夫"; notifyIcon1.Text = "(" + (userName) + ")" + notifyIcon1.Text; } lblMoney.Text = model.GetJson("user").GetValue("money"); int lv = 0; lblExp.Text = FormatExp(Convert.ToInt32(model.GetJson("user").GetValue("exp")), out lv); lblLevel.Text = lv.ToString(); }); }