Пример #1
0
    public Item(string specifier)
    {
        UID = LocalTopUID++;

        int    spec_argStart = specifier.IndexOf('{');
        int    spec_argEnd   = (spec_argStart >= 0) ? specifier.IndexOf('}', spec_argStart + 1) : 1;
        string spec_args     = "";

        if (spec_argStart >= 0 && spec_argEnd >= 0)
        {
            spec_args = specifier.Substring(spec_argStart + 1, spec_argEnd - spec_argStart - 1);
        }
        if (spec_argStart >= 0)
        {
            specifier = specifier.Substring(0, spec_argStart).Trim();
        }
        Class = ItemClassLoader.GetItemClassBySpecifier(specifier);
        if (Class == null)
        {
            Debug.LogFormat("Invalid item created (specifier={0})", specifier);
            return;
        }

        InitItem();

        // now go through effects
        MagicEffects.AddRange(ItemEffect.ParseEffectList(spec_args));

        UpdateItem();
    }
Пример #2
0
 private void ClassLoadThreadProc()
 {
     try
     {
         TemplateLoader.LoadTemplates();
         ObstacleClassLoader.InitClasses();
         StructureClassLoader.InitClasses();
         UnitClassLoader.InitClasses();
         ItemClassLoader.InitClasses();
         ProjectileClassLoader.InitClasses();
         ClassLoadThreadDone = true;
     }
     catch (Exception e)
     {
         Debug.LogErrorFormat("Exception while loading classes.\n{0}", e.ToString());
         ClassLoadThreadDone = true;
     }
 }
Пример #3
0
    public Item(ushort id, List <ItemEffect> effects = null)
    {
        UID = LocalTopUID++;

        Class = ItemClassLoader.GetItemClassById(id);
        if (Class == null)
        {
            Debug.LogFormat("Invalid item created (id={0})", id);
            return;
        }

        InitItem();

        if (effects != null)
        {
            MagicEffects = effects;
        }

        UpdateItem();
    }
Пример #4
0
    public Item(NetItem netitem)
    {
        UID        = netitem.UID;
        ParentUIDs = netitem.ParentUIDs;

        Class = ItemClassLoader.GetItemClassById(netitem.ClassID);
        if (Class == null)
        {
            Debug.LogFormat("Invalid item created (id={0})", netitem.ClassID);
            return;
        }

        Count = netitem.Count;

        InitItem();

        MagicEffects = netitem.MagicEffects;

        UpdateItem();
    }
Пример #5
0
        public bool Process()
        {
            if (!MapLogic.Instance.IsLoaded)
            {
                return(false);
            }

            MapUnit unit = MapLogic.Instance.GetUnitByTag(Tag);

            if (unit == null)
            {
                Debug.LogFormat("Attempted to pick up with nonexistent unit {0}", Tag);
                return(true);
            }

            // print message if this unit is console
            if (unit.Player != MapLogic.Instance.ConsolePlayer)
            {
                return(true);
            }

            string msg;

            if (ItemID >= 0)
            {
                // itemcount is resultant count
                ItemClass cls = ItemClassLoader.GetItemClassById((ushort)ItemID);
                msg = string.Format("{0} {1}", Locale.Main[85], (cls != null ? cls.VisualName : "(null)")); // you picked up: ...
                if (ItemCount > 1)                                                                          // (now got NNN)
                {
                    msg += string.Format(" ({0} {1} {2})", Locale.Main[86], ItemCount, Locale.Main[87]);
                }
            }
            else
            {
                msg = string.Format("{0} {1} {2}", Locale.Main[88], ItemCount, Locale.Main[89]); // you picked up NNN gold
            }

            MapViewChat.Instance.AddChatMessage(Player.AllColorsPickup, msg);
            return(true);
        }
