SilabGarza - RS Private Server  
Home Forum Play Register Store Market Highscores Mark Forums Read
Go Back   SilabGarza - RS Private Server > SilGar Media > Computers > Programming
Reload this Page [PI] Thieving - rewritten.


[PI] Thieving - rewritten.
Old
  (#1 (permalink))
phl0w is Offline
ARE YOU MAD?
image
 
phl0w's Avatar
 
Posts: 59
Cookies Given: 0
Cookies Received: 0
Time Online: 20 h 55 m
   
Default [PI] Thieving - rewritten. - 01-24-2012, 12:05 PM

Code:
package server.model.players.skills;

import java.security.SecureRandom;

import server.model.players.Client;
import server.util.Misc;
/**
 * Thieving.java
 *
 * @author Flow
 *
 **/

public class Thieving {

	private Client c;
	SecureRandom random = new SecureRandom();

	public Thieving(Client c) {
		this.c = c;
	}

	private enum NPC {
		MAN(1, 1, 8, 200, 1),
		ALKHARID_WARRIOR(18, 25, 26, 500, 1),
		GUARD(9, 40, 47, 1000, 2),
		ARDOUGNE_KNIGHT(26, 55, 85, 1500, 3),
		PALADIN(20, 70, 152, 2000, 4),
		HERO(21, 80, 273, 3000, 5);

		private int NPC, levelReq, XP, reward, damage;

		private NPC(int NPC, int levelReq, int XP, int reward, int damage) {
			this.NPC = NPC;
			this.levelReq = levelReq;
			this.XP = XP;
			this.reward = reward;
			this.damage = damage;
		}

		public int getNPC() {
			return NPC;
		}

		public int getReq() {
			return levelReq;
		}

		public int getXP() {
			return XP;
		}

		public int getReward() {
			return reward;
		}

		public int getDamage() {
			return damage;
		}
	}

	private NPC forNpc(int id) {
		for (NPC n : NPC.values()) {
			if (n.getNPC() == id) {
				return n;
			}
		}
		return null;
	}

	public void stealFromNPC(int id) {
		if (System.currentTimeMillis() - c.lastThieve < 2000)
			return;
		NPC v = forNpc(id);
		if (v != null) {
			if (c.playerLevel[c.playerThieving] >= v.getReq()) {
				if (!randomFail(v.getReq())) {
					c.getItems().addItem(995, v.getReward());
					c.getPA().addSkillXP(v.getXP(), c.playerThieving);
					c.startAnimation(881);
					c.lastThieve = System.currentTimeMillis();
					c.sendMessage("You pickpocket the NPC.");
				} else {
					c.setHitDiff(v.getDamage());
					c.setHitUpdateRequired(true);
					c.playerLevel[c.playerHitpoints] -= v.getDamage();
					c.gfx100(254);
					c.lastThieve = System.currentTimeMillis() + 2000;
					c.sendMessage("You fail to pickpocket the NPC.");
				}
			} else {
				c.sendMessage("You don't have a high enough thieving level to pickpocket this NPC.");
			}
		}
	}
	
	public boolean randomFail(int levelReq) {
		return c.playerLevel[c.playerThieving] - levelReq + getEquipmentBonus() < Misc.random(levelReq);
	}

	private int getEquipmentBonus() {
		return c.playerEquipment[c.playerHands] == 10075 ? 5 : 0;
	}

	public static StallData forStall(int id) {
		for (StallData sd : StallData.values()) {
			if (sd.getObjId() == id) {
				return sd;
			}
		}
		return null;
	}

	public static int getRandom(int stall) {
		StallData sd = forStall(stall);
		return sd.getReward()[(int)(sd.getReward().length * Math.random())];
	}
	private enum StallData {
		BAKER(2561, new int[]{1897}, 16, 5),
		SILK(2560, new int[]{950}, 24, 20),
		FUR(2563, new int[]{7680}, 36, 35),
		SPICE(2564, new int[]{1613}, 81, 65),
		GEM(2562, new int[]{1623, 1621, 1619, 1617, 1631}, 160, 75);

		private int objId, xp, level;
		private int[] reward;

		private StallData(int objId, int[] id, int xp, int level) {
			this.objId = objId;
			this.reward = id;
			this.xp = xp;
			this.level = level;
		}

		public int getObjId() {
			return objId;
		}

		public int[] getReward() {
			return reward;
		}

		public int getXP() {
			return xp;
		}

		public int getLevel() {
			return level;
		}
	}

	public void stealFromStall(int stall) {
		if (System.currentTimeMillis() - c.lastThieve > 2000) {
			StallData sd = forStall(stall);
			if (sd != null) {
				if (c.playerLevel[c.playerThieving] >= sd.getLevel()) {
					c.getItems().addItem(getRandom(stall), 1);
					c.startAnimation(832);
					c.getPA().addSkillXP(sd.getXP(), c.playerThieving);
					c.lastThieve = System.currentTimeMillis();
					c.sendMessage("You steal from the stall.");
				} else {
					c.sendMessage("You need a thieving level of at least "+sd.getLevel()+" to steal from this stall.");
				}
			}
		}
	}
}




~[email protected]
  
adsense code2.3
Closed Thread

Bookmarks

[PI] Thieving - rewritten.

Programming




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
adsense2.6
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -7. The time now is 06:34 PM.





Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2017, vBulletin Solutions, Inc.