Thread: Help with Ruse

Page 1 of 3 123 LastLast
Results 1 to 10 of 21
  1. #1 Help with Ruse 
    Registered Member
    Join Date
    Jun 2016
    Posts
    52
    Thanks given
    5
    Thanks received
    0
    Rep Power
    11
    So recently i added a new achievement to my list of achievements in my sidetab interface.
    Well after adding the achievement I get
    Code:
    java.lang.ArrayIndexOutOfBoundsException: 89
    	at content.Achievements.updateInterface(Achievements.java:202)
    	at world.entity.impl.player.PlayerHandler.handleLogin(PlayerHandler.java:129)
    	at World.sequence(World.java:121)
    	at GameEngine.run(GameEngine.java:28)
    Ive narrowed the problem down to it only throwing the error when existing accounts that were saved before the achievement was added throw the error.
    New accounts aren't affected by it.


    Fixed : Thanks to Stevenhax


    Code:
      if (reader.has("achievements-completion")) {
                	boolean[] loadedCompletion = builder.fromJson(reader.get("achievements-completion").getAsJsonArray(), boolean[].class);
                    int defaultLength = player.getAchievementAttributes().getCompletion().length;
                    if(loadedCompletion.length < defaultLength){
    
                    	for(int index = 0; index < defaultLength-1; index++){
                    		if(index < loadedCompletion.length){
                    			player.getAchievementAttributes().setCompletion(index, loadedCompletion[index]);
                    		} else {
                    			player.getAchievementAttributes().setCompletion(index, false);
                    		}
                    	}               	
                    } else {
                    	player.getAchievementAttributes().setCompletion(loadedCompletion);
                    }
                }
    Reply With Quote  
     

  2. #2  
    Donator


    Join Date
    Jul 2011
    Posts
    570
    Thanks given
    135
    Thanks received
    142
    Rep Power
    291
    Quote Originally Posted by ItsR34 View Post
    So recently i added a new achievement to my list of achievements in my sidetab interface.
    Well after adding the achievement I get
    Code:
    java.lang.ArrayIndexOutOfBoundsException: 89
    	at content.Achievements.updateInterface(Achievements.java:202)
    	at world.entity.impl.player.PlayerHandler.handleLogin(PlayerHandler.java:129)
    	at World.sequence(World.java:121)
    	at GameEngine.run(GameEngine.java:28)
    Ive narrowed the problem down to it only throwing the error when existing accounts that were saved before the achievement was added throw the error.
    New accounts aren't affected by it.
    What's on line 129 in the playerhandler class.
    PlayerHandler.java:129
    Reply With Quote  
     

  3. #3  
    Registered Member
    Join Date
    Jun 2016
    Posts
    52
    Thanks given
    5
    Thanks received
    0
    Rep Power
    11
    Quote Originally Posted by Empathy View Post
    What's on line 129 in the playerhandler class.
    PlayerHandler.java:129
    Code:
    Achievements.updateInterface(player);
    following the declaration

    Code:
     public static void updateInterface(Player player) {
    		for(AchievementData achievement : AchievementData.values()) {
    			boolean completed = player.getAchievementAttributes().getCompletion()[achievement.ordinal()];
    			boolean progress = achievement.progressData != null && player.getAchievementAttributes().getProgress()[achievement.progressData[0]] > 0;
    			player.getPacketSender().sendString(achievement.interfaceFrame, (completed ? "@gre@" : progress ? "@yel@" : "@red@") + achievement.interfaceLine);
    		}
    		player.getPacketSender().sendString(37001, "Achievements: "+player.getPointsHandler().getAchievementPoints()+"/"+AchievementData.values().length);
    	}
    Reply With Quote  
     

  4. #4  
    Donator


    Join Date
    Jul 2011
    Posts
    570
    Thanks given
    135
    Thanks received
    142
    Rep Power
    291
    Quote Originally Posted by ItsR34 View Post
    Code:
    Achievements.updateInterface(player);
    following the declaration

    Code:
     public static void updateInterface(Player player) {
    		for(AchievementData achievement : AchievementData.values()) {
    			boolean completed = player.getAchievementAttributes().getCompletion()[achievement.ordinal()];
    			boolean progress = achievement.progressData != null && player.getAchievementAttributes().getProgress()[achievement.progressData[0]] > 0;
    			player.getPacketSender().sendString(achievement.interfaceFrame, (completed ? "@gre@" : progress ? "@yel@" : "@red@") + achievement.interfaceLine);
    		}
    		player.getPacketSender().sendString(37001, "Achievements: "+player.getPointsHandler().getAchievementPoints()+"/"+AchievementData.values().length);
    	}
    Because you added a new achievement, player.getAchievementAttributes().getCompletion()[achievement.ordinal()]; is gonna return indexoutofboundsexception for existing players for that achievement, which I assume is the 89th/90th achievement you have. What you need to do is run a script that adds the achievement for all existing players as not completed.
    Reply With Quote  
     

  5. #5  
    Registered Member
    Join Date
    Jun 2016
    Posts
    52
    Thanks given
    5
    Thanks received
    0
    Rep Power
    11
    Quote Originally Posted by Empathy View Post
    Because you added a new achievement, player.getAchievementAttributes().getCompletion()[achievement.ordinal()]; is gonna return indexoutofboundsexception for existing players for that achievement, which I assume is the 89th/90th achievement you have. What you need to do is run a script that adds the achievement for all existing players as not completed.
    i believe it would be the 90th achieve im adding , how would i go about that?

    still needing some help , i looked around and tried a few things but im still stuck
    Code:
    public class PlayerSaving {
    	
    	public static void save(Player player) {
    		if(player.newPlayer()) {
    			return;
    		}
    		Path path = Paths.get("./data/saves/characters/", player.getUsername() + ".json");
    		File file = path.toFile();
    		file.getParentFile().setWritable(true);
    		
    		// Attempt to make the player save directory if it doesn't
    		// exist.
    		if (!file.getParentFile().exists()) {
    			try {
    				JsonObject jobj = new JsonObject();
    				jobj.add("false", new Gson().toJsonTree(player.getAchievementAttributes().getCompletion()));
    				jobj.add("0", new Gson().toJsonTree(player.getAchievementAttributes().getProgress()));
    				file.getParentFile().mkdirs();
    			} catch (SecurityException e) {
    				System.out.println("Unable to create directory for player data!");
    			}
    		}
    		try (FileWriter writer = new FileWriter(file)) {
    			
    			Gson builder = new GsonBuilder().setPrettyPrinting().create();
    			JsonObject object = new JsonObject();
    			object.addProperty("total-play-time-ms", player.getTotalPlayTime());
    			object.addProperty("username", player.getUsername().trim());
    			object.addProperty("password", player.getPassword().trim());
    			object.addProperty("email", player.getEmailAddress() == null ? "null" : player.getEmailAddress().trim());
    			object.addProperty("staff-rights", player.getRights().name());
    			object.addProperty("yell-title", player.getYellTitle() == null ? "null" : player.getYellTitle().trim());
    			object.addProperty("game-mode", player.getGameMode().name());
    			object.addProperty("loyalty-title", player.getLoyaltyTitle().name());
    			object.add("position", builder.toJsonTree(player.getPosition()));
    			object.addProperty("online-status", player.getRelations().getStatus().name());
    			object.addProperty("given-starter", new Boolean(player.didReceiveStarter()));
    			object.addProperty("given-darts", new Boolean(player.didReceiveDarts()));
    			object.addProperty("money-pouch", new Long(player.getMoneyInPouch()));
    			object.addProperty("donated", new Long(player.getAmountDonated()));
    			object.addProperty("ironman-points", new Long(player.getPointsHandler().getIronManPoints()));
    			object.addProperty("minutes-bonus-exp", new Integer(player.getMinutesBonusExp()));
    			object.addProperty("total-gained-exp", new Long(player.getSkillManager().getTotalGainedExp()));
    			object.addProperty("dung-prestige", (player.getPrestigeMultiplier()));
    			object.addProperty("dung-runs", (player.getDungRuns()));
    			object.addProperty("maxPrestige", player.isMaxPrestige());
    			object.addProperty("boss-points", new Integer(player.getBossPoints()));
    			object.addProperty("skill-points", player.getPointsHandler().getSkillPoints());
    			object.addProperty("prestige-points", new Integer(player.getPointsHandler().getPrestigePoints()));
    			object.addProperty("achievement-points", new Integer(player.getPointsHandler().getAchievementPoints()));
    			object.addProperty("dung-tokens", new Integer(player.getPointsHandler().getDungeoneeringTokens()));
    			object.addProperty("donator-points", new Integer(player.getPointsHandler().getDonatorPoints()));
    			object.addProperty("commendations", new Integer(player.getPointsHandler().getCommendations()));
    			object.addProperty("loyalty-points", new Integer(player.getPointsHandler().getLoyaltyPoints()));
    			object.addProperty("total-loyalty-points", new Double(player.getAchievementAttributes().getTotalLoyaltyPointsEarned()));
    			object.addProperty("voting-points", new Integer(player.getPointsHandler().getVotingPoints()));
    			object.addProperty("slayer-points", new Integer(player.getPointsHandler().getSlayerPoints()));
    			object.addProperty("pk-points", new Integer(player.getPointsHandler().getPkPoints()));
    			object.addProperty("trivia-points", new Integer(player.getPointsHandler().getTriviaPoints()));
    			object.addProperty("refeer-friend", new Integer(player.getPointsHandler().getRefeerFriendPoints()));
    			object.addProperty("refered-friend", new Boolean(player.isReferedAFriend()));
    			object.addProperty("player-kills", new Integer(player.getPlayerKillingAttributes().getPlayerKills()));
    			object.addProperty("player-killstreak", new Integer(player.getPlayerKillingAttributes().getPlayerKillStreak()));
    			object.addProperty("player-deaths", new Integer(player.getPlayerKillingAttributes().getPlayerDeaths()));
    			object.addProperty("target-percentage", new Integer(player.getPlayerKillingAttributes().getTargetPercentage()));
    			object.addProperty("bh-rank", new Integer(player.getAppearance().getBountyHunterSkull()));
    			object.addProperty("gender", player.getAppearance().getGender().name());
    			object.addProperty("shop-updated", new Boolean(player.isShopUpdated()));
    			object.addProperty("shop-earnings", new Long(player.getPlayerOwnedShopManager().getEarnings()));
    			object.addProperty("spell-book", player.getSpellbook().name());
    			object.addProperty("prayer-book", player.getPrayerbook().name());
    			object.addProperty("running", new Boolean(player.isRunning()));
    			object.addProperty("run-energy", new Integer(player.getRunEnergy()));
    			object.addProperty("music", new Boolean(player.musicActive()));
    			object.addProperty("sounds", new Boolean(player.soundsActive()));
    			object.addProperty("auto-retaliate", new Boolean(player.isAutoRetaliate()));
    			object.addProperty("xp-locked", new Boolean(player.experienceLocked()));
    			object.addProperty("veng-cast", new Boolean(player.hasVengeance()));
    			object.addProperty("last-veng", new Long(player.getLastVengeance().elapsed()));
    			object.addProperty("fight-type", player.getFightType().name());
    			object.addProperty("sol-effect", new Integer(player.getStaffOfLightEffect()));
    			object.addProperty("skull-timer", new Integer(player.getSkullTimer()));
    			object.addProperty("accept-aid", new Boolean(player.isAcceptAid()));
    			object.addProperty("poison-damage", new Integer(player.getPoisonDamage()));
    			object.addProperty("poison-immunity", new Integer(player.getPoisonImmunity()));
    			object.addProperty("overload-timer", new Integer(player.getOverloadPotionTimer()));
    			object.addProperty("fire-immunity", new Integer(player.getFireImmunity()));
    			object.addProperty("fire-damage-mod", new Integer(player.getFireDamageModifier()));
    			object.addProperty("prayer-renewal-timer", new Integer(player.getPrayerRenewalPotionTimer()));
    			object.addProperty("teleblock-timer", new Integer(player.getTeleblockTimer()));
    			object.addProperty("special-amount", new Integer(player.getSpecialPercentage()));
    			object.addProperty("entered-gwd-room", new Boolean(player.getMinigameAttributes().getGodwarsDungeonAttributes().hasEnteredRoom()));
    			object.addProperty("gwd-altar-delay", new Long(player.getMinigameAttributes().getGodwarsDungeonAttributes().getAltarDelay()));
    			object.add("gwd-killcount", builder.toJsonTree(player.getMinigameAttributes().getGodwarsDungeonAttributes().getKillcount()));
    			object.addProperty("effigy", new Integer(player.getEffigy()));
    			object.addProperty("summon-npc", new Integer(player.getSummoning().getFamiliar() != null ? player.getSummoning().getFamiliar().getSummonNpc().getId() : -1));
    			object.addProperty("summon-death", new Integer(player.getSummoning().getFamiliar() != null ? player.getSummoning().getFamiliar().getDeathTimer() : -1));
    			object.addProperty("process-farming", new Boolean(player.shouldProcessFarming()));
    			object.addProperty("clanchat", player.getClanChatName() == null ? "null" : player.getClanChatName().trim());
    			object.addProperty("autocast", new Boolean(player.isAutocast()));
    			object.addProperty("autocast-spell", player.getAutocastSpell() != null ? player.getAutocastSpell().spellId() : -1);
    			object.addProperty("dfs-charges", player.getDfsCharges());
    			object.addProperty("coins-gambled", new Integer(player.getAchievementAttributes().getCoinsGambled()));
    			object.addProperty("slayer-master", player.getSlayer().getSlayerMaster().name());
    			object.addProperty("slayer-task", player.getSlayer().getSlayerTask().name());
    			object.addProperty("prev-slayer-task", player.getSlayer().getLastTask().name());
    			object.addProperty("task-amount", player.getSlayer().getAmountToSlay());
    			object.addProperty("task-streak", player.getSlayer().getTaskStreak());
    			object.addProperty("duo-partner", player.getSlayer().getDuoPartner() == null ? "null" : player.getSlayer().getDuoPartner());
    			object.addProperty("double-slay-xp", player.getSlayer().doubleSlayerXP);
    			object.addProperty("recoil-deg", new Integer(player.getRecoilCharges()));
    			object.add("brawler-deg", builder.toJsonTree(player.getBrawlerChargers()));
    			object.add("killed-players", builder.toJsonTree(player.getPlayerKillingAttributes().getKilledPlayers()));
    			object.add("killed-gods", builder.toJsonTree(player.getAchievementAttributes().getGodsKilled()));
    			object.add("barrows-brother", builder.toJsonTree(player.getMinigameAttributes().getBarrowsMinigameAttributes().getBarrowsData()));
    			object.addProperty("random-coffin", new Integer(player.getMinigameAttributes().getBarrowsMinigameAttributes().getRandomCoffin()));
    			object.addProperty("barrows-killcount", new Integer(player.getMinigameAttributes().getBarrowsMinigameAttributes().getKillcount()));
    			object.add("nomad", builder.toJsonTree(player.getMinigameAttributes().getNomadAttributes().getQuestParts()));
    			object.add("recipe-for-disaster", builder.toJsonTree(player.getMinigameAttributes().getRecipeForDisasterAttributes().getQuestParts()));
    			object.addProperty("recipe-for-disaster-wave", new Integer(player.getMinigameAttributes().getRecipeForDisasterAttributes().getWavesCompleted()));
    			object.add("dung-items-bound", builder.toJsonTree(player.getMinigameAttributes().getDungeoneeringAttributes().getBoundItems()));
    			object.addProperty("rune-ess", new Integer(player.getStoredRuneEssence()));
    			object.addProperty("pure-ess", new Integer(player.getStoredPureEssence()));
    			object.addProperty("has-bank-pin", new Boolean(player.getBankPinAttributes().hasBankPin()));
    			object.addProperty("last-pin-attempt", new Long(player.getBankPinAttributes().getLastAttempt()));
    			object.addProperty("invalid-pin-attempts", new Integer(player.getBankPinAttributes().getInvalidAttempts()));
    			object.add("bank-pin", builder.toJsonTree(player.getBankPinAttributes().getBankPin()));
    			object.add("appearance", builder.toJsonTree(player.getAppearance().getLook()));
    			object.add("agility-obj", builder.toJsonTree(player.getCrossedObstacles()));
    			object.add("skills", builder.toJsonTree(player.getSkillManager().getSkills()));
    			object.add("inventory", builder.toJsonTree(player.getInventory().getItems()));
    			object.add("equipment", builder.toJsonTree(player.getEquipment().getItems()));			
    			object.add("bank-0", builder.toJsonTree(player.getBank(0).getValidItems()));
    			object.add("bank-1", builder.toJsonTree(player.getBank(1).getValidItems()));
    			object.add("bank-2", builder.toJsonTree(player.getBank(2).getValidItems()));
    			object.add("bank-3", builder.toJsonTree(player.getBank(3).getValidItems()));
    			object.add("bank-4", builder.toJsonTree(player.getBank(4).getValidItems()));
    			object.add("bank-5", builder.toJsonTree(player.getBank(5).getValidItems()));
    			object.add("bank-6", builder.toJsonTree(player.getBank(6).getValidItems()));
    			object.add("bank-7", builder.toJsonTree(player.getBank(7).getValidItems()));
    			object.add("bank-8", builder.toJsonTree(player.getBank(8).getValidItems()));
    			object.add("ge-slots", builder.toJsonTree(player.getGrandExchangeSlots()));
    			if(player.getSummoning().getBeastOfBurden() != null) {
    				object.add("store", builder.toJsonTree(player.getSummoning().getBeastOfBurden().getValidItems()));
    			}
    			object.add("charm-imp", builder.toJsonTree(player.getSummoning().getCharmImpConfigs()));
    			object.add("friends", builder.toJsonTree(player.getRelations().getFriendList().toArray()));
    			object.add("ignores", builder.toJsonTree(player.getRelations().getIgnoreList().toArray()));
    			object.add("loyalty-titles", builder.toJsonTree(player.getUnlockedLoyaltyTitles()));
    			object.add("kills", builder.toJsonTree(player.getKillsTracker().toArray()));
    			object.add("drops", builder.toJsonTree(player.getDropLog().toArray()));
    			object.add("achievements-completion", builder.toJsonTree(player.getAchievementAttributes().getCompletion()));
    			object.add("achievements-progress", builder.toJsonTree(player.getAchievementAttributes().getProgress()));
    			object.addProperty("is-veteran", new Boolean(player.veteran));
    			object.addProperty("scroll-effect", new Boolean(player.scrollEffect));
    			object.addProperty("blowpipe-charges", new Integer(player.getBlowPipeCharges()));
    			object.addProperty("sod-charges", new Integer(player.getStaffOfDeadCharges()));
    			object.addProperty("serpentine-charges", new Integer(player.getSerpentineHelmCharges()));
    			object.addProperty("blowpipe-darts", new Integer(player.getBlowPipeDarts()));
    			object.addProperty("blowpipe-dart-type", new Integer(player.getBlowPipeDartType()));
    			object.add("giant-pouch", builder.toJsonTree(player.getGiantPouch().toArray()));
    			object.add("coal-bag", builder.toJsonTree(player.getCoalBag().toArray()));
    			object.add("gem-bag", builder.toJsonTree(player.getGemBag().toArray()));
    			object.add("gem-bag-upgrade", builder.toJsonTree(player.getGemBagUpgrade().toArray()));
    			JsonObject clues = new JsonObject();
    			ClueScroll[] clueData = player.getClueScrolls();
    			String[] names = new String[] {"easy", "medium", "hard", "elite"};
    			for(int i = 0; i < 4; i++) {
    				JsonObject clue = new JsonObject();
    				if(clueData[i] != null) {
    					clue.addProperty("type", clueData[i].getType().name());
    					clue.addProperty("index", clueData[i].getIndexName());
    					clue.addProperty("remaining", clueData[i].getRemainingClues());
    					if(clueData[i].getType() == ClueTypes.EMOTE)
    						if(ClueConstants.Emotes.values()[clueData[i].getIndex()].isDoubleAgent())
    							clue.addProperty("agent-dead", clueData[i].isDoubleAgentDead());
    
    					clues.add(names[i], clue);
    				} else {
    					clues.add(names[i], null);
    				}
    			}
    			object.add("clue-scrolls", clues);
    			writer.write(builder.toJson(object));
    			writer.close();
    		} catch (Exception e) {
    			GameServer.getLogger().log(Level.WARNING,
    					"An error has occured while saving a character file!", e);
    		}
    		try {
    			
    			File file2 = new File("./data/saves/construction/"+player.getUsername() + ".obj");
    			
    			if(!file2.exists()) {
    				file2.createNewFile();
    			}
    			
    			FileOutputStream fileOut = new FileOutputStream(file2);
    			ConstructionSave save = new ConstructionSave();
    			save.supply(player);
    			ObjectOutputStream out = new ObjectOutputStream(fileOut);
    			out.writeObject(save);
    			out.close();
    			fileOut.close();
    			
    		} catch(Throwable t) {
    			t.printStackTrace();
    		}
    	}
    
    	public static boolean playerExists(String p) {
    		p = Misc.formatPlayerName(p.toLowerCase());
    		return new File("./data/saves/characters/"+p+".json").exists();
    	}
    }
    bump
    Reply With Quote  
     

  6. #6  
    Registered Member Versatile's Avatar
    Join Date
    Dec 2014
    Age
    26
    Posts
    433
    Thanks given
    247
    Thanks received
    9
    Rep Power
    9
    Quote Originally Posted by Empathy View Post
    Because you added a new achievement, player.getAchievementAttributes().getCompletion()[achievement.ordinal()]; is gonna return indexoutofboundsexception for existing players for that achievement, which I assume is the 89th/90th achievement you have. What you need to do is run a script that adds the achievement for all existing players as not completed.
    How would you get the server to load a new progress when once you've added a new achievement? I'm wondering this too.
    Spoiler for Don't be a deadfool:
    Reply With Quote  
     

  7. #7  
    Donator


    Join Date
    Jul 2011
    Posts
    570
    Thanks given
    135
    Thanks received
    142
    Rep Power
    291
    Quote Originally Posted by Versatile View Post
    How would you get the server to load a new progress when once you've added a new achievement? I'm wondering this too.
    I'm going to be straight, I'm not too sure how it is written on Ruse. I am highly surprised that this would be the case, but based off the OP, Ruse creates an array of all the achievements and stores it in an object defined in the player class. I personally would not do this because every time you add a new achievement, you would need to update all the players.

    Instead what I would do is store in the player object only the completed ordinal and in progress ordinals. As far as I can tell Ruse stores true/false booleans for all achievements. So when you loop through achievement data youll will get an exception, since there is no true or false for the new achievement.

    Here's a quick example, may not be entirely correct but you get the idea:

    Code:
    public static void updateInterface(Player player) {
    		outerloop: 
    		for (AchievementData achievement : AchievementData.values()) {
    			for (int i : player.getAchievementAttributes().getCompletion()) {// need to change this array from what Ruse currently does to hold the completed ordinals instead
    				if (i == achievement.ordinal()) {
    					player.getPacketSender().sendString(achievement.interfaceFrame, ("@gre@") + achievement.interfaceLine);
    					continue outerloop;
    				}
    			}
    			for (int i : player.getAchievementAttributes().getProgress()) {//same deal change this to hold the ordinals
    				if (i == achievement.ordinal()) {
    					player.getPacketSender().sendString(achievement.interfaceFrame, ("@yel@") + achievement.interfaceLine);
    					continue outerloop;
    				}
    			}
    			player.getPacketSender().sendString(achievement.interfaceFrame, ("@red@") + achievement.interfaceLine);
    		}
    
    		player.getPacketSender().sendString(37001, "Achievements: "+player.getPointsHandler().getAchievementPoints()+"/"+AchievementData.values().length);
    	}
    Reply With Quote  
     

  8. #8  
    Registered Member
    Join Date
    Jun 2016
    Posts
    52
    Thanks given
    5
    Thanks received
    0
    Rep Power
    11
    Quote Originally Posted by Empathy View Post
    I'm going to be straight, I'm not too sure how it is written on Ruse. I am highly surprised that this would be the case, but based off the OP, Ruse creates an array of all the achievements and stores it in an object defined in the player class. I personally would not do this because every time you add a new achievement, you would need to update all the players.

    Instead what I would do is store in the player object only the completed ordinal and in progress ordinals. As far as I can tell Ruse stores true/false booleans for all achievements. So when you loop through achievement data youll will get an exception, since there is no true or false for the new achievement.

    Here's a quick example, may not be entirely correct but you get the idea:

    Code:
    public static void updateInterface(Player player) {
    		outerloop: 
    		for (AchievementData achievement : AchievementData.values()) {
    			for (int i : player.getAchievementAttributes().getCompletion()) {// need to change this array from what Ruse currently does to hold the completed ordinals instead
    				if (i == achievement.ordinal()) {
    					player.getPacketSender().sendString(achievement.interfaceFrame, ("@gre@") + achievement.interfaceLine);
    					continue outerloop;
    				}
    			}
    			for (int i : player.getAchievementAttributes().getProgress()) {//same deal change this to hold the ordinals
    				if (i == achievement.ordinal()) {
    					player.getPacketSender().sendString(achievement.interfaceFrame, ("@yel@") + achievement.interfaceLine);
    					continue outerloop;
    				}
    			}
    			player.getPacketSender().sendString(achievement.interfaceFrame, ("@red@") + achievement.interfaceLine);
    		}
    
    		player.getPacketSender().sendString(37001, "Achievements: "+player.getPointsHandler().getAchievementPoints()+"/"+AchievementData.values().length);
    	}
    Code:
    public class Achievements {
    
    	
    	
    	
    	public enum AchievementData {
    		
    		//KILL_A_MONSTER_USING_MELEE(Difficulty.EASY, /*difficulty*/
    		//		"Kill a monster (melee)",/*interface line*/
    		//		"Kill any npc using a melee weapon.", /*description*/
    		//		"Armour and a sword.",/*requirements*/
    		//		"1 Achievement point",/*rewards*/
    		//		58402, null),/*stringid*/
    		//KILL_A_MONSTER_USING_RANGED(Difficulty.EASY, /*difficulty*/
    		//		"Kill a monster (ranged)",/*interface line*/
    		//		"Kill any npc using a ranged weapon.", /*description*/
    		//		"any ranged weapon and armour.",/*requirements*/
    		//		"1 Achievement point",/*rewards*/
    		//		58403, null),
    		//KILL_A_MONSTER_USING_MAGIC(Difficulty.EASY, /*difficulty*/
    		//		"Kill a monster (magic)",/*interface line*/
    		//		"Kill any npc using a magic spell.", /*description*/
    		//		"Magic armour, a staff and runes.",/*requirements*/
    		//		"1 Achievement point",/*rewards*/
    		//		58404, null),
    		//;
    
    		/*AchievementData(Difficulty difficulty, String interfaceLine, String description , String requirements, String rewards ,int interfaceFrame, int[] progressData) {
    			this.difficulty = difficulty;
    			this.interfaceLine = interfaceLine;
    			this.interfaceFrame = interfaceFrame;
    			this.progressData = progressData;
    			this.description = description;
    			this.requirements = requirements;
    			this.rewards = rewards;
    		}
    
    		private Difficulty difficulty;
    		private String interfaceLine;
    		private String description;
    		private String requirements;
    		private String rewards;
    		private int interfaceFrame;
    		private int[] progressData;*/
    
    		ENTER_THE_LOTTERY(Difficulty.EASY, "Enter The Lottery", 37005, null),
    		FILL_WELL_OF_GOODWILL_1M(Difficulty.EASY, "Pour 1M Into The Well", 37006, null),
    		CUT_AN_OAK_TREE(Difficulty.EASY, "Cut An Oak Tree", 37007, null),
    		BURN_AN_OAK_LOG(Difficulty.EASY, "Burn An Oak Log", 37008, null),
    		FISH_A_SALMON(Difficulty.EASY, "Fish A Salmon", 37009, null),
    		COOK_A_SALMON(Difficulty.EASY, "Cook A Salmon", 37010, null),
    		EAT_A_SALMON(Difficulty.EASY, "Eat A Salmon", 37011, null),
    		MINE_SOME_IRON(Difficulty.EASY, "Mine Some Iron", 37012, null),
    		SMELT_AN_IRON_BAR(Difficulty.EASY, "Smelt An Iron Bar", 37013, null),
    		HARVEST_A_CROP(Difficulty.EASY, "Harvest A Crop", 37014, null),
    		CATCH_A_YOUNG_IMPLING(Difficulty.EASY, "Catch A Young Impling", 37015, null),
    		CRAFT_A_PAIR_OF_LEATHER_BOOTS(Difficulty.EASY, "Craft A Pair of Leather Boots", 37016, null),
    		CLIMB_AN_AGILITY_OBSTACLE(Difficulty.EASY, "Climb An Agility Obstacle", 37017, null),
    		FLETCH_SOME_ARROWS(Difficulty.EASY, "Fletch Some headless arrows", 37018, null),
    		STEAL_A_RING(Difficulty.EASY, "Steal A Ring", 37019, null),
    		MIX_A_POTION(Difficulty.EASY, "Mix A Potion", 37020, null),
    		RUNECRAFT_SOME_RUNES(Difficulty.EASY, "Runecraft Some Runes", 37021, null),
    		BURY_A_BIG_BONE(Difficulty.EASY, "Bury A Big Bone", 37022, null),
    		COMPLETE_A_SLAYER_TASK(Difficulty.EASY, "Complete A Slayer Task", 37023, null),
    		KILL_A_MONSTER_USING_MELEE(Difficulty.EASY, "Kill a Monster Using Melee", 37024, null),
    		KILL_A_MONSTER_USING_RANGED(Difficulty.EASY, "Kill a Monster Using Ranged", 37025, null),
    		KILL_A_MONSTER_USING_MAGIC(Difficulty.EASY, "Kill a Monster Using Magic", 37026, null),
    		DEAL_EASY_DAMAGE_USING_MELEE(Difficulty.EASY, "Deal 1000 Melee Damage", 37027, new int[]{0, 1000}),
    		DEAL_EASY_DAMAGE_USING_RANGED(Difficulty.EASY, "Deal 1000 Ranged Damage", 37028, new int[]{1, 1000}),
    		DEAL_EASY_DAMAGE_USING_MAGIC(Difficulty.EASY, "Deal 1000 Magic Damage", 37029, new int[]{2, 1000}),
    		PERFORM_A_SPECIAL_ATTACK(Difficulty.EASY, "Perform a Special Attack", 37030, null),
    		FIGHT_ANOTHER_PLAYER(Difficulty.EASY, "Fight Another Player", 37031, null),
    
    		FILL_WELL_OF_GOODWILL_50M(Difficulty.MEDIUM, "Pour 50M Into The Well", 37038, new int[]{4, 50000000}),
    		CUT_100_MAGIC_LOGS(Difficulty.MEDIUM, "Cut 100 Magic Logs", 37039, new int[]{5, 100}),
    		BURN_100_MAGIC_LOGS(Difficulty.MEDIUM, "Burn 100 Magic Logs", 37040, new int[]{6, 100}),
    		FISH_25_ROCKTAILS(Difficulty.MEDIUM, "Fish 25 Rocktails", 37041, new int[]{7, 25}),
    		COOK_25_ROCKTAILS(Difficulty.MEDIUM, "Cook 25 Rocktails", 37042, new int[]{8, 25}),
    		MINE_25_RUNITE_ORES(Difficulty.MEDIUM, "Mine 25 Runite Ores", 37043, new int[]{9, 25}),
    		SMELT_25_RUNE_BARS(Difficulty.MEDIUM, "Smelt 25 Rune Bars", 37044, new int[]{10, 25}),
    		HARVEST_10_TORSTOLS(Difficulty.MEDIUM, "Harvest 10 Torstols", 37045, new int[]{11, 10}),
    		INFUSE_25_TITAN_POUCHES(Difficulty.MEDIUM, "Infuse 25 Steel Titans", 37046, new int[]{12, 25}),
    		COMPLETE_A_HARD_SLAYER_TASK(Difficulty.MEDIUM, "Complete A Hard Slayer Task", 37047, null),
    		CRAFT_20_BLACK_DHIDE_BODIES(Difficulty.MEDIUM, "Craft 20 Black D'hide Bodies", 37048, new int[]{14, 20}),
    		FLETCH_450_RUNE_ARROWS(Difficulty.MEDIUM, "Fletch 450 Rune Arrows", 37049, new int[]{15, 450}),
    		STEAL_140_SCIMITARS(Difficulty.MEDIUM, "Steal 140 Scimitars", 37050, new int[]{16, 140}),
    		MIX_AN_OVERLOAD_POTION(Difficulty.MEDIUM, "Mix An Overload Potion", 37051, null),
    		ASSEMBLE_A_GODSWORD(Difficulty.MEDIUM, "Assemble A Godsword", 37052, null),
    		CLIMB_50_AGILITY_OBSTACLES(Difficulty.MEDIUM, "Climb 50 Agility Obstacles", 37053, new int[]{17, 50}),
    		RUNECRAFT_500_BLOOD_RUNES(Difficulty.MEDIUM, "Runecraft 500 Blood Runes", 37054, new int[]{18, 500}),
    		BURY_25_FROST_DRAGON_BONES(Difficulty.MEDIUM, "Bury 25 Frost Dragon Bones", 37055, new int[]****, 25}),
    		DEAL_MEDIUM_DAMAGE_USING_MELEE(Difficulty.MEDIUM, "Deal 100K Melee Damage", 37056, new int[]{21, 100000}),
    		DEAL_MEDIUM_DAMAGE_USING_RANGED(Difficulty.MEDIUM, "Deal 100K Ranged Damage", 37057, new int[]{22, 100000}),
    		DEAL_MEDIUM_DAMAGE_USING_MAGIC(Difficulty.MEDIUM, "Deal 100K Magic Damage", 37058, new int[]{23, 100000}),
    		DEFEAT_THE_KING_BLACK_DRAGON(Difficulty.MEDIUM, "Defeat The King Black Dragon", 37059, null),
    		DEFEAT_THE_CHAOS_ELEMENTAL(Difficulty.MEDIUM, "Defeat The Chaos Elemental", 37060, null),
    		DEFEAT_A_TORMENTED_DEMON(Difficulty.MEDIUM, "Defeat A Tormented Demon", 37061, null),
    		DEFEAT_THE_CULINAROMANCER(Difficulty.MEDIUM, "Defeat The Culinaromancer", 37062, null),
    		DEFEAT_NOMAD(Difficulty.MEDIUM, "Defeat Nomad", 37063, null),
    		
    		FILL_WELL_OF_GOODWILL_250M(Difficulty.HARD, "Pour 250M Into The Well", 37070, new int[]{25, 250000000}),
    		CUT_5000_MAGIC_LOGS(Difficulty.HARD, "Cut 5000 Magic Logs", 37071, new int[]{26, 5000}),
    		BURN_2500_MAGIC_LOGS(Difficulty.HARD, "Burn 2500 Magic Logs", 37072, new int[]{27, 2500}),
    		FISH_2000_ROCKTAILS(Difficulty.HARD, "Fish 2000 Rocktails", 37073, new int[]{28, 2000}),
    		COOK_1000_ROCKTAILS(Difficulty.HARD, "Cook 1000 Rocktails", 37074, new int[]{29, 1000}),
    		MINE_2000_RUNITE_ORES(Difficulty.HARD, "Mine 2000 Runite Ores", 37075, new int[]{30, 2000}),
    		SMELT_1000_RUNE_BARS(Difficulty.HARD, "Smelt 1000 Rune Bars", 37076, new int[]{31, 1000}),
    		HARVEST_1000_TORSTOLS(Difficulty.HARD, "Harvest 1000 Torstols", 37077, new int[]{32, 1000}),
    		INFUSE_500_STEEL_TITAN_POUCHES(Difficulty.HARD, "Infuse 500 Steel Titans", 37078, new int[]{33, 500}),
    		CRAFT_1000_DIAMOND_GEMS(Difficulty.HARD, "Craft 1000 Diamond Gems", 37079, new int[]{34, 1000}),
    		FLETCH_5000_RUNE_ARROWS(Difficulty.HARD, "Fletch 5000 Rune Arrows", 37080, new int[]{36, 5000}),
    		STEAL_5000_SCIMITARS(Difficulty.HARD, "Steal 5000 Scimitars", 37081, new int[]{37, 5000}),
    		RUNECRAFT_8000_BLOOD_RUNES(Difficulty.HARD, "Runecraft 8000 Blood Runes", 37082, new int[]{38, 8000}),
    		BURY_500_FROST_DRAGON_BONES(Difficulty.HARD, "Bury 500 Frost Dragon Bones", 37083, new int[]{39, 500}),
    		MIX_100_OVERLOAD_POTIONS(Difficulty.HARD, "Mix 100 Overload Potions", 37084, new int[]{41, 100}),
    		COMPLETE_AN_ELITE_SLAYER_TASK(Difficulty.HARD, "Complete An Elite Slayer Task", 37085, null),
    		ASSEMBLE_5_GODSWORDS(Difficulty.HARD, "Assemble 5 Godswords", 37086, new int[]{42, 5}),
    		CLIMB_250_AGILITY_OBSTACLES(Difficulty.HARD, "Climb 250 Agility Obstacles", 37087, new int[]{42, 250}),
    		DEAL_HARD_DAMAGE_USING_MELEE(Difficulty.HARD, "Deal 10M Melee Damage", 37088, new int[]{43, 10000000}),
    		DEAL_HARD_DAMAGE_USING_RANGED(Difficulty.HARD, "Deal 10M Ranged Damage", 37089, new int[]{44, 10000000}),
    		DEAL_HARD_DAMAGE_USING_MAGIC(Difficulty.HARD, "Deal 10M Magic Damage", 37090, new int[]{45, 10000000}),
    		DEFEAT_JAD(Difficulty.HARD, "Defeat Jad", 37091, null),
    		DEFEAT_BANDOS_AVATAR(Difficulty.HARD, "Defeat Bandos Avatar", 37092, null),
    		DEFEAT_GENERAL_GRAARDOR(Difficulty.HARD, "Defeat General Graardor", 37093, null),
    		DEFEAT_KREE_ARRA(Difficulty.HARD, "Defeat Kree'Arra", 37094, null),
    		DEFEAT_COMMANDER_ZILYANA(Difficulty.HARD, "Defeat Commander Zilyana", 37095, null),
    		DEFEAT_KRIL_TSUTSAROTH(Difficulty.HARD, "Defeat K'ril Tsutsaroth", 37096, null),
    		DEFEAT_THE_CORPOREAL_BEAST(Difficulty.HARD, "Defeat The Corporeal Beast", 37097, null),
    		DEFEAT_NEX(Difficulty.HARD, "Defeat Nex", 37098, null),
    
    		COMPLETE_ALL_HARD_TASKS(Difficulty.ELITE, "Complete All Hard Tasks", 37105, new int[]{47, 32}),
    		CUT_AN_ONYX_STONE(Difficulty.ELITE, "Cut An Onyx Stone", 37106, null),
    		REACH_MAX_EXP_IN_A_SKILL(Difficulty.ELITE, "Reach Max Exp In A Skill", 37107, null),
    		MAX_OUT_ALL_SKILLS(Difficulty.ELITE, "Reach the highest level In All Skills", 37108, null),
    		DEFEAT_10000_MONSTERS(Difficulty.ELITE, "Defeat 10,000 Monsters", 37109, new int[]{49, 10000}),
    		DEFEAT_500_BOSSES(Difficulty.ELITE, "Defeat 500 Boss Monsters", 37110, new int[]{50, 500}),
    		VOTE_100_TIMES(Difficulty.ELITE, "Vote 100 Times", 37111, new int[]{51, 100}),
    		UNLOCK_ALL_LOYALTY_TITLES(Difficulty.ELITE, "Unlock All Loyalty Titles", 37112, new int[]{52, 11});
    		;
    		
    		AchievementData(Difficulty difficulty, String interfaceLine, int interfaceFrame, int[] progressData) {
    			this.difficulty = difficulty;
    			this.interfaceLine = interfaceLine;
    			this.interfaceFrame = interfaceFrame;
    			this.progressData = progressData;
    		}
    
    		private Difficulty difficulty;
    		private String interfaceLine;
    		private int interfaceFrame;
    		private int[] progressData;
    
    		public Difficulty getDifficulty() {
    			return difficulty;
    		}
    	}
    
    	public enum Difficulty {
    		BEGINNER, EASY, MEDIUM, HARD, ELITE;
    	}
    
    	public static boolean handleButton(Player player, int button) {
    		if(!(button >= -28531 && button <= -28424)) {
    			return false;
    		}
    		int index = -1;
    		if(button >= -28531 && button <= -28505) {
    			index = 28531 + button;
    		} else if(button >= -28499 && button <= -28473) {
    			index = 26 + 28499 + button;
    		} else if(button >= -28466 && button <= -28438) {
    			index = 53 + 28466 + button;
    		} else if(button >= -28432 && button <= -28424) {
    			index = 82 + 28432 + button;
    		}
    		if(index >= 0 && index < AchievementData.values().length) {
    			AchievementData achievement = AchievementData.values()[index];
    			if(player.getAchievementAttributes().getCompletion()[achievement.ordinal()]) {
    				player.getPacketSender().sendMessage("<img=10> <col=339900>You have completed the achievement: "+achievement.interfaceLine+".");
    			} else if(achievement.progressData == null) {
    				player.getPacketSender().sendMessage("<img=10> <col=660000>You have not started the achievement: "+achievement.interfaceLine+".");
    			} else {
    				int progress = player.getAchievementAttributes().getProgress()[achievement.progressData[0]];
    				int requiredProgress = achievement.progressData[1];
    				if(progress == 0) {
    					player.getPacketSender().sendMessage("<img=10> <col=660000>You have not started the achievement: "+achievement.interfaceLine+".");
    				} else if(progress != requiredProgress) {
    					player.getPacketSender().sendMessage("<img=10> <col=FFFF00>Your progress for this achievement is currently at: "+Misc.insertCommasToNumber(""+progress)+"/"+Misc.insertCommasToNumber(""+requiredProgress)+".");
    				}
    			}
    		}
    		return true;
    	}
    
    	public static void updateInterface(Player player) {
    		for(AchievementData achievement : AchievementData.values()) {
    			boolean completed = player.getAchievementAttributes().getCompletion()[achievement.ordinal()];
    			boolean progress = achievement.progressData != null && player.getAchievementAttributes().getProgress()[achievement.progressData[0]] > 0;
    			player.getPacketSender().sendString(achievement.interfaceFrame, (completed ? "@gre@" : progress ? "@yel@" : "@red@") + achievement.interfaceLine);
    		}
    		player.getPacketSender().sendString(37001, "Achievements: "+player.getPointsHandler().getAchievementPoints()+"/"+AchievementData.values().length);
    	}
    	
    	public static void setPoints(Player player) {
    		int points = 0;
    		for(AchievementData achievement : AchievementData.values()) {
    			if(player.getAchievementAttributes().getCompletion()[achievement.ordinal()]) {
    				points++;
    			}
    		}
    		player.getPointsHandler().setAchievementPoints(points, false);
    	}
    
    	public static void doProgress(Player player, AchievementData achievement) {
    		doProgress(player, achievement, 1);
    	}
    
    	public static void doProgress(Player player, AchievementData achievement, int amt) {
    		if(player.getAchievementAttributes().getCompletion()[achievement.ordinal()])
    			return;
    		if(achievement.progressData != null) {
    			int progressIndex = achievement.progressData[0];
    			int amountNeeded = achievement.progressData[1];
    			int previousDone = player.getAchievementAttributes().getProgress()[progressIndex];
    			if((previousDone+amt) < amountNeeded) {
    				player.getAchievementAttributes().getProgress()[progressIndex] = previousDone+amt;
    				if(previousDone == 0) 
    					player.getPacketSender().sendString(achievement.interfaceFrame, "@yel@"+ achievement.interfaceLine);
    			} else {
    				finishAchievement(player, achievement);
    			}
    		}
    	}
    
    	public static void finishAchievement(Player player, AchievementData achievement) {
    		if(player.getAchievementAttributes().getCompletion()[achievement.ordinal()])
    			return;
    		player.getAchievementAttributes().getCompletion()[achievement.ordinal()] = true;
    		player.getPacketSender().sendString(achievement.interfaceFrame, ("@gre@") + achievement.interfaceLine).sendMessage("<img=10> <col=339900>You have completed the achievement "+Misc.formatText(achievement.toString().toLowerCase()+".")).sendString(37001, "Achievements: "+player.getPointsHandler().getAchievementPoints()+"/"+AchievementData.values().length);
    
    		if(achievement.getDifficulty() == Difficulty.HARD) {
    			doProgress(player, AchievementData.COMPLETE_ALL_HARD_TASKS);
    		}
    		
    		player.getPointsHandler().setAchievementPoints(1, true);
    	}
    
    	public static class AchievementAttributes {
    
    		public AchievementAttributes(){}
    
    		/** ACHIEVEMENTS **/
    		private boolean[] completed = new boolean[AchievementData.values().length];
    		private int[] progress = new int[53];
    
    		public boolean[] getCompletion() {
    			return completed;
    		}
    
    		public void setCompletion(int index, boolean value) {
    			this.completed[index] = value;
    		}
    
    		public void setCompletion(boolean[] completed) {
    			this.completed = completed;
    		}
    
    		public int[] getProgress() {
    			return progress;
    		}
    
    		public void setProgress(int index, int value) {
    			this.progress[index] = value;
    		}
    
    		public void setProgress(int[] progress) {
    			this.progress = progress;
    		}
    
    		/** MISC **/
    		private int coinsGambled;
    		private double totalLoyaltyPointsEarned;
    		private boolean[] godsKilled = new boolean[5];
    
    		public int getCoinsGambled() {
    			return coinsGambled;
    		}
    
    		public void setCoinsGambled(int coinsGambled) {
    			this.coinsGambled = coinsGambled;
    		}
    
    		public double getTotalLoyaltyPointsEarned() {
    			return totalLoyaltyPointsEarned;
    		}
    
    		public void incrementTotalLoyaltyPointsEarned(double totalLoyaltyPointsEarned) {
    			this.totalLoyaltyPointsEarned += totalLoyaltyPointsEarned;
    		}
    
    		public boolean[] getGodsKilled() {
    			return godsKilled;
    		}
    
    		public void setGodKilled(int index, boolean godKilled) {
    			this.godsKilled[index] = godKilled;
    		}
    
    		public void setGodsKilled(boolean[] b) {
    			this.godsKilled = b;
    		}
    	}
    }
    Reply With Quote  
     

  9. #9  
    Extreme Donator


    Join Date
    Oct 2010
    Posts
    2,853
    Thanks given
    1,213
    Thanks received
    1,622
    Rep Power
    5000
    If it's an achievement which requires stages (progress) you must increase the int[] progress length.
    [Today 01:29 AM] RSTrials: Nice 0.97 Win/Loss Ratio luke. That's pretty bad.
    [Today 01:30 AM] Luke132: Ok u fucking moron i forgot i could influence misc.random
    Reply With Quote  
     

  10. #10  
    Registered Member
    Join Date
    Jun 2016
    Posts
    52
    Thanks given
    5
    Thanks received
    0
    Rep Power
    11
    Quote Originally Posted by Professor Oak View Post
    If it's an achievement which requires stages (progress) you must increase the int[] progress length.
    you mean here?
    Code:
     private int[] progress = new int[53];
    Reply With Quote  
     

Page 1 of 3 123 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. Need help with ruse client
    By Amirtje12 in forum Help
    Replies: 0
    Last Post: 02-27-2016, 10:56 PM
  2. paying for help with ruse client
    By teachmetocodee in forum Buying
    Replies: 0
    Last Post: 02-26-2016, 07:52 PM
  3. Need help with ruse
    By Icefishjj in forum Buying
    Replies: 1
    Last Post: 12-24-2015, 01:15 AM
  4. Help with Ruse Client
    By Torag16 in forum Help
    Replies: 0
    Last Post: 12-10-2015, 05:38 PM
  5. Help with RUSE cachedownloader.java
    By dabs in forum Help
    Replies: 5
    Last Post: 11-05-2015, 02:30 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •