RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Another Treasure Chest Question

Johabius

Knight
Another Treasure Chest Question

Okay, I have a spawnable dungeon chest that spawns with loot inside. I am wanting to add an item with a chance to be in that chest. This is what I have so far:
Code:
using System;
using System.Collections;
using Server;
using Server.Gumps;
using Server.Multis;
using Server.Network;
using Server.ContextMenus;
using Server.Engines.PartySystem;

namespace Server.Items
{
    public class TreasureChestLevel1 : LockableContainer
    {
        private const int m_Level = 1;

        public override bool Decays{ get{ return true; } } 

        public override TimeSpan DecayTime{ get{ return TimeSpan.FromMinutes( Utility.Random( 15, 60 ) ); } }

        private void SetChestAppearance()
        {
           bool UseFirstItemId = Utility.RandomBool();

            switch( Utility.RandomList( 0, 1, 2 ) )
            {
                case 0:// Large Crate
                    this.ItemID = ( UseFirstItemId ? 0xe3c : 0xe3d );
                    this.GumpID = 0x44;
                    break;

                case 1:// Medium Crate
                    this.ItemID = ( UseFirstItemId ? 0xe3e : 0xe3f );
                    this.GumpID = 0x44;
                    break;

                case 2:// Small Crate
                    this.ItemID = ( UseFirstItemId ? 0x9a9 : 0xe7e );
                    this.GumpID = 0x44;
                    break;
            
            }
        }

        public override int DefaultGumpID{ get{ return 0x42; } }
        public override int DefaultDropSound{ get{ return 0x42; } }

        public override Rectangle2D Bounds
        {
            get{ return new Rectangle2D( 18, 105, 144, 73 ); }
        }

        [Constructable]
        public TreasureChestLevel1() : base( 0xE41 )
        {
            this.SetChestAppearance();
            Movable = false;
            LiftOverride = true;

            TrapType = TrapType.DartTrap;
            TrapPower = m_Level * Utility.Random( 1, 25 );
            Locked = true;

            RequiredSkill = 52;
            LockLevel = this.RequiredSkill - Utility.Random( 1, 10 );
            MaxLockLevel = this.RequiredSkill;

            // According to OSI, loot in level 1 chest is:
            //  Gold 25 - 50
            //  Bolts 10
            //  Gems
            //  Normal weapon
            //  Normal armour
            //  Normal clothing
            //  Normal jewelry

            // Gold
            DropItem( new Gold( Utility.Random( 30, 100 ) ) );
            
            //added tmapbook
            [COLOR=Red]if( Utility.RandomDouble <= 0.05 )
                DropItem( new TMapBook() );[/COLOR]
            //end addition of tmapbook
            
            // Drop bolts
            //DropItem( new Bolt( 10 ) );

            // Gems
            if( Utility.RandomBool() == true )
            {
                Item GemLoot = Loot.RandomGem();
                GemLoot.Amount = Utility.Random( 1, 3 );
                DropItem( GemLoot );
            }

            // Weapon
            if( Utility.RandomBool() == true )
                DropItem( Loot.RandomWeapon() );
            
            // Armour
            if( Utility.RandomBool() == true )
                DropItem( Loot.RandomArmorOrShield() );

            // Clothing
            if( Utility.RandomBool() == true )
                DropItem( Loot.RandomClothing() );

            // Jewelry
            if( Utility.RandomBool() == true )
                DropItem( Loot.RandomJewelry() );
        }

        public TreasureChestLevel1( Serial serial ) : base( serial )
        {
        }

        public override void Serialize( GenericWriter writer )
        {
            base.Serialize( writer );
            writer.Write( (int) 1 ); // version
        }

        public override void Deserialize( GenericReader reader )
        {
            base.Deserialize( reader );
            int version = reader.ReadInt();
        }
    }
}
Portion in red is what I am trying to add. This is the error:

Code:
Errors:
 + Custom/Items/ArteGordon's Treasure Chests/TreasureChestLevel1.cs:
    CS0019: Line 80: Operator '<=' cannot be applied to operands of type 'method
 group' and 'double'
First of all, I have no idea what that error means in my limited knowledge of C#, second how do I get this working?
 

Greystar

Wanderer
Johabius;748563 said:
Okay, I have a spawnable dungeon chest that spawns with loot inside. I am wanting to add an item with a chance to be in that chest. This is what I have so far:
Code:
using System;
using System.Collections;
using Server;
using Server.Gumps;
using Server.Multis;
using Server.Network;
using Server.ContextMenus;
using Server.Engines.PartySystem;

namespace Server.Items
{
    public class TreasureChestLevel1 : LockableContainer
    {
        private const int m_Level = 1;

        public override bool Decays{ get{ return true; } } 

        public override TimeSpan DecayTime{ get{ return TimeSpan.FromMinutes( Utility.Random( 15, 60 ) ); } }

