@@ -15,15 +15,17 @@ public class CeBattle implements Runnable {
1515 private CeEntity selectedFightEntityPlayer2 ;
1616 private final CePlayer cePlayer1 ;
1717 private final CePlayer cePlayer2 ;
18+ private CeAi cePlayer2Ai ;
1819 private boolean turnPlayer1 ;
1920 private boolean turnPlayer2 ;
2021 private boolean fightOngoing = true ;
2122 private boolean threadSleep ;
23+ private static final boolean debug = BattleConstants .battleDebug ;
2224// private boolean onServer = false; // Maybe we need this for Server specific Logic
2325
2426
2527 public CeBattle (CePlayer cePlayer1 , CePlayer cePlayer2 ) {
26- // System.out.println("Running main constructor");
28+ if ( debug ) System .out .println ("[Battle Main Thread]: Running main constructor" );
2729 this .selectedFightEntityPlayer1 = cePlayer1 .getTeam ().get (cePlayer1 .getActiveMonsterIndex ());
2830 this .selectedFightEntityPlayer1 .setPlayerNumber (1 );
2931 this .selectedFightEntityPlayer2 = cePlayer2 .getTeam ().get (cePlayer2 .getActiveMonsterIndex ());
@@ -37,9 +39,8 @@ public CeBattle(CePlayer cePlayer1, CePlayer cePlayer2) {
3739
3840 public CeBattle (CePlayer cePlayer1 , CeAi cePlayer2 ) {
3941 this (cePlayer1 , (CePlayer ) cePlayer2 );
40- // System.out.println("Constructor2") ;
42+ this . cePlayer2Ai = cePlayer2 ;
4143 cePlayer2 .setBattle (this );
42- CeExecuterService .addThreadToExecutor (cePlayer2 );
4344 }
4445
4546 public boolean isFightOngoing () {
@@ -51,31 +52,33 @@ public void run() {
5152 final int maxTickAmount = BattleConstants .tickAmount ;
5253 int tickAmountPlayer1 = maxTickAmount ;
5354 int tickAmountPlayer2 = maxTickAmount ;
54- // System.out.println("Battle Thread Started!");
55+ if ( debug ) System .out .println ("[Battle Main Thread]: Battle Thread Started!" );
5556 while (isFightOngoing ()) {
56- // System.out.println("[THREAD] " + this.fightOngoing);
57+ if ( debug ) System .out .println ("[Battle Main Thread]: is fightOngoing: " + this .fightOngoing );
5758 tickAmountPlayer1 -= selectedFightEntityPlayer1 .getCeStats ().getSpeed ();
5859 tickAmountPlayer2 -= selectedFightEntityPlayer2 .getCeStats ().getSpeed ();
5960 if (tickAmountPlayer1 <= 0 ) {
60- // System.out.println("HP of EP1: " + selectedFightEntityPlayer1.getCeStats().getCurrentHitPoints());
61- // System.out.println("[THREAD]: PLAYER 1 TURN");
61+ if (debug ) System .out .println ("[Battle Main Thread]: HP of EP1: " + selectedFightEntityPlayer1 .getCeStats ().getCurrentHitPoints ());
62+ if (debug ) System .out .println ("[Battle Main Thread]: PLAYER 1 TURN" );
63+ if (debug ) System .out .println ("[Battle Main Thread]: HP of EP2: " + selectedFightEntityPlayer2 .getCeStats ().getCurrentHitPoints ());
6264 turnPlayer1 = true ;
63- // System.out.println("HP of EP2: " + selectedFightEntityPlayer2.getCeStats().getCurrentHitPoints());
6465 tickAmountPlayer1 = maxTickAmount + tickAmountPlayer1 ;
6566 threadSleep ();
6667 }
6768 if (isFightOngoing () && tickAmountPlayer2 <= 0 ) {
68- // System.out.println("HP of EP2: " + selectedFightEntityPlayer2.getCeStats().getCurrentHitPoints());
69- // System.out.println("[THREAD]: PLAYER 2 TURN");
69+ if (debug ) System .out .println ("[Battle Main Thread]: HP of EP2: " + selectedFightEntityPlayer2 .getCeStats ().getCurrentHitPoints ());
70+ if (debug ) System .out .println ("[Battle Main Thread]: PLAYER 2 TURN" );
71+ if (debug ) System .out .println ("[Battle Main Thread]: cePlayer2 is AI: " + cePlayer2 .isAI ());
72+ if (debug ) System .out .println ("[Battle Main Thread]: HP of EP1: " + selectedFightEntityPlayer1 .getCeStats ().getCurrentHitPoints ());
7073 turnPlayer2 = true ;
71- // System.out.println("HP of EP1: " + selectedFightEntityPlayer1.getCeStats().getCurrentHitPoints());
7274 tickAmountPlayer2 = maxTickAmount + tickAmountPlayer2 ;
73- threadSleep ();
75+ if (this .cePlayer2 .isAI ()) this .cePlayer2Ai .useAttack ();
76+ else threadSleep ();
7477 }
7578 }
76- // System.out.println("Battle Thread Ended");
7779 turnPlayer1 = false ;
7880 turnPlayer2 = false ;
81+ if (debug ) System .out .println ("[Battle Main Thread]: Battle Thread Ended" );
7982 }
8083
8184 public void setSelectedFightEntityPlayer1 (CeEntity entity ) {
@@ -86,10 +89,15 @@ public void setSelectedFightEntityPlayer2(CeEntity entity) {
8689 this .selectedFightEntityPlayer2 = entity ;
8790 }
8891
92+ public void endBatte (){
93+ setBattleEnd ();
94+ setActionDone ();
95+ }
96+
8997
9098 private void setBattleEnd () {
9199 this .fightOngoing = false ;
92- System .out .println (fightOngoing );
100+ if ( debug ) System .out .println ("[Battle Main Thread]: is fightOngoing: " + this . fightOngoing );
93101 }
94102
95103 public void flee () { //ToDo: in Progress
@@ -102,7 +110,7 @@ public void flee() { //ToDo: in Progress
102110 }
103111
104112 public boolean catchBeast (CeItem item ) throws Exception {
105- // System.out.println("Ce_Catch");
113+ if ( debug ) System .out .println ("[Battle Main Thread]: Ce_Catch" );
106114 boolean caught = false ;
107115 if (turnPlayer1 ) {
108116 turnPlayer1 = false ;
@@ -134,10 +142,10 @@ public void useAttack(CeAttack ceAttack) {
134142 private void applyAttack (CeEntity attacker , CeEntity defender , CeAttack ceAttack ) {
135143 final int damage = CeDamage .calculateDamage (attacker , defender , ceAttack );
136144 if (damage != -1 ) {
137- // System.out.println("Damage: " + damage);
145+ if ( debug ) System .out .println ("[Battle Main Thread]: Damage: " + damage );
138146 defender .dealDamage (damage );
139147 if (defender .getCeStats ().getType () == CeBeastTypes .PlayerStandard ) {
140- // System.out.println("Dealing Damage to player");
148+ if ( debug ) System .out .println ("[Battle Main Thread]: Dealing Damage to player" );
141149 if (defender .getPlayerNumber () == 1 ) cePlayer1 .dealDamage (damage );
142150 else cePlayer2 .dealDamage (damage );
143151 }
@@ -160,32 +168,33 @@ private void applyAttack(CeEntity attacker, CeEntity defender, CeAttack ceAttack
160168 this .selectedFightEntityPlayer2 .setPlayerNumber (2 );
161169 defender = selectedFightEntityPlayer2 ;
162170 if (selectedFightEntityPlayer2 .getCeStats ().getCurrentHitPoints () == 0 ) {
163- // System.out.println("IM DOIN SOMETHING WITH MY USELESS LIFE ");
171+ if ( debug ) System .out .println ("[Battle Main Thread]: Player2 fight entity HitPoints 0 " );
164172 setBattleEnd ();
165173 }
166174 }
167175
168176 }
169177 }
170- } else { System .out .println ("Missed !" );}
178+ } else { if ( debug ) System .out .println ("[Battle Main Thread]: Attack missed !" );}
171179 setActionDone ();
172180 }
173181
174182 private void threadSleep () {
175183 threadSleep = true ;
176- // System.out.println("Thread now sleeping!");
184+ if ( debug ) System .out .println ("[Battle Main Thread]: Thread now sleeping!" );
177185 while (threadSleep ) {
178186 try {
179187 Thread .sleep (1 );
180188 } catch (InterruptedException e ) {
181189 e .printStackTrace ();
182190 }
183191 }
184- // System.out.println("Thread continue");
192+ if ( debug ) System .out .println ("[Battle Main Thread]: Thread continue" );
185193 }
186194
187195 private void setActionDone () {
188196 this .threadSleep = false ;
197+ if (debug ) System .out .println ("[Battle Main Thread]: setAction Done" );
189198 }
190199
191200 public CePlayer getTurn () {
0 commit comments