chore: merge Lanana fork

Co-authored-by: Fiereu <contact@fiereu.de>
This commit is contained in:
LananaHWPandFiereu authored and Fiereu committed 2026-05-26 16:14:38 +02:00
1 parent e8f666a37f
commit 9486b83cf4
39 files changed
+56720 -277

No files matched your search

@@ -0,0 +1,76 @@
package de.fiereu.openmmo.server.game.session
import de.fiereu.openmmo.common.enums.Direction
import io.netty.channel.Channel
import java.util.concurrent.ConcurrentHashMap
data class ScriptPage(
val type: Int = 0x04,
val unk1: Int,
val unk2: Int,
val unk3: Int,
)
data class Session(
val channel: Channel,
val userId: Int,
var characterId: Long? = null,
var justWarped: Boolean = false,
var facingDirection: Direction = Direction.DOWN,
var inDialog: Boolean = false,
var dialogNpcEntityId: Long = 0,
var dialogSeqId: Int = 0,
var dialogPages: List<ScriptPage> = emptyList(),
var dialogPageIndex: Int = 0,
var regionId: Int = 1,
var bankId: Int = 51,
var mapId: Int = 3,
var x: Short = 4,
var y: Short = 2,
)
object SessionManager {
private val sessionsByChannel = ConcurrentHashMap<Channel, Session>()
private val sessionsByCharacter = ConcurrentHashMap<Long, Session>()
fun createSession(channel: Channel, userId: Int): Session {
removeSession(channel)
val session = Session(channel, userId)
sessionsByChannel[channel] = session
return session
}
fun getSessionByChannel(channel: Channel): Session? = sessionsByChannel[channel]
fun getSessionByCharacterId(characterId: Long): Session? = sessionsByCharacter[characterId]
fun setActiveCharacter(channel: Channel, characterId: Long) {
val session = sessionsByChannel[channel] ?: return
sessionsByCharacter[characterId] = session
session.characterId = characterId
}
fun removeSession(channel: Channel) {
val session = sessionsByChannel.remove(channel)
if (session != null && session.characterId != null) {
sessionsByCharacter.remove(session.characterId)
}
}
fun getOnlineCharacterIds(): Set<Long> = sessionsByCharacter.keys
fun isOnline(characterId: Long): Boolean = sessionsByCharacter.containsKey(characterId)
fun getOthersInMap(
excludeCharacterId: Long,
regionId: Int,
bankId: Int,
mapId: Int,
): List<Session> =
sessionsByCharacter.values.filter { session ->
session.characterId != excludeCharacterId &&
session.regionId == regionId &&
session.bankId == bankId &&
session.mapId == mapId
}
}
@@ -0,0 +1,110 @@
package de.fiereu.openmmo.server.game.storage
import de.fiereu.openmmo.common.CharacterInfo
import de.fiereu.openmmo.common.Pokemon
import java.time.LocalDateTime
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.atomic.AtomicLong
data class StoredCharacter(
val info: CharacterInfo,
val pokemon: MutableList<Pokemon>,
val pcStorage: MutableList<Pokemon>,
val items: MutableMap<Int, Int>,
)
object CharacterStore {
private val characters = ConcurrentHashMap<Long, StoredCharacter>()
private val charactersByUser = ConcurrentHashMap<Int, MutableList<Long>>()
private val nextCharId = AtomicLong(1)
private val nextPokemonId = AtomicLong(1)
init {
ensureTestCharacter()
}
private fun ensureTestCharacter() {
if (characters.isEmpty()) {
createCharacter(userId = 1, name = "Test")
}
}
private fun generateEntityId(): Long {
val uniqueId = nextCharId.getAndIncrement()
return (uniqueId shl 16) or 0x9000L
}
fun createCharacter(
userId: Int,
name: String,
): StoredCharacter {
val id = generateEntityId()
val now = LocalDateTime.now()
val info =
CharacterInfo(
id = id,
name = name,
namePrefix = "",
userId = userId,
rivalSex = 0,
lastLogin = now,
createdAt = now,
money = 3000,
permissions = 8,
remainingSafariSteps = 0,
remainingSafariBalls = 0,
pcExtraSlots = 0,
battleBoxExtraSlots = 0,
templateAmount = 0,
positionRegionId = 1,
positionBankId = 51,
positionMapId = 3,
positionX = 4,
positionY = 2,
repelLeft = 0,
repelItemId = 0,
lureLeft = 0,
lureItemId = 0,
)
val stored = StoredCharacter(info, mutableListOf(), mutableListOf(), mutableMapOf())
characters[id] = stored
charactersByUser.getOrPut(userId) { mutableListOf() }.add(id)
return stored
}
fun getCharacter(id: Long): StoredCharacter? = characters[id]
fun getCharactersByUser(userId: Int): List<StoredCharacter> {
return charactersByUser[userId]?.mapNotNull { characters[it] } ?: emptyList()
}
fun updateCharacter(info: CharacterInfo) {
val stored = characters[info.id] ?: return
characters[info.id] = stored.copy(info = info)
}
fun updatePosition(
characterId: Long,
x: Short,
y: Short,
) {
val stored = characters[characterId] ?: return
val oldInfo = stored.info
val newInfo =
oldInfo.copy(
positionX = x,
positionY = y,
)
characters[characterId] = stored.copy(info = newInfo)
}
fun addPokemon(characterId: Long, pokemon: Pokemon) {
characters[characterId]?.pokemon?.add(pokemon)
}
fun addMoney(characterId: Long, amount: Int) {
val stored = characters[characterId] ?: return
val newInfo = stored.info.copy(money = stored.info.money + amount)
characters[characterId] = stored.copy(info = newInfo)
}
}
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,75 @@
create extension if not exists pgcrypto;
create table "character" (
id bigserial not null,
user_id int not null,
name varchar(16) not null unique,
name_prefix varchar(16) not null default '',
rival_sex smallint not null default 0,
created_at timestamp not null default current_timestamp,
last_login timestamp not null default current_timestamp,
money int not null default 3000,
permissions int not null default 0,
remaining_safari_steps smallint not null default 0,
remaining_safari_balls smallint not null default 0,
pc_extra_slots smallint not null default 0,
battle_box_extra_slots smallint not null default 0,
template_amount smallint not null default 0,
position_region_id smallint not null default 0,
position_bank_id smallint not null default 1,
position_map_id smallint not null default 1,
position_x smallint not null default 100,
position_y smallint not null default 100,
repel_left smallint not null default 0,
repel_item_id smallint not null default 0,
lure_left smallint not null default 0,
lure_item_id smallint not null default 0,
primary key (id)
);
create table pokemon (
id bigserial not null,
character_id bigint not null,
container smallint not null default 0,
container_slot smallint not null default 0,
dex_id int not null,
seed int not null,
ot varchar(16) not null,
nickname varchar(32) not null,
level smallint not null default 1,
hp smallint not null default 10,
xp int not null default 0,
ivs int not null default 0,
ev_hp smallint not null default 0,
ev_atk smallint not null default 0,
ev_def smallint not null default 0,
ev_spatk smallint not null default 0,
ev_spdef smallint not null default 0,
ev_spd smallint not null default 0,
move1_id smallint not null default 0,
move1_pp smallint not null default 0,
move2_id smallint not null default 0,
move2_pp smallint not null default 0,
move3_id smallint not null default 0,
move3_pp smallint not null default 0,
move4_id smallint not null default 0,
move4_pp smallint not null default 0,
is_shiny boolean not null default false,
has_hidden_ability boolean not null default false,
is_alpha boolean not null default false,
is_secret boolean not null default false,
is_fateful_encounter boolean not null default false,
is_raid_encounter boolean not null default false,
caught_at timestamp not null default current_timestamp,
primary key (id),
foreign key (character_id) references "character"(id) on delete cascade
);
create table item (
id bigserial not null,
character_id bigint not null,
item_id int not null,
amount int not null default 1,
primary key (id),
foreign key (character_id) references "character"(id) on delete cascade
);