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!

Editing Summoner Victoria (Doom) Collection of Daemon Bones

Killroth

Sorceror
Hey, I'm trying to edit the summoner "Victoria" in doom to collect 1,000 Daemon Bones from all players collectively.

You would drop the bones on her and she would update (progress bar with VNC) would be best.

Once 1,000 are collected, the ferryman will teleport players to the boat if your within 6 tiles range.

I don't want this to be a quest because obviously you can't share quests like that with all players.

This system will be an attachement DOOM points / luck / highest damage system that I have created, that will use a town crier to open a portal every 2-4 hours to doom.

I will post the entire finished code for servers that wish to use the new system, which I think is 1000% less grindy and less tedious.

It's pretty great.

But im not familiar with this dragdrop stuff at all. Could anyone help me out and let me know where to get started? Here's the Victoria code:

Code:
using System;
using System.Collections;
using Server;
using Server.Items;
using Server.Mobiles;
using Server.Network;
using Server.ContextMenus;
using Server.Engines.Quests;
using Server.Engines.Quests.Necro;
 
namespace Server.Engines.Quests.Doom
{
public class Victoria : BaseQuester
{
public override bool ClickTitle{ get{ return true; } }
public override bool IsActiveVendor{ get{ return true; } }
public override bool DisallowAllMoves{ get{ return false; } }
 
public override void InitSBInfo()
{
m_SBInfos.Add( new SBMage() );
}
 
[Constructable]
public Victoria() : base( "the Bone Collector" )
{
}
 
public Victoria( Serial serial ) : base( serial )
{
}
 
public override void InitBody()
{
InitStats( 100, 100, 25 );
 
Female = true;
Hue = 0x8835;
Body = 0x191;
 
Name = "Victoria";
}
 
        private SummoningAltar m_Altar;
 
        private const int AltarRange = 24;
 
        public SummoningAltar Altar
        {
            get
            {
                if (m_Altar == null || m_Altar.Deleted || m_Altar.Map != this.Map || !Utility.InRange(m_Altar.Location, this.Location, AltarRange))
                {
                    foreach (Item item in GetItemsInRange(AltarRange))
                    {
                        if (item is SummoningAltar)
                        {
                            m_Altar = (SummoningAltar)item;
                            break;
                        }
                    }
                }
 
                return m_Altar;
            }
        }
 
public override void InitOutfit()
{
EquipItem( new GrandGrimoire() );
 
EquipItem( SetHue( new Sandals(), 0x455 ) );
EquipItem( SetHue( new SkullCap(), 0x455 ) );
EquipItem( SetHue( new PlainDress(), 0x455 ) );
 
HairItemID = 0x203C;
HairHue = 0x482;
}
 
        public override bool OnDragDrop( Mobile from, Item dropped )
        {
            PlayerMobile player = from as PlayerMobile;
            int bones = 0;
               if ( dropped is DaemonBone )
               {
                    DaemonBone bones = dropped(DaemonBone);
                    bones += dropped;
                    if ( bones.Amount >= 1000 )
                    {
                        PublicOverheadMessage( MessageType.Regular, 0x3B2, false, "Great! I now have enough bones to pay Chyloth for all of your ferry tickets!" ); 
                        PublicOverheadMessage( MessageType.Regular, 0x3B2, false, "Hurry! Go to the shore and ring the bell to summon Chyloth, I'll take care of the rest!" );
                        bones = 0;
                    }
                    else
                    {
                        ProgressBarGump pb = new ProgressBarGump(user, text: "Testing", max: 100);
 
                    SuperGump.Send(pb);
                    Timer.DelayCall(TimeSpan.FromSeconds(1.0), TimeSpan.FromMilliseconds(100), pb.MaxValue, delegate() { pb.Value++; });
                }
            }
        }
 
        public override void OnTalk(PlayerMobile player, bool contextMenu)
        {
            
        }
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();
}
}
}
 

pooka01

Sorceror
Code:
private int m_Bones = 0; //store it here if you want it collective and stored.
 
