private static void EventSink_CreatureDeath(CreatureDeathEventArgs e)
{
if (e.Killer == null || e.Creature == null || !ValidateName(e.Creature.GetType()))
{
return;
}
PlayerMobile pm = null;
if (e.Killer is BaseCreature bc)
{
if (bc.Controlled && bc.ControlMaster is PlayerMobile cm)
{
pm = cm;
}
else if (bc.Summoned && bc.SummonMaster is PlayerMobile sm)
{
pm = sm;
}
}
else if (e.Killer is PlayerMobile killerPm)
{
pm = killerPm;
}
if (pm == null || taskInfos == null || taskInfos.Count == 0)
{
return;
}
// Find the active task for this player that matches the killed creature
SkillTaskInfo currentInfo = taskInfos.FirstOrDefault(i =>
i.PlayerSerial == pm.Serial &&
!i.Completed &&
i.TargetName == e.Creature.GetType());
if (currentInfo != null)
{
if (currentInfo.TimeLimit <= DateTime.Now)
{
pm.SendMessage(53, "You ran out of time for this task!");
currentInfo.Completed = true;
}
else
{
// Valid kill: decrement and extend time
currentInfo.TaskAmount--;
currentInfo.TimeLimit += ExtraTaskTime;
if (currentInfo.TaskAmount <= 0)
{
// Award on final kill
pm.AddToBackpack(new PowerScroll(currentInfo.PlayerSkill, currentInfo.SkillCap + 5));
pm.SendMessage(53, $"You are awarded a {currentInfo.SkillCap + 5} {currentInfo.PlayerSkill} Powerscroll!");
TryGiveStatScroll(pm);
currentInfo.Completed = true;
}
else
{
// Continue task
currentInfo.TargetName = GetRandomCreature();
KillMessage(pm, currentInfo);
}
}
CleanTaskInfos();
}
}