示例#1
0
        /*
         * Make a money object
         */
        public static void make_gold(ref Object j_ptr, int lev, int coin_type)
        {
            int sval;

            /* This average is 20 at dlev0, 105 at dlev40, 220 at dlev100. */
            /* Follows the formula: y=2x+20 */
            int avg    = 2 * lev + 20;
            int spread = lev + 10;
            int value  = Random.rand_spread(avg, spread);

            /* Increase the range to infinite, moving the average to 110% */
            while (Random.one_in_(100) && value * 10 <= short.MaxValue)
            {
                value *= 10;
            }

            /* Pick a treasure variety scaled by level, or force a type */
            if (coin_type != (int)SVal.sval_gold.SV_GOLD_ANY)
            {
                sval = coin_type;
            }
            else
            {
                sval = (((value * 100) / MAX_GOLD_DROP) * (int)SVal.sval_gold.SV_GOLD_MAX) / 100;
            }

            /* Do not create illegal treasure types */
            if (sval >= (int)SVal.sval_gold.SV_GOLD_MAX)
            {
                sval = (int)SVal.sval_gold.SV_GOLD_MAX - 1;
            }

            /* Prepare a gold object */
            j_ptr.prep(Object_Kind.lookup_kind(TVal.TV_GOLD, sval), lev, aspect.RANDOMISE);

            /* If we're playing with no_selling, increase the value */
            if (Option.birth_no_selling.value && Misc.p_ptr.depth != 0)
            {
                value = value * Math.Min(5, (int)Misc.p_ptr.depth);
            }

            /* Cap gold at max short (or alternatively make pvals s32b) */
            if (value > short.MaxValue)
            {
                value = short.MaxValue;
            }

            j_ptr.pval[Misc.DEFAULT_PVAL] = (short)value;
        }
示例#2
0
        /*
         * Mega-Hack -- Attempt to create one of the "Special Objects".
         *
         * We are only called from "make_object()"
         *
         * Note -- see "make_artifact()" and "apply_magic()".
         *
         * We *prefer* to create the special artifacts in order, but this is
         * normally outweighed by the "rarity" rolls for those artifacts.
         */
        static bool make_artifact_special(ref Object o_ptr, int level)
        {
            int         i;
            Object_Kind kind;

            /* No artifacts, do nothing */
            if (Option.birth_no_artifacts.value)
            {
                return(false);
            }

            /* No artifacts in the town */
            if (Misc.p_ptr.depth == 0)
            {
                return(false);
            }

            /* Check the special artifacts */
            for (i = 0; i < Misc.ART_MIN_NORMAL; ++i)
            {
                Artifact a_ptr = Misc.a_info[i];

                /* Skip "empty" artifacts */
                if (a_ptr == null)
                {
                    continue;
                }

                /* Cannot make an artifact twice */
                if (a_ptr.created)
                {
                    continue;
                }

                /* Enforce minimum "depth" (loosely) */
                if (a_ptr.alloc_min > Misc.p_ptr.depth)
                {
                    /* Get the "out-of-depth factor" */
                    int d = (a_ptr.alloc_min - Misc.p_ptr.depth) * 2;

                    /* Roll for out-of-depth creation */
                    if (Random.randint0(d) != 0)
                    {
                        continue;
                    }
                }

                /* Enforce maximum depth (strictly) */
                if (a_ptr.alloc_max < Misc.p_ptr.depth)
                {
                    continue;
                }

                /* Artifact "rarity roll" */
                if (Random.randint1(100) > a_ptr.alloc_prob)
                {
                    continue;
                }

                /* Find the base object */
                kind = Object_Kind.lookup_kind(a_ptr.tval, a_ptr.sval);

                /* Make sure the kind was found */
                if (kind == null)
                {
                    continue;
                }

                /* Enforce minimum "object" level (loosely) */
                if (kind.level > level)
                {
                    /* Get the "out-of-depth factor" */
                    int d = (kind.level - level) * 5;

                    /* Roll for out-of-depth creation */
                    if (Random.randint0(d) != 0)
                    {
                        continue;
                    }
                }

                /* Assign the template */
                o_ptr.prep(kind, a_ptr.alloc_min, aspect.RANDOMISE);

                /* Mark the item as an artifact */
                o_ptr.artifact = a_ptr;

                /* Copy across all the data from the artifact struct */
                o_ptr.copy_artifact_data(a_ptr);

                /* Mark the artifact as "created" */
                a_ptr.created = true;

                /* Success */
                return(true);
            }

            /* Failure */
            return(false);
        }