Register for your free account! | Forgot your password?

Go Back   elitepvpers > MMORPGs > Nostale
You last visited: Today at 18:10

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Release: Steuer System

Discussion on Release: Steuer System within the Nostale forum part of the MMORPGs category.

Reply
 
Old   #1
 
Irelia<3's Avatar
 
elite*gold: 0
Join Date: Sep 2018
Posts: 239
Received Thanks: 59
Release: Steuer System

NRunHandler.cs

Leider nur halb Fertig aber ich hoffe Ihr könnt damit was anfangen.
Code:
        //NosTale Steuern.
        public static void Steuern(ClientSession Session, NRunPacket packet)
        {
            if (Session.Character.Gold < 100000000)
            {
                int Prozent = 100;
                string ProzentString = Convert.ToString(Prozent);
                int Gold = 100000000;
                string GoldString = Convert.ToString(Gold);
                int Steuern = 5;
                string SteuernString = Convert.ToString(Steuern);
                Session.Character.Gold = Steuern / Gold * Prozent;
                int ergebnis = (Steuern / Gold) * Prozent;
                string ergebnisString = Convert.ToString(ergebnis);
                Session.SendPacket(UserInterfaceHelper.GenerateMsg(string.Format(Language.Instance.GetMessageFromergenisString("DU_MUSST_DIE_STEUERN_ZAHLEN", ergebnisString)), 0));
            }
            else
            {
                Session.Disconnect();
            }
        }
Language.cs
Code:
        public string GetMessageFromergenisString(string v, string ergebnisString)
        {
            return _language.GetOrAdd(ergebnisString, name =>
            {
                string value = _manager?.GetString(name, _resourceCulture);

                if (string.IsNullOrEmpty(value))
                {
                    _streamWriter?.WriteLine(name);
                    return "none";
                }

                return value;
            });
        }
Irelia<3 is offline  
Thanks
1 User
Old 12/22/2019, 09:40   #2
 
erixor's Avatar
 
elite*gold: 0
Join Date: Jul 2013
Posts: 345
Received Thanks: 933
Why would you add anything to the language file ? Why would you code in german ? Why do you disconnect the session in a nrun handler ?

Also, instead of Convert.ToString, you could just use templated strings like $"{var}", which is slightly more efficient.

Also, I'm not sure that setting the character's gold this way is good, shouldn't it be a -= or a += ? (I can't understand german, so idk what you're trying to do here).

Also, you should generate the gold packet.
erixor is offline  
Old 12/22/2019, 11:09   #3
 
Cryless~'s Avatar
 
elite*gold: 0
Join Date: Sep 2015
Posts: 480
Received Thanks: 529
Quote:
Originally Posted by erixor View Post
Why would you add anything to the language file ? Why would you code in german ? Why do you disconnect the session in a nrun handler ?

Also, instead of Convert.ToString, you could just use templated strings like $"{var}", which is slightly more efficient.

Also, I'm not sure that setting the character's gold this way is good, shouldn't it be a -= or a += ? (I can't understand german, so idk what you're trying to do here).

Also, you should generate the gold packet.
You should prefer it because it is cleaner but it is far from being more efficient.

Code:
using System;
using System.Diagnostics;

namespace Foo
{
    class Program
    {
        static void Main(string[] args)
        {
            Stopwatch stopWatch = new Stopwatch();

            string bar;

            stopWatch.Start();

            for (int i = 0; i < 100000; i++)
            {
                bar = $"{i}";
            }

            stopWatch.Stop();

            Console.WriteLine($"string interpolation = {stopWatch.ElapsedMilliseconds} ms");

            stopWatch.Reset();

            stopWatch.Start();

            for (int i = 0; i < 100000; i++)
            {
                bar = i.ToString();
            }

            stopWatch.Stop();

            Console.WriteLine($"ToString = {stopWatch.ElapsedMilliseconds} ms");
        }
    }
}
Output:

