Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
178 commits
Select commit Hold shift + click to select a range
86fe6f2
Add consumables (#32)
kuroppoi Feb 5, 2024
8a9bc80
Send skill data before inventory data
kuroppoi Feb 5, 2024
81ceaa4
Implement a bunch of block interactions (#34)
kuroppoi Feb 17, 2024
ac1069c
Change default deep biome size to 1200x1000
kuroppoi Feb 17, 2024
c6779f0
Place spawn buildings closer to the top in `fill` terrain types
kuroppoi Feb 17, 2024
3bba089
Add layer separator zone generator feature
kuroppoi Feb 17, 2024
2b0900b
Fix space biome not configuring properly
kuroppoi Feb 17, 2024
887e235
Fix potential mechanical sign crash
kuroppoi Feb 17, 2024
3101748
Move behavior to NPC package
kuroppoi Feb 17, 2024
49ab4c4
Abstract entity damaging
kuroppoi Feb 18, 2024
dcb5e8a
Fix lava bombs
kuroppoi Feb 18, 2024
f986587
Fix inventory use sync issue with v2 clients
kuroppoi Feb 18, 2024
29dd9ac
Add note functionality
kuroppoi Feb 18, 2024
df698a3
Check if entity is dead before applying damage
kuroppoi Feb 18, 2024
45787c3
Damage check
kuroppoi Feb 18, 2024
9ec3175
Improve damage tracking
kuroppoi Feb 18, 2024
9dc5cbd
Lazy fix for potential crashes
kuroppoi Feb 18, 2024
188b78d
Implement persistence for certain NPCs
kuroppoi Feb 18, 2024
20a9b5b
Remove unused import
kuroppoi Feb 18, 2024
38cf041
Add a bunch of utility functions
kuroppoi Feb 18, 2024
5928ec5
Implement steam system
kuroppoi Feb 20, 2024
e7c4813
Add hatchet functionality
kuroppoi Feb 20, 2024
c5ff0ba
Fix an oopsie
kuroppoi Feb 20, 2024
39f75f8
Player appearance rework
kuroppoi Feb 23, 2024
34ca131
Fix zone status compatibility with older game versions
kuroppoi Feb 23, 2024
b737d46
Make `/give all` not exclude clothing items
kuroppoi Feb 23, 2024
5dbc755
Fix appearance update oopsie
kuroppoi Feb 23, 2024
7a06129
Prepack `EntityItemUseMessage`
kuroppoi Feb 23, 2024
1466ea0
Fix player name inconsistency on v2 clients
kuroppoi Feb 23, 2024
8823960
Temporary fix for system notifications playing karma warning sound on v2
kuroppoi Feb 24, 2024
c444371
Send killer entity ID in player death status message
kuroppoi Feb 24, 2024
455e63f
Swap biome & size parameters in `/genzone` command
kuroppoi Feb 24, 2024
e330b13
Prevent explosions from destroying unlooted containers
kuroppoi Feb 24, 2024
94cb2e1
Don't track explosion triggerer in burst interaction
kuroppoi Feb 24, 2024
bfeb93b
Biome survival skill requirement check
kuroppoi Feb 24, 2024
03e96be
Add skeleton burying & undertaker achievement type
kuroppoi Feb 25, 2024
a9ba168
Space biomes should have a higher surface level
kuroppoi Feb 25, 2024
e9a046c
Add creature trapping & implement trapper achievements
kuroppoi Feb 25, 2024
5de602f
Update chunk data format
kuroppoi Mar 3, 2024
75b1291
Fix oopsie
kuroppoi Mar 3, 2024
59e3212
Test
kuroppoi Mar 6, 2024
056e063
Add account lock remover for MacOS
kuroppoi Mar 9, 2024
4303c33
Automatic default zone sizes
kuroppoi Apr 26, 2024
a585753
Refactor commands
kuroppoi Apr 26, 2024
ab1147b
Undo bfeb93be809f1b74988d0d6615f1b5c8c01e5c73
kuroppoi Apr 26, 2024
261ec4e
Minor refactors
kuroppoi Apr 28, 2024
1eda985
Custom build logic (#49)
kuroppoi May 1, 2024
d4e84ad
Remove unused imports
kuroppoi May 1, 2024
f0c1187
Improve build logic
kuroppoi May 2, 2024
3752888
Update build.yml
kuroppoi May 2, 2024
90f2905
Case-insensitive commands
kuroppoi May 3, 2024
3841f4d
Add Docker support (#48)
array-in-a-matrix May 4, 2024
3d5edf1
Merge branch 'develop' of https://github.com/kuroppoi/brainwine into …
kuroppoi May 4, 2024
afa6995
Custom OffsetDateTime serializer
kuroppoi May 4, 2024
e2f6a06
Make player names in EntityManager not case-sensitive
kuroppoi May 4, 2024
0822dc4
Ecological machine assembly
kuroppoi May 4, 2024
a4c7158
Track machine part discovery
kuroppoi May 5, 2024
dfb80ca
Notification fix
kuroppoi May 5, 2024
a5f704c
Implement Deliverance achievement
kuroppoi May 5, 2024
9e439a5
Send machine status on player join
kuroppoi May 5, 2024
44fbb5c
Add interaction functionality for ecological machines
kuroppoi May 5, 2024
44e1dee
Add `/find` command
kuroppoi May 5, 2024
0b5ab23
Fix recycler
kuroppoi May 5, 2024
c954a2a
Add automatic zone generation based on exploration condition (#44)
boraini May 6, 2024
78faef8
Implement field damage
kuroppoi May 6, 2024
a2dc3ff
Delete unused class
kuroppoi May 6, 2024
0ca51a1
Generate infernal protectors in hell biomes
kuroppoi May 7, 2024
9c9dfa4
Make teleporter spawn count not random
kuroppoi May 7, 2024
d9b009f
Document functions & minor changes
kuroppoi May 7, 2024
64bfe48
Remove exit calls
kuroppoi May 7, 2024
da598ad
Update block mod directly in steam update (#46)
kuroppoi May 7, 2024
2d5913c
Quick fix
kuroppoi May 7, 2024
e38d4ce
Always unindex MetaBlock before re-indexing it
kuroppoi May 7, 2024
302a357
Move some things around & add purifier functionality
kuroppoi May 8, 2024
aaeb8ac
Forgot something
kuroppoi May 8, 2024
f7f201d
Change some comments
kuroppoi May 9, 2024
5f0dfae
Implement placed fieldability
kuroppoi May 10, 2024
37cc6ba
Execute unknown `AdminRequest` keys as console commands
kuroppoi May 14, 2024
8c7ae35
Implement plant growth (#51)
kuroppoi May 16, 2024
0e0a825
Change `ScavengingAchievement` to only track natural items mined
kuroppoi May 16, 2024
550e7ff
Add API support for sorting zones by newest
kuroppoi May 16, 2024
c323849
Add game panel for MacOS & rework parts of the user interface
kuroppoi May 16, 2024
24bf61f
Update README.md
kuroppoi May 18, 2024
338e168
Refactor various things (#54)
kuroppoi May 20, 2024
a0d9b40
Add multi-item trading (#52)
kuroppoi May 22, 2024
22a1366
Fix commands
kuroppoi May 22, 2024
a55fc3d
Conveyor belt using behavior tree (#55)
boraini May 28, 2024
47be50e
Commit progress
kuroppoi Jul 4, 2024
69da628
Merge branch 'feature/android-behavior' into develop
kuroppoi Jul 9, 2024
a60652c
Revert "Merge branch 'feature/android-behavior' into develop"
kuroppoi Jul 9, 2024
f3012f1
Throttle `/genzone` command
kuroppoi Sep 18, 2024
2e8527d
Add patch data for various old game versions
kuroppoi Sep 18, 2024
4f3154a
Remove unused `tick()` function
kuroppoi Sep 18, 2024
18ddfa0
Perform `isArtificial()` check on spawner switch interaction (#45))
kuroppoi Sep 18, 2024
a1d7480
Make `/teleport` command a bit better
kuroppoi Sep 20, 2024
3e8ca6b
Generate rubble inside of decayed structures
kuroppoi Sep 20, 2024
f109cef
Add zone map render API feature
kuroppoi Sep 24, 2024
630e0be
Incomplete fix for zone save bottleneck (#56)
kuroppoi Oct 21, 2024
2c10388
Increase autosave interval from 30 seconds to 5 minutes
kuroppoi Oct 21, 2024
6713a6f
Fix potential NPC kill assist crash...probably
kuroppoi Oct 26, 2024
06867d9
Reset prefab block mod if replaced item mod type is different
kuroppoi Oct 27, 2024
46bad3e
Add min and max acidity to EntitySpawn (#64)
boraini Oct 31, 2024
22ca9c5
Force inventory update if workshop item is crafted
kuroppoi Oct 31, 2024
3dadb52
Prepare for unforeseen consequences (#57)
kuroppoi Nov 4, 2024
d332f29
Landmark voting (#65)
boraini Nov 28, 2024
fbdaca2
Change `zone` into path param in `/v1/map` API request
kuroppoi Nov 29, 2024
78cc7ab
WIP string generator
kuroppoi Nov 29, 2024
f5b54dc
Update submodule deepworld-config
kuroppoi Nov 30, 2024
e15e944
Track structure generation
kuroppoi Dec 3, 2024
6853e9f
Fix luck
kuroppoi Dec 13, 2024
b0450b7
Player no longer sees a block being collected when using an hatchet (…
boraini Dec 14, 2024
8ceeafc
Add drowning (#66)
boraini Dec 14, 2024
0e8e16f
Add thirst
kuroppoi Dec 15, 2024
977e3fb
Add freezing
kuroppoi Dec 15, 2024
ea91e6c
Fix potential crash
kuroppoi Dec 17, 2024
e2b922c
Add crown store & zone ownership (#62)
kuroppoi Dec 20, 2024
0a13d5e
Players in god mode should always be able to enter any zone
kuroppoi Dec 20, 2024
b2cd679
Remove unused imports
kuroppoi Dec 20, 2024
00e9dcf
Improve (?) block update tracking
kuroppoi Dec 20, 2024
99dcc66
Oops
kuroppoi Dec 20, 2024
c4ba924
Add world ownership & membership item placement checks
kuroppoi Dec 21, 2024
a400e53
Add block placement spacing restrictions
kuroppoi Dec 21, 2024
070664a
Add extra dialog input checks
kuroppoi Dec 22, 2024
d7a8924
Catch & log dialog input handler exceptions
kuroppoi Dec 22, 2024
8fb9010
Player following system base
kuroppoi Dec 23, 2024
c682dff
Make players in god mode immune to drowning/thirst/cold
kuroppoi Dec 23, 2024
93d1ca5
Send social info on join
kuroppoi Dec 23, 2024
ca74a78
Hoo boy...
kuroppoi Dec 23, 2024
6333485
Allow followees through protectors that are configured to allow them
kuroppoi Dec 23, 2024
ca5d7ba
Add odd cases
kuroppoi Dec 23, 2024
16b0c49
Add target teleporter protected area bypass
kuroppoi Dec 23, 2024
8dad9c4
Fix player dialog exception
kuroppoi Dec 23, 2024
27b796d
Track recent & bookmarked zones
kuroppoi Dec 25, 2024
c550e20
Persist zone PvP state
kuroppoi Dec 25, 2024
2fb1908
Clear invalid bookmarks on zone enter
kuroppoi Dec 25, 2024
3e0ec84
Surely this won't break anything... right?
kuroppoi Dec 26, 2024
3a0a225
Allow `/tp` command to change zones
kuroppoi Dec 28, 2024
774d8c7
Fix blunder
kuroppoi Dec 29, 2024
0dfb22f
Check item tradeability
kuroppoi Dec 29, 2024
214cbce
Add `/crowns`command
kuroppoi Dec 29, 2024
d4874b2
Fix inventory use desync for real this time, I hope...
kuroppoi Dec 30, 2024
260d234
Refactor `drawSurfaceMap` function
kuroppoi Jan 1, 2025
5a1e5fa
Implement `PositionAchievement`
kuroppoi Jan 1, 2025
a170173
Generate proper API tokens for players
kuroppoi Jan 2, 2025
de690c5
Handle API token in zone search requests
kuroppoi Jan 2, 2025
81e4df4
Add `/api` command
kuroppoi Jan 2, 2025
69afade
Oops
kuroppoi Jan 2, 2025
fbbdfbe
Add zone entry codes
kuroppoi Jan 2, 2025
35c44f6
Fix some missing logger markers
kuroppoi Jan 2, 2025
5d3668e
Add auto rotation support for large block sizes
kuroppoi Jan 3, 2025
d43d507
Store products in ordered map
kuroppoi Jan 3, 2025
d650b75
Nerf player health regen
kuroppoi Jan 3, 2025
ecee966
Turns out, there *is* such an item...
kuroppoi Jan 4, 2025
7c71ea0
Remember player positions
kuroppoi Jan 4, 2025
f9e05eb
Rescue players who are out of bounds somehow
kuroppoi Jan 4, 2025
5abc98f
Refactor `onZoneChanged()` to `onZoneEntered()`
kuroppoi Jan 4, 2025
72e37ea
Generate bedrock at top of world in`FILLED` terrain types
kuroppoi Jan 5, 2025
4f0e2aa
Rework loot/luck system
kuroppoi Jan 5, 2025
2095f05
Add `/loot` command
kuroppoi Jan 5, 2025
a000e92
Fix compile error
kuroppoi Jan 5, 2025
64a54d3
Implement regen bonus
kuroppoi Jan 7, 2025
9c5ba6e
Oops
kuroppoi Jan 7, 2025
6fd0cd9
Spawn effect on zone enter
kuroppoi Jan 8, 2025
e2aa490
Send banned players to hell
kuroppoi Jan 8, 2025
9552c50
Fix crash
kuroppoi Jan 8, 2025
fce8e70
Only send delayed messages if channel is still open
kuroppoi Jan 8, 2025
59b0637
Rework horrid player spawning code... again
kuroppoi Jan 9, 2025
5929054
Rescue out-of-bounds players
kuroppoi Jan 9, 2025
ea2e753
Add `stack` mod type
kuroppoi Jan 9, 2025
0dc6016
Rework shutdown code a bit
kuroppoi Jan 12, 2025
ab3d3b4
Interpolate switch/touchplate messages (#76)
RueduBac Jan 19, 2025
e9b3475
Force player out of hell if they're unbanned
kuroppoi Jan 18, 2025
6ded672
Prevent dungeon switches from being blown up (#73)
kuroppoi Jan 20, 2025
bc50ed8
Minigame base + Pandora
kuroppoi Apr 22, 2025
1ebdd28
Add `PROFILE` notification type
kuroppoi Apr 22, 2025
6703dd5
Custom loot dialog titles
kuroppoi Apr 22, 2025
965117a
Pandora loot `null` check
kuroppoi Apr 22, 2025
5e4de71
Allow players in god mode to bypass Pandora potency bump check
kuroppoi Apr 25, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.github/
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/gradlew text eol=lf

# These are explicitly windows files and should use crlf
*.bat text eol=crlf

8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3.3.0
- uses: actions/checkout@v4.1.4
- name: Checkout submodules
run: git submodule update --init --recursive
- name: Set up JDK 8
uses: actions/setup-java@v3.6.0
uses: actions/setup-java@v4.2.1
with:
java-version: '8'
distribution: 'adopt'
Expand All @@ -29,8 +29,8 @@ jobs:
- name: Build with Gradle
run: ./gradlew dist
- name: Upload artifact
uses: actions/upload-artifact@v3.1.1
uses: actions/upload-artifact@v4.3.3
with:
name: brainwine
path: build/libs/brainwine.jar
path: build/dist/brainwine.jar
retention-days: 7
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Gradle
.gradle
build
!**/src/**/build

# Eclipse
*.launch
Expand All @@ -11,4 +12,4 @@ build
bin

# Misc
run
run
27 changes: 27 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#? Builder
FROM --platform=$BUILDPLATFORM debian:bookworm-slim AS builder
RUN apt update -y && apt upgrade -y && apt autoremove -y
RUN apt install -y git gradle
WORKDIR /src
COPY . /src
RUN git submodule init && git submodule update
RUN chmod +x gradlew && ./gradlew dist

#? Runner
FROM --platform=$BUILDPLATFORM amazoncorretto:22-alpine-jdk AS runner
RUN apk update && apk upgrade
VOLUME ["/data"]
WORKDIR /data
COPY --from=builder /src/build/dist /app
ARG GATEWAY_PORT=5001
ARG SERVER_PORT=5002
ARG PORTAL_PORT=5003
EXPOSE $GATEWAY_PORT $SERVER_PORT $PORTAL_PORT
CMD ["sh", "-c", "java -jar /app/brainwine.jar disablegui"]

LABEL org.opencontainers.image.title="Brainwine"
LABEL org.opencontainers.image.description=" A portable private server for Deepworld."
LABEL org.opencontainers.image.source="https://github.com/kuroppoi/brainwine"
LABEL org.opencontainers.image.licenses="MIT"
LABEL org.opencontainers.image.documentation="https://github.com/kuroppoi/brainwine"
LABEL org.opencontainers.image.vendor=""
92 changes: 55 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,53 +1,71 @@
# Brainwine
[![build](https://github.com/kuroppoi/brainwine/actions/workflows/build.yml/badge.svg)](https://github.com/kuroppoi/brainwine/actions)

Brainwine is a Deepworld private server written in Java, made with user-friendliness and portability in mind.
Due to the time it will take for this project to be complete (and my inconsistent working on it), brainwine has been prematurely open-sourced
and is free for all to use.\
Keep in mind, though, that this server is not finished yet. Expect to encounter bad code, bugs and missing features!\
Brainwine is currently compatible with the following versions of Deepworld:
- Steam: `v3.13.1`
<h1 align="center">Brainwine</h1>
<p align="center">
<a href="https://github.com/kuroppoi/brainwine/actions"><img src="https://github.com/kuroppoi/brainwine/actions/workflows/build.yml/badge.svg" alt="build"/></a>
<a href="https://github.com/kuroppoi/brainwine/releases/latest"><img src="https://img.shields.io/github/v/release/kuroppoi/brainwine?labelColor=30373D&label=Release&logoColor=959DA5&logo=github" alt="release"/></a>
</p>

Brainwine is a Deepworld private server written in Java, designed to be portable and easy to use.\
It's still a work in progress, so keep in mind that it's not yet feature-complete. (A to-do list can be found [here](https://github.com/kuroppoi/brainwine/projects/1).)\
Brainwine currently supports the following versions of Deepworld:

- Windows: `v3.13.1`
- iOS: `v2.11.0.1`
- MacOS: `v2.11.1`

## Features
A list of all planned, in-progress and finished features can be found [here.](https://github.com/kuroppoi/brainwine/projects/1)
## Quick Local Setup

- Install [Java 8](https://adoptium.net/temurin/releases/?package=jdk&version=8).
- Download the [latest Brainwine release](https://github.com/kuroppoi/brainwine/releases/latest).
- Start Brainwine by running the jar file.
- In the window that appears, press "Start Server" to start the server.
- Press "Start Deepworld" to launch the game.
- If you want to play on iOS, download a patching kit for it [here](https://github.com/kuroppoi/brainwine/releases/tag/patching-kits-1.0).
- Register a new account and play the game.

## Building

### Prerequisites

## Setup
- Java 8 Development Kit

### Setting up the client
Run the following to build the program:

Before you can connect to a server, a few modifications need to be made to the Deepworld game client.\
The exact process of this differs per platform.\
You may download an installation package for your desired platform [here.](https://github.com/kuroppoi/brainwine/releases/tag/patching-kits-1.0)
```sh
git clone --recurse-submodules https://github.com/kuroppoi/brainwine.git
cd brainwine
./gradlew dist
```

### Setting up the server
The output executable jar `brainwine.jar` will be located in the `/build/dist` directory.\
To start the server without a user interface, run the following:

#### Prerequisites
```sh
# This behavior is the default on platforms that do not support Java's Desktop API.
java -jar brainwine.jar disablegui
```

- Java 8 or newer
## Docker

You can download the latest release [here.](https://github.com/kuroppoi/brainwine/releases/latest)\
Alternatively, if you wish to build from source, clone this repository with the `--recurse-submodules` flag\
and run `gradlew dist` in the root directory of the repository.\
After the build has finished, the output jar will be located in `build/libs`.\
You may then start the server through the gui, or start it directly by running the jar with the `disablegui` flag.
Run the following to build the image:

#### Configurations
```sh
git clone https://github.com/kuroppoi/brainwine
cd brainwine
docker buildx build -t brainwine:latest .
```

On first-time startup, configuration files will be generated which you may modify however you like:
- `api.json` Configuration file for news & API connectivity information.
- `loottables.json` Configuration file for which loot may be obtained from containers.
- `spawning.json` Configuration file for entity spawns per biome.
- `generators` Folder containing configuration files for zone generators.
To then run the image in a container, run the following:

## Contributions
```sh
# Replace ${PWD} with %cd% if you're using a Windows Command Prompt.
docker run -p 5001-5003:5001-5003 --volume ${PWD}/run:/data brainwine:latest
```

Disagree with how I did something? Found a potential error? See some room for improvement? Or just want to add a feature?
Glad to hear it! Feel free to make a pull request anytime. Just make sure you follow the code style!
And, apologies in advance for the lack of documentation. Haven't gotten around to do it yet. Sorry!
Or alternatively, if you wish to use docker compose:

## Issues
```sh
docker compose up
```

Found a bug? Before posting an issue, make sure your build is up-to-date and your issue has not already been posted before.
Provide a detailed explanation of the issue, and how to reproduce it. I'll get to it ASAP!
The server files will be stored in a docker volume and can be accessed from `/data` in the container.\
Feel free to play around with the configuration by editing `docker-compose.yml`.
6 changes: 1 addition & 5 deletions api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,5 @@ repositories {

dependencies {
implementation 'io.javalin:javalin:4.6.8'
implementation project(':shared')
}

jar {
archiveBaseName = 'brainwine-api'
implementation project(':brainwine-shared')
}
6 changes: 5 additions & 1 deletion api/src/main/java/brainwine/api/DataFetcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ public interface DataFetcher {
public boolean isPlayerNameTaken(String name);
public String registerPlayer(String name);
public String login(String name, String password);
public String fetchPlayerName(String name);
public String fetchPlayerId(String apiToken);
public boolean verifyAuthToken(String name, String token);
public boolean verifyApiToken(String apiToken);
public ZoneInfo getZoneInfo(String nameOrId);
public Collection<ZoneInfo> fetchZoneInfo();
public Collection<ZoneInfo> fetchRecentZoneInfo(String apiToken);
public Collection<ZoneInfo> fetchBookmarkedZoneInfo(String apiToken);
}
24 changes: 22 additions & 2 deletions api/src/main/java/brainwine/api/DefaultDataFetcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,38 @@ public String login(String name, String password) {
throw exception;
}

@Override
public String fetchPlayerName(String name) {
throw exception;
}

@Override
public String fetchPlayerId(String apiToken) {
throw exception;
}

@Override
public boolean verifyAuthToken(String name, String token) {
throw exception;
}

@Override
public boolean verifyApiToken(String apiToken) {
public ZoneInfo getZoneInfo(String nameOrId) {
throw exception;
}

@Override
public Collection<ZoneInfo> fetchZoneInfo() {
throw exception;
}

@Override
public Collection<ZoneInfo> fetchRecentZoneInfo(String apiToken) {
throw exception;
}

@Override
public Collection<ZoneInfo> fetchBookmarkedZoneInfo(String apiToken) {
throw exception;
}
}
2 changes: 1 addition & 1 deletion api/src/main/java/brainwine/api/GatewayService.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private void handlePlayerLogin(Context ctx) {
return;
}

ctx.json(new ServerConnectInfo(api.getGameServerHost(), name, token));
ctx.json(new ServerConnectInfo(api.getGameServerHost(), dataFetcher.fetchPlayerName(name), token));
}

/**
Expand Down
118 changes: 118 additions & 0 deletions api/src/main/java/brainwine/api/MapRenderer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package brainwine.api;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

import javax.imageio.ImageIO;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import brainwine.api.models.ZoneInfo;
import brainwine.api.util.ImageUtils;

/**
* Functions for rendering zone maps.
*/
public class MapRenderer {

private static final Logger logger = LogManager.getLogger();
private static final double[] depths = { 0.03, 0.05, 0.08, 0.12, 0.17, 0.26, 0.3 };
private static final Map<String, int[]> colorMap = new HashMap<>();
private static final BufferedImage mapCrossImage;

static {
// Set color map data
colorMap.put("plain", new int[] { 0xFFFFFF, 0x5DB830, 0x417431, 0x414E1C, 0x4E441C, 0x2A240C, 0x18150B });
colorMap.put("arctic", new int[] { 0xFFFFFF, 0x75A49E, 0x456B74, 0x33535F, 0x2D4F5D, 0x142E3F, 0x0B1A25 });
colorMap.put("hell", new int[] { 0xFFFFFF, 0xBE8D6F, 0x905548, 0x7F3C32, 0x6F3932, 0x5F1814, 0x380E0D });
colorMap.put("brain", new int[] { 0xFFFFFF, 0xA19599, 0x705C6E, 0x5D4257, 0x4E3E55, 0x3B1C36, 0x2A0B28 });
colorMap.put("desert", new int[] { 0xECDE93, 0xB18E58, 0x7B5822, 0x614312, 0x4E350C, 0x322209, 0x1E1506 });
colorMap.put("space", new int[] { 0xFFFFFF, 0xEEEEEE, 0xDDDDDD, 0xCCCCCC, 0xBBBBBB, 0xAAAAAA, 0x999999 });

// Load image resources
mapCrossImage = loadImageResource("/map/crossMark.png");
}

private static BufferedImage loadImageResource(String name) {
try(InputStream inputStream = MapRenderer.class.getResourceAsStream(name)) {
return ImageIO.read(inputStream);
} catch(Exception e) {
logger.error("Failed to load image resource '{}'", name, e);
}

return null;
}

public static BufferedImage drawSurfaceMap(ZoneInfo zone) {
return drawSurfaceMap(zone.getWidth(), zone.getHeight(), zone.getBiome(), zone.getSurface());
}

/**
* Creates a surface map render that is visually almost identical to V2 client map renders.
*/
public static BufferedImage drawSurfaceMap(int width, int height, String biome, int[] surfaceArray) {
BufferedImage image = ImageUtils.createImage(300000, width, height);
Graphics2D g2d = image.createGraphics();
int[] colors = colorMap.getOrDefault(biome.toLowerCase(), colorMap.get("plain"));
int[] raster = ((DataBufferInt)image.getRaster().getDataBuffer()).getData();
int surfaceMin = height;
int surfaceMax = 0;

// Find highest & lowest surface points
for(int surface : surfaceArray) {
surfaceMin = Math.min(surfaceMin, surface);
surfaceMax = Math.max(surfaceMax, surface);
}

int surfaceCenter = (int)Math.floor((surfaceMax - surfaceMin) * 0.5 + surfaceMin);
double scaleX = (double)image.getWidth() / width;
double scaleY = (double)image.getHeight() / height;

// Fill raster with background color fast
int length = (int)(surfaceMax * scaleY) * image.getWidth();
raster[0] = 0x80808080;

for(int i = 1; i < length; i += i) {
System.arraycopy(raster, 0, raster, i, length - i < i ? length - i : i);
}

// Draw zone surface
// TODO potentially slow (largely because of Java2D) and can probably be optimized further
for(int i = 0; i < image.getWidth(); i++) {
int surface = surfaceArray[(int)(i / scaleX)];
int distanceToPeak = surface - surfaceMin;
double y = (height - surface) * scaleY;
double layerHeight = 1.0;
int start = image.getHeight() - (int)(y * layerHeight);

for(int j = 0; j < depths.length; j++) {
double scale = (double)distanceToPeak / height / depths.length * (j < 2 ? 2.0 : 0.5);
layerHeight -= (depths[j] - scale);
int end = j + 1 >= depths.length ? image.getHeight() : image.getHeight() - (int)(y * layerHeight);
g2d.setColor(new Color(colors[j > 0 || surface < surfaceCenter ? j : 1])); // Only use snow color if surface is above surface center
g2d.fillRect(i, start, 1, end - start);
start = end;
}
}

g2d.dispose();
return image;
}

/**
* Draws a red cross mark on an image at the given zone coordinates.
*/
public static void drawCrossMark(ZoneInfo zone, int x, int y, BufferedImage mapImage) {
double scaleX = (double)mapImage.getWidth() / zone.getWidth();
double scaleY = (double)mapImage.getHeight() / zone.getHeight();
Graphics2D g2d = mapImage.createGraphics();
g2d.drawImage(mapCrossImage, (int)(x * scaleX) - 24, (int)(y * scaleY) - 25, 50, 60, null);
g2d.dispose();
}
}
Loading