-
Notifications
You must be signed in to change notification settings - Fork 0
/
FrmFarmMain.cs
1618 lines (1508 loc) · 60.2 KB
/
FrmFarmMain.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Web;
using System.IO;
using System.Collections;
using Json;
namespace QQWinFarm
{
public partial class FrmFarmMain : Form
{
#region 变量定义
NewsBog newsbog = new NewsBog();
private System.Net.CookieContainer cookie = new System.Net.CookieContainer();
JsonObject _status_filter = new JsonObject("{}");//可操作好友列表
JsonObject model; //json模板
JsonObject _status; //用户农场信息
JsonObject _qzonefriends; //QQ空间 好友列表
string _qzonefriendsIds = ""; //QQ空间 好友 ID集合
JsonObject _shop; //商店
Thread thread1, thread2; //进程 1 可操作好友查询 2 操作好友
string _uid = "0"; //user id
bool _autoweed = true; //自动除草
bool _autonorm = true; //自动杀虫
bool _autowater = true; //自动浇水
bool _autoplant = true; //自动种植
bool _autosteal = true; //自动收获
bool _autoscarify = true; //自动翻地
bool _autoseed = true; //自动购买种子
bool _autobag = true; //查看背包
bool _autodog = true;
int _userInfoTime = 0;//用户信息刷新执行时间
int _userInfoUpTime = 60 * 5;//用户信息刷新时间
bool _autoWookBool = true; //是否工作
int _aotuWookTime = 0;//工作执行时间
int updateTime = 0; //更新时间
string _autourl = "";//默认获取地址
int setUpTime = 0; //执行的时间
string runUrl = ""; //操作好友时 运行的url
int runFriends = 0;
#endregion
#region 构造方法
public FrmFarmMain()
{
InitializeComponent();
}
public FrmFarmMain(System.Net.CookieContainer cookie)
{
InitializeComponent();
this.cookie = cookie;
}
#endregion
#region 页面打开和关闭
private void FrmFarmMain_Load(object sender, EventArgs e)
{
runFriends = Convert.ToInt32(txtFriends.Text.Trim());
updateTime = Convert.ToInt32(upTime.Text.Trim());
setUpTime = updateTime;
PanelError();
thread1 = new Thread(new ThreadStart(this.BindUserInfo));
thread1.Start();
}
private void FrmFarmMain_FormClosed(object sender, FormClosedEventArgs e)
{
Dispose();
System.Environment.Exit(System.Environment.ExitCode);
#region 说明
/*
System.Environment.Exit(System.Environment.ExitCode);
this.Dispose();
this.Close();
还有一种方法: System.Threading.Thread.CurrentThread.Abort();
或者 Process.GetCurrentProcess().Kill()
或者 Application.ExitThread();
或者 Application.ExitThread()
Application.Exit(); 方法停止在所有线程上运行的所有消息循环,并关闭应用程序的所有窗口
Application.Exit 是一种强行退出方式,就像 Win32 的 PostQuitMessage()。它意味着放弃所有消息泵,展开调用堆栈,并将执行返回给系统。
*/
#endregion
}
#endregion
#region 扫描好友
private void timer1_Tick(object sender, EventArgs e)
{
if (txtFriends.Text.Trim() == "")
{
txtFriends.Text = "0";
}
//runFriends = Convert.ToInt32(txtFriends.Text.Trim());
if (thread2 == null)
{
thread2 = new Thread(new ThreadStart(this.AutoRun));
}
if (thread1.IsAlive || thread2.IsAlive)
{
return;
}
if (_status_filter.Count >0)
{
return;
}
if (runFriends >= Convert.ToInt32(txtFriends.Text.Trim()))
{
//ChangeTSSL("");
runFriends = 0;
thread1 = new Thread(new ThreadStart(this.statusFilter));
thread1.Start();
}
else
{
runFriends++;
int shengyu = (Convert.ToInt32(txtFriends.Text.Trim()) - runFriends) + 1;
ChangeTSSL("距离下次执行时间还有:" + shengyu + "秒");
}
}
#endregion
#region timer2 执行好友
private void timer2_Tick(object sender, EventArgs e)
{
if(upTime.Text.Trim()=="")
{
upTime.Text="0";
}
updateTime = Convert.ToInt32(upTime.Text.Trim());
if (thread2 == null)
{
thread2 = new Thread(new ThreadStart(this.AutoRun));
}
if (thread1.IsAlive || thread2.IsAlive)
{
return;
}
if (_status_filter.Count <1)
{
return;
}
if (setUpTime >= updateTime)
{
//ChangeTSSL("");
setUpTime = 0;
thread2 = new Thread(new ThreadStart(this.AutoRun));
thread2.Start();
}
else
{
setUpTime++;
int shengyu = (updateTime - setUpTime) + 1;
ChangeTSSL("距离下次执行时间还有:" + shengyu + "秒");
}
}
#endregion
#region 格式化等级经验显示
/// <summary>
/// 格式化等级经验显示
/// </summary>
/// <param name="exp"></param>
/// <param name="lv"></param>
/// <returns></returns>
private string FormatExp(int exp, out int lv)
{
int level = 0;
while (exp > (level * 200) + 200)
{
exp -= (level * 200) + 200;
level++;
}
lv = level;
return exp + "/" + ((level * 200) + 200);
}
#endregion
#region 绑定用户信息
/// <summary>
/// 绑定用户信息
/// </summary>
private void BindUserInfo()
{
ChangeTSSL("正在获取农场信息...");
if (_uid == "0")
GetUsrInfo();
if (_shop == null)
this._shop = new JsonObject(ScanShop());
if (_qzonefriends == null || _xiaoyoufriends == null)
ListFriends();
ChangeTSSL("成功获取农场信息!");
}
#endregion
#region 运行农场操作
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();
}
#endregion
#region 查看自己购买的物品
/// <summary>
/// 查看自己购买的物品
/// </summary>
/// <param name="uid"></param>
/// <param name="cid"></param>
/// <param name="place"></param>
/// <returns></returns>
private string GetBag()
{
string farmtime = GetFarmTime();
string url = "http://happyfarm.xiaoyou.qq.com/api.php?mod=repertory&act=getUserSeed";
string post = "farmKey=" + GetFarmKey(farmtime) + "&farmTime=" + farmtime;
string result =GetHtml(url, post, true, cookie);
return result;
}
#endregion
#region 购买种子
/// <summary>
/// 购买种子
/// </summary>
/// <param name="uid"></param>
/// <param name="cid"></param>
/// <param name="number"></param>
/// <returns></returns>
private string Seed(string uid, string cid, int number)
{
string farmtime = GetFarmTime();
string url = "http://happyfarm.xiaoyou.qq.com//api.php?mod=repertory&act=buySeed";
string post = "cId=" + cid + "&uIdx=" + uid + "&number=" + number.ToString() + "&farmKey=" + GetFarmKey(farmtime) + "&farmTime=" + farmtime;
string result = GetHtml(url, post, true, cookie);
return result;
}
#endregion
#region 农场操作方法
/// <summary>
/// 铲除
/// </summary>
/// <param name="uid"></param> farmKey=da2c72dcbc442f97827c9f7eb8d89001&place=4&uIdx=361157088&cropStatus=7&farmTime=1260006806&ownerId=361157088
/// <param name="place"></param>
/// <returns></returns>
private string Scarify(string uid, string place)
{
string farmtime = GetFarmTime();
string url = runUrl + "/cgi-bin/cgi_farm_plant?mod=farmlandstatus&act=scarify";
string post = "uIdx="+uid+"&cropStatus=7&farmKey=" + GetFarmKey(farmtime) + "&place=" + HttpUtility.UrlEncode(place) + "&ownerId=" + _uid + "&farmTime=" + farmtime;
string result = GetHtml(url, post, true, cookie);
return result;
}
/// <summary>
/// 摘取自己菜
/// </summary>
/// <param name="uid"></param> farmKey=9b9f35a6fdc8f0a125051460ec44d29e&uIdx=361157088&farmTime=1259966227&place=6&ownerId=361157088
/// <param name="place"></param>
/// <returns></returns>
private string Harvest(string uid, string place)
{
string farmtime = GetFarmTime();
string url = runUrl + "/cgi-bin/cgi_farm_plant?mod=farmlandstatus&act=harvest";
string post = "farmKey=" + GetFarmKey(farmtime) + "&place=" + HttpUtility.UrlEncode(place) + "&ownerId=" + _uid + "&farmTime=" + farmtime;
string result = GetHtml(url, post, true, cookie);
return result;
}
/// <summary>
/// 偷好友菜
/// </summary>
/// <param name="uid"></param>
/// <param name="place"></param>
/// <returns></returns>
private string Steal(string uid, string place)
{
string farmtime = GetFarmTime();
string url = runUrl + "/cgi-bin/cgi_farm_steal?mod=farmlandstatus&act=scrounge";
string post = "farmKey=" + GetFarmKey(farmtime) + "&place=" + HttpUtility.UrlEncode(place) + "&ownerId=" + uid + "&farmTime=" + farmtime;
string result = GetHtml(url, post, true, cookie);
return result;
}
/// <summary>
/// 除草
/// </summary>
/// <param name="qq"></param>
/// <param name="place"></param>
/// <returns></returns> /cgi-bin/cgi_farm_steal?mod=farmlandstatus&act=scrounge
private string ClearWeed(string uid, string place)
{
string farmtime = GetFarmTime();
string url = runUrl + "/cgi-bin/cgi_farm_opt?mod=farmlandstatus&act=clearWeed";
string post = "farmKey=" + GetFarmKey(farmtime) + "&place=" + HttpUtility.UrlEncode(place) + "&ownerId=" + uid + "&farmTime=" + farmtime;
string result = GetHtml(url, post, true, cookie);
return result;
}
/// <summary>
/// 种植
/// </summary>
/// <param name="cid"></param>
/// <param name="uid"></param>
/// <param name="place"></param>
/// <returns></returns>
private string Plant(string cid, string uid, string place)
{
string farmtime = GetFarmTime();
string url = runUrl + "/cgi-bin/cgi_farm_plant?mod=farmlandstatus&act=planting";
string post = "cId=" + cid + "&farmKey=" + GetFarmKey(farmtime) + "&place=" +
HttpUtility.UrlEncode(place) + "&ownerId=" + uid + "&farmTime=" + farmtime;
string result = GetHtml(url, post, true, cookie);
return result;
}
/// <summary>
/// 浇水
/// </summary>
/// <param name="uid"></param>
/// <param name="place"></param>
/// <returns></returns>
private string Water(string uid, string place)
{
string farmtime = GetFarmTime();
string url = runUrl + "/cgi-bin/cgi_farm_opt?mod=farmlandstatus&act=water";
string post = "farmKey=" + GetFarmKey(farmtime) + "&place=" + HttpUtility.UrlEncode(place) + "&ownerId=" + uid + "&farmTime=" + farmtime;
string result = GetHtml(url, post, true, cookie);
return result;
return "";
}
/// <summary>
/// 杀虫
/// </summary>
/// <param name="qq"></param>
/// <param name="place"></param>
/// <returns></returns>
private string Spraying(string uid, string place)
{
string farmtime = GetFarmTime();
string url = runUrl + "/cgi-bin/cgi_farm_opt?mod=farmlandstatus&act=spraying";
string post = "farmKey=" + GetFarmKey(farmtime) + "&place=" + HttpUtility.UrlEncode(place) + "&ownerId=" + uid + "&farmTime=" + farmtime;
string result = GetHtml(url, post, true, cookie);
return result;
}
#endregion
#region 获取可操作的用户
private void addStatus(JsonObject json, string url)
{
for (int i = 0; i < _status_filter.Count; i++)
{
if (_status_filter.GetJson(i).GetJson(0).Key == json.Key)
return;
}
json.Add("url", url);
_status_filter.Add(json);
}
/// <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("获取获取可操作的用户列表完成");
}
#endregion
#region 验证
private string VerifyHtml(string html)
{
//{"code":0,"direction":"转换ID失败","poptype":3}
//{"direction":"系统错误","errorType":"timeOut","poptype":3}
if (html == "")
return "";
JsonObject model = new JsonObject(html);
if (model.GetValue("errorType") != null)
{
ChangeError(html);
string errorType = model.GetValue("errorType");
switch (errorType)
{
case "validateCode":
ChangeInfo(Utils.ConvertUnicodeStringToChinese(model.GetValue("errorContent")) + ",时间:" + DateTime.Now.ToString());
this.Invoke((MethodInvoker)delegate
{
//是否弹出验证码
if (chbVerify.Checked)
{
FrmFramVerify framverify = new FrmFramVerify(cookie, _uid);
framverify.ShowDialog(this);
}
else
{
FrmRest();
}
});
break;
/*
case "session":
break;
this.Invoke((MethodInvoker)delegate
{
Dispose();
if (thread1 != null && thread1.IsAlive)
thread1.Abort();
if (thread2 != null && thread2.IsAlive)
thread2.Abort();
FrmFarmLogin login = new FrmFarmLogin();
login.Show();
});
break;*/
default:
if (model.GetValue("errorContent") != null)
{
ChangeInfo("错误:"+Utils.ConvertUnicodeStringToChinese(model.GetValue("errorContent")));
}
ChangeInfo("错误类型:" + Utils.ConvertUnicodeStringToChinese(model.GetValue("errorType")));
break;
}
return null;
}