-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
2172 lines (1863 loc) · 83.6 KB
/
Form1.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.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Net.Mime.MediaTypeNames;
using System.IO;
using ClosedXML.Excel;
using CsvHelper;
using System.Globalization;
using CsvHelper.Configuration;
using DocumentFormat.OpenXml.Spreadsheet;
using System.Collections;
using System.Reflection;
using System.Diagnostics;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;
using DocumentFormat.OpenXml.Vml.Office;
using HeroForge_OnceAgain.Properties;
using DocumentFormat.OpenXml.InkML;
using Newtonsoft.Json;
using DocumentFormat.OpenXml.Office2010.ExcelAc;
using static HeroForge_OnceAgain.Form1;
using HeroForge_OnceAgain.Models;
using DocumentFormat.OpenXml.ExtendedProperties;
using DocumentFormat.OpenXml.Office2010.Excel;
using System.Resources;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window;
using HeroForge_OnceAgain.Utils;
using DocumentFormat.OpenXml.Math;
using System.Security.Cryptography;
using System.Net.Sockets;
using System.Windows.Interop;
using static System.Windows.Forms.AxHost;
using DocumentFormat.OpenXml.Presentation;
using System.Drawing.Printing;
using System.Runtime.Remoting.Messaging;
using DocumentFormat.OpenXml.Bibliography;
namespace HeroForge_OnceAgain
{
public partial class Form1 : Form
{
private Character character;
//private System.Windows.Forms.Button printButton = new System.Windows.Forms.Button();
private PrintDocument printDocument1 = new PrintDocument();
Bitmap memoryImage;
private Random random = new Random();
public Form1()
{
InitializeComponent();
// Inicialização do botão
btnRolar.Text = "Rolar dados";
btnRolar.Location = new System.Drawing.Point(500, 25); // Posição inicial
btnRolar.Size = new System.Drawing.Size(110, 50); // Tamanho inicial
this.Controls.Add(btnRolar); // Nome alterado
CharacterCreationInfo creationInfo = new CharacterCreationInfo();
character = new Character(creationInfo);
printDocument1.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage);
}
public void Form1_Load(object sender, EventArgs e)
{
if (workSheet == null)
workSheet = LoadFileFromResource();
//workSheet = LoadFile();
Reload();
RaceUtils.PopulateRaceComboBox(cbRaces, 3);
cbAlignment.SelectedIndex = 0;
cBAbilityScoreSystem.SelectedIndex = 0;
CheckedListBox checkede = ckListCharacterSheetDisplayHitPointOptions;
for (int i = 0; i < checkede.Items.Count; i++)
{
if (i.Equals(0))
{
checkede.SetItemCheckState(i, (true ? CheckState.Checked : CheckState.Unchecked));
}
}
LoadSupplementSources();
}
private void LoadSupplementSources()
{
// Caminho para a pasta de suplementos
string supplementsFolderPath = System.Windows.Forms.Application.StartupPath.Replace("\\bin\\Debug", "") + "\\Resources\\Supplements";
// Verifica se existem arquivos JSON na pasta
if (Directory.Exists(supplementsFolderPath))
{
string[] jsonFiles = Directory.GetFiles(supplementsFolderPath, "*.json");
if (jsonFiles.Length > 0)
{
// Carrega as fontes de suplementos da pasta
List<SupplementSource> sources = LoadSourcesFromFolder(supplementsFolderPath);
if (sources != null)
{
//if (listViewDragonLanceSources != null)
{
dataGridViewDragonLanceSources.AutoGenerateColumns = false;
dataGridViewDragonLanceSources.BackgroundColor = System.Drawing.Color.White; // Define o fundo branco
dataGridViewDragonLanceSources.DefaultCellStyle.BackColor = System.Drawing.Color.White; // Define a cor de fundo das células
dataGridViewDragonLanceSources.RowHeadersVisible = false; // Torna as linhas de grade invisíveis
// Adicione a coluna de checkboxes
DataGridViewCheckBoxColumn checkboxColumn = new DataGridViewCheckBoxColumn();
checkboxColumn.HeaderText = "";
checkboxColumn.Name = "CheckboxColumn";
checkboxColumn.Width = 20;
dataGridViewDragonLanceSources.RowsDefaultCellStyle.Font = new System.Drawing.Font("Microsoft Sans Serif", 8);
dataGridViewDragonLanceSources.Columns.Add(checkboxColumn);
dataGridViewDragonLanceSources.GridColor = dataGridViewDragonLanceSources.BackgroundColor;
// Adiciona uma coluna para exibir o campo "SupplementName"
DataGridViewTextBoxColumn supplementNameColumn = new DataGridViewTextBoxColumn();
supplementNameColumn.DataPropertyName = "SupplementName"; // O nome da propriedade no seu objeto de dados
supplementNameColumn.HeaderText = "Supplement Name"; // O cabeçalho da coluna
supplementNameColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
supplementNameColumn.ReadOnly = true;
dataGridViewDragonLanceSources.Columns.Add(supplementNameColumn);
// Remove os cabeçalhos de coluna
dataGridViewDragonLanceSources.ColumnHeadersVisible = false;
// Definindo a fonte de dados
dataGridViewDragonLanceSources.DataSource = sources;
//foreach (var source in sources)
//{
// ListViewItem item = new ListViewItem();
// item.Text = source.SupplementName;
// item.SubItems.Add(source.SupplementSourceAbbreviation);
// listViewDragonLanceSources.Items.Add(item);
//}
//listViewDragonLanceSources.Invalidate();
//DataTable dt = new DataTable();
//dt.Columns.Add(new DataColumn("column1"));
//DataRow row = dt.NewRow();
//dataGridView1.AutoGenerateColumns = false;
//dataGridView1.Columns.Add("Name", "Name");
//foreach (var item in sources)
//{
// //row[0] = item.SupplementName;
// dataGridView1.Rows.Add(item.SupplementName);
//}
//dt.Rows.Add(row);
//dataGridView1.DataSource = dt;
}
}
}
else
{
MessageBox.Show("Nenhum arquivo JSON encontrado na pasta de suplementos.", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
// Método para carregar as fontes de um arquivo JSON
public static List<SupplementSource> LoadFromJson(string filePath)
{
try
{
string jsonContent = File.ReadAllText(filePath);
// Deserializa o JSON para uma lista de SupplementSource
List<SupplementSource> sources = JsonConvert.DeserializeObject<List<SupplementSource>>(jsonContent);
return sources;
}
catch (Exception ex)
{
// Lida com qualquer erro ao ler os arquivos JSON
MessageBox.Show($"Erro ao ler {filePath}: {ex.Message}");
return new List<SupplementSource>();
}
}
public static List<SupplementSource> LoadSourcesFromFolders(string rootFolder)
{
List<SupplementSource> allSources = new List<SupplementSource>();
try
{
// Obtém todas as pastas dentro do diretório rootFolder
string[] supplementFolders = Directory.GetDirectories(rootFolder);
// Para cada pasta, carrega os arquivos JSON e adiciona as fontes
foreach (string supplementFolder in supplementFolders)
{
List<SupplementSource> sourcesInFolder = LoadSourcesFromFolder(supplementFolder);
allSources.AddRange(sourcesInFolder);
}
}
catch (Exception ex)
{
MessageBox.Show($"Erro ao carregar fontes: {ex.Message}");
}
return allSources;
}
public static List<SupplementSource> LoadSourcesFromFolder(string folderPath)
{
List<SupplementSource> sources = new List<SupplementSource>();
try
{
// Obtém todos os arquivos JSON dentro da pasta
string[] jsonFiles = Directory.GetFiles(folderPath, "*.json");
// Para cada arquivo, carrega as fontes e adiciona à lista
foreach (string jsonFile in jsonFiles)
{
List<SupplementSource> sourcesFromFile = LoadFromJson(jsonFile);
sources.AddRange(sourcesFromFile);
}
}
catch (Exception ex)
{
MessageBox.Show($"Erro ao carregar fontes: {ex.Message}");
}
return sources;
}
public void CalculateAbility(Label ability)
{
int mod = Convert.ToInt32(ability.Text);
int strMod = Convert.ToInt32(labelModStr.Text);
int dexMod = Convert.ToInt32(labelModDex.Text);
int conMod = Convert.ToInt32(labelModCon.Text);
int intMod = Convert.ToInt32(labelModInt.Text);
int wisMod = Convert.ToInt32(labelModWis.Text);
int chaMod = Convert.ToInt32(labelModCha.Text);
int str = Convert.ToInt32(lblTotalStr.Text) ;
int dex = Convert.ToInt32(lblTotalDex.Text) ;
int con = Convert.ToInt32(lblTotalCon.Text) ;
int inte = Convert.ToInt32(lblTotalInt.Text);
int wis = Convert.ToInt32(lblTotalWis.Text) ;
int cha = Convert.ToInt32(lblTotalCha.Text);
lblTotalStr.Text = (Convert.ToInt32(InitialStr.Value) + strMod).ToString();
lblTotalDex.Text = (Convert.ToInt32(InitialDex.Value) + dexMod).ToString();
lblTotalCon.Text = (Convert.ToInt32(InitialCon.Value) + conMod).ToString();
lblTotalInt.Text = (Convert.ToInt32(InitialInt.Value) + intMod).ToString();
lblTotalWis.Text = (Convert.ToInt32(InitialWis.Value) + wisMod).ToString();
lblTotalCha.Text = (Convert.ToInt32(InitialCha.Value) + chaMod).ToString();
lblModStrTotal.Text = CalcAttributeTotal(str).ToString();
lblModDexTotal.Text = CalcAttributeTotal(dex).ToString();
lblModConTotal.Text = CalcAttributeTotal(con).ToString();
lblModIntTotal.Text = CalcAttributeTotal(inte).ToString();
lblModWisTotal.Text = CalcAttributeTotal(wis).ToString();
lblModChaTotal.Text = CalcAttributeTotal(cha).ToString();
}
private int CalcAttributeTotal(int valAttrib)
{
if (valAttrib < 1 || valAttrib > 99)
{
throw new ArgumentException("Valor da habilidade inválido.");
}
double val = valAttrib;
val = val - 10;
double valpos = val % 2;
val = val / 2;
if (valpos == 1 || valpos == -1)
{
val = val - 0.5;
}
return Convert.ToInt32(val);
}
public void CalculatePointBuy()
{
//Localization();
UpdateLabels();
int totalAttrib = (Convert.ToInt32(lblModStr.Text) + Convert.ToInt32(lblModDex.Text) + Convert.ToInt32(lblModCon.Text) + Convert.ToInt32(lblModInt.Text) + Convert.ToInt32(lblModWis.Text) + Convert.ToInt32(lblModCha.Text));
if (totalAttrib > 0)
{
lblTypeCampaign.Text = "";
switch (totalAttrib)
{
case 15:
lblTypeCampaign.Text = LocalizationUtils.L("LowPoweredCampaign");
break;
case 22:
lblTypeCampaign.Text = LocalizationUtils.L("ChallengingCampaign");
break;
case 25:
lblTypeCampaign.Text = LocalizationUtils.L("StandardCampaign");
break;
case 28:
lblTypeCampaign.Text = LocalizationUtils.L("TougherCampaign");
break;
case 32:
lblTypeCampaign.Text = LocalizationUtils.L("HighPoweredCampaign");
break;
}
}
}
public void ClearStatsDescriptionSelections()
{
var confirmResult = MessageBox.Show(LocalizationUtils.L("AreYouSureClearForm1Stats"),
LocalizationUtils.L("ConfirmClear"),
MessageBoxButtons.YesNo);
if (confirmResult == DialogResult.Yes)
{
InitialStr.Value = 8;
InitialDex.Value = 8;
InitialCon.Value = 8;
InitialInt.Value = 8;
InitialWis.Value = 8;
InitialCha.Value = 8;
cbAlignment.SelectedIndex = 0;
}
}
private int CalcAttribute(int valAttrib)
{
int attrib = 0;
int valueBase = valAttrib - 8;
if (valAttrib >= 8 && valAttrib <= 14)
{
attrib = valueBase;
}
else
{
if (valAttrib == 15)
{
attrib = (valueBase + 1);
}
else
{
if (valAttrib == 16)
{
attrib = (valueBase + 2);
}
else
{
if (valAttrib == 17)
{
attrib = (valueBase + 4);
}
else
{
if (valAttrib == 18)
{
attrib = (valueBase + 6);
}
}
}
}
}
return attrib;
}
public void Reload()
{
switch (Properties.Settings.Default.LanguageIndex)
{
case 0:
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en");
break;
case 1:
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("pt-BR");
break;
}
this.Controls.Clear();
RaceUtils.PopulateRaceComboBox(cbRaces, 3);
InitializeComponent();
RaceUtils.PopulateRaceComboBox(cbRaces, 3);
cbAlignment.SelectedIndex = 0;
}
public void Localization()
{
switch (Properties.Settings.Default.LanguageIndex)
{
case 0:
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en");
break;
case 1:
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("pt-BR");
break;
}
}
private void Form1_SizeChanged(object sender, EventArgs e)
{
tabControl1.Size = new Size(this.Size.Width - 40, this.Size.Height - 80);
//tabControl1.ItemSize = this.Width - 10;
//tabControl1.Size.Height = this.Height - 10;
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
try
{
VisitLink();
}
catch (Exception ex)
{
MessageBox.Show(Resources.UnableOpenLink);
}
}
private void VisitLink()
{
// Change the color of the link text by setting LinkVisited
// to true.
linkLabel1.LinkVisited = true;
//Call the Process.Start method to open the default browser
//with a URL:
if (Properties.Settings.Default.LanguageIndex != null && Properties.Settings.Default.LanguageIndex != -1)
{
switch (Properties.Settings.Default.LanguageIndex)
{
case 0:
System.Diagnostics.Process.Start("https://creativecommons.org/licenses/by-nc-sa/4.0/");
break;
case 1:
System.Diagnostics.Process.Start("https://creativecommons.org/licenses/by-nc-sa/4.0/deed.pt_BR");
break;
}
}
else
{
MessageBox.Show("Unable to open link that was clicked.");
}
}
private void button4_Click(object sender, EventArgs e)
{
if (!lblRandomAge.Text.Equals("0"))
{
txtAge.Text = lblRandomAge.Text;
}
}
private void button7_Click(object sender, EventArgs e)
{
if (!lblRandomName.Text.Equals("__________________"))
{
txtName.Text = lblRandomName.Text;
}
}
private void button5_Click(object sender, EventArgs e)
{
if (!lblRandomHeight.Text.Equals("0 m") && !lblRandomHeight.Text.Equals("0 ft"))
{
txtHeight.Text = lblRandomHeight.Text;
}
}
private void button6_Click(object sender, EventArgs e)
{
if (!lblRandomWeight.Text.Equals("0 kg") && !lblRandomWeight.Text.Equals("0 lbs"))
{
txtWeight.Text = lblRandomWeight.Text;
}
}
private void button9_Click(object sender, EventArgs e)
{
if (!lblRandomHair.Text.Equals("__________________"))
{
txtHair.Text = lblRandomHair.Text;
}
}
private void button10_Click(object sender, EventArgs e)
{
if (!lblRandomEyes.Text.Equals("__________________"))
{
txtEyes.Text = lblRandomEyes.Text;
}
}
private void btRandomAge_Click(object sender, EventArgs e)
{
RandomAge();
}
private void RandomAge()
{
int agebasic = 0;
int ageMod = 0;
string textLookup = lblRace.Text;
List<string> AgeRace = new List<string>();
Race race = RaceUtils.GetOriginalRace(textLookup);
string BaseAgeRace = "";
if (race != null)
{
BaseAgeRace = LookupInfo("AR", race.OriginalName, "Race Info");
}
if (string.IsNullOrEmpty(BaseAgeRace))
{
lblRandomAge.Text = "0";
return;
}
AgeRace = BaseAgeRace.Split('/').ToList();
var classe = lblClasses.Text;
if (string.IsNullOrEmpty(classe))
{
lblRandomAge.Text = "0";
return;
}
var vetorClasse = classe.Split('/');
foreach (var item in vetorClasse)
{
var AgeString = AgeRace[0];
var Age = AgeString.Split('+').ToList();
agebasic = Convert.ToInt32(Age[0]);
var item2 = item.ToUpper();
if (item2.Contains("BARBARIAN") || item2.Contains("ROGUE") || item2.Contains("SORCERER"))
{
if (!string.IsNullOrEmpty(AgeRace[0]))
{
string Dice = Age[1];
ageMod = RollDice(Dice);
}
}
else if (item2.Contains("BARD") || item2.Contains("FIGHTER") || item2.Contains("PALADIN") || item2.Contains("RANGER"))
{
string AgeString2 = AgeRace[1];
ageMod = RollDice(AgeString2);
}
else if (item2.Contains("CLERIC") || item2.Contains("DRUID") || item2.Contains("MONK") || item2.Contains("WIZARD"))
{
string AgeString2 = AgeRace[2];
ageMod = RollDice(AgeString2);
}
}
lblRandomAge.Text = (agebasic + ageMod).ToString();
}
//private int RollDice(int numDice, int dieType)
//{
// Random random = new Random();
// int total = 0;
// for (int i = 0; i < numDice; i++)
// {
// total += random.Next(1, dieType + 1);
// }
// return total;
//}
private int RollDice(string diceString)
{
if (!string.IsNullOrEmpty(diceString))
{
//Random random = new Random();
if (diceString.Contains("d"))
{
var dice = diceString.Split('d').ToList();
int numDice = Convert.ToInt32(dice[0]);
int dieType = Convert.ToInt32(dice[1]);
int total = 0;
for (int i = 0; i < numDice; i++)
{
total += random.Next(1, dieType + 1);
}
return total;
}
}
else
{
return 0;
}
return 0;
}
private XLWorkbook LoadFile()
{
string path = System.IO.Path.GetTempFileName();
System.IO.File.WriteAllBytes(path, Properties.Resources.baseInfo);
var fileName = Path.ChangeExtension(path, "xlsm");
File.Copy(path, fileName, true);
pathfile = path;
tmpfile = Path.ChangeExtension(path, "xlsm");
var workbook = new XLWorkbook(tmpfile);
return workbook;
}
private XLWorkbook LoadFileFromResource()
{
// Caminho para o arquivo no sistema de arquivos
string filePath = System.Windows.Forms.Application.StartupPath.Replace("\\bin\\Debug", "") + "\\Resources\\baseInfo.xlsm";
if (File.Exists(filePath))
{
using (FileStream fileStream = File.OpenRead(filePath))
{
// Crie o XLWorkbook diretamente do FileStream
var workbook = new XLWorkbook(fileStream);
return workbook;
}
}
else
{
throw new Exception("Arquivo não encontrado.");
}
}
private IXLWorksheet getTable(string tabela, string campo)
{
try
{
var workbook = workSheet;
IXLWorksheet sheet;
try
{
sheet = workbook.Worksheets.First(w => w.Name == tabela);
}
catch (Exception)
{
throw new Exception("Planilha não encontrada");
}
//if (!validaCabecalho(sheet, campo))
// throw new Exception("Cabeçalho incorreto");
return sheet;
}
catch (Exception)
{
throw new Exception("Planilha não encontrada");
}
}
private string LookupInfo(string colunm, string textLookup, string table)
{
IXLWorksheet sheet;
sheet = getTable(table, "RACE*");
var totalLines = sheet.Rows().Count();
//var lookupRange = sheet.Range("$A$1:$BQ$523");
for (int l = 6; l <= totalLines; l++)
{
var _lineSheet = sheet.Row(l);
var _colunmSheet = sheet.Column(colunm);
var strName = _lineSheet.Cell($"A").Value.ToString();
var strBase = "";
if (strName == textLookup)
{
strBase = _lineSheet.Cell(colunm).Value.ToString();
//4'10"/4'5"+2d10
//workbook.Dispose();
return strBase;
}
}
//workSheet.Dispose();
return "";
}
private bool validaCabecalho(IXLWorksheet plan, string campo)
{
if (plan.Cell($"A{3}").Value.ToString().Trim().ToUpper() != campo
)
return false;
else
return true;
}
public class CsvRecord
{
public string Race { get; set; }
public string Category { get; set; }
public string ShortDescription { get; set; }
public string Size { get; set; }
public string Type { get; set; }
public string Subtype { get; set; }
public string HD { get; set; }
public string Land { get; set; }
public string Burrow { get; set; }
public string Climb { get; set; }
public string Fly { get; set; }
public string Maneuver { get; set; }
public string Swim { get; set; }
public string NaturalArmor { get; set; }
public string NaturalAttacks { get; set; }
public string SpecialAttacks { get; set; }
public string Spell_likeabilities { get; set; }
public string Psionicabilities { get; set; }
public string OtherSpecialAbilities { get; set; }
public string LowLightVision { get; set; }
public string Darkvision { get; set; }
public string OtherSenses { get; set; }
public string Immunities { get; set; }
public string Vulnerabilities { get; set; }
public string EnergyResistance { get; set; }
public string SpellResistance { get; set; }
public string DamageReduction { get; set; }
public string FastHealing { get; set; }
public string BonusEssentia { get; set; }
public string OtherSpecialQualities { get; set; }
public string Str { get; set; }
public string Dex { get; set; }
public string Con { get; set; }
public string Int { get; set; }
public string Wis { get; set; }
public string Cha { get; set; }
public string StrAdj { get; set; }
public string DexAdj { get; set; }
public string ConAdj { get; set; }
public string IntAdj { get; set; }
public string WisAdj { get; set; }
public string ChaAdj { get; set; }
public string RacialSkills { get; set; }
public string RacialWeaponFamiliarity { get; set; }
public string RacialWeaponProficiency { get; set; }
public string BonusFeats { get; set; }
public string AutomaticLanguages { get; set; }
public string BonusLanguages { get; set; }
public string DragonlanceLanguages { get; set; }
public string CRAdj { get; set; }
public string Alignment { get; set; }
public string LevelAdj { get; set; }
public string FavoredClass { get; set; }
public string BaseAge { get; set; }
public string Height { get; set; }
public string Weight { get; set; }
public string SpecialQualities { get; set; }
public string Filler1 { get; set; }
public string FamiliarLevel { get; set; }
public string CompanionLevel { get; set; }
public string FamiliarType { get; set; }
public string CompanionType { get; set; }
public string WildshapeSpecial { get; set; }
public string Special { get; set; }
public string Index { get; set; }
public string Species { get; set; }
public string Src { get; set; }
public string Pg { get; set; }
public string AltSrc { get; set; }
}
public class ModelClassMap : ClassMap<CsvRecord>
{
public ModelClassMap()
{
Map(m => m.Race).Name("Race");
Map(m => m.Category).Name("Category");
Map(m => m.ShortDescription).Name("Short Description");
Map(m => m.Size).Name("Size");
Map(m => m.Type).Name("Type");
Map(m => m.Subtype).Name("Subtype");
Map(m => m.HD).Name("HD");
Map(m => m.Land).Name("Land");
Map(m => m.Burrow).Name("Burrow");
Map(m => m.Climb).Name("Climb");
Map(m => m.Fly).Name("Fly");
Map(m => m.Maneuver).Name("Maneuver");
Map(m => m.Swim).Name("Swim");
Map(m => m.NaturalArmor).Name("Natural Armor");
Map(m => m.NaturalAttacks).Name("Natural Attacks");
Map(m => m.SpecialAttacks).Name("Special Attacks");
Map(m => m.Spell_likeabilities).Name("Spell-like abilities");
Map(m => m.Psionicabilities).Name("Psionic abilities");
Map(m => m.OtherSpecialAbilities).Name("Other Special Abilities");
Map(m => m.LowLightVision).Name("LowLight Vision");
Map(m => m.Darkvision).Name("Darkvision");
Map(m => m.OtherSenses).Name("Other Senses");
Map(m => m.Immunities).Name("Immunities");
Map(m => m.Vulnerabilities).Name("Vulnerabilities");
Map(m => m.EnergyResistance).Name("Energy Resistance");
Map(m => m.SpellResistance).Name("Spell Resistance");
Map(m => m.DamageReduction).Name("Damage Reduction");
Map(m => m.FastHealing).Name("Fast Healing");
Map(m => m.BonusEssentia).Name("Bonus Essentia");
Map(m => m.OtherSpecialQualities).Name("Other Special Qualities");
Map(m => m.Str).Name("Str");
Map(m => m.Dex).Name("Dex");
Map(m => m.Con).Name("Con");
Map(m => m.Int).Name("Int");
Map(m => m.Wis).Name("Wis");
Map(m => m.Cha).Name("Cha");
Map(m => m.StrAdj).Name("StrAdj");
Map(m => m.DexAdj).Name("DexAdj");
Map(m => m.ConAdj).Name("ConAdj");
Map(m => m.IntAdj).Name("IntAdj");
Map(m => m.WisAdj).Name("WisAdj");
Map(m => m.ChaAdj).Name("ChaAdj");
Map(m => m.RacialSkills).Name("Racial Skills");
Map(m => m.RacialWeaponFamiliarity).Name("Racial Weapon Familiarity");
Map(m => m.RacialWeaponProficiency).Name("Racial Weapon Proficiency");
Map(m => m.BonusFeats).Name("Bonus Feat(s)");
Map(m => m.AutomaticLanguages).Name("Automatic Languages");
Map(m => m.BonusLanguages).Name("Bonus Languages");
Map(m => m.DragonlanceLanguages).Name("Dragonlance Languages");
Map(m => m.CRAdj).Name("CR Adj.");
Map(m => m.Alignment).Name("Alignment");
Map(m => m.LevelAdj).Name("Level Adj.");
Map(m => m.FavoredClass).Name("Favored Class");
Map(m => m.BaseAge).Name("Base Age");
Map(m => m.Height).Name("Height");
Map(m => m.Weight).Name("Weight");
Map(m => m.SpecialQualities).Name("Special Qualities");
Map(m => m.Filler1).Name("Filler1");
Map(m => m.FamiliarLevel).Name("Familiar Level");
Map(m => m.CompanionLevel).Name("Companion Level");
Map(m => m.FamiliarType).Name("Familiar Type");
Map(m => m.CompanionType).Name("Companion Type");
Map(m => m.WildshapeSpecial).Name("Wildshape Special");
Map(m => m.Special).Name("Special");
Map(m => m.Index).Name("Index");
Map(m => m.Species).Name("Species");
Map(m => m.Src).Name("Src");
Map(m => m.Pg).Name("Pg");
Map(m => m.AltSrc).Name("AltSrc");
}
}
static string tmpfile = "";
static XLWorkbook workSheet = null;
static string pathfile = "";
static string pathphisicalfile = "";
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
CloseProgram();
}
private void CloseProgram()
{
HttpListenerService.Instance.StopListener();
this.Hide();
string path = System.IO.Path.GetTempFileName();
//File.Delete(path);
var dir = System.IO.Path.GetDirectoryName(path);
var d = new DirectoryInfo(dir);
foreach (var file in Directory.GetFiles(d.ToString()))
{
//File.Delete(file);
FileInfo archive = new FileInfo(file);
//for (int tries = 0; IsFileLocked(archive) && tries < 5; tries++)
// Thread.Sleep(100);
try
{
if (path.Equals(archive.FullName))
archive.Delete();
var fileName = Path.ChangeExtension(path, "xlsm");
if (fileName.Equals(archive.FullName))
archive.Delete();
if (tmpfile.Equals(archive.FullName) || pathfile.Equals(archive.FullName))
archive.Delete();
}
catch (IOException)
{
}
}
workSheet.Dispose();
}
private void btRandomHeight_Click(object sender, EventArgs e)
{
int height = RandomHeight();
RandomWeight(height);
}
private int RandomHeight()
{
int ageMod = 0, hgtMod = 0, wgtMod = 0;
string textLookup = lblRace.Text;
Race race = RaceUtils.GetOriginalRace(textLookup);
string BaseHeightRace = "";
if (race != null)
{
BaseHeightRace = LookupInfo("AS", race.OriginalName, "Race Info");
}
if (BaseHeightRace != null && !string.IsNullOrEmpty(BaseHeightRace))
{
var HeightRace = BaseHeightRace.Split('/').ToList();
var gender = lblGender.Text;
if (!string.IsNullOrEmpty(BaseHeightRace.Trim()))
{
if (!string.IsNullOrEmpty(gender))
{
var vetorGender = HeightRace[1].Split('+');
string Height = "";
if (gender.Equals("Male"))
{
Height = HeightRace[0];
}
else
{
Height = vetorGender[0];
}
if (!string.IsNullOrEmpty(Height))
{
Height = Height.Replace("\\", "");
string Dice = vetorGender[1];
var Mod = RollDice(Dice);
hgtMod = CalcHeight(Dice, Height);
}
}
}
else
{
lblRandomHeight.Text = "0";
}
}
return hgtMod;
}
private int CalcHeight(string Dice, string heightDice)
{
int hgtMod = RollDice(Dice);
// int hgtBase = var BaseHeightRace = await LookupRaceAsync("AS", race);
//int hgtBase = 0;// GetHeight();
int hgtBase = GetHeight(heightDice);