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

@@ -59,11 +59,32 @@ namespace EpinelPS.LobbyServer.Msgs.Gacha
// 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);
if (existingItem != null)
{ {
user.Items.Add(new ItemData() // If the item exists, increment the count
existingItem.Count += 1;
// Send the updated item in the response
response.Items.Add(new NetUserItemData()
{ {
ItemType = characterData.piece_id, // Assuming item id corresponds to character id Tid = existingItem.ItemType,
Csn = existingItem.Csn,
Count = existingItem.Count,
Level = existingItem.Level,
Exp = existingItem.Exp,
Position = existingItem.Position,
Isn = existingItem.Isn
});
}
else
{
// If the item does not exist, create a new item entry
var newItem = new ItemData()
{
ItemType = characterData.piece_id,
Csn = 0, Csn = 0,
Count = 1, // or any relevant count Count = 1, // or any relevant count
Level = 0, Level = 0,
@@ -71,19 +92,23 @@ namespace EpinelPS.LobbyServer.Msgs.Gacha
Position = 0, Position = 0,
Corp = 0, Corp = 0,
Isn = user.GenerateUniqueItemId() Isn = user.GenerateUniqueItemId()
}); };
user.Items.Add(newItem);
// Add the new item to response
response.Items.Add(new NetUserItemData() response.Items.Add(new NetUserItemData()
{ {
Tid = characterData.piece_id, // Assuming item id corresponds to character id Tid = newItem.ItemType,
Csn = 0, Csn = newItem.Csn,
Count = 1, // or any relevant count Count = newItem.Count,
Level = 0, Level = newItem.Level,
Exp = 0, Exp = newItem.Exp,
Position = 0, Position = newItem.Position,
Isn = user.GenerateUniqueItemId() 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)
{ {