Example #1
0
 private static void ProcessField(CreatureInfo info, int iField, string value)
 {
     if (value == ".")
     {
         DefaultDispatchTable[iField](value, info);
         return;
     }
     DispatchTable[iField](value, info);
 }
Example #2
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>	Register an item's type. </summary>
        ///
        /// <remarks>	Darrellp, 10/6/2011. </remarks>
        ///
        /// <param name="mapItemTypeToItemInfo">		Map from ItemType to ItemInfo. </param>
        /// <param name="mapItemTypeToCreatureInfo">	Map from ItemType to CreatureInfo. </param>
        /// <param name="type">							The class type being registered. </param>
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        private static void RegisterType(
            IDictionary <ItemType, ItemInfo> mapItemTypeToItemInfo,
            IDictionary <ItemType, CreatureInfo> mapItemTypeToCreatureInfo,
            Type type)
        {
            // Get the item type from the type attributes
            object[]      attributes    = type.GetCustomAttributes(true);
            ItemAttribute itemAttribute = GetAttribute <ItemAttribute>(attributes);
            ItemType      itemType      = itemAttribute.ItemType;
            ItemInfo      itemInfo      = mapItemTypeToItemInfo[itemType];
            CreatureInfo  creatureInfo  = null;

            // See if the type is the player type
            itemInfo.IsPlayer = type == typeof(Player);

            // Is this item a creature type?
            if (mapItemTypeToCreatureInfo.ContainsKey(itemType))
            {
                // Retrieve it's creature info
                creatureInfo = mapItemTypeToCreatureInfo[itemType];

                // If the creature isn't a player
                if (!itemInfo.IsPlayer)
                {
                    // For each level this creature may appear in
                    for (int iLevel = creatureInfo.Level; iLevel <= Math.Min(creatureInfo.Level + 3, MaxLevel); iLevel++)
                    {
                        // Add it to the level's list
                        MapLevelsToCreatureList[iLevel].Add(itemInfo);
                    }
                }
            }

            // Set Creature info if any
            itemInfo.CreatureInfo = creatureInfo;

            // Put item info in the type dictionary
            MapTypeToItemInfo[type]         = itemInfo;
            MapItemTypeToItemInfo[itemType] = itemInfo;

            // Create the proxy for this type
            Item proxy = Activator.CreateInstance(type) as Item;

            // Put it in the character dictionary
            MapCharToProxyItem[itemInfo.Character] = proxy;

            // And in the itemType dictionary
            MapItemTypeToProxyItem[itemInfo.ItemType] = proxy;
        }
Example #3
0
        private static void ProcessLine(IDictionary <ItemType, CreatureInfo> infoList, string readLine)
        {
            if (readLine.StartsWith("//"))
            {
                return;
            }
            CreatureInfo  info     = new CreatureInfo();
            List <string> values   = readLine.Split(Tabs).Where(s => s != string.Empty).ToList();
            ItemType      itemType = (ItemType)Enum.Parse(typeof(ItemType), values[0]);

            infoList[itemType] = info;

            for (int iField = 1; iField < values.Count; iField++)
            {
                ProcessField(info, iField, values[iField]);
            }
        }