Thread: [Any] Request Assistance

Page 1 of 2 12 LastLast
Results 1 to 10 of 17
  1. #1 [Any] Request Assistance 
    Extreme Donator


    Join Date
    Oct 2010
    Posts
    1,666
    Thanks given
    253
    Thanks received
    407
    Rep Power
    296
    Wrote this today because I was bored and wanted to add all the proper player options. Wrote this for 876 revision, although this can be implemented into any base. Hopefully people add this

    Spoiler for AssistanceManager.java:
    Code:
    package net.nocturne.game.player;
    
    import java.util.ArrayList;
    import java.util.Date;
    import java.util.HashMap;
    import java.util.List;
    import java.util.concurrent.TimeUnit;
    
    import net.nocturne.game.Animation;
    import net.nocturne.game.Graphics;
    import net.nocturne.game.tasks.WorldTask;
    import net.nocturne.game.tasks.WorldTasksManager;
    import net.nocturne.utils.Color;
    import net.nocturne.utils.Utils;
    
    /**
     * @author Miles Black (bobismyname)
     * @date Jan 1, 2017
     */
    
    public class AssistanceManager {
    	
    	private Player player, other;
    	private boolean assisting;
    	private Date lastAssist;
    	private List<Integer> skills = new ArrayList<Integer>();
    	private HashMap<Integer, Integer> xpEarned = new HashMap<Integer, Integer>();
    	
    	AssistanceManager(Player player) {
    		this.player = player;
    		this.assisting = false;
    	}
    	
    	private void setOther(Player other) {
    		this.other = other;
    		this.assisting = false;
    	}
    	
    	public boolean isAssisting() {
    		return assisting;
    	}
    	
    	private void setSkill(int skillId) {
    		if (!skills.contains(skillId)) {
    			skills.add(skillId);
    			player.getPackets().sendGameMessage(Color.YELLOW, player.getSkills().getSkillName(skillId) + " has been enabled for assistance.");
    		} else if (skills.contains(skillId)) {
    			skills.remove(skillId);
    			player.getPackets().sendGameMessage(Color.YELLOW, player.getSkills().getSkillName(skillId) + " has been disabled for assistance.");
    		}
    	}
    	
    	@SuppressWarnings("deprecation")
    	public void acceptRequest(Player other) {
    		if (!player.isAcceptingAid()) {
    			other.getPackets().sendGameMessage("This player currently has accept aid turned off.");
    			return;
    		}
    		this.other = other;
    		this.assisting = true;
    		player.setNextFaceEntity(other);
    		other.setNextFaceEntity(player);
    		WorldTasksManager.schedule(new WorldTask() {
    			int stage = 0;
    			@Override
    			public void run() {
    				if (stage == 0)
    					player.setNextAnimation(new Animation(7299));
    				else if (stage == 1)
    					player.setNextGraphics(new Graphics(1247));
    				else if (stage == 2)
    					other.setNextAnimation(new Animation(7299));
    				stage++;
    			}
    		}, 3);
    		other.getAssistanceManager().setOther(other);
    		player.getPackets().sendVar(1180, 1);
    		player.getPackets().sendHideIComponent(745, 3, false);
    		other.getPackets().sendHideIComponent(745, 3, false);
    		player.getInterfaceManager().setWindowInterface(364, 745);
    		other.getInterfaceManager().setWindowInterface(364, 745);
    		player.getInterfaceManager().sendLockGameTab(InterfaceManager.INVENTORY_TAB, true);
    		player.getPackets().sendIComponentText(301, 10, "You are currently assisting " + other.getUsername() + ".");
    		player.getInterfaceManager().sendCentralInterface(301);
    		player.getPackets().sendGameMessage("You are now assisting " + other.getUsername() + ".");
    		other.getPackets().sendGameMessage("You are now being assisted by " + player.getUsername() + ".");
    		player.setCloseInterfacesEvent(() -> {
    			this.other = null;
    			this.assisting = false;
    			other.getAssistanceManager().setOther(null);
    			player.getPackets().sendHideIComponent(745, 3, true);
    			other.getPackets().sendHideIComponent(745, 3, true);
    			player.closeInterfaces();
    			player.getInterfaceManager().sendLockGameTab(InterfaceManager.INVENTORY_TAB, false);
    			player.getPackets().sendGameMessage("You have stopped assisting " + other.getUsername() + ".");
    			other.getPackets().sendGameMessage("You are no longer being assisted by " + player.getUsername() + ".");
    		});
    	}
    	
    	boolean hasLevel(int skillId, int level) {
    		if (other != null || assisting == false || !skills.contains(skillId) || other.getSkills().getLevel(skillId) < level)
    			return false;
    		return true;
    	}
    	
    	double handleXP(int skillId, double exp) {
    		if (TimeUnit.MILLISECONDS.toDays(lastAssist.getTime() - new Date().getTime()) >= 1)
    			xpEarned = new HashMap<Integer, Integer>();
    		double totalXp = xpEarned.values().stream().mapToInt(Number::intValue).sum();
    		double completeXp = exp;
    		if (totalXp + exp >= 30000) {
    			if (totalXp >= 30000)
    				completeXp = 0;
    			else
    				completeXp = totalXp + exp - 30000;
    			if (lastAssist == null)
    				lastAssist = new Date();
    		}
    		xpEarned.put(skillId, new Double(completeXp).intValue());
    		player.getPackets().sendIComponentText(301,  getComponentForSkill(skillId), Utils.format(xpEarned.get(skillId)));
    		player.getPackets().sendIComponentText(301, 84, Utils.format(totalXp));
    		return completeXp;
    	}
    	
    	public boolean handleButtons(int componentId) {
    		switch (componentId) {
    		case 74:
    			setSkill(Skills.RUNECRAFTING);
    			return true;
    		case 75:
    			setSkill(Skills.CRAFTING);
    			return true;
    		case 76:
    			setSkill(Skills.FLETCHING);
    			return true;
    		case 77:
    			setSkill(Skills.CONSTRUCTION);
    			return true;
    		case 78:
    			setSkill(Skills.FARMING);
    			return true;
    		case 79:
    			setSkill(Skills.MAGIC);
    			return true;
    		case 80:
    			setSkill(Skills.SMITHING);
    			return true;
    		case 81:
    			setSkill(Skills.COOKING);
    			return true;
    		case 82:
    			setSkill(Skills.HERBLORE);
    			return true;
    		}
    		return false;
    	}
    	
    	int getComponentForSkill(int skillId) {
    		switch (skillId) {
    		case Skills.RUNECRAFTING:
    			return 46;
    		case Skills.CRAFTING:
    			return 48;
    		case Skills.FLETCHING:
    			return 50;
    		case Skills.CONSTRUCTION:
    			return 52;
    		case Skills.FARMING:
    			return 54;
    		case Skills.MAGIC:
    			return 56;
    		case Skills.SMITHING:
    			return 58;
    		case Skills.COOKING:
    			return 60;
    		case Skills.HERBLORE:
    			return 62;
    		default:
    			return -1;
    		}
    	}
    	
    	boolean isValidSkill(int skillId) {
    		switch (skillId) {
    		case Skills.RUNECRAFTING:
    		case Skills.CRAFTING:
    		case Skills.FLETCHING:
    		case Skills.CONSTRUCTION:
    		case Skills.FARMING:
    		case Skills.MAGIC:
    		case Skills.SMITHING:
    		case Skills.COOKING:
    		case Skills.HERBLORE:
    			return true;
    		default:
    			return false;
    		}
    	}
    
    }


    Spoiler for Skills.java:
    Code:
    private boolean hasLevel(int skill, int requiredLevel) {
    	if (player.getAssistanceManager().hasLevel(skill, requiredLevel) || level[skill] >= requiredLevel)
    		return true;
    	player.getPackets().sendGameMessage("You must have a " + getSkillName(skill).toLowerCase() + " level of at least " + requiredLevel + " to do this.");
    	return false;
    }
    Add this to the bottom of your addXp method.
    Code:
    if (player.getAssistanceManager().isAssisting() && player.getAssistanceManager().isValidSkill(skill))
    	exp = player.getAssistanceManager().handleXP(skill, exp);


    Spoiler for GamePacketsDecoder.java:

    PLAYER_OPTION_5_PACKET varies depending on your revision...
    Code:
    		} else if (opcode == PLAYER_OPTION_5_PACKET) {
    			boolean forceRun = stream.readUnsignedByte128() == 1;
    			int playerIndex = stream.readUnsignedShort128();
    			final Player p2 = World.getPlayers().get(playerIndex);
    			if (p2 == null || p2 == player || p2.isDead() || p2.hasFinished() || !player.getMapRegionsIds().contains(p2.getRegionId()))
    				return;
    			if (player.isLocked())
    				return;
    			if (forceRun)
    				player.setRun(forceRun);
    			player.stopAll();
    			player.setRouteEvent(new RouteEvent(p2, new Runnable() {
    
    				@Override
    				public void run() {
    					if (!player.getControllerManager().canPlayerOption4(p2))
    						return;
    					player.stopAll();
    					if (player.isAnIronMan()) {
    						player.getPackets().sendGameMessage("You are an " + player.getIronmanTitle(true) + ", you stand alone.");
    						return;
    					}
    					if (p2.isAnIronMan()) {
    						player.getPackets().sendGameMessage(p2.getDisplayName() + " is an " + p2.getIronmanTitle(true) + ", and assist.");
    						return;
    					}
    					if (player.isBeginningAccount()) {
    						player.getPackets().sendGameMessage("Starter accounts cannot assist for the first hour of playing time.");
    						return;
    					}
    					if (player.isCantTrade() || player.getControllerManager().getController() != null && player.getControllerManager().getController() instanceof StealingCreationLobbyController) {
    						player.getPackets().sendGameMessage("You are busy at the moment.");
    						return;
    					}
    					if (p2.isBeginningAccount()) {
    						player.getPackets().sendGameMessage("Your target is a starter account, which cannot assist for the first hour of playing time.");
    						return;
    					}
    					if (p2.getAssistanceManager().isAssisting() || p2.getInterfaceManager().containsScreenInterface() || p2.isCantTrade() || p2.getControllerManager().getController() != null && p2.getControllerManager().getController() instanceof StealingCreationLobbyController || p2.isLocked()) {
    						player.getPackets().sendGameMessage("The other player is busy at the moment.");
    						return;
    					}
    					if (!p2.withinDistance(player, 14)) {
    						player.getPackets().sendGameMessage("Unable to find target " + p2.getDisplayName() + ".");
    						return;
    					}
    					if (!player.getBank().hasVerified(10)) {
    						return;
    					}
    					if (p2.getTemporaryAttributtes().get("AssistTarget") == player) {
    						p2.getTemporaryAttributtes().remove("AssistTarget");
    						player.getAssistanceManager().acceptRequest(p2);
    						return;
    					}
    					player.getTemporaryAttributtes().put("AssistTarget", p2);
    					player.getPackets().sendGameMessage("Sending the other player an assist request...");
    					p2.getPackets().sendAssistRequestMessage(player);
    				}
    			}));


    Spoiler for WorldPacketsEncoder.java:
    Code:
    public void sendAssistRequestMessage(Player p) {
    	sendMessage(100, "is requesting assistance from you.", p);
    }


    Spoiler for Player.java:

    Code:
    private transient AssistanceManager assistanceManager;
    public AssistanceManager getAssistanceManager() {
    	return assistanceManager;
    }
    
    (inside the player constructor)
    assistanceManager = new AssistanceManager(this);
    
    (inside the init method)
    if (assistanceManager == null)
    	assistanceManager = new AssistanceManager(this);
    
    (inside the sendDefaultPlayerOptions method)
    getPackets().sendPlayerOption("Req Assist", 5, false);


    Quote Originally Posted by Joris View Post
    Code:
    	private Map<Skill, Boolean> skills = new HashMap<Skill, Boolean>();
    Buttons:
    Code:
    if(Skill.getSkillByComponent(componentId) == null)
    			return;
    		skills.put(Skill.getSkillByComponent(componentId), !skills.get(Skill.getSkillByComponent(componentId)));
    		player.getPackets().sendConfigByFile(Skill.getSkillByComponent(componentId).getBitConfig(), skills.get(Skill.getSkillByComponent(componentId)) ? 1 : 0);
    Skills
    Code:
    	/**
    	 * @author Joris
    	 *
    	 */
    	public enum Skill {
    		RUNECRAFTING(4090, 74),
    		CRAFTING(4091, 75),
    		FLETCHING(4093, 76),
    		CONSTRUCTION(4095, 77),
    		FARMING(4096, 78),
    		MAGIC(4098, 79),
    		SMITHING(4100, 80),
    		COOKING(4101, 81),
    		HERBLORE(4102, 82);
    		
    		private int bitConfig;
    		private int component;
    		Skill(int bitConfig, int component) {
    			this.setBitConfig(bitConfig);
    			this.setComponent(component);
    		}
    
    		/**
    		 * @return the bitConfig
    		 */
    		public int getBitConfig() {
    			return bitConfig;
    		}
    
    		/**
    		 * @param bitConfig the bitConfig to set
    		 */
    		public void setBitConfig(int bitConfig) {
    			this.bitConfig = bitConfig;
    		}
    
    		/**
    		 * @return the component
    		 */
    		public int getComponent() {
    			return component;
    		}
    
    		/**
    		 * @param component the component to set
    		 */
    		public void setComponent(int component) {
    			this.component = component;
    		}
    		
    		/**
    		 * Gets skill by component id
    		 * @param componentId
    		 * @return
    		 */
    		public static Skill getSkillByComponent(int componentId) {
    			return Arrays.stream(Skill.values()).filter(skill -> skill.getComponent() == componentId).findAny().orElseGet(null);
    		}
    		
    	}
    Sending XP:
    Code:
    player.getPackets().sendConfigByFile(4103, ((int) experience * 10));
    Reply With Quote  
     

  2. Thankful users:


  3. #2  
    Respected Member


    Kris's Avatar
    Join Date
    Jun 2016
    Age
    26
    Posts
    3,638
    Thanks given
    820
    Thanks received
    2,642
    Rep Power
    5000
    Well then.. Thank you. I was just thinking of writing assistance system today but I guess you saved me a ton of time. Thanks . Looks fine too btw.
    Reply With Quote  
     

  4. #3  
    Extreme Donator


    Join Date
    Oct 2010
    Posts
    1,666
    Thanks given
    253
    Thanks received
    407
    Rep Power
    296
    Quote Originally Posted by Eldritch View Post
    Well then.. Thank you. I was just thinking of writing assistance system today but I guess you saved me a ton of time. Thanks . Looks fine too btw.
    If you can figure out how to get that assist icon on the screen that would be amazing
    Reply With Quote  
     

  5. #4  
    Registered Member

    Join Date
    Sep 2014
    Posts
    300
    Thanks given
    122
    Thanks received
    91
    Rep Power
    158
    Thanks for Contributing!
    Reply With Quote  
     

  6. #5  
    Donator


    Join Date
    Jul 2013
    Posts
    1,233
    Thanks given
    1
    Thanks received
    493
    Rep Power
    0
    Never even used the assist option in rs lol nice tho
    Reply With Quote  
     

  7. #6  
    Extreme Donator


    Join Date
    Oct 2010
    Posts
    1,666
    Thanks given
    253
    Thanks received
    407
    Rep Power
    296
    Quote Originally Posted by Eldritch View Post
    Well then.. Thank you. I was just thinking of writing assistance system today but I guess you saved me a ton of time. Thanks . Looks fine too btw.
    Quote Originally Posted by Banners View Post
    Thanks for Contributing!
    Updated with the assist icon components and locking of the inventory for the person who is assisting a player.
    Reply With Quote  
     

  8. #7  
    Registered Member
    Join Date
    Apr 2016
    Posts
    139
    Thanks given
    30
    Thanks received
    38
    Rep Power
    66
    Quote Originally Posted by bobismyname View Post
    If you can figure out how to get that assist icon on the screen that would be amazing
    Picture of the icon?
    Reply With Quote  
     

  9. #8  
    Extreme Donator


    Join Date
    Oct 2010
    Posts
    1,666
    Thanks given
    253
    Thanks received
    407
    Rep Power
    296
    Quote Originally Posted by Akatosh View Post
    Picture of the icon?
    Found it, added it to the thread.

    REVISIONS:
    - Added the 24 hour timer to reset the max exp earned.
    - Added the image configuration for the assisting interface.
    - Patched a few wierd bugs I came across.
    Reply With Quote  
     

  10. #9  
    Banned

    Join Date
    Jul 2011
    Posts
    1,767
    Thanks given
    493
    Thanks received
    425
    Rep Power
    0
    good job and ty for icon
    Reply With Quote  
     

  11. #10  
    Donator


    Join Date
    Jan 2014
    Posts
    1,652
    Thanks given
    428
    Thanks received
    501
    Rep Power
    221
    Quote Originally Posted by bobismyname View Post
    TODO:
    - Configs for pressing the buttons, cba to find them in the meantime.

    If you can find any of those, please contribute to this thread and I will update it.
    Code:
    	private Map<Skill, Boolean> skills = new HashMap<Skill, Boolean>();
    Buttons:
    Code:
    if(Skill.getSkillByComponent(componentId) == null)
    			return;
    		skills.put(Skill.getSkillByComponent(componentId), !skills.get(Skill.getSkillByComponent(componentId)));
    		player.getPackets().sendConfigByFile(Skill.getSkillByComponent(componentId).getBitConfig(), skills.get(Skill.getSkillByComponent(componentId)) ? 1 : 0);
    Skills
    Code:
    	/**
    	 * @author Joris
    	 *
    	 */
    	public enum Skill {
    		RUNECRAFTING(4090, 74),
    		CRAFTING(4091, 75),
    		FLETCHING(4093, 76),
    		CONSTRUCTION(4095, 77),
    		FARMING(4096, 78),
    		MAGIC(4098, 79),
    		SMITHING(4100, 80),
    		COOKING(4101, 81),
    		HERBLORE(4102, 82);
    		
    		private int bitConfig;
    		private int component;
    		Skill(int bitConfig, int component) {
    			this.setBitConfig(bitConfig);
    			this.setComponent(component);
    		}
    
    		/**
    		 * @return the bitConfig
    		 */
    		public int getBitConfig() {
    			return bitConfig;
    		}
    
    		/**
    		 * @param bitConfig the bitConfig to set
    		 */
    		public void setBitConfig(int bitConfig) {
    			this.bitConfig = bitConfig;
    		}
    
    		/**
    		 * @return the component
    		 */
    		public int getComponent() {
    			return component;
    		}
    
    		/**
    		 * @param component the component to set
    		 */
    		public void setComponent(int component) {
    			this.component = component;
    		}
    		
    		/**
    		 * Gets skill by component id
    		 * @param componentId
    		 * @return
    		 */
    		public static Skill getSkillByComponent(int componentId) {
    			return Arrays.stream(Skill.values()).filter(skill -> skill.getComponent() == componentId).findAny().orElseGet(null);
    		}
    		
    	}
    Sending XP:
    Code:
    player.getPackets().sendConfigByFile(4103, ((int) experience * 10));
    Reply With Quote  
     

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. Requesting Assistance
    By I Am Kacey in forum Requests
    Replies: 1
    Last Post: 11-23-2011, 07:30 AM
  2. Replies: 1
    Last Post: 05-15-2011, 10:02 AM
  3. Requesting Assistance.
    By Trenton in forum Requests
    Replies: 0
    Last Post: 04-09-2011, 02:38 AM
  4. Request Assistance was being developing in 474?
    By Harry in forum RS 503+ Client & Server
    Replies: 11
    Last Post: 09-30-2009, 01:54 PM
  5. Any requests?
    By Zachhh in forum Requests
    Replies: 39
    Last Post: 09-15-2009, 05:19 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
  •