Currently trying to add some sort of bonfire method of training firemaking into my server using stock animations, but have run into a issue where it isn't grabbing the correct item count. After testing to see if everything would work and it didn't I begin to debug my problem and put a sendMessage statement to see the actual count of the item. For some odd reason it prints out multiples of them even though I don't have it called doing that. Anyone got any ideas?
Code:
package org.delrith.game.content.skill.firemaking;
import org.delrith.Server;
import org.delrith.core.event.CycleEvent;
import org.delrith.core.event.CycleEventContainer;
import org.delrith.core.event.CycleEventHandler;
import org.delrith.core.util.Misc;
import org.delrith.game.player.Client;
import org.delrith.game.player.Player;
/**
*
* @author Vili
*
*/
public class Bonfire {
public enum LogData {
NORMAL(1511, 1, 50.0), OAK(1521, 15, 70.0), WILLOW(1519, 30, 100.0), MAPLE(
1517, 45, 151.0), YEW(1515, 60, 212.5), MAGIC(1513, 75, 313.8);
/** Field Variables **/
private final int logIdentifier, levelRequired;
private final double experienceGained;
/**
* Constructs the enumerator LogData.
*
* @param logIdentifier
* The log being lighted.
* @param levelRequired
* The level required to light the log.
* @param experienceGained
* The experience given for lighting the log.
*/
private LogData(final int logIdentifier, final int levelRequired,
final double experienceGained) {
this.logIdentifier = logIdentifier;
this.levelRequired = levelRequired;
this.experienceGained = experienceGained;
}
/**
* Publicly constructs logIdentifier.
*
* @return
*/
public int getLog() {
return logIdentifier;
}
/**
* Publicly constructs levelRequired.
*
* @return
*/
public int getLevel() {
return levelRequired;
}
/**
* Publicly constructs experienceGained.
*
* @return
*/
public double getExperience() {
return experienceGained;
}
}
/**
* Handles the action for bonfires.
* @param c
* Client
* @param objectId
* Object identifier.
* @param objectX
* Object's X coordinate.
* @param objectY
* Object's Y coordinate.
* @param itemId
* Item Identifier.
*/
public static void bonfireAction(final Client c, final int objectId,
final int objectX, final int objectY, final int itemId) {
final String name = c.getItems().getItemName(itemId).toLowerCase();
final int delay = Misc.random(5) + 3;
if (Player.isSkilling == true) {
return;
}
for (final LogData l : LogData.values()) {
c.sendMessage("You have " + c.getItems().getItemAmount(l.getLog()) + " "+ name.toLowerCase() + ".");
if (itemId == l.getLog() && objectId == 2732)
if (c.playerLevel[11] < l.getLevel()) {
c.sendMessage("You need level " + l.getLevel()
+ " firemaking to bonfire " + name + ".");
}
Player.setSkilling(true);
CycleEventHandler.getSingleton().addEvent(c, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
if (!Client.isBonfire()) {
container.stop();
}
if (!Server.objectManager.objectExists(objectX, objectY)) {
container.stop();
}
if (c.getItems().getItemAmount(l.getLog()) > 0) {
c.startAnimation(894);
c.getItems().deleteItem(l.getLog(), 1);
c.getPA().addSkillXP((int) l.getExperience(), 11);
c.sendMessage("You add the " + name + " to the bonfire.");
}
if (c.getItems().getItemAmount(l.getLog()) < 1) {
c.sendMessage("You have run out of logs to throw on the bonfire.");
container.stop();
}
}
@Override
public void stop() {
Player.setSkilling(false);
Client.setBonfire(false);
}
}, delay);
}
}
}
Code:
case 2732:
Bonfire.bonfireAction(c, objectId, objectX, objectY, itemId);
break;
Code:
public int getItemAmount(final int ItemID) {
int itemCount = 0;
for (int i = 0; i < c.playerItems.length; i++) {
if ((c.playerItems[i] - 1) == ItemID) {
itemCount += c.playerItemsN[i];
}
}
return itemCount;
}