This is the emulation of a battle in D&D. This first version is a super simplified battle system:
- We only have one action: attack.
- Our characters only fights with bare hands.
- There are no armors as well.
- Movement really doesn't matter.
The goal is to improve the combat in the future to at least emulate one of those old consoles JRPGs.
Here's the supported character's attributes:
- Strength (STR): How hard they are going to hit?
- Dexterity (DEX): Used to calculate who attack first
- Hit Points (HP): How hard you can get hit and move forward?
- Armor: Although you are not wearing a real armor, your skin can be how thick?
These are the attributes that you need to fill for the characters to give them a chance to fight under the Kogito dome!
This is how our workflow looks like:
- The first thing is to decide who goes first based on each character dexterity, and their D20 roll.
- Next, the workflow define the character's turn.
- The active character attacks with their bare hands the enemy.
- If both characters are still alive, another round is taken place.
- Finally, after one of them is defeated the game is over.
The workflow was developed using the Serverless Workflow DSL, and is running with the Kogito Severless Workflow engine.
You can try the Kogito Battle Flow application by running the following commands in separated terminals:
docker-compose -f docker-compose.yaml up -d
Then you can send a POST request to http://localhost:8080/battleflow with the following contents:
{
"workflowdata": {
"player": {
"name": "Sheldon Cooper",
"armor": 5,
"class": "Physicist",
"dexterity": 2,
"strength": 4,
"hitPoints": 10
},
"enemy": {
"name": "Gobbo",
"armor": 5,
"class": "Goblin",
"dexterity": 2,
"strength": 1,
"hitPoints": 10
}
}
}
If you're interested in the produced events after each round, inspect the Sink logs with:
docker-compose logs -f
Sheldon Cooper should be able to defeat a simple Goblin, right? Wait for the response, and you shall see. Try playing around with the parameters to see the different battle outcomes.
For example, try having Sheldon fight against an Adult Black Dragon (STR 23, DEX 14, HP 195, Armor 19). :)
When you are done, run:
docker-compose down
Have fun!
Click here for more details
This project uses Quarkus, the Supersonic Subatomic Java Framework.
If you want to learn more about Quarkus, please visit its website: https://quarkus.io/ .
You can run your application in dev mode that enables live coding using:
./mvnw compile quarkus:dev
NOTE: Quarkus now ships with a Dev UI, which is available in dev mode only at http://localhost:8080/q/dev/.
The application can be packaged using:
./mvnw package
It produces the quarkus-run.jar
file in the target/quarkus-app/
directory. Be aware that it’s not an über-jar as
the dependencies are copied into the target/quarkus-app/lib/
directory.
If you want to build an über-jar, execute the following command:
./mvnw package -Dquarkus.package.type=uber-jar
The application is now runnable using java -jar target/quarkus-app/quarkus-run.jar
.
You can create a native executable using:
./mvnw package -Pnative
Or, if you don't have GraalVM installed, you can run the native executable build in a container using:
./mvnw package -Pnative -Dquarkus.native.container-build=true
You can then execute your native executable with: ./target/battle-flow-1.0.0-SNAPSHOT-runner
If you want to learn more about building native executables, please consult https://quarkus.io/guides/maven-tooling.html .