        private void SetChestAppearance()
        {
           bool UseFirstItemId = Utility.RandomBool();

            switch( Utility.RandomList( 0, 1, 2 ) )
            {
                case 0:// Large Crate
                    this.ItemID = ( UseFirstItemId ? 0xe3c : 0xe3d );
                    this.GumpID = 0x44;
                    break;

                case 1:// Medium Crate
                    this.ItemID = ( UseFirstItemId ? 0xe3e : 0xe3f );
                    this.GumpID = 0x44;
                    break;

                case 2:// Small Crate
                    this.ItemID = ( UseFirstItemId ? 0x9a9 : 0xe7e );
                    this.GumpID = 0x44;
                    break;
            
            }
        }

        public override int DefaultGumpID{ get{ return 0x42; } }
        public override int DefaultDropSound{ get{ return 0x42; } }

        public override Rectangle2D Bounds
        {
            get{ return new Rectangle2D( 18, 105, 144, 73 ); }
        }

        [Constructable]
        public TreasureChestLevel1() : base( 0xE41 )
        {
            this.SetChestAppearance();
            Movable = false;
            LiftOverride = true;

            TrapType = TrapType.DartTrap;
            TrapPower = m_Level * Utility.Random( 1, 25 );
            Locked = true;

            RequiredSkill = 52;
            LockLevel = this.RequiredSkill - Utility.Random( 1, 10 );
            MaxLockLevel = this.RequiredSkill;

            // According to OSI, loot in level 1 chest is:
            //  Gold 25 - 50
            //  Bolts 10
            //  Gems
            //  Normal weapon
            //  Normal armour
            //  Normal clothing
            //  Normal jewelry

            // Gold
            DropItem( new Gold( Utility.Random( 30, 100 ) ) );
            
            //added tmapbook
            [COLOR=Red]if( Utility.RandomDouble <= 0.05 )
                DropItem( new TMapBook() );[/COLOR]
            //end addition of tmapbook
            
            // Drop bolts
            //DropItem( new Bolt( 10 ) );

            // Gems
            if( Utility.RandomBool() == true )
            {
                Item GemLoot = Loot.RandomGem();
                GemLoot.Amount = Utility.Random( 1, 3 );
                DropItem( GemLoot );
            }

            // Weapon
            if( Utility.RandomBool() == true )
                DropItem( Loot.RandomWeapon() );
            
            // Armour
            if( Utility.RandomBool() == true )
                DropItem( Loot.RandomArmorOrShield() );

            // Clothing
            if( Utility.RandomBool() == true )
                DropItem( Loot.RandomClothing() );

            // Jewelry
            if( Utility.RandomBool() == true )
                DropItem( Loot.RandomJewelry() );
        }

        public TreasureChestLevel1( Serial serial ) : base( serial )
        {
        }

        public override void Serialize( GenericWriter writer )
        {
            base.Serialize( writer );
            writer.Write( (int) 1 ); // version
        }

        public override void Deserialize( GenericReader reader )
        {
            base.Deserialize( reader );
            int version = reader.ReadInt();
        }
    }
}
Portion in red is what I am trying to add. This is the error:

Code:
Errors:
 + Custom/Items/ArteGordon's Treasure Chests/TreasureChestLevel1.cs:
    CS0019: Line 80: Operator '<=' cannot be applied to operands of type 'method
 group' and 'double'
First of all, I have no idea what that error means in my limited knowledge of C#, second how do I get this working?

you missed the () after double.
 

Johabius

Knight
Greystar;748588 said:
you missed the () after double.
Yup, sure did...why do I always miss the little stuff like that...lol. I'll blame it on the kids again:D

I'll have to read up on RandomDouble to figure out what the numbers and math is behind it, right now though, this works, I'll figure out the "why it works" later. Thanks, man:)
 

Greystar

Wanderer
Johabius;748590 said:
Yup, sure did...why do I always miss the little stuff like that...lol. I'll blame it on the kids again:D

I'll have to read up on RandomDouble to figure out what the numbers and math is behind it, right now though, this works, I'll figure out the "why it works" later. Thanks, man:)

Well one of the devs mentioned before Utility.RandomDouble() give a number up to .99 or something like that. so any number less then that would work.

I've done that and to make it further random if done something like

if (Utility.RandomDouble() < 0.04)
{
if (Utility.RandomBool())
{
//do stuff
}
else
{
//do other stuff
}
}
 

Johabius

Knight
Greystar;748595 said:
Well one of the devs mentioned before Utility.RandomDouble() give a number up to .99 or something like that. so any number less then that would work.

I've done that and to make it further random if done something like

if (Utility.RandomDouble() < 0.04)
{
if (Utility.RandomBool())
{
//do stuff
}
else
{
//do other stuff
}
}
Cool, might have to play around with this a bit when I add my stuff that I have no other way of distributing. Next thing on my list is adding things to the TreasureMapChests I think.

Yeah, now that you mention it, I remember Zippy ( i think ) mentioning the 0.99 bit
 
Top