Jump to content
  • 0

Loop for config


DzStunk

Question

hello I have a doubt I'm creating a configuration to limit casting speed for each class but if the value of a class is different from the other I have the value of the last configuration.

 

I created a loop to map all configuration:

int val = (int) calcStat(Stats.MAGIC_ATTACK_SPEED, base, null, null);
		for (String className : Config.LIMIT_CASTING_SPEED.keySet())
		{
			if (Config.LIMIT_CASTING_SPEED.containsKey(_actor.getClassId().toString()) && val > Config.LIMIT_CASTING_SPEED.get(className))
				val = Config.LIMIT_CASTING_SPEED.get(className);
		}

 

 

Cardinal-1000;Arcana Lord-1300

 

let's say if the value is like this I get 1300 for all.

Fixed I used the java 17 documentation to understand a little about Maps Map (Java SE 17 & JDK 17) (oracle.com)

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0
				final Map<String, Integer> map = new HashMap<>();
				final String[] input = "Cardinal-1000;Arcana Lord-1300".split(";");
				for (String s : input) {
					final String[] split2 = s.split("-");
					map.put(split2[0], Integer.parseInt(split2[1]));
				}
                  
                // to test
				for (Entry<String, Integer> ent : map.entrySet()) {
					Announcements.announceToAll("k " + ent.getKey());
					Announcements.announceToAll("v " + ent.getValue());
				}
                  
                  // to use				
                int val = activeChar.getMAtkSpd();
				if (map.containsKey(activeChar.getClassId().getName()))
					val = Math.min(map.getOrDefault(activeChar.getClassId().getName(), activeChar.getMAtkSpd()), activeChar.getMAtkSpd());

 

image.png.502b98abbce2652a6f270da3b7e40a40.png

 

this?

Link to comment
Share on other sites

  • 0
34 minutes ago, eMommy said:
				final Map<String, Integer> map = new HashMap<>();
				final String[] input = "Cardinal-1000;Arcana Lord-1300".split(";");
				for (String s : input) {
					final String[] split2 = s.split("-");
					map.put(split2[0], Integer.parseInt(split2[1]));
				}
                  
                // to test
				for (Entry<String, Integer> ent : map.entrySet()) {
					Announcements.announceToAll("k " + ent.getKey());
					Announcements.announceToAll("v " + ent.getValue());
				}
                  
                  // to use				
                int val = activeChar.getMAtkSpd();
				if (map.containsKey(activeChar.getClassId().getName()))
					val = Math.min(map.getOrDefault(activeChar.getClassId().getName(), activeChar.getMAtkSpd()), activeChar.getMAtkSpd());

 

image.png.502b98abbce2652a6f270da3b7e40a40.png

 

this?

 

I used keySet() found it more viable

 

Screenshot_29.png.981eb51c2a292493e07130ca30ea6f5c.png

 


        for (String className : Config.LIMIT_CASTING_SPEED.keySet())
        {
            if (className.equals(_actor.getClassId().toString()))
                val = Config.LIMIT_CASTING_SPEED.get(className);
        }
        

Link to comment
Share on other sites

  • 0

I strongly recommend you to build around dynamic arrays, even a Set<> will be using quite less memory (even if that may already be insignificant), and might be excesivelly efficient on cpu-consuming tasks. A primitive ArrayOf[Object()] will be really faster and more convenient using the ClassID as the key for the value.


This kind of evaluations are sortta unnecessary
 

int val = (int) calcStat(Stats.MAGIC_ATTACK_SPEED, base, null, null);
		for (String className : Config.LIMIT_CASTING_SPEED.keySet())
		{
			if (Config.LIMIT_CASTING_SPEED.containsKey(_actor.getClassId().toString()) && val > Config.LIMIT_CASTING_SPEED.get(className))
				val = Config.LIMIT_CASTING_SPEED.get(className);
		}

 

Have in mind that, FOR EACH String inside your Config, the loop will be doing X function in order to find the requested value, repeating this for every Class that is requested to acquire the desired value.

Meanwhile, a simple Array[Int[]] will be faster and much more efficient:

Int[][] class_castSpd_value;

int val = class_castSpd_value[classId];

 

Edited by Bellion_Epica
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock