Reimplement the bank

This commit is contained in:
Kamil 2020-12-04 00:58:10 +01:00 committed by Gent S
parent c709d458f4
commit 889fc985c4
3 changed files with 53 additions and 10 deletions

View File

@ -859,19 +859,33 @@ void Database::getPlayer(Player* plr, int id) {
sql = R"( sql = R"(
SELECT "Slot", "Type", "Id", "Opt", "TimeLimit" from Inventory SELECT "Slot", "Type", "Id", "Opt", "TimeLimit" from Inventory
WHERE "PlayerID" = ? AND "Slot" < ? WHERE "PlayerID" = ?;
)"; )";
sqlite3_prepare_v2(db, sql, -1, &stmt, 0); sqlite3_prepare_v2(db, sql, -1, &stmt, 0);
sqlite3_bind_int(stmt, 1, id); sqlite3_bind_int(stmt, 1, id);
// we don't want bank items here
sqlite3_bind_int(stmt, 2, AEQUIP_COUNT + AINVEN_COUNT);
while (sqlite3_step(stmt) == SQLITE_ROW) { while (sqlite3_step(stmt) == SQLITE_ROW) {
int slot = sqlite3_column_int(stmt, 0); int slot = sqlite3_column_int(stmt, 0);
sItemBase* item = slot < AEQUIP_COUNT ? &plr->Equip[slot] : &plr->Inven[slot = AEQUIP_COUNT]; // for extra safety
if (slot > AEQUIP_COUNT + AINVEN_COUNT + ABANK_COUNT) {
std::cout << "[WARN] Database: Invalid item slot in db?! " << std::endl;
continue;
}
sItemBase* item;
if (slot < AEQUIP_COUNT)
//equipment
item = &plr->Equip[slot];
else if (slot < (AEQUIP_COUNT + AINVEN_COUNT))
//inventory
item = &plr->Inven[slot - AEQUIP_COUNT];
else
//bank
item = &plr->Bank[slot - AEQUIP_COUNT - AINVEN_COUNT];
item->iType = sqlite3_column_int(stmt, 1); item->iType = sqlite3_column_int(stmt, 1);
item->iID = sqlite3_column_int(stmt, 2); item->iID = sqlite3_column_int(stmt, 2);
item->iOpt = sqlite3_column_int(stmt, 3); item->iOpt = sqlite3_column_int(stmt, 3);
@ -1069,6 +1083,27 @@ void Database::updatePlayer(Player *player) {
sqlite3_reset(stmt); sqlite3_reset(stmt);
} }
for (int i = 0; i < ABANK_COUNT; i++) {
if (player->Bank[i].iID == 0)
continue;
sqlite3_bind_int(stmt, 1, player->iID);
sqlite3_bind_int(stmt, 2, i + AEQUIP_COUNT + AINVEN_COUNT);
sqlite3_bind_int(stmt, 3, player->Bank[i].iType);
sqlite3_bind_int(stmt, 4, player->Bank[i].iOpt);
sqlite3_bind_int(stmt, 5, player->Bank[i].iID);
sqlite3_bind_int(stmt, 6, player->Bank[i].iTimeLimit);
if (sqlite3_step(stmt) != SQLITE_DONE) {
sqlite3_exec(db, "ROLLBACK TRANSACTION", NULL, NULL, NULL);
sqlite3_finalize(stmt);
std::cout << "[WARN] Database: Failed to save player to database" << std::endl;
return;
}
sqlite3_reset(stmt);
}
// Update Quest Inventory // Update Quest Inventory
sql = R"( sql = R"(
DELETE FROM "QuestItems" WHERE "PlayerID" = ?; DELETE FROM "QuestItems" WHERE "PlayerID" = ?;
@ -1197,6 +1232,13 @@ void Database::updateBuddies(Player* player) {
void Database::removeExpiredVehicles(Player* player) { void Database::removeExpiredVehicles(Player* player) {
int32_t currentTime = getTimestamp(); int32_t currentTime = getTimestamp();
//if there are expired vehicles in bank just remove them silently
for (int i = 0; i < ABANK_COUNT; i++) {
if (player->Bank[i].iType == 10 && player->Bank[i].iTimeLimit < currentTime) {
memset(&player->Bank[i], 0, sizeof(sItemBase));
}
}
// we want to leave only 1 expired vehicle on player to delete it with the client packet // we want to leave only 1 expired vehicle on player to delete it with the client packet
std::vector<sItemBase*> toRemove; std::vector<sItemBase*> toRemove;

View File

@ -74,9 +74,9 @@ void ItemManager::itemMoveHandler(CNSocket* sock, CNPacketData* data) {
case SlotType::INVENTORY: case SlotType::INVENTORY:
fromItem = &plr->Inven[itemmove->iFromSlotNum]; fromItem = &plr->Inven[itemmove->iFromSlotNum];
break; break;
/*case SlotType::BANK: case SlotType::BANK:
fromItem = &plr->Bank[itemmove->iFromSlotNum]; fromItem = &plr->Bank[itemmove->iFromSlotNum];
break;*/ break;
default: default:
std::cout << "[WARN] MoveItem submitted unknown Item Type?! " << itemmove->eFrom << std::endl; std::cout << "[WARN] MoveItem submitted unknown Item Type?! " << itemmove->eFrom << std::endl;
return; return;
@ -91,9 +91,9 @@ void ItemManager::itemMoveHandler(CNSocket* sock, CNPacketData* data) {
case SlotType::INVENTORY: case SlotType::INVENTORY:
toItem = &plr->Inven[itemmove->iToSlotNum]; toItem = &plr->Inven[itemmove->iToSlotNum];
break; break;
//case SlotType::BANK: case SlotType::BANK:
// toItem = &plr->Bank[itemmove->iToSlotNum]; toItem = &plr->Bank[itemmove->iToSlotNum];
// break; break;
default: default:
std::cout << "[WARN] MoveItem submitted unknown Item Type?! " << itemmove->eTo << std::endl; std::cout << "[WARN] MoveItem submitted unknown Item Type?! " << itemmove->eTo << std::endl;
return; return;
@ -320,7 +320,7 @@ void ItemManager::itemBankOpenHandler(CNSocket* sock, CNPacketData* data) {
// just send bank inventory // just send bank inventory
INITSTRUCT(sP_FE2CL_REP_PC_BANK_OPEN_SUCC, resp); INITSTRUCT(sP_FE2CL_REP_PC_BANK_OPEN_SUCC, resp);
for (int i = 0; i < ABANK_COUNT; i++) { for (int i = 0; i < ABANK_COUNT; i++) {
//resp.aBank[i] = plr->Bank[i]; resp.aBank[i] = plr->Bank[i];
} }
resp.iExtraBank = 1; resp.iExtraBank = 1;
sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_BANK_OPEN_SUCC, sizeof(sP_FE2CL_REP_PC_BANK_OPEN_SUCC)); sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_BANK_OPEN_SUCC, sizeof(sP_FE2CL_REP_PC_BANK_OPEN_SUCC));

View File

@ -44,6 +44,7 @@ struct Player {
uint64_t instanceID; uint64_t instanceID;
sItemBase Equip[AEQUIP_COUNT]; sItemBase Equip[AEQUIP_COUNT];
sItemBase Inven[AINVEN_COUNT]; sItemBase Inven[AINVEN_COUNT];
sItemBase Bank[ABANK_COUNT];
sItemTrade Trade[12]; sItemTrade Trade[12];
int32_t moneyInTrade; int32_t moneyInTrade;
bool isTrading; bool isTrading;