public override SpellFailedReason Initialize() { lockable = m_cast.SelectedTarget == null ? m_cast.TargetItem : (ILockable)(m_cast.SelectedTarget as GameObject); if (lockable == null) { return(SpellFailedReason.BadTargets); } LockEntry lockEntry = lockable.Lock; Character casterChar = m_cast.CasterChar; if (lockEntry == null) { log.Warn("Using OpenLock on object without Lock: " + lockable); return(SpellFailedReason.Error); } if (casterChar == null) { log.Warn("Using OpenLock without Character: " + casterChar); return(SpellFailedReason.Error); } SpellFailedReason spellFailedReason = SpellFailedReason.Ok; if (!lockEntry.IsUnlocked) { LockInteractionType miscValue = (LockInteractionType)Effect.MiscValue; if (lockEntry.Keys.Length > 0 && m_cast.CasterItem != null) { if (!lockEntry.Keys.Contains( key => key.KeyId == m_cast.CasterItem.Template.ItemId)) { return(SpellFailedReason.ItemNotFound); } } else if (!lockEntry.Supports(miscValue)) { return(SpellFailedReason.BadTargets); } if (miscValue != LockInteractionType.None) { foreach (LockOpeningMethod openingMethod in lockEntry.OpeningMethods) { if (openingMethod.InteractionType == miscValue) { if (openingMethod.RequiredSkill != SkillId.None) { skill = casterChar.Skills[openingMethod.RequiredSkill]; if (skill == null || skill.ActualValue < openingMethod.RequiredSkillValue) { spellFailedReason = SpellFailedReason.MinSkill; } } method = openingMethod; break; } } if (method == null) { spellFailedReason = SpellFailedReason.BadTargets; } } } if (spellFailedReason != SpellFailedReason.Ok && lockable is GameObject && ((GameObject)lockable).Entry.IsConsumable) { ((GameObject)lockable).State = GameObjectState.Enabled; } return(spellFailedReason); }
public override void Initialize(ref SpellFailedReason failReason) { if (m_cast.Selected != null) { lockable = m_cast.Selected as GameObject; } else { lockable = m_cast.TargetItem; } if (lockable == null) { failReason = SpellFailedReason.BadTargets; } else { var lck = lockable.Lock; var chr = m_cast.CasterChar; if (lck == null) { log.Warn("Using OpenLock on object without Lock: " + lockable); failReason = SpellFailedReason.Error; return; } if (chr == null) { log.Warn("Using OpenLock without Character: " + chr); failReason = SpellFailedReason.Error; return; } if (!lck.IsUnlocked) { var type = (LockInteractionType)Effect.MiscValue; if (lck.Keys.Length > 0 && m_cast.CasterItem != null) { if (!lck.Keys.Contains(key => key.KeyId == m_cast.CasterItem.Template.ItemId)) { failReason = SpellFailedReason.ItemNotFound; return; } } else if (!lck.Supports(type)) { failReason = SpellFailedReason.BadTargets; return; } if (type != LockInteractionType.None) { foreach (var openingMethod in lck.OpeningMethods) { if (openingMethod.InteractionType == type) { if (openingMethod.RequiredSkill != SkillId.None) { skill = chr.Skills[openingMethod.RequiredSkill]; if (skill == null || skill.ActualValue < openingMethod.RequiredSkillValue) { failReason = SpellFailedReason.MinSkill; } } method = openingMethod; break; } } if (method == null) { // we are using the wrong kind of spell on the target failReason = SpellFailedReason.BadTargets; } } } if (failReason != SpellFailedReason.Ok) { // spell failed if (lockable is GameObject && ((GameObject)lockable).Entry.IsConsumable) { // re-enable GO ((GameObject)lockable).State = GameObjectState.Enabled; } } } }
public override SpellFailedReason Initialize() { if (m_cast.SelectedTarget != null) { lockable = m_cast.SelectedTarget as GameObject; } else { lockable = m_cast.TargetItem; } if (lockable == null) { return(SpellFailedReason.BadTargets); } var lck = lockable.Lock; var chr = m_cast.CasterChar; if (lck == null) { log.Warn("Using OpenLock on object without Lock: " + lockable); return(SpellFailedReason.Error); } if (chr == null) { log.Warn("Using OpenLock without Character: " + chr); return(SpellFailedReason.Error); } var failReason = SpellFailedReason.Ok; if (!lck.IsUnlocked) { var type = (LockInteractionType)Effect.MiscValue; if (lck.Keys.Length > 0 && m_cast.CasterItem != null) { if (!lck.Keys.Contains(key => key.KeyId == m_cast.CasterItem.Template.ItemId)) { return(SpellFailedReason.ItemNotFound); } } else if (!lck.Supports(type)) { return(SpellFailedReason.BadTargets); } if (type != LockInteractionType.None) { foreach (var openingMethod in lck.OpeningMethods) { if (openingMethod.InteractionType == type) { if (openingMethod.RequiredSkill != SkillId.None) { skill = chr.Skills[openingMethod.RequiredSkill]; if (skill == null || skill.ActualValue < openingMethod.RequiredSkillValue) { failReason = SpellFailedReason.MinSkill; } } method = openingMethod; break; } } if (method == null) { // we are using the wrong kind of spell on the target failReason = SpellFailedReason.BadTargets; } } } if (failReason != SpellFailedReason.Ok) { // spell failed if (lockable is GameObject && ((GameObject)lockable).Entry.IsConsumable) { // re-enable GO ((GameObject)lockable).State = GameObjectState.Enabled; } } return(failReason); }