Example #1
0
        /*
         * Attempt to make an object (normal or good/great)
         *
         * This routine plays nasty games to generate the "special artifacts".
         * We assume that the given object has been "wiped". You can optionally
         * receive the object's value in value if you pass a non-null pointer.
         *
         * Returns the whether or not creation worked.
         */
        public static bool make_object(Cave c, ref Object j_ptr, int lev, bool good, bool great, ref int value)
        {
            int         Base;
            Object_Kind kind;

            /* Try to make a special artifact */
            if (Random.one_in_(good ? 10 : 1000))
            {
                if (make_artifact_special(ref j_ptr, lev))
                {
                    if (value != 0)
                    {
                        value = j_ptr.value_real(1, false, true);
                    }
                    return(true);
                }

                /* If we failed to make an artifact, the player gets a great item */
                good = great = true;
            }

            /* Base level for the object */
            Base = (good ? (lev + 10) : lev);

            /* Get the object, prep it and apply magic */
            kind = get_obj_num(Base, good || great);
            if (kind == null)
            {
                return(false);
            }
            j_ptr.prep(kind, lev, aspect.RANDOMISE);
            j_ptr.apply_magic(lev, true, good, great);

            /* Generate multiple items */
            if (kind.gen_mult_prob >= Random.randint1(100))
            {
                j_ptr.number = (byte)Random.randcalc(kind.stack_size, lev, aspect.RANDOMISE);
            }

            if (value != 0)
            {
                value = j_ptr.value_real(j_ptr.number, false, true);
            }

            /* Return value, increased for uncursed out-of-depth objects */
            if (!Object_Flag.cursed_p(j_ptr.flags) && (kind.alloc_min > c.depth))
            {
                if (value != 0)
                {
                    value = (kind.alloc_min - c.depth) * (value / 5);
                }
            }

            return(true);
        }
Example #2
0
        /*
         * Creates a random object and gives it to store 'st'
         */
        bool create_random()
        {
            int tries, level;

            Object.Object i_ptr;
            //Object.Object object_type_body;

            int min_level, max_level;

            /* Decide min/max levels */
            if (sidx == STORE.B_MARKET) {
                min_level = Misc.p_ptr.max_depth + 5;
                max_level = Misc.p_ptr.max_depth + 20;
            } else {
                min_level = 1;
                max_level = STORE_OBJ_LEVEL + Math.Max(Misc.p_ptr.max_depth - 20, 0);
            }

            if (min_level > 55) min_level = 55;
            if (max_level > 70) max_level = 70;

            /* Consider up to six items */
            for (tries = 0; tries < 6; tries++)
            {
                Object_Kind kind;

                /* Work out the level for objects to be generated at */
                level = Random.rand_range(min_level, max_level);

                /* Black Markets have a random object, of a given level */
                if (sidx == STORE.B_MARKET)
                    kind = Object.Object.get_obj_num(level, false);
                else
                    kind = get_choice();

                /*** Pre-generation filters ***/

                /* No chests in stores XXX */
                if (kind.tval == TVal.TV_CHEST) continue;

                /*** Generate the item ***/

                /* Get local object */
                i_ptr = new Object.Object();
                //i_ptr = object_type_body;

                /* Create a new object of the chosen kind */
                i_ptr.prep(kind, level, aspect.RANDOMISE);

                /* Apply some "low-level" magic (no artifacts) */
                i_ptr.apply_magic(level, false, false, false);

                /* Reject if item is 'damaged' (i.e. negative mods) */
                switch (i_ptr.tval)
                {
                    case TVal.TV_DIGGING:
                    case TVal.TV_HAFTED:
                    case TVal.TV_POLEARM:
                    case TVal.TV_SWORD:
                    case TVal.TV_BOW:
                    case TVal.TV_SHOT:
                    case TVal.TV_ARROW:
                    case TVal.TV_BOLT:
                    {
                        if ((i_ptr.to_h < 0) || (i_ptr.to_d < 0))
                            continue;
                        if (i_ptr.to_a < 0) continue;
                        break;
                    }

                    case TVal.TV_DRAG_ARMOR:
                    case TVal.TV_HARD_ARMOR:
                    case TVal.TV_SOFT_ARMOR:
                    case TVal.TV_SHIELD:
                    case TVal.TV_HELM:
                    case TVal.TV_CROWN:
                    case TVal.TV_CLOAK:
                    case TVal.TV_GLOVES:
                    case TVal.TV_BOOTS:
                    {
                        if (i_ptr.to_a < 0) continue;
                        break;
                    }
                }

                /* The object is "known" and belongs to a store */
                i_ptr.ident |= Object.Object.IDENT_STORE;
                i_ptr.origin = Origin.STORE;

                /*** Post-generation filters ***/

                /* Black markets have expensive tastes */
                if ((sidx == STORE.B_MARKET) && !black_market_ok(i_ptr))
                    continue;

                /* No "worthless" items */
                if (i_ptr.value(1, false) < 1) continue;

                /* Mass produce and/or apply discount */
                mass_produce(i_ptr);

                /* Attempt to carry the object */
                carry(i_ptr);

                /* Definitely done */
                return true;
            }

            return false;
        }
Example #3
0
        /*
         * Attempt to make an object (normal or good/great)
         *
         * This routine plays nasty games to generate the "special artifacts".
         * We assume that the given object has been "wiped". You can optionally
         * receive the object's value in value if you pass a non-null pointer.
         *
         * Returns the whether or not creation worked.
         */
        public static bool make_object(Cave c, ref Object j_ptr, int lev, bool good, bool great, ref int value)
        {
            int Base;
            Object_Kind kind;

            /* Try to make a special artifact */
            if (Random.one_in_(good ? 10 : 1000)) {
                if (make_artifact_special(ref j_ptr, lev)) {
                    if (value != 0) value = j_ptr.value_real(1, false, true);
                    return true;
                }

                /* If we failed to make an artifact, the player gets a great item */
                good = great = true;
            }

            /* Base level for the object */
            Base = (good ? (lev + 10) : lev);

            /* Get the object, prep it and apply magic */
            kind = get_obj_num(Base, good || great);
            if (kind == null) return false;
            j_ptr.prep(kind, lev, aspect.RANDOMISE);
            j_ptr.apply_magic(lev, true, good, great);

            /* Generate multiple items */
            if (kind.gen_mult_prob >= Random.randint1(100))
                j_ptr.number = (byte)Random.randcalc(kind.stack_size, lev, aspect.RANDOMISE);

            if(value != 0) value = j_ptr.value_real(j_ptr.number, false, true);

            /* Return value, increased for uncursed out-of-depth objects */
            if (!Object_Flag.cursed_p(j_ptr.flags) && (kind.alloc_min > c.depth)) {
                if (value != 0) value = (kind.alloc_min - c.depth) * (value / 5);
            }

            return true;
        }