Post: [PI] Herb Identification
03-05-2015, 09:32 PM #1
Stunz
Former Staff
(adsbygoogle = window.adsbygoogle || []).push({});
Herb Identifying Tutorial

    package org.valor.skill.herblore;

import org.valor.model.items.definitions.ItemDefinition;
import org.valor.model.players.Client;
import org.valor.model.players.content.Music;
import org.valor.model.players.content.Sound;
import org.valor.skill.Skill;
import org.valor.skill.SkillConstants;

/**
* The main action of Herb Identification;
*
* @author Valiant (https://www.rune-server.org/members/Valiant)
* @since 2015-3-2
*/
public final class HerbIdentification {

// Herb data
private enum HerbData {

GUAM(199, 249, 3, 2.75),

MARRENTILL(201, 251, 5, 3.75),

TARROMIN(203, 253, 11, 5),

HARRALANDER(205, 255, 20, 6.25),

RANARR(207, 257, 25, 7.5),

TOADFLAX(3049, 2998, 30, Cool Man (aka Tustin),

IRIT(209, 259, 40, 8.75),

AVANTOE(211, 261, 48, 10),

KWUARM(213, 263, 54, 11.25),

SNAPDRAGON(3051, 3000, 59, 11.75),

CADANTINE(215, 265, 65, 12.5),

LANTADYME(2485, 2481, 67, 13.125),

DWARF_WEED(217, 267, 70, 13.75),

TORSTOL(219, 269, 75, 15);

// grimy herb itemID
private int grimyHerb;

// clean herb itemID
private int cleanHerb;

// level required to clean
private int levelRequired;

// experience for cleaning
private double experience;

// HerbData Constructor
private HerbData(final int grimyHerb, final int cleanHerb,
final int levelRequired, final double experience) {
this.grimyHerb = grimyHerb;
this.cleanHerb = cleanHerb;
this.levelRequired = levelRequired;
this.experience = (experience * SkillConstants.HERBLORE_EXPERIENCE);
}

// Gets the grimy herb ID
public int getGrimyHerb() {
return grimyHerb;
}

// Gets the cleaned herb ID
public int getCleanHerb() {
return cleanHerb;
}

/**
* Determines if the values from the herbs enumeration matches the
* itemId that has been clicked on from the clickItem packet, If the
* item clicked on is indeed not a herb, null is returned and no herb is
* cleaned.
*
* @param itemId
* the item clicked
* @return
*/
public static final HerbData isHerb(int item) {
for (final HerbData herb : HerbData.values()) {
if (herb.getGrimyHerb() == item) {
return herb;
}
}
return null;
}

// Gets the required level for cleanse
public int getRequired() {
return levelRequired;
}

// Gets the experience received
public double getExperience() {
return experience;
}
}

/**
* Manages the cleaning of the herb clicked on.
*
* @param player
* the player cleaning the herb.
* @param item
* the item being cleaned.
*/
public static void cleanHerb(Client player, int item) {
final HerbData herb = HerbData.isHerb(item);
if (herb == null) {
return;
} else if (Skill
.canPerform(player,
player.playerLevel[SkillConstants.HERBLORE],
herb.getRequired())) {
player.getItems().deleteItem(herb.getGrimyHerb(), 1);
player.getItems().addItem(herb.getCleanHerb(), 1);
Skill.addXP(player, (int) herb.getExperience(),
SkillConstants.HERBLORE);
player.sendMessage("You clean the dirt off the "
+ ItemDefinition.definitions[item].getName() + ".");
Music.sendSound(player, Sound.CLEAN_HERB, 0, 3, 10);
}
}
}


Clicking Item packet:
    if (ItemDefinition.definitions[itemId].getName().contains("Grimy")
&& ItemDefinition.definitions[itemId].getExamine().contains("I need to clean this herb")) {
HerbIdentification.cleanHerb(player, itemId);
}

The following user thanked Stunz for this useful post:

ResistThePower

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo