Skip to content

Commit

Permalink
fix: forge correct slots (#2850)
Browse files Browse the repository at this point in the history
Resolves #2718
  • Loading branch information
dudantas committed Oct 9, 2024
1 parent 006457c commit e1d2f22
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions src/server/network/protocol/protocolgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5370,7 +5370,8 @@ void ProtocolGame::sendForgingData() {
void ProtocolGame::sendOpenForge() {
// We will use it when sending the bytes to send the item information to the client
std::map<uint16_t, std::map<uint8_t, uint16_t>> fusionItemsMap;
std::map<int32_t, std::map<uint16_t, std::map<uint8_t, uint16_t>>> convergenceItemsMap;
std::map<int32_t, std::map<uint16_t, std::map<uint8_t, uint16_t>>> convergenceFusionItemsMap;
std::map<int32_t, std::map<uint16_t, std::map<uint8_t, uint16_t>>> convergenceTransferItemsMap;
std::map<uint16_t, std::map<uint8_t, uint16_t>> donorTierItemMap;
std::map<uint16_t, std::map<uint8_t, uint16_t>> receiveTierItemMap;

Expand Down Expand Up @@ -5405,15 +5406,20 @@ void ProtocolGame::sendOpenForge() {
getForgeInfoMap(item, receiveTierItemMap);
}
if (itemClassification == 4) {
getForgeInfoMap(item, convergenceItemsMap[item->getClassification()]);
auto slotPosition = item->getSlotPosition();
if ((slotPosition & SLOTP_TWO_HAND) != 0) {
slotPosition = SLOTP_HAND;
}
getForgeInfoMap(item, convergenceFusionItemsMap[slotPosition]);
getForgeInfoMap(item, convergenceTransferItemsMap[item->getClassification()]);
}
}
}

// Checking size of map to send in the addByte (total fusion items count)
uint8_t fusionTotalItemsCount = 0;
for (const auto &[itemId, tierAndCountMap] : fusionItemsMap) {
for (const auto [itemTier, itemCount] : tierAndCountMap) {
for (const auto &[itemTier, itemCount] : tierAndCountMap) {
if (itemCount >= 2) {
fusionTotalItemsCount++;
}
Expand All @@ -5430,7 +5436,7 @@ void ProtocolGame::sendOpenForge() {

msg.add<uint16_t>(fusionTotalItemsCount);
for (const auto &[itemId, tierAndCountMap] : fusionItemsMap) {
for (const auto [itemTier, itemCount] : tierAndCountMap) {
for (const auto &[itemTier, itemCount] : tierAndCountMap) {
if (itemCount >= 2) {
msg.addByte(0x01); // Number of friend items?
msg.add<uint16_t>(itemId);
Expand All @@ -5452,12 +5458,12 @@ void ProtocolGame::sendOpenForge() {
1 byte: tier
2 bytes: count
*/
for (const auto &[slot, itemMap] : convergenceItemsMap) {
for (const auto &[slot, itemMap] : convergenceFusionItemsMap) {
uint8_t totalItemsCount = 0;
auto totalItemsCountPosition = msg.getBufferPosition();
msg.skipBytes(1); // Total items count
for (const auto &[itemId, tierAndCountMap] : itemMap) {
for (const auto [tier, itemCount] : tierAndCountMap) {
for (const auto &[tier, itemCount] : tierAndCountMap) {
if (tier >= maxConfigTier) {
continue;
}
Expand Down Expand Up @@ -5488,11 +5494,15 @@ void ProtocolGame::sendOpenForge() {
// Let's access the itemType to check the item's (donator of tier) classification level
// Must be the same as the item that will receive the tier
const ItemType &donorType = Item::items[itemId];
auto donorSlotPosition = donorType.slotPosition;
if ((donorSlotPosition & SLOTP_TWO_HAND) != 0) {
donorSlotPosition = SLOTP_HAND;
}

// Total count of item (donator of tier)
auto donorTierTotalItemsCount = getIterationIncreaseCount(tierAndCountMap);
msg.add<uint16_t>(donorTierTotalItemsCount);
for (const auto [donorItemTier, donorItemCount] : tierAndCountMap) {
for (const auto &[donorItemTier, donorItemCount] : tierAndCountMap) {
msg.add<uint16_t>(itemId);
msg.addByte(donorItemTier);
msg.add<uint16_t>(donorItemCount);
Expand All @@ -5502,7 +5512,11 @@ void ProtocolGame::sendOpenForge() {
for (const auto &[iteratorItemId, unusedTierAndCountMap] : receiveTierItemMap) {
// Let's access the itemType to check the item's (receiver of tier) classification level
const ItemType &receiveType = Item::items[iteratorItemId];
if (donorType.upgradeClassification == receiveType.upgradeClassification) {
auto receiveSlotPosition = receiveType.slotPosition;
if ((receiveSlotPosition & SLOTP_TWO_HAND) != 0) {
receiveSlotPosition = SLOTP_HAND;
}
if (donorType.upgradeClassification == receiveType.upgradeClassification && donorSlotPosition == receiveSlotPosition) {
receiveTierTotalItemCount++;
}
}
Expand All @@ -5513,8 +5527,12 @@ void ProtocolGame::sendOpenForge() {
for (const auto &[receiveItemId, receiveTierAndCountMap] : receiveTierItemMap) {
// Let's access the itemType to check the item's (receiver of tier) classification level
const ItemType &receiveType = Item::items[receiveItemId];
if (donorType.upgradeClassification == receiveType.upgradeClassification) {
for (const auto [receiveItemTier, receiveItemCount] : receiveTierAndCountMap) {
auto receiveSlotPosition = receiveType.slotPosition;
if ((receiveSlotPosition & SLOTP_TWO_HAND) != 0) {
receiveSlotPosition = SLOTP_HAND;
}
if (donorType.upgradeClassification == receiveType.upgradeClassification && donorSlotPosition == receiveSlotPosition) {
for (const auto &[receiveItemTier, receiveItemCount] : receiveTierAndCountMap) {
msg.add<uint16_t>(receiveItemId);
msg.add<uint16_t>(receiveItemCount);
}
Expand All @@ -5540,7 +5558,7 @@ void ProtocolGame::sendOpenForge() {
2 bytes: item id
2 bytes: count
*/
for (const auto &[slot, itemMap] : convergenceItemsMap) {
for (const auto &[slot, itemMap] : convergenceTransferItemsMap) {
uint16_t donorCount = 0;
uint16_t receiverCount = 0;
auto donorCountPosition = msg.getBufferPosition();
Expand Down

0 comments on commit e1d2f22

Please sign in to comment.