Skip to content

Commit fedbd2d

Browse files
committed
Backend changes.
Should be pretty more spiffy now.
1 parent fec92ba commit fedbd2d

File tree

7 files changed

+126
-89
lines changed

7 files changed

+126
-89
lines changed

GrandHeroFarmer/Grand Hero Farmer.csproj

+3-4
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@
5252
<Reference Include="System.Xml" />
5353
</ItemGroup>
5454
<ItemGroup>
55-
<Compile Include="Helpers\Android.cs" />
56-
<Compile Include="Helpers\ConsoleLogger.cs" />
55+
<Compile Include="Modules\Android.cs" />
56+
<Compile Include="Modules\ConsoleLogger.cs" />
57+
<Compile Include="Modules\Helpers.cs" />
5758
<Compile Include="Program.cs" />
5859
<Compile Include="Properties\AssemblyInfo.cs" />
5960
<Compile Include="Properties\Resources.Designer.cs">
@@ -71,9 +72,7 @@
7172
<Content Include="Configurations\Default.xml">
7273
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
7374
</Content>
74-
<Content Include="razz-berry.ico" />
7575
<None Include="Resources\razz-berry.ico" />
76-
<None Include="Resources\Icon.ico" />
7776
</ItemGroup>
7877
<ItemGroup>
7978
<Folder Include="adb\" />

GrandHeroFarmer/Helpers/ConsoleLogger.cs

-47
This file was deleted.

GrandHeroFarmer/Helpers/Android.cs GrandHeroFarmer/Modules/Android.cs

+12-12
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
using System.Threading.Tasks;
99
using System.Xml.Linq;
1010

11-
namespace GrandHeroFarmer.Helpers
11+
namespace GrandHeroFarmer.Modules
1212
{
1313
public class Android
1414
{
@@ -29,9 +29,9 @@ public Android()
2929
}
3030
else
3131
{
32-
ConsoleLogger.Write("adb.exe not found. ", Type.Error, true);
33-
ConsoleLogger.WriteLine("Did you extract everything from the zip?", Type.Default, false);
34-
ConsoleLogger.WriteLine("Press Enter to exit.", Type.Default, true);
32+
ConsoleLogger.Write("adb.exe not found. ", textColor: ConsoleColor.Red);
33+
ConsoleLogger.Write("Did you extract everything from the zip?");
34+
ConsoleLogger.Write("Press Enter to exit.");
3535

3636
Console.ReadLine();
3737
Environment.Exit(0);
@@ -46,19 +46,19 @@ private void ConnectToAndroid()
4646
bool foundDevice = false;
4747
while (!foundDevice)
4848
{
49-
ConsoleLogger.Write("Trying to get device information... ", Type.Default);
49+
ConsoleLogger.WriteTime("Trying to get device information... ", false);
5050
if(AdbClient.Instance.GetDevices().Count != 0)
5151
{
5252

5353
_device = AdbClient.Instance.GetDevices().First();
5454
foundDevice = true;
55-
ConsoleLogger.WriteLine(_device.Name + " connected!", Type.Info, false);
55+
ConsoleLogger.Write(_device.Name + " connected!", textColor: ConsoleColor.Cyan);
5656
return;
5757
}
58-
ConsoleLogger.WriteLine("Failed! No Device was found!", Type.Error, false);
59-
ConsoleLogger.Write("Check the connection and press", Type.Default);
60-
ConsoleLogger.Write(" Enter ", Type.Info, false);
61-
ConsoleLogger.Write("to try again.", Type.Default, false);
58+
ConsoleLogger.Write("Failed! No Device was found!", textColor: ConsoleColor.Red);
59+
ConsoleLogger.WriteTime("Check the connection and press", false);
60+
ConsoleLogger.Write(" Enter ", false, ConsoleColor.Cyan);
61+
ConsoleLogger.Write("to try again.");
6262
Console.ReadLine();
6363
}
6464
}
@@ -80,8 +80,8 @@ public void Tap(Tuple<int, int> coordenates)
8080
// Monitor Functions
8181
void OnDeviceDisconnected(object sender, DeviceDataEventArgs e)
8282
{
83-
ConsoleLogger.WriteLine("The device " + _device.Name +" has disconnected to this PC", Type.Error);
84-
ConsoleLogger.WriteLine("Please restart the application and go back to the Mission Select Menu.", Type.Default);
83+
ConsoleLogger.WriteTime("The device " + _device.Name +" has disconnected to this PC", textColor: ConsoleColor.Red);
84+
ConsoleLogger.WriteTime("Please restart the application and go back to the Mission Select Menu.");
8585
ConnectToAndroid();
8686
}
8787
}
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace GrandHeroFarmer.Modules
8+
{
9+
enum Type { Info = ConsoleColor.Cyan, Error = ConsoleColor.Red, Default = ConsoleColor.Gray };
10+
11+
static class ConsoleLogger
12+
{
13+
public static void Write(string value, bool newLine = true, ConsoleColor textColor = ConsoleColor.Gray, ConsoleColor backgroundColor = ConsoleColor.Black)
14+
{
15+
Console.ForegroundColor = textColor;
16+
Console.BackgroundColor = backgroundColor;
17+
Console.Write(value);
18+
Console.ResetColor();
19+
20+
if (newLine)
21+
{
22+
Console.WriteLine();
23+
}
24+
}
25+
26+
public static void WriteTime(string value, bool newLine = true, ConsoleColor textColor = ConsoleColor.Gray, ConsoleColor backgroundColor = ConsoleColor.Black)
27+
{
28+
string timeLog = DateTime.UtcNow.ToString("[HH:mm:ss] >> ");
29+
30+
Console.Write(timeLog);
31+
Write(value, newLine, textColor, backgroundColor);
32+
}
33+
34+
public static void WriteCenter(string value, bool newLine = true, ConsoleColor textColor = ConsoleColor.Gray, ConsoleColor backgroundColor = ConsoleColor.Black)
35+
{
36+
Console.SetCursorPosition((Console.WindowWidth - value.Length) / 2, Console.CursorTop);
37+
38+
Write(value, newLine, textColor, backgroundColor);
39+
}
40+
41+
}
42+
}

