Skip to content

Loop for config

Featured Replies

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)

				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?

  • Author
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);
        }
        

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

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.