コード例 #1
0
        /*
         * Init players with some belongings
         *
         * Having an item identifies it and makes the player "aware" of its purpose.
         */
        static void player_outfit(Player.Player p)
        {
            //Object.Object object_type_body = new Object.Object();

            /* Give the player starting equipment */
            for (Start_Item si = Player.Player.instance.Class.start_items; si != null; si = si.next)
            {
                /* Get local object */
                Object.Object i_ptr = new Object.Object();

                /* Prepare the item */
                i_ptr.prep(si.kind, 0, aspect.MINIMISE);
                i_ptr.number = (byte)Random.rand_range(si.min, si.max);
                i_ptr.origin = Origin.BIRTH;

                i_ptr.flavor_aware();
                i_ptr.notice_everything();

                i_ptr.inven_carry(p);
                si.kind.everseen = true;

                /* Deduct the cost of the item from starting cash */
                p.au -= i_ptr.value(i_ptr.number, false);
            }

            /* Sanity check */
            if (p.au < 0)
            {
                p.au = 0;
            }

            /* Now try wielding everything */
            wield_all(p);
        }
コード例 #2
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);
        }
コード例 #3
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;
        }
コード例 #4
0
ファイル: Object_Make.cs プロジェクト: jobjingjo/csangband
        /*
         * 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;
        }
コード例 #5
0
ファイル: Store.cs プロジェクト: jobjingjo/csangband
        /*
         * 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;
        }
コード例 #6
0
ファイル: Store.cs プロジェクト: jobjingjo/csangband
        /*
         * Helper function: create an item with the given tval,sval pair, add it to the
         * store st.  Return the slot in the inventory.
         */
        int create_item(Object_Kind kind)
        {
            Object.Object obj = new Object.Object();

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

            /* Item belongs to a store */
            obj.ident |= Object.Object.IDENT_STORE;
            obj.origin = Origin.STORE;

            /* Attempt to carry the object */
            return carry(obj);
        }
コード例 #7
0
ファイル: Birther.cs プロジェクト: jobjingjo/csangband
        /*
         * Init players with some belongings
         *
         * Having an item identifies it and makes the player "aware" of its purpose.
         */
        static void player_outfit(Player.Player p)
        {
            //Object.Object object_type_body = new Object.Object();

            /* Give the player starting equipment */
            for (Start_Item si = Player.Player.instance.Class.start_items; si != null; si = si.next)
            {
                /* Get local object */
                Object.Object i_ptr = new Object.Object();

                /* Prepare the item */
                i_ptr.prep(si.kind, 0, aspect.MINIMISE);
                i_ptr.number = (byte)Random.rand_range(si.min, si.max);
                i_ptr.origin = Origin.BIRTH;

                i_ptr.flavor_aware();
                i_ptr.notice_everything();

                i_ptr.inven_carry(p);
                si.kind.everseen = true;

                /* Deduct the cost of the item from starting cash */
                p.au -= i_ptr.value(i_ptr.number, false);
            }

            /* Sanity check */
            if (p.au < 0)
                p.au = 0;

            /* Now try wielding everything */
            wield_all(p);
        }
コード例 #8
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);
        }
コード例 #9
0
ファイル: Object_Make.cs プロジェクト: jobjingjo/csangband
        /*
         * 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;
        }
コード例 #10
0
ファイル: Object_Make.cs プロジェクト: jobjingjo/csangband
        /*
         * 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;
        }