GrandHeroFarmer/Modules/Helpers.cs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace GrandHeroFarmer.Modules
9+
{
10+
static class Helpers
11+
{
12+
13+
public static string GetProgramVersion()
14+
{
15+
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
16+
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
17+
18+
return fvi.FileVersion;
19+
}
20+
}
21+
}

GrandHeroFarmer/Program.cs

+46-24
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
using GrandHeroFarmer.Helpers;
1+
using GrandHeroFarmer.Modules;
22
using SharpAdbClient;
33
using System;
44
using System.Collections.Generic;
5+
using System.Diagnostics;
56
using System.Linq;
67
using System.Text;
78
using System.Threading;
@@ -13,15 +14,35 @@ namespace GrandHeroFarmer
1314
{
1415
class Program
1516
{
17+
private static readonly List<string> puns = new List<string>
18+
{
19+
"Just for feathers and love",
20+
"Just one more +10 and I'm done",
21+
"We need more Armads in the game",
22+
"Just Tiki.",
23+
"r/OrderOfHeroes is pretty neat",
24+
"/feg/ is cozy sometimes"
25+
};
26+
27+
public static readonly Random rnd = new Random();
28+
1629
static void Main(string[] args)
1730
{
18-
ConsoleLogger.WriteLine("Welcome to Feh Farmer", Helpers.Type.Info, true, ConsoleColor.DarkCyan);
31+
Console.Title = "Grand Hero Farmer v" + Helpers.GetProgramVersion();
32+
Console.Clear();
33+
34+
Console.WriteLine();
35+
ConsoleLogger.WriteCenter("Grand Hero Farmer", textColor: ConsoleColor.Cyan, backgroundColor: ConsoleColor.DarkCyan);
36+
37+
ConsoleLogger.WriteCenter(puns[rnd.Next(puns.Count)], true, textColor: ConsoleColor.Magenta);
38+
39+
ConsoleLogger.WriteTime("Starting program...");
1940
try
2041
{
2142
Android phone = new Android();
2243

2344
//Initializing Service Configurations
24-
ConsoleLogger.Write("Loading service configurations from xml... ", Helpers.Type.Default);
45+
ConsoleLogger.WriteTime("Loading service configurations from xml... ", false);
2546
XDocument doc = XDocument.Load("Configurations/Default.xml");
2647
ClickArea startGBHButton = new ClickArea(doc.Descendants("StartGHBButton").FirstOrDefault());
2748
ClickArea fightButton = new ClickArea(doc.Descendants("FightButton").FirstOrDefault());
@@ -31,21 +52,23 @@ static void Main(string[] args)
3152

3253
int communicateServerTimer = ((int)(doc.Descendants("CommunicateServerTimer").FirstOrDefault()) * 1000);
3354
int stageTimer = ((int)(doc.Descendants("StageTimer").FirstOrDefault()) * 1000);
55+
ConsoleLogger.Write("OK", textColor: ConsoleColor.Cyan);
3456

35-
ConsoleLogger.WriteLine("OK", Helpers.Type.Info, false);
36-
37-
ConsoleLogger.WriteLine("Setup is done, press enter to start earning feathers.", Helpers.Type.Info);
38-
ConsoleLogger.Write("Press 'Ctrl + C' to exit the application.", Helpers.Type.Info);
57+
ConsoleLogger.WriteTime("Setup is done, press enter to start earning feathers.", textColor: ConsoleColor.Cyan);
58+
ConsoleLogger.WriteTime("Press 'Ctrl + C' to exit the application.", newLine: false, textColor: ConsoleColor.Cyan);
3959
Console.ReadLine();
4060

41-
int iterations = 1;
61+
int cicles = 1;
4262

4363
Thread thread = new Thread(() => {
64+
65+
Console.Title = "Grand Hero Farmer - Farming";
66+
4467
while (true)
4568
{
4669
Console.WriteLine();
47-
ConsoleLogger.Write("Starting iteration ", Helpers.Type.Default, true);
48-
ConsoleLogger.WriteLine(iterations.ToString(), Helpers.Type.Info, false);
70+
ConsoleLogger.WriteTime("Starting cicle ", false);
71+
ConsoleLogger.Write("[" + cicles.ToString() + "]", textColor: ConsoleColor.Cyan);
4972

5073
// Click Lunatic Button
5174
phone.Tap(startGBHButton.GenerateRandomCoords());
@@ -63,53 +86,52 @@ static void Main(string[] args)
6386
Thread.Sleep(2000);
6487

6588
// Skip Dialog
66-
ConsoleLogger.WriteLine("Skipping initial dialog", Helpers.Type.Default);
89+
ConsoleLogger.WriteTime("Skipping initial dialog");
6790
phone.Tap(skipDialogButton.GenerateRandomCoords());
6891

6992
// Wait for initial animations
7093
Thread.Sleep(3000);
7194

7295
// Click Auto Battle
73-
ConsoleLogger.WriteLine("Initializing Auto-Battle", Helpers.Type.Default);
96+
ConsoleLogger.WriteTime("Initializing Auto-Battle");
7497
phone.Tap(autoBattleButton.GenerateRandomCoords());
7598

7699
// CLick Accept
77100
phone.Tap(acceptAutoBattleButton.GenerateRandomCoords());
78101

79102
// Wait for battle to end
80-
ConsoleLogger.WriteLine("Waiting for battle to end", Helpers.Type.Default);
103+
ConsoleLogger.WriteTime("Waiting for battle to end");
81104
Thread.Sleep(stageTimer);
82105

83106
// Click again to skip animations
84107
phone.Tap(fightButton.GenerateRandomCoords());
85108

109+
// All done!
110+
ConsoleLogger.WriteTime("Finished cicle ", false);
111+
ConsoleLogger.Write("[" + cicles.ToString() + "]", textColor: ConsoleColor.Cyan);
112+
86113
// Wait to send result to server
87114
Thread.Sleep(communicateServerTimer + 1000);
88115

89-
// All done!
90-
ConsoleLogger.Write("Finished iteration ", Helpers.Type.Default);
91-
ConsoleLogger.WriteLine(iterations.ToString(), Helpers.Type.Info, false);
92-
93-
iterations++;
116+
cicles++;
94117
}
95-
96118
});
97119
thread.Start();
98120

99121
}
100122
catch (System.IO.FileNotFoundException)
101123
{
102-
ConsoleLogger.WriteLine("FAILED", Helpers.Type.Error, false);
103-
ConsoleLogger.WriteLine("Couldn't Load XML File. Press Enter to exit the application.", Helpers.Type.Error, true);
124+
ConsoleLogger.Write("FAILED", textColor: ConsoleColor.Red);
125+
ConsoleLogger.WriteTime("Couldn't Load XML File. Press Enter to exit the application.");
104126
}
105127
catch (NullReferenceException)
106128
{
107-
ConsoleLogger.WriteLine("FAILED", Helpers.Type.Error, false);
108-
ConsoleLogger.WriteLine("Looks like your XML file is malformed. Press Enter to exit the application.", Helpers.Type.Error, true);
129+
ConsoleLogger.Write("FAILED", textColor: ConsoleColor.Red);
130+
ConsoleLogger.WriteTime("Looks like your XML file is malformed. Press Enter to exit the application.");
109131
}
110132
catch (Exception ex)
111133
{
112-
ConsoleLogger.WriteLine(ex.ToString(), Helpers.Type.Error, false);
134+
ConsoleLogger.Write(ex.ToString(), textColor: ConsoleColor.Red);
113135
}
114136
finally
115137
{

GrandHeroFarmer/Properties/AssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("0.0.2")]
36-
[assembly: AssemblyFileVersion("0.0.2")]
35+
[assembly: AssemblyVersion("0.1.0")]
36+
[assembly: AssemblyFileVersion("0.1.0")]

0 commit comments

Comments
 (0)