APPROVED: Powerscroll combine bag

User avatar
Harabakc
Legendary Scribe
Posts: 467
Joined: Thu Jun 22, 2006 2:43 pm

APPROVED: Powerscroll combine bag

Post by Harabakc »

Uhm, do people really care about self repair? Legendary repair deeds are a dime a dozen.
User avatar
OldManAlewar
Legendary Scribe
Posts: 408
Joined: Sun Jan 06, 2008 3:42 pm

Re: Coding for credits.

Post by OldManAlewar »

I certainly do if it's leather an I'm doing a champ. Also some arti pieces have only 30 dura. That said I have 4 gems yet to design so I'll take suggestions.
Vrul D'gore
Apprentice Scribe
Posts: 16
Joined: Sat Sep 06, 2008 11:03 am
Location: North Georgia

Re: Coding for credits.

Post by Vrul D'gore »

what does coding for credits mean? and how did we get to talking about repair deeds in here? oh and I need some blacksmithing ones Hara. Your vendor is sold out. :)

Old man... what do you mean you have 4 gems left to design taking suggestions?
LordGaav
Adept Scribe
Posts: 49
Joined: Fri Sep 12, 2008 4:09 pm

Re: Coding for credits.

Post by LordGaav »

I have taken it upon myself to look at the powerscroll combining bag. I'm currently experimenting with something similar to a blacksmith hammer, only for powerscrolls. In this way, the power scrolls will behave like a kind of resource like wood and ingots.
LordGaav
Adept Scribe
Posts: 49
Joined: Fri Sep 12, 2008 4:09 pm

Re: Coding for credits.

Post by LordGaav »

Lord_Gaav wrote:I have taken it upon myself to look at the powerscroll combining bag. I'm currently experimenting with something similar to a blacksmith hammer, only for powerscrolls. In this way, the power scrolls will behave like a kind of resource like wood and ingots.
Actually, in retrospect, I'm probably not using this approach. Seeing as all Powerscrolls are a single item type, there is no easy way to distinguish between them. It is easier to create a container that checks what Powerscrolls it contains, and acts accordingly to that.
User avatar
+Colibri
Administrator
Posts: 3958
Joined: Sat Feb 25, 2006 4:08 pm
Location: static void Main

Re: Coding for credits.

Post by +Colibri »

Yep, the craft system doesn't distinguish.

I'd say just a bag, and there you override the functions:
public override bool OnDragDropInto( Mobile from, Item item, Point3D p )
public override bool OnDragDrop( Mobile from, Item item )

something along the lines:
if ( base.OnDragDrop(...) )
- - CheckCombine()

And the checkcombine() function should count how many scrolls of the same type there are and if there's enough, it deletes them and adds a new pack.

I'd just extend the Bag class, it's most simple. Make a nice hue and name, and those extra functions.

Since this is basically a project i'll move it to a separate thread.
+Colibri, Administrator of UO Excelsior Shard

Don't know what the purpose of your life is? Well then make something up! ;)
(Old Colibrian proverb)
User avatar
Harabakc
Legendary Scribe
Posts: 467
Joined: Thu Jun 22, 2006 2:43 pm

Re: APPROVED: Powerscroll combine bag

Post by Harabakc »

We appear to be missing half the post.
LordGaav
Adept Scribe
Posts: 49
Joined: Fri Sep 12, 2008 4:09 pm

Re: APPROVED: Powerscroll combine bag

Post by LordGaav »

Well then, I'm practically done with the bag. It's now basically a bag which upon Drag and Drop checks if the item is a PS. If it's not, it won't accept it. Upon dropping the x-th scroll of the same type in the bag, one new PS of the same type but next level of power is spawned into the bag, and the lesser scrolls are deleted.

All that remains is a proper name and icon. I'm currently calling it the Powerscroll Bag, which looks nike a normal bag with a blueish hue.
Lyandrin
Elder Scribe
Posts: 136
Joined: Mon Sep 08, 2008 3:40 am
Location: Stockholm, Sweden
Contact:

Re: APPROVED: Powerscroll combine bag

Post by Lyandrin »

So if I'm not completely mistaken here you can add like 3 110s plus 2 115 and get a 120 more or less?
User avatar
+Colibri
Administrator
Posts: 3958
Joined: Sat Feb 25, 2006 4:08 pm
Location: static void Main

