Beispiel #1
0
        /// <summary>
        /// Adds an Item to the default game data
        /// </summary>
        /// <param name="i">The Item to add</param>
        /// <param name="texture">The texture of the Item to add</param>
        /// <param name="param">Common object loading parameters</param>
        /// <param name="Aparam">Parameters for armor items</param>
        /// <returns>The IDs of the armor parts as an ArmorReturnValues</returns>
        public static ArmorReturnValues AddToGame(Item i, Texture2D texture, LoadParameters param, ArmorParameters Aparam = default(ArmorParameters))
        {
            ArmorReturnValues ret = new ArmorReturnValues(-1, -1, -1);

            i.netID       = i.type = Defs.itemNextType++;
            i.stack       = 1;
            i.name        = param.ModBase.modName + ":" + param.Name;
            i.displayName = param.Name;

            if (Aparam.HeadTexture != null)
            {
                i.headSlot = Defs.headSlotNextType++;

                if (Item.headType.ContainsKey(i.headSlot))
                {
                    Item.headType[i.headSlot] = i.type;
                }
                else
                {
                    Item.headType.Add(i.headSlot, i.type);
                }

                if (!Main.dedServ)
                {
                    Main.armorHeadTexture.Add(i.headSlot, Aparam.HeadTexture);
                }

                ret.HeadID = i.headSlot;
            }

            if (Aparam.BodyTexture != null)
            {
                i.bodySlot = Defs.bodySlotNextType++;

                if (Item.bodyType.ContainsKey(i.bodySlot))
                {
                    Item.bodyType[i.bodySlot] = i.type;
                }
                else
                {
                    Item.bodyType.Add(i.bodySlot, i.type);
                }

                if (!Main.dedServ)
                {
                    Main.armorHeadTexture.Add(i.bodySlot, Aparam.BodyTexture);

                    if (Aparam.FemaleBodyTexture != null)
                    {
                        Main.femaleBodyTexture.Add(i.bodySlot, Aparam.FemaleBodyTexture);
                    }
                }

                ret.BodyID = i.bodySlot;
            }

            if (Aparam.LegsTexture != null)
            {
                i.legSlot = Defs.legSlotNextType++;

                if (Item.legType.ContainsKey(i.legSlot))
                {
                    Item.legType[i.legSlot] = i.type;
                }
                else
                {
                    Item.legType.Add(i.legSlot, i.type);
                }

                if (!Main.dedServ)
                {
                    Main.armorLegTexture.Add(i.legSlot, Aparam.LegsTexture);
                }

                ret.LegsID = i.legSlot;
            }

            if (param.SubClassTypeName != null)
            {
                i.subClass = (ModItem)param.Assembly.CreateInstance(param.SubClassTypeName, false, BindingFlags.Public | BindingFlags.Instance, null,
                                                                    new object[] { param.ModBase, i }, CultureInfo.CurrentCulture, new object[] { });

                if (i.subClass != null)
                {
                    Defs.FillCallPriorities(i.subClass.GetType());
                }
            }

            if (!Main.dedServ)
            {
                Main.itemTexture.Add(i.type, texture);
            }
            Defs.items.Add(i.name, i);
            Defs.itemNames.Add(i.type, i.name);

            return(ret);
        }
Beispiel #2
0
        /// <summary>
        /// Adds an Item to the default game data
        /// </summary>
        /// <param name="i">The Item to add</param>
        /// <param name="texture">The texture of the Item to add</param>
        /// <param name="param">Common object loading parameters</param>
        /// <param name="Aparam">Parameters for armor items</param>
        /// <returns>The IDs of the armor parts as an ArmorReturnValues</returns>
        public static ArmorReturnValues AddToGame(Item i, Texture2D texture, LoadParameters param, ArmorParameters Aparam = default(ArmorParameters))
        {
            ArmorReturnValues ret = new ArmorReturnValues(-1, -1, -1);

            i.netID = i.type = Defs.itemNextType++;
            i.stack = 1;
            i.name = param.ModBase.modName + ":" + param.Name;
            i.displayName = param.Name;

            if (Aparam.HeadTexture != null)
            {
                i.headSlot = Defs.headSlotNextType++;

                if (Item.headType.ContainsKey(i.headSlot))
                    Item.headType[i.headSlot] = i.type;
                else
                    Item.headType.Add(i.headSlot, i.type);

                if (!Main.dedServ)
                    Main.armorHeadTexture.Add(i.headSlot, Aparam.HeadTexture);

                ret.HeadID = i.headSlot;
            }

            if (Aparam.BodyTexture != null)
            {
                i.bodySlot = Defs.bodySlotNextType++;

                if (Item.bodyType.ContainsKey(i.bodySlot))
                    Item.bodyType[i.bodySlot] = i.type;
                else
                    Item.bodyType.Add(i.bodySlot, i.type);

                if (!Main.dedServ)
                {
                    Main.armorHeadTexture.Add(i.bodySlot, Aparam.BodyTexture);

                    if (Aparam.FemaleBodyTexture != null)
                        Main.femaleBodyTexture.Add(i.bodySlot, Aparam.FemaleBodyTexture);
                }

                ret.BodyID = i.bodySlot;
            }

            if (Aparam.LegsTexture != null)
            {
                i.legSlot = Defs.legSlotNextType++;

                if (Item.legType.ContainsKey(i.legSlot))
                    Item.legType[i.legSlot] = i.type;
                else
                    Item.legType.Add(i.legSlot, i.type);

                if (!Main.dedServ)
                    Main.armorLegTexture.Add(i.legSlot, Aparam.LegsTexture);

                ret.LegsID = i.legSlot;
            }

            if (param.SubClassTypeName != null)
            {
                i.subClass = (ModItem)param.Assembly.CreateInstance(param.SubClassTypeName, false, BindingFlags.Public | BindingFlags.Instance, null,
                    new object[] { param.ModBase, i }, CultureInfo.CurrentCulture, new object[] { });

                if (i.subClass != null)
                    Defs.FillCallPriorities(i.subClass.GetType());
            }

            if (!Main.dedServ)
                Main.itemTexture.Add(i.type, texture);
            Defs.items.Add(i.name, i);
            Defs.itemNames.Add(i.type, i.name);

            return ret;
        }