Code:
% dotnet run
string interpolation = 10 ms
ToString = 4 ms
% dotnet run
string interpolation = 10 ms
ToString = 3 ms
% dotnet run
string interpolation = 10 ms
ToString = 3 ms
As you can see, it is 2-3 times slower than .ToString()! I suggest you testing next time.
Cryless~ is offline  
Old 12/22/2019, 14:12   #4

 
Blowa's Avatar
 
elite*gold: 98
Join Date: Jan 2010
Posts: 624
Received Thanks: 1,716
Quote:
Originally Posted by Cryless~ View Post
You should prefer it because it is cleaner but it is far from being more efficient.

Code:
using System;
using System.Diagnostics;

namespace Foo
{
    class Program
    {
        static void Main(string[] args)
        {
            Stopwatch stopWatch = new Stopwatch();

            string bar;

            stopWatch.Start();

            for (int i = 0; i < 100000; i++)
            {
                bar = $"{i}";
            }

            stopWatch.Stop();

            Console.WriteLine($"string interpolation = {stopWatch.ElapsedMilliseconds} ms");

            stopWatch.Reset();

            stopWatch.Start();

            for (int i = 0; i < 100000; i++)
            {
                bar = i.ToString();
            }

            stopWatch.Stop();

            Console.WriteLine($"ToString = {stopWatch.ElapsedMilliseconds} ms");
        }
    }
}
Output:

Code:
% dotnet run
string interpolation = 10 ms
ToString = 4 ms
% dotnet run
string interpolation = 10 ms
ToString = 3 ms
% dotnet run
string interpolation = 10 ms
ToString = 3 ms
As you can see, it is 2-3 times slower than .ToString()! I suggest you testing next time.
No one here is looking for micro optimizations of this kind, also Convert.ToString != object.ToString (if you test something, do it well)

String interpolation basically replace the given interpolated string with a string.Format, which uses a StringBuilder to finally construct the string so yeah, it's slower than doing a "single" call.

No sensed people would like to add this kind of micro optimization over losing maintainability on this kind of software/business logic
Especially when there are 3450435430 things that makes performances shitty on OpenNos and that a simple context switch is longer than the overhead brought by string interpolation
Blowa is online now  
Old 12/22/2019, 14:31   #5
 
Cryless~'s Avatar
 
elite*gold: 0
Join Date: Sep 2015
Posts: 480
Received Thanks: 529
Quote:
Originally Posted by val77 View Post
No one here is looking for micro optimizations of this kind, also Convert.ToString != object.ToString (if you test something, do it well)

String interpolation basically replace the given interpolated string with a string.Format, which uses a StringBuilder to finally construct the string so yeah, it's slower than doing a "single" call.
It depends on the needs you have, in some contexts even 1ms can become critical but it is also true that in that case you would most likely use different tools.

I never said that I care, indeed I said that you should prefer string interpolation because it is cleaner. But if you want to be arrogant, at least you could avoid spreading misinformation. It is not true that they are more efficient as shown.

That is all.

I have not tested Convert.ToString but most likely it does not change much. I will post the results in a few minutes to clarify.

I would also like to point out that using string interpolation or Convert.ToString makes no difference in this context. There is no concatenation so it does not complicate reading.
Cryless~ is offline  
Old 12/22/2019, 14:42   #6
 
erixor's Avatar
 
elite*gold: 0
Join Date: Jul 2013
Posts: 345
Received Thanks: 933
Quote:
Originally Posted by Cryless~ View Post
You should prefer it because it is cleaner but it is far from being more efficient.

[...]

As you can see, it is 2-3 times slower than .ToString()! I suggest you testing next time.
My bad then I messed up between string interpolation and string concatenation, which is the faster one, but it's still cleaner to use interpolation anyways... But meh, that doesn't really matter, does it ?
erixor is offline  
Thanks
1 User
Old 12/22/2019, 14:43   #7

 
Blowa's Avatar
 