Пример #6
0
        public Shelf(AllodsMap.AlmShop.AlmShopShelf rules)
        {
            // basic props
            PriceMin    = rules.PriceMin;
            PriceMax    = rules.PriceMax;
            MaxItems    = rules.MaxItems;
            MaxSameType = rules.MaxSameItems;

            // get list of classes supported for the item.
            var Materials = new List <Templates.TplMaterial>();
            var Classes   = new List <Templates.TplClass>();
            var Types     = new List <Templates.TplArmor>();

            //
            ItemClasses        = new List <ItemClass>();
            SpecialItemClasses = new List <ItemClass>();

            //
            AllowMagic  = rules.ItemExtras.HasFlag(AllodsMap.AlmShop.AlmShopItemExtra.Magic);
            AllowCommon = AllowMagic ? rules.ItemExtras.HasFlag(AllodsMap.AlmShop.AlmShopItemExtra.Common) : true;

            AllowSpecial = rules.ItemTypes.HasFlag(AllodsMap.AlmShop.AlmShopItemType.Other);

            // this currently abuses the fact that there is a hardcoded list of materials.
            // will need to be changed if we extend it.
            for (int i = 0; i < 15; i++)
            {
                uint flag  = 1u << i;
                uint value = (uint)rules.ItemMaterials;
                if ((flag & value) != 0)
                {
                    Materials.Add(TemplateLoader.GetMaterialById(i));
                }
            }

            // same goes for classes.
            for (int i = 0; i < 7; i++)
            {
                uint flag  = 1u << i;
                uint value = ((uint)rules.ItemClasses) >> 15;
                if ((flag & value) != 0)
                {
                    Classes.Add(TemplateLoader.GetClassById(i));
                }
            }

            // types are a bit more complicated, because there is no direct mapping for this.
            // we use "slot"
            // note that there is also separation between mage and warrior armor here.

            // add weapons
            if (rules.ItemTypes.HasFlag(AllodsMap.AlmShop.AlmShopItemType.Weapon))
            {
                foreach (Templates.TplArmor weapon in TemplateLoader.Templates.Weapons)
                {
                    if (!CheckArmorShapeAllowed(weapon, rules))
                    {
                        continue;
                    }
                    if (weapon.SuitableFor == 1)
                    {
                        Types.Add(weapon);
                    }
                }
            }

            if (rules.ItemTypes.HasFlag(AllodsMap.AlmShop.AlmShopItemType.Wands))
            {
                foreach (Templates.TplArmor weapon in TemplateLoader.Templates.Weapons)
                {
                    if (!CheckArmorShapeAllowed(weapon, rules))
                    {
                        continue;
                    }
                    if (weapon.SuitableFor == 2)
                    {
                        Types.Add(weapon);
                    }
                }
            }

            // add armor
            if (rules.ItemTypes.HasFlag(AllodsMap.AlmShop.AlmShopItemType.Armor))
            {
                foreach (Templates.TplArmor armor in TemplateLoader.Templates.Armor)
                {
                    if (!CheckArmorShapeAllowed(armor, rules))
                    {
                        continue;
                    }
                    if (armor.SuitableFor == 1)
                    {
                        Types.Add(armor);
                    }
                }
            }

            if (rules.ItemTypes.HasFlag(AllodsMap.AlmShop.AlmShopItemType.ArmorMage))
            {
                foreach (Templates.TplArmor armor in TemplateLoader.Templates.Armor)
                {
                    if (!CheckArmorShapeAllowed(armor, rules))
                    {
                        continue;
                    }
                    if (armor.SuitableFor == 2)
                    {
                        Types.Add(armor);
                    }
                }
            }

            // add armor suitable for everyone (e.g. rings)
            if (rules.ItemTypes.HasFlag(AllodsMap.AlmShop.AlmShopItemType.Armor) || rules.ItemTypes.HasFlag(AllodsMap.AlmShop.AlmShopItemType.ArmorMage))
            {
                foreach (Templates.TplArmor armor in TemplateLoader.Templates.Armor)
                {
                    if (!CheckArmorShapeAllowed(armor, rules))
                    {
                        continue;
                    }
                    if (armor.SuitableFor == 3)
                    {
                        Types.Add(armor);
                    }
                }
            }

            // add shields
            if (rules.ItemTypes.HasFlag(AllodsMap.AlmShop.AlmShopItemType.Shield))
            {
                foreach (Templates.TplArmor shield in TemplateLoader.Templates.Shields)
                {
                    if (!CheckArmorShapeAllowed(shield, rules))
                    {
                        continue;
                    }
                    Types.Add(shield);
                }
            }

            // add special (other)
            // copy the list (we may want to skip some items later)
            if (rules.ItemTypes.HasFlag(AllodsMap.AlmShop.AlmShopItemType.Other))
            {
                // generate id for scroll.
                for (ushort i = 6; i <= 0x3F; i++)
                {
                    ushort    itemId = (ushort)(0x0E00 | i);
                    ItemClass cls    = ItemClassLoader.GetItemClassById(itemId);
                    if (cls == null)
                    {
                        continue;
                    }
                    if (cls.Price < PriceMin || cls.Price > PriceMax)
                    {
                        continue;
                    }
                    SpecialItemClasses.Add(cls);
                }
            }

            // now that we have all the allowed combinations, let's populate items!
            // note that not all possible IDs are valid -- we need to check this
            foreach (Templates.TplArmor armor in Types)
            {
                // class id
                for (int i = 0; i < 7; i++)
                {
                    // material id
                    for (int j = 0; j < 15; j++)
                    {
                        // check if allowed
                        if ((armor.ClassesAllowed[i] & (1 << j)) == 0)
                        {
                            continue;
                        }
                        ushort    itemId = (ushort)((i << 5) | (j << 12) | (armor.Slot << 8) | (armor.Index));
                        ItemClass cls    = ItemClassLoader.GetItemClassById(itemId);
                        if (cls == null)
                        {
                            continue;
                        }
                        if (cls.Price > PriceMax || (!AllowMagic && cls.Price < PriceMin))
                        {
                            continue;
                        }
                        ItemClasses.Add(cls);
                    }
                }
            }

            Items = new ItemPack();
            GenerateItems();
        }