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(
|
NetworkMessage message = EntityMessage.constructSpawnCreatureMessage(
|
||||||
id,
|
id,
|
||||||
Utilities.stringify(CreatureUtils.getCreatureTemplate(creature)),
|
Utilities.stringify(CreatureUtils.getCreatureTemplate(creature)),
|
||||||
(float)position.x,
|
position.x,
|
||||||
(float)position.y,
|
position.y,
|
||||||
(float)position.z);
|
position.z);
|
||||||
// NetworkMessage message = EntityMessage.constructCreateMessage(id, EntityDataStrings.ENTITY_CATEGORY_CREATURE, type, (float)position.x, (float)position.y, (float)position.z);
|
// NetworkMessage message = EntityMessage.constructCreateMessage(id, EntityDataStrings.ENTITY_CATEGORY_CREATURE, type, (float)position.x, (float)position.y, (float)position.z);
|
||||||
player.addMessage(message);
|
player.addMessage(message);
|
||||||
if(CreatureUtils.hasControllerPlayerId(creature)){
|
if(CreatureUtils.hasControllerPlayerId(creature)){
|
||||||
@ -494,7 +494,44 @@ public class CreatureUtils {
|
|||||||
return (CreatureTemplate)e.getData(EntityDataStrings.CREATURE_TEMPLATE);
|
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){
|
public static void repositionCreature(Entity creature, Vector3d position){
|
||||||
//if server, get current server data cell
|
//if server, get current server data cell
|
||||||
if(Globals.RUN_SERVER){
|
if(Globals.RUN_SERVER){
|
||||||
@ -505,6 +542,7 @@ public class CreatureUtils {
|
|||||||
if(oldDataCell != null && oldDataCell != newDataCell){
|
if(oldDataCell != null && oldDataCell != newDataCell){
|
||||||
oldDataCell.removeEntity(creature);
|
oldDataCell.removeEntity(creature);
|
||||||
}
|
}
|
||||||
|
newDataCell.initializeEntityForNewPlayers(creature, oldDataCell);
|
||||||
} else {
|
} else {
|
||||||
//if it doesn't already exist, try creating it and if successfull move creature
|
//if it doesn't already exist, try creating it and if successfull move creature
|
||||||
newDataCell = Globals.dataCellManager.tryCreateGroundDataCell(EntityUtils.getPosition(creature));
|
newDataCell = Globals.dataCellManager.tryCreateGroundDataCell(EntityUtils.getPosition(creature));
|
||||||
@ -513,6 +551,7 @@ public class CreatureUtils {
|
|||||||
if(oldDataCell != null && oldDataCell != newDataCell){
|
if(oldDataCell != null && oldDataCell != newDataCell){
|
||||||
oldDataCell.removeEntity(creature);
|
oldDataCell.removeEntity(creature);
|
||||||
}
|
}
|
||||||
|
newDataCell.initializeEntityForNewPlayers(creature, oldDataCell);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -116,6 +116,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
|
* Sends the current state of the datacell to the player
|
||||||
* Commonly, this should be called when a player is added to the cell
|
* Commonly, this should be called when a player is added to the cell
|
||||||
|
|||||||
@ -34,7 +34,7 @@ public class CharacterProtocol {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case REQUESTSPAWNCHARACTER:
|
case REQUESTSPAWNCHARACTER:
|
||||||
spawnPlayerCharacter(connectionHandler);
|
spawnClientEntity(connectionHandler);
|
||||||
break;
|
break;
|
||||||
case RESPONSECHARACTERLIST:
|
case RESPONSECHARACTERLIST:
|
||||||
case RESPONSECREATECHARACTERSUCCESS:
|
case RESPONSECREATECHARACTERSUCCESS:
|
||||||
@ -51,7 +51,7 @@ public class CharacterProtocol {
|
|||||||
Entity newPlayerEntity = CreatureUtils.spawnBasicCreature("human",connectionHandler.getCurrentCreatureTemplate());
|
Entity newPlayerEntity = CreatureUtils.spawnBasicCreature("human",connectionHandler.getCurrentCreatureTemplate());
|
||||||
int playerCharacterId = newPlayerEntity.getId();
|
int playerCharacterId = newPlayerEntity.getId();
|
||||||
connectionHandler.setPlayerCharacterId(playerCharacterId);
|
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());
|
CreatureUtils.setControllerPlayerId(newPlayerEntity, connectionHandler.getPlayerId());
|
||||||
//attach player object to player character
|
//attach player object to player character
|
||||||
playerObject.setPlayerEntity(newPlayerEntity);
|
playerObject.setPlayerEntity(newPlayerEntity);
|
||||||
|
|||||||
@ -51,6 +51,7 @@ public class EntityProtocol {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
void queueChunkState(ServerConnectionHandler connectionHandler){
|
void queueChunkState(ServerConnectionHandler connectionHandler){
|
||||||
//queue messages for that chunk
|
//queue messages for that chunk
|
||||||
if(Globals.RUN_SERVER && Globals.clientPlayer == null){
|
if(Globals.RUN_SERVER && Globals.clientPlayer == null){
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user