Files
DanhengServer-OpenSource/GameServer/Game/Rogue/Event/EffectHandler/EventHandlerGetRogueMiracle.cs
Somebody 87d228eb79 Feature:Asynchronous Operation & Formatting Code
- Now the async operation is enabled!
- Code formatted by Resharper plugin <3
2024-07-22 17:12:03 +08:00

36 lines
1.3 KiB
C#

using EggLink.DanhengServer.Data;
using EggLink.DanhengServer.Enums.Rogue;
using EggLink.DanhengServer.Util;
namespace EggLink.DanhengServer.Game.Rogue.Event.EffectHandler;
[RogueEvent(DialogueEventTypeEnum.GetRogueMiracle)]
public class EventHandlerGetRogueMiracle : RogueEventEffectHandler
{
public override async ValueTask Handle(BaseRogueInstance rogue, RogueEventInstance? eventInstance,
List<int> paramList)
{
var miracleGroupId = paramList[0];
GameData.RogueMiracleGroupData.TryGetValue(miracleGroupId, out var miracleGroup);
if (miracleGroup == null) return;
var list = new List<int>();
foreach (var id in miracleGroup)
if (!rogue.RogueMiracles.ContainsKey(id))
// Add the miracle to the list if the player doesn't have it
list.Add(id);
if (list.Count == 0) return; // If the player already has all the miracles in the group, return
for (var i = 0; i < paramList[1]; i++)
{
if (list.Count == 0) break; // If the player has all the miracles in the group, break
var miracleId = list.RandomElement();
await rogue.AddMiracle(miracleId);
list.Remove(i); // Remove the miracle from the list so it can't be added again
}
}
}