Thread: Genie Resetting HP to Level 1

Results 1 to 2 of 2
  1. #1 Genie Resetting HP to Level 1 
    Registered Member
    Join Date
    Apr 2017
    Posts
    72
    Thanks given
    4
    Thanks received
    3
    Rep Power
    11
    Hey guys.

    Genie has been setup to set all combat levels to 1 except hp.

    It was created as a separate class and handles everything itself..

    Spoiler for Genie.Java:
    Code:
    public class GenieReset {
    
    	/**
    	 * Genie data for skill reseting
    	 * 
    	 * 
    	 *
    	 */
    	public enum GenieData {
    		ATTACK(232114, "Attack", 0),
    		STRENGTH(232117, "Strength", 2),
    		DEFENCE(232120, "Defence", 1),
    		RANGE(232123, "Range", 4),
    		MAGIC(232126, "Magic", 6),
    		PRAYER(232129, "Prayer", 5),
    		HITPOINTS(232132, "Hitpoints", 3);
    
    		private int buttonId, skillId;
    		private String skillName;
    
    		private GenieData(int buttonId, String skillName, int skillId) {
    			this.buttonId = buttonId;
    			this.skillName = skillName;
    			this.skillId = skillId;
    		}
    
    		public int getButton() {
    			return buttonId;
    		}
    
    		public String getSkillName() {
    			return skillName;
    		}
    
    		public int getSkillId() {
    			return skillId;
    		}
    
    		public static GenieData forId(int buttonId) {
    			for (GenieData data : GenieData.values())
    				if (data.buttonId == buttonId)
    					return data;
    			return null;
    		}
    	}
    
    	/**
    	 * Handles the skill reseting
    	 * 
    	 * @param player
    	 * @param buttonId
    	 * @return
    	 */
    	public static boolean handle(Player player, int buttonId) {
    		// Grabs the genie data
    		GenieData genie = GenieData.forId(buttonId);
    
    		// Return if genie data is null
    		if (genie == null) {
    			return false;
    		}
    
    		// Return if player does not have required amount of coins
    		if (!player.getInventory().hasItemAmount(new Item(995, 1_000_000))) {
    			DialogueManager.sendNpcChat(player, 409, Emotion.ANGRY_1, "Reseting a skill costs " + Utility.format(1_000_000) + " coins!");
    			return false;
    		}
    
    		// Return if player is wearing items
    		if (player.getEquipment().getEquipmentCount() != 0) {
    			DialogueManager.sendNpcChat(player, 409, Emotion.ANGRY_2, "Remove all equipment before prestiging.");
    			return false;
    		}
    
    		// Closes the interface
    		player.send(new SendRemoveInterfaces());
    
    		// Deletes the coins from player's inventory
    		player.getInventory().remove(new Item(995, 1_000_000));
    
    		// Resets the player's skill
    		if (genie.getSkillId() == 3) {
    			player.getLevels()[genie.getSkillId()] = ((byte) 10);
    			player.getMaxLevels()[genie.getSkillId()] = ((byte) 10);
    			player.getSkill().getExperience()[genie.getSkillId()] = player.getSkill().getXPForLevel(genie.getSkillId(), 10);
    			player.getSkill().update(genie.getSkillId());
    			player.getSkill().update();
    	        player.setAppearanceUpdateRequired(true);
    		} else {
    			player.getLevels()[genie.getSkillId()] = ((byte) 1);
    			player.getMaxLevels()[genie.getSkillId()] = ((byte) 1);
    			player.getSkill().getExperience()[genie.getSkillId()] = player.getSkill().getXPForLevel(genie.getSkillId(), 1);
    			player.getSkill().update(genie.getSkillId());
    			player.getSkill().update();
    	        player.setAppearanceUpdateRequired(true);
    		}
    		// Refreshes the player's skills
    		//player.getSkill().update();
            //player.setAppearanceUpdateRequired(true);
    
    		// Sends Genie dialogue
    		DialogueManager.sendNpcChat(player, 326, Emotion.HAPPY, "You have successfully reset your " + genie.getSkillName() + " to "+player.getSkill().getLevels()[genie.getSkillId()]+"!");
    
    		// Reset dialogue
    		player.getDialogue().setNext(-1);
    		
    		// Sends the Achievement
    		AchievementHandler.activateAchievement(player, AchievementList.RESET_5_STATISTICS, 1);
    		
    		// Return true
    		return true;
    	}
    
    }


    I think the issue is the getXPForLevel part but even if i change that another number -- e.g. genie.getSkillId(), 25); -- It doesn't ever change the HP Level from displaying as 10, but the actual level is 1. This means that the Combat level of a player resetting every stat goes to 1..

    Spoiler for Image Showing 10/1 for HP:
    Reply With Quote  
     

  2. #2  
    What's a sundial in the shade?

    Lumiere's Avatar
    Join Date
    May 2013
    Age
    23
    Posts
    531
    Thanks given
    215
    Thanks received
    97
    Rep Power
    113
    Use a ternary instead.

    Code:
    			final int level = genie.getSkillId() == GenieData.HITPOINTS.getSkillId() ? 10 : 1;
    				
    			player.getLevels()[genie.getSkillId()] = level;
    			player.getMaxLevels()[genie.getSkillId()] = level;
    			player.getSkill().getExperience()[genie.getSkillId()] = player.getSkill().getXPForLevel(genie.getSkillId(), level);
    			player.getSkill().update(genie.getSkillId());
    			player.getSkill().update();
    I personally don't think you need to use an enum for this, but also, for the skill name, you don't need to add an extra string to the enum.
    Just call; "Misc.capitalizeWords(GenieData.ATTACK.name().toLo werCase())" the name() method for an enum returns the enum constant as a string.

    Another note on the enum; if you organize the skills by their id like so; (0 - 6)
    Code:
    		ATTACK(232114),
    		DEFENCE(232120),
    		STRENGTH(232117),
    		HITPOINTS(232132),
    		RANGE(232123),
    		PRAYER(232129),
    		MAGIC(232126);
    You can use "Genie.MAGIC.ordinal()"
    Now, you just have the button ids, which you could define as constant integers, rather than in an enum.

    Code:
    public static final int GENIE_ATTACK_BUTTON = 232114;
    public static final int GENIE_DEFENCE_BUTTON = 232120;
    Then, use the Skills enum instead, to define the skill names, and skill ids, with the same idea.
    Skills.ATTACK.ordinal() > Skills.ATTACK.name().toLowerCase()
    Assuming you're using an enum for the skills

    If you really still wanted to use the enum, I would recommend naming similar to this at the very least;
    Code:
    		ATTACK_BUTTON(232114),
    		DEFENCE_BUTTON(232120),
    		STRENGTH_BUTTON(232117),
    		HITPOINTS_BUTTON(232132),
    		RANGE_BUTTON(232123),
    		PRAYER_BUTTON(232129),
    		MAGIC_BUTTON(232126);

    For a last note; "GenieData" is not a good name for the enum, "Genie" might be better, but lacking description, the point is the fact that we already know the enum contains data for the "Genie".


    If you don't already know! This is how a ternary works.
    Code:
     condition ? condition-true : condition-false
    So, for example;
    Code:
    boolean conditionExample = false;
    int integerExample = conditionExample ? 1 : 0;
    "integerExample" would always return "0" unless the value of the "conditionExample" boolean was changed.

    Spoiler for Revy is perfect:
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

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

Similar Threads

  1. Replies: 0
    Last Post: 07-25-2010, 11:24 PM
  2. [DELTA]Adding Inf Hp To Ring?
    By Drake11 in forum Help
    Replies: 10
    Last Post: 05-30-2009, 06:56 PM
  3. EXP to level chart/list
    By OldMercenary in forum Configuration
    Replies: 2
    Last Post: 02-20-2008, 02:01 PM
Tags for this Thread

View Tag Cloud

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •