mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-12-22 11:20:05 +00:00
Implemented saving inventory and nanos
This commit is contained in:
parent
fc57cae37d
commit
2fd7a8c6fc
@ -129,8 +129,8 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
|
||||
loginSessions[sock].characters[UID] = Player(*it);
|
||||
loginSessions[sock].characters[UID].FEKey = sock->getFEKey();
|
||||
|
||||
//temporary inventory stuff
|
||||
for (int i = 0; i < 4; i++) {
|
||||
//Equip info
|
||||
for (int i = 0; i < AEQUIP_COUNT; i++) {
|
||||
//equip char creation clothes and lightning rifle
|
||||
charInfo.aEquip[i] = it->Equip[i];
|
||||
}
|
||||
@ -238,12 +238,9 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
|
||||
std::cout << "\tiEquipUBID: " << (int)character->sOn_Item.iEquipUBID << std::endl;
|
||||
std::cout << "\tiEquipLBID: " << (int)character->sOn_Item.iEquipLBID << std::endl;
|
||||
std::cout << "\tiEquipFootID: " << (int)character->sOn_Item.iEquipFootID << std::endl;
|
||||
)
|
||||
|
||||
Player player =
|
||||
Database::DbToPlayer(
|
||||
Database::getDbPlayerById(character->PCStyle.iPC_UID)
|
||||
);
|
||||
)
|
||||
|
||||
Player player = Database::getPlayer(character->PCStyle.iPC_UID);
|
||||
int64_t UID = player.iID;
|
||||
|
||||
INITSTRUCT(sP_LS2CL_REP_CHAR_CREATE_SUCC, resp);
|
||||
@ -322,11 +319,11 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
|
||||
return;
|
||||
sP_CL2LS_REQ_SAVE_CHAR_TUTOR* save = (sP_CL2LS_REQ_SAVE_CHAR_TUTOR*)data->buf;
|
||||
Database::finishTutorial(save->iPC_UID);
|
||||
loginSessions[sock].characters[save->iPC_UID].PCStyle2.iTutorialFlag = 1;
|
||||
loginSessions[sock].characters[save->iPC_UID].Equip[0].iID = 328;
|
||||
loginSessions[sock].characters[save->iPC_UID].Equip[0].iType = 0;
|
||||
loginSessions[sock].characters[save->iPC_UID].Equip[0].iOpt = 1;
|
||||
|
||||
//update character in session
|
||||
auto key = loginSessions[sock].characters[save->iPC_UID].FEKey;
|
||||
loginSessions[sock].characters[save->iPC_UID] = Player(Database::getPlayer(save->iPC_UID));
|
||||
loginSessions[sock].characters[save->iPC_UID].FEKey = key;
|
||||
//no response here
|
||||
break;
|
||||
}
|
||||
case P_CL2LS_REQ_CHANGE_CHAR_NAME: {
|
||||
|
244
src/Database.cpp
244
src/Database.cpp
@ -26,6 +26,9 @@ auto db = make_storage("database.db",
|
||||
make_column("Firstname", &Database::DbPlayer::FirstName),
|
||||
make_column("LastName", &Database::DbPlayer::LastName),
|
||||
make_column("Level", &Database::DbPlayer::Level),
|
||||
make_column("Nano1", &Database::DbPlayer::Nano1),
|
||||
make_column("Nano2", &Database::DbPlayer::Nano2),
|
||||
make_column("Nano3", &Database::DbPlayer::Nano3),
|
||||
make_column("AppearanceFlag", &Database::DbPlayer::AppearanceFlag),
|
||||
make_column("TutorialFlag", &Database::DbPlayer::TutorialFlag),
|
||||
make_column("PayZoneFlag", &Database::DbPlayer::PayZoneFlag),
|
||||
@ -35,10 +38,6 @@ auto db = make_storage("database.db",
|
||||
make_column("Angle", &Database::DbPlayer::angle),
|
||||
make_column("Body", &Database::DbPlayer::Body),
|
||||
make_column("Class", &Database::DbPlayer::Class),
|
||||
make_column("EquipFoot", &Database::DbPlayer::EquipFoot),
|
||||
make_column("EquipLB", &Database::DbPlayer::EquipLB),
|
||||
make_column("EquipUB", &Database::DbPlayer::EquipUB),
|
||||
make_column("EquipWeapon1", &Database::DbPlayer::EquipWeapon1),
|
||||
make_column("EyeColor", &Database::DbPlayer::EyeColor),
|
||||
make_column("FaceStyle", &Database::DbPlayer::FaceStyle),
|
||||
make_column("Gender", &Database::DbPlayer::Gender),
|
||||
@ -54,7 +53,18 @@ auto db = make_storage("database.db",
|
||||
make_column("PCState", &Database::DbPlayer::PCState)
|
||||
),
|
||||
make_table("Inventory",
|
||||
make_column("AccountID", &Database::Inventory::AccountID, primary_key())
|
||||
make_column("PlayerId", &Database::Inventory::playerId),
|
||||
make_column("Slot", &Database::Inventory::slot),
|
||||
make_column("Id", &Database::Inventory::id),
|
||||
make_column("Type", &Database::Inventory::Type),
|
||||
make_column("Opt", &Database::Inventory::Opt),
|
||||
make_column("TimeLimit", &Database::Inventory::TimeLimit)
|
||||
),
|
||||
make_table("Nanos",
|
||||
make_column("PlayerId", &Database::Nano::playerId),
|
||||
make_column("Id", &Database::Nano::iID),
|
||||
make_column("Skill", &Database::Nano::iSkillID),
|
||||
make_column("Stamina", &Database::Nano::iStamina)
|
||||
)
|
||||
);
|
||||
|
||||
@ -132,11 +142,6 @@ int Database::createCharacter(sP_CL2LS_REQ_SAVE_CHAR_NAME* save, int AccountID)
|
||||
//create default body character
|
||||
create.Body= 0;
|
||||
create.Class= 0;
|
||||
create.EquipFoot= 0;
|
||||
create.EquipLB= 0;
|
||||
create.EquipUB= 0;
|
||||
create.EquipWeapon1= 0;
|
||||
create.EquipWeapon2= 0;
|
||||
create.EyeColor= 1;
|
||||
create.FaceStyle= 1;
|
||||
create.Gender= 1;
|
||||
@ -168,9 +173,6 @@ void Database::finishCharacter(sP_CL2LS_REQ_CHAR_CREATE* character)
|
||||
finish.AppearanceFlag = 1;
|
||||
finish.Body = character->PCStyle.iBody;
|
||||
finish.Class = character->PCStyle.iClass;
|
||||
finish.EquipFoot = character->sOn_Item.iEquipFootID;
|
||||
finish.EquipLB = character->sOn_Item.iEquipLBID;
|
||||
finish.EquipUB = character->sOn_Item.iEquipUBID;
|
||||
finish.EyeColor = character->PCStyle.iEyeColor;
|
||||
finish.FaceStyle = character->PCStyle.iFaceStyle;
|
||||
finish.Gender = character->PCStyle.iGender;
|
||||
@ -180,14 +182,52 @@ void Database::finishCharacter(sP_CL2LS_REQ_CHAR_CREATE* character)
|
||||
finish.Level = 1;
|
||||
finish.SkinColor = character->PCStyle.iSkinColor;
|
||||
db.update(finish);
|
||||
//clothes
|
||||
Inventory Foot, LB, UB;
|
||||
Foot.playerId = character->PCStyle.iPC_UID;
|
||||
Foot.id = character->sOn_Item.iEquipFootID;
|
||||
Foot.Type = 3;
|
||||
Foot.slot = 3;
|
||||
Foot.Opt = 1;
|
||||
Foot.TimeLimit = 0;
|
||||
db.insert(Foot);
|
||||
LB.playerId = character->PCStyle.iPC_UID;
|
||||
LB.id = character->sOn_Item.iEquipLBID;
|
||||
LB.Type = 2;
|
||||
LB.slot = 2;
|
||||
LB.Opt = 1;
|
||||
LB.TimeLimit = 0;
|
||||
db.insert(LB);
|
||||
UB.playerId = character->PCStyle.iPC_UID;
|
||||
UB.id = character->sOn_Item.iEquipUBID;
|
||||
UB.Type = 1;
|
||||
UB.slot = 1;
|
||||
UB.Opt = 1;
|
||||
UB.TimeLimit = 0;
|
||||
db.insert(UB);
|
||||
}
|
||||
|
||||
void Database::finishTutorial(int PlayerID)
|
||||
{
|
||||
//set flag
|
||||
DbPlayer finish = getDbPlayerById(PlayerID);
|
||||
finish.TutorialFlag = 1;
|
||||
//equip lightning gun
|
||||
finish.EquipWeapon1 = 328;
|
||||
finish.TutorialFlag = 1;
|
||||
//add Gun
|
||||
Inventory LightningGun = {};
|
||||
LightningGun.playerId = PlayerID;
|
||||
LightningGun.id = 328;
|
||||
LightningGun.slot = 0;
|
||||
LightningGun.Type = 0;
|
||||
LightningGun.Opt = 1;
|
||||
db.insert(LightningGun);
|
||||
//add Nano
|
||||
Nano Buttercup = {};
|
||||
Buttercup.playerId = PlayerID;
|
||||
Buttercup.iID = 1;
|
||||
Buttercup.iSkillID = 1;
|
||||
Buttercup.iStamina = 150;
|
||||
finish.Nano1 = 1;
|
||||
db.insert(Buttercup);
|
||||
db.update(finish);
|
||||
}
|
||||
|
||||
@ -265,14 +305,9 @@ Database::DbPlayer Database::playerToDb(Player player)
|
||||
result.y_coordinates = player.y;
|
||||
result.z_coordinates = player.z;
|
||||
result.angle = player.angle;
|
||||
result.PCState = player.iPCState;
|
||||
|
||||
//temporary inventory stuff
|
||||
result.EquipWeapon1 = player.Equip[0].iID;
|
||||
result.EquipUB = player.Equip[1].iID;
|
||||
result.EquipLB = player.Equip[2].iID;
|
||||
result.EquipFoot = player.Equip[3].iID;
|
||||
|
||||
result.Nano1 = player.equippedNanos[0];
|
||||
result.Nano2 = player.equippedNanos[1];
|
||||
result.Nano3 = player.equippedNanos[2];
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -309,62 +344,12 @@ Player Database::DbToPlayer(DbPlayer player) {
|
||||
result.money = player.Taros;
|
||||
result.fusionmatter = player.FusionMatter;
|
||||
|
||||
//TODO:: implement all of below
|
||||
result.SerialKey = 0;
|
||||
result.activeNano = 0;
|
||||
result.iPCState = 0;
|
||||
result.equippedNanos[0] = 1;
|
||||
result.equippedNanos[1] = 0;
|
||||
result.equippedNanos[2] = 0;
|
||||
result.isTrading = false;
|
||||
result.isTradeConfirm = false;
|
||||
//TODO:: implement all of below
|
||||
|
||||
//Nanos
|
||||
result.activeNano = -1;
|
||||
result.equippedNanos[0] = 0;
|
||||
result.equippedNanos[1] = 0;
|
||||
result.equippedNanos[2] = 0;
|
||||
|
||||
result.Nanos[0].iID = 0;
|
||||
result.Nanos[0].iSkillID = 0;
|
||||
result.Nanos[0].iStamina = 0;
|
||||
|
||||
for (int i = 1; i < 37; i++) {
|
||||
result.Nanos[i].iID = i;
|
||||
result.Nanos[i].iSkillID = 1;
|
||||
result.Nanos[i].iStamina = 150;
|
||||
}
|
||||
|
||||
//equip
|
||||
result.Equip[0].iID = player.EquipWeapon1;
|
||||
result.Equip[0].iType = 0;
|
||||
(player.EquipWeapon1) ? result.Equip[0].iOpt = 1 : result.Equip[0].iOpt = 0;
|
||||
|
||||
result.Equip[1].iID = player.EquipUB;
|
||||
result.Equip[1].iType = 1;
|
||||
(player.EquipUB) ? result.Equip[1].iOpt = 1 : result.Equip[1].iOpt = 0;
|
||||
|
||||
result.Equip[2].iID = player.EquipLB;
|
||||
result.Equip[2].iType = 2;
|
||||
(player.EquipLB) ? result.Equip[2].iOpt = 1 : result.Equip[2].iOpt = 0;
|
||||
|
||||
result.Equip[3].iID = player.EquipFoot;
|
||||
result.Equip[3].iType = 3;
|
||||
(player.EquipFoot) ? result.Equip[3].iOpt = 1 : result.Equip[3].iOpt = 0;
|
||||
|
||||
for (int i = 4; i < AEQUIP_COUNT; i++) {
|
||||
// empty equips
|
||||
result.Equip[i].iID = 0;
|
||||
result.Equip[i].iType = 0;
|
||||
result.Equip[i].iOpt = 0;
|
||||
}
|
||||
for (int i = 0; i < AINVEN_COUNT; i++) {
|
||||
// setup inventories
|
||||
result.Inven[i].iID = 0;
|
||||
result.Inven[i].iType = 0;
|
||||
result.Inven[i].iOpt = 0;
|
||||
}
|
||||
result.equippedNanos[0] = player.Nano1;
|
||||
result.equippedNanos[1] = player.Nano2;
|
||||
result.equippedNanos[2] = player.Nano3;
|
||||
|
||||
Database::getInventory(&result);
|
||||
Database::getNanos(&result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -373,9 +358,108 @@ Database::DbPlayer Database::getDbPlayerById(int id) {
|
||||
.front();
|
||||
}
|
||||
|
||||
Player Database::getPlayer(int id) {
|
||||
return DbToPlayer(
|
||||
getDbPlayerById(id)
|
||||
);
|
||||
}
|
||||
|
||||
#pragma endregion LoginServer
|
||||
|
||||
void Database::updatePlayer(Player player) {
|
||||
DbPlayer toUpdate = playerToDb(player);
|
||||
db.update(toUpdate);
|
||||
updateInventory(player);
|
||||
updateNanos(player);
|
||||
}
|
||||
|
||||
void Database::updateInventory(Player player) {
|
||||
//start transaction
|
||||
db.begin_transaction();
|
||||
//remove all previous items
|
||||
db.remove_all<Inventory>(
|
||||
where(c(&Inventory::playerId) == player.iID)
|
||||
);
|
||||
//insert equip
|
||||
for (int i = 0; i < AEQUIP_COUNT; i++) {
|
||||
if (player.Equip[i].iID != 0) {
|
||||
sItemBase* next = &player.Equip[i];
|
||||
Inventory toAdd = {};
|
||||
toAdd.playerId = player.iID;
|
||||
toAdd.slot = i;
|
||||
toAdd.id = next->iID;
|
||||
toAdd.Opt = next->iOpt;
|
||||
toAdd.Type = next->iType;
|
||||
toAdd.TimeLimit = next->iTimeLimit;
|
||||
db.insert(toAdd);
|
||||
}
|
||||
}
|
||||
//insert inventory
|
||||
for (int i = 0; i < AINVEN_COUNT; i++) {
|
||||
if (player.Inven[i].iID != 0) {
|
||||
sItemBase* next = &player.Inven[i];
|
||||
Inventory toAdd = {};
|
||||
toAdd.playerId = player.iID;
|
||||
toAdd.slot = i + AEQUIP_COUNT;
|
||||
toAdd.id = next->iID;
|
||||
toAdd.Opt = next->iOpt;
|
||||
toAdd.Type = next->iType;
|
||||
toAdd.TimeLimit = next->iTimeLimit;
|
||||
db.insert(toAdd);
|
||||
}
|
||||
}
|
||||
db.commit();
|
||||
}
|
||||
void Database::updateNanos(Player player) {
|
||||
//start transaction
|
||||
db.begin_transaction();
|
||||
//remove all
|
||||
db.remove_all<Nano>(
|
||||
where(c(&Nano::playerId) == player.iID)
|
||||
);
|
||||
//insert
|
||||
int i = 1;
|
||||
while ((i<SIZEOF_NANO_BANK_SLOT)&&(player.Nanos[i]).iID!=0){
|
||||
Nano toAdd = {};
|
||||
sNano* next = &player.Nanos[i];
|
||||
toAdd.playerId = player.iID;
|
||||
toAdd.iID = next->iID;
|
||||
toAdd.iSkillID = next->iSkillID;
|
||||
toAdd.iStamina = next->iStamina;
|
||||
db.insert(toAdd);
|
||||
i++;
|
||||
}
|
||||
db.commit();
|
||||
}
|
||||
void Database::getInventory(Player* player) {
|
||||
//get items from DB
|
||||
auto items = db.get_all<Inventory>(
|
||||
where(c(&Inventory::playerId) == player->iID)
|
||||
);
|
||||
//set items
|
||||
for (const Inventory ¤t : items) {
|
||||
sItemBase toSet = {};
|
||||
toSet.iID = current.id;
|
||||
toSet.iType = current.Type;
|
||||
toSet.iOpt = current.Opt;
|
||||
toSet.iTimeLimit = current.TimeLimit;
|
||||
if (current.slot > AEQUIP_COUNT)
|
||||
player->Inven[current.slot - AEQUIP_COUNT] = toSet;
|
||||
else
|
||||
player->Equip[current.slot] = toSet;
|
||||
}
|
||||
|
||||
}
|
||||
void Database::getNanos(Player* player) {
|
||||
//get from DB
|
||||
auto nanos = db.get_all<Nano>(
|
||||
where(c(&Nano::playerId) == player->iID)
|
||||
);
|
||||
//set
|
||||
for (const Nano& current : nanos) {
|
||||
sNano *toSet = &player->Nanos[current.iID];
|
||||
toSet->iID = current.iID;
|
||||
toSet->iSkillID = current.iSkillID;
|
||||
toSet->iStamina = current.iStamina;
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,18 @@ namespace Database {
|
||||
};
|
||||
struct Inventory
|
||||
{
|
||||
int AccountID;
|
||||
int playerId;
|
||||
int slot;
|
||||
int16_t Type;
|
||||
int16_t id;
|
||||
int32_t Opt;
|
||||
int32_t TimeLimit;
|
||||
};
|
||||
struct Nano {
|
||||
int playerId;
|
||||
int16_t iID;
|
||||
int16_t iSkillID;
|
||||
int16_t iStamina;
|
||||
};
|
||||
struct DbPlayer
|
||||
{
|
||||
@ -25,22 +36,20 @@ namespace Database {
|
||||
short int slot;
|
||||
std::string FirstName;
|
||||
std::string LastName;
|
||||
short int Level;
|
||||
int Nano1;
|
||||
int Nano2;
|
||||
int Nano3;
|
||||
short int AppearanceFlag;
|
||||
short int Body;
|
||||
short int Class;
|
||||
short int EquipFoot;
|
||||
short int EquipLB;
|
||||
short int EquipUB;
|
||||
short int EquipWeapon1;
|
||||
short int EquipWeapon2;
|
||||
short int EyeColor;
|
||||
short int FaceStyle;
|
||||
short int Gender;
|
||||
int HP;
|
||||
short int HairColor;
|
||||
short int HairStyle;
|
||||
short int Height;
|
||||
short int Level;
|
||||
short int Height;
|
||||
short int NameCheck;
|
||||
short int PayZoneFlag;
|
||||
short int SkinColor;
|
||||
@ -89,6 +98,12 @@ namespace Database {
|
||||
|
||||
//getting players
|
||||
DbPlayer getDbPlayerById(int id);
|
||||
Player getPlayer(int id);
|
||||
|
||||
void updatePlayer(Player player);
|
||||
void updateInventory(Player player);
|
||||
void updateNanos(Player player);
|
||||
|
||||
void getInventory(Player* player);
|
||||
void getNanos(Player* player);
|
||||
}
|
||||
|
@ -204,7 +204,7 @@ void PlayerManager::enterPlayer(CNSocket* sock, CNPacketData* data) {
|
||||
|
||||
response.iID = plr.iID;
|
||||
response.uiSvrTime = getTime();
|
||||
response.PCLoadData2CL.iUserLevel = 1;
|
||||
response.PCLoadData2CL.iUserLevel = plr.level;
|
||||
response.PCLoadData2CL.iHP = plr.HP;
|
||||
response.PCLoadData2CL.iLevel = plr.level;
|
||||
response.PCLoadData2CL.iCandy = plr.money;
|
||||
@ -215,26 +215,25 @@ void PlayerManager::enterPlayer(CNSocket* sock, CNPacketData* data) {
|
||||
response.PCLoadData2CL.iY = plr.y;
|
||||
response.PCLoadData2CL.iZ = plr.z;
|
||||
response.PCLoadData2CL.iAngle = plr.angle;
|
||||
response.PCLoadData2CL.iActiveNanoSlotNum = plr.activeNano;
|
||||
|
||||
response.PCLoadData2CL.iActiveNanoSlotNum = -1;
|
||||
response.PCLoadData2CL.iFatigue = 50;
|
||||
response.PCLoadData2CL.PCStyle = plr.PCStyle;
|
||||
response.PCLoadData2CL.PCStyle2 = plr.PCStyle2;
|
||||
|
||||
//inventory
|
||||
for (int i = 0; i < AEQUIP_COUNT; i++)
|
||||
response.PCLoadData2CL.aEquip[i] = plr.Equip[i];
|
||||
|
||||
for (int i = 0; i < AINVEN_COUNT; i++)
|
||||
response.PCLoadData2CL.aInven[i] = plr.Inven[i];
|
||||
|
||||
// don't ask..
|
||||
for (int i = 1; i < 37; i++) {
|
||||
//nanos
|
||||
for (int i = 1; i < SIZEOF_NANO_BANK_SLOT; i++) {
|
||||
response.PCLoadData2CL.aNanoBank[i] = plr.Nanos[i];
|
||||
}
|
||||
|
||||
// temporarily not add nanos for nano add test through commands
|
||||
//response.PCLoadData2CL.aNanoSlots[0] = 1;
|
||||
//response.PCLoadData2CL.aNanoSlots[1] = 2;
|
||||
//response.PCLoadData2CL.aNanoSlots[2] = 3;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
response.PCLoadData2CL.aNanoSlots[i] = plr.equippedNanos[i];
|
||||
}
|
||||
response.PCLoadData2CL.aQuestFlag[0] = -1;
|
||||
|
||||
// shut Computress up
|
||||
response.PCLoadData2CL.iFirstUseFlag1 = UINT64_MAX;
|
||||
|
Loading…
Reference in New Issue
Block a user