mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-11-22 21:40:05 +00:00
adjusted item codes logic to handle multiple items per code
This commit is contained in:
parent
ff75aa6693
commit
5f82658c8d
@ -719,7 +719,7 @@ void unhideCommand(std::string full, std::vector<std::string>& args, CNSocket* s
|
|||||||
|
|
||||||
void redeemCommand(std::string full, std::vector<std::string>& args, CNSocket* sock) {
|
void redeemCommand(std::string full, std::vector<std::string>& args, CNSocket* sock) {
|
||||||
if (args.size() < 2) {
|
if (args.size() < 2) {
|
||||||
ChatManager::sendServerMessage(sock, "/redeem: no code specified");
|
ChatManager::sendServerMessage(sock, "/redeem: No code specified");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -730,34 +730,42 @@ void redeemCommand(std::string full, std::vector<std::string>& args, CNSocket* s
|
|||||||
}
|
}
|
||||||
|
|
||||||
Player* plr = PlayerManager::getPlayer(sock);
|
Player* plr = PlayerManager::getPlayer(sock);
|
||||||
int slotNum = ItemManager::findFreeSlot(plr);
|
int itemCount = ItemManager::CodeItems[code].size();
|
||||||
|
int slots[4];
|
||||||
|
|
||||||
// no space
|
for (int i = 0; i < itemCount; i++) {
|
||||||
if (slotNum == -1) {
|
slots[i] = ItemManager::findFreeSlot(plr);
|
||||||
ChatManager::sendServerMessage(sock, "/redeem: Inventory full");
|
if (slots[i] == -1) {
|
||||||
return;
|
ChatManager::sendServerMessage(sock, "/redeem: Not enough space in inventory");
|
||||||
|
|
||||||
|
// delete any temp items we might have set
|
||||||
|
for (int j = 0; j < i; j++) {
|
||||||
|
plr->Inven[slots[j]] = { 0, 0, 0, 0 }; // empty
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
plr->Inven[slots[i]] = { 999, 999, 999, 0 }; // temp item; overwritten later
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<int32_t, int32_t> item = ItemManager::CodeItems[code];
|
for (int i = 0; i < itemCount; i++) {
|
||||||
INITSTRUCT(sP_FE2CL_REP_PC_GIVE_ITEM_SUCC, resp);
|
std::pair<int32_t, int32_t> item = ItemManager::CodeItems[code][i];
|
||||||
|
INITSTRUCT(sP_FE2CL_REP_PC_GIVE_ITEM_SUCC, resp);
|
||||||
|
|
||||||
resp.eIL = 1;
|
resp.eIL = 1;
|
||||||
resp.iSlotNum = slotNum;
|
resp.iSlotNum = slots[i];
|
||||||
// just in case it's a vehicle
|
resp.Item.iID = item.first;
|
||||||
if (item.second == 10) {
|
resp.Item.iType = item.second;
|
||||||
// set time limit: current time + 7days
|
// I think it is safe? :eyes
|
||||||
resp.Item.iTimeLimit = getTimestamp() + 604800;
|
resp.Item.iOpt = 1;
|
||||||
|
|
||||||
|
// save serverside
|
||||||
|
plr->Inven[resp.iSlotNum] = resp.Item;
|
||||||
|
|
||||||
|
sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_GIVE_ITEM_SUCC, sizeof(sP_FE2CL_REP_PC_GIVE_ITEM_SUCC));
|
||||||
}
|
}
|
||||||
resp.Item.iID = item.first;
|
std::string msg = itemCount == 1 ? "You have redeemed a code item" : "You have redeemed code items";
|
||||||
resp.Item.iType = item.second;
|
ChatManager::sendServerMessage(sock, msg);
|
||||||
// I think it is safe? :eyes
|
|
||||||
resp.Item.iOpt = 1;
|
|
||||||
|
|
||||||
// save serverside
|
|
||||||
plr->Inven[resp.iSlotNum] = resp.Item;
|
|
||||||
|
|
||||||
sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_GIVE_ITEM_SUCC, sizeof(sP_FE2CL_REP_PC_GIVE_ITEM_SUCC));
|
|
||||||
ChatManager::sendServerMessage(sock, "You have redeemed a code item");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatManager::init() {
|
void ChatManager::init() {
|
||||||
|
@ -16,7 +16,7 @@ std::map<int32_t, std::vector<int>> ItemManager::RarityRatios;
|
|||||||
std::map<int32_t, Crate> ItemManager::Crates;
|
std::map<int32_t, Crate> ItemManager::Crates;
|
||||||
// pair Itemset, Rarity -> vector of pointers (map iterators) to records in ItemData
|
// pair Itemset, Rarity -> vector of pointers (map iterators) to records in ItemData
|
||||||
std::map<std::pair<int32_t, int32_t>, std::vector<std::map<std::pair<int32_t, int32_t>, ItemManager::Item>::iterator>> ItemManager::CrateItems;
|
std::map<std::pair<int32_t, int32_t>, std::vector<std::map<std::pair<int32_t, int32_t>, ItemManager::Item>::iterator>> ItemManager::CrateItems;
|
||||||
std::map<std::string, std::pair<int32_t, int32_t>> ItemManager::CodeItems;
|
std::map<std::string, std::vector<std::pair<int32_t, int32_t>>> ItemManager::CodeItems;
|
||||||
|
|
||||||
#ifdef ACADEMY
|
#ifdef ACADEMY
|
||||||
std::map<int32_t, int32_t> ItemManager::NanoCapsules; // crate id -> nano id
|
std::map<int32_t, int32_t> ItemManager::NanoCapsules; // crate id -> nano id
|
||||||
|
@ -34,7 +34,7 @@ namespace ItemManager {
|
|||||||
// pair <Itemset, Rarity> -> vector of pointers (map iterators) to records in ItemData (it looks a lot scarier than it is)
|
// pair <Itemset, Rarity> -> vector of pointers (map iterators) to records in ItemData (it looks a lot scarier than it is)
|
||||||
extern std::map<std::pair<int32_t, int32_t>,
|
extern std::map<std::pair<int32_t, int32_t>,
|
||||||
std::vector<std::map<std::pair<int32_t, int32_t>, Item>::iterator>> CrateItems;
|
std::vector<std::map<std::pair<int32_t, int32_t>, Item>::iterator>> CrateItems;
|
||||||
extern std::map<std::string, std::pair<int32_t, int32_t>> CodeItems; // code -> <id, type>
|
extern std::map<std::string, std::vector<std::pair<int32_t, int32_t>>> CodeItems; // code -> vector of <id, type>
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
|
@ -578,11 +578,16 @@ void TableData::loadDrops() {
|
|||||||
ItemManager::NanoCapsules[(int)capsule["Crate"]] = (int)capsule["Nano"];
|
ItemManager::NanoCapsules[(int)capsule["Crate"]] = (int)capsule["Nano"];
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
nlohmann::json codes = dropData["Codes"];
|
nlohmann::json codes = dropData["CodeItems"];
|
||||||
for (nlohmann::json::iterator _code = codes.begin(); _code != codes.end(); _code++) {
|
for (nlohmann::json::iterator _code = codes.begin(); _code != codes.end(); _code++) {
|
||||||
auto code = _code.value();
|
auto code = _code.value();
|
||||||
|
std::string codeStr = code["Code"];
|
||||||
std::pair<int32_t, int32_t> item = std::make_pair((int)code["Id"], (int)code["Type"]);
|
std::pair<int32_t, int32_t> item = std::make_pair((int)code["Id"], (int)code["Type"]);
|
||||||
ItemManager::CodeItems[code["Code"]] = item;
|
|
||||||
|
if (ItemManager::CodeItems.find(codeStr) == ItemManager::CodeItems.end())
|
||||||
|
ItemManager::CodeItems[codeStr] = std::vector<std::pair<int32_t, int32_t>>();
|
||||||
|
|
||||||
|
ItemManager::CodeItems[codeStr].push_back(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "[INFO] Loaded " << ItemManager::Crates.size() << " Crates containing "
|
std::cout << "[INFO] Loaded " << ItemManager::Crates.size() << " Crates containing "
|
||||||
|
Loading…
Reference in New Issue
Block a user