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,24 +730,30 @@ 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) {
|
||||||
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<int32_t, int32_t> item = ItemManager::CodeItems[code];
|
plr->Inven[slots[i]] = { 999, 999, 999, 0 }; // temp item; overwritten later
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < itemCount; i++) {
|
||||||
|
std::pair<int32_t, int32_t> item = ItemManager::CodeItems[code][i];
|
||||||
INITSTRUCT(sP_FE2CL_REP_PC_GIVE_ITEM_SUCC, resp);
|
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
|
|
||||||
if (item.second == 10) {
|
|
||||||
// set time limit: current time + 7days
|
|
||||||
resp.Item.iTimeLimit = getTimestamp() + 604800;
|
|
||||||
}
|
|
||||||
resp.Item.iID = item.first;
|
resp.Item.iID = item.first;
|
||||||
resp.Item.iType = item.second;
|
resp.Item.iType = item.second;
|
||||||
// I think it is safe? :eyes
|
// I think it is safe? :eyes
|
||||||
@ -757,7 +763,9 @@ void redeemCommand(std::string full, std::vector<std::string>& args, CNSocket* s
|
|||||||
plr->Inven[resp.iSlotNum] = resp.Item;
|
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));
|
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");
|
}
|
||||||
|
std::string msg = itemCount == 1 ? "You have redeemed a code item" : "You have redeemed code items";
|
||||||
|
ChatManager::sendServerMessage(sock, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
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