elite*gold: 98
Join Date: Jan 2010
Posts: 624
Received Thanks: 1,716
Quote:
Originally Posted by Cryless~ View Post
It depends on the needs you have, in some contexts even 1ms can become critical but it is also true that in that case you would most likely use different tools.

I never said that I care, indeed I said that you should prefer string interpolation because it is cleaner. But if you want to be arrogant, at least you could avoid spreading misinformation. It is not true that they are more efficient as shown.

That is all.

I have not tested Convert.ToString but most likely it does not change much. I will post the results in a few minutes to clarify.
Actually, you are talking about nanosecond optimization, if this kind of optimization is a need on your software, you should better not take C# but Go, Rust or C++ that are statically compiled (no JIT nor runtime interpreter VM ****) and severely optimized by their compilers (-o3...).

This is about some business logic code, which, in case of OpenNos, does not require nanosecond optimizations at all.

Convert.ToString will, probably in most common cases, be optimized by compilers, but it will, in a "normal non optimized" manner, call some runtime things to be able to use the right type, which have an overhead (probably a simple cast in most case).
Blowa is online now  
Old 12/22/2019, 14:55   #8
 
Cryless~'s Avatar
 
elite*gold: 0
Join Date: Sep 2015
Posts: 480
Received Thanks: 529
Quote:
Originally Posted by val77 View Post
Actually, you are talking about nanosecond optimization, if this kind of optimization is a need on your software, you should better not take C# but Go, Rust or C++ that are statically compiled (no JIT nor runtime interpreter VM shit) and severely optimized by their compilers (-o3...).

This is about some business logic code, which, in case of OpenNos, does not require nanosecond optimizations at all.

Convert.ToString will, probably in most common cases, be optimized by compilers, but it will, in a "normal non optimized" manner, call some runtime things to be able to use the right type, which have an overhead (probably a simple cast in most case).
You are completely right but it is not the point for which I intervened. I just wanted to clarify that string interpolations are not more efficient than object.ToString() nor Convert.ToString() in reference to @'s answer.

Some people claim that string interpolations use not only string.Format but also string.Concat, however, I do not know if it is true and it does not matter to me.

For those who are curious:

Code:
% dotnet run
string interpolation = 9 ms
Convert.ToString = 5 ms
% dotnet run
string interpolation = 9 ms
Convert.ToString = 4 ms
% dotnet run
string interpolation = 9 ms
Convert.ToString = 4 ms

The code was run on an Intel Core i9-8950HK.
Cryless~ is offline  
Reply


Similar Threads Similar Threads
EU-Parlament will Diesel-Steuer um 22 Cent anheben
04/21/2012 - Off Topic - 3 Replies
Klick mich für die Quelle
"Killerspiel"-Steuer im Anmarsch
10/29/2011 - User Submitted News - 36 Replies
Spiele welche dem Konsumenten gewalttätige Inhalte liefern, sollten wie Tabak versteuert werden. Diesen Vorschlag machte nun eine Elternvertretung aus Österreich. Der Grund: Diese Spiele würden die erzierrischen Tätigkeiten bei Kindern und Jugendlichen erheblich erschweren. Egoshooter für Prävention einsetzen Die Einkünfte aus dieser Steuer sollen dann auch direkt in Präventions-Projekte an Schulen investiert werden, so Paul Haschka, stellvertretender Vorsitzender des Landesverbands der...
[Frage]3% Steuer
04/15/2010 - Metin2 Private Server - 12 Replies
So als erstes kommt nicht mit Such funktion ich hab nichts gefunden. Jetzt zur frage ist es möglich die 3% Steuer bei bestimmten Items raus zu nehmen ?



All times are GMT +1. The time now is 18:10.


Powered by vBulletin®
Copyright ©2000 - 2022, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2022 elitepvpers All Rights Reserved.