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] Mining - rewritten.


[PI] Mining - 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] Mining - rewritten. - 01-24-2012, 12:14 PM

Code:
package server.model.players.skills;

import server.World;
import server.model.players.Client;
import server.tick.Tick;
import server.util.Misc;

public class Mining {

	private Client c;

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

	private final int[] RANDOM_GEMS = {1623,1621,1619,1617,1631};

	private enum Pickaxe {

		Bronze(1265, 1, 625, 1.0),
		Iron(1267, 1, 626, 1.05),
		Steel(1269, 6, 627, 1.1),
		Mithril(1273, 21, 628, 1.2),
		Adamant(1271, 31, 629, 1.25),
		Rune(1275, 41, 624, 1.3),
		Dragon(15259, 61, 12188, 1.50);

		private int id, req, anim;

		private Pickaxe(int id, int req, int anim, double speed) {
			this.id = id;
			this.req = req;
			this.anim = anim;
		}

		public int getId() {
			return id;
		}
		public int getReq(){
			return req;
		}

		public int getAnim(){
			return anim;
		}
	}

	public enum Ores {

		Copper(new int[]{31080, 31081, 31082, 2090, 2091, 9708}, 1, 175, 436, 2, 4),
		Tin(new int[]{31077, 31078, 2094, 2095, 9714}, 1, 175, 438, 2, 4),
		Iron(new int[]{31071, 31072, 31073, 2093, 2092, 9717}, 15, 350, 440, 2, 5),
		Coal(new int[]{31068, 31069, 31070, 2096, 2097, 14850, 452, 450}, 30, 500, 453, 3, 7),
		Gold(new int[]{31065, 31066, 9720, 2098, 2099}, 40, 650, 444, 3, 10),
		Mithril(new int[]{31086, 31088, 2103, 2102, 14853}, 50, 800, 447, 4, 11),
		Adamantite(new int[]{31083, 31085, 14862, 2104, 2105}, 70, 950, 449, 4, 13),
		Runite(new int[]{14859, 4860, 2106, 2107}, 85, 1250, 451, 5, 15);


		private int objid[];
		private int itemid, req, xp, ticks, respawnTimer;

		private Ores(int[] objid, int req, int xp, int itemid, int ticks, int respawnTimer) {
			this.objid = objid;
			this.req = req;
			this.xp = xp;
			this.itemid = itemid;
			this.ticks = ticks;
			this.respawnTimer = respawnTimer;
		}

		public int getRespawn() {
			return respawnTimer;
		}

		public int getLevelReq(){
			return req;
		}

		public int getXpAmount(){
			return xp;
		}

		public int getItemId(){
			return itemid;
		}

		public int getTicks() {
			return ticks;
		}
	}

	public Ores forRock(int id) {
		for (Ores ore : Ores.values()) {
			for (int obj : ore.objid) {
				if (obj == id) {
					return ore;
				}
			}
		}
		return null;
	}

	public Pickaxe forPick(int id) {
		for (Pickaxe p : Pickaxe.values()) {
			if (p.getId() == id) {
				return p;
			}
		}
		return null;
	}

	private int hasPickaxe() {
		for (Pickaxe p : Pickaxe.values()) {
			if (c.playerEquipment[c.playerWeapon] == p.getId()) {
				return p.getId();
			} else if (c.getItems().playerHasItem(p.getId())) {
				return p.getId();
			}
		}
		return -1;
	}

	/*public void respawnRock(int rockId) {
		final int curObjX = c.objectX;
		final int curObjY = c.objectY;
		final int curObjId = c.objectId;
		for (int i = 0; i < Server.playerHandler.players.length; i++) {
			final Client c2 = (Client) Server.playerHandler.players[i];
			if (c2 != null) {
				c2.getPA().object(450, curObjX, curObjY, 0, 10);
			}
			final Ores o = forRock(rockId);
			if (o != null) {
				World.getWorld().submit(new Tick(5) {
					@Override
					public void execute() {
						int cycle = 0;
						if (cycle <= 5) {
							cycle++;
						}
						if (cycle == 5) {
							c2.getPA().object(curObjId, curObjX, curObjY, 0, 10);
							this.stop();
						}
					}
				});
			}
		}
	}*/

