Example #1
0
        /// <summary>
        /// Creates a new EquipmentInfo derived object that can be used by the game.
        /// For shields, the paths to the textures are similar to the SoG paths, except "Shields/" substring is removed.
        /// </summary>
        /// <returns> Either a new or existing object of type T. If item has an existing object with an incompatible type, returns null. </returns>
        /// <exception cref="ArgumentException"></exception>
        public static T CreateInfo <T>(this ItemDescription xDesc, string sResource, ContentManager xContent) where T : EquipmentInfo
        {
            if (!xDesc.enType.IsModItem())
            {
                throw new ArgumentException("Provided enType is not a mod item.");
            }

            EquipmentInfo xInfo;

            if (ModLibrary.ItemDetails.ContainsKey(xDesc.enType))
            {
                xInfo = ModLibrary.ItemDetails[xDesc.enType].xEquipmentData;
                if (xInfo != null)
                {
                    if (xInfo.GetType() == typeof(T))
                    {
                        return(xInfo as T);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }

            switch (typeof(T).Name)
            {
            case "EquipmentInfo":
                xInfo = new EquipmentInfo(sResource, xDesc.enType);
                break;

            case "FacegearInfo":
                FacegearInfo xFacegear = (FacegearInfo)(xInfo = new FacegearInfo(xDesc.enType));
                xFacegear.SetResource(sResource, xContent);
                break;

            case "HatInfo":
                HatInfo xHat = (HatInfo)(xInfo = new HatInfo(xDesc.enType));
                xHat.SetResource(sResource, xContent);
                break;

            case "WeaponInfo":
                WeaponInfo xWeapon = (WeaponInfo)(xInfo = new WeaponInfo("", xDesc.enType, WeaponInfo.WeaponCategory.OneHanded));
                xWeapon.SetResource(sResource, xContent);
                xWeapon.SetWeaponType(WeaponInfo.WeaponCategory.OneHanded, false);
                break;

            default:
                throw new ArgumentException("Received a non-vanilla Info type! Preposterous!");
            }

            ModLibrary.ItemDetails[xDesc.enType].xEquipmentData = xInfo;

            return(xInfo as T);
        }