Re: APPROVED: Powerscroll combine bag

Post by +Colibri »

I'm thinking more about 5 lesser to get a greater... but yes, that's the point.

Great Lord Gaav, can you please send the script to my email? It's listed on the front page.
+Colibri, Administrator of UO Excelsior Shard

Don't know what the purpose of your life is? Well then make something up! ;)
(Old Colibrian proverb)
LordGaav
Adept Scribe
Posts: 49
Joined: Fri Sep 12, 2008 4:09 pm

Re: APPROVED: Powerscroll combine bag

Post by LordGaav »

The way it works now is for example:

You start with 5x 110 Blacksmith PS
You get 1x 115 Blacksmith PS

So they have to be the same type, as well as the same power.
Lyandrin
Elder Scribe
Posts: 136
Joined: Mon Sep 08, 2008 3:40 am
Location: Stockholm, Sweden
Contact:

Re: APPROVED: Powerscroll combine bag

Post by Lyandrin »

thank you :)

*Runs off to buy any 115 PS she can find*
LordGaav
Adept Scribe
Posts: 49
Joined: Fri Sep 12, 2008 4:09 pm

Re: APPROVED: Powerscroll combine bag

Post by LordGaav »

Here's the first working version of the script, critique is welcome :P

Code: Select all

using System;
using System.Collections;
using Server.Multis;
using Server.Mobiles;
using Server.Network;

namespace Server.Items
{
    public class PowerscrollBag : BaseContainer
    {
        #region default stuff
        public override int DefaultGumpID { get { return 0x3D; } }
        public override int DefaultDropSound { get { return 0x48; } }

        public override Rectangle2D Bounds
        {
            get { return new Rectangle2D(29, 34, 108, 94); }
        }

        [Constructable]
        public PowerscrollBag() : base(0xE76)
        {
            Weight = 2.0;
            Hue = 86;
        }

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

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

            writer.Write((int)0); // version
        }

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

            int version = reader.ReadInt();
        }
        #endregion

        public override bool OnDragDropInto(Mobile from, Item item, Point3D p)
        {   
            // Check if this action passes BaseContainer's check
            if (!base.OnDragDropInto(from, item, p))
            {
                return false;
            }
            else
            {
                // Item is a PowerScroll
                if (item.ItemID == 0x14F0)
                {
                    // Recast Item
                    PowerScroll s = (PowerScroll)item;
                    // If scroll value is withing normal values
                    if (s.Value >= 105 && s.Value <= 115)
                    {
                        from.PublicOverheadMessage(MessageType.System, 0x22, true, "Powerscroll added, triggering check");

                        // Start counting
                        this.countPowerScrolls(s.Skill, s.Value);
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                else
                {
                    return false;
                }                
            }
        }

        public override bool OnDragDrop(Mobile from, Item dropped)
        {
            return this.OnDragDropInto(from, dropped, new Point3D());
        }

        /**
         * Count all PowerScrolls of a given type.
         */
        private void countPowerScrolls(SkillName skill, double power)
        {
            // Loop through all Items in this Bag
            int count = 0;
            foreach (Item i in this.Items)
            {
                // If this item is a PowerScroll
                if (i.ItemID == 0x14F0)
                {
                    // Recast Item
                    PowerScroll s = (PowerScroll) i;
                    // If this PowerScroll is the same as the one that was dropped
                    if (s.Skill == skill && s.Value == power)
                    {
                        // Add one
                        count++;
                    }
                }
            }

            Console.WriteLine("Counted: " + count.ToString() + "x " + skill.ToString() + " scrolls (" + power.ToString() + ")");

            // Check if transformation threshold has been reached
            this.transformPowerScrolls(skill, power, count);
        }

        /**
         * Transforms lesser PowerScrolls into greater ones, if the threshold has been reached.
         * 
         * Transformation thresholds:
         * 105 -> 110 PS: 7x
         * 110 -> 115 PS: 7x
         * 115 -> 120 PS: 5x
         */
        private void transformPowerScrolls(SkillName skill, double power, int count)
        {
            // We don't care about doubles
            switch (Convert.ToInt16(Math.Ceiling(power)))
            {
                case 105:
                    if (count >= 7)
                    {
                        Console.WriteLine("Sufficient scrolls for transform");
                        this.AddItem(new PowerScroll(skill, 110));
                        this.removePowerScrolls(skill, power);
                    }
                    else
                    {
                        Console.WriteLine("Insufficient scrolls for transform");
                    }
                    break;
                case 110:
                    if (count >= 7)
                    {
                        Console.WriteLine("Sufficient scrolls for transform");
                        this.AddItem(new PowerScroll(skill, 115));
                        this.removePowerScrolls(skill, power);
                    }
                    else
                    {
                        Console.WriteLine("Insufficient scrolls for transform");
                    }
                    break;
                case 115:
                    if (count >= 5)
                    {
                        Console.WriteLine("Sufficient scrolls for transform");
                        this.AddItem(new PowerScroll(skill, 120));
                        this.removePowerScrolls(skill, power);
                    }
                    else
                    {
                        Console.WriteLine("Insufficient scrolls for transform");
                    }
                    break;
                default:
                    Console.WriteLine("What manner of PowerScroll is this!?!?!");
                    break;
            }
        }

        /**
         * Removes all PowerScrolls of a given type
         */
        private void removePowerScrolls(SkillName skill, double power)
        {
            for (int i = (this.Items.Count - 1); i >= 0; i--)
            {
                Console.WriteLine("Checking item " + i.ToString());
                Item item = (Item)this.Items[i];
                if (item.ItemID == 0x14F0)
                {
                    PowerScroll s = (PowerScroll)item;
                    if (s.Skill == skill && s.Value == power)
                    {
                        item.Delete();
                    }
                }
            }
        }
    }
}
User avatar
+Colibri
Administrator
Posts: 3958
Joined: Sat Feb 25, 2006 4:08 pm
Location: static void Main

