SHOW:
|
|
- or go back to the newest paste.
1 | using System; | |
2 | using System.Collections.Generic; | |
3 | using System.Linq; | |
4 | using System.Text; | |
5 | using System.Threading; | |
6 | ||
7 | using D3; | |
8 | using rndWalker.Common; | |
9 | using rndWalker.Bots; | |
10 | ||
11 | ||
12 | ||
13 | namespace rndWalker { | |
14 | class rndWalker { | |
15 | public static rndWalker Instance { get; set; } | |
16 | private Thread thread; | |
17 | private Thread guardian; | |
18 | private Logger logger; | |
19 | private int gameCounter = 0; | |
20 | private Bot bot; | |
21 | private int run_start = 0; | |
22 | ||
23 | const int SECONDS_BEFORE_RESTART = 70; | |
24 | public static UIElement[] _elements = UIElement.Get(); | |
25 | ||
26 | public rndWalker() { | |
27 | this.thread = new Thread(this.ExecutingThread); | |
28 | this.guardian = new Thread(this.GuardianThread); | |
29 | this.logger = new Logger("rndWalker"); | |
30 | ||
31 | Game.OnTickEvent += new TickEventHandler(Game_OnTickEvent); | |
32 | } | |
33 | ||
34 | void Game_OnTickEvent(EventArgs e) { | |
35 | _elements = UIElement.Get(); | |
36 | ||
37 | if (Game.Ingame) { | |
38 | if (/*Me.WorldId != 0xFFFFFFFF &&*/ Me.WorldId != 0 && Me.Life == 0) { | |
39 | Console.WriteLine("I died! Exitting game"); | |
40 | Bot.ExitGame(); | |
41 | // hard reset | |
42 | rndWalker.Instance.Restart(); | |
43 | } | |
44 | } | |
45 | } | |
46 | ||
47 | public void Start() { | |
48 | this.thread.Start(); | |
49 | this.guardian.Start(); | |
50 | } | |
51 | ||
52 | public void Stop() { | |
53 | this.thread.Abort(); | |
54 | this.guardian.Abort(); | |
55 | } | |
56 | ||
57 | public void Restart() { | |
58 | this.thread.Abort(); | |
59 | this.thread = new Thread(this.ExecutingThread); | |
60 | this.thread.Start(); | |
61 | } | |
62 | ||
63 | private void GuardianThread() { | |
64 | while (true) | |
65 | { | |
66 | Thread.Sleep(5000); | |
67 | if ((System.Environment.TickCount - run_start) / 1000 > SECONDS_BEFORE_RESTART && bot != null) | |
68 | { | |
69 | bot = null; | |
70 | Restart(); | |
71 | } | |
72 | } | |
73 | } | |
74 | ||
75 | private void ExecutingThread() { | |
76 | Thread.Sleep(500); | |
77 | ||
78 | ||
79 | ||
80 | ||
81 | ||
82 | ||
83 | ||
84 | ||
85 | ||
86 | bot = new RoyalCryptsMinions(); | |
87 | //bot = new Sarkoth(); | |
88 | //bot = new a4chest(); | |
89 | ||
90 | ||
91 | ||
92 | while (true) { | |
93 | Thread.Sleep(1000); | |
94 | ||
95 | ||
96 | int start = System.Environment.TickCount; | |
97 | run_start = start; | |
98 | ||
99 | try { | |
100 | bot.Execute(); | |
101 | Thread.Sleep(5000); | |
102 | } catch (Exception e) { | |
103 | this.logger.Log(e); | |
104 | //ExitGame(); | |
105 | } | |
106 | ||
107 | int diff = System.Environment.TickCount - start; | |
108 | ||
109 | Game.Print(string.Format("Run took {0} seconds. Total Runs: {1}", diff / 1000, (gameCounter++))); | |
110 | Thread.Sleep(3000); | |
111 | } | |
112 | } | |
113 | } | |
114 | } |