Quest timer - wonky display

Tukaram

Rookie
Timers have never been my strong suit. But this seems odd. I am showing the code snippet with the timer, and included the whole script. I am testing the timer for the quest delay. The time delay works, but look at the pic and see what odd number she speaks. "9.49295261 more minutes"? I thought she was going to start reciting pi.

Is this normal? Is there something I can do to make the timer display different? I see it is in minutes, I thought most timers were in seconds? If I change it to 'TimeSpan.FromSeconds(1800)' would it work (I just thought of that while typing, so I will try, but post anyway).

~Edit~ Nope seconds or minutes both work for the delay, and both display the same way. Odd...



C#:
namespace Server.Engines.Quests
{
    public class HavenMiners : BaseQuest
    {
        public override TimeSpan RestartDelay { get { return TimeSpan.FromMinutes(30); } }
        public override bool DoneOnce{ get{ return false; } }
        public override object Title{ get{ return "HavenMiners"; } }

Capture.JPG
 

Attachments

  • HavenMiners.cs
    2 KB · Views: 2
Last edited:

Lokai

Moderator
ServUO Developer
TotalMinutes is a double, so you need to cast it to an Int if you want it to display just the truncated minute integer. The code for this is in QuestHelper.cs. It looks like this currently:

C#:
                        TimeSpan ts = endTime - DateTime.UtcNow;
                        string str;

                        if (ts.TotalDays > 1)
                            str = string.Format("I cannot offer this quest again for about {0} more days.", ts.TotalDays);
                        else if (ts.TotalHours > 1)
                            str = string.Format("I cannot offer this quest again for about {0} more hours.", ts.TotalHours);
                        else if (ts.TotalMinutes > 1)
                            str = string.Format("I cannot offer this quest again for about {0} more minutes.", ts.TotalMinutes);
                        else
                            str = "I can offer this quest again very soon.";

                        ((Mobile)quester).SayTo(player, false, str);

This could be done like this:

C#:
                        TimeSpan ts = endTime - DateTime.UtcNow;
                        string str;

                        if (ts.TotalDays > 1)
                            str = string.Format("I cannot offer this quest again for about {0} more days.", (int)ts.TotalDays);
                        else if (ts.TotalHours > 1)
                            str = string.Format("I cannot offer this quest again for about {0} more hours.", (int)ts.TotalHours);
                        else if (ts.TotalMinutes > 1)
                            str = string.Format("I cannot offer this quest again for about {0} more minutes.", (int)ts.TotalMinutes);
                        else
                            str = "I can offer this quest again very soon.";

                        ((Mobile)quester).SayTo(player, false, str);

or you could use the string.Format method itself to display the number using however many digits of precision you desire. You would do this by replacing the {0} with {0:0.##} for example, which would display 2 digits after the dot.
 

Tukaram

Rookie
Cool. I will play with that.

But this cannot be normal, can it? I never saw it like that before. I have not done the hag quest in a while (Zeefzorpul). I do not recall her saying a time at all. More of a 'come back later' kind of thing. That would be fine too. I know the escort quests always just say it in whole minutes...
 
Last edited:

Lokai

Moderator
ServUO Developer
I couldn't say whether the code was changed. Are you using EC? Perhaps it's a recent change to the way EC handles the strings. Not sure.
 

SimonOmega

Citizen
If you want it to show a decimal value:
Double to Fixed Point Decimal:
(float)System.Math.Round( [YOUR_DOUBLE], [NUMBERS_AFTER_DECIMAL]);

So:
Example Double:
(float)System.Math.Round( Utility.RandomMinMax(1.5, 2.5), 2);
Would display a value like "1.82".