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] Woodcutting - rewritten


[PI] Woodcutting - 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] Woodcutting - rewritten - 01-24-2012, 12:07 PM

Required PI Tickmanager
Code:
package server.model.players.skills;

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

public class Woodcutting {

	private Client c;

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

	public static enum Hatchet {
		BRONZE(1351, 1, 879),
		IRON(1349, 1, 877),
		STEEL(1353, 6, 875),
		BLACK(1361, 6, 873),
		MITHRIL(1355, 21, 871),
		ADAMANT(1357, 31, 869),
		RUNE(1359, 41, 867),
		DRAGON(6739, 61, 2846);

		private int id, req, anim;

		private Hatchet(int id, int level, int animation) {
			this.id = id;
			this.req = level;
			this.anim = animation;
		}

		public int getId() {
			return id;
		}

		public int getRequiredLevel() {
			return req;
		}

		public int getAnim() {
			return anim;
		}
	}

	private enum Trees {
		NORMAL(1, 25, 1511, new int[] { 1276, 1277, 1278, 1279, 1280, 1282,
				1283, 1284, 1285, 1286, 1289, 1290, 1291, 1315, 1316, 1318,
				1319, 1330, 1331, 1332, 1365, 1383, 1384, 3033, 3034, 3035,
				3036, 3881, 3882, 3883, 5902, 5903, 5904 }, 2, false),
				ACHEY(1, 25, 2862, new int[] { 2023 }, 1, false),
				OAK(15, 38, 1521, new int[] { 1281, 3037 }, 3, true),
				WILLOW(30, 68, 1519, new int[] { 1308, 5551, 5552, 5553 }, 4, true),
				TEAK(35, 85, 6333, new int[] { 9036 }, 4, true),
				DRAMEN(36, 36, 771, new int[] { 1292 }, 2, true),
				MAPLE(45, 100, 1517, new int[] { 1307, 4677 }, 5, true),
				MAHOGANY(50, 158, 6332, new int[] { 9034 }, 6, true),
				YEW(60, 175, 1515, new int[] { 1309 }, 7, true),
				MAGIC(75, 250, 1513, new int[] { 1306 }, 8, true);

		private int[] objects;
		private int req, xp, log, ticks;
		private boolean multi;

		private Trees(int req, int xp, int log, int[] obj, int ticks, boolean multi) {
			this.req = req;
			this.xp = xp;
			this.log = log;
			this.objects = obj;
			this.ticks = ticks;
			this.multi = multi;
		}

		public boolean isMulti() {
			return multi;
		}

		public int getTicks() {
			return ticks;
		}

		public int getReward() {
			return log;
		}

		public int getXp() {
			return xp;
		}

		public int getReq() {
			return req;
		}
	}

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

	public Hatchet forAxe(int id) {
		for (Hatchet h : Hatchet.values()) {
			if (h.getId() == id) {
				return h;
			}
		}
		return null;
	}

	public Trees forTree(int id) {
		for (Trees t : Trees.values()) {
			for (int obj : t.objects) {
				if (obj == id) {
					return t;
				}
			}
		}
		return null;
	}
	
	public void test() {
		World.getWorld().submit(new Tick(3) {
			@Override
			public void execute() {
				int cycle = 0;
				if (cycle != 3) {
					cycle++;
				}
				if (cycle == 3) {
					System.out.println("Hi!");
					cycle = 0;
					this.stop();
				}
			}
		});
	}

