mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-06 08:40:03 +00:00
Merged feature/region-update into master
This commit is contained in:
@@ -177,15 +177,16 @@ def on_message(args, proc)
|
|||||||
numbers = [ 'first', 'second', 'third', 'fourth', 'fifth' ]
|
numbers = [ 'first', 'second', 'third', 'fourth', 'fifth' ]
|
||||||
message = args[0]; option = 0
|
message = args[0]; option = 0
|
||||||
|
|
||||||
numbers.each_index do |index|
|
# TODO
|
||||||
number = numbers[index]
|
# numbers.each_index do |index|
|
||||||
|
# number = numbers[index]
|
||||||
if message.to_s.start_with?(number)
|
#
|
||||||
option = index + 1
|
# if message.to_s.start_with?(number)
|
||||||
message = message[number.length + 1, message.length].to_sym
|
# option = index + 1
|
||||||
break
|
# message = message[number.length + 1, message.length].to_sym
|
||||||
end
|
# break
|
||||||
end
|
# end
|
||||||
|
# end
|
||||||
|
|
||||||
|
|
||||||
class_name = message.to_s.camelize.concat('Message')
|
class_name = message.to_s.camelize.concat('Message')
|
||||||
|
|||||||
@@ -13,12 +13,12 @@ class OpenDoorAction < DistancedAction
|
|||||||
|
|
||||||
def executeAction
|
def executeAction
|
||||||
mob.turn_to(@door.position)
|
mob.turn_to(@door.position)
|
||||||
DoorUtil::toggle(@door, mob)
|
DoorUtil::toggle(@door)
|
||||||
stop
|
stop
|
||||||
end
|
end
|
||||||
|
|
||||||
def equals(other)
|
def equals(other)
|
||||||
return (get_class == other.get_class && @door_object == other.door_object)
|
return (get_class == other.get_class && @door == other.door)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -28,6 +28,7 @@ on :message, :first_object_action do |player, message|
|
|||||||
if DoorUtil::is_door?(message.id)
|
if DoorUtil::is_door?(message.id)
|
||||||
puts "Player: #{player.position}, door: #{message.position}"
|
puts "Player: #{player.position}, door: #{message.position}"
|
||||||
door = DoorUtil::get_door_object(message.position, message.id)
|
door = DoorUtil::get_door_object(message.position, message.id)
|
||||||
player.start_action(OpenDoorAction.new(player, door)) unless door.nil?
|
DoorUtil::toggle(door) unless door.nil?
|
||||||
|
# player.start_action(OpenDoorAction.new(player, door)) unless door.nil?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -46,7 +46,7 @@ module DoorUtil
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Toggles the given door.
|
# Toggles the given door.
|
||||||
def self.toggle(door, player)
|
def self.toggle(door)
|
||||||
position = door.position
|
position = door.position
|
||||||
region = $world.region_repository.from_position(position)
|
region = $world.region_repository.from_position(position)
|
||||||
region.remove_entity(door)
|
region.remove_entity(door)
|
||||||
@@ -59,7 +59,7 @@ module DoorUtil
|
|||||||
else
|
else
|
||||||
toggled_position = translate_door_position(door)
|
toggled_position = translate_door_position(door)
|
||||||
toggled_orientation = translate_door_orientation(door)
|
toggled_orientation = translate_door_orientation(door)
|
||||||
toggled_door = DynamicGameObject.createPublic(door.id, toggled_position, door.type, toggled_orientation)
|
toggled_door = DynamicGameObject.createPublic($world, door.id, toggled_position, door.type, toggled_orientation)
|
||||||
|
|
||||||
toggled_region = $world.region_repository.from_position(toggled_position)
|
toggled_region = $world.region_repository.from_position(toggled_position)
|
||||||
toggled_region.add_entity(toggled_door)
|
toggled_region.add_entity(toggled_door)
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
package org.apollo.game.message.impl;
|
package org.apollo.game.message.impl;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.apollo.game.message.Message;
|
import org.apollo.game.message.Message;
|
||||||
import org.apollo.game.model.Position;
|
import org.apollo.game.model.Position;
|
||||||
import org.apollo.game.model.area.RegionCoordinates;
|
import org.apollo.game.model.area.RegionCoordinates;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link Message} sent to the client that contains multiple
|
* A {@link Message} sent to the client that contains multiple
|
||||||
*
|
*
|
||||||
@@ -14,9 +14,9 @@ import org.apollo.game.model.area.RegionCoordinates;
|
|||||||
public final class GroupedRegionUpdateMessage extends Message {
|
public final class GroupedRegionUpdateMessage extends Message {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Position of the Player.
|
* The last known region Position of the Player.
|
||||||
*/
|
*/
|
||||||
private final Position player;
|
private final Position lastKnownRegion;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Position of the Region being updated.
|
* The Position of the Region being updated.
|
||||||
@@ -31,12 +31,12 @@ public final class GroupedRegionUpdateMessage extends Message {
|
|||||||
/**
|
/**
|
||||||
* Creates the GroupedRegionUpdateMessage.
|
* Creates the GroupedRegionUpdateMessage.
|
||||||
*
|
*
|
||||||
* @param player The {@link Position} of the Player.
|
* @param lastKnownRegion The last known region {@link Position} of the Player.
|
||||||
* @param coordinates The {@link RegionCoordinates} of the Region being updated.
|
* @param coordinates The {@link RegionCoordinates} of the Region being updated.
|
||||||
* @param messages The {@link List} of {@link RegionUpdateMessage}s.
|
* @param messages The {@link List} of {@link RegionUpdateMessage}s.
|
||||||
*/
|
*/
|
||||||
public GroupedRegionUpdateMessage(Position player, RegionCoordinates coordinates, List<RegionUpdateMessage> messages) {
|
public GroupedRegionUpdateMessage(Position lastKnownRegion, RegionCoordinates coordinates, List<RegionUpdateMessage> messages) {
|
||||||
this.player = player;
|
this.lastKnownRegion = lastKnownRegion;
|
||||||
this.region = new Position(coordinates.getAbsoluteX(), coordinates.getAbsoluteY());
|
this.region = new Position(coordinates.getAbsoluteX(), coordinates.getAbsoluteY());
|
||||||
this.messages = messages;
|
this.messages = messages;
|
||||||
}
|
}
|
||||||
@@ -46,8 +46,8 @@ public final class GroupedRegionUpdateMessage extends Message {
|
|||||||
*
|
*
|
||||||
* @return The Position.
|
* @return The Position.
|
||||||
*/
|
*/
|
||||||
public Position getPlayerPosition() {
|
public Position getLastKnownRegion() {
|
||||||
return player;
|
return lastKnownRegion;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,12 +1,6 @@
|
|||||||
package org.apollo.game.sync.task;
|
package org.apollo.game.sync.task;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.apollo.game.message.impl.ClearRegionMessage;
|
import org.apollo.game.message.impl.ClearRegionMessage;
|
||||||
import org.apollo.game.message.impl.GroupedRegionUpdateMessage;
|
import org.apollo.game.message.impl.GroupedRegionUpdateMessage;
|
||||||
import org.apollo.game.message.impl.RegionChangeMessage;
|
import org.apollo.game.message.impl.RegionChangeMessage;
|
||||||
@@ -17,7 +11,7 @@ import org.apollo.game.model.area.RegionCoordinates;
|
|||||||
import org.apollo.game.model.area.RegionRepository;
|
import org.apollo.game.model.area.RegionRepository;
|
||||||
import org.apollo.game.model.entity.Player;
|
import org.apollo.game.model.entity.Player;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link SynchronizationTask} which does pre-synchronization work for the specified {@link Player}.
|
* A {@link SynchronizationTask} which does pre-synchronization work for the specified {@link Player}.
|
||||||
@@ -181,7 +175,7 @@ public final class PrePlayerSynchronizationTask extends SynchronizationTask {
|
|||||||
player.send(new ClearRegionMessage(position, coordinates));
|
player.send(new ClearRegionMessage(position, coordinates));
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<GroupedRegionUpdateMessage> message = toUpdateMessage(local, position, coordinates, repository);
|
Optional<GroupedRegionUpdateMessage> message = toUpdateMessage(local, player.getLastKnownRegion(), coordinates, repository);
|
||||||
if (message.isPresent()) {
|
if (message.isPresent()) {
|
||||||
messages.add(message.get());
|
messages.add(message.get());
|
||||||
}
|
}
|
||||||
@@ -216,12 +210,12 @@ public final class PrePlayerSynchronizationTask extends SynchronizationTask {
|
|||||||
* {@link Optional#empty()} if no update message is required.
|
* {@link Optional#empty()} if no update message is required.
|
||||||
*
|
*
|
||||||
* @param mode The RegionUpdateMode for the Message.
|
* @param mode The RegionUpdateMode for the Message.
|
||||||
* @param position The {@link Position} of the Player.
|
* @param lastKnownRegion The last known region {@link Position} of the Player.
|
||||||
* @param coordinates The {@link RegionCoordinates} of the {@link Region}.
|
* @param coordinates The {@link RegionCoordinates} of the {@link Region}.
|
||||||
* @param repository The {@link RegionRepository} containing the Regions.
|
* @param repository The {@link RegionRepository} containing the Regions.
|
||||||
* @return The Optional containing the GroupedRegionUpdateMessage.
|
* @return The Optional containing the GroupedRegionUpdateMessage.
|
||||||
*/
|
*/
|
||||||
private Optional<GroupedRegionUpdateMessage> toUpdateMessage(RegionUpdateMode mode, Position position, RegionCoordinates coordinates, RegionRepository repository) {
|
private Optional<GroupedRegionUpdateMessage> toUpdateMessage(RegionUpdateMode mode, Position lastKnownRegion, RegionCoordinates coordinates, RegionRepository repository) {
|
||||||
List<RegionUpdateMessage> messages;
|
List<RegionUpdateMessage> messages;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -237,7 +231,7 @@ public final class PrePlayerSynchronizationTask extends SynchronizationTask {
|
|||||||
messages = updates.get(coordinates);
|
messages = updates.get(coordinates);
|
||||||
if (messages == null) {
|
if (messages == null) {
|
||||||
synchronized (updates) {
|
synchronized (updates) {
|
||||||
messages = updates.computeIfAbsent(coordinates, coords -> repository.get(coords).getUpdates(position.getHeight()));
|
messages = updates.computeIfAbsent(coordinates, coords -> repository.get(coords).getUpdates(lastKnownRegion.getHeight()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -246,7 +240,7 @@ public final class PrePlayerSynchronizationTask extends SynchronizationTask {
|
|||||||
messages = snapshots.get(coordinates);
|
messages = snapshots.get(coordinates);
|
||||||
if (messages == null) {
|
if (messages == null) {
|
||||||
synchronized (snapshots) {
|
synchronized (snapshots) {
|
||||||
messages = snapshots.computeIfAbsent(coordinates, coords -> repository.get(coords).getSnapshot(position.getHeight()));
|
messages = snapshots.computeIfAbsent(coordinates, coords -> repository.get(coords).getSnapshot(lastKnownRegion.getHeight()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,7 +249,7 @@ public final class PrePlayerSynchronizationTask extends SynchronizationTask {
|
|||||||
throw new IllegalArgumentException("Unrecognised RegionUpdateMode " + mode + ".");
|
throw new IllegalArgumentException("Unrecognised RegionUpdateMode " + mode + ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
return messages.isEmpty() ? Optional.empty() : Optional.of(new GroupedRegionUpdateMessage(position, coordinates, messages));
|
return messages.isEmpty() ? Optional.empty() : Optional.of(new GroupedRegionUpdateMessage(lastKnownRegion, coordinates, messages));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -35,11 +35,11 @@ public final class GroupedRegionUpdateMessageEncoder extends MessageEncoder<Grou
|
|||||||
@Override
|
@Override
|
||||||
public GamePacket encode(GroupedRegionUpdateMessage message) {
|
public GamePacket encode(GroupedRegionUpdateMessage message) {
|
||||||
GamePacketBuilder builder = new GamePacketBuilder(60, PacketType.VARIABLE_SHORT);
|
GamePacketBuilder builder = new GamePacketBuilder(60, PacketType.VARIABLE_SHORT);
|
||||||
Position player = message.getPlayerPosition(), region = message.getRegionPosition();
|
Position lastKnownRegion = message.getLastKnownRegion(), region = message.getRegionPosition();
|
||||||
|
|
||||||
builder.put(DataType.BYTE, player.getLocalY(region));
|
builder.put(DataType.BYTE, region.getLocalY(lastKnownRegion));
|
||||||
System.out.println("Grum: local x: " + player.getLocalX(region) + ", local y: " + player.getLocalY(region));
|
builder.put(DataType.BYTE, DataTransformation.NEGATE, region.getLocalX(lastKnownRegion));
|
||||||
builder.put(DataType.BYTE, DataTransformation.NEGATE, player.getLocalX(region));
|
System.out.println("Grum: local x: " + lastKnownRegion.getLocalX(region) + ", local y: " + lastKnownRegion.getLocalY(region));
|
||||||
|
|
||||||
for (RegionUpdateMessage update : message.getMessages()) {
|
for (RegionUpdateMessage update : message.getMessages()) {
|
||||||
System.out.println("==== Sending " + update + " as part of grum");
|
System.out.println("==== Sending " + update + " as part of grum");
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ public final class GroupedRegionUpdateMessageEncoder extends MessageEncoder<Grou
|
|||||||
@Override
|
@Override
|
||||||
public GamePacket encode(GroupedRegionUpdateMessage message) {
|
public GamePacket encode(GroupedRegionUpdateMessage message) {
|
||||||
GamePacketBuilder builder = new GamePacketBuilder(183, PacketType.VARIABLE_SHORT);
|
GamePacketBuilder builder = new GamePacketBuilder(183, PacketType.VARIABLE_SHORT);
|
||||||
Position base = message.getPlayerPosition(), region = message.getRegionPosition();
|
Position base = message.getLastKnownRegion(), region = message.getRegionPosition();
|
||||||
|
|
||||||
builder.put(DataType.BYTE, region.getLocalX(base));
|
builder.put(DataType.BYTE, region.getLocalX(base));
|
||||||
builder.put(DataType.BYTE, DataTransformation.ADD, region.getLocalY(base));
|
builder.put(DataType.BYTE, DataTransformation.ADD, region.getLocalY(base));
|
||||||
|
|||||||
Reference in New Issue
Block a user