Thread: Rs2-Server Thieving System

Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1 Rs2-Server Thieving System 
    Registered Wizard

    Jesse's Avatar
    Join Date
    Sep 2009
    Age
    29
    Posts
    5,119
    Thanks given
    1,519
    Thanks received
    1,148
    Rep Power
    5000
    This is not the best i plan on redoing it but to show some people how maybe skills can be written

    Credits:

    Abyss
    Jimmy


    Code:
    package org.rs2server.rs2.model.skills;
    
    import java.util.HashMap;
    import java.util.Map;
    import java.util.Random;
    
    import org.rs2server.rs2.action.Action;
    import org.rs2server.rs2.model.Animation;
    import org.rs2server.rs2.model.Graphic;
    import org.rs2server.rs2.model.Hit;
    import org.rs2server.rs2.model.Item;
    import org.rs2server.rs2.model.Mob.InteractionMode;
    import org.rs2server.rs2.model.NPC;
    import org.rs2server.rs2.model.Player;
    import org.rs2server.rs2.model.Skills;
    import org.rs2server.rs2.model.World;
    import org.rs2server.rs2.model.container.Equipment;
    import org.rs2server.rs2.tickable.Tickable;
    
    /**
     * @author Jesse
     */
    
    public class Thieving extends Action {
    	
    	private static final Random thievRandom = new Random();
    	
    	public enum TheivableNpc {
    		
    		MEN(new int[] {1, 3}, 994, 1, 20, 102, 1, 2),
    		
    		WARRIOR(new int[] {15}, 1050, 4, 72, 89, 25, 4);
    
    		private static Map<Integer, TheivableNpc> victims = new HashMap<Integer, TheivableNpc>();
    		
    		public static TheivableNpc forId(int npc) {
    			return victims.get(npc);
    		}
    
    		static {
    			for (TheivableNpc victim : TheivableNpc.values()) {
    				for(int npc : victim.getNpcs()) {
    					victims.put(npc, victim);
    				}
    			}
    		}
    		private final int reward;
    
    		private final int[] npcs;
    
    		private final int damage;
    
    		private final int gloves;
    
    		private final int stopfail;
    
    		private int req;
    
    		private final double exp;
    
    		private TheivableNpc(int[] npcs, int reward, int damage, int gloves, int stopfail, int req, double exp) {
    			this.npcs = npcs;
    			this.reward = reward;
    			this.damage = damage;
    			this.gloves = gloves;
    			this.stopfail = stopfail;
    			this.req = req;
    			this.exp = exp;
    		}
    
    		public int[] getNpcs() {
    			return npcs;
    		}
    
    		public int getReward() {
    			return reward;
    		}
    
    		public int getDamage() {
    			return damage;
    		}
    
    		public int getGloves() {
    			return gloves;
    		}
    
    		public int getStopfail() {
    			return stopfail;
    		}
    
    		public int getReq() {
    			return req;
    		}
    
    		public double getExp() {
    			return exp;
    		}
    	}
    	
    	private final Player player;
    
    	private final TheivableNpc thievable;
    	
    	private NPC npc;
    
    	private int tick;
    	
    	public Thieving(Player player, TheivableNpc thievable, NPC npc) {
    		super(player, 1);
    		this.player = player;
    		this.thievable = thievable;
    		this.npc = npc;
    	}
    
    	@Override
    	public void execute() {
    
    		if (player.getSkills().getLevel(Skills.THIEVING) < thievable.req) {
    			player.getActionSender().sendMessage(
    					"You need a thieving level of  " + thievable.req
    							+ " to thiev this npc.");
    			this.stop();
    			return;
    		}
    		if (player.getCombatState().getLastHitTimer() > System
    				.currentTimeMillis()) {
    			player.getActionSender().sendMessage(
    					"You can't do this while in combat.");
    			return;
    		}
    		tick++;
    		World.getWorld().submit(new Tickable(1) {
    			public void execute() {
    				player.playAnimation(Animation.create(881));
    				player.getActionSender().sendMessage(
    						"You attempt to pick the "
    								+ npc.getDefinition().getName().toLowerCase()
    								+ "'s pocket.");
    				this.stop();
    			}
    		});
    		if (tick >= 1) {
    			World.getWorld().submit(new Tickable(3) {
    				public void execute() {
    					if (isSuccessful()) {
    						player.getActionSender().sendMessage(
    								"You pick the "
    										+ npc.getDefinition().getName()
    												.toLowerCase() + "'s pocket.");
    						player.getInventory().add(new Item(thievable.getReward()));
    						player.getSkills().addExperience(Skills.THIEVING,
    								thievable.getExp());
    					} else {
    						npc.playAnimation(Animation.create(422));
    						npc.forceChat("What do you think you're doing?");
    						player.getActiveCombatAction()
    								.defend(npc, player, true);
    						npc.setInteractingEntity(InteractionMode.TALK, player);
    						player.getActionQueue().clearRemovableActions();
    						player.playGraphics(Graphic.create(80, 0, 100));
    						player.setAttribute("stunned", true);
    						World.getWorld().submit(new Tickable(12) { 
    									public void execute() {
    										player.removeAttribute("stunned");
    										this.stop();
    									}
    								});
    						player.getActionSender().sendMessage(
    								"You fail to pick the "
    										+ npc.getDefinition().getName()
    												.toLowerCase() + "'s pocket.");
    						player.getActionSender().sendMessage(
    								"You've been stunned!");
    						player.inflictDamage(new Hit(thievable.getDamage()), null);
    						this.stop();
    					}
    					this.stop();
    				}
    			});
    		}
    		this.stop();
    	}
    	@Override
    	public CancelPolicy getCancelPolicy() {
    		return CancelPolicy.ALWAYS;
    	}
    
    	@Override
    	public StackPolicy getStackPolicy() {
    		return StackPolicy.NEVER;
    	}
    
    	@Override
    	public AnimationPolicy getAnimationPolicy() {
    		return AnimationPolicy.RESET_ALL;
    	}
    
    	public boolean isSuccessful(){
    		double failBonus = 0.0;
    		int levelReq = thievable.getReq();
    		int Stopfailing = player.getEquipment().getSlotById(Equipment.SLOT_GLOVES) == 10075 ? thievable.getGloves() : thievable.getStopfail();
    
    		double fail_chance = (40.0 - failBonus);
    		double thiev_lvl = (double) player.getSkills().getLevel(Skills.THIEVING);
    		double lev_needed = (double) levelReq;
    		double stop_fail = (double) Stopfailing;
    		double multi_a = (stop_fail - lev_needed);
    		double burn_dec = (fail_chance / multi_a);
    		double multi_b = (thiev_lvl - lev_needed);
    		fail_chance -= (multi_b * burn_dec);
    
    		double randNum = thievRandom.nextDouble() * 100.0;
    		System.out.println("Fail: "+fail_chance);
    		return fail_chance <= randNum;
    	}
    
    	public TheivableNpc getThievable() {
    		return thievable;
    	}
    
    }
    Npcoption

    Code:
    TheivableNpc victim = TheivableNpc.forId(npc.getDefinition().getId());
    			if ((player.getAttribute("stunned") != null)) {
    				player.getActionSender().sendMessage("You're stunned.");
    				return;
    			}
    			if (victim != null)
    				action = new Thieving(player, victim, npc);



    Reply With Quote  
     

  2. Thankful users:


  3. #2  
    Officially Retired

    Huey's Avatar
    Join Date
    Jan 2008
    Age
    22
    Posts
    16,478
    Thanks given
    3,385
    Thanks received
    7,727
    Rep Power
    5000
    good job.
    Attached image
    Listen children don't become this guy.
    Quote Originally Posted by Owner Spikey View Post
    Why can I attack lower level npc's in a matter of a mouse hover but for a higher level npc the only choice to attack is by right clicking option attack?

    Reply With Quote  
     

  4. Thankful user:


  5. #3  
    Banned

    Join Date
    Mar 2011
    Posts
    4,062
    Thanks given
    194
    Thanks received
    689
    Rep Power
    0
    So you would have to create a new enum instance per item you can thieve? Seems like a bad way of handling this
    Reply With Quote  
     

  6. #4  
    Legends Never Die


    Join Date
    Nov 2009
    Posts
    4,289
    Thanks given
    91
    Thanks received
    1,216
    Rep Power
    5000
    Nice job Jesse.
    Reply With Quote  
     

  7. #5  
    Officially Retired

    Huey's Avatar
    Join Date
    Jan 2008
    Age
    22
    Posts
    16,478
    Thanks given
    3,385
    Thanks received
    7,727
    Rep Power
    5000
    Quote Originally Posted by relex lawl View Post
    So you would have to create a new enum instance per item you can thieve? Seems like a bad way of handling this
    Not the best way of doing things, but at-least he's helping out the community and it isn't that hard to fix it up.
    Attached image
    Listen children don't become this guy.
    Quote Originally Posted by Owner Spikey View Post
    Why can I attack lower level npc's in a matter of a mouse hover but for a higher level npc the only choice to attack is by right clicking option attack?

    Reply With Quote  
     

  8. #6  
    Aymen
    Guest
    ┏┓
    ┃┃
    ┃┃┏┫┃┏┳━━┓┏━━┓┃┗━┳━━┳━━┳━━┓
    ┃┃┣┫┗┛┫┃━┫┃┏┓┃┃┏┓┃┏┓┃━━┫━━┫
    ┃┗┫┃┏┓┫┃━┫┃┏┓┃┃┗┛┃┗┛┣━━┣━━┃
    ┗━┻┻┛┗┻━━┛┗┛┗┛┗━━┻━━┻━━┻━━┛


    good job
    Reply With Quote  
     

  9. #7  
    Registered Wizard

    Jesse's Avatar
    Join Date
    Sep 2009
    Age
    29
    Posts
    5,119
    Thanks given
    1,519
    Thanks received
    1,148
    Rep Power
    5000
    Thanks and to relax i said it was not the best ;6



    Reply With Quote  
     

  10. #8  
    Rs2-Server Thieving System



    Scu11's Avatar
    Join Date
    Aug 2007
    Age
    30
    Posts
    16,307
    Thanks given
    7,215
    Thanks received
    12,308
    Rep Power
    5000
    Code:
    			if ((player.getAttribute("stunned") != null)) {
    whats with the extra brackets?

    Attached image
    Reply With Quote  
     

  11. #9  
    Officially Retired

    Huey's Avatar
    Join Date
    Jan 2008
    Age
    22
    Posts
    16,478
    Thanks given
    3,385
    Thanks received
    7,727
    Rep Power
    5000
    Quote Originally Posted by Scu11 View Post
    Code:
    			if ((player.getAttribute("stunned") != null)) {
    whats with the extra brackets?
    More Stability as Sir Tom would say.
    Attached image
    Listen children don't become this guy.
    Quote Originally Posted by Owner Spikey View Post
    Why can I attack lower level npc's in a matter of a mouse hover but for a higher level npc the only choice to attack is by right clicking option attack?

    Reply With Quote  
     

  12. Thankful users:


  13. #10  
    Donator


    Join Date
    Aug 2010
    Posts
    3,174
    Thanks given
    1,724
    Thanks received
    2,002
    Rep Power
    3837
    Ohh god! your sexy
    Rep++
    Reply With Quote  
     

  14. Thankful user:


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. Repost Rs2-server Web system
    By Jesse in forum Snippets
    Replies: 3
    Last Post: 02-04-2012, 12:06 AM
  2. Replies: 14
    Last Post: 11-02-2010, 10:44 PM
  3. Thieving System.
    By d34tht1ck3t in forum Tutorials
    Replies: 12
    Last Post: 04-16-2008, 10:27 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
  •