33import calculationEngine .CeExecuterService ;
44import calculationEngine .entities .*;
55import calculationEngine .environment .CeItem ;
6+ import calculationEngine .environment .CeItemTypes ;
7+ import calculationEngine .environment .CeLoot ;
68import config .BattleConstants ;
79
810import java .util .Random ;
@@ -13,15 +15,17 @@ public class CeBattle implements Runnable {
1315 private CeEntity selectedFightEntityPlayer2 ;
1416 private final CePlayer cePlayer1 ;
1517 private final CePlayer cePlayer2 ;
18+ private CeAi cePlayer2Ai ;
1619 private boolean turnPlayer1 ;
1720 private boolean turnPlayer2 ;
1821 private boolean fightOngoing = true ;
1922 private boolean threadSleep ;
23+ private static final boolean debug = BattleConstants .battleDebug ;
2024// private boolean onServer = false; // Maybe we need this for Server specific Logic
2125
2226
2327 public CeBattle (CePlayer cePlayer1 , CePlayer cePlayer2 ) {
24- System .out .println ("Running main constructor" );
28+ if ( debug ) System .out .println ("[Battle Main Thread]: Running main constructor" );
2529 this .selectedFightEntityPlayer1 = cePlayer1 .getTeam ().get (cePlayer1 .getActiveMonsterIndex ());
2630 this .selectedFightEntityPlayer1 .setPlayerNumber (1 );
2731 this .selectedFightEntityPlayer2 = cePlayer2 .getTeam ().get (cePlayer2 .getActiveMonsterIndex ());
@@ -35,9 +39,8 @@ public CeBattle(CePlayer cePlayer1, CePlayer cePlayer2) {
3539
3640 public CeBattle (CePlayer cePlayer1 , CeAi cePlayer2 ) {
3741 this (cePlayer1 , (CePlayer ) cePlayer2 );
38- System . out . println ( "Constructor2" ) ;
42+ this . cePlayer2Ai = cePlayer2 ;
3943 cePlayer2 .setBattle (this );
40- CeExecuterService .addThreadToExecutor (cePlayer2 );
4144 }
4245
4346 public boolean isFightOngoing () {
@@ -49,31 +52,33 @@ public void run() {
4952 final int maxTickAmount = BattleConstants .tickAmount ;
5053 int tickAmountPlayer1 = maxTickAmount ;
5154 int tickAmountPlayer2 = maxTickAmount ;
52- System .out .println ("Battle Thread Started!" );
55+ if ( debug ) System .out .println ("[Battle Main Thread]: Battle Thread Started!" );
5356 while (isFightOngoing ()) {
54- System .out .println ("[THREAD] " + this .fightOngoing );
57+ if ( debug ) System .out .println ("[Battle Main Thread]: is fightOngoing: " + this .fightOngoing );
5558 tickAmountPlayer1 -= selectedFightEntityPlayer1 .getCeStats ().getSpeed ();
5659 tickAmountPlayer2 -= selectedFightEntityPlayer2 .getCeStats ().getSpeed ();
5760 if (tickAmountPlayer1 <= 0 ) {
58- System .out .println ("HP of EP1: " + selectedFightEntityPlayer1 .getCeStats ().getCurrentHitPoints ());
59- 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 ());
6064 turnPlayer1 = true ;
61- System .out .println ("HP of EP2: " + selectedFightEntityPlayer2 .getCeStats ().getCurrentHitPoints ());
6265 tickAmountPlayer1 = maxTickAmount + tickAmountPlayer1 ;
6366 threadSleep ();
6467 }
6568 if (isFightOngoing () && tickAmountPlayer2 <= 0 ) {
66- System .out .println ("HP of EP2: " + selectedFightEntityPlayer2 .getCeStats ().getCurrentHitPoints ());
67- 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 ());
6873 turnPlayer2 = true ;
69- System .out .println ("HP of EP1: " + selectedFightEntityPlayer1 .getCeStats ().getCurrentHitPoints ());
7074 tickAmountPlayer2 = maxTickAmount + tickAmountPlayer2 ;
71- threadSleep ();
75+ if (this .cePlayer2 .isAI ()) this .cePlayer2Ai .useAttack ();
76+ else threadSleep ();
7277 }
7378 }
74- System .out .println ("Battle Thread Ended" );
7579 turnPlayer1 = false ;
7680 turnPlayer2 = false ;
81+ if (debug ) System .out .println ("[Battle Main Thread]: Battle Thread Ended" );
7782 }
7883
7984 public void setSelectedFightEntityPlayer1 (CeEntity entity ) {
@@ -84,10 +89,15 @@ public void setSelectedFightEntityPlayer2(CeEntity entity) {
8489 this .selectedFightEntityPlayer2 = entity ;
8590 }
8691
92+ public void endBatte (){
93+ setBattleEnd ();
94+ setActionDone ();
95+ }
96+
8797
8898 private void setBattleEnd () {
8999 this .fightOngoing = false ;
90- System .out .println (fightOngoing );
100+ if ( debug ) System .out .println ("[Battle Main Thread]: is fightOngoing: " + this . fightOngoing );
91101 }
92102
93103 public void flee () { //ToDo: in Progress
@@ -99,15 +109,21 @@ public void flee() { //ToDo: in Progress
99109 }
100110 }
101111
102- public boolean catchBeast () {
103- System .out .println ("Ce_Catch" );
112+ public boolean catchBeast (CeItem item ) throws Exception {
113+ if ( debug ) System .out .println ("[Battle Main Thread]: Ce_Catch" );
104114 boolean caught = false ;
105115 if (turnPlayer1 ) {
106116 turnPlayer1 = false ;
107- CeItem item = new CeItem (1 );
108- caught = CeCatching .isCaught (cePlayer1 , selectedFightEntityPlayer2 , new CeItem (0 ));
109- if (caught ) setBattleEnd ();
110- setActionDone ();
117+ if (item .getType () == CeItemTypes .cage ) {
118+ this .cePlayer1 .getInventory ().useItem (item ); // Currently there is only one Cage option.. will need a system to decide what kind of item it is
119+ caught = CeCatching .isCaught (cePlayer1 , selectedFightEntityPlayer2 , item ); // Replace with Inventory use of Cage
120+ if (caught ) setBattleEnd ();
121+ setActionDone ();
122+ }
123+ else {
124+ setActionDone ();
125+ throw new WrongItemException (item , "Cage" );
126+ }
111127 }
112128 return caught ;
113129 }
@@ -126,10 +142,10 @@ public void useAttack(CeAttack ceAttack) {
126142 private void applyAttack (CeEntity attacker , CeEntity defender , CeAttack ceAttack ) {
127143 final int damage = CeDamage .calculateDamage (attacker , defender , ceAttack );
128144 if (damage != -1 ) {
129- System .out .println ("Damage: " + damage );
145+ if ( debug ) System .out .println ("[Battle Main Thread]: Damage: " + damage );
130146 defender .dealDamage (damage );
131147 if (defender .getCeStats ().getType () == CeBeastTypes .PlayerStandard ) {
132- System .out .println ("Dealing Damage to player" );
148+ if ( debug ) System .out .println ("[Battle Main Thread]: Dealing Damage to player" );
133149 if (defender .getPlayerNumber () == 1 ) cePlayer1 .dealDamage (damage );
134150 else cePlayer2 .dealDamage (damage );
135151 }
@@ -152,32 +168,33 @@ private void applyAttack(CeEntity attacker, CeEntity defender, CeAttack ceAttack
152168 this .selectedFightEntityPlayer2 .setPlayerNumber (2 );
153169 defender = selectedFightEntityPlayer2 ;
154170 if (selectedFightEntityPlayer2 .getCeStats ().getCurrentHitPoints () == 0 ) {
155- System .out .println ("IM DOIN SOMETHING WITH MY USELESS LIFE " );
171+ if ( debug ) System .out .println ("[Battle Main Thread]: Player2 fight entity HitPoints 0 " );
156172 setBattleEnd ();
157173 }
158174 }
159175
160176 }
161177 }
162- } else { System .out .println ("Missed !" );}
178+ } else { if ( debug ) System .out .println ("[Battle Main Thread]: Attack missed !" );}
163179 setActionDone ();
164180 }
165181
166182 private void threadSleep () {
167183 threadSleep = true ;
168- System .out .println ("Thread now sleeping!" );
184+ if ( debug ) System .out .println ("[Battle Main Thread]: Thread now sleeping!" );
169185 while (threadSleep ) {
170186 try {
171187 Thread .sleep (1 );
172188 } catch (InterruptedException e ) {
173189 e .printStackTrace ();
174190 }
175191 }
176- System .out .println ("Thread continue" );
192+ if ( debug ) System .out .println ("[Battle Main Thread]: Thread continue" );
177193 }
178194
179195 private void setActionDone () {
180196 this .threadSleep = false ;
197+ if (debug ) System .out .println ("[Battle Main Thread]: setAction Done" );
181198 }
182199
183200 public CePlayer getTurn () {
0 commit comments