-
Notifications
You must be signed in to change notification settings - Fork 0
/
frmGodville.cs
1234 lines (1091 loc) · 35.4 KB
/
frmGodville.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.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net;
using System.Drawing.Imaging;
namespace GodvilleAutoPlayer
{
public partial class frmGodville : Form
{
// Setup some timers, globals, and place holder objects
System.Windows.Forms.Timer _timer = new Timer();
Hero hero = new Hero();
Hero oldHero = new Hero();
bool isSmall = true;
string godName = "";
string godPassword = "";
Size panelSize = new Size();
Size formSize = new Size();
Point formLocation = new Point();
HtmlElement lnkEncourage;
HtmlElement lnkPunish;
HtmlElement lnkRestoreGodPower;
HtmlElement lnkSendToArena;
HtmlElement lnkMakeMiracle;
HtmlElement lnkChallengeFriend;
public frmGodville()
{
InitializeComponent();
InitializeForm();
webBrowser1.ScriptErrorsSuppressed = true;
Microsoft.Win32.RegistryKey key = null;
try
{
string appName = System.AppDomain.CurrentDomain.FriendlyName;
//// This may only be needed for WinXP...
//// Reference: http://msdn.microsoft.com/en-us/library/ee330730(v=vs.85).aspx
//// Force internal IE Browser to display in IE8 Standards mode, 8888h or 34952 (DWORD)
//key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EMULATION", true);
//if (key != null)
//{
// if (key.GetValue(appName) == null)
// {
// key.SetValue(appName, 34952);
// }
// key.Close();
//}
}
catch (Exception ex)
{
if (key != null)
key.Close();
}
panelSize = pnlMain.Size;
formSize = this.Size;
}
private void frmGodville_Load(object sender, EventArgs e)
{
lblHero.Text = "";
lblEncourage.Visible = false;
lblPunish.Visible = false;
pnlMain.Visible = false;
pnlLogin.Location = new Point(0, 0);
}
private void btnLogIn_Click(object sender, EventArgs e)
{
godName = tbxGodName.Text;
godPassword = tbxGodPassword.Text;
webBrowser1.Navigate("http://www.godvillegame.com");
_timer.Interval = 5 * 1000;
_timer.Stop();
_timer.Enabled = false;
}
private void frmGodville_Resize(object sender, EventArgs e)
{
if (this.WindowState.Equals(FormWindowState.Maximized))
{
this.WindowState = FormWindowState.Normal;
showHideIE();
}
else if (this.WindowState.Equals(FormWindowState.Minimized))
{
this.WindowState = FormWindowState.Normal;
showHideIE();
}
}
void _timer_Tick(object sender, EventArgs e)
{
// The timer should only be active on the superhero page
try
{
switch (webBrowser1.Document.Url.ToString())
{
case "http://godvillegame.com/superhero":
case "http://godvillegame.com/superhero/":
heroUpdates();
break;
}
}
catch (Exception ex)
{
if (ex.ToString().IndexOf("WebBrowser") < 0)
{
MessageBox.Show(ex.ToString());
throw;
}
}
}
private void webBrowser1_DocumentCompleted(object sender, EventArgs e)
{
// Decide where to go based on URL
switch (webBrowser1.Document.Url.ToString())
{
case "http://godvillegame.com/":
case "http://godvillegame.com/login":
case "http://godvillegame.com/login/":
case "http://godvillegame.com/login/login":
welcome();
break;
case "http://godvillegame.com/searching":
case "http://godvillegame.com/searching/":
this.Text = webBrowser1.DocumentTitle + " Searching...";
break;
case "http://godvillegame.com/superhero":
case "http://godvillegame.com/superhero/":
heroUpdates();
//if (_timer.Enabled == false)
//{
// _timer.Tick += new EventHandler(_timer_Tick);
// _timer.Enabled = true;
// _timer.Start();
//}
break;
}
}
private void lblEncourage_Click(object sender, EventArgs e)
{
if (webBrowser1.Document != null)
{
if (lnkEncourage != null)
lnkEncourage.InvokeMember("click");
}
}
private void lblPunish_Click(object sender, EventArgs e)
{
if (webBrowser1.Document != null)
{
if (lnkPunish != null)
lnkPunish.InvokeMember("click");
}
}
private void lblDiary_Click(object sender, EventArgs e)
{
frmDiary form = new frmDiary();
form.HeroName = hero.Name;
form.Show();
}
private void lblRules_Click(object sender, EventArgs e)
{
frmRules form = new frmRules();
form.HeroName = hero.Name;
form.Show();
}
private void welcome()
{
// Attempt to log the user into the game
bool errorOnLogin = false;
HtmlElement username = null;
HtmlElement password = null;
HtmlElement commit = null;
if (webBrowser1.Document != null)
{
foreach (HtmlElement divError in webBrowser1.Document.GetElementsByTagName("DIV"))
{
if (divError.ClassName() == "error")
{
if (!String.IsNullOrEmpty(divError.InnerHtml))
errorOnLogin = true;
break;
}
}
// Check for the error div and deal with it
// TODO: A new Captcha has been added that has not been addressed!
if (!errorOnLogin)
{
HtmlElementCollection elems = webBrowser1.Document.GetElementsByTagName("INPUT");
username = webBrowser1.Document.GetElementById("username");
password = webBrowser1.Document.GetElementById("password");
username.SetAttribute("value", godName);
password.SetAttribute("value", godPassword);
commit = elems[3];
commit.InvokeMember("click");
pnlMain.Visible = true;
pnlLogin.Visible = false;
this.MaximizeBox = true;
}
else
{
this.Text = "Godville: Error logging in...";
pnlLogin.Visible = true;
pnlMain.Visible = false;
this.MaximizeBox = false;
}
lblEncourage.Visible = pnlMain.Visible;
lblPunish.Visible = pnlMain.Visible;
}
}
private void getTurboLight(string Url)
{
// TODO: The turbo light was changed from an image to an HTML element
try
{
WebRequest req = WebRequest.Create(Url);
WebResponse response = req.GetResponse();
Stream stream = response.GetResponseStream();
Image img = Image.FromStream(stream);
if (img != null)
{
//picTurbo.Image = img;
//this.Icon = Icon.FromHandle(new Bitmap(picTurbo.Image).GetHicon());
using (Bitmap large = new Bitmap(16, 16, PixelFormat.Format32bppArgb))
{
using (Graphics largeGraphics = Graphics.FromImage(large))
{
largeGraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
largeGraphics.DrawEllipse(new Pen(Color.White, 2.0f), 1, 1, 12, 11);
largeGraphics.DrawImage(img, 2, 2);
}
this.Icon = Icon.FromHandle(large.GetHicon());
}
}
stream.Close();
}
catch (Exception)
{
MessageBox.Show("There was a problem downloading the file");
}
}
private void heroUpdates()
{
// Stop the timer while updates are being parsed
bool statsAndInfoLoaded = false;
_timer.Stop();
_timer.Enabled = false;
try
{
if (webBrowser1.Document != null)
{
if (isSmall)
{
lblEncourage.Visible = true;
lblPunish.Visible = true;
}
else
{
lblEncourage.Visible = false;
lblPunish.Visible = false;
}
// Try to make sure the whole page is loaded... there is probably a much better way,
// but this seems to work for the most part.
if (webBrowser1.Document.Body.InnerHtml.IndexOf("Remote Control", StringComparison.InvariantCultureIgnoreCase) > 0
& webBrowser1.Document.Body.InnerHtml.IndexOf("Hero's Diary", StringComparison.InvariantCultureIgnoreCase) > 0
)
{
//GetTurboLight(webBrowser1.Document.All["turbo_icon"].GetAttribute("class"));
int start = webBrowser1.Document.Body.InnerHtml.IndexOf("Greetings, ", StringComparison.InvariantCultureIgnoreCase) + 11;
int end = webBrowser1.Document.Body.InnerHtml.IndexOf("</b>", start, StringComparison.InvariantCultureIgnoreCase) - 1;
hero.GodName = webBrowser1.Document.Body.InnerHtml.Substring(start, end - start);
foreach (HtmlElement item in webBrowser1.Document.GetElementsByTagName("DIV"))
{
if (item.ClassName() == "gp_val")
{
hero.GodPower = int.Parse(item.InnerText.Replace("%", "").Replace("Nan", "0"));
break;
}
}
foreach (HtmlElement tag in webBrowser1.Document.GetElementsByTagName("SPAN"))
{
if (tag.InnerText != null)
{
if (tag.InnerText.Equals("Encourage", StringComparison.InvariantCultureIgnoreCase))
{
lnkEncourage = tag;
lblEncourage.Enabled = true;
}
else if (tag.InnerText.Equals("Punish", StringComparison.InvariantCultureIgnoreCase))
{
lnkPunish = tag;
lblPunish.Enabled = true;
}
else if (tag.InnerText.Equals("Restore", StringComparison.InvariantCultureIgnoreCase))
{
lnkRestoreGodPower = tag;
}
else if (tag.InnerText.Equals("Send to Arena", StringComparison.InvariantCultureIgnoreCase))
{
lnkSendToArena = tag;
}
else if (tag.InnerText.Equals("Make a Miracle", StringComparison.InvariantCultureIgnoreCase))
{
lnkMakeMiracle = tag;
}
else if (tag.InnerText.Equals("Challenge Friend", StringComparison.InvariantCultureIgnoreCase))
{
lnkChallengeFriend = tag;
}
if (tag.ClassName() == "acc_val")
{
hero.Charges = int.Parse((tag.InnerText ?? "").Trim() == "" ? "0" : tag.InnerText);
}
}
}
statsAndInfoLoaded = heroInfo();
petInfo();
Application.DoEvents();
pantheonStatus();
Application.DoEvents();
earthlyNews();
Application.DoEvents();
heroDiary();
Application.DoEvents();
heroInventory();
Application.DoEvents();
heroEquipment();
Application.DoEvents();
heroSkills();
Application.DoEvents();
if (statsAndInfoLoaded)
{
// Update the miniature Summary UI
if (!String.IsNullOrEmpty(hero.TownName))
this.Text = String.Format("Godville: {0} - {1} ({2})", hero.GodName, hero.Name, hero.TownName);
else
this.Text = String.Format("Godville: {0} - {1} (Adventuring)", hero.GodName, hero.Name);
lblHero.Text = String.Format("H: {0}% GP: {1}% G: {2} coins Q: {3}% Mi: {4}", (hero.Health * 100 / hero.MaxHealth), hero.GodPower, hero.Gold, hero.QuestPercent, hero.MilestonesPassed);
lblHero.Refresh();
lblDiary.Enabled = true;
lblRules.Enabled = true;
Application.DoEvents();
// If the hero has any updated info, then update the db and clone the current copy
if (!hero.compare(oldHero))
{
oldHero = hero.clone();
hero.saveHero();
}
executeRules();
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
throw;
}
finally
{
// Start the timer backup. If the stats have not been loaded,
// then the page is still loading via AJAX, so keep the timer going
// at 5 seconds, otherwise switch to 30 seconds
if (!_timer.Enabled)
{
_timer.Enabled = true;
_timer.Tick += new EventHandler(_timer_Tick);
_timer.Interval = (statsAndInfoLoaded ? 30 : 5) * 1000;
_timer.Start();
}
}
}
private bool heroInfo()
{
try
{
// Parse the basic Hero info details
hero.Name = webBrowser1.Document.GetElementById("hk_name").Children[1].Children[0].InnerText;
// Grab the latest hero entry from the db to setup hero comparisons
if (String.IsNullOrEmpty(oldHero.Name))
oldHero.getHero(hero.Name);
syncDiaryAndNews();
hero.Motto = webBrowser1.Document.GetElementById("hk_motto").Children[1].InnerText;
hero.Personality = webBrowser1.Document.GetElementById("hk_alignment").Children[1].InnerText;
HtmlElement elem = webBrowser1.Document.GetElementById("hk_clan");
hero.Guild = elem.Children[1].Children[0].InnerText;
hero.GuildRank = elem.Children[1].InnerText.Split('(')[1].Replace(")", "");
elem = webBrowser1.Document.GetElementById("hk_level");
hero.Level = int.Parse(elem.Children[1].InnerText);
hero.LevelPercent = int.Parse(elem.Children[2].Title().Replace("%", ""));
elem = webBrowser1.Document.GetElementById("hk_inventory_num");
hero.Inventory = int.Parse(elem.Children[1].InnerText.Split('/')[0].Trim());
hero.MaxInventory = int.Parse(elem.Children[1].InnerText.Split('/')[1].Trim());
elem = webBrowser1.Document.GetElementById("hk_health");
hero.Health = int.Parse(elem.Children[1].InnerText.Split('/')[0].Trim());
hero.MaxHealth = int.Parse(elem.Children[1].InnerText.Split('/')[1].Trim());
elem = webBrowser1.Document.GetElementById("hk_quests_completed");
hero.Quest = elem.Children[2].InnerText;
hero.QuestNumber = int.Parse(elem.Children[1].InnerText.Replace("#", ""));
hero.QuestPercent = int.Parse(elem.Children[3].Title().Replace("%", ""));
hero.Gold = int.Parse(webBrowser1.Document.GetElementById("hk_gold_we").Children[1].InnerText.Replace("coins", ""));
hero.MonstersKilled = int.Parse(webBrowser1.Document.GetElementById("hk_monsters_killed").Children[1].InnerText);
hero.DeathCount = int.Parse(webBrowser1.Document.GetElementById("hk_death_count").Children[1].InnerText);
elem = webBrowser1.Document.GetElementById("hk_arena_won");
hero.Wins = int.Parse(elem.Children[1].InnerText.Split('/')[0].Trim());
hero.Losses = int.Parse(elem.Children[1].InnerText.Split('/')[1].Trim());
hero.Bricks = webBrowser1.Document.GetElementById("hk_bricks_cnt").Children[1].InnerText;
if (isInteger(webBrowser1.Document.GetElementById("hk_distance").Children[1].InnerText))
{
hero.MilestonesPassed = int.Parse(webBrowser1.Document.GetElementById("hk_distance").Children[1].InnerText);
}
else
{
hero.TownName = webBrowser1.Document.GetElementById("hk_distance").Children[1].InnerText;
}
elem = webBrowser1.Document.GetElementById("stats");
foreach (HtmlElement child in elem.Children[1].Children)
{
if ((child.InnerHtml ?? "").ToLower().IndexOf("aura</div>") > 0)
{
if (!String.IsNullOrEmpty(child.Children[1].InnerText))
{
hero.Aura = child.Children[1].InnerText.Split('(')[0].Trim();
hero.AuraDuration = child.Children[1].InnerText.Split('(')[1].Replace(")", "").Trim();
}
}
}
// Not sure what this tag is...
//hero.Retirement = webBrowser1.Document.GetElementById("hk_level").Children[1].InnerText;
return true;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
throw;
}
}
private bool petInfo()
{
// Parse the Pet info (if there is one)
try
{
HtmlElement elem = webBrowser1.Document.GetElementById("pet");
if (elem != null)
{
if (elem.Children.Count > 1)
{
hero.PetName = elem.Children[1].Children[0].Children[1].InnerText.Split(' ')[0].Trim();
hero.PetPersonality = elem.Children[1].Children[0].Children[1].InnerText.Split(' ')[1].Trim();
hero.PetSpecies = elem.Children[1].Children[1].Children[1].Children[0].InnerText.Trim();
hero.PetLevel = elem.Children[1].Children[2].Children[1].InnerText.Trim();
hero.PetAge = elem.Children[1].Children[3].Children[1].InnerText.Trim();
hero.PetStatus = (elem.Children[1].Children[4].Children[1].InnerText ?? "").Trim();
}
}
return true;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
throw;
}
}
private bool pantheonStatus()
{
// Parse any Pantheon info
try
{
HtmlElement elem = webBrowser1.Document.GetElementById("pantheons");
if (elem != null)
{
if (elem.Children.Count > 1)
{
int startBlock = 2;
if (elem.Children[1].Children[1].ClassName() == "p_group p_group_sep")
startBlock = 1;
for (int i = startBlock; i < elem.Children[1].Children.Count; i++)
{
for (int j = 0; j < elem.Children[1].Children[i].Children.Count; j++)
{
string pantheon = elem.Children[1].Children[i].Children[j].Children[0].InnerText;
string val = elem.Children[1].Children[i].Children[j].Children[2].InnerText.Trim();
if (!isInteger(val))
val = "0";
int iVal = int.Parse(val);
switch (pantheon)
{
case "Gratitude":
hero.Gratitude = iVal;
break;
case "Might":
hero.Might = iVal;
break;
case "Templehood":
hero.Templehood = iVal;
break;
case "Gladiatorship":
hero.Gladiatorship = iVal;
break;
case "Storytelling":
hero.Storytelling = iVal;
break;
case "Mastery":
hero.Mastery = iVal;
break;
case "Construction":
hero.Construction = iVal;
break;
case "Taming":
hero.Taming = iVal;
break;
case "Survival":
hero.Survival = iVal;
break;
case "Greed":
hero.Greed = iVal;
break;
case "Creation":
hero.Creation = iVal;
break;
case "Destruction":
hero.Destruction = iVal;
break;
case "Unity":
hero.Unity = iVal;
break;
case "Popularity":
hero.Popularity = iVal;
break;
case "Aggressiveness":
hero.Aggressiveness = iVal;
break;
}
}
}
}
}
return true;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
throw;
}
}
private bool earthlyNews()
{
// Parse the rotating Earthly News section
try
{
HtmlElement elem = webBrowser1.Document.GetElementById("news");
if (elem != null)
{
if (elem.Children.Count > 1)
{
bool itemAdded = false;
HtmlElementCollection items = elem.Children[1].Children[0].Children;
HeroDetailsEntry details = new HeroDetailsEntry();
details.TopMessage = items[0].Children[0].InnerText;
details.Enemy = items[0].Children[1].InnerText;
string progress = items[0].Children[2].Title().Replace("%", "").Replace("NaN", "0");
details.Progress = int.Parse(progress);
details.BottomMessage = items[1].InnerText;
progress = items[2].Title().Replace("%", "").Replace("NaN", "0");
details.Progress2 = int.Parse(progress);
itemAdded = true;
if (itemAdded)
{
if (!hero.DetailsEntries.Contains(details))
{
hero.DetailsEntries.Add(details);
hero.saveDetailEntry(details);
}
}
if (hero.DetailsEntries.Count > 0)
tbxNews.Text = String.Format("{0}\r\n{1}",
String.IsNullOrEmpty(hero.DetailsEntries[hero.DetailsEntries.Count - 1].Enemy) ?
hero.DetailsEntries[hero.DetailsEntries.Count - 1].TopMessage :
hero.DetailsEntries[hero.DetailsEntries.Count - 1].Enemy,
hero.DetailsEntries[hero.DetailsEntries.Count - 1].BottomMessage);
}
}
return true;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
throw;
}
}
private bool heroDiary()
{
// Parse the Hero's diary
bool newestAtTop = false;
try
{
HtmlElement elem = webBrowser1.Document.GetElementById("news");
if (elem != null)
{
if (elem.Children.Count > 1)
{
HtmlElementCollection spans = webBrowser1.Document.GetElementsByTagName("SPAN");
foreach (HtmlElement span in spans)
{
if (span.Title().Equals("Change diary sort order", StringComparison.InvariantCultureIgnoreCase))
{
string temp = span.InnerText;
newestAtTop = (temp == "▼");
break;
}
}
HtmlElementCollection items = webBrowser1.Document.GetElementById("diary").Children[1].Children[0].Children[0].Children;
bool itemAdded = false;
int insertionPoint = hero.DiaryEntries.Count;
foreach (HtmlElement item in items)
{
HeroDiaryEntry entry = new HeroDiaryEntry();
entry.TimeStamp =item.Children[0].InnerText;
entry.Content = item.Children[1].InnerText;
entry.Saved = true;
if (!hero.DiaryEntries.Contains(entry))
{
entry.Saved = false;
if (newestAtTop)
hero.DiaryEntries.Insert(insertionPoint, entry);
else
hero.DiaryEntries.Add(entry);
itemAdded = true;
}
}
if (itemAdded)
{
for (int i = 0; i < hero.DiaryEntries.Count; i++)
{
HeroDiaryEntry diaryItem = hero.DiaryEntries[i];
if (!diaryItem.Saved)
{
hero.saveDiaryEntry(diaryItem);
diaryItem.Saved = true;
hero.DiaryEntries[i] = diaryItem;
}
}
}
if (hero.DiaryEntries.Count > 0)
tbxDiary.Text = hero.DiaryEntries[hero.DiaryEntries.Count - 1].Content;
}
}
return true;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
throw;
}
}
private bool heroInventory()
{
// Parse the Hero's inventory and as a List and later store as | delimited
try
{
HtmlElement elem = webBrowser1.Document.GetElementById("inv_block_content");
if (elem != null)
{
if (elem.Children.Count > 1)
{
hero.InventoryItems.Clear();
foreach (HtmlElement li in elem.Children[1].Children)
{
hero.InventoryItems.Add(li.InnerText);
}
}
}
return true;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
throw;
}
}
private bool heroEquipment()
{
// Parse the Hero's Equipment
try
{
HtmlElement elem = webBrowser1.Document.GetElementById("equipment");
if (elem != null)
{
if (elem.Children.Count > 1)
{
for (int i = 0; i < elem.Children[1].Children.Count; i++)
{
if (elem.Children[1].Children[i].Children.Count > 1)
{
string type = elem.Children[1].Children[i].Children[0].InnerText;
string level = elem.Children[1].Children[i].Children[1].InnerText;
string name = elem.Children[1].Children[i].Children[2].InnerText;
string formatted = String.Format("{0} ({1})", name, level);
switch (type)
{
case "Weapon":
hero.Weapon = formatted;
break;
case "Shield":
hero.Shield = formatted;
break;
case "Head":
hero.Head = formatted;
break;
case "Body":
hero.Body = formatted;
break;
case "Arms":
hero.Arms = formatted;
break;
case "Legs":
hero.Legs = formatted;
break;
case "Talisman":
hero.Talisman = formatted;
break;
}
}
}
}
}
return true;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
throw;
}
}
private bool heroSkills()
{
try
{
// Parse the Hero's Skills and as a List and later store as | delimited
string skill = "";
HtmlElement elem = webBrowser1.Document.GetElementById("s_b_id");
if (elem != null)
{
if (elem.Children.Count > 1)
{
hero.Skills.Clear();
foreach (HtmlElement li in elem.Children[1].Children)
{
skill = String.Format("{0} - {1}", li.Children[0].InnerText, li.Children[1].InnerText);
hero.Skills.Add(skill);
}
}
}
return true;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
throw;
}
}
private void syncDiaryAndNews()
{
// Sync the existing diary entries from the Old Hero to the current hero
if (hero.DiaryEntries.Count == 0)
{
foreach (HeroDiaryEntry oldEntry in oldHero.DiaryEntries)
{
HeroDiaryEntry newEntry = new HeroDiaryEntry();
newEntry.Content = oldEntry.Content;
newEntry.Saved = true;
newEntry.TimeStamp = oldEntry.TimeStamp;
hero.DiaryEntries.Add(newEntry);
}
}
}
private void executeRules()
{
hero.executeRules(lnkEncourage, lnkPunish);
}
private void showHideIE()
{
// Normally the default frame is very small, and only shows the abbreviated
// stats and the recent updates. Maximising will show different summary
// and also enlarge IE to be visible.
if (isSmall)
{
formLocation = this.Location;
this.Location = new Point(this.Location.X, 10);
isSmall = !isSmall;
this.MinimizeBox = true;
this.MaximizeBox = false;
this.FormBorderStyle = FormBorderStyle.Sizable;
this.Size = new Size(1000, 800);
pnlMain.Size = new Size(74, 20);
webBrowser1.Dock = DockStyle.Fill;
pnlMain.Visible = false;
lblEncourage.Visible = pnlMain.Visible;
lblPunish.Visible = pnlMain.Visible;
}
else
{
isSmall = !isSmall;
this.MinimizeBox = false;
this.MaximizeBox = true;
this.FormBorderStyle = FormBorderStyle.FixedSingle;
this.Size = formSize; //new Size(283, 47);
pnlMain.Size = panelSize; // new Size(277, 20);
this.Location = formLocation;
webBrowser1.Dock = DockStyle.None;
webBrowser1.Location = new Point(2, 27);
webBrowser1.Size = new Size(75, 20);
pnlMain.Visible = true;
lblEncourage.Visible = pnlMain.Visible;
lblPunish.Visible = pnlMain.Visible;
}
}
private void showHand(object sender, EventArgs e)
{
this.Cursor = Cursors.Hand;
}
private void resetHand(object sender, EventArgs e)
{
this.Cursor = Cursors.Default;
}
private bool isInteger(string input)
{
int results = 0;
bool isInt = false;
isInt = int.TryParse(input, out results);
return isInt;
}
#region WebBrowser and Support
// Updates the URL in TextBoxAddress upon navigation.
private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
{
toolStripTextBox1.Text = webBrowser1.Url.ToString();
}
// Displays the Save dialog box.
private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
{
webBrowser1.ShowSaveAsDialog();
}
// Displays the Page Setup dialog box.
private void pageSetupToolStripMenuItem_Click(object sender, EventArgs e)
{
webBrowser1.ShowPageSetupDialog();
}
// Displays the Print dialog box.
private void printToolStripMenuItem_Click(object sender, EventArgs e)
{
webBrowser1.ShowPrintDialog();
}
// Displays the Print Preview dialog box.
private void printPreviewToolStripMenuItem_Click(
object sender, EventArgs e)
{
webBrowser1.ShowPrintPreviewDialog();
}
// Displays the Properties dialog box.
private void propertiesToolStripMenuItem_Click(
object sender, EventArgs e)
{
webBrowser1.ShowPropertiesDialog();
}
// Selects all the text in the text box when the user clicks it.
private void toolStripTextBox1_Click(object sender, EventArgs e)
{
toolStripTextBox1.SelectAll();
}
// Navigates to the URL in the address box when
// the ENTER key is pressed while the ToolStripTextBox has focus.
private void toolStripTextBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
Navigate(toolStripTextBox1.Text);
}
}
// Navigates to the URL in the address box when
// the Go button is clicked.
private void goButton_Click(object sender, EventArgs e)
{
Navigate(toolStripTextBox1.Text);
}
// Navigates to the given URL if it is valid.
private void Navigate(String address)
{
if (String.IsNullOrEmpty(address)) return;
if (address.Equals("about:blank")) return;
if (!address.StartsWith("http://") &&