Save new chr to PG (doesn't work yet because no account)
This commit is contained in:
@@ -43,10 +43,10 @@ public record CharacterStats(
|
|||||||
int useSlots,
|
int useSlots,
|
||||||
int setupSlots,
|
int setupSlots,
|
||||||
int etcSlots,
|
int etcSlots,
|
||||||
int monsterBookCover,
|
Integer monsterBookCover,
|
||||||
int dojoVanquisherStage,
|
Integer dojoVanquisherStage,
|
||||||
int dojoPoints,
|
int dojoPoints,
|
||||||
int dojoStage,
|
Integer dojoStage,
|
||||||
boolean dojoTutorialComplete,
|
boolean dojoTutorialComplete,
|
||||||
int dojoVanquisherKills,
|
int dojoVanquisherKills,
|
||||||
int matchCardWins,
|
int matchCardWins,
|
||||||
@@ -56,7 +56,7 @@ public record CharacterStats(
|
|||||||
int omokLosses,
|
int omokLosses,
|
||||||
int omokTies,
|
int omokTies,
|
||||||
String dataString,
|
String dataString,
|
||||||
long jailExpiration,
|
Long jailExpiration,
|
||||||
Integer partnerId,
|
Integer partnerId,
|
||||||
Integer marriageItemId,
|
Integer marriageItemId,
|
||||||
Long lastExpGainTime,
|
Long lastExpGainTime,
|
||||||
|
|||||||
@@ -1,19 +1,28 @@
|
|||||||
package client.creator;
|
package client.creator;
|
||||||
|
|
||||||
|
import client.CharacterStats;
|
||||||
|
import client.Job;
|
||||||
import client.inventory.Item;
|
import client.inventory.Item;
|
||||||
import constants.id.ItemId;
|
import constants.id.ItemId;
|
||||||
import constants.id.MapId;
|
import constants.id.MapId;
|
||||||
|
import database.PgDatabaseConnection;
|
||||||
import database.character.CharacterRepository;
|
import database.character.CharacterRepository;
|
||||||
|
|
||||||
public class CharacterCreator {
|
public class CharacterCreator {
|
||||||
|
private final PgDatabaseConnection connection;
|
||||||
private final CharacterRepository chrRepository;
|
private final CharacterRepository chrRepository;
|
||||||
|
|
||||||
public CharacterCreator(CharacterRepository chrRepository) {
|
public CharacterCreator(PgDatabaseConnection connection, CharacterRepository chrRepository) {
|
||||||
|
this.connection = connection;
|
||||||
this.chrRepository = chrRepository;
|
this.chrRepository = chrRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean createNew(NewCharacterSpec spec, int accountId, int worldId) {
|
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());
|
Item guide = getStarterGuide(spec.type());
|
||||||
// TODO, save:
|
// TODO, save:
|
||||||
// - character
|
// - character
|
||||||
@@ -25,6 +34,51 @@ public class CharacterCreator {
|
|||||||
return false;
|
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) {
|
private int getStartingMap(JobType type) {
|
||||||
return switch (type) {
|
return switch (type) {
|
||||||
case ADVENTURER -> MapId.MUSHROOM_TOWN;
|
case ADVENTURER -> MapId.MUSHROOM_TOWN;
|
||||||
|
|||||||
15
src/main/java/client/creator/StarterStats.java
Normal file
15
src/main/java/client/creator/StarterStats.java
Normal 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;
|
||||||
|
}
|
||||||
@@ -1015,7 +1015,7 @@ public class Server {
|
|||||||
DropProvider dropProvider = new DropProvider(new DropRepository(connection));
|
DropProvider dropProvider = new DropProvider(new DropRepository(connection));
|
||||||
ShopFactory shopFactory = new ShopFactory(new ShopDao(connection));
|
ShopFactory shopFactory = new ShopFactory(new ShopDao(connection));
|
||||||
ChannelDependencies channelDependencies = ChannelDependencies.builder()
|
ChannelDependencies channelDependencies = ChannelDependencies.builder()
|
||||||
.characterCreator(new CharacterCreator(characterRepository))
|
.characterCreator(new CharacterCreator(connection, characterRepository))
|
||||||
.characterLoader(new CharacterLoader(monsterCardRepository))
|
.characterLoader(new CharacterLoader(monsterCardRepository))
|
||||||
.characterSaver(characterSaver)
|
.characterSaver(characterSaver)
|
||||||
.noteService(noteService)
|
.noteService(noteService)
|
||||||
|
|||||||
Reference in New Issue
Block a user