mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 08:39:11 +00:00
Fix sector repository and make minor improvement to WalkingQueue.
This commit is contained in:
@@ -18,7 +18,6 @@ import org.apollo.game.command.CommandDispatcher;
|
||||
import org.apollo.game.login.LoginDispatcher;
|
||||
import org.apollo.game.login.LogoutDispatcher;
|
||||
import org.apollo.game.model.area.Sector;
|
||||
import org.apollo.game.model.area.SectorCoordinates;
|
||||
import org.apollo.game.model.area.SectorRepository;
|
||||
import org.apollo.game.model.def.EquipmentDefinition;
|
||||
import org.apollo.game.model.def.ItemDefinition;
|
||||
@@ -329,7 +328,7 @@ public final class World {
|
||||
|
||||
boolean success = playerRepository.add(player);
|
||||
if (success) {
|
||||
Sector sector = sectorRepository.get(SectorCoordinates.fromPosition(player.getPosition()));
|
||||
Sector sector = sectorRepository.fromPosition(player.getPosition());
|
||||
sector.addEntity(player);
|
||||
|
||||
logger.info("Registered player: " + player + " [count=" + playerRepository.size() + "]");
|
||||
|
||||
@@ -3,7 +3,7 @@ package org.apollo.game.model.entity;
|
||||
import org.apollo.game.model.Position;
|
||||
|
||||
/**
|
||||
* Represents an in-game entity, such as a mob, object, projectile etc.
|
||||
* Represents an in-game entity, such as a mob, object, projectile, etc.
|
||||
*
|
||||
* @author Major
|
||||
*/
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.apollo.game.model.Graphic;
|
||||
import org.apollo.game.model.Position;
|
||||
import org.apollo.game.model.World;
|
||||
import org.apollo.game.model.area.Sector;
|
||||
import org.apollo.game.model.area.SectorCoordinates;
|
||||
import org.apollo.game.model.area.SectorRepository;
|
||||
import org.apollo.game.model.def.NpcDefinition;
|
||||
import org.apollo.game.model.entity.attr.Attribute;
|
||||
@@ -389,20 +390,23 @@ public abstract class Mob extends Entity {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the{@link Position} of this mob.
|
||||
* Sets the {@link Position} of this mob.
|
||||
*
|
||||
* @param position The position.
|
||||
*/
|
||||
public final void setPosition(Position position) {
|
||||
Position old = this.position;
|
||||
this.position = position;
|
||||
SectorRepository repository = World.getWorld().getSectorRepository();
|
||||
Sector newSector = repository.fromPosition(position);
|
||||
|
||||
if (old.getTopLeftSectorX() != position.getTopLeftSectorX()) {
|
||||
SectorRepository repository = World.getWorld().getSectorRepository();
|
||||
Sector oldSector = repository.fromPosition(old), newSector = repository.fromPosition(position);
|
||||
if (SectorCoordinates.fromPosition(this.position) != SectorCoordinates.fromPosition(position)) {
|
||||
Sector oldSector = repository.fromPosition(this.position);
|
||||
oldSector.removeEntity(this);
|
||||
newSector.addEntity(this);
|
||||
} else {
|
||||
newSector.removeEntity(this);
|
||||
}
|
||||
|
||||
this.position = position;
|
||||
newSector.addEntity(this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -104,11 +104,6 @@ public final class Player extends Mob {
|
||||
*/
|
||||
private List<String> friends = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Whether or not the player is skulled.
|
||||
*/
|
||||
private boolean isSkulled = false;
|
||||
|
||||
/**
|
||||
* The list of usernames of players this player has ignored.
|
||||
*/
|
||||
@@ -119,6 +114,11 @@ public final class Player extends Mob {
|
||||
*/
|
||||
private final transient InterfaceSet interfaceSet = new InterfaceSet(this);
|
||||
|
||||
/**
|
||||
* Whether or not the player is skulled.
|
||||
*/
|
||||
private boolean isSkulled = false;
|
||||
|
||||
/**
|
||||
* The centre of the last region the client has loaded.
|
||||
*/
|
||||
@@ -353,15 +353,6 @@ public final class Player extends Mob {
|
||||
return friends;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether or not the player is skulled
|
||||
*
|
||||
* @return {@code true} if the player is skulled, otherwise {@code false}.
|
||||
*/
|
||||
public boolean isSkulled() {
|
||||
return isSkulled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link List} of usernames of ignored players.
|
||||
*
|
||||
@@ -516,45 +507,6 @@ public final class Player extends Mob {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialises this player.
|
||||
*/
|
||||
private void init() {
|
||||
initInventories();
|
||||
initSkills();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialises the player's inventories.
|
||||
*/
|
||||
private void initInventories() {
|
||||
InventoryListener fullInventoryListener = new FullInventoryListener(this,
|
||||
FullInventoryListener.FULL_INVENTORY_MESSAGE);
|
||||
InventoryListener fullBankListener = new FullInventoryListener(this, FullInventoryListener.FULL_BANK_MESSAGE);
|
||||
InventoryListener appearanceListener = new AppearanceInventoryListener(this);
|
||||
|
||||
InventoryListener syncInventoryListener = new SynchronizationInventoryListener(this,
|
||||
SynchronizationInventoryListener.INVENTORY_ID);
|
||||
InventoryListener syncBankListener = new SynchronizationInventoryListener(this, BankConstants.BANK_INVENTORY_ID);
|
||||
InventoryListener syncEquipmentListener = new SynchronizationInventoryListener(this,
|
||||
SynchronizationInventoryListener.EQUIPMENT_ID);
|
||||
|
||||
inventory.addListener(syncInventoryListener);
|
||||
inventory.addListener(fullInventoryListener);
|
||||
bank.addListener(syncBankListener);
|
||||
bank.addListener(fullBankListener);
|
||||
equipment.addListener(syncEquipmentListener);
|
||||
equipment.addListener(appearanceListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialises the player's skills.
|
||||
*/
|
||||
private void initSkills() {
|
||||
skillSet.addListener(new SynchronizationSkillListener(this));
|
||||
skillSet.addListener(new LevelUpSkillListener(this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if there are excessive npcs.
|
||||
*
|
||||
@@ -600,6 +552,15 @@ public final class Player extends Mob {
|
||||
return running;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether or not the player is skulled
|
||||
*
|
||||
* @return {@code true} if the player is skulled, otherwise {@code false}.
|
||||
*/
|
||||
public boolean isSkulled() {
|
||||
return isSkulled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this player is withdrawing noted items.
|
||||
*
|
||||
@@ -692,29 +653,6 @@ public final class Player extends Mob {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the initial messages.
|
||||
*/
|
||||
private void sendInitialMessages() {
|
||||
send(new IdAssignmentMessage(index, members)); // TODO should this be sent when we reconnect?
|
||||
sendMessage("Welcome to RuneScape.");
|
||||
if (!newPlayer) {
|
||||
interfaceSet.openWindow(InterfaceConstants.AVATAR_DESIGN);
|
||||
}
|
||||
|
||||
int[] tabs = InterfaceConstants.DEFAULT_INVENTORY_TABS;
|
||||
for (int tab = 0; tab < tabs.length; tab++) {
|
||||
send(new SwitchTabInterfaceMessage(tab, tabs[tab]));
|
||||
}
|
||||
|
||||
inventory.forceRefresh();
|
||||
equipment.forceRefresh();
|
||||
bank.forceRefresh();
|
||||
skillSet.forceRefresh();
|
||||
|
||||
World.getWorld().getLoginDispatcher().dispatch(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a message to the player.
|
||||
*
|
||||
@@ -815,15 +753,6 @@ public final class Player extends Mob {
|
||||
this.friends = friends;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether or not the player is skulled. TODO make this an attribute
|
||||
*
|
||||
* @param isSkulled Whether or not the player is skulled.
|
||||
*/
|
||||
public void setSkulled(boolean isSkulled) {
|
||||
this.isSkulled = isSkulled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link List} of this player's ignored players.
|
||||
*
|
||||
@@ -920,6 +849,15 @@ public final class Player extends Mob {
|
||||
blockSet.add(SynchronizationBlock.createAppearanceBlock(this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether or not the player is skulled. TODO make this an attribute
|
||||
*
|
||||
* @param isSkulled Whether or not the player is skulled.
|
||||
*/
|
||||
public void setSkulled(boolean isSkulled) {
|
||||
this.isSkulled = isSkulled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the trade {@link PrivacyState}.
|
||||
*
|
||||
@@ -975,4 +913,66 @@ public final class Player extends Mob {
|
||||
+ ", clientVersion=" + clientVersion + "]";
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialises this player.
|
||||
*/
|
||||
private void init() {
|
||||
initInventories();
|
||||
initSkills();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialises the player's inventories.
|
||||
*/
|
||||
private void initInventories() {
|
||||
InventoryListener fullInventoryListener = new FullInventoryListener(this,
|
||||
FullInventoryListener.FULL_INVENTORY_MESSAGE);
|
||||
InventoryListener fullBankListener = new FullInventoryListener(this, FullInventoryListener.FULL_BANK_MESSAGE);
|
||||
InventoryListener appearanceListener = new AppearanceInventoryListener(this);
|
||||
|
||||
InventoryListener syncInventoryListener = new SynchronizationInventoryListener(this,
|
||||
SynchronizationInventoryListener.INVENTORY_ID);
|
||||
InventoryListener syncBankListener = new SynchronizationInventoryListener(this, BankConstants.BANK_INVENTORY_ID);
|
||||
InventoryListener syncEquipmentListener = new SynchronizationInventoryListener(this,
|
||||
SynchronizationInventoryListener.EQUIPMENT_ID);
|
||||
|
||||
inventory.addListener(syncInventoryListener);
|
||||
inventory.addListener(fullInventoryListener);
|
||||
bank.addListener(syncBankListener);
|
||||
bank.addListener(fullBankListener);
|
||||
equipment.addListener(syncEquipmentListener);
|
||||
equipment.addListener(appearanceListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialises the player's skills.
|
||||
*/
|
||||
private void initSkills() {
|
||||
skillSet.addListener(new SynchronizationSkillListener(this));
|
||||
skillSet.addListener(new LevelUpSkillListener(this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the initial messages.
|
||||
*/
|
||||
private void sendInitialMessages() {
|
||||
send(new IdAssignmentMessage(index, members)); // TODO should this be sent when we reconnect?
|
||||
sendMessage("Welcome to RuneScape.");
|
||||
if (!newPlayer) {
|
||||
interfaceSet.openWindow(InterfaceConstants.AVATAR_DESIGN);
|
||||
}
|
||||
|
||||
int[] tabs = InterfaceConstants.DEFAULT_INVENTORY_TABS;
|
||||
for (int tab = 0; tab < tabs.length; tab++) {
|
||||
send(new SwitchTabInterfaceMessage(tab, tabs[tab]));
|
||||
}
|
||||
|
||||
inventory.forceRefresh();
|
||||
equipment.forceRefresh();
|
||||
bank.forceRefresh();
|
||||
skillSet.forceRefresh();
|
||||
|
||||
World.getWorld().getLoginDispatcher().dispatch(this);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -228,10 +228,9 @@ public final class WalkingQueue {
|
||||
position = next.position;
|
||||
}
|
||||
}
|
||||
mob.setPosition(position);
|
||||
}
|
||||
|
||||
mob.setDirections(first, second);
|
||||
mob.setPosition(position);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -104,4 +104,21 @@ public final class PlayerCredentials {
|
||||
return usernameHash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return (int) encodedUsername;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
} else if (obj == null || getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
PlayerCredentials other = (PlayerCredentials) obj;
|
||||
return encodedUsername == other.encodedUsername;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user