Code:
package server.model.content;
import server.clip.region.Region;
import server.model.players.Client;
import server.util.Misc;
public class Flowers {
/**
* Constants & boolean checker
*/
private final int FLOWER_IDS[] = {2980,2981,2982,2983,2984,2985,2986,2987,2988};
/**
* Checks weather user is currently interacting with flower
*/
public boolean clientFlowering = false;
/**
* Stores temporary variables for each new instance of flower planted
*/
private int lastObject;
/**
* algorithm decides which flower to give.
* @param flower
* @return
*/
private static int flowerDecoder(final int flower){
int modifier = flower - 2980;
return (modifier + 2460);
}
/**
* Constructor creates the place flower event
* @param c
*/
public Flowers(Client c){
executeAction(c);
}
/**
* Main block, Spawns the object & starts animation. Moves player to the side Clipped
* @param c
*/
private void executeAction(Client c){
int newFlower = getRandom();
updateConstants(newFlower, c);
c.getPA().checkObjectSpawn(newFlower, c.getX(), c.getY(), 1, 10);
deleteSeeds(c);
sendOptions(c);
this.clientFlowering = true;
moveOneStep(c);
}
/**
* Handles movement direction.
* @param c
*/
private static void moveOneStep(Client c){
if (Region.getClipping(c.getX() - 1, c.getY(), c.heightLevel, -1, 0)) {
c.getPA().walkTo(-1, 0);
} else if (Region.getClipping(c.getX() + 1, c.getY(), c.heightLevel, 1, 0)) {
c.getPA().walkTo(1, 0);
} else if (Region.getClipping(c.getX(), c.getY() - 1, c.heightLevel, 0, -1)) {
c.getPA().walkTo(0, -1);
} else if (Region.getClipping(c.getX(), c.getY() + 1, c.heightLevel, 0, 1)) {
c.getPA().walkTo(0, 1);
}
}
/**
* Selects a random flower ID
* @return
*/
private int getRandom(){
return (FLOWER_IDS[Misc.random(FLOWER_IDS.length-1)]);
}
/**
* Sends the client an option to handle flowers
* @param c
*/
private void sendOptions(Client c){
c.getDH().sendOption2("Leave Flowers", "Harvest Flowers");
}
/**
* Removes the seeds from invent
* @param c
*/
private static void deleteSeeds(Client c){
c.getItems().deleteItem(299, 1);
}
private void updateConstants(int objectType, Client c){
lastObject = objectType;
}
/**
* Method harvests flower from ground
* @param c
* @param object
* @param oX
* @param oY
*/
public void harvestFlower(Client c, int object){
c.getItems().addItem(flowerDecoder(object), 1);
c.startAnimation(827);
c.getPA().checkObjectSpawn(-1, c.getX()+1, c.getY(), 1, 10);
}
/**
* Sends the option action
* @param option
*/
public void handleOptions(int option, Client c){
if (option == 0)
return;
else
harvestFlower(c, lastObject);
clientFlowering = false;
}
}
and then in ClickItem.java just make a boolean isFlower, and if returned true, use this