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!

Economy Control System Question

GhostRiderGrey

Sorceror
This is a question about the economy Control System http://www.runuo.com/community/threads/runuo-2-0-rc1-economy-control-system.77345/page-3

Specifically at Lokai's recommended code for lootpack.cs shown here
Code:
        //Economy Control Edit
        public int Roll()
        {
            int v = m_Bonus;
            double eco_Modifier = 100;
            double w;
 
            for ( int i = 0; i < m_Count; ++i )
                v += Utility.Random( 1, m_Sides );
            foreach (Item item in World.Items.Values)
            {
                if (item is StoneGoldCounter)
                {
                    StoneGoldCounter GC = (StoneGoldCounter)item;
                    eco_Modifier = GC.EconomyMultiplier;
                }
            }
            w = v * (eco_Modifier * .01);
            return (int)w;
        }

With this code installed, the server compiles just fine, but locks up when the world tries to load. I added some console writelines to try and see where its getting off track
Code:
//Economy Control Edit
        public int Roll()
        {
            int v = m_Bonus;
            double eco_Modifier = 100;
            double w;
 Console.WriteLine("1st");
            for (int i = 0; i < m_Count; ++i)
                v += Utility.Random(1, m_Sides);
 
 Console.WriteLine("2nd");
            foreach (Item item in World.Items.Values)
            {
                if (item is StoneGoldCounter)
                {
                    StoneGoldCounter GC = (StoneGoldCounter)item;
                    eco_Modifier = GC.EconomyMultiplier;
                }
            }
Console.WriteLine("3rd");
            w = v * (eco_Modifier * .01);
 Console.WriteLine("4th {0}", w);
            return (int)w;
        }
//Economy Control Edit End
With this code installed, the shard compiles then displays 1st, 2nd, 3rd,4th with a number, 1st, 2nd, 3rd,4th with a number. 1st, 2nd, 3rd,4th with a number over and over again....thousands of them but never finishes loading the world. Others seem to have this working, so i was wondering what I have done wrong?
 

Soteric

Knight
Code:
            foreach (Item item in World.Items.Values)
            {
                if (item is StoneGoldCounter)
                {
                    StoneGoldCounter GC = (StoneGoldCounter)item;
                    eco_Modifier = GC.EconomyMultiplier;
                }
            }
Replace this with
Code:
eco_Modifier = StoneGoldCounter.EconomyMultiplier;
It should speed the things up. Don't forget to remove Console.WriteLine lines before testing.
 

GhostRiderGrey

Sorceror
Thanks Soteric. A soon as I put that line in, Visual Studio flags an error on the EconomyMultiplier part of that line. The error is "Cannot access non-static field 'EconomyMultiplier' in static content"
 

Soteric

Knight
Okay, I see that instead of editing original files the author posted fixed version in the middle of the second page. Smart move :)

In StoneGoldCounter change
Code:
public int EconomyMultiplier;
to
Code:
public static int EconomyMultiplier = 100;
 

GhostRiderGrey

Sorceror
Thanks Soteric. That cleared the error in Lootpack.cs and it compiles and loads the world save just fine now.

A couple follow up quesitons. In the roll code posted above we have this line
Code:
double eco_Modifier = 100;
Visual Studio gives a warning on the "=100" of "Value assigned is not used in any execution path"

Does that mean that it is not even looking at the 100 here, and if one wanted to half the drop that the 100 should be changed to 50 in StoneGoldCounter instead
Code:
public static int EconomyMultiplier = 50;
 

GhostRiderGrey

Sorceror
Rereading the authors instructions, it looks like the value can be changed by Props on the counter in game. I assume that that will overriide our change in StoneGoldConter of
Code:
public static int EconomyMultiplier = 100;
 

Soteric

Knight
Yes, you are right.
Code:
double eco_Modifier = 100;
This value will never be used and will be overrided by EconomyMultiplier few lines below. I didn't mention it just to reduce confusion and edit as less lines as possible.

EconomyMultiplier value can be edited via props of StoneGoldCounter item. This
Code:
public static int EconomyMultiplier = 100;
is the default value which will be used if no StoneGoldCounter items were placed before.
 

daat99

Moderator
Staff member
You should keep in mind that in the original code (with the loop) the value 100 was acting as a "fall-back" value.
If the loop didn't find any valid item than the "100" assigned in the line you posted would've been used.

Since you removed the loop and always override the value with the static EconomyMultiplier than the original assignment of "100" is no longer used and always replaced by the static value.

It's best to delete the first line and add the word "double" to the new line you just added instead.

This way you'll declare the variable only once and assign it only once.


If you want to go with more efficiency and less readability approach than you can simply use this:
Code:
        //Economy Control Edit
        public int Roll()
        {
            int bonus = m_Bonus;
            for ( int i = 0; i < m_Count; ++i )
                bonus += Utility.Random( 1, m_Sides );
            return (int)(bonus * StoneGoldCounter.EconomyMultiplier * 0.01);
        }
 
Top