mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 00:38:21 +00:00
Fix grouped region updating. Will need to account for re-adding StaticObjects after they have been removed from the game world. Also commented out some broken functionality in bootstrap involving first/second/third/etc message handlers. Should revisit with fix.
This commit is contained in:
@@ -177,15 +177,16 @@ def on_message(args, proc)
|
||||
numbers = [ 'first', 'second', 'third', 'fourth', 'fifth' ]
|
||||
message = args[0]; option = 0
|
||||
|
||||
numbers.each_index do |index|
|
||||
number = numbers[index]
|
||||
|
||||
if message.to_s.start_with?(number)
|
||||
option = index + 1
|
||||
message = message[number.length + 1, message.length].to_sym
|
||||
break
|
||||
end
|
||||
end
|
||||
# TODO
|
||||
# numbers.each_index do |index|
|
||||
# number = numbers[index]
|
||||
#
|
||||
# if message.to_s.start_with?(number)
|
||||
# option = index + 1
|
||||
# message = message[number.length + 1, message.length].to_sym
|
||||
# break
|
||||
# end
|
||||
# end
|
||||
|
||||
|
||||
class_name = message.to_s.camelize.concat('Message')
|
||||
|
||||
@@ -13,12 +13,12 @@ class OpenDoorAction < DistancedAction
|
||||
|
||||
def executeAction
|
||||
mob.turn_to(@door.position)
|
||||
DoorUtil::toggle(@door, mob)
|
||||
DoorUtil::toggle(@door)
|
||||
stop
|
||||
end
|
||||
|
||||
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
|
||||
@@ -28,6 +28,7 @@ on :message, :first_object_action do |player, message|
|
||||
if DoorUtil::is_door?(message.id)
|
||||
puts "Player: #{player.position}, door: #{message.position}"
|
||||
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
|
||||
@@ -46,7 +46,7 @@ module DoorUtil
|
||||
end
|
||||
|
||||
# Toggles the given door.
|
||||
def self.toggle(door, player)
|
||||
def self.toggle(door)
|
||||
position = door.position
|
||||
region = $world.region_repository.from_position(position)
|
||||
region.remove_entity(door)
|
||||
@@ -59,7 +59,7 @@ module DoorUtil
|
||||
else
|
||||
toggled_position = translate_door_position(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.add_entity(toggled_door)
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package org.apollo.game.message.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apollo.game.message.Message;
|
||||
import org.apollo.game.model.Position;
|
||||
import org.apollo.game.model.area.RegionCoordinates;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
|
||||
/**
|
||||
* 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.
|
||||
@@ -31,12 +31,12 @@ public final class GroupedRegionUpdateMessage extends Message {
|
||||
/**
|
||||
* 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 messages The {@link List} of {@link RegionUpdateMessage}s.
|
||||
*/
|
||||
public GroupedRegionUpdateMessage(Position player, RegionCoordinates coordinates, List<RegionUpdateMessage> messages) {
|
||||
this.player = player;
|
||||
public GroupedRegionUpdateMessage(Position lastKnownRegion, RegionCoordinates coordinates, List<RegionUpdateMessage> messages) {
|
||||
this.lastKnownRegion = lastKnownRegion;
|
||||
this.region = new Position(coordinates.getAbsoluteX(), coordinates.getAbsoluteY());
|
||||
this.messages = messages;
|
||||
}
|
||||
@@ -46,8 +46,8 @@ public final class GroupedRegionUpdateMessage extends Message {
|
||||
*
|
||||
* @return The Position.
|
||||
*/
|
||||
public Position getPlayerPosition() {
|
||||
return player;
|
||||
public Position getLastKnownRegion() {
|
||||
return lastKnownRegion;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
package org.apollo.game.sync.task;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.apollo.game.message.impl.ClearRegionMessage;
|
||||
import org.apollo.game.message.impl.GroupedRegionUpdateMessage;
|
||||
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.entity.Player;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 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));
|
||||
}
|
||||
|
||||
Optional<GroupedRegionUpdateMessage> message = toUpdateMessage(local, position, coordinates, repository);
|
||||
Optional<GroupedRegionUpdateMessage> message = toUpdateMessage(local, player.getLastKnownRegion(), coordinates, repository);
|
||||
if (message.isPresent()) {
|
||||
messages.add(message.get());
|
||||
}
|
||||
@@ -216,12 +210,12 @@ public final class PrePlayerSynchronizationTask extends SynchronizationTask {
|
||||
* {@link Optional#empty()} if no update message is required.
|
||||
*
|
||||
* @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 repository The {@link RegionRepository} containing the Regions.
|
||||
* @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;
|
||||
|
||||
/*
|
||||
@@ -237,7 +231,7 @@ public final class PrePlayerSynchronizationTask extends SynchronizationTask {
|
||||
messages = updates.get(coordinates);
|
||||
if (messages == null) {
|
||||
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);
|
||||
if (messages == null) {
|
||||
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 + ".");
|
||||
}
|
||||
|
||||
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
|
||||
public GamePacket encode(GroupedRegionUpdateMessage message) {
|
||||
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));
|
||||
System.out.println("Grum: local x: " + player.getLocalX(region) + ", local y: " + player.getLocalY(region));
|
||||
builder.put(DataType.BYTE, DataTransformation.NEGATE, player.getLocalX(region));
|
||||
builder.put(DataType.BYTE, region.getLocalY(lastKnownRegion));
|
||||
builder.put(DataType.BYTE, DataTransformation.NEGATE, region.getLocalX(lastKnownRegion));
|
||||
System.out.println("Grum: local x: " + lastKnownRegion.getLocalX(region) + ", local y: " + lastKnownRegion.getLocalY(region));
|
||||
|
||||
for (RegionUpdateMessage update : message.getMessages()) {
|
||||
System.out.println("==== Sending " + update + " as part of grum");
|
||||
|
||||
@@ -39,7 +39,7 @@ public final class GroupedRegionUpdateMessageEncoder extends MessageEncoder<Grou
|
||||
@Override
|
||||
public GamePacket encode(GroupedRegionUpdateMessage message) {
|
||||
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, DataTransformation.ADD, region.getLocalY(base));
|
||||
|
||||
Reference in New Issue
Block a user