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!

Packing Loot on Death

Hi Community,

I am currently working on a softcoded questing system where quests can be changed, added and managed during server runtime. My current problem is the "collect quest items" goal. When a Mobile is killed (currently using the OnKilledBy(Mobile m) from BaseCreature but that can change) all goals of all quests the killer and his party has are checked and updated. In the case of the "collect quest items" goal, a dice is rolled and compared with the chance of the quest item dropping and then the quest item should be added to the loot.

I tried to realize that this way:

Code:
       public override void checkMob(Mobile m)
        {
            checkItem(p,null);
            if (complete == true) return;

            Type t = (this.goal as CollectQuestItemGoal).mobtype;
            if (t != m.GetType()) return;

            if (Utility.Random(100) <= (this.goal as CollectQuestItemGoal).chance)
            {
                Console.WriteLine("It should be packed!");
                QuestItem qI = new QuestItem(1, (this.goal as CollectQuestItemGoal).itemName, (this.goal as CollectQuestItemGoal).itemID);
                if (m is Mobiles.BaseCreature) (m as Mobiles.BaseCreature).PackItem(qI);
                else m.AddItem(qI);
            }

        }

The Console.WriteLine is reached so I think there is something wrong in the way I tried to realize it. Either OnKilledBy(Mobile m) is the wrong point to insert items or PackItem is the wrong method to add to loot.

Any suggestions?
 

Soteric

Knight
If you say that Console.WriteLine code is reachable then I see the only reason for item not to be added: the creature is summoned. In any other cases the PackItem method should drop the item to creature's pack.
 
Nope thats easily checked with another line of code:
Code:
       public override void checkMob(Mobile m)
        {
            checkItem(p,null);
            if (complete == true) return;

            Type t = (this.goal as CollectQuestItemGoal).mobtype;
            if (t != m.GetType()) return;

            if (Utility.Random(100) <= (this.goal as CollectQuestItemGoal).chance)
            {
                Console.WriteLine("It should be packed!");
                QuestItem qI = new QuestItem(1, (this.goal as CollectQuestItemGoal).itemName, (this.goal as CollectQuestItemGoal).itemID);
                if (m is Mobiles.BaseCreature) (m as Mobiles.BaseCreature).PackItem(qI);
                else m.AddItem(qI);
                if (m.Backpack.Items.Contains(qI)) Console.WriteLine("Packing Succesful!");
            }

        }
Both lines are printed though there is still nothing in the loot. I think the way loot is generated pretty much ignores packed items.
 

Soteric

Knight
Generated loot shouldn't remove items already added to pack. Probably the item is blessed. Post QuestItem please.
 
Code:
    public class QuestItem : Item
    {

        public override double DefaultWeight
        {
            get { return 0.1; }
        }

        private string name;
        public override string  DefaultName
        {
            get
            {
                return name;
            }
        }

        [Constructable]
        public QuestItem(string name, int id) : this( 1,name,id )
        {
        }

        [Constructable]
        public QuestItem( int amount,string name,int id ) : base( id )
        {
            Stackable = true;
            Amount = amount;
            this.name = name;
            this.Name = name;
        }

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



        public override void Serialize( GenericWriter writer )
        {
            base.Serialize( writer );

            writer.Write( (int) 0 ); // version
            writer.Write(name);
            this.Name = name;
        }

        public override void Deserialize( GenericReader reader )
        {
            base.Deserialize( reader );

            int version = reader.ReadInt();
            name = reader.ReadString();
        }

 


    }

In the test the quest item is created with (1,"a wolves tooth",7943)
 

Soteric

Knight
It seems I get it. If you call checkMob() method from OnDeath method it means that the creature is already deleted and all the items were moved to creature's corpse. So you should add item to corpse instead of creature itself.
 
Ok, but what method do I override or inject code into to achieve that? Like I said I tried it with the OnKilledBy(Mobile m) since this has a reference to the killer and thats what I need. A reference to the killer and seemingly one to the corpse too.
 

Soteric

Knight
You can pass container reference to checkMob method or add item to container directly in OnDeath method. checkMob() can return you true/false in this case to determine whether item should be added or not.
 
Top