コード例 #1
0
        /// <summary>
        /// <para>Returns a <see cref="BonusAttribute"/> array populated with '<paramref name="numOfAttr"/>' unique random attributes
        /// chosen from '<paramref name="randAttrs"/>' array -or- returns null if a null or empty array is supplied.</para>
        /// </summary>
        public static BonusAttribute[] GetRandomAttributes(BonusAttribute[] randAttrs, int numOfAttr)
        {
            BonusAttribute[] toAttrs = null;

            if (randAttrs != null && randAttrs.Length > 0 && numOfAttr > 0)
            {
                toAttrs = new BonusAttribute[numOfAttr];

                int avail = 0;

                List <int> numList = new List <int>();

                for (int i = 0; i < randAttrs.Length; ++i)
                {
                    numList.Add(avail++);
                }

                if (numOfAttr > randAttrs.Length)
                {
                    numOfAttr = randAttrs.Length;
                }

                int v;

                for (int i = 0; i < numOfAttr; ++i)
                {
                    v = Utility.Random(avail--);

                    toAttrs[i] = randAttrs[numList[v]];

                    numList.RemoveAt(v);
                }
            }

            return(toAttrs);
        }
コード例 #2
0
        /// <summary>
        /// <para>Returns a <see cref="BonusAttribute"/> array populated with '<paramref name="numOfAttr"/>' unique random attributes
        /// chosen from '<paramref name="randAttrs"/>' array -or- returns null if a null or empty array is supplied.</para>
        /// </summary>
        public static BonusAttribute[] GetRandomAttributes( BonusAttribute[] randAttrs, int numOfAttr )
        {
            BonusAttribute[] toAttrs = null;

            if ( randAttrs != null && randAttrs.Length > 0 && numOfAttr > 0)
            {
                toAttrs = new BonusAttribute[numOfAttr];

                int avail = 0;

                List<int> numList = new List<int>();

                for ( int i = 0; i < randAttrs.Length; ++i )
                    numList.Add( avail++ );

                if ( numOfAttr > randAttrs.Length )
                    numOfAttr = randAttrs.Length;

                int v;

                for ( int i = 0; i < numOfAttr; ++i )
                {
                    v = Utility.Random(avail--);

                    toAttrs[i] = randAttrs[numList[v]];

                    numList.RemoveAt(v);
                }
            }

            return toAttrs;
        }
コード例 #3
0
        public static void RemoveAttrsFrom( Item item, BonusAttribute[] attributes )
        {
            if ( attributes != null && attributes.Length > 0 )
            {
                int cold = 0, nrgy = 0, fire = 0, pois = 0, chaos = 0, direct = 0;

                for ( int i = 0; i < attributes.Length; i++ )
                {
                    if ( attributes[i].Attribute == null )
                        continue;

                    Type attrType = attributes[i].Attribute.GetType();

                    if ( attrType == typeof( AosAttribute ) )
                    {
                        if ( item is IAosAttributes )
                            RemoveAttribute( ((IAosAttributes)item).Attributes, (AosAttribute)attributes[i].Attribute, attributes[i].Amount );
                    }
                    else if ( attrType == typeof( AosArmorAttribute ) )
                    {
                        if ( (AosArmorAttribute)attributes[i].Attribute == AosArmorAttribute.DurabilityBonus )
                            RemoveDurability( item, attributes[i].Amount );
                        else if ( item is BaseArmor )
                            RemoveAttribute( ((BaseArmor)item).ArmorAttributes, (AosArmorAttribute)attributes[i].Attribute, attributes[i].Amount );
                        else if ( item is BaseOtherEquipable )
                            RemoveAttribute( ((BaseOtherEquipable)item).ArmorAttributes, (AosArmorAttribute)attributes[i].Attribute, attributes[i].Amount );
                    }
                    else if ( attrType == typeof( AosWeaponAttribute ) )
                    {
                        if ( (AosWeaponAttribute)attributes[i].Attribute == AosWeaponAttribute.DurabilityBonus )
                            RemoveDurability( item, attributes[i].Amount );
                        else if ( item is BaseWeapon )
                            RemoveAttribute( ((BaseWeapon)item).WeaponAttributes, (AosWeaponAttribute)attributes[i].Attribute, attributes[i].Amount );
                    }
                    else if ( attrType == typeof( AosElementAttribute ) )
                    {
                        if ( item is BaseWeapon )
                        {
                            switch ( (AosElementAttribute)attributes[i].Attribute )
                            {
                                case AosElementAttribute.Cold: 		cold = attributes[i].Amount; break;
                                case AosElementAttribute.Energy:	nrgy = attributes[i].Amount; break;
                                case AosElementAttribute.Fire:		fire = attributes[i].Amount; break;
                                case AosElementAttribute.Poison:	pois = attributes[i].Amount; break;
                                case AosElementAttribute.Chaos:		chaos = attributes[i].Amount; break;
                                case AosElementAttribute.Direct:	direct = attributes[i].Amount; break;
                            }
                        }
                    }
                    else if ( attrType == typeof( ResistanceType ) )
                    {
                        if ( item is BaseArmor )
                            RemoveResistance( (BaseArmor)item, (ResistanceType)attributes[i].Attribute, attributes[i].Amount );
                    }
                }

                if ( item is BaseWeapon )
                    RemoveElementDamages( (BaseWeapon)item, cold, nrgy, fire, pois, chaos, direct );
            }
        }
コード例 #4
0
 /// <summary>
 /// <para>Returns a <see cref="BonusAttribute"/> array populated with one unique random attribute
 /// chosen from '<paramref name="randAttrs"/>' array -or- returns null if a null or empty array is supplied.</para>
 /// </summary>
 public static BonusAttribute[] GetRandomAttributes( BonusAttribute[] randAttrs )
 {
     return GetRandomAttributes( randAttrs, 1 );
 }