Farming Skill, Orb Charging, Battle Staff Creation, etc

- Farming Skill Added
- Orb charging implemented
- Battle staff creation implemented
- Cleaned up some code
- Stuck command will now tele you from further out in wildy if you are not in combat
- Fixed an issue with amulet of glory
- Added forcechats for npcs at Gnome Agility Course, and for Cows, Ducks and Sheeps just like in actual osrs
- Added base for God Book preaching
This commit is contained in:
Mr Extremez
2020-02-19 07:01:24 -06:00
parent 9b220ec47c
commit d18fbb16ca
71 changed files with 12165 additions and 541 deletions
-2
View File
@@ -1,2 +0,0 @@
/Client.class
/LocalGame.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
-7
View File
@@ -1,7 +0,0 @@
/* AUTOMATICALLY GENERATED ON Tue Apr 16 17:20:59 EDT 2002*/
/* DO NOT EDIT */
grant {
permission java.security.AllPermission;
};
+1
View File
@@ -0,0 +1 @@
0
@@ -1,6 +1,10 @@
package com.rebotted;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.concurrent.Executors;
@@ -12,7 +16,6 @@ import java.util.concurrent.locks.ReentrantLock;
import org.apache.mina.common.IoAcceptor;
import org.apache.mina.transport.socket.nio.SocketAcceptor;
import org.apache.mina.transport.socket.nio.SocketAcceptorConfig;
import com.rebotted.console.CommandConsole;
import com.rebotted.event.CycleEventHandler;
import com.rebotted.game.content.minigames.FightCaves;
@@ -36,6 +39,8 @@ import com.rebotted.integrations.discord.DiscordActivity;
import com.rebotted.integrations.discord.JavaCord;
import com.rebotted.net.ConnectionHandler;
import com.rebotted.net.ConnectionThrottleFilter;
import com.rebotted.tick.Scheduler;
import com.rebotted.tick.Tick;
import com.rebotted.util.HostBlacklist;
import com.rebotted.world.GlobalDropsHandler;
import com.rebotted.world.ItemHandler;
@@ -54,6 +59,49 @@ import com.rebotted.world.clip.Region;
* @author Integration Julian.
*/
public class GameEngine {
private static long minutesCounter;
private static void startMinutesCounter() {
try {
minuteFile = new BufferedReader(new FileReader(
"./data/minutes.log"));
minutesCounter = Long.parseLong(minuteFile.readLine());
} catch (Exception e) {
e.printStackTrace();
}
}
private static void setMinutesCounter(long minutesCounter) {
try {
BufferedWriter minuteCounter = new BufferedWriter(new FileWriter(
"./data/minutes.log"));
minuteCounter.write(Long.toString(minutesCounter));
minuteCounter.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static long getMinutesCounter() {
long d = TimeUnit.MILLISECONDS.toMinutes(System.currentTimeMillis()
- minutesCounter);
return d;
}
private static final Scheduler scheduler2 = new Scheduler();
public static Scheduler getScheduler() {
return scheduler2;
}
public static void schedule(Tick tick) {
getScheduler().schedule(tick);
}
public static String ersSecret;
@@ -147,6 +195,8 @@ public class GameEngine {
GlobalDropsHandler.initialize();
Connection.initialize();
HostBlacklist.loadBlacklist();
startMinutesCounter();
setMinutesCounter(minutesCounter);
/**
* Server Successfully Loaded
@@ -232,5 +282,7 @@ public class GameEngine {
}
public static boolean playerExecuted = false;
private static BufferedReader minuteFile;
}
@@ -42,8 +42,8 @@ public class CombatAssistant {
player = player2;
}
public static boolean inCombat(Client c) {
return (c.underAttackBy > 0 || c.underAttackBy2 > 0);
public boolean inCombat() {
return (player.underAttackBy > 0 || player.underAttackBy2 > 0);
}
public void delayedHit(int i) { // npc hit delay
@@ -3,7 +3,7 @@ package com.rebotted.game.content.consumables;
import com.rebotted.event.CycleEvent;
import com.rebotted.event.CycleEventContainer;
import com.rebotted.event.CycleEventHandler;
import com.rebotted.game.items.Item;
import com.rebotted.game.items.ItemData;
import com.rebotted.game.items.ItemAssistant;
import com.rebotted.game.players.Player;
@@ -30,9 +30,9 @@ public class Potions {
c.getCombatAssistant().resetPlayerAttack();
c.attackTimer++;
c.getPacketSender().sendMessage(
"You drink some of your " + Item.getItemName(itemId) + ".");
"You drink some of your " + ItemData.getItemName(itemId) + ".");
c.startAnimation(829);
final String item = Item.getItemName(itemId);
final String item = ItemData.getItemName(itemId);
String m = "";
if (item.endsWith("(4)")) {
m = "You have 3 doses of potion left.";
@@ -6,7 +6,7 @@ import com.rebotted.GameEngine;
import com.rebotted.game.content.combat.prayer.PrayerDrain;
import com.rebotted.game.content.minigames.castlewars.CastleWars;
import com.rebotted.game.items.GameItem;
import com.rebotted.game.items.Item;
import com.rebotted.game.items.ItemData;
import com.rebotted.game.items.ItemAssistant;
import com.rebotted.game.items.impl.RareProtection;
import com.rebotted.game.players.Client;
@@ -243,7 +243,7 @@ public class Dueling {
return false;
}
changeDuelStuff();
if (!Item.itemStackable[itemID]) {
if (!ItemData.itemStackable[itemID]) {
for (int a = 0; a < amount; a++) {
if (player.getItemAssistant().playerHasItem(itemID, 1)) {
stakedItems.add(new GameItem(itemID, 1));
@@ -260,7 +260,7 @@ public class Dueling {
player.getPacketSender().sendFrame126("", 6684);
o.getPacketSender().sendFrame126("", 6684);
}
if (Item.itemStackable[itemID] || Item.itemIsNote[itemID]) {
if (ItemData.itemStackable[itemID] || ItemData.itemIsNote[itemID]) {
boolean found = false;
for (GameItem item : stakedItems) {
if (item.id == itemID) {
@@ -314,7 +314,7 @@ public class Dueling {
o.getDueling().declineDuel();
return false;
}
if (Item.itemStackable[itemID]) {
if (ItemData.itemStackable[itemID]) {
if (player.getItemAssistant().freeSlots() - 1 < player.duelSpaceReq) {
player.getPacketSender().sendMessage(
"You have too many rules set to remove that item.");
@@ -324,7 +324,7 @@ public class Dueling {
changeDuelStuff();
boolean goodSpace = true;
if (!Item.itemStackable[itemID]) {
if (!ItemData.itemStackable[itemID]) {
for (int a = 0; a < amount; a++) {
for (GameItem item : stakedItems) {
if (item.id == itemID) {
@@ -423,7 +423,7 @@ public class Dueling {
}
String itemId = "";
for (GameItem item : stakedItems) {
if (Item.itemStackable[item.id] || Item.itemIsNote[item.id]) {
if (ItemData.itemStackable[item.id] || ItemData.itemIsNote[item.id]) {
itemId += ItemAssistant.getItemName(item.id) + " x "
+ Misc.format(item.amount) + "\\n";
} else {
@@ -433,7 +433,7 @@ public class Dueling {
player.getPacketSender().sendFrame126(itemId, 6516);
itemId = "";
for (GameItem item : o.getDueling().stakedItems) {
if (Item.itemStackable[item.id] || Item.itemIsNote[item.id]) {
if (ItemData.itemStackable[item.id] || ItemData.itemIsNote[item.id]) {
itemId += ItemAssistant.getItemName(item.id) + " x "
+ Misc.format(item.amount) + "\\n";
} else {
@@ -651,7 +651,7 @@ public class Dueling {
public void claimStakedItems() {
for (GameItem item : otherStakedItems) {
if (item.id > 0 && item.amount > 0) {
if (Item.itemStackable[item.id]) {
if (ItemData.itemStackable[item.id]) {
if (!player.getItemAssistant().addItem(item.id, item.amount)) {
GameEngine.itemHandler.createGroundItem(player, item.id,
player.getX(), player.getY(), item.amount, player.getId());
@@ -669,7 +669,7 @@ public class Dueling {
}
for (GameItem item : stakedItems) {
if (item.id > 0 && item.amount > 0) {
if (Item.itemStackable[item.id]) {
if (ItemData.itemStackable[item.id]) {
if (!player.getItemAssistant().addItem(item.id, item.amount)) {
GameEngine.itemHandler.createGroundItem(player, item.id,
player.getX(), player.getY(), item.amount, player.getId());
@@ -713,7 +713,7 @@ public class Dueling {
if (item.amount < 1) {
continue;
}
if (Item.itemStackable[item.id] || Item.itemIsNote[item.id]) {
if (ItemData.itemStackable[item.id] || ItemData.itemIsNote[item.id]) {
player.getItemAssistant().addItem(item.id, item.amount);
} else {
player.getItemAssistant().addItem(item.id, 1);
@@ -5,7 +5,7 @@ import java.util.ArrayList;
import java.util.Random;
import com.rebotted.GameConstants;
import com.rebotted.GameEngine;
import com.rebotted.game.items.Item;
import com.rebotted.game.items.ItemData;
import com.rebotted.game.objects.Objects;
import com.rebotted.game.players.Player;
@@ -99,7 +99,7 @@ public class PartyRoom {
public static void accept(Player c) {
for (int x = 0; x < c.party.length; x++) {
if (c.partyN[x] > 0) {
if (Item.itemStackable[c.party[x]]) {
if (ItemData.itemStackable[c.party[x]]) {
int slot = arraySlot(roomItems, c.party[x]);
if (slot < 0) {
c.getPacketSender().sendMessage(
@@ -0,0 +1,33 @@
package com.rebotted.game.content.skills;
/**
* SkillConstants.java
* @author Andrew (Mr Extremez)
*/
public enum SkillConstants {
ATTACK(true), DEFENCE(true), STRENGTH(true), HITPOINTS(true), RANGE(true),
PRAYER(true), MAGIC(true), COOKING(true), WOODCUTTING(true), FLETCHING(true),
FISHING(true), FIREMAKING(true), CRAFTING(true), SMITHING(true), MINING(true),
HERBLORE(true), AGILITY(true), THIEVING(true), SLAYER(true), FARMING(true), RUNECRAFTING(true);
private SkillConstants(boolean skillEnabled) {
this.skillEnabled = skillEnabled;
}
private boolean skillEnabled;
public static boolean getEnabled(int id) {
for (final SkillConstants skillConstants : SkillConstants.values()) {
if (skillConstants.ordinal() == id && skillConstants.skillEnabled == true) {
return true;
}
}
return false;
}
public static String getName(SkillConstants skillConstants) {
return "The " + skillConstants.name().toLowerCase() + " skill is currently disabled";
}
}
@@ -1,5 +1,7 @@
package com.rebotted.game.content.skills;
import java.util.Random;
import com.rebotted.event.CycleEventHandler;
import com.rebotted.game.content.skills.cooking.Cooking;
import com.rebotted.game.content.skills.core.Fishing;
@@ -28,6 +30,13 @@ public class SkillHandler {
RUNECRAFTING = true, THIEVING = true, WOODCUTTING = true,
PRAYER = true, FLETCHING = true, CRAFTING = true, MAGIC = true,
FARMING = false, SLAYER = true, SMITHING = true;
public static final String[] skillNames = { "Attack", "Defence",
"Strength", "Hitpoints", "Range", "Prayer", "Magic", "Cooking",
"Woodcutting", "Fletching", "Fishing", "Firemaking", "Crafting",
"Smithing", "Mining", "Herblore", "Agility", "Thieving", "Slayer",
"Farming", "Runecrafting" };
public static boolean isSkilling(Player player) {
if (player.playerSkilling[10] || player.playerStun || player.playerSkilling[12]
@@ -158,6 +167,16 @@ public class SkillHandler {
}
}
}
public static boolean hasRequiredLevel(final Player player, int skillId,
int lvlReq, String event) {
if (player.playerLevel[skillId] < lvlReq) {
player.getPacketSender().sendMessage("You need at least " + lvlReq + " "
+ skillNames[skillId] + " to " + event + ".");
return false;
}
return true;
}
public static boolean hasRequiredLevel(final Player c, int id, int lvlReq,
String skill, String event) {
@@ -169,6 +188,15 @@ public class SkillHandler {
}
return true;
}
public static boolean skillCheck(int level, int levelRequired, int itemBonus) {
double chance = 0.0;
double baseChance = levelRequired < 11 ? 15 : levelRequired < 51 ? 10
: 5;// Math.pow(10d-levelRequired/10d, 2d)/2d;
chance = baseChance + ((level - levelRequired) / 2d)
+ (itemBonus / 10d);
return chance >= (new Random().nextDouble() * 100.0);
}
public static String getLine(Player c) {
return c.below459 ? "\\n\\n\\n\\n" : "\\n\\n\\n\\n\\n";
@@ -0,0 +1,104 @@
package com.rebotted.game.content.skills.crafting;
import com.rebotted.event.CycleEvent;
import com.rebotted.event.CycleEventContainer;
import com.rebotted.event.CycleEventHandler;
import com.rebotted.game.players.Player;
/**
* Battle Staff making
* @author Andrew (Mr Extremez)
*/
public class BattleStaffs {
public static enum battleStaffs {
AIR(573, 66, 138, 1397),
FIRE(569, 62, 125, 1393),
EARTH(575, 58, 113, 1399),
WATER(571, 54, 100, 1395);
private int orb, levelReq, xpRecieved, battlestaff;
private battleStaffs(final int orb, final int levelReq, final int xpRecieved, final int battlestaff) {
this.orb = orb;
this.levelReq = levelReq;
this.xpRecieved = xpRecieved;
this.battlestaff = battlestaff;
}
public int getOrb() {
return orb;
}
public int getLevelReq() {
return levelReq;
}
public int getXP() {
return xpRecieved;
}
public int getBattlestaff() {
return battlestaff;
}
}
public static void makeBattleStaff(Player player, int itemUsed, int usedWith) {
for (final battleStaffs b : battleStaffs.values()) {
if ((itemUsed == b.getOrb() && usedWith == 1391) || (itemUsed == 1391 && usedWith == b.getOrb())) {
if (player.getItemAssistant().playerHasItem(1391) && player.getItemAssistant().playerHasItem(b.getOrb())) {
if (player.isCrafting == true) {
return;
}
if (player.playerLevel[12] < b.getLevelReq()) {
player.getPacketSender().sendMessage("You need level " + b.getLevelReq() + " crafting to do that.");
return;
}
player.getPacketSender().closeAllWindows();
player.isCrafting = true;
player.skillAmount = player.getItemAssistant().getItemAmount(b.getOrb());
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
if (player.isCrafting == true && player != null) {
if (!player.getItemAssistant().playerHasItem(1391, 1)) {
player.getPacketSender().sendMessage("You have run out of battlestaffs.");
container.stop();
return;
}
if (!player.getItemAssistant().playerHasItem(b.getOrb(), 1)) {
player.getPacketSender().sendMessage("You have run out of orbs.");
container.stop();
return;
}
if (player.skillAmount == 0) {
container.stop();
return;
}
player.getItemAssistant().deleteItem(1391, 1);
player.getItemAssistant().deleteItem(b.getOrb(), 1);
player.getItemAssistant().addItem(b.getBattlestaff(), 1);
player.getPlayerAssistant().addSkillXP((int) b.getXP(), 6);
player.skillAmount--;
if (!player.getItemAssistant().playerHasItem(1391) || !player.getItemAssistant().playerHasItem(b.getOrb())) {
container.stop();
return;
}
} else {
container.stop();
}
}
@Override
public void stop() {
player.isCrafting = false;
}
}, 2);
}
}
}
}
}
@@ -0,0 +1,137 @@
package com.rebotted.game.content.skills.crafting;
import com.rebotted.event.CycleEvent;
import com.rebotted.event.CycleEventContainer;
import com.rebotted.event.CycleEventHandler;
import com.rebotted.game.items.ItemAssistant;
import com.rebotted.game.players.Player;
public class OrbCharging {
public static void chargeOrbs(final Player player, final int spellId, final int objectId) {
if (player.isCrafting == true) {
return;
}
for (final Orb l : Orb.values()) {
if (objectId == l.getObjectId(objectId)) {
if (l.getSpell() == spellId) {
if (!player.getItemAssistant().playerHasItem(567, 1)) {
player.getPacketSender().sendMessage("You need 1 " + ItemAssistant.getItemName(567).toLowerCase() + " to make "
+ ItemAssistant.getItemName(l.getProduct()).toLowerCase() + ".");
player.getPacketSender().closeAllWindows();
return;
}
player.getPacketSender().closeAllWindows();
player.isCrafting = true;
player.skillAmount = l.getAmount(objectId);
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
if (player.isCrafting == true && player != null) {
if (!player.getItemAssistant().playerHasItem(567, 1)) {
player.getPacketSender().sendMessage("You have run out of unpowered orbs.");
container.stop();
return;
}
if (!player.getCombatAssistant().checkMagicReqs(l.getSpellConfig())) {
container.stop();
return;
}
if (player.skillAmount == 0) {
container.stop();
return;
}
player.startAnimation(726);
player.gfx100(l.getOrbGfx());
player.getItemAssistant().deleteItem(567, 1);
player.getItemAssistant().addItem(l.getProduct(), 1);
player.getPlayerAssistant().addSkillXP((int) l.getXP(), 6);
player.skillAmount--;
if (!player.getItemAssistant().playerHasItem(567, 1)) {
container.stop();
return;
}
} else {
container.stop();
}
}
@Override
public void stop() {
player.isCrafting = false;
}
}, 3);
}
}
}
}
public enum Orb {
AIR(new int[][] { { 2152, 28 } }, 1058, 567, 573, 66, 76, 150, 93),
FIRE(new int[][] { { 2153, 28 }}, 1056, 567, 569, 62, 73, 152, 92),
EARTH(new int[][] { { 2150, 28} }, 1054, 567, 575, 58, 70, 151, 91),
WATER(new int[][] { { 2151, 28 } }, 1051, 567, 571, 54, 66, 149, 90);
private int[][] objectId;
private int spellId, orb, product, level, gfx, spellConfig;
private double xp;
private Orb(final int[][] objectId, final int spellId, final int orb, final int product, final int level, final double xp, final int gfx, final int spellConfig) {
this.objectId = objectId;
this.spellId = spellId;
this.orb = orb;
this.product = product;
this.level = level;
this.xp = xp;
this.gfx = gfx;
this.spellConfig = spellConfig;
}
public int getObjectId(final int object) {
for (int i = 0; i < objectId.length; i++) {
if (object == objectId[i][0]) {
return objectId[i][0];
}
}
return -1;
}
public int getAmount(final int object) {
for (int i = 0; i < objectId.length; i++) {
if (object == objectId[i][0]) {
return objectId[i][1];
}
}
return -1;
}
public int getSpell() {
return spellId;
}
public int getOrb() {
return orb;
}
public int getProduct() {
return product;
}
public int getLevel() {
return level;
}
public double getXP() {
return xp;
}
public int getOrbGfx() {
return gfx;
}
public int getSpellConfig() {
return spellConfig;
}
}
}
@@ -0,0 +1,944 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.rebotted.game.content.skills.farming;
/**
*
* @author ArrowzFtw
*/
import java.awt.Point;
import java.util.HashMap;
import java.util.Map;
import com.rebotted.GameEngine;
import com.rebotted.event.CycleEvent;
import com.rebotted.event.CycleEventContainer;
import com.rebotted.event.CycleEventHandler;
import com.rebotted.game.content.skills.SkillConstants;
import com.rebotted.game.players.Player;
import com.rebotted.util.Misc;
/**
* Created by IntelliJ IDEA. User: vayken Date: 24/02/12 Time: 20:34 To change
* this template use File | Settings | File Templates.
*/
public class Bushes {
private Player player;
// set of global constants for Farming
private static final double COMPOST_CHANCE = 0.9;
private static final double SUPERCOMPOST_CHANCE = 0.7;
private static final double CLEARING_EXPERIENCE = 4;
public Bushes(Player player) {
this.player = player;
}
// Farming data
public int[] bushesStages = new int[4];
public int[] bushesSeeds = new int[4];
public int[] bushesState = new int[4];
public long[] bushesTimer = new long[4];
public double[] diseaseChance = { 1, 1, 1, 1 };
public boolean[] hasFullyGrown = { false, false, false, false };
public boolean[] bushesWatched = { false, false, false, false };
/* set of the constants for the patch */
// states - 2 bits plant - 6 bits
public static final int GROWING = 0x00;
public static final int DISEASED = 0x01;
public static final int DEAD = 0x02;
public static final int CHECK = 0x03;
public static final int MAIN_BUSHES_CONFIG = 509;
/* This is the enum holding the seeds info */
public enum BushesData {
REDBERRY(5101, 1951, 1, 10, new int[] { 5478, 4 }, 100, 0.20, 11.5,
4.5, 0x05, 0x0e, 0x09, 0x3a, 64), CADAVABERRY(5102, 753, 1, 22,
new int[] { 5968, 3 }, 140, 0.20, 18, 7, 0x0f, 0x19, 0x14,
0x3b, 102.5), DWELLBERRY(5103, 2126, 1, 36,
new int[] { 5406, 3 }, 140, 0.20, 31.5, 12, 0x1a, 0x25, 0x20,
0x3c, 177.5), JANGERBERRY(5104, 247, 1, 48,
new int[] { 5982, 6 }, 160, 0.20, 50.5, 19, 0x26, 0x32, 0x2d,
0x3d, 284.5), WHITEBERRY(5105, 239, 1, 59,
new int[] { 6004, 8 }, 160, 0.20, 78, 29, 0x33, 0x3f, 0x3a,
0x3e, 437.5), POISONIVYBERRY(5106, 6018, 1, 70, null, 160,
0.20, 120, 45, 0xc5, 0xd1, 0xcc, 0x3f, 674);
private int seedId;
private int harvestId;
private int seedAmount;
private int levelRequired;
private int[] paymentToWatch;
private int growthTime;
private double diseaseChance;
private double plantingXp;
private double harvestXp;
private int startingState;
private int endingState;
private int limitState;
private int checkHealthState;
private double checkHealthExperience;
private static Map<Integer, BushesData> seeds = new HashMap<Integer, BushesData>();
static {
for (BushesData data : BushesData.values()) {
seeds.put(data.seedId, data);
}
}
BushesData(int seedId, int harvestId, int seedAmount,
int levelRequired, int[] paymentToWatch, int growthTime,
double diseaseChance, double plantingXp, double harvestXp,
int startingState, int endingState, int limitState,
int checkHealthState, double checkHealthExperience) {
this.seedId = seedId;
this.harvestId = harvestId;
this.seedAmount = seedAmount;
this.levelRequired = levelRequired;
this.paymentToWatch = paymentToWatch;
this.growthTime = growthTime;
this.diseaseChance = diseaseChance;
this.plantingXp = plantingXp;
this.harvestXp = harvestXp;
this.startingState = startingState;
this.endingState = endingState;
this.limitState = limitState;
this.checkHealthState = checkHealthState;
this.checkHealthExperience = checkHealthExperience;
}
public static BushesData forId(int seedId) {
return seeds.get(seedId);
}
public int getSeedId() {
return seedId;
}
public int getHarvestId() {
return harvestId;
}
public int getSeedAmount() {
return seedAmount;
}
public int getLevelRequired() {
return levelRequired;
}
public int[] getPaymentToWatch() {
return paymentToWatch;
}
public int getGrowthTime() {
return growthTime;
}
public double getDiseaseChance() {
return diseaseChance;
}
public double getPlantingXp() {
return plantingXp;
}
public double getHarvestXp() {
return harvestXp;
}
public int getStartingState() {
return startingState;
}
public int getEndingState() {
return endingState;
}
public int getLimitState() {
return limitState;
}
public int getCheckHealthState() {
return checkHealthState;
}
public double getCheckHealthXp() {
return checkHealthExperience;
}
}
/* This is the enum data about the different patches */
public enum BushesFieldsData {
ETCETERIA(0,
new Point[] { new Point(2591, 3863), new Point(2592, 3864) },
2337), SOUTH_ARDOUGNE(1, new Point[] { new Point(2617, 3225),
new Point(2618, 3226) }, 2338), CHAMPION_GUILD(2, new Point[] {
new Point(3181, 3357), new Point(3182, 3358) }, 2335), RIMMINGTON(
3,
new Point[] { new Point(2940, 3221), new Point(2941, 3222) },
2336);
private int bushesIndex;
private Point[] bushesPosition;
private int npcId;
private static Map<Integer, BushesFieldsData> npcsProtecting = new HashMap<Integer, BushesFieldsData>();
static {
for (BushesFieldsData data : BushesFieldsData.values()) {
npcsProtecting.put(data.npcId, data);
}
}
public static BushesFieldsData forId(int npcId) {
return npcsProtecting.get(npcId);
}
BushesFieldsData(int bushesIndex, Point[] bushesPosition, int npcId) {
this.bushesIndex = bushesIndex;
this.bushesPosition = bushesPosition;
this.npcId = npcId;
}
public static BushesFieldsData forIdPosition(int x, int y) {
for (BushesFieldsData bushesFieldsData : BushesFieldsData.values()) {
if (FarmingConstants.inRangeArea(
bushesFieldsData.getBushesPosition()[0],
bushesFieldsData.getBushesPosition()[1], x, y)) {
return bushesFieldsData;
}
}
return null;
}
public int getBushesIndex() {
return bushesIndex;
}
public Point[] getBushesPosition() {
return bushesPosition;
}
public int getNpcId() {
return npcId;
}
}
/* This is the enum that hold the different data for inspecting the plant */
public enum InspectData {
REDBERRY(5101, new String[][] {
{ "The Redberry seeds have only just been planted." },
{ "The Redberry bush grows larger." },
{ "The Redberry bush grows larger." },
{ "The Redberry bush grows small, unripe,", "green berries." },
{ "The berries grow larger, and pink." },
{ "The Redberry bush is ready to harvest.",
"The berries on the bush are red." }, }), CADAVABERRY(
5102,
new String[][] {
{ "The Cadavaberry seeds have only just been planted." },
{ "The Cadavaberry bush grows larger." },
{ "The Cadavaberry bush grows larger." },
{ "The Cadavaberry bush grows larger." },
{ "The Cadavaberry bush grows small, unripe,",
"green berries." },
{ "The berries grow larger, and pink." },
{ "The Cadavaberry bush is ready to harvest.",
"The berries on the bush are purple." } }), DWELLBERRY(
5103, new String[][] {
{ "The Dwellbery seeds have only just been planted." },
{ "The Dwellbery bush grows larger." },
{ "The Dwellbery bush grows larger." },
{ "The Dwellbery bush grows larger." },
{ "The Dwellbery bush grows larger." },
{ "The Dwellbery bush grows small, unripe,",
"green berries." },
{ "The berries grow larger, and light blue." },
{ "The Dwellbery bush is ready to harvest.",
"The berries on the bush are blue." }, }), JANGERBERRY(
5104,
new String[][] {
{ "The Jangerberry seeds have only just been planted." },
{ "The Jangerberry bush grows larger." },
{ "The Jangerberry bush grows larger." },
{ "The Jangerberry bush grows larger." },
{ "The Jangerberry bush grows larger." },
{ "The Jangerberry bush grows small, unripe,",
"green berries." },
{ "The berries grow larger." },
{ "The berries grow larger, and light green." },
{ "The Jangerberry bush is ready to harvest.",
"The berries on the bush are green." } }), WHITEBERRY(
5105,
new String[][] {
{ "The Whiteberry seeds have only just been planted." },
{ "The Whiteberry bush grows larger." },
{ "The Whiteberry bush grows larger." },
{ "The Whiteberry bush grows larger." },
{ "The Whiteberry bush grows larger." },
{ "The Whiteberry bush grows larger." },
{ "The Whiteberry bush grows small, unripe,",
"green berries." },
{ "The berries grow larger." },
{ "The Whiteberry bush is ready to harvest.",
"The berries on the bush are white." }, }), POISONIVYBERRY(
5106,
new String[][] {
{ "The Poison ivy seeds have only just been planted." },
{ "The Poison ivy bush grows larger." },
{ "The Poison ivy bush grows larger." },
{ "The Poison ivy bush grows larger." },
{ "The Poison ivy bush grows larger." },
{ "The Poison ivy bush grows small, unripe,",
"green berries." },
{ "The berries grow larger." },
{ "The berries grow larger, and light green." },
{ "The Poison ivy bush is ready to harvest.",
"The berries on the bush are pale yellow." } });
private int seedId;
private String[][] messages;
private static Map<Integer, InspectData> seeds = new HashMap<Integer, InspectData>();
static {
for (InspectData data : InspectData.values()) {
seeds.put(data.seedId, data);
}
}
InspectData(int seedId, String[][] messages) {
this.seedId = seedId;
this.messages = messages;
}
public static InspectData forId(int seedId) {
return seeds.get(seedId);
}
public int getSeedId() {
return seedId;
}
public String[][] getMessages() {
return messages;
}
}
/* update all the patch states */
public void updateBushesStates() {
// etceteria - south ardougne - champion guild - rimmington
int[] configValues = new int[bushesStages.length];
int configValue;
for (int i = 0; i < bushesStages.length; i++) {
configValues[i] = getConfigValue(bushesStages[i], bushesSeeds[i],
bushesState[i], i);
}
configValue = (configValues[0] << 16) + (configValues[1] << 8 << 16)
+ configValues[2] + (configValues[3] << 8);
player.getPacketSender().sendConfig(MAIN_BUSHES_CONFIG, configValue);
}
/* getting the different config values */
public int getConfigValue(int bushesStage, int seedId, int plantState,
int index) {
BushesData bushesData = BushesData.forId(seedId);
switch (bushesStage) {
case 0:// weed
return (GROWING << 6) + 0x00;
case 1:// weed cleared
return (GROWING << 6) + 0x01;
case 2:
return (GROWING << 6) + 0x02;
case 3:
return (GROWING << 6) + 0x03;
}
if (bushesData == null) {
return -1;
}
if (bushesStage > bushesData.getEndingState()
- bushesData.getStartingState() - 1) {
hasFullyGrown[index] = true;
}
if (getPlantState(plantState) == 3)
return (getPlantState(plantState) << 6)
+ bushesData.getCheckHealthState();
if (seedId == 5106) {
if (getPlantState(plantState) == 1) {
return bushesData.getStartingState() + bushesStage - 4 + 12;
} else if (getPlantState(plantState) == 2) {
return bushesData.getStartingState() + bushesStage - 4 + 20;
}
}
return (getPlantState(plantState) << 6) + bushesData.getStartingState()
+ bushesStage - 4 + (getPlantState(plantState) == 2 ? -1 : 0);
}
/* getting the plant states */
public int getPlantState(int plantState) {
switch (plantState) {
case 0:
return GROWING;
case 1:
return DISEASED;
case 2:
return DEAD;
case 3:
return CHECK;
}
return -1;
}
/* calculating the disease chance and making the plant grow */
public void doCalculations() {
for (int i = 0; i < bushesSeeds.length; i++) {
if (bushesStages[i] > 0 && bushesStages[i] <= 3
&& GameEngine.getMinutesCounter() - bushesTimer[i] >= 5) {
bushesStages[i]--;
bushesTimer[i] = GameEngine.getMinutesCounter();
updateBushesStates();
continue;
}
BushesData bushesData = BushesData.forId(bushesSeeds[i]);
if (bushesData == null) {
continue;
}
long difference = GameEngine.getMinutesCounter() - bushesTimer[i];
long growth = bushesData.getGrowthTime();
int nbStates = bushesData.getEndingState()
- bushesData.getStartingState();
int state = (int) (difference * nbStates / growth);
if (bushesTimer[i] == 0 || bushesState[i] == 2
|| bushesState[i] == 3 || (state > nbStates)) {
continue;
}
if (4 + state != bushesStages[i]) {
if (bushesStages[i] == bushesData.getEndingState()
- bushesData.getStartingState() - 1) {
bushesStages[i] = bushesData.getEndingState()
- bushesData.getStartingState() + 4;
bushesState[i] = 3;
updateBushesStates();
return;
}
bushesStages[i] = 4 + state;
if (bushesStages[i] <= 4 + state)
for (int j = bushesStages[i]; j <= 4 + state; j++)
doStateCalculation(i);
updateBushesStates();
}
}
}
public void modifyStage(int i) {
BushesData bushesData = BushesData.forId(bushesSeeds[i]);
if (bushesData == null)
return;
long difference = GameEngine.getMinutesCounter() - bushesTimer[i];
long growth = bushesData.getGrowthTime();
int nbStates = bushesData.getEndingState()
- bushesData.getStartingState();
int state = (int) (difference * nbStates / growth);
bushesStages[i] = 4 + state;
updateBushesStates();
}
/* calculations about the diseasing chance */
public void doStateCalculation(int index) {
if (bushesState[index] == 2) {
return;
}
// if the patch is diseased, it dies, if its watched by a farmer, it
// goes back to normal
if (bushesState[index] == 1) {
if (bushesWatched[index]) {
bushesState[index] = 0;
BushesData bushesData = BushesData.forId(bushesSeeds[index]);
if (bushesData == null)
return;
System.out.println(bushesSeeds[index]);
int difference = bushesData.getEndingState()
- bushesData.getStartingState();
int growth = bushesData.getGrowthTime();
bushesTimer[index] += (growth / difference);
modifyStage(index);
} else {
bushesState[index] = 2;
}
}
if (bushesState[index] == 5 && bushesStages[index] != 2) {
bushesState[index] = 0;
}
if (bushesState[index] == 0 && bushesStages[index] >= 5
&& !hasFullyGrown[index]) {
BushesData bushesData = BushesData.forId(bushesSeeds[index]);
if (bushesData == null) {
return;
}
double chance = diseaseChance[index]
* bushesData.getDiseaseChance();
int maxChance = (int) chance * 100;
if (Misc.random(100) <= maxChance) {
bushesState[index] = 1;
}
}
}
/* clearing the patch with a rake of a spade */
public boolean clearPatch(int objectX, int objectY, int itemId) {
final BushesFieldsData bushesFieldsData = BushesFieldsData
.forIdPosition(objectX, objectY);
int finalAnimation;
int finalDelay;
if (bushesFieldsData == null
|| (itemId != FarmingConstants.RAKE && itemId != FarmingConstants.SPADE)) {
return false;
}
if (bushesStages[bushesFieldsData.getBushesIndex()] == 3) {
return true;
}
if (!SkillConstants.getEnabled(SkillConstants.FARMING.ordinal())) {
player.getPacketSender().sendMessage("This skill is currently disabled.");
return true;
}
if (bushesStages[bushesFieldsData.getBushesIndex()] <= 3) {
if (!player.getItemAssistant().playerHasItem(FarmingConstants.RAKE)) {
player.getDialogueHandler().sendStatement(
"You need a rake to clear this path.");
return true;
} else {
finalAnimation = FarmingConstants.RAKING_ANIM;
finalDelay = 5;
}
} else {
if (!player.getItemAssistant().playerHasItem(FarmingConstants.SPADE)) {
player.getDialogueHandler().sendStatement("You need a spade to clear this path.");
return true;
} else {
finalAnimation = FarmingConstants.SPADE_ANIM;
finalDelay = 3;
}
}
final int animation = finalAnimation;
player.stopPlayer(true);
player.startAnimation(animation);
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
player.startAnimation(animation);
if (bushesStages[bushesFieldsData.getBushesIndex()] <= 2) {
bushesStages[bushesFieldsData.getBushesIndex()]++;
player.getItemAssistant().addItem(6055, 1);
} else {
bushesStages[bushesFieldsData.getBushesIndex()] = 3;
container.stop();
}
player.getPlayerAssistant().addSkillXP(CLEARING_EXPERIENCE, SkillConstants.FARMING.ordinal());
bushesTimer[bushesFieldsData.getBushesIndex()] = GameEngine
.getMinutesCounter();
updateBushesStates();
if (bushesStages[bushesFieldsData.getBushesIndex()] == 3) {
container.stop();
return;
}
}
@Override
public void stop() {
resetBushes(bushesFieldsData.getBushesIndex());
player.getPacketSender().sendMessage("You clear the patch.");
player.stopPlayer(false);
player.getPlayerAssistant().resetAnimation();
}
}, finalDelay);
return true;
}
/* planting the seeds */
public boolean plantSeed(int objectX, int objectY, final int seedId) {
final BushesFieldsData bushesFieldsData = BushesFieldsData
.forIdPosition(objectX, objectY);
final BushesData bushesData = BushesData.forId(seedId);
if (bushesFieldsData == null || bushesData == null) {
return false;
}
if (!SkillConstants.getEnabled(SkillConstants.FARMING.ordinal())) {
player.getPacketSender().sendMessage("This skill is currently disabled.");
return true;
}
if (bushesStages[bushesFieldsData.getBushesIndex()] != 3) {
player.getPacketSender().sendMessage("You can't plant a seed here.");
return false;
}
if (bushesData.getLevelRequired() > player.playerLevel[SkillConstants.FARMING.ordinal()]) {
player.getDialogueHandler().sendStatement("You need a farming level of "
+ bushesData.getLevelRequired()
+ " to plant this seed.");
return true;
}
if (!player.getItemAssistant().playerHasItem(FarmingConstants.SEED_DIBBER)) {
player.getDialogueHandler().sendStatement(
"You need a seed dibber to plant seed here.");
return true;
}
if (player.getItemAssistant().getItemAmount(bushesData.getSeedId()) < bushesData
.getSeedAmount()) {
player.getDialogueHandler().sendStatement("You need atleast "
+ bushesData.getSeedAmount() + " seeds to plant here.");
return true;
}
player.startAnimation(FarmingConstants.SEED_DIBBING);
bushesStages[bushesFieldsData.getBushesIndex()] = 4;
player.getItemAssistant().deleteItem(seedId, bushesData.getSeedAmount());
player.stopPlayer(true);
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
bushesState[bushesFieldsData.getBushesIndex()] = 0;
bushesSeeds[bushesFieldsData.getBushesIndex()] = seedId;
bushesTimer[bushesFieldsData.getBushesIndex()] = GameEngine
.getMinutesCounter();
player.getPlayerAssistant().addSkillXP(bushesData.getPlantingXp(), SkillConstants.FARMING.ordinal());
container.stop();
}
@Override
public void stop() {
updateBushesStates();
player.stopPlayer(false);
}
}, 3);
return true;
}
@SuppressWarnings("unused")
private void displayAll() {
for (int i = 0; i < bushesStages.length; i++) {
System.out.println("index : " + i);
System.out.println("state : " + bushesState[i]);
System.out.println("seeds : " + bushesSeeds[i]);
System.out.println("level : " + bushesStages[i]);
System.out.println("timer : " + bushesTimer[i]);
System.out.println("disease chance : " + diseaseChance[i]);
System.out
.println("-----------------------------------------------------------------");
}
}
/* harvesting the plant resulted */
public boolean harvestOrCheckHealth(int objectX, int objectY) {
final BushesFieldsData bushesFieldsData = BushesFieldsData
.forIdPosition(objectX, objectY);
if (bushesFieldsData == null) {
return false;
}
final BushesData bushesData = BushesData
.forId(bushesSeeds[bushesFieldsData.getBushesIndex()]);
if (bushesData == null) {
return false;
}
if (!SkillConstants.getEnabled(SkillConstants.FARMING.ordinal())) {
player.getPacketSender().sendMessage("This skill is currently disabled.");
return true;
}
if (player.getItemAssistant().freeSlots() <= 0) {
player.getPacketSender().sendMessage("Not enough space in your inventory.");
return true;
}
player.startAnimation(832);
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
if (player.getItemAssistant().freeSlots() <= 0) {
container.stop();
return;
}
if (bushesState[bushesFieldsData.getBushesIndex()] == 3) {
player.getPacketSender()
.sendMessage(
"You examine the bush for signs of disease and find that it's in perfect health.");
player.getPlayerAssistant().addSkillXP(bushesData.getCheckHealthXp(), SkillConstants.FARMING.ordinal());
bushesState[bushesFieldsData.getBushesIndex()] = 0;
hasFullyGrown[bushesFieldsData.getBushesIndex()] = false;
bushesTimer[bushesFieldsData.getBushesIndex()] = GameEngine
.getMinutesCounter() - bushesData.getGrowthTime();
// bushesStages[bushesFieldsData.getBushesIndex()] -= 2;
modifyStage(bushesFieldsData.getBushesIndex());
container.stop();
return;
}
player.getPacketSender().sendMessage(
"You harvest the crop, and pick some berries.");
player.getItemAssistant().addItem(bushesData.getHarvestId(), 1);
player.getPlayerAssistant().addSkillXP(bushesData.getHarvestXp(), SkillConstants.FARMING.ordinal());
bushesTimer[bushesFieldsData.getBushesIndex()] = GameEngine
.getMinutesCounter();
int difference = bushesData.getEndingState()
- bushesData.getStartingState();
int growth = bushesData.getGrowthTime();
lowerStage(
bushesFieldsData.getBushesIndex(),
growth
- (growth / difference)
* (difference + 5 - bushesStages[bushesFieldsData
.getBushesIndex()]));
modifyStage(bushesFieldsData.getBushesIndex());
container.stop();
}
@Override
public void stop() {
player.getPlayerAssistant().resetAnimation();
}
}, 2);
return true;
}
/* lowering the stage */
public void lowerStage(int index, int timer) {
hasFullyGrown[index] = false;
bushesTimer[index] -= timer;
}
/* putting compost onto the plant */
public boolean putCompost(int objectX, int objectY, final int itemId) {
if (itemId != 6032 && itemId != 6034) {
return false;
}
final BushesFieldsData bushesFieldsData = BushesFieldsData
.forIdPosition(objectX, objectY);
if (bushesFieldsData == null) {
return false;
}
if (bushesStages[bushesFieldsData.getBushesIndex()] != 3
|| bushesState[bushesFieldsData.getBushesIndex()] == 5) {
player.getPacketSender().sendMessage("This patch doesn't need compost.");
return true;
}
player.getItemAssistant().deleteItem(itemId, 1);
player.getItemAssistant().addItem(1925, 1);
player.getPacketSender().sendMessage(
"You pour some " + (itemId == 6034 ? "super" : "")
+ "compost on the patch.");
player.startAnimation(FarmingConstants.PUTTING_COMPOST);
player.getPlayerAssistant().addSkillXP(itemId == 6034 ? Compost.SUPER_COMPOST_EXP_USE
: Compost.COMPOST_EXP_USE, SkillConstants.FARMING.ordinal());
player.stopPlayer(true);
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
diseaseChance[bushesFieldsData.getBushesIndex()] *= itemId == 6032 ? COMPOST_CHANCE
: SUPERCOMPOST_CHANCE;
bushesState[bushesFieldsData.getBushesIndex()] = 5;
container.stop();
}
@Override
public void stop() {
player.stopPlayer(false);
player.getPlayerAssistant().resetAnimation();
}
}, 7);
return true;
}
/* inspecting a plant */
public boolean inspect(int objectX, int objectY) {
final BushesFieldsData bushesFieldsData = BushesFieldsData
.forIdPosition(objectX, objectY);
if (bushesFieldsData == null) {
return false;
}
if (!SkillConstants.getEnabled(SkillConstants.FARMING.ordinal())) {
player.getPacketSender().sendMessage("This skill is currently disabled.");
return true;
}
final InspectData inspectData = InspectData
.forId(bushesSeeds[bushesFieldsData.getBushesIndex()]);
final BushesData bushesData = BushesData
.forId(bushesSeeds[bushesFieldsData.getBushesIndex()]);
if (bushesState[bushesFieldsData.getBushesIndex()] == 1) {
player.getDialogueHandler().sendStatement("This plant is diseased. Use a plant cure on it to cure it, ",
"or clear the patch with a spade.");
return true;
} else if (bushesState[bushesFieldsData.getBushesIndex()] == 2) {
player.getDialogueHandler().sendStatement("This plant is dead. You did not cure it while it was diseased.",
"Clear the patch with a spade.");
return true;
} else if (bushesState[bushesFieldsData.getBushesIndex()] == 3) {
player.getDialogueHandler().sendStatement(
"This plant has fully grown. You can check it's health",
"to gain some farming experiences.");
return true;
}
if (bushesStages[bushesFieldsData.getBushesIndex()] == 0) {
player.getDialogueHandler().sendStatement(
"This is a bush patch. The soil has not been treated.",
"The patch needs weeding.");
} else if (bushesStages[bushesFieldsData.getBushesIndex()] == 3) {
player.getDialogueHandler().sendStatement(
"This is a bush patch. The soil has not been treated.",
"The patch is empty and weeded.");
} else if (inspectData != null && bushesData != null) {
player.getPacketSender().sendMessage(
"You bend down and start to inspect the patch...");
player.startAnimation(1331);
player.stopPlayer(true);
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
if (bushesStages[bushesFieldsData.getBushesIndex()] - 4 < inspectData
.getMessages().length - 2) {
player.getDialogueHandler().sendStatement( inspectData
.getMessages()[bushesStages[bushesFieldsData
.getBushesIndex()] - 4]);
} else if (bushesStages[bushesFieldsData.getBushesIndex()] < bushesData
.getEndingState()
- bushesData.getStartingState()
+ 2) {
player.getDialogueHandler().sendStatement(
inspectData.getMessages()[inspectData
.getMessages().length - 2]);
} else {
player.getDialogueHandler().sendStatement(
inspectData.getMessages()[inspectData
.getMessages().length - 1]);
}
container.stop();
}
@Override
public void stop() {
player.startAnimation(1332);
player.stopPlayer(false);
// player.reset();
}
}, 5);
}
return true;
}
/* opening the corresponding guide about the patch */
public boolean guide(int objectX, int objectY) {
final BushesFieldsData bushesFieldsData = BushesFieldsData
.forIdPosition(objectX, objectY);
if (bushesFieldsData == null) {
return false;
}
if (!SkillConstants.getEnabled(SkillConstants.FARMING.ordinal())) {
player.getPacketSender().sendMessage("This skill is currently disabled.");
return true;
}
player.getSkillInterfaces().farmingComplex(5);
player.getSkillInterfaces().selected = 20;
return true;
}
/* Curing the plant */
public boolean curePlant(int objectX, int objectY, int itemId) {
final BushesFieldsData bushesFieldsData = BushesFieldsData
.forIdPosition(objectX, objectY);
if (bushesFieldsData == null || itemId != 6036) {
return false;
}
final BushesData bushesData = BushesData
.forId(bushesSeeds[bushesFieldsData.getBushesIndex()]);
if (bushesData == null) {
return false;
}
if (!SkillConstants.getEnabled(SkillConstants.FARMING.ordinal())) {
player.getPacketSender().sendMessage("This skill is currently disabled.");
return true;
}
if (bushesState[bushesFieldsData.getBushesIndex()] != 1) {
player.getPacketSender().sendMessage("This plant doesn't need to be cured.");
return true;
}
player.getItemAssistant().deleteItem(itemId, 1);
player.getItemAssistant().addItem(229, 1);
player.startAnimation(FarmingConstants.CURING_ANIM);
player.stopPlayer(true);
bushesState[bushesFieldsData.getBushesIndex()] = 0;
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
player.getPacketSender().sendMessage(
"You cure the plant with a plant cure.");
container.stop();
}
@Override
public void stop() {
updateBushesStates();
player.stopPlayer(false);
player.getPlayerAssistant().resetAnimation();
}
}, 7);
return true;
}
private void resetBushes(int index) {
bushesSeeds[index] = 0;
bushesState[index] = 0;
diseaseChance[index] = 1;
hasFullyGrown[index] = false;
bushesWatched[index] = false;
}
/* checking if the patch is raked */
public boolean checkIfRaked(int objectX, int objectY) {
final BushesFieldsData bushesFieldData = BushesFieldsData
.forIdPosition(objectX, objectY);
if (bushesFieldData == null)
return false;
if (bushesStages[bushesFieldData.getBushesIndex()] == 3)
return true;
return false;
}
}
@@ -0,0 +1,243 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.rebotted.game.content.skills.farming;
import com.rebotted.GameConstants;
import com.rebotted.game.content.skills.SkillConstants;
import com.rebotted.game.players.Player;
import com.rebotted.util.Misc;
public class ChopTree {
private static final Axe[] axes = new Axe[8];
private static final Tree[] trees = new Tree[11];
public static final int[] COMMON_SEEDS = { 5312, 5283, 5284, 5285, 5286,
5313 };
public static final int[] UNCOMMON_SEEDS = { 5314, 5288, 5287, 5315, 5289 };
public static final int[] RARE_SEEDS = { 5316, 5290 };
public static final int[] VERY_RARE_SEEDS = { 5317 };
public static final int[] COMMON_RING = { 1635, 1637 };
public static final int[] UNCOMMON_RING = { 1639 };
public static final int[] RARE_RING = { 1641 };
public static final int[] VERY_RARE_RING = { 1643 };
static {
// Initialise axes
axes[0] = new Axe(1351, 1, 508, 879, 0);
axes[1] = new Axe(1349, 1, 510, 877, 1);
axes[2] = new Axe(1353, 6, 512, 875, 2);
axes[3] = new Axe(1361, 6, 514, 873, 3);
axes[4] = new Axe(1355, 21, 516, 871, 4);
axes[5] = new Axe(1357, 31, 518, 869, 5);
axes[6] = new Axe(1359, 41, 520, 867, 6);
axes[7] = new Axe(6739, 61, 6743, 2846, 7);
// Initialise trees
trees[0] = new Tree(new int[] { 2023 }, 1, 25, 2862, 3371, 75, 100);
trees[1] = new Tree(new int[] { 1276, 1277, 1278, 1279, 1280, 1282,
1283, 1284, 1285, 1286, 1289, 1290, 1291, 1315, 1316, 1318,
1319, 1330, 1331, 1332, 1333, 1365, 1383, 1384, 2409, 3033,
3034, 3035, 3036, 3881, 3882, 3883, 5902, 5903, 5904 }, 1, 25,
1511, 1342, 75, 100);
trees[2] = new Tree(new int[] { 1281, 2037 }, 15, 37.5, 1521, 1356, 14,
25);
trees[3] = new Tree(new int[] { 1308, 5551, 5552, 5553 }, 30, 67.5,
1519, 7399, 14, 5);
trees[4] = new Tree(new int[] { 9036 }, 35, 85, 6333, 9037, 14, 20);
trees[5] = new Tree(new int[] { 1307, 4677 }, 45, 100, 1517, 1343, 59,
15);
trees[6] = new Tree(new int[] { 2289, 4060 }, 45, 83, 3239, 2310, 59,
15);
trees[7] = new Tree(new int[] { 9034 }, 50, 125, 6332, 9035, 80, 10);
trees[8] = new Tree(new int[] { 1309 }, 60, 175, 1515, 7402, 100, 5);
trees[9] = new Tree(new int[] { 1306 }, 75, 250, 1513, 7401, 200, 3);
trees[10] = new Tree(new int[] { 1292 }, 36, 0, 771, 1513, 59, 100);
}
public static class Axe {
private int id;
private int level;
private int head;
private int animation;
private int bonus;
public Axe(int id, int level, int head, int animation, int bonus) {
this.id = id;
this.level = level;
this.head = head;
this.animation = animation;
this.bonus = bonus;
}
public int getId() {
return id;
}
public int getLevel() {
return level;
}
public int getHead() {
return head;
}
public int getAnimation() {
return animation;
}
public int getBonus() {
return bonus;
}
}
public static class Tree {
private int[] id;
private int level;
private double xp;
private int log;
private int stump;
private int respawnTime;
private int decayChance;
public Tree(int[] id, int level, double xp, int log, int stump,
int respawnTime, int decayChance) {
this.id = id;
this.level = level;
this.xp = xp;
this.log = log;
this.stump = stump;
this.respawnTime = respawnTime;
this.decayChance = decayChance;
}
public int[] getId() {
return id;
}
public int getLevel() {
return level;
}
public double getXP() {
return xp;
}
public int getLog() {
return log;
}
public int getStump() {
return stump;
}
public int getRespawnTime() {
return respawnTime;
}
public int getDecayChance() {
return decayChance;
}
}
public static boolean handleNest(Player player, int itemId) {
int[] commonItems, uncommonItems, rareItems, veryRareItems;
switch (itemId) {
case 5070:
player.getItemAssistant().deleteItem(itemId, 1);
player.getItemAssistant().addItem(5075, 1);
player.getItemAssistant().addItem(5076, 1);
return true;
case 5071:
player.getItemAssistant().deleteItem(itemId, 1);
player.getItemAssistant().addItem(5075, 1);
player.getItemAssistant().addItem(5078, 1);
return true;
case 5072:
player.getItemAssistant().deleteItem(itemId, 1);
player.getItemAssistant().addItem(5075, 1);
player.getItemAssistant().addItem(5077, 1);
return true;
case 5073:
commonItems = COMMON_SEEDS;
uncommonItems = UNCOMMON_SEEDS;
rareItems = RARE_SEEDS;
veryRareItems = VERY_RARE_SEEDS;
break;
case 5074:
commonItems = COMMON_RING;
uncommonItems = UNCOMMON_RING;
rareItems = RARE_RING;
veryRareItems = VERY_RARE_RING;
break;
default:
return false;
}
int randomNumber = Misc.random(100), finalItem;
if (randomNumber <= 60)
finalItem = commonItems[Misc.random(commonItems.length - 1)];
else if (randomNumber <= 80)
finalItem = uncommonItems[Misc.random(uncommonItems.length - 1)];
else if (randomNumber <= 95)
finalItem = rareItems[Misc.random(rareItems.length - 1)];
else
finalItem = veryRareItems[Misc.random(veryRareItems.length - 1)];
player.getPacketSender().sendMessage(
"You search the nest...and find something in it!");
player.getItemAssistant().deleteItem(itemId, 1);
player.getItemAssistant().addItem(5075, 1);
player.getItemAssistant().addItem(finalItem, 1);
return true;
}
public static Axe getAxe(Player player) {
final int axeIndex = getAxeIndex(player);
if (axeIndex == -1) {
return null;
}
return axes[axeIndex];
}
public static Tree getTree(int objectId) {
final int treeIndex = getTreeIndex(objectId);
if (treeIndex == -1) {
return null;
}
return trees[treeIndex];
}
public static int getAxeIndex(Player player) {
for (int i = 0; i < axes.length; i++) {
if (player.playerEquipment[GameConstants.WEAPON] == (axes[i].getId())) {
return i;
}
}
for (int i = axes.length - 1; i >= 0; i--) {
if (player.getItemAssistant().playerHasItem(axes[i].getId())) {
if (player.playerLevel[SkillConstants.WOODCUTTING.ordinal()] >= axes[i].getLevel()) {
return i;
}
}
}
return -1;
}
public static int getTreeIndex(final int objectId) {
for (int i = 0; i < trees.length; i++) {
int[] ids = trees[i].getId();
for (int id : ids) {
if (objectId == id) {
return i;
}
}
}
return -1;
}
}
@@ -0,0 +1,545 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.rebotted.game.content.skills.farming;
/**
*
* @author ArrowzFtw
*/
import java.util.HashMap;
import java.util.Map;
import com.rebotted.GameEngine;
import com.rebotted.event.CycleEvent;
import com.rebotted.event.CycleEventContainer;
import com.rebotted.event.CycleEventHandler;
import com.rebotted.game.content.skills.SkillConstants;
import com.rebotted.game.players.Player;
/**
* Created by IntelliJ IDEA. User: vayken Date: 22/02/12 Time: 15:43 To change
* this template use File | Settings | File Templates.
*/
public class Compost {
private Player player;
public Compost(Player player) {
this.player = player;
}
public int[] compostBins = new int[4];
public long[] compostBinsTimer = new long[4];
public int[] organicItemAdded = new int[4];
public int tempCompostState;
/* setting up the experiences constants */
public static final double COMPOST_EXP_RETRIEVE = 4.5;
public static final double SUPER_COMPOST_EXP_RETRIEVE = 8.5;
public static final double COMPOST_EXP_USE = 18;
public static final double SUPER_COMPOST_EXP_USE = 26;
public static final double ROTTEN_TOMATOES_EXP_RETRIEVE = 8.5;
/* these are the constants related to compost making */
public static final int COMPOST = 6032;
public static final int SUPER_COMPOST = 6034;
public static final int ROTTE_TOMATO = 2518;
public static final int TOMATO = 1982;
public static final int FIRST_TYPE_COMPOST_BIN = 7808;
public static final int SECOND_TYPE_COMPOST_BIN = 7818;
public static final int[] COMPOST_ORGANIC = { 6055, 1942, 1957, 1965, 5986,
5504, 5982, 249, 251, 253, 255, 257, 2998, 259, 261, 263, 3000,
265, 2481, 267, 269, 1951, 753, 2126, 247, 239, 6018 };
public static final int[] SUPER_COMPOST_ORGANIC = { 2114, 5978, 5980, 5982,
6004, 247, 6469 };
/* this is the enum that stores the different locations of the compost bins */
public enum CompostBinLocations {
NORTH_ARDOUGNE(0, FIRST_TYPE_COMPOST_BIN, 3, 2661, 3375), PHASMATYS(1,
SECOND_TYPE_COMPOST_BIN, 1, 3610, 3522), FALADOR(2,
FIRST_TYPE_COMPOST_BIN, 4, 3056, 3312), CATHERBY(3,
FIRST_TYPE_COMPOST_BIN, 3, 2804, 3464);
private int compostIndex;
private int binObjectId;
private int objectFace;
private int x, y, z;
private static Map<Integer, CompostBinLocations> bins = new HashMap<Integer, CompostBinLocations>();
static {
for (CompostBinLocations data : CompostBinLocations.values()) {
bins.put(data.compostIndex, data);
}
}
CompostBinLocations(int compostIndex, int binObjectId, int objectFace,
int x, int y) {
this.compostIndex = compostIndex;
this.binObjectId = binObjectId;
this.objectFace = objectFace;
this.x = x;
this.y = y;
}
public static CompostBinLocations forId(int index) {
return bins.get(index);
}
public static CompostBinLocations forPosition(int x, int y) {
for (CompostBinLocations compostBinLocations : CompostBinLocations
.values()) {
if (compostBinLocations.x == x && compostBinLocations.y == y) {
return compostBinLocations;
}
}
return null;
}
public int getCompostIndex() {
return compostIndex;
}
public int getBinObjectId() {
return binObjectId;
}
public int getObjectFace() {
return objectFace;
}
}
/* this is the enum that stores the different compost bins stages */
public enum CompostBinStages {
FIRST_TYPE(7808, 7813, 7809, 7810, 7811, 7812, 7814, 7815, 7816, 7817,
7828, 7829, 7830, 7831), SECOND_TYPE(7818, 7823, 7819, 7820,
7821, 7822, 7824, 7825, 7826, 7827, 7832, 7833, 7834, 7835);
private int binEmpty;
private int closedBin;
private int binWithCompostable;
private int binFullOfCompostable;
private int binWithSuperCompostable;
private int binFullOFSuperCompostable;
private int binWithCompost;
private int binFullOfCompost;
private int binWithSuperCompost;
private int binFullOfSuperCompost;
private int binWithTomatoes;
private int binFullOfTomatoes;
private int binWithRottenTomatoes;
private int binFullOfRottenTomatoes;
private static Map<Integer, CompostBinStages> bins = new HashMap<Integer, CompostBinStages>();
static {
for (CompostBinStages data : CompostBinStages.values()) {
bins.put(data.binEmpty, data);
}
}
CompostBinStages(int binEmpty, int closedBin, int binWithCompostable,
int binFullOfCompostable, int binWithSuperCompostable,
int binFullOFSuperCompostable, int binWithCompost,
int binFullOfCompost, int binWithSuperCompost,
int binFullOfSuperCompost, int binWithTomatoes,
int binFullOfTomatoes, int binWithRottenTomatoes,
int binFullOfRottenTomatoes) {
this.binEmpty = binEmpty;
this.closedBin = closedBin;
this.binWithCompostable = binWithCompostable;
this.binFullOfCompostable = binFullOfCompostable;
this.binWithSuperCompostable = binWithSuperCompostable;
this.binFullOFSuperCompostable = binFullOFSuperCompostable;
this.binWithCompost = binWithCompost;
this.binFullOfCompost = binFullOfCompost;
this.binWithSuperCompost = binWithSuperCompost;
this.binFullOfSuperCompost = binFullOfSuperCompost;
this.binWithTomatoes = binWithTomatoes;
this.binFullOfTomatoes = binFullOfTomatoes;
this.binWithRottenTomatoes = binWithRottenTomatoes;
this.binFullOfRottenTomatoes = binFullOfRottenTomatoes;
}
public static CompostBinStages forId(int binId) {
return bins.get(binId);
}
public int getBinEmpty() {
return binEmpty;
}
public int getClosedBin() {
return closedBin;
}
public int getBinWithCompostable() {
return binWithCompostable;
}
public int getBinFullOfCompostable() {
return binFullOfCompostable;
}
public int getBinWithSuperCompostable() {
return binWithSuperCompostable;
}
public int getBinFullOFSuperCompostable() {
return binFullOFSuperCompostable;
}
public int getBinWithCompost() {
return binWithCompost;
}
public int getBinFullOfCompost() {
return binFullOfCompost;
}
public int getBinWithSuperCompost() {
return binWithSuperCompost;
}
public int getBinFullOfSuperCompost() {
return binFullOfSuperCompost;
}
public int getBinWithTomatoes() {
return binWithTomatoes;
}
public int getBinFullOfTomatoes() {
return binFullOfTomatoes;
}
public int getBinWithRottenTomatoes() {
return binWithRottenTomatoes;
}
public int getBinFullOfRottenTomatoes() {
return binFullOfRottenTomatoes;
}
}
/* handle compost bin updating */
private void updateCompostBin(int index) {
CompostBinStages compostBinStages = CompostBinStages
.forId(CompostBinLocations.forId(index).getBinObjectId());
if (compostBinStages == null) {
return;
}
int x = CompostBinLocations.forId(index).x;
int y = CompostBinLocations.forId(index).y;
int z = CompostBinLocations.forId(index).z;
int finalObject;
// handling the different ways to fill a compost bin
if (compostBins[index] > 0) {
if (compostBins[index] % 17 == 0) {
finalObject = compostBinStages.getBinWithSuperCompostable();
} else if (compostBins[index] % 77 == 0) {
finalObject = compostBinStages.getBinWithTomatoes();
} else {
finalObject = compostBinStages.getBinWithCompostable();
}
} else {
finalObject = compostBinStages.getBinEmpty();
}
// handling the different ways to complete a compost bin
if (compostBins[index] == 255) {
finalObject = compostBinStages.getBinFullOFSuperCompostable();
tempCompostState = 2;
} else if (compostBins[index] == 1155) {
finalObject = compostBinStages.getBinFullOfTomatoes();
tempCompostState = 3;
} else if (organicItemAdded[index] == 15) {
finalObject = compostBinStages.getBinFullOfCompostable();
tempCompostState = 1;
}
// handling the closed state of the compost bin
switch (compostBins[index]) {
case 100:
case 200:
case 300:
finalObject = compostBinStages.getClosedBin();
break;
// handling the rotted state of the compost in the bin
case 150:
finalObject = compostBinStages.getBinFullOfCompost();
break;
case 250:
finalObject = compostBinStages.getBinFullOfSuperCompost();
break;
case 350:
finalObject = compostBinStages.getBinFullOfRottenTomatoes();
break;
}
// handle the compost bin state when the player retrieve the compost
if (compostBins[index] == 150 && organicItemAdded[index] < 15) {
finalObject = compostBinStages.getBinWithCompost();
} else if (compostBins[index] == 250 && organicItemAdded[index] < 15) {
finalObject = compostBinStages.getBinWithSuperCompost();
}
if (compostBins[index] == 350 && organicItemAdded[index] < 15) {
finalObject = compostBinStages.getBinWithRottenTomatoes();
}
player.getPacketSender().object(finalObject, x, y, z,
CompostBinLocations.forId(index).getObjectFace(), 10);
}
/* handle what happens when the player close the compost bin */
public void closeCompostBin(final int index) {
compostBins[index] = tempCompostState * 100;
compostBinsTimer[index] = GameEngine.getMinutesCounter();
player.startAnimation(835, 0);
player.stopPlayer(true);
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
player.getPacketSender()
.sendMessage(
"You close the compost bin, and its content start to rot.");
updateCompostBin(index);
container.stop();
}
@Override
public void stop() {
player.stopPlayer(false);
}
}, 2);
}
/* handle what happens when the player opens the compost bin */
public void openCompostBin(final int index) {
// check if the time elapsed is enough to rot the compost
int timerRequired;
timerRequired = compostBins[index] == 200 ? 90 : 45;
if (GameEngine.getMinutesCounter() - compostBinsTimer[index] >= timerRequired) {
compostBins[index] += 50;
player.startAnimation(834, 0);
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
updateCompostBin(index);
container.stop();
}
@Override
public void stop() {
player.stopPlayer(false);
}
}, 2);
} else {
player.getPacketSender()
.sendMessage(
"The compost bin is still rotting. I should wait until it is complete.");
}
}
/* handle compost bin filling */
@SuppressWarnings("unused")
public void fillCompostBin(int x, int y, final int organicItemUsed) {
final CompostBinLocations compostBinLocations = CompostBinLocations
.forPosition(x, y);
final int index = compostBinLocations.getCompostIndex();
if (compostBinLocations == null) {
return;
}
int incrementFactor = 0;
// setting up the different increments.
for (int normalCompost : COMPOST_ORGANIC) {
if (organicItemUsed == normalCompost) {
incrementFactor = 2;
}
}
for (int superCompost : SUPER_COMPOST_ORGANIC) {
if (organicItemUsed == superCompost) {
incrementFactor = 17;
}
}
if (organicItemUsed == TOMATO) {
if (compostBins[index] % 77 == 0) {
incrementFactor = 77;
} else {
incrementFactor = 2;
}
}
// checking if the item used was an organic item.
if (incrementFactor == 0) {
player.getPacketSender()
.sendMessage(
"You need to put organic items into the compost bin in order to make compost.");
return;
}
final int factor = incrementFactor;
// launching the main event for filling the compost bin.
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
if (!player.getItemAssistant().playerHasItem(organicItemUsed)
|| organicItemAdded[index] == 15) {
container.stop();
return;
}
organicItemAdded[index]++;
player.startAnimation(832, 0);
player.getItemAssistant().deleteItem(organicItemUsed, 1);
compostBins[index] += factor;
updateCompostBin(index);
}
@Override
public void stop() {
player.getPlayerAssistant().resetAnimation();
}
}, 2);
}
// handle what happens when the player retrieve the compost
public void retrieveCompost(final int index) {
final int finalItem = compostBins[index] == 150 ? COMPOST : compostBins[index] == 250 ? SUPER_COMPOST : ROTTE_TOMATO;
player.startAnimation(832, 0);
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
if (!player.getItemAssistant().playerHasItem(1925)
&& compostBins[index] != 350
|| organicItemAdded[index] == 0) {
container.stop();
return;
}
player.getPlayerAssistant().addSkillXP(finalItem == COMPOST ? COMPOST_EXP_RETRIEVE
: finalItem == SUPER_COMPOST ? SUPER_COMPOST_EXP_RETRIEVE
: ROTTEN_TOMATOES_EXP_RETRIEVE, SkillConstants.FARMING.ordinal());
if (compostBins[index] != 350) {
player.getItemAssistant().deleteItem(1925, 1);
}
player.getItemAssistant().addItem(finalItem, 1);
player.startAnimation(832, 0);
organicItemAdded[index]--;
if (organicItemAdded[index] == 0) {
resetVariables(index);
}
updateCompostBin(index);
}
@Override
public void stop() {
player.getPlayerAssistant().resetAnimation();
}
}, 2);
}
/* handling the item on object method */
public boolean handleItemOnObject(int itemUsed, int objectId, int objectX,
int objectY) {
switch (objectId) {
case 7814:
case 7815:
case 7816:
case 7817:
case 7824:
case 7825:
case 7826:
case 7827:
if (itemUsed == 1925) {
retrieveCompost(CompostBinLocations.forPosition(objectX,
objectY).getCompostIndex());
} else {
player.getPacketSender().sendMessage(
"You might need some buckets to gather the compost.");
}
return true;
case 7839:
case 7838:
case 7837:
case 7836:
case 7808:
case 7809:
case 7811:
case 7819:
case 7821:
case 7828:
case 7832:
fillCompostBin(objectX, objectY, itemUsed);
return true;
}
return false;
}
/* handling the object click method */
public boolean handleObjectClick(int objectId, int objectX, int objectY) {
switch (objectId) {
case 7810:
case 7812:
case 7820:
case 7822:
case 7829:
case 7833:
closeCompostBin(CompostBinLocations.forPosition(objectX, objectY)
.getCompostIndex());
return true;
case 7813:
case 7823:
openCompostBin(CompostBinLocations.forPosition(objectX, objectY)
.getCompostIndex());
return true;
case 7830:
case 7831:
case 7834:
case 7835:
retrieveCompost(CompostBinLocations.forPosition(objectX, objectY)
.getCompostIndex());
return true;
}
return false;
}
/* reseting the compost variables */
public void resetVariables(int index) {
compostBins[index] = 0;
compostBinsTimer[index] = 0;
organicItemAdded[index] = 0;
}
}
@@ -0,0 +1,274 @@
package com.rebotted.game.content.skills.farming;
import java.util.HashMap;
import java.util.Map;
import com.rebotted.GameEngine;
import com.rebotted.game.dialogues.ChatEmotes;
import com.rebotted.game.items.ItemAssistant;
import com.rebotted.game.players.Player;
import com.rebotted.util.Misc;
/**
* Created by IntelliJ IDEA. User: vayken Date: 19/04/12 Time: 02:42 To change
* this template use File | Settings | File Templates.
*/
public class Farmers {
public static final String[][] farmingAdvices = {
{ "You don't have to buy all your plantpots you know,",
"you can make them yourself on a pottery wheel. If",
"you are a good enough craftsman, that is." },
{ "Don't just throw away your weeds after you've",
"raked a patch - put them in a compost bin and",
"make some compost." },
{ "Tree seeds must be grown in a plantpot of soil",
"into a tree sapling, and then transferred to a",
"tree patch to continue growing to adulthood." },
{ "You can put up to ten potatoes, cabbages, or",
"onions in vegetable sacks, although you can't",
"have a mix in the same sack." },
{ "You can buy all the farming tools from farming",
"shops which can be found close to the allotments" },
{ "You can fill plantpots with soil from Farming",
"patches, if you have a gardening trowel." },
{ "If you want to make your own sacks and baskets",
"you'll need to use the loom that's near the",
"Farming shop in Falador." },
{ "Bittercap mushrooms can only be grown in special",
"patches in Morytania, near the Mort Myre swamp." },
{ "Applying compost to a patch will not only reduce",
"the chance that your crops will get diseased, but",
"you will also grow more crops to harvest." },
{ "Hops are good for brewing ales. I believe there",
"is a brewery up in Keldagrim somewhere." } };
public enum FarmersData {
DANTAREA(2324, 41, "allotment", new String[] { "Northern patch",
"Southern patch" }), ELSTAN(2323, 54, "allotment",
new String[] { "North-west patch", "South-East patch" }), LYRA(
2326, 123, "allotment", new String[] { "North-west patch",
"South-East patch" }), KRAGEN(2325, 99, "allotment",
new String[] { "Northern patch", "Southern patch" }), RHAZIEN(
2337, 162, "bushes", null), TARIA(2336, 139, "bushes", null), DREVEN(
2335, 47, "bushes", null), TORREL(2338, 144, "bushes", null), RHONEN(
2334, 123, "hops", null), SELENA(2332, 134, "hops", null), VASQUEN(
2333, 153, "hops", null), FRANCIS(2327, 62, "hops", null), BOLONGO(
2343, 32, "fruitTree", null), ELLENA(2331, 53, "fruitTree",
null), GILEH(2344, 74, "fruitTree", null), GARTH(2330, 70,
"fruitTree", null), HESKEL(2340, 85, "tree", null), ALAIN(2339,
163, "tree", null), TREZNOR(2341, 146, "tree", null), FAYETH(
2342, 58, "tree", null);
private int npcId;
private int shopId;
private String fieldProtected;
private String[] dialogueOptions;
private static Map<Integer, FarmersData> npcs = new HashMap<Integer, FarmersData>();
static {
for (FarmersData data : FarmersData.values()) {
npcs.put(data.npcId, data);
}
}
FarmersData(int npcId, int shopId, String fieldProtected,
String[] dialogueOptions) {
this.npcId = npcId;
this.shopId = shopId;
this.fieldProtected = fieldProtected;
this.dialogueOptions = dialogueOptions;
}
public static FarmersData forId(int npcId) {
return npcs.get(npcId);
}
public int getNpcId() {
return npcId;
}
public String getFieldProtected() {
return fieldProtected;
}
public String[] getDialogueHandlerOptions() {
return dialogueOptions;
}
public int getShopId() {
return shopId;
}
}
public static void protectPlant(Player player, int indexArray,
String fieldType, int npcId, int stage) {
int index = 0;
int[] payment = new int[2];
if (stage == 1) {
if (fieldType == "allotment") {
index = Allotments.AllotmentFieldsData.listIndexProtected(npcId).get(indexArray);
if (Allotments.AllotmentData.forId(player.getAllotment().allotmentSeeds[index]) != null)
payment = Allotments.AllotmentData.forId(player.getAllotment().allotmentSeeds[index]).getPaymentToWatch();
if (player.getAllotment().allotmentStages[index] <= 3) {
player.getDialogueHandler().sendNpcChat(player.npcType, ChatEmotes.ANNOYED, "I am sorry but you have no crops growing in this patch.");
player.getDialogueHandler().endDialogue();
} else {
player.getDialogueHandler().sendNpcChat(player.npcType, ChatEmotes.NOT_INTERESTED, "If you like, but I want " + payment[1] + " " + getFinalPaymentString(ItemAssistant.getItemName(payment[0]).toLowerCase()) + (getFinalPaymentString(ItemAssistant.getItemName(payment[0]).toLowerCase()).endsWith("s") ? "" : "s") + " for that.");
player.nextChat = 3544;
player.setTempInteger(indexArray);
}
}
if (fieldType == "bushes") {
index = Bushes.BushesFieldsData.forId(npcId).getBushesIndex();
if (Bushes.BushesData.forId(player.getBushes().bushesSeeds[index]) != null)
payment = Bushes.BushesData.forId(player.getBushes().bushesSeeds[index]).getPaymentToWatch();
if (player.getBushes().bushesStages[index] <= 3) {
player.getDialogueHandler().sendNpcChat(player.npcType, ChatEmotes.ANNOYED, "I am sorry but you have no crops growing in this patch.");
player.getDialogueHandler().endDialogue();
} else {
player.getDialogueHandler().sendNpcChat(player.npcType, ChatEmotes.NOT_INTERESTED, "If you like, but I want " + payment[1] + " " + getFinalPaymentString(ItemAssistant.getItemName(payment[0]).toLowerCase()) + (getFinalPaymentString(ItemAssistant.getItemName(payment[0]).toLowerCase()).endsWith("s") ? "" : "s") + " for that.");
player.nextChat = 3544;
player.setTempInteger(indexArray);
}
}
if (fieldType == "fruitTree") {
index = FruitTree.FruitTreeFieldsData.forId(npcId).getFruitTreeIndex();
if (FruitTree.FruitTreeData.forId(player.getFruitTrees().fruitTreeSaplings[index]) != null)
payment = FruitTree.FruitTreeData.forId(player.getFruitTrees().fruitTreeSaplings[index]).getPaymentToWatch();
if (player.getFruitTrees().fruitTreeStages[index] <= 3) {
player.getDialogueHandler().sendNpcChat(player.npcType, ChatEmotes.ANNOYED, "I am sorry but you have no crops growing in this patch.");
player.getDialogueHandler().endDialogue();
} else {
player.getDialogueHandler().sendNpcChat(player.npcType, ChatEmotes.NOT_INTERESTED,"If you like, but I want " + payment[1] + " " + getFinalPaymentString(ItemAssistant.getItemName(payment[0]).toLowerCase()) + (getFinalPaymentString(ItemAssistant.getItemName(payment[0]).toLowerCase()).endsWith("s") ? "" : "s") + " for that.");
player.nextChat = 3544;
player.setTempInteger(indexArray);
}
}
if (fieldType == "hops") {
index = Hops.HopsFieldsData.forId(npcId).getHopsIndex();
if (Hops.HopsData.forId(player.getHops().hopsSeeds[index]) != null)
payment = Hops.HopsData.forId(player.getHops().hopsSeeds[index]).getPaymentToWatch();
if (player.getHops().hopsStages[index] <= 3) {
player.getDialogueHandler().sendNpcChat(player.npcType, ChatEmotes.ANNOYED, "I am sorry but you have no crops growing in this patch.");
player.getDialogueHandler().endDialogue();
} else {
player.getDialogueHandler().sendNpcChat(player.npcType, ChatEmotes.NOT_INTERESTED, "If you like, but I want " + payment[1] + " " + getFinalPaymentString(ItemAssistant.getItemName(payment[0]).toLowerCase()) + (getFinalPaymentString(ItemAssistant.getItemName(payment[0]).toLowerCase()).endsWith("s") ? "" : "s") + " for that.");
player.nextChat = 3544;
player.setTempInteger(indexArray);
}
}
if (fieldType == "tree") {
index = WoodTrees.TreeFieldsData.forId(npcId).getTreeIndex();
if (WoodTrees.TreeData.forId(player.getTrees().treeSaplings[index]) != null)
payment = WoodTrees.TreeData.forId(player.getTrees().treeSaplings[index]).getPaymentToWatch();
if (player.getTrees().treeStages[index] <= 3) {
player.getDialogueHandler().sendNpcChat(player.npcType, ChatEmotes.ANNOYED, "I am sorry but you have no crops growing in this patch.");
player.getDialogueHandler().endDialogue();
} else {
player.getDialogueHandler().sendNpcChat(player.npcType, ChatEmotes.NOT_INTERESTED, "If you like, but I want " + payment[1] + " " + getFinalPaymentString(ItemAssistant.getItemName(payment[0]).toLowerCase()) + (getFinalPaymentString(ItemAssistant.getItemName(payment[0]).toLowerCase()).endsWith("s") ? "" : "s") + " for that.");
player.nextChat = 3544;
player.setTempInteger(indexArray);
}
}
} else if (stage == 2) {
if (fieldType == "allotment") {
index = Allotments.AllotmentFieldsData
.listIndexProtected(npcId).get(indexArray);
payment = Allotments.AllotmentData.forId(
player.getAllotment().allotmentSeeds[index])
.getPaymentToWatch();
}
if (fieldType == "bushes") {
index = Bushes.BushesFieldsData.forId(npcId).getBushesIndex();
payment = Bushes.BushesData.forId(
player.getBushes().bushesSeeds[index])
.getPaymentToWatch();
}
if (fieldType == "fruitTree") {
index = FruitTree.FruitTreeFieldsData.forId(npcId)
.getFruitTreeIndex();
payment = Hops.HopsData.forId(
player.getFruitTrees().fruitTreeSaplings[index])
.getPaymentToWatch();
}
if (fieldType == "hops") {
index = Hops.HopsFieldsData.forId(npcId).getHopsIndex();
payment = Hops.HopsData
.forId(player.getHops().hopsSeeds[index])
.getPaymentToWatch();
}
if (fieldType == "tree") {
index = WoodTrees.TreeFieldsData.forId(npcId).getTreeIndex();
payment = WoodTrees.TreeData.forId(
player.getTrees().treeSaplings[index])
.getPaymentToWatch();
}
if (player.getItemAssistant().getItemAmount(payment[0]) < payment[1]) {
player.getDialogueHandler().sendNpcChat(player.npcType, ChatEmotes.DEFAULT, "Sorry, but you do not have the required items",
"I need, for letting me take care of this patch");
} else {
if (fieldType == "allotment") {
player.getAllotment().allotmentWatched[index] = true;
}
if (fieldType == "bushes") {
player.getBushes().bushesWatched[index] = true;
}
if (fieldType == "fruitTree") {
player.getFruitTrees().fruitTreeWatched[index] = true;
}
if (fieldType == "hops") {
player.getHops().hopsWatched[index] = true;
}
if (fieldType == "tree") {
player.getTrees().treeWatched[index] = true;
}
player.getItemAssistant().deleteItem(payment[0], payment[1]);
player.getDialogueHandler().sendNpcChat(player.npcType, ChatEmotes.DEFAULT, "Here you go, I will be taking care of this patch",
"as soon as it become diseased, I will cure it",
"so you don't have to worry about it.");
}
}
}
public static void chopDownTree(Player player, int npcId) {
int index = WoodTrees.TreeFieldsData.forId(npcId).getTreeIndex();
if (player.getItemAssistant().getItemCount(995) < 200) {
player.getDialogueHandler().sendNpcChat(player.npcType, ChatEmotes.DEFAULT, "I am sorry, but you do not have enough money",
"to pay me to chop down this tree.");
} else {
player.getItemAssistant().deleteItem(995, 200);
player.getDialogueHandler().sendNpcChat(player.npcType, ChatEmotes.DEFAULT, "There you go, I have chopped down your tree but I am ",
"keeping the logs and roots as compensation.");
player.getTrees().resetTrees(index);
player.getTrees().treeStages[index] = 3;
player.getTrees().treeTimer[index] = GameEngine.getMinutesCounter();
player.getTrees().updateTreeStates();
}
}
public static void sendFarmingAdvice(Player player) {
player.getDialogueHandler().sendNpcChat(player.npcType, ChatEmotes.HAPPY_JOYFUL, farmingAdvices[Misc.random(farmingAdvices.length - 1)]);
}
public static String getFinalPaymentString(String word) {
if (word.contains("(5)"))
return "baskets of " + word.replace("(5)", "");
if (word.contains("(10)"))
return "sacks of " + word.replace("(10)", "");
return word;
}
}
@@ -2,24 +2,296 @@ package com.rebotted.game.content.skills.farming;
import com.rebotted.game.players.Player;
/**
* Farming
* @author Andrew (Mr Extremez)
*/
public class Farming {
public static void openGuide(Player player, int objectType) {
if (Flowers.isFlower(player, objectType)) {
player.getSkillInterfaces().farmingComplex(6);
player.getSkillInterfaces().selected = 20;
} else if (Herbs.isHerb(player, objectType)) {
player.getSkillInterfaces().farmingComplex(7);
player.getSkillInterfaces().selected = 20;
} else if (Allotments.isAllotment(player, objectType)) {
player.getSkillInterfaces().farmingComplex(1);
player.getSkillInterfaces().selected = 20;
}
public static void processCalc(Player p) {
p.getAllotment().doCalculations();
p.getBushes().doCalculations();
p.getFlowers().doCalculations();
p.getFruitTrees().doCalculations();
p.getHerbs().doCalculations();
p.getHops().doCalculations();
p.getSpecialPlantOne().doCalculations();
p.getSpecialPlantTwo().doCalculations();
p.getTrees().doCalculations();
}
public static boolean prepareCrop(Player player, int item, int id, int x,
int y) {
// plant pot
if (player.getSeedling().fillPotWithSoil(item, x, y)) {
return true;
}
// // allotments
if (player.getAllotment().curePlant(x, y, item)) {
return true;
}
if (player.getAllotment().putCompost(x, y, item)) {
return true;
}
if (player.getAllotment().clearPatch(x, y, item)) {
return true;
}
if (item >= 3422 && item <= 3428 && id == 4090) {
player.getItemAssistant().deleteItem(item, 1);
player.getItemAssistant().addItem(item + 8, 1);
player.startAnimation(832);
player.getPacketSender()
.sendMessage(
"You put the olive oil on the fire, and turn it into sacred oil.");
return true;
}
if (item <= 5340 && item > 5332) {
if (player.getAllotment().waterPatch(x, y, item)) {
return true;
}
}
if (player.getAllotment().plantSeed(x, y, item)) {
return true;
}
// flowers
if (player.getFlowers().plantScareCrow(x, y, item)) {
return true;
}
if (player.getFlowers().curePlant(x, y, item)) {
return true;
}
if (player.getFlowers().putCompost(x, y, item)) {
return true;
}
if (player.getFlowers().clearPatch(x, y, item)) {
return true;
}
if (item <= 5340 && item > 5332) {
if (player.getFlowers().waterPatch(x, y, item)) {
return true;
}
}
if (player.getFlowers().plantSeed(x, y, item)) {
return true;
}
if (player.getCompost().handleItemOnObject(item, id, x, y)) {
return true;
}
// herbs
if (player.getHerbs().curePlant(x, y, item)) {
return true;
}
if (player.getHerbs().putCompost(x, y, item)) {
return true;
}
if (player.getHerbs().clearPatch(x, y, item)) {
return true;
}
if (player.getHerbs().plantSeed(x, y, item)) {
return true;
}
// hops
if (player.getHops().curePlant(x, y, item)) {
return true;
}
if (player.getHops().putCompost(x, y, item)) {
return true;
}
if (player.getHops().clearPatch(x, y, item)) {
return true;
}
if (item <= 5340 && item > 5332)
if (player.getHops().waterPatch(x, y, item)) {
return true;
}
if (player.getHops().plantSeed(x, y, item)) {
return true;
}
// bushes
if (player.getBushes().curePlant(x, y, item)) {
return true;
}
if (player.getBushes().putCompost(x, y, item)) {
return true;
}
if (player.getBushes().clearPatch(x, y, item)) {
return true;
}
if (player.getBushes().plantSeed(x, y, item)) {
return true;
}
// trees
if (player.getTrees().pruneArea(x, y, item)) {
return true;
}
if (player.getTrees().putCompost(x, y, item)) {
return true;
}
if (player.getTrees().plantSapling(x, y, item)) {
return true;
}
if (player.getTrees().clearPatch(x, y, item)) {
return true;
}
// fruit trees
if (player.getFruitTrees().pruneArea(x, y, item)) {
return true;
}
if (player.getFruitTrees().putCompost(x, y, item)) {
return true;
}
if (player.getFruitTrees().clearPatch(x, y, item)) {
return true;
}
if (player.getFruitTrees().plantSapling(x, y, item)) {
return true;
}
// special plant one
if (player.getSpecialPlantOne().curePlant(x, y, item)) {
return true;
}
if (player.getSpecialPlantOne().putCompost(x, y, item)) {
return true;
}
if (player.getSpecialPlantOne().clearPatch(x, y, item)) {
return true;
}
if (player.getSpecialPlantOne().plantSapling(x, y, item)) {
return true;
}
// Special plant two
if (player.getSpecialPlantTwo().curePlant(x, y, item)) {
return true;
}
if (player.getSpecialPlantTwo().putCompost(x, y, item)) {
return true;
}
if (player.getSpecialPlantTwo().clearPatch(x, y, item)) {
return true;
}
if (player.getSpecialPlantTwo().plantSeeds(x, y, item)) {
return true;
}
// player.sendMessage("Farming disabled - coming soon");
return false;
}
public static boolean inspectObject(Player player, int x, int y) {
// allotments
if (player.getAllotment().inspect(x, y)) {
return true;
} // flowers
if (player.getFlowers().inspect(x, y)) {
return true;
}
// herbs
if (player.getHerbs().inspect(x, y)) {
return true;
}
// hops
if (player.getHops().inspect(x, y)) {
return true;
}
// bushes
if (player.getBushes().inspect(x, y)) {
return true;
}
// trees
if (player.getTrees().inspect(x, y)) {
return true;
}
// fruit trees
if (player.getFruitTrees().inspect(x, y)) {
return true;
}
// special plant one
if (player.getSpecialPlantOne().inspect(x, y)) {
return true;
}
// special plant two
if (player.getSpecialPlantTwo().inspect(x, y)) {
return true;
}
return false;
}
public static boolean guide(Player player, int x, int y) {
// allotments
if (player.getAllotment().guide(x, y)) {
return true;
} // flowers
if (player.getFlowers().guide(x, y)) {
return true;
}
// herbs
if (player.getHerbs().guide(x, y)) {
return true;
}
// hops
if (player.getHops().guide(x, y)) {
return true;
}
// bushes
if (player.getBushes().guide(x, y)) {
return true;
}
// trees
if (player.getTrees().guide(x, y)) {
return true;
}
// fruit trees
if (player.getFruitTrees().guide(x, y)) {
return true;
}
// special plant one
if (player.getSpecialPlantOne().guide(x, y)) {
return true;
}
// special plant two
if (player.getSpecialPlantTwo().guide(x, y)) {
return true;
}
return false;
}
public static boolean harvest(Player player, int x, int y) {
// allotments
if (player.getAllotment().harvest(x, y)) {
return true;
}
// flowers
if (player.getFlowers().harvest(x, y)) {
return true;
}
// herbs
if (player.getHerbs().harvest(x, y)) {
return true;
}
// hops
if (player.getHops().harvest(x, y)) {
return true;
}
// bushes
if (player.getBushes().harvestOrCheckHealth(x, y)) {
return true;
}
// trees
if (player.getTrees().checkHealth(x, y)) {
return true;
}
if (player.getTrees().cut(x, y)) {
return true;
}
// fruit trees
if (player.getFruitTrees().harvestOrCheckHealth(x, y)) {
return true;
}
// special plant one
if (player.getSpecialPlantOne().harvestOrCheckHealth(x, y)) {
return true;
}
// special plant two
if (player.getSpecialPlantTwo().harvestOrCheckHealth(x, y)) {
return true;
}
return false;
}
}
@@ -1,7 +1,25 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.rebotted.game.content.skills.farming;
public class FarmingConstants {
import java.awt.Point;
/**
*
* @author ArrowzFtw
*/
/**
* Created by IntelliJ IDEA. User: vayken Date: 25/02/12 Time: 16:39 To change
* this template use File | Settings | File Templates.
*/
public class FarmingConstants {// todo farmers watching crops
// payment to farmer
// todo sack making with jute, sack filling with
// items
public static final int WATERING_CAN_ANIM = 2293;
public static final int RAKING_ANIM = 2273;
public static final int SPADE_ANIM = 830;
@@ -13,6 +31,10 @@ public class FarmingConstants {
public static final int FILLING_POT_ANIM = 2287;
public static final int PLANTING_POT_ANIM = 2272;
public static final int PRUNING_ANIM = 2275;
public static final int GRASS_OBJECT = 8389;
public static final int HERB_OBJECT = 8143;
public static final int HERB_PATCH_DEPLETED = 8388;
public static final int RAKE = 5341;
public static final int SEED_DIBBER = 5343;
@@ -21,5 +43,16 @@ public class FarmingConstants {
public static final int SECATEURS = 5329;
public static final int MAGIC_SECATEURS = 7409;
public static final int[] WATERED_SAPPLING = {5364, 5365, 5366, 5367, 5368, 5369, 5488, 5489, 5490, 5491, 5492, 5493, 5494, 5495};
public static final int[] WATERED_SAPPLING = { 5364, 5365, 5366, 5367,
5368, 5369, 5488, 5489, 5490, 5491, 5492, 5493, 5494, 5495 };
public static boolean inRangeArea(Point base, Point top, Point point) {
return point.getX() >= base.getX() && point.getY() >= base.getY()
&& point.getX() <= top.getX() && point.getY() <= top.getY();
}
public static boolean inRangeArea(Point base, Point top, int x, int y) {
return x >= base.getX() && y >= base.getY() && x <= top.getX()
&& y <= top.getY();
}
}
@@ -0,0 +1,19 @@
package com.rebotted.game.content.skills.farming;
import com.rebotted.game.players.Player;
import com.rebotted.tick.Tick;
public class FarmingTask extends Tick {
private Player player;
public FarmingTask(Player player) {
super(10);
this.player = player;
}
@Override
protected void execute() {
Farming.processCalc(player);
}
}
@@ -1,23 +1,895 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.rebotted.game.content.skills.farming;
import com.rebotted.game.players.Player;
/**
*
* @author ArrowzFtw
*/
import java.awt.Point;
import java.util.HashMap;
import java.util.Map;
import com.rebotted.GameEngine;
import com.rebotted.event.CycleEvent;
import com.rebotted.event.CycleEventContainer;
import com.rebotted.event.CycleEventHandler;
import com.rebotted.game.content.skills.SkillConstants;
import com.rebotted.game.players.Player;
import com.rebotted.util.Misc;
/**
* Flowers
* @author Andrew (I'm A Boss on Rune-Server and Mr Extremez on Mopar & Runelocus)
* Created by IntelliJ IDEA. User: vayken Date: 24/02/12 Time: 20:34 To change
* this template use File | Settings | File Templates.
*/
public class Flowers { // todo scarecrow 6059
public class Flowers {
private static final int[] FLOWER_PATCH = {7847, 7848};
public static boolean isFlower(Player player, int objectType) {
for (int i = 0; i < FLOWER_PATCH.length; i++) {
if (objectType == FLOWER_PATCH[i]) {
return true;
private Player player;
// set of global constants for Farming
private static final double WATERING_CHANCE = 0.5;
private static final double COMPOST_CHANCE = 0.9;
private static final double SUPERCOMPOST_CHANCE = 0.7;
private static final double CLEARING_EXPERIENCE = 4;
public static final int SCARECROW = 6059;
public Flowers(Player player) {
this.player = player;
}
// Farming data
public int[] flowerStages = new int[4];
public int[] flowerSeeds = new int[4];
public int[] flowerState = new int[4];
public long[] flowerTimer = new long[4];
public double[] diseaseChance = { 1, 1, 1, 1 };
public boolean[] hasFullyGrown = { false, false, false, false };
/* set of the constants for the patch */
// states - 2 bits plant - 6 bits
public static final int GROWING = 0x00;
public static final int WATERED = 0x01;
public static final int DISEASED = 0x02;
public static final int DEAD = 0x03;
public static final int FLOWER_PATCH_CONFIGS = 508;
/* This is the enum holding the seeds info */
public enum FlowerData {
MARIGOLD(5096, 6010, 2, 20, 0.35, 8.5, 47, 0x08, 0x0c), ROSEMARY(5097,
6014, 11, 20, 0.32, 12, 66.5, 0x0d, 0x11), NASTURTIUM(5098,
6012, 24, 20, 0.30, 19.5, 111, 0x12, 0x16), WOAD(5099, 1793,
25, 20, 0.27, 20.5, 115.5, 0x17, 0x1b), LIMPWURT(5100, 225, 26,
25, 21.5, 8.5, 120, 0x1c, 0x20), ;
private int seedId;
private int harvestId;
private int levelRequired;
private int growthTime;
private double diseaseChance;
private double plantingXp;
private double harvestXp;
private int startingState;
private int endingState;
private static Map<Integer, FlowerData> seeds = new HashMap<Integer, FlowerData>();
static {
for (FlowerData data : FlowerData.values()) {
seeds.put(data.seedId, data);
}
}
FlowerData(int seedId, int harvestId, int levelRequired,
int growthTime, double diseaseChance, double plantingXp,
double harvestXp, int startingState, int endingState) {
this.seedId = seedId;
this.harvestId = harvestId;
this.levelRequired = levelRequired;
this.growthTime = growthTime;
this.diseaseChance = diseaseChance;
this.plantingXp = plantingXp;
this.harvestXp = harvestXp;
this.startingState = startingState;
this.endingState = endingState;
}
public static FlowerData forId(int seedId) {
return seeds.get(seedId);
}
public int getSeedId() {
return seedId;
}
public int getHarvestId() {
return harvestId;
}
public int getLevelRequired() {
return levelRequired;
}
public int getGrowthTime() {
return growthTime;
}
public double getDiseaseChance() {
return diseaseChance;
}
public double getPlantingXp() {
return plantingXp;
}
public double getHarvestXp() {
return harvestXp;
}
public int getStartingState() {
return startingState;
}
public int getEndingState() {
return endingState;
}
}
/* This is the enum data about the different patches */
public enum FlowerFieldsData {
ARDOUGNE(0,
new Point[] { new Point(2666, 3374), new Point(2667, 3375) }), PHASMATYS(
1, new Point[] { new Point(3601, 3525), new Point(3602, 3526) }), FALADOR(
2, new Point[] { new Point(3054, 3307), new Point(3055, 3308) }), CATHERBY(
3, new Point[] { new Point(2809, 3463), new Point(2810, 3464) });
private int flowerIndex;
private Point[] flowerPosition;
FlowerFieldsData(int flowerIndex, Point[] flowerPosition) {
this.flowerIndex = flowerIndex;
this.flowerPosition = flowerPosition;
}
public static FlowerFieldsData forIdPosition(Point point) {
for (FlowerFieldsData flowerFieldsData : FlowerFieldsData.values()) {
if (FarmingConstants.inRangeArea(
flowerFieldsData.getFlowerPosition()[0],
flowerFieldsData.getFlowerPosition()[1], point)) {
return flowerFieldsData;
}
}
return null;
}
public int getFlowerIndex() {
return flowerIndex;
}
public Point[] getFlowerPosition() {
return flowerPosition;
}
}
/* This is the enum that hold the different data for inspecting the plant */
public enum InspectData {
MARIGOLD(5096, new String[][] {
{ "The seeds have only just been planted." },
{ "The marigold plants have developed leaves." },
{ "The marigold plants have begun to grow their",
"flowers. The new flowers are orange and small at",
"first." },
{ "The marigold plants are larger, and more",
"developed in their petals." },
{ "The marigold plants are ready to harvest. Their",
"flowers are fully matured." } }), ROSEMARY(5097,
new String[][] {
{ "The seeds have only just been planted." },
{ "The rosemary plant is taller than before." },
{ "The rosemary plant is bushier and taller than",
"before." },
{ "The rosemary plant is developing a flower bud at",
"its top." },
{ "The plant is ready to harvest. The rosemary",
"plant's flower has opened." } }), NASTURTIUM(
5098,
new String[][] {
{ "The nasturtium seed has only just been planted." },
{ "The nasturtium plants have started to develop",
"leaves." },
{ "The nasturtium plants have grown more leaves,",
"and nine flower buds." },
{ "The nasturtium plants open their flower buds." },
{
"The plants are ready to harvest. The nasturtium",
"plants grow larger than before and the flowers",
"fully open." } }), WOAD(5099, new String[][] {
{ "The woad seed has only just been planted." },
{ "The woad plant produces more stalks, that split",
"in tow near the top." },
{ "The woad plant grows more segments from its",
"intitial stalks." },
{ "The woad plant develops flower buds on the end",
"of each of its stalks." },
{ "The woad plant is ready to harvest. The plant has",
"all of its stalks pointing directly up, with",
"all flowers open." } }), LIMPWURT(
5100,
new String[][] {
{ "The seed has only just been planted." },
{ "The limpwurt plant produces more roots." },
{ "The limpwurt plant produces an unopened pink",
"flower bud and continues to grow larger." },
{ "The limpwurt plant grows larger, with more loops",
"in its roots. The flower bud is still unopened." },
{
"The limpwurt plant is ready to harvest. The",
"flower finally opens wide, with a spike in the",
"middle." } });
private int seedId;
private String[][] messages;
private static Map<Integer, InspectData> seeds = new HashMap<Integer, InspectData>();
static {
for (InspectData data : InspectData.values()) {
seeds.put(data.seedId, data);
}
}
InspectData(int seedId, String[][] messages) {
this.seedId = seedId;
this.messages = messages;
}
public static InspectData forId(int seedId) {
return seeds.get(seedId);
}
public int getSeedId() {
return seedId;
}
public String[][] getMessages() {
return messages;
}
}
/* update all the patch states */
public void updateFlowerStates() {
// ardougne - phasmatys - falador - catherby
int[] configValues = new int[flowerStages.length];
int configValue;
for (int i = 0; i < flowerStages.length; i++) {
configValues[i] = getConfigValue(flowerStages[i], flowerSeeds[i],
flowerState[i], i);
}
configValue = (configValues[0] << 16) + (configValues[1] << 8 << 16)
+ configValues[2] + (configValues[3] << 8);
player.getPacketSender().sendConfig(FLOWER_PATCH_CONFIGS, configValue);
}
/* getting the different config values */
public int getConfigValue(int flowerStage, int seedId, int plantState,
int index) {
if (flowerSeeds[index] >= 0x21 && flowerSeeds[index] <= 0x24
&& flowerStages[index] > 3) {
return (GROWING << 6) + flowerSeeds[index];
}
FlowerData flowerData = FlowerData.forId(seedId);
switch (flowerStage) {
case 0:// weed
return (GROWING << 6) + 0x00;
case 1:// weed cleared
return (GROWING << 6) + 0x01;
case 2:
return (GROWING << 6) + 0x02;
case 3:
return (GROWING << 6) + 0x03;
}
if (flowerData == null) {
return -1;
}
if (flowerData.getEndingState() == flowerData.getStartingState()
+ flowerStage - 2) {
hasFullyGrown[index] = true;
}
return (getPlantState(plantState) << 6) + flowerData.getStartingState()
+ flowerStage - 4;
}
/* getting the plant states */
public int getPlantState(int plantState) {
switch (plantState) {
case 0:
return GROWING;
case 1:
return WATERED;
case 2:
return DISEASED;
case 3:
return DEAD;
}
return -1;
}
/* calculating the disease chance and making the plant grow */
public void doCalculations() {
for (int i = 0; i < flowerSeeds.length; i++) {
if (flowerStages[i] > 0 && flowerStages[i] <= 3
&& GameEngine.getMinutesCounter() - flowerTimer[i] >= 5) {
flowerStages[i]--;
flowerTimer[i] = GameEngine.getMinutesCounter();
updateFlowerStates();
}
if (GameEngine.getMinutesCounter() - flowerTimer[i] >= 5
&& flowerSeeds[i] > 0x21 && flowerSeeds[i] <= 0x24) {
flowerSeeds[i]--;
updateFlowerStates();
return;
}
FlowerData flowerData = FlowerData.forId(flowerSeeds[i]);
if (flowerData == null) {
continue;
}
long difference = GameEngine.getMinutesCounter() - flowerTimer[i];
long growth = flowerData.getGrowthTime();
int nbStates = flowerData.getEndingState()
- flowerData.getStartingState();
int state = (int) (difference * nbStates / growth);
if (flowerState[i] == 3 || flowerSeeds[i] == 0x21
|| flowerTimer[i] == 0 || state > nbStates) {
continue;
}
if (4 + state != flowerStages[i]) {
flowerStages[i] = 4 + state;
doStateCalculation(i);
updateFlowerStates();
}
}
}
/* calculations about the diseasing chance */
public void doStateCalculation(int index) {
if (flowerState[index] == 3) {
return;
}
// if the patch is diseased, it dies, if its watched by a farmer, it
// goes back to normal
if (flowerState[index] == 2) {
flowerState[index] = 3;
}
if (flowerState[index] == 1 || flowerState[index] == 5
&& flowerStages[index] != 3) {
diseaseChance[index] *= 2;
flowerState[index] = 0;
}
if (flowerState[index] == 0 && flowerStages[index] >= 5
&& !hasFullyGrown[index]) {
FlowerData flowerData = FlowerData.forId(flowerSeeds[index]);
if (flowerData == null) {
return;
}
double chance = diseaseChance[index]
* flowerData.getDiseaseChance();
int maxChance = (int) (chance * 100);
if (Misc.random(100) <= maxChance) {
flowerState[index] = 2;
}
}
}
/* watering the patch */
public boolean waterPatch(int objectX, int objectY, int itemId) {
final FlowerFieldsData flowerFieldsData = FlowerFieldsData
.forIdPosition(new Point(objectX, objectY));
if (flowerFieldsData == null) {
return false;
}
FlowerData flowerData = FlowerData.forId(flowerSeeds[flowerFieldsData
.getFlowerIndex()]);
if (flowerData == null) {
return false;
}
if (!SkillConstants.getEnabled(SkillConstants.FARMING.ordinal())) {
player.getPacketSender().sendMessage("This skill is currently disabled.");
return true;
}
if (flowerState[flowerFieldsData.getFlowerIndex()] == 1
|| flowerStages[flowerFieldsData.getFlowerIndex()] <= 1
|| flowerStages[flowerFieldsData.getFlowerIndex()] == flowerData
.getEndingState() - flowerData.getStartingState() + 4) {
player.getPacketSender().sendMessage("This patch doesn't need watering.");
return true;
}
player.getItemAssistant().deleteItem(itemId, 1);
player.getItemAssistant().addItem(itemId == 5333 ? itemId - 2 : itemId - 1, 1);
if (!player.getItemAssistant().playerHasItem(FarmingConstants.RAKE)) {
player.getDialogueHandler().sendStatement(
"You need a seed dibber to plant seed here.");
return true;
}
player.getPacketSender().sendMessage("You water the patch.");
player.startAnimation(
FarmingConstants.WATERING_CAN_ANIM);
player.stopPlayer(true);
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
diseaseChance[flowerFieldsData.getFlowerIndex()] *= WATERING_CHANCE;
flowerState[flowerFieldsData.getFlowerIndex()] = 1;
container.stop();
}
@Override
public void stop() {
updateFlowerStates();
player.stopPlayer(false);
player.getPlayerAssistant().resetAnimation();
}
}, 5);
return true;
}
/* clearing the patch with a rake of a spade */
public boolean clearPatch(int objectX, int objectY, int itemId) {
final FlowerFieldsData flowerFieldsData = FlowerFieldsData
.forIdPosition(new Point(objectX, objectY));
int finalAnimation;
int finalDelay;
if (flowerFieldsData == null
|| (itemId != FarmingConstants.RAKE && itemId != FarmingConstants.SPADE)) {
return false;
}
if (flowerStages[flowerFieldsData.getFlowerIndex()] == 3) {
return true;
}
if (!SkillConstants.getEnabled(SkillConstants.FARMING.ordinal())) {
player.getPacketSender().sendMessage("This skill is currently disabled.");
return true;
}
if (flowerStages[flowerFieldsData.getFlowerIndex()] <= 3) {
if (!player.getItemAssistant().playerHasItem(FarmingConstants.RAKE)) {
player.getDialogueHandler().sendStatement(
"You need a rake to clear this path.");
return true;
} else {
finalAnimation = FarmingConstants.RAKING_ANIM;
finalDelay = 5;
}
} else {
if (!player.getItemAssistant().playerHasItem(FarmingConstants.SPADE)) {
player.getDialogueHandler().sendStatement(
"You need a spade to clear this path.");
return true;
} else {
finalAnimation = FarmingConstants.SPADE_ANIM;
finalDelay = 3;
}
}
final int animation = finalAnimation;
player.stopPlayer(true);
player.startAnimation(animation);
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
player.startAnimation(animation);
if (flowerStages[flowerFieldsData.getFlowerIndex()] <= 2) {
flowerStages[flowerFieldsData.getFlowerIndex()]++;
player.getItemAssistant().addItem(6055, 1);
} else {
flowerStages[flowerFieldsData.getFlowerIndex()] = 3;
container.stop();
}
player.getPlayerAssistant().addSkillXP(CLEARING_EXPERIENCE, SkillConstants.FARMING.ordinal());
flowerTimer[flowerFieldsData.getFlowerIndex()] = GameEngine
.getMinutesCounter();
updateFlowerStates();
if (flowerStages[flowerFieldsData.getFlowerIndex()] == 3) {
container.stop();
return;
}
}
@Override
public void stop() {
resetFlowers(flowerFieldsData.getFlowerIndex());
player.getPacketSender().sendMessage("You clear the patch.");
player.stopPlayer(false);
player.getPlayerAssistant().resetAnimation();
}
}, finalDelay);
return true;
}
/* planting the seeds */
public boolean plantSeed(int objectX, int objectY, final int seedId) {
final FlowerFieldsData flowerFieldsData = FlowerFieldsData
.forIdPosition(new Point(objectX, objectY));
final FlowerData flowerData = FlowerData.forId(seedId);
if (flowerFieldsData == null || flowerData == null) {
return false;
}
if (!SkillConstants.getEnabled(SkillConstants.FARMING.ordinal())) {
player.getPacketSender().sendMessage("This skill is currently disabled.");
return true;
}
if (flowerStages[flowerFieldsData.getFlowerIndex()] != 3) {
player.getDialogueHandler().sendStatement(
"You can't plant a seed here.");
return false;
}
if (flowerData.getLevelRequired() > player.playerLevel[SkillConstants.FARMING.ordinal()]) {
player.getDialogueHandler().sendStatement( "You need a farming level of "
+ flowerData.getLevelRequired()
+ " to plant this seed.");
return true;
}
if (!player.getItemAssistant().playerHasItem(FarmingConstants.SEED_DIBBER)) {
player.getDialogueHandler().sendStatement(
"You need a seed dibber to plant seed here.");
return true;
}
player.startAnimation(FarmingConstants.SEED_DIBBING);
flowerStages[flowerFieldsData.getFlowerIndex()] = 4;
player.getItemAssistant().deleteItem(seedId, 1);
player.stopPlayer(true);
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
flowerState[flowerFieldsData.getFlowerIndex()] = 0;
flowerSeeds[flowerFieldsData.getFlowerIndex()] = seedId;
flowerTimer[flowerFieldsData.getFlowerIndex()] = GameEngine
.getMinutesCounter();
player.getPlayerAssistant().addSkillXP(flowerData.getPlantingXp(), SkillConstants.FARMING.ordinal());
container.stop();
}
@Override
public void stop() {
updateFlowerStates();
player.stopPlayer(false);
}
}, 3);
return true;
}
@SuppressWarnings("unused")
private void displayAll() {
for (int i = 0; i < flowerStages.length; i++) {
System.out.println("index : " + i);
System.out.println("state : " + flowerState[i]);
System.out.println("seeds : " + flowerSeeds[i]);
System.out.println("level : " + flowerStages[i]);
System.out.println("timer : " + flowerTimer[i]);
System.out.println("disease chance : " + diseaseChance[i]);
System.out
.println("-----------------------------------------------------------------");
}
}
/* harvesting the plant resulted */
public boolean harvest(int objectX, int objectY) {
final FlowerFieldsData flowerFieldsData = FlowerFieldsData
.forIdPosition(new Point(objectX, objectY));
if (flowerFieldsData == null) {
return false;
}
final FlowerData flowerData = FlowerData
.forId(flowerSeeds[flowerFieldsData.getFlowerIndex()]);
if (flowerData == null) {
return false;
}
if (!SkillConstants.getEnabled(SkillConstants.FARMING.ordinal())) {
player.getPacketSender().sendMessage("This skill is currently disabled.");
return true;
}
if (!player.getItemAssistant().playerHasItem(FarmingConstants.SPADE)) {
player.getDialogueHandler().sendStatement(
"You need a spade to harvest here.");
return true;
}
player.startAnimation(FarmingConstants.SPADE_ANIM);
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
resetFlowers(flowerFieldsData.getFlowerIndex());
flowerStages[flowerFieldsData.getFlowerIndex()] = 3;
flowerTimer[flowerFieldsData.getFlowerIndex()] = GameEngine
.getMinutesCounter();
player.startAnimation(
FarmingConstants.SPADE_ANIM);
player.getPacketSender().sendMessage(
"You harvest the crop, and get some vegetables.");
player.getItemAssistant().addItem(flowerData.getHarvestId(), flowerData.getHarvestId() == 5099 || flowerData.getHarvestId() == 5100 ? 3 : 1);
player.getPlayerAssistant().addSkillXP(flowerData.getHarvestXp(), SkillConstants.FARMING.ordinal());
container.stop();
}
@Override
public void stop() {
updateFlowerStates();
player.getPlayerAssistant().resetAnimation();
}
}, 2);
return true;
}
/* putting compost onto the plant */
public boolean putCompost(int objectX, int objectY, final int itemId) {
if (itemId != 6032 && itemId != 6034) {
return false;
}
final FlowerFieldsData flowerFieldsData = FlowerFieldsData
.forIdPosition(new Point(objectX, objectY));
if (flowerFieldsData == null) {
return false;
}
if (!SkillConstants.getEnabled(SkillConstants.FARMING.ordinal())) {
player.getPacketSender().sendMessage("This skill is currently disabled.");
return true;
}
if (flowerStages[flowerFieldsData.getFlowerIndex()] != 3
|| flowerState[flowerFieldsData.getFlowerIndex()] == 5) {
player.getPacketSender().sendMessage("This patch doesn't need compost.");
return true;
}
player.getItemAssistant().deleteItem(itemId, 1);
player.getItemAssistant().addItem(1925, 1);
player.getPacketSender().sendMessage(
"You pour some " + (itemId == 6034 ? "super" : "")
+ "compost on the patch.");
player.startAnimation(FarmingConstants.PUTTING_COMPOST);
player.getPlayerAssistant().addSkillXP(itemId == 6034 ? Compost.SUPER_COMPOST_EXP_USE : Compost.COMPOST_EXP_USE, SkillConstants.FARMING.ordinal());
player.stopPlayer(true);
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
diseaseChance[flowerFieldsData.getFlowerIndex()] *= itemId == 6032 ? COMPOST_CHANCE
: SUPERCOMPOST_CHANCE;
flowerState[flowerFieldsData.getFlowerIndex()] = 5;
container.stop();
}
@Override
public void stop() {
player.stopPlayer(false);
player.getPlayerAssistant().resetAnimation();
}
}, 7);
return true;
}
/* inspecting a plant */
public boolean inspect(int objectX, int objectY) {
final FlowerFieldsData flowerFieldsData = FlowerFieldsData
.forIdPosition(new Point(objectX, objectY));
if (flowerFieldsData == null) {
return false;
}
if (!SkillConstants.getEnabled(SkillConstants.FARMING.ordinal())) {
player.getPacketSender().sendMessage("This skill is currently disabled.");
return true;
}
final InspectData inspectData = InspectData
.forId(flowerSeeds[flowerFieldsData.getFlowerIndex()]);
final FlowerData flowerData = FlowerData
.forId(flowerSeeds[flowerFieldsData.getFlowerIndex()]);
if (flowerState[flowerFieldsData.getFlowerIndex()] == 2) {
player.getDialogueHandler().sendStatement("This plant is diseased. Use a plant cure on it to cure it, ",
"or clear the patch with a spade.");
return true;
} else if (flowerState[flowerFieldsData.getFlowerIndex()] == 3) {
player.getDialogueHandler().sendStatement("This plant is dead. You did not cure it while it was diseased.",
"Clear the patch with a spade.");
return true;
}
if (flowerStages[flowerFieldsData.getFlowerIndex()] == 0) {
player.getDialogueHandler().sendStatement(
"This is a flower patch. The soil has not been treated.",
"The patch needs weeding.");
} else if (flowerStages[flowerFieldsData.getFlowerIndex()] == 3) {
player.getDialogueHandler().sendStatement(
"This is a flower patch. The soil has not been treated.",
"The patch is empty and weeded.");
} else if (inspectData != null && flowerData != null) {
player.getPacketSender().sendMessage(
"You bend down and start to inspect the patch...");
player.startAnimation(1331);
player.stopPlayer(true);
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
if (flowerStages[flowerFieldsData.getFlowerIndex()] - 4 < inspectData
.getMessages().length - 2) {
player.getDialogueHandler().sendStatement( inspectData
.getMessages()[flowerStages[flowerFieldsData
.getFlowerIndex()] - 4]);
} else if (flowerStages[flowerFieldsData.getFlowerIndex()] < flowerData
.getEndingState()
- flowerData.getStartingState()
+ 4) {
player.getDialogueHandler().sendStatement(
inspectData.getMessages()[inspectData
.getMessages().length - 2]);
} else {
player.getDialogueHandler().sendStatement(
inspectData.getMessages()[inspectData
.getMessages().length - 1]);
}
container.stop();
}
@Override
public void stop() {
player.startAnimation(1332);
player.stopPlayer(false);
// player.reset();
}
}, 5);
}
return true;
}
/* opening the corresponding guide about the patch */
public boolean guide(int objectX, int objectY) {
final FlowerFieldsData flowerFieldsData = FlowerFieldsData
.forIdPosition(new Point(objectX, objectY));
if (flowerFieldsData == null) {
return false;
}
if (!SkillConstants.getEnabled(SkillConstants.FARMING.ordinal())) {
player.getPacketSender().sendMessage("This skill is currently disabled.");
return true;
}
player.getSkillInterfaces().farmingComplex(6);
player.getSkillInterfaces().selected = 20;
return true;
}
/* Curing the plant */
public boolean curePlant(int objectX, int objectY, int itemId) {
final FlowerFieldsData flowerFieldsData = FlowerFieldsData
.forIdPosition(new Point(objectX, objectY));
if (flowerFieldsData == null || itemId != 6036) {
return false;
}
final FlowerData flowerData = FlowerData
.forId(flowerSeeds[flowerFieldsData.getFlowerIndex()]);
if (flowerData == null) {
return false;
}
if (!SkillConstants.getEnabled(SkillConstants.FARMING.ordinal())) {
player.getPacketSender().sendMessage("This skill is currently disabled.");
return true;
}
if (flowerState[flowerFieldsData.getFlowerIndex()] != 2) {
player.getPacketSender().sendMessage("This plant doesn't need to be cured.");
return true;
}
player.getItemAssistant().deleteItem(itemId, 1);
player.getItemAssistant().addItem(229, 1);
player.startAnimation(FarmingConstants.CURING_ANIM);
flowerState[flowerFieldsData.getFlowerIndex()] = 0;
player.stopPlayer(true);
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
player.getPacketSender().sendMessage(
"You cure the plant with a plant cure.");
container.stop();
}
@Override
public void stop() {
updateFlowerStates();
player.stopPlayer(false);
player.getPlayerAssistant().resetAnimation();
}
}, 7);
return true;
}
/* Planting scarecrow to push off the birds */
public boolean plantScareCrow(int objectX, int objectY, int itemId) {
final FlowerFieldsData flowerFieldsData = FlowerFieldsData
.forIdPosition(new Point(objectX, objectY));
if (flowerFieldsData == null || itemId != SCARECROW) {
return false;
}
if (!SkillConstants.getEnabled(SkillConstants.FARMING.ordinal())) {
player.getPacketSender().sendMessage("This skill is currently disabled.");
return true;
}
if (flowerStages[flowerFieldsData.getFlowerIndex()] != 3) {
player.getPacketSender().sendMessage(
"You need to clear the patch before planting a scarecrow");
return false;
}
player.getItemAssistant().deleteItem(SCARECROW, 1);
player.startAnimation(832);
player.stopPlayer(true);
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
player.getPacketSender()
.sendMessage(
"You put a scarecrow on the flower patch, and some weeds start to grow around it.");
flowerSeeds[flowerFieldsData.getFlowerIndex()] = 0x24;
flowerStages[flowerFieldsData.getFlowerIndex()] = 4;
flowerTimer[flowerFieldsData.getFlowerIndex()] = GameEngine
.getMinutesCounter();
container.stop();
}
@Override
public void stop() {
updateFlowerStates();
player.stopPlayer(false);
player.getPlayerAssistant().resetAnimation();
}
}, 2);
return true;
}
/* reseting the patches */
private void resetFlowers(int index) {
flowerSeeds[index] = 0;
flowerState[index] = 0;
diseaseChance[index] = 1;
}
/* checking if the patch is raked */
public boolean checkIfRaked(int objectX, int objectY) {
final FlowerFieldsData flowerFieldsData = FlowerFieldsData
.forIdPosition(new Point(objectX, objectY));
if (flowerFieldsData == null)
return false;
if (flowerStages[flowerFieldsData.getFlowerIndex()] == 3)
return true;
return false;
}
@@ -1,24 +1,835 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.rebotted.game.content.skills.farming;
/**
*
* @author ArrowzFtw
*/
import java.awt.Point;
import java.util.HashMap;
import java.util.Map;
import com.rebotted.GameEngine;
import com.rebotted.event.CycleEvent;
import com.rebotted.event.CycleEventContainer;
import com.rebotted.event.CycleEventHandler;
import com.rebotted.game.content.skills.SkillConstants;
import com.rebotted.game.players.Player;
import com.rebotted.util.Misc;
/**
* Herbs
* @author Andrew (Mr Extremez)
* Created by IntelliJ IDEA. User: vayken Date: 24/02/12 Time: 20:34 To change
* this template use File | Settings | File Templates.
*/
public class Herbs {
private static final int[] HERB_PATCH = {8150, 8151};
public static boolean isHerb(Player player, int objectType) {
for (int i = 0; i < HERB_PATCH.length; i++) {
if (objectType == HERB_PATCH[i]) {
return true;
private Player player;
// set of global constants for Farming
private static final int START_HARVEST_AMOUNT = 3;
private static final int END_HARVEST_AMOUNT = 18;
private static final double COMPOST_CHANCE = 0.9;
private static final double SUPERCOMPOST_CHANCE = 0.7;
private static final double CLEARING_EXPERIENCE = 4;
public Herbs(Player player) {
this.player = player;
}
// Farming data
public int[] herbStages = new int[4];
public int[] herbSeeds = new int[4];
public int[] herbHarvest = new int[4];
public int[] herbState = new int[4];
public long[] herbTimer = new long[4];
public double[] diseaseChance = { 1, 1, 1, 1, 1 };
/* set of the constants for the patch */
// states - 2 bits plant - 6 bits
public static final int GROWING = 0x00;
public static final int MAIN_HERB_LOCATION_CONFIG = 515;
/* This is the enum holding the seeds info */
public enum HerbData {
GUAM(5291, 199, 9, 80, 0.25, 11, 12.5, 0x04, 0x08), MARRENTILL(5292,
201, 14, 80, 0.25, 13.5, 15, 0x0b, 0x0f), TARROMIN(5293, 203,
19, 80, 0.25, 16, 18, 0x12, 0x16), HARRALANDER(5294, 205, 26,
80, 0.25, 21.5, 24, 0x19, 0x1d), GOUT_TUBER(6311, 3261, 29, 80,
0.25, 105, 45, 0xc0, 0xc4), RANARR(5295, 207, 32, 80, 0.20, 27,
30.5, 0x20, 0x24), TOADFLAX(5296, 3049, 38, 80, 0.20, 34, 38.5,
0x27, 0x2b), IRIT(5297, 209, 44, 80, 0.20, 43, 48.5, 0x2e, 0x32), AVANTOE(
5298, 211, 50, 80, 0.20, 54.5, 61.5, 0x35, 0x39), KUARM(5299,
213, 56, 80, 0.20, 69, 78, 0x44, 0x48), SNAPDRAGON(5300, 3051,
62, 80, 0.15, 87.5, 98.5, 0x4b, 0x4f), CADANTINE(5301, 215, 67,
80, 0.15, 106.5, 120, 0x52, 0x56), LANTADYME(5302, 2485, 73,
80, 0.15, 134.5, 151.5, 0x59, 0x5d), DWARF(5303, 217, 79, 80,
0.15, 170.5, 192, 0x60, 0x64), TORSOL(5304, 219, 85, 80, 0.15,
199.5, 224.5, 0x67, 0x6b)
;
private int seedId;
private int harvestId;
private int levelRequired;
private int growthTime;
private double diseaseChance;
private double plantingXp;
private double harvestXp;
private int startingState;
private int endingState;
private static Map<Integer, HerbData> seeds = new HashMap<Integer, HerbData>();
static {
for (HerbData data : HerbData.values()) {
seeds.put(data.seedId, data);
}
}
HerbData(int seedId, int harvestId, int levelRequired, int growthTime,
double diseaseChance, double plantingXp, double harvestXp,
int startingState, int endingState) {
this.seedId = seedId;
this.harvestId = harvestId;
this.levelRequired = levelRequired;
this.growthTime = growthTime;
this.diseaseChance = diseaseChance;
this.plantingXp = plantingXp;
this.harvestXp = harvestXp;
this.startingState = startingState;
this.endingState = endingState;
}
public static HerbData forId(int seedId) {
return seeds.get(seedId);
}
public int getSeedId() {
return seedId;
}
public int getHarvestId() {
return harvestId;
}
public int getLevelRequired() {
return levelRequired;
}
public int getGrowthTime() {
return growthTime;
}
public double getDiseaseChance() {
return diseaseChance;
}
public double getPlantingXp() {
return plantingXp;
}
public double getHarvestXp() {
return harvestXp;
}
public int getStartingState() {
return startingState;
}
public int getEndingState() {
return endingState;
}
}
/* This is the enum data about the different patches */
public enum HerbFieldsData {
ARDOUGNE(0,
new Point[] { new Point(2670, 3374), new Point(2671, 3375) }), PHASMATYS(
1, new Point[] { new Point(3605, 3529), new Point(3606, 3530) }), FALADOR(
2, new Point[] { new Point(3058, 3311), new Point(3059, 3312) }), CATHERBY(
3, new Point[] { new Point(2813, 3463), new Point(2814, 3464) });
private int herbIndex;
private Point[] herbPosition;
HerbFieldsData(int herbIndex, Point[] herbPosition) {
this.herbIndex = herbIndex;
this.herbPosition = herbPosition;
}
public static HerbFieldsData forIdPosition(int x, int y) {
for (HerbFieldsData herbFieldsData : HerbFieldsData.values()) {
if (FarmingConstants.inRangeArea(
herbFieldsData.getHerbPosition()[0],
herbFieldsData.getHerbPosition()[1], x, y)) {
return herbFieldsData;
}
}
return null;
}
public int getHerbIndex() {
return herbIndex;
}
public Point[] getHerbPosition() {
return herbPosition;
}
}
/* This is the enum that hold the different data for inspecting the plant */
public enum InspectData {
GUAM(5291, new String[][] { { "The seed has only just been planted." },
{ "The herb is now ankle height." },
{ "The herb is now knee height." },
{ "The herb is now mid-thigh height." },
{ "The herb is fully grown and ready to harvest." } }), MARRENTILL(
5292, new String[][] {
{ "The seed has only just been planted." },
{ "The herb is now ankle height." },
{ "The herb is now knee height." },
{ "The herb is now mid-thigh height." },
{ "The herb is fully grown and ready to harvest." } }), TARROMIN(
5293, new String[][] {
{ "The seed has only just been planted." },
{ "The herb is now ankle height." },
{ "The herb is now knee height." },
{ "The herb is now mid-thigh height." },
{ "The herb is fully grown and ready to harvest." } }), HARRALANDER(
5294, new String[][] {
{ "The seed has only just been planted." },
{ "The herb is now ankle height." },
{ "The herb is now knee height." },
{ "The herb is now mid-thigh height." },
{ "The herb is fully grown and ready to harvest." } }), GOUT_TUBER(
6311, new String[][] {
{ "The seed has only just been planted." },
{ "The herb is now ankle height." },
{ "The herb is now knee height." },
{ "The herb is now mid-thigh height." },
{ "The herb is fully grown and ready to harvest." } }), RANARR(
5295, new String[][] {
{ "The seed has only just been planted." },
{ "The herb is now ankle height." },
{ "The herb is now knee height." },
{ "The herb is now mid-thigh height." },
{ "The herb is fully grown and ready to harvest." } }), TOADFLAX(
5296, new String[][] {
{ "The seed has only just been planted." },
{ "The herb is now ankle height." },
{ "The herb is now knee height." },
{ "The herb is now mid-thigh height." },
{ "The herb is fully grown and ready to harvest." } }), IRIT(
5297, new String[][] {
{ "The seed has only just been planted." },
{ "The herb is now ankle height." },
{ "The herb is now knee height." },
{ "The herb is now mid-thigh height." },
{ "The herb is fully grown and ready to harvest." } }), AVANTOE(
5298, new String[][] {
{ "The seed has only just been planted." },
{ "The herb is now ankle height." },
{ "The herb is now knee height." },
{ "The herb is now mid-thigh height." },
{ "The herb is fully grown and ready to harvest." } }), KUARM(
5299, new String[][] {
{ "The seed has only just been planted." },
{ "The herb is now ankle height." },
{ "The herb is now knee height." },
{ "The herb is now mid-thigh height." },
{ "The herb is fully grown and ready to harvest." } }), SNAPDRAGON(
5300, new String[][] {
{ "The seed has only just been planted." },
{ "The herb is now ankle height." },
{ "The herb is now knee height." },
{ "The herb is now mid-thigh height." },
{ "The herb is fully grown and ready to harvest." } }), CADANTINE(
5301, new String[][] {
{ "The seed has only just been planted." },
{ "The herb is now ankle height." },
{ "The herb is now knee height." },
{ "The herb is now mid-thigh height." },
{ "The herb is fully grown and ready to harvest." } }), LANTADYME(
5302, new String[][] {
{ "The seed has only just been planted." },
{ "The herb is now ankle height." },
{ "The herb is now knee height." },
{ "The herb is now mid-thigh height." },
{ "The herb is fully grown and ready to harvest." } }), DWARF(
5303, new String[][] {
{ "The seed has only just been planted." },
{ "The herb is now ankle height." },
{ "The herb is now knee height." },
{ "The herb is now mid-thigh height." },
{ "The herb is fully grown and ready to harvest." } }), TORSOL(
5304, new String[][] {
{ "The seed has only just been planted." },
{ "The herb is now ankle height." },
{ "The herb is now knee height." },
{ "The herb is now mid-thigh height." },
{ "The herb is fully grown and ready to harvest." } })
;
private int seedId;
private String[][] messages;
private static Map<Integer, InspectData> seeds = new HashMap<Integer, InspectData>();
static {
for (InspectData data : InspectData.values()) {
seeds.put(data.seedId, data);
}
}
InspectData(int seedId, String[][] messages) {
this.seedId = seedId;
this.messages = messages;
}
public static InspectData forId(int seedId) {
return seeds.get(seedId);
}
public int getSeedId() {
return seedId;
}
public String[][] getMessages() {
return messages;
}
}
/* update all the patch states */
public void updateHerbsStates() {
// falador catherby ardougne phasmatys
int[] configValues = new int[herbStages.length];
int configValue;
for (int i = 0; i < herbStages.length; i++) {
configValues[i] = getConfigValue(herbStages[i], herbSeeds[i],
herbState[i], i);
}
configValue = (configValues[0] << 16) + (configValues[1] << 8 << 16)
+ configValues[2] + (configValues[3] << 8);
player.getPacketSender().sendConfig(MAIN_HERB_LOCATION_CONFIG, configValue);
}
/* getting the different config values */
public int getConfigValue(int herbStage, int seedId, int plantState,
int index) {
HerbData herbData = HerbData.forId(seedId);
switch (herbStage) {
case 0:// weed
return (GROWING << 6) + 0x00;
case 1:// weed cleared
return (GROWING << 6) + 0x01;
case 2:
return (GROWING << 6) + 0x02;
case 3:
return (GROWING << 6) + 0x03;
}
if (herbData == null) {
return -1;
}
if (herbSeeds[index] == 6311) {
if (plantState == 1) {
return herbStages[index] + 0xc1;
} else if (plantState == 2) {
return herbStages[index] + 0xc3;
}
}
return (plantState == 2 ? herbStages[index] + 0x9e
: plantState == 1 ? herbStages[index] + 0x9a
: getPlantState(plantState) << 6)
+ herbData.getStartingState() + herbStage - 4;
}
/* getting the plant states */
public int getPlantState(int plantState) {
switch (plantState) {
case 0:
return GROWING;
}
return -1;
}
/* calculating the disease chance and making the plant grow */
public void doCalculations() {
for (int i = 0; i < herbSeeds.length; i++) {
if (herbStages[i] > 0 && herbStages[i] <= 3
&& GameEngine.getMinutesCounter() - herbTimer[i] >= 5) {
herbStages[i]--;
herbTimer[i] = GameEngine.getMinutesCounter();
updateHerbsStates();
}
HerbData herbData = HerbData.forId(herbSeeds[i]);
if (herbData == null) {
continue;
}
long difference = GameEngine.getMinutesCounter() - herbTimer[i];
long growth = herbData.getGrowthTime();
int nbStates = herbData.getEndingState()
- herbData.getStartingState();
int state = (int) (difference * nbStates / growth);
if (herbTimer[i] == 0 || herbState[i] == 2 || state > nbStates) {
continue;
}
if (4 + state != herbStages[i]) {
herbStages[i] = 4 + state;
doStateCalculation(i);
updateHerbsStates();
}
}
}
/* calculations about the diseasing chance */
public void doStateCalculation(int index) {
if (herbState[index] == 2) {
return;
}
// if the patch is diseased, it dies, if its watched by a farmer, it
// goes back to normal
if (herbState[index] == 1) {
herbState[index] = 2;
}
if (herbState[index] == 4 && herbStages[index] != 3) {
herbState[index] = 0;
}
if (herbState[index] == 0 && herbStages[index] >= 4
&& herbStages[index] <= 7) {
HerbData herbData = HerbData.forId(herbSeeds[index]);
if (herbData == null) {
return;
}
double chance = diseaseChance[index] * herbData.getDiseaseChance();
int maxChance = (int) chance * 100;
if (Misc.random(100) <= maxChance) {
herbState[index] = 1;
}
}
}
/* clearing the patch with a rake of a spade */
public boolean clearPatch(int objectX, int objectY, int itemId) {
final HerbFieldsData herbFieldsData = HerbFieldsData.forIdPosition(
objectX, objectY);
int finalAnimation;
int finalDelay;
if (herbFieldsData == null
|| (itemId != FarmingConstants.RAKE && itemId != FarmingConstants.SPADE)) {
return false;
}
if (herbStages[herbFieldsData.getHerbIndex()] == 3) {
return true;
}
if (!SkillConstants.getEnabled(SkillConstants.FARMING.ordinal())) {
player.getPacketSender().sendMessage("This skill is currently disabled.");
return true;
}
if (herbStages[herbFieldsData.getHerbIndex()] <= 3) {
if (!player.getItemAssistant().playerHasItem(FarmingConstants.RAKE)) {
player.getDialogueHandler().sendStatement(
"You need a rake to clear this path.");
return true;
} else {
finalAnimation = FarmingConstants.RAKING_ANIM;
finalDelay = 5;
}
} else {
if (!player.getItemAssistant().playerHasItem(FarmingConstants.SPADE)) {
player.getDialogueHandler().sendStatement(
"You need a spade to clear this path.");
return true;
} else {
finalAnimation = FarmingConstants.SPADE_ANIM;
finalDelay = 3;
}
}
final int animation = finalAnimation;
player.stopPlayer(true);
player.startAnimation(animation);
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
player.startAnimation(animation);
if (herbStages[herbFieldsData.getHerbIndex()] <= 2) {
herbStages[herbFieldsData.getHerbIndex()]++;
player.getItemAssistant().addItem(6055, 1);
} else {
herbStages[herbFieldsData.getHerbIndex()] = 3;
container.stop();
}
player.getPlayerAssistant().addSkillXP(CLEARING_EXPERIENCE, SkillConstants.FARMING.ordinal());
herbTimer[herbFieldsData.getHerbIndex()] = GameEngine
.getMinutesCounter();
updateHerbsStates();
if (herbStages[herbFieldsData.getHerbIndex()] == 3) {
container.stop();
return;
}
}
@Override
public void stop() {
resetHerbs(herbFieldsData.getHerbIndex());
player.getPacketSender().sendMessage("You clear the patch.");
player.stopPlayer(false);
player.getPlayerAssistant().resetAnimation();
}
}, finalDelay);
return true;
}
/* planting the seeds */
public boolean plantSeed(int objectX, int objectY, final int seedId) {
final HerbFieldsData herbFieldsData = HerbFieldsData.forIdPosition(
objectX, objectY);
final HerbData herbData = HerbData.forId(seedId);
if (herbFieldsData == null || herbData == null) {
return false;
}
if (!SkillConstants.getEnabled(SkillConstants.FARMING.ordinal())) {
player.getPacketSender().sendMessage("This skill is currently disabled.");
return true;
}
if (herbStages[herbFieldsData.getHerbIndex()] != 3) {
player.getPacketSender().sendMessage("You can't plant a seed here.");
return false;
}
if (herbData.getLevelRequired() > player.playerLevel[SkillConstants.FARMING.ordinal()]) {
player.getDialogueHandler().sendStatement("You need a farming level of "
+ herbData.getLevelRequired()
+ " to plant this seed.");
return true;
}
if (!player.getItemAssistant().playerHasItem(FarmingConstants.SEED_DIBBER)) {
player.getDialogueHandler().sendStatement(
"You need a seed dibber to plant seed here.");
return true;
}
player.startAnimation(FarmingConstants.SEED_DIBBING);
player.getItemAssistant().deleteItem(seedId, 1);
player.stopPlayer(true);
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
herbState[herbFieldsData.getHerbIndex()] = 0;
herbStages[herbFieldsData.getHerbIndex()] = 4;
herbSeeds[herbFieldsData.getHerbIndex()] = seedId;
herbTimer[herbFieldsData.getHerbIndex()] = GameEngine
.getMinutesCounter();
player.getPlayerAssistant().addSkillXP(herbData.getPlantingXp(), SkillConstants.FARMING.ordinal());
container.stop();
}
@Override
public void stop() {
updateHerbsStates();
player.stopPlayer(false);
player.getPlayerAssistant().resetAnimation();
}
}, 3);
return true;
}
/* harvesting the plant resulted */
public boolean harvest(int objectX, int objectY) {
final HerbFieldsData herbFieldsData = HerbFieldsData.forIdPosition(
objectX, objectY);
if (herbFieldsData == null) {
return false;
}
final HerbData herbData = HerbData.forId(herbSeeds[herbFieldsData
.getHerbIndex()]);
if (herbData == null) {
return false;
}
if (!SkillConstants.getEnabled(SkillConstants.FARMING.ordinal())) {
player.getPacketSender().sendMessage("This skill is currently disabled.");
return true;
}
if (!player.getItemAssistant().playerHasItem(FarmingConstants.SPADE)) {
player.getDialogueHandler().sendStatement(
"You need a spade to harvest here.");
return true;
}
player.startAnimation(
FarmingConstants.PICKING_VEGETABLE_ANIM);
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
if (herbHarvest[herbFieldsData.getHerbIndex()] == 0) {
herbHarvest[herbFieldsData.getHerbIndex()] = 1 + (START_HARVEST_AMOUNT + Misc
.random(END_HARVEST_AMOUNT - START_HARVEST_AMOUNT)) * (1);
}
if (herbHarvest[herbFieldsData.getHerbIndex()] == 1) {
resetHerbs(herbFieldsData.getHerbIndex());
herbStages[herbFieldsData.getHerbIndex()] = 3;
herbTimer[herbFieldsData.getHerbIndex()] = GameEngine
.getMinutesCounter();
container.stop();
return;
}
if (player.getItemAssistant().freeSlots() <= 0) {
container.stop();
return;
}
herbHarvest[herbFieldsData.getHerbIndex()]--;
player.startAnimation(
FarmingConstants.PICKING_HERB_ANIM);
player.getPacketSender().sendMessage(
"You harvest the crop, and get some herbs.");
player.getItemAssistant().addItem(herbData.getHarvestId(), 1);
player.getPlayerAssistant().addSkillXP(herbData.getHarvestXp(), SkillConstants.FARMING.ordinal());
}
@Override
public void stop() {
updateHerbsStates();
player.getPlayerAssistant().resetAnimation();
}
}, 3);
return true;
}
/* putting compost onto the plant */
public boolean putCompost(int objectX, int objectY, final int itemId) {
if (itemId != 6032 && itemId != 6034) {
return false;
}
final HerbFieldsData herbFieldsData = HerbFieldsData.forIdPosition(
objectX, objectY);
if (herbFieldsData == null) {
return false;
}
if (!SkillConstants.getEnabled(SkillConstants.FARMING.ordinal())) {
player.getPacketSender().sendMessage("This skill is currently disabled.");
return true;
}
if (herbStages[herbFieldsData.getHerbIndex()] != 3
|| herbState[herbFieldsData.getHerbIndex()] == 4) {
player.getPacketSender().sendMessage("This patch doesn't need compost.");
return true;
}
player.getItemAssistant().deleteItem(itemId, 1);
player.getItemAssistant().addItem(1925, 1);
player.getPacketSender().sendMessage(
"You pour some " + (itemId == 6034 ? "super" : "")
+ "compost on the patch.");
player.startAnimation(FarmingConstants.PUTTING_COMPOST);
player.getPlayerAssistant().addSkillXP(itemId == 6034 ? Compost.SUPER_COMPOST_EXP_USE
: Compost.COMPOST_EXP_USE, SkillConstants.FARMING.ordinal());
player.stopPlayer(true);
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
diseaseChance[herbFieldsData.getHerbIndex()] *= itemId == 6032 ? COMPOST_CHANCE
: SUPERCOMPOST_CHANCE;
herbState[herbFieldsData.getHerbIndex()] = 4;
container.stop();
}
@Override
public void stop() {
player.stopPlayer(false);
player.getPlayerAssistant().resetAnimation();
}
}, 7);
return true;
}
/* inspecting a plant */
public boolean inspect(int objectX, int objectY) {
final HerbFieldsData herbFieldsData = HerbFieldsData.forIdPosition(
objectX, objectY);
if (herbFieldsData == null) {
return false;
}
if (!SkillConstants.getEnabled(SkillConstants.FARMING.ordinal())) {
player.getPacketSender().sendMessage("This skill is currently disabled.");
return true;
}
final InspectData inspectData = InspectData
.forId(herbSeeds[herbFieldsData.getHerbIndex()]);
final HerbData herbData = HerbData.forId(herbSeeds[herbFieldsData
.getHerbIndex()]);
if (herbState[herbFieldsData.getHerbIndex()] == 1) {
player.getDialogueHandler().sendStatement("This plant is diseased. Use a plant cure on it to cure it, ",
"or clear the patch with a spade.");
return true;
} else if (herbState[herbFieldsData.getHerbIndex()] == 2) {
player.getDialogueHandler().sendStatement("This plant is dead. You did not cure it while it was diseased.",
"Clear the patch with a spade.");
return true;
}
if (herbStages[herbFieldsData.getHerbIndex()] == 0) {
player.getDialogueHandler().sendStatement(
"This is an herb patch. The soil has not been treated.",
"The patch needs weeding.");
} else if (herbStages[herbFieldsData.getHerbIndex()] == 3) {
player.getDialogueHandler().sendStatement(
"This is an herb patch. The soil has not been treated.",
"The patch is empty and weeded.");
} else if (inspectData != null && herbData != null) {
player.getPacketSender().sendMessage(
"You bend down and start to inspect the patch...");
player.startAnimation(1331);
player.stopPlayer(true);
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
if (herbStages[herbFieldsData.getHerbIndex()] - 4 < inspectData
.getMessages().length - 2) {
player.getDialogueHandler().sendStatement( inspectData
.getMessages()[herbStages[herbFieldsData
.getHerbIndex()] - 4]);
} else if (herbStages[herbFieldsData.getHerbIndex()] < herbData
.getEndingState() - herbData.getStartingState() + 2) {
player.getDialogueHandler().sendStatement(
inspectData.getMessages()[inspectData
.getMessages().length - 2]);
} else {
player.getDialogueHandler().sendStatement(
inspectData.getMessages()[inspectData
.getMessages().length - 1]);
}
container.stop();
}
@Override
public void stop() {
player.startAnimation(1332);
player.stopPlayer(false);
player.getPlayerAssistant().resetAnimation();
}
}, 5);
}
return true;
}
/* opening the corresponding guide about the patch */
public boolean guide(int objectX, int objectY) {
final HerbFieldsData herbFieldsData = HerbFieldsData.forIdPosition(
objectX, objectY);
if (herbFieldsData == null) {
return false;
}
if (!SkillConstants.getEnabled(SkillConstants.FARMING.ordinal())) {
player.getPacketSender().sendMessage("This skill is currently disabled.");
return true;
}
player.getSkillInterfaces().farmingComplex(7);
player.getSkillInterfaces().selected = 20;
return true;
}
/* Curing the plant */
public boolean curePlant(int objectX, int objectY, int itemId) {
final HerbFieldsData herbFieldsData = HerbFieldsData.forIdPosition(
objectX, objectY);
if (herbFieldsData == null || itemId != 6036) {
return false;
}
final HerbData herbData = HerbData.forId(herbSeeds[herbFieldsData
.getHerbIndex()]);
if (herbData == null) {
return false;
}
if (!SkillConstants.getEnabled(SkillConstants.FARMING.ordinal())) {
player.getPacketSender().sendMessage("This skill is currently disabled.");
return true;
}
if (herbState[herbFieldsData.getHerbIndex()] != 1) {
player.getPacketSender().sendMessage("This plant doesn't need to be cured.");
return true;
}
player.getItemAssistant().deleteItem(itemId, 1);
player.getItemAssistant().addItem(229, 1);
player.startAnimation(FarmingConstants.CURING_ANIM);
player.stopPlayer(true);
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
player.getPacketSender().sendMessage(
"You cure the plant with a plant cure.");
herbState[herbFieldsData.getHerbIndex()] = 0;
container.stop();
}
@Override
public void stop() {
updateHerbsStates();
player.stopPlayer(false);
player.getPlayerAssistant().resetAnimation();
}
}, 7);
return true;
}
@SuppressWarnings("unused")
private void resetHerbs() {
for (int i = 0; i < herbStages.length; i++) {
herbSeeds[i] = 0;
herbState[i] = 0;
diseaseChance[i] = 0;
herbHarvest[i] = 0;
}
}
/* reseting the patches */
private void resetHerbs(int index) {
herbSeeds[index] = 0;
herbState[index] = 0;
diseaseChance[index] = 1;
herbHarvest[index] = 0;
}
/* checking if the patch is raked */
public boolean checkIfRaked(int objectX, int objectY) {
final HerbFieldsData herbFieldsData = HerbFieldsData.forIdPosition(
objectX, objectY);
if (herbFieldsData == null)
return false;
if (herbStages[herbFieldsData.getHerbIndex()] == 3)
return true;
return false;
}
}
@@ -0,0 +1,933 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.rebotted.game.content.skills.farming;
/**
*
* @author ArrowzFtw
*/
import java.awt.Point;
import java.util.HashMap;
import java.util.Map;
import com.rebotted.GameEngine;
import com.rebotted.event.CycleEvent;
import com.rebotted.event.CycleEventContainer;
import com.rebotted.event.CycleEventHandler;
import com.rebotted.game.content.skills.SkillConstants;
import com.rebotted.game.players.Player;
import com.rebotted.util.Misc;
/**
* Created by IntelliJ IDEA. User: vayken Date: 24/02/12 Time: 20:34 To change
* this template use File | Settings | File Templates.
*/
public class Hops {
private Player player;
// set of global constants for Farming
private static final int START_HARVEST_AMOUNT = 3;
private static final int END_HARVEST_AMOUNT = 41;
private static final double WATERING_CHANCE = 0.5;
private static final double COMPOST_CHANCE = 0.9;
private static final double SUPERCOMPOST_CHANCE = 0.7;
private static final double CLEARING_EXPERIENCE = 4;
public Hops(Player player) {
this.player = player;
}
// Farming data
public int[] hopsStages = new int[4];
public int[] hopsSeeds = new int[4];
public int[] hopsHarvest = new int[4];
public int[] hopsState = new int[4];
public long[] hopsTimer = new long[4];
public double[] diseaseChance = { 1, 1, 1, 1 };
public boolean[] hasFullyGrown = { false, false, false, false };
public boolean[] hopsWatched = { false, false, false, false };
/* set of the constants for the patch */
// states - 2 bits plant - 6 bits
public static final int GROWING = 0x00;
public static final int WATERED = 0x01;
public static final int DISEASED = 0x02;
public static final int DEAD = 0x03;
public static final int MAIN_HOPS_CONFIG = 506;
/* This is the enum holding the seeds info */
public enum HopsData {
BARLEY(5305, 6006, 4, 3, new int[] { 6032, 3 }, 40, 0.35, 8.5, 9.5,
0x31, 0x35), HAMMERSTONE(5307, 5994, 4, 4,
new int[] { 6010, 1 }, 40, 0.35, 9, 10, 0x04, 0x08), ASGARNIAN(
5308, 5996, 4, 8, new int[] { 5458, 1 }, 40, 0.30, 10.5, 12,
0x0b, 0x10), JUTE(5306, 5931, 3, 13, new int[] { 6008, 6 }, 40,
0.30, 13, 14.5, 0x38, 0x3d), YANILLIAN(5309, 5998, 4, 16,
new int[] { 5968, 1 }, 40, 0.25, 14.5, 16, 0x13, 0x19), KRANDORIAN(
5310, 6000, 4, 21, new int[] { 5478 }, 40, 0.25, 17.5, 19.5,
0x1c, 0x23), WILDBLOOD(5311, 6002, 4, 28,
new int[] { 6012, 1 }, 40, 0.20, 23, 26, 0x26, 0x2e), ;
private int seedId;
private int harvestId;
private int seedAmount;
private int levelRequired;
private int[] paymentToWatch;
private int growthTime;
private double diseaseChance;
private double plantingXp;
private double harvestXp;
private int startingState;
private int endingState;
private static Map<Integer, HopsData> seeds = new HashMap<Integer, HopsData>();
static {
for (HopsData data : HopsData.values()) {
seeds.put(data.seedId, data);
}
}
HopsData(int seedId, int harvestId, int seedAmount, int levelRequired,
int[] paymentToWatch, int growthTime, double diseaseChance,
double plantingXp, double harvestXp, int startingState,
int endingState) {
this.seedId = seedId;
this.harvestId = harvestId;
this.seedAmount = seedAmount;
this.levelRequired = levelRequired;
this.paymentToWatch = paymentToWatch;
this.growthTime = growthTime;
this.diseaseChance = diseaseChance;
this.plantingXp = plantingXp;
this.harvestXp = harvestXp;
this.startingState = startingState;
this.endingState = endingState;
}
public static HopsData forId(int seedId) {
return seeds.get(seedId);
}
public int getSeedId() {
return seedId;
}
public int getHarvestId() {
return harvestId;
}
public int getSeedAmount() {
return seedAmount;
}
public int getLevelRequired() {
return levelRequired;
}
public int[] getPaymentToWatch() {
return paymentToWatch;
}
public int getGrowthTime() {
return growthTime;
}
public double getDiseaseChance() {
return diseaseChance;
}
public double getPlantingXp() {
return plantingXp;
}
public double getHarvestXp() {
return harvestXp;
}
public int getStartingState() {
return startingState;
}
public int getEndingState() {
return endingState;
}
}
/* This is the enum data about the different patches */
public enum HopsFieldsData {
LUMBRIDGE(0,
new Point[] { new Point(3227, 3313), new Point(3231, 3317) },
2333), MCGRUBOR(1, new Point[] { new Point(2664, 3523),
new Point(2669, 3528) }, 2334), YANILLE(2, new Point[] {
new Point(2574, 3103), new Point(2577, 3106) }, 2332), ENTRANA(
3,
new Point[] { new Point(2809, 3335), new Point(2812, 3338) },
2327);
private int hopsIndex;
private Point[] hopsPosition;
private int npcId;
private static Map<Integer, HopsFieldsData> npcsProtecting = new HashMap<Integer, HopsFieldsData>();
static {
for (HopsFieldsData data : HopsFieldsData.values()) {
npcsProtecting.put(data.npcId, data);
}
}
public static HopsFieldsData forId(int npcId) {
return npcsProtecting.get(npcId);
}
HopsFieldsData(int hopsIndex, Point[] hopsPosition, int npcId) {
this.hopsIndex = hopsIndex;
this.hopsPosition = hopsPosition;
this.npcId = npcId;
}
public static HopsFieldsData forIdPosition(int x, int y) {
for (HopsFieldsData hopsFieldsData : HopsFieldsData.values()) {
if (FarmingConstants.inRangeArea(
hopsFieldsData.getHopsPosition()[0],
hopsFieldsData.getHopsPosition()[1], x, y)) {
return hopsFieldsData;
}
}
return null;
}
public int getHopsIndex() {
return hopsIndex;
}
public Point[] getHopsPosition() {
return hopsPosition;
}
public int getNpcId() {
return npcId;
}
}
/* This is the enum that hold the different data for inspecting the plant */
public enum InspectData {
BARLEY(5305, new String[][] {
{ "The barley seeds have only just been planted." },
{ "Grain heads develop at the upper part of the stalks,",
"as the barley grows taller." },
{ "The barley grows taller, the heads weighing",
"slightly on the stalks." },
{ "The barley grows taller." },
{ "The barley is ready to harvest. The heads of grain",
"are weighing down heavily on the stalks!" } }), HAMMERSTONE(
5307,
new String[][] {
{ "The Hammerstone seeds have only just been planted." },
{ "The Hammerstone hops plant grows a little bit taller." },
{ "The Hammerstone hops plant grows a bit taller." },
{ "The Hammerstone hops plant grows a bit taller." },
{ "The Hammerstone hops plant is ready to harvest." } }), ASGARNIAN(
5308, new String[][] {
{ "The Asgarnian seeds have only just been planted." },
{ "The Asgarnian hops plant grows a bit taller." },
{ "The Asgarnian hops plant grows a bit taller." },
{ "The Asgarnian hops plant grows a bit taller." },
{ "The upper new leaves appear dark green to the",
"rest of the plant." },
{ "The Asgarnian hops plant is ready to harvest." } }), JUTE(
5306, new String[][] {
{ "The Jute seeds have only just been planted." },
{ "The jute plants grow taller." },
{ "The jute plants grow taller." },
{ "The jute plants grow taller." },
{ "The jute plant grows taller. They are as high",
"as the player." },
{ "The jute plants are ready to harvest." } }), YANILLIAN(
5309, new String[][] {
{ "The Yanillian seeds have only just been planted." },
{ "The Yanillian hops plant grows a bit taller." },
{ "The Yanillian hops plant grows a bit taller." },
{ "The Yanillian hops plant grows a bit taller." },
{ "The new leaves on the top of the Yanillian hops",
"plant are dark green." },
{ "The new leaves on the top of the Yanillian hops",
"plant are dark green." },
{ "The Yanillian hops plant is ready to harvest." } }), KRANDORIAN(
5310,
new String[][] {
{ "The Krandorian seeds have only just been planted." },
{ "The Krandorian plant grows a bit taller." },
{ "The Krandorian plant grows a bit taller." },
{ "The Krandorian plant grows a bit taller." },
{ "The new leaves on top of the Krandorian plant are",
"dark green." },
{ "The Krandorian plant grows a bit taller." },
{ "The new leaves on top of the Krandorian plant",
"are dark green." },
{ "The Krandorian plant is ready for harvesting." } }), WILDBLOOD(
5311,
new String[][] {
{ "The wildblood seeds have only just been planted." },
{ "The wildblood hops plant grows a bit taller." },
{ "The wildblood hops plant grows a bit taller." },
{ "The wildblood hops plant grows a bit taller." },
{ "The wildblood hops plant grows a bit taller." },
{ "The wildblood hops plant grows a bit taller." },
{ "The wildblood hops plant grows a bit taller." },
{
"The new leaves at the top of the wildblood hops plant",
"are dark green." },
{ "The wildblood hops plant is ready to harvest." } });
private int seedId;
private String[][] messages;
private static Map<Integer, InspectData> seeds = new HashMap<Integer, InspectData>();
static {
for (InspectData data : InspectData.values()) {
seeds.put(data.seedId, data);
}
}
InspectData(int seedId, String[][] messages) {
this.seedId = seedId;
this.messages = messages;
}
public static InspectData forId(int seedId) {
return seeds.get(seedId);
}
public int getSeedId() {
return seedId;
}
public String[][] getMessages() {
return messages;
}
}
/* update all the patch states */
public void updateHopsStates() {
// lumbridge - mc grubor - yanille - entrana
int[] configValues = new int[hopsStages.length];
int configValue;
for (int i = 0; i < hopsStages.length; i++) {
configValues[i] = getConfigValue(hopsStages[i], hopsSeeds[i],
hopsState[i], i);
}
configValue = (configValues[0] << 16) + (configValues[1] << 8 << 16)
+ configValues[2] + (configValues[3] << 8);
player.getPacketSender().sendConfig(MAIN_HOPS_CONFIG, configValue);
}
/* getting the different config values */
public int getConfigValue(int hopsStage, int seedId, int plantState,
int index) {
HopsData hopsData = HopsData.forId(seedId);
switch (hopsStage) {
case 0:// weed
return (GROWING << 6) + 0x00;
case 1:// weed cleared
return (GROWING << 6) + 0x01;
case 2:
return (GROWING << 6) + 0x02;
case 3:
return (GROWING << 6) + 0x03;
}
if (hopsData == null) {
return -1;
}
if (hopsData.getEndingState() == hopsData.getStartingState()
+ hopsStage - 1) {
hasFullyGrown[index] = true;
}
return (getPlantState(plantState) << 6) + hopsData.getStartingState()
+ hopsStage - 4;
}
/* getting the plant states */
public int getPlantState(int plantState) {
switch (plantState) {
case 0:
return GROWING;
case 1:
return WATERED;
case 2:
return DISEASED;
case 3:
return DEAD;
}
return -1;
}
/* calculating the disease chance and making the plant grow */
public void doCalculations() {
for (int i = 0; i < hopsSeeds.length; i++) {
if (hopsStages[i] > 0 && hopsStages[i] <= 3
&& GameEngine.getMinutesCounter() - hopsTimer[i] >= 5) {
hopsStages[i]--;
hopsTimer[i] = GameEngine.getMinutesCounter();
updateHopsStates();
continue;
}
HopsData hopsData = HopsData.forId(hopsSeeds[i]);
if (hopsData == null) {
continue;
}
long difference = GameEngine.getMinutesCounter() - hopsTimer[i];
long growth = hopsData.getGrowthTime();
int nbStates = hopsData.getEndingState()
- hopsData.getStartingState();
int state = (int) (difference * nbStates / growth);
if (hopsTimer[i] == 0 || hopsState[i] == 3 || state > nbStates) {
continue;
}
if (4 + state != hopsStages[i]) {
hopsStages[i] = 4 + state;
if (hopsStages[i] <= 4 + state)
for (int j = hopsStages[i]; j <= 4 + state; j++)
doStateCalculation(i);
updateHopsStates();
}
}
}
public void modifyStage(int i) {
HopsData hopsData = HopsData.forId(hopsSeeds[i]);
if (hopsData == null)
return;
long difference = GameEngine.getMinutesCounter() - hopsTimer[i];
long growth = hopsData.getGrowthTime();
int nbStates = hopsData.getEndingState() - hopsData.getStartingState();
int state = (int) (difference * nbStates / growth);
hopsStages[i] = 4 + state;
updateHopsStates();
}
/* calculations about the diseasing chance */
public void doStateCalculation(int index) {
if (hopsState[index] == 3) {
return;
}
// if the patch is diseased, it dies, if its watched by a farmer, it
// goes back to normal
if (hopsState[index] == 2) {
if (hopsWatched[index]) {
hopsState[index] = 0;
HopsData hopsData = HopsData.forId(hopsSeeds[index]);
if (hopsData == null)
return;
int difference = hopsData.getEndingState()
- hopsData.getStartingState();
int growth = hopsData.getGrowthTime();
hopsTimer[index] += (growth / difference);
modifyStage(index);
} else {
hopsState[index] = 3;
}
}
if (hopsState[index] == 1) {
diseaseChance[index] *= 2;
hopsState[index] = 0;
}
if (hopsState[index] == 5 && hopsStages[index] != 3) {
hopsState[index] = 0;
}
if (hopsState[index] == 0 && hopsStages[index] >= 5
&& !hasFullyGrown[index]) {
HopsData hopsData = HopsData.forId(hopsSeeds[index]);
if (hopsData == null) {
return;
}
double chance = diseaseChance[index] * hopsData.getDiseaseChance();
int maxChance = (int) chance * 100;
if (Misc.random(100) <= maxChance) {
hopsState[index] = 2;
}
}
}
/* watering the patch */
public boolean waterPatch(int objectX, int objectY, int itemId) {
final HopsFieldsData hopsFieldsData = HopsFieldsData.forIdPosition(
objectX, objectY);
if (hopsFieldsData == null) {
return false;
}
HopsData hopsData = HopsData.forId(hopsSeeds[hopsFieldsData
.getHopsIndex()]);
if (hopsData == null) {
return false;
}
if (!SkillConstants.getEnabled(SkillConstants.FARMING.ordinal())) {
player.getPacketSender().sendMessage("This skill is currently disabled.");
return true;
}
if (hopsState[hopsFieldsData.getHopsIndex()] == 1
|| hopsStages[hopsFieldsData.getHopsIndex()] <= 1
|| hopsStages[hopsFieldsData.getHopsIndex()] == hopsData
.getEndingState() - hopsData.getStartingState() + 4) {
player.getPacketSender().sendMessage("This patch doesn't need watering.");
return true;
}
player.getItemAssistant().deleteItem(itemId, 1);
player.getItemAssistant().addItem(itemId == 5333 ? itemId - 2 : itemId - 1, 1);
if (!player.getItemAssistant().playerHasItem(FarmingConstants.RAKE)) {
player.getDialogueHandler().sendStatement(
"You need a seed dibber to plant seed here.");
return true;
}
player.getPacketSender().sendMessage("You water the patch.");
player.startAnimation(
FarmingConstants.WATERING_CAN_ANIM);
player.stopPlayer(true);
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
diseaseChance[hopsFieldsData.getHopsIndex()] *= WATERING_CHANCE;
hopsState[hopsFieldsData.getHopsIndex()] = 1;
container.stop();
}
@Override
public void stop() {
updateHopsStates();
player.stopPlayer(false);
player.getPlayerAssistant().resetAnimation();
}
}, 5);
return true;
}
/* clearing the patch with a rake of a spade */
public boolean clearPatch(int objectX, int objectY, int itemId) {
final HopsFieldsData hopsFieldsData = HopsFieldsData.forIdPosition(
objectX, objectY);
int finalAnimation;
int finalDelay;
if (hopsFieldsData == null
|| (itemId != FarmingConstants.RAKE && itemId != FarmingConstants.SPADE)) {
return false;
}
if (!SkillConstants.getEnabled(SkillConstants.FARMING.ordinal())) {
player.getPacketSender().sendMessage("This skill is currently disabled.");
return true;
}
if (hopsStages[hopsFieldsData.getHopsIndex()] == 3) {
return true;
}
if (hopsStages[hopsFieldsData.getHopsIndex()] <= 3) {
if (!player.getItemAssistant().playerHasItem(FarmingConstants.RAKE)) {
player.getDialogueHandler().sendStatement(
"You need a rake to clear this path.");
return true;
} else {
finalAnimation = FarmingConstants.RAKING_ANIM;
finalDelay = 5;
}
} else {
if (!player.getItemAssistant().playerHasItem(FarmingConstants.SPADE)) {
player.getDialogueHandler().sendStatement(
"You need a spade to clear this path.");
return true;
} else {
finalAnimation = FarmingConstants.SPADE_ANIM;
finalDelay = 3;
}
}
final int animation = finalAnimation;
player.stopPlayer(true);
player.startAnimation(animation);
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
player.startAnimation(animation);
if (hopsStages[hopsFieldsData.getHopsIndex()] <= 2) {
hopsStages[hopsFieldsData.getHopsIndex()]++;
player.getItemAssistant().addItem(6055, 1);
} else {
hopsStages[hopsFieldsData.getHopsIndex()] = 3;
container.stop();
}
player.getPlayerAssistant().addSkillXP(CLEARING_EXPERIENCE, SkillConstants.FARMING.ordinal());
hopsTimer[hopsFieldsData.getHopsIndex()] = GameEngine
.getMinutesCounter();
updateHopsStates();
if (hopsStages[hopsFieldsData.getHopsIndex()] == 3) {
container.stop();
return;
}
}
@Override
public void stop() {
resetHops(hopsFieldsData.getHopsIndex());
player.getPacketSender().sendMessage("You clear the patch.");
player.stopPlayer(false);
player.getPlayerAssistant().resetAnimation();
}
}, finalDelay);
return true;
}
/* planting the seeds */
public boolean plantSeed(int objectX, int objectY, final int seedId) {
final HopsFieldsData hopsFieldsData = HopsFieldsData.forIdPosition(
objectX, objectY);
final HopsData hopsData = HopsData.forId(seedId);
if (hopsFieldsData == null || hopsData == null) {
return false;
}
if (!SkillConstants.getEnabled(SkillConstants.FARMING.ordinal())) {
player.getPacketSender().sendMessage("This skill is currently disabled.");
return true;
}
if (hopsStages[hopsFieldsData.getHopsIndex()] != 3) {
player.getPacketSender().sendMessage("You can't plant a seed here.");
return false;
}
if (hopsData.getLevelRequired() > player.playerLevel[SkillConstants.FARMING.ordinal()]) {
player.getDialogueHandler().sendStatement("You need a farming level of "
+ hopsData.getLevelRequired()
+ " to plant this seed.");
return true;
}
if (!player.getItemAssistant().playerHasItem(FarmingConstants.SEED_DIBBER)) {
player.getDialogueHandler().sendStatement(
"You need a seed dibber to plant seed here.");
return true;
}
if (player.getItemAssistant().getItemAmount(hopsData.getSeedId()) < hopsData
.getSeedAmount()) {
player.getDialogueHandler().sendStatement( "You need atleast "
+ hopsData.getSeedAmount() + " seeds to plant here.");
return true;
}
player.startAnimation(FarmingConstants.SEED_DIBBING);
hopsStages[hopsFieldsData.getHopsIndex()] = 4;
player.getItemAssistant().deleteItem(seedId, hopsData.getSeedAmount());
player.stopPlayer(true);
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
hopsState[hopsFieldsData.getHopsIndex()] = 0;
hopsSeeds[hopsFieldsData.getHopsIndex()] = seedId;
hopsTimer[hopsFieldsData.getHopsIndex()] = GameEngine
.getMinutesCounter();
player.getPlayerAssistant().addSkillXP(hopsData.getPlantingXp(), SkillConstants.FARMING.ordinal());
container.stop();
}
@Override
public void stop() {
updateHopsStates();
player.stopPlayer(false);
}
}, 3);
return true;
}
/* harvesting the plant resulted */
public boolean harvest(int objectX, int objectY) {
final HopsFieldsData hopsFieldsData = HopsFieldsData.forIdPosition(
objectX, objectY);
if (hopsFieldsData == null) {
return false;
}
final HopsData hopsData = HopsData.forId(hopsSeeds[hopsFieldsData
.getHopsIndex()]);
if (hopsData == null) {
return false;
}
if (!SkillConstants.getEnabled(SkillConstants.FARMING.ordinal())) {
player.getPacketSender().sendMessage("This skill is currently disabled.");
return true;
}
if (!player.getItemAssistant().playerHasItem(FarmingConstants.SPADE)) {
player.getDialogueHandler().sendStatement(
"You need a spade to harvest here.");
return true;
}
player.startAnimation(FarmingConstants.SPADE_ANIM);
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
if (hopsHarvest[hopsFieldsData.getHopsIndex()] == 0) {
hopsHarvest[hopsFieldsData.getHopsIndex()] = 1 + (START_HARVEST_AMOUNT + Misc
.random(END_HARVEST_AMOUNT - START_HARVEST_AMOUNT)) * (1);
}
if (hopsHarvest[hopsFieldsData.getHopsIndex()] == 1) {
resetHops(hopsFieldsData.getHopsIndex());
hopsStages[hopsFieldsData.getHopsIndex()] = 3;
hopsTimer[hopsFieldsData.getHopsIndex()] = GameEngine
.getMinutesCounter();
container.stop();
return;
}
if (player.getItemAssistant().freeSlots() <= 0) {
container.stop();
return;
}
hopsHarvest[hopsFieldsData.getHopsIndex()]--;
player.startAnimation(
FarmingConstants.SPADE_ANIM);
player.getPacketSender().sendMessage(
"You harvest the crop, and get some vegetables.");
player.getItemAssistant()
.addItem(hopsData.getHarvestId(), 1);
player.getPlayerAssistant().addSkillXP(hopsData.getHarvestXp(), SkillConstants.FARMING.ordinal());
}
@Override
public void stop() {
updateHopsStates();
player.getPlayerAssistant().resetAnimation();
}
}, 2);
return true;
}
/* putting compost onto the plant */
public boolean putCompost(int objectX, int objectY, final int itemId) {
if (itemId != 6032 && itemId != 6034) {
return false;
}
final HopsFieldsData hopsFieldsData = HopsFieldsData.forIdPosition(
objectX, objectY);
if (hopsFieldsData == null) {
return false;
}
if (!SkillConstants.getEnabled(SkillConstants.FARMING.ordinal())) {
player.getPacketSender().sendMessage("This skill is currently disabled.");
return true;
}
if (hopsStages[hopsFieldsData.getHopsIndex()] != 3
|| hopsState[hopsFieldsData.getHopsIndex()] == 5) {
player.getPacketSender().sendMessage("This patch doesn't need compost.");
return true;
}
player.getItemAssistant().deleteItem(itemId, 1);
player.getItemAssistant().addItem(1925, 1);
player.getPacketSender().sendMessage(
"You pour some " + (itemId == 6034 ? "super" : "")
+ "compost on the patch.");
player.startAnimation(FarmingConstants.PUTTING_COMPOST);
player.getPlayerAssistant().addSkillXP(itemId == 6034 ? Compost.SUPER_COMPOST_EXP_USE
: Compost.COMPOST_EXP_USE, SkillConstants.FARMING.ordinal());
player.stopPlayer(true);
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
diseaseChance[hopsFieldsData.getHopsIndex()] *= itemId == 6032 ? COMPOST_CHANCE
: SUPERCOMPOST_CHANCE;
hopsState[hopsFieldsData.getHopsIndex()] = 5;
container.stop();
}
@Override
public void stop() {
player.stopPlayer(false);
player.getPlayerAssistant().resetAnimation();
}
}, 7);
return true;
}
/* inspecting a plant */
public boolean inspect(int objectX, int objectY) {
final HopsFieldsData hopsFieldsData = HopsFieldsData.forIdPosition(
objectX, objectY);
if (hopsFieldsData == null) {
return false;
}
if (!SkillConstants.getEnabled(SkillConstants.FARMING.ordinal())) {
player.getPacketSender().sendMessage("This skill is currently disabled.");
return true;
}
final InspectData inspectData = InspectData
.forId(hopsSeeds[hopsFieldsData.getHopsIndex()]);
final HopsData hopsData = HopsData.forId(hopsSeeds[hopsFieldsData
.getHopsIndex()]);
if (hopsState[hopsFieldsData.getHopsIndex()] == 2) {
player.getDialogueHandler().sendStatement("This plant is diseased. Use a plant cure on it to cure it, ",
"or clear the patch with a spade.");
return true;
} else if (hopsState[hopsFieldsData.getHopsIndex()] == 3) {
player.getDialogueHandler().sendStatement("This plant is dead. You did not cure it while it was diseased.",
"Clear the patch with a spade.");
return true;
}
if (hopsStages[hopsFieldsData.getHopsIndex()] == 0) {
player.getDialogueHandler().sendStatement(
"This is a hops patch. The soil has not been treated.",
"The patch needs weeding.");
} else if (hopsStages[hopsFieldsData.getHopsIndex()] == 3) {
player.getDialogueHandler().sendStatement(
"This is a hops patch. The soil has not been treated.",
"The patch is empty and weeded.");
} else if (inspectData != null && hopsData != null) {
player.getPacketSender().sendMessage(
"You bend down and start to inspect the patch...");
player.startAnimation(1331);
player.stopPlayer(true);
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
if (hopsStages[hopsFieldsData.getHopsIndex()] - 4 < inspectData
.getMessages().length - 2) {
player.getDialogueHandler().sendStatement( inspectData
.getMessages()[hopsStages[hopsFieldsData
.getHopsIndex()] - 4]);
} else if (hopsStages[hopsFieldsData.getHopsIndex()] < hopsData
.getEndingState() - hopsData.getStartingState() + 2) {
player.getDialogueHandler().sendStatement(
inspectData.getMessages()[inspectData
.getMessages().length - 2]);
} else {
player.getDialogueHandler().sendStatement(
inspectData.getMessages()[inspectData
.getMessages().length - 1]);
}
container.stop();
}
@Override
public void stop() {
player.startAnimation(1332);
player.stopPlayer(false);
// player.reset();
}
}, 5);
}
return true;
}
/* opening the corresponding guide about the patch */
public boolean guide(int objectX, int objectY) {
final HopsFieldsData hopsFieldsData = HopsFieldsData.forIdPosition(
objectX, objectY);
if (hopsFieldsData == null) {
return false;
}
if (!SkillConstants.getEnabled(SkillConstants.FARMING.ordinal())) {
player.getPacketSender().sendMessage("This skill is currently disabled.");
return true;
}
player.getSkillInterfaces().farmingComplex(2);
player.getSkillInterfaces().selected = 20;
return true;
}
/* Curing the plant */
public boolean curePlant(int objectX, int objectY, int itemId) {
final HopsFieldsData hopsFieldsData = HopsFieldsData.forIdPosition(
objectX, objectY);
if (hopsFieldsData == null || itemId != 6036) {
return false;
}
final HopsData hopsData = HopsData.forId(hopsSeeds[hopsFieldsData
.getHopsIndex()]);
if (hopsData == null) {
return false;
}
if (!SkillConstants.getEnabled(SkillConstants.FARMING.ordinal())) {
player.getPacketSender().sendMessage("This skill is currently disabled.");
return true;
}
if (hopsState[hopsFieldsData.getHopsIndex()] != 2) {
player.getPacketSender().sendMessage("This plant doesn't need to be cured.");
return true;
}
player.getItemAssistant().deleteItem(itemId, 1);
player.getItemAssistant().addItem(229, 1);
player.startAnimation(FarmingConstants.CURING_ANIM);
player.stopPlayer(true);
hopsState[hopsFieldsData.getHopsIndex()] = 0;
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
player.getPacketSender().sendMessage(
"You cure the plant with a plant cure.");
container.stop();
}
@Override
public void stop() {
updateHopsStates();
player.stopPlayer(false);
player.getPlayerAssistant().resetAnimation();
}
}, 7);
return true;
}
private void resetHops(int index) {
hopsSeeds[index] = 0;
hopsState[index] = 0;
diseaseChance[index] = 1;
hopsHarvest[index] = 0;
hasFullyGrown[index] = false;
hopsWatched[index] = false;
}
/* checking if the patch is raked */
public boolean checkIfRaked(int objectX, int objectY) {
final HopsFieldsData hopsFieldsData = HopsFieldsData.forIdPosition(
objectX, objectY);
if (hopsFieldsData == null)
return false;
if (hopsStages[hopsFieldsData.getHopsIndex()] == 3)
return true;
return false;
}
}
@@ -1,11 +0,0 @@
package com.rebotted.game.content.skills.farming;
/**
* Patch
* @author Andrew (I'm A Boss on Rune-Server and Mr Extremez on Mopar & Runelocus)
*/
public enum Patch {
}
@@ -0,0 +1,5 @@
package com.rebotted.game.content.skills.farming;
public enum PatchState {
EMPTY, DESEASED, DEAD
}
@@ -0,0 +1,167 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.rebotted.game.content.skills.farming;
import java.util.HashMap;
import java.util.Map;
import com.rebotted.game.content.skills.SkillConstants;
import com.rebotted.game.items.Item;
import com.rebotted.game.items.ItemAssistant;
import com.rebotted.game.players.Player;
/**
* Created by IntelliJ IDEA. User: vayken Date: 18/03/12 Time: 11:00 To change
* this template use File | Settings | File Templates.
*/
public class Seedling {
private Player player;
public Seedling(Player player) {
this.player = player;
}
public enum SeedlingData {
OAK(5312, 5358, 5364, 5370), WILLOW(5313, 5359, 5365, 5371), MAPLE(
5314, 5360, 5366, 5372), YEW(5315, 5361, 5367, 5373), MAGIC(
5316, 5362, 5368, 5374), SPIRIT(5317, 5363, 5369, 5375), APPLE(
5283, 5480, 5488, 5496), BANANA(5284, 5481, 5489, 5497), ORANGE(
5285, 5482, 5490, 5498), CURRY(5286, 5483, 5491, 5499), PINEAPPLE(
5287, 5484, 5492, 5500), PAPAYA(5288, 5485, 5493, 5501), PALM(
5289, 5486, 5494, 5502), CALQUAT(5290, 5487, 5495, 5503);
private int seedId;
private int unwateredSeedlingId;
private int wateredSeedlingId;
private int saplingId;
private static Map<Integer, SeedlingData> seeds = new HashMap<Integer, SeedlingData>();
private static Map<Integer, SeedlingData> unwatered = new HashMap<Integer, SeedlingData>();
private static Map<Integer, SeedlingData> watered = new HashMap<Integer, SeedlingData>();
static {
for (SeedlingData data : SeedlingData.values()) {
seeds.put(data.seedId, data);
unwatered.put(data.unwateredSeedlingId, data);
watered.put(data.wateredSeedlingId, data);
}
}
SeedlingData(int seedId, int unwateredSeedlingId,
int wateredSeedlingId, int saplingId) {
this.seedId = seedId;
this.unwateredSeedlingId = unwateredSeedlingId;
this.wateredSeedlingId = wateredSeedlingId;
this.saplingId = saplingId;
}
public static SeedlingData getSeed(int seedId) {
return seeds.get(seedId);
}
public static SeedlingData getUnwatered(int seedId) {
return unwatered.get(seedId);
}
public static SeedlingData getWatered(int seedId) {
return watered.get(seedId);
}
public int getSeedId() {
return seedId;
}
public int getUnwateredSeedlingId() {
return unwateredSeedlingId;
}
public int getWateredSeedlingId() {
return wateredSeedlingId;
}
public int getSaplingId() {
return saplingId;
}
}
public void makeSaplingInInv(int itemId) {
SeedlingData seedlingData = SeedlingData.getWatered(itemId);
if (seedlingData == null)
return;
player.getItemAssistant().deleteItem(itemId, 1);
player.getItemAssistant().addItem(seedlingData.getSaplingId(), 1);
}
public void makeSaplingInBank(int itemId) {
SeedlingData seedlingData = SeedlingData.getWatered(itemId);
if (seedlingData == null)
return;
player.getItemAssistant().removeItemFromBank(itemId, 1);
player.getItemAssistant().addItemToBank(seedlingData.getSaplingId(), 1);
}
public boolean waterSeedling(int itemUsed, int usedWith, int itemUsedSlot,
int usedWithSlot) {
SeedlingData seedlingData = SeedlingData.getUnwatered(itemUsed);
if (seedlingData == null)
seedlingData = SeedlingData.getUnwatered(usedWith);
if (seedlingData == null
|| (!ItemAssistant.getItemName(itemUsed).toLowerCase()
.contains("watering") && !ItemAssistant.getItemName(usedWith)
.toLowerCase()
.contains("watering")))
return false;
if (itemUsed >= 5333 && itemUsed <= 5340)
player.getInventory().set(itemUsedSlot, new Item(itemUsed == 5333 ? itemUsed - 2 : itemUsed - 1));
if (usedWith >= 5333 && usedWith <= 5340)
player.getInventory().set(usedWithSlot, new Item(usedWith == 5333 ? usedWith - 2 : usedWith - 1));
player.getPacketSender().sendMessage(
"You water the "
+ ItemAssistant.getItemName(seedlingData.getSeedId()).toLowerCase() + ".");
player.getItemAssistant().deleteItem(seedlingData.getUnwateredSeedlingId(), 1);
player.getItemAssistant().addItem(seedlingData.getWateredSeedlingId(), 1);
return true;
}
public boolean placeSeedInPot(int itemUsed, int usedWith, int itemUsedSlot,
int usedWithSlot) {
SeedlingData seedlingData = SeedlingData.getSeed(itemUsed);
if (seedlingData == null)
seedlingData = SeedlingData.getUnwatered(usedWith);
if (seedlingData == null || (itemUsed != 5354 && usedWith != 5354))
return false;
player.getItemAssistant().deleteItem(seedlingData.getSeedId(), 1);
player.getInventory().set(
itemUsed == 5354 ? itemUsedSlot : usedWithSlot,
new Item(seedlingData.getUnwateredSeedlingId()));
player.getPacketSender().sendMessage(
"You sow some maple tree seeds in the plantpots.");
player.getPacketSender().sendMessage("They need watering before they will grow.");
return true;
}
public boolean fillPotWithSoil(int itemId, int objectX, int objectY) {
if (itemId != 5350)
return false;
if (!SkillConstants.getEnabled(SkillConstants.FARMING.ordinal())) {
player.getPacketSender().sendMessage("This skill is currently disabled.");
return true;
}
if (!player.getItemAssistant().playerHasItem(FarmingConstants.TROWEL)) {
player.getPacketSender().sendMessage(
"You need a gardening trowel to fill this pot with soil.");
return true;
}
player.getItemAssistant().deleteItem(itemId, 1);
player.startAnimation(FarmingConstants.FILLING_POT_ANIM);
player.getPacketSender().sendMessage("You fill the empty plant pot with soil.");
player.getItemAssistant().addItem(5354, 1);
return true;
}
}
@@ -0,0 +1,886 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.rebotted.game.content.skills.farming;
/**
*
* @author ArrowzFtw
*/
import java.awt.Point;
import java.util.HashMap;
import java.util.Map;
import com.rebotted.GameEngine;
import com.rebotted.event.CycleEvent;
import com.rebotted.event.CycleEventContainer;
import com.rebotted.event.CycleEventHandler;
import com.rebotted.game.content.skills.SkillConstants;
import com.rebotted.game.items.ItemAssistant;
import com.rebotted.game.players.Player;
import com.rebotted.util.Misc;
/**
* Created by IntelliJ IDEA. User: vayken Date: 24/02/12 Time: 20:34 To change
* this template use File | Settings | File Templates.
*/
public class SpecialPlantOne {
private Player player;
// set of global constants for Farming
private static final double COMPOST_CHANCE = 0.9;
private static final double SUPERCOMPOST_CHANCE = 0.7;
private static final double CLEARING_EXPERIENCE = 4;
public SpecialPlantOne(Player player) {
this.player = player;
}
// Farming data
public int[] specialPlantStages = new int[4];
public int[] specialPlantSaplings = new int[4];
public int[] specialPlantState = new int[4];
public long[] specialPlantTimer = new long[4];
public double[] diseaseChance = { 1, 1, 1, 1 };
public boolean[] hasFullyGrown = { false, false, false, false };
public static final int MAIN_SPECIAL_PLANT_CONFIG = 507;
/* This is the enum holding the saplings info */
public enum SpecialPlantData {
SPIRIT_TREE(5375, -1, 1, 83, 3680, 0.15, 199.5, 0, 0x09, 0x14, 0x2c,
19301.8, 12, 23), CALQUAT_TREE(5503, 5980, 1, 72, 1200, 0.15,
129.5, 48.5, 0x04, 0x12, 0x22, 12096, 14, 20);
private int saplingId;
private int harvestId;
private int saplingAmount;
private int levelRequired;
private int growthTime;
private double diseaseChance;
private double plantingXp;
private double harvestXp;
private int startingState;
private int endingState;
private int checkHealthState;
private double checkHealthExperience;
private int diseaseDiffValue;
private int deathDiffValue;
private static Map<Integer, SpecialPlantData> saplings = new HashMap<Integer, SpecialPlantData>();
static {
for (SpecialPlantData data : SpecialPlantData.values()) {
saplings.put(data.saplingId, data);
}
}
SpecialPlantData(int saplingId, int harvestId, int saplingAmount,
int levelRequired, int growthTime, double diseaseChance,
double plantingXp, double harvestXp, int startingState,
int endingState, int checkHealthState,
double checkHealthExperience, int diseaseDiffValue,
int deathDiffValue) {
this.saplingId = saplingId;
this.harvestId = harvestId;
this.saplingAmount = saplingAmount;
this.levelRequired = levelRequired;
this.growthTime = growthTime;
this.diseaseChance = diseaseChance;
this.plantingXp = plantingXp;
this.harvestXp = harvestXp;
this.startingState = startingState;
this.endingState = endingState;
this.checkHealthState = checkHealthState;
this.checkHealthExperience = checkHealthExperience;
this.diseaseDiffValue = diseaseDiffValue;
this.deathDiffValue = deathDiffValue;
}
public static SpecialPlantData forId(int saplingId) {
return saplings.get(saplingId);
}
public int getSapplingId() {
return saplingId;
}
public int getHarvestId() {
return harvestId;
}
public int getSeedAmount() {
return saplingAmount;
}
public int getLevelRequired() {
return levelRequired;
}
public int getGrowthTime() {
return growthTime;
}
public double getDiseaseChance() {
return diseaseChance;
}
public double getPlantingXp() {
return plantingXp;
}
public double getHarvestXp() {
return harvestXp;
}
public int getStartingState() {
return startingState;
}
public int getEndingState() {
return endingState;
}
public int getCheckHealthState() {
return checkHealthState;
}
public double getCheckHealthXp() {
return checkHealthExperience;
}
public int getDiseaseDiffValue() {
return diseaseDiffValue;
}
public int getDeathDiffValue() {
return deathDiffValue;
}
}
/* This is the enum data about the different patches */
public enum SpecialPlantFieldsData {
BRIMHAVEN(0,
new Point[] { new Point(2801, 3202), new Point(2803, 3204) },
5375), KARAMJA(1, new Point[] { new Point(2795, 3100),
new Point(2797, 3102) }, 5503), DRAYNOR(2, new Point[] {
new Point(3059, 3257), new Point(3061, 3259) }, 5375), ETCETERIA(
3,
new Point[] { new Point(2612, 3857), new Point(2614, 3859) },
5375);
private int specialPlantsIndex;
private Point[] specialPlantPosition;
private int seedId;
SpecialPlantFieldsData(int specialPlantsIndex,
Point[] specialPlantPosition, int seedId) {
this.specialPlantsIndex = specialPlantsIndex;
this.specialPlantPosition = specialPlantPosition;
this.seedId = seedId;
}
public static SpecialPlantFieldsData forIdPosition(int x, int y) {
for (SpecialPlantFieldsData specialPlantFieldsData : SpecialPlantFieldsData
.values()) {
if (FarmingConstants.inRangeArea(
specialPlantFieldsData.getSpecialPlantPosition()[0],
specialPlantFieldsData.getSpecialPlantPosition()[1], x,
y)) {
return specialPlantFieldsData;
}
}
return null;
}
public int getSpecialPlantsIndex() {
return specialPlantsIndex;
}
public Point[] getSpecialPlantPosition() {
return specialPlantPosition;
}
public int getSaplingd() {
return seedId;
}
}
/* This is the enum that hold the different data for inspecting the plant */
public enum InspectData {
SPIRIT_TREE(
5375,
new String[][] {
{ "The spirit tree sapling has only just been planted. It has not grown yet." },
{ "The spirit tree has grown slightly, and sprouted a few more leaves." },
{ "Some dark spots have appeared on the trees trunk, and the leaves have grown longer." },
{ "The tree has grown larger in all respects, and has grown more leaves." },
{
"The spirit tree base has widened showing some roots, and the leaves have morphed into a small canopy.",
"Two small branches have appeared on either side of the trunk." },
{
"The spirit tree has grown wider in girth, but is still the same height as before.",
"The base is larger as well." },
{ "The spirit tree has grown larger in all respects.",
"The trunk is more warped towards the west, and the roots are more visible" },
{ "The spirit tree is larger in all respects.",
"The trunk has grown in a 'S' shape." },
{
"The spirit tree has grown another knob on the trunk which will eventually become its nose.",
"The tree is larger in all respects, and its branches are growing out to the sides more." },
{
"The spirit tree canopy shifts the angle its inclining towards, and its branches are almost parallel to the ground.",
"he nose is more defined, and the tree is slightly larger." },
{ "The spirit tree branches are slightly angling towards the ground, and it is slightly larger than before." },
{
"The spirit tree canopy is smaller, the face is fully defined and the texture of the tree has changed dramatically",
"The Spirit tree is ready to be checked." } }), CALQUAT_TREE(
5503,
new String[][] {
{ "The calquat sapling has only just been planted." },
{ "The calquat tree grows another segment taller." },
{ "The calquat tree grows another segment taller." },
{ "The calquat tree grows another segment longer and starts a branch midway up its trunk." },
{ "The calquat tree grows some leaves." },
{ "The calquat tree grows another segment upside down and grows leaves on its mid-branch." },
{ "The calquat tree grows towards the ground." },
{ "The calquat tree is ready to be harvested." }, });
private int saplingId;
private String[][] messages;
private static Map<Integer, InspectData> saplings = new HashMap<Integer, InspectData>();
static {
for (InspectData data : InspectData.values()) {
saplings.put(data.saplingId, data);
}
}
InspectData(int saplingId, String[][] messages) {
this.saplingId = saplingId;
this.messages = messages;
}
public static InspectData forId(int saplingId) {
return saplings.get(saplingId);
}
public int getSeedId() {
return saplingId;
}
public String[][] getMessages() {
return messages;
}
}
/* update all the patch states */
public void updateSpecialPlants() {
// brimhaven - karamja - draynor - Etceteria
int[] configValues = new int[specialPlantStages.length];
int configValue;
for (int i = 0; i < specialPlantStages.length; i++) {
configValues[i] = getConfigValue(specialPlantStages[i],
specialPlantSaplings[i], specialPlantState[i], i);
}
configValue = (configValues[0] << 16) + (configValues[1] << 8 << 16)
+ configValues[2] + (configValues[3] << 8);
player.getPacketSender().sendConfig(MAIN_SPECIAL_PLANT_CONFIG, configValue);
}
/* getting the different config values */
public int getConfigValue(int specialStage, int saplingId, int plantState,
int index) {
SpecialPlantData specialPlantData = SpecialPlantData.forId(saplingId);
switch (specialStage) {
case 0:// weed
return 0x00;
case 1:// weed cleared
return 0x01;
case 2:
return 0x02;
case 3:
return 0x03;
}
if (specialPlantData == null) {
return -1;
}
if (specialStage > specialPlantData.getEndingState()
- specialPlantData.getStartingState() - 1) {
hasFullyGrown[index] = true;
}
if (getPlantState(plantState, specialPlantData, specialStage) == 3)
return specialPlantData.getCheckHealthState();
return getPlantState(plantState, specialPlantData, specialStage);
}
/* getting the plant states */
public int getPlantState(int plantState, SpecialPlantData specialPlantData,
int specialStage) {
int value = specialPlantData.getStartingState() + specialStage - 4;
switch (plantState) {
case 0:
return value;
case 1:
return value + specialPlantData.getDiseaseDiffValue();
case 2:
return value + specialPlantData.getDeathDiffValue();
case 3:
return specialPlantData.getCheckHealthState();
}
return -1;
}
/* calculating the disease chance and making the plant grow */
public void doCalculations() {
for (int i = 0; i < specialPlantSaplings.length; i++) {
if (specialPlantStages[i] > 0
&& specialPlantStages[i] <= 3
&& GameEngine.getMinutesCounter() - specialPlantTimer[i] >= 5) {
specialPlantStages[i]--;
specialPlantTimer[i] = GameEngine.getMinutesCounter();
updateSpecialPlants();
continue;
}
SpecialPlantData specialPlantData = SpecialPlantData
.forId(specialPlantSaplings[i]);
if (specialPlantData == null) {
continue;
}
long difference = GameEngine.getMinutesCounter()
- specialPlantTimer[i];
long growth = specialPlantData.getGrowthTime();
int nbStates = specialPlantData.getEndingState()
- specialPlantData.getStartingState();
int state = (int) (difference * nbStates / growth);
if (specialPlantTimer[i] == 0 || specialPlantState[i] == 2
|| specialPlantState[i] == 3 || (state > nbStates)) {
continue;
}
if (4 + state != specialPlantStages[i]
&& specialPlantStages[i] <= specialPlantData
.getEndingState()
- specialPlantData.getStartingState()
+ (specialPlantData == SpecialPlantData.SPIRIT_TREE ? 3
: -2)) {
if (specialPlantStages[i] == specialPlantData.getEndingState()
- specialPlantData.getStartingState()
+ (specialPlantData == SpecialPlantData.SPIRIT_TREE ? 3
: -2)) {
specialPlantStages[i] = specialPlantData.getEndingState()
- specialPlantData.getStartingState() + 7;
specialPlantState[i] = 3;
updateSpecialPlants();
return;
}
specialPlantStages[i] = 4 + state;
doStateCalculation(i);
updateSpecialPlants();
}
}
}
public void modifyStage(int i) {
SpecialPlantData specialPlantData = SpecialPlantData
.forId(specialPlantSaplings[i]);
if (specialPlantData == null)
return;
long difference = GameEngine.getMinutesCounter() - specialPlantTimer[i];
long growth = specialPlantData.getGrowthTime();
int nbStates = specialPlantData.getEndingState()
- specialPlantData.getStartingState();
int state = (int) (difference * nbStates / growth);
specialPlantStages[i] = 4 + state;
updateSpecialPlants();
}
/* calculations about the diseasing chance */
public void doStateCalculation(int index) {
if (specialPlantState[index] == 2) {
return;
}
// if the patch is diseased, it dies, if its watched by a farmer, it
// goes back to normal
if (specialPlantState[index] == 1) {
specialPlantState[index] = 2;
}
if (specialPlantState[index] == 5 && specialPlantStages[index] != 2) {
specialPlantState[index] = 0;
}
if (specialPlantState[index] == 0 && specialPlantStages[index] >= 5
&& !hasFullyGrown[index]) {
SpecialPlantData specialPlantData = SpecialPlantData
.forId(specialPlantSaplings[index]);
if (specialPlantData == null) {
return;
}
double chance = diseaseChance[index]
* specialPlantData.getDiseaseChance();
int maxChance = (int) chance * 100;
if (Misc.random(100) < maxChance) {
specialPlantState[index] = 1;
}
}
}
/* clearing the patch with a rake of a spade */
public boolean clearPatch(int objectX, int objectY, int itemId) {
final SpecialPlantFieldsData hopsFieldsData = SpecialPlantFieldsData
.forIdPosition(objectX, objectY);
int finalAnimation;
int finalDelay;
if (hopsFieldsData == null
|| (itemId != FarmingConstants.RAKE && itemId != FarmingConstants.SPADE)) {
return false;
}
if (!SkillConstants.getEnabled(SkillConstants.FARMING.ordinal())) {
player.getPacketSender().sendMessage("This skill is currently disabled.");
return true;
}
if (specialPlantStages[hopsFieldsData.getSpecialPlantsIndex()] == 3) {
return true;
}
if (specialPlantStages[hopsFieldsData.getSpecialPlantsIndex()] <= 3) {
if (!player.getItemAssistant().playerHasItem(FarmingConstants.RAKE)) {
player.getDialogueHandler().sendStatement(
"You need a rake to clear this path.");
return true;
} else {
finalAnimation = FarmingConstants.RAKING_ANIM;
finalDelay = 5;
}
} else {
if (!player.getItemAssistant().playerHasItem(FarmingConstants.SPADE)) {
player.getDialogueHandler().sendStatement(
"You need a spade to clear this path.");
return true;
} else {
finalAnimation = FarmingConstants.SPADE_ANIM;
finalDelay = 3;
}
}
final int animation = finalAnimation;
player.stopPlayer(true);
player.startAnimation(animation);
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
player.startAnimation(animation);
if (specialPlantStages[hopsFieldsData.getSpecialPlantsIndex()] <= 2) {
specialPlantStages[hopsFieldsData.getSpecialPlantsIndex()]++;
player.getItemAssistant().addItem(6055, 1);
} else {
specialPlantStages[hopsFieldsData.getSpecialPlantsIndex()] = 3;
container.stop();
}
player.getPlayerAssistant().addSkillXP(CLEARING_EXPERIENCE, SkillConstants.FARMING.ordinal());
specialPlantTimer[hopsFieldsData.getSpecialPlantsIndex()] = GameEngine
.getMinutesCounter();
updateSpecialPlants();
if (specialPlantStages[hopsFieldsData.getSpecialPlantsIndex()] == 3) {
container.stop();
return;
}
}
@Override
public void stop() {
resetSpecialPlants(hopsFieldsData.getSpecialPlantsIndex());
player.getPacketSender().sendMessage("You clear the patch.");
player.stopPlayer(false);
player.getPlayerAssistant().resetAnimation();
}
}, finalDelay);
return true;
}
/* planting the saplings */
public boolean plantSapling(int objectX, int objectY, final int saplingId) {
final SpecialPlantFieldsData specialPlantFieldData = SpecialPlantFieldsData
.forIdPosition(objectX, objectY);
final SpecialPlantData specialPlantData = SpecialPlantData
.forId(saplingId);
if (specialPlantFieldData == null || specialPlantData == null
|| specialPlantFieldData.getSaplingd() != saplingId) {
return false;
}
if (!SkillConstants.getEnabled(SkillConstants.FARMING.ordinal())) {
player.getPacketSender().sendMessage("This skill is currently disabled.");
return true;
}
if ((specialPlantStages[0] > 3 || specialPlantStages[2] > 3 || specialPlantStages[3] > 3)
&& (specialPlantFieldData.getSpecialPlantsIndex() != 1)) {
player.getPacketSender().sendMessage(
"You already have a spirit tree planted somewhere else.");
return true;
}
if (specialPlantStages[specialPlantFieldData.getSpecialPlantsIndex()] != 3) {
player.getPacketSender().sendMessage("You can't plant a sapling here.");
return true;
}
if (specialPlantData.getLevelRequired() > player.playerLevel[SkillConstants.FARMING.ordinal()]) {
player.getDialogueHandler().sendStatement("You need a farming level of "
+ specialPlantData.getLevelRequired()
+ " to plant this sapling.");
return true;
}
if (!player.getItemAssistant().playerHasItem(FarmingConstants.TROWEL)) {
player.getDialogueHandler().sendStatement(
"You need a trowel to plant the sapling here.");
return true;
}
player.startAnimation(
FarmingConstants.PLANTING_POT_ANIM);
specialPlantStages[specialPlantFieldData.getSpecialPlantsIndex()] = 4;
player.getItemAssistant().deleteItem(saplingId, 1);
player.stopPlayer(true);
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
specialPlantState[specialPlantFieldData.getSpecialPlantsIndex()] = 0;
specialPlantSaplings[specialPlantFieldData
.getSpecialPlantsIndex()] = saplingId;
specialPlantTimer[specialPlantFieldData.getSpecialPlantsIndex()] = GameEngine
.getMinutesCounter();
player.getPlayerAssistant().addSkillXP(specialPlantData.getPlantingXp(), SkillConstants.FARMING.ordinal());
container.stop();
}
@Override
public void stop() {
updateSpecialPlants();
player.stopPlayer(false);
player.getPlayerAssistant().resetAnimation();
}
}, 3);
return true;
}
/* harvesting the plant resulted */
public boolean harvestOrCheckHealth(int objectX, int objectY) {
final SpecialPlantFieldsData specialPlantFieldsData = SpecialPlantFieldsData
.forIdPosition(objectX, objectY);
if (specialPlantFieldsData == null) {
return false;
}
final SpecialPlantData specialPlantData = SpecialPlantData
.forId(specialPlantSaplings[specialPlantFieldsData
.getSpecialPlantsIndex()]);
if (specialPlantData == null) {
return false;
}
if (!SkillConstants.getEnabled(SkillConstants.FARMING.ordinal())) {
player.getPacketSender().sendMessage("This skill is currently disabled.");
return true;
}
if (specialPlantData == SpecialPlantData.SPIRIT_TREE
&& specialPlantState[specialPlantFieldsData
.getSpecialPlantsIndex()] != 3) {
handleSpiritTree();
return true;
}
if (player.getItemAssistant().freeSlots() <= 0) {
player.getPacketSender().sendMessage("Not enough space in your inventory.");
return true;
}
player.startAnimation(832);
player.stopPlayer(true);
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
if (player.getItemAssistant().freeSlots() <= 0) {
container.stop();
return;
}
if (specialPlantState[specialPlantFieldsData
.getSpecialPlantsIndex()] == 3) {
player.getPacketSender()
.sendMessage(
"You examine the plant for signs of disease and find that it's in perfect health.");
player.getPlayerAssistant().addSkillXP(specialPlantData.getCheckHealthXp(), SkillConstants.FARMING.ordinal());
specialPlantState[specialPlantFieldsData
.getSpecialPlantsIndex()] = 0;
hasFullyGrown[specialPlantFieldsData
.getSpecialPlantsIndex()] = false;
specialPlantTimer[specialPlantFieldsData
.getSpecialPlantsIndex()] = GameEngine
.getMinutesCounter()
- specialPlantData.getGrowthTime();
modifyStage(specialPlantFieldsData.getSpecialPlantsIndex());
container.stop();
return;
}
player.getPacketSender().sendMessage(
"You harvest the crop, and pick some "
+ ItemAssistant.getItemName(specialPlantData.getHarvestId()).toLowerCase() + ".");
player.getItemAssistant().addItem(
specialPlantData.getHarvestId(), 1);
player.getPlayerAssistant().addSkillXP(specialPlantData.getHarvestXp(), SkillConstants.FARMING.ordinal());
specialPlantStages[specialPlantFieldsData
.getSpecialPlantsIndex()]--;
updateSpecialPlants();
container.stop();
}
@Override
public void stop() {
player.stopPlayer(false);
player.getPlayerAssistant().resetAnimation();
}
}, 2);
return true;
}
private void handleSpiritTree() {
// SpiritTree.sendDialogue(player, 3636);
}
/* lowering the stage */
public void lowerStage(int index, int timer) {
hasFullyGrown[index] = false;
specialPlantTimer[index] -= timer;
}
/* putting compost onto the plant */
public boolean putCompost(int objectX, int objectY, final int itemId) {
if (itemId != 6032 && itemId != 6034) {
return false;
}
final SpecialPlantFieldsData specialPlantFieldsData = SpecialPlantFieldsData
.forIdPosition(objectX, objectY);
if (specialPlantFieldsData == null) {
return false;
}
if (!SkillConstants.getEnabled(SkillConstants.FARMING.ordinal())) {
player.getPacketSender().sendMessage("This skill is currently disabled.");
return true;
}
if (specialPlantStages[specialPlantFieldsData.getSpecialPlantsIndex()] != 3
|| specialPlantState[specialPlantFieldsData
.getSpecialPlantsIndex()] == 5) {
player.getPacketSender().sendMessage("This patch doesn't need compost.");
return true;
}
player.getItemAssistant().deleteItem(itemId, 1);
player.getItemAssistant().addItem(1925, 1);
player.getPacketSender().sendMessage(
"You pour some " + (itemId == 6034 ? "super" : "")
+ "compost on the patch.");
player.startAnimation(FarmingConstants.PUTTING_COMPOST);
player.getPlayerAssistant().addSkillXP(itemId == 6034 ? Compost.SUPER_COMPOST_EXP_USE
: Compost.COMPOST_EXP_USE, SkillConstants.FARMING.ordinal());
player.stopPlayer(true);
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
diseaseChance[specialPlantFieldsData.getSpecialPlantsIndex()] *= itemId == 6032 ? COMPOST_CHANCE
: SUPERCOMPOST_CHANCE;
specialPlantState[specialPlantFieldsData
.getSpecialPlantsIndex()] = 5;
container.stop();
}
@Override
public void stop() {
player.stopPlayer(false);
player.getPlayerAssistant().resetAnimation();
}
}, 7);
return true;
}
/* inspecting a plant */
public boolean inspect(int objectX, int objectY) {
final SpecialPlantFieldsData specialPlantFieldsData = SpecialPlantFieldsData
.forIdPosition(objectX, objectY);
if (specialPlantFieldsData == null) {
return false;
}
if (!SkillConstants.getEnabled(SkillConstants.FARMING.ordinal())) {
player.getPacketSender().sendMessage("This skill is currently disabled.");
return true;
}
final InspectData inspectData = InspectData
.forId(specialPlantSaplings[specialPlantFieldsData
.getSpecialPlantsIndex()]);
final SpecialPlantData specialPlantData = SpecialPlantData
.forId(specialPlantSaplings[specialPlantFieldsData
.getSpecialPlantsIndex()]);
if (specialPlantState[specialPlantFieldsData.getSpecialPlantsIndex()] == 1) {
player.getDialogueHandler().sendStatement("This plant is diseased. Use a plant cure on it to cure it, ",
"or clear the patch with a spade.");
return true;
} else if (specialPlantState[specialPlantFieldsData
.getSpecialPlantsIndex()] == 2) {
player.getDialogueHandler().sendStatement("This plant is dead. You did not cure it while it was diseased.",
"Clear the patch with a spade.");
return true;
} else if (specialPlantState[specialPlantFieldsData
.getSpecialPlantsIndex()] == 3) {
player.getDialogueHandler().sendStatement(
"This plant has fully grown. You can check it's health",
"to gain some farming experiences.");
return true;
}
if (specialPlantStages[specialPlantFieldsData.getSpecialPlantsIndex()] == 0) {
player.getDialogueHandler().sendStatement("This is one of the special patches. The soil has not been treated.",
"The patch needs weeding.");
} else if (specialPlantStages[specialPlantFieldsData
.getSpecialPlantsIndex()] == 3) {
player.getDialogueHandler().sendStatement("This is one of the special patches. The soil has not been treated.",
"The patch is empty and weeded.");
} else if (inspectData != null && specialPlantData != null) {
player.getPacketSender().sendMessage(
"You bend down and start to inspect the patch...");
player.startAnimation(1331);
player.stopPlayer(true);
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
if (specialPlantStages[specialPlantFieldsData
.getSpecialPlantsIndex()] - 4 < inspectData
.getMessages().length - 2) {
player.getDialogueHandler().sendStatement(inspectData.getMessages()[specialPlantStages[specialPlantFieldsData
.getSpecialPlantsIndex()] - 4]);
} else if (specialPlantStages[specialPlantFieldsData
.getSpecialPlantsIndex()] < specialPlantData
.getEndingState()
- specialPlantData.getStartingState() + 2) {
player.getDialogueHandler().sendStatement(
inspectData.getMessages()[inspectData
.getMessages().length - 2]);
} else {
player.getDialogueHandler().sendStatement(
inspectData.getMessages()[inspectData
.getMessages().length - 1]);
}
container.stop();
}
@Override
public void stop() {
player.startAnimation(1332);
player.stopPlayer(false);
}
}, 5);
}
return true;
}
/* opening the corresponding guide about the patch */
public boolean guide(int objectX, int objectY) {
final SpecialPlantFieldsData specialPlantFieldsData = SpecialPlantFieldsData
.forIdPosition(objectX, objectY);
if (specialPlantFieldsData == null) {
return false;
}
if (!SkillConstants.getEnabled(SkillConstants.FARMING.ordinal())) {
player.getPacketSender().sendMessage("This skill is currently disabled.");
return true;
}
player.getSkillInterfaces().farmingComplex(8);
player.getSkillInterfaces().selected = 20;
return true;
}
/* Curing the plant */
public boolean curePlant(int objectX, int objectY, int itemId) {
final SpecialPlantFieldsData specialPlantFieldsData = SpecialPlantFieldsData
.forIdPosition(objectX, objectY);
if (specialPlantFieldsData == null || itemId != 6036) {
return false;
}
final SpecialPlantData specialPlantData = SpecialPlantData
.forId(specialPlantSaplings[specialPlantFieldsData
.getSpecialPlantsIndex()]);
if (specialPlantData == null) {
return false;
}
if (!SkillConstants.getEnabled(SkillConstants.FARMING.ordinal())) {
player.getPacketSender().sendMessage("This skill is currently disabled.");
return true;
}
if (specialPlantState[specialPlantFieldsData.getSpecialPlantsIndex()] != 1) {
player.getPacketSender().sendMessage("This plant doesn't need to be cured.");
return true;
}
player.getItemAssistant().deleteItem(itemId, 1);
player.getItemAssistant().addItem(229, 1);
player.startAnimation(FarmingConstants.CURING_ANIM);
player.stopPlayer(true);
specialPlantState[specialPlantFieldsData.getSpecialPlantsIndex()] = 0;
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
player.getPacketSender().sendMessage(
"You cure the plant with a plant cure.");
container.stop();
}
@Override
public void stop() {
updateSpecialPlants();
player.stopPlayer(false);
player.getPlayerAssistant().resetAnimation();
}
}, 7);
return true;
}
private void resetSpecialPlants(int index) {
specialPlantSaplings[index] = 0;
specialPlantState[index] = 0;
diseaseChance[index] = 1;
hasFullyGrown[index] = false;
}
/* checking if the patch is raked */
public boolean checkIfRaked(int objectX, int objectY) {
final SpecialPlantFieldsData specialPlantFieldData = SpecialPlantFieldsData
.forIdPosition(objectX, objectY);
if (specialPlantFieldData == null)
return false;
if (specialPlantStages[specialPlantFieldData.getSpecialPlantsIndex()] == 3)
return true;
return false;
}
}
@@ -0,0 +1,892 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.rebotted.game.content.skills.farming;
/**
*
* @author ArrowzFtw
*/
import java.awt.Point;
import java.util.HashMap;
import java.util.Map;
import com.rebotted.GameEngine;
import com.rebotted.event.CycleEvent;
import com.rebotted.event.CycleEventContainer;
import com.rebotted.event.CycleEventHandler;
import com.rebotted.game.content.skills.SkillConstants;
import com.rebotted.game.players.Player;
import com.rebotted.util.Misc;
/**
* Created by IntelliJ IDEA. User: vayken Date: 24/02/12 Time: 20:34 To change
* this template use File | Settings | File Templates.
*/
public class SpecialPlantTwo {
private Player player;
// set of global constants for Farming
private static final double COMPOST_CHANCE = 0.9;
private static final double SUPERCOMPOST_CHANCE = 0.7;
private static final double CLEARING_EXPERIENCE = 4;
public SpecialPlantTwo(Player player) {
this.player = player;
}
// Farming data
public int[] specialPlantStages = new int[4];
public int[] specialPlantSeeds = new int[4];
public int[] specialPlantState = new int[4];
public long[] specialPlantTimer = new long[4];
public double[] diseaseChance = { 1, 1, 1, 1 };
public boolean[] hasFullyGrown = { false, false, false, false };
public static final int MAIN_SPECIAL_PLANT_CONFIG = 512;
/* This is the enum holding the seeds info */
public enum SpecialPlantData {
BELLADONNA(5281, 2398, 1, 63, 280, 0.15, 91, 512, 0x04, 0x08, -1, 0, 5,
8), CACTUS(5280, 6016, 1, 55, 550, 0.15, 66.5, 25, 0x08, 0x12,
0x1f, 374, 11, 17), BITTERCAP(5282, 6004, 1, 53, 220, 0.15,
61.5, 57.7, 0x04, 0x0f, -1, 0, 12, 17);
private int seedId;
private int harvestId;
private int seedAmount;
private int levelRequired;
private int growthTime;
private double diseaseChance;
private double plantingXp;
private double harvestXp;
private int startingState;
private int endingState;
private int checkHealthState;
private double checkHealthExperience;
private int diseaseDiffValue;
private int deathDiffValue;
private static Map<Integer, SpecialPlantData> seeds = new HashMap<Integer, SpecialPlantData>();
static {
for (SpecialPlantData data : SpecialPlantData.values()) {
seeds.put(data.seedId, data);
}
}
SpecialPlantData(int seedId, int harvestId, int seedAmount,
int levelRequired, int growthTime, double diseaseChance,
double plantingXp, double harvestXp, int startingState,
int endingState, int checkHealthState,
double checkHealthExperience, int diseaseDiffValue,
int deathDiffValue) {
this.seedId = seedId;
this.harvestId = harvestId;
this.seedAmount = seedAmount;
this.levelRequired = levelRequired;
this.growthTime = growthTime;
this.diseaseChance = diseaseChance;
this.plantingXp = plantingXp;
this.harvestXp = harvestXp;
this.startingState = startingState;
this.endingState = endingState;
this.checkHealthState = checkHealthState;
this.checkHealthExperience = checkHealthExperience;
this.diseaseDiffValue = diseaseDiffValue;
this.deathDiffValue = deathDiffValue;
}
public static SpecialPlantData forId(int seedId) {
return seeds.get(seedId);
}
public int getSeedId() {
return seedId;
}
public int getHarvestId() {
return harvestId;
}
public int getSeedAmount() {
return seedAmount;
}
public int getLevelRequired() {
return levelRequired;
}
public int getGrowthTime() {
return growthTime;
}
public double getDiseaseChance() {
return diseaseChance;
}
public double getPlantingXp() {
return plantingXp;
}
public double getHarvestXp() {
return harvestXp;
}
public int getStartingState() {
return startingState;
}
public int getEndingState() {
return endingState;
}
public int getCheckHealthState() {
return checkHealthState;
}
public double getCheckHealthXp() {
return checkHealthExperience;
}
public int getDiseaseDiffValue() {
return diseaseDiffValue;
}
public int getDeathDiffValue() {
return deathDiffValue;
}
}
/* This is the enum data about the different patches */
public enum SpecialPlantFieldsData {
DRAYNOR_MANOR(0, new Point[] { new Point(3086, 3354),
new Point(3087, 3355) }, 5281), AL_KARID(2, new Point[] {
new Point(3315, 3202), new Point(3316, 3203) }, 5280), CANIFIS(
3,
new Point[] { new Point(3451, 3472), new Point(3452, 3473) },
5282);
private int specialPlantsIndex;
private Point[] specialPlantPosition;
private int seedId;
SpecialPlantFieldsData(int specialPlantsIndex,
Point[] specialPlantPosition, int seedId) {
this.specialPlantsIndex = specialPlantsIndex;
this.specialPlantPosition = specialPlantPosition;
this.seedId = seedId;
}
public static SpecialPlantFieldsData forIdPosition(int x, int y) {
for (SpecialPlantFieldsData specialPlantFieldsData : SpecialPlantFieldsData
.values()) {
if (FarmingConstants.inRangeArea(
specialPlantFieldsData.getSpecialPlantPosition()[0],
specialPlantFieldsData.getSpecialPlantPosition()[1], x,
y)) {
return specialPlantFieldsData;
}
}
return null;
}
public int getSpecialPlantsIndex() {
return specialPlantsIndex;
}
public Point[] getSpecialPlantPosition() {
return specialPlantPosition;
}
public int getSeedId() {
return seedId;
}
}
/* This is the enum that hold the different data for inspecting the plant */
public enum InspectData {
BELLADONNA(5281, new String[][] {
{ "The belladonna seed has only just been planted." },
{ "The belladonna plant grows a little taller." },
{ "The belladonna plant grows taller and leafier." },
{ "The belladonna plant grows some flower buds." },
{ "The belladonna plant is ready to harvest." } }), CACTUS(
5280,
new String[][] {
{ "The cactus seed has only just been planted." },
{ "The cactus grows taller." },
{ "The cactus grows two small stumps." },
{ "The cactus grows its stumps longer." },
{ "The cactus grows larger." },
{ "The cactus curves its arms upwards and grows another stump." },
{ "The cactus grows all three of its arms upwards." },
{ "The cactus is ready to be harvested." } }), BITTERCAP(
5282, new String[][] {
{ "The mushroom spore has only just been planted." },
{ "The mushrooms grow a little taller." },
{ "The mushrooms grow a little taller." },
{ "The mushrooms grow a little larger." },
{ "The mushrooms grow a little larger." },
{ "The mushrooms tops grow a little wider." },
{ "The mushrooms are ready to harvest." } });
private int seedId;
private String[][] messages;
private static Map<Integer, InspectData> seeds = new HashMap<Integer, InspectData>();
static {
for (InspectData data : InspectData.values()) {
seeds.put(data.seedId, data);
}
}
InspectData(int seedId, String[][] messages) {
this.seedId = seedId;
this.messages = messages;
}
public static InspectData forId(int seedId) {
return seeds.get(seedId);
}
public int getSeedId() {
return seedId;
}
public String[][] getMessages() {
return messages;
}
}
/* update all the patch states */
public void updateSpecialPlants() {
// draynor manor - none - al karid - canifis
int[] configValues = new int[specialPlantStages.length];
int configValue;
for (int i = 0; i < specialPlantStages.length; i++) {
configValues[i] = getConfigValue(specialPlantStages[i],
specialPlantSeeds[i], specialPlantState[i], i);
}
configValue = (configValues[0] << 16) + (configValues[1] << 8 << 16)
+ configValues[2] + (configValues[3] << 8);
player.getPacketSender().sendConfig(MAIN_SPECIAL_PLANT_CONFIG, configValue);
}
/* getting the different config values */
public int getConfigValue(int specialStage, int seedId, int plantState,
int index) {
SpecialPlantData specialPlantData = SpecialPlantData.forId(seedId);
switch (specialStage) {
case 0:// weed
return 0x00;
case 1:// weed cleared
return 0x01;
case 2:
return 0x02;
case 3:
return 0x03;
}
if (specialPlantData == null) {
return -1;
}
if (specialStage > specialPlantData.getEndingState()
- specialPlantData.getStartingState() - 1) {
hasFullyGrown[index] = true;
}
if (getPlantState(plantState, specialPlantData, specialStage) == 3)
return specialPlantData.getCheckHealthState();
return getPlantState(plantState, specialPlantData, specialStage);
}
/* getting the plant states */
public int getPlantState(int plantState, SpecialPlantData specialPlantData,
int specialStage) {
int value = specialPlantData.getStartingState() + specialStage - 4;
switch (plantState) {
case 0:
return value;
case 1:
return value + specialPlantData.getDiseaseDiffValue();
case 2:
return value + specialPlantData.getDeathDiffValue();
case 3:
return specialPlantData.getCheckHealthState();
}
return -1;
}
/* calculating the disease chance and making the plant grow */
public void doCalculations() {
for (int i = 0; i < specialPlantSeeds.length; i++) {
if (specialPlantStages[i] > 0
&& specialPlantStages[i] <= 3
&& GameEngine.getMinutesCounter() - specialPlantTimer[i] >= 5) {
specialPlantStages[i]--;
specialPlantTimer[i] = GameEngine.getMinutesCounter();
updateSpecialPlants();
continue;
}
SpecialPlantData specialPlantData = SpecialPlantData
.forId(specialPlantSeeds[i]);
if (specialPlantData == null) {
continue;
}
long difference = GameEngine.getMinutesCounter()
- specialPlantTimer[i];
long growth = specialPlantData.getGrowthTime();
int nbStates = specialPlantData.getEndingState()
- specialPlantData.getStartingState();
int state = (int) (difference * nbStates / growth);
if (specialPlantTimer[i] == 0 || specialPlantState[i] == 2
|| specialPlantState[i] == 3 || (state > nbStates)) {
continue;
}
if (4 + state != specialPlantStages[i]
&& specialPlantStages[i] <= specialPlantData
.getEndingState()
- specialPlantData.getStartingState()
+ (specialPlantData == SpecialPlantData.BELLADONNA ? 5
: -2)) {
if (specialPlantStages[i] == specialPlantData.getEndingState()
- specialPlantData.getStartingState() - 2
&& specialPlantData.getCheckHealthState() != -1) {
specialPlantStages[i] = specialPlantData.getEndingState()
- specialPlantData.getStartingState() + 4;
specialPlantState[i] = 3;
updateSpecialPlants();
return;
}
specialPlantStages[i] = 4 + state;
doStateCalculation(i);
updateSpecialPlants();
}
}
}
public void modifyStage(int i) {
SpecialPlantData specialPlantData = SpecialPlantData
.forId(specialPlantSeeds[i]);
if (specialPlantData == null)
return;
long difference = GameEngine.getMinutesCounter() - specialPlantTimer[i];
long growth = specialPlantData.getGrowthTime();
int nbStates = specialPlantData.getEndingState()
- specialPlantData.getStartingState();
int state = (int) (difference * nbStates / growth);
specialPlantStages[i] = 4 + state;
updateSpecialPlants();
}
/* calculations about the diseasing chance */
public void doStateCalculation(int index) {
if (specialPlantState[index] == 2) {
return;
}
// if the patch is diseased, it dies, if its watched by a farmer, it
// goes back to normal
if (specialPlantState[index] == 1) {
specialPlantState[index] = 2;
}
if (specialPlantState[index] == 5 && specialPlantStages[index] != 2) {
specialPlantState[index] = 0;
}
if (specialPlantState[index] == 0 && specialPlantStages[index] >= 5
&& !hasFullyGrown[index]) {
SpecialPlantData specialPlantData = SpecialPlantData
.forId(specialPlantSeeds[index]);
if (specialPlantData == null) {
return;
}
double chance = diseaseChance[index]
* specialPlantData.getDiseaseChance();
int maxChance = (int) chance * 100;
if (Misc.random(100) <= maxChance) {
specialPlantState[index] = 1;
}
}
}
/* clearing the patch with a rake of a spade */
public boolean clearPatch(int objectX, int objectY, int itemId) {
final SpecialPlantFieldsData hopsFieldsData = SpecialPlantFieldsData
.forIdPosition(objectX, objectY);
int finalAnimation;
int finalDelay;
if (hopsFieldsData == null
|| (itemId != FarmingConstants.RAKE && itemId != FarmingConstants.SPADE)) {
return false;
}
if (!SkillConstants.getEnabled(SkillConstants.FARMING.ordinal())) {
player.getPacketSender().sendMessage("This skill is currently disabled.");
return true;
}
if (specialPlantStages[hopsFieldsData.getSpecialPlantsIndex()] == 3) {
return true;
}
if (specialPlantStages[hopsFieldsData.getSpecialPlantsIndex()] <= 3) {
if (!player.getItemAssistant().playerHasItem(FarmingConstants.RAKE)) {
player.getDialogueHandler().sendStatement(
"You need a rake to clear this path.");
return true;
} else {
finalAnimation = FarmingConstants.RAKING_ANIM;
finalDelay = 5;
}
} else {
if (!player.getItemAssistant().playerHasItem(FarmingConstants.SPADE)) {
player.getDialogueHandler().sendStatement(
"You need a spade to clear this path.");
return true;
} else {
finalAnimation = FarmingConstants.SPADE_ANIM;
finalDelay = 3;
}
}
final int animation = finalAnimation;
player.stopPlayer(true);
player.startAnimation(animation);
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
player.startAnimation(animation);
if (specialPlantStages[hopsFieldsData.getSpecialPlantsIndex()] <= 2) {
specialPlantStages[hopsFieldsData.getSpecialPlantsIndex()]++;
player.getItemAssistant().addItem(6055, 1);
} else {
specialPlantStages[hopsFieldsData.getSpecialPlantsIndex()] = 3;
container.stop();
}
player.getPlayerAssistant().addSkillXP(CLEARING_EXPERIENCE, SkillConstants.FARMING.ordinal());
specialPlantTimer[hopsFieldsData.getSpecialPlantsIndex()] = GameEngine
.getMinutesCounter();
updateSpecialPlants();
if (specialPlantStages[hopsFieldsData.getSpecialPlantsIndex()] == 3) {
container.stop();
return;
}
}
@Override
public void stop() {
resetSpecialPlants(hopsFieldsData.getSpecialPlantsIndex());
player.getPacketSender().sendMessage("You clear the patch.");
player.stopPlayer(false);
player.getPlayerAssistant().resetAnimation();
}
}, finalDelay);
return true;
}
/* planting the seeds */
public boolean plantSeeds(int objectX, int objectY, final int seedId) {
final SpecialPlantFieldsData specialPlantFieldsData = SpecialPlantFieldsData
.forIdPosition(objectX, objectY);
final SpecialPlantData specialPlantData = SpecialPlantData
.forId(seedId);
if (specialPlantFieldsData == null || specialPlantData == null
|| specialPlantFieldsData.getSeedId() != seedId) {
return false;
}
if (!SkillConstants.getEnabled(SkillConstants.FARMING.ordinal())) {
player.getPacketSender().sendMessage("This skill is currently disabled.");
return true;
}
if (specialPlantStages[specialPlantFieldsData.getSpecialPlantsIndex()] != 3) {
player.getPacketSender().sendMessage("You can't plant a seed here.");
return false;
}
if (specialPlantData.getLevelRequired() > player.playerLevel[SkillConstants.FARMING.ordinal()]) {
player.getDialogueHandler().sendStatement("You need a farming level of "
+ specialPlantData.getLevelRequired()
+ " to plant this seed.");
return true;
}
if (!player.getItemAssistant().playerHasItem(FarmingConstants.SEED_DIBBER)) {
player.getDialogueHandler().sendStatement(
"You need a seed dibber to plant seed here.");
return true;
}
if (player.getItemAssistant().getItemAmount(specialPlantData.getSeedId()) < specialPlantData
.getSeedAmount()) {
player.getDialogueHandler().sendStatement( "You need atleast "
+ specialPlantData.getSeedAmount()
+ " seeds to plant here.");
return true;
}
player.startAnimation(FarmingConstants.SEED_DIBBING);
specialPlantStages[specialPlantFieldsData.getSpecialPlantsIndex()] = 4;
player.getItemAssistant().deleteItem(seedId, specialPlantData.getSeedAmount());
player.stopPlayer(true);
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
specialPlantState[specialPlantFieldsData
.getSpecialPlantsIndex()] = 0;
specialPlantSeeds[specialPlantFieldsData
.getSpecialPlantsIndex()] = seedId;
specialPlantTimer[specialPlantFieldsData
.getSpecialPlantsIndex()] = GameEngine
.getMinutesCounter();
player.getPlayerAssistant().addSkillXP(specialPlantData.getPlantingXp(), SkillConstants.FARMING.ordinal());
container.stop();
}
@Override
public void stop() {
updateSpecialPlants();
player.stopPlayer(false);
}
}, 3);
return true;
}
/* harvesting the plant resulted */
public boolean harvestOrCheckHealth(int objectX, int objectY) {
final SpecialPlantFieldsData specialPlantFieldsData = SpecialPlantFieldsData
.forIdPosition(objectX, objectY);
if (specialPlantFieldsData == null) {
return false;
}
final SpecialPlantData specialPlantData = SpecialPlantData
.forId(specialPlantSeeds[specialPlantFieldsData
.getSpecialPlantsIndex()]);
if (specialPlantData == null) {
return false;
}
if (!SkillConstants.getEnabled(SkillConstants.FARMING.ordinal())) {
player.getPacketSender().sendMessage("This skill is currently disabled.");
return true;
}
if (player.getItemAssistant().freeSlots() <= 0) {
player.getPacketSender().sendMessage("Not enough space in your inventory.");
return true;
}
player.stopPlayer(true);
player.startAnimation(832);
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
if (player.getItemAssistant().freeSlots() <= 0) {
container.stop();
return;
}
if (specialPlantState[specialPlantFieldsData
.getSpecialPlantsIndex()] == 3) {
player.getPacketSender()
.sendMessage(
"You examine the plant for signs of disease and find that it's in perfect health.");
player.getPlayerAssistant().addSkillXP(specialPlantData.getCheckHealthXp(), SkillConstants.FARMING.ordinal());
specialPlantState[specialPlantFieldsData
.getSpecialPlantsIndex()] = 0;
hasFullyGrown[specialPlantFieldsData
.getSpecialPlantsIndex()] = false;
specialPlantTimer[specialPlantFieldsData
.getSpecialPlantsIndex()] = GameEngine
.getMinutesCounter()
- specialPlantData.getGrowthTime();
modifyStage(specialPlantFieldsData.getSpecialPlantsIndex());
container.stop();
return;
}
player.getPacketSender().sendMessage(
"You harvest the crop, and pick some "
+ specialPlantData.getHarvestId() + ".");
player.getItemAssistant().addItem(specialPlantData.getHarvestId(), 1);
player.getPlayerAssistant().addSkillXP(specialPlantData.getHarvestXp(), SkillConstants.FARMING.ordinal());
switch (specialPlantData) {
case BELLADONNA:
resetSpecialPlants(specialPlantFieldsData
.getSpecialPlantsIndex());
specialPlantStages[specialPlantFieldsData
.getSpecialPlantsIndex()] = 3;
specialPlantTimer[specialPlantFieldsData
.getSpecialPlantsIndex()] = GameEngine
.getMinutesCounter();
break;
case CACTUS:
specialPlantStages[specialPlantFieldsData
.getSpecialPlantsIndex()]--;
break;
case BITTERCAP:
specialPlantStages[specialPlantFieldsData
.getSpecialPlantsIndex()]++;
if (specialPlantStages[specialPlantFieldsData
.getSpecialPlantsIndex()] == 16) {
resetSpecialPlants(specialPlantFieldsData
.getSpecialPlantsIndex());
specialPlantStages[specialPlantFieldsData
.getSpecialPlantsIndex()] = 3;
specialPlantTimer[specialPlantFieldsData
.getSpecialPlantsIndex()] = GameEngine
.getMinutesCounter();
}
break;
}
updateSpecialPlants();
container.stop();
}
@Override
public void stop() {
player.stopPlayer(false);
player.getPlayerAssistant().resetAnimation();
}
}, 2);
return true;
}
/* lowering the stage */
public void lowerStage(int index, int timer) {
hasFullyGrown[index] = false;
specialPlantTimer[index] -= timer;
}
/* putting compost onto the plant */
public boolean putCompost(int objectX, int objectY, final int itemId) {
if (itemId != 6032 && itemId != 6034) {
return false;
}
final SpecialPlantFieldsData specialPlantFieldsData = SpecialPlantFieldsData
.forIdPosition(objectX, objectY);
if (specialPlantFieldsData == null) {
return false;
}
if (!SkillConstants.getEnabled(SkillConstants.FARMING.ordinal())) {
player.getPacketSender().sendMessage("This skill is currently disabled.");
return true;
}
if (specialPlantStages[specialPlantFieldsData.getSpecialPlantsIndex()] != 3
|| specialPlantState[specialPlantFieldsData
.getSpecialPlantsIndex()] == 5) {
player.getPacketSender().sendMessage("This patch doesn't need compost.");
return true;
}
player.getItemAssistant().deleteItem(itemId, 1);
player.getItemAssistant().addItem(1925, 1);
player.getPacketSender().sendMessage(
"You pour some " + (itemId == 6034 ? "super" : "")
+ "compost on the patch.");
player.startAnimation(FarmingConstants.PUTTING_COMPOST);
player.getPlayerAssistant().addSkillXP(itemId == 6034 ? Compost.SUPER_COMPOST_EXP_USE
: Compost.COMPOST_EXP_USE, SkillConstants.FARMING.ordinal());
player.stopPlayer(true);
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
diseaseChance[specialPlantFieldsData.getSpecialPlantsIndex()] *= itemId == 6032 ? COMPOST_CHANCE
: SUPERCOMPOST_CHANCE;
specialPlantState[specialPlantFieldsData
.getSpecialPlantsIndex()] = 5;
container.stop();
}
@Override
public void stop() {
player.stopPlayer(false);
player.getPlayerAssistant().resetAnimation();
}
}, 7);
return true;
}
/* inspecting a plant */
public boolean inspect(int objectX, int objectY) {
final SpecialPlantFieldsData specialPlantFieldsData = SpecialPlantFieldsData
.forIdPosition(objectX, objectY);
if (specialPlantFieldsData == null) {
return false;
}
if (!SkillConstants.getEnabled(SkillConstants.FARMING.ordinal())) {
player.getPacketSender().sendMessage("This skill is currently disabled.");
return true;
}
final InspectData inspectData = InspectData
.forId(specialPlantSeeds[specialPlantFieldsData
.getSpecialPlantsIndex()]);
final SpecialPlantData specialPlantData = SpecialPlantData
.forId(specialPlantSeeds[specialPlantFieldsData
.getSpecialPlantsIndex()]);
if (specialPlantState[specialPlantFieldsData.getSpecialPlantsIndex()] == 1) {
player.getDialogueHandler().sendStatement("This plant is diseased. Use a plant cure on it to cure it, ",
"or clear the patch with a spade.");
return true;
} else if (specialPlantState[specialPlantFieldsData
.getSpecialPlantsIndex()] == 2) {
player.getDialogueHandler().sendStatement("This plant is dead. You did not cure it while it was diseased.",
"Clear the patch with a spade.");
return true;
} else if (specialPlantState[specialPlantFieldsData
.getSpecialPlantsIndex()] == 3) {
player.getDialogueHandler().sendStatement(
"This plant has fully grown. You can check it's health",
"to gain some farming experiences.");
return true;
}
if (specialPlantStages[specialPlantFieldsData.getSpecialPlantsIndex()] == 0) {
player.getDialogueHandler().sendStatement(
"This is one of the special patches. The soil has not been treated.",
"The patch needs weeding.");
} else if (specialPlantStages[specialPlantFieldsData
.getSpecialPlantsIndex()] == 3) {
player.getDialogueHandler().sendStatement(
"This is one of the special patches. The soil has not been treated.",
"The patch is empty and weeded.");
} else if (inspectData != null && specialPlantData != null) {
player.getPacketSender().sendMessage(
"You bend down and start to inspect the patch...");
player.startAnimation(1331);
player.stopPlayer(true);
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
if (specialPlantStages[specialPlantFieldsData
.getSpecialPlantsIndex()] - 4 < inspectData
.getMessages().length - 2) {
player.getDialogueHandler().sendStatement(
inspectData.getMessages()[specialPlantStages[specialPlantFieldsData
.getSpecialPlantsIndex()] - 4]);
} else if (specialPlantStages[specialPlantFieldsData
.getSpecialPlantsIndex()] < specialPlantData
.getEndingState()
- specialPlantData.getStartingState() + 2) {
player.getDialogueHandler().sendStatement(
inspectData.getMessages()[inspectData
.getMessages().length - 2]);
} else {
player.getDialogueHandler().sendStatement(
inspectData.getMessages()[inspectData
.getMessages().length - 1]);
}
container.stop();
}
@Override
public void stop() {
player.startAnimation(1332);
player.stopPlayer(false);
// player.reset();
}
}, 5);
}
return true;
}
/* opening the corresponding guide about the patch */
public boolean guide(int objectX, int objectY) {
final SpecialPlantFieldsData specialPlantFieldsData = SpecialPlantFieldsData
.forIdPosition(objectX, objectY);
if (specialPlantFieldsData == null) {
return false;
}
if (!SkillConstants.getEnabled(SkillConstants.FARMING.ordinal())) {
player.getPacketSender().sendMessage("This skill is currently disabled.");
return true;
}
player.getSkillInterfaces().farmingComplex(8);
player.getSkillInterfaces().selected = 20;
return true;
}
/* Curing the plant */
public boolean curePlant(int objectX, int objectY, int itemId) {
final SpecialPlantFieldsData specialPlantFieldsData = SpecialPlantFieldsData
.forIdPosition(objectX, objectY);
if (specialPlantFieldsData == null || itemId != 6036) {
return false;
}
final SpecialPlantData specialPlantData = SpecialPlantData
.forId(specialPlantSeeds[specialPlantFieldsData
.getSpecialPlantsIndex()]);
if (specialPlantData == null) {
return false;
}
if (!SkillConstants.getEnabled(SkillConstants.FARMING.ordinal())) {
player.getPacketSender().sendMessage("This skill is currently disabled.");
return true;
}
if (specialPlantState[specialPlantFieldsData.getSpecialPlantsIndex()] != 1) {
player.getPacketSender().sendMessage("This plant doesn't need to be cured.");
return true;
}
player.getItemAssistant().deleteItem(itemId, 1);
player.getItemAssistant().addItem(229, 1);
player.startAnimation(FarmingConstants.CURING_ANIM);
player.stopPlayer(true);
specialPlantState[specialPlantFieldsData.getSpecialPlantsIndex()] = 0;
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
player.getPacketSender().sendMessage(
"You cure the plant with a plant cure.");
container.stop();
}
@Override
public void stop() {
updateSpecialPlants();
player.stopPlayer(false);
player.getPlayerAssistant().resetAnimation();
}
}, 7);
return true;
}
private void resetSpecialPlants(int index) {
specialPlantSeeds[index] = 0;
specialPlantState[index] = 0;
diseaseChance[index] = 1;
hasFullyGrown[index] = false;
}
/* checking if the patch is raked */
public boolean checkIfRaked(int objectX, int objectY) {
final SpecialPlantFieldsData specialPlantFieldData = SpecialPlantFieldsData
.forIdPosition(objectX, objectY);
if (specialPlantFieldData == null)
return false;
if (specialPlantStages[specialPlantFieldData.getSpecialPlantsIndex()] == 3)
return true;
return false;
}
}
@@ -0,0 +1,377 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.rebotted.game.content.skills.farming;
/**
*
* @author ArrowzFtw
*/
import java.util.HashMap;
import java.util.Map;
import com.rebotted.game.dialogues.ChatEmotes;
import com.rebotted.game.items.Item;
import com.rebotted.game.items.ItemData;
import com.rebotted.game.players.Player;
/**
* Created by IntelliJ IDEA. User: vayken Date: 23/02/12 Time: 12:12 To change
* this template use File | Settings | File Templates.
*/
public class ToolLeprechaun {
private Player player;
public ToolLeprechaun(Player player) {
this.player = player;
}
public int[] tools = { 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1 };// new
// int[18];
/* setting up the store item array and the player item array */
public Item[] storeItems = { new Item(5341), new Item(5343), new Item(952),
new Item(5329), new Item(5331), new Item(5325) };
public Item[] storeItems2 = { new Item(1925), new Item(6032),
new Item(6034) };
public Item[] storeItemsClient = { new Item(5341), new Item(5343),
new Item(952), new Item(5329), new Item(5331), new Item(5325) };
public Item[] storeItems2Client = { new Item(1925), new Item(6032),
new Item(6034) };
/* setting up the main constant field */
public static final int[] NOTABLE_ITEMS = { 225, 239, 247, 249, 251, 253,
255, 257, 259, 261, 263, 265, 267, 269, 3000, 2481, 592, 1965,
1967, 6004, 5980, 5976, 1955, 1963, 2108, 5972, 2114, 754, 2126,
248, 1951, 240, 2367, 1942, 1957, 1965, 1982, 5986, 5504, 5982,
6006, 5994, 5996, 5931, 5998, 6000, 6002, 6016, 6055 };
public static final int LEPRECHAUN_INTERFACE = 15614;
public static final int LEPRECHAUN_INTERFACE_CONTAINER = 15682;//
public static final int LEPRECHAUN_INTERFACE_CONTAINER2 = 15683;//
public static final int PLAYER_INTERFACE = 15593;
public static final int PLAYER_INTERFACE_CONTAINER = 15594;//
public static final int PLAYER_INTERFACE_CONTAINER2 = 15595;//
public static final int TOOL_CONFIGS = 615;
/* this enum store every tool data for the interfaces loading */
public enum ToolStoreData {
RAKE(0, 5341, 1, 1, 15596, 15597, "Rake"), SEED_DIBBER(1, 5343, 2, 1,
15598, 15599, "Dibber"), SPADE(2, 952, 4, 1, 15600, 15601,
"Spade"), SECATEURS(3, 5329, 8, 1, 15602, 15603, "Secateurs"), MAGIC_SECATEURS(
4, 7409, 8, 1, 15602, 15603, "Secateurs"), WATERING_CAN_0(5,
5331, 16, 1, 15604, 15605, "Watering Can"), WATERING_CAN_1(6,
5333, 32, 1, 15604, 15605, "Watering Can"), WATERING_CAN_2(7,
5334, 48, 1, 15604, 15605, "Watering Can"), WATERING_CAN_3(8,
5335, 64, 1, 15604, 15605, "Watering Can"), WATERING_CAN_4(9,
5336, 80, 1, 15604, 15605, "Watering Can"), WATERING_CAN_5(10,
5337, 96, 1, 15604, 15605, "Watering Can"), WATERING_CAN_6(11,
5338, 112, 1, 15604, 15605, "Watering Can"), WATERING_CAN_7(12,
5339, 128, 1, 15604, 15605, "Watering Can"), WATERING_CAN_8(13,
5340, 144, 1, 15604, 15605, "Watering Can"), GARDENING_TROWEL(
14, 5325, 256, 1, 15606, 15607, "Trowel"), EMPTY_BUCKETS(15,
1925, 512, 31, 15608, 15609, "Buckets"), COMPOST(16, 6032,
16384, 255, 15610, 15611, "Compost"), SUPER_COMPOST(17, 6034,
4194304, 255, 15612, 15613, "Super Compost");
private int toolIndex;
private int toolId;
private int toolConfig;
private int toolMaxQuantity;
private int toolFrameId;
private int toolCountFrameId;
private String toolName;
private static Map<Integer, ToolStoreData> tools = new HashMap<Integer, ToolStoreData>();
private static Map<Integer, ToolStoreData> indexes = new HashMap<Integer, ToolStoreData>();
public static ToolStoreData forId(int toolId) {
return tools.get(toolId);
}
public static ToolStoreData forIndex(int index) {
return indexes.get(index);
}
static {
for (ToolStoreData data : ToolStoreData.values()) {
tools.put(data.toolId, data);
indexes.put(data.toolIndex, data);
}
}
ToolStoreData(int toolIndex, int toolId, int toolConfig,
int toolMaxQuantity, int toolFrameId, int toolCountFrameId,
String toolName) {
this.toolIndex = toolIndex;
this.toolId = toolId;
this.toolConfig = toolConfig;
this.toolMaxQuantity = toolMaxQuantity;
this.toolFrameId = toolFrameId;
this.toolCountFrameId = toolCountFrameId;
this.toolName = toolName;
}
public int getToolIndex() {
return toolIndex;
}
public int getToolId() {
return toolId;
}
public int getToolConfig() {
return toolConfig;
}
public int getToolMaxQuantity() {
return toolMaxQuantity;
}
public int getToolFrameId() {
return toolFrameId;
}
public int getToolCountFrameId() {
return toolCountFrameId;
}
public String getToolName() {
return toolName;
}
}
/* loading the interfaces */
public void loadInterfaces() {
player.getPacketSender().showInterface(LEPRECHAUN_INTERFACE);
player.getPacketSender().sendUpdateItems(LEPRECHAUN_INTERFACE_CONTAINER, storeItems);
player.getPacketSender().sendUpdateItems(LEPRECHAUN_INTERFACE_CONTAINER2,
storeItems2);
player.getPacketSender().setSidebarInterface(3, PLAYER_INTERFACE);
player.getPacketSender().sendUpdateItems(PLAYER_INTERFACE_CONTAINER,
storeItemsClient);
player.getPacketSender().sendUpdateItems(PLAYER_INTERFACE_CONTAINER2,
storeItems2Client);
updateStore();
}
/* handling watering can things */
public void handleAdditionalTools() {
int item;
int i = 5340;
while (!player.getItemAssistant().playerHasItem(i)
&& i >= 5330) {
i--;
}
item = i;
if (item == 5330) {
return;
}
storeItemsClient[4] = new Item(item);
if (player.getItemAssistant().playerHasItem(7409)) {
storeItemsClient[3] = new Item(7409);
} else {
storeItemsClient[3] = new Item(5329);
}
}
public void checkWateringCanQuantity() {
int counter = 0;
int counter2 = 0;
for (int i = 5; i <= 13; i++) {
ToolStoreData toolStoreData = ToolStoreData.forIndex(i);
if (player.getItemAssistant().playerHasItem(toolStoreData.getToolId())) {
counter2++;
}
if (tools[i] == 1) {
counter++;
}
}
if (counter == 0) {
storeItems[4] = new Item(5331);
}
if (counter2 == 0) {
storeItemsClient[4] = new Item(5331);
}
}
public boolean hasWateringCanInStore() {
int counter = 0;
for (int i = 5; i <= 13; i++) {
if (tools[i] == 1) {
counter++;
}
}
if (counter == 0) {
return false;
}
return true;
}
/* updating the store state and player state */
public void updateStore() {
int configValue = 0;
for (int i = 0; i < tools.length; i++) {
ToolStoreData toolStoreData = ToolStoreData.forIndex(i);
if (toolStoreData == null) {
return;
}
configValue += toolStoreData.getToolConfig() * tools[i];
updateClientInterface(toolStoreData, player.getItemAssistant()
.getItemAmount(toolStoreData.getToolId()), i);
if (toolStoreData.getToolId() != 5332
&& toolStoreData.getToolId() >= 5331
&& toolStoreData.getToolId() <= 5340 && tools[i] == 1) {
storeItems[4] = new Item(toolStoreData.getToolId());
}
if (toolStoreData.getToolId() == 7409 && tools[i] == 1) {
storeItems[3] = new Item(7409);
}
}
handleAdditionalTools();
checkWateringCanQuantity();
player.getPacketSender().sendConfig(TOOL_CONFIGS, configValue);
player.getPacketSender().sendUpdateItems(LEPRECHAUN_INTERFACE_CONTAINER,
storeItems);
player.getPacketSender().sendUpdateItems(PLAYER_INTERFACE_CONTAINER,
storeItemsClient);
}
public void updateClientInterface(ToolStoreData toolStoreData, int count,
int index) {
player.tempBoolean = false;
if (count > 0) {
if (index >= 5 && index <= 13) {
player.tempBoolean = true;
}
player.getPacketSender().sendFrame126("@gre@" + toolStoreData.getToolName(),
toolStoreData.getToolFrameId());
player.getPacketSender().sendFrame126("@gre@" + count,
toolStoreData.getToolCountFrameId());
} else {
// watering can doses
if (index >= 5 && index <= 13 && player.tempBoolean) {
return;
}
// secateurs
if ((index == 3 || index == 4)
&& (player.getItemAssistant().playerHasItem(7409) || player
.getItemAssistant().playerHasItem(5329))) {
return;
}
player.getPacketSender().sendFrame126("" + toolStoreData.getToolName(),
toolStoreData.getToolFrameId());
player.getPacketSender().sendFrame126("" + count,
toolStoreData.getToolCountFrameId());
}
}
/* store any item with id and amount provided */
public void storeItems(int itemId, int amount) {
ToolStoreData toolStoreData = ToolStoreData.forId(itemId);
if (toolStoreData == null) {
return;
}
int storeAmount = tools[toolStoreData.getToolIndex()];
int finalAmount = amount;
if (!player.getItemAssistant().playerHasItem(itemId))
return;
if (toolStoreData.getToolMaxQuantity() == storeAmount
|| (itemId == 7409 || itemId == 5329)
&& (tools[3] == 1 || tools[4] == 1) || hasWateringCanInStore()
&& toolStoreData.getToolId() != 5332 && itemId >= 5340
&& itemId <= 5331) {
player.getPacketSender().sendMessage("You can't store any more of those.");
return;
}
if (player.getItemAssistant().getItemCount(itemId) <= 0) {
player.getPacketSender().sendMessage("You aren't carrying any of those.");
return;
}
if (player.getItemAssistant().getItemCount(itemId) < amount) {
finalAmount = player.getItemAssistant().getItemCount(itemId);
}
player.getItemAssistant().deleteItem(itemId, finalAmount);
tools[toolStoreData.getToolIndex()] += finalAmount;
updateStore();
}
/* withdraw any item with item id and amount provided */
public void withdrawItems(int itemId, int amount) {
ToolStoreData toolStoreData = ToolStoreData.forId(itemId);
if (toolStoreData == null) {
return;
}
if (player.getItemAssistant().freeSlots() <= 0) {
player.getPacketSender().sendMessage("Not enough space in your inventory.");
return;
}
if (tools[toolStoreData.getToolIndex()] <= 0) {
player.getPacketSender().sendMessage(
"You haven't got any of those stored in here.");
return;
}
int finalAmount;
if (amount > tools[toolStoreData.getToolIndex()]) {
finalAmount = tools[toolStoreData.getToolIndex()];
} else {
finalAmount = amount;
}
if (finalAmount > player.getItemAssistant().freeSlots() ) {
finalAmount = player.getItemAssistant().freeSlots() ;
}
tools[toolStoreData.getToolIndex()] -= finalAmount;
player.getItemAssistant().addItem(itemId, finalAmount);
updateStore();
}
/* note any item with the item id provided */
public boolean noteItem(int itemId) {
if (ItemData.itemIsNote[itemId]) {
player.getDialogueHandler().sendNpcChat(3021, ChatEmotes.DEFAULT, "That is a banknote!");
return true;
}
for (int item : NOTABLE_ITEMS) {
if (itemId == item) {
int count = player.getItemAssistant().getItemAmount(itemId);
player.getItemAssistant().deleteItem(itemId, count);
player.getItemAssistant().addItem(itemId + 1, count);
player.getDialogueHandler().sendStatement(
"The tool leprechaun notes those items for you.");
return true;
}
}
player.getDialogueHandler().sendNpcChat(3021, ChatEmotes.DEFAULT, "Nay, I've got no banknotes to exchange for that item.");
return true;
}
}
@@ -0,0 +1,983 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.rebotted.game.content.skills.farming;
/**
*
* @author ArrowzFtw
*/
import java.awt.Point;
import java.util.HashMap;
import java.util.Map;
import com.rebotted.GameEngine;
import com.rebotted.event.CycleEvent;
import com.rebotted.event.CycleEventContainer;
import com.rebotted.event.CycleEventHandler;
import com.rebotted.game.content.skills.SkillConstants;
import com.rebotted.game.content.skills.SkillHandler;
import com.rebotted.game.content.skills.farming.ChopTree.Tree;
import com.rebotted.game.items.ItemAssistant;
import com.rebotted.game.players.Player;
import com.rebotted.util.Misc;
/**
* Created by IntelliJ IDEA. User: vayken Date: 24/02/12 Time: 20:34 To change
* this template use File | Settings | File Templates.
*/
public class WoodTrees {
private Player player;
private static final double COMPOST_CHANCE = 0.9;
private static final double SUPERCOMPOST_CHANCE = 0.7;
private static final double CLEARING_EXPERIENCE = 4;
public WoodTrees(Player player) {
this.player = player;
}
// Farming data
public int[] treeStages = new int[4];
public int[] treeSaplings = new int[4];
public int[] treeHarvest = new int[4];
public int[] treeState = new int[4];
public long[] treeTimer = new long[4];
public double[] diseaseChance = { 1, 1, 1, 1 };
public boolean[] hasFullyGrown = { false, false, false, false };
public boolean[] treeWatched = { false, false, false, false };
/* set of the constants for the patch */
// states - 2 bits plant - 6 bits
public static final int GROWING = 0x00;
public static final int DISEASED = 0x01;
public static final int DEAD = 0x02;
public static final int MAIN_TREE_CONFIG = 502;
/* This is the enum holding the saplings info */
public enum TreeData {
OAK(5370, 6043, 15, new int[] { 5968, 1 }, 160, 0.20, 14, 467.3, 0x08,
0x0c, 0x0d, 0x0e, 1281), WILLOW(5371, 6045, 30, new int[] {
5386, 1 }, 240, 0.20, 25, 1456.3, 0x0f, 0x15, 0x16, 0x17, 1308), MAPLE(
5372, 6047, 45, new int[] { 5396, 1 }, 320, 0.25, 45, 3403.4,
0x18, 0x20, 0x21, 0x22, 1307), YEW(5373, 6049, 60, new int[] {
6016, 10 }, 400, 0.25, 81, 7069.9, 0x23, 0x2d, 0x2e, 0x2f, 1309), MAGIC(
5374, 6051, 75, new int[] { 5976, 25 }, 480, 0.25, 145.5,
13768.3, 0x30, 0x3c, 0x3d, 0x3e, 1292);
private int saplingId;
private int rootsId;
private int levelRequired;
private int[] paymentToWatch;
private int growthTime;
private double diseaseChance;
private double plantingXp;
private double checkHealthXp;
private int startingState;
private int endingState;
private int chopDownState;
private int stumpState;
private int treeObjectAssociated;
private static Map<Integer, TreeData> saplings = new HashMap<Integer, TreeData>();
static {
for (TreeData data : TreeData.values()) {
saplings.put(data.saplingId, data);
}
}
TreeData(int saplingId, int rootsId, int levelRequired,
int[] paymentToWatch, int growthTime, double diseaseChance,
double plantingXp, double checkHealthXp, int startingState,
int endingState, int chopDownState, int stumpState,
int treeObjectAssociated) {
this.saplingId = saplingId;
this.rootsId = rootsId;
this.levelRequired = levelRequired;
this.paymentToWatch = paymentToWatch;
this.growthTime = growthTime;
this.diseaseChance = diseaseChance;
this.plantingXp = plantingXp;
this.checkHealthXp = checkHealthXp;
this.startingState = startingState;
this.endingState = endingState;
this.chopDownState = chopDownState;
this.stumpState = stumpState;
this.treeObjectAssociated = treeObjectAssociated;
}
public static TreeData forId(int saplingId) {
return saplings.get(saplingId);
}
public int getSaplingId() {
return saplingId;
}
public int getRootsId() {
return rootsId;
}
public int getLevelRequired() {
return levelRequired;
}
public int[] getPaymentToWatch() {
return paymentToWatch;
}
public int getGrowthTime() {
return growthTime;
}
public double getDiseaseChance() {
return diseaseChance;
}
public double getPlantingXp() {
return plantingXp;
}
public double getCheckHealthXp() {
return checkHealthXp;
}
public int getStartingState() {
return startingState;
}
public int getEndingState() {
return endingState;
}
public int getChopDownState() {
return chopDownState;
}
public int getStumpState() {
return stumpState;
}
public int getTreeObjectAssociated() {
return treeObjectAssociated;
}
}
/* This is the enum data about the different patches */
public enum TreeFieldsData {
VARROCK(0,
new Point[] { new Point(3228, 3458), new Point(3230, 3460) },
2341), LUMBRIDGE(1, new Point[] { new Point(3192, 3230),
new Point(3194, 3232) }, 2342), TAVERLEY(2, new Point[] {
new Point(2935, 3437), new Point(2937, 3439) }, 2339), FALADOR(
3,
new Point[] { new Point(3003, 3372), new Point(3005, 3374) },
2340);
private int treeIndex;
private Point[] treePosition;
private int npcId;
private static Map<Integer, TreeFieldsData> npcsProtecting = new HashMap<Integer, TreeFieldsData>();
static {
for (TreeFieldsData data : TreeFieldsData.values()) {
npcsProtecting.put(data.npcId, data);
}
}
public static TreeFieldsData forId(int npcId) {
return npcsProtecting.get(npcId);
}
TreeFieldsData(int treeIndex, Point[] treePosition, int npcId) {
this.treeIndex = treeIndex;
this.treePosition = treePosition;
this.npcId = npcId;
}
public static TreeFieldsData forIdPosition(int x, int y) {
for (TreeFieldsData treeFieldsData : TreeFieldsData.values()) {
if (FarmingConstants.inRangeArea(
treeFieldsData.getTreePosition()[0],
treeFieldsData.getTreePosition()[1], x, y)) {
return treeFieldsData;
}
}
return null;
}
public int getTreeIndex() {
return treeIndex;
}
public Point[] getTreePosition() {
return treePosition;
}
public int getNpcId() {
return npcId;
}
}
/* This is the enum that hold the different data for inspecting the plant */
public enum InspectData {
OAK(5370, new String[][] {
{ "The acorn sapling has only just been planted." },
{ "The acorn sapling grows larger." },
{ "The oak tree produces a small canopy." },
{ "The oak tree grows larger." },
{ "The oak tree is ready to harvest." } }), WILLOW(5371,
new String[][] {
{ "The willow sapling has only just been planted." },
{ "The willow sapling grows a few small branches." },
{ "The willow tree develops a small canopy." },
{ "The willow tree trunk becomes dark brown,",
"and the canopy grows." },
{ "The trunk thickens, and the canopy grows",
"yet larger." },
{ "The willow tree is fully grown." } }), MAPLE(5372,
new String[][] {
{ "The maple sapling has only just been planted." },
{ "The mapling sapling grows a few small branches." },
{ "The maple tree develops a small canopy." },
{ "The maple tree trunk straightens and the canopy",
"grows larger." },
{ "The maple tree canopy grows." },
{ "The maple tree grows." },
{ "The maple tree is ready to be harvested." } }), YEW(
5373, new String[][] {
{ "The yew sapling has only just been planted." },
{ "The yew sapling grows a few small branches." },
{ "The yew tree develops several small canopies." },
{ "The yew tree trunk texture becomes smoother and",
"the canopies grow larger." },
{ "The yew tree grows larger." },
{ "The yew tree canopies become more angular and",
"cone shaped due to texture placement." },
{ "The yew tree gains a rougher tree bark texture and",
"the base becomes darker." },
{ "The yew tree base becomes light again, and the",
"trunk loses its texture." },
{ "The yew tree bark gains a stripy texture." },
{ "The yew tree is ready to be harvested." } }), MAGIC(
5374,
new String[][] {
{ "The magic sapling has only just been planted." },
{ "The magic sapling grows a little bit." },
{ "The magic sapling grows a little bit more." },
{ "The magic sapling grows a few small branches." },
{ "The magic tree grows a small canopy." },
{ "The magic tree canopy becomes larger, and",
"starts producing sparkles." },
{ "The magic tree grows and the base becomes lighter." },
{ "The magic tree grows and the base becomes darker." },
{ "The magic tree's bark is more prominent and the",
"canopy gains more sparkles." },
{ "The magic tree grows taller." },
{ "The magic tree grows taller." },
{ "The magic tree is ready to be harvested." } });
private int saplingId;
private String[][] messages;
private static Map<Integer, InspectData> saplings = new HashMap<Integer, InspectData>();
static {
for (InspectData data : InspectData.values()) {
saplings.put(data.saplingId, data);
}
}
InspectData(int saplingId, String[][] messages) {
this.saplingId = saplingId;
this.messages = messages;
}
public static InspectData forId(int saplingId) {
return saplings.get(saplingId);
}
public int getSaplingId() {
return saplingId;
}
public String[][] getMessages() {
return messages;
}
}
/* update all the patch states */
public void updateTreeStates() {
// varrock - lumbridge - taverley - falador
int[] configValues = new int[treeStages.length];
int configValue;
for (int i = 0; i < treeStages.length; i++) {
configValues[i] = getConfigValue(treeStages[i], treeSaplings[i],
treeState[i], i);
}
configValue = (configValues[0] << 16) + (configValues[1] << 8 << 16)
+ configValues[2] + (configValues[3] << 8);
player.getPacketSender().sendConfig(MAIN_TREE_CONFIG, configValue);
}
/* getting the different config values */
public int getConfigValue(int treeStage, int saplingId, int plantState,
int index) {
TreeData treeData = TreeData.forId(saplingId);
switch (treeStage) {
case 0:// weed
return (GROWING << 6) + 0x00;
case 1:// weed cleared
return (GROWING << 6) + 0x01;
case 2:
return (GROWING << 6) + 0x02;
case 3:
return (GROWING << 6) + 0x03;
}
if (treeData == null) {
return -1;
}
if (treeData.getEndingState() == treeData.getStartingState()
+ treeStage - 1) {
hasFullyGrown[index] = true;
}
if (plantState == 6)
return treeData.getChopDownState();
if (plantState == 7)
return treeData.getStumpState();
return (getPlantState(plantState) << 6) + treeData.getStartingState()
+ treeStage - 4;
}
/* getting the plant states */
public int getPlantState(int plantState) {
switch (plantState) {
case 0:
return GROWING;
case 1:
return DISEASED;
case 2:
return DEAD;
}
return -1;
}
/* calculating the disease chance and making the plant grow */
public void doCalculations() {
for (int i = 0; i < treeSaplings.length; i++) {
if (treeStages[i] > 0 && treeStages[i] <= 3
&& GameEngine.getMinutesCounter() - treeTimer[i] >= 5) {
treeStages[i]--;
treeTimer[i] = GameEngine.getMinutesCounter();
updateTreeStates();
continue;
}
TreeData treeData = TreeData.forId(treeSaplings[i]);
if (treeData == null) {
continue;
}
long difference = GameEngine.getMinutesCounter() - treeTimer[i];
long growth = treeData.getGrowthTime();
int nbStates = treeData.getEndingState()
- treeData.getStartingState();
int state = (int) (difference * nbStates / growth);
if (treeTimer[i] == 0 || treeState[i] == 2 || state > nbStates) {
continue;
}
if (4 + state != treeStages[i]) {
treeStages[i] = 4 + state;
if (treeStages[i] <= 4 + state)
for (int j = treeStages[i]; j <= 4 + state; j++)
doStateCalculation(i);
updateTreeStates();
}
}
}
public void modifyStage(int i) {
TreeData bushesData = TreeData.forId(treeSaplings[i]);
if (bushesData == null)
return;
long difference = GameEngine.getMinutesCounter() - treeTimer[i];
long growth = bushesData.getGrowthTime();
int nbStates = bushesData.getEndingState()
- bushesData.getStartingState();
int state = (int) (difference * nbStates / growth);
treeStages[i] = 4 + state;
updateTreeStates();
}
/* calculations about the diseasing chance */
public void doStateCalculation(int index) {
if (treeState[index] == 2) {
return;
}
// if the patch is diseased, it dies, if its watched by a farmer, it
// goes back to normal
if (treeState[index] == 1) {
if (treeWatched[index]) {
treeState[index] = 0;
TreeData treeData = TreeData.forId(treeSaplings[index]);
if (treeData == null)
return;
int difference = treeData.getEndingState()
- treeData.getStartingState();
int growth = treeData.getGrowthTime();
treeTimer[index] += (growth / difference);
modifyStage(index);
} else {
treeState[index] = 2;
}
}
if (treeState[index] == 5 && treeStages[index] != 3) {
treeState[index] = 0;
}
if (treeState[index] == 0 && treeStages[index] >= 5
&& !hasFullyGrown[index]) {
TreeData treeData = TreeData.forId(treeSaplings[index]);
if (treeData == null) {
return;
}
double chance = diseaseChance[index] * treeData.getDiseaseChance();
int maxChance = (int) chance * 100;
if (Misc.random(100) <= maxChance) {
treeState[index] = 1;
}
}
}
/* clearing the patch with a rake of a spade */
public boolean clearPatch(int objectX, int objectY, int itemId) {
final TreeFieldsData hopsFieldsData = TreeFieldsData.forIdPosition(
objectX, objectY);
int finalAnimation;
int finalDelay;
if (hopsFieldsData == null
|| (itemId != FarmingConstants.RAKE && itemId != FarmingConstants.SPADE)) {
return false;
}
if (treeStages[hopsFieldsData.getTreeIndex()] == 3) {
return true;
}
if (treeStages[hopsFieldsData.getTreeIndex()] <= 3) {
if (!player.getItemAssistant().playerHasItem(FarmingConstants.RAKE)) {
player.getDialogueHandler().sendStatement(
"You need a rake to clear this path.");
return true;
} else {
finalAnimation = FarmingConstants.RAKING_ANIM;
finalDelay = 5;
}
} else {
if (!player.getItemAssistant().playerHasItem(FarmingConstants.SPADE)) {
player.getDialogueHandler().sendStatement(
"You need a spade to clear this path.");
return true;
} else {
finalAnimation = FarmingConstants.SPADE_ANIM;
finalDelay = 3;
}
}
final int animation = finalAnimation;
player.stopPlayer(true);
player.startAnimation(animation);
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
player.startAnimation(animation);
if (treeStages[hopsFieldsData.getTreeIndex()] <= 2) {
treeStages[hopsFieldsData.getTreeIndex()]++;
player.getItemAssistant().addItem(6055, 1);
} else {
treeStages[hopsFieldsData.getTreeIndex()] = 3;
container.stop();
}
player.getPlayerAssistant().addSkillXP(CLEARING_EXPERIENCE, SkillConstants.FARMING.ordinal());
treeTimer[hopsFieldsData.getTreeIndex()] = GameEngine
.getMinutesCounter();
updateTreeStates();
if (treeStages[hopsFieldsData.getTreeIndex()] == 3) {
container.stop();
return;
}
}
@Override
public void stop() {
resetTrees(hopsFieldsData.getTreeIndex());
player.getPacketSender().sendMessage("You clear the patch.");
player.stopPlayer(false);
player.getPlayerAssistant().resetAnimation();
}
}, finalDelay);
return true;
}
/* planting the saplings */
public boolean plantSapling(int objectX, int objectY, final int saplingId) {
final TreeFieldsData treeFieldsData = TreeFieldsData.forIdPosition(
objectX, objectY);
final TreeData treeData = TreeData.forId(saplingId);
if (treeFieldsData == null || treeData == null) {
return false;
}
if (treeStages[treeFieldsData.getTreeIndex()] != 3) {
player.getPacketSender().sendMessage("You can't plant a sapling here.");
return true;
}
if (treeData.getLevelRequired() > player.playerLevel[SkillConstants.FARMING.ordinal()]) {
player.getDialogueHandler().sendStatement("You need a farming level of "
+ treeData.getLevelRequired()
+ " to plant this sapling.");
return true;
}
if (!player.getItemAssistant().playerHasItem(FarmingConstants.TROWEL)) {
player.getDialogueHandler().sendStatement(
"You need a trowel to plant the sapling here.");
return true;
}
player.startAnimation(
FarmingConstants.PLANTING_POT_ANIM);
treeStages[treeFieldsData.getTreeIndex()] = 4;
player.getItemAssistant().deleteItem(saplingId, 1);
player.stopPlayer(true);
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
treeState[treeFieldsData.getTreeIndex()] = 0;
treeSaplings[treeFieldsData.getTreeIndex()] = saplingId;
treeTimer[treeFieldsData.getTreeIndex()] = GameEngine
.getMinutesCounter();
player.getPlayerAssistant().addSkillXP(treeData.getPlantingXp(), SkillConstants.FARMING.ordinal());
container.stop();
}
@Override
public void stop() {
updateTreeStates();
player.stopPlayer(false);
}
}, 3);
return true;
}
@SuppressWarnings("unused")
private void displayAll() {
for (int i = 0; i < treeStages.length; i++) {
System.out.println("index : " + i);
System.out.println("state : " + treeState[i]);
System.out.println("harvest : " + treeHarvest[i]);
System.out.println("saplings : " + treeSaplings[i]);
System.out.println("level : " + treeStages[i]);
System.out.println("timer : " + treeTimer[i]);
System.out.println("disease chance : " + diseaseChance[i]);
System.out
.println("-----------------------------------------------------------------");
}
}
/* harvesting the plant resulted */
public boolean checkHealth(int objectX, int objectY) {
final TreeFieldsData treeFieldsData = TreeFieldsData.forIdPosition(
objectX, objectY);
if (treeFieldsData == null) {
return false;
}
final TreeData treeData = TreeData.forId(treeSaplings[treeFieldsData
.getTreeIndex()]);
if (treeData == null) {
return false;
}
if (treeState[treeFieldsData.getTreeIndex()] != 0)
return false;
player.startAnimation(832);
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
player.getPacketSender()
.sendMessage(
"You examine the tree for signs of disease and find that it is in perfect health");
player.getPlayerAssistant().addSkillXP(treeData.getCheckHealthXp(), SkillConstants.FARMING.ordinal());
treeState[treeFieldsData.getTreeIndex()] = 6;
container.stop();
}
@Override
public void stop() {
updateTreeStates();
}
}, 2);
return true;
}
public void respawnStumpTimer(final int index) {
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
if (treeState[index] == 7)
treeState[index] = 6;
container.stop();
}
@Override
public void stop() {
}
}, 500);
}
/* putting compost onto the plant */
public boolean putCompost(int objectX, int objectY, final int itemId) {
if (itemId != 6032 && itemId != 6034) {
return false;
}
final TreeFieldsData treeFieldsData = TreeFieldsData.forIdPosition(
objectX, objectY);
if (treeFieldsData == null) {
return false;
}
if (treeStages[treeFieldsData.getTreeIndex()] != 3
|| treeState[treeFieldsData.getTreeIndex()] == 5) {
player.getPacketSender().sendMessage("This patch doesn't need compost.");
return true;
}
player.getItemAssistant().deleteItem(itemId, 1);
player.getItemAssistant().addItem(1925, 1);
player.getPacketSender().sendMessage(
"You pour some " + (itemId == 6034 ? "super" : "")
+ "compost on the patch.");
player.startAnimation(FarmingConstants.PUTTING_COMPOST);
player.getPlayerAssistant().addSkillXP(itemId == 6034 ? Compost.SUPER_COMPOST_EXP_USE
: Compost.COMPOST_EXP_USE, SkillConstants.FARMING.ordinal());
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
diseaseChance[treeFieldsData.getTreeIndex()] *= itemId == 6032 ? COMPOST_CHANCE
: SUPERCOMPOST_CHANCE;
treeState[treeFieldsData.getTreeIndex()] = 5;
container.stop();
}
@Override
public void stop() {
player.stopPlayer(false);
player.getPlayerAssistant().resetAnimation();
}
}, 7);
return true;
}
/* inspecting a plant */
public boolean inspect(int objectX, int objectY) {
final TreeFieldsData treeFieldsData = TreeFieldsData.forIdPosition(
objectX, objectY);
if (treeFieldsData == null) {
return false;
}
final InspectData inspectData = InspectData
.forId(treeSaplings[treeFieldsData.getTreeIndex()]);
final TreeData treeData = TreeData.forId(treeSaplings[treeFieldsData
.getTreeIndex()]);
if (treeState[treeFieldsData.getTreeIndex()] == 1) {
player.getDialogueHandler().sendStatement(
"This tree is diseased. Use secateurs to prune the area, ",
"or clear the patch with a spade.");
return true;
} else if (treeState[treeFieldsData.getTreeIndex()] == 2) {
player.getDialogueHandler().sendStatement("This tree is dead. You did not cure it while it was diseased.",
"Clear the patch with a spade.");
return true;
} else if (treeState[treeFieldsData.getTreeIndex()] == 6) {
player.getDialogueHandler().sendStatement(
"This is a tree stump, to remove it, use a spade on it",
"to recieve some roots and clear the patch.");
return true;
}
if (treeStages[treeFieldsData.getTreeIndex()] == 0) {
player.getDialogueHandler().sendStatement(
"This is a tree patch. The soil has not been treated.",
"The patch needs weeding.");
} else if (treeStages[treeFieldsData.getTreeIndex()] == 3) {
player.getDialogueHandler().sendStatement(
"This is a tree patch. The soil has not been treated.",
"The patch is empty and weeded.");
} else if (inspectData != null && treeData != null) {
player.getPacketSender().sendMessage(
"You bend down and start to inspect the patch...");
player.startAnimation(1331);
player.stopPlayer(true);
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
if (treeStages[treeFieldsData.getTreeIndex()] - 4 < inspectData
.getMessages().length - 2) {
player.getDialogueHandler().sendStatement( inspectData
.getMessages()[treeStages[treeFieldsData
.getTreeIndex()] - 4]);
} else if (treeStages[treeFieldsData.getTreeIndex()] < treeData
.getEndingState() - treeData.getStartingState() + 2) {
player.getDialogueHandler().sendStatement(
inspectData.getMessages()[inspectData
.getMessages().length - 2]);
} else {
player.getDialogueHandler().sendStatement(
inspectData.getMessages()[inspectData
.getMessages().length - 1]);
}
container.stop();
}
@Override
public void stop() {
player.startAnimation(1332);
player.stopPlayer(false);
// player.reset();
}
}, 5);
}
return true;
}
/* opening the corresponding guide about the patch */
public boolean guide(int objectX, int objectY) {
final TreeFieldsData treeFieldsData = TreeFieldsData.forIdPosition(
objectX, objectY);
if (treeFieldsData == null) {
return false;
}
return true;
}
/* Curing the plant */
public boolean pruneArea(int objectX, int objectY, int itemId) {
final TreeFieldsData treeFieldsData = TreeFieldsData.forIdPosition(
objectX, objectY);
if (treeFieldsData == null
|| (itemId != FarmingConstants.SECATEURS && itemId != FarmingConstants.MAGIC_SECATEURS)) {
return false;
}
final TreeData treeData = TreeData.forId(treeSaplings[treeFieldsData
.getTreeIndex()]);
if (treeData == null) {
return false;
}
if (treeState[treeFieldsData.getTreeIndex()] != 1) {
player.getPacketSender().sendMessage("This area doesn't need to be pruned.");
return true;
}
player.startAnimation(FarmingConstants.PRUNING_ANIM);
player.stopPlayer(true);
treeState[treeFieldsData.getTreeIndex()] = 0;
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
player.getPacketSender().sendMessage(
"You prune the area with your secateurs.");
container.stop();
}
@Override
public void stop() {
updateTreeStates();
player.stopPlayer(false);
player.getPlayerAssistant().resetAnimation();
}
}, 15);
return true;
}
public void resetTrees(int index) {
treeSaplings[index] = 0;
treeState[index] = 0;
diseaseChance[index] = 1;
treeHarvest[index] = 0;
hasFullyGrown[index] = false;
treeWatched[index] = false;
}
/**
* Woodcutting action
*
* @param = tree id
* @param x
* = tree x location
* @param y
* = tree y location
* @return
*/
public boolean cut(final int x, final int y) {
final TreeFieldsData treeFieldsData = TreeFieldsData
.forIdPosition(x, y);
if (treeFieldsData == null)
return false;
final TreeData treeData = TreeData.forId(treeSaplings[treeFieldsData
.getTreeIndex()]);
if (treeData == null)
return false;
if (player.getItemAssistant().freeSlots() <= 0) {
player.getPacketSender().sendMessage("Not enough space in your inventory.");
return true;
}
if (ChopTree.getAxe(player) == null) {
player.getPacketSender()
.sendMessage(
"You do not have an axe which you have the woodcutting level to use.");
return true;
}
final int object = treeData.getTreeObjectAssociated();
player.getPacketSender().sendMessage("You swing your axe at the tree.");
final int emoteId = ChopTree.getAxe(player).getAnimation();
final int axeChance = ChopTree.getAxe(player).getBonus();
final int treeLevel = ChopTree.getTree(object).getLevel();
player.startAnimation(emoteId);
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
final Tree tree = ChopTree.getTree(object);
@Override
public void execute(CycleEventContainer container) {
if (player.getItemAssistant().freeSlots() <= 0) {
container.stop();
return;
}
player.startAnimation(emoteId);
if (SkillHandler.skillCheck(
player.playerLevel[SkillConstants.WOODCUTTING.ordinal()],
treeLevel, axeChance * 20)) {
player.getItemAssistant().addItem(ChopTree.getTree(object).getLog(), 1);
player.getPacketSender().sendMessage(
"You get some "
+ ItemAssistant
.getItemName(ChopTree.getTree(object)
.getLog())
.toLowerCase() + ".");
player.getPlayerAssistant().addSkillXP(ChopTree.getTree(object).getXP(), SkillConstants.WOODCUTTING.ordinal());
if (Misc.random(100) <= tree.getDecayChance()) {
respawnStumpTimer(treeFieldsData.getTreeIndex());
treeState[treeFieldsData.getTreeIndex()] = 7;
updateTreeStates();
container.stop();
player.startAnimation(-1, 0);
}
}
if (!canCut(x, y)) {
player.startAnimation(-1, 0);
container.stop();
}
}
@Override
public void stop() {
// TODO Auto-generated method stub
}
}, 4);
return true;
}
/**
* Checks if you can chop the tree
*
* @param = tree id
* @param x
* = tree x location
* @param y
* = tree y location
* @return if can cut
*/
public boolean canCut(final int x, final int y) {
final TreeFieldsData treeFieldsData = TreeFieldsData
.forIdPosition(x, y);
if (treeFieldsData == null)
return false;
final TreeData treeData = TreeData.forId(treeSaplings[treeFieldsData
.getTreeIndex()]);
if (treeData == null)
return false;
final int object = treeData.getTreeObjectAssociated();
if (!hasFullyGrown[treeFieldsData.getTreeIndex()]) {
return false;
}
if (ChopTree.getAxe(player) == null) {
player.getPacketSender()
.sendMessage(
"You do not have an axe which you have the woodcutting level to use.");
return false;
}
if (player.getItemAssistant().freeSlots() <= 0) {
return false;
}
if (!SkillHandler.hasRequiredLevel(player, SkillConstants.WOODCUTTING.ordinal(), ChopTree
.getTree(object).getLevel(), "chop this tree")) {
return false;
}
return true;
}
/* checking if the patch is raked */
public boolean checkIfRaked(int objectX, int objectY) {
final TreeFieldsData treeFieldsData = TreeFieldsData.forIdPosition(
objectX, objectY);
if (treeFieldsData == null)
return false;
if (treeStages[treeFieldsData.getTreeIndex()] == 3)
return true;
return false;
}
}
@@ -7,6 +7,7 @@ import com.rebotted.game.content.quests.QuestRewards;
import com.rebotted.game.content.randomevents.FreakyForester;
import com.rebotted.game.content.randomevents.RandomEventHandler;
import com.rebotted.game.content.skills.SkillHandler;
import com.rebotted.game.content.skills.farming.Farmers;
import com.rebotted.game.content.skills.slayer.Slayer;
import com.rebotted.game.content.traveling.Sailing;
import com.rebotted.game.globalworldobjects.PassDoor;
@@ -24,9 +25,15 @@ public class DialogueHandler {
public DialogueHandler(Player player2) {
this.player = player2;
}
public void endDialogue() {
player.nextChat = 0;
player.dialogueAction = 0;
}
public void sendDialogues(int dialogue, int npcId) {
int MOLE_SKIN = player.getItemAssistant().getItemCount(7418), MOLE_CLAW = player.getItemAssistant().getItemCount(7416);
Farmers.FarmersData farmersData = Farmers.FarmersData.forId(player.npcType);
player.talkingNpc = npcId;
switch (dialogue) {
case 0:
@@ -4079,7 +4086,7 @@ public class DialogueHandler {
break;
/*
* case 1028: client.getDialogues().sendStatement(
* case 1028: client.getDialogueHandlers().sendStatement(
* "10 coins are removed from your inventory."); client.nextChat = 0;
* break;
*/
@@ -6936,6 +6943,107 @@ public class DialogueHandler {
QuestRewards.blackKnightReward(player);
player.nextChat = 0;
break;
case 3530://1
player.getDialogueHandler().sendNpcChat(player.npcType, ChatEmotes.DEFAULT, "Hey, I am one of the master farmers of this world but", "you can call me " + NpcHandler.getNpcListName(player.npcType) + ". So, what do you need from me?");
if (farmersData.getFieldProtected() == "tree")
player.nextChat = 3531;
else
player.nextChat = 3532;
break;
case 3531://2
player.getDialogueHandler().sendOption("Would you chop my tree down for me?", "Could you take care of my crops for me?", "Can you give me any farming advice?", "Can you sell me something?", "That's all, thanks");
player.dialogueAction = 112;
break;
case 3532://3
player.getDialogueHandler().sendOption("Could you take care of my crops for me?", "Can you give me any farming advice?", "Can you sell me something?", "That's all, thanks");
player.dialogueAction = 113;
break;
case 3533://4
player.getDialogueHandler().sendPlayerChat(ChatEmotes.DEFAULT, "Would you chop my tree down for me?");
player.nextChat = 3534;
break;
case 3534://5
player.getDialogueHandler().sendNpcChat(player.npcType, ChatEmotes.DEFAULT, "Sure, for only 200gp, I will chop it down for you");
player.nextChat = 3536;
break;
case 3535://6
player.getDialogueHandler().sendNpcChat(player.npcType, ChatEmotes.DEFAULT, "Sorry, but you have no tree growing in this patch.");
player.getDialogueHandler().endDialogue();
break;
case 3536://7
player.getDialogueHandler().sendOption("Sure, here you go", "Sorry, I am a little broke.");
player.dialogueAction = 114;
break;
case 3537://8
player.getDialogueHandler().sendPlayerChat(ChatEmotes.DEFAULT, "Sure, Here you go");
player.nextChat = 3539;
break;
case 3538://9
player.getDialogueHandler().sendPlayerChat(ChatEmotes.ANNOYED, "Sorry, I am a little broke");
player.getDialogueHandler().endDialogue();
break;
case 3539://10
Farmers.chopDownTree(player, player.npcType);
break;
case 3540://11
player.getDialogueHandler().sendPlayerChat(ChatEmotes.DEFAULT, "Could you take care of my crops for me?");
if (farmersData.getFieldProtected() == "allotment")
player.nextChat = 3541;
else
player.nextChat = 3543;
break;
case 3541://12
player.getDialogueHandler().sendNpcChat(player.npcType, ChatEmotes.HAPPY_JOYFUL, "I Might, Which one were you thinking of?");
player.nextChat = 3542;
break;
case 3542://13
player.getDialogueHandler().sendOption(farmersData.getDialogueHandlerOptions());
player.dialogueAction = 115;
break;
case 3543://14
Farmers.protectPlant(player, -1, farmersData.getFieldProtected(), player.npcType, 1);
break;
case 3544://15
player.getDialogueHandler().sendOption("Sure, here you go.", "Sorry, I don't have those at the moment.");
player.dialogueAction = 116;
break;
case 3545://16
player.getDialogueHandler().sendPlayerChat(ChatEmotes.DEFAULT, "Sure, here you go.");
player.nextChat = 3547;
break;
case 3546://17
player.getDialogueHandler().sendPlayerChat(ChatEmotes.DEFAULT, "Sorry, I don't have those at the moment.");
player.getDialogueHandler().endDialogue();
break;
case 3547://18
Farmers.protectPlant(player, player.getTempInteger(), farmersData.getFieldProtected(), player.npcType, 2);
break;
case 3548://19
player.getDialogueHandler().sendPlayerChat(ChatEmotes.DEFAULT, "Can you give me any farming advice?");
player.nextChat = 3549;
break;
case 3549://20
Farmers.sendFarmingAdvice(player);
player.getDialogueHandler().endDialogue();
break;
case 3550://21
player.getDialogueHandler().sendPlayerChat(ChatEmotes.DEFAULT, "Can you sell me something?");
player.nextChat = 3551;
break;
case 3551://22
player.getDialogueHandler().sendNpcChat(player.npcType, ChatEmotes.HAPPY_JOYFUL, "Sure, I have a bunch of tools for you to use.");
player.nextChat = 3552;
break;
case 3552://23
player.getDialogueHandler().endDialogue();
player.getPacketSender().closeAllWindows();
player.getShopAssistant().openShop(farmersData.getShopId());
break;
case 3553://24
player.getDialogueHandler().sendPlayerChat(ChatEmotes.DEFAULT, "That's all, thanks");
player.getDialogueHandler().endDialogue();
break;
}
}
@@ -7135,6 +7243,46 @@ public class DialogueHandler {
/*
* Npc Chatting
*/
public void sendNpcChat(int npcId, ChatEmotes e, String... line) {
String npcName = NpcHandler.getNpcListName(npcId).replaceAll("_", " ");
switch (line.length) {
case 1:
player.getPacketSender().sendDialogueAnimation(4883, getChatAnim(e));
player.getPacketSender().sendFrame126(npcName, 4884);
player.getPacketSender().sendFrame126(line[0], 4885);
player.getPacketSender().sendNPCDialogueHead(npcId, 4883);
player.getPacketSender().sendChatInterface(4882);
break;
case 2:
player.getPacketSender().sendDialogueAnimation(4888, getChatAnim(e));
player.getPacketSender().sendFrame126(npcName, 4889);
player.getPacketSender().sendFrame126(line[0], 4890);
player.getPacketSender().sendFrame126(line[1], 4891);
player.getPacketSender().sendNPCDialogueHead(npcId, 4888);
player.getPacketSender().sendChatInterface(4887);
break;
case 3:
player.getPacketSender().sendDialogueAnimation(4894, getChatAnim(e));
player.getPacketSender().sendFrame126(npcName, 4895);
player.getPacketSender().sendFrame126(line[0], 4896);
player.getPacketSender().sendFrame126(line[1], 4897);
player.getPacketSender().sendFrame126(line[2], 4898);
player.getPacketSender().sendNPCDialogueHead(npcId, 4894);
player.getPacketSender().sendChatInterface(4893);
break;
case 4:
player.getPacketSender().sendDialogueAnimation(4901, getChatAnim(e));
player.getPacketSender().sendFrame126(npcName, 4902);
player.getPacketSender().sendFrame126(line[0], 4903);
player.getPacketSender().sendFrame126(line[1], 4904);
player.getPacketSender().sendFrame126(line[2], 4905);
player.getPacketSender().sendFrame126(line[3], 4906);
player.getPacketSender().sendNPCDialogueHead(npcId, 4901);
player.getPacketSender().sendChatInterface(4900);
break;
}
}
public void sendNpcChat1(String s, int ChatNpc, String name) {
player.getPacketSender().sendDialogueAnimation(4883, 591);
@@ -14,6 +14,41 @@ public class DialogueOptions {
public static void handleDialogueOptions(Player player, int buttonId) {
switch (buttonId) {
case 9190:
switch (player.dialogueAction) {
case 112:
player.getDialogueHandler().sendDialogues(3533, player.npcType);//4
break;
}
break;
case 9191:
switch (player.dialogueAction) {
case 112:
player.getDialogueHandler().sendDialogues(3540, player.npcType);
break;
}
break;
case 9192:
switch (player.dialogueAction) {
case 112:
player.getDialogueHandler().sendDialogues(3548, player.npcType);
break;
}
break;
case 9193:
switch (player.dialogueAction) {
case 112:
player.getDialogueHandler().sendDialogues(3550, player.npcType);
break;
}
break;
case 9194:
switch (player.dialogueAction) {
case 112:
player.getDialogueHandler().sendDialogues(3553, player.npcType);
break;
}
break;
case 9157:// barrows tele to tunnels
if (player.dialogueAction == 1) {
int r = 4;
@@ -59,8 +94,7 @@ public class DialogueOptions {
player.getDialogueHandler().sendDialogues(361, player.npcType);
return;
} else if (player.dialogueAction == 50) {
player.getPlayerAssistant().startTeleport(2898, 3562, 0,
"modern");
player.getPlayerAssistant().startTeleport(2898, 3562, 0, "modern");
Teles.necklaces(player);
return;
} else if (player.dialogueAction == 55) {
@@ -118,6 +152,12 @@ public class DialogueOptions {
} else if (player.dialogueAction == 93) {
player.getDialogueHandler().sendDialogues(23, player.npcType);
return;
} else if (player.dialogueAction == 114) {
player.getDialogueHandler().sendDialogues(3537, player.npcType);
return;
} else if (player.dialogueAction == 116) {
player.getDialogueHandler().sendDialogues(3545, player.npcType);
return;
} else if (player.dialogueAction == 118) {
player.getDialogueHandler().sendDialogues(394, player.npcType);
return;
@@ -321,6 +361,12 @@ public class DialogueOptions {
} else if (player.dialogueAction == 91) {
player.getDialogueHandler().sendDialogues(17, player.npcType);
return;
} else if (player.dialogueAction == 114) {
player.getDialogueHandler().sendDialogues(3538, player.npcType);
return;
} else if (player.dialogueAction == 116) {
player.getDialogueHandler().sendDialogues(3546, player.npcType);
return;
} else if (player.dialogueAction == 118) {
player.getDialogueHandler().sendDialogues(392, player.npcType);
return;
@@ -503,10 +549,12 @@ public class DialogueOptions {
player.getDialogueHandler().sendDialogues(378, player.npcType);
}
if (player.dialogueAction == 51) {
player.getPlayerAssistant().gloryTeleport(3088, 3500, 0,
"modern");
player.getPlayerAssistant().gloryTeleport(3088, 3500, 0, "modern");
Teles.necklaces(player);
}
if (player.dialogueAction == 113) {
player.getDialogueHandler().sendDialogues(3540, player.npcType);
}
Teles.necklaces(player);
if (player.dialogueAction == 52) {
player.getDialogueHandler().sendDialogues(52, player.npcType);
}
@@ -543,6 +591,9 @@ public class DialogueOptions {
if (player.dialogueAction == 2) {
player.getPlayerAssistant().startTeleport(2884, 3395, 0, "modern");
}
if (player.dialogueAction == 113) {
player.getDialogueHandler().sendDialogues(3548, player.npcType);
}
if (player.dialogueAction == 122 && player.objectId == 12163 || player.objectId == 12165 || player.objectId == 12166) {//champ
player.getPlayerAssistant().startTeleport(3203, 3343, 0, "modern");
} else if (player.objectId == 12164) {
@@ -571,8 +622,8 @@ public class DialogueOptions {
}
if (player.dialogueAction == 51) {
player.getPlayerAssistant().gloryTeleport(3293, 3174, 0, "modern");
Teles.necklaces(player);
}
Teles.necklaces(player);
if (player.dialogueAction == 52) {
player.getDialogueHandler().sendDialogues(64, player.npcType);
}
@@ -612,6 +663,9 @@ public class DialogueOptions {
if (player.dialogueAction == 69) {
player.getDialogueHandler().sendDialogues(500003, player.npcType);
}
if (player.dialogueAction == 113) {
player.getDialogueHandler().sendDialogues(3550, player.npcType);
}
if (player.dialogueAction == 122 && player.objectId == 12164 || player.objectId == 12165 || player.objectId == 12166) {//lumby
player.getPlayerAssistant().startTeleport(3243, 3237, 0, "modern");
} else if (player.objectId == 12163) {
@@ -640,8 +694,8 @@ public class DialogueOptions {
}
if (player.dialogueAction == 51) {
player.getPlayerAssistant().gloryTeleport(2911, 3152, 0, "modern");
Teles.necklaces(player);
}
Teles.necklaces(player);
if (player.dialogueAction == 52) {
player.getDialogueHandler().sendDialogues(65, player.npcType);
}
@@ -678,6 +732,9 @@ public class DialogueOptions {
if (player.dialogueAction == 2) {
player.getPlayerAssistant().startTeleport(2669, 3714, 0, "modern");
}
if (player.dialogueAction == 113) {
player.getDialogueHandler().sendDialogues(3553, player.npcType);
}
if (player.dialogueAction == 69) {
player.getDialogueHandler().sendDialogues(500004, player.npcType);
}
@@ -690,14 +747,12 @@ public class DialogueOptions {
}
}
if (player.dialogueAction == 3) {
player.getPlayerAssistant().startTeleport(2540, 4716, 0,
"modern");
player.getPlayerAssistant().startTeleport(2540, 4716, 0, "modern");
}
if (player.dialogueAction == 51) {
player.getPlayerAssistant().gloryTeleport(3103, 3249, 0,
"modern");
player.getPlayerAssistant().gloryTeleport(3103, 3249, 0, "modern");
Teles.necklaces(player);
}
Teles.necklaces(player);
if (player.dialogueAction == 52) {
player.getDialogueHandler().sendDialogues(63, player.npcType);
}
@@ -6,7 +6,7 @@ public class GameItem {
public boolean stackable = false;
public GameItem(int id, int amount) {
if (Item.itemStackable[id]) {
if (ItemData.itemStackable[id]) {
stackable = true;
}
this.id = id;
@@ -0,0 +1,149 @@
package com.rebotted.game.items;
import com.rebotted.GameConstants;
import com.rebotted.GameEngine;
import com.rebotted.game.players.Player;
/**
*
* @author ArrowzFtw
* @note itemId+1 is the playerItems
* @note playerItems-1 = normalItemId
*/
public class Inventory {
Player player;
public Inventory(Player player) {
this.player = player;
}
public void removeItem(Item i) {
player.getItemAssistant().deleteItem(i.getId(), i.getCount());
}
public void addItemToSlot(Item i, int slot) {
if (get(slot) != i.getId() + 1) {
player.playerItems[slot] = i.getId() + 1;
player.playerItemsN[slot] = i.getCount();
} else {
player.playerItemsN[slot] += i.getCount();
}
update();
}
public int get(int slot) {
return player.playerItems[slot];
}
public void update() {
player.getItemAssistant().resetItems(3214);
}
public boolean contains(int id) {
return player.getItemAssistant().playerHasItem(id);
}
public boolean contains(Item item) {
return player.getItemAssistant().playerHasItem(item.getId(), item.getCount());
}
public boolean contains(int id, int amount) {
return player.getItemAssistant().playerHasItem(id, amount);
}
public Inventory getItemContainer() {
return this;
}
public void addItem(Item item) {
player.getItemAssistant().addItem(item.getId(), item.getCount());
}
public int getItemAmount(int id) {
return player.getItemAssistant().getItemAmount(id);
}
public void replace(int item, int newItem) {
player.getItemAssistant().deleteItem(item, 1);
player.getItemAssistant().addItem(newItem, 1);
}
public int getCount(int i) {
return player.getItemAssistant().getItemAmount(i);
}
public void set(int slot, Item item) {
player.playerItems[slot] = item.getId() + 1;
player.playerItemsN[slot] = item.getCount();
update();
}
public int freeSlots() {
return player.getItemAssistant().freeSlots();
}
public void add(int id) {
player.getItemAssistant().addItem(id, 1);
}
public boolean add(int id, int amount) {
if (player.getItemAssistant().isStackable(id)) {
int allAmount = getStackedGroundAmount(id, amount, getCount(id));
if (allAmount > 0) {
GameEngine.itemHandler.createGroundItem(player, id, player.getX(), player
.getY(), allAmount, player
.getId());
player.getItemAssistant().deleteItem(id, Integer.MAX_VALUE);
player.getItemAssistant().addItem(id, Integer.MAX_VALUE);
return true;
}
}
return player.getItemAssistant().addItem(id, amount);
}
public int getStackedGroundAmount(int itemId, int addItemAmount,
int itemAmount) {
long x = 0;
x += itemAmount;
x += addItemAmount;
if (x > 2147483647) {
x -= 2147483647;
return (int) x;
}
return -1;
}
public boolean canAddItem(Item item) {
return item.getCount() <= freeSlots();
}
public void addItem(Item item, boolean drop) {
if (!drop) {
addItem(item);
} else {
GameEngine.itemHandler.createGroundItem(player, item.getId(), player.getX(), player.getY(), item.getCount(), player.playerId);
}
}
public boolean ownsItem(String itemName) {
for (int i = 0; i < GameConstants.ITEM_LIMIT; i++) {
if (GameEngine.itemHandler.ItemList[i] != null) {
if (GameEngine.itemHandler.ItemList[i].itemName
.equalsIgnoreCase(itemName)) {
return true;
}
}
}
return false;
}
public boolean playerHasItem(int item) {
return player.getItemAssistant().playerHasItem(item);
}
public void removeItemSlot(Item item, int slot) {
player.getItemAssistant().deleteItem(item.getId(), slot, item.getCount());
}
}
@@ -1,376 +1,105 @@
package com.rebotted.game.items;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import com.rebotted.GameConstants;
import com.rebotted.GameEngine;
/**
* Represents a single item.
*
* @author Graham Edgecombe
*
*/
public class Item {
public static int capes[] = { 2731, 2677, 2683, 2680, 2701, 2686, 2689,
2692, 2737, 2734, 2716, 2728, 2695, 2713, 2725, 2722, 2707, 2704,
2710, 2719, 2737, 2698, 14590, 2701, 8102, 8075, 8044, 8045, 8042,
8043, 8037, 8038, 8025, 8026, 8018, 7858, 7994, 7983, 7984, 7985,
7986, 7987, 7982, 7978, 3781, 3783, 3785, 3787, 3789, 3777, 3779,
3759, 3761, 3763, 3765, 6111, 6570, 6568, 1007, 1019, 1021, 1023,
1027, 1029, 1031, 1052, 2412, 2413, 2414, 4304, 4315, 4317, 4319,
4321, 4323, 4325, 4327, 4329, 4331, 4333, 4335, 4337, 4339, 4341,
4343, 4345, 4347, 4349, 4351, 4353, 4355, 4357, 4359, 4361, 4363,
4365, 4367, 4369, 4371, 4373, 4375, 4377, 4379, 4381, 4383, 4385,
4387, 4389, 4391, 4393, 4395, 4397, 4399, 4401, 4403, 4405, 4407,
4409, 4411, 4413, 4514, 4516, 6070, 6568, 6570, 4304, 3759, 3761,
3763, 3765, 3777, 3779, 3781, 3783, 3785, 3787, 3789 };
public static int boots[] = { 7596, 8029, 6619, 8017, 7159, 7991, 6666,
6061, 6106, 88, 89, 626, 628, 630, 632, 634, 1061, 1837, 1846,
2577, 2579, 2894, 2904, 2914, 2924, 2934, 3061, 3105, 3107, 3791,
4097, 4107, 4117, 4119, 4121, 4123, 4125, 4127, 4129, 4131, 4310,
5064, 5345, 5557, 6069, 6106, 6143, 6145, 6147, 6328, 6920, 6349,
6357, 3393 };
public static int gloves[] = { 7595, 6629, 8021, 8016, 7964, 2491, 1065,
2487, 2489, 3060, 1495, 775, 777, 778, 6708, 1059, 1063, 1065,
1580, 2487, 2489, 2491, 2902, 2912, 2922, 2932, 2942, 3060, 3799,
4095, 4105, 4115, 4308, 5556, 6068, 6110, 6149, 6151, 6153, 6922,
7454, 7455, 7456, 7457, 7458, 7459, 7460, 7461, 7462, 6330, 3391,
776 };
public static int shields[] = { 7676, 7342, 7348, 7354, 7360, 7334, 7340,
7347, 7352, 7358, 7356, 7350, 7344, 8087, 8058, 8059, 8060, 8061,
8062, 8063, 6633, 7977, 7976, 7972, 7959, 6591, 7332, 7338, 7336,
7360, 1171, 1173, 1175, 1177, 1179, 1181, 1183, 1185, 1187, 1189,
1191, 1193, 1195, 1197, 1199, 1201, 1540, 2589, 2597, 2603, 2611,
2621, 2629, 2659, 2667, 2675, 2890, 3122, 3488, 3758, 3839, 3840,
3841, 3842, 3843, 3844, 4072, 4156, 4224, 4225, 4226, 4227, 4228,
4229, 4230, 4231, 4232, 4233, 4234, 4302, 4507, 4512, 6215, 6217,
6219, 6221, 6223, 6225, 6227, 6229, 6231, 6233, 6235, 6237, 6239,
6241, 6243, 6245, 6247, 6249, 6251, 6253, 6255, 6257, 6259, 6261,
6263, 6265, 6267, 6269, 6271, 6273, 6275, 6277, 6279, 6524, 6889,
7051, 7053 };
public static int hats[] = { 2679, 1025, 2685, 4166, 2682, 2703, 2688,
2691, 2691, 2733, 2736, 2718, 2730, 2697, 2715, 2727, 2724, 2709,
2706, 2712, 2721, 2739, 2700, 2518, 2524, 2526, 7319, 7321, 7323,
7325, 7327, 1167, 8077, 8076, 8074, 4168, 1169, 8034, 8035, 8036,
8030, 6623, 8024, 8023, 8022, 8013, 1169, 7594, 7995, 7996, 7997,
7998, 7999, 8000, 8001, 7992, 7990, 7975, 7973, 7971, 7967, 7963,
6665, 6665, 7321, 6886, 6547, 6548, 2645, 2647, 2649, 4856, 4857,
4858, 4859, 4880, 4881, 4882, 4883, 4904, 4905, 4906, 4907, 4928,
4929, 4930, 4931, 4952, 4953, 4954, 4955, 4976, 4977, 4978, 4979,
4732, 4753, 4611, 6188, 6182, 4511, 4056, 4071, 4724, 2639, 2641,
2643, 2665, 6109, 5525, 5527, 5529, 5531, 5533, 5535, 5537, 5539,
5541, 5543, 5545, 5547, 5549, 5551, 74, 579, 656, 658, 660, 662,
664, 740, 1017, 1037, 1040, 1042, 1044, 1046, 1038, 1048, 1050,
1053, 1055, 1057, 1137, 1139, 1141, 1143, 1145, 1147, 1149, 1151,
1153, 1155, 1157, 1159, 1161, 1163, 1165, 1506, 1949, 2422, 2581,
2587, 2595, 2605, 2613, 2619, 2627, 2631, 2633, 2635, 2637, 2651,
2657, 2673, 2900, 2910, 2920, 2930, 2940, 2978, 2979, 2980, 2981,
2982, 2983, 2984, 2985, 2986, 2987, 2988, 2989, 2990, 2991, 2992,
2993, 2994, 2995, 3057, 3385, 3486, 3748, 3749, 3751, 3753, 3797,
4041, 4042, 4071, 4089, 3755, 4099, 4109, 4164, 4302, 4506, 4511,
4513, 4515, 4551, 4567, 4708, 4716, 4724, 4745, 4753, 4857, 4858,
4859, 4880, 4881, 4882, 4883, 4904, 4905, 4906, 4907, 4952, 4953,
4954, 4955, 4976, 4977, 4978, 4979, 5013, 5014, 5554, 5574, 6109,
6128, 6131, 6137, 6182, 6188, 6335, 6337, 6339, 6345, 6355, 6365,
6375, 6382, 6392, 6400, 6918, 6656, 2581, 7539, 7394, 7396, 7534,
5574, 6885, 6858, 6860, 6862, 6856, 6326, 6128, 6137, 7400, 7323,
7325, 7327, 7003, 4168, 7112, 7124, 7130, 7136 };
public static int amulets[] = { 1654, 1656, 1658, 1660, 1662, 1664, 8081,
8033, 7968, 6585, 86, 87, 295, 421, 552, 589, 1478, 1692, 1694,
1696, 1698, 1700, 1702, 1704, 1706, 1708, 1710, 1712, 1725, 1727,
1729, 1731, 4021, 4081, 4250, 4677, 6040, 6041, 6208, 1718, 1722,
6859, 6863, 6857, 3853, 3855, 3857, 3859, 3861, 3863, 3865, 3867,
1718, 4306, 1702 };
public static int arrows[] = { 11212, 8052, 9211, 9010, 9209, 9208, 9207,
9206, 9205, 9203, 9301, 8065, 7919, 7906, 7988, 7989, 78, 598, 877,
878, 879, 880, 881, 882, 883, 884, 885, 886, 887, 888, 889, 890,
891, 892, 893, 942, 2532, 2533, 2534, 2535, 2536, 2537, 2538, 2539,
2540, 2541, 2866, 4160, 4172, 4173, 4174, 4175, 4740, 5616, 5617,
5618, 5619, 5620, 5621, 5622, 5623, 5624, 5625, 5626, 5627, 6061,
6062};
public static int rings[] = { 8082, 773, 1635, 1637, 1639, 1641, 1643,
1645, 2550, 2552, 2554, 2556, 2558, 2560, 2562, 2564, 2566, 2568,
2570, 2572, 4202, 4657, 6465, 6737, 6731, 6735, 6583, 6733 };
public static int body[] = { 7608, 2520, 430, 7362, 7364, 636, 638, 640,
642, 644, 8064, 426, 430, 1005, 1757, 7592, 8031, 8027, 6617, 8019,
8014, 8002, 7376, 544, 7372, 7370, 577, 7974, 7970, 7965, 7961,
7960, 3793, 3775, 3773, 3771, 3769, 3767, 6139, 1135, 2499, 2501,
1035, 540, 5553, 4757, 1833, 6388, 6384, 4111, 4101, 4091, 6186,
6184, 6180, 3058, 4509, 4504, 4069, 4728, 4736, 4712, 6107, 2661,
3140, 1101, 1103, 1105, 1107, 1109, 1111, 1113, 1115, 1117, 1119,
1121, 1123, 1125, 1127, 1129, 1131, 1133, 2583, 2591, 2599, 2607,
2615, 2623, 2653, 2669, 3481, 4712, 4720, 4728, 4749, 4892, 4893,
4894, 4895, 4916, 4917, 4918, 4919, 4964, 4965, 4966, 4967, 6107,
6133, 6322, 6322, 6129, 75, 6916, 6916, 4111, 6654, 6654, 75, 7399, 7374, 5575, 2503, 6341, 6351, 3387, 5030, 5032, 5034, 5030,
5032, 5034,7390 , 7392, 546, 581 };
public static int legs[] = { 7609, 2522, 7378, 7380, 7382, 7368, 7366,
7388, 646, 648, 650, 652, 654, 428, 1097, 1095, 7593, 8032, 8028,
6625, 8020, 8015, 7384, 7969, 7966, 7962, 6141, 538, 1033, 5555,
4759, 6386, 6390, 2497, 2495, 2493, 1099, 4113, 4103, 4093, 6924,
6187, 6185, 6181, 3059, 4510, 4505, 4070, 6108, 542, 548, 1011,
1013, 1015, 1067, 1069, 1071, 1073, 1075, 1077, 1079, 1081, 1083,
1085, 1087, 1089, 1091, 1093, 2585, 2593, 2601, 2609, 2617, 2625,
2655, 2663, 2671, 3059, 3389, 3472, 3473, 3474, 3475, 3476, 3477,
3478, 3479, 3480, 3483, 3485, 3795, 4087, 4585, 4712, 4714, 4722,
4730, 4738, 4751, 4759, 4874, 4875, 4876, 4877, 4898, 4899, 4900,
4901, 4922, 4923, 4924, 4925, 4946, 4947, 4948, 4949, 4970, 4971,
4972, 4973, 4994, 4995, 4996, 4997, 5048, 5050, 5052, 5576, 6107,
6130, 6187, 6390, 6386, 6390, 6394, 6396, 6402, 6404, 6135, 6809, 6916, 4091,
4111, 6655, 6654, 7398, 7398, 7386, 6324, 6343, 6353, 6363, 6373, 3387, 5036,
5038, 5040, 5042, 5044, 5046, 5050, 5052, 4300, 1835, 7116, 7126, 6752,
7132, 7138 };
public static int platebody[] = { 10338, 7608, 2520, 430, 636, 638, 640,
642, 644, 426, 430, 8031, 8027, 6617, 8019, 8014, 8002, 544, 577,
7974, 7970, 7965, 7961, 7960, 3793, 3773, 3775, 3771, 3769, 3767,
6139, 1035, 540, 5553, 4757, 1833, 1835, 6388, 6384, 4111, 4101,
4868, 4869, 4870, 4871, 4892, 4893, 4894, 4895, 4916, 4917, 4918,
4919, 4940, 4941, 4942, 4943, 4964, 4965, 4966, 4967, 4988, 4989,
4990, 0x2f9a0eb, 6186, 6184, 6180, 3058, 4509, 4504, 4069, 4728,
4736, 4712, 6107, 2661, 3140, 1115, 1117, 1119, 1121, 1123, 1125,
1127, 2583, 2591, 2599, 2607, 2615, 6322, 2623, 2653, 2669, 3481,
4720, 4728, 4749, 2661, 6129, 6916, 4091, 6654, 6133, 75, 7399, 5575, 6341, 6351, 7390, 7392, 3387, 5024, 5030, 5032, 5034, 7392, 6786, 6788 };
/**
* The id.
*/
private int id;
/* Fullbody is an item that covers your arms. */
private static String[] fullbody = {
"top", "shirt", "platebody", "Wizard robe (g)", "Wizard robe (t)",
"Ahrims robetop", "Karils leathertop", "brassard", "Robe top",
"robetop", "platebody (t)", "platebody (g)", "chestplate", "torso",
"hauberk", "Dragon chainbody", "gown", "Shade robe", "Wizard robe",
"Druid's robe", "Black robe", "Fremennik robe", "Robe of elidinis",
"tunic", "blouse", "Wizard robe(g)", "Wizard robe(t)"
};
/* Fullhat covers your head but not your beard. */
private static String[] fullhat = { "med helm", "coif", "Dharok's helm",
"hood", "Initiate helm", "Coif", "Helm of neitiznot",
"Armadyl helmet", "Berserker helm", "Archer helm", "Farseer helm",
"Warrior helm", "Void"};
/* Fullmask covers your entire head. */
private static String[] fullmask = { "full helm(t)", "full helm(g)", "full helm", "mask", "Verac's helm",
"Guthan's helm", "Karil's coif", "mask", "Torag's helm", "Void", "helmet",
"sallet", "Facemask", "Bearhead"};
/**
* The number of items.
*/
private int count;
public static boolean isFullBody(int itemId) {
String weapon = getItemName(itemId);
if (weapon == null) {
return false;
}
for (String element : fullbody) {
if (weapon.endsWith(element)) {
return true;
}
}
return false;
/**
* Creates a single item.
*
* @param id
* The id.
*/
public Item(int id) {
this(id, 1);
}
public static boolean isFullHelm(int itemId) {
String weapon = getItemName(itemId);
if (weapon == null) {
return false;
}
for (String element : fullhat) {
if (weapon.endsWith(element)) {
return true;
}
}
return false;
public void setCount(int count) {
this.count = count;
}
public static boolean isFullMask(int itemId) {
String weapon = getItemName(itemId);
if (weapon == null) {
return false;
/**
* Creates a stacked item.
*
* @param id
* The id.
* @param count
* The number of items.
* @throws IllegalArgumentException
* if count is negative.
*/
public Item(int id, int count) {
if (count < 0) {
throw new IllegalArgumentException("Count cannot be negative.");
}
for (String element : fullmask) {
if (weapon.endsWith(element)) {
return true;
}
}
return false;
this.id = id;
this.count = count;
}
public static String getItemName(int id) {
for (ItemList element : GameEngine.itemHandler.ItemList) {
if (element != null) {
if (element.itemId == id) {
return element.itemName;
}
}
/**
* Creates a stacked item.
*
* @param id
* The id.
* @param count
* The number of items.
* @param timer
* The timer assigned.
* @throws IllegalArgumentException
* if count is negative.
*/
public Item(int id, int count, int timer) {
if (count < 0) {
throw new IllegalArgumentException("Count cannot be negative.");
}
return null;
this.id = id;
this.count = count;
}
public static boolean[] itemStackable = new boolean[GameConstants.ITEM_LIMIT];
public static boolean[] itemIsNote = new boolean[GameConstants.ITEM_LIMIT];
public static int[] targetSlots = new int[GameConstants.ITEM_LIMIT];
static {
int counter = 0;
int c;
try {
FileInputStream dataIn = new FileInputStream(new File("./data/data/stackable.dat"));
while ((c = dataIn.read()) != -1) {
if (c == 0) {
itemStackable[counter] = false;
itemStackable[291] = true;
} else {
itemStackable[counter] = true;
}
counter++;
}
dataIn.close();
} catch (IOException e) {
System.out.println("Critical error while loading stackabledata! Trace:");
e.printStackTrace();
}
counter = 0;
try {
FileInputStream dataIn = new FileInputStream(new File("./data/data/notes.dat"));
while ((c = dataIn.read()) != -1) {
itemIsNote[counter] = c == 0;
counter++;
}
dataIn.close();
} catch (IOException e) {
System.out.println("Critical error while loading notedata! Trace:");
e.printStackTrace();
}
counter = 0;
try {
FileInputStream dataIn = new FileInputStream(new File("./data/data/equipment.dat"));
while ((c = dataIn.read()) != -1) {
int slot;
// rebind item equip slot here
switch (counter) {
// Legs
case 6181:
case 428:
case 538:
case 6343:
case 6353:
case 6363:
case 6396:
case 6373:
case 6404:
case 5044:
case 5046:
case 5050:
case 5052:
case 5040:
case 5038:
case 6752:
case 5048:
case 5036:
case 5042:
case 4300:
case 1835:
case 7116:
case 7126:
case 7132:
case 7138:
case 548:
case 6185:
slot = GameConstants.LEGS;
break;
// Hats
case 4166:
case 1167:
case 5525:
case 4168:
case 4502:
case 1037:
case 1025:
case 7112:
case 7124:
case 7130:
case 7136:
case 4611:
case 5527:
case 5529:
case 5531:
case 5533:
case 5535:
case 5537:
case 5539:
case 5541:
case 5543:
case 5545:
case 5547:
slot = GameConstants.HAT;
break;
// Cape
case 4304:
case 3759:
case 3761:
case 3763:
case 3765:
case 3777:
case 3779:
case 3781:
case 3783:
case 3785:
case 3787:
case 3789:
case 4514:
case 4516:
slot = GameConstants.CAPE;
break;
// Shield
case 7051:
case 7053:
slot = GameConstants.SHIELD;
break;
// Chest
case 577:
case 426:
case 540:
case 430:
case 6786:
case 581:
case 5024:
case 5030:
case 1757:
case 5034:
case 5032:
case 3793:
case 1005:
case 546:
case 6402:
case 6788:
case 6184:
case 7390:
case 7392:
case 6186:
slot = GameConstants.CHEST;
break;
// Amulet
case 3853:
case 3855:
case 3857:
case 3859:
case 3861:
case 3863:
case 1718:
case 3865:
case 4306:
case 3867:
case 1702:
slot = GameConstants.AMULET;
break;
// Hands
case 776:
slot = GameConstants.HANDS;
break;
default:
slot = c;
}
targetSlots[counter] = slot;
counter++;
}
dataIn.close();
} catch (IOException e) {
System.out.println("Critical error while loading equipment data! Trace:");
e.printStackTrace();
}
/**
* Gets the item id.
*
* @return The item id.
*/
public int getId() {
return id;
}
}
/**
* Gets the count.
*
* @return The count.
*/
public int getCount() {
return count;
}
@Override
public String toString() {
return Item.class.getName() + " [id=" + id + ", count=" + count + "]";
}
public boolean equals(Item item) {
return item.getId() == id && count == item.getCount();
}
public ItemList getDefinition() {
return GameEngine.itemHandler.ItemList[id];
}
}
@@ -241,12 +241,12 @@ public class ItemAssistant {
public int getTotalCount(int itemID) {
int count = 0;
for (int j = 0; j < c.playerItems.length; j++) {
if (Item.itemIsNote[itemID + 1]) {
if (ItemData.itemIsNote[itemID + 1]) {
if (itemID + 2 == c.playerItems[j]) {
count += c.playerItemsN[j];
}
}
if (!Item.itemIsNote[itemID + 1]) {
if (!ItemData.itemIsNote[itemID + 1]) {
if (itemID + 1 == c.playerItems[j]) {
count += c.playerItemsN[j];
}
@@ -466,10 +466,10 @@ public class ItemAssistant {
return false;
}
if ((freeSlots() >= 1 || playerHasItem(item, 1))
&& Item.itemStackable[item] || freeSlots() > 0
&& !Item.itemStackable[item]) {
&& ItemData.itemStackable[item] || freeSlots() > 0
&& !ItemData.itemStackable[item]) {
for (int i = 0; i < c.playerItems.length; i++) {
if (c.playerItems[i] == item + 1 && Item.itemStackable[item]
if (c.playerItems[i] == item + 1 && ItemData.itemStackable[item]
&& c.playerItems[i] > 0) {
c.playerItems[i] = item + 1;
if (c.playerItemsN[i] + amount < GameConstants.MAXITEM_AMOUNT
@@ -1298,7 +1298,7 @@ public class ItemAssistant {
boolean canWearItem = true;
if (c.playerItems[slot] == wearID + 1) {
getRequirements(getItemName(wearID).toLowerCase(), wearID);
targetSlot = Item.targetSlots[wearID];
targetSlot = ItemData.targetSlots[wearID];
if (c.duelRule[11] && targetSlot == 0) {
c.getPacketSender().sendMessage("Wearing hats has been disabled in this duel!");
@@ -1447,7 +1447,7 @@ public class ItemAssistant {
int toEquipN = c.playerItemsN[slot];
int toRemove = c.playerEquipment[targetSlot];
int toRemoveN = c.playerEquipmentN[targetSlot];
if (toEquip == toRemove + 1 && Item.itemStackable[toRemove]) {
if (toEquip == toRemove + 1 && ItemData.itemStackable[toRemove]) {
deleteItem(toRemove, getItemSlot(toRemove), toEquipN);
c.playerEquipmentN[targetSlot] += toEquipN;
} else if (targetSlot != GameConstants.SHIELD && targetSlot != GameConstants.WEAPON) {
@@ -1781,11 +1781,11 @@ public class ItemAssistant {
if (c.playerItemsN[fromSlot] <= 0) {
return false;
}
if (!Item.itemIsNote[c.playerItems[fromSlot] - 1]) {
if (!ItemData.itemIsNote[c.playerItems[fromSlot] - 1]) {
if (c.playerItems[fromSlot] <= 0) {
return false;
}
if (Item.itemStackable[c.playerItems[fromSlot] - 1] || c.playerItemsN[fromSlot] > 1) {
if (ItemData.itemStackable[c.playerItems[fromSlot] - 1] || c.playerItemsN[fromSlot] > 1) {
int toBankSlot = 0;
boolean alreadyInBank = false;
for (int i = 0; i < GameConstants.BANK_SIZE; i++) {
@@ -1908,11 +1908,11 @@ public class ItemAssistant {
return false;
}
}
} else if (Item.itemIsNote[c.playerItems[fromSlot] - 1] && !Item.itemIsNote[c.playerItems[fromSlot] - 2]) {
} else if (ItemData.itemIsNote[c.playerItems[fromSlot] - 1] && !ItemData.itemIsNote[c.playerItems[fromSlot] - 2]) {
if (c.playerItems[fromSlot] <= 0) {
return false;
}
if (Item.itemStackable[c.playerItems[fromSlot] - 1] || c.playerItemsN[fromSlot] > 1) {
if (ItemData.itemStackable[c.playerItems[fromSlot] - 1] || c.playerItemsN[fromSlot] > 1) {
int toBankSlot = 0;
boolean alreadyInBank = false;
for (int i = 0; i < GameConstants.BANK_SIZE; i++) {
@@ -2084,7 +2084,7 @@ public class ItemAssistant {
if (!cantWithdrawCuzMaxStack)
{
if (!c.takeAsNote) {
if (Item.itemStackable[c.bankItems[fromSlot] - 1]) {
if (ItemData.itemStackable[c.bankItems[fromSlot] - 1]) {
if (c.bankItemsN[fromSlot] > amount) {
if (addItem(c.bankItems[fromSlot] - 1, amount)) {
c.bankItemsN[fromSlot] -= amount;
@@ -2116,7 +2116,7 @@ public class ItemAssistant {
resetBank();
resetItems(5064);
}
} else if (c.takeAsNote && Item.itemIsNote[c.bankItems[fromSlot]]) {
} else if (c.takeAsNote && ItemData.itemIsNote[c.bankItems[fromSlot]]) {
if (c.bankItemsN[fromSlot] > amount) {
if (addItem(c.bankItems[fromSlot], amount)) {
c.bankItemsN[fromSlot] -= amount;
@@ -2133,7 +2133,7 @@ public class ItemAssistant {
}
} else {
c.getPacketSender().sendMessage("This item can't be withdrawn as a note.");
if (Item.itemStackable[c.bankItems[fromSlot] - 1]) {
if (ItemData.itemStackable[c.bankItems[fromSlot] - 1]) {
if (c.bankItemsN[fromSlot] > amount) {
if (addItem(c.bankItems[fromSlot] - 1, amount)) {
c.bankItemsN[fromSlot] -= amount;
@@ -2186,7 +2186,7 @@ public class ItemAssistant {
}
public boolean isStackable(int itemID) {
return Item.itemStackable[itemID];
return ItemData.itemStackable[itemID];
}
/**
@@ -0,0 +1,376 @@
package com.rebotted.game.items;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import com.rebotted.GameConstants;
import com.rebotted.GameEngine;
public class ItemData {
public static int capes[] = { 2731, 2677, 2683, 2680, 2701, 2686, 2689,
2692, 2737, 2734, 2716, 2728, 2695, 2713, 2725, 2722, 2707, 2704,
2710, 2719, 2737, 2698, 14590, 2701, 8102, 8075, 8044, 8045, 8042,
8043, 8037, 8038, 8025, 8026, 8018, 7858, 7994, 7983, 7984, 7985,
7986, 7987, 7982, 7978, 3781, 3783, 3785, 3787, 3789, 3777, 3779,
3759, 3761, 3763, 3765, 6111, 6570, 6568, 1007, 1019, 1021, 1023,
1027, 1029, 1031, 1052, 2412, 2413, 2414, 4304, 4315, 4317, 4319,
4321, 4323, 4325, 4327, 4329, 4331, 4333, 4335, 4337, 4339, 4341,
4343, 4345, 4347, 4349, 4351, 4353, 4355, 4357, 4359, 4361, 4363,
4365, 4367, 4369, 4371, 4373, 4375, 4377, 4379, 4381, 4383, 4385,
4387, 4389, 4391, 4393, 4395, 4397, 4399, 4401, 4403, 4405, 4407,
4409, 4411, 4413, 4514, 4516, 6070, 6568, 6570, 4304, 3759, 3761,
3763, 3765, 3777, 3779, 3781, 3783, 3785, 3787, 3789 };
public static int boots[] = { 7596, 8029, 6619, 8017, 7159, 7991, 6666,
6061, 6106, 88, 89, 626, 628, 630, 632, 634, 1061, 1837, 1846,
2577, 2579, 2894, 2904, 2914, 2924, 2934, 3061, 3105, 3107, 3791,
4097, 4107, 4117, 4119, 4121, 4123, 4125, 4127, 4129, 4131, 4310,
5064, 5345, 5557, 6069, 6106, 6143, 6145, 6147, 6328, 6920, 6349,
6357, 3393 };
public static int gloves[] = { 7595, 6629, 8021, 8016, 7964, 2491, 1065,
2487, 2489, 3060, 1495, 775, 777, 778, 6708, 1059, 1063, 1065,
1580, 2487, 2489, 2491, 2902, 2912, 2922, 2932, 2942, 3060, 3799,
4095, 4105, 4115, 4308, 5556, 6068, 6110, 6149, 6151, 6153, 6922,
7454, 7455, 7456, 7457, 7458, 7459, 7460, 7461, 7462, 6330, 3391,
776 };
public static int shields[] = { 7676, 7342, 7348, 7354, 7360, 7334, 7340,
7347, 7352, 7358, 7356, 7350, 7344, 8087, 8058, 8059, 8060, 8061,
8062, 8063, 6633, 7977, 7976, 7972, 7959, 6591, 7332, 7338, 7336,
7360, 1171, 1173, 1175, 1177, 1179, 1181, 1183, 1185, 1187, 1189,
1191, 1193, 1195, 1197, 1199, 1201, 1540, 2589, 2597, 2603, 2611,
2621, 2629, 2659, 2667, 2675, 2890, 3122, 3488, 3758, 3839, 3840,
3841, 3842, 3843, 3844, 4072, 4156, 4224, 4225, 4226, 4227, 4228,
4229, 4230, 4231, 4232, 4233, 4234, 4302, 4507, 4512, 6215, 6217,
6219, 6221, 6223, 6225, 6227, 6229, 6231, 6233, 6235, 6237, 6239,
6241, 6243, 6245, 6247, 6249, 6251, 6253, 6255, 6257, 6259, 6261,
6263, 6265, 6267, 6269, 6271, 6273, 6275, 6277, 6279, 6524, 6889,
7051, 7053 };
public static int hats[] = { 2679, 1025, 2685, 4166, 2682, 2703, 2688,
2691, 2691, 2733, 2736, 2718, 2730, 2697, 2715, 2727, 2724, 2709,
2706, 2712, 2721, 2739, 2700, 2518, 2524, 2526, 7319, 7321, 7323,
7325, 7327, 1167, 8077, 8076, 8074, 4168, 1169, 8034, 8035, 8036,
8030, 6623, 8024, 8023, 8022, 8013, 1169, 7594, 7995, 7996, 7997,
7998, 7999, 8000, 8001, 7992, 7990, 7975, 7973, 7971, 7967, 7963,
6665, 6665, 7321, 6886, 6547, 6548, 2645, 2647, 2649, 4856, 4857,
4858, 4859, 4880, 4881, 4882, 4883, 4904, 4905, 4906, 4907, 4928,
4929, 4930, 4931, 4952, 4953, 4954, 4955, 4976, 4977, 4978, 4979,
4732, 4753, 4611, 6188, 6182, 4511, 4056, 4071, 4724, 2639, 2641,
2643, 2665, 6109, 5525, 5527, 5529, 5531, 5533, 5535, 5537, 5539,
5541, 5543, 5545, 5547, 5549, 5551, 74, 579, 656, 658, 660, 662,
664, 740, 1017, 1037, 1040, 1042, 1044, 1046, 1038, 1048, 1050,
1053, 1055, 1057, 1137, 1139, 1141, 1143, 1145, 1147, 1149, 1151,
1153, 1155, 1157, 1159, 1161, 1163, 1165, 1506, 1949, 2422, 2581,
2587, 2595, 2605, 2613, 2619, 2627, 2631, 2633, 2635, 2637, 2651,
2657, 2673, 2900, 2910, 2920, 2930, 2940, 2978, 2979, 2980, 2981,
2982, 2983, 2984, 2985, 2986, 2987, 2988, 2989, 2990, 2991, 2992,
2993, 2994, 2995, 3057, 3385, 3486, 3748, 3749, 3751, 3753, 3797,
4041, 4042, 4071, 4089, 3755, 4099, 4109, 4164, 4302, 4506, 4511,
4513, 4515, 4551, 4567, 4708, 4716, 4724, 4745, 4753, 4857, 4858,
4859, 4880, 4881, 4882, 4883, 4904, 4905, 4906, 4907, 4952, 4953,
4954, 4955, 4976, 4977, 4978, 4979, 5013, 5014, 5554, 5574, 6109,
6128, 6131, 6137, 6182, 6188, 6335, 6337, 6339, 6345, 6355, 6365,
6375, 6382, 6392, 6400, 6918, 6656, 2581, 7539, 7394, 7396, 7534,
5574, 6885, 6858, 6860, 6862, 6856, 6326, 6128, 6137, 7400, 7323,
7325, 7327, 7003, 4168, 7112, 7124, 7130, 7136 };
public static int amulets[] = { 1654, 1656, 1658, 1660, 1662, 1664, 8081,
8033, 7968, 6585, 86, 87, 295, 421, 552, 589, 1478, 1692, 1694,
1696, 1698, 1700, 1702, 1704, 1706, 1708, 1710, 1712, 1725, 1727,
1729, 1731, 4021, 4081, 4250, 4677, 6040, 6041, 6208, 1718, 1722,
6859, 6863, 6857, 3853, 3855, 3857, 3859, 3861, 3863, 3865, 3867,
1718, 4306, 1702 };
public static int arrows[] = { 11212, 8052, 9211, 9010, 9209, 9208, 9207,
9206, 9205, 9203, 9301, 8065, 7919, 7906, 7988, 7989, 78, 598, 877,
878, 879, 880, 881, 882, 883, 884, 885, 886, 887, 888, 889, 890,
891, 892, 893, 942, 2532, 2533, 2534, 2535, 2536, 2537, 2538, 2539,
2540, 2541, 2866, 4160, 4172, 4173, 4174, 4175, 4740, 5616, 5617,
5618, 5619, 5620, 5621, 5622, 5623, 5624, 5625, 5626, 5627, 6061,
6062};
public static int rings[] = { 8082, 773, 1635, 1637, 1639, 1641, 1643,
1645, 2550, 2552, 2554, 2556, 2558, 2560, 2562, 2564, 2566, 2568,
2570, 2572, 4202, 4657, 6465, 6737, 6731, 6735, 6583, 6733 };
public static int body[] = { 7608, 2520, 430, 7362, 7364, 636, 638, 640,
642, 644, 8064, 426, 430, 1005, 1757, 7592, 8031, 8027, 6617, 8019,
8014, 8002, 7376, 544, 7372, 7370, 577, 7974, 7970, 7965, 7961,
7960, 3793, 3775, 3773, 3771, 3769, 3767, 6139, 1135, 2499, 2501,
1035, 540, 5553, 4757, 1833, 6388, 6384, 4111, 4101, 4091, 6186,
6184, 6180, 3058, 4509, 4504, 4069, 4728, 4736, 4712, 6107, 2661,
3140, 1101, 1103, 1105, 1107, 1109, 1111, 1113, 1115, 1117, 1119,
1121, 1123, 1125, 1127, 1129, 1131, 1133, 2583, 2591, 2599, 2607,
2615, 2623, 2653, 2669, 3481, 4712, 4720, 4728, 4749, 4892, 4893,
4894, 4895, 4916, 4917, 4918, 4919, 4964, 4965, 4966, 4967, 6107,
6133, 6322, 6322, 6129, 75, 6916, 6916, 4111, 6654, 6654, 75, 7399, 7374, 5575, 2503, 6341, 6351, 3387, 5030, 5032, 5034, 5030,
5032, 5034,7390 , 7392, 546, 581 };
public static int legs[] = { 7609, 2522, 7378, 7380, 7382, 7368, 7366,
7388, 646, 648, 650, 652, 654, 428, 1097, 1095, 7593, 8032, 8028,
6625, 8020, 8015, 7384, 7969, 7966, 7962, 6141, 538, 1033, 5555,
4759, 6386, 6390, 2497, 2495, 2493, 1099, 4113, 4103, 4093, 6924,
6187, 6185, 6181, 3059, 4510, 4505, 4070, 6108, 542, 548, 1011,
1013, 1015, 1067, 1069, 1071, 1073, 1075, 1077, 1079, 1081, 1083,
1085, 1087, 1089, 1091, 1093, 2585, 2593, 2601, 2609, 2617, 2625,
2655, 2663, 2671, 3059, 3389, 3472, 3473, 3474, 3475, 3476, 3477,
3478, 3479, 3480, 3483, 3485, 3795, 4087, 4585, 4712, 4714, 4722,
4730, 4738, 4751, 4759, 4874, 4875, 4876, 4877, 4898, 4899, 4900,
4901, 4922, 4923, 4924, 4925, 4946, 4947, 4948, 4949, 4970, 4971,
4972, 4973, 4994, 4995, 4996, 4997, 5048, 5050, 5052, 5576, 6107,
6130, 6187, 6390, 6386, 6390, 6394, 6396, 6402, 6404, 6135, 6809, 6916, 4091,
4111, 6655, 6654, 7398, 7398, 7386, 6324, 6343, 6353, 6363, 6373, 3387, 5036,
5038, 5040, 5042, 5044, 5046, 5050, 5052, 4300, 1835, 7116, 7126, 6752,
7132, 7138 };
public static int platebody[] = { 10338, 7608, 2520, 430, 636, 638, 640,
642, 644, 426, 430, 8031, 8027, 6617, 8019, 8014, 8002, 544, 577,
7974, 7970, 7965, 7961, 7960, 3793, 3773, 3775, 3771, 3769, 3767,
6139, 1035, 540, 5553, 4757, 1833, 1835, 6388, 6384, 4111, 4101,
4868, 4869, 4870, 4871, 4892, 4893, 4894, 4895, 4916, 4917, 4918,
4919, 4940, 4941, 4942, 4943, 4964, 4965, 4966, 4967, 4988, 4989,
4990, 0x2f9a0eb, 6186, 6184, 6180, 3058, 4509, 4504, 4069, 4728,
4736, 4712, 6107, 2661, 3140, 1115, 1117, 1119, 1121, 1123, 1125,
1127, 2583, 2591, 2599, 2607, 2615, 6322, 2623, 2653, 2669, 3481,
4720, 4728, 4749, 2661, 6129, 6916, 4091, 6654, 6133, 75, 7399, 5575, 6341, 6351, 7390, 7392, 3387, 5024, 5030, 5032, 5034, 7392, 6786, 6788 };
/* Fullbody is an item that covers your arms. */
private static String[] fullbody = {
"top", "shirt", "platebody", "Wizard robe (g)", "Wizard robe (t)",
"Ahrims robetop", "Karils leathertop", "brassard", "Robe top",
"robetop", "platebody (t)", "platebody (g)", "chestplate", "torso",
"hauberk", "Dragon chainbody", "gown", "Shade robe", "Wizard robe",
"Druid's robe", "Black robe", "Fremennik robe", "Robe of elidinis",
"tunic", "blouse", "Wizard robe(g)", "Wizard robe(t)"
};
/* Fullhat covers your head but not your beard. */
private static String[] fullhat = { "med helm", "coif", "Dharok's helm",
"hood", "Initiate helm", "Coif", "Helm of neitiznot",
"Armadyl helmet", "Berserker helm", "Archer helm", "Farseer helm",
"Warrior helm", "Void"};
/* Fullmask covers your entire head. */
private static String[] fullmask = { "full helm(t)", "full helm(g)", "full helm", "mask", "Verac's helm",
"Guthan's helm", "Karil's coif", "mask", "Torag's helm", "Void", "helmet",
"sallet", "Facemask", "Bearhead"};
public static boolean isFullBody(int itemId) {
String weapon = getItemName(itemId);
if (weapon == null) {
return false;
}
for (String element : fullbody) {
if (weapon.endsWith(element)) {
return true;
}
}
return false;
}
public static boolean isFullHelm(int itemId) {
String weapon = getItemName(itemId);
if (weapon == null) {
return false;
}
for (String element : fullhat) {
if (weapon.endsWith(element)) {
return true;
}
}
return false;
}
public static boolean isFullMask(int itemId) {
String weapon = getItemName(itemId);
if (weapon == null) {
return false;
}
for (String element : fullmask) {
if (weapon.endsWith(element)) {
return true;
}
}
return false;
}
public static String getItemName(int id) {
for (ItemList element : GameEngine.itemHandler.ItemList) {
if (element != null) {
if (element.itemId == id) {
return element.itemName;
}
}
}
return null;
}
public static boolean[] itemStackable = new boolean[GameConstants.ITEM_LIMIT];
public static boolean[] itemIsNote = new boolean[GameConstants.ITEM_LIMIT];
public static int[] targetSlots = new int[GameConstants.ITEM_LIMIT];
static {
int counter = 0;
int c;
try {
FileInputStream dataIn = new FileInputStream(new File("./data/data/stackable.dat"));
while ((c = dataIn.read()) != -1) {
if (c == 0) {
itemStackable[counter] = false;
itemStackable[291] = true;
} else {
itemStackable[counter] = true;
}
counter++;
}
dataIn.close();
} catch (IOException e) {
System.out.println("Critical error while loading stackabledata! Trace:");
e.printStackTrace();
}
counter = 0;
try {
FileInputStream dataIn = new FileInputStream(new File("./data/data/notes.dat"));
while ((c = dataIn.read()) != -1) {
itemIsNote[counter] = c == 0;
counter++;
}
dataIn.close();
} catch (IOException e) {
System.out.println("Critical error while loading notedata! Trace:");
e.printStackTrace();
}
counter = 0;
try {
FileInputStream dataIn = new FileInputStream(new File("./data/data/equipment.dat"));
while ((c = dataIn.read()) != -1) {
int slot;
// rebind item equip slot here
switch (counter) {
// Legs
case 6181:
case 428:
case 538:
case 6343:
case 6353:
case 6363:
case 6396:
case 6373:
case 6404:
case 5044:
case 5046:
case 5050:
case 5052:
case 5040:
case 5038:
case 6752:
case 5048:
case 5036:
case 5042:
case 4300:
case 1835:
case 7116:
case 7126:
case 7132:
case 7138:
case 548:
case 6185:
slot = GameConstants.LEGS;
break;
// Hats
case 4166:
case 1167:
case 5525:
case 4168:
case 4502:
case 1037:
case 1025:
case 7112:
case 7124:
case 7130:
case 7136:
case 4611:
case 5527:
case 5529:
case 5531:
case 5533:
case 5535:
case 5537:
case 5539:
case 5541:
case 5543:
case 5545:
case 5547:
slot = GameConstants.HAT;
break;
// Cape
case 4304:
case 3759:
case 3761:
case 3763:
case 3765:
case 3777:
case 3779:
case 3781:
case 3783:
case 3785:
case 3787:
case 3789:
case 4514:
case 4516:
slot = GameConstants.CAPE;
break;
// Shield
case 7051:
case 7053:
slot = GameConstants.SHIELD;
break;
// Chest
case 577:
case 426:
case 540:
case 430:
case 6786:
case 581:
case 5024:
case 5030:
case 1757:
case 5034:
case 5032:
case 3793:
case 1005:
case 546:
case 6402:
case 6788:
case 6184:
case 7390:
case 7392:
case 6186:
slot = GameConstants.CHEST;
break;
// Amulet
case 3853:
case 3855:
case 3857:
case 3859:
case 3861:
case 3863:
case 1718:
case 3865:
case 4306:
case 3867:
case 1702:
slot = GameConstants.AMULET;
break;
// Hands
case 776:
slot = GameConstants.HANDS;
break;
default:
slot = c;
}
targetSlots[counter] = slot;
counter++;
}
dataIn.close();
} catch (IOException e) {
System.out.println("Critical error while loading equipment data! Trace:");
e.printStackTrace();
}
}
}
@@ -1,10 +1,12 @@
package com.rebotted.game.items;
import com.rebotted.game.content.skills.cooking.Cooking;
import com.rebotted.game.content.skills.crafting.BattleStaffs;
import com.rebotted.game.content.skills.crafting.GemCutting;
import com.rebotted.game.content.skills.crafting.JewelryMaking;
import com.rebotted.game.content.skills.crafting.LeatherMaking;
import com.rebotted.game.content.skills.crafting.SoftClay;
import com.rebotted.game.content.skills.farming.Farming;
import com.rebotted.game.content.skills.firemaking.Firemaking;
import com.rebotted.game.content.skills.fletching.ArrowMaking;
import com.rebotted.game.content.skills.fletching.LogCutting;
@@ -47,6 +49,9 @@ public class UseItem {
if (itemId == Ectofuntus.BUCKET) {
Ectofuntus.fillBucketWithSlime(c, objectID);
}
if (Farming.prepareCrop(c, itemId, objectID, objectX, objectY)) {
return;
}
for (final EctofuntusData ectofuntus : EctofuntusData.values()) {
if (itemId == ectofuntus.getBoneId()) {
Ectofuntus.boneOnLoader(c, objectID, itemId);
@@ -124,6 +129,7 @@ public class UseItem {
&& ItemAssistant.getItemName(useWith).contains("(")) {
player.getPotMixing().mixPotion2(itemUsed, useWith);
}
BattleStaffs.makeBattleStaff(player, itemUsed, useWith);
GrindingAction.init(player, itemUsed, useWith);
CapeDye.dyeItem(player, itemUsed, useWith);
GodPages.itemOnItemHandle(player, useWith, itemUsed);
@@ -1,6 +1,6 @@
package com.rebotted.game.items.impl;
import com.rebotted.game.items.Item;
import com.rebotted.game.items.ItemData;
import com.rebotted.game.items.ItemAssistant;
import com.rebotted.game.players.Player;
@@ -47,10 +47,10 @@ public enum CapeDye {
};
public static boolean blockDye(Player player, CapeDye dye, int itemUsed, int useWith) {
if (itemUsed == dye.getItemUsed() && ItemAssistant.getItemName(useWith).equalsIgnoreCase("Cape") && Item.itemIsNote[useWith]) {
if (itemUsed == dye.getItemUsed() && ItemAssistant.getItemName(useWith).equalsIgnoreCase("Cape") && ItemData.itemIsNote[useWith]) {
player.getPacketSender().sendMessage("You can't dye a noted cape.");
return true;
} else if (itemUsed == dye.getItemUsed() && ItemAssistant.getItemName(useWith).equalsIgnoreCase("Cape") && useWith == dye.getReward() && !Item.itemIsNote[useWith]) {
} else if (itemUsed == dye.getItemUsed() && ItemAssistant.getItemName(useWith).equalsIgnoreCase("Cape") && useWith == dye.getReward() && !ItemData.itemIsNote[useWith]) {
player.getPacketSender().sendMessage("That cape is already that color.");
return true;
} else if (itemUsed == dye.getItemUsed() && !ItemAssistant.getItemName(useWith).equalsIgnoreCase("Cape")) {
@@ -64,7 +64,7 @@ public enum CapeDye {
if (blockDye(player, cape, itemUsed, useWith)) {
return;
}
if (itemUsed == cape.getItemUsed() && ItemAssistant.getItemName(useWith).equalsIgnoreCase("Cape") && !Item.itemIsNote[useWith] && useWith != cape.getReward()) {
if (itemUsed == cape.getItemUsed() && ItemAssistant.getItemName(useWith).equalsIgnoreCase("Cape") && !ItemData.itemIsNote[useWith] && useWith != cape.getReward()) {
player.getItemAssistant().deleteItem(itemUsed, 1);
player.getItemAssistant().deleteItem(useWith, 1);
player.getItemAssistant().addItem(cape.getReward(), 1);
@@ -0,0 +1,127 @@
package com.rebotted.game.items.impl;
import java.util.HashMap;
import java.util.Map;
import com.rebotted.event.CycleEvent;
import com.rebotted.event.CycleEventContainer;
import com.rebotted.event.CycleEventHandler;
import com.rebotted.game.players.Player;
/**
* Handles the preaching of god books
* @author Final Project
*
*/
public enum GodBooks {
HOLY_BOOK(3840, new String[][] {
{"9178", "In the name of Saradomin,", "Protector of us all,", "I now join you in the eyes of Saradomin.", null},
{"9179", "Thy cause was false, thy skills did lack.", "See you in lumbridge when you get back", null},
{"9180", "Go in peace in the name of Saradomin,", "May his glory shine upon you like the sun.", null},
{"9181", "Walk proud, and show mercy,", "For you carry my name in your heart,", "This is Saradomin's wisdom.", null}
}),
BOOK_OF_BALANCE(3844, new String[][] {
{"9178", "Light and dark, day and night,", "Balance arises from contrast.", "I unify thee in the name of Guthix.", null},
{"9179", "Thy death was not in vain,", "For it brought some balance to the world.", "May Guthix bring you rest.", null},
{"9180", "May you walk the path and never fall,", "For guthix walks beside thee on thy journey.", "May Guthix bring you peace.", null},
{"9181", "A Journey of a single step,", "May take thee over a thousand miles.", "May Guthix bring you balance.", null}
}),
UNHOLY_BOOK(3842, new String[][] {
{"9178", "Two great warriors, joined by hand,", "to spread destruction across the land.", "In Zamorak's name, now two are one.", null},
{"9179", "The weak deserve to die,", "So that the strong may flourish.", "This is the creed of Zamorak.", null},
{"9180", "May your bloodthirst be never sated,", "and may all your battles be glorious.", "Zamorak bring you strength", null},
{"9181", "There is no opinion that cannot be proven true,", "by crushing those who choose to disagree with it.", "Zamorak give me strength!", null}
});
private int itemId;
private String[][] preachData;
private GodBooks(int itemId, String[][] preachData) {
this.itemId = itemId;
this.preachData = preachData;
}
private static Map<Integer, GodBooks> godBooks = new HashMap<Integer, GodBooks>();
static {
for (final GodBooks type : values()) {
godBooks.put(type.itemId, type);
}
}
/**
* Sends the options dialogue with preach options
* @param player
* the player to send the options to
* @param itemId
* the item the player's interacting with
*/
public static void sendPreachOptions(Player player, int itemId) {
player.preaching = true;
switch (itemId) {
case 3840:
player.getDialogueHandler().sendOption("Partnership", "Blessing","Last Rights", "Preach");
player.dialogueAction = 3840;
break;
case 3842:
case 3844:
player.getDialogueHandler().sendOption("Wedding Ceremony", "Blessing", "Last Rights", "Preach");
player.dialogueAction = 3842;
break;
}
}
/**
* Handles the preaching action
* @param player
* the player preaching
* @param itemId
* the item the player's interacting with
* @param actionButtonId
* the button id the player's interacting with
*/
public static void handlePreach(Player player, int itemId, int actionButtonId) {
player.getPacketSender().closeAllWindows();
GodBooks books = godBooks.get(itemId);
if (player.specAmount < 2.5) {
player.getPacketSender().sendMessage("You need at least 25% of special attack to preach!");
return;
}
if (itemId == books.itemId) {
player.specAmount -= 2.5;
player.getItemAssistant().updateSpecialBar();
CycleEventHandler.getSingleton().addEvent(player, new CycleEvent() {
private int currentQuote = 1;
@Override
public void execute(CycleEventContainer container) {
for (int preaches = 0; preaches < books.preachData.length; preaches++) {
if (actionButtonId == Integer.parseInt(books.preachData[preaches][0])) {
if (books.preachData[preaches][currentQuote] == null) {
container.stop();
return;
}
if (books.preachData[preaches][currentQuote] != null) {
player.startAnimation(1670);
player.forcedChat(books.preachData[preaches][currentQuote]);
currentQuote++;
}
break;
}
}
}
@Override
public void stop() {
currentQuote = 1;
player.preaching = false;
}
}, 1);
}
}
}
@@ -38,6 +38,28 @@ public class NpcActions {
}
}
switch (npcType) {
case 2324 :
case 2323 :
case 2326 :
case 2325 :
case 2337 :
case 2336 :
case 2335 :
case 2338 :
case 2334 :
case 2332 :
case 2333 :
case 2327 :
case 2343 :
case 2331 :
case 2344 :
case 2330 :
case 2340 :
case 2339 :
case 2341 :
case 2342 :
c.getDialogueHandler().sendDialogues(3530, npcType);
break;
case 209:
c.getDialogueHandler().sendDialogues(3500, 209);
break;
@@ -981,7 +1003,10 @@ public class NpcActions {
}
}
switch (npcType) {
case 3021 :
c.getFarmingTools().loadInterfaces();
break;
case 3:
c.getDialogueHandler().sendDialogues(5, npcType);
break;
@@ -479,8 +479,41 @@ public class NpcHandler {
if (npcs[i].npcType == 3782 && PestControl.gameStarted) {
if (Misc.random(10) == 4) {
npcs[i].forceChat(voidKnightTalk[Misc
.random3(voidKnightTalk.length)]);
npcs[i].forceChat(voidKnightTalk[Misc.random3(voidKnightTalk.length)]);
}
}
if (npcs[i].npcType == 162) {
if (npcs[i].getX() == 2475 && npcs[i].getY() == 3438) {
npcs[i].forceChat("Okay get over that log, quick quick!");
} else if (npcs[i].getX() == 2471 && npcs[i].getY() == 3427) {
npcs[i].forceChat("Move it, move it, move it!");
} else if (npcs[i].getX() == 2476 && npcs[i].getY() == 3423) {
npcs[i].forceChat("That's it - straight up");
} else if (npcs[i].getX() == 2475 && npcs[i].getY() == 3421) {
if (Misc.random(1) == 0) {
npcs[i].forceChat("Terrorbirds could climb faster than that!");
} else {
npcs[i].forceChat("Come on scaredy cat, get across that rope!");
}
} else if (npcs[i].getX() == 2481 && npcs[i].getY() == 3424) {
npcs[i].forceChat("My Granny can move faster than you.");
}
}
if (npcs[i].npcType == 43) {
if (Misc.random(20) == 4) {
npcs[i].forceChat("Baa!");
}
}
if (npcs[i].npcType == 81 || npcs[i].npcType == 397 || npcs[i].npcType == 1766 || npcs[i].npcType == 1767 || npcs[i].npcType == 1768) {
if (Misc.random(30) == 4) {
npcs[i].forceChat("Moo");
}
}
if (npcs[i].npcType == 45) {
if (Misc.random(30) == 6) {
npcs[i].forceChat("Quack!");
}
}
@@ -61,6 +61,10 @@ public class ObjectsActions {
player.faceUpdate(0);
player.clickObjectType = 0;
player.turnPlayerTo(objectX, objectY);
player.getCompost().handleObjectClick(objectType, objectX, objectY);
if (Farming.harvest(player, objectX, objectY)) {
return;
}
if (Webs.webs(player, objectType)) {
Webs.slashWeb(player, objectType, objectX, objectY);
return;
@@ -2567,6 +2571,9 @@ public class ObjectsActions {
Stalls.attemptStall(player, objectType, obX, obY);
return;
}
if (Farming.inspectObject(player, obX, obY)) {
return;
}
switch (objectType) {
case 6:
player.getCannon().loadCannon(obX, obY);
@@ -2870,8 +2877,6 @@ public class ObjectsActions {
if (!Region.objectExists(objectType, obX, obY, player.heightLevel)) {
return;
}
Farming.openGuide(player, player.objectId);
// switch (objectType) {
// }
Farming.guide(player, obX, obY);
}
}
@@ -44,6 +44,18 @@ import com.rebotted.game.content.skills.agility.WildernessAgility;
import com.rebotted.game.content.skills.cooking.Potatoes;
import com.rebotted.game.content.skills.core.Mining;
import com.rebotted.game.content.skills.crafting.GlassBlowing;
import com.rebotted.game.content.skills.farming.Allotments;
import com.rebotted.game.content.skills.farming.Bushes;
import com.rebotted.game.content.skills.farming.Compost;
import com.rebotted.game.content.skills.farming.Flowers;
import com.rebotted.game.content.skills.farming.FruitTree;
import com.rebotted.game.content.skills.farming.Herbs;
import com.rebotted.game.content.skills.farming.Hops;
import com.rebotted.game.content.skills.farming.Seedling;
import com.rebotted.game.content.skills.farming.SpecialPlantOne;
import com.rebotted.game.content.skills.farming.SpecialPlantTwo;
import com.rebotted.game.content.skills.farming.ToolLeprechaun;
import com.rebotted.game.content.skills.farming.WoodTrees;
import com.rebotted.game.content.skills.fletching.LogCuttingInterface;
import com.rebotted.game.content.skills.runecrafting.Runecrafting;
import com.rebotted.game.content.skills.slayer.Slayer;
@@ -56,7 +68,8 @@ import com.rebotted.game.globalworldobjects.DoubleGates;
import com.rebotted.game.globalworldobjects.GateHandler;
import com.rebotted.game.globalworldobjects.SingleGates;
import com.rebotted.game.items.GameItem;
import com.rebotted.game.items.Item;
import com.rebotted.game.items.Inventory;
import com.rebotted.game.items.ItemData;
import com.rebotted.game.items.ItemAssistant;
import com.rebotted.game.items.impl.PotionMixing;
import com.rebotted.game.items.impl.Teles;
@@ -80,6 +93,18 @@ import com.rebotted.world.ObjectManager;
public abstract class Player {
public byte buffer[] = null;
private Compost compost = new Compost(this);
private Allotments allotment = new Allotments(this);
private Flowers flower = new Flowers(this);
private Herbs herb = new Herbs(this);
private Hops hops = new Hops(this);
private Bushes bushes = new Bushes(this);
private Seedling seedling = new Seedling(this);
private WoodTrees trees = new WoodTrees(this);
private FruitTree fruitTrees = new FruitTree(this);
private SpecialPlantOne specialPlantOne = new SpecialPlantOne(this);
private SpecialPlantTwo specialPlantTwo = new SpecialPlantTwo(this);
private ToolLeprechaun toolLeprechaun = new ToolLeprechaun(this);
public Stream inStream = null, outStream = null;
public IoSession session;
private final ItemAssistant itemAssistant = new ItemAssistant(this);
@@ -135,6 +160,65 @@ public abstract class Player {
private SingleGates singleGates = new SingleGates();
private DoubleGates doubleGates = new DoubleGates();
public int lastMainFrameInterface = -1; //Possibly used in future to prevent packet exploits
public boolean isPreaching() {
return preaching;
}
public void setPreaching(boolean preaching) {
this.preaching = preaching;
}
public boolean preaching = false;
public Compost getCompost() {
return compost;
}
public Allotments getAllotment() {
return allotment;
}
public Flowers getFlowers() {
return flower;
}
public Herbs getHerbs() {
return herb;
}
public Hops getHops() {
return hops;
}
public Bushes getBushes() {
return bushes;
}
public Seedling getSeedling() {
return seedling;
}
public WoodTrees getTrees() {
return trees;
}
public FruitTree getFruitTrees() {
return fruitTrees;
}
public SpecialPlantOne getSpecialPlantOne() {
return specialPlantOne;
}
public SpecialPlantTwo getSpecialPlantTwo() {
return specialPlantTwo;
}
public ToolLeprechaun getFarmingTools() {
return toolLeprechaun;
}
public LogCuttingInterface getFletching() {
return fletching;
@@ -351,8 +435,31 @@ public abstract class Player {
public Food getFood() {
return food;
}
public Inventory getInventory() {
return inventory;
}
private Inventory inventory = new Inventory(this);
private int tempInteger;
public boolean tempBoolean = false;
public void setTempInteger(int tempInteger) {
this.tempInteger = tempInteger;
}
public int getTempInteger() {
return tempInteger;
}
public int totalShopItems;
public boolean stopPlayer(boolean stop) {
return (stop ? stopPlayerPacket == true : stopPlayerPacket == false);
}
public boolean isSnowy;
@@ -1265,7 +1372,7 @@ public abstract class Player {
followId, skullTimer, nextChat = 0, talkingNpc = -1,
dialogueAction = 0, autocastId, followDistance, followId2,
barrageCount = 0, delayedDamage = 0, delayedDamage2 = 0,
pcPoints = 0, magePoints = 0, desertTreasure = 0,
pcPoints = 0, magePoints = 0, desertTreasure = 0, skillAmount,
lastArrowUsed = -1, autoRet = 1, pcDamage = 0, xInterfaceId = 0,
xRemoveId = 0, xRemoveSlot = 0, tzhaarToKill = 0, tzhaarKilled = 0,
waveId, frozenBy = 0, poisonDamage = 0, teleAction = 0,
@@ -2541,7 +2648,7 @@ public abstract class Player {
playerProps.writeByte(0);
}
if (!Item.isFullBody(playerEquipment[playerChest])) {
if (!ItemData.isFullBody(playerEquipment[playerChest])) {
playerProps.writeWord(0x100 + playerAppearance[3]);
} else {
playerProps.writeByte(0);
@@ -2553,8 +2660,8 @@ public abstract class Player {
playerProps.writeWord(0x100 + playerAppearance[5]);
}
if (!Item.isFullHelm(playerEquipment[playerHat])
&& !Item.isFullMask(playerEquipment[playerHat])) {
if (!ItemData.isFullHelm(playerEquipment[playerHat])
&& !ItemData.isFullMask(playerEquipment[playerHat])) {
playerProps.writeWord(0x100 + playerAppearance[1]);
} else {
playerProps.writeByte(0);
@@ -2573,7 +2680,7 @@ public abstract class Player {
}
if (playerAppearance[0] != 1
&& !Item.isFullMask(playerEquipment[playerHat])) {
&& !ItemData.isFullMask(playerEquipment[playerHat])) {
playerProps.writeWord(0x100 + playerAppearance[7]);
} else {
playerProps.writeByte(0);
@@ -9,7 +9,7 @@ import com.rebotted.event.CycleEventContainer;
import com.rebotted.event.CycleEventHandler;
import com.rebotted.game.content.minigames.castlewars.CastleWars;
import com.rebotted.game.items.GameItem;
import com.rebotted.game.items.Item;
import com.rebotted.game.items.ItemData;
import com.rebotted.game.items.ItemAssistant;
import com.rebotted.util.GameLogger;
import com.rebotted.util.Misc;
@@ -149,7 +149,7 @@ public class Trading {
}
player.tradeConfirmed = false;
o.tradeConfirmed = false;
if (!Item.itemStackable[itemID]) {
if (!ItemData.itemStackable[itemID]) {
for (int a = 0; a < amount; a++) {
for (GameItem item : offeredItems) {
if (item.id == itemID) {
@@ -274,7 +274,7 @@ public class Trading {
}
player.tradeConfirmed = false;
o.tradeConfirmed = false;
if (!Item.itemStackable[itemID] && !Item.itemIsNote[itemID]) {
if (!ItemData.itemStackable[itemID] && !ItemData.itemIsNote[itemID]) {
for (int a = 0; a < amount && a < 28; a++) {
if (player.getItemAssistant().playerHasItem(itemID, 1)) {
offeredItems.add(new GameItem(itemID, 1));
@@ -306,7 +306,7 @@ public class Trading {
declineTrade();
return false;
}
if (Item.itemStackable[itemID] || Item.itemIsNote[itemID]) {
if (ItemData.itemStackable[itemID] || ItemData.itemIsNote[itemID]) {
boolean inTrade = false;
for (GameItem item : offeredItems) {
if (item.id == itemID) {
@@ -2,7 +2,7 @@ package com.rebotted.game.shops;
import com.rebotted.GameConstants;
import com.rebotted.game.bots.BotHandler;
import com.rebotted.game.items.Item;
import com.rebotted.game.items.ItemData;
import com.rebotted.game.items.ItemAssistant;
import com.rebotted.game.items.ItemDefinition;
import com.rebotted.game.players.Player;
@@ -443,7 +443,7 @@ public class ShopAssistant {
if (amount <= 0) {
return false;
}
if (Item.itemIsNote[itemID]) {
if (ItemData.itemIsNote[itemID]) {
itemID = player.getItemAssistant().getUnnotedItem(itemID);
}
for (int i = 0; i < ShopHandler.shopItems[player.shopId].length; i++) {
@@ -8,6 +8,7 @@ import com.rebotted.game.content.combat.magic.MagicTeleports;
import com.rebotted.game.content.quests.QuestAssistant;
import com.rebotted.game.content.skills.SkillHandler;
import com.rebotted.game.content.skills.runecrafting.Tiaras;
import com.rebotted.game.items.Item;
import com.rebotted.game.items.ItemAssistant;
import com.rebotted.game.items.Weight;
import com.rebotted.game.items.impl.LightSources;
@@ -26,6 +27,31 @@ public class PacketSender {
this.player = player2;
}
public PacketSender sendUpdateItems(int frame, Item[] items) {
player.getOutStream().createFrameVarSizeWord(53);
player.getOutStream().writeWord(frame);
player.getOutStream().writeWord(items.length);
Item[] var6 = items;
for (int i = 0; i < items.length; i++) {
Item item = var6[i];
if (item == null) {
player.getOutStream().writeByte(0);
player.getOutStream().writeWordBigEndianA(0);
} else {
if (item.getCount() > 254) {
player.getOutStream().writeByte(255);
player.getOutStream().writeDWord_v2(item.getCount());
} else {
player.getOutStream().writeByte(item.getCount());
}
player.getOutStream().writeWordBigEndianA(item.getId());
}
}
return this;
}
public PacketSender loginPlayer() {
player.getPlayerAssistant().loginScreen();
if (Connection.isNamedBanned(player.playerName)) {
@@ -34,6 +34,7 @@ import com.rebotted.net.packets.impl.ItemOnObject;
import com.rebotted.net.packets.impl.ItemOnPlayer;
import com.rebotted.net.packets.impl.MagicOnFloorItems;
import com.rebotted.net.packets.impl.MagicOnItems;
import com.rebotted.net.packets.impl.MagicOnObject;
import com.rebotted.net.packets.impl.MoveItems;
import com.rebotted.net.packets.impl.PickupItem;
import com.rebotted.net.packets.impl.PrivateMessaging;
@@ -112,6 +113,7 @@ public class PacketHandler {
packetId[43] = new Bank10();
packetId[129] = new BankAll();
packetId[101] = new ChangeAppearance();
packetId[35] = new MagicOnObject();
PrivateMessaging pm = new PrivateMessaging();
packetId[188] = pm;
packetId[126] = pm;
@@ -2,7 +2,7 @@ package com.rebotted.net.packets.impl;
import com.rebotted.game.content.random.PartyRoom;
import com.rebotted.game.items.GameItem;
import com.rebotted.game.items.Item;
import com.rebotted.game.items.ItemData;
import com.rebotted.game.players.Player;
import com.rebotted.net.packets.PacketType;
@@ -61,7 +61,7 @@ public class BankAll implements PacketType {
"You can't store items while trading!");
return;
}
if (Item.itemStackable[removeId]) {
if (ItemData.itemStackable[removeId]) {
player.getItemAssistant().bankItem(player.playerItems[removeSlot],
removeSlot, player.playerItemsN[removeSlot]);
} else {
@@ -97,14 +97,14 @@ public class BankAll implements PacketType {
case 3322:
if (player.duelStatus <= 0) {
if (Item.itemStackable[removeId]) {
if (ItemData.itemStackable[removeId]) {
player.getTrading().tradeItem(removeId, removeSlot,
player.playerItemsN[removeSlot]);
} else {
player.getTrading().tradeItem(removeId, removeSlot, 28);
}
} else {
if (Item.itemStackable[removeId] || Item.itemIsNote[removeId]) {
if (ItemData.itemStackable[removeId] || ItemData.itemIsNote[removeId]) {
player.getDueling().stakeItem(removeId, removeSlot,
player.playerItemsN[removeSlot]);
} else {
@@ -115,7 +115,7 @@ public class BankAll implements PacketType {
case 3415:
if (player.duelStatus <= 0) {
if (Item.itemStackable[removeId]) {
if (ItemData.itemStackable[removeId]) {
for (GameItem item : player.getTrading().offeredItems) {
if (item.id == removeId) {
player.getTrading()
@@ -137,7 +137,7 @@ public class BankAll implements PacketType {
break;
case 6669:
if (Item.itemStackable[removeId] || Item.itemIsNote[removeId]) {
if (ItemData.itemStackable[removeId] || ItemData.itemIsNote[removeId]) {
for (GameItem item : player.getDueling().stakedItems) {
if (item.id == removeId) {
player.getDueling()
@@ -13,6 +13,7 @@ import com.rebotted.game.content.skills.woodcutting.BirdNest;
import com.rebotted.game.items.ItemAssistant;
import com.rebotted.game.items.impl.ExperienceLamp;
import com.rebotted.game.items.impl.Flowers;
import com.rebotted.game.items.impl.GodBooks;
import com.rebotted.game.players.Player;
import com.rebotted.net.packets.PacketType;
import com.rebotted.util.GameLogger;
@@ -35,6 +36,7 @@ public class ClickItem implements PacketType {
if(!player.getItemAssistant().playerHasItem(itemId, 1)) {
return;
}
GodBooks.sendPreachOptions(player, itemId);
if (itemId == 6) {
player.getCannon().placeCannon();
}
@@ -404,12 +404,9 @@ public class ClickObject implements PacketType {
if (p.playerRights == 3) {
p.getPacketSender().sendMessage("ObjectId: " + p.objectId + " ObjectX: " + p.objectX + " ObjectY: " + p.objectY + " Objectclick = 4, Xoff: " + (p.getX() - p.objectX) + " Yoff: " + (p.getY() - p.objectY));
}
p.getObjects().fourthClickObject(p.objectId, p.objectX, p.objectY);
break;
}
}
}
@@ -291,7 +291,11 @@ public class Commands implements PacketType {
player.getPacketSender().showInterface(8134);
break;
case "stuck":
player.getPlayerAssistant().startTeleport(SpellTeleport.LUMBRIDGE.getDestX(), SpellTeleport.LUMBRIDGE.getDestY(), 0, "modern");
if (player.getCombatAssistant().inCombat()) {
player.getPacketSender().sendMessage("You cannot do that while in combat.");
return;
}
player.getPlayerAssistant().movePlayer(SpellTeleport.LUMBRIDGE.getDestX(), SpellTeleport.LUMBRIDGE.getDestY(), 0);
player.getPacketSender().sendMessage("How did you manage that one...");
player.getPacketSender().sendMessage("If it's bug related, please report on Github/Discord!");
player.gfx100(80);
@@ -497,24 +501,6 @@ public class Commands implements PacketType {
}
public static void adminCommands(Player player, String playerCommand, String[] arguments) {
if (playerCommand.startsWith("getid")) {
String a[] = playerCommand.split(" ");
String itemName = "";
int itemCount = 0;
for (int i = 1; i < a.length; i++) {
itemName = itemName + a[i]+ " ";
}
itemName = itemName.substring(0, itemName.length()-1);
player.getPacketSender().sendMessage("Searching: " + itemName);
for (int j = 0; j < GameEngine.itemHandler.ItemList.length; j++) {
if (GameEngine.itemHandler.ItemList[j] != null)
if (GameEngine.itemHandler.ItemList[j].itemName.replace("_", " ").toLowerCase().contains(itemName.toLowerCase())) {
player.getPacketSender().sendMessage("@dre@" + GameEngine.itemHandler.ItemList[j].itemName.replace("_", " ") + " - " + GameEngine.itemHandler.ItemList[j].itemId);
itemCount++;
}
}
player.getPacketSender().sendMessage(itemCount + " IDs found...");
}
switch (playerCommand.toLowerCase()) {
case "clearbank":
player.getItemAssistant().clearBank();
@@ -28,6 +28,11 @@ public class ItemOnNpc implements PacketType {
}
player.faceNpc(i);
switch(npcId) {
case 3021:
if (player.getFarmingTools().noteItem(itemId)) {
return;
}
break;
case 43:
NpcHandler.npcs[i].shearSheep(player, 1735, 1737, 893, 43, 42, 50);
break;
@@ -198,14 +198,6 @@ public class ItemOnObject implements PacketType {
player.getPlayerAssistant().movePlayer(2510, 3096, 0);
}
/*
* if (itemId == 1779 && objectId == 2644) { int amount =
* (c.getItemAssistant().getItemCount(1777)); int[] spin = {1777}; for
* (int i : spin) { c.getItemAssistant().deleteItem(i,
* c.getItemAssistant().getItemCount(i)); } c.startAnimation(883);
* c.getItemAssistant().addItem(1777, amount); }
*/
if (Fillables.canFill(itemId, objectId) && player.getItemAssistant().playerHasItem(itemId)) {
int amount = player.getItemAssistant().getItemCount(itemId);
player.getItemAssistant().deleteItem(itemId, amount);
@@ -5,7 +5,7 @@ import com.rebotted.event.CycleEvent;
import com.rebotted.event.CycleEventContainer;
import com.rebotted.event.CycleEventHandler;
import com.rebotted.game.content.combat.magic.MagicData;
import com.rebotted.game.items.Item;
import com.rebotted.game.items.ItemData;
import com.rebotted.game.players.Player;
import com.rebotted.net.packets.PacketType;
@@ -35,9 +35,9 @@ public class MagicOnFloorItems implements PacketType {
if ((c.getItemAssistant().freeSlots() >= 1 || c.getItemAssistant()
.playerHasItem(itemId, 1))
&& Item.itemStackable[itemId]
&& ItemData.itemStackable[itemId]
|| c.getItemAssistant().freeSlots() > 0
&& !Item.itemStackable[itemId]) {
&& !ItemData.itemStackable[itemId]) {
if (c.goodDistance(c.getX(), c.getY(), itemX, itemY, 12)) {
c.walkingToItem = true;
int offY = (c.getX() - itemX) * -1;
@@ -0,0 +1,27 @@
package com.rebotted.net.packets.impl;
import com.rebotted.game.content.skills.crafting.OrbCharging;
import com.rebotted.game.players.Player;
import com.rebotted.net.packets.PacketType;
public class MagicOnObject implements PacketType {
@Override
public void processPacket(Player player, int packetType, int packetSize) {
int x = player.getInStream().readSignedWordBigEndian();
int magicId = player.getInStream().readUnsignedWord();
int y = player.getInStream().readUnsignedWordA();
int objectId = player.getInStream().readSignedWordBigEndian();
player.turnPlayerTo(x, y);
switch (objectId) {
case 2153:
case 2152:
case 2151:
case 2150:
OrbCharging.chargeOrbs(player, magicId, objectId);
break;
}
}
}
@@ -0,0 +1,59 @@
package com.rebotted.tick;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Queue;
/**
* A class which schedules the execution of {@link Tick}s.
*
* @author Graham
*/
public final class Scheduler {
/**
* A list of active ticks.
*/
private final List<Tick> ticks = new ArrayList<Tick>();
/**
* A queue of ticks that still need to be added.
*/
private final Queue<Tick> newTicks = new ArrayDeque<Tick>();
/**
* Schedules the specified tick.
*
* @param tick
* The tick to schedule.
*/
public void schedule(final Tick tick) {
synchronized (newTicks) {
newTicks.add(tick);
}
}
/**
* This method is called every cycle and executes, adds and removes
* {@link Tick}s.
*/
public void process() {
synchronized (newTicks) {
Tick tick;
while ((tick = newTicks.poll()) != null)
ticks.add(tick);
}
for (Iterator<Tick> it = ticks.iterator(); it.hasNext();) {
Tick tick = it.next();
try {
if (!tick.tick())
it.remove();
} catch (Throwable t) {
t.printStackTrace();
}
}
}
}
@@ -0,0 +1,151 @@
package com.rebotted.tick;
/**
* Represents a periodic task that can be scheduled with a {@link Scheduler}.
*
* @author Graham
*/
public abstract class Tick {
/**
* The number of cycles between consecutive executions of this task.
*/
private final int delay;
/**
* The current 'count down' value. When this reaches zero the task will be
* executed.
*/
private int countdown;
/**
* A flag which indicates if this task is still running.
*/
private boolean running = true;
/**
* Creates a new task with the specified delay.
*
* @param delay
* The number of cycles between consecutive executions of this
* task.
* @throws IllegalArgumentException
* if the {@code delay} is not positive.
*/
public Tick(int delay) {
checkDelay(delay);
this.delay = delay;
this.countdown = delay;
}
/**
* Checks if the task is running.
*
* @return {@code true} if so, {@code false} if not.
*/
public boolean isRunning() {
return running;
}
/**
* Checks if the task is stopped.
*
* @return {@code true} if so, {@code false} if not.
*/
public boolean isStopped() {
return !running;
}
/**
* This method should be called by the scheduling class every cycle. It
* updates the {@link #countdown} and calls the {@link #execute()} method if
* necessary.
*
* @return A flag indicating if the task is running.
*/
public boolean tick() {
if (running && --countdown == 0) {
execute();
countdown = delay;
}
return running;
}
public int getCountdown() {
return countdown;
}
/**
* Performs this task's action.
*/
protected abstract void execute();
/**
* Changes the delay of this task.
*
* @param delay
* The number of cycles between consecutive executions of this
* task.
* @throws IllegalArgumentException
* if the {@code delay} is not positive.
*/
public void setDelay(int delay) {
checkDelay(delay);
delay = 0;
}
/**
* Stops this task.
*
* @throws IllegalStateException
* if the task has already been stopped.
*/
public void stop() {
if (!checkStopped())
return;
running = false;
onStop();
}
/**
* Stops this task. Does not run the onStop method.
*
* @throws IllegalStateException
* if the task has already been stopped.
*/
public void forceStop() {
checkStopped();
running = false;
}
/**
* Override this method for code which should be run when the task stops.
*/
public void onStop() {
}
/**
* Checks if the delay is negative and throws an exception if so.
*
* @param delay
* The delay.
* @throws IllegalArgumentException
* if the delay is not positive.
*/
private void checkDelay(int delay) {
if (delay < 0)
throw new IllegalArgumentException("Delay must be positive.");
}
/**
* Checks if this task has been stopped and throws an exception if so.
*
* @throws IllegalStateException
* if the task has been stopped.
*/
private boolean checkStopped() {
return running;
}
}
@@ -169,7 +169,7 @@ public int itemAmount(String name, int itemId, int itemX, int itemY) {
}
}
}
if (!com.rebotted.game.items.Item.itemStackable[itemId] && itemAmount > 0) {
if (!com.rebotted.game.items.ItemData.itemStackable[itemId] && itemAmount > 0) {
for (int j = 0; j < itemAmount; j++) {
c.getPacketSender().createGroundItem(itemId, itemX, itemY, 1);
GroundItem item = new GroundItem(itemId, itemX, itemY, c.getH(), 1, c.playerId, HIDE_TICKS, PlayerHandler.players[playerId].playerName);