public override bool OnDragDrop( Mobile from, Item dropped )
        {
            PlayerMobile player = from as PlayerMobile;
                if ( dropped is DaemonBone )
               {
                    DaemonBone bones = dropped(DaemonBone);
                    int amt = dropped.Amount;
                    m_Bones += amt;
from.PublicOverheadMessage( MessageType.Regular, 0x3B2, false, "*{0} drops {1} daemon bones*", from.Name, amt );
 
                    if ( m_Bones.Amount >= 1000 )
                    {
                        PublicOverheadMessage( MessageType.Regular, 0x3B2, false, "Great! I now have enough bones to pay Chyloth for all of your ferry tickets!" ); 
                        PublicOverheadMessage( MessageType.Regular, 0x3B2, false, "Hurry! Go to the shore and ring the bell to summon Chyloth, I'll take care of the rest!" );
                        m_Bones = 0;
                    }
                    else
                    {
                        ProgressBarGump pb = new ProgressBarGump(user, text: "Testing", max: 100);
 
                    SuperGump.Send(pb);
                    Timer.DelayCall(TimeSpan.FromSeconds(1.0), TimeSpan.FromMilliseconds(100), pb.MaxValue, delegate() { pb.Value++; });
                }
            }
        }

if you want it to keep the bone amount on serialise, i'm out, i hate serialisation :p
 

daat99

Moderator
Staff member
Serialization can be easy if you understand how if/else statements and switch cases work.

You just need to remember 1 rule:
* Always read what you wrote in the exact same order.

You can use if/else and switch to manipulate the read order based on the version number (that you usually read first and increased when you changed the serialization last).

In your case you can use the serialization method like this:
Code:
    public override void Serialize( GenericWriter writer )
    {
        base.Serialize( writer );
 
        //daat99: increase the version number to 1
        writer.Write( (int) 1 ); // version
 
        //daat99: everything below the version will be in version 1, version 0 had nothing
        writer.Write( (int) variableToSave);
    }
In the deserialization method you have 2 options.
1. Using if statement:
Code:
    public override void Deserialize( GenericReader reader )
    {
        base.Deserialize( reader );
 
        int version = reader.ReadInt(); //reading the version saved last
 
        if ( version == 1 )
        {
            //daat99: we are reading a save file made with version 1
            //            we need to read what we wrote in version 1
            variableToSave = reader.ReadInt(); //daat99: we are reading our variable
        }
        else
        {
            //daat99: nothing to do if version isn't 1
        }
    }
2. Using switch case:
Code:
    public override void Deserialize( GenericReader reader )
    {
        base.Deserialize( reader );
 
        int version = reader.ReadInt(); //reading the version saved last
       
        switch (version)
        {
            case 1:
                //daat99: we are reading a save file made with version 1
                //            we need to read what we wrote in version 1
                variableToSave = reader.ReadInt(); //daat99: we are reading our variable
            goto case 0; //daat99: continue to do what version 0 did (which is nothing, but still...)
            case 0:
                //daat99: do nothing, we didn't write anything special in version 0
            break;
        }
    }

Notes:
1. Don't forget to change the variable name in both the serialization/deserialization methods.
2. I demonstrated the usage of an integer variable.
If you need to serialize/deserialize a variable from different type than you need to locate a variable with the same type that is serialized in another file and use the code that you see there.
 

Killroth

Sorceror
Ok, I got most of what I needed to work, however I'm running across some errors in progressgump bar.
If anyone has some knowledge of progressbar gumps, can you give me a hand?

I'm curious if I need to create a new method in ProgressBar.cs and call that method in this script.
Or do I create the progress bar method in this script completely?

Also,
If I want this information on it...
Code:
public  ProgressBarGump pb = new ProgressBarGump(PlayerMobile player, int x= 303, int y = 348, int w = 230, int h = 48, text = "Daemon Bones Collected: ", displayPercent = true, int max = 1000,int value = amt, ValueChangedHandler valueChanged = null)

what is the correct way to using the progressbar with that information in my script?
 

Killroth

Sorceror
Can you post the progress bar file in code tags please?
Sure, here you go.

Code:
#region Header
//  Vorspire    _,-'/-'/  ProgressBar.cs
//  .      __,-; ,'( '/
//    \.    `-.__`-._`:_,-._      _ , . ``
//    `:-._,------' ` _,`--` -: `_ , ` ,' :
//        `---..__,,--'  (C) 2014  ` -'. -'
//        #  Vita-Nex [http://core.vita-nex.com]  #
//  {o)xxx|===============-  #  -===============|xxx(o}
//        #        The MIT License (MIT)          #
#endregion
 