	public void startMining(final int objid) {
		final Ores o = forRock(objid);
		final int reqCycle = Misc.random(o.getTicks() - 1);
		if (o != null) {
			if (hasPickaxe() > 0) {
				if (c.playerLevel[c.playerMining] >= o.getLevelReq()) {
					final Pickaxe p = forPick(hasPickaxe());
					if (c.playerLevel[c.playerMining] >= p.getReq()) {
						c.startAnimation(p.getAnim());
						World.getWorld().submit(new Tick(o.getTicks()) {
							@Override
							public void execute() {
								int cycle = 0;
								if (cycle != reqCycle) {
									cycle++;
									c.startAnimation(p.getAnim());
								}
								if (Misc.random(25) == 17) {
									c.getItems().addItem(RANDOM_GEMS[(int)(RANDOM_GEMS.length * Math.random())], 1);
									c.sendMessage("You find a gem!");
								}
								if (cycle == reqCycle) {
									c.getItems().addItem(o.getItemId(), 1);
									c.getPA().addSkillXP(o.getXpAmount(), c.playerMining);
									c.getPA().refreshSkill(c.playerMining);
									c.sendMessage("You mine a ore.");
									//respawnRock(objid);
									c.getPA().resetAnimation();
									c.getPA().resetVariables();
									c.startAnimation(65535);
									cycle = 0;
									this.stop();
								}
							}
						});
					} else {
						c.sendMessage("You need a mining level of at least "+p.getReq()+" to use this pickaxe.");
					}
				} else {
					c.sendMessage("You need a mining level of at least "+o.getLevelReq()+" to mine this rock.");
				}
			} else {
				c.sendMessage("You don't have a pickaxe to mine this rock with.");
			}
		}
	}

	private enum Prospect {

		Copper(new int[] {31080, 31081, 31082, 2090, 2091, 9708}, "copper"),
		Tin(new int[] {31077, 31078, 2094, 2095, 9714}, "tin"),
		Iron(new int[] {31071, 31072, 31073, 2093, 2092, 9717}, "iron"),
		Coal(new int[] {31068, 31069, 31070, 2096, 2097, 14850, 452, 450}, "coal"),
		Gold(new int[] {31065, 31066, 9720, 2098, 2099}, "gold"),
		Mithril(new int[] {31086, 31088, 2103, 2102, 14853}, "mithril"),
		Adamantite(new int[] {31083, 31085, 14862, 2104, 2105}, "adamant"),
		Runite(new int[] {14859, 4860, 2106, 2107}, "rune");

		private int[] objId;
		private String oreName;
		private Prospect(int[] objId, String oreName) {
			this.objId = objId;
			this.oreName = oreName;
		}

		public String oreName() {
			return oreName;
		}
	}

	public Prospect forObj(int id) {
		for (Prospect l : Prospect.values()) {
			for (int obj : l.objId) {
				if (id == obj) {
					return l;
				}
			}
		}
		return null;
	}

	public void prospectOre(int oreID) {
		final Prospect p = forObj(oreID);
		if (p != null) {
			c.sendMessage("You prospect the rock..");
			World.getWorld().submit(new Tick(2) {
				@Override
				public void execute() {
					int pcycle = 0;
					if (pcycle == 1) {
						c.sendMessage("The rock contains "+p.oreName()+" ore.");
						pcycle = 0;
						this.stop();
					}
					pcycle++;
				}
			});
		}
	}
}
As you may see I rewrote mining and uses enums and shit (not that I know what those are good for), and I added a "speed" for pickaxes, but it's currently not working as I don't know how I would go on about that. Just so you know and you may try to do it yourself




~[email protected]
  
adsense code2.3
Closed Thread

Bookmarks

[PI] Mining - 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.