mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 00:38:21 +00:00
Merge branch 'master' of git@bitbucket.org:Major-/apollo.git into pathfinding.
This commit is contained in:
@@ -1,35 +1,35 @@
|
||||
require 'java'
|
||||
|
||||
java_import 'org.apollo.game.model.entity.Player'
|
||||
java_import 'org.apollo.game.message.impl.OpenOverlayMessage'
|
||||
java_import 'org.apollo.game.message.impl.SetWidgetTextMessage'
|
||||
java_import 'org.apollo.game.message.impl.OpenOverlayMessage'
|
||||
|
||||
|
||||
# Constants constants related to the wilderness
|
||||
module WildernessConstants
|
||||
|
||||
private
|
||||
# The wilderness level overlay interface id
|
||||
OVERLAY_INTERFACE_ID = 197
|
||||
|
||||
MIN_X = 2945
|
||||
MIN_Y = 3522
|
||||
MAX_X = 3390
|
||||
MAX_Y = 3972
|
||||
# The wilderness level string id
|
||||
LEVEL_STRING_ID = 199
|
||||
|
||||
OVERLAY_INTERFACE_ID = 197
|
||||
LEVEL_STRING_ID = 199
|
||||
end
|
||||
|
||||
declare_attribute(:wilderness_level, 0, :transient)
|
||||
|
||||
# Determines the wilderness level for the specified player's position
|
||||
def wilderness_level(player)
|
||||
return (player.position.y - (MIN_Y - 1) / 8).ceil
|
||||
return ((player.position.y - 3520) / 8).ceil
|
||||
end
|
||||
|
||||
area_action :wilderness_level do
|
||||
|
||||
on_entry do |player|
|
||||
player.wilderness_level = wilderness_level(player)
|
||||
player.interface_set.open_overlay(OVERLAY_INTERFACE_ID)
|
||||
player.send(SetWidgetTextMessage.new(LEVEL_STRING_ID, "Level: #{player.wilderness_level}"))
|
||||
show_action(ATTACK_ACTION)
|
||||
player.interface_set.open_overlay(WildernessConstants::OVERLAY_INTERFACE_ID)
|
||||
player.send(SetWidgetTextMessage.new(WildernessConstants::LEVEL_STRING_ID, "Level: #{player.wilderness_level}"))
|
||||
show_action(player, ATTACK_ACTION)
|
||||
end
|
||||
|
||||
while_in do |player|
|
||||
@@ -37,16 +37,17 @@ area_action :wilderness_level do
|
||||
updated = wilderness_level(player)
|
||||
if (current != updated)
|
||||
player.wilderness_level = updated
|
||||
player.send(SetWidgetTextMessage.new(LEVEL_STRING_ID, "Level: #{player.wilderness_level}"))
|
||||
player.send(SetWidgetTextMessage.new(WildernessConstants::LEVEL_STRING_ID, "Level: #{player.wilderness_level}"))
|
||||
end
|
||||
end
|
||||
|
||||
on_exit do |player|
|
||||
player.wilderness_level = 0
|
||||
player.interface_set.close() # TODO: Will this cause issues with other potentially open interfaces?
|
||||
hide_action(ATTACK_ACTION)
|
||||
player.interface_set.close()
|
||||
player.send(OpenOverlayMessage.new(-1))
|
||||
hide_action(player, ATTACK_ACTION)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
area :name => :wilderness, :coordinates => [ MIN_X, MIN_Y, MAX_X, MAX_Y, 0 ], :actions => :wilderness_level
|
||||
area :name => :wilderness, :coordinates => [ 2945, 3522, 3390, 3972, 0 ], :actions => :wilderness_level
|
||||
@@ -18,7 +18,7 @@ class OpenDoorAction < DistancedAction
|
||||
end
|
||||
|
||||
def equals(other)
|
||||
return (get_class == other.get_class && @position == other.position)
|
||||
return (get_class == other.get_class && @door_object == other.door_object)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ module DoorUtil
|
||||
# Gets the door object at the given position, if it exists.
|
||||
def self.get_door_object(position, object_id)
|
||||
game_objects = $world.sector_repository.from_position(position).get_entities(position, EntityType::GAME_OBJECT)
|
||||
game_objects.each { |game_object| return game_object if game_object.get_id == object_id }
|
||||
game_objects.each { |game_object| return game_object if game_object.id == object_id }
|
||||
return nil
|
||||
end
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ require 'java'
|
||||
java_import 'org.apollo.game.message.impl.SetPlayerActionMessage'
|
||||
java_import 'org.apollo.game.model.entity.Player'
|
||||
|
||||
|
||||
|
||||
class PlayerAction
|
||||
attr_reader :slot, :primary, :name
|
||||
|
||||
@@ -24,7 +26,7 @@ FOLLOW_ACTION = PlayerAction.new(:fifth, true, 'Follow')
|
||||
|
||||
# Shows multiple context menu action for the specified player
|
||||
def show_actions(player, *actions)
|
||||
raise 'Must specify at least one action to show' if actions.nil?
|
||||
raise 'Must specify at least one action' if actions.nil?
|
||||
|
||||
actions.each do |action|
|
||||
player.add_action(action)
|
||||
@@ -39,7 +41,7 @@ end
|
||||
|
||||
# Hides a context menu action for the specified player
|
||||
def hide_action(player, action)
|
||||
show_action(player, PlayerAction.new('null', action.slot, action.primary))
|
||||
show_action(player, PlayerAction.new(action.slot, action.primary, 'null'))
|
||||
end
|
||||
|
||||
class Player
|
||||
|
||||
@@ -161,7 +161,8 @@ public final class CollisionMatrix {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return MoreObjects.toStringHelper(this).add("width", width).add("length", length).add("matrix", Arrays.toString(matrix)).toString();
|
||||
return MoreObjects.toStringHelper(this).add("width", width).add("length", length).add("matrix", Arrays.toString(matrix))
|
||||
.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -209,8 +210,9 @@ public final class CollisionMatrix {
|
||||
* @throws ArrayIndexOutOfBoundsException If the specified coordinate pair does not fit in this matrix.
|
||||
*/
|
||||
private int indexOf(int x, int y) {
|
||||
Preconditions.checkElementIndex(x, width, "X coordinate must be [0, " + width + "), received " + x + ".");
|
||||
Preconditions.checkElementIndex(y, length, "Y coordinate must be [0, " + length + "), received " + y + ".");
|
||||
int index = y * width + x;
|
||||
Preconditions.checkElementIndex(index, matrix.length, "Index out of bounds.");
|
||||
return index;
|
||||
}
|
||||
|
||||
|
||||
@@ -100,4 +100,9 @@ public final class ApolloHandler extends ChannelInboundHandlerAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelReadComplete(ChannelHandlerContext ctx) {
|
||||
ctx.flush();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,6 +14,8 @@ import java.nio.charset.Charset;
|
||||
import org.apollo.net.codec.jaggrab.JagGrabRequestDecoder;
|
||||
import org.apollo.net.codec.jaggrab.JagGrabResponseEncoder;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
|
||||
/**
|
||||
* A {@link ChannelInitializer} for the JAGGRAB protocol.
|
||||
*
|
||||
@@ -29,7 +31,7 @@ public final class JagGrabChannelInitializer extends ChannelInitializer<SocketCh
|
||||
/**
|
||||
* The character set used in the request.
|
||||
*/
|
||||
private static final Charset JAGGRAB_CHARSET = Charset.forName("US-ASCII");
|
||||
private static final Charset JAGGRAB_CHARSET = Charsets.US_ASCII;
|
||||
|
||||
/**
|
||||
* The maximum length of a request, in bytes.
|
||||
|
||||
@@ -90,7 +90,7 @@ public final class LoginDecoder extends StatefulFrameDecoder<LoginDecoderState>
|
||||
response.writeByte(LoginConstants.STATUS_EXCHANGE_DATA);
|
||||
response.writeLong(0);
|
||||
response.writeLong(serverSeed);
|
||||
ctx.channel().writeAndFlush(response);
|
||||
ctx.channel().write(response);
|
||||
|
||||
setState(LoginDecoderState.LOGIN_HEADER);
|
||||
}
|
||||
@@ -210,7 +210,7 @@ public final class LoginDecoder extends StatefulFrameDecoder<LoginDecoderState>
|
||||
ByteBuf buffer = ctx.alloc().buffer(1);
|
||||
buffer.writeByte(response);
|
||||
|
||||
ctx.writeAndFlush(buffer).addListener(ChannelFutureListener.CLOSE);
|
||||
ctx.write(buffer).addListener(ChannelFutureListener.CLOSE);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -107,7 +107,7 @@ public final class LoginSession extends Session {
|
||||
}
|
||||
}
|
||||
|
||||
ChannelFuture future = channel.writeAndFlush(new LoginResponse(status, rights, flagged));
|
||||
ChannelFuture future = channel.write(new LoginResponse(status, rights, flagged));
|
||||
|
||||
destroy();
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ public final class OnDemandRequestWorker extends RequestWorker<OnDemandRequest,
|
||||
ByteBuf chunkData = Unpooled.wrappedBuffer(tmp, 0, chunkSize);
|
||||
|
||||
OnDemandResponse response = new OnDemandResponse(desc, length, chunk, chunkData);
|
||||
channel.writeAndFlush(response);
|
||||
channel.write(response);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package org.apollo.update;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.apollo.Service;
|
||||
import org.apollo.fs.IndexedFileSystem;
|
||||
@@ -27,6 +30,11 @@ public final class UpdateService extends Service {
|
||||
*/
|
||||
private static final int THREADS_PER_REQUEST_TYPE = Runtime.getRuntime().availableProcessors();
|
||||
|
||||
/**
|
||||
* The logger for this class.
|
||||
*/
|
||||
private static final Logger logger = Logger.getLogger(UpdateService.class.getName());
|
||||
|
||||
/**
|
||||
* The update dispatcher.
|
||||
*/
|
||||
@@ -59,9 +67,6 @@ public final class UpdateService extends Service {
|
||||
return dispatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the threads in the pool.
|
||||
*/
|
||||
@Override
|
||||
public void start() {
|
||||
int release = getContext().getRelease().getReleaseNumber();
|
||||
@@ -72,23 +77,18 @@ public final class UpdateService extends Service {
|
||||
workers.add(new OnDemandRequestWorker(dispatcher, new IndexedFileSystem(base, true)));
|
||||
workers.add(new HttpRequestWorker(dispatcher, new IndexedFileSystem(base, true)));
|
||||
}
|
||||
|
||||
for (RequestWorker<?, ?> worker : workers) {
|
||||
service.submit(worker);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
System.err.println("Error adding request workers - " + ex.getMessage());
|
||||
} catch (FileNotFoundException reason) {
|
||||
logger.log(Level.SEVERE, "Unable to find index or data files from the file system.", reason);
|
||||
}
|
||||
|
||||
workers.forEach(service::submit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the threads in the pool.
|
||||
*/
|
||||
public void stop() {
|
||||
for (RequestWorker<?, ?> worker : workers) {
|
||||
worker.stop();
|
||||
}
|
||||
|
||||
workers.forEach(RequestWorker::stop);
|
||||
service.shutdownNow();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user