예제 #1
0
        /// <summary>
        /// Gets the <see cref="NPCChatDialogBase"/> at the specified index.
        /// </summary>
        /// <param name="id">Index of the <see cref="NPCChatDialogBase"/>.</param>
        /// <returns>The <see cref="NPCChatDialogBase"/> at the specified index, or null if invalid.</returns>
        /// <exception cref="MethodAccessException">Tried to set when <see cref="IsReadonly"/> was true.</exception>
        public NPCChatDialogBase this[NPCChatDialogID id]
        {
            get
            {
                // Check for a valid index
                if (!_npcChatDialogs.CanGet((int)id))
                {
                    const string errmsg = "Invalid NPC chat dialog index `{0}`.";
                    if (log.IsErrorEnabled)
                    {
                        log.ErrorFormat(errmsg, id);
                    }
                    Debug.Fail(string.Format(errmsg, id));
                    return(null);
                }

                return(_npcChatDialogs[(int)id]);
            }
            set
            {
                if (IsReadonly)
                {
                    throw CreateReadonlyException();
                }

                _npcChatDialogs[(int)id] = value;
            }
        }
예제 #2
0
        /// <summary>
        /// Gets the <see cref="ActionDisplay"/> with the given <see cref="ActionDisplayID"/>.
        /// </summary>
        /// <param name="id">The <see cref="ActionDisplayID"/> of the <see cref="ActionDisplay"/> to get.</param>
        /// <returns>The <see cref="ActionDisplay"/> at the given <paramref name="id"/>, or null if the <paramref name="id"/>
        /// was invalid or no <see cref="ActionDisplay"/> exists at the given ID.</returns>
        public ActionDisplay this[ActionDisplayID id]
        {
            get
            {
                if (!_items.CanGet((int)id))
                {
                    return(null);
                }

                return(_items[(int)id]);
            }
        }
        /// <summary>
        /// Gets the <see cref="IQuestDescription"/> for a quest.
        /// </summary>
        /// <param name="questID">The ID of the quest to get the <see cref="IQuestDescription"/> for.</param>
        /// <returns>The <see cref="IQuestDescription"/> for the given <see cref="QuestID"/>.</returns>
        public IQuestDescription this[QuestID questID]
        {
            get
            {
                if (!_questDescriptions.CanGet(questID.GetRawValue()))
                {
                    return(null);
                }

                return(_questDescriptions[questID.GetRawValue()]);
            }
        }
예제 #4
0
 public List <WallEntityBase> this[GrhIndex index]
 {
     get
     {
         if (!_walls.CanGet((int)index))
         {
             return(null);
         }
         return(_walls[(int)index]);
     }
     set { _walls[(int)index] = value; }
 }
예제 #5
0
        /// <summary>
        /// Gets the item at the given <paramref name="id"/>.
        /// </summary>
        /// <param name="id">The ID of the item to get.</param>
        /// <returns>The item at the given <paramref name="id"/>, or the default value of of <typeparamref name="TItem"/> if the
        /// the <paramref name="id"/> is invalid or not item exists for the <paramref name="id"/>.</returns>
        public TItem this[TID id]
        {
            get
            {
                var i = IDToInt(id);
                if (!_items.CanGet(i))
                {
                    return(default(TItem));
                }

                return(_items[i]);
            }
        }
예제 #6
0
        static void CanGetAndIndexRangeTestSub(bool trackFree)
        {
            var d = new DArray<object>(trackFree);
            d[0] = new object();

            var o = d[0];

            Assert.IsFalse(d.CanGet(-1));
            Assert.Throws<ArgumentOutOfRangeException>(() => o = d[-1],
                "Failed to generate ArgumentOutOfRangeException for d[-1].");

            Assert.IsFalse(d.CanGet(1));
            Assert.Throws<ArgumentOutOfRangeException>(() => o = d[-1], "Failed to generate ArgumentOutOfRangeException for d[1].");
        }
예제 #7
0
        static void CanGetAndIndexRangeTestSub(bool trackFree)
        {
            var d = new DArray <object>(trackFree);

            d[0] = new object();

            var o = d[0];

            Assert.IsFalse(d.CanGet(-1));
            Assert.Throws <ArgumentOutOfRangeException>(() => o = d[-1],
                                                        "Failed to generate ArgumentOutOfRangeException for d[-1].");

            Assert.IsFalse(d.CanGet(1));
            Assert.Throws <ArgumentOutOfRangeException>(() => o = d[-1], "Failed to generate ArgumentOutOfRangeException for d[1].");
        }
