spare body labels in gacha

This commit is contained in:
Mikhail
2024-12-25 16:28:07 -05:00
parent e9bcd7adfb
commit 8bb270d786
2 changed files with 140 additions and 83 deletions

View File

@@ -332,6 +332,25 @@ namespace EpinelPS.Database
} }
} }
public Character? GetCharacter(int c)
{
// Step 1: Get the 'name_code' of the input character with Tid 'c'
if (GameData.Instance.characterTable.TryGetValue(c, out var inputCharacterRecord))
{
int targetNameCode = inputCharacterRecord.name_code;
// Step 2: Find all character IDs in 'characterTable' that have the same 'name_code'
var matchingCharacterIds = GameData.Instance.characterTable.Where(kvp => kvp.Value.name_code == targetNameCode).Select(kvp => kvp.Key).ToHashSet();
// Step 3: Check if any of your owned characters have a 'Tid' in the set of matching IDs
return Characters.Where(ownedCharacter => matchingCharacterIds.Contains(ownedCharacter.Tid)).First();
}
else
{ // The character with Tid 'c' does not exist in 'characterTable'
return null;
}
}
public Character? GetCharacterBySerialNumber(long value) public Character? GetCharacterBySerialNumber(long value)
{ {
return Characters.Where(x => x.Csn == value).FirstOrDefault(); return Characters.Where(x => x.Csn == value).FirstOrDefault();

View File

@@ -26,7 +26,7 @@ namespace EpinelPS.LobbyServer.Gacha
int numberOfPulls = req.Count == 1 ? 1 : 10; int numberOfPulls = req.Count == 1 ? 1 : 10;
var user = GetUser(); var user = GetUser();
var response = new ResExecuteGacha(); var response = new ResExecuteGacha() { Reward = new NetRewardData() { PassPoint = new() } };
var entireallCharacterData = GameData.Instance.characterTable.Values.ToList(); var entireallCharacterData = GameData.Instance.characterTable.Values.ToList();
// Remove the .Values part since it's already a list. // Remove the .Values part since it's already a list.
@@ -60,19 +60,65 @@ namespace EpinelPS.LobbyServer.Gacha
} }
} }
var pieceIds = new List<Tuple<int, int>>(); // 2D array to store characterId and pieceId as Tuple int totalBodyLabels = 0;
// 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)
{ {
var gacha = new NetGachaEntityData()
{
// PieceCount = 1, // Spare Body
CurrencyValue = 0, // Body Label
Tid = characterData.id,
Type = 1
};
// Check if user has this character.
// If so, check if it is fully limit broken, then add body labels
// If not fully limit broken, add spare body item
// If user does not have character, generate CSN and add character
if (user.HasCharacter(characterData.id)) if (user.HasCharacter(characterData.id))
{ {
// Check if the item for this character already exists in user.Items based on ItemType Database.Character character = user.GetCharacter(characterData.id) ?? throw new Exception("HasCharacter() returned true, however character was null");
var existingItem = user.Items.FirstOrDefault(item => item.ItemType == characterData.piece_id); var existingItem = user.Items.FirstOrDefault(item => item.ItemType == characterData.piece_id);
bool increase_item = false;
gacha.Sn = character.Csn;
gacha.Tid = characterData.id;
// Check if we can add upgrade item
if (characterData.original_rare == "SR")
{
if (existingItem != null && character.Grade + existingItem.Count <= 1)
{
increase_item = true;
}
else if (existingItem == null && character.Grade <= 1)
{
increase_item = true;
}
}
else if (characterData.original_rare == "SSR")
{
if (existingItem != null && character.Grade + existingItem.Count <= 10)
{
increase_item = true;
}
else if (existingItem == null && character.Grade <= 10)
{
increase_item = true;
}
}
if (increase_item)
{
gacha.PieceCount = 1;
if (existingItem != null) if (existingItem != null)
{ {
// If the item exists, increment the count existingItem.Count++;
existingItem.Count += 1;
// Send the updated item in the response // Send the updated item in the response
response.Items.Add(new NetUserItemData() response.Items.Add(new NetUserItemData()
@@ -115,57 +161,49 @@ namespace EpinelPS.LobbyServer.Gacha
}); });
} }
} }
else
{
gacha.CurrencyValue = characterData.original_rare == "SSR" ? 6000 : (characterData.original_rare == "SR" ? 200 : 150);
user.AddCurrency(CurrencyType.CharacterExp, gacha.CurrencyValue);
totalBodyLabels += (int)gacha.CurrencyValue;
} }
}
// Populate the 2D array with characterId and pieceId for each selected character else
foreach (var characterData in selectedCharacters)
{
var characterId = characterData.id;
var pieceId = characterData.piece_id;
// Store characterId and pieceId in the array
pieceIds.Add(Tuple.Create(characterId, pieceId));
var id = user.GenerateUniqueCharacterId();
response.Gacha.Add(new NetGachaEntityData()
{
Corporation = 1,
PieceCount = 1,
CurrencyValue = 5,
Sn = id,
Tid = characterId,
Type = 1
});
// Check if the user already has the character, if not add it
if (!user.HasCharacter(characterId))
{ {
// Add new character to user
gacha.Sn = user.GenerateUniqueCharacterId();
response.Characters.Add(new NetUserCharacterDefaultData() response.Characters.Add(new NetUserCharacterDefaultData()
{ {
CostumeId = 0, CostumeId = 0,
Csn = id, Csn = gacha.Sn,
Grade = 0, Grade = 0,
Level = 1, Level = 1,
Skill1Lv = 1, Skill1Lv = 1,
Skill2Lv = 1, Skill2Lv = 1,
Tid = characterId, Tid = characterData.id,
UltiSkillLv = 1 UltiSkillLv = 1
}); });
user.Characters.Add(new Database.Character() user.Characters.Add(new Database.Character()
{ {
CostumeId = 0, CostumeId = 0,
Csn = id, Csn = (int)gacha.Sn,
Grade = 0, Grade = 0,
Level = 1, Level = 1,
Skill1Lvl = 1, Skill1Lvl = 1,
Skill2Lvl = 1, Skill2Lvl = 1,
Tid = characterId, Tid = characterData.id,
UltimateLevel = 1 UltimateLevel = 1
}); });
} }
response.Gacha.Add(gacha);
} }
response.Reward.Currency.Add(new NetCurrencyData(){ Type = (int)CurrencyType.SilverMileageTicket, Value = numberOfPulls});
response.Reward.Currency.Add(new NetCurrencyData(){ Type = (int)CurrencyType.CharacterExp, Value = totalBodyLabels});
user.AddCurrency(CurrencyType.SilverMileageTicket, numberOfPulls);
user.GachaTutorialPlayCount++; user.GachaTutorialPlayCount++;
JsonDb.Save(); JsonDb.Save();