#region References
using System;
using System.Drawing;
 
using Server;
using Server.Gumps;
using Server.Mobiles;
#endregion
 
namespace VitaNex.SuperGumps.UI
{
    public enum ProgressBarFlow
    {
        Up = Direction.Up,
        UpRight = Direction.North,
        Right = Direction.Right,
        DownRight = Direction.East,
        Down = Direction.Down,
        DownLeft = Direction.South,
        Left = Direction.Left,
        UpLeft = Direction.West
    }
 
    public class ProgressBarGump : SuperGump
    {
        public static int DefaultWidth = 210;
        public static int DefaultHeight = 25;
        public static int DefaultPadding = 5;
        public static int DefaultBackgroundID = 9400;
        public static int DefaultForegroundID = 1464;
        public static string DefaultText = "Progress";
        public static ProgressBarFlow DefaultFlow = ProgressBarFlow.Right;
 
        private double? _InitValue, _InitMaxValue;
 
        private double _Value;
        private double _MaxValue;
 
        public int Width { get; set; }
        public int Height { get; set; }
        public int Padding { get; set; }
 
        public int BackgroundID { get; set; }
        public int ForegroundID { get; set; }
 
        public Color TextColor { get; set; }
        public string Text { get; set; }
 
        public bool DisplayPercent { get; set; }
        public ProgressBarFlow Flow { get; set; }
        public Action<ProgressBarGump, double> ValueChanged { get; set; }
 
        public double MaxValue
        {
            get { return _MaxValue; }
            set
            {
                _MaxValue = value;
 
                if (_InitMaxValue == null)
                {
                    _InitMaxValue = _MaxValue;
                }
            }
        }
 
        public double Value
        {
            get { return _Value; }
            set
            {
                if (_Value == value)
                {
                    return;
                }
 
                double oldValue = _Value;
 
                InternalValue = Math.Min(_MaxValue, value);
 
                OnValueChanged(oldValue);
            }
        }
 
        public double InternalValue
        {
            get { return Value; }
            set
            {
                if (_Value == value)
                {
                    return;
                }
 
                _Value = Math.Min(_MaxValue, value);
 
                if (_InitValue == null)
                {
                    _InitValue = _Value;
                }
            }
        }
 
        public double PercentComplete
        {
            get
            {
                if (_Value == _MaxValue)
                {
                    return 1.0;
                }
 
                if (_MaxValue != 0)
                {
                    return _Value / _MaxValue;
                }
 
                return 1.0;
            }
        }
 
        public bool Completed { get { return PercentComplete >= 1.0; } }
 
        public ProgressBarGump(
            PlayerMobile user,
            string text,
            double max,
            double value = 0,
            bool displayPercent = true,
            ProgressBarFlow? flow = null,
            Action<ProgressBarGump, double> valueChanged = null)
            : this(user, null, null, null, null, null, text, max, value, displayPercent, flow, valueChanged)
        { }
 
 
        public ProgressBarGump(
            PlayerMobile user,
            Gump parent = null,
            int? x = null,
            int? y = null,
            int? w = null,
            int? h = null,
            string text = null,
            double max = 100,
            double value = 0,
            bool displayPercent = true,
            ProgressBarFlow? flow = null,
            Action<ProgressBarGump, double> valueChanged = null)
            : base(user, parent, x, y)
        {
            Width = w ?? DefaultWidth;
            Height = h ?? DefaultHeight;
 
            BackgroundID = DefaultBackgroundID;
            ForegroundID = DefaultForegroundID;
 
            Padding = DefaultPadding;
 
            TextColor = DefaultHtmlColor;
            Text = text ?? DefaultText;
 
            DisplayPercent = displayPercent;
            Flow = flow ?? DefaultFlow;
            ValueChanged = valueChanged;
 
            _MaxValue = max;
            _Value = value;
 
            ForceRecompile = true;
        }
 
        public virtual void Reset()
        {
            _Value = _InitValue ?? 0;
            _MaxValue = _InitMaxValue ?? 100;
 
            _InitValue = _InitMaxValue = null;
        }
 
