init, thx MrExtremez

This commit is contained in:
Nicola Paolucci
2019-06-18 15:04:35 -04:00
commit ea51313125
2488 changed files with 150207 additions and 0 deletions
@@ -0,0 +1,54 @@
package redone.game.content.random;
import java.awt.Point;
import java.util.Random;
import redone.Server;
import redone.game.objects.Objects;
import redone.game.players.Client;
public class Balloons extends Objects {
static Random r = new Random();
public static int item, amount;
public static int x, y;
@SuppressWarnings("static-access")
public Balloons(int id, int x, int y, int height, int face, int type,
int ticks, int item, int amount) {
super(id, x, y, height, face, type, ticks);
this.x = x;
this.y = y;
this.item = item;
this.amount = amount;
}
public static void popBalloon(Client c, int x, int y) {
PartyRoom.coords.remove(getCoords());
Balloons empty = remove(x, y);
Server.itemHandler.createGroundItem(c, item, x, y, amount, c.playerId);
item = 0;
amount = 0;
Server.objectHandler.addObject(empty);
Server.objectHandler.placeObject(empty);
c.startAnimation(794);
}
public static Point getCoords() {
return new Point(x, y);
}
public static Balloons getBalloon(int item, int amount) {
return new Balloons(115 + r.nextInt(5), 2730 + r.nextInt(13),
3462 + r.nextInt(13), 0, 0, 10, 0, item, amount);
}
public static Balloons getEmpty() {
return new Balloons(115 + r.nextInt(5), 2730 + r.nextInt(13),
3462 + r.nextInt(13), 0, 0, 10, 0, 0, 0);
}
public static Balloons remove(int x, int y) {
return new Balloons(-1, x, y, 0, 0, 10, 0, 0, 0);
}
}
@@ -0,0 +1,70 @@
package redone.game.content.random;
import redone.Constants;
import redone.game.players.PlayerHandler;
/**
* Holiday Drops
* @author Andrew (I'm A Boss on Rune-Server, Mr Extremez on Moparscape & Runelocus)
*/
public enum HolidayDrops {
EASTER(1961, "Easter", false), HALLOWEEN(1053, "Halloween", true), CHRISTMAS(962, "Christmas", false);
private final int item;// holiday item
private final String name;// holiday name
private final boolean whichHoliday;// if true, this holiday will be dropped
public final int DROP_DISTANCE = 40;// distance of drops
public int count = 0;// count starts at 0 and ends at 400 can be changed
public final int drops = 7;// this is just for random number of the drops
public static int DROP_AMOUNT = PlayerHandler.playerCount * 5;// players
// online *
// 5 = drop
// amount
public static int dropAmount() {
int amount = DROP_AMOUNT;
if (Constants.SERVER_DEBUG) {
return amount * 60;
}
return amount;
}
private HolidayDrops(int item, String name, boolean whichHoliday) {
this.item = item;
this.name = name;
this.whichHoliday = whichHoliday;
}
public int getItem() {
return item;
}
public String getName() {
return name;
}
public boolean getHoliday() {
return whichHoliday;
}
/*private static int addItem() {
int random = 2;
if (Misc.random(random) == 0) {
return 1053;
} else if (Misc.random(random) == 1) {
return 1055;
} else if (Misc.random(random) == 2) {
return 1057;
}
return -1;
}*/
public final int[][] COORDS = { { 3214, 3424 }, // Varrock
{ 3222, 3218 }, // Lumbridge
{ 2964, 3378 }, // Falador
{ 3082, 3419 }, // Barb
{ 3082, 3249 }, // Draynor
{ 3293, 3180 }, // Al Kharid
{ 3034, 3246 }, // Rimmington
};
}
@@ -0,0 +1,90 @@
package redone.game.content.random;
import redone.Server;
import redone.event.CycleEvent;
import redone.event.CycleEventContainer;
import redone.event.CycleEventHandler;
import redone.game.players.Client;
import redone.game.players.Player;
import redone.game.players.PlayerHandler;
import redone.util.Misc;
/**
* Holiday Drops
* @author Andrew (I'm A Boss on Rune-Server, Mr Extremez on Moparscape & Runelocus)
*/
public class Holidays {
public static void startDropping(Client c) {
for (final HolidayDrops holiday : HolidayDrops.values()) {
for (Player player : PlayerHandler.players) {
if (player != null) {
Client p1 = (Client) player;
if (holiday.getHoliday()) {
if (p1.playerRights > 2) {
p1.getActionSender().sendMessage("Currently dropping " + HolidayDrops.dropAmount() + " items.");
}
p1.getActionSender().sendMessage("The " + holiday.getName() + " event has started, goodluck!");
dropItems(c);
}
}
}
}
}
public static void dropItems(Client client) {
CycleEventHandler.getSingleton().addEvent(client, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
for (int j = 0; j < PlayerHandler.players.length; j++) {
if (PlayerHandler.players[j] != null) {
Client p1 = (Client) PlayerHandler.players[j];
for (HolidayDrops holiday : HolidayDrops.values()) {
if (holiday.count >= HolidayDrops.dropAmount() && holiday.getHoliday()) {
stop();
p1.getActionSender().sendMessage("The " + holiday.getName() + " event has ended, good luck finding the rest of the items!");
} else if (holiday.count < HolidayDrops.dropAmount() && holiday.getHoliday()) {
switch (Misc.random(holiday.drops)) {
case 0:// Varrock
Server.itemHandler.createGroundItem(p1, holiday.getItem(), 3214 + Misc.random(holiday.DROP_DISTANCE), 3424 - Misc.random(holiday.DROP_DISTANCE), 1, j);
holiday.count++;
break;
case 1:// Lumbridge
Server.itemHandler.createGroundItem(p1, holiday.getItem(), 3222 + Misc.random(holiday.DROP_DISTANCE), 3218 - Misc.random(holiday.DROP_DISTANCE), 1, j);
holiday.count++;
break;
case 2:// Falador
Server.itemHandler.createGroundItem(p1, holiday.getItem(), 2964 + Misc.random(holiday.DROP_DISTANCE), 3378 - Misc.random(holiday.DROP_DISTANCE), 1, j);
holiday.count++;
break;
case 3:// Barb Village
Server.itemHandler.createGroundItem(p1, holiday.getItem(), 3082 + Misc.random(holiday.DROP_DISTANCE), 3419 - Misc.random(holiday.DROP_DISTANCE), 1, j);
holiday.count++;
break;
case 4:// Draynor
Server.itemHandler.createGroundItem(p1, holiday.getItem(), 3082 + Misc.random(holiday.DROP_DISTANCE), 3249 - Misc.random(holiday.DROP_DISTANCE), 1, j);
holiday.count++;
break;
case 5:// Al Kharid
Server.itemHandler.createGroundItem(p1, holiday.getItem(), 3293 + Misc.random(holiday.DROP_DISTANCE), 3180 - Misc.random(holiday.DROP_DISTANCE), 1, j);
holiday.count++;
break;
case 6:// Rimmington
Server.itemHandler.createGroundItem(p1, holiday.getItem(), 3034 + Misc.random(holiday.DROP_DISTANCE), 3246 - Misc.random(holiday.DROP_DISTANCE), 1, j);
holiday.count++;
break;
}
}
}
}
}
}
@Override
public void stop() {
// TODO Auto-generated method stub
}
}, 2);
}
}
@@ -0,0 +1,237 @@
package redone.game.content.random;
import java.awt.Point;
import java.util.ArrayList;
import java.util.Random;
import redone.Constants;
import redone.Server;
import redone.game.items.Item;
import redone.game.objects.Objects;
import redone.game.players.Client;
public class PartyRoom {
static Random r = new Random();
static int[] roomItems = new int[50];
static int[] roomItemsN = new int[50];
static long lastAnnouncment;
static int announcmentFrequency = 1; // announcment frequency in mins
static ArrayList<Point> coords = new ArrayList<Point>();
public static int getAmount() {
int amount = 0;
for (int roomItem : roomItems) {
if (roomItem > 0) {
amount++;
}
}
return amount;
}
public static void startTimer(Client c) {
if (System.currentTimeMillis() - lastAnnouncment > 1000 * 60 * announcmentFrequency) {
dropAll();
lastAnnouncment = System.currentTimeMillis();
}
}
public static void dropAll() {
int trys = 0;
int amount = getAmount();
if (amount < 1) {
return;
}
for (int x = 0; x < roomItems.length; x++) {
if (roomItemsN[x] > 0) {
Balloons b = null;
do {
b = Balloons.getBalloon(roomItems[x], roomItemsN[x]);
trys++;
} while (coords.contains(Balloons.getCoords()) && trys < 100);
Server.objectHandler.addObject(b);
Server.objectHandler.placeObject(b);
}
if (trys > 100) {
break;
}
roomItems[x] = 0;
roomItemsN[x] = 0;
}
trys = 0;
for (int x = 0; x < amount * 2; x++) {
Objects o;
do {
o = Balloons.getEmpty();
} while (coords.contains(new Point(o.objectX, o.objectY))
&& trys < 100);
if (trys > 100) {
break;
}
Server.objectHandler.addObject(o);
Server.objectHandler.placeObject(o);
}
coords.clear();
}
public static int arraySlot(int[] array, int target) {
int spare = -1;
for (int x = 0; x < array.length; x++) {
if (array[x] == target) {
return x;
} else if (spare == -1 && array[x] <= 0) {
spare = x;
}
}
return spare;
}
public static void open(Client c) {
if (!Constants.PARTY_ROOM_DISABLED) {
updateGlobal(c);
updateDeposit(c);
c.getItemAssistant().resetItems(5064);
c.getPlayerAssistant().sendFrame248(2156, 5063);
} else {
c.getActionSender().sendMessage(
"The partyroom has been disabled.");
}
}
public static void accept(Client c) {
for (int x = 0; x < c.party.length; x++) {
if (c.partyN[x] > 0) {
if (Item.itemStackable[c.party[x]]) {
int slot = arraySlot(roomItems, c.party[x]);
if (slot < 0) {
c.getActionSender().sendMessage(
"Theres not enough space left in the chest.");
break;
}
if (roomItems[slot] != c.party[x]) {
roomItems[slot] = c.party[x];
roomItemsN[slot] = c.partyN[x];
} else {
roomItemsN[slot] += c.partyN[x];
}
c.party[x] = -1;
c.partyN[x] = 0;
} else {
int left = c.partyN[x];
for (int y = 0; y < left; y++) {
int slot = arraySlot(roomItems, -2);
if (slot < 0) {
c.getActionSender()
.sendMessage(
"Theres not enough space left in the chest.");
break;
}
roomItems[slot] = c.party[x];
roomItemsN[slot] = 1;
c.partyN[x]--;
}
if (c.partyN[x] <= 0) {
c.party[x] = -1;
}
}
}
}
updateDeposit(c);
updateGlobal(c);
}
// public static void updateAll() {
// for (int x = 0; x < PlayerHandler.getPlayers().length; x++) {
// updateGlobal((Client) PlayerHandler.getPlayers()[x]);
// }
// }
public static void fix(Client c) {
for (int x = 0; x < 8; x++) {
if (c.party[x] < 0) {
c.partyN[x] = 0;
} else if (c.partyN[x] <= 0) {
c.party[x] = 0;
}
}
}
public static void depositItem(Client c, int id, int amount) {
int slot = arraySlot(c.party, id);
for (int i : Constants.ITEM_TRADEABLE) {
if (i == id) {
c.getActionSender().sendMessage(
"You can't deposit this item.");
return;
}
if (id == 995) {
c.getActionSender().sendMessage("You can't deposit coins!");
return;
}
}
if (c.getItemAssistant().getItemAmount(id) < amount) {
amount = c.getItemAssistant().getItemAmount(id);
}
if (!c.getItemAssistant().playerHasItem(id, amount)) {
c.getActionSender().sendMessage(
"You don't have that many items!");
return;
}
if (slot == -1) {
c.getActionSender().sendMessage(
"You cant deposit more than 8 items at once.");
return;
}
c.getItemAssistant().deleteItem2(id, amount);
if (c.party[slot] != id) {
c.party[slot] = id;
c.partyN[slot] = amount;
} else {
c.party[slot] = id;
c.partyN[slot] += amount;
}
updateDeposit(c);
}
public static void withdrawItem(Client c, int slot) {
if (c.party[slot] >= 0 && c.getItemAssistant().freeSlots() > 0) {
c.getItemAssistant().addItem(c.party[slot], c.partyN[slot]);
c.party[slot] = 0;
c.partyN[slot] = 0;
}
updateDeposit(c);
updateGlobal(c);
}
public static void updateDeposit(Client c) {
c.getItemAssistant().resetItems(5064);
for (int x = 0; x < 8; x++) {
if (c.partyN[x] <= 0) {
itemOnInterface(c, 2274, x, -1, 0);
} else {
itemOnInterface(c, 2274, x, c.party[x], c.partyN[x]);
}
}
}
public static void updateGlobal(Client c) {
for (int x = 0; x < roomItems.length; x++) {
if (roomItemsN[x] <= 0) {
itemOnInterface(c, 2273, x, -1, 0);
} else {
itemOnInterface(c, 2273, x, roomItems[x], roomItemsN[x]);
}
}
}
public static void itemOnInterface(Client c, int frame, int slot, int id,
int amount) {
c.outStream.createFrameVarSizeWord(34);
c.outStream.writeWord(frame);
c.outStream.writeByte(slot);
c.outStream.writeWord(id + 1);
c.outStream.writeByte(255);
c.outStream.writeDWord(amount);
c.outStream.endFrameVarSizeWord();
}
}