Beispiel #1
0
        /// <summary>
        /// Some types are only valid for certain materials.  So rather than throw an error, just change the type
        /// </summary>
        private static WeaponHandleType GetHandleType(WeaponHandleMaterial material, WeaponHandleType requestedType)
        {
            switch (material)
            {
            case WeaponHandleMaterial.Soft_Wood:
            case WeaponHandleMaterial.Hard_Wood:
                return(WeaponHandleType.Rod);

            //case WeaponHandleMaterial.NylonRope:
            //case WeaponHandleMaterial.WireRope:
            //case WeaponHandleMaterial.Wraith:
            //    return WeaponHandleType.Rope;

            default:
                return(requestedType);
            }
        }
        public static WeaponHandleDNA GetRandomDNA(WeaponHandleMaterial? material = null, WeaponHandleType? type = null, bool? isDouble = null, double? length = null, double? radius = null)
        {
            const double DOUBLE_END = .2d;
            const double DOUBLE_CENTER = .05d;       // this is only half of the center

            WeaponHandleDNA retVal = new WeaponHandleDNA();

            Random rand = StaticRandom.GetRandomForThread();

            bool isDoubleActual = isDouble ?? (rand.Next(2) == 0);

            #region Material

            if (material == null)
            {
                retVal.HandleMaterial = UtilityCore.GetRandomEnum<WeaponHandleMaterial>();
            }
            else
            {
                retVal.HandleMaterial = material.Value;
            }

            #endregion

            //TODO: Support rope
            retVal.HandleType = WeaponHandleType.Rod;

            #region Length

            if (length == null)
            {
                //double lengthActual = rand.NextDouble(1.5d, 3.5d);
                double lengthActual = rand.NextDouble(1.5d, 2.8d);
                if (isDoubleActual)
                {
                    lengthActual *= 2d;
                }

                retVal.Length = lengthActual;
            }
            else
            {
                retVal.Length = length.Value;
            }

            #endregion
            #region Radius

            if (radius == null)
            {
                //double radiusActual = rand.NextDouble(.03d, .17d);
                double radiusActual = rand.NextDouble(.03d, .12d);
                if (isDoubleActual)
                {
                    radiusActual *= 2d;
                }

                retVal.Radius = radiusActual;
            }
            else
            {
                retVal.Radius = radius.Value;
            }

            #endregion
            #region AttachPoint

            if (isDoubleActual)
            {
                // Since the center of mass is in the middle, the attach point can't be in the middle.
                // Both ends are out as well.
                // So, choose one of the areas that are stars
                //  |----|********|--------|********|----|

                double randMaxValue = .5d - DOUBLE_END - DOUBLE_CENTER;
                double randValue = rand.NextDouble(randMaxValue);
                double half = DOUBLE_CENTER + randValue;

                if (rand.NextBool())
                {
                    // left side
                    retVal.AttachPointPercent = .5d - half;
                }
                else
                {
                    // right side
                    retVal.AttachPointPercent = .5d + half;
                }
            }
            else
            {
                // Choose one of the ends
                retVal.AttachPointPercent = rand.NextBool() ? 0d : 1d;
            }

            #endregion

            #region Color

            switch (retVal.HandleMaterial)
            {
                case WeaponHandleMaterial.Composite:
                    retVal.MaterialsForCustomizable = GetRandomMaterials_Composite();
                    break;

                case WeaponHandleMaterial.Klinth:
                    retVal.MaterialsForCustomizable = GetRandomMaterials_Klinth();
                    break;
            }

            #endregion

            return retVal;
        }
        /// <summary>
        /// Some types are only valid for certain materials.  So rather than throw an error, just change the type
        /// </summary>
        private static WeaponHandleType GetHandleType(WeaponHandleMaterial material, WeaponHandleType requestedType)
        {
            switch (material)
            {
                case WeaponHandleMaterial.Soft_Wood:
                case WeaponHandleMaterial.Hard_Wood:
                    return WeaponHandleType.Rod;

                //case WeaponHandleMaterial.CheapRope:
                //case WeaponHandleMaterial.HempRope:
                //case WeaponHandleMaterial.Wraith:
                //    return WeaponHandleType.Rope;

                default:
                    return requestedType;
            }
        }