Save new chr to PG (doesn't work yet because no account)

This commit is contained in:
P0nk
2024-09-25 18:31:38 +02:00
parent 7335914695
commit b85233359f
4 changed files with 76 additions and 7 deletions

View File

@@ -43,10 +43,10 @@ public record CharacterStats(
int useSlots,
int setupSlots,
int etcSlots,
int monsterBookCover,
int dojoVanquisherStage,
Integer monsterBookCover,
Integer dojoVanquisherStage,
int dojoPoints,
int dojoStage,
Integer dojoStage,
boolean dojoTutorialComplete,
int dojoVanquisherKills,
int matchCardWins,
@@ -56,7 +56,7 @@ public record CharacterStats(
int omokLosses,
int omokTies,
String dataString,
long jailExpiration,
Long jailExpiration,
Integer partnerId,
Integer marriageItemId,
Long lastExpGainTime,

View File

@@ -1,19 +1,28 @@
package client.creator;
import client.CharacterStats;
import client.Job;
import client.inventory.Item;
import constants.id.ItemId;
import constants.id.MapId;
import database.PgDatabaseConnection;
import database.character.CharacterRepository;
public class CharacterCreator {
private final PgDatabaseConnection connection;
private final CharacterRepository chrRepository;
public CharacterCreator(CharacterRepository chrRepository) {
public CharacterCreator(PgDatabaseConnection connection, CharacterRepository chrRepository) {
this.connection = connection;
this.chrRepository = chrRepository;
}
public boolean createNew(NewCharacterSpec spec, int accountId, int worldId) {
int mapId = getStartingMap(spec.type());
CharacterStats stats = getStarterStats(spec, accountId, worldId);
connection.getHandle().useTransaction(h -> {
// chrRepository.insert(h, stats); // TODO: account needs to exist first
});
Item guide = getStarterGuide(spec.type());
// TODO, save:
// - character
@@ -25,6 +34,51 @@ public class CharacterCreator {
return false;
}
private CharacterStats getStarterStats(NewCharacterSpec spec, int accountId, int worldId) {
return CharacterStats.builder()
.account(accountId)
.world(worldId)
.name(spec.name())
.job(getJob(spec.type()).getId())
.gender(spec.gender())
.skin(spec.skin().getId())
.hair(spec.hair() + spec.hairColor())
.face(spec.face())
.mapId(getStartingMap(spec.type()))
.spawnPortal(0)
.level(StarterStats.LEVEL)
.exp(0)
.str(StarterStats.STR)
.dex(StarterStats.DEX)
.int_(StarterStats.INT)
.luk(StarterStats.LUK)
.maxHp(StarterStats.HP)
.hp(StarterStats.HP)
.maxMp(StarterStats.MP)
.mp(StarterStats.MP)
.fame(0)
.ap(0)
.sp(0)
.buddyCapacity(StarterStats.BUDDY_CAPACITY)
.equipSlots(StarterStats.INVENTORY_SLOTS)
.useSlots(StarterStats.INVENTORY_SLOTS)
.setupSlots(StarterStats.INVENTORY_SLOTS)
.etcSlots(StarterStats.INVENTORY_SLOTS)
.gmLevel(StarterStats.GM_LEVEL)
.gachaExp(0)
.hpMpApUsed(0)
.party(null)
.build();
}
private Job getJob(JobType type) {
return switch (type) {
case ADVENTURER -> Job.BEGINNER;
case KNIGHT_OF_CYGNUS -> Job.NOBLESSE;
case ARAN -> Job.LEGEND;
};
}
private int getStartingMap(JobType type) {
return switch (type) {
case ADVENTURER -> MapId.MUSHROOM_TOWN;

View File

@@ -0,0 +1,15 @@
package client.creator;
public class StarterStats {
public static final int LEVEL = 1;
public static final int HP = 50;
public static final int MP = 5;
public static final int STR = 12;
public static final int DEX = 5;
public static final int INT = 4;
public static final int LUK = 4;
public static final int INVENTORY_SLOTS = 24;
public static final int BUDDY_CAPACITY = 20;
public static final int GM_LEVEL = 0;
}

View File

@@ -1015,7 +1015,7 @@ public class Server {
DropProvider dropProvider = new DropProvider(new DropRepository(connection));
ShopFactory shopFactory = new ShopFactory(new ShopDao(connection));
ChannelDependencies channelDependencies = ChannelDependencies.builder()
.characterCreator(new CharacterCreator(characterRepository))
.characterCreator(new CharacterCreator(connection, characterRepository))
.characterLoader(new CharacterLoader(monsterCardRepository))
.characterSaver(characterSaver)
.noteService(noteService)