        public virtual string FormatText(bool html = false)
        {
            string text = String.Format("{0} {1}", Text, DisplayPercent ? PercentComplete.ToString("0.##%") : String.Empty);
 
            if (html && !String.IsNullOrWhiteSpace(text))
            {
                text = text.WrapUOHtmlColor(TextColor, false).WrapUOHtmlTag("center");
            }
 
            return text;
        }
 
        protected override void Compile()
        {
            Width = Math.Max(10 + Padding, Math.Min(1024, Width));
            Height = Math.Max(10 + Padding, Math.Min(768, Height));
 
            if (Padding < 0)
            {
                Padding = DefaultPadding;
            }
 
            base.Compile();
        }
 
        protected virtual void OnValueChanged(double oldValue)
        {
            if (ValueChanged != null)
            {
                ValueChanged(this, oldValue);
            }
 
            Refresh(true);
        }
 
        protected bool FlowOffset(ref int x, ref int y, ref int w, ref int h)
        {
            double xo = x, yo = y, wo = w, ho = h;
 
            switch (Flow)
            {
                case ProgressBarFlow.Up:
                    {
                        ho *= PercentComplete;
                        yo = (y + h) - ho;
                    }
                    break;
                case ProgressBarFlow.UpRight:
                    {
                        wo *= PercentComplete;
                        ho *= PercentComplete;
                        yo = (y + h) - ho;
                    }
                    break;
                case ProgressBarFlow.Right:
                    {
                        wo *= PercentComplete;
                    }
                    break;
                case ProgressBarFlow.DownRight:
                    {
                        wo *= PercentComplete;
                        ho *= PercentComplete;
                    }
                    break;
                case ProgressBarFlow.Down:
                    {
                        ho *= PercentComplete;
                    }
                    break;
                case ProgressBarFlow.DownLeft:
                    {
                        wo *= PercentComplete;
                        ho *= PercentComplete;
                        xo = (x + w) - wo;
                    }
                    break;
                case ProgressBarFlow.Left:
                    {
                        wo *= PercentComplete;
                        xo = (x + w) - wo;
                    }
                    break;
                case ProgressBarFlow.UpLeft:
                    {
                        wo *= PercentComplete;
                        ho *= PercentComplete;
                        xo = (x + w) - wo;
                        yo = (y + h) - ho;
                    }
                    break;
            }
 
            bool contained = xo >= x && yo >= y && xo + wo <= x + w && yo + ho <= y + h;
 
            x = (int)xo;
            y = (int)yo;
            w = (int)wo;
            h = (int)ho;
 
            return contained;
        }
 
        protected override void CompileLayout(SuperGumpLayout layout)
        {
            base.CompileLayout(layout);
 
            int xyPadding = Padding;
            int whPadding = xyPadding * 2;
 
            layout.Add(
                "background/body/base",
                () =>
                {
                    AddBackground(0, 0, Width, Height, BackgroundID);
 
                    if (Width > whPadding && Height > whPadding)
                    {
                        AddAlphaRegion(xyPadding, xyPadding, Width - whPadding, Height - whPadding);
                    }
 
                    //AddTooltip(Completed ? 1049071 : 1049070);
                });
 
            layout.Add(
                "imagetiled/body/visual",
                () =>
                {
                    if (Width <= whPadding || Height <= whPadding)
                    {
                        return;
                    }
 
                    int x = xyPadding, y = xyPadding, w = Width - whPadding, h = Height - whPadding;
 
                    if (FlowOffset(ref x, ref y, ref w, ref h))
                    {
                        AddImageTiled(x, y, w, h, ForegroundID);
                    }
                });
 
            layout.Add(
                "html/body/text",
                () =>
                {
                    if (Width <= whPadding || Height <= whPadding)
                    {
                        return;
                    }
 
                    string text = FormatText(true);
 
                    if (!String.IsNullOrWhiteSpace(text))
                    {
                        AddHtml(xyPadding, xyPadding, Width - whPadding, Math.Max(40, Height - whPadding), text, false, false);
                    }
                });
        }
    }
}
 

daat99

Moderator
Staff member
I don't really have time to go into the code at the moment :(
If I forget about this and don't reply in 48 hours than please send me a PM with a reminder that I want to look at this.
 
Top