/// <summary> /// Delete any curses/blessing gained by items/pets from a player that they no longer posses, then give them any curses unique to a new item/pet. Psychopathic spellslingers make an exception and should never learn any new curses from items/pets they have gained. /// </summary> /// <param name="owner">The Player who owns/owned the item</param> /// <param name="newItemSourceId">The id of a new item that the player is gaining, if any.</param> public static void UpdateItemSpecificSkillsToPlayer(Player owner, int?newItemSourceId) { ISkillRepository skillRepo = new EFSkillRepository(); // delete all of the old item specific skills for the player IEnumerable <SkillViewModel> itemSpecificSkills = GetSkillViewModelsOwnedByPlayer__CursesOnly(owner.Id).ToList(); List <int> equippedItemSourceIds = ItemProcedures.GetAllPlayerItems_ItemOnly(owner.Id).Where(i => i.IsEquipped && i.ItemSourceId != newItemSourceId).Select(s => s.ItemSourceId).ToList(); var itemSpecificSkillsIds = new List <int>(); foreach (var s in itemSpecificSkills) { if (s.StaticSkill.ExclusiveToItemSourceId != null && !equippedItemSourceIds.Contains(s.StaticSkill.ExclusiveToItemSourceId.Value)) { itemSpecificSkillsIds.Add(s.dbSkill.Id); } } foreach (var id in itemSpecificSkillsIds) { skillRepo.DeleteSkill(id); } // don't give psychos any curses. Quit automatically if (owner.BotId == AIStatics.PsychopathBotId) { return; } // now give the player any skills they are missing if (newItemSourceId != null) { var itemSpecificSkillsToGive = SkillStatics.GetItemSpecificSkills(newItemSourceId.Value).ToList(); foreach (var skill in itemSpecificSkillsToGive) { // make sure player does not already have this skill due to some bug or othher var possibledbSkill = skillRepo.Skills.FirstOrDefault(s => s.OwnerId == owner.Id && s.SkillSourceId == skill.Id); if (possibledbSkill == null) { DomainRegistry.Repository.Execute(new CreateSkill { ownerId = owner.Id, skillSourceId = skill.Id }); } } } }