Reapply "try to fix duplicate spare body entries"

This reverts commit 2c8050a19b.
This commit is contained in:
Mikhail
2024-09-25 18:35:48 -04:00
parent 2c8050a19b
commit dd81797327

View File

@@ -57,33 +57,58 @@ namespace EpinelPS.LobbyServer.Msgs.Gacha
var pieceIds = new List<Tuple<int, int>>(); // 2D array to store characterId and pieceId as Tuple var pieceIds = new List<Tuple<int, int>>(); // 2D array to store characterId and pieceId as Tuple
// Add each character's item to user.Items if the character exists in user.Characters // Add each character's item to user.Items if the character exists in user.Characters
foreach (var characterData in selectedCharacters) foreach (var characterData in selectedCharacters)
{ {
if (user.Characters.Any(c => c.Tid == characterData.id)) // Check if the item for this character already exists in user.Items based on ItemType
{ var existingItem = user.Items.FirstOrDefault(item => item.ItemType == characterData.piece_id);
user.Items.Add(new ItemData()
{ if (existingItem != null)
ItemType = characterData.piece_id, // Assuming item id corresponds to character id {
Csn = 0, // If the item exists, increment the count
Count = 1, // or any relevant count existingItem.Count += 1;
Level = 0,
Exp = 0, // Send the updated item in the response
Position = 0, response.Items.Add(new NetUserItemData()
Corp = 0, {
Isn = user.GenerateUniqueItemId() Tid = existingItem.ItemType,
}); Csn = existingItem.Csn,
response.Items.Add(new NetUserItemData() Count = existingItem.Count,
{ Level = existingItem.Level,
Tid = characterData.piece_id, // Assuming item id corresponds to character id Exp = existingItem.Exp,
Csn = 0, Position = existingItem.Position,
Count = 1, // or any relevant count Isn = existingItem.Isn
Level = 0, });
Exp = 0, }
Position = 0, else
Isn = user.GenerateUniqueItemId() {
}); // If the item does not exist, create a new item entry
} var newItem = new ItemData()
} {
ItemType = characterData.piece_id,
Csn = 0,
Count = 1, // or any relevant count
Level = 0,
Exp = 0,
Position = 0,
Corp = 0,
Isn = user.GenerateUniqueItemId()
};
user.Items.Add(newItem);
// Add the new item to response
response.Items.Add(new NetUserItemData()
{
Tid = newItem.ItemType,
Csn = newItem.Csn,
Count = newItem.Count,
Level = newItem.Level,
Exp = newItem.Exp,
Position = newItem.Position,
Isn = newItem.Isn
});
}
}
// Populate the 2D array with characterId and pieceId for each selected character // Populate the 2D array with characterId and pieceId for each selected character
foreach (var characterData in selectedCharacters) foreach (var characterData in selectedCharacters)
{ {