Originally Posted by
'Jimmy
Alright, I'll release a little bit of the code just so everyone will shutup about how we're not even doing anything.
Code:
package org.hyperion.rs2.action.impl;
import java.util.Random;
import org.hyperion.rs2.ScriptManager;
import org.hyperion.rs2.action.Action;
import org.hyperion.rs2.content.quest.impl.TutorialIsland;
import org.hyperion.rs2.content.skills.news.Cooking.CookingItem;
import org.hyperion.rs2.content.skills.news.Cooking.HeatSource;
import org.hyperion.rs2.model.Player;
import org.hyperion.rs2.model.Skills;
/**
*
* @author Jimmy
* @author Clifton - Success rate formula
*/
public class CookingAction extends Action {
private Player player;
private HeatSource heatSource;
private CookingItem cookingItem;
private int productionAmount;
private int fourTickDelay;
public CookingAction(Player player, HeatSource heatSource, CookingItem cookingItem, int productionAmount) {
super(player, 600);
this.player = player;
this.heatSource = heatSource;
this.cookingItem = cookingItem;
this.productionAmount = productionAmount;
player.playAnimation(heatSource.getAnimation());
player.getAttributes().put("cooking", null);
player.getActionSender().sendCloseInterface();
}
public CookingAction(Player player, HeatSource heatSource, CookingItem cookingItem) {
super(player, 600);
this.player = player;
this.heatSource = heatSource;
this.cookingItem = cookingItem;
this.productionAmount = 1;
player.playAnimation(heatSource.getAnimation());
player.getAttributes().put("cooking", null);
}
private boolean isSuccessful() {
double burnBonus = 0.0;
if(heatSource == HeatSource.STOVE)
burnBonus = 3.0;
double burn_chance = (45.0 - burnBonus);
double cook_level = (double) player.getSkills().getLevel(Skills.COOKING);
double lev_needed = (double) cookingItem.getRequiredLevel();
double burn_stop = (double) cookingItem.getBurnStopLevel();
if(player.getEquipment().contains(775))
burn_stop = (double) cookingItem.getBurnStopLevelWith();
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);
Random random = new Random();
double randNum = random.nextDouble() * 100.0;
return burn_chance <= randNum;
}
@Override
public void execute() {
if(!player.getInventory().contains(cookingItem.getRawItem()) ||
productionAmount < 1) {
this.stop();
return;
}
fourTickDelay++;
if(fourTickDelay % 4 != 0)
return;
if(productionAmount > 1)
player.playAnimation(heatSource.getAnimation());
productionAmount--;
player.getInventory().remove(cookingItem.getRawItem());
if(TutorialIsland.getStage(player) == 7 || TutorialIsland.getStage(player) != 8 &&
isSuccessful()) {
player.getInventory().add(cookingItem.getCookedItem());
player.getActionSender().sendMessage("You successfully cook the " +
cookingItem.getCookedItem().getDefinition().getName() + ".");
player.getSkills().addExperience(Skills.COOKING, cookingItem.getExperience());
} else {
player.getInventory().add(cookingItem.getBurntItem());
player.getActionSender().sendMessage("You accidently burn the " +
cookingItem.getCookedItem().getDefinition().getName() + ".");
}
if(TutorialIsland.getStage(player) == 7 || TutorialIsland.getStage(player) == 8) {
ScriptManager.getScriptManager().invokeWithFailTest("tutEndCooking", player);
this.stop();
}
}
@Override
public QueuePolicy getQueuePolicy() {
return QueuePolicy.NEVER;
}
@Override
public WalkablePolicy getWalkablePolicy() {
return WalkablePolicy.NON_WALKABLE;
}
}
Lmfao.
Ok lets go through that, removing Clifton's work first
Code:
package org.hyperion.rs2.action.impl;
import java.util.Random;
import org.hyperion.rs2.ScriptManager;
import org.hyperion.rs2.action.Action;
import org.hyperion.rs2.content.quest.impl.TutorialIsland;
import org.hyperion.rs2.content.skills.news.Cooking.CookingItem;
import org.hyperion.rs2.content.skills.news.Cooking.HeatSource;
import org.hyperion.rs2.model.Player;
import org.hyperion.rs2.model.Skills;
/**
*
* @author Jimmy
* @author Clifton - Success rate formula
*/
public class CookingAction extends Action {
private Player player;
private HeatSource heatSource;
private CookingItem cookingItem;
private int productionAmount;
private int fourTickDelay;
public CookingAction(Player player, HeatSource heatSource, CookingItem cookingItem, int productionAmount) {
super(player, 600);
this.player = player;
this.heatSource = heatSource;
this.cookingItem = cookingItem;
this.productionAmount = productionAmount;
player.playAnimation(heatSource.getAnimation());
player.getAttributes().put("cooking", null);
player.getActionSender().sendCloseInterface();
}
public CookingAction(Player player, HeatSource heatSource, CookingItem cookingItem) {
super(player, 600);
this.player = player;
this.heatSource = heatSource;
this.cookingItem = cookingItem;
this.productionAmount = 1;
player.playAnimation(heatSource.getAnimation());
player.getAttributes().put("cooking", null);
}
@Override
public void execute() {
if(!player.getInventory().contains(cookingItem.getRawItem()) ||
productionAmount < 1) {
this.stop();
return;
}
fourTickDelay++;
if(fourTickDelay % 4 != 0)
return;
if(productionAmount > 1)
player.playAnimation(heatSource.getAnimation());
productionAmount--;
player.getInventory().remove(cookingItem.getRawItem());
if(TutorialIsland.getStage(player) == 7 || TutorialIsland.getStage(player) != 8 &&
isSuccessful()) {
player.getInventory().add(cookingItem.getCookedItem());
player.getActionSender().sendMessage("You successfully cook the " +
cookingItem.getCookedItem().getDefinition().getName() + ".");
player.getSkills().addExperience(Skills.COOKING, cookingItem.getExperience());
} else {
player.getInventory().add(cookingItem.getBurntItem());
player.getActionSender().sendMessage("You accidently burn the " +
cookingItem.getCookedItem().getDefinition().getName() + ".");
}
if(TutorialIsland.getStage(player) == 7 || TutorialIsland.getStage(player) == 8) {
ScriptManager.getScriptManager().invokeWithFailTest("tutEndCooking", player);
this.stop();
}
}
@Override
public QueuePolicy getQueuePolicy() {
return QueuePolicy.NEVER;
}
@Override
public WalkablePolicy getWalkablePolicy() {
return WalkablePolicy.NON_WALKABLE;
}
}
how is that better than the original PJA code, which you called "shit"
Code:
private static class CookingAction extends Action {
/**
* The cooking animations.
*/
private static final Animation RANGE_ANIMATION = Animation.create(896);
private static final Animation FIRE_ANIMATION = Animation.create(897);
/**
* The cooking event constructor.
* @param player The chef.
* @param index The index from which we get all the needed stuff.
* @param amount The amount of items we want to cook.
*/
public CookingAction(Player player, int index, int amount) {
super(player, 0);
this.rawItem = RAW_ITEMS[index];
this.noBurnLevel = getStopBurningLevel(index, player.getEquipment().get(Equipment.SLOT_GLOVES));
this.levelToCook = LEVEL_REQUIREMENTS[index];
this.burntItem = BURNT_ITEMS[index];
this.cookedItem = COOKED_ITEMS[index];
this.exp = EXPERIENCE_TABLE[index];
this.amount = amount;
}
@Override
public void execute() {
final Player player = getPlayer();
if(amount <= 0) {
this.stop();
getPlayer().getCookingVariables().setCookingItem(-1);
return;
}
if(!player.getInventory().contains(rawItem)){
player.getActionSender().sendMessage("You have run out of "+rawItem.getDefinition().getName().replaceFirst("Raw", "")+" to cook.");
this.stop();
player.getCookingVariables().setCookingItem(-1);
return;
}
if(player.getSkills().getLevel(Skills.COOKING) < levelToCook) {
player.getActionSender().sendMessage("You need a Cooking of level "+ levelToCook +" in order to cook this meal.");
this.stop();
player.getCookingVariables().setCookingItem(-1);
return;
}
int playerLevel = player.getSkills().getLevel(Skills.COOKING);
boolean shouldBurn = (playerLevel >= noBurnLevel) ? false : shouldBurn(playerLevel, noBurnLevel);
if(player.getCookingVariables().isCookingOnFire()) {
player.playAnimation(FIRE_ANIMATION);
} else {
player.playAnimation(RANGE_ANIMATION);
}
player.getInventory().remove(rawItem);
if(shouldBurn) {
player.getInventory().add(burntItem);
player.getActionSender().sendMessage("Oops! You accidently burnt the " + rawItem.getDefinition().getName().toLowerCase() + ".");
} else {
player.getInventory().add(cookedItem);
player.getActionSender().sendMessage("You succesfully cook the " + cookedItem.getDefinition().getName().replaceFirst("Cooked ", "").toLowerCase() + ".");//Removes the string "Cooked" from some food, eg. "Cooked meat" because it looks super idiotic.
if(cookedItem.getId() == 2309) {
TutorialIsland.finishedBread(player);
}
player.getSkills().addExperience(Skills.COOKING, exp);
}
this.setDelay(3000);
if(--amount <= 0) {
this.stop();
player.getCookingVariables().setCookingItem(-1);
}
}
private final Item rawItem;
private final Item burntItem;
private final Item cookedItem;
private final int noBurnLevel;
private final int levelToCook;
private final double exp;
private int amount;
@Override
public QueuePolicy getQueuePolicy() {
return QueuePolicy.NEVER;
}
@Override
public WalkablePolicy getWalkablePolicy() {
return WalkablePolicy.NON_WALKABLE;
}
}
I can't see any improvement bro
Code:
if(productionAmount > 1)
player.playAnimation(heatSource.getAnimation());
you already had a precondition check
Code:
if(!player.getInventory().contains(cookingItem.getRawItem()) ||
productionAmount < 1) {
this.stop();
return;
}
why evaluate productionAmount again, like it could suddenly change in the middle of execution
in both of your constructors, you have
Code:
player.playAnimation(heatSource.getAnimation());
ok so every time the action is instantiated, we play the animation, ok
then why do you have another
Code:
if(productionAmount > 1)
player.playAnimation(heatSource.getAnimation());
in the execute method. repetitive much?
your whole four tick delay is a hassle, why have the ENTIRE FUCKING execute method loop four fucking times each cycle when you can easily let it as originally done,
Code:
this.setDelay(3000);
600 * 4 = 3000 derp
Btw, your tick delay shit wouldn't even work based on the code you provided,
Code:
private int fourTickDelay;
ok and then you do
Code:
fourTickDelay++;
if(fourTickDelay % 4 != 0)
did you even test this shit? That would give you an immediate nullpointer, you don't even set a value to fourTickDelay in your constructor or anywhere in that class, how can you increase null by one