예제 #8
0
파일: GrhInfo.cs 프로젝트: wtfcolt/game
        static void AssertGrhIndexIsFree(GrhIndex index, GrhData ignoreWhen)
        {
            // Make sure we can even get the index
            if (!_grhDatas.CanGet((int)index))
            {
                return;
            }

            // Get the current GrhData
            var currentGD = GetData(index);

            // Check if occupied
            if (currentGD != null && (ignoreWhen == null || currentGD != ignoreWhen))
            {
                Debug.Fail("Existing GrhData is going to be overwritten. This is likely not what was intended.");
            }
        }
        IMessageProcessor[] BuildMessageProcessors(object source)
        {
            const BindingFlags bindFlags =
                BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod |
                BindingFlags.Static;

            var mpdType  = typeof(MessageProcessorHandler);
            var atbType  = typeof(MessageHandlerAttribute);
            var voidType = typeof(void);

            var tmpProcessors = new DArray <IMessageProcessor>();

            // Search through all types in the Assembly
            var assemb = Assembly.GetAssembly(source.GetType());

            foreach (var type in assemb.GetTypes())
            {
                // Search through every method in the class
                foreach (var method in type.GetMethods(bindFlags))
                {
                    // Only accept a method if it returns a void
                    if (method.ReturnType != voidType)
                    {
                        continue;
                    }

                    // Get all of the MessageAttributes for the method (should only be one)
                    var atbs = (MessageHandlerAttribute[])method.GetCustomAttributes(atbType, true);
                    if (atbs.Length > 1)
                    {
                        const string errmsg = "Multiple MessageHandlerAttributes found for method `{0}`.";
                        Debug.Fail(string.Format(errmsg, method.Name));
                        throw new ArgumentException(string.Format(errmsg, method.Name), "source");
                    }

                    // Create the message processor for the method
                    foreach (var atb in atbs)
                    {
                        if (tmpProcessors.CanGet(atb.MsgID) && tmpProcessors[atb.MsgID] != null)
                        {
                            const string errmsg =
                                "A MessageHandlerAttribute with ID `{0}` already exists. Methods in question: {1} and {2}";
                            Debug.Fail(string.Format(errmsg, atb.MsgID, tmpProcessors[atb.MsgID].Call.Method, method));
                            throw new DuplicateKeyException(string.Format(errmsg, atb.MsgID, tmpProcessors[atb.MsgID].Call.Method,
                                                                          method));
                        }

                        var del = (MessageProcessorHandler)Delegate.CreateDelegate(mpdType, source, method);
                        Debug.Assert(del != null);
                        var msgProcessor = CreateMessageProcessor(atb, del);
                        tmpProcessors.Insert(atb.MsgID, msgProcessor);
                    }
                }
            }

            return(tmpProcessors.ToArray());
        }
예제 #10
0
        static void ClearTestSub(bool trackFree)
        {
            const int size = 50;

            var d = new DArray<object>(trackFree);
            for (var i = 0; i < size; i++)
            {
                d[i] = new object();
            }

            d.Clear();

            Assert.AreEqual(0, d.Length);
            Assert.AreEqual(0, d.Count);

            object o;
            Assert.Throws<ArgumentOutOfRangeException>(() => o = d[0], "Failed to generate IndexOutOfRangeException for d[0].");
            Assert.IsFalse(d.CanGet(0));
        }
예제 #11
0
        static void ClearTestSub(bool trackFree)
        {
            const int size = 50;

            var d = new DArray <object>(trackFree);

            for (var i = 0; i < size; i++)
            {
                d[i] = new object();
            }

            d.Clear();

            Assert.AreEqual(0, d.Length);
            Assert.AreEqual(0, d.Count);

            object o;

            Assert.Throws <ArgumentOutOfRangeException>(() => o = d[0], "Failed to generate IndexOutOfRangeException for d[0].");
            Assert.IsFalse(d.CanGet(0));
        }
예제 #12
0
        IMessageProcessor[] BuildMessageProcessors(object source)
        {
            const BindingFlags bindFlags =
                BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod |
                BindingFlags.Static;

            var mpdType = typeof(MessageProcessorHandler);
            var atbType = typeof(MessageHandlerAttribute);
            var voidType = typeof(void);

            var tmpProcessors = new DArray<IMessageProcessor>();

            // Search through all types in the Assembly
            var assemb = Assembly.GetAssembly(source.GetType());
            foreach (var type in assemb.GetTypes())
            {
                // Search through every method in the class
                foreach (var method in type.GetMethods(bindFlags))
                {
                    // Only accept a method if it returns a void
                    if (method.ReturnType != voidType)
                        continue;

                    // Get all of the MessageAttributes for the method (should only be one)
                    var atbs = (MessageHandlerAttribute[])method.GetCustomAttributes(atbType, true);
                    if (atbs.Length > 1)
                    {
                        const string errmsg = "Multiple MessageHandlerAttributes found for method `{0}`.";
                        Debug.Fail(string.Format(errmsg, method.Name));
                        throw new ArgumentException(string.Format(errmsg, method.Name), "source");
                    }

                    // Create the message processor for the method
                    foreach (var atb in atbs)
                    {
                        if (tmpProcessors.CanGet(atb.MsgID) && tmpProcessors[atb.MsgID] != null)
                        {
                            const string errmsg =
                                "A MessageHandlerAttribute with ID `{0}` already exists. Methods in question: {1} and {2}";
                            Debug.Fail(string.Format(errmsg, atb.MsgID, tmpProcessors[atb.MsgID].Call.Method, method));
                            throw new DuplicateKeyException(string.Format(errmsg, atb.MsgID, tmpProcessors[atb.MsgID].Call.Method,
                                method));
                        }

                        var del = (MessageProcessorHandler)Delegate.CreateDelegate(mpdType, source, method);
                        Debug.Assert(del != null);
                        var msgProcessor = CreateMessageProcessor(atb, del);
                        tmpProcessors.Insert(atb.MsgID, msgProcessor);
                    }
                }
            }

            return tmpProcessors.ToArray();
        }