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


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

Required PI Tickmanager

Code:
package server.model.players.skills;

import java.security.SecureRandom;

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

public class Cooking {

	SecureRandom cookingRandom = new SecureRandom();
	Client c;

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

	public enum Cook {

		SHRIMP(317, 315, 7954, 1, 30, 33),
		ANCHOVIES(321, 319, 323, 5, 45, 34),
		TROUT(335, 333, 343, 20, 70, 50),
		SALMON(331, 329, 343, 30, 90, 58),
		PIKE(359, 361, 35, 343, 100, 64),
		LOBSTER(377, 379, 381, 40, 120, 74),
		SWORDFISH(371, 373, 375, 50, 140, 86),
		MONKFISH(7944, 7946, 7948, 62, 150, 91),
		SHARK(383, 385, 387, 80, 210, 94),
		MANTA_RAY(389, 391, 393, 91, 169, 99);

		int raw, cooked, burnt, levelReq, xp, stopBurn;

		private Cook(int raw, int cooked, int burnt, int levelReq, int xp, int stopBurn) {
			this.raw = raw;
			this.cooked = cooked;
			this.burnt = burnt;
			this.levelReq = levelReq;
			this.xp = xp;
			this.stopBurn = stopBurn;
		}

		public int getRaw() {
			return raw;
		}

		public int getCooked() {
			return cooked;
		}

		public int getBurnt() {
			return burnt;
		}

		public int getLevelReq() {
			return levelReq;
		}

		public int getXp() {
			return xp;
		}

		public int getStopBurn() {
			return stopBurn;
		}
	}

	public Cook forId(int id) {
		for (Cook co : Cook.values()) {
			if (co.getRaw() == id)
				return co;
		}
		return null;
	}
	
	private boolean getSuccess(int burnBonus, int levelReq, int stopBurn) {
		if (c.playerLevel[c.playerCooking] >= stopBurn) {
			return false;
		}
		double burn_chance = (55.0 - burnBonus); //52
		double cook_level = c.playerLevel[c.playerCooking]; //99
		double lev_needed = (double) levelReq; // 78
		double burn_stop = (double) stopBurn; //
		double multi_a = (burn_stop - lev_needed);
		double burn_dec = (burn_chance / multi_a);
		double multi_b = (cook_level - lev_needed);
		burn_chance -= (multi_b * burn_dec);
		double randNum = cookingRandom.nextDouble() * 100.0;
		return burn_chance <= randNum;
	}

	public void cookFish(int id) {
		final Cook co = forId(id);
		if (co != null)
			if (c.getItems().playerHasItem(co.getRaw(), 1)) {
				if (c.playerLevel[c.playerCooking] >= co.getLevelReq()) {
					World.getWorld().submit(new Tick(1) {
						@Override
						public void execute() {
							if (System.currentTimeMillis() - c.cookTimer > 2400 && c.getItems().playerHasItem(co.getRaw(), 1)) {
								boolean burn = getSuccess(3, co.getLevelReq(), co.getStopBurn());
								c.getItems().deleteItem(co.getRaw(), 1);
								c.getItems().addItem(burn ? co.getBurnt() : co.getCooked(), 1);
								c.sendMessage(burn ? "You accidently burnt the fish." : "You cooked the fish.");
								c.startAnimation(883);
								c.cookTimer = System.currentTimeMillis();
								if (!burn) {
									c.getPA().addSkillXP(co.getXp(), c.playerCooking);
								}
								if (c.getItems().playerHasItem(co.getRaw(), 1)) {
									cookFish(co.getRaw());
								} else {
									this.stop();
								}
							}
						}
					});
				}
			}
	}
}
In player.java declare:

Code:
public long cookTimer;
Should work fine, I haven't encountered any bugs!





~[email protected]
  
adsense code2.3
Closed Thread

Bookmarks

[PI] Cooking - 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 12:01 AM.





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