Code:
package server.model.minigames;
import java.util.Random;
import server.Server;
import server.event.CycleEvent;
import server.event.CycleEventContainer;
import server.event.CycleEventHandler;
import server.model.players.Client;
/**
*
* Rep me on rune-server if it helped you :) name = Emrage
* @author Emre
*
*/
public class WarriorsGuild {
public static final Random r = new Random();
public static final int CyclopsId = 6270;
/**
* arrays
*/
private static final int[] bronze = { 1075, 1117, 1155, -1};
private static final int[] iron = { 1067, 1115, 1153, -1 };
private static final int[] steel = { 1069, 1119, 1157, -1 };
private static final int[] black = { 1077, 1125, 1165, -1 };
private static final int[] mithril = { 1071, 1121, 1159, -1 };
private static final int[] adamant = { 1073, 1123, 1161, -1 };
private static final int[] rune = { 1079, 1127, 1163, -1 };
/**
* Enum
*
*
*/
public enum spawnNpc {
BRONZE(bronze),
IRON(iron),
STEEL(steel),
BLACK(black),
MITHRIL(mithril),
ADAMANT(adamant),
RUNE(rune);
private int[] itemId;
spawnNpc(int[] requiredItems) {
this.itemId = requiredItems;
}
public int[] getItemId() {
return itemId;
}
public static spawnNpc forId(int id) {
for(spawnNpc s : values()) {
for(int i : s.itemId) {
if(i == id) {
return s;
}
}
}
return null;
}
}
/**
*
* For players that dont have tokens left
*/
public static void noTokens(Client c) {
if(c.inCY())
if(c.getItems().playerHasItem(8851, 0)) {
c.getPA().movePlayer(2846, 3541, 2);
}
}
/**
*
* If the player logs out this happens
*/
public static void logOut(Client c) {
if(c.inCY());
c.getPA().movePlayer(2846, 3541, 2);
}
/**
*
* Handling stuff if player is in cyclops area
* @param c
*/
public static void inCyclops(Client c) {
c.getPA().movePlayer(2848, 3540, 2);
//System.out.println("works");
CyclopsDrops(c);
loseTokens(c);
noTokens(c);
}
/**
*
* For losing tokens
* @param c
*/
public static void loseTokens(Client c) {
CycleEventHandler.getSingleton().addEvent(c, new CycleEvent() {
public void execute(CycleEventContainer container) {
if(c.inCY()) {
c.getItems().deleteItem(8851, c.getItems().getItemSlot(8851), 30);
//System.out.println(c.playerName + "Lost 100 tokens");
}
}
@Override
public void onFinish() {
}
},500);
}
/**
*
* Cyclops drops
*/
public static void CyclopsDrops(Client c) {
if(c.inCY()) {
if(c.WarriorsGuild == 0) {
double chance = r.nextDouble();
if(chance < 1.0/10.0) {
Server.itemHandler.createGroundItem(c, 8844, c.getX()+1, c.getY(), 1, c.playerId);
c.WarriorsGuild = 1;
}
}
if(c.WarriorsGuild == 1) {
double chance = r.nextDouble();
if(chance < 1.0/12.0) {
Server.itemHandler.createGroundItem(c, 8845, c.getX()+1, c.getY(), 1, c.playerId);
c.WarriorsGuild = 2;
}
}
if(c.WarriorsGuild == 2) {
double chance = r.nextDouble();
if(chance < 1.0/14.0) {
Server.itemHandler.createGroundItem(c, 8846, c.getX()+1, c.getY(), 1, c.playerId);
c.WarriorsGuild = 3;
}
}
if(c.WarriorsGuild == 3) {
double chance = r.nextDouble();
if(chance < 1.0/14.0) {
Server.itemHandler.createGroundItem(c, 8847, c.getX()+1, c.getY(), 1, c.playerId);
c.WarriorsGuild = 4;
}
}
if(c.WarriorsGuild == 4) {
double chance = r.nextDouble();
if(chance < 1.0/14.0) {
Server.itemHandler.createGroundItem(c, 8848, c.getX()+1, c.getY(), 1, c.playerId);
c.WarriorsGuild = 5;
}
}
if(c.WarriorsGuild == 5) {
double chance = r.nextDouble();
if(chance < 1.0/14.0) {
Server.itemHandler.createGroundItem(c, 8849, c.getX()+1, c.getY(), 1, c.playerId);
c.WarriorsGuild = 6;
}
}
if(c.WarriorsGuild == 6) {
double chance = r.nextDouble();
if(chance < 1.0/14.0) {
Server.itemHandler.createGroundItem(c, 8850, c.getX()+1, c.getY(), 1, c.playerId);
c.WarriorsGuild = 7;
}
}
if(c.WarriorsGuild >= 7) {
double chance = r.nextDouble();
if(chance < 1.0/18.0) {
Server.itemHandler.createGroundItem(c, 20072, c.getX()+1, c.getY(), 1, c.playerId);
}
}
}
}
/**
* Entering the place
* @param c
*/
public static void isEntering(Client c) {
if(canEnter(c)) {
c.getDH().sendOption2("I wanna go in the warriors guild", "No thank you");;
c.dialogueAction = 1015;
}
}
/**
*
* Checking of the player has the item
* @param c
* @return
*/
public static boolean canEnter(Client c) {
if(!c.getItems().playerHasItem(8851, 100)) {
c.sendMessage("You dont have enough tokens. you need 100 tokens");
return false;
}
return true;
}
/**
*
* Checking of the player has the right item
* @return
*/
public static boolean hasItem(Client c, int[] ids) {
for(int id : ids) {
if(!c.getItems().playerHasItem(id)) {
c.sendMessage("You dont have the right items");
return false;
}
}
return true;
}
/**
*
* Method for spawning them
* @param itemId
*/
public static void NpcSpawning(Client c, int itemId) {
spawnNpc s = spawnNpc.forId(itemId);
if(s != null) {
if(hasItem(c, s.getItemId())) {
spawningNpc(c,s);
}
} else {
c.sendMessage("you can't use this item");
}
}
/**
*
* Checking to spawn the right npc and spawning them
*/
public static void spawningNpc(Client c, spawnNpc s) {
switch(s) {
case BRONZE:
Server.npcHandler.spawnNpc(c, 4278,
c.getX(), c.getY() +1, 0, 0, 20, 10, 100, 100, true, true);
break;
case IRON:
Server.npcHandler.spawnNpc(c, 4279,
c.getX(), c.getY() +1, 0, 0, 30, 12, 120, 100, true, true);
break;
case STEEL:
Server.npcHandler.spawnNpc(c, 4280,
c.getX(), c.getY() +1, 0, 0, 40, 14, 140, 100, true, true);
break;
case BLACK:
Server.npcHandler.spawnNpc(c, 4281,
c.getX(), c.getY() +1, 0, 0, 50, 16, 145, 105, true, true);
break;
case MITHRIL:
Server.npcHandler.spawnNpc(c, 4282,
c.getX(), c.getY() +1, 0, 0, 55, 18, 155, 115, true, true);
break;
case ADAMANT:
Server.npcHandler.spawnNpc(c, 4283,
c.getX(), c.getY() +1, 0, 0, 60, 20, 160, 120, true, true);
break;
case RUNE:
Server.npcHandler.spawnNpc(c, 4284,
c.getX(), c.getY() +1, 0, 0, 70, 25, 180, 125, true, true);
break;
}
for(int i : s.getItemId())
c.getItems().deleteItem(i, c.getItems().getItemSlot(i), 1);
//c-npc-x-y-h-walking-hp-max-atk-def-agressive-headicon
}
}
You could get a error at onFishish change onFinish to whatever is in your cycleevent class could be onStop or Stop