Thread: Sending correct string

Page 1 of 2 12 LastLast
Results 1 to 10 of 15
  1. #1 Sending correct string 
    Banned

    Join Date
    Oct 2012
    Posts
    4,710
    Thanks given
    1,679
    Thanks received
    1,105
    Rep Power
    0
    Thanks alot almost solved.
    Last edited by _Patrick_; 09-09-2018 at 09:26 AM.
     

  2. #2  
    Donator


    Join Date
    Aug 2012
    Posts
    2,462
    Thanks given
    312
    Thanks received
    459
    Rep Power
    457
    for(WeaponUpgrade weapon_upgrade : WeaponUpgrade.values()) {

    and

    for (int t = 0; t < 5; t++) {

    right now you are telling all the WeaponUpgrade values to do your debug 5 times. So instead of looping all the WeaponUpgrades, i'd try to pass the Value of the upgrade you need to debug instead of looping through them all to find them...


    atm your debug prints (Weaponupgrade.values() amount * 5)

    hope it helped.


    Edit:

    also

    Code:
     
    for (int t = 0; t < 5; t++) {
    				if (t >= 5) {// no next tier
    					player.send(new SendString("Maxed out", weapon_upgrade.getStringLine()));
    					break;
    				}
    				// match our current tier to possibilities
    				if (t == state) {
    					System.out.println("tier= "+tier+" / state= "+state);
    					// send state text depending on current vs required for next tier
    					String msg_to_send = current_kills < next_tier[t] ? locked : unlocked;
    					System.out.println("sending "+msg_to_send+" on line "+weapon_upgrade.getStringLine()+" depends on "+tier+" | "+current_kills+" | "+state);
    					player.send(new SendString(current_kills < next_tier[t] ? locked : unlocked, weapon_upgrade.getStringLine()));
    					
    					// send the correct item container
    					player.send(new SendItemOnInterfaceSlot(weapon_upgrade.getContainerId(), weapon_upgrade.getUpgradeItemId(), weapon_upgrade.getItemSlot()));
    					break;
    				}
    			}
    Shouldnt u just do something like (max stage)-(currentStage) > maxStep = string for maxxed else string for w.e stage its on?
     

  3. #3  
    Banned

    Join Date
    Oct 2012
    Posts
    4,710
    Thanks given
    1,679
    Thanks received
    1,105
    Rep Power
    0
    Quote Originally Posted by Guruu View Post
    for(WeaponUpgrade weapon_upgrade : WeaponUpgrade.values()) {

    and

    for (int t = 0; t < 5; t++) {

    right now you are telling all the WeaponUpgrade values to do your debug 5 times. So instead of looping all the WeaponUpgrades, i'd try to pass the Value of the upgrade you need to debug instead of looping through them all to find them...


    atm your debug prints (Weaponupgrade.values() amount * 5)

    hope it helped.
    How would you suggest i do this then? Like without the second loop.

    I legit have no idea, otherwise i wouldn't make this request thread .
     

  4. #4  
    Donator


    Join Date
    Aug 2012
    Posts
    2,462
    Thanks given
    312
    Thanks received
    459
    Rep Power
    457
    Quote Originally Posted by _Patrick_ View Post
    How would you suggest i do this then? Like without the second loop.

    I legit have no idea, otherwise i wouldn't make this request thread .
    forget what i said about passing the WeaponUpgrade. for(int t ) loop causing it. You should do what i said after my edit post. Should help i think.
     

  5. #5  
    Banned

    Join Date
    Oct 2012
    Posts
    4,710
    Thanks given
    1,679
    Thanks received
    1,105
    Rep Power
    0
    Quote Originally Posted by Guruu View Post
    for(WeaponUpgrade weapon_upgrade : WeaponUpgrade.values()) {

    Shouldnt u just do something like (max stage)-(currentStage) > maxStep = string for maxxed else string for w.e stage its on?
    Can you show me in code what you mean idk what you're trying to say. Sorry if I'm a pain in the ass.
     

  6. #6  
    Donator


    Join Date
    Aug 2012
    Posts
    2,462
    Thanks given
    312
    Thanks received
    459
    Rep Power
    457
    Quote Originally Posted by _Patrick_ View Post
    Can you show me in code what you mean idk what you're trying to say. Sorry if I'm a pain in the ass.
    Code:
    for (int t = 0; t < 5; t++) {
    				if (t >= 5) {// no next tier
    					player.send(new SendString("Maxed out", weapon_upgrade.getStringLine()));
    					break;
    				}
    				// match our current tier to possibilities
    				if (t == state) {
    					System.out.println("tier= "+tier+" / state= "+state);
    					// send state text depending on current vs required for next tier
    					String msg_to_send = current_kills < next_tier[t] ? locked : unlocked;
    					System.out.println("sending "+msg_to_send+" on line "+weapon_upgrade.getStringLine()+" depends on "+tier+" | "+current_kills+" | "+state);
    					player.send(new SendString(current_kills < next_tier[t] ? locked : unlocked, weapon_upgrade.getStringLine()));
    					
    					// send the correct item container
    					player.send(new SendItemOnInterfaceSlot(weapon_upgrade.getContainerId(), weapon_upgrade.getUpgradeItemId(), weapon_upgrade.getItemSlot()));
    					break;
    				}
    			}

    so instead of your loop i would do just put a switch to handle each current state
    if(state >= getMaxstate)
    send state sting
    else
    switch(state)
    case 0
    send state string
    case 1
    send state string

    you get me?
     

  7. #7  
    Banned

    Join Date
    Oct 2012
    Posts
    4,710
    Thanks given
    1,679
    Thanks received
    1,105
    Rep Power
    0
    Quote Originally Posted by Guruu View Post
    Code:
    for (int t = 0; t < 5; t++) {
    				if (t >= 5) {// no next tier
    					player.send(new SendString("Maxed out", weapon_upgrade.getStringLine()));
    					break;
    				}
    				// match our current tier to possibilities
    				if (t == state) {
    					System.out.println("tier= "+tier+" / state= "+state);
    					// send state text depending on current vs required for next tier
    					String msg_to_send = current_kills < next_tier[t] ? locked : unlocked;
    					System.out.println("sending "+msg_to_send+" on line "+weapon_upgrade.getStringLine()+" depends on "+tier+" | "+current_kills+" | "+state);
    					player.send(new SendString(current_kills < next_tier[t] ? locked : unlocked, weapon_upgrade.getStringLine()));
    					
    					// send the correct item container
    					player.send(new SendItemOnInterfaceSlot(weapon_upgrade.getContainerId(), weapon_upgrade.getUpgradeItemId(), weapon_upgrade.getItemSlot()));
    					break;
    				}
    			}

    so instead of your loop i would do just put a switch to handle each current state
    if(state >= getMaxstate)
    send state sting
    else
    switch(state)
    case 0
    send state string
    case 1
    send state string

    you get me?
    Did that at first no success.
     

  8. #8  
    Respected Member


    Join Date
    Jul 2015
    Posts
    781
    Thanks given
    206
    Thanks received
    394
    Rep Power
    524
    Create a tier enum like:
    Code:
    enum UpgradeTier {
    	LOCKED(0),
    	TIER_1(100),
    	TIER_2(225),
    	TIER_3(350),
    	TIER_4(475),
    	TIER_5(600);
    	
    	UpgradeTier(int killsRequired) {
    		this.killsRequired = killsRequired;
    	}
    	
    	private final int killsRequired;
    
    	public int getKillsRequired() {
    		return killsRequired;
    	}
    
    	static UpgradeTier getTierForKills(int kills) {
    		// return highest tier for current # kills
    	}
    }
    then it's as simple as this:

    Code:
    final String locked = "blah weapon %s requires %d kills blah"
    final String unlocked = "upgrade weapon %s to tier %d"
    
    for (WeaponUpgrade wep : WeaponUpgrade.values()) {
    	int currentKills = player.upgrades.computeIfAbsent(wep.getUpgradeKey(), it -> 0);
    	UpgradeTier tier = UpgradeTier.getTierForKills(currentKills);
    
    	if (tier == UpgradeTier.values()[UpgradeTier.values().length - 1]) {
    		// send maxed out or whatever, no further upgrades.
    	} else {
    		// send locked / unlocked string with # of kills for next tier to unlock
    		player.send(new SendString(String.format(tier == UpgradeTier.LOCKED ? locked : unlocked, wep.getWeaponName(), UpgradeTier.values()[tier.ordinal() + 1].getKillsRequired())));	
    	}
    	
    	// update container
    	player.send(new SendItemOnInterfaceSlot(wep.getContainerId(), wep.getUpgradeItemId(), wep.getItemSlot()));
    }
     

  9. #9  
    Banned

    Join Date
    Oct 2012
    Posts
    4,710
    Thanks given
    1,679
    Thanks received
    1,105
    Rep Power
    0
    Quote Originally Posted by Khaleesi View Post
    Create a tier enum like:
    Thanks for that, i was way overthinking also it

    But two issues:

    First when you have >= 600 kills in specific weapon it throws this error:

    Code:
    [m java.lang.ArrayIndexOutOfBoundsException: 6
    	at com.venenatis.content.upgrade.UpgradeHandler.open(UpgradeHandler.java:21) ~[bin/:?]
    	at plugin.click.npc.NpcFirstClickPlugin.firstClickNpc(NpcFirstClickPlugin.java:38) ~[bin/:?]
    	at com.venenatis.game.plugin.PluginContext.handleNpcClickEvent(PluginContext.java:332) ~[bin/:?]
    	at com.venenatis.game.plugin.PluginContext.accept(PluginContext.java:43) ~[bin/:?]
    	at com.venenatis.game.event.bus.PlayerDataBus.publish(PlayerDataBus.java:104) ~[bin/:?]
    	at com.venenatis.net.packet.in.NpcInteractionPacketListener.lambda$6(NpcInteractionPacketListener.java:113) ~[bin/:?]
    	at com.venenatis.game.world.entity.mob.movement.waypoint.WalkToWaypoint.onDestination(WalkToWaypoint.java:19) ~[bin/:?]
    	at com.venenatis.game.world.entity.mob.movement.waypoint.Waypoint.execute(Waypoint.java:64) ~[bin/:?]
    	at com.venenatis.game.task.TaskManager.schedule(TaskManager.java:54) ~[bin/:?]
    	at com.venenatis.game.world.World.schedule(World.java:228) ~[bin/:?]
    	at com.venenatis.game.world.entity.mob.Mob.walkTo(Mob.java:320) ~[bin/:?]
    	at com.venenatis.game.world.entity.mob.Mob.walkTo(Mob.java:305) ~[bin/:?]
    	at com.venenatis.net.packet.in.NpcInteractionPacketListener.lambda$2(NpcInteractionPacketListener.java:106) ~[bin/:?]
    	at java.util.Optional.ifPresent(Unknown Source) ~[?:1.8.0_131]
    	at com.venenatis.net.packet.in.NpcInteractionPacketListener.handleFirstClickNpc(NpcInteractionPacketListener.java:89) ~[bin/:?]
    	at com.venenatis.net.packet.in.NpcInteractionPacketListener.handlePacket(NpcInteractionPacketListener.java:40) ~[bin/:?]
    	at com.venenatis.net.packet.PacketRepository.lambda$0(PacketRepository.java:34) ~[bin/:?]
    	at java.util.Optional.ifPresent(Unknown Source) ~[?:1.8.0_131]
    	at com.venenatis.net.packet.PacketRepository.sendToListener(PacketRepository.java:34) ~[bin/:?]
    	at com.venenatis.net.session.GameSession.processClientPackets(GameSession.java:63) ~[bin/:?]
    	at java.util.Optional.ifPresent(Unknown Source) ~[?:1.8.0_131]
    	at com.venenatis.game.engine.GameEngine.lambda$0(GameEngine.java:71) ~[bin/:?]
    	at com.venenatis.game.world.entity.MobList.forEach(MobList.java:166) [bin/:?]
    	at com.venenatis.game.engine.GameEngine.runOneIteration(GameEngine.java:70) [bin/:?]
    	at com.google.common.util.concurrent.AbstractScheduledService$ServiceDelegate$Task.run(AbstractScheduledService.java:189) [guava-19.0.jar:?]
    	at com.google.common.util.concurrent.Callables$3.run(Callables.java:100) [guava-19.0.jar:?]
    	at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_131]
    	at java.util.concurrent.FutureTask.runAndReset(Unknown Source) [?:1.8.0_131]
    	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(Unknown Source) [?:1.8.0_131]
    	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source) [?:1.8.0_131]
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [?:1.8.0_131]
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [?:1.8.0_131]
    	at java.lang.Thread.run(Unknown Source) [?:1.8.0_131]
    Pretty sure because of the +1 ordinal, but when i remove it it fucks up the strings.

    Attached image

    And check this GIF, for certain weapons the kills required are not sent correctly:

    Attached image

    Also filled this method in like this not sure if you meant that:

    Code:
    	static UpgradeTier getTierForKills(int kills) {
    		// return highest tier for current # kills
    		switch (kills) {
    		case 100:
    			return TIER_1;
    		case 225:
    			return TIER_2;
    		case 350:
    			return TIER_3;
    		case 475:
    			return TIER_4;
    		case 600:
    			return TIER_5;
    		}
    		return LOCKED;
    	}
     

  10. #10  
    Registered Member

    Join Date
    Nov 2015
    Age
    24
    Posts
    1,980
    Thanks given
    334
    Thanks received
    1,051
    Rep Power
    5000
    Quote Originally Posted by _Patrick_ View Post
    Thanks for that, i was way overthinking also it

    But two issues:

    First when you have >= 600 kills in specific weapon it throws this error:

    Code:
    [m java.lang.ArrayIndexOutOfBoundsException: 6
    	at com.venenatis.content.upgrade.UpgradeHandler.open(UpgradeHandler.java:21) ~[bin/:?]
    	at plugin.click.npc.NpcFirstClickPlugin.firstClickNpc(NpcFirstClickPlugin.java:38) ~[bin/:?]
    	at com.venenatis.game.plugin.PluginContext.handleNpcClickEvent(PluginContext.java:332) ~[bin/:?]
    	at com.venenatis.game.plugin.PluginContext.accept(PluginContext.java:43) ~[bin/:?]
    	at com.venenatis.game.event.bus.PlayerDataBus.publish(PlayerDataBus.java:104) ~[bin/:?]
    	at com.venenatis.net.packet.in.NpcInteractionPacketListener.lambda$6(NpcInteractionPacketListener.java:113) ~[bin/:?]
    	at com.venenatis.game.world.entity.mob.movement.waypoint.WalkToWaypoint.onDestination(WalkToWaypoint.java:19) ~[bin/:?]
    	at com.venenatis.game.world.entity.mob.movement.waypoint.Waypoint.execute(Waypoint.java:64) ~[bin/:?]
    	at com.venenatis.game.task.TaskManager.schedule(TaskManager.java:54) ~[bin/:?]
    	at com.venenatis.game.world.World.schedule(World.java:228) ~[bin/:?]
    	at com.venenatis.game.world.entity.mob.Mob.walkTo(Mob.java:320) ~[bin/:?]
    	at com.venenatis.game.world.entity.mob.Mob.walkTo(Mob.java:305) ~[bin/:?]
    	at com.venenatis.net.packet.in.NpcInteractionPacketListener.lambda$2(NpcInteractionPacketListener.java:106) ~[bin/:?]
    	at java.util.Optional.ifPresent(Unknown Source) ~[?:1.8.0_131]
    	at com.venenatis.net.packet.in.NpcInteractionPacketListener.handleFirstClickNpc(NpcInteractionPacketListener.java:89) ~[bin/:?]
    	at com.venenatis.net.packet.in.NpcInteractionPacketListener.handlePacket(NpcInteractionPacketListener.java:40) ~[bin/:?]
    	at com.venenatis.net.packet.PacketRepository.lambda$0(PacketRepository.java:34) ~[bin/:?]
    	at java.util.Optional.ifPresent(Unknown Source) ~[?:1.8.0_131]
    	at com.venenatis.net.packet.PacketRepository.sendToListener(PacketRepository.java:34) ~[bin/:?]
    	at com.venenatis.net.session.GameSession.processClientPackets(GameSession.java:63) ~[bin/:?]
    	at java.util.Optional.ifPresent(Unknown Source) ~[?:1.8.0_131]
    	at com.venenatis.game.engine.GameEngine.lambda$0(GameEngine.java:71) ~[bin/:?]
    	at com.venenatis.game.world.entity.MobList.forEach(MobList.java:166) [bin/:?]
    	at com.venenatis.game.engine.GameEngine.runOneIteration(GameEngine.java:70) [bin/:?]
    	at com.google.common.util.concurrent.AbstractScheduledService$ServiceDelegate$Task.run(AbstractScheduledService.java:189) [guava-19.0.jar:?]
    	at com.google.common.util.concurrent.Callables$3.run(Callables.java:100) [guava-19.0.jar:?]
    	at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_131]
    	at java.util.concurrent.FutureTask.runAndReset(Unknown Source) [?:1.8.0_131]
    	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(Unknown Source) [?:1.8.0_131]
    	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source) [?:1.8.0_131]
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [?:1.8.0_131]
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [?:1.8.0_131]
    	at java.lang.Thread.run(Unknown Source) [?:1.8.0_131]
    Pretty sure because of the +1 ordinal, but when i remove it it fucks up the strings.

    Attached image

    And check this GIF, for certain weapons the kills required are not sent correctly:

    Attached image

    Also filled this method in like this not sure if you meant that:

    Code:
    	static UpgradeTier getTierForKills(int kills) {
    		// return highest tier for current # kills
    		switch (kills) {
    		case 100:
    			return TIER_1;
    		case 225:
    			return TIER_2;
    		case 350:
    			return TIER_3;
    		case 475:
    			return TIER_4;
    		case 600:
    			return TIER_5;
    		}
    		return LOCKED;
    	}
    do this instead of that silly method

    Code:
    private static final Map<Integer, UpgradeTier> TIERS = new HashMap<>();
    
    public static UpgradeTier get(int kills) {
             return TIERS.get(kills);
    }
    
    static {
         for (UpgradeTier tier : values()) {
             TIERS.put(tier.getKills(), tier); //add a kills variable to ur enum
         }
    }
     

Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Replies: 8
    Last Post: 08-28-2013, 11:05 PM
  2. Sending a string from server to client
    By owner blade in forum Help
    Replies: 0
    Last Post: 10-24-2010, 01:37 PM
  3. Sending a string from server to client
    By owner blade in forum Help
    Replies: 0
    Last Post: 10-24-2010, 01:16 PM
  4. Replies: 0
    Last Post: 09-20-2009, 04:50 AM
  5. Replies: 9
    Last Post: 06-10-2009, 05:44 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •