private void DebugCharacter(EnterWorldRequest request) { var dbgString = "New character"; dbgString += " " + request.Name; foreach (int skill in request.Skills) { dbgString += " " + (ActionCode)skill; } log.DebugFormat(dbgString); }
internal Entity CreateClientEntity(MMOPeer peer, EnterWorldRequest operation) { var position = GetRandomWorldPosition(); var maxHealth = GetMaxHealth((WeaponCode)operation.Weapon); var attributes = new Attribute[] { new IntAttribute(maxHealth, AttributeCode.MaxHealth), new HealthAttribute(maxHealth), new ActionStateAttribute(), new FloatAttribute(7f, AttributeCode.Speed) }; var skills = operation.Skills; Array.Resize(ref skills, skills.Length + 1); skills[skills.Length - 1] = operation.Weapon; var entity = new ClientEntity(operation.Name, position, operation.Team, attributes, peer, skills); World.Instance.AddEntity(entity); return(entity); }
private OperationResponse OperationEnterWorld(PeerBase peer, OperationRequest request, SendParameters sendParameters) { var operation = new EnterWorldRequest(peer.Protocol, request); if (!operation.IsValid) { return(new OperationResponse(request.OperationCode) { ReturnCode = (int)ReturnCode.InvalidOperationParameter, DebugMessage = operation.GetErrorMessage() }); } DebugCharacter(operation); var entity = EntityFactory.Instance.CreateClientEntity(m_Peer, operation); // TODO: Think about a different place to store the username. m_Peer.Name = operation.Name; // Send entered world response. var responseData = new EnterWorldResponse { Position = entity.Position }; var response = new OperationResponse(request.OperationCode, responseData) { ReturnCode = (short)ReturnCode.OK }; m_Peer.SendOperationResponse(response, sendParameters); // Must happen after OK is sent to server. // Notify other peers about new player by adding the entity to the world cache. //TODO: Missing checks when adding new entity. E.g. is there already an entity with the same name. //World.Instance.AddEntity(entity); m_Peer.SetCurrentOperationHandler(new EntityOperationHandler(m_Peer)); return(null); }