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] Best farming ever released


[PI] Best farming ever released
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] Best farming ever released - 01-24-2012, 12:18 PM

Farming.java:
Code:
package server.model.players.skills;

import server.model.players.Client;
import server.model.players.Patch;
import server.util.Misc;

/**
 * Farming.java
 *
 * @author Flow
 *
 **/

public class Farming {

	private Client c;

	private enum Farming_Data {

		GUAM(5291, 199, 11, 13, 1),
		MARRENTIL(5292, 201, 14, 15, 14),
		TARROMIN(5293, 203, 16, 18, 19),
		HARRALANDER(5294, 205, 22, 24, 26),
		RANARR(5295, 207, 27, 31, 32),
		TOADFLAX(5296, 3049, 34, 39, 38),
		IRIT(5297, 209, 43, 49, 44),
		AVANTOE(5298, 211, 55, 62, 50),
		KWUARM(5299, 213, 69, 78, 56),
		SNAPDRAGON(5300, 3051, 88, 99, 62),
		CADANTINE(5301, 215, 107, 120, 67),
		LANTADYME(5302, 2485, 135, 152, 73),
		DWARF_WEED(5303, 217, 171, 192, 79),
		TORSTOL(5304, 219, 200, 225, 85);

		private int seedId, produce, plantXP, herbXP, req;
		private Farming_Data(int seedId, int produce, int plantXP, int herbXP, int req) {
			this.seedId = seedId;
			this.produce = produce;
			this.plantXP = plantXP;
			this.herbXP = herbXP;
			this.req = req;
		}

		public int getSeed() {
			return seedId;
		}

		public int getReq() {
			return req;
		}

		public int getProduce() {
			return produce;
		}

		public int getPlantXP() {
			return plantXP;
		}

		public int getHerbXP() {
			return herbXP;
		}
	}

	private Patch[] p = new Patch[5];

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

	public int getNearestFreePatch() {
		for (int i = 0; i < p.length; i++) {
			if (p[i] == null) {
				return i;
			}
		}
		return -1;
	}

	public void setPatchInfo(int produce, int xp) {
		int nearest = getNearestFreePatch();
		if (getNearestFreePatch() > -1) {
			if (c.getPA().itemUsedInRegion(2809, 2812, 3335, 3338)) { //Entrana patch
				p[nearest] = new Patch(2809, 2812, 3335, 3338, new int[] {2812, 3338}, produce, Misc.random(12), xp);
			}
		}
	}

	public static Farming_Data forSeed(int seed) {
		for (Farming_Data fd : Farming_Data.values()) {
			if (fd.getSeed() == seed) {
				return fd;
			}
		}
		return null;
	}

	public void checkItemOnObject(int itemId) {
		Farming_Data fd = forSeed(itemId);
		if (fd != null) {
			handleFarming(fd);
		}
		return;
	}

	private void handleFarming(Farming_Data f) {
		if (c.playerLevel[c.playerFarming] >= f.getReq()) {
			if (c.getItems().playerHasItem(f.getSeed(), 1)) {
				c.getItems().deleteItem(f.getSeed(), c.getItems().getItemSlot(f.getSeed()), 1);
				c.getPA().addSkillXP(f.getPlantXP(), c.playerFarming);
				c.getPA().refreshSkill(c.playerFarming);
				setPatchInfo(f.getProduce(), f.getHerbXP());
				updatePatch();
				c.sendMessage("You plant the seed.");
			}
		} else {
			c.sendMessage("You need a farming level of "+f.getReq()+" to plant this seed.");
		}
	}

	public int getPatch() {
		for (int i = 0; i < p.length; i++) {
			if (c.getPA().itemUsedInRegion(p[i].minX, p[i].maxX, p[i].minY, p[i].maxY)) {
				return i;
			}
		}
		return -1;
	}

	public void updatePatch() {
		if (p != null) {
			if (getPatch() > -1) {
				if (p[getPatch()].getProduceAmount() > 0) {
					c.getPA().handleObjectRegion(-1, p[getPatch()].minX, p[getPatch()].minY, p[getPatch()].maxX, p[getPatch()].maxY);
					c.getPA().object(8143, p[getPatch()].produceSpot[0], p[getPatch()].produceSpot[1], -1, 10);
				} else {
					c.getPA().handleObjectRegion(8174, p[getPatch()].getMinX(), p[getPatch()].getMinY(), p[getPatch()].getMaxX(), p[getPatch()].getMaxY());
					resetVariables(p[getPatch()]);
				}
			}
		}
	}

	public void pickHerb() {
		if (p[getPatch()].getProduceAmount() > 0) {
			if (c.getItems().freeSlots() > 0) {
				c.startAnimation(2273);
				c.getItems().addItem(p[getPatch()].getProduce(), 1);
				c.getPA().addSkillXP(p[getPatch()].getPickXP(), c.playerFarming);
				p[getPatch()].produceAmount--;
				c.sendMessage("You pick a herb.");
				updatePatch();
				c.getPA().resetAnimation();
			} else {
				c.sendMessage("You do not have enough inventory space to pick this herb.");
			}
		}
	}

	public void resetVariables(Patch p) {
		p.minX = -1;
		p.maxX = -1;
		p.minY = -1;
		p.maxY = -1;
		p.produce = -1;
		p.produceAmount = -1;
		p.produceSpot = new int[]{-1, -1};
		p.pickXP = -1;
		p = null;
	}
}
Patch.java: (server.model.players)
Code:
package server.model.players;

public class Patch {

	public int minX = -1, maxX = -1, minY = -1, maxY = -1, produce = -1, produceAmount = -1, pickXP = -1;
	public int[] produceSpot = new int[2];
	
	public Patch(int minX, int maxX, int minY, int maxY, int[] produceSpot, int produce, int produceAmount, int pickXP) {
		this.minX = minX;
		this.maxX = maxX;
		this.minY = minY;
		this.maxY = maxY;
		this.produceSpot = produceSpot;
		this.produce = produce;
		this.produceAmount = produceAmount;
		this.pickXP = pickXP;
	}
	
	public int getMinX() {
		return minX;
	}
	
	public int getMaxX() {
		return maxX;
	}
	
	public int getMinY() {
		return minY;
	}
	
	public int getMaxY() {
		return maxY;
	}
	
	public int getProduceSpot(int i) {
		return produceSpot[i];
	}
	
	public int getProduce() {
		return produce;
	}
	
	public int getProduceAmount() {
		return produceAmount;
	}
	
	public int getPickXP() {
		return pickXP;
	}
}
Add these two methods to playerassistant.java:
Code:
	public void handleObjectRegion(int objectId, int minX, int minY, int maxX, int maxY) {
		for (int i = minX; i < maxX+1; i++) {
			for (int j = minY; j < maxY+1; j++) {
				c.getPA().object(objectId, i, j, -1, 10);
			}
		}
	}
	
	public boolean itemUsedInRegion(int minX, int maxX, int minY, int maxY) {
		return (c.objectX >= minX && c.objectX <= maxX) && (c.objectY >= minY && c.objectY <= maxY);
	}
ItemOnObject.java:
Add
Code:
		c.objectX = objectX;
		c.objectY = objectY;
if you didn't already have that.

UseItem.java:

Add
Code:
			case 8151:
			case 8389:
			case 8174:
				c.getFarming().checkItemOnObject(itemId);
			break;
If you didn't already have that.

Good luck.
Configuring new patches isn't hard, just follow what I did with Entrana.




~[email protected]
  
adsense code2.3
Closed Thread

Bookmarks

[PI] Best farming ever released

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 12:01 AM.





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