Ejemplo n.º 1
0
 /// <summary>
 /// Whether this lock can be interacted with, using the given type
 /// </summary>
 public bool Supports(LockInteractionType type)
 {
     foreach (var method in OpeningMethods)
     {
         if (method.InteractionType == type)
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Whether this lock can be interacted with, using the given type
        /// </summary>
        public bool Supports(LockInteractionType type)
        {
            foreach (LockOpeningMethod openingMethod in this.OpeningMethods)
            {
                if (openingMethod.InteractionType == type)
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 3
0
        public static void Handle(Character chr, ILockable lockable, LockInteractionType type)
        {
            var handler = InteractionHandlers.Get((uint)type);

            if (handler != null)
            {
                handler(lockable, chr);
            }
            else
            {
                log.Error("{0} trying to interact with lockable \"{1}\", but the used InteractionType \"{2}\" is not handled.",
                          chr, lockable, type);
            }
        }
Ejemplo n.º 4
0
 public static void Handle(Character chr, ILockable lockable, LockInteractionType type)
 {
     LockEntry.InteractionHandler interactionHandler =
         LockEntry.InteractionHandlers.Get <LockEntry.InteractionHandler>((uint)type);
     if (interactionHandler != null)
     {
         interactionHandler(lockable, chr);
     }
     else
     {
         LockEntry.log.Error(
             "{0} trying to interact with lockable \"{1}\", but the used InteractionType \"{2}\" is not handled.",
             (object)chr, (object)lockable, (object)type);
     }
 }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
            public override LockEntry ConvertTo(byte[] rawData, ref int id)
            {
                LockEntry lockEntry = new LockEntry((uint)(id = rawData.GetInt32(0U)));
                List <LockOpeningMethod> lockOpeningMethodList = new List <LockOpeningMethod>(5);
                List <LockKeyEntry>      lockKeyEntryList      = new List <LockKeyEntry>(5);
                uint num    = 1;
                uint field1 = 9;
                uint field2 = 17;

                for (uint index = 0; index < 5U; ++index)
                {
                    switch ((LockInteractionGroup)rawData.GetUInt32(num++))
                    {
                    case LockInteractionGroup.Key:
                        uint uint32_1 = rawData.GetUInt32(field1);
                        lockKeyEntryList.Add(new LockKeyEntry(index, uint32_1));
                        goto default;

                    case LockInteractionGroup.Profession:
                        LockInteractionType uint32_2 = (LockInteractionType)rawData.GetUInt32(field1);
                        switch (uint32_2)
                        {
                        case LockInteractionType.None:
                            continue;

                        case LockInteractionType.Close:
                        case LockInteractionType.QuickClose:
                        case LockInteractionType.PvPClose:
                            lockEntry.CanBeClosed = true;
                            goto label_9;

                        case LockInteractionType.OpenKneeling:
                            lockEntry.RequiresKneeling = true;
                            goto label_9;

                        case LockInteractionType.OpenAttacking:
                            lockEntry.RequiresAttack = true;
                            goto label_9;

                        default:
                            SkillId interactionSkill = LockEntry.InteractionSkills[(uint)uint32_2];
                            if (interactionSkill != SkillId.None)
                            {
                                lockOpeningMethodList.Add(new LockOpeningMethod(index)
                                {
                                    InteractionType    = uint32_2,
                                    RequiredSkill      = interactionSkill,
                                    RequiredSkillValue = rawData.GetUInt32(field2)
                                });
                                goto label_9;
                            }
                            else
                            {
                                goto label_9;
                            }
                        }

                    default:
label_9:
                        ++field1;
                        ++field2;
                        break;
                    }
                }

                lockEntry.IsUnlocked            = lockOpeningMethodList.Count == 0 && lockKeyEntryList.Count == 0;
                lockEntry.Keys                  = lockKeyEntryList.ToArray();
                lockEntry.OpeningMethods        = lockOpeningMethodList.ToArray();
                LockEntry.Entries[lockEntry.Id] = lockEntry;
                return(lockEntry);
            }