Sending initial entity & removing DC'd player
This commit is contained in:
parent
3e44bfbb79
commit
5c8000e4d4
@ -395,9 +395,9 @@ public class CreatureUtils {
|
||||
NetworkMessage message = EntityMessage.constructSpawnCreatureMessage(
|
||||
id,
|
||||
Utilities.stringify(CreatureUtils.getCreatureTemplate(creature)),
|
||||
(float)position.x,
|
||||
(float)position.y,
|
||||
(float)position.z);
|
||||
position.x,
|
||||
position.y,
|
||||
position.z);
|
||||
// NetworkMessage message = EntityMessage.constructCreateMessage(id, EntityDataStrings.ENTITY_CATEGORY_CREATURE, type, (float)position.x, (float)position.y, (float)position.z);
|
||||
player.addMessage(message);
|
||||
if(CreatureUtils.hasControllerPlayerId(creature)){
|
||||
@ -494,7 +494,44 @@ public class CreatureUtils {
|
||||
return (CreatureTemplate)e.getData(EntityDataStrings.CREATURE_TEMPLATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the creature is first spawned to serialize to all people in its initial chunk
|
||||
* @param creature
|
||||
* @param position
|
||||
*/
|
||||
public static void initiallyPositionCreature(Entity creature, Vector3d position){
|
||||
//if server, get current server data cell
|
||||
if(Globals.RUN_SERVER){
|
||||
ServerDataCell oldDataCell = Globals.dataCellManager.getDataCellAtPoint(EntityUtils.getPosition(creature));
|
||||
ServerDataCell newDataCell = Globals.dataCellManager.getDataCellAtPoint(position);
|
||||
if(newDataCell != null){
|
||||
newDataCell.addEntity(creature);
|
||||
if(oldDataCell != null && oldDataCell != newDataCell){
|
||||
oldDataCell.removeEntity(creature);
|
||||
}
|
||||
newDataCell.initializeEntityForNewPlayers(creature, null);
|
||||
} else {
|
||||
//if it doesn't already exist, try creating it and if successfull move creature
|
||||
newDataCell = Globals.dataCellManager.tryCreateGroundDataCell(EntityUtils.getPosition(creature));
|
||||
if(newDataCell != null){
|
||||
newDataCell.addEntity(creature);
|
||||
if(oldDataCell != null && oldDataCell != newDataCell){
|
||||
oldDataCell.removeEntity(creature);
|
||||
}
|
||||
newDataCell.initializeEntityForNewPlayers(creature, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
//reposition entity
|
||||
// CreatureUtils.repositionCreature(creature, Globals.spawnPoint);
|
||||
CollisionObjUtils.positionCharacter(creature, Globals.spawnPoint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called to reposition the creature
|
||||
* @param creature
|
||||
* @param position
|
||||
*/
|
||||
public static void repositionCreature(Entity creature, Vector3d position){
|
||||
//if server, get current server data cell
|
||||
if(Globals.RUN_SERVER){
|
||||
@ -505,6 +542,7 @@ public class CreatureUtils {
|
||||
if(oldDataCell != null && oldDataCell != newDataCell){
|
||||
oldDataCell.removeEntity(creature);
|
||||
}
|
||||
newDataCell.initializeEntityForNewPlayers(creature, oldDataCell);
|
||||
} else {
|
||||
//if it doesn't already exist, try creating it and if successfull move creature
|
||||
newDataCell = Globals.dataCellManager.tryCreateGroundDataCell(EntityUtils.getPosition(creature));
|
||||
@ -513,6 +551,7 @@ public class CreatureUtils {
|
||||
if(oldDataCell != null && oldDataCell != newDataCell){
|
||||
oldDataCell.removeEntity(creature);
|
||||
}
|
||||
newDataCell.initializeEntityForNewPlayers(creature, oldDataCell);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -115,6 +115,24 @@ public class ServerDataCell {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes the given creature to all players in this cell that aren't in the provided list of players
|
||||
* whom have already received spawn messages for the entity
|
||||
* @param creature The creature entity to spawn
|
||||
* @param previousCell The datacell the creature was previously in, which we will use to selectively not send the creature
|
||||
*/
|
||||
public void initializeEntityForNewPlayers(Entity creature, ServerDataCell previousCell){
|
||||
for(Player player : this.activePlayers){
|
||||
if(previousCell != null){
|
||||
if(!previousCell.containsPlayer(player)){
|
||||
CreatureUtils.sendEntityToPlayer(player, creature);
|
||||
}
|
||||
} else {
|
||||
CreatureUtils.sendEntityToPlayer(player, creature);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the current state of the datacell to the player
|
||||
|
||||
@ -34,7 +34,7 @@ public class CharacterProtocol {
|
||||
}
|
||||
break;
|
||||
case REQUESTSPAWNCHARACTER:
|
||||
spawnPlayerCharacter(connectionHandler);
|
||||
spawnClientEntity(connectionHandler);
|
||||
break;
|
||||
case RESPONSECHARACTERLIST:
|
||||
case RESPONSECREATECHARACTERSUCCESS:
|
||||
@ -51,7 +51,7 @@ public class CharacterProtocol {
|
||||
Entity newPlayerEntity = CreatureUtils.spawnBasicCreature("human",connectionHandler.getCurrentCreatureTemplate());
|
||||
int playerCharacterId = newPlayerEntity.getId();
|
||||
connectionHandler.setPlayerCharacterId(playerCharacterId);
|
||||
CreatureUtils.repositionCreature(newPlayerEntity, new Vector3d(Globals.spawnPoint.x,Globals.spawnPoint.y,Globals.spawnPoint.z));
|
||||
CreatureUtils.initiallyPositionCreature(newPlayerEntity, new Vector3d(Globals.spawnPoint.x,Globals.spawnPoint.y,Globals.spawnPoint.z));
|
||||
CreatureUtils.setControllerPlayerId(newPlayerEntity, connectionHandler.getPlayerId());
|
||||
//attach player object to player character
|
||||
playerObject.setPlayerEntity(newPlayerEntity);
|
||||
|
||||
@ -51,6 +51,7 @@ public class EntityProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
void queueChunkState(ServerConnectionHandler connectionHandler){
|
||||
//queue messages for that chunk
|
||||
if(Globals.RUN_SERVER && Globals.clientPlayer == null){
|
||||
|
||||
Loading…
Reference in New Issue
Block a user