Skip to content

Commit dd7f06e

Browse files
Merge pull request #11 from LittleBeasts/development
Development
2 parents e44136b + 8a41b07 commit dd7f06e

20 files changed

Lines changed: 740 additions & 155 deletions

.github/workflows/maven.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ jobs:
2424
id: bump_version
2525
uses: christian-draeger/increment-semantic-version@1.0.2
2626
with:
27-
current-version: '1.0.0-alpha1'
28-
version-fragment: 'bug'
27+
current-version: '1.0.1-alpha1'
28+
version-fragment: 'major'
2929
- name: Upload Artifacts
3030
run: mkdir builds && cp target/*.jar builds/calculationEngine-${{ steps.bump_version.outputs.next-version }}.jar
3131
- uses: actions/upload-artifact@v2

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.idea
2-
target
2+
target
3+
calculationEngine.iml

src/main/java/JSON/items.JSON

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
{
2+
"cage": {
3+
"name": "Cage",
4+
"spriteName": "sprite_name",
5+
"id": "#7",
6+
"description": "Cage to catch a litteBeast",
7+
"probability": "90",
8+
"uses": 1,
9+
"effects": "Catch",
10+
"unique": false,
11+
"type": "cage",
12+
"bonusStats":[
13+
10,
14+
10,
15+
10,
16+
10,
17+
10,
18+
10,
19+
0
20+
],
21+
"rarity": "common"
22+
},
23+
"aHealingPotion": {
24+
"name": "A healing potion",
25+
"spriteName": "sprite_name",
26+
"id": "#2",
27+
"description": "Heals a portion of your life",
28+
"probability": "80",
29+
"uses": 1,
30+
"effects": "Heals 10HP",
31+
"unique": false,
32+
"type": "consumable",
33+
"bonusStats":[
34+
10,
35+
10,
36+
10,
37+
10,
38+
10,
39+
10,
40+
0
41+
],
42+
"rarity": "common"
43+
},
44+
"aGreaterHealingPotion": {
45+
"id": "#5",
46+
"name": "A greater healing potion",
47+
"spriteName": "sprite_name",
48+
"description": "Heals a portion of your life",
49+
"probability": "20",
50+
"uses": 1,
51+
"effects": "Heals 10HP",
52+
"type": "consumable",
53+
"unique": false,
54+
"bonusStats":[
55+
10,
56+
10,
57+
10,
58+
10,
59+
10,
60+
10,
61+
0
62+
],
63+
"rarity": "common"
64+
},
65+
"stickOfBeating": {
66+
"id": "#3",
67+
"name": "The Stick of Beating",
68+
"spriteName": "sprite_name",
69+
"description": "It's a stick, you can hit someone with it. Don't.",
70+
"probability": "80",
71+
"uses": 1,
72+
"effects": "It hurts.",
73+
"type": "weapon",
74+
"unique": false,
75+
"bonusStats":[
76+
10,
77+
10,
78+
10,
79+
10,
80+
10,
81+
10,
82+
0
83+
],
84+
"rarity": "rare"
85+
},
86+
"StickOfMoreBeating": {
87+
"id": "#4",
88+
"name": "The Stick of more Beating",
89+
"spriteName": "sprite_name",
90+
"description": "It's a stick, you can hit someone with it. Do.",
91+
"probability": "20",
92+
"uses": 1,
93+
"effects": "It hurts.",
94+
"type": "weapon",
95+
"unique": false,
96+
"bonusStats":[
97+
10,
98+
10,
99+
10,
100+
10,
101+
10,
102+
10,
103+
0
104+
],
105+
"rarity": "rare"
106+
},
107+
"hammerOfZordon": {
108+
"id": "#1",
109+
"name": "The Hammer of Zordon",
110+
"spriteName": "sprite_name",
111+
"description": "It's Zordons Hammer, what do you think it will do?",
112+
"probability": "90",
113+
"uses": 1,
114+
"effects": "Hammers like crazy",
115+
"type": "weapon",
116+
"unique": false,
117+
"bonusStats":[
118+
10,
119+
10,
120+
10,
121+
10,
122+
10,
123+
10,
124+
0
125+
],
126+
"rarity": "legendary"
127+
},
128+
"hammerOfKarl": {
129+
"id": "#6",
130+
"name": "The Hammer of Karl",
131+
"spriteName": "sprite_name",
132+
"description": "It's Karls Hammer, it hammers",
133+
"probability": "10",
134+
"uses": 1,
135+
"effects": "Hammers like totally crazy",
136+
"type": "weapon",
137+
"unique": false,
138+
"bonusStats":[
139+
10,
140+
10,
141+
10,
142+
10,
143+
10,
144+
10,
145+
0
146+
],
147+
"rarity": "legendary"
148+
}
149+
}

src/main/java/calculationEngine/CeExecuterService.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
package calculationEngine;
22

3-
import java.util.concurrent.ExecutorService;
4-
import java.util.concurrent.Executors;
5-
import java.util.concurrent.TimeUnit;
3+
import config.BattleConstants;
4+
5+
import java.util.concurrent.*;
66

77
public class CeExecuterService {
88

9-
private static final ExecutorService executorService = Executors.newFixedThreadPool(4);
9+
private static final ThreadPoolExecutor executorService = (ThreadPoolExecutor) Executors.newFixedThreadPool(4);
10+
private static final boolean debug = BattleConstants.battleDebug;
1011

1112
public static void addThreadToExecutor(Runnable runnable){
1213
executorService.execute(runnable);
14+
if(debug) System.out.println("[CE Executor Service] Active Threads: " + executorService.getActiveCount());
1315
}
1416

1517
public static void shutdownExecutor(){
1618
executorService.shutdown();
17-
System.out.println("Shut Down Executor");
19+
if(debug) System.out.println("[CE Executor Service] Active Threads: " + executorService.getActiveCount());
20+
if(debug) System.out.println("[CE Executor Service]: Shut Down Executor");
1821
try {
1922
executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
2023
} catch (InterruptedException e) {

src/main/java/calculationEngine/battle/CeBattle.java

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import calculationEngine.CeExecuterService;
44
import calculationEngine.entities.*;
55
import calculationEngine.environment.CeItem;
6+
import calculationEngine.environment.CeItemTypes;
7+
import calculationEngine.environment.CeLoot;
68
import config.BattleConstants;
79

810
import 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() {

src/main/java/calculationEngine/battle/CeCatching.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ private static boolean catchingMisses(CeEntity player, CeEntity beast, CeAttack
4242
int baseDifficultly = (beast.getCeStats().getCurrentHitPoints() * 100) / (beast.getCeStats().getMaxHitPoints());
4343
double levelModifier = (double) player.getCeStats().getLevel() / beast.getCeStats().getLevel();
4444
int speed = (int) (player.getCeStats().getSpeed() * levelModifier);
45-
int difficulty = baseDifficultly + beast.getCeStats().getSpeed() - (speed + ceAttack.getAccuracy() + cage.getBonus());
45+
int difficulty = baseDifficultly + beast.getCeStats().getSpeed() - (speed + ceAttack.getAccuracy() + cage.getItemBonusStats().getCatchBonus());
4646
debugInfo += "Difficulty: " + difficulty + "\n";
4747
// if difficulty is higher than the roll the attack will miss.
4848
return difficulty > attackRoll;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package calculationEngine.battle;
2+
3+
import calculationEngine.environment.CeItem;
4+
5+
public class WrongItemException extends Exception{
6+
public WrongItemException(CeItem item, String expected) {
7+
super("Wrong Item: expected: " + expected + " got: " + item.getName());
8+
}
9+
}

0 commit comments

Comments
 (0)