-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVillage.java
More file actions
1109 lines (779 loc) · 38.4 KB
/
Village.java
File metadata and controls
1109 lines (779 loc) · 38.4 KB
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
package botpackage;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
public class Village {
public Village(String nom, String url, String x, String y, ArrayList batiments,
int bois, int argile, int fer, int cereales, int tokenconstruction,
ArrayList constructionsEnCour, ArrayList batimentsEnFileDAttente, double levelPlaceTournoi, boolean champsFinis, int maxStockDepot, int maxStockSilo) {
super();
this.nom = nom;
this.url = url;
this.x = x;
this.y = y;
this.batiments = batiments;
this.bois = bois;
this.argile = argile;
this.fer = fer;
this.cereales = cereales;
this.constructionsEnCour = constructionsEnCour;
this.batimentsEnFileDAttente = batimentsEnFileDAttente;
this.tokenconstruction = tokenconstruction;
this.levelPlaceTournoi=levelPlaceTournoi;
this.champsFinis=champsFinis;
}
public Village() {
super();
}
public String getNom() {
return nom;
}
public String getUrl() {
return url;
}
public String getX() {
return x;
}
public String getY() {
return y;
}
public int getBois() {
return bois;
}
public int getArgile() {
return argile;
}
public int getFer() {
return fer;
}
public int getCereales() {
return cereales;
}
public ArrayList getConstructionsEnCour() {
return constructionsEnCour;
}
public ArrayList getBatimentsEnFileDAttente() {
return batimentsEnFileDAttente;
}
public void setNom(String nom) {
this.nom = nom;
}
public void setUrl(String url) {
this.url = url;
}
public void setX(String x) {
this.x = x/*.substring(1)*/;
}
public void setY(String y) {
this.y = y;
//this.y = y.substring(0,y.length()-1);
/*y= y.substring(0, y.length());*/
}
/*
public void setBatiments(List<WebElement> batiments) {
this.batiments = batiments;
}
public List<WebElement> getBatiments() {
return batiments;
}
*/
public void setBois(int bois) {
this.bois = bois;
}
public void setArgile(int argile) {
this.argile = argile;
}
public void setFer(int fer) {
this.fer = fer;
}
public void setCereales(int cereales) {
this.cereales = cereales;
}
public void setConstructionsEnCour(ArrayList constructionsEnCour) {
this.constructionsEnCour = constructionsEnCour;
}
public void setBatimentsEnFileDAttente(ArrayList batimentsEnFileDAttente) {
this.batimentsEnFileDAttente = batimentsEnFileDAttente;
}
public int getTokenconstruction() {
return tokenconstruction;
}
public void setTokenconstruction(int tokenconstruction) {
this.tokenconstruction = tokenconstruction;
}
public double getLevelPlaceTournoi() {
return levelPlaceTournoi;
}
public void setLevelPlaceTournoi(double levelPlaceTournoi) {
this.levelPlaceTournoi = levelPlaceTournoi;
}
public boolean getChampsFinis() {
return champsFinis;
}
public void setChampsFinis(boolean champsFinis) {
this.champsFinis = champsFinis;
}
public int getMaxStockDepot() {
return maxStockDepot;
}
public void setMaxStockDepot(int maxStockDepot) {
this.maxStockDepot = maxStockDepot;
}
public int getMaxStockSilo() {
return maxStockSilo;
}
public void setMaxStockSilo(int maxStockSilo) {
this.maxStockSilo = maxStockSilo;
}
public int getManqueDeBois() {
return manqueDeBois;
}
public void setManqueDeBois(int manqueDeBois) {
this.manqueDeBois = manqueDeBois;
}
public int getManqueDeArgile() {
return manqueDeArgile;
}
public void setManqueDeArgile(int manqueDeArgile) {
this.manqueDeArgile = manqueDeArgile;
}
public int getManqueDeFer() {
return manqueDeFer;
}
public void setManqueDeFer(int manqueDeFer) {
this.manqueDeFer = manqueDeFer;
}
public int getManqueDeCereales() {
return manqueDeCereales;
}
public void setManqueDeCereales(int manqueDeCereales) {
this.manqueDeCereales = manqueDeCereales;
}
public void setBesoinDeFete(int besoinDeFete) {
this.besoinDeFete = besoinDeFete;
}
public int getBesoinDeFete() {
return besoinDeFete;
}
public void setVillagePillage(boolean villagePillage) {
this.villagePillage = villagePillage;
}
public boolean getVillagePillage() {
return villagePillage;
}
public void setVillageCapitale(boolean villageCapitale) {
this.villageCapitale = villageCapitale;
}
public boolean getVillageCapitale() {
return villageCapitale;
}
public void setBesoinDeNpc(boolean besoinDeNpc) {
this.besoinDeNpc = besoinDeNpc;
}
public boolean getBesoinDeNpc() {
return besoinDeNpc;
}
//public void NombreDeMarchands (){}
public void setBatiments(List<Batiment> batiments) {
this.batiments = batiments;
}
public List<Batiment> getBatiments() {
return batiments;
}
public void setCropDeath(boolean cropDeath) {
this.cropDeath = cropDeath;
}
public boolean getCropDeath() {
return cropDeath;
}
public boolean getBesoinDeConstruction() {
return besoinDeConstruction;
}
public void setBesoinDeConstruction(boolean besoinDeConstruction) {
this.besoinDeConstruction = besoinDeConstruction;
}
public List<Batiment> getTemplateDuVillage() {
return batimentsDuTemplateDuVillage;
}
public void setTemplateDuVillage(List<Batiment> template) {
this.batimentsDuTemplateDuVillage = template;
}
public boolean getBesoinMarche() {
return besoinMarche;
}
public void setBesoinMarche(boolean besoinMarche) {
this.besoinMarche = besoinMarche;
}
public List<Batiment> getBatimentsDuTemplateDuVillage() {
return batimentsDuTemplateDuVillage;
}
public void setBatimentsDuTemplateDuVillage(
List<Batiment> batimentsDuTemplateDuVillage) {
this.batimentsDuTemplateDuVillage = batimentsDuTemplateDuVillage;
}
public int getChampMin() {
return champMin;
}
public void setChampMin(int champMin) {
this.champMin = champMin;
//if (champMin <= 10 ){
TeamplatesDeVillages template = new TeamplatesDeVillages();
List<Batiment> tem = template.etablirTeamplatePourUnVillage(champMin);
this.setTemplateDuVillage(tem);
//}
}
public int getNombreDeMarchands() {
return NombreDeMarchands;
}
public void setNombreDeMarchands(int nombreDeMarchands) {
NombreDeMarchands = nombreDeMarchands;
}
private int manqueDeBois;
private int manqueDeArgile;
private int manqueDeFer;
private int manqueDeCereales;
private int maxStockDepot=720000;
private int maxStockSilo=1200000;
private String nom;
private String url;
private String x;
private String y;
//private List<WebElement> batiments;
private List<Batiment> batiments = new ArrayList<Batiment>();
private int bois;
private int argile;
private int fer;
private int cereales;
private ArrayList constructionsEnCour;
private int tokenconstruction;
private ArrayList batimentsEnFileDAttente;
private double levelPlaceTournoi;
private boolean champsFinis;
private int besoinDeFete;
private boolean villagePillage;
private boolean villageCapitale;
private boolean besoinDeNpc;
private boolean besoinMarche;
private int NombreDeMarchands;
private boolean cropDeath;
private boolean besoinDeConstruction;
private List<Batiment> batimentsDuTemplateDuVillage = new ArrayList<Batiment>();
private int champMin;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void updateRessources(Travian t) {
Village village = t.villageEnCours();
String bois =t.getCompte().getDriver().findElement(By.xpath("//*[@id=\"l1\"]")).getText().replace(" ", "");
int stockBois = Integer.parseInt(bois);
String argile = t.getCompte().getDriver().findElement(By.xpath("//*[@id=\"l2\"]")).getText().replace(" ", "");
int stockArgile = Integer.parseInt(argile);
String fer = t.getCompte().getDriver().findElement(By.xpath("//*[@id=\"l3\"]")).getText().replace(" ", "");
int stockFer = Integer.parseInt(fer);
String cereales = t.getCompte().getDriver().findElement(By.xpath("//*[@id=\"l4\"]")).getText().replace(" ", "");
int stockCereales = Integer.parseInt(cereales);
village.setBois(stockBois);
village.setArgile(stockArgile);
village.setFer(stockFer);
village.setCereales(stockCereales);
String maxDepot = t.getCompte().getDriver().findElement(By.xpath("//*[@id=\"stockBarWarehouse\"]")).getText().replace(" ", "");
int maxStockDepot = Integer.parseInt(maxDepot);
String maxSilo = t.getCompte().getDriver().findElement(By.xpath("//*[@id=\"stockBarGranary\"]")).getText().replace(" ", "");
int maxStockSilo = Integer.parseInt(maxSilo);
village.setMaxStockDepot(maxStockDepot);
village.setMaxStockSilo(maxStockSilo);
System.out.println("Update Ressources de : " +village.getNom());
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void voirListeDeConstruction(Travian t) {
Village village = t.villageEnCours();
List<WebElement> test = null;
int constructionEnCours = 0;
try {
test = t.getCompte().getDriver().findElements(By.xpath("//*[@id=\"content\"]/div[2]/div[10]/ul/li"));
if (test.size() < 1){
village.setTokenconstruction(constructionEnCours);
System.out.println("Pas de construction en cours ");
}
if (test.size()>= 1) { //(test != null)
System.out.println(test.size()+" Construction de deja en cours");
constructionEnCours = test.size();
village.setTokenconstruction(constructionEnCours);
}
}catch (Exception e) {village.setTokenconstruction(constructionEnCours);}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public void voirTroupesDuVillage(Travian t){
//compte.getDriver().get("http://ts4.travian.fr/dorf1.php?newdid=6681&");
Village village = t.villageEnCours();
boolean troupesAQuai = false;
////*[@contains, "Éclairs de Toutatis"]
try {
List<WebElement> troupesDuVillage = t.getCompte().getDriver().findElements(By.xpath("//*[@id=\"troops\"]/tbody/tr"));
for (WebElement touta : troupesDuVillage) {
boolean troupesPresentes = touta.findElement(By.className("un")).getText().contains("Éclairs de Toutatis");//Éclairs de Toutatis
int nombreTroupesPresentes = Integer.parseInt(touta.findElement(By.className("num")).getText());
if (troupesPresentes == true) {village.setVillagePillage(true);}
if(troupesPresentes && nombreTroupesPresentes >= 35){
troupesAQuai = true;
}
}//fin for
}catch(Exception e){}//fin Try
if (troupesAQuai){
t.pillage();
}
else {System.out.println("Pas de Troupes -> pas de pillages");}
}//fin
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void chargerChamps(Travian t) {
// TODO Mettre ce code sir la classe Village
Village village = t.villageEnCours(); // pas utilisee ici
//////////////////////////////////////////////////////
// se replacer sur la bonne page si un module est rester ailleur
String urlTest = null;
try {
urlTest = t.getCompte().getDriver().getCurrentUrl().split(".php")[0].split(".fr/")[1];
}catch(Exception e){System.out.println("echec urlTest1 ");}
if (!urlTest.contains("dorf1")){
t.getCompte().getDriver().get(t.getCompte().getServer()+"dorf1.php");
t.randomsleep.court();
}
//////////////////////////////////////////////////////
List<WebElement> listeWebelementChamps = t.getCompte().getDriver().findElements(By.xpath("//*[@id=\"rx\"]/area"));
ArrayList<Integer> listeLevelsChamps = new ArrayList<Integer>();
ArrayList<String> listeNomsChamps = new ArrayList<String>();
//On verifie que lon est sur la page des champs de ressources
if (t.getCompte().getDriver().getCurrentUrl().contains("dorf1.php")) {
//On liste les elements necesaires a la comparaison des champs
int i = 0;
while (i < 18) {
String nomChamp = listeWebelementChamps.get(i).getAttribute("alt");
listeNomsChamps.add(nomChamp);
listeLevelsChamps.add(Integer.parseInt(listeWebelementChamps.get(i).getAttribute("alt").split("Niveau ")[1]));
i++;
if (i == 18){
System.out.println("Liste des "+ i +" champs : " + listeLevelsChamps+ "");
}
}
//On determine le niveau des champs le plus petit
t.randomsleep.court();
champMin = Collections.min(listeLevelsChamps);
village.setChampMin(champMin);
if (champMin >= 10){village.setChampsFinis(true);}else{village.setChampsFinis(false);}
if (champMin > 10){village.setVillageCapitale(true);}else{village.setVillageCapitale(false);}
System.out.println("Min val: " + champMin);
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void chargerBatiments(Travian t){
if (!t.getCompte().getDriver().getCurrentUrl().contains("dorf2.php")) {
t.randomsleep.court();
t.getCompte().getDriver().get(t.getCompte().getServer() + "dorf2.php");
t.randomsleep.court();
}
Village village = t.villageEnCours();
List<WebElement> listeDesBatiments = t.getCompte().getDriver().findElements(By.xpath("//*[@id=\"clickareas\"]/area"));
//on cree une lsite temporaire poure lenvoyer au village une fois la liste complete.
List<Batiment> listeDesBatimentsVillage = new ArrayList();
for (WebElement webBatiment : listeDesBatiments) {
//on intialise les varible
String nomBatiment = null;
int levelBatiment = 0;
String slotBatiment = null;
boolean trouver = false;
//on les remplis
try{
nomBatiment = webBatiment.getAttribute("alt").split(" <span")[0];
levelBatiment = Integer.parseInt(webBatiment.getAttribute("alt").split("<span class=\"level\">Niveau ")[1].split("</span>")[0]);
//reperer conctructions en cours
if (webBatiment.getAttribute("alt").contains("Amélioration en cours")){
int enCoursVersLevel = Integer.parseInt(webBatiment.getAttribute("alt").split("Amélioration en cours vers le niveau ")[1].split("</span>")[0]);
levelBatiment = enCoursVersLevel;
}
slotBatiment = webBatiment.getAttribute("href").split("id=")[1];
// si un slot est vide : on le nomme
}catch (Exception e){
nomBatiment = webBatiment.getAttribute("alt");
levelBatiment = 0;
slotBatiment = webBatiment.getAttribute("href").split("id=")[1];
}
//pour chaque batiment du village on regarde si le batiment y est. Sil y est on ne fait rien et on passe au suivant
try {
for (Batiment batiment : village.getBatiments()){
if (batiment.getNomBatiment().equals(nomBatiment) && batiment.getSlotBatiment().equals(slotBatiment)){
trouver=true;
batiment.setLevelBatiment(levelBatiment);
break;
}
}
}catch (Exception e ){trouver=false;}
//si le batiment ny est pas on le met dans la liste temporaire
if (trouver==false){
Batiment newBatiment = new Batiment();
newBatiment.setNomBatiment(nomBatiment);
newBatiment.setSlotBatiment(slotBatiment);
newBatiment.setLevelBatiment(levelBatiment);
listeDesBatimentsVillage.add(newBatiment);
//on envois la liste terminee au village concerne
village.setBatiments(listeDesBatimentsVillage);
}
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public void monterChamps(Travian t) {
// TODO Mettre ce code sir la classe Village
Village village = t.villageEnCours();
List<WebElement> listeWebelementChamps = t.getCompte().getDriver().findElements(By.xpath("//*[@id=\"rx\"]/area"));
int token = village.getTokenconstruction();
if (token < 2 ){
try { //secu anti rechargement
//Lancer construction champs
// trouver lien du premier plus petit
int g = 0;
while (g < 18) {
//on met a jour le token apres une eventuelle construction
village.voirListeDeConstruction(t);
token = village.getTokenconstruction();
//on reverifie le token pour pas boucler plus que necessaire
if (token < 2 ){
//On recharge la liste apres un eventuel rechargement
listeWebelementChamps = t.getCompte().getDriver().findElements(By.xpath("//*[@id=\"rx\"]/area"));
int lien = Integer.parseInt(listeWebelementChamps.get(g).getAttribute("alt").split("Niveau ")[1]); //bug ici au retour
//String lienNom = listeWebelementChamps.get(g).getAttribute("alt").split("Niveau ")[0];
//System.out.println("valeur g : " + g);
///test ressources///////////////////////////////////////////////////////////////////////
WebElement tagUnderConstruction = null ;
try{
tagUnderConstruction = t.getCompte().getDriver().findElement(By.xpath("//*[@id=\"village_map\"]/div["+(g+1)+"][contains(@class, 'underConstruction')]"));
}catch (Exception e) {}
if (lien == champMin && tagUnderConstruction == null) {
boolean retrytoken = false;
int boisNecessaire = 0;
int argileNecessaire = 0;
int ferNecessaire = 0;
int cerealesNecessaire = 0;
System.out.println("try lien==chamPmin : " + lien + " et : "+ champMin);
//survol souris du champs = a champMin
Actions builder = new Actions(t.getCompte().getDriver());
builder.moveToElement(listeWebelementChamps.get(g));
builder.perform();
t.randomsleep.court();
//choper le tableau des ressources necessaires pour le champs en cours
List<WebElement> ressourcesNecessaires = listeWebelementChamps.get(g+1).findElements(By.xpath("//*[@class='showCosts']/span"));
// System.out.println("valeur ressourcesnecessaire "+ ressourcesNecessaires.get(0).getText());
// System.out.println("valeur ressourcesnecessaire "+ ressourcesNecessaires.get(1).getText());
// System.out.println("valeur ressourcesnecessaire "+ ressourcesNecessaires.get(2).getText());
// System.out.println("valeur ressourcesnecessaire "+ ressourcesNecessaires.get(3).getText());
//correction bug de MouseHover
if (ressourcesNecessaires.get(0).getText().isEmpty()) {retrytoken = true;}
if (retrytoken == true) {
System.out.println("Retry hover");
Actions retry = new Actions(t.getCompte().getDriver());
retry.moveToElement(listeWebelementChamps.get(g));
retry.perform();
t.randomsleep.court();
ressourcesNecessaires = listeWebelementChamps.get(g).findElements(By.xpath("//*[@class='showCosts']/span"));
// System.out.println("valeur ressourcesnecessaire "+ ressourcesNecessaires.get(0).getText());
// System.out.println("valeur ressourcesnecessaire "+ ressourcesNecessaires.get(1).getText());
// System.out.println("valeur ressourcesnecessaire "+ ressourcesNecessaires.get(2).getText());
// System.out.println("valeur ressourcesnecessaire "+ ressourcesNecessaires.get(3).getText());
retrytoken = false;
}
if (retrytoken == false){
//Parse
boisNecessaire = Integer.parseInt(ressourcesNecessaires.get(0).getText());
argileNecessaire = Integer.parseInt(ressourcesNecessaires.get(1).getText());
ferNecessaire = Integer.parseInt(ressourcesNecessaires.get(2).getText());
cerealesNecessaire = Integer.parseInt(ressourcesNecessaires.get(3).getText());
System.out.println("parse ok");
}
// On fait la comparaison des ressources avec le stock du village en cours
//Village2 village = villageEnCours();
village.updateRessources(t);
int stockBois = village.getBois();
int stockArgile = village.getArgile();
int stockFer = village.getFer();
int stockCereales = village.getCereales();
//si ressources ok
if (stockBois >= boisNecessaire&& stockArgile >= argileNecessaire&& stockFer >= ferNecessaire&& stockCereales >= cerealesNecessaire) {
System.out.println("ressource ok");
// go la page
listeWebelementChamps.get(g).click();
t.randomsleep.court();
//trouver le bouton vert
WebElement bouttonvert = null;
try {
bouttonvert = t.getCompte().getDriver().findElement(By.xpath("//button[@class=\"green build\"]"));
}catch (Exception e) {
System.out.println("Bouton vert non present => Batiment en cour probable");
t.getCompte().getDriver().get(t.getCompte().getServer() + "dorf1.php");
t.randomsleep.classic();
break;//non teste
}
//cliquer sur le bouton vert
t.randomsleep.classic();
if (bouttonvert != null){
bouttonvert.click();
System.out.println("Lancement d'un Champs de (valeur g) "+ g + " (g-1) sur le Slot " + (g+1) + "");
t.randomsleep.court();}
} else {
System.out.println("ressource manquante");}
} //fin if lien== champMin
g++;
}//fin if token de verification
else {System.out.println("2 Champs lance");
break;}
}// fin while g <18
}catch(Exception e){System.out.println("Les Retours Pillage cause un echec");}
}// fin if token <2
village.voirListeDeConstruction(t);
}//fin monterchamps
/* } */
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public boolean construireBatiments(String batimentAConstruire, int levelVoulu, Travian t){
t.randomsleep.court();
// if (!compte.getDriver().getCurrentUrl().contains("dorf2.php")) {compte.getDriver().get(compte.getServer() + "dorf2.php");}
//randomsleep.court();
Village village = t.villageEnCours();
updateRessources(t);
int boisNecessaire = 0;
int argileNecessaire = 0;
int ferNecessaire = 0;
int cerealesNecessaire = 0;
boolean possibleOuPas = true;
List<WebElement> listeDesBatiments = t.getCompte().getDriver().findElements(By.xpath("//*[@id=\"clickareas\"]/area"));
List<Batiment> batimentsDeLaPage = new ArrayList<Batiment>();
//WebElement areaBatiment;
for (WebElement webBatiment : listeDesBatiments ){
try {
String nom = webBatiment.getAttribute("alt").split(" <span")[0];
int level = Integer.parseInt(webBatiment.getAttribute("alt").split("<span class=\"level\">Niveau ")[1].split("</span>")[0]);
String slot = webBatiment.getAttribute("href").split("id=")[1];
Batiment batiment = new Batiment(nom, level, slot);
batimentsDeLaPage.add(batiment);
}catch (Exception e){
String nom = webBatiment.getAttribute("alt");
int level = 0;
String slot = webBatiment.getAttribute("href").split("id=")[1];
String alt = webBatiment.getAttribute("alt");
Batiment batiment = new Batiment(nom, level, slot, alt);
batimentsDeLaPage.add(batiment);
}
}
////////////////////////////////////////////
for(Batiment construire1 : batimentsDeLaPage) {
//listeDesBatiments = compte.getDriver().findElements(By.xpath("//*[@id=\"clickareas\"]/area"));
if (construire1.getNomBatiment().contains(batimentAConstruire)){
int level = construire1.getLevelBatiment();
if (level < levelVoulu && village.getTokenconstruction() < 2){
//Parse
try {
listeDesBatiments = t.getCompte().getDriver().findElements(By.xpath("//*[@id=\"clickareas\"]/area"));
for (WebElement as : listeDesBatiments){////////////////////////////////ici go to stale, recgargement de page souci
//voirListeDeConstruction(t);
if (as.getAttribute("alt").contains(construire1.getNomBatiment()) && as.getAttribute("href").split("id=")[1].contains(construire1.getSlotBatiment()) && village.getTokenconstruction() < 2 ){
boisNecessaire = Integer.parseInt(as.getAttribute("alt").split("r1\" src=\"img/x.gif\" />")[1].split("</span>")[0].trim());
argileNecessaire = Integer.parseInt(as.getAttribute("alt").split("r2\" src=\"img/x.gif\" />")[1].split("</span>")[0].trim());
ferNecessaire = Integer.parseInt(as.getAttribute("alt").split("r3\" src=\"img/x.gif\" />")[1].split("</span>")[0].trim());
cerealesNecessaire = Integer.parseInt(as.getAttribute("alt").split("r4\" src=\"img/x.gif\" />")[1].split("</span>")[0].trim());
System.out.println("[construireBatiment]parse ok");
// on fais la comparaison des ressources avec le stock du village en cours
updateRessources(t);
int stockBois = village.getBois();
int stockArgile = village.getArgile();
int stockFer = village.getFer();
int stockCereales = village.getCereales();
//si ressources ok
if (stockBois >= boisNecessaire&& stockArgile >= argileNecessaire&& stockFer >= ferNecessaire&& stockCereales >= cerealesNecessaire) {
System.out.println("[construireBatiment] Ressources ok");
// go la page
as.click();
t.randomsleep.court();
//si cest un marche ou autre cliquer le bon tab
try {
List<WebElement> listeDesTabs = t.getCompte().getDriver().findElements(By.xpath("//*[@class=\"tabItem\"]"));
for(WebElement tabGestion : listeDesTabs){
if(tabGestion.getText().contains("Gestion")){
tabGestion.click();
t.randomsleep.court();
break;
}
}
}catch (Exception e){System.out.println("bug :)");}
//cliquer sur le bouton vert
WebElement bouttonvert = null;
try {
bouttonvert = t.getCompte().getDriver().findElement(By.xpath("//button[@class=\"green build\"]"));
}catch (Exception e) {
System.out.println("[construireBatiment] Bouton vert non present => Champ en cour probable");
possibleOuPas = false;
t.getCompte().getDriver().get(t.getCompte().getServer() + "dorf2.php");
t.randomsleep.classic();
break;
}
if (bouttonvert != null){
bouttonvert.click();
System.out.println("[construireBatiment] Lancement "+batimentAConstruire);
possibleOuPas = true;
t.randomsleep.court();
listeDesBatiments = t.getCompte().getDriver().findElements(By.xpath("//*[@id=\"clickareas\"]/area"));
break;
}
} else { System.out.println("[construireBatiment] Pas assez de Ressources pour faire un/une "+batimentAConstruire);}
}
}//break;}
}catch (Exception e){System.out.println("[construireBatiment] Batiment de niveau deja en construction ou deja au level demande "+ batimentAConstruire );voirListeDeConstruction(t);}
} else {
System.out.println("[construireBatiment] "+batimentAConstruire+" deja a 20");
possibleOuPas = false;}
}
}
voirListeDeConstruction(t);
return possibleOuPas;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public void lancerFete(Travian t){ // a modifier : regarder avant les recap pour voir si une fete est deja lancee... sinon ca clic pour rien
t.randomsleep.court();
t.getCompte().getDriver().get(t.getCompte().getServer()+"dorf2.php");
t.randomsleep.court();
try {
List<WebElement> listeDesBatiments = t.getCompte().getDriver().findElements(By.xpath("//*[@id=\"clickareas\"]/area"));
int hotelNonPresent = 1;
for (WebElement batiment : listeDesBatiments){
if (batiment.getAttribute("alt").contains("Hôtel de Ville")){
hotelNonPresent = 0;
batiment.click();
t.randomsleep.court();
//on fait une liste des boutons de lancement de fete
List<WebElement> boutons = null;
try {
boutons = t.getCompte().getDriver().findElements(By.xpath("//*[@value=\"influence\"]"));
}catch(Exception e){System.out.println("[Fete] Erreure de listage des boutons Fete ");}
//on verifie si des boutons de lancement de fetes sont present
if (boutons.size() > 0) {
//on tente une grande fete d'abord
try {
if(boutons.get(1).getText().contains("influence")){
boutons.get(1).click();
System.out.println("[Fete] Grande fete lancee");
t.randomsleep.court();
}
}catch(Exception e){}
//puis sinon on tente une ptite fete
try {
if(boutons.get(0).getText().contains("influence")){