Thread: Matrix | Extremely simple gearcommand manager

Page 1 of 2 12 LastLast
Results 1 to 10 of 12
  1. #1 Matrix | Extremely simple gearcommand manager 
    Registered Member _Andy's Avatar
    Join Date
    May 2013
    Age
    25
    Posts
    644
    Thanks given
    224
    Thanks received
    111
    Rep Power
    4
    hi

    create class GearCommands under com/rs/game/player/content (or anywhere else you wish really)
    Code:
    package com.rs.game.player.content;
    
    import com.rs.cache.loaders.ItemDefinitions;
    import com.rs.game.item.Item;
    import com.rs.game.player.Player;
    import com.rs.game.player.Skills;
    import com.rs.game.player.actions.Summoning;
    import com.rs.game.player.actions.Summoning.Pouches;
    import com.rs.net.decoders.handlers.ButtonHandler;
    import com.rs.utils.Utils;
    
    public class GearCommands {
    	 /**
    	    * @author _Andy @rune-server.ee
    	    */
    	final static int MODERN = 0, ANCIENT = 1, LUNAR = 2;
    	
    	public static enum Gears {
    		SET1("main2", 
    				/*inventory items, order of spawning*/
    				new int[][] {{23255, 1}, {23279, 1}, {23351, 2}, {15272, 2}, {23567, 2}, {6737, 1},
    				{11732, 1}, {15272, 2}, {6585, 1}, {19748, 1}, {15272, 2}, {4736, 1}, {12681, 1}, 
    				{4720, 1}, {4722, 1}, {5698, 1}, {4151, 1}, {20072, 1}, {8013, 500}, {555, 6000}, {560, 4000}, {565, 3000}, {12437, 500}}, 
    				/*equipment items, any order*/
    				new int[][] {{2412, 1}, {4708, 1}, {7462, 1}, {6731, 1}, {6920, 1}, {15486, 1}, {4712, 1}, {4714, 1}, {6889, 1}, {18335, 1}}, 
    				/*modified stats, add one 99 stat if you want max, skillId, level*/
    				new int[][] {{1, 99}},
    				/*boolean curses, int spellbook, boolean spawnFamiliar*/
    				true, ANCIENT, true),
    		SET2("main", 
    				new int[][] {{1, 1}, {1, 1}}, 
    				new int[][] {{2412, 1}}, 
    				new int[][] {{0, 99}}, 
    				true, ANCIENT, true);
    		private int[][] inventory;
    		private int[][] equipment;
    		private int[][] stats;
    		private boolean curses;
    		private int spellbook;
    		private boolean spawnFamiliar;
    		private String name;
    		private Gears(String name, int[][] inventory, int[][] equipment, int[][] stats, boolean curses, int spellbook, boolean spawnFamiliar) {
    			this.name = name;
    			this.inventory = inventory;
    			this.equipment = equipment;
    			this.stats = stats;
    			this.curses = curses;
    			this.spellbook = spellbook;
    			this.spawnFamiliar = spawnFamiliar;
    		}
    		public String getName() {
    			return name;
    		}
    	}
    /*add items that should be randomly switched below, items are in arrays categorised(not necessary, but easier to follow)*/
    	private final static int[][] forSwitch =
    		{{ 6109, 656, 658, 660, 662, 664, 2900, 2910, 2920, 2930, 6860, 6858, 6856, 6862, 13101 },
    			
    		{ 3105, 626, 628, 630, 632, 634, 1837, 2579 },
    		
    		{ 4675, 24092, 24094, 24096, 24098 },
    		
    		{ 6107, 10458, 10460, 10462, 19380 },
    		
    		{ 6108, 10464, 10466, 10468, 19386, 646 },
    		
    		{ 2412, 2413, 2414 },
    	
    		{ 15486, 22207, 22209, 22211, 22213 },
    		
    		{ 6920, 626, 4097, 4117, 4107 },
    	
    		{ 14499, 6109, 660, 662, 664, 2900, 6860, 6858, 6856, 6862, 13101, 4109, 4099, 4089, 6918, 15602, 15608, 15620, 15614 },
    		
    		{ 6889, 24100, 24102, 24104, 24106 },
    	
    		{ 6924, 15610, 15616, 15622, 4093, 4103, 4113, 7398, 14501 },
    		
    		{ 7399, 4091, 4101, 4111, 6916, 15600, 15606, 15612, 15618, 14497 }};
    
    	private static int getRandomSwitchedItem(Player player, int init) {
    			int switchCape = player.isCompletedFightKiln() ? 23659 : player.isCompletedFightCaves() ? 6570 : 19748,
    					 imbueZerk = player.isDonator() || player.isExtremeDonator() ? 15220 : 6737, 
    							 imbueSeers = player.isDonator() || player.isExtremeDonator() ? 15018 : 6731;
    			switch (init) {
    			case 6737:
    				return imbueZerk;
    			case 19748:
    				return switchCape;
    			case 6731:
    				return imbueSeers;
    			}
    			for (int[] array : forSwitch) {
    				for (int member : array) {
    					if (member == init)
    						return array[Utils.random(array.length)];
    				}
    			}
    			return init;
    	}
    	
    	private static void refresh(Player player) {
    		player.getInventory().init();
    		player.getEquipment().init();
    		player.getSkills().restoreSkills();
    		player.setHitpoints(player.getMaxHitpoints());
    		player.refreshHitPoints();
    		player.getPrayer().restorePrayer(player.getSkills(  ).getLevel(Skills.PRAYER) * 10);
    		player.getInterfaceManager().closeXPDisplay();
    		player.getInterfaceManager().sendXPDisplay();
    		ButtonHandler.refreshEquipBonuses(player);
    		player.getAppearence().generateAppearenceData();
    	}
    	
    	private static void setStats(Player player, Gears gear) {
    		for (int id = 0; id < player.getSkills().getLevels().length; id++) {
    			if (id >= 7 && id < 23 || id > 23)
    				continue;
    player.getSkills().setXp(id, Skills.getXPForLevel(99));
    		}
    		for (int[] skills : gear.stats) {
    			player.getSkills().setXp(skills[0], Skills.getXPForLevel(skills[1]));
    		}
    	}
    	
    	private static void setInventory(Player player, Gears gear) {
    		player.getInventory().reset();
    		if (gear != null) {
    			for (int[] id : gear.inventory) {
    				int switchedItem = getRandomSwitchedItem(player, id[0]);
    				player.getInventory().addItem(switchedItem, id[1]);
    			}
    		}
    	}
    	
    	private static void setEquipment(Player player, Gears gear) {
    		player.getEquipment().reset();
    		for (int[] id : gear.equipment) {
    			int switchedItem = getRandomSwitchedItem(player, id[0]);
    			player.getEquipment().getItems().set(ItemDefinitio  ns.getItemDefinitions(switchedItem).equipSlot, new Item(switchedItem, id[1]));
    		}
    	}
    	
    	private static void setMisc(Player player, Gears gear) {
    		player.getPrayer().setPrayerBook(gear.curses);
    		player.getCombatDefinitions().setSpellBook(gear.sp  ellbook);
    		if (player.getFamiliar() == null && gear.spawnFamiliar)
    			Summoning.spawnFamiliar(player, Pouches.WOLPERTINGER);
    	}
    	
    	private static void set(Player p, Gears g) {
    		setInventory(p, g);
    		setEquipment(p, g);
    		setStats(p, g);
    		setMisc(p, g);
    		refresh(p);
    	}
    	
    	public static void setGear(Player p, Gears g) {
    		set(p, g);
    	}
    	
    	public static boolean isGearSet(Player p, String type) {
    		for (Gears gear : Gears.values()) {
    			if (gear == null)
    				continue;
    			if (gear.name.toLowerCase().equals(type)) {
    				set(p, gear);
    				return true;
    			}
    		}
    	return false;
    	}
    }
    Calling method; example in Commands
    Code:
    import com.rs.game.player.content.GearCommands.Gears;
    Code:
    			case "gear":
    				String loadouts = "";
    				int count = 0;
    				for (Gears gear : Gears.values()) {
    					count++;
    					loadouts += gear.getName() + (count < Gears.values().length ? ", " : ".");
    				}
    				if (cmd.length >= 2) {
    					if (GearCommands.isGearSet(player, String.valueOf(cmd[1]).toLowerCase()))
    						return true;
    				}
    				player.getPackets().sendGameMessage("Usage: ::gear *type*. Available loadouts: " + loadouts);
    					return true;
    let me know if theres something i could improve

    atm its as easy to use as copy/paste and then simply compose your gear set instance in the Gears enum

    also, it's extremely easy to make the command use a dialogue or an interface, i couldnt be bothered with it tho

    Spoiler for in action:

    [Only registered and activated users can see links. ]

    Last edited by _Andy; 04-28-2014 at 07:42 PM. Reason: lolol
    quit
    Reply With Quote  
     

  2. #2  
    q.q


    Join Date
    Dec 2010
    Posts
    6,535
    Thanks given
    1,072
    Thanks received
    3,534
    Rep Power
    4752
    Code:
    new String ("main2"),
    uh?
    Reply With Quote  
     

  3. #3  
    Registered Member _Andy's Avatar
    Join Date
    May 2013
    Age
    25
    Posts
    644
    Thanks given
    224
    Thanks received
    111
    Rep Power
    4
    Quote Originally Posted by Harlan View Post
    Code:
    new String ("main2"),
    uh?
    yes, the name of the set.
    problem was, that some sets names compose of longer strings and some merely of numbers
    you cant name instance like that

    edit; rofl spotted the mistake
    fixed in op
    quit
    Reply With Quote  
     

  4. #4  
    Strive for whats best.

    Chaz's Avatar
    Join Date
    Jul 2012
    Age
    25
    Posts
    2,506
    Thanks given
    376
    Thanks received
    613
    Rep Power
    170
    Looks neat, good job.
    Reply With Quote  
     

  5. #5  
    Owner Of EradicationX

    Join Date
    Sep 2013
    Posts
    88
    Thanks given
    46
    Thanks received
    11
    Rep Power
    11
    Good Job
    Reply With Quote  
     

  6. #6  
    Donator

    Join Date
    Dec 2012
    Posts
    541
    Thanks given
    42
    Thanks received
    47
    Rep Power
    27
    Good job Andy
    :: Making money is not the point, it is the community that matters in the end. ::
    > Unless your name is Pim or Kevin of course.
    Reply With Quote  
     

  7. #7  
    Registered Member
    Ynneh's Avatar
    Join Date
    Mar 2010
    Posts
    2,204
    Thanks given
    146
    Thanks received
    254
    Discord
    View profile
    Rep Power
    241
    Easy but effective. Why release doe? lol
    Reply With Quote  
     

  8. #8  
    Registered Member
    Join Date
    Nov 2014
    Posts
    9
    Thanks given
    0
    Thanks received
    0
    Rep Power
    0
    Compiling...
    src\com\rs\game\player\content\GearCommands.java:1 40: error: equipSlot has priva
    te access in ItemDefinitions
    player.getEquipment().getItems().set(ItemDefinitio ns.get
    ItemDefinitions(switchedItem).equipSlot, new Item(switchedItem, id[1]));

    ^
    1 error
    Press any key to continue . . . Anyclue?
    Reply With Quote  
     

  9. #9  
    Registered Member

    Join Date
    Oct 2012
    Posts
    1,463
    Thanks given
    560
    Thanks received
    323
    Rep Power
    122
    Nice i like it. Good job.

    “I have not failed. I've just found 10,000 ways that won't work.”
    ― Thomas A. Edison


    [Only registered and activated users can see links. ]


    Reply With Quote  
     

  10. #10  
    Donator


    Join Date
    Jul 2012
    Age
    23
    Posts
    1,954
    Thanks given
    1,035
    Thanks received
    459
    Rep Power
    89
    Quote Originally Posted by IGlitchedObama View Post
    Compiling...
    src\com\rs\game\player\content\GearCommands.java:1 40: error: equipSlot has priva
    te access in ItemDefinitions
    player.getEquipment().getItems().set(ItemDefinitio ns.get
    ItemDefinitions(switchedItem).equipSlot, new Item(switchedItem, id[1]));

    ^
    1 error
    Press any key to continue . . . Anyclue?
    Make equipSlot public instead of private
    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. [MATRIX] Simple IF Statement
    By leviathan recovery in forum Help
    Replies: 4
    Last Post: 11-04-2013, 12:42 AM
  2. Matrix 718 Simple Farming (herb seeds only)
    By Cαleb in forum Snippets
    Replies: 16
    Last Post: 03-12-2013, 10:34 AM
  3. Replies: 1
    Last Post: 01-03-2013, 08:00 PM
  4. Simple Task Manager
    By Lmctruck30 in forum Snippets
    Replies: 5
    Last Post: 08-15-2009, 09:15 AM
  5. Replies: 9
    Last Post: 07-17-2008, 07:53 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
  •