	public void cutWood(final int objId) {
		final Hatchet h = forAxe(hasHatchet());
		if (h != null) {
			if (c.playerLevel[c.playerWoodcutting] >= h.getRequiredLevel()) {
				final Trees t = forTree(objId);
				if (t != null) {
					if (c.playerLevel[c.playerWoodcutting] >= t.getReq()) {
						c.startAnimation(h.getAnim());
						World.getWorld().submit(new Tick(t.getTicks()) {
							@Override
							public void execute() {
								int cycle = 0;
								int reqCycle = Misc.random(t.getTicks());
								if (cycle != reqCycle) {
									cycle++;
									c.startAnimation(h.getAnim());
								}
								if (cycle == reqCycle) {
									c.getItems().addItem(t.getReward(), 1);
									c.getPA().addSkillXP(t.getXp(), c.playerWoodcutting);
									c.getPA().refreshSkill(c.playerWoodcutting);
									c.sendMessage("You cut a log.");
									c.getPA().resetAnimation();
									c.getPA().resetVariables();
									c.startAnimation(65535);
									cycle = 0;
									if (!t.isMulti()) {
										this.stop();
									} else {
										cutWood(objId);
									}
								}
							}
						});
					} else {
						c.sendMessage("You do not have a high enough woodcutting level to cut this tree.");
					}
				}
			} else {
				c.sendMessage("You do not have a hatchet that you can use.");
			}
		} else {
			c.sendMessage("You do not have a hatchet that you can use.");
		}
	}
}
In client.java's process method, remove this:
Code:
if (wcTimer > 0 && woodcut[0] > 0) {
			wcTimer--;
		} else if (wcTimer == 0 && woodcut[0] > 0) {
			getWoodcutting().cutWood();
Make sure to change
Code:
 } else if (smeltTimer
to
Code:
 if (smeltTimer
.

Add this in Walking.java under
Code:
	public void processPacket(Client c, int packetType, int packetSize) {
:
Code:
		if (!World.getWorld().getTickManager().getTickables().isEmpty()) {
			World.getWorld().getTickManager().getTickables().clear();
		}
(This prevents crashes when you walk away while an event is still in progress)

ActionHandler.java:

Replace
Code:
case 1276:
		case 1278:// trees
			// c.sendMessage("You chop the tree.");
			
			 * Woodcutting object respawning etc. by lmtruck... making my own -
			 * look at this for example Objects stump = new Objects(1343,
			 * c.objectX, c.objectY, 0, -1, 10, 0);
			 * Server.objectHandler.addObject(stump);
			 * Server.objectHandler.placeObject(stump); Objects tree = new
			 * Objects(c.objectId, c.objectX, c.objectY, 0, -1, 10, 7);
			 * Server.objectHandler.addObject(tree);
			 
			// c.treeId = objectType;
			c.woodcut[0] = 1511;
			c.woodcut[1] = 1;
			c.woodcut[2] = 25;
			c.getWoodcutting().startWoodcutting(c.woodcut[0], c.woodcut[1],
					c.woodcut[2]);
			break;

		case 1281: // oak
			c.woodcut[0] = 1521;
			c.woodcut[1] = 15;
			c.woodcut[2] = 37;
			c.getWoodcutting().startWoodcutting(c.woodcut[0], c.woodcut[1],
					c.woodcut[2]);
			break;

		case 1308: // willow
			c.woodcut[0] = 1519;
			c.woodcut[1] = 30;
			c.woodcut[2] = 68;
			c.getWoodcutting().startWoodcutting(c.woodcut[0], c.woodcut[1],
					c.woodcut[2]);
			break;

		case 1307: // maple
			c.woodcut[0] = 1517;
			c.woodcut[1] = 45;
			c.woodcut[2] = 100;
			c.getWoodcutting().startWoodcutting(c.woodcut[0], c.woodcut[1],
					c.woodcut[2]);
			break;

		case 1309: // yew
			c.woodcut[0] = 1515;
			c.woodcut[1] = 60;
			c.woodcut[2] = 175;
			c.getWoodcutting().startWoodcutting(c.woodcut[0], c.woodcut[1],
					c.woodcut[2]);
			break;

		case 1306: // yew
			c.woodcut[0] = 1513;
			c.woodcut[1] = 75;
			c.woodcut[2] = 250;
			c.getWoodcutting().startWoodcutting(c.woodcut[0], c.woodcut[1],
					c.woodcut[2]);
			break;
With:
Code:
		case 1276:
		case 1278:
		case 1281:
		case 1308:
		case 1307:
		case 1309:
		case 1306:
			c.getWoodcutting().cutWood(objectType);
			break;
Flaws
-Doesn't prioritize axes (will take the inventory axe over the equipment axe)
-No stump support


Good things
-Support for single log trees (normal/achey trees), and multi log trees (oak, willow, maple, yew, magic, etc.)
-Time per log different per tree.

CREDITS
Scu11 - Hyperion woodcutting base
Me - putting it all together & converting to PI (not that hard)




~Flow@hacking.rs
  
Old
  (#2 (permalink))
M1rcast is Offline
Senior Member
image
 
M1rcast's Avatar
 
Posts: 140
Cookies Given: 0
Cookies Received: 0
Time Online: 4 d 16 h 59 m
   
Default 02-17-2012, 07:25 PM

This isn't locked? But it's past 14 days so this is grave digging, oh no, the horror.

gimme another infraction brandon u bitch


x
  
adsense code2.3
Closed Thread

Bookmarks

[PI] Woodcutting - 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 10:36 AM.





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