mirror of
https://github.com/2006-Scape/2006Scape.git
synced 2026-07-03 00:31:51 +00:00
Farming task (#567)
* Firemaking: Fix some text (#548) * Network cleanup (#552) * Replaced packetType/Size with packet * Replace Instream with Packet Read data directly from packet to ease future network upgrade * Update Packet.java Removed unused methods to ease netty migration and network rewrite. * Moved packet sizes. * Removed unused stream methods * Added readhex method for buttons * preparing to replace mina * Packet->GamePacket for refactoring * Netty 3.6.6 * formatting * formatting * Apollo core * Update net.xml Added variables for 2006scape * Netty 4 migration. Jagcached replaced with Apollo Core * Porting network into apollo * WIP Packet Changes Do not merge. This is broken. * Packet read methods converted to netty buffer * Replacing game network and login with apollo * Netty 4 * Cleanup * Same port for update and game server. * Cleanup login for integration with apollo * Login works. fixing packets * Running on apollo netcode. * Server runs * Update apollo-core.jar * Disable encoder. write outstream directly to channel. * Update RS2ProtocolDecoder.java Added apollo decoder * Add constant * Synchronization not needed * Update apollo-core.jar * Better performance. * Commit pre PR * Update apollo-core.jar * Fixup Port Binding Based On World * Apollo files * Additional Commit --------- Co-authored-by: Dark98 <darkaidz98@gmail.com> * Redo StaticNpcList constants (#553) * Redo StaticNpcList constants * Added items and objects * Update NpcAggressive.java * Bump netty-all from 4.0.34.Final to 4.1.42.Final in /2006Scape Server (#555) Bumps [netty-all](https://github.com/netty/netty) from 4.0.34.Final to 4.1.42.Final. - [Release notes](https://github.com/netty/netty/releases) - [Commits](https://github.com/netty/netty/compare/netty-4.0.34.Final...netty-4.1.42.Final) --- updated-dependencies: - dependency-name: io.netty:netty-all dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Converted FarmingTask to CycleEvent * Removed redundant tick system. --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Josh Shippam <darkaidz98@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This commit is contained in:
@@ -38,8 +38,6 @@ import com.rs2.integrations.PlayersOnlineWebsite;
|
||||
import com.rs2.integrations.RegisteredAccsWebsite;
|
||||
import com.rs2.integrations.discord.DiscordActivity;
|
||||
import com.rs2.integrations.discord.JavaCord;
|
||||
import com.rs2.tick.Scheduler;
|
||||
import com.rs2.tick.Tick;
|
||||
import com.rs2.util.HostBlacklist;
|
||||
import com.rs2.world.GlobalDropsHandler;
|
||||
import com.rs2.world.ItemHandler;
|
||||
@@ -93,18 +91,6 @@ public class GameEngine {
|
||||
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;
|
||||
public static int[] cannonsX = new int[50];
|
||||
public static int[] cannonsY = new int[50];
|
||||
|
||||
+14
-10
@@ -1,19 +1,23 @@
|
||||
package com.rs2.game.content.skills.farming;
|
||||
|
||||
import com.rs2.event.CycleEvent;
|
||||
import com.rs2.event.CycleEventContainer;
|
||||
import com.rs2.game.players.Player;
|
||||
import com.rs2.tick.Tick;
|
||||
|
||||
public class FarmingTask extends Tick {
|
||||
|
||||
private Player player;
|
||||
public class FarmingTask extends CycleEventContainer {
|
||||
|
||||
public FarmingTask(Player player) {
|
||||
super(10);
|
||||
this.player = player;
|
||||
}
|
||||
super("farming task".hashCode(), player, new CycleEvent() {
|
||||
|
||||
@Override
|
||||
protected void execute() {
|
||||
Farming.processCalc(player);
|
||||
@Override
|
||||
public void execute(CycleEventContainer container) {
|
||||
Farming.processCalc(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
}
|
||||
|
||||
}, 10);
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
package com.rs2.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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,151 +0,0 @@
|
||||
package com.rs2.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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user