Re: APPROVED: Powerscroll combine bag

Post by +Colibri »

I think this new cooperation system might just work :)

Ok looks good, there's a few things that need to be fixed:
1. Since it's a bag, i'd simply extend the Bag class and remove all that DefaultGumpId/Sound, Bounds.
2. There are many items that use itemid 0x14F0 (bank checks, misc deeds), so the correct way to check for the correct type would be:
if ( item is PowerScroll )
3. This is optional, but i suggest that you dont use single chars for variable names. So, "PowerScroll scroll = .." and "Item item". Also RunUO is coded so that private&public methods are all capitalized. But if you leave the private ones starting with a lowercase that's fine too (in a way even more correct).
4. Comment out all of the Console.WriteLine. (a server with 30 people already makes a lot of console chatter :))
5. Checking the power of scrolls, i'd say you should define actual values, not the value range.
6. Instead of Math.Ceil i'd rather use Math.Round... Sometimes these doubles get freaky and a ceiling of 115.0000000001 can be turned into 116.
+Colibri, Administrator of UO Excelsior Shard

Don't know what the purpose of your life is? Well then make something up! ;)
(Old Colibrian proverb)
LordGaav
Adept Scribe
Posts: 49
Joined: Fri Sep 12, 2008 4:09 pm

Re: APPROVED: Powerscroll combine bag

Post by LordGaav »

Ah, feedback :P
+Colibri wrote:I think this new cooperation system might just work :)

Ok looks good, there's a few things that need to be fixed:
1. Since it's a bag, i'd simply extend the Bag class and remove all that DefaultGumpId/Sound, Bounds.
2. There are many items that use itemid 0x14F0 (bank checks, misc deeds), so the correct way to check for the correct type would be:
if ( item is PowerScroll )
3. This is optional, but i suggest that you dont use single chars for variable names. So, "PowerScroll scroll = .." and "Item item". Also RunUO is coded so that private&public methods are all capitalized. But if you leave the private ones starting with a lowercase that's fine too (in a way even more correct).
4. Comment out all of the Console.WriteLine. (a server with 30 people already makes a lot of console chatter :))
5. Checking the power of scrolls, i'd say you should define actual values, not the value range.
6. Instead of Math.Ceil i'd rather use Math.Round... Sometimes these doubles get freaky and a ceiling of 115.0000000001 can be turned into 116.
  1. I actually took the Bag class, and stripped all the unneeded methods. I think this methods is better, because (potential) future changes to bag now don't directly interact with this new class.
  2. Will do, I discovered that language construct later myself :P.
  3. Noted.
  4. Good point, of course this was just debug :P. We just need to decide on proper messages, and how and when we show them.
  5. Might be better indeed.
  6. Good point.
Locked