public static PresentInfo ConvertToPresentObject(string feedback) { //<data> // <ret>succ</ret> // <name>绿玫瑰</name> // <fruitpic>http://img.kaixin001.com.cn//i2/house/garden/crop/meigui_g.swf</fruitpic> // <fruit_minprice>10000</fruit_minprice> // <fruit_maxprice>10100</fruit_maxprice> // <fruitnum>4</fruitnum> // <selfnum>4</selfnum> // <bpresent>1</bpresent> // <fruitprice>10050</fruitprice> //</data> //<data> // <ret>succ</ret> // <name>黑玫瑰</name> // <fruitpic>http://img.kaixin001.com.cn//i2/house/garden/crop/meigui_b.swf</fruitpic> // <fruit_minprice>5900</fruit_minprice> // <fruit_maxprice>6100</fruit_maxprice> // <fruitnum>3</fruitnum> // <selfnum>3</selfnum> // <bpresent>1</bpresent> // <fruitprice>6000</fruitprice> //</data> //<data> // <ret>succ</ret> // <name>蓝色妖姬</name> // <fruitpic>http://img.kaixin001.com.cn//i2/house/garden/crop/meigui_bl.swf</fruitpic> // <fruit_minprice>5900</fruit_minprice> // <fruit_maxprice>6100</fruit_maxprice> // <fruitnum>3</fruitnum> // <selfnum>3</selfnum> // <bpresent>1</bpresent> // <fruitprice>6000</fruitprice> //</data> //<data> // <ret>succ</ret> // <name>双色玫瑰</name> // <fruitpic>http://img.kaixin001.com.cn//i2/house/garden/crop/meigui_s.swf</fruitpic> // <fruit_minprice>5400</fruit_minprice> // <fruit_maxprice>5600</fruit_maxprice> // <fruitnum>6</fruitnum> // <selfnum>6</selfnum> // <bpresent>1</bpresent> // <fruitprice>5500</fruitprice> //</data> //<data> // <ret>succ</ret> // <name>白玫瑰</name> // <fruitpic>http://img.kaixin001.com.cn//i2/house/garden/crop/meigui_w.swf</fruitpic> // <fruit_minprice>4900</fruit_minprice> // <fruit_maxprice>5100</fruit_maxprice> // <fruitnum>18</fruitnum> // <selfnum>18</selfnum> // <bpresent>1</bpresent> // <fruitprice>5000</fruitprice> //</data> //<data> // <ret>succ</ret> // <name>粉玫瑰</name> // <fruitpic>http://img.kaixin001.com.cn//i2/house/garden/crop/meigui_f.swf</fruitpic> // <fruit_minprice>4400</fruit_minprice> // <fruit_maxprice>4600</fruit_maxprice> // <fruitnum>18</fruitnum> // <selfnum>18</selfnum> // <bpresent>1</bpresent> // <fruitprice>4500</fruitprice> //</data> //<data> // <ret>succ</ret> // <name>黄玫瑰</name> // <fruitpic>http://img.kaixin001.com.cn//i2/house/garden/crop/meigui_y.swf</fruitpic> // <fruit_minprice>4000</fruit_minprice> // <fruit_maxprice>4100</fruit_maxprice> // <fruitnum>15</fruitnum> // <selfnum>15</selfnum> // <bpresent>1</bpresent> // <fruitprice>4050</fruitprice> //</data> try { XmlDocument objXmlDoc = new XmlDocument(); objXmlDoc.LoadXml(feedback); if (objXmlDoc == null) return null; PresentInfo present = new PresentInfo(); //garden XmlNode objNode = objXmlDoc.SelectSingleNode(Constants.GARDEN_PRESENT_ROOT); if (objNode == null) return null; present.Ret = objNode.SelectSingleNode(Constants.GARDEN_PRESENT_RET).InnerText; present.Name = objNode.SelectSingleNode(Constants.GARDEN_PRESENT_NAME).InnerText; present.FruitPic = objNode.SelectSingleNode(Constants.GARDEN_PRESENT_FRUITPIC).InnerText; present.FruitMinPrice = DataConvert.GetInt32(objNode.SelectSingleNode(Constants.GARDEN_PRESENT_FRUITMINPRICE).InnerText); present.FruitMaxPrice = DataConvert.GetInt32(objNode.SelectSingleNode(Constants.GARDEN_PRESENT_FRUITMAXPRICE).InnerText); present.FruitNum = DataConvert.GetInt32(objNode.SelectSingleNode(Constants.GARDEN_PRESENT_FRUITNUM).InnerText); present.SelfNum = DataConvert.GetInt32(objNode.SelectSingleNode(Constants.GARDEN_PRESENT_SELFNUM).InnerText); present.BPresent = DataConvert.GetInt32(objNode.SelectSingleNode(Constants.GARDEN_PRESENT_BPRESENT).InnerText); present.FruitPrice = DataConvert.GetInt32(objNode.SelectSingleNode(Constants.GARDEN_PRESENT_FRUITPRICE).InnerText); return present; } catch (Exception ex) { LogHelper.Write("转换成StealObject-" + feedback, ex); return null; } }
private void PresentFruit() { try { SetMessageLn("开始赠送果实..."); if (Operation.PresentId == 0) { SetMessage("没有设定赠送的对象,无法赠送"); return; } if (!IsAlreadyMyFriend(DataConvert.GetString(Operation.PresentId))) { SetMessage(DataConvert.GetString(Operation.PresentId) + "不是你的好友,无法赠送"); return; } string content = RequestMyWarehouse(); Collection<FruitInfo> fruits = ConfigCtrl.GetMyGardenWarehouse(content); if (fruits == null || fruits.Count == 0) { SetMessage("仓库里没有任何果实"); return; } _incorrentcount = false; if (Task.PresentFruitByPrice) { //计算价值最高 SetMessageLn("仓库里可以送的果实:"); int num = 0; Collection<PresentInfo> presents = new Collection<PresentInfo>(); foreach (FruitInfo myfruit in fruits) { //牧草 if (myfruit.FruitId == 63) continue; FruitInfo fruit = GetFruitById(myfruit.FruitId); if (fruit == null) { SetMessage(string.Format("未知果实{0}-{1},跳过 ", myfruit.FruitId, myfruit.Name)); LogHelper.Write("GameGarden.PresentFruit" + CurrentAccount.UserName, string.Format("未知果实{0}-{1},跳过 ", myfruit.FruitId, myfruit.Name), LogSeverity.Warn); continue; } PresentInfo present = new PresentInfo(); present.SeedId = myfruit.FruitId; present.Name = myfruit.Name; present.SelfNum = myfruit.Num; present.FruitPrice = fruit.SellPrice; presents.Add(present); SetMessageLn(string.Format("#{0}{1}:数量:{2},单个售价:{3},总价值:{4}", ++num, present.Name, present.SelfNum, present.FruitPrice, present.SellSum)); } if (presents.Count == 0) { SetMessage(" 没有可送的果实"); return; } for (int ix = 0; ix < presents.Count; ix++) { for (int iy = ix + 1; iy < presents.Count; iy++) { if (presents[ix].SellSum > presents[iy].SellSum) { PresentInfo temp = presents[ix]; presents[ix] = presents[iy]; presents[iy] = temp; } } } PresentInfo presentMax = presents[presents.Count - 1]; SetMessageLn(string.Format("计算出可以送的价值最高的果实:{0}:{1}*{2}={3}元", presentMax.Name, presentMax.SelfNum, presentMax.FruitPrice, presentMax.SellSum)); if (Task.PresentFruitCheckValue && presentMax.SellSum < Task.PresentFruitValue * 10000) { SetMessage(string.Format(" 总价值{0}小于最低赠送价值{1},跳过", presentMax.SellSum, Task.PresentFruitValue * 10000)); return; } SetMessageLn(string.Format("向{0}赠送{1}个{2}(单价:{3}),总价值:{4}元 ", GetFriendNameById(Operation.PresentId), presentMax.SelfNum, presentMax.Name, presentMax.FruitPrice, presentMax.SellSum)); content = HH.Post("http://www.kaixin001.com/house/garden/presentfruit.php", string.Format("seedid={0}&touid={1}&num={2}&pmsg={3}&anon=0&verify={4}", presentMax.SeedId, Operation.PresentId, presentMax.SelfNum, DataConvert.GetEncodeData("送你果实啦!"), this._verifyCode)); if (GetPresentFeedback(content)) return; if (_incorrentcount) { //http://www.kaixin001.com/house/garden/myfruitinfo.php?seedid=30&verify=6209015_1062_6209015_1238501495_1be9db343ea4e4094275e8fc3a17480b&r=0.5750930430367589 content = HH.Get(string.Format("http://www.kaixin001.com/house/garden/myfruitinfo.php?seedid={0}&verify={1}&r=0.4879359360784292", presentMax.SeedId, this._verifyCode)); PresentInfo present = ConfigCtrl.ConvertToPresentObject(content); if (present != null && present.SelfNum > 0) { if (Task.PresentFruitCheckValue && present.SelfNum * present.FruitPrice < Task.PresentFruitValue * 10000) { SetMessage(string.Format(" 总价值{0}小于最低赠送价值{1},跳过", present.SelfNum * present.FruitPrice, Task.PresentFruitValue * 10000)); return; } SetMessageLn(string.Format("向{0}赠送{1}个{2}(单价:{3}),总价值:{4}元 ", GetFriendNameById(Operation.PresentId), present.SelfNum, present.Name, present.FruitPrice, present.SellSum)); content = HH.Post("http://www.kaixin001.com/house/garden/presentfruit.php", string.Format("seedid={0}&touid={1}&num={2}&pmsg={3}&anon=0&verify={4}", presentMax.SeedId, Operation.PresentId, present.SelfNum, DataConvert.GetEncodeData("送你果实啦!"), this._verifyCode)); GetPresentFeedback(content); return; } } } else { SetMessageLn(string.Format("尝试赠送指定的果实:{0}...", GetFruitNameById(Task.PresentFruitId))); foreach (FruitInfo myfruit in fruits) { //牧草 if (myfruit.FruitId == 63) continue; if (myfruit.FruitId == Task.PresentFruitId) { if (Task.PresentFruitCheckNum && myfruit.Num < Task.PresentFruitNum) { SetMessage(string.Format("数量{0}< 最小赠送数{1},跳过 ", myfruit.Num, Task.PresentFruitNum)); return; } FruitInfo fruit = GetFruitById(myfruit.FruitId); if (fruit == null) { SetMessage(string.Format("未知果实{0}-{1},跳过 ", myfruit.FruitId, myfruit.Name)); LogHelper.Write("GameGarden.PresentFruit" + CurrentAccount.UserName, string.Format("未知果实{0}-{1},跳过 ", myfruit.FruitId, myfruit.Name), LogSeverity.Warn); return; } SetMessageLn(string.Format("向{0}赠送{1}个{2}(单价:{3}),总价值:{4}元 ", GetFriendNameById(Operation.PresentId), myfruit.Num, myfruit.Name, fruit.SellPrice, fruit.SellPrice * myfruit.Num)); content = HH.Post("http://www.kaixin001.com/house/garden/presentfruit.php", string.Format("seedid={0}&touid={1}&num={2}&pmsg={3}&anon=0&verify={4}", Task.PresentFruitId, Operation.PresentId, myfruit.Num, DataConvert.GetEncodeData("送你果实啦!"), this._verifyCode)); if (GetPresentFeedback(content)) return; if (content.Contains("请明天再送")) return; if (_incorrentcount) { //http://www.kaixin001.com/house/garden/myfruitinfo.php?seedid=30&verify=6209015_1062_6209015_1238501495_1be9db343ea4e4094275e8fc3a17480b&r=0.5750930430367589 content = HH.Get(string.Format("http://www.kaixin001.com/house/garden/myfruitinfo.php?seedid={0}&verify={1}&r=0.4879359360784292", myfruit.FruitId, this._verifyCode)); PresentInfo present = ConfigCtrl.ConvertToPresentObject(content); if (present != null && present.SelfNum > 0) { if (Task.PresentFruitCheckNum && present.SelfNum < Task.PresentFruitNum) { SetMessage(string.Format("可送数量{0}< 最小赠送数{1},跳过 ", present.SelfNum, Task.PresentFruitNum)); return; } SetMessageLn(string.Format("向{0}赠送{1}个{2}(单价:{3}),总价值:{4}元 ", GetFriendNameById(Operation.PresentId), present.SelfNum, present.Name, present.FruitPrice, present.SellSum)); content = HH.Post("http://www.kaixin001.com/house/garden/presentfruit.php", string.Format("seedid={0}&touid={1}&num={2}&pmsg={3}&anon=0&verify={4}", Task.PresentFruitId, Operation.PresentId, present.SelfNum, DataConvert.GetEncodeData("送你果实啦!"), this._verifyCode)); GetPresentFeedback(content); return; } } } } SetMessage("仓库中没有该种果实,无法赠送。"); } } catch (ThreadAbortException) { throw; } catch (ThreadInterruptedException) { throw; } catch (Exception ex) { LogHelper.Write("GameGarden.PresentFruit", GetFriendNameById(Operation.PresentId), ex, LogSeverity.Error); SetMessage(" 向" + GetFriendNameById(Operation.PresentId) + "赠送果实失败!错误:" + ex.Message); } }