Skip to content

Commit

Permalink
Fix issue with reward manager
Browse files Browse the repository at this point in the history
- Fix issue with indexing when rewards for disabled/non-existing quests
  are present.
- Added rewards to transaction where possible.
  • Loading branch information
pacampbell committed Nov 9, 2024
1 parent d3a3eaa commit 2aa6402
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
36 changes: 18 additions & 18 deletions Arrowgene.Ddon.GameServer/Handler/QuestGetRewardBoxItemHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,34 +63,34 @@ public override S2CQuestGetRewardBoxItemRes Handle(GameClient client, C2SQuestGe
}

var distinctRewards = packet.GetRewardBoxItemList.Select(x => x.UID).Distinct().ToList();
var slotCount = coalescedRewards.Sum(x =>
distinctRewards.Contains(x.Key)
? Server.ItemManager.PredictAddItemSlots(client.Character, StorageType.StorageBoxNormal, x.Value.ItemId, x.Value.Num)
: 0);

var slotCount = coalescedRewards.Sum(x => distinctRewards.Contains(x.Key) ? Server.ItemManager.PredictAddItemSlots(client.Character, StorageType.StorageBoxNormal, x.Value.ItemId, x.Value.Num) : 0);
if (slotCount > client.Character.Storage.GetStorage(StorageType.StorageBoxNormal).EmptySlots())
{
throw new ResponseErrorException(ErrorCode.ERROR_CODE_ITEM_STORAGE_OVERFLOW);
}

foreach (var rewardUID in distinctRewards)
Server.Database.ExecuteInTransaction(connection =>
{
var reward = coalescedRewards[rewardUID];
if (Server.ItemManager.IsItemWalletPoint(reward.ItemId))
foreach (var rewardUID in distinctRewards)
{
(WalletType walletType, uint amount) = Server.ItemManager.ItemToWalletPoint(reward.ItemId);
var result = Server.WalletManager.AddToWallet(client.Character, walletType, amount * reward.Num);
updateCharacterItemNtc.UpdateWalletList.Add(result);
var reward = coalescedRewards[rewardUID];
if (Server.ItemManager.IsItemWalletPoint(reward.ItemId))
{
(WalletType walletType, uint amount) = Server.ItemManager.ItemToWalletPoint(reward.ItemId);
var result = Server.WalletManager.AddToWallet(client.Character, walletType, amount * reward.Num, connectionIn: connection);
updateCharacterItemNtc.UpdateWalletList.Add(result);
}
else if (reward.Num > 0)
{
var result = Server.ItemManager.AddItem(Server, client.Character, false, reward.ItemId, reward.Num, connectionIn: connection);
updateCharacterItemNtc.UpdateItemList.AddRange(result);
}
}
else if (reward.Num > 0)
{
var result = Server.ItemManager.AddItem(Server, client.Character, false, reward.ItemId, reward.Num);
updateCharacterItemNtc.UpdateItemList.AddRange(result);
}
}
client.Send(updateCharacterItemNtc);
Server.RewardManager.DeleteQuestBoxReward(client, questBoxReward.UniqRewardId, connectionIn: connection);
});

Server.RewardManager.DeleteQuestBoxReward(client, questBoxReward.UniqRewardId);
client.Send(updateCharacterItemNtc);

return new S2CQuestGetRewardBoxItemRes();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public override S2CQuestGetRewardBoxListRes Handle(GameClient client, C2SQuestGe
var quest = QuestManager.GetQuestByScheduleId(boxReward.QuestScheduleId);
if (quest == null)
{
listNo += 1;
Logger.Error($"Quest reward for QuestScheduleId={boxReward.QuestScheduleId}, but no definition of quest exists.");
continue;
}
Expand Down

0 comments on commit 2aa6402

Please sign in to comment.